Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6026560rwb; Tue, 22 Nov 2022 07:54:28 -0800 (PST) X-Google-Smtp-Source: AA0mqf4R02yf+6PV7fd8ohBQJMq1eMExExQQTYCyeXCF19UwDCuVTLh4lX0BKyomuKMF9EQwE9NQ X-Received: by 2002:a17:907:2105:b0:7a1:1c24:e566 with SMTP id qn5-20020a170907210500b007a11c24e566mr20093304ejb.360.1669132468559; Tue, 22 Nov 2022 07:54:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669132468; cv=none; d=google.com; s=arc-20160816; b=EUg/AuQqC/0rkoJuh9LBjgvObnT8blvkmPAHIm0wIek8yl3+3pXm04vGV1sP2JJX0g Aclbpbm83Bu0ylkeqS7Mgfjh6oU+N9HIB80ZJRfbhMD6JV3B1qZsUZaBNWAqOLeN6dBP npUgyPN64uikCqE1BeFDM5FNxpg71+x6U4fHZE2n5J/eX27+Q61poa5cg8Cm5xdNBOe9 hHUsE8vQwe5VaT+64wSIimDbjKIBu7xELVC7L9eO5QZzKAopNzKYSWCK9Ky49wcaG9s/ OQ4tqy6GkQDLVg3CimYhnH2TK/ikWBl/gCWtpp1GpRyWK5+SpcfMPA6ec73x6nXvIu3h vPkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=In9GuqAn29oXIcP45h0iG42nfIf4b++tYbTcRtB/XTA=; b=pt52EL3Lt98g3soEqkZ8E3jDNVTV/S6J1yqlJK7tJ/sbbNlYxaW1f0EuJSUzpmUr4H PAHayPwk/ypqvOLPmfPBPuCDsHpBezwQv7mw9Yrb74WGcA4lHXUyASOnGSoApyOty2Ts qBK/eY0jiUofFE/wKQ8mfMHMwt1jiVMGyA69DDkOWEKTGAbTgfP0wdKECn6WWMpurinN qdqEOUpyDr/Xz1zcluNRCGp7HxUIx66asqjBHJ/nsmVD6S7rZs0xRb2c6+rRGgF7mQ04 1qoij0quPaunrlHbkvLy4CXcsOXGgl3ueSgHsHfZY5aha4Dsuq/69PlPFJnNsm7RLUcW teEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UoDFTxlR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z16-20020a056402275000b00462d53d6de6si13673476edd.10.2022.11.22.07.54.05; Tue, 22 Nov 2022 07:54:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UoDFTxlR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232192AbiKVPFR (ORCPT + 90 others); Tue, 22 Nov 2022 10:05:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233239AbiKVPFJ (ORCPT ); Tue, 22 Nov 2022 10:05:09 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D68806CA34 for ; Tue, 22 Nov 2022 07:03:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669129425; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=In9GuqAn29oXIcP45h0iG42nfIf4b++tYbTcRtB/XTA=; b=UoDFTxlRvUIM05y6A5yE5XXaLyXml2Cxe/arzQDZlxTTH03LIX4fJuqGecGKCSdtWpxTll eTQrSjBNwxzy/eO7lNVPU9AMbvZFYHNy4wCKbGmA5VkBXaTWNgFxvkEJlos+G2BJI9LvnJ J1A4Vg21FuvaOs8zOXXKeoocJNIeCFs= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-216-qFeraKSAPjaWyOIDUIhJuw-1; Tue, 22 Nov 2022 10:03:43 -0500 X-MC-Unique: qFeraKSAPjaWyOIDUIhJuw-1 Received: by mail-wr1-f72.google.com with SMTP id g14-20020adfa48e000000b00241bfca9693so3360459wrb.8 for ; Tue, 22 Nov 2022 07:03:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=In9GuqAn29oXIcP45h0iG42nfIf4b++tYbTcRtB/XTA=; b=US03WvZ0wpf3YxAv/94LL+Mytav1udNIKWOCgcwTLVFUbThpatc5Xy+tqugXa18Az/ wXjfm3h5tN4XWy44Fw5mjfaizY0j5qa87zxaRVIXUVHwEydPw2Olw+fIlVue2N/5VqRY 69Pb0/l7P8ntEPQOE3nKfYt5u1FQC8+TScEIUmMQifutr7W2vYyhZlMF+41MrIQU/8r8 6c6UrZVlH6WXXVEAiXlIjUwoW0D9ItknU7+G3dZUWUpmbOo336i7hoZadGUFeCdWXISX IMSC8uNRoRgYBd6/7amPU1FHTE2QVCPGZ7NJ/ncbg66FRORqtAphFaT/tAFRW3u71if1 JI2g== X-Gm-Message-State: ANoB5pnLRU0Q8rL/dJm+sJ9bZhDnA+IpJFSp8fNnKw6U5NECqDHeBPjJ gEWfRT0dtMp+gDX7DXM8FQXntjpW9LLUQ9X6/XEuW1OsNZf4OgEuYsKuQ72lRQAWnVuSSO6Sc8+ rlaY+4xEwJhbWIXyIbBqtk+UP X-Received: by 2002:adf:ea4d:0:b0:22e:38b9:5d6d with SMTP id j13-20020adfea4d000000b0022e38b95d6dmr4031726wrn.276.1669129422177; Tue, 22 Nov 2022 07:03:42 -0800 (PST) X-Received: by 2002:adf:ea4d:0:b0:22e:38b9:5d6d with SMTP id j13-20020adfea4d000000b0022e38b95d6dmr4031700wrn.276.1669129421815; Tue, 22 Nov 2022 07:03:41 -0800 (PST) Received: from ?IPV6:2003:cb:c706:c300:b066:75e3:f1d2:b69b? (p200300cbc706c300b06675e3f1d2b69b.dip0.t-ipconnect.de. [2003:cb:c706:c300:b066:75e3:f1d2:b69b]) by smtp.gmail.com with ESMTPSA id l13-20020a5d668d000000b00236488f62d6sm14289929wru.79.2022.11.22.07.03.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 22 Nov 2022 07:03:41 -0800 (PST) Message-ID: <56fecbe9-ecf1-bdac-4e05-4767aa9d4386@redhat.com> Date: Tue, 22 Nov 2022 16:03:39 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: Re: [PATCH RFC 16/19] mm/frame-vector: remove FOLL_FORCE usage Content-Language: en-US To: Hans Verkuil , Tomasz Figa , Marek Szyprowski Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, linux-rdma@vger.kernel.org, linux-media@vger.kernel.org, linux-kselftest@vger.kernel.org, Linus Torvalds , Andrew Morton , Jason Gunthorpe , John Hubbard , Peter Xu , Greg Kroah-Hartman , Andrea Arcangeli , Hugh Dickins , Nadav Amit , Vlastimil Babka , Matthew Wilcox , Mike Kravetz , Muchun Song , Lucas Stach , David Airlie , Oded Gabbay , Arnd Bergmann , Mauro Carvalho Chehab References: <20221107161740.144456-1-david@redhat.com> <20221107161740.144456-17-david@redhat.com> <6175d780-3307-854c-448a-8e6c7ad0772c@xs4all.nl> <6ace6cd4-3e13-8ec1-4c2a-49e2e14e81a6@redhat.com> <4d3ef082-f7b3-2b6e-6fcf-5f991ffe14e9@xs4all.nl> From: David Hildenbrand Organization: Red Hat In-Reply-To: <4d3ef082-f7b3-2b6e-6fcf-5f991ffe14e9@xs4all.nl> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 22.11.22 15:07, Hans Verkuil wrote: > On 11/22/22 13:38, David Hildenbrand wrote: >> On 22.11.22 13:25, Hans Verkuil wrote: >>> Hi Tomasz, David, >>> >>> On 11/8/22 05:45, Tomasz Figa wrote: >>>> Hi David, >>>> >>>> On Tue, Nov 8, 2022 at 1:19 AM David Hildenbrand wrote: >>>>> >>>>> FOLL_FORCE is really only for debugger access. According to commit >>>>> 707947247e95 ("media: videobuf2-vmalloc: get_userptr: buffers are always >>>>> writable"), the pinned pages are always writable. >>>> >>>> Actually that patch is only a workaround to temporarily disable >>>> support for read-only pages as they seemed to suffer from some >>>> corruption issues in the retrieved user pages. We expect to support >>>> read-only pages as hardware input after. That said, FOLL_FORCE doesn't >>>> sound like the right thing even in that case, but I don't know the >>>> background behind it being added here in the first place. +Hans >>>> Verkuil +Marek Szyprowski do you happen to remember anything about it? >>> >>> I tracked the use of 'force' all the way back to the first git commit >>> (2.6.12-rc1) in the very old video-buf.c. So it is very, very old and the >>> reason is lost in the mists of time. >>> >>> I'm not sure if the 'force' argument of get_user_pages() at that time >>> even meant the same as FOLL_FORCE today. From what I can tell it has just >>> been faithfully used ever since, but I have my doubt that anyone understands >>> the reason behind it since it was never explained. >>> >>> Looking at this old LWN article https://lwn.net/Articles/28548/ suggests >>> that it might be related to calling get_user_pages for write buffers >>> (non-zero write argument) where you also want to be able to read from the >>> buffer. That is certainly something that some drivers need to do post-capture >>> fixups. >>> >>> But 'force' was also always set for read buffers, and I don't know if that >>> was something that was actually needed, or just laziness. >>> >>> I assume that removing FOLL_FORCE from 'FOLL_FORCE|FOLL_WRITE' will still >>> allow drivers to read from the buffer? >> >> Yes. The only problematic corner case I can imagine is if someone has a >> VMA without write permissions (no PROT_WRITE/VM_WRITE) and wants to pin >> user space pages as a read buffer. We'd specify now FOLL_WRITE without >> FOLL_FORCE and GUP would reject that: write access without write >> permissions is invalid. > > I do not believe this will be an issue. > >> >> There would be no way around "fixing" this implementation to not specify >> FOLL_WRITE when only reading from user-space pages. Not sure what the >> implications are regarding that corruption that was mentioned in >> 707947247e95. > > Before 707947247e95 the FOLL_WRITE flag was only set for write buffers > (i.e. video capture, DMA_FROM_DEVICE), not for read buffers (video output, > DMA_TO_DEVICE). In the video output case there should never be any need > for drivers to write to the buffer to the best of my knowledge. > > But I have had some complaints about that commit that it causes problems > in some scenarios, and it has been on my todo list for quite some time now > to dig deeper into this. I probably should prioritize this for this or > next week. > >> >> Having said that, I assume such a scenario is unlikely -- but you might >> know better how user space usually uses this interface. There would be >> three options: >> >> 1) Leave the FOLL_FORCE hack in for now, which I *really* want to avoid. >> 2) Remove FOLL_FORCE and see if anybody even notices (this patch) and >> leave the implementation as is for now. >> 3) Remove FOLL_FORCE and fixup the implementation to only specify >> FOLL_WRITE if the pages will actually get written to. >> >> 3) would most probably ideal, however, I am no expert on that code and >> can't do it (707947247e95 confuses me). So naive me would go with 2) first. >> > > Option 3 would be best. And 707947247e95 confuses me as well, and I actually > wrote it :-) I am wondering whether it was addressed at the right level, but > as I said, I need to dig a bit deeper into this. Cool, let me know if I can help! -- Thanks, David / dhildenb