Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1402622pxj; Sat, 8 May 2021 16:51:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxywkgQO6ryH5EbMhf0ZWkRnFGKwfWVhpKljzZoCUKoL6sQ5jMSN+kYOXNlFdGHn8j8n/9N X-Received: by 2002:a6b:6c18:: with SMTP id a24mr13294080ioh.21.1620517900531; Sat, 08 May 2021 16:51:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620517900; cv=none; d=google.com; s=arc-20160816; b=o27VXiTm0cJAzz12smW6oiiB9JJMzRm2pamZ12/kPN4lktZd+mkOW1g4VUcQw+zCtD FlxQAR2HdXqWGjWxguZ7KQwvVk+Nqan4j7FDAyP+m40LjYZZmHXIWG/LqfJ+V4DDmfvY TJrOBDvH8/dHaHIE3HZMVkiuZnJ75u0iSlDxTvZXnAcyZ6lUGwsZtNLBT2ss5PkETJIW pTTETtpgdKi8AqMngX7zz3KS5r3AyB81PCOopmuRPJZuzHy+gCFlQVGaAofs57glynDV TWA9TCGPAGcS4tqFfa3tTAHIGuEnitawhpEn7YAXwkuP/XBA3LaclJ/FVM9CEoeUXLhC pbJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=ll/zX4z06adUt1RVoQyK9IWYY0WCO++4o9fcEytMR1U=; b=rYLWH0IfcPT7cVQgtolnWmWGKhu9vXFRhvLJPIjSZSecgKA3FvELmoRLkP4zThsOo1 kzWcSNGeTeeE/6B7ygspS43S4I+rtggVdzTuIOw56VzQwZd5XV0qH1kG9asvHnIxYrS0 RW2gjdnefgnOoHocriUVg/bIb+l7QwNwZpXH60c+5zL9t9M0tHMN2aBtO6Ip4dDy3T+z LBXV0pCRlQNLaMZOOnYqFqmN8vFzYwfqekNNm8i8WGt+h8rAVH6+FZZrpxJGRa88jQ7d jsH+23My4ECSsgDTmICVUbz6DirCP1JE6xwDCfQ2mfXG2EwsrI77S9OaEP6GzFixvydB 3DUA== 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=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e5si10486740jaq.6.2021.05.08.16.51.05; Sat, 08 May 2021 16:51:40 -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=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229620AbhEHXlj (ORCPT + 99 others); Sat, 8 May 2021 19:41:39 -0400 Received: from out30-130.freemail.mail.aliyun.com ([115.124.30.130]:34137 "EHLO out30-130.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229601AbhEHXlj (ORCPT ); Sat, 8 May 2021 19:41:39 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R111e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04394;MF=laijs@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0UYBf8LZ_1620517234; Received: from C02XQCBJJG5H.local(mailfrom:laijs@linux.alibaba.com fp:SMTPD_---0UYBf8LZ_1620517234) by smtp.aliyun-inc.com(127.0.0.1); Sun, 09 May 2021 07:40:35 +0800 Subject: Re: [patch 1/2] x86/cpu: Init exception handling from cpu_init_secondary() To: Thomas Gleixner , LKML Cc: x86@kernel.org, Joerg Roedel , Borislav Petkov References: <20210507110210.147106915@linutronix.de> <20210507114000.429303187@linutronix.de> From: Lai Jiangshan Message-ID: Date: Sun, 9 May 2021 07:40:34 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: <20210507114000.429303187@linutronix.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/5/7 19:02, Thomas Gleixner wrote: > 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() on secondary CPUs which can cause such #VC exceptions. > > Simplify the machinery by running that exception setup from a new function > cpu_init_secondary() and explicitly call cpu_init_exception_handling() for > the boot CPU before cpu_init(). The latter prepares for fixing and > simplifying the exception/IST setup on the boot CPU. > > There should be no functional changes resulting from this patch. > > [ tglx: Reworked it so cpu_init_exception_handling() stays separate ] > > Signed-off-by: Borislav Petkov > Signed-off-by: Thomas Gleixner > > --- > arch/x86/include/asm/processor.h | 1 + > arch/x86/kernel/cpu/common.c | 24 +++++++++++------------- > arch/x86/kernel/traps.c | 4 +--- > 3 files changed, 13 insertions(+), 16 deletions(-) > > --- a/arch/x86/include/asm/processor.h > +++ b/arch/x86/include/asm/processor.h > @@ -663,6 +663,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_secondary(void); > extern void cpu_init_exception_handling(void); > extern void cr4_init(void); > > --- a/arch/x86/kernel/cpu/common.c > +++ b/arch/x86/kernel/cpu/common.c > @@ -1938,13 +1938,12 @@ void cpu_init_exception_handling(void) > > /* > * cpu_init() initializes state that is per-CPU. Some data is already > - * initialized (naturally) in the bootstrap process, such as the GDT > - * and IDT. We reload them nevertheless, this function acts as a > - * 'CPU state barrier', nothing should get across. > + * initialized (naturally) in the bootstrap process, such as the GDT. We > + * reload it nevertheless, this function acts as a 'CPU state barrier', > + * nothing should get across. > */ > 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(); > > @@ -1957,8 +1956,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 +1967,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 +1986,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. > @@ -2017,6 +2007,14 @@ void cpu_init(void) > load_fixmap_gdt(cpu); > } > > +#ifdef CONFIG_SMP > +void cpu_init_secondary(void) > +{ > + cpu_init_exception_handling(); > + cpu_init(); > +} > +#endif Hello No code invokes this function in this patch. Forgot to invoke it from start_secondary() or somewhere? Thanks Lai > + > /* > * The microcode loader calls this upon late microcode load to recheck features, > * only when microcode has been updated. Caller holds microcode_mutex and CPU > --- a/arch/x86/kernel/traps.c > +++ b/arch/x86/kernel/traps.c > @@ -1162,9 +1162,7 @@ void __init trap_init(void) > > idt_setup_traps(); > > - /* > - * Should be a barrier for any external CPU state: > - */ > + cpu_init_exception_handling(); > cpu_init(); > > idt_setup_ist_traps(); >