From patchwork Thu Jun 1 15:16:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 102042 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp424695vqr; Thu, 1 Jun 2023 08:42:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4D9WmNxZlSuwvo3ubT7r/fOyDeLZDIxT5DLNKzDhmep27WHbG7wdZR7a4VEYZ/91s7ogjV X-Received: by 2002:a05:6a00:a8e:b0:64c:c841:4e8a with SMTP id b14-20020a056a000a8e00b0064cc8414e8amr8164653pfl.22.1685634126236; Thu, 01 Jun 2023 08:42:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685634126; cv=none; d=google.com; s=arc-20160816; b=XUAUhufTDdv6+CxODtYodr0IWy3Cr9U7dW0ZXkSd+fMD7uVOupFFwslwx9GLcdmsqU ZSdzoKgK7SzUorBIl527WJUSZoQ7cLq2Ur+JMJStbHhNCmGRTpqP2RkmmeghXlTAbx1V KlmNdYiMwiGB71GDEztOJe3oEL96+vMSqWwC92v1tnQJtL0EFVkELU1tmJuiU7vo5/RR lI/lPrNsgKoyyVafqcQ6XvtdXrIfVT17g1OAddSa9UUMbrNJ70MW2jFPamnE9pbo5BIR qzSudRjIEeUJSG0NGM2Nr+j3A7QBq/B6Go0FcDkNmANXdaC+i0aad8G9hDo0DhqCmk4h PCkw== 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=YFoufzo+VP+qK3F4DVr4gifzCbQzI56y6GSuWTORtz4=; b=bFOhYP+hzmVx9uCvT1SjI3S5O220hXuuKuIC1qODKaR1vn7G/KR1189UEjHU7vd5da C4GAq3lpzHJlM9JAmBNv1em0wSVlGXWoXDPIs+9pg98LL9qkCh5r/FKi1m3viV09GIE7 A1I8W8YXc+wXst4BWc97OHWo4QQ1VW9v+RGL6LsS5btIvBs18KnZxYvmCoWLYykSvxCq c/Ige+hX5boQM6ia8G3tYoNxNz/tx8BwdJ5WRpWdh7fU6PZpMesb12lb0nhbphCjEaxB Y0XumdNE7iVeQWT6iHAZNJmi2OlsPt4x65ijDkoiG6gRZRcWyuNe3wxYiIYxBhhOaRNq D3sQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=j4bndIiP; 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 v3-20020a655c43000000b0053f82f20bb6si2966705pgr.667.2023.06.01.08.41.50; Thu, 01 Jun 2023 08:42:06 -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=j4bndIiP; 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 S234672AbjFAPQj (ORCPT + 99 others); Thu, 1 Jun 2023 11:16:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233267AbjFAPQb (ORCPT ); Thu, 1 Jun 2023 11:16:31 -0400 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB44FB3; Thu, 1 Jun 2023 08:16:29 -0700 (PDT) Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-53404873a19so506938a12.3; Thu, 01 Jun 2023 08:16:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685632589; x=1688224589; 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=YFoufzo+VP+qK3F4DVr4gifzCbQzI56y6GSuWTORtz4=; b=j4bndIiPmBOelXmd3XgnLhCi5CCbbvEhNZtboa4HbAluJRA6HVSwiXKIUlcwwGEQPD TxMN+lplNB8EEhcVg0sh7XIqCocy1tiAojURjn27MPwoBO08DNrNz3RIpiPiAbJ9L/4n 2lBFK2asVqMTzp+6ATM9ie/VmaCQfigd9KevmntLZsXgnweGcz230jUgrQxCjqnvQM5i z01XWeWFafIl5gBbNZNqobmb3u8ZLkN2nR7olNM8mBfKIR4skxUyRqvnL8Yr3YnLGZSP iy7uL8piDjp3hHFn79dyagYdp5pTVdU8BwtfcjmjXnUiN8m3DyutvKexYGhI/RGvQV4W x4wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685632589; x=1688224589; 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=YFoufzo+VP+qK3F4DVr4gifzCbQzI56y6GSuWTORtz4=; b=dMCSBatGUXctyhSmEJ8Jmq9SRuYJlo6k05/8CiJ+yN7Qio8ojl6rK5pH/Zfa9PJXnv sl6rgWYcW/dTTUYetVCJN6FvzIWW9XAj+QVlhALhLrCC06Y6sxVbA5RzHdt81MhJjCgR VH5zVV9U+ewhXotFeqA0wELiScaxG67UwsS3qf3gwnLNG2E4/ZRYdmgdF7c++sSnfDTU 1X5jM4EVdH+/TFUseR+0FhukT/xTPuG+5j8UsRlX6jbEJ44bw6NnZOP9nJn4B98v5la2 l4lpBXylz129KKBPE/ZuZG58pg1U6L4vc5uaXifQmJ5GVYQNGm3V7iqnEVhD53J6rvrF R84Q== X-Gm-Message-State: AC+VfDwVVh6VgDU53zSsmVRPlDPTIHUgpF5ZPP10dSxgQl7GOfbdZf3o 3HkrAlerxYvAcyA4HhJvTLp0AcNmZEwa0g== X-Received: by 2002:a05:6a21:998d:b0:10b:d70d:f96b with SMTP id ve13-20020a056a21998d00b0010bd70df96bmr8574802pzb.3.1685632589154; Thu, 01 Jun 2023 08:16:29 -0700 (PDT) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:9:e0c3:5ec1:4a35:2168]) by smtp.gmail.com with ESMTPSA id f3-20020a635543000000b0051b460fd90fsm3282639pgm.8.2023.06.01.08.16.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jun 2023 08:16:28 -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 1/9] x86/hyperv: Add sev-snp enlightened guest static key Date: Thu, 1 Jun 2023 11:16:14 -0400 Message-Id: <20230601151624.1757616-2-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230601151624.1757616-1-ltykernel@gmail.com> References: <20230601151624.1757616-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_NONE,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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767515489571802675?= X-GMAIL-MSGID: =?utf-8?q?1767515489571802675?= From: Tianyu Lan Introduce static key isolation_type_en_snp for enlightened sev-snp guest check. Signed-off-by: Tianyu Lan --- arch/x86/hyperv/ivm.c | 11 +++++++++++ arch/x86/include/asm/mshyperv.h | 3 +++ arch/x86/kernel/cpu/mshyperv.c | 8 ++++++-- drivers/hv/hv_common.c | 6 ++++++ include/asm-generic/mshyperv.h | 12 +++++++++--- 5 files changed, 35 insertions(+), 5 deletions(-) diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index cc92388b7a99..5d3ee3124e00 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -409,3 +409,14 @@ bool hv_isolation_type_snp(void) { return static_branch_unlikely(&isolation_type_snp); } + +DEFINE_STATIC_KEY_FALSE(isolation_type_en_snp); +/* + * hv_isolation_type_en_snp - Check system runs in the AMD SEV-SNP based + * isolation enlightened VM. + */ +bool hv_isolation_type_en_snp(void) +{ + return static_branch_unlikely(&isolation_type_en_snp); +} + diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h index 49bb4f2bd300..31c476f4e656 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -26,6 +26,7 @@ union hv_ghcb; DECLARE_STATIC_KEY_FALSE(isolation_type_snp); +DECLARE_STATIC_KEY_FALSE(isolation_type_en_snp); typedef int (*hyperv_fill_flush_list_func)( struct hv_guest_mapping_flush_list *flush, @@ -45,6 +46,8 @@ extern void *hv_hypercall_pg; extern u64 hv_current_partition_id; +extern bool hv_isolation_type_en_snp(void); + extern union hv_ghcb * __percpu *hv_ghcb_pg; int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages); diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index c7969e806c64..9186453251f7 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -402,8 +402,12 @@ static void __init ms_hyperv_init_platform(void) pr_info("Hyper-V: Isolation Config: Group A 0x%x, Group B 0x%x\n", ms_hyperv.isolation_config_a, ms_hyperv.isolation_config_b); - if (hv_get_isolation_type() == HV_ISOLATION_TYPE_SNP) + + if (cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) { + static_branch_enable(&isolation_type_en_snp); + } else if (hv_get_isolation_type() == HV_ISOLATION_TYPE_SNP) { static_branch_enable(&isolation_type_snp); + } } if (hv_max_functions_eax >= HYPERV_CPUID_NESTED_FEATURES) { @@ -473,7 +477,7 @@ static void __init ms_hyperv_init_platform(void) #if IS_ENABLED(CONFIG_HYPERV) if ((hv_get_isolation_type() == HV_ISOLATION_TYPE_VBS) || - (hv_get_isolation_type() == HV_ISOLATION_TYPE_SNP)) + ms_hyperv.paravisor_present) hv_vtom_init(); /* * Setup the hook to get control post apic initialization. diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c index 64f9ceca887b..179bc5f5bf52 100644 --- a/drivers/hv/hv_common.c +++ b/drivers/hv/hv_common.c @@ -502,6 +502,12 @@ bool __weak hv_isolation_type_snp(void) } EXPORT_SYMBOL_GPL(hv_isolation_type_snp); +bool __weak hv_isolation_type_en_snp(void) +{ + return false; +} +EXPORT_SYMBOL_GPL(hv_isolation_type_en_snp); + void __weak hv_setup_vmbus_handler(void (*handler)(void)) { } diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h index 402a8c1c202d..d444f831d633 100644 --- a/include/asm-generic/mshyperv.h +++ b/include/asm-generic/mshyperv.h @@ -36,15 +36,21 @@ struct ms_hyperv_info { u32 nested_features; u32 max_vp_index; u32 max_lp_index; - u32 isolation_config_a; + union { + u32 isolation_config_a; + struct { + u32 paravisor_present : 1; + u32 reserved1 : 31; + }; + }; union { u32 isolation_config_b; struct { u32 cvm_type : 4; - u32 reserved1 : 1; + u32 reserved2 : 1; u32 shared_gpa_boundary_active : 1; u32 shared_gpa_boundary_bits : 6; - u32 reserved2 : 20; + u32 reserved3 : 20; }; }; u64 shared_gpa_boundary; From patchwork Thu Jun 1 15:16:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 102041 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp424418vqr; Thu, 1 Jun 2023 08:41:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4utxx7jgKMr0ViNf8psfHs12qa1dFb6p+Q2QjiY/aFL1QUXoqxOUaN1qLDhYsRyeH/4snZ X-Received: by 2002:a17:902:e851:b0:1ac:820e:c34a with SMTP id t17-20020a170902e85100b001ac820ec34amr2788380plg.0.1685634100327; Thu, 01 Jun 2023 08:41:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685634100; cv=none; d=google.com; s=arc-20160816; b=AszHOT2PUqGkLt3aBJgULRTYTPQrhqUwM5yIRgoqwPhejxgASa8YOne52KZvunr9Vw cQAK8JGkT00FYBoPgHrpxNuGCOj92/4gu/oRSkolqI+urRWzMddq3e3C3Pvru1V00FaP /jcB4MISqCxGtbBeq8RCH+OAD3laZlmDkKfoQbvKeuQ3vkU1DhfHX3c35ZLLKY9fxfhd f5aL9zjLMMOvtYDT66B0VFYeH29evd/ZY0jxKNhgW00Kh8yHBt0PVD0Gtz0vLC58w5n0 Dc5/aUQz/jhq/g7UipD7r0yAlCzyVMkyDGYtONIuvbV2AOsgqHavi15jLglyuNIWN8AG Md0g== 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=JWr3WyAHkAhesFIFgHTox4RvNi85iqkYgnLZQ+E6F+M=; b=ZzCevYbBrmAHsEI42/XojQtjdU4Pby+TOxL2G9T+EUC6I5p2anKuEBHlg8yJuaemyz JuKaQG51vJmJw0K21xL9e2OaUU6sznocntLI8/1o4ntGVoANJcLYvOV+6YDknrXyCJI7 U+jBuh2iMvJjMRe+/m0QMDq/dYuXHoRvmWbbKd8/OL+Ty6NuLT7Ydn48R8KB4ln5f8qE wKzlMWzHnrl4M3HveF1Ya1BR54dqUX1s982dMOgXmNPzmYyWV+NC4gBAgeOJhd2hSVVm ZFdfqcJPNTazJvtiswyOKOekpjKytsktifVcKpZeB77cxAFZrbD7aIZtYfN4Z4sJ8+xp 0p9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=XgcPgSjX; 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 s25-20020a63af59000000b0053fa4589ce2si750474pgo.601.2023.06.01.08.41.12; Thu, 01 Jun 2023 08:41:40 -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=XgcPgSjX; 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 S234733AbjFAPQn (ORCPT + 99 others); Thu, 1 Jun 2023 11:16:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233572AbjFAPQc (ORCPT ); Thu, 1 Jun 2023 11:16:32 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B1FED1; Thu, 1 Jun 2023 08:16:31 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-64fbfe0d037so1737242b3a.0; Thu, 01 Jun 2023 08:16:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685632590; x=1688224590; 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=JWr3WyAHkAhesFIFgHTox4RvNi85iqkYgnLZQ+E6F+M=; b=XgcPgSjX5N0a7pZH5LlDHaJmBwmaJ/rS3QXHJxYWcFCjmBmj1Ljp5N7knJY6VZ7NF7 6A6/cOOSXyt2QVuwL4egH9IrqIu2seTPU8gKCJYJ29dqb92yTpNyFOUxQYf5uxndEYDB zHD1cGUvjzHY80L5MqUcXM7wfLh2QpueDz6G2Mqvnz4IFXcazl03qevSxJVXkTvR+WVO cL3aL5nEjt7QuPuxMF0Zt8I9aejmCQvfotWCJS3GGF3go358eaPzktRNG45P4IW/CaxX qpo6IBiKVx34QnW43EwyvkrSUqCijCOJrdI/I5BgnruKD02TVuqiXPyWN8LZl9EwtOuD Wl1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685632590; x=1688224590; 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=JWr3WyAHkAhesFIFgHTox4RvNi85iqkYgnLZQ+E6F+M=; b=T49s6RhZgmqJnt/9ll6jhLrUhU6KalmN8arBB4T4g+Asl4it2XqIeZmzIsbCsLDJ7d LqvEhl1Q8oG6EJRnjreXYrEtxW80WDH27xeTpLX6DDZ3lIYtesZcaMIc2I+Cdi6jJQ9j T8zWotAhIyGwlMOHgxS6HjrWSfrEXKfNhKre+8Wm1VMrt5M3U+k/Lm6GcnXaTWD9HW+w r5rN/pkYFWpN6v9dylM8hLtaF6esgKH4YdO57+G0Z49m9uJ8t6YUjD6ifTIx7UtYcce/ 6F8c/Y7hQH7azhAiB62Hr46nvXsig29WfvCBJ++7n4D6BO94F1tFNpnIW6sz1m3GI8Bb 6S8w== X-Gm-Message-State: AC+VfDy0IL/fHY4dY8OXgNwExpvM+lBr/3+9qc8dUsE72RV+7LEcw8G+ JD4aCp7oLC8Bxc6d6XqfkrI= X-Received: by 2002:a05:6a20:101a:b0:103:b436:aef7 with SMTP id gs26-20020a056a20101a00b00103b436aef7mr2065466pzc.16.1685632590553; Thu, 01 Jun 2023 08:16:30 -0700 (PDT) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:9:e0c3:5ec1:4a35:2168]) by smtp.gmail.com with ESMTPSA id f3-20020a635543000000b0051b460fd90fsm3282639pgm.8.2023.06.01.08.16.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jun 2023 08:16:30 -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 2/9] x86/hyperv: Set Virtual Trust Level in VMBus init message Date: Thu, 1 Jun 2023 11:16:15 -0400 Message-Id: <20230601151624.1757616-3-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230601151624.1757616-1-ltykernel@gmail.com> References: <20230601151624.1757616-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_NONE,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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767515462466046280?= X-GMAIL-MSGID: =?utf-8?q?1767515462466046280?= From: Tianyu Lan SEV-SNP guest provides vtl(Virtual Trust Level) and get it from Hyper-V hvcall via register hvcall HVCALL_ GET_VP_REGISTERS. During initialization of VMBus, vtl needs to be set in the VMBus init message. Signed-off-by: Tianyu Lan --- 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 a5f9474f08e1..b4a2327c823b 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 d444f831d633..c7a90f91c0d3 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; From patchwork Thu Jun 1 15:16:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 102021 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp411555vqr; Thu, 1 Jun 2023 08:22:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5NbeC13J/DLa62wWb1/oU6cyjCYYoMLq2ogtWvoKmiee3K/x6zMMAy0+vhVfF5iDNr5CpV X-Received: by 2002:a17:90a:ce84:b0:253:3975:7a37 with SMTP id g4-20020a17090ace8400b0025339757a37mr2653428pju.9.1685632923475; Thu, 01 Jun 2023 08:22:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685632923; cv=none; d=google.com; s=arc-20160816; b=aRnxQ7IQ1Y1nvj9mMK2OsD5NLNsLxzO5Wky8kdENbayFMK+CyvLlOJhq+5+K7IQDZS jHSpv3wmj1NWXYs7X+AyI7E+T+PCmfUOcW4KircpUxzi0WRiaGr2JtbPOBYiXXS4HQIF Q5Iw3gUtlCxos0xqhwDzQtp47GiXHiED53C3zin6iMcD4Wt45USsePF6IpyuUnJ/h9If 8MigKiPicWK2KzV/ivdX97WxI7HWdW4fvcw9/GaTaydwJf7UfrRLwx90IwAAsLej+3Si 0UUvG+gAfCjeBZr7FEsfha56iL3aXcxfrsRplzh2UyL457dPIDFUCIssBYNYZwRA5uff R7Mg== 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=hZ1tAgcHb7gMFhBpYgj4F/XcDbeqYB3zwGiF2Oyroow=; b=SgY5C+UytfjTw1J2bKUOa0MUnOgDz68Dy3LF71TPG4vKvK4G23mxHsFrfPnEXAbFeE DSXC5VfQNgKDd+JqxL3qi6Em/BXAtzWva25/e7y3ONIZar2Q8W8vRXot2JZU8x8BVmXz sz7i56UIRhVqL5/A5EZkus3Ll770sZ2ugAEekI2nVIWPPIS/h6EZbh3WeDWyEqOGPnSp ROdpAINpvcJP7qVuMJjr/NMHssmDmG338tdVSVdm2d856otSqAbMswq6o6fNE+0YtR+S 8gy9GPq9ulyvy/iIIEbeV7Xmqs5YTDPsbZidcQUvIfPnLvIcC6VjwzZyT12fPlFDTJQh aOZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=DkBCDSqS; 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 gf13-20020a17090ac7cd00b00256a7c340b1si1325482pjb.3.2023.06.01.08.21.51; Thu, 01 Jun 2023 08:22:03 -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=DkBCDSqS; 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 S233018AbjFAPQt (ORCPT + 99 others); Thu, 1 Jun 2023 11:16:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233742AbjFAPQd (ORCPT ); Thu, 1 Jun 2023 11:16:33 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CC0DE2; Thu, 1 Jun 2023 08:16:32 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-64d24136685so819854b3a.1; Thu, 01 Jun 2023 08:16:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685632592; x=1688224592; 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=hZ1tAgcHb7gMFhBpYgj4F/XcDbeqYB3zwGiF2Oyroow=; b=DkBCDSqSP+wa8f/vVeVEvYMom0upaLv1kFHxNE4GX/RQCsu8DIB3Z8gJ0iYnMHqK7r uyKFuT4jQWAqhLzu8PgeGtq67dMF7Lp0elvu6y3CLZ8vLpSLVFquWGzHsRLgYRO3fuON tubEJuSthulCTWPTuSl/gZcRxyCN74LviGiz+Go9BQFR9P6qwrASUYS8ubn6F3kiujwf TB+wJNs+yMjnW5FVTHrtbOZIHlTTIs4KyaeRu/ku+gi5gAljPMFw8FplQXxtPZWxpc7p zbY9JbyB6XeliI1riT8yyyvA1mPv2QWAw++boM9BisobHrVhCRs717qrB1/H9+Vt0BiA 6DkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685632592; x=1688224592; 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=hZ1tAgcHb7gMFhBpYgj4F/XcDbeqYB3zwGiF2Oyroow=; b=ZX7YOPE3TmAvUNgr6Dj0/odKDk60MkR84zeBYt/vJHN+0Rs4YgZtp+hAWmLQee/pe0 ZhrfufLc6BxfgoVmfPLLWOC+XiBKzQPQ9jWyXM2sKWjsOSvdcKTNvfvNQltYQ7XS1TuN GckpWLYGQeR1+EGn/148ngCoEdYb7XfUr+rzj5V3P4ZJxkOlGT4X4qL9AZLThpK1Xj1J 1QpTM9/VqGuI8OscSHAz/MD1OTdx6pkLh7oh3IxjvneLgcaFit5BRKtLUGrHBie2Fh5g EgF+2fvKTVux92KLpojogInQqRzHBhhLCJTpg6efqmgsHeyUOBWLPK0WsN9I4X4yG7kf nvMw== X-Gm-Message-State: AC+VfDyrx1JVt3Hkj7gkjXG0Vl9TJ7LZe4TJB1l1W96mqGf4Xa/9Nzmu +xduFKrlUyU25YEuIaJlouY= X-Received: by 2002:a05:6a20:3d29:b0:10a:dd79:65bd with SMTP id y41-20020a056a203d2900b0010add7965bdmr2473192pzi.27.1685632591660; Thu, 01 Jun 2023 08:16:31 -0700 (PDT) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:9:e0c3:5ec1:4a35:2168]) by smtp.gmail.com with ESMTPSA id f3-20020a635543000000b0051b460fd90fsm3282639pgm.8.2023.06.01.08.16.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jun 2023 08:16:31 -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 3/9] x86/hyperv: Mark Hyper-V vp assist page unencrypted in SEV-SNP enlightened guest Date: Thu, 1 Jun 2023 11:16:16 -0400 Message-Id: <20230601151624.1757616-4-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230601151624.1757616-1-ltykernel@gmail.com> References: <20230601151624.1757616-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_NONE,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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767514228191985323?= X-GMAIL-MSGID: =?utf-8?q?1767514228191985323?= From: Tianyu Lan hv vp assist page needs to be shared between SEV-SNP guest and Hyper-V. So mark the page unencrypted in the SEV-SNP guest. Signed-off-by: Tianyu Lan --- arch/x86/hyperv/hv_init.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index b4a2327c823b..331b855314b7 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -113,6 +114,11 @@ static int hv_cpu_init(unsigned int cpu) } if (!WARN_ON(!(*hvp))) { + if (hv_isolation_type_en_snp()) { + WARN_ON_ONCE(set_memory_decrypted((unsigned long)(*hvp), 1)); + memset(*hvp, 0, PAGE_SIZE); + } + msr.enable = 1; wrmsrl(HV_X64_MSR_VP_ASSIST_PAGE, msr.as_uint64); } From patchwork Thu Jun 1 15:16:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 102038 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp423753vqr; Thu, 1 Jun 2023 08:40:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6yaJTZSwp/IIW2XKTzdze8x818wC3/zwQIGG+keCjbBJ9wtS0GUNEO0P4nm8UXIpjGa6P+ X-Received: by 2002:a17:90a:fd0f:b0:256:c3dc:dae6 with SMTP id cv15-20020a17090afd0f00b00256c3dcdae6mr8445433pjb.31.1685634040921; Thu, 01 Jun 2023 08:40:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685634040; cv=none; d=google.com; s=arc-20160816; b=orQOkYr3zukj2TOY6Waq4o/pyp+VTw7JzVE4Nfdn0l2oXnSCmls0SXO5wixidbOfsz dCLxUuaZefKS7LV7NX8tulMdtnP0lIO88JYvmWAb7/f6R+oVxCTdXQalu6dq8zX2KIjk faWKojpZNIXLcOM4MCct39VM0Me0nczDcCYbzNoFlw1OYqFDFCLJMebEd7VDv+Q7Dg1y sxqPz3aONhv+tDY/qnvH+ufRm19GH08QlGU7RDidUIybBzhkQpVdgkWwVNO1J5mgGS3C r4q4oxgbxIJDi4F1J+gTS3pvCBlYHTaQ0emL+DIvL++4wZzyqDfl4SaBAi03GzSW3wPg 6KFQ== 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=clSqwvV8e8hE1TuhQU11+QhpX7lJNDmKO1n9lfx7mM4=; b=sxHZa6vLo/o4p3imybgEEMOlvDgj7ZhW5W0XkIn7oN6nNbRe1jBrnqIMnTU3/IfXAs smfrav2VlrFg/WZYlqiIqCy3C0mtP8L1RFkhy/dE+nKlgyGBrHViSDfel6uuYpiXk8ks hzhPHpZPAYIASzQYqNIbBpmWTDxB4HQ0J0NZSbHYaqXFTbAyFH5dLrVatLNPo06+4BGT DFg4e1YK7ZqRK446vufM19OpA5WNE//iUUsd0WROp82eyLPPajdoOuyFYzLxuFIHd2b9 KYg71VxHsrcYHT4RUpKXaRLjC/UqEDHTkhbL6x94qgJ4GefhVGmLAs1d+wLkmds7oPla xnBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=OI4ATCIY; 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 o27-20020a63921b000000b0053f0bfcd4fasi3185818pgd.173.2023.06.01.08.40.26; Thu, 01 Jun 2023 08:40:40 -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=OI4ATCIY; 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 S229589AbjFAPQx (ORCPT + 99 others); Thu, 1 Jun 2023 11:16:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234381AbjFAPQh (ORCPT ); Thu, 1 Jun 2023 11:16:37 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74792123; Thu, 1 Jun 2023 08:16:33 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-64d4e4598f0so1147692b3a.2; Thu, 01 Jun 2023 08:16:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685632593; x=1688224593; 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=clSqwvV8e8hE1TuhQU11+QhpX7lJNDmKO1n9lfx7mM4=; b=OI4ATCIYKZicRB0N0Yt8sJeY2C1usR00xZNQlBWNljmBppiqTm3fuHvV2TvUPLWGVM 5/F/XmPbc0A+BIaW2XARN2cb/bzYWd7mtLKERQZVy+ODTG9v8+8tDq3K6F3oksJXxg0F mM11bWWfvJVmTbaygKmhGaQPOdG48kS7eUBbMnxLtqN0O1dlHiBLakNRTcCdZUeIYyfk UoSRPfwYTxhOdE9Rdi/WC279pnApYhoaFfkZw3mA6ejNYL7FAS3GPqWMF09vc+U0Cm8E 72SWYUYbZr7bx2ochiodYR1TbiHj4cJXUyCgmuJRCI6dARsBnB/7h0fv/neaQjaPf+bv ogPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685632593; x=1688224593; 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=clSqwvV8e8hE1TuhQU11+QhpX7lJNDmKO1n9lfx7mM4=; b=VnrGL1LKSzxHL+Lu2XUIEG/TNLlK5ak0pWatrNO3VOanQoIB7aeso17D0l7SziBfPQ VtCJMjEuKjHalJIxx/yssM9aP1H8EzZzpdo29IQCHSQBsCvQfPFu/EwYicgAHSDVhBMY 1kGym3dN9UUISjigDlHUAtzyga5kUz6NIcqObTahJK6zRF9U7yeGWXIVujUtD6io7WD3 g5DtdpRCxUXNbbll752qVMPuxj3L3UkIh0GVcldi6Tb5OJiTKyXd9OwALCnuCzPeA+Vr feeBiGhoBF5QtJICpkoe2Z+5Jl2R/I1BTbmppSYaloGCO6vyuzUXbnYlIr4Zgzfh8/zG Pw+A== X-Gm-Message-State: AC+VfDwpdv+LoeAzfv6DM1g7iJXNaqhZPlfbxKxK9HeytVqGwHR+QTqi 5BXW1AMPHzo6t3RigM8vR20= X-Received: by 2002:a05:6a00:15c7:b0:646:6cc3:4a52 with SMTP id o7-20020a056a0015c700b006466cc34a52mr11759587pfu.3.1685632592889; Thu, 01 Jun 2023 08:16:32 -0700 (PDT) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:9:e0c3:5ec1:4a35:2168]) by smtp.gmail.com with ESMTPSA id f3-20020a635543000000b0051b460fd90fsm3282639pgm.8.2023.06.01.08.16.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jun 2023 08:16:32 -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 4/9] drivers: hv: Mark shared pages unencrypted in SEV-SNP enlightened guest Date: Thu, 1 Jun 2023 11:16:17 -0400 Message-Id: <20230601151624.1757616-5-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230601151624.1757616-1-ltykernel@gmail.com> References: <20230601151624.1757616-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_NONE,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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767515400293629141?= X-GMAIL-MSGID: =?utf-8?q?1767515400293629141?= From: Tianyu Lan Hypervisor needs to access iput arg, VMBus synic event and message pages. Mask these pages unencrypted in the sev-snp guest and free them only if they have been marked encrypted successfully. Signed-off-by: Tianyu Lan --- drivers/hv/hv.c | 57 +++++++++++++++++++++++++++++++++++++++--- drivers/hv/hv_common.c | 24 +++++++++++++++++- 2 files changed, 77 insertions(+), 4 deletions(-) diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index de6708dbe0df..94406dbe0df0 100644 --- a/drivers/hv/hv.c +++ b/drivers/hv/hv.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "hyperv_vmbus.h" /* The one and only */ @@ -78,7 +79,7 @@ int hv_post_message(union hv_connection_id connection_id, int hv_synic_alloc(void) { - int cpu; + int cpu, ret = -ENOMEM; struct hv_per_cpu_context *hv_cpu; /* @@ -123,26 +124,76 @@ int hv_synic_alloc(void) goto err; } } + + if (hv_isolation_type_en_snp()) { + ret = set_memory_decrypted((unsigned long) + hv_cpu->synic_message_page, 1); + if (ret) { + pr_err("Failed to decrypt SYNIC msg page: %d\n", ret); + hv_cpu->synic_message_page = NULL; + + /* + * Free the event page here and not encrypt + * the page in hv_synic_free(). + */ + free_page((unsigned long)hv_cpu->synic_event_page); + hv_cpu->synic_event_page = NULL; + goto err; + } + + ret = set_memory_decrypted((unsigned long) + hv_cpu->synic_event_page, 1); + if (ret) { + pr_err("Failed to decrypt SYNIC event page: %d\n", ret); + hv_cpu->synic_event_page = NULL; + goto err; + } + + memset(hv_cpu->synic_message_page, 0, PAGE_SIZE); + memset(hv_cpu->synic_event_page, 0, PAGE_SIZE); + } } return 0; + err: /* * Any memory allocations that succeeded will be freed when * the caller cleans up by calling hv_synic_free() */ - return -ENOMEM; + return ret; } void hv_synic_free(void) { - int cpu; + int cpu, ret; for_each_present_cpu(cpu) { struct hv_per_cpu_context *hv_cpu = per_cpu_ptr(hv_context.cpu_context, cpu); + /* It's better to leak the page if the encryption fails. */ + if (hv_isolation_type_en_snp()) { + if (hv_cpu->synic_message_page) { + ret = set_memory_encrypted((unsigned long) + hv_cpu->synic_message_page, 1); + if (ret) { + pr_err("Failed to encrypt SYNIC msg page: %d\n", ret); + hv_cpu->synic_message_page = NULL; + } + } + + if (hv_cpu->synic_event_page) { + ret = set_memory_encrypted((unsigned long) + hv_cpu->synic_event_page, 1); + if (ret) { + pr_err("Failed to encrypt SYNIC event page: %d\n", ret); + hv_cpu->synic_event_page = NULL; + } + } + } + free_page((unsigned long)hv_cpu->synic_event_page); free_page((unsigned long)hv_cpu->synic_message_page); } diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c index 179bc5f5bf52..bed9aa6ac19a 100644 --- a/drivers/hv/hv_common.c +++ b/drivers/hv/hv_common.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -359,6 +360,7 @@ int hv_common_cpu_init(unsigned int cpu) u64 msr_vp_index; gfp_t flags; int pgcount = hv_root_partition ? 2 : 1; + int ret; /* hv_cpu_init() can be called with IRQs disabled from hv_resume() */ flags = irqs_disabled() ? GFP_ATOMIC : GFP_KERNEL; @@ -368,6 +370,17 @@ int hv_common_cpu_init(unsigned int cpu) if (!(*inputarg)) return -ENOMEM; + if (hv_isolation_type_en_snp()) { + ret = set_memory_decrypted((unsigned long)*inputarg, pgcount); + if (ret) { + kfree(*inputarg); + *inputarg = NULL; + return ret; + } + + memset(*inputarg, 0x00, pgcount * PAGE_SIZE); + } + if (hv_root_partition) { outputarg = (void **)this_cpu_ptr(hyperv_pcpu_output_arg); *outputarg = (char *)(*inputarg) + HV_HYP_PAGE_SIZE; @@ -387,7 +400,9 @@ int hv_common_cpu_die(unsigned int cpu) { unsigned long flags; void **inputarg, **outputarg; + int pgcount = hv_root_partition ? 2 : 1; void *mem; + int ret; local_irq_save(flags); @@ -402,7 +417,14 @@ int hv_common_cpu_die(unsigned int cpu) local_irq_restore(flags); - kfree(mem); + if (hv_isolation_type_en_snp()) { + ret = set_memory_encrypted((unsigned long)mem, pgcount); + if (ret) + pr_warn("Hyper-V: Failed to encrypt input arg on cpu%d: %d\n", + cpu, ret); + /* It's unsafe to free 'mem'. */ + return 0; + } return 0; } From patchwork Thu Jun 1 15:16:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 102036 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp422690vqr; Thu, 1 Jun 2023 08:38:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4VYXkqH9rPVxTpfrps6SPr+zgLL89IsISd1FCrI1LzpDbTCGrVTOcSVbOXJPch/yFWVN62 X-Received: by 2002:a05:6a00:99e:b0:64d:1585:fff2 with SMTP id u30-20020a056a00099e00b0064d1585fff2mr11428487pfg.29.1685633938975; Thu, 01 Jun 2023 08:38:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685633938; cv=none; d=google.com; s=arc-20160816; b=MmGymvyx2PiQNiVNnXqUgNytzTVo3/b/M2WRmPJMwyq6sa55bGkaXU3pAjxYSBe56z /lWc3eXRCdSymf2HRhnAZUSNd9AXJzaChHSI4ezcBcsA33rFL6fFAlmAAloPifCz57Jd d4kIS19eHJrXMUsrFHRpdxrftiYxxdQ+R8xMNdD3c3f+jXpdNagRgdDvga7tWLRpJF7Z TQxTqHH3W8XjLGwtULlcqkBJIwwg2Zwb9d+0Lu9a6rszcQIZ3HDbMx5aAJt/URXaEHsM d73JDYwD9RVLZw5OpnXu0HkmcXfmawhaPQPRgMOcYDT/9Z4hpp1CaX1vAjCIocE+K281 DgEg== 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=20PfxUIBn5Kpww1WZYnKX4OwKeg7lWWjkFwlEuv9yX8=; b=DE/ZGCFZrFMH4BX74M7AOlFht29rCeXlyL8Qc/F+R96eTC9ryRRtDcQFvBMcikF2hn 3VpEwt3FmkXckgjuj9kV1qcladNGHq9irADJK3Nnwx5zeyIefgU6EC+52kfU9GDbRyw/ LxM/MuGpTjlIgh3tY5MRFM+YFlE+WUWWJiMATI4BPsNSYN3k9XbDN2tshzPRHV+GgxIe 8tLdQWUms+3FpHjYIJq1yTkIcyjv/zvSU6kOCU1B7uEXc79vn1ozCDxYRHydfF9jZ6G7 Y1MYPvsGDasQQueqU2Rmd03P/dr5IOWvZGE4vv+oSLJBEjLncZM/M2wvO8u6rM25ONSn zokw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=mdMXADuP; 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 f127-20020a625185000000b0064d2c5f0995si3584879pfb.235.2023.06.01.08.38.44; Thu, 01 Jun 2023 08:38:58 -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=mdMXADuP; 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 S234764AbjFAPQz (ORCPT + 99 others); Thu, 1 Jun 2023 11:16:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234382AbjFAPQh (ORCPT ); Thu, 1 Jun 2023 11:16:37 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5A4112C; Thu, 1 Jun 2023 08:16:34 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-64d3bc502ddso1205712b3a.0; Thu, 01 Jun 2023 08:16:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685632594; x=1688224594; 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=20PfxUIBn5Kpww1WZYnKX4OwKeg7lWWjkFwlEuv9yX8=; b=mdMXADuPKtg6pZHi4rHdubjEZsdNyUwRcdf+1/mn0YEWGux7/x1eoRpO7JZbRlCKKp njD9GKsWD31Q/nWLjFhxKkJp4kfc5QrPg3eqwWXP8KYpfrrUgsAMjjNKC1qYfZDLatty 7GKUU49SuYeZG8eopqGeb50WCft7zv0NyBWeEn5VdivKfn+rtQ3eSsdp4sHL1uWu0AaW Lp/r1pRl6DPWuzClQkpjIS0Pdj0t+sss5B622u1I+ySyuo01E6ULflRSLRrHg8AyV9cv OsA8mmm58sdp7V/eab3zC2UHQZxBGNMgui41nqLuASPHfLxpDXbggRfotv2EDtajmZPt 9dug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685632594; x=1688224594; 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=20PfxUIBn5Kpww1WZYnKX4OwKeg7lWWjkFwlEuv9yX8=; b=ZyYhsPNFxcob3j/4uv+nJ8woCFuEV+6KVORjL/O2CsLAGv1MNAa2wB5iDGpnh50Fdx SqTDuErSELRbYzVB+djGtKprEPHzZXTdRFxcJJQjt9kHs9OdFQzcWaOm4NYel/D7AM5r MXv4HvdMrFG/VFlYMdyVRNhiCv0htc+xLI8C7hDTThWqrwpOOTb9qngn5NMBaXKFIYL2 3ZEPI09WwG/5PT5rEUy01AYJBndK+bL4S5TGaahbAV0kGJvVvXsp93bEz1v5f3ELFnVM wJ28lIuT3M4d5fJNvPico0abB+0xG/kKvJLXRnbNHpMmNJy2DmxDktPUOaZPqFqfhFcJ V4bw== X-Gm-Message-State: AC+VfDwASh+o1vhICiWJkhUBSsCZguGQLSKF7uVQej9x+rkFRwvzhPcI Ku/ix5Xz5eaXg8yELmmj18Q= X-Received: by 2002:a05:6a20:3d85:b0:100:60f3:2975 with SMTP id s5-20020a056a203d8500b0010060f32975mr11694279pzi.4.1685632594074; Thu, 01 Jun 2023 08:16:34 -0700 (PDT) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:9:e0c3:5ec1:4a35:2168]) by smtp.gmail.com with ESMTPSA id f3-20020a635543000000b0051b460fd90fsm3282639pgm.8.2023.06.01.08.16.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jun 2023 08:16:33 -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 5/9] x86/hyperv: Use vmmcall to implement Hyper-V hypercall in sev-snp enlightened guest Date: Thu, 1 Jun 2023 11:16:18 -0400 Message-Id: <20230601151624.1757616-6-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230601151624.1757616-1-ltykernel@gmail.com> References: <20230601151624.1757616-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_NONE,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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767515293544363911?= X-GMAIL-MSGID: =?utf-8?q?1767515293544363911?= From: Tianyu Lan In sev-snp enlightened guest, Hyper-V hypercall needs to use vmmcall to trigger vmexit and notify hypervisor to handle hypercall request. There is no x86 SEV SNP feature flag support so far and hardware provides MSR_AMD64_SEV register to check SEV-SNP capability with MSR_AMD64_SEV_ENABLED bit. ALTERNATIVE can't work without SEV-SNP x86 feature flag. May add later when the associated flag is introduced. Signed-off-by: Tianyu Lan Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/include/asm/mshyperv.h | 44 ++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h index 31c476f4e656..d859d7c5f5e8 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -61,16 +61,25 @@ static inline u64 hv_do_hypercall(u64 control, void *input, void *output) u64 hv_status; #ifdef CONFIG_X86_64 - if (!hv_hypercall_pg) - return U64_MAX; + if (hv_isolation_type_en_snp()) { + __asm__ __volatile__("mov %4, %%r8\n" + "vmmcall" + : "=a" (hv_status), ASM_CALL_CONSTRAINT, + "+c" (control), "+d" (input_address) + : "r" (output_address) + : "cc", "memory", "r8", "r9", "r10", "r11"); + } else { + if (!hv_hypercall_pg) + return U64_MAX; - __asm__ __volatile__("mov %4, %%r8\n" - CALL_NOSPEC - : "=a" (hv_status), ASM_CALL_CONSTRAINT, - "+c" (control), "+d" (input_address) - : "r" (output_address), - THUNK_TARGET(hv_hypercall_pg) - : "cc", "memory", "r8", "r9", "r10", "r11"); + __asm__ __volatile__("mov %4, %%r8\n" + CALL_NOSPEC + : "=a" (hv_status), ASM_CALL_CONSTRAINT, + "+c" (control), "+d" (input_address) + : "r" (output_address), + THUNK_TARGET(hv_hypercall_pg) + : "cc", "memory", "r8", "r9", "r10", "r11"); + } #else u32 input_address_hi = upper_32_bits(input_address); u32 input_address_lo = lower_32_bits(input_address); @@ -104,7 +113,13 @@ static inline u64 _hv_do_fast_hypercall8(u64 control, u64 input1) u64 hv_status; #ifdef CONFIG_X86_64 - { + if (hv_isolation_type_en_snp()) { + __asm__ __volatile__( + "vmmcall" + : "=a" (hv_status), ASM_CALL_CONSTRAINT, + "+c" (control), "+d" (input1) + :: "cc", "r8", "r9", "r10", "r11"); + } else { __asm__ __volatile__(CALL_NOSPEC : "=a" (hv_status), ASM_CALL_CONSTRAINT, "+c" (control), "+d" (input1) @@ -149,7 +164,14 @@ static inline u64 _hv_do_fast_hypercall16(u64 control, u64 input1, u64 input2) u64 hv_status; #ifdef CONFIG_X86_64 - { + if (hv_isolation_type_en_snp()) { + __asm__ __volatile__("mov %4, %%r8\n" + "vmmcall" + : "=a" (hv_status), ASM_CALL_CONSTRAINT, + "+c" (control), "+d" (input1) + : "r" (input2) + : "cc", "r8", "r9", "r10", "r11"); + } else { __asm__ __volatile__("mov %4, %%r8\n" CALL_NOSPEC : "=a" (hv_status), ASM_CALL_CONSTRAINT, From patchwork Thu Jun 1 15:16:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 102022 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp411981vqr; Thu, 1 Jun 2023 08:22:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7lJA7v+JAQcx5aaLHdi4g+7OymLPZg9f4wDoE0RdQT16bmmBdlVDpTXwg/mdahF1lsWnMt X-Received: by 2002:aa7:88c5:0:b0:640:e12a:3a20 with SMTP id k5-20020aa788c5000000b00640e12a3a20mr9097000pff.1.1685632960736; Thu, 01 Jun 2023 08:22:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685632960; cv=none; d=google.com; s=arc-20160816; b=uFGKiF4FgwRKRj+zi1OFiWCY2PtX7Z3uAXtbIbNEJ7O5EPbBa6mQ1lqTNqUfTpz9Ga NqNQWPxnaxh6nRTaafIMnF53T7mPgWPd5FZutPMkY3cu1g5h5WpLqr8z8t9DMsaMPBQj Ft2l6Tw1tPWzP+bIwJM9a0h0aXQ88lBlaKEGRySQouyrVhXNYloxty5saICUvzq8nRJG ctrpAhSLu2ntb8kzaVpFd41rmhytcRxJiHVFZ+6sHws25J88ytpgdx7arZQgkzMaZ/RZ qBjnHXMx6X1GiVlErPFzhCUnMkgiy3nH/aZP/7mswUbyb+L9H2U4uqGRc/5Opwl6GC7L H5hg== 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=1RKpz5HBE9JLrRBFLWv7AJFc4wm2/SCXversK+BtfEc=; b=H2Y8GLdKbwwpn16IRt0FGoGfcEgFy/cNz2/nsw9HxI1nD5gPcHg/DsAFwxYnh2r7s2 YNI+/woIgi1UtuelSam4uQjXVK7kdq9Vxl03/+15iQqBPjj1d0jJW7QzV282/4vQdvy3 ts/qfuMmfs6Yl9jUv73OTNGBr8fpJvYW/giQ0TDaN1sqe4W9Tcg1h+lnVtmwcL1bVxlv B5jLZcvnDzpte3f0EO4tRgXRgahdcy/XstGmAw9v2/4qhytbmDCrMT/yhrVqe2cksVbQ mgyfJA4NuEXeU/vKfSBoYn1cpKb+KQ9tacAaPWN3N8q4woa1ILPD3kfv3Bs77X/pZqk1 8dhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=rpNN7jcM; 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 e26-20020a056a0000da00b005e1cabb612fsi3561898pfj.67.2023.06.01.08.22.28; Thu, 01 Jun 2023 08:22:40 -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=rpNN7jcM; 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 S233780AbjFAPRR (ORCPT + 99 others); Thu, 1 Jun 2023 11:17:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234463AbjFAPQj (ORCPT ); Thu, 1 Jun 2023 11:16:39 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09D8B128; Thu, 1 Jun 2023 08:16:36 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-64d1a0d640cso650394b3a.1; Thu, 01 Jun 2023 08:16:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685632595; x=1688224595; 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=1RKpz5HBE9JLrRBFLWv7AJFc4wm2/SCXversK+BtfEc=; b=rpNN7jcMESOKM8JeCjmCDw6hCumBxuYudKtp04D9Tyln1yQ5Ydo4A3XiFhHw9MjoyV DpNkjj5yiXVxiOIRaviptlRexiDZvCOsw+U5equZ1TKfHV5mNsW0bRYIMRCDcKSMr2Ig C2X/7NPBdfJaH/imNWXRsof1chGIG98UG7Y7SAHuOHva5SjCZCzBVpjeytB3wWIVjjw1 e1rUcZEVNE/0iB2IFAI9NtYh/r6XGLdoHKGT5KOd4miUbjYcrhIdI02kHQnZhp7nInF9 AtP7CSXCK8WSc4PIOMV3P+KjsZAy8eMxpEXCVkPaiTNamh6gp1lW3qv5/UqSBm/P7C2K HyzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685632595; x=1688224595; 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=1RKpz5HBE9JLrRBFLWv7AJFc4wm2/SCXversK+BtfEc=; b=I3HQ/oidP3HAj6uHvDy420TXbaRJINunDUk3/6qu/21ZEtTGxtYHsjrDL0pa/kEhIr DXPGPpn5Z64eqq6JhvZUlJUzXXYzjlc8M//sWSI9qr/HTq7I4iO/rEAqwa3mGmshhWEn xwq5KxW+gyA+zZ+XBBkC/9RLPUFzCoTeXdLIscx/Uf0OuSKm1AT1UCwZBFVmlPbUUeSW bMX8yEOdHKGsLDZfgw2xVz2cyGeB8tyMId/37C0wj4KGO3pdnVptQZ6LZYRKhLYvoHas 9ps41LC507P724NX7Ig6DtU0M4G0ZZSvVIoBtmuVQLqj4IGjRlpP0/hgiUIscNL+JUK4 MSOg== X-Gm-Message-State: AC+VfDwWQK0gxC196hAz8ldjdvt7tm0TlH12PJQd5ILGCexqo/3PaXlp ftaqVPaJgnPgPFRiFzbO3PU= X-Received: by 2002:a05:6a20:158b:b0:110:6146:1040 with SMTP id h11-20020a056a20158b00b0011061461040mr7581033pzj.4.1685632595368; Thu, 01 Jun 2023 08:16:35 -0700 (PDT) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:9:e0c3:5ec1:4a35:2168]) by smtp.gmail.com with ESMTPSA id f3-20020a635543000000b0051b460fd90fsm3282639pgm.8.2023.06.01.08.16.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jun 2023 08:16:35 -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 6/9] clocksource: hyper-v: Mark hyperv tsc page unencrypted in sev-snp enlightened guest Date: Thu, 1 Jun 2023 11:16:19 -0400 Message-Id: <20230601151624.1757616-7-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230601151624.1757616-1-ltykernel@gmail.com> References: <20230601151624.1757616-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_NONE,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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767514267378396530?= X-GMAIL-MSGID: =?utf-8?q?1767514267378396530?= From: Tianyu Lan Hyper-V tsc page is shared with hypervisor and mark the page unencrypted in sev-snp enlightened guest when it's used. Signed-off-by: Tianyu Lan --- drivers/clocksource/hyperv_timer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/clocksource/hyperv_timer.c b/drivers/clocksource/hyperv_timer.c index bcd9042a0c9f..66e29a19770b 100644 --- a/drivers/clocksource/hyperv_timer.c +++ b/drivers/clocksource/hyperv_timer.c @@ -376,7 +376,7 @@ EXPORT_SYMBOL_GPL(hv_stimer_global_cleanup); static union { struct ms_hyperv_tsc_page page; u8 reserved[PAGE_SIZE]; -} tsc_pg __aligned(PAGE_SIZE); +} tsc_pg __bss_decrypted __aligned(PAGE_SIZE); static struct ms_hyperv_tsc_page *tsc_page = &tsc_pg.page; static unsigned long tsc_pfn; From patchwork Thu Jun 1 15:16:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 102024 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp412447vqr; Thu, 1 Jun 2023 08:23:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4hqsuxCY9/Ad61P1wrWqd25REyf2maCaSQCmvnOUF2IOHu/vHriUaujvdl8HB5keOFMvc/ X-Received: by 2002:a17:902:c94f:b0:1af:b5af:367b with SMTP id i15-20020a170902c94f00b001afb5af367bmr2667789pla.29.1685633002775; Thu, 01 Jun 2023 08:23:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685633002; cv=none; d=google.com; s=arc-20160816; b=E2DkwfEroUdIsfEnUXk/zqei8rWHiequOahtYKJPgMO7pQD918ETbeqxDk/2fDp5De vIOChH+trGp0ykEanLwJzKasjuCruRIh6D3OvTddiMBgDsUWDRW08ZN5CWHbx0iS7kDJ D4DBY1S/bzNw2qHyGbV3DvAFacznbtPY9fJqbU6OUiC08FJxo2OWhO9/qiomXhbcF9kb 71NAOiB+2waiS1Vpgici9n3omwKInt8j6Roboffj7VXzLBbq+zplgXFiaQoQ55A7//Tf fFnGM9isQ1jwp5jSioZisJbRvNzqzDHH6uWS0cou0EC23BrAcClHAz4OniOuD3bYSwFw RgLg== 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=2ryR3MCsZM/kE0vPKzSbMRAS9TkDfhZ1z5k+dMI2sQM=; b=0ey4MFWoMjww0fkrcoGDCl+pd+d2xmvCm1cQnqBEllLQ93fEcRgSmf/gF0QoFWTwEv c3nC6bBDJuyRzQovm1Ozm3ZErMvI5UnmX8zNwZ8UfA7Krvmh9IMNX5n/KXEyBZmSj1OI 9BeWLfdWx/OrFojaXZ/uFmRgyKjKLLuklikwdNdxEODCG9QeOjtJ/hZETEQfXj9/GJaS 8jbibc/rn5g1X3cXkrvDV+VOTGm+l6OQG7YBxYtKjYxSqRaU1739GwVOJbAlIc6aXJKJ KFaobf1ZRIxcOhOqXdvlciG9ZYMyttF6/5HFrmUj3ocyqGMhjnDVLoIrES3uf87y7rqt OqlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=fucOwaf1; 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 j3-20020a170903028300b001b0559c58d4si3067397plr.138.2023.06.01.08.23.10; Thu, 01 Jun 2023 08:23:22 -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=fucOwaf1; 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 S234830AbjFAPRZ (ORCPT + 99 others); Thu, 1 Jun 2023 11:17:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234378AbjFAPQj (ORCPT ); Thu, 1 Jun 2023 11:16:39 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66983188; Thu, 1 Jun 2023 08:16:37 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-64d44b198baso834386b3a.0; Thu, 01 Jun 2023 08:16:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685632597; x=1688224597; 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=2ryR3MCsZM/kE0vPKzSbMRAS9TkDfhZ1z5k+dMI2sQM=; b=fucOwaf1+OoDknMxiJnsAstyMXS8k3K1kx3ZtalFue2T/KM7gPPOgbASYDShrl/R2g jcUaVyxX1jIvc5cEw1Lwg3NJOElXM/yfCzdBmQtFNt0KQ+kYvTLNx6tu1sfXvwxEv1kb hQ9xJjQ+hdGX6CXA89e5SpeXeOCDNgW16T6mIFW4Z6Qtkyzmh3z/yshP0P1RpRDsOjuA R8ILWMxQi2gQ3fHKs+lrcIH3qlClRsGvyvJHWiKCGca+/PzTUdw5dujiBdlXchdnvEKp b8FgFs2920gMv9S8JE6PGcKmHb4q6ZOt2WUSDWS6VVjgp4PFn9lZV7Vyk8jBGDP/llFr 44Nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685632597; x=1688224597; 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=2ryR3MCsZM/kE0vPKzSbMRAS9TkDfhZ1z5k+dMI2sQM=; b=Fsl+aADyQ/ZpAbJhd9aVWeKUAYHwbSuHggnv946WwziF+NDXoDVkW7T6P8Kb7E5Xs+ aW1wPSkVmNQrpzSykxRxhcPm+8x6wJuaSSgRO0MstbspzBqQwE4QS9eSyXZX1U7fft0r IvoJwYDnfPOYNI4IOv6+sF8GQJukZzdgCzkTCY0awEQA6ARuc9drcPPsOTv4hT+Y1eLI xx82FgCUnJzPy5f44696XwNgUpTFHH0OWBmgBX4L979PiF0UYk/yDH44cIehaMvNsS7M 695eMllvtvJVRhdQuQhzM8rFe+r2JokPAMhHo1Nm7Ddqv3dmx7YQkwxSuBQj1xfvo7e7 2gYw== X-Gm-Message-State: AC+VfDzyZlgUa/KoUF+JzI7ga/dqG8s2YoIV7anzf85biasHITBlLguq aEzDpyIIxHlcTF8CVz9OU00= X-Received: by 2002:a05:6a00:987:b0:5a8:9858:750a with SMTP id u7-20020a056a00098700b005a89858750amr2663216pfg.13.1685632596768; Thu, 01 Jun 2023 08:16:36 -0700 (PDT) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:9:e0c3:5ec1:4a35:2168]) by smtp.gmail.com with ESMTPSA id f3-20020a635543000000b0051b460fd90fsm3282639pgm.8.2023.06.01.08.16.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jun 2023 08:16:36 -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 7/9] x86/hyperv: Initialize cpu and memory for SEV-SNP enlightened guest Date: Thu, 1 Jun 2023 11:16:20 -0400 Message-Id: <20230601151624.1757616-8-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230601151624.1757616-1-ltykernel@gmail.com> References: <20230601151624.1757616-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_NONE,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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767514311233167985?= X-GMAIL-MSGID: =?utf-8?q?1767514311233167985?= From: Tianyu Lan Hyper-V enlightened guest doesn't have boot loader support. Boot Linux kernel directly from hypervisor with data(kernel image, initrd and parameter page) and memory for boot up that is initialized via AMD SEV PSP proctol LAUNCH_UPDATE_DATA (Please refernce https://www.amd.com/system/files/TechDocs/ 55766_SEV-KM_API_Specification.pdf 1.3.1 Launch). Kernel needs to read processor and memory info from EN_SEV_ SNP_PROCESSOR/MEM_INFO_ADDR address which are populated by Hyper-V. Initialize smp cpu related ops, validate system memory and add it into e820 table. Signed-off-by: Tianyu Lan --- arch/x86/hyperv/ivm.c | 93 +++++++++++++++++++++++++++++++++ arch/x86/include/asm/mshyperv.h | 17 ++++++ arch/x86/kernel/cpu/mshyperv.c | 3 ++ 3 files changed, 113 insertions(+) diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index 5d3ee3124e00..e735507d0f54 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -17,6 +17,11 @@ #include #include #include +#include +#include +#include +#include +#include #ifdef CONFIG_AMD_MEM_ENCRYPT @@ -57,6 +62,8 @@ union hv_ghcb { static u16 hv_ghcb_version __ro_after_init; +static u32 processor_count; + u64 hv_ghcb_hypercall(u64 control, void *input, void *output, u32 input_size) { union hv_ghcb *hv_ghcb; @@ -356,6 +363,92 @@ static bool hv_is_private_mmio(u64 addr) return false; } +static __init void hv_snp_get_smp_config(unsigned int early) +{ + /* + * The "early" is only to be true when there is AMD + * numa support. Hyper-V AMD SEV-SNP guest may not + * have numa support. To make sure smp config is + * always initialized, do that when early is false. + */ + if (early) + return; + + /* + * There is no firmware and ACPI MADT table support in + * in the Hyper-V SEV-SNP enlightened guest. Set smp + * related config variable here. + */ + while (num_processors < processor_count) { + early_per_cpu(x86_cpu_to_apicid, num_processors) = num_processors; + early_per_cpu(x86_bios_cpu_apicid, num_processors) = num_processors; + physid_set(num_processors, phys_cpu_present_map); + set_cpu_possible(num_processors, true); + set_cpu_present(num_processors, true); + num_processors++; + } +} + +__init void hv_sev_init_mem_and_cpu(void) +{ + struct memory_map_entry *entry; + struct e820_entry *e820_entry; + u64 e820_end; + u64 ram_end; + u64 page; + + /* + * Hyper-V enlightened snp guest boots kernel + * directly without bootloader. So roms, bios + * regions and reserve resources are not available. + * Set these callback to NULL. + */ + x86_platform.legacy.rtc = 0; + x86_platform.legacy.reserve_bios_regions = 0; + x86_platform.set_wallclock = set_rtc_noop; + x86_platform.get_wallclock = get_rtc_noop; + x86_init.resources.probe_roms = x86_init_noop; + x86_init.resources.reserve_resources = x86_init_noop; + x86_init.mpparse.find_smp_config = x86_init_noop; + x86_init.mpparse.get_smp_config = hv_snp_get_smp_config; + + /* + * Hyper-V SEV-SNP enlightened guest doesn't support ioapic + * and legacy APIC page read/write. Switch to hv apic here. + */ + disable_ioapic_support(); + + /* Get processor and mem info. */ + processor_count = *(u32 *)__va(EN_SEV_SNP_PROCESSOR_INFO_ADDR); + entry = (struct memory_map_entry *)__va(EN_SEV_SNP_MEM_INFO_ADDR); + + /* + * There is no bootloader/EFI firmware in the SEV SNP guest. + * E820 table in the memory just describes memory for kernel, + * ACPI table, cmdline, boot params and ramdisk. The dynamic + * data(e.g, vcpu number and the rest memory layout) needs to + * be read from EN_SEV_SNP_PROCESSOR_INFO_ADDR. + */ + for (; entry->numpages != 0; entry++) { + e820_entry = &e820_table->entries[ + e820_table->nr_entries - 1]; + e820_end = e820_entry->addr + e820_entry->size; + ram_end = (entry->starting_gpn + + entry->numpages) * PAGE_SIZE; + + if (e820_end < entry->starting_gpn * PAGE_SIZE) + e820_end = entry->starting_gpn * PAGE_SIZE; + + if (e820_end < ram_end) { + pr_info("Hyper-V: add e820 entry [mem %#018Lx-%#018Lx]\n", e820_end, ram_end - 1); + e820__range_add(e820_end, ram_end - e820_end, + E820_TYPE_RAM); + for (page = e820_end; page < ram_end; page += PAGE_SIZE) + pvalidate((unsigned long)__va(page), RMP_PG_SIZE_4K, true); + } + } +} + void __init hv_vtom_init(void) { /* diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h index d859d7c5f5e8..7a9a6cdc2ae9 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -50,6 +50,21 @@ extern bool hv_isolation_type_en_snp(void); extern union hv_ghcb * __percpu *hv_ghcb_pg; +/* + * Hyper-V puts processor and memory layout info + * to this address in SEV-SNP enlightened guest. + */ +#define EN_SEV_SNP_PROCESSOR_INFO_ADDR 0x802000 +#define EN_SEV_SNP_MEM_INFO_ADDR 0x802018 + +struct memory_map_entry { + u64 starting_gpn; + u64 numpages; + u16 type; + u16 flags; + u32 reserved; +}; + int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages); int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id); int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags); @@ -255,12 +270,14 @@ void hv_ghcb_msr_read(u64 msr, u64 *value); bool hv_ghcb_negotiate_protocol(void); void __noreturn hv_ghcb_terminate(unsigned int set, unsigned int reason); void hv_vtom_init(void); +void hv_sev_init_mem_and_cpu(void); #else static inline void hv_ghcb_msr_write(u64 msr, u64 value) {} static inline void hv_ghcb_msr_read(u64 msr, u64 *value) {} static inline bool hv_ghcb_negotiate_protocol(void) { return false; } static inline void hv_ghcb_terminate(unsigned int set, unsigned int reason) {} static inline void hv_vtom_init(void) {} +static inline void hv_sev_init_mem_and_cpu(void) {} #endif extern bool hv_isolation_type_snp(void); diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index 9186453251f7..48b9eab3daf6 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -528,6 +528,9 @@ static void __init ms_hyperv_init_platform(void) if (!(ms_hyperv.features & HV_ACCESS_TSC_INVARIANT)) mark_tsc_unstable("running on Hyper-V"); + if (hv_isolation_type_en_snp()) + hv_sev_init_mem_and_cpu(); + hardlockup_detector_disable(); } From patchwork Thu Jun 1 15:16:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 102025 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp412802vqr; Thu, 1 Jun 2023 08:23:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4HMBtp/Rbfen+CvF5+hAKIiUb9D1W7fkvTVAplwlcqtwcDwYCtejSXNp7rOBijqbGv2G5s X-Received: by 2002:a05:6a20:7d83:b0:10a:a57a:9f7e with SMTP id v3-20020a056a207d8300b0010aa57a9f7emr8460000pzj.25.1685633034892; Thu, 01 Jun 2023 08:23:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685633034; cv=none; d=google.com; s=arc-20160816; b=mHumBPFbX3SLzs7SVofwBib+E4+nGY8AGgEGxIMM4TQDaeIi6uJ6MNW5O15Mt9MAoR 2qdcFxBnJeKRcECU5mPgq2ZIFJi/7dLlOl9lALSu/mBYNjAejevwpA/muon0kRZzpRcX FHT1zGDHJnKo+4M415wf2ypUTshD2pwE1QwMrJAS4R/V7ifBGqecZdEMnKtQ1Lb9oMxy sAgSJQSd6vpYfOKjLvH6KFTK+0fNP0rRDKYQGNiqNMZOZKIYIGIN8ADLAqz1xsE8bdWw ZcfdJSvCknMjWdlk76Jpp6P6sa2j8ZBANBz4AgYXUyTiiQqGU6eoLHNPcmzjZ075WXXE 6LTw== 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=ZJrY+3BKhCyIpt2KlCOdPmzAbDXEeG+dEF3DJAIJD+A=; b=nmFy8mqte6fIsLqNh6HW4ZepqKy2C+SPln9a0+qIJiloVaWXrPRPFRaoDAtuXJMlRO Vca+e0YYyNOHDBgqaZPZhaqjjPVt+MjX369IEKHqFP3K6Wp+mEhwr55Y6qwbALTxC88N B3+Ks5y6wfA9MN8/wglhtEQSYQCreCgYk55pxab8g0ogonp/nVdnStfrRa20jnPItg1X 5guMtI4hSZr1qCjbqxtu0G/vIyg2WB877Sxr+XOUdQxLJDjaYyO78Up1uB+A3f9f7Rlj bwzh+Kx9HxFqRKmoQKgvDjYhwxcFZ20wgUxRy4TkZbOvg5iLpDSKorkoSxaSxsQxPsvg T6mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=mgzXD40B; 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 l192-20020a6391c9000000b005347ef6ec11si1046875pge.760.2023.06.01.08.23.39; Thu, 01 Jun 2023 08:23:54 -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=mgzXD40B; 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 S232380AbjFAPRX (ORCPT + 99 others); Thu, 1 Jun 2023 11:17:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234795AbjFAPQ5 (ORCPT ); Thu, 1 Jun 2023 11:16:57 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48079193; Thu, 1 Jun 2023 08:16:38 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-650352b89f6so430957b3a.0; Thu, 01 Jun 2023 08:16:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685632598; x=1688224598; 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=ZJrY+3BKhCyIpt2KlCOdPmzAbDXEeG+dEF3DJAIJD+A=; b=mgzXD40Bg2V4kgffJ67CzHxGDOY9pG/fBT5qMoTNokDaKDv8ZDmMHRZhDon390clXA SRp3Ke6ZdJ3bwm+3h7DLWn49rxO+ZfdExetnVmWJKR1jqxtwMhXMAfn9sZGGauA81Jp1 mkyRrs/zCUP9FaisLYt+ARqVhaRW3y83quAuFr5G4vSnIAgfyG+S3IBc8OEqVsGr04Or eAQ5Cmojem9c7pkRe7u8XdPT9OlBPZc3k8bBkB9wEFdJLt55+OqHkqf1y7x/1oOBYAGq vyt3mhi2newu40VPgRBiXp3krcJ9RTmJfJzc5kcpyKYSdTPR89xuZkoOhRBzMGhmKn43 HO1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685632598; x=1688224598; 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=ZJrY+3BKhCyIpt2KlCOdPmzAbDXEeG+dEF3DJAIJD+A=; b=gbO6lMsKklvldrX++txST3ImaSH6ZdI5rPijupWDpIAhV3DQRnqNdSmLU67Yw00gBm p5sRzZ8lJOv6s3eDPXXsFmqnbUz1QfG+sqN3Z6II4pylT5KPGCJoVIcp2HrM9xOq4XUO kN3XEVFa+iv05pfofr2VjhsL8icPFMAFYiVrdOYmsZa8fPvkXaAWwGtPUMIOIzHkf6v4 bFyBO+VGV7SIiPkPNDzhCkdTH767tluwdb+DMTuwclgAW16Zvd/L0ynfjTGn0cmD7AAi Npu6RmtYI3c/u9Oyk3Cuen+A9Z1botW3MB1I9zYzE2Hfb4LPMflvVIiL5ZFVVpGfZTou NbrQ== X-Gm-Message-State: AC+VfDwQQg9PFDCqkM3Lvslm7KmD9SR4S+Wx1hE7LqUAFmoMROW67YWI e7LpJSI6VnT+/+t3xwoJL/c= X-Received: by 2002:a05:6a20:7fa7:b0:10f:8499:1b75 with SMTP id d39-20020a056a207fa700b0010f84991b75mr8243045pzj.9.1685632597910; Thu, 01 Jun 2023 08:16:37 -0700 (PDT) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:9:e0c3:5ec1:4a35:2168]) by smtp.gmail.com with ESMTPSA id f3-20020a635543000000b0051b460fd90fsm3282639pgm.8.2023.06.01.08.16.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jun 2023 08:16:37 -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 8/9] x86/hyperv: Add smp support for SEV-SNP guest Date: Thu, 1 Jun 2023 11:16:21 -0400 Message-Id: <20230601151624.1757616-9-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230601151624.1757616-1-ltykernel@gmail.com> References: <20230601151624.1757616-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_NONE,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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767514345169258302?= X-GMAIL-MSGID: =?utf-8?q?1767514345169258302?= From: Tianyu Lan In the AMD SEV-SNP guest, AP needs to be started up via sev es save area and Hyper-V requires to call HVCALL_START_VP hypercall to pass the gpa of sev es save area with AP's vp index and VTL(Virtual trust level) parameters. Override wakeup_secondary_cpu_64 callback with hv_snp_boot_ap. Signed-off-by: Tianyu Lan --- arch/x86/hyperv/ivm.c | 95 +++++++++++++++++++++++++++++++ arch/x86/include/asm/mshyperv.h | 9 +++ arch/x86/kernel/cpu/mshyperv.c | 13 ++++- include/asm-generic/hyperv-tlfs.h | 1 + 4 files changed, 116 insertions(+), 2 deletions(-) diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index e735507d0f54..238d73752dd8 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -22,11 +22,15 @@ #include #include #include +#include #ifdef CONFIG_AMD_MEM_ENCRYPT #define GHCB_USAGE_HYPERV_CALL 1 +static u8 ap_start_input_arg[PAGE_SIZE] __bss_decrypted __aligned(PAGE_SIZE); +static u8 ap_start_stack[PAGE_SIZE] __aligned(PAGE_SIZE); + union hv_ghcb { struct ghcb ghcb; struct { @@ -449,6 +453,97 @@ __init void hv_sev_init_mem_and_cpu(void) } } +#define hv_populate_vmcb_seg(seg, gdtr_base) \ +do { \ + if (seg.selector) { \ + seg.base = 0; \ + seg.limit = HV_AP_SEGMENT_LIMIT; \ + seg.attrib = *(u16 *)(gdtr_base + seg.selector + 5); \ + seg.attrib = (seg.attrib & 0xFF) | ((seg.attrib >> 4) & 0xF00); \ + } \ +} while (0) \ + +int hv_snp_boot_ap(int cpu, unsigned long start_ip) +{ + struct sev_es_save_area *vmsa = (struct sev_es_save_area *) + __get_free_page(GFP_KERNEL | __GFP_ZERO); + struct desc_ptr gdtr; + u64 ret, rmp_adjust, retry = 5; + struct hv_enable_vp_vtl *start_vp_input; + unsigned long flags; + + native_store_gdt(&gdtr); + + vmsa->gdtr.base = gdtr.address; + vmsa->gdtr.limit = gdtr.size; + + asm volatile("movl %%es, %%eax;" : "=a" (vmsa->es.selector)); + hv_populate_vmcb_seg(vmsa->es, vmsa->gdtr.base); + + asm volatile("movl %%cs, %%eax;" : "=a" (vmsa->cs.selector)); + hv_populate_vmcb_seg(vmsa->cs, vmsa->gdtr.base); + + asm volatile("movl %%ss, %%eax;" : "=a" (vmsa->ss.selector)); + hv_populate_vmcb_seg(vmsa->ss, vmsa->gdtr.base); + + asm volatile("movl %%ds, %%eax;" : "=a" (vmsa->ds.selector)); + hv_populate_vmcb_seg(vmsa->ds, vmsa->gdtr.base); + + vmsa->efer = native_read_msr(MSR_EFER); + + asm volatile("movq %%cr4, %%rax;" : "=a" (vmsa->cr4)); + asm volatile("movq %%cr3, %%rax;" : "=a" (vmsa->cr3)); + asm volatile("movq %%cr0, %%rax;" : "=a" (vmsa->cr0)); + + vmsa->xcr0 = 1; + vmsa->g_pat = HV_AP_INIT_GPAT_DEFAULT; + vmsa->rip = (u64)secondary_startup_64_no_verify; + vmsa->rsp = (u64)&ap_start_stack[PAGE_SIZE]; + + /* + * Set the SNP-specific fields for this VMSA: + * VMPL level + * SEV_FEATURES (matches the SEV STATUS MSR right shifted 2 bits) + */ + vmsa->vmpl = 0; + vmsa->sev_features = sev_status >> 2; + + /* + * Running at VMPL0 allows the kernel to change the VMSA bit for a page + * using the RMPADJUST instruction. However, for the instruction to + * succeed it must target the permissions of a lesser privileged + * (higher numbered) VMPL level, so use VMPL1 (refer to the RMPADJUST + * instruction in the AMD64 APM Volume 3). + */ + rmp_adjust = RMPADJUST_VMSA_PAGE_BIT | 1; + ret = rmpadjust((unsigned long)vmsa, RMP_PG_SIZE_4K, + rmp_adjust); + if (ret != 0) { + pr_err("RMPADJUST(%llx) failed: %llx\n", (u64)vmsa, ret); + return ret; + } + + local_irq_save(flags); + start_vp_input = + (struct hv_enable_vp_vtl *)ap_start_input_arg; + memset(start_vp_input, 0, sizeof(*start_vp_input)); + start_vp_input->partition_id = -1; + start_vp_input->vp_index = cpu; + start_vp_input->target_vtl.target_vtl = ms_hyperv.vtl; + *(u64 *)&start_vp_input->vp_context = __pa(vmsa) | 1; + + do { + ret = hv_do_hypercall(HVCALL_START_VP, + start_vp_input, NULL); + } while (hv_result(ret) == HV_STATUS_TIME_OUT && retry--); + + local_irq_restore(flags); + + if (!hv_result_success(ret)) + pr_err("HvCallStartVirtualProcessor failed: %llx\n", ret); + return ret; +} + void __init hv_vtom_init(void) { /* diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h index 7a9a6cdc2ae9..804c67475054 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -65,6 +65,13 @@ struct memory_map_entry { u32 reserved; }; +/* + * DEFAULT INIT GPAT and SEGMENT LIMIT value in struct VMSA + * to start AP in enlightened SEV guest. + */ +#define HV_AP_INIT_GPAT_DEFAULT 0x0007040600070406ULL +#define HV_AP_SEGMENT_LIMIT 0xffffffff + int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages); int hv_call_add_logical_proc(int node, u32 lp_index, u32 acpi_id); int hv_call_create_vp(int node, u64 partition_id, u32 vp_index, u32 flags); @@ -271,6 +278,7 @@ bool hv_ghcb_negotiate_protocol(void); void __noreturn hv_ghcb_terminate(unsigned int set, unsigned int reason); void hv_vtom_init(void); void hv_sev_init_mem_and_cpu(void); +int hv_snp_boot_ap(int cpu, unsigned long start_ip); #else static inline void hv_ghcb_msr_write(u64 msr, u64 value) {} static inline void hv_ghcb_msr_read(u64 msr, u64 *value) {} @@ -278,6 +286,7 @@ static inline bool hv_ghcb_negotiate_protocol(void) { return false; } static inline void hv_ghcb_terminate(unsigned int set, unsigned int reason) {} static inline void hv_vtom_init(void) {} static inline void hv_sev_init_mem_and_cpu(void) {} +static int hv_snp_boot_ap(int cpu, unsigned long start_ip) {} #endif extern bool hv_isolation_type_snp(void); diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index 48b9eab3daf6..fd37f47de134 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -295,6 +295,16 @@ static void __init hv_smp_prepare_cpus(unsigned int max_cpus) native_smp_prepare_cpus(max_cpus); + /* + * Override wakeup_secondary_cpu_64 callback for SEV-SNP + * enlightened guest. + */ + if (hv_isolation_type_en_snp()) + apic->wakeup_secondary_cpu_64 = hv_snp_boot_ap; + + if (!hv_root_partition) + return; + #ifdef CONFIG_X86_64 for_each_present_cpu(i) { if (i == 0) @@ -501,8 +511,7 @@ static void __init ms_hyperv_init_platform(void) # ifdef CONFIG_SMP smp_ops.smp_prepare_boot_cpu = hv_smp_prepare_boot_cpu; - if (hv_root_partition) - smp_ops.smp_prepare_cpus = hv_smp_prepare_cpus; + smp_ops.smp_prepare_cpus = hv_smp_prepare_cpus; # endif /* diff --git a/include/asm-generic/hyperv-tlfs.h b/include/asm-generic/hyperv-tlfs.h index f4e4cc4f965f..fdac4a1714ec 100644 --- a/include/asm-generic/hyperv-tlfs.h +++ b/include/asm-generic/hyperv-tlfs.h @@ -223,6 +223,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_TIME_OUT 120 #define HV_STATUS_VTL_ALREADY_ENABLED 134 /* From patchwork Thu Jun 1 15:16:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 102023 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp412442vqr; Thu, 1 Jun 2023 08:23:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6OgdveJi1VWkG9NJb/BAKpBCVNGX7ZADSF/MtaDuM/SmeMSYfJJ0mLvjAUNgY7Ao22z03m X-Received: by 2002:a17:902:d70c:b0:1ac:83d1:9269 with SMTP id w12-20020a170902d70c00b001ac83d19269mr7542862ply.16.1685633002361; Thu, 01 Jun 2023 08:23:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685633002; cv=none; d=google.com; s=arc-20160816; b=YOM2NeEN/XgaioizKZTfz/0A2kZU8GBGBgoUFPCG4J7GYVr2Ofyw923NOInZL25jKI ju/Bpyw9UKRGW25YBbSNhgMVOVnLN2nkpNCM97UC6m6iipXAwVE9XC3ZPn+U/8hEJwxu uO2BxVjgvjsl4VvZSr9jy9ttJOxgpzkIxcOZqx6VElJbkUPfR+uY8jEphmGhW9qgG4Hi T4kOEM1haxSWL3bjnFXWvu19LnGR39ghZTjZqtYCA4+OOPUvSbhAxWEIG31NOv+z8JWr FW3JHqkNWOSjdVue5MLZHj3hdky8TJSf7dPNivr9rkSBrlTUSWtrgeYADRFJ2x8wrLKY SCpQ== 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=/jE+k1UTIit7JT0AsPVhsyBlvHXp2Xy2teL4EcNLD10=; b=xjFZXLzbD4D2hOBGmjoYaQ52d35OBdzHgzqgvFQo33UV7VltNoKYeuCuV2CUJWayWM AcukkaztBOi73Z4YBt3JCsSp3tq+AwZSCOk0BJyjlbOVvK305/jl0Dyuq1XfoEHlm6C9 Q1QydmVnnAgCDce/ndP3jWh811PPZ5MbZFumcj+m0sKe5k5EE0VvTjsS9+Dn7YnmAD5C Dd9Iw68IPoNzljK3QU9fy9H836sE53i4/ioYvvOs8t2yNaADGdpIsL5L6lkZwQj7SR4E uPwyTaJ213PQGu0ZhYTCRmZAkWmmKhRuJJ1flG8PSXQaWyLAM28zOH8AXD3iMC3hLn7n cdTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=T43yoxLQ; 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 f19-20020a170902e99300b001ae8b0f8491si1701987plb.454.2023.06.01.08.23.10; Thu, 01 Jun 2023 08:23:22 -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=T43yoxLQ; 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 S234874AbjFAPRa (ORCPT + 99 others); Thu, 1 Jun 2023 11:17:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234810AbjFAPQ5 (ORCPT ); Thu, 1 Jun 2023 11:16:57 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEBD4E2; Thu, 1 Jun 2023 08:16:39 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-64d18d772bdso1147379b3a.3; Thu, 01 Jun 2023 08:16:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685632599; x=1688224599; 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=/jE+k1UTIit7JT0AsPVhsyBlvHXp2Xy2teL4EcNLD10=; b=T43yoxLQeZsGBa0LF/z1Zz8gR4MDHsXWysyPasZASl2BGpsDCiIrQJUlMT/IpkUTGD QjtbfPJFmp1KmpDgc1eknNAK/dJsSdYLxSbFW4V7bdayqtLILQdHHTLhi5EC8VwEqHqd TMtosofs7NXCQ/O65ydHOJ1YhjmYl3HVU1sxWuj9SH0Ycbr4Ipz3KQIjQ60HkednKruY q5FrRg4MApwH3VJA45648peiKQMMqciE8UwU5TruVs01Fr2KOM0Am8PKibLEA/5jTyV2 G6too/CUHm3pfYIz0O6PGMq6mklfRUicrrQQF5cE+cBROkl9NgriH+6REjRJ0RaCwfhK +flg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685632599; x=1688224599; 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=/jE+k1UTIit7JT0AsPVhsyBlvHXp2Xy2teL4EcNLD10=; b=cvhSglHXm7Gqub9TAXGY85YvD9IktwtfEm/Zj0coqQUgnEmIdSPXTh9wDrDiCeCRm4 lhieB0FLPHtWLQBIJREQvynIwKTF2kLJvxomWsOd1u32z5YmE8pKTxJwMOLEHk23qqc+ gqmCP2roC+oRzQW5QzENopNnwe4CMe7eay5dDPeCJa/Cx6LQM48Hj9aMAmr4++iwIIrR dYWjd3+ZP9mjEcSWO9Z7mzdsz90VTdm8DSdOnQ1Bg80uidbAAiCFTsp3X1zejuW9VMPq I371/dMRS7IldSR8F+jXV1MR61N69+j/W+ADlJAWdPwatWSJZh2WY5sYO2GAWmMEr2fy TsIg== X-Gm-Message-State: AC+VfDz89ZSfnNjVFMKWW3YiSItgWycbfY/d8JHd/KLEDMPXArmNCZTC K1Monhp1PvAlGOBNNOGRGGU= X-Received: by 2002:a05:6a00:1144:b0:64d:4412:9923 with SMTP id b4-20020a056a00114400b0064d44129923mr10244426pfm.3.1685632599182; Thu, 01 Jun 2023 08:16:39 -0700 (PDT) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:9:e0c3:5ec1:4a35:2168]) by smtp.gmail.com with ESMTPSA id f3-20020a635543000000b0051b460fd90fsm3282639pgm.8.2023.06.01.08.16.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jun 2023 08:16:38 -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 9/9] x86/hyperv: Add hyperv-specific handling for VMMCALL under SEV-ES Date: Thu, 1 Jun 2023 11:16:22 -0400 Message-Id: <20230601151624.1757616-10-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230601151624.1757616-1-ltykernel@gmail.com> References: <20230601151624.1757616-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_NONE,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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767514310983243447?= X-GMAIL-MSGID: =?utf-8?q?1767514310983243447?= From: Tianyu Lan Add Hyperv-specific handling for faults caused by VMMCALL instructions. Signed-off-by: Tianyu Lan --- arch/x86/kernel/cpu/mshyperv.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index fd37f47de134..eaa98100f354 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -32,6 +32,7 @@ #include #include #include +#include /* Is Linux running as the root partition? */ bool hv_root_partition; @@ -576,6 +577,20 @@ static bool __init ms_hyperv_msi_ext_dest_id(void) return eax & HYPERV_VS_PROPERTIES_EAX_EXTENDED_IOAPIC_RTE; } +static void hv_sev_es_hcall_prepare(struct ghcb *ghcb, struct pt_regs *regs) +{ + /* RAX and CPL are already in the GHCB */ + ghcb_set_rcx(ghcb, regs->cx); + ghcb_set_rdx(ghcb, regs->dx); + ghcb_set_r8(ghcb, regs->r8); +} + +static bool hv_sev_es_hcall_finish(struct ghcb *ghcb, struct pt_regs *regs) +{ + /* No checking of the return state needed */ + return true; +} + const __initconst struct hypervisor_x86 x86_hyper_ms_hyperv = { .name = "Microsoft Hyper-V", .detect = ms_hyperv_platform, @@ -583,4 +598,6 @@ const __initconst struct hypervisor_x86 x86_hyper_ms_hyperv = { .init.x2apic_available = ms_hyperv_x2apic_available, .init.msi_ext_dest_id = ms_hyperv_msi_ext_dest_id, .init.init_platform = ms_hyperv_init_platform, + .runtime.sev_es_hcall_prepare = hv_sev_es_hcall_prepare, + .runtime.sev_es_hcall_finish = hv_sev_es_hcall_finish, };