From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from SMTP.CITRIX.COM (smtp.citrix.com [66.165.176.89]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 7F93980373 for ; Thu, 9 Mar 2017 03:52:39 -0800 (PST) X-IronPort-AV: E=Sophos;i="5.36,268,1486425600"; d="scan'208";a="412633183" Date: Thu, 9 Mar 2017 11:52:37 +0000 From: Anthony PERARD To: Jiewen Yao CC: , Michael Kinney , Jeff Fan Message-ID: <20170309115237.GK1760@perard.uk.xensource.com> References: <1487660229-4820-1-git-send-email-jiewen.yao@intel.com> <1487660229-4820-2-git-send-email-jiewen.yao@intel.com> MIME-Version: 1.0 In-Reply-To: <1487660229-4820-2-git-send-email-jiewen.yao@intel.com> User-Agent: Mutt/1.8.0 (2017-02-23) Subject: Re: [PATCH V4 1/3] UefiCpuPkg/CpuDxe: Add memory attribute setting. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Mar 2017 11:52:40 -0000 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline On Tue, Feb 21, 2017 at 02:57:07PM +0800, Jiewen Yao wrote: > Add memory attribute setting in CpuArch protocol. > Previous SetMemoryAttributes() API only supports cache attribute setting. > > This patch updated SetMemoryAttributes() API to support memory attribute > setting by updating CPU page table. > > Cc: Jeff Fan > Cc: Michael Kinney > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Jiewen Yao Hi, This patch doesn't work on AMD (when running OVMF on Xen). With an AMD cpu, reading MSR 0x1a0 cause a General Protection Fault. > + AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL); > + if (RegEax > 0x80000000) { > + AsmCpuid (0x80000001, NULL, NULL, NULL, &RegEdx); > + if ((RegEdx & BIT20) != 0) { > + // XD supported This next read is where the fault is taken. > + if ((AsmReadMsr64 (0x000001A0) & BIT34) == 0) { > + // XD enabled > + if ((AsmReadMsr64 (0xC0000080) & BIT11) != 0) { > + // XD activated > + PagingContext->ContextData.Ia32.Attributes |= PAGE_TABLE_LIB_PAGING_CONTEXT_IA32_X64_ATTRIBUTES_XD_ACTIVATED; > + } > + } > + } >>From OVMF output: !!!! X64 Exception Type - 0D(#GP - General Protection) CPU Apic ID - 00000000 !!!! RIP - 000000002F323ABE, CS - 0000000000000018, RFLAGS - 0000000000010002 ExceptionData - 0000000000000000 RAX - 0000000080000001, RCX - 00000000000001A0, RDX - 000000002FD3FBFF RBX - 000000002F422CB8, RSP - 000000002F422C68, RBP - 000000002EE0AD98 RSI - 000000002F3AF018, RDI - 000000002F3229E4 R8 - 0000000000000000, R9 - 0000000000000000, R10 - 0000000000000000 R11 - 000000002F422BAD, R12 - 0000000000000000, R13 - 0000000000000000 R14 - 0000000000000000, R15 - 000000002F44A980 DS - 0000000000000008, ES - 0000000000000008, FS - 0000000000000008 GS - 0000000000000008, SS - 0000000000000008 CR0 - 00000000C0010033, CR2 - 0000000000000000, CR3 - 000000002F3C1000 CR4 - 0000000000000668, CR8 - 0000000000000000 DR0 - 0000000000000000, DR1 - 0000000000000000, DR2 - 0000000000000000 DR3 - 0000000000000000, DR6 - 00000000FFFF0FF0, DR7 - 0000000000000400 GDTR - 00000000FFFFFF80 000000000000001F, LDTR - 0000000000000000 IDTR - 000000002B68DD90 000000000000021F, TR - 0000000000000000 FXSAVE_STATE - 000000002F4228C0 !!!! Find PE image /home/osstest/build.106538.build-amd64/xen/tools/firmware/ovmf-dir-remote/Build/OvmfX64/DEBUG_GCC49/X64/UefiCpuPkg/CpuDxe/CpuDxe/DEBUG/CpuDxe.dll (ImageBase=000000002F321000, EntryPoint=000000002F321271) !!!! Thanks, -- Anthony PERARD