From patchwork Tue Jul 18 03:22:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 121745 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp1483049vqt; Mon, 17 Jul 2023 20:31:28 -0700 (PDT) X-Google-Smtp-Source: APBJJlFfCfgRO0LXvGlWCKRXPSWxhjh897b1KtGL6BSRFs1fdVCEuFbD6BXcux4/diDTz1SGeCXR X-Received: by 2002:a05:6a00:a1b:b0:682:9162:7218 with SMTP id p27-20020a056a000a1b00b0068291627218mr17851290pfh.15.1689651088418; Mon, 17 Jul 2023 20:31:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689651088; cv=none; d=google.com; s=arc-20160816; b=lx7ESMBbLLykDTy93txpl9POzgL57yslqgrJ7JMEHvi9jObtLSjBJwGrARYnJhgXqi 9O87qBJ76ew5eHCoyhx2Z1Fggf108byq1ABMO7tcpeIKYtZK/Pczze4Xb9LQjcQRR479 d6THIWvhXX3ppyR4OZ1WcqkrJklt1XQ3SIVWxyL65g0GRN8cCEUuUC4j14YrnkbtZiJ0 qb2YhqevmxfEQbc/tU5oo8JlGc5cxljG31orJmsb0CFLADFpjAPA4v+JGETIFyaiZ9SH U4Kizm8yzs3ZXTVF5k3phEJjLi62In3PUKkBfvzyDjjOuiYecEhdX+xNwgjor8LRv4rk Xleg== 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=EzmXN52+TQQdhtLMBjsRB9gT+s4o48H638S+GTEwYko=; fh=0q4Ral/ZvWHifErBr5uVVFNUVQsTG1/TVmQRaCWii40=; b=tvtDgSXwRJugN2oW1YuD8vn/EiimJNRmWDO8NNHugo7yrdsJt4GimfolpiuxyRECO1 q49DI/NvbhhZ4Gm/Rql36THkbb+Ruh1/71gwF4VBz+GmCzZ9ZZZGV/kCB1SvT3hXBXdU ZjB39Vz2O7xwmzddJIdx4ozn8KauDGel0lHC3Tm8o4tXPN5KJQkpfRdk20YniBRUoFF4 slerbIvv6uzsxmFAGPgbh7TEErx9uXiFxoICmnwyFXAD3unTrFMt+6D2PcXZayua5rqo cz2at4sF6prXxpDEDUzVTeneUTxkSwlXGuoju0Uq01r8tz1MBiBkZ9v03xXEUKf0mn6u x8+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=MaaO9u2t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r124-20020a632b82000000b0055785a37147si799716pgr.590.2023.07.17.20.31.15; Mon, 17 Jul 2023 20:31:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=MaaO9u2t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231178AbjGRDXc (ORCPT + 99 others); Mon, 17 Jul 2023 23:23:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229790AbjGRDXQ (ORCPT ); Mon, 17 Jul 2023 23:23:16 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6938810D1; Mon, 17 Jul 2023 20:23:13 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-263121cd04eso2776001a91.2; Mon, 17 Jul 2023 20:23:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689650593; x=1692242593; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EzmXN52+TQQdhtLMBjsRB9gT+s4o48H638S+GTEwYko=; b=MaaO9u2t7kLY11kzlBYjIwd+kNfrSwJGyynCDbxa20rdBog+n+riq87clrqVsCNdUA YD3+/9nmcNgkxvoJfLgHY9UHyLHH2P14oP+xhjM5faTFPfCJBukMcGxKGAjlDVmDCqhm W4jqKxGnEaom5bsVHzLHsEoZj/TDQV+zaEFeqJ8iSTDTlzHYy8w+xT85Mz8R6Z7Mb5fM HyUkBOYr+M55iUrJtH+fr0HQpYC5sPxzNegSQWY9phL1EVq8MQUz+1f81Go081L3UKBC 7QA8596vyZ2NuskITIHPpxfnzz2ntFRSPfEMuTVj7it7BwP+Hqv42O3zS43391cMq3iQ +YbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689650593; x=1692242593; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EzmXN52+TQQdhtLMBjsRB9gT+s4o48H638S+GTEwYko=; b=Wpepm970oGCzz2r2iqaOnQGBHs1Eh5UqunJrxVE9kItZdo1uEK8g6Dc8WhH88R0Q7u pFvmMS4TndXZGYDY5U9/OZV2IEt8soIqMPXt3dSzXVlJ4KlvHAF53HrU6+yhrn0YSXD4 bmbf8eqvJUV1FP65bU5MoAwnyHCR/lSZWHOM4eo6WsvZvnEmGEOInUeTNmyHZ6vZlyZe +t2d7FPptBeLhTnnF6ZbygAJpKNPQ2IcGLo3mmM9CGZOMJIOnPultL8RBECB4GzRXJ6S IB9lWqYbiZ/sFdJu6yiWcT8SEVG+1e5l91d8wJFESWVWhp62epE+xk5G9f8VuAYYSMiD HjnA== X-Gm-Message-State: ABy/qLbndJYFYRSExckzhMUObWNq/9N2VDVifOaWJhw0LB38Yl1xpBdk KklzYK7Rt0Vsux93FJojIE0= X-Received: by 2002:a17:90b:1c0e:b0:25d:eca9:1621 with SMTP id oc14-20020a17090b1c0e00b0025deca91621mr11396604pjb.6.1689650592786; Mon, 17 Jul 2023 20:23:12 -0700 (PDT) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:37:c5e9:2003:6c97:8057]) by smtp.gmail.com with ESMTPSA id s92-20020a17090a2f6500b00263f41a655esm504040pjd.43.2023.07.17.20.23.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jul 2023 20:23:12 -0700 (PDT) From: Tianyu Lan To: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, daniel.lezcano@linaro.org, arnd@arndb.de, michael.h.kelley@microsoft.com Cc: Tianyu Lan , linux-arch@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, vkuznets@redhat.com Subject: [PATCH V3 2/9] x86/hyperv: Set Virtual Trust Level in VMBus init message Date: Mon, 17 Jul 2023 23:22:56 -0400 Message-Id: <20230718032304.136888-3-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230718032304.136888-1-ltykernel@gmail.com> References: <20230718032304.136888-1-ltykernel@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771727580103434109 X-GMAIL-MSGID: 1771727580103434109 From: Tianyu Lan SEV-SNP guests on Hyper-V can run at multiple Virtual Trust Levels (VTL). During boot, get the VTL at which we're running using the GET_VP_REGISTERs hypercall, and save the value for future use. Then during VMBus initialization, set the VTL with the saved value as required in the VMBus init message. Signed-off-by: Tianyu Lan Reviewed-by: Michael Kelley --- * Change since v2: Update the change log. --- arch/x86/hyperv/hv_init.c | 36 ++++++++++++++++++++++++++++++ arch/x86/include/asm/hyperv-tlfs.h | 7 ++++++ drivers/hv/connection.c | 1 + include/asm-generic/mshyperv.h | 1 + include/linux/hyperv.h | 4 ++-- 5 files changed, 47 insertions(+), 2 deletions(-) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index 6c04b52f139b..1ba367a9686e 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -378,6 +378,40 @@ static void __init hv_get_partition_id(void) local_irq_restore(flags); } +static u8 __init get_vtl(void) +{ + u64 control = HV_HYPERCALL_REP_COMP_1 | HVCALL_GET_VP_REGISTERS; + struct hv_get_vp_registers_input *input; + struct hv_get_vp_registers_output *output; + u64 vtl = 0; + u64 ret; + unsigned long flags; + + local_irq_save(flags); + input = *this_cpu_ptr(hyperv_pcpu_input_arg); + output = (struct hv_get_vp_registers_output *)input; + if (!input) { + local_irq_restore(flags); + goto done; + } + + memset(input, 0, struct_size(input, element, 1)); + input->header.partitionid = HV_PARTITION_ID_SELF; + input->header.vpindex = HV_VP_INDEX_SELF; + input->header.inputvtl = 0; + input->element[0].name0 = HV_X64_REGISTER_VSM_VP_STATUS; + + ret = hv_do_hypercall(control, input, output); + if (hv_result_success(ret)) + vtl = output->as64.low & HV_X64_VTL_MASK; + else + pr_err("Hyper-V: failed to get VTL! %lld", ret); + local_irq_restore(flags); + +done: + return vtl; +} + /* * This function is to be invoked early in the boot sequence after the * hypervisor has been detected. @@ -506,6 +540,8 @@ void __init hyperv_init(void) /* Query the VMs extended capability once, so that it can be cached. */ hv_query_ext_cap(0); + /* Find the VTL */ + ms_hyperv.vtl = get_vtl(); return; clean_guest_os_id: diff --git a/arch/x86/include/asm/hyperv-tlfs.h b/arch/x86/include/asm/hyperv-tlfs.h index cea95dcd27c2..4bf0b315b0ce 100644 --- a/arch/x86/include/asm/hyperv-tlfs.h +++ b/arch/x86/include/asm/hyperv-tlfs.h @@ -301,6 +301,13 @@ enum hv_isolation_type { #define HV_X64_MSR_TIME_REF_COUNT HV_REGISTER_TIME_REF_COUNT #define HV_X64_MSR_REFERENCE_TSC HV_REGISTER_REFERENCE_TSC +/* + * Registers are only accessible via HVCALL_GET_VP_REGISTERS hvcall and + * there is not associated MSR address. + */ +#define HV_X64_REGISTER_VSM_VP_STATUS 0x000D0003 +#define HV_X64_VTL_MASK GENMASK(3, 0) + /* Hyper-V memory host visibility */ enum hv_mem_host_visibility { VMBUS_PAGE_NOT_VISIBLE = 0, diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c index 5978e9dbc286..02b54f85dc60 100644 --- a/drivers/hv/connection.c +++ b/drivers/hv/connection.c @@ -98,6 +98,7 @@ int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo, u32 version) */ if (version >= VERSION_WIN10_V5) { msg->msg_sint = VMBUS_MESSAGE_SINT; + msg->msg_vtl = ms_hyperv.vtl; vmbus_connection.msg_conn_id = VMBUS_MESSAGE_CONNECTION_ID_4; } else { msg->interrupt_page = virt_to_phys(vmbus_connection.int_page); diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h index 6b5c41f90398..f73a044ecaa7 100644 --- a/include/asm-generic/mshyperv.h +++ b/include/asm-generic/mshyperv.h @@ -54,6 +54,7 @@ struct ms_hyperv_info { }; }; u64 shared_gpa_boundary; + u8 vtl; }; extern struct ms_hyperv_info ms_hyperv; extern bool hv_nested; diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index bfbc37ce223b..1f2bfec4abde 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -665,8 +665,8 @@ struct vmbus_channel_initiate_contact { u64 interrupt_page; struct { u8 msg_sint; - u8 padding1[3]; - u32 padding2; + u8 msg_vtl; + u8 reserved[6]; }; }; u64 monitor_page1;