From patchwork Sun Dec 29 18:33:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11312369 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 1F185921 for ; Sun, 29 Dec 2019 18:35:22 +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 F022620748 for ; Sun, 29 Dec 2019 18:35:21 +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="ad4ZNFkX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F022620748 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 1ildOV-00005p-Od; Sun, 29 Dec 2019 18:34:27 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ildOU-0008W9-4X for xen-devel@lists.xenproject.org; Sun, 29 Dec 2019 18:34:26 +0000 X-Inumbo-ID: c7d4fbc4-2a69-11ea-a1e1-bc764e2007e4 Received: from mail-wr1-x442.google.com (unknown [2a00:1450:4864:20::442]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id c7d4fbc4-2a69-11ea-a1e1-bc764e2007e4; Sun, 29 Dec 2019 18:34:00 +0000 (UTC) Received: by mail-wr1-x442.google.com with SMTP id d16so30908595wre.10 for ; Sun, 29 Dec 2019 10:34:00 -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=StyhxDStPdtUMfRwKkbsK2BEaAdOM3U2G5Vjbak1HKc=; b=ad4ZNFkXeZ49oe7phaJulphqWcCrj4QvF3WlthAxXUijKDxuqAv8jxfkgl10R+5ZwR f/OEDDRYgkOXk/+3m7qZRC8BjTXF7mCl8pDBiN/W9SR7Ub9XL3K3o1DeovbzTJaISWIP m1mnmN41TqaDhGmJex9zf1rUQZ73T9Ir66b28uvUJv7WxUCPqw60EzRYc2iwZum2A7FN /4J+kwICeFXRn4m32HApaKIYRQY/lm9usJ6BPhZwoAbHfmyKIt5NcFFDqi3e3SNtGRU/ Id2vGL30pSA6rWrMq9vx/ceYT6dQWXLV3XoEMLHR1f6KfXSEYPDgGKHmXrkO3w8ZnSkF 09fw== 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=StyhxDStPdtUMfRwKkbsK2BEaAdOM3U2G5Vjbak1HKc=; b=T0fbyzB7XClleShFxkAE97gLJ50slSJ5Qsx7L3MaryYGxbwBxY2l/sO8spX5SSgNo6 xNkc8/RcpVDgx6ia5QgM96Oqq8Jvv4+3JVfIWMUt6mdgY1B95PQjOi7X8Opd4Coq0PTY 9+3dyw4qiD73oHP1EBGrPmuSrR5OTEhXFq4ak+0OXRvJKFSj9AciLUIYCReU5mLALCEN BT0kAtO1EOhr+SUaHky0ggephLB1IfXgZIDppFk4CX5ov4Dxja/sJJUib1hbAQ0K2d5C Fvq3HKKIAS7gLi2aFOLhZieXor3SHfRnLmw7CADePL12lS3GvN50HtZNx47vlp3jVNbT jfkQ== X-Gm-Message-State: APjAAAW1b0MXoV7Ma9MC8qXT9uBQoSlLVpyzYZyGiuNjPkLnH78rGvTY nmtU3FEs24nfm+IfV66k2zz+X/rC5sA= X-Google-Smtp-Source: APXvYqybCE4wFqLyTxmwqM75QIH48UygDKWCpeGYtU6iBh75gnOTS7eiDr1jRKDjZNqlxesQ+3JBZA== X-Received: by 2002:adf:ee45:: with SMTP id w5mr60470220wro.352.1577644439429; Sun, 29 Dec 2019 10:33:59 -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.33.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Dec 2019 10:33:59 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Sun, 29 Dec 2019 18:33:39 +0000 Message-Id: <20191229183341.14877-7-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 6/8] x86/hyperv: provide percpu hypercall input 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" Hyper-V's input / output argument must be 8 bytes aligned an not cross page boundary. The easiest way to satisfy those requirements is to use percpu page. For the foreseeable future we only need to provide input for TLB and APIC hypercalls, so skip setting up an output page. The page tracking structure is not bound to hypercall because it is a common pattern for Xen to write guest physical address to Hyper-V while at the same time accessing the page via a pointer. We will also need to provide an ap_setup hook for secondary cpus to setup its own input page. Signed-off-by: Wei Liu Reviewed-by: Paul Durrant --- xen/arch/x86/guest/hyperv/hyperv.c | 26 ++++++++++++++++++++++++++ xen/include/asm-x86/guest/hyperv.h | 8 ++++++++ 2 files changed, 34 insertions(+) diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c index 438910c8cb..67667936e9 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -28,6 +28,7 @@ struct ms_hyperv_info __read_mostly ms_hyperv; void *hv_hypercall; static struct page_info *hv_hypercall_page; +DEFINE_PER_CPU_READ_MOSTLY(struct hyperv_pcpu_page, hv_pcpu_input_arg); static const struct hypervisor_ops ops; const struct hypervisor_ops *__init hyperv_probe(void) @@ -96,14 +97,39 @@ static void __init setup_hypercall_page(void) wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); } +static void setup_hypercall_pcpu_arg(void) +{ + struct page_info *pg; + void *mapping; + unsigned int cpu = smp_processor_id(); + + pg = alloc_domheap_page(NULL, 0); + if ( !pg ) + panic("Failed to setup hypercall input page for %u\n", cpu); + + mapping = __map_domain_page_global(pg); + if ( !mapping ) + panic("Failed to map hypercall input page for %u\n", cpu); + + this_cpu(hv_pcpu_input_arg).maddr = page_to_maddr(pg); + this_cpu(hv_pcpu_input_arg).mapping = mapping; +} + static void __init setup(void) { setup_hypercall_page(); + setup_hypercall_pcpu_arg(); +} + +static void ap_setup(void) +{ + setup_hypercall_pcpu_arg(); } static const struct hypervisor_ops ops = { .name = "Hyper-V", .setup = setup, + .ap_setup = ap_setup, }; /* diff --git a/xen/include/asm-x86/guest/hyperv.h b/xen/include/asm-x86/guest/hyperv.h index c7a7f32bd5..83f297468f 100644 --- a/xen/include/asm-x86/guest/hyperv.h +++ b/xen/include/asm-x86/guest/hyperv.h @@ -51,6 +51,8 @@ static inline uint64_t hv_scale_tsc(uint64_t tsc, uint64_t scale, #ifdef CONFIG_HYPERV_GUEST +#include + #include struct ms_hyperv_info { @@ -63,6 +65,12 @@ struct ms_hyperv_info { }; extern struct ms_hyperv_info ms_hyperv; +struct hyperv_pcpu_page { + paddr_t maddr; + void *mapping; +}; +DECLARE_PER_CPU(struct hyperv_pcpu_page, hv_pcpu_input_arg); + const struct hypervisor_ops *hyperv_probe(void); #else