Received: by 2002:a05:6500:1b41:b0:1fb:d597:ff75 with SMTP id cz1csp436956lqb; Tue, 4 Jun 2024 16:37:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU9xbTeGj7ZnyIbujnMA9Vd+bTwlVFT8DlC1o59vgU8WkEvZZOkAJuyiPWOzb+cJihnARJ9Cf+Mp3b2kfUOwcDzrBbuGp6WjVnRgy/Tgg== X-Google-Smtp-Source: AGHT+IETiBygZyYsJa1Ftu+70XHL85FTF2R+ylGYOyDfC+pTzb2LFEeFIrTpHheAw8hAj+KRXuVs X-Received: by 2002:a05:6a00:b55:b0:6f8:c94f:578a with SMTP id d2e1a72fcca58-703e4d077fdmr1592555b3a.12.1717544256763; Tue, 04 Jun 2024 16:37:36 -0700 (PDT) Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d2e1a72fcca58-7025f2caaf0si5984075b3a.197.2024.06.04.16.37.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 16:37:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-201551-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=vgyjDDEJ; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-201551-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201551-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 647AE284849 for ; Tue, 4 Jun 2024 23:36:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A49E114D6ED; Tue, 4 Jun 2024 23:36:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="vgyjDDEJ" Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2079.outbound.protection.outlook.com [40.107.244.79]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CCA6BA5F; Tue, 4 Jun 2024 23:36:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.79 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717544172; cv=fail; b=PJtKEvilv922ZVqcDWXwNbetU8yIeo2ebuJVQGqiOhjVPBRCiB7Xh7dAfnodlmnJ/b3U/8hfucQJKIn4cxnlzt7BY9dUWtfkosNXDx4Km6xs2c7viWA5BEDDMha8mawTrnhCRk3SQjc3tbtGwv46leBUxG/MthxheIxWLMpcFGs= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717544172; c=relaxed/simple; bh=XqCZtA1ajN6WWkL9IxIz7HIO5f6zzWzPpu5nt3aHEGc=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=CQW0hnno0+UmqW9Jc0wwOYZEVeGMVtDuvEuQzb46Am0h3bBPDvq8s1JBGbBy1VIiZpSzK1ksTy50zd6v9eR26HUal/F1QZ1yFibxucW7e6RW/0NDyhwYSjPvioCQAhrtUvNd7Yhf656WRddo4A19+G9YabMS+3Fr7c1bAqv9ETs= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=vgyjDDEJ; arc=fail smtp.client-ip=40.107.244.79 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Oe0/T6Ee1nLhq9ynYUYvmpsqFVuAFM7zy1p7BblTIju4YY056ClMZ7YW40Np5HH4dqaHLZat2ujCdUYNWi7C5i0yxifbY5ILsdElTbykspB0qeKf6MeZBYPZuodxOklivqeE91pZpiPIgdCoKQuVsBk19G/ETPP1GZFql9KgOFEGOi/XTgJSr5e9XfZ2+vdcICsLSuWCXVVJYpxZI18JgVSwiUtbUd4lccWPF1u2znO/DxeBmoL3AY0PgvrHHx5JHygwgEN95DU7cz4w8hUGE3+TiP6uUST7sul+TaqejMLP4+udtwN/IqYJCAR85XhQmH6Zo7Az9YhEPRVoQOptoQ== 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=WlJuFPyzInGvjwzIXd5Ue7xI01aVNNrNGuSeH9SRUA4=; b=HpWAfpWLf9zUANsckwnOSFqnxp5q5PdBtemiGU2EqpcVKn6dLXI9SSZwCUiuakVrwl9dBW7vKkcUedeBCks9VPknOf9hBcnokLDksRIdpDwtBMpHYdtW3BIpgl7TGYYVoMvAMi3CDvICX2WI5ZpuImmu3hRWC7xujy98NMH/ltKtVPYp3SsTMpWrvvBHPsFtkCRY0TK8Z3TPo9824lcuSagiKO2Ghds+HpfWocJ2bQG0q1v95T2hXnOXfp24nMt+4UvbhvTRVp9fnEr6IcGwO8JhRTD9U24CtYZWi94Tho42IKybGXQaCXiOIZSLnJqO+ui14maNEp7lJ2hPcWny4Q== 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 (0) 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=WlJuFPyzInGvjwzIXd5Ue7xI01aVNNrNGuSeH9SRUA4=; b=vgyjDDEJsoeQ4XsdwwJRx0b6O5PTLcbmpJ978RTCdFCwoDBG2L5Ggy9fDOBuChfm8kqMCt9WNzoT5I9sBOdoB7eTeE1olTy9c01SXWmnGihV1oZNpya7GRvjDNAkLF/m1tfqaatDbVyL+M4jOl7uvz0Oxz3Yb1L0KA54WmzHAFQ= Received: from MN2PR17CA0023.namprd17.prod.outlook.com (2603:10b6:208:15e::36) by IA0PR12MB8326.namprd12.prod.outlook.com (2603:10b6:208:40d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7611.26; Tue, 4 Jun 2024 23:36:07 +0000 Received: from BL6PEPF0002256E.namprd02.prod.outlook.com (2603:10b6:208:15e:cafe::dd) by MN2PR17CA0023.outlook.office365.com (2603:10b6:208:15e::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.28 via Frontend Transport; Tue, 4 Jun 2024 23:36:07 +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 BL6PEPF0002256E.mail.protection.outlook.com (10.167.249.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7633.15 via Frontend Transport; Tue, 4 Jun 2024 23:36:06 +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.35; Tue, 4 Jun 2024 18:36:06 -0500 From: Michael Roth To: CC: , Paolo Bonzini , "Sean Christopherson" , Ravi Bangoria , Nikunj A Dadhania , Srikanth Aithal Subject: [PATCH] KVM: SEV-ES: Fix svm_get_msr()/svm_set_msr() for KVM_SEV_ES_INIT guests Date: Tue, 4 Jun 2024 18:35:10 -0500 Message-ID: <20240604233510.764949-1-michael.roth@amd.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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: BL6PEPF0002256E:EE_|IA0PR12MB8326:EE_ X-MS-Office365-Filtering-Correlation-Id: 6b1b105c-6dcb-48a0-776e-08dc84ef1b55 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|36860700004|82310400017|1800799015; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?zn+jjbTl2UmdBCcWwRr/fh4UqqFxIc29n3OmvDR147j4cMKgybiPO6skBf06?= =?us-ascii?Q?qOF0c/RgjslQlKkc7iM1ZJ6Tfk+Me2s9dXXXSuQz7Lpwz5rO3HM+wr1Ck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8Q8u7Itb8TcEfH76S9aAfn?= =?us-ascii?Q?i2ivlSRB1IZ/G1kHD10hPJjE9SZS8APrme9EmEuOLI5vpH9NVIkhZ8BtmO8n?= =?us-ascii?Q?Lv1ERIRqIB5BxKZu3rhfb5wAv61r/MffoqAFAsX8o6GAUc8qU2viM1w6baFh?= =?us-ascii?Q?OewNQLg+gZyQZzBCQKZf4zaGFmXh5BTQahCgqqk/7eOG07gtWieTeQAhSsuQ?= =?us-ascii?Q?ZT2QWJUs/MbKBFHSN3Sp1djYjBe990PkTbJ2AuiCIyf70nmIPSk/oX7LYoAJ?= =?us-ascii?Q?i2reSs+qo/vJX5BawG/8sOe2FmSzPD63EobJqu5d5XEVViuUHjP6pPsTs10H?= =?us-ascii?Q?EXzkx2Ls15mIPIkBKwZnvpYwK5magOStSf7AsLIy8dOBlrc7JWRamGxXLIMK?= =?us-ascii?Q?Iht7guk=3D?= 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)(376005)(36860700004)(82310400017)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jun 2024 23:36:06.9622 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6b1b105c-6dcb-48a0-776e-08dc84ef1b55 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: BL6PEPF0002256E.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8326 With commit 27bd5fdc24c0 ("KVM: SEV-ES: Prevent MSR access post VMSA encryption"), older VMMs like QEMU 9.0 and older will fail when booting SEV-ES guests with something like the following error: qemu-system-x86_64: error: failed to get MSR 0x174 qemu-system-x86_64: ../qemu.git/target/i386/kvm/kvm.c:3950: kvm_get_msrs: Assertion `ret == cpu->kvm_msr_buf->nmsrs' failed. This is because older VMMs that might still call svm_get_msr()/svm_set_msr() for SEV-ES guests after guest boot even if those interfaces were essentially just noops because of the vCPU state being encrypted and stored separately in the VMSA. Now those VMMs will get an -EINVAL and generally crash. Newer VMMs that are aware of KVM_SEV_INIT2 however are already aware of the stricter limitations of what vCPU state can be sync'd during guest run-time, so newer QEMU for instance will work both for legacy KVM_SEV_ES_INIT interface as well as KVM_SEV_INIT2. So when using KVM_SEV_INIT2 it's okay to assume userspace can deal with -EINVAL, whereas for legacy KVM_SEV_ES_INIT the kernel might be dealing with either an older VMM and so it needs to assume that returning -EINVAL might break the VMM. Address this by only returning -EINVAL if the guest was started with KVM_SEV_INIT2. Otherwise, just silently return. Cc: Ravi Bangoria Cc: Nikunj A Dadhania Reported-by: Srikanth Aithal Closes: https://lore.kernel.org/lkml/37usuu4yu4ok7be2hqexhmcyopluuiqj3k266z4gajc2rcj4yo@eujb23qc3zcm/ Fixes: 27bd5fdc24c0 ("KVM: SEV-ES: Prevent MSR access post VMSA encryption") Signed-off-by: Michael Roth --- arch/x86/kvm/svm/svm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index b252a2732b6f..c58da281f14f 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -2855,7 +2855,7 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) if (sev_es_prevent_msr_access(vcpu, msr_info)) { msr_info->data = 0; - return -EINVAL; + return vcpu->kvm->arch.has_protected_state ? -EINVAL : 0; } switch (msr_info->index) { @@ -3010,7 +3010,7 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr) u64 data = msr->data; if (sev_es_prevent_msr_access(vcpu, msr)) - return -EINVAL; + return vcpu->kvm->arch.has_protected_state ? -EINVAL : 0; switch (ecx) { case MSR_AMD64_TSC_RATIO: -- 2.43.0