Message ID | 20221116102659.70287-14-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 l7csp68590wru; Wed, 16 Nov 2022 02:40:48 -0800 (PST) X-Google-Smtp-Source: AA0mqf4A+3VXTu2EyjEfevTDv/IuF8GkhPsN+0V/USvIoFOU6YVw70KeeGE27kbzO/qprG4QxlT3 X-Received: by 2002:a05:6402:68d:b0:45f:c86e:5336 with SMTP id f13-20020a056402068d00b0045fc86e5336mr18075176edy.233.1668595248473; Wed, 16 Nov 2022 02:40:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668595248; cv=none; d=google.com; s=arc-20160816; b=ObAZ/gK7KDGMQup+ykekLAR9t/97zpO9lsmcxIBpJ0RzW8lVg/gxE/DZ9moUjYtDCs LnuVwFljxMiCqE5gHaDjUdZtFEOYUlNznLsrg4bpbeVScOSj9QdDZasdESAGOvJy5CwJ C/ZymYt6Dz8F3APzlp543Om1SyF+sFIRFNmTO9WdBL3MSxauHtM+7x1WJk/+1fkJdfxg MYftAJ6A8HhwoDkGWujA+DNyPwDTHd7OfacsDVemGgZ5Y8RDtKyJzCUMBPAGe0dcuM76 hJA1qnwBE5QnzV4HAUTsGg3EXSUcf/yzhZL73bu1uOd5WFaHLSDWw2eYXOiOWR04CV6Z FIAQ== 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=PtZFIm00BoukAq0r3vxYea1/oUxWby/yeQnBgXcmZG8=; b=TwHg81T5OJacOAsTpEVA/hiw9pNQmUDlcCGk5WTgA4mPaf9HoUJI/cnzES2SilMrqH U6iwgPsENZuWAWbOs40zkfVKJyZ+9a7AbyEJIWvmpOXMZYgwrtlcSCRXJCps5LYlGJbc KO74KPbyOy/JXubayI5bwdITw4MV1nq2ApvKSu3Bf5S3cQBolNgSrCTq4317FrCV4tza dvIp+TFLKSd24aZ+x8BiFp2CKkr/fHD3atyR1FPRvB0u6qMP0X6w9fYzQs/xpc+g6WaI xipNcm6rPQKOXYxG9HIPOVvnw+CyAbsgmAd1NnblQNv99mtr+aYQjnKUGNWPMsUU9L6+ GVUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hr1vtWj7; 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 hv21-20020a17090760d500b007ae4717bf11si12246807ejc.80.2022.11.16.02.40.24; Wed, 16 Nov 2022 02:40:48 -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=hr1vtWj7; 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 S237368AbiKPKjs (ORCPT <rfc822;just.gull.subs@gmail.com> + 99 others); Wed, 16 Nov 2022 05:39:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231185AbiKPKiT (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.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DEDA2CC80 for <linux-kernel@vger.kernel.org>; Wed, 16 Nov 2022 02:29:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668594549; 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=PtZFIm00BoukAq0r3vxYea1/oUxWby/yeQnBgXcmZG8=; b=hr1vtWj7hSzN/U8/+SOSHRcATuJ36HbEUAvStWcViiqkwKmdcn4tKY8i/Ex6sKYidjE8NW VYhLKt5bMGEzKTpCEyjFYcymoS5Y29s+T2FkjullqOkN5yx5mjGZklHUhGSSbUOTl9QG2h foWk8N3D4JgNB0zO77I1/HFftwrsAsY= 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-618-uLqpp3ByOjmb0y4uEYa0gA-1; Wed, 16 Nov 2022 05:29:02 -0500 X-MC-Unique: uLqpp3ByOjmb0y4uEYa0gA-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 95160811E7A; Wed, 16 Nov 2022 10:29:00 +0000 (UTC) Received: from t480s.fritz.box (unknown [10.39.193.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4EDB82028E8F; Wed, 16 Nov 2022 10:28:53 +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>, Mauro Carvalho Chehab <mchehab@kernel.org> Subject: [PATCH mm-unstable v1 13/20] media: videobuf-dma-sg: remove FOLL_FORCE usage Date: Wed, 16 Nov 2022 11:26:52 +0100 Message-Id: <20221116102659.70287-14-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?1749648931013738819?= X-GMAIL-MSGID: =?utf-8?q?1749648931013738819?= |
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()).
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: Mauro Carvalho Chehab <mchehab@kernel.org>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
drivers/media/v4l2-core/videobuf-dma-sg.c | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
Comments
On Wed, Nov 16, 2022 at 11:26:52AM +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()). > > 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: Mauro Carvalho Chehab <mchehab@kernel.org> > Signed-off-by: David Hildenbrand <david@redhat.com> I looked at this a while ago when going through some of the follow_pfn stuff, so Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> > --- > drivers/media/v4l2-core/videobuf-dma-sg.c | 14 +++++--------- > 1 file changed, 5 insertions(+), 9 deletions(-) > > diff --git a/drivers/media/v4l2-core/videobuf-dma-sg.c b/drivers/media/v4l2-core/videobuf-dma-sg.c > index f75e5eedeee0..234e9f647c96 100644 > --- a/drivers/media/v4l2-core/videobuf-dma-sg.c > +++ b/drivers/media/v4l2-core/videobuf-dma-sg.c > @@ -151,17 +151,16 @@ static void videobuf_dma_init(struct videobuf_dmabuf *dma) > static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma, > int direction, unsigned long data, unsigned long size) > { > + unsigned int gup_flags = FOLL_LONGTERM; > unsigned long first, last; > - int err, rw = 0; > - unsigned int flags = FOLL_FORCE; > + int err; > > dma->direction = direction; > switch (dma->direction) { > case DMA_FROM_DEVICE: > - rw = READ; > + gup_flags |= FOLL_WRITE; > break; > case DMA_TO_DEVICE: > - rw = WRITE; > break; > default: > BUG(); > @@ -177,14 +176,11 @@ static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma, > if (NULL == dma->pages) > return -ENOMEM; > > - if (rw == READ) > - flags |= FOLL_WRITE; > - > dprintk(1, "init user [0x%lx+0x%lx => %lu pages]\n", > data, size, dma->nr_pages); > > - err = pin_user_pages(data & PAGE_MASK, dma->nr_pages, > - flags | FOLL_LONGTERM, dma->pages, NULL); > + err = pin_user_pages(data & PAGE_MASK, dma->nr_pages, gup_flags, > + dma->pages, NULL); > > if (err != dma->nr_pages) { > dma->nr_pages = (err >= 0) ? err : 0; > -- > 2.38.1 >
On 16/11/2022 11:26, 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()). > > 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: Mauro Carvalho Chehab <mchehab@kernel.org> > Signed-off-by: David Hildenbrand <david@redhat.com> Acked-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Looks good! Hans > --- > drivers/media/v4l2-core/videobuf-dma-sg.c | 14 +++++--------- > 1 file changed, 5 insertions(+), 9 deletions(-) > > diff --git a/drivers/media/v4l2-core/videobuf-dma-sg.c b/drivers/media/v4l2-core/videobuf-dma-sg.c > index f75e5eedeee0..234e9f647c96 100644 > --- a/drivers/media/v4l2-core/videobuf-dma-sg.c > +++ b/drivers/media/v4l2-core/videobuf-dma-sg.c > @@ -151,17 +151,16 @@ static void videobuf_dma_init(struct videobuf_dmabuf *dma) > static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma, > int direction, unsigned long data, unsigned long size) > { > + unsigned int gup_flags = FOLL_LONGTERM; > unsigned long first, last; > - int err, rw = 0; > - unsigned int flags = FOLL_FORCE; > + int err; > > dma->direction = direction; > switch (dma->direction) { > case DMA_FROM_DEVICE: > - rw = READ; > + gup_flags |= FOLL_WRITE; > break; > case DMA_TO_DEVICE: > - rw = WRITE; > break; > default: > BUG(); > @@ -177,14 +176,11 @@ static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma, > if (NULL == dma->pages) > return -ENOMEM; > > - if (rw == READ) > - flags |= FOLL_WRITE; > - > dprintk(1, "init user [0x%lx+0x%lx => %lu pages]\n", > data, size, dma->nr_pages); > > - err = pin_user_pages(data & PAGE_MASK, dma->nr_pages, > - flags | FOLL_LONGTERM, dma->pages, NULL); > + err = pin_user_pages(data & PAGE_MASK, dma->nr_pages, gup_flags, > + dma->pages, NULL); > > if (err != dma->nr_pages) { > dma->nr_pages = (err >= 0) ? err : 0;
diff --git a/drivers/media/v4l2-core/videobuf-dma-sg.c b/drivers/media/v4l2-core/videobuf-dma-sg.c index f75e5eedeee0..234e9f647c96 100644 --- a/drivers/media/v4l2-core/videobuf-dma-sg.c +++ b/drivers/media/v4l2-core/videobuf-dma-sg.c @@ -151,17 +151,16 @@ static void videobuf_dma_init(struct videobuf_dmabuf *dma) static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma, int direction, unsigned long data, unsigned long size) { + unsigned int gup_flags = FOLL_LONGTERM; unsigned long first, last; - int err, rw = 0; - unsigned int flags = FOLL_FORCE; + int err; dma->direction = direction; switch (dma->direction) { case DMA_FROM_DEVICE: - rw = READ; + gup_flags |= FOLL_WRITE; break; case DMA_TO_DEVICE: - rw = WRITE; break; default: BUG(); @@ -177,14 +176,11 @@ static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma, if (NULL == dma->pages) return -ENOMEM; - if (rw == READ) - flags |= FOLL_WRITE; - dprintk(1, "init user [0x%lx+0x%lx => %lu pages]\n", data, size, dma->nr_pages); - err = pin_user_pages(data & PAGE_MASK, dma->nr_pages, - flags | FOLL_LONGTERM, dma->pages, NULL); + err = pin_user_pages(data & PAGE_MASK, dma->nr_pages, gup_flags, + dma->pages, NULL); if (err != dma->nr_pages) { dma->nr_pages = (err >= 0) ? err : 0;