Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1117852pxb; Fri, 20 Nov 2020 01:20:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJxSDlCT1bBsCAC5TO6+IlEkDvmo8nz1iDj2FP3fQPXnHko+97b2HYxFTVoMdu1uNxPCLr6V X-Received: by 2002:a05:6402:1284:: with SMTP id w4mr10198545edv.324.1605864052155; Fri, 20 Nov 2020 01:20:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605864052; cv=none; d=google.com; s=arc-20160816; b=pArMIhrgG0WxInWL0SF8mMf9p24haWYkP1SM1XFoTy37cc6YHaiJs2OmS4JfULzOeW 7TouPDO5iPJWqjMsSJvogqm10By/VybEWGEhahicus7ox15rrFbUx4jMRn+Mk9bJC3jJ G4SSlLeiA3h5KLlfLxQNAhgmYkqMmgTRKbZuxmH3F3XrtP46mer9PBPkL9nqbhsN6xJs aB591FY8rqiS+IHxoLZZgbsOSnKbAJ0X0BPmqhg0QNpItqwtx4oHKWKHl94+akKs0oBK 1bH9hQhZs4YL7WNIXqsTXSsrqP79q4JWvUfy9DjS6HbW7u0xIBnx4Bo2Fs3l8BrSYajK e8xQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=OtrYQoEiROvCqqv4Jka4JIhMwLKRXKEHuB2b3PjkDRI=; b=ZHvnMDMjGrwuEgOhA91c8993WcYie5PKXfpgh3j4xKzCAFmSpFzIXDx/cY1xE8TWIv u+JRD6G0peIEbPrFVcukcl27G95DOTy0o4lCtBy4laXzzIOCwLO9mOLswavcoV/JHvRN rhvbGUBL6dLNExdnqTSXS/7qo54Au5pNeigCMjvo+tRH450Zc2BPyxWnaSqrhkZFAw7I RlzaUGYHF7wF46HCMHLBlFNSRYtMgfP1RenpKr7fxiZ8/0mViICSStiGrk8yh5sRm7xb BUMn9g+4tqOBXQ0PhuY1ThELNHWmFFWbyFbNoP75dcQrmsFpmelsjzWUguzfno7c+waE 8zzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=H9pmf4ta; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m20si1212203ejg.474.2020.11.20.01.20.28; Fri, 20 Nov 2020 01:20:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=H9pmf4ta; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727285AbgKTJSn (ORCPT + 99 others); Fri, 20 Nov 2020 04:18:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726558AbgKTJSl (ORCPT ); Fri, 20 Nov 2020 04:18:41 -0500 Received: from mail-ot1-x342.google.com (mail-ot1-x342.google.com [IPv6:2607:f8b0:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAF75C0613CF for ; Fri, 20 Nov 2020 01:18:39 -0800 (PST) Received: by mail-ot1-x342.google.com with SMTP id g19so8075337otp.13 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=goh89ln+Tg8iKhOAEMGwFUDSWMcd4L2u7VtdWIdBkbVwTT2pI9tyI9IduPIUk8BTRT pA/n1hYbHU/JmoBRJh3ctNQJw3OAQhwcV//Laz1yEEyrmxGyZqde0yGp9zDu+WWdXgie 4Uk35dfTFL7mLeaAXPA/SYL91EmId9JG/vxZSCVFgZHJRqNLVhO3w8PZ2O7Uc0vDoOks LxcWbiI0DFvDMKf+7vH2I0iYLiSO0hDMlXQiJRoCJ5bm4/ari6rtQTgZ6K0n84RXTGvb mhh1HrlFHOVmL7YzT1Ab3KwAgl2G5UDWb7xDG7ZTnF0X8LgagsRucGmQn8le0w6JZopi e22A== X-Gm-Message-State: AOAM531t0muFa2pAWLjltK3JtoclU0LYAIylvrE5i6gnQnuME/kKPinC gpdG5YUTwP0e5elmN3FcnYxRA3/MGP5Bcpf4YFkFWg== 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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