Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1196701pxb; Fri, 21 Jan 2022 12:02:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJw7xEliEcVmC4yDJ6ksxb2SRrUCU78VHQyazLQj3+HhMk7Oarqz6OHpJOSPHL3oFNi68nUI X-Received: by 2002:a17:902:c144:b0:14b:7f:b23b with SMTP id 4-20020a170902c14400b0014b007fb23bmr5455935plj.86.1642795329580; Fri, 21 Jan 2022 12:02:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642795329; cv=none; d=google.com; s=arc-20160816; b=Zbqi3u78hcGFBzumksLY27mouRo76D3Uc7sNDSlTQEza8ln1J5fQ1tNnC/XaRGzQgs xCr8KmZzDiicfO86DSKWOV1juegVLWhaIss4suGjkyaJomzjjNY4uYcM7SQy15JmCAoA +Aq79snOsBUDHW7oSyCZ5Lny0WSi8zUb21grviy0VbiJPXQkeTsIHyz9rezPl9DByT3F A9WWtmv/uvFYw8JkECZulcsQvr50ymZARIrxhG49tgFQyl35NPyGvXTxH2wkMjNnG/At xrA0S9eiryhtWQHnaxPpU9/JO2PCqehEUvK0w0fwMRXYCNq1dWfiacLKkKz0tw62RuWk A0eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=TD73FcumVjwPMYsmdCD93SR7TD3EAZF9X2RVmwm/lbs=; b=iyRCcnfPPpC9G1+vebXqxXUundbjGGyUZC+p1fmvqkzE7Aem+LVuT8m32p0mLje24o HY+uoI78x6uva+QVycHUMrPADP8S0DfixOvC7kZSXX2dVm7JAr8Xr8y5IUZWVchsZ11F TngzKCdheoq1urEN+A60YxkgsjBUkjzVzb4uoNdkiboNub+2otnRtfHRZiTUgzf1Z31w Hsn7H/OdczfgAEukQPaVm8h8IpApF5yH9wcuNREyLEkHhWiTmLFb+MK41SpsX0S6z21X dHp9a/rDrflcyCobvdFRllOWKD1BND05PRbLXf2O1XarrgH9eOkMcGlqByztLkFC2etD uWZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxonhyperv.com header.s=default header.b=eBvUCcyv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxonhyperv.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l10si6924028pfu.243.2022.01.21.12.01.57; Fri, 21 Jan 2022 12:02:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxonhyperv.com header.s=default header.b=eBvUCcyv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxonhyperv.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244175AbiAST7P (ORCPT + 99 others); Wed, 19 Jan 2022 14:59:15 -0500 Received: from linux.microsoft.com ([13.77.154.182]:36944 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233089AbiAST7O (ORCPT ); Wed, 19 Jan 2022 14:59:14 -0500 Received: by linux.microsoft.com (Postfix, from userid 1004) id 17C9120B928C; Wed, 19 Jan 2022 11:59:14 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 17C9120B928C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxonhyperv.com; s=default; t=1642622354; bh=TD73FcumVjwPMYsmdCD93SR7TD3EAZF9X2RVmwm/lbs=; h=From:To:Cc:Subject:Date:From; b=eBvUCcyv6tq41PGYBlI74LOyTjvHHTYpcxewTdJK7b/PCtWXhy9pmiMzl8ZMksVL6 FjxzZ+Y96/psPocglPaicK6+Fuh5qfkiyliSiGTQLgbFzbsZHuwY+LadvtPy4WLx92 1r/PCsusCwUZkRTUYcuR83CpwzFVIwQ2kPVMOovQ= From: longli@linuxonhyperv.com To: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, paekkaladevi@microsoft.com Cc: Long Li Subject: [Patch v3] PCI: hv: Fix NUMA node assignment when kernel boots with custom NUMA topology Date: Wed, 19 Jan 2022 11:59:06 -0800 Message-Id: <1642622346-22861-1-git-send-email-longli@linuxonhyperv.com> X-Mailer: git-send-email 1.8.3.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Long Li When kernel boots with a NUMA topology with some NUMA nodes offline, the PCI driver should only set an online NUMA node on the device. This can happen during KDUMP where some NUMA nodes are not made online by the KDUMP kernel. This patch also fixes the case where kernel is booting with "numa=off". Fixes: 999dd956d838 ("PCI: hv: Add support for protocol 1.3 and support PCI_BUS_RELATIONS2") Signed-off-by: Long Li Change log: v2: use numa_map_to_online_node() to assign a node to device (suggested by Michael Kelly ) v3: add "Fixes" and check for num_possible_nodes() --- drivers/pci/controller/pci-hyperv.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index 6c9efeefae1b..b5276e81bb44 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -2129,8 +2129,17 @@ static void hv_pci_assign_numa_node(struct hv_pcibus_device *hbus) if (!hv_dev) continue; - if (hv_dev->desc.flags & HV_PCI_DEVICE_FLAG_NUMA_AFFINITY) - set_dev_node(&dev->dev, hv_dev->desc.virtual_numa_node); + if (hv_dev->desc.flags & HV_PCI_DEVICE_FLAG_NUMA_AFFINITY && + hv_dev->desc.virtual_numa_node < num_possible_nodes()) + /* + * The kernel may boot with some NUMA nodes offline + * (e.g. in a KDUMP kernel) or with NUMA disabled via + * "numa=off". In those cases, adjust the host provided + * NUMA node to a valid NUMA node used by the kernel. + */ + set_dev_node(&dev->dev, + numa_map_to_online_node( + hv_dev->desc.virtual_numa_node)); put_pcichild(hv_dev); } -- 2.25.1