From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.40]) by mx.groups.io with SMTP id smtpd.web10.21648.1590180709557021894 for ; Fri, 22 May 2020 13:51:49 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=QhD0tNia; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.94.40, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HTeZKR85s50DmQePpfRBLXg2DCZq3QwZFHzDGs50XornbV6z9Y+7mpdeqqBly5nJjKz64PMQGXWrE1sEIaNZBPhm3mm+xf5CYZB5ZQDix6E30qP64Mvv5yzma1IxLJ5kaMLCkUzmxDs5/afd4691wPg1CkAt31zRFzEDHjbklJYd/plxje6jNTMNjhu5RSUQ+8LPfqpSv5sMpTs7nWwoS+1qA8+dUnBiqef+hUte+xOyzw1hwwGPKp+JPzSljsdghNafKUmRt8ybsDV8pL8eLgu1TTlFKNTiczW85IKDlgFCmhhqHQBifl1Tahkstv9uB/CwkAxFcAtLB66OgoRYlQ== 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-SenderADCheck; bh=6PvrlOVJKTIncv0HF4YNVqutC6E9Xg64T5r/urbIEXc=; b=TxHD1R0lyTQOltbCVU/i10WpLvr3QqrIbAOAysE1LCE7AqCxRyUIiwjw+PBoKS3xWEpylpXxuWlg13JyBJUjod5RXtyJ/ntVWI6zG2JbnP5XaI9IV4j2Tkoeossu01Efri0b5HW14LpKfO9tygmegsT2u45NSXVF1K6RX3N1xGdV491QEK8tf13yTOa6jQgpPsmAENMGAN+nRfWma/WnODq3p46t2Au2aHoCQkjOICA82fb517C/NuZ4MbJ6UC53R+YdViiN8JOP3vIupWqlE2Q4cR0b/kmCqLfAZz350VBxnuuvUHQejmc1xkMtpBIVhxCx0Ab6iad55wvtgJyJqQ== 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=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6PvrlOVJKTIncv0HF4YNVqutC6E9Xg64T5r/urbIEXc=; b=QhD0tNiaR1WthycuNzkSqSNXuY2chs6nA3ss9jEiGLsi2IfguuCwYYfVCXAbnqPcmgPzEjRuOlArnh4GbwZW8rW0OSeS2hFa+SmvfV42lPRYJgi4RUp+LuMHnjIJ89RYUtEVxYFQ6igMoB8yeTWthBOzkePUs9RZV5Xvd5E6bpI= Authentication-Results: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM5PR12MB2341.namprd12.prod.outlook.com (2603:10b6:4:b5::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.27; Fri, 22 May 2020 20:51:48 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Fri, 22 May 2020 20:51:48 +0000 Subject: Re: [edk2-devel] [PATCH v8 18/46] OvmfPkg/VmgExitLib: Add support for WBINVD NAE events To: Laszlo Ersek , devel@edk2.groups.io Cc: Jordan Justen , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh , Ard Biesheuvel References: <67168bb4-9d20-0ca3-08c5-30bbd38d06d7@redhat.com> From: "Lendacky, Thomas" Message-ID: <7b346711-a421-54d7-54c2-701b2bf12040@amd.com> Date: Fri, 22 May 2020 15:51:45 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 In-Reply-To: <67168bb4-9d20-0ca3-08c5-30bbd38d06d7@redhat.com> X-ClientProxiedBy: SA9PR11CA0002.namprd11.prod.outlook.com (2603:10b6:806:6e::7) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) Return-Path: thomas.lendacky@amd.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from office-linux.texastahm.com (67.79.209.213) by SA9PR11CA0002.namprd11.prod.outlook.com (2603:10b6:806:6e::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.26 via Frontend Transport; Fri, 22 May 2020 20:51:46 +0000 X-Originating-IP: [67.79.209.213] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: fe638543-8f43-46f7-90e2-08d7fe91f1c1 X-MS-TrafficTypeDiagnostic: DM5PR12MB2341: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4941; X-Forefront-PRVS: 04111BAC64 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9FoXRLghFOo13bF0qJzC4mTMvKwWnGEzcpJ0H8AMon+4UQwJn0mOd3W+AtF9mHWiIv8mCLbMelfJfhJMgVEi1eCaccOoOoJ1gaTypWvqJKza4r1oApHX9teBmHBX88kvGcJ+A515uNhLOVyhbBv79Mc8mRnzmc8EC8xhV4NXx7owNpZlc5Kl3KD0zLsdxP5ClH7akc49qW2TOE6KcufI1Ng2VnrTIT9VlJ8TydZgZ7/dA8tj3pEitLAOURlZVqJI3f6MEb87l0gK9a+WT9fl+V7OVioUxHa1LxJzS0HdjjymyXFnzJ0cTT3bmWGonJbsCcm789NeEC51IvGh92zoz1TbNlMI+tZaLFV8vBBzHTcnklritGBvhiOQ6LNu9qPekz9lVS8bFAoTtDXk0TPSSLfNyWvivlhBXQtByPIs/1xqJDWnZHXWvMu7QdtHmP4TOb2n+tPh2CF6OYo3Y4Gu7wBCjXTz7fYZH3j9QT9k+PMkefwv7hwa7nOQodFTBFc2VZ/Mpy2EKeZDR2CVEP0vCfKuoVGljd3H2tb8LS+TNtuF3wnW2jBr16QkYRS5xAE3U0ep5rzdsnLe4eNxQRLMvw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR12MB1355.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(39860400002)(366004)(396003)(376002)(346002)(136003)(66556008)(186003)(6506007)(966005)(66476007)(19627235002)(53546011)(956004)(52116002)(86362001)(2616005)(66946007)(8936002)(8676002)(45080400002)(4326008)(5660300002)(478600001)(16526019)(31686004)(36756003)(6512007)(26005)(54906003)(2906002)(6486002)(316002)(31696002)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: e2KU26evkuzmhUqTAoZw36tDVZ2boh8Yar2rohM6sd3xAIqFAYwdlYNXTMzbtlZUqAp3IW9yQTYJbe3pOhN8OVNCTpLQiIRMJeesydDz8IYoEZn21SYFcUWH5dF8FlVDUHTo79Sz6hFWyXxaSTgzt1ZKli5u5rnxXX4wpq04FM3fqX3udkZ31AuEippYR88yLQnYgPp4nnAWeomwbLs5rDVmkvU+7S2qpWu7lVWLkIXbbUfB/xRP7TTS4k+QkeUiuZas60EyH+dUCEm7Or7jsQl9Da+3oHGOSzj2Y3vXyeyW69Bl+69XhNtPvz+q5iOMtmU2O6MepyzU9HglV7Abyu7DpsuZ82UzIf1GGkvKYv+69Wc6smvhZUJjg/BmTdAm+LHGvQFJNX2AO4jtqmvSTaxrmzJo42cLMuirEXwUZmJ8h5GL4wWypqFxoKXKWdCThQA0/kaDJDQQ31H9zozju0JaJYcJhL2bE7+3UjjYoWE= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: fe638543-8f43-46f7-90e2-08d7fe91f1c1 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 May 2020 20:51:47.9870 (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: 87K4h80FW/6eqH5yplBmHFn1CqZOnx0TFPYSeL8Cpq/JWah61jgmTfNuuzWJ45zSSfD4EkYuRqBTUqGP2ZnCEA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2341 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit On 5/22/20 9:19 AM, Laszlo Ersek wrote: > On 05/19/20 23:50, Lendacky, Thomas wrote: >> BZ: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2198&data=02%7C01%7Cthomas.lendacky%40amd.com%7Cfc8d0918a2474d08139808d7fe5b2a93%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637257539824804827&sdata=aiIeMfwp9GQCrgqOw2si6NzLZOZzRRV%2Bzu3dpT6S%2F5k%3D&reserved=0 >> >> Under SEV-ES, a WBINVD intercept generates a #VC exception. VMGEXIT must be >> used to allow the hypervisor to handle this intercept. >> >> Cc: Jordan Justen >> Cc: Laszlo Ersek >> Cc: Ard Biesheuvel >> Signed-off-by: Tom Lendacky >> --- >> .../Library/VmgExitLib/X64/VmgExitVcHandler.c | 36 +++++++++++++++++++ >> 1 file changed, 36 insertions(+) >> >> diff --git a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c b/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c >> index 50199845ceef..0cf26c052b32 100644 >> --- a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c >> +++ b/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c >> @@ -843,6 +843,38 @@ MmioExit ( >> return Status; >> } >> >> +/** >> + Handle a WBINVD event. >> + >> + Use the VMGEXIT instruction to handle a WBINVD event. >> + >> + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communication >> + Block >> + @param[in, out] Regs x64 processor context >> + @param[in] InstructionData Instruction parsing context >> + >> + @retval 0 Event handled successfully >> + @retval Others New exception value to propagate >> + >> +**/ >> +STATIC >> +UINT64 >> +WbinvdExit ( >> + IN OUT GHCB *Ghcb, >> + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, >> + IN SEV_ES_INSTRUCTION_DATA *InstructionData >> + ) >> +{ >> + UINT64 Status; >> + >> + Status = VmgExit (Ghcb, SVM_EXIT_WBINVD, 0, 0); >> + if (Status) { >> + return Status; >> + } >> + >> + return 0; > > (1) I'd simplify: > > return VmgExit (Ghcb, SVM_EXIT_WBINVD, 0, 0); > > unless you want to keep the Status variable (maybe for inserting DEBUG > statements more easily, if needed). Even in that case: > > Status = VmgExit (Ghcb, SVM_EXIT_WBINVD, 0, 0); > return Status; > > With either option adopted: > > Acked-by: Laszlo Ersek > > (The real wart I'm trying to address here is the evaluation of "Status" > in a logical context, as usual.) Yup, I'm going through all of the patches. Thanks! Tom > > Thanks, > Laszlo > >> +} >> + >> /** >> Handle an MSR event. >> >> @@ -1238,6 +1270,10 @@ VmgExitHandleVc ( >> NaeExit = MsrExit; >> break; >> >> + case SVM_EXIT_WBINVD: >> + NaeExit = WbinvdExit; >> + break; >> + >> case SVM_EXIT_NPF: >> NaeExit = MmioExit; >> break; >> >