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 B8376E7717D for ; Mon, 9 Dec 2024 22:21:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 52B346B00C6; Mon, 9 Dec 2024 17:21:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4DAE76B00C8; Mon, 9 Dec 2024 17:21:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3A2F86B00C9; Mon, 9 Dec 2024 17:21:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 177816B00C6 for ; Mon, 9 Dec 2024 17:21:16 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 89E6380823 for ; Mon, 9 Dec 2024 22:21:15 +0000 (UTC) X-FDA: 82876842090.04.3BE0545 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by imf29.hostedemail.com (Postfix) with ESMTP id EE634120008 for ; Mon, 9 Dec 2024 22:20:43 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=uIfYZ8ig; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf29.hostedemail.com: domain of isaacmanjarres@google.com designates 209.85.214.180 as permitted sender) smtp.mailfrom=isaacmanjarres@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733782853; a=rsa-sha256; cv=none; b=m8+6Y6kO2Vi2LaeCwOvE2tn7BJHJE4TGt+UGTcVZPZav/wVbpI8J1YcfhxJXf5mk1JxS/f knQDe3Xn2ueC7Io0w8hrSPaPZc4/1/zA0IKi4/UAFTdvqivDIctnsPFbvs7kBulgWqwAMY W8yqFCv2bazai55+CIDwTz/5YT8oQeo= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=uIfYZ8ig; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf29.hostedemail.com: domain of isaacmanjarres@google.com designates 209.85.214.180 as permitted sender) smtp.mailfrom=isaacmanjarres@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733782853; 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=UQ0c4ML2FptDBwiBhUUUxjDY/ghZvOgo20xW04jmY1g=; b=iktLA82qV7kkk25TCuAMuQXN4icXhhXsnDSf0GmKEZuSmicp0NFbWkl+RSm7FFCmP0TrdV EBgVtDzHp+VTwnvCyKHyXyi2x4jlmRFLB3iKI2+giYgEiBEoYpkBNjypTK9pXEilGs1RBs pYd2SXLssuGAfMV9le9AP7OynuFaIyE= Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2163affd184so23475ad.1 for ; Mon, 09 Dec 2024 14:21:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733782872; x=1734387672; darn=kvack.org; 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=UQ0c4ML2FptDBwiBhUUUxjDY/ghZvOgo20xW04jmY1g=; b=uIfYZ8igzYr5h/NxKMOyAMz807SNUh4LpNDdF43T0TmJU/cqrT+bmLAL4d4D+xqyRY Do72s3+HSms0h3NmrzYkeEGgjDYMZKVxCBQoc7mvWU1H5f9UxKEzv4xHAOyWUo+UJTDC 0xteLbkXxWIiFCDnenRJlPp+Rj5veM5mQPRM02esPrOhlkJ0IjfklHiUZu6f9Tr1D9Wk 0PD75V2sGAOWRvOYy1swaMdHH9U67EkYFw4makPtjjo3KKafWsSlGiY5+FRCErNUfieO Y9tFiY+bfGGglxGoEWK0klfhUMVaXm6ITOQW49M3u13GrT+KL7vbCuEPtWLyVfzvkANi C3JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733782872; x=1734387672; 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=UQ0c4ML2FptDBwiBhUUUxjDY/ghZvOgo20xW04jmY1g=; b=nAeQMeSMDUicmvwR53Kk5BE0CqBvGERroWlCAtKXwH+c3c91gW4qBrWBIE7KuleOL0 dU/ywGcT+w/FvOCvFEqk2gip/0C5CIZKnCyG1TAVxa0PEIfl1X6AfyXPuYhV+2g6gTae tl6qFT3hWNlPfurPvi1w3vfTVflF9bDD4NZR1MlUGOOQYjW09IKCgfNUp2g/rG5KPfHa aV05WB+80JTKvDRy3RZAPNvILK2QeTyq+j+mMA4gLBZsFmsAC4dWEXMUX2sKhum0iTIY YbxGCCY603iheEXIlzxKNB37PhHMT2tJy0pZcnmXgQsyqwGhyOtpmE7beuPTKJEMprC6 pJGw== X-Forwarded-Encrypted: i=1; AJvYcCVzRtgLbNL5FF33QyCmj1foHgXopkIOtGpEnY0tgMogUsGsoF1riSSEentLMY5MNnHaZivLbjainQ==@kvack.org X-Gm-Message-State: AOJu0YxabCiNGudXWl+AHu85g6fd1Y8d/goUTAtIpc6to607Hykd9mkd kTf68A5ZuHhnqONJe8KvmT9nrq6YAvKMjeNwWr56INXXDt1jMK4290wSm0Y3iQ== X-Gm-Gg: ASbGncvsyhZu+2JRdxyeHHdFauVrRh5RbQbOd27elSJToZNQPQCE1XqobHV2qN5z9Fd Tn5hZefQGbaHzzICCXIy6zzSGSBW1brlCRqpOo42gPGLIsEQ+aHVrxzwdaWKEGpS+LS6RPSew8a sCfzIshsLIRsxyDQPatF80+WTcrvUEI0LEajX8kP10OAvUW0IjK48dZrRENkT/NhxvtKb8iV6IC j0imE+dxTy94J5+Ema07sm5sNLtPpJqydV5bj6AsYNwAsAL563rrQ== X-Google-Smtp-Source: AGHT+IGk+N2pyB4iTzK+9jBz8LLAHJvjli7QNO9KTLd4YcGLC+ooS6UqWfBpPBphl6cTEpCdV8UIFg== X-Received: by 2002:a17:903:2ca:b0:216:6ecd:8950 with SMTP id d9443c01a7336-21674d77ed3mr164555ad.19.1733782872098; Mon, 09 Dec 2024 14:21:12 -0800 (PST) Received: from google.com ([2620:15c:2d:3:ca13:4616:5dfd:8e7a]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2166fc21dcbsm3026395ad.117.2024.12.09.14.21.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Dec 2024 14:21:11 -0800 (PST) Date: Mon, 9 Dec 2024 14:21:07 -0800 From: Isaac Manjarres To: Lorenzo Stoakes Cc: Andrew Morton , "Liam R . Howlett" , Muchun Song , Vlastimil Babka , Jann Horn , Hugh Dickins , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Kalesh Singh Subject: Re: [PATCH] mm: perform all memfd seal checks in a single place Message-ID: References: <20241206212846.210835-1-lorenzo.stoakes@oracle.com> <7dee6c5d-480b-4c24-b98e-6fa47dbd8a23@lucifer.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7dee6c5d-480b-4c24-b98e-6fa47dbd8a23@lucifer.local> X-Stat-Signature: 848pouaf7eh9e1pq5n79mac9x8wsun13 X-Rspam-User: X-Rspamd-Queue-Id: EE634120008 X-Rspamd-Server: rspam08 X-HE-Tag: 1733782843-551009 X-HE-Meta: U2FsdGVkX1+ijgO9roJalQBAGJJmzyzErHVh786F2vX8mGXo+dtAAfZi1Jlic4UqtQ1A7a7Tm8jqLVuvR4k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LqVcvNJkfbEH3+ee49pz4TulPcKGmtmvbAvHPCQ9WfyqUiVlpzz0QOoMOC0V5IC245DXo7gxvxLVMYlFqlVF80QohLWGzT3lIpDoK7zQ9b6LeG68/Nv80qXA0Zx537rk+57RfhWw0OfHLPJ8LdwYjnwQtzZPgoyWG7bd7g+cECiQlh9Ivzwt+IOo3CILGFvNTpkFnWRCwdUuHYReK+yOTCbXkN X-Bogosity: Unsure, tests=bogofilter, spamicity=0.455291, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Mon, Dec 09, 2024 at 11:13:14AM +0000, Lorenzo Stoakes wrote: > On Fri, Dec 06, 2024 at 09:28:46PM +0000, Lorenzo Stoakes wrote: > > We no longer actually need to perform these checks in the f_op->mmap() hook > > any longer. > > > > We already moved the operation which clears VM_MAYWRITE on a read-only > > mapping of a write-sealed memfd in order to work around the restrictions > > imposed by commit 5de195060b2e ("mm: resolve faulty mmap_region() error > > path behaviour"). > > > > There is no reason for us not to simply go ahead and additionally check to > > see if any pre-existing seals are in place here rather than defer this to > > the f_op->mmap() hook. > > > > By doing this we remove more logic from shmem_mmap() which doesn't belong > > there, as well as doing the same for hugetlbfs_file_mmap(). We also remove > > dubious shared logic in mm.h which simply does not belong there either. > > > > It makes sense to do these checks at the earliest opportunity, we know > > these are shmem (or hugetlbfs) mappings whose relevant VMA flags will not > > change from the invoking do_mmap() so there is simply no need to wait. > > > > This also means the implementation of further memfd seal flags can be done > > within mm/memfd.c and also have the opportunity to modify VMA flags as > > necessary early in the mapping logic. > > > > Signed-off-by: Lorenzo Stoakes > ----8<---- > From 6cfef80e2ea5154302ba9b1925acd8e77ea6cd18 Mon Sep 17 00:00:00 2001 > From: Lorenzo Stoakes > Date: Mon, 9 Dec 2024 11:04:08 +0000 > Subject: [PATCH] mm: fix typos in !memfd inline stub > > I typo'd the declaration of memfd_check_seals_mmap() in the case where > CONFIG_MEMFD_CREATE is not defined, resulting in build failures. > > Fix this, and correct the misspelling of vm_flags which should be > vm_flags_ptr at the same time. > > Signed-off-by: Lorenzo Stoakes > --- > include/linux/memfd.h | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/include/linux/memfd.h b/include/linux/memfd.h > index d53408b0bd31..246daadbfde8 100644 > --- a/include/linux/memfd.h > +++ b/include/linux/memfd.h > @@ -24,7 +24,8 @@ static inline struct folio *memfd_alloc_folio(struct file *memfd, pgoff_t idx) > { > return ERR_PTR(-EINVAL); > } > -int memfd_check_seals_mmap(struct file *file, unsigned long *vm_flags) > +static inline int memfd_check_seals_mmap(struct file *file, > + unsigned long *vm_flags_ptr) > { > return 0; > } > -- > 2.47.1 Thanks for sending this out so quickly! I think this came out nicely, and makes the memfd sealing code easier to comprehend :). I applied both the patch that moves the memfd seal checks to one place and the fix up patch, and tested it out on my Pixel 6 device. The device boots, and I do not see any errors related to memfd. Please feel free to add my tested-by tag to the patch: Tested-by: Isaac J. Manjarres Thanks, Isaac