From patchwork Sun Dec 29 18:33:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11312373 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 795EE138C for ; Sun, 29 Dec 2019 18:35:32 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 562D520748 for ; Sun, 29 Dec 2019 18:35:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Sd5UeMLW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 562D520748 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ildOf-0000DK-EG; Sun, 29 Dec 2019 18:34:37 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ildOe-0000CJ-5K for xen-devel@lists.xenproject.org; Sun, 29 Dec 2019 18:34:36 +0000 X-Inumbo-ID: c8ce5a2a-2a69-11ea-88e7-bc764e2007e4 Received: from mail-wm1-x341.google.com (unknown [2a00:1450:4864:20::341]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id c8ce5a2a-2a69-11ea-88e7-bc764e2007e4; Sun, 29 Dec 2019 18:34:02 +0000 (UTC) Received: by mail-wm1-x341.google.com with SMTP id b19so12372785wmj.4 for ; Sun, 29 Dec 2019 10:34:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3d0oAYCyKACs7Jy203uplvN0cNjl3u8rMIY3VL6ToB4=; b=Sd5UeMLWT/ULhIt8rsmXOfpj1l/hPLNOYGjd7XhnZ65OnTkhbxpsScWPgkWybcN6CK tU/eTPQkjAnLHePBhkZqSLBN0TDaqmC7e+mjgbWNHyJ/2SbRnwq0TZoDtXSsXonz9IEt vX6u06amFCuiYqHY2waJ0+7Q9xFruNt2z1GSR5gH1f6EEoDeTIWCyHIa/DLY6b5N51Y9 Qa81e4c+m14uHpU0+cqMYmhC9y4GYbgtirmSFr8VOdMROw4SWcZamUctlPP8Bqnrtkb5 3+e9x3B3murU62Ht3bObs12QElYJOyE7Ts8ZllFSDyUDzLjwPJ6V2HL/KVfzH2IlkoxJ oHfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=3d0oAYCyKACs7Jy203uplvN0cNjl3u8rMIY3VL6ToB4=; b=axaCYO08On3duYJAC4916xkOEuTTxeyyUzurSzk/6/JBbM0uaZ+pHU3Vl6WNP/7uHn wnBrT9RDQTZsKjcS+BklyXPYbuXc1pQ93XeMoOZdON5QWNDyzWfcRaSR65AQmNyyqtpx AGDYe1vYf5WXH19EzCH5ptD/DGWNCE0Vm2QG7jqsXf702Av43nLWO3ihN9eUPzlaSFaG j4s6jBRvNPYbEfCcQrLPsPG5OpvaFchmQrBQs37MYw513nWaxaKde5A6WFoNG8sTQubt ygDa8s0KtyCS5q1BTuFg+JEtf7isqrALF+u2yGWOv6klCL4eQ2HhvV/9iwNVaU4VjwFM lWfw== X-Gm-Message-State: APjAAAVoR59zAhou2/F4N5MOS/d/Ul4mFoTKCXPm2dZvcytULgk/8cTI eh8MW+Wh+XwsxCtvhqaR4xLJsVwC/Gw= X-Google-Smtp-Source: APXvYqyrf/tgheg5khGn4qrLjdxD4PqIp9ePYibVwAtbgqUC8fVlrdP0wLyJAoQCOpH/YXW+MITFfw== X-Received: by 2002:a7b:cfc2:: with SMTP id f2mr28916093wmm.44.1577644441234; Sun, 29 Dec 2019 10:34:01 -0800 (PST) Received: from localhost.localdomain (38.163.200.146.dyn.plus.net. [146.200.163.38]) by smtp.gmail.com with ESMTPSA id f207sm19667903wme.9.2019.12.29.10.34.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Dec 2019 10:34:00 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Sun, 29 Dec 2019 18:33:41 +0000 Message-Id: <20191229183341.14877-9-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191229183341.14877-1-liuwe@microsoft.com> References: <20191229183341.14877-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 8/8] x86/hyperv: setup VP assist page X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Wei Liu , Paul Durrant , Andrew Cooper , Michael Kelley , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" VP assist page is rather important as we need to toggle some bits in that page such that L1 guest can make hypercalls directly to L0 Hyper-V. Preemptively split out set_vp_assist page which will be used in the resume path. Signed-off-by: Wei Liu --- xen/arch/x86/guest/hyperv/hyperv.c | 35 ++++++++++++++++++++++++++++++ xen/include/asm-x86/guest/hyperv.h | 1 + 2 files changed, 36 insertions(+) diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c index da3a8cd85d..a88b9ae6d9 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -30,6 +30,7 @@ void *hv_hypercall; static struct page_info *hv_hypercall_page; DEFINE_PER_CPU_READ_MOSTLY(struct hyperv_pcpu_page, hv_pcpu_input_arg); DEFINE_PER_CPU_READ_MOSTLY(unsigned int, hv_vp_index); +DEFINE_PER_CPU_READ_MOSTLY(struct hyperv_pcpu_page, hv_vp_assist); static const struct hypervisor_ops ops; const struct hypervisor_ops *__init hyperv_probe(void) @@ -125,17 +126,51 @@ static void setup_vp_index(void) this_cpu(hv_vp_index) = vp_index_msr; } +static void set_vp_assist(void) +{ + uint64_t val = paddr_to_pfn(this_cpu(hv_vp_assist).maddr); + + val = (val << HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_SHIFT) | + HV_X64_MSR_VP_ASSIST_PAGE_ENABLE; + + wrmsrl(HV_X64_MSR_VP_ASSIST_PAGE, val); +} + +static void setup_vp_assist(void) +{ + struct page_info *pg; + void *mapping; + unsigned int cpu = smp_processor_id(); + + pg = alloc_domheap_page(NULL, 0); + if ( !pg ) + panic("Failed to allocate vp_assist page for %u\n", cpu); + + mapping = __map_domain_page_global(pg); + if ( !mapping ) + panic("Failed to map vp_assist page for %u\n", cpu); + + clear_page(mapping); + + this_cpu(hv_vp_assist).maddr = page_to_maddr(pg); + this_cpu(hv_vp_assist).mapping = mapping; + + set_vp_assist(); +} + static void __init setup(void) { setup_hypercall_page(); setup_hypercall_pcpu_arg(); setup_vp_index(); + setup_vp_assist(); } static void ap_setup(void) { setup_hypercall_pcpu_arg(); setup_vp_index(); + setup_vp_assist(); } static const struct hypervisor_ops ops = { diff --git a/xen/include/asm-x86/guest/hyperv.h b/xen/include/asm-x86/guest/hyperv.h index 4b635829f3..917f4e02c2 100644 --- a/xen/include/asm-x86/guest/hyperv.h +++ b/xen/include/asm-x86/guest/hyperv.h @@ -71,6 +71,7 @@ struct hyperv_pcpu_page { }; DECLARE_PER_CPU(struct hyperv_pcpu_page, hv_pcpu_input_arg); DECLARE_PER_CPU(unsigned int, hv_vp_index); +DECLARE_PER_CPU(struct hyperv_pcpu_page, hv_vp_assist); const struct hypervisor_ops *hyperv_probe(void);