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 02966C77B61 for ; Mon, 24 Apr 2023 23:03:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 732956B0072; Mon, 24 Apr 2023 19:03:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6BE0A6B0074; Mon, 24 Apr 2023 19:03:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 534F96B0075; Mon, 24 Apr 2023 19:03:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 3F3BB6B0072 for ; Mon, 24 Apr 2023 19:03:40 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id F06EF1403EA for ; Mon, 24 Apr 2023 23:03:39 +0000 (UTC) X-FDA: 80717813358.03.5F87606 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) by imf10.hostedemail.com (Postfix) with ESMTP id 2A166C0018 for ; Mon, 24 Apr 2023 23:03:37 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b="EuHX7Z/v"; spf=pass (imf10.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.53 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682377418; a=rsa-sha256; cv=none; b=QkGtha/VvyJLvc7npAdy9lVuymistDx1G4FGRpYc0LszbmRs+x5qi6Di46WMqOB00xHIg1 9ax5niEn0L9hwjW/oogoMrqb1uixpHWIcEIYpK7wec8XN4R1CsopKJng8zdLAmOnFJIHPs rd1KhYNJVMSVScCrVSxr2nBJbc32bGs= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b="EuHX7Z/v"; spf=pass (imf10.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.53 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1682377418; 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=P0nMjLjJ2Ejf4Gum9iKdCO8GGAzyEOx1mv4U4DYV4qE=; b=cBEEueJ/sqqTJpRCVanaDuTMqk0jLVQ/IbM7y9IynTUYlVqBOZ3pB75c9pZ54d+U4EeFPC 8YfMcV6am5fnzp3d3MeHS9IfK0PUlExmvQroSQ4nB1puCT1a39ZY5UiYxhrRq9Jgr2+Rc4 9WFrvY6Kj1SqPGZZEjoeiUK+wySda1Q= Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-2f8405b3dc1so3034112f8f.3 for ; Mon, 24 Apr 2023 16:03:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682377416; x=1684969416; 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=P0nMjLjJ2Ejf4Gum9iKdCO8GGAzyEOx1mv4U4DYV4qE=; b=EuHX7Z/vAZocfhu4Vgyz49xCCl2q92HT9jd7KAaQxRyLHLUDRyT1hLjdT5+bk3UXb0 RFVUJ3ICo+HD9jfBMqoShj5ln64HLYckW5U9H24eAMXOLV1BEJbCwqLJuTDq6xty7NGx cGvpM8DB3RDh7Anccmdge6TYaiqUOxvmmyhgkXDnFgOqaphLKnqe1pFzz2iZPuivObec d6L6S3mBEuw6NA3pUpIwzfSFUsz6ErK0neRJMH6NkT5PpgVYsoczXw7CprHX7Pi5SDm4 QRRzJc/IHUy0nKhvW1yl2PtKcHCvXN4Y9BysJ8M0UHc3XfJiEv7dAKHcYsyju0hSDT73 Tekw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682377416; x=1684969416; 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=P0nMjLjJ2Ejf4Gum9iKdCO8GGAzyEOx1mv4U4DYV4qE=; b=Ey6gl+HASvuio40gBYOLjyfHonn2So7kO7R+0EBTRVyBbfxtoAvoShmqM0Jr4PKsFK 9r8gVNCpN9VSXqhC0CWKnigvcvCqg72vo6RdtmLkNKaeM8AJwbEZLe0RhvjxJEPSUve4 yheyczFVdwyyf6PyPdtEACOW3/N4r1pD6otG+11Sguqjn6fHrDtB9K9CzN9EpWjo4IoD BTbjqDHIKXYGab3zi8Qu0XeAmm3cWTrYDiXOE+G9O1G8xqLl1cNqixK2aeCvjIj9999W 8id2oqI0c9P8dBIlk0omPx3/9UsFNJEfE00+ckVNR+njsVv/DLgM0tOqvRl+7Mes6d6R HWhQ== X-Gm-Message-State: AAQBX9e+4pRNOa+tIMWFLAdvKAhEQ80n+iMfB/0Ij6JAURB9OfzgoyBr TuC0Nzgqg9tkVhfbizUkZJI= X-Google-Smtp-Source: AKy350bEw1oYBxZ1aQpLH2RCWXylid0vlvZ0fQa3JAem1BWm3uFPUGdsWn5khS006UqQkx6YbrWY7A== X-Received: by 2002:adf:f185:0:b0:2f4:cfb4:57f7 with SMTP id h5-20020adff185000000b002f4cfb457f7mr9983848wro.61.1682377416362; Mon, 24 Apr 2023 16:03:36 -0700 (PDT) Received: from localhost (host86-156-84-164.range86-156.btcentralplus.com. [86.156.84.164]) by smtp.gmail.com with ESMTPSA id g3-20020a5d5543000000b002fe254f6c33sm11648252wrw.92.2023.04.24.16.03.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Apr 2023 16:03:35 -0700 (PDT) Date: Tue, 25 Apr 2023 00:03:34 +0100 From: Lorenzo Stoakes To: Jason Gunthorpe Cc: Christoph Hellwig , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Jens Axboe , Matthew Wilcox , Dennis Dalessandro , Leon Romanovsky , Christian Benvenuti , Nelson Escobar , Bernard Metzler , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Bjorn Topel , Magnus Karlsson , Maciej Fijalkowski , Jonathan Lemon , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Christian Brauner , Richard Cochran , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , linux-fsdevel@vger.kernel.org, linux-perf-users@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, Oleg Nesterov Subject: Re: [PATCH v2] mm/gup: disallow GUP writing to file-backed mappings by default Message-ID: <4f16b1fc-6bc5-4e41-8e94-151c336fcf69@lucifer.local> References: <90a54439-5d30-4711-8a86-eba816782a66@lucifer.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Rspamd-Queue-Id: 2A166C0018 X-Rspamd-Server: rspam01 X-Stat-Signature: k3bn3cb86jphba9tm967bxjgxqhseu4j X-HE-Tag: 1682377417-637568 X-HE-Meta: U2FsdGVkX1/F2S5wxFUJdldNTYhcN7y6s7HGSEtI7wdRYIhvp8dssn4pKuZe+5AaIzIGiu+qkj40y+KTlSF2GACX1jjMSe7hCq8wgr/17JIemBwlxMAspW1lmc9/9iQ922ieaZ4Pnei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ebHQecZocRLFe6mAEsyU6Bq9kJ6aDeZOOUEmKP4gQHLdc67Vb/IuKQdFpZ2852Hyasyv/rFg0duEtfdokn1EzOntp9OZG6vI/4DjKbLRXL2l8xozWUeYzKwYJlM/AhwrtJcTFJ6yhCoMEr9SgIf9ovqRRP0h1bH0vH7XFzeDqIzWOE7hhPENac+N4IK5+x5IOznpAQbIGGBXiFngvtIXvtUHCi4TuZ65r6V37R2Ojkkmzw== 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 Mon, Apr 24, 2023 at 07:53:26PM -0300, Jason Gunthorpe wrote: > On Mon, Apr 24, 2023 at 08:18:33PM +0100, Lorenzo Stoakes wrote: > > > I think this patch suggestion has scope crept from 'incremental > > improvement' to 'major rework of GUP' at this point. > > I don't really expect to you clean up all the callers - but we are > trying to understand what is actually wrong here to come up with the > right FOLL_ names and overall strategy. Leave behind a comment, for > instance. > Right, but you are suggesting introducing a whole new GUP interface holding the right locks etc. which is really scope-creeping from the original intent. I'm not disagreeing that we need an interface that can return things in a state where the dirtying can be done correctly, I just don't think _this_ patch series is the place for it. > I don't think anyone has really thought about the ptrace users too > much till now, we were all thinking about DMA use cases, it shows we > still have some areas that need attention. I do like to feel that my recent glut of GUP activity, even if noisy and frustrating, has at least helped give some insights into usage and semantics :) > > > Also surely you'd want to obtain the PTL of all mappings to a file? > > No, just one is fine. If you do the memcpy under a single PTL that > points at a writable copy of the page then everything is trivially > fine because it is very similar to what the CPU itself would do, which > is fine by definition.. > > Jason Except you dirty a page that is mapped elsewhere that thought everything was cleaned and... not sure the PTLs really help you much? Anyway I feel we're digressing into the broader discussion which needs to be had, but not when trying to unstick the vmas series :) I am going to put forward an opt-in variant of this change that explicitly checks whether any VMA in the range requires dirty page tracking, if not failing the GUP operation. This can then form the basis of the opt-OUT variant (it'll be the same check code right?) and help provide a basis for the additional work that clearly needs to be done. It will also replace the open-coded VMA check in io_uring so has utility and justification just from that. If we want to be more adventerous the opt-in variant could default to on for FOLL_LONGTERM too, but that discussion can be had over on that patch series.