Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3358324pxk; Mon, 7 Sep 2020 10:32:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyAiBFwjsVlXOJD1z7j8Fw/zWCmI9Fd/bFWg2jOk7VVqg34/T/LAXO4iRL2N6ejSzG7AYh1 X-Received: by 2002:a17:906:b881:: with SMTP id hb1mr21701450ejb.207.1599499975435; Mon, 07 Sep 2020 10:32:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599499975; cv=none; d=google.com; s=arc-20160816; b=AkYhHjqsmDp/UY5CY1fwl4k5VACyXNtOAQQJ3DhprRN9l5jMTomW1zPAhKpIqQzuEf NyiO/8hEN4C9vADUcHo9Q9I8Bi1k12YbEUUjQqF6lWFC5jz84kxkFjfJzzm+MZ/ty4dA qIEG0k7vreDcLNVKfwKQMHsU7G8F9jq2fb6CDY7Ayrb7Zzps1ggN9Sr+rj2JogsSDizi D76zRqWhPIFff7MPSh0SR5q8u83JhDuX2FvkgkeZ/CoX90549QyFU9wK9giZsMT7nzrS H9eJHMbaOS9CjW8ahBdLGG2t9517v01hFD+1jyqy307FG6YehGomQ7/etdKy1Qkf9o6w veuw== 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=qX2qpI1EOzsJX8w0T2dqXgYiXQokxCmggZeyijcnNSI=; b=e/3FTAE+zQwJgKgkrTV72b2nkO7jISgdr46lSzAfeZrizX6CMDy27rZVgT2c2sUom/ D0iJE+yfYLNkybkjdQ+vZ0hlsxW0qUiCw67mCTppU9/pYlFv+d9D9d1rAtrz993Kv5L2 036MPtW66Pw6g6otiTZZwH76LSVpkDcaRB2/4llcSgmfZJd4ns4OhuuxPeW56539XSVv 0BzGDL26kgIYUczoD7PeVas20MWfY2KSuvoWMpUs5xQS8LT9Xkf/6gP652wC0CIu3jMj Jz3vAT70s79WEShWVceclgQFmnAYfbT03tHw9QBl6TDDOXvwzrtrPaxWdHDwm9VEdX1a RLtg== 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 i11si10648156edl.230.2020.09.07.10.32.33; Mon, 07 Sep 2020 10:32:55 -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 S1730585AbgIGR1r (ORCPT + 99 others); Mon, 7 Sep 2020 13:27:47 -0400 Received: from 8bytes.org ([81.169.241.247]:43658 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729526AbgIGNTh (ORCPT ); Mon, 7 Sep 2020 09:19:37 -0400 Received: from cap.home.8bytes.org (p549add56.dip0.t-ipconnect.de [84.154.221.86]) (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 C630B3AAA; Mon, 7 Sep 2020 15:17:17 +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 v7 67/72] x86/smpboot: Load TSS and getcpu GDT entry before loading IDT Date: Mon, 7 Sep 2020 15:16:08 +0200 Message-Id: <20200907131613.12703-68-joro@8bytes.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200907131613.12703-1-joro@8bytes.org> References: <20200907131613.12703-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 IDT on 64bit contains vectors which use paranoid_entry() and/or IST stacks. To make these vectors work the TSS and the getcpu GDT entry need to be set up before the IDT is loaded. Signed-off-by: Joerg Roedel --- arch/x86/include/asm/processor.h | 1 + arch/x86/kernel/cpu/common.c | 23 +++++++++++++++++++++++ arch/x86/kernel/smpboot.c | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h index d8a82e650810..5ac507586769 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -696,6 +696,7 @@ extern void load_direct_gdt(int); extern void load_fixmap_gdt(int); extern void load_percpu_segment(int); extern void cpu_init(void); +extern void cpu_init_exception_handling(void); extern void cr4_init(void); static inline unsigned long get_debugctlmsr(void) diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 1d65365363a1..a9527c0c38fb 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1854,6 +1854,29 @@ static inline void tss_setup_io_bitmap(struct tss_struct *tss) #endif } +/* + * Setup everything needed to handle exceptions from the IDT, including the IST + * exceptions which use paranoid_entry() + */ +void cpu_init_exception_handling(void) +{ + struct tss_struct *tss = this_cpu_ptr(&cpu_tss_rw); + int cpu = raw_smp_processor_id(); + + /* paranoid_entry() gets the CPU number from the GDT */ + setup_getcpu(cpu); + + /* IST vectors need TSS to be set up. */ + tss_setup_ist(tss); + tss_setup_io_bitmap(tss); + set_tss_desc(cpu, &get_cpu_entry_area(cpu)->tss.x86_tss); + + load_TR_desc(); + + /* Finally load the IDT */ + load_current_idt(); +} + /* * cpu_init() initializes state that is per-CPU. Some data is already * initialized (naturally) in the bootstrap process, such as the GDT diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index f5ef689dd62a..de776b2e6046 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -227,7 +227,7 @@ static void notrace start_secondary(void *unused) load_cr3(swapper_pg_dir); __flush_tlb_all(); #endif - load_current_idt(); + cpu_init_exception_handling(); cpu_init(); x86_cpuinit.early_percpu_clock_init(); preempt_disable(); -- 2.28.0