Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp438508rwi; Thu, 27 Oct 2022 03:28:15 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4x9LqW8T10DTX1pfYkm30jqElHWqjGTml/2pCdRo7kDaguAefMr+vVVGzrQZm4+esYiDGa X-Received: by 2002:a05:6a00:24cb:b0:56c:7815:bc7d with SMTP id d11-20020a056a0024cb00b0056c7815bc7dmr5880282pfv.44.1666866495560; Thu, 27 Oct 2022 03:28:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666866495; cv=none; d=google.com; s=arc-20160816; b=F4MidpnnvPafWgzMt88nOIn7B1iqHWungf+dMfytEWqLitAw54+DPo/8UhN7I/4KnL zd2c+11L8Ozty91pgQvkUfvJ9N8+kwfeGDXwcj3GmHyJXxESvy7iwELX7hinlkk6Xphj 79sIUaOtrftS/b21rOfUEi5hNw16drs/oUPFMnHAIGoOi30s7+NR0P5DLaAaoljVH8v4 /WS7N/5mmw1H09cxuPVA/rqfotl+otSJ0LtTfdsyTdJXZxcJVTS81TUrxG5NcV1OemGH O/RuhxgDvdV463UCklTEeAnmoO5GFgMXhq+cKxtMsXMZqhlcQ2b2bHf0/UcHgNiciGyh E7pQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-filter; bh=6KQYehyzA42XebAaFlbNJVdMgguB/LDgiJKpKe/Ug68=; b=hjNLyLMpk5cycemfZwONgwH57ikEIsqCOttqCJbkOXWSlJZUkZ6vElx/zolHBRk4UR 7mvhHXNLvPxovSimHNuv3ja5UfI5iEKzPmB/K1+dParfPDWA83tjFNQWL2j0lcWjyS5a oqjcUW0kjL9Q4OGayCNn9qwxk0zV//dgwUyghAVUz8gq4mWPOKbsLyg+CsxbareGX4yt BaJ29eSXT9n+vpqbkvdFrM5AgzvIme9tBnRyp9igV/FimlhEzM8OvO5o8eb1QerQog+o MbRN/kTdBDlW0PAvq8uZr4SlNBSVESKcrruY3iHw+/7UUeRhhf7GItKn4O7Xp9e9sQk9 bA4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=jU5CqsWf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r13-20020a65498d000000b0046ae2a9741dsi1195961pgs.50.2022.10.27.03.28.04; Thu, 27 Oct 2022 03:28:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=jU5CqsWf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234305AbiJ0KCb (ORCPT + 99 others); Thu, 27 Oct 2022 06:02:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235222AbiJ0KCD (ORCPT ); Thu, 27 Oct 2022 06:02:03 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 92EE825E7; Thu, 27 Oct 2022 03:01:37 -0700 (PDT) Received: from anrayabh-desk (unknown [167.220.238.193]) by linux.microsoft.com (Postfix) with ESMTPSA id A1954210D86A; Thu, 27 Oct 2022 03:01:32 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com A1954210D86A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1666864897; bh=6KQYehyzA42XebAaFlbNJVdMgguB/LDgiJKpKe/Ug68=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=jU5CqsWfQcPxchwyYcHysjgEZ992DP5WADuvIqSyTkmhswuGMfCbsBLARvfW3blvA I58XuiJsv8YXX1IScTpH67uM5edDbeEZz6r3Jvk1kZg1GbCHPSwOOeAoN7c5Zzfgu8 nMJOUzL0xrL3NKGgupeBcK8l4Roc/hz3zj6LrRD4= Date: Thu, 27 Oct 2022 15:31:24 +0530 From: Anirudh Rayabharam To: "Michael Kelley (LINUX)" Cc: KY Srinivasan , Haiyang Zhang , Stephen Hemminger , "wei.liu@kernel.org" , Dexuan Cui , "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 Bergmann , "linux-hyperv@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-arch@vger.kernel.org" , "kumarpraveen@linux.microsoft.com" , "mail@anirudhrb.com" Subject: Re: [PATCH 1/2] x86/hyperv: fix invalid writes to MSRs during root partition kexec Message-ID: References: <20221026134715.1438789-1-anrayabh@linux.microsoft.com> <20221026134715.1438789-2-anrayabh@linux.microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 26, 2022 at 02:58:16PM +0000, Michael Kelley (LINUX) wrote: > From: Anirudh Rayabharam Sent: Wednesday, October 26, 2022 6:47 AM > > > > hv_cleanup resets the hypercall page by setting the MSR to 0. However, > > the root partition is not allowed to write to the GPA bits of the MSR. > > Instead, it uses the hypercall page provided by the MSR. Similar is the > > case with the reference TSC MSR. > > > > Clear only the enable bit instead of zeroing the entire MSR to make > > the code valid for root partition too. > > When the enable bit is cleared (but not the PFN) in the MSR, do we know > for sure that Hyper-V removes the overlay page for the PFN? Making sure > that the overlay page is removed is the main reason for clearing the entire > MSR. If we're going to leave the PFN in place and just clear the enable bit, > we need to confirm with the Hyper-V guys that the overlay page will be > removed. I checked the hypervisor code. Just clearing the enable bit does cause the overlay page to be unmapped by the hypervisor. Thanks, Anirudh. > > Michael > > > > > Signed-off-by: Anirudh Rayabharam > > --- > > arch/x86/hyperv/hv_init.c | 9 ++++++--- > > 1 file changed, 6 insertions(+), 3 deletions(-) > > > > diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c > > index 29774126e931..76ff63d69461 100644 > > --- a/arch/x86/hyperv/hv_init.c > > +++ b/arch/x86/hyperv/hv_init.c > > @@ -537,6 +537,7 @@ void __init hyperv_init(void) > > void hyperv_cleanup(void) > > { > > union hv_x64_msr_hypercall_contents hypercall_msr; > > + u64 tsc_msr; > > > > unregister_syscore_ops(&hv_syscore_ops); > > > > @@ -552,12 +553,14 @@ void hyperv_cleanup(void) > > hv_hypercall_pg = NULL; > > > > /* Reset the hypercall page */ > > - hypercall_msr.as_uint64 = 0; > > + rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); > > + hypercall_msr.enable = 0; > > wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); > > > > /* Reset the TSC page */ > > - hypercall_msr.as_uint64 = 0; > > - wrmsrl(HV_X64_MSR_REFERENCE_TSC, hypercall_msr.as_uint64); > > + rdmsrl(HV_X64_MSR_REFERENCE_TSC, tsc_msr); > > + tsc_msr &= ~BIT_ULL(0); > > + wrmsrl(HV_X64_MSR_REFERENCE_TSC, tsc_msr); > > } > > > > void hyperv_report_panic(struct pt_regs *regs, long err, bool in_die) > > -- > > 2.34.1