Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp562466imm; Wed, 4 Jul 2018 01:56:42 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdT0SZJhqTtbIUzI5gQ1OfbK8vQm/pv3kJBlZHAv+8RwcHi9Ze5hXqXxDbookUqbFxaZv5f X-Received: by 2002:a17:902:be04:: with SMTP id r4-v6mr1233101pls.324.1530694602767; Wed, 04 Jul 2018 01:56:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530694602; cv=none; d=google.com; s=arc-20160816; b=DYBuoYCDh823CgyYlmm/wV82KpYp+cQDhhvU7qG357lpFNvCKPbERhuj8TYh5GS9mX 8irfGSnv9fEDkAqvJeFNfe4odKWuSf9we+Q3cSClaVqF/W5VHDxf6GCTU6tER7IUAK0Z NquHexphnsy3M0VE4IboODXizhvGDubWg9+5XWC9gy21whBXaw7FhqiBcnVFhX0cldyS JlW1XocIhH8eSVmIOvmvwmmed0ta0wEjQnBWx3ecrarIdbMQwA+QqbT6DBJnk4t5UM3m OndZ7M/KUmdHBkyIRaI7LnDf1YzMV6Zk1ru+tmD35xTQy82SA++eHsFps/qiu51M+TYN 7Ygg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=OWERCyexLa5weC2VGEy5vh+pXZMvaB6sR0iTXXNbgh0=; b=afsMS2JLveHHJoSogG8QuYTXi4bP99DzdKbEE21v313/irSQ0DmKOxfMGCDWssFX0y m3SSdv8iKj1+hRv2K3f0NF4652xoiQrswyse5owduwJk24JJv9sCksm8MwVI+WIxUF4X utcNk7T4xdTZ2QchlDExPyQI0xM4y41LcJGFX/9AfF7XYIQWdL0wwD5gtKdjBMfBBkRy u3tI6nrUzZrs0dnZfh/wJi83LLDXqXfC6Ik5sxFqL0qzfzNWOAOeEhffKznm99EGW+Ox BiA/aC4OdI/bbBemRjFNRFLcKMLAY9mGcJNyKknq+v5tVsLkBp+B2uzkktYqmitKf1F+ WPEg== 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 23-v6si2918721pgx.323.2018.07.04.01.56.28; Wed, 04 Jul 2018 01:56:42 -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 S934113AbeGDIzj (ORCPT + 99 others); Wed, 4 Jul 2018 04:55:39 -0400 Received: from terminus.zytor.com ([198.137.202.136]:50367 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932324AbeGDIzg (ORCPT ); Wed, 4 Jul 2018 04:55:36 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w648sp4j611842 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 4 Jul 2018 01:54:51 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w648sofJ611839; Wed, 4 Jul 2018 01:54:50 -0700 Date: Wed, 4 Jul 2018 01:54:50 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: "tip-bot for K. Y. Srinivasan" Message-ID: Cc: mikelley@microsoft.com, peterz@infradead.org, hpa@zytor.com, linux-kernel@vger.kernel.org, kys@microsoft.com, tglx@linutronix.de, torvalds@linux-foundation.org, mingo@kernel.org Reply-To: linux-kernel@vger.kernel.org, kys@microsoft.com, tglx@linutronix.de, torvalds@linux-foundation.org, mingo@kernel.org, mikelley@microsoft.com, peterz@infradead.org, hpa@zytor.com In-Reply-To: <20180703230155.15160-1-kys@linuxonhyperv.com> References: <20180703230155.15160-1-kys@linuxonhyperv.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/urgent] x86/hyper-v: Fix the circular dependency in IPI enlightenment Git-Commit-ID: 5e6f19db2deca9e7eaa378447c77616b35693399 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, T_DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 5e6f19db2deca9e7eaa378447c77616b35693399 Gitweb: https://git.kernel.org/tip/5e6f19db2deca9e7eaa378447c77616b35693399 Author: K. Y. Srinivasan AuthorDate: Tue, 3 Jul 2018 16:01:55 -0700 Committer: Ingo Molnar CommitDate: Wed, 4 Jul 2018 10:50:03 +0200 x86/hyper-v: Fix the circular dependency in IPI enlightenment The IPI hypercalls depend on being able to map the Linux notion of CPU ID to the hypervisor's notion of the CPU ID. The array hv_vp_index[] provides this mapping. Code for populating this array depends on the IPI functionality. Break this circular dependency. Tested-by: Michael Kelley Signed-off-by: K. Y. Srinivasan Acked-by: Thomas Gleixner Cc: Linus Torvalds Cc: Michael.H.Kelley@microsoft.com Cc: Peter Zijlstra Cc: apw@canonical.com Cc: devel@linuxdriverproject.org Cc: gregkh@linuxfoundation.org Cc: jasowang@redhat.com Cc: olaf@aepfle.de Cc: sthemmin@microsoft.com Cc: vkuznets@redhat.com Fixes: 68bb7bfb7985 ("X86/Hyper-V: Enable IPI enlightenments") Link: http://lkml.kernel.org/r/20180703230155.15160-1-kys@linuxonhyperv.com Signed-off-by: Ingo Molnar --- arch/x86/hyperv/hv_apic.c | 5 +++++ arch/x86/hyperv/hv_init.c | 5 ++++- arch/x86/include/asm/mshyperv.h | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/arch/x86/hyperv/hv_apic.c b/arch/x86/hyperv/hv_apic.c index f68855499391..63d7c196739f 100644 --- a/arch/x86/hyperv/hv_apic.c +++ b/arch/x86/hyperv/hv_apic.c @@ -114,6 +114,8 @@ static bool __send_ipi_mask_ex(const struct cpumask *mask, int vector) ipi_arg->vp_set.format = HV_GENERIC_SET_SPARSE_4K; nr_bank = cpumask_to_vpset(&(ipi_arg->vp_set), mask); } + if (nr_bank == -1) + goto ipi_mask_ex_done; if (!nr_bank) ipi_arg->vp_set.format = HV_GENERIC_SET_ALL; @@ -158,6 +160,9 @@ static bool __send_ipi_mask(const struct cpumask *mask, int vector) for_each_cpu(cur_cpu, mask) { vcpu = hv_cpu_number_to_vp_number(cur_cpu); + if (vcpu == -1) + goto ipi_mask_done; + /* * This particular version of the IPI hypercall can * only target upto 64 CPUs. diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index 4c431e1c1eff..04159893702e 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -265,7 +265,7 @@ void __init hyperv_init(void) { u64 guest_id, required_msrs; union hv_x64_msr_hypercall_contents hypercall_msr; - int cpuhp; + int cpuhp, i; if (x86_hyper_type != X86_HYPER_MS_HYPERV) return; @@ -293,6 +293,9 @@ void __init hyperv_init(void) if (!hv_vp_index) return; + for (i = 0; i < num_possible_cpus(); i++) + hv_vp_index[i] = -1; + hv_vp_assist_page = kcalloc(num_possible_cpus(), sizeof(*hv_vp_assist_page), GFP_KERNEL); if (!hv_vp_assist_page) { diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h index 3cd14311edfa..dee3f7347253 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -281,6 +281,8 @@ static inline int cpumask_to_vpset(struct hv_vpset *vpset, */ for_each_cpu(cpu, cpus) { vcpu = hv_cpu_number_to_vp_number(cpu); + if (vcpu == -1) + return -1; vcpu_bank = vcpu / 64; vcpu_offset = vcpu % 64; __set_bit(vcpu_offset, (unsigned long *)