From patchwork Mon Jun 12 04:25:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13275526 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 8EDF4C7EE37 for ; Mon, 12 Jun 2023 04:44:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2F6E16B0074; Mon, 12 Jun 2023 00:44:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 27F008E0005; Mon, 12 Jun 2023 00:44:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0F88A8E0002; Mon, 12 Jun 2023 00:44:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id F34F66B0074 for ; Mon, 12 Jun 2023 00:44:26 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id A6830A0261 for ; Mon, 12 Jun 2023 04:44:26 +0000 (UTC) X-FDA: 80892854532.22.A3FE862 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2074.outbound.protection.outlook.com [40.107.237.74]) by imf12.hostedemail.com (Postfix) with ESMTP id 9FA8940007 for ; Mon, 12 Jun 2023 04:44:23 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=ZFg1dBhI; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf12.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.237.74 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1686545063; 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=3sDrVPW9K6hr5iqjy87+FTvyv+9ltC0aCsqlHuApz6k=; b=X4NaxDQnQhPrsemfPFo6kacjmT1bBmHIksysBMFq8XvyQ2qEZ1hlJH7eYQQy8IZeP1vNLp +dDr03wAKHOM4A9VAwoxJE9mcEG4cQZfZASisVsQM6sU7ch0BW13gZut2CtesUG3fHIZTJ Jg/89NfY7eLYlnyBWFIN83/ZmKp8p5s= ARC-Authentication-Results: i=2; imf12.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=ZFg1dBhI; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); spf=pass (imf12.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.237.74 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1686545063; a=rsa-sha256; cv=pass; b=aovI+s6Lb6kFFcZ7mu6ZrQ2wIzroMONnNN/nXbcqipQvr6OtWbEjNoUwdQ01tt58hZz3ms ZF1A/t7V/GG5hYdNBcI6eAO0FG9pAOi/m2Y34KOG9K7er25IghDYCxdQC5u+BAGd93/rxw cfPORyk4LlDUirn3trsj+8WKBKpuEAM= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VOmWeOCa6NkYH7ePV3RsOvkDgBdH4Chk5VCtWI8IYBX/NzqQ+uUg4n747GRM0oCbxzs5+m/xLHZhfv5Atb14ieTbqW2iuBbbPOJr1otAAmScD1Jaz9leomaopWIXZ0NuYVnOMnYUNDGO3g8bzodyh+gS0rw5HuvG8dlP8lkLVT/VKzli5MTnlckbJ/TmqpHKnKGNJ8rvkNx3GcnnEk2LGUgZA9JSsVAYbLf0k0PgEFHnC5gzMDUNAnXIlrzy49YS1Vs+ToXlgcUKHDHSOi3CyjdW53bXx/sEUzDbkK26KTn4q/JdTE57t1O2xzVcHsqEnML6Jj2qVqp5qriTamwwvw== 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=3sDrVPW9K6hr5iqjy87+FTvyv+9ltC0aCsqlHuApz6k=; b=eBbZMCxgr7rn9nKM7H+ydg7gfayNpM8tczu6Ao6pJ9J7wYBK3WB6ngIhpHZrULiOGIpFJDwCwAx/p3H7/5J25H91aQd4+MbB3DQsgVlBJZafwTQDcSnBGPWxBCyxnZ0fD1dS8OT2yvBHKnt4IHDOoh/uNl7FfnZA+zCXPmpHTfv3Ve4JZchQftPun3GpIgn3EaBAVmHgpamnGCBBM76DmAcoqo47AUTrzaHiTIseRqkVXGiAwOP59XnH7Fnr8RhmggAnx2VgGChpas5s4Xbqdse+zaAJ4eHgGaf3EPQ3TnivdRjTkdXVKaeJQZKp0+7TgvI8QI1L/PtVNCTvNfO1NQ== 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=3sDrVPW9K6hr5iqjy87+FTvyv+9ltC0aCsqlHuApz6k=; b=ZFg1dBhIO/GPB96ZYa0CbeIMDY4CVnzwabNCjvbpGdwRsIe5XkfcW4UCW2bzHvNKCam70NLibNEODKA87b1Bl1eHlt9fknedxu5ttOgVgHc8rA4zk3fX67zLSMmBJ6XmGXWEJ6ZRK2Mcn0r7pRnxElMvJLFs5blIVRJrjLih05Q= Received: from DM6PR02CA0113.namprd02.prod.outlook.com (2603:10b6:5:1b4::15) by DM6PR12MB4500.namprd12.prod.outlook.com (2603:10b6:5:28f::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6455.46; Mon, 12 Jun 2023 04:44:19 +0000 Received: from DM6NAM11FT046.eop-nam11.prod.protection.outlook.com (2603:10b6:5:1b4:cafe::f4) by DM6PR02CA0113.outlook.office365.com (2603:10b6:5:1b4::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.33 via Frontend Transport; Mon, 12 Jun 2023 04:44:19 +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 DM6NAM11FT046.mail.protection.outlook.com (10.13.172.121) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6500.22 via Frontend Transport; Mon, 12 Jun 2023 04:44:19 +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.23; Sun, 11 Jun 2023 23:44:18 -0500 From: Michael Roth To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Brijesh Singh Subject: [PATCH RFC v9 36/51] KVM: SVM: Add support to handle MSR based Page State Change VMGEXIT Date: Sun, 11 Jun 2023 23:25:44 -0500 Message-ID: <20230612042559.375660-37-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230612042559.375660-1-michael.roth@amd.com> References: <20230612042559.375660-1-michael.roth@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT046:EE_|DM6PR12MB4500:EE_ X-MS-Office365-Filtering-Correlation-Id: 7d9c5aea-57bc-4b7d-8f60-08db6affaf32 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YnoRJBIiWIS8VmyL7Q71Yz9l76DEfTekyzl/7U8sJW4ZomDagrcBw4q+7e0B4+ge21/zXE7IgkBmUOpPuIS3Vyq0SBsOTiBWoGiygSDwp8DwZsATzmnJvL93/5eqGfnboNR2AjvgBLErx3m1aNe17uZWOkqL/HJgNUv2clhZIXxj8328s10Mh7hAOvVHBrinjeV3Z1IgMOEJtu80oKpYPnOtRC/DubE1B5cjAzmUe9RYIQTMo0Jdz6Oj3hMxW7/qx+1xMOm9GxK1c6Eh9c1VstOB5jNghJ2e4Ib3Dve4gvIY2q0+Z1Z6IoIdHAzZp7h7CPk3xzArVfoFVe9SGIy6wesCLwVlbSxPHZhguzgHR0bukTnTr7nIzBvZDj5J2JnJ+12KoPdNRfh5tArl5uFXF+DV0TczLiVahUrrwq+eL2uCzwB63f5TenNUnKjE9duvgH6tGRsSSIc+BvVK6aWoBSWJXIMQEnRAqe1x0tcYHyJv8PX0zVl2Gkv8ccm1++a9pyyaYFXWJCV57em8ZrgcVFOlde2O0tM3tfaaQ09/C0B6V0slzxhjL6rMI3oW1eHpUp30MpxSehxglBFhqpBwdUk8APBHKPnvuzZa1w732I4FjgVOawmPzAuiJCULHNGobzFbmoQmE3lOa6EC/b+TciBikkpjjU0zevWu5r2IKmJCplqky14Bd4ppQ3ZvZF/3ivmwHNxsJd01RSoZOIWEp92Oo4CLHDJiFgSFiWAZBEZ9TZyjKyoqkMQRCz5q1e3alXMV0HG5GddoUXS0pGCUBw== 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:(13230028)(4636009)(396003)(376002)(136003)(346002)(39860400002)(451199021)(36840700001)(40470700004)(46966006)(7416002)(7406005)(5660300002)(70586007)(70206006)(4326008)(6916009)(44832011)(2906002)(316002)(41300700001)(6666004)(54906003)(8676002)(8936002)(426003)(16526019)(336012)(2616005)(186003)(26005)(1076003)(83380400001)(47076005)(36860700001)(86362001)(82740400003)(356005)(81166007)(478600001)(40460700003)(36756003)(40480700001)(82310400005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jun 2023 04:44:19.0807 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7d9c5aea-57bc-4b7d-8f60-08db6affaf32 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: DM6NAM11FT046.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4500 X-Rspam-User: X-Stat-Signature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7s2SO+C9NfS f4Ykdb5K wn8AHoMJk6llA6PhN0IMXM9wMea0k7yJ0iCeVMXtJ1PlVnazknsarMM/pP++Dz8oY2o7cw+U64JlTwV6VvyDd0mizP9oscIMwdh+OuyiNmuYF88KjHSgevdMLFBVrIOTqIGxaGl78DGS373NCxPzUvAJ3CxxI7Q2fUbbI0/4RTHDbj++aPvjag5WQP4TiC0CAoKu3qRrWKKCXcVDwcs88og//h52q5UWbXTkf/+cIRK0EXld2vefI01QMGxmMZnIzpVVDRUBoBqrXKY7aWznwfU/Lo7XJ9KSfr55Flr652U4k9ZeweNW2V0dHRK/25EmcWVL+5dUHH5KrYTAMk/g97jUJoA== 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 MSR protocol as defined in the GHCB specification. When using gmem, private/shared memory is allocated through separate pools, and KVM relies on userspace issuing a KVM_SET_MEMORY_ATTRIBUTES KVM ioctl to tell KVM MMU whether or not a particular GFN should be backed by private memory or not. Forward these page state change requests to userspace so that it can issue the expected KVM ioctls. The KVM MMU will handle updating the RMP entries when it is ready to map a private page into a guest. 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 44fdcf407759..2afc59b86b91 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -3233,6 +3233,15 @@ static void set_ghcb_msr(struct vcpu_svm *svm, u64 value) svm->vmcb->control.ghcb_gpa = value; } +static int snp_complete_psc_msr_protocol(struct kvm_vcpu *vcpu) +{ + struct vcpu_svm *svm = to_svm(vcpu); + + set_ghcb_msr(svm, vcpu->run->vmgexit.ghcb_msr); + + return 1; /* resume */ +} + static int sev_handle_vmgexit_msr_protocol(struct vcpu_svm *svm) { struct vmcb_control_area *control = &svm->vmcb->control; @@ -3333,6 +3342,13 @@ static int sev_handle_vmgexit_msr_protocol(struct vcpu_svm *svm) GHCB_MSR_INFO_POS); break; } + case GHCB_MSR_PSC_REQ: + vcpu->run->exit_reason = KVM_EXIT_VMGEXIT; + vcpu->run->vmgexit.ghcb_msr = control->ghcb_gpa; + vcpu->arch.complete_userspace_io = snp_complete_psc_msr_protocol; + + ret = -1; + break; case GHCB_MSR_TERM_REQ: { u64 reason_set, reason_code;