From patchwork Tue Jan 29 07:20:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maya Nakamura X-Patchwork-Id: 1032532 X-Patchwork-Delegate: lorenzo.pieralisi@arm.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-pci-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="bF/t8AjV"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43pdFn51zNz9sDK for ; Tue, 29 Jan 2019 18:21:01 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725446AbfA2HVA (ORCPT ); Tue, 29 Jan 2019 02:21:00 -0500 Received: from mail-io1-f65.google.com ([209.85.166.65]:43778 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725267AbfA2HVA (ORCPT ); Tue, 29 Jan 2019 02:21:00 -0500 Received: by mail-io1-f65.google.com with SMTP id b23so15740871ios.10; Mon, 28 Jan 2019 23:20:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=HyzxbTH26FfhVsAa9oAD4X5nXO58/54A8xeITPEZ/A0=; b=bF/t8AjVNsLVx9T21Q/ty/6+Ta9273qD0uR4iJPQDFvHXnE1YwHsSwgAZ6VNVSgTuN dM+PQxMvJv27GGbbuctEPssL/CDTN17p8s9Ea+0zqsvKoU7fC2r396ii/N288wW5/54H FxGNXFQdeiFsyHrm4o2YX5gmW+XLdPGxv6uFiktcuCO6CCRvAlkbgsxo5p9h8xi4hDdl c3YMHNtW5EaDw8auo6v/D0zagKkOXPPUwJov/9Ttq/vZQh95/X7lP/D4xlYR/n4m+omT p4Je1DI7Ha3Bvx2Yn110Gc4K9ilcCdO01/B/EM40i9vYFvdKmVMLseX2KbyDTyDhAxRL ETMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=HyzxbTH26FfhVsAa9oAD4X5nXO58/54A8xeITPEZ/A0=; b=EkxiWcxaj2M7lVLK+ZXXqXX/z8Co81uvETy1bUpjJpU0AYqY7ei59kCUgBUIklQFrQ wZe8q/X09KIU6Fw3oByFHkuxq9txAOAiedq06CHV4c8/FQGySRH/HuupR5RFzPBJktvb OIEoI1xk2l9P2NaOpbXAku07uBYIe3JNoZR+I21a1edmWgjyOP4mPTctN2/7TTlYGZU0 fTkaDHsiG46fJX7zPkBInFCbkaysYgs3J0XwNoX3E8XnG7De/38zyS/dqGJPHH0ToYkT ey9TXD2/3n0h+WnG16ZkYzcdmWBaa7ojy3ry9AyAQWBNg/wknupZA+ZD9HxGf3e4PNA3 zYYA== X-Gm-Message-State: AJcUukdK5QZKFA2+1TaY02p2Q0lMDjnTYEZ882mvFhEhAhDjufABgJk2 d/dX8rk/6Kx8EMPPIw45TEM= X-Google-Smtp-Source: ALg8bN7DpAmH3CYO/dt9xZkod+oEYtUPmblHDemcXBTMIEyS1hKRdTH6YAPQeiAEPzdyTf3Sy8t4wg== X-Received: by 2002:a5e:8817:: with SMTP id l23mr13607861ioj.272.1548746458713; Mon, 28 Jan 2019 23:20:58 -0800 (PST) Received: from m-hyperV (50-47-88-57.evrt.wa.frontiernet.net. [50.47.88.57]) by smtp.gmail.com with ESMTPSA id q15sm13867509ioj.64.2019.01.28.23.20.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Jan 2019 23:20:58 -0800 (PST) Date: Mon, 28 Jan 2019 23:20:56 -0800 From: Maya Nakamura To: lorenzo.pieralisi@arm.com, bhelgaas@google.com, linux-pci@vger.kernel.org, kys@microsoft.com, sthemmin@microsoft.com, olaf@aepfle.de, apw@canonical.com, jasowang@redhat.com, mikelley@microsoft.com, Alexander.Levin@microsoft.com Cc: linux-kernel@vger.kernel.org, driverdev-devel@linuxdriverproject.org, haiyangz@microsoft.com, vkuznets@redhat.com, marcelo.cerri@canonical.com Subject: [PATCH v3 2/2] PCI: hv: Refactor hv_irq_unmask() to use cpumask_to_vpset() Message-ID: <00e13af711510001e589c7b1ddd75beb99f58db5.1548745212.git.m.maya.nakamura@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Remove the duplicate implementation of cpumask_to_vpset() and use the shared implementation. Export hv_max_vp_index, which is required by cpumask_to_vpset(). Apply changes to hv_irq_unmask() based on feedback. Signed-off-by: Maya Nakamura --- Changes in v3: - Modify to catch all failures from cpumask_to_vpset(). - Correct the v2 change log about the commit message. Changes in v2: - Remove unnecessary nr_bank initialization. - Delete two unnecessary dev_err()'s. - Unlock before returning. - Update the commit message. arch/x86/hyperv/hv_init.c | 1 + drivers/pci/controller/pci-hyperv.c | 38 +++++++++++++---------------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index 7abb09e2eeb8..7f2eed1fc81b 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -96,6 +96,7 @@ void __percpu **hyperv_pcpu_input_arg; EXPORT_SYMBOL_GPL(hyperv_pcpu_input_arg); u32 hv_max_vp_index; +EXPORT_SYMBOL_GPL(hv_max_vp_index); static int hv_cpu_init(unsigned int cpu) { diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index da8b58d8630d..a78def332bbc 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -391,8 +391,6 @@ struct hv_interrupt_entry { u32 data; }; -#define HV_VP_SET_BANK_COUNT_MAX 5 /* current implementation limit */ - /* * flags for hv_device_interrupt_target.flags */ @@ -908,12 +906,12 @@ static void hv_irq_unmask(struct irq_data *data) struct retarget_msi_interrupt *params; struct hv_pcibus_device *hbus; struct cpumask *dest; + cpumask_var_t tmp; struct pci_bus *pbus; struct pci_dev *pdev; unsigned long flags; u32 var_size = 0; - int cpu_vmbus; - int cpu; + int cpu, nr_bank; u64 res; dest = irq_data_get_effective_affinity_mask(data); @@ -953,29 +951,27 @@ static void hv_irq_unmask(struct irq_data *data) */ params->int_target.flags |= HV_DEVICE_INTERRUPT_TARGET_PROCESSOR_SET; - params->int_target.vp_set.valid_bank_mask = - (1ull << HV_VP_SET_BANK_COUNT_MAX) - 1; + + if (!alloc_cpumask_var(&tmp, GFP_KERNEL)) { + res = 1; + goto exit_unlock; + } + + cpumask_and(tmp, dest, cpu_online_mask); + nr_bank = cpumask_to_vpset(¶ms->int_target.vp_set, tmp); + free_cpumask_var(tmp); + + if (nr_bank <= 0) { + res = 1; + goto exit_unlock; + } /* * var-sized hypercall, var-size starts after vp_mask (thus * vp_set.format does not count, but vp_set.valid_bank_mask * does). */ - var_size = 1 + HV_VP_SET_BANK_COUNT_MAX; - - for_each_cpu_and(cpu, dest, cpu_online_mask) { - cpu_vmbus = hv_cpu_number_to_vp_number(cpu); - - if (cpu_vmbus >= HV_VP_SET_BANK_COUNT_MAX * 64) { - dev_err(&hbus->hdev->device, - "too high CPU %d", cpu_vmbus); - res = 1; - goto exit_unlock; - } - - params->int_target.vp_set.bank_contents[cpu_vmbus / 64] |= - (1ULL << (cpu_vmbus & 63)); - } + var_size = 1 + nr_bank; } else { for_each_cpu_and(cpu, dest, cpu_online_mask) { params->int_target.vp_mask |=