From patchwork Tue Apr 11 05:55:28 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: 81751 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2355061vqo; Mon, 10 Apr 2023 23:03:13 -0700 (PDT) X-Google-Smtp-Source: AKy350ZoqQzIbeb9sJbYnJM6cKiTGNBtPbl7MgQozp3UoIWU8tM0djcMFmawRIX3mdbe+JX0XGms X-Received: by 2002:a17:906:90d4:b0:94a:7696:4188 with SMTP id v20-20020a17090690d400b0094a76964188mr1204315ejw.74.1681192993136; Mon, 10 Apr 2023 23:03:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681192993; cv=none; d=google.com; s=arc-20160816; b=QVSApaOQ8RDj2F0VsGDVZ/xZQXypooGHMkHtDLEoJil257h0+1mFjlrvUhkcuKwgjl TULzqaZdv4MMK879vbwsKmsD0CFrPl2PcAlKDDBnzDng/j+rZcr8cuJHk0qZjCt4MN8V 7UpZsTB+Fz1uH7fRLlTYrmf+/xS5zoeN44JCzRMjYklCGebuPi+Ep7Kgn+0++NH0DrSc WdxvDOWHptSSO1DyjUBet83e9Kbu1ZdG7mpfp09pmxjEi0WgSicNafmm9gXbkyRk/KR3 2oh7dG7Si8EtPhRsiTGJfc1gvKh3kZLzg9unqidEn3DzTse+6eQLc+JUz+TjGi9qTB50 qRcw== 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=sYN20W6hPtwdUe2Zl//cBVNvF4+/oIZeshaAhbV6svU=; b=Hc6330OtPgc6t5UG29j0lFSToIPjPeybcMq5XU9kBO5II8errnj4z8ow3Fk3ZorHtw SjA1E2r0Z+jx4ZWyWjV5FcRUvvCTBO9GVN0cKoGbZrQ0KPoEY4uXn+UAdKU1h+pgCVt0 AtqyWgsvMmbHBL0+IILajXkk22pSdrQA9N5GIR7DfgTgOiEYhHgh42FdqH0yWpfIyU5e mbcVdJtWJDyBcxiMS3ZZxIXIF4J6p5O7JAI7LKwEJ4ekmeRJWlZ6v2hnHVuwtsy3kCCP GAqbjmVYMQbEApuWV8ctWXsBBbuH8MaVpsWqh68ggy7CqsggFXhp8Ulij/sNEQEYinhJ /s+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=idzwUv6G; 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 tx27-20020a1709078e9b00b0094a6cf63d3dsi1663923ejc.517.2023.04.10.23.02.48; Mon, 10 Apr 2023 23:03:13 -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=idzwUv6G; 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 S230099AbjDKFzo (ORCPT + 99 others); Tue, 11 Apr 2023 01:55:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229745AbjDKFzi (ORCPT ); Tue, 11 Apr 2023 01:55:38 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E32B3E6A; Mon, 10 Apr 2023 22:55:37 -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 11C622174E4C; Mon, 10 Apr 2023 22:55:36 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 11C622174E4C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1681192536; bh=sYN20W6hPtwdUe2Zl//cBVNvF4+/oIZeshaAhbV6svU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=idzwUv6Gsdkg0wnyQqpq5lQkOeM6LIXE5fuooJdMtIHc+LywW6HD5zD3UO4eknCiq v+/jYfSZQZb34Coj6puOwdMHmRyFkhm35IT4ASF9xJbKdsdd2d82VeJG95k1REsFpW ropd9J62LPnJs9RMsXECXs+SZJGiOqm+E+25n7MU= 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, jgross@suse.com, mat.jonczyk@o2.pl Subject: [PATCH v5 1/5] x86/init: Make get/set_rtc_noop() public Date: Mon, 10 Apr 2023 22:55:28 -0700 Message-Id: <1681192532-15460-2-git-send-email-ssengar@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1681192532-15460-1-git-send-email-ssengar@linux.microsoft.com> References: <1681192532-15460-1-git-send-email-ssengar@linux.microsoft.com> X-Spam-Status: No, score=-17.9 required=5.0 tests=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=unavailable 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?1762858624077243788?= X-GMAIL-MSGID: =?utf-8?q?1762858624077243788?= 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 Acked-by: Borislav Petkov (AMD) --- 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 acc20ae4079d..88085f369ff6 100644 --- a/arch/x86/include/asm/x86_init.h +++ b/arch/x86/include/asm/x86_init.h @@ -330,5 +330,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 95be3831df73..d82f4fa2f1bf 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 Tue Apr 11 05:55:29 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: 81752 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2355601vqo; Mon, 10 Apr 2023 23:04:21 -0700 (PDT) X-Google-Smtp-Source: AKy350aScAL6eHuJ8/nNAW9cCIu5ImrqWC7IW+R8GdXtH4FSvdrbOpfeE6KRyutRKLNlqFKtYsDj X-Received: by 2002:a17:906:6b8d:b0:94a:75d6:64b6 with SMTP id l13-20020a1709066b8d00b0094a75d664b6mr6127541ejr.17.1681193061394; Mon, 10 Apr 2023 23:04:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681193061; cv=none; d=google.com; s=arc-20160816; b=Tc6hLvo1Inr557dS4AsyUobkpwjlQ0r0n7pMG55rLTFnDqapGJglUwPYxm2NxrtWJc PAWJxsM1NbzwSDjBQvsah5jcOsLBR1sYWETDXVBSchsUSNsscLHEKaYHrshe1ZVAUzhd Sk6zuEirxFoiLqVdhPD/yIqap6O/kG3lAXo+dbeVREYMpRjInwBfX991CZGCHhMJ6uqE 3TzvYLZHlKCI9P/FLvvvUl6x/mFsMnau60YkIzib5iMRrRhrDZfzran2016IExFU9vfx Cwn/vut8zaWrHuRvwn7cLTVQ37zi6f0haD/aapWxP9ObRR66Alhgwv1Dg8dlE5F7H1+M g48w== 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=KkJORnzMR+CBheAYPQesJLR4S70FDAPfCyfgXX/hmQw=; b=VtV+BtCW4uUZAcpGQ1Ax4YBgh9IhEGLsWzXmnokr5dGOJM6nrqDQGNeQDwobhStOez xtxQ1++hmC+0dBy/1kgYkifNsUCPiPdQq5E+k+PFBQzVDWSYWZZ3ZkMkeGP+FClF/dHz ZuK2e0N8yiVZ/nnS9BVrSnenWjxHYqg8GE91ioD7kA7GOQbfNBLPSOE5lPbn9AW8BNvO 562TVJOQJ5x6DAvVR7NXRQ985YcXLjWMMjOB4X+GaHt0/dfBndcXOkc1koxGOEH1dIAI 6ZtPZH+Xb8ac2jwaqSiuFvR8A7d2qO/gSpZcwkCGE7Z3iRZH1ATm71THcFX9ws0b6aKo 7oxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=OapdhksH; 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 s15-20020aa7c54f000000b004af515d5657si10931473edr.61.2023.04.10.23.03.57; Mon, 10 Apr 2023 23:04:21 -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=OapdhksH; 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 S230172AbjDKFzx (ORCPT + 99 others); Tue, 11 Apr 2023 01:55:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229915AbjDKFzj (ORCPT ); Tue, 11 Apr 2023 01:55:39 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E3EE5E7A; Mon, 10 Apr 2023 22:55:37 -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 2C2C42174E4E; Mon, 10 Apr 2023 22:55:36 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 2C2C42174E4E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1681192536; bh=KkJORnzMR+CBheAYPQesJLR4S70FDAPfCyfgXX/hmQw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=OapdhksHiAtrdnMXpvnfZMVKRMw6PPD1nbRuG7X1WL4uLwvObFAkC/T3gyXx+YVwd FwCqp1/wHyMuZ89jBfGyzIAiK1Vl/bJlsr3ZCK2bF62oSz6Hd8/KgOL4/TsGEsGDLZ DrYhYGvJJwUVsp4wd3C4Ob7ieWS0csMe1zy8ZtOg= 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, jgross@suse.com, mat.jonczyk@o2.pl Subject: [PATCH v5 2/5] x86/hyperv: Add VTL specific structs and hypercalls Date: Mon, 10 Apr 2023 22:55:29 -0700 Message-Id: <1681192532-15460-3-git-send-email-ssengar@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1681192532-15460-1-git-send-email-ssengar@linux.microsoft.com> References: <1681192532-15460-1-git-send-email-ssengar@linux.microsoft.com> X-Spam-Status: No, score=-17.9 required=5.0 tests=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=unavailable 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?1762858695825856615?= X-GMAIL-MSGID: =?utf-8?q?1762858695825856615?= Add structs and hypercalls required to enable VTL support on x86. Signed-off-by: Saurabh Sengar Reviewed-by: Michael Kelley Reviewed-by: Stanislav Kinsburskii --- [V5] - __u64/__u16 -> u64/u16 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..a493fbdb38ef 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 Tue Apr 11 05:55:30 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: 81750 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2352471vqo; Mon, 10 Apr 2023 22:57:45 -0700 (PDT) X-Google-Smtp-Source: AKy350ZPmW7HE2a5zJSXGQLWZqW9/VuhLkduicsj5zBh87i7/2vIol/T+WaW7VkcrYCMqNFFLLaQ X-Received: by 2002:a17:907:2d0f:b0:94a:5d49:6f9f with SMTP id gs15-20020a1709072d0f00b0094a5d496f9fmr8937489ejc.52.1681192664957; Mon, 10 Apr 2023 22:57:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681192664; cv=none; d=google.com; s=arc-20160816; b=D3QgbhZcMn6iGzBypNLQ9mLH1UegtFCfwfVoq+nTkPsA5sB7ZbYlD9sW/e7NTz6sJK tKV4asePac5ndt1lbcEW8+E/hfAcLMd471Bi+38k0Bqt7kaTpHFbDYibxTYRWOf/mD1P M+FzEzyCsGU+oyHj0weiNxLRaOEdb+5vS0XE6DNjriMPXEK1u+zaCj3TgttNnOlGAEiA 2pAHxxlNZEKuL6gyJxcbIiBk8apKbCiDI6yp04LmnC4W/ik5f1lqr/w4OJ0iXh/lmRDQ 7FfFzUJF4xYu+XiIFHHOtXsiXjU6tuEn5yQ0MD4hyojP4D2NFYTX9WFOIcbpULVDGJVo RmVQ== 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=lolaL0ucqGcng5SGGnPtcnPytbtw0ZL9CTqusc/YQDI=; b=xiizeSuiQ7Qd4tu8NTmdl5uJJ4r5oDgvFKWh4VceNwfC5yjduM8w+PAk3xuga1WcTu y1t/NhIUaC2vJt8R0XvOSAvwBf950OhqVla9LuWqz5f9ucn7XU5ksi6UxCp8Zw8egEwR HGCSE7VkSflhUyArHfbz1U70vfSiJ8tnuK5VrBg/J/kO3Ok/Z/FUDyqctbsZ4YuGviEF tlTANYnLI+pWl37ZvMLI8lA4C/z2hB+6eR6moGEPKf56VITNx5/L+aucQDxJcpa/9ejt gbX1nChsRhTAOjjbu+MZwC7YJqLUDqVg0tPzvd+2uBVsAV6VKfHYJShRUSL519v0Eb50 G4cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=BXwvquHt; 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 sd35-20020a1709076e2300b0094a8988e37dsi99813ejc.151.2023.04.10.22.57.21; Mon, 10 Apr 2023 22:57: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=BXwvquHt; 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 S229721AbjDKFzr (ORCPT + 99 others); Tue, 11 Apr 2023 01:55:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229800AbjDKFzj (ORCPT ); Tue, 11 Apr 2023 01:55:39 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E43AB10D4; Mon, 10 Apr 2023 22:55:37 -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 455842174E4F; Mon, 10 Apr 2023 22:55:36 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 455842174E4F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1681192536; bh=lolaL0ucqGcng5SGGnPtcnPytbtw0ZL9CTqusc/YQDI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=BXwvquHtBr6Re8VjeCHtAyVRWvmmFwNiveyrm2zQJqsemISfeG9+UPHF350niuhS/ 4fx3fnGARBS21c3ZDSpcszDb9XMSfV+Dc+sjTTIm+zOf/6Q0DrW4vsWhxF+vGgAZL9 8ZSDdYOrapI72yk4H1xW8wyx4oJevCuGoyMgXBkQ= 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, jgross@suse.com, mat.jonczyk@o2.pl Subject: [PATCH v5 3/5] x86/hyperv: Make hv_get_nmi_reason public Date: Mon, 10 Apr 2023 22:55:30 -0700 Message-Id: <1681192532-15460-4-git-send-email-ssengar@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1681192532-15460-1-git-send-email-ssengar@linux.microsoft.com> References: <1681192532-15460-1-git-send-email-ssengar@linux.microsoft.com> X-Spam-Status: No, score=-17.9 required=5.0 tests=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=unavailable 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?1762858279829628062?= X-GMAIL-MSGID: =?utf-8?q?1762858279829628062?= 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 e3cef98a0142..71ed240ef66d 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -189,6 +189,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 315fc358e584..5ee02af57dac 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -249,11 +249,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 Tue Apr 11 05:55:31 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: 81749 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2352476vqo; Mon, 10 Apr 2023 22:57:46 -0700 (PDT) X-Google-Smtp-Source: AKy350b/Jo7ujPuopPBr2uEY7ssMfkzO9b7urIJO+Mf2p9K7E7wR7g/HR78Wsm2GG3DM4+9IIt8v X-Received: by 2002:a17:906:ee1:b0:939:4c86:d47b with SMTP id x1-20020a1709060ee100b009394c86d47bmr9771457eji.19.1681192666000; Mon, 10 Apr 2023 22:57:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681192665; cv=none; d=google.com; s=arc-20160816; b=BghR3Kr8TuYvMJOM4Gl1wwAbo1lc+lV0EItJfs4sEgMf7BEO0Z65qMiADOMoO11UUL ppq+DtRkvhXcn14ufO6pfvP+p2eaBnBK0QEP5ohPkgwUUryhHdeBFUjGofkzpoSxKn9D NYzmhd3yCHAoUB1zGkZ2Uqtpezmah/wymUbQaJfVT64tPW6uOV8N6SZ4McT0jahf9w0h XxAalTB09lfOAYTbFNVKf5pnEZBoIhMYW8oAD0PpoKTa2Cfn3HSbG66UN9qwep+tqYun QF5GfkmiSHnTNY2MtyNctmxl7Uj1k4cXdH4vFY5Ze3C4zBxTr6pJLKe1Im+TdyslxucM dlIQ== 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=2v3Futr2TrTut2gyPVUY322R/kDTCpaOa1lUm2Z5nAs=; b=YxFBxSKoEeBhOlPRt6CnWAsfbt57GpmaDB2orsJGArbqDdPMYP1/fTmfwjlHKQtf9v p7yIGaI2GbBuPwaz7wRWqCzBwOr/4u2H+EkwcnPMCSVy9f0SpIVonEVFIU7WU7PZuGPu 6JpFTcw4MKQGIIfFV4HBCI/qyY1lBvoEOksyVRwnEjlQg0DNv7MHGO/62Eo7VTSiOZ/9 eIpU5vJOnKUTf1IOJzc0g6woUNHTLoCs0AP14sMBngEU/b3TQHPnq4hueDCBmKgZbnFe b7F3y/DbI1ZQe6eLhJLYEgp62aEFpkbboq0nlhM7HayJpcfXsnG6IQH6oZzhgy8eKNOn mc/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=eiKKFA1C; 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 w25-20020a17090649d900b0093defbd6273si10732545ejv.1018.2023.04.10.22.57.22; Mon, 10 Apr 2023 22:57:45 -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=eiKKFA1C; 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 S230134AbjDKFzu (ORCPT + 99 others); Tue, 11 Apr 2023 01:55:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229896AbjDKFzj (ORCPT ); Tue, 11 Apr 2023 01:55:39 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E40C910C3; Mon, 10 Apr 2023 22:55:37 -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 5EA3A2174E57; Mon, 10 Apr 2023 22:55:36 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 5EA3A2174E57 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1681192536; bh=2v3Futr2TrTut2gyPVUY322R/kDTCpaOa1lUm2Z5nAs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=eiKKFA1CgTkKePZRAgR/Ll6+Wg8vytcKeVzze4J4U1C1F9Qn29ciDRqjBLE500Qr2 VWtMhx+o0pFI6lxjnwG7fSbHtt437kT7j3kPlerGXQUojE6sZV7LGqRueOch4BzDkU YxxxoZa7exQrOP9vJE9ahP6aVsuTM52iSBCsYQzE= 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, jgross@suse.com, mat.jonczyk@o2.pl Subject: [PATCH v5 4/5] Drivers: hv: Kconfig: Add HYPERV_VTL_MODE Date: Mon, 10 Apr 2023 22:55:31 -0700 Message-Id: <1681192532-15460-5-git-send-email-ssengar@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1681192532-15460-1-git-send-email-ssengar@linux.microsoft.com> References: <1681192532-15460-1-git-send-email-ssengar@linux.microsoft.com> X-Spam-Status: No, score=-17.9 required=5.0 tests=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=unavailable 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?1762858280550337893?= X-GMAIL-MSGID: =?utf-8?q?1762858280550337893?= Add HYPERV_VTL_MODE Kconfig flag for VTL mode. Signed-off-by: Saurabh Sengar Reviewed-by: Michael Kelley --- drivers/hv/Kconfig | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/hv/Kconfig b/drivers/hv/Kconfig index 0747a8f1fcee..511f2e012c59 100644 --- a/drivers/hv/Kconfig +++ b/drivers/hv/Kconfig @@ -13,6 +13,30 @@ config HYPERV Select this option to run Linux as a Hyper-V client operating system. +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 HYPERV_TIMER def_bool HYPERV && X86 From patchwork Tue Apr 11 05:55:32 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: 81753 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2356828vqo; Mon, 10 Apr 2023 23:07:01 -0700 (PDT) X-Google-Smtp-Source: AKy350amxqOfQFFdz1n4DOxNzzI+CDrsaEwQDgmMeolbnhC1tWj6sHy/B0hlqsnzdY29Mi8MuhHD X-Received: by 2002:aa7:9ec5:0:b0:63a:b035:8bf2 with SMTP id r5-20020aa79ec5000000b0063ab0358bf2mr3100773pfq.4.1681193221337; Mon, 10 Apr 2023 23:07:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681193221; cv=none; d=google.com; s=arc-20160816; b=FuTHzXUimPB4/tJs2zXtPhMjtDhz5tOAi4nQUpWbupZKMNSJEDpPvqeizfAmQi85+3 ciwXHnYIbFeObEzerqlsUQgY2FQE2Bmv/RySsjJglOtHOsS2ryzXrybUS/FELFXEBeyr Bds9+CuM6k6mwyOAPIkjKaSsPECmYIzhjgD2rnkNlYVBggEpoiv3YmHPI6Tvmc08sDnH z68M3c3LYfQIuh1GG1lCG8i08DJ73kQPyywCKfz8Bh3o0Gf4ytPOWnqzXvmcZe1pWO1t J/PK3MfP4XLiaFzC05d9A7lpNR8PKrr9ZgMuJUmWWttcB0+cUEKzVLoURPCMw3tkYOLx JFRQ== 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=kOT3ibvD8lYQupJbVimNWJ394pTLR6UA9Inug5i1mHs=; b=XH28uAf5WR3w8iFitQ7WsuS8XIRiuohBFEjCPbAKbFXE3QGhKp+XDh6YFxfKnytahz jTNG68Iax23ins/rKVokZ9km7LGZomrqdnj2E0SCCoBu0wjIYd8bVRsQ9nUA8BRmbqk+ Jx6dX4PZpvFsDaMneOmEnrpyoyW7KmAC0JsGHHjXiLaheVqlsq3OQqCx0rXHbZ9so48S NbaxgVu9HctIoMdpo+UjHGtuILTLOwUKGQhZSdkAA/Zfq58Uyu8SddNu0p1S1U++TLWV WXDMw35NIKq8DTYPkXpU50vUchKM4QN2lCEBwdYSnlYNyvFzQj7uh4rN/TGovC6UQBpO t0QA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=AjaoVE+A; 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 200-20020a6219d1000000b00637e7c7fd8bsi4380097pfz.393.2023.04.10.23.06.48; Mon, 10 Apr 2023 23:07:01 -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=AjaoVE+A; 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 S230159AbjDKFz5 (ORCPT + 99 others); Tue, 11 Apr 2023 01:55:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229485AbjDKFzk (ORCPT ); Tue, 11 Apr 2023 01:55:40 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2A81B10DA; Mon, 10 Apr 2023 22:55:39 -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 77E952174E58; Mon, 10 Apr 2023 22:55:36 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 77E952174E58 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1681192536; bh=kOT3ibvD8lYQupJbVimNWJ394pTLR6UA9Inug5i1mHs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=AjaoVE+AQv84DM10aWK1r2yI6XwDtpYm3LcJZihcAatb6AocNgrCpOJT7pgQtqbos SkqzcqiQ8QxfBiotpnybbQB/tRucTpRy5uQ3jCx6XHbw7/fMEEGHHCSjQuFd8PtLj6 YioybGOxUnZS2Mrg3zV9bvX0kqvLftErEEwcRSpw= 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, jgross@suse.com, mat.jonczyk@o2.pl Subject: [PATCH v5 5/5] x86/hyperv: VTL support for Hyper-V Date: Mon, 10 Apr 2023 22:55:32 -0700 Message-Id: <1681192532-15460-6-git-send-email-ssengar@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1681192532-15460-1-git-send-email-ssengar@linux.microsoft.com> References: <1681192532-15460-1-git-send-email-ssengar@linux.microsoft.com> X-Spam-Status: No, score=-17.9 required=5.0 tests=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=unavailable 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?1762858863454618306?= X-GMAIL-MSGID: =?utf-8?q?1762858863454618306?= 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 Reviewed-by: Michael Kelley Reviewed-by: Stanislav Kinsburskii --- arch/x86/hyperv/Makefile | 1 + arch/x86/hyperv/hv_vtl.c | 227 ++++++++++++++++++++++++++++++++ arch/x86/include/asm/mshyperv.h | 10 ++ arch/x86/kernel/cpu/mshyperv.c | 1 + 4 files changed, 239 insertions(+) create mode 100644 arch/x86/hyperv/hv_vtl.c 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 diff --git a/arch/x86/hyperv/hv_vtl.c b/arch/x86/hyperv/hv_vtl.c new file mode 100644 index 000000000000..1ba5d3b99b16 --- /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 = current->thread.sp; + 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 71ed240ef66d..de4ad38f7d74 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -19,6 +19,10 @@ */ #define HV_IOAPIC_BASE_ADDRESS 0xfec00000 +#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); @@ -276,6 +280,12 @@ static inline u64 hv_get_non_nested_register(unsigned int reg) { return 0; } #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 5ee02af57dac..5180e3c50184 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -519,6 +519,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