From patchwork Wed Jan 22 20:23:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11346359 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 083601580 for ; Wed, 22 Jan 2020 20:25:12 +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 D505A24655 for ; Wed, 22 Jan 2020 20:25:11 +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="gtWqCrbH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D505A24655 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 1iuMY4-0006RO-I7; Wed, 22 Jan 2020 20:24:24 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iuMY3-0006Ql-1G for xen-devel@lists.xenproject.org; Wed, 22 Jan 2020 20:24:23 +0000 X-Inumbo-ID: 1bd0d312-3d55-11ea-8e9a-bc764e2007e4 Received: from mail-wr1-x442.google.com (unknown [2a00:1450:4864:20::442]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 1bd0d312-3d55-11ea-8e9a-bc764e2007e4; Wed, 22 Jan 2020 20:23:54 +0000 (UTC) Received: by mail-wr1-x442.google.com with SMTP id w15so517542wru.4 for ; Wed, 22 Jan 2020 12:23:54 -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=ljuvtGQ8FLfUz4xqMnHKyZjGxy69y+jnVAsAFm6RVds=; b=gtWqCrbHnArBT6pIE/e3Y59E1lIcOgMjtNLGL1C7YC42YtP68AF5M4BX6OCuElrzDZ Hrf/QYX18PFyL/bWd8GgoXfky6CXRkPqGZbmXgJ8kx7K5FH0i3aXpi3BYSAwW6+QdqDB eRQhsk/PYzUzkbEEV/TLKOHi10fDaCrESQDdJncT5TgyMIX4Ke2ZcV9gIZ5oLb5FUfYv yBtK0iMqxC10cyTQu8CsBulBx4JtLodzGHUJE20mN6iWDAUYzb7U9mk+LAZJqLZWXdWU Ba71w9stZVz5OJ5HtYKNqF16AoJIWLkgADxtW92ZoDBA70lFwfNkX6RIVv0PLJswqF1H OHIQ== 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=ljuvtGQ8FLfUz4xqMnHKyZjGxy69y+jnVAsAFm6RVds=; b=EcaGVcGtkZWB8BA2wyKtOIQ7ancTGx8X+nSTNiE32ASY17EUFYG4esB0gWjIPL31ax CwbjlYM6WibuQGpPf/hQ0GW1gSDZe5DxetjnIWtdGR3OyHhHd9qT/YeJqB87GZpugmUW NVkmgZTPJT9c2S+161ilGZLvx7s/E+weXGZZrVQgi3nGUdCF+vjjIDtBB9oO1dTS+TOd 6o8ZUItXmK9MqQ6KjW/pjd/9kYinX36fH8Ykkrpw7h1olc8QcgShc0qIwyGwYZHMezdM QA3x8FrjsSKgZb22BAtu7ziEuUX3R2hDffyr4QhCV8LZHtA5BRZvpiFkDPQy/OBF5G96 tdHQ== X-Gm-Message-State: APjAAAX3xPia5PziEnOksEpIvn3Fa+/0TFaSwfKUE7gg3M/yWr2qqvzX cFFMVRCAQTaL0kI4YLs54futBWWn7MPifQ== X-Google-Smtp-Source: APXvYqxPFih+zc1HHE4XDSBA6Wgr59+EAa8ucv5Qi9jgZF14d9ZZt7xwP2/sOF8TCZ+dbKmIGZUe2w== X-Received: by 2002:adf:ea05:: with SMTP id q5mr12536429wrm.48.1579724633088; Wed, 22 Jan 2020 12:23:53 -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.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jan 2020 12:23:52 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Wed, 22 Jan 2020 20:23:43 +0000 Message-Id: <20200122202343.5703-8-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 7/7] 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 , 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" VP assist page is rather important as we need to toggle some bits in it for efficient nested virtualisation. Signed-off-by: Wei Liu --- 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 | 26 ++++++++++++++++++++++++++ xen/arch/x86/guest/hyperv/private.h | 1 + 2 files changed, 27 insertions(+) diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c index 085e646dc6..89a8f316b2 100644 --- a/xen/arch/x86/guest/hyperv/hyperv.c +++ b/xen/arch/x86/guest/hyperv/hyperv.c @@ -32,6 +32,7 @@ struct ms_hyperv_info __read_mostly ms_hyperv; DEFINE_PER_CPU_READ_MOSTLY(void *, hv_pcpu_input_arg); DEFINE_PER_CPU_READ_MOSTLY(unsigned int, hv_vp_index); +DEFINE_PER_CPU_READ_MOSTLY(void *, hv_vp_assist); static uint64_t generate_guest_id(void) { @@ -142,15 +143,40 @@ static void setup_hypercall_pcpu_arg(void) this_cpu(hv_vp_index) = vp_index_msr; } +static void setup_vp_assist(void) +{ + void *mapping; + uint64_t val; + + mapping = this_cpu(hv_vp_assist); + + if ( !mapping ) + { + mapping = alloc_xenheap_page(); + if ( !mapping ) + panic("Failed to allocate vp_assist page for CPU%u\n", + smp_processor_id()); + + 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); +} + static void __init setup(void) { setup_hypercall_page(); setup_hypercall_pcpu_arg(); + setup_vp_assist(); } static void ap_setup(void) { setup_hypercall_pcpu_arg(); + setup_vp_assist(); } 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 da70990401..af419e9d4b 100644 --- a/xen/arch/x86/guest/hyperv/private.h +++ b/xen/arch/x86/guest/hyperv/private.h @@ -26,5 +26,6 @@ DECLARE_PER_CPU(void *, hv_pcpu_input_arg); DECLARE_PER_CPU(unsigned int, hv_vp_index); +DECLARE_PER_CPU(void *, hv_vp_assist); #endif /* __XEN_HYPERV_PRIVIATE_H__ */