6.12.119-rc1 review
Subsystems (3)
Greg Kroah-Hartman
maintainerPATCH 854/1756 svcrdma: Fix svc_rdma_recv_cid_init() kernel-doc
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit d1caedce2d015573b4c26b127c488059f25aabc4 ]
svc_rdma_recv_cid_init() initializes a Receive Queue completion ID, but its kernel-doc heading names svc_rdma_send_cid_init(). The latter is a separate helper immediately below it, so kernel-doc cannot match this comment to the receive helper.
Fix the copied function name.
--- include/linux/sunrpc/svc_rdma.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/sunrpc/svc_rdma.h +1 -1
@@ -138,7 +138,7 @@ enum {#define RPCSVC_MAXPAYLOAD_RDMA RPCSVC_MAXPAYLOAD/** -* svc_rdma_send_cid_init - Initialize a Receive Queue completion ID +* svc_rdma_recv_cid_init - Initialize a Receive Queue completion ID * @rdma: controlling transport * @cid: completion ID to initialize */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 855/1756 cpufreq: sparc-us2e: fix frequency table index copy-paste error
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xueqin Luo <[email protected]>
[ Upstream commit e5b33fa47792375ca7fc49ccadee87d8e4b72929 ]
In us2e_freq_cpu_init(), the last two frequency writes both use index [2] instead of [3] and [4] respectively, and the terminator uses [3] instead of [5]. This is a copy-paste error where the index was not incremented, causing the divider-6 and divider-8 entries to overwrite the already-written divider-4 entry.
As a result, only three frequency steps (div 1, 2, and 4) are actually available to the cpufreq core, while the intended dividers 6 and 8 are silently lost. The struct us2e_freq_percpu_info::table[6] has room for 5 entries plus a terminator, matching the 5 hardware dividers.
Fix the indices so all five frequency steps are correctly populated:
table[0]=div1, table[1]=div2, table[2]=div4, table[3]=div6, table[4]=div8, table[5]=TABLE_END.
--- drivers/cpufreq/sparc-us2e-cpufreq.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/cpufreq/sparc-us2e-cpufreq.c +5 -6
@@ -282,12 +282,11 @@ static int us2e_freq_cpu_init(struct cpufreq_policy *policy) table[1 ].frequency = clock_tick /2 ; table[2 ].driver_data =2 ; table[2 ].frequency = clock_tick /4 ; - table[2 ].driver_data =3 ; - table[2 ].frequency = clock_tick /6 ; - table[2 ].driver_data =4 ; - table[2 ].frequency = clock_tick /8 ; - table[2 ].driver_data =5 ; - table[3 ].frequency =CPUFREQ_TABLE_END ; + table[3 ].driver_data =3 ; + table[3 ].frequency = clock_tick /6 ; + table[4 ].driver_data =4 ; + table[4 ].frequency = clock_tick /8 ; + table[5 ].frequency =CPUFREQ_TABLE_END ; policy->cpuinfo.transition_latency =0 ; policy->cur = clock_tick;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 856/1756 cpufreq: tegra194: fix double-pointer error in get_cpu_ndiv
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xueqin Luo <[email protected]>
[ Upstream commit f0a750dad7da1c653e85f0698063235453b43831 ]
ndiv is already a u64 pointer, passing &ndiv to smp_call_function_single() results in a u64** being written to instead of the caller's u64 variable, so the caller always reads back an uninitialized ndiv. Drop the spurious '&'.
--- drivers/cpufreq/tegra194-cpufreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/tegra194-cpufreq.c +1 -1
@@ -367,7 +367,7 @@ static void tegra194_get_cpu_ndiv_sysreg(void *ndiv)static int tegra194_get_cpu_ndiv (u32 cpu,u32 cpuid,u32 clusterid,u64 *ndiv) { -return smp_call_function_single (cpu, tegra194_get_cpu_ndiv_sysreg, &ndiv, true); +return smp_call_function_single (cpu, tegra194_get_cpu_ndiv_sysreg, ndiv, true); }static void tegra194_set_cpu_ndiv_sysreg (void *data)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 857/1756 cpufreq: sti: avoid NULL dereference in dev_err()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xueqin Luo <[email protected]>
[ Upstream commit fdbe4cae71c8196cd7681ad47254b5b0560d3c1e ]
ddata.cpu is NULL-checked, then immediately passed to dev_err(). Replace with pr_err() to avoid dereferencing NULL.
--- drivers/cpufreq/sti-cpufreq.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/cpufreq/sti-cpufreq.c +2 -2
@@ -263,7 +263,7 @@ static int __init sti_cpufreq_init(void) ddata.cpu =get_cpu_device (0 );if (!ddata.cpu) { -dev_err (ddata.cpu,"Failed to get device for CPU0\n" ); +pr_err ("Failed to get device for CPU0\n" ); goto skip_voltage_scaling; }
@@ -281,7 +281,7 @@ static int __init sti_cpufreq_init(void) goto register_cpufreq_dt; skip_voltage_scaling: -dev_err (ddata.cpu,"Not doing voltage scaling\n" ); +pr_err ("Not doing voltage scaling\n" ); register_cpufreq_dt:platform_device_register_simple ("cpufreq-dt" ,-1 ,NULL ,0 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 858/1756 drm/msm/dpu: round up the compressed INTF width
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joonhoe Kim <[email protected]>
[ Upstream commit 6b93e8b453fa27a1b6a1d472f3ff8663e6811fae ]
For DSI with DSC, drm_mode_to_intf_timing_params() scales the INTF active width by bpp / (3 * bits_per_component) and rounds down. The DSI host computes the same width with DIV_ROUND_UP, both for the pixel clock (dsi_adjust_pclk_for_compression()) and for the active width it programs (dsi_timing_setup(), from bytes per line). When the division is not exact the INTF line is one pclk shorter than the DSI line, and the DSI FIFO overflows.
Example: a bonded DSI video-mode panel, 952 pixels per link, DSC 8 bpp at 10 bpc: 952 * 8 / 30 = 253.87, so the INTF uses 253 and the DSI 254.
Round up, as the DSI host does. Qualcomm's downstream SDE driver also rounds this width up, and Pengyu Luo needed the same rounding on the Legion Y700 gen 4 [1].
Tested on a Lenovo Legion Tab Y700 gen 5 (SM8850) with that panel, with a module parameter selecting the rounding: rounding down, DPMS off/on gives no vblank and 14000-17000 DSI FIFO error interrupts per second (dsi_err_worker: status=4); rounding up, the picture comes back and there are no errors. Only tested on this device.
Patchwork: https://patchwork.freedesktop.org/patch/757958/
--- drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_vid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_vid.c +2 -2
@@ -133,8 +133,8 @@ static void drm_mode_to_intf_timing_params(* TODO: replace drm_dsc_get_bpp_int with logic to handle * fractional part if there is fraction */ - timing->width = timing->width *drm_dsc_get_bpp_int (dsc) / - (dsc->bits_per_component *3 ); + timing->width =DIV_ROUND_UP (timing->width *drm_dsc_get_bpp_int (dsc), + dsc->bits_per_component *3 ); timing->xres = timing->width; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 859/1756 firmware: qcom: tzmem: Use DO_ONCE_SLEEPABLE() in qcom_tzmem_enable()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mukesh Ojha <[email protected]>
[ Upstream commit 60d4a6edea9ec617725db6dd1e66d96a13bc8d0a ]
qcom_tzmem_enable() is called from qcom_scm_probe() in a sleepable process context. The helper it wraps, qcom_tzmem_init(), calls qcom_scm_shm_bridge_enable() -> qcom_scm_call(), which invokes might_sleep() and later acquires the qcom_scm_lock mutex via __scm_smc_do().
DO_ONCE() takes the once_lock spinlock with IRQs disabled, so invoking qcom_tzmem_init() from inside DO_ONCE() runs a sleepable call chain in atomic context. CONFIG_DEBUG_ATOMIC_SLEEP=y catches this on boot:
BUG: sleeping function called from invalid context at drivers/firmware/qcom/qcom_scm.c:334 in_atomic(): 1, irqs_disabled(): 1, non_block: 0, pid: 49, name: kworker/u16:2 ... __might_resched+0x148/0x24c __might_sleep+0x48/0x7c qcom_scm_call+0x30/0xc0 __qcom_scm_is_call_available+0x98/0x100 qcom_scm_shm_bridge_enable+0x60/0xbc qcom_tzmem_enable+0xf8/0x118 qcom_scm_probe+0x2d0/0x680
[ BUG: Invalid wait context ]
...
kworker/u16:2/49 is trying to lock:
ffffa83e8a485e38 (qcom_scm_lock){....}-{4:4}, at: __scm_smc_do+0x70/0x488
Switch to DO_ONCE_SLEEPABLE(), which guards the one-shot init with a mutex-style path (__do_once_sleepable_start/done) that is safe to hold across sleeping callees. All callers of qcom_tzmem_enable() are in process context (driver probe), so this is safe.
--- drivers/firmware/qcom/qcom_tzmem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/qcom/qcom_tzmem.c +1 -1
@@ -476,7 +476,7 @@ int qcom_tzmem_enable(struct device *dev)static int result; qcom_tzmem_dev = dev; -DO_ONCE (qcom_tzmem_do_init, &result); +DO_ONCE_SLEEPABLE (qcom_tzmem_do_init, &result);return result; }EXPORT_SYMBOL_GPL (qcom_tzmem_enable);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 860/1756 soc: qcom: pmic_glink: simplify locking with guard()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Krzysztof Kozlowski <[email protected]>
[ Upstream commit e9f826b0459f1376b9c8beba019b84f9878419c6 ]
Simplify error handling over locks with guard(). In few places this elimiates error gotos and local variables. Switch to guard() everywhere (except when jumps would go over scoped guard) for consistency, even if it does not bring benefit in such places.
Stable-dep-of: 0c79a829af36 ("soc: qcom: pmic_glink: Avoid losing early rpmsg probe")
--- drivers/soc/qcom/pmic_glink.c | 70 +++++++++++++++-------------------- 1 file changed, 29 insertions(+), 41 deletions(-)
drivers/soc/qcom/pmic_glink.c +29 -41
@@ -4,6 +4,7 @@* Copyright (c) 2022, Linaro Ltd */ #include <linux/auxiliary_bus.h> +#include <linux/cleanup.h> #include <linux/delay.h> #include <linux/module.h> #include <linux/of.h>
@@ -100,15 +101,13 @@ void pmic_glink_client_register(struct pmic_glink_client *client)struct pmic_glink *pg = client->pg;unsigned long flags; -mutex_lock (&pg->state_lock); +guard (mutex)(&pg->state_lock);spin_lock_irqsave (&pg->client_lock, flags);list_add (&client->node, &pg->clients); client->pdr_notify (client->priv, pg->client_state);spin_unlock_irqrestore (&pg->client_lock, flags); -mutex_unlock (&pg->state_lock); - }EXPORT_SYMBOL_GPL (pmic_glink_client_register);
@@ -119,26 +118,25 @@ int pmic_glink_send(struct pmic_glink_client *client, void *data, size_t len)unsigned long start;int ret; -mutex_lock (&pg->state_lock); +guard (mutex)(&pg->state_lock);if (!pg->ept) { - ret = -ECONNRESET ; - }else { - start = jiffies; -for (;;) { - ret =rpmsg_send (pg->ept, data, len); -if (ret != -EAGAIN ) -break ; - -if (timeout_reached) { - ret = -ETIMEDOUT ; -break ; - } - -usleep_range (1000 ,5000 ); - timeout_reached =time_after (jiffies, start +PMIC_GLINK_SEND_TIMEOUT ); +return -ECONNRESET ; + } + + start = jiffies; +for (;;) { + ret =rpmsg_send (pg->ept, data, len); +if (ret != -EAGAIN ) +break ; + +if (timeout_reached) { + ret = -ETIMEDOUT ; +break ; } + +usleep_range (1000 ,5000 ); + timeout_reached =time_after (jiffies, start +PMIC_GLINK_SEND_TIMEOUT ); } -mutex_unlock (&pg->state_lock);return ret; }
@@ -232,51 +230,42 @@ static void pmic_glink_pdr_callback(int state, char *svc_path, void *priv) {struct pmic_glink *pg = priv; -mutex_lock (&pg->state_lock); +guard (mutex)(&pg->state_lock); pg->pdr_state = state;pmic_glink_state_notify_clients (pg); -mutex_unlock (&pg->state_lock); }static int pmic_glink_rpmsg_probe (struct rpmsg_device *rpdev) {struct pmic_glink *pg = __pmic_glink; -int ret =0 ; -mutex_lock (&__pmic_glink_lock); -if (!pg) { - ret =dev_err_probe (&rpdev->dev, -ENODEV ,"no pmic_glink device to attach to\n" ); - goto out_unlock; - } +guard (mutex)(&__pmic_glink_lock); + pg = __pmic_glink; +if (!pg) +return dev_err_probe (&rpdev->dev, -ENODEV ,"no pmic_glink device to attach to\n" );dev_set_drvdata (&rpdev->dev, pg); -mutex_lock (&pg->state_lock); +guard (mutex)(&pg->state_lock); pg->ept = rpdev->ept;pmic_glink_state_notify_clients (pg); -mutex_unlock (&pg->state_lock); -out_unlock: -mutex_unlock (&__pmic_glink_lock); -return ret; +return 0 ; }static void pmic_glink_rpmsg_remove (struct rpmsg_device *rpdev) {struct pmic_glink *pg; -mutex_lock (&__pmic_glink_lock); +guard (mutex)(&__pmic_glink_lock); pg = __pmic_glink;if (!pg) - goto out_unlock; +return ; -mutex_lock (&pg->state_lock); +guard (mutex)(&pg->state_lock); pg->ept =NULL ;pmic_glink_state_notify_clients (pg); -mutex_unlock (&pg->state_lock); -out_unlock: -mutex_unlock (&__pmic_glink_lock); }static const struct rpmsg_device_id pmic_glink_rpmsg_id_match[] = {
@@ -383,9 +372,8 @@ static void pmic_glink_remove(struct platform_device *pdev)if (pg->client_mask &BIT (PMIC_GLINK_CLIENT_UCSI ))pmic_glink_del_aux_device (pg, &pg->ucsi_aux); -mutex_lock (&__pmic_glink_lock); +guard (mutex)(&__pmic_glink_lock); __pmic_glink =NULL ; -mutex_unlock (&__pmic_glink_lock); } static const unsigned long pmic_glink_sc8280xp_client_mask = BIT(PMIC_GLINK_CLIENT_BATT) |
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 861/1756 soc: qcom: pmic_glink: Avoid losing early rpmsg probe
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Konrad Dybcio <[email protected]>
[ Upstream commit 0c79a829af36a94143c747a0ab8f0a8563b17cfa ]
The PMIC GLINK rpmsg device can appear before the platform device has finished probing. In that case pmic_glink_rpmsg_probe() sees __pmic_glink as NULL and returns -ENODEV, which is treated as a fatal probe failure for the rpmsg endpoint.
If this race is hit, pg->ept is never installed and PMIC GLINK clients never receive the service-up notification. This may leave the system with no Type-C functionality and without battery/power supply management.
Return -EPROBE_DEFER when the rpmsg endpoint arrives before the platform device is ready.
--- drivers/soc/qcom/pmic_glink.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/soc/qcom/pmic_glink.c +2 -1
@@ -243,7 +243,8 @@ static int pmic_glink_rpmsg_probe(struct rpmsg_device *rpdev)guard (mutex)(&__pmic_glink_lock); pg = __pmic_glink;if (!pg) -return dev_err_probe (&rpdev->dev, -ENODEV ,"no pmic_glink device to attach to\n" ); +return dev_err_probe (&rpdev->dev, -EPROBE_DEFER , +"no pmic_glink device to attach to\n" );dev_set_drvdata (&rpdev->dev, pg);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 862/1756 soc: qcom: pmic_pdcharger_ulog: prevent work requeue during remove
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yibo Tan <[email protected]>
[ Upstream commit 66894a1c51366cc2d5c498178105dfe3bcccc1e4 ]
pmic_pdcharger_ulog_rpmsg_remove() cancels the delayed worker while the RPMsg endpoint can still deliver callbacks. The RPMsg core invokes the driver remove callback before destroying the endpoint, so a response callback can run after cancel_delayed_work_sync() returns and queue the worker again.
Device cleanup then frees the devm-allocated pmic_pdcharger_ulog while the requeued delayed work still embeds and dereferences that object. KASAN reports a slab-use-after-free in pmic_pdcharger_ulog_work().
Use disable_delayed_work_sync() to drain the worker and reject queue attempts that race with removal.
The issue was reproduced in four of four runs with the real target driver, RPMsg bus removal, endpoint teardown, workqueue code and devres cleanup. The test provider delivered a valid response in the window between the driver remove callback and endpoint destruction. With this change, the same late callback occurred in four of four runs without a KASAN report, warning, Oops or panic.
The reproducer uses a test RPMsg provider to control the teardown timing. No unprivileged trigger or physical Qualcomm-device result is claimed.
--- drivers/soc/qcom/pmic_pdcharger_ulog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/soc/qcom/pmic_pdcharger_ulog.c +1 -1
@@ -143,7 +143,7 @@ static void pmic_pdcharger_ulog_rpmsg_remove(struct rpmsg_device *rpdev) {struct pmic_pdcharger_ulog *pg =dev_get_drvdata (&rpdev->dev); -cancel_delayed_work_sync (&pg->ulog_work); +disable_delayed_work_sync (&pg->ulog_work); }static const struct rpmsg_device_id pmic_pdcharger_ulog_rpmsg_id_match[] = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 863/1756 wifi: cfg80211: allow zero HE OBSS PD offsets
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dominic White <[email protected]>
[ Upstream commit d9ecaa0a31732014a128e3b03243de54bbbd8394 ]
IEEE Std 802.11 permits the OBSS PD offset fields in the Spatial Reuse Parameter Set element to have a value of zero. (IEEE Std 802.11-2024, 26.10.2.4)
The standard specifies the offsets as unsigned values added to -82 dBm, with field presence signalled independently. The valid offset range is therefore 0..20.
nl80211 currently rejects zero for all three HE OBSS PD offset attributes during nested netlink policy validation, before the values reach cfg80211 or the driver. Allow zero while retaining the upper bound and the existing minimum/maximum relationship validation.
--- net/wireless/nl80211.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/wireless/nl80211.c +3 -3
@@ -365,11 +365,11 @@ nl80211_pmsr_attr_policy[NL80211_PMSR_ATTR_MAX + 1] = {static const struct nla_policy he_obss_pd_policy[NL80211_HE_OBSS_PD_ATTR_MAX +1 ] = { [NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET ] = -NLA_POLICY_RANGE (NLA_U8 ,1 ,20 ), +NLA_POLICY_RANGE (NLA_U8 ,0 ,20 ), [NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET ] = -NLA_POLICY_RANGE (NLA_U8 ,1 ,20 ), +NLA_POLICY_RANGE (NLA_U8 ,0 ,20 ), [NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET ] = -NLA_POLICY_RANGE (NLA_U8 ,1 ,20 ), +NLA_POLICY_RANGE (NLA_U8 ,0 ,20 ), [NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP ] =NLA_POLICY_EXACT_LEN (8 ), [NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP] =
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 864/1756 wifi: b43: dont pass unterminated string to sscanf()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dan Carpenter <[email protected]>
[ Upstream commit 9b6cb072f9249e2cdb7c32be2b8069774c7e01e6 ]
The "buf" buffer is a PAGE_SIZE and allocated with kzalloc(). We store a string from the user in it and then pass it to sscanf() in the write functions such as shm32write__write_file(). Only a few numbers are stored in the buffer so it never comes close to filling up the whole PAGE_SIZE. Reserve the last character of the page for a NUL terminator.
This is debugfs so it's root only.
--- drivers/net/wireless/broadcom/b43/debugfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/broadcom/b43/debugfs.c +1 -1
@@ -561,7 +561,7 @@ static ssize_t b43_debugfs_write(struct file *file,if (!count)return 0 ; -if (count >PAGE_SIZE ) +if (count >=PAGE_SIZE )return -E2BIG ; dev = file->private_data;if (!dev)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 865/1756 wifi: b43legacy: debugfs: NUL terminate string in debugfs
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dan Carpenter <[email protected]>
[ Upstream commit f94595252b318a9ae3c01d78b3bcd33b01b1c082 ]
The "buf" buffer is PAGE_SIZE and allocated with kzalloc(). We store a string from the user in it and then pass it to sscanf() in the write functions such as tsf_write_file(). The buffer is only used to store a number so we never come close to filling up the whole PAGE_SIZE. Reserve the last character of the page for a NUL terminator.
This is debugfs so it's root only.
--- drivers/net/wireless/broadcom/b43legacy/debugfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/broadcom/b43legacy/debugfs.c +1 -1
@@ -263,7 +263,7 @@ static ssize_t b43legacy_debugfs_write(struct file *file,if (!count)return 0 ; -if (count >PAGE_SIZE ) +if (count >=PAGE_SIZE )return -E2BIG ; dev = file->private_data;if (!dev)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 866/1756 wifi: carl9170: NUL terminate string in debugfs
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dan Carpenter <[email protected]>
[ Upstream commit ece30e1daf6a9c95d6f9d0518534a0b9c8c7fd42 ]
The "buf" buffer comes from the user. We use it to store a number or two so it doesn't need to be large. It gets passed to sscanf() in the write functions such as carl9170_debugfs_erp_write(). Ensure that buffer is NUL terminated.
This is debugfs so it's root only.
--- drivers/net/wireless/ath/carl9170/debug.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/wireless/ath/carl9170/debug.c +3 -2
@@ -121,7 +121,7 @@ static ssize_t carl9170_debugfs_write(struct file *file,if (!count)return 0 ; -if (count >PAGE_SIZE ) +if (count >=PAGE_SIZE )return -E2BIG ; ar = file->private_data;
@@ -134,7 +134,7 @@ static ssize_t carl9170_debugfs_write(struct file *file,if (!dfops->write)return -ENOSYS ; - buf =vmalloc (count); + buf =vmalloc (count +1 );if (!buf)return -ENOMEM ;
@@ -142,6 +142,7 @@ static ssize_t carl9170_debugfs_write(struct file *file, err = -EFAULT ; goto out_free; } + buf[count] ='\0' ;if (mutex_trylock (&ar->mutex) ==0 ) { err = -EAGAIN ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 867/1756 Revert "wifi: mac80211: do not use old MBSSID elements"
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aloka Dixit <[email protected]>
[ Upstream commit 56fb2334c86cef0b6d44099a6b21de4c8d80a7cb ]
Commit a519be2f5d95 ("wifi: mac80211: do not use old MBSSID elements") fixed the incorrect inclusion of stopped/removed non-transmitted profiles from the Beacon frames, but it caused a regression for channel switch (CSA) and BSS color change (CCA) operations initiated from hostapd.
Hostapd passes two Beacon templates to kernel for CSA and CCA -
(1) beacon_csa/beacon_color_change used during the countdown.
(2) beacon_after/beacon_next used after the countdown completes. Hostapd relies on the kernel to include the old MBSSID elements while sending beacon_csa/beacon_color_change templates to the driver.
This path is now broken and results in CSA/CCA failure.
Including existing MBSSID elements explicitly makes the netlink buffer larger than default 4 KB depending on the number of APs which would need unnecessary complication to pre-calculate the buffer length.
Revert the commit to fix the regression.
Regarding the original issue fixed by the reverted commit - Hostapd now has a new commit which always includes at least one MBSSID element when the feature is enabled, hence when all non-transmitted profiles are removed, this empty element ensures that stopped profiles are not advertised.
--- net/mac80211/cfg.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
net/mac80211/cfg.c +10 -0
@@ -1165,6 +1165,7 @@ ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata, size =sizeof (*new) + new_head_len + new_tail_len; +/* new or old multiple BSSID elements? */ if (params->mbssid_ies) { mbssid = params->mbssid_ies; size +=struct_size (new->mbssid_ies, elem, mbssid->cnt);
@@ -1174,6 +1175,15 @@ ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata, } size +=ieee80211_get_mbssid_beacon_len (mbssid, rnr, mbssid->cnt); + }else if (old && old->mbssid_ies) { + mbssid = old->mbssid_ies; + size +=struct_size (new->mbssid_ies, elem, mbssid->cnt); +if (old && old->rnr_ies) { + rnr = old->rnr_ies; + size +=struct_size (new->rnr_ies, elem, rnr->cnt); + } + size +=ieee80211_get_mbssid_beacon_len (mbssid, rnr, + mbssid->cnt); } new =kzalloc (size,GFP_KERNEL );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 868/1756 dmaengine: ioat: disable relaxed ordering before registering the device
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Logan Gunthorpe <[email protected]>
[ Upstream commit 10d34fbca6e09a6a18d64fa3ebaa3db9f27fc1a6 ]
ioat3_dma_probe() disabled PCIe relaxed ordering after calling dma_async_device_register(), so if an error occurs and the code jumps to err_disable_interrupts, the function returns with the device still registered in the core's dma_device_list while the caller frees the ioatdma_device struct, leaving a dangling registration that anything walking the device list can dereference after it's been freed.
Move the capability read/write ahead of dma_async_device_register() instead. Nothing after registration depends on relaxed ordering already being disabled, and nothing before it depends on the device being registered, so this is a plain reordering. It also means every remaining step after registration can't fail, so there's no need to ever have to unregister the device once registered.
--- drivers/dma/ioat/init.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/dma/ioat/init.c +9 -9
@@ -1170,15 +1170,6 @@ static int ioat3_dma_probe(struct ioatdma_device *ioat_dma, int dca) ioat_chan->reg_base + IOAT_DCACTRL_OFFSET); } - err =dma_async_device_register (&ioat_dma->dma_dev); -if (err) - goto err_disable_interrupts; - -ioat_kobject_add (ioat_dma, &ioat_ktype); - -if (dca) - ioat_dma->dca =ioat_dca_init (pdev, ioat_dma->reg_base); -/* disable relaxed ordering */ err =pcie_capability_read_word (pdev,PCI_EXP_DEVCTL , &val16);if (err) {
@@ -1194,6 +1185,15 @@ static int ioat3_dma_probe(struct ioatdma_device *ioat_dma, int dca) goto err_disable_interrupts; } + err =dma_async_device_register (&ioat_dma->dma_dev); +if (err) + goto err_disable_interrupts; + +ioat_kobject_add (ioat_dma, &ioat_ktype); + +if (dca) + ioat_dma->dca =ioat_dca_init (pdev, ioat_dma->reg_base); +if (ioat_dma->cap &IOAT_CAP_DPS )writeb (ioat_pending_level +1 , ioat_dma->reg_base +IOAT_PREFETCH_LIMIT_OFFSET );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 869/1756 dmaengine: plx_dma: fix NULL pointer deref in plx_dma_isr()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Logan Gunthorpe <[email protected]>
[ Upstream commit f3017892457d8bb664ea4b912910dc254e2dd825 ]
plx_dma_create() registered the interrupt handler with request_irq() before initializing plxdev->bar. If the device raised an interrupt in that window, plx_dma_isr() would dereference the still-NULL bar.
Move the bar assignment ahead of request_irq() so everything the handler can touch is initialized before it can run.
--- drivers/dma/plx_dma.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/dma/plx_dma.c +5 -5
@@ -505,17 +505,17 @@ static int plx_dma_create(struct pci_dev *pdev)if (!plxdev)return -ENOMEM ; - rc =request_irq (pci_irq_vector (pdev,0 ), plx_dma_isr,0 , -KBUILD_MODNAME , plxdev); -if (rc) - goto free_plx; -spin_lock_init (&plxdev->ring_lock);tasklet_setup (&plxdev->desc_task, plx_dma_desc_task);RCU_INIT_POINTER (plxdev->pdev, pdev); plxdev->bar =pcim_iomap_table (pdev)[0 ]; + rc =request_irq (pci_irq_vector (pdev,0 ), plx_dma_isr,0 , +KBUILD_MODNAME , plxdev); +if (rc) + goto free_plx; + dma = &plxdev->dma_dev;INIT_LIST_HEAD (&dma->channels);dma_cap_set (DMA_MEMCPY , dma->cap_mask);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 870/1756 SUNRPC: reject a client-side TLS alert record that is not two octets
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 1e87497aac8d2d4aee9b288ba43f58d1690b9a89 ]
tls_alert_recv() reads two octets from the kvec it is handed and does not check the length (net/handshake/alert.c). xs_sock_process_cmsg() calls it for any alert record, and the alert[] buffer that xs_sock_recv_cmsg() supplies carries no initializer. A one-octet alert body leaves the description read from uninitialized stack and reported through trace_tls_alert_recv().
The peer controls that length. Neither tls_rx_msg_size() nor tls_rx_one_record() enforces the two-octet Alert payload. A TLS 1.3 record carrying only the inner content-type octet decrypts to a zero-length payload. RFC 8446 Section 5.1 requires a record with an Alert type to carry exactly one message, so any other length is malformed. RFC 9289 Section 5 bars RPC-with-TLS from negotiating a version below TLS 1.3, so no other alert framing applies.
Require exactly two octets before parsing and return -EACCES otherwise. xs_stream_data_receive() already treats -EACCES as a fatal alert and reports it to the pending tasks. Gate the path on a control message rather than a positive count so that a zero-length record reaches the check.
--- net/sunrpc/xprtsock.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
net/sunrpc/xprtsock.c +18 -2
@@ -407,9 +407,25 @@ xs_sock_recv_cmsg(struct socket *sock, unsigned int *msg_flags, int flags)iov_iter_kvec (&msg.msg_iter,ITER_DEST , &alert_kvec,1 , alert_kvec.iov_len); ret =sock_recvmsg (sock, &msg, flags); -if (ret >0 ) { -if (tls_get_record_type (sock->sk, &u.cmsg) ==TLS_RECORD_TYPE_ALERT ) +/* put_cmsg() shrinks msg_controllen, so a short one means +* kTLS filled in u.cmsg. +*/ +if (ret >=0 && msg.msg_controllen <sizeof (u)) { +if (tls_get_record_type (sock->sk, &u.cmsg) == +TLS_RECORD_TYPE_ALERT ) { +/* RFC 8446 Section 5.1 requires a record with an +* Alert type to carry exactly one message. An alert +* is two octets. tls_alert_recv() reads both without +* checking the length. alert_kvec caps the count at +* two, so a longer record fills it as well. kTLS +* sets MSG_EOR only once the record has been +* drained. +*/ +if (ret !=sizeof (alert) || + !(msg.msg_flags &MSG_EOR )) +return -EACCES ;iov_iter_revert (&msg.msg_iter, ret); + } ret =xs_sock_process_cmsg (sock, &msg, msg_flags, &u.cmsg, -EAGAIN ); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 871/1756 SUNRPC: treat every client-side TLS error alert as fatal
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 9b7b1f89b93a3ec1ed121e1ab28450acde815bff ]
xs_sock_process_cmsg() decides whether an alert ends the session by reading the alert's level octet. RFC 8446 Section 6 retired that field. The severity is implicit in the description, and a receiver treats every alert listed in Section 6.2 as an error alert "regardless of the AlertLevel in the message". A peer that aborts with unexpected_message but leaves the legacy octet set to warning makes the client return -EAGAIN. xs_stream_data_receive() wakes no pending task for that error, so RPC Calls queued on a dead TLS session wait for their timeouts to expire.
Decide from the alert description instead. close_notify and user_canceled are the closure alerts (RFC 8446 Section 6.1). Every other description ends the session, including one this kernel does not recognize.
--- net/sunrpc/xprtsock.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
net/sunrpc/xprtsock.c +12 -2
@@ -375,8 +375,18 @@ xs_sock_process_cmsg(struct socket *sock, struct msghdr *msg,break ;case TLS_RECORD_TYPE_ALERT :tls_alert_recv (sock->sk, msg, &level, &description); - ret = (level ==TLS_ALERT_LEVEL_FATAL ) ? - -EACCES : -EAGAIN ; +/* RFC 8446 Section 6: every alert but a closure alert is +* an error alert, whatever the legacy AlertLevel octet +* says. +*/ +switch (description) { +case TLS_ALERT_DESC_CLOSE_NOTIFY : +case TLS_ALERT_DESC_USER_CANCELED : + ret = -EAGAIN ; +break ; +default : + ret = -EACCES ; + }break ;default :/* discard this record type */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 872/1756 NFS: filelayout: calculate dense stripe width in 64 bits
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jérémy Jean <[email protected]>
[ Upstream commit 9ba13ef0e3ad033d3ddbaeb740b12d135a88363d ]
filelayout_get_dense_offset() calculates the stripe width from the stripe unit and count, where both values are provided by the server. Their product is stored on 32 bits, and can wrap to zero despite passing individual checks. For example, a 1 GiB stripe unit (0x40000000) and four stripes (4) cause the following div_u64() to raise a divide error during the first read through the dense layout.
Update u32 to u64 and use div64_u64() instead of div_u64(). stripe_unit is a u32 and stripe_count is limited to 4096, so the product cannot overflow a u64.
--- fs/nfs/filelayout/filelayout.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/nfs/filelayout/filelayout.c +3 -2
@@ -55,12 +55,13 @@ static loff_t filelayout_get_dense_offset(struct nfs4_filelayout_segment *flseg, loff_t offset) { -u32 stripe_width = flseg->stripe_unit * flseg->dsaddr->stripe_count; +u64 stripe_width = (u64 )flseg->stripe_unit * + flseg->dsaddr->stripe_count;u64 stripe_no;u32 rem; offset -= flseg->pattern_offset; - stripe_no =div_u64 (offset, stripe_width); + stripe_no =div64_u64 (offset, stripe_width);div_u64_rem (offset, flseg->stripe_unit, &rem);return stripe_no * flseg->stripe_unit + rem;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 873/1756 floppy: flush pending work before releasing resources on init failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit 74c2e2eeb7e51cdeb5e3eceaf324cfcf8dcd0d32 ]
do_floppy_init() probes each FDC with user_reset_fdc(), which queues a redo_fd_request() work item on floppy_wq that may still be pending when the probe finishes. When no controller is found, the error path calls floppy_release_irq_and_dma() to free the IRQ and DMA channel, and only later destroys the workqueue. destroy_workqueue() drains the queued work last, so it can run after the IRQ and DMA are already gone:
floppy0: no floppy controllers found
work still pending
The flush used to be here. Commit 070ad7e793dc ("floppy: convert to delayed work and single-thread wq") renamed the label out_flush_work to out_release_dma and dropped it. Restore it so the work drains before the IRQ and DMA are released, as floppy_module_exit() already does.
--- drivers/block/floppy.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/block/floppy.c +2 -0
@@ -4751,6 +4751,8 @@ static int __init do_floppy_init(void) } } out_release_dma: +/* Drain the queued redo_fd_request() before releasing IRQ and DMA. */ +flush_workqueue (floppy_wq);if (atomic_read (&usage_count))floppy_release_irq_and_dma (); out_unreg_driver:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 874/1756 floppy: avoid NULL deref in reset_interrupt when cont is cleared
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yang Xiuwei <[email protected]>
[ Upstream commit 7c82781039c03a3e47b70d3259f336adbb9d2692 ]
reset_fdc() arms do_floppy = reset_interrupt; the IRQ handler then queues that function via schedule_bh(). If unlock_fdc() or do_wakeup() clears cont before the work runs, reset_interrupt() dereferences a NULL cont and oopses.
Example crash excerpt:
[ 1070.468148] status=80 [ 1070.468152] fdc_busy=1 [ 1070.468158] cont= (null) [ 1070.468161] current_req= (null) [ 1070.468162] command_status=-1 [ 1070.468163] [ 1070.557051] floppy0: floppy timeout called [ 1070.557053] no cont in shutdown! [ 1070.557056] floppy0: floppy_shutdown: timeout handler died. [ 1074.419509] floppy0: FDC access conflict! [ 1074.419782] BUG: unable to handle kernel NULL pointer dereference at 0000000000000008 [ 1074.421969] PGD 0 P4D 0 [ 1074.422320] Oops: 0000 [#1] SMP NOPTI [ 1074.422648] CPU: 10 PID: 3269 Comm: kworker/u256:4 Kdump: loaded [ 1074.423830] Hardware name: inspur Standard PC (i440FX + PIIX, 1996), BIOS 0.0.0 02/06/2015 [ 1074.424284] Workqueue: floppy floppy_work_workfn [floppy] [ 1074.424757] RIP: 0010:reset_interrupt+0x3a/0xa0 [floppy]
The same NULL deref has also been reported by syzbot on upstream.
Return early if cont is already NULL after result(). The hardware reset has completed; result() still drains the FDC. A later request can lock the FDC and reset again. This is a defensive fix for stale work, not a rewrite of the floppy continuation state machine.
--- drivers/block/floppy.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/block/floppy.c +3 -0
@@ -1788,6 +1788,9 @@ static void reset_interrupt(void) {debugt (__func__,"" );result (current_fdc);/* get the status ready for set_fdc */ +/* Stale work: unlock_fdc()/do_wakeup() may have cleared cont. */ +if (!cont) +return ;if (fdc_state[current_fdc].reset) {pr_info ("reset set in interrupt, calling %ps\n" , cont->error); cont->error ();/* a reset just after a reset. BAD! */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 875/1756 floppy: unregister platform device on add_disk failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
[ Upstream commit f1e72d80ad4ac5ff3573796d07bd1a1e74909f94 ]
The change referenced by the Fixes tag reverted a previous fix because that fix added incorrect cleanup for the platform_device_register() failure path.
However, reverting the whole change also removed the cleanup for a later failure path. If platform_device_register() succeeds but device_add_disk() fails, the current floppy platform device has already been registered and registered[drive] has been set.
The common out_remove_drives path uses while (drive--), so it starts from the previous drive and does not unregister the current one. As a result, the platform device registered for the failing drive is leaked.
Unregister the current platform device directly on the device_add_disk() failure path, where platform_device_register() is known to have succeeded. Leave the platform_device_register() failure path unchanged.
--- drivers/block/floppy.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/block/floppy.c +4 -1
@@ -4739,8 +4739,11 @@ static int __init do_floppy_init(void) err =device_add_disk (&floppy_device[drive].dev, disks[drive][0 ],NULL ); -if (err) +if (err) { +platform_device_unregister (&floppy_device[drive]); + registered[drive] = false; goto out_remove_drives; + } }return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 876/1756 wifi: ath12k: Reserve space for a string terminator
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiale Yao <[email protected]>
[ Upstream commit 13b15eabe2c541b80406166964cdc8ccb5e9c32a ]
ath12k_write_htt_stats_type() accepts count == size, which fills the zero-initialized buffer without a terminating NUL. sscanf() then reads beyond the buffer.
Reject input that leaves no room for the trailing NUL.
--- drivers/net/wireless/ath/ath12k/debugfs_htt_stats.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ath/ath12k/debugfs_htt_stats.c +1 -1
@@ -1646,7 +1646,7 @@ static ssize_t ath12k_write_htt_stats_type(struct file *file,const int size =32 ;int num_args; -if (count > size) +if (count >= size)return -EINVAL ; char *buf __free(kfree) = kzalloc(size, GFP_KERNEL);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 877/1756 drm/msm/a6xx: fix use-after-free of OPP in a6xx_pm_resume
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Roman Demidov <[email protected]>
[ Upstream commit 8128ae7af6b4dc95e486c5c0a80839a069df578e ]
The OPP reference obtained via dev_pm_opp_find_freq_ceil() is dropped with dev_pm_opp_put() before being passed to dev_pm_opp_set_opp(). If the reference count reaches zero, the OPP object may be freed, leading to a use-after-free when dev_pm_opp_set_opp() dereferences it.
Fix the order of calls: first use the OPP to set the required performance state, then release the reference.
Patchwork: https://patchwork.freedesktop.org/patch/757104/
Message-ID: <[email protected]>
--- drivers/gpu/drm/msm/adreno/a6xx_gpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +1 -1
@@ -1879,10 +1879,10 @@ static int a6xx_pm_resume(struct msm_gpu *gpu) ret =PTR_ERR (opp); goto err_set_opp; } -dev_pm_opp_put (opp);/* Set the core clock and bus bw, having VDD scaling in mind */ dev_pm_opp_set_opp (&gpu->pdev->dev, opp); +dev_pm_opp_put (opp);pm_runtime_resume_and_get (gmu->dev);pm_runtime_resume_and_get (gmu->gxpd);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 878/1756 dmaengine: ste_dma40: Fix physical cyclic capability
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Walleij <[email protected]>
[ Upstream commit 11101a8e3e42273a5910a149f6324040b88f4747 ]
d40_dmaengine_init() configures dma_both for physical channels that can handle both slave and memcpy transfers. Physical DMA40 channel setup has supported cyclic LLIs since cyclic transfer support was added, but the DMA_CYCLIC capability is set on dma_slave a second time instead of dma_both.
Set DMA_CYCLIC on dma_both so d40_ops_init() installs device_prep_dma_cyclic and physical channels advertise cyclic support.
--- drivers/dma/ste_dma40.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/ste_dma40.c +1 -1
@@ -2907,7 +2907,7 @@ static int __init d40_dmaengine_init(struct d40_base *base,dma_cap_zero (base->dma_both.cap_mask);dma_cap_set (DMA_SLAVE , base->dma_both.cap_mask);dma_cap_set (DMA_MEMCPY , base->dma_both.cap_mask); -dma_cap_set (DMA_CYCLIC , base->dma_slave.cap_mask); +dma_cap_set (DMA_CYCLIC , base->dma_both.cap_mask);d40_ops_init (base, &base->dma_both); err =dmaenginem_async_device_register (&base->dma_both);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 879/1756 dmaengine: ste_dma40: Fix failed start cleanup
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Walleij <[email protected]>
[ Upstream commit 8175ead5727173d4b96d1e830e696765d75ade71 ]
If d40_start() fails after a queued descriptor has been moved to the active list, d40_queue_start() currently returns NULL without unwinding the transfer state or clearing the channel busy flag.
Fix this pre-existing error path by completing the descriptor through the normal tasklet path, clearing the busy flag, balancing the runtime PM reference and returning an error pointer to distinguish the failure from the no-work case. Do not free the descriptor directly, since it has already been submitted and has a DMA cookie.
When starting the next queued transfer from the completion handler, put the completed descriptor on the done list first. This preserves FIFO completion order if the new transfer fails to start and prevents the completed cookie from moving backwards.
Use done-list membership rather than the cyclic flag to identify terminal descriptors in the tasklet. A cyclic descriptor that failed to start is then completed and removed instead of remaining permanently at the head of the done list.
--- drivers/dma/ste_dma40.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-)
drivers/dma/ste_dma40.c +17 -8
@@ -1533,8 +1533,15 @@ static struct d40_desc *d40_queue_start(struct d40_chan *d40c)/* Start dma job */ err =d40_start (d40c); -if (err) -return NULL ; +if (err) { +d40_desc_remove (d40d); +d40_desc_done (d40c, d40d); + d40c->pending_tx++; + d40c->busy = false; +pm_runtime_put_autosuspend (d40c->base->dev); +tasklet_schedule (&d40c->tasklet); +return ERR_PTR (err); + } }return d40d;
@@ -1578,15 +1585,15 @@ static void dma_tc_handle(struct d40_chan *d40c)return ; } +d40_desc_remove (d40d); +d40_desc_done (d40c, d40d); +if (d40_queue_start (d40c) ==NULL ) { d40c->busy = false;pm_runtime_mark_last_busy (d40c->base->dev);pm_runtime_put_autosuspend (d40c->base->dev); } - -d40_desc_remove (d40d); -d40_desc_done (d40c, d40d); } d40c->pending_tx++;
@@ -1600,20 +1607,22 @@ static void dma_tasklet(struct tasklet_struct *t)struct d40_desc *d40d;unsigned long flags;bool callback_active; +bool from_done;struct dmaengine_desc_callback cb;spin_lock_irqsave (&d40c->lock, flags);/* Get first entry from the done list */ d40d =d40_first_done (d40c); -if (d40d ==NULL ) { + from_done = !!d40d; +if (!from_done) {/* Check if we have reached here for cyclic job */ d40d =d40_first_active_get (d40c);if (d40d ==NULL || !d40d->cyclic) goto check_pending_tx; } -if (!d40d->cyclic) +if (from_done)dma_cookie_complete (&d40d->txd);/*
@@ -1629,7 +1638,7 @@ static void dma_tasklet(struct tasklet_struct *t) callback_active = !!(d40d->txd.flags &DMA_PREP_INTERRUPT );dmaengine_desc_get_callback (&d40d->txd, &cb); -if (!d40d->cyclic) { +if (from_done) {if (async_tx_test_ack (&d40d->txd)) {d40_desc_remove (d40d);d40_desc_free (d40c, d40d);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 880/1756 dmaengine: ste_dma40: Fix probe runtime PM disable
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Walleij <[email protected]>
[ Upstream commit c6809b381e34f8966cc3d9e5d7d658775a408f83 ]
Some d40_probe() error paths jump to destroy_cache before runtime PM has been enabled for the DMA controller device. The label unconditionally calls pm_runtime_disable(), which increments disable_depth even though this probe attempt never enabled runtime PM.
Use devm_pm_runtime_set_active_enabled() to mark the controller active, enable runtime PM and register balanced cleanup for probe failure. This avoids both the disable-depth imbalance and ad-hoc probe state tracking.
The interrupt handler uses pm_runtime_get_if_active() and cannot acknowledge a pending interrupt while runtime PM is disabled. Request the IRQ only after enabling runtime PM so the handler cannot enter an unacknowledged interrupt loop during probe.
--- drivers/dma/ste_dma40.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)
drivers/dma/ste_dma40.c +13 -10
@@ -3602,12 +3602,6 @@ static int __init d40_probe(struct platform_device *pdev) goto destroy_cache; } - ret =request_irq (base->irq, d40_handle_interrupt,0 ,D40_NAME , base); -if (ret) { -d40_err (dev,"No IRQ defined\n" ); - goto destroy_cache; - } -if (base->plat_data->use_esram_lcla) { base->lcpa_regulator =regulator_get (base->dev,"lcla_esram" );
@@ -3632,10 +3626,20 @@ static int __init d40_probe(struct platform_device *pdev)pm_runtime_irq_safe (base->dev);pm_runtime_set_autosuspend_delay (base->dev,DMA40_AUTOSUSPEND_DELAY ); -pm_runtime_use_autosuspend (base->dev);pm_runtime_mark_last_busy (base->dev); -pm_runtime_set_active (base->dev); -pm_runtime_enable (base->dev); + + ret =devm_pm_runtime_set_active_enabled (base->dev); +if (ret) { +d40_err (dev,"Failed to enable runtime PM: %d\n" , ret); + goto destroy_cache; + } +pm_runtime_use_autosuspend (base->dev); + + ret =request_irq (base->irq, d40_handle_interrupt,0 ,D40_NAME , base); +if (ret) { +d40_err (dev,"No IRQ defined\n" ); + goto destroy_cache; + } ret =d40_dmaengine_init (base, num_reserved_chans);if (ret)
@@ -3671,7 +3675,6 @@ static int __init d40_probe(struct platform_device *pdev)regulator_disable (base->lcpa_regulator);regulator_put (base->lcpa_regulator); } -pm_runtime_disable (base->dev); report_failure:d40_err (dev,"probe failed\n" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 881/1756 dmaengine: ste_dma40: Check runtime PM in IRQ
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Walleij <[email protected]>
[ Upstream commit 12787e3f2f93f3af59769b08ee4fcb044531120b ]
d40_handle_interrupt() reads DMA40 interrupt registers unconditionally. A spurious interrupt can arrive while the device is runtime suspended, after dma40_runtime_suspend() has disabled the GCC clock.
Avoid touching the registers unless the device is runtime active by taking a conditional runtime PM reference. Return IRQ_NONE when the device is suspended, and drop the reference after handling an active interrupt.
When CONFIG_PM is disabled, pm_runtime_get_if_active() returns -EINVAL even though the registers remain accessible. Keep handling interrupts in that configuration and only drop the runtime PM reference when one was acquired.
--- drivers/dma/ste_dma40.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/dma/ste_dma40.c +8 -0
@@ -1679,6 +1679,11 @@ static irqreturn_t d40_handle_interrupt(int irq, void *data)u32 *regs = base->regs_interrupt;struct d40_interrupt_lookup *il = base->gen_dmac.il;u32 il_size = base->gen_dmac.il_size; +int ret; + + ret =pm_runtime_get_if_active (base->dev); +if (IS_ENABLED (CONFIG_PM ) && ret <=0 ) +return IRQ_NONE ;spin_lock (&base->interrupt_lock);
@@ -1727,6 +1732,9 @@ static irqreturn_t d40_handle_interrupt(int irq, void *data)spin_unlock (&base->interrupt_lock); +if (ret >0 ) +pm_runtime_put_autosuspend (base->dev); +return IRQ_HANDLED ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 882/1756 dmaengine: ste_dma40: Remove redundant pm_runtime_mark_last_busy() calls
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sakari Ailus <[email protected]>
[ Upstream commit 01f2bcf06d7e0e3c4badd03c030cf634ca10a172 ]
pm_runtime_put_autosuspend(), pm_runtime_put_sync_autosuspend(), pm_runtime_autosuspend() and pm_request_autosuspend() now include a call to pm_runtime_mark_last_busy(). Remove the now-reduntant explicit call to pm_runtime_mark_last_busy().
Stable-dep-of: 55a35231b8ce ("dmaengine: ste_dma40: Handle runtime PM resume errors")
--- drivers/dma/ste_dma40.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)
drivers/dma/ste_dma40.c +2 -12
@@ -1452,7 +1452,6 @@ static int d40_pause(struct dma_chan *chan) res =d40_channel_execute_command (d40c,D40_DMA_SUSPEND_REQ ); -pm_runtime_mark_last_busy (d40c->base->dev);pm_runtime_put_autosuspend (d40c->base->dev);spin_unlock_irqrestore (&d40c->lock, flags);return res;
@@ -1479,7 +1478,6 @@ static int d40_resume(struct dma_chan *chan)if (d40_residue (d40c) ||d40_tx_is_linked (d40c)) res =d40_channel_execute_command (d40c,D40_DMA_RUN ); -pm_runtime_mark_last_busy (d40c->base->dev);pm_runtime_put_autosuspend (d40c->base->dev);spin_unlock_irqrestore (&d40c->lock, flags);return res;
@@ -1591,7 +1589,6 @@ static void dma_tc_handle(struct d40_chan *d40c)if (d40_queue_start (d40c) ==NULL ) { d40c->busy = false; -pm_runtime_mark_last_busy (d40c->base->dev);pm_runtime_put_autosuspend (d40c->base->dev); } }
@@ -2071,16 +2068,13 @@ static int d40_free_dma(struct d40_chan *d40c)else d40c->base->lookup_phy_chans[phy->num] =NULL ; -if (d40c->busy) { -pm_runtime_mark_last_busy (d40c->base->dev); +if (d40c->busy)pm_runtime_put_autosuspend (d40c->base->dev); - } d40c->busy = false; d40c->phy_chan =NULL ; d40c->configured = false; mark_last_busy: -pm_runtime_mark_last_busy (d40c->base->dev);pm_runtime_put_autosuspend (d40c->base->dev);return res; }
@@ -2483,7 +2477,6 @@ static int d40_alloc_chan_resources(struct dma_chan *chan)if (is_free_phy)d40_config_write (d40c); mark_last_busy: -pm_runtime_mark_last_busy (d40c->base->dev);pm_runtime_put_autosuspend (d40c->base->dev);spin_unlock_irqrestore (&d40c->lock, flags);return err;
@@ -2635,12 +2628,9 @@ static int d40_terminate_all(struct dma_chan *chan)chan_err (d40c,"Failed to stop channel\n" );d40_term_all (d40c); -pm_runtime_mark_last_busy (d40c->base->dev);pm_runtime_put_autosuspend (d40c->base->dev); -if (d40c->busy) { -pm_runtime_mark_last_busy (d40c->base->dev); +if (d40c->busy)pm_runtime_put_autosuspend (d40c->base->dev); - } d40c->busy = false;spin_unlock_irqrestore (&d40c->lock, flags);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 883/1756 dmaengine: ste_dma40: Handle runtime PM resume errors
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Walleij <[email protected]>
[ Upstream commit 55a35231b8ced2250a7743ec350a9566d553780e ]
Several channel operations use pm_runtime_get_sync() and access DMA40 registers without checking whether runtime resume succeeded. If resume fails, the registers may be inaccessible. pm_runtime_get_sync() also increments the usage counter on failure, making error unwinding easy to unbalance.
Use pm_runtime_resume_and_get() and avoid register access when resume fails. Acquire the runtime PM reference before allocating a channel so failure needs no channel-allocation rollback.
If a queued transfer cannot be started because resume failed, retire all issued descriptors through the normal tasklet path. Since dma_async_issue_pending() cannot return an error, leaving them queued would make clients wait indefinitely for callbacks.
Termination and channel release must also clean up software state when the controller cannot resume. d40_term_all() only releases descriptor state and does not access DMA40 registers, so it remains unconditional.
Balance each transient runtime PM reference in its successful acquisition block, without bookkeeping flags. Release the outstanding busy reference and channel allocation state when freeing a channel. Skip only the hardware stop that requires register access.
--- drivers/dma/ste_dma40.c | 74 +++++++++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 22 deletions(-)
drivers/dma/ste_dma40.c +52 -22
@@ -1448,11 +1448,14 @@ static int d40_pause(struct dma_chan *chan)return 0 ;spin_lock_irqsave (&d40c->lock, flags); -pm_runtime_get_sync (d40c->base->dev); + res =pm_runtime_resume_and_get (d40c->base->dev); +if (res <0 ) + goto unlock; res =d40_channel_execute_command (d40c,D40_DMA_SUSPEND_REQ );pm_runtime_put_autosuspend (d40c->base->dev); + unlock:spin_unlock_irqrestore (&d40c->lock, flags);return res; }
@@ -1472,13 +1475,16 @@ static int d40_resume(struct dma_chan *chan)return 0 ;spin_lock_irqsave (&d40c->lock, flags); -pm_runtime_get_sync (d40c->base->dev); + res =pm_runtime_resume_and_get (d40c->base->dev); +if (res <0 ) + goto unlock;/* If bytes left to transfer or linked tx resume job */ if (d40_residue (d40c) ||d40_tx_is_linked (d40c)) res =d40_channel_execute_command (d40c,D40_DMA_RUN );pm_runtime_put_autosuspend (d40c->base->dev); + unlock:spin_unlock_irqrestore (&d40c->lock, flags);return res; }
@@ -1515,8 +1521,20 @@ static struct d40_desc *d40_queue_start(struct d40_chan *d40c)if (d40d !=NULL ) {if (!d40c->busy) { + err =pm_runtime_resume_and_get (d40c->base->dev); +if (err <0 ) { +chan_err (d40c,"Failed to resume DMA: %d\n" , + err); +do { +d40_desc_remove (d40d); +d40_desc_done (d40c, d40d); + d40c->pending_tx++; + d40d =d40_first_queued (d40c); + }while (d40d); +tasklet_schedule (&d40c->tasklet); +return ERR_PTR (err); + } d40c->busy = true; -pm_runtime_get_sync (d40c->base->dev); }/* Remove from queue */
@@ -2030,9 +2048,6 @@ static int d40_free_dma(struct d40_chan *d40c)struct d40_phy_res *phy = d40c->phy_chan;bool is_src; -/* Terminate all queued and active transfers */ -d40_term_all (d40c); -if (phy ==NULL ) {chan_err (d40c,"phy == null\n" );return -EINVAL ;
@@ -2054,11 +2069,18 @@ static int d40_free_dma(struct d40_chan *d40c)return -EINVAL ; } -pm_runtime_get_sync (d40c->base->dev); - res =d40_channel_execute_command (d40c,D40_DMA_STOP ); -if (res) { -chan_err (d40c,"stop failed\n" ); - goto mark_last_busy; +/* Release descriptor state; this does not access DMA40 registers. */ +d40_term_all (d40c); + + res =pm_runtime_resume_and_get (d40c->base->dev); +if (res >=0 ) { + res =d40_channel_execute_command (d40c,D40_DMA_STOP ); +if (res) +chan_err (d40c,"stop failed\n" ); + +pm_runtime_put_autosuspend (d40c->base->dev); +if (res) +return res; }d40_alloc_mask_free (phy, is_src,chan_is_logical (d40c) ? event :0 );
@@ -2074,8 +2096,6 @@ static int d40_free_dma(struct d40_chan *d40c) d40c->busy = false; d40c->phy_chan =NULL ; d40c->configured = false; - mark_last_busy: -pm_runtime_put_autosuspend (d40c->base->dev);return res; }
@@ -2434,10 +2454,14 @@ static int d40_alloc_chan_resources(struct dma_chan *chan) err =d40_config_memcpy (d40c);if (err) {chan_err (d40c,"Failed to configure memcpy channel\n" ); - goto mark_last_busy; + goto unlock; } } + err =pm_runtime_resume_and_get (d40c->base->dev); +if (err <0 ) + goto unlock; + err =d40_allocate_channel (d40c, &is_free_phy);if (err) {chan_err (d40c,"Failed to allocate channel\n" );
@@ -2445,8 +2469,6 @@ static int d40_alloc_chan_resources(struct dma_chan *chan) goto mark_last_busy; } -pm_runtime_get_sync (d40c->base->dev); -d40_set_prio_realtime (d40c);if (chan_is_logical (d40c)) {
@@ -2478,6 +2500,7 @@ static int d40_alloc_chan_resources(struct dma_chan *chan)d40_config_write (d40c); mark_last_busy:pm_runtime_put_autosuspend (d40c->base->dev); + unlock:spin_unlock_irqrestore (&d40c->lock, flags);return err; }
@@ -2622,19 +2645,26 @@ static int d40_terminate_all(struct dma_chan *chan)spin_lock_irqsave (&d40c->lock, flags); -pm_runtime_get_sync (d40c->base->dev); - ret =d40_channel_execute_command (d40c,D40_DMA_STOP ); -if (ret) -chan_err (d40c,"Failed to stop channel\n" ); + ret =pm_runtime_resume_and_get (d40c->base->dev); +if (ret >=0 ) { + ret =d40_channel_execute_command (d40c,D40_DMA_STOP ); +if (ret) +chan_err (d40c,"Failed to stop channel\n" ); + +pm_runtime_put_autosuspend (d40c->base->dev); + } +/* +* Always release software state, even when the controller cannot +* resume. d40_term_all() does not access DMA40 registers. +*/ d40_term_all (d40c); -pm_runtime_put_autosuspend (d40c->base->dev);if (d40c->busy)pm_runtime_put_autosuspend (d40c->base->dev); d40c->busy = false;spin_unlock_irqrestore (&d40c->lock, flags); -return 0 ; +return ret; } static int
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 884/1756 dmaengine: ste_dma40: Return IRQ_NONE when no interrupt is pending
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Walleij <[email protected]>
[ Upstream commit b96967644c524d34b2fdd2e58c31e7b36e3469e6 ]
d40_handle_interrupt() returns IRQ_HANDLED even when no terminal-count or error status bit is pending.
IRQ_NONE is not only used to identify a device on a shared interrupt. The generic IRQ core also counts it as unhandled for spurious IRQ detection. DMA40 does not request this IRQ with IRQF_SHARED, so interrupt sharing is not the purpose of this change.
If the line remains asserted without matching DMA40 status, returning IRQ_HANDLED hides the stuck interrupt and can leave the CPU servicing it indefinitely. Track whether any DMA40 status is pending and return IRQ_NONE when none is present, allowing the generic IRQ core to diagnose and eventually disable the faulty line.
DMA40 channels can be owned by other SoC cores. Their status means that the interrupt is real, but Linux must not acknowledge it. Treat foreign status as handled and leave its acknowledgment to the owning core, while acknowledging and dispatching only registered Linux channels.
--- drivers/dma/ste_dma40.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/dma/ste_dma40.c +8 -1
@@ -1685,6 +1685,7 @@ static void dma_tasklet(struct tasklet_struct *t)static irqreturn_t d40_handle_interrupt (int irq,void *data) { +irqreturn_t handled =IRQ_NONE ;int i;u32 idx;u32 row;
@@ -1718,6 +1719,12 @@ static irqreturn_t d40_handle_interrupt(int irq, void *data) row = chan /BITS_PER_LONG ; idx = chan & (BITS_PER_LONG -1 ); +/* +* Status for a channel owned by another core still explains +* the interrupt, but only ACK Linux-owned channels below. +*/ + handled =IRQ_HANDLED ; +if (il[row].offset ==D40_PHY_CHAN ) d40c = base->lookup_phy_chans[idx];else
@@ -1750,7 +1757,7 @@ static irqreturn_t d40_handle_interrupt(int irq, void *data)if (ret >0 )pm_runtime_put_autosuspend (base->dev); -return IRQ_HANDLED ; +return handled; } static int d40_validate_conf(struct d40_chan *d40c,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 885/1756 dmaengine: ste_dma40: Init hardware before registration
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Walleij <[email protected]>
[ Upstream commit ffd583a734dc4bdafb9e18d9aa48b6efafd1a628 ]
d40_probe() enables the interrupt handler and registers DMAengine devices before calling d40_hw_init(). An interrupt pending from the bootloader can therefore reach the handler while the hardware interrupt state is not initialized and channel lookup entries are empty. The handler deliberately does not acknowledge an interrupt for an unknown channel, so a level IRQ can retrigger continuously.
Initialize the hardware and set the DMA segment limit before requesting the IRQ or registering DMAengine devices. d40_hw_init() clears pending logical and physical interrupt status, so request_irq() can enable the line normally after the hardware state is initialized.
This ensures that the handler and clients only observe initialized hardware.
--- drivers/dma/ste_dma40.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/dma/ste_dma40.c +4 -5
@@ -3670,20 +3670,19 @@ static int __init d40_probe(struct platform_device *pdev) }pm_runtime_use_autosuspend (base->dev); +dma_set_max_seg_size (base->dev,STEDMA40_MAX_SEG_SIZE ); + +d40_hw_init (base); + ret =request_irq (base->irq, d40_handle_interrupt,0 ,D40_NAME , base);if (ret) {d40_err (dev,"No IRQ defined\n" ); goto destroy_cache; } - ret =d40_dmaengine_init (base, num_reserved_chans);if (ret) goto destroy_cache; -dma_set_max_seg_size (base->dev,STEDMA40_MAX_SEG_SIZE ); - -d40_hw_init (base); - ret =of_dma_controller_register (np, d40_xlate,NULL );if (ret) { dev_err(dev,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 886/1756 dmaengine: ste_dma40: Fix probe IRQ leak
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Walleij <[email protected]>
[ Upstream commit 7ca608cf6b842685bbbe131d4f7d638f7cdc2b5d ]
d40_probe() registers the hardware interrupt before several later probe steps that can fail. Those error paths jump to destroy_cache without freeing the IRQ, leaving the handler registered after probe resources have been released.
Route failures after a successful IRQ request through a dedicated cleanup label. Keep the request before DMAengine registration because that registration publishes channels to clients.
--- drivers/dma/ste_dma40.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/dma/ste_dma40.c +4 -2
@@ -3681,18 +3681,20 @@ static int __init d40_probe(struct platform_device *pdev) } ret =d40_dmaengine_init (base, num_reserved_chans);if (ret) - goto destroy_cache; + goto release_irq; ret =of_dma_controller_register (np, d40_xlate,NULL );if (ret) {dev_err (dev,"could not register of_dma_controller\n" ); - goto destroy_cache; + goto release_irq; }dev_info (base->dev,"initialized\n" );return 0 ; + release_irq: +free_irq (base->irq, base); destroy_cache:if (base->lcla_pool.dma_addr) dma_unmap_single(base->dev, base->lcla_pool.dma_addr,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 887/1756 dmaengine: ste_dma40: Fix DMA registration unwind
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Walleij <[email protected]>
[ Upstream commit f71ef686f913c8e9771a54466a76d653b83cd3dd ]
d40_dmaengine_init() registers DMAengine devices using devres-managed unregister actions. If probe fails after one of those registrations, the DMAengine devices stay visible until devres unwinds after d40_probe() returns.
The channel tasklets are also initialized before each DMAengine device is registered. An interrupt can therefore have queued a tasklet by the time a later registration step fails, but unregistering the DMAengine devices does not drain that tasklet before probe-owned storage is released.
Add tasklet cleanup actions to the DMAengine registration devres group. Install each action before publishing its DMAengine device. If action registration fails, those tasklets have never been exposed and cannot have been scheduled, so use devm_add_action() without immediate reset cleanup.
On later failure, free the IRQ before releasing the group so no new tasklets can be scheduled, then unregister the DMAengine devices and drain their tasklets before freeing the remaining probe resources. Keep the managed registrations and cleanup actions in place on successful probe by removing only the temporary group markers.
--- drivers/dma/ste_dma40.c | 45 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-)
drivers/dma/ste_dma40.c +43 -2
@@ -2876,6 +2876,18 @@ static void __init d40_chan_init(struct d40_base *base, struct dma_device *dma, } } +static void d40_kill_tasklets (void *data) +{ +struct dma_device *dma = data; +struct d40_chan *d40c; +struct dma_chan *chan; + +list_for_each_entry (chan, &dma->channels, device_node) { + d40c = container_of(chan, struct d40_chan, chan); +tasklet_kill (&d40c->tasklet); + } +} +static void d40_ops_init (struct d40_base *base,struct dma_device *dev) {if (dma_has_cap (DMA_SLAVE , dev->cap_mask)) {
@@ -2922,6 +2934,11 @@ static int __init d40_dmaengine_init(struct d40_base *base,d40_ops_init (base, &base->dma_slave); + err =devm_add_action (base->dev, d40_kill_tasklets, + &base->dma_slave); +if (err) + goto exit; + err =dmaenginem_async_device_register (&base->dma_slave);if (err) {
@@ -2937,6 +2954,11 @@ static int __init d40_dmaengine_init(struct d40_base *base,d40_ops_init (base, &base->dma_memcpy); + err =devm_add_action (base->dev, d40_kill_tasklets, + &base->dma_memcpy); +if (err) + goto exit; + err =dmaenginem_async_device_register (&base->dma_memcpy);if (err) {
@@ -2954,6 +2976,12 @@ static int __init d40_dmaengine_init(struct d40_base *base,dma_cap_set (DMA_CYCLIC , base->dma_both.cap_mask);d40_ops_init (base, &base->dma_both); + + err =devm_add_action (base->dev, d40_kill_tasklets, + &base->dma_both); +if (err) + goto exit; + err =dmaenginem_async_device_register (&base->dma_both);if (err) {
@@ -3549,6 +3577,7 @@ static int __init d40_probe(struct platform_device *pdev)struct d40_base *base;struct resource *res;struct resource res_lcpa; +void *dmaenginem_reg_group;int num_reserved_chans;u32 val;int ret;
@@ -3679,20 +3708,32 @@ static int __init d40_probe(struct platform_device *pdev)d40_err (dev,"No IRQ defined\n" ); goto destroy_cache; } + + dmaenginem_reg_group =devres_open_group (dev,NULL ,GFP_KERNEL ); +if (!dmaenginem_reg_group) { + ret = -ENOMEM ; + goto release_irq; + } + ret =d40_dmaengine_init (base, num_reserved_chans);if (ret) - goto release_irq; + goto release_dmaenginem; ret =of_dma_controller_register (np, d40_xlate,NULL );if (ret) {dev_err (dev,"could not register of_dma_controller\n" ); - goto release_irq; + goto release_dmaenginem; } +devres_remove_group (dev, dmaenginem_reg_group);dev_info (base->dev,"initialized\n" );return 0 ; + release_dmaenginem: +free_irq (base->irq, base); +devres_release_group (dev, dmaenginem_reg_group); + goto destroy_cache; release_irq:free_irq (base->irq, base); destroy_cache:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 888/1756 dmaengine: ste_dma40: Fix LCLA allocation order
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Walleij <[email protected]>
[ Upstream commit 7d4dc355c574d414d2402ac481a2fc4ee51e2771 ]
d40_lcla_allocate() calculates the number of pages needed for LCLA, but passes that raw page count as the allocation order to __get_free_pages(). The same value is later passed to free_pages().
Store the allocation order with get_order() instead, and use a separate byte size for allocation diagnostics, fallback kmalloc() sizing and DMA mapping.
--- drivers/dma/ste_dma40.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-)
drivers/dma/ste_dma40.c +16 -17
@@ -411,8 +411,8 @@ struct d40_desc {* @dma_addr: DMA address, if mapped * @base_unaligned: The original kmalloc pointer, if kmalloc is used. * This pointer is only there for clean-up on error. -* @pages: The number of pages needed for all physical channels. -* Only used later for clean-up on error +* @alloc_order: Order used for the LCLA page allocation. +* Only used later for clean-up on error. * @lock: Lock to protect the content in this struct. * @alloc_map: big map over which LCLA entry is own by which job. */
@@ -420,7 +420,7 @@ struct d40_lcla_pool {void *base;dma_addr_t dma_addr;void *base_unaligned; -int pages; +unsigned int alloc_order;spinlock_t lock;struct d40_desc **alloc_map; };
@@ -3438,6 +3438,7 @@ static void __init d40_hw_init(struct d40_base *base)static int __init d40_lcla_allocate (struct d40_base *base) {struct d40_lcla_pool *pool = &base->lcla_pool; +size_t lcla_size =SZ_1K * base->num_phy_chans;unsigned long *page_list;int i, j;int ret;
@@ -3453,20 +3454,20 @@ static int __init d40_lcla_allocate(struct d40_base *base)if (!page_list)return -ENOMEM ; -/* Calculating how many pages that are required */ - base->lcla_pool.pages =SZ_1K * base->num_phy_chans /PAGE_SIZE ; + base->lcla_pool.alloc_order =get_order (lcla_size);for (i =0 ; i <MAX_LCLA_ALLOC_ATTEMPTS ; i++) { page_list[i] =__get_free_pages (GFP_KERNEL , - base->lcla_pool.pages); + base->lcla_pool.alloc_order);if (!page_list[i]) { -d40_err (base->dev,"Failed to allocate %d pages.\n" , - base->lcla_pool.pages); +d40_err (base->dev,"Failed to allocate %zu bytes.\n" , + lcla_size); ret = -ENOMEM ;for (j =0 ; j < i; j++) -free_pages (page_list[j], base->lcla_pool.pages); +free_pages (page_list[j], + base->lcla_pool.alloc_order); goto free_page_list; }
@@ -3476,7 +3477,7 @@ static int __init d40_lcla_allocate(struct d40_base *base) }for (j =0 ; j < i; j++) -free_pages (page_list[j], base->lcla_pool.pages); +free_pages (page_list[j], base->lcla_pool.alloc_order);if (i <MAX_LCLA_ALLOC_ATTEMPTS ) { base->lcla_pool.base = (void *)page_list[i];
@@ -3486,10 +3487,9 @@ static int __init d40_lcla_allocate(struct d40_base *base)* alignment, try with allocating a big buffer. */ dev_warn (base->dev, -"[%s] Failed to get %d pages @ 18 bit align.\n" , - __func__, base->lcla_pool.pages); - base->lcla_pool.base_unaligned =kmalloc (SZ_1K * - base->num_phy_chans + +"[%s] Failed to get %zu bytes @ 18 bit align.\n" , + __func__, lcla_size); + base->lcla_pool.base_unaligned =kmalloc (lcla_size +LCLA_ALIGNMENT ,GFP_KERNEL );if (!base->lcla_pool.base_unaligned) {
@@ -3501,8 +3501,7 @@ static int __init d40_lcla_allocate(struct d40_base *base) LCLA_ALIGNMENT); } - pool->dma_addr =dma_map_single (base->dev, pool->base, -SZ_1K * base->num_phy_chans, + pool->dma_addr =dma_map_single (base->dev, pool->base, lcla_size,DMA_TO_DEVICE );if (dma_mapping_error (base->dev, pool->dma_addr)) { pool->dma_addr =0 ;
@@ -3744,7 +3743,7 @@ static int __init d40_probe(struct platform_device *pdev)if (!base->lcla_pool.base_unaligned && base->lcla_pool.base)free_pages ((unsigned long )base->lcla_pool.base, - base->lcla_pool.pages); + base->lcla_pool.alloc_order);kfree (base->lcla_pool.base_unaligned);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 889/1756 dmaengine: ste_dma40: Fix probe LCLA free
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Walleij <[email protected]>
[ Upstream commit 750dfcdb7a406bdd52d604099a631bbe96ddda91 ]
When LCLA is placed in ESRAM, d40_probe() stores a devm_ioremap() address in lcla_pool.base and leaves base_unaligned unset. The destroy_cache error path can then pass the ioremap address to free_pages().
Only free lcla_pool.base with free_pages() when the driver allocated the LCLA pool from normal memory. The ESRAM mapping is devm-managed.
--- drivers/dma/ste_dma40.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/dma/ste_dma40.c +2 -1
@@ -3741,7 +3741,8 @@ static int __init d40_probe(struct platform_device *pdev)SZ_1K * base->num_phy_chans, DMA_TO_DEVICE); -if (!base->lcla_pool.base_unaligned && base->lcla_pool.base) +if (!base->plat_data->use_esram_lcla && + !base->lcla_pool.base_unaligned && base->lcla_pool.base)free_pages ((unsigned long )base->lcla_pool.base, base->lcla_pool.alloc_order);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 890/1756 dmaengine: ste_dma40: Put the LCPA SRAM node
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Walleij <[email protected]>
[ Upstream commit 9a3762b470421658214baeb6cce3eed7344bb435 ]
of_parse_phandle() takes a reference to the LCPA SRAM node, but d40_probe() does not release it after translating the node into a resource. This leaks the node reference for the lifetime of the system.
Put the node immediately after of_address_to_resource() so both the success and error paths release the reference.
--- drivers/dma/ste_dma40.c | 1 + 1 file changed, 1 insertion(+)
drivers/dma/ste_dma40.c +1 -0
@@ -3606,6 +3606,7 @@ static int __init d40_probe(struct platform_device *pdev) }/* This is no device so read the address directly from the node */ ret =of_address_to_resource (np_lcpa,0 , &res_lcpa); +of_node_put (np_lcpa);if (ret) {dev_err (dev,"no LCPA SRAM resource\n" ); goto report_failure;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 891/1756 dmaengine: ste_dma40: turn d40_base phy_chans into a flexible array
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rosen Penev <[email protected]>
[ Upstream commit cc4fea19daeb0460fe3569e0a2d523f427b2bac1 ]
Convert the separately-offset phy_chans pointer to a C99 flexible array member at the end of struct d40_base, and switch the allocation to struct_size(). The log_chans and memcpy_chans slots continue to live in the same allocation immediately after phy_chans, indexed via base->log_chans. This removes the hand-rolled pointer fixup that recomputed phy_chans from base + ALIGN(sizeof(struct d40_base), 4).
The ALIGN(sizeof(struct d40_base), 4) requirement is met implicitly by the C compiler when using a flexible array member. With struct d40_chan phy_chans[] as the last member, the C standard guarantees sizeof(struct d40_base) includes trailing padding to satisfy the alignment of the flexible array element type (struct d40_chan). Since struct d40_chan contains members like spinlock_t, pointers, and struct dma_chan — all with alignment ≥ 4 — the compiler ensures sizeof(struct d40_base) is already a multiple of _Alignof(struct d40_chan) >= 4. The struct_size() macro then computes sizeof(struct d40_base) + sizeof(struct d40_chan) * num_phy_chans, so phy_chans[0] lands at a properly aligned offset without needing the manual ALIGN.
Stable-dep-of: f2baf04a695d ("dmaengine: ste_dma40: Fix memcpy channel parsing")
--- drivers/dma/ste_dma40.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/dma/ste_dma40.c +8 -6
@@ -602,7 +602,6 @@ struct d40_base {struct dma_device dma_both;struct dma_device dma_slave;struct dma_device dma_memcpy; -struct d40_chan *phy_chans;struct d40_chan *log_chans;struct d40_chan **lookup_log_chans;struct d40_chan **lookup_phy_chans;
@@ -621,6 +620,7 @@ struct d40_base {u32 *regs_interrupt;u16 gcc_pwr_off_mask;struct d40_gen_dmac gen_dmac; +struct d40_chan phy_chans[]; };static struct device *chan2dev (struct d40_chan *d40c)
@@ -3210,6 +3210,7 @@ static int __init d40_hw_detect_init(struct platform_device *pdev,struct clk *clk;void __iomem *virtbase;struct d40_base *base; +size_t alloc_size;int num_log_chans;int num_phy_chans;int num_memcpy_chans;
@@ -3267,22 +3268,24 @@ static int __init d40_hw_detect_init(struct platform_device *pdev,else num_phy_chans =4 * (readl (virtbase +D40_DREG_ICFG ) &0x7 ) +4 ; + num_phy_chans =min (num_phy_chans,STEDMA40_MAX_PHYS ); +/* The number of channels used for memcpy */ if (plat_data->num_of_memcpy_chans) num_memcpy_chans = plat_data->num_of_memcpy_chans;else num_memcpy_chans =ARRAY_SIZE (dma40_memcpy_channels); + num_memcpy_chans =min (num_memcpy_chans,D40_MEMCPY_MAX_CHANS ); num_log_chans = num_phy_chans *D40_MAX_LOG_CHAN_PER_PHY ;dev_info (dev,"hardware rev: %d with %d physical and %d logical channels\n" , rev, num_phy_chans, num_log_chans); - base =devm_kzalloc (dev, -ALIGN (sizeof (struct d40_base ),4 ) + - (num_phy_chans + num_log_chans + num_memcpy_chans) * -sizeof (struct d40_chan ),GFP_KERNEL ); + alloc_size =struct_size (base, phy_chans, num_phy_chans); + alloc_size +=sizeof (*base->log_chans) * (num_log_chans + num_memcpy_chans); + base =devm_kzalloc (dev, alloc_size,GFP_KERNEL );if (!base)return -ENOMEM ;
@@ -3295,7 +3298,6 @@ static int __init d40_hw_detect_init(struct platform_device *pdev, base->virtbase = virtbase; base->plat_data = plat_data; base->dev = dev; - base->phy_chans = ((void *)base) +ALIGN (sizeof (struct d40_base ),4 ); base->log_chans = &base->phy_chans[num_phy_chans];if (base->plat_data->num_of_phy_chans ==14 ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 892/1756 dmaengine: ste_dma40: Fix memcpy channel parsing
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Walleij <[email protected]>
[ Upstream commit f2baf04a695de4f952513cb00ccf0338c6db2e00 ]
d40_of_probe() validates the memcpy-channels property against D40_MEMCPY_MAX_CHANS, but reads the property directly into a smaller global array. A long property can therefore overwrite adjacent data. The mutable global also lets a later DMA40 instance replace the memcpy channel mapping used for future allocations on an earlier instance.
Store the mapping in the per-device platform data, validate the property against that storage, and check the property read result. The property is required and d40_probe() always populates the platform data, so remove the obsolete global mapping and fallback.
--- drivers/dma/ste_dma40.c | 45 +++++++++++++---------------------------- 1 file changed, 14 insertions(+), 31 deletions(-)
drivers/dma/ste_dma40.c +14 -31
@@ -28,6 +28,8 @@#include "ste_dma40.h" #include "ste_dma40_ll.h" +#define D40_MEMCPY_MAX_CHANS 8 +/** * struct stedma40_platform_data - Configuration struct for the dma device. *
@@ -41,6 +43,7 @@* to use SoftLLI. * @use_esram_lcla: flag for mapping the lcla into esram region * @num_of_memcpy_chans: The number of channels reserved for memcpy. +* @memcpy_channels: The event lines used for memcpy. * @num_of_phy_chans: The number of physical channels implemented in HW. * 0 means reading the number of channels from DMA HW but this is only valid * for 'multiple of 4' channels, like 8.
@@ -51,6 +54,7 @@ struct stedma40_platform_data {int num_of_soft_lli_chans;bool use_esram_lcla;int num_of_memcpy_chans; +u32 memcpy_channels[D40_MEMCPY_MAX_CHANS ];int num_of_phy_chans; };
@@ -86,25 +90,6 @@ struct stedma40_platform_data {#define D40_ALLOC_PHY BIT(30)#define D40_ALLOC_LOG_FREE 0 -#define D40_MEMCPY_MAX_CHANS 8 - -/* Reserved event lines for memcpy only. */ -#define DB8500_DMA_MEMCPY_EV_0 51 -#define DB8500_DMA_MEMCPY_EV_1 56 -#define DB8500_DMA_MEMCPY_EV_2 57 -#define DB8500_DMA_MEMCPY_EV_3 58 -#define DB8500_DMA_MEMCPY_EV_4 59 -#define DB8500_DMA_MEMCPY_EV_5 60 - -static int dma40_memcpy_channels[] = { -DB8500_DMA_MEMCPY_EV_0 , -DB8500_DMA_MEMCPY_EV_1 , -DB8500_DMA_MEMCPY_EV_2 , -DB8500_DMA_MEMCPY_EV_3 , -DB8500_DMA_MEMCPY_EV_4 , -DB8500_DMA_MEMCPY_EV_5 , -}; -/* Default configuration for physical memcpy */ static const struct stedma40_chan_cfg dma40_memcpy_conf_phy = { .mode =STEDMA40_MODE_PHYSICAL ,
@@ -2023,7 +2008,8 @@ static int d40_config_memcpy(struct d40_chan *d40c)if (dma_has_cap (DMA_MEMCPY , cap) && !dma_has_cap (DMA_SLAVE , cap)) { d40c->dma_cfg = dma40_memcpy_conf_log; - d40c->dma_cfg.dev_type = dma40_memcpy_channels[d40c->chan.chan_id]; + d40c->dma_cfg.dev_type = + d40c->base->plat_data->memcpy_channels[d40c->chan.chan_id];d40_log_cfg (&d40c->dma_cfg, &d40c->log_def.lcsp1, &d40c->log_def.lcsp3);
@@ -3271,12 +3257,7 @@ static int __init d40_hw_detect_init(struct platform_device *pdev, num_phy_chans =min (num_phy_chans,STEDMA40_MAX_PHYS );/* The number of channels used for memcpy */ -if (plat_data->num_of_memcpy_chans) - num_memcpy_chans = plat_data->num_of_memcpy_chans; -else - num_memcpy_chans =ARRAY_SIZE (dma40_memcpy_channels); - - num_memcpy_chans =min (num_memcpy_chans,D40_MEMCPY_MAX_CHANS ); + num_memcpy_chans = plat_data->num_of_memcpy_chans; num_log_chans = num_phy_chans *D40_MAX_LOG_CHAN_PER_PHY ; dev_info(dev,
@@ -3525,6 +3506,7 @@ static int __init d40_of_probe(struct device *dev,struct stedma40_platform_data *pdata;int num_phy =0 , num_memcpy =0 , num_disabled =0 ;const __be32 *list; +int ret; pdata =devm_kzalloc (dev,sizeof (*pdata),GFP_KERNEL );if (!pdata)
@@ -3538,18 +3520,19 @@ static int __init d40_of_probe(struct device *dev, list =of_get_property (np,"memcpy-channels" , &num_memcpy); num_memcpy /=sizeof (*list); -if (num_memcpy >D40_MEMCPY_MAX_CHANS || num_memcpy <=0 ) { +if (num_memcpy >ARRAY_SIZE (pdata->memcpy_channels) || + num_memcpy <=0 ) {d40_err (dev,"Invalid number of memcpy channels specified (%d)\n" , num_memcpy);return -EINVAL ; } + ret =of_property_read_u32_array (np,"memcpy-channels" , + pdata->memcpy_channels, num_memcpy); +if (ret) +return ret; pdata->num_of_memcpy_chans = num_memcpy; -of_property_read_u32_array (np,"memcpy-channels" , - dma40_memcpy_channels, - num_memcpy); - list =of_get_property (np,"disabled-channels" , &num_disabled); num_disabled /=sizeof (*list);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 893/1756 dmaengine: ste_dma40: Validate disabled channel indexes
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Walleij <[email protected]>
[ Upstream commit c96e9f056095825b5f8d4a11f4107fc174892f92 ]
d40_of_probe() checks how many entries disabled-channels contains, but not the channel numbers themselves. d40_phy_res_init() later uses every value as an index into base->phy_res, whose size is the number of channels found in this DMA40 instance. An out-of-range value can therefore write beyond the allocation.
Validate each disabled channel against the detected hardware channel count before allocating and initializing the channel resources.
--- drivers/dma/ste_dma40.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/dma/ste_dma40.c +9 -0
@@ -3256,6 +3256,15 @@ static int __init d40_hw_detect_init(struct platform_device *pdev, num_phy_chans =min (num_phy_chans,STEDMA40_MAX_PHYS ); +for (i =0 ; plat_data->disabled_channels[i] !=-1 ; i++) { +int chan = plat_data->disabled_channels[i]; + +if (chan <0 || chan >= num_phy_chans) { +dev_err (dev,"Invalid disabled channel %d\n" , chan); +return -EINVAL ; + } + } +/* The number of channels used for memcpy */ num_memcpy_chans = plat_data->num_of_memcpy_chans; num_log_chans = num_phy_chans *D40_MAX_LOG_CHAN_PER_PHY ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 894/1756 dmaengine: ste_dma40: Validate DMA specifier length
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Walleij <[email protected]>
[ Upstream commit 9f1064ebe17cf3ab65ac6eb166398e02678aea33 ]
The DMA40 binding requires three cells, but d40_xlate() reads args[0], args[1], and args[2] without checking args_count. A malformed provider node can specify fewer cells, leaving some of these values uninitialized when the OF DMA core invokes the translation callback.
Reject specifiers that do not contain exactly three cells before reading the argument array.
--- drivers/dma/ste_dma40.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/dma/ste_dma40.c +3 -0
@@ -2395,6 +2395,9 @@ static struct dma_chan *d40_xlate(struct of_phandle_args *dma_spec,dma_cap_mask_t cap;u32 flags; +if (dma_spec->args_count !=3 ) +return NULL ; +memset (&cfg,0 ,sizeof (struct stedma40_chan_cfg ));dma_cap_zero (cap);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 895/1756 dmaengine: ste_dma40: Reject direction changes after allocation
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Walleij <[email protected]>
[ Upstream commit 77ebc64f40717b8501793b5f5ee717a141e62e8e ]
Logical channel allocation uses the configured direction to select the source or destination allocation mask, derive the logical channel number, and choose the LCPA location.
d40_set_runtime_config_write() nevertheless overwrites the configured direction when a transfer is prepared for the opposite direction. d40_free_dma() then clears the wrong allocation mask, leaking the original resource and potentially releasing one used by another client.
Reject directions that differ from the direction used during allocation and propagate runtime configuration errors to callers. Skip slave runtime configuration for memcpy transfers, which also use d40_prep_sg() but do not require it.
--- drivers/dma/ste_dma40.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-)
drivers/dma/ste_dma40.c +14 -15
@@ -2268,7 +2268,13 @@ d40_prep_sg(struct dma_chan *dchan, struct scatterlist *sg_src,return NULL ; } -d40_set_runtime_config_write (dchan, &chan->slave_config, direction); +if (direction !=DMA_MEM_TO_MEM ) { + ret =d40_set_runtime_config_write (dchan, + &chan->slave_config, + direction); +if (ret) +return NULL ; + }spin_lock_irqsave (&chan->lock, flags);
@@ -2723,6 +2729,13 @@ static int d40_set_runtime_config_write(struct dma_chan *chan,return -EINVAL ; } +if (direction != cfg->dir) { +chan_err (d40c, +"transfer direction %d differs from allocated direction %d\n" , + direction, cfg->dir); +return -EINVAL ; + } + src_addr_width = config->src_addr_width; src_maxburst = config->src_maxburst; dst_addr_width = config->dst_addr_width;
@@ -2731,13 +2744,6 @@ static int d40_set_runtime_config_write(struct dma_chan *chan,if (direction ==DMA_DEV_TO_MEM ) { config_addr = config->src_addr; -if (cfg->dir !=DMA_DEV_TO_MEM ) -dev_dbg (d40c->base->dev, -"channel was not configured for peripheral " -"to memory transfer (%d) overriding\n" , - cfg->dir); - cfg->dir =DMA_DEV_TO_MEM ; -/* Configure the memory side */ if (dst_addr_width ==DMA_SLAVE_BUSWIDTH_UNDEFINED ) dst_addr_width = src_addr_width;
@@ -2747,13 +2753,6 @@ static int d40_set_runtime_config_write(struct dma_chan *chan, }else if (direction ==DMA_MEM_TO_DEV ) { config_addr = config->dst_addr; -if (cfg->dir !=DMA_MEM_TO_DEV ) -dev_dbg (d40c->base->dev, -"channel was not configured for memory " -"to peripheral transfer (%d) overriding\n" , - cfg->dir); - cfg->dir =DMA_MEM_TO_DEV ; -/* Configure the memory side */ if (src_addr_width ==DMA_SLAVE_BUSWIDTH_UNDEFINED ) src_addr_width = dst_addr_width;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 896/1756 dmaengine: ste_dma40: Fix logical channel bounds check
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Walleij <[email protected]>
[ Upstream commit 57938e0c2a24f9f792fe9f611391ef6b58d1aa21 ]
d40_validate_conf() checks the raw dev_type against num_log_chans, but d40_allocate_channel() derives the lookup_log_chans index as either 2 * dev_type or 2 * dev_type + 1.
Validate the dev_type against the derived logical channel index limit so channel allocation cannot write past lookup_log_chans.
--- drivers/dma/ste_dma40.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/dma/ste_dma40.c +14 -3
@@ -1750,15 +1750,26 @@ static int d40_validate_conf(struct d40_chan *d40c, {int res =0 ;bool is_log = conf->mode ==STEDMA40_MODE_LOGICAL ; +bool invalid_dev_type = conf->dev_type <0 ;if (!conf->dir) {chan_err (d40c,"Invalid direction.\n" ); res = -EINVAL ; } -if ((is_log && conf->dev_type > d40c->base->num_log_chans) || - (!is_log && conf->dev_type > d40c->base->num_phy_chans) || - (conf->dev_type <0 )) { +if (!invalid_dev_type && is_log) { +int max_dev_type; + +if (conf->dir ==DMA_DEV_TO_MEM ) + max_dev_type =DIV_ROUND_UP (d40c->base->num_log_chans,2 ); +else + max_dev_type = d40c->base->num_log_chans /2 ; + + invalid_dev_type = conf->dev_type >= max_dev_type; + } + +if (invalid_dev_type || + (!is_log && conf->dev_type > d40c->base->num_phy_chans)) {chan_err (d40c,"Invalid device type (%d)\n" , conf->dev_type); res = -EINVAL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 897/1756 dmaengine: ste_dma40: Fix event group bounds
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Walleij <[email protected]>
[ Upstream commit e66a9dbe04c71249cfb2a544c9c25d1b3b761fba ]
The dev_type validation can allow values whose derived event group has no matching physical channel pair. d40_allocate_channel() then indexes phy_res with j + event_group * 2, and __d40_set_prio_rt() uses the same group to select priority and realtime registers.
The physical-mode validation also compares dev_type with the number of physical channels. However, dev_type identifies an event line: DB8500 has eight physical channels but 64 source and 64 destination event lines. The event group determines which physical channel pair can serve an event, so the physical channel count is not a valid dev_type limit.
Reject dev_type values outside the hardware event-group range, remove the incorrect physical channel count limit, and stop the physical-channel search before a partial final channel group can index past phy_res.
--- drivers/dma/ste_dma40.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-)
drivers/dma/ste_dma40.c +22 -4
@@ -79,6 +79,10 @@ struct stedma40_platform_data {#define D40_LCLA_LINK_PER_EVENT_GRP 128#define D40_LCLA_END D40_LCLA_LINK_PER_EVENT_GRP +/* Number of event groups per hardware register layout */ +#define D40_EVENT_GROUPS_V4A 4 +#define D40_EVENT_GROUPS_V4B 5 +/* Max number of logical channels per physical channel */ #define D40_MAX_LOG_CHAN_PER_PHY 32
@@ -507,6 +511,7 @@ struct d40_chan {* @high_prio_clear: the high priority clear register * @interrupt_en: the interrupt enable register * @interrupt_clear: the interrupt clear register +* @num_event_groups: number of supported event groups * @il: the pointer to struct d40_interrupt_lookup * @il_size: the size of d40_interrupt_lookup array * @init_reg: the pointer to the struct d40_reg_val
@@ -521,6 +526,7 @@ struct d40_gen_dmac {u32 high_prio_clear;u32 interrupt_en;u32 interrupt_clear; +u32 num_event_groups;struct d40_interrupt_lookup *il;u32 il_size;struct d40_reg_val *init_reg;
@@ -1752,6 +1758,11 @@ static int d40_validate_conf(struct d40_chan *d40c,bool is_log = conf->mode ==STEDMA40_MODE_LOGICAL ;bool invalid_dev_type = conf->dev_type <0 ; +if (!invalid_dev_type && +D40_TYPE_TO_GROUP (conf->dev_type) >= + d40c->base->gen_dmac.num_event_groups) + invalid_dev_type = true; +if (!conf->dir) {chan_err (d40c,"Invalid direction.\n" ); res = -EINVAL ;
@@ -1768,8 +1779,7 @@ static int d40_validate_conf(struct d40_chan *d40c, invalid_dev_type = conf->dev_type >= max_dev_type; } -if (invalid_dev_type || - (!is_log && conf->dev_type > d40c->base->num_phy_chans)) { +if (invalid_dev_type) {chan_err (d40c,"Invalid device type (%d)\n" , conf->dev_type); res = -EINVAL ; }
@@ -1934,8 +1944,12 @@ static int d40_allocate_channel(struct d40_chan *d40c, bool *first_phy_user) } } }else -for (j =0 ; j < d40c->base->num_phy_chans; j +=8 ) { +for (j =0 ; j < d40c->base->num_phy_chans; + j +=D40_GROUP_SIZE ) {int phy_num = j + event_group *2 ; +if (phy_num +1 >= num_phy_chans) +break ; +for (i = phy_num; i < phy_num +2 ; i++) { if (d40_alloc_mask_set(&phys[i], is_src,
@@ -1955,8 +1969,10 @@ static int d40_allocate_channel(struct d40_chan *d40c, bool *first_phy_user)return -EINVAL ;/* Find logical channel */ -for (j =0 ; j < d40c->base->num_phy_chans; j +=8 ) { +for (j =0 ; j < d40c->base->num_phy_chans; j +=D40_GROUP_SIZE ) {int phy_num = j + event_group *2 ; +if (phy_num +1 >= num_phy_chans) +break ;if (d40c->dma_cfg.use_fixed_channel) { i = d40c->dma_cfg.phy_channel;
@@ -3304,6 +3320,7 @@ static int __init d40_hw_detect_init(struct platform_device *pdev, base->log_chans = &base->phy_chans[num_phy_chans];if (base->plat_data->num_of_phy_chans ==14 ) { + base->gen_dmac.num_event_groups =D40_EVENT_GROUPS_V4B ; base->gen_dmac.backup = d40_backup_regs_v4b; base->gen_dmac.backup_size =BACKUP_REGS_SZ_V4B ; base->gen_dmac.interrupt_en =D40_DREG_CPCMIS ;
@@ -3317,6 +3334,7 @@ static int __init d40_hw_detect_init(struct platform_device *pdev, base->gen_dmac.init_reg = dma_init_reg_v4b; base->gen_dmac.init_reg_size =ARRAY_SIZE (dma_init_reg_v4b); }else { + base->gen_dmac.num_event_groups =D40_EVENT_GROUPS_V4A ;if (base->rev >=3 ) { base->gen_dmac.backup = d40_backup_regs_v4a; base->gen_dmac.backup_size =BACKUP_REGS_SZ_V4A ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 898/1756 dmaengine: ste_dma40: Fix V4B event group mapping
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Walleij <[email protected]>
[ Upstream commit b36f8fce7314fed53563c60e683ff86deb8a51ae ]
DMA40 physical resources are connected in pairs to event groups. The mapping repeats after each complete set of groups.
D40_GROUP_SIZE and D40_PHYS_TO_GROUP() encode the four-group V4A layout. On V4B, which has five groups, resources 8 and 9 are consequently offered both to event groups 0 and 4. The GCC clock bookkeeping also treats these resources as group 0 instead of group 4.
Derive the physical-resource stride and reverse mapping from the variant-specific number of event groups. This preserves the V4A mapping and gives V4B a ten-resource stride: resources 8 and 9 belong only to group 4, while resources 10 and 11 repeat group 0.
--- drivers/dma/ste_dma40.c | 47 ++++++++++++++++++++++++++------------ drivers/dma/ste_dma40_ll.h | 2 -- 2 files changed, 33 insertions(+), 16 deletions(-)
drivers/dma/ste_dma40.c +33 -14
@@ -82,6 +82,7 @@ struct stedma40_platform_data {/* Number of event groups per hardware register layout */ #define D40_EVENT_GROUPS_V4A 4#define D40_EVENT_GROUPS_V4B 5 +#define D40_PHYS_PER_EVENT_GROUP 2/* Max number of logical channels per physical channel */ #define D40_MAX_LOG_CHAN_PER_PHY 32
@@ -1896,6 +1897,12 @@ static bool d40_alloc_mask_free(struct d40_phy_res *phy, bool is_src,return is_free; } +static int d40_phy_to_group (struct d40_base *base,int phy) +{ +return (phy /D40_PHYS_PER_EVENT_GROUP ) % + base->gen_dmac.num_event_groups; +} +static int d40_allocate_channel (struct d40_chan *d40c,bool *first_phy_user) {int dev_type = d40c->dma_cfg.dev_type;
@@ -1906,11 +1913,14 @@ static int d40_allocate_channel(struct d40_chan *d40c, bool *first_phy_user)int j;int log_num;int num_phy_chans; +int phy_group_stride;bool is_src;bool is_log = d40c->dma_cfg.mode ==STEDMA40_MODE_LOGICAL ; phys = d40c->base->phy_res; num_phy_chans = d40c->base->num_phy_chans; + phy_group_stride =D40_PHYS_PER_EVENT_GROUP * + d40c->base->gen_dmac.num_event_groups;if (d40c->dma_cfg.dir ==DMA_DEV_TO_MEM ) { log_num =2 * dev_type;
@@ -1944,13 +1954,18 @@ static int d40_allocate_channel(struct d40_chan *d40c, bool *first_phy_user) } } }else -for (j =0 ; j < d40c->base->num_phy_chans; - j +=D40_GROUP_SIZE ) { -int phy_num = j + event_group *2 ; -if (phy_num +1 >= num_phy_chans) +for (j =0 ; j < num_phy_chans; + j += phy_group_stride) { +int phy_num = j + event_group * +D40_PHYS_PER_EVENT_GROUP ; + +if (phy_num +D40_PHYS_PER_EVENT_GROUP > + num_phy_chans)break ; -for (i = phy_num; i < phy_num +2 ; i++) { +for (i = phy_num; + i < phy_num +D40_PHYS_PER_EVENT_GROUP ; + i++) { if (d40_alloc_mask_set(&phys[i], is_src, 0,
@@ -1969,9 +1984,10 @@ static int d40_allocate_channel(struct d40_chan *d40c, bool *first_phy_user)return -EINVAL ;/* Find logical channel */ -for (j =0 ; j < d40c->base->num_phy_chans; j +=D40_GROUP_SIZE ) { -int phy_num = j + event_group *2 ; -if (phy_num +1 >= num_phy_chans) +for (j =0 ; j < num_phy_chans; j += phy_group_stride) { +int phy_num = j + event_group *D40_PHYS_PER_EVENT_GROUP ; + +if (phy_num +D40_PHYS_PER_EVENT_GROUP > num_phy_chans)break ;if (d40c->dma_cfg.use_fixed_channel) {
@@ -1998,14 +2014,17 @@ static int d40_allocate_channel(struct d40_chan *d40c, bool *first_phy_user)* channels. */ if (is_src) { -for (i = phy_num; i < phy_num +2 ; i++) { +for (i = phy_num; + i < phy_num +D40_PHYS_PER_EVENT_GROUP ; + i++) {if (d40_alloc_mask_set (&phys[i], is_src, event_line, is_log, first_phy_user)) goto found_log; } }else { -for (i = phy_num +1 ; i >= phy_num; i--) { +for (i = phy_num +D40_PHYS_PER_EVENT_GROUP -1 ; + i >= phy_num; i--) {if (d40_alloc_mask_set (&phys[i], is_src, event_line, is_log, first_phy_user))
@@ -3144,9 +3163,9 @@ static int __init d40_phy_res_init(struct d40_base *base) base->phy_res[i].allocated_src =D40_ALLOC_PHY ; base->phy_res[i].allocated_dst =D40_ALLOC_PHY ; base->phy_res[i].reserved = true; - gcc |=D40_DREG_GCC_EVTGRP_ENA (D40_PHYS_TO_GROUP (i), + gcc |=D40_DREG_GCC_EVTGRP_ENA (d40_phy_to_group (base, i),D40_DREG_GCC_SRC ); - gcc |=D40_DREG_GCC_EVTGRP_ENA (D40_PHYS_TO_GROUP (i), + gcc |=D40_DREG_GCC_EVTGRP_ENA (d40_phy_to_group (base, i),D40_DREG_GCC_DST );
@@ -3166,9 +3185,9 @@ static int __init d40_phy_res_init(struct d40_base *base) base->phy_res[chan].allocated_src =D40_ALLOC_PHY ; base->phy_res[chan].allocated_dst =D40_ALLOC_PHY ; base->phy_res[chan].reserved = true; - gcc |=D40_DREG_GCC_EVTGRP_ENA (D40_PHYS_TO_GROUP (chan), + gcc |=D40_DREG_GCC_EVTGRP_ENA (d40_phy_to_group (base, chan),D40_DREG_GCC_SRC ); - gcc |=D40_DREG_GCC_EVTGRP_ENA (D40_PHYS_TO_GROUP (chan), + gcc |=D40_DREG_GCC_EVTGRP_ENA (d40_phy_to_group (base, chan),D40_DREG_GCC_DST ); num_phy_chans_avail--; }
drivers/dma/ste_dma40_ll.h +0 -2
@@ -16,8 +16,6 @@#define D40_TYPE_TO_GROUP (type) (type / 16)#define D40_TYPE_TO_EVENT (type) (type % 16) -#define D40_GROUP_SIZE 8 -#define D40_PHYS_TO_GROUP (phys) ((phys & (D40_GROUP_SIZE - 1)) / 2)/* Most bits of the CFG register are the same in log as in phy mode */ #define D40_SREG_CFG_MST_POS 15
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 899/1756 dmaengine: ste_dma40: Validate fixed physical channel indexes
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Walleij <[email protected]>
[ Upstream commit 884e01160bc727509b4fdf04e763a86b936df464 ]
Fixed physical memcpy allocation uses dma_cfg.phy_channel directly as an index into phy_res when use_fixed_channel is set. d40_validate_conf() validates dev_type but not the fixed physical channel, allowing an invalid configuration to access memory outside the array.
Validate the fixed physical channel centrally before accepting the channel configuration.
--- drivers/dma/ste_dma40.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/dma/ste_dma40.c +8 -0
@@ -1785,6 +1785,14 @@ static int d40_validate_conf(struct d40_chan *d40c, res = -EINVAL ; } +if (conf->use_fixed_channel && + (conf->phy_channel <0 || + conf->phy_channel >= d40c->base->num_phy_chans)) { +chan_err (d40c,"Invalid physical channel (%d)\n" , + conf->phy_channel); + res = -EINVAL ; + } +if (conf->dir ==DMA_DEV_TO_DEV ) {/* * DMAC HW supports it. Will be added to this driver,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 900/1756 dmaengine: ste_dma40: Validate memcpy configuration
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Walleij <[email protected]>
[ Upstream commit 0ac4a90c4805b41013044fdefff051ae59a54302 ]
d40_config_memcpy() builds a default memcpy configuration without passing it through d40_validate_conf(). A dev_type supplied through the memcpy-channels device tree property can therefore bypass the bounds checks added for client configurations.
The generic DMA direction enum assigns zero to DMA_MEM_TO_MEM, unlike DMA40's old private enum. Allow memory-to-memory directions in the validator so checking the generated configuration does not reject all memcpy channels.
Validate the generated memcpy configuration before deriving logical channel registers or allocating the channel.
--- drivers/dma/ste_dma40.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/dma/ste_dma40.c +11 -1
@@ -1764,7 +1764,8 @@ static int d40_validate_conf(struct d40_chan *d40c, d40c->base->gen_dmac.num_event_groups) invalid_dev_type = true; -if (!conf->dir) { +if (conf->dir !=DMA_MEM_TO_MEM && + !is_slave_direction (conf->dir)) {chan_err (d40c,"Invalid direction.\n" ); res = -EINVAL ; }
@@ -2059,12 +2060,17 @@ static int d40_allocate_channel(struct d40_chan *d40c, bool *first_phy_user)static int d40_config_memcpy (struct d40_chan *d40c) {dma_cap_mask_t cap = d40c->chan.device->cap_mask; +int ret;if (dma_has_cap (DMA_MEMCPY , cap) && !dma_has_cap (DMA_SLAVE , cap)) { d40c->dma_cfg = dma40_memcpy_conf_log; d40c->dma_cfg.dev_type = d40c->base->plat_data->memcpy_channels[d40c->chan.chan_id]; + ret =d40_validate_conf (d40c, &d40c->dma_cfg); +if (ret) +return ret; +d40_log_cfg (&d40c->dma_cfg, &d40c->log_def.lcsp1, &d40c->log_def.lcsp3);
@@ -2072,6 +2078,10 @@ static int d40_config_memcpy(struct d40_chan *d40c) dma_has_cap(DMA_SLAVE, cap)) { d40c->dma_cfg = dma40_memcpy_conf_phy; + ret =d40_validate_conf (d40c, &d40c->dma_cfg); +if (ret) +return ret; +/* Generate interrupt at end of transfer or relink. */ d40c->dst_def_cfg |=BIT (D40_SREG_CFG_TIM_POS );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 901/1756 pNFS/flexfiles: honor FF_FLAGS_NO_IO_THRU_MDS over the mdsthreshold hint
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mike Snitzer <[email protected]>
[ Upstream commit 78422f623c1e150e3cdfe62598c6e352a2dcfc5f ]
A flexfiles layout may carry FF_FLAGS_NO_IO_THRU_MDS, which tells the client that this file's data must not be read or written through the metadata server.
The RFC 5661 mdsthreshold hint pulls the other way. When a server returns one, pnfs_within_mdsthreshold() answers "use MDS I/O" for every I/O below the threshold, pnfs_update_layout() then hands back no segment, and ff_layout_pg_init_read() reads through the MDS - the very thing the layout forbids. A server that sets both is asking for two incompatible things; the layout flag is the stronger statement, and the one whose violation the client cannot recover from.
Record the policy on the inode, where it outlives the layout hdr that carried it, and consult it before the hint:
- ff_layout_alloc_lseg() sets NFS_INO_NO_IO_THRU_MDS beside the existing sticky hdr-level NFS4_FF_HDR_NO_IO_THRU_MDS bit.
- pnfs_within_mdsthreshold() returns false at once for such an inode, so no I/O is diverted to the MDS on the strength of the hint.
The bit is never cleared for the life of the in-core inode. Servers are assumed to be consistent in their no-fallback policy per file, which is the assumption ff_layout_hdr_no_fallback_to_mds() already makes; a server that was not would lose the effect of its mdsthreshold hint - a SHOULD - on an inode that is already in core, and nothing else.
--- fs/nfs/flexfilelayout/flexfilelayout.c | 5 ++++- fs/nfs/internal.h | 29 ++++++++++++++++++++++++++ fs/nfs/pnfs.c | 12 ++++++++++- 3 files changed, 44 insertions(+), 2 deletions(-)
fs/nfs/flexfilelayout/flexfilelayout.c +4 -1
@@ -574,9 +574,12 @@ ff_layout_alloc_lseg(struct pnfs_layout_hdr *lh,if (!p) goto out_sort_mirrors; fls->flags =be32_to_cpup (p); -if (fls->flags &FF_FLAGS_NO_IO_THRU_MDS ) +if (fls->flags &FF_FLAGS_NO_IO_THRU_MDS ) {set_bit (NFS4_FF_HDR_NO_IO_THRU_MDS , &FF_LAYOUT_FROM_HDR (lh)->flags); +/* Outlives this layout hdr; see NFS_INO_NO_IO_THRU_MDS */ +nfs_set_no_io_thru_mds (lh->plh_inode); + } p =xdr_inline_decode (&stream,4 );if (!p)
fs/nfs/internal.h +29 -0
@@ -529,6 +529,35 @@ static inline bool nfs_file_io_is_buffered(struct nfs_inode *nfsi)return test_bit (NFS_INO_ODIRECT , &nfsi->flags) ==0 ; } +/* +* Module-private nfs_inode->flags bit (not in <linux/nfs_fs.h>, so no +* exported layout changes): set, and never cleared for the life of the +* in-core inode, once a layout driver has seen the server forbid I/O +* through the MDS for this file (flexfiles sets it from +* FF_FLAGS_NO_IO_THRU_MDS in ff_layout_alloc_lseg()). The RFC 5661 +* mdsthreshold hint must not be acted on for such a file, since the only +* thing pnfs_within_mdsthreshold() can ask for is the one thing the +* layout forbids. Servers are assumed to be consistent in their +* no-fallback policy per file, the same assumption +* ff_layout_hdr_no_fallback_to_mds() already makes; if one were not, the +* only effect is that its mdsthreshold hint - a SHOULD - stops being +* honored for an inode that is already in core. +*/ +#define NFS_INO_NO_IO_THRU_MDS (30) + +static inline void nfs_set_no_io_thru_mds (struct inode *inode) +{ +struct nfs_inode *nfsi =NFS_I (inode); + +if (!test_bit (NFS_INO_NO_IO_THRU_MDS , &nfsi->flags)) +set_bit (NFS_INO_NO_IO_THRU_MDS , &nfsi->flags); +} + +static inline bool nfs_no_io_thru_mds (struct inode *inode) +{ +return test_bit (NFS_INO_NO_IO_THRU_MDS , &NFS_I (inode)->flags); +} +/* Must be called with exclusively locked inode->i_rwsem */ static inline void nfs_file_block_o_direct (struct nfs_inode *nfsi) {
fs/nfs/pnfs.c +11 -1
@@ -1992,7 +1992,9 @@ pnfs_find_lseg(struct pnfs_layout_hdr *lo,* is set to IOMODE_READ for a READ request, and set to IOMODE_RW for a * WRITE request. * -* A return of true means use MDS I/O. +* A return of true means use MDS I/O, so for a file whose layout forbids +* that (see NFS_INO_NO_IO_THRU_MDS) the hint is not evaluated at all: +* there is no answer it could give that this client may act on. * * From rfc 5661: * If a file's size is smaller than the file size threshold, data accesses
@@ -2013,6 +2015,14 @@ static bool pnfs_within_mdsthreshold(struct nfs_open_context *ctx,if (t ==NULL )return ret; +/* +* The server has told a layout driver that this file's I/O may not +* go through the MDS (flexfiles FF_FLAGS_NO_IO_THRU_MDS). Honor +* that over its own mdsthreshold hint. +*/ +if (nfs_no_io_thru_mds (ino)) +return ret; +dprintk ("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n" , __func__, t->bm, t->rd_sz, t->wr_sz, t->rd_io_sz, t->wr_io_sz);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 902/1756 pNFS/flexfiles: dont read through MDS when previous layout forbid it
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mike Snitzer <[email protected]>
[ Upstream commit 2f007ba074ad77e70d941e16956d1937dc3080c6 ]
ff_layout_pg_init_read() falls back to the MDS whenever pnfs_update_layout() returns no segment and no error: a bulk CB_LAYOUTRECALL (FSID, DEVICEID or ALL), LAYOUTGETs blocked behind a layout being returned, or a LAYOUTGET refused with NFS4ERR_LAYOUTUNAVAILABLE or NFS4ERR_TOOSMALL, which set the per-iomode fail bit for PNFS_LAYOUTGET_RETRY_TIMEOUT. That is the read-side twin of the write path fixed by commit 1d62e659c0bf ("NFSv4/flexfiles:
honor FF_FLAGS_NO_IO_THRU_MDS in pg_get_mirror_count_write"), and it is reached in exactly the situation that matters most: the file had a valid layout, the layout had to go back, and the next one has not arrived yet.
The write side could answer -EAGAIN because writeback owns the retry and redirties the page. A read has no such owner, so -EAGAIN here would surface as an I/O error to the application. Wait for a layout instead, on the same terms the function already uses when the layout lookup itself returns -EAGAIN: sleep a second and retry, bounded by pg_maxretrans, which ff_layout_pg_init_read() sets only for soft and softerr mounts. A hard mount therefore waits, which is what a hard mount is for, and matches what the FF_FLAGS_NO_IO_THRU_MDS check on the data server selection a few lines above already does. That includes waiting out NFS4ERR_LAYOUTUNAVAILABLE: a file that was given a layout with this flag must not be read off the MDS, whatever the server says afterwards.
The test asks the inode (NFS_INO_NO_IO_THRU_MDS) rather than the layout hdr, because in this path there is no segment, and the hdr that carried the flag may already have been destroyed. Where a segment is in hand - the data server selection above, ff_layout_read_pagelist() - the existing per-segment ff_layout_no_fallback_to_mds() test stays, since it is the more precise question.
--- fs/nfs/flexfilelayout/flexfilelayout.c | 38 ++++++++++++++++++-------- 1 file changed, 26 insertions(+), 12 deletions(-)
fs/nfs/flexfilelayout/flexfilelayout.c +26 -12
@@ -918,19 +918,33 @@ ff_layout_pg_init_read(struct nfs_pageio_descriptor *pgio,if (pgio->pg_error <0 ) {if (pgio->pg_error != -EAGAIN )return ; -/* Retry getting layout segment if lower layer returned -EAGAIN */ -if (pgio->pg_maxretrans && req->wb_nio++ > pgio->pg_maxretrans) { -if (NFS_SERVER (pgio->pg_inode)->flags &NFS_MOUNT_SOFTERR ) - pgio->pg_error = -ETIMEDOUT ; -else - pgio->pg_error = -EIO ; -return ; - } - pgio->pg_error =0 ; -/* Sleep for 1 second before retrying */ -ssleep (1 ); - goto retry; + goto retry_nolseg; + } +/* +* No segment, and no error to report either: pnfs_update_layout() +* simply has nothing to give (NFS_LAYOUT_BULK_RECALL, a failed +* pnfs_layout_io_test, blocked LAYOUTGETs, a layout being +* returned). If the server forbids reading this file through the +* MDS there is no fallback to take, so wait for a layout on the +* same terms as the -EAGAIN above. The layout hdr that carried +* FF_FLAGS_NO_IO_THRU_MDS may itself be gone by now, which is why +* this asks the inode and not the hdr. +*/ +if (!nfs_no_io_thru_mds (pgio->pg_inode)) + goto out_mds; +retry_nolseg: +/* Retry getting layout segment if lower layer returned -EAGAIN */ +if (pgio->pg_maxretrans && req->wb_nio++ > pgio->pg_maxretrans) { +if (NFS_SERVER (pgio->pg_inode)->flags &NFS_MOUNT_SOFTERR ) + pgio->pg_error = -ETIMEDOUT ; +else + pgio->pg_error = -EIO ; +return ; } + pgio->pg_error =0 ; +/* Sleep for 1 second before retrying */ +ssleep (1 ); + goto retry; out_mds: trace_pnfs_mds_fallback_pg_init_read(pgio->pg_inode, 0, NFS4_MAX_UINT64, IOMODE_READ,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 903/1756 pNFS/flexfiles: dont reset to MDS for v4 error when previous layout forbid it
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mike Snitzer <[email protected]>
[ Upstream commit ec906cf7bee60f3bbc8500bac14e65813e38ac93 ]
ff_layout_async_handle_error_v4() ends in -NFS4ERR_RESET_TO_MDS, which makes ff_layout_read_release() / ff_layout_write_release() call ff_layout_reset_read() or ff_layout_reset_write(hdr, false), and those call pnfs_read_done_resend_to_mds() / pnfs_write_done_resend_to_mds(). Those build a page I/O descriptor with force_mds set, so the flexfiles ->pg_init() never runs and no layout is consulted anywhere on the way:
the READ or WRITE goes to the metadata server unconditionally. For a layout carrying FF_FLAGS_NO_IO_THRU_MDS that is exactly what the server forbade.
The fall-through into reset: is already safe, because ff_layout_avoid_mds_available_ds() returns true for a segment with the flag and so answers -NFS4ERR_RESET_TO_PNFS first. What is not safe is the goto: the invalid-layout errors (NFS4ERR_PNFS_NO_LAYOUT, STALE, BADHANDLE, ISDIR, FHEXPIRED, WRONG_TYPE) call pnfs_destroy_layout() and jump straight to reset:, over that check. That is the case where the file had a perfectly good layout, something forced it to be given back, and the client answers by writing to the MDS behind the server's back.
Test at reset: itself, so it covers the goto and any future one, and ask the inode (NFS_INO_NO_IO_THRU_MDS): the callers that jump here have just destroyed the layout hdr, so the hdr-level flag is no longer reachable, while the inode-level one is set for the life of the in-core inode.
-NFS4ERR_RESET_TO_PNFS is the right answer rather than an error. It is what the fall-through already returns for the same flag, and the resends it drives - ff_layout_resend_pnfs_read() and ff_layout_reset_write(hdr, true) - re-enter the pgio path with force_mds clear, so a fresh LAYOUTGET is taken, which is precisely what a destroyed layout needs. A LAYOUTGET that fails fatally makes pnfs_update_layout() return an error, which ->pg_init() reports; a non-fatal refusal (NFS4ERR_LAYOUTUNAVAILABLE, NFS4ERR_TOOSMALL) returns no segment instead, and the client keeps retrying through pNFS rather than falling back.
ff_layout_async_handle_error_v3() needs no such change: it returns only -NFS4ERR_RESET_TO_PNFS or -EAGAIN.
--- fs/nfs/flexfilelayout/flexfilelayout.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
fs/nfs/flexfilelayout/flexfilelayout.c +17 -0
@@ -1250,6 +1250,23 @@ static int ff_layout_async_handle_error_v4(struct rpc_task *task,if (ff_layout_avoid_mds_available_ds (lseg))return -NFS4ERR_RESET_TO_PNFS ; reset: +/* +* FF_FLAGS_NO_IO_THRU_MDS: never resend through the MDS. The +* caller would do so with force_mds set (ff_layout_reset_read(), +* ff_layout_reset_write(hdr, false) -> pnfs_*_done_resend_to_mds()), +* which builds a descriptor out of the plain MDS page ops and so +* consults no layout at all -- this is the last point at which the +* policy can still be applied. Retry through pNFS instead, which +* takes a fresh LAYOUTGET; that is also the right answer for the +* invalid-layout cases that jump here, since they have just called +* pnfs_destroy_layout(). Having done so they can no longer ask the +* layout hdr about the flag, hence the inode. +*/ +if (nfs_no_io_thru_mds (inode)) { +dprintk ("%s Retry through pNFS, no MDS fallback. Error %d\n" , + __func__, task->tk_status); +return -NFS4ERR_RESET_TO_PNFS ; + }dprintk ("%s Retry through MDS. Error %d\n" , __func__, task->tk_status);return -NFS4ERR_RESET_TO_MDS ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 904/1756 arm64: dts: allwinner: sun50i-h6: Add missing SRAM region for video engine
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chen-Yu Tsai <[email protected]>
[ Upstream commit d7287d940f3cd8d5945009076058a8120281744b ]
The SRAM C region contains a partial alias to the VE SRAM already referenced by the video engine. To avoid access through this alias window, the region should also be claimed by the video engine.
Add a reference to the SRAM C region to the video engine node.
--- arch/arm64/boot/dts/allwinner/sun50i-h6.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/allwinner/sun50i-h6.dtsi +1 -1
@@ -209,7 +209,7 @@ video-codec@1c0e000 { clock-names = "ahb", "mod", "ram"; resets = <&ccu RST_BUS_VE>; interrupts = <GIC_SPI 89 IRQ_TYPE_LEVEL_HIGH>; - allwinner,sram = <&ve_sram 1>; + allwinner,sram = <&ve_sram 1>, <&de2_sram 1>; iommus = <&iommu 3>; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 905/1756 arm64: dts: allwinner: sun50i-h6: Add missing IOMMU for video engine
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chen-Yu Tsai <[email protected]>
[ Upstream commit 965a49fc413d996eba9bae2a3132f03f45a2ea1b ]
The video engine on the H6 actually has two IOMMU ports. The one already listed is simply named "VE" in the user manual. The missing one is named "VE_R" and is probably either read-only or used for reference frames. Either way, it should be listed.
Add a reference to the "VE_R" IOMMU port to the video engine node.
--- arch/arm64/boot/dts/allwinner/sun50i-h6.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/allwinner/sun50i-h6.dtsi +1 -1
@@ -210,7 +210,7 @@ video-codec@1c0e000 { resets = <&ccu RST_BUS_VE>; interrupts = <GIC_SPI 89 IRQ_TYPE_LEVEL_HIGH>; allwinner,sram = <&ve_sram 1>, <&de2_sram 1>; - iommus = <&iommu 3>; + iommus = <&iommu 3>, <&iommu 1>; }; gpu: gpu@1800000 {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 906/1756 ipv4: fix IP ID reuse in ip_select_ident_segs()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit fe7ca0c13f7d477d6f461114815c57fde3f930ca ]
ip_select_ident_segs() must put the first of the @segs reserved IP IDs in iph->id, as GSO assigns id, id + 1, ..., id + segs - 1 to segments.
Commit f866fbc842de ("ipv4: fix data-races around inet->inet_id") used atomic_add_return() for non-TCP sockets, which returns the first ID of the next packet instead. Consecutive GSO packets can then reuse IP IDs.
SCTP GSO is affected. Other callers use segs == 1, and only see a harmless off-by-one (UDP GSO has a separate, older issue).
Use atomic_fetch_add() instead, like the TCP path.
--- include/net/ip.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/net/ip.h +1 -1
@@ -582,7 +582,7 @@ static inline void ip_select_ident_segs(struct net *net, struct sk_buff *skb, val =atomic_read (&inet_sk (sk)->inet_id);atomic_set (&inet_sk (sk)->inet_id, val + segs); }else { - val =atomic_add_return (segs, &inet_sk (sk)->inet_id); + val =atomic_fetch_add (segs, &inet_sk (sk)->inet_id); } iph->id =htons (val);return ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 907/1756 ipv4: reserve one IP ID per segment for UDP GSO packets
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 852c08d6a99149dc71c51cea125b5083f555237e ]
__ip_make_skb() reserves a single IP ID for UDP GSO packets, but GSO assigns one IP ID per segment. Following packets then reuse these IDs, either from inet->inet_id or from the shared generator.
Unless IP_PMTUDISC_DO/PROBE is used, DF is not set on UDP GSO packets, so segments can be fragmented on the path and IP ID reuse can lead to incorrect reassembly.
Reserve one IP ID per segment, using the same test as udp_send_skb().
--- net/ipv4/ip_output.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
net/ipv4/ip_output.c +14 -1
@@ -1412,6 +1412,7 @@ struct sk_buff *__ip_make_skb(struct sock *sk,struct iphdr *iph;u8 pmtudisc, ttl;__be16 df =0 ; +int segs; skb =__skb_dequeue (queue);if (!skb)
@@ -1466,7 +1467,19 @@ struct sk_buff *__ip_make_skb(struct sock *sk, iph->ttl = ttl; iph->protocol = sk->sk_protocol;ip_copy_addrs (iph, fl4); -ip_select_ident (net, skb, sk); + +/* UDP GSO packets are segmented later (see udp_send_skb()): +* reserve one IP ID per segment. +*/ + segs =1 ; +if (cork->gso_size &&sk_is_udp (sk)) { +int datalen = skb->len -skb_transport_offset (skb) - +sizeof (struct udphdr ); + +if (datalen > cork->gso_size) + segs =DIV_ROUND_UP (datalen, cork->gso_size); + } +ip_select_ident_segs (net, skb, sk, segs);if (opt) { iph->ihl += opt->optlen >>2 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 908/1756 riscv: fix RVG_SYSTEM_CSR_MASK width mask
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aurelien Jarno <[email protected]>
[ Upstream commit f89e5ee4d8c6cd56499cd87e550d4d4e19cf7e17 ]
RVG_SYSTEM_CSR_MASK should be 12 bits [31:20], shifted down by 20 bits. Replace GENMASK(12, 0) by GENMASK(11, 0).
--- arch/riscv/include/asm/insn.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/include/asm/insn.h +1 -1
@@ -141,7 +141,7 @@#define RVG_OPCODE_JAL 0x6f#define RVG_OPCODE_SYSTEM 0x73#define RVG_SYSTEM_CSR_OFF 20 -#define RVG_SYSTEM_CSR_MASK GENMASK(12, 0) +#define RVG_SYSTEM_CSR_MASK GENMASK(11, 0)/* parts of opcode for RVF, RVD and RVQ */ #define RVFDQ_FL_FS_WIDTH_OFF 12
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 909/1756 sh: uaccess: Require offsettable operands for 64-bit user access
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Fuchs <[email protected]>
[ Upstream commit 8b5dba9ea4a3f5ed994f03d6ca7686c49491b426 ]
The 64-bit __get_user_u64()/__put_user_u64() paths address the memory operand as %T2 (base+4). This base+4 requires an offsettable address, but "m" also allows the indexed mode @(R0,Rn) (e.g. for a variable- indexed array element), which has no displacement field for the +4. Depending on optimization this build fails with "invalid 'asm'" or an ICE in GCC's change_address_1.
Require an offsettable memory operand, allowing GCC to reload an unsuitable indexed address into an appropriate form.
--- arch/sh/include/asm/uaccess_32.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/sh/include/asm/uaccess_32.h +4 -4
@@ -92,7 +92,7 @@ __asm__ __volatile__( \ ".long 1b + 2, 3b\n\t" \ ".previous" \ :"=&r" (err), "=&r" (x) \ - :"m" (__m(addr)), "i" (-EFAULT), "0" (err)); }) + :"o" (__m(addr)), "i" (-EFAULT), "0" (err)); })#else #define __get_user_u64 (x, addr, err) \ ({ \
@@ -116,7 +116,7 @@ __asm__ __volatile__( \ ".long 1b + 2, 3b\n\t" \ ".previous" \ :"=&r" (err), "=&r" (x) \ - :"m" (__m(addr)), "i" (-EFAULT), "0" (err)); }) + :"o" (__m(addr)), "i" (-EFAULT), "0" (err)); })#endif #define __put_user_size (x,ptr,size,retval) \
@@ -196,7 +196,7 @@ __asm__ __volatile__( \ ".long 1b, 3b\n\t" \ ".previous" \ : "=r" (retval) \ - : "r" (val), "m" (__m(addr)), "i" (-EFAULT), "0" (retval) \ + : "r" (val), "o" (__m(addr)), "i" (-EFAULT), "0" (retval) \ : "memory"); }) #else #define __put_user_u64(val,addr,retval) \
@@ -218,7 +218,7 @@ __asm__ __volatile__( \ ".long 1b, 3b\n\t" \ ".previous" \ : "=r" (retval) \ - : "r" (val), "m" (__m(addr)), "i" (-EFAULT), "0" (retval) \ + : "r" (val), "o" (__m(addr)), "i" (-EFAULT), "0" (retval) \ : "memory"); }) #endif
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 910/1756 sh: defconfig: Enable the current M66592 UDC symbol
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit 9b65dcd94222c37febf98127b1ac5452c94a16d0 ]
The M66592 UDC provider is built under CONFIG_USB_M66592. Several SuperH defconfigs still enable the removed CONFIG_USB_GADGET_M66592 symbol.
Replace the stale entries with the current provider symbol.
--- arch/sh/configs/migor_defconfig | 2 +- arch/sh/configs/sdk7786_defconfig | 2 +- arch/sh/configs/shx3_defconfig | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
arch/sh/configs/migor_defconfig +1 -1
@@ -74,7 +74,7 @@ CONFIG_LOGO=y # CONFIG_LOGO_SUPERH_MONO is not set # CONFIG_LOGO_SUPERH_CLUT224 is not set CONFIG_USB_GADGET=y -CONFIG_USB_GADGET_M66592=y +CONFIG_USB_M66592=y CONFIG_USB_G_SERIAL=m CONFIG_RTC_CLASS=y CONFIG_RTC_DRV_RS5C372=y
arch/sh/configs/sdk7786_defconfig +1 -1
@@ -147,7 +147,7 @@ CONFIG_USB_MON=y CONFIG_USB_OHCI_HCD=y CONFIG_USB_STORAGE=y CONFIG_USB_GADGET=y -CONFIG_USB_GADGET_M66592=y +CONFIG_USB_M66592=y CONFIG_RTC_CLASS=y CONFIG_RTC_DRV_MAX6900=y CONFIG_RTC_DRV_SH=y
arch/sh/configs/shx3_defconfig +1 -1
@@ -79,7 +79,7 @@ CONFIG_USB=y CONFIG_USB_MON=y CONFIG_USB_R8A66597_HCD=m CONFIG_USB_GADGET=y -CONFIG_USB_GADGET_M66592=y +CONFIG_USB_M66592=y CONFIG_RTC_CLASS=y CONFIG_RTC_DRV_SH=y CONFIG_UIO=m
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 911/1756 efi/libstub: Fix error unwind freeing fdt in allocate_new_fdt_and_exit_boot()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jason Gunthorpe <[email protected]>
[ Upstream commit d83fe67339f2032d8facf0fe8a047a4c5d15394f ]
Sashiko says fdt_addr can point to either an allocated fdt or the fdt from get_fdt() which is memory owned by FW.
Only the allocated fdt should be freed on the error unwind path. Use a dedicated variable for the allocation's size so that the free does not get confused.
--- drivers/firmware/efi/libstub/fdt.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/firmware/efi/libstub/fdt.c +4 -2
@@ -229,6 +229,7 @@ efi_status_t allocate_new_fdt_and_exit_boot(void *handle,u32 desc_ver;efi_status_t status;struct exit_boot_struct priv; +unsigned long fdt_size_allocated =0 ;unsigned long fdt_addr =0 ;unsigned long fdt_size =0 ;
@@ -251,12 +252,13 @@ efi_status_t allocate_new_fdt_and_exit_boot(void *handle,if (strstr (cmdline_ptr,"dtb=" ))efi_err ("Ignoring DTB from command line.\n" ); }else { - status =efi_load_dtb (image, &fdt_addr, &fdt_size); + status =efi_load_dtb (image, &fdt_addr, &fdt_size_allocated);if (status !=EFI_SUCCESS && status !=EFI_NOT_READY ) {efi_err ("Failed to load device tree!\n" ); goto fail; } + fdt_size = fdt_size_allocated; }if (fdt_addr) {
@@ -334,7 +336,7 @@ efi_status_t allocate_new_fdt_and_exit_boot(void *handle,efi_free (MAX_FDT_SIZE , *new_fdt_addr); fail: -efi_free (fdt_size, fdt_addr); +efi_free (fdt_size_allocated, fdt_addr);if (!efi_novamap)efi_bs_call (free_pool, priv.runtime_map);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 912/1756 efi/riscv: libstub: Dont set image_size in handle_kernel_image()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jason Gunthorpe <[email protected]>
[ Upstream commit fd4465f49b53c7379d10610f8edb71f77366a5b7 ]
Sashiko points out the image_size should only be set if image_addr was reassigned to some allocated memory. If image_size is not zero then the caller will free the image_addr pointer.
efi_kaslr_relocate_kernel() never works like that, if it changes image_addr to allocated memory the free is done through reserve_size.
--- drivers/firmware/efi/libstub/riscv-stub.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/firmware/efi/libstub/riscv-stub.c +2 -5
@@ -37,17 +37,14 @@ efi_status_t handle_kernel_image(unsigned long *image_addr, kernel_codesize = __init_text_end - _start; kernel_memsize = kernel_size + (_end - _edata); *image_addr = (unsigned long )_start; - *image_size = kernel_memsize; - *reserve_size = *image_size; + *reserve_size = kernel_memsize; status =efi_kaslr_relocate_kernel (image_addr, reserve_addr, reserve_size, kernel_size, kernel_codesize, kernel_memsize,efi_kaslr_get_phys_seed (image_handle)); -if (status !=EFI_SUCCESS ) { +if (status !=EFI_SUCCESS )efi_err ("Failed to relocate kernel\n" ); - *image_size =0 ; - }return status; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 913/1756 x86/efi: Drop support for the EFI_PROPERTIES_TABLE
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicolas Saenz Julienne <[email protected]>
[ Upstream commit 7eb4e1dd71009472215bc1f8226ee9a041da8d37 ]
Drop support for the EFI_PROPERTIES_TABLE. It was a failed, short-lived experiment that broke the boot both on Linux and Windows, and was replaced by the EFI_MEMORY_ATTRIBUTES_TABLE shortly after.
Stable-dep-of: 8ea857a2bb54 ("efi/libstub: Free cmdline_ptr in efi_pe_entry")
--- arch/x86/platform/efi/efi.c | 19 --------------- arch/x86/platform/efi/efi_64.c | 42 ---------------------------------- include/linux/efi.h | 17 +++----------- 3 files changed, 3 insertions(+), 75 deletions(-)
arch/x86/platform/efi/efi.c +0 -19
@@ -54,14 +54,12 @@#include <asm/uv/uv.h> static unsigned long efi_systab_phys__initdata ; -static unsigned long prop_phys =EFI_INVALID_TABLE_ADDR ;static unsigned long uga_phys =EFI_INVALID_TABLE_ADDR ;static unsigned long efi_runtime, efi_nr_tables;unsigned long efi_fw_vendor, efi_config_table;static const efi_config_table_type_t arch_tables[]__initconst = { - {EFI_PROPERTIES_TABLE_GUID , &prop_phys,"PROP" }, {UGA_IO_PROTOCOL_GUID , &uga_phys,"UGA" }, #ifdef CONFIG_X86_UV {UV_SYSTEM_TABLE_GUID, &uv_systab_phys, "UVsystab" },
@@ -82,7 +80,6 @@ static const unsigned long * const efi_tables[] = { &efi_runtime, &efi_config_table, &efi.esrt, - &prop_phys, &efi_mem_attr_table, #ifdef CONFIG_EFI_RCI2_TABLE &rci2_table_phys,
@@ -502,22 +499,6 @@ void __init efi_init(void)return ; } -/* Parse the EFI Properties table if it exists */ -if (prop_phys !=EFI_INVALID_TABLE_ADDR ) { -efi_properties_table_t *tbl; - - tbl =early_memremap_ro (prop_phys,sizeof (*tbl)); -if (tbl ==NULL ) { -pr_err ("Could not map Properties table!\n" ); - }else { -if (tbl->memory_protection_attribute & -EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA ) -set_bit (EFI_NX_PE_DATA , &efi.flags); - -early_memunmap (tbl,sizeof (*tbl)); - } - } -set_bit (EFI_RUNTIME_SERVICES , &efi.flags);efi_clean_memmap ();
arch/x86/platform/efi/efi_64.c +0 -42
51 lines not on this page · raw message
include/linux/efi.h +3 -14
@@ -380,7 +380,6 @@ void efi_native_runtime_setup(void);#define EFI_SYSTEM_RESOURCE_TABLE_GUID EFI_GUID(0xb122a263, 0x3661, 0x4f68, 0x99, 0x29, 0x78, 0xf8, 0xb0, 0xd6, 0x21, 0x80)#define EFI_FILE_SYSTEM_GUID EFI_GUID(0x964e5b22, 0x6459, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)#define DEVICE_TREE_GUID EFI_GUID(0xb1b621d5, 0xf19c, 0x41a5, 0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0) -#define EFI_PROPERTIES_TABLE_GUID EFI_GUID(0x880aaca3, 0x4adc, 0x4a04, 0x90, 0x79, 0xb7, 0x47, 0x34, 0x08, 0x25, 0xe5)#define EFI_RNG_PROTOCOL_GUID EFI_GUID(0x3152bca5, 0xeade, 0x433d, 0x86, 0x2e, 0xc0, 0x1c, 0xdc, 0x29, 0x1f, 0x44)#define EFI_RNG_ALGORITHM_RAW EFI_GUID(0xe43176d7, 0xb6e8, 0x4827, 0xb7, 0x84, 0x7f, 0xfd, 0xc4, 0xb6, 0x85, 0x61)#define EFI_MEMORY_ATTRIBUTES_TABLE_GUID EFI_GUID(0xdcfa911d, 0x26eb, 0x469f, 0xa2, 0x20, 0x38, 0xb7, 0xdc, 0x46, 0x12, 0x20)
@@ -581,15 +580,6 @@ struct efi_mem_range {u64 attribute; }; -typedef struct { -u32 version; -u32 length; -u64 memory_protection_attribute; -}efi_properties_table_t ; - -#define EFI_PROPERTIES_TABLE_VERSION 0x00010000 -#define EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA 0x1 - typedef struct { u16 version; u16 length;
@@ -872,10 +862,9 @@ static inline int efi_range_is_wc(unsigned long start, unsigned long len)#define EFI_PARAVIRT 6/* Access is via a paravirt interface */ #define EFI_ARCH_1 7/* First arch-specific bit */ #define EFI_DBG 8/* Print additional debug info at runtime */ -#define EFI_NX_PE_DATA 9/* Can runtime data regions be mapped non-executable? */ -#define EFI_MEM_ATTR 10/* Did firmware publish an EFI_MEMORY_ATTRIBUTES table? */ -#define EFI_MEM_NO_SOFT_RESERVE 11/* Is the kernel configured to ignore soft reservations? */ -#define EFI_PRESERVE_BS_REGIONS 12/* Are EFI boot-services memory segments available? */ +#define EFI_MEM_ATTR 9/* Did firmware publish an EFI_MEMORY_ATTRIBUTES table? */ +#define EFI_MEM_NO_SOFT_RESERVE 10/* Is the kernel configured to ignore soft reservations? */ +#define EFI_PRESERVE_BS_REGIONS 11/* Are EFI boot-services memory segments available? */ #ifdef CONFIG_EFI /*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 914/1756 x86/efistub: Drop long obsolete UGA support
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ard Biesheuvel <[email protected]>
[ Upstream commit 144d52dd8fc83a082a275e1b663e7454d2b616a4 ]
UGA is the EFI graphical output protocol that preceded GOP, and has been long obsolete. Drop support for it from the x86 implementation of the EFI stub - other architectures never bothered to implement it (save for ia64)
Stable-dep-of: 8ea857a2bb54 ("efi/libstub: Free cmdline_ptr in efi_pe_entry")
--- arch/x86/platform/efi/efi.c | 10 --- drivers/firmware/efi/efi.c | 3 - drivers/firmware/efi/libstub/x86-stub.c | 90 ------------------------- include/linux/efi.h | 4 -- 4 files changed, 107 deletions(-)
arch/x86/platform/efi/efi.c +0 -10
@@ -54,13 +54,11 @@#include <asm/uv/uv.h> static unsigned long efi_systab_phys__initdata ; -static unsigned long uga_phys =EFI_INVALID_TABLE_ADDR ;static unsigned long efi_runtime, efi_nr_tables;unsigned long efi_fw_vendor, efi_config_table;static const efi_config_table_type_t arch_tables[]__initconst = { - {UGA_IO_PROTOCOL_GUID , &uga_phys,"UGA" }, #ifdef CONFIG_X86_UV {UV_SYSTEM_TABLE_GUID , &uv_systab_phys,"UVsystab" }, #endif
@@ -72,7 +70,6 @@ static const unsigned long * const efi_tables[] = { &efi.acpi20, &efi.smbios, &efi.smbios3, - &uga_phys, #ifdef CONFIG_X86_UV &uv_systab_phys, #endif
@@ -890,13 +887,6 @@ bool efi_is_table_address(unsigned long phys_addr)return false; } -char *efi_systab_show_arch (char *str) -{ -if (uga_phys !=EFI_INVALID_TABLE_ADDR ) - str +=sprintf (str,"UGA=0x%lx\n" , uga_phys); -return str; -} -#define EFI_FIELD (var) efi_ ## var#define EFI_ATTR_SHOW (name) \
drivers/firmware/efi/efi.c +0 -3
@@ -148,9 +148,6 @@ static ssize_t systab_show(struct kobject *kobj,if (efi.smbios !=EFI_INVALID_TABLE_ADDR ) str +=sprintf (str,"SMBIOS=0x%lx\n" , efi.smbios); -if (IS_ENABLED (CONFIG_X86 )) - str =efi_systab_show_arch (str); -return str - buf; }
drivers/firmware/efi/libstub/x86-stub.c +0 -90
109 lines not on this page · raw message
include/linux/efi.h +0 -4
@@ -364,7 +364,6 @@ void efi_native_runtime_setup(void);#define ACPI_20_TABLE_GUID EFI_GUID(0x8868e871, 0xe4f1, 0x11d3, 0xbc, 0x22, 0x00, 0x80, 0xc7, 0x3c, 0x88, 0x81)#define SMBIOS_TABLE_GUID EFI_GUID(0xeb9d2d31, 0x2d88, 0x11d3, 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d)#define SMBIOS3_TABLE_GUID EFI_GUID(0xf2fd1544, 0x9794, 0x4a2c, 0x99, 0x2e, 0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94) -#define UGA_IO_PROTOCOL_GUID EFI_GUID(0x61a4d49e, 0x6f68, 0x4f1b, 0xb9, 0x22, 0xa8, 0x6e, 0xed, 0x0b, 0x07, 0xa2)#define EFI_GLOBAL_VARIABLE_GUID EFI_GUID(0x8be4df61, 0x93ca, 0x11d2, 0xaa, 0x0d, 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c)#define UV_SYSTEM_TABLE_GUID EFI_GUID(0x3b13a7d4, 0x633e, 0x11dd, 0x93, 0xec, 0xda, 0x25, 0x56, 0xd8, 0x95, 0x93)#define LINUX_EFI_CRASH_GUID EFI_GUID(0xcfc8fc79, 0xbe2e, 0x4ddc, 0x97, 0xf0, 0x9f, 0x98, 0xbf, 0xe2, 0x98, 0xa0)
@@ -374,7 +373,6 @@ void efi_native_runtime_setup(void);#define EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID EFI_GUID(0x8b843e20, 0x8132, 0x4852, 0x90, 0xcc, 0x55, 0x1a, 0x4e, 0x4a, 0x7f, 0x1c)#define EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL_GUID EFI_GUID(0x05c99a21, 0xc70f, 0x4ad2, 0x8a, 0x5f, 0x35, 0xdf, 0x33, 0x43, 0xf5, 0x1e)#define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID EFI_GUID(0x9042a9de, 0x23dc, 0x4a38, 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a) -#define EFI_UGA_PROTOCOL_GUID EFI_GUID(0x982c298b, 0xf4fa, 0x41cb, 0xb8, 0x38, 0x77, 0xaa, 0x68, 0x8f, 0xb8, 0x39)#define EFI_PCI_IO_PROTOCOL_GUID EFI_GUID(0x4cf5b200, 0x68b8, 0x4ca5, 0x9e, 0xec, 0xb2, 0x3e, 0x3f, 0x50, 0x02, 0x9a)#define EFI_FILE_INFO_ID EFI_GUID(0x09576e92, 0x6d3f, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b)#define EFI_SYSTEM_RESOURCE_TABLE_GUID EFI_GUID(0xb122a263, 0x3661, 0x4f68, 0x99, 0x29, 0x78, 0xf8, 0xb0, 0xd6, 0x21, 0x80)
@@ -1287,8 +1285,6 @@ struct linux_efi_memreserve {void __init efi_arch_mem_reserve (phys_addr_t addr,u64 size); -char *efi_systab_show_arch (char *str); -/* * The LINUX_EFI_MOK_VARIABLE_TABLE_GUID config table can be provided * to the kernel by an EFI boot loader. The table contains a packed
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 915/1756 efi/libstub: Use C99-style for loop to traverse handle buffer
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ard Biesheuvel <[email protected]>
[ Upstream commit c14bca3f7aa94fd8d3f5e621ce5b56535ef2396b ]
Tweak the for_each_efi_handle() macro in order to avoid the need on the part of the caller to provide a loop counter variable.
Also move efi_get_handle_num() to the callers, so that each occurrence can be replaced with the actual number returned by the simplified LocateHandleBuffer API.
Stable-dep-of: 8ea857a2bb54 ("efi/libstub: Free cmdline_ptr in efi_pe_entry")
--- drivers/firmware/efi/libstub/efistub.h | 9 ++++----- drivers/firmware/efi/libstub/gop.c | 3 +-- drivers/firmware/efi/libstub/pci.c | 5 ++--- drivers/firmware/efi/libstub/x86-stub.c | 3 +-- 4 files changed, 8 insertions(+), 12 deletions(-)
drivers/firmware/efi/libstub/efistub.h +4 -5
@@ -122,11 +122,10 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,#define efi_get_handle_num (size) \ ((size) / (efi_is_native() ? sizeof(efi_handle_t) : sizeof(u32))) -#define for_each_efi_handle (handle, array, size, i) \ - for (i = 0; \ - i < efi_get_handle_num(size) && \ - ((handle = efi_get_handle_at((array), i)) || true); \ - i++) +#define for_each_efi_handle (handle, array, num) \ + for (int __i = 0; __i < (num) && \ + ((handle = efi_get_handle_at((array), __i)) || true); \ + __i++)static inline void efi_set_u64_split (u64 data,u32 *lo,u32 *hi)
drivers/firmware/efi/libstub/gop.c +1 -2
@@ -466,11 +466,10 @@ find_gop(efi_guid_t *proto, unsigned long size, void **handles) {efi_graphics_output_protocol_t *first_gop;efi_handle_t h; -int i; first_gop =NULL ; -for_each_efi_handle (h, handles, size, i) { +for_each_efi_handle (h, handles,efi_get_handle_num (size)) {efi_status_t status;efi_graphics_output_protocol_t *gop;
drivers/firmware/efi/libstub/pci.c +2 -3
@@ -21,7 +21,6 @@ void efi_pci_disable_bridge_busmaster(void)efi_handle_t handle;efi_status_t status;u16 class, command; -int i; status =efi_bs_call (locate_handle,EFI_LOCATE_BY_PROTOCOL , &pci_proto,NULL , &pci_handle_size,NULL );
@@ -46,7 +45,7 @@ void efi_pci_disable_bridge_busmaster(void) goto free_handle; } -for_each_efi_handle (handle, pci_handle, pci_handle_size, i) { +for_each_efi_handle (handle, pci_handle,efi_get_handle_num (pci_handle_size)) {efi_pci_io_protocol_t *pci;unsigned long segment_nr, bus_nr, device_nr, func_nr;
@@ -82,7 +81,7 @@ void efi_pci_disable_bridge_busmaster(void)efi_bs_call (disconnect_controller, handle,NULL ,NULL ); } -for_each_efi_handle (handle, pci_handle, pci_handle_size, i) { +for_each_efi_handle (handle, pci_handle,efi_get_handle_num (pci_handle_size)) {efi_pci_io_protocol_t *pci; status = efi_bs_call(handle_protocol, handle, &pci_proto,
drivers/firmware/efi/libstub/x86-stub.c +1 -2
@@ -124,7 +124,6 @@ static void setup_efi_pci(struct boot_params *params)unsigned long size =0 ;struct setup_data *data;efi_handle_t h; -int i; status =efi_bs_call (locate_handle,EFI_LOCATE_BY_PROTOCOL , &pci_proto,NULL , &size, pci_handle);
@@ -150,7 +149,7 @@ static void setup_efi_pci(struct boot_params *params)while (data && data->next) data = (struct setup_data *)(unsigned long )data->next; -for_each_efi_handle (h, pci_handle, size, i) { +for_each_efi_handle (h, pci_handle,efi_get_handle_num (size)) {efi_pci_io_protocol_t *pci =NULL ;struct pci_setup_rom *rom;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 916/1756 efi/libstub: Simplify GOP handling code
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ard Biesheuvel <[email protected]>
[ Upstream commit 60a34085c36d6eb292c1e03bc355b1aa3a74a689 ]
Use the LocateHandleBuffer() API and a __free() function to simplify the logic that allocates a handle buffer to iterate over all GOP protocols in the EFI database.
Stable-dep-of: 8ea857a2bb54 ("efi/libstub: Free cmdline_ptr in efi_pe_entry")
--- arch/x86/include/asm/efi.h | 3 ++ drivers/firmware/efi/libstub/efi-stub.c | 28 +++++------- drivers/firmware/efi/libstub/efistub.h | 9 ++-- drivers/firmware/efi/libstub/gop.c | 57 +++++++++---------------- drivers/firmware/efi/libstub/x86-stub.c | 17 +------- 5 files changed, 40 insertions(+), 74 deletions(-)
arch/x86/include/asm/efi.h +3 -0
@@ -250,6 +250,9 @@ static inline u32 efi64_convert_status(efi_status_t status)#define __efi64_argmap_allocate_pool (type, size, buffer) \ ((type), (size), efi64_zero_upper(buffer)) +#define __efi64_argmap_locate_handle_buffer (type, proto, key, num, buf) \ + ((type), (proto), (key), efi64_zero_upper(num), efi64_zero_upper(buf)) +#define __efi64_argmap_create_event (type, tpl, f, c, event) \ ((type), (tpl), (f), (c), efi64_zero_upper(event))
drivers/firmware/efi/libstub/efi-stub.c +10 -18
@@ -10,6 +10,7 @@*/ #include <linux/efi.h> +#include <linux/screen_info.h> #include <asm/efi.h> #include "efistub.h"
@@ -53,25 +54,16 @@ void __weak free_screen_info(struct screen_info *si)static struct screen_info *setup_graphics (void ) { -efi_guid_t gop_proto =EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID ; -efi_status_t status; -unsigned long size; -void **gop_handle =NULL ; -struct screen_info *si =NULL ; +struct screen_info *si, tmp = {}; - size =0 ; - status =efi_bs_call (locate_handle,EFI_LOCATE_BY_PROTOCOL , - &gop_proto,NULL , &size, gop_handle); -if (status ==EFI_BUFFER_TOO_SMALL ) { - si =alloc_screen_info (); -if (!si) -return NULL ; - status =efi_setup_gop (si, &gop_proto, size); -if (status !=EFI_SUCCESS ) { -free_screen_info (si); -return NULL ; - } - } +if (efi_setup_gop (&tmp) !=EFI_SUCCESS ) +return NULL ; + + si =alloc_screen_info (); +if (!si) +return NULL ; + + *si = tmp;return si; }
drivers/firmware/efi/libstub/efistub.h +6 -3
@@ -4,6 +4,7 @@#define _DRIVERS_FIRMWARE_EFI_EFISTUB_H#include <linux/compiler.h> +#include <linux/cleanup.h> #include <linux/efi.h> #include <linux/kernel.h> #include <linux/kern_levels.h>
@@ -313,7 +314,9 @@ union efi_boot_services {void *close_protocol;void *open_protocol_information;void *protocols_per_handle; -void *locate_handle_buffer; + efi_status_t (__efiapi *locate_handle_buffer)(int, efi_guid_t *, + void *, unsigned long *, + efi_handle_t **); efi_status_t (__efiapi *locate_protocol)(efi_guid_t *, void *, void **); efi_status_t (__efiapi *install_multiple_protocol_interfaces)(efi_handle_t *, ...);
@@ -1052,6 +1055,7 @@ void efi_puts(const char *str); __printf(1, 2) int efi_printk(char const *fmt, ...);void efi_free (unsigned long size,unsigned long addr); +DEFINE_FREE(efi_pool, void *, if (_T) efi_bs_call(free_pool, _T));void efi_apply_loadoptions_quirk (const void **load_options,u32 *load_options_size);
@@ -1081,8 +1085,7 @@ efi_status_t efi_parse_options(char const *cmdline);void efi_parse_option_graphics (char *option); -efi_status_t efi_setup_gop (struct screen_info *si,efi_guid_t *proto, -unsigned long size); +efi_status_t efi_setup_gop (struct screen_info *si); efi_status_t handle_cmdline_files(efi_loaded_image_t *image, const efi_char16_t *optstr,
drivers/firmware/efi/libstub/gop.c +19 -38
96 lines not on this page · raw message
drivers/firmware/efi/libstub/x86-stub.c +2 -15
@@ -406,24 +406,11 @@ static void setup_quirks(struct boot_params *boot_params)static void setup_graphics (struct boot_params *boot_params) { -efi_guid_t graphics_proto =EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID ; -struct screen_info *si; -efi_status_t status; -unsigned long size; -void **gop_handle =NULL ; - - si = &boot_params->screen_info; -memset (si,0 ,sizeof (*si)); - - size =0 ; - status =efi_bs_call (locate_handle,EFI_LOCATE_BY_PROTOCOL , - &graphics_proto,NULL , &size, gop_handle); -if (status ==EFI_BUFFER_TOO_SMALL ) - status =efi_setup_gop (si, &graphics_proto, size); +struct screen_info *si =memset (&boot_params->screen_info,0 ,sizeof (*si)); +efi_setup_gop (si); } -static void __noreturn efi_exit (efi_handle_t handle,efi_status_t status) {efi_bs_call (exit, handle, status,0 ,NULL );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 917/1756 efi/libstub: Simplify PCI I/O handle buffer traversal
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ard Biesheuvel <[email protected]>
[ Upstream commit 90534e689d2e52202c276ade5cf1dfc13d9e116f ]
Use LocateHandleBuffer() and a __free() cleanup helper to simplify the PCI I/O handle buffer traversal code.
Stable-dep-of: 8ea857a2bb54 ("efi/libstub: Free cmdline_ptr in efi_pe_entry")
--- drivers/firmware/efi/libstub/pci.c | 33 ++++++------------------- drivers/firmware/efi/libstub/x86-stub.c | 29 +++++----------------- 2 files changed, 13 insertions(+), 49 deletions(-)
drivers/firmware/efi/libstub/pci.c +7 -26
@@ -16,36 +16,20 @@void efi_pci_disable_bridge_busmaster (void ) {efi_guid_t pci_proto =EFI_PCI_IO_PROTOCOL_GUID ; -unsigned long pci_handle_size =0 ; -efi_handle_t *pci_handle =NULL ; + efi_handle_t *pci_handle __free(efi_pool) = NULL; +unsigned long pci_handle_num;efi_handle_t handle;efi_status_t status;u16 class, command; - status =efi_bs_call (locate_handle,EFI_LOCATE_BY_PROTOCOL , &pci_proto, -NULL , &pci_handle_size,NULL ); - -if (status !=EFI_BUFFER_TOO_SMALL ) { -if (status !=EFI_SUCCESS && status !=EFI_NOT_FOUND ) -efi_err ("Failed to locate PCI I/O handles'\n" ); -return ; - } - - status =efi_bs_call (allocate_pool,EFI_LOADER_DATA , pci_handle_size, - (void **)&pci_handle); + status =efi_bs_call (locate_handle_buffer,EFI_LOCATE_BY_PROTOCOL , + &pci_proto,NULL , &pci_handle_num, &pci_handle);if (status !=EFI_SUCCESS ) { -efi_err ("Failed to allocate memory for 'pci_handle'\n" ); +efi_err ("Failed to locate PCI I/O handles\n" );return ; } - status =efi_bs_call (locate_handle,EFI_LOCATE_BY_PROTOCOL , &pci_proto, -NULL , &pci_handle_size, pci_handle); -if (status !=EFI_SUCCESS ) { -efi_err ("Failed to locate PCI I/O handles'\n" ); - goto free_handle; - } - -for_each_efi_handle (handle, pci_handle,efi_get_handle_num (pci_handle_size)) { +for_each_efi_handle (handle, pci_handle, pci_handle_num) {efi_pci_io_protocol_t *pci;unsigned long segment_nr, bus_nr, device_nr, func_nr;
@@ -81,7 +65,7 @@ void efi_pci_disable_bridge_busmaster(void)efi_bs_call (disconnect_controller, handle,NULL ,NULL ); } -for_each_efi_handle (handle, pci_handle,efi_get_handle_num (pci_handle_size)) { +for_each_efi_handle (handle, pci_handle, pci_handle_num) {efi_pci_io_protocol_t *pci; status = efi_bs_call(handle_protocol, handle, &pci_proto,
@@ -107,7 +91,4 @@ void efi_pci_disable_bridge_busmaster(void)if (status !=EFI_SUCCESS )efi_err ("Failed to disable PCI busmastering\n" ); } - -free_handle: -efi_bs_call (free_pool, pci_handle); }
drivers/firmware/efi/libstub/x86-stub.c +6 -23
@@ -119,37 +119,23 @@ preserve_pci_rom_image(efi_pci_io_protocol_t *pci, struct pci_setup_rom **__rom)static void setup_efi_pci (struct boot_params *params) {efi_status_t status; -void **pci_handle =NULL ; + efi_handle_t *pci_handle __free(efi_pool) = NULL;efi_guid_t pci_proto =EFI_PCI_IO_PROTOCOL_GUID ; -unsigned long size =0 ;struct setup_data *data; +unsigned long num;efi_handle_t h; - status =efi_bs_call (locate_handle,EFI_LOCATE_BY_PROTOCOL , - &pci_proto,NULL , &size, pci_handle); - -if (status ==EFI_BUFFER_TOO_SMALL ) { - status =efi_bs_call (allocate_pool,EFI_LOADER_DATA , size, - (void **)&pci_handle); - -if (status !=EFI_SUCCESS ) { -efi_err ("Failed to allocate memory for 'pci_handle'\n" ); -return ; - } - - status =efi_bs_call (locate_handle,EFI_LOCATE_BY_PROTOCOL , - &pci_proto,NULL , &size, pci_handle); - } - + status =efi_bs_call (locate_handle_buffer,EFI_LOCATE_BY_PROTOCOL , + &pci_proto,NULL , &num, &pci_handle);if (status !=EFI_SUCCESS ) - goto free_handle; +return ; data = (struct setup_data *)(unsigned long )params->hdr.setup_data;while (data && data->next) data = (struct setup_data *)(unsigned long )data->next; -for_each_efi_handle (h, pci_handle,efi_get_handle_num (size)) { +for_each_efi_handle (h, pci_handle, num) {efi_pci_io_protocol_t *pci =NULL ;struct pci_setup_rom *rom;
@@ -169,9 +155,6 @@ static void setup_efi_pci(struct boot_params *params) data = (struct setup_data *)rom; } - -free_handle: -efi_bs_call (free_pool, pci_handle); }static void retrieve_apple_device_properties (struct boot_params *boot_params)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 918/1756 efi/libstub: Use cleanup helpers for freeing copies of the memory map
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ard Biesheuvel <[email protected]>
[ Upstream commit ad69b0b6f9954796875ee4faf6c16c9caca21999 ]
The EFI stub may obtain the memory map from the firmware numerous times, and this involves doing a EFI pool allocation first, which needs to be freed after use.
Streamline this using a cleanup helper, which makes the code easier to follow.
Stable-dep-of: 8ea857a2bb54 ("efi/libstub: Free cmdline_ptr in efi_pe_entry")
--- drivers/firmware/efi/libstub/kaslr.c | 4 +--- drivers/firmware/efi/libstub/mem.c | 20 ++++++++------------ drivers/firmware/efi/libstub/randomalloc.c | 4 +--- drivers/firmware/efi/libstub/relocate.c | 10 ++++------ drivers/firmware/efi/libstub/x86-stub.c | 11 ++++++----- 5 files changed, 20 insertions(+), 29 deletions(-)
drivers/firmware/efi/libstub/kaslr.c +1 -3
@@ -57,7 +57,7 @@ u32 efi_kaslr_get_phys_seed(efi_handle_t image_handle)*/ static bool check_image_region (u64 base,u64 size) { -struct efi_boot_memmap *map; + struct efi_boot_memmap *map __free(efi_pool) = NULL;efi_status_t status;bool ret = false;int map_offset;
@@ -80,8 +80,6 @@ static bool check_image_region(u64 base, u64 size) } } -efi_bs_call (free_pool, map); -return ret; }
drivers/firmware/efi/libstub/mem.c +8 -12
@@ -20,10 +20,10 @@efi_status_t efi_get_memory_map (struct efi_boot_memmap **map,bool install_cfg_tbl) { + struct efi_boot_memmap tmp, *m __free(efi_pool) = NULL;int memtype = install_cfg_tbl ?EFI_ACPI_RECLAIM_MEMORY :EFI_LOADER_DATA ;efi_guid_t tbl_guid =LINUX_EFI_BOOT_MEMMAP_GUID ; -struct efi_boot_memmap *m, tmp;efi_status_t status;unsigned long size;
@@ -48,24 +48,20 @@ efi_status_t efi_get_memory_map(struct efi_boot_memmap **map,*/ status =efi_bs_call (install_configuration_table, &tbl_guid, m);if (status !=EFI_SUCCESS ) - goto free_map; +return status; } m->buff_size = m->map_size = size; status =efi_bs_call (get_memory_map, &m->map_size, m->map, &m->map_key, &m->desc_size, &m->desc_ver); -if (status !=EFI_SUCCESS ) - goto uninstall_table; +if (status !=EFI_SUCCESS ) { +if (install_cfg_tbl) +efi_bs_call (install_configuration_table, &tbl_guid,NULL ); +return status; + } - *map = m; + *map =no_free_ptr (m);return EFI_SUCCESS ; - -uninstall_table: -if (install_cfg_tbl) -efi_bs_call (install_configuration_table, &tbl_guid,NULL ); -free_map: -efi_bs_call (free_pool, m); -return status; }/**
drivers/firmware/efi/libstub/randomalloc.c +1 -3
@@ -62,9 +62,9 @@ efi_status_t efi_random_alloc(unsigned long size,unsigned long alloc_min, unsigned long alloc_max) { + struct efi_boot_memmap *map __free(efi_pool) = NULL;unsigned long total_slots =0 , target_slot;unsigned long total_mirrored_slots =0 ; -struct efi_boot_memmap *map;efi_status_t status;int map_offset;
@@ -137,7 +137,5 @@ efi_status_t efi_random_alloc(unsigned long size,break ; } -efi_bs_call (free_pool, map); -return status; }
drivers/firmware/efi/libstub/relocate.c +4 -6
@@ -23,14 +23,14 @@efi_status_t efi_low_alloc_above (unsigned long size,unsigned long align,unsigned long *addr,unsigned long min) { -struct efi_boot_memmap *map; + struct efi_boot_memmap *map __free(efi_pool) = NULL;efi_status_t status;unsigned long nr_pages;int i; status =efi_get_memory_map (&map, false);if (status !=EFI_SUCCESS ) - goto fail; +return status;/* * Enforce minimum alignment that EFI or Linux requires when
@@ -82,11 +82,9 @@ efi_status_t efi_low_alloc_above(unsigned long size, unsigned long align, }if (i == map->map_size / map->desc_size) - status =EFI_NOT_FOUND ; +return EFI_NOT_FOUND ; -efi_bs_call (free_pool, map); -fail: -return status; +return EFI_SUCCESS ; }/**
drivers/firmware/efi/libstub/x86-stub.c +6 -5
@@ -617,7 +617,7 @@ static efi_status_t allocate_e820(struct boot_params *params,struct setup_data **e820ext, u32 *e820ext_size) { - struct efi_boot_memmap *map; + struct efi_boot_memmap *map __free(efi_pool) = NULL;efi_status_t status;__u32 nr_desc;
@@ -631,13 +631,14 @@ static efi_status_t allocate_e820(struct boot_params *params,EFI_MMAP_NR_SLACK_SLOTS ; status =alloc_e820ext (nr_e820ext, e820ext, e820ext_size); +if (status !=EFI_SUCCESS ) +return status; } -if (IS_ENABLED (CONFIG_UNACCEPTED_MEMORY ) && status ==EFI_SUCCESS ) - status =allocate_unaccepted_bitmap (nr_desc, map); +if (IS_ENABLED (CONFIG_UNACCEPTED_MEMORY )) +return allocate_unaccepted_bitmap (nr_desc, map); -efi_bs_call (free_pool, map); -return status; +return EFI_SUCCESS ; }struct exit_boot_struct {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 919/1756 x86/efistub: Merge PE and handover entrypoints
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ard Biesheuvel <[email protected]>
[ Upstream commit dac628e9563640e2de7878decc03a508b1ba319a ]
The difference between the PE and handover entrypoints in the EFI stub is that the former allocates a struct boot_params whereas the latter expects one from the caller. Currently, these are two completely separate entrypoints, duplicating some logic and both relying of efi_exit() to return straight back to the firmware on an error.
Simplify this by making the PE entrypoint call the handover entrypoint with NULL as the argument for the struct boot_params parameter. This makes the code easier to follow, and removes the need to support two different calling conventions in the mixed mode asm code.
While at it, move the assignment of boot_params_ptr into the function that actually calls into the legacy decompressor, which is where its value is required.
Stable-dep-of: 8ea857a2bb54 ("efi/libstub: Free cmdline_ptr in efi_pe_entry")
--- arch/x86/boot/compressed/efi_mixed.S | 16 +------- drivers/firmware/efi/libstub/x86-stub.c | 52 ++++++++++++++----------- 2 files changed, 30 insertions(+), 38 deletions(-)
arch/x86/boot/compressed/efi_mixed.S +1 -15
@@ -56,22 +56,8 @@ SYM_FUNC_START(startup_64_mixed_mode) movl efi32_boot_sp(%rip), %esp andl $~7, %esp -#ifdef CONFIG_EFI_HANDOVER_PROTOCOL mov 8(%rdx), %edx // saved bootparams pointer - test %edx, %edx - jnz efi_stub_entry -#endif - /* - * efi_pe_entry uses MS calling convention, which requires 32 bytes of - * shadow space on the stack even if all arguments are passed in - * registers. We also need an additional 8 bytes for the space that - * would be occupied by the return address, and this also results in - * the correct stack alignment for entry. - */ - sub $40, %rsp - mov %rdi, %rcx // MS calling convention - mov %rsi, %rdx - jmp efi_pe_entry + call efi_stub_entry SYM_FUNC_END(startup_64_mixed_mode) SYM_FUNC_START(__efi64_thunk)
drivers/firmware/efi/libstub/x86-stub.c +29 -23
134 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 920/1756 efi/libstub: make local GUID variables static
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vincent Mailhol <[email protected]>
[ Upstream commit e57b05932a49b1ef54c6f116b9b044ce37db7dcc ]
Local efi_guid_t variables with automatic storage produce assembly similar to passing the address of the GUID macro directly. For the same reason, make these GUID variables static.
Put the static declarations first in their local declaration block to visually separate them from the automatic variables.
For an x86_64 build with gcc 15.3.0, bloat-o-meter reports:
add/remove: 15/0 grow/shrink: 0/10 up/down: 336/-742 (-406)
Function old new delta
tbl_guid - 32 +32 rng_proto - 32 +32 pci_proto - 32 +32 guid - 32 +32 fs_proto - 32 +32 cc_guid - 32 +32 tpm2_guid - 16 +16 text_to_dp_guid - 16 +16 tcg2_guid - 16 +16 rng_table_guid - 16 +16 rng_algo_raw - 16 +16 proto - 16 +16 linux_eventlog_guid - 16 +16 lf2_proto_guid - 16 +16 info_guid - 16 +16 efi_get_memory_map 707 696 -11 efi_pci_disable_bridge_busmaster 1199 1184 -15 efi_get_random_bytes 216 188 -28 efi_remap_image 357 328 -29 efi_load_initrd 1113 1065 -48 efi_random_get_seed 1368 1297 -71 efi_measure_tagged_event 935 854 -81 efi_retrieve_eventlog 1686 1570 -116 handle_cmdline_files 2501 2341 -160 efi_stub_entry 4136 3953 -183
Total: Before=28877, After=28471, chg -1.41%
Stable-dep-of: 8ea857a2bb54 ("efi/libstub: Free cmdline_ptr in efi_pe_entry")
--- drivers/firmware/efi/libstub/efi-stub-entry.c | 2 +- drivers/firmware/efi/libstub/efi-stub-helper.c | 10 +++++----- drivers/firmware/efi/libstub/efi-stub.c | 2 +- drivers/firmware/efi/libstub/file.c | 8 ++++---- drivers/firmware/efi/libstub/kaslr.c | 2 +- drivers/firmware/efi/libstub/mem.c | 2 +- drivers/firmware/efi/libstub/pci.c | 2 +- drivers/firmware/efi/libstub/random.c | 8 ++++---- drivers/firmware/efi/libstub/riscv.c | 2 +- drivers/firmware/efi/libstub/tpm.c | 8 ++++---- drivers/firmware/efi/libstub/unaccepted_memory.c | 2 +- drivers/firmware/efi/libstub/x86-stub.c | 10 +++++----- 12 files changed, 29 insertions(+), 29 deletions(-)
drivers/firmware/efi/libstub/efi-stub-entry.c +1 -1
@@ -30,13 +30,13 @@ struct screen_info *alloc_screen_info(void) efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,efi_system_table_t *systab) { +static efi_guid_t loaded_image_proto =LOADED_IMAGE_PROTOCOL_GUID ;efi_loaded_image_t *image;efi_status_t status;unsigned long image_addr;unsigned long image_size =0 ;/* addr/point and size pairs for memory management*/ char *cmdline_ptr =NULL ; -efi_guid_t loaded_image_proto =LOADED_IMAGE_PROTOCOL_GUID ;unsigned long reserve_addr =0 ;unsigned long reserve_size =0 ;
drivers/firmware/efi/libstub/efi-stub-helper.c +5 -5
@@ -244,6 +244,7 @@ static efi_status_t efi_measure_tagged_event(unsigned long load_addr,unsigned long load_size, enum efistub_event_type event) { + static efi_guid_t tcg2_guid = EFI_TCG2_PROTOCOL_GUID; union { efi_status_t (__efiapi *hash_log_extend_event)(void *, u64, efi_physical_addr_t,
@@ -253,7 +254,6 @@ static efi_status_t efi_measure_tagged_event(unsigned long load_addr,struct efistub_measured_event *evt;int size =struct_size (evt, tagged_event.tagged_event_data, events[event].event_data_len); -efi_guid_t tcg2_guid =EFI_TCG2_PROTOCOL_GUID ;efi_tcg2_protocol_t *tcg2 =NULL ;union efistub_event ev;efi_status_t status;
@@ -272,7 +272,7 @@ static efi_status_t efi_measure_tagged_event(unsigned long load_addr, method.hash_log_extend_event = (void *)efi_table_attr (tcg2, hash_log_extend_event); }else { -efi_guid_t cc_guid =EFI_CC_MEASUREMENT_PROTOCOL_GUID ; +static efi_guid_t cc_guid =EFI_CC_MEASUREMENT_PROTOCOL_GUID ;efi_cc_protocol_t *cc =NULL ;efi_bs_call (locate_protocol, &cc_guid,NULL , (void **)&cc);
@@ -550,7 +550,7 @@ staticefi_status_t efi_load_initrd_dev_path (struct linux_efi_initrd *initrd,unsigned long max) { -efi_guid_t lf2_proto_guid =EFI_LOAD_FILE2_PROTOCOL_GUID ; +static efi_guid_t lf2_proto_guid =EFI_LOAD_FILE2_PROTOCOL_GUID ;efi_device_path_protocol_t *dp;efi_load_file2_protocol_t *lf2;efi_handle_t handle;
@@ -612,7 +612,7 @@ efi_status_t efi_load_initrd(efi_loaded_image_t *image,unsigned long hard_limit, const struct linux_efi_initrd **out) { - efi_guid_t tbl_guid = LINUX_EFI_INITRD_MEDIA_GUID; + static efi_guid_t tbl_guid = LINUX_EFI_INITRD_MEDIA_GUID;efi_status_t status =EFI_SUCCESS ;struct linux_efi_initrd initrd, *tbl;
@@ -722,7 +722,7 @@ efi_status_t efi_wait_for_key(unsigned long usec, efi_input_key_t *key)void efi_remap_image (unsigned long image_base,unsigned alloc_size,unsigned long code_size) { -efi_guid_t guid =EFI_MEMORY_ATTRIBUTE_PROTOCOL_GUID ; +static efi_guid_t guid =EFI_MEMORY_ATTRIBUTE_PROTOCOL_GUID ;efi_memory_attribute_protocol_t *memattr;efi_status_t status;u64 attr;
drivers/firmware/efi/libstub/efi-stub.c +1 -1
@@ -69,8 +69,8 @@ static struct screen_info *setup_graphics(void)static void install_memreserve_table (void ) { +static efi_guid_t memreserve_table_guid =LINUX_EFI_MEMRESERVE_TABLE_GUID ;struct linux_efi_memreserve *rsv; -efi_guid_t memreserve_table_guid =LINUX_EFI_MEMRESERVE_TABLE_GUID ;efi_status_t status;/*
drivers/firmware/efi/libstub/file.c +4 -4
@@ -39,7 +39,7 @@ static efi_status_t efi_open_file(efi_file_protocol_t *volume,efi_file_protocol_t **handle, unsigned long *file_size) { - efi_guid_t info_guid = EFI_FILE_INFO_ID; + static efi_guid_t info_guid = EFI_FILE_INFO_ID;efi_file_protocol_t *fh;unsigned long info_sz;efi_status_t status;
@@ -74,7 +74,7 @@ static efi_status_t efi_open_file(efi_file_protocol_t *volume,static efi_status_t efi_open_volume (efi_loaded_image_t *image,efi_file_protocol_t **fh) { -efi_guid_t fs_proto =EFI_FILE_SYSTEM_GUID ; +static efi_guid_t fs_proto =EFI_FILE_SYSTEM_GUID ;efi_simple_file_system_protocol_t *io;efi_status_t status;
@@ -128,9 +128,9 @@ static int find_file_option(const efi_char16_t *cmdline, int cmdline_len,static efi_status_t efi_open_device_path (efi_file_protocol_t **volume,struct finfo *fi) { -efi_guid_t text_to_dp_guid =EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL_GUID ; +static efi_guid_t text_to_dp_guid =EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL_GUID ; +static efi_guid_t fs_proto =EFI_FILE_SYSTEM_GUID ;static efi_device_path_from_text_protocol_t *text_to_dp =NULL ; -efi_guid_t fs_proto =EFI_FILE_SYSTEM_GUID ;efi_device_path_protocol_t *initrd_dp;efi_simple_file_system_protocol_t *io;struct efi_file_path_dev_path *fpath;
drivers/firmware/efi/libstub/kaslr.c +1 -1
@@ -18,7 +18,7 @@*/ u32 efi_kaslr_get_phys_seed (efi_handle_t image_handle) { -efi_guid_t li_fixed_proto =LINUX_EFI_LOADED_IMAGE_FIXED_GUID ; +static efi_guid_t li_fixed_proto =LINUX_EFI_LOADED_IMAGE_FIXED_GUID ;void *p;if (!IS_ENABLED (CONFIG_RANDOMIZE_BASE ))
drivers/firmware/efi/libstub/mem.c +1 -1
@@ -20,10 +20,10 @@efi_status_t efi_get_memory_map (struct efi_boot_memmap **map,bool install_cfg_tbl) { +static efi_guid_t tbl_guid =LINUX_EFI_BOOT_MEMMAP_GUID ; struct efi_boot_memmap tmp, *m __free(efi_pool) = NULL;int memtype = install_cfg_tbl ?EFI_ACPI_RECLAIM_MEMORY :EFI_LOADER_DATA ; -efi_guid_t tbl_guid =LINUX_EFI_BOOT_MEMMAP_GUID ;efi_status_t status;unsigned long size;
drivers/firmware/efi/libstub/pci.c +1 -1
@@ -15,7 +15,7 @@void efi_pci_disable_bridge_busmaster (void ) { -efi_guid_t pci_proto =EFI_PCI_IO_PROTOCOL_GUID ; +static efi_guid_t pci_proto =EFI_PCI_IO_PROTOCOL_GUID ; efi_handle_t *pci_handle __free(efi_pool) = NULL;unsigned long pci_handle_num;efi_handle_t handle;
drivers/firmware/efi/libstub/random.c +4 -4
@@ -38,7 +38,7 @@ union efi_rng_protocol {*/ efi_status_t efi_get_random_bytes (unsigned long size,u8 *out) { -efi_guid_t rng_proto =EFI_RNG_PROTOCOL_GUID ; +static efi_guid_t rng_proto =EFI_RNG_PROTOCOL_GUID ;efi_status_t status;efi_rng_protocol_t *rng =NULL ;
@@ -64,9 +64,9 @@ efi_status_t efi_get_random_bytes(unsigned long size, u8 *out)*/ efi_status_t efi_random_get_seed (void ) { -efi_guid_t rng_proto =EFI_RNG_PROTOCOL_GUID ; -efi_guid_t rng_algo_raw =EFI_RNG_ALGORITHM_RAW ; -efi_guid_t rng_table_guid =LINUX_EFI_RANDOM_SEED_TABLE_GUID ; +static efi_guid_t rng_proto =EFI_RNG_PROTOCOL_GUID ; +static efi_guid_t rng_algo_raw =EFI_RNG_ALGORITHM_RAW ; +static efi_guid_t rng_table_guid =LINUX_EFI_RANDOM_SEED_TABLE_GUID ;struct linux_efi_random_seed *prev_seed, *seed =NULL ;int prev_seed_size =0 , seed_size =EFI_RANDOM_SEED_SIZE ;unsigned long nv_seed_size =0 , offset =0 ;
drivers/firmware/efi/libstub/riscv.c +1 -1
@@ -45,7 +45,7 @@ static int get_boot_hartid_from_fdt(void)static efi_status_t get_boot_hartid_from_efi (void ) { -efi_guid_t boot_protocol_guid =RISCV_EFI_BOOT_PROTOCOL_GUID ; +static efi_guid_t boot_protocol_guid =RISCV_EFI_BOOT_PROTOCOL_GUID ;struct riscv_efi_boot_protocol *boot_protocol;efi_status_t status;
drivers/firmware/efi/libstub/tpm.c +4 -4
@@ -28,8 +28,8 @@ static const efi_char16_t efi_MemoryOverWriteRequest_name[] =*/ void efi_enable_reset_attack_mitigation (void ) { +static efi_guid_t var_guid =MEMORY_ONLY_RESET_CONTROL_GUID ;u8 val =1 ; -efi_guid_t var_guid =MEMORY_ONLY_RESET_CONTROL_GUID ;efi_status_t status;unsigned long datasize =0 ;
@@ -52,7 +52,7 @@ static void efi_retrieve_tcg2_eventlog(int version, efi_physical_addr_t log_locaefi_bool_t truncated, struct efi_tcg2_final_events_table *final_events_table) { - efi_guid_t linux_eventlog_guid = LINUX_EFI_TPM_EVENT_LOG_GUID; + static efi_guid_t linux_eventlog_guid = LINUX_EFI_TPM_EVENT_LOG_GUID;efi_status_t status;struct linux_efi_tpm_eventlog *log_tbl =NULL ;unsigned long first_entry_addr, last_entry_addr;
@@ -147,9 +147,9 @@ static void efi_retrieve_tcg2_eventlog(int version, efi_physical_addr_t log_locavoid efi_retrieve_eventlog (void ) { +static efi_guid_t tpm2_guid =EFI_TCG2_PROTOCOL_GUID ;struct efi_tcg2_final_events_table *final_events_table =NULL ;efi_physical_addr_t log_location =0 , log_last_entry =0 ; -efi_guid_t tpm2_guid =EFI_TCG2_PROTOCOL_GUID ;int version =EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 ;efi_tcg2_protocol_t *tpm2 =NULL ;efi_bool_t truncated;
@@ -170,7 +170,7 @@ void efi_retrieve_eventlog(void)get_efi_config_table (EFI_TCG2_FINAL_EVENTS_TABLE_GUID ); } }else { -efi_guid_t cc_guid =EFI_CC_MEASUREMENT_PROTOCOL_GUID ; +static efi_guid_t cc_guid =EFI_CC_MEASUREMENT_PROTOCOL_GUID ;efi_cc_protocol_t *cc =NULL ; status =efi_bs_call (locate_protocol, &cc_guid,NULL , (void **)&cc);
drivers/firmware/efi/libstub/unaccepted_memory.c +1 -1
@@ -9,7 +9,7 @@ struct efi_unaccepted_memory *unaccepted_table;efi_status_t allocate_unaccepted_bitmap (__u32 nr_desc,struct efi_boot_memmap *map) { -efi_guid_t unaccepted_table_guid =LINUX_EFI_UNACCEPTED_MEM_TABLE_GUID ; +static efi_guid_t unaccepted_table_guid =LINUX_EFI_UNACCEPTED_MEM_TABLE_GUID ;u64 unaccepted_start =ULLONG_MAX , unaccepted_end =0 , bitmap_size;efi_status_t status;int i;
drivers/firmware/efi/libstub/x86-stub.c +5 -5
@@ -118,9 +118,9 @@ preserve_pci_rom_image(efi_pci_io_protocol_t *pci, struct pci_setup_rom **__rom)*/ static void setup_efi_pci (struct boot_params *params) { +static efi_guid_t pci_proto =EFI_PCI_IO_PROTOCOL_GUID ;efi_status_t status; efi_handle_t *pci_handle __free(efi_pool) = NULL; -efi_guid_t pci_proto =EFI_PCI_IO_PROTOCOL_GUID ;struct setup_data *data;unsigned long num;efi_handle_t h;
@@ -159,7 +159,7 @@ static void setup_efi_pci(struct boot_params *params)static void retrieve_apple_device_properties (struct boot_params *boot_params) { -efi_guid_t guid =APPLE_PROPERTIES_PROTOCOL_GUID ; +static efi_guid_t guid =APPLE_PROPERTIES_PROTOCOL_GUID ;struct setup_data *data, *new;efi_status_t status;u32 size =0 ;
@@ -347,7 +347,7 @@ efi_status_t efi_adjust_memory_range_protection(unsigned long start,static void setup_unaccepted_memory (void ) { -efi_guid_t mem_acceptance_proto =OVMF_SEV_MEMORY_ACCEPTANCE_PROTOCOL_GUID ; +static efi_guid_t mem_acceptance_proto =OVMF_SEV_MEMORY_ACCEPTANCE_PROTOCOL_GUID ;sev_memory_acceptance_protocol_t *proto;efi_status_t status;
@@ -409,7 +409,7 @@ static void __noreturn efi_exit(efi_handle_t handle, efi_status_t status)static efi_status_t efi_allocate_bootparams (efi_handle_t handle,struct boot_params **bp) { -efi_guid_t proto =LOADED_IMAGE_PROTOCOL_GUID ; +static efi_guid_t proto =LOADED_IMAGE_PROTOCOL_GUID ;struct boot_params *boot_params;struct setup_header *hdr;int options_size =0 ;
@@ -815,7 +815,7 @@ void __noreturn efi_stub_entry(efi_handle_t handle, struct boot_params *boot_params) { -efi_guid_t guid =EFI_MEMORY_ATTRIBUTE_PROTOCOL_GUID ; +static efi_guid_t guid =EFI_MEMORY_ATTRIBUTE_PROTOCOL_GUID ;const struct linux_efi_initrd *initrd =NULL ;unsigned long kernel_entry;struct setup_header *hdr;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 921/1756 efi/libstub: Free cmdline_ptr in efi_pe_entry
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jason Gunthorpe <[email protected]>
[ Upstream commit 8ea857a2bb547e388e86ca42c58a97e162e09f83 ]
Sashiko points out that efi_handle_cmdline() allocates this memory and hands it over to the caller. If efi_pe_entry() ever returns it should be freed. Add a __free annotation.
--- drivers/firmware/efi/libstub/efi-stub-entry.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/efi/libstub/efi-stub-entry.c +1 -1
@@ -36,7 +36,6 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,unsigned long image_addr;unsigned long image_size =0 ;/* addr/point and size pairs for memory management*/ -char *cmdline_ptr =NULL ;unsigned long reserve_addr =0 ;unsigned long reserve_size =0 ;
@@ -58,6 +57,7 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,return status; } + char *cmdline_ptr __free(efi_pool) = NULL; status =efi_handle_cmdline (image, &cmdline_ptr);if (status !=EFI_SUCCESS )return status;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 922/1756 dt-bindings: dma: dma40: Restore disabled-channels
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Walleij <[email protected]>
[ Upstream commit 38d97b1122e02f6b8859e660990aaeda1c32e00f ]
The conversion of the DMA40 binding to YAML omitted the optional disabled-channels property from the original text binding. The driver still parses this property, but additionalProperties: false rejects any device tree using it.
Restore disabled-channels and constrain it to the physical channel range. Also constrain memcpy-channels to the limits enforced by the driver and reject duplicate channel entries in both properties.
--- .../devicetree/bindings/dma/stericsson,dma40.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
Documentation/devicetree/bindings/dma/stericsson,dma40.yaml +14 -0
@@ -145,8 +145,22 @@ properties: items: maxItems: 1 + disabled-channels: + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 1 + maxItems: 31 + uniqueItems: true + items: + maximum: 31 + description: Physical channels that cannot be used by the DMA engine. + memcpy-channels: $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 1 + maxItems: 8 + uniqueItems: true + items: + maximum: 63 description: Array of u32 elements indicating which channels on the DMA engine are eligible for memcpy transfers
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 923/1756 spi: spi-sun4i: sun4i_spi_transfer_one(): fix transfers for SUN4I_FIFO_DEPTH
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Kleine-Budde <[email protected]>
[ Upstream commit f3ce7a3ca82bd9cda9ef61250aeff65fe6b44809 ]
In commit 6d9fe44bd73d ("spi: sun4i: fix FIFO limit"), the TX-FIFO is filled max to SUN4I_FIFO_DEPTH - 1 (= 63) bytes to work around timeouts observed on A10s SoCs.
Commit 196737912da5 ("spi: sun4i: Allow transfers larger than FIFO size") added support for transfers larger than the FIFO size. But this commit only enabled the TX-FIFO empty interrupt for transfers larger than the FIFO (= 64) bytes.
This breaks transfers with exactly 64 bytes: the TX-FIFO is only filled with 63 bytes but the interrupt to refill the FIFO is not triggered. The problem can be reproduced with the following command:
| spidev_test -D /dev/spidev0.1 -S 64 -s 20000000 -I 1 | | [ 7797.548745] spi_master spi0: spi0.1: timeout transferring 64 bytes@20000000Hz for 110(100)ms | [ 7797.557237] spidev spi0.1: SPI transfer failed: -110 | [ 7797.562308] spi_master spi0: failed to transfer one message from queue | [ 7797.568936] spi_master spi0: noqueue transfer failed
To fix the problem enable the TX-FIFO interrupt if the total TX length is larger than SUN4I_FIFO_DEPTH - 1 (= 63) bytes.
--- drivers/spi/spi-sun4i.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/spi-sun4i.c +1 -1
@@ -322,7 +322,7 @@ static int sun4i_spi_transfer_one(struct spi_controller *host,sun4i_spi_enable_interrupt (sspi,SUN4I_INT_CTL_TC |SUN4I_INT_CTL_RF_F34 );/* Only enable Tx FIFO interrupt if we really need it */ -if (tx_len >SUN4I_FIFO_DEPTH ) +if (tx_len >SUN4I_FIFO_DEPTH -1 )sun4i_spi_enable_interrupt (sspi,SUN4I_INT_CTL_TF_E34 );/* Start the transfer */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 924/1756 spi: spi-sun4i: sun4i_spi_fill_fifo(): always apply A10 FIFO fill level workaround
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Kleine-Budde <[email protected]>
[ Upstream commit ee109e2bbea0986f6ad34bfbcba90fce36f17538 ]
In commit 6d9fe44bd73d ("spi: sun4i: fix FIFO limit"), the TX FIFO is filled max to SUN4I_FIFO_DEPTH - 1 (= 63) bytes to work around timeouts observed on A10s SoCs.
Commit 196737912da5 ("spi: sun4i: Allow transfers larger than FIFO size") added support for transfers larger than the FIFO size. This commit did not consider the A10 workaround (limit the TX FIFO fill size to SUN4I_FIFO_DEPTH - 1 (= 63) bytes) for refilling the TX FIFO in the IRQ handler.
To apply the workaround independent from where sun4i_spi_fill_fifo() is called, remove the length argument from the function and directly take the max fill level of SUN4I_FIFO_DEPTH - 1 into account when calculating the free space in the FIFO.
Due to the lack of HW this patch has not been tested on an A10 SoC, but on an A20 SoC. It was not possible to reproduce the timeout on the A20.
--- drivers/spi/spi-sun4i.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-)
drivers/spi/spi-sun4i.c +13 -11
@@ -142,15 +142,21 @@ static inline void sun4i_spi_drain_fifo(struct sun4i_spi *sspi, int len) } } -static inline void sun4i_spi_fill_fifo (struct sun4i_spi *sspi,int len) +static inline void sun4i_spi_fill_fifo (struct sun4i_spi *sspi) {u32 cnt; +int len;u8 byte; -/* See how much data we can fit */ - cnt =SUN4I_FIFO_DEPTH -sun4i_spi_get_tx_fifo_count (sspi); +/* +* See how much data we can fit +* +* Filling the FIFO fully causes timeout for some reason +* at least on spi2 on A10s +*/ + cnt =SUN4I_FIFO_DEPTH -1 -sun4i_spi_get_tx_fifo_count (sspi); - len =min3 (len, (int )cnt, sspi->len); + len =min_t (int, cnt, sspi->len);while (len--) { byte = sspi->tx_buf ? *sspi->tx_buf++ :0 ;
@@ -311,12 +317,8 @@ static int sun4i_spi_transfer_one(struct spi_controller *host,sun4i_spi_write (sspi,SUN4I_BURST_CNT_REG ,SUN4I_BURST_CNT (tfr->len));sun4i_spi_write (sspi,SUN4I_XMIT_CNT_REG ,SUN4I_XMIT_CNT (tx_len)); -/* -* Fill the TX FIFO -* Filling the FIFO fully causes timeout for some reason -* at least on spi2 on A10s -*/ -sun4i_spi_fill_fifo (sspi,SUN4I_FIFO_DEPTH -1 ); +/* Fill the TX FIFO */ +sun4i_spi_fill_fifo (sspi);/* Enable the interrupts */ sun4i_spi_enable_interrupt(sspi, SUN4I_INT_CTL_TC |
@@ -373,7 +375,7 @@ static irqreturn_t sun4i_spi_handler(int irq, void *dev_id)/* Transmit FIFO 3/4 empty */ if (status &SUN4I_INT_CTL_TF_E34 ) { -sun4i_spi_fill_fifo (sspi,SUN4I_FIFO_DEPTH ); +sun4i_spi_fill_fifo (sspi);if (!sspi->len)/* nothing left to transmit */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 925/1756 spi: spi-sun4i: sun4i_spi_transfer_one(): fix setting of clock rate
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Kleine-Budde <[email protected]>
[ Upstream commit 672ba6d88324f223634dd2dc4098f6fb6b346b25 ]
A SPI transfer defines the _maximum_ speed of the SPI transfer. However the driver doesn't take into account that the clock divider is always rounded down (due to integer arithmetic). This results in a too high clock rate for the SPI transfer.
E.g.: with an mclk_rate of 24 MHz and an SPI transfer speed of 10 MHz, the original code calculates a reg of "0", which results in an effective divider of "2" and a 12 MHz clock for the SPI transfer.
Use DIV_ROUND_UP() instead of a plain integer division to fix the problem.
While there simplify the divider calculation for the CDR1 case, use order_base_2() instead of two ilog2() calculations.
--- drivers/spi/spi-sun4i.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
drivers/spi/spi-sun4i.c +7 -9
@@ -212,7 +212,7 @@ static int sun4i_spi_transfer_one(struct spi_controller *host, struct spi_transfer *tfr) {struct sun4i_spi *sspi =spi_controller_get_devdata (host); -unsigned int mclk_rate, div; +unsigned int mclk_rate, div, div_cdr1, div_cdr2;unsigned long time_left;unsigned int start, end, tx_time;unsigned int tx_len =0 ;
@@ -296,15 +296,13 @@ static int sun4i_spi_transfer_one(struct spi_controller *host,* First try CDR2, and if we can't reach the expected * frequency, fall back to CDR1. */ - div = mclk_rate / (2 * tfr->speed_hz); -if (div <= (SUN4I_CLK_CTL_CDR2_MASK +1 )) { -if (div >0 ) - div--; - - reg =SUN4I_CLK_CTL_CDR2 (div) |SUN4I_CLK_CTL_DRS ; + div_cdr1 =DIV_ROUND_UP (mclk_rate, tfr->speed_hz); + div_cdr2 =DIV_ROUND_UP (div_cdr1,2 ); +if (div_cdr2 <= (SUN4I_CLK_CTL_CDR2_MASK +1 )) { + reg =SUN4I_CLK_CTL_CDR2 (div_cdr2 -1 ) |SUN4I_CLK_CTL_DRS ; }else { - div =ilog2 (mclk_rate) -ilog2 (tfr->speed_hz); - reg =SUN4I_CLK_CTL_CDR1 (div); + div =min (SUN4I_CLK_CTL_CDR1_MASK +1 ,order_base_2 (div_cdr1)); + reg =SUN4I_CLK_CTL_CDR1 (div -1 ); }sun4i_spi_write (sspi,SUN4I_CLK_CTL_REG , reg);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 926/1756 spi: spi-sun4i: sun4i_spi_handler(): fix race condition between transfer completion and RX FIFO interrupt
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Kleine-Budde <[email protected]>
[ Upstream commit b8f09251da7871fbb9c62bd83516af422641d816 ]
In commit 196737912da5 ("spi: sun4i: Allow transfers larger than FIFO size"), support for transfers larger than the FIFO size was added.
This commit moves the draining of the RX-FIFO from sun4i_spi_transfer_one() (after completion of the transfer) to the IRQ handler when the IRQ "transfer complete" is handled. In addition, the IRQ "RX-FIFO 3/4 full" is activated for all transfers.
However, this does not take into account that the RX-IRQ for transfers that exceed 3/4 of the FIFO size is still pending after the IRQ "transfer complete" has been processed. All interrupt sources are only deactivated after the wait_for_completion_timeout() in sun4i_spi_transfer_one().
This opens a race window for "RX-FIFO 3/4 full" interrupts to come. The sequence is as follows:
| sun4i_spi_transfer_one() | sun4i_spi_fill_fifo() // fill TX-FIFO with 48 bytes | // enable RX-FIFO 3/4 full IRQ | wait_for_completion_timeout(); | | // SPI controller transfers 48 bytes | // SPI controller issues "transfer complete" and "RX-FIFO 3/4 full" IRQ | | // IRQ handler start | sun4i_spi_handler() | // ACK "transfer complete" IRQ | sun4i_spi_drain_fifo(); | complete(); ----. | return IRQ_HANDLED; \ | // IRQ handler end \__ race | / window | // wait_for_completion_timeout() continues / | // disable all IRQ sources ----'
Avoid the race condition by disabling all interrupts when handling the "transfer complete" IRQ and before calling complete(). Also move the draining of the RX-FIFO back into sun4i_spi_transfer_one() where it was before commit 196737912da5 ("spi: sun4i: Allow transfers larger than FIFO size").
This has the added benefit of spending a little less time in the IRQ handler.
With all interrupts disabled once the transfer completed, omit the clearing of the Transfer Complete bit in sun4i_spi_handler. This is safe because sun4i_spi_transfer_one() takes care of this before enabling any interrupts again.
--- drivers/spi/spi-sun4i.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/spi/spi-sun4i.c +8 -6
@@ -82,6 +82,8 @@ struct sun4i_spi {struct completion done; +int irq; +const u8 *tx_buf;u8 *rx_buf;int len;
@@ -333,6 +335,7 @@ static int sun4i_spi_transfer_one(struct spi_controller *host, start = jiffies; time_left =wait_for_completion_timeout (&sspi->done,msecs_to_jiffies (tx_time)); + end = jiffies;if (!time_left) { dev_warn(&host->dev,
@@ -340,12 +343,11 @@ static int sun4i_spi_transfer_one(struct spi_controller *host,dev_name (&spi->dev), tfr->len, tfr->speed_hz, jiffies_to_msecs(end - start), tx_time); ret = -ETIMEDOUT ; - goto out; +sun4i_spi_write (sspi,SUN4I_INT_CTL_REG ,0 ); +synchronize_irq (sspi->irq); } - -out: -sun4i_spi_write (sspi,SUN4I_INT_CTL_REG ,0 ); +sun4i_spi_drain_fifo (sspi,SUN4I_FIFO_DEPTH );return ret; }
@@ -357,8 +359,7 @@ static irqreturn_t sun4i_spi_handler(int irq, void *dev_id)/* Transfer complete */ if (status &SUN4I_INT_CTL_TC ) { -sun4i_spi_write (sspi,SUN4I_INT_STA_REG ,SUN4I_INT_CTL_TC ); -sun4i_spi_drain_fifo (sspi,SUN4I_FIFO_DEPTH ); +sun4i_spi_write (sspi,SUN4I_INT_CTL_REG ,0 );complete (&sspi->done);return IRQ_HANDLED ; }
@@ -462,6 +463,7 @@ static int sun4i_spi_probe(struct platform_device *pdev) goto err_free_host; } + sspi->irq = irq; sspi->host = host; host->max_speed_hz =100 *1000 *1000 ; host->min_speed_hz =3 *1000 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 927/1756 NFS: return DENIED in decode_lock_denied if we cannot decode owner
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Roberto Bergantinos Corpas <[email protected]>
[ Upstream commit 4fdfe2312cbed99b1438dcf20b348e72393f9633 ]
After commit 43502f6e8d1e ("NFS: fix open_owner_id_maxsz and related fields.") we dramatically changed the size of the LOCK/LOCKT reply buffer from 164 to 52 bytes. This made visible a situation on a buggy NFS server that sent oversized denied responses which led to us returning EIO instead of DENIED.
Now, apart from buggy server issue, this poses an interesting question:
what if other implementations have legitimate but bigger than we expect lock owner response, especially now that we have reduced the size we allocate for it (20 bytes for the lock owner part).
This change proposes to tackle that issue returning DENIED instead of EIO regardless of whether we manage to decode the owner or not:
- At this point of decode_lock_denied we know there is an owner.
- Server legitimately denied the lock request, with an owner that fits on NFS4_OPAQUE_LIMIT but we returned EIO instead to userspace.
- The owner data is decoded but actually never used, decode_lock path simply retries, and decode_lockt turns it into 0 on file_lock and returns it to userspace.
- LOCK/LOCKT are the last operations on the compound so it's not relevant if we didn't advance the pointer.
- Also removes an inverted likely(!p) hint.
--- fs/nfs/nfs4xdr.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/nfs/nfs4xdr.c +1 -2
@@ -5102,8 +5102,7 @@ static int decode_lock_denied(struct xdr_stream *xdr, struct file_lock *fl) p =xdr_decode_hyper (p, &clientid);/* read 8 bytes */ namelen =be32_to_cpup (p);/* read 4 bytes */ /* have read all 32 bytes now */ p =xdr_inline_decode (xdr, namelen);/* variable size field */ -if (likely (!p)) -return -EIO ; +/* We have an owner here, return DENIED */ return -NFS4ERR_DENIED ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 928/1756 nilfs2: fix link count underflow when removing corrupted directory
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ryusuke Konishi <[email protected]>
[ Upstream commit 814f5a53b4724798795b15690ff3d1c1d9ac1eb6 ]
When removing an empty directory with a corrupted link count (e.g., i_nlink is 1 due to filesystem corruption), nilfs_rmdir() calls drop_nlink() via nilfs_do_unlink() and then calls drop_nlink() again on the directory inode. This second call causes an underflow of i_nlink, triggering a kernel WARNING in drop_nlink().
Fix this issue by using clear_nlink() instead of drop_nlink() to finalize the link count reset for the target directory in nilfs_rmdir(). Additionally, log a warning message when i_nlink is not 2 before removing an empty directory to notify about the link count inconsistency.
--- fs/nilfs2/namei.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
fs/nilfs2/namei.c +7 -1
@@ -341,10 +341,16 @@ static int nilfs_rmdir(struct inode *dir, struct dentry *dentry) err = -ENOTEMPTY ;if (nilfs_empty_dir (inode)) { +if (unlikely (inode->i_nlink !=2 )) +nilfs_warn (dir->i_sb, +"inconsistent empty directory link count %u (ino=%llu)" , + inode->i_nlink, + (unsigned long long )inode->i_ino); + err =nilfs_do_unlink (dir, dentry);if (!err) { inode->i_size =0 ; -drop_nlink (inode); +clear_nlink (inode);nilfs_mark_inode_dirty (inode);drop_nlink (dir);nilfs_mark_inode_dirty (dir);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 929/1756 selftests: cgroup: Optionally set up v1 environment
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michal Koutný <[email protected]>
[ Upstream commit d74cd7864ffa6913f1d70f80858bd3fd19101cdf ]
Use the missing mount of the unifier hierarchy as a hint of legacy system and prepare our own named v1 hierarchy for tests.
The code is only in test_core.c and not cgroup_util.c because other selftests are related to controllers which will be exposed on v2 hierarchy but named hierarchies are only v1 thing.
Stable-dep-of: 0567c7eaefd7 ("selftests/cgroup: test_zswap: fix implicit unsigned promotion bug in test_no_kmem_bypass")
--- tools/testing/selftests/cgroup/test_core.c | 44 +++++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-)
tools/testing/selftests/cgroup/test_core.c +42 -2
@@ -5,6 +5,8 @@#include <linux/sched.h> #include <sys/types.h> #include <sys/mman.h> +#include <sys/mount.h> +#include <sys/stat.h> #include <sys/wait.h> #include <unistd.h> #include <fcntl.h>
@@ -842,6 +844,38 @@ static int test_cgcore_lesser_ns_open(const char *root)return ret; } +static int setup_named_v1_root (char *root,size_t len,const char *name) +{ +char options[PATH_MAX ]; +int r; + + r =snprintf (root, len,"/mnt/cg_selftest" ); +if (r <0 ) +return r; + + r =snprintf (options,sizeof (options),"none,name=%s" , name); +if (r <0 ) +return r; + + r =mkdir (root,0755 ); +if (r <0 && errno !=EEXIST ) +return r; + + r =mount ("none" , root,"cgroup" ,0 , options); +if (r <0 ) +return r; + +return 0 ; +} + +static void cleanup_named_v1_root (char *root) +{ +if (!cg_test_v1_named) +return ; +umount (root); +rmdir (root); +} +#define T (x) { x, #x }struct corecg_test {int (*fn)(const char *root);
@@ -867,13 +901,18 @@ int main(int argc, char *argv[])char root[PATH_MAX ];int i, ret =EXIT_SUCCESS ; -if (cg_find_unified_root (root,sizeof (root), &nsdelegate)) -ksft_exit_skip ("cgroup v2 isn't mounted\n" ); +if (cg_find_unified_root (root,sizeof (root), &nsdelegate)) { +if (setup_named_v1_root (root,sizeof (root),CG_NAMED_NAME )) +ksft_exit_skip ("cgroup v2 isn't mounted and could not setup named v1 hierarchy\n" ); + cg_test_v1_named = true; + goto post_v2_setup; + }if (cg_read_strstr (root,"cgroup.subtree_control" ,"memory" ))if (cg_write (root,"cgroup.subtree_control" ,"+memory" ))ksft_exit_skip ("Failed to set memory controller\n" ); +post_v2_setup:for (i =0 ; i <ARRAY_SIZE (tests); i++) {switch (tests[i].fn (root)) {case KSFT_PASS :
@@ -889,5 +928,6 @@ int main(int argc, char *argv[]) } } +cleanup_named_v1_root (root);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 930/1756 selftests/cgroup: conform test to KTAP format output
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guopeng Zhang <[email protected]>
[ Upstream commit 1dc830ee4c155bff572a43a66b948e1c46483d6a ]
Conform the layout, informational and status messages to KTAP. No functional change is intended other than the layout of output messages.
Stable-dep-of: 0567c7eaefd7 ("selftests/cgroup: test_zswap: fix implicit unsigned promotion bug in test_no_kmem_bypass")
--- tools/testing/selftests/cgroup/test_core.c | 7 ++++--- tools/testing/selftests/cgroup/test_cpu.c | 7 ++++--- tools/testing/selftests/cgroup/test_cpuset.c | 7 ++++--- tools/testing/selftests/cgroup/test_freezer.c | 7 ++++--- tools/testing/selftests/cgroup/test_kill.c | 7 ++++--- tools/testing/selftests/cgroup/test_kmem.c | 7 ++++--- tools/testing/selftests/cgroup/test_memcontrol.c | 7 ++++--- tools/testing/selftests/cgroup/test_zswap.c | 7 ++++--- 8 files changed, 32 insertions(+), 24 deletions(-)
tools/testing/selftests/cgroup/test_core.c +4 -3
@@ -899,8 +899,10 @@ struct corecg_test {int main (int argc,char *argv[]) {char root[PATH_MAX ]; -int i, ret =EXIT_SUCCESS ; +int i; +ksft_print_header (); +ksft_set_plan (ARRAY_SIZE (tests));if (cg_find_unified_root (root,sizeof (root), &nsdelegate)) {if (setup_named_v1_root (root,sizeof (root),CG_NAMED_NAME ))ksft_exit_skip ("cgroup v2 isn't mounted and could not setup named v1 hierarchy\n" );
@@ -922,12 +924,11 @@ int main(int argc, char *argv[])ksft_test_result_skip ("%s\n" , tests[i].name);break ;default : - ret =EXIT_FAILURE ;ksft_test_result_fail ("%s\n" , tests[i].name);break ; } }cleanup_named_v1_root (root); -return ret; +ksft_finished (); }
tools/testing/selftests/cgroup/test_cpu.c +4 -3
@@ -698,8 +698,10 @@ struct cpucg_test {int main (int argc,char *argv[]) {char root[PATH_MAX ]; -int i, ret =EXIT_SUCCESS ; +int i; +ksft_print_header (); +ksft_set_plan (ARRAY_SIZE (tests));if (cg_find_unified_root (root,sizeof (root),NULL ))ksft_exit_skip ("cgroup v2 isn't mounted\n" );
@@ -716,11 +718,10 @@ int main(int argc, char *argv[])ksft_test_result_skip ("%s\n" , tests[i].name);break ;default : - ret =EXIT_FAILURE ;ksft_test_result_fail ("%s\n" , tests[i].name);break ; } } -return ret; +ksft_finished (); }
tools/testing/selftests/cgroup/test_cpuset.c +4 -3
@@ -247,8 +247,10 @@ struct cpuset_test {int main (int argc,char *argv[]) {char root[PATH_MAX ]; -int i, ret =EXIT_SUCCESS ; +int i; +ksft_print_header (); +ksft_set_plan (ARRAY_SIZE (tests));if (cg_find_unified_root (root,sizeof (root),NULL ))ksft_exit_skip ("cgroup v2 isn't mounted\n" );
@@ -265,11 +267,10 @@ int main(int argc, char *argv[])ksft_test_result_skip ("%s\n" , tests[i].name);break ;default : - ret =EXIT_FAILURE ;ksft_test_result_fail ("%s\n" , tests[i].name);break ; } } -return ret; +ksft_finished (); }
tools/testing/selftests/cgroup/test_freezer.c +4 -3
@@ -825,8 +825,10 @@ struct cgfreezer_test {int main (int argc,char *argv[]) {char root[PATH_MAX ]; -int i, ret =EXIT_SUCCESS ; +int i; +ksft_print_header (); +ksft_set_plan (ARRAY_SIZE (tests));if (cg_find_unified_root (root,sizeof (root),NULL ))ksft_exit_skip ("cgroup v2 isn't mounted\n" );for (i =0 ; i <ARRAY_SIZE (tests); i++) {
@@ -838,11 +840,10 @@ int main(int argc, char *argv[])ksft_test_result_skip ("%s\n" , tests[i].name);break ;default : - ret =EXIT_FAILURE ;ksft_test_result_fail ("%s\n" , tests[i].name);break ; } } -return ret; +ksft_finished (); }
tools/testing/selftests/cgroup/test_kill.c +4 -3
@@ -274,8 +274,10 @@ struct cgkill_test {int main (int argc,char *argv[]) {char root[PATH_MAX ]; -int i, ret =EXIT_SUCCESS ; +int i; +ksft_print_header (); +ksft_set_plan (ARRAY_SIZE (tests));if (cg_find_unified_root (root,sizeof (root),NULL ))ksft_exit_skip ("cgroup v2 isn't mounted\n" );for (i =0 ; i <ARRAY_SIZE (tests); i++) {
@@ -287,11 +289,10 @@ int main(int argc, char *argv[])ksft_test_result_skip ("%s\n" , tests[i].name);break ;default : - ret =EXIT_FAILURE ;ksft_test_result_fail ("%s\n" , tests[i].name);break ; } } -return ret; +ksft_finished (); }
tools/testing/selftests/cgroup/test_kmem.c +4 -3
@@ -418,8 +418,10 @@ struct kmem_test {int main (int argc,char **argv) {char root[PATH_MAX ]; -int i, ret =EXIT_SUCCESS ; +int i; +ksft_print_header (); +ksft_set_plan (ARRAY_SIZE (tests));if (cg_find_unified_root (root,sizeof (root),NULL ))ksft_exit_skip ("cgroup v2 isn't mounted\n" );
@@ -443,11 +445,10 @@ int main(int argc, char **argv)ksft_test_result_skip ("%s\n" , tests[i].name);break ;default : - ret =EXIT_FAILURE ;ksft_test_result_fail ("%s\n" , tests[i].name);break ; } } -return ret; +ksft_finished (); }
tools/testing/selftests/cgroup/test_memcontrol.c +4 -3
@@ -1649,8 +1649,10 @@ struct memcg_test {int main (int argc,char **argv) {char root[PATH_MAX ]; -int i, proc_status, ret =EXIT_SUCCESS ; +int i, proc_status; +ksft_print_header (); +ksft_set_plan (ARRAY_SIZE (tests));if (cg_find_unified_root (root,sizeof (root),NULL ))ksft_exit_skip ("cgroup v2 isn't mounted\n" );
@@ -1684,11 +1686,10 @@ int main(int argc, char **argv)ksft_test_result_skip ("%s\n" , tests[i].name);break ;default : - ret =EXIT_FAILURE ;ksft_test_result_fail ("%s\n" , tests[i].name);break ; } } -return ret; +ksft_finished (); }
tools/testing/selftests/cgroup/test_zswap.c +4 -3
@@ -597,8 +597,10 @@ static bool zswap_configured(void)int main (int argc,char **argv) {char root[PATH_MAX ]; -int i, ret =EXIT_SUCCESS ; +int i; +ksft_print_header (); +ksft_set_plan (ARRAY_SIZE (tests));if (cg_find_unified_root (root,sizeof (root),NULL ))ksft_exit_skip ("cgroup v2 isn't mounted\n" );
@@ -625,11 +627,10 @@ int main(int argc, char **argv)ksft_test_result_skip ("%s\n" , tests[i].name);break ;default : - ret =EXIT_FAILURE ;ksft_test_result_fail ("%s\n" , tests[i].name);break ; } } -return ret; +ksft_finished (); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 931/1756 selftests/cgroup: add test for zswap incompressible pages
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiayuan Chen <[email protected]>
[ Upstream commit 4e89004eebc559595e58d75fd7f7f8ecd5aa600d ]
Add test_zswap_incompressible() to verify that the zswap_incomp memcg stat correctly tracks incompressible pages.
The test allocates memory filled with random data from /dev/urandom, which cannot be effectively compressed by zswap. When this data is swapped out to zswap, it should be stored as-is and tracked by the zswap_incomp counter.
The test verifies that:
1. Pages are swapped out to zswap (zswpout increases)
2. Incompressible pages are tracked (zswap_incomp increases)
test:
dd if=/dev/zero of=/swapfile bs=1M count=2048
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo Y > /sys/module/zswap/parameters/enabled
./test_zswap
TAP version 13
1..8
ok 1 test_zswap_usage
ok 2 test_swapin_nozswap
ok 3 test_zswapin
ok 4 test_zswap_writeback_enabled
ok 5 test_zswap_writeback_disabled
ok 6 test_no_kmem_bypass
ok 7 test_no_invasive_cgroup_shrink
ok 8 test_zswap_incompressible
Totals: pass:8 fail:0 xfail:0 xpass:0 skip:0 error:0
Stable-dep-of: 0567c7eaefd7 ("selftests/cgroup: test_zswap: fix implicit unsigned promotion bug in test_no_kmem_bypass")
--- tools/testing/selftests/cgroup/test_zswap.c | 136 ++++++++++++++++++++ 1 file changed, 136 insertions(+)
tools/testing/selftests/cgroup/test_zswap.c +136 -0
@@ -5,6 +5,8 @@#include <unistd.h> #include <stdio.h> #include <signal.h> +#include <errno.h> +#include <fcntl.h> #include <sys/sysinfo.h> #include <string.h> #include <sys/wait.h>
@@ -574,6 +576,139 @@ static int test_no_kmem_bypass(const char *root)return ret; } +struct incomp_child_args { +size_t size; +int pipefd[2 ]; +int madvise_ret; +int madvise_errno; +}; + +static int allocate_random_and_wait (const char *cgroup,void *arg) +{ +struct incomp_child_args *values = arg; +size_t size = values->size; +char *mem; +int fd; +ssize_t n; + +close (values->pipefd[0 ]); + + mem =mmap (NULL , size,PROT_READ |PROT_WRITE , +MAP_PRIVATE |MAP_ANONYMOUS ,-1 ,0 ); +if (mem ==MAP_FAILED ) +return -1 ; + +/* Fill with random data from /dev/urandom - incompressible */ + fd =open ("/dev/urandom" ,O_RDONLY ); +if (fd <0 ) { +munmap (mem, size); +return -1 ; + } + +for (size_t i =0 ; i < size; ) { + n =read (fd, mem + i, size - i); +if (n <=0 ) +break ; + i += n; + } +close (fd); + +/* Touch all pages to ensure they're faulted in */ +for (size_t i =0 ; i < size; i +=PAGE_SIZE ) + mem[i] = mem[i]; + +/* Use MADV_PAGEOUT to push pages into zswap */ + values->madvise_ret =madvise (mem, size,MADV_PAGEOUT ); + values->madvise_errno = errno; + +/* Notify parent that allocation and pageout are done */ +write (values->pipefd[1 ],"x" ,1 ); +close (values->pipefd[1 ]); + +/* Keep memory alive for parent to check stats */ +pause (); +munmap (mem, size); +return 0 ; +} + +static long get_zswap_incomp (const char *cgroup) +{ +return cg_read_key_long (cgroup,"memory.stat" ,"zswap_incomp " ); +} + +/* +* Test that incompressible pages (random data) are tracked by zswap_incomp. +* +* The child process allocates random data within memory.max, then uses +* MADV_PAGEOUT to push pages into zswap. The parent waits on a pipe for +* the child to finish, then checks the zswap_incomp stat before the child +* exits (zswap_incomp is a gauge that decreases on free). +*/ +static int test_zswap_incompressible (const char *root) +{ +int ret =KSFT_FAIL ; +struct incomp_child_args *values; +char *test_group; +long zswap_incomp; +pid_t child_pid; +int child_status; +char buf; + + values =mmap (0 ,sizeof (struct incomp_child_args ),PROT_READ | +PROT_WRITE ,MAP_SHARED |MAP_ANONYMOUS ,-1 ,0 ); +if (values ==MAP_FAILED ) +return KSFT_FAIL ; + +if (pipe (values->pipefd)) { +munmap (values,sizeof (struct incomp_child_args )); +return KSFT_FAIL ; + } + + test_group =cg_name (root,"zswap_incompressible_test" ); +if (!test_group) + goto out; +if (cg_create (test_group)) + goto out; +if (cg_write (test_group,"memory.max" ,"32M" )) + goto out; + + values->size =MB (4 ); + child_pid =cg_run_nowait (test_group, allocate_random_and_wait, values); +if (child_pid <0 ) + goto out; + +close (values->pipefd[1 ]); + +/* Wait for child to finish allocating and pageout */ +read (values->pipefd[0 ], &buf,1 ); +close (values->pipefd[0 ]); + + zswap_incomp =get_zswap_incomp (test_group); +if (zswap_incomp <=0 ) { +long zswpout =get_zswpout (test_group); +long zswapped =cg_read_key_long (test_group,"memory.stat" ,"zswapped " ); +long zswap_b =cg_read_key_long (test_group,"memory.stat" ,"zswap " ); + +ksft_print_msg ("zswap_incomp not increased: %ld\n" , zswap_incomp); +ksft_print_msg ("debug: zswpout=%ld zswapped=%ld zswap_b=%ld\n" , + zswpout, zswapped, zswap_b); +ksft_print_msg ("debug: madvise ret=%d errno=%d\n" , + values->madvise_ret, values->madvise_errno); + goto out_kill; + } + + ret =KSFT_PASS ; + +out_kill: +kill (child_pid,SIGTERM ); +waitpid (child_pid, &child_status,0 ); +out: +cg_destroy (test_group); +free (test_group); +munmap (values,sizeof (struct incomp_child_args )); +return ret; +} +#define T (x) { x, #x }struct zswap_test {int (*fn)(const char *root);
@@ -586,6 +721,7 @@ struct zswap_test {T (test_zswap_writeback_disabled),T (test_no_kmem_bypass),T (test_no_invasive_cgroup_shrink), + T(test_zswap_incompressible), };#undef T
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 932/1756 selftests/cgroup: skip test_zswap if zswap is globally disabled
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li Wang <[email protected]>
[ Upstream commit 9f40c3cdf0fa3011c3a15f8acc0b9ffb3ed11171 ]
Patch series "selftests/cgroup: improve zswap tests robustness and support large page sizes", v7.
This patchset aims to fix various spurious failures and improve the overall robustness of the cgroup zswap selftests.
The primary motivation is to make the tests compatible with architectures that use non-4K page sizes (such as 64K on ppc64le and arm64). Currently, the tests rely heavily on hardcoded 4K page sizes and fixed memory limits. On 64K page size systems, these hardcoded values lead to sub-page granularity accesses, incorrect page count calculations, and insufficient memory pressure to trigger zswap writeback, ultimately causing the tests to fail.
Additionally, this series addresses OOM kills occurring in test_swapin_nozswap by dynamically scaling memory limits, and prevents spurious test failures when zswap is built into the kernel but globally disabled.
This patch (of 8):
test_zswap currently only checks whether zswap is present by testing /sys/module/zswap. This misses the runtime global state exposed in /sys/module/zswap/parameters/enabled.
When zswap is built/loaded but globally disabled, the zswap cgroup selftests run in an invalid environment and may fail spuriously.
Check the runtime enabled state before running the tests:
- skip if zswap is not configured,
- fail if the enabled knob cannot be read,
- skip if zswap is globally disabled.
Also print a hint in the skip message on how to enable zswap.
Stable-dep-of: 0567c7eaefd7 ("selftests/cgroup: test_zswap: fix implicit unsigned promotion bug in test_no_kmem_bypass")
--- tools/testing/selftests/cgroup/test_zswap.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
tools/testing/selftests/cgroup/test_zswap.c +15 -4
@@ -15,6 +15,9 @@#include "../kselftest.h" #include "cgroup_util.h" +#define PATH_ZSWAP "/sys/module/zswap" +#define PATH_ZSWAP_ENABLED "/sys/module/zswap/parameters/enabled" +static int read_int (const char *path,size_t *value) {FILE *file;
@@ -725,9 +728,18 @@ struct zswap_test { };#undef T -static bool zswap_configured (void ) +static void check_zswap_enabled (void ) { -return access ("/sys/module/zswap" ,F_OK ) ==0 ; +char value[2 ]; + +if (access (PATH_ZSWAP ,F_OK )) +ksft_exit_skip ("zswap isn't configured\n" ); + +if (read_text (PATH_ZSWAP_ENABLED , value,sizeof (value)) <=0 ) +ksft_exit_fail_msg ("Failed to read " PATH_ZSWAP_ENABLED "\n" ); + +if (value[0 ] =='N' ) +ksft_exit_skip ("zswap is disabled (hint: echo 1 > " PATH_ZSWAP_ENABLED ")\n" ); }int main (int argc,char **argv)
@@ -740,8 +752,7 @@ int main(int argc, char **argv)if (cg_find_unified_root (root,sizeof (root),NULL ))ksft_exit_skip ("cgroup v2 isn't mounted\n" ); -if (!zswap_configured ()) -ksft_exit_skip ("zswap isn't configured\n" ); +check_zswap_enabled ();/* * Check that memory controller is available:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 933/1756 selftests/cgroup: avoid OOM in test_swapin_nozswap
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li Wang <[email protected]>
[ Upstream commit 0d38cded3c6294b0dfa38e3fc92077b5d381951e ]
test_swapin_nozswap can hit OOM before reaching its assertions on some setups. The test currently sets memory.max=8M and then allocates/reads 32M with memory.zswap.max=0, which may over-constrain reclaim and kill the workload process.
Replace hardcoded sizes with PAGE_SIZE-based values:
- control_allocation_size = PAGE_SIZE * 512
- memory.max = control_allocation_size * 3 / 4
- minimum expected swap = control_allocation_size / 4
This keeps the test pressure model intact (allocate/read beyond memory.max to force swap-in/out) while making it more robust across different environments.
The test intent is unchanged: confirm that swapping occurs while zswap remains unused when memory.zswap.max=0.
=== Error Logs ===
# ./test_zswap TAP version 13 1..7 ok 1 test_zswap_usage not ok 2 test_swapin_nozswap ...
# dmesg [271641.879153] test_zswap invoked oom-killer: gfp_mask=0xcc0(GFP_KERNEL), order=0, oom_score_adj=0 [271641.879168] CPU: 1 UID: 0 PID: 177372 Comm: test_zswap Kdump: loaded Not tainted 6.12.0-211.el10.ppc64le #1 VOLUNTARY [271641.879171] Hardware name: IBM,9009-41A POWER9 (architected) 0x4e0202 0xf000005 of:IBM,FW940.02 (UL940_041) hv:phyp pSeries [271641.879173] Call Trace: [271641.879174] [c00000037540f730] [c00000000127ec44] dump_stack_lvl+0x88/0xc4 (unreliable) [271641.879184] [c00000037540f760] [c0000000005cc594] dump_header+0x5c/0x1e4 [271641.879188] [c00000037540f7e0] [c0000000005cb464] oom_kill_process+0x324/0x3b0 [271641.879192] [c00000037540f860] [c0000000005cbe48] out_of_memory+0x118/0x420 [271641.879196] [c00000037540f8f0] [c00000000070d8ec] mem_cgroup_out_of_memory+0x18c/0x1b0 [271641.879200] [c00000037540f990] [c000000000713888] try_charge_memcg+0x598/0x890 [271641.879204] [c00000037540fa70] [c000000000713dbc] charge_memcg+0x5c/0x110 [271641.879207] [c00000037540faa0] [c0000000007159f8] __mem_cgroup_charge+0x48/0x120 [271641.879211] [c00000037540fae0] [c000000000641914] alloc_anon_folio+0x2b4/0x5a0 [271641.879215] [c00000037540fb60] [c000000000641d58] do_anonymous_page+0x158/0x6b0 [271641.879218] [c00000037540fbd0] [c000000000642f8c] __handle_mm_fault+0x4bc/0x910 [271641.879221] [c00000037540fcf0] [c000000000643500] handle_mm_fault+0x120/0x3c0 [271641.879224] [c00000037540fd40] [c00000000014bba0] ___do_page_fault+0x1c0/0x980 [271641.879228] [c00000037540fdf0] [c00000000014c44c] hash__do_page_fault+0x2c/0xc0 [271641.879232] [c00000037540fe20] [c0000000001565d8] do_hash_fault+0x128/0x1d0 [271641.879236] [c00000037540fe50] [c000000000008be0] data_access_common_virt+0x210/0x220 [271641.879548] Tasks state (memory values in pages): ... [271641.879550] [ pid ] uid tgid total_vm rss rss_anon rss_file rss_shmem pgtables_bytes swapents oom_score_adj name [271641.879555] [ 177372] 0 177372 571 0 0 0 0 51200 96 0 test_zswap [271641.879562] oom-kill:constraint=CONSTRAINT_MEMCG,nodemask=(null),cpuset=/,mems_allowed=0,oom_memcg=/no_zswap_test,task_memcg=/no_zswap_test,task=test_zswap,pid=177372,uid=0 [271641.879578] Memory cgroup out of memory: Killed process 177372 (test_zswap) total-vm:36544kB, anon-rss:0kB, file-rss:0kB, shmem-rss:0kB, UID:0 pgtables:50kB oom_score_adj:0
Stable-dep-of: 0567c7eaefd7 ("selftests/cgroup: test_zswap: fix implicit unsigned promotion bug in test_no_kmem_bypass")
--- tools/testing/selftests/cgroup/test_zswap.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
tools/testing/selftests/cgroup/test_zswap.c +11 -6
@@ -165,21 +165,25 @@ static int test_zswap_usage(const char *root)static int test_swapin_nozswap (const char *root) {int ret =KSFT_FAIL ; -char *test_group; -long swap_peak, zswpout; +char *test_group, mem_max_buf[32 ]; +long swap_peak, zswpout, min_swap; +size_t allocation_size =sysconf (_SC_PAGESIZE) *512 ; + + min_swap = allocation_size /4 ; +snprintf (mem_max_buf,sizeof (mem_max_buf),"%zu" , allocation_size *3 /4 ); test_group =cg_name (root,"no_zswap_test" );if (!test_group) goto out;if (cg_create (test_group)) goto out; -if (cg_write (test_group,"memory.max" ,"8M" )) +if (cg_write (test_group,"memory.max" , mem_max_buf)) goto out;if (cg_write (test_group,"memory.zswap.max" ,"0" )) goto out;/* Allocate and read more than memory.max to trigger swapin */ -if (cg_run (test_group, allocate_and_read_bytes, (void *)MB (32 ))) +if (cg_run (test_group, allocate_and_read_bytes, (void *)allocation_size)) goto out;/* Verify that pages are swapped out, but no zswap happened */
@@ -189,8 +193,9 @@ static int test_swapin_nozswap(const char *root) goto out; } -if (swap_peak <MB (24 )) { -ksft_print_msg ("at least 24MB of memory should be swapped out\n" ); +if (swap_peak < min_swap) { +ksft_print_msg ("at least %ldKB of memory should be swapped out\n" , + min_swap /1024 ); goto out; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 934/1756 selftests/cgroup: use runtime page size for zswpin check
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li Wang <[email protected]>
[ Upstream commit b19ee588e159c71f0d314246a944dcfc3e2a6009 ]
test_zswapin compares memory.stat:zswpin (counted in pages) against a byte threshold converted with PAGE_SIZE. In cgroup selftests, PAGE_SIZE is hardcoded to 4096, which makes the conversion wrong on systems with non-4K base pages (e.g. 64K).
As a result, the test requires too many pages to pass and fails spuriously even when zswap is working.
Use sysconf(_SC_PAGESIZE) for the zswpin threshold conversion so the check matches the actual system page size.
Stable-dep-of: 0567c7eaefd7 ("selftests/cgroup: test_zswap: fix implicit unsigned promotion bug in test_no_kmem_bypass")
--- tools/testing/selftests/cgroup/test_zswap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/cgroup/test_zswap.c +1 -1
@@ -245,7 +245,7 @@ static int test_zswapin(const char *root) goto out; } -if (zswpin <MB (24 ) /PAGE_SIZE ) { +if (zswpin <MB (24 ) /sysconf (_SC_PAGESIZE)) {ksft_print_msg ("at least 24MB should be brought back from zswap\n" ); goto out; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 935/1756 selftests/cgroup: replace hardcoded page size values in test_zswap
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li Wang <[email protected]>
[ Upstream commit 43743cc516684e40faf15afbb123eccd3d90e244 ]
test_zswap uses hardcoded values of 4095 and 4096 throughout as page stride and page size, which are only correct on systems with a 4K page size. On architectures with larger pages (e.g., 64K on arm64 or ppc64), these constants cause memory to be touched at sub-page granularity, leading to inefficient access patterns and incorrect page count calculations, which can cause test failures.
Replace all hardcoded 4095 and 4096 values with a global pagesize variable initialized from sysconf(_SC_PAGESIZE) at startup, and remove the redundant local sysconf() calls scattered across individual functions. No functional change on 4K page size systems.
Stable-dep-of: 0567c7eaefd7 ("selftests/cgroup: test_zswap: fix implicit unsigned promotion bug in test_no_kmem_bypass")
--- tools/testing/selftests/cgroup/test_zswap.c | 45 ++++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-)
tools/testing/selftests/cgroup/test_zswap.c +25 -20
@@ -15,6 +15,8 @@#include "../kselftest.h" #include "cgroup_util.h" +static int page_size; +#define PATH_ZSWAP "/sys/module/zswap"#define PATH_ZSWAP_ENABLED "/sys/module/zswap/parameters/enabled"
@@ -73,11 +75,11 @@ static int allocate_and_read_bytes(const char *cgroup, void *arg)if (!mem)return -1 ; -for (int i =0 ; i < size; i +=4095 ) +for (int i =0 ; i < size; i += page_size) mem[i] ='a' ;/* Go through the allocated memory to (z)swap in and out pages */ -for (int i =0 ; i < size; i +=4095 ) { +for (int i =0 ; i < size; i += page_size) {if (mem[i] !='a' ) ret =-1 ; }
@@ -93,7 +95,7 @@ static int allocate_bytes(const char *cgroup, void *arg)if (!mem)return -1 ; -for (int i =0 ; i < size; i +=4095 ) +for (int i =0 ; i < size; i += page_size) mem[i] ='a' ;free (mem);return 0 ;
@@ -167,7 +169,7 @@ static int test_swapin_nozswap(const char *root)int ret =KSFT_FAIL ;char *test_group, mem_max_buf[32 ];long swap_peak, zswpout, min_swap; -size_t allocation_size =sysconf (_SC_PAGESIZE) *512 ; +size_t allocation_size = page_size *512 ; min_swap = allocation_size /4 ;snprintf (mem_max_buf,sizeof (mem_max_buf),"%zu" , allocation_size *3 /4 );
@@ -245,7 +247,7 @@ static int test_zswapin(const char *root) goto out; } -if (zswpin <MB (24 ) /sysconf (_SC_PAGESIZE)) { +if (zswpin <MB (24 ) / page_size) {ksft_print_msg ("at least 24MB should be brought back from zswap\n" ); goto out; }
@@ -272,9 +274,8 @@ static int test_zswapin(const char *root)*/ static int attempt_writeback (const char *cgroup,void *arg) { -long pagesize =sysconf (_SC_PAGESIZE);size_t memsize =MB (4 ); -char buf[pagesize]; +char buf[page_size];long zswap_usage;bool wb_enabled = *(bool *) arg;int ret =-1 ;
@@ -289,11 +290,11 @@ static int attempt_writeback(const char *cgroup, void *arg)* half empty, this will result in data that is still compressible * and ends up in zswap, with material zswap usage. */ -for (int i =0 ; i < pagesize; i++) - buf[i] = i < pagesize/2 ? (char ) i :0 ; +for (int i =0 ; i < page_size; i++) + buf[i] = i < page_size/2 ? (char ) i :0 ; -for (int i =0 ; i < memsize; i += pagesize) -memcpy (&mem[i], buf, pagesize); +for (int i =0 ; i < memsize; i += page_size) +memcpy (&mem[i], buf, page_size);/* Try and reclaim allocated memory */ if (cg_write_numeric (cgroup,"memory.reclaim" , memsize)) {
@@ -304,8 +305,8 @@ static int attempt_writeback(const char *cgroup, void *arg) zswap_usage =cg_read_long (cgroup,"memory.zswap.current" );/* zswpin */ -for (int i =0 ; i < memsize; i += pagesize) { -if (memcmp (&mem[i], buf, pagesize)) { +for (int i =0 ; i < memsize; i += page_size) { +if (memcmp (&mem[i], buf, page_size)) {ksft_print_msg ("invalid memory\n" ); goto out; }
@@ -441,7 +442,7 @@ static int test_no_invasive_cgroup_shrink(const char *root)if (cg_enter_current (control_group)) goto out; control_allocation =malloc (control_allocation_size); -for (int i =0 ; i < control_allocation_size; i +=4095 ) +for (int i =0 ; i < control_allocation_size; i += page_size) control_allocation[i] ='a' ;if (cg_read_key_long (control_group,"memory.stat" ,"zswapped" ) <1 ) goto out;
@@ -481,7 +482,7 @@ static int no_kmem_bypass_child(const char *cgroup, void *arg) values->child_allocated = true;return -1 ; } -for (long i =0 ; i < values->target_alloc_bytes; i +=4095 ) +for (long i =0 ; i < values->target_alloc_bytes; i += page_size) ((char *)allocation)[i] ='a' ; values->child_allocated = true;pause ();
@@ -529,7 +530,7 @@ static int test_no_kmem_bypass(const char *root) min_free_kb_low = sys_info.totalram /500000 ; values->target_alloc_bytes = (sys_info.totalram - min_free_kb_high *1000 ) + sys_info.totalram *5 /100 ; - stored_pages_threshold = sys_info.totalram /5 /4096 ; + stored_pages_threshold = sys_info.totalram /5 / page_size; trigger_allocation_size = sys_info.totalram /20 ;/* Set up test memcg */
@@ -556,7 +557,7 @@ static int test_no_kmem_bypass(const char *root)if (!trigger_allocation)break ; -for (int i =0 ; i < trigger_allocation_size; i +=4095 ) +for (int i =0 ; i < trigger_allocation_size; i += page_size) trigger_allocation[i] ='b' ;usleep (100000 );free (trigger_allocation);
@@ -567,8 +568,8 @@ static int test_no_kmem_bypass(const char *root)/* If memory was pushed to zswap, verify it belongs to memcg */ if (stored_pages > stored_pages_threshold) {int zswapped =cg_read_key_long (test_group,"memory.stat" ,"zswapped " ); -int delta = stored_pages *4096 - zswapped; -int result_ok = delta < stored_pages *4096 /4 ; +int delta = stored_pages * page_size - zswapped; +int result_ok = delta < stored_pages * page_size /4 ; ret = result_ok ?KSFT_PASS :KSFT_FAIL ;break ;
@@ -622,7 +623,7 @@ static int allocate_random_and_wait(const char *cgroup, void *arg)close (fd);/* Touch all pages to ensure they're faulted in */ -for (size_t i =0 ; i < size; i +=PAGE_SIZE ) +for (size_t i =0 ; i < size; i += page_size) mem[i] = mem[i];/* Use MADV_PAGEOUT to push pages into zswap */
@@ -752,6 +753,10 @@ int main(int argc, char **argv)char root[PATH_MAX ];int i; + page_size =sysconf (_SC_PAGE_SIZE); +if (page_size <=0 ) + page_size =BUF_SIZE ; +ksft_print_header ();ksft_set_plan (ARRAY_SIZE (tests));if (cg_find_unified_root (root,sizeof (root),NULL ))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 936/1756 selftests/cgroup: test_zswap: fix implicit unsigned promotion bug in test_no_kmem_bypass
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wilson Felipe Pereira <[email protected]>
[ Upstream commit 0567c7eaefd7ea1b26d76c46964f9a1d92120d7d ]
In test_no_kmem_bypass(), delta (stored_pages * page_size - zswapped) is checked against stored_pages * page_size / 4 to verify that the pages pushed to zswap belong to the test memory cgroup.
Due to slight stat update timing differences, delta can evaluate to a small negative number (e.g. -5MB out of 1GB). Because delta is declared as a signed int and stored_pages is an unsigned size_t, C's usual arithmetic conversions implicitly promote a negative delta to a large unsigned 64-bit integer, causing delta < stored_pages * page_size / 4 to falsely evaluate to 0 and fail the test.
Fix this by declaring zswapped and delta as signed long long and comparing against a signed threshold, ensuring negative deltas correctly evaluate to true.
--- tools/testing/selftests/cgroup/test_zswap.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
tools/testing/selftests/cgroup/test_zswap.c +8 -5
@@ -567,11 +567,14 @@ static int test_no_kmem_bypass(const char *root)break ;/* If memory was pushed to zswap, verify it belongs to memcg */ if (stored_pages > stored_pages_threshold) { -int zswapped =cg_read_key_long (test_group,"memory.stat" ,"zswapped " ); -int delta = stored_pages * page_size - zswapped; -int result_ok = delta < stored_pages * page_size /4 ; - - ret = result_ok ?KSFT_PASS :KSFT_FAIL ; +long zswapped =cg_read_key_long ( + test_group,"memory.stat" ,"zswapped " ); +long long delta = + (long long )stored_pages * page_size - zswapped; +long long max_delta = + (long long )stored_pages * page_size /4 ; + + ret = (delta < max_delta) ?KSFT_PASS :KSFT_FAIL ;break ; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 937/1756 checkpatch: skip CamelCase cache for --no-tree without root
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Petr Vorel <[email protected]>
[ Upstream commit d41ebc7f9e2cc80cb57139c05e71415a79582ab0 ]
Running outside tree (--no-tree) without git root (--root DIR) is not doable because we have no include/ directory which could be cached. But 3445686af721 expected that we are always in Linux tree (w/a git). But --no-tree does not require --root. Therefore skip whole caching in that case.
This fixes perl and find errors when running checkpatch.pl *with* --no-tree --strict and *without* --root:
No structs that should be const will be found - file 'scripts/const_structs.checkpatch': No such file or directory Use of uninitialized value $root in concatenation (.) or string at scripts/checkpatch.pl line 1213.
find: `/include': No such file or directory
--- scripts/checkpatch.pl | 2 ++ 1 file changed, 2 insertions(+)
scripts/checkpatch.pl +2 -0
@@ -1174,6 +1174,8 @@ sub seed_camelcase_includes { my $git_last_include_commit = `${git_command} log --no-merges --pretty=format:"%h%n" -1 -- include`; chomp $git_last_include_commit; $camelcase_cache = ".checkpatch-camelcase.git.$git_last_include_commit"; + } elsif (not defined $root) { + return; } else { my $last_mod_date = 0; $files = `find $root/include -name "*.h"`;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 938/1756 ocfs2: fix deadlock in inline-data truncate transactions
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joseph Qi <[email protected]>
[ Upstream commit c204bf5ac3eeb66648904d0374d6f7b84d843aac ]
Updating an inode xattr can cause an ABBA deadlock with inline file truncation:
ocfs2_truncate_file()
down_write(&oi->ip_alloc_sem)
ocfs2_truncate_inline()
ocfs2_start_trans() ocfs2_xattr_set()
ocfs2_start_trans()
ocfs2_xattr_ibody_set()
down_write(&oi->ip_alloc_sem)The xattr set path starts the merged transaction before the inode-body xattr helper acquires ip_alloc_sem, reversing the ip_alloc_sem -> transaction order used by the allocation and truncate paths. The transaction merge in commit 85db90e77806 ("ocfs2/xattr: Merge xattr set transaction.") introduced this ordering.
Fix it by acquiring ip_alloc_sem once in ocfs2_xattr_set(), before xattr preparation, allocation reservations and ocfs2_start_trans(), and removing the per-helper acquisition from ocfs2_xattr_ibody_find(), ocfs2_xattr_ibody_set() and ocfs2_xattr_create_index_block(). These helpers now assert via lockdep that the caller holds ip_alloc_sem.
ocfs2_xattr_set_handle(), which only sets initial ACL or security xattrs on unpublished inodes inside the create transaction, takes ip_alloc_sem under a dedicated lockdep subclass so that the assertions hold without creating a transaction -> ip_alloc_sem cycle against the ip_alloc_sem -> transaction order. The inode is unpublished, so the acquisition can never contend.
This keeps the established ip_alloc_sem -> transaction order and makes the locking unconditional, so lockdep can verify a single plain ordering instead of conditional acquisitions.
--- fs/ocfs2/xattr.c | 79 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 26 deletions(-)
fs/ocfs2/xattr.c +53 -26
@@ -2912,6 +2912,9 @@ static int ocfs2_xattr_has_space_inline(struct inode *inode,* * Find extended attribute in inode block and * fill search info into struct ocfs2_xattr_search. +* +* The inline free-space check races with truncate and allocation, so +* callers must hold ip_alloc_sem for writing. */ static int ocfs2_xattr_ibody_find(struct inode *inode, int name_index,
@@ -2923,13 +2926,13 @@ static int ocfs2_xattr_ibody_find(struct inode *inode,int ret;int has_space =0 ; +lockdep_assert_held_write (&oi->ip_alloc_sem); +if (inode->i_sb->s_blocksize ==OCFS2_MIN_BLOCKSIZE )return 0 ;if (!(oi->ip_dyn_features &OCFS2_INLINE_XATTR_FL )) { -down_read (&oi->ip_alloc_sem); has_space =ocfs2_xattr_has_space_inline (inode, di); -up_read (&oi->ip_alloc_sem);if (!has_space)return 0 ; }
@@ -3008,6 +3011,7 @@ static int ocfs2_xattr_ibody_init(struct inode *inode,* * Set, replace or remove an extended attribute into inode block. * +* Callers must hold ip_alloc_sem for writing. */ static int ocfs2_xattr_ibody_set(struct inode *inode, struct ocfs2_xattr_info *xi,
@@ -3018,16 +3022,17 @@ static int ocfs2_xattr_ibody_set(struct inode *inode,struct ocfs2_inode_info *oi =OCFS2_I (inode);struct ocfs2_xa_loc loc; +lockdep_assert_held_write (&oi->ip_alloc_sem); +if (inode->i_sb->s_blocksize ==OCFS2_MIN_BLOCKSIZE )return -ENOSPC ; -down_write (&oi->ip_alloc_sem);if (!(oi->ip_dyn_features &OCFS2_INLINE_XATTR_FL )) { ret =ocfs2_xattr_ibody_init (inode, xs->inode_bh, ctxt);if (ret) {if (ret != -ENOSPC )mlog_errno (ret); - goto out; +return ret; } }
@@ -3037,13 +3042,10 @@ static int ocfs2_xattr_ibody_set(struct inode *inode,if (ret) {if (ret != -ENOSPC )mlog_errno (ret); - goto out; +return ret; } xs->here = loc.xl_entry; -out: -up_write (&oi->ip_alloc_sem); -return ret; }
@@ -3701,6 +3703,18 @@ static int __ocfs2_xattr_set_handle(struct inode *inode,return ret; } +/* +* ip_alloc_sem subclass for inodes being initialized before publication. +* ocfs2_xattr_set_handle() runs inside the create transaction, so taking +* ip_alloc_sem there adds a transaction -> ip_alloc_sem order that would +* form a lockdep cycle with the ip_alloc_sem -> transaction order used +* elsewhere, if not for this separate subclass. The inode is unpublished +* so the acquisition can never contend. +*/ +enum { +OCFS2_IP_ALLOC_SEM_UNPUBLISHED =1 , +}; +/* * This helper is only for setting initial ACL or security xattrs on an inode * that is still unpublished, unhashed, and unattached to a dentry.
@@ -3762,6 +3776,13 @@ int ocfs2_xattr_set_handle(handle_t *handle, xis.inode_bh = xbs.inode_bh = di_bh; di = (struct ocfs2_dinode *)di_bh->b_data; +/* +* The inode is unpublished and cannot contend, but take the +* semaphore anyway so the helpers' lockdep assertions hold. +*/ +down_write_nested (&OCFS2_I (inode)->ip_alloc_sem, +OCFS2_IP_ALLOC_SEM_UNPUBLISHED ); + ret =ocfs2_xattr_ibody_find (inode, name_index, name, &xis);if (ret) goto cleanup;
@@ -3774,6 +3795,7 @@ int ocfs2_xattr_set_handle(handle_t *handle, ret =__ocfs2_xattr_set_handle (inode, di, &xi, &xis, &xbs, &ctxt); cleanup: +up_write (&OCFS2_I (inode)->ip_alloc_sem);brelse (xbs.xattr_bh);ocfs2_xattr_bucket_free (xbs.bucket);
@@ -3842,30 +3864,38 @@ int ocfs2_xattr_set(struct inode *inode, di = (struct ocfs2_dinode *)di_bh->b_data;down_write (&OCFS2_I (inode)->ip_xattr_sem); +/* +* The allocation and truncate paths take ip_alloc_sem before +* starting a transaction, so take it here before xattr +* preparation, allocation reservations and ocfs2_start_trans() +* to keep that order. The xattr helpers below no longer take +* it themselves. +*/ +down_write (&OCFS2_I (inode)->ip_alloc_sem);/* * Scan inode and external block to find the same name * extended attribute and collect search information. */ ret =ocfs2_xattr_ibody_find (inode, name_index, name, &xis);if (ret) - goto cleanup; + goto out_free_ac;if (xis.not_found) { ret =ocfs2_xattr_block_find (inode, name_index, name, &xbs);if (ret) - goto cleanup; + goto out_free_ac; }if (xis.not_found && xbs.not_found) { ret = -ENODATA ;if (flags &XATTR_REPLACE ) - goto cleanup; + goto out_free_ac; ret =0 ;if (!value) - goto cleanup; + goto out_free_ac; }else { ret = -EEXIST ;if (flags &XATTR_CREATE ) - goto cleanup; + goto out_free_ac; }/* Check whether the value is refcounted and do some preparation. */
@@ -3876,7 +3906,7 @@ int ocfs2_xattr_set(struct inode *inode, &ref_meta, &ref_credits);if (ret) {mlog_errno (ret); - goto cleanup; + goto out_free_ac; } }
@@ -3887,7 +3917,7 @@ int ocfs2_xattr_set(struct inode *inode,if (ret <0 ) {inode_unlock (tl_inode);mlog_errno (ret); - goto cleanup; + goto out_free_ac; } }inode_unlock (tl_inode);
@@ -3896,7 +3926,7 @@ int ocfs2_xattr_set(struct inode *inode, &xbs, &ctxt, ref_meta, &credits);if (ret) {mlog_errno (ret); - goto cleanup; + goto out_free_ac; }/* we need to update inode's ctime field, so add credit for it. */
@@ -3914,6 +3944,7 @@ int ocfs2_xattr_set(struct inode *inode,ocfs2_commit_trans (osb, ctxt.handle); out_free_ac: +up_write (&OCFS2_I (inode)->ip_alloc_sem);if (ctxt.data_ac)ocfs2_free_alloc_context (ctxt.data_ac);if (ctxt.meta_ac)
@@ -3922,7 +3953,6 @@ int ocfs2_xattr_set(struct inode *inode,ocfs2_schedule_truncate_log_flush (osb,1 );ocfs2_run_deallocs (osb, &ctxt.dealloc); -cleanup:if (ref_tree)ocfs2_unlock_refcount_tree (osb, ref_tree,1 );up_write (&OCFS2_I (inode)->ip_xattr_sem);
@@ -4623,6 +4653,10 @@ static void ocfs2_xattr_update_xattr_search(struct inode *inode, xs->here = xs->header->xh_entries; } +/* +* Caller must hold ip_alloc_sem for writing, since a new xattr block +* is allocated and the xattr block header is rewritten. +*/ static int ocfs2_xattr_create_index_block(struct inode *inode, struct ocfs2_xattr_info *xi, struct ocfs2_xattr_search *xs,
@@ -4639,19 +4673,14 @@ static int ocfs2_xattr_create_index_block(struct inode *inode,struct ocfs2_xattr_tree_root *xr;u16 xb_flags =le16_to_cpu (xb->xb_flags); +lockdep_assert_held_write (&oi->ip_alloc_sem); +trace_ocfs2_xattr_create_index_block_begin ( (unsigned long long )xb_bh->b_blocknr);BUG_ON (xb_flags &OCFS2_XATTR_INDEXED );BUG_ON (!xs->bucket); -/* -* XXX: -* We can use this lock for now, and maybe move to a dedicated mutex -* if performance becomes a problem later. -*/ -down_write (&oi->ip_alloc_sem); - ret =ocfs2_journal_access_xb (handle,INODE_CACHE (inode), xb_bh,OCFS2_JOURNAL_ACCESS_WRITE );if (ret) {
@@ -4713,8 +4742,6 @@ static int ocfs2_xattr_create_index_block(struct inode *inode,ocfs2_journal_dirty (handle, xb_bh); out: -up_write (&oi->ip_alloc_sem); -return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 939/1756 selftests/epoll: fix race condition in multi-waiter wakeup tests
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Schmaus <[email protected]>
[ Upstream commit 4238e66c82b6ee888a768cb298c85083b4566726 ]
In tests with multiple concurrent waiters on edge-triggered epoll instances where an emitter writes to multiple sockets (epoll16, epoll56, epoll58):
When the emitter performs its first write(), ep_poll_callback() fires and wakes up both waiters because one waiter uses epoll_wait() and the other one uses poll(). This translates to different wait queues, ep->wq for epoll and ep->poll_wait for poll/select, which are both awoken by the kernel because of that single write. Next, both waiter threads invoke epoll_wait(), but since there is only one event, only one epoll_wait() will return non-zero because of the edge-triggered mode being used (in level-triggered mode, the kernel would re-queue the event because of remaining unread data).
Since the second waiter sees an empty ready list, it does not increment ctx.count and the test fails spuriously with ctx.count == 1 instead of 2.
Emitter (CPU 0) Thread 0 (CPU 1) Thread 1 (CPU 2)
=============== ================ ================
epoll_wait(e0, -1) poll(e0, -1)
[on e0->wq] [on e0->poll_wait] write(sfd[1])
|
+--(Kernel wakes BOTH e0->wq and e0->poll_wait via callback)--+
| |
| wakes up wakes up |
| epoll_wait() reaps e1 poll() returns 1 |
| (e1 removed via ET) (wants event) |
| e0->rdllist is EMPTY | |
| count++ (count = 1) v |
| epoll_wait(e0, 0) |
| sees EMPTY list! |
| returns 0! |
| thread exits |
v |
write(sfd[3]) |
(event arrives too late!) v
EXPECT_EQ(count, 2) <-- SPURIOUS FAILURE!
Introduce waiter_entry1ap_loop() to retry poll() if the initial epoll_wait(..., 0) yielded no events. This ensures the thread waits for the subsequent write rather than failing immediately. Apply this helper in epoll16, epoll56, and for both waiter threads in epoll58.
--- .../filesystems/epoll/epoll_wakeup_test.c | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-)
tools/testing/selftests/filesystems/epoll/epoll_wakeup_test.c +22 -10
@@ -74,6 +74,24 @@ static void *waiter_entry1ap(void *data)return NULL ; } +static void *waiter_entry1ap_loop (void *data) +{ +struct pollfd pfd; +struct epoll_event e; +struct epoll_mtcontext *ctx = data; + + pfd.fd = ctx->efd[0 ]; + pfd.events =POLLIN ; +while (poll (&pfd,1 ,2000 ) >0 ) { +if (epoll_wait (ctx->efd[0 ], &e,1 ,0 ) >0 ) { +__sync_fetch_and_add (&ctx->count,1 ); +break ; + } + } + +return NULL ; +} +static void *waiter_entry1o (void *data) {struct epoll_event e;
@@ -809,7 +827,7 @@ TEST(epoll16)ASSERT_EQ (epoll_ctl (ctx.efd[0 ],EPOLL_CTL_ADD , ctx.sfd[2 ], events),0 ); ctx.main =pthread_self (); -ASSERT_EQ (pthread_create (&ctx.waiter,NULL , waiter_entry1ap, &ctx),0 ); +ASSERT_EQ (pthread_create (&ctx.waiter,NULL , waiter_entry1ap_loop, &ctx),0 );ASSERT_EQ (pthread_create (&emitter,NULL , emitter_entry2, &ctx),0 );if (epoll_wait (ctx.efd[0 ], events,1 ,-1 ) >0 )
@@ -2925,7 +2943,7 @@ TEST(epoll56)ASSERT_EQ (epoll_ctl (ctx.efd[0 ],EPOLL_CTL_ADD , ctx.efd[2 ], &e),0 ); ctx.main =pthread_self (); -ASSERT_EQ (pthread_create (&ctx.waiter,NULL , waiter_entry1ap, &ctx),0 ); +ASSERT_EQ (pthread_create (&ctx.waiter,NULL , waiter_entry1ap_loop, &ctx),0 );ASSERT_EQ (pthread_create (&emitter,NULL , emitter_entry2, &ctx),0 );if (epoll_wait (ctx.efd[0 ], &e,1 ,-1 ) >0 )
@@ -3030,7 +3048,6 @@ TEST(epoll57)TEST (epoll58) {pthread_t emitter; -struct pollfd pfd;struct epoll_event e;struct epoll_mtcontext ctx = {0 };
@@ -3061,15 +3078,10 @@ TEST(epoll58)ASSERT_EQ (epoll_ctl (ctx.efd[0 ],EPOLL_CTL_ADD , ctx.efd[2 ], &e),0 ); ctx.main =pthread_self (); -ASSERT_EQ (pthread_create (&ctx.waiter,NULL , waiter_entry1ap, &ctx),0 ); +ASSERT_EQ (pthread_create (&ctx.waiter,NULL , waiter_entry1ap_loop, &ctx),0 );ASSERT_EQ (pthread_create (&emitter,NULL , emitter_entry2, &ctx),0 ); - pfd.fd = ctx.efd[0 ]; - pfd.events =POLLIN ; -if (poll (&pfd,1 ,-1 ) >0 ) { -if (epoll_wait (ctx.efd[0 ], &e,1 ,0 ) >0 ) -__sync_fetch_and_add (&ctx.count,1 ); - } +waiter_entry1ap_loop (&ctx);ASSERT_EQ (pthread_join (ctx.waiter,NULL ),0 );EXPECT_EQ (ctx.count,2 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 940/1756 init/main: fix off-by-one in argv_init cleanup
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wilson Felipe Pereira <[email protected]>
[ Upstream commit b82ed0e3a1dafe41577b095318a3ea6c0eec6f46 ]
Patch series "init: fix array boundary bugs in boot parameter parsing".
This series fixes two distinct boundary logic edge-case bugs in init/main.c related to parsing boot command-line arguments and environment variables. Both bugs have been present since the early git history (Linux-2.6.12-rc2).
1. The first patch fixes an off-by-one error in init_setup() where the final slot of the argv_init array was left uncleared. This allowed a stale kernel parameter to leak into the init process's user-space command line if exactly MAX_INIT_ARGS unknown parameters were passed.
2. The second patch fixes a false-positive kernel panic in unknown_bootoption(). If a user filled the environment variable array up to its exact limit (32) and then attempted to overwrite the final variable, the kernel would panic before evaluating whether it was a harmless duplicate.
Exact QEMU reproduction steps for both edge cases are documented inside their respective commit descriptions.
This patch (of 2):
When cleaning up argv_init in init_setup() and rdinit_setup(), the loop terminates one element early due to using '<' instead of '<='. Since argv_init is sized MAX_INIT_ARGS+2, index MAX_INIT_ARGS is a valid element that should be cleared to NULL.
If exactly MAX_INIT_ARGS unknown arguments are passed before 'init=', the uncleared argv_init[MAX_INIT_ARGS] can act as a ghost argument to /sbin/init or cause a spurious kernel panic when later appended to.
To verify the argument leak, boot a VM into a shell with 32 unknown kernel arguments, the init parameter, and 31 user arguments:
STALE_ARGS=$(for i in {1..32}; do echo -n "stale$i "; done)
USER_ARGS=$(for i in {1..31}; do echo -n "user$i "; done)
qemu-system-x86_64 -kernel bzImage \
-append "$STALE_ARGS init=/bin/sh $USER_ARGS"Running cat /proc/1/cmdline inside the shell reveals that the 32nd kernel argument ('stale32') incorrectly leaked into the init process's command line. This patch zeroes the final slot, cleanly terminating the array.
--- init/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
init/main.c +2 -2
@@ -570,7 +570,7 @@ static int __init init_setup(char *str)* the shell think it should execute a script with such name. * So we ignore all arguments entered _before_ init=... [MJ] */ -for (i =1 ; i <MAX_INIT_ARGS ; i++) +for (i =1 ; i <=MAX_INIT_ARGS ; i++) argv_init[i] =NULL ;return 1 ; }
@@ -582,7 +582,7 @@ static int __init rdinit_setup(char *str) ramdisk_execute_command = str;/* See "auto" comment in init_setup */ -for (i =1 ; i <MAX_INIT_ARGS ; i++) +for (i =1 ; i <=MAX_INIT_ARGS ; i++) argv_init[i] =NULL ;return 1 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 941/1756 init/main: fix false-positive kernel panic on environment variable overwrite
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wilson Felipe Pereira <[email protected]>
[ Upstream commit 51e766bcd35e706d8df29dd0fac98871fdced261 ]
In unknown_bootoption(), the limit checking for environment variables sets panic_later *before* checking if the variable already exists in envp_init.
If a user passes exactly MAX_INIT_ENVS custom variables and then overwrites the final variable by matching its key, it causes a false-positive hard panic on boot despite not actually exceeding the array bounds or increasing the total variable count.
Swapping the order of these checks allows the duplicate check to break out of the loop before the panic flag is erroneously latched.
To verify, boot a VM with 31 custom variables (filling the array up to its limit of 32) and then overwrite the very last variable:
ENV_VARS=$(for i in {1..31}; do echo -n "var$i=$i "; done)
qemu-system-x86_64 -kernel bzImage -append "$ENV_VARS var31=overwrite"Without this patch, the kernel crashes instantly with:
Kernel panic - not syncing: Too many boot env vars at 'var31=overwrite'
With this patch, the kernel safely overwrites the variable and boots.
--- init/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
init/main.c +2 -2
@@ -537,12 +537,12 @@ static int __init unknown_bootoption(char *param, char *val,/* Environment option */ unsigned int i;for (i =0 ; envp_init[i]; i++) { +if (!strncmp (param, envp_init[i], len+1 )) +break ;if (i ==MAX_INIT_ENVS ) { panic_later ="env" ; panic_param = param; } -if (!strncmp (param, envp_init[i], len+1 )) -break ; } envp_init[i] = param; }else {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 942/1756 ocfs2: allow xattr bucket entries to span multiple blocks
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joseph Qi <[email protected]>
[ Upstream commit 78cce2082d22d3c56bd3a6146ef0dcf7cd661a33 ]
Patch series "ocfs2: xattr bucket validation fixes", v2.
This series fixes two problems around xattr bucket validation.
Patch 1 fixes a false-corruption failure on blocksize-512 volumes: the bucket validator limited the entry array to the first bucket block while the write path stores entries across the whole 4096-byte bucket region, so a legitimately written, fsck-clean bucket could be rejected and force the filesystem read-only. It also adds an alignment check on the bucket block number, since the entry array is accessed as one contiguous region and a corrupted xattr tree could otherwise point a bucket at blocks straddling a page boundary.
Patch 2 converts two mlog_bug_on_msg() checks in the bucket defrag path to ocfs2_error() returns, so that a corrupt bucket holding overlapping entries or an inflated xh_free_start marks the filesystem read-only and fails the setxattr instead of panicking the kernel.
Both patches have been tested in QEMU: the blocksize-512 reproducer (40 xattrs with 100-byte values, previously failing with "entry count 32 exceeds maximum 31") now passes with a clean fsck.ocfs2 result, and the ocfs2 testsuite xattr tests pass 48/48 across blocksize combinations.
This patch (of 2):
ocfs2_validate_xattr_bucket() limits the entry array to the first bucket block, but the write path stores entries across the whole OCFS2_XATTR_BUCKET_SIZE region. With 512-byte blocks a bucket spans eight blocks, and a bucket filled with small xattrs places its last entries past offset 512. Reading such a bucket back errors out:
OCFS2: ERROR (device loop0): ocfs2_validate_xattr_bucket: Invalid xattr bucket 86072: entry count 32 exceeds maximum 31 On-disk corruption discovered. Please run fsck.ocfs2 once the filesystem is unmounted.
OCFS2: File system is now read-only.
This is reproducible by setting ~33 xattrs with 100-byte values on a file on a blocksize-512 volume; fsck.ocfs2 reports the resulting image clean.
Check the entry count against the full bucket region instead. The per-block bounds checks for names and values stay as they are, since ocfs2_bucket_align_free_start() keeps each name+value pair within a single block.
The entry array is one contiguous region, so a bucket from a corrupted xattr tree whose first block is not aligned to OCFS2_XATTR_BUCKET_SIZE could straddle a page and make the validation loop read out of bounds. Buckets allocated within clusters are always aligned, so reject any other block number while validating.
--- fs/ocfs2/xattr.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
fs/ocfs2/xattr.c +20 -1
@@ -1121,11 +1121,30 @@ static int ocfs2_validate_xattr_bucket(struct ocfs2_xattr_bucket *bucket,struct ocfs2_xattr_header *xh =bucket_xh (bucket);u16 xattr_count =le16_to_cpu (xh->xh_count);size_t region_size = (size_t )sb->s_blocksize * bucket->bu_blocks; -size_t entries_limit = sb->s_blocksize; +/* +* The entry array grows up from the header across the whole +* bucket region, so it may extend beyond the first bucket block +* when the blocksize is smaller than OCFS2_XATTR_BUCKET_SIZE. +* Name/value pairs, however, always live within a single block. +*/ +size_t entries_limit = region_size;size_t nv_limit = sb->s_blocksize;size_t max_entries;int i; +/* +* The entry array is one contiguous region that may span the +* bucket's buffer_heads. Buckets are allocated within clusters, +* so their first block is always aligned to +* OCFS2_XATTR_BUCKET_SIZE and the whole bucket fits in one page. +* A corrupted xattr tree can point a bucket at blocks straddling +* a page, so reject it before touching the entry array. +*/ +if (blkno & (bucket->bu_blocks -1 )) +return ocfs2_error (sb, +"Invalid xattr bucket %llu: unaligned block number\n" , + (unsigned long long )blkno); +if (region_size <sizeof (*xh)) return ocfs2_error(sb, "Invalid xattr bucket %llu: region size %zu is too small\n",
Signature · 1 line
2.53.0
Re: [PATCH 6.12 0942/1756] ocfs2: allow xattr bucket entries to span multiple blocks
Hi Sasha/Greg,
Quoted 9 lines · Greg Kroah-Hartman
6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joseph Qi <[email protected]>
[ Upstream commit
78cce2082d22d3c56bd3a6146ef0dcf7cd661a33]Patch series "ocfs2: xattr bucket validation fixes", v2.
...
Quoted 15 lines
Cc Junxiao Bi <[email protected]>Cc Changwei Ge <[email protected]>Cc Jun Piao <[email protected]>Cc Heming Zhao <[email protected]>Signed-off-by Sasha Levin <[email protected]>--- fs/ocfs2/xattr.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)fs/ocfs2/xattr.c +0
-0@@ -1121,11 +1121,30 @@ static int ocfs2_validate_xattr_bucket(struct ocfs2_xattr_bucket *bucket,struct ocfs2_xattr_header *xh =bucket_xh (bucket);
fs/ocfs2/xattr.c static int ocfs2_validate_xattr_bucket(struct ocfs2_xattr_bucket *bucket, · line 1130
Quoted 10 lines
fs/ocfs2/xattr.c +7
-1u16 xattr_count =le16_to_cpu (xh->xh_count);size_t region_size = (size_t )sb->s_blocksize * bucket->bu_blocks; -size_t entries_limit = sb->s_blocksize; +/* +* The entry array grows up from the header across the whole +* bucket region, so it may extend beyond the first bucket block +* when the blocksize is smaller than OCFS2_XATTR_BUCKET_SIZE. +* Name/value pairs, however, always live within a single block. +*/ +size_t entries_limit = region_size;
I ran an AI-assisted backport review and I checked the finding against the code, and it looks valid to me.
verdict: We might need a followup fix, nothing to drop for this now.
This patch allows xattr entry arrays to span multiple blocks.
In fs/ocfs2/xattr.c, ocfs2_defrag_xattr_bucket(), the difference is (6.12.y -> upstream):
for (i = 0; i < le16_to_cpu(xh->xh_count); i++, xe++) {
+ ret = ocfs2_validate_xattr_entry(inode->i_sb, blkno, xe);
+ if (ret)
+ goto out;
offset = le16_to_cpu(xe->xe_name_offset);
len = namevalue_size_xe(xe);The missing check rejects local xattr values larger than 80 bytes. Without it, a corrupt value can pass the block-size bounds check and reach this assertion in namevalue_size_xe():
BUG_ON((value_len > OCFS2_XATTR_INLINE_SIZE) &&
ocfs2_xattr_is_local(xe));The bug already exists for smaller buckets; this backport allows additional corrupt buckets to reach it.
Could we also include 415ad9147484 ("ocfs2: reject inconsistent local xattr entries")? It adds the missing validation both when reading buckets and before the size calculation.
thanks,
Harshit
Quoted 20 lines
fs/ocfs2/xattr.c +13
-0size_t nv_limit = sb->s_blocksize;size_t max_entries;int i; +/* +* The entry array is one contiguous region that may span the +* bucket's buffer_heads. Buckets are allocated within clusters, +* so their first block is always aligned to +* OCFS2_XATTR_BUCKET_SIZE and the whole bucket fits in one page. +* A corrupted xattr tree can point a bucket at blocks straddling +* a page, so reject it before touching the entry array. +*/ +if (blkno & (bucket->bu_blocks -1 )) +return ocfs2_error (sb, +"Invalid xattr bucket %llu: unaligned block number\n" , + (unsigned long long )blkno); +if (region_size <sizeof (*xh)) return ocfs2_error(sb, "Invalid xattr bucket %llu: region size %zu is too small\n",
Sasha Levin
maintainerRe: [PATCH 6.12 0942/1756] ocfs2: allow xattr bucket entries to span multiple blocks
Quoted 3 lines
Could we also include
415ad9147484("ocfs2: reject inconsistent local xattr entries")? It adds the missing validation both when reading buckets and before the size calculation.
Queued for 7.3. 6.12 and 6.6 have to wait until 6.18 has the rest of the xattr validation work, which it is missing: 2cf82b46d5e4 ("ocfs2: validate external xattr entries when reading metadata"), 8914a3330b72 ("ocfs2: validate inline xattrs during inode block validation") and 78cce2082d22 ("ocfs2: allow xattr bucket entries to span multiple blocks").
Signature · 2 lines
Thanks, Sasha
Greg Kroah-Hartman
maintainerPATCH 943/1756 ocfs2: reject inconsistent xattr bucket during defrag
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joseph Qi <[email protected]>
[ Upstream commit bd40b997f04542869afeabe94f2cf1a016fc9bfa ]
ocfs2_defrag_xattr_bucket() has two mlog_bug_on_msg() checks that assume the name/value pairs in a bucket are disjoint and that xh_free_start is not below the compacted region.
ocfs2_validate_xattr_bucket() only checks each entry in isolation, so a corrupt bucket holding overlapping entries, or one with an inflated xh_free_start, passes validation and then hits BUG() in defrag when a setxattr triggers it.
Defrag works on a linear copy of the bucket and does not touch the real blocks before the copy back, so the checks can return an error instead of calling BUG().
--- fs/ocfs2/xattr.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
fs/ocfs2/xattr.c +11 -5
@@ -4856,16 +4856,22 @@ static int ocfs2_defrag_xattr_bucket(struct inode *inode,memmove (bucket_buf + end - len, bucket_buf + offset, len); xe->xe_name_offset =cpu_to_le16 (end - len); + }else if (end < offset + len) { + ret =ocfs2_error (inode->i_sb, +"Defrag check failed for bucket %llu\n" , + (unsigned long long )blkno); + goto out; } -mlog_bug_on_msg (end < offset + len,"Defrag check failed for " -"bucket %llu\n" , (unsigned long long )blkno); - end -= len; } -mlog_bug_on_msg (xh_free_start > end,"Defrag check failed for " -"bucket %llu\n" , (unsigned long long )blkno); +if (xh_free_start > end) { + ret =ocfs2_error (inode->i_sb, +"Defrag check failed for bucket %llu\n" , + (unsigned long long )blkno); + goto out; + }if (xh_free_start == end) goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 944/1756 PCI/AER: Fix struct pci_dev reference leak in aer_process_err_devices()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Priyank Rathod <[email protected]>
[ Upstream commit e86ac10110d00e6c3801f38bde1863951315222b ]
When an AER error occurs, candidate error-source devices are added to e_info->dev[] by add_error_device(), which takes a reference with pci_dev_get().
A device can be recorded without any error status being present: the Requester ID fast path in is_error_source(),
if (e_info->id == pci_dev_id(dev))
return true;
matches purely on the ID reported by the Root Port and returns true without reading the device's AER status registers.
In aer_process_err_devices(), handle_error_source() is called only if aer_get_device_error_info() returns non-zero, i.e. only if an unmasked error status bit is actually set. It returns 0 if the device has become inaccessible (status and mask both read as all ones, so status & ~mask == 0) or if no unmasked status bit is set.
Because handle_error_source() was responsible for calling pci_dev_put(), skipping it permanently leaks the reference taken in add_error_device().
Decouple reference lifetime from error handling by moving pci_dev_put() out of handle_error_source() and into the aer_process_err_devices() loop, so every recorded device is put exactly once.
handle_error_source() is static and aer_process_err_devices() is its only caller, so no other path is affected.
--- drivers/pci/pcie/aer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/pcie/aer.c +1 -1
@@ -1124,7 +1124,6 @@ static void handle_error_source(struct pci_dev *dev, struct aer_err_info *info) {cxl_rch_handle_error (dev, info);pci_aer_handle_error (dev, info); -pci_dev_put (dev); }#ifdef CONFIG_ACPI_APEI_PCIEAER
@@ -1277,6 +1276,7 @@ static inline void aer_process_err_devices(struct aer_err_info *e_info)for (i =0 ; i < e_info->error_dev_num && e_info->dev[i]; i++) {if (aer_get_device_error_info (e_info->dev[i], e_info))handle_error_source (e_info->dev[i], e_info); +pci_dev_put (e_info->dev[i]); } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 945/1756 ALSA: caiaq: Allow zero-length packet handling for EP1
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit ccfe6ab672c020fca56988e634088bfb7764e2a7 ]
The recent fix to avoid OOB access for malformed packets added a packet length check and returns immediately if it's too short. However, this can be lead to a regression because the completion handler doesn't resubmit the packet, while a zero-length packet itself is valid, per se.
For addressing the potential regression above, change the handling for a zero-length packet to just resubmit without processing the incoming contents.
--- sound/usb/caiaq/device.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
sound/usb/caiaq/device.c +2 -1
@@ -142,7 +142,7 @@ static void usb_ep1_command_reply_dispatch (struct urb* urb)return ; }if (urb->actual_length <1 ) -return ; + goto resubmit; payload_len = urb->actual_length -1 ;
@@ -192,6 +192,7 @@ static void usb_ep1_command_reply_dispatch (struct urb* urb)break ; } + resubmit: cdev->ep1_in_urb->actual_length =0 ; ret =usb_submit_urb (cdev->ep1_in_urb,GFP_ATOMIC );if (ret <0 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 946/1756 gen_init_cpio: stop parsing on lines with a missing argument list
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leizhen Zhang <[email protected]>
[ Upstream commit c8dd1aa0274d8ad3df82ec1b064065f410ce99ed ]
When a line in the cpio list consists of a file type followed only by whitespace and no newline (e.g. "slink " as the last line of the file), strtok(NULL, "\n") returns NULL. main() prints an error and sets ec, but then carries on and passes the NULL args pointer to the type handler, which hands it to sscanf() and crashes:
AddressSanitizer: SEGV on unknown address 0x000000000000
#4 __isoc99_sscanf
#5 cpio_mkslink_line usr/gen_init_cpio.c:169Break out of the loop as is already done for the other format error, so that the error is reported and gen_init_cpio exits with a failure status.
Found by fuzzing gen_init_cpio built with ASan/UBSan.
Reproducer:
printf 'slink ' > list && usr/gen_init_cpio list
--- usr/gen_init_cpio.c | 1 + 1 file changed, 1 insertion(+)
usr/gen_init_cpio.c +1 -0
@@ -672,6 +672,7 @@ int main (int argc, char *argv[])"ERROR: incorrect format, newline required line %d: '%s'\n" , line_nr, line); ec =-1 ; +break ; }for (type_idx =0 ; file_handler_table[type_idx].type; type_idx++) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 947/1756 pinctrl: sprd: free maps on DT map failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiale Yao <[email protected]>
[ Upstream commit e873c665e503ebfb6dafaf9346c3956695686226 ]
sprd_dt_node_to_map() reserves map storage before adding mux and configuration entries. If a later operation fails, the error path only frees the temporary configurations and leaves the map allocation reachable through the output pointer.
Free the partially built map on failure. The caller ignores the output parameters when the mapping callback returns an error, so they do not need to be reset after freeing the map.
--- drivers/pinctrl/sprd/pinctrl-sprd.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/pinctrl/sprd/pinctrl-sprd.c +3 -0
@@ -329,6 +329,9 @@ static int sprd_dt_node_to_map(struct pinctrl_dev *pctldev, out:kfree (configs); +if (ret <0 ) +pinctrl_utils_free_map (pctldev, *map, *num_maps); +return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 948/1756 wifi: mt76: mt7915: check default EEPROM firmware size before copying
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Felix Fietkau <[email protected]>
[ Upstream commit bce4aef211b3941af9ca297162406fc84f22ed5d ]
mt7915_eeprom_load_default() copied mt7915_eeprom_size() bytes from the firmware blob after only checking that it was non-NULL. A truncated default bin caused an out-of-bounds read past the firmware buffer into the EEPROM image. Reject a blob smaller than the EEPROM size.
--- drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c +6 -0
@@ -111,6 +111,12 @@ mt7915_eeprom_load_default(struct mt7915_dev *dev) goto out; } +if (fw->size <mt7915_eeprom_size (dev)) { +dev_err (dev->mt76.dev,"Invalid default bin size\n" ); + ret = -EINVAL ; + goto out; + } +memcpy (eeprom, fw->data,mt7915_eeprom_size (dev)); dev->flash_mode = true;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 949/1756 wifi: mt76: mt7996: validate firmware event lengths before parsing
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Felix Fietkau <[email protected]>
[ Upstream commit c88f880c6430948492a4eee00d90e48fa800febf ]
Two unsolicited event handlers trusted firmware-provided lengths:mt7996_mcu_rx_all_sta_info_event() looped over res->sta_num without checking it against skb->len, reading the flex array out of bounds; and mt7996_mcu_rx_log_message() could compute a negative or oversized length from tlv->len and feed it to %.*s and the debugfs log path. Bound both against the actual skb length.
--- .../net/wireless/mediatek/mt76/mt7996/mcu.c | 46 +++++++++++++++++-- 1 file changed, 41 insertions(+), 5 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/mcu.c +41 -5
@@ -380,21 +380,32 @@ mt7996_mcu_rx_log_message(struct mt7996_dev *dev, struct sk_buff *skb) {#define UNI_EVENT_FW_LOG_FORMAT 0struct mt7996_mcu_rxd *rxd = (struct mt7996_mcu_rxd *)skb->data; -const char *data = (char *)&rxd[1 ] +4 , *type; -struct tlv *tlv = (struct tlv *)data; +const char *data, *type; +struct tlv *tlv;int len; +if (skb->len <sizeof (*rxd)) +return ; +if (!(rxd->option &MCU_UNI_CMD_EVENT )) { - len = skb->len -sizeof (*rxd); data = (char *)&rxd[1 ]; + len = skb->len -sizeof (*rxd); goto out; } +if (skb->len <sizeof (*rxd) +4 +sizeof (*tlv)) +return ; + + tlv = (struct tlv *)((char *)&rxd[1 ] +4 );if (le16_to_cpu (tlv->tag) !=UNI_EVENT_FW_LOG_FORMAT )return ; - data +=sizeof (*tlv) +4 ; +if (le16_to_cpu (tlv->len) <sizeof (*tlv) +4 ) +return ; + + data = (char *)tlv +sizeof (*tlv) +4 ; len =le16_to_cpu (tlv->len) -sizeof (*tlv) -4 ; + len =min_t (int, len, skb->len - (int )(data - (char *)skb->data)); out:switch (rxd->s2d_index) {
@@ -507,13 +518,38 @@ static void mt7996_mcu_rx_all_sta_info_event(struct mt7996_dev *dev, struct sk_buff *skb) { struct mt7996_mcu_all_sta_info_event *res; +u32 elem_size; +u16 sta_num;u16 i; +if (skb->len <sizeof (struct mt7996_mcu_rxd )) +return ; +skb_pull (skb,sizeof (struct mt7996_mcu_rxd )); res = (struct mt7996_mcu_all_sta_info_event *)skb->data; +if (skb->len <sizeof (*res)) +return ; + + sta_num =le16_to_cpu (res->sta_num); +switch (le16_to_cpu (res->tag)) { +case UNI_ALL_STA_TXRX_RATE : + elem_size =sizeof (res->rate[0 ]); +break ; +case UNI_ALL_STA_TXRX_ADM_STAT : + elem_size =sizeof (res->adm_stat[0 ]); +break ; +case UNI_ALL_STA_TXRX_MSDU_COUNT : + elem_size =sizeof (res->msdu_cnt[0 ]); +break ; +default : +return ; + } + +if (sta_num > (skb->len -sizeof (*res)) / elem_size) + sta_num = (skb->len -sizeof (*res)) / elem_size; -for (i =0 ; i <le16_to_cpu (res->sta_num); i++) { +for (i =0 ; i < sta_num; i++) {u8 ac;u16 wlan_idx;struct mt76_wcid *wcid;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 950/1756 wifi: mt76: mt7915: unregister thermal cooling device on hwmon failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Felix Fietkau <[email protected]>
[ Upstream commit b8286bc7fe520e7117e7b6e1a1fd4c0df439aa3a ]
mt7915_thermal_init() registered the thermal cooling device and its sysfs link, then returned the hwmon registration error without undoing them. The cooling device (not devm-managed) and the link then leaked, and its callbacks referenced the freed phy. Unregister the cooling device before returning the error.
--- drivers/net/wireless/mediatek/mt76/mt7915/init.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7915/init.c +6 -1
@@ -215,7 +215,12 @@ static int mt7915_thermal_init(struct mt7915_phy *phy) hwmon =devm_hwmon_device_register_with_groups (&wiphy->dev, name, phy, mt7915_hwmon_groups); -return PTR_ERR_OR_ZERO (hwmon); +if (IS_ERR (hwmon)) { +mt7915_unregister_thermal (phy); +return PTR_ERR (hwmon); + } + +return 0 ; } static void mt7915_led_set_config(struct led_classdev *led_cdev,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 951/1756 wifi: mt76: mt7915: guard firmware memory dump write on disabled memdump
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Felix Fietkau <[email protected]>
[ Upstream commit decf5142c2d4c295684da8644d4cb93dcf956c5d ]
mt7915_coredump_build()/mt7996_coredump_build() wrote dump_mem->len unconditionally, but the allocation only reserves room for the memory dump header when coredump_memdump is enabled and memdump_buf_len is non-zero. In the default configuration the allocation ends right after the fixed header, so the write landed one struct past the buffer. Only populate the memory-dump section when it was actually allocated.
--- drivers/net/wireless/mediatek/mt76/mt7915/coredump.c | 7 ++++--- drivers/net/wireless/mediatek/mt76/mt7996/coredump.c | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7915/coredump.c +4 -3
@@ -345,11 +345,12 @@ static struct mt7915_coredump *mt7915_coredump_build(struct mt7915_dev *dev)mt7915_coredump_fw_stack (dev, dump, exception);/* gather memory content */ - dump_mem = (struct mt7915_coredump_mem *)(buf + sofar); - dump_mem->len = crash_data->memdump_buf_len; -if (coredump_memdump && crash_data->memdump_buf_len) +if (coredump_memdump && crash_data->memdump_buf_len) { + dump_mem = (struct mt7915_coredump_mem *)(buf + sofar); + dump_mem->len = crash_data->memdump_buf_len;memcpy (dump_mem->data, crash_data->memdump_buf, crash_data->memdump_buf_len); + }mutex_unlock (&dev->dump_mutex);
drivers/net/wireless/mediatek/mt76/mt7996/coredump.c +4 -3
@@ -202,11 +202,12 @@ static struct mt7996_coredump *mt7996_coredump_build(struct mt7996_dev *dev)mt7996_coredump_fw_stack (dev, dump, exception);/* gather memory content */ - dump_mem = (struct mt7996_coredump_mem *)(buf + sofar); - dump_mem->len = crash_data->memdump_buf_len; -if (coredump_memdump && crash_data->memdump_buf_len) +if (coredump_memdump && crash_data->memdump_buf_len) { + dump_mem = (struct mt7996_coredump_mem *)(buf + sofar); + dump_mem->len = crash_data->memdump_buf_len;memcpy (dump_mem->data, crash_data->memdump_buf, crash_data->memdump_buf_len); + }mutex_unlock (&dev->dump_mutex);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 952/1756 wifi: mt76: mt7921: fix lock inversion between dev->mutex and iflist_mtx
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Devin Wittmayer <[email protected]>
[ Upstream commit 3dcb98c5cb51a70750ae8dc006d6d787ca09f425 ]
mt7921_config() holds dev->mutex across ieee80211_iterate_active_interfaces(), which takes local->iflist_mtx. mac80211 uses the opposite order: ieee80211_del_virtual_monitor() holds iflist_mtx while calling drv_unassign_vif_chanctx(), and mt792x_unassign_vif_chanctx() takes dev->mutex.
Deleting a monitor interface that has a channel assigned reaches the second order and lockdep reports the cycle. The driver side of it:
-> #1 (&local->iflist_mtx){+.+.}-{4:4}:
__mutex_lock+0xda/0x1070
ieee80211_iterate_interfaces+0x34/0x70 [mac80211]
mt7921_config+0xb8/0xe0 [mt7921_common]
drv_config+0x63/0x1d0 [mac80211].config is only reached through drv_config(), which asserts the wiphy mutex, so ieee80211_iterate_active_interfaces_mtx() can be used. It walks the same list under the wiphy mutex and never takes iflist_mtx, which drops the driver's dev->mutex -> iflist_mtx edge.
--- drivers/net/wireless/mediatek/mt76/mt7921/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7921/main.c +3 -3
@@ -645,9 +645,9 @@ static int mt7921_config(struct ieee80211_hw *hw, u32 changed) }if (changed &IEEE80211_CONF_CHANGE_MONITOR ) { -ieee80211_iterate_active_interfaces (hw, -IEEE80211_IFACE_ITER_RESUME_ALL , - mt7921_sniffer_interface_iter, dev); +ieee80211_iterate_active_interfaces_mtx (hw, +IEEE80211_IFACE_ITER_RESUME_ALL , + mt7921_sniffer_interface_iter, dev); } out:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 953/1756 wifi: mt76: mt7925: fix lock inversion between dev->mutex and iflist_mtx
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Devin Wittmayer <[email protected]>
[ Upstream commit 3208623121309a42f878364aff3c770f597d6a70 ]
mt7925_config() has the same inversion as mt7921_config(): it holds dev->mutex across ieee80211_iterate_active_interfaces(), which takes local->iflist_mtx, while mac80211 calls drv_unassign_vif_chanctx() with iflist_mtx already held.
.config is only reached through drv_config(), which asserts the wiphy mutex, so use ieee80211_iterate_active_interfaces_mtx() here too.
--- drivers/net/wireless/mediatek/mt76/mt7925/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +3 -3
@@ -792,9 +792,9 @@ static int mt7925_config(struct ieee80211_hw *hw, u32 changed) }if (changed &IEEE80211_CONF_CHANGE_MONITOR ) { -ieee80211_iterate_active_interfaces (hw, -IEEE80211_IFACE_ITER_RESUME_ALL , - mt7925_sniffer_interface_iter, dev); +ieee80211_iterate_active_interfaces_mtx (hw, +IEEE80211_IFACE_ITER_RESUME_ALL , + mt7925_sniffer_interface_iter, dev); } out:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 954/1756 wifi: mt76: mt7921: check drv_pmctrl return in the PCIe reset path
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Devin Wittmayer <[email protected]>
[ Upstream commit 75673ab3c0e4186628e0a76b94443cddfbeca255 ]
mt7921e_mac_reset() ignores the return value of mt792xe_mcu_drv_pmctrl(). When the driver-own handshake fails, __mt792xe_mcu_drv_pmctrl() returns -EIO without reinitialising WPDMA or clearing MT76_STATE_PM, and the reset carries on: it writes the interrupt enable registers, cycles NAPI, resets WPDMA and downloads firmware to a chip the driver does not own.
Return the error instead. The call is the first statement in the function, before any teardown, so nothing needs unwinding.
--- drivers/net/wireless/mediatek/mt76/mt7921/pci_mac.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7921/pci_mac.c +3 -1
@@ -57,7 +57,9 @@ int mt7921e_mac_reset(struct mt792x_dev *dev) {int i, err; -mt792xe_mcu_drv_pmctrl (dev); + err =mt792xe_mcu_drv_pmctrl (dev); +if (err) +return err;mt76_connac_free_pending_tx_skbs (&dev->pm,NULL );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 955/1756 wifi: mt76: mt7925: check drv_pmctrl return in the PCIe reset path
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Devin Wittmayer <[email protected]>
[ Upstream commit d12a54be2604ecd23a1e9ac863583e34034aadde ]
mt7925e_mac_reset() ignores the return value of mt792xe_mcu_drv_pmctrl(), unlike the two pmctrl calls later in the same function. When the driver-own handshake fails, __mt792xe_mcu_drv_pmctrl() returns -EIO without reinitialising WPDMA or clearing MT76_STATE_PM, and the reset carries on: it writes the interrupt enable registers, cycles NAPI, resets WPDMA and calls mt7925_run_firmware() on a chip the driver does not own.
Return the error instead. The call is the first statement in the function, before MT76_RESET is set and before the TX worker and NAPI are disabled, so nothing needs unwinding.
--- drivers/net/wireless/mediatek/mt76/mt7925/pci_mac.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7925/pci_mac.c +3 -1
@@ -72,7 +72,9 @@ int mt7925e_mac_reset(struct mt792x_dev *dev)const struct mt792x_irq_map *irq_map = dev->irq_map;int i, err; -mt792xe_mcu_drv_pmctrl (dev); + err =mt792xe_mcu_drv_pmctrl (dev); +if (err) +return err;mt76_connac_free_pending_tx_skbs (&dev->pm,NULL );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 956/1756 wifi: mt76: mt7925: restore the reset state when fw_pmctrl fails
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Felix Fietkau <[email protected]>
[ Upstream commit 8d2f5990cd429a2fe5fff05f7acf84d6799d4324 ]
mt7925e_mac_reset() returns directly when mt792xe_mcu_fw_pmctrl() fails, leaving MT76_RESET set and the TX worker parked. Every other error path jumps to out, which clears both. mt7925_mac_reset_work() clears neither, so once every reset attempt fails there, TX stays blocked until another reset succeeds.
Jump to out instead.
--- drivers/net/wireless/mediatek/mt76/mt7925/pci_mac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7925/pci_mac.c +1 -1
@@ -122,7 +122,7 @@ int mt7925e_mac_reset(struct mt792x_dev *dev) err =mt792xe_mcu_fw_pmctrl (dev);if (err) -return err; + goto out; err =__mt792xe_mcu_drv_pmctrl (dev);if (err)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 957/1756 wifi: mt76: mt7921: fix the lock inversion in suspend and resume
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Devin Wittmayer <[email protected]>
[ Upstream commit 0e6472108d51a42272332f5b6a95871244b64301 ]
Same inversion as the config path, same one word fix, missed the first time. Both are called with the wiphy mutex held, so the walk can rely on that instead of taking the list mutex.
No new splat: same class pair as the accepted fix, and lockdep reports a pair once per boot.
--- drivers/net/wireless/mediatek/mt76/mt7921/main.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7921/main.c +8 -8
@@ -1136,10 +1136,10 @@ static int mt7921_suspend(struct ieee80211_hw *hw,mt792x_mutex_acquire (dev);clear_bit (MT76_STATE_RUNNING , &phy->mt76->state); -ieee80211_iterate_active_interfaces (hw, -IEEE80211_IFACE_ITER_RESUME_ALL , - mt7921_mcu_set_suspend_iter, - &dev->mphy); +ieee80211_iterate_active_interfaces_mtx (hw, +IEEE80211_IFACE_ITER_RESUME_ALL , + mt7921_mcu_set_suspend_iter, + &dev->mphy);mt792x_mutex_release (dev);
@@ -1154,10 +1154,10 @@ static int mt7921_resume(struct ieee80211_hw *hw)mt792x_mutex_acquire (dev);set_bit (MT76_STATE_RUNNING , &phy->mt76->state); -ieee80211_iterate_active_interfaces (hw, -IEEE80211_IFACE_ITER_RESUME_ALL , - mt76_connac_mcu_set_suspend_iter, - &dev->mphy); +ieee80211_iterate_active_interfaces_mtx (hw, +IEEE80211_IFACE_ITER_RESUME_ALL , + mt76_connac_mcu_set_suspend_iter, + &dev->mphy);ieee80211_queue_delayed_work (hw, &phy->mt76->mac_work, MT792x_WATCHDOG_TIME);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 958/1756 wifi: mt76: mt7925: fix the lock inversion in suspend and resume
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Devin Wittmayer <[email protected]>
[ Upstream commit a105a9fe9a07a56d1e0b5a6978a49cde2ac7e7be ]
Same as the previous patch, other driver.
--- drivers/net/wireless/mediatek/mt76/mt7925/main.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +8 -8
@@ -1543,10 +1543,10 @@ static int mt7925_suspend(struct ieee80211_hw *hw,mt792x_mutex_acquire (dev);clear_bit (MT76_STATE_RUNNING , &phy->mt76->state); -ieee80211_iterate_active_interfaces (hw, -IEEE80211_IFACE_ITER_RESUME_ALL , - mt7925_mcu_set_suspend_iter, - &dev->mphy); +ieee80211_iterate_active_interfaces_mtx (hw, +IEEE80211_IFACE_ITER_RESUME_ALL , + mt7925_mcu_set_suspend_iter, + &dev->mphy);mt792x_mutex_release (dev);
@@ -1561,10 +1561,10 @@ static int mt7925_resume(struct ieee80211_hw *hw)mt792x_mutex_acquire (dev);set_bit (MT76_STATE_RUNNING , &phy->mt76->state); -ieee80211_iterate_active_interfaces (hw, -IEEE80211_IFACE_ITER_RESUME_ALL , - mt7925_mcu_set_suspend_iter, - &dev->mphy); +ieee80211_iterate_active_interfaces_mtx (hw, +IEEE80211_IFACE_ITER_RESUME_ALL , + mt7925_mcu_set_suspend_iter, + &dev->mphy);ieee80211_queue_delayed_work (hw, &phy->mt76->mac_work, MT792x_WATCHDOG_TIME);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 959/1756 wifi: mt76: mt7925: honour mac80211s FIF_FCSFAIL instead of hardcoding drop_err
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mark Anthony Agarro <[email protected]>
[ Upstream commit 31b53a9c4ada2ce49201ed0da0105819acfd86bf ]
mt7925_mcu_config_sniffer() hardcodes drop_err = 1, ignoring what mac80211 actually requested via configure_filter(). FIF_FCSFAIL is computed there but discarded instead of persisted.
Persist the FCSFAIL bit on the phy in mt7925_configure_filter() and read it back in mt7925_mcu_config_sniffer() to derive drop_err, so the firmware sniffer only passes through unfiltered/marginal frames when a monitor listener actually requested them.
mt7925_mcu_config_sniffer() is only reached from mt7925_change_chanctx(), which is itself only exercised on a monitor-mode chanctx, so this stays scoped to monitor mode.
--- drivers/net/wireless/mediatek/mt76/mt7925/main.c | 7 +++---- drivers/net/wireless/mediatek/mt76/mt7925/mcu.c | 2 +- drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h | 5 +++++ drivers/net/wireless/mediatek/mt76/mt792x.h | 1 + 4 files changed, 10 insertions(+), 5 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +3 -4
@@ -808,11 +808,8 @@ static void mt7925_configure_filter(struct ieee80211_hw *hw, unsigned int *total_flags, u64 multicast) { -#define MT7925_FILTER_FCSFAIL BIT(2) -#define MT7925_FILTER_CONTROL BIT(5) -#define MT7925_FILTER_OTHER_BSS BIT(6) -#define MT7925_FILTER_ENABLE BIT(31)struct mt792x_dev *dev =mt792x_hw_dev (hw); +struct mt792x_phy *phy =mt792x_hw_phy (hw);u32 flags =MT7925_FILTER_ENABLE ;#define MT7925_FILTER (_fif, _type) do { \
@@ -824,6 +821,8 @@ static void mt7925_configure_filter(struct ieee80211_hw *hw,MT7925_FILTER (FIF_CONTROL ,CONTROL );MT7925_FILTER (FIF_OTHER_BSS ,OTHER_BSS ); + phy->rxfilter = flags; +mt792x_mutex_acquire (dev);mt7925_mcu_set_rxfilter (dev, flags,0 ,0 );mt792x_mutex_release (dev);
drivers/net/wireless/mediatek/mt76/mt7925/mcu.c +1 -1
@@ -2180,7 +2180,7 @@ int mt7925_mcu_config_sniffer(struct mt792x_vif *vif, .len = cpu_to_le16(sizeof(req.tlv)), .control_ch = chandef->chan->hw_value, .center_ch = ieee80211_frequency_to_channel(freq1), - .drop_err = 1, + .drop_err = !(vif->phy->rxfilter & MT7925_FILTER_FCSFAIL), }, };
drivers/net/wireless/mediatek/mt76/mt7925/mt7925.h +5 -0
@@ -7,6 +7,11 @@#include "../mt792x.h" #include "regs.h" +#define MT7925_FILTER_FCSFAIL BIT(2) +#define MT7925_FILTER_CONTROL BIT(5) +#define MT7925_FILTER_OTHER_BSS BIT(6) +#define MT7925_FILTER_ENABLE BIT(31) +#define MT7925_BEACON_RATES_TBL 25#define MT7925_TX_RING_SIZE 2048
drivers/net/wireless/mediatek/mt76/mt792x.h +1 -0
@@ -148,6 +148,7 @@ struct mt792x_phy {s16 coverage_class;u8 slottime; +u32 rxfilter;u32 rx_ampdu_ts;u32 ampdu_ref;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 960/1756 wifi: mt76: mt7921: honour FIF_FCSFAIL instead of hardcoding drop_err
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Devin Wittmayer <[email protected]>
[ Upstream commit f8794eb3ff6dedbba0337c5197626b62da0ef057 ]
When a monitor interface asks to see frames that failed their checksum, mac80211 passes the request down to the driver. mt7921 works out the answer, sends it to the firmware as a receive filter, and then configures the sniffer with a hardcoded byte telling it to drop those frames anyway. The answer is used once and never kept, so the sniffer never gets to see it.
That matters to anyone using monitor mode to judge a link honestly, which is most of the reason to be in monitor mode at all.
Mark Anthony Agarro posted the same change for mt7925: keep what mac80211 asked for on the phy, and read it back when the sniffer is configured. This does that for mt7921, and applies on top of it, since that patch is what adds the field.
https://lore.kernel.org/linux-wireless/[email protected]/
The stored value is read in one place only, configuring the sniffer, which has a single caller, and that call sits inside a branch reached only by a monitor interface. Nothing else changes.
Measured on an MT7922 with a read-only probe on the command as the driver sends it, so these are the driver's own bytes rather than an inference from what came back:
request arm drop_err none stock 1 1 1 1 none patched 1 1 1 1 fcsfail stock 1 1 fcsfail patched 0 0
Stock sends the drop byte whether or not anyone asked for it. Patched sends it only when nobody did. Withdrawing the request and making it again inside one driver load moves the byte back and forth, 0 then 1 then 0 across three changes, so nothing sticks once set.
If it does appear to stick when trying this against an MT7927, that is mac80211 rather than the driver. It raises the filter count unconditionally when a monitor comes up, but skips lowering it again for drivers that set NO_VIRTUAL_MONITOR, and that is the only chip in this family which does.
--- drivers/net/wireless/mediatek/mt76/mt7921/main.c | 8 +++----- drivers/net/wireless/mediatek/mt76/mt7921/mcu.c | 2 +- drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h | 5 +++++ 3 files changed, 9 insertions(+), 6 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7921/main.c +3 -5
@@ -661,12 +661,8 @@ static void mt7921_configure_filter(struct ieee80211_hw *hw, unsigned int *total_flags, u64 multicast) { -#define MT7921_FILTER_FCSFAIL BIT(2) -#define MT7921_FILTER_CONTROL BIT(5) -#define MT7921_FILTER_OTHER_BSS BIT(6) -#define MT7921_FILTER_ENABLE BIT(31) -struct mt792x_dev *dev =mt792x_hw_dev (hw); +struct mt792x_phy *phy =mt792x_hw_phy (hw);u32 flags =MT7921_FILTER_ENABLE ;#define MT7921_FILTER (_fif, _type) do { \
@@ -678,6 +674,8 @@ static void mt7921_configure_filter(struct ieee80211_hw *hw,MT7921_FILTER (FIF_CONTROL ,CONTROL );MT7921_FILTER (FIF_OTHER_BSS ,OTHER_BSS ); + phy->rxfilter = flags; +mt792x_mutex_acquire (dev);mt7921_mcu_set_rxfilter (dev, flags,0 ,0 );mt792x_mutex_release (dev);
drivers/net/wireless/mediatek/mt76/mt7921/mcu.c +1 -1
@@ -1224,7 +1224,7 @@ int mt7921_mcu_config_sniffer(struct mt792x_vif *vif, .len = cpu_to_le16(sizeof(req.tlv)), .control_ch = chandef->chan->hw_value, .center_ch = ieee80211_frequency_to_channel(freq1), - .drop_err = 1, + .drop_err = !(vif->phy->rxfilter & MT7921_FILTER_FCSFAIL), }, };if (chandef->chan->band <ARRAY_SIZE (ch_band))
drivers/net/wireless/mediatek/mt76/mt7921/mt7921.h +5 -0
@@ -7,6 +7,11 @@#include "../mt792x.h" #include "regs.h" +#define MT7921_FILTER_FCSFAIL BIT(2) +#define MT7921_FILTER_CONTROL BIT(5) +#define MT7921_FILTER_OTHER_BSS BIT(6) +#define MT7921_FILTER_ENABLE BIT(31) +#define MT7921_MAX_AID 20#define MT7921_TX_RING_SIZE 2048
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 961/1756 wifi: mt76: mt7915: publish wcid before MCU add commands
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ryan Leung <[email protected]>
[ Upstream commit a2d1c02c59f84e982179751bced5fb2fd5bb4212 ]
mt7915_add_interface() enables the BSS/STA in firmware via mt7915_mcu_add_bss_info() and mt7915_mcu_add_sta() before publishing dev->mt76.wcid[idx] with rcu_assign_pointer(). Firmware can start generating tx-status/tx-free events referencing that wcid as soon as it processes those MCU commands, but mt76's rx/tx-free handlers (e.g. mt7915_mac_tx_free()) look up dev->mt76.wcid[idx] to service them, and won't find it published yet. This can lead to memory corruption and kernel crashes shortly after an AP interface is brought up.
This ordering was introduced by commit 8e3e7567b8c1 ("mt76: mt7915: add sta_rec with EXTRA_INFO_NEW for the first time only"):mt7915_mcu_add_sta() derived its "newly added" flag from !rcu_access_pointer(dev->mt76.wcid[idx]), so the publish had to happen after that call. Commit 33eb14f10290 ("wifi: mt76: mt7915: use mac80211 .sta_state op") later replaced that flag with a caller-supplied newly argument to mt7915_mcu_add_sta(), now simply hardcoded to true, so the ordering is no longer required.
Move the rcu_assign_pointer() before the MCU add_bss_info/add_sta calls, so that the wcid is visible to lookups before firmware is told it's live. This makes the ordering symmetric with mt7915_remove_interface(), which keeps the pointer published until after the MCU disable commands have been issued.
--- drivers/net/wireless/mediatek/mt76/mt7915/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7915/main.c +1 -1
@@ -275,9 +275,9 @@ static int mt7915_add_interface(struct ieee80211_hw *hw,mt7915_init_bitrate_mask (vif);memset (&mvif->cap,-1 ,sizeof (mvif->cap)); +rcu_assign_pointer (dev->mt76.wcid[idx], &mvif->sta.wcid);mt7915_mcu_add_bss_info (phy, vif, true);mt7915_mcu_add_sta (dev, vif,NULL ,CONN_STATE_PORT_SECURE , true); -rcu_assign_pointer (dev->mt76.wcid[idx], &mvif->sta.wcid);mutex_unlock (&dev->mt76.mutex);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 962/1756 wifi: mt76: fix unlocked wcid check in mt76_tx_status_skb_add()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ryan Leung <[email protected]>
[ Upstream commit cfb05250ded4d6de09dfd273c2a72092f48b55a3 ]
mt76_tx_status_skb_add() checks rcu_access_pointer(dev->wcid[wcid->idx]) before taking dev->status_lock, then allocates a pktid afterwards. A concurrent mt76_wcid_cleanup() can run between the check and the lock, letting a stale wcid be re-added to dev->wcid_list after teardown. Worse, the check only tests for a non-NULL slot, so it also passes if a different wcid has since been published at the same idx.
Move the check under status_lock, alongside idr_alloc(), and compare identity (rcu_access_pointer(dev->wcid[wcid->idx]) != wcid) instead of just testing for non-NULL, so that a reused index is correctly rejected.
--- drivers/net/wireless/mediatek/mt76/tx.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/tx.c +6 -1
@@ -129,7 +129,7 @@ mt76_tx_status_skb_add(struct mt76_dev *dev, struct mt76_wcid *wcid,memset (cb,0 ,sizeof (*cb)); -if (!wcid || !rcu_access_pointer (dev->wcid[wcid->idx])) +if (!wcid)return MT_PACKET_ID_NO_ACK ;if (info->flags &IEEE80211_TX_CTL_NO_ACK )
@@ -147,6 +147,11 @@ mt76_tx_status_skb_add(struct mt76_dev *dev, struct mt76_wcid *wcid,spin_lock_bh (&dev->status_lock); +if (rcu_access_pointer (dev->wcid[wcid->idx]) != wcid) { + pid =MT_PACKET_ID_NO_ACK ; + goto out; + } + pid =idr_alloc (&wcid->pktid, skb,MT_PACKET_ID_FIRST ,MT_PACKET_ID_MASK ,GFP_ATOMIC );if (pid <0 ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 963/1756 wifi: mt76: fix wcid teardown ordering in mt76_reset_device()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ryan Leung <[email protected]>
[ Upstream commit 5cebbd7a87df834efe002c8e54211e6adc99703a ]
mt76_reset_device() tears down each wcid's pktid idr before clearing dev->wcid[i], which is the reverse of the ordering used on the sta removal path. Until the pointer is cleared, a concurrent lookup under status_lock can still find the wcid and access its already destroyed idr.
Clear dev->wcid[i] before calling mt76_wcid_cleanup(), reproducing the ordering mac80211 already enforces for normal sta removal (where mt76_sta_pre_rcu_remove() clears dev->wcid[idx] before mt76_wcid_cleanup() runs via the .sta_state callback).
--- drivers/net/wireless/mediatek/mt76/mac80211.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mac80211.c +1 -1
@@ -812,8 +812,8 @@ void mt76_reset_device(struct mt76_dev *dev)continue ; wcid->sta =0 ; -mt76_wcid_cleanup (dev, wcid);rcu_assign_pointer (dev->wcid[i],NULL ); +mt76_wcid_cleanup (dev, wcid); }rcu_read_unlock ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 964/1756 wifi: mt76: mt76x02: validate RX padding before use
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiale Yao <[email protected]>
[ Upstream commit baf375ca58eaa24503f9febac75c056852694c3a ]
The RX descriptor provides L2 and PN padding lengths that are used to locate the CCMP IV and determine how many bytes to remove from the packet. These lengths are not checked against the received skb length before the IV is read or mt76x02_remove_hdr_pad() is called.
Reject frames whose IV does not fit within the skb or whose header padding would extend past the end of the skb.
--- drivers/net/wireless/mediatek/mt76/mt76x02_mac.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt76x02_mac.c +9 -2
@@ -818,9 +818,13 @@ int mt76x02_mac_process_rx(struct mt76x02_dev *dev, struct sk_buff *skb, len =FIELD_GET (MT_RXWI_CTL_MPDU_LEN , ctl); pn_len =FIELD_GET (MT_RXINFO_PN_LEN , rxinfo);if (pn_len) { -int offset =ieee80211_get_hdrlen_from_skb (skb) + pad_len; -u8 *data = skb->data + offset; +unsigned int offset =ieee80211_get_hdrlen_from_skb (skb) + pad_len; +u8 *data; +if (offset +8 > skb->len) +return -EINVAL ; + + data = skb->data + offset; status->iv[0 ] = data[7 ]; status->iv[1 ] = data[6 ]; status->iv[2 ] = data[5 ];
@@ -840,6 +844,9 @@ int mt76x02_mac_process_rx(struct mt76x02_dev *dev, struct sk_buff *skb, } } +if (pad_len +ieee80211_get_hdrlen_from_skb (skb) > skb->len) +return -EINVAL ; +mt76x02_remove_hdr_pad (skb, pad_len);if ((rxinfo &MT_RXINFO_BA ) && !(rxinfo &MT_RXINFO_NULL ))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 965/1756 wifi: mt76: mt7921: keep the join ROC until the station is authorized
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mark Anthony Agarro <[email protected]>
[ Upstream commit 6f591a4bb5d9a6a4a28f3f2fd77f394ddbcc4e05 ]
When an association succeeds mac80211 calls mgd_complete_tx(), and mt7921 aborts the join ROC there. The AP starts the 4-way handshake right away, so the abort lands where message 3 arrives. On an MT7922 this loses message 3 often enough to matter: the supplicant sends message 2 (acked), never receives message 3, and the connection ends with reason 15 (4WAY_HANDSHAKE_TIMEOUT) after about 3.3 s. The mt7925 capture in the linked issue shows the same ordering: abort, message 2 out, then message 3 retried by the AP several times without an answer.
Keep the ROC after a successful (re)association on a station interface and release it when the station is authorized, on disassociation, or when the station is removed. The ROC timer still ends it if none of that happens. The state lives in a flag in struct mt792x_vif so that an unrelated ROC, for example a user remain-on-channel, is never aborted by the authorize hook.
Tested on an MT7922 (PCIe), kernel 7.3.0-rc4, WPA3-SAE AP, two rounds of 20 disconnect/reconnect cycles per build in the same boot, unpatched and patched in ABAB order:
unpatched 34 of 73 association attempts: M1 rx, M2 tx acked,
no M3, reason 15
patched 0 of 40
Delaying the abort by 20 ms before it made no difference (8 of 29), and delaying 20 ms after it removed the failures (0 of 20), so what matters is where the abort lands relative to the handshake. The firmware behaviour after the abort is inferred from these outcomes, not observed directly.
Not tested: MT7921 and other connac2 parts, USB and SDIO, APs other than the one above, open or WPA2 networks, scheduled scan, suspend and resume.
--- .../net/wireless/mediatek/mt76/mt7921/main.c | 17 +++++++++++++++++ drivers/net/wireless/mediatek/mt76/mt792x.h | 1 + 2 files changed, 18 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7921/main.c +17 -0
@@ -853,6 +853,12 @@ int mt7921_mac_sta_event(struct mt76_dev *mdev, struct ieee80211_vif *vif,if (sta->aid >MT7921_MAX_AID )return -ENOENT ; +if (mvif->roc_join_held && !sta->tdls && + (ev ==MT76_STA_EVENT_AUTHORIZE || ev ==MT76_STA_EVENT_DISASSOC )) { + mvif->roc_join_held = false; +mt7921_abort_roc (mvif->phy, mvif); + } +if (ev !=MT76_STA_EVENT_ASSOC )return 0 ;
@@ -894,6 +900,7 @@ void mt7921_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; mvif->wep_sta =NULL ; + mvif->roc_join_held = false;ewma_rssi_init (&mvif->bss_conf.rssi);if (!sta->tdls) mt76_connac_mcu_uni_add_bss(&dev->mphy, vif,
@@ -1417,6 +1424,16 @@ static void mt7921_mgd_complete_tx(struct ieee80211_hw *hw, {struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; +/* Keep the join ROC until the station is authorized, so that it +* covers the 4-way handshake. mt7921_mac_sta_event() releases it. +*/ +if (vif->type ==NL80211_IFTYPE_STATION && info->success && + (info->subtype ==IEEE80211_STYPE_ASSOC_REQ || + info->subtype ==IEEE80211_STYPE_REASSOC_REQ )) { + mvif->roc_join_held = true; +return ; + } +mt7921_abort_roc (mvif->phy, mvif); }
drivers/net/wireless/mediatek/mt76/mt792x.h +1 -0
@@ -131,6 +131,7 @@ struct mt792x_vif {struct mt792x_sta *wep_sta;struct mt792x_phy *phy; +bool roc_join_held;/* join ROC kept until the STA is authorized */ u16 valid_links;u8 deflink_id; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 966/1756 wifi: mt76: mt7925: keep the join ROC until the station is authorized
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mark Anthony Agarro <[email protected]>
[ Upstream commit ac22c8c723c62013dd45b74e32249fc877c86fe0 ]
When a non-MLO station associates, mgd_complete_tx() aborts the join ROC as soon as the association succeeds, which is right before the supplicant sends message 2 of the 4-way handshake. With the abort that close to message 2, the adapter acknowledges nothing the AP sends for the next several ms: the AP sends message 3 and its seven retries within about 5 ms, none is acknowledged, and the handshake ends with reason 15 (4WAY_HANDSHAKE_TIMEOUT).
Keep the ROC after a successful (re)association on a non-MLD station interface and release it when the station is authorized, on disassociation, or when the station is removed. The ROC timer still ends it if none of that happens. MLD interfaces keep the old behaviour: there the ROC that is active at this point is the MLO ROC set up by mt7925_mac_set_links(), and holding it makes mt7925_set_mlo_roc() fail with -EBUSY in the link activation work, which leaves one link instead of two.
Tested by a reporter on an MT7925U (USB) against a FRITZ!Box 5690 Pro on a 6 GHz-only, non-MLO SSID, kernel 7.2.3, from traces and monitor captures taken in separate runs:
handshakes first M3 acked abort before M2
unpatched 8 of 84 0 of 83 84 of 84
this patch 30 of 30 31 of 31 0 of 30
With the patch the AP sends message 3 once and the adapter acknowledges it straight away; the ROC is released right after the station is authorized. A 20 ms delay after the abort instead of this change gave 15 of 15, which points at the abort timing and not at the delay.
Tested here on an MT7925 and an MT7927 (PCIe), kernel 7.3.0-rc4: on a non-MLO SSID neither build showed the failure (1 stalled handshake in 110 unpatched, none patched), so no effect could be measured there. On an MLO connection the change is inert: 16 of 16 link activations succeeded in two rounds per build, with two active links and the same ROC order as before.
Not tested: other APs, other USB parts, MT7927 over USB, MLO connections beyond the check above.
--- .../net/wireless/mediatek/mt76/mt7925/main.c | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7925/main.c +21 -0
@@ -1134,6 +1134,13 @@ int mt7925_mac_sta_event(struct mt76_dev *mdev, struct ieee80211_vif *vif, struct ieee80211_sta *sta, enum mt76_sta_event ev) {struct ieee80211_link_sta *link_sta = &sta->deflink; +struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; + +if (mvif->roc_join_held && !sta->tdls && + (ev ==MT76_STA_EVENT_AUTHORIZE || ev ==MT76_STA_EVENT_DISASSOC )) { + mvif->roc_join_held = false; +mt7925_abort_roc (mvif->phy, &mvif->bss_conf); + }if (ev !=MT76_STA_EVENT_ASSOC )return 0 ;
@@ -1287,6 +1294,7 @@ void mt7925_mac_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; mvif->wep_sta =NULL ; + mvif->roc_join_held = false;ewma_rssi_init (&mvif->bss_conf.rssi); } }
@@ -1899,6 +1907,19 @@ static void mt7925_mgd_complete_tx(struct ieee80211_hw *hw, {struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv; +/* Keep the join ROC until the station is authorized, so that it +* covers the 4-way handshake. mt7925_mac_sta_event() releases it. +* On MLD, the active ROC is the MLO ROC, which must be released +* before the link activation work sets its own. +*/ +if (vif->type ==NL80211_IFTYPE_STATION && !ieee80211_vif_is_mld (vif) && + info->success && + (info->subtype ==IEEE80211_STYPE_ASSOC_REQ || + info->subtype ==IEEE80211_STYPE_REASSOC_REQ )) { + mvif->roc_join_held = true; +return ; + } +mt7925_abort_roc (mvif->phy, &mvif->bss_conf); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 967/1756 wifi: mt76: usb: fix source overread in mt76u_copy
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiale Yao <[email protected]>
[ Upstream commit d435130cdd064b901d8ce5ada0322298e6a86a49 ]
mt76u_copy() rounds up len to a multiple of four and uses the rounded length as the bound for memcpy() from the source buffer. When the caller's length is not four-byte aligned, the final copy reads up to three bytes past the source buffer.
Keep the original length for the source copy and zero the remaining bytes in the transmit buffer so that the hardware access width remains four-byte aligned.
--- drivers/net/wireless/mediatek/mt76/usb.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
drivers/net/wireless/mediatek/mt76/usb.c +11 -5
@@ -160,8 +160,10 @@ static void mt76u_copy(struct mt76_dev *dev, u32 offset, {struct mt76_usb *usb = &dev->usb;const u8 *val = data; -int ret;int current_batch_size; +int len_aligned; +int copy_len; +int ret;int i =0 ;/* Assure that always a multiple of 4 bytes are copied,
@@ -169,12 +171,16 @@ static void mt76u_copy(struct mt76_dev *dev, u32 offset,* See: "mt76: round up length on mt76_wr_copy" * Commit 850e8f6fbd5d0003b0 */ - len =round_up (len,4 ); + len_aligned =round_up (len,4 );mutex_lock (&usb->usb_ctrl_mtx); -while (i < len) { - current_batch_size =min_t (int, usb->data_len, len - i); -memcpy (usb->data, val + i, current_batch_size); +while (i < len_aligned) { + current_batch_size =min_t (int, usb->data_len, len_aligned - i); + copy_len =min_t (int, current_batch_size, len - i); +memcpy (usb->data, val + i, copy_len); +if (copy_len < current_batch_size) +memset (usb->data + copy_len,0 , + current_batch_size - copy_len); ret = __mt76u_vendor_request(dev, MT_VEND_MULTI_WRITE, USB_DIR_OUT | USB_TYPE_VENDOR, 0, offset + i, usb->data,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 968/1756 wifi: mt76: mt7615: usb: fix source overread in mt7663u_copy
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiale Yao <[email protected]>
[ Upstream commit 0c2fcb5225361f71905697ef9db287b24bcc67cf ]
mt7663u_copy() rounds up len to a multiple of four and uses the rounded length as the bound for memcpy() from the source buffer. When the caller's length is not four-byte aligned, the final copy reads up to three bytes past the source buffer.
Keep the original length for the source copy and zero the remaining bytes in the transmit buffer so that the hardware access width remains four-byte aligned.
--- drivers/net/wireless/mediatek/mt76/mt7615/usb.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7615/usb.c +12 -5
@@ -58,15 +58,22 @@ static void mt7663u_copy(struct mt76_dev *dev, u32 offset, const void *data, int len) {struct mt76_usb *usb = &dev->usb; -int ret, i =0 , batch_len;const u8 *val = data; +int len_aligned; +int batch_len; +int copy_len; +int ret; +int i =0 ; - len =round_up (len,4 ); + len_aligned =round_up (len,4 );mutex_lock (&usb->usb_ctrl_mtx); -while (i < len) { - batch_len =min_t (int, usb->data_len, len - i); -memcpy (usb->data, val + i, batch_len); +while (i < len_aligned) { + batch_len =min_t (int, usb->data_len, len_aligned - i); + copy_len =min_t (int, batch_len, len - i); +memcpy (usb->data, val + i, copy_len); +if (copy_len < batch_len) +memset (usb->data + copy_len,0 , batch_len - copy_len); ret = __mt76u_vendor_request(dev, MT_VEND_WRITE_EXT, USB_DIR_OUT | USB_TYPE_VENDOR, (offset + i) >> 16, offset + i,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 969/1756 wifi: mt76: mt7603: dont drop short frames looped back on PS entry
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cristian Papa <[email protected]>
[ Upstream commit 9956c4cac9d3f479817d6fe6a057aef3e86defcf ]
When a station enters power save, mt7603 has the PSE redirect the frames still queued for it back to the host, and mt7603_rx_loopback_skb() parks them until the station wakes up.
The handler rejects every frame shorter than a four-address header (sizeof(struct ieee80211_hdr), 30 bytes) before looking at it. A BlockAck request is 20 bytes and a QoS-Null 26, so both are freed without a trace. Since commit b473c0e47f04 ("wifi: mt76: mt7603: fix tx queue of loopback packets"), a BAR would also be freed later as a frame that is not a bufferable MMPDU, although mac80211 buffers BARs for a sleeping station like any other unicast frame.
mac80211 queues the BAR with IEEE80211_TX_CTL_REQ_TX_STATUS, so it only learns about the loss when the tx status times out, and the recipient keeps waiting on its reorder window until then.
Check the length against the header length of the actual frame, and park a BlockAck request on the queue of its TID, behind the data frames it refers to.
Found on a TP-Link Archer XR500v (MT7603E) with a client whose Bluetooth coexistence toggles PM every ~15 ms under load. To test the change on its own, a temporary debugfs switch flipped between the old and the new checks every 30 seconds during a bidirectional TCP test, with counters on the loop-back path and on the tx status of BARs. With the old check, all 92 BARs that came back were freed, and 91 of the 544 BARs queued in those phases never got a tx status from the hardware. With this change, all 129 BARs that came back were parked and sent again, and 11 of 411 got no tx status. Throughput was the same with both checks.
--- .../net/wireless/mediatek/mt76/mt7603/dma.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7603/dma.c +17 -1
@@ -34,7 +34,7 @@ mt7603_rx_loopback_skb(struct mt7603_dev *dev, struct sk_buff *skb)int idx;u32 val; -if (skb->len <MT_TXD_SIZE +sizeof (struct ieee80211_hdr )) +if (skb->len <MT_TXD_SIZE +2 ) goto free; val =le32_to_cpu (txd[1 ]);
@@ -52,6 +52,9 @@ mt7603_rx_loopback_skb(struct mt7603_dev *dev, struct sk_buff *skb) sta = container_of(priv, struct ieee80211_sta, drv_priv); hdr = (struct ieee80211_hdr *)&skb->data[MT_TXD_SIZE ]; +if (skb->len <MT_TXD_SIZE +ieee80211_hdrlen (hdr->frame_control)) + goto free; + hwq = wmm_queue_map[IEEE80211_AC_BE ];if (ieee80211_is_data_qos (hdr->frame_control)) { tid = *ieee80211_get_qos_ctl(hdr) &
@@ -62,6 +65,19 @@ mt7603_rx_loopback_skb(struct mt7603_dev *dev, struct sk_buff *skb) }else if (ieee80211_is_data (hdr->frame_control)) {skb_set_queue_mapping (skb,IEEE80211_AC_BE ); hwq = wmm_queue_map[IEEE80211_AC_BE ]; + }else if (ieee80211_is_back_req (hdr->frame_control)) { +struct ieee80211_bar *bar = (struct ieee80211_bar *)hdr; + +if (skb->len <MT_TXD_SIZE +sizeof (*bar)) + goto free; + + tid = (le16_to_cpu (bar->control) & +IEEE80211_BAR_CTRL_TID_INFO_MASK ) >> +IEEE80211_BAR_CTRL_TID_INFO_SHIFT ; + tid &=IEEE80211_QOS_CTL_TAG1D_MASK ; + qid = tid_to_ac[tid]; + hwq = wmm_queue_map[qid]; +skb_set_queue_mapping (skb, qid); }else {skb_pull (skb,MT_TXD_SIZE );if (!ieee80211_is_bufferable_mmpdu (skb))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 970/1756 wifi: mt76: fix wcid->pktid corruption in mt76_wcid_cleanup()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ryan Leung <[email protected]>
[ Upstream commit 158c1145fe7ddd82914011a00de7cc3262616b16 ]
mt76_wcid_cleanup() releases dev->status_lock before calling idr_destroy(&wcid->pktid) to tear down the pktid idr. Meanwhile, mt76_tx_status_skb_add() from tx.c can concurrently insert into that same idr during tx completion handling:
spin_lock_bh(&dev->status_lock); pid = idr_alloc(&wcid->pktid, skb, MT_PACKET_ID_FIRST, MT_PACKET_ID_MASK, GFP_ATOMIC);
Since idr_destroy() runs outside the lock, it can execute concurrently with idr_alloc() on the same idr, corrupting its internal data structures. Because idr nodes are freed through the generic slab allocator, this corruption can resurface later as an unrelated-looking crash anywhere in the kernel that happens to reuse the same freed memory.
Fix this by calling idr_destroy() before releasing dev->status_lock, so that the table teardown and any concurrent insertion are mutually exclusive.
--- drivers/net/wireless/mediatek/mt76/mac80211.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mac80211.c +1 -2
@@ -1641,9 +1641,8 @@ void mt76_wcid_cleanup(struct mt76_dev *dev, struct mt76_wcid *wcid)mt76_tx_status_lock (dev, &list);mt76_tx_status_skb_get (dev, wcid,-1 , &list); -mt76_tx_status_unlock (dev, &list); -idr_destroy (&wcid->pktid); +mt76_tx_status_unlock (dev, &list);spin_lock_bh (&phy->tx_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 971/1756 wifi: mt76: mt7615: read MT7663 temperature from the correct offset
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ahmed Naseef <[email protected]>
[ Upstream commit 40217d8e6cba433a6ccb8c73737dd38b54dcc26f ]
On MT7663 the hwmon temp1_input attribute always reads 0.
mt7615_mcu_parse_response() takes the temperature from the first dword of the THERMAL_CTRL response payload, but MT7663 firmware reports it in the second one. On a DASAN H660GM-A (MT7663E, N9 firmware 7663mp1827) the request and its response are:
request: 00 00 00 00
response: 00 00 00 00 2a 00 00 00
0x2a is the reading, 42 degrees, while the driver returns the leading zero. mt7915 and mt7921 already pull sizeof(*rxd) + 4 for this command.
Restrict the extra pull to MT7663, as no MT7615 or MT7622 hardware was available to check whether their firmware uses the same layout.
--- drivers/net/wireless/mediatek/mt76/mt7615/mcu.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7615/mcu.c +2 -0
@@ -153,6 +153,8 @@ int mt7615_mcu_parse_response(struct mt76_dev *mdev, int cmd, ret = *skb->data; }else if (cmd ==MCU_EXT_CMD (THERMAL_CTRL )) {skb_pull (skb,sizeof (*rxd)); +if (is_mt7663 (mdev)) +skb_pull (skb,4 ); ret =le32_to_cpu (*(__le32 *)skb->data); }else if (cmd ==MCU_EXT_QUERY (RF_REG_ACCESS )) {skb_pull (skb,sizeof (*rxd));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 972/1756 wifi: mt76: mt7615: validate MCU response lengths
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit 356735fc612ea54062eb741ea15fa4ff7df4fc36 ]
mt7615_mcu_parse_response() reads the common response header before checking its size and then consumes command-specific fields after unchecked skb_pull() calls. A short firmware response can therefore be read beyond its current extent.
Validate the common header and each command-specific payload before reading it.
--- drivers/net/wireless/mediatek/mt76/mt7615/mcu.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7615/mcu.c +11 -0
@@ -145,6 +145,9 @@ int mt7615_mcu_parse_response(struct mt76_dev *mdev, int cmd, } rxd = (struct mt7615_mcu_rxd *)skb->data; +if (skb->len <sizeof (*rxd)) +return -EMSGSIZE ; +if (seq != rxd->seq)return -EAGAIN ;
@@ -152,11 +155,15 @@ int mt7615_mcu_parse_response(struct mt76_dev *mdev, int cmd,skb_pull (skb,sizeof (*rxd) -4 ); ret = *skb->data; }else if (cmd ==MCU_EXT_CMD (THERMAL_CTRL )) { +if (skb->len <sizeof (*rxd) + (is_mt7663 (mdev) ?8 :4 )) +return -EMSGSIZE ;skb_pull (skb,sizeof (*rxd));if (is_mt7663 (mdev))skb_pull (skb,4 ); ret =le32_to_cpu (*(__le32 *)skb->data); }else if (cmd ==MCU_EXT_QUERY (RF_REG_ACCESS )) { +if (skb->len <sizeof (*rxd) +8 +sizeof (__le32)) +return -EMSGSIZE ;skb_pull (skb,sizeof (*rxd)); ret =le32_to_cpu (*(__le32 *)&skb->data[8 ]); } else if (cmd == MCU_UNI_CMD(DEV_INFO_UPDATE) ||
@@ -167,12 +174,16 @@ int mt7615_mcu_parse_response(struct mt76_dev *mdev, int cmd, cmd == MCU_UNI_CMD(SUSPEND)) {struct mt76_connac_mcu_uni_event *event; +if (skb->len <sizeof (*rxd) +sizeof (*event)) +return -EMSGSIZE ;skb_pull (skb,sizeof (*rxd)); event = (struct mt76_connac_mcu_uni_event *)skb->data; ret =le32_to_cpu (event->status); } else if (cmd == MCU_CE_QUERY(REG_READ)) {struct mt76_connac_mcu_reg_event *event; +if (skb->len <sizeof (*rxd) +sizeof (*event)) +return -EMSGSIZE ;skb_pull (skb,sizeof (*rxd)); event = (struct mt76_connac_mcu_reg_event *)skb->data; ret = (int )le32_to_cpu (event->val);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 973/1756 wifi: mt76: feed the station RSSI average from the chain signals
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cristian Papa <[email protected]>
[ Upstream commit e1534fef1ae4df6e16401117394c26dbef84f361 ]
mt76_check_sta() adds status->signal of every received frame to the station's RSSI average, wcid->rssi, which mt76_get_min_avg_rssi() reads for the dynamic sensitivity of mt7603 and mt7615 and for the gain control of mt76x0 and mt76x2.
Since commit 4550fb9e9810 ("mt76: improve signal strength reporting"), drivers no longer set status->signal: mt76_rx_convert() computes it from the chain values when the frame is handed to mac80211, after mt76_check_sta() has run. Except on mt7921, which still sets it, the average is fed zeros. mt76_get_min_avg_rssi() then returns 0, so mt7603 and mt7615 leave the sensitivity at its default, and mt76x0 and mt76x2 fall back to -75 dBm for their gain settings.
Compute the signal from the chain values in mt76_check_sta() as well, as mt76_rx_convert() does. On mt7921, the average now follows the same combined value that mac80211 gets instead of the strongest chain.
Tested on a TP-Link Archer XR500v with one client, switching between the old and the new input every 30 seconds. On the MT7662E (mt76x2), the average the AGC works with was -75 dBm, its fallback, with the old input and -54 dBm with the new one, while iw reported -54 and -52 dBm for the station, and the AGC mostly used its low_gain 2 setting instead of 1. On the MT7603E, the station average was 0 with the old input and -41 dBm with the new one, while iw reported -42 and -41 dBm. The mt7603 sensitivity still stayed at its default: a separate bug keeps it from leaving 0.
--- drivers/net/wireless/mediatek/mt76/mac80211.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mac80211.c +4 -2
@@ -1375,6 +1375,7 @@ mt76_check_sta(struct mt76_dev *dev, struct sk_buff *skb)struct ieee80211_hw *hw;struct mt76_wcid *wcid = status->wcid;u8 tidno = status->qos_ctl &IEEE80211_QOS_CTL_TID_MASK ; +int signal;bool ps; hw =mt76_phy_hw (dev, status->phy_idx);
@@ -1392,8 +1393,9 @@ mt76_check_sta(struct mt76_dev *dev, struct sk_buff *skb) sta = container_of((void *)wcid, struct ieee80211_sta, drv_priv); -if (status->signal <=0 ) -ewma_signal_add (&wcid->rssi, -status->signal); + signal =mt76_rx_signal (status->chains, status->chain_signal); +if (signal <=0 && signal >-128 ) +ewma_signal_add (&wcid->rssi, -signal); wcid->inactive_count =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 974/1756 wifi: mt76: mt7996: fix PLE free page and AC queue register offsets
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Felix Fietkau <[email protected]>
[ Upstream commit c33af2e4622baafc56c565a13823f6b89d3f50db ]
The PLE register map in the MediaTek vendor driver places the free page counter, the free page head and tail, and the HIF group page status at 0x3a0, 0x3a4 and 0x3a8. The driver reads them at 0x380, 0x384 and 0x388, and the vendor map has the band 1 TXCMD queue empty status at 0x388. The same map has 0x100 bytes per AC for the station queue empty bitmaps, with the MT7992 extension register at offset 0x80. The driver uses 0x80, which cannot hold the 34 registers per AC of MT7996, so the hw-queues file reads AC1 to AC3 of a station from the wrong register.
Use the offsets of the vendor register map.
--- drivers/net/wireless/mediatek/mt76/mt7996/regs.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/regs.h +4 -4
@@ -121,12 +121,12 @@ enum offs_rev {#define MT_FL_Q2_CTRL MT_PLE(0x3e8)#define MT_FL_Q3_CTRL MT_PLE(0x3ec) -#define MT_PLE_FREEPG_CNT MT_PLE(0x380) -#define MT_PLE_FREEPG_HEAD_TAIL MT_PLE(0x384) +#define MT_PLE_FREEPG_CNT MT_PLE(0x3a0) +#define MT_PLE_FREEPG_HEAD_TAIL MT_PLE(0x3a4)#define MT_PLE_PG_HIF_GROUP MT_PLE(0x00c) -#define MT_PLE_HIF_PG_INFO MT_PLE(0x388) +#define MT_PLE_HIF_PG_INFO MT_PLE(0x3a8) -#define MT_PLE_AC_QEMPTY (ac, n) MT_PLE(0x600 + 0x80 * (ac) + ((n) << 2)) +#define MT_PLE_AC_QEMPTY (ac, n) MT_PLE(0x600 + 0x100 * (ac) + ((n) << 2))#define MT_PLE_AMSDU_PACK_MSDU_CNT (n) MT_PLE(0x10e0 + ((n) << 2))/* WF MDP TOP */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 975/1756 wifi: mt76: mt7996: disable the RX NAPIs before the DMA cleanup
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Crispin <[email protected]>
[ Upstream commit 7a5a3843178c61d99d939b231318692d08fff79b ]
mt7996_unregister_device() leaves the RX NAPIs enabled, so mt76_dma_cleanup() deletes enabled NAPIs and destroys page pools that are still bound to them. On rmmod, the kernel warns in __netif_napi_del_locked() for every RX queue and in page_pool_disable_direct_recycling(). Until the IRQ tasklet is disabled, an interrupt can still schedule a NAPI that was already deleted.
Disable every RX NAPI that was added before the MCU exit and the DMA cleanup. This includes the host RRO queues: mt76_dma_init() skips them, but mt7996_dma_rro_start() adds their NAPIs later when WED is not active, so a check for mt76_queue_is_wed_rro() would miss them.
--- drivers/net/wireless/mediatek/mt76/mt7996/init.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7996/init.c +6 -0
@@ -1403,6 +1403,8 @@ int mt7996_register_device(struct mt7996_dev *dev)void mt7996_unregister_device (struct mt7996_dev *dev) { +int i; +cancel_work_sync (&dev->dump_work);cancel_work_sync (&dev->wed_rro.work);cancel_work_sync (&dev->reset_work);
@@ -1413,6 +1415,10 @@ void mt7996_unregister_device(struct mt7996_dev *dev)mt7996_coredump_unregister (dev);mt76_unregister_device (&dev->mt76);mt7996_wed_rro_free (dev); +for (i =0 ; i <ARRAY_SIZE (dev->mt76.napi); i++) { +if (dev->mt76.napi[i].dev) +napi_disable (&dev->mt76.napi[i]); + }mt7996_mcu_exit (dev);mt7996_tx_token_put (dev);mt7996_dma_cleanup (dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 976/1756 ASoC: rockchip: rockchip_i2s: Handle runtime PM resume failures in set_fmt
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit e9eb1854d16136006c6fe94c927b54b2b264b429 ]
rockchip_i2s_set_fmt() calls pm_runtime_get_sync() before accessing hardware registers, but ignores its return value.
If the runtime resume fails, the function continues to perform register accesses while the device state is undefined.
Replace pm_runtime_get_sync() with pm_runtime_resume_and_get() and return early on failure to avoid unpowered register accesses.
--- sound/soc/rockchip/rockchip_i2s.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
sound/soc/rockchip/rockchip_i2s.c +3 -1
@@ -244,7 +244,9 @@ static int rockchip_i2s_set_fmt(struct snd_soc_dai *cpu_dai,unsigned int mask =0 , val =0 ;int ret =0 ; -pm_runtime_get_sync (cpu_dai->dev); + ret =pm_runtime_resume_and_get (cpu_dai->dev); +if (ret) +return ret; mask =I2S_CKR_MSS_MASK ;switch (fmt &SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK ) {case SND_SOC_DAIFMT_BP_FP :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 977/1756 kobject: Fix the kobj_set_name reference in kset_register() kernel-doc
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit 3aac49b236c137fa77b97968d25338a28c49f0f8 ]
The kernel-doc comment of kset_register() refers to kobj_set_name, which does not exist. The name is kobject_set_name. Say kobject_set_name.
--- lib/kobject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/kobject.c +1 -1
@@ -851,7 +851,7 @@ EXPORT_SYMBOL_GPL(kobj_sysfs_ops);* kset_register() - Initialize and add a kset. * @k: kset. * -* NOTE: On error, the kset.kobj.name allocated by() kobj_set_name() +* NOTE: On error, the kset.kobj.name allocated by kobject_set_name() * is freed, it can not be used any more. */ int kset_register (struct kset *k)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 978/1756 wifi: mt76: mt792x: compute the assoc RSSI from the chain signals
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Felix Fietkau <[email protected]>
[ Upstream commit 2d12f56631ef307e58651b560ccda1f324a059f9 ]
mt792x_mac_rssi_iter() adds status->signal of auth and assoc response frames to the BSS RSSI average, which mt7921_mcu_sta_update() and mt7925_mcu_sta_update() send to the firmware as the station RCPI. mt7925 never sets status->signal, since mt76_rx_convert() computes it from the chain values later. The average is thus fed 0 dBm on mt7925.
Compute the signal from the chain values, as mt76_rx_convert() and mt76_check_sta() do, and skip a frame without a valid chain signal. On mt7921, the average now follows the combined value instead of the strongest chain.
--- drivers/net/wireless/mediatek/mt76/mt792x_mac.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt792x_mac.c +4 -2
@@ -168,14 +168,16 @@ mt792x_mac_rssi_iter(void *priv, u8 *mac, struct ieee80211_vif *vif)struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb;struct mt792x_vif *mvif = (struct mt792x_vif *)vif->drv_priv;struct ieee80211_hdr *hdr =mt76_skb_get_hdr (skb); +int signal; -if (status->signal >0 ) + signal =mt76_rx_signal (status->chains, status->chain_signal); +if (signal >0 || signal <=-128 )return ;if (!ether_addr_equal (vif->addr, hdr->addr1))return ; -ewma_rssi_add (&mvif->bss_conf.rssi, -status->signal); +ewma_rssi_add (&mvif->bss_conf.rssi, -signal); }void mt792x_mac_assoc_rssi (struct mt792x_dev *dev,struct sk_buff *skb)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 979/1756 checkkconfigsymbols.py: Parse Git status output line by line
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ting-Han Hou <[email protected]>
[ Upstream commit 72a61a7fef954152abd9df9def4f94816eb344ca ]
tree_is_dirty() iterates over the string returned by execute() one character at a time. Its status check therefore examines filenames as well as the two status columns.
An otherwise clean tree containing an untracked README is reported as dirty because its name contains letters matched by [URMADC]. This prevents --commit and --diff from running, whereas an untracked notes.txt does not trigger the check.
Split the output into lines before examining the two status columns so that filenames do not affect the dirty-tree check.
--- scripts/checkkconfigsymbols.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/checkkconfigsymbols.py +1 -1
@@ -245,7 +245,7 @@ def tree_is_dirty(): """Return true if the current working tree is dirty (i.e., if any file has been added, deleted, modified, renamed or copied but not committed).""" stdout = execute(["git", "status", "--porcelain"]) - for line in stdout: + for line in stdout.splitlines(): if re.findall(r"[URMADC]{1}", line[:2]): return True return False
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 980/1756 drm/amd/display: assign missing trace entry in amdgpu_dm_dc_clocks_state
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Melissa Wen <[email protected]>
[ Upstream commit ec167063dbf9fc66dc1364b6f9dd220c6742edeb ]
disp_dpp_voltage_level_khz is declared and printed, but never assigned. So when using clock tracepoint the value of this clock is just garbage. Assign clk->disp_dpp_voltage_level_khz since this is stored in dc_clocks as other entries.
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_trace.h | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_trace.h +1 -0
@@ -512,6 +512,7 @@ TRACE_EVENT(amdgpu_dm_dc_clocks_state,TP_fast_assign ( __entry->dispclk_khz = clk->dispclk_khz; __entry->dppclk_khz = clk->dppclk_khz; + __entry->disp_dpp_voltage_level_khz = clk->disp_dpp_voltage_level_khz; __entry->dcfclk_khz = clk->dcfclk_khz; __entry->socclk_khz = clk->socclk_khz; __entry->dcfclk_deep_sleep_khz = clk->dcfclk_deep_sleep_khz;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 981/1756 drm/amd/display: remove duplicated prev_p_state_change_support assignment
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Melissa Wen <[email protected]>
[ Upstream commit 11e8f72b09a6a3c0950b9558abd37559dd098698 ]
The prev_p_state_change_support trace entry is assigned and printed twice, remove the unnecessary duplicates.
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_trace.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_trace.h +2 -4
@@ -522,7 +522,6 @@ TRACE_EVENT(amdgpu_dm_dc_clocks_state, __entry->p_state_change_support = clk->p_state_change_support; __entry->prev_p_state_change_support = clk->prev_p_state_change_support; __entry->pwr_state = clk->pwr_state; - __entry->prev_p_state_change_support = clk->prev_p_state_change_support; __entry->dtm_level = clk->dtm_level; __entry->max_supported_dppclk_khz = clk->max_supported_dppclk_khz; __entry->max_supported_dispclk_khz = clk->max_supported_dispclk_khz;
@@ -532,8 +531,8 @@ TRACE_EVENT(amdgpu_dm_dc_clocks_state, TP_printk("dispclk_khz=%d dppclk_khz=%d disp_dpp_voltage_level_khz=%d dcfclk_khz=%d socclk_khz=%d " "dcfclk_deep_sleep_khz=%d fclk_khz=%d phyclk_khz=%d " "dramclk_khz=%d p_state_change_support=%d " - "prev_p_state_change_support=%d pwr_state=%d prev_p_state_change_support=%d " - "dtm_level=%d max_supported_dppclk_khz=%d max_supported_dispclk_khz=%d " + "prev_p_state_change_support=%d pwr_state=%d dtm_level=%d " + "max_supported_dppclk_khz=%d max_supported_dispclk_khz=%d " "bw_dppclk_khz=%d bw_dispclk_khz=%d ", __entry->dispclk_khz, __entry->dppclk_khz,
@@ -547,7 +546,6 @@ TRACE_EVENT(amdgpu_dm_dc_clocks_state, __entry->p_state_change_support, __entry->prev_p_state_change_support, __entry->pwr_state, - __entry->prev_p_state_change_support, __entry->dtm_level, __entry->max_supported_dppclk_khz, __entry->max_supported_dispclk_khz,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 982/1756 drm/amd/display: fix vready offset assignment in dcn_optc_lock_unlock_state
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Melissa Wen <[email protected]>
[ Upstream commit 3ad7f4ca58efd6c1216632c50873dfffdefbe3ff ]
vready_offset is captured by optc_state, but the trace point entry is wrongly assigned to vupdate_offset. Fix vready_offset tracepoint field in dcn_optc_lock_unloack_state to record optc_state->vready_offset.
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_trace.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_trace.h +1 -1
@@ -700,7 +700,7 @@ TRACE_EVENT(dcn_optc_lock_unlock_state, __entry->vstartup_start = optc_state->vstartup_start; __entry->vupdate_offset = optc_state->vupdate_offset; __entry->vupdate_width = optc_state->vupdate_width; - __entry->vready_offset = optc_state->vupdate_offset; + __entry->vready_offset = optc_state->vready_offset; ),TP_printk ("%s: %s()+%d: optc_instance=%d opp_count=%d max_h_total=%d max_v_total=%d " "min_h_blank=%d min_h_sync_width=%d min_v_sync_width=%d min_v_blank=%d "
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 983/1756 drm/amd/display: use right type for amdgpu_dc_performance event entries
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Melissa Wen <[email protected]>
[ Upstream commit 99858eda764364bae733448c7eb79145d3d043ec ]
Some amdgpu_dc_performance trace event params are passed as unsigned long but stored as uint32_t, cutting them off on 64-bit. Use the right type on entry fields and on printk use unsigned format accordingly.
--- .../drm/amd/display/amdgpu_dm/amdgpu_dm_trace.h | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_trace.h +7 -10
@@ -75,10 +75,10 @@ TRACE_EVENT(amdgpu_dc_performance, const char *func, unsigned int line),TP_ARGS (read_count ,write_count ,last_read ,last_write ,func ,line ),TP_STRUCT__entry ( - __field(uint32_t, reads) -__field (uint32_t ,writes ) -__field (uint32_t, read_delta) -__field (uint32_t, write_delta) + __field(unsigned long, reads) +__field (unsigned long ,writes ) + __field(unsigned long, read_delta) + __field(unsigned long, write_delta)__string (func, func)__field (uint32_t, line) ),
@@ -92,12 +92,9 @@ TRACE_EVENT(amdgpu_dc_performance, *last_read = read_count; *last_write = write_count; ), -TP_printk ("%s:%d reads=%08ld (%08ld total), writes=%08ld (%08ld total)" , -__get_str (func), __entry->line, - (unsigned long )__entry->read_delta, - (unsigned long )__entry->reads, - (unsigned long )__entry->write_delta, - (unsigned long )__entry->writes) +TP_printk ("%s:%u reads=%08lu (%08lu total), writes=%08lu (%08lu total)" , +__get_str (func), __entry->line, __entry->read_delta, + __entry->reads, __entry->write_delta, __entry->writes) ); TRACE_EVENT(amdgpu_dm_connector_atomic_check,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 984/1756 drm/amd/display: copy function name into dcn_fpu trace event
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Melissa Wen <[email protected]>
[ Upstream commit b4d41522012d91cd875cebdfd1a3bbb04eb863dd ]
Userspace trace tools that use libtraceevent to read binary buffer only see a kernel address when printing const char *. Use string macros in dcn_fpu to copy the function name into the trace event.
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_trace.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_trace.h +3 -3
@@ -641,20 +641,20 @@ TRACE_EVENT(dcn_fpu,TP_STRUCT__entry (__field (bool ,begin ) - __field(const char *, function) +__string (function, function)__field (int, line)__field (int, recursion_depth) ),TP_fast_assign ( __entry->begin = begin; - __entry->function = function; +__assign_str (function); __entry->line = line; __entry->recursion_depth = recursion_depth; ),TP_printk ("%s: recursion_depth: %d: %s()+%d:" , __entry->begin ?"begin" :"end" , __entry->recursion_depth, - __entry->function, +__get_str (function), __entry->line ) );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 985/1756 drm/amd/display: copy function name into dcn_optc_lock_unlock_state trace event
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Melissa Wen <[email protected]>
[ Upstream commit 624a5a158c2a49f07edba7f8653eeecca114921f ]
Userspace trace tools that use libtraceevent to read binary buffer only see a kernel address when printing const char *. Use string macros in dcn_optc_lock_unlock_state to copy the function name into the trace event.
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_trace.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_trace.h +3 -3
@@ -664,7 +664,7 @@ TRACE_EVENT(dcn_optc_lock_unlock_state, TP_ARGS(optc_state, instance, lock, function, line),TP_STRUCT__entry ( -__field (const char *,function ) +__string (function ,function )__field (int, instance)__field (bool, lock) __field(int, line)
@@ -682,7 +682,7 @@ TRACE_EVENT(dcn_optc_lock_unlock_state,__field (int, vready_offset) ),TP_fast_assign ( - __entry->function = function; + __assign_str(function); __entry->instance = instance; __entry->lock = lock; __entry->line = line;
@@ -704,7 +704,7 @@ TRACE_EVENT(dcn_optc_lock_unlock_state,"min_v_blank_interlace=%d vstartup_start=%d vupdate_offset=%d vupdate_width=%d " "vready_offset=%d" , __entry->lock ?"Lock" :"Unlock" , - __entry->function, +__get_str (function), __entry->line, __entry->instance, __entry->opp_count,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 986/1756 ASoC: mediatek: common: Handle constraint return value in FE startup
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit 5fcdb40a4776cc6f8d3179aa9cf9663fc18c7861 ]
snd_pcm_hw_constraint_integer() may return 1, which is then returned from mtk_afe_fe_startup(). ASoC only treats 0 as success when marking the DAI as started, so .shutdown() can be skipped on rollback.
Return 0 explicitly on success.
--- sound/soc/mediatek/common/mtk-afe-fe-dai.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
sound/soc/mediatek/common/mtk-afe-fe-dai.c +5 -3
@@ -75,8 +75,10 @@ int mtk_afe_fe_startup(struct snd_pcm_substream *substream, ret =snd_pcm_hw_constraint_integer (runtime,SNDRV_PCM_HW_PARAM_PERIODS ); -if (ret <0 ) +if (ret <0 ) {dev_err (afe->dev,"snd_pcm_hw_constraint_integer failed\n" ); +return ret; + }/* dynamic allocate irq to memif */ if (memif->irq_usage <0 ) {
@@ -88,10 +90,10 @@ int mtk_afe_fe_startup(struct snd_pcm_substream *substream, }else {dev_err (afe->dev,"%s() error: no more asys irq\n" , __func__); - ret = -EBUSY ; +return -EBUSY ; } } -return ret; +return 0 ; }EXPORT_SYMBOL_GPL (mtk_afe_fe_startup);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 987/1756 ASoC: mediatek: mt8188: Handle constraint return value in FE startup
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit 71253751586b8ce37570b8e15cfbc74f0dd06c3d ]
snd_pcm_hw_constraint_minmax() may return 1, which is then returned from mt8188_afe_fe_startup(). ASoC only treats 0 as success when marking the DAI as started, so .shutdown() can be skipped on rollback.
Return 0 explicitly on success.
--- sound/soc/mediatek/mt8188/mt8188-afe-pcm.c | 3 +++ 1 file changed, 3 insertions(+)
sound/soc/mediatek/mt8188/mt8188-afe-pcm.c +3 -0
@@ -320,6 +320,9 @@ static int mt8188_afe_fe_startup(struct snd_pcm_substream *substream, MT8188_MEMIF_DL7_MAX_PERIOD_SIZE);if (ret <0 )dev_dbg (afe->dev,"hw_constraint_minmax failed\n" ); +else + ret =0 ; + out:return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 988/1756 ASoC: mediatek: mt8365: Handle constraint return value in FE startup
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit 8de3f4e8e81148dd4cdd19e622d4be1fe07a7f52 ]
snd_pcm_hw_constraint_integer() may return 1, which is then returned from mt8365_afe_fe_startup(). ASoC only treats 0 as success when marking the DAI as started, so .shutdown() can be skipped on rollback.
Return 0 explicitly on success.
--- sound/soc/mediatek/mt8365/mt8365-afe-pcm.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
sound/soc/mediatek/mt8365/mt8365-afe-pcm.c +5 -2
@@ -514,11 +514,14 @@ static int mt8365_afe_fe_startup(struct snd_pcm_substream *substream,snd_soc_set_runtime_hwparams (substream, afe->mtk_afe_hardware); ret =snd_pcm_hw_constraint_integer (runtime,SNDRV_PCM_HW_PARAM_PERIODS ); -if (ret <0 ) +if (ret <0 ) {dev_err (afe->dev,"snd_pcm_hw_constraint_integer failed\n" ); +return ret; + }mt8365_afe_enable_main_clk (afe); -return ret; + +return 0 ; } static void mt8365_afe_fe_shutdown(struct snd_pcm_substream *substream,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 989/1756 PCI/sysfs: Stop reporting _DSM failures as -EPERM
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Krzysztof Wilczyński <[email protected]>
[ Upstream commit 36f9bd09920ed71c1b79db397170412b2de22319 ]
Currently, dsm_get_label() returns the literal -1 on every failure path. The sysfs read path passes that value to userspace as -EPERM. Reading the "label" or "acpi_index" attribute on a platform where the Device Name _DSM returns a malformed result then fails with:
$ cat /sys/bus/pci/devices/0000:00:08.3/label cat: /sys/bus/pci/devices/0000:00:08.3/label: Operation not permitted
Nothing in that path performs a permission check, and the read fails the same way for a privileged reader. The error code points at a cause that does not exist, and tools such as lspci report it on every invocation.
Return -ENODEV when the device has no ACPI companion, and -EIO when the _DSM evaluation fails or returns an object that cannot be parsed. Other _DSM users in the tree report such failures the same way.
The set of reads that succeed, and the bytes they return, stay the same. Only the error code of reads that already fail differs.
--- drivers/pci/pci-label.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/pci/pci-label.c +3 -3
@@ -160,12 +160,12 @@ static int dsm_get_label(struct device *dev, char *buf,int len =0 ;if (!handle) -return -1 ; +return -ENODEV ; obj =acpi_evaluate_dsm (handle, &pci_acpi_dsm_guid,0x2 ,DSM_PCI_DEVICE_NAME ,NULL );if (!obj) -return -1 ; +return -EIO ; tmp = obj->package.elements; if (obj->type == ACPI_TYPE_PACKAGE && obj->package.count == 2 &&
@@ -190,7 +190,7 @@ static int dsm_get_label(struct device *dev, char *buf,ACPI_FREE (obj); -return len >0 ? len :-1 ; +return len >0 ? len : -EIO ; } static ssize_t label_show(struct device *dev, struct device_attribute *attr,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 990/1756 PCI/sysfs: Handle a malformed _DSM result in acpi_attr_is_visible()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Krzysztof Wilczyński <[email protected]>
[ Upstream commit 1832dc1579aa7cc7cd41843770767e7a3ffa8364 ]
Currently, the "label" and "acpi_index" attributes are created whenever the _DSM function 0 bitmap advertises the Device Name function, without evaluating that function. The documented ABI states that each attribute is created only if the firmware has given a name or an instance number to the PCI device.
The bitmap says nothing about the object the function returns. Firmware that advertises the function but returns an object that cannot be parsed therefore produces attributes that exist and fail every read, as in the report below.
Evaluate the Device Name _DSM when deciding attribute visibility and create each attribute only when the element it exports has a type the read path accepts, mirroring the checks performed at read time. The SMBIOS attribute group already follows this pattern by performing the DMI lookup in its is_visible() callback. The read side checks remain in place since the two evaluations happen at different times.
This restores the behaviour from before commit 2fc59fe2ecdc ("PCI /
pci-label: treat PCI label with index 0 as valid label"), which switched visibility from evaluating the function to checking only the function 0 bitmap. The check is now made for each attribute, not once for both.
--- Documentation/ABI/testing/sysfs-bus-pci | 14 ++++++++--- drivers/pci/pci-label.c | 33 ++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 5 deletions(-)
Documentation/ABI/testing/sysfs-bus-pci +10 -4
@@ -244,10 +244,16 @@ Contact: Narendra K <[email protected]>, [email protected] Description: Reading this attribute will provide the firmware given name (SMBIOS type 41 string or ACPI _DSM string) of - the PCI device. The attribute will be created only - if the firmware has given a name to the PCI device. - ACPI _DSM string name will be given priority if the - system firmware provides SMBIOS type 41 string also. + the PCI device. The attribute will be created only if the + firmware naming mechanism is implemented for the device: + a SMBIOS type 41 record with a non-empty reference + designation, or a Device Name _DSM that returns the name + as a string or a buffer. The value read is empty when the + firmware implements the _DSM but gives the device no name, + which per PCI Firmware r3.3, sec 4.6.7 the firmware reports + as a NULL string. ACPI _DSM string name will be given + priority if the system firmware provides SMBIOS type 41 + string also. Users: Userspace applications interested in knowing the firmware assigned name of the PCI device.
drivers/pci/pci-label.c +32 -1
@@ -217,11 +217,42 @@ static umode_t acpi_attr_is_visible(struct kobject *kobj, struct attribute *a, int n) {struct device *dev =kobj_to_dev (kobj); +union acpi_object *obj, *tmp; +umode_t mode =0 ;if (!device_has_acpi_name (dev))return 0 ; -return a->mode; +/* +* The bitmap from _DSM function 0 only advertises function 7, +* and whether the returned object can be parsed is a separate +* question. Evaluate it and expose each attribute only if the +* element it exports has one of the types the read path +* accepts, mirroring the checks in dsm_get_label(). +*/ + obj =acpi_evaluate_dsm (ACPI_HANDLE (dev), &pci_acpi_dsm_guid,0x2 , +DSM_PCI_DEVICE_NAME ,NULL ); +if (!obj) +return 0 ; + +if (obj->type !=ACPI_TYPE_PACKAGE || obj->package.count !=2 ) + goto out; + + tmp = obj->package.elements; +if (tmp[0 ].type !=ACPI_TYPE_INTEGER ) + goto out; + +if (a == &dev_attr_acpi_index.attr) + mode = a->mode; +else if (a == &dev_attr_label.attr && + (tmp[1 ].type ==ACPI_TYPE_STRING || + tmp[1 ].type ==ACPI_TYPE_BUFFER )) + mode = a->mode; + +out: +ACPI_FREE (obj); + +return mode; }const struct attribute_group pci_dev_acpi_attr_group = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 991/1756 ALSA: hda: Fix potential UAF for gating jack
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit 27cee4141c8de82cf051104ca830c3a209816033 ]
snd_hda_jack_set_gating_jack() assigns gated and gating variables from the succeeding calls of snd_hda_jack_tbl_get(). This works normally, but the second call might kick off the reallocation of the jack table, hence the first pointer might become invalid, which leads to a UAF.
For avoiding that pitfall, this patch changes the code to two phases:
the first to only create two entries, and the second phase to get the pointers from the table, so that no relocation can happen any longer.
--- sound/pci/hda/hda_jack.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
sound/pci/hda/hda_jack.c +6 -3
@@ -383,12 +383,15 @@ EXPORT_SYMBOL_GPL(snd_hda_jack_detect_enable);int snd_hda_jack_set_gating_jack (struct hda_codec *codec,hda_nid_t gated_nid,hda_nid_t gating_nid) { -struct hda_jack_tbl *gated =snd_hda_jack_tbl_new (codec, gated_nid,0 ); -struct hda_jack_tbl *gating = -snd_hda_jack_tbl_new (codec, gating_nid,0 ); +struct hda_jack_tbl *gated, *gating;WARN_ON (codec->dp_mst); +if (!snd_hda_jack_tbl_new (codec, gated_nid,0 ) || + !snd_hda_jack_tbl_new (codec, gating_nid,0 )) +return -ENOMEM ; + gated =snd_hda_jack_tbl_get_mst (codec, gated_nid,0 ); + gating =snd_hda_jack_tbl_get_mst (codec, gating_nid,0 );if (!gated || !gating)return -EINVAL ;
Signature · 1 line
2.53.0