Skip to contentSkip to conversation

lib/rwmmio/arm64: Add support to trace register reads/writes

PATCH Superseded Sai Prakash Ranjan 3 participants 16 messages Apr 28, 2022

Subsystems (14)

v11 of 15 Superseded Latest is v15 →

lore
Share & tools
lore
#0 lore raw

v11 cover lib/rwmmio/arm64: Add support to trace register reads/writes

Generic MMIO read/write i.e., __raw_{read,write}{b,l,w,q} accessors are typically used to read/write from/to memory mapped registers and can cause hangs or some undefined behaviour in following cases,

* If the access to the register space is unclocked, for example: if there is an access to multimedia(MM) block registers without MM clocks.

* If the register space is protected and not set to be accessible from non-secure world, for example: only EL3 (EL: Exception level) access is allowed and any EL2/EL1 access is forbidden.

* If xPU(memory/register protection units) is controlling access to certain memory/register space for specific clients.

and more...

Such cases usually results in instant reboot/SErrors/NOC or interconnect hangs and tracing these register accesses can be very helpful to debug such issues during initial development stages and also in later stages.

So use ftrace trace events to log such MMIO register accesses which provides rich feature set such as early enablement of trace events, filtering capability, dumping ftrace logs on console and many more.

Sample output:

rwmmio_write: __qcom_geni_serial_console_write+0x160/0x1e0 width=32 val=0xa0d5d addr=0xfffffbfffdbff700
rwmmio_post_write: __qcom_geni_serial_console_write+0x160/0x1e0 width=32 val=0xa0d5d addr=0xfffffbfffdbff700
rwmmio_read: qcom_geni_serial_poll_bit+0x94/0x138 width=32 addr=0xfffffbfffdbff610
rwmmio_post_read: qcom_geni_serial_poll_bit+0x94/0x138 width=32 val=0x0 addr=0xfffffbfffdbff610

This series is a follow-up for the series [1] and a recent series [2] making use of both.

[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/

Note in v4 version, Arnd suggested to benchmark and compare size with callback based implementation, please see [3] for more details on that with brief comparison below.

**Inline version with CONFIG_FTRACE=y and CONFIG_TRACE_MMIO_ACCESS=y**

$ size vmlinux
   text           data             bss     dec             hex         filename
 23884219        14284468         532568 38701255        24e88c7        vmlinux

**Callback version with CONFIG_FTRACE=y and CONFIG_TRACE_MMIO_ACCESS=y**

$ size vmlinux
    text          data             bss     dec             hex        filename
 24108179        14279596         532568 38920343        251e097       vmlinux
$ ./scripts/bloat-o-meter inline-vmlinux callback-vmlinux
add/remove: 8/3 grow/shrink: 4889/89 up/down: 242244/-11564 (230680)
Total: Before=25812612, After=26043292, chg +0.89%

[3] https://lore.kernel.org/lkml/[email protected]/

Changes in v11:
* Use unsigned long for caller ip and current ip addr (Steven Rostedt).
* Include review tags from Arnd.

Changes in v10:
* Use GENMASK(31, 0) for -Woverflow warning in irqchip tegra driver (Marc).
* Convert ETM4x ARM64 driver to use asm-generic IO memory barriers (Catalin).
* Collect ack from Catalin for arm64 change.

Changes in v9:
* Use TRACE_EVENT_CLASS for rwmmio_write and post_write (Steven Rostedt).

Changes in v8:
* Fix build error reported by kernel test robot.

Changes in v7:
* Use lib/ instead of kernel/trace/ based on review comment by Steven Rostedt.

Changes in v6:
* Implemented suggestions by Arnd Bergmann:
- Use arch independent IO barriers in arm64/asm
- Add ARCH_HAVE_TRACE_MMIO_ACCESS
- Add post read and post write logging support
- Remove tracepoint_active check
* Fix build error reported by kernel test robot.

Changes in v5:
* Move arm64 to use asm-generic provided high level MMIO accessors (Arnd).
* Add inline logging for MMIO relaxed and non-relaxed accessors.
* Move nVHE KVM comment to makefile (Marc).
* Fix overflow warning due to switch to inline accessors instead of macro.
* Modify trace event field to include caller and parent details for more detailed logs.

Changes in v4:
* Drop dynamic debug based filter support since that will be developed later with the help from Steven (Ftrace maintainer).
* Drop value passed to writel as it is causing hangs when tracing is enabled.
* Code cleanup for trace event as suggested by Steven for earlier version.
* Fixed some build errors reported by 0-day bot.

Changes in v3:
* Create a generic mmio header for instrumented version (Earlier suggested in [1] by Will Deacon and recently [2] by Greg to have a generic version first).
* Add dynamic debug support to filter out traces which can be very useful for targeted debugging specific to subsystems or drivers.
* Few modifications to the rwmmio trace event fields to include the mmio width and print addresses in hex.
* Rewrote commit msg to explain some more about usecases.

Prasad Sodagudi (1):
lib: Add register read/write tracing support

Sai Prakash Ranjan (5):
arm64: io: Use asm-generic high level MMIO accessors
coresight: etm4x: Use asm-generic IO memory barriers irqchip/tegra: Fix overflow implicit truncation warnings drm/meson: Fix overflow implicit truncation warnings asm-generic/io: Add logging support for MMIO accessors

 arch/Kconfig                                  |  3 +
 arch/arm64/Kconfig                            |  1 +
 arch/arm64/include/asm/io.h                   | 41 ++------
 arch/arm64/kvm/hyp/nvhe/Makefile              |  7 +-
 drivers/gpu/drm/meson/meson_viu.c             | 22 ++---
 .../coresight/coresight-etm4x-core.c          |  8 +-
 drivers/hwtracing/coresight/coresight-etm4x.h |  8 +-
 drivers/irqchip/irq-tegra.c                   | 10 +-
 include/asm-generic/io.h                      | 82 +++++++++++++++-
 include/trace/events/rwmmio.h                 | 97 +++++++++++++++++++
 lib/Kconfig                                   |  7 ++
 lib/Makefile                                  |  2 +
 lib/trace_readwrite.c                         | 47 +++++++++
 13 files changed, 273 insertions(+), 62 deletions(-)
 create mode 100644 include/trace/events/rwmmio.h
 create mode 100644 lib/trace_readwrite.c

base-commit: 53ab78cd6d5aba25575a7cfb95729336ba9497d8

Signature · 1 line
2.33.1
#1 lore raw

PATCH v11 1/6 arm64: io: Use asm-generic high level MMIO accessors

Remove custom arm64 MMIO accessors read{b,w,l,q} and their relaxed versions in support to use asm-generic defined accessors. Also define one set of IO barriers (ar/bw version) used by asm-generic code to override the arm64 specific variants.

---
 arch/arm64/include/asm/io.h | 41 ++++++++-----------------------------
 1 file changed, 8 insertions(+), 33 deletions(-)
arch/arm64/include/asm/io.h +8 -33
index 7fd836bea7eb..1b436810d779 100644
@@ -91,7 +91,7 @@ static inline u64 __raw_readq(const volatile void __iomem *addr)
 }
 
 /* IO barriers */
-#define __iormb(v)							\
+#define __io_ar(v)							\
 ({									\
 	unsigned long tmp;						\
 									\
@@ -108,39 +108,14 @@ static inline u64 __raw_readq(const volatile void __iomem *addr)
 		     : "memory");					\
 })
 
-#define __io_par(v)		__iormb(v)
-#define __iowmb()		dma_wmb()
-#define __iomb()		dma_mb()
-
-/*
- * Relaxed I/O memory access primitives. These follow the Device memory
- * ordering rules but do not guarantee any ordering relative to Normal memory
- * accesses.
- */
-#define readb_relaxed(c)	({ u8  __r = __raw_readb(c); __r; })
-#define readw_relaxed(c)	({ u16 __r = le16_to_cpu((__force __le16)__raw_readw(c)); __r; })
-#define readl_relaxed(c)	({ u32 __r = le32_to_cpu((__force __le32)__raw_readl(c)); __r; })
-#define readq_relaxed(c)	({ u64 __r = le64_to_cpu((__force __le64)__raw_readq(c)); __r; })
+#define __io_bw()		dma_wmb()
+#define __io_br(v)
+#define __io_aw(v)
 
-#define writeb_relaxed(v,c)	((void)__raw_writeb((v),(c)))
-#define writew_relaxed(v,c)	((void)__raw_writew((__force u16)cpu_to_le16(v),(c)))
-#define writel_relaxed(v,c)	((void)__raw_writel((__force u32)cpu_to_le32(v),(c)))
-#define writeq_relaxed(v,c)	((void)__raw_writeq((__force u64)cpu_to_le64(v),(c)))
-
-/*
- * I/O memory access primitives. Reads are ordered relative to any
- * following Normal memory access. Writes are ordered relative to any prior
- * Normal memory access.
- */
-#define readb(c)		({ u8  __v = readb_relaxed(c); __iormb(__v); __v; })
-#define readw(c)		({ u16 __v = readw_relaxed(c); __iormb(__v); __v; })
-#define readl(c)		({ u32 __v = readl_relaxed(c); __iormb(__v); __v; })
-#define readq(c)		({ u64 __v = readq_relaxed(c); __iormb(__v); __v; })
-
-#define writeb(v,c)		({ __iowmb(); writeb_relaxed((v),(c)); })
-#define writew(v,c)		({ __iowmb(); writew_relaxed((v),(c)); })
-#define writel(v,c)		({ __iowmb(); writel_relaxed((v),(c)); })
-#define writeq(v,c)		({ __iowmb(); writeq_relaxed((v),(c)); })
+/* arm64-specific, don't use in portable drivers */
+#define __iormb(v)		__io_ar(v)
+#define __iowmb()		__io_bw()
+#define __iomb()		dma_mb()
 
 /*
  *  I/O port access primitives.
Signature · 1 line
2.33.1
#2 lore raw

PATCH v11 2/6 coresight: etm4x: Use asm-generic IO memory barriers

In reply to Sai Prakash Ranjan

Per discussion in [1], it was decided to move to using architecture independent/asm-generic IO memory barriers to have just one set of them and deprecate use of arm64 specific IO memory barriers in driver code. So replace current usage of __io_rmb()/__iowmb() in drivers to __io_ar()/__io_bw().

[1] https://lore.kernel.org/lkml/CAK8P3a0L2tLeF1Q0+0ijUxhGNaw+Z0fyPC1oW6_ELQfn0=i4iw@mail.gmail.com/

---
 drivers/hwtracing/coresight/coresight-etm4x-core.c | 8 ++++----
 drivers/hwtracing/coresight/coresight-etm4x.h      | 8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)
drivers/hwtracing/coresight/coresight-etm4x-core.c +4 -4
index bf18128cf5de..89ba7bb4c41d 100644
@@ -98,7 +98,7 @@ u64 etm4x_sysreg_read(u32 offset, bool _relaxed, bool _64bit)
 	}
 
 	if (!_relaxed)
-		__iormb(res);	/* Imitate the !relaxed I/O helpers */
+		__io_ar(res);	/* Imitate the !relaxed I/O helpers */
 
 	return res;
 }
@@ -106,7 +106,7 @@ u64 etm4x_sysreg_read(u32 offset, bool _relaxed, bool _64bit)
 void etm4x_sysreg_write(u64 val, u32 offset, bool _relaxed, bool _64bit)
 {
 	if (!_relaxed)
-		__iowmb();	/* Imitate the !relaxed I/O helpers */
+		__io_bw();	/* Imitate the !relaxed I/O helpers */
 	if (!_64bit)
 		val &= GENMASK(31, 0);
 
@@ -130,7 +130,7 @@ static u64 ete_sysreg_read(u32 offset, bool _relaxed, bool _64bit)
 	}
 
 	if (!_relaxed)
-		__iormb(res);	/* Imitate the !relaxed I/O helpers */
+		__io_ar(res);	/* Imitate the !relaxed I/O helpers */
 
 	return res;
 }
@@ -138,7 +138,7 @@ static u64 ete_sysreg_read(u32 offset, bool _relaxed, bool _64bit)
 static void ete_sysreg_write(u64 val, u32 offset, bool _relaxed, bool _64bit)
 {
 	if (!_relaxed)
-		__iowmb();	/* Imitate the !relaxed I/O helpers */
+		__io_bw();	/* Imitate the !relaxed I/O helpers */
 	if (!_64bit)
 		val &= GENMASK(31, 0);
 
drivers/hwtracing/coresight/coresight-etm4x.h +4 -4
index 3c4d69b096ca..f54698731582 100644
@@ -448,14 +448,14 @@
 #define etm4x_read32(csa, offset)					\
 	({								\
 		u32 __val = etm4x_relaxed_read32((csa), (offset));	\
-		__iormb(__val);						\
+		__io_ar(__val);						\
 		__val;							\
 	 })
 
 #define etm4x_read64(csa, offset)					\
 	({								\
 		u64 __val = etm4x_relaxed_read64((csa), (offset));	\
-		__iormb(__val);						\
+		__io_ar(__val);						\
 		__val;							\
 	 })
 
@@ -479,13 +479,13 @@
 
 #define etm4x_write32(csa, val, offset)					\
 	do {								\
-		__iowmb();						\
+		__io_bw();						\
 		etm4x_relaxed_write32((csa), (val), (offset));		\
 	} while (0)
 
 #define etm4x_write64(csa, val, offset)					\
 	do {								\
-		__iowmb();						\
+		__io_bw();						\
 		etm4x_relaxed_write64((csa), (val), (offset));		\
 	} while (0)
 
Signature · 1 line
2.33.1
#3 lore raw

PATCH v11 3/6 irqchip/tegra: Fix overflow implicit truncation warnings

In reply to Sai Prakash Ranjan

Fix -Woverflow warnings for tegra irqchip driver which is a result of moving arm64 custom MMIO accessor macros to asm-generic function implementations giving a bonus type-checking now and uncovering these overflow warnings.

drivers/irqchip/irq-tegra.c: In function ‘tegra_ictlr_suspend’:
drivers/irqchip/irq-tegra.c:151:18: warning: large integer implicitly truncated to unsigned type [-Woverflow]

   writel_relaxed(~0ul, ictlr + ICTLR_COP_IER_CLR);
                  ^
---
 drivers/irqchip/irq-tegra.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/irqchip/irq-tegra.c +5 -5
index e1f771c72fc4..ad3e2c1b3c87 100644
@@ -148,10 +148,10 @@ static int tegra_ictlr_suspend(void)
 		lic->cop_iep[i] = readl_relaxed(ictlr + ICTLR_COP_IEP_CLASS);
 
 		/* Disable COP interrupts */
-		writel_relaxed(~0ul, ictlr + ICTLR_COP_IER_CLR);
+		writel_relaxed(GENMASK(31, 0), ictlr + ICTLR_COP_IER_CLR);
 
 		/* Disable CPU interrupts */
-		writel_relaxed(~0ul, ictlr + ICTLR_CPU_IER_CLR);
+		writel_relaxed(GENMASK(31, 0), ictlr + ICTLR_CPU_IER_CLR);
 
 		/* Enable the wakeup sources of ictlr */
 		writel_relaxed(lic->ictlr_wake_mask[i], ictlr + ICTLR_CPU_IER_SET);
@@ -172,12 +172,12 @@ static void tegra_ictlr_resume(void)
 
 		writel_relaxed(lic->cpu_iep[i],
 			       ictlr + ICTLR_CPU_IEP_CLASS);
-		writel_relaxed(~0ul, ictlr + ICTLR_CPU_IER_CLR);
+		writel_relaxed(GENMASK(31, 0), ictlr + ICTLR_CPU_IER_CLR);
 		writel_relaxed(lic->cpu_ier[i],
 			       ictlr + ICTLR_CPU_IER_SET);
 		writel_relaxed(lic->cop_iep[i],
 			       ictlr + ICTLR_COP_IEP_CLASS);
-		writel_relaxed(~0ul, ictlr + ICTLR_COP_IER_CLR);
+		writel_relaxed(GENMASK(31, 0), ictlr + ICTLR_COP_IER_CLR);
 		writel_relaxed(lic->cop_ier[i],
 			       ictlr + ICTLR_COP_IER_SET);
 	}
@@ -312,7 +312,7 @@ static int __init tegra_ictlr_init(struct device_node *node,
 		lic->base[i] = base;
 
 		/* Disable all interrupts */
-		writel_relaxed(~0UL, base + ICTLR_CPU_IER_CLR);
+		writel_relaxed(GENMASK(31, 0), base + ICTLR_CPU_IER_CLR);
 		/* All interrupts target IRQ */
 		writel_relaxed(0, base + ICTLR_CPU_IEP_CLASS);
 
Signature · 1 line
2.33.1
#4 lore raw

PATCH v11 4/6 drm/meson: Fix overflow implicit truncation warnings

In reply to Sai Prakash Ranjan

Fix -Woverflow warnings for drm/meson driver which is a result of moving arm64 custom MMIO accessor macros to asm-generic function implementations giving a bonus type-checking now and uncovering these overflow warnings.

drivers/gpu/drm/meson/meson_viu.c: In function ‘meson_viu_init’:
drivers/gpu/drm/meson/meson_registers.h:1826:48: error: large integer implicitly truncated to unsigned type [-Werror=overflow]

 #define  VIU_OSD_BLEND_REORDER(dest, src)      ((src) << (dest * 4))
                                                ^
drivers/gpu/drm/meson/meson_viu.c:472:18: note: in expansion of macro ‘VIU_OSD_BLEND_REORDER’
   writel_relaxed(VIU_OSD_BLEND_REORDER(0, 1) |
                  ^~~~~~~~~~~~~~~~~~~~~
---
 drivers/gpu/drm/meson/meson_viu.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
drivers/gpu/drm/meson/meson_viu.c +11 -11
index 259f3e6bec90..bb7e109534de 100644
@@ -469,17 +469,17 @@ void meson_viu_init(struct meson_drm *priv)
 			priv->io_base + _REG(VD2_IF0_LUMA_FIFO_SIZE));
 
 	if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) {
-		writel_relaxed(VIU_OSD_BLEND_REORDER(0, 1) |
-			       VIU_OSD_BLEND_REORDER(1, 0) |
-			       VIU_OSD_BLEND_REORDER(2, 0) |
-			       VIU_OSD_BLEND_REORDER(3, 0) |
-			       VIU_OSD_BLEND_DIN_EN(1) |
-			       VIU_OSD_BLEND1_DIN3_BYPASS_TO_DOUT1 |
-			       VIU_OSD_BLEND1_DOUT_BYPASS_TO_BLEND2 |
-			       VIU_OSD_BLEND_DIN0_BYPASS_TO_DOUT0 |
-			       VIU_OSD_BLEND_BLEN2_PREMULT_EN(1) |
-			       VIU_OSD_BLEND_HOLD_LINES(4),
-			       priv->io_base + _REG(VIU_OSD_BLEND_CTRL));
+		u32 val = (u32)VIU_OSD_BLEND_REORDER(0, 1) |
+			  (u32)VIU_OSD_BLEND_REORDER(1, 0) |
+			  (u32)VIU_OSD_BLEND_REORDER(2, 0) |
+			  (u32)VIU_OSD_BLEND_REORDER(3, 0) |
+			  (u32)VIU_OSD_BLEND_DIN_EN(1) |
+			  (u32)VIU_OSD_BLEND1_DIN3_BYPASS_TO_DOUT1 |
+			  (u32)VIU_OSD_BLEND1_DOUT_BYPASS_TO_BLEND2 |
+			  (u32)VIU_OSD_BLEND_DIN0_BYPASS_TO_DOUT0 |
+			  (u32)VIU_OSD_BLEND_BLEN2_PREMULT_EN(1) |
+			  (u32)VIU_OSD_BLEND_HOLD_LINES(4);
+		writel_relaxed(val, priv->io_base + _REG(VIU_OSD_BLEND_CTRL));
 
 		writel_relaxed(OSD_BLEND_PATH_SEL_ENABLE,
 			       priv->io_base + _REG(OSD1_BLEND_SRC_CTRL));
Signature · 1 line
2.33.1
#5 lore raw

PATCH v11 5/6 lib: Add register read/write tracing support

In reply to Sai Prakash Ranjan

From: Prasad Sodagudi <[email protected]>

Generic MMIO read/write i.e., __raw_{read,write}{b,l,w,q} accessors are typically used to read/write from/to memory mapped registers and can cause hangs or some undefined behaviour in following few cases,

* If the access to the register space is unclocked, for example: if there is an access to multimedia(MM) block registers without MM clocks.

* If the register space is protected and not set to be accessible from non-secure world, for example: only EL3 (EL: Exception level) access is allowed and any EL2/EL1 access is forbidden.

* If xPU(memory/register protection units) is controlling access to certain memory/register space for specific clients.

and more...

Such cases usually results in instant reboot/SErrors/NOC or interconnect hangs and tracing these register accesses can be very helpful to debug such issues during initial development stages and also in later stages.

So use ftrace trace events to log such MMIO register accesses which provides rich feature set such as early enablement of trace events, filtering capability, dumping ftrace logs on console and many more.

Sample output:

rwmmio_write: __qcom_geni_serial_console_write+0x160/0x1e0 width=32 val=0xa0d5d addr=0xfffffbfffdbff700
rwmmio_post_write: __qcom_geni_serial_console_write+0x160/0x1e0 width=32 val=0xa0d5d addr=0xfffffbfffdbff700
rwmmio_read: qcom_geni_serial_poll_bit+0x94/0x138 width=32 addr=0xfffffbfffdbff610
rwmmio_post_read: qcom_geni_serial_poll_bit+0x94/0x138 width=32 val=0x0 addr=0xfffffbfffdbff610

---
 arch/Kconfig                  |  3 ++
 arch/arm64/Kconfig            |  1 +
 include/trace/events/rwmmio.h | 97 +++++++++++++++++++++++++++++++++++
 lib/Kconfig                   |  7 +++
 lib/Makefile                  |  2 +
 lib/trace_readwrite.c         | 47 +++++++++++++++++
 6 files changed, 157 insertions(+)
 create mode 100644 include/trace/events/rwmmio.h
 create mode 100644 lib/trace_readwrite.c
arch/Kconfig +3 -0
index 678a80713b21..efbbc36658dc 100644
@@ -1315,6 +1315,9 @@ config ARCH_HAS_ELFCORE_COMPAT
 config ARCH_HAS_PARANOID_L1D_FLUSH
 	bool
 
+config ARCH_HAVE_TRACE_MMIO_ACCESS
+	bool
+
 config DYNAMIC_SIGFRAME
 	bool
 
arch/arm64/Kconfig +1 -0
index 09b885cc4db5..321ae97df987 100644
@@ -46,6 +46,7 @@ config ARM64
 	select ARCH_HAS_ZONE_DMA_SET if EXPERT
 	select ARCH_HAVE_ELF_PROT
 	select ARCH_HAVE_NMI_SAFE_CMPXCHG
+	select ARCH_HAVE_TRACE_MMIO_ACCESS
 	select ARCH_INLINE_READ_LOCK if !PREEMPTION
 	select ARCH_INLINE_READ_LOCK_BH if !PREEMPTION
 	select ARCH_INLINE_READ_LOCK_IRQ if !PREEMPTION
include/trace/events/rwmmio.h new file +97 -0

97 lines not on this page · raw message

lib/Kconfig +7 -0
index c80fde816a7e..ea520c315c0f 100644
@@ -119,6 +119,13 @@ config INDIRECT_IOMEM_FALLBACK
 	  mmio accesses when the IO memory address is not a registered
 	  emulated region.
 
+config TRACE_MMIO_ACCESS
+	bool "Register read/write tracing"
+	depends on TRACING && ARCH_HAVE_TRACE_MMIO_ACCESS
+	help
+	  Create tracepoints for MMIO read/write operations. These trace events
+	  can be used for logging all MMIO read/write operations.
+
 source "lib/crypto/Kconfig"
 
 config CRC_CCITT
lib/Makefile +2 -0
index 300f569c626b..43813b0061cd 100644
@@ -152,6 +152,8 @@ lib-y += logic_pio.o
 
 lib-$(CONFIG_INDIRECT_IOMEM) += logic_iomem.o
 
+obj-$(CONFIG_TRACE_MMIO_ACCESS) += trace_readwrite.o
+
 obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
 
 obj-$(CONFIG_BTREE) += btree.o
lib/trace_readwrite.c new file +47 -0

47 lines not on this page · raw message

Signature · 1 line
2.33.1
#6 lore raw

PATCH v11 6/6 asm-generic/io: Add logging support for MMIO accessors

In reply to Sai Prakash Ranjan

Add logging support for MMIO high level accessors such as read{b,w,l,q} and their relaxed versions to aid in debugging unexpected crashes/hangs caused by the corresponding MMIO operation. Also add a generic flag (__DISABLE_TRACE_MMIO__) which is used to disable MMIO tracing in nVHE KVM and if required can be used to disable MMIO tracing for specific drivers.

---
 arch/arm64/kvm/hyp/nvhe/Makefile |  7 ++-
 include/asm-generic/io.h         | 82 ++++++++++++++++++++++++++++++--
 2 files changed, 84 insertions(+), 5 deletions(-)
arch/arm64/kvm/hyp/nvhe/Makefile +6 -1
index 24b2c2425b38..228d1f8921c3 100644
@@ -4,7 +4,12 @@
 #
 
 asflags-y := -D__KVM_NVHE_HYPERVISOR__ -D__DISABLE_EXPORTS
-ccflags-y := -D__KVM_NVHE_HYPERVISOR__ -D__DISABLE_EXPORTS
+
+# Tracepoint and MMIO logging symbols should not be visible at nVHE KVM as
+# there is no way to execute them and any such MMIO access from nVHE KVM
+# will explode instantly (Words of Marc Zyngier). So introduce a generic flag
+# __DISABLE_TRACE_MMIO__ to disable MMIO tracing for nVHE KVM.
+ccflags-y := -D__KVM_NVHE_HYPERVISOR__ -D__DISABLE_EXPORTS -D__DISABLE_TRACE_MMIO__
 
 hostprogs := gen-hyprel
 HOST_EXTRACFLAGS += -I$(objtree)/include
include/asm-generic/io.h +78 -4

218 lines not on this page · raw message

Signature · 1 line
2.33.1
#7 lore raw

Re: [PATCHv11 6/6] asm-generic/io: Add logging support for MMIO accessors

Quoted 5 lines · Sai Prakash Ranjan

Add logging support for MMIO high level accessors such as read{b,w,l,q} and their relaxed versions to aid in debugging unexpected crashes/hangs caused by the corresponding MMIO operation. Also add a generic flag (__DISABLE_TRACE_MMIO__) which is used to disable MMIO tracing in nVHE KVM and if required can be used to disable MMIO tracing for specific drivers.

This "add a build flag to a Makefile to change how a driver operates" feels very wrong to me given that this is now a totally new way to control how a driver works at build time. That's not anything we have done before for drivers and if added, is only going to create much added complexity.

How about requiring that the #define be in the .c files, and not in the Makefile, as Makefile changes are much much harder to notice and review over time.

Also, I see that this "disable the trace" feature has already been asked for for 2 other drivers in the Android kernel tree, why not include those changes here as well? That kind of shows that this new feature is limited in that driver authors are already wanting it disabled, even before it is accepted.

Because of that, who _will_ be using this feature?

thanks,

greg k-h

#14 lore raw

Re: [PATCHv11 6/6] asm-generic/io: Add logging support for MMIO accessors

In reply to Sai Prakash Ranjan
Quoted 5 lines · Sai Prakash Ranjan

Add logging support for MMIO high level accessors such as read{b,w,l,q} and their relaxed versions to aid in debugging unexpected crashes/hangs caused by the corresponding MMIO operation. Also add a generic flag (__DISABLE_TRACE_MMIO__) which is used to disable MMIO tracing in nVHE KVM and if required can be used to disable MMIO tracing for specific drivers.

Also, this should be split up into 2 patches, one to add the "disable the feature" flag, and one to enable it for the specific driver(s) you want.

Hint, when you say "also" in a changelog text, that's a huge sign that it perhaps should be split up into smaller pieces.

thanks,

greg k-h

#8 lore raw

Re: [PATCHv11 6/6] asm-generic/io: Add logging support for MMIO accessors

In reply to Greg KH
Quoted 11 lines · Greg KH
Quoted 5 lines · Sai Prakash Ranjan

Add logging support for MMIO high level accessors such as read{b,w,l,q} and their relaxed versions to aid in debugging unexpected crashes/hangs caused by the corresponding MMIO operation. Also add a generic flag (__DISABLE_TRACE_MMIO__) which is used to disable MMIO tracing in nVHE KVM and if required can be used to disable MMIO tracing for specific drivers.

This "add a build flag to a Makefile to change how a driver operates" feels very wrong to me given that this is now a totally new way to control how a driver works at build time. That's not anything we have done before for drivers and if added, is only going to create much added complexity.

Not exactly, there are already many such build flags being used currently across kernel.

Example: "-D__KVM_NVHE_HYPERVISOR__, D__KVM_VHE_HYPERVISOR__, -D__NO_FORTIFY, -D__DISABLE_EXPORTS, -DDISABLE_BRANCH_PROFILING".

It gives us even more flexibility to disable feature for multiple files under a directory rather than individually cluttering each file, look at "-D__KVM_NVHE_HYPERVISOR__" for files under "arch/arm64/kvm/hyp/nvhe/".

Quoted 3 lines

How about requiring that the #define be in the .c files, and not in the Makefile, as Makefile changes are much much harder to notice and review over time.

How is this cleaner, lets say we have many such drivers like all drivers under drivers/serial, so we go and add #define for each of them? That looks more spread out than having all such information under one file (Makefile).

And I didn't understand how is it harder to track changes to makefile? Makefile is  part of the driver directory and any changes to makefile is visible to the corresponding maintainers. Do you mean something else?

Quoted 6 lines

Also, I see that this "disable the trace" feature has already been asked for for 2 other drivers in the Android kernel tree, why not include those changes here as well? That kind of shows that this new feature is limited in that driver authors are already wanting it disabled, even before it is accepted.

That can be done later on top of this series right? This series mainly deals with adding initial support for such tracing, there could be numerous drivers who might or might not want the feature which can be added onto later. We can't actually identify all the driver requirements upfront. As an example, we have already used the flag to disable tracing for nVHE KVM, so we know how to use the flag.

Quoted 2 lines

Because of that, who _will_ be using this feature?

Every driver except those two or few more, and it is not a bug or anything, they just want to disable it to limit the logs in case of example UART driver since the reads/writes are very frequent in those cases and the logs are not necessarily useful for them.

Thanks,
Sai

#15 lore raw

Re: [PATCHv11 6/6] asm-generic/io: Add logging support for MMIO accessors

In reply to Greg KH
Quoted 6 lines · Greg KH
Quoted 5 lines · Sai Prakash Ranjan

Add logging support for MMIO high level accessors such as read{b,w,l,q} and their relaxed versions to aid in debugging unexpected crashes/hangs caused by the corresponding MMIO operation. Also add a generic flag (__DISABLE_TRACE_MMIO__) which is used to disable MMIO tracing in nVHE KVM and if required can be used to disable MMIO tracing for specific drivers.

Quoted 7 lines

Also, this should be split up into 2 patches, one to add the "disable the feature" flag, and one to enable it for the specific driver(s) you want.

Hint, when you say "also" in a changelog text, that's a huge sign that it perhaps should be split up into smaller pieces.

Right, will split them.

Thanks,
Sai

#9 lore raw

Re: [PATCHv11 6/6] asm-generic/io: Add logging support for MMIO accessors

In reply to Sai Prakash Ranjan
Quoted 13 lines · Sai Prakash Ranjan
Quoted 11 lines · Greg KH
Quoted 5 lines · Sai Prakash Ranjan

Add logging support for MMIO high level accessors such as read{b,w,l,q} and their relaxed versions to aid in debugging unexpected crashes/hangs caused by the corresponding MMIO operation. Also add a generic flag (__DISABLE_TRACE_MMIO__) which is used to disable MMIO tracing in nVHE KVM and if required can be used to disable MMIO tracing for specific drivers.

This "add a build flag to a Makefile to change how a driver operates" feels very wrong to me given that this is now a totally new way to control how a driver works at build time. That's not anything we have done before for drivers and if added, is only going to create much added complexity.

Quoted 3 lines

Not exactly, there are already many such build flags being used currently across kernel.

Example: "-D__KVM_NVHE_HYPERVISOR__, D__KVM_VHE_HYPERVISOR__,

That's crazy KVM stuff, don't extrapoloate that to all kernel drivers please.

Quoted 1 line

-D__NO_FORTIFY, -D__DISABLE_EXPORTS, -DDISABLE_BRANCH_PROFILING".

Those are compiler flags that affect gcc, not kernel code functionality.

Quoted 3 lines

It gives us even more flexibility to disable feature for multiple files under a directory rather than individually cluttering each file, look at "-D__KVM_NVHE_HYPERVISOR__" for files under "arch/arm64/kvm/hyp/nvhe/".

Again, crazy KVM stuff, do not want that for all drivers in the kernel.

Quoted 7 lines
Quoted 3 lines

How about requiring that the #define be in the .c files, and not in the Makefile, as Makefile changes are much much harder to notice and review over time.

How is this cleaner, lets say we have many such drivers like all drivers under drivers/serial, so we go and add #define for each of them? That looks more spread out than having all such information under one file (Makefile).

If you have to go and add this to each and every driver, that is a HUGE hint that this feature is not a good one and that no one should be using it in the first place, right?

Again, this is a new way to modify driver functionality that is outside of the driver itself, which is not something that I would like to see added without a whole lot of discussion and planning. To throw it in as part of a kvm change is not a nice way to hide such a thing.

Quoted 3 lines

And I didn't understand how is it harder to track changes to makefile? Makefile is  part of the driver directory and any changes to makefile is visible to the corresponding maintainers. Do you mean something else?

I mean that we review driver changes all the time, and code is self-contained and the functionality is only affected right now by Kconfig options, and what is in the .c files itself. You are adding a new way to change functionality by adding a Makefile configuration option as well. That is a major functional change for how we do our configuration logic in Linux.

Quoted 11 lines
Quoted 5 lines

Also, I see that this "disable the trace" feature has already been asked for for 2 other drivers in the Android kernel tree, why not include those changes here as well? That kind of shows that this new feature is limited in that driver authors are already wanting it disabled, even before it is accepted.

That can be done later on top of this series right? This series mainly deals with adding initial support for such tracing, there could be numerous drivers who might or might not want the feature which can be added onto later. We can't actually identify all the driver requirements upfront. As an example, we have already used the flag to disable tracing for nVHE KVM, so we know how to use the flag.

Again, make it explicit in the driver file itself that it is doing this, not in the Makefile, and I will not have any objections.

Quoted 6 lines
Quoted 2 lines

Because of that, who _will_ be using this feature?

Every driver except those two or few more, and it is not a bug or anything, they just want to disable it to limit the logs in case of example UART driver since the reads/writes are very frequent in those cases and the logs are not necessarily useful for them.

I have a feeling that lots more drivers will want this disabled due to the noise it will cause. The fact that we already have 2 requests to change this _before_ the code is even merged is proof of that.

thanks,

greg k-h

#10 lore raw

Re: [PATCHv11 6/6] asm-generic/io: Add logging support for MMIO accessors

Quoted 13 lines · Greg KH
Quoted 12 lines · Sai Prakash Ranjan
Quoted 11 lines · Greg KH
Quoted 5 lines · Sai Prakash Ranjan

Add logging support for MMIO high level accessors such as read{b,w,l,q} and their relaxed versions to aid in debugging unexpected crashes/hangs caused by the corresponding MMIO operation. Also add a generic flag (__DISABLE_TRACE_MMIO__) which is used to disable MMIO tracing in nVHE KVM and if required can be used to disable MMIO tracing for specific drivers.

This "add a build flag to a Makefile to change how a driver operates" feels very wrong to me given that this is now a totally new way to control how a driver works at build time. That's not anything we have done before for drivers and if added, is only going to create much added complexity.

Quoted 5 lines
Quoted 3 lines

Not exactly, there are already many such build flags being used currently across kernel.

Example: "-D__KVM_NVHE_HYPERVISOR__, D__KVM_VHE_HYPERVISOR__,

That's crazy KVM stuff, don't extrapoloate that to all kernel drivers please.

Ok :)

Quoted 14 lines
Quoted 1 line

-D__NO_FORTIFY, -D__DISABLE_EXPORTS, -DDISABLE_BRANCH_PROFILING".

Those are compiler flags that affect gcc, not kernel code functionality.

Quoted 3 lines

It gives us even more flexibility to disable feature for multiple files under a directory rather than individually cluttering each file, look at "-D__KVM_NVHE_HYPERVISOR__" for files under "arch/arm64/kvm/hyp/nvhe/".

Again, crazy KVM stuff, do not want that for all drivers in the kernel.

Quoted 6 lines
Quoted 3 lines

How about requiring that the #define be in the .c files, and not in the Makefile, as Makefile changes are much much harder to notice and review over time.

How is this cleaner, lets say we have many such drivers like all drivers under drivers/serial, so we go and add #define for each of them? That looks more spread out than having all such information under one file (Makefile).

Quoted 8 lines

If you have to go and add this to each and every driver, that is a HUGE hint that this feature is not a good one and that no one should be using it in the first place, right?

Again, this is a new way to modify driver functionality that is outside of the driver itself, which is not something that I would like to see added without a whole lot of discussion and planning. To throw it in as part of a kvm change is not a nice way to hide such a thing.

Sure, will make the change as you suggested.

Quoted 9 lines
Quoted 3 lines

And I didn't understand how is it harder to track changes to makefile? Makefile is  part of the driver directory and any changes to makefile is visible to the corresponding maintainers. Do you mean something else?

I mean that we review driver changes all the time, and code is self-contained and the functionality is only affected right now by Kconfig options, and what is in the .c files itself. You are adding a new way to change functionality by adding a Makefile configuration option as well. That is a major functional change for how we do our configuration logic in Linux.

Ah ok, you mean like that. Sure I don't have any strong opinion, so will move it to the driver file.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Also, I see that this "disable the trace" feature has already been asked for for 2 other drivers in the Android kernel tree, why not include those changes here as well? That kind of shows that this new feature is limited in that driver authors are already wanting it disabled, even before it is accepted.

Quoted 7 lines
Quoted 5 lines

That can be done later on top of this series right? This series mainly deals with adding initial support for such tracing, there could be numerous drivers who might or might not want the feature which can be added onto later. We can't actually identify all the driver requirements upfront. As an example, we have already used the flag to disable tracing for nVHE KVM, so we know how to use the flag.

Again, make it explicit in the driver file itself that it is doing this, not in the Makefile, and I will not have any objections.

Ok, for kernel drivers I will make the define at the top of the .c driver file and include those 2 driver changes in the series.

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

Because of that, who _will_ be using this feature?

Every driver except those two or few more, and it is not a bug or anything, they just want to disable it to limit the logs in case of example UART driver since the reads/writes are very frequent in those cases and the logs are not necessarily useful for them.

Quoted 7 lines

I have a feeling that lots more drivers will want this disabled due to the noise it will cause. The fact that we already have 2 requests to change this _before_ the code is even merged is proof of that.

thanks,

greg k-h

Thanks,
Sai

maintainer
#12 lore raw

Re: [PATCHv11 6/6] asm-generic/io: Add logging support for MMIO accessors

In reply to Greg KH
Quoted 8 lines · Greg KH
Quoted 4 lines · Sai Prakash Ranjan
Quoted 1 line · Greg KH

On Thu, Apr 28, 2022 at 09:00:13AM +0530, Sai Prakash Ranjan wrote:

-D__NO_FORTIFY, -D__DISABLE_EXPORTS, -DDISABLE_BRANCH_PROFILING".

Those are compiler flags that affect gcc, not kernel code functionality.

It's normal for invasive instrumentation to need flags to disable them. If you look at mm/kasan/Makefile, you see

KASAN_SANITIZE := n
UBSAN_SANITIZE := n
KCOV_INSTRUMENT := n
CC_FLAGS_KASAN_RUNTIME += -DDISABLE_BRANCH_PROFILING CFLAGS_REMOVE_common.o = $(CC_FLAGS_FTRACE)

all of which disable one of the instrumentation options, either per file or per directory, in order to break recursion.

I don't know where exactly there is a problem with recursion in the MMIO trace, but I can imagine that one of the other instrumentations ends up doing an MMIO operation on some machine.

The part you obviously need to avoid is that running 'perf record' to trace the MMIOs itself triggers more MMIO.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

Also, I see that this "disable the trace" feature has already been asked for for 2 other drivers in the Android kernel tree, why not include those changes here as well? That kind of shows that this new feature is limited in that driver authors are already wanting it disabled, even before it is accepted.

Quoted 8 lines
Quoted 5 lines

That can be done later on top of this series right? This series mainly deals with adding initial support for such tracing, there could be numerous drivers who might or might not want the feature which can be added onto later. We can't actually identify all the driver requirements upfront. As an example, we have already used the flag to disable tracing for nVHE KVM, so we know how to use the flag.

Again, make it explicit in the driver file itself that it is doing this, not in the Makefile, and I will not have any objections.

We discussed a few options already, but we can revisit this again. The current solution has a per-file compile-time switch and a global runtime switch for the tracepoint.

I think moving the tracepoint into the header would make it a per-file runtime switch (depending on how it gets inlined etc). I think that would avoid the need for having the compile-time disable switch, but may result in an excessive number of tracepoints.

Arnd

#11 lore raw

Re: [PATCHv11 6/6] asm-generic/io: Add logging support for MMIO accessors

In reply to Sai Prakash Ranjan
Quoted 10 lines · Sai Prakash Ranjan
Quoted 10 lines
Quoted 10 lines
Quoted 5 lines

Also, I see that this "disable the trace" feature has already been asked for for 2 other drivers in the Android kernel tree, why not include those changes here as well? That kind of shows that this new feature is limited in that driver authors are already wanting it disabled, even before it is accepted.

That can be done later on top of this series right? This series mainly deals with adding initial support for such tracing, there could be numerous drivers who might or might not want the feature which can be added onto later. We can't actually identify all the driver requirements upfront. As an example, we have already used the flag to disable tracing for nVHE KVM, so we know how to use the flag.

Quoted 5 lines
Quoted 2 lines

Again, make it explicit in the driver file itself that it is doing this, not in the Makefile, and I will not have any objections.

Ok, for kernel drivers I will make the define at the top of the .c driver file and include those 2 driver changes in the series.

Thank you, that is a much better way forward.

greg k-h

#13 lore raw

Re: [PATCHv11 6/6] asm-generic/io: Add logging support for MMIO accessors

In reply to Arnd Bergmann
Quoted 13 lines · Arnd Bergmann
Quoted 8 lines · Greg KH
Quoted 4 lines · Sai Prakash Ranjan
Quoted 1 line · Greg KH

On Thu, Apr 28, 2022 at 09:00:13AM +0530, Sai Prakash Ranjan wrote:

-D__NO_FORTIFY, -D__DISABLE_EXPORTS, -DDISABLE_BRANCH_PROFILING".

Those are compiler flags that affect gcc, not kernel code functionality.

It's normal for invasive instrumentation to need flags to disable them. If you look at mm/kasan/Makefile, you see

Quoted 8 lines

KASAN_SANITIZE := n
UBSAN_SANITIZE := n
KCOV_INSTRUMENT := n
CC_FLAGS_KASAN_RUNTIME += -DDISABLE_BRANCH_PROFILING CFLAGS_REMOVE_common.o = $(CC_FLAGS_FTRACE)

all of which disable one of the instrumentation options, either per file or per directory, in order to break recursion.

That's not for logging stuff (which seems to change the functionality of the driver), it's for system-wide profiling/code-coverage/checking/etc type of stuff.

Let's keep a #define at the top of the driver for the drivers that absolutely need this feature disabled as it is much easier to track that and to see how it affects things. If you put it in a Makefile, reviewers will miss it and wonder what is going on.

thanks,

greg k-h