From patchwork Tue Jul 16 17:43:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 11046561 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5056E138D for ; Tue, 16 Jul 2019 17:45:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 37B6228676 for ; Tue, 16 Jul 2019 17:45:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2779F28694; Tue, 16 Jul 2019 17:45:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D932328676 for ; Tue, 16 Jul 2019 17:45:51 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 01DA36E11C; Tue, 16 Jul 2019 17:45:51 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2E6636E11C; Tue, 16 Jul 2019 17:45:50 +0000 (UTC) Received: by mail-pl1-x644.google.com with SMTP id ay6so10477738plb.9; Tue, 16 Jul 2019 10:45:50 -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:mime-version :content-transfer-encoding; bh=Xhvxxodyt4FVnA+Q4PptUiZxNmKTKZXnvXrsa2hJq/o=; b=RgZPr2vOgz0bzB7QvnTeSrBToqw/XDWpsx1O7tNGtEkW51en7iaOMXkgsuLg7+z+My o67DPI2+yRpIqSUBAWqowcHElo7DMqMYPP655rtkMcX7IZbtJL93lk9vWU22l72j2ore 9BiwzUFWyMI2YG9bAwzggSM1mQy67BuRg9fiTqORBRjfwHgeI715sZxt+8hnT0+OvXD9 bBCIht46LCLPLErFnstmmeABDWSn1ktaQmynzFnX2n2lnrP7CTfYCjSGYxBOvuPmrqYl 3W04bbrQ2GH7xoN1ZXa9GfmYnD6eWT8Fk8wslukLUDIL1i76g9SJmtGDjvG+OcGUbb+F DtPA== X-Gm-Message-State: APjAAAV8+7IYNxlHbu0ryviUlNExylKbmLyCDpVnWJffI1JNlqYVTQXR 3I0VGKhxHIAeIiERRXHMcDYIMojOMHk= X-Google-Smtp-Source: APXvYqyvLxSlL5GDt6wdl98KfA3lI5LIyr/lONf5ccilGqUx3VHCMUUVQyBqHX3SfEBLwglwuoop9A== X-Received: by 2002:a17:902:3081:: with SMTP id v1mr38149628plb.169.1563299149369; Tue, 16 Jul 2019 10:45:49 -0700 (PDT) Received: from localhost ([100.118.89.203]) by smtp.gmail.com with ESMTPSA id g62sm21681297pje.11.2019.07.16.10.45.48 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 16 Jul 2019 10:45:48 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Date: Tue, 16 Jul 2019 10:43:21 -0700 Message-Id: <20190716174331.7371-1-robdclark@gmail.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Xhvxxodyt4FVnA+Q4PptUiZxNmKTKZXnvXrsa2hJq/o=; b=mlimn4TLRvW/lqjE5coN8thyz8i9X1tiCMaNdAFPB/0qvOyooTYEfXXXG4+yFGsgDW +YfqxLFliWAsIcSE14CkOb6NQYkgIreCHQOSuiTEVluUu6oZgsfO4ZxXxNpA0Nob9avD Ts1pCcQaQMALo0p6x0WOMlXoEKAIlo/vxHCbaOs5UjJQYEx/S402jWpC5JAjchqkbIMn 1+gGiHhCvzyfPrVegyPK/FEhwzEUfWClX2kBC/vQZOkWuXUbqI/s2WUZcvJRwBfbfANO xiOeWvdsPLkBhRbiKEVwmjyWo5D1Xb5+McYTgNjFX0aMeZyJp0XPn0UQNqRpGtg8UwLM V3zQ== Subject: [Intel-gfx] [PATCH v2 1/3] drm/gem: don't force writecombine mmap'ing X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rob Clark , Maxime Ripard , Intel Graphics Development , linux-kernel@vger.kernel.org, David Airlie Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Rob Clark The driver should be in control of this. Signed-off-by: Rob Clark --- It is possible that this was masking bugs (ie. not setting appropriate pgprot) in drivers. I don't have a particularly good idea for tracking those down (since I don't have the hw for most drivers). Unless someone has a better idea, maybe land this and let driver maintainers fix any potential fallout in their drivers? This is necessary for the last patch to fix VGEM brokenness on arm. drivers/gpu/drm/drm_gem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index 8a55f71325b1..7d6242cc69f2 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -1110,7 +1110,7 @@ int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size, vma->vm_flags |= VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP; vma->vm_private_data = obj; - vma->vm_page_prot = pgprot_writecombine(vm_get_page_prot(vma->vm_flags)); + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot); /* Take a ref for this mapping of the object, so that the fault From patchwork Tue Jul 16 17:43:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 11046567 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 66B206C5 for ; Tue, 16 Jul 2019 17:48:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E8BC28694 for ; Tue, 16 Jul 2019 17:48:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4111A2869D; Tue, 16 Jul 2019 17:48:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 721EE28694 for ; Tue, 16 Jul 2019 17:48:18 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 76F676E162; Tue, 16 Jul 2019 17:48:15 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by gabe.freedesktop.org (Postfix) with ESMTPS id BD6F56E162; Tue, 16 Jul 2019 17:48:13 +0000 (UTC) Received: by mail-pf1-x441.google.com with SMTP id r1so9449237pfq.12; Tue, 16 Jul 2019 10:48: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=9g4Md16DCAxWYz0fYzP1PJhZRgUGpb8Cny7KRqZ/Ew0=; b=OdmfVT9TxjZN/+b/Tr3OwVT4N2fr43aXWbnLTgdwTcewJX6zeRxtogwaJzLGlDHNqB I0wtT1zM8v9maULfsOXaRewuPznXE3JMxCvDKmsNvc5SMPx5FxLxqWI8DUPWMT2JRxWt BMf2O+XUL8UzutdYx6ysE9m6KZ4g4P2EyHv8LDrlBu11d0nit5Qpi5hdBoRrNh++Wn5D ykS1XYEoXoPtzJ+po3Q3QtkmFFapox+IHEzfmbKNKjFmvExCcF1X/+kX+dikNfUfC7wk GrrouPdvfVzgo9RRWHUOs/IAnGOcsTsODC8LTKWUjpQjfyfNPg6ZbKxzQmHNOYKRIKbv jatQ== X-Gm-Message-State: APjAAAXijCYS6qMMdKZJlM1qg+xgZB9syIa0Z+zPw1zLhWf3saqNxE5X 0MTOwyewos3FRjrYw5eBEwiby/vZAYkJgw== X-Google-Smtp-Source: APXvYqx8QX41rDX34LIUzD8Oec4VxbCKn35kpEbgw14+HdY+DpTKpNjb9u2WDeygpdvc6XYdJUsJGA== X-Received: by 2002:a65:654f:: with SMTP id a15mr34676339pgw.73.1563299292765; Tue, 16 Jul 2019 10:48:12 -0700 (PDT) Received: from localhost ([100.118.89.203]) by smtp.gmail.com with ESMTPSA id 65sm21825749pff.148.2019.07.16.10.48.11 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 16 Jul 2019 10:48:12 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Date: Tue, 16 Jul 2019 10:43:22 -0700 Message-Id: <20190716174331.7371-2-robdclark@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190716174331.7371-1-robdclark@gmail.com> References: <20190716174331.7371-1-robdclark@gmail.com> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9g4Md16DCAxWYz0fYzP1PJhZRgUGpb8Cny7KRqZ/Ew0=; b=Z6WB3pngMQtPLpQxxvQac9oM2e37ImNX+vxNX5iUn6gjv6OFmkKv94mojBUEDA5+Ai l6f2AD+8Wz9XIlT4OsAWTS62vaRdSv9vRbJqkFrYei8D7SN9s56O2xzFU4hQRfskxete ZPyiv6JyI6+ILOrGa+FDay5VrMQOjghQhLiIadAewHe+CuemnJprp2LRfOdXyf5W6Qah bhqIp5agYmDSR0CHaF3W7m+9zK50TGWwbsN1NoW4S3aKZeexyyWRxaR6zlct5d45+7u3 Nq/9ZG8nX1IJkWgeIv02RL2hUB2Qma6O4FKm1Z4nBckGfBJGkowW0x/CamlTguOrywpN bVLw== Subject: [Intel-gfx] [PATCH v2 2/3] drm: plumb attaching dev thru to prime_pin/unpin X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eric Biggers , Maxime Ripard , nouveau@lists.freedesktop.org, Gerd Hoffmann , Emil Velikov , Rob Clark , "David \(ChunMing\) Zhou" , amd-gfx@lists.freedesktop.org, David Airlie , Ben Skeggs , Russell King , Dave Airlie , Laura Abbott , Deepak Sharma , Thomas Zimmermann , linux-arm-msm@vger.kernel.org, Intel Graphics Development , etnaviv@lists.freedesktop.org, spice-devel@lists.freedesktop.org, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Alex Deucher , freedreno@lists.freedesktop.org, =?utf-8?q?Christian_K=C3=B6nig?= , Lucas Stach Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Rob Clark Needed in the following patch for cache operations. Signed-off-by: Rob Clark --- drivers/gpu/drm/drm_gem.c | 10 ++++++---- drivers/gpu/drm/drm_gem_vram_helper.c | 6 ++++-- drivers/gpu/drm/drm_prime.c | 4 ++-- drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c | 4 ++-- drivers/gpu/drm/msm/msm_drv.h | 4 ++-- drivers/gpu/drm/msm/msm_gem_prime.c | 4 ++-- drivers/gpu/drm/nouveau/nouveau_gem.h | 4 ++-- drivers/gpu/drm/nouveau/nouveau_prime.c | 4 ++-- drivers/gpu/drm/qxl/qxl_prime.c | 4 ++-- drivers/gpu/drm/radeon/radeon_prime.c | 4 ++-- drivers/gpu/drm/vboxvideo/vbox_prime.c | 4 ++-- drivers/gpu/drm/vgem/vgem_drv.c | 4 ++-- include/drm/drm_drv.h | 4 ++-- include/drm/drm_gem.h | 4 ++-- include/drm/drm_gem_vram_helper.h | 4 ++-- 15 files changed, 36 insertions(+), 32 deletions(-) diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index 7d6242cc69f2..0a2645769624 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -1219,18 +1219,19 @@ void drm_gem_print_info(struct drm_printer *p, unsigned int indent, /** * drm_gem_pin - Pin backing buffer in memory * @obj: GEM object + * @dev: the device the buffer is being pinned for * * Make sure the backing buffer is pinned in memory. * * Returns: * 0 on success or a negative error code on failure. */ -int drm_gem_pin(struct drm_gem_object *obj) +int drm_gem_pin(struct drm_gem_object *obj, struct device *dev) { if (obj->funcs && obj->funcs->pin) return obj->funcs->pin(obj); else if (obj->dev->driver->gem_prime_pin) - return obj->dev->driver->gem_prime_pin(obj); + return obj->dev->driver->gem_prime_pin(obj, dev); else return 0; } @@ -1239,15 +1240,16 @@ EXPORT_SYMBOL(drm_gem_pin); /** * drm_gem_unpin - Unpin backing buffer from memory * @obj: GEM object + * @dev: the device the buffer is being pinned for * * Relax the requirement that the backing buffer is pinned in memory. */ -void drm_gem_unpin(struct drm_gem_object *obj) +void drm_gem_unpin(struct drm_gem_object *obj, struct device *dev) { if (obj->funcs && obj->funcs->unpin) obj->funcs->unpin(obj); else if (obj->dev->driver->gem_prime_unpin) - obj->dev->driver->gem_prime_unpin(obj); + obj->dev->driver->gem_prime_unpin(obj, dev); } EXPORT_SYMBOL(drm_gem_unpin); diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c b/drivers/gpu/drm/drm_gem_vram_helper.c index 4de782ca26b2..62fafec93948 100644 --- a/drivers/gpu/drm/drm_gem_vram_helper.c +++ b/drivers/gpu/drm/drm_gem_vram_helper.c @@ -548,7 +548,8 @@ EXPORT_SYMBOL(drm_gem_vram_driver_dumb_mmap_offset); * 0 on success, or * a negative errno code otherwise. */ -int drm_gem_vram_driver_gem_prime_pin(struct drm_gem_object *gem) +int drm_gem_vram_driver_gem_prime_pin(struct drm_gem_object *gem, + struct device *dev) { struct drm_gem_vram_object *gbo = drm_gem_vram_of_gem(gem); @@ -569,7 +570,8 @@ EXPORT_SYMBOL(drm_gem_vram_driver_gem_prime_pin); Implements &struct drm_driver.gem_prime_unpin * @gem: The GEM object to unpin */ -void drm_gem_vram_driver_gem_prime_unpin(struct drm_gem_object *gem) +void drm_gem_vram_driver_gem_prime_unpin(struct drm_gem_object *gem, + struct device *dev) { struct drm_gem_vram_object *gbo = drm_gem_vram_of_gem(gem); diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c index d0c01318076b..505893cfac8e 100644 --- a/drivers/gpu/drm/drm_prime.c +++ b/drivers/gpu/drm/drm_prime.c @@ -196,7 +196,7 @@ int drm_gem_map_attach(struct dma_buf *dma_buf, { struct drm_gem_object *obj = dma_buf->priv; - return drm_gem_pin(obj); + return drm_gem_pin(obj, attach->dev); } EXPORT_SYMBOL(drm_gem_map_attach); @@ -213,7 +213,7 @@ void drm_gem_map_detach(struct dma_buf *dma_buf, { struct drm_gem_object *obj = dma_buf->priv; - drm_gem_unpin(obj); + drm_gem_unpin(obj, attach->dev); } EXPORT_SYMBOL(drm_gem_map_detach); diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c b/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c index 00e8b6a817e3..44385d590aa7 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c @@ -43,7 +43,7 @@ int etnaviv_gem_prime_mmap(struct drm_gem_object *obj, return etnaviv_obj->ops->mmap(etnaviv_obj, vma); } -int etnaviv_gem_prime_pin(struct drm_gem_object *obj) +int etnaviv_gem_prime_pin(struct drm_gem_object *obj, struct device *dev) { if (!obj->import_attach) { struct etnaviv_gem_object *etnaviv_obj = to_etnaviv_bo(obj); @@ -55,7 +55,7 @@ int etnaviv_gem_prime_pin(struct drm_gem_object *obj) return 0; } -void etnaviv_gem_prime_unpin(struct drm_gem_object *obj) +void etnaviv_gem_prime_unpin(struct drm_gem_object *obj, struct device *dev) { if (!obj->import_attach) { struct etnaviv_gem_object *etnaviv_obj = to_etnaviv_bo(obj); diff --git a/drivers/gpu/drm/msm/msm_drv.h b/drivers/gpu/drm/msm/msm_drv.h index 9ada948f6b01..6f8f6df9c289 100644 --- a/drivers/gpu/drm/msm/msm_drv.h +++ b/drivers/gpu/drm/msm/msm_drv.h @@ -298,8 +298,8 @@ void msm_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr); int msm_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma); struct drm_gem_object *msm_gem_prime_import_sg_table(struct drm_device *dev, struct dma_buf_attachment *attach, struct sg_table *sg); -int msm_gem_prime_pin(struct drm_gem_object *obj); -void msm_gem_prime_unpin(struct drm_gem_object *obj); +int msm_gem_prime_pin(struct drm_gem_object *obj, struct device *dev); +void msm_gem_prime_unpin(struct drm_gem_object *obj, struct device *dev); void *msm_gem_get_vaddr(struct drm_gem_object *obj); void *msm_gem_get_vaddr_active(struct drm_gem_object *obj); void msm_gem_put_vaddr(struct drm_gem_object *obj); diff --git a/drivers/gpu/drm/msm/msm_gem_prime.c b/drivers/gpu/drm/msm/msm_gem_prime.c index 60bb290700ce..8e0ddf5c9460 100644 --- a/drivers/gpu/drm/msm/msm_gem_prime.c +++ b/drivers/gpu/drm/msm/msm_gem_prime.c @@ -58,14 +58,14 @@ struct drm_gem_object *msm_gem_prime_import_sg_table(struct drm_device *dev, return msm_gem_import(dev, attach->dmabuf, sg); } -int msm_gem_prime_pin(struct drm_gem_object *obj) +int msm_gem_prime_pin(struct drm_gem_object *obj, struct device *dev) { if (!obj->import_attach) msm_gem_get_pages(obj); return 0; } -void msm_gem_prime_unpin(struct drm_gem_object *obj) +void msm_gem_prime_unpin(struct drm_gem_object *obj, struct device *dev) { if (!obj->import_attach) msm_gem_put_pages(obj); diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.h b/drivers/gpu/drm/nouveau/nouveau_gem.h index fe39998f65cc..91dcf89138f1 100644 --- a/drivers/gpu/drm/nouveau/nouveau_gem.h +++ b/drivers/gpu/drm/nouveau/nouveau_gem.h @@ -32,9 +32,9 @@ extern int nouveau_gem_ioctl_cpu_fini(struct drm_device *, void *, extern int nouveau_gem_ioctl_info(struct drm_device *, void *, struct drm_file *); -extern int nouveau_gem_prime_pin(struct drm_gem_object *); +extern int nouveau_gem_prime_pin(struct drm_gem_object *, struct device *); struct reservation_object *nouveau_gem_prime_res_obj(struct drm_gem_object *); -extern void nouveau_gem_prime_unpin(struct drm_gem_object *); +extern void nouveau_gem_prime_unpin(struct drm_gem_object *, struct device *); extern struct sg_table *nouveau_gem_prime_get_sg_table(struct drm_gem_object *); extern struct drm_gem_object *nouveau_gem_prime_import_sg_table( struct drm_device *, struct dma_buf_attachment *, struct sg_table *); diff --git a/drivers/gpu/drm/nouveau/nouveau_prime.c b/drivers/gpu/drm/nouveau/nouveau_prime.c index 1fefc93af1d7..dec2d5e37b34 100644 --- a/drivers/gpu/drm/nouveau/nouveau_prime.c +++ b/drivers/gpu/drm/nouveau/nouveau_prime.c @@ -88,7 +88,7 @@ struct drm_gem_object *nouveau_gem_prime_import_sg_table(struct drm_device *dev, return &nvbo->gem; } -int nouveau_gem_prime_pin(struct drm_gem_object *obj) +int nouveau_gem_prime_pin(struct drm_gem_object *obj, struct device *dev) { struct nouveau_bo *nvbo = nouveau_gem_object(obj); int ret; @@ -101,7 +101,7 @@ int nouveau_gem_prime_pin(struct drm_gem_object *obj) return 0; } -void nouveau_gem_prime_unpin(struct drm_gem_object *obj) +void nouveau_gem_prime_unpin(struct drm_gem_object *obj, struct device *dev) { struct nouveau_bo *nvbo = nouveau_gem_object(obj); diff --git a/drivers/gpu/drm/qxl/qxl_prime.c b/drivers/gpu/drm/qxl/qxl_prime.c index 7d3816fca5a8..21e9b44eb2e4 100644 --- a/drivers/gpu/drm/qxl/qxl_prime.c +++ b/drivers/gpu/drm/qxl/qxl_prime.c @@ -28,14 +28,14 @@ /* Empty Implementations as there should not be any other driver for a virtual * device that might share buffers with qxl */ -int qxl_gem_prime_pin(struct drm_gem_object *obj) +int qxl_gem_prime_pin(struct drm_gem_object *obj, struct device *dev) { struct qxl_bo *bo = gem_to_qxl_bo(obj); return qxl_bo_pin(bo); } -void qxl_gem_prime_unpin(struct drm_gem_object *obj) +void qxl_gem_prime_unpin(struct drm_gem_object *obj, struct device *dev) { struct qxl_bo *bo = gem_to_qxl_bo(obj); diff --git a/drivers/gpu/drm/radeon/radeon_prime.c b/drivers/gpu/drm/radeon/radeon_prime.c index d3a5bea9a2c5..2d3eadcf0f2d 100644 --- a/drivers/gpu/drm/radeon/radeon_prime.c +++ b/drivers/gpu/drm/radeon/radeon_prime.c @@ -83,7 +83,7 @@ struct drm_gem_object *radeon_gem_prime_import_sg_table(struct drm_device *dev, return &bo->gem_base; } -int radeon_gem_prime_pin(struct drm_gem_object *obj) +int radeon_gem_prime_pin(struct drm_gem_object *obj, struct device *dev) { struct radeon_bo *bo = gem_to_radeon_bo(obj); int ret = 0; @@ -101,7 +101,7 @@ int radeon_gem_prime_pin(struct drm_gem_object *obj) return ret; } -void radeon_gem_prime_unpin(struct drm_gem_object *obj) +void radeon_gem_prime_unpin(struct drm_gem_object *obj, struct device *dev) { struct radeon_bo *bo = gem_to_radeon_bo(obj); int ret = 0; diff --git a/drivers/gpu/drm/vboxvideo/vbox_prime.c b/drivers/gpu/drm/vboxvideo/vbox_prime.c index 702b1aa53494..ad6de9a41950 100644 --- a/drivers/gpu/drm/vboxvideo/vbox_prime.c +++ b/drivers/gpu/drm/vboxvideo/vbox_prime.c @@ -13,13 +13,13 @@ * device that might share buffers with vboxvideo */ -int vbox_gem_prime_pin(struct drm_gem_object *obj) +int vbox_gem_prime_pin(struct drm_gem_object *obj, struct device *dev) { WARN_ONCE(1, "not implemented"); return -ENODEV; } -void vbox_gem_prime_unpin(struct drm_gem_object *obj) +void vbox_gem_prime_unpin(struct drm_gem_object *obj, struct device *dev) { WARN_ONCE(1, "not implemented"); } diff --git a/drivers/gpu/drm/vgem/vgem_drv.c b/drivers/gpu/drm/vgem/vgem_drv.c index 11a8f99ba18c..a179e962b79e 100644 --- a/drivers/gpu/drm/vgem/vgem_drv.c +++ b/drivers/gpu/drm/vgem/vgem_drv.c @@ -307,7 +307,7 @@ static void vgem_unpin_pages(struct drm_vgem_gem_object *bo) mutex_unlock(&bo->pages_lock); } -static int vgem_prime_pin(struct drm_gem_object *obj) +static int vgem_prime_pin(struct drm_gem_object *obj, struct device *dev) { struct drm_vgem_gem_object *bo = to_vgem_bo(obj); long n_pages = obj->size >> PAGE_SHIFT; @@ -325,7 +325,7 @@ static int vgem_prime_pin(struct drm_gem_object *obj) return 0; } -static void vgem_prime_unpin(struct drm_gem_object *obj) +static void vgem_prime_unpin(struct drm_gem_object *obj, struct device *dev) { struct drm_vgem_gem_object *bo = to_vgem_bo(obj); diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h index 68ca736c548d..6a9489b9532f 100644 --- a/include/drm/drm_drv.h +++ b/include/drm/drm_drv.h @@ -584,8 +584,8 @@ struct drm_driver { */ struct drm_gem_object * (*gem_prime_import)(struct drm_device *dev, struct dma_buf *dma_buf); - int (*gem_prime_pin)(struct drm_gem_object *obj); - void (*gem_prime_unpin)(struct drm_gem_object *obj); + int (*gem_prime_pin)(struct drm_gem_object *obj, struct device *dev); + void (*gem_prime_unpin)(struct drm_gem_object *obj, struct device *dev); struct reservation_object * (*gem_prime_res_obj)( struct drm_gem_object *obj); struct sg_table *(*gem_prime_get_sg_table)(struct drm_gem_object *obj); diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h index 5047c7ee25f5..ebd12be354d2 100644 --- a/include/drm/drm_gem.h +++ b/include/drm/drm_gem.h @@ -401,8 +401,8 @@ int drm_gem_dumb_destroy(struct drm_file *file, struct drm_device *dev, uint32_t handle); -int drm_gem_pin(struct drm_gem_object *obj); -void drm_gem_unpin(struct drm_gem_object *obj); +int drm_gem_pin(struct drm_gem_object *obj, struct device *dev); +void drm_gem_unpin(struct drm_gem_object *obj, struct device *dev); void *drm_gem_vmap(struct drm_gem_object *obj); void drm_gem_vunmap(struct drm_gem_object *obj, void *vaddr); diff --git a/include/drm/drm_gem_vram_helper.h b/include/drm/drm_gem_vram_helper.h index 9581ea0a4f7e..33556e157202 100644 --- a/include/drm/drm_gem_vram_helper.h +++ b/include/drm/drm_gem_vram_helper.h @@ -133,8 +133,8 @@ int drm_gem_vram_driver_dumb_mmap_offset(struct drm_file *file, * PRIME helpers for struct drm_driver */ -int drm_gem_vram_driver_gem_prime_pin(struct drm_gem_object *obj); -void drm_gem_vram_driver_gem_prime_unpin(struct drm_gem_object *obj); +int drm_gem_vram_driver_gem_prime_pin(struct drm_gem_object *obj, struct device *dev); +void drm_gem_vram_driver_gem_prime_unpin(struct drm_gem_object *obj, struct device *dev); void *drm_gem_vram_driver_gem_prime_vmap(struct drm_gem_object *obj); void drm_gem_vram_driver_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr); From patchwork Tue Jul 16 17:43:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 11046573 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CE3A76C5 for ; Tue, 16 Jul 2019 17:51:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B5D3428694 for ; Tue, 16 Jul 2019 17:51:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A6CF828681; Tue, 16 Jul 2019 17:51:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 417C928681 for ; Tue, 16 Jul 2019 17:51:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9EE1B6E16D; Tue, 16 Jul 2019 17:51:38 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by gabe.freedesktop.org (Postfix) with ESMTPS id 17C656E16D; Tue, 16 Jul 2019 17:51:38 +0000 (UTC) Received: by mail-pl1-x644.google.com with SMTP id 4so3531663pld.10; Tue, 16 Jul 2019 10:51:38 -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=UiLaRqQi+KN5P/cP6egPb78oRpeEozQB/t5Ad8Uztd4=; b=sEAAPG2MjtWLaBOmuz6d3L8QoVd0abF8irrZyTFrDgLYFZAPTtTrFz8axbtknWFfPx +IPloko84Q2rB/ebRzPo98H1CLbZFurtsAnl7XQ3Lxy0Cfw8WuBhRYwt7H8UTt4Z7U39 1KmOarMzIMTAVDYpXuUA5YeR9JHBRIscbvr0aXWuDVOb+EzDnrWUBPIjlZdfwglL2ss3 Bg/M2RbFnLSYirltwbO8Xnk5M4FPJ+4E2hRMpOu9cZuEYlPBMRBNGPmLyrwozGX/T305 fkYP6OIN4Rg9GVr8zgpAhcxVZhFmJ3Jnu0xo5PKGCvDx+cAj1RgQp/uSuz2NL9tHAV6j QdWQ== X-Gm-Message-State: APjAAAUwvaWjwsC5rO3N9wNTvbVaByZIE50fpjS+Bl1XbxQO2z58349U 1TVSde5yJsulU8qS3iIbx457pMbVe/I= X-Google-Smtp-Source: APXvYqzFKslRA486uFuMA8KNQnLtCFo8RE9hfK9nYj7zlrGlay5yFSTuwTPyyWNjseq42zgOr7Agbw== X-Received: by 2002:a17:902:b20c:: with SMTP id t12mr37712885plr.285.1563299497373; Tue, 16 Jul 2019 10:51:37 -0700 (PDT) Received: from localhost ([100.118.89.203]) by smtp.gmail.com with ESMTPSA id g8sm2243238pgk.1.2019.07.16.10.51.36 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 16 Jul 2019 10:51:36 -0700 (PDT) From: Rob Clark To: dri-devel@lists.freedesktop.org Date: Tue, 16 Jul 2019 10:43:23 -0700 Message-Id: <20190716174331.7371-3-robdclark@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190716174331.7371-1-robdclark@gmail.com> References: <20190716174331.7371-1-robdclark@gmail.com> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UiLaRqQi+KN5P/cP6egPb78oRpeEozQB/t5Ad8Uztd4=; b=hE+P9H/tFUK8qpoBOYsg1V+ORebpPk0bjpfOrC11X3dwjJrq2UGU4kOsytw14cbTLr wOCN+LCKewt/JS2Z7zT+JsuLCfkk4iUXQE8zLGFD5oXwY1X2j/uwAXBu3t6Q4Bnvn1Wx vFmYwvPOkVkNb6SrLMRO9kIvJjMAHedXhrxRwMH2aOEKlBKWbDH52oySlExA8sO0L5qN Z3Y5nlT3eMF64tjLSabZV4HyjvDWAdJhcAkwUJkcqINqNFuuzyiWRzNwT8mlUVt6FN25 WCb2Gw3g9txNOZzeaUw2/X1747vo9vF+zVUp2X9B2xpJwRDDKucIlInL8yT74rg4dCQj Rqng== Subject: [Intel-gfx] [PATCH v2 3/3] drm/vgem: use normal cached mmap'ings X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rob Clark , Deepak Sharma , Thomas Zimmermann , Eric Biggers , David Airlie , Intel Graphics Development , linux-kernel@vger.kernel.org, Emil Velikov Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Rob Clark Since there is no real device associated with VGEM, it is impossible to end up with appropriate dev->dma_ops, meaning that we have no way to invalidate the shmem pages allocated by VGEM. So, at least on platforms without drm_cflush_pages(), we end up with corruption when cache lines from previous usage of VGEM bo pages get evicted to memory. The only sane option is to use cached mappings. Signed-off-by: Rob Clark --- drivers/gpu/drm/vgem/vgem_drv.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/vgem/vgem_drv.c b/drivers/gpu/drm/vgem/vgem_drv.c index a179e962b79e..b6071a466b92 100644 --- a/drivers/gpu/drm/vgem/vgem_drv.c +++ b/drivers/gpu/drm/vgem/vgem_drv.c @@ -259,9 +259,6 @@ static int vgem_mmap(struct file *filp, struct vm_area_struct *vma) if (ret) return ret; - /* Keep the WC mmaping set by drm_gem_mmap() but our pages - * are ordinary and not special. - */ vma->vm_flags = flags | VM_DONTEXPAND | VM_DONTDUMP; return 0; } @@ -310,17 +307,17 @@ static void vgem_unpin_pages(struct drm_vgem_gem_object *bo) static int vgem_prime_pin(struct drm_gem_object *obj, struct device *dev) { struct drm_vgem_gem_object *bo = to_vgem_bo(obj); - long n_pages = obj->size >> PAGE_SHIFT; + long i, n_pages = obj->size >> PAGE_SHIFT; struct page **pages; pages = vgem_pin_pages(bo); if (IS_ERR(pages)) return PTR_ERR(pages); - /* Flush the object from the CPU cache so that importers can rely - * on coherent indirect access via the exported dma-address. - */ - drm_clflush_pages(pages, n_pages); + for (i = 0; i < n_pages; i++) { + dma_sync_single_for_device(dev, page_to_phys(pages[i]), + PAGE_SIZE, DMA_BIDIRECTIONAL); + } return 0; } @@ -328,6 +325,13 @@ static int vgem_prime_pin(struct drm_gem_object *obj, struct device *dev) static void vgem_prime_unpin(struct drm_gem_object *obj, struct device *dev) { struct drm_vgem_gem_object *bo = to_vgem_bo(obj); + long i, n_pages = obj->size >> PAGE_SHIFT; + struct page **pages = bo->pages; + + for (i = 0; i < n_pages; i++) { + dma_sync_single_for_cpu(dev, page_to_phys(pages[i]), + PAGE_SIZE, DMA_BIDIRECTIONAL); + } vgem_unpin_pages(bo); } @@ -382,7 +386,7 @@ static void *vgem_prime_vmap(struct drm_gem_object *obj) if (IS_ERR(pages)) return NULL; - return vmap(pages, n_pages, 0, pgprot_writecombine(PAGE_KERNEL)); + return vmap(pages, n_pages, 0, PAGE_KERNEL); } static void vgem_prime_vunmap(struct drm_gem_object *obj, void *vaddr) @@ -411,7 +415,7 @@ static int vgem_prime_mmap(struct drm_gem_object *obj, fput(vma->vm_file); vma->vm_file = get_file(obj->filp); vma->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP; - vma->vm_page_prot = pgprot_writecombine(vm_get_page_prot(vma->vm_flags)); + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags); return 0; }