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=ham 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 5E8CFC63798 for ; Fri, 20 Nov 2020 08:33:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DC8D222249 for ; Fri, 20 Nov 2020 08:33:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="b0w6ldKp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726719AbgKTIdG (ORCPT ); Fri, 20 Nov 2020 03:33:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726321AbgKTIdF (ORCPT ); Fri, 20 Nov 2020 03:33:05 -0500 Received: from mail-ej1-x644.google.com (mail-ej1-x644.google.com [IPv6:2a00:1450:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CEB2C0613CF for ; Fri, 20 Nov 2020 00:33:04 -0800 (PST) Received: by mail-ej1-x644.google.com with SMTP id f20so11719325ejz.4 for ; Fri, 20 Nov 2020 00:33:04 -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=pO+DEYPPqelzI9zcwK5RRN91Ld58ikInFuJkUwe5AItc89BlpYsWQwARl6zFFgdZJV eVGtz5BpmdY6YXUtRpoAO/8qyh242mc0ZV/hzlV1y2/MoHdCiBHvxwFYA2OXfpIBGNIA KnraYMzrqAXMWQsAuFxgnWktIb9/nQd77CGlgkJuyJDCRqPeshC1RiLqug4VTCfpG1d/ Rcy1ybLrqwQ8A7kobnaL4TiGdPiI25z+WC5DvvcMbdvAw5fzK/vcCOi5leDUeHW+mC72 r8ARwKza9Kx2aOfaPf43UHjDmLCMc13aVzJ76KsTqo0RCnPSMCB59JK8UGAiLdNyoHw6 kAUw== X-Gm-Message-State: AOAM53337Cs80i+zVBxdCFNwD1ViAijrz6FjHnQP5idKRaRiJZJfAoth 1N2myPozgJ+PstyS1kRlXH+rKQA2STs8RQ== X-Google-Smtp-Source: ABdhPJzcFB/lPSrQIbdA7+kzX52LGBN8ejaKu9bpqnGMfvRyGtgpBun6tOA4Fqull+PI0JBRvI3Q1A== X-Received: by 2002:a17:907:396:: with SMTP id ss22mr16414769ejb.24.1605861182678; Fri, 20 Nov 2020 00:33:02 -0800 (PST) Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com. [209.85.221.53]) by smtp.gmail.com with ESMTPSA id 65sm773073edj.83.2020.11.20.00.33.01 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 20 Nov 2020 00:33:01 -0800 (PST) Received: by mail-wr1-f53.google.com with SMTP id o15so9147574wru.6 for ; Fri, 20 Nov 2020 00:33:01 -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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; > >> > >> > > >