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=-4.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 8ED6AC41604 for ; Wed, 7 Oct 2020 15:12:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C6E2A20797 for ; Wed, 7 Oct 2020 15:12:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="GQuHp0If" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C6E2A20797 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 15DBD900002; Wed, 7 Oct 2020 11:12:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 10EDD8E0001; Wed, 7 Oct 2020 11:12:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F1686900002; Wed, 7 Oct 2020 11:12:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0253.hostedemail.com [216.40.44.253]) by kanga.kvack.org (Postfix) with ESMTP id B96128E0001 for ; Wed, 7 Oct 2020 11:12:53 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 11658362B for ; Wed, 7 Oct 2020 15:12:53 +0000 (UTC) X-FDA: 77345471826.06.man53_5a0239a271d0 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin06.hostedemail.com (Postfix) with ESMTP id D181D100EF7C6 for ; Wed, 7 Oct 2020 15:12:52 +0000 (UTC) X-HE-Tag: man53_5a0239a271d0 X-Filterd-Recvd-Size: 10449 Received: from mail-lj1-f195.google.com (mail-lj1-f195.google.com [209.85.208.195]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Wed, 7 Oct 2020 15:12:52 +0000 (UTC) Received: by mail-lj1-f195.google.com with SMTP id l13so2327440ljg.10 for ; Wed, 07 Oct 2020 08:12:52 -0700 (PDT) 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; bh=qomXKB9LTOxqFLlUD4Oklytq/bQfaT6n1NJQmGHOKPw=; b=GQuHp0IfOJqhA6wU7mJvXeimN1VGvICbuBzTJeX8fXdXgvz+DrjhcqtOofhyX9/NY4 HMfgo+F9FVBNOZlXUgXeMbVrWYN+LfqH1bmUSPR0KO52FQno45bnDvvCtjz8zgHotyAQ M425Efq5uAraBx3glB+yx/tJ0SMWlV8QVMXJg= 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; bh=qomXKB9LTOxqFLlUD4Oklytq/bQfaT6n1NJQmGHOKPw=; b=LZWGlMc4/t6bt2ZRQt/azDsu5JytbdYGT9mXdMCspE3lwyeiy/9Vh0wKSWyknEicaM oexgLWwMcagiC0gcT2KmsCeIcAFyZH3xXJjwxCT8fjOhRtswj2ZDVBHNLxBCOY9g5y7K Qd1a3lv5NcZO3Ss3/V6zgD5yx3+hcDWaNjgyMs6qPr6zKm+QacEek8X0m1FBWsaNx1IT ZwBBnar19yTfWnzWV33eayBvUapIEnPastJhY9e9xYNwrpGKOcR/PRaGPd1tILQkW2om hcrVTNf18NhJOz7y5zCnx+FQWcVQ4jK40TxaCmMfr6R/0orq2a/gb/YHfBkl7UJh/7Rp nApg== X-Gm-Message-State: AOAM5336lUx6zkzbbb7I+GJpfDxv6lXwNF7TzKRSyB3LNv46WYvXxmdB 93gRMVQb0RdFh2uEYUVY88ME/eGfPXoeQA== X-Google-Smtp-Source: ABdhPJxQggi6TXv/p1mDh3D15qx+hpliNHJHhf7ZrNNrwP1uU0FkBU3G29eIab51Ms+OONdSMfNPgg== X-Received: by 2002:a2e:a588:: with SMTP id m8mr1348684ljp.210.1602083570103; Wed, 07 Oct 2020 08:12:50 -0700 (PDT) Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com. [209.85.208.175]) by smtp.gmail.com with ESMTPSA id f207sm378122lfd.47.2020.10.07.08.12.49 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 07 Oct 2020 08:12:49 -0700 (PDT) Received: by mail-lj1-f175.google.com with SMTP id f21so2336998ljh.7 for ; Wed, 07 Oct 2020 08:12:49 -0700 (PDT) X-Received: by 2002:adf:fe08:: with SMTP id n8mr3984098wrr.159.1602083132176; Wed, 07 Oct 2020 08:05:32 -0700 (PDT) MIME-Version: 1.0 References: <20201002233118.GM9916@ziepe.ca> <725819e9-4f07-3f04-08f8-b6180406b339@samsung.com> <20201007124409.GN5177@ziepe.ca> <20201007130610.GP5177@ziepe.ca> In-Reply-To: From: Tomasz Figa Date: Wed, 7 Oct 2020 17:05:19 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 2/2] mm/frame-vec: use FOLL_LONGTERM To: Daniel Vetter Cc: Jason Gunthorpe , Marek Szyprowski , DRI Development , LKML , Daniel Vetter , Andrew Morton , John Hubbard , =?UTF-8?B?SsOpcsO0bWUgR2xpc3Nl?= , Jan Kara , Dan Williams , Linux MM , Linux ARM , Pawel Osciak , Kyungmin Park , Inki Dae , Joonyoung Shim , Seung-Woo Kim , linux-samsung-soc , "open list:DMA BUFFER SHARING FRAMEWORK" , Oded Gabbay Content-Type: text/plain; charset="UTF-8" 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 Wed, Oct 7, 2020 at 4:23 PM Daniel Vetter wrote: > > On Wed, Oct 7, 2020 at 4:12 PM Tomasz Figa wrote: > > > > On Wed, Oct 7, 2020 at 4:09 PM Daniel Vetter wrote: > > > > > > On Wed, Oct 7, 2020 at 3:34 PM Tomasz Figa wrote: > > > > > > > > On Wed, Oct 7, 2020 at 3:06 PM Jason Gunthorpe wrote: > > > > > > > > > > On Wed, Oct 07, 2020 at 02:58:33PM +0200, Daniel Vetter wrote: > > > > > > On Wed, Oct 7, 2020 at 2:48 PM Tomasz Figa wrote: > > > > > > > > > > > > > > On Wed, Oct 7, 2020 at 2:44 PM Jason Gunthorpe wrote: > > > > > > > > > > > > > > > > On Wed, Oct 07, 2020 at 02:33:56PM +0200, Marek Szyprowski wrote: > > > > > > > > > Well, it was in vb2_get_vma() function, but now I see that it has been > > > > > > > > > lost in fb639eb39154 and 6690c8c78c74 some time ago... > > > > > > > > > > > > > > > > There is no guarentee that holding a get on the file says anthing > > > > > > > > about the VMA. This needed to check that the file was some special > > > > > > > > kind of file that promised the VMA layout and file lifetime are > > > > > > > > connected. > > > > > > > > > > > > > > > > Also, cloning a VMA outside the mm world is just really bad. That > > > > > > > > would screw up many assumptions the drivers make. > > > > > > > > > > > > > > > > If it is all obsolete I say we hide it behind a default n config > > > > > > > > symbol and taint the kernel if anything uses it. > > > > > > > > > > > > > > > > Add a big comment above the follow_pfn to warn others away from this > > > > > > > > code. > > > > > > > > > > > > > > Sadly it's just verbally declared as deprecated and not formally noted > > > > > > > anyway. There are a lot of userspace applications relying on user > > > > > > > pointer support. > > > > > > > > > > > > userptr can stay, it's the userptr abuse for zerocpy buffer sharing > > > > > > which doesn't work anymore. At least without major surgery (you'd need > > > > > > an mmu notifier to zap mappings and recreate them, and that pretty > > > > > > much breaks the v4l model of preallocating all buffers to make sure we > > > > > > never underflow the buffer queue). And static mappings are not coming > > > > > > back I think, we'll go ever more into the direction of dynamic > > > > > > mappings and moving stuff around as needed. > > > > > > > > > > Right, and to be clear, the last time I saw a security flaw of this > > > > > magnitude from a subsystem badly mis-designing itself, Linus's > > > > > knee-jerk reaction was to propose to remove the whole subsystem. > > > > > > > > > > Please don't take status-quo as acceptable, V4L community has to work > > > > > to resolve this, uABI breakage or not. The follow_pfn related code > > > > > must be compiled out of normal distro kernel builds. > > > > > > > > I think the userptr zero-copy hack should be able to go away indeed, > > > > given that we now have CMA that allows having carveouts backed by > > > > struct pages and having the memory represented as DMA-buf normally. > > > > > > Not sure whether there's a confusion here: dma-buf supports memory not > > > backed by struct page. > > > > > > > That's new to me. The whole API relies on sg_tables a lot, which in > > turn rely on struct page pointers to describe the physical memory. > > You're not allowed to look at struct page pointers from the importer > side, those might not be there. Which isn't the prettiest thing, but > it works. And even if there's a struct page, you're still not allowed > to look at it, since it's fully managed by the exporter under whatever > rules that might need. So no touching it, ever. > > This is also not news, supporting this was in the design brief from > the kickoff session 10+ years ago at some linaro connect thing (in > Budapest iirc). And we have implementations doing that for almost as > long merged in upstream. > > > > > How about the regular userptr use case, though? > > > > > > > > The existing code resolves the user pointer into pages by following > > > > the get_vaddr_frames() -> frame_vector_to_pages() -> > > > > sg_alloc_table_from_pages() / vm_map_ram() approach. > > > > get_vaddr_frames() seems to use pin_user_pages() behind the scenes if > > > > the vma is not an IO or a PFNMAP, falling back to follow_pfn() > > > > otherwise. > > > > > > Yeah pin_user_pages is fine, it's just the VM_IO | VM_PFNMAP vma that > > > don't work. > > > > Ack. > > > > > > > > > > Is your intention to drop get_vaddr_frames() or we could still keep > > > > using it and if vec->is_pfns is true: > > > > a) if CONFIG_VIDEO_LEGACY_PFN_USERPTR is set, taint the kernel > > > > b) otherwise just undo and fail? > > > > > > I'm typing that patch series (plus a pile more) right now. > > > > Cool, thanks! > > > > We also need to bring back the vma_open() that somehow disappeared > > around 4.2, as Marek found. > > The vm_open isn't enough to stop the problems (it doesn't and cannot > protect against unmap_mapping_range), I don't think keeping an > incomplete solution around has much benefit. People who need this can > disable CONFIG_STRICT_FOLLOW_PFN to keep things working, everyone else > probably doesn't want these mm internals leaking into the media > subsystem. Okay, I think I mixed up the two different threads in the earlier discussion. Since pin_user_pages() would atomically look up and pin the underlying pages, we should be fine, so that vm_open() was only needed for the bad follow_pfn path. Best regards, Tomasz