Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp234161pxu; Fri, 11 Dec 2020 00:37:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJz4PQzDPJNV+BScuGnPqlrexk7c/uQhf6boIbYYr2p15YhfbliMbtpW7sYu4hmJRM6F4IH9 X-Received: by 2002:a05:6402:16c8:: with SMTP id r8mr10503872edx.59.1607675869031; Fri, 11 Dec 2020 00:37:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1607675869; cv=pass; d=google.com; s=arc-20160816; b=Cv7lqV2wtdkMMacUSZCayU9xPoqnO2UNF7tzHgePOLRJvVQkes6DlKpDtEvYOA23z5 yyRVTGu78zlfDDvJJZx7au2yWttorW94DvbxjSDARhae88v0qdMZorypA6KY6KjEyelQ 5WD2mMQ+AeUPx8vc/7IKIcFoOp9nZI53jSGXRe//NcXw0UsO9kuzubgd7zHAQlTcBGex VuJjTQw0KIAHUPO/RSQAqgTolhBmj2iNJcoBO2MGHYhVeEu4nskTEKupIhnVJzqdgThc H4sqCJwqhnvJK9VuQtYTcXXEpfApua55d6zi7WdwY1jJAtQrtYbbMEzp7t/2jTc+faAs Z2eQ== 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=vMSAUbVqemGru/527gfru/9I+K7McdmSIs5VZm1ec6c=; b=hGJweI2fy2k66eqYgZ7Z3Ci1fLx5FJ/vNu17IPRuq/11zQ0GnL7It+unWF4qC2BCI2 H8DtRAd8bMY9vB1tM9fBPf+avZtqmzaVE+8QxDnMPXeh0KEflVwgGA1nBs6nR8EsDwgr N1LFPXxOl1LCoH83i66sU8tdPGw7VzNq7j/sZJ3hekjfGn26vdcrxrdn1GALMf/h/GY9 4LAqq1G5vIunWShQRaUSc/gmFY6CQ2ztWxyl0fvpsoL3nFV8oeNN2NbMUeQTqGe21Lew N9e42ZzrUDEdPj+ZHidFbsNWVSdxiOxtl0yru8TBmn74pLsVVtWrk1Usl3/jpl9+HYrV 4Vxg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b="vONSx/5v"; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=amd.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a7si4291778edj.215.2020.12.11.00.37.25; Fri, 11 Dec 2020 00:37:49 -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="vONSx/5v"; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388615AbgLJROM (ORCPT + 99 others); Thu, 10 Dec 2020 12:14:12 -0500 Received: from mail-dm6nam11on2069.outbound.protection.outlook.com ([40.107.223.69]:37494 "EHLO NAM11-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2390277AbgLJRNU (ORCPT ); Thu, 10 Dec 2020 12:13:20 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IODUTILQkG9egPeE0slIf0/ot4Sf8Nr0qrl+V6zZFQyLdUi4IcrQ6m+mfiedRJqm7d300sugRjwL5pbZAm/Cq/HrEsAQWmNGiiQ0FqKkwFTOaOK3J2W9XzL35rU3HWbGCvPZ1stZFaT+IlJ6a1Z93Vcc2g27v6wYcsVkj2NqAfM3D2ZR94X9D6bT7vi2fZs67uYdaMzIGGtxDHT60UqK82WjX4xRk74kY6d6za5jwyDXCIneMz5w49C+ZMvTu9C6Yz2jxce3hDnisCDB1+NTo2KLFaOHhtk7o2A6Y/+FvIjIuITVcKbiX0NSyV5l96tuzSwk9Xhhgb8pX9XDNVHUmg== 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=vMSAUbVqemGru/527gfru/9I+K7McdmSIs5VZm1ec6c=; b=LSiQPOCxs++JYfWy1fmL3L+K/BQllxuobNr9waYv38MmWj3Ck3QwuvtN60tXsvIR9E3F5r/gK/DdvYdB/mh4ihxX4MmxFP0Dk7Kb3zhjgiZzc3DwqFTBLO92ohULbwHAQ7GpmzLc/44OpdMIJwoVwT3Da10gu8AmuM8Y8gqcRAAU4Wzj4YkwEI6+U99u8KT9j58sWUNfU3Cghr38o1VVhG74IoxnxX43fp/zr2Q8ru/A/IKp5SlrWGqkRjV9nlwY462ySaTYGoFSkMNTAJed1rrhfYhGyj7ukv/8k3FMJpghKJJ3kEjDLmnjROO5sBDrtylRmPhDodBO//4imZVypQ== 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=vMSAUbVqemGru/527gfru/9I+K7McdmSIs5VZm1ec6c=; b=vONSx/5vBZ974nrqWBfBuv2ie7izTI3mHesv9m2PiUMd/NYAiTz1ETWkRfiHJBG42++5HXJ7H7CJDylmPW6Pdvzq+ojJzKsLPfYma7LYFmoZ/2fGgO9F7DhhpaqLd+B+7jtiBEBfsB1de34XxZ1I3/a8Nde9kpjwPp6EVOJGy6E= 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 CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR1201MB0168.namprd12.prod.outlook.com (2603:10b6:910:1d::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.22; Thu, 10 Dec 2020 17:12:22 +0000 Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::a10a:295e:908d:550d]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::a10a:295e:908d:550d%8]) with mapi id 15.20.3632.021; Thu, 10 Dec 2020 17:12:22 +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 v5 14/34] KVM: SVM: Add support for SEV-ES GHCB MSR protocol function 0x002 Date: Thu, 10 Dec 2020 11:09:49 -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: CH2PR18CA0049.namprd18.prod.outlook.com (2603:10b6:610:55::29) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from tlendack-t1.amd.com (165.204.77.1) by CH2PR18CA0049.namprd18.prod.outlook.com (2603:10b6:610:55::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3654.12 via Frontend Transport; Thu, 10 Dec 2020 17:12:20 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 07837e1c-c515-43de-74b2-08d89d2ec20e X-MS-TrafficTypeDiagnostic: CY4PR1201MB0168: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zfRzFQQAyh2/4UoRjxzBDvSDsCBXwX0DIgZg8PXoOXFQQL43vCoFa73e931MjVHoLbRPRxi6W+LIqNsRbqD73H6ViqVNSWLYUOpezY/Bgm8k52NG2KQ6zJJVkkpfx2irjlnuOzcPFanCW2sw84LRN4Y1Dehydo4M4OdZXLm4067cGVHzJp0JJDlsiBtazbKSZy5oec3yFHJA8A/eenfPy4/UGqrfCT8O9wM1oSkNpuFRoSbszR7rPHOzvU3rHrC1823+Jq87+UT1jjktCFjUcCOlqOoo0756Jnt003nSOzCtUULo/JoMEThj5hH+Seqzkv47wvJub2K5V8hzXOi6h7GSXXZod9emDecAzjPfCFLs4wfzufo374QcrqlHfFhH X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY4PR12MB1352.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(136003)(346002)(376002)(36756003)(8676002)(6486002)(4326008)(66476007)(86362001)(7416002)(66946007)(7696005)(54906003)(6666004)(26005)(16526019)(34490700003)(66556008)(8936002)(83380400001)(186003)(2906002)(2616005)(52116002)(956004)(508600001)(5660300002);DIR:OUT;SFP:1101; X-MS-Ex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W0lcmLNSPxbx69oiFiPrMzvLPNWqNvcEwAjtB88FFsw80K1WA9z?= =?us-ascii?Q?kazmcr4bTTD3l5zWOAxkehA33B20BSbqJ9dJd8xR9QyYNmtpHD75eU78MxJN?= =?us-ascii?Q?sjRXIVSxMn64l1x40TbcB3LF3eZEkfT3/4Z0erdon3Ud54heVosgBb4GGdmD?= =?us-ascii?Q?NKmu?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2020 17:12:22.1309 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-Network-Message-Id: 07837e1c-c515-43de-74b2-08d89d2ec20e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: agQAVBtkRxbqLMxHmHnalu21QDjnOfTHBHSiWjpMLyODDA8q+ER5yyQU0U9lCSjXibNwj/paFRqpNhQ/pjrtWQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1201MB0168 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tom Lendacky The GHCB specification defines a GHCB MSR protocol using the lower 12-bits of the GHCB MSR (in the hypervisor this corresponds to the GHCB GPA field in the VMCB). Function 0x002 is a request to set the GHCB MSR value to the SEV INFO as per the specification via the VMCB GHCB GPA field. Signed-off-by: Tom Lendacky --- arch/x86/kvm/svm/sev.c | 26 +++++++++++++++++++++++++- arch/x86/kvm/svm/svm.h | 17 +++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index da473c6b725e..58861515d3e3 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -22,6 +22,7 @@ #include "cpuid.h" #include "trace.h" +static u8 sev_enc_bit; static int sev_flush_asids(void); static DECLARE_RWSEM(sev_deactivate_lock); static DEFINE_MUTEX(sev_bitmap_lock); @@ -1142,6 +1143,9 @@ void __init sev_hardware_setup(void) /* Retrieve SEV CPUID information */ cpuid(0x8000001f, &eax, &ebx, &ecx, &edx); + /* Set encryption bit location for SEV-ES guests */ + sev_enc_bit = ebx & 0x3f; + /* Maximum number of encrypted guests supported simultaneously */ max_sev_asid = ecx; @@ -1500,9 +1504,29 @@ void pre_sev_run(struct vcpu_svm *svm, int cpu) vmcb_mark_dirty(svm->vmcb, VMCB_ASID); } +static void set_ghcb_msr(struct vcpu_svm *svm, u64 value) +{ + svm->vmcb->control.ghcb_gpa = value; +} + static int sev_handle_vmgexit_msr_protocol(struct vcpu_svm *svm) { - return -EINVAL; + struct vmcb_control_area *control = &svm->vmcb->control; + u64 ghcb_info; + + ghcb_info = control->ghcb_gpa & GHCB_MSR_INFO_MASK; + + switch (ghcb_info) { + case GHCB_MSR_SEV_INFO_REQ: + set_ghcb_msr(svm, GHCB_MSR_SEV_INFO(GHCB_VERSION_MAX, + GHCB_VERSION_MIN, + sev_enc_bit)); + break; + default: + return -EINVAL; + } + + return 1; } int sev_handle_vmgexit(struct vcpu_svm *svm) diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 89bcb26977e5..546f8d05e81e 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -514,9 +514,26 @@ void svm_vcpu_unblocking(struct kvm_vcpu *vcpu); /* sev.c */ +#define GHCB_VERSION_MAX 1ULL +#define GHCB_VERSION_MIN 1ULL + #define GHCB_MSR_INFO_POS 0 #define GHCB_MSR_INFO_MASK (BIT_ULL(12) - 1) +#define GHCB_MSR_SEV_INFO_RESP 0x001 +#define GHCB_MSR_SEV_INFO_REQ 0x002 +#define GHCB_MSR_VER_MAX_POS 48 +#define GHCB_MSR_VER_MAX_MASK 0xffff +#define GHCB_MSR_VER_MIN_POS 32 +#define GHCB_MSR_VER_MIN_MASK 0xffff +#define GHCB_MSR_CBIT_POS 24 +#define GHCB_MSR_CBIT_MASK 0xff +#define GHCB_MSR_SEV_INFO(_max, _min, _cbit) \ + ((((_max) & GHCB_MSR_VER_MAX_MASK) << GHCB_MSR_VER_MAX_POS) | \ + (((_min) & GHCB_MSR_VER_MIN_MASK) << GHCB_MSR_VER_MIN_POS) | \ + (((_cbit) & GHCB_MSR_CBIT_MASK) << GHCB_MSR_CBIT_POS) | \ + GHCB_MSR_SEV_INFO_RESP) + extern unsigned int max_sev_asid; static inline bool svm_sev_enabled(void) -- 2.28.0