From nobody Fri Dec 19 18:21:44 2025 Received: from out187-23.us.a.mail.aliyun.com (out187-23.us.a.mail.aliyun.com [47.90.187.23]) (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 E4D181C460A for ; Sat, 29 Mar 2025 13:36:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=47.90.187.23 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743255403; cv=none; b=IIN+Dw845AsdfYxTNpoewdIf/1KGlMcIsHra9pQI9VOyqj1ZJLuRCi/G2uMnhP50rU6O8lgYV2/BnLQAD1M3DvTBw3DAqlYjns4qzHwLzEFtfz1n9/39rFw6CFFBaaSqxNmE5VpqvCi9vsVLZy8XxOIcTW1G1BP+C9x2pGfALeo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743255403; c=relaxed/simple; bh=GYA6XhR04RH+1CAfGlxWuNUtvxz+KVpOVf0+Uyr+8/U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HT+P7/LXrbWVadK+XIkwmLDiTOjaIv2fBBbR4QdNFGsDBPOB9yi1cXliePEdgp9yfneOoFUVK3KHpLvO3PfBXOfqxlmE4BExTZWzL2U+XQV4O/16fmmwefR1MPidiiQwLwitx2/9GZAsEOpa2VWnx1qmXHc+RvAWJysSbmZldwk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=antgroup.com; spf=pass smtp.mailfrom=antgroup.com; dkim=pass (1024-bit key) header.d=antgroup.com header.i=@antgroup.com header.b=hga6NPIf; arc=none smtp.client-ip=47.90.187.23 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=antgroup.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antgroup.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antgroup.com header.i=@antgroup.com header.b="hga6NPIf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antgroup.com; s=default; t=1743255385; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=eajsjoiON1I0Jxv4Hsr4N5ua6b1s7QOKAILrBRn4bpM=; b=hga6NPIf8GI/H5QBBckg8fs/izWnHFnysOz+hQLv/Oa3BA9336mYI76Co5HGpCGRJHPJwsv6QI2clAM6mNq/baAsEgtw28ApOv7gjf9JljRnrkMo6q26JWTQGhk/IKpb1MjKyCwGEWzMEPVzo7HiE0acoBd+Dp0FVyJSuKzhA4k= Received: from localhost(mailfrom:houwenlong.hwl@antgroup.com fp:SMTPD_---.c7ROdG-_1743253534 cluster:ay29) by smtp.aliyun-inc.com; Sat, 29 Mar 2025 21:05:35 +0800 From: "Hou Wenlong" To: linux-kernel@vger.kernel.org Cc: "Hou Wenlong" , "Dave Hansen" , "Andy Lutomirski" , "Peter Zijlstra" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , , "H. Peter Anvin" , "Rik van Riel" Subject: [PATCH 1/3] x86/mm: Correct the actual count of available global ASIDs Date: Sat, 29 Mar 2025 21:05:24 +0800 Message-Id: <0954cb7ec766d6d1e0b66a93876762b516ae9bae.1743250122.git.houwenlong.hwl@antgroup.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: 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" The available ASID range for global ASID allocation is [TLB_NR_DYN_ASIDS, MAX_ASID_AVAILABLE-1], which is a close interval. So the actual count of available ASIDs for global ASID allocation should be '(MAX_ASID_AVIALBE-1) - TLB_NR_DYN_ASIDS + 1'. Fixes: d504d1247e36 ("x86/mm: Add global ASID allocation helper functions") Signed-off-by: Hou Wenlong --- arch/x86/mm/tlb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index e459d97ef397..cad4a8eae2d8 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -279,7 +279,7 @@ static DEFINE_RAW_SPINLOCK(global_asid_lock); static u16 last_global_asid =3D MAX_ASID_AVAILABLE; static DECLARE_BITMAP(global_asid_used, MAX_ASID_AVAILABLE); static DECLARE_BITMAP(global_asid_freed, MAX_ASID_AVAILABLE); -static int global_asid_available =3D MAX_ASID_AVAILABLE - TLB_NR_DYN_ASIDS= - 1; +static int global_asid_available =3D MAX_ASID_AVAILABLE - TLB_NR_DYN_ASIDS; =20 /* * When the search for a free ASID in the global ASID space reaches --=20 2.31.1 From nobody Fri Dec 19 18:21:44 2025 Received: from out0-218.mail.aliyun.com (out0-218.mail.aliyun.com [140.205.0.218]) (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 9C11B18A92D for ; Sat, 29 Mar 2025 13:21:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=140.205.0.218 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743254477; cv=none; b=QK3l7C7PnyzD7a9Moo/bszj9jUF4K44fIFJLLzwcs7qCwb6Z+KrpIm++JLQYZMFI/cnp4Om5TQtOlQ4RWzBYGgXkJYUMgzcrSyThhFujSPHCeSWAIQK95PezevtzGTfIK3GyMQdh5liPU1UaDcZVC7usLzyafFwA1IiOPO7cT6k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743254477; c=relaxed/simple; bh=tdHBFBo/TEYibTp45k+sQQzC3i+qYGY+W8PbDi4tgrg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=d7Fag+bFOAWp4gUZdjNmA59Epfxz1IHTbZtzD6wLdiBJtq5jVyEdbOlZ4Z2dIyyihq30VFyu/9uA5c7blyB8K4DEF3VCdHaFryQLkdXe+rQoEaaAOMmQzwHqxbjQZy+hWRL+b9s9IGjxf6L5wHA9+ulK27408BWTn8Rpfq8xgHk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=antgroup.com; spf=pass smtp.mailfrom=antgroup.com; dkim=pass (1024-bit key) header.d=antgroup.com header.i=@antgroup.com header.b=AowBBROc; arc=none smtp.client-ip=140.205.0.218 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=antgroup.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antgroup.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antgroup.com header.i=@antgroup.com header.b="AowBBROc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antgroup.com; s=default; t=1743254470; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=pO5v6BVMqgqC6aARK169RT0wgqkBk4nwsWaRp7E2lKM=; b=AowBBROc6jIYsF5XLraCCHCZXLVFTD1b8V+Eyg/EdXuOz3/XxZBYORtognBpjecTAZ9lwEmNOTdOd5dbeDfpSZ/siKyloQKRBQgisng11OHU30lSP+Y3V1nAeKh8M9qrJAscBbPS5kFz9GJ7eMsvMSJDPeyycGqJAF5P2GDe9pg= Received: from localhost(mailfrom:houwenlong.hwl@antgroup.com fp:SMTPD_---.c6kOebC_1743253536 cluster:ay29) by smtp.aliyun-inc.com; Sat, 29 Mar 2025 21:05:36 +0800 From: "Hou Wenlong" To: linux-kernel@vger.kernel.org Cc: "Hou Wenlong" , "Dave Hansen" , "Andy Lutomirski" , "Peter Zijlstra" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , , "H. Peter Anvin" , "Rik van Riel" Subject: [PATCH 2/3] mm/tlb: Fix wrong judgement in allocate_global_asid() Date: Sat, 29 Mar 2025 21:05:25 +0800 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: 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" In allocate_global_asid(), 'global_asid_available' cannot be zero, as it has already been checked in use_global_asid(). Therefore, the warning in allocate_global_asid() cannot be triggered; fix the wrong judgment in allocate_global_asid(). Fixes: d504d1247e36 ("x86/mm: Add global ASID allocation helper functions") Signed-off-by: Hou Wenlong Reviewed-by: Rik van Riel --- arch/x86/mm/tlb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index cad4a8eae2d8..e9eda296fb0e 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -319,7 +319,7 @@ static u16 allocate_global_asid(void) =20 asid =3D find_next_zero_bit(global_asid_used, MAX_ASID_AVAILABLE, last_gl= obal_asid); =20 - if (asid >=3D MAX_ASID_AVAILABLE && !global_asid_available) { + if (asid >=3D MAX_ASID_AVAILABLE && global_asid_available) { /* This should never happen. */ VM_WARN_ONCE(1, "Unable to allocate global ASID despite %d available\n", global_asid_available); --=20 2.31.1 From nobody Fri Dec 19 18:21:45 2025 Received: from out0-196.mail.aliyun.com (out0-196.mail.aliyun.com [140.205.0.196]) (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 EE1101B424F for ; Sat, 29 Mar 2025 13:21:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=140.205.0.196 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743254481; cv=none; b=UAizlUj3SgH7b99p2ygB9N076UQldcJg6aS+2NQJujYmZY4H+slO+gj2sVx0SN/l1Nzfeh5kC/2tiZuO9iXq9COYXfGsrAV0Uho+QiPoPgqBr44wnT+c8f3HHQeE8FsihBX4izauP5Wrdz7VjvX9gUo600OBUNmGqmi/HX8G2qE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743254481; c=relaxed/simple; bh=Tj33r8eFpGults4WH7vOF0SmaR01AmzbqRML+2nDOwQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eOdKFPFVq9sFq4yogvsZi7OXa7hJrMMVj7XO0eUEgOQVhxW5bJphUi/q6DzBgRF3qxSqn4E8OIeT1LqfAH8V29VEvbxrcbUzKTSVsFjsrVSXbGMoHQan3MrTsj+Lm8zzNDbLCy9T2MLZ6KLBNY7TJNm68nN7xpOs/IvdEzR4+pE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=antgroup.com; spf=pass smtp.mailfrom=antgroup.com; dkim=pass (1024-bit key) header.d=antgroup.com header.i=@antgroup.com header.b=XFltEFGi; arc=none smtp.client-ip=140.205.0.196 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=antgroup.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antgroup.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=antgroup.com header.i=@antgroup.com header.b="XFltEFGi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=antgroup.com; s=default; t=1743254474; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=aY+k5xAO7wlEJHM5XbSfo9/O2E1HKvzBj9211YyF+U4=; b=XFltEFGifNO1MOmmbDmIp1zqHaflS28WIMY4DuOVqaf75NYyEVV1HRPmbiGW0P+8x7w0wFaDSlbHj1ld7qTOA+aOBoX28uuOulev0UN4/xIwcJqAT0GBNa8PCY6H+cAGZhCfB9lizwAfCaK3Pav3RMOgOL+thmbp/GGyImllLg8= Received: from localhost(mailfrom:houwenlong.hwl@antgroup.com fp:SMTPD_---.c6iAtj2_1743253538 cluster:ay29) by smtp.aliyun-inc.com; Sat, 29 Mar 2025 21:05:38 +0800 From: "Hou Wenlong" To: linux-kernel@vger.kernel.org Cc: "Hou Wenlong" , "Dave Hansen" , "Andy Lutomirski" , "Peter Zijlstra" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , , "H. Peter Anvin" Subject: [PATCH 3/3] x86/mm: Fix wrong usage of 'MAX_ASID_AVAILABLE' in global ASID allocation Date: Sat, 29 Mar 2025 21:05:26 +0800 Message-Id: <55dd1b47ef7c8dd5518878fc682290825570225d.1743250122.git.houwenlong.hwl@antgroup.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: 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" 'MAX_ASID_AVAILABLE' represents the maximum valid ASID in the current definetion, meaning that the available ASID range is [0, MAX_ASID_AVAILABLE]. So the actual count of available ASIDs is 'MAX_ASID_AVAIABLE + 1'. However, global ASID allocation use this value as the size of the bitmap, which results in the maximum ASID number being excluded from global ASID allocation. To address this issue, redefine the 'MAX_ASID_AVAILABLE' as the count of available ASIDs. Signed-off-by: Hou Wenlong Reviewed-by: Rik van Riel --- arch/x86/mm/tlb.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c index e9eda296fb0e..0f86c3140fdc 100644 --- a/arch/x86/mm/tlb.c +++ b/arch/x86/mm/tlb.c @@ -102,18 +102,17 @@ #define CR3_AVAIL_PCID_BITS (X86_CR3_PCID_BITS - PTI_CONSUMED_PCID_BITS) /* - * ASIDs are zero-based: 0->MAX_AVAIL_ASID are valid. -1 below to account - * for them being zero-based. Another -1 is because PCID 0 is reserved for - * use by non-PCID-aware users. + * ASIDs are zero-based: 0->MAX_ASID_AVAILABLE-1 are valid. -1 is because= PCID + * 0 is reserved for use by non-PCID-aware users. */ -#define MAX_ASID_AVAILABLE ((1 << CR3_AVAIL_PCID_BITS) - 2) +#define MAX_ASID_AVAILABLE ((1 << CR3_AVAIL_PCID_BITS) - 1) /* * Given @asid, compute kPCID */ static inline u16 kern_pcid(u16 asid) { - VM_WARN_ON_ONCE(asid > MAX_ASID_AVAILABLE); + VM_WARN_ON_ONCE(asid >=3D MAX_ASID_AVAILABLE); #ifdef CONFIG_MITIGATION_PAGE_TABLE_ISOLATION /* -- 2.31.1