From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta0.migadu.com (out-136.mta0.migadu.com [91.218.175.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E312A442FA0 for ; Mon, 14 Sep 2026 11:44:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.136 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789386247; cv=none; b=fxAgku06qNBh4JptIbMrRaKjilFr6M/iVela8GGRaxIAVbwByzQh62winEpWvVuHVusN2xb/mrFKJ2K4wJnNThsxFEZttzFegiCA8kKrKJpzPKtufFHPhhlmou7rnowFIepPMqmYwuEuJicjbduqt7LyFGovOaJHNWs7DkD1S30= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789386247; c=relaxed/simple; bh=m3zofWqXNwwubO6EsHPEBwbDlkXPNebnA/BZT3Zr5yk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hyzxc6Xdpety5jyZpoUH9DWIO9ukFEvKohIx9YBTxiNFqGbaQt9NED6uaA6gHSuionYSECAydPY8mPR/YTZcbDcJBbb52r/K1MRx7QtwyY2WBgezaXT+yqP3W6NGDDLaNVs6ck2lL/R8zt/yAbrt//248rEKTInL2DE0sgBa9MA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=ONt0a/jw; arc=none smtp.client-ip=91.218.175.136 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="ONt0a/jw" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=m3zofWqXNwwubO6EsHPEBwbDlkXPNebnA/BZT3Zr5yk=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1789386243; v=1; x=1789991043; b=ONt0a/jw7tfJdUHOv6+2nLmRjfU0MWIU7IIKQLtddo5S6i9iYku/450AMUHftEs8PwfwR3Qs t7U+iQPx0ysvxdr7Xat267zTuybuJGd0kzybqbqXS6Q29lSUU7xLnsKCrxXvbv8GyuJb1L4HU2P 5LieswihxSkgK85tRp2Hzrmc= X-Envelope-To: linux-kernel@vger.kernel.org Received: by mta10.migadu.com with ESMTPS id 91b9be05c6e28011; Mon, 14 Sep 2026 11:44:03 +0000 X-Mizu-Trace-ID: 91b9be05c6e28011 X-Migadu-Flow: FLOW_OUT From: Usama Arif To: Andrew Morton , david@kernel.org, chrisl@kernel.org, kasong@tencent.com, ljs@kernel.org, ziy@nvidia.com, linux-mm@kvack.org Cc: ying.huang@linux.alibaba.com, Baoquan He , willy@infradead.org, youngjun.park@lge.com, hannes@cmpxchg.org, riel@surriel.com, shakeel.butt@linux.dev, alex@ghiti.fr, kas@kernel.org, baohua@kernel.org, dev.jain@arm.com, baolin.wang@linux.alibaba.com, Nico Pache , Liam R. Howlett , ryan.roberts@arm.com, Vlastimil Babka , lance.yang@linux.dev, linux-kernel@vger.kernel.org, nphamcs@gmail.com, shikemeng@huaweicloud.com, yosry@kernel.org, qi.zheng@linux.dev, luizcap@redhat.com, kernel-team@meta.com, Usama Arif , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Subject: [PATCH v7 07/29] x86: mm: add PMD swap-exclusive helpers Date: Mon, 14 Sep 2026 04:41:59 -0700 Message-ID: <20260914114320.12988-8-usama.arif@linux.dev> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260914114320.12988-1-usama.arif@linux.dev> References: <20260914114320.12988-1-usama.arif@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit A later patch keeps a PMD-mapped anonymous THP mapped by a PMD across the swap round-trip, so PG_anon_exclusive now has to survive in a swap PMD and not just in a swap PTE. x86-64 encodes a swap PMD exactly like a swap PTE, so the new helpers reuse _PAGE_SWP_EXCLUSIVE, bit 3, which the swap-entry layout already reserves for PG_anon_exclusive. 32-bit x86 aliases that bit to _PAGE_PSE and does not select ARCH_HAS_PMD_SOFTLEAVES. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: x86@kernel.org Signed-off-by: Usama Arif --- arch/x86/include/asm/pgtable.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index d551120a7c889..a2d1cd03cba23 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -1525,6 +1525,23 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte) return pte_clear_flags(pte, _PAGE_SWP_EXCLUSIVE); } +#ifdef CONFIG_ARCH_HAS_PMD_SOFTLEAVES +static inline pmd_t pmd_swp_mkexclusive(pmd_t pmd) +{ + return pmd_set_flags(pmd, _PAGE_SWP_EXCLUSIVE); +} + +static inline bool pmd_swp_exclusive(pmd_t pmd) +{ + return pmd_flags(pmd) & _PAGE_SWP_EXCLUSIVE; +} + +static inline pmd_t pmd_swp_clear_exclusive(pmd_t pmd) +{ + return pmd_clear_flags(pmd, _PAGE_SWP_EXCLUSIVE); +} +#endif + #ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY static inline pte_t pte_swp_mksoft_dirty(pte_t pte) { -- 2.53.0-Meta