Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp3807874pxy; Tue, 4 May 2021 10:19:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5p7o07usLbGNeMVBXe1pgSeN9ZJjOGvwX1iKJeekdZ6XSFIqblJ2+pQPbmFBOKfa1uYlB X-Received: by 2002:a17:902:ec87:b029:ee:910d:acf5 with SMTP id x7-20020a170902ec87b02900ee910dacf5mr26901885plg.66.1620148787807; Tue, 04 May 2021 10:19:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620148787; cv=none; d=google.com; s=arc-20160816; b=wIz0l75ENZJ6yoD6hXfwo1aeViea7tf4lKf+i+XNCh4Iu3ETeS7OKZH9i5WVpNhn1v xp24ezRc7coH+PpZDWwQepE34Dq395kt+EB1voBCfVWGcp5fYIdOZ8BFq3NuxJC8udAR dAqu+7DBCwvAC8jxXNWegC56rsM8XoY/+k17K2avNRAMN9b7oABC5CKXkq9dT7I+EIHO 4bSfY8ji8ZlqNi3mDvLZRm2t9JNkPUkUrxwkY+n5nyB25nGeLV9BOvdK0d/GXxCDRT4m ADmQO9sbhUss1mcKh1JMmrs2JVT4nmaJKEgaBRWFKKKvk2tadtqoQ/4a056vRKj4N2O5 5gDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=faOl1enp2RXY/vCNHMiZNrvMY4eODQWN39NdXIdQhhM=; b=dGjibB5X5RPlW5HNxHQYuM3jLxdIKzYk398bMbANB0R9nCfBjZMEXPivlTd+KKN9QF lUOKJyhOhRXZVEvXMKLW5wWoiZ/2cadK7SNRyIXABmSmsSIxHITKfeOSzSuBVY1rI6K5 7KmA2RkkxDXCkplTKidVVpDVVPdEtECWWYts1AWeGlORg/opPTbNwH/gzhYssFPDmwEs o9x88snmE/C8f4KN8s0ezzz6RMoU4rssa74KCA4WNiWmlxjBybv5SZWb1ZjTpLpVVy0U 2xJYikmpMOigPkmlb/T3D3hvd5csy4zuzO8sUOO2cXGh27TWQbF4ixh5TRfvLPhrahHo W2oA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b="PP6gw/4/"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k1si3981047pgq.470.2021.05.04.10.19.35; Tue, 04 May 2021 10:19:47 -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; dkim=pass header.i=@alien8.de header.s=dkim header.b="PP6gw/4/"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232171AbhEDRTC (ORCPT + 99 others); Tue, 4 May 2021 13:19:02 -0400 Received: from mail.skyhub.de ([5.9.137.197]:37362 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232101AbhEDRSr (ORCPT ); Tue, 4 May 2021 13:18:47 -0400 Received: from zn.tnic (p200300ec2f0c8400434730836ea897d2.dip0.t-ipconnect.de [IPv6:2003:ec:2f0c:8400:4347:3083:6ea8:97d2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id A37791EC0598; Tue, 4 May 2021 19:17:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1620148670; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=faOl1enp2RXY/vCNHMiZNrvMY4eODQWN39NdXIdQhhM=; b=PP6gw/4/Je0ez7PryntJth4RB4SQFcNS/2yFVyuFCg3aSRcH5PB3ahn5drriYwZATkgaKd DlUzzo5CtlYNJdcj74N98RYvFvBkMVM1yUl3km0495GwyQAkWAIHEniu+JeWNcqygDjhYK AIP2Tn1oRACoAfeN3YsY7cx9R5S0LvA= From: Borislav Petkov To: X86 ML Cc: Joerg Roedel , LKML Subject: [PATCH] x86/cpu: Init exception handling from cpu_init() Date: Tue, 4 May 2021 19:17:45 +0200 Message-Id: <20210504171745.2249-1-bp@alien8.de> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Borislav Petkov SEV-ES guests require properly setup task register with which the TSS descriptor in the GDT can be located so that the IST-type #VC exception handler which they need to function properly, can be executed. This setup needs to happen before attempting to load microcode in ucode_cpu_init() which can cause such #VC exceptions. Simplify the machinery by running that exception setup from cpu_init() directly. There should be no functional changes resulting from this patch. Signed-off-by: Borislav Petkov --- arch/x86/include/asm/processor.h | 1 - arch/x86/kernel/cpu/common.c | 14 +++----------- arch/x86/kernel/smpboot.c | 1 - 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h index 154321d29050..50059c988167 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -663,7 +663,6 @@ 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 6bdb69a9a7dc..1aa20b5e4e66 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1917,7 +1917,7 @@ static inline void tss_setup_io_bitmap(struct tss_struct *tss) * Setup everything needed to handle exceptions from the IDT, including the IST * exceptions which use paranoid_entry(). */ -void cpu_init_exception_handling(void) +static void init_exception_handling(void) { struct tss_struct *tss = this_cpu_ptr(&cpu_tss_rw); int cpu = raw_smp_processor_id(); @@ -1944,10 +1944,11 @@ void cpu_init_exception_handling(void) */ void cpu_init(void) { - struct tss_struct *tss = this_cpu_ptr(&cpu_tss_rw); struct task_struct *cur = current; int cpu = raw_smp_processor_id(); + init_exception_handling(); + wait_for_master_cpu(cpu); ucode_cpu_init(cpu); @@ -1957,8 +1958,6 @@ void cpu_init(void) early_cpu_to_node(cpu) != NUMA_NO_NODE) set_numa_node(early_cpu_to_node(cpu)); #endif - setup_getcpu(cpu); - pr_debug("Initializing CPU#%d\n", cpu); if (IS_ENABLED(CONFIG_X86_64) || cpu_feature_enabled(X86_FEATURE_VME) || @@ -1970,7 +1969,6 @@ void cpu_init(void) * and set up the GDT descriptor: */ switch_to_new_gdt(cpu); - load_current_idt(); if (IS_ENABLED(CONFIG_X86_64)) { loadsegment(fs, 0); @@ -1990,12 +1988,6 @@ void cpu_init(void) initialize_tlbstate_and_flush(); enter_lazy_tlb(&init_mm, cur); - /* Initialize the TSS. */ - tss_setup_ist(tss); - tss_setup_io_bitmap(tss); - set_tss_desc(cpu, &get_cpu_entry_area(cpu)->tss.x86_tss); - - load_TR_desc(); /* * sp0 points to the entry trampoline stack regardless of what task * is running. diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index 7ffb0cf3f997..5e5899d046e4 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -232,7 +232,6 @@ static void notrace start_secondary(void *unused) load_cr3(swapper_pg_dir); __flush_tlb_all(); #endif - cpu_init_exception_handling(); cpu_init(); rcu_cpu_starting(raw_smp_processor_id()); x86_cpuinit.early_percpu_clock_init(); -- 2.29.2