From patchwork Mon Oct 16 13:28:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13423342 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A195CDB465 for ; Mon, 16 Oct 2023 13:40:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3B9638D008A; Mon, 16 Oct 2023 09:40:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 36A5F8D0001; Mon, 16 Oct 2023 09:40:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 20B6C8D008A; Mon, 16 Oct 2023 09:40:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 0F2F78D0001 for ; Mon, 16 Oct 2023 09:40:34 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id DBC4D4095D for ; Mon, 16 Oct 2023 13:40:33 +0000 (UTC) X-FDA: 81351434346.24.46EE377 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2052.outbound.protection.outlook.com [40.107.100.52]) by imf16.hostedemail.com (Postfix) with ESMTP id C867618001C for ; Mon, 16 Oct 2023 13:40:30 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=uq9xBeFq; spf=pass (imf16.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.100.52 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697463630; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=DUa4LLN/5rx18Dya9AF6PZolJHOKQF5UHzcW/KaErq4=; b=JRO/MWLnj68girgqPQN6bzIbCKfVik0tMBiJH+kUcxkYgTeHoiG28bZZnHZVcYPHbJ8vrR 3x6a1ybowA7/T/GpcWm+WcclnV0awCifEPwXlyQpIV1CwFL/qrmUY1R774Y4xt/ievT714 2nhegVIImpW7Xvfvv74SjEP3dHkrhgk= ARC-Authentication-Results: i=2; imf16.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=uq9xBeFq; spf=pass (imf16.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.100.52 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1697463630; a=rsa-sha256; cv=pass; b=YrQBSJ1JYDLkTTXYk3LfP6neiwTp+9pWO1c9ZzRDWxqBkW5BHvV2tjG+N2wpwOpHMCtKKE KHoSVV67Ikzm9DkPXcO+sF7K5PhR+ehJpQOFu4rRE9/W6en5jDAYcLnayIhczy+m6o1qo1 UofipxoEmF/adfmz4W7MIgo+dW/QsxY= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V+jYcA+pn2G17xiz2r4hu/jjEFmyAlxm/BlXSqkguWhTuEJ5fplC1zOCLBb8IXv4otBDbMrVcYwQ2pmqr1seBUVgVAkOnhPPgfdtFDhFD4btx6zHCTcoYlHmTMazWYOVPmemKK0BjOe9+Skhd3rD+SB5xxX7qvf+47s6O5faLW9xekfaUgWG17itDfGVz785CzkvgcKSDgk6ZYg7EpY8bFa559jS/KWRSvAMAzPytzcjm2ZToaxaM+JdShEUXGX8zdNDirV99En0yGmLn2zYyhv04QxS9Mfjl/korLlT5m56sJmJBiORA43ry4gPSbuhx8jg7eTTFMhyWjYMWurI8Q== 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=DUa4LLN/5rx18Dya9AF6PZolJHOKQF5UHzcW/KaErq4=; b=G+o7I4gbtVSkFXPzivo6NWDgWsTCFbcEmnnEg8QWK/26pGE4c49QIZBWRBMEqkzcZvM/2Qc+7hL37Jkd4N2fbWDg1fYBRv6SVpjZsbQZd/XQWkoXRRJoazkP8rXxvDGIW7f7hEwyNXK1P2GGb12sFuc1fxw5mEXnXKsIJ1P8liyduHWvnj75BI/6CV15vTYt/FdDsbPcvDxxWFwj7EkJaLnDHw34IyLbPDynesmUs3NLDd8rlGhpVZQp7f2mEIyvtSAiL7m5Fr9AJm6FiQplcmU/nAkDkg7QyaSSjbCvE4kVumzQ5ruqBIpJWvsbgIjjbKIO+B/QHftdNhzVPNi1iA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); 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=DUa4LLN/5rx18Dya9AF6PZolJHOKQF5UHzcW/KaErq4=; b=uq9xBeFqA/3ZAO+/jRiI4TgjSpIO1VoBn+3D2+/GlNZKHZJglpO3w+WnquWGobCe7IDx9YLnHx1uc2dOh1KMrvVCh1HCKFBsEIBR+WTQI2l/b/sUI5vjigLcLDtam4tQFYY4NLq2zAC26exzn5ZHCjPkfTZBCEiC4TobsMkmqng= Received: from MN2PR22CA0009.namprd22.prod.outlook.com (2603:10b6:208:238::14) by BL1PR12MB5063.namprd12.prod.outlook.com (2603:10b6:208:31a::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.35; Mon, 16 Oct 2023 13:40:28 +0000 Received: from BL02EPF0001A0FD.namprd03.prod.outlook.com (2603:10b6:208:238:cafe::86) by MN2PR22CA0009.outlook.office365.com (2603:10b6:208:238::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.36 via Frontend Transport; Mon, 16 Oct 2023 13:40:28 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by BL02EPF0001A0FD.mail.protection.outlook.com (10.167.242.104) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6838.22 via Frontend Transport; Mon, 16 Oct 2023 13:40:28 +0000 Received: from localhost (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Mon, 16 Oct 2023 08:40:26 -0500 From: Michael Roth To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Brijesh Singh Subject: [PATCH v10 33/50] KVM: SEV: Add support to handle Page State Change VMGEXIT Date: Mon, 16 Oct 2023 08:28:02 -0500 Message-ID: <20231016132819.1002933-34-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231016132819.1002933-1-michael.roth@amd.com> References: <20231016132819.1002933-1-michael.roth@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A0FD:EE_|BL1PR12MB5063:EE_ X-MS-Office365-Filtering-Correlation-Id: ebab6e9f-3d80-4c8c-353a-08dbce4d7591 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uWM/sit0AX4lrdxh6e5divQtzSDR0AmcQ2infXvZ5YoA7PlPMCQyxY1RWZshW9CqKnYtal1b1mI9JI8/VLgebEHpczat1BknGjRlHmwU9YcRMpIgXu1aKuWEKxN4R/HPBuAJXw+GAeYDR87P7q5KGM4YqCLnpeyaKlCZC9UBhi0GvqRYtY14APvUX4X/I40hcHKW1g715nwltJfylKTumBj7K3/AvF+Kel40UWNZ49u7SyExpJZQM1ZZizwaVFFatgz8Lvy2qwOcqIMGCpcSLIBtqAVX2ZxtR3aU0suuWsxcSjSdOqIZwrk4NUL30SyY0GSeS9SiOLdod+VCFe+YZoEw0Kss4A7t4Bd2EjQhE/OQPaoKPHIREzWV3wmdFXiWwtyZ07jOZtCQyKuIMQIRsoG7PcSy3GxEACj7T00Z7joPBcVEB691NK/+6YOsayMZcZcofpBrJ1plPX7iVLqv/G9B9CiQEcmhBNaJUG7aMoCJBQCqcUVXWIQ6z81MiMzGvQORKp9beWV+SaWMvoKS/KD1QyxGbg7s2BZb4RSeJZ5TntpzA/RvsJ4Y0yMkV+rP+JxsH9sIPNwxF8LqnaGJvAjxXM0uA6E0mJYVTyllRWKtP2auqEQPPtZBCiagYfHkn81sfu8tF9PjZUgAZzAhXzs2JsDtDlz86PoVo69SAYJeee5qzJhxMX1efo1E4cLAFwMgx/00Rgt2XyYTihFLJ5FQIqEZwNtOFeiyi46YJ7Uvh+S72plAwuC4a+hamklafXcVw0PcN2oHpnqg6KAy+w== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(39860400002)(376002)(136003)(346002)(396003)(230922051799003)(82310400011)(1800799009)(186009)(64100799003)(451199024)(40470700004)(46966006)(36840700001)(70206006)(70586007)(2616005)(6916009)(54906003)(478600001)(316002)(7406005)(426003)(1076003)(336012)(26005)(16526019)(5660300002)(8676002)(8936002)(4326008)(44832011)(2906002)(7416002)(41300700001)(86362001)(6666004)(36756003)(82740400003)(356005)(47076005)(83380400001)(36860700001)(81166007)(66899024)(40460700003)(40480700001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2023 13:40:28.2686 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ebab6e9f-3d80-4c8c-353a-08dbce4d7591 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF0001A0FD.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5063 X-Rspamd-Queue-Id: C867618001C X-Rspam-User: X-Stat-Signature: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MApfR2Y2UC2FYhX4s62rw00xWYgmyNOo0cpfJsX00hbu7uVaZurnErnSeZne6qeKBQS1URXJA9/clW8BZglP49vIR0i96fcyscLXKynvVLRo+zYA6Xt+h8xQNEipQNwVjrEzWKfgY+iN/BtEVkVjuAOjJg6MjxVFwE2Cmkj8CtHKQPm3DhUL1Ipih8Y8cVsOeG/WjjRJkK6p6Y5JXsrhO94KmmZTfwZjlyOgCVei7/Q6Ptm6GbDHfYLC0pyEH+PCuHbPqge6i7XORxJm4cHhseC2NNtYA4/GnPIVENECJ6pYC56hIuI2JlOHx54LDWYUnMeV8o3aBWY+aLNA32yJ5Iox5hX+88eiodTkg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Brijesh Singh SEV-SNP VMs can ask the hypervisor to change the page state in the RMP table to be private or shared using the Page State Change NAE event as defined in the GHCB specification version 2. Forward these requests to userspace as KVM_EXIT_VMGEXITs, similar to how it is done for requests that don't use a GHCB page. Co-developed-by: Michael Roth Signed-off-by: Michael Roth Signed-off-by: Brijesh Singh Signed-off-by: Ashish Kalra --- arch/x86/kvm/svm/sev.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 4890e910e6e0..0287fadeae76 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -3081,6 +3081,7 @@ static int sev_es_validate_vmgexit(struct vcpu_svm *svm) case SVM_VMGEXIT_AP_JUMP_TABLE: case SVM_VMGEXIT_UNSUPPORTED_EVENT: case SVM_VMGEXIT_HV_FEATURES: + case SVM_VMGEXIT_PSC: break; default: reason = GHCB_ERR_INVALID_EVENT; @@ -3278,6 +3279,15 @@ static int snp_complete_psc_msr_protocol(struct kvm_vcpu *vcpu) return 1; /* resume */ } +static int snp_complete_psc(struct kvm_vcpu *vcpu) +{ + struct vcpu_svm *svm = to_svm(vcpu); + + ghcb_set_sw_exit_info_2(svm->sev_es.ghcb, vcpu->run->vmgexit.ret); + + return 1; /* resume */ +} + static int sev_handle_vmgexit_msr_protocol(struct vcpu_svm *svm) { struct vmcb_control_area *control = &svm->vmcb->control; @@ -3522,6 +3532,12 @@ int sev_handle_vmgexit(struct kvm_vcpu *vcpu) ret = 1; break; } + case SVM_VMGEXIT_PSC: + /* Let userspace handling allocating/deallocating backing pages. */ + vcpu->run->exit_reason = KVM_EXIT_VMGEXIT; + vcpu->run->vmgexit.ghcb_msr = ghcb_gpa; + vcpu->arch.complete_userspace_io = snp_complete_psc; + break; case SVM_VMGEXIT_UNSUPPORTED_EVENT: vcpu_unimpl(vcpu, "vmgexit: unsupported event - exit_info_1=%#llx, exit_info_2=%#llx\n",