kernel_optimize_test/fs/afs
David Howells 0f5dc39714 afs: Fix tracepoint string placement with built-in AFS
[ Upstream commit 6c881ca0b3040f3e724eae513117ba4ddef86057 ]

To quote Alexey[1]:

    I was adding custom tracepoint to the kernel, grabbed full F34 kernel
    .config, disabled modules and booted whole shebang as VM kernel.

    Then did

	perf record -a -e ...

    It crashed:

	general protection fault, probably for non-canonical address 0x435f5346592e4243: 0000 [#1] SMP PTI
	CPU: 1 PID: 842 Comm: cat Not tainted 5.12.6+ #26
	Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-1.fc33 04/01/2014
	RIP: 0010:t_show+0x22/0xd0

    Then reproducer was narrowed to

	# cat /sys/kernel/tracing/printk_formats

    Original F34 kernel with modules didn't crash.

    So I started to disable options and after disabling AFS everything
    started working again.

    The root cause is that AFS was placing char arrays content into a
    section full of _pointers_ to strings with predictable consequences.

    Non canonical address 435f5346592e4243 is "CB.YFS_" which came from
    CM_NAME macro.

    Steps to reproduce:

	CONFIG_AFS=y
	CONFIG_TRACING=y

	# cat /sys/kernel/tracing/printk_formats

Fix this by the following means:

 (1) Add enum->string translation tables in the event header with the AFS
     and YFS cache/callback manager operations listed by RPC operation ID.

 (2) Modify the afs_cb_call tracepoint to print the string from the
     translation table rather than using the string at the afs_call name
     pointer.

 (3) Switch translation table depending on the service we're being accessed
     as (AFS or YFS) in the tracepoint print clause.  Will this cause
     problems to userspace utilities?

     Note that the symbolic representation of the YFS service ID isn't
     available to this header, so I've put it in as a number.  I'm not sure
     if this is the best way to do this.

 (4) Remove the name wrangling (CM_NAME) macro and put the names directly
     into the afs_call_type structs in cmservice.c.

Fixes: 8e8d7f13b6 ("afs: Add some tracepoints")
Reported-by: Alexey Dobriyan (SK hynix) <adobriyan@gmail.com>
Signed-off-by: David Howells <dhowells@redhat.com>
Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Reviewed-by: Marc Dionne <marc.dionne@auristor.com>
cc: Andrew Morton <akpm@linux-foundation.org>
cc: linux-afs@lists.infradead.org
Link: https://lore.kernel.org/r/YLAXfvZ+rObEOdc%2F@localhost.localdomain/ [1]
Link: https://lore.kernel.org/r/643721.1623754699@warthog.procyon.org.uk/
Link: https://lore.kernel.org/r/162430903582.2896199.6098150063997983353.stgit@warthog.procyon.org.uk/ # v1
Link: https://lore.kernel.org/r/162609463957.3133237.15916579353149746363.stgit@warthog.procyon.org.uk/ # v1 (repost)
Link: https://lore.kernel.org/r/162610726860.3408253.445207609466288531.stgit@warthog.procyon.org.uk/ # v2
Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-07-28 14:35:41 +02:00
..
addr_list.c
afs_cm.h
afs_fs.h
afs_vl.h
afs.h
cache.c
callback.c
cell.c afs: Fix tracing deref-before-check 2020-10-27 22:05:56 +00:00
cmservice.c afs: Fix tracepoint string placement with built-in AFS 2021-07-28 14:35:41 +02:00
dir_edit.c afs: Fix to take ref on page when PG_private is set 2020-10-29 13:53:04 +00:00
dir_silly.c afs: Fix speculative status fetches 2021-05-14 09:50:45 +02:00
dir.c afs: Fix the nlink handling of dir-over-dir rename 2021-06-03 09:00:39 +02:00
dynroot.c
file.c afs: Stop listxattr() from listing "afs.*" attributes 2021-03-25 09:04:07 +01:00
flock.c
fs_operation.c afs: Fix speculative status fetches 2021-05-14 09:50:45 +02:00
fs_probe.c
fsclient.c
inode.c afs: Fix speculative status fetches 2021-05-14 09:50:45 +02:00
internal.h afs: Fix speculative status fetches 2021-05-14 09:50:45 +02:00
Kconfig
main.c afs: Fix an IS_ERR() vs NULL check 2021-06-23 14:42:40 +02:00
Makefile
misc.c
mntpt.c afs: Stop listxattr() from listing "afs.*" attributes 2021-03-25 09:04:07 +01:00
proc.c
protocol_uae.h
protocol_yfs.h
rotate.c
rxrpc.c
security.c
server_list.c
server.c
super.c afs: Fix memory leak when mounting with multiple source parameters 2020-12-08 15:59:25 -08:00
vl_alias.c
vl_list.c
vl_probe.c
vl_rotate.c
vlclient.c
volume.c
write.c afs: Fix speculative status fetches 2021-05-14 09:50:45 +02:00
xattr.c afs: Stop listxattr() from listing "afs.*" attributes 2021-03-25 09:04:07 +01:00
xdr_fs.h
yfsclient.c afs: Fix warning due to unadvanced marshalling pointer 2020-11-03 09:53:40 -08:00