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 A6697C77B61 for ; Mon, 24 Apr 2023 14:30:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 29B626B0071; Mon, 24 Apr 2023 10:30:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 223FA6B0074; Mon, 24 Apr 2023 10:30:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 09EA36B0075; Mon, 24 Apr 2023 10:30:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E84496B0071 for ; Mon, 24 Apr 2023 10:30:02 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 8BB4C1A0128 for ; Mon, 24 Apr 2023 14:30:02 +0000 (UTC) X-FDA: 80716519044.06.5766704 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) by imf04.hostedemail.com (Postfix) with ESMTP id ADD3040014 for ; Mon, 24 Apr 2023 14:30:00 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=jN6OPjaH; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf04.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.53 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=1682346600; 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=ALXzGJ5JvLTy0+4F2uq1xRRPXqqALEamM+dBHIwr4DU=; b=jV8fKWAfsubLbVc26tSu+eulqJIZoggYPW9lnjsKsl58WtMnkhumJhVnf7ta0c7mHvxHNO HtSFJHNtlOfpV3R9TD8aCMoP96I1L5TPQmijPX2PAiryBdLBeTCReValgSQ5uQ0ZxpqDoR DJmRo+BmgQtovrNjiq3QkqsocYYPaoc= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=jN6OPjaH; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf04.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.53 as permitted sender) smtp.mailfrom=lstoakes@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682346600; a=rsa-sha256; cv=none; b=3qvdhJVv/iJvLL98wuDf8utNKnrKbzC9D6HcfnnioNha1SRz4c4KdRiGRWDH7LrZDyD5fK Muqv32175xUpVk77g4CVL1YSlT9xMl068gwvfPXkWsAEJR9zS1zMf1fk3Y5tdxs/LKfFU/ D9XX0JLrd7weTfonyYI9/L9Auh+C/8Y= Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-3f1958d3a53so31055125e9.0 for ; Mon, 24 Apr 2023 07:30:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682346599; x=1684938599; 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=ALXzGJ5JvLTy0+4F2uq1xRRPXqqALEamM+dBHIwr4DU=; b=jN6OPjaHPR+35RVu5HjWm806ZMgHf01oApnLVzOoITrD4+H3+33xZ6dZ5oRf6qOZUP D8hA3Wt44+/uTDeVRl8Ov5vr+CJfATx0OLo0X1EW5HpwpfUNG+UJik3wBieB7KEjsimQ y1HCZNLKGyA7om63+beqZU93mzJXtP5mOtlZ6xytdf2q3oM+pAkAGAUnopDzvWh322W1 4P+KbO6x4luVrUwPFIY3Kz+NJFvZi9mRoQERFsgyWpa7xNiB+Kl9hiYh2UGYR8newEsb nNPRnYDg7clTomT3WnhQfQKHmrFMU6VtI4ds5fP3IX5FZTm3u1VX+ZmjErAMXFNfLvTc Gtzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682346599; x=1684938599; 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=ALXzGJ5JvLTy0+4F2uq1xRRPXqqALEamM+dBHIwr4DU=; b=he03Bsmp2teE6fE4W3vaHfKh++7u5i6Htkx2rTm0wVHQTfgVFEAfrv/jJ/4wlBFInj NO8FXuhLlYL9GwVd8CHxyVO8rYmqqhVV4ebO/GMnAxxAT3KgkJ6pTaEw/8fULQOks/ed XsbM4d0tz8j9rs+nvV1MTd9X6BH4o0vhW6A/HZp9kizywAO3dyQtVTAbwa6HSEBYN+M6 BGDpgw4UTpQLNiavBK2OOohCOJ8fc/xlXn8w2YWr3BGKy+h4l/ycFUZSQ2vwjTafIAou TOuipAZSLZSPMol2OPy0VAwXqs2jnw5QfQNB7uNQ8v2amuruUhkVG37ywbqmARPJMRag 8UKQ== X-Gm-Message-State: AAQBX9dWZAZyGY8E4HaLFeQ5IhJruouiam7qXV7nQTjLY/QHiXmrP5EM ++Z2DqQzqQzdbQXTXHXBJFI= X-Google-Smtp-Source: AKy350b0rBDMlMKwXgslvzplbT1eTTOv7dxTLMhpCvOuA79NqOaO/7KznoKPY9xRsZr4W2xUpEdJIw== X-Received: by 2002:a05:600c:2214:b0:3f1:98bd:acec with SMTP id z20-20020a05600c221400b003f198bdacecmr5257735wml.11.1682346598884; Mon, 24 Apr 2023 07:29:58 -0700 (PDT) Received: from localhost (host86-156-84-164.range86-156.btcentralplus.com. [86.156.84.164]) by smtp.gmail.com with ESMTPSA id y21-20020a05600c365500b003f182a10106sm12424385wmq.8.2023.04.24.07.29.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Apr 2023 07:29:57 -0700 (PDT) Date: Mon, 24 Apr 2023 15:29:57 +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: 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-Server: rspam02 X-Rspamd-Queue-Id: ADD3040014 X-Stat-Signature: ax7md3c9nan4mqypbe6x7ns6e1ud46k6 X-HE-Tag: 1682346600-673576 X-HE-Meta: U2FsdGVkX1+IQInaRYFdV3xBeebar9qYDE6dtbmR7o2GBn3tO8HaBFjYyHz4JqCBZrOhY3coVB1JS/FSS78W4jQl6PFN0t21b5xDzGUTqhBLAmEM5t3NMFNt0IceDnMku7WqaWZzxv2QjLCBLmatBajw8phB/Qywcn65cX2rtq3M3k9JL2OT+TkZ5QUGTFDB20d928Sp9tVWf5yE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HpVINQf89myDj83t4e9ShW1UqGnjRJUJdl8gWcVamTkXryiscdFFspcACGIWD6sLv6ixJPqWDO4Szw4PsSbGjm57jG+FwjdwklyPuhhM5RZmtNCo8N3WZ2fatMTF7cmnwQNWSjY0/gV5wb4F+LjzRr5Wk+G5XQCGWuw== 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 10:39:25AM -0300, Jason Gunthorpe wrote: > On Mon, Apr 24, 2023 at 01:38:49PM +0100, Lorenzo Stoakes wrote: > > > I was being fairly conservative in that list, though we certainly need to > > set the flag for /proc/$pid/mem and ptrace to avoid breaking this > > functionality (I observed breakpoints breaking without it which obviously > > is a no go :). I'm not sure if there's a more general way we could check > > for this though? > > More broadly we should make sure these usages of GUP safe somehow so > that it can reliably write to those types of pages without breaking > the current FS contract.. > > I forget exactly, but IIRC, don't you have to hold some kind of page > spinlock while writing to the page memory? > I think perhaps you're thinking of the mm->mmap_lock? Which will be held for the FOLL_GET cases and simply prevent the VMA from disappearing below us but not do much else. > So, users that do this, or can be fixed to do this, can get file > backed pages. It suggests that a flag name is more like > FOLL_CALLER_USES_FILE_WRITE_LOCKING > As stated above, I'm not sure what locking you're referring to, but seems to me that FOLL_GET already implies what you're thinking? I wonder whether we should do this check purely for FOLL_PIN to be honest? As this indicates medium to long-term access without mmap_lock held. This would exclude the /proc/$pid/mem and ptrace paths which use gup_remote(). That and a very specific use of uprobes are the only places that use FOLL_GET in this instance and each of them are careful in any case to handle setting the dirty page flag. All PUP cases that do not specify FOLL_LONGTERM also do this, so we could atually go so far as to reduce the patch to simply performing the vma_wants_writenotify() check if (FOLL_PIN | FOLL_LONGTERM) is specified, which covers the io_uring case. Alternatively if we wanted to be safer, we could add a FOLL_ALLOW_FILE_PIN that is checked on FOLL_PIN and ignored on FOLL_LONGTERM? > > I wouldn't be totally opposed to dropping it for RDMA too, because I > > suspect accessing file-backed mappings for that is pretty iffy. > > > > Do you have a sense of which in the list you feel could be pared back? > > Anything using FOLL_LONGTERM should not set the flag, GUP should even > block the combination. OK > > And we need to have in mind that the flag indicates the code is > buggy, so if you set it then we should understand how is that caller > expected to be fixed. > > Jason I think we are working towards a much simpler solution in any case!