From patchwork Wed Nov 8 11:17:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Saenz Julienne X-Patchwork-Id: 162967 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:aa0b:0:b0:403:3b70:6f57 with SMTP id k11csp843154vqo; Wed, 8 Nov 2023 03:22:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IF5qJ+hflil5WNBJWVZvSLlvn9a+y87jtGwE6/5gNZ6luZB5K6GduxkhwaICrIVV84oOAeH X-Received: by 2002:a05:6a00:9385:b0:6c2:bc81:2787 with SMTP id ka5-20020a056a00938500b006c2bc812787mr1366591pfb.6.1699442543192; Wed, 08 Nov 2023 03:22:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699442543; cv=none; d=google.com; s=arc-20160816; b=xxQVG+NJO77Opxbv9C4en8hLSHbegH/v6T1yOi3Ae2XnG4WCOf1lUWS3O1aY2oTX8z Y1W59hUqT+SL3ePT+au0ldT3AZYuvj5ig8w+zLwXHuV5aMwZtf48klN5ZJFptq098xd3 NVH+dvsEE6zG6quiI9yigrG5I3tv6lg3XLHrBo9/BX9FD4IZWzWzY1tQE5g6fJ7jX/MW kRSn+9u5kBwcdX7KF5g3K9zQ34cMtqj30VoEX+JwhAMl3X7ykBP+6BEkcpH1Dtu1E8WA HgbSaLbpJvT/bHOMhvcgF4j/mgdBoWZn/9tBMSX99yF4D4GiVUz4Jd8oh7HLjkD55bCZ dO4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7C45WW2plKc9LGS1hg04kUsdvaSyLe7Yr2kIsIf6Lys=; fh=Qdq7NqGm5JR9LpctBpXjoRI38Lb2mCk6xy26GEDp1Bg=; b=T++eo84xwgHlKxGtKsu9sCMcF783zFVZ/FddalrKUcY6z2bXSLRuDWu7whl26GVhVv znxYm5gz1WypjKUxXiq0ufaEBAZyLgPYEAHDQ0jBXmz0QVyKCRXSzdQ9OLaC5YwneBVk Wu1gLtHtAQxEh8YPE9DzDVx9811FfOt+/9ugMl6NqYnO0oUS6mX4TNw8zkeO37V5rP6m vkIAy3q8Pmk1S2rcUJAdWcXz1x8FO644ez3jVk1BB53knD5fGoCPWS4oxvkwrSaV3nJg ZmReGPNPSlezKSZV8MvKlfj1IXKC1wYK57pjbpp9CuC8yIleHt5o+s27hE2HcEyUU/36 k4eQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=PBBdMmlK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id j12-20020a056a00174c00b0069100de2235si13681501pfc.187.2023.11.08.03.22.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 03:22:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=PBBdMmlK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 1BE3280A22F8; Wed, 8 Nov 2023 03:21:27 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344644AbjKHLVO (ORCPT + 32 others); Wed, 8 Nov 2023 06:21:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344402AbjKHLVF (ORCPT ); Wed, 8 Nov 2023 06:21:05 -0500 Received: from smtp-fw-80006.amazon.com (smtp-fw-80006.amazon.com [99.78.197.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDC0B1BF5; Wed, 8 Nov 2023 03:21:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1699442464; x=1730978464; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7C45WW2plKc9LGS1hg04kUsdvaSyLe7Yr2kIsIf6Lys=; b=PBBdMmlKTVNOph/CauxitBiIZC2KKZDRZoDPYrP9M4s46/tyZCXrGesw EopIKJhR5etsB50qYBfKZhCn3BEkZk7/oahfr0RJhI3xKx8AZ9wy5DxYs QJ1k7B0GZJsSKlIGCX3MXcBrNLAyqtfsi4dGzUoeQB+V5Wi9flFULTzz6 Y=; X-IronPort-AV: E=Sophos;i="6.03,286,1694736000"; d="scan'208";a="250876207" Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO email-inbound-relay-iad-1a-m6i4x-edda28d4.us-east-1.amazon.com) ([10.25.36.214]) by smtp-border-fw-80006.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2023 11:21:01 +0000 Received: from smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev (iad7-ws-svc-p70-lb3-vlan3.iad.amazon.com [10.32.235.38]) by email-inbound-relay-iad-1a-m6i4x-edda28d4.us-east-1.amazon.com (Postfix) with ESMTPS id 11B3F806CD; Wed, 8 Nov 2023 11:20:56 +0000 (UTC) Received: from EX19MTAEUA001.ant.amazon.com [10.0.17.79:3212] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.32.187:2525] with esmtp (Farcaster) id 71b58972-fe97-42fd-b068-56f96eb17f93; Wed, 8 Nov 2023 11:20:55 +0000 (UTC) X-Farcaster-Flow-ID: 71b58972-fe97-42fd-b068-56f96eb17f93 Received: from EX19D004EUC001.ant.amazon.com (10.252.51.190) by EX19MTAEUA001.ant.amazon.com (10.252.50.192) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.39; Wed, 8 Nov 2023 11:20:55 +0000 Received: from dev-dsk-nsaenz-1b-189b39ae.eu-west-1.amazon.com (10.13.235.138) by EX19D004EUC001.ant.amazon.com (10.252.51.190) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.39; Wed, 8 Nov 2023 11:20:50 +0000 From: Nicolas Saenz Julienne To: CC: , , , , , , , , , , , , , , , Nicolas Saenz Julienne Subject: [RFC 12/33] KVM: x86: hyper-v: Handle VSM hcalls in user-space Date: Wed, 8 Nov 2023 11:17:45 +0000 Message-ID: <20231108111806.92604-13-nsaenz@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231108111806.92604-1-nsaenz@amazon.com> References: <20231108111806.92604-1-nsaenz@amazon.com> MIME-Version: 1.0 X-Originating-IP: [10.13.235.138] X-ClientProxiedBy: EX19D040UWA001.ant.amazon.com (10.13.139.22) To EX19D004EUC001.ant.amazon.com (10.252.51.190) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 08 Nov 2023 03:21:27 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781994664234564186 X-GMAIL-MSGID: 1781994664234564186 Let user-space handle all hypercalls that fall under the AccessVsm partition privilege flag. That is: - HVCALL_MODIFY_VTL_PROTECTION_MASK: - HVCALL_ENABLE_PARTITION_VTL: - HVCALL_ENABLE_VP_VTL: - HVCALL_VTL_CALL: - HVCALL_VTL_RETURN: The hypercalls are processed through the KVM_EXIT_HYPERV_HVCALL exit. Additionally, expose the cpuid bit. Signed-off-by: Nicolas Saenz Julienne --- arch/x86/kvm/hyperv.c | 15 +++++++++++++++ include/asm-generic/hyperv-tlfs.h | 7 ++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c index a3970d52eef1..a266c5d393f5 100644 --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -2462,6 +2462,11 @@ static bool kvm_hv_is_xmm_output_hcall(u16 code) return false; } +static inline bool kvm_hv_is_vtl_call_return(u16 code) +{ + return code == HVCALL_VTL_CALL || code == HVCALL_VTL_RETURN; +} + static int kvm_hv_hypercall_complete_userspace(struct kvm_vcpu *vcpu) { bool fast = !!(vcpu->run->hyperv.u.hcall.input & HV_HYPERCALL_FAST_BIT); @@ -2471,6 +2476,9 @@ static int kvm_hv_hypercall_complete_userspace(struct kvm_vcpu *vcpu) if (kvm_hv_is_xmm_output_hcall(code) && hv_result_success(result) && fast) kvm_hv_write_xmm(vcpu->run->hyperv.u.hcall.xmm); + if (kvm_hv_is_vtl_call_return(code)) + return kvm_skip_emulated_instruction(vcpu); + return kvm_hv_hypercall_complete(vcpu, result); } @@ -2525,6 +2533,7 @@ static bool is_xmm_fast_hypercall(struct kvm_hv_hcall *hc) case HVCALL_SEND_IPI_EX: case HVCALL_GET_VP_REGISTERS: case HVCALL_SET_VP_REGISTERS: + case HVCALL_MODIFY_VTL_PROTECTION_MASK: return true; } @@ -2745,6 +2754,11 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu) goto hypercall_userspace_exit; case HVCALL_GET_VP_REGISTERS: case HVCALL_SET_VP_REGISTERS: + case HVCALL_MODIFY_VTL_PROTECTION_MASK: + case HVCALL_ENABLE_PARTITION_VTL: + case HVCALL_ENABLE_VP_VTL: + case HVCALL_VTL_CALL: + case HVCALL_VTL_RETURN: goto hypercall_userspace_exit; default: ret = HV_STATUS_INVALID_HYPERCALL_CODE; @@ -2912,6 +2926,7 @@ int kvm_get_hv_cpuid(struct kvm_vcpu *vcpu, struct kvm_cpuid2 *cpuid, ent->ebx |= HV_SIGNAL_EVENTS; ent->ebx |= HV_ENABLE_EXTENDED_HYPERCALLS; ent->ebx |= HV_ACCESS_VP_REGISTERS; + ent->ebx |= HV_ACCESS_VSM; ent->edx |= HV_X64_HYPERCALL_XMM_INPUT_AVAILABLE; ent->edx |= HV_X64_HYPERCALL_XMM_OUTPUT_AVAILABLE; diff --git a/include/asm-generic/hyperv-tlfs.h b/include/asm-generic/hyperv-tlfs.h index 24ea699a3d8e..a8b5c8a84bbc 100644 --- a/include/asm-generic/hyperv-tlfs.h +++ b/include/asm-generic/hyperv-tlfs.h @@ -89,6 +89,7 @@ #define HV_ACCESS_STATS BIT(8) #define HV_DEBUGGING BIT(11) #define HV_CPU_MANAGEMENT BIT(12) +#define HV_ACCESS_VSM BIT(16) #define HV_ACCESS_VP_REGISTERS BIT(17) #define HV_ENABLE_EXTENDED_HYPERCALLS BIT(20) #define HV_ISOLATION BIT(22) @@ -147,9 +148,13 @@ union hv_reference_tsc_msr { /* Declare the various hypercall operations. */ #define HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE 0x0002 #define HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST 0x0003 -#define HVCALL_ENABLE_VP_VTL 0x000f #define HVCALL_NOTIFY_LONG_SPIN_WAIT 0x0008 #define HVCALL_SEND_IPI 0x000b +#define HVCALL_MODIFY_VTL_PROTECTION_MASK 0x000c +#define HVCALL_ENABLE_PARTITION_VTL 0x000d +#define HVCALL_ENABLE_VP_VTL 0x000f +#define HVCALL_VTL_CALL 0x0011 +#define HVCALL_VTL_RETURN 0x0012 #define HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE_EX 0x0013 #define HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST_EX 0x0014 #define HVCALL_SEND_IPI_EX 0x0015