LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Barry Song <21cnbao@gmail.com>
To: linux-kernel@vger.kernel.org, maz@kernel.org, tglx@linutronix.de
Cc: bhelgaas@google.com, dwmw@amazon.co.uk,
	gregkh@linuxfoundation.org, linux-pci@vger.kernel.org,
	linuxarm@huawei.com, lorenzo.pieralisi@arm.com,
	rafael@kernel.org, robin.murphy@arm.com,
	song.bao.hua@hisilicon.com, will@kernel.org,
	Zhou Wang <wangzhou1@hisilicon.com>
Subject: [PATCH v3 2/2] platform-msi: Add ABI to show msi_irqs of platform devices
Date: Fri, 13 Aug 2021 15:56:28 +1200	[thread overview]
Message-ID: <20210813035628.6844-3-21cnbao@gmail.com> (raw)
In-Reply-To: <20210813035628.6844-1-21cnbao@gmail.com>

From: Barry Song <song.bao.hua@hisilicon.com>

Just like PCI devices have msi_irqs which can be used by userspace IRQ
affinity tools or applications to bind IRQs, platform devices also widely
support MSI IRQs. For some platform devices such as ARM SMMU, userspaces
also care about its MSI IRQs as applications can know the mapping between
devices and IRQs and then make smarter decision on handling IRQ affinity.
For example, in SVA mode, it is better to pin I/O page fault to the NUMA
node applications are running on. Otherwise, I/O page fault will get a
remote page from the node IOPF happens.
With this patch, a system with multiple ARM SMMUs in multiple different
NUMA nodes can get the mapping between devices and IRQs now:

  root@ubuntu:/sys/devices/platform# ls -l arm-smmu-v3.*/msi_irqs/*
  -r--r--r-- 1 root root 4096 Aug 11 10:29 arm-smmu-v3.0.auto/msi_irqs/25
  -r--r--r-- 1 root root 4096 Aug 11 10:29 arm-smmu-v3.0.auto/msi_irqs/26
  -r--r--r-- 1 root root 4096 Aug 11 10:28 arm-smmu-v3.1.auto/msi_irqs/27
  -r--r--r-- 1 root root 4096 Aug 11 10:28 arm-smmu-v3.1.auto/msi_irqs/28
  -r--r--r-- 1 root root 4096 Aug 11 10:29 arm-smmu-v3.2.auto/msi_irqs/29
  -r--r--r-- 1 root root 4096 Aug 11 10:29 arm-smmu-v3.2.auto/msi_irqs/30
  -r--r--r-- 1 root root 4096 Aug 11 10:29 arm-smmu-v3.3.auto/msi_irqs/31
  -r--r--r-- 1 root root 4096 Aug 11 10:29 arm-smmu-v3.3.auto/msi_irqs/32
  -r--r--r-- 1 root root 4096 Aug 11 10:29 arm-smmu-v3.4.auto/msi_irqs/33
  -r--r--r-- 1 root root 4096 Aug 11 10:29 arm-smmu-v3.4.auto/msi_irqs/34
  -r--r--r-- 1 root root 4096 Aug 11 10:29 arm-smmu-v3.5.auto/msi_irqs/35
  -r--r--r-- 1 root root 4096 Aug 11 10:29 arm-smmu-v3.5.auto/msi_irqs/36
  -r--r--r-- 1 root root 4096 Aug 11 10:29 arm-smmu-v3.6.auto/msi_irqs/37
  -r--r--r-- 1 root root 4096 Aug 11 10:29 arm-smmu-v3.6.auto/msi_irqs/38
  -r--r--r-- 1 root root 4096 Aug 11 10:29 arm-smmu-v3.7.auto/msi_irqs/39
  -r--r--r-- 1 root root 4096 Aug 11 10:29 arm-smmu-v3.7.auto/msi_irqs/40

Applications can use the mapping and the NUMA node information to pin
IRQs by further leveraging the numa information which has also been
exported:

  root@ubuntu:/sys/devices/platform# cat arm-smmu-v3.0.auto/numa_node
  0
  root@ubuntu:/sys/devices/platform# cat arm-smmu-v3.4.auto/numa_node
  2

Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: Zhou Wang <wangzhou1@hisilicon.com>
Signed-off-by: Barry Song <song.bao.hua@hisilicon.com>
---
 Documentation/ABI/testing/sysfs-bus-platform | 14 ++++++++++++++
 drivers/base/platform-msi.c                  | 10 ++++++++++
 2 files changed, 24 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-bus-platform b/Documentation/ABI/testing/sysfs-bus-platform
index 194ca70..ff30728 100644
--- a/Documentation/ABI/testing/sysfs-bus-platform
+++ b/Documentation/ABI/testing/sysfs-bus-platform
@@ -28,3 +28,17 @@ Description:
 		value comes from an ACPI _PXM method or a similar firmware
 		source. Initial users for this file would be devices like
 		arm smmu which are populated by arm64 acpi_iort.
+
+What:		/sys/bus/platform/devices/.../msi_irqs/
+Date:		August 2021
+Contact:	Barry Song <song.bao.hua@hisilicon.com>
+Description:
+		The /sys/devices/.../msi_irqs directory contains a variable set
+		of files, with each file being named after a corresponding msi
+		irq vector allocated to that device.
+
+What:		/sys/bus/platform/devices/.../msi_irqs/<N>
+Date:		August 2021
+Contact:	Barry Song <song.bao.hua@hisilicon.com>
+Description:
+		This attribute will show "msi" if <N> is a valid msi irq
diff --git a/drivers/base/platform-msi.c b/drivers/base/platform-msi.c
index 0b72b13..a3bf910 100644
--- a/drivers/base/platform-msi.c
+++ b/drivers/base/platform-msi.c
@@ -23,6 +23,7 @@
 struct platform_msi_priv_data {
 	struct device		*dev;
 	void 			*host_data;
+	const struct attribute_group    **msi_irq_groups;
 	msi_alloc_info_t	arg;
 	irq_write_msi_msg_t	write_msg;
 	int			devid;
@@ -272,8 +273,16 @@ int platform_msi_domain_alloc_irqs(struct device *dev, unsigned int nvec,
 	if (err)
 		goto out_free_desc;
 
+	priv_data->msi_irq_groups = msi_populate_sysfs(dev);
+	if (IS_ERR(priv_data->msi_irq_groups)) {
+		err = PTR_ERR(priv_data->msi_irq_groups);
+		goto out_free_irqs;
+	}
+
 	return 0;
 
+out_free_irqs:
+	msi_domain_free_irqs(dev->msi_domain, dev);
 out_free_desc:
 	platform_msi_free_descs(dev, 0, nvec);
 out_free_priv_data:
@@ -293,6 +302,7 @@ void platform_msi_domain_free_irqs(struct device *dev)
 		struct msi_desc *desc;
 
 		desc = first_msi_entry(dev);
+		msi_destroy_sysfs(dev, desc->platform.msi_priv_data->msi_irq_groups);
 		platform_msi_free_priv_data(desc->platform.msi_priv_data);
 	}
 
-- 
1.8.3.1


  parent reply	other threads:[~2021-08-13  3:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-13  3:56 [PATCH v3 0/2] msi: extend msi_irqs sysfs entries to " Barry Song
2021-08-13  3:56 ` [PATCH v3 1/2] genirq/msi: Extract common sysfs populate entries to MSI core from PCI Barry Song
2021-08-24  7:20   ` [tip: irq/core] genirq/msi: Move MSI sysfs handling from PCI to MSI core tip-bot2 for Barry Song
2021-08-13  3:56 ` Barry Song [this message]
2021-08-24  7:20   ` [tip: irq/core] platform-msi: Add ABI to show msi_irqs of platform devices tip-bot2 for Barry Song
2021-08-14  9:45 ` [PATCH v3 0/2] msi: extend msi_irqs sysfs entries to " Marc Zyngier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210813035628.6844-3-21cnbao@gmail.com \
    --to=21cnbao@gmail.com \
    --cc=bhelgaas@google.com \
    --cc=dwmw@amazon.co.uk \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=maz@kernel.org \
    --cc=rafael@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=song.bao.hua@hisilicon.com \
    --cc=tglx@linutronix.de \
    --cc=wangzhou1@hisilicon.com \
    --cc=will@kernel.org \
    --subject='Re: [PATCH v3 2/2] platform-msi: Add ABI to show msi_irqs of platform devices' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).