From nobody Wed Dec 17 03:46:00 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1B7801E5739 for ; Fri, 21 Feb 2025 04:42:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740112967; cv=none; b=kdnU7P4Galkn5mRm2mPwfunms/RztuC9m6cHFpE+5S3AM3tfN+c+/ZE1zdB4vfVXxsGBxGx19KV1iUbm4F3j79wvXxamwhpReU83Ubc+r5TBxE4WZ5zXpW3Fbd5gIbPtCW6R0miIvTiDGsyymHr2y0HIQZMZSb/y/IJDyhVDoZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740112967; c=relaxed/simple; bh=IMsivwxnTz2kUJzB7ajupk7X90MRaRxC9txhEy2nBng=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=j58T/ip7hj+BNCtHT7noSr0RkDCkDdEw3YOAHBglG+CLJoUt2l+2cFpgqdhF6dCa5TuI68yRLKMsnQYn61PfhM03giB+AY5rtnBLcmjx9QoHVcdHF3fY8HiH9peySwXPy9CQ4YHqefVMYG6vm/BAXFaoattknYnzHGlg3o5MWz8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 48B7D1C01; Thu, 20 Feb 2025 20:43:03 -0800 (PST) Received: from a077893.blr.arm.com (a077893.blr.arm.com [10.162.40.21]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D29CF3F6A8; Thu, 20 Feb 2025 20:42:40 -0800 (PST) From: Anshuman Khandual To: arm-kernel@lists.infradead.org Cc: Anshuman Khandual , Marc Zyngier , Oliver Upton , James Morse , Catalin Marinas , Will Deacon , Ard Biesheuvel , Ryan Roberts , Mark Rutland , kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 1/8] KVM: arm64: ptdump: Test PMD_TYPE_MASK for block mapping Date: Fri, 21 Feb 2025 10:12:20 +0530 Message-Id: <20250221044227.1145393-2-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250221044227.1145393-1-anshuman.khandual@arm.com> References: <20250221044227.1145393-1-anshuman.khandual@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Test given page table entries against PMD_TYPE_SECT on PMD_TYPE_MASK mask bits for identifying block mappings in stage 2 page tables. Cc: Marc Zyngier Cc: Oliver Upton Cc: James Morse Cc: Catalin Marinas Cc: Will Deacon Cc: linux-arm-kernel@lists.infradead.org Cc: kvmarm@lists.linux.dev Cc: linux-kernel@vger.kernel.org Signed-off-by: Anshuman Khandual Acked-by: Marc Zyngier --- arch/arm64/kvm/ptdump.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/ptdump.c b/arch/arm64/kvm/ptdump.c index e4a342e903e2..098416d7e5c2 100644 --- a/arch/arm64/kvm/ptdump.c +++ b/arch/arm64/kvm/ptdump.c @@ -52,8 +52,8 @@ static const struct ptdump_prot_bits stage2_pte_bits[] = =3D { .set =3D "AF", .clear =3D " ", }, { - .mask =3D PTE_TABLE_BIT | PTE_VALID, - .val =3D PTE_VALID, + .mask =3D PMD_TYPE_MASK, + .val =3D PMD_TYPE_SECT, .set =3D "BLK", .clear =3D " ", }, --=20 2.25.1 From nobody Wed Dec 17 03:46:00 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 194851CD1E1 for ; Fri, 21 Feb 2025 04:42:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740112972; cv=none; b=gO5egBPPd7DeYRwxILB8soVx8j4BCrOJ/Em99/c9eTDEp8JBuy125nocHFCD+JwCwvtoHeB8z32uiGipb8OXy9PhKonsf4K54Z+K5jQIwDZO9W3qzyC/jHPAFaOUilzVzEhCHRKSd/3gFmvs3YO6ll+5o16hHUs5wQIAv/QHbwE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740112972; c=relaxed/simple; bh=unapYRLzN4vF8MFbKRnudeDyNWTZmUnDpCl2Q5uv/zQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jEwoopIn262+6Nzxs7voUHeMhSgb88PB3e+foGcghiqWPS2AagzCYjVkP6jiBQRVT90wwH0bkbGC1hT3Dyuus24DXHvbPLpEi4FISSbS3LEDzPbpzATUwScVsYHh02Obr7qzhecDKadKvXpEHqWxG3eaKz+jo2GqEQWNOivsnN8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A191B1C01; Thu, 20 Feb 2025 20:43:08 -0800 (PST) Received: from a077893.blr.arm.com (a077893.blr.arm.com [10.162.40.21]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 145E03F6A8; Thu, 20 Feb 2025 20:42:45 -0800 (PST) From: Anshuman Khandual To: arm-kernel@lists.infradead.org Cc: Anshuman Khandual , Marc Zyngier , Oliver Upton , James Morse , Catalin Marinas , Will Deacon , Ard Biesheuvel , Ryan Roberts , Mark Rutland , kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 2/8] arm64/ptdump: Test PMD_TYPE_MASK for block mapping Date: Fri, 21 Feb 2025 10:12:21 +0530 Message-Id: <20250221044227.1145393-3-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250221044227.1145393-1-anshuman.khandual@arm.com> References: <20250221044227.1145393-1-anshuman.khandual@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Test given page table entries against PMD_TYPE_SECT on PMD_TYPE_MASK mask bits for identifying block mappings in stage 1 page tables. Cc: Catalin Marinas Cc: Will Deacon Cc: Ard Biesheuvel Cc: Ryan Roberts Cc: Mark Rutland Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Anshuman Khandual --- arch/arm64/mm/ptdump.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index 688fbe0271ca..8cec0da4cff2 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -80,8 +80,8 @@ static const struct ptdump_prot_bits pte_bits[] =3D { .set =3D "CON", .clear =3D " ", }, { - .mask =3D PTE_TABLE_BIT | PTE_VALID, - .val =3D PTE_VALID, + .mask =3D PMD_TYPE_MASK, + .val =3D PMD_TYPE_SECT, .set =3D "BLK", .clear =3D " ", }, { --=20 2.25.1 From nobody Wed Dec 17 03:46:00 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 734301FC7D4 for ; Fri, 21 Feb 2025 04:42:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740112977; cv=none; b=pelq2Gj14qF52BhQW8YFi/3qBy3IGDWYVSU/n81om3TT3A3y+1gUTScmP7sASLYDrlQv9xcfsTG764dkyZnPugUbdPYuO3wi8i88vtuH83v0kc6ZJ2eNA2+vNmHoBCGlpklYv+mSyC3gPK65HD8bCxBlryq/wNnv0HF6FXP18os= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740112977; c=relaxed/simple; bh=hueR/qKnuhBthJQUELmNrlp0F0JfQ1aUISp4QGJ6+f4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=V7PPSDtz3S7x3yDUBKgZEEbuthI+LDbLfB+vGZOq4t7pLkMPY5DCuPKgDhYbZXEnzaoft6doaDVMPI+P44Z5BEgT3Trl/IMASuvdsvD19WDoUBxwGrxdRhciaJY2GDG0K9Z3GmaH4Rj8mlGVNnPEhBFyv7ZONJN9hS7w4dvANMA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C0E381C01; Thu, 20 Feb 2025 20:43:13 -0800 (PST) Received: from a077893.blr.arm.com (a077893.blr.arm.com [10.162.40.21]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 630C83F6A8; Thu, 20 Feb 2025 20:42:51 -0800 (PST) From: Anshuman Khandual To: arm-kernel@lists.infradead.org Cc: Anshuman Khandual , Marc Zyngier , Oliver Upton , James Morse , Catalin Marinas , Will Deacon , Ard Biesheuvel , Ryan Roberts , Mark Rutland , kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 3/8] arm64/mm: Clear PXX_TYPE_MASK in mk_[pmd|pud]_sect_prot() Date: Fri, 21 Feb 2025 10:12:22 +0530 Message-Id: <20250221044227.1145393-4-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250221044227.1145393-1-anshuman.khandual@arm.com> References: <20250221044227.1145393-1-anshuman.khandual@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Clear PXX_TYPE_MASK bits in mk_[pmd|pud]_sect_prot() while creating section mappings instead of just clearing the PXX_TABLE_BIT. Cc: Catalin Marinas Cc: Will Deacon Cc: Ard Biesheuvel Cc: Ryan Roberts Cc: Mark Rutland Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Anshuman Khandual --- arch/arm64/include/asm/pgtable.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgta= ble.h index 0b2a2ad1b9e8..c16e9e74e309 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -483,12 +483,12 @@ static inline pmd_t pte_pmd(pte_t pte) =20 static inline pgprot_t mk_pud_sect_prot(pgprot_t prot) { - return __pgprot((pgprot_val(prot) & ~PUD_TABLE_BIT) | PUD_TYPE_SECT); + return __pgprot((pgprot_val(prot) & ~PUD_TYPE_MASK) | PUD_TYPE_SECT); } =20 static inline pgprot_t mk_pmd_sect_prot(pgprot_t prot) { - return __pgprot((pgprot_val(prot) & ~PMD_TABLE_BIT) | PMD_TYPE_SECT); + return __pgprot((pgprot_val(prot) & ~PMD_TYPE_MASK) | PMD_TYPE_SECT); } =20 static inline pte_t pte_swp_mkexclusive(pte_t pte) --=20 2.25.1 From nobody Wed Dec 17 03:46:00 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A523B1FBE89 for ; Fri, 21 Feb 2025 04:43:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740112983; cv=none; b=mdLNLlGezjbihxFw5jQ2ZZMDrcZ5UHMX4OQKnOdl7ItnrYMZZisQms4cQlDHWB742pJWKEBL9pE3Rj5EUVPeKjndXmzDVVXUq87GYPOraEwNNmmCrDLvAOrXAl5kTcpCIE7nD+rd9XAfHQLkqQ6oGVykEKRe/YeL3k8Dxe+ZUGY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740112983; c=relaxed/simple; bh=w12RmaK2E7AsICmm7r1Zy5+t5NgzhGpim7OZ2dRKUyA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fGaovn7Cg4+5UsycuHrsC3MBBnsrWNUVwXx8ZlgUH7XsifPz/QS6Sgq8+6mdNzNuskrjL2B8UO5K+KXC/QGhrjEUMzz1MBDF/lgmzxZ7F1yijDRK++Fzt3gCcLja6ofspxQHeZTq3gaxBMdpXD5bC/xyNfVZYyA0czkFaECWijU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DBB601C01; Thu, 20 Feb 2025 20:43:18 -0800 (PST) Received: from a077893.blr.arm.com (a077893.blr.arm.com [10.162.40.21]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 808E03F6A8; Thu, 20 Feb 2025 20:42:56 -0800 (PST) From: Anshuman Khandual To: arm-kernel@lists.infradead.org Cc: Anshuman Khandual , Marc Zyngier , Oliver Upton , James Morse , Catalin Marinas , Will Deacon , Ard Biesheuvel , Ryan Roberts , Mark Rutland , kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 4/8] arm64/mm: Clear PXX_TYPE_MASK and set PXD_TYPE_SECT in [pmd|pud]_mkhuge() Date: Fri, 21 Feb 2025 10:12:23 +0530 Message-Id: <20250221044227.1145393-5-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250221044227.1145393-1-anshuman.khandual@arm.com> References: <20250221044227.1145393-1-anshuman.khandual@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Clear PXX_TYPE_MASK in [pmd|pud]_mkhuge() while creating section mappings instead of just the PXX_TABLE_BIT and also set PXD_TYPE_SECT. Also ensure PTE_VALID does not get modified in these helpers, because present-invalid entries should preserve their state across. Cc: Catalin Marinas Cc: Will Deacon Cc: Ard Biesheuvel Cc: Ryan Roberts Cc: Mark Rutland Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Anshuman Khandual --- arch/arm64/include/asm/pgtable.h | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgta= ble.h index c16e9e74e309..4485ecdffd8a 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -585,7 +585,18 @@ static inline int pmd_trans_huge(pmd_t pmd) =20 #define pmd_write(pmd) pte_write(pmd_pte(pmd)) =20 -#define pmd_mkhuge(pmd) (__pmd(pmd_val(pmd) & ~PMD_TABLE_BIT)) +static inline pmd_t pmd_mkhuge(pmd_t pmd) +{ + /* + * It's possible that the pmd is present-invalid on entry + * and in that case it needs to remain present-invalid on + * exit. So ensure the VALID bit does not get modified. + */ + pmdval_t mask =3D PMD_TYPE_MASK & ~PTE_VALID; + pmdval_t val =3D PMD_TYPE_SECT & ~PTE_VALID; + + return __pmd((pmd_val(pmd) & ~mask) | val); +} =20 #ifdef CONFIG_TRANSPARENT_HUGEPAGE #define pmd_devmap(pmd) pte_devmap(pmd_pte(pmd)) @@ -613,7 +624,18 @@ static inline pmd_t pmd_mkspecial(pmd_t pmd) #define pud_mkyoung(pud) pte_pud(pte_mkyoung(pud_pte(pud))) #define pud_write(pud) pte_write(pud_pte(pud)) =20 -#define pud_mkhuge(pud) (__pud(pud_val(pud) & ~PUD_TABLE_BIT)) +static inline pud_t pud_mkhuge(pud_t pud) +{ + /* + * It's possible that the pud is present-invalid on entry + * and in that case it needs to remain present-invalid on + * exit. So ensure the VALID bit does not get modified. + */ + pudval_t mask =3D PUD_TYPE_MASK & ~PTE_VALID; + pudval_t val =3D PUD_TYPE_SECT & ~PTE_VALID; + + return __pud((pud_val(pud) & ~mask) | val); +} =20 #define __pud_to_phys(pud) __pte_to_phys(pud_pte(pud)) #define __phys_to_pud_val(phys) __phys_to_pte_val(phys) --=20 2.25.1 From nobody Wed Dec 17 03:46:00 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 654A41FBE89 for ; Fri, 21 Feb 2025 04:43:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740112987; cv=none; b=FIv8LTl1gD0fkcSpXIiX67b7DD8dMaZ2Uza6OTCug0YV6GQEy+TTZSUcSYXR72B5V1ap4Ij9nm2+r+C0iCQYwGHaFFrlOnP2tUes/YeybwBeuzamRY36cG6EhszOigxpfx91uVR1ViBqiTfBtktPtmnECYWe1S0h4vlC6IQS4Eg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740112987; c=relaxed/simple; bh=0PX5MVDBSGVG2PGxKPjhBBIhYbfxharACAP4e3x6TKA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Gsbub33lxr1XVXjYJU35DNTvQPr8c83aXwtajdCeIxXFbgMLoC7faAz0sXSKcQHkYfwqHME26jTs4ksFJA4YQtBca+KddZW0iR8Vu2z6CIWLa2wS6VIeVHwaSEqYWT0RfihVZA7+y8o6Ku8nLAusinj214D+QccpPBjYNv1++EU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DF2B01C01; Thu, 20 Feb 2025 20:43:23 -0800 (PST) Received: from a077893.blr.arm.com (a077893.blr.arm.com [10.162.40.21]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id B72703F6A8; Thu, 20 Feb 2025 20:43:01 -0800 (PST) From: Anshuman Khandual To: arm-kernel@lists.infradead.org Cc: Anshuman Khandual , Marc Zyngier , Oliver Upton , James Morse , Catalin Marinas , Will Deacon , Ard Biesheuvel , Ryan Roberts , Mark Rutland , kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 5/8] arm64/mm: Check PXD_TYPE_TABLE in [p4d|pgd]_bad() Date: Fri, 21 Feb 2025 10:12:24 +0530 Message-Id: <20250221044227.1145393-6-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250221044227.1145393-1-anshuman.khandual@arm.com> References: <20250221044227.1145393-1-anshuman.khandual@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Check page table entries against PXD_TYPE_TABLE on PXD_TYPE_MASK mask bits in [p4d|pgd]_bad() while determining a table entry instead of just checking only for PXD_TABLE_BIT. Cc: Catalin Marinas Cc: Will Deacon Cc: Ard Biesheuvel Cc: Ryan Roberts Cc: Mark Rutland Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Anshuman Khandual --- arch/arm64/include/asm/pgtable.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgta= ble.h index 4485ecdffd8a..0c1691979c14 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -918,7 +918,9 @@ static inline bool mm_pud_folded(const struct mm_struct= *mm) pr_err("%s:%d: bad pud %016llx.\n", __FILE__, __LINE__, pud_val(e)) =20 #define p4d_none(p4d) (pgtable_l4_enabled() && !p4d_val(p4d)) -#define p4d_bad(p4d) (pgtable_l4_enabled() && !(p4d_val(p4d) & P4D_TABLE_= BIT)) +#define p4d_bad(p4d) (pgtable_l4_enabled() && \ + ((p4d_val(p4d) & P4D_TYPE_MASK) !=3D \ + P4D_TYPE_TABLE)) #define p4d_present(p4d) (!p4d_none(p4d)) =20 static inline void set_p4d(p4d_t *p4dp, p4d_t p4d) @@ -1045,7 +1047,9 @@ static inline bool mm_p4d_folded(const struct mm_stru= ct *mm) pr_err("%s:%d: bad p4d %016llx.\n", __FILE__, __LINE__, p4d_val(e)) =20 #define pgd_none(pgd) (pgtable_l5_enabled() && !pgd_val(pgd)) -#define pgd_bad(pgd) (pgtable_l5_enabled() && !(pgd_val(pgd) & PGD_TABLE_= BIT)) +#define pgd_bad(pgd) (pgtable_l5_enabled() && \ + ((pgd_val(pgd) & PGD_TYPE_MASK) !=3D \ + PGD_TYPE_TABLE)) #define pgd_present(pgd) (!pgd_none(pgd)) =20 static inline void set_pgd(pgd_t *pgdp, pgd_t pgd) --=20 2.25.1 From nobody Wed Dec 17 03:46:00 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 86AE31E9B04 for ; Fri, 21 Feb 2025 04:43:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740112992; cv=none; b=JNoQqjHPSXcE1DZbtmM5nRyRIxZLRYOVjM4vY8jHl2/r4rKKTP0RayTgJzcPUkhE2KePwX55BDWI53lOFTGf/zwgH7RqkHGYvTOzV9c3SOmZU1l5Jm/MyXT7vKaSXJIoVOKSZ2JvbvoLP8MoRW79cI+G69zBf2KSU2HBopo/m4o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740112992; c=relaxed/simple; bh=S77b++vPhAM9w69z2S5XUCUrpjXKuwTVoLA5kTrEL8k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MvEUjfbPK4Z9VpPZ01opueybkZFHf8twARP4tPHTieo5I5PkX8SjLlfbmPwK6GgcllBdJIHQc7GK32n8VdGvKhh9S/dzQZjh7pYU8srpCZHVTiEQ/+Cu/jM4RmQkIa4FHHqsN+k/XB4WafjyBme4wSR+0iqF6hwxyj3g0547QEs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 094C71C01; Thu, 20 Feb 2025 20:43:29 -0800 (PST) Received: from a077893.blr.arm.com (a077893.blr.arm.com [10.162.40.21]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id A1BFE3F6A8; Thu, 20 Feb 2025 20:43:06 -0800 (PST) From: Anshuman Khandual To: arm-kernel@lists.infradead.org Cc: Anshuman Khandual , Marc Zyngier , Oliver Upton , James Morse , Catalin Marinas , Will Deacon , Ard Biesheuvel , Ryan Roberts , Mark Rutland , kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 6/8] arm64/mm: Check PUD_TYPE_TABLE in pud_bad() Date: Fri, 21 Feb 2025 10:12:25 +0530 Message-Id: <20250221044227.1145393-7-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250221044227.1145393-1-anshuman.khandual@arm.com> References: <20250221044227.1145393-1-anshuman.khandual@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ryan Roberts pud_bad() is currently defined in terms of pud_table(). Although for some configs, pud_table() is hard-coded to true i.e. when using 64K base pages or when page table levels are less than 3. pud_bad() is intended to check that the pud is configured correctly. Hence let's open-code the same check that the full version of pud_table() uses into pud_bad(). Then it always performs the check regardless of the config. Cc: Catalin Marinas Cc: Will Deacon Cc: Ard Biesheuvel Cc: Ryan Roberts Cc: Mark Rutland Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Ryan Roberts Signed-off-by: Anshuman Khandual --- arch/arm64/include/asm/pgtable.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgta= ble.h index 0c1691979c14..d16f514bde0f 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -827,7 +827,8 @@ static inline unsigned long pmd_page_vaddr(pmd_t pmd) pr_err("%s:%d: bad pmd %016llx.\n", __FILE__, __LINE__, pmd_val(e)) =20 #define pud_none(pud) (!pud_val(pud)) -#define pud_bad(pud) (!pud_table(pud)) +#define pud_bad(pud) ((pud_val(pud) & PUD_TYPE_MASK) !=3D \ + PUD_TYPE_TABLE) #define pud_present(pud) pte_present(pud_pte(pud)) #ifndef __PAGETABLE_PMD_FOLDED #define pud_leaf(pud) (pud_present(pud) && !pud_table(pud)) --=20 2.25.1 From nobody Wed Dec 17 03:46:00 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A719A1FBC9A for ; Fri, 21 Feb 2025 04:43:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740112998; cv=none; b=kjMhDqjhiLXPUTWIijqVmi4gkb0SciUMEkbtTAHzgwyQodkwhsRtOJatNM/Tba/uLGglJNur2Xgj/IFGZaQrJTV/ZrPG/mB2soSJJSnbJAloogS7qvFE8Pes8FzhyX7gDN+OZCFt+/0jZOYKtfTf/5b9Kmpo4+pbFiKobCg6cG4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740112998; c=relaxed/simple; bh=o7ocm2mFHHcbmmMokLaKZy8UH7LG+uFyktAwvZTFEd0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=e23CsKVRyu6HmCUOMN/BtO3FrKhuWXYdFkxN8vJZfEQQ61xNIvPVcz3g4wsy293a1lm/BxTqtay6UGoQ3X4CivB3YJWCvtK3eNrSshGIK9SxpdcCI5srMu1yeiD8IVsgGtqL0eqyfRlVIGPWEN0OCo4lPmXR+oNkhSsgrqrKw3o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 261351C01; Thu, 20 Feb 2025 20:43:34 -0800 (PST) Received: from a077893.blr.arm.com (a077893.blr.arm.com [10.162.40.21]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id BF62E3F6A8; Thu, 20 Feb 2025 20:43:11 -0800 (PST) From: Anshuman Khandual To: arm-kernel@lists.infradead.org Cc: Anshuman Khandual , Marc Zyngier , Oliver Upton , James Morse , Catalin Marinas , Will Deacon , Ard Biesheuvel , Ryan Roberts , Mark Rutland , kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 7/8] arm64/mm: Check pmd_table() in pmd_trans_huge() Date: Fri, 21 Feb 2025 10:12:26 +0530 Message-Id: <20250221044227.1145393-8-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250221044227.1145393-1-anshuman.khandual@arm.com> References: <20250221044227.1145393-1-anshuman.khandual@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ryan Roberts Check for pmd_table() in pmd_trans_huge() rather then just checking for the PMD_TABLE_BIT. But ensure all present-invalid entries are handled correctly by always setting PTE_VALID before checking with pmd_table(). Cc: Catalin Marinas Cc: Will Deacon Cc: Ard Biesheuvel Cc: Ryan Roberts Cc: Mark Rutland Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Ryan Roberts Signed-off-by: Anshuman Khandual --- arch/arm64/include/asm/pgtable.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgta= ble.h index d16f514bde0f..df89e8ec8413 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -548,18 +548,6 @@ static inline int pmd_protnone(pmd_t pmd) #endif =20 #define pmd_present(pmd) pte_present(pmd_pte(pmd)) - -/* - * THP definitions. - */ - -#ifdef CONFIG_TRANSPARENT_HUGEPAGE -static inline int pmd_trans_huge(pmd_t pmd) -{ - return pmd_val(pmd) && pmd_present(pmd) && !(pmd_val(pmd) & PMD_TABLE_BIT= ); -} -#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ - #define pmd_dirty(pmd) pte_dirty(pmd_pte(pmd)) #define pmd_young(pmd) pte_young(pmd_pte(pmd)) #define pmd_valid(pmd) pte_valid(pmd_pte(pmd)) @@ -746,6 +734,18 @@ extern pgprot_t phys_mem_access_prot(struct file *file= , unsigned long pfn, #define pmd_leaf_size(pmd) (pmd_cont(pmd) ? CONT_PMD_SIZE : PMD_SIZE) #define pte_leaf_size(pte) (pte_cont(pte) ? CONT_PTE_SIZE : PAGE_SIZE) =20 +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +static inline int pmd_trans_huge(pmd_t pmd) +{ + /* + * If pmd is present-invalid, pmd_table() won't detect it + * as a table, so force the valid bit for the comparison. + */ + return pmd_val(pmd) && pmd_present(pmd) && + !pmd_table(__pmd(pmd_val(pmd) | PTE_VALID)); +} +#endif /* CONFIG_TRANSPARENT_HUGEPAGE */ + #if defined(CONFIG_ARM64_64K_PAGES) || CONFIG_PGTABLE_LEVELS < 3 static inline bool pud_sect(pud_t pud) { return false; } static inline bool pud_table(pud_t pud) { return true; } --=20 2.25.1 From nobody Wed Dec 17 03:46:00 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E2A541CD1E1 for ; Fri, 21 Feb 2025 04:43:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740113003; cv=none; b=ahhavdcV1AfXfYB5ASyLtLO4R0dS5kBiZiiy/hK9jCxkQnjPVljCvBsdwffyNZ6fGZxwppMCVEd7V7WM/ufMGrNPhyrVN6t6tmB85hH1xlh+pdBHC9TDuODs5+KBX4lREIecngCf1Skc1MXv9Ty4LYkUsbcVixn6tEKYXyGWyfo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740113003; c=relaxed/simple; bh=D2OKJrx1OW0VXw8kaAyRpIYZbuy2DmVlwH6ECyJpnJM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=N7ai37Md5zeRBEC0ADQO6oG+p/w707LwbMuigFGg0JJhZjAIgHQGnjxIzzfi3WrfUeBzs/OSfCj3sAJ3DuCqWNMM36CNye8L/PzdNBKSanHL2gCbAhRFh7Aj/Z8LxNvoHfPS2YGplOC7uLPFXvRGlh7Mltze/g+hRAkR5uPY1lg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2A1DD271B; Thu, 20 Feb 2025 20:43:39 -0800 (PST) Received: from a077893.blr.arm.com (a077893.blr.arm.com [10.162.40.21]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id DCE923F6A8; Thu, 20 Feb 2025 20:43:16 -0800 (PST) From: Anshuman Khandual To: arm-kernel@lists.infradead.org Cc: Anshuman Khandual , Marc Zyngier , Oliver Upton , James Morse , Catalin Marinas , Will Deacon , Ard Biesheuvel , Ryan Roberts , Mark Rutland , kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 8/8] arm64/mm: Drop PXD_TABLE_BIT Date: Fri, 21 Feb 2025 10:12:27 +0530 Message-Id: <20250221044227.1145393-9-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250221044227.1145393-1-anshuman.khandual@arm.com> References: <20250221044227.1145393-1-anshuman.khandual@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Drop all PXD_TABLE_BIT macros as they are not used any more. Cc: Catalin Marinas Cc: Will Deacon Cc: Ard Biesheuvel Cc: Ryan Roberts Cc: Mark Rutland Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Anshuman Khandual --- arch/arm64/include/asm/pgtable-hwdef.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/arch/arm64/include/asm/pgtable-hwdef.h b/arch/arm64/include/as= m/pgtable-hwdef.h index a9136cc551cc..d2a13c329702 100644 --- a/arch/arm64/include/asm/pgtable-hwdef.h +++ b/arch/arm64/include/asm/pgtable-hwdef.h @@ -97,7 +97,6 @@ * Level -1 descriptor (PGD). */ #define PGD_TYPE_TABLE (_AT(pgdval_t, 3) << 0) -#define PGD_TABLE_BIT (_AT(pgdval_t, 1) << 1) #define PGD_TYPE_MASK (_AT(pgdval_t, 3) << 0) #define PGD_TABLE_AF (_AT(pgdval_t, 1) << 10) /* Ignored if no FEAT_HAFT = */ #define PGD_TABLE_PXN (_AT(pgdval_t, 1) << 59) @@ -107,7 +106,6 @@ * Level 0 descriptor (P4D). */ #define P4D_TYPE_TABLE (_AT(p4dval_t, 3) << 0) -#define P4D_TABLE_BIT (_AT(p4dval_t, 1) << 1) #define P4D_TYPE_MASK (_AT(p4dval_t, 3) << 0) #define P4D_TYPE_SECT (_AT(p4dval_t, 1) << 0) #define P4D_SECT_RDONLY (_AT(p4dval_t, 1) << 7) /* AP[2] */ @@ -119,7 +117,6 @@ * Level 1 descriptor (PUD). */ #define PUD_TYPE_TABLE (_AT(pudval_t, 3) << 0) -#define PUD_TABLE_BIT (_AT(pudval_t, 1) << 1) #define PUD_TYPE_MASK (_AT(pudval_t, 3) << 0) #define PUD_TYPE_SECT (_AT(pudval_t, 1) << 0) #define PUD_SECT_RDONLY (_AT(pudval_t, 1) << 7) /* AP[2] */ @@ -133,7 +130,6 @@ #define PMD_TYPE_MASK (_AT(pmdval_t, 3) << 0) #define PMD_TYPE_TABLE (_AT(pmdval_t, 3) << 0) #define PMD_TYPE_SECT (_AT(pmdval_t, 1) << 0) -#define PMD_TABLE_BIT (_AT(pmdval_t, 1) << 1) #define PMD_TABLE_AF (_AT(pmdval_t, 1) << 10) /* Ignored if no FEAT_HAFT = */ =20 /* @@ -162,7 +158,6 @@ #define PTE_VALID (_AT(pteval_t, 1) << 0) #define PTE_TYPE_MASK (_AT(pteval_t, 3) << 0) #define PTE_TYPE_PAGE (_AT(pteval_t, 3) << 0) -#define PTE_TABLE_BIT (_AT(pteval_t, 1) << 1) #define PTE_USER (_AT(pteval_t, 1) << 6) /* AP[1] */ #define PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */ #define PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */ --=20 2.25.1