Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp4019816pxb; Tue, 17 Nov 2020 09:13:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJw7LOH9pZHiET8MSO/7rLPiHXGH+fKqKgEAe/YYfxf8lW/VDGMQ5U84Jgeuf/Xj2o8H+Ubq X-Received: by 2002:a17:906:1183:: with SMTP id n3mr20099376eja.188.1605633238619; Tue, 17 Nov 2020 09:13:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1605633238; cv=pass; d=google.com; s=arc-20160816; b=C+N/+ktF3PTLTTCGJU5Mm+KTyraTxSA1lThCR7AAgo67b5zgJJ+orXf8PbS7hdjsHO iE8pO4+OB4UGCHH0U/mQ2pvmKlsk82kHj+IHjpDjPR0EH5oftRKMEGwBwF/muG43rJz2 H/0tjeO9WmSSZYRdPOJUa6OH9fDurhEBQowhdHkuOWqJ5RdM8Sou8emQ3QKlyxJmn/Jy eqgdEkslwv19T/L99Qg9bQDTTxx4CS0Tf2dTtWGYMXHruskJz/Q8s4hV9NcpsXJY3TwF +ywykjpyrlzz/1fHfrEOqRf5pjruvwkijMDCRXdxNLqUibPc/UBMu1SGqn2RKmI9jYHL v+Cg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Pz6XKK5knHG3n+HFC+WTUWLA+DRNa2OYCXiU9WPJ3EU=; b=YAnMENqkG44otLklw0wdevLkVpTpkAvkQ1H2FfJnVyDofI6cMTics+bI4zNqzAN9od 9m9R1UK1LnnNej6hy7cYO9xmuwLLbGrbnuBBClH6CwsiBCYZxv1eEEtcpxHG7xh92WTb UFgaxYZLf/VGmzF/69/PXnfg04Yr5lzH6qQtRI+rD7UaAIH539Pf0K6fgnLvgsN0plYB xbcL36Nog6Ek+i9L1RlEHyro/FEQT3eFfS98G7KpSVASDP22wxJUu2AcAZRsdMd0tQ2L sdVTRkRzJdjt/00Fj+VaYKNW+InwOE00aZdkwSPbfyqf4zRU2/caoHwBH3/sXxZY4EC/ iZ0w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=xVhUOSVO; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m30si14046779edj.103.2020.11.17.09.13.34; Tue, 17 Nov 2020 09:13:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=xVhUOSVO; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728530AbgKQRI5 (ORCPT + 99 others); Tue, 17 Nov 2020 12:08:57 -0500 Received: from mail-dm6nam11on2052.outbound.protection.outlook.com ([40.107.223.52]:19136 "EHLO NAM11-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728487AbgKQRI4 (ORCPT ); Tue, 17 Nov 2020 12:08:56 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MxWK0M6WK7elXd6ZThcqyTRcI892/PO5uMFQTn1WdnzSNyZJ1J2s2G9dxBwuqUX8LSaXayS3MpL9CGdju36emaoEpodO+A/Fy2W7m9OdbagdcAu3sHm0vFtdp68lmu93bp82OHIB/O/N6Wfs/nw2L69lfadQciO/HzjCIZlN3M2DJL+cibF87NETAZhMsKGjsfdKyBhDGNIKZX6Qfw35vH7Z+59qvcs6M5OHjTNOfWZBpGinjxPrxAtNX214Req70B6OR8Zv/5w0qo1Myr+nd0nyR2wB/6bkXPeiiRWsaqMExGcUSYIRhf65I4VpK60qQ+eSoaJPOS4VQUtaaJ/xAw== 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=Pz6XKK5knHG3n+HFC+WTUWLA+DRNa2OYCXiU9WPJ3EU=; b=bGF7M0ohnu3fXX19waYvWCYWMgSABELSLGsLl0Wl8XnY1fU7do6vr3pSPDi08/2vKEd5+QFrP7XPlqXluNjaYVgomUpmutOGryZIhb8w/J4h+8atrACjqxNMZVeYq/dbA4O4rRPQ2lAWSjcjVD2Ur9wGLno7vd02XoARbc4P6n7EbiJpOs6x22pkReAzraBSUSVk1pCf7unFYCTz9C5ifvxnzcsID91+B+l9WFYyg33v6nRN5nbIQiLKHxEwvJpvid7gA7WagFoq6YpUAYvtB/Ws+r0IX3KLFUTZL42mTdZes7sNSTcX8p9go7WfgccQSTEyOLTo/lEofD1t1g0/uA== 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=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Pz6XKK5knHG3n+HFC+WTUWLA+DRNa2OYCXiU9WPJ3EU=; b=xVhUOSVOrknXFZGLh6BJLKoS/KXFXZ8kXcw5qtn2ITRZbJeA/jtw4JxqTfG2yXrCanvUP+IxyOlK3li9+nDdEE5dVRTgOhwP9qNYuA0Az8J9Ay5jycG9QFRbk5yRBUHPTosCL0uv/kCqfZdLv9VDEBQltEe0Jkmo3K24hMTX6II= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM5PR12MB1772.namprd12.prod.outlook.com (2603:10b6:3:107::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3541.25; Tue, 17 Nov 2020 17:08:51 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::dcda:c3e8:2386:e7fe]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::dcda:c3e8:2386:e7fe%12]) with mapi id 15.20.3564.028; Tue, 17 Nov 2020 17:08:51 +0000 From: Tom Lendacky To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org Cc: Paolo Bonzini , Jim Mattson , Joerg Roedel , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Borislav Petkov , Ingo Molnar , Thomas Gleixner , Brijesh Singh Subject: [PATCH v4 08/34] KVM: SVM: Prevent debugging under SEV-ES Date: Tue, 17 Nov 2020 11:07:11 -0600 Message-Id: X-Mailer: git-send-email 2.28.0 In-Reply-To: References: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: DM6PR14CA0054.namprd14.prod.outlook.com (2603:10b6:5:18f::31) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from tlendack-t1.amd.com (165.204.77.1) by DM6PR14CA0054.namprd14.prod.outlook.com (2603:10b6:5:18f::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3589.20 via Frontend Transport; Tue, 17 Nov 2020 17:08:50 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: de351532-4d12-4cef-3f1d-08d88b1b74a2 X-MS-TrafficTypeDiagnostic: DM5PR12MB1772: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1002; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nnpHNu1hv9ikOrELYOI8/Z2TXlUXJxr27TW1Joqlem4dAyZu1F7e1DpsMGVkNy6RKtacr62h3wc5IE82ZfNQAhK1oKNQUqQAu8yJVytlLbvKdxdGP5KhLcmuAT0EmMjqn7Z9D+lLtmb21XhXM50PYJxcaQpivv/aItVbE3rixKs5UEztIff9D1RuDsmYOS4widyO4t/xM5G/4sXJNuObsxUW0SmngSrCouJFPy9AYXWTGebP+hn9mCH4DGSJqDUTYdox0Tk+AmPN04+6ABDSdMQDtYKUqMHkX+jdUgyripXBYncFBZif2eQOSPIP6Kq4N10otONpYLb3kZx5BqpRhQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR12MB1355.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(366004)(346002)(376002)(39860400002)(136003)(6486002)(66476007)(66946007)(8936002)(83380400001)(5660300002)(26005)(478600001)(66556008)(16526019)(6666004)(186003)(36756003)(86362001)(8676002)(316002)(956004)(52116002)(4326008)(54906003)(7696005)(7416002)(2616005)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: DZZOSluKAEUJvS/JxzJpWbPZq01JWr0WTjTcq/fOMhyqw1lRCdZeB/OTzTwTrMWx2BQ8zxrk56uZOM7G8MOBeucROnM6pV7vk7Bon+KpzVt2KYgwreIpXSSxf9GyiZMP7qf9uxt0e6+0B2stz59SAlcw/gZBsuOppS+Vr12FNShUraqepGanf11yaVmmenrH/ZX7jcyXmdv8cwVy3YtLYnJc/ODtRtEuN7qdQb8yZYYugQbvWzYWgemNoMtxNKoK9aNM02DHDt0J9J83UXwRrGYAqffiI6bBzAgzT0U67nVW81D0NC20N803OeBL/0k7zF2lEh0sezzuBsGnHtLcjN7kLXk6+ggOYWFK8CvPG2/0OKV1k8ogtchcF4+fRcEXHqJcpHY6x2nd3tvwaRddZ/xG0AE6G2PdqnRXE9bvKa+RQNXg/WcIP+CammlbMLCu3UxCtHaupzN6KX41N6HqcvjVyZFpADsItRqS0QISkHcpXnWJbdDoW7ixX5Tf5TeBAVYbwXMYmcTVEZZRKFX6H60a+rxDbdcTefLysVNZmpTQ7Yhw7KFBTpV+XxEv3+d1Rwf4Cql3UbbIGrqm2vkzVxJmY/eYIUsDSjJ/DSXLQC/sZdzRVA9j8kZxK/QN3ZjrTRGjsBrwRQ+Lk+JlCVUUuw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: de351532-4d12-4cef-3f1d-08d88b1b74a2 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Nov 2020 17:08:51.1992 (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: UCueKn2sYpsl87ojK4rZxDplu4DLI4wqlXSmeH++u2+bnK+8tvky8bpf+jFm+ySdCJXwoqJ7BIqqe+ZYgZtdsg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1772 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tom Lendacky Since the guest register state of an SEV-ES guest is encrypted, debugging is not supported. Update the code to prevent guest debugging when the guest has protected state. Additionally, an SEV-ES guest must only and always intercept DR7 reads and writes. Update set_dr_intercepts() and clr_dr_intercepts() to account for this. Signed-off-by: Tom Lendacky --- arch/x86/kvm/svm/svm.c | 9 +++++ arch/x86/kvm/svm/svm.h | 81 +++++++++++++++++++++++------------------- arch/x86/kvm/x86.c | 3 ++ 3 files changed, 57 insertions(+), 36 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 9a3d57ed997f..7f805cd5bbe7 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -1802,6 +1802,9 @@ static void svm_set_dr6(struct vcpu_svm *svm, unsigned long value) { struct vmcb *vmcb = svm->vmcb; + if (svm->vcpu.arch.guest_state_protected) + return; + if (unlikely(value != vmcb->save.dr6)) { vmcb->save.dr6 = value; vmcb_mark_dirty(vmcb, VMCB_DR); @@ -1812,6 +1815,9 @@ static void svm_sync_dirty_debug_regs(struct kvm_vcpu *vcpu) { struct vcpu_svm *svm = to_svm(vcpu); + if (vcpu->arch.guest_state_protected) + return; + get_debugreg(vcpu->arch.db[0], 0); get_debugreg(vcpu->arch.db[1], 1); get_debugreg(vcpu->arch.db[2], 2); @@ -1830,6 +1836,9 @@ static void svm_set_dr7(struct kvm_vcpu *vcpu, unsigned long value) { struct vcpu_svm *svm = to_svm(vcpu); + if (vcpu->arch.guest_state_protected) + return; + svm->vmcb->save.dr7 = value; vmcb_mark_dirty(svm->vmcb, VMCB_DR); } diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 8f0a3ed0d790..66ea889f71ed 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -198,6 +198,28 @@ static inline struct kvm_svm *to_kvm_svm(struct kvm *kvm) return container_of(kvm, struct kvm_svm, kvm); } +static inline bool sev_guest(struct kvm *kvm) +{ +#ifdef CONFIG_KVM_AMD_SEV + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + + return sev->active; +#else + return false; +#endif +} + +static inline bool sev_es_guest(struct kvm *kvm) +{ +#ifdef CONFIG_KVM_AMD_SEV + struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; + + return sev_guest(kvm) && sev->es_active; +#else + return false; +#endif +} + static inline void vmcb_mark_all_dirty(struct vmcb *vmcb) { vmcb->control.clean = 0; @@ -249,21 +271,24 @@ static inline void set_dr_intercepts(struct vcpu_svm *svm) { struct vmcb *vmcb = get_host_vmcb(svm); - vmcb_set_intercept(&vmcb->control, INTERCEPT_DR0_READ); - vmcb_set_intercept(&vmcb->control, INTERCEPT_DR1_READ); - vmcb_set_intercept(&vmcb->control, INTERCEPT_DR2_READ); - vmcb_set_intercept(&vmcb->control, INTERCEPT_DR3_READ); - vmcb_set_intercept(&vmcb->control, INTERCEPT_DR4_READ); - vmcb_set_intercept(&vmcb->control, INTERCEPT_DR5_READ); - vmcb_set_intercept(&vmcb->control, INTERCEPT_DR6_READ); + if (!sev_es_guest(svm->vcpu.kvm)) { + vmcb_set_intercept(&vmcb->control, INTERCEPT_DR0_READ); + vmcb_set_intercept(&vmcb->control, INTERCEPT_DR1_READ); + vmcb_set_intercept(&vmcb->control, INTERCEPT_DR2_READ); + vmcb_set_intercept(&vmcb->control, INTERCEPT_DR3_READ); + vmcb_set_intercept(&vmcb->control, INTERCEPT_DR4_READ); + vmcb_set_intercept(&vmcb->control, INTERCEPT_DR5_READ); + vmcb_set_intercept(&vmcb->control, INTERCEPT_DR6_READ); + vmcb_set_intercept(&vmcb->control, INTERCEPT_DR0_WRITE); + vmcb_set_intercept(&vmcb->control, INTERCEPT_DR1_WRITE); + vmcb_set_intercept(&vmcb->control, INTERCEPT_DR2_WRITE); + vmcb_set_intercept(&vmcb->control, INTERCEPT_DR3_WRITE); + vmcb_set_intercept(&vmcb->control, INTERCEPT_DR4_WRITE); + vmcb_set_intercept(&vmcb->control, INTERCEPT_DR5_WRITE); + vmcb_set_intercept(&vmcb->control, INTERCEPT_DR6_WRITE); + } + vmcb_set_intercept(&vmcb->control, INTERCEPT_DR7_READ); - vmcb_set_intercept(&vmcb->control, INTERCEPT_DR0_WRITE); - vmcb_set_intercept(&vmcb->control, INTERCEPT_DR1_WRITE); - vmcb_set_intercept(&vmcb->control, INTERCEPT_DR2_WRITE); - vmcb_set_intercept(&vmcb->control, INTERCEPT_DR3_WRITE); - vmcb_set_intercept(&vmcb->control, INTERCEPT_DR4_WRITE); - vmcb_set_intercept(&vmcb->control, INTERCEPT_DR5_WRITE); - vmcb_set_intercept(&vmcb->control, INTERCEPT_DR6_WRITE); vmcb_set_intercept(&vmcb->control, INTERCEPT_DR7_WRITE); recalc_intercepts(svm); @@ -275,6 +300,12 @@ static inline void clr_dr_intercepts(struct vcpu_svm *svm) vmcb->control.intercepts[INTERCEPT_DR] = 0; + /* DR7 access must remain intercepted for an SEV-ES guest */ + if (sev_es_guest(svm->vcpu.kvm)) { + vmcb_set_intercept(&vmcb->control, INTERCEPT_DR7_READ); + vmcb_set_intercept(&vmcb->control, INTERCEPT_DR7_WRITE); + } + recalc_intercepts(svm); } @@ -480,28 +511,6 @@ void svm_vcpu_unblocking(struct kvm_vcpu *vcpu); extern unsigned int max_sev_asid; -static inline bool sev_guest(struct kvm *kvm) -{ -#ifdef CONFIG_KVM_AMD_SEV - struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; - - return sev->active; -#else - return false; -#endif -} - -static inline bool sev_es_guest(struct kvm *kvm) -{ -#ifdef CONFIG_KVM_AMD_SEV - struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info; - - return sev_guest(kvm) && sev->es_active; -#else - return false; -#endif -} - static inline bool svm_sev_enabled(void) { return IS_ENABLED(CONFIG_KVM_AMD_SEV) ? max_sev_asid : 0; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 3aafbd2540be..569fbdb4ee87 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -9663,6 +9663,9 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, unsigned long rflags; int i, r; + if (vcpu->arch.guest_state_protected) + return -EINVAL; + vcpu_load(vcpu); if (dbg->control & (KVM_GUESTDBG_INJECT_DB | KVM_GUESTDBG_INJECT_BP)) { -- 2.28.0