Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1702969ybh; Tue, 14 Jul 2020 05:15:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzj7we/tAAVy6BXmsEESEeL7u871gXxxRewPuQa0HF3kZrEdf8QEI4PyZxc3VTz/n2WzcBz X-Received: by 2002:a17:906:d8db:: with SMTP id re27mr4123055ejb.554.1594728933355; Tue, 14 Jul 2020 05:15:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594728933; cv=none; d=google.com; s=arc-20160816; b=s5FWJ272KQ4894TMV58wJ1hAPG6LPrYorSUbAS5S6GOfTQmqcHrm7kZJP5ZpG8gRfy r5n2P7so5aCDOrLf0knxSMyBHlT+p62lqWrdNw0NL8kZucL7gZ5wxmGwn4t2xILjPp0u bTEF7c75ydPdA7/cNlvQsy1e7WTwdb9YmCnGJ9UXB5xYTTm7A07uUf39Y5120WIxF1lA PhDxWUzFZ6jrwleZuA9OI+fI6i3NwulcoC1wPQTbo6e8IcdkPqAFE3JZNuqmAHwlWVZa BC51CToi4zrGaeBaqEIBqrsURqWIhE2HPc5Wp6matV5ogEP8DpeM8Avf4+7eR36fwhe+ oXdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=cCkSRl/WcjaDX2Xr4W/pHnIOxzvqVk+uJgdkDhEQ3iE=; b=Lois+l1lEdcfiwd2jwGUFuqXhj6uMG1XlEBsgl1Qvj1GSt6kOga9dNQsp9CDo/2eoy H8hkLCmFdk7agjlvIEM7xb1vX+OoQ+mZu02PZuTyvLajORTIX2uiejvsXIwj5Os+y7F+ BIhAIYhZc+GGgd2HALMm1lPPLzYX9YgqffMbD3A3FNyYmEMt6cXr2nPYUz4wR4XTjkoQ KVw5/ihPLhFMdJAFvXI3NQiy828T+A9Hly6182AvehUyg4nfvH87tV1o/QnqUHyOKItX g0zCrUIK0YyN4w7s9EpcHOgCYGoxlUDhTcZXoE1vsxMys8XHE91e3sW6YRlRrc/wcuwc 9FCg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k19si11271147ejk.27.2020.07.14.05.15.07; Tue, 14 Jul 2020 05:15:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728737AbgGNMMC (ORCPT + 99 others); Tue, 14 Jul 2020 08:12:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728595AbgGNMLU (ORCPT ); Tue, 14 Jul 2020 08:11:20 -0400 Received: from theia.8bytes.org (8bytes.org [IPv6:2a01:238:4383:600:38bc:a715:4b6d:a889]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EA51C061794; Tue, 14 Jul 2020 05:11:20 -0700 (PDT) Received: from cap.home.8bytes.org (p5b006776.dip0.t-ipconnect.de [91.0.103.118]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by theia.8bytes.org (Postfix) with ESMTPSA id 3BFD8FEA; Tue, 14 Jul 2020 14:11:11 +0200 (CEST) From: Joerg Roedel To: x86@kernel.org Cc: Joerg Roedel , Joerg Roedel , hpa@zytor.com, Andy Lutomirski , Dave Hansen , Peter Zijlstra , Jiri Slaby , Dan Williams , Tom Lendacky , Juergen Gross , Kees Cook , David Rientjes , Cfir Cohen , Erdem Aktas , Masami Hiramatsu , Mike Stunes , Sean Christopherson , Martin Radev , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH v4 69/75] x86/head/64: Setup TSS early for secondary CPUs Date: Tue, 14 Jul 2020 14:09:11 +0200 Message-Id: <20200714120917.11253-70-joro@8bytes.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200714120917.11253-1-joro@8bytes.org> References: <20200714120917.11253-1-joro@8bytes.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joerg Roedel The #VC exception will trigger very early in head_64.S, when the first CPUID instruction is executed. When secondary CPUs boot, they already load the real system IDT, which has the #VC handler configured to use an IST stack. IST stacks require a TSS to be loaded, so set up the TSS early for bringing up the secondary CPUs. Use the read-write version of the per-CPU TSS struct early, until cpu_init() switches to the read-only mapping. On the boot CPU the TSS will also be loaded early, but not used as the the early boot #VC handlers do not use IST stacks. Signed-off-by: Joerg Roedel --- arch/x86/kernel/head64.c | 13 +++++++++++++ arch/x86/kernel/head_64.S | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c index 23d492091f3b..f57eefb1e4ba 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c @@ -545,6 +545,19 @@ void __head early_idt_setup_early_handler(unsigned long descr_addr, unsigned lon } } +void __head early_load_tss(void) +{ + struct desc_struct *gdt = (struct desc_struct *)boot_gdt; + struct tss_struct *tss = this_cpu_ptr(&cpu_tss_rw); + tss_desc tss_desc; + + set_tssldt_descriptor(&tss_desc, (unsigned long)tss, DESC_TSS, + __KERNEL_TSS_LIMIT); + native_write_gdt_entry(gdt, GDT_ENTRY_TSS, &tss_desc, DESC_TSS); + + asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8)); +} + #ifdef CONFIG_AMD_MEM_ENCRYPT static void __head set_early_idt_handler(gate_desc *idt, int n, void *handler) { diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S index 3bd4c36d1d36..5b577d6bce7a 100644 --- a/arch/x86/kernel/head_64.S +++ b/arch/x86/kernel/head_64.S @@ -235,6 +235,11 @@ SYM_CODE_START(secondary_startup_64) */ movq initial_stack(%rip), %rsp + /* Setup a TSS for early IST handlers - needs %gs to be set up */ + pushq %rsi + call early_load_tss + popq %rsi + /* Load IDT */ lidt idt_descr(%rip) -- 2.27.0