From patchwork Wed Feb 19 09:20:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13981794 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CCEC0C021AB for ; Wed, 19 Feb 2025 09:22:25 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.892511.1301484 (Exim 4.92) (envelope-from ) id 1tkgHZ-0008On-KW; Wed, 19 Feb 2025 09:22:17 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 892511.1301484; Wed, 19 Feb 2025 09:22:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tkgHZ-0008Og-Gv; Wed, 19 Feb 2025 09:22:17 +0000 Received: by outflank-mailman (input) for mailman id 892511; Wed, 19 Feb 2025 09:22:16 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tkgHY-00082q-Eu for xen-devel@lists.xenproject.org; Wed, 19 Feb 2025 09:22:16 +0000 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [2607:f8b0:4864:20::62c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 01d368d1-eea3-11ef-9aa8-95dc52dad729; Wed, 19 Feb 2025 10:22:15 +0100 (CET) Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-220bff984a0so116188365ad.3 for ; Wed, 19 Feb 2025 01:22:15 -0800 (PST) Received: from localhost ([84.78.159.3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d5348e68sm101300795ad.28.2025.02.19.01.22.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2025 01:22:13 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 01d368d1-eea3-11ef-9aa8-95dc52dad729 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1739956934; x=1740561734; darn=lists.xenproject.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=7ZJg6bVS4EQSvqcvYB18UYZOZ9WdLOPfmEHjgud3AfI=; b=vsFlE8k6dfFN8uEkx8rfLF+cVkGYb+3AQtDtEBe7wUq07MEPlH7fyy4rafS9xldvaS JKji4HPGSDklymQDdt9KgHtpKBNO/aMVE73jn9cGNC/ysLyoaMvsOgQSyISo/tZU5GPd Y56VMmTbBEB4WidBSp0R2lxNtsFU+73ZtQcJA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739956934; x=1740561734; 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=7ZJg6bVS4EQSvqcvYB18UYZOZ9WdLOPfmEHjgud3AfI=; b=t8h6poOyDEgfoMdRSnhhkjs77MoDFq9sq+sLp2IJPnIMJZa7gptANtSOuBIIyQILDd JCkewBA1JoJw5lQjf5T9v5fUAOG0r7SVqSv3VWF3Gl/mMkV+YvRiMUyBPGpVhVygvkVG zoF9zvRr/E3t7YNAstLytLWtxXgL9AVEhURvtRAMWnargzxw0VaBhPlTS35O/u/GEvAZ cz1kEMN0cUH1jRMsqOYx1l4Z5A6DOgJ9sKOX6Z8d3RbLGjp8YGbfJ45LW8SxdrZXQJcJ 1ws95ognKKpD7j3DG1+tmrhrsRlMUP6zzHVfo4LGH0xUkY00q3LWCGPlNG1kpN0tW97T 3MMA== X-Forwarded-Encrypted: i=1; AJvYcCVpObdthNtDMa3Kx+AGbE6izksgpvXc/AjcR7kMr1xa/MQFtLaRucsU+3xbtNb5cjJz3UzqVSmnvC0=@lists.xenproject.org X-Gm-Message-State: AOJu0YxooO+MqISSjCkshM9dLkG7CuaEsDbf5l7smBjxvVmubz8/cZqz EP6X+UK3IpE8e5KT8p6/klrz6pmvugZXSqM93/GekEQMDhR7eNFBhsNHdSZ08/8= X-Gm-Gg: ASbGnctw7Dyhzi5fErLkMCY1yeGVhpuZ8a3S6BHn/O4i5dZIw2n0gY4I9r2g0eIV7Z+ 6GXNnO9zCGd6GIdmJArCP5QO3tF/ruzyHkuVT4TKmF9dN/zXgmpzXIejQ+cTkqufFhRb2n2ikSD kxJsTD6hVjNHofjwVbXm7VGHCC3AYUEhmJW4Q/HjDE1lqlh+hvXQtdd/gpwDpo++H6Z3uM8xk+a oEHtGbDTFl7/Klt85xu0W18t6mCAbfZ303I+29G2lAKegFntcKepGGHR0BvbJtffGxImgnUr/Q2 5+VOLUlDMschQm9HHMr+ X-Google-Smtp-Source: AGHT+IH2CJE5OkGckIlv4JN5MuajJLAOUuGuc18ZFqOtmBHZImObUq5mVTJXCcZHX2k+NCDuJBVy7A== X-Received: by 2002:a17:903:41c8:b0:215:853d:38 with SMTP id d9443c01a7336-2210405d2ffmr289308605ad.25.1739956934306; Wed, 19 Feb 2025 01:22:14 -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 v3 1/3] xen/pci: Do not register devices with segments >= 0x10000 Date: Wed, 19 Feb 2025 10:20:55 +0100 Message-ID: <20250219092059.90850-2-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20250219092059.90850-1-roger.pau@citrix.com> References: <20250219092059.90850-1-roger.pau@citrix.com> MIME-Version: 1.0 The current hypercall interface for doing PCI device operations always uses a segment field that has a 16 bit width. However on Linux there are buses like VMD that hook up devices into the PCI hierarchy at segment >= 0x10000, after the maximum possible segment enumerated in ACPI. 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. Note also that the VMD segment numbers are arbitrarily assigned by the OS, and hence there would need to be some negotiation between Xen and the OS to agree on how to enumerate VMD segments and devices behind them. Skip notifying Xen about those devices. Given how VMD bridges can multiplex interrupts on behalf of devices behind them there's no need for Xen to be aware of such devices for them to be usable by Linux. Signed-off-by: Roger Pau Monné Acked-by: Juergen Gross --- Changes since v2: - Capitalize subject. - Add extra comments to note thet 16bit segments value hypercall interface limitation. Changes since v1: - Adjust commit message width to 75 columns. - Expand commit message. --- drivers/xen/pci.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/drivers/xen/pci.c b/drivers/xen/pci.c index 416f231809cb..bfe07adb3e3a 100644 --- a/drivers/xen/pci.c +++ b/drivers/xen/pci.c @@ -43,6 +43,18 @@ static int xen_add_device(struct device *dev) pci_mcfg_reserved = true; } #endif + + if (pci_domain_nr(pci_dev->bus) >> 16) { + /* + * The hypercall interface is limited to 16bit PCI segment + * values, do not attempt to register devices with Xen in + * segments greater or equal than 0x10000. + */ + 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 +161,16 @@ 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) { + /* + * The hypercall interface is limited to 16bit PCI segment + * values. + */ + 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 +204,16 @@ int xen_reset_device(const struct pci_dev *dev) .flags = PCI_DEVICE_RESET_FLR, }; + if (pci_domain_nr(dev->bus) >> 16) { + /* + * The hypercall interface is limited to 16bit PCI segment + * values. + */ + 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); From patchwork Wed Feb 19 09:20:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13981795 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A2BD7C021AA for ; Wed, 19 Feb 2025 09:22:45 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.892519.1301494 (Exim 4.92) (envelope-from ) id 1tkgHt-0000Sp-RQ; Wed, 19 Feb 2025 09:22:37 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 892519.1301494; Wed, 19 Feb 2025 09:22:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tkgHt-0000Se-Of; Wed, 19 Feb 2025 09:22:37 +0000 Received: by outflank-mailman (input) for mailman id 892519; Wed, 19 Feb 2025 09:22:36 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tkgHs-0000F4-UX for xen-devel@lists.xenproject.org; Wed, 19 Feb 2025 09:22:36 +0000 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [2607:f8b0:4864:20::62b]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 0b991080-eea3-11ef-9896-31a8f345e629; Wed, 19 Feb 2025 10:22:32 +0100 (CET) Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-21c2f1b610dso164346425ad.0 for ; Wed, 19 Feb 2025 01:22:32 -0800 (PST) Received: from localhost ([84.78.159.3]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220d545d621sm100543165ad.136.2025.02.19.01.22.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2025 01:22:30 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 0b991080-eea3-11ef-9896-31a8f345e629 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1739956951; x=1740561751; darn=lists.xenproject.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=zjpV/rOsBTZhvMzmuINLNFZE/6rbEow5DAVU2rYU1PQ=; b=XEnyaCUfIjFXll9bREoZGqfc4z9/J7rgCRy454ENM6JpQTlrvF3okEDKQAgZSVqv+S psYHHMLV/miaJ+YwNM9iypsvkxhL3mEcwpM0T/dOfWAxSy+TjzgqWRxoC50z4SG8QL72 1m5BQEi1RKKlqcYq2l2zvUvnAl7eB442M6m8U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739956951; x=1740561751; 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=zjpV/rOsBTZhvMzmuINLNFZE/6rbEow5DAVU2rYU1PQ=; b=RmITKc0LiI9e/FU/SzUUxNNI5TKEBt7BHcF7NHlr2JT/yCtTP2IEk+yljA2mO15xl/ bmXf4pUJpH2QATBsG24UUGdFyZkoSauqPrQfdOelALE6OLroRpUsLeMTjLbUluHerENT ZA+I9fHzO5a2ZMlvZgOvHRiIGAYinHOgsI6L99ps74/K1OWZhhxk2CXHrqCeZnP7ZkQ8 azFiXFrGE53Z/MTD8o+7HrqevasGXZRl2/R98bFFwsB4B1wGpVE74/BJXHFLbPyZ66n8 4+7GJH7yB0+1FBawub9JuwmZ3ZorAn+8ztTMz6xZUSPf13TECpujcjvNmzwqRTd7dbkn glCg== X-Forwarded-Encrypted: i=1; AJvYcCXmP74j4w9nq0UshI8zgPHGy1bOhwfg75wYnvbLM87SOE7CTJse5xvY7IzgkOIXNevUeQPkBShnolk=@lists.xenproject.org X-Gm-Message-State: AOJu0YwByYsLaiTcoaterswnKsX+hZiONmfvx3yqsfx7B1hvu2wGQU1t Y/j8x/hE4h+lhmVHQg3paosIiFMmMt0iZJvh57ob/2C3N+/hyAulaT5/GcUbsHc= X-Gm-Gg: ASbGncu6D1hSpitAvSkdYtmQ1E4JO8O+Cq0wZLzZdOojhxXVPjDEsnOlVsaQIlwJc0P mJQPP1TO1IrbY8Y4JpMxMS8/OpGKSqbaZSPPkxgQZWaT07i1raO4Cv2Y8CPa0wm6U3mGRJpRh9W WZEgKPuQToe4ALvAQEwULb/M63RvYqXQDKV4f3RNl+Yhal66//gc7XjgCdPMpYCN9ID5+5D0D2d Y/pkAxsa8UrA346zX7ievlGiM3wz1eLzKRUfEJzdKVmji+kUOv8oflmjYEc921DdPHmCdxMLIDT pV6DeDH6FiZPYF5uJjNm X-Google-Smtp-Source: AGHT+IEJm44nEb0TxcOjkAjrcsD0xsD/CPlwgrhHME8dtzpc5/4Onda8YE7jAeRTGmWr+ZG5phmDmw== X-Received: by 2002:a17:902:ce87:b0:21f:85ee:f2df with SMTP id d9443c01a7336-22103f16b56mr276089045ad.15.1739956950796; Wed, 19 Feb 2025 01:22:30 -0800 (PST) From: Roger Pau Monne To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, linux-pci@vger.kernel.org Cc: Roger Pau Monne , Nirmal Patel , Jonathan Derrick , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Manivannan Sadhasivam , Rob Herring , Bjorn Helgaas Subject: [PATCH v3 2/3] PCI: vmd: Disable MSI remapping bypass under Xen Date: Wed, 19 Feb 2025 10:20:56 +0100 Message-ID: <20250219092059.90850-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20250219092059.90850-1-roger.pau@citrix.com> References: <20250219092059.90850-1-roger.pau@citrix.com> MIME-Version: 1.0 MSI remapping bypass (directly configuring MSI entries for devices on the VMD bus) won't work under Xen, as Xen is not aware of devices in such bus, and hence cannot configure the entries using the pIRQ interface in the PV case, and in the PVH case traps won't be setup for MSI entries for such devices. Until Xen is aware of devices in the VMD bus prevent the VMD_FEAT_CAN_BYPASS_MSI_REMAP capability from being used when running as any kind of Xen guest. The MSI remapping bypass is an optional feature of VMD bridges, and hence when running under Xen it will be masked and devices will be forced to redirect its interrupts from the VMD bridge. That mode of operation must always be supported by VMD bridges and works when Xen is not aware of devices behind the VMD bridge. Signed-off-by: Roger Pau Monné --- Changes since v2: - Adjust patch subject. - Adjust code comment. Changes since v1: - Add xen header. - Expand comment. --- drivers/pci/controller/vmd.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/pci/controller/vmd.c b/drivers/pci/controller/vmd.c index 9d9596947350..e619accca49d 100644 --- a/drivers/pci/controller/vmd.c +++ b/drivers/pci/controller/vmd.c @@ -17,6 +17,8 @@ #include #include +#include + #include #define VMD_CFGBAR 0 @@ -970,6 +972,24 @@ static int vmd_probe(struct pci_dev *dev, const struct pci_device_id *id) struct vmd_dev *vmd; int err; + if (xen_domain()) { + /* + * Xen doesn't have knowledge about devices in the VMD bus + * because the config space of devices behind the VMD bridge is + * not known to Xen, and hence Xen cannot discover or configure + * them in any way. + * + * Bypass of MSI remapping won't work in that case as direct + * write by Linux to the MSI entries won't result in functional + * interrupts, as Xen is the entity that manages the host + * interrupt controller and must configure interrupts. However + * multiplexing of interrupts by the VMD bridge will work under + * Xen, so force the usage of that mode which must always be + * supported by VMD bridges. + */ + features &= ~VMD_FEAT_CAN_BYPASS_MSI_REMAP; + } + if (resource_size(&dev->resource[VMD_CFGBAR]) < (1 << 20)) return -ENOMEM; From patchwork Wed Feb 19 09:20:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13981796 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BC4CFC021AA for ; Wed, 19 Feb 2025 09:22:56 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.892527.1301504 (Exim 4.92) (envelope-from ) id 1tkgI3-0000s5-3t; Wed, 19 Feb 2025 09:22:47 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 892527.1301504; Wed, 19 Feb 2025 09:22:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tkgI2-0000rs-Vz; Wed, 19 Feb 2025 09:22:46 +0000 Received: by outflank-mailman (input) for mailman id 892527; Wed, 19 Feb 2025 09:22:46 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tkgI2-00082q-4z for xen-devel@lists.xenproject.org; Wed, 19 Feb 2025 09:22:46 +0000 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [2607:f8b0:4864:20::62b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 136f6605-eea3-11ef-9aa8-95dc52dad729; Wed, 19 Feb 2025 10:22:45 +0100 (CET) Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-220dc3831e3so10514835ad.0 for ; Wed, 19 Feb 2025 01:22:45 -0800 (PST) Received: from localhost ([84.78.159.3]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7325b1afd0esm9030926b3a.137.2025.02.19.01.22.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2025 01:22:43 -0800 (PST) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 136f6605-eea3-11ef-9aa8-95dc52dad729 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1739956964; x=1740561764; darn=lists.xenproject.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=YnGtO5JguyJMDAVVd/amsK5Mk4hYl7NsHvQivQkdUR8=; b=rA808aXj0q9HVaUg8QNyKkgwAj2VmOcrbTBiRwUo/l8eoT2vcBUeBmc7Jb6lJQczhI 3UBkGnMAGOkmdNLThZpdzV0C8iCe1ulE+awY0lBZIc9fFmtRYyUGNx3pIHAovapdIAmd Tw+2g5cnHaWA4BaTt9ng6194Cqp2Jqt8DW458= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739956964; x=1740561764; 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=YnGtO5JguyJMDAVVd/amsK5Mk4hYl7NsHvQivQkdUR8=; b=GuHaNtqUkKS/ieumZ22kn6nUsnbCAOOxxFJ6bZQhrm0Bi4pBWtdHLHClveA7WG+nV2 loq34iEiXVsX3PA9Kht2qoGoNT7rqh8hPznznrnav2547859IYNg2bUcQPESJ84td0Yh ByZwK9Q27cOHXHSiNLmF/ZlvGfJ+u9Xa4Ml0nbxtJYDBZzIPVtfBo84y0pThRLkScNMB AQwj5YJnfCOSFLzSsodmXDueISxVoVcuCJcm1O+LIhPQD6YA80ZCOe/2hRpesWHsVezl W6PNBRjYZykmIsB+UvwE+irnUyHhniv/IKyVp+G/hxEeQGvm3HiuStN+UYGk36LLxBWV biMw== X-Forwarded-Encrypted: i=1; AJvYcCUPk0Q/YMgEqZ9oAlc/QfxP5+rXiG992WC2zLQXDKd97trTIzLQGDYeN56u31KiPA3GNyxfZ5xiDIg=@lists.xenproject.org X-Gm-Message-State: AOJu0Yw7BKfA3B9sDs+6DZ9qnj8rv0xDi3Z6PxBz83j43VpVl9z/9WFb QLJl5MoZwDQCPnoyQsqVh22dr7u9IJmyHI0JI7uJ2Rc7BgVAlP/QhbcBJJ7SRQY= X-Gm-Gg: ASbGncu9KhMB7jBm3vcHI4TbTmGDsgf64GX6/ZeacV6yFSwxCLFd3k1va1N4hrgi9Zx 1XenXfbxEYqvoJf+M3XynwCVjiDT/M8nPPKli+sRfw2dXl7m1721vCZFCPW1TvR8o1k/3O9+6gC 9KSWv2eMQP7rPUxup1DNVukyBhWwqbadTAOhU6LQfKOQ5s6PZu2Ih618Du0f6YbH1Vxh028v9jf zlIL6AeaCvE5mtq+1AXHpOWC/locSqzfMs9Wils75O7KUyws7fFyZPByD0c9xWQ+YeMPH8/06TY Og5otsTpm7LMN6Qx2Mif X-Google-Smtp-Source: AGHT+IEyC15TnZIAvUKjVtLm/x4/Lo6Nn8PENAHDVB3FMrtCAy7HQuzopUgCjPn21zM5n19hoHeGqw== X-Received: by 2002:a05:6a00:9297:b0:727:39a4:30cc with SMTP id d2e1a72fcca58-7329cd75fe4mr5153986b3a.1.1739956963747; Wed, 19 Feb 2025 01:22:43 -0800 (PST) From: Roger Pau Monne To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, linux-pci@vger.kernel.org Cc: Roger Pau Monne , Thomas Gleixner , Juergen Gross , Bjorn Helgaas , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" Subject: [PATCH v3 3/3] PCI/MSI: Convert pci_msi_ignore_mask to per MSI domain flag Date: Wed, 19 Feb 2025 10:20:57 +0100 Message-ID: <20250219092059.90850-4-roger.pau@citrix.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20250219092059.90850-1-roger.pau@citrix.com> References: <20250219092059.90850-1-roger.pau@citrix.com> MIME-Version: 1.0 Setting pci_msi_ignore_mask inhibits the toggling of the mask bit for both MSI and MSI-X entries globally, regardless of the IRQ chip they are using. Only Xen sets the pci_msi_ignore_mask when routing physical interrupts over event channels, to prevent PCI code from attempting to toggle the maskbit, as it's Xen that controls the bit. However, the pci_msi_ignore_mask being global will affect devices that use MSI interrupts but are not routing those interrupts over event channels (not using the Xen pIRQ chip). One example is devices behind a VMD PCI bridge. In that scenario the VMD bridge configures MSI(-X) using the normal IRQ chip (the pIRQ one in the Xen case), and devices behind the bridge configure the MSI entries using indexes into the VMD bridge MSI table. The VMD bridge then demultiplexes such interrupts and delivers to the destination device(s). Having pci_msi_ignore_mask set in that scenario prevents (un)masking of MSI entries for devices behind the VMD bridge. Move the signaling of no entry masking into the MSI domain flags, as that allows setting it on a per-domain basis. Set it for the Xen MSI domain that uses the pIRQ chip, while leaving it unset for the rest of the cases. Remove pci_msi_ignore_mask at once, since it was only used by Xen code, and with Xen dropping usage the variable is unneeded. This fixes using devices behind a VMD bridge on Xen PV hardware domains. Albeit Devices behind a VMD bridge are not known to Xen, that doesn't mean Linux cannot use them. By inhibiting the usage of VMD_FEAT_CAN_BYPASS_MSI_REMAP and the removal of the pci_msi_ignore_mask bodge devices behind a VMD bridge do work fine when use from a Linux Xen hardware domain. That's the whole point of the series. Signed-off-by: Roger Pau Monné Reviewed-by: Thomas Gleixner Acked-by: Juergen Gross --- Changes since v2: - Fix subject line. Changes since v1: - Fix build. - Expand commit message. --- arch/x86/pci/xen.c | 8 ++------ drivers/pci/msi/msi.c | 37 +++++++++++++++++++++---------------- include/linux/msi.h | 3 ++- kernel/irq/msi.c | 2 +- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/arch/x86/pci/xen.c b/arch/x86/pci/xen.c index 0f2fe524f60d..b8755cde2419 100644 --- a/arch/x86/pci/xen.c +++ b/arch/x86/pci/xen.c @@ -436,7 +436,8 @@ static struct msi_domain_ops xen_pci_msi_domain_ops = { }; static struct msi_domain_info xen_pci_msi_domain_info = { - .flags = MSI_FLAG_PCI_MSIX | MSI_FLAG_FREE_MSI_DESCS | MSI_FLAG_DEV_SYSFS, + .flags = MSI_FLAG_PCI_MSIX | MSI_FLAG_FREE_MSI_DESCS | + MSI_FLAG_DEV_SYSFS | MSI_FLAG_NO_MASK, .ops = &xen_pci_msi_domain_ops, }; @@ -484,11 +485,6 @@ static __init void xen_setup_pci_msi(void) * in allocating the native domain and never use it. */ x86_init.irqs.create_pci_msi_domain = xen_create_pci_msi_domain; - /* - * With XEN PIRQ/Eventchannels in use PCI/MSI[-X] masking is solely - * controlled by the hypervisor. - */ - pci_msi_ignore_mask = 1; } #else /* CONFIG_PCI_MSI */ diff --git a/drivers/pci/msi/msi.c b/drivers/pci/msi/msi.c index 2f647cac4cae..4c8c2b57b5f6 100644 --- a/drivers/pci/msi/msi.c +++ b/drivers/pci/msi/msi.c @@ -10,12 +10,12 @@ #include #include #include +#include #include "../pci.h" #include "msi.h" int pci_msi_enable = 1; -int pci_msi_ignore_mask; /** * pci_msi_supported - check whether MSI may be enabled on a device @@ -285,6 +285,8 @@ static void pci_msi_set_enable(struct pci_dev *dev, int enable) static int msi_setup_msi_desc(struct pci_dev *dev, int nvec, struct irq_affinity_desc *masks) { + const struct irq_domain *d = dev_get_msi_domain(&dev->dev); + const struct msi_domain_info *info = d->host_data; struct msi_desc desc; u16 control; @@ -295,8 +297,7 @@ static int msi_setup_msi_desc(struct pci_dev *dev, int nvec, /* Lies, damned lies, and MSIs */ if (dev->dev_flags & PCI_DEV_FLAGS_HAS_MSI_MASKING) control |= PCI_MSI_FLAGS_MASKBIT; - /* Respect XEN's mask disabling */ - if (pci_msi_ignore_mask) + if (info->flags & MSI_FLAG_NO_MASK) control &= ~PCI_MSI_FLAGS_MASKBIT; desc.nvec_used = nvec; @@ -604,12 +605,15 @@ static void __iomem *msix_map_region(struct pci_dev *dev, */ void msix_prepare_msi_desc(struct pci_dev *dev, struct msi_desc *desc) { + const struct irq_domain *d = dev_get_msi_domain(&dev->dev); + const struct msi_domain_info *info = d->host_data; + desc->nvec_used = 1; desc->pci.msi_attrib.is_msix = 1; desc->pci.msi_attrib.is_64 = 1; desc->pci.msi_attrib.default_irq = dev->irq; desc->pci.mask_base = dev->msix_base; - desc->pci.msi_attrib.can_mask = !pci_msi_ignore_mask && + desc->pci.msi_attrib.can_mask = !(info->flags & MSI_FLAG_NO_MASK) && !desc->pci.msi_attrib.is_virtual; if (desc->pci.msi_attrib.can_mask) { @@ -659,9 +663,6 @@ static void msix_mask_all(void __iomem *base, int tsize) u32 ctrl = PCI_MSIX_ENTRY_CTRL_MASKBIT; int i; - if (pci_msi_ignore_mask) - return; - for (i = 0; i < tsize; i++, base += PCI_MSIX_ENTRY_SIZE) writel(ctrl, base + PCI_MSIX_ENTRY_VECTOR_CTRL); } @@ -714,6 +715,8 @@ static int msix_setup_interrupts(struct pci_dev *dev, struct msix_entry *entries static int msix_capability_init(struct pci_dev *dev, struct msix_entry *entries, int nvec, struct irq_affinity *affd) { + const struct irq_domain *d = dev_get_msi_domain(&dev->dev); + const struct msi_domain_info *info = d->host_data; int ret, tsize; u16 control; @@ -744,15 +747,17 @@ static int msix_capability_init(struct pci_dev *dev, struct msix_entry *entries, /* Disable INTX */ pci_intx_for_msi(dev, 0); - /* - * Ensure that all table entries are masked to prevent - * stale entries from firing in a crash kernel. - * - * Done late to deal with a broken Marvell NVME device - * which takes the MSI-X mask bits into account even - * when MSI-X is disabled, which prevents MSI delivery. - */ - msix_mask_all(dev->msix_base, tsize); + if (!(info->flags & MSI_FLAG_NO_MASK)) { + /* + * Ensure that all table entries are masked to prevent + * stale entries from firing in a crash kernel. + * + * Done late to deal with a broken Marvell NVME device + * which takes the MSI-X mask bits into account even + * when MSI-X is disabled, which prevents MSI delivery. + */ + msix_mask_all(dev->msix_base, tsize); + } pci_msix_clear_and_set_ctrl(dev, PCI_MSIX_FLAGS_MASKALL, 0); pcibios_free_irq(dev); diff --git a/include/linux/msi.h b/include/linux/msi.h index b10093c4d00e..59a421fc42bf 100644 --- a/include/linux/msi.h +++ b/include/linux/msi.h @@ -73,7 +73,6 @@ struct msi_msg { }; }; -extern int pci_msi_ignore_mask; /* Helper functions */ struct msi_desc; struct pci_dev; @@ -556,6 +555,8 @@ enum { MSI_FLAG_PCI_MSIX_ALLOC_DYN = (1 << 20), /* PCI MSIs cannot be steered separately to CPU cores */ MSI_FLAG_NO_AFFINITY = (1 << 21), + /* Inhibit usage of entry masking */ + MSI_FLAG_NO_MASK = (1 << 22), }; /** diff --git a/kernel/irq/msi.c b/kernel/irq/msi.c index 396a067a8a56..7682c36cbccc 100644 --- a/kernel/irq/msi.c +++ b/kernel/irq/msi.c @@ -1143,7 +1143,7 @@ static bool msi_check_reservation_mode(struct irq_domain *domain, if (!(info->flags & MSI_FLAG_MUST_REACTIVATE)) return false; - if (IS_ENABLED(CONFIG_PCI_MSI) && pci_msi_ignore_mask) + if (info->flags & MSI_FLAG_NO_MASK) return false; /*