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,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 8D615C63798 for ; Fri, 20 Nov 2020 09:18:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 329AD223AC for ; Fri, 20 Nov 2020 09:18:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="H9pmf4ta" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 329AD223AC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 522A96B005C; Fri, 20 Nov 2020 04:18:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4D3126B0070; Fri, 20 Nov 2020 04:18:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3737D6B0072; Fri, 20 Nov 2020 04:18:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0121.hostedemail.com [216.40.44.121]) by kanga.kvack.org (Postfix) with ESMTP id EC5C66B005C for ; Fri, 20 Nov 2020 04:18:41 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 73126180AD838 for ; Fri, 20 Nov 2020 09:18:41 +0000 (UTC) X-FDA: 77504246442.06.mint38_5302ac02734a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin06.hostedemail.com (Postfix) with ESMTP id 5899210044BDF for ; Fri, 20 Nov 2020 09:18:41 +0000 (UTC) X-HE-Tag: mint38_5302ac02734a X-Filterd-Recvd-Size: 9842 Received: from mail-ot1-f66.google.com (mail-ot1-f66.google.com [209.85.210.66]) by imf07.hostedemail.com (Postfix) with ESMTP for ; Fri, 20 Nov 2020 09:18:40 +0000 (UTC) Received: by mail-ot1-f66.google.com with SMTP id l36so8134109ota.4 for ; Fri, 20 Nov 2020 01:18:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=OtrYQoEiROvCqqv4Jka4JIhMwLKRXKEHuB2b3PjkDRI=; b=H9pmf4taWGwhJj0TCPHRqUSjU70cWnKJjp7fPbvY9crHvLcESWQq3LyuXCxK4oLrKU cE0KMzfuWCfbRfL+I6J1/V6V741Gq4+hcyfquL+KRX7CcWHTILWoG6kc2xEtShyJEd6T 7BjZeDAZNI4WxIxvtHfYIUlI9hmefqlvmBIDQ= 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=OtrYQoEiROvCqqv4Jka4JIhMwLKRXKEHuB2b3PjkDRI=; b=LLgEq+rS7NBxdckxljNA3bEuAv8mv/ZenP1Rq60VeEixYq1BYBe36u6xA2IXz+lM5K nPt83hUX62Om/VFik69lsiNAjSP6LlrRvWJuOve26+URjkmFmxPEQW6SmqxWx/lBuW17 45jZ1U7fGzZSbqhFCVTdQelBCiiotlgkFgjP80LOtJ5IIf2jCAGJD2QY/53TpxlUDOQn ufsgEcPpS6KEk5i2yxLMKSobCj/yT3qGWvKL79lBxohEsm5rv7iKWhDIhCtyugpykmZU qlrHsxZlL2fNqIyo64uFh0WmR6ELcvB5FmeUzx1y1nMYZpfSUdMEszTTCX5ZNUZpV6n4 fIwA== X-Gm-Message-State: AOAM5324z02p/C6SjV3stZL5boywW4bJvwnmE2cmMIKxfWwK30wqBDNw 3h+UMehFTikeJHqFg7QMM4+44TsiNFlI+wylxkHGoA== X-Google-Smtp-Source: ABdhPJwRO5d84BxTeYThG2QPCXAsJdc+1sEa8OQumtyte52NF7Ay2wUea1iF99xa2TqGcNyZBAN0DrcCHGfwp68L+Co= X-Received: by 2002:a05:6830:3155:: with SMTP id c21mr13756463ots.281.1605863919326; Fri, 20 Nov 2020 01:18:39 -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: Daniel Vetter Date: Fri, 20 Nov 2020 10:18:27 +0100 Message-ID: Subject: Re: [PATCH v6 09/17] media/videbuf1|2: Mark follow_pfn usage as unsafe To: Hans Verkuil Cc: DRI Development , LKML , KVM list , Linux MM , Linux ARM , linux-samsung-soc , "open list:DMA BUFFER SHARING FRAMEWORK" , Tomasz Figa , 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 9:28 AM 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 happy to add a comment, but otherwise if you all want to ditch this, can we do this as a follow up on top? There's quite a bit of code that can be deleted and I'd like to not hold up this patch set here on that - it's already a fairly sprawling pain touching about 7 different subsystems (ok only 6-ish now since the s390 patch landed). For the comment, is the explanation next to unsafe_follow_pfn not good enough? So ... can I get you to un-cancel your ack? Thanks, Daniel > > 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; > >> > >> > > > --=20 Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch