From patchwork Mon Mar 20 10:03:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saurabh Singh Sengar X-Patchwork-Id: 72062 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1124654wrt; Mon, 20 Mar 2023 03:06:32 -0700 (PDT) X-Google-Smtp-Source: AK7set9rLPqPEU4vvRQbP1SZZBBKqvCoMrE7hgJO5sntOQj5x5TTQORolIxhwK1hmJfBv33HdmTr X-Received: by 2002:a17:902:db07:b0:1a1:a146:f6d7 with SMTP id m7-20020a170902db0700b001a1a146f6d7mr15199272plx.4.1679306792418; Mon, 20 Mar 2023 03:06:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679306792; cv=none; d=google.com; s=arc-20160816; b=thXP9BFd43pAauAVo0VGo5VwYT5P2SpqnobHFhKIrvOrDtueWO1nN85lLdjrL8P5Tg YVA5bAveu5N0d9WscoqIGcDVro5gACSVz9Arj1RFm6V8u3C0S1aocli0VsZBFFMPS4re +qsyzeirJGd80WNMeVDgfV//9w+6nHlZloGbtnfHM3itAGho7vu67uk156YLDVg6/BE7 roH7Xz5m3+0ms4cOfQMYvd2e3aIOKOwqZKY7xvNpKCen5VwZKWUN4Qs/EO1+Fy/kN9nn lqXAq7KXNoW9yOngUE2KYMOpfRDNP5CZkkcseEACLTulKqev6/q76RpcyjC4V5HJDnfB QOzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :to:from:dkim-signature:dkim-filter; bh=XJGsmNUD3KYthEmUtcPnLGFUy0O6jC650pPe5cXvUH4=; b=fXnOwzgsQevgob04YKa12kMqtjtdtzlW/BvLX2385SNhnA8fKDgOu9xmzviKDZkc/S z+fhACuhEaKHnXvGlIlgESv8nuIWjmfRKMx5DKRvyYYgmyE9gQpuU6WKIpwcohW+gOq3 rv0CEDjUaNtQd+mP8IbwC4cLX6d/lpYaVIYk0CHyIX/9plRqQXwHaK1K6z0k7XmAVXJc C1QkY1WHtCPb1wUSRAI5TUkO1wAAtMjge1Tgb6nOj9tX1njl0KKe7oDy3Ltlt1c9LOYW ICtiu+vMSy3/Gz4VacPBGOGZNsiMOtDDGzZDB4JtAcCtRHFe0enzMOwMBzrj4H0fujjk 2Sqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=pYUk5tPx; 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=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lf5-20020a170902fb4500b001945ff85d7asi9204483plb.357.2023.03.20.03.06.17; Mon, 20 Mar 2023 03:06:32 -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=@linux.microsoft.com header.s=default header.b=pYUk5tPx; 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=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229922AbjCTKEi (ORCPT + 99 others); Mon, 20 Mar 2023 06:04:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229871AbjCTKE3 (ORCPT ); Mon, 20 Mar 2023 06:04:29 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 315F7BDE3; Mon, 20 Mar 2023 03:03:55 -0700 (PDT) Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id D2D5D20FAEC9; Mon, 20 Mar 2023 03:03:42 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com D2D5D20FAEC9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1679306622; bh=XJGsmNUD3KYthEmUtcPnLGFUy0O6jC650pPe5cXvUH4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=pYUk5tPxJsbHm3xm61VRG/KqPerAnzNDGFWo568XIKLsOMjexwkVUFo/wA1NhNnFx P/vYQ8rM2ewLieELC/NtEGk61Uqfe2qoVohLIswvW4Ms2RO0HF7eUQavTV6eopJMDU Gd7369pzAwY+w10k5mV65x6lPODjDfDtgC+3lhDQ= From: Saurabh Sengar To: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, arnd@arndb.de, tiala@microsoft.com, mikelley@microsoft.com, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-arch@vger.kernel.org Subject: [PATCH v3 1/5] x86/init: Make get/set_rtc_noop() public Date: Mon, 20 Mar 2023 03:03:34 -0700 Message-Id: <1679306618-31484-2-git-send-email-ssengar@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1679306618-31484-1-git-send-email-ssengar@linux.microsoft.com> References: <1679306618-31484-1-git-send-email-ssengar@linux.microsoft.com> X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760880798746249270?= X-GMAIL-MSGID: =?utf-8?q?1760880798746249270?= Make get/set_rtc_noop() to be public so that they can be used in other modules as well. Co-developed-by: Tianyu Lan Signed-off-by: Tianyu Lan Signed-off-by: Saurabh Sengar Reviewed-by: Wei Liu Reviewed-by: Michael Kelley --- arch/x86/include/asm/x86_init.h | 2 ++ arch/x86/kernel/x86_init.c | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h index c1c8c581759d..d8fb3a1639e9 100644 --- a/arch/x86/include/asm/x86_init.h +++ b/arch/x86/include/asm/x86_init.h @@ -326,5 +326,7 @@ extern void x86_init_uint_noop(unsigned int unused); extern bool bool_x86_init_noop(void); extern void x86_op_int_noop(int cpu); extern bool x86_pnpbios_disabled(void); +extern int set_rtc_noop(const struct timespec64 *now); +extern void get_rtc_noop(struct timespec64 *now); #endif diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c index ef80d361b463..d93aeffec19b 100644 --- a/arch/x86/kernel/x86_init.c +++ b/arch/x86/kernel/x86_init.c @@ -33,8 +33,8 @@ static int __init iommu_init_noop(void) { return 0; } static void iommu_shutdown_noop(void) { } bool __init bool_x86_init_noop(void) { return false; } void x86_op_int_noop(int cpu) { } -static __init int set_rtc_noop(const struct timespec64 *now) { return -EINVAL; } -static __init void get_rtc_noop(struct timespec64 *now) { } +int set_rtc_noop(const struct timespec64 *now) { return -EINVAL; } +void get_rtc_noop(struct timespec64 *now) { } static __initconst const struct of_device_id of_cmos_match[] = { { .compatible = "motorola,mc146818" }, From patchwork Mon Mar 20 10:03:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saurabh Singh Sengar X-Patchwork-Id: 72068 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1130602wrt; Mon, 20 Mar 2023 03:20:59 -0700 (PDT) X-Google-Smtp-Source: AK7set/Qxiyywmw+8Zd/akVYaNn8YTPBstTcV+LXSXZpbRJrGmdCW4eDyZsqoyx8+j4QWNQesm9V X-Received: by 2002:a17:90a:355:b0:237:24a8:c5e2 with SMTP id 21-20020a17090a035500b0023724a8c5e2mr18129159pjf.40.1679307659595; Mon, 20 Mar 2023 03:20:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679307659; cv=none; d=google.com; s=arc-20160816; b=AotWdtNYjfNobFBXDbZ4+1Tl5HFSC+IzyRG7lJC7Y5pU1fGLIKgyK6FcrC4fqCZE0T mpfwNwG9ymY3lXTW8v76isiVDrUfRYSSEg465QW65piujtDmWT2h+mlNroTY9E5pz3jU EDI48OpNvIg8ZxS50lAd5zORqzMDQ4/J7CzI5Cm/JZ/ILNQ3JVS02LtkYHfXZ937IyLc P3gXfOpc7XRJybcXt4TrGB9mfENdxNhs/00fscEPyPwd3Cg4bxU5oR5IPaL69PVFYNbb +PfY0/v91u6sYEWg3fNSf7dj8KvheHxLXxiXr5TXgkl2urUkKSZPs3WNY1Cz2bgCDxJx sCOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :to:from:dkim-signature:dkim-filter; bh=j33V+lRmdypNPo/5POd8iHHMbdWcF0C+HhIy3rM9JsQ=; b=Pua996E+CO/MNSZOJ03CTRuBxNgQ7Bv8waWJoRtA2rzVSsNkyzu0HGFoONZ5IbtvtW hTGF79ULRL2ue/VMuwyc5sOwRYe4bfhINIwY77iBDlWZDPo1vdNY7AAspdlb/9+TPbrp H4ckG6Z1VL0Dkl5svB0ZK8YvaRcGO5+3gvTVRbtKTiE/uy6NnHYu8shbQVBolOGcFIzq mV6h5MZGctr9Pq8nA6riFtbzv6+msn06PvU/naBbHEYxZeP0wHOVqC1LRfq2yJ82hRiz oy8E9+lrRyXycODEGDK+xP+aq+c0zbmPMUspOPf7CXFGPyRe6EXSYsu8Wi/A2AIiAPRe e3hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=ESMBxJZY; 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=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k69-20020a638448000000b0050bfa82c243si10753723pgd.17.2023.03.20.03.20.45; Mon, 20 Mar 2023 03:20:59 -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=@linux.microsoft.com header.s=default header.b=ESMBxJZY; 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=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230014AbjCTKEt (ORCPT + 99 others); Mon, 20 Mar 2023 06:04:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229879AbjCTKEb (ORCPT ); Mon, 20 Mar 2023 06:04:31 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 07814EA; Mon, 20 Mar 2023 03:03:56 -0700 (PDT) Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id EB15520FAED2; Mon, 20 Mar 2023 03:03:42 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com EB15520FAED2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1679306623; bh=j33V+lRmdypNPo/5POd8iHHMbdWcF0C+HhIy3rM9JsQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ESMBxJZYw40VCUfdJROv7RmM5GvMMN2gzq31Bg27l4d/egS9G9b0VRZHGOuKDuHBo ffyGHGor7Mi/xlJfykXSuM+vU9sd+qeBuScV4MpVveGBZHjM13NTL91mUzQVBaWBgk auJL0ulT2pGUmTtI6ebNIeYMM8KdL8rqfHuuNc6U= From: Saurabh Sengar To: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, arnd@arndb.de, tiala@microsoft.com, mikelley@microsoft.com, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-arch@vger.kernel.org Subject: [PATCH v3 2/5] x86/hyperv: Add VTL specific structs and hypercalls Date: Mon, 20 Mar 2023 03:03:35 -0700 Message-Id: <1679306618-31484-3-git-send-email-ssengar@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1679306618-31484-1-git-send-email-ssengar@linux.microsoft.com> References: <1679306618-31484-1-git-send-email-ssengar@linux.microsoft.com> X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760881708432532302?= X-GMAIL-MSGID: =?utf-8?q?1760881708432532302?= Add structs and hypercalls required to enable VTL support on x86. Signed-off-by: Saurabh Sengar Reviewed-by: Michael Kelley --- arch/x86/include/asm/hyperv-tlfs.h | 75 ++++++++++++++++++++++++++++++ include/asm-generic/hyperv-tlfs.h | 4 ++ 2 files changed, 79 insertions(+) diff --git a/arch/x86/include/asm/hyperv-tlfs.h b/arch/x86/include/asm/hyperv-tlfs.h index 0b73a809e9e1..0b0b4e9a4318 100644 --- a/arch/x86/include/asm/hyperv-tlfs.h +++ b/arch/x86/include/asm/hyperv-tlfs.h @@ -713,6 +713,81 @@ union hv_msi_entry { } __packed; }; +struct hv_x64_segment_register { + __u64 base; + __u32 limit; + __u16 selector; + union { + struct { + __u16 segment_type : 4; + __u16 non_system_segment : 1; + __u16 descriptor_privilege_level : 2; + __u16 present : 1; + __u16 reserved : 4; + __u16 available : 1; + __u16 _long : 1; + __u16 _default : 1; + __u16 granularity : 1; + } __packed; + __u16 attributes; + }; +} __packed; + +struct hv_x64_table_register { + __u16 pad[3]; + __u16 limit; + __u64 base; +} __packed; + +struct hv_init_vp_context { + u64 rip; + u64 rsp; + u64 rflags; + + struct hv_x64_segment_register cs; + struct hv_x64_segment_register ds; + struct hv_x64_segment_register es; + struct hv_x64_segment_register fs; + struct hv_x64_segment_register gs; + struct hv_x64_segment_register ss; + struct hv_x64_segment_register tr; + struct hv_x64_segment_register ldtr; + + struct hv_x64_table_register idtr; + struct hv_x64_table_register gdtr; + + u64 efer; + u64 cr0; + u64 cr3; + u64 cr4; + u64 msr_cr_pat; +} __packed; + +union hv_input_vtl { + u8 as_uint8; + struct { + u8 target_vtl: 4; + u8 use_target_vtl: 1; + u8 reserved_z: 3; + }; +} __packed; + +struct hv_enable_vp_vtl { + u64 partition_id; + u32 vp_index; + union hv_input_vtl target_vtl; + u8 mbz0; + u16 mbz1; + struct hv_init_vp_context vp_context; +} __packed; + +struct hv_get_vp_from_apic_id_in { + u64 partition_id; + union hv_input_vtl target_vtl; + u8 res[7]; + u32 apic_ids[]; +} __packed; + #include #endif diff --git a/include/asm-generic/hyperv-tlfs.h b/include/asm-generic/hyperv-tlfs.h index b870983596b9..87258341fd7c 100644 --- a/include/asm-generic/hyperv-tlfs.h +++ b/include/asm-generic/hyperv-tlfs.h @@ -146,6 +146,7 @@ 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_FLUSH_VIRTUAL_ADDRESS_SPACE_EX 0x0013 @@ -165,6 +166,8 @@ union hv_reference_tsc_msr { #define HVCALL_MAP_DEVICE_INTERRUPT 0x007c #define HVCALL_UNMAP_DEVICE_INTERRUPT 0x007d #define HVCALL_RETARGET_INTERRUPT 0x007e +#define HVCALL_START_VP 0x0099 +#define HVCALL_GET_VP_ID_FROM_APIC_ID 0x009a #define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE 0x00af #define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_LIST 0x00b0 #define HVCALL_MODIFY_SPARSE_GPA_PAGE_HOST_VISIBILITY 0x00db @@ -218,6 +221,7 @@ enum HV_GENERIC_SET_FORMAT { #define HV_STATUS_INVALID_PORT_ID 17 #define HV_STATUS_INVALID_CONNECTION_ID 18 #define HV_STATUS_INSUFFICIENT_BUFFERS 19 +#define HV_STATUS_VTL_ALREADY_ENABLED 134 /* * The Hyper-V TimeRefCount register and the TSC From patchwork Mon Mar 20 10:03:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saurabh Singh Sengar X-Patchwork-Id: 72066 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1130474wrt; Mon, 20 Mar 2023 03:20:45 -0700 (PDT) X-Google-Smtp-Source: AK7set+Go1IB9PJWU47XgH6bL0+kw/X9OLD87keaiPE/bk0E2PSbyWFAv76cSX7m+hgzeOE01/WW X-Received: by 2002:a17:902:cecb:b0:19e:416e:abf5 with SMTP id d11-20020a170902cecb00b0019e416eabf5mr12173649plg.34.1679307644862; Mon, 20 Mar 2023 03:20:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679307644; cv=none; d=google.com; s=arc-20160816; b=MbWtQwSJQ4dPXHnulpPMqnpHguJUypBcoZ2p9FhPa48o84fEa55h7mdKgReBgMn71J c5YRhXQbQRaNM/yURxfz/AQQ9EJLWzg59Z5n+EkJqBEvpz8UEpKD0AXOyBmK2fC4RJV8 022qtR5Dg3t3tydn+0h12agyhiRtpizbWNGyjc6aaKk2QKn93Q6NGPtpPn0vpSj4fMbD tLwMbFrCx6NvLo9qawMWuJx0p0tbhXlNt4HCkt3tozyiSmZ1K/sv/M56CgN+M0i/+NtE H3ChrXl/UEDiDrCNmgrGeuVViMRKfVR4uQ7JKtNX4R5eSMvCs8OqX0XZbglbzw/jmQL1 HL/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :to:from:dkim-signature:dkim-filter; bh=rnTbUjR9n2/4s9Jdr0rdLVFg2m8YA/nI+pUJy8tCLnQ=; b=NF8/4qNxK0zT27ovuv0x2x0o2JuvoJ6vT49+SeR9e8qZyO41uJjkRyioJxnSgIGCOp i2FjlOdWnwIWUKgtvn8tVKHxLjoZheVlB2lDLH99uuALr9H24t8YQdl1V23ZVPCyrn4J zbmaEL6jq/GGNuBHsPtTLO2qSObqIIXw6VEAYP/5kdpfhkLeWvfQd96okOfYk3D9dDmc cKB2MkQgJpaRHV0tgmZ7waYl4diTobvbjmENSqJijnqgBfcI4/I4DXO9vxyIZOGk9621 9iWWzgx0KdfeJDAaXNGa17BMdRaSGHNePgtcdK7kyP4M66JV6LAtBqNQGNzmqy4c01lf xiBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=hTbzzy28; 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=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w11-20020a170902d10b00b0019aa67f4a05si9645302plw.484.2023.03.20.03.20.30; Mon, 20 Mar 2023 03:20:44 -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=@linux.microsoft.com header.s=default header.b=hTbzzy28; 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=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229937AbjCTKEl (ORCPT + 99 others); Mon, 20 Mar 2023 06:04:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229685AbjCTKE3 (ORCPT ); Mon, 20 Mar 2023 06:04:29 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 390F5CC14; Mon, 20 Mar 2023 03:03:57 -0700 (PDT) Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id 0F75E20FAED7; Mon, 20 Mar 2023 03:03:43 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 0F75E20FAED7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1679306623; bh=rnTbUjR9n2/4s9Jdr0rdLVFg2m8YA/nI+pUJy8tCLnQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=hTbzzy28fIdvCV1TThZYkkPtL4PH3HXlp1i9HCpN6+eOdBCZSkfz478fWdv5Ld1Qe wVxY3g0ylwClQww6J3hgtwoSZ2vGgDyF0TKob/jRlXtdhtQPmyyeGYfhqto4A6Xd2A HSBS0f3jlgMJMKttkOJv7/cXbzBjUAGMGicsotAQ= From: Saurabh Sengar To: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, arnd@arndb.de, tiala@microsoft.com, mikelley@microsoft.com, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-arch@vger.kernel.org Subject: [PATCH v3 3/5] x86/hyperv: Make hv_get_nmi_reason public Date: Mon, 20 Mar 2023 03:03:36 -0700 Message-Id: <1679306618-31484-4-git-send-email-ssengar@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1679306618-31484-1-git-send-email-ssengar@linux.microsoft.com> References: <1679306618-31484-1-git-send-email-ssengar@linux.microsoft.com> X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760881692639811445?= X-GMAIL-MSGID: =?utf-8?q?1760881692639811445?= Move hv_get_nmi_reason to .h file so it can be used in other modules as well. Signed-off-by: Saurabh Sengar Reviewed-by: Michael Kelley --- arch/x86/include/asm/mshyperv.h | 5 +++++ arch/x86/kernel/cpu/mshyperv.c | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h index 4c4c0ec3b62e..35b16b177035 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -181,6 +181,11 @@ static inline struct hv_vp_assist_page *hv_get_vp_assist_page(unsigned int cpu) return hv_vp_assist_page[cpu]; } +static inline unsigned char hv_get_nmi_reason(void) +{ + return 0; +} + void __init hyperv_init(void); void hyperv_setup_mmu_ops(void); void set_hv_tscchange_cb(void (*cb)(void)); diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index f1197366a97d..61363ce0b335 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -250,11 +250,6 @@ static uint32_t __init ms_hyperv_platform(void) return HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS; } -static unsigned char hv_get_nmi_reason(void) -{ - return 0; -} - #ifdef CONFIG_X86_LOCAL_APIC /* * Prior to WS2016 Debug-VM sends NMIs to all CPUs which makes From patchwork Mon Mar 20 10:03:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saurabh Singh Sengar X-Patchwork-Id: 72076 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1132999wrt; Mon, 20 Mar 2023 03:27:27 -0700 (PDT) X-Google-Smtp-Source: AK7set/2ASOTg/+gi0XORxffmU9y8h6uZ+g5IMURgOAWev90eaYArxrA7+QQBfJe8uS2XyYFCM+I X-Received: by 2002:a17:902:c411:b0:1a0:7422:939a with SMTP id k17-20020a170902c41100b001a07422939amr24433911plk.4.1679308047703; Mon, 20 Mar 2023 03:27:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679308047; cv=none; d=google.com; s=arc-20160816; b=rcJd6SX7Z6a9T8rjvNLzv/fC81i12usu5riEi+oheNLjQkBH5hZ0maakshMP46wn3y nC2B0d5h+nwf4yPgEPEi0h7firbSDWIaFGHWgKO1ohkWaEJ9FdTOqfC4caWh+A1jE+xL uRqlj8Ull0h9Oc7Tfay05FJZ2s3KW/huJ93YZLhMkvQcvCjLbfeSDO8Le1TaqraNtEKo +xW1BwtMnDhclZr2L2jZsqeBnebNLF4hZCzI4I3BttJtRc6ywWjw+xr3BLVaUUg59qzp t17SEgHAPathnrAgG3GMzZSpfFpOiwwbmxYRMHGlkKdM/Eke6HWH4Z/mywW/jNSv+OrU XjmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :to:from:dkim-signature:dkim-filter; bh=EVNIDnxp0bQTMl3qb/5ZOjn2SkfWyHEbrXRC4WbcsFA=; b=S4VB6fT5UNEF15jR5XM1RGeCFwTtKhcsuK9EdIt1ZZD+Bv0oBQ8fDnSvLWfSfnzoYw 4xuiOdG9u5NWBCGYyfuPeu1/HxJjS4UXZZr8vlkm3KVGOayBu3QyStZc/srf0WJDqkBl ba0KyH53S9BN5k/fwur1glEsrWV2VCC7wrX5/S2s3XFEZsUGBSrz6T5aVQLukCmohdKA aqSj4mMP/9l4LGyw9isniEDk4b5F3iodepuk2J4Pw/injZpNvVsZZ+IIXDplmbEEKUhz Uw54AkDGoMVy35Q7gL1yv8+EvvPCjv8/kOa6nEk++JPHVTGdb2P4iN19a5pk0PPoWuFf xtUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=H7k3MJJ3; 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=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d8-20020a170903230800b0019e2c25d670si10632726plh.572.2023.03.20.03.27.12; Mon, 20 Mar 2023 03:27:27 -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=@linux.microsoft.com header.s=default header.b=H7k3MJJ3; 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=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229986AbjCTKEp (ORCPT + 99 others); Mon, 20 Mar 2023 06:04:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229838AbjCTKEa (ORCPT ); Mon, 20 Mar 2023 06:04:30 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 49118CC28; Mon, 20 Mar 2023 03:03:57 -0700 (PDT) Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id 2786D20FAED9; Mon, 20 Mar 2023 03:03:43 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 2786D20FAED9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1679306623; bh=EVNIDnxp0bQTMl3qb/5ZOjn2SkfWyHEbrXRC4WbcsFA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=H7k3MJJ378brHGLwNPgmNawx1QLZM0mIXJE2IndWEudSCmzEetAjjHslPHsPKpBf/ UsI6J1wdVGJ90cM2yHigP4DMUhHO/HbefgoQu9G78UrbjFJI/H6PAF3YmkapYe3bgY VYyQL/h2qwu4lHtcxzLkzH0s0ypDhqBdfZaPcya0= From: Saurabh Sengar To: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, arnd@arndb.de, tiala@microsoft.com, mikelley@microsoft.com, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-arch@vger.kernel.org Subject: [PATCH v3 4/5] x86/hyperv: VTL support for Hyper-V Date: Mon, 20 Mar 2023 03:03:37 -0700 Message-Id: <1679306618-31484-5-git-send-email-ssengar@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1679306618-31484-1-git-send-email-ssengar@linux.microsoft.com> References: <1679306618-31484-1-git-send-email-ssengar@linux.microsoft.com> X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760882115243016001?= X-GMAIL-MSGID: =?utf-8?q?1760882115243016001?= Virtual Trust Levels (VTL) helps enable Hyper-V Virtual Secure Mode (VSM) feature. VSM is a set of hypervisor capabilities and enlightenments offered to host and guest partitions which enable the creation and management of new security boundaries within operating system software. VSM achieves and maintains isolation through VTLs. Add early initialization for Virtual Trust Levels (VTL). This includes initializing the x86 platform for VTL and enabling boot support for secondary CPUs to start in targeted VTL context. For now, only enable the code for targeted VTL level as 2. When starting an AP at a VTL other than VTL0, the AP must start directly in 64-bit mode, bypassing the usual 16-bit -> 32-bit -> 64-bit mode transition sequence that occurs after waking up an AP with SIPI whose vector points to the 16-bit AP startup trampoline code. Signed-off-by: Saurabh Sengar --- arch/x86/hyperv/hv_vtl.c | 227 ++++++++++++++++++++++++++++++++ arch/x86/include/asm/mshyperv.h | 10 ++ arch/x86/kernel/cpu/mshyperv.c | 1 + 3 files changed, 238 insertions(+) create mode 100644 arch/x86/hyperv/hv_vtl.c diff --git a/arch/x86/hyperv/hv_vtl.c b/arch/x86/hyperv/hv_vtl.c new file mode 100644 index 000000000000..143df170812f --- /dev/null +++ b/arch/x86/hyperv/hv_vtl.c @@ -0,0 +1,227 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2023, Microsoft Corporation. + * + * Author: + * Saurabh Sengar + */ + +#include +#include +#include +#include +#include +#include + +extern struct boot_params boot_params; +static struct real_mode_header hv_vtl_real_mode_header; + +void __init hv_vtl_init_platform(void) +{ + pr_info("Linux runs in Hyper-V Virtual Trust Level\n"); + + x86_init.irqs.pre_vector_init = x86_init_noop; + x86_init.timers.timer_init = x86_init_noop; + + x86_platform.get_wallclock = get_rtc_noop; + x86_platform.set_wallclock = set_rtc_noop; + x86_platform.get_nmi_reason = hv_get_nmi_reason; + + x86_platform.legacy.i8042 = X86_LEGACY_I8042_PLATFORM_ABSENT; + x86_platform.legacy.rtc = 0; + x86_platform.legacy.warm_reset = 0; + x86_platform.legacy.reserve_bios_regions = 0; + x86_platform.legacy.devices.pnpbios = 0; +} + +static inline u64 hv_vtl_system_desc_base(struct ldttss_desc *desc) +{ + return ((u64)desc->base3 << 32) | ((u64)desc->base2 << 24) | + (desc->base1 << 16) | desc->base0; +} + +static inline u32 hv_vtl_system_desc_limit(struct ldttss_desc *desc) +{ + return ((u32)desc->limit1 << 16) | (u32)desc->limit0; +} + +typedef void (*secondary_startup_64_fn)(void*, void*); +static void hv_vtl_ap_entry(void) +{ + ((secondary_startup_64_fn)secondary_startup_64)(&boot_params, &boot_params); +} + +static int hv_vtl_bringup_vcpu(u32 target_vp_index, u64 eip_ignored) +{ + u64 status; + int ret = 0; + struct hv_enable_vp_vtl *input; + unsigned long irq_flags; + + struct desc_ptr gdt_ptr; + struct desc_ptr idt_ptr; + + struct ldttss_desc *tss; + struct ldttss_desc *ldt; + struct desc_struct *gdt; + + u64 rsp = initial_stack; + u64 rip = (u64)&hv_vtl_ap_entry; + + native_store_gdt(&gdt_ptr); + store_idt(&idt_ptr); + + gdt = (struct desc_struct *)((void *)(gdt_ptr.address)); + tss = (struct ldttss_desc *)(gdt + GDT_ENTRY_TSS); + ldt = (struct ldttss_desc *)(gdt + GDT_ENTRY_LDT); + + local_irq_save(irq_flags); + + input = *this_cpu_ptr(hyperv_pcpu_input_arg); + memset(input, 0, sizeof(*input)); + + input->partition_id = HV_PARTITION_ID_SELF; + input->vp_index = target_vp_index; + input->target_vtl.target_vtl = HV_VTL_MGMT; + + /* + * The x86_64 Linux kernel follows the 16-bit -> 32-bit -> 64-bit + * mode transition sequence after waking up an AP with SIPI whose + * vector points to the 16-bit AP startup trampoline code. Here in + * VTL2, we can't perform that sequence as the AP has to start in + * the 64-bit mode. + * + * To make this happen, we tell the hypervisor to load a valid 64-bit + * context (most of which is just magic numbers from the CPU manual) + * so that AP jumps right to the 64-bit entry of the kernel, and the + * control registers are loaded with values that let the AP fetch the + * code and data and carry on with work it gets assigned. + */ + + input->vp_context.rip = rip; + input->vp_context.rsp = rsp; + input->vp_context.rflags = 0x0000000000000002; + input->vp_context.efer = __rdmsr(MSR_EFER); + input->vp_context.cr0 = native_read_cr0(); + input->vp_context.cr3 = __native_read_cr3(); + input->vp_context.cr4 = native_read_cr4(); + input->vp_context.msr_cr_pat = __rdmsr(MSR_IA32_CR_PAT); + input->vp_context.idtr.limit = idt_ptr.size; + input->vp_context.idtr.base = idt_ptr.address; + input->vp_context.gdtr.limit = gdt_ptr.size; + input->vp_context.gdtr.base = gdt_ptr.address; + + /* Non-system desc (64bit), long, code, present */ + input->vp_context.cs.selector = __KERNEL_CS; + input->vp_context.cs.base = 0; + input->vp_context.cs.limit = 0xffffffff; + input->vp_context.cs.attributes = 0xa09b; + /* Non-system desc (64bit), data, present, granularity, default */ + input->vp_context.ss.selector = __KERNEL_DS; + input->vp_context.ss.base = 0; + input->vp_context.ss.limit = 0xffffffff; + input->vp_context.ss.attributes = 0xc093; + + /* System desc (128bit), present, LDT */ + input->vp_context.ldtr.selector = GDT_ENTRY_LDT * 8; + input->vp_context.ldtr.base = hv_vtl_system_desc_base(ldt); + input->vp_context.ldtr.limit = hv_vtl_system_desc_limit(ldt); + input->vp_context.ldtr.attributes = 0x82; + + /* System desc (128bit), present, TSS, 0x8b - busy, 0x89 -- default */ + input->vp_context.tr.selector = GDT_ENTRY_TSS * 8; + input->vp_context.tr.base = hv_vtl_system_desc_base(tss); + input->vp_context.tr.limit = hv_vtl_system_desc_limit(tss); + input->vp_context.tr.attributes = 0x8b; + + status = hv_do_hypercall(HVCALL_ENABLE_VP_VTL, input, NULL); + + if (!hv_result_success(status) && + hv_result(status) != HV_STATUS_VTL_ALREADY_ENABLED) { + pr_err("HVCALL_ENABLE_VP_VTL failed for VP : %d ! [Err: %#llx\n]", + target_vp_index, status); + ret = -EINVAL; + goto free_lock; + } + + status = hv_do_hypercall(HVCALL_START_VP, input, NULL); + + if (!hv_result_success(status)) { + pr_err("HVCALL_START_VP failed for VP : %d ! [Err: %#llx]\n", + target_vp_index, status); + ret = -EINVAL; + } + +free_lock: + local_irq_restore(irq_flags); + + return ret; +} + +static int hv_vtl_apicid_to_vp_id(u32 apic_id) +{ + u64 control; + u64 status; + unsigned long irq_flags; + struct hv_get_vp_from_apic_id_in *input; + u32 *output, ret; + + local_irq_save(irq_flags); + + input = *this_cpu_ptr(hyperv_pcpu_input_arg); + memset(input, 0, sizeof(*input)); + input->partition_id = HV_PARTITION_ID_SELF; + input->apic_ids[0] = apic_id; + + output = (u32 *)input; + + control = HV_HYPERCALL_REP_COMP_1 | HVCALL_GET_VP_ID_FROM_APIC_ID; + status = hv_do_hypercall(control, input, output); + ret = output[0]; + + local_irq_restore(irq_flags); + + if (!hv_result_success(status)) { + pr_err("failed to get vp id from apic id %d, status %#llx\n", + apic_id, status); + return -EINVAL; + } + + return ret; +} + +static int hv_vtl_wakeup_secondary_cpu(int apicid, unsigned long start_eip) +{ + int vp_id; + + pr_debug("Bringing up CPU with APIC ID %d in VTL2...\n", apicid); + vp_id = hv_vtl_apicid_to_vp_id(apicid); + + if (vp_id < 0) { + pr_err("Couldn't find CPU with APIC ID %d\n", apicid); + return -EINVAL; + } + if (vp_id > ms_hyperv.max_vp_index) { + pr_err("Invalid CPU id %d for APIC ID %d\n", vp_id, apicid); + return -EINVAL; + } + + return hv_vtl_bringup_vcpu(vp_id, start_eip); +} + +static int __init hv_vtl_early_init(void) +{ + /* + * `boot_cpu_has` returns the runtime feature support, + * and here is the earliest it can be used. + */ + if (cpu_feature_enabled(X86_FEATURE_XSAVE)) + panic("XSAVE has to be disabled as it is not supported by this module.\n" + "Please add 'noxsave' to the kernel command line.\n"); + + real_mode_header = &hv_vtl_real_mode_header; + apic->wakeup_secondary_cpu_64 = hv_vtl_wakeup_secondary_cpu; + + return 0; +} +early_initcall(hv_vtl_early_init); diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h index 35b16b177035..4af218e70395 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -11,6 +11,10 @@ #include #include +#define HV_VTL_NORMAL 0x0 +#define HV_VTL_SECURE 0x1 +#define HV_VTL_MGMT 0x2 + union hv_ghcb; DECLARE_STATIC_KEY_FALSE(isolation_type_snp); @@ -272,6 +276,12 @@ static inline int hv_set_mem_host_visibility(unsigned long addr, int numpages, #endif /* CONFIG_HYPERV */ +#ifdef CONFIG_HYPERV_VTL_MODE +void __init hv_vtl_init_platform(void); +#else +static inline void __init hv_vtl_init_platform(void) {} +#endif + #include #endif diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index 61363ce0b335..0dd385cdc332 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -520,6 +520,7 @@ static void __init ms_hyperv_init_platform(void) /* Register Hyper-V specific clocksource */ hv_init_clocksource(); + hv_vtl_init_platform(); #endif /* * TSC should be marked as unstable only after Hyper-V From patchwork Mon Mar 20 10:03:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saurabh Singh Sengar X-Patchwork-Id: 72077 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1133026wrt; Mon, 20 Mar 2023 03:27:33 -0700 (PDT) X-Google-Smtp-Source: AK7set8Xx+dMV0Z9o55h//RqAUFmmy36wJGxfA8BPO581XVuBvZjQUVoUKyY1fGMl33xBm65XGcN X-Received: by 2002:a62:7b4b:0:b0:625:c048:2f81 with SMTP id w72-20020a627b4b000000b00625c0482f81mr13809759pfc.32.1679308052890; Mon, 20 Mar 2023 03:27:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679308052; cv=none; d=google.com; s=arc-20160816; b=bdwfDWNZfbMmSeE95ixwA4fd7zcMd9d3z0+BEuZ2+G0DAbEsd3niAWv8+Ts/TMzZL1 nM6ZqiwWsS9g4iyMGl4/GRlTcFy4dV3t6TSEHVnkSKqRx8fwQkzb9Ls/dvLdiqCp++Wf r+rAUPZk48q3IG8wpHtGne4qcS1ipIyfd7sJ7cFL8olj7xDNukgyFUUeeaBP9LL37n4j WSvNZ8kK/3mvI476/0o/Ik1/a286xGkIhw2wKljmCvLeVUF96ZYYA+Hg/yhfqbbDDlme gBYdz2Rh6ULatW9CSjuBdn4tqy7r2gFDxegLH5+Bxj36GDIe1wJhLKUY7cJl3RpF336q tOyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :to:from:dkim-signature:dkim-filter; bh=m8jjVQgvGPJQeoOJeABcx5K8xClDg9B7AC1Hcldbrs8=; b=RnGFmsedtfKu39QwvEwd9UD+cN+y2HqLyqIVy5mnPenMjUPXzYGsZliP87mVQ+12rA 8uxMywZRIkpfc1Y0Fhgf8yv0jAmzAEheccctFtagjH8arbK8ynONo5OiFRzdBGHAV10U 8g/6qp86TqVwPMIBenOE27xg8w0oCs2OX78kd0OAYc4V1t/tMfuyUwBZRUnmxu49iRmr O9otUFWEvil0O96aM59mEx5e5jyQSAbUNsWbKqrylf4Xi/FZsQwFicEtrxHPF90MCrlv 0ZgtsHWG7V0W6mZcpGMJyoG/OGYvT7vzhL4mtdJnN+Zv8cZZUZqbJG1p6yCFhZggUbiY iwcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=MUoybISV; 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=NONE dis=NONE) header.from=linux.microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x5-20020a654145000000b004fbb899417dsi9691256pgp.851.2023.03.20.03.27.19; Mon, 20 Mar 2023 03:27:32 -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=@linux.microsoft.com header.s=default header.b=MUoybISV; 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=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230030AbjCTKF7 (ORCPT + 99 others); Mon, 20 Mar 2023 06:05:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230041AbjCTKFd (ORCPT ); Mon, 20 Mar 2023 06:05:33 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 79601244B3; Mon, 20 Mar 2023 03:04:49 -0700 (PDT) Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id 400B920FAEE0; Mon, 20 Mar 2023 03:03:43 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 400B920FAEE0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1679306623; bh=m8jjVQgvGPJQeoOJeABcx5K8xClDg9B7AC1Hcldbrs8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=MUoybISV2S+ERAmGjzyKq7Wdl8ucOSzVHudOtGJVcZepbSFWVn1W9upTtGRLgyA+k lUdlObmhHMu870qd0yXxcBF6RwRxdfcy8Mef1FPL7upOnzKmm9y2Kr/Udy9DhA7gHo uIeYdlneVs5pRJyWI9RXcS9yVCYrwt5oxiHyd3O4= From: Saurabh Sengar To: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, arnd@arndb.de, tiala@microsoft.com, mikelley@microsoft.com, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-arch@vger.kernel.org Subject: [PATCH v3 5/5] x86/Kconfig: Add HYPERV_VTL_MODE Date: Mon, 20 Mar 2023 03:03:38 -0700 Message-Id: <1679306618-31484-6-git-send-email-ssengar@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1679306618-31484-1-git-send-email-ssengar@linux.microsoft.com> References: <1679306618-31484-1-git-send-email-ssengar@linux.microsoft.com> X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760882120543451981?= X-GMAIL-MSGID: =?utf-8?q?1760882120543451981?= Add HYPERV_VTL_MODE Kconfig flag for VTL mode. Signed-off-by: Saurabh Sengar --- arch/x86/Kconfig | 24 ++++++++++++++++++++++++ arch/x86/hyperv/Makefile | 1 + 2 files changed, 25 insertions(+) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 453f462f6c9c..c3faaaea1e31 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -782,6 +782,30 @@ menuconfig HYPERVISOR_GUEST if HYPERVISOR_GUEST +config HYPERV_VTL_MODE + bool "Enable Linux to boot in VTL context" + depends on X86_64 && HYPERV + default n + help + Virtual Secure Mode (VSM) is a set of hypervisor capabilities and + enlightenments offered to host and guest partitions which enables + the creation and management of new security boundaries within + operating system software. + + VSM achieves and maintains isolation through Virtual Trust Levels + (VTLs). Virtual Trust Levels are hierarchical, with higher levels + being more privileged than lower levels. VTL0 is the least privileged + level, and currently only other level supported is VTL2. + + Select this option to build a Linux kernel to run at a VTL other than + the normal VTL0, which currently is only VTL2. This option + initializes the x86 platform for VTL2, and adds the ability to boot + secondary CPUs directly into 64-bit context as required for VTLs other + than 0. A kernel built with this option must run at VTL2, and will + not run as a normal guest. + + If unsure, say N + config PARAVIRT bool "Enable paravirtualization code" depends on HAVE_STATIC_CALL diff --git a/arch/x86/hyperv/Makefile b/arch/x86/hyperv/Makefile index 5d2de10809ae..3a1548054b48 100644 --- a/arch/x86/hyperv/Makefile +++ b/arch/x86/hyperv/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only obj-y := hv_init.o mmu.o nested.o irqdomain.o ivm.o obj-$(CONFIG_X86_64) += hv_apic.o hv_proc.o +obj-$(CONFIG_HYPERV_VTL_MODE) += hv_vtl.o ifdef CONFIG_X86_64 obj-$(CONFIG_PARAVIRT_SPINLOCKS) += hv_spinlock.o