From patchwork Thu Feb 22 18:23:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Gerst X-Patchwork-Id: 204990 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp133980dyb; Thu, 22 Feb 2024 10:36:28 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWjebNsNr2IChArcDPhGhCi6FQNxn2626mSEx9LgJHpfAuz+iUpkL/Hkf3Xqg+5/m/f0mA6OGSPc42u2fLpwn/PeXVfzQ== X-Google-Smtp-Source: AGHT+IGgll3BknPUVqS6D6/0/A/lU+KpnUxeSrkJs37OPbjowruaTsiLJOFgayfJ3+JuAuzYOpN8 X-Received: by 2002:a17:906:84c:b0:a3e:52d2:b63a with SMTP id f12-20020a170906084c00b00a3e52d2b63amr9367157ejd.65.1708626988374; Thu, 22 Feb 2024 10:36:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708626988; cv=pass; d=google.com; s=arc-20160816; b=HztrKhX7KaHOU/KiXULF46eZyEVJrknpFqvmZYv1RU0Iv6u8zlkoMvx0qYxMAOyJYM QAMBzDYOx/w/VjR9k1wMRxVgrrhqDnUESYAqyTFGjKQRAbBVSjVl6gu9zDJSU4PdRqSg UeqN/ICfdAK/HvAngba/eWQmHKui/Br83kT+fkGEbdHmodx2p6ujKmk95U0w6BSmWyT5 vk7WDo/jd7SZZ3CPsJV+MOchg7y1OLsi0SAIy6PPJiaW2jX+ZkKbkiLfiYIKlZHDFSVf Q4DCklBZVvPtBT+Z/iYY1dsYfF5e/qcznEKwRHyQVY4G86gI6NwMzWh/dOi2/BPc/IA6 4IJQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=e7tNy5a20yjAdBWrxhg+cmTPuB6N559ig/Ixy5c9u2c=; fh=vwdQUKS3nNaq1WCA7s3Ch2OClKyb6ikG3TRiHx5kZCQ=; b=n73GKAiuAS7oHaFC91Z+eej2IZkDTDsNa22amLMCj4Ntjlq9WlHnLS22XQF+e6PJKG KAv1E6UUmd30KPq54D6AvNQm7ytYDwStccQR5xzppf/fKBJ1LZV9eXPA3K3RcFJHtMiW taTVsq2aO5/0VuNXtYzCwSu6bQu/+w3ZqWghgs6nx0yD+PLl0O6YvI2h/zIGBohLZal1 92U6jNhW/Rozibht72/gUpXwQ/JR0ah8c4V8EJICTZROoVbagG6j5F36Dgz5OiEoQyGX QV5lTWd4A7W7n4MZqNtRCgl4BSJyJ2M2dLiv5gdjmAGdKGdmtwmp595EedcSK15j0ZQ9 BbYw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=c3KMfIw9; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-77132-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77132-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id w13-20020a170906d20d00b00a3d20ec721esi5791402ejz.88.2024.02.22.10.36.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 10:36:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77132-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=c3KMfIw9; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-77132-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77132-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 017491F26D86 for ; Thu, 22 Feb 2024 18:36:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F34506AFB4; Thu, 22 Feb 2024 18:24:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="c3KMfIw9" Received: from mail-qv1-f44.google.com (mail-qv1-f44.google.com [209.85.219.44]) (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 A04375491F for ; Thu, 22 Feb 2024 18:24:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708626254; cv=none; b=i094RGf1i6Sg2NjnrIdi88OGZ6+N0J+EFU/bcX7y1hkQi+VllCyp7Xfk5BAeQB0bAPUDpKPeDZpqXeiQbnNXoIIRPiGBnjyDzcPOYVD5nEquMtYKaxv3vbe+EpmKYV0p+KiOpcTiDnlfyFRynFIc7gT9BnA/Vex3UAWK/Hib9ik= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708626254; c=relaxed/simple; bh=jRj9g/e5y+7mPp797YSNxH82vqmTM40/2K74tJ+n/68=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Ci9hqu/MTUVuk4MWjLLFG4HJj5o5ku5GWBSd85kpMH/Z9veNuvYr7yV1b3vcdyWbUQ7hipqtgmY4r3rRRpOPvT3AkG9Z5wBqBDkugaCNcP+ysRF7Kgpip2j1Q3oaNYgIkBW97Tn6wfjtqN7yjYl9WcH6wEe7cWnvDbyxMF1Zrko= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=c3KMfIw9; arc=none smtp.client-ip=209.85.219.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qv1-f44.google.com with SMTP id 6a1803df08f44-68fb74416ccso444846d6.1 for ; Thu, 22 Feb 2024 10:24:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708626249; x=1709231049; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=e7tNy5a20yjAdBWrxhg+cmTPuB6N559ig/Ixy5c9u2c=; b=c3KMfIw9nGAY3JNyQRsPqo/wyvMGdMDyMcH4BNWir6oQ19l/9N6snxhPoLmo6dhABt jYm+QMd90ppRBrOO+ys+FsqN6uqCQuaSjgBIVptXGwqGZ2LGyNPwJtAAs5kMNA/sRlGd rcCC9nGxcGS/d9ER1yvk4dSj2nLuoORm8RgNjdvtUWcsXoWdnzizyK1I2L9synzkMYca 88CW5986C0hgJrXsBh9nLU4X2pTMd3JRx4t1mAuJ1KKw8bUj2RhdwUeNprWJEYheCMop GRCey/iIpO7mIkHSPfZ8NR4jJd9ZtvkijgoF5x6/H9UQE5IDqpwQL61eWijVd6FjG1WI 47Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708626249; x=1709231049; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=e7tNy5a20yjAdBWrxhg+cmTPuB6N559ig/Ixy5c9u2c=; b=T4NMRXht5osxRZRv9fW3j4lezF8KkN4V12mm7e9Jp+dODVYoJzhix3YTzFWymm26h6 XQScKiXB9ncNX9v7VkbGlglb86CsGSmdZmWqu1sSJghp2almFPxUyW5S7ARNAYP62D8g r1YNJZEkdDEVqvoHsZs5EFVydhAYopvHg283oa5kDDN3+tZOFza4UfEd/v3lVkuLavUI glwWMIYOFUQpqHq8GGXAbn/S1P3Vw+1U2TwHbwqu6y0eleyPJM3gZH8sLX69b6vcY5Ag 46WvB6TaA3+JlX6kLBR1RXgTYvHt0aBN4GFOexOiynNST4Uv+p+RbCluvrIUaOhXwQHI FVjA== X-Gm-Message-State: AOJu0Yw3/rPk8VJ2zFUakAwwtgfyqqJngeMbZRrIosaA/niMU6xXCoWI JUXk69+kAbGLIlge4yAiG1qOcuQ7qw5ezrbdYZh/cse7JnDm9v4plACazb0= X-Received: by 2002:a05:6214:484:b0:68f:1138:8ee3 with SMTP id pt4-20020a056214048400b0068f11388ee3mr27099297qvb.52.1708626249583; Thu, 22 Feb 2024 10:24:09 -0800 (PST) Received: from citadel.lan (2600-6c4a-4d3f-6d5c-0000-0000-0000-1019.inf6.spectrum.com. [2600:6c4a:4d3f:6d5c::1019]) by smtp.gmail.com with ESMTPSA id lh10-20020a05621454ca00b0068fbe6d38f6sm949541qvb.54.2024.02.22.10.24.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 10:24:09 -0800 (PST) From: Brian Gerst To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Ingo Molnar , Thomas Gleixner , Borislav Petkov , "H . Peter Anvin" , Peter Zijlstra , Ard Biesheuvel , Brian Gerst Subject: [PATCH] x86/boot/64: Load kernel GDT in early boot Date: Thu, 22 Feb 2024 13:23:56 -0500 Message-ID: <20240222182356.69549-1-brgerst@gmail.com> X-Mailer: git-send-email 2.43.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791625253007924527 X-GMAIL-MSGID: 1791625253007924527 Instead of loading a duplicate GDT just for early boot, load the kernel GDT from its physical address. Signed-off-by: Brian Gerst --- arch/x86/include/asm/desc.h | 1 + arch/x86/kernel/head64.c | 14 +++----------- 2 files changed, 4 insertions(+), 11 deletions(-) base-commit: c56ac217a3c00d12e23606e0635cc95d6eb8c36a diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h index ec95fe44fa3a..62dc9f59ea76 100644 --- a/arch/x86/include/asm/desc.h +++ b/arch/x86/include/asm/desc.h @@ -46,6 +46,7 @@ struct gdt_page { } __attribute__((aligned(PAGE_SIZE))); DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page); +DECLARE_INIT_PER_CPU(gdt_page); /* Provide the original GDT */ static inline struct desc_struct *get_cpu_gdt_rw(unsigned int cpu) diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c index dc0956067944..09c67e6add62 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c @@ -67,21 +67,12 @@ unsigned long vmemmap_base __ro_after_init = __VMEMMAP_BASE_L4; EXPORT_SYMBOL(vmemmap_base); #endif -/* - * GDT used on the boot CPU before switching to virtual addresses. - */ -static struct desc_struct startup_gdt[GDT_ENTRIES] __initdata = { - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(DESC_CODE32, 0, 0xfffff), - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(DESC_CODE64, 0, 0xfffff), - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(DESC_DATA64, 0, 0xfffff), -}; - /* * Address needs to be set at runtime because it references the startup_gdt * while the kernel still uses a direct mapping. */ static struct desc_ptr startup_gdt_descr __initdata = { - .size = sizeof(startup_gdt)-1, + .size = GDT_SIZE - 1, .address = 0, }; @@ -624,7 +615,8 @@ void early_setup_idt(void) void __head startup_64_setup_env(unsigned long physbase) { /* Load GDT */ - startup_gdt_descr.address = (unsigned long)fixup_pointer(startup_gdt, physbase); + startup_gdt_descr.address = + (unsigned long)fixup_pointer(&init_per_cpu_var(gdt_page.gdt), physbase); native_load_gdt(&startup_gdt_descr); /* New GDT is live - reload data segment registers */