From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.73]) by mx.groups.io with SMTP id smtpd.web10.24048.1671641962451580384 for ; Wed, 21 Dec 2022 08:59:22 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@amd.com header.s=selector1 header.b=icR8M8dO; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: amd.com, ip: 40.107.223.73, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O4KcL9BAF394SJS+FYQAk90fbw9fbqO4l2DTgajYxAI/D3bLhJA4DGc08eqhLIREI90Ems4D+TRnkXs6yUVpWKnxMORHu3XAoFfjPCSZRxXCtJtuGCHuP6eoAuCerh0QvqSi1Jmo9jscCVlib47guHpXpyMXhsesFJAJjJ48U9ZG8bPmbd3R2Nz1zqn5KowNYoDrcA8gAqgE7EbMiJg6GR+4oAgn5xHqm4wAKLYRlBv3r4aYdSp19eHczrofW0wLrSEQgLfj+TjBnmaDLjcEnTvNguVxfD5Vv/QkuY63+KNuPHqcB/hChxViVw9aGgWEFyz1gBKEcKWWOzzbWxCA4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=/YeouebFkcJrmbmhp3HfJFQ52SaSrShxPN13Q9g8Eg4=; b=mZxnMOHhSkLSp5bx6zAkD5IieQXxyrcOnuzRo2GSl5hw/0mD+CMhyjQqE4LIqf6wxoXt1M6msqShMhv5fqjw8BbSLYVrGZI2JG49LBHgv6E0hcySzo/xlIRcLW77jETM6pHFPjStiM1CQlWxfYaMQmpkd0GC/IGvmc1GP8DJtMK1PP8D1hz5qYvwnBlThNTZd3dzIej9gD5U1g8HgmFiu/dMUlULLY42QQoZsuT2KNKZtNJ44p9bkqr69OUgQAlk3m1MTgw+9V3ZgvtskOxnTCKcBS9UYL/zIeyuNmIFQLwmvEwLH/hovBdD3LQicSe2QGKetUbFe/Jy4n2Hv7YXpg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/YeouebFkcJrmbmhp3HfJFQ52SaSrShxPN13Q9g8Eg4=; b=icR8M8dOjc9ymHbhGWW4hh9Yn/kM3d640s1oHOQTuNhkYklfv6Lt5Wd8QnriuwOG581kJY4HC/+xPOpufnQqjOOmiteOUD8eAuy8cdSPgUuEN/vCch+bYxbKwD9MSBgE3ty3n3CvloMBY4OUseJIOlhTcDiWifpruFNMITMM0KY= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from DM4PR12MB5229.namprd12.prod.outlook.com (2603:10b6:5:398::12) by PH7PR12MB5997.namprd12.prod.outlook.com (2603:10b6:510:1d9::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5924.16; Wed, 21 Dec 2022 16:59:20 +0000 Received: from DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::8200:4042:8db4:63d7]) by DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::8200:4042:8db4:63d7%3]) with mapi id 15.20.5924.016; Wed, 21 Dec 2022 16:59:20 +0000 Message-ID: Date: Wed, 21 Dec 2022 10:59:18 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH 4/4] OvmfPkg/CcExitLib: Use documented XSave area base size for SEV-SNP To: Michael Roth , devel@edk2.groups.io Cc: ray.ni@intel.com References: <20221221160651.182143-1-michael.roth@amd.com> <20221221160651.182143-5-michael.roth@amd.com> From: "Lendacky, Thomas" In-Reply-To: <20221221160651.182143-5-michael.roth@amd.com> X-ClientProxiedBy: SA9PR13CA0040.namprd13.prod.outlook.com (2603:10b6:806:22::15) To DM4PR12MB5229.namprd12.prod.outlook.com (2603:10b6:5:398::12) Return-Path: Thomas.Lendacky@amd.com MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR12MB5229:EE_|PH7PR12MB5997:EE_ X-MS-Office365-Filtering-Correlation-Id: c8e45e50-5541-4dea-c390-08dae374b3e4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yRxnAGoYtOgGnyutn5P4WfC2+fP+SU7yB3XwNq0EGmOm+AN37OBCoG3ulhpfK4Bzakjrl6tZeVi6Tr5KT86utm/yn1dk5DgIulmI3Izj5qsoTAYaIwUJUxbMAcSf989rMQL6g8ba5aIfUcMcGD/RbtxhA4OeLgiYISSBEUvYeYaOVQ+XfZep6fhCmHo3EmRTYJ9la6R3p7Q8uL4EbmAX4hoplMz5c1rJimnvSdQAfB3kl1DL1tuKdPvBiSEo4dQkJ5gF4Wgmokuaqt5+eZCN1I5LzESEtPcXdzZTDK03IgUvPF1VjdOvRemoYoEBHrq2cEBEx88MrukmHHFwMBTlqWV8U1f7sT/ZGi4kEU/Ch0VAC74QNQfTVIFnaBGDuAZQR+KAW1m4uyutsxixovS/VzYv7ite5A/3UWkiJ/hP7HxpCVcKP1g4Z4xH5Cjazo8Em57TZjaEzSjIzeJ2GYTM2H7a08yELKlWOTLa5DJ4OflhD3sPme3Jcnkfe188I9XcJvqh0UfwbXm1PIgbClYzqaNkwY1Wrll2Tmhcau48nLjq85tr9PntI0fSQ4jl8C7n3sAV3fDFPl3hrGbxxe/MzJ21eEZguzEBluvoLPoO991v2jMO2tDGTthHiFTHlseGHB573FmxUS8rWCIpgpCI2ZFwCqkutXoJApTdEbpXqQjkbdNUAf3ncPK6E7Ve8UNAhPwUeX0wa/rizwrmMc1mkk0r9QZdFLImMz2nfyKvh2w= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM4PR12MB5229.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(6029001)(4636009)(396003)(346002)(376002)(366004)(39860400002)(136003)(451199015)(41300700001)(31686004)(66476007)(5660300002)(8676002)(31696002)(66946007)(66556008)(316002)(8936002)(2906002)(86362001)(4326008)(38100700002)(2616005)(83380400001)(26005)(186003)(6512007)(6486002)(36756003)(478600001)(6506007)(53546011)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?S1RJUXV6Tk9xTDZwd3ZRYmw0ZTV0ZDgvQWlnRnFFYzNQL3FhV1NiSU5qQUNC?= =?utf-8?B?cHhjOHVPZDJDN042U3ZMSHpPUmFCUTk3MVRwMkNaNCtyZUxHWW56dWZtSlFJ?= =?utf-8?B?NHM3U2xJaFArVXBWODB1aW1hM0RneUMzTi8zbWt6Q2lCT3ZWcEwzUDQxMUlD?= =?utf-8?B?bytqd1R1aFJJSEk5aWh3Yk5VRndQdHFtQm9xenU5NXVaWjNMYjYvcGp0ZFZF?= =?utf-8?B?L1ZmbkV0YlVhNXA2TkRwWG5vQjVMRUMzSms4VG45WVVxb3EwY2sxZlBQSm1a?= =?utf-8?B?TDhmdEhhcXQ2NVZHa2dOME1TM3JqZ3Q2MDJrcldBZnZLbkJvdEpCeEMwVkYz?= =?utf-8?B?VzFraFVSdmxKejdHcUE1QTVnRU5UMmMrbytLbHpjVkZ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id: c8e45e50-5541-4dea-c390-08dae374b3e4 X-MS-Exchange-CrossTenant-AuthSource: DM4PR12MB5229.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Dec 2022 16:59:20.1577 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: dI7Ua5VkCx9bXWydL4L/eGKbK7465xZmTQjXSmGt31Z8SruckHs9jbf0p+pf6xu+AmP5QLhUqfnAUSa15v0aeg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5997 Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 12/21/22 10:06, Michael Roth wrote: > Currently OVMF tries to rely on the base size advertised via the CPUID > table entries corresponding to leaf 0xD, sub-leafs 0x0/0x1. This will > generally work for KVM guests, but might not for other SEV-SNP > hypervisor implementations. Make the handling more robust by simply > using the base area size documented by the APM. > > Signed-off-by: Michael Roth Reviewed-by: Tom Lendacky > --- > OvmfPkg/Library/CcExitLib/CcExitVcHandler.c | 9 ++++----- > 1 file changed, 4 insertions(+), 5 deletions(-) > > diff --git a/OvmfPkg/Library/CcExitLib/CcExitVcHandler.c b/OvmfPkg/Library/CcExitLib/CcExitVcHandler.c > index cd117d5a31..f985dcff8d 100644 > --- a/OvmfPkg/Library/CcExitLib/CcExitVcHandler.c > +++ b/OvmfPkg/Library/CcExitLib/CcExitVcHandler.c > @@ -1647,8 +1647,6 @@ SnpEnabled ( > > @param[in] XFeaturesEnabled Bit-mask of enabled XSAVE features/areas as > indicated by XCR0/MSR_IA32_XSS bits > - @param[in] XSaveBaseSize Base/legacy XSAVE area size (e.g. when > - XCR0 is 1) > @param[in, out] XSaveSize Pointer to storage for calculated XSAVE area > size > @param[in] Compacted Whether or not the calculation is for the > @@ -1663,7 +1661,6 @@ STATIC > BOOLEAN > GetCpuidXSaveSize ( > IN UINT64 XFeaturesEnabled, > - IN UINT32 XSaveBaseSize, > IN OUT UINT32 *XSaveSize, > IN BOOLEAN Compacted > ) > @@ -1672,7 +1669,10 @@ GetCpuidXSaveSize ( > UINT64 XFeaturesFound = 0; > UINT32 Idx; > > - *XSaveSize = XSaveBaseSize; > + // > + // The base/legacy XSave size is documented to be 0x240 in the APM. > + // > + *XSaveSize = 0x240; > CpuidInfo = (SEV_SNP_CPUID_INFO *)(UINT64)PcdGet32 (PcdOvmfCpuidBase); > > for (Idx = 0; Idx < CpuidInfo->Count; Idx++) { > @@ -1888,7 +1888,6 @@ GetCpuidFw ( > > if (!GetCpuidXSaveSize ( > XCr0 | XssMsr.Uint64, > - *Ebx, > &XSaveSize, > Compacted > ))