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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 093C7EA71AD for ; Sun, 19 Apr 2026 23:02:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=yn9BwNFPc89fvZ6YHMLSVbzYF6HL3OKh3lDc7MlWaa8=; b=dLGbmXZCQP3rkM 2O8SCWXErQ/2rPuvJ0dhWEsKiI7o8DQ9bZlrWWOtwJHBDHWwy3t3K+zRIj+AF8ntxrjfabxEfEh1V 0mrNovuTvrs86Tejf7Gm4p9M6I84P7dnGZlzKoO+oWpV/+anyuT98zb9lA/jitnZrfIG72t/2uLaL niGY3ZH1MxcPSNGCISN64aFthMvlKXrH2fHJlRwBpJMSHP8Jye1bjwxZ6AifihdXHb+3ndy28JA9x qOH3odjMyuD7LD9c/Y5/Jwc1jFheJrkKZqHwf5HRJz5apajCvOO9yx+bTLLU1zb2+NX5FUXIeDFRC rYc2U10rVwl0ALgBLLQw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1wEb9X-000000069VZ-2jnP; Sun, 19 Apr 2026 23:02:11 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1wBDcz-0000000CRuX-0DiC; Fri, 10 Apr 2026 15:18:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=MIME-Version:Content-Transfer-Encoding :Content-Type:In-Reply-To:References:Message-ID:Date:Subject:CC:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=wjP/j8AJgPbtZq1XgPne0gPzghOZdblPBwP2xhZse4E=; b=G5Eh8NZs1gzF0bl4Xz4QcN0dq3 mjYt4BAzXTrQKZmm/VxGWZv9fWPbrummTgH4hXlaxsnnNLzZljYSBMLdJOX5Melp38S5M+x+pqhwl C4ihwuU8lUdyYEMZmpcKk6ijnZN73IErPrNGa0J1XWiZO2HQXVmnmP7UOwpuN8HezSnV/VvXL8mcM yCrxUFwYOshFNA6Usw+3aS4jDSP3XiUcluyL3kiwl3vpBJOzxdAMQ+Lt6dyq7juDywnAWkDYRgNXr 55k5q7ZlsIJhj0E95lWl/FkTHmocnzOcx3tycxOOgvYSxi829EtLWCN82Q/FbQxE69uONrhbZDB/Y FymOPCnA==; Received: from iad-out-008.esa.us-east-1.outbound.mail-perimeter.amazon.com ([34.193.58.168]) by desiato.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1wBDcw-0000000DkCV-0p9T; Fri, 10 Apr 2026 15:18:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.co.uk; i=@amazon.co.uk; q=dns/txt; s=amazoncorp2; t=1775834314; x=1807370314; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=wjP/j8AJgPbtZq1XgPne0gPzghOZdblPBwP2xhZse4E=; b=Gkf4etI4xMBpUucRhIrOvF4Z7VUZXdfaUE1D+uoVROetCbr+kYvnQgEp YY21MRnVkDq6LDI5CujjoxyKSQ7+E10nfj1/Uv6TE+WZMFil+K6q+x3vF ggvF9eVRunQDpjLjqGvPh21WS/uhVSGYsX5yc6dE0vZpGADj0wRE66w6P qveZeDEdnoLS3/wmLfgwzAF+kKwteGMjKKVWBI2e/9DYA/EETYtSHIlEe H9dJzjnpSei4xroSTmzkbxkxRzdO6WnqIzKv82VXSEMwRhYO0xSp/IgLJ XUE69RkcVZiSoUHtj2mdowIs5xYJiPJ7KU8uvyZjsOvrOclgOyghFwA4J A==; X-CSE-ConnectionGUID: pgHA7Q/vSB6ui62eJSHjYA== X-CSE-MsgGUID: ocAl+iY7TA2wuReKD5Ta6w== X-IronPort-AV: E=Sophos;i="6.23,171,1770595200"; d="scan'208";a="15816372" Received: from ip-10-4-7-229.ec2.internal (HELO smtpout.naws.us-east-1.prod.farcaster.email.amazon.dev) ([10.4.7.229]) by internal-iad-out-008.esa.us-east-1.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2026 15:18:31 +0000 Received: from EX19MTAUEB002.ant.amazon.com [72.21.198.67:12659] by smtpin.naws.us-east-1.prod.farcaster.email.amazon.dev [10.0.46.155:2525] with esmtp (Farcaster) id 84389257-d52f-41af-8219-0534a3422f4b; Fri, 10 Apr 2026 15:18:31 +0000 (UTC) X-Farcaster-Flow-ID: 84389257-d52f-41af-8219-0534a3422f4b Received: from EX19D027UEC004.ant.amazon.com (10.252.137.178) by EX19MTAUEB002.ant.amazon.com (10.252.135.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.37; Fri, 10 Apr 2026 15:18:31 +0000 Received: from EX19D027UEC003.ant.amazon.com (10.252.137.250) by EX19D027UEC004.ant.amazon.com (10.252.137.178) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.37; Fri, 10 Apr 2026 15:18:30 +0000 Received: from EX19D027UEC003.ant.amazon.com ([fe80::887f:519b:ba73:21d]) by EX19D027UEC003.ant.amazon.com ([fe80::887f:519b:ba73:21d%3]) with mapi id 15.02.2562.037; Fri, 10 Apr 2026 15:18:30 +0000 From: "Kalyazin, Nikita" To: "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" , "linux-pm@vger.kernel.org" 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@kernel.org" , "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" , "vbabka@kernel.org" , "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" , "skhan@linuxfoundation.org" , "riel@surriel.com" , "ryan.roberts@arm.com" , "jgross@suse.com" , "yu-cheng.yu@intel.com" , "kas@kernel.org" , "coxu@redhat.com" , "ackerleytng@google.com" , "yosry@kernel.org" , "ajones@ventanamicro.com" , "maobibo@loongson.cn" , "tabba@google.com" , "prsampat@amd.com" , "wu.fei9@sanechips.com.cn" , "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" , "baolu.lu@linux.intel.com" , "dev.jain@arm.com" , "gor@linux.ibm.com" , "hca@linux.ibm.com" , "palmer@dabbelt.com" , "pjw@kernel.org" , "shijie@os.amperecomputing.com" , "svens@linux.ibm.com" , "thuth@redhat.com" , "yang@os.amperecomputing.com" , "Liam.Howlett@oracle.com" , "urezki@gmail.com" , "zhengqi.arch@bytedance.com" , "gerald.schaefer@linux.ibm.com" , "jiayuan.chen@shopee.com" , "lenb@kernel.org" , "pavel@kernel.org" , "rafael@kernel.org" , "yangyicong@hisilicon.com" , "vannapurve@google.com" , "jackmanb@google.com" , "patrick.roy@linux.dev" , "Thomson, Jack" , "Itazuri, Takahiro" , "Manwaring, Derek" , "Kalyazin, Nikita" , Vlastimil Babka Subject: [PATCH v12 04/16] mm/gup: drop secretmem optimization from gup_fast_folio_allowed Thread-Topic: [PATCH v12 04/16] mm/gup: drop secretmem optimization from gup_fast_folio_allowed Thread-Index: AQHcyP1JW+htqwjvM0iCi2ukTUvS0A== Date: Fri, 10 Apr 2026 15:18:30 +0000 Message-ID: <20260410151746.61150-5-kalyazin@amazon.com> References: <20260410151746.61150-1-kalyazin@amazon.com> In-Reply-To: <20260410151746.61150-1-kalyazin@amazon.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [172.19.103.116] MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260410_161834_481897_C455F50A X-CRM114-Status: GOOD ( 13.36 ) X-Mailman-Approved-At: Sun, 19 Apr 2026 16:02:05 -0700 X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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. To make sure the fast path for ZONE_DEVICE pages (like Device DAX and PCI P2PDMA) is still allowed, check for folio_is_zone_device() if mapping is NULL. 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 Acked-by: David Hildenbrand (Red Hat) Signed-off-by: Nikita Kalyazin --- mm/gup.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 8e7dc2c6ee73..e8367564d636 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) 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; @@ -2787,9 +2778,13 @@ static bool gup_fast_folio_allowed(struct folio *folio, unsigned int flags) * 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. + * + * ZONE_DEVICE folios (e.g. Device DAX, PCI P2PDMA) may legitimately + * have a NULL mapping. They are never secretmem/no-direct-map folios, + * so let them through. */ if (!mapping) - return false; + return folio_is_zone_device(folio); /* Anonymous folios pose no problem. */ mapping_flags = (unsigned long)mapping & FOLIO_MAPPING_FLAGS; @@ -2800,7 +2795,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 _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv