Received: by 2002:a05:6500:1b41:b0:1fb:d597:ff75 with SMTP id cz1csp425928lqb; Tue, 4 Jun 2024 16:10:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUnWvphNMRQIp3FW+sJHujdUWuze7drcNJdriKTK814w0qM0N8jVIdZGRJIe8oxcO1eM8+zmzMDuMtrdH3AH1qZlwjoJ9T7Tcv5GVd+fg== X-Google-Smtp-Source: AGHT+IEvpP+OvrNaTcAUzqHcx6P0KxL9LJEob5dWbMdgTX2CR76cr+Rn4lyNzRfmyjGtq9Imohvm X-Received: by 2002:a50:d6d8:0:b0:578:5771:dc2c with SMTP id 4fb4d7f45d1cf-57a8b69d84amr670461a12.3.1717542640307; Tue, 04 Jun 2024 16:10:40 -0700 (PDT) Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57a31b80d80si5483362a12.86.2024.06.04.16.10.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 16:10:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-201535-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@amd.com header.s=selector1 header.b=I1SCBCKM; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-201535-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201535-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (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 am.mirrors.kernel.org (Postfix) with ESMTPS id CD5781F2390A for ; Tue, 4 Jun 2024 23:10:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5814614D45E; Tue, 4 Jun 2024 23:10:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amd.com header.i=@amd.com header.b="I1SCBCKM" Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2047.outbound.protection.outlook.com [40.107.94.47]) (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 7996314B077; Tue, 4 Jun 2024 23:10:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.47 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717542626; cv=fail; b=LD0QQKXWHfuuTF4GgT+FR7QEdJVs1rwJnjR5xo/QiKmdG2d2ZCXI9W59PQ1veinIfxnKFTEcpXYlkAlS0h2TXyurzjwo10nbLZ2sN01Z2EaNhS0kbKYNFwOhqJ1SL8pCHoWgsy1L9s3OVSHoR6k1M+seGgWv4yk9zd+35JScfJM= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717542626; c=relaxed/simple; bh=fdjEyX59p5xIs0REzL+hmBjiVWCxZVCWnwALt6zKejE=; h=Date:From:To:CC:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=B7TJAGqS2d46LP6Io/TP1NabHGwkIDM+GLj5EdTZ0XF131CRFtIiSirGVC8PsIjdhg/l84qfoLjSKJMvu1Z7cG2eKpbkSOLdL4Oc+W71KkNQXv63TrKdqA2hzIIlpZBlg5BGGIF5J36bIfchdrAeMII+5aHQsp12Rs/7e+cWnaA= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=fail (1024-bit key) header.d=amd.com header.i=@amd.com header.b=I1SCBCKM reason="signature verification failed"; arc=fail smtp.client-ip=40.107.94.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (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=XoPktVgQDojkrgt5r+RQaMqIiIMnZbcXbJcxg5Z2cuZF3N6NVSK0fRGJaKvjILGI9NJUUmF6mgTdVrm3FTAKBOgUjvlWagrROnBIlamzCWGNP8SUjoIZC4vnsg3SyYA1mH9LqhGr2h70OQojMaK1yz5puPPp07yd16yz5EyGFWjNhcUhfSeMDHSPUwbGNw3m3s6u7VkvmreXcdBvBbT5EZ7X2CktkVckeQP/7h3pTANCM+bL6zGpCRKVZlckdxh3/kslvu7njdv+BO7nufPwh8D85WNx9snx1wne/5HcJ9ro+xuXTjd0CAbXJiupf3GpMxeDGJFlf5ZdVyIjcKgyuA== 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=AZK6BewWgvIvT6+tk6GAwnInJZuFFKdjVRF383/RKxk=; b=QVwhmWfw08yKkMPZgyYb/zE5QKFmpuZ2C9LsjwVB06/SvrFaXPfrRls/TWL1M15Am/XZPx5RObF2YQbhvTVGlDmRVEwtg2MReD5jelsSU0zLpB7WXEO8QjviuKJkOFl7eal8pqScVcC1lXsGfXyOvASFAiNW0hln2GI73D3IHz9c3TPrmhrtabZMKVNUlkCG1oiYJjXvbyx3Q2+AwBj7eWeZYkUHTrBBaSLFLiYnczgmagkqWWXjNWEBuVYPvaJg25gNPSth1ukmUSmuqUsRd2Xdyj67JkhX+I3JBKfzHc94RE5SjMpltqlh/Xd5HXKOqU6dTaLg1xJPNWifaO729Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com 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=AZK6BewWgvIvT6+tk6GAwnInJZuFFKdjVRF383/RKxk=; b=I1SCBCKMgNZGjf0CIvpFWxPNc8iMtRT0JBMNQWRpwk+Q9GG6F8cnktOjkvaN84XfDO2klW0PcGTMCS+mGzN56JYfbhdArrvRQJdA4KMZWdgdkuOcAhjm0BT7oxAYWbepOwLT1B3TLWdBB0VPcPWhrWpklTnjCBkHvwLefPMXXJE= Received: from SJ0PR13CA0097.namprd13.prod.outlook.com (2603:10b6:a03:2c5::12) by CY5PR12MB6525.namprd12.prod.outlook.com (2603:10b6:930:32::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.27; Tue, 4 Jun 2024 23:10:18 +0000 Received: from MWH0EPF000A672E.namprd04.prod.outlook.com (2603:10b6:a03:2c5:cafe::87) by SJ0PR13CA0097.outlook.office365.com (2603:10b6:a03:2c5::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7656.16 via Frontend Transport; Tue, 4 Jun 2024 23:10:18 +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 MWH0EPF000A672E.mail.protection.outlook.com (10.167.249.20) 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:10:17 +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:10:16 -0500 Date: Tue, 4 Jun 2024 18:10:02 -0500 From: Michael Roth To: Ravi Bangoria CC: Paolo Bonzini , , , , , , , , , , , , , Subject: Re: [PATCH v3 1/3] KVM: SEV-ES: Prevent MSR access post VMSA encryption Message-ID: <37usuu4yu4ok7be2hqexhmcyopluuiqj3k266z4gajc2rcj4yo@eujb23qc3zcm> References: <20240523121828.808-1-ravi.bangoria@amd.com> <20240523121828.808-2-ravi.bangoria@amd.com> <3eca1e7e-9ddc-47a2-b214-d8788a069222@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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: MWH0EPF000A672E:EE_|CY5PR12MB6525:EE_ X-MS-Office365-Filtering-Correlation-Id: 92d4fe89-946a-40ab-cb94-08dc84eb8007 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|36860700004|7416005|376005|82310400017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KcxkDqqXZkaNGWXJ521tc8HLoioHDxbcfBWUZQRvEngPfA0hexC?= =?iso-8859-1?Q?GuBT3q6FjJ8G5eX5/Sb0ug9hzxopJSzMvOfSuqs0ksacz1IpVYfxL86OHT?= =?iso-8859-1?Q?Q8D6bxxgyHHKnZMWXdDwcHzi6y8HcfO5gOE76i+jDk4dERxGFiMJYf9pFv?= =?iso-8859-1?Q?cAVwT6GWbMjcmCSbiYjiZMb4ZPPylSv3V3/VAkkxzXQMaMH3RkavQR48Uf?= =?iso-8859-1?Q?lqncgT//JiqpJSfxQmq0d32XOFPWUalJgIRmjmUWnIp2yNVTsoq5ySkrDI?= =?iso-8859-1?Q?2zzeYOpvbOrE4Nn8s9HC6q4Hh/xDRlQb/6Ss7ca51pUJhJiIdbmEFTw04/?= =?iso-8859-1?Q?VdHNHs4Y66HZ/I2L51aFN4WQYs9IiOnxcQO9BaOy0Sa1npaLpaco+BHmHw?= =?iso-8859-1?Q?k3DsWIBpFUw6yGUnsh08sIlY3lDchf7uCEKno9slQbqUkFYZfOqrxuN4oi?= =?iso-8859-1?Q?ATLfvj7VX5R1U72l34k9AKucLE473NumOkKBdKTvdhSnSyc+0Z0FWNXCJd?= =?iso-8859-1?Q?BnqaJgVaKCi8KjM6YnL2w5EJjdXtN0hKgevS1/PBaOzJBIq52p4hvlHMwK?= =?iso-8859-1?Q?eMG/2rD0S2f4kdzH?= 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)(1800799015)(36860700004)(7416005)(376005)(82310400017);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jun 2024 23:10:17.7599 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 92d4fe89-946a-40ab-cb94-08dc84eb8007 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: MWH0EPF000A672E.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6525 On Wed, May 29, 2024 at 04:14:10PM +0530, Ravi Bangoria wrote: > On 5/28/2024 10:01 PM, Paolo Bonzini wrote: > > On 5/23/24 14:18, Ravi Bangoria wrote: > >> From: Nikunj A Dadhania > >> > >> KVM currently allows userspace to read/write MSRs even after the VMSA is > >> encrypted. This can cause unintentional issues if MSR access has side- > >> effects. For ex, while migrating a guest, userspace could attempt to > >> migrate MSR_IA32_DEBUGCTLMSR and end up unintentionally disabling LBRV on > >> the target. Fix this by preventing access to those MSRs which are context > >> switched via the VMSA, once the VMSA is encrypted. > >> > >> Suggested-by: Sean Christopherson > >> Signed-off-by: Nikunj A Dadhania > >> Signed-off-by: Ravi Bangoria > >> --- > >> ? arch/x86/kvm/svm/svm.c | 18 ++++++++++++++++++ > >> ? 1 file changed, 18 insertions(+) > >> > >> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c > >> index 3d0549ca246f..489b0183f37d 100644 > >> --- a/arch/x86/kvm/svm/svm.c > >> +++ b/arch/x86/kvm/svm/svm.c > >> @@ -2834,10 +2834,24 @@ static int svm_get_msr_feature(struct kvm_msr_entry *msr) > >> ????? return 0; > >> ? } > >> ? +static bool > >> +sev_es_prevent_msr_access(struct kvm_vcpu *vcpu, struct msr_data *msr_info) > >> +{ > >> +??? return sev_es_guest(vcpu->kvm) && > >> +?????????? vcpu->arch.guest_state_protected && > >> +?????????? svm_msrpm_offset(msr_info->index) != MSR_INVALID && > >> +?????????? !msr_write_intercepted(vcpu, msr_info->index); > >> +} > >> + > >> ? static int svm_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) > >> ? { > >> ????? struct vcpu_svm *svm = to_svm(vcpu); > >> ? +??? if (sev_es_prevent_msr_access(vcpu, msr_info)) { > >> +??????? msr_info->data = 0; > >> +??????? return 0; > > > > This should return -EINVAL, not 0.? Likewise below in svm_set_msr(). > > Sure. One consequence of this change is that older VMMs that might still call svm_get_msr()/svm_set_msr() for SEV-ES guests. 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 we sort of have to assume the VMM does not have the necessary changes to deal with -EINVAL, so in that case it's probably more appropriate to return 0 and just silently noop. We had a similar situations with stricter limitations on fpstate sync'ing for KVM_SEV_INIT2 and that was the approach taken there: https://lore.kernel.org/kvm/ZfRhu0GVjWeAAJMB@google.com/ so I'll submit a patch that takes the same approach. -Mike > > Thanks, > Ravi