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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4CA93C6FD18 for ; Wed, 19 Apr 2023 17:47:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 933DB900004; Wed, 19 Apr 2023 13:47:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8E373900003; Wed, 19 Apr 2023 13:47:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7AB4F900004; Wed, 19 Apr 2023 13:47:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6CBCC900003 for ; Wed, 19 Apr 2023 13:47:24 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 3937FA03DC for ; Wed, 19 Apr 2023 17:47:24 +0000 (UTC) X-FDA: 80698872408.20.43AEC88 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) by imf30.hostedemail.com (Postfix) with ESMTP id 4406780015 for ; Wed, 19 Apr 2023 17:47:22 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=kkzmwfcz; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf30.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.54 as permitted sender) smtp.mailfrom=lstoakes@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681926442; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=foa53WKZC60JspXp1EgnvL6+H+mX7HMNrIjNztz1zm0=; b=7bCT7UfzgI1j5l6b3FveHFz8H4nUD8b4j+V2RsqA/5Wzp2AN97kExriZeHxiQwYxVziNn1 R1svn+CBwBeBtgxlxT2/bDAWJYSWWfeVcmFnAgr9ST3i5JW+ffzAxKZipJISQWYJeA5oJs m5hTPHXbk2KLLFJibQ4p6/DqfQ1wb48= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=kkzmwfcz; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf30.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.54 as permitted sender) smtp.mailfrom=lstoakes@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681926442; a=rsa-sha256; cv=none; b=GnCFSbHl14Q/5jqejKOtqaCV9x84dmtbybMs9dBYMwG7VxkZpD92vWmRZkBdEb2y95rqHc XjzdwFrDhQ9YqkoVkx23Uid227xO4jOAmA0nTrqogHGZ2GsdzOKA6imbwZ5n7qjckX+KRI WXZE6lJ+C7B+jfGsT1YfhAojoDNs/z0= Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-3f178da21b5so309785e9.3 for ; Wed, 19 Apr 2023 10:47:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681926441; x=1684518441; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=foa53WKZC60JspXp1EgnvL6+H+mX7HMNrIjNztz1zm0=; b=kkzmwfcz+S/rE6WazwmwiRT0Pyl8gJRjiGcIS6xLzTnBDByiDpe7AfzETde8Rkflxu 6grjRNkaJ0ZjOjUj8qFopQxWw2zXXdO3Wxt0zhGJlBSAkMbIrlvZ9P2ssBx+grOnkDSG TtBw+oxdy9utVeiD1TzxtedKHV/eNExAywSngFQPgCSnMb1KW5atp5nPQ71x6FFEiHA7 UFDtP6PH99QI/oy1SyO7dGW6G+KUAgWSHpJvmR0NF2APY/h7PvpPJiAZEYaVy0jahvSE FBpbc5GxD4XD2gnl5S8/SFLYK/P0ZSJy4At0ycSTOsUWO2EwQqW0QpbzS2ExOlsKd8Zd SlHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681926441; x=1684518441; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=foa53WKZC60JspXp1EgnvL6+H+mX7HMNrIjNztz1zm0=; b=YIsX3HiiHp/kVt70tP/iQRcwP73/JHxYn6uNPE/obf4N0dH3FmleoxpDLmhYwCnmXD Kvs03xnmhvNEuRlFfkatrk6q8Xn5QOdmWmf4m5Auv2M2eXWWwpCnA2W8DXhPox6nwvRT Di6BG9nXf4fZtF2yBB3hEwJC1FxBXcdhLSCXyBnX2laynVnnc4vA7lsaBQLmcxixjHp3 6AihB6iwQMmXAlGQ23vJiRTKszYYhIsH1T5/xZ7ZqyfdEmcXhWjvVX5x4fcA+HdTWabv w+KfPWXP4QULet3A4nL4okm2MkSRi/fPNu9UjHTifPrBtKQHtqi+2nJUUeRqYfokCrrG 3Y/Q== X-Gm-Message-State: AAQBX9ekHQe5TTXCjPdSmcbv+1DgLbm5mVptL+tA1+Xq5bs+pjLZZN/l xrldaciubxcH1cRnVj1KkQc= X-Google-Smtp-Source: AKy350YXGjQs5LfN7GPboqOO260zQNSJ7enU8x2xyAqdAF7LVSt1PBKM4vvwSrK2nEECIruNreMzNg== X-Received: by 2002:adf:e84d:0:b0:2f2:542a:6f50 with SMTP id d13-20020adfe84d000000b002f2542a6f50mr5629437wrn.56.1681926440598; Wed, 19 Apr 2023 10:47:20 -0700 (PDT) Received: from localhost ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.gmail.com with ESMTPSA id b2-20020adfe302000000b002fae2a08089sm7732368wrj.70.2023.04.19.10.47.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 10:47:19 -0700 (PDT) Date: Wed, 19 Apr 2023 18:47:18 +0100 From: Lorenzo Stoakes To: Jens Axboe Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Matthew Wilcox , David Hildenbrand , Pavel Begunkov , io-uring@vger.kernel.org, Jason Gunthorpe Subject: Re: [PATCH v4 4/6] io_uring: rsrc: avoid use of vmas parameter in pin_user_pages() Message-ID: References: <956f4fc2204f23e4c00e9602ded80cb4e7b5df9b.1681831798.git.lstoakes@gmail.com> <936e8f52-00be-6721-cb3e-42338f2ecc2f@kernel.dk> <69f48cc6-8fc6-0c49-5a79-6c7d248e4ad5@kernel.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <69f48cc6-8fc6-0c49-5a79-6c7d248e4ad5@kernel.dk> X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 4406780015 X-Stat-Signature: uh1unxt1jqdqwq6ujyny3ocyq9hz6omr X-HE-Tag: 1681926442-504592 X-HE-Meta: U2FsdGVkX19Ktb57BBHd09mUWaZQukLDbUcKTRNrvI58QaJOwL0NpoJyyVVw7weu2zUwP+j8iBLVLeAJG8hGIZUtAhnqaT0n4QDmag51hopSlYgj/CsvGDtw825aDo2fhUIZt3Ze6Ssxyb4v40i6ttbxF/gCxJnTRkWXhvrGqTtmRG8167eJPvKps6E1Jhtumkue/DC+PuIIUzgUO7qWykU2k4HYzIxVJvudPvETkgzmwFePu14Z3DWP9ZR6Cc21NOQJ8a8V5f7GZtcUJyCUwHPRyotezetknHNLs3XVr450mfUnsmXnLOvMHGyulRKiGNbDKLGSdTsfbeAtF0pnO2p2skzNBHw8Iy3mm6Q4VO9jCOF36/mnUTpfDVgprYdhtDovbFOUDH4j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1fgjpAxFW6kdN30N+CzolzM7M++nSCa+njGl6iovX2Zhyrg== 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, Apr 19, 2023 at 11:35:58AM -0600, Jens Axboe wrote: > On 4/19/23 11:23?AM, Lorenzo Stoakes wrote: > > On Wed, Apr 19, 2023 at 10:59:27AM -0600, Jens Axboe wrote: > >> On 4/19/23 10:35?AM, Jens Axboe wrote: > >>> On 4/18/23 9:49?AM, Lorenzo Stoakes wrote: > >>>> We are shortly to remove pin_user_pages(), and instead perform the required > >>>> VMA checks ourselves. In most cases there will be a single VMA so this > >>>> should caues no undue impact on an already slow path. > >>>> > >>>> Doing this eliminates the one instance of vmas being used by > >>>> pin_user_pages(). > >>> > >>> First up, please don't just send single patches from a series. It's > >>> really annoying when you are trying to get the full picture. Just CC the > >>> whole series, so reviews don't have to look it up separately. > >>> > >>> So when you're doing a respin for what I'll mention below and the issue > >>> that David found, please don't just show us patch 4+5 of the series. > >> > >> I'll reply here too rather than keep some of this conversaion > >> out-of-band. > >> > >> I don't necessarily think that making io buffer registration dumber and > >> less efficient by needing a separate vma lookup after the fact is a huge > >> deal, as I would imagine most workloads register buffers at setup time > >> and then don't change them. But if people do switch sets at runtime, > >> it's not necessarily a slow path. That said, I suspect the other bits > >> that we do in here, like the GUP, is going to dominate the overhead > >> anyway. > > > > Thanks, and indeed I expect the GUP will dominate. > > Unless you have a lot of vmas... Point is, it's _probably_ not a > problem, but it might and it's making things worse for no real gain as > far as I can tell outside of some notion of "cleaning up the code". > > >> My main question is, why don't we just have a __pin_user_pages or > >> something helper that still takes the vmas argument, and drop it from > >> pin_user_pages() only? That'd still allow the cleanup of the other users > >> that don't care about the vma at all, while retaining the bundled > >> functionality for the case/cases that do? That would avoid needing > >> explicit vma iteration in io_uring. > >> > > > > The desire here is to completely eliminate vmas as an externally available > > parameter from GUP. While we do have a newly introduced helper that returns > > a VMA, doing the lookup manually for all other vma cases (which look up a > > single page and vma), that is more so a helper that sits outside of GUP. > > > > Having a separate function that still bundled the vmas would essentially > > undermine the purpose of the series altogether which is not just to clean > > up some NULL's but rather to eliminate vmas as part of the GUP interface > > altogether. > > > > The reason for this is that by doing so we simplify the GUP interface, > > eliminate a whole class of possible future bugs with people holding onto > > pointers to vmas which may dangle and lead the way to future changes in GUP > > which might be more impactful, such as trying to find means to use the fast > > paths in more areas with an eye to gradual eradication of the use of > > mmap_lock. > > > > While we return VMAs, none of this is possible and it also makes the > > interface more confusing - without vmas GUP takes flags which define its > > behaviour and in most cases returns page objects. The odd rules about what > > can and cannot return vmas under what circumstances are not helpful for new > > users. > > > > Another point here is that Jason suggested adding a new > > FOLL_ALLOW_BROKEN_FILE_MAPPINGS flag which would, by default, not be > > set. This could assert that only shmem/hugetlb file mappings are permitted > > which would eliminate the need for you to perform this check at all. > > > > This leads into the larger point that GUP-writing file mappings is > > fundamentally broken due to e.g. GUP not honouring write notify so this > > check should at least in theory not be necessary. > > > > So it may be the case that should such a flag be added this code will > > simply be deleted at a future point :) > > Why don't we do that first then? There's nothing more permanent than a > temporary workaround/fix. Once it's in there, motivation to get rid of > it for most people is zero because they just never see it. Seems like > that'd be a much saner approach rather than the other way around, and > make this patchset simpler/cleaner too as it'd only be removing code in > all of the callers. > Because I'd then need to audit all GUP callers to see whether they in some way brokenly access files in order to know which should and should not use this new flag. It'd change this series from 'remove the vmas parameter' to something a lot more involved. I think it's much safer to do the two separately, as I feel that change would need quite a bit of scrutiny too. As for temporary, I can assure you I will be looking at introducing this flag, for what it's worth :) and Jason is certainly minded to do work in this area also. > -- > Jens Axboe >