Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1704249ybh; Tue, 14 Jul 2020 05:17:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJCKyXQjV2J27bO4gUpoJRl9vG6ehykhCer6spKG/jA3t/5bFgqheHYMYRKRHX8MXCwcfR X-Received: by 2002:a05:6402:1c11:: with SMTP id ck17mr4023444edb.38.1594729050338; Tue, 14 Jul 2020 05:17:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594729050; cv=none; d=google.com; s=arc-20160816; b=zPkuysUZXnDKrLxhEqGODoyvITBcCsoS5nB/8pLtaXp9kPXvP8ft2xeaHDg7myuwsm VVa5hq8elVurR3Y/nOBUzAuMeSAz9nNv6SuSi5Mo5t0an2w4/3phYqOdnqKfshHNwkF5 L45ZNvK1MlV91ZkoivhKHT4OAcpHj5b4YHUJiFc9YCQUZKC3czRCqYtagGaqraE9ZXAw Imh8kXSas1gHr6aPy3rX8fRgLdygSLpfPcakHhmLxgHyKolfKN/8y82gGeg8UACCPkdV T4l1w/mFc+zx9J9q/emYzisB1+JAPhfHOGmTS19duD7EJmvWWkbu6PNekDR9m0uDaCsa u/NA== 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=oQp+bQmRpEjyjkNEEyPl0u7aytnStvEpxUE3mIvGSqs=; b=hrjTF53HP6s56X60SGMSLjO2T8WNCKZdHuyEkrxXeBv8IXUWExssgJvxX6c5rVFj/I oO24Vpiche6dgkERGjssb5WgLFjrcb3PlNRwmxMngYQ1VkagsiQMM7bU11sLX705MNvs 32JYVonWRckz7gDCFlrln4YdqSeKbRHxYLYDHx0wmgGfizS8ppoF0v8SrjqBm1VzTrDW g1bzuwSc4I1H8gtoSAZxqcbrX0zIZAtRKaz65YH/M5zEyhqPcYOHyXKAaAxwuEI08AcH Bq0TI4LWqlpmErY5nwWI9/5ionkxXIGzWFNN68IemtsE/DBaVhfzjRCtnz1t5dXVSMKg AZOg== 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 j13si10519517eds.407.2020.07.14.05.17.06; Tue, 14 Jul 2020 05:17:30 -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 S1728977AbgGNMPg (ORCPT + 99 others); Tue, 14 Jul 2020 08:15:36 -0400 Received: from 8bytes.org ([81.169.241.247]:52918 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728304AbgGNMKx (ORCPT ); Tue, 14 Jul 2020 08:10:53 -0400 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 25E2EE1F; Tue, 14 Jul 2020 14:10:50 +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 32/75] x86/head/64: Load segment registers earlier Date: Tue, 14 Jul 2020 14:08:34 +0200 Message-Id: <20200714120917.11253-33-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 Make sure segments are properly set up before setting up an IDT and doing anything that might cause a #VC exception. This is later needed for early exception handling. Signed-off-by: Joerg Roedel --- arch/x86/kernel/head_64.S | 52 +++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S index 87ea9f540608..61aa1e56fc9c 100644 --- a/arch/x86/kernel/head_64.S +++ b/arch/x86/kernel/head_64.S @@ -169,6 +169,32 @@ SYM_CODE_START(secondary_startup_64) movq %rax, boot_gdt_descr+2(%rip) lgdt boot_gdt_descr(%rip) + /* set up data segments */ + xorl %eax,%eax + movl %eax,%ds + movl %eax,%ss + movl %eax,%es + + /* + * We don't really need to load %fs or %gs, but load them anyway + * to kill any stale realmode selectors. This allows execution + * under VT hardware. + */ + movl %eax,%fs + movl %eax,%gs + + /* Set up %gs. + * + * The base of %gs always points to fixed_percpu_data. If the + * stack protector canary is enabled, it is located at %gs:40. + * Note that, on SMP, the boot cpu uses init data section until + * the per cpu areas are set up. + */ + movl $MSR_GS_BASE,%ecx + movl initial_gs(%rip),%eax + movl initial_gs+4(%rip),%edx + wrmsr + /* Check if nx is implemented */ movl $0x80000001, %eax cpuid @@ -204,32 +230,6 @@ SYM_CODE_START(secondary_startup_64) */ lgdt early_gdt_descr(%rip) - /* set up data segments */ - xorl %eax,%eax - movl %eax,%ds - movl %eax,%ss - movl %eax,%es - - /* - * We don't really need to load %fs or %gs, but load them anyway - * to kill any stale realmode selectors. This allows execution - * under VT hardware. - */ - movl %eax,%fs - movl %eax,%gs - - /* Set up %gs. - * - * The base of %gs always points to fixed_percpu_data. If the - * stack protector canary is enabled, it is located at %gs:40. - * Note that, on SMP, the boot cpu uses init data section until - * the per cpu areas are set up. - */ - movl $MSR_GS_BASE,%ecx - movl initial_gs(%rip),%eax - movl initial_gs+4(%rip),%edx - wrmsr - /* rsi is pointer to real mode structure with interesting info. pass it to C */ movq %rsi, %rdi -- 2.27.0