6.12.112-rc1 review
Greg Kroah-Hartman
maintainerPATCH 716/877 tracing: Constify struct event_trigger_ops
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christophe JAILLET <[email protected]>
[ Upstream commit 502d2e71a89fa706843fa9277f4d6de1947072c8 ]
'event_trigger_ops mwifiex_if_ops' are not modified in these drivers.
Constifying these structures moves some data to a read-only section, so increase overall security, especially when the structure holds some function pointers.
On a x86_64, with allmodconfig, as an example:
Before:
======
text data bss dec hex filename
31368 9024 6200 46592 b600 kernel/trace/trace_events_trigger.o
After:
=====
text data bss dec hex filename
31752 8608 6200 46560 b5e0 kernel/trace/trace_events_trigger.o
Stable-dep-of: 6ede78d0563a ("tracing: Set the trace clock before registering the histogram trigger")
--- kernel/trace/trace.h | 4 +-- kernel/trace/trace_eprobe.c | 6 ++--- kernel/trace/trace_events_hist.c | 20 +++++++++--------- kernel/trace/trace_events_trigger.c | 38 ++++++++++++++++++------------------ 4 files changed, 34 insertions(+), 34 deletions(-)
kernel/trace/trace.h +2 -2
@@ -1698,7 +1698,7 @@ struct event_trigger_data {unsigned long count;int ref;int flags; -struct event_trigger_ops *ops; +const struct event_trigger_ops *ops;struct event_command *cmd_ops;struct event_filter __rcu *filter;char *filter_str;
@@ -1941,7 +1941,7 @@ struct event_command {int (*set_filter)(char *filter_str,struct event_trigger_data *data,struct trace_event_file *file); -struct event_trigger_ops *(*get_trigger_ops)(char *cmd,char *param); +const struct event_trigger_ops *(*get_trigger_ops)(char *cmd,char *param); };/**
kernel/trace/trace_eprobe.c +3 -3
@@ -479,7 +479,7 @@ static void eprobe_trigger_func(struct e__eprobe_trace_func (edata, rec); } -static struct event_trigger_ops eprobe_trigger_ops = { +static const struct event_trigger_ops eprobe_trigger_ops = { .trigger = eprobe_trigger_func, .print = eprobe_trigger_print, .init = eprobe_trigger_init,
@@ -508,8 +508,8 @@ static void eprobe_trigger_unreg_func(ch } -static struct event_trigger_ops *eprobe_trigger_get_ops (char *cmd, -char *param) +static const struct event_trigger_ops *eprobe_trigger_get_ops (char *cmd, +char *param) {return &eprobe_trigger_ops; }
kernel/trace/trace_events_hist.c +10 -10
@@ -6323,7 +6323,7 @@ static void event_hist_trigger_free(strufree_hist_pad (); } -static struct event_trigger_ops event_hist_trigger_ops = { +static const struct event_trigger_ops event_hist_trigger_ops = { .trigger = event_hist_trigger, .print = event_hist_trigger_print, .init = event_hist_trigger_init,
@@ -6353,15 +6353,15 @@ static void event_hist_trigger_named_fre } } -static struct event_trigger_ops event_hist_trigger_named_ops = { +static const struct event_trigger_ops event_hist_trigger_named_ops = { .trigger = event_hist_trigger, .print = event_hist_trigger_print, .init = event_hist_trigger_named_init, .free = event_hist_trigger_named_free, }; -static struct event_trigger_ops *event_hist_get_trigger_ops (char *cmd, -char *param) +static const struct event_trigger_ops *event_hist_get_trigger_ops (char *cmd, +char *param) {return &event_hist_trigger_ops; }
@@ -6958,38 +6958,38 @@ hist_enable_count_trigger(struct event_thist_enable_trigger (data, buffer, rec, event); } -static struct event_trigger_ops hist_enable_trigger_ops = { +static const struct event_trigger_ops hist_enable_trigger_ops = { .trigger = hist_enable_trigger, .print = event_enable_trigger_print, .init = event_trigger_init, .free = event_enable_trigger_free, }; -static struct event_trigger_ops hist_enable_count_trigger_ops = { +static const struct event_trigger_ops hist_enable_count_trigger_ops = { .trigger = hist_enable_count_trigger, .print = event_enable_trigger_print, .init = event_trigger_init, .free = event_enable_trigger_free, }; -static struct event_trigger_ops hist_disable_trigger_ops = { +static const struct event_trigger_ops hist_disable_trigger_ops = { .trigger = hist_enable_trigger, .print = event_enable_trigger_print, .init = event_trigger_init, .free = event_enable_trigger_free, }; -static struct event_trigger_ops hist_disable_count_trigger_ops = { +static const struct event_trigger_ops hist_disable_count_trigger_ops = { .trigger = hist_enable_count_trigger, .print = event_enable_trigger_print, .init = event_trigger_init, .free = event_enable_trigger_free, }; -static struct event_trigger_ops * +static const struct event_trigger_ops *hist_enable_get_trigger_ops (char *cmd,char *param) { -struct event_trigger_ops *ops; +const struct event_trigger_ops *ops;bool enable; enable = (strcmp (cmd,ENABLE_HIST_STR ) ==0 );
kernel/trace/trace_events_trigger.c +19 -19
@@ -849,7 +849,7 @@ struct event_trigger_data *trigger_data_ void *private_data) {struct event_trigger_data *trigger_data; -struct event_trigger_ops *trigger_ops; +const struct event_trigger_ops *trigger_ops; trigger_ops = cmd_ops->get_trigger_ops (cmd, param);
@@ -1391,38 +1391,38 @@ traceoff_trigger_print(struct seq_file * data->filter_str); } -static struct event_trigger_ops traceon_trigger_ops = { +static const struct event_trigger_ops traceon_trigger_ops = { .trigger = traceon_trigger, .print = traceon_trigger_print, .init = event_trigger_init, .free = event_trigger_free, }; -static struct event_trigger_ops traceon_count_trigger_ops = { +static const struct event_trigger_ops traceon_count_trigger_ops = { .trigger = traceon_count_trigger, .print = traceon_trigger_print, .init = event_trigger_init, .free = event_trigger_free, }; -static struct event_trigger_ops traceoff_trigger_ops = { +static const struct event_trigger_ops traceoff_trigger_ops = { .trigger = traceoff_trigger, .print = traceoff_trigger_print, .init = event_trigger_init, .free = event_trigger_free, }; -static struct event_trigger_ops traceoff_count_trigger_ops = { +static const struct event_trigger_ops traceoff_count_trigger_ops = { .trigger = traceoff_count_trigger, .print = traceoff_trigger_print, .init = event_trigger_init, .free = event_trigger_free, }; -static struct event_trigger_ops * +static const struct event_trigger_ops *onoff_get_trigger_ops (char *cmd,char *param) { -struct event_trigger_ops *ops; +const struct event_trigger_ops *ops;/* we register both traceon and traceoff to this callback */ if (strcmp (cmd,"traceon" ) ==0 )
@@ -1515,21 +1515,21 @@ snapshot_trigger_print(struct seq_file * data->filter_str); } -static struct event_trigger_ops snapshot_trigger_ops = { +static const struct event_trigger_ops snapshot_trigger_ops = { .trigger = snapshot_trigger, .print = snapshot_trigger_print, .init = event_trigger_init, .free = event_trigger_free, }; -static struct event_trigger_ops snapshot_count_trigger_ops = { +static const struct event_trigger_ops snapshot_count_trigger_ops = { .trigger = snapshot_count_trigger, .print = snapshot_trigger_print, .init = event_trigger_init, .free = event_trigger_free, }; -static struct event_trigger_ops * +static const struct event_trigger_ops *snapshot_get_trigger_ops (char *cmd,char *param) {return param ? &snapshot_count_trigger_ops : &snapshot_trigger_ops;
@@ -1610,21 +1610,21 @@ stacktrace_trigger_print(struct seq_file data->filter_str); } -static struct event_trigger_ops stacktrace_trigger_ops = { +static const struct event_trigger_ops stacktrace_trigger_ops = { .trigger = stacktrace_trigger, .print = stacktrace_trigger_print, .init = event_trigger_init, .free = event_trigger_free, }; -static struct event_trigger_ops stacktrace_count_trigger_ops = { +static const struct event_trigger_ops stacktrace_count_trigger_ops = { .trigger = stacktrace_count_trigger, .print = stacktrace_trigger_print, .init = event_trigger_init, .free = event_trigger_free, }; -static struct event_trigger_ops * +static const struct event_trigger_ops *stacktrace_get_trigger_ops (char *cmd,char *param) {return param ? &stacktrace_count_trigger_ops : &stacktrace_trigger_ops;
@@ -1735,28 +1735,28 @@ void event_enable_trigger_free(struct ev } } -static struct event_trigger_ops event_enable_trigger_ops = { +static const struct event_trigger_ops event_enable_trigger_ops = { .trigger = event_enable_trigger, .print = event_enable_trigger_print, .init = event_trigger_init, .free = event_enable_trigger_free, }; -static struct event_trigger_ops event_enable_count_trigger_ops = { +static const struct event_trigger_ops event_enable_count_trigger_ops = { .trigger = event_enable_count_trigger, .print = event_enable_trigger_print, .init = event_trigger_init, .free = event_enable_trigger_free, }; -static struct event_trigger_ops event_disable_trigger_ops = { +static const struct event_trigger_ops event_disable_trigger_ops = { .trigger = event_enable_trigger, .print = event_enable_trigger_print, .init = event_trigger_init, .free = event_enable_trigger_free, }; -static struct event_trigger_ops event_disable_count_trigger_ops = { +static const struct event_trigger_ops event_disable_count_trigger_ops = { .trigger = event_enable_count_trigger, .print = event_enable_trigger_print, .init = event_trigger_init,
@@ -1940,10 +1940,10 @@ void event_enable_unregister_trigger(cha data->ops->free (data); } -static struct event_trigger_ops * +static const struct event_trigger_ops *event_enable_get_trigger_ops (char *cmd,char *param) { -struct event_trigger_ops *ops; +const struct event_trigger_ops *ops;bool enable;#ifdef CONFIG_HIST_TRIGGERS
Greg Kroah-Hartman
maintainerPATCH 717/877 tracing: Remove get_trigger_ops() and add count_func() from trigger ops
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Steven Rostedt <[email protected]>
[ Upstream commit bdafb4d4cb3bb18b29517eaae09fb49d25f854f0 ]
The struct event_command has a callback function called get_trigger_ops(). This callback returns the "trigger_ops" to use for the trigger. These ops define the trigger function, how to init the trigger, how to print the trigger and how to free it.
The only reason there's a callback function to get these ops is because some triggers have two types of operations. One is an "always on" operation, and the other is a "count down" operation. If a user passes in a parameter to say how many times the trigger should execute. For example:
echo stacktrace:5 > events/kmem/kmem_cache_alloc/trigger
It will trigger the stacktrace for the first 5 times the kmem_cache_alloc event is hit.
Instead of having two different trigger_ops since the only difference between them is the tigger itself (the print, init and free functions are all the same), just use a single ops that the event_command points to and add a function field to the trigger_ops to have a count_func.
When a trigger is added to an event, if there's a count attached to it and the trigger ops has the count_func field, the data allocated to represent this trigger will have a new flag set called COUNT.
Then when the trigger executes, it will check if the COUNT data flag is set, and if so, it will call the ops count_func(). If that returns false, it returns without executing the trigger.
This removes the need for duplicate event_trigger_ops structures.
Stable-dep-of: 6ede78d0563a ("tracing: Set the trace clock before registering the histogram trigger")
--- kernel/trace/trace.h | 26 ++- kernel/trace/trace_eprobe.c | 8 - kernel/trace/trace_events_hist.c | 60 -------- kernel/trace/trace_events_trigger.c | 257 ++++++++++++------------------------ 4 files changed, 116 insertions(+), 235 deletions(-)
kernel/trace/trace.h +18 -8
@@ -1692,6 +1692,7 @@ extern void clear_event_triggers(structenum {EVENT_TRIGGER_FL_PROBE =BIT (0 ), +EVENT_TRIGGER_FL_COUNT =BIT (1 ), };struct event_trigger_data {
@@ -1723,6 +1724,10 @@ struct enable_trigger_data {bool hist; }; +bool event_trigger_count (struct event_trigger_data *data, +struct trace_buffer *buffer,void *rec, +struct ring_buffer_event *event); +extern int event_enable_trigger_print (struct seq_file *m,struct event_trigger_data *data);extern void event_enable_trigger_free (struct event_trigger_data *data);
@@ -1810,6 +1815,11 @@ extern void event_file_put(struct trace_* registered the trigger (see struct event_command) along with * the trace record, rec. * +* @count_func: If defined and a numeric parameter is passed to the +* trigger, then this function will be called before @trigger +* is called. If this function returns false, then @trigger is not +* executed. +* * @init: An optional initialization function called for the trigger * when the trigger is registered (via the event_command reg() * function). This can be used to perform per-trigger
@@ -1837,6 +1847,10 @@ struct event_trigger_ops {struct trace_buffer *buffer, void *rec, struct ring_buffer_event *rbe); +bool (*count_func)(struct event_trigger_data *data, +struct trace_buffer *buffer, +void *rec, +struct ring_buffer_event *rbe);int (*init)(struct event_trigger_data *data);void (*free)(struct event_trigger_data *data); int (*print)(struct seq_file *m,
@@ -1863,6 +1877,9 @@ struct event_trigger_ops {* @name: The unique name that identifies the event command. This is * the name used when setting triggers via trigger files. * +* @trigger_ops: The event_trigger_ops implementation associated with +* the command. +* * @trigger_type: A unique id that identifies the event command * 'type'. This value has two purposes, the first to ensure that * only one trigger of the same type can be set at a given time
@@ -1914,17 +1931,11 @@ struct event_trigger_ops {* event command, filters set by the user for the command will be * ignored. This is usually implemented by the generic utility * function @set_trigger_filter() (see trace_event_triggers.c). -* -* @get_trigger_ops: The callback function invoked to retrieve the -* event_trigger_ops implementation associated with the command. -* This callback function allows a single event_command to -* support multiple trigger implementations via different sets of -* event_trigger_ops, depending on the value of the @param -* string. */ struct event_command {struct list_head list;char *name; +const struct event_trigger_ops *trigger_ops;enum event_trigger_type trigger_type;int flags; int (*parse)(struct event_command *cmd_ops,
@@ -1941,7 +1952,6 @@ struct event_command {int (*set_filter)(char *filter_str,struct event_trigger_data *data,struct trace_event_file *file); -const struct event_trigger_ops *(*get_trigger_ops)(char *cmd,char *param); };/**
kernel/trace/trace_eprobe.c +1 -7
@@ -508,21 +508,15 @@ static void eprobe_trigger_unreg_func(ch } -static const struct event_trigger_ops *eprobe_trigger_get_ops (char *cmd, -char *param) -{ -return &eprobe_trigger_ops; -} -static struct event_command event_trigger_cmd = { .name ="eprobe" , .trigger_type =ETT_EVENT_EPROBE , .flags =EVENT_CMD_FL_NEEDS_REC , + .trigger_ops = &eprobe_trigger_ops, .parse = eprobe_trigger_cmd_parse, .reg = eprobe_trigger_reg_func, .unreg = eprobe_trigger_unreg_func, .unreg_all =NULL , - .get_trigger_ops = eprobe_trigger_get_ops, .set_filter =NULL , };
kernel/trace/trace_events_hist.c +5 -55
115 lines not on this page · raw message
kernel/trace/trace_events_trigger.c +92 -165
476 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 718/877 tracing: Merge struct event_trigger_ops into struct event_command
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Steven Rostedt <[email protected]>
[ Upstream commit b052d70f7c9c156409a70e65c10d83b5650e7e78 ]
Now that there's pretty much a one to one mapping between the struct event_trigger_ops and struct event_command, there's no reason to have two different structures. Merge the function pointers of event_trigger_ops into event_command.
There's one exception in trace_events_hist.c for the event_hist_trigger_named_ops. This has special logic for the init and free function pointers for "named histograms". In this case, allocate the cmd_ops of the event_trigger_data and set it to the proper init and free functions, which are used to initialize and free the event_trigger_data respectively. Have the free function and the init function (on failure) free the cmd_ops of the data element.
Stable-dep-of: 6ede78d0563a ("tracing: Set the trace clock before registering the histogram trigger")
--- kernel/trace/trace.h | 126 ++++++++++++++---------------------- kernel/trace/trace_eprobe.c | 13 +-- kernel/trace/trace_events_hist.c | 93 +++++++++++++------------- kernel/trace/trace_events_trigger.c | 121 +++++++++++++--------------------- 4 files changed, 151 insertions(+), 202 deletions(-)
kernel/trace/trace.h +51 -75
@@ -1699,7 +1699,6 @@ struct event_trigger_data {unsigned long count;int ref;int flags; -const struct event_trigger_ops *ops;struct event_command *cmd_ops;struct event_filter __rcu *filter;char *filter_str;
@@ -1791,73 +1790,6 @@ extern void event_file_get(struct trace_extern void event_file_put (struct trace_event_file *file);/** -* struct event_trigger_ops - callbacks for trace event triggers -* -* The methods in this structure provide per-event trigger hooks for -* various trigger operations. -* -* The @init and @free methods are used during trigger setup and -* teardown, typically called from an event_command's @parse() -* function implementation. -* -* The @print method is used to print the trigger spec. -* -* The @trigger method is the function that actually implements the -* trigger and is called in the context of the triggering event -* whenever that event occurs. -* -* All the methods below, except for @init() and @free(), must be -* implemented. -* -* @trigger: The trigger 'probe' function called when the triggering -* event occurs. The data passed into this callback is the data -* that was supplied to the event_command @reg() function that -* registered the trigger (see struct event_command) along with -* the trace record, rec. -* -* @count_func: If defined and a numeric parameter is passed to the -* trigger, then this function will be called before @trigger -* is called. If this function returns false, then @trigger is not -* executed. -* -* @init: An optional initialization function called for the trigger -* when the trigger is registered (via the event_command reg() -* function). This can be used to perform per-trigger -* initialization such as incrementing a per-trigger reference -* count, for instance. This is usually implemented by the -* generic utility function @event_trigger_init() (see -* trace_event_triggers.c). -* -* @free: An optional de-initialization function called for the -* trigger when the trigger is unregistered (via the -* event_command @reg() function). This can be used to perform -* per-trigger de-initialization such as decrementing a -* per-trigger reference count and freeing corresponding trigger -* data, for instance. This is usually implemented by the -* generic utility function @event_trigger_free() (see -* trace_event_triggers.c). -* -* @print: The callback function invoked to have the trigger print -* itself. This is usually implemented by a wrapper function -* that calls the generic utility function @event_trigger_print() -* (see trace_event_triggers.c). -*/ -struct event_trigger_ops { -void (*trigger)(struct event_trigger_data *data, -struct trace_buffer *buffer, -void *rec, -struct ring_buffer_event *rbe); -bool (*count_func)(struct event_trigger_data *data, -struct trace_buffer *buffer, -void *rec, -struct ring_buffer_event *rbe); -int (*init)(struct event_trigger_data *data); -void (*free)(struct event_trigger_data *data); -int (*print)(struct seq_file *m, -struct event_trigger_data *data); -}; - -/** * struct event_command - callbacks and data members for event commands * * Event commands are invoked by users by writing the command name
@@ -1877,9 +1809,6 @@ struct event_trigger_ops {* @name: The unique name that identifies the event command. This is * the name used when setting triggers via trigger files. * -* @trigger_ops: The event_trigger_ops implementation associated with -* the command. -* * @trigger_type: A unique id that identifies the event command * 'type'. This value has two purposes, the first to ensure that * only one trigger of the same type can be set at a given time
@@ -1909,7 +1838,7 @@ struct event_trigger_ops {* * @reg: Adds the trigger to the list of triggers associated with the * event, and enables the event trigger itself, after -* initializing it (via the event_trigger_ops @init() function). +* initializing it (via the event_command @init() function). * This is also where commands can use the @trigger_type value to * make the decision as to whether or not multiple instances of * the trigger should be allowed. This is usually implemented by
@@ -1918,7 +1847,7 @@ struct event_trigger_ops {* * @unreg: Removes the trigger from the list of triggers associated * with the event, and disables the event trigger itself, after -* initializing it (via the event_trigger_ops @free() function). +* initializing it (via the event_command @free() function). * This is usually implemented by the generic utility function * @unregister_trigger() (see trace_event_triggers.c). *
@@ -1931,11 +1860,46 @@ struct event_trigger_ops {* event command, filters set by the user for the command will be * ignored. This is usually implemented by the generic utility * function @set_trigger_filter() (see trace_event_triggers.c). +* +* All the methods below, except for @init() and @free(), must be +* implemented. +* +* @trigger: The trigger 'probe' function called when the triggering +* event occurs. The data passed into this callback is the data +* that was supplied to the event_command @reg() function that +* registered the trigger (see struct event_command) along with +* the trace record, rec. +* +* @count_func: If defined and a numeric parameter is passed to the +* trigger, then this function will be called before @trigger +* is called. If this function returns false, then @trigger is not +* executed. +* +* @init: An optional initialization function called for the trigger +* when the trigger is registered (via the event_command reg() +* function). This can be used to perform per-trigger +* initialization such as incrementing a per-trigger reference +* count, for instance. This is usually implemented by the +* generic utility function @event_trigger_init() (see +* trace_event_triggers.c). +* +* @free: An optional de-initialization function called for the +* trigger when the trigger is unregistered (via the +* event_command @reg() function). This can be used to perform +* per-trigger de-initialization such as decrementing a +* per-trigger reference count and freeing corresponding trigger +* data, for instance. This is usually implemented by the +* generic utility function @event_trigger_free() (see +* trace_event_triggers.c). +* +* @print: The callback function invoked to have the trigger print +* itself. This is usually implemented by a wrapper function +* that calls the generic utility function @event_trigger_print() +* (see trace_event_triggers.c). */ struct event_command {struct list_head list;char *name; -const struct event_trigger_ops *trigger_ops;enum event_trigger_type trigger_type;int flags; int (*parse)(struct event_command *cmd_ops,
@@ -1952,6 +1916,18 @@ struct event_command {int (*set_filter)(char *filter_str,struct event_trigger_data *data,struct trace_event_file *file); +void (*trigger)(struct event_trigger_data *data, +struct trace_buffer *buffer, +void *rec, +struct ring_buffer_event *rbe); +bool (*count_func)(struct event_trigger_data *data, +struct trace_buffer *buffer, +void *rec, +struct ring_buffer_event *rbe); +int (*init)(struct event_trigger_data *data); +void (*free)(struct event_trigger_data *data); +int (*print)(struct seq_file *m, +struct event_trigger_data *data); };/**
@@ -1972,7 +1948,7 @@ struct event_command {* either committed or discarded. At that point, if any commands * have deferred their triggers, those commands are finally * invoked following the close of the current event. In other -* words, if the event_trigger_ops @func() probe implementation +* words, if the event_command @func() probe implementation * itself logs to the trace buffer, this flag should be set, * otherwise it can be left unspecified. *
kernel/trace/trace_eprobe.c +4 -9
@@ -479,13 +479,6 @@ static void eprobe_trigger_func(struct e__eprobe_trace_func (edata, rec); } -static const struct event_trigger_ops eprobe_trigger_ops = { - .trigger = eprobe_trigger_func, - .print = eprobe_trigger_print, - .init = eprobe_trigger_init, - .free = eprobe_trigger_free, -}; - static int eprobe_trigger_cmd_parse(struct event_command *cmd_ops, struct trace_event_file *file, char *glob, char *cmd,
@@ -512,12 +505,15 @@ static struct event_command event_trigge .name = "eprobe", .trigger_type = ETT_EVENT_EPROBE, .flags = EVENT_CMD_FL_NEEDS_REC, - .trigger_ops = &eprobe_trigger_ops, .parse = eprobe_trigger_cmd_parse, .reg = eprobe_trigger_reg_func, .unreg = eprobe_trigger_unreg_func, .unreg_all = NULL, .set_filter = NULL, + .trigger = eprobe_trigger_func, + .print = eprobe_trigger_print, + .init = eprobe_trigger_init, + .free = eprobe_trigger_free, }; static struct event_trigger_data *
@@ -537,7 +533,6 @@ new_eprobe_trigger(struct trace_eprobe * trigger->flags =EVENT_TRIGGER_FL_PROBE ; trigger->count =-1 ; - trigger->ops = &eprobe_trigger_ops;/* * EVENT PROBE triggers are not registered as commands with
kernel/trace/trace_events_hist.c +48 -45
194 lines not on this page · raw message
kernel/trace/trace_events_trigger.c +48 -73
268 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 719/877 tracing: Set the trace clock before registering the histogram trigger
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Donggeun Yoo <[email protected]>
[ Upstream commit 6ede78d0563a2a3ae3e46f9c07cedb5d79645429 ]
hist_register_trigger() puts the trigger on the global named_triggers list in cmd_ops->init(), and only then sets the trace clock:
if (data->cmd_ops->init) {
ret = data->cmd_ops->init(data);
if (ret < 0)
goto out;
}
if (hist_data->enable_timestamps) {
ret = tracing_set_clock(file->tr, hist_data->attrs->clock);
if (ret) {
hist_err(tr, HIST_ERR_SET_CLOCK_FAIL, errpos(clock));
goto out;
}The clock string is not checked anywhere before that call, so a named trigger using common_timestamp with an unknown clock fails after it has already become findable. event_hist_trigger_parse() then frees it without taking it off the list, and the next lookup by name reads the freed object:
~# cd /sys/kernel/tracing/events/sched/sched_switch
~# echo 'hist:name=foo:keys=common_pid:ts=common_timestamp:clock=bogus' > trigger
bash: echo: write error: Invalid argument
~# echo 'hist:name=foo:keys=common_pid' > trigger
BUG: KASAN: slab-use-after-free in find_named_trigger+0xac/0xc0 Read of size 8 at addr ffff88800915d760 by task init/1 find_named_trigger+0xac/0xc0 hist_register_trigger+0xc1/0x900 event_hist_trigger_parse+0x3146/0x6af0 event_trigger_write+0xce/0x160 Freed by task 63: kfree+0x154/0x420 trigger_kthread_fn+0xfd/0x160
Set the clock before the trigger is registered, so that nothing which can fail runs after it is published, the way commit 6f86bdeab633 ("tracing: Fix bad hist from corrupting named_triggers list") moved the registration below the rest of the setup.
tracing_set_filter_buffering() is reference counted, so the init failure path has to drop the reference that the clock block now takes first.
--- kernel/trace/trace_events_hist.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
kernel/trace/trace_events_hist.c +9 -6
@@ -6566,12 +6566,6 @@ static int hist_register_trigger(char *g data->cmd_ops = cmd_ops; } -if (data->cmd_ops->init) { - ret = data->cmd_ops->init (data); -if (ret <0 ) - goto out; - } -if (hist_data->enable_timestamps) {char *clock = hist_data->attrs->clock;
@@ -6584,6 +6578,15 @@ static int hist_register_trigger(char *gtracing_set_filter_buffering (file->tr, true); } +if (data->cmd_ops->init) { + ret = data->cmd_ops->init (data); +if (ret <0 ) { +if (hist_data->enable_timestamps) +tracing_set_filter_buffering (file->tr, false); + goto out; + } + } +if (named_data) {remove_hist_vars (hist_data);destroy_hist_data (hist_data);
Greg Kroah-Hartman
maintainerPATCH 720/877 virtio-mmio: Remove virtqueue list from mmio device
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Viresh Kumar <[email protected]>
[ Upstream commit 564a69ad90d15c782176e1a8c9e1c95661e1aed0 ]
The MMIO transport implementation creates a list of virtqueues for a virtio device, while the same is already available in the struct virtio_device.
Don't create a duplicate list, and use the other one instead.
While at it, fix the virtio_device_for_each_vq() macro to accept an argument like "&vm_dev->vdev" (which currently fails to build).
Message-Id: <3e56c6f74002987e22f364d883cbad177cd9ad9c.1747827066.git.viresh.kumar@linaro.org>
Stable-dep-of: d14d693adb05 ("virtio_mmio: disable IRQ wake before free_irq")
--- drivers/virtio/virtio_mmio.c | 52 ++----------------------------------------- include/linux/virtio.h | 2 - 2 files changed, 4 insertions(+), 50 deletions(-)
drivers/virtio/virtio_mmio.c +3 -49
@@ -65,7 +65,6 @@#include <linux/platform_device.h> #include <linux/pm.h> #include <linux/slab.h> -#include <linux/spinlock.h> #include <linux/virtio.h> #include <linux/virtio_config.h> #include <uapi/linux/virtio_mmio.h>
@@ -88,22 +87,8 @@ struct virtio_mmio_device {void __iomem *base;unsigned long version; - -/* a list of queues so we can dispatch IRQs */ -spinlock_t lock; -struct list_head virtqueues; -}; - -struct virtio_mmio_vq_info { -/* the actual virtqueue */ -struct virtqueue *vq; - -/* the list node for the virtqueues list */ -struct list_head node; }; - -/* Configuration interface */ static u64 vm_get_features (struct virtio_device *vdev)
@@ -300,9 +285,8 @@ static bool vm_notify_with_data(struct vstatic irqreturn_t vm_interrupt (int irq,void *opaque) {struct virtio_mmio_device *vm_dev = opaque; -struct virtio_mmio_vq_info *info; +struct virtqueue *vq;unsigned long status; -unsigned long flags;irqreturn_t ret =IRQ_NONE ;/* Read and acknowledge interrupts */
@@ -315,10 +299,8 @@ static irqreturn_t vm_interrupt(int irq, }if (likely (status &VIRTIO_MMIO_INT_VRING )) { -spin_lock_irqsave (&vm_dev->lock, flags); -list_for_each_entry (info, &vm_dev->virtqueues, node) - ret |=vring_interrupt (irq, info->vq); -spin_unlock_irqrestore (&vm_dev->lock, flags); +virtio_device_for_each_vq (&vm_dev->vdev, vq) + ret |=vring_interrupt (irq, vq); }return ret;
@@ -329,14 +311,8 @@ static irqreturn_t vm_interrupt(int irq,static void vm_del_vq (struct virtqueue *vq) {struct virtio_mmio_device *vm_dev =to_virtio_mmio_device (vq->vdev); -struct virtio_mmio_vq_info *info = vq->priv; -unsigned long flags;unsigned int index = vq->index; -spin_lock_irqsave (&vm_dev->lock, flags); -list_del (&info->node); -spin_unlock_irqrestore (&vm_dev->lock, flags); -/* Select and deactivate the queue */ writel (index, vm_dev->base +VIRTIO_MMIO_QUEUE_SEL );if (vm_dev->version ==1 ) {
@@ -347,8 +323,6 @@ static void vm_del_vq(struct virtqueue * }vring_del_virtqueue (vq); - -kfree (info); }static void vm_del_vqs (struct virtio_device *vdev)
@@ -375,9 +349,7 @@ static struct virtqueue *vm_setup_vq(str {struct virtio_mmio_device *vm_dev =to_virtio_mmio_device (vdev);bool (*notify)(struct virtqueue *vq); -struct virtio_mmio_vq_info *info;struct virtqueue *vq; -unsigned long flags;unsigned int num;int err;
@@ -399,13 +371,6 @@ static struct virtqueue *vm_setup_vq(str goto error_available; } -/* Allocate and fill out our active queue description */ - info =kmalloc (sizeof (*info),GFP_KERNEL ); -if (!info) { - err = -ENOMEM ; - goto error_kmalloc; - } - num =readl (vm_dev->base +VIRTIO_MMIO_QUEUE_NUM_MAX );if (num ==0 ) { err = -ENOENT ;
@@ -463,13 +428,6 @@ static struct virtqueue *vm_setup_vq(strwritel (1 , vm_dev->base +VIRTIO_MMIO_QUEUE_READY ); } - vq->priv = info; - info->vq = vq; - -spin_lock_irqsave (&vm_dev->lock, flags); -list_add (&info->node, &vm_dev->virtqueues); -spin_unlock_irqrestore (&vm_dev->lock, flags); -return vq; error_bad_pfn:
@@ -481,8 +439,6 @@ error_new_virtqueue:writel (0 , vm_dev->base +VIRTIO_MMIO_QUEUE_READY );WARN_ON (readl (vm_dev->base +VIRTIO_MMIO_QUEUE_READY )); } -kfree (info); -error_kmalloc: error_available:return ERR_PTR (err); }
@@ -627,8 +583,6 @@ static int virtio_mmio_probe(struct plat vm_dev->vdev.dev.release = virtio_mmio_release_dev; vm_dev->vdev.config = &virtio_mmio_config_ops; vm_dev->pdev = pdev; -INIT_LIST_HEAD (&vm_dev->virtqueues); -spin_lock_init (&vm_dev->lock); vm_dev->base =devm_platform_ioremap_resource (pdev,0 );if (IS_ERR (vm_dev->base)) {
include/linux/virtio.h +1 -1
@@ -184,7 +184,7 @@ void virtio_reset_device(struct virtio_dsize_t virtio_max_dma_size (const struct virtio_device *vdev);#define virtio_device_for_each_vq (vdev, vq) \ - list_for_each_entry(vq, &vdev->vqs, list) + list_for_each_entry(vq, &(vdev)->vqs, list)/** * struct virtio_driver - operations for a virtio I/O driver
Greg Kroah-Hartman
maintainerPATCH 721/877 virtio_mmio: disable IRQ wake before free_irq
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiong Weimin <[email protected]>
[ Upstream commit d14d693adb055e98ca705822ba6daebc18602d9a ]
When the DT node has "wakeup-source", vm_find_vqs() calls enable_irq_wake() on the shared IRQ, but vm_del_vqs() freed that IRQ without a matching disable_irq_wake(). That leaves a wake reference behind and can warn on later free_irq()/request_irq() cycles.
Record whether enable_irq_wake() succeeded, and disable it in vm_del_vqs() before free_irq().
Message-ID: <[email protected]>
--- drivers/virtio/virtio_mmio.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
drivers/virtio/virtio_mmio.c +13 -3
@@ -87,6 +87,9 @@ struct virtio_mmio_device {void __iomem *base;unsigned long version; + +/* True if enable_irq_wake() succeeded for the shared IRQ. */ +bool wake_irq_enabled; };/* Configuration interface */
@@ -329,11 +332,17 @@ static void vm_del_vqs(struct virtio_dev {struct virtio_mmio_device *vm_dev =to_virtio_mmio_device (vdev);struct virtqueue *vq, *n; +int irq =platform_get_irq (vm_dev->pdev,0 );list_for_each_entry_safe (vq, n, &vdev->vqs, list)vm_del_vq (vq); -free_irq (platform_get_irq (vm_dev->pdev,0 ), vm_dev); +if (vm_dev->wake_irq_enabled) { +disable_irq_wake (irq); + vm_dev->wake_irq_enabled = false; + } + +free_irq (irq, vm_dev); }static void vm_synchronize_cbs (struct virtio_device *vdev)
@@ -460,8 +469,9 @@ static int vm_find_vqs(struct virtio_devif (err)return err; -if (of_property_read_bool (vm_dev->pdev->dev.of_node,"wakeup-source" )) -enable_irq_wake (irq); +if (of_property_read_bool (vm_dev->pdev->dev.of_node,"wakeup-source" ) && + !enable_irq_wake (irq)) + vm_dev->wake_irq_enabled = true;for (i =0 ; i < nvqs; ++i) {struct virtqueue_info *vqi = &vqs_info[i];
Greg Kroah-Hartman
maintainerPATCH 722/877 tools/bootconfig: Cleanup bootconfig footer size calculations
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Masami Hiramatsu (Google)" <[email protected]>
[ Upstream commit 26dda57695090e05c1a99c3e8f802f862d1ac474 ]
There are many same pattern of 8 + BOOTCONFIG_MAGIC_LEN for calculating the size of bootconfig footer. Use BOOTCONFIG_FOOTER_SIZE macro to clean up those magic numbers.
Stable-dep-of: 462d0b066b61 ("tools/bootconfig: Fix integer overflow and truncation in size checks")
--- tools/bootconfig/main.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)
tools/bootconfig/main.c +11 -8
@@ -16,6 +16,10 @@#define pr_err (fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__) +/* Bootconfig footer is [size][csum][BOOTCONFIG_MAGIC]. */ +#define BOOTCONFIG_FOOTER_SIZE \ + (sizeof(uint32_t) * 2 + BOOTCONFIG_MAGIC_LEN) +static int xbc_show_value (struct xbc_node *node,bool semicolon) {const char *val, *eol;
@@ -188,7 +192,7 @@ static int load_xbc_from_initrd(int fd,if (ret <0 )return -errno; -if (stat.st_size <8 +BOOTCONFIG_MAGIC_LEN ) +if (stat.st_size <BOOTCONFIG_FOOTER_SIZE )return 0 ;if (lseek (fd, -BOOTCONFIG_MAGIC_LEN ,SEEK_END ) <0 )
@@ -201,7 +205,7 @@ static int load_xbc_from_initrd(int fd,if (memcmp (magic,BOOTCONFIG_MAGIC ,BOOTCONFIG_MAGIC_LEN ) !=0 )return 0 ; -if (lseek (fd, -(8 +BOOTCONFIG_MAGIC_LEN ),SEEK_END ) <0 ) +if (lseek (fd, -BOOTCONFIG_FOOTER_SIZE ,SEEK_END ) <0 )return pr_errno ("Failed to lseek for size" , -errno);if (read (fd, &size,sizeof (uint32_t )) <0 )
@@ -213,12 +217,12 @@ static int load_xbc_from_initrd(int fd, csum =le32toh (csum);/* Wrong size error */ -if (stat.st_size < size +8 +BOOTCONFIG_MAGIC_LEN ) { +if (stat.st_size < size +BOOTCONFIG_FOOTER_SIZE ) {pr_err ("bootconfig size is too big\n" );return -E2BIG ; } -if (lseek (fd, stat.st_size - (size +8 +BOOTCONFIG_MAGIC_LEN ), +if (lseek (fd, stat.st_size - (size +BOOTCONFIG_FOOTER_SIZE ),SEEK_SET ) <0 )return pr_errno ("Failed to lseek" , -errno);
@@ -349,7 +353,7 @@ static int delete_xbc(const char *path) ret =fstat (fd, &stat);if (!ret) ret =ftruncate (fd, stat.st_size - - size -8 -BOOTCONFIG_MAGIC_LEN ); + - size -BOOTCONFIG_FOOTER_SIZE );if (ret) ret = -errno; }/* Ignore if there is no boot config in initrd */
@@ -379,8 +383,7 @@ static int apply_xbc(const char *path, c csum =xbc_calc_checksum (buf, size);/* Backup the bootconfig data */ - data =calloc (size +BOOTCONFIG_ALIGN + -sizeof (uint32_t ) +sizeof (uint32_t ) +BOOTCONFIG_MAGIC_LEN ,1 ); + data =calloc (size +BOOTCONFIG_ALIGN +BOOTCONFIG_FOOTER_SIZE ,1 );if (!data)return -ENOMEM ;memcpy (data, buf, size);
@@ -428,7 +431,7 @@ static int apply_xbc(const char *path, c }/* To align up the total size to BOOTCONFIG_ALIGN, get padding size */ - total_size = stat.st_size + size +sizeof (uint32_t ) *2 +BOOTCONFIG_MAGIC_LEN ; + total_size = stat.st_size + size +BOOTCONFIG_FOOTER_SIZE ; pad = ((total_size +BOOTCONFIG_ALIGN -1 ) & (~BOOTCONFIG_ALIGN_MASK )) - total_size; size += pad;
Greg Kroah-Hartman
maintainerPATCH 723/877 tools/bootconfig: Fix integer overflow and truncation in size checks
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Masami Hiramatsu (Google)" <[email protected]>
[ Upstream commit 462d0b066b613103f579793031429db2ca23abc0 ]
Sashiko reported that on 32-bit systems, if an attacker crafts size in the bootconfig footer such that adding BOOTCONFIG_FOOTER_SIZE wraps around (for instance, if size is 0xFFFFFFFF), the size check in load_xbc_from_initrd() can be bypassed:
if (stat.st_size < size + BOOTCONFIG_FOOTER_SIZE) {
pr_err("bootconfig size is too big\n");
return -E2BIG;
}Furthermore, on 64-bit systems with an initrd > 4.29 GB, comparing a corrupted 32-bit size (e.g. 0xFFFFFFFF) against
stat.st_size - BOOTCONFIG_FOOTER_SIZE can also bypass the check if size is not bounded. Similarly, load_xbc_file() passes 64-bit stat.st_size directly into the 32-bit int size parameter of load_xbc_fd(), truncating large standalone files (>= 2GB).
In both cases, passing 0xFFFFFFFF to load_xbc_fd() truncates to -1, resulting in malloc(0), an integer overflow in read(), and an out-of-bounds null-byte write.
Fix this by:
1. Rejecting size > XBC_DATA_MAX or
size > stat.st_size - BOOTCONFIG_FOOTER_SIZE in load_xbc_from_initrd().
2. Rejecting stat.st_size > XBC_DATA_MAX in load_xbc_file() before passing it to load_xbc_fd().
3. Checking size < 0 || size > XBC_DATA_MAX defensively in load_xbc_fd().
--- tools/bootconfig/main.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
tools/bootconfig/main.c +12 -1
@@ -139,6 +139,9 @@ static int load_xbc_fd(int fd, char **bu {int ret; +if (size <0 || size >XBC_DATA_MAX ) +return -EINVAL ; + *buf =malloc (size +1 );if (!*buf)return -ENOMEM ;
@@ -167,6 +170,13 @@ static int load_xbc_file(const char *patreturn ret; } +if (stat.st_size >XBC_DATA_MAX ) { +pr_err ("%s size is too big\n" , path); + ret = -E2BIG ; +close (fd); +return ret; + } + ret =load_xbc_fd (fd, buf, stat.st_size);close (fd);
@@ -217,7 +227,8 @@ static int load_xbc_from_initrd(int fd, csum =le32toh (csum);/* Wrong size error */ -if (stat.st_size < size +BOOTCONFIG_FOOTER_SIZE ) { +if (size >XBC_DATA_MAX || + size > stat.st_size -BOOTCONFIG_FOOTER_SIZE ) {pr_err ("bootconfig size is too big\n" );return -E2BIG ; }
Greg Kroah-Hartman
maintainerPATCH 724/877 tracing: Take trace_array reference when opening a tracer options file
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Steven Rostedt <[email protected]>
[ Upstream commit ed0aff60f83a9bdc2f6556376ac79c96b3ce7e80 ]
When a tracer option file is opened, it is passed a descriptor that points to an element on the trace_array's topts array. This element has information to find the trace array and other information. It uses this element to take a reference of the trace_array so that the trace_array does not get removed while this file is opened.
Unfortunately, there's a race condition where the element itself could be freed by the removal of the instance the trace_array represents causing a use-after-free as this element that is used to find the trace_array to increment its reference counter is also freed when the instance is removed.
To solve this, add a trace_array_tracer_options_get() helper function that will take the address of the element that is passed to the open function by the inode->i_private pointer and search all the trace_arrays under a lock to find the one that the element's address is in the range of the trace_arrays topts array elements. When a match happens, that trace_array's reference would be increased.
Note, there's a race where if an admin was deleting and creating trace instances at the same time and the memory of the old trace_array's array matched the memory of the new trace_array that it could in theory open the option from the wrong trace array. But we do not care because it would be stupid to perform that kind of action. As long as the only thing that can happen is that the option from the wrong trace array is used and doesn't crash the kernel it will only make the user confused. But if they are doing something stupid like this, they are already confused, so no harm done.
--- kernel/trace/trace.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++- kernel/trace/trace.h | 1 + 2 files changed, 48 insertions(+), 1 deletion(-)
kernel/trace/trace.c +47 -1
@@ -8737,12 +8737,57 @@ trace_options_write(struct file *filp, creturn cnt; } +static bool tr_option_match (struct trace_array *tr,void *topt) +{ +for (int i =0 ; i < tr->nr_topts; i++) { +struct trace_options *tr_topts = &tr->topts[i]; + +if (topt >= (void *)&tr_topts->topts[0 ] && + topt < (void *)&tr_topts->topts[tr_topts->nr_topts]) +return true; + } +return false; +} + +/* +* The topt is the address of a trace_array->topts[] element that holds the +* the tracer options descriptor. But since the trace_array reference has not +* been taken yet, it cannot be dereferenced as it could have been freed by +* a rmdir of the instance the trace_array represents. +* +* Search the list of trace_arrays and compare the topt to the address of +* the entire trace_array topts array for each trace_array in the list. +* If one is matched, then take the reference and return it. If not, the +* trace_array no longer exits. +*/ +static int trace_array_tracer_options_get (void *topt) +{ +struct trace_array *tr; +int ret; + + ret =security_locked_down (LOCKDOWN_TRACEFS ); +if (ret) +return ret; + +if (tracing_disabled) +return -ENODEV ; + +guard (mutex)(&trace_types_lock); +list_for_each_entry (tr, &ftrace_trace_arrays, list) { +if (tr_option_match (tr, topt)) { + tr->ref++; +return 0 ; + } + } +return -ENODEV ; +} +static int tracing_open_options (struct inode *inode,struct file *filp) {struct trace_option_dentry *topt = inode->i_private;int ret; - ret =tracing_check_open_get_tr (topt->tr); + ret =trace_array_tracer_options_get (topt);if (ret)return ret;
@@ -9026,6 +9071,7 @@ create_trace_option_files(struct trace_a tr->topts = tr_topts; tr->topts[tr->nr_topts].tracer = tracer; tr->topts[tr->nr_topts].topts = topts; + tr->topts[tr->nr_topts].nr_topts = cnt; tr->nr_topts++;for (cnt =0 ; opts[cnt].name; cnt++) {
kernel/trace/trace.h +1 -0
@@ -223,6 +223,7 @@ struct array_buffer {struct trace_options {struct tracer *tracer;struct trace_option_dentry *topts; +int nr_topts; };struct trace_pid_list *trace_pid_list_alloc (void );
Greg Kroah-Hartman
maintainerPATCH 725/877 tracing: Take the reference before publishing the named histogram trigger
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Donggeun Yoo <[email protected]>
[ Upstream commit 0fe23b8eaba0d3372c66b7b31204408da0715edc ]
event_hist_trigger_named_init() puts the trigger on the global named_triggers list and only then takes the reference on the trigger it shares its histogram with:
data->ref++;
save_named_trigger(data->named_data->name, data);
ret = event_hist_trigger_init(data->named_data);
if (ret < 0) {
kfree(data->cmd_ops);
data->cmd_ops = &trigger_hist_cmd;
}
return ret;event_hist_trigger_init() fails when alloc_hist_pad() cannot allocate, and nothing takes the trigger back off the list on the way out. event_hist_trigger_parse() frees it, and the next lookup by name reads the freed object:
BUG: KASAN: slab-use-after-free in find_named_trigger+0xac/0xc0 Read of size 8 at addr ffff888009346860 by task init/1 find_named_trigger+0xac/0xc0 hist_register_trigger+0xc1/0xa00 event_hist_trigger_parse+0x3146/0x6af0 event_trigger_write+0xce/0x160 Freed by task 67: kfree+0x154/0x420 trigger_kthread_fn+0xfd/0x160
Do the reference first and publish once it has succeeded, so that nothing which can fail runs after the trigger becomes findable.
--- kernel/trace/trace_events_hist.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
kernel/trace/trace_events_hist.c +6 -5
@@ -6327,17 +6327,18 @@ static int event_hist_trigger_named_init {int ret; - data->ref++; - -save_named_trigger (data->named_data->name, data); - ret =event_hist_trigger_init (data->named_data);if (ret <0 ) {kfree (data->cmd_ops); data->cmd_ops = &trigger_hist_cmd; +return ret; } -return ret; + data->ref++; + +save_named_trigger (data->named_data->name, data); + +return 0 ; }static void event_hist_trigger_named_free (struct event_trigger_data *data)
Greg Kroah-Hartman
maintainerPATCH 726/877 tracing: Undo the registration when enabling the histogram trigger fails
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Donggeun Yoo <[email protected]>
[ Upstream commit 92383cef66791a0c63a2f27755cadbdb2fbf270b ]
Commit 6f86bdeab633 ("tracing: Fix bad hist from corrupting named_triggers list") described how a trigger that is registered but not on file->triggers ends up freed while still on the global named_triggers list, and moved the registration down so that hist_trigger_enable() follows it immediately. One path still gets there. hist_trigger_enable() adds the trigger and takes it straight back out when the event cannot be enabled:
list_add_tail_rcu(&data->list, &file->triggers);
update_cond_flag(file);
if (trace_event_trigger_enable_disable(file, 1) < 0) {
list_del_rcu(&data->list);
update_cond_flag(file);
ret--;
}so the list walk in hist_unregister_trigger() matches nothing, test stays NULL, and the ->free() that would call del_named_trigger() is skipped. out_unreg falls through to out_free, which frees the trigger anyway:
BUG: KASAN: slab-use-after-free in find_named_trigger+0xac/0xc0 Read of size 8 at addr ffff8880091d3160 by task init/1 find_named_trigger+0xac/0xc0 hist_register_trigger+0xc1/0xa00 event_hist_trigger_parse+0x3146/0x6af0 event_trigger_write+0xce/0x160 Freed by task 69: kfree+0x154/0x420 trigger_kthread_fn+0xfd/0x160
Leave the trigger where hist_unregister_trigger() can find it and let that undo the registration, which is the only code that knows all of what cmd_ops->init() took: the named list entry, the hist_pad reference, the reference on the trigger a named histogram is shared with, and the copied cmd_ops. It also pairs the failed trace_event_trigger_enable_disable(), whose sm_ref and buffered event reference are otherwise left behind.
Since ->free() releases trigger_data and, for a trigger that does not share its histogram, hist_data with it, out_unreg can no longer fall through to out_free. For a trigger that does share, hist_register_trigger() has already destroyed the caller's hist_data, so the fall-through was reading freed memory there as well.
Move the enable_timestamps check in hist_unregister_trigger() above the ->free() call for the same reason: hist_data does not outlive it once the trigger being removed is the one that owns it.
--- kernel/trace/trace_events_hist.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
kernel/trace/trace_events_hist.c +10 -7
@@ -6605,11 +6605,12 @@ static int hist_trigger_enable(struct evupdate_cond_flag (file); -if (trace_event_trigger_enable_disable (file,1 ) <0 ) { -list_del_rcu (&data->list); -update_cond_flag (file); +/* +* On failure the caller undoes the registration, and +* hist_unregister_trigger() can only find the trigger here. +*/ +if (trace_event_trigger_enable_disable (file,1 ) <0 ) ret--; - }return ret; }
@@ -6687,13 +6688,13 @@ static void hist_unregister_trigger(char } } -if (test && test->cmd_ops->free) - test->cmd_ops->free (test); -if (hist_data->enable_timestamps) {if (!hist_data->remove || test)tracing_set_filter_buffering (file->tr, false); } + +if (test && test->cmd_ops->free) + test->cmd_ops->free (test); }static bool hist_file_check_refs (struct trace_event_file *file)
@@ -6898,6 +6899,8 @@ static int event_hist_trigger_parse(strureturn ret; out_unreg:event_trigger_unregister (cmd_ops, file, glob+1 , trigger_data); +/* The unregister frees trigger_data, skip out_free */ + goto out; out_free:event_trigger_reset_filter (cmd_ops, trigger_data);
Greg Kroah-Hartman
maintainerPATCH 727/877 EDAC/altera: Use ECC manager compatible to select A10/S10 IRQ layout
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rounak Das <[email protected]>
[ Upstream commit d4486fc3098e176cb4a29fee037216484761f9ca ]
The SDMMC ECC IRQ layout selection uses CONFIG_64BIT to distinguish between Arria10 and Stratix10 paths.
Detect the SoC once at probe via the device match table (.data) store it in struct altr_arria10_edac, and use it instead of CONFIG_64BIT.
This keeps the decision correct for every ECC child device (OCRAM, SD/MMC, etc.) and avoids any runtime compatible lookup.
Stable-dep-of: 9868f5c077df ("EDAC/altera: Use parent device for devres in altr_portb_setup()")
--- drivers/edac/altera_edac.c | 107 ++++++++++++++++++++++----------------------- drivers/edac/altera_edac.h | 1 2 files changed, 55 insertions(+), 53 deletions(-)
drivers/edac/altera_edac.c +54 -53
@@ -1507,6 +1507,7 @@ static int altr_portb_setup(struct altr_int edac_idx, rc;struct device_node *np;const struct edac_device_prv_data *prv = &a10_sdmmceccb_data; +bool is_s10 = device->edac->is_s10; rc =altr_check_ecc_deps (device);if (rc)
@@ -1548,15 +1549,14 @@ static int altr_portb_setup(struct altr_/* * Update the PortB IRQs - A10 has 4, S10 has 2, Index accordingly -* -* FIXME: Instead of ifdefs with different architectures the driver -* should properly use compatibles. */ -#ifdef CONFIG_64BIT - altdev->sb_irq =irq_of_parse_and_map (np,1 ); -#else - altdev->sb_irq =irq_of_parse_and_map (np,2 ); -#endif + +/* Using compatibles to determine the IRQ Index */ +if (is_s10) + altdev->sb_irq =irq_of_parse_and_map (np,1 ); +else + altdev->sb_irq =irq_of_parse_and_map (np,2 ); +if (!altdev->sb_irq) {edac_printk (KERN_ERR ,EDAC_DEVICE ,"Error PortB SBIRQ alloc\n" ); rc = -ENODEV ;
@@ -1570,29 +1570,28 @@ static int altr_portb_setup(struct altr_ goto err_release_group_1; } -#ifdef CONFIG_64BIT -/* Use IRQ to determine SError origin instead of assigning IRQ */ - rc =of_property_read_u32_index (np,"interrupts" ,1 , &altdev->db_irq); -if (rc) { -edac_printk (KERN_ERR ,EDAC_DEVICE , -"Error PortB DBIRQ alloc\n" ); - goto err_release_group_1; - } -#else - altdev->db_irq =irq_of_parse_and_map (np,3 ); -if (!altdev->db_irq) { -edac_printk (KERN_ERR ,EDAC_DEVICE ,"Error PortB DBIRQ alloc\n" ); - rc = -ENODEV ; - goto err_release_group_1; - } - rc =devm_request_irq (&altdev->ddev, altdev->db_irq, - prv->ecc_irq_handler,IRQF_TRIGGER_HIGH , - ecc_name, altdev); -if (rc) { -edac_printk (KERN_ERR ,EDAC_DEVICE ,"PortB DBERR IRQ error\n" ); - goto err_release_group_1; +if (is_s10) { +/* Use IRQ to determine SError origin instead of assigning IRQ */ + rc =of_property_read_u32_index (np,"interrupts" ,1 , &altdev->db_irq); +if (rc) { +edac_printk (KERN_ERR ,EDAC_DEVICE ,"Error PortB DBIRQ alloc\n" ); + goto err_release_group_1; + } + }else { + altdev->db_irq =irq_of_parse_and_map (np,3 ); +if (!altdev->db_irq) { +edac_printk (KERN_ERR ,EDAC_DEVICE ,"Error PortB DBIRQ alloc\n" ); + rc = -ENODEV ; + goto err_release_group_1; + } + rc =devm_request_irq (&altdev->ddev, altdev->db_irq, + prv->ecc_irq_handler,IRQF_TRIGGER_HIGH , + ecc_name, altdev); +if (rc) { +edac_printk (KERN_ERR ,EDAC_DEVICE ,"PortB DBERR IRQ error\n" ); + goto err_release_group_1; + } } -#endif rc =edac_device_add_device (dci);if (rc) {
@@ -1974,29 +1973,29 @@ static int altr_edac_a10_device_add(stru goto err_release_group1; } -#ifdef CONFIG_64BIT -/* Use IRQ to determine SError origin instead of assigning IRQ */ - rc =of_property_read_u32_index (np,"interrupts" ,0 , &altdev->db_irq); -if (rc) { -edac_printk (KERN_ERR ,EDAC_DEVICE , -"Unable to parse DB IRQ index\n" ); - goto err_release_group1; - } -#else - altdev->db_irq =irq_of_parse_and_map (np,1 ); -if (!altdev->db_irq) { -edac_printk (KERN_ERR ,EDAC_DEVICE ,"Error allocating DBIRQ\n" ); - rc = -ENODEV ; - goto err_release_group1; - } - rc =devm_request_irq (edac->dev, altdev->db_irq, prv->ecc_irq_handler, -IRQF_TRIGGER_HIGH , - ecc_name, altdev); -if (rc) { -edac_printk (KERN_ERR ,EDAC_DEVICE ,"No DBERR IRQ resource\n" ); - goto err_release_group1; +if (edac->is_s10) { +/* Use IRQ to determine SError origin instead of assigning IRQ */ + rc =of_property_read_u32_index (np,"interrupts" ,0 , &altdev->db_irq); +if (rc) { +edac_printk (KERN_ERR ,EDAC_DEVICE , +"Unable to parse DB IRQ index\n" ); + goto err_release_group1; + } + }else { + altdev->db_irq =irq_of_parse_and_map (np,1 ); +if (!altdev->db_irq) { +edac_printk (KERN_ERR ,EDAC_DEVICE ,"Error allocating DBIRQ\n" ); + rc = -ENODEV ; + goto err_release_group1; + } + rc =devm_request_irq (edac->dev, altdev->db_irq, prv->ecc_irq_handler, +IRQF_TRIGGER_HIGH , + ecc_name, altdev); +if (rc) { +edac_printk (KERN_ERR ,EDAC_DEVICE ,"No DBERR IRQ resource\n" ); + goto err_release_group1; + } } -#endif rc =edac_device_add_device (dci);if (rc) {
@@ -2122,6 +2121,8 @@ static int altr_edac_a10_probe(struct plplatform_set_drvdata (pdev, edac);INIT_LIST_HEAD (&edac->a10_ecc_devices); + edac->is_s10 = !!device_get_match_data (&pdev->dev); + edac->ecc_mgr_map =altr_sysmgr_regmap_lookup_by_phandle (pdev->dev.of_node,"altr,sysmgr-syscon" );
@@ -2207,7 +2208,7 @@ static int altr_edac_a10_probe(struct plstatic const struct of_device_id altr_edac_a10_of_match[] = { { .compatible ="altr,socfpga-a10-ecc-manager" }, - { .compatible ="altr,socfpga-s10-ecc-manager" }, + { .compatible ="altr,socfpga-s10-ecc-manager" , .data = (void *)1 }, {}, };MODULE_DEVICE_TABLE (of, altr_edac_a10_of_match);
drivers/edac/altera_edac.h +1 -0
@@ -395,6 +395,7 @@ struct altr_arria10_edac {struct irq_chip irq_chip;struct list_head a10_ecc_devices;struct notifier_block panic_notifier; + bool is_s10; };#endif /* #ifndef _ALTERA_EDAC_H */
Greg Kroah-Hartman
maintainerPATCH 728/877 EDAC/altera: Use parent device for devres in altr_portb_setup()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dinh Nguyen <[email protected]>
[ Upstream commit 9868f5c077dfe0b606331f2e782484f91a5789a5 ]
Anchor the devres group and the devm-managed IRQ requests in altr_portb_setup() to the actual parent device (device->edac->dev) instead of the embedded struct device inside the copied per-port altr_edac_device_dev.
This keeps devres_open_group(), devm_request_irq(), devres_remove_group() and devres_release_group() all referring to the same long-lived device so the group and the resources allocated inside it are torn down together.
--- drivers/edac/altera_edac.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/edac/altera_edac.c +5 -5
@@ -1534,7 +1534,7 @@ static int altr_portb_setup(struct altr_ altdev = dci->pvt_info; *altdev = *device; -if (!devres_open_group (&altdev->ddev, altr_portb_setup,GFP_KERNEL )) +if (!devres_open_group (device->edac->dev, altr_portb_setup,GFP_KERNEL ))return -ENOMEM ;/* Update PortB specific values */
@@ -1562,7 +1562,7 @@ static int altr_portb_setup(struct altr_ rc = -ENODEV ; goto err_release_group_1; } - rc =devm_request_irq (&altdev->ddev, altdev->sb_irq, + rc =devm_request_irq (device->edac->dev, altdev->sb_irq, prv->ecc_irq_handler,IRQF_TRIGGER_HIGH , ecc_name, altdev);if (rc) {
@@ -1584,7 +1584,7 @@ static int altr_portb_setup(struct altr_ rc = -ENODEV ; goto err_release_group_1; } - rc =devm_request_irq (&altdev->ddev, altdev->db_irq, + rc =devm_request_irq (device->edac->dev, altdev->db_irq, prv->ecc_irq_handler,IRQF_TRIGGER_HIGH , ecc_name, altdev);if (rc) {
@@ -1604,13 +1604,13 @@ static int altr_portb_setup(struct altr_list_add (&altdev->next, &altdev->edac->a10_ecc_devices); -devres_remove_group (&altdev->ddev, altr_portb_setup); +devres_remove_group (device->edac->dev, altr_portb_setup);return 0 ; err_release_group_1:edac_device_free_ctl_info (dci); -devres_release_group (&altdev->ddev, altr_portb_setup); +devres_release_group (device->edac->dev, altr_portb_setup);edac_printk (KERN_ERR ,EDAC_DEVICE ,"%s:Error setting up EDAC device: %d\n" , ecc_name, rc);return rc;
Greg Kroah-Hartman
maintainerPATCH 729/877 genetlink: pin family module during policy dump
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: XingWang Xiang <[email protected]>
[ Upstream commit 6a1094c34d176827b2b173e163dcc964a13af93f ]
The generic netlink controller's policy dump keeps pointers to the target family's operation and policy tables in its callback state. A dump may be split across multiple skbs and remain pending after the initial request.
Netlink pins the module which owns the dump callback, but in this case that is the controller's owner rather than the target family's owner. The target family can consequently be unregistered and its module unloaded while a policy dump is pending. Advancing the dump then dereferences policy memory from the unloaded module.
Take a reference to the target family's module when the dump starts. Drop it from the error and done paths. This matches the lifetime for which the dump context retains the family and policy pointers.
--- net/netlink/genetlink.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
net/netlink/genetlink.c +16 -5
@@ -1514,6 +1514,7 @@ struct ctrl_dump_policy_ctx {struct netlink_policy_dump_state *state;const struct genl_family *rt;struct genl_op_iter *op_iter; +struct module *owner;u32 op;u16 fam_id; u8 dump_map:1,
@@ -1556,6 +1557,9 @@ static int ctrl_dumppolicy_start(structreturn -ENOENT ; ctx->rt = rt; + ctx->owner = rt->module; +if (!try_module_get (ctx->owner)) +return -ENOENT ;if (tb[CTRL_ATTR_OP ]) {struct genl_split_ops doit, dump;
@@ -1566,7 +1570,7 @@ static int ctrl_dumppolicy_start(struct err =genl_get_cmd_both (ctx->op, rt, &doit, &dump);if (err) {NL_SET_BAD_ATTR (cb->extack, tb[CTRL_ATTR_OP ]); -return err; + goto err_put_owner; }if (doit.policy) {
@@ -1584,16 +1588,20 @@ static int ctrl_dumppolicy_start(struct goto err_free_state; } -if (!ctx->state) -return -ENODATA ; +if (!ctx->state) { + err = -ENODATA ; + goto err_put_owner; + } ctx->dump_map =1 ;return 0 ; } ctx->op_iter =kmalloc (sizeof (*ctx->op_iter),GFP_KERNEL ); -if (!ctx->op_iter) -return -ENOMEM ; +if (!ctx->op_iter) { + err = -ENOMEM ; + goto err_put_owner; + }genl_op_iter_init (rt, ctx->op_iter); ctx->dump_map =genl_op_iter_next (ctx->op_iter);
@@ -1625,6 +1633,8 @@ err_free_state:netlink_policy_dump_free (ctx->state); err_free_op_iter:kfree (ctx->op_iter); +err_put_owner: +module_put (ctx->owner);return err; }
@@ -1763,6 +1773,7 @@ static int ctrl_dumppolicy_done(struct nkfree (ctx->op_iter);netlink_policy_dump_free (ctx->state); +module_put (ctx->owner);return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 730/877 drm/bridge: tc358768: Enforce input bus flags via atomic_check
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leonardo Costa <[email protected]>
[ Upstream commit ed761e0693950fcb4f6b0f60387a3961b972adf3 ]
The tc358768 declares static bridge timings requiring pixel data to be sampled on the positive clock edge.
However, the DRM core default propagation simply copies the output-side bus flags, coming from the next bridge, connector or panel, to the input side. If the propagated flags are incompatible with the bridge ones, the data is wrongly sampled, typically resulting in visual artifacts on the panel.
Implement the atomic_check hook, replacing the mutually exclusive mode_fixup, and set the bridge state input bus flags to the ones required by the tc358768. The sync polarity defaulting previously done in mode_fixup is carried over into atomic_check unchanged.
--- drivers/gpu/drm/bridge/tc358768.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/gpu/drm/bridge/tc358768.c +10 -5
@@ -1145,10 +1145,13 @@ tc358768_atomic_get_input_bus_fmts(strucreturn input_fmts; } -static bool tc358768_mode_fixup (struct drm_bridge *bridge, -const struct drm_display_mode *mode, -struct drm_display_mode *adjusted_mode) +static int tc358768_bridge_atomic_check (struct drm_bridge *bridge, +struct drm_bridge_state *bridge_state, +struct drm_crtc_state *crtc_state, +struct drm_connector_state *conn_state) { +struct drm_display_mode *adjusted_mode = &crtc_state->adjusted_mode; +/* Default to positive sync */ if (!(adjusted_mode->flags &
@@ -1159,13 +1162,15 @@ static bool tc358768_mode_fixup(struct d (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) adjusted_mode->flags |=DRM_MODE_FLAG_PVSYNC ; -return true; + bridge_state->input_bus_cfg.flags = bridge->timings->input_bus_flags; + +return 0 ; }static const struct drm_bridge_funcs tc358768_bridge_funcs = { .attach = tc358768_bridge_attach, .mode_valid = tc358768_bridge_mode_valid, - .mode_fixup = tc358768_mode_fixup, + .atomic_check = tc358768_bridge_atomic_check, .pre_enable = tc358768_bridge_pre_enable, .enable = tc358768_bridge_enable, .disable = tc358768_bridge_disable,
Greg Kroah-Hartman
maintainerPATCH 731/877 io_uring/rw: end write accounting from ->ki_complete
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jens Axboe <[email protected]>
[ Upstream commit 796aa0547557e63338657ed1c487906f9fac4c73 ]
Commit b000145e9907 moved both the fsnotify calls and the write accounting out of the kiocb completion handler and into the io_req_rw_complete() task_work. However, only the fsnotify part actually needed to move as it may sleep. Ending the write accounting is just a percpu_up_read() on the superblock writers sem.
Deferring it is a problem, because it makes dropping SB_FREEZE_WRITE protection depend on the ring owner getting to running task_work. But the task may be blocked in freeze_super(), causing it to never get to that:
task io-wq worker
--------------------------------------------------------------
io_write()
io_kiocb_start_write() (takes sb_writers, hidden from
lockdep by __sb_writers_release)
write_iter() -> -EIOCBQUEUED
ioctl(FS_IOC_SHUTDOWN)
bdev_freeze()
freeze_super()
percpu_down_write() <- waits for the reader above
io_write()
kiocb_start_write()
percpu_down_read() <- queued
behind the writer
<bio completes>
io_complete_rw()
queues io_req_rw_complete() <- never runs, task is in D state
End the write from io_complete_rw() instead, and leave only the fsnotify calls in task_work.
--- io_uring/rw.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-)
io_uring/rw.c +15 -17
@@ -460,31 +460,23 @@ static void io_req_end_write(struct io_k } } -/* -* Trigger the notifications after having done some IO, and finish the write -* accounting, if any. -*/ -static void io_req_io_end (struct io_kiocb *req) +/* Trigger the notifications after having done some IO. */ +static void io_req_io_notify (struct io_kiocb *req) { struct io_rw *rw = io_kiocb_to_cmd(req, struct io_rw); -if (rw->kiocb.ki_flags &IOCB_WRITE ) { -io_req_end_write (req); +if (rw->kiocb.ki_flags &IOCB_WRITE )fsnotify_modify (req->file); - }else { +else fsnotify_access (req->file); - } }static bool __io_complete_rw_common (struct io_kiocb *req,long res) {if (unlikely (res != req->cqe.res)) {if ((res == -EOPNOTSUPP || res == -EAGAIN ) &&io_rw_should_reissue (req)) { -/* -* Reissue will start accounting again, finish the -* current cycle. -*/ -io_req_io_end (req); +/* Reissue bypasses task_work, so notify here. */ +io_req_io_notify (req); req->flags |=REQ_F_REISSUE |REQ_F_BL_NO_RECYCLE ;return true; }
@@ -519,7 +511,7 @@ void io_req_rw_complete(struct io_kiocbio_req_set_res (req,io_fixup_rw_res (req, res),0 ); } -io_req_io_end (req); +io_req_io_notify (req);if (req->flags & (REQ_F_BUFFER_SELECTED |REQ_F_BUFFER_RING )) req->cqe.flags |=io_put_kbuf (req, req->cqe.res,NULL );
@@ -533,6 +525,10 @@ static void io_complete_rw(struct kiocb struct io_rw *rw = container_of(kiocb, struct io_rw, kiocb);struct io_kiocb *req =cmd_to_io_kiocb (rw); +/* ring owner may block in freeze_super() before task_work runs */ +if (kiocb->ki_flags &IOCB_WRITE ) +io_req_end_write (req); +if (!kiocb->dio_complete || !(kiocb->ki_flags &IOCB_DIO_CALLER_COMP )) {if (__io_complete_rw_common (req, res))return ;
@@ -604,11 +600,13 @@ static int kiocb_done(struct io_kiocb *rif (!__io_complete_rw_common (req, ret)) {u32 cflags =0 ; +if (rw->kiocb.ki_flags &IOCB_WRITE ) +io_req_end_write (req);/* -* Safe to call io_end from here as we're inline +* Safe to notify from here as we're inline * from the submission path. */ -io_req_io_end (req); +io_req_io_notify (req);if (sel) cflags =io_put_kbuf (req, ret, sel->buf_list);io_req_set_res (req, final_ret, cflags);
Greg Kroah-Hartman
maintainerPATCH 732/877 io_uring/net: dont overconsume buffers when using MSG_TRUNC
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gabriel Krisman Bertazi <[email protected]>
[ Upstream commit 6028b543884f8735e057ec9eea4908cd61cab230 ]
When a recv/recvmsg is issued with MSG_TRUNC and the incoming packet is larger than the provided buffer, the net layer returns the full length of the packet rather than the number of bytes actually copied into the buffer. As a result, io_uring advances more of the provided buffer ring than was actually filled. Use the actual filled region size to consume the buffer, but still return the full size to preserve MSG_TRUNC semantics.
Take care with multishot, because that seems to already truncate the consumption based on the available payload size.
This was reported in https://github.com/axboe/liburing/issues/1619.
--- io_uring/net.c | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-)
io_uring/net.c +33 -8
@@ -858,7 +858,7 @@ int io_recvmsg_prep(struct io_kiocb *reqstatic inline bool io_recv_finish (struct io_kiocb *req,struct io_async_msghdr *kmsg,struct io_br_sel *sel,bool mshot_finished, -unsigned issue_flags) +unsigned issue_flags,int consumed) { struct io_sr_msg *sr = io_kiocb_to_cmd(req, struct io_sr_msg);unsigned int cflags =0 ;
@@ -869,7 +869,7 @@ static inline bool io_recv_finish(structif (sr->flags &IORING_RECVSEND_BUNDLE ) {size_t this_ret = sel->val - sr->done_io; - cflags |=io_put_kbufs (req, this_ret, sel->buf_list,io_bundle_nbufs (kmsg, this_ret)); + cflags |=io_put_kbufs (req, consumed, sel->buf_list,io_bundle_nbufs (kmsg, consumed));if (sr->retry_flags &IO_SR_MSG_RETRY ) cflags = req->cqe.flags | (cflags &CQE_F_MASK );/* bundle with no more immediate buffers, we're done */
@@ -888,7 +888,7 @@ static inline bool io_recv_finish(structreturn false; } }else { - cflags |=io_put_kbuf (req, sel->val, sel->buf_list); + cflags |=io_put_kbuf (req, consumed, sel->buf_list); }/*
@@ -1021,6 +1021,8 @@ int io_recvmsg(struct io_kiocb *req, unsint ret, min_ret =0 ;bool force_nonblock = issue_flags &IO_URING_F_NONBLOCK ;bool mshot_finished = true; +int consumed =0 ; +size_t len; sock =sock_from_file (req->file);if (unlikely (!sock))
@@ -1036,9 +1038,8 @@ int io_recvmsg(struct io_kiocb *req, uns retry_multishot: sel.buf_list =NULL ; + len = sr->len;if (io_do_buffer_select (req)) { -size_t len = sr->len; - sel =io_buffer_select (req, &len, issue_flags);if (!sel.addr)return -ENOBUFS ;
@@ -1059,6 +1060,7 @@ retry_multishot:if (req->flags &REQ_F_APOLL_MULTISHOT ) { ret =io_recvmsg_multishot (sock, sr, kmsg, flags, &mshot_finished); + consumed = ret; }else {/* disable partial retry for recvmsg with cmsg attached */ if (flags &MSG_WAITALL && !kmsg->msg.msg_controllen)
@@ -1066,6 +1068,15 @@ retry_multishot: ret =__sys_recvmsg_sock (sock, &kmsg->msg, sr->umsg, kmsg->uaddr, flags); +/* +* With MSG_TRUNC, the net layer will return the full size of +* the packet, even if we only filled part of it in the buffers. +* Adjust the returned size to consume only the real part of the +* buffer. +*/ + consumed = ret; +if (ret >0 ) + consumed =min_t (size_t, ret, len); }if (ret < min_ret) {
@@ -1094,7 +1105,7 @@ retry_multishot:io_kbuf_recycle (req, sel.buf_list, issue_flags); sel.val = ret; -if (!io_recv_finish (req, kmsg, &sel, mshot_finished, issue_flags)) +if (!io_recv_finish (req, kmsg, &sel, mshot_finished, issue_flags, consumed)) goto retry_multishot;return sel.val;
@@ -1177,9 +1188,10 @@ int io_recv(struct io_kiocb *req, unsignstruct io_br_sel sel;struct socket *sock;unsigned flags; -int ret, min_ret =0 ; +int ret, min_ret =0 , consumed =0 ;bool force_nonblock = issue_flags &IO_URING_F_NONBLOCK ;bool mshot_finished; +size_t len =0 ;if (!(req->flags &REQ_F_POLLED ) && (sr->flags &IORING_RECVSEND_POLL_FIRST ))
@@ -1195,6 +1207,7 @@ int io_recv(struct io_kiocb *req, unsign retry_multishot: sel.buf_list =NULL ; + len = sr->len;if (io_do_buffer_select (req)) { sel.val = sr->len; ret =io_recv_buf_select (req, kmsg, &sel, issue_flags);
@@ -1202,6 +1215,7 @@ retry_multishot: kmsg->msg.msg_inq =-1 ; goto out_free; } + len =iov_iter_count (&kmsg->msg.msg_iter); sr->buf =NULL ; }
@@ -1234,6 +1248,17 @@ out_free: } mshot_finished = ret <=0 ; + +/* +* With MSG_TRUNC, the net layer will return the full size of +* the packet, even if we only filled part of it in the buffers. +* Adjust the returned size to consume only the real part of the +* buffer. +*/ + consumed = ret; +if (ret >0 ) + consumed =min_t (size_t, ret, len); +if (ret >0 ) ret += sr->done_io;else if (sr->done_io)
@@ -1242,7 +1267,7 @@ out_free:io_kbuf_recycle (req, sel.buf_list, issue_flags); sel.val = ret; -if (!io_recv_finish (req, kmsg, &sel, mshot_finished, issue_flags)) +if (!io_recv_finish (req, kmsg, &sel, mshot_finished, issue_flags, consumed)) goto retry_multishot;return sel.val;
Greg Kroah-Hartman
maintainerPATCH 733/877 bootconfig: Fix integer overflow in initrd size check
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Masami Hiramatsu (Google)" <[email protected]>
[ Upstream commit 7812d6dab0698001e50e8c2f901e17da3eb6f429 ]
Sashiko reported that in get_boot_config_from_initrd(), a crafted initrd with a huge bootconfig size (such as 0xFFFFFFFF) can cause the pointer arithmetic:
data = ((void *)hdr) - size;
to wrap around on 32-bit systems (or when pointer subtraction overflows). Because data wraps around, the subsequent bounds check:
if ((unsigned long)data < initrd_start)
evaluates to false, bypassing the check. The kernel then calls xbc_calc_checksum(data, size), which attempts to read 4GB of memory, hitting unmapped pages and triggering a fatal kernel page fault during early boot. Furthermore, on 64-bit systems with an initrd > 4.29 GB, an unbounded 32-bit size can similarly bypass the initrd_start check.
Fix this by:
1. Ensuring the initrd is at least large enough to contain the bootconfig footer and verifying hdr is within the initrd bounds.
2. Checking that size does not exceed XBC_DATA_MAX and does not exceed the available space between initrd_start and hdr before performing pointer subtraction.
--- init/main.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-)
init/main.c +15 -10
@@ -270,7 +270,8 @@ static void * __init get_boot_config_frou32 *hdr;int i; -if (!initrd_end) +if (!initrd_end || initrd_end < initrd_start || + initrd_end - initrd_start <BOOTCONFIG_MAGIC_LEN +8 )return NULL ; data = (char *)initrd_end -BOOTCONFIG_MAGIC_LEN ;
@@ -287,16 +288,26 @@ static void * __init get_boot_config_fro found: hdr = (u32 *)(data -8 ); +if ((unsigned long )hdr < initrd_start) +return NULL ; + size =le32_to_cpu (hdr[0 ]); csum =le32_to_cpu (hdr[1 ]); - data = ((void *)hdr) - size; -if ((unsigned long )data < initrd_start) { -pr_err ("bootconfig size %d is greater than initrd size %ld\n" , +if (size >XBC_DATA_MAX ) { +pr_err ("bootconfig size %u is greater than max size %d\n" , + size,XBC_DATA_MAX ); +return NULL ; + } + +if (size > ((unsigned long )hdr - initrd_start)) { +pr_err ("bootconfig size %u is greater than initrd size %lu\n" , size, initrd_end - initrd_start);return NULL ; } + data = ((void *)hdr) - size; +if (xbc_calc_checksum (data, size) != csum) {pr_err ("bootconfig checksum failed\n" );return NULL ;
@@ -399,12 +410,6 @@ static void __init setup_boot_config(voireturn ; } -if (size >=XBC_DATA_MAX ) { -pr_err ("bootconfig size %ld greater than max size %d\n" , - (long )size,XBC_DATA_MAX ); -return ; - } - ret =xbc_init (data, size, &msg, &pos);if (ret <0 ) {if (pos <0 )
Greg Kroah-Hartman
maintainerPATCH 734/877 net: bridge: use option bits for CFM/MRP frame handlers
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhiling Zou <[email protected]>
[ Upstream commit 7a49e6b16f36b8e085521699adbca3e321b6dd0c ]
CFM and MRP register a global br_frame_type whose hlist_node is linked into the per-bridge frame_type_list when the first MEP/MRP instance is created. Enabling the protocol on multiple bridges therefore inserts the same node into multiple lists. Unregistering it on one bridge then corrupts list state belonging to another.
These handlers can only be installed once per bridge, and they are uncommon. Track their per-bridge enable state with net_bridge option bits, which already live on the Rx hot cache line, and dispatch the matching handler directly from the receive path. Check both bits together first as an unlikely case.
Remove the generic frame_type_list and br_frame_type helpers, which have had no other users since CFM and MRP were added. That shrinks struct net_bridge by 8 bytes and drops the list walk from the fast path. When neither protocol is compiled in, BR_CFM_MRP_OPTS is 0 and the compiler prunes the branch.
--- net/bridge/br_cfm.c | 11 +++-------- net/bridge/br_device.c | 1 - net/bridge/br_input.c | 35 ++++++++++++++--------------------- net/bridge/br_mrp.c | 13 +++---------- net/bridge/br_private.h | 26 +++++++++++++++----------- 5 files changed, 35 insertions(+), 51 deletions(-)
net/bridge/br_cfm.c +3 -8
@@ -367,7 +367,7 @@ static u32 ccm_tlv_extract(struct sk_buf }/* note: already called with rcu_read_lock */ -static int br_cfm_frame_rx (struct net_bridge_port *port,struct sk_buff *skb) +int br_cfm_frame_rx (struct net_bridge_port *port,struct sk_buff *skb) {u32 mdlevel, interval, size, index, max;const struct br_cfm_common_hdr *hdr;
@@ -489,11 +489,6 @@ static int br_cfm_frame_rx(struct net_brreturn 1 ; } -static struct br_frame_type cfm_frame_type__read_mostly = { - .type =cpu_to_be16 (ETH_P_CFM ), - .frame_handler = br_cfm_frame_rx, -}; - int br_cfm_mep_create(struct net_bridge *br, const u32 instance, struct br_cfm_mep_create *const create,
@@ -559,7 +554,7 @@ int br_cfm_mep_create(struct net_bridgeINIT_DELAYED_WORK (&mep->ccm_tx_dwork, ccm_tx_work_expired);if (hlist_empty (&br->mep_list)) -br_add_frame (br, &cfm_frame_type); +br_opt_toggle (br,BROPT_CFM_ENABLED , true);hlist_add_tail_rcu (&mep->head, &br->mep_list);
@@ -588,7 +583,7 @@ static void mep_delete_implementation(stkfree_rcu (mep, rcu);if (hlist_empty (&br->mep_list)) -br_del_frame (br, &cfm_frame_type); +br_opt_toggle (br,BROPT_CFM_ENABLED , false); } int br_cfm_mep_delete(struct net_bridge *br,
net/bridge/br_device.c +0 -1
@@ -501,7 +501,6 @@ void br_dev_setup(struct net_device *devspin_lock_init (&br->lock);INIT_LIST_HEAD (&br->port_list);INIT_HLIST_HEAD (&br->fdb_list); -INIT_HLIST_HEAD (&br->frame_type_list);#if IS_ENABLED (CONFIG_BRIDGE_MRP )INIT_HLIST_HEAD (&br->mrp_list);#endif
net/bridge/br_input.c +14 -21
@@ -303,17 +303,25 @@ frame_finish:return RX_HANDLER_CONSUMED ; } +#define BR_CFM_MRP_OPTS \ + ((IS_ENABLED(CONFIG_BRIDGE_CFM) ? BIT(BROPT_CFM_ENABLED) : 0UL) | \ + (IS_ENABLED(CONFIG_BRIDGE_MRP) ? BIT(BROPT_MRP_ENABLED) : 0UL)) +/* Return 0 if the frame was not processed otherwise 1 * note: already called with rcu_read_lock */ static int br_process_frame_type (struct net_bridge_port *p,struct sk_buff *skb) { -struct br_frame_type *tmp; +struct net_bridge *br = p->br; -hlist_for_each_entry_rcu (tmp, &p->br->frame_type_list, list) -if (unlikely (tmp->type == skb->protocol)) -return tmp->frame_handler (p, skb); +if (skb->protocol ==htons (ETH_P_CFM ) && +br_opt_get (br,BROPT_CFM_ENABLED )) +return br_cfm_frame_rx (p, skb); + +if (skb->protocol ==htons (ETH_P_MRP ) && +br_opt_get (br,BROPT_MRP_ENABLED )) +return br_mrp_process (p, skb);return 0 ; }
@@ -407,7 +415,8 @@ static rx_handler_result_t br_handle_fra } } -if (unlikely (br_process_frame_type (p, skb))) +if (unlikely ((READ_ONCE (p->br->options) &BR_CFM_MRP_OPTS ) && +br_process_frame_type (p, skb)))return RX_HANDLER_PASS ; forward:
@@ -448,19 +457,3 @@ rx_handler_func_t *br_get_rx_handler(conreturn br_handle_frame; } - -void br_add_frame (struct net_bridge *br,struct br_frame_type *ft) -{ -hlist_add_head_rcu (&ft->list, &br->frame_type_list); -} - -void br_del_frame (struct net_bridge *br,struct br_frame_type *ft) -{ -struct br_frame_type *tmp; - -hlist_for_each_entry (tmp, &br->frame_type_list, list) -if (ft == tmp) { -hlist_del_rcu (&ft->list); -return ; - } -}
net/bridge/br_mrp.c +3 -10
@@ -6,13 +6,6 @@static const u8 mrp_test_dmac[ETH_ALEN ] = {0x1 ,0x15 ,0x4e ,0x0 ,0x0 ,0x1 };static const u8 mrp_in_test_dmac[ETH_ALEN ] = {0x1 ,0x15 ,0x4e ,0x0 ,0x0 ,0x3 }; -static int br_mrp_process (struct net_bridge_port *p,struct sk_buff *skb); - -static struct br_frame_type mrp_frame_type__read_mostly = { - .type =cpu_to_be16 (ETH_P_MRP ), - .frame_handler = br_mrp_process, -}; -static bool br_mrp_is_ring_port (struct net_bridge_port *p_port,struct net_bridge_port *s_port,struct net_bridge_port *port)
@@ -486,7 +479,7 @@ static void br_mrp_del_impl(struct net_bkfree_rcu (mrp, rcu);if (hlist_empty (&br->mrp_list)) -br_del_frame (br, &mrp_frame_type); +br_opt_toggle (br,BROPT_MRP_ENABLED , false); }/* Adds a new MRP instance.
@@ -536,7 +529,7 @@ int br_mrp_add(struct net_bridge *br, strcu_assign_pointer (mrp->s_port, p);if (hlist_empty (&br->mrp_list)) -br_add_frame (br, &mrp_frame_type); +br_opt_toggle (br,BROPT_MRP_ENABLED , true);INIT_DELAYED_WORK (&mrp->test_work, br_mrp_test_work_expired);INIT_DELAYED_WORK (&mrp->in_test_work, br_mrp_in_test_work_expired);
@@ -1241,7 +1234,7 @@ no_forward:* normal forwarding. * note: already called with rcu_read_lock */ -static int br_mrp_process (struct net_bridge_port *p,struct sk_buff *skb) +int br_mrp_process (struct net_bridge_port *p,struct sk_buff *skb) {/* If there is no MRP instance do normal forwarding */ if (likely (!(p->flags &BR_MRP_AWARE )))
net/bridge/br_private.h +15 -11
@@ -486,12 +486,13 @@ enum net_bridge_opts {BROPT_VLAN_BRIDGE_BINDING ,BROPT_MCAST_VLAN_SNOOPING_ENABLED ,BROPT_MST_ENABLED , +BROPT_CFM_ENABLED , + BROPT_MRP_ENABLED, };struct net_bridge {spinlock_t lock;spinlock_t hash_lock; -struct hlist_head frame_type_list;struct net_device *dev;unsigned long options;/* These fields are accessed on each packet */
@@ -919,16 +920,6 @@ int nbp_backup_change(struct net_bridge_int br_handle_frame_finish (struct net *net,struct sock *sk,struct sk_buff *skb);rx_handler_func_t *br_get_rx_handler (const struct net_device *dev); -struct br_frame_type { -__be16 type; -int (*frame_handler)(struct net_bridge_port *port, -struct sk_buff *skb); -struct hlist_node list; -}; - -void br_add_frame (struct net_bridge *br,struct br_frame_type *ft); -void br_del_frame (struct net_bridge *br,struct br_frame_type *ft); -static inline bool br_rx_handler_check_rcu (const struct net_device *dev) {return rcu_dereference (dev->rx_handler) ==br_get_rx_handler (dev);
@@ -2033,6 +2024,7 @@ int br_mrp_parse(struct net_bridge *br,bool br_mrp_enabled (struct net_bridge *br);void br_mrp_port_del (struct net_bridge *br,struct net_bridge_port *p);int br_mrp_fill_info (struct sk_buff *skb,struct net_bridge *br); +int br_mrp_process (struct net_bridge_port *p,struct sk_buff *skb);#else static inline int br_mrp_parse(struct net_bridge *br, struct net_bridge_port *p, struct nlattr *attr, int cmd,
@@ -2056,6 +2048,11 @@ static inline int br_mrp_fill_info(struc return 0; } +static inline int br_mrp_process (struct net_bridge_port *p,struct sk_buff *skb) +{ +return 0 ; +} +#endif /* br_cfm.c */
@@ -2064,6 +2061,7 @@ int br_cfm_parse(struct net_bridge *br, struct nlattr *attr, int cmd, struct netlink_ext_ack *extack);bool br_cfm_created (struct net_bridge *br);void br_cfm_port_del (struct net_bridge *br,struct net_bridge_port *p); +int br_cfm_frame_rx (struct net_bridge_port *port,struct sk_buff *skb);int br_cfm_config_fill_info (struct sk_buff *skb,struct net_bridge *br); int br_cfm_status_fill_info(struct sk_buff *skb, struct net_bridge *br,
@@ -2088,6 +2086,12 @@ static inline void br_cfm_port_del(struc { } +static inline int br_cfm_frame_rx (struct net_bridge_port *port, +struct sk_buff *skb) +{ +return 0 ; +} +static inline int br_cfm_config_fill_info (struct sk_buff *skb,struct net_bridge *br) {return -EOPNOTSUPP ;
Greg Kroah-Hartman
maintainerPATCH 735/877 drm/xe: Flush LSC untyped L1 dataport cache after rcs/ccs batches
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Hellström <[email protected]>
[ Upstream commit f5fcf7e638b904397ec0f66d3ea6766ef0cfe25b ]
emit_render_cache_flush() sets PIPE_CONTROL0_HDC_PIPELINE_FLUSH to flush the L2/HDC data cache before fence signalling, but it never requests a flush of the LSC untyped L1 data cache via the 'Untyped Data-Port Cache Flush Enable' bit in PIPE_CONTROL DWord0[11].
Per the Bspec, in 3D pipeline mode HDC Pipeline Flush is documented to also flush/invalidate the untyped L1 cache, but only depending on how HDC_CHICKEN0[13:11] is programmed. Starting with MTL, this coupling between HDC Pipeline Flush and the untyped L1 cache flush no longer holds in practice, regardless of how HDC_CHICKEN0 is programmed, so relying on it is not safe on newer platforms such as BMG. Mesa's Vulkan driver (anv) has been assuming the kernel flushes both caches between submissions, and hit user-visible corruption in apps such as Llama.cpp because of this gap; it now works around it by flushing both caches again from userspace at the end of every command buffer.
Correctness between submissions on the same queue is userspace's responsibility and belongs in Mesa, not the kernel. However, for security we must ensure stale data can't leak through the untyped L1 dataport cache once memory is reclaimed or evicted, which requires the KMD to flush it before releasing memory for reuse.
Prior to MTL, HDC_CHICKEN0 could be programmed (as already done for DG2 via Wa_22010960976/Wa_14013347512) to reliably keep HDC Pipeline Flush coupled to the untyped L1 cache flush, so those platforms are unaffected. Mesa's own anv driver found that on MTL the HW disconnected the two independently of how HDC_CHICKEN0 is programmed, and could not bring the old behavior back even by writing the register by hand; see Mesa commit 7c2ff46a4fc3 ("anv: don't prevent L1 untyped cache flush in 3D mode"). The kernel can't reliably request the flush from the CS on MTL either, so restrict the new PIPE_CONTROL bit to GRAPHICS_VERx100 >= 2000 (Xe2 and later), where it can be relied on.
Explicitly set PIPE_CONTROL0_UNTYPED_DATAPORT_CACHE_FLUSH together with PIPE_CONTROL0_HDC_PIPELINE_FLUSH in emit_render_cache_flush() on Xe2 and later, so the L1 data cache is known clean before memory is released for reuse, without depending on undocumented platform-specific HDC_CHICKEN0 behavior.
Bspec: 56551
--- drivers/gpu/drm/xe/instructions/xe_gpu_commands.h | 1 + drivers/gpu/drm/xe/xe_ring_ops.c | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-)
drivers/gpu/drm/xe/instructions/xe_gpu_commands.h +1 -0
@@ -41,6 +41,7 @@#define GFX_OP_PIPE_CONTROL (len) ((0x3<<29)|(0x3<<27)|(0x2<<24)|((len)-2)) +#define PIPE_CONTROL0_UNTYPED_DATAPORT_CACHE_FLUSH BIT(11)/* gen12 */ #define PIPE_CONTROL0_HDC_PIPELINE_FLUSH BIT(9)/* gen12 */ #define PIPE_CONTROL_COMMAND_CACHE_INVALIDATE (1<<29)
drivers/gpu/drm/xe/xe_ring_ops.c +14 -2
@@ -174,9 +174,21 @@ static int emit_store_imm_ppgtt_posted(ustatic int emit_render_cache_flush (struct xe_sched_job *job,u32 *dw,int i) {struct xe_gt *gt = job->q->gt; +struct xe_device *xe =gt_to_xe (gt);bool lacks_render = !(gt->info.engine_mask &XE_HW_ENGINE_RCS_MASK ); -u32 flags; +u32 flags0, flags; + flags0 =PIPE_CONTROL0_HDC_PIPELINE_FLUSH ; +/* +* Prior to MTL, HDC Pipeline Flush reliably also flushes the LSC +* untyped L1 dataport cache, provided HDC_CHICKEN0 is programmed +* correctly. Starting with MTL that coupling no longer holds +* regardless of how HDC_CHICKEN0 is programmed, but explicitly +* requesting the flush via PIPE_CONTROL is itself only reliable +* from Xe2 onward, so only gate it in on Xe2+. +*/ +if (GRAPHICS_VERx100 (xe) >=2000 ) + flags0 |=PIPE_CONTROL0_UNTYPED_DATAPORT_CACHE_FLUSH ; flags = (PIPE_CONTROL_CS_STALL | PIPE_CONTROL_TILE_CACHE_FLUSH | PIPE_CONTROL_RENDER_TARGET_CACHE_FLUSH |
@@ -192,7 +204,7 @@ static int emit_render_cache_flush(strucelse if (job->q->class ==XE_ENGINE_CLASS_COMPUTE ) flags &= ~PIPE_CONTROL_3D_ENGINE_FLAGS ; -return emit_pipe_control (dw, i,PIPE_CONTROL0_HDC_PIPELINE_FLUSH , flags,0 ,0 ); +return emit_pipe_control (dw, i, flags0, flags,0 ,0 ); }static int emit_pipe_control_to_ring_end (struct xe_hw_engine *hwe,u32 *dw,int i)
Greg Kroah-Hartman
maintainerPATCH 736/877 netfilter: cttimeout: detach dataplane timeout policy and repurpose refcount
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pablo Neira Ayuso <[email protected]>
[ Upstream commit 7d6a9cdb8d3a51d9cfe546a09a518ab3d2671549 ]
Add a refcount for struct nf_ct_timeout which is used by ct extension to set the custom ct timeout policy, this tells us that the ct timeout is being used by a conntrack entry. When the last conntrack entry drops the refcount on the ct timeout, the ct timeout is released.
Remove the refcount for control plane which controls if the ruleset refers to the timeout policy. After this update, it is possible to remove the ct timeout policy from nfnetlink_cttimeout immediately. This is for simplicity not to handle two refcounts on a single object.
Remove nf_queue_nf_hook_drop(): a packet sitting in nfqueue will just hold a reference to the nf_ct_timeout object until packet is reinjected, since this is part of the ct extension, this will be released by the time the conntrack is freed.
nf_ct_untimeout() is still called to clean up in a best effort basis:
the ct timeout on existing entries gets removed when the ct timeout goes away, but as long as the iptables ruleset still refers to the ct timeout through a template, new conntracks may keep attaching it and extend its lifetime until the rule is removed.
nf_ct_untimeout() is not called anymore from module removal path, this is unlikely to find timeouts give module refcount is bumped, and the new refcount already tracks the ct timeout policy use so it is released when unused.
Stable-dep-of: fec9b1de0d02 ("netfilter: cttimeout: prevent UAF during module unload")
--- include/net/netfilter/nf_conntrack_timeout.h | 27 ++++++ net/netfilter/nf_conntrack_core.c | 6 - net/netfilter/nf_conntrack_timeout.c | 27 +++++- net/netfilter/nfnetlink_cttimeout.c | 112 ++++++++++++--------------- net/netfilter/nft_ct.c | 7 - net/netfilter/xt_CT.c | 2 6 files changed, 107 insertions(+), 74 deletions(-)
include/net/netfilter/nf_conntrack_timeout.h +25 -2
@@ -12,6 +12,7 @@#define CTNL_TIMEOUT_NAME_MAX 32struct nf_ct_timeout { +refcount_t refcnt;__u16 l3num;const struct nf_conntrack_l4proto *l4proto;struct rcu_head rcu;
@@ -22,6 +23,22 @@ struct nf_conn_timeout {struct nf_ct_timeout __rcu *timeout; }; +static inline void nf_ct_timeout_put (const struct nf_conn *ct) +{ +#ifdef CONFIG_NF_CONNTRACK_TIMEOUT +struct nf_conn_timeout *timeout_ext; +struct nf_ct_timeout *timeout; + + timeout_ext =nf_ct_ext_find (ct,NF_CT_EXT_TIMEOUT ); +if (!timeout_ext) +return ; + + timeout =rcu_dereference (timeout_ext->timeout); +if (timeout &&refcount_dec_and_test (&timeout->refcnt)) +kfree_rcu (timeout, rcu); +#endif +} +static inline unsigned int *nf_ct_timeout_data (const struct nf_conn_timeout *t) {
@@ -56,8 +73,14 @@ struct nf_conn_timeout *nf_ct_timeout_ex#ifdef CONFIG_NF_CONNTRACK_TIMEOUT struct nf_conn_timeout *timeout_ext; +if (!timeout) +return NULL ; + timeout_ext =nf_ct_ext_add (ct,NF_CT_EXT_TIMEOUT , gfp); -if (timeout_ext ==NULL ) +if (!timeout_ext || timeout_ext->timeout) +return NULL ; + +if (!refcount_inc_not_zero (&timeout->refcnt))return NULL ;rcu_assign_pointer (timeout_ext->timeout, timeout);
@@ -75,7 +98,7 @@ static inline unsigned int *nf_ct_timeoustruct nf_conn_timeout *timeout_ext; timeout_ext =nf_ct_timeout_find (ct); -if (timeout_ext) +if (timeout_ext &&rcu_access_pointer (timeout_ext->timeout)) timeouts =nf_ct_timeout_data (timeout_ext);#endif return timeouts;
net/netfilter/nf_conntrack_core.c +4 -2
@@ -1692,16 +1692,18 @@ void nf_conntrack_free(struct nf_conn *c*/ WARN_ON (refcount_read (&ct->ct_general.use) !=0 ); +rcu_read_lock ();if (ct->status &IPS_SRC_NAT_DONE ) {const struct nf_nat_hook *nat_hook; -rcu_read_lock (); nat_hook =rcu_dereference (nf_nat_hook);if (nat_hook) nat_hook->remove_nat_bysrc (ct); -rcu_read_unlock (); } +nf_ct_timeout_put (ct); +rcu_read_unlock (); +kfree (ct->ext);kmem_cache_free (nf_conntrack_cachep, ct); cnet =nf_ct_pernet (net);
net/netfilter/nf_conntrack_timeout.c +24 -3
@@ -25,17 +25,32 @@const struct nf_ct_timeout_hooks __rcu *nf_ct_timeout_hook__read_mostly ;EXPORT_SYMBOL_GPL (nf_ct_timeout_hook); +/* nf_ct_iterate_cleanup() holds the conntrack lock. */ static int untimeout (struct nf_conn *ct,void *timeout) {struct nf_conn_timeout *timeout_ext =nf_ct_timeout_find (ct);if (timeout_ext) { -const struct nf_ct_timeout *t; +struct nf_ct_timeout *t; - t =rcu_access_pointer (timeout_ext->timeout); +rcu_read_lock (); + t =rcu_dereference (timeout_ext->timeout); +if (!t) { +rcu_read_unlock (); +return 0 ; + } -if (!timeout || t == timeout) +if (!timeout || t == timeout) {RCU_INIT_POINTER (timeout_ext->timeout,NULL ); + +/* No race with nf_conntrack_free() which is called +* only after the conntrack has been removed from +* the hashes. +*/ +if (refcount_dec_and_test (&t->refcnt)) +kfree_rcu (t, rcu); + } +rcu_read_unlock (); }/* We are not intended to delete this conntrack. */
@@ -70,6 +85,8 @@ int nf_ct_set_timeout(struct net *net, sconst char *errmsg =NULL ;int ret =0 ; +WARN_ON_ONCE (!nf_ct_is_template (ct)); +rcu_read_lock (); h =rcu_dereference (nf_ct_timeout_hook);if (!h) {
@@ -127,6 +144,8 @@ void nf_ct_destroy_timeout(struct nf_construct nf_conn_timeout *timeout_ext;const struct nf_ct_timeout_hooks *h; +WARN_ON_ONCE (!nf_ct_is_template (ct)); +rcu_read_lock (); h =rcu_dereference (nf_ct_timeout_hook);
@@ -139,6 +158,8 @@ void nf_ct_destroy_timeout(struct nf_conif (t) h->timeout_put (t);RCU_INIT_POINTER (timeout_ext->timeout,NULL ); +if (t &&refcount_dec_and_test (&t->refcnt)) +kfree_rcu (t, rcu); } }rcu_read_unlock ();
net/netfilter/nfnetlink_cttimeout.c +50 -62
219 lines not on this page · raw message
net/netfilter/nft_ct.c +3 -4
@@ -879,8 +879,6 @@ static void nft_ct_timeout_obj_eval(stru } } -rcu_assign_pointer (timeout->timeout, priv->timeout); -/* adjust the timeout as per 'new' state. ct is unconfirmed, * so the current timestamp must not be added. */
@@ -931,6 +929,7 @@ static int nft_ct_timeout_obj_init(const timeout->l3num = l3num; timeout->l4proto = l4proto; +refcount_set (&timeout->refcnt,1 ); ret =nf_ct_netns_get (ctx->net, ctx->family);if (ret <0 )
@@ -951,10 +950,10 @@ static void nft_ct_timeout_obj_destroy(cstruct nft_ct_timeout_obj *priv =nft_obj_data (obj);struct nf_ct_timeout *timeout = priv->timeout; -nf_queue_nf_hook_drop (ctx->net);nf_ct_untimeout (ctx->net, timeout);nf_ct_netns_put (ctx->net, ctx->family); -kfree_rcu (priv->timeout, rcu); +if (refcount_dec_and_test (&timeout->refcnt)) +kfree_rcu (priv->timeout, rcu); } static int nft_ct_timeout_obj_dump(struct sk_buff *skb,
net/netfilter/xt_CT.c +1 -1
@@ -284,7 +284,7 @@ static void xt_ct_tg_destroy(const strucstruct nf_conn_help *help;if (ct) { -if (info->helper[0 ] || info->timeout[0 ]) +if (info->helper[0 ])nf_queue_nf_hook_drop (par->net); help =nfct_help (ct);
Greg Kroah-Hartman
maintainerPATCH 737/877 netfilter: cttimeout: prevent UAF during module unload
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chengfeng Ye <[email protected]>
[ Upstream commit fec9b1de0d02de8dafa3cc344bcb91cf28660643 ]
nf_ct_set_timeout() protects the timeout hook dereference and policy lookup with rcu_read_lock(). cttimeout_exit(), however, unregisters the per-net operations before it clears the hook.
This allows the following interleaving:
CPU 0 CPU 1
cttimeout_exit() nf_ct_set_timeout()
unregister_pernet_subsys() rcu_read_lock()
kfree(pernet) h = nf_ct_timeout_hook
h->timeout_find_get()
nfct_timeout_pernet()
The hook still points to ctnl_timeout_find_get() when CPU 1 looks up the already freed per-net timeout list. KASAN reported:
BUG: KASAN: slab-use-after-free in ctnl_timeout_find_get Read of size 8 by task poc/90 Call Trace: ctnl_timeout_find_get+0x271/0x2a0 [nfnetlink_cttimeout] nf_ct_set_timeout+0x7b/0x3c0 xt_ct_tg_check+0x724/0xb20 xt_check_target+0x234/0xa90 do_ipt_set_ctl+0x570/0x1270 Allocated by task 89: __kmalloc_noprof+0x16e/0x460 ops_init+0x6d/0x420 register_pernet_operations+0x2f6/0x670 Freed by task 91: kfree+0x131/0x390 ops_undo_list+0x3d4/0x730 unregister_pernet_operations+0x232/0x490 unregister_pernet_subsys+0x1c/0x30 cttimeout_exit+0x52/0x970 [nfnetlink_cttimeout]
Clear the hook and wait for existing readers before unregistering the per-net operations. This blocks new policy lookups and ensures readers that observed the hook finish before the per-net storage is freed.
--- net/netfilter/nfnetlink_cttimeout.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nfnetlink_cttimeout.c +1 -1
@@ -659,9 +659,9 @@ static void __exit cttimeout_exit(void) {nfnetlink_subsys_unregister (&cttimeout_subsys); -unregister_pernet_subsys (&cttimeout_ops);RCU_INIT_POINTER (nf_ct_timeout_hook,NULL );synchronize_net (); +unregister_pernet_subsys (&cttimeout_ops); }module_init (cttimeout_init);
Greg Kroah-Hartman
maintainerPATCH 738/877 net: macb: Replace open-coded implementation with napi_schedule()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kevin Hao <[email protected]>
[ Upstream commit dc3bd465ea36af7fd6f9197c05353effc616145c ]
The driver currently duplicates the logic of napi_schedule() primarily to include additional debug information. However, these debug details are not essential for a specific driver and can be effectively obtained through existing tracepoints in the networking core, such as /sys/kernel/tracing/events/napi/napi_poll. Therefore, this patch replaces the open-coded implementation with napi_schedule() to simplify the driver's code.
Stable-dep-of: e1406330d70e ("net: macb: initialize PTP state before registering clock")
--- drivers/net/ethernet/cadence/macb_main.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-)
drivers/net/ethernet/cadence/macb_main.c +2 -8
@@ -2020,10 +2020,7 @@ static irqreturn_t macb_interrupt(int irif (bp->caps &MACB_CAPS_ISR_CLEAR_ON_WRITE )queue_writel (queue,ISR ,MACB_BIT (RCOMP )); -if (napi_schedule_prep (&queue->napi_rx)) { -netdev_vdbg (bp->dev,"scheduling RX softirq\n" ); -__napi_schedule (&queue->napi_rx); - } +napi_schedule (&queue->napi_rx); } if (status & (MACB_BIT(TCOMP) |
@@ -2038,10 +2035,7 @@ static irqreturn_t macb_interrupt(int irwmb ();// ensure softirq can see update } -if (napi_schedule_prep (&queue->napi_tx)) { -netdev_vdbg (bp->dev,"scheduling TX softirq\n" ); -__napi_schedule (&queue->napi_tx); - } +napi_schedule (&queue->napi_tx); }if (unlikely (status & (MACB_TX_ERR_FLAGS ))) {
Greg Kroah-Hartman
maintainerPATCH 739/877 net: macb: Use netif_napi_add_tx() instead of netif_napi_add() for TX NAPI
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kevin Hao <[email protected]>
[ Upstream commit c321b5676d0c41de9155c1966aa6af8b7ca35091 ]
The TX NAPI should be registered via netif_napi_add_tx() to avoid unnecessarily polluting the napi_hash table.
Stable-dep-of: e1406330d70e ("net: macb: initialize PTP state before registering clock")
--- drivers/net/ethernet/cadence/macb_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/cadence/macb_main.c +1 -1
@@ -4240,7 +4240,7 @@ static int macb_init(struct platform_dev queue->bp = bp;spin_lock_init (&queue->tx_ptr_lock);netif_napi_add (dev, &queue->napi_rx, macb_rx_poll); -netif_napi_add (dev, &queue->napi_tx, macb_tx_poll); +netif_napi_add_tx (dev, &queue->napi_tx, macb_tx_poll);if (hw_q) { queue->ISR =GEM_ISR (hw_q -1 ); queue->IER =GEM_IER (hw_q -1 );
Greg Kroah-Hartman
maintainerPATCH 740/877 net: macb: unify device pointer naming convention
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Théo Lebrun <[email protected]>
[ Upstream commit 07362f68e61d82ee53da0e9ae2c7f981c3538861 ]
Here are all device pointer variable permutations inside MACB:
struct device *dev;
struct net_device *dev;
struct net_device *ndev;
struct net_device *netdev;
struct pci_dev *pdev; // inside macb_pci.c
struct phy_device *phy;
struct phy_device *phydev;
struct platform_device *pdev;
struct platform_device *plat_dev; // inside macb_pci.c
Unify to this convention:
struct device *dev;
struct net_device *netdev;
struct pci_dev *pci;
struct phy_device *phydev;
struct platform_device *pdev;
Ensure nothing slipped through using ctags tooling:
⟩ ctags -o - --kinds-c='{local}{member}{parameter}' \
--fields='{typeref}' drivers/net/ethernet/cadence/* | \
awk -F"\t" '
$NF~/struct:.*(device|dev) / {print $NF, $1}' | \ sort -u
typeref:struct:device * dev
typeref:struct:in_device * idev // ignored
typeref:struct:net_device * netdev
typeref:struct:pci_dev * pci
typeref:struct:phy_device * phydev
typeref:struct:platform_device * pdev
Also fix some printk() calls to use __func__ instead of hardcoding. This silences some checkpatch.pl warnings and doesn't deserve a separate commit.
Backport note: retain only the dev-to-netdev rename in gem_ptp_init(). The target e1406330d70e ("net: macb: initialize PTP state before registering clock") needs this spelling in its ptp_clock_register() context; its macb_probe() hunk already applies to this stable tree. Drop the unrelated driver-wide renames and logging cleanup. In particular, do not import newer EEE, interrupt, DMA, queue, or probe changes absent from this branch. This limited rename changes no behavior and adds no functions.
[ sashal: Reduced backport -- upstream 07362f68e61d8 touches 4 file(s), this
backport carries 1. Not backported here:
drivers/net/ethernet/cadence/macb.h drivers/net/ethernet/cadence/macb_main.c drivers/net/ethernet/cadence/macb_pci.c
This note is generated from the file lists only; see the resolution record for the reasoning. ]
Stable-dep-of: e1406330d70e ("net: macb: initialize PTP state before registering clock")
--- drivers/net/ethernet/cadence/macb_ptp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/cadence/macb_ptp.c +3 -3
@@ -331,9 +331,9 @@ void gem_ptp_txstamp(struct macb *bp, stskb_tstamp_tx (skb, &shhwtstamps); } -void gem_ptp_init (struct net_device *dev) +void gem_ptp_init (struct net_device *netdev) { -struct macb *bp =netdev_priv (dev); +struct macb *bp =netdev_priv (netdev); bp->ptp_clock_info = gem_ptp_caps_template;
@@ -341,7 +341,7 @@ void gem_ptp_init(struct net_device *dev bp->tsu_rate = bp->ptp_info->get_tsu_rate (bp); bp->ptp_clock_info.max_adj = bp->ptp_info->get_ptp_max_adj ();gem_ptp_init_timer (bp); - bp->ptp_clock =ptp_clock_register (&bp->ptp_clock_info, &dev->dev); + bp->ptp_clock =ptp_clock_register (&bp->ptp_clock_info, &netdev->dev);if (IS_ERR (bp->ptp_clock)) {pr_err ("ptp clock register failed: %ld\n" ,PTR_ERR (bp->ptp_clock));
Greg Kroah-Hartman
maintainerPATCH 741/877 net: macb: initialize PTP state before registering clock
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
[ Upstream commit e1406330d70e56dd44fa6fbafc86e77e5c80c122 ]
gem_ptp_init() registers the PTP clock before initializing bp->tsu_clk_lock and the TSU hardware. Since ptp_clock_register() publishes the PTP character device, userspace may invoke PTP callbacks before the lock and hardware are ready.
In addition, gem_ptp_init() is called from both the interface open and resume paths. Reinitializing tsu_clk_lock there can reset the lock while timestamp processing is using it.
This race is theoretical and has not been observed in practice.
Initialize tsu_clk_lock once during probe and initialize the TSU before registering the PTP clock.
--- drivers/net/ethernet/cadence/macb_main.c | 1 + drivers/net/ethernet/cadence/macb_ptp.c | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-)
drivers/net/ethernet/cadence/macb_main.c +1 -0
@@ -5227,6 +5227,7 @@ static int macb_probe(struct platform_de }spin_lock_init (&bp->lock);spin_lock_init (&bp->stats_lock); +spin_lock_init (&bp->tsu_clk_lock);/* setup capabilities */ macb_configure_caps (bp, macb_config);
drivers/net/ethernet/cadence/macb_ptp.c +1 -4
@@ -341,6 +341,7 @@ void gem_ptp_init(struct net_device *net bp->tsu_rate = bp->ptp_info->get_tsu_rate (bp); bp->ptp_clock_info.max_adj = bp->ptp_info->get_ptp_max_adj ();gem_ptp_init_timer (bp); +gem_ptp_init_tsu (bp); bp->ptp_clock =ptp_clock_register (&bp->ptp_clock_info, &netdev->dev);if (IS_ERR (bp->ptp_clock)) { pr_err("ptp clock register failed: %ld\n",
@@ -352,10 +353,6 @@ void gem_ptp_init(struct net_device *netreturn ; } -spin_lock_init (&bp->tsu_clk_lock); - -gem_ptp_init_tsu (bp); -dev_info (&bp->pdev->dev,"%s ptp clock registered.\n" ,GEM_PTP_TIMER_NAME ); }
Greg Kroah-Hartman
maintainerPATCH 742/877 erofs: add sysfs feature entry for xattr prefixes
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jingbo Xu <[email protected]>
[ Upstream commit 839f075aabdf5c21048f9801b87c0b841dd3d064 ]
Let /sys/fs/erofs/features/xattr_prefixes advertise that this kernel supports the EROFS_FEATURE_INCOMPAT_XATTR_PREFIXES on-disk format.
--- Documentation/ABI/testing/sysfs-fs-erofs | 2 +- fs/erofs/sysfs.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
Documentation/ABI/testing/sysfs-fs-erofs +1 -1
@@ -5,7 +5,7 @@ Description: Shows all enabled kernel fe Supported features: zero_padding, compr_cfgs, big_pcluster, chunked_file, device_table, compr_head2, sb_chksum, ztailpacking, - dedupe, fragments. + dedupe, fragments, xattr_prefixes. What: /sys/fs/erofs/<disk>/sync_decompress Date: November 2021
fs/erofs/sysfs.c +2 -0
@@ -81,6 +81,7 @@ EROFS_ATTR_FEATURE(sb_chksum);EROFS_ATTR_FEATURE (ztailpacking);EROFS_ATTR_FEATURE (fragments);EROFS_ATTR_FEATURE (dedupe); +EROFS_ATTR_FEATURE (xattr_prefixes);static struct attribute *erofs_feat_attrs[] = {ATTR_LIST (zero_padding),
@@ -93,6 +94,7 @@ static struct attribute *erofs_feat_attrATTR_LIST (ztailpacking),ATTR_LIST (fragments),ATTR_LIST (dedupe), +ATTR_LIST (xattr_prefixes),NULL , };ATTRIBUTE_GROUPS (erofs_feat);
Greg Kroah-Hartman
maintainerPATCH 743/877 idpf: Fix kernel-doc descriptions to avoid warnings
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andy Shevchenko <[email protected]>
[ Upstream commit 7fe9c81aa24a2374b1a9a2160d44f4afbf8ab80d ]
In many functions the Return section is missing. Fix kernel-doc descriptions to address that and other warnings.
Before the change:
$ scripts/kernel-doc -none -Wreturn drivers/net/ethernet/intel/idpf/idpf_txrx.c 2>&1 | wc -l 85
Stable-dep-of: 7dd4c829bac2 ("idpf: disable DIM work before freeing q_vectors")
--- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 94 +++++++++++++++++----------- 1 file changed, 58 insertions(+), 36 deletions(-)
drivers/net/ethernet/intel/idpf/idpf_txrx.c +58 -36
@@ -19,6 +19,8 @@ LIBETH_SQE_CHECK_PRIV(u32);* Make sure we don't exceed maximum scatter gather buffers for a single * packet. * TSO case has been handled earlier from idpf_features_check(). +* +* Return: %true if skb exceeds max descriptors per packet, %false otherwise. */ static bool idpf_chk_linearize(const struct sk_buff *skb, unsigned int max_bufs,
@@ -148,7 +150,7 @@ static void idpf_tx_desc_rel_all(struct* idpf_tx_buf_alloc_all - Allocate memory for all buffer resources * @tx_q: queue for which the buffers are allocated * -* Returns 0 on success, negative on failure +* Return: 0 on success, negative on failure */ static int idpf_tx_buf_alloc_all (struct idpf_tx_queue *tx_q) {
@@ -172,7 +174,7 @@ static int idpf_tx_buf_alloc_all(struct* @vport: vport to allocate resources for * @tx_q: the tx ring to set up * -* Returns 0 on success, negative on failure +* Return: 0 on success, negative on failure */ static int idpf_tx_desc_alloc (const struct idpf_vport *vport,struct idpf_tx_queue *tx_q)
@@ -264,7 +266,7 @@ static int idpf_compl_desc_alloc(const s* idpf_tx_desc_alloc_all - allocate all queues Tx resources * @vport: virtual port private structure * -* Returns 0 on success, negative on failure +* Return: 0 on success, negative on failure */ static int idpf_tx_desc_alloc_all (struct idpf_vport *vport) {
@@ -509,7 +511,7 @@ static void idpf_rx_buf_hw_update(struct* idpf_rx_hdr_buf_alloc_all - Allocate memory for header buffers * @bufq: ring to use * -* Returns 0 on success, negative on failure. +* Return: 0 on success, negative on failure. */ static int idpf_rx_hdr_buf_alloc_all (struct idpf_buf_queue *bufq) {
@@ -560,7 +562,7 @@ static void idpf_post_buf_refill(struct* @bufq: buffer queue to post to * @buf_id: buffer id to post * -* Returns false if buffer could not be allocated, true otherwise. +* Return: %false if buffer could not be allocated, %true otherwise. */ static bool idpf_rx_post_buf_desc (struct idpf_buf_queue *bufq,u16 buf_id) {
@@ -609,7 +611,7 @@ static bool idpf_rx_post_buf_desc(struct* @bufq: buffer queue to post working set to * @working_set: number of buffers to put in working set * -* Returns true if @working_set bufs were posted successfully, false otherwise. +* Return: %true if @working_set bufs were posted successfully, %false otherwise. */ static bool idpf_rx_post_init_bufs (struct idpf_buf_queue *bufq,u16 working_set)
@@ -678,7 +680,7 @@ static int idpf_rx_bufs_init_singleq(str* idpf_rx_buf_alloc_all - Allocate memory for all buffer resources * @rxbufq: queue for which the buffers are allocated * -* Returns 0 on success, negative on failure +* Return: 0 on success, negative on failure */ static int idpf_rx_buf_alloc_all (struct idpf_buf_queue *rxbufq) {
@@ -706,7 +708,7 @@ rx_buf_alloc_all_out:* @bufq: buffer queue to create page pool for * @type: type of Rx buffers to allocate * -* Returns 0 on success, negative on failure +* Return: 0 on success, negative on failure */ static int idpf_rx_bufs_init (struct idpf_buf_queue *bufq,enum libeth_fqe_type type)
@@ -737,7 +739,7 @@ static int idpf_rx_bufs_init(struct idpf* idpf_rx_bufs_init_all - Initialize all RX bufs * @vport: virtual port struct * -* Returns 0 on success, negative on failure +* Return: 0 on success, negative on failure */ int idpf_rx_bufs_init_all (struct idpf_vport *vport) {
@@ -790,7 +792,7 @@ int idpf_rx_bufs_init_all(struct idpf_vp* @vport: vport to allocate resources for * @rxq: Rx queue for which the resources are setup * -* Returns 0 on success, negative on failure +* Return: 0 on success, negative on failure */ static int idpf_rx_desc_alloc (const struct idpf_vport *vport,struct idpf_rx_queue *rxq)
@@ -849,7 +851,7 @@ static int idpf_bufq_desc_alloc(const st* idpf_rx_desc_alloc_all - allocate all RX queues resources * @vport: virtual port structure * -* Returns 0 on success, negative on failure +* Return: 0 on success, negative on failure */ static int idpf_rx_desc_alloc_all (struct idpf_vport *vport) {
@@ -1038,7 +1040,7 @@ void idpf_vport_queues_rel(struct idpf_v* dereference the queue from queue groups. This allows us to quickly pull a * txq based on a queue index. * -* Returns 0 on success, negative on failure +* Return: 0 on success, negative on failure */ static int idpf_vport_init_fast_path_txqs (struct idpf_vport *vport) {
@@ -1151,7 +1153,7 @@ void idpf_vport_calc_num_q_desc(struct i* @vport_msg: message to fill with data * @max_q: vport max queue info * -* Return 0 on success, error value on failure. +* Return: 0 on success, error value on failure. */ int idpf_vport_calc_total_qs(struct idpf_adapter *adapter, u16 vport_idx, struct virtchnl2_create_vport *vport_msg,
@@ -1274,7 +1276,7 @@ static void idpf_rxq_set_descids(const s* @vport: vport to allocate txq groups for * @num_txq: number of txqs to allocate for each group * -* Returns 0 on success, negative on failure +* Return: 0 on success, negative on failure */ static int idpf_txq_group_alloc (struct idpf_vport *vport,u16 num_txq) {
@@ -1365,7 +1367,7 @@ err_alloc:* @vport: vport to allocate rxq groups for * @num_rxq: number of rxqs to allocate for each group * -* Returns 0 on success, negative on failure +* Return: 0 on success, negative on failure */ static int idpf_rxq_group_alloc (struct idpf_vport *vport,u16 num_rxq) {
@@ -1495,7 +1497,7 @@ err_alloc:* idpf_vport_queue_grp_alloc_all - Allocate all queue groups/resources * @vport: vport with qgrps to allocate * -* Returns 0 on success, negative on failure +* Return: 0 on success, negative on failure */ static int idpf_vport_queue_grp_alloc_all (struct idpf_vport *vport) {
@@ -1524,8 +1526,9 @@ err_out:* idpf_vport_queues_alloc - Allocate memory for all queues * @vport: virtual port * -* Allocate memory for queues associated with a vport. Returns 0 on success, -* negative on failure. +* Allocate memory for queues associated with a vport. +* +* Return: 0 on success, negative on failure. */ int idpf_vport_queues_alloc (struct idpf_vport *vport) {
@@ -1737,7 +1740,7 @@ static void idpf_tx_handle_rs_completion* @budget: Used to determine if we are in netpoll * @cleaned: returns number of packets cleaned * -* Returns true if there's any budget left (e.g. the clean is finished) +* Return: %true if there's any budget left (e.g. the clean is finished) */ static bool idpf_tx_clean_complq (struct idpf_compl_queue *complq,int budget,int *cleaned)
@@ -1903,7 +1906,7 @@ void idpf_tx_splitq_build_flow_desc(unio }/** -* idpf_tx_splitq_has_room - check if enough Tx splitq resources are available +* idpf_txq_has_room - check if enough Tx splitq resources are available * @tx_q: the queue to be checked * @descs_needed: number of descriptors required for this packet * @bufs_needed: number of Tx buffers required for this packet
@@ -2034,6 +2037,8 @@ unsigned int idpf_tx_res_count_required(* idpf_tx_splitq_bump_ntu - adjust NTU and generation * @txq: the tx ring to wrap * @ntu: ring index to bump +* +* Return: the next ring index hopping to 0 when wraps around */ static unsigned int idpf_tx_splitq_bump_ntu (struct idpf_tx_queue *txq,u16 ntu) {
@@ -2302,7 +2307,7 @@ static void idpf_tx_splitq_map(struct id* @skb: pointer to skb * @off: pointer to struct that holds offload parameters * -* Returns error (negative) if TSO was requested but cannot be applied to the +* Return: error (negative) if TSO was requested but cannot be applied to the * given skb, 0 if TSO does not apply to the given skb, or 1 otherwise. */ int idpf_tso (struct sk_buff *skb,struct idpf_tx_offload_params *off)
@@ -2380,6 +2385,8 @@ int idpf_tso(struct sk_buff *skb, struct* * Since the TX buffer rings mimics the descriptor ring, update the tx buffer * ring entry to reflect that this index is a context descriptor +* +* Return: pointer to the next descriptor */ static struct idpf_flex_tx_ctx_desc *idpf_tx_splitq_get_ctx_desc (struct idpf_tx_queue *txq)
@@ -2398,6 +2405,8 @@ idpf_tx_splitq_get_ctx_desc(struct idpf_* idpf_tx_drop_skb - free the SKB and bump tail if necessary * @tx_q: queue to send buffer on * @skb: pointer to skb +* +* Return: always NETDEV_TX_OK */ netdev_tx_t idpf_tx_drop_skb (struct idpf_tx_queue *tx_q,struct sk_buff *skb) {
@@ -2432,7 +2441,7 @@ static bool idpf_tx_splitq_need_re(struc* @skb: send buffer * @tx_q: queue to send buffer on * -* Returns NETDEV_TX_OK if sent, else an error code +* Return: NETDEV_TX_OK if sent, else an error code */ static netdev_tx_t idpf_tx_splitq_frame (struct sk_buff *skb,struct idpf_tx_queue *tx_q)
@@ -2549,7 +2558,7 @@ static netdev_tx_t idpf_tx_splitq_frame(* @skb: send buffer * @netdev: network interface device structure * -* Returns NETDEV_TX_OK if sent, else an error code +* Return: NETDEV_TX_OK if sent, else an error code */ netdev_tx_t idpf_tx_start (struct sk_buff *skb,struct net_device *netdev) {
@@ -2698,10 +2707,10 @@ idpf_rx_splitq_extract_csum_bits(const s* @rx_desc: Receive descriptor * @decoded: Decoded Rx packet type related fields * -* Return 0 on success and error code on failure -* * Populate the skb fields with the total number of RSC segments, RSC payload * length and packet type. +* +* Return: 0 on success and error code on failure */ static int idpf_rx_rsc(struct idpf_rx_queue *rxq, struct sk_buff *skb, const struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc,
@@ -2776,6 +2785,8 @@ static int idpf_rx_rsc(struct idpf_rx_qu* This function checks the ring, descriptor, and packet information in * order to populate the hash, checksum, protocol, and * other fields within the skb. +* +* Return: 0 on success and error code on failure */ static int idpf_rx_process_skb_fields(struct idpf_rx_queue *rxq, struct sk_buff *skb,
@@ -2894,6 +2905,7 @@ struct sk_buff *idpf_rx_build_skb(const* @stat_err_field: field from descriptor to test bits in * @stat_err_bits: value to mask * +* Return: %true if any of given @stat_err_bits are set, %false otherwise. */ static bool idpf_rx_splitq_test_staterr (const u8 stat_err_field,const u8 stat_err_bits)
@@ -2905,8 +2917,8 @@ static bool idpf_rx_splitq_test_staterr(* idpf_rx_splitq_is_eop - process handling of EOP buffers * @rx_desc: Rx descriptor for current buffer * -* If the buffer is an EOP buffer, this function exits returning true, -* otherwise return false indicating that this is in fact a non-EOP buffer. +* Return: %true if the buffer is an EOP buffer, %false otherwise, indicating +* that this is in fact a non-EOP buffer. */ static bool idpf_rx_splitq_is_eop (struct virtchnl2_rx_flex_desc_adv_nic_3 *rx_desc) {
@@ -2925,7 +2937,7 @@ static bool idpf_rx_splitq_is_eop(struct* expensive overhead for IOMMU access this provides a means of avoiding * it by maintaining the mapping of the page to the system. * -* Returns amount of work completed +* Return: amount of work completed */ static int idpf_rx_splitq_clean (struct idpf_rx_queue *rxq,int budget) {
@@ -3087,7 +3099,7 @@ skip_data:* @buf_id: buffer ID * @buf_desc: Buffer queue descriptor * -* Return 0 on success and negative on failure. +* Return: 0 on success and negative on failure. */ static int idpf_rx_update_bufq_desc (struct idpf_buf_queue *bufq,u32 buf_id,struct virtchnl2_splitq_rx_buf_desc *buf_desc)
@@ -3214,6 +3226,7 @@ static void idpf_rx_clean_refillq_all(st* @irq: interrupt number * @data: pointer to a q_vector * +* Return: always IRQ_HANDLED */ static irqreturn_t idpf_vport_intr_clean_queues (int __always_unused irq,void *data)
@@ -3320,6 +3333,8 @@ static void idpf_vport_intr_dis_irq_all(/** * idpf_vport_intr_buildreg_itr - Enable default interrupt generation settings * @q_vector: pointer to q_vector +* +* Return: value to be written back to HW to enable interrupt generation */ static u32 idpf_vport_intr_buildreg_itr (struct idpf_q_vector *q_vector) {
@@ -3451,6 +3466,8 @@ void idpf_vport_intr_update_itr_ena_irq(/** * idpf_vport_intr_req_irq - get MSI-X vectors from the OS for the vport * @vport: main vport structure +* +* Return: 0 on success, negative on failure */ static int idpf_vport_intr_req_irq (struct idpf_vport *vport) {
@@ -3659,7 +3676,7 @@ static void idpf_vport_intr_napi_ena_all* @budget: Used to determine if we are in netpoll * @cleaned: returns number of packets cleaned * -* Returns false if clean is not complete else returns true +* Return: %false if clean is not complete else returns %true */ static bool idpf_tx_splitq_clean_all (struct idpf_q_vector *q_vec,int budget,int *cleaned)
@@ -3686,7 +3703,7 @@ static bool idpf_tx_splitq_clean_all(str* @budget: Used to determine if we are in netpoll * @cleaned: returns number of packets cleaned * -* Returns false if clean is not complete else returns true +* Return: %false if clean is not complete else returns %true */ static bool idpf_rx_splitq_clean_all (struct idpf_q_vector *q_vec,int budget,int *cleaned)
@@ -3725,6 +3742,8 @@ static bool idpf_rx_splitq_clean_all(str* idpf_vport_splitq_napi_poll - NAPI handler * @napi: struct from which you get q_vector * @budget: budget provided by stack +* +* Return: how many packets were cleaned */ static int idpf_vport_splitq_napi_poll (struct napi_struct *napi,int budget) {
@@ -3861,7 +3880,9 @@ static void idpf_vport_intr_map_vector_t* idpf_vport_intr_init_vec_idx - Initialize the vector indexes * @vport: virtual port * -* Initialize vector indexes with values returened over mailbox +* Initialize vector indexes with values returned over mailbox. +* +* Return: 0 on success, negative on failure */ static int idpf_vport_intr_init_vec_idx (struct idpf_vport *vport) {
@@ -3922,8 +3943,9 @@ static void idpf_vport_intr_napi_add_all* idpf_vport_intr_alloc - Allocate memory for interrupt vectors * @vport: virtual port * -* We allocate one q_vector per queue interrupt. If allocation fails we -* return -ENOMEM. +* Allocate one q_vector per queue interrupt. +* +* Return: 0 on success, if allocation fails we return -ENOMEM. */ int idpf_vport_intr_alloc (struct idpf_vport *vport) {
@@ -4004,7 +4026,7 @@ error:* idpf_vport_intr_init - Setup all vectors for the given vport * @vport: virtual port * -* Returns 0 on success or negative on failure +* Return: 0 on success or negative on failure */ int idpf_vport_intr_init (struct idpf_vport *vport) {
@@ -4043,7 +4065,7 @@ void idpf_vport_intr_ena(struct idpf_vpo* idpf_config_rss - Send virtchnl messages to configure RSS * @vport: virtual port * -* Return 0 on success, negative on failure +* Return: 0 on success, negative on failure */ int idpf_config_rss (struct idpf_vport *vport) {
Greg Kroah-Hartman
maintainerPATCH 744/877 idpf: introduce idpf_q_vec_rsrc struct and move vector resources to it
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pavan Kumar Linga <[email protected]>
[ Upstream commit d1061502f353d5e1a8937181b84b722e75fabf11 ]
To group all the vector and queue resources, introduce idpf_q_vec_rsrc structure. This helps to reuse the same config path functions by other features. For example, PTP implementation can use the existing config infrastructure to configure secondary mailbox by passing its queue and vector info. It also helps to avoid any duplication of code.
Existing queue and vector resources are grouped as default resources. This patch moves vector info to the newly introduced structure. Following patch moves the queue resources.
While at it, declare the loop iterator for 'num_q_vectors' in loop and use the correct type.
Include idpf_q_vec_rsrc backpointer in idpf_alloc_queue_set along with vport.
[Backport to 6.12: retain the vector-resource grouping and convert the existing PF/VF register, interrupt, vport lifecycle and vector-allocation paths. Also convert the stable-only NAPI scheduling in idpf_send_disable_queues_msg().
Drop changes to the unavailable queue-set, AF_XDP and NOIRQ support; retain the stable queue/vector counts, mailbox interface and vport state handling. Keep the resource member at the original vector fields' location. No functions are added. This prepares the existing interrupt lifecycle for 7dd4c829bac2 ("idpf: disable DIM work before freeing q_vectors").]
Stable-dep-of: 7dd4c829bac2 ("idpf: disable DIM work before freeing q_vectors")
--- drivers/net/ethernet/intel/idpf/idpf.h | 24 ++- drivers/net/ethernet/intel/idpf/idpf_dev.c | 10 - drivers/net/ethernet/intel/idpf/idpf_lib.c | 35 ++-- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 183 ++++++++++++------------ drivers/net/ethernet/intel/idpf/idpf_txrx.h | 14 + drivers/net/ethernet/intel/idpf/idpf_vf_dev.c | 10 - drivers/net/ethernet/intel/idpf/idpf_virtchnl.c | 20 +- drivers/net/ethernet/intel/idpf/idpf_virtchnl.h | 3 8 files changed, 167 insertions(+), 132 deletions(-)
drivers/net/ethernet/intel/idpf/idpf.h +17 -7
@@ -8,6 +8,7 @@struct idpf_adapter ;struct idpf_vport ;struct idpf_vport_max_q ; +struct idpf_q_vec_rsrc ;#include <net/pkt_sched.h> #include <linux/aer.h>
@@ -196,7 +197,8 @@ struct idpf_vport_max_q {*/ struct idpf_reg_ops {void (*ctlq_reg_init)(struct idpf_ctlq_create_info *cq); -int (*intr_reg_init)(struct idpf_vport *vport); +int (*intr_reg_init)(struct idpf_vport *vport, +struct idpf_q_vec_rsrc *rsrc);void (*mb_intr_reg_init)(struct idpf_adapter *adapter);void (*reset_reg_init)(struct idpf_adapter *adapter); void (*trigger_reset)(struct idpf_adapter *adapter,
@@ -252,6 +254,18 @@ struct idpf_port_stats { };/** +* struct idpf_q_vec_rsrc - handle for queue and vector resources +* @q_vectors: array of queue vectors +* @q_vector_idxs: starting index of queue vectors +* @num_q_vectors: number of IRQ vectors allocated +*/ +struct idpf_q_vec_rsrc { +struct idpf_q_vector *q_vectors; +u16 *q_vector_idxs; +u16 num_q_vectors; +}; + +/** * struct idpf_vport - Handle for netdevices and queue resources * @num_txq: Number of allocated TX queues * @num_complq: Number of allocated completion queues
@@ -284,9 +298,7 @@ struct idpf_port_stats {* @idx: Software index in adapter vports struct * @default_vport: Use this vport if one isn't specified * @base_rxd: True if the driver should use base descriptors instead of flex -* @num_q_vectors: Number of IRQ vectors allocated -* @q_vectors: Array of queue vectors -* @q_vector_idxs: Starting index of queue vectors +* @dflt_qv_rsrc: contains default queue and vector resources * @max_mtu: device given max possible MTU * @default_mac_addr: device will give a default MAC to use * @rx_itr_profile: RX profiles for Dynamic Interrupt Moderation
@@ -326,9 +338,7 @@ struct idpf_vport {bool default_vport;bool base_rxd; -u16 num_q_vectors; -struct idpf_q_vector *q_vectors; -u16 *q_vector_idxs; +struct idpf_q_vec_rsrc dflt_qv_rsrc;u16 max_mtu;u8 default_mac_addr[ETH_ALEN ];u16 rx_itr_profile[IDPF_DIM_PROFILE_SLOTS ];
drivers/net/ethernet/intel/idpf/idpf_dev.c +6 -4
@@ -66,11 +66,13 @@ static void idpf_mb_intr_reg_init(struct/** * idpf_intr_reg_init - Initialize interrupt registers * @vport: virtual port structure +* @rsrc: pointer to queue and vector resources */ -static int idpf_intr_reg_init (struct idpf_vport *vport) +static int idpf_intr_reg_init (struct idpf_vport *vport, +struct idpf_q_vec_rsrc *rsrc) {struct idpf_adapter *adapter = vport->adapter; -int num_vecs = vport->num_q_vectors; +u16 num_vecs = rsrc->num_q_vectors;struct idpf_vec_regs *reg_vals;int num_regs, i, err =0 ;u32 rx_itr, tx_itr;
@@ -89,8 +91,8 @@ static int idpf_intr_reg_init(struct idp }for (i =0 ; i < num_vecs; i++) { -struct idpf_q_vector *q_vector = &vport->q_vectors[i]; -u16 vec_id = vport->q_vector_idxs[i] -IDPF_MBX_Q_VEC ; +struct idpf_q_vector *q_vector = &rsrc->q_vectors[i]; +u16 vec_id = rsrc->q_vector_idxs[i] -IDPF_MBX_Q_VEC ;struct idpf_intr_reg *intr = &q_vector->intr_reg;u32 spacing;
drivers/net/ethernet/intel/idpf/idpf_lib.c +20 -15
@@ -908,6 +908,7 @@ static void idpf_remove_features(structstatic void idpf_vport_stop (struct idpf_vport *vport) {struct idpf_netdev_priv *np =netdev_priv (vport->netdev); +struct idpf_q_vec_rsrc *rsrc = &vport->dflt_qv_rsrc;if (np->state <= __IDPF_VPORT_DOWN)return ;
@@ -929,9 +930,9 @@ static void idpf_vport_stop(struct idpf_idpf_remove_features (vport); vport->link_up = false; -idpf_vport_intr_deinit (vport); +idpf_vport_intr_deinit (vport, rsrc);idpf_vport_queues_rel (vport); -idpf_vport_intr_rel (vport); +idpf_vport_intr_rel (rsrc); np->state = __IDPF_VPORT_DOWN; }
@@ -991,6 +992,7 @@ static void idpf_decfg_netdev(struct idp*/ static void idpf_vport_rel (struct idpf_vport *vport) { +struct idpf_q_vec_rsrc *rsrc = &vport->dflt_qv_rsrc;struct idpf_adapter *adapter = vport->adapter;struct idpf_vport_config *vport_config;struct idpf_vector_info vec_info;
@@ -1015,13 +1017,13 @@ static void idpf_vport_rel(struct idpf_v/* Release all the allocated vectors on the stack */ vec_info.num_req_vecs =0 ; - vec_info.num_curr_vecs = vport->num_q_vectors; + vec_info.num_curr_vecs = rsrc->num_q_vectors; vec_info.default_vport = vport->default_vport; -idpf_req_rel_vector_indexes (adapter, vport->q_vector_idxs, &vec_info); +idpf_req_rel_vector_indexes (adapter, rsrc->q_vector_idxs, &vec_info); -kfree (vport->q_vector_idxs); - vport->q_vector_idxs =NULL ; +kfree (rsrc->q_vector_idxs); + rsrc->q_vector_idxs =NULL ;kfree (adapter->vport_params_recvd[idx]); adapter->vport_params_recvd[idx] =NULL ;
@@ -1146,6 +1148,7 @@ static struct idpf_vport *idpf_vport_all {struct idpf_rss_data *rss_data;u16 idx = adapter->next_vport; +struct idpf_q_vec_rsrc *rsrc;struct idpf_vport *vport;u16 num_max_q;int err;
@@ -1193,8 +1196,9 @@ static struct idpf_vport *idpf_vport_all vport->default_vport = adapter->num_alloc_vports <idpf_get_default_vports (adapter); - vport->q_vector_idxs =kcalloc (num_max_q,sizeof (u16),GFP_KERNEL ); -if (!vport->q_vector_idxs) + rsrc = &vport->dflt_qv_rsrc; + rsrc->q_vector_idxs =kcalloc (num_max_q,sizeof (u16),GFP_KERNEL ); +if (!rsrc->q_vector_idxs) goto free_vport;idpf_vport_init (vport, max_q);
@@ -1232,7 +1236,7 @@ free_rss_key:kfree (rss_data->rss_key); rss_data->rss_key =NULL ; free_vector_idxs: -kfree (vport->q_vector_idxs); +kfree (rsrc->q_vector_idxs); free_vport:kfree (vport);
@@ -1405,6 +1409,7 @@ static void idpf_rx_init_buf_tail(structstatic int idpf_vport_open (struct idpf_vport *vport) {struct idpf_netdev_priv *np =netdev_priv (vport->netdev); +struct idpf_q_vec_rsrc *rsrc = &vport->dflt_qv_rsrc;struct idpf_adapter *adapter = vport->adapter;int err;
@@ -1414,7 +1419,7 @@ static int idpf_vport_open(struct idpf_v/* we do not allow interface up just yet */ netif_carrier_off (vport->netdev); - err =idpf_vport_intr_alloc (vport); + err =idpf_vport_intr_alloc (vport, rsrc);if (err) {dev_err (&adapter->pdev->dev,"Failed to allocate interrupts for vport %u: %d\n" , vport->vport_id, err);
@@ -1432,7 +1437,7 @@ static int idpf_vport_open(struct idpf_v goto queues_rel; } - err =idpf_vport_intr_init (vport); + err =idpf_vport_intr_init (vport, rsrc);if (err) {dev_err (&adapter->pdev->dev,"Failed to initialize interrupts for vport %u: %d\n" , vport->vport_id, err);
@@ -1454,7 +1459,7 @@ static int idpf_vport_open(struct idpf_v }idpf_rx_init_buf_tail (vport); -idpf_vport_intr_ena (vport); +idpf_vport_intr_ena (vport, rsrc); err =idpf_send_config_queues_msg (vport);if (err) {
@@ -1510,11 +1515,11 @@ disable_queues: unmap_queue_vectors:idpf_send_map_unmap_queue_vector_msg (vport, false); intr_deinit: -idpf_vport_intr_deinit (vport); +idpf_vport_intr_deinit (vport, rsrc); queues_rel:idpf_vport_queues_rel (vport); intr_rel: -idpf_vport_intr_rel (vport); +idpf_vport_intr_rel (rsrc);return err; }
@@ -1958,7 +1963,7 @@ int idpf_initiate_soft_reset(struct idpfmemcpy (vport, new_vport, offsetof(struct idpf_vport , link_up));if (reset_cause ==IDPF_SR_Q_CHANGE ) -idpf_vport_alloc_vec_indexes (vport); +idpf_vport_alloc_vec_indexes (vport, &vport->dflt_qv_rsrc); err =idpf_set_real_num_queues (vport);if (err)
drivers/net/ethernet/intel/idpf/idpf_txrx.c +95 -88
432 lines not on this page · raw message
drivers/net/ethernet/intel/idpf/idpf_txrx.h +9 -5
@@ -1011,12 +1011,16 @@ int idpf_vport_calc_total_qs(struct idpfvoid idpf_vport_calc_num_q_groups (struct idpf_vport *vport);int idpf_vport_queues_alloc (struct idpf_vport *vport);void idpf_vport_queues_rel (struct idpf_vport *vport); -void idpf_vport_intr_rel (struct idpf_vport *vport); -int idpf_vport_intr_alloc (struct idpf_vport *vport); +void idpf_vport_intr_rel (struct idpf_q_vec_rsrc *rsrc); +int idpf_vport_intr_alloc (struct idpf_vport *vport, +struct idpf_q_vec_rsrc *rsrc);void idpf_vport_intr_update_itr_ena_irq (struct idpf_q_vector *q_vector); -void idpf_vport_intr_deinit (struct idpf_vport *vport); -int idpf_vport_intr_init (struct idpf_vport *vport); -void idpf_vport_intr_ena (struct idpf_vport *vport); +void idpf_vport_intr_deinit (struct idpf_vport *vport, +struct idpf_q_vec_rsrc *rsrc); +int idpf_vport_intr_init (struct idpf_vport *vport, +struct idpf_q_vec_rsrc *rsrc); +void idpf_vport_intr_ena (struct idpf_vport *vport, +struct idpf_q_vec_rsrc *rsrc);void idpf_fill_dflt_rss_lut (struct idpf_vport *vport);int idpf_config_rss (struct idpf_vport *vport);int idpf_init_rss_lut (struct idpf_vport *vport);
drivers/net/ethernet/intel/idpf/idpf_vf_dev.c +6 -4
@@ -66,11 +66,13 @@ static void idpf_vf_mb_intr_reg_init(str/** * idpf_vf_intr_reg_init - Initialize interrupt registers * @vport: virtual port structure +* @rsrc: pointer to queue and vector resources */ -static int idpf_vf_intr_reg_init (struct idpf_vport *vport) +static int idpf_vf_intr_reg_init (struct idpf_vport *vport, +struct idpf_q_vec_rsrc *rsrc) {struct idpf_adapter *adapter = vport->adapter; -int num_vecs = vport->num_q_vectors; +u16 num_vecs = rsrc->num_q_vectors;struct idpf_vec_regs *reg_vals;int num_regs, i, err =0 ;u32 rx_itr, tx_itr;
@@ -89,8 +91,8 @@ static int idpf_vf_intr_reg_init(struct }for (i =0 ; i < num_vecs; i++) { -struct idpf_q_vector *q_vector = &vport->q_vectors[i]; -u16 vec_id = vport->q_vector_idxs[i] -IDPF_MBX_Q_VEC ; +struct idpf_q_vector *q_vector = &rsrc->q_vectors[i]; +u16 vec_id = rsrc->q_vector_idxs[i] -IDPF_MBX_Q_VEC ;struct idpf_intr_reg *intr = &q_vector->intr_reg;u32 spacing;
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c +12 -8
@@ -1993,6 +1993,7 @@ int idpf_send_enable_queues_msg(struct i*/ int idpf_send_disable_queues_msg (struct idpf_vport *vport) { +struct idpf_q_vec_rsrc *rsrc = &vport->dflt_qv_rsrc;int err, i; err =idpf_send_ena_dis_queues_msg (vport, false);
@@ -2007,8 +2008,8 @@ int idpf_send_disable_queues_msg(struct/* schedule the napi to receive all the marker packets */ local_bh_disable (); -for (i =0 ; i < vport->num_q_vectors; i++) -napi_schedule (&vport->q_vectors[i].napi); +for (u16 i =0 ; i < rsrc->num_q_vectors; i++) +napi_schedule (&rsrc->q_vectors[i].napi);local_bh_enable ();return idpf_wait_for_marker_event (vport);
@@ -3118,25 +3119,27 @@ void idpf_vc_core_deinit(struct idpf_ada/** * idpf_vport_alloc_vec_indexes - Get relative vector indexes * @vport: virtual port data struct +* @rsrc: pointer to queue and vector resources * * This function requests the vector information required for the vport and * stores the vector indexes received from the 'global vector distribution' * in the vport's queue vectors array. * -* Return 0 on success, error on failure +* Return: 0 on success, error on failure */ -int idpf_vport_alloc_vec_indexes (struct idpf_vport *vport) +int idpf_vport_alloc_vec_indexes (struct idpf_vport *vport, +struct idpf_q_vec_rsrc *rsrc) {struct idpf_vector_info vec_info;int num_alloc_vecs; - vec_info.num_curr_vecs = vport->num_q_vectors; + vec_info.num_curr_vecs = rsrc->num_q_vectors; vec_info.num_req_vecs =max (vport->num_txq, vport->num_rxq); vec_info.default_vport = vport->default_vport; vec_info.index = vport->idx; num_alloc_vecs =idpf_req_rel_vector_indexes (vport->adapter, - vport->q_vector_idxs, + rsrc->q_vector_idxs, &vec_info);if (num_alloc_vecs <=0 ) { dev_err(&vport->adapter->pdev->dev, "Vector distribution failed: %d\n",
@@ -3144,7 +3147,7 @@ int idpf_vport_alloc_vec_indexes(structreturn -EINVAL ; } - vport->num_q_vectors = num_alloc_vecs; + rsrc->num_q_vectors = num_alloc_vecs;return 0 ; }
@@ -3158,6 +3161,7 @@ int idpf_vport_alloc_vec_indexes(struct*/ void idpf_vport_init (struct idpf_vport *vport,struct idpf_vport_max_q *max_q) { +struct idpf_q_vec_rsrc *rsrc = &vport->dflt_qv_rsrc;struct idpf_adapter *adapter = vport->adapter;struct virtchnl2_create_vport *vport_msg;struct idpf_vport_config *vport_config;
@@ -3196,7 +3200,7 @@ void idpf_vport_init(struct idpf_vport *idpf_vport_init_num_qs (vport, vport_msg);idpf_vport_calc_num_q_desc (vport);idpf_vport_calc_num_q_groups (vport); -idpf_vport_alloc_vec_indexes (vport); +idpf_vport_alloc_vec_indexes (vport, rsrc); vport->crc_enable = adapter->crc_enable; }
drivers/net/ethernet/intel/idpf/idpf_virtchnl.h +2 -1
@@ -45,7 +45,8 @@ int idpf_send_enable_queues_msg(struct iint idpf_send_disable_queues_msg (struct idpf_vport *vport);int idpf_send_config_queues_msg (struct idpf_vport *vport); -int idpf_vport_alloc_vec_indexes (struct idpf_vport *vport); +int idpf_vport_alloc_vec_indexes (struct idpf_vport *vport, +struct idpf_q_vec_rsrc *rsrc);int idpf_get_vec_ids (struct idpf_adapter *adapter,u16 *vecids,int num_vecids,struct virtchnl2_vector_chunks *chunks);
Greg Kroah-Hartman
maintainerPATCH 745/877 idpf: disable DIM work before freeing q_vectors
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
[ Upstream commit 7dd4c829bac2916be98a3e34b41daaba7f42b4c4 ]
idpf never drains the Tx/Rx DIM works before freeing the memory they live in. tx_dim and rx_dim are embedded in struct idpf_q_vector, they are queued from the NAPI poll via net_dim(), and idpf_vport_intr_rel() ends with kfree(rsrc->q_vectors). Nothing in the driver cancels them.
idpf_tx_dim_work() and idpf_rx_dim_work() then run on freed memory:idpf_vport_intr_write_itr() writes the ITR register through q_vector->intr_reg.tx_itr / rx_itr, void __iomem pointers loaded out of the freed q_vector. No configuration is needed to get there -- IDPF_ITR_IS_DYNAMIC() is defined as (itr_mode) and idpf_vport_alloc() initialises both modes to IDPF_ITR_DYNAMIC.
Draining after idpf_vport_intr_napi_dis_all() is not enough on its own. idpf_net_dim() is called from inside the
"if (napi_complete_done(napi, work_done))" branch of the poll, and napi_complete_done() has already cleared NAPIF_STATE_SCHED by then. napi_disable_locked() waits only while (val & (NAPIF_STATE_SCHED | NAPIF_STATE_NPSVC)), so napi_disable() can return while the poll tail is still queueing the work, and a plain cancel_work_sync() would be re-armed behind the drain.
Use disable_work_sync(): schedule_work() on a work with a non-zero disable count is dropped by clear_pending_if_disabled() before __queue_work() is reached.
Move idpf_init_dim() to idpf_vport_intr_alloc() so the works are initialised on every path that can reach the drain -- the three "goto intr_deinit" sites between idpf_vport_intr_init() and idpf_vport_intr_ena() get there without the enable side having run. Nothing re-enables them: rsrc->q_vectors is freed on every exit from idpf_vport_open() and on every idpf_vport_stop(), so the count dies with the object.
It is a race, not a deterministic failure -- net_dim() only schedules once DIM_NEVENTS events have accumulated and the profile index changes. A KASAN ifup/ifdown loop under load is the way to see it.
--- drivers/net/ethernet/intel/idpf/idpf_txrx.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/idpf/idpf_txrx.c +23 -1
@@ -3574,6 +3574,26 @@ static void idpf_vport_intr_ena_irq_all( }/** +* idpf_vport_intr_dis_dim_all - Disable DIM work for all q_vectors +* @rsrc: pointer to queue and vector resources +* +* The DIM works are embedded in the q_vector array that +* idpf_vport_intr_rel() frees, and the poll arms them after +* napi_complete_done() has already cleared NAPI_STATE_SCHED. Disable +* rather than just cancel, so that a poll tail still running past +* napi_disable() cannot queue them again behind the drain. +*/ +static void idpf_vport_intr_dis_dim_all (struct idpf_q_vec_rsrc *rsrc) +{ +for (u16 v_idx =0 ; v_idx < rsrc->num_q_vectors; v_idx++) { +struct idpf_q_vector *q_vector = &rsrc->q_vectors[v_idx]; + +disable_work_sync (&q_vector->tx_dim.work); +disable_work_sync (&q_vector->rx_dim.work); + } +} + +/** * idpf_vport_intr_deinit - Release all vector associations for the vport * @vport: main vport structure * @rsrc: pointer to queue and vector resources
@@ -3583,6 +3603,7 @@ void idpf_vport_intr_deinit(struct idpf_ {idpf_vport_intr_dis_irq_all (rsrc);idpf_vport_intr_napi_dis_all (rsrc); +idpf_vport_intr_dis_dim_all (rsrc);idpf_vport_intr_napi_del_all (rsrc);idpf_vport_intr_rel_irq (vport, rsrc); }
@@ -3663,7 +3684,6 @@ static void idpf_vport_intr_napi_ena_allfor (u16 q_idx =0 ; q_idx < rsrc->num_q_vectors; q_idx++) {struct idpf_q_vector *q_vector = &rsrc->q_vectors[q_idx]; -idpf_init_dim (q_vector);napi_enable (&q_vector->napi); } }
@@ -3983,6 +4003,8 @@ int idpf_vport_intr_alloc(struct idpf_vp q_coal = &user_config->q_coalesce[v_idx]; q_vector->vport = vport; +idpf_init_dim (q_vector); + q_vector->tx_itr_value = q_coal->tx_coalesce_usecs; q_vector->tx_intr_mode = q_coal->tx_intr_mode; q_vector->tx_itr_idx =VIRTCHNL2_ITR_IDX_1 ;
Greg Kroah-Hartman
maintainerPATCH 746/877 ipv4: remove fib_devindex_hashfn()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 8a0f62fdeb9ea66ad3d0e959c7c4addbabeac1be ]
fib_devindex_hashfn() converts a 32bit ifindex value to a 8bit hash.
It makes no sense doing this from fib_info_hashfn() and fib_find_info_nh().
It is better to keep as many bits as possible to let fib_info_hashfn_result() have better spread.
Only fib_info_devhash_bucket() needs to make this operation, we can 'inline' trivial fib_devindex_hashfn() in it.
Stable-dep-of: 8d6cd1885085 ("ipv6: flowlabel: cap duplicate leases per socket")
--- net/ipv4/fib_semantics.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
net/ipv4/fib_semantics.c +4 -9
@@ -322,17 +322,12 @@ static inline int nh_comp(struct fib_infreturn 0 ; } -static inline unsigned int fib_devindex_hashfn (unsigned int val) -{ -return hash_32 (val,DEVINDEX_HASHBITS ); -} -static struct hlist_head *fib_info_devhash_bucket (const struct net_device *dev) {u32 val =net_hash_mix (dev_net (dev)) ^ dev->ifindex; -return &fib_info_devhash[fib_devindex_hashfn (val)]; +return &fib_info_devhash[hash_32 (val,DEVINDEX_HASHBITS )]; } static unsigned int fib_info_hashfn_1(int init_val, u8 protocol, u8 scope,
@@ -363,10 +358,10 @@ static inline unsigned int fib_info_hash fi->fib_priority);if (fi->nh) { - val ^=fib_devindex_hashfn (fi->nh->id); + val ^= fi->nh->id; }else {for_nexthops (fi) { - val ^=fib_devindex_hashfn (nh->fib_nh_oif); + val ^= nh->fib_nh_oif; } endfor_nexthops(fi) }
@@ -381,7 +376,7 @@ static struct fib_info *fib_find_info_nhstruct fib_info *fi;unsigned int hash; - hash =fib_info_hashfn_1 (fib_devindex_hashfn (cfg->fc_nh_id), + hash =fib_info_hashfn_1 (cfg->fc_nh_id, cfg->fc_protocol, cfg->fc_scope, (__force u32 )cfg->fc_prefsrc, cfg->fc_priority);
Re: [PATCH 6.12 746/877] ipv4: remove fib_devindex_hashfn()
Quoted 34 lines · Greg Kroah-Hartman
6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit
8a0f62fdeb9ea66ad3d0e959c7c4addbabeac1be]
fib_devindex_hashfn()converts a 32bit ifindex value to a 8bit hash.It makes no sense doing this from
fib_info_hashfn()andfib_find_info_nh().It is better to keep as many bits as possible to let
fib_info_hashfn_result()have better spread.Only
fib_info_devhash_bucket()needs to make this operation, we can 'inline' trivialfib_devindex_hashfn()in it.Signed-off-by Eric Dumazet <[email protected]>Reviewed-by Kuniyuki Iwashima <[email protected]>Reviewed-by David Ahern <[email protected]>Signed-off-by Jakub Kicinski <[email protected]>Stable-dep-of:
8d6cd1885085("ipv6: flowlabel: cap duplicate leases per socket")Signed-off-by Sasha Levin <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- net/ipv4/fib_semantics.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
net/ipv4/fib_semantics.c static inline int nh_comp(struct fib_inf · line 329
Quoted 8 lines
net/ipv4/fib_semantics.c +0
-5@@ -322,17 +322,12 @@ static inline int nh_comp(struct fib_infreturn 0 ; } -static inline unsigned int fib_devindex_hashfn (unsigned int val) -{ -return hash_32 (val,DEVINDEX_HASHBITS ); -} -
Hi Greg/Sasha,
An AI-assisted review flagged this, and I checked the upstream and 6.12 code. Removing fib_devindex_hashfn() also needs the upstream finalizer.
Upstream, net/ipv4/fib_semantics.c:
return hash_32(val ^ net_hash_mix(net), fib_info_hash_bits);
6.12.y still has:
unsigned int mask = (fib_info_hash_size - 1);
return (val ^ (val >> 7) ^ (val >> 12)) & mask;The old finalizer ignores upper bits of raw nexthop IDs/ifindices at ordinary table sizes. In a 256-bucket check with equal route metadata, 128 IDs differing only in their upper byte use 128 buckets before, one after, and 128 upstream.
I think 6.12 needs 9b8ca04854fd1253a58aeb1bd089c191cb5a074c ("ipv4:
avoid quadratic behavior in FIB insertion of common address") before this change, including both finalizer callers, thoughts?
thanks,
Harshit> static struct hlist_head *
Quoted 34 lines
net/ipv4/fib_semantics.c +4
-4fib_info_devhash_bucket(const struct net_device *dev) {u32 val =net_hash_mix (dev_net (dev)) ^ dev->ifindex; -return &fib_info_devhash[fib_devindex_hashfn (val)]; +return &fib_info_devhash[hash_32 (val,DEVINDEX_HASHBITS )]; } static unsigned int fib_info_hashfn_1(int init_val, u8 protocol, u8 scope,@@ -363,10 +358,10 @@ static inline unsigned int fib_info_hash fi->fib_priority);if (fi->nh) { - val ^=fib_devindex_hashfn (fi->nh->id); + val ^= fi->nh->id; }else {for_nexthops (fi) { - val ^=fib_devindex_hashfn (nh->fib_nh_oif); + val ^= nh->fib_nh_oif; } endfor_nexthops(fi) }@@ -381,7 +376,7 @@ static struct fib_info *fib_find_info_nhstruct fib_info *fi;unsigned int hash; - hash =fib_info_hashfn_1 (fib_devindex_hashfn (cfg->fc_nh_id), + hash =fib_info_hashfn_1 (cfg->fc_nh_id, cfg->fc_protocol, cfg->fc_scope, (__force u32 )cfg->fc_prefsrc, cfg->fc_priority);
Re: [PATCH 6.12 746/877] ipv4: remove fib_devindex_hashfn()
Hi Greg/Sasha,
Quoted 9 lines · Harshit Mogalapalli
Quoted 6 lines · Greg Kroah-Hartman
6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
....
Quoted 13 lines
An AI-assisted review flagged this, and I checked the upstream and 6.12 code. Removing
fib_devindex_hashfn()also needs the upstream finalizer.Upstream,
net/ipv4/fib_semantics.c:return
hash_32(val ^ net_hash_mix(net), fib_info_hash_bits);6.12.y still has:
unsigned int mask = (
fib_info_hash_size- 1); return (val ^ (val >> 7) ^ (val >> 12)) & mask;
Quoted 8 lines
The old finalizer ignores upper bits of raw nexthop IDs/ifindices at ordinary table sizes. In a 256-bucket check with equal route metadata, 128 IDs differing only in their upper byte use 128 buckets before, one after, and 128 upstream.
I think 6.12 needs
9b8ca04854fd1253a58aeb1bd089c191cb5a074c("ipv4:
avoid quadratic behavior in FIB insertion of common address") before this change, including both finalizer callers, thoughts?
This also belongs to - we need not/should not take the fix until we take a prerequisite category. Could we drop this until we have a proper backport ?
Sorry for the ping.
thanks,
Harshit
Sasha Levin
maintainerRe: [PATCH 6.12 746/877] ipv4: remove fib_devindex_hashfn()
Quoted 3 lines
This also belongs to - we need not/should not take the fix until we take a prerequisite category. Could we drop this until we have a proper backport ?
Dropped from the 6.12 queue, together with fc38b28365e5 ("ipv4: use rcu in ip_fib_check_default()") and a3f5f4c2f9b6 ("ipv4: remove fib_info_devhash[]"), which were queued alongside it, thanks.
The ipv6 flowlabel fix they were pulled in for, 8d6cd1885085 ("ipv6:
flowlabel: cap duplicate leases per socket"), doesn't actually depend on any of the three, so it stays.
Signature · 2 lines
Thanks, Sasha
Sasha Levin
maintainerRe: [PATCH 6.12 746/877] ipv4: remove fib_devindex_hashfn()
In reply to Harshit MogalapalliQuoted 8 lines
The old finalizer ignores upper bits of raw nexthop IDs/ifindices at ordinary table sizes. In a 256-bucket check with equal route metadata, 128 IDs differing only in their upper byte use 128 buckets before, one after, and 128 upstream.
I think 6.12 needs
9b8ca04854fd1253a58aeb1bd089c191cb5a074c("ipv4:
avoid quadratic behavior in FIB insertion of common address") before this change, including both finalizer callers, thoughts?
Right, 6.12 still has the old finalizer. The cost is longer fib_info hash chains when inserting routes; nothing becomes incorrect. I'm not going to pull that commit into 6.12 for now.
Signature · 2 lines
Thanks, Sasha
Re: [PATCH 6.12 746/877] ipv4: remove fib_devindex_hashfn()
Hi Sasha,
Quoted 5 lines · Sasha Levin
Quoted 5 lines
The old finalizer ignores upper bits of raw nexthop IDs/ifindices at ordinary table sizes. In a 256-bucket check with equal route metadata, 128 IDs differing only in their upper byte use 128 buckets before, one after, and 128 upstream.
Quoted 7 lines
Quoted 3 lines
I think 6.12 needs
9b8ca04854fd1253a58aeb1bd089c191cb5a074c("ipv4:
avoid quadratic behavior in FIB insertion of common address") before this change, including both finalizer callers, thoughts?Right, 6.12 still has the old finalizer. The cost is longer
fib_infohash chains when inserting routes; nothing becomes incorrect. I'm not going to pull that commit into 6.12 for now.
Sure, sounds good.
Regards,
Harshit>
Greg Kroah-Hartman
maintainerPATCH 747/877 ipv4: use rcu in ip_fib_check_default()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit fc38b28365e5f1396209d2878a34065468765087 ]
fib_info_devhash[] is not resized in fib_info_hash_move().
fib_nh structs are already freed after an rcu grace period.
This will allow to remove fib_info_lock in the following patch.
Stable-dep-of: 8d6cd1885085 ("ipv6: flowlabel: cap duplicate leases per socket")
--- net/ipv4/fib_semantics.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
net/ipv4/fib_semantics.c +4 -9
@@ -275,7 +275,7 @@ void fib_release_info(struct fib_info *fchange_nexthops (fi) {if (!nexthop_nh->fib_nh_dev)continue ; -hlist_del (&nexthop_nh->nh_hash); +hlist_del_rcu (&nexthop_nh->nh_hash); } endfor_nexthops(fi) }/* Paired with READ_ONCE() from fib_table_lookup() */
@@ -432,28 +432,23 @@ static struct fib_info *fib_find_info(st }/* Check, that the gateway is already configured. -* Used only by redirect accept routine. +* Used only by redirect accept routine, under rcu_read_lock(); */ int ip_fib_check_default (__be32 gw,struct net_device *dev) {struct hlist_head *head;struct fib_nh *nh; -spin_lock (&fib_info_lock); - head =fib_info_devhash_bucket (dev); -hlist_for_each_entry (nh, head, nh_hash) { +hlist_for_each_entry_rcu (nh, head, nh_hash) {if (nh->fib_nh_dev == dev && nh->fib_nh_gw4 == gw && !(nh->fib_nh_flags &RTNH_F_DEAD )) { -spin_unlock (&fib_info_lock);return 0 ; } } -spin_unlock (&fib_info_lock); -return -1 ; }
@@ -1638,7 +1633,7 @@ link_it:if (!nexthop_nh->fib_nh_dev)continue ; head =fib_info_devhash_bucket (nexthop_nh->fib_nh_dev); -hlist_add_head (&nexthop_nh->nh_hash, head); +hlist_add_head_rcu (&nexthop_nh->nh_hash, head); } endfor_nexthops(fi) }spin_unlock_bh (&fib_info_lock);
Greg Kroah-Hartman
maintainerPATCH 748/877 ipv4: remove fib_info_devhash[]
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit a3f5f4c2f9b6bc2aa6f5a3e8e23b7519e4f2e3e3 ]
Upcoming per-netns RTNL conversion needs to get rid of shared hash tables.
fib_info_devhash[] is one of them.
It is unclear why we used a hash table, because
a single hlist_head per net device was cheaper and scalable.
Stable-dep-of: 8d6cd1885085 ("ipv6: flowlabel: cap duplicate leases per socket")
--- Documentation/networking/net_cachelines/net_device.rst | 1 include/linux/netdevice.h | 3 + net/ipv4/fib_semantics.c | 35 +++++++---------- 3 files changed, 19 insertions(+), 20 deletions(-)
Documentation/networking/net_cachelines/net_device.rst +1 -0
@@ -83,6 +83,7 @@ unsigned_int allm bool uc_promisc unsigned_char nested_level struct_in_device* ip_ptr read_mostly read_mostly __in_dev_get +struct hlist_head fib_nh_head struct_inet6_dev* ip6_ptr read_mostly read_mostly __in6_dev_get struct_vlan_info* vlan_info struct_dsa_port* dsa_ptr
include/linux/netdevice.h +3 -0
@@ -2217,6 +2217,9 @@ struct net_device {/* Protocol-specific pointers */ struct in_device __rcu *ip_ptr; +/** @fib_nh_head: nexthops associated with this netdev */ +struct hlist_head fib_nh_head; +#if IS_ENABLED (CONFIG_VLAN_8021Q )struct vlan_info __rcu *vlan_info;#endif
net/ipv4/fib_semantics.c +15 -20
@@ -57,10 +57,6 @@ static unsigned int fib_info_hash_size;static unsigned int fib_info_hash_bits;static unsigned int fib_info_cnt; -#define DEVINDEX_HASHBITS 8 -#define DEVINDEX_HASHSIZE (1U << DEVINDEX_HASHBITS) -static struct hlist_head fib_info_devhash[DEVINDEX_HASHSIZE ]; -/* for_nexthops and change_nexthops only used when nexthop object * is not set in a fib_info. The logic within can reference fib_nh. */
@@ -322,12 +318,9 @@ static inline int nh_comp(struct fib_infreturn 0 ; } -static struct hlist_head * -fib_info_devhash_bucket (const struct net_device *dev) +static struct hlist_head *fib_nh_head (struct net_device *dev) { -u32 val =net_hash_mix (dev_net (dev)) ^ dev->ifindex; - -return &fib_info_devhash[hash_32 (val,DEVINDEX_HASHBITS )]; +return &dev->fib_nh_head; } static unsigned int fib_info_hashfn_1(int init_val, u8 protocol, u8 scope,
@@ -439,11 +432,11 @@ int ip_fib_check_default(__be32 gw, strustruct hlist_head *head;struct fib_nh *nh; - head =fib_info_devhash_bucket (dev); + head =fib_nh_head (dev);hlist_for_each_entry_rcu (nh, head, nh_hash) { -if (nh->fib_nh_dev == dev && - nh->fib_nh_gw4 == gw && +DEBUG_NET_WARN_ON_ONCE (nh->fib_nh_dev != dev); +if (nh->fib_nh_gw4 == gw && !(nh->fib_nh_flags &RTNH_F_DEAD )) {return 0 ; }
@@ -1632,7 +1625,7 @@ link_it:if (!nexthop_nh->fib_nh_dev)continue ; - head =fib_info_devhash_bucket (nexthop_nh->fib_nh_dev); + head =fib_nh_head (nexthop_nh->fib_nh_dev);hlist_add_head_rcu (&nexthop_nh->nh_hash, head); } endfor_nexthops(fi) }
@@ -1974,12 +1967,12 @@ out:void fib_sync_mtu (struct net_device *dev,u32 orig_mtu) { -struct hlist_head *head =fib_info_devhash_bucket (dev); +struct hlist_head *head =fib_nh_head (dev);struct fib_nh *nh;hlist_for_each_entry (nh, head, nh_hash) { -if (nh->fib_nh_dev == dev) -fib_nhc_update_mtu (&nh->nh_common, dev->mtu, orig_mtu); +DEBUG_NET_WARN_ON_ONCE (nh->fib_nh_dev != dev); +fib_nhc_update_mtu (&nh->nh_common, dev->mtu, orig_mtu); } }
@@ -1993,7 +1986,7 @@ void fib_sync_mtu(struct net_device *dev*/ int fib_sync_down_dev (struct net_device *dev,unsigned long event,bool force) { -struct hlist_head *head =fib_info_devhash_bucket (dev); +struct hlist_head *head =fib_nh_head (dev);struct fib_info *prev_fi =NULL ;int scope =RT_SCOPE_NOWHERE ;struct fib_nh *nh;
@@ -2007,7 +2000,8 @@ int fib_sync_down_dev(struct net_deviceint dead;BUG_ON (!fi->fib_nhs); -if (nh->fib_nh_dev != dev || fi == prev_fi) +DEBUG_NET_WARN_ON_ONCE (nh->fib_nh_dev != dev); +if (fi == prev_fi)continue ; prev_fi = fi; dead =0 ;
@@ -2157,7 +2151,7 @@ int fib_sync_up(struct net_device *dev, } prev_fi =NULL ; - head =fib_info_devhash_bucket (dev); + head =fib_nh_head (dev); ret =0 ;hlist_for_each_entry (nh, head, nh_hash) {
@@ -2165,7 +2159,8 @@ int fib_sync_up(struct net_device *dev,int alive;BUG_ON (!fi->fib_nhs); -if (nh->fib_nh_dev != dev || fi == prev_fi) +DEBUG_NET_WARN_ON_ONCE (nh->fib_nh_dev != dev); +if (fi == prev_fi)continue ; prev_fi = fi;
Greg Kroah-Hartman
maintainerPATCH 749/877 ipv6: make ipv6_pinfo.saddr_cache a boolean
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 3fbb2a6f3a70c27a6a2be80d131970608c0f84d0 ]
ipv6_pinfo.saddr_cache is either NULL or &np->saddr.
We do not need 8 bytes, a boolean is enough.
Stable-dep-of: 8d6cd1885085 ("ipv6: flowlabel: cap duplicate leases per socket")
--- include/linux/ipv6.h | 4 ++-- include/net/ip6_route.h | 4 ++-- net/ipv6/af_inet6.c | 2 +- net/ipv6/inet6_connection_sock.c | 2 +- net/ipv6/ip6_output.c | 3 ++- net/ipv6/route.c | 4 ++-- net/ipv6/tcp_ipv6.c | 4 ++-- 7 files changed, 12 insertions(+), 11 deletions(-)
include/linux/ipv6.h +2 -2
@@ -214,10 +214,10 @@ struct inet6_cork {struct ipv6_pinfo {struct in6_addr saddr;struct in6_pktinfo sticky_pktinfo; -const struct in6_addr *daddr_cache;#ifdef CONFIG_IPV6_SUBTREES -const struct in6_addr *saddr_cache; +bool saddr_cache;#endif +const struct in6_addr *daddr_cache;__be32 flow_label;__u32 frag_size;
include/net/ip6_route.h +2 -2
@@ -230,7 +230,7 @@ static inline const struct rt6_info *skb*/ static inline void ip6_dst_store (struct sock *sk,struct dst_entry *dst,const struct in6_addr *daddr, -const struct in6_addr *saddr) +bool saddr_set) {struct ipv6_pinfo *np =inet6_sk (sk);
@@ -238,7 +238,7 @@ static inline void ip6_dst_store(structsk_setup_caps (sk, dst); np->daddr_cache = daddr;#ifdef CONFIG_IPV6_SUBTREES - np->saddr_cache = saddr; + np->saddr_cache = saddr_set;#endif }
net/ipv6/af_inet6.c +1 -1
@@ -856,7 +856,7 @@ int inet6_sk_rebuild_header(struct sockreturn PTR_ERR (dst); } -ip6_dst_store (sk, dst,NULL ,NULL ); +ip6_dst_store (sk, dst,NULL , false); }return 0 ;
net/ipv6/inet6_connection_sock.c +1 -1
@@ -106,7 +106,7 @@ static struct dst_entry *inet6_csk_route dst =ip6_dst_lookup_flow (sock_net (sk), sk, fl6, final_p);if (!IS_ERR (dst)) -ip6_dst_store (sk, dst,NULL ,NULL ); +ip6_dst_store (sk, dst,NULL , false); }return dst; }
net/ipv6/ip6_output.c +2 -1
@@ -1103,7 +1103,8 @@ static struct dst_entry *ip6_sk_dst_chec*/ if (ip6_rt_check(&rt->rt6i_dst, &fl6->daddr, np->daddr_cache) ||#ifdef CONFIG_IPV6_SUBTREES - ip6_rt_check(&rt->rt6i_src, &fl6->saddr, np->saddr_cache) || + ip6_rt_check(&rt->rt6i_src, &fl6->saddr, + np->saddr_cache ? &np->saddr : NULL) || #endif (fl6->flowi6_oif && fl6->flowi6_oif != dst_dev(dst)->ifindex)) {dst_release (dst);
net/ipv6/route.c +2 -2
@@ -3049,9 +3049,9 @@ void ip6_sk_dst_store_flow(struct sock * &sk->sk_v6_daddr : NULL,#ifdef CONFIG_IPV6_SUBTREES ipv6_addr_equal (&fl6->saddr, &np->saddr) ? - &np->saddr : + true : #endif - NULL); + false); } static bool ip6_redirect_nh_match(const struct fib6_result *res,
net/ipv6/tcp_ipv6.c +2 -2
@@ -293,7 +293,7 @@ static int tcp_v6_connect(struct sock *s inet->inet_rcv_saddr =LOOPBACK4_IPV6 ; sk->sk_gso_type =SKB_GSO_TCPV6 ; -ip6_dst_store (sk, dst,NULL ,NULL ); +ip6_dst_store (sk, dst,NULL , false); icsk->icsk_ext_hdr_len =0 ;if (opt)
@@ -1435,7 +1435,7 @@ static struct sock *tcp_v6_syn_recv_sockmemcpy (newnp, np,sizeof (struct ipv6_pinfo )); -ip6_dst_store (newsk, dst,NULL ,NULL ); +ip6_dst_store (newsk, dst,NULL , false); newsk->sk_v6_daddr = ireq->ir_v6_rmt_addr; newnp->saddr = ireq->ir_v6_loc_addr;
Greg Kroah-Hartman
maintainerPATCH 750/877 ipv6: reorganise struct ipv6_pinfo
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit b76543b21fbcfbb96332fd80cc0d85bbcd72d8f0 ]
Move fields used in tx fast path at the beginning of the structure, and seldom used ones at the end.
Note that rxopt is also in the first cache line.
Stable-dep-of: 8d6cd1885085 ("ipv6: flowlabel: cap duplicate leases per socket")
--- include/linux/ipv6.h | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-)
include/linux/ipv6.h +16 -17
@@ -212,18 +212,21 @@ struct inet6_cork {/* struct ipv6_pinfo - ipv6 private area */ struct ipv6_pinfo { +/* Used in tx path (inet6_csk_route_socket(), ip6_xmit()) */ struct in6_addr saddr; -struct in6_pktinfo sticky_pktinfo; +__be32 flow_label; +u32 dst_cookie; +struct ipv6_txoptions __rcu *opt; +s16 hop_limit; +u8 pmtudisc; +u8 tclass;#ifdef CONFIG_IPV6_SUBTREES bool saddr_cache;#endif const struct in6_addr *daddr_cache; -__be32 flow_label; -__u32 frag_size; - -s16 hop_limit;u8 mcast_hops; +u32 frag_size;int ucast_oif;int mcast_oif;
@@ -231,7 +234,7 @@ struct ipv6_pinfo {/* pktoption flags */ union {struct { -__u16 srcrt:1 , +u16 srcrt:1 , osrcrt:1 , rxinfo:1 , rxoinfo:1,
@@ -248,29 +251,25 @@ struct ipv6_pinfo { recvfragsize:1 ;/* 1 bits hole */ } bits; -__u16 all; +u16 all; } rxopt;/* sockopt flags */ -__u8 srcprefs;/* 001: prefer temporary address +u8 srcprefs;/* 001: prefer temporary address * 010: prefer public address * 100: prefer care-of address */ -__u8 pmtudisc; -__u8 min_hopcount; -__u8 tclass; +u8 min_hopcount;__be32 rcv_flowinfo; +struct in6_pktinfo sticky_pktinfo; -__u32 dst_cookie; +struct sk_buff *pktoptions; +struct sk_buff *rxpmtu; +struct inet6_cork cork;struct ipv6_mc_socklist __rcu *ipv6_mc_list;struct ipv6_ac_socklist *ipv6_ac_list;struct ipv6_fl_socklist __rcu *ipv6_fl_list; - -struct ipv6_txoptions __rcu *opt; -struct sk_buff *pktoptions; -struct sk_buff *rxpmtu; -struct inet6_cork cork; };/* We currently use available bits from inet_sk(sk)->inet_flags,
Greg Kroah-Hartman
maintainerPATCH 751/877 ipv6: Move ipv6_fl_list from ipv6_pinfo to inet_sock.
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
[ Upstream commit 1c17f4373d4db1e1f0ebd3ddcd8e7a642927a826 ]
In {tcp6,udp6,raw6}_sock, struct ipv6_pinfo is always placed at the beginning of a new cache line because
1. __alignof__(struct tcp_sock) is 64 due to ____cacheline_aligned of __cacheline_group_begin(tcp_sock_write_tx)
2. __alignof__(struct udp_sock) is 64 due to ____cacheline_aligned of struct numa_drop_counters
3. in raw6_sock, struct numa_drop_counters is placed before struct ipv6_pinfo
. struct ipv6_pinfo is 136 bytes, but the last cache line is only used by ipv6_fl_list:
$ pahole -C ipv6_pinfo vmlinux
struct ipv6_pinfo {
...
/* --- cacheline 2 boundary (128 bytes) --- */
struct ipv6_fl_socklist * ipv6_fl_list; /* 128 8 *//* size: 136, cachelines: 3, members: 23 */
Let's move ipv6_fl_list from struct ipv6_pinfo to struct inet_sock to save a full cache line for {tcp6,udp6,raw6}_sock.
Now, struct ipv6_pinfo is 128 bytes, and {tcp6,udp6,raw6}_sock have 64 bytes less, while {tcp,udp,raw}_sock retain the same size.
Before:
# grep -E "^(RAW|UDP[^L\-]|TCP)" /proc/slabinfo | awk '{print $1, "\t", $4}'
RAWv6 1408
UDPv6 1472
TCPv6 2560
RAW 1152
UDP 1280
TCP 2368After:
# grep -E "^(RAW|UDP[^L\-]|TCP)" /proc/slabinfo | awk '{print $1, "\t", $4}'
RAWv6 1344
UDPv6 1408
TCPv6 2496
RAW 1152
UDP 1280
TCP 2368Also, ipv6_fl_list and inet_flags (SNDFLOW bit) are placed in the same cache line.
$ pahole -C inet_sock vmlinux ... /* --- cacheline 11 boundary (704 bytes) was 56 bytes ago --- */ struct ipv6_pinfo * pinet6; /* 760 8 */ /* --- cacheline 12 boundary (768 bytes) --- */ struct ipv6_fl_socklist * ipv6_fl_list; /* 768 8 */ unsigned long inet_flags; /* 776 8 */
Doc churn is due to the insufficient Type column (only 1 space short).
Stable adaptation:
Keep the stable TCP mapped-child initialization callback introduced by 9ed654e340f4c ("tcp: fix potential race in tcp_v6_syn_recv_sock()") and reset the relocated flowlabel list in that existing helper. Update both DCCP child paths too, since DCCP is still present in this tree. Preserve the existing cacheline-documentation format and add only the new field.
Name the existing unprivileged total limit in mem_check() and use it in an algebraically equivalent room check. This supplies the context needed by 8d6cd1885085 ("ipv6: flowlabel: cap duplicate leases per socket") without importing the later per-netns accounting or changing admission policy. No new functions are introduced by this dependency.
Stable-dep-of: 8d6cd1885085 ("ipv6: flowlabel: cap duplicate leases per socket")
--- Documentation/networking/net_cachelines/inet_sock.rst | 1 drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c | 4 - include/linux/ipv6.h | 1 include/net/inet_sock.h | 1 net/dccp/ipv6.c | 4 - net/ipv6/ip6_flowlabel.c | 48 ++++++------ net/ipv6/tcp_ipv6.c | 10 +- net/sctp/ipv6.c | 8 +- 8 files changed, 40 insertions(+), 37 deletions(-)
Documentation/networking/net_cachelines/inet_sock.rst +1 -0
@@ -9,6 +9,7 @@ Type Name ..struct ..inet_sock struct_sock sk read_mostly read_mostly tcp_init_buffer_space,tcp_init_transfer,tcp_finish_connect,tcp_connect,tcp_send_rcvq,tcp_send_syn_data struct_ipv6_pinfo* pinet6 - - +struct_ipv6_fl_socklist* ipv6_fl_list read_mostly - tcp_v6_connect,__ip6_datagram_connect,udpv6_sendmsg,rawv6_sendmsg be16 inet_sport read_mostly - __tcp_transmit_skb be32 inet_daddr read_mostly - ip_select_ident_segs be32 inet_rcv_saddr - -
drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_cm.c +2 -2
@@ -1197,12 +1197,12 @@ static struct sock *chtls_recv_sock(strustruct ipv6_pinfo *newnp =inet6_sk (newsk);struct ipv6_pinfo *np =inet6_sk (lsk); -inet_sk (newsk)->pinet6 = &newtcp6sk->inet6; + newinet->pinet6 = &newtcp6sk->inet6; + newinet->ipv6_fl_list =NULL ;memcpy (newnp, np,sizeof (struct ipv6_pinfo )); newsk->sk_v6_daddr = treq->ir_v6_rmt_addr; newsk->sk_v6_rcv_saddr = treq->ir_v6_loc_addr;inet6_sk (newsk)->saddr = treq->ir_v6_loc_addr; - newnp->ipv6_fl_list =NULL ; newnp->pktoptions =NULL ; newsk->sk_bound_dev_if = treq->ir_iif; newinet->inet_opt =NULL ;
include/linux/ipv6.h +0 -1
@@ -269,7 +269,6 @@ struct ipv6_pinfo {struct ipv6_mc_socklist __rcu *ipv6_mc_list;struct ipv6_ac_socklist *ipv6_ac_list; -struct ipv6_fl_socklist __rcu *ipv6_fl_list; };/* We currently use available bits from inet_sk(sk)->inet_flags,
include/net/inet_sock.h +1 -0
@@ -212,6 +212,7 @@ struct inet_sock {struct sock sk;#if IS_ENABLED (CONFIG_IPV6 )struct ipv6_pinfo *pinet6; +struct ipv6_fl_socklist __rcu *ipv6_fl_list;#endif /* Socket demultiplex comparisons on incoming packets. */ #define inet_daddr sk.__sk_common.skc_daddr
net/dccp/ipv6.c +2 -2
@@ -456,7 +456,7 @@ static struct sock *dccp_v6_request_recv newnp->opt =NULL ; newnp->ipv6_mc_list =NULL ; newnp->ipv6_ac_list =NULL ; - newnp->ipv6_fl_list =NULL ; + newinet->ipv6_fl_list =NULL ; newnp->mcast_oif =inet_iif (skb); newnp->mcast_hops =ip_hdr (skb)->ttl;
@@ -523,7 +523,7 @@ static struct sock *dccp_v6_request_recv newnp->ipv6_mc_list =NULL ; newnp->ipv6_ac_list =NULL ; - newnp->ipv6_fl_list =NULL ; + newinet->ipv6_fl_list =NULL ; newnp->pktoptions =NULL ; newnp->opt =NULL ; newnp->mcast_oif =inet6_iif (skb);
net/ipv6/ip6_flowlabel.c +24 -24
150 lines not on this page · raw message
net/ipv6/tcp_ipv6.c +5 -5
@@ -1349,6 +1349,7 @@ static void tcp_v6_mapped_child_init(strstruct ipv6_pinfo *newnp; newinet->pinet6 = newnp =tcp_inet6_sk (newsk); + newinet->ipv6_fl_list =NULL ;memcpy (newnp,tcp_inet6_sk (sk),sizeof (struct ipv6_pinfo ));
@@ -1364,7 +1365,6 @@ static void tcp_v6_mapped_child_init(str newnp->ipv6_mc_list =NULL ; newnp->ipv6_ac_list =NULL ; - newnp->ipv6_fl_list =NULL ; newnp->pktoptions =NULL ; newnp->opt =NULL ;
@@ -1427,10 +1427,12 @@ static struct sock *tcp_v6_syn_recv_sock newsk->sk_gso_type =SKB_GSO_TCPV6 ;inet6_sk_rx_dst_set (newsk, skb); -inet_sk (newsk)->pinet6 =tcp_inet6_sk (newsk); + newinet =inet_sk (newsk); + newinet->pinet6 =tcp_inet6_sk (newsk); + newinet->ipv6_fl_list =NULL ; + newinet->inet_opt =NULL ; newtp =tcp_sk (newsk); - newinet =inet_sk (newsk); newnp =tcp_inet6_sk (newsk);memcpy (newnp, np,sizeof (struct ipv6_pinfo ));
@@ -1446,10 +1448,8 @@ static struct sock *tcp_v6_syn_recv_sockFirst: no IPv4 options. */ - newinet->inet_opt =NULL ; newnp->ipv6_mc_list =NULL ; newnp->ipv6_ac_list =NULL ; - newnp->ipv6_fl_list =NULL ;/* Clone RX bits */ newnp->rxopt.all = np->rxopt.all;
net/sctp/ipv6.c +5 -3
@@ -784,9 +784,10 @@ static struct sock *sctp_v6_create_accep struct sctp_association *asoc, bool kern) { -struct sock *newsk;struct ipv6_pinfo *newnp, *np =inet6_sk (sk);struct sctp6_sock *newsctp6sk; +struct inet_sock *newinet; +struct sock *newsk; newsk =sk_alloc (sock_net (sk),PF_INET6 ,GFP_KERNEL , sk->sk_prot, kern);if (!newsk)
@@ -798,7 +799,9 @@ static struct sock *sctp_v6_create_accepsock_reset_flag (sk,SOCK_ZAPPED ); newsctp6sk = (struct sctp6_sock *)newsk; -inet_sk (newsk)->pinet6 = &newsctp6sk->inet6; + newinet =inet_sk (newsk); + newinet->pinet6 = &newsctp6sk->inet6; + newinet->ipv6_fl_list =NULL ;sctp_sk (newsk)->v4mapped =sctp_sk (sk)->v4mapped;
@@ -807,7 +810,6 @@ static struct sock *sctp_v6_create_accepmemcpy (newnp, np,sizeof (struct ipv6_pinfo )); newnp->ipv6_mc_list =NULL ; newnp->ipv6_ac_list =NULL ; - newnp->ipv6_fl_list =NULL ;sctp_v6_copy_ip_options (sk, newsk);
Greg Kroah-Hartman
maintainerPATCH 752/877 ipv6: flowlabel: cap duplicate leases per socket
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhiling Zou <[email protected]>
[ Upstream commit 8d6cd188508513503805c156165de38e4e4a8615 ]
ipv6_flowlabel_get() allocates an ipv6_fl_socklist entry for every successful GET. The recheck path for a compatible existing flowlabel links another lease without applying any lease admission check. Repeated GET requests for one shareable label can therefore grow a socket's lease list without bound.
Reject a new unprivileged lease once the socket already holds FL_MAX_PER_SOCK leases. Check this on the shared recheck path so reuse of a globally interned label, including the fl_intern() collision path, is covered as well. New-label admission remains under the existing mem_check() policy.
Use capable(CAP_NET_ADMIN) rather than ns_capable(), matching mem_check(). An unprivileged user must not bypass the cap by creating a user namespace and a netns where they have CAP_NET_ADMIN, which would still consume host memory.
Check the capability only when the socket reaches the limit, so successful unprivileged GET requests below the cap do not generate a capability audit. Do the admission check before updating linger and expires so a rejected GET does not refresh the shared label, matching the existing socket-list allocation failure path.
--- net/ipv6/ip6_flowlabel.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
net/ipv6/ip6_flowlabel.c +19 -0
@@ -462,6 +462,21 @@ done:return NULL ; } +static bool fl_sock_at_lease_limit (const struct sock *sk) +{ +const struct ipv6_fl_socklist *sfl; +int count =0 ; + +rcu_read_lock (); +for_each_sk_fl_rcu (sk, sfl) { +if (++count >=FL_MAX_PER_SOCK ) +break ; + } +rcu_read_unlock (); + +return count >=FL_MAX_PER_SOCK ; +} +static int mem_check (struct sock *sk) {const int unpriv_total_limit =FL_MAX_SIZE - (FL_MAX_SIZE /4 );
@@ -673,6 +688,10 @@ recheck: err = -ENOMEM ;if (!sfl1) goto release; + err = -ENOBUFS ; +if (fl_sock_at_lease_limit (sk) && + !capable (CAP_NET_ADMIN )) + goto release;if (fl->linger > fl1->linger) fl1->linger = fl->linger;if ((long )(fl->expires - fl1->expires) >0 )
Greg Kroah-Hartman
maintainerPATCH 753/877 landlock: Clarify documentation for the IOCTL access right
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Günther Noack <[email protected]>
[ Upstream commit 6abbb8703aeeb645a681ab6ad155e0b450413787 ]
Move the description of the LANDLOCK_ACCESS_FS_IOCTL_DEV access right together with the file access rights.
This group of access rights applies to files (in this case device files), and they can be added to file or directory inodes using landlock_add_rule(2). The check for that works the same for all file access rights, including LANDLOCK_ACCESS_FS_IOCTL_DEV.
Invoking ioctl(2) on directory FDs can not currently be restricted with Landlock. Having it grouped separately in the documentation is a remnant from earlier revisions of the LANDLOCK_ACCESS_FS_IOCTL_DEV patch set.
Stable-dep-of: 2c6dc7925382 ("landlock: Fix use-after-free of the source's parent directory")
--- include/uapi/linux/landlock.h | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-)
include/uapi/linux/landlock.h +17 -20
@@ -156,6 +156,23 @@ struct landlock_net_port_attr {* :manpage:`ftruncate(2)`, :manpage:`creat(2)`, or :manpage:`open(2)` with * ``O_TRUNC``. This access right is available since the third version of the * Landlock ABI. +* - %LANDLOCK_ACCESS_FS_IOCTL_DEV: Invoke :manpage:`ioctl(2)` commands on an opened +* character or block device. +* +* This access right applies to all `ioctl(2)` commands implemented by device +* drivers. However, the following common IOCTL commands continue to be +* invokable independent of the %LANDLOCK_ACCESS_FS_IOCTL_DEV right: +* +* * IOCTL commands targeting file descriptors (``FIOCLEX``, ``FIONCLEX``), +* * IOCTL commands targeting file descriptions (``FIONBIO``, ``FIOASYNC``), +* * IOCTL commands targeting file systems (``FIFREEZE``, ``FITHAW``, +* ``FIGETBSZ``, ``FS_IOC_GETFSUUID``, ``FS_IOC_GETFSSYSFSPATH``) +* * Some IOCTL commands which do not make sense when used with devices, but +* whose implementations are safe and return the right error codes +* (``FS_IOC_FIEMAP``, ``FICLONE``, ``FICLONERANGE``, ``FIDEDUPERANGE``) +* +* This access right is available since the fifth version of the Landlock +* ABI. * * Whether an opened file can be truncated with :manpage:`ftruncate(2)` or used * with `ioctl(2)` is determined during :manpage:`open(2)`, in the same way as
@@ -216,26 +233,6 @@ struct landlock_net_port_attr {* If multiple requirements are not met, the ``EACCES`` error code takes * precedence over ``EXDEV``. * -* The following access right applies both to files and directories: -* -* - %LANDLOCK_ACCESS_FS_IOCTL_DEV: Invoke :manpage:`ioctl(2)` commands on an opened -* character or block device. -* -* This access right applies to all `ioctl(2)` commands implemented by device -* drivers. However, the following common IOCTL commands continue to be -* invokable independent of the %LANDLOCK_ACCESS_FS_IOCTL_DEV right: -* -* * IOCTL commands targeting file descriptors (``FIOCLEX``, ``FIONCLEX``), -* * IOCTL commands targeting file descriptions (``FIONBIO``, ``FIOASYNC``), -* * IOCTL commands targeting file systems (``FIFREEZE``, ``FITHAW``, -* ``FIGETBSZ``, ``FS_IOC_GETFSUUID``, ``FS_IOC_GETFSSYSFSPATH``) -* * Some IOCTL commands which do not make sense when used with devices, but -* whose implementations are safe and return the right error codes -* (``FS_IOC_FIEMAP``, ``FICLONE``, ``FICLONERANGE``, ``FIDEDUPERANGE``) -* -* This access right is available since the fifth version of the Landlock -* ABI. -* * .. warning:: * * It is currently not possible to restrict some file-related actions
Greg Kroah-Hartman
maintainerPATCH 754/877 landlock: Fix use-after-free of the sources parent directory
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Norbert Szetei <[email protected]>
[ Upstream commit 2c6dc792538260a8087ac5b22c31b3b8e47c85d6 ]
current_check_refer_path() reads old_dentry->d_parent without holding a reference nor a lock on it, and then dereferences it in collect_domain_accesses() and in the audit record.
A reference on a child does not pin its parent: __d_move() reassigns dentry->d_parent and drops the reference the child held on its former parent. hook_path_rename() is not affected because the rename path calls lock_rename() before the hook, so the source cannot be reparented under it. hook_path_link() has no such protection: filename_linkat() holds a reference on the source dentry but neither locks nor references its parent, so a concurrent rename(2) can reparent the source while security_path_link() runs, and the former parent can then be removed and freed while the hook walks it.
A process can trigger this after entering a Landlock domain that handles at least one filesystem access right. The process can then race a linkat(2) loop against rename(2) and rmdir(2):
BUG: KASAN: slab-use-after-free in collect_domain_accesses+0x278/0x290 Read of size 4 at addr ffff888160bd53f4 by task llrepro2/549 collect_domain_accesses+0x278/0x290 current_check_refer_path+0x952/0x1120 security_path_link+0x1be/0x320 filename_linkat+0x342/0x6d0 __x64_sys_linkat+0xfa/0x150 Freed by task 562: kmem_cache_free+0x139/0x4c0 i_callback+0x4b/0x80 rcu_core+0x7dc/0x10a0
Take a reference on the dentry selected as the source parent, using dget() for the common-mount-root case and dget_parent() otherwise. Release it after the hierarchy walk and synchronous audit logging.
--- security/landlock/fs.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
security/landlock/fs.c +12 -6
@@ -1192,11 +1192,12 @@ static int current_check_refer_path(stru/* * old_dentry may be the root of the common mount point and * !IS_ROOT(old_dentry) at the same time (e.g. with open_tree() and -* OPEN_TREE_CLONE). We do not need to call dget(old_parent) because -* we keep a reference to old_dentry. +* OPEN_TREE_CLONE). Pin the dentry used as old_parent in either case. +* Otherwise, dget_parent() safely fetches and pins the current parent +* against a concurrent rename(2). */ - old_parent = (old_dentry == mnt_dir.dentry) ? old_dentry : - old_dentry->d_parent; + old_parent = (old_dentry == mnt_dir.dentry) ?dget (old_dentry) : +dget_parent (old_dentry);/* new_dir->dentry is equal to new_dentry->d_parent */ allow_parent1 = collect_domain_accesses(dom, mnt_dir.dentry, old_parent,
@@ -1204,8 +1205,10 @@ static int current_check_refer_path(stru allow_parent2 =collect_domain_accesses ( dom, mnt_dir.dentry, new_dir->dentry, &layer_masks_parent2); -if (allow_parent1 && allow_parent2) +if (allow_parent1 && allow_parent2) { +dput (old_parent);return 0 ; + }/* * To be able to compare source and destination domain access rights,
@@ -1216,8 +1219,11 @@ static int current_check_refer_path(struif (is_access_to_paths_allowed ( dom, &mnt_dir, access_request_parent1, &layer_masks_parent1, old_dentry, access_request_parent2, &layer_masks_parent2, - exchange ? new_dentry :NULL )) + exchange ? new_dentry :NULL )) { +dput (old_parent);return 0 ; + } +dput (old_parent);/* * This prioritizes EACCES over EXDEV for all actions, including
Greg Kroah-Hartman
maintainerPATCH 755/877 netmem: add a couple of page helper wrappers
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexander Lobakin <[email protected]>
[ Upstream commit 9bd9f72a74344b54cfb6fcabf1173e6c6e5c6952 ]
Add the following netmem counterparts:
* virt_to_netmem() -- simple page_to_netmem(virt_to_page()) wrapper;
* netmem_is_pfmemalloc() -- page_is_pfmemalloc() for page-backed
netmems, false otherwise;
and the following "unsafe" versions:
* __netmem_to_page()
* __netmem_get_pp()
* __netmem_address()
They do the same as their non-underscored buddies, but assume the netmem is always page-backed. When working with header &page_pools, you don't need to check whether netmem belongs to the host memory and you can never get NULL instead of &page. Checks for the LSB, clearing the LSB, branches take cycles and increase object code size, sometimes significantly. When you're sure your PP is always host, you can avoid this by using the underscored counterparts.
Stable-dep-of: b814dfbfeb0a ("bnxt_en: Propagate TPA buffer allocation failures in bnxt_queue_mem_alloc()")
--- include/net/netmem.h | 78 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 76 insertions(+), 2 deletions(-)
include/net/netmem.h +76 -2
@@ -72,6 +72,22 @@ static inline bool netmem_is_net_iov(conreturn (__force unsigned long )netmem &NET_IOV ; } +/** +* __netmem_to_page - unsafely get pointer to the &page backing @netmem +* @netmem: netmem reference to convert +* +* Unsafe version of netmem_to_page(). When @netmem is always page-backed, +* e.g. when it's a header buffer, performs faster and generates smaller +* object code (no check for the LSB, no WARN). When @netmem points to IOV, +* provokes undefined behaviour. +* +* Return: pointer to the &page (garbage if @netmem is not page-backed). +*/ +static inline struct page *__netmem_to_page (netmem_ref netmem) +{ +return (__force struct page *)netmem; +} +/* This conversion fails (returns NULL) if the netmem_ref is not struct page * backed. */
@@ -80,7 +96,7 @@ static inline struct page *netmem_to_pagif (WARN_ON_ONCE (netmem_is_net_iov (netmem)))return NULL ; -return (__force struct page *)netmem; +return __netmem_to_page (netmem); }static inline struct net_iov *netmem_to_net_iov (netmem_ref netmem)
@@ -103,6 +119,17 @@ static inline netmem_ref page_to_netmem(return (__force netmem_ref )page; } +/** +* virt_to_netmem - convert virtual memory pointer to a netmem reference +* @data: host memory pointer to convert +* +* Return: netmem reference to the &page backing this virtual address. +*/ +static inline netmem_ref virt_to_netmem (const void *data) +{ +return page_to_netmem (virt_to_page (data)); +} +static inline int netmem_ref_count (netmem_ref netmem) {/* The non-pp refcount of net_iov is always 1. On net_iov, we only
@@ -127,6 +154,22 @@ static inline struct net_iov *__netmem_creturn (struct net_iov *)((__force unsigned long )netmem & ~NET_IOV ); } +/** +* __netmem_get_pp - unsafely get pointer to the &page_pool backing @netmem +* @netmem: netmem reference to get the pointer from +* +* Unsafe version of netmem_get_pp(). When @netmem is always page-backed, +* e.g. when it's a header buffer, performs faster and generates smaller +* object code (avoids clearing the LSB). When @netmem points to IOV, +* provokes invalid memory access. +* +* Return: pointer to the &page_pool (garbage if @netmem is not page-backed). +*/ +static inline struct page_pool *__netmem_get_pp (netmem_ref netmem) +{ +return __netmem_to_page (netmem)->pp; +} +static inline struct page_pool *netmem_get_pp (netmem_ref netmem) {return __netmem_clear_lsb (netmem)->pp;
@@ -158,12 +201,43 @@ static inline netmem_ref netmem_compoundreturn page_to_netmem (compound_head (netmem_to_page (netmem))); } +/** +* __netmem_address - unsafely get pointer to the memory backing @netmem +* @netmem: netmem reference to get the pointer for +* +* Unsafe version of netmem_address(). When @netmem is always page-backed, +* e.g. when it's a header buffer, performs faster and generates smaller +* object code (no check for the LSB). When @netmem points to IOV, provokes +* undefined behaviour. +* +* Return: pointer to the memory (garbage if @netmem is not page-backed). +*/ +static inline void *__netmem_address (netmem_ref netmem) +{ +return page_address (__netmem_to_page (netmem)); +} +static inline void *netmem_address (netmem_ref netmem) {if (netmem_is_net_iov (netmem))return NULL ; -return page_address (netmem_to_page (netmem)); +return __netmem_address (netmem); +} + +/** +* netmem_is_pfmemalloc - check if @netmem was allocated under memory pressure +* @netmem: netmem reference to check +* +* Return: true if @netmem is page-backed and the page was allocated under +* memory pressure, false otherwise. +*/ +static inline bool netmem_is_pfmemalloc (netmem_ref netmem) +{ +if (netmem_is_net_iov (netmem)) +return false; + +return page_is_pfmemalloc (netmem_to_page (netmem)); }static inline unsigned long netmem_get_dma_addr (netmem_ref netmem)
Greg Kroah-Hartman
maintainerPATCH 756/877 net: page_pool: rename page_pool_alloc_netmem to *_netmems
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mina Almasry <[email protected]>
[ Upstream commit 91a152cbb49c26609d217cf2f116d46143b9b8be ]
page_pool_alloc_netmem (without an s) was the mirror of page_pool_alloc_pages (with an s), which was confusing.
Rename to page_pool_alloc_netmems so it's the mirror of page_pool_alloc_pages.
Stable-dep-of: b814dfbfeb0a ("bnxt_en: Propagate TPA buffer allocation failures in bnxt_queue_mem_alloc()")
--- include/net/page_pool/types.h | 2 +- net/core/page_pool.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-)
include/net/page_pool/types.h +1 -1
@@ -252,7 +252,7 @@ struct page_pool { };struct page *page_pool_alloc_pages (struct page_pool *pool,gfp_t gfp); -netmem_ref page_pool_alloc_netmem (struct page_pool *pool,gfp_t gfp); +netmem_ref page_pool_alloc_netmems (struct page_pool *pool,gfp_t gfp);struct page *page_pool_alloc_frag (struct page_pool *pool,unsigned int *offset,unsigned int size,gfp_t gfp); netmem_ref page_pool_alloc_frag_netmem(struct page_pool *pool,
net/core/page_pool.c +4 -4
@@ -673,7 +673,7 @@ static noinline netmem_ref __page_pool_a/* For using page_pool replace: alloc_pages() API calls, but provide * synchronization guarantee for allocation side. */ -netmem_ref page_pool_alloc_netmem (struct page_pool *pool,gfp_t gfp) +netmem_ref page_pool_alloc_netmems (struct page_pool *pool,gfp_t gfp) {netmem_ref netmem;
@@ -689,11 +689,11 @@ netmem_ref page_pool_alloc_netmem(struct netmem =__page_pool_alloc_pages_slow (pool, gfp);return netmem; } -EXPORT_SYMBOL (page_pool_alloc_netmem); +EXPORT_SYMBOL (page_pool_alloc_netmems);struct page *page_pool_alloc_pages (struct page_pool *pool,gfp_t gfp) { -return netmem_to_page (page_pool_alloc_netmem (pool, gfp)); +return netmem_to_page (page_pool_alloc_netmems (pool, gfp)); }EXPORT_SYMBOL (page_pool_alloc_pages);ALLOW_ERROR_INJECTION (page_pool_alloc_pages,NULL );
@@ -1051,7 +1051,7 @@ netmem_ref page_pool_alloc_frag_netmem(s }if (!netmem) { - netmem =page_pool_alloc_netmem (pool, gfp); + netmem =page_pool_alloc_netmems (pool, gfp);if (unlikely (!netmem)) { pool->frag_page =0 ;return 0 ;
Greg Kroah-Hartman
maintainerPATCH 757/877 page_pool: disable sync for cpu for dmabuf memory provider
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mina Almasry <[email protected]>
[ Upstream commit 7dba339faae991a23c54f7b93a58798c58f8c16f ]
dmabuf dma-addresses should not be dma_sync'd for CPU/device. Typically its the driver responsibility to dma_sync for CPU, but the driver should not dma_sync for CPU if the netmem is actually coming from a dmabuf memory provider.
The page_pool already exposes a helper for dma_sync_for_cpu:page_pool_dma_sync_for_cpu. Upgrade this existing helper to handle netmem, and have it skip dma_sync if the memory is from a dmabuf memory provider. Drivers should migrate to using this helper when adding support for netmem.
Also minimize the impact on the dma syncing performance for pages. Special case the dma-sync path for pages to not go through the overhead checks for dma-syncing and conversion to netmem.
Stable-dep-of: b814dfbfeb0a ("bnxt_en: Propagate TPA buffer allocation failures in bnxt_queue_mem_alloc()")
--- include/net/page_pool/helpers.h | 35 ++++++++++++++++++++++++++++++----- include/net/page_pool/types.h | 3 ++- net/core/devmem.c | 1 + net/core/page_pool.c | 1 + 4 files changed, 34 insertions(+), 6 deletions(-)
include/net/page_pool/helpers.h +30 -5
@@ -418,7 +418,21 @@ static inline dma_addr_t page_pool_get_d*/ static inline dma_addr_t page_pool_get_dma_addr (const struct page *page) { -return page_pool_get_dma_addr_netmem (page_to_netmem ((struct page *)page)); +dma_addr_t ret = page->dma_addr; + +if (PAGE_POOL_32BIT_ARCH_WITH_64BIT_DMA ) + ret <<=PAGE_SHIFT ; + +return ret; +} + +static inline void __page_pool_dma_sync_for_cpu (const struct page_pool *pool, +const dma_addr_t dma_addr, +u32 offset,u32 dma_sync_size) +{ +dma_sync_single_range_for_cpu (pool->p.dev, dma_addr, + offset + pool->p.offset, dma_sync_size, +page_pool_get_dma_dir (pool)); }/**
@@ -437,10 +451,21 @@ static inline void page_pool_dma_sync_foconst struct page *page, u32 offset, u32 dma_sync_size) { - dma_sync_single_range_for_cpu(pool->p.dev, -page_pool_get_dma_addr (page ), - offset + pool->p.offset, dma_sync_size, -page_pool_get_dma_dir (pool )); +__page_pool_dma_sync_for_cpu (pool ,page_pool_get_dma_addr (page ),offset , +dma_sync_size ); +} + +static inline void +page_pool_dma_sync_netmem_for_cpu (const struct page_pool *pool, +const netmem_ref netmem,u32 offset, +u32 dma_sync_size) +{ +if (!pool->dma_sync_for_cpu) +return ; + +__page_pool_dma_sync_for_cpu (pool, +page_pool_get_dma_addr_netmem (netmem), + offset, dma_sync_size); }static inline bool page_pool_put (struct page_pool *pool)
include/net/page_pool/types.h +2 -1
@@ -171,7 +171,8 @@ struct page_pool { bool has_init_callback:1; /* slow::init_callback is set */ bool dma_map:1; /* Perform DMA mapping */ - bool dma_sync:1; /* Perform DMA sync */ + bool dma_sync:1; /* Perform DMA sync for device */ + bool dma_sync_for_cpu:1; /* Perform DMA sync for cpu */#ifdef CONFIG_PAGE_POOL_STATS bool system:1; /* This is a global percpu pool */#endif
net/core/devmem.c +1 -0
@@ -343,6 +343,7 @@ int mp_dmabuf_devmem_init(struct page_po* dma_sync_for_cpu/device. Force disable dma_sync. */ pool->dma_sync = false; + pool->dma_sync_for_cpu = false;if (pool->p.order !=0 )return -E2BIG ;
net/core/page_pool.c +1 -0
@@ -203,6 +203,7 @@ static int page_pool_init(struct page_pomemcpy (&pool->slow, ¶ms->slow,sizeof (pool->slow)); pool->cpuid = cpuid; + pool->dma_sync_for_cpu = true;/* Validate only known flags were used */ if (pool->slow.flags & ~PP_FLAG_ALL )
Greg Kroah-Hartman
maintainerPATCH 758/877 bnxt_en: Propagate TPA buffer allocation failures in bnxt_queue_mem_alloc()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joe Damato <[email protected]>
[ Upstream commit b814dfbfeb0a68c9a52073f2caa05a2d5247a329 ]
bnxt_alloc_one_tpa_info_data() returns -ENOMEM as soon as one allocation fails. This leaves the remaining rxr->rx_tpa[] entries zeroed.
bnxt_queue_mem_alloc() discards that return value, so the partially initialized ring is installed by bnxt_queue_start().
Since the agg_id is picked by the hardware and bnxt_alloc_agg_idx maps it to a SW index in rxr->rx_tpa[], it is possible that an uninitialized slot can be chosen which would hand a zero DMA address to the device.
Fix this by checking the return value of bnxt_alloc_one_tpa_info_data and unwinding, freeing the ring buffers.
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +7 -2
@@ -15430,11 +15430,16 @@ static int bnxt_queue_mem_alloc(struct nbnxt_alloc_one_rx_ring_skb (bp, clone, idx);if (bp->flags &BNXT_FLAG_AGG_RINGS )bnxt_alloc_one_rx_ring_page (bp, clone, idx); -if (bp->flags &BNXT_FLAG_TPA ) -bnxt_alloc_one_tpa_info_data (bp, clone); +if (bp->flags &BNXT_FLAG_TPA ) { + rc =bnxt_alloc_one_tpa_info_data (bp, clone); +if (rc) + goto err_free_rx_ring_skbs; + }return 0 ; +err_free_rx_ring_skbs: +bnxt_free_one_rx_ring_skbs (bp, clone); err_free_tpa_info:bnxt_free_one_tpa_info (bp, clone); err_free_rx_agg_ring:
Greg Kroah-Hartman
maintainerPATCH 759/877 mptcp: pm: drop match in userspace_pm_append_new_local_addr
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Geliang Tang <[email protected]>
[ Upstream commit 640e3d69d0bc70d7d3de34800a1640793262bd08 ]
The variable 'match' in mptcp_userspace_pm_append_new_local_addr() is a redundant one, and this patch drops it.
No need to define 'match' as 'struct mptcp_pm_addr_entry *' type. In this function, it's only used to check whether it's NULL. It can be defined as a Boolean one.
Also other variables 'addr_match' and 'id_match' make 'match' a redundant one, which can be replaced by directly checking 'addr_match && id_match'.
Stable-dep-of: f9f0068e8813 ("mptcp: pm: userspace: fix address ID overflow")
--- net/mptcp/pm_userspace.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
net/mptcp/pm_userspace.c +3 -8
@@ -41,7 +41,6 @@ static int mptcp_userspace_pm_append_new bool needs_id) {DECLARE_BITMAP (id_bitmap,MPTCP_PM_MAX_ADDR_ID +1 ); -struct mptcp_pm_addr_entry *match =NULL ;struct sock *sk = (struct sock *)msk;struct mptcp_pm_addr_entry *e;bool addr_match = false;
@@ -60,16 +59,12 @@ static int mptcp_userspace_pm_append_newif (addr_match && entry->addr.id ==0 && needs_id) entry->addr.id = e->addr.id; id_match = (e->addr.id == entry->addr.id); -if (addr_match && id_match) { - match = e; +if (addr_match || id_match)break ; - }else if (addr_match || id_match) { -break ; - }__set_bit (e->addr.id, id_bitmap); } -if (!match && !addr_match && !id_match) { +if (!addr_match && !id_match) {/* Memory for the entry is allocated from the * sock option buffer. */
@@ -87,7 +82,7 @@ static int mptcp_userspace_pm_append_newlist_add_tail_rcu (&e->list, &msk->pm.userspace_pm_local_addr_list); msk->pm.local_addr_used++; ret = e->addr.id; - }else if (match) { + }else if (addr_match && id_match) { ret = entry->addr.id; }
Greg Kroah-Hartman
maintainerPATCH 760/877 sock: add sock_kmemdup helper
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Geliang Tang <[email protected]>
[ Upstream commit 456cc675b6d4cadd4872a477d8976ff56eef4b6f ]
This patch adds the sock version of kmemdup() helper, named sock_kmemdup(), to duplicate the input "src" memory block using the socket's option memory buffer.
Stable-dep-of: f9f0068e8813 ("mptcp: pm: userspace: fix address ID overflow")
--- include/net/sock.h | 2 ++ net/core/sock.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+)
include/net/sock.h +2 -0
@@ -1840,6 +1840,8 @@ static inline struct sk_buff *sock_alloc }void *sock_kmalloc (struct sock *sk,int size,gfp_t priority); +void *sock_kmemdup (struct sock *sk,const void *src, +int size,gfp_t priority);void sock_kfree_s (struct sock *sk,void *mem,int size);void sock_kzfree_s (struct sock *sk,void *mem,int size);void sk_send_sigurg (struct sock *sk);
net/core/sock.c +16 -0
@@ -2837,6 +2837,22 @@ void *sock_kmalloc(struct sock *sk, int }EXPORT_SYMBOL (sock_kmalloc); +/* +* Duplicate the input "src" memory block using the socket's +* option memory buffer. +*/ +void *sock_kmemdup (struct sock *sk,const void *src, +int size,gfp_t priority) +{ +void *mem; + + mem =sock_kmalloc (sk, size, priority); +if (mem) +memcpy (mem, src, size); +return mem; +} +EXPORT_SYMBOL (sock_kmemdup); +/* Free an option memory block. Note, we actually want the inline * here as this allows gcc to detect the nullify and fold away the * condition entirely.
Greg Kroah-Hartman
maintainerPATCH 761/877 mptcp: use sock_kmemdup for address entry
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Geliang Tang <[email protected]>
[ Upstream commit 52f83c0b5f857dbe24f66fc9a7f035523e9ffbc9 ]
Instead of using sock_kmalloc() to allocate an address entry "e" and then immediately duplicate the input "entry" to it, the newly added sock_kmemdup() helper can be used in mptcp_userspace_pm_append_new_local_addr() to simplify the code.
More importantly, the code "*e = *entry;" that assigns "entry" to "e" is not easy to implemented in BPF if we use the same code to implement an append_new_local_addr() helper of a BFP path manager. This patch avoids this type of memory assignment operation.
Stable-dep-of: f9f0068e8813 ("mptcp: pm: userspace: fix address ID overflow")
--- net/mptcp/pm_userspace.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
net/mptcp/pm_userspace.c +1 -2
@@ -68,13 +68,12 @@ static int mptcp_userspace_pm_append_new/* Memory for the entry is allocated from the * sock option buffer. */ - e =sock_kmalloc (sk,sizeof (*e),GFP_ATOMIC ); + e =sock_kmemdup (sk, entry,sizeof (*entry),GFP_ATOMIC );if (!e) { ret = -ENOMEM ; goto append_err; } - *e = *entry;if (!e->addr.id && needs_id) e->addr.id = find_next_zero_bit(id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1,
Greg Kroah-Hartman
maintainerPATCH 762/877 mptcp: pm: userspace: fix address ID overflow
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qing Luo <[email protected]>
[ Upstream commit f9f0068e8813d8c10d016b030fc3a320d0b6767c ]
When all MPTCP address IDs (1-255) are exhausted in the userspace PM, find_next_zero_bit() returns MPTCP_PM_MAX_ADDR_ID + 1 (256). This value overflows when stored in the u8 field e->addr.id, resulting in ID 0 being stored and the entry being incorrectly added to the list.
ID 0 is reserved for the initial connection in MPTCP, so this overflow can cause address conflicts.
Note: the in-kernel PM already has an 'endpoints == MPTCP_PM_MAX_ADDR_ID' check in mptcp_pm_nl_append_new_local_addr() that returns -ERANGE before reaching find_next_zero_bit(), preventing this overflow. So this fix only addresses the userspace PM path.
Check the find_next_zero_bit() result against MPTCP_PM_MAX_ADDR_ID and return -ENOSPC if all IDs are truly exhausted. Move the ID allocation check before the memory allocation so that the error path does not need to free the allocated entry.
--- net/mptcp/pm_userspace.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
net/mptcp/pm_userspace.c +14 -4
@@ -65,6 +65,19 @@ static int mptcp_userspace_pm_append_new }if (!addr_match && !id_match) { +unsigned int id; + +if (!entry->addr.id && needs_id) { + id =find_next_zero_bit (id_bitmap, +MPTCP_PM_MAX_ADDR_ID +1 ,1 ); +if (id >MPTCP_PM_MAX_ADDR_ID ) { + ret = -ENOSPC ; + goto append_err; + } + }else { + id = entry->addr.id; + } +/* Memory for the entry is allocated from the * sock option buffer. */
@@ -74,10 +87,7 @@ static int mptcp_userspace_pm_append_new goto append_err; } -if (!e->addr.id && needs_id) - e->addr.id =find_next_zero_bit (id_bitmap, -MPTCP_PM_MAX_ADDR_ID +1 , -1 ); + e->addr.id = id;list_add_tail_rcu (&e->list, &msk->pm.userspace_pm_local_addr_list); msk->pm.local_addr_used++; ret = e->addr.id;
Greg Kroah-Hartman
maintainerPATCH 763/877 bnxt_en: Do not set EOP on RX AGG BDs on 5760X chips
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Chan <[email protected]>
[ Upstream commit 30f253f8d9a01d532fdb7ec6c8a9d4c15fe29241 ]
With End-of-Packet padding (EOP) set, the chip will disable Relaxed Ordering (RO) of TPA data packets. A TPA segment with EOP set will be padded to the next cache boundary and can potentially overwrite the beginning bytes of the next TPA segment when RO is enabled on 5760X. To prevent that, the chip disables RO for TPA when EOP is set.
To take advantge of RO and higher performance, do not set EOP on 5760X chips when TPA is enabled. Define a proper RX_BD_FLAGS_AGG_EOP constant to make it clear that we are setting EOP.
Stable-dep-of: 5ce7f36c334d ("bnxt_en: Don't free the live ring's TPA state on queue restart failure")
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 9 ++++++++- drivers/net/ethernet/broadcom/bnxt/bnxt.h | 1 + 2 files changed, 9 insertions(+), 1 deletion(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +8 -1
@@ -4300,7 +4300,14 @@ static void bnxt_init_one_rx_agg_ring_rx ring->fw_ring_id =INVALID_HW_RING_ID ;if ((bp->flags &BNXT_FLAG_AGG_RINGS )) { type = ((u32 )BNXT_RX_PAGE_SIZE <<RX_BD_LEN_SHIFT ) | -RX_BD_TYPE_RX_AGG_BD |RX_BD_FLAGS_SOP ; +RX_BD_TYPE_RX_AGG_BD ; + +/* On P7, setting EOP will cause the chip to disable +* Relaxed Ordering (RO) for TPA data. Disable EOP for +* potentially higher performance with RO. +*/ +if (BNXT_CHIP_P5_AND_MINUS (bp) || !(bp->flags &BNXT_FLAG_TPA )) + type |=RX_BD_FLAGS_AGG_EOP ;bnxt_init_rxbd_pages (ring, type); }
drivers/net/ethernet/broadcom/bnxt/bnxt.h +1 -0
@@ -124,6 +124,7 @@ struct rx_bd {#define RX_BD_TYPE_48B_BD_SIZE (2 << 4)#define RX_BD_TYPE_64B_BD_SIZE (3 << 4)#define RX_BD_FLAGS_SOP (1 << 6) +#define RX_BD_FLAGS_AGG_EOP (1 << 6)#define RX_BD_FLAGS_EOP (1 << 7)#define RX_BD_FLAGS_BUFFERS (3 << 8)#define RX_BD_FLAGS_1_BUFFER_PACKET (0 << 8)
Greg Kroah-Hartman
maintainerPATCH 764/877 eth: bnxt: store rx buffer size per queue
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pavel Begunkov <[email protected]>
[ Upstream commit f57efb32aae1da5c0a25acf473ef4ab559894adf ]
Instead of using a constant buffer length, allow configuring the size for each queue separately. There is no way to change the length yet, and it'll be passed from memory providers in a later patch.
Stable adaptation for 6.12:
Keep the per-queue buffer size change using the existing page-based RX and XDP interfaces. Apply aggregation truesize accounting in bnxt_rx_agg_pages_skb(), and program the size in the existing firmware ring allocation path instead of adding the newer helper functions.
This tree has no unreadable netmem pools. Derive head-pool separation from the queue buffer size, keep head allocations at order zero, and use the same queue-specific decision for allocation and cleanup. Keep the existing pool sizing and NAPI association. Queue sizes start at BNXT_RX_PAGE_SIZE and are inherited by restart clones.
Initialize the clone's rx_agg_bmap to NULL to separate it from the live ring and provide the common initialization context needed to cherry-pick 5ce7f36c334d ("bnxt_en: Don't free the live ring's TPA state on queue restart failure") cleanly. The target's TPA pointer resets are left to that commit. No functions are added.
Stable-dep-of: 5ce7f36c334d ("bnxt_en: Don't free the live ring's TPA state on queue restart failure")
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 60 ++++++++++++++------------ drivers/net/ethernet/broadcom/bnxt/bnxt.h | 1 drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c | 6 +- drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.h | 2 4 files changed, 39 insertions(+), 30 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +34 -26
@@ -867,9 +867,9 @@ static void bnxt_tx_int(struct bnxt *bp, bnapi->events &= ~BNXT_TX_CMP_EVENT ; } -static bool bnxt_separate_head_pool (void ) +static bool bnxt_separate_head_pool (struct bnxt_rx_ring_info *rxr) { -return PAGE_SIZE >BNXT_RX_PAGE_SIZE ; +return rxr->rx_page_size !=PAGE_SIZE ; } static struct page *__bnxt_alloc_rx_page(struct bnxt *bp, dma_addr_t *mapping,
@@ -879,9 +879,9 @@ static struct page *__bnxt_alloc_rx_page {struct page *page; -if (PAGE_SIZE >BNXT_RX_PAGE_SIZE ) { +if (rxr->rx_page_size <PAGE_SIZE ) { page =page_pool_dev_alloc_frag (rxr->page_pool, offset, -BNXT_RX_PAGE_SIZE ); + rxr->rx_page_size); }else { page =page_pool_dev_alloc_pages (rxr->page_pool); *offset =0 ;
@@ -1101,9 +1101,9 @@ static struct sk_buff *bnxt_rx_multi_pagreturn NULL ; } dma_addr -= bp->rx_dma_offset; -dma_sync_single_for_cpu (&bp->pdev->dev, dma_addr,BNXT_RX_PAGE_SIZE , +dma_sync_single_for_cpu (&bp->pdev->dev, dma_addr, rxr->rx_page_size, bp->rx_dir); - skb =napi_build_skb (data_ptr - bp->rx_offset,BNXT_RX_PAGE_SIZE ); + skb =napi_build_skb (data_ptr - bp->rx_offset, rxr->rx_page_size);if (!skb) {page_pool_recycle_direct (rxr->page_pool, page);return NULL ;
@@ -1135,7 +1135,7 @@ static struct sk_buff *bnxt_rx_page_skb(return NULL ; } dma_addr -= bp->rx_dma_offset; -dma_sync_single_for_cpu (&bp->pdev->dev, dma_addr,BNXT_RX_PAGE_SIZE , +dma_sync_single_for_cpu (&bp->pdev->dev, dma_addr, rxr->rx_page_size, bp->rx_dir);if (unlikely (!payload))
@@ -1149,7 +1149,7 @@ static struct sk_buff *bnxt_rx_page_skb(skb_mark_for_recycle (skb); off = (void *)data_ptr -page_address (page); -skb_add_rx_frag (skb,0 , page, off, len,BNXT_RX_PAGE_SIZE ); +skb_add_rx_frag (skb,0 , page, off, len, rxr->rx_page_size);memcpy (skb->data -NET_IP_ALIGN , data_ptr -NET_IP_ALIGN , payload +NET_IP_ALIGN );
@@ -1253,7 +1253,7 @@ static u32 __bnxt_rx_agg_pages(struct bnreturn 0 ; } -dma_sync_single_for_cpu (&pdev->dev, mapping,BNXT_RX_PAGE_SIZE , +dma_sync_single_for_cpu (&pdev->dev, mapping, rxr->rx_page_size, bp->rx_dir); total_frag_len += frag_len;
@@ -1268,6 +1268,7 @@ static struct sk_buff *bnxt_rx_agg_pages struct sk_buff *skb, u16 idx, u32 agg_bufs, bool tpa) { + struct bnxt_rx_ring_info *rxr = cpr->bnapi->rx_ring;struct skb_shared_info *shinfo =skb_shinfo (skb);u32 total_frag_len =0 ;
@@ -1281,7 +1282,7 @@ static struct sk_buff *bnxt_rx_agg_pages skb->data_len += total_frag_len; skb->len += total_frag_len; - skb->truesize +=BNXT_RX_PAGE_SIZE * agg_bufs; + skb->truesize += rxr->rx_page_size * agg_bufs;return skb; }
@@ -2222,8 +2223,7 @@ static int bnxt_rx_pkt(struct bnxt *bp,if (!skb) goto oom_next_rx; }else { - skb =bnxt_xdp_build_skb (bp, skb, agg_bufs, - rxr->page_pool, &xdp); + skb =bnxt_xdp_build_skb (bp, skb, agg_bufs, rxr, &xdp);if (!skb) {/* we should be able to free the old skb here */ bnxt_xdp_buff_frags_free (rxr, &xdp);
@@ -3647,7 +3647,7 @@ static void bnxt_free_rx_rings(struct bnxdp_rxq_info_unreg (&rxr->xdp_rxq);page_pool_destroy (rxr->page_pool); -if (bnxt_separate_head_pool ()) +if (bnxt_separate_head_pool (rxr))page_pool_destroy (rxr->head_pool); rxr->page_pool = rxr->head_pool =NULL ;
@@ -3672,12 +3672,14 @@ static int bnxt_alloc_rx_page_pool(struc pp.pool_size = bp->rx_agg_ring_size;if (BNXT_RX_PAGE_MODE (bp)) pp.pool_size += bp->rx_ring_size; + + pp.order =get_order (rxr->rx_page_size); pp.nid = numa_node; pp.napi = &rxr->bnapi->napi; pp.netdev = bp->dev; pp.dev = &bp->pdev->dev; pp.dma_dir = bp->rx_dir; - pp.max_len =PAGE_SIZE ; + pp.max_len =PAGE_SIZE << pp.order; pp.flags =PP_FLAG_DMA_MAP |PP_FLAG_DMA_SYNC_DEV ; pool =page_pool_create (&pp);
@@ -3685,7 +3687,9 @@ static int bnxt_alloc_rx_page_pool(strucreturn PTR_ERR (pool); rxr->page_pool = pool; -if (bnxt_separate_head_pool ()) { +if (bnxt_separate_head_pool (rxr)) { + pp.order =0 ; + pp.max_len =PAGE_SIZE ; pp.pool_size =max (bp->rx_ring_size,1024 ); pool =page_pool_create (&pp);if (IS_ERR (pool))
@@ -4140,6 +4144,8 @@ static void bnxt_init_ring_struct(structif (!rxr) goto skip_rx; + rxr->rx_page_size =BNXT_RX_PAGE_SIZE ; + ring = &rxr->rx_ring_struct; rmem = &ring->ring_mem; rmem->nr_pages = bp->rx_nr_pages;
@@ -4299,7 +4305,7 @@ static void bnxt_init_one_rx_agg_ring_rx ring = &rxr->rx_agg_ring_struct; ring->fw_ring_id =INVALID_HW_RING_ID ;if ((bp->flags &BNXT_FLAG_AGG_RINGS )) { - type = ((u32 )BNXT_RX_PAGE_SIZE <<RX_BD_LEN_SHIFT ) | + type = ((u32 )rxr->rx_page_size <<RX_BD_LEN_SHIFT ) |RX_BD_TYPE_RX_AGG_BD ;/* On P7, setting EOP will cause the chip to disable
@@ -6865,6 +6871,7 @@ static void bnxt_hwrm_ring_grp_free(stru }static int hwrm_ring_alloc_send_msg (struct bnxt *bp, +struct bnxt_rx_ring_info *rxr,struct bnxt_ring_struct *ring,u32 ring_type,u32 map_index) {
@@ -6937,7 +6944,7 @@ static int hwrm_ring_alloc_send_msg(stru/* Association of agg ring with rx ring */ grp_info = &bp->grp_info[ring->grp_idx]; req->rx_ring_id =cpu_to_le16 (grp_info->rx_fw_ring_id); - req->rx_buf_size =cpu_to_le16 (BNXT_RX_PAGE_SIZE ); + req->rx_buf_size =cpu_to_le16 (rxr->rx_page_size); req->stat_ctx_id =cpu_to_le32 (grp_info->fw_stats_ctx); req->enables |= cpu_to_le32( RING_ALLOC_REQ_ENABLES_RX_RING_ID_VALID |
@@ -7093,7 +7100,7 @@ static int bnxt_hwrm_rx_ring_alloc(strucu32 map_idx = bnapi->index;int rc; - rc =hwrm_ring_alloc_send_msg (bp, ring, type, map_idx); + rc =hwrm_ring_alloc_send_msg (bp, rxr, ring, type, map_idx);if (rc)return rc;
@@ -7113,7 +7120,7 @@ static int bnxt_hwrm_rx_agg_ring_alloc(sint rc; map_idx = grp_idx + bp->rx_nr_rings; - rc =hwrm_ring_alloc_send_msg (bp, ring, type, map_idx); + rc =hwrm_ring_alloc_send_msg (bp, rxr, ring, type, map_idx);if (rc)return rc;
@@ -7145,7 +7152,7 @@ static int bnxt_hwrm_ring_alloc(struct b vector = bp->irq_tbl[map_idx].vector;disable_irq_nosync (vector); - rc =hwrm_ring_alloc_send_msg (bp, ring, type, map_idx); + rc =hwrm_ring_alloc_send_msg (bp,NULL , ring, type, map_idx);if (rc) {enable_irq (vector); goto err_out;
@@ -7176,7 +7183,7 @@ static int bnxt_hwrm_ring_alloc(struct b ring = &cpr2->cp_ring_struct; ring->handle =BNXT_SET_NQ_HDL (cpr2); map_idx = bnapi->index; - rc =hwrm_ring_alloc_send_msg (bp, ring, type2, map_idx); + rc =hwrm_ring_alloc_send_msg (bp,NULL , ring, type2, map_idx);if (rc) goto err_out; bnxt_set_db(bp, &cpr2->cp_db, type2, map_idx,
@@ -7185,7 +7192,7 @@ static int bnxt_hwrm_ring_alloc(struct b } ring = &txr->tx_ring_struct; map_idx = i; - rc =hwrm_ring_alloc_send_msg (bp, ring, type, map_idx); + rc =hwrm_ring_alloc_send_msg (bp,NULL , ring, type, map_idx);if (rc) goto err_out;bnxt_set_db (bp, &txr->tx_db, type, map_idx, ring->fw_ring_id);
@@ -7209,7 +7216,7 @@ static int bnxt_hwrm_ring_alloc(struct b ring = &cpr2->cp_ring_struct; ring->handle =BNXT_SET_NQ_HDL (cpr2); - rc =hwrm_ring_alloc_send_msg (bp, ring, type2, map_idx); + rc =hwrm_ring_alloc_send_msg (bp,NULL , ring, type2, map_idx);if (rc) goto err_out; bnxt_set_db(bp, &cpr2->cp_db, type2, map_idx,
@@ -15394,6 +15401,7 @@ static int bnxt_queue_mem_alloc(struct n clone->rx_agg_prod =0 ; clone->rx_sw_agg_prod =0 ; clone->rx_next_cons =0 ; + clone->rx_agg_bmap =NULL ; rc =bnxt_alloc_rx_page_pool (bp, clone, rxr->page_pool->p.nid);if (rc)
@@ -15457,7 +15465,7 @@ err_rxq_info_unreg:xdp_rxq_info_unreg (&clone->xdp_rxq); err_page_pool_destroy:page_pool_destroy (clone->page_pool); -if (bnxt_separate_head_pool ()) +if (bnxt_separate_head_pool (clone))page_pool_destroy (clone->head_pool); clone->page_pool =NULL ; clone->head_pool =NULL ;
@@ -15476,7 +15484,7 @@ static void bnxt_queue_mem_free(struct nxdp_rxq_info_unreg (&rxr->xdp_rxq);page_pool_destroy (rxr->page_pool); -if (bnxt_separate_head_pool ()) +if (bnxt_separate_head_pool (rxr))page_pool_destroy (rxr->head_pool); rxr->page_pool =NULL ; rxr->head_pool =NULL ;
@@ -15620,7 +15628,7 @@ static int bnxt_queue_stop(struct net_debnxt_hwrm_rx_agg_ring_free (bp, rxr, false); rxr->rx_next_cons =0 ;page_pool_disable_direct_recycling (rxr->page_pool); -if (bnxt_separate_head_pool ()) +if (bnxt_separate_head_pool (rxr))page_pool_disable_direct_recycling (rxr->head_pool);memcpy (qmem, rxr,sizeof (*rxr));
drivers/net/ethernet/broadcom/bnxt/bnxt.h +1 -0
@@ -1098,6 +1098,7 @@ struct bnxt_rx_ring_info {unsigned long *rx_agg_bmap;u16 rx_agg_bmap_size; +u32 rx_page_size;dma_addr_t rx_desc_mapping[MAX_RX_PAGES ];dma_addr_t rx_agg_desc_mapping[MAX_RX_AGG_PAGES ];
drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c +3 -3
@@ -182,7 +182,7 @@ void bnxt_xdp_buff_init(struct bnxt *bp, u16 cons, u8 *data_ptr, unsigned int len, struct xdp_buff *xdp) { - u32 buflen = BNXT_RX_PAGE_SIZE; + u32 buflen = rxr->rx_page_size;struct bnxt_sw_rx_bd *rx_buf;struct pci_dev *pdev;dma_addr_t mapping;
@@ -454,7 +454,7 @@ int bnxt_xdp(struct net_device *dev, strstruct sk_buff *bnxt_xdp_build_skb (struct bnxt *bp,struct sk_buff *skb,u8 num_frags, -struct page_pool *pool,struct xdp_buff *xdp) +struct bnxt_rx_ring_info *rxr,struct xdp_buff *xdp) {struct skb_shared_info *sinfo =xdp_get_shared_info_from_buff (xdp);
@@ -463,7 +463,7 @@ bnxt_xdp_build_skb(struct bnxt *bp, struxdp_update_skb_shared_info (skb, num_frags, sinfo->xdp_frags_size, -BNXT_RX_PAGE_SIZE * num_frags, + rxr->rx_page_size * num_frags,xdp_buff_is_frag_pfmemalloc (xdp));return skb; }
drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.h +1 -1
@@ -32,6 +32,6 @@ void bnxt_xdp_buff_init(struct bnxt *bp,void bnxt_xdp_buff_frags_free (struct bnxt_rx_ring_info *rxr,struct xdp_buff *xdp);struct sk_buff *bnxt_xdp_build_skb (struct bnxt *bp,struct sk_buff *skb, -u8 num_frags,struct page_pool *pool, +u8 num_frags,struct bnxt_rx_ring_info *rxr,struct xdp_buff *xdp);#endif
Greg Kroah-Hartman
maintainerPATCH 765/877 bnxt: fix memory leak in bnxt_queue_mem_alloc error cases
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Chen <[email protected]>
[ Upstream commit d1000fd7995e51deec872d154e0a40d82f7a539f ]
There is a small memory leak in bnxt_queue_mem_alloc:
when bnxt_alloc_rx_agg_bmap() succeeds
but bnxt_alloc_one_tpa_info() later fails, the rx_agg_bmap allocated by bnxt_alloc_rx_agg_bmap() is not freed in the fallthrough cleanup cases.
Free the rx_agg_bmap in the err_free_rx_agg_ring case and initialize clone->rx_agg_bmap = NULL earlier in the function to allow for safe fallthrough.
Stable adaptation for 6.12:
The preceding per-queue buffer-size backport already initializes the clone's rx_agg_bmap to NULL. Retain that initialization and apply the missing bitmap cleanup to err_free_rx_agg_ring. This frees the clone's bitmap when TPA allocation fails, while earlier allocation failures can safely fall through with a NULL bitmap.
Keep the existing queue allocation interface and inherited RX page
size: this tree has neither qcfg nor need_head_pool. Leave the TPA pointer resets to target commit 5ce7f36c334d. No functions are added.
Stable-dep-of: 5ce7f36c334d ("bnxt_en: Don't free the live ring's TPA state on queue restart failure")
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +2 -0
@@ -15459,6 +15459,8 @@ err_free_tpa_info:bnxt_free_one_tpa_info (bp, clone); err_free_rx_agg_ring:bnxt_free_ring (bp, &clone->rx_agg_ring_struct.ring_mem); +kfree (clone->rx_agg_bmap); + clone->rx_agg_bmap =NULL ; err_free_rx_ring:bnxt_free_ring (bp, &clone->rx_ring_struct.ring_mem); err_rxq_info_unreg:
Greg Kroah-Hartman
maintainerPATCH 766/877 bnxt_en: Dont free the live rings TPA state on queue restart failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joe Damato <[email protected]>
[ Upstream commit 5ce7f36c334d723954855ac769ede2fe0e8f89c8 ]
bnxt_queue_mem_alloc() shallow copies the live RX ring into the clone:
memcpy(clone, rxr, sizeof(*rxr));
the code currently clears pointers that the clone owns (such as rx_agg_bmap), but rx_tpa and rx_tpa_idx_map are left pointing at memory of the live ring that was cloned.
If an allocation failure happens later and the err_free_tpa_info label is taken, the live ring's memory can be freed while still in use.
Fix this by initializing the clone's pointers to NULL to prevent live ring state from being freed inadvertently.
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +2 -0
@@ -15402,6 +15402,8 @@ static int bnxt_queue_mem_alloc(struct n clone->rx_sw_agg_prod =0 ; clone->rx_next_cons =0 ; clone->rx_agg_bmap =NULL ; + clone->rx_tpa =NULL ; + clone->rx_tpa_idx_map =NULL ; rc =bnxt_alloc_rx_page_pool (bp, clone, rxr->page_pool->p.nid);if (rc)
Greg Kroah-Hartman
maintainerPATCH 767/877 mptcp: pm: reset retrans_time when ADD_ADDR entry is reused
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Matthieu Baerts (NGI0)" <[email protected]>
[ Upstream commit f968190c0b42ea2004dc1426359a53ec365a7a37 ]
When an ADD_ADDR entry is reused, the timer is re-armed, because the goal is to re-announce an ADD_ADDR, and eventually retransmit it if needed.
In this case, the retransmission counter should be reset as well, so the re-announced address gets its retransmissions back instead of relying on what was left before, and possibly not being able to retransmit it.
--- net/mptcp/pm_netlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/mptcp/pm_netlink.c +1 -1
@@ -417,10 +417,10 @@ bool mptcp_pm_alloc_anno_list(struct mpt add_entry->addr = *addr; add_entry->sock = msk; - add_entry->retrans_times =0 ;timer_setup (&add_entry->add_timer, mptcp_pm_add_timer,0 ); reset_timer: + add_entry->retrans_times =0 ; add_entry->timer_done = false; timeout =mptcp_get_add_addr_timeout (net);if (timeout)
Greg Kroah-Hartman
maintainerPATCH 768/877 mptcp: pm: use for_each_subflow helper
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Matthieu Baerts (NGI0)" <[email protected]>
[ Upstream commit f81689172429885d6c2c7c3dd4926ec626e794bb ]
Similar to most places in the MPTCP code. So instead of passing the subflow list and use list_for_each_entry(subflow, list, node), pass the msk and use mptcp_for_each_subflow(msk, subflow).
That's clearer and more uniform with the rest.
While at it, add 'pm_' prefix for the exported one to easily identify the origin. Plus replace 'lookup' by 'has', because a bool is returned.
Stable backport adaptation for 2ac7d6e620764f1fc79eb4edd3610a7a661981ca:
The stable tree keeps both subflow lookups and their callers in pm_netlink.c. Apply the iterator conversion there, retaining private helpers and using has_subflow_saddr() for the source-address lookup. Drop the upstream pm.c, pm_userspace.c and protocol.h hunks, which assume helper moves and a userspace callback not present on this branch.
Rename pm_netlink.c to pm_kernel.c and update the Makefile so the target patch finds its existing ID0 removal function at the upstream path. Rename the existing remove_anno_list_by_saddr() and mptcp_pm_nl_rm_subflow_received() helpers to mptcp_pm_announced_remove() and mptcp_pm_rm_subflow(), updating all callers, to provide the target's helper name and patch context. Keep their stable implementations and static linkage. No functions are added and the ID0 fix itself remains for the target commit.
[ sashal: Reduced backport -- upstream f816891724298 touches 4 file(s), this
backport carries 2. Not backported here:
net/mptcp/pm.c
net/mptcp/pm_userspace.c
net/mptcp/protocol.h
This note is generated from the file lists only; see the resolution record for the reasoning. ]
Stable-dep-of: 2ac7d6e62076 ("mptcp: pm: kernel: drop pending ADD_ADDR when removing ID0")
---
net/mptcp/Makefile | 2
net/mptcp/pm_kernel.c | 2602 ++++++++++++++++++++++++++++++++++++++++++++++++
net/mptcp/pm_netlink.c | 2603 -------------------------------------------------
3 files changed, 2603 insertions(+), 2604 deletions(-)
rename net/mptcp/{pm_netlink.c => pm_kernel.c} (98%)net/mptcp/Makefile +1 -1
@@ -2,7 +2,7 @@ obj-$(CONFIG_MPTCP) += mptcp.o mptcp-y := protocol.o subflow.o options.o token.o crypto.o ctrl.o pm.o diag.o \ - mib.o pm_netlink.o sockopt.o pm_userspace.o fastopen.o sched.o \ + mib.o pm_kernel.o sockopt.o pm_userspace.o fastopen.o sched.o \ mptcp_pm_gen.o obj-$(CONFIG_SYN_COOKIES) += syncookies.o
net/mptcp/pm_kernel.c new file +2602 -0
2,602 lines not on this page · raw message
net/mptcp/pm_netlink.c deleted +0 -2603
390 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
Greg Kroah-Hartman
maintainerPATCH 769/877 mptcp: pm: rename add_entry structure to add_addr
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Matthieu Baerts (NGI0)" <[email protected]>
[ Upstream commit 350d76dd6e79468ac85767f2d236299a135572df ]
Using only the 'add' prefix is confusing: does it refer to a generic added entry or address, or specifically to ADD_ADDRs. Using add_addr removes this confusion.
Stable backport adaptation for 2ac7d6e620764f1fc79eb4edd3610a7a661981ca:
The stable tree retains the ADD_ADDR announcement structure and helpers in pm_kernel.c, renamed from pm_netlink.c by the preceding dependency. Apply the structure-tag rename to those existing definitions and users instead of importing the upstream helper block into pm.c.
Update both return-type declarations in protocol.h: the announcement lookup is still externally visible on this branch. Preserve the stable function bodies, timer APIs, allocation APIs and linkage; no functions are added. The target's ID0 removal hunks apply unchanged to pm_kernel.c.
[ sashal: Reduced backport -- upstream 350d76dd6e794 touches 2 file(s), this
backport carries 2. Not backported here:
net/mptcp/pm.c
This note is generated from the file lists only; see the resolution record for the reasoning. ]
Stable-dep-of: 2ac7d6e62076 ("mptcp: pm: kernel: drop pending ADD_ADDR when removing ID0")
--- net/mptcp/pm_kernel.c | 20 ++++++++++---------- net/mptcp/protocol.h | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-)
net/mptcp/pm_kernel.c +10 -10
@@ -18,7 +18,7 @@static int pm_nl_pernet_id; -struct mptcp_pm_add_entry { +struct mptcp_pm_add_addr {struct list_head list;struct mptcp_addr_info addr;u8 retrans_times;
@@ -253,11 +253,11 @@ bool mptcp_pm_nl_check_work_pending(strureturn true; } -struct mptcp_pm_add_entry * +struct mptcp_pm_add_addr *mptcp_lookup_anno_list_by_saddr (const struct mptcp_sock *msk,const struct mptcp_addr_info *addr) { -struct mptcp_pm_add_entry *entry; +struct mptcp_pm_add_addr *entry;lockdep_assert_held (&msk->pm.lock);
@@ -271,7 +271,7 @@ mptcp_lookup_anno_list_by_saddr(const stbool mptcp_pm_sport_in_anno_list (struct mptcp_sock *msk,const struct sock *sk) { -struct mptcp_pm_add_entry *entry; +struct mptcp_pm_add_addr *entry;struct mptcp_addr_info saddr;bool ret = false;
@@ -292,7 +292,7 @@ out:static void mptcp_pm_add_timer (struct timer_list *timer) { -struct mptcp_pm_add_entry *entry =from_timer (entry, timer, add_timer); +struct mptcp_pm_add_addr *entry =from_timer (entry, timer, add_timer);struct mptcp_sock *msk = entry->sock;struct sock *sk = (struct sock *)msk;unsigned int timeout =0 ;
@@ -353,11 +353,11 @@ out:sock_put (sk); } -struct mptcp_pm_add_entry * +struct mptcp_pm_add_addr *mptcp_pm_del_add_timer (struct mptcp_sock *msk,const struct mptcp_addr_info *addr,bool check_id) { -struct mptcp_pm_add_entry *entry; +struct mptcp_pm_add_addr *entry;struct sock *sk = (struct sock *)msk;bool stop_timer = false;
@@ -390,7 +390,7 @@ mptcp_pm_del_add_timer(struct mptcp_sockbool mptcp_pm_alloc_anno_list (struct mptcp_sock *msk,const struct mptcp_addr_info *addr) { -struct mptcp_pm_add_entry *add_entry =NULL ; +struct mptcp_pm_add_addr *add_entry =NULL ;struct sock *sk = (struct sock *)msk;struct net *net =sock_net (sk);unsigned int timeout;
@@ -431,7 +431,7 @@ reset_timer:void mptcp_pm_free_anno_list (struct mptcp_sock *msk) { -struct mptcp_pm_add_entry *entry, *tmp; +struct mptcp_pm_add_addr *entry, *tmp;struct sock *sk = (struct sock *)msk;LIST_HEAD (free_list);
@@ -1575,7 +1575,7 @@ out_free:static bool mptcp_pm_announced_remove (struct mptcp_sock *msk,const struct mptcp_addr_info *addr) { -struct mptcp_pm_add_entry *entry; +struct mptcp_pm_add_addr *entry; entry =mptcp_pm_del_add_timer (msk, addr, false);if (entry) {
net/mptcp/protocol.h +2 -2
@@ -1049,10 +1049,10 @@ bool mptcp_pm_alloc_anno_list(struct mpt const struct mptcp_addr_info *addr);void mptcp_pm_free_anno_list (struct mptcp_sock *msk);bool mptcp_pm_sport_in_anno_list (struct mptcp_sock *msk,const struct sock *sk); -struct mptcp_pm_add_entry * +struct mptcp_pm_add_addr *mptcp_pm_del_add_timer (struct mptcp_sock *msk,const struct mptcp_addr_info *addr,bool check_id); -struct mptcp_pm_add_entry * +struct mptcp_pm_add_addr *mptcp_lookup_anno_list_by_saddr (const struct mptcp_sock *msk,const struct mptcp_addr_info *addr);int mptcp_pm_set_flags (struct sk_buff *skb,struct genl_info *info);
Greg Kroah-Hartman
maintainerPATCH 770/877 mptcp: pm: kernel: drop pending ADD_ADDR when removing ID0
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kalpan Jani <[email protected]>
[ Upstream commit 2ac7d6e620764f1fc79eb4edd3610a7a661981ca ]
The in-kernel MPTCP path manager can leave a stale ADD_ADDR announcement entry alive when removing the id 0 endpoint. This happens because the id 0 removal path does not tear down pending announcements, unlike the non-zero id path.
When the PM later reselects id 0 after adding another signal endpoint, it finds the stale anno_list entry and hits WARN_ON_ONCE(mptcp_pm_is_kernel()) in mptcp_pm_announced_alloc().
Root cause: asymmetry between removal paths.
- Non-zero id path: mptcp_nl_remove_subflow_and_signal_addr() calls mptcp_pm_remove_announced() to clean up.
- Id 0 path: mptcp_nl_remove_id_zero_address() skips cleanup entirely.
Fix by making the id 0 path symmetric: call mptcp_pm_announced_remove() and decrement add_addr_signaled before queuing the RM_ADDR.
Subtle detail: signal endpoints are stored in anno_list with port 0, but msk_local carries the connection's local port. In other words, entries linked to ID0 paths should have port == 0. A follow-up patch will ensure that. mptcp_pm_announced_remove() uses use_port=true for comparison. So clear the port before the lookup.
--- net/mptcp/pm_kernel.c | 8 ++++++++ 1 file changed, 8 insertions(+)
net/mptcp/pm_kernel.c +8 -0
@@ -1677,6 +1677,8 @@ static int mptcp_nl_remove_id_zero_addrewhile ((msk =mptcp_token_iter_next (net, &s_slot, &s_num)) !=NULL ) {struct sock *sk = (struct sock *)msk;struct mptcp_addr_info msk_local; +struct mptcp_addr_info anno_addr; +bool announced;if (list_empty (&msk->conn_list) ||mptcp_pm_is_userspace (msk)) goto next;
@@ -1686,7 +1688,13 @@ static int mptcp_nl_remove_id_zero_addre goto next;lock_sock (sk); +/* Drop a possibly pending ADD_ADDR for this address. */ + anno_addr = msk_local; + anno_addr.port =0 ; + announced =mptcp_pm_announced_remove (msk, &anno_addr);spin_lock_bh (&msk->pm.lock); +if (announced) + msk->pm.add_addr_signaled--;mptcp_pm_remove_addr (msk, &list);mptcp_pm_rm_subflow (msk, &list);__mark_subflow_endp_available (msk,0 );
Greg Kroah-Hartman
maintainerPATCH 771/877 tcp: introduce icsk->icsk_keepalive_timer
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 08dfe370239e53494453cee1e2ded2cdaa1efd12 ]
sk->sk_timer has been used for TCP keepalives.
Keepalive timers are not in fast path, we want to use sk->sk_timer storage for retransmit timers, for better cache locality.
Create icsk->icsk_keepalive_timer and change keepalive code to no longer use sk->sk_timer.
Added space is reclaimed in the following patch.
This includes changes to MPTCP, which was also using sk_timer.
Alias icsk->mptcp_tout_timer and icsk->icsk_keepalive_timer for inet_sk_diag_fill() sake.
Stable dependency adaptation for e2ab913f68c7d11e2561b8a8ad0b87ffefcad667:
Retain the 6.12 from_timer() API, icsk_timeout fields, documentation format and existing inet_csk_{reset,delete}_keepalive_timer() helpers. Convert the DCCP keepalive callback as well, since DCCP still shares the inet_csk timer initialization on this branch. Do not add TCP-only timer helper functions from newer kernels.
Include the MPTCP portion of 9a5e5334adc03: alias sk_timer storage as mptcp_retransmit_timer and migrate every MPTCP retransmit timer user. TCP and DCCP retain their existing icsk_retransmit_timer storage.
Adapt the fallback accounting preparation from c65c2e3bae69, authored by Paolo Abeni. Move the existing __mptcp_try_fallback() from protocol.h to protocol.c, pass its fallback MIB through the existing callers, and add the matching counters. Preserve the mptcp_subflow_early_fallback() name and use the stable simultaneous-connect and blackhole fallback paths. This supplies the fallback-helper context expected by the target.
No new functions are introduced. The target's RTX enable-bit fix remains in the target commit; this dependency only prepares its application.
Stable-dep-of: e2ab913f68c7 ("mptcp: do not reschedule the RTX timer for fallback sockets")
--- Documentation/networking/net_cachelines/inet_connection_sock.rst | 1 include/net/inet_connection_sock.h | 11 + include/net/sock.h | 6 net/dccp/timer.c | 4 net/ipv4/inet_connection_sock.c | 10 - net/ipv4/inet_diag.c | 4 net/ipv4/tcp_ipv4.c | 4 net/ipv4/tcp_timer.c | 5 net/ipv6/tcp_ipv6.c | 4 net/mptcp/ctrl.c | 4 net/mptcp/mib.c | 5 net/mptcp/mib.h | 5 net/mptcp/options.c | 6 net/mptcp/protocol.c | 70 +++++----- net/mptcp/protocol.h | 31 +--- net/mptcp/subflow.c | 10 - tools/testing/selftests/bpf/progs/bpf_iter_tcp4.c | 4 tools/testing/selftests/bpf/progs/bpf_iter_tcp6.c | 4 18 files changed, 107 insertions(+), 81 deletions(-)
Documentation/networking/net_cachelines/inet_connection_sock.rst +1 -0
@@ -14,6 +14,7 @@ struct_inet_bind2_bucket icsk unsigned_long icsk_timeout read_mostly - inet_csk_reset_xmit_timer,tcp_connect struct_timer_list icsk_retransmit_timer read_mostly - inet_csk_reset_xmit_timer,tcp_connect struct_timer_list icsk_delack_timer read_mostly - inet_csk_reset_xmit_timer,tcp_connect +struct_timer_list icsk_keepalive_timer - - u32 icsk_rto read_write - tcp_cwnd_validate,tcp_schedule_loss_probe,tcp_connect_init,tcp_connect,tcp_write_xmit,tcp_push_one u32 icsk_rto_min - - u32 icsk_delack_max - -
include/net/inet_connection_sock.h +9 -2
@@ -62,6 +62,9 @@ struct inet_connection_sock_af_ops {* @icsk_bind2_hash: Bind node in the bhash2 table * @icsk_timeout: Timeout * @icsk_retransmit_timer: Resend (no ack) +* @icsk_delack_timer: Delayed ACK timer +* @icsk_keepalive_timer: Keepalive timer +* @mptcp_tout_timer: MPTCP timeout timer * @icsk_rto: Retransmit timeout * @icsk_pmtu_cookie Last pmtu seen by socket * @icsk_ca_ops Pluggable congestion control hook
@@ -88,8 +91,12 @@ struct inet_connection_sock {struct inet_bind_bucket *icsk_bind_hash;struct inet_bind2_bucket *icsk_bind2_hash;unsigned long icsk_timeout; -struct timer_list icsk_retransmit_timer; -struct timer_list icsk_delack_timer; +struct timer_list icsk_retransmit_timer; +struct timer_list icsk_delack_timer; +union { +struct timer_list icsk_keepalive_timer; +struct timer_list mptcp_tout_timer; + };__u32 icsk_rto;__u32 icsk_rto_min;__u32 icsk_delack_max;
include/net/sock.h +5 -1
@@ -300,6 +300,7 @@ struct sk_filter;* @sk_txrehash: enable TX hash rethink * @sk_filter: socket filtering instructions * @sk_timer: sock cleanup timer +* @mptcp_retransmit_timer: MPTCP retransmit timer * @sk_stamp: time stamp of last packet received * @sk_stamp_seq: lock for accessing sk_stamp on 32 bit architectures only * @sk_tsflags: SO_TIMESTAMPING flags
@@ -465,7 +466,10 @@ struct sock {u32 sk_dst_pending_confirm;u32 sk_pacing_status;/* see enum sk_pacing */ struct page_frag sk_frag; -struct timer_list sk_timer; +union { +struct timer_list sk_timer; +struct timer_list mptcp_retransmit_timer; + };unsigned long sk_pacing_rate;/* bytes per second */ atomic_t sk_zckey;
net/dccp/timer.c +3 -1
@@ -160,7 +160,9 @@ out:static void dccp_keepalive_timer (struct timer_list *t) { -struct sock *sk =from_timer (sk, t, sk_timer); +struct inet_connection_sock *icsk = +from_timer (icsk, t, icsk_keepalive_timer); +struct sock *sk = &icsk->icsk_inet.sk;pr_err ("dccp should not use a keepalive timer !\n" );sock_put (sk);
net/ipv4/inet_connection_sock.c +5 -5
@@ -750,7 +750,7 @@ void inet_csk_init_xmit_timers(struct sotimer_setup (&icsk->icsk_retransmit_timer, retransmit_handler,0 );timer_setup (&icsk->icsk_delack_timer, delack_handler,0 ); -timer_setup (&sk->sk_timer, keepalive_handler,0 ); +timer_setup (&icsk->icsk_keepalive_timer, keepalive_handler,0 ); icsk->icsk_pending = icsk->icsk_ack.pending =0 ; }EXPORT_SYMBOL (inet_csk_init_xmit_timers);
@@ -763,7 +763,7 @@ void inet_csk_clear_xmit_timers(struct ssk_stop_timer (sk, &icsk->icsk_retransmit_timer);sk_stop_timer (sk, &icsk->icsk_delack_timer); -sk_stop_timer (sk, &sk->sk_timer); +sk_stop_timer (sk, &icsk->icsk_keepalive_timer); }EXPORT_SYMBOL (inet_csk_clear_xmit_timers);
@@ -778,18 +778,18 @@ void inet_csk_clear_xmit_timers_sync(strsk_stop_timer_sync (sk, &icsk->icsk_retransmit_timer);sk_stop_timer_sync (sk, &icsk->icsk_delack_timer); -sk_stop_timer_sync (sk, &sk->sk_timer); +sk_stop_timer_sync (sk, &icsk->icsk_keepalive_timer); }void inet_csk_delete_keepalive_timer (struct sock *sk) { -sk_stop_timer (sk, &sk->sk_timer); +sk_stop_timer (sk, &inet_csk (sk)->icsk_keepalive_timer); }EXPORT_SYMBOL (inet_csk_delete_keepalive_timer);void inet_csk_reset_keepalive_timer (struct sock *sk,unsigned long len) { -sk_reset_timer (sk, &sk->sk_timer, jiffies + len); +sk_reset_timer (sk, &inet_csk (sk)->icsk_keepalive_timer, jiffies + len); }EXPORT_SYMBOL (inet_csk_reset_keepalive_timer);
net/ipv4/inet_diag.c +2 -2
@@ -319,11 +319,11 @@ int inet_sk_diag_fill(struct sock *sk, s r->idiag_retrans = icsk->icsk_probes_out; r->idiag_expires =jiffies_delta_to_msecs (icsk->icsk_timeout - jiffies); - }else if (timer_pending (&sk->sk_timer)) { + }else if (timer_pending (&icsk->icsk_keepalive_timer)) { r->idiag_timer =2 ; r->idiag_retrans = icsk->icsk_probes_out; r->idiag_expires = -jiffies_delta_to_msecs (sk->sk_timer.expires - jiffies); +jiffies_delta_to_msecs (icsk->icsk_keepalive_timer.expires - jiffies); }if ((ext & (1 << (INET_DIAG_INFO -1 ))) && handler->idiag_info_size) {
net/ipv4/tcp_ipv4.c +2 -2
@@ -2918,9 +2918,9 @@ static void get_tcp4_sock(struct sock *s }else if (icsk->icsk_pending ==ICSK_TIME_PROBE0 ) { timer_active =4 ; timer_expires = icsk->icsk_timeout; - }else if (timer_pending (&sk->sk_timer)) { + }else if (timer_pending (&icsk->icsk_keepalive_timer)) { timer_active =2 ; - timer_expires = sk->sk_timer.expires; + timer_expires = icsk->icsk_keepalive_timer.expires; }else { timer_active =0 ; timer_expires = jiffies;
net/ipv4/tcp_timer.c +3 -2
@@ -755,8 +755,9 @@ EXPORT_IPV6_MOD_GPL(tcp_set_keepalive);static void tcp_keepalive_timer (struct timer_list *t) { -struct sock *sk =from_timer (sk, t, sk_timer); -struct inet_connection_sock *icsk =inet_csk (sk); +struct inet_connection_sock *icsk = +from_timer (icsk, t, icsk_keepalive_timer); +struct sock *sk = &icsk->icsk_inet.sk;struct tcp_sock *tp =tcp_sk (sk);u32 elapsed;
net/ipv6/tcp_ipv6.c +2 -2
@@ -2179,9 +2179,9 @@ static void get_tcp6_sock(struct seq_fil }else if (icsk->icsk_pending ==ICSK_TIME_PROBE0 ) { timer_active =4 ; timer_expires = icsk->icsk_timeout; - }else if (timer_pending (&sp->sk_timer)) { + }else if (timer_pending (&icsk->icsk_keepalive_timer)) { timer_active =2 ; - timer_expires = sp->sk_timer.expires; + timer_expires = icsk->icsk_keepalive_timer.expires; }else { timer_active =0 ; timer_expires = jiffies;
net/mptcp/ctrl.c +2 -2
@@ -407,9 +407,9 @@ void mptcp_active_detect_blackhole(strucif (subflow->request_mptcp && ssk->sk_state ==TCP_SYN_SENT ) {if (timeouts ==2 || (timeouts <2 && expired)) { -MPTCP_INC_STATS (sock_net (ssk),MPTCP_MIB_MPCAPABLEACTIVEDROP ); subflow->mpc_drop =1 ; -mptcp_subflow_early_fallback (mptcp_sk (subflow->conn), subflow); +mptcp_subflow_early_fallback (mptcp_sk (subflow->conn), subflow, +MPTCP_MIB_MPCAPABLEACTIVEDROP ); } }else if (ssk->sk_state ==TCP_SYN_SENT ) { subflow->mpc_drop =0 ;
net/mptcp/mib.c +5 -0
@@ -79,6 +79,11 @@ static const struct snmp_mib mptcp_snmp_SNMP_MIB_ITEM ("RcvWndConflict" ,MPTCP_MIB_RCVWNDCONFLICT ),SNMP_MIB_ITEM ("MPCurrEstab" ,MPTCP_MIB_CURRESTAB ),SNMP_MIB_ITEM ("Blackhole" ,MPTCP_MIB_BLACKHOLE ), +SNMP_MIB_ITEM ("MPCapableDataFallback" ,MPTCP_MIB_MPCAPABLEDATAFALLBACK ), +SNMP_MIB_ITEM ("MD5SigFallback" ,MPTCP_MIB_MD5SIGFALLBACK ), +SNMP_MIB_ITEM ("DssFallback" ,MPTCP_MIB_DSSFALLBACK ), +SNMP_MIB_ITEM ("SimultConnectFallback" ,MPTCP_MIB_SIMULTCONNFALLBACK ), +SNMP_MIB_ITEM ("FallbackFailed" ,MPTCP_MIB_FALLBACKFAILED ),SNMP_MIB_SENTINEL };
net/mptcp/mib.h +5 -0
@@ -80,6 +80,11 @@ enum linux_mptcp_mib_field {MPTCP_MIB_RCVWNDCONFLICT ,/* Conflict with while updating msk rcv wnd */ MPTCP_MIB_CURRESTAB ,/* Current established MPTCP connections */ MPTCP_MIB_BLACKHOLE ,/* A blackhole has been detected */ +MPTCP_MIB_MPCAPABLEDATAFALLBACK ,/* No DSS/MPC+data on first established packet */ +MPTCP_MIB_MD5SIGFALLBACK ,/* Conflicting TCP option enabled */ +MPTCP_MIB_DSSFALLBACK ,/* Bad or missing DSS */ +MPTCP_MIB_SIMULTCONNFALLBACK ,/* Simultaneous connect */ +MPTCP_MIB_FALLBACKFAILED ,/* Can't fallback due to msk status */ __MPTCP_MIB_MAX };
net/mptcp/options.c +4 -2
@@ -473,7 +473,7 @@ bool mptcp_syn_options(struct sock *sk, subflow->snd_isn =TCP_SKB_CB (skb)->end_seq;if (subflow->request_mptcp) {if (unlikely (subflow_simultaneous_connect (sk))) { -WARN_ON_ONCE (!mptcp_try_fallback (sk)); +WARN_ON_ONCE (!mptcp_try_fallback (sk,MPTCP_MIB_SIMULTCONNFALLBACK ));/* Ensure mptcp_finish_connect() will not process the * MPC handshake.
@@ -1043,8 +1043,10 @@ static bool check_fully_established(struif (subflow->mp_join) goto reset; subflow->mp_capable =0 ; -if (!mptcp_try_fallback (ssk)) +if (!mptcp_try_fallback (ssk,MPTCP_MIB_MPCAPABLEDATAFALLBACK )) { +MPTCP_INC_STATS (sock_net (ssk),MPTCP_MIB_FALLBACKFAILED ); goto reset; + }pr_fallback (msk);return false; }
net/mptcp/protocol.c +41 -29
152 lines not on this page · raw message
net/mptcp/protocol.h +8 -23
@@ -845,7 +845,7 @@ static inline void mptcp_stop_tout_timerif (!inet_csk (sk)->icsk_mtup.probe_timestamp)return ; -sk_stop_timer (sk, &sk->sk_timer); +sk_stop_timer (sk, &inet_csk (sk)->mptcp_tout_timer);inet_csk (sk)->icsk_mtup.probe_timestamp =0 ; }
@@ -1216,24 +1216,6 @@ static inline bool mptcp_check_fallback(return __mptcp_check_fallback (msk); } -static inline bool __mptcp_try_fallback (struct mptcp_sock *msk) -{ -if (__mptcp_check_fallback (msk)) { -pr_debug ("TCP fallback already done (msk=%p)\n" , msk); -return true; - } -spin_lock_bh (&msk->fallback_lock); -if (!msk->allow_infinite_fallback) { -spin_unlock_bh (&msk->fallback_lock); -return false; - } - - msk->allow_subflows = false; -set_bit (MPTCP_FALLBACK_DONE , &msk->flags); -spin_unlock_bh (&msk->fallback_lock); -return true; -} -static inline bool __mptcp_has_initial_subflow (const struct mptcp_sock *msk) {struct sock *ssk =READ_ONCE (msk->first);
@@ -1243,14 +1225,16 @@ static inline bool __mptcp_has_initial_s TCPF_SYN_RECV | TCPF_LISTEN)); } -static inline bool mptcp_try_fallback (struct sock *ssk) +bool __mptcp_try_fallback (struct mptcp_sock *msk,int fb_mib); + +static inline bool mptcp_try_fallback (struct sock *ssk,int fb_mib) {struct mptcp_subflow_context *subflow =mptcp_subflow_ctx (ssk);struct sock *sk = subflow->conn;struct mptcp_sock *msk; msk =mptcp_sk (sk); -if (!__mptcp_try_fallback (msk)) +if (!__mptcp_try_fallback (msk, fb_mib))return false;if (READ_ONCE (msk->snd_data_fin_enable) && !(ssk->sk_shutdown &SEND_SHUTDOWN )) {gfp_t saved_allocation = ssk->sk_allocation;
@@ -1269,11 +1253,12 @@ static inline bool mptcp_try_fallback(st#define pr_fallback (a) pr_debug("%s:fallback to TCP (msk=%p)\n", __func__, a)static inline void mptcp_subflow_early_fallback (struct mptcp_sock *msk, -struct mptcp_subflow_context *subflow) +struct mptcp_subflow_context *subflow, +int fb_mib) {pr_fallback (msk); subflow->request_mptcp =0 ; -WARN_ON_ONCE (!__mptcp_try_fallback (msk)); +WARN_ON_ONCE (!__mptcp_try_fallback (msk, fb_mib)); }static inline bool mptcp_check_infinite_map (struct sk_buff *skb)
net/mptcp/subflow.c +6 -4
@@ -550,11 +550,13 @@ static void subflow_finish_connect(strucmptcp_get_options (skb, &mp_opt);if (subflow->request_mptcp) {if (!(mp_opt.suboptions &OPTION_MPTCP_MPC_SYNACK )) { -if (!mptcp_try_fallback (sk)) +if (!mptcp_try_fallback (sk, +MPTCP_MIB_MPCAPABLEACTIVEFALLBACK )) { +MPTCP_INC_STATS (sock_net (sk), +MPTCP_MIB_FALLBACKFAILED ); goto do_reset; + } -MPTCP_INC_STATS (sock_net (sk), -MPTCP_MIB_MPCAPABLEACTIVEFALLBACK );pr_fallback (msk); goto fallback; }
@@ -1404,7 +1406,7 @@ fallback:return true; } -if (!mptcp_try_fallback (ssk)) { +if (!mptcp_try_fallback (ssk,MPTCP_MIB_DSSFALLBACK )) {/* fatal protocol error, close the socket. * subflow_error_report() will introduce the appropriate barriers */
tools/testing/selftests/bpf/progs/bpf_iter_tcp4.c +2 -2
@@ -103,9 +103,9 @@ static int dump_tcp_sock(struct seq_file }else if (icsk->icsk_pending ==ICSK_TIME_PROBE0 ) { timer_active =4 ; timer_expires = icsk->icsk_timeout; - }else if (timer_pending (&sp->sk_timer)) { + }else if (timer_pending (&icsk->icsk_keepalive_timer)) { timer_active =2 ; - timer_expires = sp->sk_timer.expires; + timer_expires = icsk->icsk_keepalive_timer.expires; }else { timer_active =0 ; timer_expires =bpf_jiffies64 ();
tools/testing/selftests/bpf/progs/bpf_iter_tcp6.c +2 -2
@@ -103,9 +103,9 @@ static int dump_tcp6_sock(struct seq_fil }else if (icsk->icsk_pending ==ICSK_TIME_PROBE0 ) { timer_active =4 ; timer_expires = icsk->icsk_timeout; - }else if (timer_pending (&sp->sk_timer)) { + }else if (timer_pending (&icsk->icsk_keepalive_timer)) { timer_active =2 ; - timer_expires = sp->sk_timer.expires; + timer_expires = icsk->icsk_keepalive_timer.expires; }else { timer_active =0 ; timer_expires =bpf_jiffies64 ();
Greg Kroah-Hartman
maintainerPATCH 772/877 mptcp: do not reschedule the RTX timer for fallback sockets
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paolo Abeni <[email protected]>
[ Upstream commit e2ab913f68c7d11e2561b8a8ad0b87ffefcad667 ]
On fallback socket the retrans timer is a quite convoluted no-op, but currently nothing prevents the MPTCP core to keep rescheduling it.
Additionally gate RTX timer reset to the msk not being fallen back to TCP yet. To avoid adding multiple tests in fast-path, use a new flags bit for such condition.
The RTX enable bit is clear at close time and set before the msk could start retransmitting, with a couple of caveats:
- passive sockets inherit the bit from the listener msk; set the bit on such socket to avoid flipping it in the fast-path, even if the listener will obviously never retransmit.
- while fastopening (MPTFO), mptcp_sendmsg_fastopen still ends-up calling mptcp_connect via tcp_sendmsg_fastopen -> __inet_stream_connect(ssk->sk_socket), and the first subflow's sk_socket points to the msk one.
--- net/mptcp/protocol.c | 13 ++++++++++--- net/mptcp/protocol.h | 1 + 2 files changed, 11 insertions(+), 3 deletions(-)
net/mptcp/protocol.c +10 -3
@@ -82,6 +82,7 @@ bool __mptcp_try_fallback(struct mptcp_s msk->allow_subflows = false;set_bit (MPTCP_FALLBACK_DONE , &msk->flags); +clear_bit (MPTCP_RTX_ENABLED , &msk->flags);__MPTCP_INC_STATS (net, fb_mib);spin_unlock_bh (&msk->fallback_lock);return true;
@@ -993,13 +994,14 @@ static bool mptcp_rtx_timer_pending(strustatic void mptcp_reset_rtx_timer (struct sock *sk) { +struct mptcp_sock *msk =mptcp_sk (sk);unsigned long tout; -/* prevent rescheduling on close */ -if (unlikely (inet_sk_state_load (sk) ==TCP_CLOSE )) +/* Prevent rescheduling on close and in case of fallback. */ +if (!test_bit (MPTCP_RTX_ENABLED , &msk->flags))return ; - tout =mptcp_sk (sk)->timer_ival; + tout = msk->timer_ival;sk_reset_timer (sk, &sk->mptcp_retransmit_timer, jiffies + tout); }
@@ -3121,6 +3123,9 @@ void mptcp_set_state(struct sock *sk, in* transition from TCP_SYN_RECV to TCP_CLOSE_WAIT. */ break ; +case TCP_CLOSE : +clear_bit (MPTCP_RTX_ENABLED , &mptcp_sk (sk)->flags); + fallthrough;default :if (oldstate ==TCP_ESTABLISHED || oldstate ==TCP_CLOSE_WAIT )MPTCP_DEC_STATS (sock_net (sk),MPTCP_MIB_CURRESTAB );
@@ -3944,6 +3949,7 @@ static int mptcp_connect(struct sock *skif (IS_ERR (ssk))return PTR_ERR (ssk); +set_bit (MPTCP_RTX_ENABLED , &msk->flags);mptcp_set_state (sk,TCP_SYN_SENT ); subflow =mptcp_subflow_ctx (ssk);#ifdef CONFIG_TCP_MD5SIG
@@ -4092,6 +4098,7 @@ static int mptcp_listen(struct socket *s goto unlock; } +set_bit (MPTCP_RTX_ENABLED , &msk->flags);mptcp_set_state (sk,TCP_LISTEN );sock_set_flag (sk,SOCK_RCU_FREE );
net/mptcp/protocol.h +1 -0
@@ -116,6 +116,7 @@#define MPTCP_WORK_RTX 1#define MPTCP_FALLBACK_DONE 2#define MPTCP_WORK_CLOSE_SUBFLOW 3 +#define MPTCP_RTX_ENABLED 4/* MPTCP socket release cb flags */ #define MPTCP_PUSH_PENDING 1
Greg Kroah-Hartman
maintainerPATCH 773/877 mptcp: prevent race between disconnect() and rtx
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paolo Abeni <[email protected]>
[ Upstream commit 85c580b0d8590520ae00a15c29e9fb9c99427a3e ]
Sashiko noted that the two event can race, leading to inconsistent status. Prevent the race using the synchronous timer stop operation.
--- net/mptcp/protocol.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
net/mptcp/protocol.c +8 -2
@@ -3367,6 +3367,7 @@ static void mptcp_copy_inaddrs(struct sostatic int mptcp_disconnect (struct sock *sk,int flags) { +struct inet_connection_sock *icsk =inet_csk (sk);struct mptcp_sock *msk =mptcp_sk (sk);/* We are on the fastopen error path. We can't call straight into the
@@ -3379,8 +3380,13 @@ static int mptcp_disconnect(struct sockmptcp_check_listen_stop (sk);mptcp_set_state (sk,TCP_CLOSE ); -mptcp_stop_rtx_timer (sk); -mptcp_stop_tout_timer (sk); +/* The later subflow close can not kick again the tout timer, +* as the msk is already in closed status. +*/ + msk->timer_ival = icsk->icsk_rto_min; +sk_stop_timer_sync (sk, &sk->mptcp_retransmit_timer); + icsk->icsk_mtup.probe_timestamp =0 ; +sk_stop_timer_sync (sk, &icsk->mptcp_tout_timer);if (msk->token)mptcp_event (MPTCP_EVENT_CLOSED , msk,NULL ,GFP_KERNEL );
Re: [PATCH 6.12 773/877] mptcp: prevent race between disconnect() and rtx
Quoted 35 lines · Greg Kroah-Hartman
6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paolo Abeni <[email protected]>
[ Upstream commit
85c580b0d8590520ae00a15c29e9fb9c99427a3e]Sashiko noted that the two event can race, leading to inconsistent status. Prevent the race using the synchronous timer stop operation.
Fixes b29fcfb54cd7 ("mptcp: full disconnect implementation")Signed-off-by Paolo Abeni <[email protected]>Reviewed-by Matthieu Baerts (NGI0) <[email protected]>Signed-off-by Matthieu Baerts (NGI0) <[email protected]>Link https://patch.msgid.link/20260908-net-mptcp-misc-fixes-7-3-rc1-v2-6-df1de70348b6@kernel.org open hereSigned-off-by Jakub Kicinski <[email protected]>Signed-off-by Sasha Levin <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- net/mptcp/protocol.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)net/mptcp/protocol.c +1
-0@@ -3367,6 +3367,7 @@ static void mptcp_copy_inaddrs(struct sostatic int mptcp_disconnect (struct sock *sk,int flags) { +struct inet_connection_sock *icsk =inet_csk (sk);struct mptcp_sock *msk =mptcp_sk (sk);/* We are on the fastopen error path. We can't call straight into the
net/mptcp/protocol.c static int mptcp_disconnect(struct sock · line 3386
Quoted 9 lines
net/mptcp/protocol.c +4
-2@@ -3379,8 +3380,13 @@ static int mptcp_disconnect(struct sockmptcp_check_listen_stop (sk);mptcp_set_state (sk,TCP_CLOSE ); -mptcp_stop_rtx_timer (sk); -mptcp_stop_tout_timer (sk); +/* The later subflow close can not kick again the tout timer, +* as the msk is already in closed status. +*/ + msk->timer_ival = icsk->icsk_rto_min;
^^^
Hi Greg/Sasha,
An AI-assisted review flagged the reset expression, and I checked the MPTCP parent-socket initialization on 6.12.
Upstream, net/mptcp/protocol.c, __mptcp_init_sock():
icsk->icsk_rto_min =
usecs_to_jiffies(READ_ONCE(net->ipv4.sysctl_tcp_rto_min_us));Then mptcp_disconnect() uses:
msk->timer_ival = icsk->icsk_rto_min;
6.12's initializer instead has:
msk->timer_ival = TCP_RTO_MIN;
6.12 never initializes the parent's icsk_rto_min or calls tcp_init_sock(), so disconnect reads zero; the subflow's initialized field does not help. Upstream's broader RTO feature, ea4eb2adb0d3414abeddaba72dbf8876fa66528f ("mptcp: honour configured min/max RTO in retransmit paths"), supplies the missing initialization.
Could we use msk->timer_ival = TCP_RTO_MIN on 6.12, matching its initializer while retaining the synchronous stops?
should we drop this for now ?
thanks,
Harshit
Quoted 9 lines
net/mptcp/protocol.c +3
-0+sk_stop_timer_sync (sk, &sk->mptcp_retransmit_timer); + icsk->icsk_mtup.probe_timestamp =0 ; +sk_stop_timer_sync (sk, &icsk->mptcp_tout_timer);if (msk->token)mptcp_event (MPTCP_EVENT_CLOSED , msk,NULL ,GFP_KERNEL );
Greg Kroah-Hartman
maintainerRe: [PATCH 6.12 773/877] mptcp: prevent race between disconnect() and rtx
Quoted 70 lines · Harshit Mogalapalli
Quoted 33 lines · Greg Kroah-Hartman
6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paolo Abeni <[email protected]>
[ Upstream commit
85c580b0d8590520ae00a15c29e9fb9c99427a3e]Sashiko noted that the two event can race, leading to inconsistent status. Prevent the race using the synchronous timer stop operation.
Fixes b29fcfb54cd7 ("mptcp: full disconnect implementation")Signed-off-by Paolo Abeni <[email protected]>Reviewed-by Matthieu Baerts (NGI0) <[email protected]>Signed-off-by Matthieu Baerts (NGI0) <[email protected]>Link https://patch.msgid.link/20260908-net-mptcp-misc-fixes-7-3-rc1-v2-6-df1de70348b6@kernel.org open hereSigned-off-by Jakub Kicinski <[email protected]>Signed-off-by Sasha Levin <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>--- net/mptcp/protocol.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)net/mptcp/protocol.c +1
-0@@ -3367,6 +3367,7 @@ static void mptcp_copy_inaddrs(struct sostatic int mptcp_disconnect (struct sock *sk,int flags) { +struct inet_connection_sock *icsk =inet_csk (sk);struct mptcp_sock *msk =mptcp_sk (sk);/* We are on the fastopen error path. We can't call straight into the net/mptcp/protocol.c static int mptcp_disconnect(struct sock · line 3385
Quoted 8 lines
net/mptcp/protocol.c +4
-2@@ -3379,8 +3380,13 @@ static int mptcp_disconnect(struct sockmptcp_check_listen_stop (sk);mptcp_set_state (sk,TCP_CLOSE ); -mptcp_stop_rtx_timer (sk); -mptcp_stop_tout_timer (sk); +/* The later subflow close can not kick again the tout timer, +* as the msk is already in closed status. +*/ + msk->timer_ival = icsk->icsk_rto_min;^^^
Hi Greg/Sasha,
An AI-assisted review flagged the reset expression, and I checked the MPTCP parent-socket initialization on 6.12.
Upstream,
net/mptcp/protocol.c,__mptcp_init_sock():icsk->icsk_rto_min = usecs_to_jiffies(READ_ONCE(net->ipv4.sysctl_tcp_rto_min_us));Then
mptcp_disconnect()uses:msk->timer_ival = icsk->icsk_rto_min;6.12's initializer instead has:
msk->timer_ival = TCP_RTO_MIN;6.12 never initializes the parent's
icsk_rto_minor callstcp_init_sock(), so disconnect reads zero; the subflow's initialized field does not help. Upstream's broader RTO feature,ea4eb2adb0d3414abeddaba72dbf8876fa66528f("mptcp: honour configured min/max RTO in retransmit paths"), supplies the missing initialization.
Quoted 5 lines
Could we use
msk->timer_ival=TCP_RTO_MINon 6.12, matching its initializer while retaining the synchronous stops?should we drop this for now ?
Now dropped, thanks.
greg k-h
Greg Kroah-Hartman
maintainerPATCH 774/877 smb: client: refactor ACL setting control flow in id_mode_to_cifs_acl()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ralph Boehme <[email protected]>
[ Upstream commit a540a64c4801fe02e452ee37e961018106418260 ]
Refactor the control flow in id_mode_to_cifs_acl() to reduce nesting and prevent error code overwriting.
Instead of wrapping the call to ops->set_acl() in a conditional block, introduce early exits (goto id_mode_to_cifs_acl_exit) when build_sec_desc() fails or ops->set_acl is NULL. This ensures that any actual error returned by build_sec_desc() is not overwritten with -EOPNOTSUPP.
Stable-dep-of: d05045177a85 ("smb: client: fail DACL rewrite when the new DACL exceeds 64K")
--- fs/smb/client/cifsacl.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
fs/smb/client/cifsacl.c +10 -6
@@ -1798,14 +1798,18 @@ id_mode_to_cifs_acl(struct inode *inode,cifs_dbg (NOISY ,"build_sec_desc rc: %d\n" , rc); -if (ops->set_acl ==NULL ) - rc = -EOPNOTSUPP ; +if (rc !=0 ) + goto id_mode_to_cifs_acl_exit; -if (!rc) { -/* Set the security descriptor */ - rc = ops->set_acl (pnntsd, nsecdesclen, inode, path, aclflag); -cifs_dbg (NOISY ,"set_cifs_acl rc: %d\n" , rc); +if (ops->set_acl ==NULL ) { + rc = -EOPNOTSUPP ; + goto id_mode_to_cifs_acl_exit; } + +/* Set the security descriptor */ + rc = ops->set_acl (pnntsd, nsecdesclen, inode, path, aclflag); +cifs_dbg (NOISY ,"set_cifs_acl rc: %d\n" , rc); + id_mode_to_cifs_acl_exit:cifs_put_tlink (tlink);
Greg Kroah-Hartman
maintainerPATCH 775/877 smb/client: fix security flag calculation when setting security descriptors
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ralph Boehme <[email protected]>
[ Upstream commit 4939889c985da68936090cc013e58c28b7bff34f ]
In id_mode_to_cifs_acl(), aclflag was initialized to CIFS_ACL_DACL by default. This forced the client to request setting the DACL even when only an ownership (chown) or group (chgrp) change was being performed.
Let build_sec_desc() do the proper flag calculation by initializing aclflag to 0. build_sec_desc() sets the appropriate bits (CIFS_ACL_OWNER, CIFS_ACL_GROUP, or CIFS_ACL_DACL) depending on what actually changed. During ownership transfer, CIFS_ACL_DACL is only set if replace_sids_and_copy_aces() actually replaces the SIDs inside any of the DACL's ACEs.
If build_sec_desc() results in aclflag being 0 (meaning no changes were mapped), exit early to avoid sending an empty security descriptor update to the server.
Stable-dep-of: d05045177a85 ("smb: client: fail DACL rewrite when the new DACL exceeds 64K")
--- fs/smb/client/cifsacl.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
fs/smb/client/cifsacl.c +16 -6
@@ -1131,7 +1131,8 @@ set_size:static __u16 replace_sids_and_copy_aces (struct smb_acl *pdacl,struct smb_acl *pndacl,struct smb_sid *pownersid,struct smb_sid *pgrpsid, -struct smb_sid *pnownersid,struct smb_sid *pngrpsid) +struct smb_sid *pnownersid,struct smb_sid *pngrpsid, +int *aclflag) {int i;u16 size =0 ;
@@ -1155,12 +1156,15 @@ static __u16 replace_sids_and_copy_aces( pntace = (struct smb_ace *) (acl_base + size); pnntace = (struct smb_ace *) (nacl_base + nsize); -if (pnownersid &&compare_sids (&pntace->sid, pownersid) ==0 ) +if (pnownersid &&compare_sids (&pntace->sid, pownersid) ==0 ) { ace_size =cifs_copy_ace (pnntace, pntace, pnownersid); -else if (pngrpsid &&compare_sids (&pntace->sid, pgrpsid) ==0 ) + *aclflag |=CIFS_ACL_DACL ; + }else if (pngrpsid &&compare_sids (&pntace->sid, pgrpsid) ==0 ) { ace_size =cifs_copy_ace (pnntace, pntace, pngrpsid); -else + *aclflag |=CIFS_ACL_DACL ; + }else { ace_size =cifs_copy_ace (pnntace, pntace,NULL ); + } size +=le16_to_cpu (pntace->size); nsize += ace_size;
@@ -1482,7 +1486,8 @@ static int build_sec_desc(struct smb_nts/* Replace ACEs for old owner with new one */ size =replace_sids_and_copy_aces (dacl_ptr, ndacl_ptr, owner_sid_ptr, group_sid_ptr, - nowner_sid_ptr, ngroup_sid_ptr); + nowner_sid_ptr, ngroup_sid_ptr, + aclflag); ndacl_ptr->size =cpu_to_le16 (size); }
@@ -1697,7 +1702,7 @@ id_mode_to_cifs_acl(struct inode *inode, kuid_t uid, kgid_t gid) { int rc = 0; -int aclflag =CIFS_ACL_DACL ;/* default flag to set */ +int aclflag =0 ;__u32 secdesclen =0 ;__u32 nsecdesclen =0 ;__u32 dacloffset =0 ;
@@ -1801,6 +1806,11 @@ id_mode_to_cifs_acl(struct inode *inode,if (rc !=0 ) goto id_mode_to_cifs_acl_exit; +if (aclflag ==0 ) { +cifs_dbg (FYI ,"set_cifs_acl aclflag=0, no change mapped\n" ); + goto id_mode_to_cifs_acl_exit; + } +if (ops->set_acl ==NULL ) { rc = -EOPNOTSUPP ; goto id_mode_to_cifs_acl_exit;
Greg Kroah-Hartman
maintainerPATCH 776/877 smb: client: fail DACL rewrite when the new DACL exceeds 64K
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bjoern Doebel <[email protected]>
[ Upstream commit d05045177a855386bca5e1909e08d06290e6e3b3 ]
replace_sids_and_copy_aces() and set_chmod_dacl() accumulate the size of the DACL they build in a u16. That accumulator can wrap.
validate_dacl() caps num_aces at (dacl_size - sizeof(struct smb_acl)) / 20, i.e. 3276 for a maximally sized DACL, while each rewritten ACE can grow to sizeof(struct smb_ace) (76 bytes) once its SID is replaced with one carrying SID_MAX_SUB_AUTHORITIES sub-authorities. The worst case is therefore sizeof(struct smb_acl) + 3276 * 76 = 248984 bytes, far beyond what a u16 can hold. A wraparound is reached with 863 ACEs.
After the wraparound, ndacl_ptr->size becomes meaningless and the offset will point anywhere in the ACE array. As a result, we will see corruption of the DACL, which then gets sent to the server. This is not an out-of-bounds write as the allocation now covers the worst-case expansion, so writes will always go into the buffer.
Adjust the code to use a u32 internally and return -EOVERFLOW in the overflow case. The operation must be refused, because a DACL can only hold 2^16-1 bytes on the wire and larger DACLs cannot be represented.
set_chmod_dacl() carries the same pattern and is fixed the same way. It only wraps once the source DACL comes within roughly 380 bytes of the 64K ceiling, but the failure mode is identical.
--- fs/smb/client/cifsacl.c | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-)
fs/smb/client/cifsacl.c +26 -13
@@ -1024,13 +1024,13 @@ unsigned int setup_special_user_owner_ACstatic void populate_new_aces (char *nacl_base,struct smb_sid *pownersid,struct smb_sid *pgrpsid, -__u64 *pnmode,u16 *pnum_aces,u16 *pnsize, +__u64 *pnmode,u16 *pnum_aces,u32 *pnsize,bool modefromsid,bool posix) {__u64 nmode;u16 num_aces =0 ; -u16 nsize =0 ; +u32 nsize =0 ;__u64 user_mode;__u64 group_mode;__u64 other_mode;
@@ -1129,17 +1129,17 @@ set_size: *pnsize = nsize; } -static __u16 replace_sids_and_copy_aces (struct smb_acl *pdacl,struct smb_acl *pndacl, -struct smb_sid *pownersid,struct smb_sid *pgrpsid, -struct smb_sid *pnownersid,struct smb_sid *pngrpsid, -int *aclflag) +static int replace_sids_and_copy_aces (struct smb_acl *pdacl,struct smb_acl *pndacl, +struct smb_sid *pownersid,struct smb_sid *pgrpsid, +struct smb_sid *pnownersid,struct smb_sid *pngrpsid, +int *aclflag,u16 *pnsize) {int i;u16 size =0 ;struct smb_ace *pntace =NULL ;char *acl_base =NULL ;u16 src_num_aces =0 ; -u16 nsize =0 ; +u32 nsize =0 ;struct smb_ace *pnntace =NULL ;char *nacl_base =NULL ;u16 ace_size =0 ;
@@ -1168,9 +1168,12 @@ static __u16 replace_sids_and_copy_aces( size +=le16_to_cpu (pntace->size); nsize += ace_size; +if (nsize >U16_MAX ) +return -EOVERFLOW ; } -return nsize; + *pnsize = nsize; +return 0 ; } static int set_chmod_dacl(struct smb_acl *pdacl, struct smb_acl *pndacl,
@@ -1182,7 +1185,7 @@ static int set_chmod_dacl(struct smb_aclstruct smb_ace *pntace =NULL ;char *acl_base =NULL ;u16 src_num_aces =0 ; -u16 nsize =0 ; +u32 nsize =0 ;struct smb_ace *pnntace =NULL ;char *nacl_base =NULL ;u16 num_aces =0 ;
@@ -1233,6 +1236,8 @@ static int set_chmod_dacl(struct smb_acl nsize +=cifs_copy_ace (pnntace, pntace,NULL ); num_aces++; +if (nsize >U16_MAX ) +return -EOVERFLOW ; next_ace: size +=le16_to_cpu (pntace->size);
@@ -1249,6 +1254,10 @@ next_ace: } finalize_dacl: +/* The DACL size field is 16-bit on the wire, see MS-DTYP 2.4.5 */ +if (nsize >U16_MAX ) +return -EOVERFLOW ; + pndacl->num_aces =cpu_to_le16 (num_aces); pndacl->size =cpu_to_le16 (nsize);
@@ -1409,6 +1418,8 @@ static int build_sec_desc(struct smb_nts rc =set_chmod_dacl (dacl_ptr, ndacl_ptr, owner_sid_ptr, group_sid_ptr, pnmode, mode_from_sid, posix); +if (rc) +return rc; sidsoffset = ndacloffset +le16_to_cpu (ndacl_ptr->size);/* copy the non-dacl portion of secdesc */
@@ -1484,10 +1495,12 @@ static int build_sec_desc(struct smb_ntsif (dacloffset) {/* Replace ACEs for old owner with new one */ - size =replace_sids_and_copy_aces (dacl_ptr, ndacl_ptr, - owner_sid_ptr, group_sid_ptr, - nowner_sid_ptr, ngroup_sid_ptr, - aclflag); + rc =replace_sids_and_copy_aces (dacl_ptr, ndacl_ptr, + owner_sid_ptr, group_sid_ptr, + nowner_sid_ptr, ngroup_sid_ptr, + aclflag, &size); +if (rc) + goto chown_chgrp_exit; ndacl_ptr->size =cpu_to_le16 (size); }
Greg Kroah-Hartman
maintainerPATCH 777/877 xfs: report healthy filesystem events in scrub stats
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Darrick J. Wong" <[email protected]>
[ Upstream commit 0ae61c331ec552ad0c278c5c48a1c4ccb90b4bab ]
LOLLM also notices that I forgot to expose the "clean bill of health" scrub stats. Fix that.
--- fs/xfs/scrub/stats.c | 1 + 1 file changed, 1 insertion(+)
fs/xfs/scrub/stats.c +1 -0
@@ -80,6 +80,7 @@ static const char *name_map[XFS_SCRUB_TY [XFS_SCRUB_TYPE_QUOTACHECK] = "quotacheck", [XFS_SCRUB_TYPE_NLINKS] = "nlinks", [XFS_SCRUB_TYPE_DIRTREE] = "dirtree", + [XFS_SCRUB_TYPE_HEALTHY] = "healthy", };/* Format the scrub stats into a text buffer, similar to pcp style. */
Greg Kroah-Hartman
maintainerPATCH 778/877 xfs: fix short ifork reaping computation in xreap_bmapi_binval
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Darrick J. Wong" <[email protected]>
[ Upstream commit eacb8479507756c3305994e87fb2fb1183827e98 ]
LOLLM got really confused about the update to imap->br_blockcount in xreap_bmapi_binval if xreap_inc_binval returns false. The intent of this code is that we shorten the imap to whatever length of space we invalidated so that the next iteration through the loop will start wherever we left off. Unfortunately, the calculation sets br_blockcount to the amount of *unfinished* work, which means that we pointlessly re-scan blocks that we already reaped. This is benign, but we should fix the computation anyway.
--- fs/xfs/scrub/reap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/scrub/reap.c +1 -1
@@ -861,7 +861,7 @@ xreap_bmapi_binval(* much of the mapping we've seen so far. */ if (invalidated >XREAP_MAX_BINVAL ) { - imap->br_blockcount = agbno_next - bno; + imap->br_blockcount = bno - agbno; goto out; } }
Greg Kroah-Hartman
maintainerPATCH 779/877 xfs: strengthen the "is cow staging" helpers in scrub
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Darrick J. Wong" <[email protected]>
[ Upstream commit 0d43368844a75ad13561a1198a3b027940730756 ]
LOLLM pointed out a bug in both of the refcount scrub predicates that determine if a range of blocks is marked as CoW staging in the btree. While it compares blockcount < len, this isn't enough to determine that the CoW staging record is at least as large as the range passed into the helper. Fix both of them.
--- fs/xfs/scrub/refcount.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/xfs/scrub/refcount.c +5 -1
@@ -581,8 +581,12 @@ xchk_xref_is_cow_staging(if (rc.rc_domain !=XFS_REFC_DOMAIN_COW )xchk_btree_xref_set_corrupt (sc, sc->sa.refc_cur,0 ); +/* Can't start after bno */ +if (rc.rc_startblock > agbno) +xchk_btree_xref_set_corrupt (sc, sc->sa.refc_cur,0 ); +/* Must be at least as long as what was passed in */ -if (rc.rc_blockcount < len) +if (rc.rc_startblock + rc.rc_blockcount < agbno + len)xchk_btree_xref_set_corrupt (sc, sc->sa.refc_cur,0 ); }
Greg Kroah-Hartman
maintainerPATCH 780/877 xfs: remove the i_ino field in struct xfs_inode
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christoph Hellwig <[email protected]>
[ Upstream commit 1113a6d6d5d1336f4415fa1367aac0f853f0892d ]
Now that the VFS inode has a u64 i_ino field, there is no need to store a copy of the inode number in the xfs_inode structure.
Introduce an I_INO() wrapper as a shortcut to the inode number so that we don't have to propagate the VFS inode everywhere.
The only non-obvious part is the clearing of i_ino to 0 for RCU freeing the inode. None of this calls into VFS paths, which makes clearing the VFS inode field here just as safe as clearing the old field in the xfs_inode.
[6.12 dependency adaptation]
Keep only the inode-number accessor spelling needed for the attr and directory repair hunks of 4d3c07591534517c633945c8d8e6526f10e3fabc to apply cleanly. Define I_INO as a macro over xfs_inode.i_ino and convert only the two xfs_da_args.owner initializers in xrep_xattr_swap_prep and xrep_dir_swap_prep. No functions are added.
Unlike upstream, this stable tree still has an unsigned long VFS i_ino. Retain the separate 64-bit XFS inode number and all existing allocation, reinitialization, reclaim, and VFS setup behavior to avoid truncation on 32-bit systems. Drop the remaining tree-wide conversions, including changes to metadata-directory, realtime, and health-monitor files that do not exist in this tree. The accessor and the two substitutions are behavior preserving; the reservation fix remains in the target commit.
Original upstream rationale follows:
Now that the VFS inode has a u64 i_ino field, there is no need to store a copy of the inode number in the xfs_inode structure.
Introduce an I_INO() wrapper as a shortcut to the inode number so that we don't have to propagate the VFS inode everywhere.
The only non-obvious part is the clearing of i_ino to 0 for RCU freeing the inode. None of this calls into VFS paths, which makes clearing the VFS inode field here just as safe as clearing the old field in the xfs_inode.
[ sashal: Reduced backport -- upstream 1113a6d6d5d13 touches 91 file(s), this
backport carries 3. Not backported here:
fs/xfs/libxfs/xfs_attr.c
fs/xfs/libxfs/xfs_attr_leaf.c
fs/xfs/libxfs/xfs_bmap_btree.c
fs/xfs/libxfs/xfs_bmap.c
fs/xfs/libxfs/xfs_btree.c
fs/xfs/libxfs/xfs_btree_staging.c
fs/xfs/libxfs/xfs_da_btree.c
fs/xfs/libxfs/xfs_dir2.c
... and 80 more
This note is generated from the file lists only; see the resolution record for the reasoning. ]
Stable-dep-of: 4d3c07591534 ("xfs: fix under-reservation of blocks when repairing sf directories")
--- fs/xfs/scrub/attr_repair.c | 2 +- fs/xfs/scrub/dir_repair.c | 2 +- fs/xfs/xfs_inode.h | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-)
fs/xfs/scrub/attr_repair.c +1 -1
@@ -1295,7 +1295,7 @@ xrep_xattr_swap_prep( .whichfork = XFS_ATTR_FORK, .trans = sc->tp, .total = 1, - .owner = sc->ip->i_ino, + .owner = I_INO(sc->ip), }; error =xfs_attr_shortform_to_leaf (&args);
fs/xfs/scrub/dir_repair.c +1 -1
@@ -1487,7 +1487,7 @@ xrep_dir_swap_prep( .whichfork = XFS_DATA_FORK, .trans = sc->tp, .total = 1, - .owner = sc->ip->i_ino, + .owner = I_INO(sc->ip), }; error =xfs_dir2_sf_to_block (&args);
fs/xfs/xfs_inode.h +3 -0
@@ -178,6 +178,9 @@ static inline const struct inode *VFS_ICreturn &ip->i_vnode; } +/* Keep the full inode number on systems with a 32-bit VFS i_ino. */ +#define I_INO (ip) ((ip)->i_ino) +/* * For regular files we only update the on-disk filesize when actually * writing data back to disk. Until then only the copy in the VFS inode
Greg Kroah-Hartman
maintainerPATCH 781/877 xfs: fix under-reservation of blocks when repairing sf directories
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Darrick J. Wong" <[email protected]>
[ Upstream commit 4d3c07591534517c633945c8d8e6526f10e3fabc ]
Whilst running QA on XFS for-next as of 7.3-rc2 with MKFS_OPTIONS="-n size=8192", I observed the following (trimmed) dmesg splat:
XFS: Assertion failed: args->total >= dp->i_nblocks - nblks, file: fs/xfs/libxfs/xfs_da_btree.c, line: 2387
WARNING: fs/xfs/xfs_message.c:104 at assfail+0x46/0x4a [xfs], CPU#0: xfs_scrub/1426511 CPU: 0 UID: 0 PID: 1426511 Comm: xfs_scrub Tainted: G W 7.3.0-rc2-djwx #rc2 PREEMPT(lazy) 6e418570b606a39783b0e7e7b30dc407b965f9e8 Tainted: [W]=WARN RIP: 0010:assfail+0x46/0x4a [xfs] RSP: 0018:ffffc900010d7890 EFLAGS: 00010246 RAX: 0000000000000000 RBX: 0000000000000000 RCX: 00000000ffffffd1 RDX: 0000000000000000 RSI: 0000000000000021 RDI: ffffffffa059fd38 RBP: 0000000000000002 R08: 0000000000000000 R09: 0000000000000000 R10: 000000000000000a R11: 000000007fffffff R12: ffffc900010d7940 R13: ffff888368d8f980 R14: ffffc900010d7a48 R15: ffffc900010d78d0 FS: 00007f445c5ce680(0000) GS:ffff8884a97ea000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f443803b9a8 CR3: 0000000107a4b000 CR4: 00000000003506f0 Call Trace: <TASK> xfs_da_grow_inode_int+0x2e0/0x300 [xfs 5de2257e14108c136f11317e6bbb8ac77efd392c] xfs_dir2_grow_inode+0x6e/0x150 [xfs 5de2257e14108c136f11317e6bbb8ac77efd392c] xfs_dir2_sf_to_block+0x149/0x870 [xfs 5de2257e14108c136f11317e6bbb8ac77efd392c] xrep_dir_swap_prep+0xe2/0x110 [xfs 5de2257e14108c136f11317e6bbb8ac77efd392c] xrep_dir_swap+0xfb/0x2f0 [xfs 5de2257e14108c136f11317e6bbb8ac77efd392c] xrep_dir_rebuild_tree+0x99/0x100 [xfs 5de2257e14108c136f11317e6bbb8ac77efd392c] xrep_directory+0x83/0x1c0 [xfs 5de2257e14108c136f11317e6bbb8ac77efd392c] xrep_attempt+0x4f/0x1e0 [xfs 5de2257e14108c136f11317e6bbb8ac77efd392c] xfs_scrub_metadata+0x393/0x5b0 [xfs 5de2257e14108c136f11317e6bbb8ac77efd392c] xfs_ioc_scrubv_metadata+0x306/0x570 [xfs 5de2257e14108c136f11317e6bbb8ac77efd392c] xfs_file_ioctl+0xa4f/0x1150 [xfs 5de2257e14108c136f11317e6bbb8ac77efd392c] __x64_sys_ioctl+0x76/0xc0 do_syscall_64+0x7a/0x3b0 entry_SYSCALL_64_after_hwframe+0x4b/0x53
This is a consequence of commit 0fe77e57588b98, which added the following assertion to xfs_da_grow_inode_int:
ASSERT(args->total >= dp->i_nblocks - nblks);
Tracing this back to xrep_dir_swap_prep, I noticed that the xfs_da_args object that's passed to xfs_dir2_sf_to_block sets args->total to 1. This is incorrect because mkfs set the directory block size to 8k and the filesystem block size to 4k. In other words, args->total should be 2 here, not 1.
Dave Chinner tripped over the same problem with the same branch through a different channel -- his test setup set the fs block size to 1k, in which case the directory block size is still set to 4k. Here, args->total should be 4.
Changing the assignment of args->total to sc->mp->m_dir_geo->fsbcount makes the assertion go away, but that isn't a complete fix. In xrep_tempexch_estimate, we also incorrectly assume that a shortform conversion requires 1 fsblock when it should be m_dir_geo->fsbcount. Without that, we can under-reserve space in the transaction and cause a filesystem shutdown.
Note that the xfs_dabuf_nfsb helper will compute the correct value for directories and xattr, so we use that instead of open-coding the logic. Also fix xrep_xattr_swap_prep to assign args->total via xfs_dabuf_nfsb to avoid one logic bomb if we ever support multi-fsblock attrs.
--- fs/xfs/libxfs/xfs_da_btree.c | 2 +- fs/xfs/libxfs/xfs_da_btree.h | 2 ++ fs/xfs/scrub/attr_repair.c | 2 +- fs/xfs/scrub/dir_repair.c | 2 +- fs/xfs/scrub/tempfile.c | 29 ++++++++++++++++++++++------- 5 files changed, 27 insertions(+), 10 deletions(-)
fs/xfs/libxfs/xfs_da_btree.c +1 -1
@@ -130,7 +130,7 @@ xfs_da_state_reset( state->mp = state->args->dp->i_mount; } -static inline int xfs_dabuf_nfsb (struct xfs_mount *mp,int whichfork) +inline int xfs_dabuf_nfsb (struct xfs_mount *mp,int whichfork) {if (whichfork ==XFS_DATA_FORK )return mp->m_dir_geo->fsbcount;
fs/xfs/libxfs/xfs_da_btree.h +2 -0
@@ -242,4 +242,6 @@ xfs_failaddr_t xfs_da3_node_header_checkextern struct kmem_cache *xfs_da_state_cache; +int xfs_dabuf_nfsb (struct xfs_mount *mp,int whichfork); +#endif /* __XFS_DA_BTREE_H__ */
fs/xfs/scrub/attr_repair.c +1 -1
@@ -1294,7 +1294,7 @@ xrep_xattr_swap_prep( .geo = sc->mp->m_attr_geo, .whichfork = XFS_ATTR_FORK, .trans = sc->tp, - .total = 1, + .total = xfs_dabuf_nfsb(sc->mp, XFS_ATTR_FORK), .owner = I_INO(sc->ip), };
fs/xfs/scrub/dir_repair.c +1 -1
@@ -1486,7 +1486,7 @@ xrep_dir_swap_prep( .geo = sc->mp->m_dir_geo, .whichfork = XFS_DATA_FORK, .trans = sc->tp, - .total = 1, + .total = xfs_dabuf_nfsb(sc->mp, XFS_DATA_FORK), .owner = I_INO(sc->ip), };
fs/xfs/scrub/tempfile.c +22 -7
@@ -536,6 +536,19 @@ xrep_tempexch_prep_request(return 0 ; } +static inline unsigned int +xrep_tempexch_estimate_sf_resblks ( +struct xfs_scrub *sc, +int whichfork) +{ +/* repairing a symlink target */ +if (S_ISLNK (VFS_I (sc->ip)->i_mode) && whichfork ==XFS_DATA_FORK ) +return 1 ; + +/* everything else is a directory or an xattr structure */ +return xfs_dabuf_nfsb (sc->mp, whichfork); +} +/* * Fill out the mapping exchange resource estimation structures in preparation * for exchanging the contents of a metadata file that we've rebuilt in the
@@ -550,6 +563,8 @@ xrep_tempexch_estimate(struct xfs_ifork *ifp;struct xfs_ifork *tifp;int whichfork =xfs_exchmaps_reqfork (req); +unsigned int sf_resblks = +xrep_tempexch_estimate_sf_resblks (sc, whichfork);int state =0 ;/*
@@ -580,9 +595,9 @@ xrep_tempexch_estimate(* plus the block we converted. */ req->ip1_bcount = sc->tempip->i_nblocks; - req->ip2_bcount =1 ; + req->ip2_bcount = sf_resblks; req->nr_exchanges =1 + tifp->if_nextents; - req->resblks =1 ; + req->resblks = sf_resblks;break ;case 2 :/*
@@ -594,10 +609,10 @@ xrep_tempexch_estimate(* is (worst case) the extent count of the file being repaired * plus the block we converted. */ - req->ip1_bcount =1 ; + req->ip1_bcount = sf_resblks; req->ip2_bcount = sc->ip->i_nblocks; req->nr_exchanges =1 + ifp->if_nextents; - req->resblks =1 ; + req->resblks = sf_resblks;break ;case 3 :/*
@@ -609,10 +624,10 @@ xrep_tempexch_estimate(* fileoff 0. Presumably, the caller could not exchange the * two inode fork areas directly. */ - req->ip1_bcount =1 ; - req->ip2_bcount =1 ; + req->ip1_bcount = sf_resblks; + req->ip2_bcount = sf_resblks; req->nr_exchanges =1 ; - req->resblks =2 ; + req->resblks =2 * sf_resblks;break ; }
Greg Kroah-Hartman
maintainerPATCH 782/877 xfs: fix backwards mergeability logic in refcount scrubber
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Darrick J. Wong" <[email protected]>
[ Upstream commit e8b01aaafffe6b852325debdf1ef4b13ccea1cd7 ]
When we start the refcount or rtrefcount btree scanners, prev_rec is initialized to all zeroes. This is done so that the record mergeability checks skip the first record because you must have two records to compare. Unfortunately, I got the logic backwards, so scrub has never complained about mergeable refcountbt records. Fix this bug that LOLLM noticed.
--- fs/xfs/scrub/refcount.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/scrub/refcount.c +1 -1
@@ -411,7 +411,7 @@ xchk_refcount_mergeable(const struct xfs_refcount_irec *r1 = &rrc->prev_rec;/* Ignore if prev_rec is not yet initialized. */ -if (r1->rc_blockcount >0 ) +if (r1->rc_blockcount ==0 )return false;if (r1->rc_domain != r2->rc_domain)
Greg Kroah-Hartman
maintainerPATCH 783/877 cifs: Fix specification of function pointers
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit 6a86a4cc281a5cfceda7af60ea6fa506b3db7430 ]
Change the mid_receive_t, mid_callback_t and mid_handle_t function pointers to have the pointer marker in the typedef.
Stable-dep-of: c60ae98c5aa6 ("9p: Fix v9fs_issue_write() to update i_size and remote_i_size")
--- fs/smb/client/cifsglob.h | 12 ++++++------ fs/smb/client/cifsproto.h | 8 ++++---- fs/smb/client/transport.c | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-)
fs/smb/client/cifsglob.h +6 -6
@@ -1619,7 +1619,7 @@ static inline void cifs_stats_bytes_read* Returns zero on a successful receive, or an error. The receive state in * the TCP_Server_Info will also be updated. */ -typedef int (mid_receive_t )(struct TCP_Server_Info *server, +typedef int (*mid_receive_t )(struct TCP_Server_Info *server,struct mid_q_entry *mid);/*
@@ -1630,13 +1630,13 @@ typedef int (mid_receive_t)(struct TCP_S* - it will be called by cifsd, with no locks held * - the mid will be removed from any lists */ -typedef void (mid_callback_t )(struct mid_q_entry *mid); +typedef void (*mid_callback_t )(struct mid_q_entry *mid);/* * This is the protopyte for mid handle function. This is called once the mid * has been recognized after decryption of the message. */ -typedef int (mid_handle_t )(struct TCP_Server_Info *server, +typedef int (*mid_handle_t )(struct TCP_Server_Info *server,struct mid_q_entry *mid);/* one of these for every pending CIFS request to the server */
@@ -1654,9 +1654,9 @@ struct mid_q_entry {unsigned long when_sent;/* time when smb send finished */ unsigned long when_received;/* when demux complete (taken off wire) */ #endif -mid_receive_t *receive;/* call receive callback */ -mid_callback_t *callback;/* call completion callback */ -mid_handle_t *handle;/* call handle mid callback */ +mid_receive_t receive;/* call receive callback */ +mid_callback_t callback;/* call completion callback */ +mid_handle_t handle;/* call handle mid callback */ void *callback_data;/* general purpose pointer for callback */ struct task_struct *creator;void *resp_buf;/* pointer to received SMB header */
fs/smb/client/cifsproto.h +4 -4
@@ -96,10 +96,10 @@ extern int cifs_ipaddr_cmp(struct sockadextern bool cifs_match_ipaddr (struct sockaddr *srcaddr,struct sockaddr *rhs);extern int cifs_discard_remaining_data (struct TCP_Server_Info *server);extern int cifs_call_async (struct TCP_Server_Info *server, -struct smb_rqst *rqst, -mid_receive_t *receive,mid_callback_t *callback, -mid_handle_t *handle,void *cbdata,const int flags, -const struct cifs_credits *exist_credits); +struct smb_rqst *rqst, +mid_receive_t receive,mid_callback_t callback, +mid_handle_t handle,void *cbdata,const int flags, +const struct cifs_credits *exist_credits);extern struct TCP_Server_Info *cifs_pick_channel (struct cifs_ses *ses); extern int cifs_send_recv(const unsigned int xid, struct cifs_ses *ses, struct TCP_Server_Info *server,
fs/smb/client/transport.c +2 -2
@@ -792,8 +792,8 @@ cifs_setup_async_request(struct TCP_Serv*/ int cifs_call_async (struct TCP_Server_Info *server,struct smb_rqst *rqst, -mid_receive_t *receive,mid_callback_t *callback, -mid_handle_t *handle,void *cbdata,const int flags, +mid_receive_t receive,mid_callback_t callback, +mid_handle_t handle,void *cbdata,const int flags,const struct cifs_credits *exist_credits) {int rc;
Greg Kroah-Hartman
maintainerPATCH 784/877 9p: Fix v9fs_issue_write() to update i_size and remote_i_size
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit c60ae98c5aa64021751b38ab1313b19d620bf640 ]
Fix v9fs_issue_write() to update i_size and remote_i_size to the new size of the server file if we made it larger, using the start fpos and the count returned by p9_client_write() to calculate the new minimum file size.
This assumes that if the 9P server makes a short write (say it hits ENOSPC), a reduced count is returned.
Message-ID: <[email protected]>
--- fs/9p/vfs_addr.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
fs/9p/vfs_addr.c +12 -0
@@ -54,9 +54,21 @@ static void v9fs_begin_writeback(structstatic void v9fs_issue_write (struct netfs_io_subrequest *subreq) {struct p9_fid *fid = subreq->rreq->netfs_priv; +struct inode *inode = subreq->rreq->inode; +struct netfs_inode *ictx =netfs_inode (inode);int err, len; len =p9_client_write (fid, subreq->start, &subreq->io_iter, &err); +if (len >0 ) { +unsigned long long end = subreq->start + len; + +spin_lock (&inode->i_lock); +if (end >i_size_read (inode)) +i_size_write (inode, end); +if (end > ictx->remote_i_size) + ictx->remote_i_size = end; +spin_unlock (&inode->i_lock); + }netfs_write_subrequest_terminated (subreq, len ?: err, false); }
Greg Kroah-Hartman
maintainerPATCH 785/877 phy: renesas: rcar-gen3-usb2: Avoid long delay in atomic context
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Claudiu Beznea <[email protected]>
[ Upstream commit 48e97c59a49c9e90270f5e3d221db253b76de5da ]
The OTG PHY initialization sequence needs to wait for 20 ms at a specific step, as described in commit 72c0339c115b ("phy: renesas:
rcar-gen3-usb2: follow the hardware manual procedure").
Commit 55a387ebb921 ("phy: renesas: rcar-gen3-usb2: Lock around hardware registers and driver data") tried to address various problems in the rcar-gen3-usb2 driver and converted the mutex protecting HW register accesses to a spin lock, leaving, however, a long delay in the critical section protected by the spin lock. This may become a problem, especially on RT kernels.
To address this, release the spin lock before sleeping for 20 ms as required by the HW manual and reacquire it afterwards. To avoid other threads entering the critical section and configuring the HW while the software is waiting for the OTG initialization to complete, introduce the otg_initializing variable alongside the otg_init_done wait queue. Any other thread trying to configure the HW while the OTG PHY initialization is in progress waits for the wait queue instead of immediately returning errors to PHY users. The IRQs were also disabled while waiting for the OTG PHY initialization to complete, as the interrupt handler may also apply HW settings.
The OTG can only be initialized once. It is initialized by the first PHY that calls struct phy_ops::rcar_gen3_phy_usb2_init().
To avoid failures when multiple PHYs call struct phy_ops::rcar_gen3_phy_usb2_init() simultaneously, and the PHY responsible for initializing the OTG either fails or deinit quiqly and another PHY takes over the PHY init role), the code waiting for the channel->otg_init_done wait queue retries up to NUM_OF_PHYS times.
--- drivers/phy/renesas/phy-rcar-gen3-usb2.c | 302 ++++++++++++++++++++++++++----- 1 file changed, 261 insertions(+), 41 deletions(-)
drivers/phy/renesas/phy-rcar-gen3-usb2.c +261 -41
@@ -23,6 +23,7 @@#include <linux/reset.h> #include <linux/string.h> #include <linux/usb/of.h> +#include <linux/wait.h> #include <linux/workqueue.h> /******* USB2.0 Host registers (original offset is +0x200) *******/
@@ -88,6 +89,13 @@#define USB2_OBINT_IDCHG_EN BIT(0)#define USB2_LINECTRL1_USB2_IDMON BIT(0) +/* +* The OTG initialization is expected to finish in 20ms. Choose a large enough +* timeout to avoid waiters exit prematurely the waiting section under heavy +* CPU load. +*/ +#define USB2_OTG_INIT_TIMEOUT msecs_to_jiffies(120) +#define NUM_OF_PHYS 4enum rcar_gen3_phy_index {PHY_INDEX_BOTH_HC ,
@@ -118,6 +126,7 @@ struct rcar_gen3_chan {struct rcar_gen3_phy rphys[NUM_OF_PHYS ];struct regulator *vbus;struct work_struct work; +wait_queue_head_t otg_init_done;spinlock_t lock;/* protects access to hardware and driver data structure. */ enum usb_dr_mode dr_mode;u32 obint_enable_bits;
@@ -125,6 +134,13 @@ struct rcar_gen3_chan {bool is_otg_channel;bool uses_otg_pins;bool soc_no_adp_ctrl; +/* +* The OTG can be initialized only once and needs to release the spinlock +* and wait for 20 ms due to hardware constraints. If a thread executes +* PHY configuration code while the OTG PHY is waiting for the 20 ms, the +* thread will have to wait for the OTG PHY initialization to complete. +*/ +bool otg_initializing; };struct rcar_gen3_phy_drv_data {
@@ -347,26 +363,58 @@ static ssize_t role_store(struct devicestruct rcar_gen3_chan *ch =dev_get_drvdata (dev);bool is_b_device;enum phy_mode cur_mode, new_mode; +int retries =NUM_OF_PHYS ; +unsigned long flags; +int ret = -EIO ; -guard (spinlock_irqsave)(&ch->lock); +spin_lock_irqsave (&ch->lock, flags); -if (!ch->is_otg_channel || !rcar_gen3_is_any_otg_rphy_initialized (ch)) -return -EIO ; +if (!ch->is_otg_channel) + goto unlock; -if (sysfs_streq (buf,"host" )) +while (retries-- && ch->otg_initializing) { +spin_unlock_irqrestore (&ch->lock, flags); + + ret =wait_event_timeout (ch->otg_init_done, !ch->otg_initializing, +USB2_OTG_INIT_TIMEOUT ); + ret = ret ?0 : -ETIMEDOUT ; +if (ret && !retries) + goto exit; + +spin_lock_irqsave (&ch->lock, flags); + } + +/* If another thread started a new initialization just return -EBUSY. */ +if (ch->otg_initializing) { + ret = -EBUSY ; + goto unlock; + }else { + ret =0 ; + } + +if (!rcar_gen3_is_any_otg_rphy_initialized (ch)) { + ret = -EIO ; + goto unlock; + } + +if (sysfs_streq (buf,"host" )) { new_mode =PHY_MODE_USB_HOST ; -else if (sysfs_streq (buf,"peripheral" )) + }else if (sysfs_streq (buf,"peripheral" )) { new_mode =PHY_MODE_USB_DEVICE ; -else -return -EINVAL ; + }else { + ret = -EINVAL ; + goto unlock; + }/* is_b_device: true is B-Device. false is A-Device. */ is_b_device =rcar_gen3_check_id (ch); cur_mode =rcar_gen3_get_phy_mode (ch);/* If current and new mode is the same, this returns the error */ -if (cur_mode == new_mode) -return -EINVAL ; +if (cur_mode == new_mode) { + ret = -EINVAL ; + goto unlock; + }if (new_mode ==PHY_MODE_USB_HOST ) {/* And is_host must be false */ if (!is_b_device)/* A-Peripheral */
@@ -380,7 +428,10 @@ static ssize_t role_store(struct devicercar_gen3_init_for_peri (ch); } -return count; +unlock: +spin_unlock_irqrestore (&ch->lock, flags); +exit: +return ret ?: count; } static ssize_t role_show(struct device *dev, struct device_attribute *attr,
@@ -396,14 +447,11 @@ static ssize_t role_show(struct device * }static DEVICE_ATTR_RW (role); -static void rcar_gen3_init_otg (struct rcar_gen3_chan *ch) +static void rcar_gen3_init_otg_phase0 (struct rcar_gen3_chan *ch) {void __iomem *usb2_base = ch->base;u32 val; -if (!ch->is_otg_channel ||rcar_gen3_is_any_otg_rphy_initialized (ch)) -return ; -/* Should not use functions of read-modify-write a register */ val =readl (usb2_base +USB2_LINECTRL1 ); val = (val & ~USB2_LINECTRL1_DP_RPD) | USB2_LINECTRL1_DPRPD_EN |
@@ -417,7 +465,11 @@ static void rcar_gen3_init_otg(struct rc val =readl (usb2_base +USB2_ADPCTRL );writel (val |USB2_ADPCTRL_IDPULLUP , usb2_base +USB2_ADPCTRL ); } -mdelay (20 ); +} + +static void rcar_gen3_init_otg_phase1 (struct rcar_gen3_chan *ch) +{ +void __iomem *usb2_base = ch->base;writel (0xffffffff , usb2_base +USB2_OBINTSTA );writel (ch->obint_enable_bits, usb2_base +USB2_OBINTEN );
@@ -431,6 +483,7 @@ static irqreturn_t rcar_gen3_phy_usb2_irvoid __iomem *usb2_base = ch->base;struct device *dev = ch->dev;irqreturn_t ret =IRQ_NONE ; +unsigned long flags;u32 status;pm_runtime_get_noresume (dev);
@@ -438,29 +491,98 @@ static irqreturn_t rcar_gen3_phy_usb2_irif (pm_runtime_suspended (dev)) goto rpm_put; - scoped_guard(spinlock, &ch->lock) { - status =readl (usb2_base +USB2_OBINTSTA ); -if (status & ch->obint_enable_bits) { -dev_vdbg (dev,"%s: %08x\n" , __func__, status); -writel (ch->obint_enable_bits, usb2_base +USB2_OBINTSTA ); -rcar_gen3_device_recognition (ch); - ret =IRQ_HANDLED ; - } +spin_lock_irqsave (&ch->lock, flags); + + status =readl (usb2_base +USB2_OBINTSTA ); +if (status & ch->obint_enable_bits) { +dev_vdbg (dev,"%s: %08x\n" , __func__, status); +writel (ch->obint_enable_bits, usb2_base +USB2_OBINTSTA ); + + ret =IRQ_HANDLED ; + +/* This should not happen! */ +if (ch->otg_initializing) + goto unlock; + +rcar_gen3_device_recognition (ch); } +unlock: +spin_unlock_irqrestore (&ch->lock, flags); rpm_put:pm_runtime_put_noidle (dev);return ret; } +static void rcar_gen3_phy_usb2_irqs_mask_all (struct rcar_gen3_chan *channel, +u32 *masked_irqs_bits) +{ +u32 val, bitmask =USB2_INT_ENABLE_UCOM_INTEN ; +void __iomem *usb2_base = channel->base; + +for (unsigned int i =0 ; i <NUM_OF_PHYS ; i++) + bitmask |= channel->rphys[i].int_enable_bits; + + val =readl (usb2_base +USB2_INT_ENABLE ); + *masked_irqs_bits = val & bitmask; + val &= ~bitmask; +writel (val, usb2_base +USB2_INT_ENABLE ); + +/* +* Don't report channel->obint_enable_bits IRQs. These are +* unmasked anyway in rcar_gen3_init_otg_phase1(). +*/ + val =readl (usb2_base +USB2_OBINTEN ); + val &= ~channel->obint_enable_bits; +writel (val, usb2_base +USB2_OBINTEN ); +} + +static void rcar_gen3_phy_usb2_irqs_unmask (struct rcar_gen3_chan *channel, +u32 irqs_bits) +{ +u32 val, bitmask =USB2_INT_ENABLE_UCOM_INTEN ; +void __iomem *usb2_base = channel->base; + +for (unsigned int i =0 ; i <NUM_OF_PHYS ; i++) + bitmask |= channel->rphys[i].int_enable_bits; + + val =readl (usb2_base +USB2_INT_ENABLE ); + val &= ~bitmask; + val |= irqs_bits; +writel (val, usb2_base +USB2_INT_ENABLE ); +} +static int rcar_gen3_phy_usb2_init (struct phy *p) {struct rcar_gen3_phy *rphy =phy_get_drvdata (p);struct rcar_gen3_chan *channel = rphy->ch;void __iomem *usb2_base = channel->base; +int retries =NUM_OF_PHYS ; +unsigned long flags;u32 val; +int ret; + +spin_lock_irqsave (&channel->lock, flags); + +while (retries-- && channel->otg_initializing) { +spin_unlock_irqrestore (&channel->lock, flags); -guard (spinlock_irqsave)(&channel->lock); + ret =wait_event_timeout (channel->otg_init_done, !channel->otg_initializing, +USB2_OTG_INIT_TIMEOUT ); + ret = ret ?0 : -ETIMEDOUT ; +if (ret && !retries) +return ret; + +spin_lock_irqsave (&channel->lock, flags); + } + +/* If another thread started a new initialization just return -EBUSY. */ +if (channel->otg_initializing) { + ret = -EBUSY ; + goto unlock; + }else { + ret =0 ; + }/* Initialize USB2 part */ val =readl (usb2_base +USB2_INT_ENABLE );
@@ -473,12 +595,30 @@ static int rcar_gen3_phy_usb2_init(struc }/* Initialize otg part (only if we initialize a PHY with IRQs). */ -if (rphy->int_enable_bits) -rcar_gen3_init_otg (channel); +if (rphy->int_enable_bits && channel->is_otg_channel && + !rcar_gen3_is_any_otg_rphy_initialized (channel)) { +u32 masked_irq_bits =0 ; + +rcar_gen3_init_otg_phase0 (channel); +rcar_gen3_phy_usb2_irqs_mask_all (channel, &masked_irq_bits); + channel->otg_initializing = true; +spin_unlock_irqrestore (&channel->lock, flags); + +fsleep (20000 ); + +spin_lock_irqsave (&channel->lock, flags); +rcar_gen3_phy_usb2_irqs_unmask (channel, masked_irq_bits); +rcar_gen3_init_otg_phase1 (channel); + channel->otg_initializing = false; +wake_up_all (&channel->otg_init_done); + } rphy->initialized = true; -return 0 ; +unlock: +spin_unlock_irqrestore (&channel->lock, flags); + +return ret; }static int rcar_gen3_phy_usb2_exit (struct phy *p)
@@ -486,9 +626,32 @@ static int rcar_gen3_phy_usb2_exit(strucstruct rcar_gen3_phy *rphy =phy_get_drvdata (p);struct rcar_gen3_chan *channel = rphy->ch;void __iomem *usb2_base = channel->base; +int retries =NUM_OF_PHYS ; +unsigned long flags;u32 val; +int ret; + +spin_lock_irqsave (&channel->lock, flags); + +while (retries-- && channel->otg_initializing) { +spin_unlock_irqrestore (&channel->lock, flags); -guard (spinlock_irqsave)(&channel->lock); + ret =wait_event_timeout (channel->otg_init_done, !channel->otg_initializing, +USB2_OTG_INIT_TIMEOUT ); + ret = ret ?0 : -ETIMEDOUT ; +if (ret && !retries) +return ret; + +spin_lock_irqsave (&channel->lock, flags); + } + +/* If another thread started a new initialization just return -EBUSY. */ +if (channel->otg_initializing) { + ret = -EBUSY ; + goto unlock; + }else { + ret =0 ; + } rphy->initialized = false;
@@ -498,7 +661,9 @@ static int rcar_gen3_phy_usb2_exit(struc val &= ~USB2_INT_ENABLE_UCOM_INTEN ;writel (val, usb2_base +USB2_INT_ENABLE ); -return 0 ; +unlock: +spin_unlock_irqrestore (&channel->lock, flags); +return ret; }static int rcar_gen3_phy_usb2_power_on (struct phy *p)
@@ -506,8 +671,10 @@ static int rcar_gen3_phy_usb2_power_on(sstruct rcar_gen3_phy *rphy =phy_get_drvdata (p);struct rcar_gen3_chan *channel = rphy->ch;void __iomem *usb2_base = channel->base; +int retries =NUM_OF_PHYS ; +unsigned long flags;u32 val; -int ret =0 ; +int ret;if (channel->vbus) { ret =regulator_enable (channel->vbus);
@@ -515,7 +682,27 @@ static int rcar_gen3_phy_usb2_power_on(sreturn ret; } -guard (spinlock_irqsave)(&channel->lock); +spin_lock_irqsave (&channel->lock, flags); + +while (retries-- && channel->otg_initializing) { +spin_unlock_irqrestore (&channel->lock, flags); + + ret =wait_event_timeout (channel->otg_init_done, !channel->otg_initializing, +USB2_OTG_INIT_TIMEOUT ); + ret = ret ?0 : -ETIMEDOUT ; +if (ret && !retries) + goto disable_regulator; + +spin_lock_irqsave (&channel->lock, flags); + } + +/* If another thread started a new initialization just return -EBUSY. */ +if (channel->otg_initializing) { + ret = -EBUSY ; + goto unlock; + }else { + ret =0 ; + }if (!rcar_gen3_are_all_rphys_power_off (channel)) goto out;
@@ -530,27 +717,59 @@ out:/* The powered flag should be set for any other phys anyway */ rphy->powered = true; -return 0 ; +unlock: +spin_unlock_irqrestore (&channel->lock, flags); + +disable_regulator: +if (ret && channel->vbus) +regulator_disable (channel->vbus); + +return ret; }static int rcar_gen3_phy_usb2_power_off (struct phy *p) {struct rcar_gen3_phy *rphy =phy_get_drvdata (p);struct rcar_gen3_chan *channel = rphy->ch; -int ret =0 ; +int retries =NUM_OF_PHYS ; +unsigned long flags; +int ret; - scoped_guard(spinlock_irqsave, &channel->lock) { - rphy->powered = false; +spin_lock_irqsave (&channel->lock, flags); -if (rcar_gen3_are_all_rphys_power_off (channel)) { -u32 val =readl (channel->base +USB2_USBCTR ); +while (retries-- && channel->otg_initializing) { +spin_unlock_irqrestore (&channel->lock, flags); - val |=USB2_USBCTR_PLL_RST ; -writel (val, channel->base +USB2_USBCTR ); - } + ret =wait_event_timeout (channel->otg_init_done, !channel->otg_initializing, +USB2_OTG_INIT_TIMEOUT ); + ret = ret ?0 : -ETIMEDOUT ; +if (ret && !retries) +return ret; + +spin_lock_irqsave (&channel->lock, flags); + } + +/* If another thread started a new initialization just return -EBUSY. */ +if (channel->otg_initializing) { + ret = -EBUSY ; + goto unlock; + }else { + ret =0 ; + } + + rphy->powered = false; + +if (rcar_gen3_are_all_rphys_power_off (channel)) { +u32 val =readl (channel->base +USB2_USBCTR ); + + val |=USB2_USBCTR_PLL_RST ; +writel (val, channel->base +USB2_USBCTR ); } -if (channel->vbus) +unlock: +spin_unlock_irqrestore (&channel->lock, flags); + +if (!ret && channel->vbus) ret =regulator_disable (channel->vbus);return ret;
@@ -774,6 +993,7 @@ static int rcar_gen3_phy_usb2_probe(stru channel->obint_enable_bits =USB2_OBINT_IDCHG_EN ;spin_lock_init (&channel->lock); +init_waitqueue_head (&channel->otg_init_done);for (i =0 ; i <NUM_OF_PHYS ; i++) { channel->rphys[i].phy =devm_phy_create (dev,NULL , phy_data->phy_usb2_ops);
Greg Kroah-Hartman
maintainerPATCH 786/877 ALSA: usb-audio: Optimize the copy of packet sizes for implicit fb handling
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit 36adb51ac0b19edb32ffeea3fe66b174bad25ead ]
We did manual copies over loop for the packet data update of the implicit feedback, but this can be optimized with a simple memcpy().
Along with it, change the data type of snd_usb_packet_info struct to align with other (from uint32_t to int).
No functional changes but only code optimizations.
Stable-dep-of: 76a986c980bb ("ALSA: usb-audio: Clamp implicit feedback packet count to URB capacity")
--- sound/usb/card.h | 2 +- sound/usb/endpoint.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)
sound/usb/card.h +1 -1
@@ -89,7 +89,7 @@ struct snd_usb_endpoint {struct snd_urb_ctx urb[MAX_URBS ];struct snd_usb_packet_info { -uint32_t packet_size[MAX_PACKS_HS ]; +int packet_size[MAX_PACKS_HS ];int packets; } next_packet[MAX_URBS ];unsigned int next_packet_head;/* ring buffer offset to read */
sound/usb/endpoint.c +3 -3
@@ -478,7 +478,7 @@ int snd_usb_queue_pending_output_urbs(stunsigned long flags;struct snd_usb_packet_info *packet;struct snd_urb_ctx *ctx =NULL ; -int err, i; +int err;spin_lock_irqsave (&ep->lock, flags); if ((!implicit_fb || ep->next_packet_queued > 0) &&
@@ -498,8 +498,8 @@ int snd_usb_queue_pending_output_urbs(st/* copy over the length information */ if (implicit_fb) { ctx->packets = packet->packets; -for (i =0 ; i < packet->packets; i++) - ctx->packet_size[i] = packet->packet_size[i]; +memcpy (ctx->packet_size, packet->packet_size, + packet->packets *sizeof (packet->packet_size[0 ])); }/* call the data handler to fill in playback data */
Greg Kroah-Hartman
maintainerPATCH 787/877 ALSA: usb-audio: Clamp implicit feedback packet count to URB capacity
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiang Mei <[email protected]>
[ Upstream commit 76a986c980bb502c7688d605ac7a67fd257a9a1b ]
data_ep_set_params() allocates each data URB for exactly u->packets isochronous frames, so urb->iso_frame_desc[] has u->packets slots and ctx->packets is the driver's only record of that limit. For an implicit feedback sink, snd_usb_queue_pending_output_urbs() overwrites it with the sync source's packet count, which is calculated independently from the capture endpoint's parameters. When that count is larger, prepare_playback_urb() and prepare_silent_urb() can write iso_frame_desc[] past the allocation; their existing bounds limit payload bytes, not the descriptor index.
The reproducer uses a high-speed UAC2 device declaring bInterval 1 for implicit feedback capture (8 packets) and bInterval 4 for playback (1 packet). On the first capture completion after the stream starts, it accesses seven descriptors spanning 112 bytes beyond the one-packet URB:
BUG: KASAN: slab-out-of-bounds in prepare_playback_urb (sound/usb/pcm.c:1560) Write of size 4 at addr ffff88801e696ad0 by task vhci_rx/178 prepare_playback_urb (sound/usb/pcm.c:1560) prepare_outbound_urb (sound/usb/endpoint.c:340) snd_usb_queue_pending_output_urbs (sound/usb/endpoint.c:501) snd_complete_urb (sound/usb/endpoint.c:1834) __usb_hcd_giveback_urb (drivers/usb/core/hcd.c:1657) usb_hcd_giveback_urb (drivers/usb/core/hcd.c:1741) vhci_rx_loop (drivers/usb/usbip/vhci_rx.c:107) kthread (kernel/kthread.c:436) The buggy address belongs to the object at ffff88801e696a00 which belongs to the cache kmalloc-256 of size 256 The buggy address is located 0 bytes to the right of allocated 208-byte region [ffff88801e696a00, ffff88801e696ad0)
Record the allocated packet count per endpoint and clamp both the adopted count and the packet-size copy to it. Fold the Format Type II delimiter into urb_packs before the allocation loop so the recorded limit matches every URB.
--- sound/usb/card.h | 1 + sound/usb/endpoint.c | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-)
sound/usb/card.h +1 -0
@@ -115,6 +115,7 @@ struct snd_usb_endpoint {unsigned int phase;/* phase accumulator */ unsigned int maxpacksize;/* max packet size in bytes */ unsigned int maxframesize;/* max packet size in frames */ +unsigned int max_urb_packs;/* packets allocated per data URB */ unsigned int max_urb_frames;/* max URB size in frames */ unsigned int curpacksize;/* current packet size in bytes (for capture) */ unsigned int curframesize;/* current packet size in frames (for capture) */
sound/usb/endpoint.c +7 -5
@@ -497,9 +497,10 @@ int snd_usb_queue_pending_output_urbs(st/* copy over the length information */ if (implicit_fb) { - ctx->packets = packet->packets; + ctx->packets =min_t (int, packet->packets, + ep->max_urb_packs);memcpy (ctx->packet_size, packet->packet_size, - packet->packets *sizeof (packet->packet_size[0 ])); + ctx->packets *sizeof (packet->packet_size[0 ])); }/* call the data handler to fill in playback data */
@@ -1259,15 +1260,16 @@ static int data_ep_set_params(struct snd ep->nurbs =min (max_urbs, urbs_per_period * ep->cur_buffer_periods); } +if (fmt->fmt_type ==UAC_FORMAT_TYPE_II ) + urb_packs++;/* for transfer delimiter */ + ep->max_urb_packs = urb_packs; +/* allocate and initialize data urbs */ for (i =0 ; i < ep->nurbs; i++) {struct snd_urb_ctx *u = &ep->urb[i]; u->index = i; u->ep = ep; u->packets = urb_packs; - -if (fmt->fmt_type ==UAC_FORMAT_TYPE_II ) - u->packets++;/* for transfer delimiter */ u->buffer_size = maxsize * u->packets; u->urb =usb_alloc_urb (u->packets,GFP_KERNEL );if (!u->urb)
Greg Kroah-Hartman
maintainerPATCH 788/877 swiotlb: use the adjusted address for the highmem page lookup
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Donggeun Yoo <[email protected]>
[ Upstream commit b7d7914a9ae3097e63d113007e4fb44d33d515b1 ]
swiotlb_bounce() reads the page frame number from the slot's recorded orig_addr, then advances orig_addr by tlb_offset to reach the address the caller asked about. The highmem branch mixes the two: the offset within the page comes from the adjusted address, the page from the value before it.
Once the adjustment crosses a page boundary the pair no longer describes one location, and the whole copy lands one page below the intended one for a positive tlb_offset, one above for a negative one. DMA_FROM_DEVICE writes the device data over the wrong page and leaves the intended one stale, DMA_TO_DEVICE feeds the device from a page the mapping may not cover. Partial syncs through dma_sync_single_range_for_*() are what make tlb_offset non-zero.
The branch test is picked the same way, so a slot recorded in lowmem can be adjusted into highmem and the lowmem path then hands a highmem address to phys_to_virt().
Take both from orig_addr once it is final and keep pfn in the branch that uses it. PhysHighMem() asks the question straight from the address, as dma-debug already does.
--- kernel/dma/swiotlb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/dma/swiotlb.c +2 -2
@@ -869,7 +869,6 @@ static void swiotlb_bounce(struct deviceint index = (tlb_addr - mem->start) >>IO_TLB_SHIFT ;phys_addr_t orig_addr = mem->slots[index].orig_addr;size_t alloc_size = mem->slots[index].alloc_size; -unsigned long pfn =PFN_DOWN (orig_addr);unsigned char *vaddr = mem->vaddr + tlb_addr - mem->start;int tlb_offset;
@@ -899,7 +898,8 @@ static void swiotlb_bounce(struct device size = alloc_size; } -if (PageHighMem (pfn_to_page (pfn))) { +if (PageHighMem (pfn_to_page (PFN_DOWN (orig_addr)))) { +unsigned long pfn =PFN_DOWN (orig_addr);unsigned int offset = orig_addr & ~PAGE_MASK ;struct page *page;unsigned int sz =0 ;
Greg Kroah-Hartman
maintainerPATCH 789/877 net: phy: mediatek: do not report link and per-speed LED rules together
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ahmed Naseef <[email protected]>
[ Upstream commit bde5212360bd44506edec073ebbd6d0c72f75820 ]
mtk_phy_led_hw_ctrl_get() reports TRIGGER_NETDEV_LINK whenever any of the speed bits in on_set is on, and in addition reports every individual TRIGGER_NETDEV_LINK_* bit that is set. The netdev trigger refuses that
combination: netdev_led_attr_store() rejects TRIGGER_NETDEV_LINK together with any per-speed rule, and it validates the whole resulting mode rather than just the bit being written. Once the hardware has any link bit programmed, every write to the trigger attributes of that LED therefore fails with -EINVAL and the LED can no longer be configured.
The rules are also fed back into the hardware: the trigger stores what is read back, and a later write of device_name programs it again, expanding TRIGGER_NETDEV_LINK to every speed in on_set. An LED configured for a single speed is thereby silently widened to "on at any link speed".
Both are easy to see on the EcoNet EN7528, whose four PHYs share one LED block. The first LED programs the block correctly, the second reads those rules back and rewrites them widened, and the remaining two then read the widened value, so an LED configured for "link_10 link_100" ends up lit on a 1000 Mbps link.
on_set holds every speed the LED can indicate and is exactly what mtk_phy_led_hw_ctrl_set() programs for TRIGGER_NETDEV_LINK, so report the speed independent rule only when all of them are on, and the individual speeds otherwise. The mapping is then the inverse of the one used when programming the LED and round trips without changing the register.
--- drivers/net/phy/mediatek/mtk-ge-soc.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-)
drivers/net/phy/mediatek/mtk-ge-soc.c +15 -8
@@ -1276,17 +1276,24 @@ static int mt798x_phy_led_hw_control_getif (!rules)return 0 ; -if (on &MTK_PHY_LED_ON_LINK ) +/* TRIGGER_NETDEV_LINK must not be reported together with any of the +* per-speed rules, the netdev trigger rejects that combination. +* MTK_PHY_LED_ON_LINK holds every speed this LED can indicate and is what +* mt798x_phy_led_hw_control_set() programs for TRIGGER_NETDEV_LINK, so +* report the speed independent rule only when they are all on. +*/ +if ((on &MTK_PHY_LED_ON_LINK ) ==MTK_PHY_LED_ON_LINK ) { *rules |=BIT (TRIGGER_NETDEV_LINK ); + }else { +if (on &MTK_PHY_LED_ON_LINK10 ) + *rules |=BIT (TRIGGER_NETDEV_LINK_10 ); -if (on &MTK_PHY_LED_ON_LINK10 ) - *rules |=BIT (TRIGGER_NETDEV_LINK_10 ); +if (on &MTK_PHY_LED_ON_LINK100 ) + *rules |=BIT (TRIGGER_NETDEV_LINK_100 ); -if (on &MTK_PHY_LED_ON_LINK100 ) - *rules |=BIT (TRIGGER_NETDEV_LINK_100 ); - -if (on &MTK_PHY_LED_ON_LINK1000 ) - *rules |=BIT (TRIGGER_NETDEV_LINK_1000 ); +if (on &MTK_PHY_LED_ON_LINK1000 ) + *rules |=BIT (TRIGGER_NETDEV_LINK_1000 ); + }if (on &MTK_PHY_LED_ON_FDX ) *rules |=BIT (TRIGGER_NETDEV_FULL_DUPLEX );
Greg Kroah-Hartman
maintainerPATCH 790/877 btrfs: take commit root semaphore when iterating in mark_block_group_to_copy()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hongling Zeng <[email protected]>
[ Upstream commit 0594e3423f4ba3137c734371169491f9a98e9af4 ]
mark_block_group_to_copy() iterates over the commit root with skip_locking=true. A concurrent transaction commit can swap and free the commit root during iteration, causing use-after-free when accessing extent buffers.
Fix it by using path->need_commit_sem to protect the commit root search.
--- fs/btrfs/dev-replace.c | 1 + 1 file changed, 1 insertion(+)
fs/btrfs/dev-replace.c +1 -0
@@ -505,6 +505,7 @@ static int mark_block_group_to_copy(stru path->reada =READA_FORWARD ; path->search_commit_root =1 ; path->skip_locking =1 ; + path->need_commit_sem =1 ; key.objectid = src_dev->devid; key.type =BTRFS_DEV_EXTENT_KEY ;
Greg Kroah-Hartman
maintainerPATCH 791/877 arm64: Use load LSE atomics for the non-return per-CPU atomic operations
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Catalin Marinas <[email protected]>
[ Upstream commit 535fdfc5a228524552ee8810c9175e877e127c27 ]
The non-return per-CPU this_cpu_*() atomic operations are implemented as STADD/STCLR/STSET when FEAT_LSE is available. On many microarchitecture implementations, these instructions tend to be executed "far" in the interconnect or memory subsystem (unless the data is already in the L1 cache). This is in general more efficient when there is contention as it avoids bouncing cache lines between CPUs. The load atomics (e.g. LDADD without XZR as destination), OTOH, tend to be executed "near" with the data loaded into the L1 cache.
STADD executed back to back as in srcu_read_{lock,unlock}*() incur an additional overhead due to the default posting behaviour on several CPU implementations. Since the per-CPU atomics are unlikely to be used concurrently on the same memory location, encourage the hardware to to execute them "near" by issuing load atomics - LDADD/LDCLR/LDSET - with the destination register unused (but not XZR).
Stable-dep-of: 8cf2093f5372 ("arm64: percpu: Fix LSE operations on {8,16}-bit types")
--- arch/arm64/include/asm/percpu.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
arch/arm64/include/asm/percpu.h +11 -4
@@ -77,7 +77,7 @@ __percpu_##name##_case_##sz(void *ptr, u " stxr" #sfx "\t%w[loop], %" #w "[tmp], %[ptr]\n" \ " cbnz %w[loop], 1b", \ /* LSE atomics */ \ -#op_lse "\t%" #w "[val], %[ptr]\n" \ +#op_lse "\t%" #w "[val], %" #w "[tmp], %[ptr]\n" \ __nops(3)) \ : [loop] "=&r" (loop), [tmp] "=&r" (tmp), \ [ptr] "+Q"(*(u##sz *)ptr) \
@@ -124,9 +124,16 @@ PERCPU_RW_OPS(8) PERCPU_RW_OPS(16) PERCPU_RW_OPS(32)PERCPU_RW_OPS (64 ) -PERCPU_OP(add, add, stadd) -PERCPU_OP(andnot, bic, stclr) -PERCPU_OP(or, orr, stset) + +/* +* Use value-returning atomics for CPU-local ops as they are more likely +* to execute "near" to the CPU (e.g. in L1$). +* +* https://lore.kernel.org/r/e7d539ed-ced0-4b96-8ecd-048a5b803b85@paulmck-laptop + */ +PERCPU_OP(add, add, ldadd) +PERCPU_OP(andnot, bic, ldclr) +PERCPU_OP(or, orr, ldset) PERCPU_RET_OP(add, add, ldadd)#undef PERCPU_RW_OPS
Greg Kroah-Hartman
maintainerPATCH 792/877 arm64: percpu: Fix LSE operations on {8,16}-bit types
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mark Rutland <[email protected]>
[ Upstream commit 8cf2093f5372952a9ebc805c418d45df7112cd14 ]
The assembly for __percpu_##name##_case_##sz() and __percpu_##name##_return_case_##sz() doesn't use the 'sfx' macro argument to form the LSE instruction. Without 'sfx', a W register argument will imply a 32-bit memory location, and consequently {8,16}-bit ops will erroneously read and write 32 bits of memory when the LSE instruction is used.
Fix this by appending 'sfx' to 'op_lse' to LSE instruction. It is not necessary (and not valid) to append 'sfx' to 'op_llsc', as 'op_llsc' is a register-register operation which does not access memory (and does not take a size suffix).
--- arch/arm64/include/asm/percpu.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/include/asm/percpu.h +2 -2
@@ -77,7 +77,7 @@ __percpu_##name##_case_##sz(void *ptr, u " stxr" #sfx "\t%w[loop], %" #w "[tmp], %[ptr]\n" \ " cbnz %w[loop], 1b", \ /* LSE atomics */ \ -#op_lse "\t%" #w "[val], %" #w "[tmp], %[ptr]\n" \ +#op_lse #sfx "\t%" #w "[val], %" #w "[tmp], %[ptr]\n" \ __nops(3)) \ : [loop] "=&r" (loop), [tmp] "=&r" (tmp), \ [ptr] "+Q"(*(u##sz *)ptr) \
@@ -98,7 +98,7 @@ __percpu_##name##_return_case_##sz(void " stxr" #sfx "\t%w[loop], %" #w "[ret], %[ptr]\n" \ " cbnz %w[loop], 1b", \ /* LSE atomics */ \ -#op_lse "\t%" #w "[val], %" #w "[ret], %[ptr]\n" \ +#op_lse #sfx "\t%" #w "[val], %" #w "[ret], %[ptr]\n" \ #op_llsc "\t%" #w "[ret], %" #w "[ret], %" #w "[val]\n" \ __nops(2)) \ : [loop] "=&r" (loop), [ret] "=&r" (ret), \
Greg Kroah-Hartman
maintainerPATCH 793/877 i2c: qcom-cci: Stop complaining about DT set clock rate
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryan O'Donoghue <[email protected]>
[ Upstream commit 8284750a182937bf805f703311501730f02eb40e ]
It is common practice in the downstream and upstream CCI dt to set CCI clock rates to 19.2 MHz. It appears to be fairly common for initial code to set the CCI clock rate to 37.5 MHz.
Applying the widely used CCI clock rates from downstream ought not to cause warning messages in the upstream kernel where our general policy is to usually copy downstream hardware clock rates across the range of Qualcomm drivers.
Drop the warning it is pervasive across CAMSS users but doesn't add any information or warrant any changes to the DT to align the DT clock rate to the bootloader clock rate.
Stable-dep-of: 7362a1553eb0 ("i2c: qcom-cci: fix device_node refcount leak in cci_probe()/cci_remove()")
--- drivers/i2c/busses/i2c-qcom-cci.c | 8 -------- 1 file changed, 8 deletions(-)
drivers/i2c/busses/i2c-qcom-cci.c +0 -8
@@ -602,14 +602,6 @@ static int cci_probe(struct platform_dev } } -if (cci_clk_rate != cci->data->cci_clk_rate) { -/* cci clock set by the bootloader or via assigned clock rate -* in DT. -*/ -dev_warn (dev,"Found %lu cci clk rate while %lu was expected\n" , - cci_clk_rate, cci->data->cci_clk_rate); - } - ret =cci_enable_clocks (cci);if (ret <0 )return ret;
Greg Kroah-Hartman
maintainerPATCH 794/877 i2c: qcom-cci: Remove the unused variable cci_clk_rate
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiapeng Chong <[email protected]>
[ Upstream commit b88c79699d72caa947ecaae85839b3563662ccce ]
Variable cci_clk_rate is not effectively used, so delete it.
drivers/i2c/busses/i2c-qcom-cci.c:526:16: warning: variable ‘cci_clk_rate’ set but not used.
Stable-dep-of: 7362a1553eb0 ("i2c: qcom-cci: fix device_node refcount leak in cci_probe()/cci_remove()")
--- drivers/i2c/busses/i2c-qcom-cci.c | 9 --------- 1 file changed, 9 deletions(-)
drivers/i2c/busses/i2c-qcom-cci.c +0 -9
@@ -523,7 +523,6 @@ static const struct dev_pm_ops qcom_cci_static int cci_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev; -unsigned long cci_clk_rate =0 ;struct device_node *child;struct resource *r;struct cci *cci;
@@ -594,14 +593,6 @@ static int cci_probe(struct platform_devreturn dev_err_probe (dev, -EINVAL ,"not enough clocks in DT\n" ); cci->nclocks = ret; -/* Retrieve CCI clock rate */ -for (i =0 ; i < cci->nclocks; i++) { -if (!strcmp (cci->clocks[i].id,"cci" )) { - cci_clk_rate =clk_get_rate (cci->clocks[i].clk); -break ; - } - } - ret =cci_enable_clocks (cci);if (ret <0 )return ret;
Greg Kroah-Hartman
maintainerPATCH 795/877 i2c: qcom-cci: fix device_node refcount leak in cci_probe()/cci_remove()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Liu Zhenlong <[email protected]>
[ Upstream commit 7362a1553eb09a8cdf8be7e509bd5309a8342486 ]
The of_node_put() matching of_node_get() runs after i2c_del_adapter(), whose trailing memset() zeroes adap->dev and thus adap->dev.of_node, making the put a no-op and leaking the node on every adapter removal and error cleanup.
Use a devm action: the pointer is captured at registration, out of reach of that memset(), and devres runs the put once on probe failure and detach, replacing the three manual of_node_put() calls. The setup loop uses the scoped iterator form so the child node is released automatically if devm_add_action_or_reset() fails mid-loop.
--- drivers/i2c/busses/i2c-qcom-cci.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
drivers/i2c/busses/i2c-qcom-cci.c +11 -9
@@ -520,10 +520,14 @@ static const struct dev_pm_ops qcom_cci_ SET_RUNTIME_PM_OPS(cci_suspend_runtime, cci_resume_runtime, NULL) }; +static void cci_put_of_node (void *data) +{ +of_node_put (data); +} +static int cci_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev; -struct device_node *child;struct resource *r;struct cci *cci;int ret, i;
@@ -539,7 +543,7 @@ static int cci_probe(struct platform_devif (!cci->data)return -ENOENT ; -for_each_available_child_of_node (dev->of_node, child) { +for_each_available_child_of_node_scoped (dev->of_node, child) {struct cci_master *master;u32 idx;
@@ -560,6 +564,9 @@ static int cci_probe(struct platform_dev master->adap.algo = &cci_algo; master->adap.dev.parent = dev; master->adap.dev.of_node =of_node_get (child); + ret =devm_add_action_or_reset (dev, cci_put_of_node, child); +if (ret) +return ret; master->master = idx; master->cci = cci;
@@ -631,10 +638,8 @@ static int cci_probe(struct platform_devcontinue ; ret =i2c_add_adapter (&cci->master[i].adap); -if (ret <0 ) { -of_node_put (cci->master[i].adap.dev.of_node); +if (ret <0 ) goto error_i2c; - } }return 0 ;
@@ -644,10 +649,8 @@ error_i2c:pm_runtime_dont_use_autosuspend (dev);for (--i ; i >=0 ; i--) { -if (cci->master[i].cci) { +if (cci->master[i].cci)i2c_del_adapter (&cci->master[i].adap); -of_node_put (cci->master[i].adap.dev.of_node); - } } error:disable_irq (cci->irq);
@@ -665,7 +668,6 @@ static void cci_remove(struct platform_dfor (i =0 ; i < cci->data->num_masters; i++) {if (cci->master[i].cci) {i2c_del_adapter (&cci->master[i].adap); -of_node_put (cci->master[i].adap.dev.of_node);cci_halt (cci, i); } }
Greg Kroah-Hartman
maintainerPATCH 796/877 scsi: fnic: Fix missed link-up when critical IRQ targets offline CPU
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arun Easi <[email protected]>
[ Upstream commit 0cb1fd924126f1f581621a5e804df98a02be9dff ]
When CPU Hyper Threading is disabled, sibling CPUs remain present but are reported offline. Managed MSI-X IRQs can still receive affinity masks that include those offline CPUs. If a driver-critical vector is managed, it can be parked on an offline CPU and the driver may miss critical events such as link-up.
Keep driver-critical vectors unmanaged so they can be migrated by the IRQ core when their target CPU is offlined.
Since HWQ-0 is unmanaged now, in some queue combinations there can be no mappings to it in mq_map. So without the blk-mq fix mentioned below, system may crash during cpu offline/online tests.
Depends-on: commit 10845a105bbc ("blk-mq: skip CPU offline notify on unmapped hctx")
--- drivers/scsi/fnic/fnic.h | 2 +- drivers/scsi/fnic/fnic_isr.c | 13 ++++++++++--- drivers/scsi/fnic/fnic_main.c | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 43 insertions(+), 5 deletions(-)
drivers/scsi/fnic/fnic.h +1 -1
@@ -27,7 +27,7 @@#define DRV_NAME "fnic"#define DRV_DESCRIPTION "Cisco FCoE HBA Driver" -#define DRV_VERSION "1.7.0.0" +#define DRV_VERSION "1.7.0.1"#define PFX DRV_NAME ": "#define DFX DRV_NAME "%d: "
drivers/scsi/fnic/fnic_isr.c +10 -3
@@ -245,7 +245,14 @@ int fnic_set_intr_mode_msix(struct fnicunsigned int m =ARRAY_SIZE (fnic->wq);unsigned int o =ARRAY_SIZE (fnic->hw_copy_wq);unsigned int min_irqs = n + m +1 +1 ;/*rq, raw wq, wq, err*/ - +/* +* Make driver critical vectors unmanaged, or else it can get tied +* to an offline CPU. This can happen when hyper-threading is off. +*/ +struct irq_affinity affd = { + .pre_vectors = n + m +1 ,/* rq, raw wq, 1 ioq */ + .post_vectors =1 ,/* err */ + };/* * We need n RQs, m WQs, o Copy WQs, n+m+o CQs, and n+m+o+1 INTRs * (last INTR is used for WQ/RQ errors and notification area)
@@ -263,8 +270,8 @@ int fnic_set_intr_mode_msix(struct fnicint vec_count =0 ;int vecs = fnic->rq_count + fnic->raw_wq_count + fnic->wq_copy_count +1 ; - vec_count =pci_alloc_irq_vectors (fnic->pdev, min_irqs, vecs, -PCI_IRQ_MSIX |PCI_IRQ_AFFINITY ); + vec_count =pci_alloc_irq_vectors_affinity (fnic->pdev, min_irqs, + vecs,PCI_IRQ_MSIX |PCI_IRQ_AFFINITY , &affd);FNIC_ISR_DBG (KERN_INFO , fnic->lport->host, fnic->fnic_num,"allocated %d MSI-X vectors\n" , vec_count);
drivers/scsi/fnic/fnic_main.c +32 -1
@@ -579,6 +579,8 @@ static int fnic_scsi_drv_init(struct fnivoid fnic_mq_map_queues_cpus (struct Scsi_Host *host) { +const struct cpumask *mask; +unsigned int queue, cpu;struct fc_lport *lp =shost_priv (host);struct fnic *fnic =lport_priv (lp);struct pci_dev *l_pdev = fnic->pdev;
@@ -600,7 +602,36 @@ void fnic_mq_map_queues_cpus(struct Scsireturn ; } -blk_mq_map_hw_queues (qmap, &l_pdev->dev,FNIC_PCI_OFFSET ); +for_each_possible_cpu (cpu) + qmap->mq_map[cpu] =0 ; + +/* +* Setup CPU to Queue mapping for all managed MSI-X IRQs. +* Q0 is driver critical and non-managed, hence start from Q1. +*/ +for (queue =1 ; queue < qmap->nr_queues; queue++) { +int irq_num =pci_irq_vector (fnic->pdev, + queue +FNIC_PCI_OFFSET ); + +if (irq_num <0 ) +continue ; + + mask =pci_irq_get_affinity (fnic->pdev, + queue +FNIC_PCI_OFFSET ); +if (!mask) { +shost_printk (KERN_ERR , host, +"failed to get irq_affinity map for queue:%d\n" , irq_num); +continue ; + } +FNIC_MAIN_DBG (KERN_INFO , fnic->lport->host, fnic->fnic_num, +"got irq_affinity map for %d:\n" , irq_num); +for_each_cpu (cpu, mask) { + qmap->mq_map[cpu] = qmap->queue_offset + queue; +FNIC_MAIN_DBG (KERN_INFO , fnic->lport->host, fnic->fnic_num, +"[Q%d] cpu:%d <=> irq:%d\n" , + queue, cpu, irq_num); + } + } }static int fnic_probe (struct pci_dev *pdev,const struct pci_device_id *ent)
Greg Kroah-Hartman
maintainerPATCH 797/877 Input: hp_sdc - shut down kicker timer on module exit
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
[ Upstream commit 309731e95917125bbd13626a7a5600490a5bf44f ]
hp_sdc_kicker() rearms hp_sdc.kicker with mod_timer() after scheduling the tasklet. The module exit path uses timer_delete_sync(). That waits for a callback already running but can still leave the timer rearmed.
A callback can therefore leave the timer pending while hp_sdc_exit() tears down the driver, allowing timer activity to access dismantled driver state.
Use timer_shutdown_sync() for final teardown. It waits for a running callback and prevents rearming after module exit begins.
--- drivers/input/serio/hp_sdc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/serio/hp_sdc.c +1 -1
@@ -980,7 +980,7 @@ static void hp_sdc_exit(void)free_irq (hp_sdc.irq, &hp_sdc);write_unlock_irq (&hp_sdc.lock); -del_timer_sync (&hp_sdc.kicker); +timer_shutdown_sync (&hp_sdc.kicker);tasklet_kill (&hp_sdc.task);
Greg Kroah-Hartman
maintainerPATCH 798/877 wifi: wcn36xx: Fix potential use-after-free in TX ack timer teardown
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
[ Upstream commit d9be5e75530772fc31637070d51e5717d6aeaa2a ]
wcn36xx_dxe_deinit() tears down the TX ack timer with timer_delete(), which only dequeues the timer and does not wait for a callback that is already executing; the preceding free_irq() calls synchronize the interrupt handlers only. The callback, wcn36xx_dxe_tx_timer(), can therefore be running past the teardown and use the wcn freed along with the ieee80211_hw in wcn36xx_remove(): it takes wcn->dxe_lock, reads wcn->tx_ack_skb and passes wcn->hw to ieee80211_tx_status_irqsafe().
Fix this by using timer_shutdown_sync(), which waits for a running callback and also prevents the timer from being rearmed again. The timer is set up again by wcn36xx_dxe_init() on the next start, so the start/stop cycle is unaffected.
This issue was found by an in-house static analysis tool.
--- drivers/net/wireless/ath/wcn36xx/dxe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ath/wcn36xx/dxe.c +1 -1
@@ -1055,7 +1055,7 @@ void wcn36xx_dxe_deinit(struct wcn36xx *free_irq (wcn->tx_irq, wcn);free_irq (wcn->rx_irq, wcn); -del_timer (&wcn->tx_ack_timer); +timer_shutdown_sync (&wcn->tx_ack_timer);if (wcn->tx_ack_skb) {ieee80211_tx_status_irqsafe (wcn->hw, wcn->tx_ack_skb);
Greg Kroah-Hartman
maintainerPATCH 799/877 hwmon: (pwm-fan) Stop RPM timer before freeing tach data
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yibo Tan <[email protected]>
[ Upstream commit 26d5ff79768548efb1e604bb6e8697c101e06269 ]
sample_timer() rearms the RPM timer and accesses the devm-managed ctx->tachs and ctx->pulses_per_revolution arrays. The cleanup action which stops the timer is registered before those arrays are allocated.
Since devres releases entries in reverse order, driver detach can free the arrays before pwm_fan_cleanup() shuts down the timer. A timer expiry in that window accesses the freed tach data.
With a KASAN kernel, a test-only kprobe delayed entry to pwm_fan_cleanup() while normal sysfs unbind ran. Each of three runs reported three four-byte reads and two four-byte writes in sample_timer() after its backing devm allocations had been freed. The helper did not invoke the timer callback, cleanup actions or free functions.
With the fix, three matching unbind runs completed without KASAN, BUG, WARNING, Oops or panic. Instrumentation confirmed that timer retirement completed before the first timer backing allocation was released.
Split timer retirement from the power cleanup and register its devres action after the timer backing data and IRQ actions are installed. This preserves the early power rollback action while ensuring the timer is retired before its backing data is released. Use timer_shutdown_sync() because the callback can rearm itself.
--- drivers/hwmon/pwm-fan.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/hwmon/pwm-fan.c +12 -1
@@ -466,12 +466,18 @@ static void pwm_fan_cleanup(void *__ctx) {struct pwm_fan_ctx *ctx = __ctx; -del_timer_sync (&ctx->rpm_timer);/* Switch off everything */ ctx->enable_mode = pwm_disable_reg_disable;pwm_fan_power_off (ctx, true); } +static void pwm_fan_timer_cleanup (void *__ctx) +{ +struct pwm_fan_ctx *ctx = __ctx; + +timer_shutdown_sync (&ctx->rpm_timer); +} +static int pwm_fan_probe (struct platform_device *pdev) {struct thermal_cooling_device *cdev;
@@ -614,6 +620,10 @@ static int pwm_fan_probe(struct platform }if (ctx->tach_count >0 ) { + ret =devm_add_action_or_reset (dev, pwm_fan_timer_cleanup, ctx); +if (ret) +return ret; + ctx->sample_start =ktime_get ();mod_timer (&ctx->rpm_timer, jiffies +HZ );
@@ -655,6 +665,7 @@ static void pwm_fan_shutdown(struct plat {struct pwm_fan_ctx *ctx =platform_get_drvdata (pdev); +pwm_fan_timer_cleanup (ctx);pwm_fan_cleanup (ctx); }
Greg Kroah-Hartman
maintainerPATCH 800/877 drm/msm/dpu: clear pending peripheral flush state
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Saim Shujah <[email protected]>
[ Upstream commit a5b5cc909931572aec446e129c035b76b3f0c1fa ]
dpu_hw_ctl_clear_pending_flush() resets the cached per-block state after a flush transaction, but misses pending_periph_flush_mask.
The peripheral flush updater accumulates interface bits in this mask. A later transaction which sets the top-level peripheral flush bit can write stale interface bits to CTL_PERIPH_FLUSH together with the current state.
Peripheral flush support was added after the helper started clearing every individual pending flush mask. Clear the peripheral mask together with the other cached child masks.
Patchwork: https://patchwork.freedesktop.org/patch/748968/
--- drivers/gpu/drm/msm/disp/dpu1/dpu_hw_ctl.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/msm/disp/dpu1/dpu_hw_ctl.c +1 -0
@@ -110,6 +110,7 @@ static inline void dpu_hw_ctl_clear_pend ctx->pending_flush_mask =0x0 ; ctx->pending_intf_flush_mask =0 ; ctx->pending_wb_flush_mask =0 ; + ctx->pending_periph_flush_mask =0 ; ctx->pending_merge_3d_flush_mask =0 ; ctx->pending_dsc_flush_mask =0 ; ctx->pending_cdm_flush_mask =0 ;
Greg Kroah-Hartman
maintainerPATCH 801/877 wifi: libipw: reject TKIP frames without a full MIC
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daehyeon Ko <[email protected]>
[ Upstream commit 06f42accaf3c6aecab1dcc57f68dde6c06c8b380 ]
libipw_michael_mic_verify() assumes that an skb contains an eight-byte Michael MIC. A short TKIP frame makes the unsigned payload length wrap, causing michael_mic() to read past the skb.
Check that the MIC is present before verifying it, and use the existing MICHAEL_MIC_LEN constant for all MIC lengths in the verifier.
--- net/wireless/lib80211_crypt_tkip.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
net/wireless/lib80211_crypt_tkip.c +8 -5
@@ -38,6 +38,7 @@ MODULE_DESCRIPTION("lib80211 crypt: TKIPMODULE_LICENSE ("GPL" );#define TKIP_HDR_LEN 8 +#define MICHAEL_MIC_LEN 8struct lib80211_tkip_data {#define TKIP_KEY_LEN 32
@@ -585,16 +586,18 @@ static int lib80211_michael_mic_verify(s int hdr_len, void *priv) { struct lib80211_tkip_data *tkey = priv; -u8 mic[8 ]; +u8 mic[MICHAEL_MIC_LEN ]; -if (!tkey->key_set) +if (!tkey->key_set || skb->len < hdr_len +MICHAEL_MIC_LEN )return -1 ;michael_mic_hdr (skb, tkey->rx_hdr);if (michael_mic (tkey->rx_tfm_michael, &tkey->key[24 ], tkey->rx_hdr, - skb->data + hdr_len, skb->len -8 - hdr_len, mic)) + skb->data + hdr_len, + skb->len -MICHAEL_MIC_LEN - hdr_len, mic))return -1 ; -if (memcmp (mic, skb->data + skb->len -8 ,8 ) !=0 ) { +if (memcmp (mic, skb->data + skb->len -MICHAEL_MIC_LEN , +MICHAEL_MIC_LEN ) !=0 ) {struct ieee80211_hdr *hdr; hdr = (struct ieee80211_hdr *)skb->data; printk(KERN_DEBUG "%s: Michael MIC verification failed for "
@@ -612,7 +615,7 @@ static int lib80211_michael_mic_verify(s tkey->rx_iv32 = tkey->rx_iv32_new; tkey->rx_iv16 = tkey->rx_iv16_new; -skb_trim (skb, skb->len -8 ); +skb_trim (skb, skb->len -MICHAEL_MIC_LEN );return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 802/877 wifi: mac80211: track MU-MIMO configuration on disabled interfaces
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Benjamin Berg <[email protected]>
[ Upstream commit a5aa46f1ac4f53e03b9b75cbf55634131f2f8cac ]
For monitoring, userspace will try to configure the VIF sdata, while the driver may see the monitor_sdata that is created when only monitor interfaces are up. This causes the odd situation that it may not be possible to store the MU-MIMO configuration on monitor_sdata.
Fix this by storing that information on the VIF sdata and updating the monitor_sdata when available and the interface is up. Also, adjust the code that adds monitor_sdata so that it will configure MU-MIMO based on the newly added interface or one of the existing ones.
This should give a mostly consistent behaviour when configuring MU-MIMO on sniffer interfaces. Should the user configure MU-MIMO on multiple sniffer interfaces, then mac80211 will simply select one of the configurations. This behaviour should be good enough and avoids breaking user expectations in the common scenarios.
[ Backport to 6.12: omit NO_VIRTUAL_MONITOR handling, since this tree
only exposes WANT_MONITOR_VIF. Keep the existing monitors counter and cooked-monitor handling, and traverse mon_list through u.mntr.list. Update the existing reconfiguration call at wake_up rather than adding the later upstream call site. All three virtual-monitor creation calls now pass the configuration source, or NULL to select a running monitor.
Retain the MU-MIMO configuration changes so target 2b04d6556964 ("wifi: mac80211: refuse to make a monitor active when it has no queue") merges cleanly on top. No new functions are introduced. ]
Stable-dep-of: 2b04d6556964 ("wifi: mac80211: refuse to make a monitor active when it has no queue")
--- net/mac80211/cfg.c | 39 +++++++++++++++++++++++++++++---------- net/mac80211/ieee80211_i.h | 3 ++- net/mac80211/iface.c | 43 +++++++++++++++++++++++++++++++++++++------ net/mac80211/util.c | 3 ++- 4 files changed, 70 insertions(+), 18 deletions(-)
net/mac80211/cfg.c +29 -10
@@ -63,12 +63,14 @@ static void ieee80211_set_mu_mimo_followmemcpy (sdata->vif.bss_conf.mu_group.position, params->vht_mumimo_groups +WLAN_MEMBERSHIP_LEN ,WLAN_USER_POSITION_LEN ); -ieee80211_link_info_change_notify (sdata, &sdata->deflink, -BSS_CHANGED_MU_GROUPS ); +/* don't care about endianness - just check for 0 */ memcpy (&membership, params->vht_mumimo_groups,WLAN_MEMBERSHIP_LEN ); mu_mimo_groups = membership !=0 ; + +/* Unset following if configured explicitly */ +eth_broadcast_addr (sdata->u.mntr.mu_follow_addr); }if (params->vht_mumimo_follow_addr) {
@@ -76,16 +78,26 @@ static void ieee80211_set_mu_mimo_followis_valid_ether_addr (params->vht_mumimo_follow_addr);ether_addr_copy (sdata->u.mntr.mu_follow_addr, params->vht_mumimo_follow_addr); + +/* Unset current membership until a management frame is RXed */ +memset (sdata->vif.bss_conf.mu_group.membership,0 , +WLAN_MEMBERSHIP_LEN ); } sdata->vif.bss_conf.mu_mimo_owner = mu_mimo_groups || mu_mimo_follow; + +/* Notify only after setting mu_mimo_owner */ +if (sdata->vif.bss_conf.mu_mimo_owner && + sdata->flags &IEEE80211_SDATA_IN_DRIVER ) +ieee80211_link_info_change_notify (sdata, &sdata->deflink, +BSS_CHANGED_MU_GROUPS ); }static int ieee80211_set_mon_options (struct ieee80211_sub_if_data *sdata,struct vif_params *params) {struct ieee80211_local *local = sdata->local; -struct ieee80211_sub_if_data *monitor_sdata; +struct ieee80211_sub_if_data *monitor_sdata =NULL ;/* check flags first */ if (params->flags &&ieee80211_sdata_running (sdata)) {
@@ -104,18 +116,25 @@ static int ieee80211_set_mon_options(strreturn -EBUSY ; } -/* also validate MU-MIMO change */ - monitor_sdata =wiphy_dereference (local->hw.wiphy, - local->monitor_sdata); - -if (!monitor_sdata && +/* validate whether MU-MIMO can be configured */ +if (!ieee80211_hw_check (&local->hw,WANT_MONITOR_VIF ) && (params->vht_mumimo_groups || params->vht_mumimo_follow_addr))return -EOPNOTSUPP ; +/* Also update dependent monitor_sdata if required */ +if (test_bit (SDATA_STATE_RUNNING , &sdata->state)) + monitor_sdata =wiphy_dereference (local->hw.wiphy, + local->monitor_sdata); +/* apply all changes now - no failures allowed */ -if (monitor_sdata &&ieee80211_hw_check (&local->hw,WANT_MONITOR_VIF )) -ieee80211_set_mu_mimo_follow (monitor_sdata, params); +if (ieee80211_hw_check (&local->hw,WANT_MONITOR_VIF )) { +/* This is copied in when the VIF is activated */ +ieee80211_set_mu_mimo_follow (sdata, params); + +if (monitor_sdata) +ieee80211_set_mu_mimo_follow (monitor_sdata, params); + }if (params->flags) {if (ieee80211_sdata_running (sdata)) {
net/mac80211/ieee80211_i.h +2 -1
@@ -2045,7 +2045,8 @@ void ieee80211_adjust_monitor_flags(stru const int offset);int ieee80211_do_open (struct wireless_dev *wdev,bool coming_up);void ieee80211_sdata_stop (struct ieee80211_sub_if_data *sdata); -int ieee80211_add_virtual_monitor (struct ieee80211_local *local); +int ieee80211_add_virtual_monitor (struct ieee80211_local *local, +struct ieee80211_sub_if_data *creator_sdata);void ieee80211_del_virtual_monitor (struct ieee80211_local *local);bool __ieee80211_recalc_txpower (struct ieee80211_sub_if_data *sdata);
net/mac80211/iface.c +37 -6
74 lines not on this page · raw message
net/mac80211/util.c +2 -1
@@ -2144,8 +2144,9 @@ int ieee80211_reconfig(struct ieee80211_ wake_up: +/* Passing NULL means an interface is picked for configuration */ if (local->monitors == local->open_count && local->monitors >0 ) -ieee80211_add_virtual_monitor (local); +ieee80211_add_virtual_monitor (local,NULL );/* * Clear the WLAN_STA_BLOCK_BA flag so new aggregation
Greg Kroah-Hartman
maintainerPATCH 803/877 wifi: mac80211: refuse to make a monitor active when it has no queue
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Devin Wittmayer <[email protected]>
[ Upstream commit 2b04d6556964ae9f89819b86a0a7801e39c3aae5 ]
A monitor interface only gets a TXQ if it's created active, and one can't be added later. Setting the flag on a down interface is still allowed, so the driver is handed a monitor with no queue. ath9k dereferences it:
BUG: kernel NULL pointer dereference, address: 0000000000000066 RIP: 0010:ath_tx_node_init+0x49/0x170 [ath9k] ath9k_add_interface+0x10c/0x140 [ath9k] drv_add_interface+0x54/0x250 [mac80211] ieee80211_do_open+0x32f/0x800 [mac80211]
Reached with CAP_NET_ADMIN by "iw dev X set monitor active" followed by "ip link set X up". RTNL is held, so netlink operations block behind it.
Refuse the flag when there is no queue to give.
--- net/mac80211/cfg.c | 4 ++++ 1 file changed, 4 insertions(+)
net/mac80211/cfg.c +4 -0
@@ -116,6 +116,10 @@ static int ieee80211_set_mon_options(strreturn -EBUSY ; } +/* TXQs are reserved in ieee80211_if_add() and cannot be added later */ +if ((params->flags &MONITOR_FLAG_ACTIVE ) && !sdata->vif.txq) +return -EOPNOTSUPP ; +/* validate whether MU-MIMO can be configured */ if (!ieee80211_hw_check (&local->hw,WANT_MONITOR_VIF ) && (params->vht_mumimo_groups || params->vht_mumimo_follow_addr))
Greg Kroah-Hartman
maintainerPATCH 804/877 smb: mark the new channel addition log as informational log with cifs_info
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bharath SM <[email protected]>
[ Upstream commit faf1b64888ff13caa94fa09835fcfdabee18b057 ]
For multichannel mounts, when a new channel is successfully opened we currently log 'successfully opened new channel on iface: <>' as cifs_dbg(VFS..) which is eventually translated into a pr_err log. Marking these informational logs as error logs may lead to confusion for users so they will now be logged as info logs instead.
Stable-dep-of: d034e836eefd ("smb: client: fix use-after-free of iface in cifs_try_adding_channels()")
--- fs/smb/client/sess.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/client/sess.c +1 -1
@@ -267,7 +267,7 @@ int cifs_try_adding_channels(struct cifs iface->num_channels++; iface->weight_fulfilled++; -cifs_dbg (VFS ,"successfully opened new channel on iface:%pIS\n" , +cifs_info ("successfully opened new channel on iface:%pIS\n" , &iface->sockaddr);break ; }