Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2091550pxk; Mon, 14 Sep 2020 04:40:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxYRb4ogOR/vN+06L/7TrnWcoI6kNoGhsXwHcGUfQ6t6ehPx9CwtX68liYAVzx6UGQxpwgh X-Received: by 2002:a50:e68a:: with SMTP id z10mr17354129edm.100.1600083655257; Mon, 14 Sep 2020 04:40:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600083655; cv=none; d=google.com; s=arc-20160816; b=O6/VOOPzII4lJbPixkU+QAnD0hG6dMzu+y2wbuJEU2GQcnOo7TqCzuL32uj6F6hkKU iHIKSA4k3VNabOLqWfkYStjw5gfr9tjI2h6wC8mnlXkQRPGbInoEmVuHFwvyGYSV+hV6 pOs/bMKHbHbfWxIqmq/aMkHZ1vbcIJ5PRTtYAIAc3M++CEJ4O7xrTBVi5v50C5Tb2Q61 4BBKbboi8Z+E8zlKkCkPVtHva0AIUeiVNZEJgTnBZCBg6/lf8ZZhfWYkXu9pyT48M+wL XoESnYs9p37LE6lfYTxCcbUSVLSWSucA0pbm1e8kT2zZUeu3xXWfzHHSVl1HODGclRS4 +CUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=3d4JMvjpduBqCz6k+QE3NkfxQ9su5/24VCmbJg/2Vm4=; b=0sRLZ+416Bo/Ia1HMOY2E4GC5mXocJWx6b+Kw2z+NxeRBJpYGF42pDqGRW7AM9oUvU JzQxbQo9LJy3J18/q16KkBZxhOJbxbCWt761b+BkEU/hudtZqykXTS81mIEt54wNJMDb ei7oxQK4wiTh1fZcA272S+1fPT4XQloSMto+UCe4WEkVAHTchvYyNuyr3x3Oqje7rhLz 63bimm/KAac0651Im7+vYQNJw4ml7jzOSJNmI/KHsFrg44XXTxaPK11I2baQlMfelc6a RBvOdTLLuFIs7roSyCFKwoCrbNfbDn/Uel13gAQTHW08I+/dIsXB/vFcXJP1XpGC3FUz Cc3g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n13si6679273ejd.442.2020.09.14.04.40.33; Mon, 14 Sep 2020 04:40:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726120AbgINLjd (ORCPT + 99 others); Mon, 14 Sep 2020 07:39:33 -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-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