Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4049579imm; Tue, 25 Sep 2018 10:27:14 -0700 (PDT) X-Google-Smtp-Source: ACcGV61/xBXv4oxNL2Zzmr7GxwwwllqOPE2HiBcuumJ/Z6oy9PyJAC6XVVNK2gyigJrkJmycB0mz X-Received: by 2002:a63:f414:: with SMTP id g20-v6mr1947745pgi.407.1537896434834; Tue, 25 Sep 2018 10:27:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537896434; cv=none; d=google.com; s=arc-20160816; b=JqzreGam1hjANexBoqEK66SupKZT/AlOtqizu4KmgRu7qcgSJqhcSGuWIK4yRpd4dH liutSdrfQFWfTIosAKqnQxgPf//kod/Zx1iQ0ChNMtop1sRX9Mfp+1rwyEv6iXoNv3JZ Guacj1490ckxhbs+TY6U5dEmf5/Y2GW5evJxMr6xRNk+CogQIVm0HNDNHla1tFD1Cm4U uKQVtlohYx/oQ5+peN1SCsvVBenYH2byoSFofqPTsCM80umHjWywHT4tdVq0j76qAM75 S2vPgAXTCUrEtuA8qP4E8AVZIgIZV421I1NLu/0zolN8QIpM3vkg5w+04+PqZHMhbLks Onew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=Nh6hWzSt45ofbOmEaddzgdQ+YLQ5h3aU0w1RUuPpHgs=; b=jl5Fq5lDjQUeOl4qpKq/iIqQN5KqSgKKZ/aCJeFbZbeCBL6cfzdaLFp0pTmaXFb4F8 qFOBYvWjaX+XcDTNCJ40Mt6ZmCy6gKT0g/ph+10ZFhu2SsUWwFvz6KOvMa9wSGcVlIam 8U17+2Tmu2NdKKjvNYTW0OBmK44oYMbzLTthd5tdWwGo0Lt9/eno4qDhMaUAE1iVPS+k KSv+Q0citLhk5waR1g5/xJm0GA7wltFYCSnx7Dh9lVMiHRL/LUCQKRbk7gGlZoEzqUeK 86Ev+eOunJH+8YPxYSchdwCMStKHSMeJR5fgvC8ovYSKZjYNOc8iIa3jGOcWoMaaM0fx 04Dg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v13-v6si44575plo.182.2018.09.25.10.26.59; Tue, 25 Sep 2018 10:27:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727602AbeIYXeh (ORCPT + 99 others); Tue, 25 Sep 2018 19:34:37 -0400 Received: from mx2.suse.de ([195.135.220.15]:32816 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726456AbeIYXeh (ORCPT ); Tue, 25 Sep 2018 19:34:37 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 9F47EACD1; Tue, 25 Sep 2018 17:26:05 +0000 (UTC) Date: Tue, 25 Sep 2018 19:26:08 +0200 From: Borislav Petkov To: "Lendacky, Thomas" , Kairui Song Cc: "linux-kernel@vger.kernel.org" , "tglx@linutronix.de" , "mingo@redhat.com" , "hpa@zytor.com" , "x86@kernel.org" , "Singh, Brijesh" , "kexec@lists.infradead.org" , "dyoung@redhat.com" Subject: Re: [PATCH] x86/boot: Fix kexec booting failure after SEV early boot support Message-ID: <20180925172608.GB15464@zn.tnic> References: <20180925111020.23834-1-kasong@redhat.com> <6e15796e-31e9-2dc6-4a31-5c1b01554b45@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <6e15796e-31e9-2dc6-4a31-5c1b01554b45@amd.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 25, 2018 at 02:33:48PM +0000, Lendacky, Thomas wrote: > On 09/25/2018 06:10 AM, Kairui Song wrote: > > Commit 1958b5fc4010 ("x86/boot: Add early boot support when running > > with SEV active") is causing kexec becomes sometimes unstable, kexec > > reboot won't start a second kernel bypassing BIOS boot process, instead, > > the system got reset. > > > > That's because, in get_sev_encryption_bit function, we are using > > 32-bit RIP-relative addressing to read the value of enc_bit, but > > kexec may alloc the early boot up code to a higher location, which > > is beyond 32-bit addressing limit. Some garbage will be read and > > get_sev_encryption_bit will return the wrong value, which lead to > > wrong memory page flag. > > > > This patch adds a get_sev_encryption_bit_64 function to avoid this > > problem. 64-bit early boot code will use this function instead, it > > uses native RIP addressing to read the enc_bit which have no problem > > with any location. > > > > Fixes: 1958b5fc4010 ("x86/boot: Add early boot support when running with SEV active") > > Signed-off-by: Kairui Song > > Reviewed-by: Tom Lendacky > > > --- > > arch/x86/boot/compressed/mem_encrypt.S | 64 ++++++++++++++++++-------- > > 1 file changed, 45 insertions(+), 19 deletions(-) > > > > diff --git a/arch/x86/boot/compressed/mem_encrypt.S b/arch/x86/boot/compressed/mem_encrypt.S > > index eaa843a52907..41933550449a 100644 > > --- a/arch/x86/boot/compressed/mem_encrypt.S > > +++ b/arch/x86/boot/compressed/mem_encrypt.S > > @@ -18,27 +18,13 @@ > > > > .text > > .code32 > > -ENTRY(get_sev_encryption_bit) > > +do_get_sev_encryption_bit: > > xor %eax, %eax > > > > #ifdef CONFIG_AMD_MEM_ENCRYPT > > push %ebx > > push %ecx > > push %edx > > - push %edi > > - > > - /* > > - * RIP-relative addressing is needed to access the encryption bit > > - * variable. Since we are running in 32-bit mode we need this call/pop > > - * sequence to get the proper relative addressing. > > - */ > > - call 1f > > -1: popl %edi > > - subl $1b, %edi > > - > > - movl enc_bit(%edi), %eax > > - cmpl $0, %eax > > - jge .Lsev_exit > > > > /* Check if running under a hypervisor */ > > movl $1, %eax > > @@ -69,25 +55,65 @@ ENTRY(get_sev_encryption_bit) > > > > movl %ebx, %eax > > andl $0x3f, %eax /* Return the encryption bit location */ > > - movl %eax, enc_bit(%edi) IINM, the problem can be addressed in a simpler way by getting rid of enc_bit and thus getting rid of the need to do relative addressing of anything and simply doing the whole dance of figuring out the C-bit each time. It probably wouldn't be even measurable... -- Regards/Gruss, Boris. SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg) --