From patchwork Wed Jan 29 20:20:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11356793 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 1FB4214E3 for ; Wed, 29 Jan 2020 20:22:25 +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 F09ED20702 for ; Wed, 29 Jan 2020 20:22:24 +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="cqrZ/HK5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F09ED20702 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 1iwtqF-00071c-Sn; Wed, 29 Jan 2020 20:21:39 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iwtqF-00070e-13 for xen-devel@lists.xenproject.org; Wed, 29 Jan 2020 20:21:39 +0000 X-Inumbo-ID: d73435f2-42d4-11ea-a933-bc764e2007e4 Received: from mail-wr1-x444.google.com (unknown [2a00:1450:4864:20::444]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d73435f2-42d4-11ea-a933-bc764e2007e4; Wed, 29 Jan 2020 20:20:50 +0000 (UTC) Received: by mail-wr1-x444.google.com with SMTP id z7so980299wrl.13 for ; Wed, 29 Jan 2020 12:20:50 -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=Rh3eILGi6Pt9jrhFdjXvi2DHTn3SFwkuAe2IR7Kx73I=; b=cqrZ/HK5s+9C95BpQsykUZBvq8Jcim3QbrSzcndE9FH3xdhaBPs4L6BJmoYJC3d7/Z Dbt4ztw6r5vPp4gvUbTqUBGIJoXQe46JUs5QtwE57SNpd0vjaPG3ezrmD6N+1KFqGkFE QiAjcCnseqzi4eWf4VXCaJPTfBXBnAtdox4S534yJOPCp7f/fKZcIzqgV3jbbw8Xap4L 6Cz7OFPifeLBMuDlG9q7jhMyLnD3pphXpONedrCx+/7vzXg0LAjJd2xIuwxF6eEVMEAc MjZto6Qrr6FCq7cFGPproX+qabF/vC8gpbal49qxWjSTIkGJWidrqFBq92dPNjQHzQg4 F45w== 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=Rh3eILGi6Pt9jrhFdjXvi2DHTn3SFwkuAe2IR7Kx73I=; b=EGhzElnZaiV2zHBpbPz+7YMISLfR/KNTr7N5nQtVt3+rPUhS4l3ntCy+h1kKdKYSfZ gh6Gpx0jkfV2inkQlZEpZ58LhikjYALsRfLhy4eHPGPe6Iaf9Pv6kSkRpbIvbyw7N7OT TN0QDnE6Ydkk8XtiGSaRrwIcc3DEi2gfZyJ7hYGpTaH/i7QqOrsP3mU32yKyraPXhjgv tuzF9ZeUUHi8fXmRCZ68+PyffoF3AR92hgO0rrSPX7unR/8SJRH2+SWDOTnc7/ibz7w7 hI6AXVsC1UVPJ+Fh5/eX2oYSHd63/wtprxztMD4rla3ibeiVLUUwiFpA84TJHPOzoDzZ WFCg== X-Gm-Message-State: APjAAAWe34p14xD+fTju20EaTM2IKN7jV+NyI38zQQE6dx1qW1AUOxfb vst+NkCbrTUNnFjDdywIBSMDpnUvnBk= X-Google-Smtp-Source: APXvYqwijMIDoAbcJTodCytjbe3qLDZnoi+0PHbIxiYk2xgC9j6ATtj966TGNyNQzCsXnfAc91IACg== X-Received: by 2002:a5d:6144:: with SMTP id y4mr552432wrt.367.1580329249422; Wed, 29 Jan 2020 12:20:49 -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.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2020 12:20:49 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Wed, 29 Jan 2020 20:20:34 +0000 Message-Id: <20200129202034.15052-13-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 12/12] 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 , 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" VP assist page is rather important as we need to toggle some bits in it for efficient nested virtualisation. Signed-off-by: Wei Liu --- v5: 1. Deal with error properly instead of always panicking 2. Swap percpu variables declarations' location v4: 1. Use private.h 2. Prevent leak v3: 1. Use xenheap page 2. Drop set_vp_assist v2: 1. Use HV_HYP_PAGE_SHIFT instead --- xen/arch/x86/guest/hyperv/hyperv.c | 44 ++++++++++++++++++++++++++++- xen/arch/x86/guest/hyperv/private.h | 1 + 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c index af0d6ed692..bc40a3d338 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -31,6 +31,7 @@ struct ms_hyperv_info __read_mostly ms_hyperv; DEFINE_PER_CPU_READ_MOSTLY(void *, hv_pcpu_input_page); +DEFINE_PER_CPU_READ_MOSTLY(void *, hv_vp_assist); DEFINE_PER_CPU_READ_MOSTLY(unsigned int, hv_vp_index); static uint64_t generate_guest_id(void) @@ -155,16 +156,57 @@ static int setup_hypercall_pcpu_arg(void) return 0; } +static int setup_vp_assist(void) +{ + void *mapping; + uint64_t val; + + mapping = this_cpu(hv_vp_assist); + + if ( !mapping ) + { + mapping = alloc_xenheap_page(); + if ( !mapping ) + { + printk("Failed to allocate vp_assist page for CPU%u\n", + smp_processor_id()); + return -ENOMEM; + } + + clear_page(mapping); + this_cpu(hv_vp_assist) = mapping; + } + + val = (virt_to_mfn(mapping) << HV_HYP_PAGE_SHIFT) + | HV_X64_MSR_VP_ASSIST_PAGE_ENABLE; + wrmsrl(HV_X64_MSR_VP_ASSIST_PAGE, val); + + return 0; +} + static void __init setup(void) { setup_hypercall_page(); + if ( setup_hypercall_pcpu_arg() ) panic("Hypercall percpu arg setup failed\n"); + + if ( setup_vp_assist() ) + panic("VP assist page setup failed\n"); } static int ap_setup(void) { - return setup_hypercall_pcpu_arg(); + int rc; + + rc = setup_hypercall_pcpu_arg(); + if ( rc ) + goto out; + + rc = setup_vp_assist(); + + out: + return rc; } static const struct hypervisor_ops ops = { diff --git a/xen/arch/x86/guest/hyperv/private.h b/xen/arch/x86/guest/hyperv/private.h index c1c2431eff..fcddc47544 100644 --- a/xen/arch/x86/guest/hyperv/private.h +++ b/xen/arch/x86/guest/hyperv/private.h @@ -25,6 +25,7 @@ #include DECLARE_PER_CPU(void *, hv_pcpu_input_page); +DECLARE_PER_CPU(void *, hv_vp_assist); DECLARE_PER_CPU(unsigned int, hv_vp_index); #endif /* __XEN_HYPERV_PRIVIATE_H__ */