Received: by 10.192.165.148 with SMTP id m20csp397131imm; Thu, 3 May 2018 23:10:46 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrthfIRwDI17ukfmZqUx+CV6gaYRDZsPEFCmHxzHq2yGa4nHd1PwlM7Z0D2TiGdCKRwcfNF X-Received: by 10.98.50.198 with SMTP id y189mr20442330pfy.241.1525414246508; Thu, 03 May 2018 23:10:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525414246; cv=none; d=google.com; s=arc-20160816; b=SsvHiOtdjyweZm4fBGlbbtRDft9FqAUKMgpSpS2fsZI8U7Zl0NTJkXR4H2pamRlItx V0KYwJQgnRl28J9Uo1eIVZceTCjjV8uC87sbO5HDjTv/oQE4vJ1cigWKc0Mwd63WRkxe wuDTxO+za/EJkPaGnJ+G/SKPAN6DLqSTcxQZHrFPSYwEcEjn7vUMVhhKT6mcAfKwsnGy B7gF0crIwU2Pndiyg5SlJmccyqM5vnaFf52nbEawK2WvnDeJDPzop/H0GKcW/9bD9D37 JDXjrRKL3WUxcbGJA0EgwUgDddsdSkxohopWYacIIYnT4NSKshhJtuipqfZOpNWT0uVz JgbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:reply-to:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=NDho73Jm6I42cPIqvRNy5nZ4Hv2JHFW8JQPk9osklV0=; b=LiQ5uiIqbtZyco2jc09hsxIpRkjZB9f8+VvMtGnh8Tteyc1uZT/doKppe7kkudyJVP H8nays/gQGmUHSGYAIn3atTvRCeMb8KGlZEAtV+SuXSLZa/s0Mu1+EJPpViE7zyL0wG+ AJ/X7q/PdOJ89eKobClJh91sjZODgQa0EXT8bnYenpp1HnFxTc+Q24mwBPEFr9uq/ZyR b+HKeWziMHbLEtKX/hlQxAgpEekhtt0N+uVrVq7Oq37hV7Aia7iUd5eSLvDHPZaa6M2G yUdAIkbGlPwr0qF1wSTB6VD+PhbQis5q/rrt50boBA/AtzFJ9N6GJsPMpSRZfGGgHvj+ cCmg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s65-v6si12887105pgc.269.2018.05.03.23.10.32; Thu, 03 May 2018 23:10:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751593AbeEDGJt (ORCPT + 99 others); Fri, 4 May 2018 02:09:49 -0400 Received: from a2nlsmtp01-02.prod.iad2.secureserver.net ([198.71.225.36]:47566 "EHLO a2nlsmtp01-02.prod.iad2.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751002AbeEDGJ1 (ORCPT ); Fri, 4 May 2018 02:09:27 -0400 Received: from linuxonhyperv2.linuxonhyperv.com ([107.180.71.197]) by : HOSTING RELAY : with SMTP id ETtJfJN3TlLMSETtJfbnKZ; Thu, 03 May 2018 23:08:26 -0700 x-originating-ip: 107.180.71.197 Received: from kys by linuxonhyperv2.linuxonhyperv.com with local (Exim 4.89_1) (envelope-from ) id 1fETtJ-0000sv-NA; Thu, 03 May 2018 23:08:25 -0700 From: kys@linuxonhyperv.com To: x86@kernel.org, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, devel@linuxdriverproject.org, olaf@aepfle.de, apw@canonical.com, jasowang@redhat.com, tglx@linutronix.de, hpa@zytor.com, sthemmin@microsoft.com, Michael.H.Kelley@microsoft.com, vkuznets@redhat.com Cc: "K. Y. Srinivasan" Subject: [PATCH V2 3/5] X86: Hyper-V: Enhanced IPI enlightenment Date: Thu, 3 May 2018 23:08:21 -0700 Message-Id: <20180504060823.3345-3-kys@linuxonhyperv.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180504060823.3345-1-kys@linuxonhyperv.com> References: <20180504060653.3240-1-kys@linuxonhyperv.com> <20180504060823.3345-1-kys@linuxonhyperv.com> Reply-To: kys@microsoft.com X-CMAE-Envelope: MS4wfKaZGpIcRPkEI3q0K+apsAgnPKIpzcm8snjHCaVDqxK4jdhSwjlgHyAMb6K/Me7ByOgcLqdR20g2smWpcalCkCWaMJgxrlzaD7N4EoLvbZ9jDW5dME9w EinYlPlMQLzX8QQOGCm7OVqmgoYVxzdNoL9HBT07X6PaondB6Qi/xT596BnSL0KQqziSrtEmh3t1EiJESk/FwhnZA+7pyv8CKL7muElMJNZ+OfPUKeGDoUtl INTZUMtyHwfvLW1vkt810StnJCsEM0JV8WiVg8ivglhS5f9E/sWrRTT5H+nVNONf0BlC+ItsSbrDdI+moXqtATVbKBnzP9JVtINTXxIUl+EoUQndavTKeCsu faA4OFAKMd5+9rVXnaEgzySVxVkRmOAad2J9TOEd0GxwVCalzbtdAhOd6Fj/1nouS+jOMeWO+6zA4oFvbr5TZ8Y9vcDbGXcLVlc2iwrcR8Pndxl6zT4KsDYa kiBPVtTshoBYgM4mYIf+Ei4mZsF+eWWOr9MEjee+JTxgH8BOGOfzSTea1GP2/5FbbCpFOQqkgUv3MmfukcfPnGj7Tc6ycHGObOpaDMYhoeAN75FAhNEfx7lu T8hH619+SI5uupFv7r/ZfdI/ Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "K. Y. Srinivasan" Support enhanced IPI enlightenments (to target more than 64 CPUs). Signed-off-by: K. Y. Srinivasan --- arch/x86/hyperv/hv_apic.c | 42 +++++++++++++++++++++++++++++++++++++- arch/x86/hyperv/mmu.c | 2 +- arch/x86/include/asm/hyperv-tlfs.h | 15 +++++++++++++- arch/x86/include/asm/mshyperv.h | 33 ++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 3 deletions(-) diff --git a/arch/x86/hyperv/hv_apic.c b/arch/x86/hyperv/hv_apic.c index f52d08a7a343..1e269a318c27 100644 --- a/arch/x86/hyperv/hv_apic.c +++ b/arch/x86/hyperv/hv_apic.c @@ -92,6 +92,40 @@ static void hv_apic_eoi_write(u32 reg, u32 val) /* * IPI implementation on Hyper-V. */ +static bool __send_ipi_mask_ex(const struct cpumask *mask, int vector) +{ + struct ipi_arg_ex **arg; + struct ipi_arg_ex *ipi_arg; + unsigned long flags; + int nr_bank = 0; + int ret = 1; + + local_irq_save(flags); + arg = (struct ipi_arg_ex **)this_cpu_ptr(hyperv_pcpu_input_arg); + + ipi_arg = *arg; + if (unlikely(!ipi_arg)) + goto ipi_mask_ex_done; + + ipi_arg->vector = vector; + ipi_arg->reserved = 0; + ipi_arg->vp_set.valid_bank_mask = 0; + + if (!cpumask_equal(mask, cpu_present_mask)) { + ipi_arg->vp_set.format = HV_GENERIC_SET_SPARSE_4K; + nr_bank = cpumask_to_vpset(&(ipi_arg->vp_set), mask); + } + if (!nr_bank) + ipi_arg->vp_set.format = HV_GENERIC_SET_ALL; + + ret = hv_do_rep_hypercall(HVCALL_SEND_IPI_EX, 0, nr_bank, + ipi_arg, NULL); + +ipi_mask_ex_done: + local_irq_restore(flags); + return ((ret == 0) ? true : false); +} + static bool __send_ipi_mask(const struct cpumask *mask, int vector) { int cur_cpu, vcpu; @@ -109,6 +143,9 @@ static bool __send_ipi_mask(const struct cpumask *mask, int vector) if ((vector < HV_IPI_LOW_VECTOR) || (vector > HV_IPI_HIGH_VECTOR)) return false; + if ((ms_hyperv.hints & HV_X64_EX_PROCESSOR_MASKS_RECOMMENDED)) + return __send_ipi_mask_ex(mask, vector); + local_irq_save(flags); arg = (struct ipi_arg_non_ex **)this_cpu_ptr(hyperv_pcpu_input_arg); @@ -192,7 +229,10 @@ static void hv_send_ipi_self(int vector) void __init hv_apic_init(void) { if (ms_hyperv.hints & HV_X64_CLUSTER_IPI_RECOMMENDED) { - pr_info("Hyper-V: Using IPI hypercalls\n"); + if ((ms_hyperv.hints & HV_X64_EX_PROCESSOR_MASKS_RECOMMENDED)) + pr_info("Hyper-V: Using ext hypercalls for IPI\n"); + else + pr_info("Hyper-V: Using IPI hypercalls\n"); /* * Set the IPI entry points. */ diff --git a/arch/x86/hyperv/mmu.c b/arch/x86/hyperv/mmu.c index 56c9ebac946f..adee39a7a3f2 100644 --- a/arch/x86/hyperv/mmu.c +++ b/arch/x86/hyperv/mmu.c @@ -239,7 +239,7 @@ static void hyperv_flush_tlb_others_ex(const struct cpumask *cpus, flush->hv_vp_set.valid_bank_mask = 0; if (!cpumask_equal(cpus, cpu_present_mask)) { - flush->hv_vp_set.format = HV_GENERIC_SET_SPARCE_4K; + flush->hv_vp_set.format = HV_GENERIC_SET_SPARSE_4K; nr_bank = cpumask_to_vp_set(flush, cpus); } diff --git a/arch/x86/include/asm/hyperv-tlfs.h b/arch/x86/include/asm/hyperv-tlfs.h index 332e786d4deb..3bfa92c2793c 100644 --- a/arch/x86/include/asm/hyperv-tlfs.h +++ b/arch/x86/include/asm/hyperv-tlfs.h @@ -344,6 +344,7 @@ struct hv_tsc_emulation_status { #define HVCALL_SEND_IPI 0x000b #define HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE_EX 0x0013 #define HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST_EX 0x0014 +#define HVCALL_SEND_IPI_EX 0x0015 #define HVCALL_POST_MESSAGE 0x005c #define HVCALL_SIGNAL_EVENT 0x005d @@ -369,7 +370,7 @@ struct hv_tsc_emulation_status { #define HV_FLUSH_USE_EXTENDED_RANGE_FORMAT BIT(3) enum HV_GENERIC_SET_FORMAT { - HV_GENERIC_SET_SPARCE_4K, + HV_GENERIC_SET_SPARSE_4K, HV_GENERIC_SET_ALL, }; @@ -721,4 +722,16 @@ struct ipi_arg_non_ex { u64 cpu_mask; }; +struct hv_vpset { + u64 format; + u64 valid_bank_mask; + u64 bank_contents[]; +}; + +struct ipi_arg_ex { + u32 vector; + u32 reserved; + struct hv_vpset vp_set; +}; + #endif diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h index 1eff91599c2b..0ee82519957b 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -259,6 +259,39 @@ static inline int hv_cpu_number_to_vp_number(int cpu_number) return hv_vp_index[cpu_number]; } +static inline int cpumask_to_vpset(struct hv_vpset *vpset, + const struct cpumask *cpus) +{ + int cpu, vcpu, vcpu_bank, vcpu_offset, nr_bank = 1; + + /* valid_bank_mask can represent up to 64 banks */ + if (hv_max_vp_index / 64 >= 64) + return 0; + + /* + * Clear all banks up to the maximum possible bank as hv_flush_pcpu_ex + * structs are not cleared between calls, we risk flushing unneeded + * vCPUs otherwise. + */ + for (vcpu_bank = 0; vcpu_bank <= hv_max_vp_index / 64; vcpu_bank++) + vpset->bank_contents[vcpu_bank] = 0; + + /* + * Some banks may end up being empty but this is acceptable. + */ + for_each_cpu(cpu, cpus) { + vcpu = hv_cpu_number_to_vp_number(cpu); + vcpu_bank = vcpu / 64; + vcpu_offset = vcpu % 64; + __set_bit(vcpu_offset, (unsigned long *) + &vpset->bank_contents[vcpu_bank]); + if (vcpu_bank >= nr_bank) + nr_bank = vcpu_bank + 1; + } + vpset->valid_bank_mask = GENMASK_ULL(nr_bank - 1, 0); + return nr_bank; +} + void __init hyperv_init(void); void hyperv_setup_mmu_ops(void); void hyper_alloc_mmu(void); -- 2.15.1