From patchwork Thu Aug 8 22:21:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 170866 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp9165182ile; Thu, 8 Aug 2019 15:22:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqzqiZ/aNypDfOlekjR8Ng1FA7NaKHDrDUl7Za155BkeVp6+4XkxIzW73Ziwd9lvGHZ2WpiE X-Received: by 2002:a17:902:aa41:: with SMTP id c1mr15780156plr.201.1565302929086; Thu, 08 Aug 2019 15:22:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565302929; cv=none; d=google.com; s=arc-20160816; b=WHGI1l+3DzouRJtA0A8FOPRQ7Vqgml6wMh6tbho0eTuE9RxMwLdq2erhEdSlFGOfde dN7XE06x7iCxh35a7yD1Un8BwU8xEs72RcxkexthmNxCE5Lb6qKR49hwlyI7CAyFUTmM u4RUfKBi3JaUUfT5AwDLqTfdsVffbTHcO3EApoiBj+eU8tnuk+/dKsYXFKmtZkuiZcyK Si7NRt65yuym8AFBjbpN1PUfO7zb7LK64NnFZq16vDc2eZHwF/tiHqWNImcTwqDIa9L4 0HD0WTjQnfgsFmmn9mfLr3EfSekWpkkVe3S8dC/x+1c+Ltn1xVJuIqG1nePuk8cV6C1S MgSQ== 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=S9pFbrG9QU871bkAhbR+T6iE3jCBamQbHsmjO3LfTZw=; b=x3pzl0CRkVDxpR7l+9MSPCRmdHcqUvOR7MpBILkPd4l4TtNIf5yvGLL0jFwOuJ9KTR KutAstvMJynlyWoi+wov9WnGjjsN3WhUuNMEmW+TI1UsDjkWdq02kAJQJFGpP0/ky7PM ECUvybF70ipMSXP7wbC20GBebd1eMj15yLdRayYrcX990tV0r7Q7rI326wm7CBL1lw9b q8todV566tniigrBgpWlb00uOUuxZ6rT+5C6oIZ3STTxGgP/+flEIhewV+srCsN0qEIc jxykdaQOvD74ebG0TFclZVubq8yQ+9mSbGdG/LP4GDsiit4FySJmBU5oyNaLert5idHg Vd+A== 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 a6si48450926pla.259.2019.08.08.15.22.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 08 Aug 2019 15:22:09 -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 9E12D6ECCD; Thu, 8 Aug 2019 22:22:06 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ot1-f65.google.com (mail-ot1-f65.google.com [209.85.210.65]) by gabe.freedesktop.org (Postfix) with ESMTPS id 78CAA6ECCD for ; Thu, 8 Aug 2019 22:22:04 +0000 (UTC) Received: by mail-ot1-f65.google.com with SMTP id l15so67857730oth.7 for ; Thu, 08 Aug 2019 15:22:04 -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=T+bEnEpkz+ZRgimT11B8n1cZQnPJ56dXCRl4mSO81UA=; b=k0vUGxpn8egUs7jS0u4o3GPbRo29eUVz3PfW4wM0q0Nwtfqyix/e+7t01OhB+NUBWk EDcCWW8/WRO1mHIH7/22TDD1nC72G+VhFGcopKJQxX9ltcfon6iiaJ3447UdOPYnho0z SyHQWIrY/WpJPZWAZ02nDLcKFGfOPvAiQgifEnEaqbJdN+6W8ihk+UVxK4JL8GkGX3AR xQBoHfzdR/+83xffbByc8+oppGoPXUIoGu9bDT3ZRb2Hj4kMtGL/GeDhRnB+JosnOc+Q /G1iHcDNL5w9W7SQEKm+NN3GafxmJEfRX+qtJe4SSIJhv8Bn8zZG76hhCSS8B4I/7r7f 4gbg== X-Gm-Message-State: APjAAAUCI8zRa4YtKeiZbGgXv/v7CYZnE/BPnJb3Le+mVHybudChLk16 Im+mUIV9xb+wQpqo9s2qbGBVTF8= X-Received: by 2002:a5d:924e:: with SMTP id e14mr16640982iol.215.1565302923477; Thu, 08 Aug 2019 15:22:03 -0700 (PDT) Received: from xps15.herring.priv ([64.188.179.254]) by smtp.googlemail.com with ESMTPSA id i4sm118528553iog.31.2019.08.08.15.22.02 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 08 Aug 2019 15:22:03 -0700 (PDT) From: Rob Herring To: dri-devel@lists.freedesktop.org Subject: [PATCH v4 1/9] drm/gem: Allow sparsely populated page arrays in drm_gem_put_pages Date: Thu, 8 Aug 2019 16:21:52 -0600 Message-Id: <20190808222200.13176-2-robh@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190808222200.13176-1-robh@kernel.org> References: <20190808222200.13176-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 , Robin Murphy , Steven Price , David Airlie , Boris Brezillon , Alyssa Rosenzweig , Sean Paul 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 Reviewed-by: Steven Price Acked-by: Alyssa Rosenzweig Signed-off-by: Rob Herring --- drivers/gpu/drm/drm_gem.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index afc38cece3f5..a2dd198177f2 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 Aug 8 22:21:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 170867 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp9165218ile; Thu, 8 Aug 2019 15:22:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqwBtdKNjsGIYxsMkEH7pz5IqVYAlirw5JOOc1BU1ww7+Yrvvq6bpjvVGYkR0m02z6pWd/ZH X-Received: by 2002:a62:7641:: with SMTP id r62mr17773648pfc.35.1565302931239; Thu, 08 Aug 2019 15:22:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565302931; cv=none; d=google.com; s=arc-20160816; b=MQ2Co2ooflmSNoHS2gEqI4Imj9jkiXxJMkTENcQfZ2YQkcbVbONe6QoRzgX7XA7Niw sNSuHCbH/g6T+eAdkfWNrd/57Z38M0MGPeAwjHayLPXCnT860zWZVKDrxqs1ylBCDNiG mkG83haQer5NtNCDbZdf+QRPrbVNWtWNxbXHrvdyd1QUPqLdz+XDmZNMJ5b54idduw75 VRMUAiN2IT86npL+zC+laZ4vVqeKjo0ULc/ohK84dB73mDntT/dK7wIbxc1r1DMr/sfq ENlrb7QHMuuiioRjqr/zOlMX88dvgAnFXhZwuYyO/IoecE3DQ4Z3NAf9SDm/PEFfNnXC qjOg== 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=WDle76tEh1iTxAGxPWCewvIvmKkf9ILVKJSbPVEbyNc=; b=C4qkrXV5PN6166DU2/2CSKmFv01JxE3bHuX0ZIJ/ryKEspYwn4ykPWCmw29g8HZzvw 5euCUwP4q8wYi1415hAMF10jg/LzDmul2NF6zH4ViMqMEhibt8gUtcgvaR+hHhpCbGFA 1tlyAEqLsNI9Am4/J8mHGuoxBJ5szTz3tBpSKmUvG5CNFM/uQyfZco0et22IHQipC1Q+ mq/0QRrc44eoffHhW9JO/Q+g6TFoo0IFRy2hIXlhTx9gEX+rkVipK2RZzfcgMp3j0tfx tUkiQyyki75EzOudiunr+cNO+f6lZ8jl21Nczs0kaCv3pMvNyZStu8otJ4vjozb4i6Ng Tflw== 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 y187si56178084pgb.480.2019.08.08.15.22.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 08 Aug 2019 15:22:11 -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 05A8E6ECCE; Thu, 8 Aug 2019 22:22:09 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ot1-f66.google.com (mail-ot1-f66.google.com [209.85.210.66]) by gabe.freedesktop.org (Postfix) with ESMTPS id C4A3E6ECCD for ; Thu, 8 Aug 2019 22:22:05 +0000 (UTC) Received: by mail-ot1-f66.google.com with SMTP id d17so125212836oth.5 for ; Thu, 08 Aug 2019 15:22:05 -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=9uNhmbTEbbQrM0MoHTtlKr7OqFoVNlAP3gF7AhHdlds=; b=ECw8BKPPQ5uDbTNj5F4/e3xSiplHnObjxUuzE4C/mjOWZy9Y/1WJxmji6+t0pOpR2w mfBcWkbExlzLGua0QlLxpo2F25fjomyKG5I/Har11kFVdIjpo8mGUsFVjdIZqTvwkAQ9 drWHdOwPeqOT4Fheg8bnkotFn+Sl8dYDlKcXAVoMGCfmwUqK1XgRWEV0E6w+qLzN0Mi1 g3/Wvb3VkghuVJOKVDSAsLGiROeGVb/DdHyNWEvrbARHmuvI7BbF6cVIt6eNcw3eYco5 gIft7C13Zv4RR4uIoJ2h0Kwbzn3K8hPAfISYLYJEOYzns510hCXkD4eqtYJxhmush6K+ f1rQ== X-Gm-Message-State: APjAAAUZ6SYkc17neWTWE2aZUsQ/ZTzbDbVZVOeCuVON7EAgX8CPB3nT pDgzH6SdT2rdIKCKD2C3lZJ1xZM= X-Received: by 2002:a02:b883:: with SMTP id p3mr19677005jam.79.1565302924703; Thu, 08 Aug 2019 15:22:04 -0700 (PDT) Received: from xps15.herring.priv ([64.188.179.254]) by smtp.googlemail.com with ESMTPSA id i4sm118528553iog.31.2019.08.08.15.22.03 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 08 Aug 2019 15:22:04 -0700 (PDT) From: Rob Herring To: dri-devel@lists.freedesktop.org Subject: [PATCH v4 2/9] drm/shmem: Put pages independent of a SG table being set Date: Thu, 8 Aug 2019 16:21:53 -0600 Message-Id: <20190808222200.13176-3-robh@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190808222200.13176-1-robh@kernel.org> References: <20190808222200.13176-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 , Robin Murphy , Steven Price , David Airlie , Boris Brezillon , Alyssa Rosenzweig , Sean Paul 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 Reviewed-by: Steven Price Acked-by: Alyssa Rosenzweig Signed-off-by: Rob Herring Reviewed-by: Eric Anholt --- drivers/gpu/drm/drm_gem_shmem_helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c index 4b442576de1c..df8f2c8adb2b 100644 --- a/drivers/gpu/drm/drm_gem_shmem_helper.c +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c @@ -119,11 +119,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 Aug 8 22:21:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 170869 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp9165289ile; Thu, 8 Aug 2019 15:22:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqwp9/3njdsj8RXqz57y7BIA3psJEmlU4ifLDKFPUx7vISLvLGiOtX+qyiW4Ad7Julgpmg+D X-Received: by 2002:a62:be02:: with SMTP id l2mr18292803pff.63.1565302935572; Thu, 08 Aug 2019 15:22:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565302935; cv=none; d=google.com; s=arc-20160816; b=LZkMoPYBNS4CmmNhmfrfi5Nd2g7J9wqgf/3DP9lzuyFObGILI6wUgie+Y7f/cR5GM4 k8WaN57IWJ5PT5qttM2sAB0l8jHfn/hTW03HC6Yf5OlJGLismdtXXITRNQvgR0G/rTbY Z0IayS/xdh+lNKCJY3YicGsNhfVQahRu/8Bd05qZkV5x2IO1tV//DA8zDHsgee1ftJ5L HUoNRlvYlAE1ezU9z7fn0FzdlXFSXsW9ocuTm9ZvuQkoIK7u1onhAxvGLWg2550LxKIr wpSeubSCbKxh6fbg4DQb6DMJIBck1UvrpnDYd1a2aNdWp8JZhY29EMIsWMFwfdr76adx vyWA== 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=hkOGDxao1cmftX5Isf+8SRBzLHjyUu/EU3itkmdYjKs=; b=bHkQYaJPBmwLDzOGkFiE0BHSVDyFG1zpAZYLFsHY6VgaPSKCUBwc4Nh9OSIMwpRiAy Of5aiH2cKpWLgq6OwPOzyU+/1RG9tdlqsCt162uxLX8oG3dh+7zyu5htZSq+PcN6yGzV rRSlzgzZCuH56mZTv7C64BGNd30BWQvTiRqs/cM4m4Uhps7XRPMPnGUxO+9v/lYuH0VF hPaZve/+ViDzfricBjWVqJm8tZy0YtVdIF/Hv0IHlsqOeRPXzMZIeB891i1KI9lZPm1P Oua4nn8p8G+42btFAPBX0HzhY/eQQ7FXUc0I44UxER8Xd75tDbkkOHCvmvaFgtAhk3mb zwyA== 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 y65si51001682pgd.487.2019.08.08.15.22.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 08 Aug 2019 15:22:15 -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 ED5616ECD1; Thu, 8 Aug 2019 22:22:11 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ot1-f67.google.com (mail-ot1-f67.google.com [209.85.210.67]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7BA546ECCF for ; Thu, 8 Aug 2019 22:22:07 +0000 (UTC) Received: by mail-ot1-f67.google.com with SMTP id r6so125062371oti.3 for ; Thu, 08 Aug 2019 15:22:07 -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=9XWAdju+IoI2fqlCu19mLm3Rct7rl0h7CjpFgTCovt8=; b=aHVPlM5JuHjJt8CxCmvPp8tI74mY8j8aERx0Ta46gvXuoh66DWrLDcApxVsBknQS4T C2E3SODconWz7CoFTflmlhjObBaUdJVzeq70DXarmUejRBAqsuicV/5qe9RDqCjixpUk km6w8f36MFQ+vIOaPn6j5UU8Hj9n0BSibBZPud2MxgGP4bI3IvPLSqoxuLhUqsFJPGgZ 0yGQl3C8qDYwBwVrPx3QBsy5gY7KeN5JhUcWzE89np4+Jjc6qcWm4zq/eCVw+EvKub6r VrU1BFByNjoVdRYIgAPJJP5hzuhPsXIeM6Sp3z61lhaxB4LohQpneET6cbnw98SmXkDY z5Ig== X-Gm-Message-State: APjAAAVwzVSaEoBfZQuhnrhT4nv2+l2FAoSRhPQKF2DrbqSv3Ns0AzoA rJ36A4MHqpdo7AnVDSncecHyGuA= X-Received: by 2002:a6b:cdcc:: with SMTP id d195mr4793841iog.78.1565302926193; Thu, 08 Aug 2019 15:22:06 -0700 (PDT) Received: from xps15.herring.priv ([64.188.179.254]) by smtp.googlemail.com with ESMTPSA id i4sm118528553iog.31.2019.08.08.15.22.04 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 08 Aug 2019 15:22:05 -0700 (PDT) From: Rob Herring To: dri-devel@lists.freedesktop.org Subject: [PATCH v4 3/9] drm/panfrost: Restructure the GEM object creation Date: Thu, 8 Aug 2019 16:21:54 -0600 Message-Id: <20190808222200.13176-4-robh@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190808222200.13176-1-robh@kernel.org> References: <20190808222200.13176-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 , Robin Murphy , Steven Price , David Airlie , Boris Brezillon , Alyssa Rosenzweig , Sean Paul 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 to the mapping. In preparation to support adjusting the mapping and per FD address spaces, restructure the GEM object creation to map and unmap the GEM object in the GEM object .open() and .close() hooks. While panfrost_gem_free_object() and panfrost_gem_prime_import_sg_table() are not really needed after this commit, keep them as we'll need them in subsequent commits. Cc: Tomeu Vizoso Cc: Boris Brezillon Cc: Robin Murphy Reviewed-by: Steven Price Acked-by: Alyssa Rosenzweig Signed-off-by: Rob Herring --- Steven, Alyssa, I kept your tags, but please take another look as things moved around a bit here. drivers/gpu/drm/panfrost/panfrost_drv.c | 9 ---- drivers/gpu/drm/panfrost/panfrost_gem.c | 67 ++++++++++++++----------- 2 files changed, 37 insertions(+), 39 deletions(-) -- 2.20.1 diff --git a/drivers/gpu/drm/panfrost/panfrost_drv.c b/drivers/gpu/drm/panfrost/panfrost_drv.c index 926d021ee202..2894cfbbce2b 100644 --- a/drivers/gpu/drm/panfrost/panfrost_drv.c +++ b/drivers/gpu/drm/panfrost/panfrost_drv.c @@ -78,7 +78,6 @@ 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 drm_panfrost_create_bo *args = data; @@ -90,17 +89,9 @@ static int panfrost_ioctl_create_bo(struct drm_device *dev, void *data, if (IS_ERR(shmem)) return PTR_ERR(shmem); - ret = panfrost_mmu_map(to_panfrost_bo(&shmem->base)); - if (ret) - goto err_free; - args->offset = to_panfrost_bo(&shmem->base)->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 67d374184340..3933f83ba6b0 100644 --- a/drivers/gpu/drm/panfrost/panfrost_gem.c +++ b/drivers/gpu/drm/panfrost/panfrost_gem.c @@ -15,6 +15,39 @@ * BO. */ static void panfrost_gem_free_object(struct drm_gem_object *obj) +{ + mutex_lock(&pfdev->shrinker_lock); + if (!list_empty(&bo->base.madv_list)) + list_del(&bo->base.madv_list); + mutex_unlock(&pfdev->shrinker_lock); + + drm_gem_shmem_free_object(obj); +} + +static int panfrost_gem_open(struct drm_gem_object *obj, struct drm_file *file_priv) +{ + int ret; + size_t size = obj->size; + u64 align = size >= SZ_2M ? SZ_2M >> PAGE_SHIFT : 0; + struct panfrost_gem_object *bo = to_panfrost_bo(obj); + struct panfrost_device *pfdev = obj->dev->dev_private; + + spin_lock(&pfdev->mm_lock); + ret = drm_mm_insert_node_generic(&pfdev->mm, &bo->node, + size >> PAGE_SHIFT, align, 0, 0); + if (ret) + goto out; + + ret = panfrost_mmu_map(bo); + if (ret) + drm_mm_remove_node(&bo->node); + +out: + spin_unlock(&pfdev->mm_lock); + return ret; +} + +static void panfrost_gem_close(struct drm_gem_object *obj, struct drm_file *file_priv) { struct panfrost_gem_object *bo = to_panfrost_bo(obj); struct panfrost_device *pfdev = obj->dev->dev_private; @@ -23,19 +56,15 @@ 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); - - mutex_lock(&pfdev->shrinker_lock); - if (!list_empty(&bo->base.madv_list)) - list_del(&bo->base.madv_list); - mutex_unlock(&pfdev->shrinker_lock); - - drm_gem_shmem_free_object(obj); } static const struct drm_gem_object_funcs panfrost_gem_funcs = { .free = panfrost_gem_free_object, + .open = panfrost_gem_open, + .close = panfrost_gem_close, .print_info = drm_gem_shmem_print_info, .pin = drm_gem_shmem_pin, .unpin = drm_gem_shmem_unpin, @@ -55,10 +84,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) @@ -66,21 +92,7 @@ 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; - - spin_lock(&pfdev->mm_lock); - ret = drm_mm_insert_node_generic(&pfdev->mm, &obj->node, - size >> PAGE_SHIFT, align, 0, 0); - spin_unlock(&pfdev->mm_lock); - if (ret) - goto free_obj; - return &obj->base.base; - -free_obj: - kfree(obj); - return ERR_PTR(ret); } struct drm_gem_object * @@ -89,15 +101,10 @@ panfrost_gem_prime_import_sg_table(struct drm_device *dev, struct sg_table *sgt) { struct drm_gem_object *obj; - struct panfrost_gem_object *pobj; obj = drm_gem_shmem_prime_import_sg_table(dev, attach, sgt); if (IS_ERR(obj)) return ERR_CAST(obj); - pobj = to_panfrost_bo(obj); - - panfrost_mmu_map(pobj); - return obj; } From patchwork Thu Aug 8 22:21:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 170868 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp9165263ile; Thu, 8 Aug 2019 15:22:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqxvHF7FFnDykTtvhMIgvFkol2y9wQP+En8DcBlbcmM30Wm/0oep1v6Yn0vved2ihVlHEags X-Received: by 2002:a17:90a:5887:: with SMTP id j7mr6180625pji.136.1565302933610; Thu, 08 Aug 2019 15:22:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565302933; cv=none; d=google.com; s=arc-20160816; b=iqUazJUbs9AjNL/wkGKgGoQpq5Ui0Nh7/bvEBRrLu0r2ehWoFgyjtK3hvo99jDHENJ KQu0e/+uyznUGb68yyNdyOC/UXLg7TZ1eIjj9Tj8hiQI3APZyOAYl6flMETyN44RfdPe kmdES0N4F55Iv3fC6aPqZyhSgdkbjeln1aSf/M4Jlp7PJqSVMoPHPRdfVAQsdOy5/1Gf +JpLU5sXfjlJYXbUlyKO0/rnjXFVAE5c6JyOh9YEE5i5Yqhm6mH7YM7svoZnyZ3IWiUG Ef5xLbwalNMqC+WqnrgTlvt/oO/p+pyzAQh8WPn4YYzmismdYYJkdq5shN2DxVqlO38P nDrg== 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=GFsKv0wBfr8OD7BLISnXA/qpQpURRmk/zOX6PaU/Z5I=; b=eKQWmhuvbD4h6Lsa/ffT0b6j9YpYTWbG+pxEJhviTfkJ1kc72Ur6Aoh1RgZuC0wzHS Mw1tHlFseNvF91FOtbUyYEzuJLnpQ9uTV4h5qp2qw1cjV8+EIk+ctMWWfkhyVmAqZd8v yGqZdiVUGi384MyHvvAebMdyy3BaK3/fG+8RqxLoubFbcXEhvSCQ2buD3Smtp2f4tlqG /QD+0S4qWPFwNajZ86Uw00v3Ae77MY5ZkMQ5pxdBUhmkOpKy7tif+zOlkEySezZIQaiK ATAmU1NtTuLO3do5XEaJEU79cwmaplY2v3UfMeLH5uSgUoKsB9uDJYQBu9JGVFi4nPgM zgtQ== 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 s11si51134616pgm.412.2019.08.08.15.22.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 08 Aug 2019 15:22:13 -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 56F886ECD0; Thu, 8 Aug 2019 22:22:11 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ot1-f68.google.com (mail-ot1-f68.google.com [209.85.210.68]) by gabe.freedesktop.org (Postfix) with ESMTPS id 90CA76ECCE for ; Thu, 8 Aug 2019 22:22:08 +0000 (UTC) Received: by mail-ot1-f68.google.com with SMTP id b7so74845378otl.11 for ; Thu, 08 Aug 2019 15:22: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=1fnUesRlbFn29wRcuFLexUuzLWRtNkSEYvkJw+HNGBY=; b=phziIbTi2qFlsanX42sfTeo9bWfxqMIaDmlMCSrFXk7g6fIHntDdXcRxwOEyOD2lJx DP4m+qgwFBKLe/dUfCl7jpBFjaqb8qvaSH5sqnvRWcMefGaVPguF1cyj5/ELQaaydzuC ohEBpjoNlbMhQo8377+xihX7vGoy1pK6yAO4yQh0qasB/PA9bhTUMlmEt4DvMnDd3VsP LuEjy9r+KOv4Fx7i8hD+LmIvoAhVza4fwn9Y9MzQ2O/gBwQaS2pa3bUPIDElALtGdYvc x5/9++Da6hnWGnfhzucv+6YhaQdYDLw6m+iVm405rz7weTPdDjroOwULehLZ0YNk7o1g cgSw== X-Gm-Message-State: APjAAAWbjGq9hZz9R99InZ//diBexNU8JHGmeQ5SMXg0O1WUP9eb0Z6i N2LjB5+Q/WWHWwI2s6TGnmefXWo= X-Received: by 2002:a6b:8ed7:: with SMTP id q206mr10306346iod.120.1565302927425; Thu, 08 Aug 2019 15:22:07 -0700 (PDT) Received: from xps15.herring.priv ([64.188.179.254]) by smtp.googlemail.com with ESMTPSA id i4sm118528553iog.31.2019.08.08.15.22.06 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 08 Aug 2019 15:22:06 -0700 (PDT) From: Rob Herring To: dri-devel@lists.freedesktop.org Subject: [PATCH v4 4/9] drm/panfrost: Split panfrost_mmu_map SG list mapping to its own function Date: Thu, 8 Aug 2019 16:21:55 -0600 Message-Id: <20190808222200.13176-5-robh@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190808222200.13176-1-robh@kernel.org> References: <20190808222200.13176-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 , Robin Murphy , Steven Price , David Airlie , Boris Brezillon , Alyssa Rosenzweig , Sean Paul 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 Reviewed: Steven Price Acked-by: Alyssa Rosenzweig 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 Aug 8 22:21:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 170870 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp9165316ile; Thu, 8 Aug 2019 15:22:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqyc46/z3g5uTH7XB7V5DbmpSd9+DiO1M8XktPCA/YK5USTSwFw5AJPPJZngV3I8FjRxv9BG X-Received: by 2002:a17:90a:7788:: with SMTP id v8mr6413964pjk.132.1565302937558; Thu, 08 Aug 2019 15:22:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565302937; cv=none; d=google.com; s=arc-20160816; b=jt9ROxPmUe1T+xYPULC5HzC+296rOhXGB1c1KxvsSdysaLUb/UadCrI7B0GQPGKZjd G2MYE4cBCypgmUuTX7iFZqb78ZsiWJAsXhNkxzHPIKGOX8v22AmXtjVyG5SXYivSFwXr pH/ceerCLA3sxt8jEjzCPRNwIa9mETgAW+sFxnTaCPNF+m4zLsdT7iM1wLZxSsiIYxTV kLCA0wMQvDmbgeQMyAXHigYNyxtg5z9mGZVUBNNPRCNPaYPLujl0mMn4EpdNfT4b8TFm 1ZKnzPLuTvavdBlHnSHDM8NJ51WJqdpsJUTtjuRjmzXzYHe08l0AYK0hij6z9CS6zrNE nz0w== 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=k5FxeWVjQx0Zn5bL8ejNMcD70KLvlFCaFzzpTuDoogo=; b=aLkUFVSMfo+vN+Bpk/aJ5uuRwUlPBBXhKMyIbf8OrBFwpkuQYdv0ypck0pKiPpCbB6 lNmr+7DTHpTYRglllBmA39uKgnvmxJS68tsnsW0IcjUY9dtbMnpbSBX5pktaZz1Ap/yX ETj78PVksnRGyxSMs+xVYD7cFiocbcJXHY/HSBE9GEFDD87jD84Uv8mT7MMSeMVL7eou xT14umpV2Qvo54ctepwjCgfmrQmbfNRywfGWpmTp2WgBehqSXx7RG7P1d+I9bFTf+CyB x18vT26ySVg86QHv8Jho521OKuV6NgUczbOecFlpChXwQElULtVZQGyefHB7ezMUN0y8 mO9w== 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 l6si53944150pgg.489.2019.08.08.15.22.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 08 Aug 2019 15:22:17 -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 7CDDF6ECD2; Thu, 8 Aug 2019 22:22:14 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ot1-f66.google.com (mail-ot1-f66.google.com [209.85.210.66]) by gabe.freedesktop.org (Postfix) with ESMTPS id 39F8E6ECD0 for ; Thu, 8 Aug 2019 22:22:10 +0000 (UTC) Received: by mail-ot1-f66.google.com with SMTP id s20so59577139otp.4 for ; Thu, 08 Aug 2019 15:22: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=U5aq6+CMjPdu74RcykL36X8rKkb/+fTPEkGiQ5mxOLE=; b=VMDDSslr2G5dtGV5mnA0BQPQSgMNYmL8eP3oZodODUemHfX8+LDZ+P/N5fOlVJNCOg KqgHJBvaKB69YV1/UGdOVcxkcpo8UzOxB+WQn/u4+pmjebY3kOAydmc8V73LeuLtbUrE i/DvbWJx9gUfbM+Kf+tM0hKUrtjDx5LfYKGy9BgqZjnrEAAS7OVym0vgnWe4C5kaEphv VSovzpxBREYmUQUU+JCBbNAaQ+LjYcbc08KM60lccXaOe4JYxwqdaplO2r9abRiw+z3H 0rs+nL+LqmtCg74Avzc/iQA+HESFbD3j+r7crXc6ygLQxRjxHFvkVCqE+XhP/C7+1IWx 3dWw== X-Gm-Message-State: APjAAAXckp7QtV1E18JyxBAVzZL3Gzc70+2zGwR0/liviBzF14DFaYBf lar6ujPeFyb9QQBd/qf7EfSrB+k= X-Received: by 2002:a5d:9710:: with SMTP id h16mr2716736iol.237.1565302928721; Thu, 08 Aug 2019 15:22:08 -0700 (PDT) Received: from xps15.herring.priv ([64.188.179.254]) by smtp.googlemail.com with ESMTPSA id i4sm118528553iog.31.2019.08.08.15.22.07 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 08 Aug 2019 15:22:08 -0700 (PDT) From: Rob Herring To: dri-devel@lists.freedesktop.org Subject: [PATCH v4 5/9] drm/panfrost: Add a no execute flag for BO allocations Date: Thu, 8 Aug 2019 16:21:56 -0600 Message-Id: <20190808222200.13176-6-robh@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190808222200.13176-1-robh@kernel.org> References: <20190808222200.13176-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 , Robin Murphy , Steven Price , David Airlie , Boris Brezillon , Alyssa Rosenzweig , Sean Paul 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 Reviewed-by: Steven Price Acked-by: Alyssa Rosenzweig Signed-off-by: Rob Herring --- drivers/gpu/drm/panfrost/panfrost_drv.c | 42 +++++++++++++++++---- drivers/gpu/drm/panfrost/panfrost_gem.c | 50 ++++++++++++++++++++++++- drivers/gpu/drm/panfrost/panfrost_gem.h | 9 ++++- drivers/gpu/drm/panfrost/panfrost_mmu.c | 3 ++ include/uapi/drm/panfrost_drm.h | 2 + 5 files changed, 96 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/panfrost/panfrost_drv.c b/drivers/gpu/drm/panfrost/panfrost_drv.c index 2894cfbbce2b..f070f2dd9f84 100644 --- a/drivers/gpu/drm/panfrost/panfrost_drv.c +++ b/drivers/gpu/drm/panfrost/panfrost_drv.c @@ -78,18 +78,19 @@ 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) { - 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) + if (!args->size || args->pad || + (args->flags & ~PANFROST_BO_NOEXEC)) return -EINVAL; - shmem = drm_gem_shmem_create_with_handle(file, dev, args->size, - &args->handle); - if (IS_ERR(shmem)) - return PTR_ERR(shmem); + 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; } @@ -364,6 +365,32 @@ int panfrost_unstable_ioctl_check(void) return 0; } +#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_open(struct drm_device *dev, struct drm_file *file) { @@ -461,6 +488,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 3933f83ba6b0..f398109b8e0c 100644 --- a/drivers/gpu/drm/panfrost/panfrost_gem.c +++ b/drivers/gpu/drm/panfrost/panfrost_gem.c @@ -28,13 +28,25 @@ static int panfrost_gem_open(struct drm_gem_object *obj, struct drm_file *file_p { int ret; size_t size = obj->size; - u64 align = size >= SZ_2M ? SZ_2M >> PAGE_SHIFT : 0; + u64 align; struct panfrost_gem_object *bo = to_panfrost_bo(obj); struct panfrost_device *pfdev = obj->dev->dev_private; + 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); if (ret) goto out; @@ -95,16 +107,50 @@ struct drm_gem_object *panfrost_gem_create_object(struct drm_device *dev, size_t return &obj->base.base; } +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 drm_gem_shmem_object *shmem; + struct panfrost_gem_object *bo; + + shmem = drm_gem_shmem_create(dev, size); + if (IS_ERR(shmem)) + return ERR_CAST(shmem); + + bo = to_panfrost_bo(&shmem->base); + bo->noexec = !!(flags & PANFROST_BO_NOEXEC); + + /* + * Allocate an id of idr table where the obj is registered + * and handle has the id what user can see. + */ + ret = drm_gem_handle_create(file_priv, &shmem->base, handle); + /* drop reference from allocate - handle holds it now. */ + drm_gem_object_put_unlocked(&shmem->base); + if (ret) + return ERR_PTR(ret); + + return bo; +} + struct drm_gem_object * panfrost_gem_prime_import_sg_table(struct drm_device *dev, struct dma_buf_attachment *attach, struct sg_table *sgt) { struct drm_gem_object *obj; + struct panfrost_gem_object *bo; obj = drm_gem_shmem_prime_import_sg_table(dev, attach, sgt); if (IS_ERR(obj)) return ERR_CAST(obj); + bo = to_panfrost_bo(obj); + bo->noexec = true; + return obj; } diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.h b/drivers/gpu/drm/panfrost/panfrost_gem.h index 5f51f881ea3f..d4c7aa1790a7 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 @@ -27,6 +28,12 @@ panfrost_gem_prime_import_sg_table(struct drm_device *dev, struct dma_buf_attachment *attach, struct sg_table *sgt); +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); + void panfrost_gem_shrinker_init(struct drm_device *dev); void panfrost_gem_shrinker_cleanup(struct drm_device *dev); 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 1e547f9692e9..b80c20d17dec 100644 --- a/include/uapi/drm/panfrost_drm.h +++ b/include/uapi/drm/panfrost_drm.h @@ -84,6 +84,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 Aug 8 22:21:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 170871 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp9165346ile; Thu, 8 Aug 2019 15:22:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqz1RD03Uc8+UA9swDLmWEAOH7gkelxewfaGZ7wqlTC0e1PALXxcqO8DqHNsEr5sm7VIRNTf X-Received: by 2002:a17:902:b944:: with SMTP id h4mr15756474pls.179.1565302939423; Thu, 08 Aug 2019 15:22:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565302939; cv=none; d=google.com; s=arc-20160816; b=o6krM+RbcjTVsaqXRH3gp6BfMK2MSmV4PGlAFJkLZIeBEFgQplN8mT0gpnsA5Z+xLV batRhVgKXh+YGD66OF/Xdd71kXaFQFYA99TDrHgSO+T6ad7DC/EtjQV2re+DpbQVEiM8 8BBpeLIYqxklezMi1J/snSeZflxGewElMgbaZ1eypkNMetdjTMbhxXbbwHbcDMsQK36w drYyLioU73l72LanDW0pJuXGCBg5O2c8nZQohTurF4TFZKy4e4jnPQlIJ1MYlDvlGfG1 OkhZHfUva01Skd/VAOyhdSBp0SsOvmK7kXD8vdZq4mtrUVMu5yfgV5RE878GQVl1X6jQ PzQw== 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=yXaITJAPwnwOJAkAIfxf6ca2LVOS6r9eQ5t0w8WA/8g=; b=Ey/LiZt8qWKy1gN+X2YMCeAJnnM3ykQEDNdFQLEEuLJojaw20CIUGPs2CtL/JMAUNj P++si+g1q5kZRBp6ro7G+uSiK/lxmPk5nYH0ealQlXrsP+JSd1HmoiuFfjlrgg2VdLRr 6A+GbS3cXcmMJA5q83vSkugcqEsVjQZyzn9baNJutE+u5ddDGvHkIyzHXVxJ8d0mfcHp vzu5+xFp0W0r+KvI51RF0/nDC1XXrynJgVnUdmHjWmLWX01b9LCsZmfndEV+6mKOuKPs 0+Vj5qBbhk+NDkTiEONYZn6YarSFWnbDqOeZYkKpUR+D32OCQW0DxOQQXODISUFvFpeO gvxA== 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 a19si2941181pjv.47.2019.08.08.15.22.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 08 Aug 2019 15:22:19 -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 CD96E6ECD4; Thu, 8 Aug 2019 22:22:14 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ot1-f66.google.com (mail-ot1-f66.google.com [209.85.210.66]) by gabe.freedesktop.org (Postfix) with ESMTPS id E08846ECCF for ; Thu, 8 Aug 2019 22:22:10 +0000 (UTC) Received: by mail-ot1-f66.google.com with SMTP id z17so6636475otk.13 for ; Thu, 08 Aug 2019 15:22: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=tIGYBEAKqVgwzDzza0w3ws8fmDy9FL3lVKuHvGDNjY4=; b=aPls8pdm5Rcod130fBCgHfe8NUVd0Ub10XGtARVOk4CoESIroAHZUfEsbn8W9tPhC1 nCzKykhNaNMSRjRVPcerCK/dYbAMTtcgcAhla0WhXRcdpy34H3Xpo9Ph4Qngx+sUSlNs u/IuwaVV5C3Zoa/aOAGSl5ujaaSJiEloqws+UwUdpE52n/SVJ+sWmwbaMzf0URemy6oL Y8yyoEAdSi1+3RsWidDjPhDwE15mZWIpiMWj6PC9I2q43GHeYskr/wH+6Rv1SCGCmx7e t5u6gZC3jl7eCra+kiJpBVpnGZliQG+CnDbhFom16V3fZtr+HFjUlsDUQztorgiffVwZ HmBw== X-Gm-Message-State: APjAAAV36qgGdJ38YghPLh3Y/0AjBGffu9RdFQ1cWI0WxkcDtqp3K25K Ss5z1F5U4y5vXBh5uIsqcBW4kvw= X-Received: by 2002:a6b:7619:: with SMTP id g25mr1752619iom.92.1565302929753; Thu, 08 Aug 2019 15:22:09 -0700 (PDT) Received: from xps15.herring.priv ([64.188.179.254]) by smtp.googlemail.com with ESMTPSA id i4sm118528553iog.31.2019.08.08.15.22.08 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 08 Aug 2019 15:22:09 -0700 (PDT) From: Rob Herring To: dri-devel@lists.freedesktop.org Subject: [PATCH v4 6/9] drm/panfrost: Consolidate reset handling Date: Thu, 8 Aug 2019 16:21:57 -0600 Message-Id: <20190808222200.13176-7-robh@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190808222200.13176-1-robh@kernel.org> References: <20190808222200.13176-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 , Robin Murphy , Steven Price , David Airlie , Boris Brezillon , Alyssa Rosenzweig , Sean Paul Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Runtime PM resume and job timeouts both call the same sequence of functions, so consolidate them to a common function. This will make changing the reset related code easier. The MMU also needs some re-initialization on reset, so rework its call. In the process, we hide the address space details within the MMU code in preparation to support multiple address spaces. Cc: Tomeu Vizoso Cc: David Airlie Cc: Daniel Vetter Cc: Robin Murphy Cc: Steven Price Cc: Alyssa Rosenzweig Signed-off-by: Rob Herring Reviewed-by: Steven Price --- New patch in this version. drivers/gpu/drm/panfrost/panfrost_device.c | 16 ++++++++++------ drivers/gpu/drm/panfrost/panfrost_device.h | 1 + drivers/gpu/drm/panfrost/panfrost_job.c | 7 +------ drivers/gpu/drm/panfrost/panfrost_mmu.c | 16 +++++++++------- drivers/gpu/drm/panfrost/panfrost_mmu.h | 3 +-- 5 files changed, 22 insertions(+), 21 deletions(-) -- 2.20.1 diff --git a/drivers/gpu/drm/panfrost/panfrost_device.c b/drivers/gpu/drm/panfrost/panfrost_device.c index 8a111d7c0200..9814f4ccbd26 100644 --- a/drivers/gpu/drm/panfrost/panfrost_device.c +++ b/drivers/gpu/drm/panfrost/panfrost_device.c @@ -254,18 +254,22 @@ const char *panfrost_exception_name(struct panfrost_device *pfdev, u32 exception return "UNKNOWN"; } +void panfrost_device_reset(struct panfrost_device *pfdev) +{ + panfrost_gpu_soft_reset(pfdev); + + panfrost_gpu_power_on(pfdev); + panfrost_mmu_reset(pfdev); + panfrost_job_enable_interrupts(pfdev); +} + #ifdef CONFIG_PM int panfrost_device_resume(struct device *dev) { struct platform_device *pdev = to_platform_device(dev); struct panfrost_device *pfdev = platform_get_drvdata(pdev); - panfrost_gpu_soft_reset(pfdev); - - /* TODO: Re-enable all other address spaces */ - panfrost_gpu_power_on(pfdev); - panfrost_mmu_enable(pfdev, 0); - panfrost_job_enable_interrupts(pfdev); + panfrost_device_reset(pfdev); panfrost_devfreq_resume(pfdev); return 0; diff --git a/drivers/gpu/drm/panfrost/panfrost_device.h b/drivers/gpu/drm/panfrost/panfrost_device.h index 038b32c62484..4e5641db9c7e 100644 --- a/drivers/gpu/drm/panfrost/panfrost_device.h +++ b/drivers/gpu/drm/panfrost/panfrost_device.h @@ -132,6 +132,7 @@ int panfrost_unstable_ioctl_check(void); int panfrost_device_init(struct panfrost_device *pfdev); void panfrost_device_fini(struct panfrost_device *pfdev); +void panfrost_device_reset(struct panfrost_device *pfdev); int panfrost_device_resume(struct device *dev); int panfrost_device_suspend(struct device *dev); diff --git a/drivers/gpu/drm/panfrost/panfrost_job.c b/drivers/gpu/drm/panfrost/panfrost_job.c index 9bb9260d9181..d567ce98494c 100644 --- a/drivers/gpu/drm/panfrost/panfrost_job.c +++ b/drivers/gpu/drm/panfrost/panfrost_job.c @@ -395,12 +395,7 @@ static void panfrost_job_timedout(struct drm_sched_job *sched_job) /* panfrost_core_dump(pfdev); */ panfrost_devfreq_record_transition(pfdev, js); - panfrost_gpu_soft_reset(pfdev); - - /* TODO: Re-enable all other address spaces */ - panfrost_mmu_enable(pfdev, 0); - panfrost_gpu_power_on(pfdev); - panfrost_job_enable_interrupts(pfdev); + panfrost_device_reset(pfdev); for (i = 0; i < NUM_JOB_SLOTS; i++) drm_sched_resubmit_jobs(&pfdev->js->queue[i].sched); diff --git a/drivers/gpu/drm/panfrost/panfrost_mmu.c b/drivers/gpu/drm/panfrost/panfrost_mmu.c index eba6ce785ef0..13757427b886 100644 --- a/drivers/gpu/drm/panfrost/panfrost_mmu.c +++ b/drivers/gpu/drm/panfrost/panfrost_mmu.c @@ -105,15 +105,12 @@ static int mmu_hw_do_operation(struct panfrost_device *pfdev, u32 as_nr, return ret; } -void panfrost_mmu_enable(struct panfrost_device *pfdev, u32 as_nr) +static void panfrost_mmu_enable(struct panfrost_device *pfdev, u32 as_nr) { struct io_pgtable_cfg *cfg = &pfdev->mmu->pgtbl_cfg; u64 transtab = cfg->arm_mali_lpae_cfg.transtab; u64 memattr = cfg->arm_mali_lpae_cfg.memattr; - mmu_write(pfdev, MMU_INT_CLEAR, ~0); - mmu_write(pfdev, MMU_INT_MASK, ~0); - mmu_write(pfdev, AS_TRANSTAB_LO(as_nr), transtab & 0xffffffffUL); mmu_write(pfdev, AS_TRANSTAB_HI(as_nr), transtab >> 32); @@ -137,6 +134,14 @@ static void mmu_disable(struct panfrost_device *pfdev, u32 as_nr) write_cmd(pfdev, as_nr, AS_COMMAND_UPDATE); } +void panfrost_mmu_reset(struct panfrost_device *pfdev) +{ + panfrost_mmu_enable(pfdev, 0); + + mmu_write(pfdev, MMU_INT_CLEAR, ~0); + mmu_write(pfdev, MMU_INT_MASK, ~0); +} + static size_t get_pgsize(u64 addr, size_t size) { if (addr & (SZ_2M - 1) || size < SZ_2M) @@ -375,9 +380,6 @@ int panfrost_mmu_init(struct panfrost_device *pfdev) dev_err(pfdev->dev, "failed to request mmu irq"); return err; } - mmu_write(pfdev, MMU_INT_CLEAR, ~0); - mmu_write(pfdev, MMU_INT_MASK, ~0); - pfdev->mmu->pgtbl_cfg = (struct io_pgtable_cfg) { .pgsize_bitmap = SZ_4K | SZ_2M, .ias = FIELD_GET(0xff, pfdev->features.mmu_features), diff --git a/drivers/gpu/drm/panfrost/panfrost_mmu.h b/drivers/gpu/drm/panfrost/panfrost_mmu.h index f5878d86a5ce..d5f9b24537db 100644 --- a/drivers/gpu/drm/panfrost/panfrost_mmu.h +++ b/drivers/gpu/drm/panfrost/panfrost_mmu.h @@ -11,7 +11,6 @@ void panfrost_mmu_unmap(struct panfrost_gem_object *bo); int panfrost_mmu_init(struct panfrost_device *pfdev); void panfrost_mmu_fini(struct panfrost_device *pfdev); - -void panfrost_mmu_enable(struct panfrost_device *pfdev, u32 as_nr); +void panfrost_mmu_reset(struct panfrost_device *pfdev); #endif From patchwork Thu Aug 8 22:21:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 170872 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp9165375ile; Thu, 8 Aug 2019 15:22:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqyt1c4Rv7kjZoAu1qu9E6AUmoXgvKNemnC+3xFEGP7HfEmJmpXwxigNCV5p/eEBwi6mlUwE X-Received: by 2002:aa7:8201:: with SMTP id k1mr17455647pfi.97.1565302941323; Thu, 08 Aug 2019 15:22:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565302941; cv=none; d=google.com; s=arc-20160816; b=RRJLL63d8mYUdx8Si8RDEpprtIQ0yGTDH4Bq6mJCWD339vzCmVpwNvCEWVtahw9eot zVCp3SANft2KfYWANp0qssNTe6CdB03tExB439pq6q6zhQogl4DrOEPEJL1hO06UvBE+ AOJAjHi6mKiuoYQgMQJ1TK1H1Yn75rM3ckQOz5zxn/oYF4vRjO5XntUzh1DFw2MEUkEb 1bBGC9bmHY9X2SnoJbvzqoh/lJYwpPBLX5KEHpCqrHeJOxTO3pbLD6qNTUBEYssdFhDk Fhh2DQU/WDbIoFoswKXfu5f0aQpN82UoFcr6rz5DNzVlnKvM/htbDQtxHvgoqTcUaaSG 1Tlg== 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=hHKKLsqUqjaN4zdH4toaGsz1B2wnSPmoncENhi431FU=; b=a10ga9G6h/wuydsXhTRpz9vOdRZs1JsApIO8zdYsVZeiz4WNLXTGla9qarpG6gyHL1 CsCgjBIdePQFrQeW5KMNEubKmyLJvbn3xtJlU8dyfLjsxYP0HJCrBJlij8CaxkLBeNoi NBmhX+LpIAlVAEDl2Jk6dkaZUXHbR60616hhcdgtEFXxHY6Xwvz4zCaqFdAFL99nKdre EKxbOny4I1+2X7lijDGEYXe+PN/o5wWAXuxsmUnXL8+EPJjforZW60mIXXbAMKZLezWv pcFjJbLnXqbAimXJO5hTQHGI4xY7GsHPW0PyAUK+xSNdUDZyWdFV3HRg+D1x0Uq8lXDz yg9g== 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 g1si48571131plg.353.2019.08.08.15.22.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 08 Aug 2019 15:22:21 -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 6564D6ECD5; Thu, 8 Aug 2019 22:22:19 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ot1-f65.google.com (mail-ot1-f65.google.com [209.85.210.65]) by gabe.freedesktop.org (Postfix) with ESMTPS id B38DC6ECD3 for ; Thu, 8 Aug 2019 22:22:12 +0000 (UTC) Received: by mail-ot1-f65.google.com with SMTP id r21so119114962otq.6 for ; Thu, 08 Aug 2019 15:22: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=UpyT+Why+/m435rOz7NzCAgLp1lFXGESsqeBXgIEbKc=; b=ZsR63saxpVQTpbmPNS238OXBpGvdzi8vU+aoJ+Sx3vk885XFfUN5ewB1ewfhOjrd9u djSSThNFdWBOrUwcAJ7qOYGUiNkiBX8YqVxGOogg6J8QhiApBNV3YHDOAqeGi0QinOPc Pnw5VbeZYg1WzEm/Vwp1pKGsBcpJubnTOHLA9LwaQLzeR0nBsG+l/hTNlmEKkuQUT41o Uq52nzpo55QtzQBYabbmthS6ZZAoSK5Gng58/XyslIeterMYH6KKgmp4DjFh2PRTEoCe A9sLvKwyR9XPYlZDb6XAsZu+Z9un+BUHZ9KX/6cucP4D53YvFcpQwflC93C0w54DUB4u Skig== X-Gm-Message-State: APjAAAUrxHElh5j5Pe0/8sbDhMIaUjq9qJkBxBrwbjRZANevp62gbh0c Vicb7GYVnt9k7Vl2erCrfbOqQyQ= X-Received: by 2002:a5d:924e:: with SMTP id e14mr16641446iol.215.1565302931039; Thu, 08 Aug 2019 15:22:11 -0700 (PDT) Received: from xps15.herring.priv ([64.188.179.254]) by smtp.googlemail.com with ESMTPSA id i4sm118528553iog.31.2019.08.08.15.22.09 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 08 Aug 2019 15:22:10 -0700 (PDT) From: Rob Herring To: dri-devel@lists.freedesktop.org Subject: [PATCH v4 7/9] drm/panfrost: Convert MMU IRQ handler to threaded handler Date: Thu, 8 Aug 2019 16:21:58 -0600 Message-Id: <20190808222200.13176-8-robh@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190808222200.13176-1-robh@kernel.org> References: <20190808222200.13176-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 , Robin Murphy , Steven Price , David Airlie , Boris Brezillon , Alyssa Rosenzweig , Sean Paul Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" In preparation to handle mapping of page faults, we need the MMU handler to be threaded as code paths take a mutex. As the IRQ may be shared, we can't use the default handler and must disable the MMU interrupts locally. Cc: Tomeu Vizoso Cc: Boris Brezillon Cc: Robin Murphy Reviewed-by: Steven Price Acked-by: Alyssa Rosenzweig Signed-off-by: Rob Herring --- drivers/gpu/drm/panfrost/panfrost_mmu.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/panfrost/panfrost_mmu.c b/drivers/gpu/drm/panfrost/panfrost_mmu.c index 13757427b886..b609ee55a872 100644 --- a/drivers/gpu/drm/panfrost/panfrost_mmu.c +++ b/drivers/gpu/drm/panfrost/panfrost_mmu.c @@ -305,12 +305,20 @@ static const char *access_type_name(struct panfrost_device *pfdev, 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; - if (!status) + if (!mmu_read(pfdev, MMU_INT_STAT)) return IRQ_NONE; + mmu_write(pfdev, MMU_INT_MASK, 0); + return IRQ_WAKE_THREAD; +} + +static irqreturn_t panfrost_mmu_irq_handler_thread(int irq, void *data) +{ + struct panfrost_device *pfdev = data; + u32 status = mmu_read(pfdev, MMU_INT_RAWSTAT); + int i; + dev_err(pfdev->dev, "mmu irq status=%x\n", status); for (i = 0; status; i++) { @@ -355,6 +363,7 @@ static irqreturn_t panfrost_mmu_irq_handler(int irq, void *data) status &= ~mask; } + mmu_write(pfdev, MMU_INT_MASK, ~0); return IRQ_HANDLED; }; @@ -373,8 +382,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, panfrost_mmu_irq_handler, + panfrost_mmu_irq_handler_thread, + IRQF_SHARED, "mmu", pfdev); if (err) { dev_err(pfdev->dev, "failed to request mmu irq"); From patchwork Thu Aug 8 22:21:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 170874 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp9165407ile; Thu, 8 Aug 2019 15:22:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqxoX8uDUgIawlCOiOhTX8wTlbYXXTIPatQSEQXZrV81/QHhw8RZGM7DJ+wt1f+8k5cgJ7fE X-Received: by 2002:a65:60cd:: with SMTP id r13mr15100704pgv.315.1565302944539; Thu, 08 Aug 2019 15:22:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565302944; cv=none; d=google.com; s=arc-20160816; b=mhoOcgIxfFusld11+mNEerL6yO8n7kyR7HhAmRjOSi0pz7ZFtfGNjzT3+pX3YhUjwG igqzUrsXQApoxtmh6is5QDnT6I1e5onlhmCacm7LKGB72SYNXotEVCr7/mNxjvt3GtaN Y4TwD6QLY+Y2w2MQVog1F+rpC10O5HpXoy7T2IrQx0ygqwQTZbkiwwiNjNqZpT0nYpfU jS49CifZszhPduOX7jQvLHCaVhs1/UouyAy9bLjcYk2nD1whccmkhssTRtM5G3s8wZm+ C5J/tJ18SGrecj4EYWjB3c19mKTot6q682Afb/c5ilkAr9D89VJADK9V8fhIjFXYWloU zA5A== 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=LoVdRAb4YiXNXeT4kJTIJjPpUgxwYkb8oQ2hE726FzI=; b=QeWfqZL7QKredjnzc0uRDQ9C3gUVZB1NYMZBKRyjPMvPZF1Oj41tPRiKB584QeQOLJ UYfmo5MXg0T9tQT9hGMiV9R3A/zcM83ijxEWUTRhYRC4/NMAiwtb32z7Fu0kZ7tlEHsH jEWbf1Pwif3Jbg2qw1WURK2Z1XhK1KJgIzvNOri3nwbf5aPDLrZQgY6DvY6kJEiLVZGk sLaaF2z/rNE+7ZCLuov1pUcLCdMOnS0cuqerhUjJpPf9BCoLEZV3nwh+h4ERG6bhv5la GSQBu9DH/MwDMl5GFv6AM9sE385oWyOsfT+4ByAhmx2ldabHnR2ZNVzzKXQip6NMgoVK 50QQ== 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 r8si48455535pls.372.2019.08.08.15.22.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 08 Aug 2019 15:22:24 -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 6CB8C6ECD6; Thu, 8 Aug 2019 22:22:22 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ot1-f66.google.com (mail-ot1-f66.google.com [209.85.210.66]) by gabe.freedesktop.org (Postfix) with ESMTPS id 782C86ECD2 for ; Thu, 8 Aug 2019 22:22:13 +0000 (UTC) Received: by mail-ot1-f66.google.com with SMTP id r21so119115142otq.6 for ; Thu, 08 Aug 2019 15:22: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=K3lSPZ8ZHz84GXmRfNdToPRbubskKbANjNyMN/eubKU=; b=eVXgILeThmomJKnY9RrSc1k0UoYffPA8oMPdqjtfVyOSPgrRr7+TOC3RceQN0jk2xL 597Iw8NkGocZ1QpwoYzfu7g6CczLOHrpeB2A0P9qT2FTYJB7y80UTjBG3mDw5bbjdmHi uLbW4SULXASDogRbzNMN6YOPkwaTwoXmnFpdFXiRel3Fnko7o45obCLQrTcD0sdaX2SW JJpkPso65BcG0rigZEAjTHm0RYdDpic/NbN7zzkBcfutc/iSGZyepsvNM64YQ77PwDkL LXZGYbemVkq9zHLWZSoNN9ansa+i/53wB3e/jL2bKuhH1fNJzHqKcqehUtoitl8TtPmn Ny2A== X-Gm-Message-State: APjAAAV9Or9rQcrk0PwI5eoixB8z/lsgyh2k52NkXNtzyJwHunkHG3P4 8UdPyYo7J5wRBa2H+mMg3tK2RpU= X-Received: by 2002:a02:4005:: with SMTP id n5mr19768700jaa.73.1565302932055; Thu, 08 Aug 2019 15:22:12 -0700 (PDT) Received: from xps15.herring.priv ([64.188.179.254]) by smtp.googlemail.com with ESMTPSA id i4sm118528553iog.31.2019.08.08.15.22.11 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 08 Aug 2019 15:22:11 -0700 (PDT) From: Rob Herring To: dri-devel@lists.freedesktop.org Subject: [PATCH v4 8/9] drm/panfrost: Add support for GPU heap allocations Date: Thu, 8 Aug 2019 16:21:59 -0600 Message-Id: <20190808222200.13176-9-robh@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190808222200.13176-1-robh@kernel.org> References: <20190808222200.13176-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 , Robin Murphy , Steven Price , David Airlie , Boris Brezillon , Alyssa Rosenzweig , Sean Paul 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 Acked-by: Alyssa Rosenzweig Signed-off-by: Rob Herring Reviewed-by: Steven Price --- drivers/gpu/drm/panfrost/TODO | 2 - drivers/gpu/drm/panfrost/panfrost_drv.c | 11 +- drivers/gpu/drm/panfrost/panfrost_gem.c | 43 +++++++- drivers/gpu/drm/panfrost/panfrost_gem.h | 8 ++ drivers/gpu/drm/panfrost/panfrost_mmu.c | 129 ++++++++++++++++++++++-- include/uapi/drm/panfrost_drm.h | 1 + 6 files changed, 177 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/drm/panfrost/TODO b/drivers/gpu/drm/panfrost/TODO index d4c7fb7e7d13..e7727b292355 100644 --- a/drivers/gpu/drm/panfrost/TODO +++ b/drivers/gpu/drm/panfrost/TODO @@ -10,8 +10,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) - Compute job support. So called 'compute only' jobs need to be plumbed up to diff --git a/drivers/gpu/drm/panfrost/panfrost_drv.c b/drivers/gpu/drm/panfrost/panfrost_drv.c index f070f2dd9f84..994dbc37e4d0 100644 --- a/drivers/gpu/drm/panfrost/panfrost_drv.c +++ b/drivers/gpu/drm/panfrost/panfrost_drv.c @@ -82,7 +82,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, @@ -297,6 +302,10 @@ static int panfrost_ioctl_mmap_bo(struct drm_device *dev, void *data, return -ENOENT; } + /* Don't allow mmapping of heap objects as pages are not pinned. */ + if (to_panfrost_bo(gem_obj)->is_heap) + return -EINVAL; + ret = drm_gem_create_mmap_offset(gem_obj); if (ret == 0) args->offset = drm_vma_node_offset_addr(&gem_obj->vma_node); diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.c b/drivers/gpu/drm/panfrost/panfrost_gem.c index f398109b8e0c..37a3a6ed4617 100644 --- a/drivers/gpu/drm/panfrost/panfrost_gem.c +++ b/drivers/gpu/drm/panfrost/panfrost_gem.c @@ -16,6 +16,23 @@ */ static void panfrost_gem_free_object(struct drm_gem_object *obj) { + struct panfrost_gem_object *bo = to_panfrost_bo(obj); + struct panfrost_device *pfdev = obj->dev->dev_private; + + 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); + sg_free_table(&bo->sgts[i]); + } + } + kfree(bo->sgts); + } + mutex_lock(&pfdev->shrinker_lock); if (!list_empty(&bo->base.madv_list)) list_del(&bo->base.madv_list); @@ -50,10 +67,11 @@ static int panfrost_gem_open(struct drm_gem_object *obj, struct drm_file *file_p if (ret) goto out; - ret = panfrost_mmu_map(bo); - if (ret) - drm_mm_remove_node(&bo->node); - + if (!bo->is_heap) { + ret = panfrost_mmu_map(bo); + if (ret) + drm_mm_remove_node(&bo->node); + } out: spin_unlock(&pfdev->mm_lock); return ret; @@ -73,12 +91,20 @@ static void panfrost_gem_close(struct drm_gem_object *obj, struct drm_file *file spin_unlock(&pfdev->mm_lock); } +static int panfrost_gem_pin(struct drm_gem_object *obj) +{ + if (to_panfrost_bo(obj)->is_heap) + return -EINVAL; + + return drm_gem_shmem_pin(obj); +} + static const struct drm_gem_object_funcs panfrost_gem_funcs = { .free = panfrost_gem_free_object, .open = panfrost_gem_open, .close = panfrost_gem_close, .print_info = drm_gem_shmem_print_info, - .pin = drm_gem_shmem_pin, + .pin = panfrost_gem_pin, .unpin = drm_gem_shmem_unpin, .get_sg_table = drm_gem_shmem_get_sg_table, .vmap = drm_gem_shmem_vmap, @@ -117,12 +143,19 @@ panfrost_gem_create_with_handle(struct drm_file *file_priv, struct drm_gem_shmem_object *shmem; struct panfrost_gem_object *bo; + /* 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(dev, size); if (IS_ERR(shmem)) return ERR_CAST(shmem); bo = to_panfrost_bo(&shmem->base); bo->noexec = !!(flags & PANFROST_BO_NOEXEC); + bo->is_heap = !!(flags & PANFROST_BO_HEAP); /* * Allocate an id of idr table where the obj is registered diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.h b/drivers/gpu/drm/panfrost/panfrost_gem.h index d4c7aa1790a7..e10f58316915 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 drm_gem_object * diff --git a/drivers/gpu/drm/panfrost/panfrost_mmu.c b/drivers/gpu/drm/panfrost/panfrost_mmu.c index b609ee55a872..2ed411f09d80 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" @@ -240,12 +242,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, @@ -281,6 +283,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) { @@ -317,9 +418,7 @@ static irqreturn_t panfrost_mmu_irq_handler_thread(int irq, void *data) { struct panfrost_device *pfdev = data; u32 status = mmu_read(pfdev, MMU_INT_RAWSTAT); - int i; - - dev_err(pfdev->dev, "mmu irq status=%x\n", status); + int i, ret; for (i = 0; status; i++) { u32 mask = BIT(i) | BIT(i + 16); @@ -341,6 +440,18 @@ static irqreturn_t panfrost_mmu_irq_handler_thread(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" diff --git a/include/uapi/drm/panfrost_drm.h b/include/uapi/drm/panfrost_drm.h index b80c20d17dec..ec19db1eead8 100644 --- a/include/uapi/drm/panfrost_drm.h +++ b/include/uapi/drm/panfrost_drm.h @@ -85,6 +85,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 Aug 8 22:22:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 170873 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp9165385ile; Thu, 8 Aug 2019 15:22:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqzbDYhR9o9Ksq2qzxJf3gd1wXPC2Zzz6H6zbRW3lY2jYSR4ACgmwRDSyul3KrS/N9M2jswq X-Received: by 2002:a63:f816:: with SMTP id n22mr14478875pgh.175.1565302942599; Thu, 08 Aug 2019 15:22:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565302942; cv=none; d=google.com; s=arc-20160816; b=w6BfFaHnDKo7w92LyrYCq8NUlKuh12RrvqWnixRIpaiYHDoSLSIKAqrPSk7caiwpDv I3TCc4JSClI7sV4ciRsM0IKy1H4HSVE1WoyQom8xt9knq9o6qltAx/WQDnAwFre3nAhe lQFaV6Hs2T3nG/FN68pgju+KbtAW+d0AVhayXCCQsNnVw90aiaDy2H9PQD0cNU4fjVlM S1k7NOZVN73tph3smDHp772lmndoJ8xA8dpFemkBkkY+TdgUjYCF0xYBlUPEW3Vji3s2 bDLQVu1QxYdI6nuJBytniDGuf2OiD5Gi5++vxilvqTaOfNicupGpc8CZtG1U9qwThDs/ Gxfw== 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=0pxflVZX7jDhEXh4kD+UeAWUebSjzvCkM7VU52+G0jk=; b=cCs/SWWLxNPgUmASh/HQsEjS4TxJj/zjH2KPSX4zUQG0hrXBEMT5WlL6W3s0vjH3pc 3zUmQ2CsCyfwqadG6DEGbL4pUfLB8Zoj5R9yJ4tab3HHLz9e5+aChyNLZKzizp+/+HFT Gef/9Vc79rRwtVKKe30yXyKe0pPms5EGaU+NXcgbbCHZE3YymM8/oQSfa17mPRVwRtTx muw7GCTCG9Ln6kCzUpnscbdLTAHkFLrmSXYszve61vDB0upReyEX5oWqPQW5wje9S3+I sbx7ijF9nZFyx3NUX2HpGsN3mgId3BSh3CrNwatwf2A5JmQMfdkiyoemAkgqT00sQpjX hdrg== 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 b5si52517770pfd.273.2019.08.08.15.22.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 08 Aug 2019 15:22:22 -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 4E6036ECD3; Thu, 8 Aug 2019 22:22:19 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ot1-f65.google.com (mail-ot1-f65.google.com [209.85.210.65]) by gabe.freedesktop.org (Postfix) with ESMTPS id 82C9F6ECD3 for ; Thu, 8 Aug 2019 22:22:14 +0000 (UTC) Received: by mail-ot1-f65.google.com with SMTP id z17so6636926otk.13 for ; Thu, 08 Aug 2019 15:22: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=xrPog449LK1tekUd7IZ+epi5xcJogpnkPqslbREhU2k=; b=bn6/734U6zxzNFGw+Oqrs5XGQXV1t7e7b3gT8GFsnLRRpH2IqhHKKl9NaV51AtGqKF r98MmQuDOMg4rSWQpI1q1FyLYo9N4ITbn7rWTMih0PyChFm7nLfCWVi6xoz9RqMRZge5 8vfCAYp7ucSvWiMhpL0XtE/fHFQddtzgNM/pemJZNS4Drep7yE6PXN9Y3kWUjyTUx/bH znbPp+77xg0vG7T+5c3K7aBfLgPKfvI2G5RdnAlSNppGmetpXjqdcQ5j4nvJV9LxP6PR eufB8lfqryt7gKUqaBraQnHbUg4uBmplDZZbinDHP6Fy4a2iI3y8AmLnudLkOOjOF7pA Foxw== X-Gm-Message-State: APjAAAXrAkYTuk0uiU4kKyjzSD4obSDqYaDF/b7GLJDGWHWfkZItNUbj BUcZhpUuSIbWfzjWXoPAAT94QXw= X-Received: by 2002:a6b:cdcc:: with SMTP id d195mr4794360iog.78.1565302933164; Thu, 08 Aug 2019 15:22:13 -0700 (PDT) Received: from xps15.herring.priv ([64.188.179.254]) by smtp.googlemail.com with ESMTPSA id i4sm118528553iog.31.2019.08.08.15.22.12 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 08 Aug 2019 15:22:12 -0700 (PDT) From: Rob Herring To: dri-devel@lists.freedesktop.org Subject: [PATCH v4 9/9] drm/panfrost: Bump driver version to 1.1 Date: Thu, 8 Aug 2019 16:22:00 -0600 Message-Id: <20190808222200.13176-10-robh@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190808222200.13176-1-robh@kernel.org> References: <20190808222200.13176-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 , Robin Murphy , Steven Price , David Airlie , Boris Brezillon , Alyssa Rosenzweig , Sean Paul 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 Acked-by: 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 994dbc37e4d0..a1352750984c 100644 --- a/drivers/gpu/drm/panfrost/panfrost_drv.c +++ b/drivers/gpu/drm/panfrost/panfrost_drv.c @@ -448,6 +448,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, @@ -459,7 +464,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,