From patchwork Fri Jan 3 16:08:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11316991 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 97370139A for ; Fri, 3 Jan 2020 16:10:36 +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 7428F222C3 for ; Fri, 3 Jan 2020 16:10:36 +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="gmCFLGnF" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7428F222C3 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 1inPVx-0005aG-2X; Fri, 03 Jan 2020 16:09:29 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1inPVv-0005ZG-Lo for xen-devel@lists.xenproject.org; Fri, 03 Jan 2020 16:09:27 +0000 X-Inumbo-ID: 5c099f48-2e43-11ea-88e7-bc764e2007e4 Received: from mail-wr1-x444.google.com (unknown [2a00:1450:4864:20::444]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 5c099f48-2e43-11ea-88e7-bc764e2007e4; Fri, 03 Jan 2020 16:09:03 +0000 (UTC) Received: by mail-wr1-x444.google.com with SMTP id y17so42927838wrh.5 for ; Fri, 03 Jan 2020 08:09:03 -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=CQAPrwZ6zHYdeecjna9SU+ovWbg6SlC0hmlnmabw3K0=; b=gmCFLGnFcf+29R1n5v0xIWDuW3zWHEzSWuTJErOBQYqfjFbu4+LY+8t0UDm6Scl4d+ Yb/BlmUMcNvH7G0tXDLB/0tpUmsIolrrwTd04qfX+uGSzVJxqe3obvWDdGq1UMOj2WLG l43pZD3fIx+5+t2UTf9T8BCKPftCDDaSyGCILETg+EQFtbpAWoVN0dPi5WWMakKXwVfx wvQZlImx2HGb0irF7dkRPvCFVoLBoZGifjOUZyyL1ObNhhaugvhOGTPc1Zy0jrk5y7dW jO9RUQ7Ntve/jPdROGyoPeKaGINVS1M0Yo0uk30SNsLyGB0mZLiQoOidu6KeUTRHG0S3 M5Eg== 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=CQAPrwZ6zHYdeecjna9SU+ovWbg6SlC0hmlnmabw3K0=; b=BmvHGAxUiOmOEjdhfA/scbq7l98V0yxSnZsAlh1Q63wgfix/wNlqt1lOT4WOThH2tV XgRQm0Nt7apEs3wAPx0hVbQ02MqRs+C/pYE2rKhHlJzQLxt13zN6/mKLjMSH2qpT4UuL ygMBvw/QwNpEAcYL6vS3mc4fIDjpnR6gvEihtB4Lh+edXVQiMgwceB1Q9QTcN+bWLHQW fCD1yXSLAx7l45LlaP5HXJvFuzV9kdCl10TEnh+tao55mGzuf7RDtqEg9lyeuxwqQJJg tCoORGFC+6ku5Inakce9GY+bjab9Y+3qiorAbg+n7ejgx1dzJN8ELAj+yCRWnyCkb/T+ KtYA== X-Gm-Message-State: APjAAAV367xutEqH07KFLI/6RgEX4p89dLLWNbZdxfC5c52Lbsbx0A2V lIxENzakYCV1mdbYMtYFwUU0gbdyZ/D3DQ== X-Google-Smtp-Source: APXvYqyWeqNbXCdXFT2fFknZH+3j9VXX2ry3FTDYp8zpb2KWhKVx4hj6hXbMX0G6+30mCzVZ/fLI/g== X-Received: by 2002:adf:fd07:: with SMTP id e7mr86811193wrr.21.1578067742550; Fri, 03 Jan 2020 08:09:02 -0800 (PST) Received: from localhost.localdomain (38.163.200.146.dyn.plus.net. [146.200.163.38]) by smtp.gmail.com with ESMTPSA id z11sm61000235wrt.82.2020.01.03.08.09.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jan 2020 08:09:02 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Fri, 3 Jan 2020 16:08:23 +0000 Message-Id: <20200103160825.19377-7-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200103160825.19377-1-liuwe@microsoft.com> References: <20200103160825.19377-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 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 381be2a68c..03027bd453 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -27,6 +27,7 @@ struct ms_hyperv_info __read_mostly ms_hyperv; extern char 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) @@ -83,14 +84,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