From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DF2DC5519F for ; Fri, 20 Nov 2020 08:39:56 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 668482224C for ; Fri, 20 Nov 2020 08:39:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="b0w6ldKp" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 668482224C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B294D6B0036; Fri, 20 Nov 2020 03:39:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B00E36B005C; Fri, 20 Nov 2020 03:39:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9C7D36B0070; Fri, 20 Nov 2020 03:39:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0030.hostedemail.com [216.40.44.30]) by kanga.kvack.org (Postfix) with ESMTP id 5F4DF6B0036 for ; Fri, 20 Nov 2020 03:39:54 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id E95BC181AEF15 for ; Fri, 20 Nov 2020 08:39:53 +0000 (UTC) X-FDA: 77504148666.20.tank84_3912f5e2734a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id CD2C8180C07A3 for ; Fri, 20 Nov 2020 08:39:53 +0000 (UTC) X-HE-Tag: tank84_3912f5e2734a X-Filterd-Recvd-Size: 10093 Received: from mail-lf1-f67.google.com (mail-lf1-f67.google.com [209.85.167.67]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Fri, 20 Nov 2020 08:39:52 +0000 (UTC) Received: by mail-lf1-f67.google.com with SMTP id z21so12263961lfe.12 for ; Fri, 20 Nov 2020 00:39:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=CSkCdCaqLBM0bWRHZ00ADxnd+NBE6b99YIUgGCXQ0N8=; b=b0w6ldKpDUpMxM+H9MUxFarymLOND8rU0+XNOChF0O2Py4IV00Gt47AXtaGeXw0t2r wHUIYai3iA2izngwjfCKMot50mClxBEGuQx4AYiM8qhD4pjCPBDtKuI2ns6damGBZZ29 fteKSJKPs2hjKnRux2ro3BntaD5Y1UZDqK8Mo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=CSkCdCaqLBM0bWRHZ00ADxnd+NBE6b99YIUgGCXQ0N8=; b=dbRvE5x+YTjun7u/K1WHyNn9dVh2a5xDdoDQ9j+e/77n8uWy4cOTRMJyCWZm62gRLv ls7LC1QHRa19CiZxz7CkE8O9RxDMuD4eBh3K5+5CbUnRmHZHt2W0eM6j+v2Yc2jZZU/b 15fr6Rw64iEjgV5BVo7H/+Ahnp9R72/q31nY7UwtR1qA7A/qG6sCl2I/J5R6n6Qzwx00 AlPS+tjZRI0Hd+Xkep8TIeezBw2CWFC2qYCtb2fxbbXD21NWx3Lxt7InMnhV9ljfiqHM XCED6nGMmQ1l77ShlfESjwk5R9rmtoQKqeRafBaqJgJknCRbOZBXZDA+jA24HiUaQp9w WX5w== X-Gm-Message-State: AOAM5330yslvKIWZluYtNgWOijA8z2VzVytnVwJvjpxTOzwaDezye03v n/nlFKKkWqnzfbwGLNTKBqz/yDuWg5VntA== X-Google-Smtp-Source: ABdhPJzL9uyZWm8WtBx2EPnHRHrNo3r8DhVMSQAVwgKg7fP2wscUqXOziEK0IYQayreRAhfDmbAl2w== X-Received: by 2002:a05:6512:14e:: with SMTP id m14mr7430573lfo.22.1605861591009; Fri, 20 Nov 2020 00:39:51 -0800 (PST) Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com. [209.85.208.175]) by smtp.gmail.com with ESMTPSA id i6sm275263lfo.70.2020.11.20.00.39.50 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 20 Nov 2020 00:39:50 -0800 (PST) Received: by mail-lj1-f175.google.com with SMTP id y16so9233854ljh.0 for ; Fri, 20 Nov 2020 00:39:50 -0800 (PST) X-Received: by 2002:adf:fb90:: with SMTP id a16mr13977920wrr.192.1605861181149; Fri, 20 Nov 2020 00:33:01 -0800 (PST) MIME-Version: 1.0 References: <20201119144146.1045202-1-daniel.vetter@ffwll.ch> <20201119144146.1045202-10-daniel.vetter@ffwll.ch> In-Reply-To: From: Tomasz Figa Date: Fri, 20 Nov 2020 17:32:49 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v6 09/17] media/videbuf1|2: Mark follow_pfn usage as unsafe To: Hans Verkuil Cc: Daniel Vetter , DRI Development , LKML , kvm , Linux MM , "list@263.net:IOMMU DRIVERS , Joerg Roedel ," , linux-samsung-soc , Linux Media Mailing List , Daniel Vetter , Jason Gunthorpe , Kees Cook , Dan Williams , Andrew Morton , John Hubbard , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , Jan Kara , Pawel Osciak , Marek Szyprowski , Kyungmin Park , Laurent Dufour , Vlastimil Babka , Daniel Jordan , Michel Lespinasse , Mauro Carvalho Chehab Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, Nov 20, 2020 at 5:28 PM Hans Verkuil wrote: > > On 20/11/2020 09:06, Hans Verkuil wrote: > > On 19/11/2020 15:41, Daniel Vetter wrote: > >> The media model assumes that buffers are all preallocated, so that > >> when a media pipeline is running we never miss a deadline because the > >> buffers aren't allocated or available. > >> > >> This means we cannot fix the v4l follow_pfn usage through > >> mmu_notifier, without breaking how this all works. The only real fix > >> is to deprecate userptr support for VM_IO | VM_PFNMAP mappings and > >> tell everyone to cut over to dma-buf memory sharing for zerocopy. > >> > >> userptr for normal memory will keep working as-is, this only affects > >> the zerocopy userptr usage enabled in 50ac952d2263 ("[media] > >> videobuf2-dma-sg: Support io userptr operations on io memory"). > >> > >> Acked-by: Tomasz Figa > > > > Acked-by: Hans Verkuil > > Actually, cancel this Acked-by. > > So let me see if I understand this right: VM_IO | VM_PFNMAP mappings can > move around. There is a mmu_notifier that can be used to be notified when > that happens, but that can't be used with media buffers since those buffe= rs > must always be available and in the same place. > > So follow_pfn is replaced by unsafe_follow_pfn to signal that what is att= empted > is unsafe and unreliable. > > If CONFIG_STRICT_FOLLOW_PFN is set, then unsafe_follow_pfn will fail, if = it > is unset, then it writes a warning to the kernel log but just continues w= hile > still unsafe. > > I am very much inclined to just drop VM_IO | VM_PFNMAP support in the med= ia > subsystem. For vb2 there is a working alternative in the form of dmabuf, = and > frankly for vb1 I don't care. If someone really needs this for a vb1 driv= er, > then they can do the work to convert that driver to vb2. > > I've added Mauro to the CC list and I'll ping a few more people to see wh= at > they think, but in my opinion support for USERPTR + VM_IO | VM_PFNMAP > should just be killed off. > > If others would like to keep it, then frame_vector.c needs a comment befo= re > the 'while' explaining why the unsafe_follow_pfn is there and that using > dmabuf is the proper alternative to use. That will make it easier for > developers to figure out why they see a kernel warning and what to do to > fix it, rather than having to dig through the git history for the reason. I'm all for dropping that code. Best regards, Tomasz > > Regards, > > Hans > > > > > Thanks! > > > > Hans > > > >> Signed-off-by: Daniel Vetter > >> Cc: Jason Gunthorpe > >> Cc: Kees Cook > >> Cc: Dan Williams > >> Cc: Andrew Morton > >> Cc: John Hubbard > >> Cc: J=C3=A9r=C3=B4me Glisse > >> Cc: Jan Kara > >> Cc: Dan Williams > >> Cc: linux-mm@kvack.org > >> Cc: linux-arm-kernel@lists.infradead.org > >> Cc: linux-samsung-soc@vger.kernel.org > >> Cc: linux-media@vger.kernel.org > >> Cc: Pawel Osciak > >> Cc: Marek Szyprowski > >> Cc: Kyungmin Park > >> Cc: Tomasz Figa > >> Cc: Laurent Dufour > >> Cc: Vlastimil Babka > >> Cc: Daniel Jordan > >> Cc: Michel Lespinasse > >> Signed-off-by: Daniel Vetter > >> -- > >> v3: > >> - Reference the commit that enabled the zerocopy userptr use case to > >> make it abundandtly clear that this patch only affects that, and not > >> normal memory userptr. The old commit message already explained that > >> normal memory userptr is unaffected, but I guess that was not clear > >> enough. > >> --- > >> drivers/media/common/videobuf2/frame_vector.c | 2 +- > >> drivers/media/v4l2-core/videobuf-dma-contig.c | 2 +- > >> 2 files changed, 2 insertions(+), 2 deletions(-) > >> > >> diff --git a/drivers/media/common/videobuf2/frame_vector.c b/drivers/m= edia/common/videobuf2/frame_vector.c > >> index a0e65481a201..1a82ec13ea00 100644 > >> --- a/drivers/media/common/videobuf2/frame_vector.c > >> +++ b/drivers/media/common/videobuf2/frame_vector.c > >> @@ -70,7 +70,7 @@ int get_vaddr_frames(unsigned long start, unsigned i= nt nr_frames, > >> break; > >> > >> while (ret < nr_frames && start + PAGE_SIZE <=3D vma->vm_= end) { > >> - err =3D follow_pfn(vma, start, &nums[ret]); > >> + err =3D unsafe_follow_pfn(vma, start, &nums[ret])= ; > >> if (err) { > >> if (ret =3D=3D 0) > >> ret =3D err; > >> diff --git a/drivers/media/v4l2-core/videobuf-dma-contig.c b/drivers/m= edia/v4l2-core/videobuf-dma-contig.c > >> index 52312ce2ba05..821c4a76ab96 100644 > >> --- a/drivers/media/v4l2-core/videobuf-dma-contig.c > >> +++ b/drivers/media/v4l2-core/videobuf-dma-contig.c > >> @@ -183,7 +183,7 @@ static int videobuf_dma_contig_user_get(struct vid= eobuf_dma_contig_memory *mem, > >> user_address =3D untagged_baddr; > >> > >> while (pages_done < (mem->size >> PAGE_SHIFT)) { > >> - ret =3D follow_pfn(vma, user_address, &this_pfn); > >> + ret =3D unsafe_follow_pfn(vma, user_address, &this_pfn); > >> if (ret) > >> break; > >> > >> > > >