From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta1.migadu.com (out-79.mta1.migadu.com [95.215.58.79]) (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 DA808476CE8 for ; Fri, 2 Oct 2026 09:55:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.79 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790934959; cv=none; b=Djmh5cl4aVx3tiQPwifHLcU01iEjuZJapxQKjR6QctHT4iKqkgnoBKiwdB2vBguepp0KYl6h5/G8wua7lHmf/Mc7NmzesK8zQmt4ullFC3SuYN8vEXpQ2fS3+S9gQVV8KehMnHGII/pOcURJxGzu23TyxaasFlAH8Me/FxyMp+Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790934959; c=relaxed/simple; bh=EKokArehgD8rZsdXiQ8lLAgAY9hoxZ0T6UO2qk4aEM8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jIJe95TxHe19qZUWGLb5wey/IcAv0TlVyC8TWLmreK4BUna9y38q5B6kf9yS7S8j8x2tbd9kCaQPaFzjhx1VO9SSPA7ak77BMS8uFO9g3cqGAPJO3CfZnTwcUu/pDDcQbAyAmeE1EALQnHdq5x6hkURiDADSc78RCtvkdtj1PpQ= 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=AB2wfVjE; arc=none smtp.client-ip=95.215.58.79 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="AB2wfVjE" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=EKokArehgD8rZsdXiQ8lLAgAY9hoxZ0T6UO2qk4aEM8=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1790934955; v=1; x=1791539755; b=AB2wfVjEQ5InkSFG4tpyVMm950tIQTUxVRgSeeWn7d3U9Eaz/NAtekmo+yVBJANfqNLCSnNE REZUhbn9+RiBuniVNvUfpn2NxGsF2U9GcYt10wxiLMNpB8tIC/5H7r1i/ca65X6BtOUAxHVv5Db nfSrP9puCFC51I2penaqxXzA= X-Envelope-To: linux-kernel@vger.kernel.org Received: by mta10.migadu.com with ESMTPS id 69e3887844b5b59c; Fri, 02 Oct 2026 09:55:54 +0000 X-Mizu-Trace-ID: 69e3887844b5b59c 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 , Huacai Chen Subject: [PATCH v8 03/30] loongarch: mm: add PMD swap-exclusive helpers Date: Fri, 2 Oct 2026 02:52:17 -0700 Message-ID: <20261002095503.3585565-4-usama.arif@linux.dev> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261002095503.3585565-1-usama.arif@linux.dev> References: <20261002095503.3585565-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 Prepare for keeping a PMD-mapped anonymous THP mapped by a PMD across the swap round-trip, which makes PG_anon_exclusive have to survive in a swap PMD and not just in a swap PTE. A LoongArch swap PMD is the swap PTE value plus _PAGE_HUGE, and _PAGE_SWP_EXCLUSIVE sits outside both the type and the offset field, so the PMD helpers can use the same bit. Cc: Huacai Chen Signed-off-by: Usama Arif Reviewed-by: David Hildenbrand (Arm) --- arch/loongarch/include/asm/pgtable.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/arch/loongarch/include/asm/pgtable.h b/arch/loongarch/include/asm/pgtable.h index cf29a4c8ac593..87fecc3a51001 100644 --- a/arch/loongarch/include/asm/pgtable.h +++ b/arch/loongarch/include/asm/pgtable.h @@ -351,6 +351,25 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte) return pte; } +#ifdef CONFIG_ARCH_HAS_PMD_SOFTLEAVES +static inline pmd_t pmd_swp_mkexclusive(pmd_t pmd) +{ + pmd_val(pmd) |= _PAGE_SWP_EXCLUSIVE; + return pmd; +} + +static inline bool pmd_swp_exclusive(pmd_t pmd) +{ + return pmd_val(pmd) & _PAGE_SWP_EXCLUSIVE; +} + +static inline pmd_t pmd_swp_clear_exclusive(pmd_t pmd) +{ + pmd_val(pmd) &= ~_PAGE_SWP_EXCLUSIVE; + return pmd; +} +#endif + #define pte_none(pte) (!(pte_val(pte) & ~_PAGE_GLOBAL)) #define pte_present(pte) (pte_val(pte) & (_PAGE_PRESENT | _PAGE_PROTNONE)) #define pte_no_exec(pte) (pte_val(pte) & _PAGE_NO_EXEC) -- 2.53.0-Meta