From patchwork Wed Jan 22 20:23:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11346357 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 5296792A for ; Wed, 22 Jan 2020 20:25:07 +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 2ED4824655 for ; Wed, 22 Jan 2020 20:25:07 +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="t7h5F9pi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2ED4824655 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 1iuMXu-0006LW-JN; Wed, 22 Jan 2020 20:24:14 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iuMXt-0006Kr-0j for xen-devel@lists.xenproject.org; Wed, 22 Jan 2020 20:24:13 +0000 X-Inumbo-ID: 1ab8b9d6-3d55-11ea-aecd-bc764e2007e4 Received: from mail-wr1-x444.google.com (unknown [2a00:1450:4864:20::444]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 1ab8b9d6-3d55-11ea-aecd-bc764e2007e4; Wed, 22 Jan 2020 20:23:52 +0000 (UTC) Received: by mail-wr1-x444.google.com with SMTP id d16so475116wre.10 for ; Wed, 22 Jan 2020 12:23:52 -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=YBVOWoTwbZt9RyjSkTi/ui/Jx6IMZiyjvsALlSN6nSE=; b=t7h5F9pi2aI+55TSpCLtn2rYRhsgcOeZSKkqceGIwlLZ12DZuXOEWQYuKn0r1Gk1Vi H1iFskjWdIccISsgsS8621EpA3z70oHSPlyy4ZDpHemT/Q9K4I5jknw/V/6cTgpPrFG9 QqxTRW0+ADCG584d/dgjdwI5mRDrGNpR+kDJ+5GT1AtwO4m7HeECHhNQBptN/69t7WnV 3AiQ3suzxDBoAbl3/hGuM2WDsgfpqic8/aLlNejYkTnULhx0F1z3sYftParDWlYffcM7 cNaoAGQ2/tJsmuV1ZreGVDPcabUwzvt+9U8Uy7jBXAKMzOIP8uL4B21JgAC4qqNpkTRN xhKQ== 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=YBVOWoTwbZt9RyjSkTi/ui/Jx6IMZiyjvsALlSN6nSE=; b=AO0V2UkNUcV2K/UZHisY+LdRoSoPfCACvZ+FIYd8rAD+lA1ZmnM8GafFQS1om9hSkR 0lxCTuk48lMSGYIuidvX73aHVrx/u8N4V5PF20/Ym3pdKsXV4wFOmRSzDG2LMKI/K0yn osRWMaPxIod+RYp9sxql+qo+jj+UbyzX9iLzC80pFI20ZSyOhqGNnyW7pSJpmqW1OyN9 h7lAzWDoRU9U1KYXax0wfGQBcIlZsRrcEUV8cYH8U3ICbERBbiO0PweEVGxzJMb+5d7t Eowaz1e1VPFoAMZJDvHDdgEARZzAUlMUeEq0jMlVlN8aOob7giOuH1wzNLCrO9YaBq1h I1CQ== X-Gm-Message-State: APjAAAUXakRtSQothBTOC++pTC+U5kMpYK76ZfYDv94ITRs/rqzaYlWk Iouo5hS4VJGJvJukBGqP3vOsy4cb/PLu+g== X-Google-Smtp-Source: APXvYqyAuuFKdrMyEvBBl88vXcykiPuUdzNUrlZbFli+SHlAWWXlKZQlqT+j+Zb4nGDz4nikvOW4pg== X-Received: by 2002:a05:6000:160d:: with SMTP id u13mr12590691wrb.22.1579724631245; Wed, 22 Jan 2020 12:23:51 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id r6sm60267992wrq.92.2020.01.22.12.23.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jan 2020 12:23:50 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Wed, 22 Jan 2020 20:23:41 +0000 Message-Id: <20200122202343.5703-6-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200122202343.5703-1-liuwe@microsoft.com> References: <20200122202343.5703-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v4 5/7] 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 , =?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. One 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. We will also need to provide an ap_setup hook for secondary cpus to setup its own input page. Signed-off-by: Wei Liu --- v4: 1. Change wording in commit message 2. Prevent leak 3. Introduce a private header v3: 1. Use xenheap page instead 2. Drop page tracking structure 3. Drop Paul's review tag --- xen/arch/x86/guest/hyperv/hyperv.c | 25 +++++++++++++++++++++++++ xen/arch/x86/guest/hyperv/private.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 xen/arch/x86/guest/hyperv/private.h diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c index 536ce0d0dd..c5195af948 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -27,7 +27,10 @@ #include #include +#include "private.h" + struct ms_hyperv_info __read_mostly ms_hyperv; +DEFINE_PER_CPU_READ_MOSTLY(void *, hv_pcpu_input_arg); static uint64_t generate_guest_id(void) { @@ -119,14 +122,36 @@ static void __init setup_hypercall_page(void) } } +static void setup_hypercall_pcpu_arg(void) +{ + void *mapping; + + if ( this_cpu(hv_pcpu_input_arg) ) + return; + + mapping = alloc_xenheap_page(); + if ( !mapping ) + panic("Failed to allocate hypercall input page for CPU%u\n", + smp_processor_id()); + + this_cpu(hv_pcpu_input_arg) = 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/arch/x86/guest/hyperv/private.h b/xen/arch/x86/guest/hyperv/private.h new file mode 100644 index 0000000000..b6902b5639 --- /dev/null +++ b/xen/arch/x86/guest/hyperv/private.h @@ -0,0 +1,29 @@ +/****************************************************************************** + * arch/x86/guest/hyperv/private.h + * + * Definitions / declarations only useful to Hyper-V code. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; If not, see . + * + * Copyright (c) 2020 Microsoft. + */ + +#ifndef __XEN_HYPERV_PRIVIATE_H__ +#define __XEN_HYPERV_PRIVIATE_H__ + +#include + +DECLARE_PER_CPU(void *, hv_pcpu_input_arg); + +#endif /* __XEN_HYPERV_PRIVIATE_H__ */