From patchwork Tue Feb 4 15:37:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 11364891 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 0506A138D for ; Tue, 4 Feb 2020 15:38:55 +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 D5E4D2082E for ; Tue, 4 Feb 2020 15:38:54 +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="W9n4dXVH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D5E4D2082E 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 1iz0H4-0001mN-BB; Tue, 04 Feb 2020 15:38:02 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iz0H2-0001l1-B3 for xen-devel@lists.xenproject.org; Tue, 04 Feb 2020 15:38:00 +0000 X-Inumbo-ID: 3b6f9898-4764-11ea-b211-bc764e2007e4 Received: from mail-wr1-x444.google.com (unknown [2a00:1450:4864:20::444]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 3b6f9898-4764-11ea-b211-bc764e2007e4; Tue, 04 Feb 2020 15:37:21 +0000 (UTC) Received: by mail-wr1-x444.google.com with SMTP id y17so23643826wrh.5 for ; Tue, 04 Feb 2020 07:37:21 -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=ixwCG7/dZigNeiQzjDCIJqTFxi0+dHXprIOccPvDWlE=; b=W9n4dXVH3YhHhSFNQL7ay9oK4yb/l8DW3qCFgZWh8/LZ4SI1Em49MYLmkAXflaXf6p eLlYcGKHMElmRemTL2RGXusI7flXFfrp5VnE4xnoBdIpVybjR3WqfIzuDtviB+5DQXNz f4mkUdPIvwFmRF9LT3LLMolrIDKnuRZ+j13v4el9wiiabiV74XCT3hHFAilD6GqhAjPK PSVtB85f+9FQqflfbwTFEAJxKv0tZddxzr/SNMQD/9jQpTY5XeZ6JSk1umCeOXk7VT8n U4mr//9c6/trOH6trb+tqqAIfcK2fMh6gpaaorNejoYR9peen5GZPjX9/vgkfFSq9ScO W/6w== 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=ixwCG7/dZigNeiQzjDCIJqTFxi0+dHXprIOccPvDWlE=; b=JtTkc7ehz3K1pkLiQodeFFSX+LFQn1rDUpr2St+Fo5DgmyCEAkRMN11gFpynb/Kc54 SK/RODFhPHYCl+M9+ih1LXIWTi7VSZf17fh4zCixhSmBV4DQBcKNzFFgGOpOPqFQaXlz 29ejBjYerg+CGLMzENkXh8VS6vXPWqng6iEEL7yQR+Az54BMol1ErzP14LGSXFOJE+6D KO2CwK65EU/rCD6pAUtJhNrn3kF0pLijM40Acn4e0aKFKmBKz6AyrjWIqR5dCVcsGMJE RAZKsCk1EMZpJItN4NEIlWEEFWEv44o8uwWfLSuEVkf0TcufxZxbMoRmK1fkIgFRi8Bb zklQ== X-Gm-Message-State: APjAAAWTd54nFj21NQXtbtgBEY/ajXWnROYW3fz+cVKcHFbFSFh8tYQz 3yD8fCl46rm8BW/kvJAVb1wcEQ8D14g= X-Google-Smtp-Source: APXvYqyiU6qRLPBWmWeyDX9Fop1YYuoqvKApCuYZBDwUm8hYOrjIIB9n2ASEN5V7azHy7AQqGI39zw== X-Received: by 2002:a05:6000:118e:: with SMTP id g14mr24264342wrx.39.1580830640287; Tue, 04 Feb 2020 07:37:20 -0800 (PST) Received: from localhost.localdomain (41.142.6.51.dyn.plus.net. [51.6.142.41]) by smtp.gmail.com with ESMTPSA id p26sm4067143wmc.24.2020.02.04.07.37.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 07:37:19 -0800 (PST) From: Wei Liu X-Google-Original-From: Wei Liu To: Xen Development List Date: Tue, 4 Feb 2020 15:37:04 +0000 Message-Id: <20200204153704.15934-11-liuwe@microsoft.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200204153704.15934-1-liuwe@microsoft.com> References: <20200204153704.15934-1-liuwe@microsoft.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v7 10/10] 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 , Jan Beulich , =?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 Reviewed-by: Paul Durrant Reviewed-by: Roger Pau Monné --- v6: 1. Use hv_vp_assist_page_msr 2. Make code shorter 3. Preserve rsvdP fields 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 | 37 ++++++++++++++++++++++++++++- xen/arch/x86/guest/hyperv/private.h | 1 + 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c index e31c4b30b8..248f854d6e 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_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,6 +156,31 @@ static int setup_hypercall_pcpu_arg(void) return 0; } +static int setup_vp_assist(void) +{ + union hv_vp_assist_page_msr msr; + + if ( !this_cpu(hv_vp_assist) ) + { + this_cpu(hv_vp_assist) = alloc_xenheap_page(); + if ( !this_cpu(hv_vp_assist) ) + { + printk("CPU%u: Failed to allocate vp_assist page\n", + smp_processor_id()); + return -ENOMEM; + } + + clear_page(this_cpu(hv_vp_assist)); + } + + rdmsrl(HV_X64_MSR_VP_ASSIST_PAGE, msr.raw); + msr.pfn = virt_to_mfn(this_cpu(hv_vp_assist)); + msr.enabled = 1; + wrmsrl(HV_X64_MSR_VP_ASSIST_PAGE, msr.raw); + + return 0; +} + static void __init setup(void) { ASM_CONSTANT(HV_HCALL_PAGE, __fix_x_to_virt(FIX_X_HYPERV_HCALL)); @@ -163,11 +189,20 @@ static void __init setup(void) if ( setup_hypercall_pcpu_arg() ) panic("Hyper-V 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 ) + return rc; + + return setup_vp_assist(); } static void __init e820_fixup(struct e820map *e820) diff --git a/xen/arch/x86/guest/hyperv/private.h b/xen/arch/x86/guest/hyperv/private.h index d1765d4f23..956eff831f 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_input_page); +DECLARE_PER_CPU(void *, hv_vp_assist); DECLARE_PER_CPU(unsigned int, hv_vp_index); #endif /* __XEN_HYPERV_PRIVIATE_H__ */