From nobody Fri Dec 19 12:31:07 2025 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (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 EC2D020DC7 for ; Tue, 19 Dec 2023 15:12:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="XAHWTTH3" Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3BJ9wuhs017135; Tue, 19 Dec 2023 15:12:16 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2023-11-20; bh=J8ZeLl+PGi8hKGYRJZMnlviIymGZLOM1z26ehHHKW20=; b=XAHWTTH3CS1TzVHi6QGwwojDjChn/AhPCQNC9oTwebi2DQkaD41REK2mMm3wQgKMutua DQQ3Tajj13wxDkTLugTiyIozgO7xGgn8p2WdOBFJLyrix8YMH3Zd+yBIkBO4aeZJNSFV BEYcTUDXGzpyYEIlL0PtTxbqAIrHjWAi/X5vyMS82O5OMjbnmKEKUpzu2Fv/sKHT3P+q Kd0lIYQCqMsEyfLzQ0IgEd7IdEtHzcq7fNgG4AVopQZn+NTEV2jHPBs7sIbO2CJOQQma 1A9/I70RpyWkijGvZfy9Vji3y0WRj3UdnydRHDBMMhClcnVjiea7PqIVtgyG3oFpQICL QQ== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3v12p465pb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Dec 2023 15:12:16 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 3BJEAb9N029105; Tue, 19 Dec 2023 15:12:15 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3v12b6w7c3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Dec 2023 15:12:15 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3BJF7SdP008899; Tue, 19 Dec 2023 15:12:14 GMT Received: from localhost.localdomain (dhcp-10-175-58-169.vpn.oracle.com [10.175.58.169]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3v12b6w71u-3; Tue, 19 Dec 2023 15:12:14 +0000 From: Vegard Nossum To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: "H. Peter Anvin" , linux-kernel@vger.kernel.org, Brian Gerst , Peter Zijlstra , Linus Torvalds , Vegard Nossum Subject: [PATCH 2/5] x86: replace magic numbers in GDT descriptors, part 1 Date: Tue, 19 Dec 2023 16:11:57 +0100 Message-Id: <20231219151200.2878271-3-vegard.nossum@oracle.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231219151200.2878271-1-vegard.nossum@oracle.com> References: <20231219151200.2878271-1-vegard.nossum@oracle.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 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-19_08,2023-12-14_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 malwarescore=0 phishscore=0 mlxscore=0 bulkscore=0 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2312190113 X-Proofpoint-GUID: iC0-4Gw37qFi30fZuKLHZL7xhP7oriIM X-Proofpoint-ORIG-GUID: iC0-4Gw37qFi30fZuKLHZL7xhP7oriIM Content-Type: text/plain; charset="utf-8" We'd like to replace all the magic numbers in various GDT descriptors with new, semantically meaningful, symbolic values. In order to be able to verify that the change doesn't cause any actual changes to the compiled binary code, I've split the change into two patches: Part 1 (this commit): everything _but_ actually replacing the numbers Part 2 (the following commit): _only_ replacing the numbers These two commits may be squashed together when merged. The reason we need this split for verification is that including new headers causes some spurious changes to the object files, mostly line number changes in the debug info but occasionally other subtle codegen changes. Link: https://lore.kernel.org/all/CAHk-=3Dwib5XLebuEra7y2YH96wxdk=3D8vJnA8X= oVq0FExpzVvN=3DQ@mail.gmail.com/ Signed-off-by: Vegard Nossum --- arch/x86/boot/pm.c | 1 + arch/x86/include/asm/desc_defs.h | 2 ++ arch/x86/kernel/cpu/common.c | 8 -------- arch/x86/platform/pvh/head.S | 1 + arch/x86/realmode/rm/reboot.S | 1 + 5 files changed, 5 insertions(+), 8 deletions(-) diff --git a/arch/x86/boot/pm.c b/arch/x86/boot/pm.c index 40031a614712..0361b5307bd8 100644 --- a/arch/x86/boot/pm.c +++ b/arch/x86/boot/pm.c @@ -11,6 +11,7 @@ */ =20 #include "boot.h" +#include #include =20 /* diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_d= efs.h index b33f5bb240eb..014878e584fe 100644 --- a/arch/x86/include/asm/desc_defs.h +++ b/arch/x86/include/asm/desc_defs.h @@ -144,6 +144,7 @@ struct gate_struct { =20 typedef struct gate_struct gate_desc; =20 +#ifndef _SETUP static inline unsigned long gate_offset(const gate_desc *g) { #ifdef CONFIG_X86_64 @@ -158,6 +159,7 @@ static inline unsigned long gate_segment(const gate_des= c *g) { return g->segment; } +#endif =20 struct desc_ptr { unsigned short size; diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index b14fc8c1c953..ceb6e4b6d57e 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -204,25 +204,17 @@ DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page= ) =3D { .gdt =3D { * They code segments and data segments have fixed 64k limits, * the transfer segment sizes are set at run time. */ - /* 32-bit code */ [GDT_ENTRY_PNPBIOS_CS32] =3D GDT_ENTRY_INIT(0x409a, 0, 0xffff), - /* 16-bit code */ [GDT_ENTRY_PNPBIOS_CS16] =3D GDT_ENTRY_INIT(0x009a, 0, 0xffff), - /* 16-bit data */ [GDT_ENTRY_PNPBIOS_DS] =3D GDT_ENTRY_INIT(0x0092, 0, 0xffff), - /* 16-bit data */ [GDT_ENTRY_PNPBIOS_TS1] =3D GDT_ENTRY_INIT(0x0092, 0, 0), - /* 16-bit data */ [GDT_ENTRY_PNPBIOS_TS2] =3D GDT_ENTRY_INIT(0x0092, 0, 0), /* * The APM segments have byte granularity and their bases * are set at run time. All have 64k limits. */ - /* 32-bit code */ [GDT_ENTRY_APMBIOS_BASE] =3D GDT_ENTRY_INIT(0x409a, 0, 0xffff), - /* 16-bit code */ [GDT_ENTRY_APMBIOS_BASE+1] =3D GDT_ENTRY_INIT(0x009a, 0, 0xffff), - /* data */ [GDT_ENTRY_APMBIOS_BASE+2] =3D GDT_ENTRY_INIT(0x4092, 0, 0xffff), =20 [GDT_ENTRY_ESPFIX_SS] =3D GDT_ENTRY_INIT(0xc092, 0, 0xfffff), diff --git a/arch/x86/platform/pvh/head.S b/arch/x86/platform/pvh/head.S index c4365a05ab83..9bcafdded2a1 100644 --- a/arch/x86/platform/pvh/head.S +++ b/arch/x86/platform/pvh/head.S @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include diff --git a/arch/x86/realmode/rm/reboot.S b/arch/x86/realmode/rm/reboot.S index f10515b10e0a..447641820a8d 100644 --- a/arch/x86/realmode/rm/reboot.S +++ b/arch/x86/realmode/rm/reboot.S @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0 */ #include +#include #include #include #include --=20 2.34.1