From patchwork Thu Jul 25 01:09:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 169658 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp10934927ilk; Wed, 24 Jul 2019 18:10:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqxV3jseCzXrKhxW+ArItF4Z0oF5UVSQLnQulKyiq33gOYbC0nTuX8zcn/3uFYaHjo/m+4HF X-Received: by 2002:a17:90a:208d:: with SMTP id f13mr87470600pjg.68.1564017013916; Wed, 24 Jul 2019 18:10:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564017013; cv=none; d=google.com; s=arc-20160816; b=ioJCJc8SedVReyPvEjOG9H6YFHY+47CxSZ+fqCx2vwu8FEQK6DzHPdgDYZJbXIKGQz Rf5QYhLQxxJMDlbBE9kyMQ6qDPMcoNL6V85MhsreleXatA6fXS6evGBIl/uZwnLgpj06 tbtRAl0fw3Wqh2lSZc+ehaqtb6apWaGi7LLgXpe7SuX7wMqmDVKrX0Dhoy02uQbAIxpz WFuNYUy3yExtghJE8jqGEHdvDYEJrH9RgQ3dHlAx6+344XuOfPGvYvR55sndcs9/D7nZ ld15B0aB8shzDipbkkpRsqZoEbN4ApIDUsK6PUmYGj8jW8UshKsrAOvGfZVC1bi/EvlK p9pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:references:in-reply-to:message-id:date :subject:to:from:delivered-to; bh=MrPoWX214gLRs1JCqG80V24D2Awrns3iAaLQH0X3yMA=; b=iJyu+IP4XYOLPGahx6MOrBl2DyVlirqXsBq+jwKyCrUABO5TgCmQquCyBS7gBC0k5z NuJ5stJwBpCnH4TfFWcpcY+QXusaaM5flnoK+xPQUvvqjlj2JIxVuV4e2dMkVsSLls/l vULCDbR9YKrM3hkAK47c0uPb1dLSbfVpZx++nIGqu+PZQlYhxGziIZoYrw5kc0cM92// XBzwoVZs7okyZcnLZkTcpv35qX1SFPstz5S9RyyT90FPOaHvzj22hFqlPdtCHbNJB5Ut 4Wu06dkHCtY1WGEjy4As+06i7VFCz82XoT6HIPahCrsHVeeezwN5GmAc5b3dPCAML1Tf ocAA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTPS id s19si15391269pgm.291.2019.07.24.18.10.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Jul 2019 18:10:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 439766E313; Thu, 25 Jul 2019 01:10:12 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-io1-f65.google.com (mail-io1-f65.google.com [209.85.166.65]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2DB366E2D1 for ; Thu, 25 Jul 2019 01:10:08 +0000 (UTC) Received: by mail-io1-f65.google.com with SMTP id k20so93609921ios.10 for ; Wed, 24 Jul 2019 18:10:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ohz11I0BD5v1dSKvx1LVUw/2M1EDEBmAhM95SHgIQi4=; b=VGC8enFEGg+QLvlkKPTECdxHdybsnxtvkU01SFJoyiM9mcVZI9+m/vwTp1WSqg6HAC T7hqtmYVp1KEJzeHDW3CgRu6CmydxZBfipECZ1l+eHmkCuwhWYtYEgEi4VL/NA70WSil GyelarPYEso2bPS47/JyccxZoET7/LeOhfEKEwiy7EXPOQjR3OYyTlMQfT18N2qT2Bsl 1IsJpgnfLhpc270jGL7KNm/D0RsxW6lYdWtldNygPi8bCNcEVpe83gdG/lWIInXqqBEi 5ZWKfJY53WJ1J5oV7NwS3xdVpF5JuyKO/xazb3JjqCAkrV4HHsuVzt6MaOoQBKMOdnj+ TLIg== X-Gm-Message-State: APjAAAUpSHWpVuhdaf1AoiLw0EWQkeRRGmTTehTJOjDV3XwNS+6/E3tU GUntdHw/txhKIPhH9b964HCWqL8= X-Received: by 2002:a5e:d817:: with SMTP id l23mr9457434iok.282.1564017007097; Wed, 24 Jul 2019 18:10:07 -0700 (PDT) Received: from xps15.herring.priv ([64.188.179.254]) by smtp.googlemail.com with ESMTPSA id o7sm40675924ioo.81.2019.07.24.18.10.05 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 24 Jul 2019 18:10:06 -0700 (PDT) From: Rob Herring To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 1/7] drm/gem: Allow sparsely populated page arrays in drm_gem_put_pages Date: Wed, 24 Jul 2019 19:09:57 -0600 Message-Id: <20190725011003.30837-2-robh@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190725011003.30837-1-robh@kernel.org> References: <20190725011003.30837-1-robh@kernel.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tomeu Vizoso , Maxime Ripard , Sean Paul , Steven Price , David Airlie , Boris Brezillon , Alyssa Rosenzweig , Robin Murphy Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Panfrost has a need for pages allocated on demand via GPU page faults. When releasing the pages, the only thing preventing using drm_gem_put_pages() is needing to skip over unpopulated pages, so allow for skipping over NULL struct page pointers. Cc: Maarten Lankhorst Cc: Maxime Ripard Cc: Sean Paul Cc: David Airlie Cc: Daniel Vetter Cc: dri-devel@lists.freedesktop.org Signed-off-by: Rob Herring --- v2: - new patch drivers/gpu/drm/drm_gem.c | 3 +++ 1 file changed, 3 insertions(+) -- 2.20.1 diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index 243f43d70f42..db373c945f16 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -633,6 +633,9 @@ void drm_gem_put_pages(struct drm_gem_object *obj, struct page **pages, pagevec_init(&pvec); for (i = 0; i < npages; i++) { + if (!pages[i]) + continue; + if (dirty) set_page_dirty(pages[i]); From patchwork Thu Jul 25 01:09:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 169659 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp10934971ilk; Wed, 24 Jul 2019 18:10:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqznjk2jD0Tio5LAxdt9f1X2LsjG7B4AUzDHAxatlhJ54R2wNIrrz0MBbFUJ/zM8J8OM9h2n X-Received: by 2002:a17:902:b608:: with SMTP id b8mr89730735pls.303.1564017016843; Wed, 24 Jul 2019 18:10:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564017016; cv=none; d=google.com; s=arc-20160816; b=06NeD0rCV+NBZ2R6Q5OOAwljfVRWZWFJFv+0TWoYxEq9ATOMXlxApfY9ZbCJzC19Nn VtGVALMGlxTdZP+RxYcR645Yhhhi4swC1h89x+KJBbxXPukt/YoCxdmoD4tKObPIi9oj +udWqYd6h4WURNwZCXCUS1XW4S0y1vmEwJ/vydIsW1ZktdP8ULOKBVdAcDkDJjJ9ow1K QY4eTmzrM5w2arVxm4uy+1W+yPQXt8tAfpdEKCo/2NkOT/3wxBYj6Ec+HjA9y+pKatQy sLG20p5+N/U6srV3IDnytQq4RyxnxYOeFnNqhCr/lkg5B8GLne1A53SGDirZSpD2EfBz YsFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:references:in-reply-to:message-id:date :subject:to:from:delivered-to; bh=+X9uNoJSUAaVqVpKQDzL9NtXL+yT7SpGftwfMsqyc9c=; b=SJ/j22f1dNfLMh8Q8J1S6VaoDuNP16WArJ2LMJfVWIZejs2YY8ceaBBo57QnADUYE+ jRZ66iG5Q3PL7rrRre8giGeWTMtdFnPxobEVWpEiMnNC4YdsodWnj4XK4l62IK/f984t du3xoYish8X2EHCiYoE4kw93N/K5VSvOrEctnUraS1NAWl4jjJOQjsr+vqWXzMPNyyAW L8VdSL43QFkZivicLTQ8fAiYsUZ0XTeTNZimdW+wr3Mbcf2bEg/YBfnvAcGWJkxgeHnT wpUtMP5DQi4oDtv79Yu7bd2D/3PDCDgKz/JA8TDULCEwKucyTtnpTDuyXuC4BHaUBeyq rBmg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [2610:10:20:722:a800:ff:fe36:1795]) by mx.google.com with ESMTPS id h7si19617193pgc.130.2019.07.24.18.10.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Jul 2019 18:10:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) client-ip=2610:10:20:722:a800:ff:fe36:1795; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AD9DC6E2D1; Thu, 25 Jul 2019 01:10:15 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-io1-f66.google.com (mail-io1-f66.google.com [209.85.166.66]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6D3946E2D1 for ; Thu, 25 Jul 2019 01:10:09 +0000 (UTC) Received: by mail-io1-f66.google.com with SMTP id j6so18497643ioa.5 for ; Wed, 24 Jul 2019 18:10:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7wo6KKh0OlJFgHNJTysz7wNQAp+MWYAtsandKNyFgTE=; b=MhGqhTlAi6o9ewT2IapteV84Tmn0FK1ChG4gvsNT1UG915Eqyu7xozXaCyZJvMzMqg Qg5RAguL+nt8mJSo1V80d0gto1tUPPEKwrsIDUtu+CzdH1XAXcdKDPYm1HtLR35Z/GRk 6JNCmP18kTNtBuakyYsVo6huxmHvD0+EKE6A407E0P2mcyqQmSayXiXUwAqPTQDMWBs2 JKdybEV/Np7+sZvOY0pUOaiaQ0m8nvdNDc5Y1BXvfG9Q2uM4oAHP1mam7EhiqJZByxsF Zz/6bUsSbho5uOkS34fQraXluZBchgJrhMqAkZsYAiPfsbUvojy7myBGTSDniREZ2i1c LNgw== X-Gm-Message-State: APjAAAV4QNDAdB5wmbw0jMYDuDJXiJ1B9Rucz7E+a5n3ticKrsK9Di/P tCJQK0bDtOFuwcW3OVbugOHyxMM= X-Received: by 2002:a02:b609:: with SMTP id h9mr84902773jam.36.1564017008474; Wed, 24 Jul 2019 18:10:08 -0700 (PDT) Received: from xps15.herring.priv ([64.188.179.254]) by smtp.googlemail.com with ESMTPSA id o7sm40675924ioo.81.2019.07.24.18.10.07 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 24 Jul 2019 18:10:07 -0700 (PDT) From: Rob Herring To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 2/7] drm/shmem: Put pages independent of a SG table being set Date: Wed, 24 Jul 2019 19:09:58 -0600 Message-Id: <20190725011003.30837-3-robh@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190725011003.30837-1-robh@kernel.org> References: <20190725011003.30837-1-robh@kernel.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tomeu Vizoso , Maxime Ripard , Sean Paul , Steven Price , David Airlie , Boris Brezillon , Alyssa Rosenzweig , Robin Murphy Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" If a driver does its own management of pages, the shmem helper object's pages array could be allocated when a SG table is not. There's not really any good reason to tie putting pages with having a SG table when freeing the object, so just put pages if the pages array is populated. Cc: Maarten Lankhorst Cc: Maxime Ripard Cc: Sean Paul Cc: David Airlie Cc: Daniel Vetter Cc: Eric Anholt Signed-off-by: Rob Herring --- v2: - new patch drivers/gpu/drm/drm_gem_shmem_helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.20.1 diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c index 2f64667ac805..477e4cc50f7a 100644 --- a/drivers/gpu/drm/drm_gem_shmem_helper.c +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c @@ -118,11 +118,11 @@ void drm_gem_shmem_free_object(struct drm_gem_object *obj) if (shmem->sgt) { dma_unmap_sg(obj->dev->dev, shmem->sgt->sgl, shmem->sgt->nents, DMA_BIDIRECTIONAL); - - drm_gem_shmem_put_pages(shmem); sg_free_table(shmem->sgt); kfree(shmem->sgt); } + if (shmem->pages) + drm_gem_shmem_put_pages(shmem); } WARN_ON(shmem->pages_use_count); From patchwork Thu Jul 25 01:09:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 169661 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp10935062ilk; Wed, 24 Jul 2019 18:10:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqyWVRGLTs3wTwAA3eEo1NQ6hMETOeYO9kiFP0KCpTDJPv+32xNvbahLc9AGaCT8l90Owsjt X-Received: by 2002:a17:902:e282:: with SMTP id cf2mr89552042plb.301.1564017021391; Wed, 24 Jul 2019 18:10:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564017021; cv=none; d=google.com; s=arc-20160816; b=WZUlpzvnrDv3hvfBLF0rVFxdK+y77P+5OcthxTr4mMzTtXBXLEG0ympm59DPMftGF+ TcuBYjN7eVZkMkixxFTSwqDEW9spNx7ISf1xHua96qETqe7xmoV67tIMvfu8RxtWXueY s5Dm60cSZDo4Vgl/qcEUfAM79jlNg0ilZaZOMqDdwQRBhKsTMTsg7s4M+81TCMbEUTzP SPeiBFKyWbiliXlone8Tycc85qX8SqpJ8TizD7haVivTnDW/UlAmmUWtgl1D6H9dpahM ZOe58SBaNooeXl9yCUgJ7z/2TARbxM9GFYpO77mDZEd97dUd2bKdW4+OK5k0WDCk17NW vLcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:references:in-reply-to:message-id:date :subject:to:from:delivered-to; bh=gIMyHDvGHWO7TgCZdnp4ymdVbYUxwTVGiI+4CvTIXPQ=; b=CER70QxwtY9/YXybrzyAQxPODEV9T6CK1d8O3Wty3q/V0MwCcmKcR2qDg2UV55ckiZ vBwhUdvXAVnw0WdKnz4j9AhleGh47wV8o0DUxDkO+34zrvwy1H4ENbNjaWZx9Sif/Qtt YrOyacz2fTe1icBbD7h7HvAdi2o7eEUcmThZBtypfzxodQ6+YWbyGiAsC6vIuCDh1S/L LtWckmYGi7P308cuBH3SAb5AIAJu5gCS16O0kN1GbdO6Uxk1a+JwLLCeUx5EcRgWVc9C FqU+ew3MASf4ywiHR//ntcQI3rAaEwOK6SAz21cfhyXH758n70OKVKAgX7JgY0dj0kdt cF0w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [2610:10:20:722:a800:ff:fe36:1795]) by mx.google.com with ESMTPS id f6si14626496pgc.123.2019.07.24.18.10.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Jul 2019 18:10:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) client-ip=2610:10:20:722:a800:ff:fe36:1795; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2F0BE6E40C; Thu, 25 Jul 2019 01:10:16 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-io1-f66.google.com (mail-io1-f66.google.com [209.85.166.66]) by gabe.freedesktop.org (Postfix) with ESMTPS id CD18B6E2D1 for ; Thu, 25 Jul 2019 01:10:10 +0000 (UTC) Received: by mail-io1-f66.google.com with SMTP id s7so93526115iob.11 for ; Wed, 24 Jul 2019 18:10:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mZskfzh4pExVQqC0Zvot0kraSl5jZ+n0SUHyy93+Vts=; b=CVh7ft6iWOusz5n4FLBzz7Dx7ScDsKNnhlo9o5mn4doy5kpuI/vEaextpAwuER6IaY BKv1CPl4oARDGjbMumILjLMKyCmOjGKuYT+BFQL+suasNFFWhipQyYjLxvPvtCrLJvl4 Uke684pjOYGJetz/F/HLEUSwXPzXXTWoSvF+9qjK2LHb6mnSOhpkHw7MBBGffY7gufCW wdUQSZgRXx6oTjdPdxeILVhMigCYsKKRp/QNQYY0bz0gLtrM9L+WXvifUv0yQRgi5M6y CSRwcz/fdvhUAtX67OUicMKhoTUkELGlKB7n9oh10sTFBRVfoZOjyeU9sIPITNQAYe5N FgAQ== X-Gm-Message-State: APjAAAU/6cBag6hHCe8jPguRAqze7TEWLc4yy56h+2O7ribAT4hhDiFZ CcZMswgpG2XJj2Olv2a9OEMw6Sk= X-Received: by 2002:a02:aa1d:: with SMTP id r29mr16432097jam.127.1564017009706; Wed, 24 Jul 2019 18:10:09 -0700 (PDT) Received: from xps15.herring.priv ([64.188.179.254]) by smtp.googlemail.com with ESMTPSA id o7sm40675924ioo.81.2019.07.24.18.10.08 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 24 Jul 2019 18:10:09 -0700 (PDT) From: Rob Herring To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 3/7] drm/panfrost: Restructure the GEM object creation Date: Wed, 24 Jul 2019 19:09:59 -0600 Message-Id: <20190725011003.30837-4-robh@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190725011003.30837-1-robh@kernel.org> References: <20190725011003.30837-1-robh@kernel.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tomeu Vizoso , Maxime Ripard , Sean Paul , Steven Price , David Airlie , Boris Brezillon , Alyssa Rosenzweig , Robin Murphy Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Setting the GPU VA when creating the GEM object doesn't allow for any conditional adjustments. In preparation to support adjusting the mapping, restructure the GEM object creation to map the GEM object after we've created the base shmem object. Cc: Tomeu Vizoso Cc: Boris Brezillon Cc: Robin Murphy Cc: Steven Price Cc: Alyssa Rosenzweig Signed-off-by: Rob Herring Reviewed-by: Steven Price --- drivers/gpu/drm/panfrost/panfrost_drv.c | 21 +++------ drivers/gpu/drm/panfrost/panfrost_gem.c | 58 ++++++++++++++++++++----- drivers/gpu/drm/panfrost/panfrost_gem.h | 5 +++ 3 files changed, 59 insertions(+), 25 deletions(-) diff --git a/drivers/gpu/drm/panfrost/panfrost_drv.c b/drivers/gpu/drm/panfrost/panfrost_drv.c index cb43ff4ebf4a..d354b92964d5 100644 --- a/drivers/gpu/drm/panfrost/panfrost_drv.c +++ b/drivers/gpu/drm/panfrost/panfrost_drv.c @@ -46,29 +46,20 @@ static int panfrost_ioctl_get_param(struct drm_device *ddev, void *data, struct static int panfrost_ioctl_create_bo(struct drm_device *dev, void *data, struct drm_file *file) { - int ret; - struct drm_gem_shmem_object *shmem; + struct panfrost_gem_object *bo; struct drm_panfrost_create_bo *args = data; if (!args->size || args->flags || args->pad) return -EINVAL; - shmem = drm_gem_shmem_create_with_handle(file, dev, args->size, - &args->handle); - if (IS_ERR(shmem)) - return PTR_ERR(shmem); - - ret = panfrost_mmu_map(to_panfrost_bo(&shmem->base)); - if (ret) - goto err_free; + bo = panfrost_gem_create_with_handle(file, dev, args->size, args->flags, + &args->handle); + if (IS_ERR(bo)) + return PTR_ERR(bo); - args->offset = to_panfrost_bo(&shmem->base)->node.start << PAGE_SHIFT; + args->offset = bo->node.start << PAGE_SHIFT; return 0; - -err_free: - drm_gem_handle_delete(file, args->handle); - return ret; } /** diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.c b/drivers/gpu/drm/panfrost/panfrost_gem.c index 543ab1b81bd5..df70dcf3cb2f 100644 --- a/drivers/gpu/drm/panfrost/panfrost_gem.c +++ b/drivers/gpu/drm/panfrost/panfrost_gem.c @@ -23,7 +23,8 @@ static void panfrost_gem_free_object(struct drm_gem_object *obj) panfrost_mmu_unmap(bo); spin_lock(&pfdev->mm_lock); - drm_mm_remove_node(&bo->node); + if (drm_mm_node_allocated(&bo->node)) + drm_mm_remove_node(&bo->node); spin_unlock(&pfdev->mm_lock); drm_gem_shmem_free_object(obj); @@ -50,10 +51,7 @@ static const struct drm_gem_object_funcs panfrost_gem_funcs = { */ struct drm_gem_object *panfrost_gem_create_object(struct drm_device *dev, size_t size) { - int ret; - struct panfrost_device *pfdev = dev->dev_private; struct panfrost_gem_object *obj; - u64 align; obj = kzalloc(sizeof(*obj), GFP_KERNEL); if (!obj) @@ -61,20 +59,52 @@ struct drm_gem_object *panfrost_gem_create_object(struct drm_device *dev, size_t obj->base.base.funcs = &panfrost_gem_funcs; - size = roundup(size, PAGE_SIZE); - align = size >= SZ_2M ? SZ_2M >> PAGE_SHIFT : 0; + return &obj->base.base; +} + +static int panfrost_gem_map(struct panfrost_device *pfdev, struct panfrost_gem_object *bo) +{ + int ret; + size_t size = bo->base.base.size; + u64 align = size >= SZ_2M ? SZ_2M >> PAGE_SHIFT : 0; spin_lock(&pfdev->mm_lock); - ret = drm_mm_insert_node_generic(&pfdev->mm, &obj->node, + ret = drm_mm_insert_node_generic(&pfdev->mm, &bo->node, size >> PAGE_SHIFT, align, 0, 0); spin_unlock(&pfdev->mm_lock); + if (ret) + return ret; + + return panfrost_mmu_map(bo); +} + +struct panfrost_gem_object * +panfrost_gem_create_with_handle(struct drm_file *file_priv, + struct drm_device *dev, size_t size, + u32 flags, + uint32_t *handle) +{ + int ret; + struct panfrost_device *pfdev = dev->dev_private; + struct drm_gem_shmem_object *shmem; + struct panfrost_gem_object *bo; + + size = roundup(size, PAGE_SIZE); + + shmem = drm_gem_shmem_create_with_handle(file_priv, dev, size, handle); + if (IS_ERR(shmem)) + return ERR_CAST(shmem); + + bo = to_panfrost_bo(&shmem->base); + + ret = panfrost_gem_map(pfdev, bo); if (ret) goto free_obj; - return &obj->base.base; + return bo; free_obj: - kfree(obj); + drm_gem_handle_delete(file_priv, *handle); return ERR_PTR(ret); } @@ -83,8 +113,10 @@ panfrost_gem_prime_import_sg_table(struct drm_device *dev, struct dma_buf_attachment *attach, struct sg_table *sgt) { + int ret; struct drm_gem_object *obj; struct panfrost_gem_object *pobj; + struct panfrost_device *pfdev = dev->dev_private; obj = drm_gem_shmem_prime_import_sg_table(dev, attach, sgt); if (IS_ERR(obj)) @@ -92,7 +124,13 @@ panfrost_gem_prime_import_sg_table(struct drm_device *dev, pobj = to_panfrost_bo(obj); - panfrost_mmu_map(pobj); + ret = panfrost_gem_map(pfdev, pobj); + if (ret) + goto free_obj; return obj; + +free_obj: + drm_gem_object_put_unlocked(obj); + return ERR_PTR(ret); } diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.h b/drivers/gpu/drm/panfrost/panfrost_gem.h index 6dbcaba020fc..ce065270720b 100644 --- a/drivers/gpu/drm/panfrost/panfrost_gem.h +++ b/drivers/gpu/drm/panfrost/panfrost_gem.h @@ -22,6 +22,11 @@ struct panfrost_gem_object *to_panfrost_bo(struct drm_gem_object *obj) struct drm_gem_object *panfrost_gem_create_object(struct drm_device *dev, size_t size); +struct panfrost_gem_object * +panfrost_gem_create_with_handle(struct drm_file *file_priv, + struct drm_device *dev, size_t size, u32 flags, + uint32_t *handle); + struct drm_gem_object * panfrost_gem_prime_import_sg_table(struct drm_device *dev, struct dma_buf_attachment *attach, From patchwork Thu Jul 25 01:10:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 169660 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp10935020ilk; Wed, 24 Jul 2019 18:10:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqyOG0tJvtMlzTB5tKozD+hP+bGJNfUuhps0TcVLP61w8n32Grw3tvBITEe33sjm6/+0PrUH X-Received: by 2002:a63:3fc9:: with SMTP id m192mr85504766pga.429.1564017019369; Wed, 24 Jul 2019 18:10:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564017019; cv=none; d=google.com; s=arc-20160816; b=kvNx800SzZM/azNE6W/A22oG2YAW/3ulknl7gGgk5vdTP+4zRa3uHX+rV9HQfG2lLR kEMLMTNBSE+ZtMyFCnYIPKFTNRbLvTSjORXuV05sfHLa98OX9qU9+mMrIQTl5qNCD43c gjU7dsdt7ct4ro9gwzUC06ao4lwiZgLg0/w9d6uIfWVF7y4DhX5cyiZHxCaCbOMUNes9 c3jXi/L06c/Dre2RMS716DRLci0ROf+C2VWEAeWh0rXrgi8Qc6gMoszKueTOXkgEX+Dy MggtFQXiDEMHJESo6igGWfj/4OcY+PBkNDwoFd0xIMfsKmPDrwWnLywDPZUIRqtNdXgG eFFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:references:in-reply-to:message-id:date :subject:to:from:delivered-to; bh=KNl57wjsHSYUZbBywNEzn7NIKR5Ar+yvCQQALIn62AQ=; b=NpyRB1HPJYNUVoqLkFpqJceRC5Axppj0vY7T8r61UmUY3rWVG1oKi1Z/FQNdyO+b/7 o+ZmWomLwYdsUWBpJl3BcoExgRN3BKgh/ijlHyj0iIX6JijIdUmLc22idFoTyBMwyrWx Rc2agD1FS83d0cOCefBJHqUJbXMY/F3Xky+udvjyTc59DLQkXFtELelQKfP3riPsnLAc 2ObHii4J1sMnhfiMI7D3uDoUztBFPVjX2u9M0osyOOueTulBz4ZSHUmT2JsmVop8jYOJ zLNRe3mnO5WM9RqHmh1psR4wZykJO2tZe/uoj52bPQnAj7SYssiZUoam6AfGt7zyVKwG Vdog== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTPS id w9si14226632pjv.67.2019.07.24.18.10.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Jul 2019 18:10:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2244B6E386; Thu, 25 Jul 2019 01:10:16 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-io1-f66.google.com (mail-io1-f66.google.com [209.85.166.66]) by gabe.freedesktop.org (Postfix) with ESMTPS id 150996E2D1 for ; Thu, 25 Jul 2019 01:10:12 +0000 (UTC) Received: by mail-io1-f66.google.com with SMTP id i10so93582806iol.13 for ; Wed, 24 Jul 2019 18:10:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Vtjr2+2ofsw45xyTHE3FvXFioIOLEbSTpIy61lySGK0=; b=twLRZTWrT4vFrN996zPkX3YRS/mDlNSuha7ZQ57gJeBAuZBu97bnu2BYYZcFhQidn6 ao/xZOCHzKugWEAJUfz9j7JQ56u/wsmLVpyrpBFayX3FBtL9VCLaukc3clODYQnWWwnw CQWU/41ak33xA+Mixl8TvwTjYBl+gp+vzXRMdXxy3+aZsRCVEeDb4IHAK6yrmJIybT6j iqRbkV7Djz99tRFxjFgUiSsIUH2d1ZpcS9hd/YeWnV0Q0DAKX/2nM27ZABCmtsq3MaJh OSgDOjVP8iTs5ACyKvrq9y+S1ggWDFhqxhEacm6ObJ8TJjYYAO8ly3jKB7N7Po9yGNVZ UIBw== X-Gm-Message-State: APjAAAVYSLVkHaFlWxSPLH57M8ytbTAW2KPTE+rtfEtiOlPt8rPJcUx/ 548S2/QpVcJWdttDr3C2ErrK81k= X-Received: by 2002:a5d:8411:: with SMTP id i17mr49770529ion.83.1564017011013; Wed, 24 Jul 2019 18:10:11 -0700 (PDT) Received: from xps15.herring.priv ([64.188.179.254]) by smtp.googlemail.com with ESMTPSA id o7sm40675924ioo.81.2019.07.24.18.10.09 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 24 Jul 2019 18:10:10 -0700 (PDT) From: Rob Herring To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 4/7] drm/panfrost: Split panfrost_mmu_map SG list mapping to its own function Date: Wed, 24 Jul 2019 19:10:00 -0600 Message-Id: <20190725011003.30837-5-robh@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190725011003.30837-1-robh@kernel.org> References: <20190725011003.30837-1-robh@kernel.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tomeu Vizoso , Maxime Ripard , Sean Paul , Steven Price , David Airlie , Boris Brezillon , Alyssa Rosenzweig , Robin Murphy Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" In preparation to create partial GPU mappings of BOs on page faults, split out the SG list handling of panfrost_mmu_map(). Cc: Tomeu Vizoso Cc: Boris Brezillon Cc: Robin Murphy Cc: Alyssa Rosenzweig Reviewed-by: Steven Price Signed-off-by: Rob Herring --- drivers/gpu/drm/panfrost/panfrost_mmu.c | 52 +++++++++++++++---------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/panfrost/panfrost_mmu.c b/drivers/gpu/drm/panfrost/panfrost_mmu.c index 92ac995dd9c6..b4ac149b2399 100644 --- a/drivers/gpu/drm/panfrost/panfrost_mmu.c +++ b/drivers/gpu/drm/panfrost/panfrost_mmu.c @@ -145,27 +145,13 @@ static size_t get_pgsize(u64 addr, size_t size) return SZ_2M; } -int panfrost_mmu_map(struct panfrost_gem_object *bo) +static int mmu_map_sg(struct panfrost_device *pfdev, u64 iova, + int prot, struct sg_table *sgt) { - struct drm_gem_object *obj = &bo->base.base; - struct panfrost_device *pfdev = to_panfrost_device(obj->dev); - struct io_pgtable_ops *ops = pfdev->mmu->pgtbl_ops; - u64 iova = bo->node.start << PAGE_SHIFT; unsigned int count; struct scatterlist *sgl; - struct sg_table *sgt; - int ret; - - if (WARN_ON(bo->is_mapped)) - return 0; - - sgt = drm_gem_shmem_get_pages_sgt(obj); - if (WARN_ON(IS_ERR(sgt))) - return PTR_ERR(sgt); - - ret = pm_runtime_get_sync(pfdev->dev); - if (ret < 0) - return ret; + struct io_pgtable_ops *ops = pfdev->mmu->pgtbl_ops; + u64 start_iova = iova; mutex_lock(&pfdev->mmu->lock); @@ -178,18 +164,42 @@ int panfrost_mmu_map(struct panfrost_gem_object *bo) while (len) { size_t pgsize = get_pgsize(iova | paddr, len); - ops->map(ops, iova, paddr, pgsize, IOMMU_WRITE | IOMMU_READ); + ops->map(ops, iova, paddr, pgsize, prot); iova += pgsize; paddr += pgsize; len -= pgsize; } } - mmu_hw_do_operation(pfdev, 0, bo->node.start << PAGE_SHIFT, - bo->node.size << PAGE_SHIFT, AS_COMMAND_FLUSH_PT); + mmu_hw_do_operation(pfdev, 0, start_iova, iova - start_iova, + AS_COMMAND_FLUSH_PT); mutex_unlock(&pfdev->mmu->lock); + return 0; +} + +int panfrost_mmu_map(struct panfrost_gem_object *bo) +{ + struct drm_gem_object *obj = &bo->base.base; + struct panfrost_device *pfdev = to_panfrost_device(obj->dev); + struct sg_table *sgt; + int ret; + int prot = IOMMU_READ | IOMMU_WRITE; + + if (WARN_ON(bo->is_mapped)) + return 0; + + sgt = drm_gem_shmem_get_pages_sgt(obj); + if (WARN_ON(IS_ERR(sgt))) + return PTR_ERR(sgt); + + ret = pm_runtime_get_sync(pfdev->dev); + if (ret < 0) + return ret; + + mmu_map_sg(pfdev, bo->node.start << PAGE_SHIFT, prot, sgt); + pm_runtime_mark_last_busy(pfdev->dev); pm_runtime_put_autosuspend(pfdev->dev); bo->is_mapped = true; From patchwork Thu Jul 25 01:10:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 169662 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp10935102ilk; Wed, 24 Jul 2019 18:10:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqyVtZc85F8SxyrwBSIvNyg3hnJgcncL6eF8r7jSa5vYNVWfFHebx7d2+m+2a3x+2D9kINrY X-Received: by 2002:a65:64ce:: with SMTP id t14mr18066182pgv.137.1564017023389; Wed, 24 Jul 2019 18:10:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564017023; cv=none; d=google.com; s=arc-20160816; b=vJQBPau1JliJyj/lwOxVbPsQi/EK58bKYdkxRSdZIv0s87w1zvhE1suprYoBTa8hzY BYj2etqYmmxQdlJxo6WnETpGd4dV3Y47Dvy7vPxFVK/XNUIqBRf1vbY4XZamv/MreGzq s/qZd5z+GljBcmjjM329x9Zf1Ghx5SrXeB9Y/EXgAcowo7cZvo51NiR9xtfSruucOSz8 nTuRkis76DuytkSyO/ybSbVqu4kemX/EcjCWWIrJJgZSjyRER2rrep70NvAj+SJ8yyrS kwLowelPPE2SJ0gwGe7kE33ocTwX1zadgLucjnocwnWzZcM8Dj+3gQv37X7t/HjhZG/o /eWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:references:in-reply-to:message-id:date :subject:to:from:delivered-to; bh=SC6pUTBg8Mpyz5aBPYikncatHaJr7k4m7pMXQtF/Ggk=; b=i+3FPYH5WgB5QV/f3xGX6vHpnu2dZ8nriEgtdM/2IkSdhILDbRgxtO95HdFvvSqLg3 GiLg4SQnAmInzBw+GZN/CE1wVL2hvcai+oaJDI/C11YuRYhUuhWD3FMEuEBNsQWzsDh2 sYq0ZrhgREwlaJxHQHzSy8WgvaUhQ6E61ELPJH1EY2IKtSFX03PGrJ0zPeIR3m+x42XX ibXRAuNFonDmrB5uLapsXrhpZjb0L/0YeUhoFu6R96L2KuCowb+iRW7ACjPxXMh3RLnf c16NdKYZtyQwVizoMPHdyi60Cz/dZArpipFacq5zNmoDFqdpihND3SuL1ltTe3WepH4G lzWg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTPS id l62si14969390pgd.24.2019.07.24.18.10.23 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Jul 2019 18:10:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 467636E45F; Thu, 25 Jul 2019 01:10:16 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-io1-f65.google.com (mail-io1-f65.google.com [209.85.166.65]) by gabe.freedesktop.org (Postfix) with ESMTPS id 546386E386 for ; Thu, 25 Jul 2019 01:10:13 +0000 (UTC) Received: by mail-io1-f65.google.com with SMTP id o9so93741901iom.3 for ; Wed, 24 Jul 2019 18:10:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=itUCHgd5+YDoNqZ0pCFisl8uhAQ4AkF2IFCgpskUGRg=; b=HiCAeFYuf5WZB+nQJWOWhv+TIYR//m0busDGH/e67MAInsMteR/rXVMwX74A/yuUED 9Rt4x0V1YWUar0Y0pyeOYyYhvMhGiiO8CjH19NLpsz9bkfK9jUF1HvCM8DwOKnExq8xo zUPGL/VkFD3rnsZElHvAwuZiaMW7r+rT3VWh61hzHMf8pSqypQPh8InXyRcN5YnLZvQ5 LRT2Wgfd3gsBas3mQ8BQR86IZJEyUGZBEBO/lAN53gbvIWbeRaAxzb1l4OT1JgBJIvrx vEhhxkZ733HP8y7475hhNz/kPcEIq/advQz30rbBN+L7ZrXSxYkr5u71YVhFuQcknr+z o/Rg== X-Gm-Message-State: APjAAAVoseWd0hV3PVBq2pBRCUR/na3scDZDQC/bQ1oSFy3zWbABOKhX 4y7VNj2LkWGXpcWEAcefNaT0ylI= X-Received: by 2002:a02:cb4b:: with SMTP id k11mr87664214jap.109.1564017012246; Wed, 24 Jul 2019 18:10:12 -0700 (PDT) Received: from xps15.herring.priv ([64.188.179.254]) by smtp.googlemail.com with ESMTPSA id o7sm40675924ioo.81.2019.07.24.18.10.11 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 24 Jul 2019 18:10:11 -0700 (PDT) From: Rob Herring To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 5/7] drm/panfrost: Add a no execute flag for BO allocations Date: Wed, 24 Jul 2019 19:10:01 -0600 Message-Id: <20190725011003.30837-6-robh@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190725011003.30837-1-robh@kernel.org> References: <20190725011003.30837-1-robh@kernel.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tomeu Vizoso , Maxime Ripard , Sean Paul , Steven Price , David Airlie , Boris Brezillon , Alyssa Rosenzweig , Robin Murphy Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Executable buffers have an alignment restriction that they can't cross 16MB boundary as the GPU program counter is 24-bits. This restriction is currently not handled and we just get lucky. As current userspace assumes all BOs are executable, that has to remain the default. So add a new PANFROST_BO_NOEXEC flag to allow userspace to indicate which BOs are not executable. There is also a restriction that executable buffers cannot start or end on a 4GB boundary. This is mostly avoided as there is only 4GB of space currently and the beginning is already blocked out for NULL ptr detection. Add support to handle this restriction fully regardless of the current constraints. For existing userspace, all created BOs remain executable, but the GPU VA alignment will be increased to the size of the BO. This shouldn't matter as there is plenty of GPU VA space. Cc: Tomeu Vizoso Cc: Boris Brezillon Cc: Robin Murphy Cc: Steven Price Acked-by: Alyssa Rosenzweig Signed-off-by: Rob Herring Reviewed-by: Steven Price --- v2: - Rework panfrost_drm_mm_color_adjust() from Steven and Robin drivers/gpu/drm/panfrost/panfrost_drv.c | 30 ++++++++++++++++++++++++- drivers/gpu/drm/panfrost/panfrost_gem.c | 18 +++++++++++++-- drivers/gpu/drm/panfrost/panfrost_gem.h | 3 ++- drivers/gpu/drm/panfrost/panfrost_mmu.c | 3 +++ include/uapi/drm/panfrost_drm.h | 2 ++ 5 files changed, 52 insertions(+), 4 deletions(-) -- 2.20.1 diff --git a/drivers/gpu/drm/panfrost/panfrost_drv.c b/drivers/gpu/drm/panfrost/panfrost_drv.c index d354b92964d5..7ebd82d8d570 100644 --- a/drivers/gpu/drm/panfrost/panfrost_drv.c +++ b/drivers/gpu/drm/panfrost/panfrost_drv.c @@ -49,7 +49,8 @@ static int panfrost_ioctl_create_bo(struct drm_device *dev, void *data, struct panfrost_gem_object *bo; struct drm_panfrost_create_bo *args = data; - if (!args->size || args->flags || args->pad) + if (!args->size || args->pad || + (args->flags & ~PANFROST_BO_NOEXEC)) return -EINVAL; bo = panfrost_gem_create_with_handle(file, dev, args->size, args->flags, @@ -367,6 +368,32 @@ static struct drm_driver panfrost_drm_driver = { .gem_prime_mmap = drm_gem_prime_mmap, }; +#define PFN_4G (SZ_4G >> PAGE_SHIFT) +#define PFN_4G_MASK (PFN_4G - 1) +#define PFN_16M (SZ_16M >> PAGE_SHIFT) + +static void panfrost_drm_mm_color_adjust(const struct drm_mm_node *node, + unsigned long color, + u64 *start, u64 *end) +{ + /* Executable buffers can't start or end on a 4GB boundary */ + if (!(color & PANFROST_BO_NOEXEC)) { + u64 next_seg; + + if ((*start & PFN_4G_MASK) == 0) + (*start)++; + + if ((*end & PFN_4G_MASK) == 0) + (*end)--; + + next_seg = ALIGN(*start, PFN_4G); + if (next_seg - *start <= PFN_16M) + *start = next_seg + 1; + + *end = min(*end, ALIGN(*start, PFN_4G) - 1); + } +} + static int panfrost_probe(struct platform_device *pdev) { struct panfrost_device *pfdev; @@ -394,6 +421,7 @@ static int panfrost_probe(struct platform_device *pdev) /* 4G enough for now. can be 48-bit */ drm_mm_init(&pfdev->mm, SZ_32M >> PAGE_SHIFT, (SZ_4G - SZ_32M) >> PAGE_SHIFT); + pfdev->mm.color_adjust = panfrost_drm_mm_color_adjust; pm_runtime_use_autosuspend(pfdev->dev); pm_runtime_set_autosuspend_delay(pfdev->dev, 50); /* ~3 frames */ diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.c b/drivers/gpu/drm/panfrost/panfrost_gem.c index df70dcf3cb2f..63731f6c5223 100644 --- a/drivers/gpu/drm/panfrost/panfrost_gem.c +++ b/drivers/gpu/drm/panfrost/panfrost_gem.c @@ -66,11 +66,23 @@ static int panfrost_gem_map(struct panfrost_device *pfdev, struct panfrost_gem_o { int ret; size_t size = bo->base.base.size; - u64 align = size >= SZ_2M ? SZ_2M >> PAGE_SHIFT : 0; + u64 align; + unsigned long color = bo->noexec ? PANFROST_BO_NOEXEC : 0; + + /* + * Executable buffers cannot cross a 16MB boundary as the program + * counter is 24-bits. We assume executable buffers will be less than + * 16MB and aligning executable buffers to their size will avoid + * crossing a 16MB boundary. + */ + if (!bo->noexec) + align = size >> PAGE_SHIFT; + else + align = size >= SZ_2M ? SZ_2M >> PAGE_SHIFT : 0; spin_lock(&pfdev->mm_lock); ret = drm_mm_insert_node_generic(&pfdev->mm, &bo->node, - size >> PAGE_SHIFT, align, 0, 0); + size >> PAGE_SHIFT, align, color, 0); spin_unlock(&pfdev->mm_lock); if (ret) return ret; @@ -96,6 +108,7 @@ panfrost_gem_create_with_handle(struct drm_file *file_priv, return ERR_CAST(shmem); bo = to_panfrost_bo(&shmem->base); + bo->noexec = !!(flags & PANFROST_BO_NOEXEC); ret = panfrost_gem_map(pfdev, bo); if (ret) @@ -123,6 +136,7 @@ panfrost_gem_prime_import_sg_table(struct drm_device *dev, return ERR_CAST(obj); pobj = to_panfrost_bo(obj); + pobj->noexec = true; ret = panfrost_gem_map(pfdev, pobj); if (ret) diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.h b/drivers/gpu/drm/panfrost/panfrost_gem.h index ce065270720b..132f02399b7b 100644 --- a/drivers/gpu/drm/panfrost/panfrost_gem.h +++ b/drivers/gpu/drm/panfrost/panfrost_gem.h @@ -11,7 +11,8 @@ struct panfrost_gem_object { struct drm_gem_shmem_object base; struct drm_mm_node node; - bool is_mapped; + bool is_mapped :1; + bool noexec :1; }; static inline diff --git a/drivers/gpu/drm/panfrost/panfrost_mmu.c b/drivers/gpu/drm/panfrost/panfrost_mmu.c index b4ac149b2399..eba6ce785ef0 100644 --- a/drivers/gpu/drm/panfrost/panfrost_mmu.c +++ b/drivers/gpu/drm/panfrost/panfrost_mmu.c @@ -190,6 +190,9 @@ int panfrost_mmu_map(struct panfrost_gem_object *bo) if (WARN_ON(bo->is_mapped)) return 0; + if (bo->noexec) + prot |= IOMMU_NOEXEC; + sgt = drm_gem_shmem_get_pages_sgt(obj); if (WARN_ON(IS_ERR(sgt))) return PTR_ERR(sgt); diff --git a/include/uapi/drm/panfrost_drm.h b/include/uapi/drm/panfrost_drm.h index b5d370638846..17fb5d200f7a 100644 --- a/include/uapi/drm/panfrost_drm.h +++ b/include/uapi/drm/panfrost_drm.h @@ -82,6 +82,8 @@ struct drm_panfrost_wait_bo { __s64 timeout_ns; /* absolute */ }; +#define PANFROST_BO_NOEXEC 1 + /** * struct drm_panfrost_create_bo - ioctl argument for creating Panfrost BOs. * From patchwork Thu Jul 25 01:10:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 169663 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp10935147ilk; Wed, 24 Jul 2019 18:10:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqxNKhNgQqyGArkJvWvXkKbDiGNlWCziKLLTFBfF2vEh5+gDgAtxgtz6roBpvLe0jYi361Pq X-Received: by 2002:a65:52c5:: with SMTP id z5mr69846730pgp.118.1564017025382; Wed, 24 Jul 2019 18:10:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564017025; cv=none; d=google.com; s=arc-20160816; b=oJQtW1/BHTNiVo8TwqGLy8wn0uD+/ENDTAyN0DO0imfmPV5PALUy+CJVVRZ0fGanCP ydRWjDXIGu2I96d2+D6Zlcy3aNNxZXnRmhznTbRAL6o5xl0Gzes+Kr1nMGyl3zN+9IlV LwIBKKaWl+6XoXJx+p4lRi5EibTD+97r2/XTI+/XGhQRgm3FqhmmFdKXi5ftEKZrZ8rA hRZGhYSgFAVyEOEPaQ3wz4XLZ4zNR7cWweo4CSf4yz5phD6sVbWaDwfCs4IjQXlOsUWV 9b4QH8xV+ItJAX397hqDBbr0Zx9v8YC0vEuvV6Ce435wDWYMA3OcUiBV/aw1TEzVi++l zeew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:references:in-reply-to:message-id:date :subject:to:from:delivered-to; bh=bYzueyS8uCKd+TCD6JYdRBLTn0+HAs8NECJEUU3OoB0=; b=et9eHtyXaxe1lUV2kGG3VxH/pym2HjyYC7tkbKvqaalVH5Y80Tg8Onv6TsC7j7TEOc N4/yDqJhc3qQAkSl81q83xP/FGM9xgM8kgz4Je6LzYKlgDMagcEpkgJiC79NV9bFqPKq 7qLQGxrYFB2YUylyFU8RXSkTRaIRtNkiEgxQ8ZwemunUVn6dgzm37dUR70UBe7jL77g1 IHd77z77IXAeVi5rSGo6hmC/UaiPn5H/dG14J856aCB5nm4att8S+nJQKKvvqMCPzasb s5xmq7m0RB4WVE8RZprcIRXZ/LsTCEhwE5pPjiqKB1Wcm5+EUJ8dwuKXty6RIX7qqFkF E9Cg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTPS id v141si19912492pgb.183.2019.07.24.18.10.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Jul 2019 18:10:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 495E36E536; Thu, 25 Jul 2019 01:10:20 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-io1-f66.google.com (mail-io1-f66.google.com [209.85.166.66]) by gabe.freedesktop.org (Postfix) with ESMTPS id F0EED6E2D1 for ; Thu, 25 Jul 2019 01:10:14 +0000 (UTC) Received: by mail-io1-f66.google.com with SMTP id o9so93742019iom.3 for ; Wed, 24 Jul 2019 18:10:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZiKK8EDUD+QO/UCroXmjRy0syE8YB65DdnjmccAyQPU=; b=JNg3Q0Yqri9v/65q47mcwCvMCeX1BQji/x/xwu0Aoo2jwgPmNzZUqUb5Soj48IiQSj 1UcPVo9+jMYd6TPln26ScymkF1vr64HLzTwbsIJ39lntfsUR9KbaOzXe5FmbXta7eh3i G9dVFgiCfJNJ5VIm0CobF9BjWJBspPzql505v7yNEEg9xmyd/YBOzh3Qt4d1+oEHPApL xY1GBzvgIeoOICHMz21yoP5NOtNWk+b47vkOUuts4XHMxgaWEQpfA2GnBjPUmC1YJo5W Nr9GegccNHaRxNt4xxn0O3b2UAFexYE9dZlgaLcOcZEXrFfR8DKffKJgvrPL7rr/+Z9h SomA== X-Gm-Message-State: APjAAAVQMb4GsotYkTK5cWWjYVTRT6eSKuKWOSlEVXxpuCYfqpLMY26Z vej0jU2sHBSAFzDbRXA8Jc4ertk= X-Received: by 2002:a02:22c6:: with SMTP id o189mr85067296jao.35.1564017013572; Wed, 24 Jul 2019 18:10:13 -0700 (PDT) Received: from xps15.herring.priv ([64.188.179.254]) by smtp.googlemail.com with ESMTPSA id o7sm40675924ioo.81.2019.07.24.18.10.12 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 24 Jul 2019 18:10:12 -0700 (PDT) From: Rob Herring To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 6/7] drm/panfrost: Add support for GPU heap allocations Date: Wed, 24 Jul 2019 19:10:02 -0600 Message-Id: <20190725011003.30837-7-robh@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190725011003.30837-1-robh@kernel.org> References: <20190725011003.30837-1-robh@kernel.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tomeu Vizoso , Maxime Ripard , Sean Paul , Steven Price , David Airlie , Boris Brezillon , Alyssa Rosenzweig , Robin Murphy Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The midgard/bifrost GPUs need to allocate GPU heap memory which is allocated on GPU page faults and not pinned in memory. The vendor driver calls this functionality GROW_ON_GPF. This implementation assumes that BOs allocated with the PANFROST_BO_NOEXEC flag are never mmapped or exported. Both of those may actually work, but I'm unsure if there's some interaction there. It would cause the whole object to be pinned in memory which would defeat the point of this. On faults, we map in 2MB at a time in order to utilize huge pages (if enabled). Currently, once we've mapped pages in, they are only unmapped if the BO is freed. Once we add shrinker support, we can unmap pages with the shrinker. Cc: Tomeu Vizoso Cc: Boris Brezillon Cc: Robin Murphy Cc: Steven Price Cc: Alyssa Rosenzweig Signed-off-by: Rob Herring --- v2: - Stop leaking pages! - Properly call dma_unmap_sg on cleanup - Enforce PANFROST_BO_NOEXEC when PANFROST_BO_HEAP is set drivers/gpu/drm/panfrost/TODO | 2 - drivers/gpu/drm/panfrost/panfrost_drv.c | 7 +- drivers/gpu/drm/panfrost/panfrost_gem.c | 23 +++- drivers/gpu/drm/panfrost/panfrost_gem.h | 8 ++ drivers/gpu/drm/panfrost/panfrost_mmu.c | 134 ++++++++++++++++++++++-- include/uapi/drm/panfrost_drm.h | 1 + 6 files changed, 159 insertions(+), 16 deletions(-) -- 2.20.1 diff --git a/drivers/gpu/drm/panfrost/TODO b/drivers/gpu/drm/panfrost/TODO index c2e44add37d8..64129bf73933 100644 --- a/drivers/gpu/drm/panfrost/TODO +++ b/drivers/gpu/drm/panfrost/TODO @@ -14,8 +14,6 @@ The hard part is handling when more address spaces are needed than what the h/w provides. -- Support pinning pages on demand (GPU page faults). - - Support userspace controlled GPU virtual addresses. Needed for Vulkan. (Tomeu) - Support for madvise and a shrinker. diff --git a/drivers/gpu/drm/panfrost/panfrost_drv.c b/drivers/gpu/drm/panfrost/panfrost_drv.c index 7ebd82d8d570..46a6bec7a0f2 100644 --- a/drivers/gpu/drm/panfrost/panfrost_drv.c +++ b/drivers/gpu/drm/panfrost/panfrost_drv.c @@ -50,7 +50,12 @@ static int panfrost_ioctl_create_bo(struct drm_device *dev, void *data, struct drm_panfrost_create_bo *args = data; if (!args->size || args->pad || - (args->flags & ~PANFROST_BO_NOEXEC)) + (args->flags & ~(PANFROST_BO_NOEXEC | PANFROST_BO_HEAP))) + return -EINVAL; + + /* Heaps should never be executable */ + if ((args->flags & PANFROST_BO_HEAP) && + !(args->flags & PANFROST_BO_NOEXEC)) return -EINVAL; bo = panfrost_gem_create_with_handle(file, dev, args->size, args->flags, diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.c b/drivers/gpu/drm/panfrost/panfrost_gem.c index 63731f6c5223..1237fb531321 100644 --- a/drivers/gpu/drm/panfrost/panfrost_gem.c +++ b/drivers/gpu/drm/panfrost/panfrost_gem.c @@ -27,6 +27,17 @@ static void panfrost_gem_free_object(struct drm_gem_object *obj) drm_mm_remove_node(&bo->node); spin_unlock(&pfdev->mm_lock); + if (bo->sgts) { + int i; + int n_sgt = bo->base.base.size / SZ_2M; + + for (i = 0; i < n_sgt; i++) { + if (bo->sgts[i].sgl) + dma_unmap_sg(pfdev->dev, bo->sgts[i].sgl, + bo->sgts[i].nents, DMA_BIDIRECTIONAL); + } + } + drm_gem_shmem_free_object(obj); } @@ -87,7 +98,10 @@ static int panfrost_gem_map(struct panfrost_device *pfdev, struct panfrost_gem_o if (ret) return ret; - return panfrost_mmu_map(bo); + if (!bo->is_heap) + ret = panfrost_mmu_map(bo); + + return ret; } struct panfrost_gem_object * @@ -101,7 +115,11 @@ panfrost_gem_create_with_handle(struct drm_file *file_priv, struct drm_gem_shmem_object *shmem; struct panfrost_gem_object *bo; - size = roundup(size, PAGE_SIZE); + /* Round up heap allocations to 2MB to keep fault handling simple */ + if (flags & PANFROST_BO_HEAP) + size = roundup(size, SZ_2M); + else + size = roundup(size, PAGE_SIZE); shmem = drm_gem_shmem_create_with_handle(file_priv, dev, size, handle); if (IS_ERR(shmem)) @@ -109,6 +127,7 @@ panfrost_gem_create_with_handle(struct drm_file *file_priv, bo = to_panfrost_bo(&shmem->base); bo->noexec = !!(flags & PANFROST_BO_NOEXEC); + bo->is_heap = !!(flags & PANFROST_BO_HEAP); ret = panfrost_gem_map(pfdev, bo); if (ret) diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.h b/drivers/gpu/drm/panfrost/panfrost_gem.h index 132f02399b7b..b628c9b67784 100644 --- a/drivers/gpu/drm/panfrost/panfrost_gem.h +++ b/drivers/gpu/drm/panfrost/panfrost_gem.h @@ -9,10 +9,12 @@ struct panfrost_gem_object { struct drm_gem_shmem_object base; + struct sg_table *sgts; struct drm_mm_node node; bool is_mapped :1; bool noexec :1; + bool is_heap :1; }; static inline @@ -21,6 +23,12 @@ struct panfrost_gem_object *to_panfrost_bo(struct drm_gem_object *obj) return container_of(to_drm_gem_shmem_obj(obj), struct panfrost_gem_object, base); } +static inline +struct panfrost_gem_object *drm_mm_node_to_panfrost_bo(struct drm_mm_node *node) +{ + return container_of(node, struct panfrost_gem_object, node); +} + struct drm_gem_object *panfrost_gem_create_object(struct drm_device *dev, size_t size); struct panfrost_gem_object * diff --git a/drivers/gpu/drm/panfrost/panfrost_mmu.c b/drivers/gpu/drm/panfrost/panfrost_mmu.c index eba6ce785ef0..d164eeaf39be 100644 --- a/drivers/gpu/drm/panfrost/panfrost_mmu.c +++ b/drivers/gpu/drm/panfrost/panfrost_mmu.c @@ -2,6 +2,7 @@ /* Copyright 2019 Linaro, Ltd, Rob Herring */ #include #include +#include #include #include #include @@ -9,6 +10,7 @@ #include #include #include +#include #include #include "panfrost_device.h" @@ -235,12 +237,12 @@ void panfrost_mmu_unmap(struct panfrost_gem_object *bo) size_t unmapped_page; size_t pgsize = get_pgsize(iova, len - unmapped_len); - unmapped_page = ops->unmap(ops, iova, pgsize); - if (!unmapped_page) - break; - - iova += unmapped_page; - unmapped_len += unmapped_page; + if (ops->iova_to_phys(ops, iova)) { + unmapped_page = ops->unmap(ops, iova, pgsize); + WARN_ON(unmapped_page != pgsize); + } + iova += pgsize; + unmapped_len += pgsize; } mmu_hw_do_operation(pfdev, 0, bo->node.start << PAGE_SHIFT, @@ -276,6 +278,105 @@ static const struct iommu_gather_ops mmu_tlb_ops = { .tlb_sync = mmu_tlb_sync_context, }; +static struct drm_mm_node *addr_to_drm_mm_node(struct panfrost_device *pfdev, int as, u64 addr) +{ + struct drm_mm_node *node; + u64 offset = addr >> PAGE_SHIFT; + + drm_mm_for_each_node(node, &pfdev->mm) { + if (offset >= node->start && offset < (node->start + node->size)) + return node; + } + return NULL; +} + +#define NUM_FAULT_PAGES (SZ_2M / PAGE_SIZE) + +int panfrost_mmu_map_fault_addr(struct panfrost_device *pfdev, int as, u64 addr) +{ + int ret, i; + struct drm_mm_node *node; + struct panfrost_gem_object *bo; + struct address_space *mapping; + pgoff_t page_offset; + struct sg_table *sgt; + struct page **pages; + + node = addr_to_drm_mm_node(pfdev, as, addr); + if (!node) + return -ENOENT; + + bo = drm_mm_node_to_panfrost_bo(node); + if (!bo->is_heap) { + dev_WARN(pfdev->dev, "matching BO is not heap type (GPU VA = %llx)", + node->start << PAGE_SHIFT); + return -EINVAL; + } + /* Assume 2MB alignment and size multiple */ + addr &= ~((u64)SZ_2M - 1); + page_offset = addr >> PAGE_SHIFT; + page_offset -= node->start; + + mutex_lock(&bo->base.pages_lock); + + if (!bo->base.pages) { + bo->sgts = kvmalloc_array(bo->base.base.size / SZ_2M, + sizeof(struct sg_table), GFP_KERNEL | __GFP_ZERO); + if (!bo->sgts) + return -ENOMEM; + + pages = kvmalloc_array(bo->base.base.size >> PAGE_SHIFT, + sizeof(struct page *), GFP_KERNEL | __GFP_ZERO); + if (!pages) { + kfree(bo->sgts); + bo->sgts = NULL; + return -ENOMEM; + } + bo->base.pages = pages; + bo->base.pages_use_count = 1; + } else + pages = bo->base.pages; + + mapping = bo->base.base.filp->f_mapping; + mapping_set_unevictable(mapping); + + for (i = page_offset; i < page_offset + NUM_FAULT_PAGES; i++) { + pages[i] = shmem_read_mapping_page(mapping, i); + if (IS_ERR(pages[i])) { + mutex_unlock(&bo->base.pages_lock); + ret = PTR_ERR(pages[i]); + goto err_pages; + } + } + + mutex_unlock(&bo->base.pages_lock); + + sgt = &bo->sgts[page_offset / (SZ_2M / PAGE_SIZE)]; + ret = sg_alloc_table_from_pages(sgt, pages + page_offset, + NUM_FAULT_PAGES, 0, SZ_2M, GFP_KERNEL); + if (ret) + goto err_pages; + + if (!dma_map_sg(pfdev->dev, sgt->sgl, sgt->nents, DMA_BIDIRECTIONAL)) { + ret = -EINVAL; + goto err_map; + } + + mmu_map_sg(pfdev, addr, IOMMU_WRITE | IOMMU_READ | IOMMU_NOEXEC, sgt); + + bo->is_mapped = true; + + dev_dbg(pfdev->dev, "mapped page fault @ %llx", addr); + + return 0; + +err_map: + sg_free_table(sgt); +err_pages: + drm_gem_shmem_put_pages(&bo->base); + return ret; +} + static const char *access_type_name(struct panfrost_device *pfdev, u32 fault_status) { @@ -301,13 +402,11 @@ static irqreturn_t panfrost_mmu_irq_handler(int irq, void *data) { struct panfrost_device *pfdev = data; u32 status = mmu_read(pfdev, MMU_INT_STAT); - int i; + int i, ret; if (!status) return IRQ_NONE; - dev_err(pfdev->dev, "mmu irq status=%x\n", status); - for (i = 0; status; i++) { u32 mask = BIT(i) | BIT(i + 16); u64 addr; @@ -328,6 +427,18 @@ static irqreturn_t panfrost_mmu_irq_handler(int irq, void *data) access_type = (fault_status >> 8) & 0x3; source_id = (fault_status >> 16); + /* Page fault only */ + if ((status & mask) == BIT(i)) { + WARN_ON(exception_type < 0xC1 || exception_type > 0xC4); + + ret = panfrost_mmu_map_fault_addr(pfdev, i, addr); + if (!ret) { + mmu_write(pfdev, MMU_INT_CLEAR, BIT(i)); + status &= ~mask; + continue; + } + } + /* terminal fault, print info about the fault */ dev_err(pfdev->dev, "Unhandled Page fault in AS%d at VA 0x%016llX\n" @@ -368,8 +479,9 @@ int panfrost_mmu_init(struct panfrost_device *pfdev) if (irq <= 0) return -ENODEV; - err = devm_request_irq(pfdev->dev, irq, panfrost_mmu_irq_handler, - IRQF_SHARED, "mmu", pfdev); + err = devm_request_threaded_irq(pfdev->dev, irq, NULL, + panfrost_mmu_irq_handler, + IRQF_ONESHOT, "mmu", pfdev); if (err) { dev_err(pfdev->dev, "failed to request mmu irq"); diff --git a/include/uapi/drm/panfrost_drm.h b/include/uapi/drm/panfrost_drm.h index 17fb5d200f7a..9150dd75aad8 100644 --- a/include/uapi/drm/panfrost_drm.h +++ b/include/uapi/drm/panfrost_drm.h @@ -83,6 +83,7 @@ struct drm_panfrost_wait_bo { }; #define PANFROST_BO_NOEXEC 1 +#define PANFROST_BO_HEAP 2 /** * struct drm_panfrost_create_bo - ioctl argument for creating Panfrost BOs. From patchwork Thu Jul 25 01:10:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 169664 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp10935270ilk; Wed, 24 Jul 2019 18:10:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqw+q9hwlEF3uyYZSgo3ScihLKzZKv1ng+wXTtO6fdksXmXZj/Zi7TPsPs87ET4or/5zMW/z X-Received: by 2002:a63:607:: with SMTP id 7mr6864316pgg.240.1564017033101; Wed, 24 Jul 2019 18:10:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564017033; cv=none; d=google.com; s=arc-20160816; b=AHICHNjauSVPJ8vdVWQDvgsWW8C/W8D+iKVYRKoaCymPxV67BTPD7AWnBU+Zcr803s 6sXFmZcS2GwOgnWR5IsR+F5L8WifBxrVVMBpGMVTcORNqEt6iRlpKQ4OfCdKPoGy8va7 UYu70zpqZi4qCWMqeFqGMWW9Cy6ReE4m7QC7Y0nco8CPydLZu2vc6NB9moQU6xj35KyB YSMUp/dT0IJd7MyN9j3mNGqvscxGukUpFmnwge5yL5D6z342igA6onorePzLB557akTG le+EHJuuVp25QQdPwRulSA35USevZNYFq7XFescjWpNDdRVqdkSdQ8Xc4dXob4equReX kbEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:references:in-reply-to:message-id:date :subject:to:from:delivered-to; bh=3Rz8dAQxbUtJoPHymPGLRElA+A1B3DgvtdXkPpHI7dM=; b=o71eI+fH86/enmQOALywtXwuv+ri1/aOa75VOnWzgqnj/EvnbJFmb7jSqDqUh+i3oI XPJ/EUCnbx2aCczUhSBFLh/H5laplZuw8os/eT1BuWRgz6JhDwHeWmOcJRkZ51c5kEkJ UjnemvgDh6DcBBtD1OQhMdRV5QNmOx7HCFq0JMnSLxYMq5JYuOGzUKOIJOUYjsw6+z+Z XNPPojWvJnRDO8f9XQ1jZKAO9vEqyZN14QKb72bZE/mTEVAGXXYKTlW/I6ekPn0dS6DD gXzw98qRj95yqpodzzAP6aDQxJxZI2L3LNHfQXbpeLKjzoFAnAtSslQ6JtRBotpgLNx/ OnRA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [2610:10:20:722:a800:ff:fe36:1795]) by mx.google.com with ESMTPS id be3si15590894plb.383.2019.07.24.18.10.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 Jul 2019 18:10:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) client-ip=2610:10:20:722:a800:ff:fe36:1795; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F30FB6E4CF; Thu, 25 Jul 2019 01:10:31 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-io1-f66.google.com (mail-io1-f66.google.com [209.85.166.66]) by gabe.freedesktop.org (Postfix) with ESMTPS id B67A16E386 for ; Thu, 25 Jul 2019 01:10:15 +0000 (UTC) Received: by mail-io1-f66.google.com with SMTP id e20so63261766iob.9 for ; Wed, 24 Jul 2019 18:10:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2CdEvm+oRnTE1ZhDZPZZ4V4OiU5E9Xkf4wlrzQfNBQM=; b=GhchDEItgGnWWguDhNMs7VwWSNStQi91veWoX8tq3S6062kuLa6DSTu7xCzc1tZoLi /XX61dGgnM4x8HmL+Mx6EW2Dx8lTC02tl1NxQlPpQt5rZKIhukAz0b/HC6LyDblCY/S7 c18ieuh1l9y9uMxHbLHTS5NDUGBJ1VhcrPRTY5RT1woVPpxwluRFr5lkNPWkZcoPkA3W U3KdrfxHJ8e95z0aoB9WzTwoIlr3lSuiGMEpEjawADjhab2EQHOzqjms7KB7tzhQgLew qoXazuGUWODVp3fr31f4cSc8hSwgyCqyUOqiYMR9jq48OdrI8OxXaCwMZ4JjMt/W6Y4c +6tg== X-Gm-Message-State: APjAAAWCvtmcHsqS3DU1Id+CHIGjZLxJyBtBz7e6S7BlmstmJDAAAWr+ d8A6ZHIrjg/8NVRlgu2xUu6p5/k= X-Received: by 2002:a5d:8416:: with SMTP id i22mr54434529ion.248.1564017014746; Wed, 24 Jul 2019 18:10:14 -0700 (PDT) Received: from xps15.herring.priv ([64.188.179.254]) by smtp.googlemail.com with ESMTPSA id o7sm40675924ioo.81.2019.07.24.18.10.13 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 24 Jul 2019 18:10:14 -0700 (PDT) From: Rob Herring To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 7/7] drm/panfrost: Bump driver version to 1.1 Date: Wed, 24 Jul 2019 19:10:03 -0600 Message-Id: <20190725011003.30837-8-robh@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190725011003.30837-1-robh@kernel.org> References: <20190725011003.30837-1-robh@kernel.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tomeu Vizoso , Maxime Ripard , Sean Paul , Steven Price , David Airlie , Boris Brezillon , Alyssa Rosenzweig , Robin Murphy Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Increment the driver version to expose the new BO allocation flags. Cc: Tomeu Vizoso Cc: Boris Brezillon Cc: Robin Murphy Cc: Steven Price Cc: Alyssa Rosenzweig Signed-off-by: Rob Herring --- drivers/gpu/drm/panfrost/panfrost_drv.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/panfrost/panfrost_drv.c b/drivers/gpu/drm/panfrost/panfrost_drv.c index 46a6bec7a0f2..a6bef3b6da59 100644 --- a/drivers/gpu/drm/panfrost/panfrost_drv.c +++ b/drivers/gpu/drm/panfrost/panfrost_drv.c @@ -353,6 +353,11 @@ static const struct drm_ioctl_desc panfrost_drm_driver_ioctls[] = { DEFINE_DRM_GEM_SHMEM_FOPS(panfrost_drm_driver_fops); +/* + * Panfrost driver version: + * - 1.0 - initial interface + * - 1.1 - adds HEAP and NOEXEC flags for CREATE_BO + */ static struct drm_driver panfrost_drm_driver = { .driver_features = DRIVER_RENDER | DRIVER_GEM | DRIVER_SYNCOBJ, .open = panfrost_open, @@ -364,7 +369,7 @@ static struct drm_driver panfrost_drm_driver = { .desc = "panfrost DRM", .date = "20180908", .major = 1, - .minor = 0, + .minor = 1, .gem_create_object = panfrost_gem_create_object, .prime_handle_to_fd = drm_gem_prime_handle_to_fd,