Message ID | 20221116102659.70287-15-david@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp68670wru; Wed, 16 Nov 2022 02:41:05 -0800 (PST) X-Google-Smtp-Source: AA0mqf6b3Skido6Ake5vEbv8M6hCG6UX7Piau6wo5pM7VzSAjqc/4eMO9fCdxRYYHheV8CctHm2J X-Received: by 2002:a17:906:4e0d:b0:7ad:b822:d2e4 with SMTP id z13-20020a1709064e0d00b007adb822d2e4mr17057378eju.35.1668595264850; Wed, 16 Nov 2022 02:41:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668595264; cv=none; d=google.com; s=arc-20160816; b=tl9I+IAhBwQ0NJJeHdRjpXSP1+VhDoKA//IQ88eSOFpIhChVmaXOHKCkFQkcwXr1hh ebNUF2htqgSK7BOSx8xSpt0SZTW2RvN6gPLJXwwWHzUZWH3kByTtg6OrJrm1eudeygxi be/U60fzL2JYlc5EeEajlHzOzzpPxEcZquNkF8OTB4SPHvXTHvC4XZfXXr6cBKhBibUM wFjg6QjkZ9O5h3a0I0cg+iOuIYl+hyNmYekme1pHL+ySzMk1as5mI19EgWiSaxQPXQPm xwtI50uJ0MzSLFZ4nefipMhB+ZqrE+Yt2mVZSAaX0l96QtS2Rq/11MdCpoBR8Q23yocC TbfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ddMjxbE+d57ySmRYhTvAErVzb9ykjmc/iLClBCHgJ7c=; b=HX9u+hYXOFCqSud8FzPNtqAw36K2kuwvmPpANn5UPTVX1IW8M3Pwgflw+n/ZMh/Jk1 dVGUbHkbCLHumL2w8glEjnMzw5OiCTRyNi2lQzgNN6f7D8bqnlGJ3ZpV0+UK5SgJQiJJ vD9F5iqRijq3439BCSDqFc7t0k7KBFF6G1xUy4sTHuKdl9B7chu32ikGQbsYzN/AYIr3 24M01DqQmxhRNZS+waxORDIvZ9eqh+2hboz4UPylXeQpBWn02NXH97xcmLtM2uiDbeGc G3N2NE67wM0+CNRYW+JVMmIO2fCu/Ap1lbnmG34YmdQGCUzAzTKrDqxjFnoZOHX7N8nY fgxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hwWhhQCb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a7-20020a50c307000000b0045dc9b4c034si12034178edb.582.2022.11.16.02.40.39; Wed, 16 Nov 2022 02:41:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hwWhhQCb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233914AbiKPKj6 (ORCPT <rfc822;just.gull.subs@gmail.com> + 99 others); Wed, 16 Nov 2022 05:39:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233584AbiKPKiT (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 16 Nov 2022 05:38:19 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE9952D754 for <linux-kernel@vger.kernel.org>; Wed, 16 Nov 2022 02:29:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668594557; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ddMjxbE+d57ySmRYhTvAErVzb9ykjmc/iLClBCHgJ7c=; b=hwWhhQCb9J5G2PUYpiEbIIDQ905iD55CpVdw/OqIcwM3G4C/z9Y/AH/7+8LX2HZjlzGFm9 o4jZ53v9w+KSRC/BL1iCE+RpKMlqWPHwVoOH7MHmjWThZ4VPJ/TS6R+ai9cj3D4KR5P5xN Z/6n25FQcSBbh2lX+QHlKAW3WIQkfZs= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-281-3wHpF2z_Ol-w_Oz0Io_Gqg-1; Wed, 16 Nov 2022 05:29:09 -0500 X-MC-Unique: 3wHpF2z_Ol-w_Oz0Io_Gqg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ED87586F130; Wed, 16 Nov 2022 10:29:07 +0000 (UTC) Received: from t480s.fritz.box (unknown [10.39.193.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0046B2027064; Wed, 16 Nov 2022 10:29:00 +0000 (UTC) From: David Hildenbrand <david@redhat.com> To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, linux-alpha@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-ia64@vger.kernel.org, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, sparclinux@vger.kernel.org, linux-um@lists.infradead.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-samsung-soc@vger.kernel.org, linux-rdma@vger.kernel.org, linux-media@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-perf-users@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kselftest@vger.kernel.org, Linus Torvalds <torvalds@linux-foundation.org>, Andrew Morton <akpm@linux-foundation.org>, Jason Gunthorpe <jgg@ziepe.ca>, John Hubbard <jhubbard@nvidia.com>, Peter Xu <peterx@redhat.com>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Andrea Arcangeli <aarcange@redhat.com>, Hugh Dickins <hughd@google.com>, Nadav Amit <namit@vmware.com>, Vlastimil Babka <vbabka@suse.cz>, Matthew Wilcox <willy@infradead.org>, Mike Kravetz <mike.kravetz@oracle.com>, Muchun Song <songmuchun@bytedance.com>, Shuah Khan <shuah@kernel.org>, Lucas Stach <l.stach@pengutronix.de>, David Airlie <airlied@gmail.com>, Oded Gabbay <ogabbay@kernel.org>, Arnd Bergmann <arnd@arndb.de>, Christoph Hellwig <hch@infradead.org>, Alex Williamson <alex.williamson@redhat.com>, David Hildenbrand <david@redhat.com>, Daniel Vetter <daniel.vetter@ffwll.ch>, Russell King <linux+etnaviv@armlinux.org.uk>, Christian Gmeiner <christian.gmeiner@gmail.com> Subject: [PATCH mm-unstable v1 14/20] drm/etnaviv: remove FOLL_FORCE usage Date: Wed, 16 Nov 2022 11:26:53 +0100 Message-Id: <20221116102659.70287-15-david@redhat.com> In-Reply-To: <20221116102659.70287-1-david@redhat.com> References: <20221116102659.70287-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749648948568618311?= X-GMAIL-MSGID: =?utf-8?q?1749648948568618311?= |
Series |
mm/gup: remove FOLL_FORCE usage from drivers (reliable R/O long-term pinning)
|
|
Commit Message
David Hildenbrand
Nov. 16, 2022, 10:26 a.m. UTC
GUP now supports reliable R/O long-term pinning in COW mappings, such
that we break COW early. MAP_SHARED VMAs only use the shared zeropage so
far in one corner case (DAXFS file with holes), which can be ignored
because GUP does not support long-term pinning in fsdax (see
check_vma_flags()).
commit cd5297b0855f ("drm/etnaviv: Use FOLL_FORCE for userptr")
documents that FOLL_FORCE | FOLL_WRITE was really only used for reliable
R/O pinning.
Consequently, FOLL_FORCE | FOLL_WRITE | FOLL_LONGTERM is no longer required
for reliable R/O long-term pinning: FOLL_LONGTERM is sufficient. So stop
using FOLL_FORCE, which is really only for ptrace access.
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Lucas Stach <l.stach@pengutronix.de>
Cc: Russell King <linux+etnaviv@armlinux.org.uk>
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: David Airlie <airlied@gmail.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
drivers/gpu/drm/etnaviv/etnaviv_gem.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
Comments
On Wed, Nov 16, 2022 at 11:26:53AM +0100, David Hildenbrand wrote: > GUP now supports reliable R/O long-term pinning in COW mappings, such > that we break COW early. MAP_SHARED VMAs only use the shared zeropage so > far in one corner case (DAXFS file with holes), which can be ignored > because GUP does not support long-term pinning in fsdax (see > check_vma_flags()). > > commit cd5297b0855f ("drm/etnaviv: Use FOLL_FORCE for userptr") > documents that FOLL_FORCE | FOLL_WRITE was really only used for reliable > R/O pinning. > > Consequently, FOLL_FORCE | FOLL_WRITE | FOLL_LONGTERM is no longer required > for reliable R/O long-term pinning: FOLL_LONGTERM is sufficient. So stop > using FOLL_FORCE, which is really only for ptrace access. > > Cc: Daniel Vetter <daniel.vetter@ffwll.ch> > Cc: Lucas Stach <l.stach@pengutronix.de> > Cc: Russell King <linux+etnaviv@armlinux.org.uk> > Cc: Christian Gmeiner <christian.gmeiner@gmail.com> > Cc: David Airlie <airlied@gmail.com> > Signed-off-by: David Hildenbrand <david@redhat.com> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> Also ack for merging through whatever tree suits best, since I guess this should all land together. -Daniel > --- > drivers/gpu/drm/etnaviv/etnaviv_gem.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem.c b/drivers/gpu/drm/etnaviv/etnaviv_gem.c > index cc386f8a7116..efe2240945d0 100644 > --- a/drivers/gpu/drm/etnaviv/etnaviv_gem.c > +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem.c > @@ -638,6 +638,7 @@ static int etnaviv_gem_userptr_get_pages(struct etnaviv_gem_object *etnaviv_obj) > struct page **pvec = NULL; > struct etnaviv_gem_userptr *userptr = &etnaviv_obj->userptr; > int ret, pinned = 0, npages = etnaviv_obj->base.size >> PAGE_SHIFT; > + unsigned int gup_flags = FOLL_LONGTERM; > > might_lock_read(¤t->mm->mmap_lock); > > @@ -648,14 +649,15 @@ static int etnaviv_gem_userptr_get_pages(struct etnaviv_gem_object *etnaviv_obj) > if (!pvec) > return -ENOMEM; > > + if (!userptr->ro) > + gup_flags |= FOLL_WRITE; > + > do { > unsigned num_pages = npages - pinned; > uint64_t ptr = userptr->ptr + pinned * PAGE_SIZE; > struct page **pages = pvec + pinned; > > - ret = pin_user_pages_fast(ptr, num_pages, > - FOLL_WRITE | FOLL_FORCE | FOLL_LONGTERM, > - pages); > + ret = pin_user_pages_fast(ptr, num_pages, gup_flags, pages); > if (ret < 0) { > unpin_user_pages(pvec, pinned); > kvfree(pvec); > -- > 2.38.1 >
diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem.c b/drivers/gpu/drm/etnaviv/etnaviv_gem.c index cc386f8a7116..efe2240945d0 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gem.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem.c @@ -638,6 +638,7 @@ static int etnaviv_gem_userptr_get_pages(struct etnaviv_gem_object *etnaviv_obj) struct page **pvec = NULL; struct etnaviv_gem_userptr *userptr = &etnaviv_obj->userptr; int ret, pinned = 0, npages = etnaviv_obj->base.size >> PAGE_SHIFT; + unsigned int gup_flags = FOLL_LONGTERM; might_lock_read(¤t->mm->mmap_lock); @@ -648,14 +649,15 @@ static int etnaviv_gem_userptr_get_pages(struct etnaviv_gem_object *etnaviv_obj) if (!pvec) return -ENOMEM; + if (!userptr->ro) + gup_flags |= FOLL_WRITE; + do { unsigned num_pages = npages - pinned; uint64_t ptr = userptr->ptr + pinned * PAGE_SIZE; struct page **pages = pvec + pinned; - ret = pin_user_pages_fast(ptr, num_pages, - FOLL_WRITE | FOLL_FORCE | FOLL_LONGTERM, - pages); + ret = pin_user_pages_fast(ptr, num_pages, gup_flags, pages); if (ret < 0) { unpin_user_pages(pvec, pinned); kvfree(pvec);