Skip to content

Commit 6c881ca

Browse files
committed
afs: Fix tracepoint string placement with built-in AFS
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: 8e8d7f1 ("afs: Add some tracepoints") Reported-by: Alexey Dobriyan (SK hynix) <[email protected]> Signed-off-by: David Howells <[email protected]> Reviewed-by: Steven Rostedt (VMware) <[email protected]> Reviewed-by: Marc Dionne <[email protected]> cc: Andrew Morton <[email protected]> cc: [email protected] Link: https://lore.kernel.org/r/YLAXfvZ+rObEOdc%[email protected]/ [1] Link: https://lore.kernel.org/r/[email protected]/ 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
1 parent e73f0f0 commit 6c881ca

File tree

2 files changed

+69
-23
lines changed

2 files changed

+69
-23
lines changed

fs/afs/cmservice.c

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,11 @@ static void SRXAFSCB_TellMeAboutYourself(struct work_struct *);
2929

3030
static int afs_deliver_yfs_cb_callback(struct afs_call *);
3131

32-
#define CM_NAME(name) \
33-
char afs_SRXCB##name##_name[] __tracepoint_string = \
34-
"CB." #name
35-
3632
/*
3733
* CB.CallBack operation type
3834
*/
39-
static CM_NAME(CallBack);
4035
static const struct afs_call_type afs_SRXCBCallBack = {
41-
.name = afs_SRXCBCallBack_name,
36+
.name = "CB.CallBack",
4237
.deliver = afs_deliver_cb_callback,
4338
.destructor = afs_cm_destructor,
4439
.work = SRXAFSCB_CallBack,
@@ -47,9 +42,8 @@ static const struct afs_call_type afs_SRXCBCallBack = {
4742
/*
4843
* CB.InitCallBackState operation type
4944
*/
50-
static CM_NAME(InitCallBackState);
5145
static const struct afs_call_type afs_SRXCBInitCallBackState = {
52-
.name = afs_SRXCBInitCallBackState_name,
46+
.name = "CB.InitCallBackState",
5347
.deliver = afs_deliver_cb_init_call_back_state,
5448
.destructor = afs_cm_destructor,
5549
.work = SRXAFSCB_InitCallBackState,
@@ -58,9 +52,8 @@ static const struct afs_call_type afs_SRXCBInitCallBackState = {
5852
/*
5953
* CB.InitCallBackState3 operation type
6054
*/
61-
static CM_NAME(InitCallBackState3);
6255
static const struct afs_call_type afs_SRXCBInitCallBackState3 = {
63-
.name = afs_SRXCBInitCallBackState3_name,
56+
.name = "CB.InitCallBackState3",
6457
.deliver = afs_deliver_cb_init_call_back_state3,
6558
.destructor = afs_cm_destructor,
6659
.work = SRXAFSCB_InitCallBackState,
@@ -69,9 +62,8 @@ static const struct afs_call_type afs_SRXCBInitCallBackState3 = {
6962
/*
7063
* CB.Probe operation type
7164
*/
72-
static CM_NAME(Probe);
7365
static const struct afs_call_type afs_SRXCBProbe = {
74-
.name = afs_SRXCBProbe_name,
66+
.name = "CB.Probe",
7567
.deliver = afs_deliver_cb_probe,
7668
.destructor = afs_cm_destructor,
7769
.work = SRXAFSCB_Probe,
@@ -80,9 +72,8 @@ static const struct afs_call_type afs_SRXCBProbe = {
8072
/*
8173
* CB.ProbeUuid operation type
8274
*/
83-
static CM_NAME(ProbeUuid);
8475
static const struct afs_call_type afs_SRXCBProbeUuid = {
85-
.name = afs_SRXCBProbeUuid_name,
76+
.name = "CB.ProbeUuid",
8677
.deliver = afs_deliver_cb_probe_uuid,
8778
.destructor = afs_cm_destructor,
8879
.work = SRXAFSCB_ProbeUuid,
@@ -91,9 +82,8 @@ static const struct afs_call_type afs_SRXCBProbeUuid = {
9182
/*
9283
* CB.TellMeAboutYourself operation type
9384
*/
94-
static CM_NAME(TellMeAboutYourself);
9585
static const struct afs_call_type afs_SRXCBTellMeAboutYourself = {
96-
.name = afs_SRXCBTellMeAboutYourself_name,
86+
.name = "CB.TellMeAboutYourself",
9787
.deliver = afs_deliver_cb_tell_me_about_yourself,
9888
.destructor = afs_cm_destructor,
9989
.work = SRXAFSCB_TellMeAboutYourself,
@@ -102,9 +92,8 @@ static const struct afs_call_type afs_SRXCBTellMeAboutYourself = {
10292
/*
10393
* YFS CB.CallBack operation type
10494
*/
105-
static CM_NAME(YFS_CallBack);
10695
static const struct afs_call_type afs_SRXYFSCB_CallBack = {
107-
.name = afs_SRXCBYFS_CallBack_name,
96+
.name = "YFSCB.CallBack",
10897
.deliver = afs_deliver_yfs_cb_callback,
10998
.destructor = afs_cm_destructor,
11099
.work = SRXAFSCB_CallBack,

include/trace/events/afs.h

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,34 @@ enum afs_vl_operation {
174174
afs_VL_GetCapabilities = 65537, /* AFS Get VL server capabilities */
175175
};
176176

177+
enum afs_cm_operation {
178+
afs_CB_CallBack = 204, /* AFS break callback promises */
179+
afs_CB_InitCallBackState = 205, /* AFS initialise callback state */
180+
afs_CB_Probe = 206, /* AFS probe client */
181+
afs_CB_GetLock = 207, /* AFS get contents of CM lock table */
182+
afs_CB_GetCE = 208, /* AFS get cache file description */
183+
afs_CB_GetXStatsVersion = 209, /* AFS get version of extended statistics */
184+
afs_CB_GetXStats = 210, /* AFS get contents of extended statistics data */
185+
afs_CB_InitCallBackState3 = 213, /* AFS initialise callback state, version 3 */
186+
afs_CB_ProbeUuid = 214, /* AFS check the client hasn't rebooted */
187+
};
188+
189+
enum yfs_cm_operation {
190+
yfs_CB_Probe = 206, /* YFS probe client */
191+
yfs_CB_GetLock = 207, /* YFS get contents of CM lock table */
192+
yfs_CB_XStatsVersion = 209, /* YFS get version of extended statistics */
193+
yfs_CB_GetXStats = 210, /* YFS get contents of extended statistics data */
194+
yfs_CB_InitCallBackState3 = 213, /* YFS initialise callback state, version 3 */
195+
yfs_CB_ProbeUuid = 214, /* YFS check the client hasn't rebooted */
196+
yfs_CB_GetServerPrefs = 215,
197+
yfs_CB_GetCellServDV = 216,
198+
yfs_CB_GetLocalCell = 217,
199+
yfs_CB_GetCacheConfig = 218,
200+
yfs_CB_GetCellByNum = 65537,
201+
yfs_CB_TellMeAboutYourself = 65538, /* get client capabilities */
202+
yfs_CB_CallBack = 64204,
203+
};
204+
177205
enum afs_edit_dir_op {
178206
afs_edit_dir_create,
179207
afs_edit_dir_create_error,
@@ -436,6 +464,32 @@ enum afs_cb_break_reason {
436464
EM(afs_YFSVL_GetCellName, "YFSVL.GetCellName") \
437465
E_(afs_VL_GetCapabilities, "VL.GetCapabilities")
438466

467+
#define afs_cm_operations \
468+
EM(afs_CB_CallBack, "CB.CallBack") \
469+
EM(afs_CB_InitCallBackState, "CB.InitCallBackState") \
470+
EM(afs_CB_Probe, "CB.Probe") \
471+
EM(afs_CB_GetLock, "CB.GetLock") \
472+
EM(afs_CB_GetCE, "CB.GetCE") \
473+
EM(afs_CB_GetXStatsVersion, "CB.GetXStatsVersion") \
474+
EM(afs_CB_GetXStats, "CB.GetXStats") \
475+
EM(afs_CB_InitCallBackState3, "CB.InitCallBackState3") \
476+
E_(afs_CB_ProbeUuid, "CB.ProbeUuid")
477+
478+
#define yfs_cm_operations \
479+
EM(yfs_CB_Probe, "YFSCB.Probe") \
480+
EM(yfs_CB_GetLock, "YFSCB.GetLock") \
481+
EM(yfs_CB_XStatsVersion, "YFSCB.XStatsVersion") \
482+
EM(yfs_CB_GetXStats, "YFSCB.GetXStats") \
483+
EM(yfs_CB_InitCallBackState3, "YFSCB.InitCallBackState3") \
484+
EM(yfs_CB_ProbeUuid, "YFSCB.ProbeUuid") \
485+
EM(yfs_CB_GetServerPrefs, "YFSCB.GetServerPrefs") \
486+
EM(yfs_CB_GetCellServDV, "YFSCB.GetCellServDV") \
487+
EM(yfs_CB_GetLocalCell, "YFSCB.GetLocalCell") \
488+
EM(yfs_CB_GetCacheConfig, "YFSCB.GetCacheConfig") \
489+
EM(yfs_CB_GetCellByNum, "YFSCB.GetCellByNum") \
490+
EM(yfs_CB_TellMeAboutYourself, "YFSCB.TellMeAboutYourself") \
491+
E_(yfs_CB_CallBack, "YFSCB.CallBack")
492+
439493
#define afs_edit_dir_ops \
440494
EM(afs_edit_dir_create, "create") \
441495
EM(afs_edit_dir_create_error, "c_fail") \
@@ -569,6 +623,8 @@ afs_server_traces;
569623
afs_cell_traces;
570624
afs_fs_operations;
571625
afs_vl_operations;
626+
afs_cm_operations;
627+
yfs_cm_operations;
572628
afs_edit_dir_ops;
573629
afs_edit_dir_reasons;
574630
afs_eproto_causes;
@@ -649,20 +705,21 @@ TRACE_EVENT(afs_cb_call,
649705

650706
TP_STRUCT__entry(
651707
__field(unsigned int, call )
652-
__field(const char *, name )
653708
__field(u32, op )
709+
__field(u16, service_id )
654710
),
655711

656712
TP_fast_assign(
657713
__entry->call = call->debug_id;
658-
__entry->name = call->type->name;
659714
__entry->op = call->operation_ID;
715+
__entry->service_id = call->service_id;
660716
),
661717

662-
TP_printk("c=%08x %s o=%u",
718+
TP_printk("c=%08x %s",
663719
__entry->call,
664-
__entry->name,
665-
__entry->op)
720+
__entry->service_id == 2501 ?
721+
__print_symbolic(__entry->op, yfs_cm_operations) :
722+
__print_symbolic(__entry->op, afs_cm_operations))
666723
);
667724

668725
TRACE_EVENT(afs_call,

0 commit comments

Comments
 (0)