From patchwork Sun Apr 26 20:46:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 1277235 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 499Kj80V36z9sSb; Mon, 27 Apr 2020 06:47:24 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1jSoBK-0004DQ-GD; Sun, 26 Apr 2020 20:47:18 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jSoAg-0003mM-Ib for kernel-team@lists.ubuntu.com; Sun, 26 Apr 2020 20:46:38 +0000 Received: from mail-qt1-f200.google.com ([209.85.160.200]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jSoAc-0001fW-KJ for kernel-team@lists.ubuntu.com; Sun, 26 Apr 2020 20:46:34 +0000 Received: by mail-qt1-f200.google.com with SMTP id g8so18147078qtq.2 for ; Sun, 26 Apr 2020 13:46:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+Hyw/KSb1lH/Umun15P3MKOE2mIAKmJk/o5sFYgLxwI=; b=IlW+nldS27e8l2EPVaHkXjwK4EWeW27k+LYv1FoSMhEJ6sEt0NaIEeX7vbj9Arl9HB hw+lmDSBf3KnukWdpMh3bPYMwcVkdiW5up9lPHHhuSmm4BbE1I8OfHG/akv01t/0zmsZ qd2VDqsEMcxkgvXfTUx7ErqN+84YG/3Rh6BWoQdd9Bvl2A4eR9z6irbTHsItQOMxDuTt U9726R5BL9SiYAqkt4egHHNmT9t3YULjRx6j+PqHYOMwDW7l4H2gQtNgmSrdkKS3HNFu c9bzNHFTN+AZ4RmjjT0H6EypKQEo2eGMDBBtNqkSabAuD7TwskC4zEO9/zvMhywBCQpS dWVg== X-Gm-Message-State: AGi0PuZvTXmuEqP7WJUOVSNkQR+/HhIWahZtvVeM+trQryxilA6fJITM qEc2Pn+GWmeLee9hexPNgw4vtNKvHOlnzS9TZeOH+kBBzX8wJk7Wm56It/d1GFUh+r8YbItZzK0 OTV44II4pYGmSTrOyVnUkHOOv8eh7jSd/niPzeooD X-Received: by 2002:a0c:c190:: with SMTP id n16mr19819838qvh.107.1587933993321; Sun, 26 Apr 2020 13:46:33 -0700 (PDT) X-Google-Smtp-Source: APiQypIN5LcFz64DVKF82ID7V99xbyg/5uAUzjgseDDJ6PK/Z32wqA30rhdmHemgyNSETRFleqIJ/A== X-Received: by 2002:a0c:c190:: with SMTP id n16mr19819825qvh.107.1587933992992; Sun, 26 Apr 2020 13:46:32 -0700 (PDT) Received: from gallifrey.lan ([201.82.186.200]) by smtp.gmail.com with ESMTPSA id h63sm8261654qkd.49.2020.04.26.13.46.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Apr 2020 13:46:32 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [eoan:linux-azure][PATCH 1/4] Revert "UBUNTU: SAUCE: pci-hyperv: Use only 16 bit integer for PCI domain" Date: Sun, 26 Apr 2020 17:46:24 -0300 Message-Id: <20200426204627.121419-2-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200426204627.121419-1-marcelo.cerri@canonical.com> References: <20200426203646.115503-1-marcelo.cerri@canonical.com> <20200426204627.121419-1-marcelo.cerri@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" BugLink: https://bugs.launchpad.net/bugs/1867220 This reverts commit 5106ea7eace25bac7add4da0940431439f06cdd7. Signed-off-by: Marcelo Henrique Cerri --- drivers/pci/controller/pci-hyperv.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index 2c6a82a41d5c..8a30c1693699 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -1630,11 +1630,9 @@ static struct hv_pci_dev *new_pcichild_device(struct hv_pcibus_device *hbus, * can have shorter names than based on the bus instance UUID. * Only the first device serial number is used for domain, so the * domain number will not change after the first device is added. - * The lower 16 bits of the serial number is used, otherwise some - * drivers may not be able to handle it. */ if (list_empty(&hbus->children)) - hbus->sysdata.domain = desc->ser & 0xFFFF; + hbus->sysdata.domain = desc->ser; list_add_tail(&hpdev->list_entry, &hbus->children); spin_unlock_irqrestore(&hbus->device_list_lock, flags); return hpdev; From patchwork Sun Apr 26 20:46:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 1277236 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 499Kj95YGcz9sRY; Mon, 27 Apr 2020 06:47:25 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1jSoBM-0004Ed-BA; Sun, 26 Apr 2020 20:47:20 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jSoAj-0003nV-4T for kernel-team@lists.ubuntu.com; Sun, 26 Apr 2020 20:46:41 +0000 Received: from mail-qk1-f198.google.com ([209.85.222.198]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jSoAe-0001fb-La for kernel-team@lists.ubuntu.com; Sun, 26 Apr 2020 20:46:36 +0000 Received: by mail-qk1-f198.google.com with SMTP id d15so17361687qkg.1 for ; Sun, 26 Apr 2020 13:46:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lEfBZrs45IRzNqXIhT1mTGowPLwy/XatgES3C4rr48c=; b=TFO9bKpjeJ+nXbvqEVX0xhb6WY4TlGCksk2MBHtShm8qfOaM6Z2bvv34Jjgbzdw85q YgTKx3yAud0iPic1S31x4BtImjEvmCr7I0z3jOh386JZXFxN2MA697k1XMJ3FKhUzZQ8 zXksP5jsDZT2T7FXVohM1f/xhZOh0WKnOW/83qAox/ueHzU794+kiDjKp08pU+jh6R+D Y5KUX6P4wCE6mSTWUd8BIqOGmVv2j4ve2nJcd3RWreDeJg1cF3Mkz9pLrF0LBTA23T2X 1pImZ/6k4x3qKgbillulYFR1cgF/aJxg3yRAcaguFh3DGL/kpQgMXedBCsKA3IznRrsM R4fw== X-Gm-Message-State: AGi0PuZRBf1EPRLJGtm2Z5C9JP3H4VaqIMQKwPPHwsgt/HAY/q1p+C3K QJOV6RCkfCWTS4pxtuCziZJIrNWc+AZ8/xmrdQTs50VikfkX5YaHK0pfzGF5SUzk/mNQOvwX/ph W72NnmC+a5G3ZaIUIJjHmgVWRzdhx2tJLM6wqPemG X-Received: by 2002:a37:b183:: with SMTP id a125mr18870259qkf.199.1587933995330; Sun, 26 Apr 2020 13:46:35 -0700 (PDT) X-Google-Smtp-Source: APiQypIS2XwWz2j82MAR+KgNbUxFNVkCSKN5Re0H+oyl1RFVZNd3hk+3hskusO/guOZWWw4ZczrHvQ== X-Received: by 2002:a37:b183:: with SMTP id a125mr18870249qkf.199.1587933995031; Sun, 26 Apr 2020 13:46:35 -0700 (PDT) Received: from gallifrey.lan ([201.82.186.200]) by smtp.gmail.com with ESMTPSA id h63sm8261654qkd.49.2020.04.26.13.46.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Apr 2020 13:46:34 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [eoan:linux-azure][PATCH 2/4] Revert "Revert "PCI: hv: Make sure the bus domain is really unique"" Date: Sun, 26 Apr 2020 17:46:25 -0300 Message-Id: <20200426204627.121419-3-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200426204627.121419-1-marcelo.cerri@canonical.com> References: <20200426203646.115503-1-marcelo.cerri@canonical.com> <20200426204627.121419-1-marcelo.cerri@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" BugLink: https://bugs.launchpad.net/bugs/1867220 This reverts commit cd2b8908303d2a64a4a438049f3636cdb648f32c. Signed-off-by: Marcelo Henrique Cerri --- drivers/pci/controller/pci-hyperv.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index 8a30c1693699..2b53976cd9f9 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -1622,17 +1622,6 @@ static struct hv_pci_dev *new_pcichild_device(struct hv_pcibus_device *hbus, get_pcichild(hpdev); spin_lock_irqsave(&hbus->device_list_lock, flags); - /* - * When a device is being added to the bus, we set the PCI domain - * number to be the device serial number, which is non-zero and - * unique on the same VM. The serial numbers start with 1, and - * increase by 1 for each device. So device names including this - * can have shorter names than based on the bus instance UUID. - * Only the first device serial number is used for domain, so the - * domain number will not change after the first device is added. - */ - if (list_empty(&hbus->children)) - hbus->sysdata.domain = desc->ser; list_add_tail(&hpdev->list_entry, &hbus->children); spin_unlock_irqrestore(&hbus->device_list_lock, flags); return hpdev; From patchwork Sun Apr 26 20:46:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 1277238 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 499KjP0kZjz9sRY; Mon, 27 Apr 2020 06:47:37 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1jSoBX-0004Mb-3v; Sun, 26 Apr 2020 20:47:31 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jSoAk-0003oG-Q6 for kernel-team@lists.ubuntu.com; Sun, 26 Apr 2020 20:46:43 +0000 Received: from mail-qv1-f71.google.com ([209.85.219.71]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jSoAg-0001ff-U2 for kernel-team@lists.ubuntu.com; Sun, 26 Apr 2020 20:46:39 +0000 Received: by mail-qv1-f71.google.com with SMTP id z14so16343495qvv.6 for ; Sun, 26 Apr 2020 13:46:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hZ2lav/mNRJB0V0sD5MU0rzpk7BYj+bc6w+P6rIWMCQ=; b=k6MUMzsEvMfBcojM/he8EPi3kYggj0y73Mp+zblkY6kwgRe2bzbBDIAZPaqhg9IPRg oKRAeaMQrOv5AfIR+6Om42SU7RmUPGiqJ9CO9+Nqein+/7PuBEwt+VF5fIVHnBNYW6HX 2VRgGjcVZalByEKbXZy8+s9+sO/9t5QBHQmgJrbmPy2ryj7oSs3KLsyLhlCpU+ctYUF8 ultOZj50geyQ3kjP5T1/mCQ9yB6Lwbn0TSCXd3lheEUmBbLoZiYWv4Wbk+V4ZWfiGdr/ DDMGkJn8bpXOW4Y9jSRkub3WvwqH4F/5MRdWkQxQn8TmaCeFrfTRmyTYrqmv3x1U3ptt rv0Q== X-Gm-Message-State: AGi0PuZUXfMkgoB44Vxyjl92vo519c/AR+u5D6JDqqMc3Q7KWy7X/G3h pvPKi0sQKbS83Z2BypVPngsM+ci+tqy668oS2wxloVgkTQp33yWl+b1qtA42PMlF2BKo9HqJiwF oBd1bYmM+4JFo3TeOOUq0KkkPtpQ84HlVtqVKVzfQ X-Received: by 2002:ad4:45ec:: with SMTP id q12mr19508825qvu.157.1587933997484; Sun, 26 Apr 2020 13:46:37 -0700 (PDT) X-Google-Smtp-Source: APiQypIzbu2ZEWB/CL3l0lCjZ1RrWd9qjm3qoEitUl8a0cJjvPxu8jnls3C0KSzUJWhrAKMeezJWQg== X-Received: by 2002:ad4:45ec:: with SMTP id q12mr19508809qvu.157.1587933997078; Sun, 26 Apr 2020 13:46:37 -0700 (PDT) Received: from gallifrey.lan ([201.82.186.200]) by smtp.gmail.com with ESMTPSA id h63sm8261654qkd.49.2020.04.26.13.46.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Apr 2020 13:46:36 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [eoan:linux-azure][PATCH 3/4] PCI: hv: Detect and fix Hyper-V PCI domain number collision Date: Sun, 26 Apr 2020 17:46:26 -0300 Message-Id: <20200426204627.121419-4-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200426204627.121419-1-marcelo.cerri@canonical.com> References: <20200426203646.115503-1-marcelo.cerri@canonical.com> <20200426204627.121419-1-marcelo.cerri@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Haiyang Zhang BugLink: https://bugs.launchpad.net/bugs/1867220 Currently in Azure cloud, for passthrough devices, the host sets the device instance ID's bytes 8 - 15 to a value derived from the host HWID, which is the same on all devices in a VM. So, the device instance ID's bytes 8 and 9 provided by the host are no longer unique. This affects all Azure hosts since July 2018, and can cause device passthrough to VMs to fail because the bytes 8 and 9 are used as PCI domain number. Collision of domain numbers will cause the second device with the same domain number fail to load. In the cases of collision, we will detect and find another number that is not in use. Suggested-by: Michael Kelley Signed-off-by: Haiyang Zhang Signed-off-by: Lorenzo Pieralisi Acked-by: Sasha Levin (cherry picked from commit be700103efd1050808db1cf00e52c3a2837bf802) Signed-off-by: Marcelo Henrique Cerri --- drivers/pci/controller/pci-hyperv.c | 92 +++++++++++++++++++++++++---- 1 file changed, 79 insertions(+), 13 deletions(-) diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index 2b53976cd9f9..4caa3388692a 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -2510,6 +2510,48 @@ static void put_hvpcibus(struct hv_pcibus_device *hbus) complete(&hbus->remove_event); } +#define HVPCI_DOM_MAP_SIZE (64 * 1024) +static DECLARE_BITMAP(hvpci_dom_map, HVPCI_DOM_MAP_SIZE); + +/* + * PCI domain number 0 is used by emulated devices on Gen1 VMs, so define 0 + * as invalid for passthrough PCI devices of this driver. + */ +#define HVPCI_DOM_INVALID 0 + +/** + * hv_get_dom_num() - Get a valid PCI domain number + * Check if the PCI domain number is in use, and return another number if + * it is in use. + * + * @dom: Requested domain number + * + * return: domain number on success, HVPCI_DOM_INVALID on failure + */ +static u16 hv_get_dom_num(u16 dom) +{ + unsigned int i; + + if (test_and_set_bit(dom, hvpci_dom_map) == 0) + return dom; + + for_each_clear_bit(i, hvpci_dom_map, HVPCI_DOM_MAP_SIZE) { + if (test_and_set_bit(i, hvpci_dom_map) == 0) + return i; + } + + return HVPCI_DOM_INVALID; +} + +/** + * hv_put_dom_num() - Mark the PCI domain number as free + * @dom: Domain number to be freed + */ +static void hv_put_dom_num(u16 dom) +{ + clear_bit(dom, hvpci_dom_map); +} + /** * hv_pci_probe() - New VMBus channel probe, for a root PCI bus * @hdev: VMBus's tracking struct for this root PCI bus @@ -2521,6 +2563,7 @@ static int hv_pci_probe(struct hv_device *hdev, const struct hv_vmbus_device_id *dev_id) { struct hv_pcibus_device *hbus; + u16 dom_req, dom; int ret; /* @@ -2535,19 +2578,34 @@ static int hv_pci_probe(struct hv_device *hdev, hbus->state = hv_pcibus_init; /* - * The PCI bus "domain" is what is called "segment" in ACPI and - * other specs. Pull it from the instance ID, to get something - * unique. Bytes 8 and 9 are what is used in Windows guests, so - * do the same thing for consistency. Note that, since this code - * only runs in a Hyper-V VM, Hyper-V can (and does) guarantee - * that (1) the only domain in use for something that looks like - * a physical PCI bus (which is actually emulated by the - * hypervisor) is domain 0 and (2) there will be no overlap - * between domains derived from these instance IDs in the same - * VM. + * The PCI bus "domain" is what is called "segment" in ACPI and other + * specs. Pull it from the instance ID, to get something usually + * unique. In rare cases of collision, we will find out another number + * not in use. + * + * Note that, since this code only runs in a Hyper-V VM, Hyper-V + * together with this guest driver can guarantee that (1) The only + * domain used by Gen1 VMs for something that looks like a physical + * PCI bus (which is actually emulated by the hypervisor) is domain 0. + * (2) There will be no overlap between domains (after fixing possible + * collisions) in the same VM. */ - hbus->sysdata.domain = hdev->dev_instance.b[9] | - hdev->dev_instance.b[8] << 8; + dom_req = hdev->dev_instance.b[8] << 8 | hdev->dev_instance.b[9]; + dom = hv_get_dom_num(dom_req); + + if (dom == HVPCI_DOM_INVALID) { + dev_err(&hdev->device, + "Unable to use dom# 0x%hx or other numbers", dom_req); + ret = -EINVAL; + goto free_bus; + } + + if (dom != dom_req) + dev_info(&hdev->device, + "PCI dom# 0x%hx has collision, using 0x%hx", + dom_req, dom); + + hbus->sysdata.domain = dom; hbus->hdev = hdev; refcount_set(&hbus->remove_lock, 1); @@ -2562,7 +2620,7 @@ static int hv_pci_probe(struct hv_device *hdev, hbus->sysdata.domain); if (!hbus->wq) { ret = -ENOMEM; - goto free_bus; + goto free_dom; } ret = vmbus_open(hdev->channel, pci_ring_size, pci_ring_size, NULL, 0, @@ -2639,6 +2697,8 @@ static int hv_pci_probe(struct hv_device *hdev, vmbus_close(hdev->channel); destroy_wq: destroy_workqueue(hbus->wq); +free_dom: + hv_put_dom_num(hbus->sysdata.domain); free_bus: free_page((unsigned long)hbus); return ret; @@ -2720,6 +2780,9 @@ static int hv_pci_remove(struct hv_device *hdev) put_hvpcibus(hbus); wait_for_completion(&hbus->remove_event); destroy_workqueue(hbus->wq); + + hv_put_dom_num(hbus->sysdata.domain); + free_page((unsigned long)hbus); return 0; } @@ -2747,6 +2810,9 @@ static void __exit exit_hv_pci_drv(void) static int __init init_hv_pci_drv(void) { + /* Set the invalid domain number's bit, so it will not be used */ + set_bit(HVPCI_DOM_INVALID, hvpci_dom_map); + return vmbus_driver_register(&hv_pci_drv); } From patchwork Sun Apr 26 20:46:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Henrique Cerri X-Patchwork-Id: 1277237 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 499KjG4xQLz9sRY; Mon, 27 Apr 2020 06:47:30 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1jSoBQ-0004Hd-7v; Sun, 26 Apr 2020 20:47:24 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jSoAo-0003on-6C for kernel-team@lists.ubuntu.com; Sun, 26 Apr 2020 20:46:46 +0000 Received: from mail-qk1-f198.google.com ([209.85.222.198]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jSoAi-0001fn-UB for kernel-team@lists.ubuntu.com; Sun, 26 Apr 2020 20:46:41 +0000 Received: by mail-qk1-f198.google.com with SMTP id x5so17292512qkn.20 for ; Sun, 26 Apr 2020 13:46:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OsztqKkZWFNwe+tVlfV54VMWJoHdb/zThSnirR9xnZY=; b=IxiEehRWN4JH6h0yGN12b40g49jnEapD7FRjVdoN6tf1zg5AVgUICks4nltr85fd0T f2Fut1a4tj7V8z9vuvhABOcAtJTaXC/8Z5XhpkxdVfCzIL7OdT6qeYYhb0+cOnUWMaU8 Fi28IQEFX3red6O9KlnnGC/JCyvswljM0t0a2UyIumNszRv54jrnO54qHQHb7sG1YO2b QbLWrQR/pM3bTLIY4PW++RUtmdMU4JF6s71Wz8SYGlsB6sAc1WhumsyOzmiJWt25Xasp JcKMHmmA24DBPfk9tnWR1GvxQDUosgpPcaz88csuYKdgwQcpYRbJoQCtrkFASxfRc6Iy WrYA== X-Gm-Message-State: AGi0PuadH/zd7TMo5LdQh4yQWxUOAbbsP5OQB5uYVj3SrA+RFrt6vvDk bQhI1QNGjnJnRkaByCS53ue5L1/2Fo/GsSrlOyrwwiITMOavQs5Pl3Gb+yrf1nqktKBaME/S0d0 IewubQoiu8yiVXiPvw8XAfu/OOrSpymNF3Razt3Sr X-Received: by 2002:a37:9d0d:: with SMTP id g13mr18174699qke.350.1587933999499; Sun, 26 Apr 2020 13:46:39 -0700 (PDT) X-Google-Smtp-Source: APiQypI/Z7/u7+TqKE9LlHKk3Lrf1zf4VjN1ZfpDIvHx9SAr4LTLKIcDN4lHmEo8XR69Di+jASQ/TA== X-Received: by 2002:a37:9d0d:: with SMTP id g13mr18174681qke.350.1587933999043; Sun, 26 Apr 2020 13:46:39 -0700 (PDT) Received: from gallifrey.lan ([201.82.186.200]) by smtp.gmail.com with ESMTPSA id h63sm8261654qkd.49.2020.04.26.13.46.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Apr 2020 13:46:38 -0700 (PDT) From: Marcelo Henrique Cerri To: kernel-team@lists.ubuntu.com Subject: [eoan:linux-azure][PATCH 4/4] PCI: hv: Use bytes 4 and 5 from instance ID as the PCI domain numbers Date: Sun, 26 Apr 2020 17:46:27 -0300 Message-Id: <20200426204627.121419-5-marcelo.cerri@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200426204627.121419-1-marcelo.cerri@canonical.com> References: <20200426203646.115503-1-marcelo.cerri@canonical.com> <20200426204627.121419-1-marcelo.cerri@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Haiyang Zhang BugLink: https://bugs.launchpad.net/bugs/1867220 As recommended by Azure host team, the bytes 4, 5 have more uniqueness (info entropy) than bytes 8, 9 so use them as the PCI domain numbers. On older hosts, bytes 4, 5 can also be used -- no backward compatibility issues are introduced and the chance of collision is greatly reduced. In the rare cases of collision, the driver code detects and finds another number that is not in use. Suggested-by: Michael Kelley Signed-off-by: Haiyang Zhang Signed-off-by: Lorenzo Pieralisi Acked-by: Sasha Levin (cherry picked from commit f73f8a504e27959576a2f4d85182202561e426f2) Signed-off-by: Marcelo Henrique Cerri --- drivers/pci/controller/pci-hyperv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c index 4caa3388692a..3a56de6b2ec2 100644 --- a/drivers/pci/controller/pci-hyperv.c +++ b/drivers/pci/controller/pci-hyperv.c @@ -2590,7 +2590,7 @@ static int hv_pci_probe(struct hv_device *hdev, * (2) There will be no overlap between domains (after fixing possible * collisions) in the same VM. */ - dom_req = hdev->dev_instance.b[8] << 8 | hdev->dev_instance.b[9]; + dom_req = hdev->dev_instance.b[5] << 8 | hdev->dev_instance.b[4]; dom = hv_get_dom_num(dom_req); if (dom == HVPCI_DOM_INVALID) {