From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22F27C43461 for ; Mon, 14 Sep 2020 11:40:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BF06D21D80 for ; Mon, 14 Sep 2020 11:40:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600083644; bh=Lc/rkJYnmVCoBDSj8NBuEZBSz06mQTxcRXQScgUKGnM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=V6fXUJAcztQ8YVgqCI0E93Wmvf2uiuDFQNYdu3Yhpci8ajjaE8gzTjZETLNdZaCkC EER+fO4lGk6yFizP+r9c1W4jaKAv9Q4+chTSf2RS5gc3Q/w2HLg7e0ZVYapT4uxQmc wub0l9xq3pSpfqX8VVsBtwfI6Gm5ve5IRGUVlt0I= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725984AbgINLkm (ORCPT ); Mon, 14 Sep 2020 07:40:42 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:38387 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726094AbgINL2U (ORCPT ); Mon, 14 Sep 2020 07:28:20 -0400 Received: by mail-wm1-f67.google.com with SMTP id l9so10863762wme.3; Mon, 14 Sep 2020 04:28:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3d4JMvjpduBqCz6k+QE3NkfxQ9su5/24VCmbJg/2Vm4=; b=TXnFyoqEwYFTSUpA8DPAX8bstot46vmXpVt/XL3yRjgUstcqjhLPCm2DieF+VkZ/Q7 8rDnG8K++UMPDIsU7IyFqYgxyPurcsIEjcvAZKGfxPfgLMREHR5Wh838iGg49jXXMT2Z b+/0jdMNHcSa6m7fL46kcQItMyN5Qbki/nZ5skR6VMleRYofe7z8bO2s9IUqxLmE5FZt t8J7Z76o1tF/1SFoaILUgMHVx5BwaGKJHz8UbZq0Gy0oqnYJtPFeonBU0oUynCPx7vwZ O1vfOosLOcCJU16DBVuKY0okhHKR8ZTc43fVq7Y7LsgoQkhIVOarvKX9+d6tbd6ZH4rs vXew== X-Gm-Message-State: AOAM531EOk8QfztQSJu/mdi9Kx4+oYNUYLjvx03Ib5aFHo7yfG7L07bc hgiXeDBkQbED0dpTyqNYk/azA3YRgRo= X-Google-Smtp-Source: ABdhPJystUif1wRjcF7mRpnR+zmeWbWgyHyEK47dCztPMpjeOrLJ9raORZNTohyNmiK+Y3KwzAGL8A== X-Received: by 2002:a1c:a557:: with SMTP id o84mr14199501wme.96.1600082897536; Mon, 14 Sep 2020 04:28:17 -0700 (PDT) Received: from liuwe-devbox-debian-v2.j3c5onc20sse1dnehy4noqpfcg.zx.internal.cloudapp.net ([51.145.34.42]) by smtp.gmail.com with ESMTPSA id s12sm12024606wmd.20.2020.09.14.04.28.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Sep 2020 04:28:17 -0700 (PDT) From: Wei Liu To: Linux on Hyper-V List Cc: virtualization@lists.linux-foundation.org, Linux Kernel List , Michael Kelley , Vineeth Pillai , Sunil Muthuswamy , Nuno Das Neves , Wei Liu , Lillian Grassin-Drake , "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), "H. Peter Anvin" Subject: [PATCH RFC v1 08/18] x86/hyperv: handling hypercall page setup for root Date: Mon, 14 Sep 2020 11:27:52 +0000 Message-Id: <20200914112802.80611-9-wei.liu@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200914112802.80611-1-wei.liu@kernel.org> References: <20200914112802.80611-1-wei.liu@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When Linux is running as the root partition, the hypercall page will have already been setup by Hyper-V. Copy the content over to the allocated page. The suspend, resume and cleanup paths remain untouched because they are not supported in this setup yet. Signed-off-by: Lillian Grassin-Drake Signed-off-by: Sunil Muthuswamy Signed-off-by: Nuno Das Neves Co-Developed-by: Lillian Grassin-Drake Co-Developed-by: Sunil Muthuswamy Co-Developed-by: Nuno Das Neves Signed-off-by: Wei Liu --- arch/x86/hyperv/hv_init.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index 0eec1ed32023..26233aebc86c 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -25,6 +25,7 @@ #include #include #include +#include /* Is Linux running as the root partition? */ bool hv_root_partition; @@ -448,8 +449,29 @@ void __init hyperv_init(void) rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); hypercall_msr.enable = 1; - hypercall_msr.guest_physical_address = vmalloc_to_pfn(hv_hypercall_pg); - wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); + + if (hv_root_partition) { + struct page *pg; + void *src, *dst; + + /* + * Order is important here. We must enable the hypercall page + * so it is populated with code, then copy the code to an + * executable page. + */ + wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); + + pg = vmalloc_to_page(hv_hypercall_pg); + dst = kmap(pg); + src = memremap(hypercall_msr.guest_physical_address << PAGE_SHIFT, PAGE_SIZE, + MEMREMAP_WB); + memcpy(dst, src, PAGE_SIZE); + memunmap(src); + kunmap(pg); + } else { + hypercall_msr.guest_physical_address = vmalloc_to_pfn(hv_hypercall_pg); + wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); + } /* * Ignore any errors in setting up stimer clockevents -- 2.20.1