From patchwork Fri Aug 20 15:59:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 12449959 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C78E8C4338F for ; Fri, 20 Aug 2021 16:05:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ABB1661250 for ; Fri, 20 Aug 2021 16:05:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238521AbhHTQGY (ORCPT ); Fri, 20 Aug 2021 12:06:24 -0400 Received: from mail-bn8nam12on2072.outbound.protection.outlook.com ([40.107.237.72]:45024 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229772AbhHTQEX (ORCPT ); Fri, 20 Aug 2021 12:04:23 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P4e4I4WQlD056UUR+LDDow/+cjcoO9crrtoA7KQxA/RT/uu1vpDQqPcs+fw6DmBvtXHuEEZe/Bjg4a+mOl7V3AD0ZPsTopaBA2U5eCbnkMFTKs3dUWWFzoAM1Pjo3sk5jb0N2SKPbFBiUWuyBT9OEiECMt7IN4b1rFUmy/M6MGlZOJAUumTbWckak7kcp/S4HL2pqzcOof/75E/dGp/ZBXA0Z09fUCaOW4GByCP7VuAFx1PYTzSN7z1/TPyfqB4sE2/e4jCWF6jCZ2GaKl3VCXrJSgdJhgto2bhUWizpl+i33yZthQWGUTZ6a3OwRu8Ocsn9QTz2IHdzU+fpSJUE8A== 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=jgGy54dnJkrivIr9eJV5SEJ/kD8j1HP7vpZl/8sU0RA=; b=ZA6fmE8B0z+pSqvVB/UC2GdVhG0NO9dLgDblIHycuMZddqSb98amAeJBf3pKgONUWVFlu/pNtnYHTN2YX2jIPE0gNejn3R7SdDdNcBvdWb3oSl0JuqcL4onndbXRMOkORu/47JNIjqGiUpAy8IDtZNuGDTtJylNwmboyMCJM6boK97vme0hYBgYOQM29Gw8s8DAXqBCif244tx89As12/ZWcuGzVMDey3n57CQlgDjhqq6y6+rI4tx68yhTczdbhhqsH7qraLPfqXWgBZn67OYgMTzaz6+P3+hWd0vEF3wRLYH0BaYvPRE6Vu2hxGlUYVrETgXotfle5dKP7tp0Kbw== 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=jgGy54dnJkrivIr9eJV5SEJ/kD8j1HP7vpZl/8sU0RA=; b=EVRX/8qCGaI14kUNdhV4IKIUAM+WBHbRSbEfdULq42NicloGRfmB70CJVzaj0A99XIVyh5d+OnZf1v9XBHwaYRgEFXvjpeO1gID3PZt3SzKOE7Wgnb3vTyZ+YDTaIBb/IbowFc9NPpXV6noztkWfgQKEP7Ft/91UPU3YH+zNvkA= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) by SA0PR12MB4509.namprd12.prod.outlook.com (2603:10b6:806:9e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19; Fri, 20 Aug 2021 16:01:10 +0000 Received: from SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::78b7:7336:d363:9be3]) by SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::78b7:7336:d363:9be3%6]) with mapi id 15.20.4436.019; Fri, 20 Aug 2021 16:01:10 +0000 From: Brijesh Singh To: x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-mm@kvack.org, linux-crypto@vger.kernel.org Cc: Thomas Gleixner , Ingo Molnar , Joerg Roedel , Tom Lendacky , "H. Peter Anvin" , Ard Biesheuvel , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Andy Lutomirski , Dave Hansen , Sergio Lopez , Peter Gonda , Peter Zijlstra , Srinivas Pandruvada , David Rientjes , Dov Murik , Tobin Feldman-Fitzthum , Borislav Petkov , Michael Roth , Vlastimil Babka , "Kirill A . Shutemov" , Andi Kleen , tony.luck@intel.com, marcorr@google.com, sathyanarayanan.kuppuswamy@linux.intel.com Subject: [PATCH Part2 v5 43/45] KVM: SVM: Use a VMSA physical address variable for populating VMCB Date: Fri, 20 Aug 2021 10:59:16 -0500 Message-Id: <20210820155918.7518-44-brijesh.singh@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210820155918.7518-1-brijesh.singh@amd.com> References: <20210820155918.7518-1-brijesh.singh@amd.com> X-ClientProxiedBy: SN7P222CA0013.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:124::11) To SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sbrijesh-desktop.amd.com (165.204.77.1) by SN7P222CA0013.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:124::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.18 via Frontend Transport; Fri, 20 Aug 2021 16:00:47 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1bde20be-330a-48cb-7b6b-08d963f3ad3c X-MS-TrafficTypeDiagnostic: SA0PR12MB4509: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jGx/slJKI788K8bBwDS3vhaYyv+Y9cv0cE13gSgkNjfh6lUbuvlOmFWV0Ja235VnQ2tbqYFykDY8hlWa+MEQmih3bocDKPiHBe+LLcIP9lGm17YTPW64NRe/Aj/SiM1Uy6Yc+CYl1XkSqHau3Oai1wTKt2AHneJtUd0b2pZ3GOkvx2yJNsuHHiR7Dhb+Gyhdrg3oWgjFBgYa6GkX8FrrEXCWUPTgXiPdlY8ZoADzlzZsuHGuUKMMx49g2kHCGlGBF4i8xdecf08oXHyCXA3q3tdaIvUTMWHB7bHfB7e7OGfiGZJtJJEdtf0nMm4+H//OL2xct1XFFU8sn8Db+0Pe09CxD0PNiW75pO07j3YySLGhZ414qsb7xRSF9cdetZDL+0HPU99RYdOAtmTfYqL46Kh0aGQns7xLwLIS/LGNIRrgL2D9bdYiXJ65HkNHWr12EHg6qDP/2BmVHDK0hhbAniFu60v5vAhYUQCm4f08E0w3Z1bPP1cgd+5XHrKHoO9gwXrLJhrraBYH1gVj8qdyewvKGMlM65RlbPiSatFnR9z9GG0KyXF3x+F+veocIa4qKofOnLOAfD7Jq6txzSgqxVR95TmTdNqPzXarcXBlWyUAfhwnSXbGjDpIN/H02JUIYbcT2neuJlQLckCShsCLeUilHmZ0YVOU7KoxL/kiT+PkruwlLG7WCTcJrEmyXUp9wXSmxauOgMFqvzs9Jgt3EQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2718.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(508600001)(4326008)(36756003)(7416002)(44832011)(54906003)(316002)(66946007)(66556008)(66476007)(86362001)(7406005)(956004)(6486002)(2616005)(2906002)(83380400001)(38350700002)(38100700002)(186003)(5660300002)(8936002)(52116002)(1076003)(7696005)(8676002)(26005)(6666004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 4JtmKJWKk6l0BlUGxidwA87nFdQ++XUtG8DhXe/J4vSVP0OkR7T3LuhtibVUjUCqW9/TGzTP/d8ckJQtrWMLPdVShQxCXCBqi9EQ+qGUcQBSXkCXTbC+rpt8OOby9q7+n7VNQZDpu64w+nJNz8XvzY1nWWKXldVrHoK+fUGsuzEF+oZSmkd1OXR7xOsjRpqLZJ+QfqFHG5RqHhn8cjhuE51C71S7jcCfzVs2b/DZXzXgaB5V8+j4TdshecaA94duvjWDM3943uLAHBnIGY+X4xNBZ308yboQr5wCOVHD27yaQFJtiKZq+JuixI+R4nIAAM6HXZQQzRF/C5ve1mHoHfwkXmqX18m80ajqzaIkigi+8XUhM70NjF72YEXeRaIqbcpLvvNXSGupDrU0b7Jv4Cw8/pBb/AndeO4q22fd0fWxi0wK9pwydDEVfspmSCeHzqqtOcNe7Kec8ZisRxyKeilVMiaWGFSEgxG1tiPljYbEDtitaFCDcpKYvIU6+3eX/v+LcC0Sk1Fzn2ov1H7enLNoh9SGDOO3peAsjCFoks5i81WyHzZ/m6m5Tx/P2C1+BHIMxrIanLeR7160IVXUIQtF3wwK2U2gkqi9V6mNE8hzo2RU9n03PfAcf0sbHSA1QqndOsgKPGeBnsU8Es4ngkmP6/jYSgtkd4C68Es7ut60F6Pvb7s6WoAq4QdMu7oQGqJIVdobtJXGtP2O7dB7kuHpdrAY1ZjPvTzx/6gZ0zgY/dJyYelwSsDhmBb5Eud/z+Hkowf8peHRPW0UWQELeNJddT40lL5zAhQ9tlLW2hxgn/8ERRP2T8TkSyNhG69PwWW5Ou2D9T60ksTfBjbgZoyMxrE+TbOsFmcqQQeITL6p6IeibamF1Nfj2psCaG/Kslwohk0AlppuXQr4LdDnwhCcWEzHlkJrn5lL0kXYTV55T80NBJjLR+MBefrQwbKa/dvx/bb57uj9ILVfVImIbtVPpJ5/2aoQO1Gx1El8W0TBEa00G7lRjII1OI/qThGM5KFy+u4DdbYrO16z0i5QVJv7uwyOquD2OvCkqaDeXobsBlBKtlZeYjUz6kiWoPKgbGGEYSXyluOJaupDoRfAiHJWktP+gPpiVbeKhpQTpZ5LMLkrsfiPFGYZT+pnnljHFfT4STa4qOt/qeDPR5zubUKwOQUkAM41ARizPQwDc+lFiHlh9qLZfgqshgzaa+tTAuJP8fgRjB78D98SjSU7T/u9pgpkyYkAxnSkCov5iZ4oAWmj8HSbon5KHqPFzBbLoGqhO8nUFDgUtDPIcWVzBHJpJMvSVCBUeBWRvxPh3X9WnR8lGNYh4Uk0Mb2kxteB X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1bde20be-330a-48cb-7b6b-08d963f3ad3c X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2718.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Aug 2021 16:00:48.5969 (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: uxkdFAa+z3sW9ePyL7RVdF00vj7kXWpz66ufjoJb2UviR56CXNznBXbO6Q5TeafIivNANRNf71K5sMiT7LwxUg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4509 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Tom Lendacky In preparation to support SEV-SNP AP Creation, use a variable that holds the VMSA physical address rather than converting the virtual address. This will allow SEV-SNP AP Creation to set the new physical address that will be used should the vCPU reset path be taken. Signed-off-by: Tom Lendacky --- arch/x86/kvm/svm/sev.c | 5 ++--- arch/x86/kvm/svm/svm.c | 9 ++++++++- arch/x86/kvm/svm/svm.h | 1 + 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 81ccad412e55..05f795c30816 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -3619,10 +3619,9 @@ void sev_es_init_vmcb(struct vcpu_svm *svm) /* * An SEV-ES guest requires a VMSA area that is a separate from the - * VMCB page. Do not include the encryption mask on the VMSA physical - * address since hardware will access it using the guest key. + * VMCB page. */ - svm->vmcb->control.vmsa_pa = __pa(svm->vmsa); + svm->vmcb->control.vmsa_pa = svm->vmsa_pa; /* Can't intercept CR register access, HV can't modify CR registers */ svm_clr_intercept(svm, INTERCEPT_CR0_READ); diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 3ba62f21b113..be820eb999fb 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -1409,9 +1409,16 @@ static int svm_create_vcpu(struct kvm_vcpu *vcpu) svm->vmcb01.ptr = page_address(vmcb01_page); svm->vmcb01.pa = __sme_set(page_to_pfn(vmcb01_page) << PAGE_SHIFT); - if (vmsa_page) + if (vmsa_page) { svm->vmsa = page_address(vmsa_page); + /* + * Do not include the encryption mask on the VMSA physical + * address since hardware will access it using the guest key. + */ + svm->vmsa_pa = __pa(svm->vmsa); + } + svm->guest_state_loaded = false; svm_switch_vmcb(svm, &svm->vmcb01); diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 71fe46a778f3..9bf6404142dd 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -199,6 +199,7 @@ struct vcpu_svm { /* SEV-ES support */ struct sev_es_save_area *vmsa; + hpa_t vmsa_pa; bool ghcb_in_use; bool received_first_sipi; unsigned int ap_reset_hold_type;