From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bedivere.hansenpartnership.com (bedivere.hansenpartnership.com [96.44.175.130]) by mx.groups.io with SMTP id smtpd.web11.5719.1608004077499082155 for ; Mon, 14 Dec 2020 19:47:57 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@hansenpartnership.com header.s=20151216 header.b=axlydCSO; spf=pass (domain: hansenpartnership.com, ip: 96.44.175.130, mailfrom: james.bottomley@hansenpartnership.com) Received: from localhost (localhost [127.0.0.1]) by bedivere.hansenpartnership.com (Postfix) with ESMTP id 0052612801BC; Mon, 14 Dec 2020 19:47:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=hansenpartnership.com; s=20151216; t=1608004077; bh=HSs8DZUbm57OBwWEOdGbEg+IuSv0ZocMg60FjcYZY7w=; h=Message-ID:Subject:From:To:Date:In-Reply-To:References:From; b=axlydCSO7fEjVxZJkQVSaXfdgJ5YKBO2fm8Xw6iPlWR9z3AtIAIF31Tv1ZZUEaU1G FIvDIgTRaAJxg9IlPPjUfUFH9NNsmwwR2XVaxx0cHLoGjNOURclecPQn6dqrW7yYIf dQ6VbzXKHcLKM6IpmsFoxfbEfHkr1R+jmn54yjCU= Received: from bedivere.hansenpartnership.com ([127.0.0.1]) by localhost (bedivere.hansenpartnership.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wU4ALTD8IugQ; Mon, 14 Dec 2020 19:47:56 -0800 (PST) Received: from jarvis.int.hansenpartnership.com (unknown [IPv6:2601:600:8280:66d1::527]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bedivere.hansenpartnership.com (Postfix) with ESMTPSA id 7B2B112801B7; Mon, 14 Dec 2020 19:47:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=hansenpartnership.com; s=20151216; t=1608004076; bh=HSs8DZUbm57OBwWEOdGbEg+IuSv0ZocMg60FjcYZY7w=; h=Message-ID:Subject:From:To:Date:In-Reply-To:References:From; b=ixZeV3fcKlPvvvj3BTwOaatPXhQQZUm6mKyixNEppJYP0Mesc5RNUQuS+QYtT+q+Q UJVo0C8hsHiYqPIWvhqmbYrVh0sxBTMVzWi1M64XD47Eryc7De5qHnu0NcQIHoleOc EmW1A1vcAQ2Ainzcdu5tCvwZ3iOPlUT0k5126Iic= Message-ID: <9c5f7e74f7c4adca81acaa6a7527484f0387d927.camel@HansenPartnership.com> Subject: Re: [edk2-devel] BUG: OvmfPkgX64 is broken with cee5b0441af3 UefiCpuPkg/CpuDxe: Fix boot error From: "James Bottomley" To: devel@edk2.groups.io Cc: Guo Dong , "Dong, Eric" , "Ni, Ray" , "Kumar, Rahul1" , LaszloErsek Date: Mon, 14 Dec 2020 19:47:54 -0800 In-Reply-To: <58408ffaedfd7f7a1c433ff539b69acb625890dc.camel@HansenPartnership.com> References: <58408ffaedfd7f7a1c433ff539b69acb625890dc.camel@HansenPartnership.com> User-Agent: Evolution 3.34.4 MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit On Mon, 2020-12-14 at 15:51 -0800, James Bottomley wrote: > I found this trying to test out the upstream SEV secret injection on > an > AMD rome system. However, I rebuilt the OvmfPkgX64 (still on a rome > system) just to check. I get a boot loop here if I leave this commit > unreverted: > > InstallProtocolInterface: BC62157E-3E33-4FEC-9920-2D3B36D750DF > 7F1AD918 > ProtectUefiImageCommon - 0x7F1AD2C0 > - 0x000000007F068000 - 0x000000000000FCC0 > Paging: added 512 pages to page table pool > CurrentPagingContext: > MachineType - 0x8664 > PageTableBase - 0x7F801000 > Attributes - 0xC0000006 > SecCoreStartupWithStack(0xFFFCC000, 0x820000) > > If I revert this commit, it will boot up normally. > > The memory specification for qemu-kvm I'm using is > > -m 4096M,slots=5,maxmem=30G > > but reducing it to under 4GB doesn't help I think I found the source of the problem: nasm is generating this assembly sequence (disassembled by objdump): 14: 48 ff 2c 24 rex.W ljmp *(%rsp) However, on AMD the rex.W prefix to a ljmp can be ineffective and the recommended way to do this is with lretq (or retfq in nasm speak). If I apply the patch below, I can get the long word version to work for me on SEV. James --- diff --git a/UefiCpuPkg/CpuDxe/X64/CpuAsm.nasm b/UefiCpuPkg/CpuDxe/X64/CpuAsm.nasm index 6ad32b49f4ef..a2490073cef6 100644 --- a/UefiCpuPkg/CpuDxe/X64/CpuAsm.nasm +++ b/UefiCpuPkg/CpuDxe/X64/CpuAsm.nasm @@ -20,13 +20,11 @@ ;------------------------------------------------------------------------------ global ASM_PFX(SetCodeSelector) ASM_PFX(SetCodeSelector): - sub rsp, 0x10 lea rax, [setCodeSelectorLongJump] - mov [rsp], rax - mov [rsp+8], cx - jmp qword far [rsp] + push rcx + push rax + retfq setCodeSelectorLongJump: - add rsp, 0x10 ret ;------------------------------------------------------------------------------