6.18.65-rc1 review
Greg Kroah-Hartman
maintainerPATCH 1960/2151 cgroup/cpuset: Make sure compute_partition_effective_cpumask() is only called for valid partition
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Waiman Long <[email protected]>
[ Upstream commit 356a3aa7404e420e6f19c5ed42db7b8bd0c7ee9f ]
With visual inspection to make sure that compute_partition_effective_cpumask() is only called for valid partition root, it was found that the function can be called for an invalidated partition near the end of cpuset_hotplug_update_tasks(). When partcmd is set, update_parent_effective_cpumask() is called to either invalidate a valid partition or with partcmd_update to check if an invalid partition can be switched back to valid. In both cases, cpuset_force_rebuild() should be invoked. However, compute_partition_effective_cpumask() should only be called when an invalid partition is switched back to valid. When a partition is invalidated, compute_effective_cpumask() should be called instead.
Also add a WARN_ON_ONCE() in compute_partition_effective_cpumask() to ensure that a valid partition root is passed in.
--- kernel/cgroup/cpuset.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/cgroup/cpuset.c +6 -1
@@ -2181,6 +2181,8 @@ static void compute_partition_effective_cpumask(struct cpuset *cs,struct cpuset *child;bool populated =partition_is_populated (cs,NULL ); +WARN_ON_ONCE (!is_partition_valid (cs)); +/* * Check child partition roots to see if they should be * invalidated when
@@ -4065,9 +4067,12 @@ static void cpuset_hotplug_update_tasks(struct cpuset *cs, struct tmpmasks *tmp)if (partcmd >=0 ) {update_parent_effective_cpumask (cs, partcmd,NULL , tmp); -if ((partcmd == partcmd_invalidate) ||is_partition_valid (cs)) { +if (is_partition_valid (cs)) {compute_partition_effective_cpumask (cs, &new_cpus);cpuset_force_rebuild (); + }else if (partcmd == partcmd_invalidate) { +compute_effective_cpumask (&new_cpus, cs, parent); +cpuset_force_rebuild (); } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1961/2151 block: advance iterator after copy-in for SG_DXFER_TO_FROM_DEV
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: TJ Adams <[email protected]>
[ Upstream commit 82e72ea18d0af724914c31a1f274c1aef452aad0 ]
When a passthrough request uses transfer direction SG_DXFER_TO_FROM_DEV, bio_copy_user_iov() sets up a temporary iterator iter2 with data_source = ITER_SOURCE to copy user data into the bio pages before execution.
bio_copy_from_iter(bio, &iter2) copies the data and advances iter2, but the original iter is never advanced. Consequently, iov_iter_count(&i) remains non-zero in the caller loop in blk_rq_map_user_iov():
i = *iter;
do {
if (copy)
ret = bio_copy_user_iov(rq, map_data, &i, gfp_mask);
...
} while (iov_iter_count(&i));Because i is never advanced, blk_rq_map_user_iov() loops indefinitely, continually allocating bios and consuming map_data pages until it exhausts pages and fails with -EINVAL.
Fix this by calling iov_iter_advance(iter, bio->bi_iter.bi_size) in the map_data && map_data->from_user branch after bio_copy_from_iter().
--- block/blk-map.c | 1 + 1 file changed, 1 insertion(+)
block/blk-map.c +1 -0
@@ -218,6 +218,7 @@ static int bio_copy_user_iov(struct request *rq, struct rq_map_data *map_data, ret =bio_copy_from_iter (bio, &iter2);if (ret) goto cleanup; +iov_iter_advance (iter, bio->bi_iter.bi_size); }else {if (bmd->is_our_pages)zero_fill_bio (bio);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1962/2151 spi: cs42l43: Add speaker ID quirk for Dell XPS 13 DX13260 SKU 0E54
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jérémie Rodon <[email protected]>
[ Upstream commit 7da2aca123754c0e06092bbe179d58078b58d8d4 ]
The Dell XPS 13 DX13260 is also sold with SKU 0E54, which has the same ACPI speaker ID layout as SKU 0E53: two pins in one GpioIo() while the spk-id-gpios _DSD property references only the first. Without the quirk the speaker ID is wrong (0), so there is no speaker audio and no amp firmware is loaded.
Add a DMI entry for SKU 0E54 using the same handler.
--- drivers/spi/spi-cs42l43.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/spi/spi-cs42l43.c +8 -0
@@ -316,6 +316,14 @@ static const struct dmi_system_id cs42l43_spk_id_quirks[] = { }, .driver_data = cs42l43_get_2bit_speaker_id_from_one_gpioio, }, + { + .ident = "Dell XPS 13 DX13260", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), + DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0E54"), + }, + .driver_data = cs42l43_get_2bit_speaker_id_from_one_gpioio, + }, { } };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1963/2151 selftests: fix ARCH normalization to handle command-line argument
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aleksei Oladko <[email protected]>
[ Upstream commit 5a1292137e89c8c4b12076b17427eb00f788a4ed ]
Several selftests Makefiles (e.g. prctl, breakpoints, etc) attempt to normalize the ARCH variable by converting x86_64 and i.86 to x86. However, it uses the conditional assignment operator '?='.
When ARCH is passed as a command-line argument (e.g., during an rpmbuild process), the '?=' operator ignores the shell command and the sed transformation. This leads to an incorrect ARCH value being used, which causes build failures
# make -C tools/testing/selftests TARGETS=prctl ARCH=x86_64 make: Entering directory '/build/tools/testing/selftests' make[1]: Entering directory '/build/tools/testing/selftests/prctl' make[1]: *** No targets. Stop. make[1]: Leaving directory '/build/tools/testing/selftests/prctl' make: *** [Makefile:197: all] Error 2
Change the assignment to use 'override' and ':=' to ensure the normalization logic is applied regardless of how the ARCH variable was initially defined.
Stable-dep-of: ff4194e54f84 ("selftests/thermal: allow cross builds of the Intel tests")
--- tools/testing/selftests/breakpoints/Makefile | 4 ++-- tools/testing/selftests/ipc/Makefile | 8 ++++---- tools/testing/selftests/prctl/Makefile | 4 ++-- tools/testing/selftests/sparc64/Makefile | 4 ++-- .../testing/selftests/thermal/intel/power_floor/Makefile | 4 ++-- .../selftests/thermal/intel/workload_hint/Makefile | 4 ++-- 6 files changed, 14 insertions(+), 14 deletions(-)
tools/testing/selftests/breakpoints/Makefile +2 -2
@@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 # Taken from perf makefile -uname_M := $(shell uname -m 2>/dev/null || echo not) -ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/) +ARCH ?= $(shell uname -m 2>/dev/null || echo not) +override ARCH := $(shell echo $(ARCH) | sed -e s/i.86/x86/ -e s/x86_64/x86/) TEST_GEN_PROGS := step_after_suspend_test
tools/testing/selftests/ipc/Makefile +4 -4
@@ -1,12 +1,12 @@ # SPDX-License-Identifier: GPL-2.0 -uname_M := $(shell uname -m 2>/dev/null || echo not) -ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/) +ARCH ?= $(shell uname -m 2>/dev/null || echo not) +override ARCH := $(shell echo $(ARCH) | sed -e s/i.86/i386/) ifeq ($(ARCH),i386) - ARCH := x86 + override ARCH := x86 CFLAGS := -DCONFIG_X86_32 -D__i386__ endif ifeq ($(ARCH),x86_64) - ARCH := x86 + override ARCH := x86 CFLAGS := -DCONFIG_X86_64 -D__x86_64__ endif
tools/testing/selftests/prctl/Makefile +2 -2
@@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 ifndef CROSS_COMPILE -uname_M := $(shell uname -m 2>/dev/null || echo not) -ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/) +ARCH ?= $(shell uname -m 2>/dev/null || echo not) +override ARCH := $(shell echo $(ARCH) | sed -e s/i.86/x86/ -e s/x86_64/x86/) ifeq ($(ARCH),x86) TEST_PROGS := disable-tsc-ctxt-sw-stress-test disable-tsc-on-off-stress-test \
tools/testing/selftests/sparc64/Makefile +2 -2
@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 -uname_M := $(shell uname -m 2>/dev/null || echo not) -ARCH ?= $(shell echo $(uname_M) | sed -e s/x86_64/x86/) +ARCH ?= $(shell uname -m 2>/dev/null || echo not) +override ARCH := $(shell echo $(ARCH) | sed -e s/x86_64/x86/) ifneq ($(ARCH),sparc64) nothing:
tools/testing/selftests/thermal/intel/power_floor/Makefile +2 -2
@@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 ifndef CROSS_COMPILE -uname_M := $(shell uname -m 2>/dev/null || echo not) -ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/) +ARCH ?= $(shell uname -m 2>/dev/null || echo not) +override ARCH := $(shell echo $(ARCH) | sed -e s/i.86/x86/ -e s/x86_64/x86/) ifeq ($(ARCH),x86) TEST_GEN_PROGS := power_floor_test
tools/testing/selftests/thermal/intel/workload_hint/Makefile +2 -2
@@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 ifndef CROSS_COMPILE -uname_M := $(shell uname -m 2>/dev/null || echo not) -ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/) +ARCH ?= $(shell uname -m 2>/dev/null || echo not) +override ARCH := $(shell echo $(ARCH) | sed -e s/i.86/x86/ -e s/x86_64/x86/) ifeq ($(ARCH),x86) TEST_GEN_PROGS := workload_hint_test
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1964/2151 selftests/thermal: allow cross builds of the Intel tests
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
[ Upstream commit ff4194e54f840b4df4eb2489c63ee88283895efc ]
The power_floor and workload_hint Makefiles build nothing when CROSS_COMPILE is set, even for an x86 target, and they include lib.mk only on x86. Other architectures therefore have no install or emit_tests rules for these suites, and their installation fails with a missing target.
Select the x86 tests from the target ARCH when it is given and from the host's SUBARCH otherwise, and include lib.mk unconditionally so that the suites install and emit an empty runlist on other architectures. Use a private ARCH_PROCESSED instead of the ARCH override added by commit 5a1292137e89 ("selftests: fix ARCH normalization to handle command-line argument"): the override changed the value lib.mk uses to pick the clang target, whereas leaving ARCH unset lets lib.mk use the compiler's native triple. A command-line ARCH such as x86_64 is still normalized for the selection, while an ARCH spelling that lib.mk does not know, such as i686 with LLVM=1, is rejected as in other selftests.
--- .../selftests/thermal/intel/power_floor/Makefile | 12 +++++------- .../selftests/thermal/intel/workload_hint/Makefile | 12 +++++------- 2 files changed, 10 insertions(+), 14 deletions(-)
tools/testing/selftests/thermal/intel/power_floor/Makefile +5 -7
@@ -1,12 +1,10 @@ # SPDX-License-Identifier: GPL-2.0 -ifndef CROSS_COMPILE -ARCH ?= $(shell uname -m 2>/dev/null || echo not) -override ARCH := $(shell echo $(ARCH) | sed -e s/i.86/x86/ -e s/x86_64/x86/) +top_srcdir = ../../../../../.. +include $(top_srcdir)/scripts/subarch.include +ARCH_PROCESSED := $(shell echo $(or $(ARCH),$(SUBARCH)) | sed -e s/i.86/x86/ -e s/x86_64/x86/) -ifeq ($(ARCH),x86) +ifeq ($(ARCH_PROCESSED),x86) TEST_GEN_PROGS := power_floor_test +endif include ../../../lib.mk - -endif -endif
tools/testing/selftests/thermal/intel/workload_hint/Makefile +5 -7
@@ -1,12 +1,10 @@ # SPDX-License-Identifier: GPL-2.0 -ifndef CROSS_COMPILE -ARCH ?= $(shell uname -m 2>/dev/null || echo not) -override ARCH := $(shell echo $(ARCH) | sed -e s/i.86/x86/ -e s/x86_64/x86/) +top_srcdir = ../../../../../.. +include $(top_srcdir)/scripts/subarch.include +ARCH_PROCESSED := $(shell echo $(or $(ARCH),$(SUBARCH)) | sed -e s/i.86/x86/ -e s/x86_64/x86/) -ifeq ($(ARCH),x86) +ifeq ($(ARCH_PROCESSED),x86) TEST_GEN_PROGS := workload_hint_test +endif include ../../../lib.mk - -endif -endif
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1965/2151 thermal: Fix CPU mask truncation in power limit trace event
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hungyu Lin <[email protected]>
[ Upstream commit 82c9c94f54a444a686e926c872dae4b198d1036f ]
num_possible_cpus() counts CPUs, but CPU IDs need not be contiguous. Using it to size the thermal_power_cpu_limit bitmap can omit CPUs with higher IDs. For example, possible CPUs 0 and 64 produce an eight-byte bitmap on a 64-bit system, dropping CPU 64.
Use nr_cpumask_bits for both sizing and copying the bitmap.
--- drivers/thermal/thermal_trace.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/thermal/thermal_trace.h +2 -2
@@ -119,7 +119,7 @@ TRACE_EVENT(thermal_power_cpu_limit,TP_ARGS (cpus, freq, cdev_state, power),TP_STRUCT__entry ( - __bitmask(cpumask, num_possible_cpus()) + __bitmask(cpumask, nr_cpumask_bits) __field(unsigned int, freq ) __field(unsigned long, cdev_state) __field(u32, power )
@@ -127,7 +127,7 @@ TRACE_EVENT(thermal_power_cpu_limit,TP_fast_assign (__assign_bitmask (cpumask,cpumask_bits (cpus), - num_possible_cpus()); + nr_cpumask_bits); __entry->freq = freq; __entry->cdev_state = cdev_state; __entry->power = power;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1966/2151 ASoC: codecs: wsa884x: disable runtime PM on unbind
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Srinivas Kandagatla <[email protected]>
[ Upstream commit 54c121eaeed8ee7751935db8100b6b5c57124db9 ]
Probe enables runtime PM but nothing disables it on unbind. The pending autosuspend then runs wsa884x_runtime_suspend() after the devm-managed regmap is freed, and dereferences NULL:
Unable to handle kernel NULL pointer dereference at virtual address 0000000000000020 pc : regcache_cache_only+0x18/0x80 lr : wsa884x_runtime_suspend+0x24/0x40 [snd_soc_wsa884x]
Use devm_pm_runtime_enable() so runtime PM is disabled before the regmap is freed.
--- sound/soc/codecs/wsa884x.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
sound/soc/codecs/wsa884x.c +3 -1
@@ -2127,7 +2127,9 @@ static int wsa884x_probe(struct sdw_slave *pdev,pm_runtime_use_autosuspend (dev);pm_runtime_mark_last_busy (dev);pm_runtime_set_active (dev); -pm_runtime_enable (dev); + ret =devm_pm_runtime_enable (dev); +if (ret) +return ret; return devm_snd_soc_register_component(dev, &wsa884x_component_drv,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1967/2151 ASoC: codecs: wsa883x: disable runtime PM on unbind
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Srinivas Kandagatla <[email protected]>
[ Upstream commit ea63182d71956dc33c6f08dc4171f1052f8409a9 ]
Probe enables runtime PM but nothing disables it on unbind, or when registering the component fails. A pending autosuspend can then run wsa883x_runtime_suspend() after the devm-managed regmap is freed, and dereference NULL, as seen on wsa884x.
Use devm_pm_runtime_enable() so runtime PM is disabled before the regmap is freed.
--- sound/soc/codecs/wsa883x.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
sound/soc/codecs/wsa883x.c +3 -1
@@ -1672,7 +1672,9 @@ static int wsa883x_probe(struct sdw_slave *pdev,pm_runtime_use_autosuspend (dev);pm_runtime_mark_last_busy (dev);pm_runtime_set_active (dev); -pm_runtime_enable (dev); + ret =devm_pm_runtime_enable (dev); +if (ret) + goto err; ret = devm_snd_soc_register_component(dev, &wsa883x_component_drv,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1968/2151 ASoC: codecs: wsa884x: Fix VI sense port channel count
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ravi Hothi <[email protected]>
[ Upstream commit a6093f98cbfc4a717ef3d1048b0e38fb2035be98 ]
The VI sense port carries both the voltage and the current sense data of the speaker, but it is described with max_ch = 1 and, since commit 060fac202eb8 ("ASoC: codecs: wsa884x: Correct VI sense channel mask"), a channel mask of 0x1, so only half of the V/I pair is transferred.
Describe the port as two channels and set the channel mask back to 0x3.
--- sound/soc/codecs/wsa884x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
sound/soc/codecs/wsa884x.c +2 -2
@@ -859,7 +859,7 @@ static struct sdw_dpn_prop wsa884x_sink_dpn_prop[WSA884X_MAX_SWR_PORTS] = { .num = WSA884X_PORT_VISENSE + 1, .type = SDW_DPN_SIMPLE, .min_ch = 1, - .max_ch = 1, + .max_ch = 2, .simple_ch_prep_sm = true, .read_only_wordlength = true, },
@@ -892,7 +892,7 @@ static const struct sdw_port_config wsa884x_pconfig[WSA884X_MAX_SWR_PORTS] = { }, [WSA884X_PORT_VISENSE] = { .num = WSA884X_PORT_VISENSE + 1, - .ch_mask = 0x1, + .ch_mask = 0x3, }, [WSA884X_PORT_CPS] = { .num = WSA884X_PORT_CPS + 1,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1969/2151 ASoC: codecs: wsa883x: Fix VI sense port channel count
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ravi Hothi <[email protected]>
[ Upstream commit 9728b328d7adf228d5f691d0ec43bb7a6d07e44b ]
The VI sense port carries both the voltage and the current sense data of the speaker, but it is described with max_ch = 1 and, since commit ed3b274abc40 ("ASoC: codecs: wsa883x: Correct VI sense channel mask"), a channel mask of 0x1, so only half of the V/I pair is transferred.
Describe the port as two channels and set the channel mask back to 0x3.
--- sound/soc/codecs/wsa883x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
sound/soc/codecs/wsa883x.c +2 -2
@@ -551,7 +551,7 @@ static struct sdw_dpn_prop wsa_sink_dpn_prop[WSA883X_MAX_SWR_PORTS] = { .num = WSA883X_PORT_VISENSE + 1, .type = SDW_DPN_SIMPLE, .min_ch = 1, - .max_ch = 1, + .max_ch = 2, .simple_ch_prep_sm = true, .read_only_wordlength = true, }
@@ -572,7 +572,7 @@ static const struct sdw_port_config wsa883x_pconfig[WSA883X_MAX_SWR_PORTS] = { }, [WSA883X_PORT_VISENSE ] = { .num =WSA883X_PORT_VISENSE +1 , - .ch_mask =0x1 , + .ch_mask =0x3 , }, };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1970/2151 ASoC: codecs: es*: Modify the registers related to ALC RECOVERY
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhang Yi <[email protected]>
[ Upstream commit dd64271fe1b935252cf454a72a558cbdb7be57c5 ]
The register related to "ALC Capture Recovery Level" is ES8326_ALC_RECOVERY, not ES8326_ALC_LEVEL.
--- sound/soc/codecs/es8326.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/es8326.c +1 -1
@@ -247,7 +247,7 @@ static const struct snd_kcontrol_new es8326_snd_controls[] = {SOC_SINGLE_TLV ("ADC PGA Gain Volume" ,ES8326_PGAGAIN ,0 ,10 ,0 , adc_analog_pga_tlv),SOC_SINGLE_TLV ("ADC Ramp Rate" ,ES8326_ADC_RAMPRATE ,0 ,0x0f ,0 , softramp_rate),SOC_SINGLE ("ALC Capture Switch" ,ES8326_ALC_RECOVERY ,3 ,1 ,0 ), -SOC_SINGLE_TLV ("ALC Capture Recovery Level" ,ES8326_ALC_LEVEL , +SOC_SINGLE_TLV ("ALC Capture Recovery Level" ,ES8326_ALC_RECOVERY ,0 ,4 ,0 , drc_recovery_tlv),SOC_ENUM ("ALC Capture Winsize" , alc_winsize), SOC_SINGLE_TLV("ALC Capture Target Level", ES8326_ALC_LEVEL,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1971/2151 ASoC: codecs: es*: Modify the maximum value of DMIC_GAIN
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhang Yi <[email protected]>
[ Upstream commit 29b867d8351de378704775d3733bfb589c48ab1f ]
The Kcontrol related to DMIC_GAIN affects bits[3:2].
However, the old code sets ES8375_DMIC_GAIN_MAX to 4, which causes the Kcontrol to affect bits [4:2],this is incorrect. Therefore, change ES8375_DMIC_GAIN_MAX to 3.
--- sound/soc/codecs/es8375.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/es8375.h +1 -1
@@ -91,7 +91,7 @@// Function values #define ES8375_ADC_OSR_GAIN_MAX 0x3F -#define ES8375_DMIC_GAIN_MAX 0x04 +#define ES8375_DMIC_GAIN_MAX 0x03#define ES8375_ADC_AUTOMUTE_ATTN_MAX 0x1F#define ES8375_AUTOMUTE_NG_MAX 0x07#define ES8375_ADC_VOLUME_MAX 0xFF
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1972/2151 net/sched: gred: keep the qdisc lock while updating the table
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dudu Lu <[email protected]>
[ Upstream commit 306f788134a21a3d60c1eb872d0ec0ce7c7e09bc ]
gred_change_table_def() publishes table->DPs/def/red_flags under sch_tree_lock(), drops the lock, and then keeps writing state the datapath reads without it:
- gred_enable_rio_mode()/gred_disable_rio_mode()/gred_disable_wred_mode()
set/clear table->flags;
- the red_flags_changed loop writes table->tab[i]->red_flags;
- the shadowed-VQ loop frees table->tab[i] and clears the slot.
gred_enqueue() and gred_dequeue() read those same fields (test_bit on table->flags, q->red_flags, t->tab[]/t->DPs) under the same root lock on another CPU, so the post-unlock writes race with the enqueue path:
BUG: KCSAN: data-race in gred_change_table_def [sch_gred] / gred_enqueue [sch_gred] read (marked) to 0xffff000007ad3b00 of 8 bytes by task 110 on cpu 0: gred_enqueue+0x88/0xc60 [sch_gred] dev_qdisc_enqueue+0x4c/0x19c __dev_queue_xmit+0x10a4/0x1ea4
The comment justifying the early unlock only covers the DP-vs-DPs check, which the shadowed-VQ free loop relies on; it does not cover the scalar mode bits and per-VQ red_flags written afterwards. Move the unlock below those updates so everything the datapath reads is published under the lock that protects it.
--- net/sched/sch_gred.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
net/sched/sch_gred.c +9 -7
@@ -442,13 +442,6 @@ static int gred_change_table_def(struct Qdisc *sch, struct nlattr *dps, red_flags_changed = table->red_flags != sopt->flags; table->red_flags = sopt->flags; -/* -* Every entry point to GRED is synchronized with the above code -* and the DP is checked against DPs, i.e. shadowed VQs can no -* longer be found so we can unlock right here. -*/ -sch_tree_unlock (sch); -if (sopt->grio) {gred_enable_rio_mode (table);gred_disable_wred_mode (table);
@@ -474,6 +467,15 @@ static int gred_change_table_def(struct Qdisc *sch, struct nlattr *dps, } } +/* +* Keep the lock until every field the datapath reads (the +* RIO/WRED mode bits, the per-VQ red_flags and the tab[] slots) +* has been updated: gred_enqueue()/gred_dequeue() read them under +* the same lock, so publishing them after the unlock races with +* the enqueue path. +*/ +sch_tree_unlock (sch); +gred_offload (sch,TC_GRED_REPLACE );return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1973/2151 net: usb: lan78xx: avoid NULL PHY dereference in WoL setup
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Prashant Sengar <[email protected]>
[ Upstream commit dacb77e32e2bba78f90a8637fd27e13e2c9775dd ]
LAN7801 supports fixed-link configurations without an attached PHY. However, lan78xx_set_wol() unconditionally passes netdev->phydev to phy_ethtool_set_wol(), causing a NULL pointer dereference when a userspace WoL request reaches this path.
Report no WoL capabilities when no PHY is attached, and return -EOPNOTSUPP from lan78xx_set_wol() before modifying the wakeup configuration. Keep the existing phylib WoL handling for devices with an attached PHY.
The issue was reproduced using USB Raw Gadget and dummy_hcd in QEMU. An ETHTOOL_SWOL ioctl triggered a kernel Oops with the original driver. With this change, the PHY-less configuration no longer advertises unsupported WoL operations, avoiding the crash.
--- drivers/net/usb/lan78xx.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/net/usb/lan78xx.c +9 -0
@@ -1767,6 +1767,12 @@ static void lan78xx_get_wol(struct net_device *netdev,u32 buf;struct lan78xx_priv *pdata = (struct lan78xx_priv *)(dev->data[0 ]); +if (!netdev->phydev) { + wol->supported =0 ; + wol->wolopts =0 ; +return ; + } +if (usb_autopm_get_interface (dev->intf) <0 )return ;
@@ -1798,6 +1804,9 @@ static int lan78xx_set_wol(struct net_device *netdev,if (wol->wolopts & ~WAKE_ALL )return -EINVAL ; +if (!netdev->phydev) +return -EOPNOTSUPP ; + ret =usb_autopm_get_interface (dev->intf);if (ret <0 )return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1974/2151 net/sched: act_api: inherit filter offload flags only on new actions
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexandre Cassen <[email protected]>
[ Upstream commit 9463e8d8c6922a5aa87f7e4fe6deb4f16925d498 ]
tcf_action_init() gives the skip_sw and skip_hw flags of a filter to the actions it binds. An action that another filter created gets them too, they then apply to every filter that uses this action. When a skip_sw filter reuses the action of a software filter, the software filter silently stops running it. This happens even when the filter add fails on a later action. A skip_hw filter likewise prevents a later filter without flags from reusing the action.
Give the flags only to the actions that the filter creates. The mismatch check still rejects a filter that reuses an action with a flag that the filter does not have.
Discovered by manual code inspection after the Sashiko AI review [1] of a tunnel_key patch questioned how actions get the filter flags. Reproduced on netdevsim without kernel changes. The egress filter below runs in software only, since netdevsim offloads only ingress filters. Once the skip_sw filter reuses its drop action, the last command shows skip_sw on this action and the egress filter stops dropping packets:
ethtool -K eth0 hw-tc-offload on
tc qdisc add dev eth0 clsact
tc filter add dev eth0 egress protocol ip flower dst_ip 192.0.2.1 \
action gact drop index 1
tc filter add dev eth0 ingress protocol ip flower skip_sw \
dst_ip 192.0.2.2 action gact drop index 1
tc actions get action gact index 1
Tested with the reproducer and the tc-testing action, matchall and flower tests.
--- net/sched/act_api.c | 3 +++ 1 file changed, 3 insertions(+)
net/sched/act_api.c +3 -0
@@ -1544,6 +1544,9 @@ int tcf_action_init(struct net *net, struct tcf_proto *tp, struct nlattr *nla, err = -EINVAL ; goto err; } +/* Other filters share an existing action */ +if (init_res[i -1 ] !=ACT_P_CREATED ) +continue ;if (skip_sw) act->tcfa_flags |=TCA_ACT_FLAGS_SKIP_SW ;if (skip_hw)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1975/2151 net/sched: taprio: unwind the netdevice notifier if register_qdisc() fails
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dudu Lu <[email protected]>
[ Upstream commit c5234f89d7cb311880ef218cb7a969794a106678 ]
taprio_module_init() registers taprio_device_notifier and then returns register_qdisc()'s error directly. When register_qdisc() fails the notifier stays registered, but the loader's failure path frees the module image without ever calling the __exit function, so netdev_chain is left pointing at taprio_device_notifier.notifier_call -- a function pointer that lives in text that has just been freed.
register_qdisc() has two failure returns: -EEXIST (duplicate .id) and -EINVAL (malformed cl_ops). taprio_class_ops satisfies every checked implication, so -EINVAL is unreachable and -EEXIST is the only reachable failure; it needs a pre-existing "taprio" entry in qdisc_base. In-tree that is reachable only through bpf_qdisc_reg() (CONFIG_NET_SCH_BPF); a module calling the exported register_qdisc() reaches it as well.
Once the notifier is left dangling, the next netdevice event that walks netdev_chain calls through the stale pointer:
BUG: KASAN: vmalloc-out-of-bounds in notifier_call_chain+0x650/0xb5c Read of size 8 at addr ffff80001fc5ab08 by task ip/110 notifier_call_chain+0x650/0xb5c raw_notifier_call_chain+0x34/0x64 call_netdevice_notifiers_info+0xa8/0x198 __dev_close_many+0xe0/0x800 ... >ffff80001fc5ab00: f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8
The shadow row is all f8 (KASAN_VMALLOC_INVALID): the read lands in vmalloc memory that was poisoned when the module image was freed, and the indirect call is unguarded because the only check, func_ptr_is_kernel_text(), is compiled out unless CONFIG_DEBUG_NOTIFIERS.
Mirror the sibling sch_cbs.c and act_mirred.c, which unwind the notifier on this failure path.
--- net/sched/sch_taprio.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/sched/sch_taprio.c +5 -1
@@ -2567,7 +2567,11 @@ static int __init taprio_module_init(void)if (err)return err; -return register_qdisc (&taprio_qdisc_ops); + err =register_qdisc (&taprio_qdisc_ops); +if (err) +unregister_netdevice_notifier (&taprio_device_notifier); + +return err; } static void __exit taprio_module_exit(void)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1976/2151 net: stmmac: fix rx checksum offload with extended descriptors
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: alex todadze <[email protected]>
[ Upstream commit 72ee27b97986f4d331fe1c26e4333f12738d982f ]
With extended descriptors, bit 0 of RDES0 is the Extended Status Available flag. enh_desc_get_rx_status() still reads it as the payload checksum error bit of the checksum offload table, so every IP frame that has extended status is reported as csum_none and its checksum is verified again in software.
When extended status is available, take the result from RDES4 instead. A TCP, UDP or ICMP payload with no IP header error, no payload error and no checksum bypass is a good frame. Everything else keeps the status from RDES0. Since RDES4 now decides the checksum status, read it after the own bit with dma_rmb(). While at it, fix the IP payload type mask, which covered bits 6:2 instead of 2:0 and had no users.
Tested on a Siflower SF19A2890 (GMAC 3.70) with the board as the iperf3 endpoint. TCP receive goes from 326 to 378 Mbit/s with one stream and from 259 to 329 Mbit/s with four, and CPU use while receiving 200 Mbit/s drops from 26.6% to 21.5%. In stmmac_rx(), frames with a bad TCP, UDP or ICMP checksum, over IPv4 and IPv6 and including fragmented UDP, are still passed up as CHECKSUM_NONE and dropped by the stack.
--- drivers/net/ethernet/stmicro/stmmac/descs.h | 6 ++++- .../net/ethernet/stmicro/stmmac/enh_desc.c | 25 +++++++++++++++++-- drivers/net/ethernet/stmicro/stmmac/hwif.h | 6 ++--- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 19 ++++++++++---- 4 files changed, 45 insertions(+), 11 deletions(-)
drivers/net/ethernet/stmicro/stmmac/descs.h +5 -1
@@ -123,7 +123,7 @@#define ETDES1_BUFFER2_SIZE_SHIFT 16/* Extended Receive descriptor definitions */ -#define ERDES4_IP_PAYLOAD_TYPE_MASK GENMASK(6, 2) +#define ERDES4_IP_PAYLOAD_TYPE_MASK GENMASK(2, 0)#define ERDES4_IP_HDR_ERR BIT(3)#define ERDES4_IP_PAYLOAD_ERR BIT(4)#define ERDES4_IP_CSUM_BYPASSED BIT(5)
@@ -154,6 +154,10 @@#define RDES_PTP_SIGNALING 0xa#define RDES_PTP_PKT_RESERVED_TYPE 0xf +#define RDES_EXT_PAYLOAD_UDP 0x1 +#define RDES_EXT_PAYLOAD_TCP 0x2 +#define RDES_EXT_PAYLOAD_ICMP 0x3 +/* Basic descriptor structure for normal and alternate descriptors */ struct dma_desc {__le32 des0;
drivers/net/ethernet/stmicro/stmmac/enh_desc.c +23 -2
@@ -114,8 +114,25 @@ static int enh_desc_coe_rdes0(int ipc_err, int type, int payload_err)return ret; } -static void enh_desc_get_ext_status (struct stmmac_extra_stats *x, -struct dma_extended_desc *p) +static int enh_desc_ext_rx_csum (u32 rdes0,u32 rdes4,int status) +{ +u32 type =FIELD_GET (ERDES4_IP_PAYLOAD_TYPE_MASK , rdes4); + +if (status != csum_none || !(rdes0 &RDES0_FRAME_TYPE )) +return status; +if (!(rdes4 & (ERDES4_IPV4_PKT_RCVD |ERDES4_IPV6_PKT_RCVD )) || + (rdes4 & (ERDES4_IP_HDR_ERR |ERDES4_IP_PAYLOAD_ERR | +ERDES4_IP_CSUM_BYPASSED ))) +return status; +if (type !=RDES_EXT_PAYLOAD_UDP && type !=RDES_EXT_PAYLOAD_TCP && + type !=RDES_EXT_PAYLOAD_ICMP ) +return status; + +return good_frame; +} + +static int enh_desc_get_ext_status (struct stmmac_extra_stats *x, +struct dma_extended_desc *p,int status) {unsigned int rdes0 =le32_to_cpu (p->basic.des0);unsigned int rdes4 =le32_to_cpu (p->des4);
@@ -175,7 +192,11 @@ static void enh_desc_get_ext_status(struct stmmac_extra_stats *x, x->l4_filter_match++;if ((rdes4 &ERDES4_L3_L4_FILT_NO_MATCH_MASK ) >>26 ) x->l3_l4_filter_no_match++; + + status =enh_desc_ext_rx_csum (rdes0, rdes4, status); } + +return status; } static int enh_desc_get_rx_status(struct stmmac_extra_stats *x,
drivers/net/ethernet/stmicro/stmmac/hwif.h +3 -3
@@ -75,8 +75,8 @@ struct stmmac_desc_ops {/* Return the reception status looking at the RDES1 */ int (*rx_status)(struct stmmac_extra_stats *x,struct dma_desc *p); -void (*rx_extended_status)(struct stmmac_extra_stats *x, -struct dma_extended_desc *p); +int (*rx_extended_status)(struct stmmac_extra_stats *x, +struct dma_extended_desc *p,int status);/* Set tx timestamp enable bit */ void (*enable_tx_timestamp) (struct dma_desc *p);/* get tx timestamp status */
@@ -139,7 +139,7 @@ struct stmmac_desc_ops { #define stmmac_rx_status(__priv, __args...) \ stmmac_do_callback(__priv, desc, rx_status, __args) #define stmmac_rx_extended_status(__priv, __args...) \ - stmmac_do_void_callback(__priv, desc, rx_extended_status, __args) + stmmac_do_callback(__priv, desc, rx_extended_status, __args) #define stmmac_enable_tx_timestamp(__priv, __args...) \ stmmac_do_void_callback(__priv, desc, enable_tx_timestamp, __args) #define stmmac_get_tx_timestamp_status(__priv, __args...) \
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +14 -5
@@ -5407,9 +5407,13 @@ static int stmmac_rx_zc(struct stmmac_priv *priv, int limit, u32 queue)if (!buf->xdp)break ; -if (priv->extend_desc) -stmmac_rx_extended_status (priv, &priv->xstats, - rx_q->dma_erx + entry); +if (priv->extend_desc) { +/* Read the extended status after the own bit */ +dma_rmb (); + status =stmmac_rx_extended_status (priv, &priv->xstats, + &rx_q->dma_erx[entry], + status); + }if (unlikely (status == discard_frame)) {xsk_buff_free (buf->xdp); buf->xdp =NULL ;
@@ -5602,8 +5606,13 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)prefetch (np); -if (priv->extend_desc) -stmmac_rx_extended_status (priv, &priv->xstats, rx_q->dma_erx + entry); +if (priv->extend_desc) { +/* Read the extended status after the own bit */ +dma_rmb (); + status =stmmac_rx_extended_status (priv, &priv->xstats, + &rx_q->dma_erx[entry], + status); + }if (unlikely (status == discard_frame)) {page_pool_put_page (rx_q->page_pool, buf->page,0 , true); buf->page =NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1977/2151 ipmr: clear skb->cb[] in reg_vif_xmit()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 389952e8776a4663044df2ae3e8987a9e81964cf ]
reg_vif_xmit() hands the skb to ipmr_cache_report() as an IGMPMSG_WHOLEPKT report. When the mroute socket has IP_PKTINFO enabled, ipmr_cache_report() calls ipv4_pktinfo_prepare() on the original skb, which reads skb->cb[] as IPCB.
By the time the pimreg device transmits the packet, skb->cb[] is not IPCB anymore: qdisc_pkt_len_init() overwrites IPCB(skb)->iif with qdisc_skb_cb(skb)->pkt_len, and any qdisc installed on the device or a tc BPF program writing skb->cb[] fills the area holding the IP options and IPCB(skb)->flags.
For locally generated packets routed out pimreg (they carry an rtable dst), the mroute socket can therefore receive a bogus ipi_ifindex (the packet length), and the l3mdev slave test in ipv4_pktinfo_prepare() is driven by stale qdisc data.
Clear IPCB before building the report, as done for IPv6 in commit 238164201431 ("ip6mr: clear skb->cb[] in reg_vif_xmit()"). The skb is freed right after, so nothing else depends on its control block.
--- net/ipv4/ipmr.c | 5 +++++ 1 file changed, 5 insertions(+)
net/ipv4/ipmr.c +5 -0
@@ -547,6 +547,11 @@ static netdev_tx_t reg_vif_xmit(struct sk_buff *skb, struct net_device *dev)DEV_STATS_ADD (dev, tx_bytes, skb->len);DEV_STATS_INC (dev, tx_packets); +/* skb->cb[] holds qdisc/tc state at this point, not IPCB. +* ipmr_cache_report() reads it as IPCB to build IP_PKTINFO. +*/ +memset (IPCB (skb),0 ,sizeof (*IPCB (skb))); +/* Pairs with WRITE_ONCE() in vif_add() and vif_delete() */ ipmr_cache_report (mrt, skb,READ_ONCE (mrt->mroute_reg_vif_num),IGMPMSG_WHOLEPKT );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1978/2151 clk: lmk04832: Handle reset GPIO lookup errors
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit 5c7c0cbf81bba69695efa12e451f0f2ecd4b92a5 ]
devm_gpiod_get_optional() may return -EPROBE_DEFER or other errors, but lmk04832_probe() currently ignores them.
Check the return value and propagate errors from the reset GPIO lookup.
--- drivers/clk/clk-lmk04832.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/clk/clk-lmk04832.c +3 -0
@@ -1422,6 +1422,9 @@ static int lmk04832_probe(struct spi_device *spi) lmk->reset_gpio =devm_gpiod_get_optional (&spi->dev,"reset" ,GPIOD_OUT_LOW ); +if (IS_ERR (lmk->reset_gpio)) +return dev_err_probe (lmk->dev,PTR_ERR (lmk->reset_gpio), +"failed to get reset GPIO\n" ); lmk->dclk =devm_kcalloc (lmk->dev, info->num_channels >>1 ,sizeof (struct lmk_dclk ),GFP_KERNEL );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1979/2151 clk: stm32: fix clock array size for STM32MP21
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gabriel Fernandez <[email protected]>
[ Upstream commit 40e5d379cc19fa7fa477414087df5e915d5e843f ]
STM32MP21_LAST_CLK is used as the number of entries of the onecell clk_hw array allocated in stm32_rcc_clock_init(), and as the bound of the clock IDs it can hold. It was wrongly set to CK_SCMI_KER_ETR (112), which belongs to the SCMI clock ID range, whereas the RCC clock IDs go up to CK_KER_STM (289).
As a result the array is too small, and registering a clock whose ID is greater than 111 writes past the end of the allocated clk_hw array (hws[cfg_clock->id] = hw), and consumers requesting such a clock get rejected or read out of bounds.
Define STM32MP21_LAST_CLK as CK_KER_STM + 1 so that the array covers all the RCC clock IDs.
No device tree node uses the STM32MP21 RCC driver yet, so there is no need to backport this patch to stable kernels.
--- drivers/clk/stm32/clk-stm32mp21.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/stm32/clk-stm32mp21.c +2 -2
@@ -17,8 +17,8 @@#include <dt-bindings/clock/st,stm32mp21-rcc.h> #include <dt-bindings/reset/st,stm32mp21-rcc.h> -/* Max clock binding value */ -#define STM32MP21_LAST_CLK CK_SCMI_KER_ETR +/* Number of RCC clock bindings (highest RCC clock ID + 1) */ +#define STM32MP21_LAST_CLK (CK_KER_STM + 1)/* Clock security definition */ #define SECF_NONE -1
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1980/2151 clk: cdce925: Size the PLL child name buffer for any int
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jerome Brunet <[email protected]>
[ Upstream commit e9e6b4dc303dff637ef725aca4f4968d7600798b ]
The PLL child node name is built from "PLL%d" in a 6 byte stack buffer. The PLL index is bounded by the chip's num_plls, at most 4, but GCC cannot see that bound and, with W=1, warns that the formatted string may not fit.
Make the buffer large enough to hold any int and use snprintf() with sizeof() so the size stays tied to the declaration.
--- drivers/clk/clk-cdce925.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/clk/clk-cdce925.c +7 -2
@@ -625,7 +625,12 @@ static int cdce925_probe(struct i2c_client *client)int i;int err;struct device_node *np_output; -char child_name[6 ]; +/* +* The PLL number isn't a compile time constant so GCC can't infer +* the number. Make the stack buffer large enough to hold any int +* so Wformat-truncation does not complain. +*/ +char child_name[15 ];struct regmap_config config = { .name ="configuration0" , .reg_bits =8 ,
@@ -697,7 +702,7 @@ static int cdce925_probe(struct i2c_client *client)dev_err (&client->dev,"Failed register PLL %d\n" , i); goto error; } -sprintf (child_name,"PLL%d" , i+1 ); +snprintf (child_name,sizeof (child_name),"PLL%d" , i +1 ); np_output =of_get_child_by_name (node, child_name);if (!np_output)continue ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1981/2151 tipc: fix refcount panic in tipc_rcv() when receiving shared skb
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tung Nguyen <[email protected]>
[ Upstream commit 5308a2049b764aa55513c90c68933abf596c51d2 ]
TIPC assumes that the received skb is not shared with other users. However, syzbot reports a bug triggered by receiving a shared skb:
...
RIP: 0010:pskb_expand_head+0x135a/0x13a0 net/core/skbuff.c:2308 __pskb_pull_tail+0x111/0x1870 net/core/skbuff.c:2890 skb_cow_data+0x2ed/0xc50 net/core/skbuff.c:5398 tipc_aead_decrypt net/tipc/crypto.c:892 [inline] tipc_crypto_rcv+0x346/0x23d0 net/tipc/crypto.c:1843 tipc_rcv+0x4b7/0x1040 net/tipc/node.c:2119 tipc_l2_rcv_msg+0x2d9/0x470 net/tipc/bearer.c:669 deliver_ptype_list_skb net/core/dev.c:2533 [inline]
...
The root cause is that local delivery hooks in the kernel (e.g., deliver_skb()) may increment the skb's reference count (users) before TIPC processes it on ingress.
Fix this by calling skb_share_check() to ensure exclusive ownership before passing the skb to tipc_rcv(). As TIPC needs to modify the skb's data, the cloned skb needs to be uncloned when needed. This can be addressed in separate patch.
--- net/tipc/bearer.c | 4 ++++ 1 file changed, 4 insertions(+)
net/tipc/bearer.c +4 -0
@@ -659,6 +659,10 @@ static int tipc_l2_rcv_msg(struct sk_buff *skb, struct net_device *dev, {struct tipc_bearer *b; + skb =skb_share_check (skb,GFP_ATOMIC ); +if (!skb) +return NET_RX_DROP ; +rcu_read_lock (); b =rcu_dereference (dev->tipc_ptr) ?:rcu_dereference (orig_dev->tipc_ptr);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1982/2151 pppoe: drop discovery frames with no MAC header
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qingfang Deng <[email protected]>
[ Upstream commit 406bf2dc8d6d3e93fdae0b66d2ae99b6b62e479c ]
Commit 8540827ebac6 ("pppoe: fix reception of frames with no mac header") drops PPPoE session frames with no MAC header to avoid reading uninitialized memory.
Apply the same to PPPoE discovery frames, as both functions read eth_hdr(skb)->h_source.
Found by LLM static analysis, and reproduced using the same TUN injection as described in the mentioned commit.
--- drivers/net/ppp/pppoe.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/ppp/pppoe.c +3 -0
@@ -492,6 +492,9 @@ static int pppoe_disc_rcv(struct sk_buff *skb, struct net_device *dev,if (skb->pkt_type !=PACKET_HOST ) goto abort; +if (skb_mac_header_len (skb) <ETH_HLEN ) + goto abort; +if (!pskb_may_pull (skb,sizeof (struct pppoe_hdr ))) goto abort;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1983/2151 gtp: hold RCU in gtp_genl_send_echo_req()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paolo Abeni <[email protected]>
[ Upstream commit a204e9c001dfafe83cac01b16508b1cf5c953355 ]
Such function is invoked in process context, performs an RCU device lookup and dereference the found device with no additional protection.
=============================
WARNING: suspicious RCU usage
7.3.0-virtme #7 Not tainted
-----------------------------
net/core/dev.c:1047 RCU-list traversed in non-reader section!!
other info that might help us debug this:
rcu_scheduler_active = 2, debug_locks = 1
locks held by python3/233: 2, last CPU#5:
#0: ffffffffbab93268 (cb_lock){++++}-{4:4}, at: genl_rcv+0x19/0x40 #1: ffffffffbab93320 (genl_mutex){+.+.}-{4:4}, at:
genl_rcv_msg+0x12c/0x160 stack backtrace: CPU: 5 UID: 0 PID: 233 Comm: python3 Not tainted 7.3.0#7 PREEMPT(full) Hardware name: Bochs, BIOS Bochs 01/01/2011 Call Trace: <TASK> dump_stack_lvl+0x6f/0xb0 lockdep_rcu_suspicious.cold+0x37/0x8e dev_get_by_index_rcu+0x135/0x180 gtp_find_dev+0xe7/0x360 [gtp] gtp_genl_send_echo_req+0x298/0xb30 [gtp] genl_family_rcv_msg_doit+0x20f/0x310 genl_family_rcv_msg+0x3a8/0x640 genl_rcv_msg+0xbb/0x160 netlink_rcv_skb+0x154/0x3a0 genl_rcv+0x28/0x40 netlink_unicast+0x54b/0x860 netlink_sendmsg+0x7fb/0xf60 __sys_sendto+0x3d6/0x450 __x64_sys_sendto+0xe4/0x1f0 do_syscall_64+0xff/0x530 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7ffa43b0256e Code: 4d 89 d8 e8 d4 bd 00 00 4c 8b 5d f8 41 8b 93 08 03 00 00 59 5e 48 83 f8 fc 74 11 c9 c3 0f 1f 80 00 00 00 00 48 8b 45 10 0f 05 <c9> c3 83 e2 39 83 fa 08 75 e7 e8 03 ff ff ff 0f 1f 00 f3 0f 1e fa RSP: 002b:00007ffd3b8828d0 EFLAGS: 00000202 ORIG_RAX: 000000000000002c RAX: ffffffffffffffda RBX: 00007ffd3b8829e0 RCX: 00007ffa43b0256e RDX: 0000000000000034 RSI: 00007ffa3519d0d0 RDI: 0000000000000006 RBP: 00007ffd3b8828e0 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000202 R12: 00007ffa351cc0c0 R13: 00007ffd3b8829e0 R14: 00007ffa354ca130 R15: 00007ffa4433d498 </TASK>
Add the missing RCU guards and keep it for the whole function body, while the RCU-protected device is used.
Found by code inspection, validated explicitly testing the relevant code path.
--- drivers/net/gtp.c | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-)
drivers/net/gtp.c +30 -14
@@ -2355,9 +2355,9 @@ static int gtp_genl_send_echo_req(struct sk_buff *skb, struct genl_info *info)struct gtp_dev *gtp;struct flowi4 fl4;struct rtable *rt; +int len, ret =0 ;struct sock *sk;__be16 port; -int len; if (!info->attrs[GTPA_VERSION] || !info->attrs[GTPA_LINK] ||
@@ -2369,14 +2369,21 @@ static int gtp_genl_send_echo_req(struct sk_buff *skb, struct genl_info *info) dst_ip =nla_get_be32 (info->attrs[GTPA_PEER_ADDRESS ]); src_ip =nla_get_be32 (info->attrs[GTPA_MS_ADDRESS ]); +rcu_read_lock (); gtp =gtp_find_dev (sock_net (skb->sk), info->attrs); -if (!gtp) -return -ENODEV ; +if (!gtp) { + ret = -ENODEV ; + goto unlock; + } -if (!gtp->sk_created) -return -EOPNOTSUPP ; -if (!(gtp->dev->flags &IFF_UP )) -return -ENETDOWN ; +if (!gtp->sk_created) { + ret = -EOPNOTSUPP ; + goto unlock; + } +if (!(gtp->dev->flags &IFF_UP )) { + ret = -ENETDOWN ; + goto unlock; + }if (version ==GTP_V0 ) {struct gtp0_header *gtp0_h;
@@ -2385,8 +2392,10 @@ static int gtp_genl_send_echo_req(struct sk_buff *skb, struct genl_info *info)sizeof (struct iphdr ) +sizeof (struct udphdr ); skb_to_send =netdev_alloc_skb_ip_align (gtp->dev, len); -if (!skb_to_send) -return -ENOMEM ; +if (!skb_to_send) { + ret = -ENOMEM ; + goto unlock; + } sk = gtp->sk0; port =htons (GTP0_PORT );
@@ -2402,8 +2411,10 @@ static int gtp_genl_send_echo_req(struct sk_buff *skb, struct genl_info *info)sizeof (struct iphdr ) +sizeof (struct udphdr ); skb_to_send =netdev_alloc_skb_ip_align (gtp->dev, len); -if (!skb_to_send) -return -ENOMEM ; +if (!skb_to_send) { + ret = -ENOMEM ; + goto unlock; + } sk = gtp->sk1u; port =htons (GTP1U_PORT );
@@ -2413,7 +2424,8 @@ static int gtp_genl_send_echo_req(struct sk_buff *skb, struct genl_info *info)memset (gtp1u_h,0 ,sizeof (struct gtp1_header_long ));gtp1u_build_echo_msg (gtp1u_h,GTP_ECHO_REQ ); }else { -return -ENODEV ; + ret = -ENODEV ; + goto unlock; } rt =ip4_route_output_gtp (&fl4, sk, dst_ip, src_ip);
@@ -2421,7 +2433,8 @@ static int gtp_genl_send_echo_req(struct sk_buff *skb, struct genl_info *info)netdev_dbg (gtp->dev,"no route for echo request to %pI4\n" , &dst_ip);kfree_skb (skb_to_send); -return -ENODEV ; + ret = -ENODEV ; + goto unlock; }local_bh_disable ();
@@ -2435,7 +2448,10 @@ static int gtp_genl_send_echo_req(struct sk_buff *skb, struct genl_info *info) dev_net(gtp->dev)), false, 0);local_bh_enable (); -return 0 ; + +unlock: +rcu_read_unlock (); +return ret; }static const struct nla_policy gtp_genl_policy[GTPA_MAX +1 ] = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1984/2151 net: atlantic: Unregister before clearing RXNFC rules
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Binbin Deng <[email protected]>
[ Upstream commit 13b364c765e69db1f8446399d8db0b331c23b50c ]
aq_pci_remove() clears the driver's RXNFC rule list before unregistering the netdevice. Until unregister_netdev() returns, ethtool operations can still call aq_get_rxnfc_rule(), aq_get_rxnfc_all_rules(), aq_add_rxnfc_rule(), or aq_del_rxnfc_rule(). Those paths traverse the same unlocked hlist that aq_clear_rxnfc_all_rules() is mutating and freeing.
The race is reachable by issuing RXNFC ethtool commands concurrently with PCI device removal or driver unbind. A reader can dereference a node that has just been freed, and two writers can corrupt the list or free the same rule more than once, causing KASAN reports, list corruption, or a kernel panic.
Reverse the removal order: unregister the netdevice first, then clear the RXNFC rules. After unregister_netdev() returns, ethtool can no longer enter the driver, while the PCI device is still available for the rule-clearing routine to issue hardware commands.
Found during a static-analysis-assisted audit: candidate sites were surfaced by a Coccinelle rule, and the reader/writer paths were confirmed by LLM-assisted (GLM-5.3) code inspection. The issue was not observed at runtime; it is identified by code inspection only.
--- drivers/net/ethernet/aquantia/atlantic/aq_pci_func.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/aquantia/atlantic/aq_pci_func.c +1 -1
@@ -343,9 +343,9 @@ static void aq_pci_remove(struct pci_dev *pdev)struct aq_nic_s *self =pci_get_drvdata (pdev);if (self->ndev) { -aq_clear_rxnfc_all_rules (self);if (self->ndev->reg_state ==NETREG_REGISTERED )unregister_netdev (self->ndev); +aq_clear_rxnfc_all_rules (self);#if IS_ENABLED (CONFIG_MACSEC )aq_macsec_free (self);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1985/2151 net: usb: cdc_ncm: dont enable BHs in tx_fixup under netpoll
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicolai Buchwitz <[email protected]>
[ Upstream commit 108ca34cf4b453f6375a70079e32b11866b02601 ]
netpoll holds the txq lock and calls ndo_start_xmit() with IRQs off but BHs on. The spin_unlock_bh() in cdc_ncm_tx_fixup() then runs pending softirqs. If one of them transmits, it spins on the txq lock that netpoll holds. With netconsole on a cdc_ncm device this ends in a soft or hard lockup.
Every caller of cdc_ncm_tx_fixup() holds the txq lock with BHs or IRQs off, so the softirq user of ctx->mtx cannot interrupt it. Use plain spin_lock().
--- drivers/net/usb/cdc_ncm.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/usb/cdc_ncm.c +5 -2
@@ -1535,14 +1535,17 @@ cdc_ncm_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)if (ctx ==NULL ) goto error; -spin_lock_bh (&ctx->mtx); +/* BHs or IRQs are always off here. netpoll only disables IRQs, and +* spin_unlock_bh() would then run softirqs with the txq lock held. +*/ +spin_lock (&ctx->mtx);if (ctx->is_ndp16) skb_out =cdc_ncm_fill_tx_frame (dev, skb,cpu_to_le32 (USB_CDC_NCM_NDP16_NOCRC_SIGN ));else skb_out =cdc_ncm_fill_tx_frame (dev, skb,cpu_to_le32 (USB_CDC_NCM_NDP32_NOCRC_SIGN )); -spin_unlock_bh (&ctx->mtx); +spin_unlock (&ctx->mtx);return skb_out; error:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1986/2151 net: usb: cdc_mbim: dont enable BHs in tx_fixup under netpoll
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicolai Buchwitz <[email protected]>
[ Upstream commit bfd7ced012c7857b5ab5edf7e416c2789b652702 ]
cdc_mbim_tx_fixup() has the same spin_unlock_bh() as cdc_ncm_tx_fixup(). Under netpoll it runs pending softirqs while the txq lock is held, and a transmit from one of them spins on that lock.
Use plain spin_lock() as in cdc_ncm.
--- drivers/net/usb/cdc_mbim.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/usb/cdc_mbim.c +3 -2
@@ -290,9 +290,10 @@ static struct sk_buff *cdc_mbim_tx_fixup(struct usbnet *dev, struct sk_buff *skb } } -spin_lock_bh (&ctx->mtx); +/* BHs or IRQs are always off here, see cdc_ncm_tx_fixup() */ +spin_lock (&ctx->mtx); skb_out =cdc_ncm_fill_tx_frame (dev, skb, sign); -spin_unlock_bh (&ctx->mtx); +spin_unlock (&ctx->mtx);return skb_out; error:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1987/2151 ALSA: pcmtest: Honor the enable parameter
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: HyeongJun An <[email protected]>
[ Upstream commit fe3b45a0875a8b0944d2adee3ca62283d876edc0 ]
The enable module parameter is declared and documented as "Enable pcmtest soundcard.", but nothing reads it. Loading the module with enable=0 still creates the card.
Return -ENODEV from mod_init() when enable is false, as the pcsp driver does.
--- sound/drivers/pcmtest.c | 3 +++ 1 file changed, 3 insertions(+)
sound/drivers/pcmtest.c +3 -0
@@ -763,6 +763,9 @@ static int __init mod_init(void) {int err =0 ; +if (!enable) +return -ENODEV ; + buf_allocated =setup_patt_bufs ();if (!buf_allocated)return -ENOMEM ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1988/2151 ALSA: usb-audio: Add correct datainterval in the quirks-table for Microbook II
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sally Marcher <[email protected]>
[ Upstream commit a09c2f3b267e47767b8937f65930567edbb88d44 ]
This patch fixes playback issues on the Microbook II. The correct value was in the older driver for this device
(https://github.com/manuel-rhdt/snd-microbookii/blob/dd304c097bb6a9d52276ac29c6969fa02bc7674a/audio.c#L914).
Datainterval needs to be set explicitly.
--- sound/usb/quirks-table.h | 2 ++ 1 file changed, 2 insertions(+)
sound/usb/quirks-table.h +2 -0
@@ -2753,6 +2753,7 @@ YAMAHA_DEVICE(0x7010, "UB99"), .rates = SNDRV_PCM_RATE_96000, .ep_attr =USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_ASYNC, + .datainterval = 1, .rate_min = 96000, .rate_max = 96000, .nr_rates = 1,
@@ -2775,6 +2776,7 @@ YAMAHA_DEVICE(0x7010, "UB99"), .rates = SNDRV_PCM_RATE_96000, .ep_attr =USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_ASYNC, + .datainterval = 1, .rate_min = 96000, .rate_max = 96000, .nr_rates = 1,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1989/2151 net: tun: hold napi_mutex when deleting NAPI in tun_detach_all()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cheng Yongkang <[email protected]>
[ Upstream commit 6c799b4998c87bb44574bb090b8728bb3b3dbc47 ]
With IFF_NAPI_FRAGS, tun_get_user() takes tfile->napi_mutex, gets the skb from napi_get_frags() and copies the user data into it before it enters the RCU read-side section around napi_gro_frags().
tun_detach_all() waits with synchronize_net() and then calls tun_napi_del() without napi_mutex. netif_napi_del() frees napi->skb through napi_free_frags(). A writer that is still copying has not yet entered its RCU section, so synchronize_net() does not wait for it, and deleting the device frees the skb while the writer is using it:
BUG: KASAN: slab-use-after-free in skb_copy_datagram_from_iter+0x175/0x720 Read of size 8 at addr ffff888077def990 by task br029-poc/9406 Call Trace: skb_copy_datagram_from_iter+0x175/0x720 tun_get_user+0xb42/0x3d00 tun_chr_write_iter+0x113/0x200 ... Freed by task 9405: kmem_cache_free+0x184/0x670 __netif_napi_del_locked+0x2bb/0x3c0 tun_net_uninit+0x566/0xa70 unregister_netdevice_many_notify+0x1a26/0x2090 rtnl_dellink+0x514/0x710
__tun_detach() also calls tun_napi_del() without the mutex, but only from tun_chr_close(), when no write on that file can be in flight.
Take napi_mutex around tun_napi_del() in tun_detach_all() for both attached and disabled queues.
--- drivers/net/tun.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/tun.c +4 -0
@@ -672,14 +672,18 @@ static void tun_detach_all(struct net_device *dev)synchronize_net ();for (i =0 ; i < n; i++) { tfile =rtnl_dereference (tun->tfiles[i]); +mutex_lock (&tfile->napi_mutex);tun_napi_del (tfile); +mutex_unlock (&tfile->napi_mutex);/* Drop read queue */ tun_queue_purge (tfile);xdp_rxq_info_unreg (&tfile->xdp_rxq);sock_put (&tfile->sk); }list_for_each_entry_safe (tfile, tmp, &tun->disabled, next) { +mutex_lock (&tfile->napi_mutex);tun_napi_del (tfile); +mutex_unlock (&tfile->napi_mutex);tun_enable_queue (tfile);tun_queue_purge (tfile);xdp_rxq_info_unreg (&tfile->xdp_rxq);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1990/2151 net: dsa: mt7530: trap frames to conduit in MFC on EN7581 and AN7583
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tao Gong <[email protected]>
[ Upstream commit a58b221496dd576191095d12996f39cee58cf6a8 ]
On EN7581, STP BPDUs received on switch user ports never reach the CPU.
Like MT7531 and MT7988, EN7581 and AN7583 only set the CPU port bitmap in MT7531_CFC and are skipped by mt753x_conduit_state_change(). On EN7581 this is not enough: trapped BPDUs reach the CPU only when MT7530_CPU_EN and MT7530_CPU_PORT are also set in MT753X_MFC. Add EN7581 and AN7583 to mt753x_conduit_state_change().
Tested on an AN7581 board (Gemtek W1700K, airoha,en7581-switch), where only lan3 and lan4 are switch user ports. With RSTP BPDUs arriving on lan4:
- without this patch, none reached the CPU;
- setting CPU_EN and CPU_PORT by hand delivered them, and clearing them stopped them;
- with this patch, they are received from boot.
Only BPDUs were tested. AN7583 is untested and is included because the driver sets it up like EN7581.
--- drivers/net/dsa/mt7530.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/dsa/mt7530.c +5 -2
@@ -3280,10 +3280,13 @@ mt753x_conduit_state_change(struct dsa_switch *ds,/* Set the CPU port to trap frames to for MT7530. Trapped frames will be * forwarded to the numerically smallest CPU port whose conduit -* interface is up. +* interface is up. On EN7581, trapped BPDUs do not reach the CPU port +* without this, even with the CPU port bitmap set. AN7583 is set up +* the same way as EN7581. */ if (priv->id !=ID_MT7530 && priv->id !=ID_MT7621 && - priv->id !=ID_EN7528 ) + priv->id !=ID_EN7528 && + priv->id !=ID_EN7581 && priv->id !=ID_AN7583 )return ; mask =BIT (cpu_dp->index);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1991/2151 net/rds: do not fail init when CONFIG_SYSCTL=n
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Allison Henderson <[email protected]>
[ Upstream commit fbea154a86641d2543a871aa19f7c77a366de542 ]
With CONFIG_SYSCTL=n, register_net_sysctl() and register_net_sysctl_sz() are inline stubs that return NULL. rds_sysctl_init(), rds_ib_sysctl_init() and rds_tcp_init_net() all treat that NULL as -ENOMEM, so RDS refuses to initialize at all even though every tunable has a sane compiled-in default.
When RDS is built in, that is worse than a missing feature: the failed rds_init() destroys rds_wq, but the rds_rdma initcall still runs, and when rds_ib_sysctl_init() fails the same way, the error path in rds_ib_init() flushes the already freed workqueue:
BUG: KASAN: slab-use-after-free in touch_wq_lockdep_map ... __flush_workqueue rds_ib_init rds_rdma_init ... Allocated by task 1: alloc_workqueue_noprof rds_threads_init rds_init ... Freed by task 0: kfree rcu_do_batch
Only treat the NULL return as a failure when sysctl support is actually compiled in. The exit paths need no change: unregister_net_sysctl_table() is an empty stub with CONFIG_SYSCTL=n and already tolerates a NULL header otherwise.
The underlying problem of built-in transports initializing after rds_init() has failed is independent of sysctl and is addressed separately.
--- net/rds/ib_sysctl.c | 2 +- net/rds/sysctl.c | 2 +- net/rds/tcp.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
net/rds/ib_sysctl.c +1 -1
@@ -114,7 +114,7 @@ void rds_ib_sysctl_exit(void)int rds_ib_sysctl_init (void ) { rds_ib_sysctl_hdr =register_net_sysctl (&init_net,"net/rds/ib" , rds_ib_sysctl_table); -if (!rds_ib_sysctl_hdr) +if (!rds_ib_sysctl_hdr &&IS_ENABLED (CONFIG_SYSCTL ))return -ENOMEM ;return 0 ; }
net/rds/sysctl.c +1 -1
@@ -103,7 +103,7 @@ int rds_sysctl_init(void) rds_sysctl_reg_table =register_net_sysctl (&init_net,"net/rds" , rds_sysctl_rds_table); -if (!rds_sysctl_reg_table) +if (!rds_sysctl_reg_table &&IS_ENABLED (CONFIG_SYSCTL ))return -ENOMEM ;return 0 ; }
net/rds/tcp.c +1 -1
@@ -643,7 +643,7 @@ static __net_init int rds_tcp_init_net(struct net *net) tbl[RDS_TCP_RCVBUF ].data = &rtn->rcvbuf_size; rtn->rds_tcp_sysctl =register_net_sysctl_sz (net,"net/rds/tcp" , tbl,ARRAY_SIZE (rds_tcp_sysctl_table)); -if (!rtn->rds_tcp_sysctl) { +if (!rtn->rds_tcp_sysctl &&IS_ENABLED (CONFIG_SYSCTL )) {pr_warn ("could not register sysctl\n" ); err = -ENOMEM ; goto fail;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1992/2151 net/rds: do not initialize transports after rds_init() failed
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Allison Henderson <[email protected]>
[ Upstream commit ffbbc315b8b883a1c0e131fb3186b9428d2812aa ]
rds, rds_rdma and rds_tcp each have their own module_init(). When they are built in, those run in link order, so rds_init() goes first, but do_initcalls() does not stop when it fails. The transports then initialize against a core that has already been torn down: rds_wq has been destroyed, yet rds_ib_dev_put(), rds_ib_unregister_client() and rds_tcp_accept_work() still queue onto or flush it, and rds_trans_register() hands the transports to a core whose socket family may never have been registered.
This was seen with CONFIG_SYSCTL=n, where rds_sysctl_init() failed and rds_ib_init()'s error path then flushed the freed rds_wq [1], but any rds_init() failure after rds_threads_init() has the same effect.
Record whether rds_init() succeeded and have rds_rdma_init() and rds_tcp_init() bail out with -ENODEV otherwise. Modular builds are
unaffected: the transports need symbols exported by rds.ko, so they cannot be loaded unless rds_init() succeeded.
[1] https://lore.kernel.org/oe-lkp/[email protected]
--- net/rds/af_rds.c | 14 ++++++++++++++ net/rds/rdma_transport.c | 3 +++ net/rds/rds.h | 1 + net/rds/tcp.c | 3 +++ 4 files changed, 21 insertions(+)
net/rds/af_rds.c +14 -0
@@ -921,8 +921,11 @@ static void rds6_sock_info(struct socket *sock, unsigned int len, }#endif +static bool rds_initialized; +static void rds_exit (void ) { + rds_initialized = false;sock_unregister (rds_family_ops.family);proto_unregister (&rds_proto);rds_conn_exit ();
@@ -943,6 +946,16 @@ module_exit(rds_exit);u32 rds_gen_num; +/* When RDS is built in, a failed rds_init() does not stop the rds_rdma +* and rds_tcp initcalls from running against a core that has already +* been torn down (rds_wq in particular). Let them bail out early. +*/ +bool rds_is_initialized (void ) +{ +return rds_initialized; +} +EXPORT_SYMBOL_GPL (rds_is_initialized); +static int __init rds_init (void ) {int ret;
@@ -979,6 +992,7 @@ static int __init rds_init(void)rds_info_register_func (RDS6_INFO_SOCKETS , rds6_sock_info);rds_info_register_func (RDS6_INFO_RECV_MESSAGES , rds6_sock_inc_info);#endif + rds_initialized = true; goto out;
net/rds/rdma_transport.c +3 -0
@@ -325,6 +325,9 @@ static int __init rds_rdma_init(void) {int ret; +if (!rds_is_initialized ()) +return -ENODEV ; + ret =rds_ib_init ();if (ret) goto out;
net/rds/rds.h +1 -0
@@ -1008,6 +1008,7 @@ extern unsigned int rds_sysctl_trace_level;int rds_threads_init (void );void rds_threads_exit (void );extern struct workqueue_struct *rds_wq; +bool rds_is_initialized (void );void rds_queue_reconnect (struct rds_conn_path *cp);void rds_connect_worker (struct work_struct *);void rds_shutdown_worker (struct work_struct *);
net/rds/tcp.c +3 -0
@@ -819,6 +819,9 @@ static int __init rds_tcp_init(void) {int ret; +if (!rds_is_initialized ()) +return -ENODEV ; + rds_tcp_conn_slab =KMEM_CACHE (rds_tcp_connection,0 );if (!rds_tcp_conn_slab) { ret = -ENOMEM ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1993/2151 vxlan: keep reserved_bits across changelink
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hannes Laimer <[email protected]>
[ Upstream commit e3a629477d52a9f49d50d72903be06a4d1f4aa58 ]
vxlan_nl2conf() derives reserved_bits from the extension attributes set in the netlink message if IFLA_VXLAN_RESERVED_BITS is absent. A changelink having it set is rejected, so this means that every changelink will reset all extension bits and reserve them again. vxlan_nl2flag() rejects setting a flag on an attribute that is create-only on changelink. So also setting an extension attribute will fail before it can un-reserve its fields.
The extension's header bits being reserved again then makes vxlan_rcv() drop frames that have them set in their header as invalid. The device still reports the extension as enabled, because only the reserved_bits are rebuilt and the flags are just copied.
A simple reproducer is
ip link add vxgbp type vxlan id 1 dstport 4789 local 10.0.0.1 gbp ip link set dev vxgbp type vxlan ageing 300
After setting the unrelated ageing, incoming packets with the GBP bit set in the header start getting dropped.
Keeping the reserved_bits on changelink is safe because anything a changelink accepts leaves the header bits enabled extensions use unchanged.
Ran into this when adding support for the GBP flag in ifupdown2, see link below. The device kept dropping packets after some time, it turned out it always started after a changelink.
Tested this by changing ageing by hand on a vxlan device that was created by ifupdown2 with the gbp flag, and checking the reserved bits using
ip -d link show vxgbp | grep -o 'reserved_bits 0x[0-9a-f]*'
Without the fix I got 0xf7ffffff000000ff after the changelink, and with the fix it stayed 0x77000000000000ff. The following patch contains a selftest that fails without the fix and passes with it.
--- drivers/net/vxlan/vxlan_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/vxlan/vxlan_core.c +1 -1
@@ -4350,7 +4350,7 @@ static int vxlan_nl2conf(struct nlattr *tb[], struct nlattr *data[], } conf->reserved_bits = reserved_bits; - }else { + }else if (!changelink) {/* For backwards compatibility, only allow reserved fields to be * used by VXLAN extensions if explicitly requested. */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1994/2151 pppoe: wait for RCU readers before reusing a socket
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qingfang Deng <[email protected]>
[ Upstream commit e7b01bc0202a57f1b7dcdf19b2ffab6b781d47f8 ]
When pppoe_connect() disconnects or reuses a socket, it removes the old session from the hash table and resets the socket's fields. An RCU reader that reached the entry before it was unlinked can still be using its address, ifindex or next pointer.
If sockets A and B share a hash bucket with A preceding B, a concurrent __get_item() looking for B can be traversing A when it is removed. Clearing A->next then makes the lookup miss B and drop the packet. Reinserting A can similarly redirect the reader into another hash chain.
Call synchronize_net() after unlinking the old session and before clearing its fields. This allows existing receive-path and /proc/net/pppoe readers to finish before the socket is cleared or reused.
This was found by Sashiko's static analysis, and reproduced on a VM stress test with KCSAN.
BUG: KCSAN: data-race in hash_item+0x1c/0x60
race at unknown origin, with read to 0xffff888000a1c566 of 2 bytes by task 147 on cpu 2:
hash_item+0x1c/0x60 pppoe_seq_next+0x112/0x1b0 seq_read_iter+0x595/0x700 seq_read+0xb0/0xe0 proc_reg_read+0xd0/0xf0 vfs_read+0xbd/0x220 ksys_read+0xa9/0x100 __x64_sys_read+0x47/0x60 x64_sys_call+0x98/0x1fd0 do_syscall_64+0x5b/0x260 entry_SYSCALL_64_after_hwframe+0x4b/0x53
value changed: 0x0002 -> 0x0000
--- drivers/net/ppp/pppoe.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/ppp/pppoe.c +4 -0
@@ -653,6 +653,10 @@ static int pppoe_connect(struct socket *sock, struct sockaddr *uservaddr,pppox_unbind_sock (sk); pn =pppoe_pernet (sock_net (sk));delete_item (pn, po); + +/* wait for concurrent readers before clearing the fields */ +synchronize_net (); +if (po->pppoe_dev) {dev_put (po->pppoe_dev); po->pppoe_dev =NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1995/2151 net: xps: bound the cleanup loop by the old maps num_tc
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dudu Lu <[email protected]>
[ Upstream commit 6d5a2cb0b7d6caf170d37ae7ac74738d592d2a05 ]
__netif_set_xps_queue() walks the OLD dev_maps to free its entries. The per-row trip count uses the NEW num_tc while the row stride uses the OLD dev_maps->num_tc, so when dev->num_tc was raised without rebuilding the XPS map the last row indexes attr_map[] past the allocation:
BUG: KASAN: slab-out-of-bounds in __netif_set_xps_queue+0x1458/0x1ee8 Read of size 8 at addr ffff000014f69458 by task insmod/112
The loop frees entries in dev_maps, so both the trip count and the stride must come from dev_maps->num_tc. The map is sized XPS_CPU_DEV_MAPS_SIZE(old num_tc)/XPS_RXQ_DEV_MAPS_SIZE(old num_tc, ...), so iterating the new (larger) num_tc reads past the end.
--- net/core/dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/dev.c +1 -1
@@ -2971,7 +2971,7 @@ int __netif_set_xps_queue(struct net_device *dev, const unsigned long *mask, goto out_no_old_maps;for (j =0 ; j < dev_maps->nr_ids; j++) { -for (i = num_tc, tci = j * dev_maps->num_tc; i--; tci++) { +for (i = dev_maps->num_tc, tci = j * dev_maps->num_tc; i--; tci++) { map =xmap_dereference (dev_maps->attr_map[tci]);if (!map)continue ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1996/2151 net: lan966x: do not inject uninitialised bytes past skb->len
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Machon <[email protected]>
[ Upstream commit b4a7180558eb3cd8affa1e240b22171425bdfcb4 ]
lan966x_port_ifh_xmit() writes the frame to the injection FIFO one 32-bit word at a time, and pads frames shorter than 60 bytes with zero words.
Before this patch, the last word is loaded whole even when skb->len is not a multiple of four, so 1 to 3 bytes past the end of the frame are read. For a frame shorter than 60 bytes those bytes are also transmitted, as VLD_BYTES marks the whole last word valid and the padding starts at the next word.
Write the trailing bytes from a zeroed word. The number of words written and VLD_BYTES are unchanged.
Found by an AI code review agent. Reproduced on a lan9668 board with register injection, by sending a
57 byte frame and capturing it on the link partner: byte 57 of the padded frame was not zero. With the fix all padding bytes are zero.
--- .../ethernet/microchip/lan966x/lan966x_main.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
drivers/net/ethernet/microchip/lan966x/lan966x_main.c +16 -3
@@ -253,9 +253,8 @@ static int lan966x_port_ifh_xmit(struct sk_buff *skb,lan_wr ((__force u32 )ifh[i], lan966x,QS_INJ_WR (grp)); } -/* Write frame */ - count =DIV_ROUND_UP (skb->len,4 ); - last = skb->len %4 ; +/* Write the whole words of the frame */ + count = skb->len /4 ;for (i =0 ; i < count; ++i) {/* Wait until the fifo is ready */ err =lan966x_port_inj_ready (lan966x, grp);
@@ -265,6 +264,20 @@ static int lan966x_port_ifh_xmit(struct sk_buff *skb,lan_wr (((u32 *)skb->data)[i], lan966x,QS_INJ_WR (grp)); } +/* Write the last 1 to 3 bytes, zero padded to a whole word */ + last = skb->len %4 ; +if (last) { +/* Wait until the fifo is ready */ + err =lan966x_port_inj_ready (lan966x, grp); +if (err) + goto err; + + val =0 ; +memcpy (&val, skb->data + count *4 , last); +lan_wr (val, lan966x,QS_INJ_WR (grp)); + ++i; + } +/* Add padding */ while (i < (LAN966X_BUFFER_MIN_SZ /4 )) {/* Wait until the fifo is ready */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1997/2151 net: lan966x: do not warn on MAC entries that are not port destined
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Machon <[email protected]>
[ Upstream commit 2cffcf1aeabb187e4f08fe4f5363128a3c45d786 ]
lan966x_mac_irq_handler() scans the rows of the MAC table that the analyzer reports as changed, reads back all four columns of each row and treats ANA_MACACCESS.DEST_IDX as a port number.
Before this patch, a destination index above num_phys_ports hits a WARN_ON(). The driver installs such entries itself:lan966x_mac_cpu_learn() uses PGID_CPU, and L2 multicast entries use a general-purpose PGID. A row holding one of them is read back whenever another entry in the same row is learned or aged out, so the scan warns in normal operation, repeatedly once the MAC table is busy.
Skipping such a column is already the right behaviour. Drop the WARN_ON() and keep the bounds check as a plain filter.
Found by an AI code review agent. Reproduced on a lan9668 board by bridging two ports with a 10 s ageing time and sending three rounds of 2048 new source MACs: the base kernel warned 42 times from lan966x_mac_irq_process(), the fixed kernel did not warn.
--- drivers/net/ethernet/microchip/lan966x/lan966x_mac.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/microchip/lan966x/lan966x_mac.c +2 -2
@@ -447,7 +447,7 @@ static void lan966x_mac_irq_process(struct lan966x *lan966x, u32 row,lan966x_mac_process_raw_entry (&raw_entries[column], mac, &vid, &dest_idx); -if (WARN_ON (dest_idx >= lan966x->num_phys_ports)) +if (dest_idx >= lan966x->num_phys_ports)continue ;/* If the entry in SW is found, then there is nothing
@@ -501,7 +501,7 @@ static void lan966x_mac_irq_process(struct lan966x *lan966x, u32 row,lan966x_mac_process_raw_entry (&raw_entries[column], mac, &vid, &dest_idx); -if (WARN_ON (dest_idx >= lan966x->num_phys_ports)) +if (dest_idx >= lan966x->num_phys_ports)continue ;spin_lock (&lan966x->mac_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1998/2151 block: fix recursive i_rwsem locking in blkdev_write_iter()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhenxian Ma <[email protected]>
[ Upstream commit 21b88cc8bafceee6c6c82503e3b2cc6f1d0c78bf ]
Commit 2fec4fd97cc3 ("block: take i_rwsem for the direct I/O write fallback") takes i_rwsem around blkdev_buffered_write() in the direct write fallback to close a race with set_blocksize(). Commit 1b1be9ea4e34 ("block: take the inode lock for buffered write fallback") fixes the same race by taking i_rwsem inside blkdev_buffered_write() instead. With both commits applied, the fallback path takes i_rwsem recursively:
blkdev_write_iter()
inode_lock_shared(bd_inode)
blkdev_buffered_write()
inode_lock_shared(inode)
syzbot reports this as:
WARNING: possible recursive locking detected
syz.0.40/6005 is trying to acquire lock:
ffff888024956f68 (&sb->s_type->i_mutex_key#10){++++}-{4:4}, at: blkdev_buffered_write+0xd7/0x160 block/fops.c:738 but task is already holding lock:
ffff888024956f68 (&sb->s_type->i_mutex_key#10){++++}-{4:4}, at: blkdev_write_iter+0x6c5/0x810 block/fops.c:815
rw_semaphore read locks are not recursive: once a writer is queued, new readers block behind it. If set_blocksize() calls inode_lock() between the two acquisitions, it waits for the first read lock to be released, while the second inode_lock_shared() waits behind set_blocksize(), and the task deadlocks.
Drop the outer locking in the fallback.
--- block/fops.c | 2 -- 1 file changed, 2 deletions(-)
block/fops.c +0 -2
@@ -845,9 +845,7 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from) }else {ssize_t ret2; -inode_lock_shared (bd_inode); ret2 =blkdev_buffered_write (iocb, from); -inode_unlock_shared (bd_inode); ret =direct_write_fallback (iocb, from, ret, ret2); need_sync = true;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1999/2151 x86_energy_perf_policy: Fix optarg keyword matching
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Len Brown <[email protected]>
[ Upstream commit 0177067d195a4757149f6702af191987377c71c3 ]
Replace strncmp() with strcmp() for exact string matching in parse_optarg_string(). Exact keyword matching is safer and clearer. This prevents accidental matches with longer strings
like "performance-foo".
--- .../x86_energy_perf_policy/x86_energy_perf_policy.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c +6 -6
@@ -312,22 +312,22 @@ int parse_optarg_string(char *s)int i;char *endptr; -if (!strncmp (s,"default" ,7 )) +if (strcmp (s,"default" ) ==0 )return OPTARG_NORMAL ; -if (!strncmp (s,"normal" ,6 )) +if (strcmp (s,"normal" ) ==0 )return OPTARG_NORMAL ; -if (!strncmp (s,"power" ,9 )) +if (strcmp (s,"power" ) ==0 )return OPTARG_POWER ; -if (!strncmp (s,"balance-power" ,17 )) +if (strcmp (s,"balance-power" ) ==0 )return OPTARG_BALANCE_POWER ; -if (!strncmp (s,"balance-performance" ,19 )) +if (strcmp (s,"balance-performance" ) ==0 )return OPTARG_BALANCE_PERFORMANCE ; -if (!strncmp (s,"performance" ,11 )) +if (strcmp (s,"performance" ) ==0 )return OPTARG_PERFORMANCE ; i =strtol (s, &endptr,0 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2000/2151 x86_energy_perf_policy: Cleanup: Check fseek() in VM path
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Len Brown <[email protected]>
[ Upstream commit 2778dc35d40e7e84c134ca4cab1376fa58208f80 ]
Add return value validation for fseek() and ensure consistent resource cleanup on all error paths in err_on_hypervisor().
--- .../x86/x86_energy_perf_policy/x86_energy_perf_policy.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
tools/power/x86/x86_energy_perf_policy/x86_energy_perf_policy.c +5 -1
@@ -661,7 +661,11 @@ void err_on_hypervisor(void) flags =strstr (buffer,"flags" );rewind (cpuinfo); -fseek (cpuinfo, flags - buffer,SEEK_SET ); +if (fseek (cpuinfo, flags - buffer,SEEK_SET ) !=0 ) { +fclose (cpuinfo); +free (buffer); +err (1 ,"Failed to seek in /proc/cpuinfo" ); + }if (!fgets (buffer,4096 , cpuinfo)) {fclose (cpuinfo);free (buffer);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2001/2151 perf mmap: Use the head selected by read_init
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paul Moses <[email protected]>
[ Upstream commit 022c64992af554cfd8c564bff86100fb5ed98678 ]
perf_mmap__push() reads the producer head before calling perf_mmap__read_init(), which reads it again to select the range to copy.
If the producer advances between those reads, push() copies through the newer head but stores the earlier head in prev. The next drain starts at that earlier position and can write the same records to perf.data again.
Use the head selected by read_init(): end for forward buffers and start for overwrite buffers. Save it before the copy loop advances start so prev matches the range that was copied.
--- tools/perf/util/mmap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/mmap.c +2 -1
@@ -328,7 +328,7 @@ int mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, struct perf_cpuint perf_mmap__push (struct mmap *md,void *to,int push (struct mmap *map,void *to,void *buf,size_t size)) { -u64 head =perf_mmap__read_head (&md->core); +u64 head;unsigned char *data = md->core.base + page_size;unsigned long size;void *buf;
@@ -338,6 +338,7 @@ int perf_mmap__push(struct mmap *md, void *to,if (rc <0 )return (rc == -EAGAIN ) ?1 :-1 ; + head = md->core.overwrite ? md->core.start : md->core.end; size = md->core.end - md->core.start;if ((md->core.start & md->core.mask) + size != (md->core.end & md->core.mask)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2002/2151 perf mmap: Preserve the consumed cursor in forward mode
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paul Moses <[email protected]>
[ Upstream commit 1e826983ceef421d7047ed76581840b778294ad4 ]
perf_mmap__read_event() updates prev as it consumes forward-buffer records. perf_mmap__read_done() then overwrites prev with a fresh producer head, even when unread records remain.
perf_kvm__mmap_read_idx() stops after 25 records per mmap and calls read_done(). If more records are pending, prev advances past them. The next drain starts at that new position and skips the unread remainder.
An event arriving after the last empty read_event() and before read_done() can also be skipped. read_done() does not itself update the kernel's data_tail.
Only refresh prev for overwrite buffers, which need the current head as the end of the next backward read. Leave the forward cursor at the consumed position.
--- tools/lib/perf/mmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/perf/mmap.c +1 -1
@@ -200,7 +200,7 @@ void perf_mmap__read_done(struct perf_mmap *map)/* * Check if event was unmapped due to a POLLHUP/POLLERR. */ -if (!refcount_read (&map->refcnt)) +if (!refcount_read (&map->refcnt) || !map->overwrite)return ; map->prev =perf_mmap__read_head (map);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2003/2151 perf print_insn: Include sys/types.h for ssize_t
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Fainelli <[email protected]>
[ Upstream commit e0e4470aa53c0022418290fb551c21da4bd50209 ]
print_insn.h declares fprintf_insn_asm() with an ssize_t return type but does not include the header defining that type. This causes builds where stdio.h does not provide ssize_t to fail when compiling util/print_insn.c:
util/print_insn.h:21:1: error: unknown type name 'ssize_t'
Include sys/types.h so the header provides its own dependency for ssize_t.
--- tools/perf/util/print_insn.h | 1 + 1 file changed, 1 insertion(+)
tools/perf/util/print_insn.h +1 -0
@@ -4,6 +4,7 @@#include <stddef.h> #include <stdio.h> +#include <sys/types.h> struct perf_sample ;struct thread ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2004/2151 perf parse-events: Include errno.h before kernel headers
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Fainelli <[email protected]>
[ Upstream commit 022b0ac5d3e87f87cb7ba42d04d0bc3ddfdd6be4 ]
Building perf against uClibc fails in config_term_common():
util/parse-events.c:954:30: error: 'ERANGE' undeclared
The kernel headers included before errno.h pull in asm/errno.h. uClibc's bits/errno.h undefines EDOM, EILSEQ and ERANGE before including linux/errno.h, but the kernel header include guards prevent these macros from being defined again.
Include errno.h before the kernel headers so ERANGE remains defined.
--- tools/perf/util/parse-events.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/parse-events.c +1 -1
@@ -1,10 +1,10 @@// SPDX-License-Identifier: GPL-2.0 +#include <errno.h> #include <linux/hw_breakpoint.h> #include <linux/err.h> #include <linux/list_sort.h> #include <linux/zalloc.h> #include <dirent.h> -#include <errno.h> #include <sys/ioctl.h> #include <sys/param.h> #include "cpumap.h"
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2005/2151 drm/amdgpu: re-enable GFXOFF for compute on GFX12
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Harkirat Gill <[email protected]>
[ Upstream commit 6a1dbb006056ad1ce6df0d6d5f2155767c20f410 ]
Commit 2affe2bbc997 ("drm/amdgpu: disable gfxoff with the compute workload on gfx12") disabled GFXOFF whenever a user-mode compute queue exists, as a workaround for an OpenCL test failure. The MES firmware issue behind that failure has since been addressed, so the workaround is no longer required.
Without this change, idle inference servers that hold a context for hours never let the graphics block power down, costing roughly 3-4% reported GPU activity and ~3 W per GPU at idle.
Measured on gfx1200 with an idle HIP process holding one stream and two resident KFD queues:
before: VDDGFX 695 mV, GPU load 2%, ~9-10 W
after: VDDGFX 35 mV, GPU load 0%, ~8 W (idle baseline)
The resident queue count is unchanged in both cases; only GFXOFF availability differs. The ocltst runtime suite (40 tests) passes with and without this change.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +2 -3
@@ -719,9 +719,8 @@ int amdgpu_amdkfd_submit_ib(struct amdgpu_device *adev,void amdgpu_amdkfd_set_compute_idle (struct amdgpu_device *adev,bool idle) {enum amd_powergating_state state = idle ?AMD_PG_STATE_GATE :AMD_PG_STATE_UNGATE ; -if ((IP_VERSION_MAJ (amdgpu_ip_version (adev,GC_HWIP ,0 )) ==11 && - ((adev->mes.kiq_version &AMDGPU_MES_VERSION_MASK ) <=64 )) || - (IP_VERSION_MAJ (amdgpu_ip_version (adev,GC_HWIP ,0 )) ==12 )) { +if (IP_VERSION_MAJ (amdgpu_ip_version (adev,GC_HWIP ,0 )) ==11 && + ((adev->mes.kiq_version &AMDGPU_MES_VERSION_MASK ) <=64 )) {pr_debug ("GFXOFF is %s\n" , idle ?"enabled" :"disabled" );amdgpu_gfx_off_ctrl (adev, idle); } else if ((IP_VERSION_MAJ(amdgpu_ip_version(adev, GC_HWIP, 0)) == 9) &&
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2006/2151 net: lan966x: fix the DB dataptr of frames from ndo_xdp_xmit
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Machon <[email protected]>
[ Upstream commit ce3192e0dafa829e76edefecc16a32589b53c875 ]
lan966x_fdma_xmit_xdpf() transmits both XDP_TX frames and xdp_frames from ndo_xdp_xmit, and builds the DB with lan966x_fdma_xdp_tx_dataptr_cb(), which adds XDP_PACKET_HEADROOM to the stored DMA address.
Before this patch, the headroom is also added for xdp_frames. For XDP_TX the stored address is the start of the page pool page, but for an xdp_frame it is the mapping of the IFH placed in front of the frame data, so frames from ndo_xdp_xmit are read from XDP_PACKET_HEADROOM bytes after their IFH.
Use the plain tx dataptr callback for xdp_frames.
Found by an AI code review agent. Reproduced on a lan9668 board with an XDP program redirecting frames from one port to another: none of the 20 frames arrived intact on the link partner. With the fix all 20 did.
--- drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +2 -1
@@ -686,7 +686,8 @@ int lan966x_fdma_xmit_xdpf(struct lan966x_port *port, void *ptr, u32 len)FDMA_DCB_STATUS_BLOCKO (0 ) |FDMA_DCB_STATUS_BLOCKL (next_dcb_buf->len), &fdma_nextptr_cb, - &lan966x_fdma_xdp_tx_dataptr_cb); + len ? &lan966x_fdma_xdp_tx_dataptr_cb : + &lan966x_fdma_tx_dataptr_cb);/* Start the transmission */ lan966x_fdma_tx_start (tx);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2007/2151 net: lan966x: release the in-flight slot of a stale TX skb
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Machon <[email protected]>
[ Upstream commit 074caa30a62726c0ee959e8b8ccb64cda0b26ae5 ]
lan966x_ptp_txtstamp_request() counts every two step TX skb waiting for its timestamp in lan966x->ptp_skbs, and refuses new ones once LAN966X_MAX_PTP_ID are in flight. lan966x_ptp_txtstamp_old_release() frees the skbs that have waited longer than LAN966X_PTP_TIMEOUT.
Before this patch, old_release() does not decrement ptp_skbs, so every skb whose timestamp never arrives, for example because the switch discarded the frame, keeps its slot forever. Once LAN966X_MAX_PTP_ID slots are lost, two step frames fail to transmit on every port of the switch.
Return the number of released skbs from old_release() and subtract it from ptp_skbs in txtstamp_request(), under the ptp_ts_id_lock it already takes.
This fixes the accounting only. A port's stale skbs are still aged out only when that port sends a two step frame, so a port that stops sending them keeps its stale skbs, and their slots, until it sends one again. That behaviour is unchanged by this patch.
Found by an AI code review agent. Reproduced on a lan9668 board.
--- drivers/net/ethernet/microchip/lan966x/lan966x_ptp.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/net/ethernet/microchip/lan966x/lan966x_ptp.c +8 -2
@@ -376,9 +376,10 @@ static void lan966x_ptp_classify(struct lan966x_port *port, struct sk_buff *skb, *rew_op =IFH_REW_OP_TWO_STEP_PTP ; } -static void lan966x_ptp_txtstamp_old_release (struct lan966x_port *port) +static unsigned int lan966x_ptp_txtstamp_old_release (struct lan966x_port *port) {struct sk_buff *skb, *skb_tmp; +unsigned int purged =0 ;unsigned long flags;spin_lock_irqsave (&port->tx_skbs.lock, flags);
@@ -389,14 +390,18 @@ static void lan966x_ptp_txtstamp_old_release(struct lan966x_port *port)__skb_unlink (skb, &port->tx_skbs);dev_kfree_skb_any (skb); + purged++; }spin_unlock_irqrestore (&port->tx_skbs.lock, flags); + +return purged; }int lan966x_ptp_txtstamp_request (struct lan966x_port *port,struct sk_buff *skb) {struct lan966x *lan966x = port->lan966x; +unsigned int purged;unsigned long flags;u8 pdu_type;u8 rew_op;
@@ -408,9 +413,10 @@ int lan966x_ptp_txtstamp_request(struct lan966x_port *port,if (rew_op !=IFH_REW_OP_TWO_STEP_PTP )return 0 ; -lan966x_ptp_txtstamp_old_release (port); + purged =lan966x_ptp_txtstamp_old_release (port);spin_lock_irqsave (&lan966x->ptp_ts_id_lock, flags); + lan966x->ptp_skbs -= purged;if (lan966x->ptp_skbs ==LAN966X_MAX_PTP_ID ) {spin_unlock_irqrestore (&lan966x->ptp_ts_id_lock, flags);return -EBUSY ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2008/2151 net: microchip: fdma: use little-endian types for descriptor fields
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Machon <[email protected]>
[ Upstream commit 9786c387b299bda5277eed98284a6f6fa7331fb9 ]
The FDMA engine reads and writes the DCB and DB descriptors in little-endian byte order. So far the descriptors have only been produced by the little-endian SoC itself, so plain u64 fields were fine. With the PCIe FDMA path, the descriptors live in host memory and are written by the host CPU, which may be big-endian.
Change the descriptor fields to __le64 and convert at the library
boundary: in __fdma_db_add() and __fdma_dcb_add() on write, and in the fdma_db_*() accessors on read. The dataptr and nextptr callbacks keep their u64 signatures, so their implementations are unchanged. Add fdma_db_dataptr_get(), and convert the lan966x sites that read the descriptor fields directly to use the accessors.
No functional change on little-endian hosts.
Stable-dep-of: 573a6d4c7a21 ("net: microchip: fdma: fix DCB corruption under sustained load")
--- .../net/ethernet/microchip/fdma/fdma_api.c | 21 ++++++++++++++----- .../net/ethernet/microchip/fdma/fdma_api.h | 20 +++++++++++------- .../ethernet/microchip/lan966x/lan966x_fdma.c | 9 ++++---- 3 files changed, 34 insertions(+), 16 deletions(-)
drivers/net/ethernet/microchip/fdma/fdma_api.c +16 -5
@@ -12,10 +12,18 @@ static int __fdma_db_add(struct fdma *fdma, int dcb_idx, int db_idx, u64 status, int db_idx, u64 *dataptr)) { struct fdma_db *db = fdma_db_get(fdma, dcb_idx, db_idx); +u64 dataptr; +int err; - db->status = status; + db->status =cpu_to_le64 (status); -return cb (fdma, dcb_idx, db_idx, &db->dataptr); + err =cb (fdma, dcb_idx, db_idx, &dataptr); +if (unlikely (err)) +return err; + + db->dataptr =cpu_to_le64 (dataptr); + +return 0 ; }/* Add a DB to a DCB, using the callback set in the fdma_ops struct. */
@@ -35,6 +43,7 @@ int __fdma_dcb_add(struct fdma *fdma, int dcb_idx, u64 info, u64 status, u64 *dataptr)) {struct fdma_dcb *dcb =fdma_dcb_get (fdma, dcb_idx); +u64 nextptr;int i, err;for (i =0 ; i < fdma->n_dbs; i++) {
@@ -43,14 +52,16 @@ int __fdma_dcb_add(struct fdma *fdma, int dcb_idx, u64 info, u64 status,return err; } - err =dcb_cb (fdma, dcb_idx, &fdma->last_dcb->nextptr); + err =dcb_cb (fdma, dcb_idx, &nextptr);if (unlikely (err))return err; + fdma->last_dcb->nextptr =cpu_to_le64 (nextptr); + fdma->last_dcb = dcb; - dcb->nextptr =FDMA_DCB_INVALID_DATA ; - dcb->info = info; + dcb->nextptr =cpu_to_le64 (FDMA_DCB_INVALID_DATA ); + dcb->info =cpu_to_le64 (info);return 0 ; }
drivers/net/ethernet/microchip/fdma/fdma_api.h +13 -7
@@ -64,13 +64,13 @@struct fdma ;struct fdma_db { -u64 dataptr; -u64 status; +__le64 dataptr; +__le64 status; };struct fdma_dcb { -u64 nextptr; -u64 info; +__le64 nextptr; +__le64 info;struct fdma_db db[FDMA_DB_MAX ]; };
@@ -140,19 +140,25 @@ static inline bool fdma_dcb_is_reusable(struct fdma *fdma)/* Check if the FDMA has marked this DB as done. */ static inline bool fdma_db_is_done (struct fdma_db *db) { -return db->status &FDMA_DCB_STATUS_DONE ; +return le64_to_cpu (db->status) &FDMA_DCB_STATUS_DONE ; }/* Get the length of a DB. */ static inline int fdma_db_len_get (struct fdma_db *db) { -return FDMA_DCB_STATUS_BLOCKL (db->status); +return FDMA_DCB_STATUS_BLOCKL (le64_to_cpu (db->status)); +} + +/* Get the dataptr of a DB. */ +static inline u64 fdma_db_dataptr_get (struct fdma_db *db) +{ +return le64_to_cpu (db->dataptr); }/* Set the length of a DB. */ static inline void fdma_dcb_len_set (struct fdma_dcb *dcb,u32 len) { - dcb->info =FDMA_DCB_INFO_DATAL (len); + dcb->info =cpu_to_le64 (FDMA_DCB_INFO_DATAL (len)); }/* Get a DB by index. */
drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +5 -4
@@ -406,8 +406,9 @@ static int lan966x_fdma_rx_check_frame(struct lan966x_rx *rx, u64 *src_port)return FDMA_ERROR ;dma_sync_single_for_cpu (lan966x->dev, - (dma_addr_t )db->dataptr +XDP_PACKET_HEADROOM , -FDMA_DCB_STATUS_BLOCKL (db->status), + (dma_addr_t )fdma_db_dataptr_get (db) + +XDP_PACKET_HEADROOM , +fdma_db_len_get (db),DMA_FROM_DEVICE ); lan966x_ifh_get_src_port(page_address(page) + XDP_PACKET_HEADROOM,
@@ -419,7 +420,7 @@ static int lan966x_fdma_rx_check_frame(struct lan966x_rx *rx, u64 *src_port)if (!lan966x_xdp_port_present (port))return FDMA_PASS ; -return lan966x_xdp_run (port, page,FDMA_DCB_STATUS_BLOCKL (db->status)); +return lan966x_xdp_run (port, page,fdma_db_len_get (db)); } static struct sk_buff *lan966x_fdma_rx_get_frame(struct lan966x_rx *rx,
@@ -443,7 +444,7 @@ static struct sk_buff *lan966x_fdma_rx_get_frame(struct lan966x_rx *rx,skb_mark_for_recycle (skb);skb_reserve (skb,XDP_PACKET_HEADROOM ); -skb_put (skb,FDMA_DCB_STATUS_BLOCKL (db->status)); +skb_put (skb,fdma_db_len_get (db));lan966x_ifh_get_timestamp (skb->data, ×tamp);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2009/2151 net: microchip: fdma: fix DCB corruption under sustained load
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Machon <[email protected]>
[ Upstream commit 573a6d4c7a21e34d7a2174b8d3c7ca67a5e850b6 ]
__fdma_dcb_add() prepares a DCB and links it into a channel's chain by writing its address to the NEXT_PTR of the current last DCB. The FDMA may be processing the chain while this happens.
Before this patch, the link is written before the new DCB's own nextptr and info fields, so the FDMA can follow it to a DCB that hasn't been fully prepared yet. Under sustained load this stalls the FDMA.
Prepare the new DCB fully before linking it, and update the previous DCB's NEXT_PTR using the two-step sequence from the datasheet (poison the LSB and flush, then clear it) so the FDMA never observes a partially-updated pointer.
Reported by a customer running iperf3 --bidir against a lan969x board.
Reproduced on lan969x with iperf3, throughput collapsing to zero:
[ 5] 1.00-2.00 sec 73.9 MBytes 620 Mbits/sec 0 305 KBytes [ 5] 2.00-3.00 sec 73.9 MBytes 620 Mbits/sec 0 305 KBytes [ 5] 3.00-4.00 sec 13.9 MBytes 116 Mbits/sec 2 1.41 KBytes [ 5] 4.00-5.00 sec 0.00 Bytes 0.00 bits/sec 1 1.41 KBytes [ 5] 5.00-6.00 sec 0.00 Bytes 0.00 bits/sec 0 1.41 KBytes [ 5] 6.00-7.00 sec 0.00 Bytes 0.00 bits/sec 1 1.41 KBytes
The race is timing-dependent: across three reproductions the stall appeared anywhere from ~400s to ~3000s into the run.
--- .../net/ethernet/microchip/fdma/fdma_api.c | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-)
drivers/net/ethernet/microchip/fdma/fdma_api.c +26 -4
@@ -43,9 +43,19 @@ int __fdma_dcb_add(struct fdma *fdma, int dcb_idx, u64 info, u64 status, u64 *dataptr)) {struct fdma_dcb *dcb =fdma_dcb_get (fdma, dcb_idx); +struct fdma_dcb *prev = fdma->last_dcb;u64 nextptr;int i, err; +/* Per the FDMA datasheet, adding a DCB to an active channel takes +* three steps: +* 1) Write NEXT_PTR of the current last DCB with the LSB forced to +* FDMA_DCB_INVALID_DATA, and flush that write. +* 2) Clear the LSB to complete the link. +* 3) Reload the channel (FDMA_CH_RELOAD); this is done by the caller +* once the chain has been extended. +*/ +for (i =0 ; i < fdma->n_dbs; i++) { err =__fdma_db_add (fdma, dcb_idx, i, status, db_cb);if (unlikely (err))
@@ -56,13 +66,25 @@ int __fdma_dcb_add(struct fdma *fdma, int dcb_idx, u64 info, u64 status,if (unlikely (err))return err; - fdma->last_dcb->nextptr =cpu_to_le64 (nextptr); - - fdma->last_dcb = dcb; - dcb->nextptr =cpu_to_le64 (FDMA_DCB_INVALID_DATA ); dcb->info =cpu_to_le64 (info); +/* On the first DCB of fdma_dcbs_init() prev is the DCB itself; +* don't link it to itself. +*/ +if (prev != dcb) { +/* Write NEXT_PTR of the current last DCB with the LSB forced +* to FDMA_DCB_INVALID_DATA, and flush that write. +*/ + prev->nextptr =cpu_to_le64 (nextptr |FDMA_DCB_INVALID_DATA ); +dma_wmb (); + +/* Clear the LSB to complete the link. */ + prev->nextptr =cpu_to_le64 (nextptr); + } + + fdma->last_dcb = dcb; +return 0 ; }EXPORT_SYMBOL_GPL (__fdma_dcb_add);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2010/2151 devlink: region: fix snapshot id leak on kernel-allocated ids
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fernando Fernandez Mancera <[email protected]>
[ Upstream commit ef8f0a1d888e0280452792f6d4edad237c934a51 ]
When DEVLINK_CMD_REGION_NEW is issued without a snapshot id, the kernel allocates one with __devlink_region_snapshot_id_get(). That helper counts the caller as a user of the id, and the caller must release this hold once it is done.
devlink_nl_region_new_doit() never drops it. The refcount of the id goes 1 (allocation) -> 2 (snapshot created) and stays at 2. When the snapshot is deleted the count only drops to 1, so the id is never erased from the snapshot_ids xarray. The id then stays in use for the lifetime of the devlink instance: requesting a snapshot with that explicit id fails with -EEXIST, and there is no snapshot left to delete to clean it up.
Reproducer steps:
# devlink region new pci/0000:13:00.0/device-caps pci/0000:13:00.0/device-caps: snapshot 0 # devlink region del pci/0000:13:00.0/device-caps snapshot 0 # devlink region new pci/0000:13:00.0/device-caps snapshot 0 kernel answers: File exists
Drop the caller's reference right after the snapshot has been created, as the snapshot then holds its own.
--- net/devlink/region.c | 5 +++++ 1 file changed, 5 insertions(+)
net/devlink/region.c +5 -0
@@ -719,6 +719,11 @@ int devlink_nl_region_new_doit(struct sk_buff *skb, struct genl_info *info)if (!snapshot_id_attr) {struct sk_buff *msg; +/* Drop the allocation reference, the snapshot +* now holds its own. +*/ +__devlink_snapshot_id_decrement (devlink, snapshot_id); + snapshot =devlink_region_snapshot_get_by_id (region, snapshot_id);if (WARN_ON (!snapshot)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2011/2151 tcp: Fix fastreuse cache initialization on first bind
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhewei Yuan <[email protected]>
[ Upstream commit 947ccedf683ed6cc53c1f88ac9eb8747e4567ed6 ]
inet_csk_update_fastreuse() initializes the reuse caches only when tb->bhash2 is empty, but both inet_csk_get_port() and __inet_inherit_port() link tb2 before calling it, so the first-bind branch is never taken.
As a result, SO_REUSEADDR binds never get fastreuse=1 and keep scanning existing owners, and SO_REUSEPORT starts in STRICT instead of ANY.
Initialize the caches when tb2 is the only entry in tb->bhash2 and has no owners. Timewait sockets are also linked on tb2->owners, so this is equivalent to the old hlist_empty(&tb->owners) test.
Found by manual code inspection and confirmed with GDB. Binding 16000 SO_REUSEADDR sockets to one address/port in a KVM guest takes 4.18 s before and 19.4 ms after this patch. Existing bind/reuse selftests pass. Analysis and testing were assisted by an AI tool (Codex).
--- net/ipv4/inet_connection_sock.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/ipv4/inet_connection_sock.c +2 -1
@@ -447,7 +447,8 @@ void inet_csk_update_fastreuse(const struct sock *sk, {bool reuse = sk->sk_reuse && sk->sk_state !=TCP_LISTEN ; -if (hlist_empty (&tb->bhash2)) { +if (hlist_is_singular_node (&tb2->bhash_node, &tb->bhash2) && +hlist_empty (&tb2->owners)) { tb->fastreuse = reuse;if (sk->sk_reuseport) { tb->fastreuseport =FASTREUSEPORT_ANY ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2012/2151 net: lan966x: dont disable hardirqs in fdma tx clear path
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Machon <[email protected]>
[ Upstream commit b2e17432e7ee75997657f99862eb83be0c78a6c1 ]
lan966x_fdma_tx_clear_buf() runs from the NAPI poll and frees the buffers of completed tx DCBs with napi_consume_skb(), page_pool_recycle_direct() and xdp_return_frame_bulk(), under lan966x->tx_lock.
Before this patch, the lock is taken with spin_lock_irqsave(), so the buffers are freed with hardirqs disabled. RX skbs are marked for page_pool recycling, so when such an skb is forwarded back out and its tx completion frees it here, the free path reaches __page_pool_put_page(), which warns via lockdep_assert_no_hardirq().
Take tx_lock with a plain spin_lock(), as the other tx_lock users, lan966x_port_xmit() and lan966x_fdma_xmit_xdpf(), already do. tx_clear_buf() runs from the NAPI poll, so disabling hardirqs there is not needed.
Found with lockdep enabled (CONFIG_PROVE_LOCKING), which the assert depends on. Reproduced on a lan9668 board by redirecting received frames out of another port with tc mirred.
--- drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +2 -3
@@ -337,14 +337,13 @@ static void lan966x_fdma_tx_clear_buf(struct lan966x *lan966x, int weight)struct lan966x_tx_dcb_buf *dcb_buf;struct fdma *fdma = &tx->fdma;struct xdp_frame_bulk bq; -unsigned long flags;bool clear = false;struct fdma_db *db;int i;xdp_frame_bulk_init (&bq); -spin_lock_irqsave (&lan966x->tx_lock, flags); +spin_lock (&lan966x->tx_lock);for (i =0 ; i < fdma->n_dcbs; ++i) { dcb_buf = &tx->dcbs_buf[i];
@@ -389,7 +388,7 @@ static void lan966x_fdma_tx_clear_buf(struct lan966x *lan966x, int weight)if (clear)lan966x_fdma_wakeup_netdev (lan966x); -spin_unlock_irqrestore (&lan966x->tx_lock, flags); +spin_unlock (&lan966x->tx_lock); }static int lan966x_fdma_rx_check_frame (struct lan966x_rx *rx,u64 *src_port)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2013/2151 net: dsa: mv88e6xxx: fix 6351 family statistics snapshot
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Fainelli <[email protected]>
[ Upstream commit 9663edfa71e8807890203578dab6db60c6b548c4 ]
The 88E6171, 88E6175, 88E6350 and 88E6351 take the port number in the low bits of the statistics operation register. The 6320 snapshot helper instead encodes the port as (port + 1) << 5. On an EA4500 with an 88E6171, this causes ethtool -S to return physical port 0's MIB counters for every user port. Traffic on other ports does not update their reported hardware counters.
Before the snapshot operation was moved into the chip operations, only the 6320 and 6352 families used the shifted encoding. The refactoring incorrectly assigned that encoding to all four 6351 family chips.
Use the unshifted snapshot helper for the entire 6351 family. This matches the Marvell DSDT statsCapture() implementation, which uses the raw port number for chips outside DEV_RMON_PORT_BITS, including these four chips.
The original 88E6171 change was tested on an EA4500: pings through different switch ports updated only the corresponding port's hardware counters. The other three chips have not been hardware tested.
--- drivers/net/dsa/mv88e6xxx/chip.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/dsa/mv88e6xxx/chip.c +4 -4
@@ -4580,7 +4580,7 @@ static const struct mv88e6xxx_ops mv88e6171_ops = { .port_disable_pri_override = mv88e6xxx_port_disable_pri_override, .port_get_cmode = mv88e6352_port_get_cmode, .port_setup_message_port = mv88e6xxx_setup_message_port, - .stats_snapshot = mv88e6320_g1_stats_snapshot, + .stats_snapshot = mv88e6xxx_g1_stats_snapshot, .stats_set_histogram = mv88e6095_g1_stats_set_histogram, .stats_get_sset_count = mv88e6095_stats_get_sset_count, .stats_get_strings = mv88e6095_stats_get_strings,
@@ -4683,7 +4683,7 @@ static const struct mv88e6xxx_ops mv88e6175_ops = { .port_disable_pri_override = mv88e6xxx_port_disable_pri_override, .port_get_cmode = mv88e6352_port_get_cmode, .port_setup_message_port = mv88e6xxx_setup_message_port, - .stats_snapshot = mv88e6320_g1_stats_snapshot, + .stats_snapshot = mv88e6xxx_g1_stats_snapshot, .stats_set_histogram = mv88e6095_g1_stats_set_histogram, .stats_get_sset_count = mv88e6095_stats_get_sset_count, .stats_get_strings = mv88e6095_stats_get_strings,
@@ -5343,7 +5343,7 @@ static const struct mv88e6xxx_ops mv88e6350_ops = { .port_disable_pri_override = mv88e6xxx_port_disable_pri_override, .port_get_cmode = mv88e6352_port_get_cmode, .port_setup_message_port = mv88e6xxx_setup_message_port, - .stats_snapshot = mv88e6320_g1_stats_snapshot, + .stats_snapshot = mv88e6xxx_g1_stats_snapshot, .stats_set_histogram = mv88e6095_g1_stats_set_histogram, .stats_get_sset_count = mv88e6095_stats_get_sset_count, .stats_get_strings = mv88e6095_stats_get_strings,
@@ -5389,7 +5389,7 @@ static const struct mv88e6xxx_ops mv88e6351_ops = { .port_disable_pri_override = mv88e6xxx_port_disable_pri_override, .port_get_cmode = mv88e6352_port_get_cmode, .port_setup_message_port = mv88e6xxx_setup_message_port, - .stats_snapshot = mv88e6320_g1_stats_snapshot, + .stats_snapshot = mv88e6xxx_g1_stats_snapshot, .stats_set_histogram = mv88e6095_g1_stats_set_histogram, .stats_get_sset_count = mv88e6095_stats_get_sset_count, .stats_get_strings = mv88e6095_stats_get_strings,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2014/2151 net: dsa: mv88e6xxx: fix 88E6171 statistics type
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Fainelli <[email protected]>
[ Upstream commit df66431f39426b685f6693f0731cd5881c51679c ]
The 88E6171 uses the 6095 statistics operations, which advertise and name BANK0 and PORT counters. Its stats_type bitmap instead selects BANK0 and BANK1. Since statistics collection started using that bitmap, it has written a different set of counters from the one advertised to ethtool.
For this chip, get_sset_count() accounts for 30 BANK0 counters, three PORT counters and five ATU/VTU counters. Collection instead writes 30 BANK0 counters, 26 BANK1 counters and five ATU/VTU counters: 61 entries rather than the advertised 38. This mislabels the tail of the returned statistics and writes past the advertised statistics buffer.
Select BANK0 and PORT counters to match the chip's statistics operations and restore the filter used before the bitmap was introduced. Tested on an EA4500, where the two-bridge forwarding and multicast snooping tests now pass their hardware counter checks.
--- drivers/net/dsa/mv88e6xxx/chip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/dsa/mv88e6xxx/chip.c +1 -1
@@ -5922,7 +5922,7 @@ static const struct mv88e6xxx_info mv88e6xxx_table[] = { .age_time_coeff = 15000, .g1_irqs = 9, .g2_irqs = 10, - .stats_type = STATS_TYPE_BANK0 | STATS_TYPE_BANK1, + .stats_type = STATS_TYPE_BANK0 | STATS_TYPE_PORT, .atu_move_port_mask = 0xf, .pvt = true, .multi_chip = true,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2015/2151 usbnet: fix EVENT_RX_PAUSED race in usbnet_skb_return()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ömer Mete Kaya <[email protected]>
[ Upstream commit 67ae1b80cf73f592b35e4b5e5001a24d6d6c8637 ]
On SMP, usbnet_skb_return() can observe EVENT_RX_PAUSED as set on CPU0 while usbnet_resume_rx() clears the flag and drains rxq_pause on CPU1. The skb can then be queued after the drain has completed and remain stranded until the next MTU change or device stop.
Synchronize the EVENT_RX_PAUSED state transition and paused-queue dequeue operations with rxq_pause.lock. In usbnet_resume_rx() splice the paused queue into a local queue under the lock, then drain the local queue lock-free. In usbnet_skb_return() use a double-check pattern under rxq_pause.lock on the slow path, keeping the normal RX fast path lock-free. Use spin_lock_irqsave() to match the lockdep class shared with other sk_buff_head locks taken from hardirq context in defer_bh().
Discovered by Sashiko, not triggered, not tested on real hardware.
--- drivers/net/usb/usbnet.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
drivers/net/usb/usbnet.c +16 -4
@@ -332,9 +332,14 @@ void usbnet_skb_return (struct usbnet *dev, struct sk_buff *skb)unsigned long flags;int status; -if (test_bit (EVENT_RX_PAUSED , &dev->flags)) { -skb_queue_tail (&dev->rxq_pause, skb); -return ; +if (unlikely (test_bit (EVENT_RX_PAUSED , &dev->flags))) { +spin_lock_irqsave (&dev->rxq_pause.lock, flags); +if (test_bit (EVENT_RX_PAUSED , &dev->flags)) { +__skb_queue_tail (&dev->rxq_pause, skb); +spin_unlock_irqrestore (&dev->rxq_pause.lock, flags); +return ; + } +spin_unlock_irqrestore (&dev->rxq_pause.lock, flags); }/* only update if unset to allow minidriver rx_fixup override */
@@ -701,13 +706,20 @@ EXPORT_SYMBOL_GPL(usbnet_pause_rx);void usbnet_resume_rx (struct usbnet *dev) { +struct sk_buff_head q;struct sk_buff *skb; +unsigned long flags;int num =0 ; +__skb_queue_head_init (&q); +local_bh_disable (); +spin_lock_irqsave (&dev->rxq_pause.lock, flags);clear_bit (EVENT_RX_PAUSED , &dev->flags); +skb_queue_splice_init (&dev->rxq_pause, &q); +spin_unlock_irqrestore (&dev->rxq_pause.lock, flags); -while ((skb =skb_dequeue (&dev->rxq_pause)) !=NULL ) { +while ((skb =__skb_dequeue (&q))) {usbnet_skb_return (dev, skb); num++; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2016/2151 bpf: Fix out-of-bounds btf->types write for split BTF
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Feng Yang <[email protected]>
[ Upstream commit 6c476d2b73056ed151c3f8b884c627c75999ed7c ]
btf_add_type() stores the types of a BTF in btf->types[], which can hold at most BTF_MAX_TYPE entries. The types of a split BTF get IDs start_id .. start_id + nr_types - 1, so only BTF_MAX_TYPE - start_id of them fit, but neither the limit check nor the size used to grow the array accounts forstart_id: the check is an equality test against BTF_MAX_TYPE ('start_id + btf->types_size == BTF_MAX_TYPE') and the new size is clamped to BTF_MAX_TYPE.
The check therefore only fires if the array happens to grow to exactly BTF_MAX_TYPE - start_id entries. Otherwise, if the module has more than BTF_MAX_TYPE types, the array is filled up to BTF_MAX_TYPE entries. The next type that needs to be added reallocates the array to the same size, after which btf->types_size no longer equals btf->nr_types and the growth path is not taken anymore, so every following type is written past the end of the array:
BUG: unable to handle page fault for address: ffffc90006200000 RIP: 0010:btf_add_type+0x74/0x270 Call Trace: btf_check_all_metas btf_parse_module
Bound both the array size and the limit check by BTF_MAX_TYPE - start_id. Base BTF (start_id == 0) is unaffected.
--- kernel/bpf/btf.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
kernel/bpf/btf.c +4 -3
@@ -1619,15 +1619,16 @@ static int btf_add_type(struct btf_verifier_env *env, struct btf_type *t)/* Expand 'types' array */ struct btf_type **new_types; -u32 expand_by, new_size; +u32 expand_by, new_size, max_size; -if (btf->start_id + btf->types_size ==BTF_MAX_TYPE ) { +if (btf->start_id + btf->types_size >=BTF_MAX_TYPE ) {btf_verifier_log (env,"Exceeded max num of types" );return -E2BIG ; } + max_size =BTF_MAX_TYPE - btf->start_id; expand_by =max_t (u32, btf->types_size >>2 ,16 ); - new_size =min_t (u32,BTF_MAX_TYPE , + new_size =min_t (u32, max_size, btf->types_size + expand_by); new_types = kvcalloc(new_size, sizeof(*new_types),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2017/2151 net/mlx4: always create the eth and ib auxiliary devices
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Morrow <[email protected]>
[ Upstream commit 557d80138618b9d17407733d4ec25b33d3971d60 ]
Since commit 7d22b1cb9d84 ("mlx4: Connect the infiniband part to the auxiliary bus"), mlx4_core creates the "ib" auxiliary device only for an IB port or a device that advertises IBoE. Before it, each mlx4 interface was offered every device and decided in its own add callback. mlx4_ib_add() accepted Ethernet ports without IBoE and registered them for raw packet QPs only.
ConnectX-3 VFs on Azure have an Ethernet port and no IBoE, so since v6.6 they get no RDMA device. DPDK's mlx4 PMD, which needs only raw packet QPs, then cannot open them:
net_mlx4: cannot access device, is mlx4_ib loaded?
Restore the old behaviour by creating both auxiliary devices for every device and letting mlx4_en and mlx4_ib decide in probe, as their add callbacks did. mlx4_ib_probe() returns -ENODEV when there are no usable ports, and mlx4_en_probe() binds a device without Ethernet ports but creates no netdevs, as mlx4_en_add() did.
Tested on 6.12.111 on an Azure VM with two ConnectX-3 VFs: each gets an eth and an ib auxiliary device, and DPDK attaches both VFs and passes traffic through them.
--- drivers/net/ethernet/mellanox/mlx4/intf.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-)
drivers/net/ethernet/mellanox/mlx4/intf.c +2 -13
@@ -43,23 +43,12 @@ static DEFINE_IDA(mlx4_adev_ida);static bool is_eth_supported (struct mlx4_dev *dev) { -for (int port =1 ; port <= dev->caps.num_ports; port++) -if (dev->caps.port_type[port] ==MLX4_PORT_TYPE_ETH ) -return true; - -return false; +return true; }static bool is_ib_supported (struct mlx4_dev *dev) { -for (int port =1 ; port <= dev->caps.num_ports; port++) -if (dev->caps.port_type[port] ==MLX4_PORT_TYPE_IB ) -return true; - -if (dev->caps.flags &MLX4_DEV_CAP_FLAG_IBOE ) -return true; - -return false; +return true; } static const struct mlx4_adev_device {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2018/2151 nfp: flower: fix use-after-free in neighbour update work
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sicong Huang <[email protected]>
[ Upstream commit 083aaafd453c3fb14411519d6ada9a8917573fdb ]
The netevent notifier handles neighbour updates and redirects by queuing nfp_tun_neigh_update() on system_highpri_wq. Each work item holds a reference to the neighbour, but only stores a pointer to the flower app.
During device removal, nfp_tunnel_config_stop() unregisters the notifier. This waits for notifier callbacks to return, but does not wait for the work they queued. The teardown then frees app->priv and app without waiting for these work items. Flushing cmsg_work in nfp_flower_clean() does not cover the neighbour update work.
A pending work item can therefore run after the app has been freed. Its call to nfp_flower_get_port_id_from_netdev() can then access freed memory while checking whether the neighbour's device can be offloaded. Even notifications for unrelated devices can reach this check. The same problem affects shutdown and probe error paths that tear down the app after the netevent notifier has been registered.
One possible interleaving is shown below. The neighbour belongs to another network device that remains registered.
CPU0 (remove) CPU1 (notifier / kworker)
nfp_tun_neigh_event_handler()
queue_work(system_highpri_wq, ...)
return
/* Work has not run yet. */
nfp_tunnel_config_stop()
unregister_netevent_notifier()
/* Notifier callbacks have finished, but work may be pending. */
nfp_flower_clean()
vfree(app->priv)
app->priv = NULL
nfp_app_free()
kfree(app)
nfp_tun_neigh_update()
app = update_work->app
nfp_flower_get_port_id_from_netdev()
app->priv /* use-after-free */The work items are allocated per event and free themselves, so they cannot be cancelled individually, and flushing system_highpri_wq is not allowed. Use a dedicated workqueue for neighbour updates instead. In nfp_tunnel_config_stop(), unregister the notifier and destroy the workqueue before cleaning up the tunnel state. This prevents new work from being queued and waits for pending and running work to finish while the app and its resources are still valid.
Found by code inspection.
--- .../net/ethernet/netronome/nfp/flower/main.h | 2 ++ .../netronome/nfp/flower/tunnel_conf.c | 24 ++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-)
drivers/net/ethernet/netronome/nfp/flower/main.h +2 -0
@@ -94,6 +94,7 @@ struct nfp_fl_stats_id {* @ipv6_off_lock: Lock for the IPv6 address list * @mac_off_ids: IDA to manage id assignment for offloaded MACs * @neigh_nb: Notifier to monitor neighbour state +* @neigh_wq: Workqueue for neighbour updates */ struct nfp_fl_tunnel_offloads {struct rhashtable offloaded_macs;
@@ -103,6 +104,7 @@ struct nfp_fl_tunnel_offloads {struct mutex ipv6_off_lock;struct ida mac_off_ids;struct notifier_block neigh_nb; +struct workqueue_struct *neigh_wq; };/**
drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c +18 -6
@@ -742,7 +742,7 @@ nfp_tun_neigh_event_handler(struct notifier_block *nb, unsigned long event,if (!update_work)return NOTIFY_DONE ; -queue_work (system_highpri_wq, &update_work->work); +queue_work (app_priv->tun.neigh_wq, &update_work->work);return NOTIFY_DONE ; }
@@ -1516,6 +1516,13 @@ int nfp_tunnel_config_start(struct nfp_app *app)if (err)return err; + priv->tun.neigh_wq =alloc_workqueue ("nfp-flower-neigh" , +WQ_HIGHPRI |WQ_PERCPU ,0 ); +if (!priv->tun.neigh_wq) { + err = -ENOMEM ; + goto err_free_macs; + } +ida_init (&priv->tun.mac_off_ids);/* Initialise priv data for IPv4/v6 offloading. */
@@ -1528,13 +1535,17 @@ int nfp_tunnel_config_start(struct nfp_app *app) priv->tun.neigh_nb.notifier_call = nfp_tun_neigh_event_handler; err =register_netevent_notifier (&priv->tun.neigh_nb); -if (err) { -rhashtable_free_and_destroy (&priv->tun.offloaded_macs, - nfp_check_rhashtable_empty,NULL ); -return err; - } +if (err) + goto err_destroy_neigh_wq;return 0 ; + +err_destroy_neigh_wq: +destroy_workqueue (priv->tun.neigh_wq); +err_free_macs: +rhashtable_free_and_destroy (&priv->tun.offloaded_macs, + nfp_check_rhashtable_empty,NULL ); +return err; }void nfp_tunnel_config_stop (struct nfp_app *app)
@@ -1544,6 +1555,7 @@ void nfp_tunnel_config_stop(struct nfp_app *app)struct list_head *ptr, *storage;unregister_netevent_notifier (&priv->tun.neigh_nb); +destroy_workqueue (priv->tun.neigh_wq);ida_destroy (&priv->tun.mac_off_ids);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2019/2151 ASoC: xilinx: formatter_pcm: Fix read-modify-write of AUD_CTRL in hw_params
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit 3b54e739273752b370e49b09976da152fa3b802c ]
xlnx_formatter_pcm_hw_params() does a read-modify-write on XLNX_AUD_CTRL but only ORs in the new data width and active channel values without clearing the old ones. If hw_params is called more than once on an open stream, these fields may retain bits from the previous configuration, resulting in an incorrect sample width or channel count.
Clear both fields before writing the new values, and use FIELD_PREP() so the values cannot spill into neighbouring bits.
--- sound/soc/xilinx/xlnx_formatter_pcm.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
sound/soc/xilinx/xlnx_formatter_pcm.c +10 -8
@@ -6,6 +6,7 @@// // Author: Maruthi Srinivas Bayyavarapu <[email protected]> +#include <linux/bitfield.h> #include <linux/clk.h> #include <linux/io.h> #include <linux/module.h>
@@ -57,8 +58,8 @@#define CFG_S2MM_XFER_SHIFT 29#define CFG_S2MM_PKG_MASK BIT(28) -#define AUD_CTRL_DATA_WIDTH_SHIFT 16 -#define AUD_CTRL_ACTIVE_CH_SHIFT 19 +#define AUD_CTRL_DATA_WIDTH_MASK GENMASK(18, 16) +#define AUD_CTRL_ACTIVE_CH_MASK GENMASK(22, 19)#define PERIOD_CFG_PERIODS_SHIFT 16#define PERIODS_MIN 2
@@ -509,28 +510,29 @@ static int xlnx_formatter_pcm_hw_params(struct snd_soc_component *component,writel (high, stream_data->mmio +XLNX_AUD_BUFF_ADDR_MSB ); val =readl (stream_data->mmio +XLNX_AUD_CTRL ); + val &= ~(AUD_CTRL_DATA_WIDTH_MASK |AUD_CTRL_ACTIVE_CH_MASK ); bits_per_sample =params_width (params);switch (bits_per_sample) {case 8 : - val |= (BIT_DEPTH_8 <<AUD_CTRL_DATA_WIDTH_SHIFT ); + val |=FIELD_PREP (AUD_CTRL_DATA_WIDTH_MASK ,BIT_DEPTH_8 );break ;case 16 : - val |= (BIT_DEPTH_16 <<AUD_CTRL_DATA_WIDTH_SHIFT ); + val |=FIELD_PREP (AUD_CTRL_DATA_WIDTH_MASK ,BIT_DEPTH_16 );break ;case 20 : - val |= (BIT_DEPTH_20 <<AUD_CTRL_DATA_WIDTH_SHIFT ); + val |=FIELD_PREP (AUD_CTRL_DATA_WIDTH_MASK ,BIT_DEPTH_20 );break ;case 24 : - val |= (BIT_DEPTH_24 <<AUD_CTRL_DATA_WIDTH_SHIFT ); + val |=FIELD_PREP (AUD_CTRL_DATA_WIDTH_MASK ,BIT_DEPTH_24 );break ;case 32 : - val |= (BIT_DEPTH_32 <<AUD_CTRL_DATA_WIDTH_SHIFT ); + val |=FIELD_PREP (AUD_CTRL_DATA_WIDTH_MASK ,BIT_DEPTH_32 );break ;default :return -EINVAL ; } - val |= active_ch <<AUD_CTRL_ACTIVE_CH_SHIFT ; + val |=FIELD_PREP (AUD_CTRL_ACTIVE_CH_MASK , active_ch);writel (val, stream_data->mmio +XLNX_AUD_CTRL ); val = (params_periods (params) <<PERIOD_CFG_PERIODS_SHIFT )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2020/2151 nvmet: zns: reject a NUMD whose byte count wraps
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrea Parri <[email protected]>
[ Upstream commit 12740bec646dafe009a7d9a4d22d3495ef1ea5cd ]
Zone Management Receive computes its buffer size as (numd + 1) << 2 in u32, in nvmet_bdev_validate_zone_mgmt_recv(), nvmet_bdev_zone_zmgmt_recv_work() and nvmet_bdev_execute_zone_mgmt_recv(). NUMD is a 32-bit dword count, so any NUMD from 0x3fffffff up wraps.
The data length check in nvmet_bdev_execute_zone_mgmt_recv() sees the same wrapped value, so such a command can pass it. A data length that does not match the wrapped size is already rejected by that check, with Data SGL Length Invalid.
Every site agrees on the wrapped size, so the target zeroes and fills only that many bytes and nothing leaks, but it answers a command whose NUMD asks for 4 GiB or more.
Reject a NUMD from U32_MAX / 4 up with Invalid Field at the start of nvmet_bdev_execute_zone_mgmt_recv(), before this handler or its work item computes the byte count. A size_t computation would still wrap on 32-bit kernels, where nvmet_check_transfer_len() and req->transfer_len are 32 bits wide.
nvmet_io_cmd_transfer_len() in core.c, which the pci-epf transport uses to size its buffer, computes the same expression before this handler runs. Return 0 there for such a NUMD, so pci-epf allocates no buffer and the handler then rejects the command.
Tested over the loop, tcp, rdma and fc transports with a zoned null_blk namespace: a wrapping NUMD, sent with a data length that matches the wrapped size, was accepted before this patch and now fails with Invalid Field, while ordinary NUMD values still succeed. The core.c change only affects pci-epf and is build-tested only.
--- drivers/nvme/target/core.c | 3 +++ drivers/nvme/target/zns.c | 12 ++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-)
drivers/nvme/target/core.c +3 -0
@@ -1075,6 +1075,9 @@ static u32 nvmet_io_cmd_transfer_len(struct nvmet_req *req)case nvme_cmd_dsm:return nvmet_dsm_len (req);case nvme_cmd_zone_mgmt_recv: +/* The handler rejects a NUMD whose byte count would wrap. */ +if (le32_to_cpu (req->cmd->zmr.numd) >=U32_MAX /4 ) +return 0 ;return (le32_to_cpu (req->cmd->zmr.numd) +1 ) <<2 ;default :return 0 ;
drivers/nvme/target/zns.c +10 -2
@@ -319,9 +319,17 @@ static void nvmet_bdev_zone_zmgmt_recv_work(struct work_struct *w)void nvmet_bdev_execute_zone_mgmt_recv (struct nvmet_req *req) { -u32 out_bufsize = (le32_to_cpu (req->cmd->zmr.numd) +1 ) <<2 ; +u32 numd =le32_to_cpu (req->cmd->zmr.numd); + +/* From U32_MAX / 4 up, (numd + 1) << 2 wraps here and in the work. */ +if (numd >=U32_MAX /4 ) { + req->error_loc = offsetof(struct nvme_zone_mgmt_recv_cmd , numd); +nvmet_req_complete (req, +NVME_SC_INVALID_FIELD |NVME_STATUS_DNR ); +return ; + } -if (!nvmet_check_transfer_len (req, out_bufsize)) +if (!nvmet_check_transfer_len (req, (numd +1 ) <<2 ))return ;INIT_WORK (&req->z.zmgmt_work, nvmet_bdev_zone_zmgmt_recv_work);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2021/2151 nvmet: prevent double-free after metadata SGL allocation failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Avi Weiss <[email protected]>
[ Upstream commit 2f61b9d1d54edf75a352c43eebe3804144b5d44e ]
If metadata SGL allocation fails, nvmet_req_alloc_sgls() frees req->sg without clearing it. The RDMA error completion path later frees the same scatterlist again.
Use nvmet_req_free_sgls() instead so that the scatterlist pointers and counts are cleared before response cleanup.
--- drivers/nvme/target/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/target/core.c +1 -1
@@ -1338,7 +1338,7 @@ int nvmet_req_alloc_sgls(struct nvmet_req *req)return 0 ; out_free: -sgl_free (req->sg); +nvmet_req_free_sgls (req); out:return -ENOMEM ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2022/2151 nvmet: protect nvmet_ports_list with nvmet_config_sem
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qing Zhang <[email protected]>
[ Upstream commit cead6beb89256ae7145b65fbe8e8a5fedba4a47c ]
Readers of nvmet_ports_list (e.g. nvmet_subsys_disc_changed()) hold nvmet_config_sem and assert it via lockdep. The writers -- nvmet_ports_make() and nvmet_port_release() -- do not take the lock; they rely on the parent directory's VFS inode lock for serialization, which is an implementation detail of configfs and not a guaranteed contract. Align the writers with the lock the readers already require.
Also move list_add() in nvmet_ports_make() to after the port is fully
initialized: the old position published the port on the global list before INIT_LIST_HEAD(&port->subsystems), so a concurrent reader could traverse uninitialized list heads.
flush_workqueue() in nvmet_port_release() stays outside the semaphore to avoid a lock dependency on nvmet_wq.
--- drivers/nvme/target/configfs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/nvme/target/configfs.c +6 -2
@@ -1984,7 +1984,9 @@ static void nvmet_port_release(struct config_item *item)/* Let inflight controllers teardown complete */ flush_workqueue (nvmet_wq); +down_write (&nvmet_config_sem);list_del (&port->global_entry); +up_write (&nvmet_config_sem);key_put (port->keyring);kfree (port->ana_state);
@@ -2052,8 +2054,6 @@ static struct config_group *nvmet_ports_make(struct config_group *group, port->ana_state[i] =NVME_ANA_INACCESSIBLE ; } -list_add (&port->global_entry, &nvmet_ports_list); -INIT_LIST_HEAD (&port->entry);INIT_LIST_HEAD (&port->subsystems);INIT_LIST_HEAD (&port->referrals);
@@ -2086,6 +2086,10 @@ static struct config_group *nvmet_ports_make(struct config_group *group,configfs_add_default_group (&port->ana_default_group.group, &port->ana_groups_group); +down_write (&nvmet_config_sem); +list_add (&port->global_entry, &nvmet_ports_list); +up_write (&nvmet_config_sem); +return &port->group; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2023/2151 nvmet: use the enabled transport when disabling a port
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rongzheng Wang <[email protected]>
[ Upstream commit 60385038754ed9fb05dab127b35f88c702252505 ]
nvmet_disable_port() looks up the transport from the current disc_addr.trtype, while nvmet_enable_port() records the transport in port->tr_ops. If trtype is changed while a port is being enabled, the port can be removed through a different transport, passing the private data of the original transport to the wrong ->remove_port().
The same mismatch is reachable with loop and RDMA: loop add_port() leaves port->priv NULL, and RDMA remove_port() dereferences it.
Use port->tr_ops for removal and serialize trtype changes with nvmet_config_sem in nvmet_addr_trtype_store(), so the transport that added the port is also the one that removes it.
--- drivers/nvme/target/configfs.c | 16 ++++++++++++---- drivers/nvme/target/core.c | 8 +++++--- 2 files changed, 17 insertions(+), 7 deletions(-)
drivers/nvme/target/configfs.c +12 -4
@@ -360,10 +360,15 @@ static ssize_t nvmet_addr_trtype_store(struct config_item *item, const char *page, size_t count) {struct nvmet_port *port =to_nvmet_port (item); +ssize_t ret = count;int i; -if (nvmet_is_port_enabled (port, __func__)) -return -EACCES ; +down_write (&nvmet_config_sem); + +if (nvmet_is_port_enabled (port, __func__)) { + ret = -EACCES ; + goto out; + }for (i =0 ; i <ARRAY_SIZE (nvmet_transport); i++) {if (sysfs_streq (page, nvmet_transport[i].name))
@@ -371,7 +376,8 @@ static ssize_t nvmet_addr_trtype_store(struct config_item *item, }pr_err ("Invalid value '%s' for trtype\n" , page); -return -EINVAL ; + ret = -EINVAL ; + goto out; found:memset (&port->disc_addr.tsas,0 ,NVMF_TSAS_SIZE );
@@ -380,7 +386,9 @@ static ssize_t nvmet_addr_trtype_store(struct config_item *item,nvmet_port_init_tsas_rdma (port); else if (port->disc_addr.trtype == NVMF_TRTYPE_TCP) nvmet_port_init_tsas_tcp(port, NVMF_TCP_SECTYPE_NONE); -return count; +out: +up_write (&nvmet_config_sem); +return ret; }CONFIGFS_ATTR (nvmet_, addr_trtype);
drivers/nvme/target/core.c +5 -3
@@ -384,11 +384,13 @@ void nvmet_disable_port(struct nvmet_port *port)lockdep_assert_held (&nvmet_config_sem); - port->enabled = false; - port->tr_ops =NULL ; +if (!port->enabled) +return ; - ops = nvmet_transports[port->disc_addr.trtype]; + ops = port->tr_ops; + port->enabled = false; ops->remove_port (port); + port->tr_ops =NULL ;module_put (ops->owner); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2024/2151 kdb: fix memory leak in kdb_setenv() when environment is full
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Naveen Kumar Chaudhary <[email protected]>
[ Upstream commit 22d59ccad2935b7dea7f818793b739343de433a8 ]
When kdb_setenv() fails to find a free slot in __env[], the function returns KDB_ENVFULL without freeing the previously allocated string buffer 'ep', leaking memory on every failed call.
Add the missing kfree(ep) before returning KDB_ENVFULL.
--- kernel/debug/kdb/kdb_main.c | 1 + 1 file changed, 1 insertion(+)
kernel/debug/kdb/kdb_main.c +1 -0
@@ -341,6 +341,7 @@ static int kdb_setenv(const char *var, const char *val) } } +kfree (ep);return KDB_ENVFULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2025/2151 kdb: unify CMD_BUFLEN definition into kdb_private.h
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Naveen Kumar Chaudhary <[email protected]>
[ Upstream commit 2a052074582d976bfa81e41a0337d8ae6dd1dc65 ]
CMD_BUFLEN was defined separately in kdb_io.c (256) and kdb_main.c (200), causing kdb_main.c to use the wrong size when formatting the prompt string into kdb_prompt_str (which is 256 bytes).
Move CMD_BUFLEN (256) into kdb_private.h so all users share a single consistent definition, and remove the local definitions from both files.
--- kernel/debug/kdb/kdb_io.c | 1 - kernel/debug/kdb/kdb_main.c | 6 ++---- kernel/debug/kdb/kdb_private.h | 3 ++- 3 files changed, 4 insertions(+), 6 deletions(-)
kernel/debug/kdb/kdb_io.c +0 -1
@@ -25,7 +25,6 @@#include <linux/kallsyms.h> #include "kdb_private.h" -#define CMD_BUFLEN 256char kdb_prompt_str[CMD_BUFLEN ];int kdb_trap_printk;
kernel/debug/kdb/kdb_main.c +2 -4
@@ -787,8 +787,6 @@ static int kdb_exec_defcmd(int argc, const char **argv)/* Command history */ #define KDB_CMD_HISTORY_COUNT 32 -#define CMD_BUFLEN 200/* kdb_printf: max printline -* size == 256 */ static unsigned int cmd_head, cmd_tail;static unsigned int cmdptr;static char cmd_hist[KDB_CMD_HISTORY_COUNT ][CMD_BUFLEN ];
@@ -1269,8 +1267,8 @@ static int kdb_local(kdb_reason_t reason, int error, struct pt_regs *regs, do_full_getstr:/* PROMPT can only be set if we have MEM_READ permission. */ -snprintf (kdb_prompt_str,CMD_BUFLEN ,kdbgetenv ("PROMPT" ), -raw_smp_processor_id ()); +snprintf (kdb_prompt_str,CMD_BUFLEN , +kdbgetenv ("PROMPT" ),raw_smp_processor_id ());/* * Fetch command from keyboard
kernel/debug/kdb/kdb_private.h +2 -1
@@ -224,7 +224,8 @@ extern void kdb_kbd_cleanup_state(void);#define kdb_kbd_cleanup_state ()#endif /* ! CONFIG_KDB_KEYBOARD */ -extern char kdb_prompt_str[]; +#define CMD_BUFLEN 256 +extern char kdb_prompt_str[CMD_BUFLEN ];#define KDB_WORD_SIZE ((int)sizeof(unsigned long))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2026/2151 nvmet: ignore discard return value
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chaitanya Kulkarni <[email protected]>
[ Upstream commit 38d12f15c4772b5383b1249b2afb0d206a430f0f ]
__blkdev_issue_discard() always returns 0, making the error checking in nvmet_bdev_discard_range() dead code.
Kill the function nvmet_bdev_discard_range() and call __blkdev_issue_discard() directly from nvmet_bdev_execute_discard(), since no error handling is needed anymore for __blkdev_issue_discard() call.
Stable-dep-of: 424bd0e98ca4 ("nvmet: don't truncate the length of big discards")
--- drivers/nvme/target/io-cmd-bdev.c | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-)
drivers/nvme/target/io-cmd-bdev.c +7 -21
@@ -364,29 +364,14 @@ u16 nvmet_bdev_flush(struct nvmet_req *req)return 0 ; } -static u16 nvmet_bdev_discard_range (struct nvmet_req *req, -struct nvme_dsm_range *range,struct bio **bio) -{ -struct nvmet_ns *ns = req->ns; -int ret; - - ret =__blkdev_issue_discard (ns->bdev, -nvmet_lba_to_sect (ns, range->slba), -le32_to_cpu (range->nlb) << (ns->blksize_shift -9 ), -GFP_KERNEL , bio); -if (ret && ret != -EOPNOTSUPP ) { - req->error_slba =le64_to_cpu (range->slba); -return errno_to_nvme_status (req, ret); - } -return NVME_SC_SUCCESS ; -} -static void nvmet_bdev_execute_discard (struct nvmet_req *req) { +struct nvmet_ns *ns = req->ns;struct nvme_dsm_range range;struct bio *bio =NULL ; +sector_t nr_sects;int i; -u16 status; +u16 status =NVME_SC_SUCCESS ;for (i =0 ; i <=le32_to_cpu (req->cmd->dsm.nr); i++) { status = nvmet_copy_from_sgl(req, i * sizeof(range), &range,
@@ -394,9 +379,10 @@ static void nvmet_bdev_execute_discard(struct nvmet_req *req)if (status)break ; - status =nvmet_bdev_discard_range (req, &range, &bio); -if (status) -break ; + nr_sects =le32_to_cpu (range.nlb) << (ns->blksize_shift -9 ); +__blkdev_issue_discard (ns->bdev, +nvmet_lba_to_sect (ns, range.slba), nr_sects, +GFP_KERNEL , &bio); }if (bio) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2027/2151 nvmet: dont truncate the length of big discards
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 424bd0e98ca4f227d424c3543166a9982ca45819 ]
nvmet_bdev_execute_discard() shifts the 32-bit nlb of a DSM range into sectors before widening it to sector_t, so on a 4k namespace the top bits are lost. A 3 TiB range discards 1 TiB, a 2 TiB range discards nothing, and both complete with success. The target announces no DMRSL, and hosts other than Linux (and nvme dsm passthrough) do send ranges that big.
Widen before the shift.
--- drivers/nvme/target/io-cmd-bdev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/nvme/target/io-cmd-bdev.c +2 -1
@@ -379,7 +379,8 @@ static void nvmet_bdev_execute_discard(struct nvmet_req *req)if (status)break ; - nr_sects =le32_to_cpu (range.nlb) << (ns->blksize_shift -9 ); + nr_sects = (sector_t )le32_to_cpu (range.nlb) << + (ns->blksize_shift -9 );__blkdev_issue_discard (ns->bdev,nvmet_lba_to_sect (ns, range.slba), nr_sects,GFP_KERNEL , &bio);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2028/2151 nvmet-auth: take only AUTH_Negotiate for a negotiation
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 7dd1d31e2e3124f331056d68af9a48c501b37e02 ]
nvmet_execute_auth_send() hands a common-type message to nvmet_auth_negotiate() if its ID is AUTH_Negotiate or matches the step the queue is in. The second case is wrong: the only other common-type message a host sends is AUTH_Failure2, and no queue waits in that step. A host can name the step on purpose though, and its message is then treated as a new AUTH_Negotiate without the work that goes with a new transaction, like reloading the keys on the admin queue.
Fail every other common-type message, as AUTH_Failure2 already is.
--- drivers/nvme/target/fabrics-cmd-auth.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/nvme/target/fabrics-cmd-auth.c +2 -1
@@ -347,8 +347,9 @@ void nvmet_execute_auth_send(struct nvmet_req *req) } req->sq->dhchap_step =NVME_AUTH_DHCHAP_MESSAGE_NEGOTIATE ; - }else if (data->auth_id != req->sq->dhchap_step) + }else { goto done_failure1; + }/* Validate negotiation parameters */ dhchap_status =nvmet_auth_negotiate (req, d, tl);if (dhchap_status ==0 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2029/2151 nvmet: fix NULL dereference of PCI endpoint targets
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 4a5ace11b5a367270bc86097d31c35cb61890a95 ]
nvmet_pci_epf_create_ctrl() calls nvmet_alloc_ctrl() without a queue, the admin queue comes later from the host. nvmet_alloc_ctrl() passes args->sq to nvmet_queue_tls_keyid(), which with CONFIG_NVME_TARGET_TCP_TLS dereferences it, so every PCI endpoint controller creation crashes on such a kernel. The debugfs tls_key file passes ctrl->sqs[0] to the same function, which is NULL until the admin queue exists and again once a fabrics host has closed it while keeping an I/O queue.
A queue that isn't there has no TLS key.
--- drivers/nvme/target/nvmet.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/nvme/target/nvmet.h +2 -1
@@ -892,7 +892,8 @@ static inline void nvmet_req_bio_put(struct nvmet_req *req, struct bio *bio)#ifdef CONFIG_NVME_TARGET_TCP_TLS static inline key_serial_t nvmet_queue_tls_keyid (struct nvmet_sq *sq) { -return sq->tls_key ?key_serial (sq->tls_key) :0 ; +/* A PCI endpoint controller is created without a queue */ +return sq && sq->tls_key ?key_serial (sq->tls_key) :0 ; }static inline void nvmet_sq_put_tls_key (struct nvmet_sq *sq) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2030/2151 nvmet-tcp: stop listening when a port is removed
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit ece0f4e67f08792c8572080fb0fcc231554f08ca ]
nvmet_tcp_accept_work() accepts until there's nothing left. A connection that is already dead when accepted is torn down right there, which takes a few ms, and more can arrive meanwhile. nvmet_tcp_remove_port() waits for the work with cancel_work_sync(), so someone opening and closing connections in a loop keeps the removal from finishing. It holds nvmet_config_sem for writing, so nothing can be configured and no port answers a Connect until the flood stops. No secret needed, just an admin removing the port at the wrong time.
Shut the listening socket down first. Pending connections are dropped, as they were on release, and the next kernel_accept() fails and ends the work.
--- drivers/nvme/target/tcp.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/nvme/target/tcp.c +2 -0
@@ -2213,6 +2213,8 @@ static void nvmet_tcp_remove_port(struct nvmet_port *nport) port->sock->sk->sk_data_ready = port->data_ready; port->sock->sk->sk_user_data =NULL ;write_unlock_bh (&port->sock->sk->sk_callback_lock); +/* The accept work goes on for as long as there is something to accept */ +kernel_sock_shutdown (port->sock,SHUT_RDWR );cancel_work_sync (&port->accept_work);/* * Destroy the remaining queues, which are not belong to any
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2031/2151 nvmet: fix NULL dereference in debugfs host_traddr
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 81ce4d9bbe8cf47d4b023e932ee29b22367545e6 ]
The host_traddr callbacks of tcp, rdma and fc take the host address from the transport queue around ctrl->sqs[0], which nvmet_sq_destroy() clears when the admin queue goes away while the controller lives on with its I/O queues. A host that closes the admin connection and keeps an I/O queue leaves such a controller behind, and reading its host_traddr in debugfs dereferences a near-NULL pointer:
BUG: kernel NULL pointer dereference, address: 00000000000002e0 RIP: 0010:nvmet_tcp_host_port_addr+0x19/0x50 [nvmet_tcp]
Don't ask the transport if there's no admin queue. Nothing holds the queue for debugfs, so a reader that's past the check when the queue goes away is still on its own.
--- drivers/nvme/target/core.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/nvme/target/core.c +3 -0
@@ -1802,6 +1802,9 @@ ssize_t nvmet_ctrl_host_traddr(struct nvmet_ctrl *ctrl, {if (!ctrl->ops->host_traddr)return -EOPNOTSUPP ; +/* They all take the address from the admin queue */ +if (!ctrl->sqs[0 ]) +return -ENOTCONN ;return ctrl->ops->host_traddr (ctrl, traddr, traddr_len); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2032/2151 nvmet-tcp: dont read a removed port at Connect time
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 3f98ce65a87979e881343dcf082c9595ec90ddc7 ]
nvmet_tcp_alloc_cmd() takes the nvmet port of a command from queue->port, and the commands of a queue are allocated from the io work when the Connect arrives. nvmet_tcp_remove_port() shuts down the queues that have no controller yet and frees the port without waiting for them, they're released later from a work. An io work handling a Connect at that moment reads the freed port for every command of the queue and hands the result to the core.
Note the nvmet port in the queue at allocation. It outlives the transport port.
--- drivers/nvme/target/tcp.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/nvme/target/tcp.c +4 -1
@@ -166,6 +166,7 @@ enum nvmet_tcp_queue_state {struct nvmet_tcp_queue {struct socket *sock;struct nvmet_tcp_port *port; +struct nvmet_port *nport;struct work_struct io_work;struct nvmet_cq nvme_cq;struct nvmet_sq nvme_sq;
@@ -1535,7 +1536,7 @@ static int nvmet_tcp_alloc_cmd(struct nvmet_tcp_queue *queue,u8 hdgst =nvmet_tcp_hdgst_len (queue); c->queue = queue; - c->req.port = queue->port->nport; + c->req.port = queue->nport; c->cmd_pdu =page_frag_alloc (&queue->pf_cache,sizeof (*c->cmd_pdu) + hdgst,GFP_KERNEL | __GFP_ZERO);
@@ -1991,6 +1992,8 @@ static void nvmet_tcp_alloc_queue(struct nvmet_tcp_port *port,kref_init (&queue->kref); queue->sock = newsock; queue->port = port; +/* The port may be gone when the commands are allocated */ + queue->nport = port->nport; queue->nr_cmds =0 ;spin_lock_init (&queue->state_lock); if (queue->port->nport->disc_addr.tsas.tcp.sectype ==
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2033/2151 nvme-loop: dont BUG() if a scan runs beside a reset
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 64e21d782020e267ca57765a30216c38b34f296d ]
A reset sets queue_count to 1 while it destroys the I/O queues and counts it back up when the new ones are made, and it doesn't stop the scan work. A new namespace found in that window trips the check in nvme_loop_init_hctx() for every hctx but the first:
kernel BUG at drivers/nvme/target/loop.c:224!
nvme_loop_init_hctx+0x7d/0x80 __blk_mq_realloc_hw_ctxs+0x3af/0xa80 nvme_alloc_ns+0x1a2/0x22f0
The check protects nothing. ctrl->queues has nr_io_queues + 1 entries for the life of the controller, the tag set never has more hardware queues than that, and nvme_loop_queue_rq() rejects requests until the controller is live again.
Remove it.
--- drivers/nvme/target/loop.c | 2 -- 1 file changed, 2 deletions(-)
drivers/nvme/target/loop.c +0 -2
@@ -221,8 +221,6 @@ static int nvme_loop_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,struct nvme_loop_ctrl *ctrl =to_loop_ctrl (data);struct nvme_loop_queue *queue = &ctrl->queues[hctx_idx +1 ]; -BUG_ON (hctx_idx >= ctrl->ctrl.queue_count); -/* * flush_end_io() can be called recursively for us, so use our own * lock class key for avoiding lockdep possible recursive locking,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2034/2151 nvmet-rdma: flush nvmet-wq on module exit
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit 2b646788ee24d895b8862514e12a95ce5d72d6cc ]
nvmet_rdma_exit() relies on ib_unregister_client() to flush nvmet-wq through nvmet_rdma_remove_one(), but since commit a3dd7d0022c3 that returns at once for a device no longer on device_list. The release work of the last queue takes the device off the list in nvmet_rdma_free_dev() and still has to drop the mutex, free the struct and return through nvmet_rdma_release_queue_work(), so an rmmod in that window frees the module code it's running.
Flush nvmet-wq after ib_unregister_client(). No release work can be queued after that point.
--- drivers/nvme/target/rdma.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/nvme/target/rdma.c +6 -0
@@ -2148,6 +2148,12 @@ static void __exit nvmet_rdma_exit(void) {nvmet_unregister_transport (&nvmet_rdma_ops);ib_unregister_client (&nvmet_rdma_ib_client); +/* +* nvmet_rdma_remove_one() does not flush for a device that has left +* device_list, and the release work that took it off still has to +* return from nvmet_rdma_free_dev(). +*/ +flush_workqueue (nvmet_wq);WARN_ON_ONCE (!list_empty (&nvmet_rdma_queue_list));ida_destroy (&nvmet_rdma_queue_ida); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2035/2151 nvmet-rdma: disable interrupts under rsp_wr_wait_lock
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit 14e4e09443ac2b5cd90c1e313ee3c0bdd4928e0d ]
rsp_wr_wait_lock protects the list of commands waiting for room in the send queue, and it's taken with plain spin_lock(). But nvmet_rdma_queue_response() calls nvmet_rdma_release_rsp() directly if ib_post_send() fails, and that processes the wait list. The call chain starts in nvmet_req_complete(), which for a block device namespace runs from the bio end_io callback, which can be in hard interrupt context. An interrupt that completes a command on a CPU holding the lock for the same queue spins forever. Lockdep over siw with a null_blk namespace:
inconsistent {HARDIRQ-ON-W} -> {IN-HARDIRQ-W} usage
Use spin_lock_irqsave() for both takers. The processing loop still drops the lock, and restores the caller's interrupt state, around nvmet_rdma_execute_command().
--- drivers/nvme/target/rdma.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/nvme/target/rdma.c +9 -6
@@ -513,7 +513,9 @@ static int nvmet_rdma_post_recv(struct nvmet_rdma_device *ndev,static void nvmet_rdma_process_wr_wait_list (struct nvmet_rdma_queue *queue) { -spin_lock (&queue->rsp_wr_wait_lock); +unsigned long flags; + +spin_lock_irqsave (&queue->rsp_wr_wait_lock, flags);while (!list_empty (&queue->rsp_wr_wait_list)) {struct nvmet_rdma_rsp *rsp;bool ret;
@@ -522,16 +524,16 @@ static void nvmet_rdma_process_wr_wait_list(struct nvmet_rdma_queue *queue) struct nvmet_rdma_rsp, wait_list);list_del (&rsp->wait_list); -spin_unlock (&queue->rsp_wr_wait_lock); +spin_unlock_irqrestore (&queue->rsp_wr_wait_lock, flags); ret =nvmet_rdma_execute_command (rsp); -spin_lock (&queue->rsp_wr_wait_lock); +spin_lock_irqsave (&queue->rsp_wr_wait_lock, flags);if (!ret) {list_add (&rsp->wait_list, &queue->rsp_wr_wait_list);break ; } } -spin_unlock (&queue->rsp_wr_wait_lock); +spin_unlock_irqrestore (&queue->rsp_wr_wait_lock, flags); }static u16 nvmet_rdma_check_pi_status (struct ib_mr *sig_mr)
@@ -977,6 +979,7 @@ static bool nvmet_rdma_execute_command(struct nvmet_rdma_rsp *rsp)static void nvmet_rdma_handle_command (struct nvmet_rdma_queue *queue,struct nvmet_rdma_rsp *cmd) { +unsigned long flags;u16 status; ib_dma_sync_single_for_cpu(queue->dev->device,
@@ -994,9 +997,9 @@ static void nvmet_rdma_handle_command(struct nvmet_rdma_queue *queue, goto out_err;if (unlikely (!nvmet_rdma_execute_command (cmd))) { -spin_lock (&queue->rsp_wr_wait_lock); +spin_lock_irqsave (&queue->rsp_wr_wait_lock, flags);list_add_tail (&cmd->wait_list, &queue->rsp_wr_wait_list); -spin_unlock (&queue->rsp_wr_wait_lock); +spin_unlock_irqrestore (&queue->rsp_wr_wait_lock, flags); }return ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2036/2151 nvmet-rdma: fix double puts after a failed RDMA WRITE
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit f1dac2a2e75260d1466d9f03ccf0944d6d0449a4 ]
For a read with T10-PI the RDMA WRITE is posted alone and nvmet_rdma_write_data_done() posts the SEND once the metadata check result is known. By then the request has been completed and its references put: __nvmet_req_complete() put ns->ref and the pc_ref, and nvmet_req_complete() sq->ref, right after queuing the response. The error branch of nvmet_rdma_write_data_done() copies the one from nvmet_rdma_read_data_done() and calls nvmet_req_uninit(), which puts all three again. A WRITE fails whenever the connection ends with reads in flight, which is up to the host. Depending on timing the sq->ref count goes to zero early and the queue is freed under the remaining completions, or never reaches zero and nvmet_sq_destroy() sleeps forever, or percpu_ref_put() dereferences NULL after percpu_ref_exit(). ns->ref stays too low for good, so disabling the namespace hangs too. Reproduced with KASAN over rxe with a test patch forcing the PI path.
Drop the nvmet_req_uninit(). The branch still releases the RDMA context and the response, which is all the request owns at that point.
--- drivers/nvme/target/rdma.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/nvme/target/rdma.c +4 -1
@@ -803,7 +803,10 @@ static void nvmet_rdma_write_data_done(struct ib_cq *cq, struct ib_wc *wc)if (unlikely (wc->status !=IB_WC_SUCCESS )) {nvmet_rdma_rw_ctx_destroy (rsp); -nvmet_req_uninit (&rsp->req); +/* +* Unlike in nvmet_rdma_read_data_done(), the request has been +* completed and its references are put: no nvmet_req_uninit(). +*/ nvmet_rdma_release_rsp (rsp);if (wc->status !=IB_WC_WR_FLUSH_ERR ) { pr_info("RDMA WRITE for CQE failed with status %s (%d).\n",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2037/2151 nvmet: dont clear sq->ctrl for a Connect with sqsize 0
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit 89480d137bf0d943a82c64f86ae2407a15276b5e ]
nvmet_install_queue() checks sqsize first and jumps to err on zero, where sq->ctrl is set to NULL. Since commit b71df12605ca the cmpxchg() that sets sq->ctrl comes after the checks, so err now undoes a bind that this call never made. Over RDMA a host can send two Connects together and the second is parsed before the first executes, so a second Connect with sqsize 0 clears the sq->ctrl the first one set. The reference it held is never dropped and the controller leaks, with its cntlid, until reboot. The discovery subsystem lets any host do that, 20 connections leak around 10 controllers. A pending AER on such a queue hangs nvmet_sq_destroy() forever, and a queue can keep its "authenticated" mark across a rebind.
Return the status directly, as the two checks after it do, so err is only reached after this call's cmpxchg() succeeded.
--- drivers/nvme/target/fabrics-cmd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/nvme/target/fabrics-cmd.c +1 -2
@@ -186,8 +186,7 @@ static u16 nvmet_install_queue(struct nvmet_ctrl *ctrl, struct nvmet_req *req)pr_warn ("queue size zero!\n" ); req->error_loc = offsetof(struct nvmf_connect_command , sqsize); req->cqe->result.u32 =IPO_IATTR_CONNECT_SQE (sqsize); - ret =NVME_SC_CONNECT_INVALID_PARAM |NVME_STATUS_DNR ; - goto err; +return NVME_SC_CONNECT_INVALID_PARAM |NVME_STATUS_DNR ; }if (ctrl->sqs[qid] !=NULL ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2038/2151 blk-throttle: dont truncate the cgroup v1 iops limits
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 7d96874ba80ba7a2ab578ea9139c2af79c353b88 ]
tg_set_conf() parses the limit into a u64 and stores the iops ones through an unsigned int, so anything above UINT_MAX is truncated and a multiple of 2^32 becomes a limit of 0. The next IO of the group then divides by it in tg_within_iops_limit().
Clamp to UINT_MAX, which means no limit, like tg_set_limit() does on the default hierarchy.
--- block/blk-throttle.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
block/blk-throttle.c +2 -1
@@ -1398,7 +1398,8 @@ static ssize_t tg_set_conf(struct kernfs_open_file *of,if (is_u64) *(u64 *)((void *)tg +of_cft (of)->private) = v;else - *(unsigned int *)((void *)tg +of_cft (of)->private) = v; + *(unsigned int *)((void *)tg +of_cft (of)->private) = +min_t (u64, v,UINT_MAX );tg_conf_updated (tg, false); ret =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2039/2151 blk-cgroup: fix root io.stat byte counts on 32-bit
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit e335b853d919f2c6246ca0993115285742a2acc1 ]
blkcg_fill_root_iostats() shifts the unsigned long sector counts by 9 before adding them to the u64 byte counts, so on 32-bit the contribution of a CPU wraps every 4GB. Widen before the shift.
--- block/blk-cgroup.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
block/blk-cgroup.c +3 -3
@@ -1165,11 +1165,11 @@ static void blkcg_fill_root_iostats(void) cpu_dkstats->ios[STAT_DISCARD ];// convert sectors to bytes tmp.bytes[BLKG_IOSTAT_READ ] += - cpu_dkstats->sectors[STAT_READ ] <<9 ; + (u64 )cpu_dkstats->sectors[STAT_READ ] <<9 ; tmp.bytes[BLKG_IOSTAT_WRITE ] += - cpu_dkstats->sectors[STAT_WRITE ] <<9 ; + (u64 )cpu_dkstats->sectors[STAT_WRITE ] <<9 ; tmp.bytes[BLKG_IOSTAT_DISCARD ] += - cpu_dkstats->sectors[STAT_DISCARD ] <<9 ; + (u64 )cpu_dkstats->sectors[STAT_DISCARD ] <<9 ; } flags =u64_stats_update_begin_irqsave (&blkg->iostat.sync);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2040/2151 blk-cgroup: dont free a blkg with its punt work queued
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 4def096314cf29fb6940b74c087a0b923185580e ]
blkg_async_bio_workfn() relies on the bios on the list pinning the blkg. But blkcg_punt_bio_submit() can call queue_work() after a running instance already took and completed the bio, and queue_work() succeeds on an empty list for the same reason. Nothing holds the blkg then, and free_work shares its memory with async_bio_work on top of that.
Hold a reference across blkcg_punt_bio_submit(), give the two works memory of their own, and cancel async_bio_work in blkg_free_workfn().
--- block/blk-cgroup.c | 13 ++++++++++++- block/blk-cgroup.h | 6 ++---- 2 files changed, 14 insertions(+), 5 deletions(-)
block/blk-cgroup.c +12 -1
@@ -118,6 +118,11 @@ static void blkg_free_workfn(struct work_struct *work)struct request_queue *q = blkg->q;int i; +#ifdef CONFIG_BLK_CGROUP_PUNT_BIO +/* It may have been queued for bios which an earlier run has taken */ +cancel_work_sync (&blkg->async_bio_work); +#endif +/* * pd_free_fn() can also be called from blkcg_deactivate_policy(), * in order to make sure pd_free_fn() is called in order, the deletion
@@ -212,7 +217,7 @@ static void blkg_async_bio_workfn(struct work_struct *work)struct blk_plug plug;bool need_plug = false; -/* as long as there are pending bios, @blkg can't go away */ +/* blkg_free_workfn() waits for us */ spin_lock (&blkg->async_bio_lock);bio_list_merge_init (&bios, &blkg->async_bios);spin_unlock (&blkg->async_bio_lock);
@@ -239,10 +244,16 @@ void blkcg_punt_bio_submit(struct bio *bio)struct blkcg_gq *blkg = bio->bi_blkg;if (blkg->parent) { +/* +* Once it is on the list, a run which is under way can submit +* @bio, and its reference goes when it completes. +*/ +blkg_get (blkg);spin_lock (&blkg->async_bio_lock);bio_list_add (&blkg->async_bios, bio);spin_unlock (&blkg->async_bio_lock);queue_work (blkcg_punt_bio_wq, &blkg->async_bio_work); +blkg_put (blkg); }else {/* never bounce for the root cgroup */ submit_bio (bio);
block/blk-cgroup.h +2 -4
@@ -76,11 +76,9 @@ struct blkcg_gq {#ifdef CONFIG_BLK_CGROUP_PUNT_BIO spinlock_t async_bio_lock;struct bio_list async_bios; +struct work_struct async_bio_work;#endif -union { -struct work_struct async_bio_work; -struct work_struct free_work; - }; +struct work_struct free_work;atomic_t use_delay;atomic64_t delay_nsec;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2041/2151 blk-iolatency: flush enable_work after going offline
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 020f61242d6ebeba5f8f2ef6e429aeffdd63f1c1 ]
blkcg_iolatency_exit() flushes enable_work before it deactivates the policy, but iolatency_pd_offline() schedules it again for the last group with a target, so the blk_iolatency is freed with the work queued. Flush it after the deactivation.
--- block/blk-iolatency.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
block/blk-iolatency.c +2 -1
@@ -637,8 +637,9 @@ static void blkcg_iolatency_exit(struct rq_qos *rqos)struct blk_iolatency *blkiolat =BLKIOLATENCY (rqos);timer_shutdown_sync (&blkiolat->timer); -flush_work (&blkiolat->enable_work);blkcg_deactivate_policy (rqos->disk, &blkcg_policy_iolatency); +/* iolatency_pd_offline() schedules it for the last group with a target */ +flush_work (&blkiolat->enable_work);kfree (blkiolat); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2042/2151 blk-throttle: pass the I/O counts of a dead group on
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 587edb931fdda032bcd63fdfb0db4ded75159ee9 ]
The recursive io_service_bytes and io_serviced files sum up the online groups plus what dead descendants left in aux_cnt. That worked while the counters lived in the blkg. Since commit 7ca464383aec they're in the throtl_grp and nobody passes them up, so the files go backwards when a child is removed. Add them to the parent in throtl_pd_offline().
--- block/blk-throttle.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
block/blk-throttle.c +12 -1
@@ -1676,7 +1676,18 @@ static void tg_flush_bios(struct throtl_grp *tg)static void throtl_pd_offline (struct blkg_policy_data *pd) { -tg_flush_bios (pd_to_tg (pd)); +struct throtl_grp *tg =pd_to_tg (pd); +struct throtl_grp *parent =blkg_to_tg (tg_to_blkg (tg)->parent); + +tg_flush_bios (tg); + +/* the recursive files of the ancestors go on counting what it did */ +if (parent) { +blkg_rwstat_add_aux (&parent->stat_bytes, &tg->stat_bytes); +blkg_rwstat_add_aux (&parent->stat_ios, &tg->stat_ios); +blkg_rwstat_reset (&tg->stat_bytes); +blkg_rwstat_reset (&tg->stat_ios); + } }struct blkcg_policy blkcg_policy_throtl = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2043/2151 blk-throttle: make blkio.reset_stats reset I/O counts
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit ac81a07a0bd5e75e8edc0eb5be563be1b2d56554 ]
blkio.throttle.io_service_bytes and io_serviced were reset by blkcg_reset_stats() while the counters were part of the blkg. Now that they live in the throtl_grp, add a pd_reset_stats_fn for them.
--- block/blk-throttle.c | 9 +++++++++ 1 file changed, 9 insertions(+)
block/blk-throttle.c +9 -0
@@ -1690,6 +1690,14 @@ static void throtl_pd_offline(struct blkg_policy_data *pd) } } +static void throtl_pd_reset_stats (struct blkg_policy_data *pd) +{ +struct throtl_grp *tg =pd_to_tg (pd); + +blkg_rwstat_reset (&tg->stat_bytes); +blkg_rwstat_reset (&tg->stat_ios); +} +struct blkcg_policy blkcg_policy_throtl = { .dfl_cftypes = throtl_files, .legacy_cftypes = throtl_legacy_files,
@@ -1699,6 +1707,7 @@ struct blkcg_policy blkcg_policy_throtl = { .pd_online_fn = throtl_pd_online, .pd_offline_fn = throtl_pd_offline, .pd_free_fn = throtl_pd_free, + .pd_reset_stats_fn = throtl_pd_reset_stats, };void blk_throtl_cancel_bios (struct gendisk *disk)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2044/2151 net: bcmgenet: recover from a failed resume
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicolai Buchwitz <[email protected]>
[ Upstream commit 1c1f51c3ee9ccf86462e36548291ed44fecd5355 ]
A resume that fails in bcmgenet_init_dma() returns with the interface still IFF_UP and the datapath gone. The next ifdown runs the teardown a second time and napi_disable() waits for a NAPI_STATE_SCHED bit that nothing will clear:
task:ip state:D
usleep_range_state+0xec/0x158
napi_disable_locked+0x254/0x318
napi_disable+0x3c/0x68
bcmgenet_netif_stop+0x1c8/0x318
bcmgenet_close+0x24/0xd0
__dev_close_many+0x18c/0x310RTNL is held across the wait, so everything else blocks behind it.
The same resume gates the clock and detaches the device. Close releases the clock a second time and ifup fails with -ENODEV. The hardware filters stay armed, so the next WoL suspend wakes on any frame. That suspend sets CMD_RX_EN for magic packet detection, so the WoL resume reuses rings that are gone.
A failed resume should leave a state the ordinary paths can handle. Clear rx_cbs and tx_cbs as they are freed so they answer whether a datapath exists, and leave the clock alone so close and suspend release it once. The WoL resume rebuilds instead, so stop the PHY first, phy_start() only takes PHY_READY or PHY_HALTED.
Flagged in a sashiko review and reproduced on a CM4 by forcing the resume allocation to fail.
--- .../net/ethernet/broadcom/genet/bcmgenet.c | 92 +++++++++++++------ 1 file changed, 62 insertions(+), 30 deletions(-)
drivers/net/ethernet/broadcom/genet/bcmgenet.c +62 -30
@@ -3113,7 +3113,9 @@ static void bcmgenet_fini_dma(struct bcmgenet_priv *priv)bcmgenet_free_rx_buffers (priv);bcmgenet_destroy_rx_page_pools (priv);kfree (priv->rx_cbs); + priv->rx_cbs =NULL ;kfree (priv->tx_cbs); + priv->tx_cbs =NULL ; }/* init_edma: Initialize DMA control register */
@@ -3173,6 +3175,7 @@ static int bcmgenet_init_dma(struct bcmgenet_priv *priv, bool flush_rx) GFP_KERNEL);if (!priv->tx_cbs) {kfree (priv->rx_cbs); + priv->rx_cbs =NULL ;return -ENOMEM ; }
@@ -3192,7 +3195,9 @@ static int bcmgenet_init_dma(struct bcmgenet_priv *priv, bool flush_rx)bcmgenet_free_rx_buffers (priv);bcmgenet_destroy_rx_page_pools (priv);kfree (priv->rx_cbs); + priv->rx_cbs =NULL ;kfree (priv->tx_cbs); + priv->tx_cbs =NULL ;return ret; }
@@ -3501,7 +3506,9 @@ static int bcmgenet_close(struct net_device *dev)netif_dbg (priv, ifdown, dev,"bcmgenet_close\n" ); -bcmgenet_netif_stop (dev, false); +/* A failed resume has torn the datapath down already */ +if (priv->tx_cbs) +bcmgenet_netif_stop (dev, false);/* Really kill the PHY state machine and disconnect from it */ phy_disconnect (dev->phydev);
@@ -3509,6 +3516,9 @@ static int bcmgenet_close(struct net_device *dev)free_irq (priv->irq0, priv);free_irq (priv->irq1, priv); +/* A failed resume left the device detached, __dev_open() refuses that */ +netif_device_attach (dev); +if (priv->internal_phy) ret =bcmgenet_power_down (priv,GENET_POWER_PASSIVE );
@@ -4273,7 +4283,11 @@ static int bcmgenet_resume(struct device *d)if (device_may_wakeup (d) && priv->wolopts) { reg =bcmgenet_umac_readl (priv,UMAC_CMD ); -if (reg &CMD_RX_EN ) { + +/* The WoL power down sets CMD_RX_EN itself, so the bit +* alone does not mean the rings survived +*/ +if (priv->tx_cbs && (reg &CMD_RX_EN )) {/* Successfully exited WoL, just resume data flows */ list_for_each_entry (rule, &priv->rxnfc_list, list)if (rule->state ==BCMGENET_RXNFC_STATE_ENABLED )
@@ -4303,6 +4317,9 @@ static int bcmgenet_resume(struct device *d)bcmgenet_rdma_disable (priv);bcmgenet_intr_disable (priv);bcmgenet_fini_dma (priv); +if (phy_is_started (dev->phydev) || + dev->phydev->state ==PHY_ERROR ) +phy_stop (dev->phydev);enable_irq (priv->irq1); }
@@ -4325,8 +4342,9 @@ static int bcmgenet_resume(struct device *d)/* Reinitialize TDMA and RDMA and SW housekeeping */ ret =bcmgenet_init_dma (priv, false);if (ret) { +/* Leave the block clocked, close and suspend tear it down */ netdev_err (dev,"failed to initialize DMA\n" ); - goto out_clk_disable; +return ret; }if (!device_may_wakeup (d))
@@ -4337,24 +4355,57 @@ static int bcmgenet_resume(struct device *d)netif_device_attach (dev);return 0 ; +} -out_clk_disable: -if (priv->internal_phy) -bcmgenet_power_down (priv,GENET_POWER_PASSIVE ); -clk_disable_unprepare (priv->clk); -return ret; +/* Arm the configured wake filters and drop the rest, then clear old +* matches so that only a new one wakes the system +*/ +static void bcmgenet_wol_arm_filters (struct bcmgenet_priv *priv) +{ +struct bcmgenet_rxnfc_rule *rule; +u32 reg, hfb_enable =0 ; + +if (priv->wolopts &WAKE_FILTER ) +list_for_each_entry (rule, &priv->rxnfc_list, list) +if (rule->fs.ring_cookie ==RX_CLS_FLOW_WAKE && + rule->state ==BCMGENET_RXNFC_STATE_ENABLED ) + hfb_enable |=1 << rule->fs.location; + + reg =bcmgenet_hfb_reg_readl (priv,HFB_CTRL ); +if (GENET_IS_V1 (priv) ||GENET_IS_V2 (priv)) { + reg &= ~RBUF_HFB_FILTER_EN_MASK ; + reg |= hfb_enable << (RBUF_HFB_FILTER_EN_SHIFT +1 ); + }else { +bcmgenet_hfb_reg_writel (priv, hfb_enable <<1 , +HFB_FLT_ENABLE_V3PLUS +4 ); + } +if (!hfb_enable) + reg &= ~RBUF_HFB_EN ; +bcmgenet_hfb_reg_writel (priv, reg,HFB_CTRL ); + +bcmgenet_intrl2_0_writel (priv,0xFFFFFFFF ,INTRL2_CPU_MASK_SET ); +bcmgenet_intrl2_0_writel (priv,0xFFFFFFFF ,INTRL2_CPU_CLEAR ); }static int bcmgenet_suspend (struct device *d) {struct net_device *dev =dev_get_drvdata (d);struct bcmgenet_priv *priv =netdev_priv (dev); -struct bcmgenet_rxnfc_rule *rule; -u32 reg, hfb_enable =0 ;if (!netif_running (dev))return 0 ; +/* A failed resume has torn the datapath down already. Resume still +* enables irq1 on the WoL path, so it has to be disabled here. +*/ +if (!priv->tx_cbs) { +if (device_may_wakeup (d) && priv->wolopts) { +bcmgenet_wol_arm_filters (priv); +disable_irq (priv->irq1); + } +return 0 ; + } +netif_device_detach (dev);if (device_may_wakeup (d) && priv->wolopts) {
@@ -4363,26 +4414,7 @@ static int bcmgenet_suspend(struct device *d)netif_tx_disable (dev);/* Suspend non-wake Rx data flows */ -if (priv->wolopts &WAKE_FILTER ) -list_for_each_entry (rule, &priv->rxnfc_list, list) -if (rule->fs.ring_cookie ==RX_CLS_FLOW_WAKE && - rule->state ==BCMGENET_RXNFC_STATE_ENABLED ) - hfb_enable |=1 << rule->fs.location; - reg =bcmgenet_hfb_reg_readl (priv,HFB_CTRL ); -if (GENET_IS_V1 (priv) ||GENET_IS_V2 (priv)) { - reg &= ~RBUF_HFB_FILTER_EN_MASK ; - reg |= hfb_enable << (RBUF_HFB_FILTER_EN_SHIFT +1 ); - }else { -bcmgenet_hfb_reg_writel (priv, hfb_enable <<1 , -HFB_FLT_ENABLE_V3PLUS +4 ); - } -if (!hfb_enable) - reg &= ~RBUF_HFB_EN ; -bcmgenet_hfb_reg_writel (priv, reg,HFB_CTRL ); - -/* Clear any old filter matches so only new matches wake */ -bcmgenet_intrl2_0_writel (priv,0xFFFFFFFF ,INTRL2_CPU_MASK_SET ); -bcmgenet_intrl2_0_writel (priv,0xFFFFFFFF ,INTRL2_CPU_CLEAR ); +bcmgenet_wol_arm_filters (priv);if (-ETIMEDOUT ==bcmgenet_tdma_disable (priv)) netdev_warn(priv->dev,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2045/2151 net: bcmgenet: restore the Tx coalescing setting when the rings are rebuilt
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicolai Buchwitz <[email protected]>
[ Upstream commit ff8a7c0c06762a2a2333fbd6148d637bbd3d5090 ]
bcmgenet_set_coalesce() writes tx_max_coalesced_frames straight into DMA_MBUF_DONE_THRESH and keeps no copy of it, while bcmgenet_init_tx_ring() programs a fixed 1. An ifdown and ifup or a resume then puts the Tx coalescing back to one frame per interrupt.
Rx keeps its value per ring and reapplies it on init. Do the same for Tx.
--- drivers/net/ethernet/broadcom/genet/bcmgenet.c | 10 ++++++++-- drivers/net/ethernet/broadcom/genet/bcmgenet.h | 1 + 2 files changed, 9 insertions(+), 2 deletions(-)
drivers/net/ethernet/broadcom/genet/bcmgenet.c +8 -2
@@ -932,10 +932,13 @@ static int bcmgenet_set_coalesce(struct net_device *dev,/* Program all TX queues with the same values, as there is no * ethtool knob to do coalescing on a per-queue basis */ -for (i =0 ; i <= priv->hw_params->tx_queues; i++) +for (i =0 ; i <= priv->hw_params->tx_queues; i++) { + priv->tx_rings[i].tx_max_coalesced_frames = + ec->tx_max_coalesced_frames;bcmgenet_tdma_ring_writel (priv, i, ec->tx_max_coalesced_frames,DMA_MBUF_DONE_THRESH ); + }for (i =0 ; i <= priv->hw_params->rx_queues; i++)bcmgenet_set_ring_rx_coalesce (&priv->rx_rings[i], ec);
@@ -2754,7 +2757,8 @@ static void bcmgenet_init_tx_ring(struct bcmgenet_priv *priv,bcmgenet_tdma_ring_writel (priv, index,0 ,TDMA_PROD_INDEX );bcmgenet_tdma_ring_writel (priv, index,0 ,TDMA_CONS_INDEX ); -bcmgenet_tdma_ring_writel (priv, index,1 ,DMA_MBUF_DONE_THRESH ); +bcmgenet_tdma_ring_writel (priv, index, ring->tx_max_coalesced_frames, +DMA_MBUF_DONE_THRESH );/* Disable rate control for now */ bcmgenet_tdma_ring_writel (priv, index, flow_period_val,TDMA_FLOW_PERIOD );
@@ -4181,6 +4185,8 @@ static int bcmgenet_probe(struct platform_device *pdev) priv->rx_rings[i].index = i; priv->rx_rings[i].rx_max_coalesced_frames =1 ; } +for (i =0 ; i <= priv->hw_params->tx_queues; i++) + priv->tx_rings[i].tx_max_coalesced_frames =1 ;/* Initialize u64 stats seq counter for 32bit machines */ for (i =0 ; i <=GENET_MAX_MQ_CNT ; i++) {
drivers/net/ethernet/broadcom/genet/bcmgenet.h +1 -0
@@ -553,6 +553,7 @@ struct bcmgenet_tx_ring {unsigned int prod_index;/* Tx ring producer index SW copy */ unsigned int cb_ptr;/* Tx ring initial CB ptr */ unsigned int end_ptr;/* Tx ring end CB ptr */ +unsigned int tx_max_coalesced_frames;struct bcmgenet_priv *priv; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2046/2151 net: dcb: initialize PFC value before calling getpfccfg
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joas Antonio dos Santos <[email protected]>
[ Upstream commit ca87a2dffbb550fc934647d5e8d1c4ae85590132 ]
dcbnl_getpfccfg() and dcbnl_cee_fill() pass the address of an uninitialized stack u8 to the driver's getpfccfg() op and then put it into the netlink reply unconditionally. The op returns void, so the core cannot tell whether the driver wrote the value.
i40e_dcbnl_get_pfc_cfg() and ice_dcbnl_get_pfc_cfg() return without writing *setting unless the DCBX agent is host managed and in CEE mode. Both drivers normally run with firmware managed DCBX (DCB_CAP_DCBX_LLD_MANAGED), and i40e with FW LLDP disabled runs host managed in IEEE mode, so on a DCB capable i40e/ice port the PFC values in DCB_CMD_PFC_GCFG and DCB_CMD_CEE_GET replies, and in the CEE part of RTNLGRP_DCB notifications, come from uninitialized stack. The same u8 is reused for all eight priorities, so this is one byte per reply.
dcb_doit() only requires CAP_NET_ADMIN for RTM_SETDCB, so the GET commands are available to unprivileged users.
Set the value to 0 before each call, like the PG config path already presets its outputs to DCB_ATTR_VALUE_UNDEFINED. 0 is also what the reply contains today on kernels built with CONFIG_INIT_STACK_ALL_ZERO, so nothing changes for those.
Found by code inspection, compile-tested only (W=1). I don't have i40e/ice hardware to check the reply.
--- net/dcb/dcbnl.c | 2 ++ 1 file changed, 2 insertions(+)
net/dcb/dcbnl.c +2 -0
@@ -281,6 +281,7 @@ static int dcbnl_getpfccfg(struct net_device *netdev, struct nlmsghdr *nlh,if (!getall && !data[i])continue ; + value =0 ; netdev->dcbnl_ops->getpfccfg (netdev, i -DCB_PFC_UP_ATTR_0 , &value); ret =nla_put_u8 (skb, i, value);
@@ -1396,6 +1397,7 @@ static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev) goto nla_put_failure;for (i =DCB_PFC_UP_ATTR_0 ; i <=DCB_PFC_UP_ATTR_7 ; i++) { + value =0 ; ops->getpfccfg (netdev, i -DCB_PFC_UP_ATTR_0 , &value);if (nla_put_u8 (skb, i, value)) goto nla_put_failure;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2047/2151 ppp: linearize and segment bridged packets when required
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 0de4e69cd021c99d0aa13e1f30aafd13ad74a2a5 ]
PPP channel bridging hands packets received on one channel directly to the start_xmit() of another. Packets received by PPPoE can be non-linear, GSO since commit 55a5d8fca836 ("net: pppoe: implement GRO/GSO support"), or CHECKSUM_PARTIAL when injected with a virtio_net_hdr. The regular transmit path never sees such packets, and only PPPoE, which uses dev_queue_xmit(), handles them:
- PPP Async reads the whole packet through skb->data, transmitting unrelated memory for non-linear packets.
- PPP Async and Sync send GSO packets as single frames of up to 64KB, and CHECKSUM_PARTIAL packets with a bad L4 checksum.
- PPTP and L2TP cannot segment a TCP GSO packet once their GRE or UDP header is pushed, and do not finish pending checksums.
Add a xmit_offload flag to struct ppp_channel, set for PPPoE. For other channels, segment GSO packets in software, using the PPP protocol field as the L2 header, finish CHECKSUM_PARTIAL checksums (including SCTP CRC32c), and linearize packets for channels without direct_xmit, as ppp_push() does. Packets are dropped if any step fails, or if the channel is busy, as before.
skb->dev is NULL at this point for PPPoE (cleared by __sk_receive_skb()), and tunnel and IPv6 UFO GSO handlers dereference it: only TCP, UDP L4 and fraglist GSO packets without encapsulation are segmented, others are dropped.
Receive paths like L2TP pull headers without updating the checksum state, possibly leaving a CHECKSUM_PARTIAL state with csum_start before skb->data. Reset it to CHECKSUM_NONE, as skb_postpull_rcsum() does, so that skb_checksum_help() does not warn, and so that PPPoE does not offload a checksum at a wrong offset.
Tested in a VM by bridging PPPoE (on a TAP with IFF_NAPI_FRAGS, or on veth) to PPP Async on a PTY, PPPoL2TP and PPPoE: non-linear packets no longer leak garbage, GSO packets (including fraglist GRO) are sent as valid segments for IPv4 and IPv6, CHECKSUM_PARTIAL packets get a valid checksum, and PPPoE still receives GSO packets unchanged.
--- drivers/net/ppp/ppp_generic.c | 95 ++++++++++++++++++++++++++++++++++- drivers/net/ppp/pppoe.c | 1 + include/linux/ppp_channel.h | 1 + 3 files changed, 95 insertions(+), 2 deletions(-)
drivers/net/ppp/ppp_generic.c +93 -2
@@ -46,6 +46,7 @@#include <linux/slab.h> #include <linux/file.h> #include <linux/unaligned.h> +#include <net/gso.h> #include <net/netdev_lock.h> #include <net/slhc_vj.h> #include <linux/atomic.h>
@@ -2313,6 +2314,73 @@ static bool ppp_decompress_proto(struct sk_buff *skb)return pskb_may_pull (skb,2 ); } +#define PPP_BRIDGE_GSO_TYPES (SKB_GSO_TCPV4 | SKB_GSO_TCPV6 | \ + SKB_GSO_TCP_ECN | SKB_GSO_TCP_ACCECN | \ + SKB_GSO_TCP_FIXEDID | SKB_GSO_UDP_L4 | \ + SKB_GSO_FRAGLIST | SKB_GSO_DODGY) + +/* Segment a GSO packet (built by PPPoE GRO, or injected with a +* virtio_net_hdr) before sending it to a bridged channel that does +* not accept GSO packets. +* skb->data points to the PPP protocol field, which is replicated +* in front of each segment. +* Returns a list of segments, or NULL if the packet was dropped. +*/ +static struct sk_buff *ppp_bridge_gso_segment (struct sk_buff *skb, +netdev_features_t features) +{ +struct sk_buff *segs; + +/* skb->dev is NULL here (cleared by __sk_receive_skb() for PPPoE), +* and some GSO handlers (tunnels, IPv6 UFO) dereference it. +*/ +if (skb->encapsulation || + (skb_shinfo (skb)->gso_type & ~PPP_BRIDGE_GSO_TYPES )) + goto drop; + +if (!pskb_may_pull (skb,PPP_PROTO_LEN )) + goto drop; + +switch (get_unaligned ((__be16 *)skb->data)) { +case htons (PPP_IP ): + skb->protocol =htons (ETH_P_IP ); +break ; +case htons (PPP_IPV6 ): + skb->protocol =htons (ETH_P_IPV6 ); +break ; +default : + goto drop; + } +skb_set_network_header (skb,PPP_PROTO_LEN ); + +/* No checksum offload: skb_segment() computes the checksums. */ + segs =skb_gso_segment (skb, features); +if (IS_ERR_OR_NULL (segs)) + goto drop; + +consume_skb (skb); +return segs; + +drop: +kfree_skb (skb); +return NULL ; +} + +static void ppp_bridge_xmit (struct ppp_channel *chan,struct sk_buff *skb) +{ +if (!chan->direct_xmit &&skb_linearize (skb)) + goto drop; + +if (!chan->xmit_offload && skb->ip_summed ==CHECKSUM_PARTIAL && +skb_csum_hwoffload_help (skb,0 )) + goto drop; + +if (chan->ops->start_xmit (chan, skb)) +return ; +drop: +kfree_skb (skb); +} +/* Attempt to handle a frame via. a bridged channel, if one exists. * If the channel is bridged, the frame is consumed by the bridge. * If not, the caller must handle the frame by normal recv mechanisms.
@@ -2320,6 +2388,8 @@ static bool ppp_decompress_proto(struct sk_buff *skb)*/ static bool ppp_channel_bridge_input (struct channel *pch,struct sk_buff *skb) { +struct sk_buff *segs, *next; +struct ppp_channel *chan;struct channel *pchb;rcu_read_lock ();
@@ -2335,8 +2405,29 @@ static bool ppp_channel_bridge_input(struct channel *pch, struct sk_buff *skb) }skb_scrub_packet (skb, !net_eq (pch->chan_net, pchb->chan_net)); -if (!pchb->chan->ops->start_xmit (pchb->chan, skb)) -kfree_skb (skb); + +/* Receive paths such as L2TP pull headers without updating +* the checksum state: drop a stale CHECKSUM_PARTIAL state +* pointing before skb->data, as skb_postpull_rcsum() does. +*/ +if (skb->ip_summed ==CHECKSUM_PARTIAL && +skb_checksum_start_offset (skb) <0 ) + skb->ip_summed =CHECKSUM_NONE ; + + chan = pchb->chan; +if (!chan->xmit_offload &&skb_is_gso (skb)) { +/* Channels needing linear packets get linear segments, +* others keep references to the original pages. +*/ + segs =ppp_bridge_gso_segment (skb, chan->direct_xmit ? +NETIF_F_SG :0 ); + skb_list_walk_safe(segs, skb, next) { +skb_mark_not_on_list (skb); +ppp_bridge_xmit (chan, skb); + } + }else { +ppp_bridge_xmit (chan, skb); + } outl:spin_unlock_bh (&pchb->downl);
drivers/net/ppp/pppoe.c +1 -0
@@ -704,6 +704,7 @@ static int pppoe_connect(struct socket *sock, struct sockaddr *uservaddr, po->chan.private = sk; po->chan.ops = &pppoe_chan_ops; po->chan.direct_xmit = true; + po->chan.xmit_offload = true; error =ppp_register_net_channel (dev_net (dev), &po->chan);if (error) {
include/linux/ppp_channel.h +1 -0
@@ -43,6 +43,7 @@ struct ppp_channel {void *ppp;/* opaque to channel */ int speed;/* transfer rate (bytes/second) */ bool direct_xmit;/* no qdisc, xmit directly */ +bool xmit_offload;/* accepts GSO and CHECKSUM_PARTIAL skbs */ };#ifdef __KERNEL__
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2048/2151 bnge: cap RSS contexts and RX rings to the RSS table size
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dharmender Garg <[email protected]>
[ Upstream commit e8f6ca11167d4753386340ce88444b5445dff831 ]
The hardware supports at most BNGE_RSS_TABLE_MAX_TBL (8) RSS contexts. They are stored in vnic->fw_rss_cos_lb_ctx[8] and back a 512-entry (BNGE_MAX_RSS_TABLE_ENTRIES) indirection table and DMA buffer, so at most 512 RX rings can be served by RSS.
bnge_cal_nr_rss_ctxs() has no upper bound, so with more RX rings it returns more than 8 contexts: bnge_setup_vnic() writes past fw_rss_cos_lb_ctx[], bnge_set_dflt_rss_indir_tbl() and bnge_fill_hw_rss_tbl() write past the indirection table and its DMA buffer, and the pad computation in bnge_set_dflt_rss_indir_tbl() underflows into a huge memset().
Cap the number of contexts at BNGE_RSS_TABLE_MAX_TBL and the number of RX rings at BNGE_MAX_RSS_TABLE_ENTRIES, so the sizes derived from the ring count always fit the arrays.
--- drivers/net/ethernet/broadcom/bnge/bnge_resc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/broadcom/bnge/bnge_resc.c +4 -2
@@ -170,8 +170,9 @@ int bnge_cal_nr_rss_ctxs(u16 rx_rings)if (!rx_rings)return 0 ; -return bnge_adjust_pow_two (rx_rings -1 , -BNGE_RSS_TABLE_ENTRIES ); +return min_t (int,bnge_adjust_pow_two (rx_rings -1 , +BNGE_RSS_TABLE_ENTRIES ), +BNGE_RSS_TABLE_MAX_TBL ); } static u16 bnge_rss_ctxs_in_use(struct bnge_dev *bd,
@@ -447,6 +448,7 @@ static void _bnge_get_max_rings(struct bnge_dev *bd, u16 *max_rx, } *max_rx =min_t (int, *max_rx, max_ring_grps); + *max_rx =min_t (int, *max_rx,BNGE_MAX_RSS_TABLE_ENTRIES ); } static int bnge_get_max_rings(struct bnge_dev *bd, u16 *max_rx,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2049/2151 bnge: fix RSS table sizing for large RX ring counts
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dharmender Garg <[email protected]>
[ Upstream commit 8b97091eae744a577573797e5d5abc3e0da10769 ]
bnge_adjust_pow_two() adds one block before rounding up to a power of two only when the quotient is 0 or 1. A larger quotient that is already a power of two is returned unchanged, so 129-192 RX rings get a 128-entry RSS indirection table and 257-320 rings a 256-entry one. The rings above the table size never receive default RSS traffic. bnxt_calc_nr_ring_pages() always adds one, which is correct.
Make bnge_adjust_pow_two() always add one block before rounding up.
bnge_adjust_pow_two() also sizes the RX, RX aggregation, TX and completion ring pages. For the default 511-entry rings their page counts do not change. The completion ring is sized from more than the default depth, so its page count changes where the old code dropped a partial page. With 8K ring pages, TPA off and the default rings, its budget is 1533 entries and the page count goes from 2 to 4. With 4K ring pages and TPA on, when the firmware reports a max_aggs_supported of 260 to 387, it goes from 16 to 32.
In these cases the old completion ring held fewer entries than its budget.
--- drivers/net/ethernet/broadcom/bnge/bnge_resc.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/net/ethernet/broadcom/bnge/bnge_resc.h +3 -6
@@ -80,13 +80,10 @@ bnge_adjust_pow_two(u32 total_ent, u16 ent_per_blk) {u32 blks = total_ent / ent_per_blk; -if (blks ==0 || blks ==1 ) -return ++blks; +if (!blks) +return 1 ; -if (!is_power_of_2 (blks)) - blks =roundup_pow_of_two (blks); - -return blks; +return roundup_pow_of_two (blks +1 ); }#define BNGE_MAX_ROCE_MSIX 64
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2050/2151 ice: set in_use only after preparing Tx timestamp index
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jacob Keller <[email protected]>
[ Upstream commit 50870d62116038e6f1e17a6aedcf2a95cec37ec7 ]
The ice_ptp_request_ts() function is used to request a timestamp index for use with a packet. When reserving an index, it sets the start time and saves a pointer to the skb into the appropriate index. The function marks the in_use bit first before doing any of these steps. The IRQ handler which clears the timestamps reads the in_use bits uses a lockless flow for reading the in_use bits to determine which ones are in-use. This is necessary as actually processing a complete timestamp must be able to sleep so we cannot hold the timestamp tracker lock over the entire sequence. Additionally, blocking the Tx hotpath with such a lock indefinitely would be problematic.
However, the existing flow now has a very narrow window where the IRQ handler could see a timestamp as in-use but read a stale value for its "start" time.
Fix this by ordering the sequence to mark the in_use bit last, and add a memory barrier to prevent re-ordering of the previous writes to setup the index.
This was found and reported by Sashiko while reviewing an unrelated change.
--- drivers/net/ethernet/intel/ice/ice_ptp.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/net/ethernet/intel/ice/ice_ptp.c +10 -2
@@ -589,6 +589,12 @@ static void ice_ptp_process_tx_tstamp(struct ice_ptp_tx *tx)bool drop_ts = !link_up;struct sk_buff *skb; +/* Paired with smp_mb__before_atomic() in ice_ptp_request_ts() +* to ensure ordering the in_use bitmap and the indexed fields +* in the tstamps array. +*/ +smp_rmb (); +/* Drop packets which have waited for more than 2 seconds */ if (time_is_before_jiffies (tx->tstamps[idx].start +2 *HZ )) { drop_ts = true;
@@ -2593,11 +2599,13 @@ s8 ice_ptp_request_ts(struct ice_ptp_tx *tx, struct sk_buff *skb)* a reference to the skb and the start time to allow discarding old * requests. */ -set_bit (idx, tx->in_use); -clear_bit (idx, tx->stale); tx->tstamps[idx].start = jiffies; tx->tstamps[idx].skb =skb_get (skb);skb_shinfo (skb)->tx_flags |=SKBTX_IN_PROGRESS ; +clear_bit (idx, tx->stale); +/* Ensure index is setup before marking it as used */ +smp_mb__before_atomic (); +set_bit (idx, tx->in_use);ice_trace (tx_tstamp_request, skb, idx); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2051/2151 ice: E822: keep Tx timestamps disabled during offset calibration
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karol Kolacinski <[email protected]>
[ Upstream commit 56af436b90acce7eaa7531189c827773983f7d07 ]
Do not clear the tx.calibrating flag immediately after starting the PHY timer in ice_ptp_port_phy_restart(). Instead, keep Tx timestamps disabled until the offset verification work (ice_ptp_wait_for_offsets) has confirmed that the Tx PHY offset is properly configured.
Previously, tx.calibrating was set to true, then immediately back to false right after ice_start_phy_timer_e82x() returned. This allowed Tx timestamp requests to be served during the window where offset verification was still pending. Timestamps produced during this window should have their valid bit cleared, but it is better to prevent requests until the driver has confirmed calibration is complete.
Rename the tx.calibrating field to tx.disabled, and change where it is cleared. Only clear it in ice_ptp_wait_for_offsets(), and only after Tx offset configuration has completed successfully. This ensures that new Tx timestamp requests are only accepted after the PHY has properly calibrated the Tx offset.
If ice_start_phy_timer_e82x() fails, do not restore disabled to false. The device is in a state where timestamps cannot succeed properly anyways. A dev_err message is already logged on failure to start the timer at the end of the function.
Renaming the field improves clarity and will better reflect the nature of the flag in a future change that also applies disabling Tx timestamps in software in a following commit.
Log a debug message while offset calibration is still pending, including the specific Tx/Rx error codes to aid debugging stalled calibration. This path is expected on every routine link-up: ov_work is first queued with no delay and the vernier offset cannot be computed until at least one packet has been transmitted, so the first several invocations normally land here. Use dev_dbg() rather than a rate-limited warning to avoid emitting KERN_WARNING on every link-up during normal operation. Log a debug message when calibration completes successfully.
Note that sashiko review has previously complained that leaving the disabled flag set "permanently" disables Tx timestamps if vernier calibration never completes. This is true, but its important to realize that timestamps would still fail regardless of whether the flag is set. Until vernier calibration completes the device will not report valid timestamps regardless. Thus, keeping the calibrating flag set simply prevents new timestamp requests from software while it is known that the hardware will not complete them.
--- drivers/net/ethernet/intel/ice/ice_ptp.c | 37 +++++++++++++++++------- drivers/net/ethernet/intel/ice/ice_ptp.h | 6 ++-- 2 files changed, 29 insertions(+), 14 deletions(-)
drivers/net/ethernet/intel/ice/ice_ptp.c +26 -11
@@ -368,7 +368,7 @@ ice_ptp_is_tx_tracker_up(struct ice_ptp_tx *tx) {lockdep_assert_held (&tx->lock); -return tx->init && !tx->calibrating; +return tx->init && !tx->disabled; }/**
@@ -1134,6 +1134,7 @@ static int ice_ptp_check_tx_fifo(struct ice_ptp_port *port)static void ice_ptp_wait_for_offsets (struct kthread_work *work) {struct ice_ptp_port *port; +unsigned long flags;struct ice_pf *pf;struct ice_hw *hw;int tx_err;
@@ -1154,9 +1155,26 @@ static void ice_ptp_wait_for_offsets(struct kthread_work *work) tx_err =ice_ptp_check_tx_fifo (port);if (!tx_err) tx_err =ice_phy_cfg_tx_offset_e82x (hw, port->port_num); +if (!tx_err) { +/* Tx offset has been configured, re-enable Tx timestamps */ +spin_lock_irqsave (&port->tx.lock, flags); +if (port->tx.disabled) { + port->tx.disabled = false; +dev_dbg (ice_pf_to_dev (pf),"PTP Tx offset valid for port %u, Tx timestamps enabled\n" , + port->port_num); + } +spin_unlock_irqrestore (&port->tx.lock, flags); + } + rx_err =ice_phy_cfg_rx_offset_e82x (hw, port->port_num);if (tx_err || rx_err) { -/* Tx and/or Rx offset not yet configured, try again later */ +/* Tx and/or Rx offset not yet configured, try again later. +* This is expected during normal link-up: the vernier offset +* calibration cannot complete until at least one packet has +* been transmitted, so the first retries routinely land here. +*/ +dev_dbg (ice_pf_to_dev (pf),"PTP offset not yet valid for port %u (tx_err=%d rx_err=%d)\n" , + port->port_num, tx_err, rx_err);kthread_queue_delayed_work (pf->ptp.kworker, &port->ov_work,msecs_to_jiffies (100 ));
@@ -1234,11 +1252,9 @@ ice_ptp_port_phy_restart(struct ice_ptp_port *ptp_port)/* Start the PHY timer in Vernier mode */ kthread_cancel_delayed_work_sync (&ptp_port->ov_work); -/* temporarily disable Tx timestamps while calibrating -* PHY offset -*/ +/* Disable Tx timestamps until PHY calibration completes */ spin_lock_irqsave (&ptp_port->tx.lock, flags); - ptp_port->tx.calibrating = true; + ptp_port->tx.disabled = true;spin_unlock_irqrestore (&ptp_port->tx.lock, flags); ptp_port->tx_fifo_busy_cnt =0 ;
@@ -1247,11 +1263,10 @@ ice_ptp_port_phy_restart(struct ice_ptp_port *ptp_port)if (err)break ; -/* Enable Tx timestamps right away */ -spin_lock_irqsave (&ptp_port->tx.lock, flags); - ptp_port->tx.calibrating = false; -spin_unlock_irqrestore (&ptp_port->tx.lock, flags); - +/* Do not clear disabled flag here. Tx timestamp requests +* remain disabled until ice_ptp_wait_for_offsets() has +* verified that the Tx offset calibration has completed. +*/ kthread_queue_delayed_work (pf->ptp.kworker, &ptp_port->ov_work,0 );break ;
drivers/net/ethernet/intel/ice/ice_ptp.h +3 -3
@@ -104,8 +104,8 @@ enum ice_tx_tstamp_work {* @offset: offset into timestamp block to get the real index * @len: length of the tstamps and in_use fields. * @init: if true, the tracker is initialized; -* @calibrating: if true, the PHY is calibrating the Tx offset. During this -* window, timestamps are temporarily disabled. +* @disabled: set to true when new Tx timestamp requests are disabled, such as +* while the PHY Tx offset configuration has not yet completed. * @has_ready_bitmap: if true, the hardware has a valid Tx timestamp ready * bitmap register. If false, fall back to verifying new * timestamp values against previously cached copy.
@@ -120,7 +120,7 @@ struct ice_ptp_tx {u8 offset;u8 len; u8 init : 1; - u8 calibrating : 1; + u8 disabled : 1; u8 has_ready_bitmap : 1;s8 last_ll_ts_idx_read; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2052/2151 bridge: No DEV_PATH_BR_VLAN_UNTAG_HW for dsa foreign
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Woudstra <[email protected]>
[ Upstream commit 96450df197bda7de927b51372c13f1002d0e76e3 ]
In network setup as below:
fastpath bypass
.----------------------------------------.
/ \
| IP - forwarding |
| / \ v
| / wan ...
| /
| |
| |
| brlan.1
| |
| +-------------------------------+
| | vlan 1 |
| | |
| | brlan (vlan-filtering) |
| | +---------------+
| | | DSA-SWITCH |
| | vlan 1 | |
| | to | |
| | untagged 1 vlan 1 |
| +---------------+---------------+
. / \
----->wlan1 lan0
. .
. ^
^ vlan 1 tagged packetsuntagged packets
br_vlan_fill_forward_path_mode() sets DEV_PATH_BR_VLAN_UNTAG_HW when filling in from brlan.1 towards wlan1. But it should be set to DEV_PATH_BR_VLAN_UNTAG in this case. Using BR_VLFLAG_ADDED_BY_SWITCHDEV is not correct. The dsa switchdev adds it as a foreign port.
The same problem for all foreignly added dsa vlans on the bridge.
First add the vlan, trying only native devices.
If this fails, we know this may be a vlan from a foreign device.
Use BR_VLFLAG_TAGGING_BY_SWITCHDEV to make sure DEV_PATH_BR_VLAN_UNTAG_HW is set only when there if no foreign device involved.
Stable-dep-of: fcc00b15cb21 ("net: bridge: netlink: do not clear the vlan info dump error")
--- include/net/switchdev.h | 1 + net/bridge/br_private.h | 10 ++++++++++ net/bridge/br_switchdev.c | 15 +++++++++++++++ net/bridge/br_vlan.c | 7 ++++++- net/switchdev/switchdev.c | 2 +- 5 files changed, 33 insertions(+), 2 deletions(-)
include/net/switchdev.h +1 -0
@@ -15,6 +15,7 @@#define SWITCHDEV_F_NO_RECURSE BIT(0)#define SWITCHDEV_F_SKIP_EOPNOTSUPP BIT(1)#define SWITCHDEV_F_DEFER BIT(2) +#define SWITCHDEV_F_NO_FOREIGN BIT(3)enum switchdev_attr_id {SWITCHDEV_ATTR_ID_UNDEFINED ,
net/bridge/br_private.h +10 -0
@@ -182,6 +182,7 @@ enum {BR_VLFLAG_MCAST_ENABLED =BIT (2 ),BR_VLFLAG_GLOBAL_MCAST_ENABLED =BIT (3 ),BR_VLFLAG_NEIGH_SUPPRESS_ENABLED =BIT (4 ), + BR_VLFLAG_TAGGING_BY_SWITCHDEV = BIT(5), };/**
@@ -2231,6 +2232,8 @@ void br_switchdev_mdb_notify(struct net_device *dev, int type);int br_switchdev_port_vlan_add (struct net_device *dev,u16 vid,u16 flags,bool changed,struct netlink_ext_ack *extack); +int br_switchdev_port_vlan_no_foreign_add (struct net_device *dev,u16 vid,u16 flags, +bool changed,struct netlink_ext_ack *extack);int br_switchdev_port_vlan_del (struct net_device *dev,u16 vid);void br_switchdev_init (struct net_bridge *br);
@@ -2314,6 +2317,13 @@ static inline int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid,return -EOPNOTSUPP ; } +static inline int br_switchdev_port_vlan_no_foreign_add (struct net_device *dev,u16 vid, +u16 flags,bool changed, +struct netlink_ext_ack *extack) +{ +return -EOPNOTSUPP ; +} +static inline int br_switchdev_port_vlan_del (struct net_device *dev,u16 vid) {return -EOPNOTSUPP ;
net/bridge/br_switchdev.c +15 -0
@@ -189,6 +189,21 @@ int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags,return switchdev_port_obj_add (dev, &v.obj, extack); } +int br_switchdev_port_vlan_no_foreign_add (struct net_device *dev,u16 vid,u16 flags, +bool changed,struct netlink_ext_ack *extack) +{ +struct switchdev_obj_port_vlan v = { + .obj.orig_dev = dev, + .obj.id =SWITCHDEV_OBJ_ID_PORT_VLAN , + .obj.flags =SWITCHDEV_F_NO_FOREIGN , + .flags = flags, + .vid = vid, + .changed = changed, + }; + +return switchdev_port_obj_add (dev, &v.obj, extack); +} +int br_switchdev_port_vlan_del (struct net_device *dev,u16 vid) {struct switchdev_obj_port_vlan v = {
net/bridge/br_vlan.c +6 -1
@@ -109,6 +109,11 @@ static int __vlan_vid_add(struct net_device *dev, struct net_bridge *br,/* Try switchdev op first. In case it is not supported, fallback to * 8021q add. */ + err =br_switchdev_port_vlan_no_foreign_add (dev, v->vid, flags, false, extack); +if (err != -EOPNOTSUPP ) { + v->priv_flags |=BR_VLFLAG_ADDED_BY_SWITCHDEV |BR_VLFLAG_TAGGING_BY_SWITCHDEV ; +return err; + } err =br_switchdev_port_vlan_add (dev, v->vid, flags, false, extack);if (err == -EOPNOTSUPP )return vlan_vid_add (dev, br->vlan_proto, v->vid);
@@ -1491,7 +1496,7 @@ int br_vlan_fill_forward_path_mode(struct net_bridge *br,if (path->bridge.vlan_mode ==DEV_PATH_BR_VLAN_TAG ) path->bridge.vlan_mode =DEV_PATH_BR_VLAN_KEEP ; -else if (v->priv_flags &BR_VLFLAG_ADDED_BY_SWITCHDEV ) +else if (v->priv_flags &BR_VLFLAG_TAGGING_BY_SWITCHDEV ) path->bridge.vlan_mode =DEV_PATH_BR_VLAN_UNTAG_HW ;else path->bridge.vlan_mode =DEV_PATH_BR_VLAN_UNTAG ;
net/switchdev/switchdev.c +1 -1
@@ -760,7 +760,7 @@ static int __switchdev_handle_port_obj_add(struct net_device *dev,/* Event is neither on a bridge nor a LAG. Check whether it is on an * interface that is in a bridge with us. */ -if (!foreign_dev_check_cb) +if (!foreign_dev_check_cb || port_obj_info->obj->flags &SWITCHDEV_F_NO_FOREIGN )return err; br =netdev_master_upper_dev_get (dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2053/2151 bridge: Add internal flags for neigh_forward_grat
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Danielle Ratson <[email protected]>
[ Upstream commit 3a28ccb9dd47d1b6f64c64a94c958a968299aa1d ]
Add internal flags for the neigh_forward_grat feature:
- BR_NEIGH_FORWARD_GRAT: Port-level flag
- BR_VLFLAG_NEIGH_FORWARD_GRAT_ENABLED: Per-VLAN flag
These will be used to control whether gratuitous ARP and unsolicited NA packets are forwarded when neighbor suppression is enabled.
Stable-dep-of: fcc00b15cb21 ("net: bridge: netlink: do not clear the vlan info dump error")
--- include/linux/if_bridge.h | 1 + net/bridge/br_private.h | 1 + 2 files changed, 2 insertions(+)
include/linux/if_bridge.h +1 -0
@@ -61,6 +61,7 @@ struct br_ip_list {#define BR_PORT_LOCKED BIT(21)#define BR_PORT_MAB BIT(22)#define BR_NEIGH_VLAN_SUPPRESS BIT(23) +#define BR_NEIGH_FORWARD_GRAT BIT(24)#define BR_DEFAULT_AGEING_TIME (300 * HZ)
net/bridge/br_private.h +1 -0
@@ -183,6 +183,7 @@ enum {BR_VLFLAG_GLOBAL_MCAST_ENABLED =BIT (3 ),BR_VLFLAG_NEIGH_SUPPRESS_ENABLED =BIT (4 ),BR_VLFLAG_TAGGING_BY_SWITCHDEV =BIT (5 ), + BR_VLFLAG_NEIGH_FORWARD_GRAT_ENABLED = BIT(6), };/**
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2054/2151 bridge: add bridge_flags_bit enum
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 87020def2529ec26fc9077e889fa1c34f53f1f83 ]
We want to use atomic operations for lockless p->flags changes and reads.
Add definitions for bits in addition of masks so that we can use test_bit(), clear_bit() and set_bit() in subsequent patches.
Stable-dep-of: fcc00b15cb21 ("net: bridge: netlink: do not clear the vlan info dump error")
--- include/linux/if_bridge.h | 78 ++++++++++++++++++++++++++------------- 1 file changed, 53 insertions(+), 25 deletions(-)
include/linux/if_bridge.h +53 -25
@@ -36,32 +36,60 @@ struct br_ip_list {struct br_ip addr; }; -#define BR_HAIRPIN_MODE BIT(0) -#define BR_BPDU_GUARD BIT(1) -#define BR_ROOT_BLOCK BIT(2) -#define BR_MULTICAST_FAST_LEAVE BIT(3) -#define BR_ADMIN_COST BIT(4) -#define BR_LEARNING BIT(5) -#define BR_FLOOD BIT(6) +enum bridge_flags_bit { +BR_HAIRPIN_MODE_BIT , +BR_BPDU_GUARD_BIT , +BR_ROOT_BLOCK_BIT , +BR_MULTICAST_FAST_LEAVE_BIT , +BR_ADMIN_COST_BIT , +BR_LEARNING_BIT , +BR_FLOOD_BIT , +BR_PROMISC_BIT , +BR_PROXYARP_BIT , +BR_LEARNING_SYNC_BIT , +BR_PROXYARP_WIFI_BIT , +BR_MCAST_FLOOD_BIT , +BR_MULTICAST_TO_UNICAST_BIT , +BR_VLAN_TUNNEL_BIT , +BR_BCAST_FLOOD_BIT , +BR_NEIGH_SUPPRESS_BIT , +BR_ISOLATED_BIT , +BR_MRP_AWARE_BIT , +BR_MRP_LOST_CONT_BIT , +BR_MRP_LOST_IN_CONT_BIT , +BR_TX_FWD_OFFLOAD_BIT , +BR_PORT_LOCKED_BIT , +BR_PORT_MAB_BIT , +BR_NEIGH_VLAN_SUPPRESS_BIT , +BR_NEIGH_FORWARD_GRAT_BIT , +}; + +#define BR_HAIRPIN_MODE BIT(BR_HAIRPIN_MODE_BIT) +#define BR_BPDU_GUARD BIT(BR_BPDU_GUARD_BIT) +#define BR_ROOT_BLOCK BIT(BR_ROOT_BLOCK_BIT) +#define BR_MULTICAST_FAST_LEAVE BIT(BR_MULTICAST_FAST_LEAVE_BIT) +#define BR_ADMIN_COST BIT(BR_ADMIN_COST_BIT) +#define BR_LEARNING BIT(BR_LEARNING_BIT) +#define BR_FLOOD BIT(BR_FLOOD_BIT)#define BR_AUTO_MASK (BR_FLOOD | BR_LEARNING) -#define BR_PROMISC BIT(7) -#define BR_PROXYARP BIT(8) -#define BR_LEARNING_SYNC BIT(9) -#define BR_PROXYARP_WIFI BIT(10) -#define BR_MCAST_FLOOD BIT(11) -#define BR_MULTICAST_TO_UNICAST BIT(12) -#define BR_VLAN_TUNNEL BIT(13) -#define BR_BCAST_FLOOD BIT(14) -#define BR_NEIGH_SUPPRESS BIT(15) -#define BR_ISOLATED BIT(16) -#define BR_MRP_AWARE BIT(17) -#define BR_MRP_LOST_CONT BIT(18) -#define BR_MRP_LOST_IN_CONT BIT(19) -#define BR_TX_FWD_OFFLOAD BIT(20) -#define BR_PORT_LOCKED BIT(21) -#define BR_PORT_MAB BIT(22) -#define BR_NEIGH_VLAN_SUPPRESS BIT(23) -#define BR_NEIGH_FORWARD_GRAT BIT(24) +#define BR_PROMISC BIT(BR_PROMISC_BIT) +#define BR_PROXYARP BIT(BR_PROXYARP_BIT) +#define BR_LEARNING_SYNC BIT(BR_LEARNING_SYNC_BIT) +#define BR_PROXYARP_WIFI BIT(BR_PROXYARP_WIFI_BIT) +#define BR_MCAST_FLOOD BIT(BR_MCAST_FLOOD_BIT) +#define BR_MULTICAST_TO_UNICAST BIT(BR_MULTICAST_TO_UNICAST_BIT) +#define BR_VLAN_TUNNEL BIT(BR_VLAN_TUNNEL_BIT) +#define BR_BCAST_FLOOD BIT(BR_BCAST_FLOOD_BIT) +#define BR_NEIGH_SUPPRESS BIT(BR_NEIGH_SUPPRESS_BIT) +#define BR_ISOLATED BIT(BR_ISOLATED_BIT) +#define BR_MRP_AWARE BIT(BR_MRP_AWARE_BIT) +#define BR_MRP_LOST_CONT BIT(BR_MRP_LOST_CONT_BIT) +#define BR_MRP_LOST_IN_CONT BIT(BR_MRP_LOST_IN_CONT_BIT) +#define BR_TX_FWD_OFFLOAD BIT(BR_TX_FWD_OFFLOAD_BIT) +#define BR_PORT_LOCKED BIT(BR_PORT_LOCKED_BIT) +#define BR_PORT_MAB BIT(BR_PORT_MAB_BIT) +#define BR_NEIGH_VLAN_SUPPRESS BIT(BR_NEIGH_VLAN_SUPPRESS_BIT) +#define BR_NEIGH_FORWARD_GRAT BIT(BR_NEIGH_FORWARD_GRAT_BIT)#define BR_DEFAULT_AGEING_TIME (300 * HZ)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2055/2151 net: bridge: use atomic ops to read/change p->flags (III)
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit f76ae12b6ba3530590e151a18dca51d90c5d81d4 ]
Use test_bit(), clear_bit(), set_bit() in:
net/bridge/br_multicast.c
net/bridge/br_netlink.c
net/bridge/br_stp.c
net/bridge/br_stp_bpdu.c
net/bridge/br_switchdev.c
net/bridge/br_vlan_options.c
Stable-dep-of: fcc00b15cb21 ("net: bridge: netlink: do not clear the vlan info dump error")
--- net/bridge/br_multicast.c | 5 +++-- net/bridge/br_netlink.c | 2 +- net/bridge/br_stp.c | 4 ++-- net/bridge/br_stp_bpdu.c | 2 +- net/bridge/br_switchdev.c | 8 ++++---- net/bridge/br_vlan_options.c | 2 +- 6 files changed, 12 insertions(+), 11 deletions(-)
net/bridge/br_multicast.c +3 -2
@@ -285,7 +285,7 @@ static bool br_port_group_equal(struct net_bridge_port_group *p,if (p->key.port != port)return false; -if (!(port->flags &BR_MULTICAST_TO_UNICAST )) +if (!test_bit (BR_MULTICAST_TO_UNICAST_BIT , &port->flags))return true;return ether_addr_equal (src, p->eth_addr);
@@ -3706,7 +3706,8 @@ br_multicast_leave_group(struct net_bridge_mcast *brmctx,if (!mp) goto out; -if (pmctx && (pmctx->port->flags &BR_MULTICAST_FAST_LEAVE )) { +if (pmctx && +test_bit (BR_MULTICAST_FAST_LEAVE_BIT , &pmctx->port->flags)) {struct net_bridge_port_group __rcu **pp; for (pp = &mp->ports;
net/bridge/br_netlink.c +1 -1
@@ -534,7 +534,7 @@ static int br_fill_ifinfo(struct sk_buff *skb,else err =br_fill_ifvlaninfo (skb, vg); -if (port && (port->flags &BR_VLAN_TUNNEL )) +if (port &&test_bit (BR_VLAN_TUNNEL_BIT , &port->flags)) err =br_fill_vlan_tunnel_info (skb, vg);rcu_read_unlock ();if (err)
net/bridge/br_stp.c +2 -2
@@ -39,7 +39,7 @@ void br_set_state(struct net_bridge_port *p, unsigned int state)/* Don't change the state of the ports if they are driven by a different * protocol. */ -if (p->flags &BR_MRP_AWARE ) +if (test_bit (BR_MRP_AWARE_BIT , &p->flags))return ; p->state = state;
@@ -173,7 +173,7 @@ static void br_root_selection(struct net_bridge *br)if (!br_should_become_root_port (p, root_port))continue ; -if (p->flags &BR_ROOT_BLOCK ) +if (test_bit (BR_ROOT_BLOCK_BIT , &p->flags))br_root_port_block (br, p);else root_port = p->port_no;
net/bridge/br_stp_bpdu.c +1 -1
@@ -181,7 +181,7 @@ void br_stp_rcv(const struct stp_proto *proto, struct sk_buff *skb,if (!ether_addr_equal (eth_hdr (skb)->h_dest, br->group_addr)) goto out; -if (p->flags &BR_BPDU_GUARD ) { +if (test_bit (BR_BPDU_GUARD_BIT , &p->flags)) {br_notice (br,"BPDU received on blocked port %u(%s)\n" , (unsigned int ) p->port_no, p->dev->name);br_stp_disable_port (p);
net/bridge/br_switchdev.c +4 -4
@@ -20,7 +20,7 @@ static bool nbp_switchdev_can_offload_tx_fwd(const struct net_bridge_port *p,if (br_multicast_igmp_type (skb))return false; -return (p->flags &BR_TX_FWD_OFFLOAD ) && +return test_bit (BR_TX_FWD_OFFLOAD_BIT , &p->flags) && (p->hwdom !=BR_INPUT_SKB_CB (skb)->src_hwdom); }
@@ -287,7 +287,7 @@ static int nbp_switchdev_add(struct net_bridge_port *p,return err;if (tx_fwd_offload) { - p->flags |=BR_TX_FWD_OFFLOAD ; +set_bit (BR_TX_FWD_OFFLOAD_BIT , &p->flags);static_branch_inc (&br_switchdev_tx_fwd_offload); }
@@ -307,8 +307,8 @@ static void nbp_switchdev_del(struct net_bridge_port *p)if (p->hwdom)nbp_switchdev_hwdom_put (p); -if (p->flags &BR_TX_FWD_OFFLOAD ) { - p->flags &= ~BR_TX_FWD_OFFLOAD ; +if (test_bit (BR_TX_FWD_OFFLOAD_BIT , &p->flags)) { +clear_bit (BR_TX_FWD_OFFLOAD_BIT , &p->flags);static_branch_dec (&br_switchdev_tx_fwd_offload); } }
net/bridge/br_vlan_options.c +1 -1
@@ -148,7 +148,7 @@ static int br_vlan_modify_tunnel(const struct net_bridge_port *p,NL_SET_ERR_MSG_MOD (extack,"Can't modify tunnel mapping of non-port vlans" );return -EINVAL ; } -if (!(p->flags &BR_VLAN_TUNNEL )) { +if (!test_bit (BR_VLAN_TUNNEL_BIT , &p->flags)) {NL_SET_ERR_MSG_MOD (extack,"Port doesn't have tunnel flag set" );return -EINVAL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2056/2151 net: bridge: netlink: do not clear the vlan info dump error
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linkui Xiao <[email protected]>
[ Upstream commit fcc00b15cb21a6de76826e5012b2c758505f5e65 ]
br_fill_ifinfo() assigns the result of br_fill_vlan_tunnel_info() over the result of br_fill_ifvlaninfo() or br_fill_ifvlaninfo_compressed() instead of only running the second helper when the first one succeeded.
When the vlan information no longer fits in the skb but the port has no vlan mapped to a tunnel dst, br_fill_vlan_tunnel_info() walks the vlan list and returns 0 without touching the skb. The -EMSGSIZE is lost, br_fill_ifinfo() completes a message whose IFLA_AF_SPEC is truncated, and the dump carries on to the next interface instead of stopping, so userspace silently sees an incomplete vlan list.
Only fill the tunnel information when the vlan information was filled successfully.
This was flagged as a pre-existing issue in the Sashiko review of the net-next series, which noted that the VLAN fill result is overwritten before it is tested (see the Link tag below). Not triggered or tested.
--- net/bridge/br_netlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/bridge/br_netlink.c +1 -1
@@ -534,7 +534,7 @@ static int br_fill_ifinfo(struct sk_buff *skb,else err =br_fill_ifvlaninfo (skb, vg); -if (port &&test_bit (BR_VLAN_TUNNEL_BIT , &port->flags)) +if (!err && port &&test_bit (BR_VLAN_TUNNEL_BIT , &port->flags)) err =br_fill_vlan_tunnel_info (skb, vg);rcu_read_unlock ();if (err)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2057/2151 net/mlx5: Only set num_doorbells on a fully initialized SF
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cosmin Ratiu <[email protected]>
[ Upstream commit fa503935c2d6603856dafff0a0852631ab6e9503 ]
The validation for the num_doorbells devlink param rejects values greater than num_channels. For lightweight SFs, this ends up accessing a NULL priv->eq_table, leading to a crash.
Fix that by rejecting setting num_doorbells on uninitialized SFs.
--- drivers/net/ethernet/mellanox/mlx5/core/devlink.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/devlink.c +6 -0
@@ -541,6 +541,12 @@ static int mlx5_devlink_num_doorbells_validate(struct devlink *devlink, u32 id,u32 val32 = val.vu32;u32 max_num_channels; +if (mlx5_dev_is_lightweight (mdev)) { +NL_SET_ERR_MSG_MOD (extack, +"Setting num_doorbells requires full device initialization; reload the device first" ); +return -EOPNOTSUPP ; + } + max_num_channels =mlx5e_get_max_num_channels (mdev);if (val32 > max_num_channels) { NL_SET_ERR_MSG_FMT_MOD(extack,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2058/2151 net: mctp: free reassembly head skb when key_add fails on SOM
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joas Antonio dos Santos <[email protected]>
[ Upstream commit d2bfe74a8fe219a86b86c1f126e1d722a5001790 ]
When a start-of-message fragment creates a new reassembly key on the broadcast/bind path, mctp_frag_queue() stores the skb as key->reasm_head before the key is made observable with mctp_key_add().
If mctp_key_add() fails (a race with another SOM packet for the same source/dest/tag, or the receiving socket going away), the error path only drops the key reference via mctp_key_unref(). The final key destructor frees the key itself but not key->reasm_head, and since the key was never added to any list, neither the expiry worker nor socket teardown can reach it to release the queued fragment. The skb is leaked.
Free key->reasm_head on the key_add failure path before releasing the key. Other teardown paths (__mctp_key_done_in(), EOM delivery) already clear reasm_head before the final unref, so this only affects the failure path.
--- net/mctp/route.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
net/mctp/route.c +9 -1
@@ -552,8 +552,16 @@ static int mctp_dst_input(struct mctp_dst *dst, struct sk_buff *skb)* can do is drop. */ rc =mctp_key_add (key, msk); -if (!rc) +if (!rc) {trace_mctp_key_acquire (key); + }else { +/* key_add failed: the key is not observable by +* any cleanup path, so free the fragment we +* just queued on it to avoid leaking the skb. +*/ +kfree_skb (key->reasm_head); + key->reasm_head =NULL ; + }/* we don't need to release key->lock on exit, so * clean up here and suppress the unlock via
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2059/2151 rtc: s35390a: Add missing newline to dev_err
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Markus Probst <[email protected]>
[ Upstream commit a27b25bb9b422c8468cb6965b2d72b7b64187fd2 ]
--- drivers/rtc/rtc-s35390a.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/rtc/rtc-s35390a.c +1 -1
@@ -467,7 +467,7 @@ static int s35390a_probe(struct i2c_client *client) buf =0 ; err =s35390a_set_reg (s35390a,S35390A_CMD_STATUS2 , &buf,1 );if (err <0 ) { -dev_err (dev,"error disabling alarm" ); +dev_err (dev,"error disabling alarm\n" );return err; } }else {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2060/2151 rtc: s35390a: Fix alarm not disabling
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Markus Probst <[email protected]>
[ Upstream commit d93f29e41089bbb14637289fe77bdd72b71e9ac5 ]
Implement alarm_irq_enable callback.
--- drivers/rtc/rtc-s35390a.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-)
drivers/rtc/rtc-s35390a.c +24 -5
@@ -269,6 +269,24 @@ static int s35390a_rtc_read_time(struct device *dev, struct rtc_time *tm)return 0 ; } +static int s35390a_rtc_alarm_irq_enable (struct device *dev,unsigned int enabled) +{ +struct s35390a *s35390a =dev_get_drvdata (dev); +u8 sts; +int err; + +if (enabled) + sts =S35390A_INT2_MODE_ALARM ; +else + sts =S35390A_INT2_MODE_NOINTR ; + + err =s35390a_set_reg (s35390a,S35390A_CMD_STATUS2 , &sts,sizeof (sts)); +if (err <0 ) +return err; + +return 0 ; +} +static int s35390a_rtc_set_alarm (struct device *dev,struct rtc_wkalrm *alm) {struct i2c_client *client =to_i2c_client (dev);
@@ -409,11 +427,12 @@ static int s35390a_rtc_ioctl(struct device *dev, unsigned int cmd, }static const struct rtc_class_ops s35390a_rtc_ops = { - .read_time = s35390a_rtc_read_time, - .set_time = s35390a_rtc_set_time, - .set_alarm = s35390a_rtc_set_alarm, - .read_alarm = s35390a_rtc_read_alarm, - .ioctl = s35390a_rtc_ioctl, + .read_time = s35390a_rtc_read_time, + .set_time = s35390a_rtc_set_time, + .set_alarm = s35390a_rtc_set_alarm, + .read_alarm = s35390a_rtc_read_alarm, + .alarm_irq_enable = s35390a_rtc_alarm_irq_enable, + .ioctl = s35390a_rtc_ioctl, };static int s35390a_probe (struct i2c_client *client)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2061/2151 rtc: s35390a: use u8 instead of char for register buffer
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nick Huang <[email protected]>
[ Upstream commit 73c4638a2864e69ff2251080ce874d360fd13056 ]
The register buffer in s35390a_get_reg() was previously defined as char *buf. This is not ideal since register data represents raw binary values rather than textual data.
Switch the type to u8 *buf to better reflect its intended usage and to avoid potential issues with sign extension when handling register values on platforms where char is signed by default.
This change improves type safety and makes the code consistent with other RTC drivers that operate on raw register data.
Stable-dep-of: 6199051016cd ("rtc: s35390a: Read 24-hour mode on access")
--- drivers/rtc/rtc-s35390a.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/rtc/rtc-s35390a.c +9 -9
@@ -66,7 +66,7 @@ struct s35390a {int twentyfourhour; }; -static int s35390a_set_reg (struct s35390a *s35390a,int reg,char *buf,int len) +static int s35390a_set_reg (struct s35390a *s35390a,int reg,u8 *buf,int len) {struct i2c_client *client = s35390a->client[reg];struct i2c_msg msg[] = {
@@ -83,7 +83,7 @@ static int s35390a_set_reg(struct s35390a *s35390a, int reg, char *buf, int len)return 0 ; } -static int s35390a_get_reg (struct s35390a *s35390a,int reg,char *buf,int len) +static int s35390a_get_reg (struct s35390a *s35390a,int reg,u8 *buf,int len) {struct i2c_client *client = s35390a->client[reg];struct i2c_msg msg[] = {
@@ -168,7 +168,7 @@ static int s35390a_read_status(struct s35390a *s35390a, char *status1)static int s35390a_disable_test_mode (struct s35390a *s35390a) { -char buf[1 ]; +u8 buf[1 ];if (s35390a_get_reg (s35390a,S35390A_CMD_STATUS2 , buf,sizeof (buf)) <0 )return -EIO ;
@@ -210,7 +210,7 @@ static int s35390a_rtc_set_time(struct device *dev, struct rtc_time *tm)struct i2c_client *client =to_i2c_client (dev);struct s35390a *s35390a =i2c_get_clientdata (client);int i; -char buf[7 ], status; +u8 buf[7 ], status; dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d mday=%d, " "mon=%d, year=%d, wday=%d\n", __func__, tm->tm_sec,
@@ -239,7 +239,7 @@ static int s35390a_rtc_read_time(struct device *dev, struct rtc_time *tm) {struct i2c_client *client =to_i2c_client (dev);struct s35390a *s35390a =i2c_get_clientdata (client); -char buf[7 ], status; +u8 buf[7 ], status;int i, err;if (s35390a_read_status (s35390a, &status) ==1 )
@@ -291,7 +291,7 @@ static int s35390a_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm) {struct i2c_client *client =to_i2c_client (dev);struct s35390a *s35390a =i2c_get_clientdata (client); -char buf[3 ], sts =0 ; +u8 buf[3 ], sts =0 ;int err, i; dev_dbg(&client->dev, "%s: alm is secs=%d, mins=%d, hours=%d mday=%d, "\
@@ -344,7 +344,7 @@ static int s35390a_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm) {struct i2c_client *client =to_i2c_client (dev);struct s35390a *s35390a =i2c_get_clientdata (client); -char buf[3 ], sts; +u8 buf[3 ], sts;int i, err; err =s35390a_get_reg (s35390a,S35390A_CMD_STATUS2 , &sts,sizeof (sts));
@@ -401,7 +401,7 @@ static int s35390a_rtc_ioctl(struct device *dev, unsigned int cmd, {struct i2c_client *client =to_i2c_client (dev);struct s35390a *s35390a =i2c_get_clientdata (client); -char sts; +u8 sts;int err;switch (cmd) {
@@ -441,7 +441,7 @@ static int s35390a_probe(struct i2c_client *client)unsigned int i;struct s35390a *s35390a;struct rtc_device *rtc; -char buf, status1; +u8 buf, status1;struct device *dev = &client->dev;if (!i2c_check_functionality (client->adapter,I2C_FUNC_I2C ))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2062/2151 rtc: s35390a: fix typo in comment
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexandre Belloni <[email protected]>
[ Upstream commit 50ccdc31010ed623e68e496aebd4b1d3d8430664 ]
Fix trivial typo
Stable-dep-of: 6199051016cd ("rtc: s35390a: Read 24-hour mode on access")
--- drivers/rtc/rtc-s35390a.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/rtc/rtc-s35390a.c +1 -1
@@ -314,7 +314,7 @@ static int s35390a_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)else sts =S35390A_INT2_MODE_NOINTR ; -/* set interupt mode*/ +/* set interrupt mode*/ err =s35390a_set_reg (s35390a,S35390A_CMD_STATUS2 , &sts,sizeof (sts));if (err <0 )return err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2063/2151 rtc: s35390a: Read 24-hour mode on access
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Markus Probst <[email protected]>
[ Upstream commit 6199051016cddba920b6023a44199c5221352c44 ]
Instead of reading if the 24-hour mode is used on probe once, read it on access. This makes it impossible for the mode to be out of sync and fixes time corruption if resetting the chip while in 12-hour mode, as s35390a_init did not update the cached value.
--- drivers/rtc/rtc-s35390a.c | 78 +++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 36 deletions(-)
drivers/rtc/rtc-s35390a.c +42 -36
@@ -63,7 +63,6 @@ MODULE_DEVICE_TABLE(of, s35390a_of_match);struct s35390a {struct i2c_client *client[8 ]; -int twentyfourhour; };static int s35390a_set_reg (struct s35390a *s35390a,int reg,u8 *buf,int len)
@@ -101,9 +100,8 @@ static int s35390a_get_reg(struct s35390a *s35390a, int reg, u8 *buf, int len)return 0 ; } -static int s35390a_init (struct s35390a *s35390a) +static int s35390a_init (struct s35390a *s35390a,u8 *sts) { -u8 buf;int ret;unsigned initcount =0 ;
@@ -116,17 +114,17 @@ static int s35390a_init(struct s35390a *s35390a)* The 24H bit is kept over reset, so set it already here. */ initialize: - buf =S35390A_FLAG_RESET |S35390A_FLAG_24H ; - ret =s35390a_set_reg (s35390a,S35390A_CMD_STATUS1 , &buf,1 ); + *sts =S35390A_FLAG_RESET |S35390A_FLAG_24H ; + ret =s35390a_set_reg (s35390a,S35390A_CMD_STATUS1 , sts,1 );if (ret <0 )return ret; - ret =s35390a_get_reg (s35390a,S35390A_CMD_STATUS1 , &buf,1 ); + ret =s35390a_get_reg (s35390a,S35390A_CMD_STATUS1 , sts,1 );if (ret <0 )return ret; -if (buf & (S35390A_FLAG_POC |S35390A_FLAG_BLD )) { +if (*sts & (S35390A_FLAG_POC |S35390A_FLAG_BLD )) {/* Try up to five times to reset the chip */ if (initcount <5 ) { ++initcount;
@@ -180,9 +178,9 @@ static int s35390a_disable_test_mode(struct s35390a *s35390a)return s35390a_set_reg (s35390a,S35390A_CMD_STATUS2 , buf,sizeof (buf)); } -static char s35390a_hr2reg (struct s35390a *s35390a,int hour) +static char s35390a_hr2reg (int hour,bool twentyfourhour) { -if (s35390a->twentyfourhour) +if (twentyfourhour)return bin2bcd (hour);if (hour <12 )
@@ -191,11 +189,11 @@ static char s35390a_hr2reg(struct s35390a *s35390a, int hour)return 0x40 |bin2bcd (hour -12 ); } -static int s35390a_reg2hr (struct s35390a *s35390a,char reg) +static int s35390a_reg2hr (char reg,bool twentyfourhour) {unsigned hour; -if (s35390a->twentyfourhour) +if (twentyfourhour)return bcd2bin (reg &0x3f ); hour =bcd2bin (reg &0x3f );
@@ -209,7 +207,7 @@ static int s35390a_rtc_set_time(struct device *dev, struct rtc_time *tm) {struct i2c_client *client =to_i2c_client (dev);struct s35390a *s35390a =i2c_get_clientdata (client); -int i; +int i, err;u8 buf[7 ], status; dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d mday=%d, "
@@ -217,14 +215,18 @@ static int s35390a_rtc_set_time(struct device *dev, struct rtc_time *tm) tm->tm_min, tm->tm_hour, tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); -if (s35390a_read_status (s35390a, &status) ==1 ) -s35390a_init (s35390a); + err =s35390a_read_status (s35390a, &status); +if (err ==1 ) + err =s35390a_init (s35390a, &status); + +if (err <0 ) +return err; buf[S35390A_BYTE_YEAR ] =bin2bcd (tm->tm_year -100 ); buf[S35390A_BYTE_MONTH ] =bin2bcd (tm->tm_mon +1 ); buf[S35390A_BYTE_DAY ] =bin2bcd (tm->tm_mday); buf[S35390A_BYTE_WDAY ] =bin2bcd (tm->tm_wday); - buf[S35390A_BYTE_HOURS ] =s35390a_hr2reg (s35390a, tm->tm_hour); + buf[S35390A_BYTE_HOURS ] =s35390a_hr2reg (tm->tm_hour, status &S35390A_FLAG_24H ); buf[S35390A_BYTE_MINS ] =bin2bcd (tm->tm_min); buf[S35390A_BYTE_SECS ] =bin2bcd (tm->tm_sec);
@@ -242,8 +244,11 @@ static int s35390a_rtc_read_time(struct device *dev, struct rtc_time *tm)u8 buf[7 ], status;int i, err; -if (s35390a_read_status (s35390a, &status) ==1 ) + err =s35390a_read_status (s35390a, &status); +if (err ==1 )return -EINVAL ; +if (err <0 ) +return err; err =s35390a_get_reg (s35390a,S35390A_CMD_TIME1 , buf,sizeof (buf));if (err <0 )
@@ -255,7 +260,7 @@ static int s35390a_rtc_read_time(struct device *dev, struct rtc_time *tm) tm->tm_sec =bcd2bin (buf[S35390A_BYTE_SECS ]); tm->tm_min =bcd2bin (buf[S35390A_BYTE_MINS ]); - tm->tm_hour =s35390a_reg2hr (s35390a, buf[S35390A_BYTE_HOURS ]); + tm->tm_hour =s35390a_reg2hr (buf[S35390A_BYTE_HOURS ], status &S35390A_FLAG_24H ); tm->tm_wday =bcd2bin (buf[S35390A_BYTE_WDAY ]); tm->tm_mday =bcd2bin (buf[S35390A_BYTE_DAY ]); tm->tm_mon =bcd2bin (buf[S35390A_BYTE_MONTH ]) -1 ;
@@ -291,7 +296,7 @@ static int s35390a_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm) {struct i2c_client *client =to_i2c_client (dev);struct s35390a *s35390a =i2c_get_clientdata (client); -u8 buf[3 ], sts =0 ; +u8 buf[3 ], status1, status2 =0 ;int err, i; dev_dbg(&client->dev, "%s: alm is secs=%d, mins=%d, hours=%d mday=%d, "\
@@ -300,22 +305,22 @@ static int s35390a_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm) alm->time.tm_mon, alm->time.tm_year, alm->time.tm_wday);/* disable interrupt (which deasserts the irq line) */ - err =s35390a_set_reg (s35390a,S35390A_CMD_STATUS2 , &sts,sizeof (sts)); + err =s35390a_set_reg (s35390a,S35390A_CMD_STATUS2 , &status2,sizeof (status2));if (err <0 )return err;/* clear pending interrupt (in STATUS1 only), if any */ - err =s35390a_get_reg (s35390a,S35390A_CMD_STATUS1 , &sts,sizeof (sts)); + err =s35390a_get_reg (s35390a,S35390A_CMD_STATUS1 , &status1,sizeof (status1));if (err <0 )return err;if (alm->enabled) - sts =S35390A_INT2_MODE_ALARM ; + status2 =S35390A_INT2_MODE_ALARM ;else - sts =S35390A_INT2_MODE_NOINTR ; + status2 =S35390A_INT2_MODE_NOINTR ;/* set interrupt mode*/ - err =s35390a_set_reg (s35390a,S35390A_CMD_STATUS2 , &sts,sizeof (sts)); + err =s35390a_set_reg (s35390a,S35390A_CMD_STATUS2 , &status2,sizeof (status2));if (err <0 )return err;
@@ -324,8 +329,8 @@ static int s35390a_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)else buf[S35390A_ALRM_BYTE_WDAY ] =0 ; - buf[S35390A_ALRM_BYTE_HOURS ] =s35390a_hr2reg (s35390a, - alm->time.tm_hour) |0x80 ; + buf[S35390A_ALRM_BYTE_HOURS ] =s35390a_hr2reg (alm->time.tm_hour, + status1 &S35390A_FLAG_24H ) |0x80 ; buf[S35390A_ALRM_BYTE_MINS ] =bin2bcd (alm->time.tm_min) |0x80 ;if (alm->time.tm_hour >=12 )
@@ -344,14 +349,20 @@ static int s35390a_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm) {struct i2c_client *client =to_i2c_client (dev);struct s35390a *s35390a =i2c_get_clientdata (client); -u8 buf[3 ], sts; +u8 buf[3 ], status1, status2;int i, err; - err =s35390a_get_reg (s35390a,S35390A_CMD_STATUS2 , &sts,sizeof (sts)); + err =s35390a_read_status (s35390a, &status1); +if (err ==1 ) +return -EINVAL ; +if (err <0 ) +return err; + + err =s35390a_get_reg (s35390a,S35390A_CMD_STATUS2 , &status2,sizeof (status2));if (err <0 )return err; -if ((sts &S35390A_INT2_MODE_MASK ) !=S35390A_INT2_MODE_ALARM ) { +if ((status2 &S35390A_INT2_MODE_MASK ) !=S35390A_INT2_MODE_ALARM ) {/* * When the alarm isn't enabled, the register to configure * the alarm time isn't accessible.
@@ -380,8 +391,8 @@ static int s35390a_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm)if (buf[S35390A_ALRM_BYTE_HOURS ] &0x80 ) alm->time.tm_hour = -s35390a_reg2hr (s35390a, - buf[S35390A_ALRM_BYTE_HOURS ] & ~0x80 ); +s35390a_reg2hr (buf[S35390A_ALRM_BYTE_HOURS ] & ~0x80 , + status1 &S35390A_FLAG_24H );if (buf[S35390A_ALRM_BYTE_MINS ] &0x80 ) alm->time.tm_min =bcd2bin (buf[S35390A_ALRM_BYTE_MINS ] & ~0x80 );
@@ -415,7 +426,7 @@ static int s35390a_rtc_ioctl(struct device *dev, unsigned int cmd,break ;case RTC_VL_CLR :/* update flag and clear register */ - err =s35390a_init (s35390a); + err =s35390a_init (s35390a, &sts);if (err <0 )return err;break ;
@@ -476,11 +487,6 @@ static int s35390a_probe(struct i2c_client *client)return err_read; } -if (status1 &S35390A_FLAG_24H ) - s35390a->twentyfourhour =1 ; -else - s35390a->twentyfourhour =0 ; -if (status1 &S35390A_FLAG_INT2 ) {/* disable alarm (and maybe test mode) */ buf =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2064/2151 octeontx2-pf: fix skb use-after-free on ipsec transmit drop
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicolai Buchwitz <[email protected]>
[ Upstream commit 14d01ff1a4952198abae713a4ad428e07819b4aa ]
When an SA is removed while packets for it are still queued, the transmit path frees the packet but reports the queue as busy. The stack then requeues the freed skb, and the DMA mappings leak.
--- drivers/net/ethernet/marvell/octeontx2/nic/cn10k_ipsec.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeontx2/nic/cn10k_ipsec.c +4 -1
@@ -1037,6 +1037,9 @@ bool cn10k_ipsec_transmit(struct otx2_nic *pf, struct netdev_queue *txq,cn10k_cpt_inst_flush (pf, &inst,sizeof (struct cpt_inst_s ));return true; drop: +otx2_dma_unmap_skb_frags (pf, &sq->sg[sq->head]); + sq->sg[sq->head].skb = (u64 )NULL ; +atomic_long_inc (&pf->hw.dev_stats.tx_discards);dev_kfree_skb_any (skb); -return false; +return true; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2065/2151 octeontx2-pf: pass the skb to otx2_dma_unmap_skb_frags()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicolai Buchwitz <[email protected]>
[ Upstream commit 92cb8653970e4efaa7d2c2e2819c6d050b25e462 ]
After a DMA mapping error, the unmap reads an skb pointer that is not set yet. It can be NULL or left over from an earlier packet.
--- .../net/ethernet/marvell/octeontx2/nic/cn10k_ipsec.c | 2 +- .../net/ethernet/marvell/octeontx2/nic/otx2_common.c | 5 ++--- .../net/ethernet/marvell/octeontx2/nic/otx2_common.h | 3 ++- drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c | 10 +++++----- 4 files changed, 10 insertions(+), 10 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/cn10k_ipsec.c +1 -1
@@ -1037,7 +1037,7 @@ bool cn10k_ipsec_transmit(struct otx2_nic *pf, struct netdev_queue *txq,cn10k_cpt_inst_flush (pf, &inst,sizeof (struct cpt_inst_s ));return true; drop: -otx2_dma_unmap_skb_frags (pf, &sq->sg[sq->head]); +otx2_dma_unmap_skb_frags (pf, &sq->sg[sq->head], skb); sq->sg[sq->head].skb = (u64 )NULL ;atomic_long_inc (&pf->hw.dev_stats.tx_discards);dev_kfree_skb_any (skb);
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +2 -3
@@ -2130,13 +2130,12 @@ dma_addr_t otx2_dma_map_skb_frag(struct otx2_nic *pfvf,return otx2_dma_map_page (pfvf, page, offset, *len, dir); } -void otx2_dma_unmap_skb_frags (struct otx2_nic *pfvf,struct sg_list *sg) +void otx2_dma_unmap_skb_frags (struct otx2_nic *pfvf,struct sg_list *sg, +struct sk_buff *skb) {enum dma_data_direction dir =DMA_TO_DEVICE ; -struct sk_buff *skb =NULL ;int seg; - skb = (struct sk_buff *)sg->skb;if (unlikely (xfrm_offload (skb))) dir =DMA_BIDIRECTIONAL ;
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +2 -1
@@ -1199,7 +1199,8 @@ static inline int mcam_entry_cmp(const void *a, const void *b)dma_addr_t otx2_dma_map_skb_frag (struct otx2_nic *pfvf,struct sk_buff *skb,int seg,int *len); -void otx2_dma_unmap_skb_frags (struct otx2_nic *pfvf,struct sg_list *sg); +void otx2_dma_unmap_skb_frags (struct otx2_nic *pfvf,struct sg_list *sg, +struct sk_buff *skb);int otx2_read_free_sqe (struct otx2_nic *pfvf,u16 qidx);void otx2_queue_vf_work (struct mbox *mw,struct workqueue_struct *mbox_wq,int first,int mdevs,u64 intr);
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +5 -5
@@ -160,7 +160,7 @@ static void otx2_snd_pkt_handler(struct otx2_nic *pfvf, *tx_bytes += skb->len; (*tx_pkts)++; -otx2_dma_unmap_skb_frags (pfvf, sg); +otx2_dma_unmap_skb_frags (pfvf, sg, skb);napi_consume_skb (skb, budget); sg->skb = (u64 )NULL ; }
@@ -872,7 +872,7 @@ static int otx2_dma_map_tso_skb(struct otx2_nic *pfvf, }return 0 ; unmap: -otx2_dma_unmap_skb_frags (pfvf, sg); +otx2_dma_unmap_skb_frags (pfvf, sg, skb);return -EINVAL ; }
@@ -1252,7 +1252,7 @@ bool otx2_sq_append_skb(void *dev, struct netdev_queue *txq, ret =otx2_sqe_add_sg (pfvf, sq, skb, num_segs, &offset);if (!ret) { -otx2_dma_unmap_skb_frags (pfvf, &sq->sg[sq->head]); +otx2_dma_unmap_skb_frags (pfvf, &sq->sg[sq->head], skb);return false; }
@@ -1344,7 +1344,7 @@ void otx2_cleanup_tx_cqes(struct otx2_nic *pfvf, struct otx2_cq_queue *cq)if (skb) { tx_bytes += skb->len; tx_pkts++; -otx2_dma_unmap_skb_frags (pfvf, sg); +otx2_dma_unmap_skb_frags (pfvf, sg, skb);dev_kfree_skb_any (skb); sg->skb = (u64 )NULL ; }
@@ -1399,7 +1399,7 @@ void otx2_free_pending_sqe(struct otx2_nic *pfvf)if (skb) { tx_bytes += skb->len; tx_pkts++; -otx2_dma_unmap_skb_frags (pfvf, sg); +otx2_dma_unmap_skb_frags (pfvf, sg, skb);dev_kfree_skb_any (skb); sg->skb = (u64 )NULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2066/2151 fork: Let nobody keep a task that may not come to life
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 5cf0881344cfa0a3b558107741884d8f43269d7b ]
dup_task_struct() sets rcu_users to 2. From then on bpf_task_acquire() hands out references to the new task, which BPF programs see as a trusted pointer long before it is sure to live: in the task_alloc LSM hook and in ops.init_task() of sched_ext.
If copy_process() fails later on, it undoes what it has done and frees the task without a look at the count. A program that has stored its reference in a map is left with a pointer to freed memory:
BUG: KASAN: slab-use-after-free in put_task_struct_rcu_user+0x22/0x90
The program is loaded by the administrator, but any user can make a fork fail, for example at the pids.max of a cgroup.
Honouring the count would not do: the task would stay behind with its mm, files and credentials freed. Leave rcu_users at zero until copy_process() cannot fail any more. bpf_task_acquire() returns NULL until then, which its callers have to be prepared for, and which they get for init_task, whose count has always been zero. The other users of rcu_users deal with tasks that have run.
--- kernel/fork.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
kernel/fork.c +9 -3
@@ -917,10 +917,10 @@ static struct task_struct *dup_task_struct(struct task_struct *orig, int node)dup_user_cpus_ptr (tsk, orig, node);/* -* One for the user space visible state that goes away when reaped. -* One for the scheduler. +* Nobody can keep the task while copy_process() may still fail, which +* frees it no matter what. */ -refcount_set (&tsk->rcu_users,2 ); +refcount_set (&tsk->rcu_users,0 );/* One for the rcu users */ refcount_set (&tsk->usage,1 );#ifdef CONFIG_BLK_DEV_IO_TRACE
@@ -2378,6 +2378,12 @@ __latent_entropy struct task_struct *copy_process(/* No more failure paths after this point. */ +/* +* One for the user space visible state that goes away when reaped. +* One for the scheduler. +*/ +refcount_set (&p->rcu_users,2 ); +/* * Copy seccomp details explicitly here, in case they were changed * before holding sighand lock.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2067/2151 xattr: always invoke cap_convert_nscap() for security.capability writes
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dominik Maier <[email protected]>
[ Upstream commit 0f4a9e682f7fa5becc3af7204606d9bf4780e425 ]
Commit 8db6c34f1dbc ("Introduce v3 namespaced file capabilities") changed cap_inode_setxattr() to return 0 unconditionally for XATTR_NAME_CAPS ("security.capability") and moved capability validation into cap_convert_nscap(), but placed the call inside the "if (size)" block in setxattr(). Commit 7c03e2cda4a5 ("vfs: move cap_convert_nscap() call into vfs_setxattr()") preserved that "size &&" condition in vfs_setxattr():
if (size && strcmp(name, XATTR_NAME_CAPS) == 0) {
error = cap_convert_nscap(idmap, dentry, &value, size);
...
}For security.* extended attributes, xattr_permission() skips inode_permission(MAY_WRITE) and leaves permission checks to the security module, while cap_inode_setxattr() returns 0 for XATTR_NAME_CAPS assuming cap_convert_nscap() has already validated the write. Because __vfs_setxattr() treats size == 0 as an empty attribute write (setting value = "") rather than a removal, calling setxattr(2) on "security.capability" with size == 0 bypasses cap_convert_nscap() and allows an unprivileged caller without CAP_SETFCAP or write permission on the target inode to write a 0-byte security.capability xattr (or overwrite an existing one).
When that binary is subsequently executed, get_vfs_caps_from_disk() reads the 0-byte security.capability xattr and fails the
size < sizeof(magic_etc) check with -EINVAL, causing execve(2) to fail with -EINVAL.
Always invoke cap_convert_nscap() when strcmp(name, XATTR_NAME_CAPS) == 0 regardless of size, so that 0-byte writes hit the existing !*ivalue / !validheader() checks in cap_convert_nscap() and are rejected with -EINVAL.
--- fs/xattr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xattr.c +1 -1
@@ -309,7 +309,7 @@ vfs_setxattr(struct mnt_idmap *idmap, struct dentry *dentry,const void *orig_value = value;int error; -if (size &&strcmp (name,XATTR_NAME_CAPS ) ==0 ) { +if (strcmp (name,XATTR_NAME_CAPS ) ==0 ) { error =cap_convert_nscap (idmap, dentry, &value, size);if (error <0 )return error;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2068/2151 selftests/ovl: fix detached layer mountinfo expectations
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amir Goldstein <[email protected]>
[ Upstream commit aefaf9521c999206b7cd2df8435a270ea8b8112b ]
set_layers_via_detached_mount_fds was copied from the attached-fd test and still looks for /tmp paths. Detached open_tree() layers are recorded by d_path() as upperdir=/upper, workdir=/work, and lowerdir+=/ and datadir+=/ for each cloned directory. The test has failed since it was added.
--- .../filesystems/overlayfs/set_layers_via_fds.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
tools/testing/selftests/filesystems/overlayfs/set_layers_via_fds.c +9 -9
@@ -686,23 +686,23 @@ TEST_F(set_layers_via_fds, set_layers_via_detached_mount_fds)while (getline (&line, &len, f_mountinfo) !=-1 ) {char *haystack = line; -if (strstr (haystack,"workdir=/tmp/w" )) +if (strstr (haystack,"workdir=/work" )) layers_found[0 ] = true; -if (strstr (haystack,"upperdir=/tmp/u" )) +if (strstr (haystack,"upperdir=/upper" )) layers_found[1 ] = true; -if (strstr (haystack,"lowerdir+=/tmp/l1" )) +if (strstr (haystack,"lowerdir+=/" )) layers_found[2 ] = true; -if (strstr (haystack,"lowerdir+=/tmp/l2" )) +if (strstr (haystack,"lowerdir+=/" )) layers_found[3 ] = true; -if (strstr (haystack,"lowerdir+=/tmp/l3" )) +if (strstr (haystack,"lowerdir+=/" )) layers_found[4 ] = true; -if (strstr (haystack,"lowerdir+=/tmp/l4" )) +if (strstr (haystack,"lowerdir+=/" )) layers_found[5 ] = true; -if (strstr (haystack,"datadir+=/tmp/d1" )) +if (strstr (haystack,"datadir+=/" )) layers_found[6 ] = true; -if (strstr (haystack,"datadir+=/tmp/d2" )) +if (strstr (haystack,"datadir+=/" )) layers_found[7 ] = true; -if (strstr (haystack,"datadir+=/tmp/d3" )) +if (strstr (haystack,"datadir+=/" )) layers_found[8 ] = true; }free (line);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2069/2151 block: fix use-after-free of the disk in sync_bdevs()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit cebb1c2331c2af1b7f1c822ac672a7f77b54bd90 ]
sync_bdevs() holds a reference to the bdev inode while it takes bd_disk->open_mutex. For a partition the inode doesn't keep the gendisk alive, the device reference does: part_release() drops the disk as soon as the last reference to the partition device is gone. A sync(2) racing with the last close of a partition of an already deleted disk locks a freed open_mutex.
Take a device reference before touching the disk, like blkdev_get_no_open() does, and skip the bdev if it's on its way out.
--- block/bdev.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
block/bdev.c +10 -0
@@ -1298,6 +1298,15 @@ void sync_bdevs(bool wait) old_inode = inode; bdev =I_BDEV (inode); +/* +* The inode does not keep the gendisk of a partition alive, the +* device does. +*/ +if (!kobject_get_unless_zero (&bdev->bd_device.kobj)) { +spin_lock (&blockdev_superblock->s_inode_list_lock); +continue ; + } +mutex_lock (&bdev->bd_disk->open_mutex);if (!atomic_read (&bdev->bd_openers)) { ;/* skip */
@@ -1313,6 +1322,7 @@ void sync_bdevs(bool wait)filemap_fdatawrite (inode->i_mapping); }mutex_unlock (&bdev->bd_disk->open_mutex); +put_device (&bdev->bd_device);spin_lock (&blockdev_superblock->s_inode_list_lock); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2070/2151 block: dont lose the status of a failed flush request
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 67c43ceaa29e9b904216651697adf20445b219fc ]
flush_end_io() stores the status in fq->rq_status for whoever drops the last reference to finish the flush sequence. blk_mq_put_rq_ref() calls it with BLK_STS_OK from tag iterators and the timeout handler and overwrites an error the real completion stored. With two extra references, reading /sys/block/<disk>/inflight is enough for that, a failed flush completes everything waiting on it with success and fsync() lies to the application.
Only store a status that is an error.
--- block/blk-flush.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
block/blk-flush.c +7 -1
@@ -211,7 +211,13 @@ static enum rq_end_io_ret flush_end_io(struct request *flush_rq,spin_lock_irqsave (&fq->mq_flush_lock, flags);if (!req_ref_put_and_test (flush_rq)) { - fq->rq_status = error; +/* +* Remember the status of the flush for whoever drops the last +* reference. blk_mq_put_rq_ref() gets here with BLK_STS_OK and +* must not wipe it out. +*/ +if (error !=BLK_STS_OK ) + fq->rq_status = error;spin_unlock_irqrestore (&fq->mq_flush_lock, flags);return RQ_END_IO_NONE ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2071/2151 blk-mq: use array manage hctx map instead of xarray
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fengnan Chang <[email protected]>
[ Upstream commit d0c98769ee7d5db8d699a270690639cde1766cd4 ]
After commit 4e5cc99e1e48 ("blk-mq: manage hctx map via xarray"), we use an xarray instead of array to store hctx, but in poll mode, each time in blk_mq_poll, we need use xa_load to find corresponding hctx, this introduce some costs. In my test, xa_load may cost 3.8% cpu.
This patch revert previous change, eliminates the overhead of xa_load and can result in a 3% performance improvement.
Stable-dep-of: 24974185999f ("blk-mq: don't trust the cookie in blk_mq_poll()")
--- block/blk-mq-tag.c | 2 +- block/blk-mq.c | 58 +++++++++++++++++++++++++++--------------- block/blk-mq.h | 2 +- include/linux/blk-mq.h | 3 ++- include/linux/blkdev.h | 2 +- 5 files changed, 42 insertions(+), 25 deletions(-)
block/blk-mq-tag.c +1 -1
@@ -506,7 +506,7 @@ void blk_mq_queue_tag_busy_iter(struct request_queue *q, busy_tag_iter_fn *fn,int srcu_idx;/* -* __blk_mq_update_nr_hw_queues() updates nr_hw_queues and hctx_table +* __blk_mq_update_nr_hw_queues() updates nr_hw_queues and queue_hw_ctx * while the queue is frozen. So we can use q_usage_counter to avoid * racing with it. */
block/blk-mq.c +37 -21
127 lines not on this page · raw message
block/blk-mq.h +1 -1
@@ -84,7 +84,7 @@ static inline struct blk_mq_hw_ctx *blk_mq_map_queue_type(struct request_queue * enum hctx_type type, unsigned int cpu) { -return xa_load (&q->hctx_table, q->tag_set->map[type].mq_map[cpu]); +return q->queue_hw_ctx[q->tag_set->map[type].mq_map[cpu]]; }static inline enum hctx_type blk_mq_get_hctx_type (blk_opf_t opf)
include/linux/blk-mq.h +2 -1
@@ -1013,7 +1013,8 @@ static inline void *blk_mq_rq_to_pdu(struct request *rq) }#define queue_for_each_hw_ctx (q, hctx, i) \ - xa_for_each(&(q)->hctx_table, (i), (hctx)) + for ((i) = 0; (i) < (q)->nr_hw_queues && \ + ({ hctx = (q)->queue_hw_ctx[i]; 1; }); (i)++)#define hctx_for_each_ctx (hctx, ctx, i) \ for ((i) = 0; (i) < (hctx)->nr_ctx && \
include/linux/blkdev.h +1 -1
@@ -497,7 +497,7 @@ struct request_queue {/* hw dispatch queues */ unsigned int nr_hw_queues; -struct xarray hctx_table; +struct blk_mq_hw_ctx **queue_hw_ctx;struct percpu_ref q_usage_counter;struct lock_class_key io_lock_cls_key;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2072/2151 blk-mq: dont trust the cookie in blk_mq_poll()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 24974185999fd80b676fbe2a6c7a97bbd38aaf3a ]
blk_mq_poll() indexes queue_hw_ctx[] with bio->bi_cookie unchecked. Zone write plugging keeps the segment count of a plugged write in __bi_nr_segments, which shares a union with the cookie, and clears REQ_POLLED, but bio_poll() only looks at the cookie. A plugged polled write with more segments than there are hardware queues reads past the array. The bio is also SLAB_TYPESAFE_BY_RCU, so a cookie from a bio reused for another device can meet the wrong array as well.
Ignore a cookie that is out of range or doesn't name a poll queue.
--- block/blk-mq.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
block/blk-mq.c +14 -1
@@ -5248,9 +5248,22 @@ static int blk_hctx_poll(struct request_queue *q, struct blk_mq_hw_ctx *hctx,int blk_mq_poll (struct request_queue *q,blk_qc_t cookie,struct io_comp_batch *iob,unsigned int flags) { +struct blk_mq_hw_ctx *hctx; +if (!blk_mq_can_poll (q))return 0 ; -return blk_hctx_poll (q, q->queue_hw_ctx[cookie], iob, flags); + +/* +* The cookie is no more than a hint. iocb_bio_iopoll() may have read it +* from a bio that was reused for another queue right afterwards, and +* zone write plugging keeps the number of segments in the same field. +*/ +if (cookie >= q->nr_hw_queues) +return 0 ; + hctx = q->queue_hw_ctx[cookie]; +if (hctx->type !=HCTX_TYPE_POLL ) +return 0 ; +return blk_hctx_poll (q, hctx, iob, flags); } int blk_rq_poll(struct request *rq, struct io_comp_batch *iob,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2073/2151 blk-mq: keep sharing tags fairly after a queue update
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 620cfc7a664278a55d068ed88fff1242fddc4ef2 ]
A hctx only gets BLK_MQ_F_TAG_QUEUE_SHARED from blk_mq_add_queue_tag_set(). The hctxs blk_mq_update_nr_hw_queues() allocates for queues that joined long ago never get it, so they aren't counted in active_queues and hctx_may_queue() lets them take all the tags. One NVMe namespace can starve the others after the first update.
Set the flag on the new hctxs.
--- block/blk-mq.c | 3 +++ 1 file changed, 3 insertions(+)
block/blk-mq.c +3 -0
@@ -5180,6 +5180,9 @@ static void __blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set, goto fallback; }blk_mq_map_swqueue (q); +/* The new hctxs don't know yet that they share their tags */ +if (set->flags &BLK_MQ_F_TAG_QUEUE_SHARED ) +queue_set_hctx_shared (q, true); } switch_back:/* The blk_mq_elv_switch_back unfreezes queue for us. */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2074/2151 blk-mq: dont bring back flags of a completed request
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 9531230ee1fcb8eca2c9cbb9bf02651cbf798842 ]
The timeout handler sets and clears RQF_TIMED_OUT in a request it only holds a reference to, with a plain read-modify-write, while the completion clears flags in rq_flags the same way. If the two interleave, blk_mq_finish_request() runs twice with the flags back: the zone write plug reference is dropped twice and the scheduler's ->finish_request() is called again.
Change RQF_TIMED_OUT with cmpxchg, so the handler never writes back a flag that changed under it.
--- block/blk-mq.c | 2 +- block/blk-timeout.c | 3 ++- block/blk.h | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-)
block/blk-mq.c +1 -1
@@ -1669,7 +1669,7 @@ EXPORT_SYMBOL_GPL(blk_mq_queue_inflight);static void blk_mq_rq_timed_out (struct request *req) { - req->rq_flags |=RQF_TIMED_OUT ; +blk_rq_change_timed_out (req, true);if (req->q->mq_ops->timeout) {enum blk_eh_timer_return ret;
block/blk-timeout.c +2 -1
@@ -137,7 +137,8 @@ void blk_add_timer(struct request *req)if (!req->timeout) req->timeout = q->rq_timeout; - req->rq_flags &= ~RQF_TIMED_OUT ; +if (req->rq_flags &RQF_TIMED_OUT ) +blk_rq_change_timed_out (req, false); expiry = jiffies + req->timeout;WRITE_ONCE (req->deadline, expiry);
block/blk.h +14 -0
@@ -331,6 +331,20 @@ static inline void bio_integrity_free(struct bio *bio)unsigned long blk_rq_timeout (unsigned long timeout);void blk_add_timer (struct request *req); +/* +* The timeout handler changes RQF_TIMED_OUT in a request which it does not +* own: whoever completes it changes rq_flags at the same time, with plain +* loads and stores. Never write back a flag that has changed under us. +*/ +static inline void blk_rq_change_timed_out (struct request *rq,bool set) +{ +req_flags_t old =READ_ONCE (rq->rq_flags), new; + +do { + new = set ? old |RQF_TIMED_OUT : old & ~RQF_TIMED_OUT ; + }while (!try_cmpxchg (&rq->rq_flags, &old, new)); +} +enum bio_merge_status {BIO_MERGE_OK ,BIO_MERGE_NONE ,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2075/2151 blk-mq: dont forget a timer the driver has restarted
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 0db9f8968a8941d4fc9fddf220d4983d9b68deaf ]
If ->timeout() returns BLK_EH_RESET_TIMER, blk_add_timer() gives the request a new deadline that blk_mq_timeout_work() doesn't know about when it picks the next expiry. A 2s nbd read next to a 60s one expires once and then not again for a minute. Let the new deadline take part.
--- block/blk-mq.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
block/blk-mq.c +4 -1
@@ -1740,8 +1740,11 @@ static bool blk_mq_handle_expired(struct request *rq, void *priv) {struct blk_expired_data *expired = priv; -if (blk_mq_req_expired (rq, expired)) +if (blk_mq_req_expired (rq, expired)) {blk_mq_rq_timed_out (rq); +/* If its timer has been started again, count the new deadline */ +blk_mq_req_expired (rq, expired); + }return true; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2076/2151 blk-mq: quiesce a queue that joins a quiesced tag set
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 71ec3c7d6db80737b781d2739d1325b7e39758e1 ]
blk_mq_quiesce_tagset() only quiesces the queues on the list at that moment. A queue added before blk_mq_unquiesce_tagset() runs unquiesced, and then gets unquiesced without ever having been quiesced, which trips the warning in blk_mq_unquiesce_queue(). NVMe gets there when a controller fails while its namespaces are being scanned.
Count the quiesce calls in the tag set and quiesce a joining queue that many times, under a spinlock that also serializes the two functions. It can't be tag_list_lock, see commit 59e25ef2b413.
--- block/blk-mq.c | 22 ++++++++++++++++++++++ include/linux/blk-mq.h | 6 ++++++ 2 files changed, 28 insertions(+)
block/blk-mq.c +22 -0
@@ -336,12 +336,15 @@ void blk_mq_quiesce_tagset(struct blk_mq_tag_set *set) {struct request_queue *q; +spin_lock (&set->quiesce_lock); + set->quiesce_depth++;rcu_read_lock ();list_for_each_entry_rcu (q, &set->tag_list, tag_set_list) {if (!blk_queue_skip_tagset_quiesce (q))blk_mq_quiesce_queue_nowait (q); }rcu_read_unlock (); +spin_unlock (&set->quiesce_lock);blk_mq_wait_quiesce_done (set); }
@@ -351,12 +354,16 @@ void blk_mq_unquiesce_tagset(struct blk_mq_tag_set *set) {struct request_queue *q; +spin_lock (&set->quiesce_lock); +if (set->quiesce_depth) + set->quiesce_depth--;rcu_read_lock ();list_for_each_entry_rcu (q, &set->tag_list, tag_set_list) {if (!blk_queue_skip_tagset_quiesce (q))blk_mq_unquiesce_queue (q); }rcu_read_unlock (); +spin_unlock (&set->quiesce_lock); }EXPORT_SYMBOL_GPL (blk_mq_unquiesce_tagset);
@@ -4353,6 +4360,8 @@ static void blk_mq_del_queue_tag_set(struct request_queue *q)static void blk_mq_add_queue_tag_set (struct blk_mq_tag_set *set,struct request_queue *q) { +unsigned int i; +mutex_lock (&set->tag_list_lock);/*
@@ -4366,7 +4375,18 @@ static void blk_mq_add_queue_tag_set(struct blk_mq_tag_set *set, }if (set->flags &BLK_MQ_F_TAG_QUEUE_SHARED )queue_set_hctx_shared (q, true); + +/* +* A queue that joins a quiesced tag set is quiesced like the others, +* and blk_mq_unquiesce_tagset() finds what it is going to undo. +*/ +spin_lock (&set->quiesce_lock);list_add_tail_rcu (&q->tag_set_list, &set->tag_list); +if (!blk_queue_skip_tagset_quiesce (q)) { +for (i =0 ; i < set->quiesce_depth; i++) +blk_mq_quiesce_queue_nowait (q); + } +spin_unlock (&set->quiesce_lock);mutex_unlock (&set->tag_list_lock); }
@@ -4930,6 +4950,8 @@ int blk_mq_alloc_tag_set(struct blk_mq_tag_set *set)mutex_init (&set->tag_list_lock);INIT_LIST_HEAD (&set->tag_list); +spin_lock_init (&set->quiesce_lock); + set->quiesce_depth =0 ;return 0 ;
include/linux/blk-mq.h +6 -0
@@ -521,6 +521,10 @@ enum hctx_type {* @tag_list_lock: Serializes tag_list accesses. * @tag_list: List of the request queues that use this tag set. See also * request_queue.tag_set_list. +* @quiesce_lock: Serializes blk_mq_[un]quiesce_tagset() against each other +* and against a request queue being added to @tag_list. +* @quiesce_depth: How often blk_mq_quiesce_tagset() has been called without +* blk_mq_unquiesce_tagset(). * @srcu: Use as lock when type of the request queue is blocking * (BLK_MQ_F_BLOCKING). * @update_nr_hwq_lock:
@@ -546,6 +550,8 @@ struct blk_mq_tag_set {struct mutex tag_list_lock;struct list_head tag_list; +spinlock_t quiesce_lock; +unsigned int quiesce_depth;struct srcu_struct *srcu;struct rw_semaphore update_nr_hwq_lock;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2077/2151 blk-mq: exit the hctxs of a queue under tag_list_lock
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 89a2381482d8ff8e4fe0b7d32797bb4f77503b89 ]
blk_mq_update_nr_hw_queues() exits and replaces the hctxs of every queue on set->tag_list under tag_list_lock. blk_mq_exit_queue() exits its hctxs without the lock and only then takes the queue off the list, so an update running at the same time exits them again and sets up new ones that nobody exits. del_gendisk() is kept away by update_nr_hwq_lock, disk_release() of a never added disk and blk_mq_destroy_queue() are not, and nvme_alloc_ns() drops such a disk when it finds the queues frozen by a reset.
Hold tag_list_lock for both steps.
--- block/blk-mq.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
block/blk-mq.c +8 -2
@@ -4346,7 +4346,8 @@ static void blk_mq_del_queue_tag_set(struct request_queue *q) {struct blk_mq_tag_set *set = q->tag_set; -mutex_lock (&set->tag_list_lock); +lockdep_assert_held (&set->tag_list_lock); +list_del_rcu (&q->tag_set_list);if (list_is_singular (&set->tag_list)) {/* just transitioned to unshared */
@@ -4354,7 +4355,6 @@ static void blk_mq_del_queue_tag_set(struct request_queue *q)/* update existing queue */ blk_mq_update_tag_set_shared (set, false); } -mutex_unlock (&set->tag_list_lock); } static void blk_mq_add_queue_tag_set(struct blk_mq_tag_set *set,
@@ -4713,10 +4713,16 @@ void blk_mq_exit_queue(struct request_queue *q) {struct blk_mq_tag_set *set = q->tag_set; +/* +* As long as the queue is on set->tag_list, its hctxs belong to +* blk_mq_update_nr_hw_queues() as well, which exits and replaces them. +*/ +mutex_lock (&set->tag_list_lock);/* Checks hctx->flags & BLK_MQ_F_TAG_QUEUE_SHARED. */ blk_mq_exit_hw_queues (q, set, set->nr_hw_queues);/* May clear BLK_MQ_F_TAG_QUEUE_SHARED in hctx->flags. */ blk_mq_del_queue_tag_set (q); +mutex_unlock (&set->tag_list_lock); }static int __blk_mq_alloc_rq_maps (struct blk_mq_tag_set *set)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2078/2151 blk-mq: set up a queue under tag_list_lock
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 4fcc499ea9bc31b02393904a1903e794d146f5f7 ]
blk_mq_init_allocated_queue() only takes tag_list_lock at the end, when it adds the queue to the set. Before that it sizes the queue by set->nr_hw_queues, hands out set->tags[], maps by set->map[], and blk_mq_map_swqueue() frees tags of the set. An update clearing the maps at that time makes the new queue free tags that all the other queues share. An NVMe controller reset during a namespace scan does exactly that.
Take the lock before the first look at the set. An update can be part of error handling, so the allocations under the lock must not wait for IO:memalloc_noio_save(), as in add_disk_fwnode().
--- block/blk-mq.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
block/blk-mq.c +18 -3
@@ -4362,7 +4362,7 @@ static void blk_mq_add_queue_tag_set(struct blk_mq_tag_set *set, {unsigned int i; -mutex_lock (&set->tag_list_lock); +lockdep_assert_held (&set->tag_list_lock);/* * Check to see if we're transitioning to shared (from 1 to 2 queues).
@@ -4387,8 +4387,6 @@ static void blk_mq_add_queue_tag_set(struct blk_mq_tag_set *set,blk_mq_quiesce_queue_nowait (q); }spin_unlock (&set->quiesce_lock); - -mutex_unlock (&set->tag_list_lock); }/* All allocations will be freed in release handler of q->mq_kobj */
@@ -4661,6 +4659,8 @@ static void blk_mq_realloc_hw_ctxs(struct blk_mq_tag_set *set,int blk_mq_init_allocated_queue (struct blk_mq_tag_set *set,struct request_queue *q) { +unsigned int memflags; +/* mark the queue as mq asap */ q->mq_ops = set->ops;
@@ -4679,6 +4679,16 @@ int blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,INIT_LIST_HEAD (&q->unused_hctx_list);spin_lock_init (&q->unused_hctx_lock); +/* +* Keep blk_mq_update_nr_hw_queues() away until the queue is on +* set->tag_list: it changes the number of hardware queues, the tags and +* the maps, and blk_mq_map_swqueue() allocates and frees tags of the set. +* An update can be part of the error handling of a driver, so it must +* not have to wait for somebody who waits for I/O. +*/ + memflags =memalloc_noio_save (); +mutex_lock (&set->tag_list_lock); +blk_mq_realloc_hw_ctxs (set, q);if (!q->nr_hw_queues) goto err_hctxs;
@@ -4698,9 +4708,14 @@ int blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,blk_mq_init_cpu_queues (q, set->nr_hw_queues);blk_mq_map_swqueue (q);blk_mq_add_queue_tag_set (set, q); + +mutex_unlock (&set->tag_list_lock); +memalloc_noio_restore (memflags);return 0 ; err_hctxs: +mutex_unlock (&set->tag_list_lock); +memalloc_noio_restore (memflags);blk_mq_release (q); err_exit: q->mq_ops =NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2079/2151 block: partitions/mac: compute the sectors in 64 bits
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 6c55f94317249bc195e197f6a8730c843e72ea8c ]
start_block and block_count are converted to 512 byte sectors in 32-bit arithmetic, although put_partition() takes a sector_t. With a block size above 512 bytes anything beyond 2TiB wraps and the partition lands on top of another one.
--- block/partitions/mac.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
block/partitions/mac.c +2 -2
@@ -97,8 +97,8 @@ int mac_partition(struct parsed_partitions *state)if (be16_to_cpu (part->signature) !=MAC_PARTITION_MAGIC )break ;put_partition (state, slot, -be32_to_cpu (part->start_block) * (secsize/512 ), -be32_to_cpu (part->block_count) * (secsize/512 )); + (sector_t )be32_to_cpu (part->start_block) * (secsize/512 ), + (sector_t )be32_to_cpu (part->block_count) * (secsize/512 ));if (!strncasecmp (part->type,"Linux_RAID" ,10 )) state->parts[slot].flags =ADDPART_FLAG_RAID ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2080/2151 blk-mq: free the bitmaps of tags in the SRCU callback
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 10b249e9b05eed0c4c65b9b89dfc2cf33d68d19a ]
Commit ad0d05dbddc1 keeps struct blk_mq_tags and the requests until the iterators under tags_srcu are gone, but the two bitmaps they walk are still freed right away. When the number of hardware queues shrinks, blk_mq_tagset_busy_iter() may be about to walk tags that __blk_mq_update_nr_hw_queues() frees. sbitmap_free() clears the map pointer, so that's a NULL dereference or a use-after-free, depending on the timing.
Free the bitmaps with the rest in the callback.
--- block/blk-mq-tag.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
block/blk-mq-tag.c +4 -4
@@ -605,17 +605,17 @@ static void blk_mq_free_tags_callback(struct rcu_head *head)kmemleak_free (page_address (page));__free_pages (page, page->private); } +/* An iterator may walk the bitmaps for as long as it may see the tags */ +sbitmap_queue_free (&tags->bitmap_tags); +sbitmap_queue_free (&tags->breserved_tags);kfree (tags); }void blk_mq_free_tags (struct blk_mq_tag_set *set,struct blk_mq_tags *tags) { -sbitmap_queue_free (&tags->bitmap_tags); -sbitmap_queue_free (&tags->breserved_tags); -/* if tags pages is not allocated yet, free tags directly */ if (list_empty (&tags->page_list)) { -kfree (tags); +blk_mq_free_tags_callback (&tags->rcu_head);return ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2081/2151 drbd: stop the start_resync timer of a dying device
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit a439d3fe3ec2bfe0b4ccb77973ae97949bcf46ec ]
start_resync_timer gets armed for up to a second and nothing ever deletes it, so drbd_destroy_device() can free the device with the timer pending. Shut it down where request_timer is shut down.
--- drivers/block/drbd/drbd_main.c | 1 + 1 file changed, 1 insertion(+)
drivers/block/drbd/drbd_main.c +1 -0
@@ -2159,6 +2159,7 @@ void drbd_destroy_device(struct kref *kref)struct drbd_peer_device *peer_device, *tmp_peer_device;timer_shutdown_sync (&device->request_timer); +timer_shutdown_sync (&device->start_resync_timer);/* paranoia asserts */ D_ASSERT (device, device->open_cnt ==0 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2082/2151 drbd: take req_lock to skip the initial sync as peer
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit bf7fff620c890a7ee0b444f1c7e9f0d1263a30ac ]
_drbd_set_state() must be called with req_lock held. drbd_adm_new_c_uuid() does, receive_uuids() on the peer doesn't, so a concurrent state change gets lost: the device is Secondary again, or its failed disk UpToDate, while the work for the lost change is already queued.
--- drivers/block/drbd/drbd_receiver.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/block/drbd/drbd_receiver.c +2 -0
@@ -4096,8 +4096,10 @@ static int receive_uuids(struct drbd_connection *connection, struct packet_info BM_LOCKED_TEST_ALLOWED, NULL);_drbd_uuid_set (device,UI_CURRENT , p_uuid[UI_CURRENT ]);_drbd_uuid_set (device,UI_BITMAP ,0 ); +spin_lock_irq (&device->resource->req_lock);_drbd_set_state (_NS2 (device, disk,D_UP_TO_DATE , pdsk,D_UP_TO_DATE ),CS_VERBOSE ,NULL ); +spin_unlock_irq (&device->resource->req_lock);drbd_md_sync (device); updated_uuids =1 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2083/2151 block/rnbd-srv: dont free the device on a sysfs error
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit d9667ade40f986c565769a900ced6ee95edd33c6 ]
rnbd_srv_create_dev_sysfs() drops the only kobject reference on its error paths, and the release function frees the rnbd_srv_dev. process_msg_open() keeps using it and ends in destroy_device() with a list_del() and a second kfree(). This doesn't need memory pressure: a client opening a device while its last mapping goes away gets -EEXIST from kobject_add() against the old directory.
Only undo kobject_add() on failure and leave the reference to destroy_device(). Initialise the kobject once, the next open retries.
--- drivers/block/rnbd/rnbd-srv-sysfs.c | 16 ++++++++++------ drivers/block/rnbd/rnbd-srv.c | 3 +++ 2 files changed, 13 insertions(+), 6 deletions(-)
drivers/block/rnbd/rnbd-srv-sysfs.c +10 -6
@@ -44,12 +44,17 @@ int rnbd_srv_create_dev_sysfs(struct rnbd_srv_dev *dev,struct kobject *bdev_kobj;int ret; - ret =kobject_init_and_add (&dev->dev_kobj, &dev_ktype, - rnbd_devs_kobj,"%pg" , bdev); -if (ret) { -kobject_put (&dev->dev_kobj); +/* +* The release function frees the device, which the caller goes on +* using and which others may share: never drop the reference of the +* kobject here. That is for destroy_device(). +*/ +if (!dev->dev_kobj.state_initialized) +kobject_init (&dev->dev_kobj, &dev_ktype); + + ret =kobject_add (&dev->dev_kobj, rnbd_devs_kobj,"%pg" , bdev); +if (ret)return ret; - } dev->dev_sessions_kobj =kobject_create_and_add ("sessions" , &dev->dev_kobj);
@@ -69,7 +74,6 @@ int rnbd_srv_create_dev_sysfs(struct rnbd_srv_dev *dev,kobject_put (dev->dev_sessions_kobj); free_dev_kobj:kobject_del (&dev->dev_kobj); -kobject_put (&dev->dev_kobj);return ret; }
drivers/block/rnbd/rnbd-srv.c +3 -0
@@ -207,6 +207,9 @@ static void destroy_device(struct kref *kref)* Destroy kobj only if it was really created. */ rnbd_srv_destroy_dev_sysfs (dev); + else if (dev->dev_kobj.state_initialized) + /* The files could not be created. Frees the name, too. */ + kobject_put(&dev->dev_kobj); elsekfree (dev ); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2084/2151 block/rnbd-srv: drop the sess_dev kobject unlocked
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 81941915d53ef3384ab4e4b68e92673e66cf66d7 ]
rnbd_srv_create_dev_session_sysfs() drops the kobject reference when it fails. The release function is rnbd_destroy_sess_dev(), which takes srv_dev->lock, and the caller holds that lock: the worker deadlocks on itself. A client opening one device as "ram0" and "./ram0" gets there through -EEXIST from kobject_add().
Have process_msg_open() drop the reference after releasing the lock, and leave the rest of the cleanup to the release function.
--- drivers/block/rnbd/rnbd-srv-sysfs.c | 12 ++++++------ drivers/block/rnbd/rnbd-srv.c | 8 +++++++- 2 files changed, 13 insertions(+), 7 deletions(-)
drivers/block/rnbd/rnbd-srv-sysfs.c +6 -6
@@ -193,6 +193,10 @@ static const struct kobj_type rnbd_srv_sess_dev_ktype = { .release = rnbd_srv_sess_dev_release, }; +/* +* On failure the caller has to drop the reference of the kobject. The release +* function takes the lock of the device, which the caller holds here. +*/ int rnbd_srv_create_dev_session_sysfs (struct rnbd_srv_sess_dev *sess_dev) {int ret;
@@ -200,17 +204,13 @@ int rnbd_srv_create_dev_session_sysfs(struct rnbd_srv_sess_dev *sess_dev) ret =kobject_init_and_add (&sess_dev->kobj, &rnbd_srv_sess_dev_ktype, sess_dev->dev->dev_sessions_kobj,"%s" , sess_dev->sess->sessname); -if (ret) { -kobject_put (&sess_dev->kobj); +if (ret)return ret; - } ret =sysfs_create_group (&sess_dev->kobj, &rnbd_srv_default_dev_session_attr_group); -if (ret) { +if (ret)kobject_del (&sess_dev->kobj); -kobject_put (&sess_dev->kobj); - }return ret; }
drivers/block/rnbd/rnbd-srv.c +7 -1
@@ -589,6 +589,7 @@ rnbd_srv_create_set_sess_dev(struct rnbd_srv_session *srv_sess,return sdev;kref_init (&sdev->kref); +INIT_LIST_HEAD (&sdev->dev_list);strscpy (sdev->pathname, open_msg->dev_name,sizeof (sdev->pathname));
@@ -787,7 +788,12 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess,rnbd_srv_err (srv_sess_dev,"Opening device failed, failed to create dev client sysfs files, err: %d\n" , ret); - goto free_srv_sess_dev; +/* +* rnbd_destroy_sess_dev() undoes everything down to the open +* of the block device. +*/ +kobject_put (&srv_sess_dev->kobj); + goto free_path; }list_add (&srv_sess_dev->dev_list, &srv_dev->sess_dev_list);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2085/2151 rnbd-srv: fix use-after-free on two CLOSE messages
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit 4912dab88baa5f7034dc9e38807804d470ae5438 ]
process_msg_close() looks the sess_dev up with a kref, drops it right away, and only then takes the session mutex for the teardown. A session has several connections handled by different workers, so two CLOSE messages for the same ID both finish the lookup before either one tears the sess_dev down, and the second one works on freed memory. Any host that can open a device on the server can do that.
Take the mutex first and look the ID up with xa_load() under it. The second CLOSE then finds nothing.
--- drivers/block/rnbd/rnbd-srv.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/block/rnbd/rnbd-srv.c +8 -7
@@ -359,14 +359,15 @@ static void process_msg_close(struct rnbd_srv_session *srv_sess,trace_process_msg_close (srv_sess, close_msg); - sess_dev =rnbd_get_sess_dev (le32_to_cpu (close_msg->device_id), - srv_sess); -if (IS_ERR (sess_dev)) -return ; - -rnbd_put_sess_dev (sess_dev); +/* +* Each teardown of a sess_dev runs under srv_sess->lock and erases the +* ID, so an entry that is found under the lock is alive. +*/ mutex_lock (&srv_sess->lock); -rnbd_srv_destroy_dev_session_sysfs (sess_dev); + sess_dev =xa_load (&srv_sess->index_idr, +le32_to_cpu (close_msg->device_id)); +if (sess_dev) +rnbd_srv_destroy_dev_session_sysfs (sess_dev);mutex_unlock (&srv_sess->lock); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2086/2151 rnbd-srv: publish the sess_dev at the end of OPEN
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit 08ebf69c78a02afb39b7728f3358c09bc4cf067d ]
rnbd_sess_dev_alloc() stores the empty sess_dev in the XArray as its first step. An IO message with the new ID from another connection can find it before bdev_file is set, or hold a reference while a failing OPEN frees it after a mere RCU grace period. Both are reachable from any host that can open a device.
Reserve the ID with a NULL entry and store the sess_dev once nothing can fail anymore. The error path still erases the ID, and no longer needs synchronize_rcu().
--- drivers/block/rnbd/rnbd-srv.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/block/rnbd/rnbd-srv.c +8 -2
@@ -430,7 +430,7 @@ static struct rnbd_srv_sess_devif (!sess_dev)return ERR_PTR (-ENOMEM ); - error =xa_alloc (&srv_sess->index_idr, &sess_dev->device_id, sess_dev, + error =xa_alloc (&srv_sess->index_idr, &sess_dev->device_id,NULL , xa_limit_32b,GFP_NOWAIT );if (error <0 ) {pr_warn ("Allocating idr failed, err: %d\n" , error);
@@ -800,6 +800,13 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess,list_add (&srv_sess_dev->dev_list, &srv_dev->sess_dev_list);mutex_unlock (&srv_dev->lock); +/* +* Nothing fails from here on, so let I/O messages find the sess_dev. +* The ID is reserved, so this store allocates nothing. +*/ +xa_store (&srv_sess->index_idr, srv_sess_dev->device_id, srv_sess_dev, +GFP_KERNEL ); +rnbd_srv_info (srv_sess_dev,"Opened device '%s'\n" , srv_dev->name);kfree (full_path);
@@ -811,7 +818,6 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess, free_srv_sess_dev:xa_erase (&srv_sess->index_idr, srv_sess_dev->device_id); -synchronize_rcu ();kfree (srv_sess_dev); srv_dev_put:if (open_msg->access_mode !=RNBD_ACCESS_RO ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2087/2151 block/blk-iocost: Split ioc_rqos_throttle()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bart Van Assche <[email protected]>
[ Upstream commit 1ff85a387947890938c05cfe22041dfeef3098dd ]
Prepare for inlining iocg_lock() and iocg_unlock() by moving the code between these two calls into a new function. No functionality has been changed.
Stable-dep-of: 0150554a3f38 ("blk-iocost: publish hweights as one atomic value")
--- block/blk-iocost.c | 163 ++++++++++++++++++++++++++------------------- 1 file changed, 94 insertions(+), 69 deletions(-)
block/blk-iocost.c +94 -69
@@ -2609,6 +2609,88 @@ static u64 calc_size_vtime_cost(struct request *rq, struct ioc *ioc)return cost; } +enum over_budget_action { + action_retry, + action_commit, + action_wait, + action_return, +}; + +static enum over_budget_action +iocg_handle_over_budget (struct rq_qos *rqos,struct ioc_gq *iocg, +struct bio *bio,struct ioc_now *now, +struct iocg_wait *wait,bool use_debt,bool ioc_locked, +u64 abs_cost,u64 cost) +{ +lockdep_assert_held (&iocg->waitq.lock); + +/* +* @iocg must stay activated for debt and waitq handling. Deactivation +* is synchronized against both ioc->lock and waitq.lock and we won't +* get deactivated as long as we're waiting or have debt, so we're good +* if we're activated here. In the unlikely cases that we aren't, just +* issue the IO. +*/ +if (unlikely (list_empty (&iocg->active_list))) +return action_commit; + +/* +* We're over budget. If @bio has to be issued regardless, remember +* the abs_cost instead of advancing vtime. iocg_kick_waitq() will pay +* off the debt before waking more IOs. +* +* This way, the debt is continuously paid off each period with the +* actual budget available to the cgroup. If we just wound vtime, we +* would incorrectly use the current hw_inuse for the entire amount +* which, for example, can lead to the cgroup staying blocked for a +* long time even with substantially raised hw_inuse. +* +* An iocg with vdebt should stay online so that the timer can keep +* deducting its vdebt and [de]activate use_delay mechanism +* accordingly. We don't want to race against the timer trying to +* clear them and leave @iocg inactive w/ dangling use_delay heavily +* penalizing the cgroup and its descendants. +*/ +if (use_debt) { +iocg_incur_debt (iocg, abs_cost, now); +if (iocg_kick_delay (iocg, now)) +blkcg_schedule_throttle (rqos->disk, + (bio->bi_opf &REQ_SWAP ) == +REQ_SWAP ); +return action_return; + } + +/* guarantee that iocgs w/ waiters have maximum inuse */ +if (!iocg->abs_vdebt && iocg->inuse != iocg->active) { +if (!ioc_locked) +return action_retry; +lockdep_assert_held (&iocg->ioc->lock); +propagate_weights (iocg, iocg->active, iocg->active, true, now); + } + +/* +* Append self to the waitq and schedule the wakeup timer if we're +* the first waiter. The timer duration is calculated based on the +* current vrate. vtime and hweight changes can make it too short +* or too long. Each wait entry records the absolute cost it's +* waiting for to allow re-evaluation using a custom wait entry. +* +* If too short, the timer simply reschedules itself. If too long, +* the period timer will notice and trigger wakeups. +* +* All waiters are on iocg->waitq and the wait states are +* synchronized using waitq.lock. +*/ +init_wait_func (&wait->wait, iocg_wake_fn); + wait->bio = bio; + wait->abs_cost = abs_cost; + wait->committed = false;/* will be set true by waker */ + +__add_wait_queue_entry_tail (&iocg->waitq, &wait->wait); +iocg_kick_waitq (iocg, ioc_locked, now); +return action_wait; +} +static void ioc_rqos_throttle (struct rq_qos *rqos,struct bio *bio) {struct blkcg_gq *blkg = bio->bi_blkg;
@@ -2618,6 +2700,7 @@ static void ioc_rqos_throttle(struct rq_qos *rqos, struct bio *bio)struct iocg_wait wait;u64 abs_cost, cost, vtime;bool use_debt, ioc_locked; +enum over_budget_action action;unsigned long flags;/* bypass IOs if disabled, still initializing, or for root cgroup */
@@ -2658,80 +2741,22 @@ static void ioc_rqos_throttle(struct rq_qos *rqos, struct bio *bio) ioc_locked = use_debt ||READ_ONCE (iocg->abs_vdebt); retry_lock:iocg_lock (iocg, ioc_locked, &flags); - -/* -* @iocg must stay activated for debt and waitq handling. Deactivation -* is synchronized against both ioc->lock and waitq.lock and we won't -* get deactivated as long as we're waiting or has debt, so we're good -* if we're activated here. In the unlikely cases that we aren't, just -* issue the IO. -*/ -if (unlikely (list_empty (&iocg->active_list))) { -iocg_unlock (iocg, ioc_locked, &flags); + action =iocg_handle_over_budget (rqos, iocg, bio, &now, &wait, use_debt, + ioc_locked, abs_cost, cost); +iocg_unlock (iocg, ioc_locked, &flags); +switch (action) { +case action_retry: + ioc_locked = true; + goto retry_lock; +case action_commit:iocg_commit_bio (iocg, bio, abs_cost, cost);return ; - } - -/* -* We're over budget. If @bio has to be issued regardless, remember -* the abs_cost instead of advancing vtime. iocg_kick_waitq() will pay -* off the debt before waking more IOs. -* -* This way, the debt is continuously paid off each period with the -* actual budget available to the cgroup. If we just wound vtime, we -* would incorrectly use the current hw_inuse for the entire amount -* which, for example, can lead to the cgroup staying blocked for a -* long time even with substantially raised hw_inuse. -* -* An iocg with vdebt should stay online so that the timer can keep -* deducting its vdebt and [de]activate use_delay mechanism -* accordingly. We don't want to race against the timer trying to -* clear them and leave @iocg inactive w/ dangling use_delay heavily -* penalizing the cgroup and its descendants. -*/ -if (use_debt) { -iocg_incur_debt (iocg, abs_cost, &now); -if (iocg_kick_delay (iocg, &now)) -blkcg_schedule_throttle (rqos->disk, - (bio->bi_opf &REQ_SWAP ) ==REQ_SWAP ); -iocg_unlock (iocg, ioc_locked, &flags); +case action_return:return ; +case action_wait: +break ; } -/* guarantee that iocgs w/ waiters have maximum inuse */ -if (!iocg->abs_vdebt && iocg->inuse != iocg->active) { -if (!ioc_locked) { -iocg_unlock (iocg, false, &flags); - ioc_locked = true; - goto retry_lock; - } -propagate_weights (iocg, iocg->active, iocg->active, true, - &now); - } - -/* -* Append self to the waitq and schedule the wakeup timer if we're -* the first waiter. The timer duration is calculated based on the -* current vrate. vtime and hweight changes can make it too short -* or too long. Each wait entry records the absolute cost it's -* waiting for to allow re-evaluation using a custom wait entry. -* -* If too short, the timer simply reschedules itself. If too long, -* the period timer will notice and trigger wakeups. -* -* All waiters are on iocg->waitq and the wait states are -* synchronized using waitq.lock. -*/ -init_wait_func (&wait.wait, iocg_wake_fn); - wait.bio = bio; - wait.abs_cost = abs_cost; - wait.committed = false;/* will be set true by waker */ - -__add_wait_queue_entry_tail (&iocg->waitq, &wait.wait); -iocg_kick_waitq (iocg, ioc_locked, &now); - -iocg_unlock (iocg, ioc_locked, &flags); -while (true) {set_current_state (TASK_UNINTERRUPTIBLE );if (wait.committed)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2088/2151 block/blk-iocost: Inline iocg_lock() and iocg_unlock()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bart Van Assche <[email protected]>
[ Upstream commit a255026594e9b7eea24c12d2bd4acae0c11eea94 ]
Both iocg_lock() and iocg_unlock() use conditional locking. Fold these functions into their callers such that unlocking becomes unconditional.
Stable-dep-of: 0150554a3f38 ("blk-iocost: publish hweights as one atomic value")
--- block/blk-iocost.c | 53 +++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 27 deletions(-)
block/blk-iocost.c +26 -27
@@ -727,26 +727,6 @@ static void iocg_commit_bio(struct ioc_gq *iocg, struct bio *bio,put_cpu_ptr (gcs); } -static void iocg_lock (struct ioc_gq *iocg,bool lock_ioc,unsigned long *flags) -{ -if (lock_ioc) { -spin_lock_irqsave (&iocg->ioc->lock, *flags); -spin_lock (&iocg->waitq.lock); - }else { -spin_lock_irqsave (&iocg->waitq.lock, *flags); - } -} - -static void iocg_unlock (struct ioc_gq *iocg,bool unlock_ioc,unsigned long *flags) -{ -if (unlock_ioc) { -spin_unlock (&iocg->waitq.lock); -spin_unlock_irqrestore (&iocg->ioc->lock, *flags); - }else { -spin_unlock_irqrestore (&iocg->waitq.lock, *flags); - } -} -#define CREATE_TRACE_POINTS #include <trace/events/iocost.h>
@@ -1589,9 +1569,17 @@ static enum hrtimer_restart iocg_waitq_timer_fn(struct hrtimer *timer)ioc_now (iocg->ioc, &now); -iocg_lock (iocg, pay_debt, &flags); -iocg_kick_waitq (iocg, pay_debt, &now); -iocg_unlock (iocg, pay_debt, &flags); +if (pay_debt) { +spin_lock_irqsave (&iocg->ioc->lock, flags); +spin_lock (&iocg->waitq.lock); +iocg_kick_waitq (iocg, pay_debt, &now); +spin_unlock (&iocg->waitq.lock); +spin_unlock_irqrestore (&iocg->ioc->lock, flags); + }else { +spin_lock_irqsave (&iocg->waitq.lock, flags); +iocg_kick_waitq (iocg, pay_debt, &now); +spin_unlock_irqrestore (&iocg->waitq.lock, flags); + }return HRTIMER_NORESTART ; }
@@ -2740,10 +2728,21 @@ static void ioc_rqos_throttle(struct rq_qos *rqos, struct bio *bio) use_debt =bio_issue_as_root_blkg (bio) ||fatal_signal_pending (current); ioc_locked = use_debt ||READ_ONCE (iocg->abs_vdebt); retry_lock: -iocg_lock (iocg, ioc_locked, &flags); - action =iocg_handle_over_budget (rqos, iocg, bio, &now, &wait, use_debt, - ioc_locked, abs_cost, cost); -iocg_unlock (iocg, ioc_locked, &flags); +if (ioc_locked) { +spin_lock_irqsave (&iocg->ioc->lock, flags); +spin_lock (&iocg->waitq.lock); + action =iocg_handle_over_budget (rqos, iocg, bio, &now, &wait, + use_debt, ioc_locked, abs_cost, + cost); +spin_unlock (&iocg->waitq.lock); +spin_unlock_irqrestore (&iocg->ioc->lock, flags); + }else { +spin_lock_irqsave (&iocg->waitq.lock, flags); + action =iocg_handle_over_budget (rqos, iocg, bio, &now, &wait, + use_debt, ioc_locked, abs_cost, + cost); +spin_unlock_irqrestore (&iocg->waitq.lock, flags); + }switch (action) {case action_retry: ioc_locked = true;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2089/2151 blk-iocost: publish hweights as one atomic value
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kunhai Dai <[email protected]>
[ Upstream commit 0150554a3f38e1850d5964102eb89a720c5fe789 ]
current_hweight() publishes the cache generation and both weights with separate stores. Refreshers running on different CPUs can interleave their stores and leave a new generation paired with weights from an older calculation. The compiler can also reorder the generation store before the weight stores, so a reader that sees the new generation can accept stale weights.
A stale weight is not only a reporting artifact. It feeds the cost calculation and the donation logic, where an inconsistent combination can lead to a zero divisor in transfer_surpluses().
In addition, the slow path rereads iocg->hweight_active/inuse after publishing them, so the value it returns can be the one written by another refresher instead of the locally computed one.
Pack the generation and both weights into a single atomic64_t and publish them with one atomic write. Readers take one atomic snapshot and return the local values. Weights are in [1, WEIGHT_ONE]; storing each minus one preserves the full range in 16 bits and leaves 32 bits for the generation.
The two weight fields remain as the donation workspace used under ioc->lock. Tracepoints decode the packed cache without refreshing it and iocost_monitor.py is updated accordingly.
Developed with assistance from Claude Code (Anthropic): the assistant drafted the packed representation, the helpers and the tracepoint/monitor changes, and ran the checks listed below. The author reviewed the result and remains responsible for it.
--- block/blk-iocost.c | 109 +++++++++++++++++++++++++++------ include/trace/events/iocost.h | 7 ++- tools/cgroup/iocost_monitor.py | 7 ++- 3 files changed, 99 insertions(+), 24 deletions(-)
block/blk-iocost.c +89 -20
@@ -173,6 +173,7 @@*/ #include <linux/kernel.h> +#include <linux/bitfield.h> #include <linux/module.h> #include <linux/timer.h> #include <linux/time64.h>
@@ -472,8 +473,8 @@ struct ioc_gq {* * When an idle cgroup becomes active its `active` goes from 0 to * `weight`. `inuse` is the surplus adjusted active weight. -* `active` and `inuse` are used to calculate `hweight_active` and -* `hweight_inuse`. +* `active` and `inuse` determine the hierarchical weights cached in +* `hweight_cache`. * * `last_inuse` remembers `inuse` while an iocg is idle to persist * surplus adjustments.
@@ -520,7 +521,9 @@ struct ioc_gq {u64 child_active_sum;u64 child_inuse_sum;u64 child_adjusted_sum; -int hweight_gen; +/* Generation in bits 63:32; active - 1 and inuse - 1 in 31:16/15:0. */ +atomic64_t hweight_cache; +/* Donation workspace, protected by ioc->lock. */ u32 hweight_active;u32 hweight_inuse;u32 hweight_donating;
@@ -727,6 +730,54 @@ static void iocg_commit_bio(struct ioc_gq *iocg, struct bio *bio,put_cpu_ptr (gcs); } +/* +* The hierarchical weights are in [1, WEIGHT_ONE] and the generation is a +* 32-bit counter. Pack generation and both weights into one 64-bit value so +* that a reader or a refresher always observes a complete snapshot: +* +* bits 63:32 generation +* bits 31:16 hweight_active - 1 +* bits 15:0 hweight_inuse - 1 +*/ +#define HWEIGHT_GEN_MASK GENMASK_ULL(63, 32) +#define HWEIGHT_ACTIVE_MASK GENMASK_ULL(31, 16) +#define HWEIGHT_INUSE_MASK GENMASK_ULL(15, 0) + +static inline u64 hweight_cache_pack (u32 gen,u32 active,u32 inuse) +{ +return FIELD_PREP (HWEIGHT_GEN_MASK , gen) | +FIELD_PREP (HWEIGHT_ACTIVE_MASK , active -1 ) | +FIELD_PREP (HWEIGHT_INUSE_MASK , inuse -1 ); +} + +static inline void hweight_cache_unpack (u64 cache,u32 *genp,u32 *activep, +u32 *inusep) +{ +if (genp) + *genp =FIELD_GET (HWEIGHT_GEN_MASK , cache); +if (activep) + *activep =FIELD_GET (HWEIGHT_ACTIVE_MASK , cache) +1 ; +if (inusep) + *inusep =FIELD_GET (HWEIGHT_INUSE_MASK , cache) +1 ; +} + +/* Decode the published weights without refreshing the cache. */ +static inline void iocg_hweight_cache (struct ioc_gq *iocg,u32 *activep, +u32 *inusep) +{ +hweight_cache_unpack (atomic64_read (&iocg->hweight_cache),NULL , + activep, inusep); +} + +/* Decode the cached inuse weight; only used by tracepoints. */ +static inline u32 iocg_hweight_cache_inuse (struct ioc_gq *iocg) +{ +u32 inuse; + +iocg_hweight_cache (iocg,NULL , &inuse); +return inuse; +} +#define CREATE_TRACE_POINTS #include <trace/events/iocost.h>
@@ -1154,12 +1205,15 @@ static void current_hweight(struct ioc_gq *iocg, u32 *hw_activep, u32 *hw_inusep {struct ioc *ioc = iocg->ioc;int lvl; -u32 hwa, hwi; -int ioc_gen; +u32 hwa, hwi, ioc_gen, cache_gen; +u64 cache; + + ioc_gen = (u32 )atomic_read (&ioc->hweight_gen); -/* hot path - if uptodate, use cached */ - ioc_gen =atomic_read (&ioc->hweight_gen); -if (ioc_gen == iocg->hweight_gen) +/* hot path - if uptodate, use the cached snapshot */ + cache =atomic64_read (&iocg->hweight_cache); +hweight_cache_unpack (cache, &cache_gen, &hwa, &hwi); +if (cache_gen == ioc_gen) goto out;/*
@@ -1194,14 +1248,20 @@ static void current_hweight(struct ioc_gq *iocg, u32 *hw_activep, u32 *hw_inusep hwi =div64_u64 ((u64 )hwi * inuse, inuse_sum); } - iocg->hweight_active =max_t (u32, hwa,1 ); - iocg->hweight_inuse =max_t (u32, hwi,1 ); - iocg->hweight_gen = ioc_gen; + hwa =max_t (u32, hwa,1 ); + hwi =max_t (u32, hwi,1 ); +/* +* Publish the generation and both weights as one atomic snapshot. +* A concurrent refresher may overwrite this with its own snapshot, +* but the generation travels with the weights so the next reader +* detects the mismatch and refreshes again. +*/ +atomic64_set (&iocg->hweight_cache,hweight_cache_pack (ioc_gen, hwa, hwi)); out:if (hw_activep) - *hw_activep = iocg->hweight_active; + *hw_activep = hwa;if (hw_inusep) - *hw_inusep = iocg->hweight_inuse; + *hw_inusep = hwi; }/*
@@ -1249,7 +1309,8 @@ static bool iocg_activate(struct ioc_gq *iocg, struct ioc_now *now) {struct ioc *ioc = iocg->ioc;u64 __maybe_unused last_period, cur_period; -u64 vtime, vtarget; +u64 vtime, vtarget, cache; +u32 active, inuse;int i;/*
@@ -1299,11 +1360,16 @@ static bool iocg_activate(struct ioc_gq *iocg, struct ioc_now *now) vtime = vtarget;/* -* Activate, propagate weight and start period timer if not -* running. Reset hweight_gen to avoid accidental match from -* wrapping. +* Activate, propagate weight and start period timer if not running. +* Invalidate the cached generation to avoid an accidental match from +* wrapping. Keep the last published weights so that the activation +* tracepoint can report them; the next current_hweight() recomputes. */ - iocg->hweight_gen =atomic_read (&ioc->hweight_gen) -1 ; + cache =atomic64_read (&iocg->hweight_cache); +hweight_cache_unpack (cache,NULL , &active, &inuse); +atomic64_set (&iocg->hweight_cache, +hweight_cache_pack ((u32)(atomic_read (&ioc->hweight_gen) -1 ), + active, inuse));list_add (&iocg->active_list, &ioc->active_iocgs); propagate_weights(iocg, iocg->weight,
@@ -2046,7 +2112,7 @@ static void transfer_surpluses(struct list_head *surpluses, struct ioc_now *now)TRACE_IOCG_PATH (inuse_transfer, iocg, now, iocg->inuse, inuse, - iocg->hweight_inuse, +iocg_hweight_cache_inuse (iocg), iocg->hweight_after_donation);__propagate_weights (iocg, iocg->active, inuse, true, now);
@@ -2361,7 +2427,7 @@ static void ioc_timer_fn(struct timer_list *timer)*/ TRACE_IOCG_PATH (inuse_shortage, iocg, &now, iocg->inuse, iocg->active, - iocg->hweight_inuse, new_hwi); + old_hwi, new_hwi);__propagate_weights (iocg, iocg->active, iocg->active, true, &now);
@@ -3031,6 +3097,9 @@ static void ioc_pd_init(struct blkg_policy_data *pd)INIT_LIST_HEAD (&iocg->active_list);INIT_LIST_HEAD (&iocg->walk_list);INIT_LIST_HEAD (&iocg->surplus_list); +atomic64_set (&iocg->hweight_cache, +hweight_cache_pack ((u32)(atomic_read (&ioc->hweight_gen) -1 ), +WEIGHT_ONE ,WEIGHT_ONE )); iocg->hweight_active =WEIGHT_ONE ; iocg->hweight_inuse =WEIGHT_ONE ;
include/trace/events/iocost.h +5 -2
@@ -34,6 +34,9 @@ DECLARE_EVENT_CLASS(iocost_iocg_state, ),TP_fast_assign ( + u32 hwa, hwi; + +iocg_hweight_cache (iocg, &hwa, &hwi);__assign_str (devname);__assign_str (cgroup); __entry->now = now->now;
@@ -44,8 +47,8 @@ DECLARE_EVENT_CLASS(iocost_iocg_state, __entry->vtime = vtime; __entry->weight = iocg->weight; __entry->inuse = iocg->inuse; - __entry->hweight_active = iocg->hweight_active; - __entry->hweight_inuse = iocg->hweight_inuse; + __entry->hweight_active = hwa; + __entry->hweight_inuse = hwi; ), TP_printk("[%s:%s] now=%llu:%llu vrate=%llu "
tools/cgroup/iocost_monitor.py +5 -2
@@ -149,8 +149,11 @@ class IocgStat: self.weight = iocg.weight.value_() / WEIGHT_ONE self.active = iocg.active.value_() / WEIGHT_ONE self.inuse = iocg.inuse.value_() / WEIGHT_ONE - self.hwa_pct = iocg.hweight_active.value_() * 100 / WEIGHT_ONE - self.hwi_pct = iocg.hweight_inuse.value_() * 100 / WEIGHT_ONE + hweight_cache = iocg.hweight_cache.counter.value_() + hwa = ((hweight_cache >> 16) & (WEIGHT_ONE - 1)) + 1 + hwi = (hweight_cache & (WEIGHT_ONE - 1)) + 1 + self.hwa_pct = hwa * 100 / WEIGHT_ONE + self.hwi_pct = hwi * 100 / WEIGHT_ONE self.address = iocg.value_() vdone = iocg.done_vtime.counter.value_()
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2090/2151 selftests: net: txtimestamp: fix out-of-bounds read in raw UDP checksum
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jamie Nguyen <[email protected]>
[ Upstream commit 8daacee78b3d2798fcf92398b6dff364eab64466 ]
With -r (SOCK_RAW, IPPROTO_UDP) the test writes only the UDP header and payload, and the kernel adds the IP header. get_udp_csum() still expects the IP source and destination addresses to directly precede the UDP header, and reads 2 * alen bytes before the start of the buffer: 8 bytes for IPv4, 32 bytes for IPv6.
ASan reports a heap-buffer-overflow for both -4 -r and -6 -r. Without ASan the read usually goes unnoticed, but it faults when the buffer is the first chunk in the heap. That happens on Ubuntu 26.04, where the kselftest runner wraps the test in uutils stdbuf, and txtimestamp.sh fails with SIGSEGV on every run.
Even without a crash, -r packets were sent with a checksum computed over unrelated heap memory, so their UDP checksum was invalid.
Build the pseudo-header from the destination address and checksum only the UDP header and payload. -R and -P already write daddr as both the source and destination address, so their checksums are unchanged. With -r the kernel selects the source address, which equals daddr for the loopback addresses used by txtimestamp.sh.
--- tools/testing/selftests/net/txtimestamp.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
tools/testing/selftests/net/txtimestamp.c +14 -9
@@ -420,19 +420,25 @@ static uint16_t get_ip_csum(const uint16_t *start, int num_words,return ~sum; } -static uint16_t get_udp_csum (const struct udphdr *udph,int alen) +static uint16_t get_udp_csum (const struct udphdr *udph,bool is_ipv4) { -unsigned long pseudo_sum, csum_len; -const void *csum_start = udph; +const void *addr = is_ipv4 ? (void *)&daddr.sin_addr : &daddr6.sin6_addr; +int alen = is_ipv4 ?sizeof (struct in_addr ) :sizeof (struct in6_addr ); +uint16_t addr16[sizeof (struct in6_addr ) /sizeof (uint16_t )]; +unsigned long pseudo_sum; +int i; pseudo_sum =htons (IPPROTO_UDP ); pseudo_sum += udph->len; -/* checksum ip(v6) addresses + udp header + payload */ - csum_start -= alen *2 ; - csum_len =ntohs (udph->len) + alen *2 ; +/* pseudo-header source and destination: both are daddr */ +memcpy (addr16, addr, alen); +for (i =0 ; i < alen /2 ; i++) + pseudo_sum +=2 * addr16[i]; -return get_ip_csum (csum_start, csum_len >>1 , pseudo_sum); +/* checksum udp header + payload */ +return get_ip_csum ((const uint16_t *)udph,ntohs (udph->len) >>1 , + pseudo_sum); }static int fill_header_ipv4 (void *p)
@@ -481,8 +487,7 @@ static void fill_header_udp(void *p, bool is_ipv4) udph->len =ntohs (sizeof (*udph) + cfg_payload_len); udph->check =0 ; - udph->check =get_udp_csum (udph, is_ipv4 ?sizeof (struct in_addr ) : -sizeof (struct in6_addr )); + udph->check =get_udp_csum (udph, is_ipv4); }static void do_test (int family,unsigned int report_opt)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2091/2151 apparmor: report a label allocation failure as -ENOMEM
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maxime Bélair <[email protected]>
[ Upstream commit 07aee062c6ecaa7199be583c83a1c74ae9885f03 ]
aa_label_strn_parse() returns -ENOENT for every failure, so a caller cannot tell "no such profile" from "could not allocate a label".
Report an allocation failure as -ENOMEM.
--- security/apparmor/label.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
security/apparmor/label.c +10 -4
@@ -1919,12 +1919,18 @@ struct aa_label *aa_label_strn_parse(struct aa_label *base, const char *str, goto out; } -if (create) +if (create) { label =aa_vec_find_or_create_label (vec, len, gfp); -else +if (!label) { +/* not absence: creating only fails on allocation */ + label =ERR_PTR (-ENOMEM ); + goto out; + } + }else { label =vec_find (vec, len); -if (!label) - goto fail; +if (!label) + goto fail; + } out:/* use adjusted len from after vec_unique, not original */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2092/2151 zloop: remove a duplicate call to zloop_get_block_size
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christoph Hellwig <[email protected]>
[ Upstream commit 0835f4909553e78a97d1ac59ed6eb776b4f78c92 ]
The sequential zone path has two calls to zloop_get_block_size, one conditional on not having a block size, and one unconditionally.
Remove the latter as the block size only needs to be queried once.
--- drivers/block/zloop.c | 2 -- 1 file changed, 2 deletions(-)
drivers/block/zloop.c +0 -2
@@ -887,8 +887,6 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,return ret; } -zloop_get_block_size (zlo, zone); -mutex_lock (&zone->lock); ret =zloop_update_seq_zone (zlo, zone_no);mutex_unlock (&zone->lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2093/2151 zloop: share more code for opening a zone backing file
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christoph Hellwig <[email protected]>
[ Upstream commit 5e9929e2f03c79574e76605e1a82509575db2d30 ]
Use a common path for opening and querying the block size.
Stable-dep-of: 134ffb075562 ("zloop: fput file after failed zone init")
--- drivers/block/zloop.c | 65 +++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 39 deletions(-)
drivers/block/zloop.c +26 -39
@@ -813,8 +813,6 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts, {struct zloop_zone *zone = &zlo->zones[zone_no];int oflags =O_RDWR ; -struct kstat stat; -sector_t file_sectors;int ret;mutex_init (&zone->lock);
@@ -826,27 +824,33 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,if (!opts->buffered_io) oflags |=O_DIRECT ; + zone->file =zloop_filp_open_fmt (oflags,0600 ,"%s/%u/%s-%06u" , + zlo->base_dir, zlo->id, + zone_no < zlo->nr_conv_zones ?"cnv" :"seq" , + zone_no); +if (IS_ERR (zone->file)) { +pr_err ("Failed to open zone %u file %s/%u/%s-%06u (err=%ld)" , + zone_no, zlo->base_dir, zlo->id, + zone_no < zlo->nr_conv_zones ?"cnv" :"seq" , + zone_no,PTR_ERR (zone->file)); +return PTR_ERR (zone->file); + } + +if (zlo->block_size) { + ret =zloop_get_block_size (zlo, zone); +if (ret) +return ret; + } +if (zone_no < zlo->nr_conv_zones) { +sector_t file_sectors; +struct kstat stat; +/* Conventional zone file. */ set_bit (ZLOOP_ZONE_CONV , &zone->flags); zone->cond =BLK_ZONE_COND_NOT_WP ; zone->wp =U64_MAX ; - zone->file =zloop_filp_open_fmt (oflags,0600 ,"%s/%u/cnv-%06u" , - zlo->base_dir, zlo->id, zone_no); -if (IS_ERR (zone->file)) { -pr_err ("Failed to open zone %u file %s/%u/cnv-%06u (err=%ld)" , - zone_no, zlo->base_dir, zlo->id, zone_no, -PTR_ERR (zone->file)); -return PTR_ERR (zone->file); - } - -if (!zlo->block_size) { - ret =zloop_get_block_size (zlo, zone); -if (ret) -return ret; - } - ret =vfs_getattr (&zone->file->f_path, &stat,STATX_SIZE ,0 );if (ret <0 ) {pr_err ("Failed to get zone %u file stat\n" , zone_no);
@@ -867,30 +871,13 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts, zone_no, ret);return ret; } - -return 0 ; - } - -/* Sequential zone file. */ - zone->file =zloop_filp_open_fmt (oflags,0600 ,"%s/%u/seq-%06u" , - zlo->base_dir, zlo->id, zone_no); -if (IS_ERR (zone->file)) { -pr_err ("Failed to open zone %u file %s/%u/seq-%06u (err=%ld)" , - zone_no, zlo->base_dir, zlo->id, zone_no, -PTR_ERR (zone->file)); -return PTR_ERR (zone->file); - } - -if (!zlo->block_size) { - ret =zloop_get_block_size (zlo, zone); -if (ret) -return ret; + }else { +/* Sequential zone file. */ +mutex_lock (&zone->lock); + ret =zloop_update_seq_zone (zlo, zone_no); +mutex_unlock (&zone->lock); } -mutex_lock (&zone->lock); - ret =zloop_update_seq_zone (zlo, zone_no); -mutex_unlock (&zone->lock); -return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2094/2151 zloop: fput file after failed zone init
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christoph Hellwig <[email protected]>
[ Upstream commit 134ffb0755626c91af82fc7debc8b6f75f1f777e ]
Clean up after failure in zloop_init_zone, as the caller only cleans up the zones before the current one.
--- drivers/block/zloop.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/block/zloop.c +10 -4
@@ -839,7 +839,7 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,if (zlo->block_size) { ret =zloop_get_block_size (zlo, zone);if (ret) -return ret; + goto out_fput; }if (zone_no < zlo->nr_conv_zones) {
@@ -854,14 +854,14 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts, ret =vfs_getattr (&zone->file->f_path, &stat,STATX_SIZE ,0 );if (ret <0 ) {pr_err ("Failed to get zone %u file stat\n" , zone_no); -return ret; + goto out_fput; } file_sectors = stat.size >>SECTOR_SHIFT ;if (restore && file_sectors != zlo->zone_size) {pr_err ("Invalid conventional zone %u file size (%llu sectors != %llu)\n" , zone_no, file_sectors, zlo->zone_capacity); -return ret; + goto out_fput; } ret = vfs_truncate(&zone->file->f_path,
@@ -869,15 +869,21 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,if (ret <0 ) {pr_err ("Failed to truncate zone %u file (err=%d)\n" , zone_no, ret); -return ret; + goto out_fput; } }else {/* Sequential zone file. */ mutex_lock (&zone->lock); ret =zloop_update_seq_zone (zlo, zone_no);mutex_unlock (&zone->lock); +if (ret) + goto out_fput; } +return 0 ; + +out_fput: +fput (zone->file);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2095/2151 zloop: check that the zone backing file support ->{read,write}_iter
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christoph Hellwig <[email protected]>
[ Upstream commit 0c10f8a1a7ae1502ea4ea7e13f222df89c28adf4 ]
I/O to backing files requires support for iter based read/write, so check for that upfront instead of dereferencing a NULL pointer later.
--- drivers/block/zloop.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/block/zloop.c +5 -0
@@ -836,6 +836,11 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,return PTR_ERR (zone->file); } +if (!zone->file->f_op->read_iter || !zone->file->f_op->write_iter) { + ret = -EINVAL ; + goto out_fput; + } +if (zlo->block_size) { ret =zloop_get_block_size (zlo, zone);if (ret)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2096/2151 apparmor: fix table_size() integer overflow on 32 bit
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maxime Bélair <[email protected]>
[ Upstream commit 449195a4bb7d9c456c02b871eec6905edb449bd2 ]
table_size() checks ALIGN(sizeof(struct table_header) + len * el_size, 8) in size_t, where @len is td_lolen, a u32 user-provided value from the policy blob. On 32 bit kernels both operations can overflow.
Triggering this bug allows to:
- overflow a 16 byte allocation with up to 4GiB of policy data
- store the table header at address ZERO_SIZE_PTR (kvzalloc(0))
However, this bug requires CAP_MAC_ADMIN, only affects 32 bit kernels, and the copy runs until the machine is destroyed, so it gives no controllable primitive and is therefore not a security issue.
Compute the size with the checked helpers and return 0 when the result is not representable, so the callers can reject the table. A valid table is never 0 bytes, the header alone is 12.
64 bit kernels cannot overflow (these structs are 32 bit), and are hence not affected.
--- security/apparmor/include/match.h | 11 ++++++++++- security/apparmor/match.c | 6 +++++- security/apparmor/policy_unpack.c | 5 +++++ 3 files changed, 20 insertions(+), 2 deletions(-)
security/apparmor/include/match.h +10 -1
@@ -12,6 +12,7 @@#define __AA_MATCH_H#include <linux/kref.h> +#include <linux/overflow.h> #define DFA_NOMATCH 0#define DFA_START 1
@@ -120,7 +121,15 @@ struct aa_dfa {static inline size_t table_size (size_t len,size_t el_size) { -return ALIGN (sizeof (struct table_header ) + len * el_size,8 ); +size_t size; + +/* Need check_*_overflow for 32 bit machines */ +if (check_mul_overflow (len, el_size, &size) || +check_add_overflow (size,sizeof (struct table_header ), &size) || + size >SIZE_MAX -7 ) +return 0 ; + +return ALIGN (size,8 ); }#define aa_state_t unsigned int
security/apparmor/match.c +5 -1
@@ -58,7 +58,7 @@ static struct table_header *unpack_table(char *blob, size_t bsize)if (th.td_lolen ==0 ) goto out; tsize =table_size (th.td_lolen, th.td_flags); -if (bsize < tsize) +if (!tsize || bsize < tsize) goto out; table =kvzalloc (tsize,GFP_KERNEL );
@@ -281,6 +281,10 @@ static struct table_header *remap_data16_to_data32(struct table_header *old)u32 i; tsize =table_size (old->td_lolen,YYTD_DATA32 ); +if (!tsize) { +kvfree (old); +return NULL ; + } new =kvzalloc (tsize,GFP_KERNEL );if (!new) {kvfree (old);
security/apparmor/policy_unpack.c +5 -0
@@ -810,6 +810,11 @@ static int unpack_pdb(struct aa_ext *e, struct aa_policydb **policy,u16 tdflags = pdb->dfa->tables[YYTD_ID_ACCEPT ]->td_flags;size_t tsize =table_size (noents, tdflags); +if (!tsize) { + *info ="invalid dfa flags table size" ; + error = -EPROTO ; + goto fail; + } pdb->dfa->tables[YYTD_ID_ACCEPT2 ] =kvzalloc (tsize,GFP_KERNEL );if (!pdb->dfa->tables[YYTD_ID_ACCEPT2 ]) { *info ="failed to alloc dfa flags table" ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2097/2151 apparmor: convert duplicated dfa transitions to match_char()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maxime Bélair <[email protected]>
[ Upstream commit e667fc72f7f4a54674962c324048ca2cc58bc703 ]
For historical reasons several matchers duplicate the dfa character transition instead of using match_char().
This is because aa_dfa_match_until() and aa_dfa_matchn_until() were written on a branch that did not yet have match_char(), and copied code from aa_dfa_match(). leftmatch_fb() used the same pattern.
When match_char() added support for diff-encoded states, the change was never ported to these copies.
match_char() resolves a diff encoded state by using def[state] and retrying the same character, until it reaches a state with a valid transition. The copies instead do a simple state = def[state]; after the character is consumed, so on a diff encoded state one byte is dropped and the walk continues from the diff parent in the wrong state.
This makes an unnamed px/Px/cx/Cx transition resolve to no profile, and exec fails with
apparmor="DENIED" operation="exec" info="profile transition not found"
Convert the three copies to match_char(). For a dfa with no diff encoded state this is a no-op.
This bug is latent until the kernel advertises policy/diff-encode.
--- security/apparmor/match.c | 52 ++++++++++++++------------------------- 1 file changed, 19 insertions(+), 33 deletions(-)
security/apparmor/match.c +19 -33
@@ -614,7 +614,7 @@ aa_state_t aa_dfa_match_until(struct aa_dfa *dfa, aa_state_t start,u32 *next =NEXT_TABLE (dfa);u32 *check =CHECK_TABLE (dfa);u32 *accept =ACCEPT_TABLE (dfa); -aa_state_t state = start, pos; +aa_state_t state = start;if (state ==DFA_NOMATCH )return DFA_NOMATCH ;
@@ -625,22 +625,18 @@ aa_state_t aa_dfa_match_until(struct aa_dfa *dfa, aa_state_t start,u8 *equiv =EQUIV_TABLE (dfa);/* default is direct to next state */ while (*str) { - pos =base_idx (base[state]) + equiv[(u8) *str++]; -if (check[pos] == state) - state = next[pos]; -else - state = def[state]; +u8 c = equiv[(u8) *str++]; + +match_char (state, def, base, next, check, c);if (accept[state])break ; } }else {/* default is direct to next state */ while (*str) { - pos =base_idx (base[state]) + (u8) *str++; -if (check[pos] == state) - state = next[pos]; -else - state = def[state]; +u8 c = (u8) *str++; + +match_char (state, def, base, next, check, c);if (accept[state])break ; }
@@ -675,7 +671,7 @@ aa_state_t aa_dfa_matchn_until(struct aa_dfa *dfa, aa_state_t start,u32 *next =NEXT_TABLE (dfa);u32 *check =CHECK_TABLE (dfa);u32 *accept =ACCEPT_TABLE (dfa); -aa_state_t state = start, pos; +aa_state_t state = start; *retpos =NULL ;if (state ==DFA_NOMATCH )
@@ -687,22 +683,18 @@ aa_state_t aa_dfa_matchn_until(struct aa_dfa *dfa, aa_state_t start,u8 *equiv =EQUIV_TABLE (dfa);/* default is direct to next state */ for (; n; n--) { - pos =base_idx (base[state]) + equiv[(u8) *str++]; -if (check[pos] == state) - state = next[pos]; -else - state = def[state]; +u8 c = equiv[(u8) *str++]; + +match_char (state, def, base, next, check, c);if (accept[state])break ; } }else {/* default is direct to next state */ for (; n; n--) { - pos =base_idx (base[state]) + (u8) *str++; -if (check[pos] == state) - state = next[pos]; -else - state = def[state]; +u8 c = (u8) *str++; + +match_char (state, def, base, next, check, c);if (accept[state])break ; }
@@ -751,7 +743,7 @@ static aa_state_t leftmatch_fb(struct aa_dfa *dfa, aa_state_t start,u32 *base =BASE_TABLE (dfa);u32 *next =NEXT_TABLE (dfa);u32 *check =CHECK_TABLE (dfa); -aa_state_t state = start, pos; +aa_state_t state = start;AA_BUG (!dfa);AA_BUG (!str);
@@ -769,13 +761,10 @@ static aa_state_t leftmatch_fb(struct aa_dfa *dfa, aa_state_t start,/* default is direct to next state */ while (*str) {unsigned int adjust; +u8 c = equiv[(u8) *str++]; wb->history[wb->pos] = state; - pos =base_idx (base[state]) + equiv[(u8) *str++]; -if (check[pos] == state) - state = next[pos]; -else - state = def[state]; +match_char (state, def, base, next, check, c);if (is_loop (wb, state, &adjust)) { state =aa_dfa_match (dfa, state, str); *count -= adjust;
@@ -788,13 +777,10 @@ static aa_state_t leftmatch_fb(struct aa_dfa *dfa, aa_state_t start,/* default is direct to next state */ while (*str) {unsigned int adjust; +u8 c = (u8) *str++; wb->history[wb->pos] = state; - pos =base_idx (base[state]) + (u8) *str++; -if (check[pos] == state) - state = next[pos]; -else - state = def[state]; +match_char (state, def, base, next, check, c);if (is_loop (wb, state, &adjust)) { state =aa_dfa_match (dfa, state, str); *count -= adjust;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2098/2151 apparmor: Fix namespace reference leak in __aa_find_or_create_ns()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
[ Upstream commit 8f1f7f664c1822af34c5465f9820b4e39146786b ]
When the namespace already exists, the reference taken by aa_get_ns() is overwritten with ERR_PTR(-EEXIST) without being released. The caller in apparmorfs.c clears ns on IS_ERR() and so cannot drop it either, leaking the reference on raced mkdir of an existing namespace.
Release the reference before returning -EEXIST.
--- security/apparmor/policy_ns.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
security/apparmor/policy_ns.c +4 -2
@@ -265,10 +265,12 @@ struct aa_ns *__aa_find_or_create_ns(struct aa_ns *parent, const char *name,/* try and find the specified ns */ /* released by caller */ ns =aa_get_ns (__aa_find_ns (&parent->sub_ns, name)); -if (!ns) +if (!ns) { ns =__aa_create_ns (parent, name, dir); -else + }else { +aa_put_ns (ns); ns =ERR_PTR (-EEXIST ); + }/* return ref */ return ns;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2099/2151 apparmor: check connect permission for SCTP
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jérémy Jean <[email protected]>
[ Upstream commit 2f764c08bb191a8c8f4051926dba0d25d195f39b ]
SCTP can start an association through sendmsg() or CONNECTX. These paths call the SCTP-specific sctp_bind_connect hook instead of the normal socket connect hook, but AppArmor does not register it. As a result, a profile can deny connect and allow send or setopt, yet a task can still create an SCTP association.
Register the SCTP hook. Ask for connect permission when SENDMSG_CONNECT or CONNECTX creates an association.
--- security/apparmor/lsm.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
security/apparmor/lsm.c +14 -0
@@ -15,6 +15,7 @@#include <linux/mount.h> #include <linux/namei.h> #include <linux/ptrace.h> +#include <linux/sctp.h> #include <linux/ctype.h> #include <linux/sysctl.h> #include <linux/audit.h>
@@ -1387,6 +1388,18 @@ static int apparmor_socket_connect(struct socket *sock,return aa_sk_perm (OP_CONNECT ,AA_MAY_CONNECT , sock->sk); } +static int apparmor_sctp_bind_connect (struct sock *sk,int optname, +struct sockaddr *address,int addrlen) +{ +switch (optname) { +case SCTP_SOCKOPT_CONNECTX : +case SCTP_SENDMSG_CONNECT : +return aa_sk_perm (OP_CONNECT ,AA_MAY_CONNECT , sk); + } + +return 0 ; +} +static int apparmor_socket_listen (struct socket *sock,int backlog) {AA_BUG (!sock);
@@ -1740,6 +1753,7 @@ static struct security_hook_list apparmor_hooks[] __ro_after_init = {LSM_HOOK_INIT (socket_getsockopt, apparmor_socket_getsockopt),LSM_HOOK_INIT (socket_setsockopt, apparmor_socket_setsockopt),LSM_HOOK_INIT (socket_shutdown, apparmor_socket_shutdown), +LSM_HOOK_INIT (sctp_bind_connect, apparmor_sctp_bind_connect), #ifdef CONFIG_NETWORK_SECMARK LSM_HOOK_INIT(socket_sock_rcv_skb, apparmor_socket_sock_rcv_skb), #endif
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2100/2151 netdev-genl: ignore NETDEV_UNREGISTER rebroadcasts
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Naman Gulati <[email protected]>
[ Upstream commit fd0909e963ed8f36967bd072ed484be7babe46de ]
netdev_wait_allrefs_any() re-sends NETDEV_UNREGISTER every second while it waits for the last references on a device to be dropped. By then netdev_run_todo() has already marked the device NETREG_UNREGISTERED and RTNL has been dropped at least once since the initial notification sent by unregister_netdevice_many_notify().
netdev_genl_netdevice_event() does not tell these rebroadcasts apart from the initial notification and sends a NETDEV_CMD_DEV_DEL_NTF multicast for each of them. At best this spams NETDEV_NLGRP_MGMT listeners with duplicate notifications; at worst the pernet state of the netns the device belongs to is already gone and the handler dereferences a NULL pointer.
default_device_exit_batch() only unregisters the devices still listed in the exiting netns; it does not wait for in-flight unregistrations of devices that were already unlisted (the barrier doing that was removed by commit 8a4fc54b07d7 ("net: get rid of rtnl_lock_unregistering()")). So when a device is unregistered by something other than the cleanup_net() of its own netns while references on it are still held, e.g. a veth whose peer in another netns gets deleted, and that netns exits while the device is stuck in netdev_wait_allrefs_any(), the remaining pernet exit handlers run and genl_pernet_exit() sets net->genl_sock to NULL. The next rebroadcast then crashes in genl_has_listeners():
BUG: KASAN: null-ptr-deref in netlink_has_listeners+0x3d/0x3f0 net/netlink/af_netlink.c:1388 Read of size 8 at addr 0000000000000578 by task syz.0.0/5325 Call Trace: <TASK> netlink_has_listeners+0x3d/0x3f0 net/netlink/af_netlink.c:1388 genl_has_listeners include/net/genetlink.h:644 [inline] netdev_genl_dev_notify+0x161/0x450 net/core/netdev-genl.c:93 netdev_genl_netdevice_event+0x98/0x3c0 net/core/netdev-genl.c:1491 notifier_call_chain+0x1a5/0x3d0 kernel/notifier.c:85 netdev_wait_allrefs_any net/core/dev.c:11690 [inline] netdev_run_todo+0x731/0x1060 net/core/dev.c:11808 rtnl_unlock net/core/rtnetlink.c:157 [inline] rtnl_dellink+0x68f/0x810 net/core/rtnetlink.c:3707
syzbot hit this by moving one end of a veth pair into a short-lived netns while netdevsim's deferred FIB event processing still held a reference on it, and then deleting the other end (repro [1]). While the source of this bug is netdevsim deferring FIB processing for and holding onto the device reference for O(seconds) which is being fixed separately [2], any driver may introduce such a delay and trigger the null-ptr-deref.
Skip the rebroadcasts, which are the only NETDEV_UNREGISTER events delivered with reg_state == NETREG_UNREGISTERED. The notifications sent by unregister_netdevice_many_notify() and, for a device leaving a netns, by __dev_change_net_namespace() are issued under RTNL in the same critical section that unlists the device, before its netns can be torn down, and keep being handled. This mirrors what ip6_route_dev_notify() already does to cope with the rebroadcasts.
This change should not break the UAPI spec as it defines dev-del-ntf as a "Notification about device disappearing." which is a single event. The rebroadcast in netdev_wait_allrefs_any() exists to re-kick in-kernel subsystems holding references; netdev-genl happens to be on the notifier chain and forwards it.
[1] https://gist.github.com/NamanGulati/2d1b49b8757f9a88b0bd6e55018c02ae
[2] https://lore.kernel.org/r/[email protected]
--- net/core/netdev-genl.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/core/netdev-genl.c +6 -0
@@ -1165,6 +1165,12 @@ static int netdev_genl_netdevice_event(struct notifier_block *nb,netdev_unlock_full_to_ops (netdev);break ;case NETDEV_UNREGISTER : +/* netdev_wait_allrefs_any() rebroadcasts NETDEV_UNREGISTER +* while waiting for the last references to be dropped; the +* netns may already be torn down by then. Notify only once. +*/ +if (READ_ONCE (netdev->reg_state) ==NETREG_UNREGISTERED ) +break ;netdev_lock (netdev);netdev_genl_dev_notify (netdev,NETDEV_CMD_DEV_DEL_NTF );netdev_unlock (netdev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2101/2151 bnxt_en: use bnxt_xdp_buff for xdp context
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris J Arges <[email protected]>
[ Upstream commit 542d3ec4508f02c9d5d9cdf92f7f3ae6958ca67c ]
This adds bnxt_xdp_buff which embeds the xdp_buff struct and stores pointers to hardware RX completion descriptors (rx_cmp and rx_cmp_ext) along with the completion type.
Stable-dep-of: db2c610df81e ("eth: bnxt: recycle agg buffers when Rx head buffer allocation fails")
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 29 ++++++++++++------- drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.h | 7 +++++ 2 files changed, 26 insertions(+), 10 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +19 -10
@@ -2115,13 +2115,13 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,u32 tmp_raw_cons = *raw_cons;u16 cons, prod, cp_cons =RING_CMP (tmp_raw_cons);struct skb_shared_info *sinfo; +struct bnxt_xdp_buff bnxt_xdp;struct bnxt_sw_rx_bd *rx_buf;unsigned int len;u8 *data_ptr, agg_bufs, cmp_type;bool xdp_active = false;dma_addr_t dma_addr;struct sk_buff *skb; -struct xdp_buff xdp;u32 flags, misc;u32 cmpl_ts;void *data;
@@ -2234,9 +2234,14 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_cp_ring_info *cpr, dma_addr = rx_buf->mapping;if (bnxt_xdp_attached (bp, rxr)) { -bnxt_xdp_buff_init (bp, rxr, cons, data_ptr, len, &xdp); + bnxt_xdp.rxcmp = rxcmp; + bnxt_xdp.rxcmp1 = rxcmp1; + bnxt_xdp.cmp_type = cmp_type; + +bnxt_xdp_buff_init (bp, rxr, cons, data_ptr, len, &bnxt_xdp.xdp);if (agg_bufs) { -u32 frag_len =bnxt_rx_agg_netmems_xdp (bp, cpr, &xdp, +u32 frag_len =bnxt_rx_agg_netmems_xdp (bp, cpr, + &bnxt_xdp.xdp, cp_cons, agg_bufs, false);
@@ -2248,12 +2253,13 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_cp_ring_info *cpr, }if (xdp_active) { -if (bnxt_rx_xdp (bp, rxr, cons, &xdp, data, &data_ptr, &len, event)) { +if (bnxt_rx_xdp (bp, rxr, cons, &bnxt_xdp.xdp, data, &data_ptr, + &len, event)) { rc =1 ; goto next_rx; } -if (xdp_buff_has_frags (&xdp)) { - sinfo =xdp_get_shared_info_from_buff (&xdp); +if (xdp_buff_has_frags (&bnxt_xdp.xdp)) { + sinfo =xdp_get_shared_info_from_buff (&bnxt_xdp.xdp); agg_bufs = sinfo->nr_frags; }else { agg_bufs =0 ;
@@ -2264,7 +2270,8 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,if (!xdp_active) skb =bnxt_copy_skb (bnapi, data_ptr, len, dma_addr);else - skb =bnxt_copy_xdp (bnapi, &xdp, len, dma_addr); + skb =bnxt_copy_xdp (bnapi, &bnxt_xdp.xdp, len, + dma_addr);bnxt_reuse_rx_data (rxr, cons, data);if (!skb) {if (agg_bufs) {
@@ -2272,7 +2279,8 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,bnxt_reuse_rx_agg_bufs (cpr, cp_cons,0 , agg_bufs, false); else - bnxt_xdp_buff_frags_free(rxr, &xdp); + bnxt_xdp_buff_frags_free(rxr, + &bnxt_xdp.xdp); } goto oom_next_rx; }
@@ -2296,10 +2304,11 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,if (!skb) goto oom_next_rx; }else { - skb =bnxt_xdp_build_skb (bp, skb, agg_bufs, rxr, &xdp); + skb =bnxt_xdp_build_skb (bp, skb, agg_bufs, + rxr, &bnxt_xdp.xdp);if (!skb) {/* we should be able to free the old skb here */ -bnxt_xdp_buff_frags_free (rxr, &xdp); +bnxt_xdp_buff_frags_free (rxr, &bnxt_xdp.xdp); goto oom_next_rx; } }
drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.h +7 -0
@@ -12,6 +12,13 @@DECLARE_STATIC_KEY_FALSE (bnxt_xdp_locking_key); +struct bnxt_xdp_buff { +struct xdp_buff xdp; +struct rx_cmp *rxcmp; +struct rx_cmp_ext *rxcmp1; +u8 cmp_type; +}; + struct bnxt_sw_tx_bd *bnxt_xmit_bd(struct bnxt *bp, struct bnxt_tx_ring_info *txr, dma_addr_t mapping, u32 len,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2102/2151 eth: bnxt: recycle agg buffers when Rx head buffer allocation fails
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jakub Kicinski <[email protected]>
[ Upstream commit db2c610df81e34d497f49b68a0a1681c3f203bdb ]
bnxt_rx_pkt() tries to return the aggregation buffers of a packet to the ring when the copybreak allocation fails, but the same logic is missing on the rx_skb_func() failure path. The agg BDs consumed by the device are then never posted again. The agg ring is only refilled one-for-one as completions consume its buffers, so each such failure permanently shrinks it. Under sustained memory pressure the ring drains completely, and the queue stops receiving anything that does not fit into the head buffer, even once memory is available again. Only re-creating the rings (e.g. ifdown / ifup) recovers it.
Commit 296d5b541639 ("bnxt_en: Fix aggregation buffer leak under OOM condition.") fixed the copybreak path only. Recently commit bd3beb5c8691 ("eth: bnxt: disable rx-copybreak by default") made the non-copybreak path the default, re-surfacing the issue.
With XDP, the agg buffers are attached to the xdp_buff as frags by this point. Their agg ring slots have already been refilled. We need to keep the original head page (and therefore shinfo) around until the xdp_buff cleanup.
Note the odd split of ownership here: rx_skb_func() only deals with the head buffer, the agg buffers stay with the caller in whatever state they are in, still on the ring without XDP, or frags of the xdp_buff with XDP. This complicates rx_skb_func() cleaning up all the buffers (head and frags), which would be more intuitive.
Discovered in production, severe packet loss would persist after a transient OOM event. Tested on a BCM57504 by failing the head buffer allocations in bnxt_rx_skb() (bpftrace override() of should_failslab() and should_fail_alloc_page()) while receiving 1400B ICMPv6 echo requests. 341k packets were dropped on that queue, enough to drain its 8188 entry agg ring 40 times over, and the queue kept receiving large frames afterwards with no loss and no new HW drops. With a frags-capable XDP_PASS program at MTU 9000, receiving 8000B ICMPv6 echo requests while napi_build_skb() called from bnxt_rx_multi_page_skb() failed, 9.2k packets were dropped, the page pools' inflight count stayed flat and
there were no KASAN or DEBUG_PAGEALLOC splats.
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 33 ++++++++++++++--------- 1 file changed, 20 insertions(+), 13 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +20 -13
@@ -1160,7 +1160,15 @@ static struct sk_buff *bnxt_rx_multi_page_skb(struct bnxt *bp, bp->rx_dir); skb =napi_build_skb (frag_start, rxr->rx_page_size);if (!skb) { -page_pool_recycle_direct (rxr->page_pool, page); +struct page *new_page; + + new_page = rxr->rx_buf_ring[RING_RX (bp, prod)].data; +/* The caller may still need the XDP frags from shinfo at the +* end of the head page. Release the new buffer instead and +* put the head back on the ring. +*/ +page_pool_recycle_direct (rxr->page_pool, new_page); +bnxt_reuse_rx_data (rxr, cons, data);return NULL ; }skb_mark_for_recycle (skb);
@@ -2273,17 +2281,8 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_cp_ring_info *cpr, skb =bnxt_copy_xdp (bnapi, &bnxt_xdp.xdp, len, dma_addr);bnxt_reuse_rx_data (rxr, cons, data); -if (!skb) { -if (agg_bufs) { -if (!xdp_active) -bnxt_reuse_rx_agg_bufs (cpr, cp_cons,0 , - agg_bufs, false); -else -bnxt_xdp_buff_frags_free (rxr, - &bnxt_xdp.xdp); - } - goto oom_next_rx; - } +if (!skb) + goto oom_next_rx_agg; }else {u32 payload;
@@ -2294,7 +2293,7 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_cp_ring_info *cpr, skb = bp->rx_skb_func (bp, rxr, cons, data, data_ptr, dma_addr, payload | len);if (!skb) - goto oom_next_rx; + goto oom_next_rx_agg; }if (agg_bufs) {
@@ -2384,6 +2383,14 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,return rc; +oom_next_rx_agg: +if (agg_bufs) { +if (!xdp_active) +bnxt_reuse_rx_agg_bufs (cpr, cp_cons,0 , agg_bufs, + false); +else +bnxt_xdp_buff_frags_free (rxr, &bnxt_xdp.xdp); + } oom_next_rx: cpr->sw_stats->rx.rx_oom_discards +=1 ; rc = -ENOMEM ;
Signature · 1 line
2.53.0