From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from fra-out-001.esa.eu-central-1.outbound.mail-perimeter.amazon.com (fra-out-001.esa.eu-central-1.outbound.mail-perimeter.amazon.com [18.156.205.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 530D623D2B2; Fri, 16 Jan 2026 14:56:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=18.156.205.64 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768575383; cv=none; b=DAAEL/ythQC9dcNK4inEoLJdHBLeXIDYhp8B/zWP9QzKE9IvYa7r4za6VGrKDLtjbSnbrrKaAg6fmYVJwqsigEU4TOSFsU/qs2NVk/atVu1NdRRuSNdT5qFz/e+8h6TEWup4KibdcunnSVwzyCIw+2qymXLJMQWytk68tx1iDpo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768575383; c=relaxed/simple; bh=BxZnyiI6YgvskaCwpGEH+hfPdJiGYdOF3yczju02EHM=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=b/JAdQvUEdGVM+Wf43S6WyAWz2pkI/+ltYRfr9jVv8atARLfFnvYYu6uZZ+ioq/OzyIRaVX5G8+98jiprqI+JZmvarV7Gm1ZE0n6SzfarpNFy+wXaglFbdaXlH2t+OeQec0rz2gGBxMV4uWt/GS0FVjUyJ4kUVyXCZMzwfsVGXo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.uk; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b=F0NxxFs7; arc=none smtp.client-ip=18.156.205.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.com header.i=@amazon.com header.b="F0NxxFs7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1768575381; x=1800111381; h=message-id:date:mime-version:reply-to:subject:to:cc: references:from:in-reply-to:content-transfer-encoding; bh=IEO4wkDrWsP8gb8dVRwVt7tfKvgBUuiF6zz/e0uDn6E=; b=F0NxxFs7rBOpuPtGdmPKFR/XqYq1t+f3Brm9bFysGyZrP3gPftBLJw/i Wh5P7IUKOKdVho9MP82TqY40LlX9qP84QSwMeu8tPY5QUX8wuwUybHvAH ovqE+OvhOcMUrNusqjSXCf90nYcXKoL1nmKlKiRksCwwYPAcn568K2rpj Zq6R4GcTOUEWuLLs1x6zuDKdmkaZFhFTLRDGI0/wt7b+qSK4UMyO/lLoP u5Xx3nzWkD2eqZJq7uXPn/avRekRG18I3qBE/1WcohS0AA/SxrY5pkt18 Dbf/Jtx36fSUWubpBI96UeCyLTkQmvYDq2aPsxNi5NBwhpvT1cyB9L7tV A==; X-CSE-ConnectionGUID: t80jrskTRzKiYCPAndralA== X-CSE-MsgGUID: hn4FZT+mTRGLqNyYAxxD5Q== X-IronPort-AV: E=Sophos;i="6.21,231,1763424000"; d="scan'208";a="7704673" Received: from ip-10-6-6-97.eu-central-1.compute.internal (HELO smtpout.naws.eu-central-1.prod.farcaster.email.amazon.dev) ([10.6.6.97]) by internal-fra-out-001.esa.eu-central-1.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jan 2026 14:56:02 +0000 Received: from EX19MTAEUA002.ant.amazon.com [54.240.197.232:3849] by smtpin.naws.eu-central-1.prod.farcaster.email.amazon.dev [10.0.41.192:2525] with esmtp (Farcaster) id 260b6298-10cb-4eed-9151-e85b598fcfcc; Fri, 16 Jan 2026 14:56:02 +0000 (UTC) X-Farcaster-Flow-ID: 260b6298-10cb-4eed-9151-e85b598fcfcc Received: from EX19D005EUB003.ant.amazon.com (10.252.51.31) by EX19MTAEUA002.ant.amazon.com (10.252.50.124) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.35; Fri, 16 Jan 2026 14:56:01 +0000 Received: from [192.168.12.13] (10.106.82.9) by EX19D005EUB003.ant.amazon.com (10.252.51.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.35; Fri, 16 Jan 2026 14:55:57 +0000 Message-ID: <6b50a83e-acd7-4db3-ae9b-015ffad4f615@amazon.com> Date: Fri, 16 Jan 2026 14:55:56 +0000 Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Reply-To: Subject: Re: [PATCH v9 02/13] mm/gup: drop secretmem optimization from gup_fast_folio_allowed To: Ackerley Tng , "Kalyazin, Nikita" , "kvm@vger.kernel.org" , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "kvmarm@lists.linux.dev" , "linux-fsdevel@vger.kernel.org" , "linux-mm@kvack.org" , "bpf@vger.kernel.org" , "linux-kselftest@vger.kernel.org" , "kernel@xen0n.name" , "linux-riscv@lists.infradead.org" , "linux-s390@vger.kernel.org" , "loongarch@lists.linux.dev" CC: "pbonzini@redhat.com" , "corbet@lwn.net" , "maz@kernel.org" , "oupton@kernel.org" , "joey.gouly@arm.com" , "suzuki.poulose@arm.com" , "yuzenghui@huawei.com" , "catalin.marinas@arm.com" , "will@kernel.org" , "seanjc@google.com" , "tglx@linutronix.de" , "mingo@redhat.com" , "bp@alien8.de" , "dave.hansen@linux.intel.com" , "x86@kernel.org" , "hpa@zytor.com" , "luto@kernel.org" , "peterz@infradead.org" , "willy@infradead.org" , "akpm@linux-foundation.org" , "david@kernel.org" , "lorenzo.stoakes@oracle.com" , "Liam.Howlett@oracle.com" , "vbabka@suse.cz" , "rppt@kernel.org" , "surenb@google.com" , "mhocko@suse.com" , "ast@kernel.org" , "daniel@iogearbox.net" , "andrii@kernel.org" , "martin.lau@linux.dev" , "eddyz87@gmail.com" , "song@kernel.org" , "yonghong.song@linux.dev" , "john.fastabend@gmail.com" , "kpsingh@kernel.org" , "sdf@fomichev.me" , "haoluo@google.com" , "jolsa@kernel.org" , "jgg@ziepe.ca" , "jhubbard@nvidia.com" , "peterx@redhat.com" , "jannh@google.com" , "pfalcato@suse.de" , "shuah@kernel.org" , "riel@surriel.com" , "ryan.roberts@arm.com" , "jgross@suse.com" , "yu-cheng.yu@intel.com" , "kas@kernel.org" , "coxu@redhat.com" , "kevin.brodsky@arm.com" , "maobibo@loongson.cn" , "prsampat@amd.com" , "mlevitsk@redhat.com" , "jmattson@google.com" , "jthoughton@google.com" , "agordeev@linux.ibm.com" , "alex@ghiti.fr" , "aou@eecs.berkeley.edu" , "borntraeger@linux.ibm.com" , "chenhuacai@kernel.org" , "dev.jain@arm.com" , "gor@linux.ibm.com" , "hca@linux.ibm.com" , "Jonathan.Cameron@huawei.com" , "palmer@dabbelt.com" , "pjw@kernel.org" , "shijie@os.amperecomputing.com" , "svens@linux.ibm.com" , "thuth@redhat.com" , "wyihan@google.com" , "yang@os.amperecomputing.com" , "vannapurve@google.com" , "jackmanb@google.com" , "aneesh.kumar@kernel.org" , "patrick.roy@linux.dev" , "Thomson, Jack" , "Itazuri, Takahiro" , "Manwaring, Derek" , "Cali, Marco" References: <20260114134510.1835-1-kalyazin@amazon.com> <20260114134510.1835-3-kalyazin@amazon.com> Content-Language: en-US From: Nikita Kalyazin Autocrypt: addr=kalyazin@amazon.com; keydata= xjMEY+ZIvRYJKwYBBAHaRw8BAQdA9FwYskD/5BFmiiTgktstviS9svHeszG2JfIkUqjxf+/N JU5pa2l0YSBLYWx5YXppbiA8a2FseWF6aW5AYW1hem9uLmNvbT7CjwQTFggANxYhBGhhGDEy BjLQwD9FsK+SyiCpmmTzBQJnrNfABQkFps9DAhsDBAsJCAcFFQgJCgsFFgIDAQAACgkQr5LK IKmaZPOpfgD/exazh4C2Z8fNEz54YLJ6tuFEgQrVQPX6nQ/PfQi2+dwBAMGTpZcj9Z9NvSe1 CmmKYnYjhzGxzjBs8itSUvWIcMsFzjgEY+ZIvRIKKwYBBAGXVQEFAQEHQCqd7/nb2tb36vZt ubg1iBLCSDctMlKHsQTp7wCnEc4RAwEIB8J+BBgWCAAmFiEEaGEYMTIGMtDAP0Wwr5LKIKma ZPMFAmes18AFCQWmz0MCGwwACgkQr5LKIKmaZPNTlQEA+q+rGFn7273rOAg+rxPty0M8lJbT i2kGo8RmPPLu650A/1kWgz1AnenQUYzTAFnZrKSsXAw5WoHaDLBz9kiO5pAK In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: EX19D012EUA003.ant.amazon.com (10.252.50.98) To EX19D005EUB003.ant.amazon.com (10.252.51.31) On 15/01/2026 21:40, Ackerley Tng wrote: > "Kalyazin, Nikita" writes: > >> From: Patrick Roy >> >> This drops an optimization in gup_fast_folio_allowed() where >> secretmem_mapping() was only called if CONFIG_SECRETMEM=y. secretmem is >> enabled by default since commit b758fe6df50d ("mm/secretmem: make it on >> by default"), so the secretmem check did not actually end up elided in >> most cases anymore anyway. >> >> This is in preparation of the generalization of handling mappings where >> direct map entries of folios are set to not present. Currently, >> mappings that match this description are secretmem mappings >> (memfd_secret()). Later, some guest_memfd configurations will also fall >> into this category. >> >> Signed-off-by: Patrick Roy >> Acked-by: Vlastimil Babka >> Signed-off-by: Nikita Kalyazin >> --- >> mm/gup.c | 11 +---------- >> 1 file changed, 1 insertion(+), 10 deletions(-) >> >> diff --git a/mm/gup.c b/mm/gup.c >> index 95d948c8e86c..9cad53acbc99 100644 >> --- a/mm/gup.c >> +++ b/mm/gup.c >> @@ -2739,7 +2739,6 @@ static bool gup_fast_folio_allowed(struct folio *folio, unsigned int flags) >> { >> bool reject_file_backed = false; >> struct address_space *mapping; >> - bool check_secretmem = false; >> unsigned long mapping_flags; >> >> /* >> @@ -2751,14 +2750,6 @@ static bool gup_fast_folio_allowed(struct folio *folio, unsigned int flags) > > Copying some lines the diff didn't contain: > > /* > * If we aren't pinning then no problematic write can occur. A long term > * pin is the most egregious case so this is the one we disallow. > */ > if ((flags & (FOLL_PIN | FOLL_LONGTERM | FOLL_WRITE)) == > (FOLL_PIN | FOLL_LONGTERM | FOLL_WRITE)) > > If we're pinning, can we already return true here? IIUC this function > is passed a folio that is file-backed, and the check if (!mapping) is > just there to catch the case where the mapping got truncated. I have to admit that I am not comfortable with removing this check, unless someone says it's certainly alright. > > Or should we wait for the check where the mapping got truncated? If so, > then maybe we can move this "are we pinning" check to after this check > and remove the reject_file_backed variable? I can indeed move the pinning check to the end to remove the variable. I'd do it in a separate patch. > > /* > * The mapping may have been truncated, in any case we cannot determine > * if this mapping is safe - fall back to slow path to determine how to > * proceed. > */ > if (!mapping) > return false; > > >> reject_file_backed = true; >> >> /* We hold a folio reference, so we can safely access folio fields. */ >> - >> - /* secretmem folios are always order-0 folios. */ >> - if (IS_ENABLED(CONFIG_SECRETMEM) && !folio_test_large(folio)) >> - check_secretmem = true; >> - >> - if (!reject_file_backed && !check_secretmem) >> - return true; >> - >> if (WARN_ON_ONCE(folio_test_slab(folio))) >> return false; >> >> @@ -2800,7 +2791,7 @@ static bool gup_fast_folio_allowed(struct folio *folio, unsigned int flags) >> * At this point, we know the mapping is non-null and points to an >> * address_space object. >> */ >> - if (check_secretmem && secretmem_mapping(mapping)) >> + if (secretmem_mapping(mapping)) >> return false; >> /* The only remaining allowed file system is shmem. */ >> return !reject_file_backed || shmem_mapping(mapping); >> -- >> 2.50.1