From patchwork Wed Jan 29 20:20:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11356791 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 626AB92A for ; Wed, 29 Jan 2020 20:22:19 +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 3F1CA20702 for ; Wed, 29 Jan 2020 20:22:19 +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="tVwiF6rL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3F1CA20702 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 1iwtq7-0006tl-3v; Wed, 29 Jan 2020 20:21:31 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iwtq5-0006sR-0K for xen-devel@lists.xenproject.org; Wed, 29 Jan 2020 20:21:29 +0000 X-Inumbo-ID: d61964f8-42d4-11ea-b211-bc764e2007e4 Received: from mail-wr1-x441.google.com (unknown [2a00:1450:4864:20::441]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d61964f8-42d4-11ea-b211-bc764e2007e4; Wed, 29 Jan 2020 20:20:48 +0000 (UTC) Received: by mail-wr1-x441.google.com with SMTP id y11so1043480wrt.6 for ; Wed, 29 Jan 2020 12:20:48 -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=RzyOqBOVVAhQpV3lENjn6NyUC6dkaBmuVSXJthxFeDo=; b=tVwiF6rLrO3eOWMXW337suntCd+02cBaulZA8iz82SvDHIxXPKlDhU1WZ693ML3BP3 NjXO1XHGo6EysyZ7CLntBoluIMWcFu3zjM8M3rfs5ybgF8J1eMQ9mgUMMfZta2eSy30X +qXiwES7EhGudr8CxQWMrCMb7bdrKhaC7tl+0o3Pm+x6lrU+3hwQvvWRleEjuj9PBtg0 ANx80USJP9IpNK3dInzDkZaWTMSNftycTRToW6J97TlmbeQukfKVyk41jlzaW/ZUNpqE Hen0LoURoeFWY+CeDOT5I/EM7s12rNrHhOAJFyYIFpn+NdWo89VmD0XA220eQT3RRGkY 1wJA== 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=RzyOqBOVVAhQpV3lENjn6NyUC6dkaBmuVSXJthxFeDo=; b=tWSjO5VNplATU1mAzBkZe6v3dGVn2pOz0DLncmhwDzKPYrEEPp6zteKalqLmtbPo/3 h94PB0uO5rKmmN+A+gcL8xFfte29w60YMJw7k9BSGsmE4ZnbfLUOmQdtsBc2GxKn7Ckh txJZiSPGVxAkJWqmy7azYxHU/1rC10RWNdKDQ12U/0CElJEhjMbNKVkJ9vV4X/dJPafw +wRtUzBa3vvlUE+aX8F5tAAxZOF3KV2aZxu/y06DnD8Drt7Te1z+pxlBP9GqYA7ePOob 9r2KLcCJbCNTclHE3hqLblxNCoK1yyin4nRuwNHgJAylqCvEWP6MoSjsPZL+y/WQ4enF f72g== X-Gm-Message-State: APjAAAXRBbVKPNt1WWNSBcEcMgGUVpSuCHo3S4iX+OWIT4h9s8v8XEeD ih+SVTRKcwR6zeb5s36Thl4Mi0WkMjs= X-Google-Smtp-Source: APXvYqzwjLjlOp06e+zlACqgmsdgD2iIe6NpsKXB8oa29a81W/0W/Qetj2PJHKKKNz4LwsuofXKrcA== X-Received: by 2002:adf:e74a:: with SMTP id c10mr624231wrn.386.1580329247544; Wed, 29 Jan 2020 12:20:47 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id a22sm3564115wmd.20.2020.01.29.12.20.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2020 12:20:47 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Wed, 29 Jan 2020 20:20:32 +0000 Message-Id: <20200129202034.15052-11-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200129202034.15052-1-liuwe@microsoft.com> References: <20200129202034.15052-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v5 10/12] 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 , Andrew Cooper , Paul Durrant , 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 Reviewed-by: Paul Durrant Reviewed-by: Roger Pau Monné --- v5: 1. Adjust to new ap_setup 2. Change variable name to hv_pcpu_input_page 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 | 31 +++++++++++++++++++++++++++++ xen/arch/x86/guest/hyperv/private.h | 29 +++++++++++++++++++++++++++ 2 files changed, 60 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 4387b6541e..f0facccbad 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_page); static uint64_t generate_guest_id(void) { @@ -127,14 +130,42 @@ static void __init setup_hypercall_page(void) } } +static int setup_hypercall_pcpu_arg(void) +{ + void *mapping; + + if ( this_cpu(hv_pcpu_input_page) ) + return 0; + + mapping = alloc_xenheap_page(); + if ( !mapping ) + { + printk("Failed to allocate hypercall input page for CPU%u\n", + smp_processor_id()); + return -ENOMEM; + } + + this_cpu(hv_pcpu_input_page) = mapping; + + return 0; +} + static void __init setup(void) { setup_hypercall_page(); + if ( setup_hypercall_pcpu_arg() ) + panic("Hypercall percpu arg setup failed\n"); +} + +static int ap_setup(void) +{ + return setup_hypercall_pcpu_arg(); } static const struct hypervisor_ops ops = { .name = "Hyper-V", .setup = setup, + .ap_setup = ap_setup, }; static void __maybe_unused build_assertions(void) diff --git a/xen/arch/x86/guest/hyperv/private.h b/xen/arch/x86/guest/hyperv/private.h new file mode 100644 index 0000000000..a339274985 --- /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_page); + +#endif /* __XEN_HYPERV_PRIVIATE_H__ */