Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1619314

RE: [PATCH 5/7] hyper-v: globalize vp_index

Path csiph.com!news.mixmin.net!news.unit0.net!news.panservice.it!diesel.cu.mi.it!bofh.it!news.nic.it!robomod
From KY Srinivasan <kys@microsoft.com>
Newsgroups linux.kernel
Subject RE: [PATCH 5/7] hyper-v: globalize vp_index
Date Sat, 08 Apr 2017 17:50:01 +0200
Message-ID <tu0MF-78Z-3@gated-at.bofh.it> (permalink)
References <ttAfw-6oW-11@gated-at.bofh.it> <ttAfx-6oW-41@gated-at.bofh.it>
X-Original-To Vitaly Kuznetsov <vkuznets@redhat.com>, "devel@linuxdriverproject.org" <devel@linuxdriverproject.org>, "x86@kernel.org" <x86@kernel.org>
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=LXRtkvKiYwZeatMkUXooo74tzo26V8tMOExZCjbAjms=; b=K7hytVhvYGD0Cwqk7x0hHpHqTVG/YW3t5OoiQ0SdrNxCLGPxlxFXMiMPyXMmZ1k5GvioEGwV6sWsPpMONoySOV5a+FjUF7OyjlSXDnEG7ATWY5nc2RlnBKVoY7w+7A7HJMljmFg1Egd690FmrlTwwLnlLnO57pxiCBko4crfcaQ=
Thread-Topic [PATCH 5/7] hyper-v: globalize vp_index
Thread-Index AQHSr5Ht0pT9RlLf00u/VooaNB63lqG7nFeg
Accept-Language en-US
Content-Language en-US
Authentication-Results redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=none action=none header.from=microsoft.com;
X-Originating-IP [2601:600:8c00:1040:bdd6:d020:3aef:2c08]
X-Microsoft-Exchange-Diagnostics 1;BN3PR03MB1413;7:3nqregoviU23rQQPup8S9E2Lippkvx+VnD6l0lUOT7nACSDl1EF7OvsJLDKzTClERKzbc5bVSIUMJHaikO2iq+IGklzeru2lWpCMXbl9sjkBeqmyWS9wKs7XQN3wLRQ1e6H+aQQawlAJCAH6mDJ6v3RDgfiVGOfd/HYcUu7z9cyYg3aJzE7uDltmhuBdGcO6C7/UVt7eVaocu0CNYLmsuO+jWjVQqhwn2hhZYrtHpafEcA7l3rO6BZ0Y9lvpqyvLywEZty+nO9CfWNhZAUrsnfgxssU1wI5+KiBKkOdocI+ZUWlywh49nVe0D0pi9sDZiltR3ehO/4+pBhpH/X7JeHgJ+c/7DPLqmB5J/y3UziI=
X-Ms-Office365-Filtering-Correlation-ID ac027b5a-8b07-4ac3-29af-08d47e95c394
X-Ms-Office365-Filtering-Ht Tenant
X-Microsoft-Antispam UriScan:;BCL:0;PCL:0;RULEID:(22001)(2017030254075)(48565401081)(201703131423075)(201703031133081)(201702281549075);SRVR:BN3PR03MB1413;
X-Microsoft-Antispam-Prvs <BN3PR03MB141332E40CB8E44BA533CE16A00F0@BN3PR03MB1413.namprd03.prod.outlook.com>
X-Exchange-Antispam-Report-Test UriScan:(9452136761055)(21532816269658);
X-Exchange-Antispam-Report-Cfa-Test BCL:0;PCL:0;RULEID:(61425038)(6040450)(601004)(2401047)(8121501046)(5005006)(10201501046)(93006095)(93001095)(3002001)(6055026)(61426038)(61427038)(6041248)(201703131423075)(201702281528075)(201703061421075)(20161123564025)(20161123560025)(20161123555025)(20161123562025)(6072148);SRVR:BN3PR03MB1413;BCL:0;PCL:0;RULEID:;SRVR:BN3PR03MB1413;
X-Forefront-Prvs 0271483E06
X-Forefront-Antispam-Report SFV:NSPM;SFS:(10019020)(6009001)(39860400002)(39400400002)(39410400002)(39450400003)(39840400002)(39850400002)(377454003)(13464003)(8676002)(6246003)(3280700002)(2906002)(6506006)(53936002)(122556002)(189998001)(10090500001)(10290500002)(2501003)(86362001)(5005710100001)(33656002)(86612001)(81166006)(3660700001)(8936002)(2201001)(7696004)(4326008)(6436002)(74316002)(9686003)(8990500004)(6116002)(54356999)(76176999)(102836003)(2950100002)(77096006)(107886003)(38730400002)(5660300001)(99286003)(50986999)(55016002)(2900100001)(7736002)(305945005)(25786009);DIR:OUT;SFP:1102;SCL:1;SRVR:BN3PR03MB1413;H:BN6PR03MB2481.namprd03.prod.outlook.com;FPR:;SPF:None;MLV:sfv;LANG:en;
Spamdiagnosticoutput 1:99
Spamdiagnosticmetadata NSPM
Content-Type text/plain; charset="us-ascii"
Content-Transfer-Encoding quoted-printable
MIME-Version 1.0
X-Originatororg microsoft.com
X-Ms-Exchange-Crosstenant-Originalarrivaltime 08 Apr 2017 15:41:45.9964 (UTC)
X-Ms-Exchange-Crosstenant-Fromentityheader Hosted
X-Ms-Exchange-Crosstenant-ID 72f988bf-86f1-41af-91ab-2d7cd011db47
X-Ms-Exchange-Transport-Crosstenantheadersstamped BN3PR03MB1413
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 299
Organization linux.* mail to news gateway
X-Original-Cc "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>, "Haiyang Zhang" <haiyangz@microsoft.com>, Stephen Hemminger <sthemmin@microsoft.com>, Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>, Steven Rostedt <rostedt@goodmis.org>, "Jork Loeser" <Jork.Loeser@microsoft.com>
X-Original-Date Sat, 8 Apr 2017 15:41:45 +0000
X-Original-Message-ID <BN6PR03MB2481A3F628A7753C21251CA6A00F0@BN6PR03MB2481.namprd03.prod.outlook.com>
X-Original-References <20170407112701.17157-1-vkuznets@redhat.com> <20170407112701.17157-6-vkuznets@redhat.com>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1619314

Show key headers only | View raw



> -----Original Message-----
> From: Vitaly Kuznetsov [mailto:vkuznets@redhat.com]
> Sent: Friday, April 7, 2017 4:27 AM
> To: devel@linuxdriverproject.org; x86@kernel.org
> Cc: linux-kernel@vger.kernel.org; KY Srinivasan <kys@microsoft.com>;
> Haiyang Zhang <haiyangz@microsoft.com>; Stephen Hemminger
> <sthemmin@microsoft.com>; Thomas Gleixner <tglx@linutronix.de>; Ingo
> Molnar <mingo@redhat.com>; H. Peter Anvin <hpa@zytor.com>; Steven
> Rostedt <rostedt@goodmis.org>; Jork Loeser <Jork.Loeser@microsoft.com>
> Subject: [PATCH 5/7] hyper-v: globalize vp_index
> 
> To support implementing remote TLB flushing on Hyper-V with a hypercall
> we need to make vp_index available outside of vmbus module. Rename and
> globalize.
> 
> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> ---
>  arch/x86/hyperv/hv_init.c       | 34
> +++++++++++++++++++++++++++++++++-
>  arch/x86/include/asm/mshyperv.h | 26 ++++++++++++++++++++++++++
>  drivers/hv/channel_mgmt.c       |  7 +++----
>  drivers/hv/connection.c         |  3 ++-
>  drivers/hv/hv.c                 |  9 ---------
>  drivers/hv/hyperv_vmbus.h       | 11 -----------
>  drivers/hv/vmbus_drv.c          | 17 -----------------
>  include/linux/hyperv.h          |  1 -
>  8 files changed, 64 insertions(+), 44 deletions(-)
> 
> diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
> index 7d961d4..1c14088 100644
> --- a/arch/x86/hyperv/hv_init.c
> +++ b/arch/x86/hyperv/hv_init.c
> @@ -26,6 +26,8 @@
>  #include <linux/mm.h>
>  #include <linux/clockchips.h>
>  #include <linux/hyperv.h>
> +#include <linux/slab.h>
> +#include <linux/cpuhotplug.h>
> 
>  #ifdef CONFIG_X86_64
> 
> @@ -103,6 +105,20 @@ EXPORT_SYMBOL_GPL(hv_hypercall_pg);
>  struct clocksource *hyperv_cs;
>  EXPORT_SYMBOL_GPL(hyperv_cs);
> 
> +u32 *hv_vp_index;
> +EXPORT_SYMBOL_GPL(hv_vp_index);
> +
> +static int hv_cpu_init(unsigned int cpu)
> +{
> +	u64 msr_vp_index;
> +
> +	hv_get_vp_index(msr_vp_index);
> +
> +	hv_vp_index[smp_processor_id()] = (u32)msr_vp_index;
> +
> +	return 0;
> +}
> +
>  /*
>   * This function is to be invoked early in the boot sequence after the
>   * hypervisor has been detected.
> @@ -118,6 +134,16 @@ void hyperv_init(void)
>  	if (x86_hyper != &x86_hyper_ms_hyperv)
>  		return;
> 
> +	/* Allocate percpu VP index */
> +	hv_vp_index = kcalloc(num_possible_cpus(), sizeof(*hv_vp_index),
> +			      GFP_KERNEL);
> +	if (!hv_vp_index)
> +		return;
> +
> +	if (cpuhp_setup_state(CPUHP_AP_ONLINE_DYN,
> "x86/hyperv_init:online",
> +			      hv_cpu_init, NULL) < 0)
> +		goto free_vp_index;
> +
>  	/*
>  	 * Setup the hypercall page and enable hypercalls.
>  	 * 1. Register the guest ID
> @@ -129,7 +155,7 @@ void hyperv_init(void)
>  	hv_hypercall_pg  = __vmalloc(PAGE_SIZE, GFP_KERNEL,
> PAGE_KERNEL_RX);
>  	if (hv_hypercall_pg == NULL) {
>  		wrmsrl(HV_X64_MSR_GUEST_OS_ID, 0);
> -		return;
> +		goto free_vp_index;
>  	}
> 
>  	rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
> @@ -169,6 +195,12 @@ void hyperv_init(void)
>  	hyperv_cs = &hyperv_cs_msr;
>  	if (ms_hyperv.features &
> HV_X64_MSR_TIME_REF_COUNT_AVAILABLE)
>  		clocksource_register_hz(&hyperv_cs_msr,
> NSEC_PER_SEC/100);
> +
> +	return;
> +
> +free_vp_index:
> +	kfree(hv_vp_index);
> +	hv_vp_index = NULL;
>  }
> 
>  /*
> diff --git a/arch/x86/include/asm/mshyperv.h
> b/arch/x86/include/asm/mshyperv.h
> index a2c996b..1293c84 100644
> --- a/arch/x86/include/asm/mshyperv.h
> +++ b/arch/x86/include/asm/mshyperv.h
> @@ -274,6 +274,32 @@ static inline u64 hv_do_rep_hypercall(u16 code, u16
> rep_count, void *input,
>  	return status;
>  }
> 
> +/*
> + * Hypervisor's notion of virtual processor ID is different from
> + * Linux' notion of CPU ID. This information can only be retrieved
> + * in the context of the calling CPU. Setup a map for easy access
> + * to this information.
> + */
> +extern u32 __percpu *hv_vp_index;
> +
> +/**
> + * vmbus_cpu_number_to_vp_number() - Map CPU to VP.
> + * @cpu_number: CPU number in Linux terms
> + *
> + * This function returns the mapping between the Linux processor
> + * number and the hypervisor's virtual processor number, useful
> + * in making hypercalls and such that talk about specific
> + * processors.
> + *
> + * Return: Virtual processor number in Hyper-V terms
> + */
> +static inline int vmbus_cpu_number_to_vp_number(int cpu_number)
> +{
> +	WARN_ON(hv_vp_index[cpu_number] == -1);
> +
> +	return hv_vp_index[cpu_number];
> +}

Now that we have moved this functionality into the Hyper-V specific 
base kernel, a hv prefix maybe more appropriate for the function.

> +
>  void hyperv_init(void);
>  void hyperv_report_panic(struct pt_regs *regs);
>  bool hv_is_hypercall_page_setup(void);
> diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c
> index 6cfa297..9969c82 100644
> --- a/drivers/hv/channel_mgmt.c
> +++ b/drivers/hv/channel_mgmt.c
> @@ -599,7 +599,7 @@ static void init_vp_index(struct vmbus_channel
> *channel, u16 dev_type)
>  		 */
>  		channel->numa_node = 0;
>  		channel->target_cpu = 0;
> -		channel->target_vp = hv_context.vp_index[0];
> +		channel->target_vp =
> vmbus_cpu_number_to_vp_number(0);
>  		return;
>  	}
> 
> @@ -683,7 +683,7 @@ static void init_vp_index(struct vmbus_channel
> *channel, u16 dev_type)
>  	}
> 
>  	channel->target_cpu = cur_cpu;
> -	channel->target_vp = hv_context.vp_index[cur_cpu];
> +	channel->target_vp =
> vmbus_cpu_number_to_vp_number(cur_cpu);
>  }
> 
>  static void vmbus_wait_for_unload(void)
> @@ -1187,8 +1187,7 @@ struct vmbus_channel
> *vmbus_get_outgoing_channel(struct vmbus_channel *primary)
>  		return outgoing_channel;
>  	}
> 
> -	cur_cpu = hv_context.vp_index[get_cpu()];
> -	put_cpu();
> +	cur_cpu =
> vmbus_cpu_number_to_vp_number(smp_processor_id());
>  	list_for_each_safe(cur, tmp, &primary->sc_list) {
>  		cur_channel = list_entry(cur, struct vmbus_channel, sc_list);
>  		if (cur_channel->state != CHANNEL_OPENED_STATE)
> diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c
> index 545f2a4..7026d13 100644
> --- a/drivers/hv/connection.c
> +++ b/drivers/hv/connection.c
> @@ -96,7 +96,8 @@ static int vmbus_negotiate_version(struct
> vmbus_channel_msginfo *msginfo,
>  	 * the CPU attempting to connect may not be CPU 0.
>  	 */
>  	if (version >= VERSION_WIN8_1)
> -		msg->target_vcpu =
> hv_context.vp_index[smp_processor_id()];
> +		msg->target_vcpu =
> +
> 	vmbus_cpu_number_to_vp_number(smp_processor_id());
>  	else
>  		msg->target_vcpu = 0;
> 
> diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
> index 12e7bae..7e67ef4 100644
> --- a/drivers/hv/hv.c
> +++ b/drivers/hv/hv.c
> @@ -229,7 +229,6 @@ int hv_synic_init(unsigned int cpu)
>  	union hv_synic_siefp siefp;
>  	union hv_synic_sint shared_sint;
>  	union hv_synic_scontrol sctrl;
> -	u64 vp_index;
> 
>  	/* Setup the Synic's message page */
>  	hv_get_simp(simp.as_uint64);
> @@ -271,14 +270,6 @@ int hv_synic_init(unsigned int cpu)
>  	hv_context.synic_initialized = true;
> 
>  	/*
> -	 * Setup the mapping between Hyper-V's notion
> -	 * of cpuid and Linux' notion of cpuid.
> -	 * This array will be indexed using Linux cpuid.
> -	 */
> -	hv_get_vp_index(vp_index);
> -	hv_context.vp_index[cpu] = (u32)vp_index;
> -
> -	/*
>  	 * Register the per-cpu clockevent source.
>  	 */
>  	if (ms_hyperv.features & HV_X64_MSR_SYNTIMER_AVAILABLE)
> diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
> index 6113e91..d624526 100644
> --- a/drivers/hv/hyperv_vmbus.h
> +++ b/drivers/hv/hyperv_vmbus.h
> @@ -229,17 +229,6 @@ struct hv_context {
>  	struct hv_per_cpu_context __percpu *cpu_context;
> 
>  	/*
> -	 * Hypervisor's notion of virtual processor ID is different from
> -	 * Linux' notion of CPU ID. This information can only be retrieved
> -	 * in the context of the calling CPU. Setup a map for easy access
> -	 * to this information:
> -	 *
> -	 * vp_index[a] is the Hyper-V's processor ID corresponding to
> -	 * Linux cpuid 'a'.
> -	 */
> -	u32 vp_index[NR_CPUS];
> -
> -	/*
>  	 * To manage allocations in a NUMA node.
>  	 * Array indexed by numa node ID.
>  	 */
> diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
> index 0087b49..63e743d 100644
> --- a/drivers/hv/vmbus_drv.c
> +++ b/drivers/hv/vmbus_drv.c
> @@ -1455,23 +1455,6 @@ void vmbus_free_mmio(resource_size_t start,
> resource_size_t size)
>  }
>  EXPORT_SYMBOL_GPL(vmbus_free_mmio);
> 
> -/**
> - * vmbus_cpu_number_to_vp_number() - Map CPU to VP.
> - * @cpu_number: CPU number in Linux terms
> - *
> - * This function returns the mapping between the Linux processor
> - * number and the hypervisor's virtual processor number, useful
> - * in making hypercalls and such that talk about specific
> - * processors.
> - *
> - * Return: Virtual processor number in Hyper-V terms
> - */
> -int vmbus_cpu_number_to_vp_number(int cpu_number)
> -{
> -	return hv_context.vp_index[cpu_number];
> -}
> -EXPORT_SYMBOL_GPL(vmbus_cpu_number_to_vp_number);
> -
>  static int vmbus_acpi_add(struct acpi_device *device)
>  {
>  	acpi_status result;
> diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
> index 5d6777c..2450e07 100644
> --- a/include/linux/hyperv.h
> +++ b/include/linux/hyperv.h
> @@ -1184,7 +1184,6 @@ int vmbus_allocate_mmio(struct resource **new,
> struct hv_device *device_obj,
>  			resource_size_t size, resource_size_t align,
>  			bool fb_overlap_ok);
>  void vmbus_free_mmio(resource_size_t start, resource_size_t size);
> -int vmbus_cpu_number_to_vp_number(int cpu_number);
> 
>  /*
>   * GUID definitions of various offer types - services offered to the guest.
> --
> 2.9.3

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 0/7] Hyper-V: praravirtualized remote TLB flushing and hypercall improvements Vitaly Kuznetsov <vkuznets@redhat.com> - 2017-04-07 13:30 +0200
  [PATCH 3/7] hyper-v: use fast hypercall for HVCALL_SIGNAL_EVENT Vitaly Kuznetsov <vkuznets@redhat.com> - 2017-04-07 13:30 +0200
  [PATCH 6/7] x86/hyper-v: use hypercall for remove TLB flush Vitaly Kuznetsov <vkuznets@redhat.com> - 2017-04-07 13:30 +0200
    RE: [PATCH 6/7] x86/hyper-v: use hypercall for remove TLB flush Jork Loeser <Jork.Loeser@microsoft.com> - 2017-04-07 22:50 +0200
    RE: [PATCH 6/7] x86/hyper-v: use hypercall for remove TLB flush KY Srinivasan <kys@microsoft.com> - 2017-04-08 18:50 +0200
      Re: [PATCH 6/7] x86/hyper-v: use hypercall for remove TLB flush Vitaly Kuznetsov <vkuznets@redhat.com> - 2017-04-10 16:50 +0200
  [PATCH 4/7] x86/hyperv: implement rep hypercalls Vitaly Kuznetsov <vkuznets@redhat.com> - 2017-04-07 13:30 +0200
    RE: [PATCH 4/7] x86/hyperv: implement rep hypercalls Jork Loeser <Jork.Loeser@microsoft.com> - 2017-04-07 21:50 +0200
      Re: [PATCH 4/7] x86/hyperv: implement rep hypercalls Vitaly Kuznetsov <vkuznets@redhat.com> - 2017-04-10 11:10 +0200
  [PATCH 5/7] hyper-v: globalize vp_index Vitaly Kuznetsov <vkuznets@redhat.com> - 2017-04-07 13:30 +0200
    RE: [PATCH 5/7] hyper-v: globalize vp_index KY Srinivasan <kys@microsoft.com> - 2017-04-08 17:50 +0200
  RE: [PATCH 0/7] Hyper-V: praravirtualized remote TLB flushing and  hypercall improvements KY Srinivasan <kys@microsoft.com> - 2017-04-08 17:00 +0200

csiph-web