From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5756A20E701 for ; Fri, 10 Jan 2025 14:02:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736517735; cv=none; b=srA7AeNOptV6/z6oNUKsXwathneylKjSq8AMVriB4RMW9febAYwu5O+eEgNiU9uI4/aiG5smvirFPAQCk73tH3E7sU5+TZwymfc353awcyW/bd0FPC5KFH8lZsuSU7Sy7mFmzmZfn//n/Z6uqwS4Ljo4agIvviJa92SLwwb/Yc0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736517735; c=relaxed/simple; bh=Ah5H5zTDfKEUJA5hN6gL6kPiwPZimlV1CUvKlAMoa08=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nKyBUp9qlfUn7Cc0U+16CyDvTN+A1YZrCITNUbkaqqvj6PXykS2ps+yT+y5mm9c3G6jFnPEve4RB+0yxLNPVPsIFV0sM7vsgT0lxk7TtPq8NygVOWSUDZt8343XL4KWvtCYY8UGUA7sePQ37S5VVcmG5ML9IaFdPPpoS8wIhMSU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=citrix.com; spf=pass smtp.mailfrom=cloud.com; dkim=pass (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b=OGMEkT7P; arc=none smtp.client-ip=209.85.208.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=citrix.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cloud.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="OGMEkT7P" Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-5d3ecae02beso2716930a12.0 for ; Fri, 10 Jan 2025 06:02:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1736517731; x=1737122531; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QOPaP/mU6vt7fi9w+3JVCzGSZ59QyAsOxxCexGJ2z2A=; b=OGMEkT7PExzYhr/JwHtma1WrKqhX9y4wY3EbDVJsmU/ZXVM9l+XUi2L+dGAlVfL/rA 7hNupQpyuhbhf63M/RCJcknp7pOWHaKhHBsbfwak90svDXM1DhP4FAargfzwS3fiGSQS MohqbejbJDJeGbsH+gqCtG4L5XKu/kbYoKhRA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736517731; x=1737122531; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QOPaP/mU6vt7fi9w+3JVCzGSZ59QyAsOxxCexGJ2z2A=; b=RT6h7LsYbhJjBkZchNS8GGgqV+iuA+RjQK1NFpFAUYsQv+TOb6CSKlmMHZR2spI3tQ BPOrJKL4xz5hZmVYaaHpPFyMkvKWZJlyFAMysGkfjrLAoXmoWgBOSVsLsSi8kLbh1ARD IM5ciPuvFWwXzoaSXhJeTOFukpTjUcZvLtxMhawVmqbOIsn+0upzHHFH+isPSB0crJPA Pe97LANc59KP6wksjPL+FZMnKVLGMg8VDgLB0o4TQ3fLYHxvb9sj7o5K/tlDuHBYiOuB FIIvnSYSrQSY9D5h7kwGAeA4Scrrkk4xz2dxtVGSbntGooKcQKvNBA/jN1NVyIrVdqmq glRg== X-Gm-Message-State: AOJu0Yx8Oeuac0FJpQ2qI5kDreREj7HAoAwfTDMvYy1z9D3b0HF+etHj MUWrGnTZfsisfyh8H6NzQa4Bc+q8LXAdiUt8bgQC7DMktwAEZy4F9WxthBwC1oPUOh32pHSq7b8 t X-Gm-Gg: ASbGncsfoFc5DhTn0X9D7pgJDy+H/rEjA+Y++6Pa1N71wbEXXaLrgbtQZS1XiwwFgyO Sjc7mfd/CtZ80aCP1tDlTBHpnCAcgEf/yYDxCd039ELbzJc7LUYcImyU3IWovkmansH8SV9tv+H ZT8IJoSByxw3zhLsFTs1V3hVEz92h6pKUtCCmmChJDW6wPDf0sS9TIdDbOSjbTcGfDMGLGjgp0r IXAZnT6OaX56h2Wnw2f3FRC5zWSyiKLJEbEY4SUjpU0EnSXDM2Zihot+yIcB9FCyuA= X-Google-Smtp-Source: AGHT+IHwiF6pZdggWtSRTr6pLMwM8np6twiqSyLvaaV8RNsdWeIBSWUdDT3itr1SN8CI6AcxoSrZBQ== X-Received: by 2002:a17:907:94c8:b0:aaf:7321:f05a with SMTP id a640c23a62f3a-ab2abc6e773mr980949866b.46.1736517717515; Fri, 10 Jan 2025 06:01:57 -0800 (PST) Received: from localhost ([84.78.159.3]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab2c9645408sm167312266b.166.2025.01.10.06.01.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jan 2025 06:01:56 -0800 (PST) From: Roger Pau Monne To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko Subject: [PATCH 1/3] xen/pci: do not register devices outside of PCI segment scope Date: Fri, 10 Jan 2025 15:01:48 +0100 Message-ID: <20250110140152.27624-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20250110140152.27624-1-roger.pau@citrix.com> References: <20250110140152.27624-1-roger.pau@citrix.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The PCI segment value is limited to 16 bits, however there are buses like VMD that fake being part of the PCI topology by adding segment with a number outside the scope of the PCI firmware specification range (>= 0x10000). The MCFG ACPI Table "PCI Segment Group Number" field is defined as having a 16 bit width. Attempting to register or manage those devices with Xen would result in errors at best, or overlaps with existing devices living on the truncated equivalent segment values. Skip notifying Xen about those devices. Signed-off-by: Roger Pau Monné --- drivers/xen/pci.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/xen/pci.c b/drivers/xen/pci.c index 416f231809cb..08e82fd1263e 100644 --- a/drivers/xen/pci.c +++ b/drivers/xen/pci.c @@ -43,6 +43,13 @@ static int xen_add_device(struct device *dev) pci_mcfg_reserved = true; } #endif + + if (pci_domain_nr(pci_dev->bus) >> 16) { + dev_info(dev, + "not registering with Xen: invalid PCI segment\n"); + return 0; + } + if (pci_seg_supported) { DEFINE_RAW_FLEX(struct physdev_pci_device_add, add, optarr, 1); @@ -149,6 +156,12 @@ static int xen_remove_device(struct device *dev) int r; struct pci_dev *pci_dev = to_pci_dev(dev); + if (pci_domain_nr(pci_dev->bus) >> 16) { + dev_info(dev, + "not unregistering with Xen: invalid PCI segment\n"); + return 0; + } + if (pci_seg_supported) { struct physdev_pci_device device = { .seg = pci_domain_nr(pci_dev->bus), @@ -182,6 +195,12 @@ int xen_reset_device(const struct pci_dev *dev) .flags = PCI_DEVICE_RESET_FLR, }; + if (pci_domain_nr(dev->bus) >> 16) { + dev_info(&dev->dev, + "unable to notify Xen of device reset: invalid PCI segment\n"); + return 0; + } + return HYPERVISOR_physdev_op(PHYSDEVOP_pci_device_reset, &device); } EXPORT_SYMBOL_GPL(xen_reset_device); -- 2.46.0