From patchwork Tue Jun 27 03:22:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 113188 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7918903vqr; Mon, 26 Jun 2023 20:35:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6EnHHaIjLgc36/bpncfkivEAXqlmh5eermz/KY5vH91n358ZKDUPf+nTja0z+2MskQZKod X-Received: by 2002:a05:6359:628:b0:133:a55:7e24 with SMTP id eh40-20020a056359062800b001330a557e24mr3621160rwb.0.1687836954309; Mon, 26 Jun 2023 20:35:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687836954; cv=none; d=google.com; s=arc-20160816; b=PgmLW5+XThdaBNyk7dYBUCVR+J40HC3VF1USYNpKuaFaJw0OIwGvkbPcoX6ezxjeqf AxZEfnMXmj7hNKaKavgDa+ci44Fmo/f5LMN//V9mfd57ffi/9JggPJsXPmjWFQ5WRa0r NDYj3Bry79XppYycm24w/QmYxFepYkrWU0X0xz0PSewzRwfU4lY3zW6lZRpPkoEHTDAA OTlDgEnpa4gd8WYoYroE2cdq+FLKH3YY8gB2Fq9uIOhWgPbzlk3HodMGnJ9gGhM+kvYD TjkrnD05JP99vamBW+hOPWXf2tY73m6U713y+buxMia3ATGMBFQgLkY2Skrw0ntdHz5E kzpw== 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=PE11yTMAExZ2ZoYVCcn2Tq5He2Vs69778pFMKMEukgk=; fh=ZK/DmW1x+WWTXdJ/EJHTsBEUe1j1GuqfQXG5AYfW/uc=; b=cs0iryd1FC74vc68fJXvOViRe26SS8gnBg5H38W5mHenPBL0VIEAOThpYv8KeiT3tK rFGPhOwfAJmtNrupbGL0BcRCPLtlM4mXNNNDl/VMnptYUkqBbAeftCKDbd4Qz/g0Wupa LP7T17o9yBf2EiFmz+FX5ebwld97zth3+nw5rL+j+68Li7J0x8A2xm6rUquHpfJs6qCQ bM9SfkRfx9GldlSJwgBXrBbKpkzQh9vA4X3qmmAA0HgvQn3hb+em/Ebd24PbchUn8gKp UVFN1j1Z9k9UYARVJE7h1B3+yVkWHTYZxB/6pZcUhKz6FGQXDkN4nEwC1HzxU9aj9e/G PWSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="L/IebApg"; 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 u20-20020a056a00159400b006786b7f4cbcsi3033855pfk.235.2023.06.26.20.35.39; Mon, 26 Jun 2023 20:35: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="L/IebApg"; 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 S230158AbjF0D3B (ORCPT + 99 others); Mon, 26 Jun 2023 23:29:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229727AbjF0D2S (ORCPT ); Mon, 26 Jun 2023 23:28:18 -0400 Received: from mail-ot1-x32b.google.com (mail-ot1-x32b.google.com [IPv6:2607:f8b0:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04A3D2106; Mon, 26 Jun 2023 20:22:54 -0700 (PDT) Received: by mail-ot1-x32b.google.com with SMTP id 46e09a7af769-6b74faaac3bso1294473a34.1; Mon, 26 Jun 2023 20:22:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687836173; x=1690428173; 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=PE11yTMAExZ2ZoYVCcn2Tq5He2Vs69778pFMKMEukgk=; b=L/IebApgWhFXHgPqF3us42fzqDADcFJR4vXUnyhDeL+wsoamYd/aEpG2bPbCG1XevS fraPdupxXbgIchbLfBM00pEIOjfm84OFptvDPRrLcSJtNOatnAJqnXKWF213wICpwa4F XD9mK4KbsvwY3v5nthP1o84FxOS9aS9vt/mIZaxDDcsMWhm4GBxUmYrWm/3TW97zQ6/M lA06WcxUQtIseHh/WjUjwvtE6iXBWs5w0oTPHCQXLlRIwmVdp984G+RUxhEZQgBc2qus qSlCmdCmLr7ZV5tDFgQU0EERQXKBW4O6Ss+agZJ36A7vObM6IPd4NwmYv6yrGNDUp5bN M1Hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687836173; x=1690428173; 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=PE11yTMAExZ2ZoYVCcn2Tq5He2Vs69778pFMKMEukgk=; b=fWR/nWxqQI6DY3iTxh1NiaJB9hKA3jKOnhkDdG9igoCLMwm/jLSf9vHXBfWMkOa/KW 0fANLvKHIF7h6lxkiqYiT8QFiv7TDvx1NiWFW+6/Yt+2N6FLnaQiWo20zf83jQzkBt1p svoWgJ/HocaYgzHLxe4abkAWQCTqjZLSlqeTTiSz5psOfSR8q0g4zJYKHw93Pn3X0+hU tdqGW+b1HflGomLWKCZW+Q8C3YOPsrEBMZ59vlZ2ZfheTScA/hRsN10kNIpVo+21yrIr u0SnynbI1gpHyJHFeF8GHyDWF4YfcccXYel2K1hQXM9iH7b2sFHS5D94OwOBIPPOUClV bhzw== X-Gm-Message-State: AC+VfDwBWTjACfReW83vG6ycY3WKlGOZA/Kt1C181fV6R6/56jn6slHu 7VeeCA2GzdEghxcxTYhJnZo= X-Received: by 2002:a05:6808:2022:b0:3a1:b47d:9296 with SMTP id q34-20020a056808202200b003a1b47d9296mr13366617oiw.17.1687836173245; Mon, 26 Jun 2023 20:22:53 -0700 (PDT) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:37:c5e9:2003:6c97:8057]) by smtp.gmail.com with ESMTPSA id mm12-20020a17090b358c00b0025ec54be16asm618756pjb.2.2023.06.26.20.22.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jun 2023 20:22:52 -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 V2 1/9] x86/hyperv: Add sev-snp enlightened guest static key Date: Mon, 26 Jun 2023 23:22:39 -0400 Message-Id: <20230627032248.2170007-2-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230627032248.2170007-1-ltykernel@gmail.com> References: <20230627032248.2170007-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?1769825322106224989?= X-GMAIL-MSGID: =?utf-8?q?1769825322106224989?= 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 | 9 +++++++-- drivers/hv/hv_common.c | 6 ++++++ include/asm-generic/mshyperv.h | 12 +++++++++--- 5 files changed, 36 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..5398fb2f4d39 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,8 @@ 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)) + ((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 542a1d53b303..4b4aa53c34c2 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..6b5c41f90398 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 reserved_a1 : 31; + }; + }; union { u32 isolation_config_b; struct { u32 cvm_type : 4; - u32 reserved1 : 1; + u32 reserved_b1 : 1; u32 shared_gpa_boundary_active : 1; u32 shared_gpa_boundary_bits : 6; - u32 reserved2 : 20; + u32 reserved_b2 : 20; }; }; u64 shared_gpa_boundary; From patchwork Tue Jun 27 03:22:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 113194 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7922583vqr; Mon, 26 Jun 2023 20:47:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5dpF1S4HOSRnD2slQh6nFB3hPwviifoEn3ZBXdrMTJw2CWH2kaCEMHjZcJ90T5XXoR/I9A X-Received: by 2002:a17:907:60d6:b0:98d:264a:422e with SMTP id hv22-20020a17090760d600b0098d264a422emr12725260ejc.23.1687837640035; Mon, 26 Jun 2023 20:47:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687837640; cv=none; d=google.com; s=arc-20160816; b=QiatDSZd8yc7r1oQoN/wySPPjWLBquLVNIlfhEOaDIhUcf5DFAqNJxgTmbn2A50hRs pMrmCqmqI52yr85Ax/iB59TwLt2thkXh15sInojgKZQ1hdW8y1rX4zXYaguOUwHRTxxz 9ciH95oY4zCu5VRiqO917SXwOnx76PYP2JEPyck1AKm8rrKm9YfqO/3w4/miO3HB9U7o NwQCcOM3QpwfRZZjISIimAWGlm8WbLSo7hI7ISlHgj0aNtTo48kwyXrwqfAFdRkGobhm 32T5Amx2sJBhlinI403JtVeFGgphaXJF4MZmRj6jsJMl8BWifSYd6d9ThOOJe8gjP3GR kPwQ== 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=V1z877s9cdWqHPRWW2XoomxLF4Ko1N0KieO7s3qiybM=; fh=ZK/DmW1x+WWTXdJ/EJHTsBEUe1j1GuqfQXG5AYfW/uc=; b=OesKYZ8fCJg7SB6KDU+inNuT0IXLyr+mMUBVWpr1PAYIQR1jBL+d11mtu5N+MyjnGF MA9EBmbp93K6KXofoqNe14RotLJVw5A4E6gPew3O6d8SkmCH7OY+skiBBKMMNk6ggoPJ YqH/o70FqNSqjAE3dIp4biUjeY0nooqMZfM4sy++y34iBBFpck4iuz0Br/nurASTdyA5 /pjKaPMsHJwTrgKkjGMLmv8N87wL9/VQze4LRs4caxi04d7RYkS5I55RpQEE3AwiPSeJ MTirf9xKX84Gs5Cs4BJ25l5JpFZ8Z+axOASkJm6CkGzbPG7uP3BymbUjjGZoMYrTu/bF v6HA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=QAabkL3O; 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 l14-20020a170906078e00b0098f698a8267si2316961ejc.357.2023.06.26.20.46.56; Mon, 26 Jun 2023 20:47:20 -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=QAabkL3O; 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 S230203AbjF0D3H (ORCPT + 99 others); Mon, 26 Jun 2023 23:29:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229738AbjF0D2U (ORCPT ); Mon, 26 Jun 2023 23:28:20 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B2BF2107; Mon, 26 Jun 2023 20:22:55 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-544c0d768b9so3289183a12.0; Mon, 26 Jun 2023 20:22:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687836175; x=1690428175; 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=V1z877s9cdWqHPRWW2XoomxLF4Ko1N0KieO7s3qiybM=; b=QAabkL3Ofzm9XDTI/IWFugYTFhTKChrsC0ueRyh4N6Olfut7c8UBUesPAqNxSrg0ee bCAlVUcJ7r7ceeC0x4le+45nMSHUdDm/vPJuy9Slh2uFzcc3LTea076asMc+ZyQ8PBz+ iRdRWZO58T1CUIaYKbLP+iZJwQJETM42r256fnZ/qJHyE3ZbkmZU2bdJ++Gz5DDsb1/d 2qCEPs9M6LJD9QiSs58f31BX3F/yoghTFbp5pETDlnXDYJusFH5D9bgH5GCxZHkQ9GWx 6vh355jexv4Jncp9qChheDeEPKOWFNFyWWUY87vpdCj3CcfHSWtTL5IGGw8D4WKPzjgk zBPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687836175; x=1690428175; 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=V1z877s9cdWqHPRWW2XoomxLF4Ko1N0KieO7s3qiybM=; b=hEXaccSZMlChT5XyY9RFrgUD8hRVfs+2gEkz/dFPwNqzxAUyYCPAtaBgP3YtuWajSn hUKC5MacNRMqWPyfN4C5hiCvLrq4gfpPx6vxxuKWEdnVP/nN2nFJHeP8SWbN0okK12W8 FQLU5jpw7BYl6V/iPw/IxvderXBeYq3ysSgqAJkFAvJEze7AVPEP/MwS3e6WEN2patso tAUITaAoFI4d+qOVtz/kU9c1zkQ2yXS8clcFp/Bhr3akpP6LYLK/LNp1wQJ5dZcdt/68 C8kOOcwsbfXDwXwZQSJnEd4ZKJDIAsps6qD6iXM5dMb4hLECQ3i1xJVbUeUrEhv/6bOD aweQ== X-Gm-Message-State: AC+VfDxinsnLmnIbyd001rfdZlrmeancI/2SmM5nQLKoX2O2lWytzWNB rommwM9DMCWTwR11KxSXfYasq75cLeBGpQ== X-Received: by 2002:a17:90a:550:b0:258:b651:4f80 with SMTP id h16-20020a17090a055000b00258b6514f80mr28854208pjf.36.1687836174790; Mon, 26 Jun 2023 20:22:54 -0700 (PDT) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:37:c5e9:2003:6c97:8057]) by smtp.gmail.com with ESMTPSA id mm12-20020a17090b358c00b0025ec54be16asm618756pjb.2.2023.06.26.20.22.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jun 2023 20:22:54 -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 V2 2/9] x86/hyperv: Set Virtual Trust Level in VMBus init message Date: Mon, 26 Jun 2023 23:22:40 -0400 Message-Id: <20230627032248.2170007-3-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230627032248.2170007-1-ltykernel@gmail.com> References: <20230627032248.2170007-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?1769826041329232153?= X-GMAIL-MSGID: =?utf-8?q?1769826041329232153?= 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 6c04b52f139b..1ba367a9686e 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -378,6 +378,40 @@ static void __init hv_get_partition_id(void) local_irq_restore(flags); } +static u8 __init get_vtl(void) +{ + u64 control = HV_HYPERCALL_REP_COMP_1 | HVCALL_GET_VP_REGISTERS; + struct hv_get_vp_registers_input *input; + struct hv_get_vp_registers_output *output; + u64 vtl = 0; + u64 ret; + unsigned long flags; + + local_irq_save(flags); + input = *this_cpu_ptr(hyperv_pcpu_input_arg); + output = (struct hv_get_vp_registers_output *)input; + if (!input) { + local_irq_restore(flags); + goto done; + } + + memset(input, 0, struct_size(input, element, 1)); + input->header.partitionid = HV_PARTITION_ID_SELF; + input->header.vpindex = HV_VP_INDEX_SELF; + input->header.inputvtl = 0; + input->element[0].name0 = HV_X64_REGISTER_VSM_VP_STATUS; + + ret = hv_do_hypercall(control, input, output); + if (hv_result_success(ret)) + vtl = output->as64.low & HV_X64_VTL_MASK; + else + pr_err("Hyper-V: failed to get VTL! %lld", ret); + local_irq_restore(flags); + +done: + return vtl; +} + /* * This function is to be invoked early in the boot sequence after the * hypervisor has been detected. @@ -506,6 +540,8 @@ void __init hyperv_init(void) /* Query the VMs extended capability once, so that it can be cached. */ hv_query_ext_cap(0); + /* Find the VTL */ + ms_hyperv.vtl = get_vtl(); return; clean_guest_os_id: diff --git a/arch/x86/include/asm/hyperv-tlfs.h b/arch/x86/include/asm/hyperv-tlfs.h index cea95dcd27c2..4bf0b315b0ce 100644 --- a/arch/x86/include/asm/hyperv-tlfs.h +++ b/arch/x86/include/asm/hyperv-tlfs.h @@ -301,6 +301,13 @@ enum hv_isolation_type { #define HV_X64_MSR_TIME_REF_COUNT HV_REGISTER_TIME_REF_COUNT #define HV_X64_MSR_REFERENCE_TSC HV_REGISTER_REFERENCE_TSC +/* + * Registers are only accessible via HVCALL_GET_VP_REGISTERS hvcall and + * there is not associated MSR address. + */ +#define HV_X64_REGISTER_VSM_VP_STATUS 0x000D0003 +#define HV_X64_VTL_MASK GENMASK(3, 0) + /* Hyper-V memory host visibility */ enum hv_mem_host_visibility { VMBUS_PAGE_NOT_VISIBLE = 0, diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c index 5978e9dbc286..02b54f85dc60 100644 --- a/drivers/hv/connection.c +++ b/drivers/hv/connection.c @@ -98,6 +98,7 @@ int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo, u32 version) */ if (version >= VERSION_WIN10_V5) { msg->msg_sint = VMBUS_MESSAGE_SINT; + msg->msg_vtl = ms_hyperv.vtl; vmbus_connection.msg_conn_id = VMBUS_MESSAGE_CONNECTION_ID_4; } else { msg->interrupt_page = virt_to_phys(vmbus_connection.int_page); diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h index 6b5c41f90398..f73a044ecaa7 100644 --- a/include/asm-generic/mshyperv.h +++ b/include/asm-generic/mshyperv.h @@ -54,6 +54,7 @@ struct ms_hyperv_info { }; }; u64 shared_gpa_boundary; + u8 vtl; }; extern struct ms_hyperv_info ms_hyperv; extern bool hv_nested; diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index bfbc37ce223b..1f2bfec4abde 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -665,8 +665,8 @@ struct vmbus_channel_initiate_contact { u64 interrupt_page; struct { u8 msg_sint; - u8 padding1[3]; - u32 padding2; + u8 msg_vtl; + u8 reserved[6]; }; }; u64 monitor_page1; From patchwork Tue Jun 27 03:22:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 113193 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7922095vqr; Mon, 26 Jun 2023 20:45:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4wnkOL4fB5JhoZP2vjMenosZBtfvbenSzOc94RiCF9CGRsM8DZ27a3UhitvzWvl+hRMj5w X-Received: by 2002:a17:90b:211:b0:262:deec:502d with SMTP id fy17-20020a17090b021100b00262deec502dmr8924514pjb.7.1687837540856; Mon, 26 Jun 2023 20:45:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687837540; cv=none; d=google.com; s=arc-20160816; b=e85jQ/lYtbleZgDKT3R+gWdn2ScTvzGgDB0atsk4YDwIubpgTMihFkM5a8NLNv6EuK RvbgKfMCDH1+0jPzK2qhXWDtxNHK1sEShZwmtm9/qbNEiv02TVwftlzsUlbQVqKNBKxA 1yk6d1J61sTcFAu8P+IV9uo5JJlP6JIAEQw6SO7ivcaIhamgC2LRy17ReP0/rSAQvNEV /Jc+Y2B/u3QTNcIPNA1uB6xlVAWIqnH8tEPyOURjTdT4GWY0ygcntFfn7tZZGizdYqbB vMaCb5H9aeIz4709vv2r4G9swHMg+91E+zRJ4NdPrxqTNLSTuSZeJZsqruU97QVQHyqe 44WA== 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=JlZUHIVX+pLdqy3tdQrgw8rCrC0s3HRsxT6pRIRlNIE=; fh=ZK/DmW1x+WWTXdJ/EJHTsBEUe1j1GuqfQXG5AYfW/uc=; b=BqclM/4oMnQ1e9NGj97OdnDhhaJU9+fhojhr9z3GovafgyMjzjicTaIjusxwzOvypO sCZ76e6og6if02YXqkjlArlidxR2f1xfQuIyJ9L0qBwxru8pZC9Om8QTWLq9KtISvYHO /DKxtAtpsYaE/v0sl46SPhzOktA86ca1pBf2gR6dzJwJntvlw1iacyOiTnpybcO/C5IP /kQO5/zqqb1jfbPaaeCzJGYWlVH5wVf/QiPC/yGPbSUArv6rUhKIhUbdlolvOxSlQaIy fXGqd/+v6JEaj8DfXjAIzMkVkf/z25we17wK0dmA37cNuAwAZfjyihU4poej8+we4I+9 T9Nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=DB0Z17X6; 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 l14-20020a17090aaa8e00b0024dec043858si6223362pjq.74.2023.06.26.20.45.28; Mon, 26 Jun 2023 20:45: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=DB0Z17X6; 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 S229810AbjF0D30 (ORCPT + 99 others); Mon, 26 Jun 2023 23:29:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229501AbjF0D2U (ORCPT ); Mon, 26 Jun 2023 23:28:20 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6CB92109; Mon, 26 Jun 2023 20:22:56 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id 41be03b00d2f7-54fbcfe65caso3376673a12.1; Mon, 26 Jun 2023 20:22:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687836176; x=1690428176; 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=JlZUHIVX+pLdqy3tdQrgw8rCrC0s3HRsxT6pRIRlNIE=; b=DB0Z17X6Lpl4T2saaSH+rXYHxawtqP5dN2yw0s7VS0VB99q80xDbUEkg4AgWUSp0iK sPVnb26Pf7zvgT1qOIje7gXwd9JGrquTTCLwmr1qc4b0XvCZeLqkW0RxOWmROKrCBLJv bFaIxteNjNfoQV+A1fRL4dRRSDDQek8OkHjYVk3Eo9Wc6SVqgrBxZQUZG9euvk/ny+7l WbxOANGYP0nWiPQUFKsGMieNM85vcXr1QUmyRxiUxOmeFp78gwNtVDI9fGw77CskuUkl aLNuWxAwMaME/ttN6S1Xz+r+0sb1/mRHSCu6TmAh3isumIwCo34SySN5cYPvb4zQi6LA cEqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687836176; x=1690428176; 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=JlZUHIVX+pLdqy3tdQrgw8rCrC0s3HRsxT6pRIRlNIE=; b=ZZbzzynPRMvUEUd8zFu/YB71QU8ChsCajxw80Xx0xK6vueHrAQafLK4/J0Jjr+Cbhs f6eUgGP2dol3LZ54IPKwJAAVgsIFeLmOfBx+mPxjhWScJGFQkXXm022BpXNHdgbIhWQ+ cilifdiVTeBSu5Jv5+v4CgBW6s5V5l6DHYuTbYz6H2/SiiCXWhxpn0dfeMCB44zBmb0Y I6rwoe5M2VkyLHFSemAst3t6TibgtTDd4xH43mVz+sXnWfPbYo3/hf/OTLQZfT8zD/HR sIPjsLZWe809XHlnM152cyh4kEixH4EhPhszvJuYHjOSWxjolBlr4NekIeCQ1Ky8/CJa zNQw== X-Gm-Message-State: AC+VfDw9FCxcDd+KAdmnqZyRY3ScGAflOjC3heHi3YCQBUMjuV9U2Gx9 WZ7C8TNxoTfRdzflk+ZNGZc= X-Received: by 2002:a17:90a:4e:b0:261:a75:928d with SMTP id 14-20020a17090a004e00b002610a75928dmr22135434pjb.18.1687836176324; Mon, 26 Jun 2023 20:22:56 -0700 (PDT) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:37:c5e9:2003:6c97:8057]) by smtp.gmail.com with ESMTPSA id mm12-20020a17090b358c00b0025ec54be16asm618756pjb.2.2023.06.26.20.22.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jun 2023 20:22:55 -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 V2 3/9] x86/hyperv: Mark Hyper-V vp assist page unencrypted in SEV-SNP enlightened guest Date: Mon, 26 Jun 2023 23:22:41 -0400 Message-Id: <20230627032248.2170007-4-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230627032248.2170007-1-ltykernel@gmail.com> References: <20230627032248.2170007-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?1769825937048025007?= X-GMAIL-MSGID: =?utf-8?q?1769825937048025007?= 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 Reviewed-by: Michael Kelley --- arch/x86/hyperv/hv_init.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index 1ba367a9686e..b004370d3b01 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 @@ -106,8 +107,21 @@ static int hv_cpu_init(unsigned int cpu) * in hv_cpu_die(), otherwise a CPU may not be stopped in the * case of CPU offlining and the VM will hang. */ - if (!*hvp) + if (!*hvp) { *hvp = __vmalloc(PAGE_SIZE, GFP_KERNEL | __GFP_ZERO); + + /* + * Hyper-V should never specify a VM that is a Confidential + * VM and also running in the root partition. Root partition + * is blocked to run in Confidential VM. So only decrypt assist + * page in non-root partition here. + */ + if (*hvp && hv_isolation_type_en_snp()) { + WARN_ON_ONCE(set_memory_decrypted((unsigned long)(*hvp), 1)); + memset(*hvp, 0, PAGE_SIZE); + } + } + if (*hvp) msr.pfn = vmalloc_to_pfn(*hvp); From patchwork Tue Jun 27 03:22:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 113195 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7923198vqr; Mon, 26 Jun 2023 20:49:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6BHC4bWqeMqEIv90/oGnXGJT1dwi7f5sLxYrVJ2ge13xBaiveILb2GOxbA/hUi//ILS21J X-Received: by 2002:a17:907:3f87:b0:97d:9b73:690b with SMTP id hr7-20020a1709073f8700b0097d9b73690bmr30860048ejc.59.1687837763216; Mon, 26 Jun 2023 20:49:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687837763; cv=none; d=google.com; s=arc-20160816; b=LC4C5oCSZ+NrlI2/IWdBR6WHeM63oSlLMJN/E34qgYkXBoJ+6xksRZcJYky0h3Ltc8 P2qX6VYj8kUi0/KoKxSEYkg2PwfMTlrHnOK0sPvapNUKc8ApxEgbHx0aWXsnhe3Td3Zn iR5ipMTmDlZAit7zGjABc2LWhu3p9aumo/pTo5vLsM/hlhbBwO7N7LI7jOUhFJDdN+HG 4pVtMjE0zRgSGhsStmSBVLDNhJpUJjNeDWtuYjOVSijX/jvLUpqU2a3Bp0c5vEIJAQr0 k2EbpnBZcp9QfrV6gMFvIKFKafslKqHVMPS5q4qMJdPPJY5g0t7s6aogse0HnLdPVhDJ YHqg== 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=fCJn92OFxJwU4IHGtLWMi2EWhzMeBfc+oQquYxaIu1M=; fh=ZK/DmW1x+WWTXdJ/EJHTsBEUe1j1GuqfQXG5AYfW/uc=; b=OYVoe5ERsSTUCQ4DlL4jTUiCi4kmWTesTnmQAJY4CGIEj38kSQFpPSZUdkdcly9rH3 IBhUeKhXBT3TDM97UXgdeTWTcTejz63GDa7ZgimmQg1E/SI40ARxIk4EKStk32ZZsqmU 5ZMJKApnrTGAKyUAW36GhGKA+1pKCbKvGpz9qouu7VtC1RqYcI0MW8UhCvoUpBnXB/uF EZihMM1zzmpWCPID5KPgoEogDXPSrfn34QxuSbpFiP5RmzL48CT51kO64uHZa30EShtT TrHSkJt5HaznvD3ogNMjvdBleP0/S3a7QI2B6wlvOdHohUBlyRumtHqttXVQ4E+FVc0M mzSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=JbFLkeTa; 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 j11-20020a50ed0b000000b00516a20ac223si3317390eds.650.2023.06.26.20.48.59; Mon, 26 Jun 2023 20:49:23 -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=JbFLkeTa; 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 S230230AbjF0D3O (ORCPT + 99 others); Mon, 26 Jun 2023 23:29:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229742AbjF0D2U (ORCPT ); Mon, 26 Jun 2023 23:28:20 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 675942108; Mon, 26 Jun 2023 20:22:58 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-25ec175b86bso2944637a91.1; Mon, 26 Jun 2023 20:22:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687836178; x=1690428178; 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=fCJn92OFxJwU4IHGtLWMi2EWhzMeBfc+oQquYxaIu1M=; b=JbFLkeTaVejKuX3CeuGv44gh+qkdefxVqrHJOKNTDrxVRruZIyb0M4GfupBU7MRgwl 1QfqHrNFWnAlAX2c5vvQb8CfQ5RUudBYAnrzYxc3UQXsEwEMgi0RUWDwHVy0VABtOKzJ gbPlb/iif6JFZDpEhAtRTb9N5Tt2d0HR+RfKjSqDxf+JnVvRBjWqbhaOBBLlJ71VrfPk 6AdarjmdqyR9xzmP60NECzv9U31LlPl+oShpHXyuo+sD0sAEmJdm9kH1mmMLbZ/7dlwa TITD2U9Vn+cNuhwpLsKNN9W75FiETCk5KH5caVuvoPwkLasWTxo6KJ0l3dhCITCJhW8h DpyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687836178; x=1690428178; 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=fCJn92OFxJwU4IHGtLWMi2EWhzMeBfc+oQquYxaIu1M=; b=bxyf/xcAFvF2H/2yffRdBnGLEff95l/d5hoPYUzA9wENdHJgqt53FbXJy6YyNuYZnZ 1yIEzbArOapenrPdNRvjof+0ki9XJdHRaUmYhYT6PUXDL/EHTpux5GFJqyhM49xbv/TZ EVrOOn0eDwvS9Qk5c+IYNys3QdPf0qlRfPpDh0uZt6VQqNWXtuRih9pJ7/smmTKyApFh L2kmqnIBU+SCAcKz+E+a/MBqxsAcp6/esLZX/Tj8yiGpAZYCssK108Ktjd1aYd832iAQ 2TCE+o+UF/6F5pAuaic/sHUwJ9SEHOzqP0B7sI4DWv3zhisQvxtE74B5ffvc5bTLlPPz /XEw== X-Gm-Message-State: AC+VfDyL6h1iIPiq98LUkDECKVjtKlvC/EcnjhXXTl0Blj3oa/LwaFjW 2dWViUsUthid/zsaIeIlyaY= X-Received: by 2002:a17:90a:7042:b0:255:cddf:a0c8 with SMTP id f60-20020a17090a704200b00255cddfa0c8mr29171624pjk.41.1687836177773; Mon, 26 Jun 2023 20:22:57 -0700 (PDT) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:37:c5e9:2003:6c97:8057]) by smtp.gmail.com with ESMTPSA id mm12-20020a17090b358c00b0025ec54be16asm618756pjb.2.2023.06.26.20.22.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jun 2023 20:22:57 -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 V2 4/9] drivers: hv: Mark percpu hvcall input arg page unencrypted in SEV-SNP enlightened guest Date: Mon, 26 Jun 2023 23:22:42 -0400 Message-Id: <20230627032248.2170007-5-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230627032248.2170007-1-ltykernel@gmail.com> References: <20230627032248.2170007-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?1769826170254334974?= X-GMAIL-MSGID: =?utf-8?q?1769826170254334974?= From: Tianyu Lan Hypervisor needs to access input arg, VMBus synic event and message pages. Mark these pages unencrypted in the SEV-SNP guest and free them only if they have been marked encrypted successfully. Signed-off-by: Tianyu Lan Reviewed-by: Michael Kelley --- drivers/hv/hv.c | 57 +++++++++++++++++++++++++++++++++++++++--- drivers/hv/hv_common.c | 13 ++++++++++ 2 files changed, 67 insertions(+), 3 deletions(-) diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c index de6708dbe0df..ec6e35a0d9bf 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 so that hv_synic_free() + * won't later try to re-encrypt it. + */ + 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 4b4aa53c34c2..2d43ba2bc925 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; @@ -378,6 +380,17 @@ int hv_common_cpu_init(unsigned int cpu) outputarg = (void **)this_cpu_ptr(hyperv_pcpu_output_arg); *outputarg = (char *)(*inputarg) + HV_HYP_PAGE_SIZE; } + + 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); + } } msr_vp_index = hv_get_register(HV_REGISTER_VP_INDEX); From patchwork Tue Jun 27 03:22:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 113192 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7921849vqr; Mon, 26 Jun 2023 20:44:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6HffyNJ1t0jOqCfYnPlnTaGgU+e54fX3O/XILkU7jBNg7z6rRmT1GFdDYJwT5ZvwVy7LDV X-Received: by 2002:a17:90a:134c:b0:262:f798:b60e with SMTP id y12-20020a17090a134c00b00262f798b60emr4239038pjf.43.1687837496113; Mon, 26 Jun 2023 20:44:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687837496; cv=none; d=google.com; s=arc-20160816; b=xYxFX2+UnYrd2cshG4v6lZq6J+r5Xmw2Sz+RXWy/ldJSNyFSPx+hrhQqDiZEqurPkU ukgyy0agdbCFcUyaVt/sKL1Rl3reieyju2fHcuulH2zGvqxI3/5DwUYSPnPqB9R+IqnT GziDBEggEvhx7JivNBT0nVZItD9S/8NPgfoOK7+hUEFgzswNEfKTiMhZhV54OutELJ+Z 0XFEEGY6WZpEt2qfSg+zQEpaCUVLA7gBiFT6H4O1si5+jOC78dvoTAhsUev2VEG+Vts1 BH1RSYD2248RMJV2r92y1m0yp/wpeMiBpLL0xEcK1MarVsmqDTRhNHcnbATubeUxutce Ocfg== 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=WavXlIUDaiNvQ7Jhn4eQcl+B7LwqPDg8ntyEa3A0jyM=; fh=ZK/DmW1x+WWTXdJ/EJHTsBEUe1j1GuqfQXG5AYfW/uc=; b=A/VuEucYnYsV6IQqzJAkLzMdD/9QlSi52a6DlNJ8LqRrS5Ik1Rx1gmkxQBHa4Cek9F AkhNb1HQY4Va1ZCgQaoX0kBw93djNkriDdkG/xgsFZUwevpzD5qoOw7tiZaA0V82dR6m 6CWWh0owi8iprx0CNO6Iyh0HF5mdIPQO2c/lhbj9bnS65VyvN2Er2Y4ywTbfqMASxROK x4yRqvoCeJjDv/g9iNelCG3nSAzMo+2XpJn6IadUG5xxH1nwg0rtQptpPai/kST8+fMW E/CZrAe/ear8RlSVJmqknC8nPJhQP+A0vYbPwkHMDNVT7/L6xkgpLPjkhL2OasttBfOe LAjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=LSRiUlnV; 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 29-20020a17090a1a5d00b0025be125bda9si6424703pjl.38.2023.06.26.20.44.43; Mon, 26 Jun 2023 20:44:56 -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=LSRiUlnV; 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 S230269AbjF0D3b (ORCPT + 99 others); Mon, 26 Jun 2023 23:29:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229653AbjF0D2V (ORCPT ); Mon, 26 Jun 2023 23:28:21 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B627C2117; Mon, 26 Jun 2023 20:22:59 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-25ec175b86bso2944648a91.1; Mon, 26 Jun 2023 20:22:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687836179; x=1690428179; 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=WavXlIUDaiNvQ7Jhn4eQcl+B7LwqPDg8ntyEa3A0jyM=; b=LSRiUlnVbD1yG2LtgeNbwA5zFxbzqYOZMJQQOSULLaJJLryLZPpcKSTWUqJvZt4Qme OQc7BpsRmxlvTFgL8eFXT26zQTRFpN7CL7Eg2ZApv1ea3T1bM2OwHzOP+qQo/DMiMydl m5k1OTpGQz9kXiIzwZC6JoLBfQ+S4hVOGciYKWnEICaM8jJuWqahZu03anyCH1Vn37fU MLPDgVVy5G9paXDSIQ8wPTof6jMTMmyVPmgeKV8soGX/dB8tEkOWyMj+IiFhVedctgis jEaAe44y9o7UZhiQyYGQshMWn/x2Oe8wl5xg7bTgGHalCuVBxEdtKL7+WjGk9m1vj5FR lrqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687836179; x=1690428179; 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=WavXlIUDaiNvQ7Jhn4eQcl+B7LwqPDg8ntyEa3A0jyM=; b=Yft2M8fpU/CZR2uz/wJU1xx6NVZ5hzyZFAkLFzJ9kZ4q2zpeje+1G9yzxolnSJ9LXw JrMh2cQs/yH2Nh54J0fun595XDsNAmT9iKBhw6Fd4qwefTkSvMZaXt4VYcjU2fTRJZOJ I2sAcpee9e5wN2a/bk1cDfZ/0u6SrIopt6CQyJx0FM5UXl93DhlOcKtUHb2Yw0esDNpy ql8h6O6rH16C46rGmMh36jaCwDQRaXr5mUW5yg5XKgsaVbNsWyq/8K6tyzI8JQ0hcNjo rwUjNzZ0TWqcOvKzNtmBMYgMo0SdK9078LOEUHS3+CUDbQt9bLPMr276r3Vgm2THr+99 zN6Q== X-Gm-Message-State: AC+VfDzUcukr1s652cTi9FhkFcJUbq8XSc+XhfHkDVfbiSOEBLZlpdTJ E1Ths7hfs0OnFbLn8+9rdMw= X-Received: by 2002:a17:90a:19ca:b0:25f:20f:2f7d with SMTP id 10-20020a17090a19ca00b0025f020f2f7dmr23774243pjj.2.1687836179114; Mon, 26 Jun 2023 20:22:59 -0700 (PDT) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:37:c5e9:2003:6c97:8057]) by smtp.gmail.com with ESMTPSA id mm12-20020a17090b358c00b0025ec54be16asm618756pjb.2.2023.06.26.20.22.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jun 2023 20:22:58 -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 V2 5/9] x86/hyperv: Use vmmcall to implement Hyper-V hypercall in sev-snp enlightened guest Date: Mon, 26 Jun 2023 23:22:43 -0400 Message-Id: <20230627032248.2170007-6-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230627032248.2170007-1-ltykernel@gmail.com> References: <20230627032248.2170007-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?1769825890254076463?= X-GMAIL-MSGID: =?utf-8?q?1769825890254076463?= 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. Signed-off-by: Tianyu Lan --- 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 Tue Jun 27 03:22:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 113196 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7923895vqr; Mon, 26 Jun 2023 20:51:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6znakN9FClcLkBNIr2fXBImOUuaQxik8vCwLRH2TwfnnjyYTENwiMAoIdrhO1ROoDt9Yq1 X-Received: by 2002:a05:622a:1312:b0:3f9:d266:7bcc with SMTP id v18-20020a05622a131200b003f9d2667bccmr35523338qtk.38.1687837890720; Mon, 26 Jun 2023 20:51:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687837890; cv=none; d=google.com; s=arc-20160816; b=f31teVGNKDcl5UgOW6KFy/PUoJkpFsjXQtw5P4Z4uKcP61ky2W3X5ADRb/JPkipnqS OTfjNH7Hzc6bXKzSG0bVe0Aobsxfx/2GmZUbmDzmyAVE2VgElGJqMYeO9dvp7LQQMSsm cHxjqdtUo6pcndnwotPe+QJMvu1w5fQ/0nOLkFU+5Ror4ZIBWXp06g4j7UXf3LcUOeMD P0r2udiX9OqTDMHvdrv4PQcVDbfTaJgZB4He38DPvjivQqK+0VA9YmKziWKCWf6zFbS3 rbGAyMIiwz3gMOGn3B18k7FlSSTvdregnzJf1YZDd+8iE+Dxyo+VE48KBDbBuGo4nbyr yStQ== 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=; fh=ZK/DmW1x+WWTXdJ/EJHTsBEUe1j1GuqfQXG5AYfW/uc=; b=XR6/XEHcPp1zlWIc2zdvUTZ5xS4Jm2MtYy2/u90DZj7sGtcBuVOk9tnJFqRRy+nHOw UnRX8xL8J+NIHFVu465IZjAm1By/PTagDwjFDCEQy++kckO5/DDZv2Eq4pJ1IJiPxAZY 4Fz0OGE40Odfg4KA1ZNqxMzLN8wdZVvkcwaIgrxPtp1hE7ys/C3lQwbBe2C2G15RhNVX 62G4YXJUJqt8giIfg09oCAoYrDUtOKfgOqwnfAR5ChYkRkXcnCkzSZzt4ScpuqJ77Tk0 8P0gOB8RJLfUp+O+iMNqG5Gn17W7Hidl6r0MFhJ4KVTB3Sw09zfS5k+p3NZbVYvMJUeD kA5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=akngYKBl; 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 d8-20020a056a0024c800b0065930ad0643si6364451pfv.79.2023.06.26.20.51.18; Mon, 26 Jun 2023 20:51:30 -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=akngYKBl; 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 S230284AbjF0D3j (ORCPT + 99 others); Mon, 26 Jun 2023 23:29:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229623AbjF0D2V (ORCPT ); Mon, 26 Jun 2023 23:28:21 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 344622115; Mon, 26 Jun 2023 20:23:01 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-25f0e0bbcaaso1934878a91.3; Mon, 26 Jun 2023 20:23:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687836180; x=1690428180; 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=akngYKBlJ50MAGPqRAGc1r0u1GU6Eqd/kAPm+PCdK8pSl+BholJ8W5Lz/XKnrwxX/f XnfqQZCHFL4E3BVGKY1SMlHs+NQCxB9766HYFgLJNBCA3n+GCUq9PX3hcptZdmN/GDK0 eTp9qy4HkSuMUg7ntO6H+3RPeDxLRQiG7+OJP1ePF1Yv3QhuQVsG52hTKdJaNcqZSxNK BKLbEut+IXrScoi0AeaKz3UqI2w/QVgciZFaj/fKtxcWnAi1BRBz1StRmLXlilAAK0uy 8I6YPeJAJwukwzJWe+IQJvM4W19WDMFMZ+Grkr6xjMFE0uoIkwKl4JiHb6muyR0mc1Xq nP7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687836180; x=1690428180; 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=KZ5lrT1SWyVJJc4vNXmzflQch5kP/Y35+31v3Xhx0X+p3q5aacs/+sol4vKtNQFqjs 9QMk+eYyiGnGCVVbkEChKzDeP9Ictr+DBDNmlHwAV3i9z9OVm+yRj+f/qwlYeve4vHBg 43RB0gp+kgcY3ilsDTVjwBOQrCR14ynAqgYEWOo5az+kbLIHNS9lVLsbbkYIDeiWTzMU 1hVAj7wGjEH33tvvSpQea61ztlAMulC5xkKOFezVNyiZctWzDgPkJQNPq9nzinBg/LjZ /CNbXpftntwT9IBGdetvzOLZQZGjrZHiNW2NEkiq9dma/zikBDXjyAn8AZLuBGIoAMWJ 6d4Q== X-Gm-Message-State: AC+VfDz5o/OZTZJai/t7Z+Ta1Kj9xy52gdbqy7QyenfciypMcrMPPXPL eaUazSZmgh9rKP2EU3pHayw= X-Received: by 2002:a17:90a:354:b0:263:14fc:f9a6 with SMTP id 20-20020a17090a035400b0026314fcf9a6mr787598pjf.14.1687836180547; Mon, 26 Jun 2023 20:23:00 -0700 (PDT) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:37:c5e9:2003:6c97:8057]) by smtp.gmail.com with ESMTPSA id mm12-20020a17090b358c00b0025ec54be16asm618756pjb.2.2023.06.26.20.22.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jun 2023 20:23:00 -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 V2 6/9] clocksource: hyper-v: Mark hyperv tsc page unencrypted in sev-snp enlightened guest Date: Mon, 26 Jun 2023 23:22:44 -0400 Message-Id: <20230627032248.2170007-7-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230627032248.2170007-1-ltykernel@gmail.com> References: <20230627032248.2170007-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?1769826304362761505?= X-GMAIL-MSGID: =?utf-8?q?1769826304362761505?= 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 Reviewed-by: Michael Kelley --- 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 Tue Jun 27 03:22:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 113191 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7921046vqr; Mon, 26 Jun 2023 20:42:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5WGVd6TliXv7RnzW/hAmg/SyMUBeQ+7RegSLd3SlTorLRjyylX9X4gtBiJDa5AvkpzUdpW X-Received: by 2002:a05:6a00:23c2:b0:668:69fa:f791 with SMTP id g2-20020a056a0023c200b0066869faf791mr21097244pfc.3.1687837345142; Mon, 26 Jun 2023 20:42:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687837345; cv=none; d=google.com; s=arc-20160816; b=NCE5fai9skhiVmspwIjDXxBKB8Z1RPDpU5fAVjJkfbwq7akRBG6aHSGvI88vBXAm5d ETTAdVdS3cfGocVDYrWfUTfDyCUlZPI5S1lLnxEGoioW7eIBMh3L7zb7K6OHx6gcDyMA i7Be570SSiWowlrM/+88tavQ32oJBYQP+6MaKF3N3Byk9v+1se3tdD7j4OF73TMCBry/ upsmdEFyqFbN68dIvT+iO6HgIIjipytw6gvAHEypq81HU1Vza+J7/FGFN5bUISvQi3L7 IFDs7BTo0L5jVZRTaHuTnEBLXK2HqVykIvzSL3XQdTl93PK+tWhlug/xoXW9TV9wNrgb g/uw== 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=IJTPSxR2JGN4fgMuHptSG8Hdo91/jubbscb7t5UbRBo=; fh=ZK/DmW1x+WWTXdJ/EJHTsBEUe1j1GuqfQXG5AYfW/uc=; b=UUF1URHIiZIh+eIMxusBLlGIkTwusNmczxvlJVfx6vqcIAEZqbAHFxX/ij/RDAxCVZ 4FP/wAqi+bzTGF5KwS8MbIoVqdoTxXuPLqVsgbtfE3LlOoV16kVMeGUMc9Ygbd7FjA4m AowEJuzsU3w+cDrSzrdr3qCsrdwa9H1Q/AydsddYLSizQuELZWfcj6WBQzqpzQUlCc88 M+NNuPemhTzLNiRm7kDMGnadAlGMQjk5vhjoKc4AOvQTwtGFOT3Ml70QXYC4kwd0DHsQ cedBlTlUgsOPHCYk3YcWRKUfv0Cno3FvpOOGROWRd6X6kGaI40cu3Fem+F8Yo3VyLk7b QTAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=rzDQGPna; 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 b15-20020a630c0f000000b0053084a794f0si6529916pgl.290.2023.06.26.20.42.12; Mon, 26 Jun 2023 20:42:25 -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=rzDQGPna; 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 S230336AbjF0D3o (ORCPT + 99 others); Mon, 26 Jun 2023 23:29:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229628AbjF0D2V (ORCPT ); Mon, 26 Jun 2023 23:28:21 -0400 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F0B4211B; Mon, 26 Jun 2023 20:23:02 -0700 (PDT) Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-55767141512so1729752a12.3; Mon, 26 Jun 2023 20:23:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687836182; x=1690428182; 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=IJTPSxR2JGN4fgMuHptSG8Hdo91/jubbscb7t5UbRBo=; b=rzDQGPnaqRnWoXI/FbVlXs2gDJI3IyYY8/Rj6Qj5+N2MJO35f66NUsLN3FZOKOxvSL WGIL4dO94S5C2vQEwP9Lsla+yoJpHQyNF7FI4yQulIMmk8XZK7HYG3Optpme14KVrNcc tfS6oMBXyV4T0FFCGQvEtsnihEy7EByahZhuCDvdAPZZ05cudg/bR6tQNmMWLeJjeokm iYflSwyu70PMdtzqFKRyKKwRSpHJaQQ41x+DJrnvt0kDrm7Pc15pRNsEbODakM1LMkiV VzHnMBb2hmaT1Gzi1v9FnexRjuNen5KcLwHnTjuv99mHPrN6biEG8TMgC0VrLPyo8C1z 6TwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687836182; x=1690428182; 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=IJTPSxR2JGN4fgMuHptSG8Hdo91/jubbscb7t5UbRBo=; b=QcoXjYaLniFBGaqmnqiEGFJ2da7c3GCrerxgqt/H+BRq8bxTPJ8tX0zchvlSJqig+c diZvuGZqemmn4U+7Cn/YGXKcxy56FjgPbT9nOfMS5e4hA15swn+yuihLrmFZ1eg9B52r nUgvYbWdf8eDd3qipFiJnW+iD6l0yL/Pl7VqTLjujXgElXLk9s1nFMHwzwdjw6xAr36o yoSxlliyyggZyMhUPsb5uEST0LC614N7GdnYSo973mLgYAeE25vGU4d0jrPVC+TQkwPF X1DVKFEn4oaipoCwvj0fnQUiM39M343L9tsJ/hWAZ5J+oK/FUMxqNctv2sI6ELo+R9EJ Umgg== X-Gm-Message-State: AC+VfDwWmP0ZcX+2Mi/XdCRflqCzceBLhflHTDCr8FktOPnT7JW0kbl1 5YaggEr1k3YuED4CPOx9l5k= X-Received: by 2002:a17:90a:4902:b0:259:a879:cb8f with SMTP id c2-20020a17090a490200b00259a879cb8fmr16077197pjh.7.1687836182033; Mon, 26 Jun 2023 20:23:02 -0700 (PDT) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:37:c5e9:2003:6c97:8057]) by smtp.gmail.com with ESMTPSA id mm12-20020a17090b358c00b0025ec54be16asm618756pjb.2.2023.06.26.20.23.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jun 2023 20:23:01 -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 V2 7/9] x86/hyperv: Initialize cpu and memory for SEV-SNP enlightened guest Date: Mon, 26 Jun 2023 23:22:45 -0400 Message-Id: <20230627032248.2170007-8-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230627032248.2170007-1-ltykernel@gmail.com> References: <20230627032248.2170007-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, URIBL_BLOCKED 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?1769825731804624225?= X-GMAIL-MSGID: =?utf-8?q?1769825731804624225?= 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 protocol (Please reference Section 4.5 Launching a Guest of [1]). Kernel needs to read processor and memory info from EN_SEV_ SNP_PROCESSOR/MEM_INFO_ADDR address which are populated by Hyper-V. The these data is prepared by hypervisor via SNP_ LAUNCH_UPDATE with page type SNP_PAGE_TYPE_UNMEASURED and Initialize smp cpu related ops, validate system memory and add them into e820 table. [1]: https://www.amd.com/system/files/TechDocs/56860.pdf Signed-off-by: Tianyu Lan Reviewed-by: Michael Kelley --- 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..b1639ec07155 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" parameter can be true only if old-style AMD + * Opteron NUMA detection is enabled, which should never be + * the case for an SEV-SNP guest. See CONFIG_AMD_NUMA. + * For safety, just do nothing if "early" is true. + */ + 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 5398fb2f4d39..d3bb921ee7fe 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -529,6 +529,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 Tue Jun 27 03:22:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 113190 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7920405vqr; Mon, 26 Jun 2023 20:40:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6pv08eEKbkm/EB46iOE9CUF3JDQxuQpC7figH0rhy3AsZrBrms9RE9vJlnvcCRnz9CdwTW X-Received: by 2002:a05:6a20:7349:b0:11c:d2d0:6439 with SMTP id v9-20020a056a20734900b0011cd2d06439mr52544918pzc.25.1687837226801; Mon, 26 Jun 2023 20:40:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687837226; cv=none; d=google.com; s=arc-20160816; b=Wxi01PEOYnBHj/0FoXq3s2cClpCpcJFhGjq5HVCj5IU5e67d0kB4gloZKWzX/hRZiW a0Rqb/foalz2mNQWRLzuJzK3NX0E8AfdkJWWX8mU4x5jy90CWNm1jvuHDEB7YJ7Qxypr +/Zon782Ota3cWxAcpTIrqBjaEf1/LD0zCvbFfvt+3P/KIeJyRoCQorQ8QDfe8QP25HV oNuZilLGX4XGwztDKDYQvVPnTFJgOcYO7UYTNMMivRxMLC+nI1N//hXPPftbulsJSHZS Jnwkt5yt08N+4+hJJuBoQUxcW+qr7+sA6SbtrmhilKFuqFRg6AKvID9ZGj6KguIdaz7Q 9B2g== 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=bj0GajAExDkGrY+2aoG6AAOFcPqRGDxZFdmu7SDntpw=; fh=ZK/DmW1x+WWTXdJ/EJHTsBEUe1j1GuqfQXG5AYfW/uc=; b=AkY1MNGjK9cmUpAEwqcvk4vD190oNCA40gi3Cx99088FrKu6Iti+C0eFW1e8LYkxrQ Cf2Gf99xJE6i7CoLfPB8yJkIwsCw3tw6iTH8VsraTyRcaUSTqYtMD4MoOPfuZ7HwQY03 H0bIgq5mXFo6Nw1keie33u+yBdG6GHFLKxTwmKJEtIxcv0Wj4zKzEYZlM5KxSfhMefg3 pbENNrQ1qeV/Dko09xbq29wzpBfp7z+6FqkPvBETaw4/V2PlaArBHAerAkN/zmQh7ZG5 gV4hZGTSxA3S5la+++kVgL3YWonbytDGffxxZW046JVncdR9gHPOfa6dfmQi8WDVw+G4 fMKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=BSw+LTRV; 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 v186-20020a6389c3000000b0055384eb4f43si6625279pgd.221.2023.06.26.20.40.13; Mon, 26 Jun 2023 20:40:26 -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=BSw+LTRV; 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 S230353AbjF0D3u (ORCPT + 99 others); Mon, 26 Jun 2023 23:29:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229759AbjF0D2W (ORCPT ); Mon, 26 Jun 2023 23:28:22 -0400 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2DD22120; Mon, 26 Jun 2023 20:23:03 -0700 (PDT) Received: by mail-pj1-x102e.google.com with SMTP id 98e67ed59e1d1-262e5e71978so1363757a91.1; Mon, 26 Jun 2023 20:23:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687836183; x=1690428183; 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=bj0GajAExDkGrY+2aoG6AAOFcPqRGDxZFdmu7SDntpw=; b=BSw+LTRVdT1e7ZkI8XUBBv+rzxoFPY2eJ9u1G13E4CvIdoq/K3rKVp06esoyKvEsJd 6nnDvvTRROlVn/1/AdUVrp2iR9sV2qfaeGv/SxY8ituvxBTNsi6Fz7mPYrgF5RE9eetN IoE0nB2k0DicnfUkFfT8GScnLgG6eDbf2Y4RWbSTd2G6B/9wyMLpF5qSvZLIPNkbNsD2 juhfNjwx8MuszauU5AMMdQIgb3zwHwi8r4Cqz/zSincCwLAiY6PpO57OQsXNzBlqHeny j6XtOqQybuNLQW6yjsuTAze+NjGHNaAsFMceyEW+YLYyHs268P/FHn6qC8NXmdRfOE9J J8QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687836183; x=1690428183; 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=bj0GajAExDkGrY+2aoG6AAOFcPqRGDxZFdmu7SDntpw=; b=Qh/4YYiXfjIC1NSCGxW/7hhUC0p3pOaXE3BKUwV61n4vGl20hPJ8d6zfVJQT6UM9+w 89dNeioDXSX0pODRGIdRKrE4tZhhUh610MAilAhY/xL7sA1Dr7MgPl38+1EThvJPjYB7 h1KtBERCgw/BWYVlGa09Z9rEXRZ+z8fbTr/yb/mm4vn3+g9PeAOawKScXUt2xfHEkdgf cve1eWxJgTGFNx5RSsuhdISKJ2rvQbf572k8vAhuEFSatTTmVYl7GdsZUkamFujjXWqn 3E0KlZ/P3wbMIVWLOxEEvEKcxOb4e+q6Cvyew5C8A3o00WKJFoBPobX2eXbKTydzr+oC OygA== X-Gm-Message-State: AC+VfDzmnjqB2bjI2h4D5rBQ9zZ/HEMr3J7qMQ5yRgmIp6cTBdm00sfq eUms3Xio2JdUmVbUqcKyW3Y= X-Received: by 2002:a17:90a:6f43:b0:25e:fb6d:ce68 with SMTP id d61-20020a17090a6f4300b0025efb6dce68mr35450752pjk.6.1687836183325; Mon, 26 Jun 2023 20:23:03 -0700 (PDT) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:37:c5e9:2003:6c97:8057]) by smtp.gmail.com with ESMTPSA id mm12-20020a17090b358c00b0025ec54be16asm618756pjb.2.2023.06.26.20.23.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jun 2023 20:23:02 -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 V2 8/9] x86/hyperv: Add smp support for SEV-SNP guest Date: Mon, 26 Jun 2023 23:22:46 -0400 Message-Id: <20230627032248.2170007-9-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230627032248.2170007-1-ltykernel@gmail.com> References: <20230627032248.2170007-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?1769825607782653913?= X-GMAIL-MSGID: =?utf-8?q?1769825607782653913?= 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 Reviewed-by: Michael Kelley --- 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 b1639ec07155..9b307f99b540 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 d3bb921ee7fe..8e1d9ed6a1e0 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) @@ -502,8 +512,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 Tue Jun 27 03:22:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 113201 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7936190vqr; Mon, 26 Jun 2023 21:24:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5VttKPQZz5RMUmj3XWYOvpbsRJpnOYCbed6X5AOlRZO6IzDMC8W9CEHTYERAURcb4Rk7iJ X-Received: by 2002:a05:620a:8b0f:b0:766:fc65:b7de with SMTP id qw15-20020a05620a8b0f00b00766fc65b7demr2312888qkn.28.1687839841629; Mon, 26 Jun 2023 21:24:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687839841; cv=none; d=google.com; s=arc-20160816; b=uDw1JOuewd2dHfF39UHr0cV4Fkfbs0ZpHsboCiSIq8VydglwU6xm5aASrtynwitvpY JJsun/TdOBReWzNMu6naZXbUl7Qwi7etczZVzBcRaOXfLO2PJ6gh5FhKtZnAiYfseG9Y XEg8cvCCFpJYjQztKUNr5MW+Ebr5Wdh08XxOam45WKneNclHL22Z8SzAakKWpSx/hF98 he5Z/3AO8FC85yf5jtWw7lOThIo9cIDaa4Zxfm/l9k9mBbifu+OOtn1VorAIalPfvih+ 1KAmdjZ/M2Vn8I8THavjBRbFrWmqu/OQ6Px7SiFHbgSS7JH6RTMS8psJpgSq2s409t8A vAUw== 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=mOH4gSPEIhpTW98QIj0wv6cpCR35fy8xVOmhHBHDwaY=; fh=ZK/DmW1x+WWTXdJ/EJHTsBEUe1j1GuqfQXG5AYfW/uc=; b=xtcd7S+JtDw6ZqB9rYQq+FCzVzk17TEWPbgo2PAcyFMwOZS+6WoKelGGbn/XnfMGph h1+8wTzLksoRFufDWNbvXHMxyv4dCitshR7oRV9Gb0XIywhrZqmQFlmLy1OeCJCTQrNN 3piqmwAEzDA+8lpLu0ftKp2sxuMAuIJ/GJdxATSSZ0ZxpF9sfFRfKNNgM9BqFdSAk1hR 8166KZITcg10pQmcKeRCg9tBsg2ROLlBesU0K0nz9Bpj786E1LW8rdVsWdUSTfa6+rcP vr+l9qyBmm9xn9lMrLat1qlBadOXp7lFTtjseW4ydVcAyZbPb2O08DE+U52F1h8eW9ZX 6Y2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=ANaNPobi; 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 i62-20020a638741000000b005443ff97149si6796205pge.331.2023.06.26.21.23.48; Mon, 26 Jun 2023 21:24: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=@gmail.com header.s=20221208 header.b=ANaNPobi; 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 S229851AbjF0D35 (ORCPT + 99 others); Mon, 26 Jun 2023 23:29:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229886AbjF0D2W (ORCPT ); Mon, 26 Jun 2023 23:28:22 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F8392126; Mon, 26 Jun 2023 20:23:05 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-54fb23ff7d3so1993391a12.0; Mon, 26 Jun 2023 20:23:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687836184; x=1690428184; 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=mOH4gSPEIhpTW98QIj0wv6cpCR35fy8xVOmhHBHDwaY=; b=ANaNPobi1LlQxW0wdCG0Glnw3AHYwUIa8Qg4DBjBLvScG0WBKr8qCsf7Mz+18u/WU3 6dnIcVY47eOtyjpkaJW2cwyZTRkxtt7WjcP/1r2C0JYR4nlZbgTajeasbRLIeXdjnpSr pgJH+0iCGnFXJZLFj9ubxwQZlVh4ApQop/80AwlYke3TSc+1HoTIcvK2Zd16Aa9T/UoJ aGzVTEb5uixiEWDzFa45ZsAj19OfxlC6Vgvv3g8/E5CrvvsVDH0Uf6cISC2eKl79G1MX o8q2alCiD3y1+06C69O4r2j5dX0F85D1sY52ObLUgxLFJWE3Iw+tDzOboKE2N/izIfNQ 1juQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687836184; x=1690428184; 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=mOH4gSPEIhpTW98QIj0wv6cpCR35fy8xVOmhHBHDwaY=; b=QozppQlYoYy/1RyqNBMof2wLBCn+nw5LmSRh44AhD92KPT3+IBF/tJYRB3kf0yQg2T szVu3GVp4kTnXIO2gCv+Q6NPKi6WZd3nECeUPeKj8MR+7gQU72AVo836OOytkcEdWjo1 ynR6f+5vrVfVessoJcDIlUICmr8G0LPw51XCIbCepNC2qb4mwPJs1PEJq+f9AONuhLQX HsQSmK7wIIZKyvEMozc/993M/qvMAh4ATrLkG/Uvn/Md9UwA4opkHmK+F/R6xp4ov49g QK/Fniw/pjWHQLCWk41EYnE2gnb2t3uIrLoPWD4/PiGhjzxqG62yr9zZrt+e2WKjiG3F qvlQ== X-Gm-Message-State: AC+VfDxCTL7rGs6XmZCFC7L296/xXnXxsCn9jLGANa2wjt0QtsY3cG7R /qlxkRsKJsAQMMSWAePurQA= X-Received: by 2002:a17:90a:1906:b0:25e:ae0f:7311 with SMTP id 6-20020a17090a190600b0025eae0f7311mr20920818pjg.23.1687836184513; Mon, 26 Jun 2023 20:23:04 -0700 (PDT) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:37:c5e9:2003:6c97:8057]) by smtp.gmail.com with ESMTPSA id mm12-20020a17090b358c00b0025ec54be16asm618756pjb.2.2023.06.26.20.23.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jun 2023 20:23:04 -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 V2 9/9] x86/hyperv: Add hyperv-specific handling for VMMCALL under SEV-ES Date: Mon, 26 Jun 2023 23:22:47 -0400 Message-Id: <20230627032248.2170007-10-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230627032248.2170007-1-ltykernel@gmail.com> References: <20230627032248.2170007-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?1769828349477332323?= X-GMAIL-MSGID: =?utf-8?q?1769828349477332323?= From: Tianyu Lan Add Hyperv-specific handling for faults caused by VMMCALL instructions. Signed-off-by: Tianyu Lan Reviewed-by: Michael Kelley --- 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 8e1d9ed6a1e0..ba9a3a65f664 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; @@ -577,6 +578,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, @@ -584,4 +599,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, };