6.12.114-rc1 review
Subsystems (5)
Greg Kroah-Hartman
maintainerPATCH 701/869 firmware: arm_scmi: Fix SCMI device destroy lifetimes
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sudeep Holla <[email protected]>
[ Upstream commit 6abe8fe36b29ff51d1a42c2f338972883f4751a5 ]
scmi_child_dev_find() drops the reference returned by device_find_child() before returning the scmi_device pointer. A concurrent unregister can then release the device while the destroy path is still using the returned pointer.
Make the lookup helper return the device_find_child() reference and keep it until scmi_device_destroy() has finished unregistering the child.
Also split device_unregister() in __scmi_device_destroy() so the SCMI bus ID is not made reusable until after device_del() has removed the old scmi_dev.N name from sysfs. This avoids a new SCMI device reusing the same ID while the old device is still registered.
The final device release callback is also a possible cleanup path when SCMI children are deleted by driver core recursion rather than __scmi_device_destroy(). Release the SCMI bus ID from a common helper used by destroy, register-failure and final-release paths, and clear scmi_dev->id after freeing it so the final release cannot free the same ID again.
--- drivers/firmware/arm_scmi/bus.c | 36 ++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 12 deletions(-)
drivers/firmware/arm_scmi/bus.c +24 -12
@@ -249,8 +249,9 @@ static int scmi_match_by_id_table(struct device *dev, void *data) (id_table->name && !strcmp (sdev->name, id_table->name)); } -static struct scmi_device *scmi_child_dev_find (struct device *parent, -int prot_id,const char *name) +/* Returns a device_find_child() reference which must be dropped by caller. */ +static struct scmi_device * +scmi_child_dev_find_get (struct device *parent,int prot_id,const char *name) {struct scmi_device_id id_table;struct device *dev;
@@ -262,9 +263,6 @@ static struct scmi_device *scmi_child_dev_find(struct device *parent,if (!dev)return NULL ; -/* Drop the refcnt bumped implicitly by device_find_child */ -put_device (dev); -return to_scmi_dev (dev); }
@@ -332,10 +330,19 @@ void scmi_driver_unregister(struct scmi_driver *driver) }EXPORT_SYMBOL_GPL (scmi_driver_unregister); +static void scmi_device_release_resources (struct scmi_device *scmi_dev) +{ +if (scmi_dev->id) { +ida_free (&scmi_bus_id, scmi_dev->id); + scmi_dev->id =0 ; + } +} +static void scmi_device_release (struct device *dev) {struct scmi_device *scmi_dev =to_scmi_dev (dev); +scmi_device_release_resources (scmi_dev);kfree_const (scmi_dev->name);kfree (scmi_dev); }
@@ -350,8 +357,9 @@ static void __scmi_device_destroy(struct scmi_device *scmi_dev)if (scmi_dev->protocol_id ==SCMI_PROTOCOL_SYSTEM )atomic_set (&scmi_syspower_registered,0 ); -ida_free (&scmi_bus_id, scmi_dev->id); -device_unregister (&scmi_dev->dev); +device_del (&scmi_dev->dev); +scmi_device_release_resources (scmi_dev); +put_device (&scmi_dev->dev); } static struct scmi_device *
@@ -368,9 +376,11 @@ __scmi_device_create(struct device_node *np, struct device *parent,* each DT defined protocol at probe time, and the concurrent * registration of SCMI drivers. */ - scmi_dev =scmi_child_dev_find (parent, protocol, name); -if (scmi_dev) + scmi_dev =scmi_child_dev_find_get (parent, protocol, name); +if (scmi_dev) { +put_device (&scmi_dev->dev);return scmi_dev; + }/* * Ignore any possible subsequent failures while creating the device
@@ -421,8 +431,8 @@ __scmi_device_create(struct device_node *np, struct device *parent,return scmi_dev; put_dev: +scmi_device_release_resources (scmi_dev);put_device (&scmi_dev->dev); -ida_free (&scmi_bus_id, id);return NULL ; }
@@ -494,9 +504,11 @@ void scmi_device_destroy(struct device *parent, int protocol, const char *name) {struct scmi_device *scmi_dev; - scmi_dev =scmi_child_dev_find (parent, protocol, name); -if (scmi_dev) + scmi_dev =scmi_child_dev_find_get (parent, protocol, name); +if (scmi_dev) {__scmi_device_destroy (scmi_dev); +put_device (&scmi_dev->dev); + } }EXPORT_SYMBOL_GPL (scmi_device_destroy);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 702/869 fs/resctrl: Prevent use-after-free in rdtgroup_kn_put()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Reinette Chatre <[email protected]>
[ Upstream commit f5bcf539484d2d604c2f2330e09487ea090b21c7 ]
A struct rdtgroup is reference counted via rdtgroup::waitcount. Callers that need the structure to remain valid across a sleep (while waiting on acquiring rdtgroup_mutex) take a reference with rdtgroup_kn_get() and release it with rdtgroup_kn_put().
The release path is intended to serve as the fallback freer: if the count drops to zero and the group has already been marked RDT_DELETED, rdtgroup_kn_put() frees the structure.
The bulk teardown paths free_all_child_rdtgrp() and rmdir_all_sub() resulting from a resctrl directory remove or resctrl fs unmount act as the primary
freer: they hold rdtgroup_mutex and free each rdtgroup whose waitcount is zero, otherwise they set RDT_DELETED and leave the freeing to the last waiter.
These two freers race. rdtgroup_kn_put() commits waitcount == 0 with atomic_dec_and_test() outside rdtgroup_mutex, then reads rdtgroup::flags. Between those two operations a concurrent caller of free_all_child_rdtgrp() or rmdir_all_sub() (which holds the mutex) can observe waitcount == 0 via atomic_read(), call rdtgroup_remove(), and kfree() the structure.
The subsequent read of rdtgroup::flags in rdtgroup_kn_put() is then a use-after-free, and the structure may even be freed twice if the freed memory happens to satisfy the RDT_DELETED flag check.
Replace the bare atomic_dec_and_test() with atomic_dec_and_mutex_lock() so that the decrement-to-zero takes rdtgroup_mutex before the count becomes globally visible. The inspection of rdtgroup::flags then runs under the same mutex held by the bulk freers, making the two paths mutually exclusive.
The common case where the count does not reach zero remains lock-free. Defer kernfs_unbreak_active_protection() until after the mutex is dropped since kernfs active protections functionally wrap rdtgroup_mutex. Remove resource group, which in turn drops its kernfs reference, after kernfs protection is restored.
[ bp: Split the commit messsages into smaller, easier-parseable paragraphs. ]
--- arch/x86/kernel/cpu/resctrl/rdtgroup.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +14 -5
@@ -2447,15 +2447,24 @@ static void rdtgroup_kn_get(struct rdtgroup *rdtgrp, struct kernfs_node *kn)static void rdtgroup_kn_put (struct rdtgroup *rdtgrp,struct kernfs_node *kn) { -if (atomic_dec_and_test (&rdtgrp->waitcount) && - (rdtgrp->flags &RDT_DELETED )) { +bool needs_free; + +if (!atomic_dec_and_mutex_lock (&rdtgrp->waitcount, &rdtgroup_mutex)) { +kernfs_unbreak_active_protection (kn); +return ; + } + + needs_free = rdtgrp->flags &RDT_DELETED ; + +mutex_unlock (&rdtgroup_mutex); + +kernfs_unbreak_active_protection (kn); + +if (needs_free) {if (rdtgrp->mode ==RDT_MODE_PSEUDO_LOCKSETUP || rdtgrp->mode ==RDT_MODE_PSEUDO_LOCKED )rdtgroup_pseudo_lock_remove (rdtgrp); -kernfs_unbreak_active_protection (kn);rdtgroup_remove (rdtgrp); - }else { -kernfs_unbreak_active_protection (kn); } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 703/869 RDMA/rvt: Return NULL after port allocation failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leon Romanovsky <[email protected]>
[ Upstream commit 2982eaf3b9d2d953318c74cd6f1b7576ea6d7b1f ]
rvt_alloc_device() deallocates the IB device when its port array cannot be allocated but then returns the pointer to the released allocation. Callers treat any non-NULL value as valid and dereference it, resulting in a use-after-free.
Return NULL immediately after deallocation so callers can propagate the allocation failure.
--- drivers/infiniband/sw/rdmavt/vt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/infiniband/sw/rdmavt/vt.c +3 -1
@@ -54,8 +54,10 @@ struct rvt_dev_info *rvt_alloc_device(size_t size, int nports)return rdi; rdi->ports =kcalloc (nports,sizeof (*rdi->ports),GFP_KERNEL ); -if (!rdi->ports) +if (!rdi->ports) {ib_dealloc_device (&rdi->ibdev); +return NULL ; + }return rdi; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 704/869 esp: do not unref managed frag pages in esp_ssg_unref()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maher Azzouzi <[email protected]>
[ Upstream commit 21697720ff43b8dfa25b8e8d9ca7f56f4597fc80 ]
esp_ssg_unref() releases the page references held on the source scatterlist after the AEAD operation completes. It calls skb_page_unref() on every frag page for an out-of-place transform (req->src != req->dst), and in the error path of esp_output_tail() (already_unref == true) on the request's own scatterlist.
This is wrong when the skb carries managed frags (SKBFL_MANAGED_FRAG_REFS). Managed frags are owned by a zerocopy ubuf and the skb does not hold a per-frag page reference; io_uring SEND_ZC with a registered buffer attaches the bvec pages this way via io_sg_from_iter(). The rest of the stack honours this invariant:skb_release_data() skips the per-frag unref when SKBFL_MANAGED_FRAG_REFS is set, and skb_zcopy_managed() is the guard used at the other unref sites.
esp_ssg_unref() is missing that guard, so for a managed-frag skb it drops a page reference the skb never acquired. This can underflow the page reference count and free a page that is still in use.
Guard the function with skb_zcopy_managed() so both unref paths are skipped for managed-frag skbs, matching skb_release_data().
--- net/ipv4/esp4.c | 7 +++++++ net/ipv6/esp6.c | 7 +++++++ 2 files changed, 14 insertions(+)
net/ipv4/esp4.c +7 -0
@@ -104,6 +104,13 @@ static void esp_ssg_unref(struct xfrm_state *x, void *tmp, struct sk_buff *skb)struct aead_request *req;struct scatterlist *sg; +/* Managed frags are owned by the zerocopy ubuf; the skb holds no +* per-frag page reference, so we must not drop one here. Mirrors +* the SKBFL_MANAGED_FRAG_REFS handling in skb_release_data(). +*/ +if (skb_zcopy_managed (skb)) +return ; +if (x->props.flags &XFRM_STATE_ESN ) extralen +=sizeof (struct esp_output_extra );
net/ipv6/esp6.c +7 -0
@@ -121,6 +121,13 @@ static void esp_ssg_unref(struct xfrm_state *x, void *tmp, struct sk_buff *skb)struct aead_request *req;struct scatterlist *sg; +/* Managed frags are owned by the zerocopy ubuf; the skb holds no +* per-frag page reference, so we must not drop one here. Mirrors +* the SKBFL_MANAGED_FRAG_REFS handling in skb_release_data(). +*/ +if (skb_zcopy_managed (skb)) +return ; +if (x->props.flags &XFRM_STATE_ESN ) extralen +=sizeof (struct esp_output_extra );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 705/869 platform/x86: asus-wmi: fix resource leaks on probe failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marco Scardovi <[email protected]>
[ Upstream commit ef3daa2b84a2b8499ce9e2ce1c865dca36d39f95 ]
During driver initialization in asus_wmi_add(), various subsystems are registered sequentially. However, the error path labels are out of order relative to the registration sequence.
Specifically:
1. If asus_wmi_custom_fan_curve_init() fails, the driver jumps to fail_custom_fan_curve. Because this label is placed below fail_sysfs, it bypasses the cleanup calls for the input device and sysfs groups, which were successfully registered before, leaking those resources.
2. If asus_screenpad_init() fails, the driver jumps to fail_screenpad. Because fail_screenpad is placed below fail_backlight, it bypasses the cleanup calls for backlight and rfkill, leaking those resources.
Fix these resource leaks by reordering the error path labels in asus_wmi_add() to match the exact reverse order of the resource allocations.
--- drivers/platform/x86/asus-wmi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/platform/x86/asus-wmi.c +3 -3
@@ -4840,20 +4840,20 @@ static int asus_wmi_add(struct platform_device *pdev)return 0 ; fail_wmi_handler: +asus_screenpad_exit (asus); +fail_screenpad:asus_wmi_backlight_exit (asus); fail_backlight:asus_wmi_rfkill_exit (asus); -fail_screenpad: -asus_screenpad_exit (asus); fail_rfkill:asus_wmi_led_exit (asus); fail_leds: +fail_custom_fan_curve: fail_hwmon:asus_wmi_input_exit (asus); fail_input:asus_wmi_sysfs_exit (asus->platform_device); fail_sysfs: -fail_custom_fan_curve: fail_platform_profile_setup:if (asus->platform_profile_support)platform_profile_remove ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 706/869 usb: gadget: uac: validate rate list length before storing
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qing Ming <[email protected]>
[ Upstream commit 844d83d5964b87919b958ff48405188c6ddae9cc ]
UAC1 and UAC2 configfs rate-list attributes parse a comma-separated list of sampling rates and store each parsed value in fixed-size arrays. The arrays have UAC_MAX_RATES entries, but the store paths do not check that the input contains at most that many tokens before writing through opts->name##s[i++].
Writing more than ten rates therefore writes past the end of the p_srates[] or c_srates[] array in struct f_uac1_opts or struct f_uac2_opts.
With CONFIG_UBSAN_BOUNDS enabled, writing an 11-entry rate list to the UAC1 p_srate attribute reports:
UBSAN: array-index-out-of-bounds drivers/usb/gadget/function/f_uac1.c:1669:1 index 10 is out of range for type 'int [10]' __ubsan_handle_out_of_bounds.cold f_uac1_opts_p_srate_store configfs_write_iter vfs_write ksys_write do_syscall_64
The same reproducer against the UAC2 p_srate attribute reports:
UBSAN: array-index-out-of-bounds drivers/usb/gadget/function/f_uac2.c:2087:1 index 10 is out of range for type 'int [10]' __ubsan_handle_out_of_bounds.cold f_uac2_opts_p_srate_store configfs_write_iter vfs_write ksys_write do_syscall_64
Reject additional tokens once UAC_MAX_RATES entries have been parsed. Also keep the original kstrdup() pointer for kfree(), because strsep() advances the parsing cursor. Freeing the advanced cursor leaks the original buffer on successful parses and can free an interior pointer on some error paths.
--- drivers/usb/gadget/function/f_uac1.c | 13 +++++++++---- drivers/usb/gadget/function/f_uac2.c | 13 +++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-)
drivers/usb/gadget/function/f_uac1.c +9 -4
@@ -1594,7 +1594,8 @@ static ssize_t f_uac1_opts_##name##_store(struct config_item *item, \ const char *page, size_t len) \ { \struct f_uac1_opts *opts =to_f_uac1_opts (item); \ -char *split_page =NULL ; \ +char *buf =NULL ; \ +char *split_page; \int ret = -EINVAL ; \char *token; \u32 num; \
@@ -1608,18 +1609,22 @@ static ssize_t f_uac1_opts_##name##_store(struct config_item *item, \ \ i =0 ; \ memset(opts->name##s, 0x00, sizeof(opts->name##s)); \ - split_page = kstrdup(page, GFP_KERNEL); \ + buf = kstrdup(page, GFP_KERNEL); \ + split_page = buf; \ while ((token = strsep(&split_page, ",")) != NULL) { \ ret = kstrtou32(token, 0, &num); \ if (ret) \ goto end; \ - \ + if (i >= UAC_MAX_RATES) { \ + ret = -EINVAL; \ + goto end; \ + } \ opts->name##s[i++] = num; \ ret = len; \ }; \ \ end: \ - kfree(split_page); \ + kfree(buf); \ mutex_unlock(&opts->lock); \ return ret; \ } \
drivers/usb/gadget/function/f_uac2.c +9 -4
@@ -2012,7 +2012,8 @@ static ssize_t f_uac2_opts_##name##_store(struct config_item *item, \ const char *page, size_t len) \ { \struct f_uac2_opts *opts =to_f_uac2_opts (item); \ -char *split_page =NULL ; \ +char *buf =NULL ; \ +char *split_page; \int ret = -EINVAL ; \char *token; \u32 num; \
@@ -2026,18 +2027,22 @@ static ssize_t f_uac2_opts_##name##_store(struct config_item *item, \ \ i =0 ; \ memset(opts->name##s, 0x00, sizeof(opts->name##s)); \ - split_page = kstrdup(page, GFP_KERNEL); \ + buf = kstrdup(page, GFP_KERNEL); \ + split_page = buf; \ while ((token = strsep(&split_page, ",")) != NULL) { \ ret = kstrtou32(token, 0, &num); \ if (ret) \ goto end; \ - \ + if (i >= UAC_MAX_RATES) { \ + ret = -EINVAL; \ + goto end; \ + } \ opts->name##s[i++] = num; \ ret = len; \ }; \ \ end: \ - kfree(split_page); \ + kfree(buf); \ mutex_unlock(&opts->lock); \ return ret; \ } \
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 707/869 bpf: Reject rdonly/rdwr_buf_size kfunc arguments that exceed u32 max
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicholas Dudar <[email protected]>
[ Upstream commit 2aaf67f0516fde29620d0edfc29c01b9ea7ad430 ]
check_kfunc_args() detects a kfunc argument named rdonly_buf_size or rdwr_buf_size and stores reg->var_off.value into meta->r0_size, a u64, and does not bound it. check_kfunc_call() later copies that value into the returned register's mem_size field:
meta->r0_size = reg->var_off.value; ... regs[BPF_REG_0].mem_size = meta.r0_size;
regs[BPF_REG_0].mem_size is u32. A constant whose upper 32 bits are set gets truncated instead of causing a load-time rejection, so the verifier records a PTR_TO_MEM register with an approximately 4 GiB mem_size for whatever allocation the kfunc returned. A later access check against that register uses the truncated, wrong bound.
Reject rdonly_buf_size/rdwr_buf_size values that exceed U32_MAX at the point meta->r0_size is set.
--- kernel/bpf/verifier.c | 5 +++++ 1 file changed, 5 insertions(+)
kernel/bpf/verifier.c +5 -0
@@ -12347,6 +12347,11 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_kfunc_call_ } meta->r0_size = reg->var_off.value; +if (meta->r0_size >U32_MAX ) { +verbose (env,"R%d rdonly/rdwr_buf_size exceeds u32 max\n" , + regno); +return -EINVAL ; + } ret =mark_chain_precision (env, regno);if (ret)return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 708/869 platform/x86: dell-wmi-base: Fix handling of ultra performance key
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Armin Wolf <[email protected]>
[ Upstream commit adfd6846bea13667ff28f8aaf00c32fbd69825ab ]
The commit message of commit 5fbd827eb9c2 ("platform/x86: dell-wmi: Recognise or support new switches") states that the ultra performance key contains additional data
after the type and code fields. The event data passed todell_wmi_process_key() is already parsed, so "buffer" already
starts after those two fields.
Use the correct index for accessing the first data field to avoid a potential buffer overread.
--- drivers/platform/x86/dell/dell-wmi-base.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/dell/dell-wmi-base.c +1 -1
@@ -442,7 +442,7 @@ static int dell_wmi_process_key(struct wmi_device *wdev, int type, int code, u16 SW_TABLET_MODE, !buffer[0]);return 1 ; }else if (type ==0x0012 && code ==0x000d && remaining >0 ) { - value = (buffer[2 ] ==2 ); + value = (buffer[0 ] ==2 ); used =1 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 709/869 bpf: Reject writes through untrusted BTF pointers
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicholas Dudar <[email protected]>
[ Upstream commit ac65c710cc643cbc52b899627577357867249530 ]
check_ptr_to_btf_access() lets program-type btf_struct_access callbacks validate writes before the default BTF access path rejects non-read accesses. That bypasses the read-only policy for untrusted BTF pointers created by helpers such as bpf_rdonly_cast().
Reject non-read accesses through PTR_UNTRUSTED BTF pointers at the common entry point, before the callback branch to handle all cases.
--- kernel/bpf/verifier.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
kernel/bpf/verifier.c +6 -2
@@ -6907,6 +6907,11 @@ static int check_ptr_to_btf_access(struct bpf_verifier_env *env,return -EACCES ; } +if (atype !=BPF_READ && (type_flag (reg->type) &PTR_UNTRUSTED )) { +verbose (env,"only read is supported\n" ); +return -EACCES ; + } +if (env->ops->btf_struct_access && !type_is_alloc (reg->type) && atype ==BPF_WRITE ) {if (!btf_is_kernel (reg->btf)) {verbose (env,"verifier internal error: reg->btf must be kernel btf\n" );
@@ -6915,8 +6920,7 @@ static int check_ptr_to_btf_access(struct bpf_verifier_env *env, ret = env->ops->btf_struct_access (&env->log, reg, off, size); }else {/* Writes are permitted with default btf_struct_access for -* program allocated objects (which always have ref_obj_id > 0), -* but not for untrusted PTR_TO_BTF_ID | MEM_ALLOC. +* program allocated objects (which always have ref_obj_id > 0). */ if (atype !=BPF_READ && !type_is_ptr_alloc_obj (reg->type)) {verbose (env,"only read is supported\n" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 710/869 time/namespace: Validate nanosecond field in proc_timens_set_offset()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Malaya Kumar Rout <[email protected]>
[ Upstream commit 06aba58e58492d2b8eae059274caed29025ea96e ]
The function validates tv_sec to be within [-KTIME_SEC_MAX, KTIME_SEC_MAX] but never validates that tv_nsec is within the valid range of [0, NSEC_PER_SEC-1] before using it in timespec64_add().
timespec64_add() expects both timespec64 structures to have normalized values with tv_nsec in the range [0, 999999999]. If off->val.tv_nsec contains invalid values (negative or >= NSEC_PER_SEC), it could lead to incorrect calculations or unexpected behavior.
Add validation to ensure tv_nsec is within the valid range before performing the addition.
--- kernel/time/namespace.c | 5 +++++ 1 file changed, 5 insertions(+)
kernel/time/namespace.c +5 -0
@@ -410,6 +410,11 @@ int proc_timens_set_offset(struct file *file, struct task_struct *p, goto out; } +if (off->val.tv_nsec <0 || off->val.tv_nsec >=NSEC_PER_SEC ) { + err = -EINVAL ; + goto out; + } + err = -ERANGE ; if (off->val.tv_sec > KTIME_SEC_MAX ||
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 711/869 bpf: Reject MEM_ALLOC BTF accesses past object bounds
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yiyang Chen <[email protected]>
[ Upstream commit 9c9ee0324c774490ae953162aaaf4561d222bd93 ]
BTF struct walks relax the struct-size check for accesses through a trailing flexible array. That is valid for ordinary BTF type walking, but PTR_TO_BTF_ID | MEM_ALLOC values point to objects allocated with the static BTF type size.
When walking a MEM_ALLOC object, reject the access before applying the flexible-array relaxation if the access range extends past the struct size. Apply the same policy to struct ID matching so kfunc and kptr type checks do not walk past the allocated object bounds either.
--- include/linux/bpf.h | 2 +- kernel/bpf/btf.c | 17 +++++++++++------ kernel/bpf/verifier.c | 11 +++++++---- 3 files changed, 19 insertions(+), 11 deletions(-)
include/linux/bpf.h +1 -1
@@ -2658,7 +2658,7 @@ int btf_struct_access(struct bpf_verifier_log *log,bool btf_struct_ids_match (struct bpf_verifier_log *log,const struct btf *btf,u32 id,int off,const struct btf *need_btf,u32 need_type_id, -bool strict); +bool strict,bool walk_flex_arrays); int btf_distill_func_proto(struct bpf_verifier_log *log, struct btf *btf,
kernel/bpf/btf.c +11 -6
@@ -6841,7 +6841,7 @@ enum bpf_struct_walk_result {static int btf_struct_walk (struct bpf_verifier_log *log,const struct btf *btf,const struct btf_type *t,int off,int size,u32 *next_btf_id,enum bpf_type_flag *flag, -const char **field_name) +const char **field_name,bool walk_flex_arrays) {u32 i, moff, mtrue_end, msize =0 , total_nelems =0 ;const struct btf_type *mtype, *elem_type =NULL ;
@@ -6868,11 +6868,14 @@ static int btf_struct_walk(struct bpf_verifier_log *log, const struct btf *btf, *flag |=PTR_UNTRUSTED ;if (off + size > t->size) { +struct btf_array *array_elem; + +if (!walk_flex_arrays) + goto error; +/* If the last element is a variable size array, we may * need to relax the rule. */ -struct btf_array *array_elem; -if (vlen ==0 ) goto error;
@@ -7133,7 +7136,8 @@ int btf_struct_access(struct bpf_verifier_log *log, t =btf_type_by_id (btf, id); do { - err = btf_struct_walk(log, btf, t, off, size, &id, &tmp_flag, field_name); + err = btf_struct_walk(log, btf, t, off, size, &id, &tmp_flag, + field_name, !type_is_alloc(reg->type)); switch (err) { case WALK_PTR:
@@ -7189,7 +7193,7 @@ bool btf_types_are_same(const struct btf *btf1, u32 id1,bool btf_struct_ids_match (struct bpf_verifier_log *log,const struct btf *btf,u32 id,int off,const struct btf *need_btf,u32 need_type_id, -bool strict) +bool strict,bool walk_flex_arrays) {const struct btf_type *type;enum bpf_type_flag flag =0 ;
@@ -7208,7 +7212,8 @@ bool btf_struct_ids_match(struct bpf_verifier_log *log, type =btf_type_by_id (btf, id);if (!type)return false; - err =btf_struct_walk (log, btf, type, off,1 , &id, &flag,NULL ); + err =btf_struct_walk (log, btf, type, off,1 , &id, &flag,NULL , + walk_flex_arrays);if (err !=WALK_STRUCT )return false;
kernel/bpf/verifier.c +7 -4
@@ -5570,7 +5570,8 @@ static int map_kptr_match_type(struct bpf_verifier_env *env,*/ if (!btf_struct_ids_match (&env->log, reg->btf, reg->btf_id, reg->off, kptr_field->kptr.btf, kptr_field->kptr.btf_id, - kptr_field->type !=BPF_KPTR_UNREF )) + kptr_field->type !=BPF_KPTR_UNREF , + !type_is_alloc (reg->type))) goto bad_type;return 0 ; bad_type:
@@ -8895,7 +8896,7 @@ static int check_reg_type(struct bpf_verifier_env *env, u32 regno,if (!btf_struct_ids_match (&env->log, reg->btf, reg->btf_id, reg->off, btf_vmlinux, *arg_btf_id, - strict_type_match)) { + strict_type_match, !type_is_alloc (reg->type))) {verbose (env,"R%d is of type %s but %s is expected\n" , regno,btf_type_name (reg->btf, reg->btf_id),btf_type_name (btf_vmlinux, *arg_btf_id));
@@ -11858,7 +11859,8 @@ static int process_kf_arg_ptr_to_btf_id(struct bpf_verifier_env *env, reg_ref_t =btf_type_skip_modifiers (reg_btf, reg_ref_id, ®_ref_id); reg_ref_tname =btf_name_by_offset (reg_btf, reg_ref_t->name_off); - struct_same =btf_struct_ids_match (&env->log, reg_btf, reg_ref_id, reg->off, meta->btf, ref_id, strict_type_match); + struct_same =btf_struct_ids_match (&env->log, reg_btf, reg_ref_id, reg->off, meta->btf, ref_id, + strict_type_match, !type_is_alloc (reg->type));/* If kfunc is accepting a projection type (ie. __sk_buff), it cannot * actually use it -- it must cast to the underlying type. So we allow * caller to pass in the underlying type.
@@ -12214,7 +12216,8 @@ __process_kf_arg_ptr_to_graph_node(struct bpf_verifier_env *env, et =btf_type_by_id (field->graph_root.btf, field->graph_root.value_btf_id); t =btf_type_by_id (reg->btf, reg->btf_id);if (!btf_struct_ids_match (&env->log, reg->btf, reg->btf_id,0 , field->graph_root.btf, - field->graph_root.value_btf_id, true)) { + field->graph_root.value_btf_id, true, + !type_is_alloc (reg->type))) { verbose(env, "operation on %s expects arg#1 %s at offset=%d " "in struct %s, but arg is at offset=%d in struct %s\n", btf_field_type_name(head_field_type),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 712/869 dmaengine: xilinx_dma: Fix CPU stall in xilinx_dma_poll_timeout
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alex Bereza <[email protected]>
[ Upstream commit aa99c4d1d63bbc26a5fc4c667d89b2595743c19d ]
Currently when calling xilinx_dma_poll_timeout with delay_us=0 and a condition that is never fulfilled, the CPU busy-waits for prolonged time and the timeout triggers only with a massive delay causing a CPU stall.
This happens due to a huge underestimation of wall clock time in poll_timeout_us_atomic. Commit 7349a69cf312 ("iopoll: Do not use timekeeping in read_poll_timeout_atomic()") changed the behavior to no longer use ktime_get at the expense of underestimation of wall clock time which appears to be very large for delay_us=0. Instead of timing out after approximately XILINX_DMA_LOOP_COUNT microseconds, the timeout takes XILINX_DMA_LOOP_COUNT * 1000 * (time that the overhead of the for loop in poll_timeout_us_atomic takes) which is in the range of several minutes for XILINX_DMA_LOOP_COUNT=1000000. Fix this by using a non-zero value for delay_us. Use delay_us=10 to keep the delay in the hot path of starting DMA transfers minimal but still avoid CPU stalls in case of unexpected hardware failures.
One-off measurement with delay_us=0 causes the cpu to busy wait around 7 minutes in the timeout case. After applying this patch with delay_us=10 the measured timeout was 1053428 microseconds which is roughly equivalent to the expected 1000000 microseconds specified in XILINX_DMA_LOOP_COUNT.
Add a constant XILINX_DMA_POLL_DELAY_US for delay_us value.
--- drivers/dma/xilinx/xilinx_dma.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/dma/xilinx/xilinx_dma.c +10 -4
@@ -166,6 +166,8 @@/* Delay loop counter to prevent hardware failure */ #define XILINX_DMA_LOOP_COUNT 1000000 +/* Delay between polls (avoid a delay of 0 to prevent CPU stalls) */ +#define XILINX_DMA_POLL_DELAY_US 10/* AXI DMA Specific Registers/Offsets */ #define XILINX_DMA_REG_SRCDSTADDR 0x18
@@ -1315,7 +1317,8 @@ static int xilinx_dma_stop_transfer(struct xilinx_dma_chan *chan)/* Wait for the hardware to halt */ return xilinx_dma_poll_timeout (chan,XILINX_DMA_REG_DMASR , val, - val &XILINX_DMA_DMASR_HALTED ,0 , + val &XILINX_DMA_DMASR_HALTED , +XILINX_DMA_POLL_DELAY_US ,XILINX_DMA_LOOP_COUNT ); }
@@ -1330,7 +1333,8 @@ static int xilinx_cdma_stop_transfer(struct xilinx_dma_chan *chan)u32 val;return xilinx_dma_poll_timeout (chan,XILINX_DMA_REG_DMASR , val, - val &XILINX_DMA_DMASR_IDLE ,0 , + val &XILINX_DMA_DMASR_IDLE , +XILINX_DMA_POLL_DELAY_US ,XILINX_DMA_LOOP_COUNT ); }
@@ -1347,7 +1351,8 @@ static void xilinx_dma_start(struct xilinx_dma_chan *chan)/* Wait for the hardware to start */ err =xilinx_dma_poll_timeout (chan,XILINX_DMA_REG_DMASR , val, - !(val &XILINX_DMA_DMASR_HALTED ),0 , + !(val &XILINX_DMA_DMASR_HALTED ), +XILINX_DMA_POLL_DELAY_US ,XILINX_DMA_LOOP_COUNT );if (err) {
@@ -1780,7 +1785,8 @@ static int xilinx_dma_reset(struct xilinx_dma_chan *chan)/* Wait for the hardware to finish reset */ err =xilinx_dma_poll_timeout (chan,XILINX_DMA_REG_DMACR , tmp, - !(tmp &XILINX_DMA_DMACR_RESET ),0 , + !(tmp &XILINX_DMA_DMACR_RESET ), +XILINX_DMA_POLL_DELAY_US ,XILINX_DMA_LOOP_COUNT );if (err) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 713/869 drm/amd/display: Fix dangling pointer in CRTC reset function
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Evgenii Burenchev <[email protected]>
[ Upstream commit 0aeed866cb938943908c3ba46422128e49d2d080 ]
amdgpu_dm_crtc_reset_state() frees the old state before allocating a new one. If kzalloc() fails, the function returns without updating the state pointer, leaving a dangling pointer to already freed memory.
Fix this by allocating the new state first. On allocation failure, the old state remains untouched and the function safely returns.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +4 -4
@@ -479,13 +479,13 @@ static void amdgpu_dm_crtc_reset_state(struct drm_crtc *crtc) {struct dm_crtc_state *state; -if (crtc->state) -amdgpu_dm_crtc_destroy_state (crtc, crtc->state); - state =kzalloc (sizeof (*state),GFP_KERNEL ); -if (WARN_ON (!state)) +if (!state)return ; +if (crtc->state) +amdgpu_dm_crtc_destroy_state (crtc, crtc->state); +__drm_atomic_helper_crtc_reset (crtc, &state->base); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 714/869 drm/amd/display: Fix dangling pointer in plane reset function
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Evgenii Burenchev <[email protected]>
[ Upstream commit 98cad4bd1443975d972f4c7f705980da03722a22 ]
amdgpu_dm_plane_drm_plane_reset() frees the old state before allocating a new one. If kzalloc() fails, the function returns without updating the state pointer, leaving a dangling pointer to already freed memory.
Fix this by allocating the new state first. On allocation failure, the old state remains untouched and the function safely returns.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c +4 -6
@@ -1415,17 +1415,15 @@ static const struct drm_plane_helper_funcs dm_plane_helper_funcs = {static void amdgpu_dm_plane_drm_plane_reset (struct drm_plane *plane) { -struct dm_plane_state *amdgpu_state =NULL ; - -if (plane->state) - plane->funcs->atomic_destroy_state (plane, plane->state); +struct dm_plane_state *amdgpu_state; amdgpu_state =kzalloc (sizeof (*amdgpu_state),GFP_KERNEL ); -WARN_ON (amdgpu_state ==NULL ); -if (!amdgpu_state)return ; +if (plane->state) + plane->funcs->atomic_destroy_state (plane, plane->state); +__drm_atomic_helper_plane_reset (plane, &amdgpu_state->base); amdgpu_state->degamma_tf =AMDGPU_TRANSFER_FUNCTION_DEFAULT ; amdgpu_state->hdr_mult =AMDGPU_HDR_MULT_DEFAULT ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 715/869 mm/page_owner: use memcg_data snapshot to avoid TOCTOU in print_page_owner_memcg()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ye Liu <[email protected]>
[ Upstream commit 90f095b816e25c6a9e4446d299bac5007fdcb3df ]
print_page_owner_memcg() reads page->memcg_data via READ_ONCE() at the start to guard against tail pages and NULL data. However, it later re-reads page->memcg_data locklessly in two places:
1: page_memcg_check(page)
2: PageMemcgKmem(page) (via folio_memcg_kmem(), which includes
VM_BUG_ON assertions for tail pages and MEMCG_DATA_OBJEXTS)
If the page is concurrently freed and reallocated as a THP tail page or slab page between these calls, the VM_BUG_ON assertions can trigger on CONFIG_DEBUG_VM=y builds, crashing the kernel.
Fix both TOCTOU issues by using the memcg_data snapshot throughout.
--- mm/page_owner.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
mm/page_owner.c +7 -3
@@ -501,6 +501,7 @@ static inline int print_page_owner_memcg(char *kbuf, size_t count, int ret, {#ifdef CONFIG_MEMCG unsigned long memcg_data; +struct obj_cgroup *objcg;struct mem_cgroup *memcg;bool online;char name[80 ];
@@ -510,11 +511,14 @@ static inline int print_page_owner_memcg(char *kbuf, size_t count, int ret,if (!memcg_data) goto out_unlock; -if (memcg_data &MEMCG_DATA_OBJEXTS ) +if (memcg_data &MEMCG_DATA_OBJEXTS ) { ret +=scnprintf (kbuf + ret, count - ret,"Slab cache page\n" ); + goto out_unlock; + } - memcg =page_memcg_check (page); + objcg = (void *)(memcg_data & ~OBJEXTS_FLAGS_MASK ); + memcg = objcg ?obj_cgroup_memcg (objcg) :NULL ;if (!memcg) goto out_unlock;
@@ -522,7 +526,7 @@ static inline int print_page_owner_memcg(char *kbuf, size_t count, int ret,cgroup_name (memcg->css.cgroup, name,sizeof (name)); ret +=scnprintf (kbuf + ret, count - ret,"Charged %sto %smemcg %s\n" , -PageMemcgKmem (page) ?"(via objcg) " :"" , + (memcg_data &MEMCG_DATA_KMEM ) ?"(via objcg) " :"" , online ?"" :"offline " , name); out_unlock:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 716/869 nfsd: convert nfsd_net boolean flags to unsigned long flags word
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Mason <[email protected]>
[ Upstream commit 11a5fe42e1811f793e04ef885b639ea7668f439d ]
nfsd_net contains several boolean fields that are accessed from concurrent contexts without serialization. In particular, nfsd4_end_grace() guards its drain path with a plain bool:
if (nn->grace_ended)
return;
nn->grace_ended = true;The read and the write are independent, and nothing in struct nfsd_net serializes them. At least two contexts can reach this code with no lock held:
laundromat path
laundry_wq kworker
nfs4_laundromat()
nfsd4_end_grace()
RECLAIM_COMPLETE path
nfsd compound kthread
nfsd4_reclaim_complete()
inc_reclaim_complete()
nfsd4_end_grace()Both callers can observe grace_ended == false on different CPUs, both store true, and both proceed into nfsd4_record_grace_done(), which invokes the active client_tracking_ops->grace_done callback. For tracking ops that drain reclaim_str_hashtbl (legacy_tracking_ops via nfsd4_recdir_purge_old, and the cld v1+ ops via nfsd4_cld_grace_done), grace_done calls nfs4_release_reclaim(), which walks every bucket of reclaim_str_hashtbl with no lock and calls nfs4_remove_reclaim_record() (list_del + kfree) on each entry. Two concurrent walkers corrupt the list and double-free every nfs4_client_reclaim. A concurrent nfsd4_find_reclaim_client() iterating the same bucket reads through freed memory.
A third call site exists in nfs4_state_start_net() on the skip_grace startup path, but it runs under nfsd_mutex before any client has connected and before the laundromat's first delayed work fires, so it cannot race with the two callers above.
Replace the scattered boolean fields in nfsd_net with a single unsigned long flags word and an enum nfsd_net_flag for the bit positions. The grace_ended race is fixed by using test_and_set_bit(), which is atomic on all architectures. The remaining flags (grace_end_forced, in_grace, somebody_reclaimed, track_reclaim_completes, nfsd_net_up, lockd_up) are converted to use test_bit/set_bit/clear_bit for consistency. This avoids sub-word cmpxchg issues on architectures like Hexagon that only support word-sized atomic operations.
--- fs/nfsd/netns.h | 19 +++++++++++-------- fs/nfsd/nfs4proc.c | 2 +- fs/nfsd/nfs4recover.c | 12 ++++++------ fs/nfsd/nfs4state.c | 41 +++++++++++++++++++++++++---------------- fs/nfsd/nfsctl.c | 4 ++-- fs/nfsd/nfssvc.c | 22 +++++++++++----------- 6 files changed, 56 insertions(+), 44 deletions(-)
fs/nfsd/netns.h +11 -8
@@ -27,6 +27,16 @@struct cld_net ;struct nfsd4_client_tracking_ops ; +enum nfsd_net_flag { +NFSD_NET_GRACE_ENDED , +NFSD_NET_GRACE_END_FORCED , +NFSD_NET_IN_GRACE , +NFSD_NET_SOMEBODY_RECLAIMED , +NFSD_NET_TRACK_RECLAIM_COMPLETES , +NFSD_NET_UP , +NFSD_NET_LOCKD_UP , +}; +enum {/* cache misses due only to checksum comparison failures */ NFSD_STATS_PAYLOAD_MISSES ,
@@ -65,8 +75,7 @@ struct nfsd_net {struct cache_detail *nametoid_cache;struct lock_manager nfsd4_manager; -bool grace_ended; -bool grace_end_forced; +unsigned long flags;bool client_tracking_active;time64_t boot_time;time64_t boot_time_bt;/* same instant in CLOCK_BOOTTIME */
@@ -124,19 +133,13 @@ struct nfsd_net {spinlock_t blocked_locks_lock;struct file *rec_file; -bool in_grace;const struct nfsd4_client_tracking_ops *client_tracking_ops;time64_t nfsd4_lease;time64_t nfsd4_grace; -bool somebody_reclaimed; -bool track_reclaim_completes;atomic_t nr_reclaim_complete; -bool nfsd_net_up; -bool lockd_up; -seqlock_t writeverf_lock;unsigned char writeverf[8 ];
fs/nfsd/nfs4proc.c +1 -1
@@ -627,7 +627,7 @@ nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,pr_warn ("nfsd4_process_open2 failed to open newly-created file: status=%u\n" ,be32_to_cpu (status));if (reclaim && !status) - nn->somebody_reclaimed = true; +set_bit (NFSD_NET_SOMEBODY_RECLAIMED , &nn->flags); out:if (open->op_filp) {fput (open->op_filp);
fs/nfsd/nfs4recover.c +6 -6
@@ -229,7 +229,7 @@ nfsd4_create_clid_dir(struct nfs4_client *clp) out_unlock:inode_unlock (d_inode (dir));if (status ==0 ) { -if (nn->in_grace) +if (test_bit (NFSD_NET_IN_GRACE , &nn->flags))__nfsd4_create_reclaim_record_grace (clp, dname, nn);vfs_fsync (nn->rec_file,0 ); }else {
@@ -391,7 +391,7 @@ nfsd4_remove_clid_dir(struct nfs4_client *clp)nfs4_reset_creds (original_cred);if (status ==0 ) {vfs_fsync (nn->rec_file,0 ); -if (nn->in_grace) +if (test_bit (NFSD_NET_IN_GRACE , &nn->flags))__nfsd4_remove_reclaim_record_grace (dname,HEXDIR_LEN , nn); }
@@ -449,7 +449,7 @@ nfsd4_recdir_purge_old(struct nfsd_net *nn) {int status; - nn->in_grace = false; +clear_bit (NFSD_NET_IN_GRACE , &nn->flags);if (!nn->rec_file)return ; status =mnt_want_write_file (nn->rec_file);
@@ -531,7 +531,7 @@ nfsd4_init_recdir(struct net *net)nfs4_reset_creds (original_cred);if (!status) - nn->in_grace = true; +set_bit (NFSD_NET_IN_GRACE , &nn->flags);return status; }
@@ -1510,7 +1510,7 @@ nfs4_cld_state_init(struct net *net)INIT_LIST_HEAD (&nn->reclaim_str_hashtbl[i]); nn->reclaim_str_hashtbl_size =0 ;init_rwsem (&nn->reclaim_str_hashtbl_lock); - nn->track_reclaim_completes = true; +set_bit (NFSD_NET_TRACK_RECLAIM_COMPLETES , &nn->flags);atomic_set (&nn->nr_reclaim_complete,0 );return 0 ;
@@ -1521,7 +1521,7 @@ nfs4_cld_state_shutdown(struct net *net) {struct nfsd_net *nn =net_generic (net, nfsd_net_id); - nn->track_reclaim_completes = false; +clear_bit (NFSD_NET_TRACK_RECLAIM_COMPLETES , &nn->flags);kfree (nn->reclaim_str_hashtbl); }
fs/nfsd/nfs4state.c +25 -16
103 lines not on this page · raw message
fs/nfsd/nfsctl.c +2 -2
@@ -301,7 +301,7 @@ static ssize_t write_unlock_fs(struct file *file, char *buf, size_t size) error =nlmsvc_unlock_all_by_sb (path.dentry->d_sb);mutex_lock (&nfsd_mutex); nn =net_generic (netns (file), nfsd_net_id); -if (nn->nfsd_net_up) +if (test_bit (NFSD_NET_UP , &nn->flags))nfsd4_revoke_states (nn, path.dentry->d_sb);else error = -EINVAL ;
@@ -1150,7 +1150,7 @@ static ssize_t write_v4_end_grace(struct file *file, char *buf, size_t size) }return scnprintf (buf,SIMPLE_TRANSACTION_LIMIT ,"%c\n" , - nn->grace_ended ?'Y' :'N' ); +test_bit (NFSD_NET_GRACE_ENDED , &nn->flags) ?'Y' :'N' ); }#endif
fs/nfsd/nfssvc.c +11 -11
@@ -381,7 +381,7 @@ static int nfsd_startup_net(struct net *net, const struct cred *cred)struct nfsd_net *nn =net_generic (net, nfsd_net_id);int ret; -if (nn->nfsd_net_up) +if (test_bit (NFSD_NET_UP , &nn->flags))return 0 ; ret =nfsd_startup_generic ();
@@ -391,11 +391,11 @@ static int nfsd_startup_net(struct net *net, const struct cred *cred)if (ret) goto out_socks; -if (nfsd_needs_lockd (nn) && !nn->lockd_up) { +if (nfsd_needs_lockd (nn) && !test_bit (NFSD_NET_LOCKD_UP , &nn->flags)) { ret =lockd_up (net, cred);if (ret) goto out_socks; - nn->lockd_up = true; +set_bit (NFSD_NET_LOCKD_UP , &nn->flags); } ret =nfsd_file_cache_start_net (net);
@@ -413,7 +413,7 @@ static int nfsd_startup_net(struct net *net, const struct cred *cred)if (ret) goto out_reply_cache; - nn->nfsd_net_up = true; +set_bit (NFSD_NET_UP , &nn->flags);return 0 ; out_reply_cache:
@@ -421,9 +421,9 @@ static int nfsd_startup_net(struct net *net, const struct cred *cred) out_filecache:nfsd_file_cache_shutdown_net (net); out_lockd: -if (nn->lockd_up) { +if (test_bit (NFSD_NET_LOCKD_UP , &nn->flags)) {lockd_down (net); - nn->lockd_up = false; +clear_bit (NFSD_NET_LOCKD_UP , &nn->flags); } out_socks:nfsd_shutdown_generic ();
@@ -434,7 +434,7 @@ static void nfsd_shutdown_net(struct net *net) {struct nfsd_net *nn =net_generic (net, nfsd_net_id); -if (nn->nfsd_net_up) { +if (test_bit (NFSD_NET_UP , &nn->flags)) {percpu_ref_kill_and_confirm (&nn->nfsd_net_ref, nfsd_net_done);wait_for_completion (&nn->nfsd_net_confirm_done);
@@ -442,18 +442,18 @@ static void nfsd_shutdown_net(struct net *net)nfs4_state_shutdown_net (net);nfsd_reply_cache_shutdown (nn);nfsd_file_cache_shutdown_net (net); -if (nn->lockd_up) { +if (test_bit (NFSD_NET_LOCKD_UP , &nn->flags)) {lockd_down (net); - nn->lockd_up = false; +clear_bit (NFSD_NET_LOCKD_UP , &nn->flags); }wait_for_completion (&nn->nfsd_net_free_done); }percpu_ref_exit (&nn->nfsd_net_ref); -if (nn->nfsd_net_up) +if (test_bit (NFSD_NET_UP , &nn->flags))nfsd_shutdown_generic (); - nn->nfsd_net_up = false; +clear_bit (NFSD_NET_UP , &nn->flags); }static DEFINE_SPINLOCK (nfsd_notifier_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 717/869 mm/hugetlb: refactor code around vmemmap_walk
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kiryl Shutsemau <[email protected]>
[ Upstream commit c0b495b91a47b6c5ee54cf00e620dbadeb884253 ]
To prepare for removing fake head pages, the vmemmap_walk code is being reworked.
The reuse_page and reuse_addr variables are being eliminated. There will no longer be an expectation regarding the reuse address in relation to the operated range. Instead, the caller will provide head and tail vmemmap pages.
Currently, vmemmap_head and vmemmap_tail are set to the same page, but this will change in the future.
The only functional change is that __hugetlb_vmemmap_optimize_folio() will abandon optimization if memory allocation fails.
Stable-dep-of: b1b7c045e808 ("mm/hugetlb: initialize gigantic bootmem hugepage struct pages earlier")
--- mm/hugetlb_vmemmap.c | 224 +++++++++++++++++-------------------------- 1 file changed, 89 insertions(+), 135 deletions(-)
mm/hugetlb_vmemmap.c +89 -135
@@ -24,8 +24,8 @@* * @remap_pte: called for each lowest-level entry (PTE). * @nr_walked: the number of walked pte. -* @reuse_page: the page which is reused for the tail vmemmap pages. -* @reuse_addr: the virtual address of the @reuse_page page. +* @vmemmap_head: the page to be installed as first in the vmemmap range +* @vmemmap_tail: the page to be installed as non-first in the vmemmap range * @vmemmap_pages: the list head of the vmemmap pages that can be freed * or is mapped from. * @flags: used to modify behavior in vmemmap page table walking
@@ -34,11 +34,13 @@struct vmemmap_remap_walk {void (*remap_pte)(pte_t *pte,unsigned long addr,struct vmemmap_remap_walk *walk); +unsigned long nr_walked; -struct page *reuse_page; -unsigned long reuse_addr; +struct page *vmemmap_head; +struct page *vmemmap_tail;struct list_head *vmemmap_pages; +/* Skip the TLB flush when we split the PMD */ #define VMEMMAP_SPLIT_NO_TLB_FLUSH BIT(0)/* Skip the TLB flush when we remap the PTE */
@@ -140,14 +142,7 @@ static int vmemmap_pte_entry(pte_t *pte, unsigned long addr, {struct vmemmap_remap_walk *vmemmap_walk = walk->private; -/* -* The reuse_page is found 'first' in page table walking before -* starting remapping. -*/ -if (!vmemmap_walk->reuse_page) - vmemmap_walk->reuse_page =pte_page (ptep_get (pte)); -else - vmemmap_walk->remap_pte (pte, addr, vmemmap_walk); + vmemmap_walk->remap_pte (pte, addr, vmemmap_walk); vmemmap_walk->nr_walked++;return 0 ;
@@ -207,18 +202,12 @@ static void free_vmemmap_page_list(struct list_head *list)static void vmemmap_remap_pte (pte_t *pte,unsigned long addr,struct vmemmap_remap_walk *walk) { -/* -* Remap the tail pages as read-only to catch illegal write operation -* to the tail pages. -*/ -pgprot_t pgprot =PAGE_KERNEL_RO ;struct page *page =pte_page (ptep_get (pte));pte_t entry;/* Remapping the head page requires r/w */ -if (unlikely (addr == walk->reuse_addr)) { - pgprot =PAGE_KERNEL ; -list_del (&walk->reuse_page->lru); +if (unlikely (walk->nr_walked ==0 && walk->vmemmap_head)) { +list_del (&walk->vmemmap_head->lru);/* * Makes sure that preceding stores to the page contents from
@@ -226,53 +215,50 @@ static void vmemmap_remap_pte(pte_t *pte, unsigned long addr,* write. */ smp_wmb (); + + entry =mk_pte (walk->vmemmap_head,PAGE_KERNEL ); + }else { +/* +* Remap the tail pages as read-only to catch illegal write +* operation to the tail pages. +*/ + entry =mk_pte (walk->vmemmap_tail,PAGE_KERNEL_RO ); } - entry =mk_pte (walk->reuse_page, pgprot);list_add (&page->lru, walk->vmemmap_pages);set_pte_at (&init_mm, addr, pte, entry); } -/* -* How many struct page structs need to be reset. When we reuse the head -* struct page, the special metadata (e.g. page->flags or page->mapping) -* cannot copy to the tail struct page structs. The invalid value will be -* checked in the free_tail_page_prepare(). In order to avoid the message -* of "corrupted mapping in tail page". We need to reset at least 4 (one -* head struct page struct and three tail struct page structs) struct page -* structs. -*/ -#define NR_RESET_STRUCT_PAGE 4 - -static inline void reset_struct_pages (struct page *start) -{ -struct page *from = start +NR_RESET_STRUCT_PAGE ; - -BUILD_BUG_ON (NR_RESET_STRUCT_PAGE *2 >PAGE_SIZE /sizeof (struct page )); -memcpy (start, from,sizeof (*from) *NR_RESET_STRUCT_PAGE ); -} -static void vmemmap_restore_pte (pte_t *pte,unsigned long addr,struct vmemmap_remap_walk *walk) { -pgprot_t pgprot =PAGE_KERNEL ;struct page *page; -void *to; - -BUG_ON (pte_page (ptep_get (pte)) != walk->reuse_page); +struct page *from, *to; page = list_first_entry(walk->vmemmap_pages, struct page, lru);list_del (&page->lru); + +/* +* Initialize tail pages in the newly allocated vmemmap page. +* +* There is folio-scope metadata that is encoded in the first few +* tail pages. +* +* Use the value last tail page in the page with the head page +* to initialize the rest of tail pages. +*/ + from =compound_head ((struct page *)addr) + +PAGE_SIZE /sizeof (struct page ) -1 ; to =page_to_virt (page); -copy_page (to, (void *)walk->reuse_addr); -reset_struct_pages (to); +for (int i =0 ; i <PAGE_SIZE /sizeof (struct page ); i++, to++) + *to = *from;/* * Makes sure that preceding stores to the page contents become visible * before the set_pte_at() write. */ smp_wmb (); -set_pte_at (&init_mm, addr, pte,mk_pte (page, pgprot)); +set_pte_at (&init_mm, addr, pte,mk_pte (page,PAGE_KERNEL )); }/**
@@ -282,33 +268,28 @@ static void vmemmap_restore_pte(pte_t *pte, unsigned long addr,* to remap. * @end: end address of the vmemmap virtual address range that we want to * remap. -* @reuse: reuse address. -* * Return: %0 on success, negative error code otherwise. */ -static int vmemmap_remap_split (unsigned long start,unsigned long end, -unsigned long reuse) +static int vmemmap_remap_split (unsigned long start,unsigned long end) {struct vmemmap_remap_walk walk = { .remap_pte =NULL , .flags =VMEMMAP_SPLIT_NO_TLB_FLUSH , }; -/* See the comment in the vmemmap_remap_free(). */ -BUG_ON (start - reuse !=PAGE_SIZE ); - -return vmemmap_remap_range (reuse, end, &walk); +return vmemmap_remap_range (start, end, &walk); }/** * vmemmap_remap_free - remap the vmemmap virtual address range [@start, @end) -* to the page which @reuse is mapped to, then free vmemmap -* which the range are mapped to. +* to use @vmemmap_head/tail, then free vmemmap which +* the range are mapped to. * @start: start address of the vmemmap virtual address range that we want * to remap. * @end: end address of the vmemmap virtual address range that we want to * remap. -* @reuse: reuse address. +* @vmemmap_head: the page to be installed as first in the vmemmap range +* @vmemmap_tail: the page to be installed as non-first in the vmemmap range * @vmemmap_pages: list to deposit vmemmap pages to be freed. It is callers * responsibility to free pages. * @flags: modifications to vmemmap_remap_walk flags
@@ -316,69 +297,38 @@ static int vmemmap_remap_split(unsigned long start, unsigned long end,* Return: %0 on success, negative error code otherwise. */ static int vmemmap_remap_free (unsigned long start,unsigned long end, -unsigned long reuse, +struct page *vmemmap_head, +struct page *vmemmap_tail,struct list_head *vmemmap_pages,unsigned long flags) {int ret;struct vmemmap_remap_walk walk = { .remap_pte = vmemmap_remap_pte, - .reuse_addr = reuse, + .vmemmap_head = vmemmap_head, + .vmemmap_tail = vmemmap_tail, .vmemmap_pages = vmemmap_pages, .flags = flags, }; -int nid =page_to_nid ((struct page *)reuse); -gfp_t gfp_mask =GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN; -/* -* Allocate a new head vmemmap page to avoid breaking a contiguous -* block of struct page memory when freeing it back to page allocator -* in free_vmemmap_page_list(). This will allow the likely contiguous -* struct page backing memory to be kept contiguous and allowing for -* more allocations of hugepages. Fallback to the currently -* mapped head page in case should it fail to allocate. -*/ - walk.reuse_page =alloc_pages_node (nid, gfp_mask,0 ); -if (walk.reuse_page) { -copy_page (page_to_virt (walk.reuse_page), - (void *)walk.reuse_addr); -list_add (&walk.reuse_page->lru, vmemmap_pages); -memmap_pages_add (1 ); - } + ret =vmemmap_remap_range (start, end, &walk); +if (!ret || !walk.nr_walked) +return ret; + + end = start + walk.nr_walked *PAGE_SIZE ;/* -* In order to make remapping routine most efficient for the huge pages, -* the routine of vmemmap page table walking has the following rules -* (see more details from the vmemmap_pte_range()): -* -* - The range [@start, @end) and the range [@reuse, @reuse + PAGE_SIZE) -* should be continuous. -* - The @reuse address is part of the range [@reuse, @end) that we are -* walking which is passed to vmemmap_remap_range(). -* - The @reuse address is the first in the complete range. -* -* So we need to make sure that @start and @reuse meet the above rules. +* vmemmap_pages contains pages from the previous vmemmap_remap_range() +* call which failed. These are pages which were removed from +* the vmemmap. They will be restored in the following call. */ -BUG_ON (start - reuse !=PAGE_SIZE ); + walk = (struct vmemmap_remap_walk ) { + .remap_pte = vmemmap_restore_pte, + .vmemmap_pages = vmemmap_pages, + .flags =0 , + }; - ret =vmemmap_remap_range (reuse, end, &walk); -if (ret && walk.nr_walked) { - end = reuse + walk.nr_walked *PAGE_SIZE ; -/* -* vmemmap_pages contains pages from the previous -* vmemmap_remap_range call which failed. These -* are pages which were removed from the vmemmap. -* They will be restored in the following call. -*/ - walk = (struct vmemmap_remap_walk ) { - .remap_pte = vmemmap_restore_pte, - .reuse_addr = reuse, - .vmemmap_pages = vmemmap_pages, - .flags =0 , - }; - -vmemmap_remap_range (reuse, end, &walk); - } +vmemmap_remap_range (start, end, &walk);return ret; }
@@ -415,29 +365,24 @@ static int alloc_vmemmap_page_list(unsigned long start, unsigned long end,* to remap. * @end: end address of the vmemmap virtual address range that we want to * remap. -* @reuse: reuse address. * @flags: modifications to vmemmap_remap_walk flags * * Return: %0 on success, negative error code otherwise. */ static int vmemmap_remap_alloc (unsigned long start,unsigned long end, -unsigned long reuse,unsigned long flags) +unsigned long flags) {LIST_HEAD (vmemmap_pages);struct vmemmap_remap_walk walk = { .remap_pte = vmemmap_restore_pte, - .reuse_addr = reuse, .vmemmap_pages = &vmemmap_pages, .flags = flags, }; -/* See the comment in the vmemmap_remap_free(). */ -BUG_ON (start - reuse !=PAGE_SIZE ); -if (alloc_vmemmap_page_list (start, end, &vmemmap_pages))return -ENOMEM ; -return vmemmap_remap_range (reuse, end, &walk); +return vmemmap_remap_range (start, end, &walk); }DEFINE_STATIC_KEY_FALSE (hugetlb_optimize_vmemmap_key);
@@ -450,8 +395,7 @@ static int __hugetlb_vmemmap_restore_folio(const struct hstate *h, struct folio *folio, unsigned long flags) { int ret; -unsigned long vmemmap_start = (unsigned long )&folio->page, vmemmap_end; -unsigned long vmemmap_reuse; +unsigned long vmemmap_start, vmemmap_end;VM_WARN_ON_ONCE_FOLIO (!folio_test_hugetlb (folio), folio);VM_WARN_ON_ONCE_FOLIO (folio_ref_count (folio), folio);
@@ -462,18 +406,18 @@ static int __hugetlb_vmemmap_restore_folio(const struct hstate *h,if (flags &VMEMMAP_SYNCHRONIZE_RCU )synchronize_rcu (); + vmemmap_start = (unsigned long )&folio->page; vmemmap_end = vmemmap_start +hugetlb_vmemmap_size (h); - vmemmap_reuse = vmemmap_start; + vmemmap_start +=HUGETLB_VMEMMAP_RESERVE_SIZE ;/* * The pages which the vmemmap virtual address range [@vmemmap_start, -* @vmemmap_end) are mapped to are freed to the buddy allocator, and -* the range is mapped to the page which @vmemmap_reuse is mapped to. +* @vmemmap_end) are mapped to are freed to the buddy allocator. * When a HugeTLB page is freed to the buddy allocator, previously * discarded vmemmap pages must be allocated and remapping. */ - ret =vmemmap_remap_alloc (vmemmap_start, vmemmap_end, vmemmap_reuse, flags); + ret =vmemmap_remap_alloc (vmemmap_start, vmemmap_end, flags);if (!ret) {folio_clear_hugetlb_vmemmap_optimized (folio);static_branch_dec (&hugetlb_optimize_vmemmap_key);
@@ -561,9 +505,9 @@ static int __hugetlb_vmemmap_optimize_folio(const struct hstate *h, struct list_head *vmemmap_pages, unsigned long flags) { - int ret = 0; -unsigned long vmemmap_start = (unsigned long )&folio->page, vmemmap_end; -unsigned long vmemmap_reuse; +unsigned long vmemmap_start, vmemmap_end; +struct page *vmemmap_head, *vmemmap_tail; +int nid, ret =0 ;VM_WARN_ON_ONCE_FOLIO (!folio_test_hugetlb (folio), folio);VM_WARN_ON_ONCE_FOLIO (folio_ref_count (folio), folio);
@@ -588,18 +532,30 @@ static int __hugetlb_vmemmap_optimize_folio(const struct hstate *h,*/ folio_set_hugetlb_vmemmap_optimized (folio); + nid =folio_nid (folio); + vmemmap_head =alloc_pages_node (nid,GFP_KERNEL ,0 ); +if (!vmemmap_head) { + ret = -ENOMEM ; + goto out; + } + +copy_page (page_to_virt (vmemmap_head), folio); +list_add (&vmemmap_head->lru, vmemmap_pages); +memmap_pages_add (1 ); + + vmemmap_tail = vmemmap_head; + vmemmap_start = (unsigned long )&folio->page; vmemmap_end = vmemmap_start +hugetlb_vmemmap_size (h); - vmemmap_reuse = vmemmap_start; - vmemmap_start +=HUGETLB_VMEMMAP_RESERVE_SIZE ;/* -* Remap the vmemmap virtual address range [@vmemmap_start, @vmemmap_end) -* to the page which @vmemmap_reuse is mapped to. Add pages previously -* mapping the range to vmemmap_pages list so that they can be freed by -* the caller. +* Remap the vmemmap virtual address range [@vmemmap_start, @vmemmap_end). +* Add pages previously mapping the range to vmemmap_pages list so that +* they can be freed by the caller. */ - ret =vmemmap_remap_free (vmemmap_start, vmemmap_end, vmemmap_reuse, + ret =vmemmap_remap_free (vmemmap_start, vmemmap_end, + vmemmap_head, vmemmap_tail, vmemmap_pages, flags); +out:if (ret) {static_branch_dec (&hugetlb_optimize_vmemmap_key);folio_clear_hugetlb_vmemmap_optimized (folio);
@@ -628,21 +584,19 @@ void hugetlb_vmemmap_optimize_folio(const struct hstate *h, struct folio *folio)static int hugetlb_vmemmap_split_folio (const struct hstate *h,struct folio *folio) { -unsigned long vmemmap_start = (unsigned long )&folio->page, vmemmap_end; -unsigned long vmemmap_reuse; +unsigned long vmemmap_start, vmemmap_end;if (!vmemmap_should_optimize_folio (h, folio))return 0 ; + vmemmap_start = (unsigned long )&folio->page; vmemmap_end = vmemmap_start +hugetlb_vmemmap_size (h); - vmemmap_reuse = vmemmap_start; - vmemmap_start +=HUGETLB_VMEMMAP_RESERVE_SIZE ;/* * Split PMDs on the vmemmap virtual address range [@vmemmap_start, * @vmemmap_end] */ -return vmemmap_remap_split (vmemmap_start, vmemmap_end, vmemmap_reuse); +return vmemmap_remap_split (vmemmap_start, vmemmap_end); }void hugetlb_vmemmap_optimize_folios (struct hstate *h,struct list_head *folio_list)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 718/869 mm/hugetlb: initialize gigantic bootmem hugepage struct pages earlier
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muchun Song <[email protected]>
[ Upstream commit b1b7c045e808c761b1cc8c19b3040fadedda3fef ]
Gigantic bootmem HugeTLB pages are currently initialized from hugetlb_init(), but page_alloc_init_late() runs earlier and walks pageblocks to determine zone contiguity.
If a bootmem HugeTLB region is marked noinit, set_zone_contiguous() can observe still-uninitialized struct pages through __pageblock_pfn_to_page(). This may not trigger an immediate failure, but it can make set_zone_contiguous() compute the wrong zone contiguity state. If extra poisoned-page checks are added in this path, such as PF_POISONED_CHECK() in page_zone_id(), it can also trigger an early boot panic.
Initialize gigantic bootmem HugeTLB struct pages from page_alloc_init_late(), before zone contiguity is evaluated, so later page allocator setup only sees valid struct page state. This also makes the initialization order more natural, as struct pages should be initialized before later code inspects them.
--- include/linux/hugetlb.h | 6 ++++++ mm/hugetlb.c | 9 ++++++--- mm/mm_init.c | 2 ++ 3 files changed, 14 insertions(+), 3 deletions(-)
include/linux/hugetlb.h +6 -0
@@ -172,6 +172,8 @@ struct address_space *hugetlb_folio_mapping_lock_write(struct folio *folio);extern int sysctl_hugetlb_shm_group;extern struct list_head huge_boot_pages[MAX_NUMNODES ]; +void hugetlb_bootmem_struct_page_init (void ); +/* arch callbacks */ #ifndef CONFIG_HIGHPTE
@@ -1265,6 +1267,10 @@ static inline bool hugetlbfs_pagecache_present( {return false; } + +static inline void hugetlb_bootmem_struct_page_init (void ) +{ +}#endif /* CONFIG_HUGETLB_PAGE */ static inline spinlock_t *huge_pte_lock(struct hstate *h,
mm/hugetlb.c +6 -3
@@ -3260,6 +3260,10 @@ static void __init gather_bootmem_prealloc_node(unsigned long nid)struct huge_bootmem_page *m;struct hstate *h =NULL , *prev_h =NULL ; +/* The lists are only initialized once a gigantic hstate was allocated. */ +if (!huge_boot_pages[nid].next) +return ; +list_for_each_entry (m, &huge_boot_pages[nid], list) {struct page *page =virt_to_page (m);struct folio *folio = (void *)page;
@@ -3302,7 +3306,7 @@ static void __init gather_bootmem_prealloc_parallel(unsigned long start,gather_bootmem_prealloc_node (nid); } -static void __init gather_bootmem_prealloc (void ) +void __init hugetlb_bootmem_struct_page_init (void ) {struct padata_mt_job job = { .thread_fn = gather_bootmem_prealloc_parallel,
@@ -3457,7 +3461,7 @@ static unsigned long __init hugetlb_pages_alloc_boot(struct hstate *h)* - For gigantic pages, this is called early in the boot process and * pages are allocated from memblock allocated or something similar. * Gigantic pages are actually added to pools later with the routine -* gather_bootmem_prealloc. +* hugetlb_bootmem_struct_page_init. * - For non-gigantic pages, this is called later in the boot process after * all of mm is up and functional. Pages are allocated from buddy and * then added to hugetlb pools.
@@ -4496,7 +4500,6 @@ static int __init hugetlb_init(void)hugetlb_cma_check ();hugetlb_init_hstates (); -gather_bootmem_prealloc ();report_hugepages ();hugetlb_sysfs_init ();
mm/mm_init.c +2 -0
@@ -29,6 +29,7 @@#include <linux/cma.h> #include <linux/crash_dump.h> #include <linux/execmem.h> +#include <linux/hugetlb.h> #include <linux/vmstat.h> #include "internal.h" #include "slab.h"
@@ -2320,6 +2321,7 @@ void __init page_alloc_init_late(void)/* Reinit limits that are based on free pages after the kernel is up */ files_maxfiles_init ();#endif +hugetlb_bootmem_struct_page_init ();/* Accounting of total+free memory is stable at this point. */ mem_init_print_info ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 719/869 ACPI: bus: Introduce acpi_bus_get_primary_device()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rafael J. Wysocki <[email protected]>
[ Upstream commit 72530e1f72b0515a73fd88292254d04fecf03649 ]
The function used for obtaining the first "physical" device for which the given ACPI one is the ACPI companion, acpi_get_first_physical_node(), may return a stale device pointer (mostly in theory) because acpi_unbind_one() may run as a whole after dropping the ACPI device's physical_node_lock in acpi_get_first_physical_node() and before it returns. The last reference to the "physical" device may be dropped then before the pointer to it is returned to the caller.
If that happens and the acpi_get_first_physical_node() caller invokes get_device() on the pointer obtained from it, which is done by the majority of its callers, a use-after-free will occur.
To prepare for addressing this problem, introduce a new function for getting the first "physical" device associated with the given ACPI one (the "primary physical device") that will also reference count the device in question before returning a pointer to it.
Make that new function and acpi_get_first_physical_node() share the physical node list lookup code.
No intentional functional impact.
--- drivers/acpi/bus.c | 54 +++++++++++++++++++++++++++++------------ include/acpi/acpi_bus.h | 6 +++++ 2 files changed, 44 insertions(+), 16 deletions(-)
drivers/acpi/bus.c +38 -16
@@ -747,30 +747,52 @@ static int __init acpi_setup_sb_notify_handler(void)Device Matching -------------------------------------------------------------------------- */ + +static struct device *primary_physical_device (struct acpi_device *adev) +{ +struct acpi_device_physical_node *pn; + + pn =list_first_entry_or_null (&adev->physical_node_list, + struct acpi_device_physical_node, node); +if (pn) +return pn->dev; + +return NULL ; +} +/** -* acpi_get_first_physical_node - Get first physical node of an ACPI device +* acpi_bus_get_primary_device - Get first physical device for a given ACPI one +* @adev: ACPI device to get the first physical device for. +* +* Find the first physical device for which @adev is the ACPI companion and +* reference count it if present. +* +* Return: Pointer to the first physical counterpart of @adev or NULL if there +* are none. Callers are responsible for invoking put_device() on the returned +* device. +*/ +struct device *acpi_bus_get_primary_device (struct acpi_device *adev) +{ +if (!adev) +return NULL ; + +guard (mutex)(&adev->physical_node_lock); + +return get_device (primary_physical_device (adev)); +} +EXPORT_SYMBOL_GPL (acpi_bus_get_primary_device); + +/** +* acpi_get_first_physical_node - Find first physical node of an ACPI device * @adev: ACPI device in question * * Return: First physical node of ACPI device @adev */ struct device *acpi_get_first_physical_node (struct acpi_device *adev) { -struct mutex *physical_node_lock = &adev->physical_node_lock; -struct device *phys_dev; - -mutex_lock (physical_node_lock); -if (list_empty (&adev->physical_node_list)) { - phys_dev =NULL ; - }else { -const struct acpi_device_physical_node *node; +guard (mutex)(&adev->physical_node_lock); - node =list_first_entry (&adev->physical_node_list, - struct acpi_device_physical_node, node); - - phys_dev = node->dev; - } -mutex_unlock (physical_node_lock); -return phys_dev; +return primary_physical_device (adev); }EXPORT_SYMBOL_GPL (acpi_get_first_physical_node);
include/acpi/acpi_bus.h +6 -0
@@ -677,6 +677,7 @@ void acpi_bus_unregister_driver(struct acpi_driver *driver);int acpi_bus_scan (acpi_handle handle);void acpi_bus_trim (struct acpi_device *start);acpi_status acpi_bus_get_ejd (acpi_handle handle,acpi_handle * ejd); +struct device *acpi_bus_get_primary_device (struct acpi_device *adev);int acpi_match_device_ids (struct acpi_device *device,const struct acpi_device_id *ids); void acpi_set_modalias(struct acpi_device *adev, const char *default_id,
@@ -1000,6 +1001,11 @@ int acpi_scan_add_dep(acpi_handle handle, struct acpi_handle_list *dep_devices);u32 arch_acpi_add_auto_dep (acpi_handle handle);#else /* CONFIG_ACPI */ +static inline struct device *acpi_bus_get_primary_device (struct acpi_device *adev) +{ +return NULL ; +} +static inline int register_acpi_bus_type (void *bus) {return 0 ; }static inline int unregister_acpi_bus_type (void *bus) {return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 720/869 powerpc/xive: add error return value to xive_smp_probe()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gou Hao <[email protected]>
[ Upstream commit ab5ae5dceb86614f6c9e7488f91b652000edfdc5 ]
xive_smp_probe() calls xive_init_ipis() which can fail, but its return value is currently ignored. Change xive_smp_probe() to return int so that errors can be propagated to callers.
This is a preparatory patch for the next one.
No functional change yet; the return value is always 0 at this point.
Stable-dep-of: 411a3c016e7a ("powerpc/xive: propagate IPI init errors to prevent use-after-free")
--- arch/powerpc/include/asm/xive.h | 4 ++-- arch/powerpc/sysdev/xive/common.c | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-)
arch/powerpc/include/asm/xive.h +2 -2
@@ -91,7 +91,7 @@ static inline bool xive_enabled(void) { return __xive_enabled; }bool xive_spapr_init (void );bool xive_native_init (void ); -void xive_smp_probe (void ); +int xive_smp_probe (void );int xive_smp_prepare_cpu (unsigned int cpu);void xive_smp_setup_cpu (void );void xive_smp_disable_cpu (void );
@@ -154,7 +154,7 @@ static inline bool xive_enabled(void) { return false; }static inline bool xive_spapr_init (void ) {return false; }static inline bool xive_native_init (void ) {return false; } -static inline void xive_smp_probe (void ) { } +static inline int xive_smp_probe (void ) {return -EINVAL ; }static inline int xive_smp_prepare_cpu (unsigned int cpu) {return -EINVAL ; }static inline void xive_smp_setup_cpu (void ) { }static inline void xive_smp_disable_cpu (void ) { }
arch/powerpc/sysdev/xive/common.c +3 -1
@@ -1270,7 +1270,7 @@ noinstr static void xive_cleanup_cpu_ipi(unsigned int cpu, struct xive_cpu *xc) xive_ops->put_ipi (cpu, xc); } -void __init xive_smp_probe (void ) +int __init xive_smp_probe (void ) { smp_ops->cause_ipi = xive_cause_ipi;
@@ -1279,6 +1279,8 @@ void __init xive_smp_probe(void)/* Allocate and setup IPI for the boot CPU */ xive_setup_cpu_ipi (smp_processor_id ()); + + return 0; }#endif /* CONFIG_SMP */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 721/869 powerpc/xive: propagate IPI init errors to prevent use-after-free
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gou Hao <[email protected]>
[ Upstream commit 411a3c016e7a95f5fa105a0587e07d0647a77727 ]
When xive_init_ipis() fails (e.g. irq_domain_alloc_irqs() fails), the error path frees the global xive_ipis array. However, xive_smp_probe() previously ignored this failure and proceeded to call xive_setup_cpu_ipi(), which dereferences the already-freed xive_ipis pointer -- a use-after-free.
Now that xive_smp_probe() returns int (previous patch), propagate the error from xive_init_ipis() and xive_setup_cpu_ipi() through xive_smp_probe(). Check the return value in both pnv_smp_probe() and pSeries_smp_probe() so that IPI setup is aborted cleanly on failure, avoiding the use-after-free.
--- arch/powerpc/platforms/powernv/smp.c | 8 +++++--- arch/powerpc/platforms/pseries/smp.c | 8 +++++--- arch/powerpc/sysdev/xive/common.c | 10 ++++++---- 3 files changed, 16 insertions(+), 10 deletions(-)
arch/powerpc/platforms/powernv/smp.c +5 -3
@@ -329,10 +329,12 @@ static void pnv_cause_ipi(int cpu)static void __init pnv_smp_probe (void ) { -if (xive_enabled ()) -xive_smp_probe (); -else +if (xive_enabled ()) { +if (xive_smp_probe () <0 ) +return ; + }else {xics_smp_probe (); + }if (cpu_has_feature (CPU_FTR_DBELL )) { ic_cause_ipi = smp_ops->cause_ipi;
arch/powerpc/platforms/pseries/smp.c +5 -3
@@ -194,10 +194,12 @@ static int pseries_cause_nmi_ipi(int cpu)static __init void pSeries_smp_probe (void ) { -if (xive_enabled ()) -xive_smp_probe (); -else +if (xive_enabled ()) { +if (xive_smp_probe () <0 ) +return ; + }else {xics_smp_probe (); + }/* No doorbell facility, must use the interrupt controller for IPIs */ if (!cpu_has_feature (CPU_FTR_DBELL ))
arch/powerpc/sysdev/xive/common.c +6 -4
@@ -1272,15 +1272,17 @@ noinstr static void xive_cleanup_cpu_ipi(unsigned int cpu, struct xive_cpu *xc)int __init xive_smp_probe (void ) { +int ret; + smp_ops->cause_ipi = xive_cause_ipi;/* Register the IPI */ -xive_init_ipis (); + ret =xive_init_ipis (); +if (ret <0 ) +return ret;/* Allocate and setup IPI for the boot CPU */ -xive_setup_cpu_ipi (smp_processor_id ()); - -return 0 ; +return xive_setup_cpu_ipi (smp_processor_id ()); }#endif /* CONFIG_SMP */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 722/869 remoteproc: qcom_wcnss: Fix handling the lack of PD regulators in v3
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Val Packett <[email protected]>
[ Upstream commit 3dbc90b9c22ea96e37bf55f6011e63b5123ec668 ]
The changes introduced to handle single power domain platforms have swapped the info pointer increment from num_pd_vregs to num_pds, which would shift the info pointer past the end of the array for pronto-v3, which does not list power domain regulators in vregs.
This showed up as a difference between GCC- and LLVM-compiled kernels on SDM632 devices, where only with LLVM one would get the "regulator request with no identifier" error, because the out-of-bounds memory ended up being zeroed. Fix by skipping the increment when there are more power domains than regulators.
--- drivers/remoteproc/qcom_wcnss.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
drivers/remoteproc/qcom_wcnss.c +14 -9
@@ -441,25 +441,31 @@ static void wcnss_release_pds(struct qcom_wcnss *wcnss) }static int wcnss_init_regulators (struct qcom_wcnss *wcnss, -const struct wcnss_vreg_info *info, -int num_vregs,int num_pd_vregs) +const struct wcnss_data *data) { +const struct wcnss_vreg_info *info = data->vregs;struct regulator_bulk_data *bulk; +size_t i, possible_pds =0 , num_vregs = data->num_vregs;int ret; -int i; + +for (i =0 ; i <WCNSS_MAX_PDS ; i++) +if (data->pd_names[i]) + possible_pds++;/* * If attaching the power domains suceeded we can skip requesting * the regulators for the power domains. For old device trees we need to * reserve extra space to manage them through the regulator interface. */ -if (wcnss->num_pds) { +if (possible_pds >= num_vregs) { +/* Do nothing if vregs do not include PD regulators (pronto-v3) */ + }else if (wcnss->num_pds) { info += wcnss->num_pds;/* Handle single power domain case */ -if (wcnss->num_pds < num_pd_vregs) - num_vregs += num_pd_vregs - wcnss->num_pds; +if (wcnss->num_pds < data->num_pd_vregs) + num_vregs += data->num_pd_vregs - wcnss->num_pds; }else { - num_vregs += num_pd_vregs; + num_vregs += data->num_pd_vregs; } bulk = devm_kcalloc(wcnss->dev,
@@ -612,8 +618,7 @@ static int wcnss_probe(struct platform_device *pdev)if (ret && (ret != -ENODATA || !data->num_pd_vregs))return ret; - ret =wcnss_init_regulators (wcnss, data->vregs, data->num_vregs, - data->num_pd_vregs); + ret =wcnss_init_regulators (wcnss, data);if (ret) goto detach_pds;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 723/869 ksmbd: remove redundant DACL check in smb_check_perm_dacl
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexey Velichayshiy <[email protected]>
[ Upstream commit 8dd2e58b62731a96e276ee0545fb910ffb2057d9 ]
A zero value of pdacl->num_aces is already handled at the start of smb_check_perm_dacl() so the second check is useless.
Drop the unreachable code block, no functional impact intended.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Stable-dep-of: cc2f133e80eb ("ksmbd: fix maximum allowed access checks")
--- fs/smb/server/smbacl.c | 3 --- 1 file changed, 3 deletions(-)
fs/smb/server/smbacl.c +0 -3
@@ -1511,9 +1511,6 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, const struct path *path, granted |=le32_to_cpu (ace->access_req); ace = (struct smb_ace *)((char *)ace +le16_to_cpu (ace->size)); } - -if (!pdacl->num_aces) - granted =GENERIC_ALL_FLAGS ; }if (!uid)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 724/869 ksmbd: fix maximum allowed access checks
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
[ Upstream commit cc2f133e80eb2c4a04bfa77a2f207749fe2f516a ]
The DACL permission check looks for an ACE matching the current user and falls back to the Everyone ACE. It does not consider an Authenticated Users ACE, even though an authenticated session is a member of that well-known group.
As a result, opening a file whose access is granted through S-1-5-11 can incorrectly fail with STATUS_ACCESS_DENIED. Treat an Authenticated Users ACE as a fallback entry alongside Everyone.
The maximal access calculation also combines access masks from every ACE, regardless of whether its SID applies to the current user. This can grant rights belonging to an unrelated principal. Process only ACEs applying to the user, Everyone, or Authenticated Users, and accumulate allowed and denied masks in ACL order. Preserve explicitly requested access bits so they are validated against the resulting maximal mask.
When ACCESS_SYSTEM_SECURITY is denied, report STATUS_PRIVILEGE_NOT_HELD instead of the generic STATUS_ACCESS_DENIED. Access to the system ACL requires a security privilege that ksmbd does not grant.
For regular files, include FILE_EXECUTE in maximal access when the client requested GENERIC_EXECUTE and the DACL grants the complete file-read set. Keep a direct FILE_EXECUTE request subject to the explicit DACL bit. This matches the POSIX file ACL mapping without broadening specific execute requests.
Do not replace rights from an applicable NT ACE with a POSIX ACL entry. The POSIX ACL is only a fallback when no user, Everyone, or Authenticated Users ACE applies; otherwise it can incorrectly broaden the stored DACL.
This fixes smb2.maximum_allowed.maximum_allowed.
--- fs/smb/server/smb2pdu.c | 9 ++++- fs/smb/server/smbacl.c | 83 ++++++++++++++++++++++++++--------------- fs/smb/server/smbacl.h | 2 +- 3 files changed, 61 insertions(+), 33 deletions(-)
fs/smb/server/smb2pdu.c +7 -2
@@ -3269,6 +3269,7 @@ int smb2_open(struct ksmbd_work *work)if (file_present && !(req->CreateOptions &FILE_DELETE_ON_CLOSE_LE )) { rc =smb_check_perm_dacl (conn, &path, &daccess, + req->DesiredAccess, sess->user->uid);if (rc) goto err_out;
@@ -3813,8 +3814,12 @@ int smb2_open(struct ksmbd_work *work) rsp->hdr.Status =STATUS_INVALID_PARAMETER ; else if (rc == -EOPNOTSUPP) rsp->hdr.Status = STATUS_NOT_SUPPORTED; - else if (rc == -EACCES || rc == -ESTALE || rc == -EXDEV) - rsp->hdr.Status =STATUS_ACCESS_DENIED ; + else if (rc == -EACCES || rc == -ESTALE || rc == -EXDEV) { +if (req->DesiredAccess &FILE_ACCESS_SYSTEM_SECURITY_LE ) + rsp->hdr.Status =STATUS_PRIVILEGE_NOT_HELD ; +else + rsp->hdr.Status =STATUS_ACCESS_DENIED ; + } else if (rc == -ENOENT) rsp->hdr.Status = STATUS_OBJECT_NAME_INVALID; else if (rc == -EPERM)
fs/smb/server/smbacl.c +53 -30
134 lines not on this page · raw message
fs/smb/server/smbacl.h +1 -1
@@ -95,7 +95,7 @@ bool smb_inherit_flags(int flags, bool is_dir);int smb_inherit_dacl (struct ksmbd_conn *conn,const struct path *path,unsigned int uid,unsigned int gid);int smb_check_perm_dacl (struct ksmbd_conn *conn,const struct path *path, -__le32 *pdaccess,int uid); +__le32 *pdaccess,__le32 raw_daccess,int uid);int set_info_sec (struct ksmbd_conn *conn,struct ksmbd_tree_connect *tcon,const struct path *path,struct smb_ntsd *pntsd,int ntsd_len,bool type_check,bool get_write);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 725/869 drm/amdkfd: fix SMI event cross-process information leak
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yongqiang Sun <[email protected]>
[ Upstream commit 92a8dba246d371fe268280e5fd74b0955688e6df ]
kfd_smi_ev_enabled() skips the suser privilege check when pid=0. PROCESS_START, PROCESS_END, and VMFAULT events are emitted with pid=0 while carrying another process's PID and command name, so any /dev/kfd user in the render group can monitor all GPU workloads.
Pass the target process PID into kfd_smi_event_add() for these events so the existing per-client filter restricts delivery to the owning process or CAP_SYS_ADMIN subscribers.
--- drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c +4 -2
@@ -255,8 +255,10 @@ void kfd_smi_event_update_vmfault(struct kfd_node *dev, uint16_t pasid)if (task_info) {/* Report VM faults from user applications, not retry from kernel */ if (task_info->pid) -kfd_smi_event_add (0 , dev,KFD_SMI_EVENT_VMFAULT ,KFD_EVENT_FMT_VMFAULT ( - task_info->pid, task_info->task_name)); +kfd_smi_event_add (task_info->tgid, dev, +KFD_SMI_EVENT_VMFAULT , +KFD_EVENT_FMT_VMFAULT (task_info->pid, + task_info->task_name));amdgpu_vm_put_task_info (task_info); } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 726/869 drm/amdgpu: Update SRIOV Exchange Headers for RAS Telemetry Support
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Victor Skvortsov <[email protected]>
[ Upstream commit 60c58d72afb81d2dc3f52f638eff5197511ac114 ]
The SRIOV PF/VF Data exchange is extended by 64KB for VF RAS Telemetry data. Add Host RAS Telemetry enable capabilities bitfields.
Add a new VF msg REQ_RAS_ERROR_COUNT, the host response data will be populated in the RAS Telemetry region.
Stable-dep-of: e3829992dd9f ("drm/amdgpu/ras: add ras_suspend callback and use it for cp_ecc_error_irq")
--- drivers/gpu/drm/amd/amdgpu/amdgv_sriovmsg.h | 131 +++++++++++++++++--- drivers/gpu/drm/amd/amdgpu/mxgpu_nv.h | 3 + 2 files changed, 115 insertions(+), 19 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgv_sriovmsg.h +112 -19
@@ -28,17 +28,21 @@#define AMD_SRIOV_MSG_VBIOS_SIZE_KB 64#define AMD_SRIOV_MSG_DATAEXCHANGE_OFFSET_KB AMD_SRIOV_MSG_VBIOS_SIZE_KB#define AMD_SRIOV_MSG_DATAEXCHANGE_SIZE_KB 4 - +#define AMD_SRIOV_MSG_TMR_OFFSET_KB 2048 +#define AMD_SRIOV_MSG_BAD_PAGE_SIZE_KB 2 +#define AMD_SRIOV_RAS_TELEMETRY_SIZE_KB 64/* * layout -* 0 64KB 65KB 66KB -* | VBIOS | PF2VF | VF2PF | Bad Page | ... -* | 64KB | 1KB | 1KB | +* 0 64KB 65KB 66KB 68KB 132KB +* | VBIOS | PF2VF | VF2PF | Bad Page | RAS Telemetry Region | ... +* | 64KB | 1KB | 1KB | 2KB | 64KB | ... */ +#define AMD_SRIOV_MSG_SIZE_KB 1#define AMD_SRIOV_MSG_PF2VF_OFFSET_KB AMD_SRIOV_MSG_DATAEXCHANGE_OFFSET_KB#define AMD_SRIOV_MSG_VF2PF_OFFSET_KB (AMD_SRIOV_MSG_PF2VF_OFFSET_KB + AMD_SRIOV_MSG_SIZE_KB)#define AMD_SRIOV_MSG_BAD_PAGE_OFFSET_KB (AMD_SRIOV_MSG_VF2PF_OFFSET_KB + AMD_SRIOV_MSG_SIZE_KB) +#define AMD_SRIOV_MSG_RAS_TELEMETRY_OFFSET_KB (AMD_SRIOV_MSG_BAD_PAGE_OFFSET_KB + AMD_SRIOV_MSG_BAD_PAGE_SIZE_KB)/* * PF2VF history log:
@@ -86,30 +90,59 @@ enum amd_sriov_ucode_engine_id {union amd_sriov_msg_feature_flags {struct { -uint32_t error_log_collect :1 ; -uint32_t host_load_ucodes :1 ; -uint32_t host_flr_vramlost :1 ; -uint32_t mm_bw_management :1 ; -uint32_t pp_one_vf_mode :1 ; -uint32_t reg_indirect_acc :1 ; -uint32_t av1_support :1 ; -uint32_t vcn_rb_decouple :1 ; -uint32_t mes_info_enable :1 ; -uint32_t reserved :23 ; +uint32_t error_log_collect :1 ; +uint32_t host_load_ucodes :1 ; +uint32_t host_flr_vramlost :1 ; +uint32_t mm_bw_management :1 ; +uint32_t pp_one_vf_mode :1 ; +uint32_t reg_indirect_acc :1 ; +uint32_t av1_support :1 ; +uint32_t vcn_rb_decouple :1 ; +uint32_t mes_info_dump_enable :1 ; +uint32_t ras_caps :1 ; +uint32_t ras_telemetry :1 ; +uint32_t reserved :21 ; } flags;uint32_t all; };union amd_sriov_reg_access_flags {struct { -uint32_t vf_reg_access_ih :1 ; -uint32_t vf_reg_access_mmhub :1 ; -uint32_t vf_reg_access_gc :1 ; -uint32_t reserved :29 ; +uint32_t vf_reg_access_ih :1 ; +uint32_t vf_reg_access_mmhub :1 ; +uint32_t vf_reg_access_gc :1 ; +uint32_t reserved :29 ; } flags;uint32_t all; }; +union amd_sriov_ras_caps { +struct { +uint64_t block_umc :1 ; +uint64_t block_sdma :1 ; +uint64_t block_gfx :1 ; +uint64_t block_mmhub :1 ; +uint64_t block_athub :1 ; +uint64_t block_pcie_bif :1 ; +uint64_t block_hdp :1 ; +uint64_t block_xgmi_wafl :1 ; +uint64_t block_df :1 ; +uint64_t block_smn :1 ; +uint64_t block_sem :1 ; +uint64_t block_mp0 :1 ; +uint64_t block_mp1 :1 ; +uint64_t block_fuse :1 ; +uint64_t block_mca :1 ; +uint64_t block_vcn :1 ; +uint64_t block_jpeg :1 ; +uint64_t block_ih :1 ; +uint64_t block_mpio :1 ; +uint64_t poison_propogation_mode :1 ; +uint64_t reserved :44 ; + } bits; +uint64_t all; +}; +union amd_sriov_msg_os_info {struct {uint32_t windows :1 ;
@@ -158,7 +191,7 @@ struct amd_sriov_msg_pf2vf_info_header {uint32_t reserved[2 ]; }; -#define AMD_SRIOV_MSG_PF2VF_INFO_FILLED_SIZE (49) +#define AMD_SRIOV_MSG_PF2VF_INFO_FILLED_SIZE (55)struct amd_sriov_msg_pf2vf_info {/* header contains size and version */ struct amd_sriov_msg_pf2vf_info_header header;
@@ -211,6 +244,12 @@ struct amd_sriov_msg_pf2vf_info {uint32_t pcie_atomic_ops_support_flags;/* Portion of GPU memory occupied by VF. MAX value is 65535, but set to uint32_t to maintain alignment with reserved size */ uint32_t gpu_capacity; +/* vf bdf on host pci tree for debug only */ +uint32_t bdf_on_host; +uint32_t more_bp;//Reserved for future use. +union amd_sriov_ras_caps ras_en_caps; +union amd_sriov_ras_caps ras_telemetry_en_caps; +/* reserved */ uint32_t reserved[256 -AMD_SRIOV_MSG_PF2VF_INFO_FILLED_SIZE ]; } __packed;
@@ -283,8 +322,12 @@ enum amd_sriov_mailbox_request_message {MB_REQ_MSG_REL_GPU_FINI_ACCESS ,MB_REQ_MSG_REQ_GPU_RESET_ACCESS ,MB_REQ_MSG_REQ_GPU_INIT_DATA , +MB_REQ_MSG_PSP_VF_CMD_RELAY ,MB_REQ_MSG_LOG_VF_ERROR =200 , +MB_REQ_MSG_READY_TO_RESET =201 , +MB_REQ_MSG_RAS_POISON =202 , + MB_REQ_RAS_ERROR_COUNT = 203, };/* mailbox message send from host to guest */
@@ -297,10 +340,60 @@ enum amd_sriov_mailbox_response_message {MB_RES_MSG_FAIL ,MB_RES_MSG_QUERY_ALIVE ,MB_RES_MSG_GPU_INIT_DATA_READY , +MB_RES_MSG_RAS_ERROR_COUNT_READY =11 ,MB_RES_MSG_TEXT_MESSAGE =255 }; +enum amd_sriov_ras_telemetry_gpu_block { +RAS_TELEMETRY_GPU_BLOCK_UMC =0 , +RAS_TELEMETRY_GPU_BLOCK_SDMA =1 , +RAS_TELEMETRY_GPU_BLOCK_GFX =2 , +RAS_TELEMETRY_GPU_BLOCK_MMHUB =3 , +RAS_TELEMETRY_GPU_BLOCK_ATHUB =4 , +RAS_TELEMETRY_GPU_BLOCK_PCIE_BIF =5 , +RAS_TELEMETRY_GPU_BLOCK_HDP =6 , +RAS_TELEMETRY_GPU_BLOCK_XGMI_WAFL =7 , +RAS_TELEMETRY_GPU_BLOCK_DF =8 , +RAS_TELEMETRY_GPU_BLOCK_SMN =9 , +RAS_TELEMETRY_GPU_BLOCK_SEM =10 , +RAS_TELEMETRY_GPU_BLOCK_MP0 =11 , +RAS_TELEMETRY_GPU_BLOCK_MP1 =12 , +RAS_TELEMETRY_GPU_BLOCK_FUSE =13 , +RAS_TELEMETRY_GPU_BLOCK_MCA =14 , +RAS_TELEMETRY_GPU_BLOCK_VCN =15 , +RAS_TELEMETRY_GPU_BLOCK_JPEG =16 , +RAS_TELEMETRY_GPU_BLOCK_IH =17 , +RAS_TELEMETRY_GPU_BLOCK_MPIO =18 , +RAS_TELEMETRY_GPU_BLOCK_COUNT =19 , +}; + +struct amd_sriov_ras_telemetry_header { +uint32_t checksum; +uint32_t used_size; +uint32_t reserved[2 ]; +}; + +struct amd_sriov_ras_telemetry_error_count { +struct { +uint32_t ce_count; +uint32_t ue_count; +uint32_t de_count; +uint32_t ce_overflow_count; +uint32_t ue_overflow_count; +uint32_t de_overflow_count; +uint32_t reserved[6 ]; + } block[RAS_TELEMETRY_GPU_BLOCK_COUNT ]; +}; + +struct amdsriov_ras_telemetry { +struct amd_sriov_ras_telemetry_header header; + +union { +struct amd_sriov_ras_telemetry_error_count error_count; + } body; +}; +/* version data stored in MAILBOX_MSGBUF_RCV_DW1 for future expansion */ enum amd_sriov_gpu_init_data_version { GPU_INIT_DATA_READY_V1 = 1,
drivers/gpu/drm/amd/amdgpu/mxgpu_nv.h +3 -0
@@ -40,6 +40,7 @@ enum idh_request {IDH_LOG_VF_ERROR =200 ,IDH_READY_TO_RESET =201 ,IDH_RAS_POISON =202 , + IDH_REQ_RAS_ERROR_COUNT = 203, }; enum idh_event {
@@ -54,6 +55,8 @@ enum idh_event {IDH_RAS_POISON_READY ,IDH_PF_SOFT_FLR_NOTIFICATION ,IDH_RAS_ERROR_DETECTED , +IDH_RAS_ERROR_COUNT_READY =11 , + IDH_TEXT_MESSAGE = 255, };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 727/869 drm/amdgpu/ras: add ras_suspend callback and use it for cp_ecc_error_irq
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yunxiang Li <[email protected]>
[ Upstream commit e3829992dd9fa0a82511af4f01733fc854cd15a5 ]
cp_ecc_error_irq is acquired in amdgpu_gfx_ras_late_init() but released in gfx_v9_0_hw_fini(), so the put site has to query amdgpu_irq_enabled() because the get is skipped on SR-IOV VF.
ras_late_init / ras_fini have no suspend counterpart, so move the put to amdgpu_gfx_ras_suspend() / amdgpu_gfx_ras_fini() and add a matching ras_suspend callback that is invoked from amdgpu_ras_suspend() before disable_all_features(). The get and put now sit in the same place and check the same condition (not VF, funcs registered), no refcount querying needed.
An active flag gates ras_fini so the suspend-then-unload-without-resume path falls into amdgpu_ras_block_late_fini_default() instead of double-releasing what ras_suspend already cleaned up.
Drop the cp_ecc_error_irq put from gfx_v9_0_hw_fini(). gfx_v8_0 manages cp_ecc_error_irq locally and is unaffected; no other GFX generation has this IRQ.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 23 +++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 3 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 32 +++++++++++++++++++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h | 1 + drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 2 -- 5 files changed, 53 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +22 -1
@@ -922,7 +922,7 @@ int amdgpu_gfx_ras_late_init(struct amdgpu_device *adev, struct ras_common_if *rif (r)return r; -if (adev->gfx.cp_ecc_error_irq.funcs) { +if (!amdgpu_sriov_vf (adev) && adev->gfx.cp_ecc_error_irq.funcs) { r =amdgpu_irq_get (adev, &adev->gfx.cp_ecc_error_irq,0 );if (r) goto late_fini;
@@ -937,6 +937,21 @@ int amdgpu_gfx_ras_late_init(struct amdgpu_device *adev, struct ras_common_if *rreturn r; } +void amdgpu_gfx_ras_suspend (struct amdgpu_device *adev, +struct ras_common_if *ras_block) +{ +if (!amdgpu_sriov_vf (adev) && adev->gfx.cp_ecc_error_irq.funcs) +amdgpu_irq_put (adev, &adev->gfx.cp_ecc_error_irq,0 ); +} + +void amdgpu_gfx_ras_fini (struct amdgpu_device *adev, +struct ras_common_if *ras_block) +{ +if (!amdgpu_sriov_vf (adev) && adev->gfx.cp_ecc_error_irq.funcs) +amdgpu_irq_put (adev, &adev->gfx.cp_ecc_error_irq,0 ); +amdgpu_ras_block_late_fini (adev, ras_block); +} +int amdgpu_gfx_ras_sw_init (struct amdgpu_device *adev) {int err =0 ;
@@ -965,6 +980,12 @@ int amdgpu_gfx_ras_sw_init(struct amdgpu_device *adev)if (!ras->ras_block.ras_late_init) ras->ras_block.ras_late_init = amdgpu_gfx_ras_late_init; +if (!ras->ras_block.ras_suspend) + ras->ras_block.ras_suspend = amdgpu_gfx_ras_suspend; + +if (!ras->ras_block.ras_fini) + ras->ras_block.ras_fini = amdgpu_gfx_ras_fini; +/* If not defined special ras_cb function, use default ras_cb */ if (!ras->ras_block.ras_cb) ras->ras_block.ras_cb = amdgpu_gfx_process_ras_data_cb;
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +2 -1
@@ -547,7 +547,8 @@ bool amdgpu_gfx_is_me_queue_enabled(struct amdgpu_device *adev, int me,void amdgpu_gfx_off_ctrl (struct amdgpu_device *adev,bool enable);int amdgpu_get_gfx_off_status (struct amdgpu_device *adev,uint32_t *value);int amdgpu_gfx_ras_late_init (struct amdgpu_device *adev,struct ras_common_if *ras_block); -void amdgpu_gfx_ras_fini (struct amdgpu_device *adev); +void amdgpu_gfx_ras_suspend (struct amdgpu_device *adev,struct ras_common_if *ras_block); +void amdgpu_gfx_ras_fini (struct amdgpu_device *adev,struct ras_common_if *ras_block);int amdgpu_get_gfx_off_entrycount (struct amdgpu_device *adev,u64 *value);int amdgpu_get_gfx_off_residency (struct amdgpu_device *adev,u32 *residency);int amdgpu_set_gfx_off_residency (struct amdgpu_device *adev,bool value);
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c +28 -4
@@ -90,6 +90,9 @@ struct amdgpu_ras_block_list {struct list_head node;struct amdgpu_ras_block_object *ras_obj; + +/* set by ras_late_init, cleared by ras_suspend/ras_fini */ +bool active; };const char *get_ras_block_str (struct ras_common_if *ras_block)
@@ -3874,10 +3877,23 @@ void amdgpu_ras_resume(struct amdgpu_device *adev)void amdgpu_ras_suspend (struct amdgpu_device *adev) {struct amdgpu_ras *con =amdgpu_ras_get_context (adev); +struct amdgpu_ras_block_list *node; +struct amdgpu_ras_block_object *obj;if (!adev->ras_enabled || !con)return ; +/* run per-block ras_suspend before tearing down the RAS context */ +list_for_each_entry (node, &adev->ras_list, node) { +if (!node->active) +continue ; + + obj = node->ras_obj; +if (obj && obj->ras_suspend) + obj->ras_suspend (adev, &obj->ras_comm); + node->active = false; + } +amdgpu_ras_disable_all_features (adev,0 );/* Make sure all ras objects are disabled. */ if (AMDGPU_RAS_GET_FEATURES (con->features))
@@ -3931,8 +3947,15 @@ int amdgpu_ras_late_init(struct amdgpu_device *adev) obj->ras_comm.name, r);return r; } - }else -amdgpu_ras_block_late_init_default (adev, &obj->ras_comm); + }else { + r =amdgpu_ras_block_late_init_default (adev, &obj->ras_comm); +if (r) { +dev_err (adev->dev,"%s failed to execute ras_block_late_init_default! ret:%d\n" , + obj->ras_comm.name, r); +return r; + } + } + node->active = true; }return 0 ;
@@ -3966,11 +3989,12 @@ int amdgpu_ras_fini(struct amdgpu_device *adev)list_for_each_entry_safe (ras_node, tmp, &adev->ras_list, node) {if (ras_node->ras_obj) { obj = ras_node->ras_obj; -if (amdgpu_ras_is_supported (adev, obj->ras_comm.block) && - obj->ras_fini) +/* fall back to default cleanup if ras_suspend already ran */ +if (ras_node->active && obj->ras_fini) obj->ras_fini (adev, &obj->ras_comm);else amdgpu_ras_block_late_fini_default (adev, &obj->ras_comm); + ras_node->active = false; }/* Clear ras blocks from ras_list and free ras block list node */
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h +1 -0
@@ -706,6 +706,7 @@ struct amdgpu_ras_block_object {int (*ras_block_match)(struct amdgpu_ras_block_object *block_obj,enum amdgpu_ras_block block,uint32_t sub_block_index);int (*ras_late_init)(struct amdgpu_device *adev,struct ras_common_if *ras_block); +void (*ras_suspend)(struct amdgpu_device *adev,struct ras_common_if *ras_block);void (*ras_fini)(struct amdgpu_device *adev,struct ras_common_if *ras_block);ras_ih_cb ras_cb;const struct amdgpu_ras_block_hw_ops *hw_ops;
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +0 -2
@@ -4018,8 +4018,6 @@ static int gfx_v9_0_hw_fini(void *handle) {struct amdgpu_device *adev = (struct amdgpu_device *)handle; -if (amdgpu_ras_is_supported (adev,AMDGPU_RAS_BLOCK__GFX )) -amdgpu_irq_put (adev, &adev->gfx.cp_ecc_error_irq,0 );amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 );amdgpu_irq_put (adev, &adev->gfx.priv_inst_irq,0 );amdgpu_irq_put (adev, &adev->gfx.bad_op_irq,0 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 728/869 wifi: iwlwifi: simplify nested if checks
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Berg <[email protected]>
[ Upstream commit 63a59880ec116cebb8a01ead28b1b23c3846ebb9 ]
In the absence of (an) else clause(s), "if (a) if (b)" is equivalent to "if (a && b)", so simplify the code a bit.
Stable-dep-of: b74e377cad92 ("wifi: iwlwifi: mvm: fix P2P-Device binding handling")
--- drivers/net/wireless/intel/iwlwifi/mvm/binding.c | 7 +++---- drivers/net/wireless/intel/iwlwifi/mvm/link.c | 5 ++--- drivers/net/wireless/intel/iwlwifi/pcie/trans-gen2.c | 6 +++--- 3 files changed, 8 insertions(+), 10 deletions(-)
drivers/net/wireless/intel/iwlwifi/mvm/binding.c +3 -4
@@ -2,7 +2,7 @@/* * Copyright (C) 2012-2014, 2020 Intel Corporation * Copyright (C) 2016 Intel Deutschland GmbH -* Copyright (C) 2022 Intel Corporation +* Copyright (C) 2022, 2024 Intel Corporation */ #include <net/mac80211.h> #include "fw-api.h"
@@ -158,9 +158,8 @@ int iwl_mvm_binding_remove_vif(struct iwl_mvm *mvm, struct ieee80211_vif *vif) ret =iwl_mvm_binding_update (mvm, vif, mvmvif->deflink.phy_ctxt, false); -if (!ret) -if (iwl_mvm_sf_update (mvm, vif, true)) -IWL_ERR (mvm,"Failed to update SF state\n" ); +if (!ret &&iwl_mvm_sf_update (mvm, vif, true)) +IWL_ERR (mvm,"Failed to update SF state\n" );return ret; }
drivers/net/wireless/intel/iwlwifi/mvm/link.c +2 -3
@@ -410,9 +410,8 @@ int iwl_mvm_remove_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif, ret =iwl_mvm_link_cmd_send (mvm, &cmd,FW_CTXT_ACTION_REMOVE ); -if (!ret) -if (iwl_mvm_sf_update (mvm, vif, true)) -IWL_ERR (mvm,"Failed to update SF state\n" ); +if (!ret &&iwl_mvm_sf_update (mvm, vif, true)) +IWL_ERR (mvm,"Failed to update SF state\n" );return ret; }
drivers/net/wireless/intel/iwlwifi/pcie/trans-gen2.c +3 -3
@@ -139,9 +139,9 @@ void _iwl_trans_pcie_gen2_stop_device(struct iwl_trans *trans)if (trans_pcie->is_down)return ; -if (trans->state >=IWL_TRANS_FW_STARTED ) -if (trans_pcie->fw_reset_handshake) -iwl_trans_pcie_fw_reset_handshake (trans); +if (trans->state >=IWL_TRANS_FW_STARTED && + trans_pcie->fw_reset_handshake) +iwl_trans_pcie_fw_reset_handshake (trans); trans_pcie->is_down = true;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 729/869 wifi: iwlwifi: mvm: fix P2P-Device binding handling
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Berg <[email protected]>
[ Upstream commit b74e377cad9271950c57472867c469e4b5b2ff0c ]
Our binding handling for P2P-Device can run into the following scenario, as observed by our testing:
- a station interface is connected on some channel
- the P2P-Device does a remain-on-channel (ROC) on that channel
- the ROC ends, and the P2P-Device is removed from the binding, but the phy_ctxt pointer is left around as a PHY cache so we don't need to recalibrate to the channel again and again in case it's not shared
- a binding update by the station interface, even a removal, will re-add the P2P-Device to the binding
- the P2P-Device is removed, which removes the PHY context, but it's still in the binding so the firmware crashes
Since the P2P device is removed from the binding and only re- added by unrelated code, but we want to keep the phy_ctxt around as a cache for future ROC usage, fix it by adding a boolean that indicates whether or not the P2P-Device should be added to the binding, and handle that in the binding iterator. That way, the station interface cannot re-add the P2P-Device to the binding when that isn't active.
--- drivers/net/wireless/intel/iwlwifi/mvm/binding.c | 5 ++++- drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c | 12 +++++++++++- drivers/net/wireless/intel/iwlwifi/mvm/mvm.h | 3 +++ drivers/net/wireless/intel/iwlwifi/mvm/time-event.c | 3 ++- 4 files changed, 20 insertions(+), 3 deletions(-)
drivers/net/wireless/intel/iwlwifi/mvm/binding.c +4 -1
@@ -2,7 +2,7 @@/* * Copyright (C) 2012-2014, 2020 Intel Corporation * Copyright (C) 2016 Intel Deutschland GmbH -* Copyright (C) 2022, 2024 Intel Corporation +* Copyright (C) 2022, 2024, 2026 Intel Corporation */ #include <net/mac80211.h> #include "fw-api.h"
@@ -76,6 +76,9 @@ static void iwl_mvm_iface_iterator(void *_data, u8 *mac,if (vif == data->ignore_vif)return ; +if (vif->type ==NL80211_IFTYPE_P2P_DEVICE && !mvmvif->p2p_in_binding) +return ; +if (mvmvif->deflink.phy_ctxt != data->phyctxt)return ;
drivers/net/wireless/intel/iwlwifi/mvm/mac80211.c +11 -1
@@ -1098,6 +1098,7 @@ static void iwl_mvm_cleanup_iterator(void *data, u8 *mac,spin_unlock_bh (&mvm->time_event_lock); mvmvif->roc_activity =ROC_NUM_ACTIVITIES ; + mvmvif->p2p_in_binding = false; mvmvif->bf_enabled = false; mvmvif->ba_enabled = false;
@@ -4786,6 +4787,7 @@ static int iwl_mvm_add_aux_sta_for_hs20(struct iwl_mvm *mvm, u32 lmac_id)static int iwl_mvm_roc_link (struct iwl_mvm *mvm,struct ieee80211_vif *vif) { +struct iwl_mvm_vif *mvmvif =iwl_mvm_vif_from_mac80211 (vif);int ret;lockdep_assert_held (&mvm->mutex);
@@ -4794,10 +4796,18 @@ static int iwl_mvm_roc_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif)if (WARN (ret,"Failed binding P2P_DEVICE\n" ))return ret; + mvmvif->p2p_in_binding = true; +/* The station and queue allocation must be done only after the binding * is done, as otherwise the FW might incorrectly configure its state. */ -return iwl_mvm_add_p2p_bcast_sta (mvm, vif); + ret =iwl_mvm_add_p2p_bcast_sta (mvm, vif); +if (ret) { +iwl_mvm_binding_remove_vif (mvm, vif); + mvmvif->p2p_in_binding = false; + } + +return ret; } static int iwl_mvm_roc(struct ieee80211_hw *hw,
drivers/net/wireless/intel/iwlwifi/mvm/mvm.h +3 -0
@@ -454,6 +454,8 @@ struct iwl_mvm_esr_exit {* @unblock_esr_tpt_wk: work for unblocking EMLSR when tpt is high enough. * @roc_activity: currently running ROC activity for this vif (or * ROC_NUM_ACTIVITIES if no activity is running). +* @p2p_in_binding: indicates that this P2P-Device interface should be +* added to the binding, i.e. is running ROC right now * @session_prot_connection_loss: the connection was lost due to session * protection ending without receiving a beacon, so we need to now * protect the deauth separately
@@ -565,6 +567,7 @@ struct iwl_mvm_vif {struct iwl_mvm_time_event_data time_event_data;struct iwl_mvm_time_event_data hs_time_event_data;enum iwl_roc_activity roc_activity; +bool p2p_in_binding;/* TCP Checksum Offload */ netdev_features_t features;
drivers/net/wireless/intel/iwlwifi/mvm/time-event.c +2 -1
@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause /* -* Copyright (C) 2012-2014, 2018-2024 Intel Corporation +* Copyright (C) 2012-2014, 2018-2024, 2026 Intel Corporation * Copyright (C) 2013-2015 Intel Mobile Communications GmbH * Copyright (C) 2017 Intel Deutschland GmbH */
@@ -90,6 +90,7 @@ static void iwl_mvm_cleanup_roc(struct iwl_mvm *mvm) }else {iwl_mvm_rm_p2p_bcast_sta (mvm, vif);iwl_mvm_binding_remove_vif (mvm, vif); + mvmvif->p2p_in_binding = false; }/* Do not remove the PHY context as removing and adding
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 730/869 RDMA/counter: Fix num_counters leak on bind_qp failure in alloc_and_bind()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tao Cui <[email protected]>
[ Upstream commit 4fbc8230009f5b1bcd13cc74c5a6a43ddba141fd ]
When __rdma_counter_bind_qp() fails in alloc_and_bind(), the error path jumps to err_mode which frees the counter without decrementing port_counter->num_counters. The only place that decrements is rdma_counter_free(), which is unreachable since the counter was never successfully bound.
This leak accumulates across repeated failures, permanently preventing the port from switching to AUTO mode (-EBUSY in __counter_set_mode()) and blocking the MANUAL→NONE auto-revert in rdma_counter_free(). When the mode was NONE before the call, the MANUAL mode set by __counter_set_mode() also leaks since the revert logic is never reached.
Add an err_bind label between the num_counters increment and the existing err_mode label. It decrements num_counters and mirrors the MANUAL→NONE revert from rdma_counter_free(), ensuring the port state is fully restored on bind failure.
--- drivers/infiniband/core/counters.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/infiniband/core/counters.c +8 -1
@@ -190,12 +190,19 @@ static struct rdma_counter *alloc_and_bind(struct ib_device *dev, u32 port, ret =__rdma_counter_bind_qp (counter, qp);if (ret) - goto err_mode; + goto err_bind;rdma_restrack_parent_name (&counter->res, &qp->res);rdma_restrack_add (&counter->res);return counter; +err_bind: +mutex_lock (&port_counter->lock); + port_counter->num_counters--; +if (!port_counter->num_counters && + port_counter->mode.mode ==RDMA_COUNTER_MODE_MANUAL ) +__counter_set_mode (port_counter,RDMA_COUNTER_MODE_NONE ,0 ); +mutex_unlock (&port_counter->lock); err_mode:rdma_free_hw_stats_struct (counter->stats); err_stats:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 731/869 virt: acrn: Remove unused list acrn_irqfd_clients
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dr. David Alan Gilbert <[email protected]>
[ Upstream commit 97e72c1e0c5424cd8d7b95c31144e713c44c4244 ]
It doesn't look like this was ever used.
Build tested only.
Stable-dep-of: 666c7f9e0792 ("virt: acrn: Fix irqfd use-after-free during eventfd shutdown")
--- drivers/virt/acrn/irqfd.c | 2 -- 1 file changed, 2 deletions(-)
drivers/virt/acrn/irqfd.c +0 -2
@@ -16,8 +16,6 @@#include "acrn_drv.h" -static LIST_HEAD (acrn_irqfd_clients); -/** * struct hsm_irqfd - Properties of HSM irqfd * @vm: Associated VM pointer
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 732/869 virt: acrn: Fix irqfd use-after-free during eventfd shutdown
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sicong Huang <[email protected]>
[ Upstream commit 666c7f9e07925aa0863348f960e09bb89f8f05a3 ]
acrn_irqfd_deassign() and the eventfd EPOLLHUP wakeup can race and free the same struct hsm_irqfd:
CPU0 CPU1
---- ----
eventfd_release()
wake_up_poll(EPOLLHUP)
hsm_irqfd_wakeup()
queue_work(&irqfd->shutdown)
acrn_irqfd_deassign()
hsm_irqfd_shutdown()
list_del_init()
eventfd_ctx_remove_wait_queue()
eventfd_ctx_put()
kfree(irqfd) hsm_irqfd_shutdown_work()
container_of(work, ..., shutdown)
irqfd->vm <-- use-after-free
The deassign path freed the irqfd while a shutdown work item was already queued by EPOLLHUP (or vice versa), so the work item could resurrect a dangling pointer through container_of().
Switch to the lifetime model used by KVM irqfds:
- Deassign/deinit only deactivate the irqfd: remove it from vm->irqfds under irqfds_lock and queue the cleanup work.
- hsm_irqfd_shutdown_work() becomes the sole owner that unhooks the eventfd waitqueue entry, drops the eventfd reference and frees the irqfd.
- A new HSM_IRQFD_FLAG_SHUTDOWN bit guarded by test_and_set_bit() ensures the cleanup work is queued at most once, no matter how many of {EPOLLHUP, deassign, deinit} fire concurrently. This is safe to call from the waitqueue callback, which runs with wqh->lock held and IRQs disabled and therefore cannot take irqfds_lock.
- acrn_irqfd_deassign() flushes vm->irqfd_wq before returning so the eventfd is fully detached on return. acrn_irqfd_deinit() deactivates every irqfd, flushes the workqueue and only then destroys it, so no path can queue_work() onto a torn-down workqueue.
- acrn_irqfd_assign() now installs the eventfd waitqueue entry and publishes the irqfd to vm->irqfds under irqfds_lock, so the irqfd is never visible to deassign/deinit before its waitqueue entry is in place, and any EPOLLHUP that fires in the assign window queues cleanup work that blocks on irqfds_lock until publication is done.
--- drivers/virt/acrn/irqfd.c | 71 ++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 27 deletions(-)
drivers/virt/acrn/irqfd.c +44 -27
@@ -16,6 +16,9 @@#include "acrn_drv.h" +/* Cleanup work has been queued; set via test_and_set_bit(). */ +#define HSM_IRQFD_FLAG_SHUTDOWN 0 +/** * struct hsm_irqfd - Properties of HSM irqfd * @vm: Associated VM pointer
@@ -25,6 +28,7 @@* @list: Entry within &acrn_vm.irqfds of irqfds of a VM * @pt: Structure for select/poll on the associated eventfd * @msi: MSI data +* @flags: Internal lifecycle flags (HSM_IRQFD_FLAG_*) */ struct hsm_irqfd {struct acrn_vm *vm;
@@ -34,6 +38,7 @@ struct hsm_irqfd {struct list_head list;poll_table pt;struct acrn_msi_entry msi; +unsigned long flags; };static void acrn_irqfd_inject (struct hsm_irqfd *irqfd)
@@ -44,30 +49,29 @@ static void acrn_irqfd_inject(struct hsm_irqfd *irqfd) irqfd->msi.msi_data); } -static void hsm_irqfd_shutdown (struct hsm_irqfd *irqfd) +/* Queue the cleanup work at most once. Safe from atomic context. */ +static void hsm_irqfd_queue_shutdown (struct hsm_irqfd *irqfd) { -u64 cnt; - -lockdep_assert_held (&irqfd->vm->irqfds_lock); - -/* remove from wait queue */ -list_del_init (&irqfd->list); -eventfd_ctx_remove_wait_queue (irqfd->eventfd, &irqfd->wait, &cnt); -eventfd_ctx_put (irqfd->eventfd); -kfree (irqfd); +if (!test_and_set_bit (HSM_IRQFD_FLAG_SHUTDOWN , &irqfd->flags)) +queue_work (irqfd->vm->irqfd_wq, &irqfd->shutdown); } +/* Sole owner of @irqfd: unhook waitqueue, drop eventfd ref, free. */ static void hsm_irqfd_shutdown_work (struct work_struct *work) { -struct hsm_irqfd *irqfd; -struct acrn_vm *vm; + struct hsm_irqfd *irqfd = container_of(work, struct hsm_irqfd, + shutdown); +struct acrn_vm *vm = irqfd->vm; +u64 cnt; - irqfd = container_of(work, struct hsm_irqfd, shutdown); - vm = irqfd->vm;mutex_lock (&vm->irqfds_lock);if (!list_empty (&irqfd->list)) -hsm_irqfd_shutdown (irqfd); +list_del_init (&irqfd->list);mutex_unlock (&vm->irqfds_lock); + +eventfd_ctx_remove_wait_queue (irqfd->eventfd, &irqfd->wait, &cnt); +eventfd_ctx_put (irqfd->eventfd); +kfree (irqfd); }/* Called with wqh->lock held and interrupts disabled */
@@ -76,17 +80,16 @@ static int hsm_irqfd_wakeup(wait_queue_entry_t *wait, unsigned int mode, {unsigned long poll_bits = (unsigned long )key;struct hsm_irqfd *irqfd; -struct acrn_vm *vm; irqfd = container_of(wait, struct hsm_irqfd, wait); - vm = irqfd->vm; +if (poll_bits &POLLIN )/* An event has been signaled, inject an interrupt */ acrn_irqfd_inject (irqfd);if (poll_bits &POLLHUP ) -/* Do shutdown work in thread to hold wqh->lock */ -queue_work (vm->irqfd_wq, &irqfd->shutdown); +/* Defer teardown to the cleanup work; can't sleep here. */ +hsm_irqfd_queue_shutdown (irqfd);return 0 ; }
@@ -143,6 +146,12 @@ static int acrn_irqfd_assign(struct acrn_vm *vm, struct acrn_irqfd *args)init_waitqueue_func_entry (&irqfd->wait, hsm_irqfd_wakeup);init_poll_funcptr (&irqfd->pt, hsm_irqfd_poll_func); +/* +* Hold irqfds_lock across waitqueue install and list_add so the +* irqfd is not visible to deassign/deinit before its waitqueue +* entry is in place, and any racing EPOLLHUP cleanup work blocks +* on irqfds_lock until publication completes. +*/ mutex_lock (&vm->irqfds_lock);list_for_each_entry (tmp, &vm->irqfds, list) {if (irqfd->eventfd != tmp->eventfd)
@@ -151,14 +160,12 @@ static int acrn_irqfd_assign(struct acrn_vm *vm, struct acrn_irqfd *args)mutex_unlock (&vm->irqfds_lock); goto fail; } -list_add_tail (&irqfd->list, &vm->irqfds); -mutex_unlock (&vm->irqfds_lock); -/* Check the pending event in this stage */ events =vfs_poll (fd_file (f), &irqfd->pt); - +list_add_tail (&irqfd->list, &vm->irqfds);if (events &EPOLLIN )acrn_irqfd_inject (irqfd); +mutex_unlock (&vm->irqfds_lock);fdput (f);return 0 ;
@@ -185,13 +192,17 @@ static int acrn_irqfd_deassign(struct acrn_vm *vm,mutex_lock (&vm->irqfds_lock);list_for_each_entry_safe (irqfd, tmp, &vm->irqfds, list) {if (irqfd->eventfd == eventfd) { -hsm_irqfd_shutdown (irqfd); +list_del_init (&irqfd->list); +hsm_irqfd_queue_shutdown (irqfd);break ; } }mutex_unlock (&vm->irqfds_lock);eventfd_ctx_put (eventfd); +/* Wait for cleanup work to finish so the eventfd is fully detached. */ +flush_workqueue (vm->irqfd_wq); +return 0 ; }
@@ -224,9 +235,15 @@ void acrn_irqfd_deinit(struct acrn_vm *vm)struct hsm_irqfd *irqfd, *next;dev_dbg (acrn_dev.this_device,"VM %u irqfd deinit.\n" , vm->vmid); -destroy_workqueue (vm->irqfd_wq); +mutex_lock (&vm->irqfds_lock); -list_for_each_entry_safe (irqfd, next, &vm->irqfds, list) -hsm_irqfd_shutdown (irqfd); +list_for_each_entry_safe (irqfd, next, &vm->irqfds, list) { +list_del_init (&irqfd->list); +hsm_irqfd_queue_shutdown (irqfd); + }mutex_unlock (&vm->irqfds_lock); + +/* Drain all cleanup work before tearing the workqueue down. */ +flush_workqueue (vm->irqfd_wq); +destroy_workqueue (vm->irqfd_wq); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 733/869 PM: sleep: core: Synchronize runtime PM status of parents and children
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rafael J. Wysocki <[email protected]>
[ Upstream commit 3775fc538f535a7c5adaf11990c7932a0bd1f9eb ]
Commit 6e176bf8d461 ("PM: sleep: core: Do not skip callbacks in the resume phase") overlooked the case in which the parent of a device with DPM_FLAG_SMART_SUSPEND set did not use that flag and could be runtime- suspended before a transition into a system-wide sleep state. In that case, if the child is resumed during the subsequent transition from that state into the working state, its runtime PM status will be set to RPM_ACTIVE, but the runtime PM status of the parent will not be updated accordingly, even though the parent will be resumed too, because of the dev_pm_skip_suspend() check in device_resume_noirq().
Address this problem by tracking the need to set the runtime PM status to RPM_ACTIVE during system-wide resume transitions for devices with DPM_FLAG_SMART_SUSPEND set and all of the devices depended on by them.
Stable-dep-of: 36d74f17e03f ("driver core: Avoid warning when removing a device while its supplier is unbinding")
--- drivers/base/power/main.c | 29 ++++++++++++++++++++--------- include/linux/pm.h | 1 + 2 files changed, 21 insertions(+), 9 deletions(-)
drivers/base/power/main.c +20 -9
@@ -654,13 +654,15 @@ static void device_resume_noirq(struct device *dev, pm_message_t state, bool asy* so change its status accordingly. * * Otherwise, the device is going to be resumed, so set its PM-runtime -* status to "active", but do that only if DPM_FLAG_SMART_SUSPEND is set -* to avoid confusing drivers that don't use it. +* status to "active" unless its power.set_active flag is clear, in +* which case it is not necessary to update its PM-runtime status. */ -if (skip_resume) +if (skip_resume) {pm_runtime_set_suspended (dev); -else if (dev_pm_skip_suspend (dev)) + }else if (dev->power.set_active) {pm_runtime_set_active (dev); + dev->power.set_active = false; + }if (dev->pm_domain) { info ="noirq power domain " ;
@@ -1187,18 +1189,24 @@ static pm_message_t resume_event(pm_message_t sleep_state)return PMSG_ON ; } -static void dpm_superior_set_must_resume (struct device *dev) +static void dpm_superior_set_must_resume (struct device *dev,bool set_active) {struct device_link *link;int idx; -if (dev->parent) +if (dev->parent) { dev->parent->power.must_resume = true; +if (set_active) + dev->parent->power.set_active = true; + } idx =device_links_read_lock (); -list_for_each_entry_rcu_locked (link, &dev->links.suppliers, c_node) +list_for_each_entry_rcu_locked (link, &dev->links.suppliers, c_node) { link->supplier->power.must_resume = true; +if (set_active) + link->supplier->power.set_active = true; + }device_links_read_unlock (idx); }
@@ -1275,8 +1283,11 @@ static int device_suspend_noirq(struct device *dev, pm_message_t state, bool asy dev->power.may_skip_resume) || !pm_runtime_need_not_resume(dev)) dev->power.must_resume = true; -if (dev->power.must_resume) -dpm_superior_set_must_resume (dev); +if (dev->power.must_resume) { + dev->power.set_active = dev->power.set_active || +dev_pm_test_driver_flags (dev,DPM_FLAG_SMART_SUSPEND ); +dpm_superior_set_must_resume (dev, dev->power.set_active); + } Complete:complete_all (&dev->power.completion);
include/linux/pm.h +1 -0
@@ -683,6 +683,7 @@ struct dev_pm_info { bool no_pm_callbacks:1; /* Owned by the PM core */ bool async_in_progress:1; /* Owned by the PM core */ bool must_resume:1; /* Owned by the PM core */ + bool set_active:1; /* Owned by the PM core */ bool may_skip_resume:1; /* Set by subsystems */#else bool should_wakeup:1;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 734/869 PM: sleep: core: Restrict power.set_active propagation
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rafael J. Wysocki <[email protected]>
[ Upstream commit 7585946243d614bd2cd4e13377be2c711c9539e0 ]
Commit 3775fc538f53 ("PM: sleep: core: Synchronize runtime PM status of parents and children") exposed an issue related to simple_pm_bus_pm_ops that uses pm_runtime_force_suspend() and pm_runtime_force_resume() as bus type PM callbacks for the noirq phases of system-wide suspend and resume.
The problem is that pm_runtime_force_suspend() does not distinguish runtime-suspended devices from devices for which runtime PM has never been enabled, so if it sees a device with runtime PM status set to RPM_ACTIVE, it will assume that runtime PM is enabled for that device and so it will attempt to suspend it with the help of its runtime PM callbacks which may not be ready for that. As it turns out, this causes simple_pm_bus_runtime_suspend() to crash due to a NULL pointer dereference.
Another problem related to the above commit and simple_pm_bus_pm_ops is that setting runtime PM status of a device handled by the latter to RPM_ACTIVE will actually prevent it from being resumed because pm_runtime_force_resume() only resumes devices with runtime PM status set to RPM_SUSPENDED.
To mitigate these issues, do not allow power.set_active to propagate beyond the parent of the device with DPM_FLAG_SMART_SUSPEND set that will need to be resumed, which should be a sufficient stop-gap for the time being, but they will need to be properly addressed in the future because in general during system-wide resume it is necessary to resume all devices in a dependency chain in which at least one device is going to be resumed.
Stable-dep-of: 36d74f17e03f ("driver core: Avoid warning when removing a device while its supplier is unbinding")
--- drivers/base/power/main.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-)
drivers/base/power/main.c +9 -12
@@ -1189,24 +1189,18 @@ static pm_message_t resume_event(pm_message_t sleep_state)return PMSG_ON ; } -static void dpm_superior_set_must_resume (struct device *dev,bool set_active) +static void dpm_superior_set_must_resume (struct device *dev) {struct device_link *link;int idx; -if (dev->parent) { +if (dev->parent) dev->parent->power.must_resume = true; -if (set_active) - dev->parent->power.set_active = true; - } idx =device_links_read_lock (); -list_for_each_entry_rcu_locked (link, &dev->links.suppliers, c_node) { +list_for_each_entry_rcu_locked (link, &dev->links.suppliers, c_node) link->supplier->power.must_resume = true; -if (set_active) - link->supplier->power.set_active = true; - }device_links_read_unlock (idx); }
@@ -1284,9 +1278,12 @@ static int device_suspend_noirq(struct device *dev, pm_message_t state, bool asy dev->power.must_resume = true;if (dev->power.must_resume) { - dev->power.set_active = dev->power.set_active || -dev_pm_test_driver_flags (dev,DPM_FLAG_SMART_SUSPEND ); -dpm_superior_set_must_resume (dev, dev->power.set_active); +if (dev_pm_test_driver_flags (dev,DPM_FLAG_SMART_SUSPEND )) { + dev->power.set_active = true; +if (dev->parent && !dev->parent->power.ignore_children) + dev->parent->power.set_active = true; + } +dpm_superior_set_must_resume (dev); } Complete:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 735/869 PM: Rearrange documentation related to __pm_runtime_disable()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rafael J. Wysocki <[email protected]>
[ Upstream commit 258e231dc29fbd72bc82c16859a8304f71780ba2 ]
There are only two callers of __pm_runtime_disable(), one of which is device_suspend_late() and the other is pm_runtime_disable() that has its own kerneldoc comment and there are no plans to add any more of them. Since they use different values of the __pm_runtime_disable() second parameter, the actual code behavior is different in each case, but it is all documented in the __pm_runtime_disable() kerneldoc comment which is not particularly straightforward.
For this reason, move the information from the __pm_runtime_disable() kerneldoc comment to the pm_runtime_disable() one and into a separate comment in device_suspend_late() and remove the __pm_runtime_disable() kerneldoc comment altogether.
No functional impact.
Stable-dep-of: 36d74f17e03f ("driver core: Avoid warning when removing a device while its supplier is unbinding")
--- drivers/base/power/main.c | 4 ++++ drivers/base/power/runtime.c | 14 -------------- include/linux/pm_runtime.h | 17 ++++++++++++----- 3 files changed, 16 insertions(+), 19 deletions(-)
drivers/base/power/main.c +4 -0
@@ -1401,6 +1401,10 @@ static int device_suspend_late(struct device *dev, pm_message_t state, bool asynTRACE_DEVICE (dev);TRACE_SUSPEND (0 ); +/* +* Disable runtime PM for the device without checking if there is a +* pending resume request for it. +*/ __pm_runtime_disable (dev, false);dpm_wait_for_subordinate (dev, async);
drivers/base/power/runtime.c +0 -14
@@ -1469,20 +1469,6 @@ int pm_runtime_barrier(struct device *dev) }EXPORT_SYMBOL_GPL (pm_runtime_barrier); -/** -* __pm_runtime_disable - Disable runtime PM of a device. -* @dev: Device to handle. -* @check_resume: If set, check if there's a resume request for the device. -* -* Increment power.disable_depth for the device and if it was zero previously, -* cancel all pending runtime PM requests for the device and wait for all -* operations in progress to complete. The device can be either active or -* suspended after its runtime PM has been disabled. -* -* If @check_resume is set and there's a resume request pending when -* __pm_runtime_disable() is called and power.disable_depth is zero, the -* function will wake up the device before disabling its runtime PM. -*/ void __pm_runtime_disable (struct device *dev,bool check_resume) {spin_lock_irq (&dev->power.lock);
include/linux/pm_runtime.h +12 -5
@@ -562,11 +562,18 @@ static inline int pm_runtime_set_suspended(struct device *dev)* pm_runtime_disable - Disable runtime PM for a device. * @dev: Target device. * -* Prevent the runtime PM framework from working with @dev (by incrementing its -* "blocking" counter). -* -* For each invocation of this function for @dev there must be a matching -* pm_runtime_enable() call in order for runtime PM to be enabled for it. +* Prevent the runtime PM framework from working with @dev by incrementing its +* "disable" counter. +* +* If the counter is zero when this function runs and there is a pending runtime +* resume request for @dev, it will be resumed. If the counter is still zero at +* that point, all of the pending runtime PM requests for @dev will be canceled +* and all runtime PM operations in progress involving it will be waited for to +* complete. +* +* For each invocation of this function for @dev, there must be a matching +* pm_runtime_enable() call, so that runtime PM is eventually enabled for it +* again. */ static inline void pm_runtime_disable (struct device *dev) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 736/869 PM: Block enabling of runtime PM during system suspend
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rafael J. Wysocki <[email protected]>
[ Upstream commit 3e5eee147b7b0f5a93f56beffe34e81fdd00fa0d ]
If device_prepare() runs on a device that has never had runtime PM enabled so far, it may reasonably assume that runtime PM will not be enabled for that device during the system suspend-resume cycle currently in progress, but this has never been guaranteed.
To verify this assumption, make device_prepare() arrange for triggering a device warning accompanied by a call trace dump if runtime PM is enabled for such a device after it has returned.
Stable-dep-of: 36d74f17e03f ("driver core: Avoid warning when removing a device while its supplier is unbinding")
--- drivers/base/power/main.c | 9 +++++++++ drivers/base/power/runtime.c | 24 ++++++++++++++++++++++++ include/linux/pm.h | 1 + include/linux/pm_runtime.h | 4 ++++ 4 files changed, 38 insertions(+)
drivers/base/power/main.c +9 -0
@@ -1107,6 +1107,8 @@ static void device_complete(struct device *dev, pm_message_t state)device_unlock (dev); out: +/* If enabling runtime PM for the device is blocked, unblock it. */ +pm_runtime_unblock (dev);pm_runtime_put (dev); }
@@ -1813,6 +1815,13 @@ static int device_prepare(struct device *dev, pm_message_t state)* it again during the complete phase. */ pm_runtime_get_noresume (dev); +/* +* If runtime PM is disabled for the device at this point and it has +* never been enabled so far, it should not be enabled until this system +* suspend-resume cycle is complete, so prepare to trigger a warning on +* subsequent attempts to enable it. +*/ +pm_runtime_block_if_disabled (dev);if (dev->power.syscore)return 0 ;
drivers/base/power/runtime.c +24 -0
@@ -1469,6 +1469,26 @@ int pm_runtime_barrier(struct device *dev) }EXPORT_SYMBOL_GPL (pm_runtime_barrier); +void pm_runtime_block_if_disabled (struct device *dev) +{ +spin_lock_irq (&dev->power.lock); + +if (dev->power.disable_depth && dev->power.last_status ==RPM_INVALID ) + dev->power.last_status =RPM_BLOCKED ; + +spin_unlock_irq (&dev->power.lock); +} + +void pm_runtime_unblock (struct device *dev) +{ +spin_lock_irq (&dev->power.lock); + +if (dev->power.last_status ==RPM_BLOCKED ) + dev->power.last_status =RPM_INVALID ; + +spin_unlock_irq (&dev->power.lock); +} +void __pm_runtime_disable (struct device *dev,bool check_resume) {spin_lock_irq (&dev->power.lock);
@@ -1527,6 +1547,10 @@ void pm_runtime_enable(struct device *dev)if (--dev->power.disable_depth >0 ) goto out; +if (dev->power.last_status ==RPM_BLOCKED ) { +dev_warn (dev,"Attempt to enable runtime PM when it is blocked\n" ); +dump_stack (); + } dev->power.last_status =RPM_INVALID ; dev->power.accounting_timestamp =ktime_get_mono_fast_ns ();
include/linux/pm.h +1 -0
@@ -600,6 +600,7 @@ enum rpm_status {RPM_RESUMING ,RPM_SUSPENDED ,RPM_SUSPENDING , + RPM_BLOCKED, };/*
include/linux/pm_runtime.h +4 -0
@@ -78,6 +78,8 @@ extern int pm_runtime_get_if_in_use(struct device *dev);extern int pm_schedule_suspend (struct device *dev,unsigned int delay);extern int __pm_runtime_set_status (struct device *dev,unsigned int status);extern int pm_runtime_barrier (struct device *dev); +extern void pm_runtime_block_if_disabled (struct device *dev); +extern void pm_runtime_unblock (struct device *dev);extern void pm_runtime_enable (struct device *dev);extern void __pm_runtime_disable (struct device *dev,bool check_resume);extern void pm_runtime_allow (struct device *dev);
@@ -275,6 +277,8 @@ static inline int pm_runtime_get_if_active(struct device *dev)static inline int __pm_runtime_set_status (struct device *dev,unsigned int status) {return 0 ; }static inline int pm_runtime_barrier (struct device *dev) {return 0 ; } +static inline void pm_runtime_block_if_disabled (struct device *dev) {} +static inline void pm_runtime_unblock (struct device *dev) {}static inline void pm_runtime_enable (struct device *dev) {}static inline void __pm_runtime_disable (struct device *dev,bool c) {}static inline void pm_runtime_allow (struct device *dev) {}
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 737/869 PM: runtime: Introduce pm_runtime_blocked()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rafael J. Wysocki <[email protected]>
[ Upstream commit 758cc55ce3d5d79e8f98adbd03ad2cd29133af33 ]
Introduce a new helper function called pm_runtime_blocked() for checking the power.last_status value indicating whether or not enabling runtime PM for the given device has been blocked (which happens in the "prepare" phase of system-wide suspend if runtime PM is disabled for the given device at that point).
Stable-dep-of: 36d74f17e03f ("driver core: Avoid warning when removing a device while its supplier is unbinding")
--- drivers/base/power/runtime.c | 17 +++++++++++++++++ include/linux/pm_runtime.h | 2 ++ 2 files changed, 19 insertions(+)
drivers/base/power/runtime.c +17 -0
@@ -1590,6 +1590,23 @@ int devm_pm_runtime_set_active_enabled(struct device *dev) }EXPORT_SYMBOL_GPL (devm_pm_runtime_set_active_enabled); +bool pm_runtime_blocked (struct device *dev) +{ +bool ret; + +/* +* dev->power.last_status is a bit field, so in case it is updated via +* RMW, read it under the spin lock. +*/ +spin_lock_irq (&dev->power.lock); + + ret = dev->power.last_status ==RPM_BLOCKED ; + +spin_unlock_irq (&dev->power.lock); + +return ret; +} +static void pm_runtime_disable_action (void *data) {pm_runtime_dont_use_autosuspend (data);
include/linux/pm_runtime.h +2 -0
@@ -82,6 +82,7 @@ extern void pm_runtime_block_if_disabled(struct device *dev);extern void pm_runtime_unblock (struct device *dev);extern void pm_runtime_enable (struct device *dev);extern void __pm_runtime_disable (struct device *dev,bool check_resume); +extern bool pm_runtime_blocked (struct device *dev);extern void pm_runtime_allow (struct device *dev);extern void pm_runtime_forbid (struct device *dev);extern void pm_runtime_no_callbacks (struct device *dev);
@@ -281,6 +282,7 @@ static inline void pm_runtime_block_if_disabled(struct device *dev) {}static inline void pm_runtime_unblock (struct device *dev) {}static inline void pm_runtime_enable (struct device *dev) {}static inline void __pm_runtime_disable (struct device *dev,bool c) {} +static inline bool pm_runtime_blocked (struct device *dev) {return true; }static inline void pm_runtime_allow (struct device *dev) {}static inline void pm_runtime_forbid (struct device *dev) {}
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 738/869 PM: sleep: Use DPM_FLAG_SMART_SUSPEND conditionally
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rafael J. Wysocki <[email protected]>
[ Upstream commit bca84a7b93fdc744d79d94423c2cb905b1832310 ]
A recent discussion has revealed that using DPM_FLAG_SMART_SUSPEND unconditionally is generally problematic because it may lead to situations in which the device's runtime PM information is internally inconsistent or does not reflect its real state [1].
For this reason, change the handling of DPM_FLAG_SMART_SUSPEND so that it is only taken into account if it is consistently set by the drivers of all devices having any PM callbacks throughout dependency graphs in accordance with the following rules:
- The "smart suspend" feature is only enabled for devices whose drivers ask for it (that is, set DPM_FLAG_SMART_SUSPEND) and for devices without PM callbacks unless they have never had runtime PM enabled.
- The "smart suspend" feature is not enabled for a device if it has not been enabled for the device's parent unless the parent does not take children into account or it has never had runtime PM enabled.
- The "smart suspend" feature is not enabled for a device if it has not been enabled for one of the device's suppliers taking runtime PM into account unless that supplier has never had runtime PM enabled.
Namely, introduce a new device PM flag called smart_suspend that is only set if the above conditions are met and update all DPM_FLAG_SMART_SUSPEND users to check power.smart_suspend instead of directly checking the latter.
At the same time, drop the power.set_active flage introduced recently in commit 3775fc538f53 ("PM: sleep: core: Synchronize runtime PM status of parents and children") because it is now sufficient to check power.smart_suspend along with the dev_pm_skip_resume() return value to decide whether or not pm_runtime_set_active() needs to be called for the device.
Stable-dep-of: 36d74f17e03f ("driver core: Avoid warning when removing a device while its supplier is unbinding")
--- drivers/acpi/device_pm.c | 4 +-- drivers/base/power/main.c | 63 ++++++++++++++++++++++++++++++--------- drivers/mfd/intel-lpss.c | 2 +- drivers/pci/pci-driver.c | 6 ++-- include/linux/device.h | 9 ++++++ include/linux/pm.h | 2 +- 6 files changed, 64 insertions(+), 22 deletions(-)
drivers/acpi/device_pm.c +2 -2
@@ -1161,7 +1161,7 @@ EXPORT_SYMBOL_GPL(acpi_subsys_complete);*/ int acpi_subsys_suspend (struct device *dev) { -if (!dev_pm_test_driver_flags (dev,DPM_FLAG_SMART_SUSPEND ) || +if (!dev_pm_smart_suspend (dev) ||acpi_dev_needs_resume (dev,ACPI_COMPANION (dev)))pm_runtime_resume (dev);
@@ -1320,7 +1320,7 @@ EXPORT_SYMBOL_GPL(acpi_subsys_restore_early);*/ int acpi_subsys_poweroff (struct device *dev) { -if (!dev_pm_test_driver_flags (dev,DPM_FLAG_SMART_SUSPEND ) || +if (!dev_pm_smart_suspend (dev) ||acpi_dev_needs_resume (dev,ACPI_COMPANION (dev)))pm_runtime_resume (dev);
drivers/base/power/main.c +49 -14
96 lines not on this page · raw message
drivers/mfd/intel-lpss.c +1 -1
@@ -480,7 +480,7 @@ EXPORT_SYMBOL_NS_GPL(intel_lpss_remove, INTEL_LPSS);static int resume_lpss_device (struct device *dev,void *data) { -if (!dev_pm_test_driver_flags (dev,DPM_FLAG_SMART_SUSPEND )) +if (!dev_pm_smart_suspend (dev))pm_runtime_resume (dev);return 0 ;
drivers/pci/pci-driver.c +2 -4
@@ -839,8 +839,7 @@ static int pci_pm_suspend(struct device *dev)* suspend callbacks can cope with runtime-suspended devices, it is * better to resume the device from runtime suspend here. */ -if (!dev_pm_test_driver_flags (dev,DPM_FLAG_SMART_SUSPEND ) || -pci_dev_need_resume (pci_dev)) { +if (!dev_pm_smart_suspend (dev) ||pci_dev_need_resume (pci_dev)) {pm_runtime_resume (dev); pci_dev->state_saved = false; }else {
@@ -1181,8 +1180,7 @@ static int pci_pm_poweroff(struct device *dev) }/* The reason to do that is the same as in pci_pm_suspend(). */ -if (!dev_pm_test_driver_flags (dev,DPM_FLAG_SMART_SUSPEND ) || -pci_dev_need_resume (pci_dev)) { +if (!dev_pm_smart_suspend (dev) ||pci_dev_need_resume (pci_dev)) {pm_runtime_resume (dev); pci_dev->state_saved = false; }else {
include/linux/device.h +9 -0
@@ -994,6 +994,15 @@ static inline bool dev_pm_test_driver_flags(struct device *dev, u32 flags)return !!(dev->power.driver_flags & flags); } +static inline bool dev_pm_smart_suspend (struct device *dev) +{ +#ifdef CONFIG_PM_SLEEP +return dev->power.smart_suspend; +#else +return false; +#endif +} +static inline void device_lock (struct device *dev) {mutex_lock (&dev->mutex);
include/linux/pm.h +1 -1
@@ -683,8 +683,8 @@ struct dev_pm_info { bool syscore:1; bool no_pm_callbacks:1; /* Owned by the PM core */ bool async_in_progress:1; /* Owned by the PM core */ + bool smart_suspend:1; /* Owned by the PM core */ bool must_resume:1; /* Owned by the PM core */ - bool set_active:1; /* Owned by the PM core */ bool may_skip_resume:1; /* Set by subsystems */#else bool should_wakeup:1;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 739/869 PM: sleep: Fix bit masking operation
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Colin Ian King <[email protected]>
[ Upstream commit 3860cbe239639503e56bd4365c6bf4cb957ef04e ]
The mask operation link->flags | DL_FLAG_PM_RUNTIME is always true which is incorrect. The mask operation should be using the bit-wise & operator. Fix this.
Stable-dep-of: 36d74f17e03f ("driver core: Avoid warning when removing a device while its supplier is unbinding")
--- drivers/base/power/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/base/power/main.c +1 -1
@@ -1817,7 +1817,7 @@ static void device_prepare_smart_suspend(struct device *dev) idx =device_links_read_lock ();list_for_each_entry_rcu_locked (link, &dev->links.suppliers, c_node) { -if (!(link->flags |DL_FLAG_PM_RUNTIME )) +if (!(link->flags &DL_FLAG_PM_RUNTIME ))continue ; if (!dev_pm_smart_suspend(link->supplier) &&
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 740/869 driver core: Add device_link_test() for testing device link flags
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rafael J. Wysocki <[email protected]>
[ Upstream commit b29929b819f35503024c6a7e6ad442f6e36c68a0 ]
To avoid coding mistakes like the one fixed by commit 3860cbe23963 ("PM:
sleep: Fix bit masking operation"), introduce device_link_test() for testing device link flags and use it where applicable.
No intentional functional impact.
Stable-dep-of: 36d74f17e03f ("driver core: Avoid warning when removing a device while its supplier is unbinding")
--- drivers/base/core.c | 73 ++++++++++++++++++------------------ drivers/base/power/main.c | 2 +- drivers/base/power/runtime.c | 6 +-- include/linux/device.h | 5 +++ 4 files changed, 45 insertions(+), 41 deletions(-)
drivers/base/core.c +36 -37
@@ -533,9 +533,9 @@ static ssize_t auto_remove_on_show(struct device *dev,struct device_link *link =to_devlink (dev);const char *output; -if (link->flags &DL_FLAG_AUTOREMOVE_SUPPLIER ) +if (device_link_test (link,DL_FLAG_AUTOREMOVE_SUPPLIER )) output ="supplier unbind" ; -else if (link->flags &DL_FLAG_AUTOREMOVE_CONSUMER ) +else if (device_link_test (link,DL_FLAG_AUTOREMOVE_CONSUMER )) output ="consumer unbind" ;else output ="never" ;
@@ -549,7 +549,7 @@ static ssize_t runtime_pm_show(struct device *dev, {struct device_link *link =to_devlink (dev); -return sysfs_emit (buf,"%d\n" , !!(link->flags &DL_FLAG_PM_RUNTIME )); +return sysfs_emit (buf,"%d\n" ,device_link_test (link,DL_FLAG_PM_RUNTIME )); }static DEVICE_ATTR_RO (runtime_pm);
@@ -558,8 +558,7 @@ static ssize_t sync_state_only_show(struct device *dev, {struct device_link *link =to_devlink (dev); -return sysfs_emit (buf,"%d\n" , - !!(link->flags &DL_FLAG_SYNC_STATE_ONLY )); +return sysfs_emit (buf,"%d\n" ,device_link_test (link,DL_FLAG_SYNC_STATE_ONLY )); }static DEVICE_ATTR_RO (sync_state_only);
@@ -865,12 +864,12 @@ struct device_link *device_link_add(struct device *consumer,if (link->consumer != consumer)continue ; -if (link->flags &DL_FLAG_INFERRED && +if (device_link_test (link,DL_FLAG_INFERRED ) && !(flags &DL_FLAG_INFERRED )) link->flags &= ~DL_FLAG_INFERRED ;if (flags &DL_FLAG_PM_RUNTIME ) { -if (!(link->flags &DL_FLAG_PM_RUNTIME )) { +if (!device_link_test (link,DL_FLAG_PM_RUNTIME )) {pm_runtime_new_link (consumer); link->flags |=DL_FLAG_PM_RUNTIME ; }
@@ -880,8 +879,8 @@ struct device_link *device_link_add(struct device *consumer,if (flags &DL_FLAG_STATELESS ) {kref_get (&link->kref); -if (link->flags &DL_FLAG_SYNC_STATE_ONLY && - !(link->flags &DL_FLAG_STATELESS )) { +if (device_link_test (link,DL_FLAG_SYNC_STATE_ONLY ) && + !device_link_test (link,DL_FLAG_STATELESS )) { link->flags |=DL_FLAG_STATELESS ; goto reorder; }else {
@@ -896,7 +895,7 @@ struct device_link *device_link_add(struct device *consumer,* update the existing link to stay around longer. */ if (flags &DL_FLAG_AUTOREMOVE_SUPPLIER ) { -if (link->flags &DL_FLAG_AUTOREMOVE_CONSUMER ) { +if (device_link_test (link,DL_FLAG_AUTOREMOVE_CONSUMER )) { link->flags &= ~DL_FLAG_AUTOREMOVE_CONSUMER ; link->flags |=DL_FLAG_AUTOREMOVE_SUPPLIER ; }
@@ -904,12 +903,12 @@ struct device_link *device_link_add(struct device *consumer, link->flags &= ~(DL_FLAG_AUTOREMOVE_CONSUMER |DL_FLAG_AUTOREMOVE_SUPPLIER ); } -if (!(link->flags &DL_FLAG_MANAGED )) { +if (!device_link_test (link,DL_FLAG_MANAGED )) {kref_get (&link->kref); link->flags |=DL_FLAG_MANAGED ;device_link_init_status (link, consumer, supplier); } -if (link->flags &DL_FLAG_SYNC_STATE_ONLY && +if (device_link_test (link,DL_FLAG_SYNC_STATE_ONLY ) && !(flags &DL_FLAG_SYNC_STATE_ONLY )) { link->flags &= ~DL_FLAG_SYNC_STATE_ONLY ; goto reorder;
@@ -1013,7 +1012,7 @@ static void __device_link_del(struct kref *kref)static void device_link_put_kref (struct device_link *link) { -if (link->flags &DL_FLAG_STATELESS ) +if (device_link_test (link,DL_FLAG_STATELESS ))kref_put (&link->kref, __device_link_del);else if (!device_is_registered (link->consumer))__device_link_del (&link->kref);
@@ -1077,7 +1076,7 @@ static void device_links_missing_supplier(struct device *dev)if (link->supplier->links.status ==DL_DEV_DRIVER_BOUND ) {WRITE_ONCE (link->status,DL_STATE_AVAILABLE ); }else { -WARN_ON (!(link->flags &DL_FLAG_SYNC_STATE_ONLY )); +WARN_ON (!device_link_test (link,DL_FLAG_SYNC_STATE_ONLY ));WRITE_ONCE (link->status,DL_STATE_DORMANT ); } }
@@ -1145,14 +1144,14 @@ int device_links_check_suppliers(struct device *dev)device_links_write_lock ();list_for_each_entry (link, &dev->links.suppliers, c_node) { -if (!(link->flags &DL_FLAG_MANAGED )) +if (!device_link_test (link,DL_FLAG_MANAGED ))continue ;if (link->status !=DL_STATE_AVAILABLE && - !(link->flags &DL_FLAG_SYNC_STATE_ONLY )) { + !device_link_test (link,DL_FLAG_SYNC_STATE_ONLY )) {if (dev_is_best_effort (dev) && - link->flags &DL_FLAG_INFERRED && +device_link_test (link,DL_FLAG_INFERRED ) && !link->supplier->can_match) { ret = -EAGAIN ;continue ;
@@ -1201,7 +1200,7 @@ static void __device_links_queue_sync_state(struct device *dev,return ;list_for_each_entry (link, &dev->links.consumers, s_node) { -if (!(link->flags &DL_FLAG_MANAGED )) +if (!device_link_test (link,DL_FLAG_MANAGED ))continue ;if (link->status !=DL_STATE_ACTIVE )return ;
@@ -1341,7 +1340,7 @@ void device_links_force_bind(struct device *dev)device_links_write_lock ();list_for_each_entry_safe (link, ln, &dev->links.suppliers, c_node) { -if (!(link->flags &DL_FLAG_MANAGED )) +if (!device_link_test (link,DL_FLAG_MANAGED ))continue ;if (link->status !=DL_STATE_AVAILABLE ) {
@@ -1394,7 +1393,7 @@ void device_links_driver_bound(struct device *dev)device_links_write_lock ();list_for_each_entry (link, &dev->links.consumers, s_node) { -if (!(link->flags &DL_FLAG_MANAGED )) +if (!device_link_test (link,DL_FLAG_MANAGED ))continue ;/*
@@ -1410,7 +1409,7 @@ void device_links_driver_bound(struct device *dev)WARN_ON (link->status !=DL_STATE_DORMANT );WRITE_ONCE (link->status,DL_STATE_AVAILABLE ); -if (link->flags &DL_FLAG_AUTOPROBE_CONSUMER ) +if (device_link_test (link,DL_FLAG_AUTOPROBE_CONSUMER ))driver_deferred_probe_add (link->consumer); }
@@ -1422,11 +1421,11 @@ void device_links_driver_bound(struct device *dev)list_for_each_entry_safe (link, ln, &dev->links.suppliers, c_node) {struct device *supplier; -if (!(link->flags &DL_FLAG_MANAGED )) +if (!device_link_test (link,DL_FLAG_MANAGED ))continue ; supplier = link->supplier; -if (link->flags &DL_FLAG_SYNC_STATE_ONLY ) { +if (device_link_test (link,DL_FLAG_SYNC_STATE_ONLY )) {/* * When DL_FLAG_SYNC_STATE_ONLY is set, it means no * other DL_MANAGED_LINK_FLAGS have been set. So, it's
@@ -1434,7 +1433,7 @@ void device_links_driver_bound(struct device *dev)*/ device_link_drop_managed (link); }else if (dev_is_best_effort (dev) && - link->flags &DL_FLAG_INFERRED && +device_link_test (link,DL_FLAG_INFERRED ) && link->status !=DL_STATE_CONSUMER_PROBE && !link->supplier->can_match) {/*
@@ -1486,10 +1485,10 @@ static void __device_links_no_driver(struct device *dev)struct device_link *link, *ln;list_for_each_entry_safe_reverse (link, ln, &dev->links.suppliers, c_node) { -if (!(link->flags &DL_FLAG_MANAGED )) +if (!device_link_test (link,DL_FLAG_MANAGED ))continue ; -if (link->flags &DL_FLAG_AUTOREMOVE_CONSUMER ) { +if (device_link_test (link,DL_FLAG_AUTOREMOVE_CONSUMER )) {device_link_drop_managed (link);continue ; }
@@ -1501,7 +1500,7 @@ static void __device_links_no_driver(struct device *dev)if (link->supplier->links.status ==DL_DEV_DRIVER_BOUND ) {WRITE_ONCE (link->status,DL_STATE_AVAILABLE ); }else { -WARN_ON (!(link->flags &DL_FLAG_SYNC_STATE_ONLY )); +WARN_ON (!device_link_test (link,DL_FLAG_SYNC_STATE_ONLY ));WRITE_ONCE (link->status,DL_STATE_DORMANT ); } }
@@ -1526,7 +1525,7 @@ void device_links_no_driver(struct device *dev)device_links_write_lock ();list_for_each_entry (link, &dev->links.consumers, s_node) { -if (!(link->flags &DL_FLAG_MANAGED )) +if (!device_link_test (link,DL_FLAG_MANAGED ))continue ;/*
@@ -1563,10 +1562,10 @@ void device_links_driver_cleanup(struct device *dev)device_links_write_lock ();list_for_each_entry_safe (link, ln, &dev->links.consumers, s_node) { -if (!(link->flags &DL_FLAG_MANAGED )) +if (!device_link_test (link,DL_FLAG_MANAGED ))continue ; -WARN_ON (link->flags &DL_FLAG_AUTOREMOVE_CONSUMER ); +WARN_ON (device_link_test (link,DL_FLAG_AUTOREMOVE_CONSUMER ));WARN_ON (link->status !=DL_STATE_SUPPLIER_UNBIND );/*
@@ -1575,7 +1574,7 @@ void device_links_driver_cleanup(struct device *dev)* has moved to DL_STATE_SUPPLIER_UNBIND. */ if (link->status ==DL_STATE_SUPPLIER_UNBIND && - link->flags &DL_FLAG_AUTOREMOVE_SUPPLIER ) +device_link_test (link,DL_FLAG_AUTOREMOVE_SUPPLIER ))device_link_drop_managed (link);WRITE_ONCE (link->status,DL_STATE_DORMANT );
@@ -1609,7 +1608,7 @@ bool device_links_busy(struct device *dev)device_links_write_lock ();list_for_each_entry (link, &dev->links.consumers, s_node) { -if (!(link->flags &DL_FLAG_MANAGED )) +if (!device_link_test (link,DL_FLAG_MANAGED ))continue ; if (link->status == DL_STATE_CONSUMER_PROBE
@@ -1651,8 +1650,8 @@ void device_links_unbind_consumers(struct device *dev)list_for_each_entry (link, &dev->links.consumers, s_node) {enum device_link_state status; -if (!(link->flags &DL_FLAG_MANAGED ) || - link->flags &DL_FLAG_SYNC_STATE_ONLY ) +if (!device_link_test (link,DL_FLAG_MANAGED ) || +device_link_test (link,DL_FLAG_SYNC_STATE_ONLY ))continue ; status = link->status;
@@ -1808,7 +1807,7 @@ static void fw_devlink_parse_fwtree(struct fwnode_handle *fwnode)static void fw_devlink_relax_link (struct device_link *link) { -if (!(link->flags &DL_FLAG_INFERRED )) +if (!device_link_test (link,DL_FLAG_INFERRED ))return ;if (device_link_flag_is_sync_state_only (link->flags))
@@ -1844,7 +1843,7 @@ static int fw_devlink_dev_sync_state(struct device *dev, void *data)struct device_link *link =to_devlink (dev);struct device *sup = link->supplier; -if (!(link->flags &DL_FLAG_MANAGED ) || +if (!device_link_test (link,DL_FLAG_MANAGED ) || link->status ==DL_STATE_ACTIVE || sup->state_synced || !dev_has_sync_state (sup))return 0 ;
@@ -2126,7 +2125,7 @@ static bool __fw_devlink_relax_cycles(struct fwnode_handle *con_handle,* such due to a cycle. */ if (device_link_flag_is_sync_state_only (dev_link->flags) && - !(dev_link->flags &DL_FLAG_CYCLE )) + !device_link_test (dev_link,DL_FLAG_CYCLE ))continue ; if (__fw_devlink_relax_cycles(con_handle,
drivers/base/power/main.c +1 -1
@@ -1817,7 +1817,7 @@ static void device_prepare_smart_suspend(struct device *dev) idx =device_links_read_lock ();list_for_each_entry_rcu_locked (link, &dev->links.suppliers, c_node) { -if (!(link->flags &DL_FLAG_PM_RUNTIME )) +if (!device_link_test (link,DL_FLAG_PM_RUNTIME ))continue ; if (!dev_pm_smart_suspend(link->supplier) &&
drivers/base/power/runtime.c +3 -3
@@ -290,7 +290,7 @@ static int rpm_get_suppliers(struct device *dev) device_links_read_lock_held()) {int retval; -if (!(link->flags &DL_FLAG_PM_RUNTIME )) +if (!device_link_test (link,DL_FLAG_PM_RUNTIME ))continue ; retval =pm_runtime_get_sync (link->supplier);
@@ -1900,7 +1900,7 @@ void pm_runtime_get_suppliers(struct device *dev)list_for_each_entry_rcu (link, &dev->links.suppliers, c_node,device_links_read_lock_held ()) -if (link->flags &DL_FLAG_PM_RUNTIME ) { +if (device_link_test (link,DL_FLAG_PM_RUNTIME )) { link->supplier_preactivated = true;pm_runtime_get_sync (link->supplier); }
@@ -1954,7 +1954,7 @@ static void pm_runtime_drop_link_count(struct device *dev)*/ void pm_runtime_drop_link (struct device_link *link) { -if (!(link->flags &DL_FLAG_PM_RUNTIME )) +if (!device_link_test (link,DL_FLAG_PM_RUNTIME ))return ;pm_runtime_drop_link_count (link->consumer);
include/linux/device.h +5 -0
@@ -1262,6 +1262,11 @@ void device_links_supplier_sync_state_pause(void);void device_links_supplier_sync_state_resume (void );void device_link_wait_removal (void ); +static inline bool device_link_test (const struct device_link *link,u32 flags) +{ +return !!(link->flags & flags); +} +/* Create alias, so I can be autoloaded. */ #define MODULE_ALIAS_CHARDEV (major,minor) \ MODULE_ALIAS("char-major-" __stringify(major) "-" __stringify(minor))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 741/869 driver core: Avoid warning when removing a device while its supplier is unbinding
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Herve Codina <[email protected]>
[ Upstream commit 36d74f17e03f7e60e1b08fbe16cfad6e69cc3aa9 ]
During driver removal, the following warning can appear:
WARNING: CPU: 1 PID: 139 at drivers/base/core.c:1497 __device_links_no_driver+0xcc/0xfc
...
Call trace:
__device_links_no_driver+0xcc/0xfc (P)
device_links_driver_cleanup+0xa8/0xf0
device_release_driver_internal+0x208/0x23c
device_links_unbind_consumers+0xe0/0x108
device_release_driver_internal+0xec/0x23c
device_links_unbind_consumers+0xe0/0x108
device_release_driver_internal+0xec/0x23c
device_links_unbind_consumers+0xe0/0x108
device_release_driver_internal+0xec/0x23c
driver_detach+0xa0/0x12c
bus_remove_driver+0x6c/0xbc
driver_unregister+0x30/0x60
pci_unregister_driver+0x20/0x9c
lan966x_pci_driver_exit+0x18/0xa90 [lan966x_pci]This warning is triggered when a consumer is removed because the links status of its supplier is not DL_DEV_DRIVER_BOUND and the link flag DL_FLAG_SYNC_STATE_ONLY is not set.
The topology in terms of consumers/suppliers used was the following (consumer ---> supplier):
i2c -----------> OIC ----> PCI device
| ^
| |
+---> pinctrl ---+When the PCI device is removed, the OIC (interrupt controller) has to be removed. In order to remove the OIC, pinctrl and i2c need to be removed and to remove pinctrl, i2c need to be removed. The removal order is:
1) i2c
2) pinctrl
3) OIC
4) PCI device
In details, the removal sequence is the following (with 0000:01:00.0 the PCI device):
driver_detach: call device_release_driver_internal(0000:01:00.0)...
device_links_busy(0000:01:00.0):
links->status = DL_DEV_UNBINDING
device_links_unbind_consumers(0000:01:00.0):
0000:01:00.0--oic link->status = DL_STATE_SUPPLIER_UNBIND
call device_release_driver_internal(oic)...
device_links_busy(oic):
links->status = DL_DEV_UNBINDING
device_links_unbind_consumers(oic):
oic--pinctrl link->status = DL_STATE_SUPPLIER_UNBIND
call device_release_driver_internal(pinctrl)...
device_links_busy(pinctrl):
links->status = DL_DEV_UNBINDING
device_links_unbind_consumers(pinctrl):
pinctrl--i2c link->status = DL_STATE_SUPPLIER_UNBIND
call device_release_driver_internal(i2c)...
device_links_busy(i2c): links->status = DL_DEV_UNBINDING
__device_links_no_driver(i2c)...
pinctrl--i2c link->status is DL_STATE_SUPPLIER_UNBIND
oic--i2c link->status is DL_STATE_ACTIVE
oic--i2c link->supplier->links.status is DL_DEV_UNBINDINGThe warning is triggered by the i2c removal because the OIC (supplier) links status is not DL_DEV_DRIVER_BOUND. Its links status is indeed set to DL_DEV_UNBINDING.
It is perfectly legit to have the links status set to DL_DEV_UNBINDING in that case. Indeed we had started to unbind the OIC which triggered the consumer unbinding and didn't finish yet when the i2c is unbound.
Avoid the warning when the supplier links status is set to DL_DEV_UNBINDING and thus support this removal sequence without any warnings.
--- drivers/base/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/base/core.c +2 -1
@@ -1500,7 +1500,8 @@ static void __device_links_no_driver(struct device *dev)if (link->supplier->links.status ==DL_DEV_DRIVER_BOUND ) {WRITE_ONCE (link->status,DL_STATE_AVAILABLE ); }else { -WARN_ON (!device_link_test (link,DL_FLAG_SYNC_STATE_ONLY )); +WARN_ON (link->supplier->links.status !=DL_DEV_UNBINDING && + !device_link_test (link,DL_FLAG_SYNC_STATE_ONLY ));WRITE_ONCE (link->status,DL_STATE_DORMANT ); } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 742/869 serial: 8250: invert serial8250_register_8250_port() CIR condition
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiri Slaby (SUSE) <[email protected]>
[ Upstream commit 05b537a175442c530593013ea31b3f48d5624916 ]
There is no point in a long 'if' in serial8250_register_8250_port() to just return ENOSPC for PORT_8250_CIR ports. Invert the condition and return immediately.
'gpios' variable was moved to its set location.
And return ENODEV instead of ENOSPC. The latter is a leftover from the previous find-uart 'if'. The former makes a lot more sense in this case.
Stable-dep-of: 941c9f84c9b6 ("tty: serial: 8250: protect against NULL uart->port.dev in register")
--- drivers/tty/serial/8250/8250_core.c | 253 ++++++++++++++-------------- 1 file changed, 127 insertions(+), 126 deletions(-)
drivers/tty/serial/8250/8250_core.c +127 -126
@@ -715,139 +715,140 @@ int serial8250_register_8250_port(const struct uart_8250_port *up) nr_uarts++; } -if (uart->port.type !=PORT_8250_CIR ) { -struct mctrl_gpios *gpios; - -if (uart->port.dev) -uart_remove_one_port (&serial8250_reg, &uart->port); - - uart->port.ctrl_id = up->port.ctrl_id; - uart->port.port_id = up->port.port_id; - uart->port.iobase = up->port.iobase; - uart->port.membase = up->port.membase; - uart->port.irq = up->port.irq; - uart->port.irqflags = up->port.irqflags; - uart->port.uartclk = up->port.uartclk; - uart->port.fifosize = up->port.fifosize; - uart->port.regshift = up->port.regshift; - uart->port.iotype = up->port.iotype; - uart->port.flags = up->port.flags |UPF_BOOT_AUTOCONF ; - uart->bugs = up->bugs; - uart->port.mapbase = up->port.mapbase; - uart->port.mapsize = up->port.mapsize; - uart->port.private_data = up->port.private_data; - uart->tx_loadsz = up->tx_loadsz; - uart->capabilities = up->capabilities; - uart->port.throttle = up->port.throttle; - uart->port.unthrottle = up->port.unthrottle; - uart->port.rs485_config = up->port.rs485_config; - uart->port.rs485_supported = up->port.rs485_supported; - uart->port.rs485 = up->port.rs485; - uart->rs485_start_tx = up->rs485_start_tx; - uart->rs485_stop_tx = up->rs485_stop_tx; - uart->lsr_save_mask = up->lsr_save_mask; - uart->dma = up->dma; - -/* Take tx_loadsz from fifosize if it wasn't set separately */ -if (uart->port.fifosize && !uart->tx_loadsz) - uart->tx_loadsz = uart->port.fifosize; - -if (up->port.dev) { - uart->port.dev = up->port.dev; - ret =uart_get_rs485_mode (&uart->port); -if (ret) - goto err; - } +if (uart->port.type ==PORT_8250_CIR ) { + ret = -ENODEV ; + goto unlock; + } -if (up->port.flags &UPF_FIXED_TYPE ) - uart->port.type = up->port.type; +if (uart->port.dev) +uart_remove_one_port (&serial8250_reg, &uart->port); + + uart->port.ctrl_id = up->port.ctrl_id; + uart->port.port_id = up->port.port_id; + uart->port.iobase = up->port.iobase; + uart->port.membase = up->port.membase; + uart->port.irq = up->port.irq; + uart->port.irqflags = up->port.irqflags; + uart->port.uartclk = up->port.uartclk; + uart->port.fifosize = up->port.fifosize; + uart->port.regshift = up->port.regshift; + uart->port.iotype = up->port.iotype; + uart->port.flags = up->port.flags |UPF_BOOT_AUTOCONF ; + uart->bugs = up->bugs; + uart->port.mapbase = up->port.mapbase; + uart->port.mapsize = up->port.mapsize; + uart->port.private_data = up->port.private_data; + uart->tx_loadsz = up->tx_loadsz; + uart->capabilities = up->capabilities; + uart->port.throttle = up->port.throttle; + uart->port.unthrottle = up->port.unthrottle; + uart->port.rs485_config = up->port.rs485_config; + uart->port.rs485_supported = up->port.rs485_supported; + uart->port.rs485 = up->port.rs485; + uart->rs485_start_tx = up->rs485_start_tx; + uart->rs485_stop_tx = up->rs485_stop_tx; + uart->lsr_save_mask = up->lsr_save_mask; + uart->dma = up->dma; + +/* Take tx_loadsz from fifosize if it wasn't set separately */ +if (uart->port.fifosize && !uart->tx_loadsz) + uart->tx_loadsz = uart->port.fifosize; + +if (up->port.dev) { + uart->port.dev = up->port.dev; + ret =uart_get_rs485_mode (&uart->port); +if (ret) + goto err; + } -/* -* Only call mctrl_gpio_init(), if the device has no ACPI -* companion device -*/ -if (!has_acpi_companion (uart->port.dev)) { - gpios =mctrl_gpio_init (&uart->port,0 ); -if (IS_ERR (gpios)) { - ret =PTR_ERR (gpios); - goto err; - }else { - uart->gpios = gpios; - } - } +if (up->port.flags &UPF_FIXED_TYPE ) + uart->port.type = up->port.type; -serial8250_set_defaults (uart); - -/* Possibly override default I/O functions. */ -if (up->port.serial_in) - uart->port.serial_in = up->port.serial_in; -if (up->port.serial_out) - uart->port.serial_out = up->port.serial_out; -if (up->port.handle_irq) - uart->port.handle_irq = up->port.handle_irq; -/* Possibly override set_termios call */ -if (up->port.set_termios) - uart->port.set_termios = up->port.set_termios; -if (up->port.set_ldisc) - uart->port.set_ldisc = up->port.set_ldisc; -if (up->port.get_mctrl) - uart->port.get_mctrl = up->port.get_mctrl; -if (up->port.set_mctrl) - uart->port.set_mctrl = up->port.set_mctrl; -if (up->port.get_divisor) - uart->port.get_divisor = up->port.get_divisor; -if (up->port.set_divisor) - uart->port.set_divisor = up->port.set_divisor; -if (up->port.startup) - uart->port.startup = up->port.startup; -if (up->port.shutdown) - uart->port.shutdown = up->port.shutdown; -if (up->port.pm) - uart->port.pm = up->port.pm; -if (up->port.handle_break) - uart->port.handle_break = up->port.handle_break; -if (up->dl_read) - uart->dl_read = up->dl_read; -if (up->dl_write) - uart->dl_write = up->dl_write; - -if (uart->port.type !=PORT_8250_CIR ) { -if (uart_console_registered (&uart->port)) -pm_runtime_get_sync (uart->port.dev); - -if (serial8250_isa_config !=NULL ) -serial8250_isa_config (0 , &uart->port, - &uart->capabilities); - -serial8250_apply_quirks (uart); - ret =uart_add_one_port (&serial8250_reg, - &uart->port); -if (ret) - goto err; - - ret = uart->port.line; +/* +* Only call mctrl_gpio_init(), if the device has no ACPI +* companion device +*/ +if (!has_acpi_companion (uart->port.dev)) { +struct mctrl_gpios *gpios =mctrl_gpio_init (&uart->port,0 ); +if (IS_ERR (gpios)) { + ret =PTR_ERR (gpios); + goto err; }else { -dev_info (uart->port.dev, -"skipping CIR port at 0x%lx / 0x%llx, IRQ %d\n" , - uart->port.iobase, - (unsigned long long )uart->port.mapbase, - uart->port.irq); - - ret =0 ; + uart->gpios = gpios; } + } -if (!uart->lsr_save_mask) - uart->lsr_save_mask =LSR_SAVE_FLAGS ;/* Use default LSR mask */ +serial8250_set_defaults (uart); + +/* Possibly override default I/O functions. */ +if (up->port.serial_in) + uart->port.serial_in = up->port.serial_in; +if (up->port.serial_out) + uart->port.serial_out = up->port.serial_out; +if (up->port.handle_irq) + uart->port.handle_irq = up->port.handle_irq; +/* Possibly override set_termios call */ +if (up->port.set_termios) + uart->port.set_termios = up->port.set_termios; +if (up->port.set_ldisc) + uart->port.set_ldisc = up->port.set_ldisc; +if (up->port.get_mctrl) + uart->port.get_mctrl = up->port.get_mctrl; +if (up->port.set_mctrl) + uart->port.set_mctrl = up->port.set_mctrl; +if (up->port.get_divisor) + uart->port.get_divisor = up->port.get_divisor; +if (up->port.set_divisor) + uart->port.set_divisor = up->port.set_divisor; +if (up->port.startup) + uart->port.startup = up->port.startup; +if (up->port.shutdown) + uart->port.shutdown = up->port.shutdown; +if (up->port.pm) + uart->port.pm = up->port.pm; +if (up->port.handle_break) + uart->port.handle_break = up->port.handle_break; +if (up->dl_read) + uart->dl_read = up->dl_read; +if (up->dl_write) + uart->dl_write = up->dl_write; -/* Initialise interrupt backoff work if required */ -if (up->overrun_backoff_time_ms >0 ) { - uart->overrun_backoff_time_ms = - up->overrun_backoff_time_ms; -INIT_DELAYED_WORK (&uart->overrun_backoff, - serial_8250_overrun_backoff_work); - }else { - uart->overrun_backoff_time_ms =0 ; - } +if (uart->port.type !=PORT_8250_CIR ) { +if (uart_console_registered (&uart->port)) +pm_runtime_get_sync (uart->port.dev); + +if (serial8250_isa_config !=NULL ) +serial8250_isa_config (0 , &uart->port, + &uart->capabilities); + +serial8250_apply_quirks (uart); + ret =uart_add_one_port (&serial8250_reg, + &uart->port); +if (ret) + goto err; + + ret = uart->port.line; + }else { +dev_info (uart->port.dev, +"skipping CIR port at 0x%lx / 0x%llx, IRQ %d\n" , + uart->port.iobase, + (unsigned long long )uart->port.mapbase, + uart->port.irq); + + ret =0 ; + } + +if (!uart->lsr_save_mask) + uart->lsr_save_mask =LSR_SAVE_FLAGS ;/* Use default LSR mask */ + +/* Initialise interrupt backoff work if required */ +if (up->overrun_backoff_time_ms >0 ) { + uart->overrun_backoff_time_ms = + up->overrun_backoff_time_ms; +INIT_DELAYED_WORK (&uart->overrun_backoff, + serial_8250_overrun_backoff_work); + }else { + uart->overrun_backoff_time_ms =0 ; } unlock:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 743/869 tty: serial: 8250: protect against NULL uart->port.dev in register
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stepan Ionichev <[email protected]>
[ Upstream commit 941c9f84c9b6310f7aaa1c8c785dcc634ee33050 ]
serial8250_register_8250_port() conditionally copies uart->port.dev from up->port.dev only when up->port.dev is non-NULL:
if (up->port.dev) {
uart->port.dev = up->port.dev;
...
}So if both the existing uart slot and up have a NULL ->dev, uart->port.dev remains NULL. The very next ACPI companion check then dereferences it unconditionally:
if (!has_acpi_companion(uart->port.dev)) {has_acpi_companion() reads dev->fwnode without a NULL guard (include/linux/acpi.h), so this NULL-derefs the kernel for the remaining no-dev case rather than just skipping the mctrl_gpio_init() initialisation as intended.
smatch flags the inconsistency:
drivers/tty/serial/8250/8250_core.c:767 serial8250_register_8250_port() error: 'uart->port.dev' could be null (see line 719)
Guard the call with a NULL check so register continues to work for callers that legitimately have no parent device (legacy non-OF/non-ACPI registrations).
No functional change for callers that pass a non-NULL ->dev.
--- drivers/tty/serial/8250/8250_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/8250/8250_core.c +1 -1
@@ -768,7 +768,7 @@ int serial8250_register_8250_port(const struct uart_8250_port *up)* Only call mctrl_gpio_init(), if the device has no ACPI * companion device */ -if (!has_acpi_companion (uart->port.dev)) { +if (uart->port.dev && !has_acpi_companion (uart->port.dev)) {struct mctrl_gpios *gpios =mctrl_gpio_init (&uart->port,0 );if (IS_ERR (gpios)) { ret =PTR_ERR (gpios);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 744/869 drm/amdgpu: Remove unused amdgpu_i2c functions
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dr. David Alan Gilbert <[email protected]>
[ Upstream commit 0ee239911634dd29c3b05e1138d617cc3cab33fa ]
amdgpu_i2c_add and amdgpu_i2c_init were added in 2015's commit d38ceaf99ed0 ("drm/amdgpu: add core driver (v4)") but never used.
Remove them.
Stable-dep-of: a99cd231cd92 ("drm/amdgpu: Bound GPIO I2C table entry count from VBIOS")
--- drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c | 25 ------------------------- drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.h | 4 ---- 2 files changed, 29 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c +0 -25
@@ -225,15 +225,6 @@ void amdgpu_i2c_destroy(struct amdgpu_i2c_chan *i2c)kfree (i2c); } -/* Add the default buses */ -void amdgpu_i2c_init (struct amdgpu_device *adev) -{ -if (amdgpu_hw_i2c) -DRM_INFO ("hw_i2c forced on, you may experience display detection problems!\n" ); - -amdgpu_atombios_i2c_init (adev); -} -/* remove all the buses */ void amdgpu_i2c_fini (struct amdgpu_device *adev) {
@@ -247,22 +238,6 @@ void amdgpu_i2c_fini(struct amdgpu_device *adev) } } -/* Add additional buses */ -void amdgpu_i2c_add (struct amdgpu_device *adev, -const struct amdgpu_i2c_bus_rec *rec, -const char *name) -{ -struct drm_device *dev =adev_to_drm (adev); -int i; - -for (i =0 ; i <AMDGPU_MAX_I2C_BUS ; i++) { -if (!adev->i2c_bus[i]) { - adev->i2c_bus[i] =amdgpu_i2c_create (dev, rec, name); -return ; - } - } -} -/* looks up bus based on id */ struct amdgpu_i2c_chan * amdgpu_i2c_lookup(struct amdgpu_device *adev,
drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.h +0 -4
@@ -28,11 +28,7 @@ struct amdgpu_i2c_chan *amdgpu_i2c_create(struct drm_device *dev,const struct amdgpu_i2c_bus_rec *rec, const char *name);void amdgpu_i2c_destroy (struct amdgpu_i2c_chan *i2c); -void amdgpu_i2c_init (struct amdgpu_device *adev);void amdgpu_i2c_fini (struct amdgpu_device *adev); -void amdgpu_i2c_add (struct amdgpu_device *adev, -const struct amdgpu_i2c_bus_rec *rec, -const char *name);struct amdgpu_i2c_chan *amdgpu_i2c_lookup (struct amdgpu_device *adev,const struct amdgpu_i2c_bus_rec *i2c_bus);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 745/869 drm/amdgpu/atombios: drop empty function
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alex Deucher <[email protected]>
[ Upstream commit ba7f8eb7e447a8120f5bcb8e8d72964324ee5b84 ]
This was leftover from when amdgpu was forked from radeon. The function is empty so drop it.
Stable-dep-of: a99cd231cd92 ("drm/amdgpu: Bound GPIO I2C table entry count from VBIOS")
--- drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c | 12 ------------ 1 file changed, 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c +0 -12
@@ -36,13 +36,6 @@#include "atombios_encoders.h" #include "bif/bif_4_1_d.h" -static void amdgpu_atombios_lookup_i2c_gpio_quirks (struct amdgpu_device *adev, -ATOM_GPIO_I2C_ASSIGMENT *gpio, -u8 index) -{ - -} -static struct amdgpu_i2c_bus_rec amdgpu_atombios_get_bus_rec_for_i2c_gpio (ATOM_GPIO_I2C_ASSIGMENT *gpio) {struct amdgpu_i2c_bus_rec i2c;
@@ -108,9 +101,6 @@ struct amdgpu_i2c_bus_rec amdgpu_atombios_lookup_i2c_gpio(struct amdgpu_device * gpio = &i2c_info->asGPIO_Info[0 ];for (i =0 ; i < num_indices; i++) { - -amdgpu_atombios_lookup_i2c_gpio_quirks (adev, gpio, i); -if (gpio->sucI2cId.ucAccess == id) { i2c =amdgpu_atombios_get_bus_rec_for_i2c_gpio (gpio);break ;
@@ -142,8 +132,6 @@ void amdgpu_atombios_i2c_init(struct amdgpu_device *adev) gpio = &i2c_info->asGPIO_Info[0 ];for (i =0 ; i < num_indices; i++) { -amdgpu_atombios_lookup_i2c_gpio_quirks (adev, gpio, i); - i2c =amdgpu_atombios_get_bus_rec_for_i2c_gpio (gpio);if (i2c.valid) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 746/869 drm/amdgpu: rework i2c init and fini
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alex Deucher <[email protected]>
[ Upstream commit 1c0b144bf7628a62575a4ec26623f7a6cdf0cb2b ]
No functional change. Rework the code to allow for adding some additional i2c buses in conjunction with DC in the future.
Stable-dep-of: a99cd231cd92 ("drm/amdgpu: Bound GPIO I2C table entry count from VBIOS")
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 6 ++---- drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c | 8 ++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.h | 1 + 3 files changed, 11 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -4
@@ -4518,8 +4518,7 @@ int amdgpu_device_init(struct amdgpu_device *adev, goto failed; }/* init i2c buses */ -if (!amdgpu_device_has_dc_support (adev)) -amdgpu_atombios_i2c_init (adev); +amdgpu_i2c_init (adev); } }
@@ -4793,8 +4792,7 @@ void amdgpu_device_fini_sw(struct amdgpu_device *adev)amdgpu_reset_fini (adev);/* free i2c buses */ -if (!amdgpu_device_has_dc_support (adev)) -amdgpu_i2c_fini (adev); +amdgpu_i2c_fini (adev);if (amdgpu_emu_mode !=1 )amdgpu_atombios_fini (adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.c +8 -0
@@ -225,6 +225,14 @@ void amdgpu_i2c_destroy(struct amdgpu_i2c_chan *i2c)kfree (i2c); } +void amdgpu_i2c_init (struct amdgpu_device *adev) +{ +if (!adev->is_atom_fw) { +if (!amdgpu_device_has_dc_support (adev)) +amdgpu_atombios_i2c_init (adev); + } +} +/* remove all the buses */ void amdgpu_i2c_fini (struct amdgpu_device *adev) {
drivers/gpu/drm/amd/amdgpu/amdgpu_i2c.h +1 -0
@@ -28,6 +28,7 @@ struct amdgpu_i2c_chan *amdgpu_i2c_create(struct drm_device *dev,const struct amdgpu_i2c_bus_rec *rec, const char *name);void amdgpu_i2c_destroy (struct amdgpu_i2c_chan *i2c); +void amdgpu_i2c_init (struct amdgpu_device *adev);void amdgpu_i2c_fini (struct amdgpu_device *adev);struct amdgpu_i2c_chan * amdgpu_i2c_lookup(struct amdgpu_device *adev,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 747/869 drm/amdgpu: Bound GPIO I2C table entry count from VBIOS
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Candice Li <[email protected]>
[ Upstream commit a99cd231cd924b7160fecb9fb3a94b801522323b ]
Reject undersized tables and cap the derived entry count to AMDGPU_MAX_I2C_BUS so we do not overrun adev->i2c_bus[] or walk an absurd number of entries on corrupt size fields.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c | 21 ++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c +17 -4
@@ -36,6 +36,21 @@#include "atombios_encoders.h" #include "bif/bif_4_1_d.h" +/* VBIOS-reported table size is unchecked against the image; cap iterations and +* adev->i2c_bus[] indexing to AMDGPU_MAX_I2C_BUS. +*/ +static int amdgpu_atombios_gpio_i2c_num_entries (uint16_t size) +{ +u32 bytes; + +if (size <sizeof (ATOM_COMMON_TABLE_HEADER )) +return 0 ; + + bytes = size -sizeof (ATOM_COMMON_TABLE_HEADER ); +return (int )min_t (u32, bytes /sizeof (ATOM_GPIO_I2C_ASSIGMENT ), +AMDGPU_MAX_I2C_BUS ); +} +static struct amdgpu_i2c_bus_rec amdgpu_atombios_get_bus_rec_for_i2c_gpio (ATOM_GPIO_I2C_ASSIGMENT *gpio) {struct amdgpu_i2c_bus_rec i2c;
@@ -96,8 +111,7 @@ struct amdgpu_i2c_bus_rec amdgpu_atombios_lookup_i2c_gpio(struct amdgpu_device *if (amdgpu_atom_parse_data_header (ctx, index, &size,NULL ,NULL , &data_offset)) { i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset); - num_indices = (size -sizeof (ATOM_COMMON_TABLE_HEADER )) / -sizeof (ATOM_GPIO_I2C_ASSIGMENT ); + num_indices =amdgpu_atombios_gpio_i2c_num_entries (size); gpio = &i2c_info->asGPIO_Info[0 ];for (i =0 ; i < num_indices; i++) {
@@ -127,8 +141,7 @@ void amdgpu_atombios_i2c_init(struct amdgpu_device *adev)if (amdgpu_atom_parse_data_header (ctx, index, &size,NULL ,NULL , &data_offset)) { i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset); - num_indices = (size -sizeof (ATOM_COMMON_TABLE_HEADER )) / -sizeof (ATOM_GPIO_I2C_ASSIGMENT ); + num_indices =amdgpu_atombios_gpio_i2c_num_entries (size); gpio = &i2c_info->asGPIO_Info[0 ];for (i =0 ; i < num_indices; i++) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 748/869 gpiolib: make value setters have return values
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bartosz Golaszewski <[email protected]>
[ Upstream commit 8ce258f62f90cb2d339cc39fa43e5634594a9dfb ]
Change the in-kernel consumer interface for GPIOs: make all variants of value setters that don't have a return value, return a signed integer instead. That will allow these routines to indicate failures to callers.
This doesn't change the implementation just yet, we'll do it in subsequent commits.
We need to update the gpio-latch module as it passes the address of value setters as a function pointer argument and thus cares about its type.
Stable-dep-of: c87c9046c4e0 ("pinctrl: mediatek: paris: bypass pinctrl GPIO layer in set GPIO direction")
--- drivers/gpio/gpio-latch.c | 2 +- drivers/gpio/gpiolib.c | 53 ++++++++++++++++++++--------------- include/linux/gpio.h | 4 +-- include/linux/gpio/consumer.h | 22 +++++++++------ 4 files changed, 46 insertions(+), 35 deletions(-)
drivers/gpio/gpio-latch.c +1 -1
@@ -72,7 +72,7 @@ static int gpio_latch_get_direction(struct gpio_chip *gc, unsigned int offset) }static void gpio_latch_set_unlocked (struct gpio_latch_priv *priv, -void (*set)(struct gpio_desc *desc,int value), +int (*set)(struct gpio_desc *desc,int value),unsigned int offset,bool val) {int latch = offset / priv->n_latched_gpios;
drivers/gpio/gpiolib.c +30 -23
140 lines not on this page · raw message
include/linux/gpio.h +2 -2
@@ -94,7 +94,7 @@ static inline int gpio_get_value_cansleep(unsigned gpio) }static inline void gpio_set_value_cansleep (unsigned gpio,int value) { -return gpiod_set_raw_value_cansleep (gpio_to_desc (gpio), value); +gpiod_set_raw_value_cansleep (gpio_to_desc (gpio), value); }static inline int gpio_get_value (unsigned gpio)
@@ -103,7 +103,7 @@ static inline int gpio_get_value(unsigned gpio) }static inline void gpio_set_value (unsigned gpio,int value) { -return gpiod_set_raw_value (gpio_to_desc (gpio), value); +gpiod_set_raw_value (gpio_to_desc (gpio), value); }static inline int gpio_to_irq (unsigned gpio)
include/linux/gpio/consumer.h +13 -9
@@ -119,7 +119,7 @@ int gpiod_get_array_value(unsigned int array_size,struct gpio_desc **desc_array, struct gpio_array *array_info, unsigned long *value_bitmap); -void gpiod_set_value (struct gpio_desc *desc,int value); +int gpiod_set_value (struct gpio_desc *desc,int value); int gpiod_set_array_value(unsigned int array_size, struct gpio_desc **desc_array, struct gpio_array *array_info,
@@ -129,7 +129,7 @@ int gpiod_get_raw_array_value(unsigned int array_size,struct gpio_desc **desc_array, struct gpio_array *array_info, unsigned long *value_bitmap); -void gpiod_set_raw_value (struct gpio_desc *desc,int value); +int gpiod_set_raw_value (struct gpio_desc *desc,int value); int gpiod_set_raw_array_value(unsigned int array_size, struct gpio_desc **desc_array, struct gpio_array *array_info,
@@ -141,7 +141,7 @@ int gpiod_get_array_value_cansleep(unsigned int array_size,struct gpio_desc **desc_array, struct gpio_array *array_info, unsigned long *value_bitmap); -void gpiod_set_value_cansleep (struct gpio_desc *desc,int value); +int gpiod_set_value_cansleep (struct gpio_desc *desc,int value); int gpiod_set_array_value_cansleep(unsigned int array_size, struct gpio_desc **desc_array, struct gpio_array *array_info,
@@ -151,7 +151,7 @@ int gpiod_get_raw_array_value_cansleep(unsigned int array_size,struct gpio_desc **desc_array, struct gpio_array *array_info, unsigned long *value_bitmap); -void gpiod_set_raw_value_cansleep (struct gpio_desc *desc,int value); +int gpiod_set_raw_value_cansleep (struct gpio_desc *desc,int value); int gpiod_set_raw_array_value_cansleep(unsigned int array_size, struct gpio_desc **desc_array, struct gpio_array *array_info,
@@ -375,10 +375,11 @@ static inline int gpiod_get_array_value(unsigned int array_size,WARN_ON (desc_array);return 0 ; } -static inline void gpiod_set_value (struct gpio_desc *desc,int value) +static inline int gpiod_set_value (struct gpio_desc *desc,int value) {/* GPIO can never have been requested */ WARN_ON (desc); +return 0 ; } static inline int gpiod_set_array_value(unsigned int array_size, struct gpio_desc **desc_array,
@@ -404,10 +405,11 @@ static inline int gpiod_get_raw_array_value(unsigned int array_size,WARN_ON (desc_array);return 0 ; } -static inline void gpiod_set_raw_value (struct gpio_desc *desc,int value) +static inline int gpiod_set_raw_value (struct gpio_desc *desc,int value) {/* GPIO can never have been requested */ WARN_ON (desc); +return 0 ; } static inline int gpiod_set_raw_array_value(unsigned int array_size, struct gpio_desc **desc_array,
@@ -434,10 +436,11 @@ static inline int gpiod_get_array_value_cansleep(unsigned int array_size,WARN_ON (desc_array);return 0 ; } -static inline void gpiod_set_value_cansleep (struct gpio_desc *desc,int value) +static inline int gpiod_set_value_cansleep (struct gpio_desc *desc,int value) {/* GPIO can never have been requested */ WARN_ON (desc); +return 0 ; } static inline int gpiod_set_array_value_cansleep(unsigned int array_size, struct gpio_desc **desc_array,
@@ -463,11 +466,12 @@ static inline int gpiod_get_raw_array_value_cansleep(unsigned int array_size,WARN_ON (desc_array);return 0 ; } -static inline void gpiod_set_raw_value_cansleep (struct gpio_desc *desc, -int value) +static inline int gpiod_set_raw_value_cansleep (struct gpio_desc *desc, +int value) {/* GPIO can never have been requested */ WARN_ON (desc); +return 0 ; } static inline int gpiod_set_raw_array_value_cansleep(unsigned int array_size, struct gpio_desc **desc_array,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 749/869 gpiolib: wrap gpio_chip::set()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bartosz Golaszewski <[email protected]>
[ Upstream commit d36058b89a4aa30865d4cfeb101bbfd1d1dcb22f ]
We have three places where we dereference the gpio_chip::set() callback. In order to make it easier to incorporate the upcoming new variant of this callback (one returning an integer value), wrap it in a helper so that the dereferencing only happens once.
Stable-dep-of: c87c9046c4e0 ("pinctrl: mediatek: paris: bypass pinctrl GPIO layer in set GPIO direction")
--- drivers/gpio/gpiolib.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
drivers/gpio/gpiolib.c +16 -5
@@ -2722,6 +2722,17 @@ int gpiod_direction_input(struct gpio_desc *desc) }EXPORT_SYMBOL_GPL (gpiod_direction_input); +static int gpiochip_set (struct gpio_chip *gc,unsigned int offset,int value) +{ +lockdep_assert_held (&gc->gpiodev->srcu); + +if (WARN_ON (unlikely (!gc->set))) +return -EOPNOTSUPP ; + + gc->set (gc, offset, value); +return 0 ; +} +static int gpiod_direction_output_raw_commit (struct gpio_desc *desc,int value) {int val = !!value, ret =0 ;
@@ -2758,7 +2769,9 @@ static int gpiod_direction_output_raw_commit(struct gpio_desc *desc, int value)* If we can't actively set the direction, we are some * output-only chip, so just drive the output as desired. */ - guard.gc->set (guard.gc,gpio_chip_hwgpio (desc), val); + ret =gpiochip_set (guard.gc,gpio_chip_hwgpio (desc), val); +if (ret) +return ret; }if (!ret)
@@ -3390,9 +3403,7 @@ static int gpiod_set_raw_value_commit(struct gpio_desc *desc, bool value)return -ENODEV ;trace_gpio_value (desc_to_gpio (desc),0 , value); - guard.gc->set (guard.gc,gpio_chip_hwgpio (desc), value); - -return 0 ; +return gpiochip_set (guard.gc,gpio_chip_hwgpio (desc), value); }/*
@@ -3417,7 +3428,7 @@ static void gpio_chip_set_multiple(struct gpio_chip *gc,/* set outputs if the corresponding mask bit is set */ for_each_set_bit (i, mask, gc->ngpio) - gc->set (gc, i,test_bit (i, bits)); +gpiochip_set (gc, i,test_bit (i, bits)); } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 750/869 gpiolib: rework the wrapper around gpio_chip::set_multiple()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bartosz Golaszewski <[email protected]>
[ Upstream commit 9b407312755fd5db012413ca005f0f3a661db8dd ]
Make the existing wrapper around gpio_chip::set_multiple() consistent with the one for gpio_chip::set(): make it return int, add a lockdep assertion, warn on missing set callback and move the code a bit for better readability.
Add return value checks in all call places.
Stable-dep-of: c87c9046c4e0 ("pinctrl: mediatek: paris: bypass pinctrl GPIO layer in set GPIO direction")
--- drivers/gpio/gpiolib.c | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-)
drivers/gpio/gpiolib.c +29 -11
@@ -3415,21 +3415,33 @@ static int gpiod_set_raw_value_commit(struct gpio_desc *desc, bool value)* defines which outputs are to be changed * @bits: bit value array; one bit per output; BITS_PER_LONG bits per word * defines the values the outputs specified by mask are to be set to +* +* Returns: 0 on success, negative error number on failure. */ -static void gpio_chip_set_multiple (struct gpio_chip *gc, -unsigned long *mask,unsigned long *bits) +static int gpiochip_set_multiple (struct gpio_chip *gc, +unsigned long *mask,unsigned long *bits) { +unsigned int i; +int ret; +lockdep_assert_held (&gc->gpiodev->srcu); +if (WARN_ON (unlikely (!gc->set_multiple && !gc->set))) +return -EOPNOTSUPP ; +if (gc->set_multiple) { gc->set_multiple (gc, mask, bits); - }else { -unsigned int i; +return 0 ; + } -/* set outputs if the corresponding mask bit is set */ -for_each_set_bit (i, mask, gc->ngpio) -gpiochip_set (gc, i,test_bit (i, bits)); +/* set outputs if the corresponding mask bit is set */ +for_each_set_bit (i, mask, gc->ngpio) { + ret =gpiochip_set (gc, i,test_bit (i, bits)); +if (ret) +break ; } + +return ret; } int gpiod_set_array_value_complex(bool raw, bool can_sleep,
@@ -3439,7 +3451,7 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep, unsigned long *value_bitmap) {struct gpio_chip *gc; -int i =0 ; +int i =0 , ret;/* * Validate array_info against desc_array and its size.
@@ -3462,7 +3474,10 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep,bitmap_xor (value_bitmap, value_bitmap, array_info->invert_mask, array_size); -gpio_chip_set_multiple (gc, array_info->set_mask, value_bitmap); + ret =gpiochip_set_multiple (gc, array_info->set_mask, + value_bitmap); +if (ret) +return ret; i =find_first_zero_bit (array_info->set_mask, array_size);if (i == array_size)
@@ -3539,8 +3554,11 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep, }while ((i < array_size) &&gpio_device_chip_cmp (desc_array[i]->gdev, guard.gc));/* push collected bits to outputs */ -if (count !=0 ) -gpio_chip_set_multiple (guard.gc, mask, bits); +if (count !=0 ) { + ret =gpiochip_set_multiple (guard.gc, mask, bits); +if (ret) +return ret; + }if (mask != fastpath_mask)bitmap_free (mask);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 751/869 gpiolib: introduce gpio_chip setters that return values
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bartosz Golaszewski <[email protected]>
[ Upstream commit 98ce1eb1fd87ea1b016e0913ef6836ab0139b5c4 ]
Add new variants of the set() and set_multiple() callbacks that have integer return values allowing to indicate failures to users of the GPIO consumer API. Until we convert all GPIO providers treewide to using them, they will live in parallel to the existing ones.
Make sure that providers cannot define both. Prefer the new ones and only use the old ones as fallback.
Stable-dep-of: c87c9046c4e0 ("pinctrl: mediatek: paris: bypass pinctrl GPIO layer in set GPIO direction")
--- drivers/gpio/gpiolib.c | 28 ++++++++++++++++++++++++++-- drivers/leds/leds-aw200xx.c | 2 +- include/linux/gpio/driver.h | 10 ++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-)
drivers/gpio/gpiolib.c +26 -2
@@ -945,6 +945,11 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,int base =0 ;int ret; +/* Only allow one set() and one set_multiple(). */ +if ((gc->set && gc->set_rv) || + (gc->set_multiple && gc->set_multiple_rv)) +return -EINVAL ; + gdev =kzalloc (sizeof (*gdev),GFP_KERNEL );if (!gdev)return -ENOMEM ;
@@ -2724,11 +2729,21 @@ EXPORT_SYMBOL_GPL(gpiod_direction_input);static int gpiochip_set (struct gpio_chip *gc,unsigned int offset,int value) { +int ret; +lockdep_assert_held (&gc->gpiodev->srcu); -if (WARN_ON (unlikely (!gc->set))) +if (WARN_ON (unlikely (!gc->set && !gc->set_rv)))return -EOPNOTSUPP ; +if (gc->set_rv) { + ret = gc->set_rv (gc, offset, value); +if (ret >0 ) + ret = -EBADE ; + +return ret; + } + gc->set (gc, offset, value);return 0 ; }
@@ -3426,9 +3441,18 @@ static int gpiochip_set_multiple(struct gpio_chip *gc,lockdep_assert_held (&gc->gpiodev->srcu); -if (WARN_ON (unlikely (!gc->set_multiple && !gc->set))) +if (WARN_ON (unlikely (!gc->set_multiple && !gc->set_multiple_rv && + !gc->set && !gc->set_rv)))return -EOPNOTSUPP ; +if (gc->set_multiple_rv) { + ret = gc->set_multiple_rv (gc, mask, bits); +if (ret >0 ) + ret = -EBADE ; + +return ret; + } +if (gc->set_multiple) { gc->set_multiple (gc, mask, bits);return 0 ;
drivers/leds/leds-aw200xx.c +1 -1
@@ -379,7 +379,7 @@ static void aw200xx_enable(const struct aw200xx *const chip)static void aw200xx_disable (const struct aw200xx *const chip) { -return gpiod_set_value_cansleep (chip->hwen,0 ); +gpiod_set_value_cansleep (chip->hwen,0 ); } static int aw200xx_probe_get_display_rows(struct device *dev,
include/linux/gpio/driver.h +10 -0
@@ -346,6 +346,10 @@ struct gpio_irq_chip {* stores them in "bits", returns 0 on success or negative error * @set: assigns output value for signal "offset" * @set_multiple: assigns output values for multiple signals defined by "mask" +* @set_rv: assigns output value for signal "offset", returns 0 on success or +* negative error value +* @set_multiple_rv: assigns output values for multiple signals defined by +* "mask", returns 0 on success or negative error value * @set_config: optional hook for all kinds of settings. Uses the same * packed config format as generic pinconf. * @to_irq: optional hook supporting non-static gpiod_to_irq() mappings;
@@ -441,6 +445,12 @@ struct gpio_chip {void (*set_multiple)(struct gpio_chip *gc,unsigned long *mask,unsigned long *bits); +int (*set_rv)(struct gpio_chip *gc, +unsigned int offset, +int value); +int (*set_multiple_rv)(struct gpio_chip *gc, +unsigned long *mask, +unsigned long *bits);int (*set_config)(struct gpio_chip *gc,unsigned int offset,unsigned long config);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 752/869 pinctrl: mediatek: paris: dont double-check the GPIO number
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bartosz Golaszewski <[email protected]>
[ Upstream commit 9c791cbaf3cf2671404dc4f7679548071b38e104 ]
GPIO core already makes sure we don't pass invalid GPIO numbers down to the driver callbacks. Remove needless checks from the driver.
Stable-dep-of: c87c9046c4e0 ("pinctrl: mediatek: paris: bypass pinctrl GPIO layer in set GPIO direction")
--- drivers/pinctrl/mediatek/pinctrl-paris.c | 19 ------------------- 1 file changed, 19 deletions(-)
drivers/pinctrl/mediatek/pinctrl-paris.c +0 -19
@@ -840,9 +840,6 @@ static int mtk_gpio_get_direction(struct gpio_chip *chip, unsigned int gpio)const struct mtk_pin_desc *desc;int value, err; -if (gpio >= hw->soc->npins) -return -EINVAL ; -/* * "Virtual" GPIOs are always and only used for interrupts * Since they are only used for interrupts, they are always inputs
@@ -868,9 +865,6 @@ static int mtk_gpio_get(struct gpio_chip *chip, unsigned int gpio)const struct mtk_pin_desc *desc;int value, err; -if (gpio >= hw->soc->npins) -return -EINVAL ; - desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio]; err =mtk_hw_get_value (hw, desc,PINCTRL_PIN_REG_DI , &value);
@@ -885,9 +879,6 @@ static void mtk_gpio_set(struct gpio_chip *chip, unsigned int gpio, int value)struct mtk_pinctrl *hw =gpiochip_get_data (chip);const struct mtk_pin_desc *desc; -if (gpio >= hw->soc->npins) -return ; - desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio];mtk_hw_set_value (hw, desc,PINCTRL_PIN_REG_DO , !!value);
@@ -895,22 +886,12 @@ static void mtk_gpio_set(struct gpio_chip *chip, unsigned int gpio, int value)static int mtk_gpio_direction_input (struct gpio_chip *chip,unsigned int gpio) { -struct mtk_pinctrl *hw =gpiochip_get_data (chip); - -if (gpio >= hw->soc->npins) -return -EINVAL ; -return pinctrl_gpio_direction_input (chip, gpio); }static int mtk_gpio_direction_output (struct gpio_chip *chip,unsigned int gpio,int value) { -struct mtk_pinctrl *hw =gpiochip_get_data (chip); - -if (gpio >= hw->soc->npins) -return -EINVAL ; -mtk_gpio_set (chip, gpio, value);return pinctrl_gpio_direction_output (chip, gpio);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 753/869 pinctrl: mediatek: paris: use new GPIO line value setter callbacks
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bartosz Golaszewski <[email protected]>
[ Upstream commit 1849d1a3d388caf898b18791c40edac464c809d1 ]
struct gpio_chip now has callbacks for setting line values that return an integer, allowing to indicate failures. Convert the driver to using them.
Stable-dep-of: c87c9046c4e0 ("pinctrl: mediatek: paris: bypass pinctrl GPIO layer in set GPIO direction")
--- drivers/pinctrl/mediatek/pinctrl-paris.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/pinctrl/mediatek/pinctrl-paris.c +8 -4
@@ -874,14 +874,14 @@ static int mtk_gpio_get(struct gpio_chip *chip, unsigned int gpio)return !!value; } -static void mtk_gpio_set (struct gpio_chip *chip,unsigned int gpio,int value) +static int mtk_gpio_set (struct gpio_chip *chip,unsigned int gpio,int value) {struct mtk_pinctrl *hw =gpiochip_get_data (chip);const struct mtk_pin_desc *desc; desc = (const struct mtk_pin_desc *)&hw->soc->pins[gpio]; -mtk_hw_set_value (hw, desc,PINCTRL_PIN_REG_DO , !!value); +return mtk_hw_set_value (hw, desc,PINCTRL_PIN_REG_DO , !!value); }static int mtk_gpio_direction_input (struct gpio_chip *chip,unsigned int gpio)
@@ -892,7 +892,11 @@ static int mtk_gpio_direction_input(struct gpio_chip *chip, unsigned int gpio)static int mtk_gpio_direction_output (struct gpio_chip *chip,unsigned int gpio,int value) { -mtk_gpio_set (chip, gpio, value); +int ret; + + ret =mtk_gpio_set (chip, gpio, value); +if (ret) +return ret;return pinctrl_gpio_direction_output (chip, gpio); }
@@ -945,7 +949,7 @@ static int mtk_build_gpiochip(struct mtk_pinctrl *hw) chip->direction_input = mtk_gpio_direction_input; chip->direction_output = mtk_gpio_direction_output; chip->get = mtk_gpio_get; - chip->set = mtk_gpio_set; + chip->set_rv = mtk_gpio_set; chip->to_irq = mtk_gpio_to_irq; chip->set_config = mtk_gpio_set_config; chip->base =-1 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 754/869 pinctrl: mediatek: paris: bypass pinctrl GPIO layer in set GPIO direction
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 c87c9046c4e00d599454e033a477176c4d73ac2a ]
pinctrl_gpio_direction_input() / pinctrl_gpio_direction_output() take the pinctrl mutex. This causes a gpiochip operations to need to sleep. Worse yet, the .can_sleep field in the gpiochip is not set. This causes the shared GPIO proxy to trip over, as it uses gpiod_cansleep() to check whether it can use a spinlock or needs a mutex. In this case, it ends up taking a spinlock, then calls pinctrl_gpio_direction_output(), which takes a mutex. This causes a huge warning.
While this class of Mediatek hardware does not have separate clear/set registers, the pinctrl context has a spinlock that is taken whenever a register read-modify-write is done. Also, once the GPIO function is selected / muxed in, further GPIO operations do not involve pinctrl operations or state. The GPIO direction and level values do not require toggling the pinmux or any other pin config options.
Switch to directly calling mtk_pinmux_gpio_set_direction() in the GPIO set direction callbacks to avoid taking the pinctrl mutex. Drop the .gpio_set_direction field in mtk_pmxops to signal we are no longer using the pinctrl GPIO layer for setting the direction.
--- drivers/pinctrl/mediatek/pinctrl-paris.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/pinctrl/mediatek/pinctrl-paris.c +5 -3
@@ -771,7 +771,6 @@ static const struct pinmux_ops mtk_pmxops = { .get_function_name = mtk_pmx_get_func_name, .get_function_groups = mtk_pmx_get_func_groups, .set_mux = mtk_pmx_set_mux, - .gpio_set_direction = mtk_pinmux_gpio_set_direction, .gpio_request_enable = mtk_pinmux_gpio_request_enable, };
@@ -886,19 +885,22 @@ static int mtk_gpio_set(struct gpio_chip *chip, unsigned int gpio, int value)static int mtk_gpio_direction_input (struct gpio_chip *chip,unsigned int gpio) { -return pinctrl_gpio_direction_input (chip, gpio); +struct mtk_pinctrl *hw =gpiochip_get_data (chip); + +return mtk_pinmux_gpio_set_direction (hw->pctrl,NULL , gpio, true); }static int mtk_gpio_direction_output (struct gpio_chip *chip,unsigned int gpio,int value) { +struct mtk_pinctrl *hw =gpiochip_get_data (chip);int ret; ret =mtk_gpio_set (chip, gpio, value);if (ret)return ret; -return pinctrl_gpio_direction_output (chip, gpio); +return mtk_pinmux_gpio_set_direction (hw->pctrl,NULL , gpio, false); }static int mtk_gpio_to_irq (struct gpio_chip *chip,unsigned int offset)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 755/869 genirq/proc: Switch to lock guards
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Gleixner <[email protected]>
[ Upstream commit 659ff9c9d77b8ad9d9c18e264abc9a56bd19230e ]
Convert all lock/unlock pairs to guards and tidy up the code.
No functional change.
Stable-dep-of: c2c7983c93f5 ("genirq/proc: Size interrupt directory names for 10-digit interrupt numbers")
--- kernel/irq/proc.c | 65 +++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 41 deletions(-)
kernel/irq/proc.c +24 -41
@@ -81,20 +81,18 @@ static int show_irq_affinity(int type, struct seq_file *m)static int irq_affinity_hint_proc_show (struct seq_file *m,void *v) {struct irq_desc *desc =irq_to_desc ((long )m->private); -unsigned long flags;cpumask_var_t mask;if (!zalloc_cpumask_var (&mask,GFP_KERNEL ))return -ENOMEM ; -raw_spin_lock_irqsave (&desc->lock, flags); -if (desc->affinity_hint) -cpumask_copy (mask, desc->affinity_hint); -raw_spin_unlock_irqrestore (&desc->lock, flags); + scoped_guard(raw_spinlock_irq, &desc->lock) { +if (desc->affinity_hint) +cpumask_copy (mask, desc->affinity_hint); + }seq_printf (m,"%*pb\n" ,cpumask_pr_args (mask));free_cpumask_var (mask); -return 0 ; }
@@ -295,23 +293,18 @@ static int irq_spurious_proc_show(struct seq_file *m, void *v)#define MAX_NAMELEN 128 -static int name_unique (unsigned int irq,struct irqaction *new_action) +static bool name_unique (unsigned int irq,struct irqaction *new_action) {struct irq_desc *desc =irq_to_desc (irq);struct irqaction *action; -unsigned long flags; -int ret =1 ; -raw_spin_lock_irqsave (&desc->lock, flags); +guard (raw_spinlock_irq)(&desc->lock);for_each_action_of_desc (desc, action) {if ((action != new_action) && action->name && - !strcmp (new_action->name, action->name)) { - ret =0 ; -break ; - } + !strcmp (new_action->name, action->name)) +return false; } -raw_spin_unlock_irqrestore (&desc->lock, flags); -return ret; +return true; }void register_handler_proc (unsigned int irq,struct irqaction *action)
@@ -319,8 +312,7 @@ void register_handler_proc(unsigned int irq, struct irqaction *action)char name [MAX_NAMELEN ];struct irq_desc *desc =irq_to_desc (irq); -if (!desc->dir || action->dir || !action->name || - !name_unique (irq, action)) +if (!desc->dir || action->dir || !action->name || !name_unique (irq, action))return ;snprintf (name,MAX_NAMELEN ,"%s" , action->name);
@@ -347,17 +339,16 @@ void register_irq_proc(unsigned int irq, struct irq_desc *desc)* added, not when the descriptor is created, so multiple * tasks might try to register at the same time. */ -mutex_lock (®ister_lock); +guard (mutex)(®ister_lock);if (desc->dir) - goto out_unlock; - -sprintf (name,"%d" , irq); +return ;/* create /proc/irq/1234 */ +sprintf (name,"%d" , irq); desc->dir =proc_mkdir (name, root_irq_dir);if (!desc->dir) - goto out_unlock; +return ;#ifdef CONFIG_SMP umode_t umode =S_IRUGO ;
@@ -366,31 +357,27 @@ void register_irq_proc(unsigned int irq, struct irq_desc *desc) umode |=S_IWUSR ;/* create /proc/irq/<irq>/smp_affinity */ -proc_create_data ("smp_affinity" , umode, desc->dir, - &irq_affinity_proc_ops, irqp); +proc_create_data ("smp_affinity" , umode, desc->dir, &irq_affinity_proc_ops, irqp);/* create /proc/irq/<irq>/affinity_hint */ proc_create_single_data ("affinity_hint" ,0444 , desc->dir, - irq_affinity_hint_proc_show, irqp); + irq_affinity_hint_proc_show, irqp);/* create /proc/irq/<irq>/smp_affinity_list */ proc_create_data ("smp_affinity_list" , umode, desc->dir, &irq_affinity_list_proc_ops, irqp); -proc_create_single_data ("node" ,0444 , desc->dir, irq_node_proc_show, - irqp); +proc_create_single_data ("node" ,0444 , desc->dir, irq_node_proc_show, irqp);# ifdef CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK proc_create_single_data ("effective_affinity" ,0444 , desc->dir, - irq_effective_aff_proc_show, irqp); + irq_effective_aff_proc_show, irqp);proc_create_single_data ("effective_affinity_list" ,0444 , desc->dir, - irq_effective_aff_list_proc_show, irqp); + irq_effective_aff_list_proc_show, irqp);# endif #endif proc_create_single_data ("spurious" ,0444 , desc->dir, - irq_spurious_proc_show, (void *)(long )irq); + irq_spurious_proc_show, (void *)(long )irq); -out_unlock: -mutex_unlock (®ister_lock); }void unregister_irq_proc (unsigned int irq,struct irq_desc *desc)
@@ -467,7 +454,6 @@ int show_interrupts(struct seq_file *p, void *v)int i = *(loff_t *) v, j;struct irqaction *action;struct irq_desc *desc; -unsigned long flags;if (i >ACTUAL_NR_IRQS )return 0 ;
@@ -486,19 +472,19 @@ int show_interrupts(struct seq_file *p, void *v)seq_putc (p,'\n' ); } -rcu_read_lock (); +guard (rcu)(); desc =irq_to_desc (i);if (!desc ||irq_settings_is_hidden (desc)) - goto outsparse; +return 0 ;if (!desc->action ||irq_desc_is_chained (desc) || !desc->kstat_irqs) - goto outsparse; +return 0 ;seq_printf (p,"%*d: " , prec, i);for_each_online_cpu (j)seq_printf (p,"%10u " , desc->kstat_irqs ?per_cpu (desc->kstat_irqs->cnt, j) :0 ); -raw_spin_lock_irqsave (&desc->lock, flags); +guard (raw_spinlock_irq)(&desc->lock);if (desc->irq_data.chip) {if (desc->irq_data.chip->irq_print_chip) desc->irq_data.chip->irq_print_chip (&desc->irq_data, p);
@@ -527,9 +513,6 @@ int show_interrupts(struct seq_file *p, void *v) }seq_putc (p,'\n' ); -raw_spin_unlock_irqrestore (&desc->lock, flags); -outsparse: -rcu_read_unlock ();return 0 ; }#endif
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 756/869 genirq: Consistently use %u format specifier for unsigned int variables
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andy Shevchenko <[email protected]>
[ Upstream commit 47af06c9d31fe558493de4e04f9a07847dc4992f ]
There are three cases in the genirq code when the irq, as an unsigned integer variable, is converted to text representation by sprintf(). In two cases it uses '%d' specifier which is for signed values. While it's not a problem right now, potentially it might be in the future in case too big (> INT_MAX) number will appear there.
Consistently use '%u' format specifier for @irq which is declared as unsigned int in all these cases.
Stable-dep-of: c2c7983c93f5 ("genirq/proc: Size interrupt directory names for 10-digit interrupt numbers")
--- kernel/irq/debugfs.c | 2 +- kernel/irq/proc.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
kernel/irq/debugfs.c +1 -1
@@ -231,7 +231,7 @@ void irq_add_debugfs_entry(unsigned int irq, struct irq_desc *desc)if (!irq_dir || !desc || desc->debugfs_file)return ; -sprintf (name,"%d" , irq); +sprintf (name,"%u" , irq); desc->debugfs_file =debugfs_create_file (name,0644 , irq_dir, desc, &dfs_irq_ops); }
kernel/irq/proc.c +2 -2
@@ -309,7 +309,7 @@ static bool name_unique(unsigned int irq, struct irqaction *new_action)void register_handler_proc (unsigned int irq,struct irqaction *action) { -char name [MAX_NAMELEN ]; +char name[MAX_NAMELEN ];struct irq_desc *desc =irq_to_desc (irq);if (!desc->dir || action->dir || !action->name || !name_unique (irq, action))
@@ -345,7 +345,7 @@ void register_irq_proc(unsigned int irq, struct irq_desc *desc)return ;/* create /proc/irq/1234 */ -sprintf (name,"%d" , irq); +sprintf (name,"%u" , irq); desc->dir =proc_mkdir (name, root_irq_dir);if (!desc->dir)return ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 757/869 genirq/proc: Size interrupt directory names for 10-digit interrupt numbers
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 c2c7983c93f5d86962318be7e7298f1bc3feb1a6 ]
/proc/irq/<n>/ directory names are built in char name[10] buffers with sprintf(name, "%u", irq).
Ten-digit IRQ numbers already need 11 bytes including the trailing NUL, and current sparse-IRQ configurations allow interrupt numbers in that range.
Size the temporary name buffer for the current decimal form and switch to bounded formatting when creating or removing the proc entry.
--- kernel/irq/proc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
kernel/irq/proc.c +4 -3
@@ -10,6 +10,7 @@#include <linux/proc_fs.h> #include <linux/seq_file.h> #include <linux/interrupt.h> +#include <linux/kernel.h> #include <linux/kernel_stat.h> #include <linux/mutex.h>
@@ -323,7 +324,7 @@ void register_handler_proc(unsigned int irq, struct irqaction *action)#undef MAX_NAMELEN -#define MAX_NAMELEN 10 +#define MAX_NAMELEN 11void register_irq_proc (unsigned int irq,struct irq_desc *desc) {
@@ -345,7 +346,7 @@ void register_irq_proc(unsigned int irq, struct irq_desc *desc)return ;/* create /proc/irq/1234 */ -sprintf (name,"%u" , irq); +snprintf (name,MAX_NAMELEN ,"%u" , irq); desc->dir =proc_mkdir (name, root_irq_dir);if (!desc->dir)return ;
@@ -398,7 +399,7 @@ void unregister_irq_proc(unsigned int irq, struct irq_desc *desc)#endif remove_proc_entry ("spurious" , desc->dir); -sprintf (name,"%u" , irq); +snprintf (name,MAX_NAMELEN ,"%u" , irq);remove_proc_entry (name, root_irq_dir); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 758/869 media: chips-media: wave5: Release m2m_ctx after Instance Removed from List
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Brandon Brnich <[email protected]>
[ Upstream commit 7cdbd7bb21949a8fda10c7104a2b12ee363cbf5c ]
Possible use after free if IRQ thread manages to obtain spinlock between m2m_ctx release and wave5_release function removing stream instance from list of active instances. The IRQ thread looks for the m2m_ctx which is freed so null pointer dereference occurs.
--- drivers/media/platform/chips-media/wave5/wave5-helper.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/media/platform/chips-media/wave5/wave5-helper.c +3 -1
@@ -67,7 +67,6 @@ int wave5_vpu_release_device(struct file *filp,int ret =0 ;unsigned long flags; -v4l2_m2m_ctx_release (inst->v4l2_fh.m2m_ctx);/* * To prevent Null reference exception, the existing irq handler were * separated to two modules.
@@ -88,6 +87,9 @@ int wave5_vpu_release_device(struct file *filp,list_del_init (&inst->list);spin_unlock_irqrestore (&inst->dev->irq_spinlock, flags);mutex_unlock (&inst->dev->irq_lock); + +v4l2_m2m_ctx_release (inst->v4l2_fh.m2m_ctx); +if (inst->state !=VPU_INST_STATE_NONE ) {u32 fail_res;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 759/869 i3c: master: svc: Fix npcm845 FIFO empty issue
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stanley Chu <[email protected]>
[ Upstream commit 4008a74e0f9b0ec25441028e324452933644ed2a ]
I3C HW stalls the write transfer if the transmit FIFO becomes empty, when new data is written to FIFO, I3C HW resumes the transfer but the first transmitted data bit may have the wrong value.
Fill the FIFO in advance to prevent FIFO from becoming empty.
Stable-dep-of: 1effa3adfe53 ("i3c: master: svc: Prevent IRQ storm from false SLVSTART on NPCM845")
--- drivers/i3c/master/svc-i3c-master.c | 71 +++++++++++++++++++++++++---- 1 file changed, 61 insertions(+), 10 deletions(-)
drivers/i3c/master/svc-i3c-master.c +61 -10
@@ -113,6 +113,7 @@#define SVC_I3C_MWDATAHE 0x0BC#define SVC_I3C_MRDATAB 0x0C0#define SVC_I3C_MRDATAH 0x0C8 +#define SVC_I3C_MWDATAB1 0x0CC#define SVC_I3C_MWMSG_SDR 0x0D0#define SVC_I3C_MRMSG_SDR 0x0D4#define SVC_I3C_MWMSG_DDR 0x0D8
@@ -133,6 +134,16 @@#define SVC_I3C_EVENT_IBI GENMASK(7, 0)#define SVC_I3C_EVENT_HOTJOIN BIT(31) +/* +* SVC_I3C_QUIRK_FIFO_EMPTY: +* I3C HW stalls the write transfer if the transmit FIFO becomes empty, +* when new data is written to FIFO, I3C HW resumes the transfer but +* the first transmitted data bit may have the wrong value. +* Workaround: +* Fill the FIFO in advance to prevent FIFO from becoming empty. +*/ +#define SVC_I3C_QUIRK_FIFO_EMPTY BIT(0) +struct svc_i3c_cmd {u8 addr;bool rnw;
@@ -236,6 +247,11 @@ struct svc_i3c_i2c_dev_data {struct i3c_generic_ibi_pool *ibi_pool; }; +static inline bool svc_has_quirk (struct svc_i3c_master *master,u32 quirk) +{ +return (master->drvdata->quirks & quirk); +} +static inline bool is_events_enabled (struct svc_i3c_master *master,u32 mask) {return !!(master->enabled_events & mask);
@@ -892,7 +908,7 @@ static int svc_i3c_master_do_daa_locked(struct svc_i3c_master *master, u8 *addrs, unsigned int *count) { u64 prov_id[SVC_I3C_MAX_DEVS] = {}, nacking_prov_id = 0; -unsigned int dev_nb =0 , last_addr =0 ; +unsigned int dev_nb =0 , last_addr =0 , dyn_addr;u32 reg;int ret, i;
@@ -934,6 +950,25 @@ static int svc_i3c_master_do_daa_locked(struct svc_i3c_master *master,if (SVC_I3C_MSTATUS_RXPEND (reg)) {u8 data[6 ]; +/* +* One slave sends its ID to request for address assignment, +* prefilling the dynamic address can reduce SCL clock stalls +* and also fix the SVC_I3C_QUIRK_FIFO_EMPTY quirk. +* +* Ideally, prefilling before the processDAA command is better. +* However, it requires an additional check to write the dyn_addr +* at the right time because the driver needs to write the processDAA +* command twice for one assignment. +* Prefilling here is safe and efficient because the FIFO starts +* filling within a few hundred nanoseconds, which is significantly +* faster compared to the 64 SCL clock cycles. +*/ + dyn_addr =i3c_master_get_free_addr (&master->base, last_addr +1 ); +if (dyn_addr <0 ) +return -ENOSPC ; + +writel (dyn_addr, master->regs +SVC_I3C_MWDATAB ); +/* * We only care about the 48-bit provisioned ID yet to * be sure a device does not nack an address twice.
@@ -1007,21 +1042,16 @@ static int svc_i3c_master_do_daa_locked(struct svc_i3c_master *master,if (ret)break ; -/* Give the slave device a suitable dynamic address */ - ret =i3c_master_get_free_addr (&master->base, last_addr +1 ); -if (ret <0 ) -break ; - - addrs[dev_nb] = ret; + addrs[dev_nb] = dyn_addr;dev_dbg (master->dev,"DAA: device %d assigned to 0x%02x\n" , dev_nb, addrs[dev_nb]); - -writel (addrs[dev_nb], master->regs +SVC_I3C_MWDATAB ); last_addr = addrs[dev_nb++]; }/* Need manual issue STOP except for Complete condition */ svc_i3c_master_emit_stop (master); +svc_i3c_master_flush_fifo (master); +return ret; }
@@ -1218,6 +1248,24 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master,SVC_I3C_MCTRL_RDTERM (*actual_len), master->regs + SVC_I3C_MCTRL); +/* +* The entire transaction can consist of multiple write transfers. +* Prefilling before EmitStartAddr causes the data to be emitted +* immediately, becoming part of the previous transfer. +* The only way to work around this hardware issue is to let the +* FIFO start filling as soon as possible after EmitStartAddr. +*/ +if (svc_has_quirk (master,SVC_I3C_QUIRK_FIFO_EMPTY ) && !rnw && xfer_len) { +u32 end = xfer_len >SVC_I3C_FIFO_SIZE ?0 :SVC_I3C_MWDATAB_END ; +u32 len =min_t (u32, xfer_len,SVC_I3C_FIFO_SIZE ); + +writesb (master->regs +SVC_I3C_MWDATAB1 , out, len -1 ); +/* Mark END bit if this is the last byte */ +writel (out[len -1 ] | end, master->regs +SVC_I3C_MWDATAB ); + xfer_len -= len; + out += len; + } + ret =readl_poll_timeout (master->regs +SVC_I3C_MSTATUS , reg,SVC_I3C_MSTATUS_MCTRLDONE (reg),0 ,1000 );if (ret)
@@ -1304,6 +1352,7 @@ static int svc_i3c_master_xfer(struct svc_i3c_master *master, emit_stop:svc_i3c_master_emit_stop (master);svc_i3c_master_clear_merrwarn (master); +svc_i3c_master_flush_fifo (master);return ret; }
@@ -1958,7 +2007,9 @@ static const struct dev_pm_ops svc_i3c_pm_ops = { svc_i3c_runtime_resume, NULL) }; -static const struct svc_i3c_drvdata npcm845_drvdata = {}; +static const struct svc_i3c_drvdata npcm845_drvdata = { + .quirks =SVC_I3C_QUIRK_FIFO_EMPTY , +};static const struct svc_i3c_drvdata svc_default_drvdata = {};
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 760/869 i3c: master: svc: Fix npcm845 invalid slvstart event
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stanley Chu <[email protected]>
[ Upstream commit 4dd12e944f07013ac280d7f46463c19157898bd1 ]
I3C HW may generate an invalid SlvStart event when emitting a STOP. If it is a true SlvStart, the MSTATUS state is SLVREQ. Check the MSTATUS state to ignore the false event.
Stable-dep-of: 1effa3adfe53 ("i3c: master: svc: Prevent IRQ storm from false SLVSTART on NPCM845")
--- drivers/i3c/master/svc-i3c-master.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/i3c/master/svc-i3c-master.c +14 -1
@@ -58,6 +58,7 @@#define SVC_I3C_MSTATUS 0x088#define SVC_I3C_MSTATUS_STATE (x) FIELD_GET(GENMASK(2, 0), (x))#define SVC_I3C_MSTATUS_STATE_DAA (x) (SVC_I3C_MSTATUS_STATE(x) == 5) +#define SVC_I3C_MSTATUS_STATE_SLVREQ (x) (SVC_I3C_MSTATUS_STATE(x) == 1)#define SVC_I3C_MSTATUS_STATE_IDLE (x) (SVC_I3C_MSTATUS_STATE(x) == 0)#define SVC_I3C_MSTATUS_BETWEEN (x) FIELD_GET(BIT(4), (x))#define SVC_I3C_MSTATUS_NACKED (x) FIELD_GET(BIT(5), (x))
@@ -143,6 +144,12 @@* Fill the FIFO in advance to prevent FIFO from becoming empty. */ #define SVC_I3C_QUIRK_FIFO_EMPTY BIT(0) +/* +* SVC_I3C_QUIRK_FLASE_SLVSTART: +* I3C HW may generate an invalid SlvStart event when emitting a STOP. +* If it is a true SlvStart, the MSTATUS state is SLVREQ. +*/ +#define SVC_I3C_QUIRK_FALSE_SLVSTART BIT(1)struct svc_i3c_cmd {u8 addr;
@@ -584,6 +591,11 @@ static irqreturn_t svc_i3c_master_irq_handler(int irq, void *dev_id)/* Clear the interrupt status */ writel (SVC_I3C_MINT_SLVSTART , master->regs +SVC_I3C_MSTATUS ); +/* Ignore the false event */ +if (svc_has_quirk (master,SVC_I3C_QUIRK_FALSE_SLVSTART ) && + !SVC_I3C_MSTATUS_STATE_SLVREQ (active)) +return IRQ_HANDLED ; +svc_i3c_master_disable_interrupts (master);/* Handle the interrupt in a non atomic context */
@@ -2008,7 +2020,8 @@ static const struct dev_pm_ops svc_i3c_pm_ops = { };static const struct svc_i3c_drvdata npcm845_drvdata = { - .quirks =SVC_I3C_QUIRK_FIFO_EMPTY , + .quirks =SVC_I3C_QUIRK_FIFO_EMPTY | +SVC_I3C_QUIRK_FALSE_SLVSTART , };static const struct svc_i3c_drvdata svc_default_drvdata = {};
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 761/869 i3c: master: svc: Prevent IRQ storm from false SLVSTART on NPCM845
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stanley Chu <[email protected]>
[ Upstream commit 1effa3adfe53cb2bb28bf5640a676b791d5ab405 ]
On NPCM845, when a target on the I3C bus gets stuck holding SDA low, the controller reports a false Master Request (MR) in-band interrupt event. The driver handles this by emitting a STOP condition to restore the bus.
However, the hardware quirk SVC_I3C_QUIRK_FALSE_SLVSTART indicates that emitting a STOP condition may spuriously set the SLVSTART interrupt status bit. In the Master Request case, this creates a feedback loop:
the STOP triggers a new SLVSTART event, the IRQ handler fires again, the controller still reports an MR type, another STOP is emitted, and the cycle repeats indefinitely, resulting in an IRQ storm that can lock up the CPU.
Clear the SLVSTART status bit explicitly after emitting the STOP in the Master Request IBI handler when the SVC_I3C_QUIRK_FALSE_SLVSTART quirk is set. This breaks the feedback loop without affecting normal SLVSTART processing, which is already guarded in the top-level IRQ handler by checking that MSTATUS is in SLVREQ state.
--- drivers/i3c/master/svc-i3c-master.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/i3c/master/svc-i3c-master.c +9 -0
@@ -570,6 +570,15 @@ static void svc_i3c_master_ibi_work(struct work_struct *work)break ;case SVC_I3C_MSTATUS_IBITYPE_MASTER_REQUEST :svc_i3c_master_emit_stop (master); + +/* +* If a target gets stuck holding SDA low, the controller reports a MR. +* On NPCM845, emitting STOP may spuriously set SLVSTART, retriggering +* the interrupt and re-entering MR handling, leading to an IRQ storm. +* Clear SLVSTART after STOP to break the loop. +*/ +if (svc_has_quirk (master,SVC_I3C_QUIRK_FALSE_SLVSTART )) +writel (SVC_I3C_MINT_SLVSTART , master->regs +SVC_I3C_MSTATUS );break ;default :break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 762/869 hwmon: (asus_rog_ryujin) Rely on subsystem locking
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guenter Roeck <[email protected]>
[ Upstream commit b4306c0c8e24f9e031185fb87de45391bc8c7fe9 ]
Attribute access is now serialized in the hardware monitoring core, so locking in the driver code is no longer necessary. Drop it.
Stable-dep-of: 8042312e73c5 ("hwmon: (asus_rog_ryujin) Validate HID report lengths")
--- drivers/hwmon/asus_rog_ryujin.c | 48 +++++++-------------------------- 1 file changed, 9 insertions(+), 39 deletions(-)
drivers/hwmon/asus_rog_ryujin.c +9 -39
@@ -81,10 +81,6 @@ static const char *const rog_ryujin_speed_label[] = {struct rog_ryujin_data {struct hid_device *hdev;struct device *hwmon_dev; -/* For locking access to buffer */ -struct mutex buffer_lock; -/* For queueing multiple readers */ -struct mutex status_report_request_mutex;/* For reinitializing the completions below */ spinlock_t status_report_request_lock;struct completion cooler_status_received;
@@ -153,18 +149,10 @@ static umode_t rog_ryujin_is_visible(const void *data,/* Writes the command to the device with the rest of the report filled with zeroes */ static int rog_ryujin_write_expanded (struct rog_ryujin_data *priv,const u8 *cmd,int cmd_length) { -int ret; - -mutex_lock (&priv->buffer_lock); -memcpy_and_pad (priv->buffer,MAX_REPORT_LENGTH , cmd, cmd_length,0x00 ); - ret =hid_hw_output_report (priv->hdev, priv->buffer,MAX_REPORT_LENGTH ); - -mutex_unlock (&priv->buffer_lock); -return ret; +return hid_hw_output_report (priv->hdev, priv->buffer,MAX_REPORT_LENGTH ); } -/* Assumes priv->status_report_request_mutex is locked */ static int rog_ryujin_execute_cmd (struct rog_ryujin_data *priv,const u8 *cmd,int cmd_length,struct completion *status_completion) {
@@ -196,14 +184,11 @@ static int rog_ryujin_execute_cmd(struct rog_ryujin_data *priv, const u8 *cmd, istatic int rog_ryujin_get_status (struct rog_ryujin_data *priv) { -int ret =mutex_lock_interruptible (&priv->status_report_request_mutex); - -if (ret <0 ) -return ret; +int ret;if (!time_after (jiffies, priv->updated +msecs_to_jiffies (STATUS_VALIDITY ))) {/* Data is up to date */ - goto unlock_and_return; +return 0 ; }/* Retrieve cooler status */
@@ -211,36 +196,30 @@ static int rog_ryujin_get_status(struct rog_ryujin_data *priv)rog_ryujin_execute_cmd (priv, get_cooler_status_cmd,GET_CMD_LENGTH , &priv->cooler_status_received);if (ret <0 ) - goto unlock_and_return; +return ret;/* Retrieve controller status (speeds) */ ret =rog_ryujin_execute_cmd (priv, get_controller_speed_cmd,GET_CMD_LENGTH , &priv->controller_status_received);if (ret <0 ) - goto unlock_and_return; +return ret;/* Retrieve cooler duty */ ret =rog_ryujin_execute_cmd (priv, get_cooler_duty_cmd,GET_CMD_LENGTH , &priv->cooler_duty_received);if (ret <0 ) - goto unlock_and_return; +return ret;/* Retrieve controller duty */ ret =rog_ryujin_execute_cmd (priv, get_controller_duty_cmd,GET_CMD_LENGTH , &priv->controller_duty_received); -if (ret <0 ) - goto unlock_and_return; - - priv->updated = jiffies; - -unlock_and_return: -mutex_unlock (&priv->status_report_request_mutex);if (ret <0 )return ret; + priv->updated = jiffies;return 0 ; }
@@ -303,14 +282,11 @@ static int rog_ryujin_write_fixed_duty(struct rog_ryujin_data *priv, int channel* Retrieve cooler duty since both pump and internal fan are set * together, then write back with one of them modified. */ - ret =mutex_lock_interruptible (&priv->status_report_request_mutex); -if (ret <0 ) -return ret; ret =rog_ryujin_execute_cmd (priv, get_cooler_duty_cmd,GET_CMD_LENGTH , &priv->cooler_duty_received);if (ret <0 ) - goto unlock_and_return; +return ret;memcpy (set_cmd, set_cooler_duty_cmd,SET_CMD_LENGTH );
@@ -329,11 +305,7 @@ static int rog_ryujin_write_fixed_duty(struct rog_ryujin_data *priv, int channel set_cmd[RYUJIN_SET_COOLER_FAN_DUTY_OFFSET ] = val; } - ret =rog_ryujin_execute_cmd (priv, set_cmd,SET_CMD_LENGTH , &priv->cooler_duty_set); -unlock_and_return: -mutex_unlock (&priv->status_report_request_mutex); -if (ret <0 ) -return ret; +return rog_ryujin_execute_cmd (priv, set_cmd,SET_CMD_LENGTH , &priv->cooler_duty_set); }else {/* * Controller fan duty (channel == 2). No need to retrieve current
@@ -538,8 +510,6 @@ static int rog_ryujin_probe(struct hid_device *hdev, const struct hid_device_id goto fail_and_close; } -mutex_init (&priv->status_report_request_mutex); -mutex_init (&priv->buffer_lock);spin_lock_init (&priv->status_report_request_lock);init_completion (&priv->cooler_status_received);init_completion (&priv->controller_status_received);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 763/869 hwmon: (asus_rog_ryujin) Add per-device configuration
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arie Miller <[email protected]>
[ Upstream commit b20ee9aee8779427d2f9de99cbb578b048bf7c04 ]
Move model-specific report offsets and capabilities into a device information structure. This prepares the driver for coolers which use a different report layout or do not include the external fan controller, while preserving the existing Ryujin II 360 behavior.
Handles an issue reported by Sashiko where an id could be missing driver_data.
Stable-dep-of: 8042312e73c5 ("hwmon: (asus_rog_ryujin) Validate HID report lengths")
--- drivers/hwmon/asus_rog_ryujin.c | 75 +++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 23 deletions(-)
drivers/hwmon/asus_rog_ryujin.c +52 -23
@@ -18,15 +18,25 @@#define USB_VENDOR_ID_ASUS_ROG 0x0b05#define USB_PRODUCT_ID_RYUJIN_AIO 0x1988/* ASUS ROG RYUJIN II 360 */ +struct rog_ryujin_device_info { +u8 temp_offset; +u8 pump_speed_offset; +u8 fan_speed_offset; +u8 duty_channel; +bool has_controller; +}; + +static const struct rog_ryujin_device_info rog_ryujin_ii_360_info = { + .temp_offset =3 , + .pump_speed_offset =5 , + .fan_speed_offset =7 , + .duty_channel =0 , + .has_controller = true, +}; +#define STATUS_VALIDITY 1500/* ms */ #define MAX_REPORT_LENGTH 65 -/* Cooler status report offsets */ -#define RYUJIN_TEMP_SENSOR_1 3 -#define RYUJIN_TEMP_SENSOR_2 4 -#define RYUJIN_PUMP_SPEED 5 -#define RYUJIN_INTERNAL_FAN_SPEED 7 -/* Cooler duty report offsets */ #define RYUJIN_PUMP_DUTY 4#define RYUJIN_INTERNAL_FAN_DUTY 5
@@ -81,6 +91,7 @@ static const char *const rog_ryujin_speed_label[] = {struct rog_ryujin_data {struct hid_device *hdev;struct device *hwmon_dev; +const struct rog_ryujin_device_info *info;/* For reinitializing the completions below */ spinlock_t status_report_request_lock;struct completion cooler_status_received;
@@ -112,6 +123,8 @@ static int rog_ryujin_pwm_to_percent(long val)static umode_t rog_ryujin_is_visible (const void *data,enum hwmon_sensor_types type,u32 attr,int channel) { +const struct rog_ryujin_data *priv = data; +switch (type) {case hwmon_temp:switch (attr) {
@@ -123,6 +136,8 @@ static umode_t rog_ryujin_is_visible(const void *data, }break ;case hwmon_fan: +if (channel >=2 && !priv->info->has_controller) +return 0 ;switch (attr) {case hwmon_fan_label:case hwmon_fan_input:
@@ -132,6 +147,8 @@ static umode_t rog_ryujin_is_visible(const void *data, }break ;case hwmon_pwm: +if (channel >=2 && !priv->info->has_controller) +return 0 ;switch (attr) {case hwmon_pwm_input:return 0644 ;
@@ -198,12 +215,14 @@ static int rog_ryujin_get_status(struct rog_ryujin_data *priv)if (ret <0 )return ret; -/* Retrieve controller status (speeds) */ - ret = -rog_ryujin_execute_cmd (priv, get_controller_speed_cmd,GET_CMD_LENGTH , - &priv->controller_status_received); -if (ret <0 ) -return ret; +if (priv->info->has_controller) { +/* Retrieve controller status (speeds) */ + ret =rog_ryujin_execute_cmd (priv, get_controller_speed_cmd, +GET_CMD_LENGTH , + &priv->controller_status_received); +if (ret <0 ) +return ret; + }/* Retrieve cooler duty */ ret =
@@ -212,12 +231,14 @@ static int rog_ryujin_get_status(struct rog_ryujin_data *priv)if (ret <0 )return ret; -/* Retrieve controller duty */ - ret = -rog_ryujin_execute_cmd (priv, get_controller_duty_cmd,GET_CMD_LENGTH , - &priv->controller_duty_received); -if (ret <0 ) -return ret; +if (priv->info->has_controller) { +/* Retrieve controller duty */ + ret =rog_ryujin_execute_cmd (priv, get_controller_duty_cmd, +GET_CMD_LENGTH , + &priv->controller_duty_received); +if (ret <0 ) +return ret; + } priv->updated = jiffies;return 0 ;
@@ -289,6 +310,7 @@ static int rog_ryujin_write_fixed_duty(struct rog_ryujin_data *priv, int channelreturn ret;memcpy (set_cmd, set_cooler_duty_cmd,SET_CMD_LENGTH ); + set_cmd[2 ] = priv->info->duty_channel;/* Cooler duties are set as 0-100% */ val =rog_ryujin_pwm_to_percent (val);
@@ -394,10 +416,12 @@ static int rog_ryujin_raw_event(struct hid_device *hdev, struct hid_report *repoif (data[1 ] ==RYUJIN_GET_COOLER_STATUS_CMD_RESPONSE ) {/* Received coolant temp and speeds of pump and internal fan */ - priv->temp_input[0 ] = - data[RYUJIN_TEMP_SENSOR_1 ] *1000 + data[RYUJIN_TEMP_SENSOR_2 ] *100 ; - priv->speed_input[0 ] =get_unaligned_le16 (data +RYUJIN_PUMP_SPEED ); - priv->speed_input[1 ] =get_unaligned_le16 (data +RYUJIN_INTERNAL_FAN_SPEED ); + priv->temp_input[0 ] = data[priv->info->temp_offset] *1000 + + data[priv->info->temp_offset +1 ] *100 ; + priv->speed_input[0 ] = +get_unaligned_le16 (data + priv->info->pump_speed_offset); + priv->speed_input[1 ] = +get_unaligned_le16 (data + priv->info->fan_speed_offset);if (!completion_done (&priv->cooler_status_received))complete_all (&priv->cooler_status_received);
@@ -471,11 +495,15 @@ static int rog_ryujin_probe(struct hid_device *hdev, const struct hid_device_idstruct rog_ryujin_data *priv;int ret; +if (!id->driver_data) +return -EINVAL ; + priv =devm_kzalloc (&hdev->dev,sizeof (*priv),GFP_KERNEL );if (!priv)return -ENOMEM ; priv->hdev = hdev; + priv->info = (const struct rog_ryujin_device_info *)id->driver_data;hid_set_drvdata (hdev, priv);/*
@@ -546,7 +574,8 @@ static void rog_ryujin_remove(struct hid_device *hdev) }static const struct hid_device_id rog_ryujin_table[] = { - {HID_USB_DEVICE (USB_VENDOR_ID_ASUS_ROG ,USB_PRODUCT_ID_RYUJIN_AIO ) }, + {HID_USB_DEVICE (USB_VENDOR_ID_ASUS_ROG ,USB_PRODUCT_ID_RYUJIN_AIO ), + .driver_data = (kernel_ulong_t)&rog_ryujin_ii_360_info }, { } };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 764/869 hwmon: (asus_rog_ryujin) Validate HID report lengths
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arie Miller <[email protected]>
[ Upstream commit 8042312e73c50de82634ce63eae7cf219464b481 ]
rog_ryujin_raw_event() parses response headers and payload fields without first checking that they are present in the received report. A short report can therefore make the driver consume uninitialized bytes from the HID transport buffer and expose them as sensor values through sysfs.
Validate the response header and the fields used by each response type before parsing them.
--- drivers/hwmon/asus_rog_ryujin.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/hwmon/asus_rog_ryujin.c +15 -1
@@ -411,10 +411,15 @@ static int rog_ryujin_raw_event(struct hid_device *hdev, struct hid_report *repo {struct rog_ryujin_data *priv =hid_get_drvdata (hdev); -if (data[0 ] !=RYUJIN_CMD_PREFIX ) +if (size <2 || data[0 ] !=RYUJIN_CMD_PREFIX )return 0 ;if (data[1 ] ==RYUJIN_GET_COOLER_STATUS_CMD_RESPONSE ) { +if (size <= priv->info->temp_offset +1 || + size <= priv->info->pump_speed_offset +1 || + size <= priv->info->fan_speed_offset +1 ) +return 0 ; +/* Received coolant temp and speeds of pump and internal fan */ priv->temp_input[0 ] = data[priv->info->temp_offset] *1000 + data[priv->info->temp_offset +1 ] *100 ;
@@ -426,6 +431,9 @@ static int rog_ryujin_raw_event(struct hid_device *hdev, struct hid_report *repoif (!completion_done (&priv->cooler_status_received))complete_all (&priv->cooler_status_received); }else if (data[1 ] ==RYUJIN_GET_CONTROLLER_SPEED_CMD_RESPONSE ) { +if (size <=RYUJIN_CONTROLLER_SPEED_3 +1 ) +return 0 ; +/* Received speeds of four fans attached to the controller */ priv->speed_input[2 ] =get_unaligned_le16 (data +RYUJIN_CONTROLLER_SPEED_1 ); priv->speed_input[3 ] =get_unaligned_le16 (data +RYUJIN_CONTROLLER_SPEED_2 );
@@ -435,6 +443,9 @@ static int rog_ryujin_raw_event(struct hid_device *hdev, struct hid_report *repoif (!completion_done (&priv->controller_status_received))complete_all (&priv->controller_status_received); }else if (data[1 ] ==RYUJIN_GET_COOLER_DUTY_CMD_RESPONSE ) { +if (size <=RYUJIN_INTERNAL_FAN_DUTY ) +return 0 ; +/* Received report for pump and internal fan duties (in %) */ if (data[RYUJIN_PUMP_DUTY ] ==0 && data[RYUJIN_INTERNAL_FAN_DUTY ] ==0 ) {/*
@@ -461,6 +472,9 @@ static int rog_ryujin_raw_event(struct hid_device *hdev, struct hid_report *repoif (!completion_done (&priv->cooler_duty_received))complete_all (&priv->cooler_duty_received); }else if (data[1 ] ==RYUJIN_GET_CONTROLLER_DUTY_CMD_RESPONSE ) { +if (size <=RYUJIN_CONTROLLER_DUTY ) +return 0 ; +/* Received report for controller duty for fans (in PWM) */ if (data[RYUJIN_CONTROLLER_DUTY ] ==0 ) {/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 765/869 smb: client: avoid using uninitialized SIDs in cifs_posix_to_fattr()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
[ Upstream commit da6e25842431982d5a53cf00d925b98c690f4467 ]
cifs_posix_to_fattr() ignores the return value of posix_info_parse(). When a malformed POSIX directory entry is encountered (e.g. invalid SID lengths from an untrusted server), posix_info_parse() returns -1 without populating the 'parsed' struct. The uninitialized stack memory in parsed.owner and parsed.group is then passed to sid_to_id(), which processes the garbage bytes and passes them to request_key() to construct a SID string, potentially leaking kernel stack contents to the userspace idmap daemon.
Fix this by checking the return value and skipping the SID-to-id mapping when parsing fails. The remaining fattr fields (timestamps, mode, etc.) are populated directly from the 'info' pointer so they are unaffected.
--- fs/smb/client/readdir.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
fs/smb/client/readdir.c +11 -3
@@ -242,8 +242,9 @@ cifs_posix_to_fattr(struct cifs_fattr *fattr, struct smb2_posix_info *info, struct cifs_sb_info *cifs_sb) {struct smb2_posix_info_parsed parsed; +int rc; -posix_info_parse (info,NULL , &parsed); + rc =posix_info_parse (info,NULL , &parsed);memset (fattr,0 ,sizeof (*fattr)); fattr->cf_uniqueid =le64_to_cpu (info->Inode);
@@ -280,8 +281,15 @@ cifs_posix_to_fattr(struct cifs_fattr *fattr, struct smb2_posix_info *info,le32_to_cpu (info->ReparseTag), le32_to_cpu(info->Mode)); -sid_to_id (cifs_sb, &parsed.owner, fattr,SIDOWNER ); -sid_to_id (cifs_sb, &parsed.group, fattr,SIDGROUP ); + fattr->cf_uid = cifs_sb->ctx->linux_uid; + fattr->cf_gid = cifs_sb->ctx->linux_gid; +if (rc <0 ) { +cifs_dbg (VFS ,"%s: failed to parse SIDs: %d\n" , + __func__, rc); + }else { +sid_to_id (cifs_sb, &parsed.owner, fattr,SIDOWNER ); +sid_to_id (cifs_sb, &parsed.group, fattr,SIDGROUP ); + } }static void __dir_info_to_fattr (struct cifs_fattr *fattr,const void *info)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 766/869 smb: client: honor forceuid/forcegid when mapping SIDs to uid/gid
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
[ Upstream commit 18a72975e9f35aadecc75b031f693f2d1f49308f ]
When the administrator mounts with forceuid or forcegid (uid=/gid= mount options), they expect all files to appear owned by the specified user/group. However, several code paths unconditionally called sid_to_id() to overwrite cf_uid/cf_gid with server-provided values, ignoring the administrator's explicit override:
- smb311_posix_info_to_fattr() (stat via POSIX extensions)
- cifs_posix_to_fattr() (readdir via POSIX extensions)
- parse_sec_desc() (CIFS ACL ownership mapping)
This allowed an untrusted server to dictate local file ownership even when the mount was configured to force specific uid/gid values.
Fix all three call sites to check CIFS_MOUNT_OVERR_UID and CIFS_MOUNT_OVERR_GID before calling sid_to_id(), following the same pattern already used by cifs_unix_basic_to_fattr() for unix extensions.
--- fs/smb/client/cifsacl.c | 28 ++++++++++++++++++---------- fs/smb/client/inode.c | 9 +++++++-- fs/smb/client/readdir.c | 7 +++++-- 3 files changed, 30 insertions(+), 14 deletions(-)
fs/smb/client/cifsacl.c +18 -10
@@ -1315,6 +1315,7 @@ static int parse_sec_desc(struct cifs_sb_info *cifs_sb, {int rc =0 ;struct smb_sid *owner_sid_ptr, *group_sid_ptr; +unsigned int sbflags = cifs_sb->mnt_cifs_flags;struct smb_acl *dacl_ptr;/* no need for SACL ptr */ char *end_of_acl = ((char *)pntsd) + acl_len;__u32 dacloffset;
@@ -1332,16 +1333,21 @@ static int parse_sec_desc(struct cifs_sb_info *cifs_sb,le32_to_cpu (pntsd->gsidoffset), le32_to_cpu(pntsd->sacloffset), dacloffset);/* cifs_dump_mem("owner_sid: ", owner_sid_ptr, 64); */ + fattr->cf_uid = cifs_sb->ctx->linux_uid; + fattr->cf_gid = cifs_sb->ctx->linux_gid; + rc =parse_sid (owner_sid_ptr, end_of_acl);if (rc) {cifs_dbg (FYI ,"%s: Error %d parsing Owner SID\n" , __func__, rc);return rc; } - rc =sid_to_id (cifs_sb, owner_sid_ptr, fattr,SIDOWNER ); -if (rc) { -cifs_dbg (FYI ,"%s: Error %d mapping Owner SID to uid\n" , - __func__, rc); -return rc; +if (!(sbflags &CIFS_MOUNT_OVERR_UID )) { + rc =sid_to_id (cifs_sb, owner_sid_ptr, fattr,SIDOWNER ); +if (rc) { +cifs_dbg (FYI ,"%s: Error %d mapping Owner SID to uid\n" , + __func__, rc); +return rc; + } } rc =parse_sid (group_sid_ptr, end_of_acl);
@@ -1350,11 +1356,13 @@ static int parse_sec_desc(struct cifs_sb_info *cifs_sb, __func__, rc);return rc; } - rc =sid_to_id (cifs_sb, group_sid_ptr, fattr,SIDGROUP ); -if (rc) { -cifs_dbg (FYI ,"%s: Error %d mapping Group SID to gid\n" , - __func__, rc); -return rc; +if (!(sbflags &CIFS_MOUNT_OVERR_GID )) { + rc =sid_to_id (cifs_sb, group_sid_ptr, fattr,SIDGROUP ); +if (rc) { +cifs_dbg (FYI ,"%s: Error %d mapping Group SID to gid\n" , + __func__, rc); +return rc; + } }if (dacloffset) {
fs/smb/client/inode.c +7 -2
@@ -833,6 +833,7 @@ static void smb311_posix_info_to_fattr(struct cifs_fattr *fattr,struct smb311_posix_qinfo *info = &data->posix_fi;struct cifs_sb_info *cifs_sb =CIFS_SB (sb);struct cifs_tcon *tcon =cifs_sb_master_tcon (cifs_sb); +unsigned int sbflags = cifs_sb->mnt_cifs_flags;memset (fattr,0 ,sizeof (*fattr));
@@ -877,8 +878,12 @@ static void smb311_posix_info_to_fattr(struct cifs_fattr *fattr, fattr->cf_symlink_target = data->symlink_target; data->symlink_target =NULL ; } -sid_to_id (cifs_sb, &data->posix_owner, fattr,SIDOWNER ); -sid_to_id (cifs_sb, &data->posix_group, fattr,SIDGROUP ); + fattr->cf_uid = cifs_sb->ctx->linux_uid; + fattr->cf_gid = cifs_sb->ctx->linux_gid; +if (!(sbflags &CIFS_MOUNT_OVERR_UID )) +sid_to_id (cifs_sb, &data->posix_owner, fattr,SIDOWNER ); +if (!(sbflags &CIFS_MOUNT_OVERR_GID )) +sid_to_id (cifs_sb, &data->posix_group, fattr,SIDGROUP );cifs_dbg (FYI ,"POSIX query info: mode 0x%x uniqueid 0x%llx nlink %d\n" , fattr->cf_mode, fattr->cf_uniqueid, fattr->cf_nlink);
fs/smb/client/readdir.c +5 -2
@@ -241,6 +241,7 @@ static void cifs_posix_to_fattr(struct cifs_fattr *fattr, struct smb2_posix_info *info, struct cifs_sb_info *cifs_sb) { + unsigned int sbflags = cifs_sb->mnt_cifs_flags;struct smb2_posix_info_parsed parsed;int rc;
@@ -287,8 +288,10 @@ cifs_posix_to_fattr(struct cifs_fattr *fattr, struct smb2_posix_info *info,cifs_dbg (VFS ,"%s: failed to parse SIDs: %d\n" , __func__, rc); }else { -sid_to_id (cifs_sb, &parsed.owner, fattr,SIDOWNER ); -sid_to_id (cifs_sb, &parsed.group, fattr,SIDGROUP ); +if (!(sbflags &CIFS_MOUNT_OVERR_UID )) +sid_to_id (cifs_sb, &parsed.owner, fattr,SIDOWNER ); +if (!(sbflags &CIFS_MOUNT_OVERR_GID )) +sid_to_id (cifs_sb, &parsed.group, fattr,SIDGROUP ); } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 767/869 drm/amdgpu: skip the VMID 0 flush for VRAM
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arunpravin Paneer Selvam <[email protected]>
[ Upstream commit 87ceb8cba73d0b3c4025ff42495bccd8164acaed ]
Clear-on-release only runs on VRAM, which amdgpu_ttm_map_buffer() reaches via its direct MC address without programming a GART window, yet the wipe still forces a VMID 0 flush. On GFX11 (e.g. Navi33) that spurious SDMA flush can wedge the engine; only flush when a GART window is actually used.
v2: Let amdgpu_ttm_map_buffer() return whether the VMID 0 flush is needed,
and drive the clear and copy paths from that. (Christian)
v3: Make the vm_needs_flush output parameter mandatory instead of
allowing NULL. (Christian)
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +17 -8
@@ -174,6 +174,8 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo,* @tmz: if we should setup a TMZ enabled mapping * @size: in number of bytes to map, out number of bytes mapped * @addr: resulting address inside the MC address space +* @vm_needs_flush: out, set true if a GART window was programmed (VMID 0 flush +* needed) or false for a direct address * * Setup one of the GART windows to access a specific piece of memory or return * the physical address for local memory.
@@ -182,7 +184,8 @@ static int amdgpu_ttm_map_buffer(struct ttm_buffer_object *bo,struct ttm_resource *mem, struct amdgpu_res_cursor *mm_cur, unsigned int window, struct amdgpu_ring *ring, - bool tmz, uint64_t *size, uint64_t *addr) + bool tmz, uint64_t *size, uint64_t *addr, + bool *vm_needs_flush) { struct amdgpu_device *adev = ring->adev;unsigned int offset, num_pages, num_dw, num_bytes;
@@ -203,9 +206,12 @@ static int amdgpu_ttm_map_buffer(struct ttm_buffer_object *bo,if (!tmz && mem->start !=AMDGPU_BO_INVALID_OFFSET ) { *addr =amdgpu_ttm_domain_start (adev, mem->mem_type) + mm_cur->start; + *vm_needs_flush = false;return 0 ; } +/* A GART window is programmed below, so its VMID 0 TLB needs a flush */ + *vm_needs_flush = true;/* * If start begins at an offset inside the page, then adjust the size
@@ -314,6 +320,7 @@ int amdgpu_ttm_copy_mem_to_mem(struct amdgpu_device *adev,while (src_mm.remaining) {uint64_t from, to, cur_size, tiling_flags;uint32_t num_type, data_format, max_com, write_compress_disable; +bool src_vm_flush, dst_vm_flush;struct dma_fence *next;/* Never copy more than 256MiB at once to avoid a timeout */
@@ -321,12 +328,12 @@ int amdgpu_ttm_copy_mem_to_mem(struct amdgpu_device *adev,/* Map src to window 0 and dst to window 1. */ r =amdgpu_ttm_map_buffer (src->bo, src->mem, &src_mm, -0 , ring, tmz, &cur_size, &from); +0 , ring, tmz, &cur_size, &from, &src_vm_flush);if (r) goto error; r =amdgpu_ttm_map_buffer (dst->bo, dst->mem, &dst_mm, -1 , ring, tmz, &cur_size, &to); +1 , ring, tmz, &cur_size, &to, &dst_vm_flush);if (r) goto error;
@@ -354,7 +361,7 @@ int amdgpu_ttm_copy_mem_to_mem(struct amdgpu_device *adev, } r =amdgpu_copy_buffer (ring, from, to, cur_size, resv, - &next, false, true, copy_flags); + &next, false, src_vm_flush || dst_vm_flush, copy_flags);if (r) goto error;
@@ -2311,6 +2318,7 @@ int amdgpu_ttm_clear_buffer(struct amdgpu_bo *bo,struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev);struct amdgpu_ring *ring = adev->mman.buffer_funcs_ring;struct amdgpu_res_cursor cursor; +bool vm_needs_flush = false;u64 addr;int r =0 ;
@@ -2338,12 +2346,12 @@ int amdgpu_ttm_clear_buffer(struct amdgpu_bo *bo, size =min (cursor.size,256ULL <<20 ); r =amdgpu_ttm_map_buffer (&bo->tbo, bo->tbo.resource, &cursor, -1 , ring, false, &size, &addr); +1 , ring, false, &size, &addr, &vm_needs_flush);if (r) goto err; r =amdgpu_ttm_fill_mem (ring,0 , addr, size, resv, - &next, true, true, + &next, vm_needs_flush, true,AMDGPU_KERNEL_JOB_ID_TTM_CLEAR_BUFFER );if (r) goto err;
@@ -2370,6 +2378,7 @@ int amdgpu_fill_buffer(struct amdgpu_bo *bo,struct amdgpu_ring *ring = adev->mman.buffer_funcs_ring;struct dma_fence *fence =NULL ;struct amdgpu_res_cursor dst; +bool vm_needs_flush = false;int r;if (!adev->mman.buffer_funcs_enabled) {
@@ -2388,12 +2397,12 @@ int amdgpu_fill_buffer(struct amdgpu_bo *bo, cur_size =min (dst.size,256ULL <<20 ); r =amdgpu_ttm_map_buffer (&bo->tbo, bo->tbo.resource, &dst, -1 , ring, false, &cur_size, &to); +1 , ring, false, &cur_size, &to, &vm_needs_flush);if (r) goto error; r =amdgpu_ttm_fill_mem (ring, src_data, to, cur_size, resv, - &next, true, delayed, k_job_id); + &next, vm_needs_flush, delayed, k_job_id);if (r) goto error;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 768/869 perf/x86/intel: Prevent drain_pebs() reentry
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dapeng Mi <[email protected]>
[ Upstream commit a56c03a397e2cd0c4cf8da96dcd6214f7d0e7d8c ]
The PEBS buffer is shared by all events on a CPU, so drain_pebs() must not be reentered. If so, one instance may observe stale buffer state and potentially access out-of-bound memory.
Most invocations happen in NMI context, which naturally prevents reentry. However, drain_pebs() is also reachable from process context via intel_pmu_drain_pebs_buffer().
In those paths, the PMU is often already disabled, but not guaranteed. For example, __intel_pmu_pebs_disable() only disables the target counter, so other active counters can still raise a PMI and interrupt an in-flight drain_pebs(). Here is an example,
__perf_addr_filters_adjust()
perf_event_stop()
__perf_event_stop()
x86_pmu_stop() (event->pmu->stop)
intel_pmu_disable_event()
intel_pmu_pebs_disable()
__intel_pmu_pebs_disable()
intel_pmu_drain_large_pebs()
intel_pmu_drain_pebs_buffer()Introduce __intel_pmu_quiesce() and __intel_pmu_resume() helpers and use them in intel_pmu_drain_large_pebs() to disable the full PMU around the intel_pmu_drain_pebs_buffer() call, preventing reentry.
Also add a warning in intel_pmu_drain_pebs_buffer() when the full PMU is not disabled.
--- arch/x86/events/intel/core.c | 32 ++++++++++++++++++++++++-------- arch/x86/events/intel/ds.c | 8 +++++++- arch/x86/events/perf_event.h | 3 +++ 3 files changed, 34 insertions(+), 9 deletions(-)
arch/x86/events/intel/core.c +24 -8
@@ -2606,6 +2606,27 @@ static void intel_pmu_del_event(struct perf_event *event)intel_pmu_pebs_del (event); } +int __intel_pmu_quiesce (void ) +{ +struct cpu_hw_events *cpuc =this_cpu_ptr (&cpu_hw_events); +int pmu_enabled = cpuc->enabled; + + cpuc->enabled =0 ; +if (pmu_enabled) +intel_pmu_disable_all (); + +return pmu_enabled; +} + +void __intel_pmu_resume (int pmu_enabled) +{ +struct cpu_hw_events *cpuc =this_cpu_ptr (&cpu_hw_events); + + cpuc->enabled = pmu_enabled; +if (pmu_enabled) +intel_pmu_enable_all (0 ); +} +static int icl_set_topdown_event_period (struct perf_event *event) {struct hw_perf_event *hwc = &event->hw;
@@ -2784,24 +2805,19 @@ static void intel_pmu_read_event(struct perf_event *event) {if (event->hw.flags & (PERF_X86_EVENT_AUTO_RELOAD |PERF_X86_EVENT_TOPDOWN )) {struct cpu_hw_events *cpuc =this_cpu_ptr (&cpu_hw_events); -bool pmu_enabled = cpuc->enabled; +int pmu_enabled;/* Only need to call update_topdown_event() once for group read. */ if (is_metric_event (event) && (cpuc->txn_flags &PERF_PMU_TXN_READ ))return ; - cpuc->enabled =0 ; -if (pmu_enabled) -intel_pmu_disable_all (); + pmu_enabled =__intel_pmu_quiesce ();if (is_topdown_count (event))static_call (intel_pmu_update_topdown_event)(event);else intel_pmu_drain_pebs_buffer (); - - cpuc->enabled = pmu_enabled; -if (pmu_enabled) -intel_pmu_enable_all (0 ); +__intel_pmu_resume (pmu_enabled);return ; }
arch/x86/events/intel/ds.c +7 -1
@@ -949,8 +949,11 @@ int intel_pmu_drain_bts_buffer(void)void intel_pmu_drain_pebs_buffer (void ) { +struct cpu_hw_events *cpuc =this_cpu_ptr (&cpu_hw_events);struct perf_sample_data data; +WARN_ON_ONCE (cpuc->enabled); +static_call (x86_pmu_drain_pebs)(NULL , &data); }
@@ -1448,8 +1451,11 @@ static void intel_pmu_pebs_via_pt_enable(struct perf_event *event)static inline void intel_pmu_drain_large_pebs (struct cpu_hw_events *cpuc) {if (cpuc->n_pebs == cpuc->n_large_pebs && - cpuc->n_pebs != cpuc->n_pebs_via_pt) + cpuc->n_pebs != cpuc->n_pebs_via_pt) { +int enabled =__intel_pmu_quiesce ();intel_pmu_drain_pebs_buffer (); +__intel_pmu_resume (enabled); + } }void intel_pmu_pebs_enable (struct perf_event *event)
arch/x86/events/perf_event.h +3 -0
@@ -1560,6 +1560,9 @@ static __always_inline void __intel_pmu_lbr_disable(void)wrmsrl (MSR_IA32_DEBUGCTLMSR , debugctl); } +extern int __intel_pmu_quiesce (void ); +extern void __intel_pmu_resume (int pmu_enabled); +int intel_pmu_save_and_restart (struct perf_event *event); struct event_constraint *
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 769/869 net/mlx5e: Move representor vnic reporter to eswitch devlink port
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Carolina Jubran <[email protected]>
[ Upstream commit 7f26a5e8040b4957ef4dbdfcde6cc7ba2db53937 ]
The representor vnic devlink health reporter is created and destroyed along the representor netdev (un)load path, which is not serialized by the devlink instance lock. Destroying the reporter from there triggers a devl_assert_locked() splat on driver unbind:
WARNING: net/devlink/core.c:259 at devl_assert_locked+0x54/0x70, CPU#2: bash/3758 Modules linked in: mlx5_vdpa vringh vdpa mlx5_ib mlx5_fwctl mlx5_core ... CPU: 2 UID: 0 PID: 3758 Comm: bash Tainted: G W 6.19.0+ #1 PREEMPT Tainted: [W]=WARN Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), ... RIP: 0010:devl_assert_locked+0x54/0x70 Call Trace: <TASK> devl_health_reporter_destroy+0x3a/0x1b0 mlx5e_vport_rep_unload+0x12d/0x2b0 [mlx5_core] mlx5_eswitch_unregister_vport_reps+0x1b8/0x220 [mlx5_core] ? __esw_offloads_unload_rep+0x190/0x190 [mlx5_core] ? kernfs_remove_by_name_ns+0xc3/0xf0 device_release_driver_internal+0x3b2/0x560 unbind_store+0xce/0xf0
Move the reporter's lifecycle to the eswitch devlink port (un)register paths, which are already serialized by the devlink instance lock, and store the handle on mlx5_devlink_port. Use the port's mlx5_vport as the reporter priv since the diagnose callback only needs a device handle and a vport number, and mlx5_vport carries both and is initialized before any representor driver probes.
--- .../net/ethernet/mellanox/mlx5/core/en_rep.c | 52 +------------------ .../net/ethernet/mellanox/mlx5/core/en_rep.h | 1 - .../mellanox/mlx5/core/esw/devlink_port.c | 36 +++++++++++++ .../net/ethernet/mellanox/mlx5/core/eswitch.h | 1 + 4 files changed, 38 insertions(+), 52 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c +1 -51
@@ -56,7 +56,6 @@#include "lib/vxlan.h" #define CREATE_TRACE_POINTS #include "diag/en_rep_tracepoint.h" -#include "diag/reporter_vnic.h" #include "en_accel/ipsec.h" #include "en/tc/int_port.h" #include "en/ptp.h"
@@ -1412,51 +1411,6 @@ static unsigned int mlx5e_ul_rep_stats_grps_num(struct mlx5e_priv *priv)return ARRAY_SIZE (mlx5e_ul_rep_stats_grps); } -static int -mlx5e_rep_vnic_reporter_diagnose (struct devlink_health_reporter *reporter, -struct devlink_fmsg *fmsg, -struct netlink_ext_ack *extack) -{ -struct mlx5e_rep_priv *rpriv =devlink_health_reporter_priv (reporter); -struct mlx5_eswitch_rep *rep = rpriv->rep; - -mlx5_reporter_vnic_diagnose_counters (rep->esw->dev, fmsg, rep->vport, - true); -return 0 ; -} - -static const struct devlink_health_reporter_ops mlx5_rep_vnic_reporter_ops = { - .name ="vnic" , - .diagnose = mlx5e_rep_vnic_reporter_diagnose, -}; - -static void mlx5e_rep_vnic_reporter_create (struct mlx5e_priv *priv, -struct devlink_port *dl_port) -{ -struct mlx5e_rep_priv *rpriv = priv->ppriv; -struct devlink_health_reporter *reporter; - - reporter =devl_port_health_reporter_create (dl_port, - &mlx5_rep_vnic_reporter_ops, -0 , rpriv); -if (IS_ERR (reporter)) { -mlx5_core_err (priv->mdev, -"Failed to create representor vnic reporter, err = %ld\n" , -PTR_ERR (reporter)); -return ; - } - - rpriv->rep_vnic_reporter = reporter; -} - -static void mlx5e_rep_vnic_reporter_destroy (struct mlx5e_priv *priv) -{ -struct mlx5e_rep_priv *rpriv = priv->ppriv; - -if (!IS_ERR_OR_NULL (rpriv->rep_vnic_reporter)) -devl_health_reporter_destroy (rpriv->rep_vnic_reporter); -} -static const struct mlx5e_profile mlx5e_rep_profile = { .init = mlx5e_init_rep, .cleanup = mlx5e_cleanup_rep,
@@ -1580,10 +1534,8 @@ mlx5e_vport_vf_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep) dl_port =mlx5_esw_offloads_devlink_port (dev->priv.eswitch, rpriv->rep->vport); -if (!IS_ERR (dl_port)) { +if (!IS_ERR (dl_port))SET_NETDEV_DEVLINK_PORT (netdev, dl_port); -mlx5e_rep_vnic_reporter_create (priv, dl_port); - } err =register_netdev (netdev);if (err) {
@@ -1596,7 +1548,6 @@ mlx5e_vport_vf_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)return 0 ; err_detach_netdev: -mlx5e_rep_vnic_reporter_destroy (priv);mlx5e_detach_netdev (netdev_priv (netdev)); err_cleanup_profile: priv->profile->cleanup (priv);
@@ -1654,7 +1605,6 @@ mlx5e_vport_rep_unload(struct mlx5_eswitch_rep *rep) }unregister_netdev (netdev); -mlx5e_rep_vnic_reporter_destroy (priv);mlx5e_detach_netdev (priv); priv->profile->cleanup (priv);mlx5e_destroy_netdev (netdev);
drivers/net/ethernet/mellanox/mlx5/core/en_rep.h +0 -1
@@ -118,7 +118,6 @@ struct mlx5e_rep_priv {struct rtnl_link_stats64 prev_vf_vport_stats;struct mlx5_flow_handle *send_to_vport_meta_rule;struct rhashtable tc_ht; -struct devlink_health_reporter *rep_vnic_reporter; }; static inline
drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c +36 -0
@@ -3,6 +3,26 @@#include <linux/mlx5/driver.h> #include "eswitch.h" +#include "diag/reporter_vnic.h" + +static int +mlx5_esw_rep_vnic_reporter_diagnose (struct devlink_health_reporter *reporter, +struct devlink_fmsg *fmsg, +struct netlink_ext_ack *extack) +{ +struct mlx5_vport *vport =devlink_health_reporter_priv (reporter); + +mlx5_reporter_vnic_diagnose_counters (vport->dev, fmsg, vport->vport, + true); + +return 0 ; +} + +static const +struct devlink_health_reporter_ops mlx5_esw_rep_vnic_reporter_ops = { + .name ="vnic" , + .diagnose = mlx5_esw_rep_vnic_reporter_diagnose, +};static void mlx5_esw_get_port_parent_id (struct mlx5_core_dev *dev,struct netdev_phys_item_id *ppid)
@@ -153,6 +173,7 @@ static const struct devlink_port_ops mlx5_esw_dl_sf_port_ops = {int mlx5_esw_offloads_devlink_port_register (struct mlx5_eswitch *esw,struct mlx5_vport *vport) { +struct devlink_health_reporter *reporter;struct mlx5_core_dev *dev = esw->dev;const struct devlink_port_ops *ops;struct mlx5_devlink_port *dl_port;
@@ -182,6 +203,16 @@ int mlx5_esw_offloads_devlink_port_register(struct mlx5_eswitch *esw, struct mlxif (err) goto rate_err; + reporter =devl_port_health_reporter_create ( + &dl_port->dl_port, &mlx5_esw_rep_vnic_reporter_ops, +0 , vport); +if (IS_ERR (reporter)) +mlx5_core_err (dev, +"Failed to create vnic health reporter for vport %d: %ld\n" , + vport_num,PTR_ERR (reporter)); +else + dl_port->vnic_reporter = reporter; +return 0 ; rate_err:
@@ -197,6 +228,11 @@ void mlx5_esw_offloads_devlink_port_unregister(struct mlx5_eswitch *esw, structreturn ; dl_port = vport->dl_port; +if (dl_port->vnic_reporter) { +devl_health_reporter_destroy (dl_port->vnic_reporter); + dl_port->vnic_reporter =NULL ; + } +mlx5_esw_qos_vport_update_group (esw, vport,NULL ,NULL );devl_rate_leaf_destroy (&dl_port->dl_port);
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +1 -0
@@ -179,6 +179,7 @@ struct mlx5_vport;struct mlx5_devlink_port {struct devlink_port dl_port;struct mlx5_vport *vport; +struct devlink_health_reporter *vnic_reporter; }; static inline void mlx5_devlink_port_init(struct mlx5_devlink_port *dl_port,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 770/869 Bluetooth: hci_sysfs: Fix NULL pointer dereference in device_del()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Krystian Kaniewski <[email protected]>
[ Upstream commit 9b851b09b392da68bd715601f10a5adb2d8d19b8 ]
A NULL pointer dereference in klist_put() occurs when a child device (such as a BNEP network device in bnep_session) is concurrently being unregistered while hci_conn_del_sysfs() reparents child devices.
This is caused by a race condition between hci_conn_del_sysfs() and concurrent child device unregistration (e.g. bnep_session calling unregister_netdev()). During device unregistration, device_del() snapshots a non-NULL parent pointer. Concurrently, hci_conn_del_sysfs() finds the child device using device_find_any_child() and calls device_move() to reparent it to NULL, which removes the node from its parent's klist and clears knode_parent. Subsequently, device_del() calls klist_del(&dev->p->knode_parent) using the stale parent snapshot, causing klist_put() to dereference knode_klist(n)->put on an already removed node, resulting in a NULL pointer dereference.
This race was introduced by commit 27aabf27fd01 ("Bluetooth: fix use-after-free in device_for_each_child()"), which replaced device_find_child(..., __match_tty) with device_find_any_child() in hci_conn_del_sysfs(). That change was intended to avoid a use-after-free where conn->dev outlived its parent hdev->dev when child devices held references to conn->dev, because conn->dev only held a reference to hdev->dev while registered in sysfs.
Fix the issue properly by taking an explicit reference to the parent device with get_device(&hdev->dev) in hci_conn_init_sysfs() and dropping it with put_device(parent) in bt_link_release() when the conn device is freed. This ensures that hdev->dev remains valid for the entire lifecycle of conn->dev, resolving the underlying use-after-free. With the parent reference held properly, restore the __match_tty filter in hci_conn_del_sysfs() so that device_move() is only invoked on persistent RFCOMM TTY devices as originally intended, eliminating the race condition with unregistering network devices.
--- net/bluetooth/hci_sysfs.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
net/bluetooth/hci_sysfs.c +15 -2
@@ -13,7 +13,10 @@ static const struct class bt_class = {static void bt_link_release (struct device *dev) {struct hci_conn *conn =to_hci_conn (dev); +struct device *parent = dev->parent; +kfree (conn); +put_device (parent); }static const struct device_type bt_link = {
@@ -21,6 +24,16 @@ static const struct device_type bt_link = { .release = bt_link_release, }; +/* +* The rfcomm tty device will possibly retain even when conn +* is down, and sysfs doesn't support move zombie device, +* so we should move the device before conn device is destroyed. +*/ +static int __match_tty (struct device *dev,void *data) +{ +return !strncmp (dev_name (dev),"rfcomm" ,6 ); +} +void hci_conn_init_sysfs (struct hci_conn *conn) {struct hci_dev *hdev = conn->hdev;
@@ -29,7 +42,7 @@ void hci_conn_init_sysfs(struct hci_conn *conn) conn->dev.type = &bt_link; conn->dev.class = &bt_class; - conn->dev.parent = &hdev->dev; + conn->dev.parent =get_device (&hdev->dev);device_initialize (&conn->dev); }
@@ -69,7 +82,7 @@ void hci_conn_del_sysfs(struct hci_conn *conn)while (1 ) {struct device *dev; - dev =device_find_any_child (&conn->dev); + dev =device_find_child (&conn->dev,NULL , __match_tty);if (!dev)break ;device_move (dev,NULL ,DPM_ORDER_DEV_LAST );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 771/869 vhost: invalidate vring access on IOTLB transitions
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jia Jia <[email protected]>
[ Upstream commit e4f4761879a230aa59e569102a6ab9851847d833 ]
When VIRTIO_F_ACCESS_PLATFORM changes, cached vring pointers and IOTLB metadata are interpreted in a different address space. Keeping them across the transition can leave stale ring mappings in use.
Clearing d->iotlb before taking the VQ locks also lets a worker observe a transient NULL d->iotlb and fall back to d->umem while translating a descriptor.
Add a common vhost_clear_device_iotlb() helper for vhost-net and vhost-vsock. Take all VQ mutexes in index order before dropping the device-wide IOTLB, invalidate each VQ's cached ring access and metadata, clear pending IOTLB messages, and free the old table after the handoff. This serializes the transition with workers and prevents mixed address space mappings.
On the first direct-to-IOTLB transition, invalidate the cached vring addresses. When an existing device IOTLB is replaced, preserve the GIOVA ring addresses and reset only the metadata cache. After clearing ACCESS_PLATFORM, userspace must configure the vring addresses for the new address mode.
vhost_vq_invalidate_access() clears desc, avail, and used together. Treat the VQ as invalidated only when all three are NULL, since a single GIOVA address may legitimately be zero.
Message-ID: <[email protected]>
--- drivers/vhost/net.c | 2 ++ drivers/vhost/vhost.c | 57 ++++++++++++++++++++++++++++++++++++++++++- drivers/vhost/vhost.h | 1 + drivers/vhost/vsock.c | 2 ++ 4 files changed, 61 insertions(+), 1 deletion(-)
drivers/vhost/net.c +2 -0
@@ -1637,6 +1637,8 @@ static int vhost_net_set_features(struct vhost_net *n, u64 features)if ((features & (1ULL <<VIRTIO_F_ACCESS_PLATFORM ))) {if (vhost_init_device_iotlb (&n->dev)) goto out_unlock; + }else { +vhost_clear_device_iotlb (&n->dev); }for (i =0 ; i <VHOST_NET_VQ_MAX ; ++i) {
drivers/vhost/vhost.c +56 -1
81 lines not on this page · raw message
drivers/vhost/vhost.h +1 -0
@@ -264,6 +264,7 @@ ssize_t vhost_chr_read_iter(struct vhost_dev *dev, struct iov_iter *to, int noblock);ssize_t vhost_chr_write_iter (struct vhost_dev *dev,struct iov_iter *from); +void vhost_clear_device_iotlb (struct vhost_dev *d);int vhost_init_device_iotlb (struct vhost_dev *d); void vhost_iotlb_map_free(struct vhost_iotlb *iotlb,
drivers/vhost/vsock.c +2 -0
@@ -819,6 +819,8 @@ static int vhost_vsock_set_features(struct vhost_vsock *vsock, u64 features)if ((features & (1ULL <<VIRTIO_F_ACCESS_PLATFORM ))) {if (vhost_init_device_iotlb (&vsock->dev)) goto err; + }else { +vhost_clear_device_iotlb (&vsock->dev); } vsock->seqpacket_allow = features & (1ULL <<VIRTIO_VSOCK_F_SEQPACKET );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 772/869 vduse: validate virtqueue alignment
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jia Jia <[email protected]>
[ Upstream commit fa2c25b4add57888acfa89e398389e267bff3dcf ]
vduse_validate_config() only checks the upper bound of vq_align. Invalid values can therefore reach vring_create_virtqueue_map(). The split-ring helpers use align - 1 as a bit mask, so the alignment must be a non-zero power of two. A zero value makes vring_size() drop the descriptor and available-ring part and vring_init() leave the used ring pointer NULL.
The VIRTIO spec requires the used ring to start at an address aligned to at least 4 bytes. Reject values below VRING_USED_ALIGN_SIZE as well as non-power-of-two values before they reach the virtio ring helpers.
Opening a virtio-net device created with vq_align=0 triggered:
BUG: KASAN: null-ptr-deref in virtqueue_kick_prepare_split+0xe3/0x100 Read of size 2 at addr 0000000000000000 by task systemd-network/1062
Call Trace (relevant frames):
dump_stack_lvl
print_report
kasan_report
__asan_load2
virtqueue_kick_prepare_split+0xe3/0x100 virtqueue_kick_prepare+0x40/0x60 try_fill_recv+0x857/0x1250 virtnet_open+0x189/0x460 __dev_open+0x225/0x390 __dev_change_flags+0x368/0x3b0 netif_change_flags+0x56/0xc0 do_setlink.isra.0+0x68c/0x1e30
Validate the value before it reaches the virtio ring helpers.
Message-ID: <[email protected]>
--- drivers/vdpa/vdpa_user/vduse_dev.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/vdpa/vdpa_user/vduse_dev.c +3 -1
@@ -1756,7 +1756,9 @@ static bool vduse_validate_config(struct vduse_dev_config *config) sizeof(config->reserved)))return false; -if (config->vq_align >PAGE_SIZE ) +if (config->vq_align <VRING_USED_ALIGN_SIZE || + !is_power_of_2 (config->vq_align) || + config->vq_align >PAGE_SIZE )return false;if (config->config_size >PAGE_SIZE )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 773/869 virtio_ring: fix stale descriptor flags after a failed packed add
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexander Graf <[email protected]>
[ Upstream commit 75d276e5bb68778b2916f98a2bc30f142ebadc64 ]
In a packed ring the AVAIL and USED bits sit in the descriptor itself, so writing them makes that descriptor available. Those bit combinations flip meaning on every round of the ring, tracked by a wrap counter, so invalidating or validating a descriptor means inverting both bits.
Commit 1ce9e6055fa0 ("virtio_ring: introduce packed ring support") has virtqueue_add_packed() make every descriptor of a chain available as it maps the chain, and write the head last. The device consumes the ring in order and stops at a head that is not available yet, so it never reaches the rest.
When vring_map_one_sg() fails partway, unmap_release unmaps the segments and restores avail_used_flags, but the descriptors it wrote to in the ring stay marked with AVAIL and USED bits. The head is now the only entry that keeps the device from consuming these stale entries.
For example, the ring would look like this now.
Z - pre-previous command
A - previous command
B - aborted command
C - current command
[A1 DONE] [A2 DONE] <C1 EMPTY> [B2] [B3] [Z1 DONE]
When the driver now attempts to issue the C command, the next add starts at the same head as B. If C spans less descriptors than B, there is no end marker because AVAIL and USED bits were still in place. And that means the device will start interpreting these stale entries (B2/B3) as another command entry, which then blocks the queue.
This effect typically happens in swiotlb configurations under memory pressure, because vring_map_one_sg() can then fail with larger I/O requests which then leads to command abortions.
There are broadly 2 ways to avoid leaving those flags behind:
1) Defer those flags too until the chain is complete.
2) Rewrite those flags for the previous wrap counter.
Implement the second option in both packed add paths. The first option traverses the chain a second time on every successful add. The second option invalidates all added descriptors when any add fails.
With this patch applied, a packed virtqueue keeps completing requests after a failed add.
Message-ID: <[email protected]>
--- drivers/virtio/virtio_ring.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
drivers/virtio/virtio_ring.c +17 -2
@@ -1412,7 +1412,7 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq,struct scatterlist *sg;unsigned int i, n, c, descs_used, err_idx;__le16 head_flags, flags; -u16 head, id, prev, curr, avail_used_flags; +u16 head, id, prev, curr, avail_used_flags, unpub_flags;int err;START_USE (vq);
@@ -1535,15 +1535,30 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq, curr = vq->free_head; vq->packed.avail_used_flags = avail_used_flags; + unpub_flags = avail_used_flags ^ (1 <<VRING_PACKED_DESC_F_AVAIL | +1 <<VRING_PACKED_DESC_F_USED );for (n =0 ; n < total_sg; n++) {if (i == err_idx)break ; +/* +* The mapping loop made every descriptor but the head +* available. Stamp the previous wrap counter's AVAIL and USED +* bits on those, so that a later and shorter chain at this head +* does not leave one of them available beyond its own last +* descriptor. Marking them used instead would hand +* is_used_desc_packed() a completion we never made. +*/ +if (i != head) + desc[i].flags =cpu_to_le16 (unpub_flags);vring_unmap_extra_packed (vq, &vq->packed.desc_extra[curr]); curr = vq->packed.desc_extra[curr].next; i++; -if (i >= vq->packed.vring.num) +if (i >= vq->packed.vring.num) { i =0 ; + unpub_flags ^=1 <<VRING_PACKED_DESC_F_AVAIL | +1 <<VRING_PACKED_DESC_F_USED ; + } }END_USE (vq);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 774/869 iommu/amd: Do not reallocate GA log buffers on resume
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 00a7dd64888d6dd72110b40e2824a088cf7b7386 ]
Commit c5e1a1eb9279 ("iommu/amd: Simplify and Consolidate Virtual APIC (AVIC) Enablement") moved the GA log allocation from iommu_init_pci() to enable_iommus_vapic(), which is called on every resume.
iommu_init_ga_log() assigns iommu->ga_log and iommu->ga_log_tail unconditionally. Each resume therefore replaces the boot-time pointers and leaks both old allocations. The function also uses GFP_KERNEL from a syscore resume callback, where interrupts are disabled and the non-boot CPUs are offline.
Return early if both buffers are already allocated. Clear the pointers in free_ga_log() so a partial allocation failure cannot leave ga_log dangling.
--- drivers/iommu/amd/init.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/iommu/amd/init.c +5 -0
@@ -912,7 +912,9 @@ static void free_ga_log(struct amd_iommu *iommu) {#ifdef CONFIG_IRQ_REMAP iommu_free_pages (iommu->ga_log,get_order (GA_LOG_SIZE )); + iommu->ga_log =NULL ;iommu_free_pages (iommu->ga_log_tail,get_order (8 )); + iommu->ga_log_tail =NULL ;#endif }
@@ -957,6 +959,9 @@ static int iommu_init_ga_log(struct amd_iommu *iommu)if (!AMD_IOMMU_GUEST_IR_VAPIC (amd_iommu_guest_ir))return 0 ; +if (iommu->ga_log && iommu->ga_log_tail) +return 0 ; + iommu->ga_log =iommu_alloc_pages (GFP_KERNEL ,get_order (GA_LOG_SIZE ));if (!iommu->ga_log) goto err_out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 775/869 bpf: mark a NULL call argument precise
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eduard Zingerman <[email protected]>
[ Upstream commit 1a3a10b030c96ea88868ccc060a16827c01eaa5a ]
check_func_arg() allows bpf_register_is_null() for nullable arguments w/o marking the underlying scalar register precise. Hence a checkpoint created on such a path would prune against arbitrary scalar value.
check_helper_call() enforces second parameter of the bpf_get_local_storage() to be zero, w/o marking the underlying scalar register precise. Hence a checkpoint created on such a path would prune against arbitrary scalar value.
Grouping these two into one patch, as they share the same fixes tag.
--- kernel/bpf/verifier.c | 9 ++++++++- .../selftests/bpf/progs/verifier_subprog_precision.c | 12 ++++++------ 2 files changed, 14 insertions(+), 7 deletions(-)
kernel/bpf/verifier.c +8 -1
@@ -9172,11 +9172,15 @@ static int check_func_arg(struct bpf_verifier_env *env, u32 arg,return err; } -if (register_is_null (reg) &&type_may_be_null (arg_type)) +if (register_is_null (reg) &&type_may_be_null (arg_type)) {/* A NULL register has a SCALAR_VALUE type, so skip * type checking. */ + err =mark_chain_precision (env, regno); +if (err) +return err; goto skip_type_check; + }/* arg_btf_id and arg_size are in a union. */ if (base_type(arg_type) == ARG_PTR_TO_BTF_ID ||
@@ -10961,6 +10965,9 @@ static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insnverbose (env,"get_local_storage() doesn't support non-zero flags\n" );return -EINVAL ; } + err =mark_chain_precision (env,BPF_REG_2 ); +if (err) +return err;break ;case BPF_FUNC_for_each_map_elem: err = push_callback_call(env, insn, insn_idx, meta.subprogno,
tools/testing/selftests/bpf/progs/verifier_subprog_precision.c +6 -6
@@ -287,9 +287,9 @@ __msg("17: (b7) r0 = 0") __msg("18: (95) exit") __msg("returning from callee:") __msg("to caller at 9:") -__msg("frame 0: propagating r1,r4") +__msg("frame 0: propagating r1,r3,r4") __msg("mark_precise: frame0: last_idx 9 first_idx 9 subseq_idx -1") -__msg("mark_precise: frame0: regs=r1,r4 stack= before 18: (95) exit") +__msg("mark_precise: frame0: regs=r1,r3,r4 stack= before 18: (95) exit") __msg("from 18 to 9: safe")__naked int callback_result_precise (void ) {
@@ -419,9 +419,9 @@ __msg("to caller at 9:")/* r1, r4 are always precise for bpf_loop(), * r6 was marked before backtracking to callback body. */ -__msg("frame 0: propagating r1,r4,r6") +__msg("frame 0: propagating r1,r3,r4,r6") __msg("mark_precise: frame0: last_idx 9 first_idx 9 subseq_idx -1") -__msg("mark_precise: frame0: regs=r1,r4,r6 stack= before 16: (95) exit") +__msg("mark_precise: frame0: regs=r1,r3,r4,r6 stack= before 16: (95) exit") __msg("mark_precise: frame1: regs= stack= before 15: (b7) r0 = 0") __msg("mark_precise: frame1: regs= stack= before 9: (85) call bpf_loop")__msg ("mark_precise: frame0: parent state regs= stack=:" )
@@ -575,9 +575,9 @@ __msg("to caller at 10:")/* r1, r4 are always precise for bpf_loop(), * fp-8 was marked before backtracking to callback body. */ -__msg("frame 0: propagating r1,r4,fp-8") +__msg("frame 0: propagating r1,r3,r4,fp-8") __msg("mark_precise: frame0: last_idx 10 first_idx 10 subseq_idx -1") -__msg("mark_precise: frame0: regs=r1,r4 stack=-8 before 18: (95) exit") +__msg("mark_precise: frame0: regs=r1,r3,r4 stack=-8 before 18: (95) exit") __msg("mark_precise: frame1: regs= stack= before 17: (b7) r0 = 0") __msg("mark_precise: frame1: regs= stack= before 10: (85) call bpf_loop#181")__msg ("mark_precise: frame0: parent state regs= stack=:" )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 776/869 tracing: Fix subbuf resize races with trace_pipe_raw readers
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vincent Donnefort <[email protected]>
[ Upstream commit dae8dda341d2d9034a90d59e8a7d502e1263813f ]
Concurrent subbuffer resizes may crash trace_pipe_raw readers or leak uninitialized memory to userspace due to stale size values.
Modify ring_buffer_alloc_read_page() to handle the resizing of an existing buffer_data_read_page if necessary and add a new ring_buffer_read_page_size(). This new function enables ring-buffer buffer_data_read_page users to not call the racy ring_buffer_subbuf_size_get(). This makes the spare_size member of ftrace_buffer_info redundant.
Finally, handle buffer_data_read_page/reader_page order discrepancy in ring_buffer_read_page(). On a mismatch simply copy manually the data to the buffer_data_read_page.
--- include/linux/ring_buffer.h | 5 +- kernel/trace/ring_buffer.c | 135 ++++++++++++++++++--------- kernel/trace/ring_buffer_benchmark.c | 6 +- kernel/trace/trace.c | 106 +++++++++------------ 4 files changed, 144 insertions(+), 108 deletions(-)
include/linux/ring_buffer.h +3 -2
@@ -214,14 +214,15 @@ bool ring_buffer_time_stamp_abs(struct trace_buffer *buffer);size_t ring_buffer_nr_dirty_pages (struct trace_buffer *buffer,int cpu);struct buffer_data_read_page ; -struct buffer_data_read_page * -ring_buffer_alloc_read_page (struct trace_buffer *buffer,int cpu); +int ring_buffer_alloc_read_page (struct trace_buffer *buffer,int cpu, +struct buffer_data_read_page **rpage);void ring_buffer_free_read_page (struct trace_buffer *buffer,int cpu,struct buffer_data_read_page *page);int ring_buffer_read_page (struct trace_buffer *buffer,struct buffer_data_read_page *data_page,size_t len,int cpu,int full);void *ring_buffer_read_page_data (struct buffer_data_read_page *page); +unsigned int ring_buffer_read_page_size (struct buffer_data_read_page *rpage);struct trace_seq ;
kernel/trace/ring_buffer.c +92 -43
258 lines not on this page · raw message
kernel/trace/ring_buffer_benchmark.c +3 -3
@@ -104,7 +104,7 @@ static enum event_status read_event(int cpu)static enum event_status read_page (int cpu) { -struct buffer_data_read_page *bpage; +struct buffer_data_read_page *bpage =NULL ;struct ring_buffer_event *event;struct rb_page *rpage;unsigned long commit;
@@ -114,8 +114,8 @@ static enum event_status read_page(int cpu)int inc;int i; - bpage =ring_buffer_alloc_read_page (buffer, cpu); -if (IS_ERR (bpage)) + ret =ring_buffer_alloc_read_page (buffer, cpu, &bpage); +if (ret <0 )return EVENT_DROPPED ; page_size =ring_buffer_subbuf_size_get (buffer);
kernel/trace/trace.c +46 -60
185 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 777/869 bpf: Preserve inner map identity in callback frames
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kumar Kartikeya Dwivedi <[email protected]>
[ Upstream commit b90c5d770dad910fb89e6c1b15052a8a1e8db752 ]
Callback frame constructors initialize map-typed argument registers with __mark_reg_known_zero() and then restore map_ptr. This clears map_uid, which is the only field distinguishing inner maps that share an inner_map_meta template.
When a timer callback invokes bpf_for_each_map_elem() on a second inner map, both the saved first map and the second map value can reach the nested callback as the same template with map_uid zero. bpf_timer_init() then accepts pairing the timer from the second map with the first map.
The runtime records the first map in the timer without taking a reference. Freeing that map does not find the timer stored in the second map, so a later timer callback dereferences the freed map.
Copy map_uid from the same caller register as map_ptr when constructing for-each, timer/workqueue, and task-work callback arguments. The existing identity check can then reject mismatched inner maps while allowing a callback value to be paired with its actual map.
--- kernel/bpf/verifier.c | 6 ++++++ 1 file changed, 6 insertions(+)
kernel/bpf/verifier.c +6 -0
@@ -10203,10 +10203,12 @@ int map_set_for_each_callback_args(struct bpf_verifier_env *env, callee->regs[BPF_REG_2 ].type =PTR_TO_MAP_KEY ;__mark_reg_known_zero (&callee->regs[BPF_REG_2 ]); callee->regs[BPF_REG_2 ].map_ptr = caller->regs[BPF_REG_1 ].map_ptr; + callee->regs[BPF_REG_2 ].map_uid = caller->regs[BPF_REG_1 ].map_uid; callee->regs[BPF_REG_3 ].type =PTR_TO_MAP_VALUE ;__mark_reg_known_zero (&callee->regs[BPF_REG_3 ]); callee->regs[BPF_REG_3 ].map_ptr = caller->regs[BPF_REG_1 ].map_ptr; + callee->regs[BPF_REG_3 ].map_uid = caller->regs[BPF_REG_1 ].map_uid;/* pointer to stack or null */ callee->regs[BPF_REG_4 ] = caller->regs[BPF_REG_3 ];
@@ -10284,6 +10286,7 @@ static int set_timer_callback_state(struct bpf_verifier_env *env, int insn_idx) {struct bpf_map *map_ptr = caller->regs[BPF_REG_1 ].map_ptr; +u32 map_uid = caller->regs[BPF_REG_1 ].map_uid;/* bpf_timer_set_callback(struct bpf_timer *timer, void *callback_fn); * callback_fn(struct bpf_map *map, void *key, void *value);
@@ -10291,14 +10294,17 @@ static int set_timer_callback_state(struct bpf_verifier_env *env, callee->regs[BPF_REG_1 ].type =CONST_PTR_TO_MAP ;__mark_reg_known_zero (&callee->regs[BPF_REG_1 ]); callee->regs[BPF_REG_1 ].map_ptr = map_ptr; + callee->regs[BPF_REG_1 ].map_uid = map_uid; callee->regs[BPF_REG_2 ].type =PTR_TO_MAP_KEY ;__mark_reg_known_zero (&callee->regs[BPF_REG_2 ]); callee->regs[BPF_REG_2 ].map_ptr = map_ptr; + callee->regs[BPF_REG_2 ].map_uid = map_uid; callee->regs[BPF_REG_3 ].type =PTR_TO_MAP_VALUE ;__mark_reg_known_zero (&callee->regs[BPF_REG_3 ]); callee->regs[BPF_REG_3 ].map_ptr = map_ptr; + callee->regs[BPF_REG_3 ].map_uid = map_uid;/* unused */ __mark_reg_not_init (env, &callee->regs[BPF_REG_4 ]);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 778/869 bpf: Mark NULL kptr stores precise
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kumar Kartikeya Dwivedi <[email protected]>
[ Upstream commit ecdc5043794c9184aa8e6c814603899479c46b35 ]
check_map_kptr_access() permits a scalar store into an untrusted kptr field only when the register is known to contain zero. Unlike other verifier checks whose outcome depends on a scalar value, it does not mark that register precise.
A state checkpoint reached with an imprecise zero can therefore prune a second path that reaches the store with an arbitrary nonzero scalar. The program can write attacker-controlled bits into the kptr field and load them back as a PTR_TO_BTF_ID.
Call mark_chain_precision() before accepting a known-zero register. This forces state equivalence to compare its scalar range and makes the verifier visit and reject a path carrying a nonzero value.
--- kernel/bpf/verifier.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
kernel/bpf/verifier.c +9 -2
@@ -5704,8 +5704,15 @@ static int check_map_kptr_access(struct bpf_verifier_env *env, u32 regno, kptr_field->kptr.btf_id, btf_ld_kptr_type(env, kptr_field)); }else if (class ==BPF_STX ) { val_reg =reg_state (env, value_regno); -if (!register_is_null (val_reg) && -map_kptr_match_type (env, kptr_field, val_reg, value_regno)) +if (register_is_null (val_reg)) { +/* +* This store is valid only because the scalar is known to be +* zero. Mark it precise so another scalar cannot be pruned +* against this state. +*/ +return mark_chain_precision (env, value_regno); + } +if (map_kptr_match_type (env, kptr_field, val_reg, value_regno))return -EACCES ; }else if (class ==BPF_ST ) {if (insn->imm) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 779/869 bpf: Keep refcount_acquire nullable for borrowed RCU kptrs
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ning Ding <[email protected]>
[ Upstream commit dc36739e5cc9f60485418a910b42bc95339218d2 ]
bpf_refcount_acquire() is fallible for a borrowed reference because the object may have reached a zero refcount. The verifier therefore keeps KF_RET_NULL on the return value unless the argument is an owning reference.
An RCU-protected load of a local kptr is marked MEM_ALLOC, but it only receives NON_OWN_REF when the pointee contains a graph node. A refcounted object without a graph node consequently looks like an owning reference even though the loaded register has no acquired reference state. If the program drops the last real reference while remaining in the RCU critical section, refcount_inc_not_zero() returns NULL while the verifier treats the result as non-NULL.
Only classify the argument as owning when it is backed by a verifier-tracked reference. This retains the non-NULL return for pointers from bpf_obj_new(), bpf_kptr_xchg(), or an earlier successful acquisition, while requiring a NULL check for borrowed RCU kptrs.
--- kernel/bpf/verifier.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/verifier.c +1 -1
@@ -12732,7 +12732,7 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_kfunc_call_verbose (env,"arg#%d is neither owning or non-owning ref\n" , i);return -EINVAL ; } -if (!type_is_non_owning_ref (reg->type)) +if (!type_is_non_owning_ref (reg->type) && reg->ref_obj_id) meta->arg_owning_ref = true; rec =reg_btf_record (reg);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 780/869 bpf: Dont infer non-NULL from a pointer with an unbounded offset
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eduard Zingerman <[email protected]>
[ Upstream commit 67b529f521a6676cdfc78b91b0217d7eaa84216b ]
reg_not_null() decides that a register holds a non-NULL value by looking at its type alone. For pointer types that allow arithmetic the type only guarantees a non-NULL base, in case of an unbound offset the runtime offset value might still add up to NULL. Consider the followng program:
r6 = bpf_map_lookup_elem(map, &0); /* present */
if (r6 == 0) return 0;
r7 = bpf_map_lookup_elem(map, &1); /* absent, NULL at runtime */
r8 = r7;
r8 -= r6; /* pointer - pointer: unknown scalar, -r6 */
r8 <<= 1;
r8 >>= 1; /* any non-negative offset is accepted by */
/* check_reg_sane_offset_ptr() */
r6 += r8; /* verifier: map value; runtime: zero */
if (r7 != r6) return 0;
*(u8 *)(r7 + 0); /* r7 is inferred non-NULL, both are zero */At runtime both registers are zero, the comparison is true and the load faults with NULL pointer dereference.
Require the offset to be within +-BPF_MAX_VAR_OFF in reg_not_null().
--- kernel/bpf/verifier.c | 7 +++++++ 1 file changed, 7 insertions(+)
kernel/bpf/verifier.c +7 -0
@@ -395,6 +395,13 @@ static bool reg_not_null(const struct bpf_reg_state *reg)if (type_may_be_null (type))return false; +/* +* The types below guarantee a non-NULL base, an unbounded offset can +* still wrap base + offset to zero. +*/ +if (reg->smin_value <= -BPF_MAX_VAR_OFF || reg->smax_value >=BPF_MAX_VAR_OFF ) +return false; + type =base_type (type);return type ==PTR_TO_SOCKET || type == PTR_TO_TCP_SOCK ||
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 781/869 bpf: Reject legacy packet loads from callbacks
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kumar Kartikeya Dwivedi <[email protected]>
[ Upstream commit e7d28823c662128caae63f14e16bd394916c139b ]
check_ld_abs() models a failed BPF_LD_ABS or BPF_LD_IND in a subprogram as an implicit return with R0 set to zero. It calls prepare_func_exit() to explore this synthesized path.
When the load is reached directly from a synchronous callback, prepare_func_exit() enforces the callback return contract and marks R0 precise. R0 is not derived from a real instruction on this path, so precision backtracking reaches the callback call with R0 still requested and triggers the "callback unexpected regs" verifier bug. A privileged program loader can therefore cause a verifier warning and an -EFAULT BPF_PROG_LOAD.
These legacy packet-load instructions are deprecated. Reject them from callbacks rather than complicating their implicit-return model. Check all active frames before constructing the implicit return so nested static subprograms cannot hide the callback context.
Global functions are verified independently with a fresh frame zero, so an active-frame check cannot identify a global function called from a callback. Also check the complete subprogram call graph during stack-depth validation and reject a function containing a legacy load when any caller is a callback. This covers global and static descendants without making has_ld_abs transitive, preserving its per-function BTF return-type check. Ordinary uses outside callbacks remain supported.
--- kernel/bpf/verifier.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
kernel/bpf/verifier.c +19 -0
@@ -6257,6 +6257,17 @@ static int check_max_stack_depth_subprog(struct bpf_verifier_env *env, int idx,if (!priv_stack_supported) subprog[idx].priv_stack_mode =NO_PRIV_STACK ; process_func: +if (subprog[idx].has_ld_abs) { +bool in_cb = subprog[idx].is_cb; + +for (j =0 ; j < frame && !in_cb; j++) + in_cb = subprog[ret_prog[j]].is_cb; +if (in_cb) { +verbose (env,"cannot use BPF_LD_[ABS|IND] within callback\n" ); +return -EINVAL ; + } + } +/* protect against potential stack overflow that might happen when * bpf2bpf calls get combined with tailcalls. Limit the caller's stack * depth for such case down to 256 so that the worst case scenario
@@ -16202,6 +16213,7 @@ static bool may_access_skb(enum bpf_prog_type type)*/ static int check_ld_abs (struct bpf_verifier_env *env,struct bpf_insn *insn) { +struct bpf_verifier_state *state = env->cur_state;struct bpf_reg_state *regs =cur_regs (env);static const int ctx_reg =BPF_REG_6 ;u8 mode =BPF_MODE (insn->code);
@@ -16212,6 +16224,13 @@ static int check_ld_abs(struct bpf_verifier_env *env, struct bpf_insn *insn)return -EINVAL ; } +for (i = state->curframe; i; i--) { +if (state->frame[i]->in_callback_fn) { +verbose (env,"cannot use BPF_LD_[ABS|IND] within callback\n" ); +return -EINVAL ; + } + } +if (!env->ops->gen_ld_abs) {verbose (env,"bpf verifier is misconfigured\n" );return -EINVAL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 782/869 bpf: Check ancestor frames for rbtree callbacks
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kumar Kartikeya Dwivedi <[email protected]>
[ Upstream commit 369f4ce734570bdfedaa4b5ca50e2a3f6a892728 ]
bpf_rbtree_add() invokes its comparator while the caller holds the root lock. The native insertion code retains raw parent and link pointers across the callback, so the verifier prohibits unlocking, consuming tree nodes, or changing RCU state from that callback.
in_rbtree_lock_required_cb() only checks the innermost verifier frame. Static subprogram calls are permitted while holding a spin lock, and such a call pushes a frame without in_callback_fn set. Consequently, all callback restrictions disappear in the nested frame. The subprogram can unlock the tree, remove and drop the node being compared, then relock. Native insertion resumes with the stale parent pointer and links freed memory into the tree.
Walk all active frames for the rbtree callback instead. Benign static subprograms remain permitted, while callback restrictions follow execution into nested frames.
--- kernel/bpf/verifier.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
kernel/bpf/verifier.c +14 -11
@@ -10424,9 +10424,10 @@ static int set_rbtree_add_callback_state(struct bpf_verifier_env *env,static bool is_rbtree_lock_required_kfunc (u32 btf_id); -/* Are we currently verifying the callback for a rbtree helper that must -* be called with lock held? If so, no need to complain about unreleased -* lock +/* +* Are we currently verifying the callback for an rbtree kfunc that must +* be called with a lock held, or one of that callback's subprogs? If so, +* no need to complain about an unreleased lock. */ static bool in_rbtree_lock_required_cb (struct bpf_verifier_env *env) {
@@ -10434,17 +10435,19 @@ static bool in_rbtree_lock_required_cb(struct bpf_verifier_env *env)struct bpf_insn *insn = env->prog->insnsi;struct bpf_func_state *callee;int kfunc_btf_id; +u32 frame; -if (!state->curframe) -return false; - - callee = state->frame[state->curframe]; +for (frame = state->curframe; frame; frame--) { + callee = state->frame[frame]; +if (!callee->in_callback_fn) +continue ; -if (!callee->in_callback_fn) -return false; + kfunc_btf_id = insn[callee->callsite].imm; +if (is_rbtree_lock_required_kfunc (kfunc_btf_id)) +return true; + } - kfunc_btf_id = insn[callee->callsite].imm; -return is_rbtree_lock_required_kfunc (kfunc_btf_id); +return false; } static bool retval_range_within(struct bpf_retval_range range, const struct bpf_reg_state *reg,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 783/869 bpf: dont rewrite bpf_fastcall patterns entered by a jump
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eduard Zingerman <[email protected]>
[ Upstream commit 0b1c83dc3c4401cd7e846548f62e3caf3d06742e ]
mark_fastcall_pattern_for_call() must ensure that matched "spill; call; fill" instruction series is not interrupted by a jump. Otherwise the rewrite applied by bpf_remove_fastcall_spills_fills() is not sound.
Record the instructions targeted by jumps in insn_aux_data[*].jump_target when the CFG is built and use this flag to stop growing a pattern at such an instruction. Jumps to the first spill are fine.
Note that existing insn_aux_data[*].jmp_point field can't be reused, as it marks subprogram return instructions.
--- include/linux/bpf_verifier.h | 2 ++ kernel/bpf/verifier.c | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+)
include/linux/bpf_verifier.h +2 -0
@@ -604,6 +604,8 @@ struct bpf_insn_aux_data {* accepts callback function as a parameter. */ bool calls_callback; +/* true if some jump or call instruction targets this instruction */ +bool jump_target; };#define MAX_USED_MAPS 64/* max number of maps accessed by one eBPF program */
kernel/bpf/verifier.c +20 -0
@@ -3531,6 +3531,16 @@ static bool is_jmp_point(struct bpf_verifier_env *env, int insn_idx)return env->insn_aux_data[insn_idx].jmp_point; } +static void mark_jump_target (struct bpf_verifier_env *env,int idx) +{ + env->insn_aux_data[idx].jump_target = true; +} + +static bool bpf_is_jump_target (struct bpf_verifier_env *env,int insn_idx) +{ +return env->insn_aux_data[insn_idx].jump_target; +} +#define LR_FRAMENO_BITS 3#define LR_SPI_BITS 6#define LR_ENTRY_BITS (LR_SPI_BITS + LR_FRAMENO_BITS + 1)
@@ -16629,6 +16639,7 @@ static int push_insn(int t, int w, int e, struct bpf_verifier_env *env)/* mark branch target for state pruning */ mark_prune_point (env, w);mark_jmp_point (env, w); +mark_jump_target (env, w); }if (insn_state[w] ==0 ) {
@@ -16817,6 +16828,10 @@ static bool is_fastcall_kfunc_call(struct bpf_kfunc_call_arg_meta *meta)* r0 = *(u64 *)(r10 - 8); r0 += r1; * r0 += r1; exit; * exit; +* +* Both uses of the marks assume that a pattern is entered at its first +* spill and thus executes as a unit, hence a pattern is not grown past +* an instruction targeted by a jump. */ static void mark_fastcall_pattern_for_call(struct bpf_verifier_env *env, struct bpf_subprog_info *subprog,
@@ -16871,6 +16886,10 @@ static void mark_fastcall_pattern_for_call(struct bpf_verifier_env *env,for (i =1 , off = lowest_off; i <=ARRAY_SIZE (caller_saved); ++i, off +=BPF_REG_SIZE ) {if (insn_idx - i <0 || insn_idx + i >= env->prog->len)break ; +/* stx/ldx/call must not be a jump targets, a jump to the first stx is fine */ +if (bpf_is_jump_target (env, insn_idx - i +1 ) || +bpf_is_jump_target (env, insn_idx + i)) +break ; stx = &insns[insn_idx - i]; ldx = &insns[insn_idx + i];/* must be a stack spill/fill pair */
@@ -17036,6 +17055,7 @@ static int visit_insn(int t, struct bpf_verifier_env *env)mark_prune_point (env, t + off +1 );mark_jmp_point (env, t + off +1 ); +mark_jump_target (env, t + off +1 );return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 784/869 bpf: zero extend the result of an arena 32-bit cmpxchg
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eduard Zingerman <[email protected]>
[ Upstream commit 4814ed6406f3493bd554ad046da5f7fc04833571 ]
bpf_convert_ctx_accesses() rewrites an atomic on an arena pointer from BPF_STX | BPF_ATOMIC to BPF_STX | BPF_PROBE_ATOMIC, and it runs before bpf_opt_subreg_zext_lo32_rnd_hi32().
That pass emits an explicit zero extension for a 32-bit cmpxchg even when bpf_jit_needs_zext() is false. This is done because on some architectures 32-bit cmpxchg requires explicit zero extension for the dst register. E.g. on x86-64 'lock cmpxchg' does not change the %eax if comparison is successful, while BPF semantics declare that each operation on a 32-bit register zero extends it's upper half.
is_cmpxchg_insn() matches BPF_MODE == BPF_ATOMIC only, so an arena cmpxchg misses said zero extension adjustment. This patch adjusts is_cmpxchg_insn() to match BPF_PROBE_ATOMIC alongside BPF_ATOMIC.
--- kernel/bpf/verifier.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/bpf/verifier.c +6 -1
@@ -578,10 +578,15 @@ static bool helper_multiple_ref_obj_use(enum bpf_func_id func_id,return ref_obj_uses >1 ; } +/* +* Matches BPF_PROBE_ATOMIC too: convert_ctx_accesses() rewrites arena +* atomics before opt_subreg_zext_lo32_rnd_hi32() runs. +*/ static bool is_cmpxchg_insn (const struct bpf_insn *insn) {return BPF_CLASS (insn->code) ==BPF_STX && -BPF_MODE (insn->code) ==BPF_ATOMIC && + (BPF_MODE (insn->code) ==BPF_ATOMIC || +BPF_MODE (insn->code) ==BPF_PROBE_ATOMIC ) && insn->imm ==BPF_CMPXCHG ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 785/869 ASoC: Intel: avs: Refactor and fix init_config access
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cezary Rojewski <[email protected]>
[ Upstream commit 681e91035dc794896a904852040837190e5041f5 ]
Existing code accesses enties found in ->init_configs array through indexes that are part of ->config_ids array. Those two are limited by:
->num_init_configs and ->num_config_ids respectively. Using ID larger or equal to ->num_init_configs leads to out-of-bounds access:
avs_path_module_send_init_configs()
loop:
(...) &acomp->tplg->init_configs[ids[i]] ^ out-of-bounds candidate
Rather than adding another if-statement, refactor the code. There is no need to store the IDs, have a list of pointers to actual config-entries instead. As the verification of ->init_config entries does not differ from verification of other types that are part of the topology.c file, simply reuse the code.
--- sound/soc/intel/avs/path.c | 11 +++----- sound/soc/intel/avs/topology.c | 47 +++++++++++++++++++--------------- sound/soc/intel/avs/topology.h | 4 +-- 3 files changed, 32 insertions(+), 30 deletions(-)
sound/soc/intel/avs/path.c +3 -8
@@ -548,15 +548,10 @@ static int avs_path_module_type_create(struct avs_dev *adev, struct avs_path_modstatic int avs_path_module_send_init_configs (struct avs_dev *adev,struct avs_path_module *mod) { -struct avs_soc_component *acomp; - - acomp =to_avs_soc_component (mod->template->owner->owner->owner->owner->comp); - -u32 num_ids = mod->template->num_config_ids; -u32 *ids = mod->template->config_ids; +struct avs_tplg_module *template = mod->template; -for (int i =0 ; i < num_ids; i++) { -struct avs_tplg_init_config *config = &acomp->tplg->init_configs[ids[i]]; +for (int i =0 ; i < template->num_init_configs; i++) { +struct avs_tplg_init_config *config = template->init_configs[i];size_t len = config->length;void *data = config->data;u32 param = config->param;
sound/soc/intel/avs/topology.c +27 -20
77 lines not on this page · raw message
sound/soc/intel/avs/topology.h +2 -2
@@ -194,8 +194,8 @@ struct avs_tplg_module {u8 domain;struct avs_tplg_modcfg_ext *cfg_ext;u32 ctl_id; -u32 num_config_ids; -u32 *config_ids; +u32 num_init_configs; +struct avs_tplg_init_config **init_configs;struct avs_tplg_pipeline *owner;/* Pipeline modules management. */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 786/869 bpf: Mark syscall helpers as sleepable
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kumar Kartikeya Dwivedi <[email protected]>
[ Upstream commit d05524794240b52fdc3b6c1220dd05505715824d ]
bpf_sys_bpf() executes the bpf(2) syscall body, which can take mutexes, allocate with GFP_KERNEL, and wait for an RCU grace period. bpf_sys_close() reaches close_fd() and filp_close(), which can sleep as well.
Both helpers are limited to BPF_PROG_TYPE_SYSCALL, whose main program is sleepable. That does not make every callback sleepable: a syscall program can register a bpf_timer callback, and the verifier checks that callback in a non-sleepable context while retaining the syscall helper set.
Without .might_sleep on the prototypes, such a callback can invoke bpf_sys_bpf() from hrtimer softirq context and trigger a scheduling-while-atomic failure. bpf_sys_close() is exposed through the same missing context check.
Set .might_sleep on both prototypes so the existing helper-context check rejects them from timer callbacks and other atomic regions. Calls from the sleepable main body remain valid.
--- kernel/bpf/syscall.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/bpf/syscall.c +2 -0
@@ -5899,6 +5899,7 @@ EXPORT_SYMBOL_NS(kern_sys_bpf, BPF_INTERNAL);static const struct bpf_func_proto bpf_sys_bpf_proto = { .func = bpf_sys_bpf, .gpl_only = false, + .might_sleep = true, .ret_type =RET_INTEGER , .arg1_type =ARG_ANYTHING , .arg2_type =ARG_PTR_TO_MEM |MEM_RDONLY ,
@@ -5924,6 +5925,7 @@ BPF_CALL_1(bpf_sys_close, u32, fd)static const struct bpf_func_proto bpf_sys_close_proto = { .func = bpf_sys_close, .gpl_only = false, + .might_sleep = true, .ret_type =RET_INTEGER , .arg1_type =ARG_ANYTHING , };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 787/869 bpf: Mark signal tracepoint siginfo arguments as scalar
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kumar Kartikeya Dwivedi <[email protected]>
[ Upstream commit 77515ab12e4983e6416f8c35039a3f0c0822ac70 ]
The signal_generate and signal_deliver tracepoints declare their info argument as a struct kernel_siginfo pointer. btf_ctx_access() therefore treats it as a trusted pointer for tp_btf programs.
Signal delivery also uses SEND_SIG_NOINFO and SEND_SIG_PRIV as special values for this argument. Those values are zero and one respectively, and are not pointers. A tp_btf program can currently dereference either value and fault the kernel. In particular, signal_generate can run from timer interrupt context, turning the fault into a kernel panic.
Record both tracepoints in raw_tp_null_args[] and mark argument one as a non-pointer. This preserves scalar access to the cookie while rejecting direct and helper-mediated pointer use. Merely marking it nullable would not suffice because SEND_SIG_PRIV is nonzero.
--- kernel/bpf/btf.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/bpf/btf.c +3 -0
@@ -6558,6 +6558,9 @@ static const struct bpf_raw_tp_null_args raw_tp_null_args[] = {/* rxrpc */ { "rxrpc_recvdata", 0x1 }, { "rxrpc_resend", 0x10 }, +/* signal */ + { "signal_generate", 0x20 }, + { "signal_deliver", 0x20 },/* skb */ {"kfree_skb", 0x1000},/* sunrpc */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 788/869 erofs: disable LZ4 rolling decompression for now
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gao Xiang <[email protected]>
[ Upstream commit 82e664cf1219c459c33aae931b222cf951af9cb7 ]
LZ4 rolling decompression [1] was introduced to reduce the memory footprint of temporary pages:
For many cases, it is needed for users to read small data within a compressed extent (pcluster), either due to random small read, or since uptodate folios (typically order-0) cannot be reused for decompression again since decompression algorithm refills already-uptodate folios.
Rolling decompression works because LZ4 is LZ77-based and only refers to the most recent 64 KiB of decompressed data, so in theory only a bounded rolling window of temporary pages is needed when decompressing.
It can save a lot of temporary memory, e.g.
601,960-byte data can be compressed into a 256k LZ4 compressed extent, which means it needs 146 extra pages per request in the worst case if rolling decompression is disabled.
However, the upstream LZ4 implementation is not under EROFS' control:
For example, the literal copy memmove() may still **copy long literals backward** on x86 based on the address comparison even when the source and destination ranges do not overlap (IOWs, inline decompression doesn't need to be considered here). That breaks the rolling assumption and makes the optimization broken.
Disable it for now to make sure the data correctness first since EROFS is used everywhere now: The rolling window approach can be revived once we either ensure that the official LZ4 code always copies forward for non-overlapping ranges or maintain our own LZ4 implementation in EROFS.
The main impact is a higher runtime memory footprint; However, recent commit 0f6273ab4637 ("erofs: add a reserved buffer pool for lz4 decompression") helps mitigate this when enabled but it's still not perfect.
[1] https://www.usenix.org/conference/atc19/presentation/gao
§ 3.3 Decompression
--- fs/erofs/decompressor.c | 60 +++++++++-------------------------------- fs/erofs/internal.h | 6 +---- fs/erofs/zdata.c | 18 +++---------- 3 files changed, 16 insertions(+), 68 deletions(-)
fs/erofs/decompressor.c +12 -48
@@ -7,11 +7,6 @@#include "compress.h" #include <linux/lz4.h> -#ifndef LZ4_DISTANCE_MAX /* history window size */ -#define LZ4_DISTANCE_MAX 65535/* set to maximum value by default */ -#endif - -#define LZ4_MAX_DISTANCE_PAGES (DIV_ROUND_UP(LZ4_DISTANCE_MAX, PAGE_SIZE) + 1)#ifndef LZ4_DECOMPRESS_INPLACE_MARGIN #define LZ4_DECOMPRESS_INPLACE_MARGIN (srcsize) (((srcsize) >> 8) + 32)#endif
@@ -21,15 +16,12 @@ static int z_erofs_load_lz4_config(struct super_block *sb, {struct erofs_sb_info *sbi =EROFS_SB (sb);struct z_erofs_lz4_cfgs *lz4 = data; -u16 distance;if (lz4) {if (size <sizeof (struct z_erofs_lz4_cfgs )) {erofs_err (sb,"invalid lz4 cfgs, size=%u" , size);return -EINVAL ; } - distance =le16_to_cpu (lz4->max_distance); - sbi->lz4.max_pclusterblks =le16_to_cpu (lz4->max_pclusterblks);if (!sbi->lz4.max_pclusterblks) { sbi->lz4.max_pclusterblks =1 ;/* reserved case */
@@ -40,48 +32,27 @@ static int z_erofs_load_lz4_config(struct super_block *sb,return -EINVAL ; } }else { - distance =le16_to_cpu (dsb->u1.lz4_max_distance); sbi->lz4.max_pclusterblks =1 ; } - - sbi->lz4.max_distance_pages = distance ? -DIV_ROUND_UP (distance,PAGE_SIZE ) +1 : -LZ4_MAX_DISTANCE_PAGES ;return z_erofs_gbuf_growsize (sbi->lz4.max_pclusterblks); }/* -* Fill all gaps with bounce pages if it's a sparse page list. Also check if -* all physical pages are consecutive, which can be seen for moderate CR. +* Fill all gaps with bounce pages if it's a sparse page list (for example some +* folios are already uptodate and thus can be mapped into userspace). Also +* check if pages are physically consecutive, which can be seen for moderate CR. */ -static int z_erofs_lz4_prepare_dstpages (struct z_erofs_decompress_req *rq, -struct page **pagepool) +static int z_erofs_oneshot_prepare_dstpages (struct z_erofs_decompress_req *rq, +struct page **pagepool) { -struct page *availables[LZ4_MAX_DISTANCE_PAGES ] = {NULL }; -unsigned long bounced[DIV_ROUND_UP (LZ4_MAX_DISTANCE_PAGES , -BITS_PER_LONG )] = {0 }; -unsigned int lz4_max_distance_pages = -EROFS_SB (rq->sb)->lz4.max_distance_pages;void *kaddr =NULL ; -unsigned int i, j, top; - - top =0 ; -for (i = j =0 ; i < rq->outpages; ++i, ++j) { -struct page *const page = rq->out[i]; -struct page *victim; - -if (j >= lz4_max_distance_pages) - j =0 ; +unsigned int i; -/* 'valid' bounced can only be tested after a complete round */ -if (!rq->fillgaps &&test_bit (j, bounced)) { -DBG_BUGON (i < lz4_max_distance_pages); -DBG_BUGON (top >= lz4_max_distance_pages); - availables[top++] = rq->out[i - lz4_max_distance_pages]; - } +for (i =0 ; i < rq->outpages; ++i) { +struct page *page, *victim; + page = rq->out[i];if (page) { -__clear_bit (j, bounced);if (!PageHighMem (page)) {if (!i) { kaddr =page_address (page);
@@ -93,21 +64,14 @@ static int z_erofs_lz4_prepare_dstpages(struct z_erofs_decompress_req *rq,continue ; } } - kaddr =NULL ; -continue ; - } - kaddr =NULL ; -__set_bit (j, bounced); - -if (top) { - victim = availables[--top]; }else { victim =__erofs_allocpage (pagepool, rq->gfp, true);if (!victim)return -ENOMEM ;set_page_private (victim,Z_EROFS_SHORTLIVED_PAGE ); + rq->out[i] = victim; } - rq->out[i] = victim; + kaddr =NULL ; }return kaddr ?1 :0 ; }
@@ -279,7 +243,7 @@ static int z_erofs_lz4_decompress(struct z_erofs_decompress_req *rq, dst_maptype =0 ; }else {/* general decoding path which can be used for all cases */ - ret =z_erofs_lz4_prepare_dstpages (rq, pagepool); + ret =z_erofs_oneshot_prepare_dstpages (rq, pagepool);if (ret <0 )return ret;if (ret >0 ) {
fs/erofs/internal.h +1 -5
@@ -77,12 +77,8 @@ struct erofs_dev_context {bool flatdev; }; -/* all filesystem-wide lz4 configurations */ struct erofs_sb_lz4_info { -/* # of pages needed for EROFS lz4 rolling decompression */ -u16 max_distance_pages; -/* maximum possible blocks for pclusters in the filesystem */ -u16 max_pclusterblks; +u16 max_pclusterblks;/* maximum physical blocks for LZ4 pclusters */ };struct erofs_domain {
fs/erofs/zdata.c +3 -15
@@ -1237,7 +1237,7 @@ static int z_erofs_decompress_pcluster(struct z_erofs_backend *be, bool eio)unsigned int pclusterpages =z_erofs_pclusterpages (pcl);const struct z_erofs_decompressor *decomp = z_erofs_decomp[pcl->algorithmformat]; -int i, j, jtop, err2, err = eio ? -EIO :0 ; +int i, err2, err = eio ? -EIO :0 ;struct page *page;bool overlapped;bool try_free = true;
@@ -1314,7 +1314,6 @@ static int z_erofs_decompress_pcluster(struct z_erofs_backend *be, bool eio) be->compressed_pages >= be->onstack_pages + Z_EROFS_ONSTACK_PAGES)kvfree (be->compressed_pages); - jtop =0 ;z_erofs_fill_other_copies (be, err);for (i =0 ; i < be->nr_pages; ++i) { page = be->decompressed_pages[i];
@@ -1322,22 +1321,11 @@ static int z_erofs_decompress_pcluster(struct z_erofs_backend *be, bool eio)continue ;DBG_BUGON (z_erofs_page_is_invalidated (page)); -if (!z_erofs_is_shortlived_page (page)) { +if (!z_erofs_is_shortlived_page (page))erofs_onlinefolio_end (page_folio (page), err, true); -continue ; - } -if (pcl->algorithmformat !=Z_EROFS_COMPRESSION_LZ4 ) { +else erofs_pagepool_add (be->pagepool, page); -continue ; - } -for (j =0 ; j < jtop && be->decompressed_pages[j] != page; ++j) - ; -if (j >= jtop)/* this bounce page is newly detected */ - be->decompressed_pages[jtop++] = page; } -while (jtop) -erofs_pagepool_add (be->pagepool, - be->decompressed_pages[--jtop]);if (be->decompressed_pages != be->onstack_pages)kvfree (be->decompressed_pages);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 789/869 net: rename netns_local to netns_immutable
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicolas Dichtel <[email protected]>
[ Upstream commit 0c493da86374dffff7505e67289ad75b21f5b301 ]
The name 'netns_local' is confusing. A following commit will export it via netlink, so let's use a more explicit name.
Adapted to the older tree: the net_cachelines documentation is in the older format and only the netns_local row is renamed there, the ieee802154 switch_netns hunk keeps the existing WARN_ON condition, and the missed ip6_vti user of the flag is converted as well.
Stable-dep-of: debac3a20dec ("net: Remove conflicting altnames for dying netns in __dev_change_net_namespace().")
--- Documentation/networking/net_cachelines/net_device.rst | 2 +- Documentation/networking/switchdev.rst | 2 +- drivers/net/amt.c | 2 +- drivers/net/bonding/bond_main.c | 2 +- drivers/net/ethernet/adi/adin1110.c | 2 +- drivers/net/ethernet/marvell/prestera/prestera_main.c | 2 +- drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 4 ++-- drivers/net/ethernet/mellanox/mlx5/core/en_rep.c | 2 +- drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 2 +- drivers/net/ethernet/rocker/rocker_main.c | 2 +- drivers/net/ethernet/ti/cpsw_new.c | 2 +- drivers/net/loopback.c | 2 +- drivers/net/net_failover.c | 2 +- drivers/net/team/team_core.c | 2 +- drivers/net/vrf.c | 2 +- include/linux/netdevice.h | 4 ++-- net/batman-adv/soft-interface.c | 2 +- net/bridge/br_device.c | 2 +- net/core/dev.c | 4 ++-- net/hsr/hsr_device.c | 2 +- net/ieee802154/6lowpan/core.c | 2 +- net/ieee802154/core.c | 10 +++++----- net/ipv4/ip_tunnel.c | 2 +- net/ipv4/ipmr.c | 2 +- net/ipv6/ip6_gre.c | 2 +- net/ipv6/ip6_tunnel.c | 2 +- net/ipv6/ip6_vti.c | 2 +- net/ipv6/ip6mr.c | 2 +- net/ipv6/sit.c | 2 +- net/openvswitch/vport-internal_dev.c | 2 +- net/wireless/core.c | 10 +++++----- tools/testing/selftests/net/forwarding/README | 2 +- 32 files changed, 43 insertions(+), 43 deletions(-)
Documentation/networking/net_cachelines/net_device.rst +1 -1
@@ -166,7 +166,7 @@ unsigned:1 wol_enabled unsigned:1 threaded - - napi_poll(napi_enable,dev_set_threaded) unsigned_long:1 see_all_hwtstamp_requests unsigned_long:1 change_proto_down -unsigned_long:1 netns_local +unsigned_long:1 netns_immutable unsigned_long:1 fcoe_mtu struct_list_head net_notifier_list struct_macsec_ops* macsec_ops
Documentation/networking/switchdev.rst +1 -1
@@ -137,7 +137,7 @@ would be sub-port 0 on port 1 on switch 1. Port Features ^^^^^^^^^^^^^ -dev->netns_local +dev->netns_immutable If the switchdev driver (and device) only supports offloading of the default network namespace (netns), the driver should set this private flag to prevent
drivers/net/amt.c +1 -1
@@ -3126,7 +3126,7 @@ static void amt_link_setup(struct net_device *dev) dev->addr_len =0 ; dev->priv_flags |=IFF_NO_QUEUE ; dev->lltx = true; - dev->netns_local = true; + dev->netns_immutable = true; dev->features |=NETIF_F_GSO_SOFTWARE ; dev->hw_features |=NETIF_F_SG |NETIF_F_HW_CSUM ; dev->hw_features |=NETIF_F_FRAGLIST |NETIF_F_RXCSUM ;
drivers/net/bonding/bond_main.c +1 -1
@@ -6088,7 +6088,7 @@ void bond_setup(struct net_device *bond_dev) bond_dev->lltx = true;/* Don't allow bond devices to change network namespaces. */ - bond_dev->netns_local = true; + bond_dev->netns_immutable = true;/* By default, we declare the bond to be fully * VLAN hardware accelerated capable. Special
drivers/net/ethernet/adi/adin1110.c +1 -1
@@ -1602,7 +1602,7 @@ static int adin1110_probe_netdevs(struct adin1110_priv *priv) netdev->netdev_ops = &adin1110_netdev_ops; netdev->ethtool_ops = &adin1110_ethtool_ops; netdev->priv_flags |=IFF_UNICAST_FLT ; - netdev->netns_local = true; + netdev->netns_immutable = true; port_priv->phydev =get_phy_device (priv->mii_bus, i +1 , false);if (IS_ERR (port_priv->phydev)) {
drivers/net/ethernet/marvell/prestera/prestera_main.c +1 -1
@@ -634,7 +634,7 @@ static int prestera_port_create(struct prestera_switch *sw, u32 id) goto err_dl_port_register; dev->features |=NETIF_F_HW_TC ; - dev->netns_local = true; + dev->netns_immutable = true; dev->netdev_ops = &prestera_netdev_ops; dev->ethtool_ops = &prestera_ethtool_ops;SET_NETDEV_DEV (dev, sw->dev->dev);
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +2 -2
@@ -4401,9 +4401,9 @@ static netdev_features_t mlx5e_fix_features(struct net_device *netdev,if (mlx5e_is_uplink_rep (priv)) { features =mlx5e_fix_uplink_rep_features (netdev, features); - netdev->netns_local = true; + netdev->netns_immutable = true; }else { - netdev->netns_local = false; + netdev->netns_immutable = false; }mutex_unlock (&priv->state_lock);
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c +1 -1
@@ -903,7 +903,7 @@ static void mlx5e_build_rep_netdev(struct net_device *netdev, netdev->features |= netdev->hw_features; - netdev->netns_local = true; + netdev->netns_immutable = true; } static int mlx5e_init_rep(struct mlx5_core_dev *mdev,
drivers/net/ethernet/mellanox/mlxsw/spectrum.c +1 -1
@@ -1680,7 +1680,7 @@ static int mlxsw_sp_port_create(struct mlxsw_sp *mlxsw_sp, u16 local_port,NETIF_F_HW_TC ; dev->hw_features |=NETIF_F_HW_TC |NETIF_F_LOOPBACK ; dev->lltx = true; - dev->netns_local = true; + dev->netns_immutable = true; dev->min_mtu =ETH_MIN_MTU ; dev->max_mtu =MLXSW_PORT_MAX_MTU -MLXSW_PORT_ETH_FRAME_HDR ;
drivers/net/ethernet/rocker/rocker_main.c +1 -1
@@ -2575,7 +2575,7 @@ static int rocker_probe_port(struct rocker *rocker, unsigned int port_number)rocker_carrier_init (rocker_port); dev->features |=NETIF_F_SG ; - dev->netns_local = true; + dev->netns_immutable = true;/* MTU range: 68 - 9000 */ dev->min_mtu =ROCKER_PORT_MIN_MTU ;
drivers/net/ethernet/ti/cpsw_new.c +1 -1
@@ -1427,7 +1427,7 @@ static int cpsw_create_ports(struct cpsw_common *cpsw) ndev->features |=NETIF_F_HW_VLAN_CTAG_FILTER |NETIF_F_HW_VLAN_CTAG_RX |NETIF_F_HW_TC ; - ndev->netns_local = true; + ndev->netns_immutable = true; ndev->xdp_features =NETDEV_XDP_ACT_BASIC | NETDEV_XDP_ACT_REDIRECT |
drivers/net/loopback.c +1 -1
@@ -172,7 +172,7 @@ static void gen_lo_setup(struct net_device *dev, dev->flags =IFF_LOOPBACK ; dev->priv_flags |=IFF_LIVE_ADDR_CHANGE |IFF_NO_QUEUE ; dev->lltx = true; - dev->netns_local = true; + dev->netns_immutable = true;netif_keep_dst (dev); dev->hw_features =NETIF_F_GSO_SOFTWARE ; dev->features =NETIF_F_SG |NETIF_F_FRAGLIST
drivers/net/net_failover.c +1 -1
@@ -734,7 +734,7 @@ struct failover *net_failover_create(struct net_device *standby_dev) failover_dev->lltx = true;/* Don't allow failover devices to change network namespaces. */ - failover_dev->netns_local = true; + failover_dev->netns_immutable = true; failover_dev->hw_features =FAILOVER_VLAN_FEATURES | NETIF_F_HW_VLAN_CTAG_TX |
drivers/net/team/team_core.c +1 -1
@@ -2305,7 +2305,7 @@ static void team_setup(struct net_device *dev) dev->lltx = true;/* Don't allow team devices to change network namespaces. */ - dev->netns_local = true; + dev->netns_immutable = true; dev->features |=NETIF_F_GRO ;
drivers/net/vrf.c +1 -1
@@ -1624,7 +1624,7 @@ static void vrf_setup(struct net_device *dev) dev->lltx = true;/* don't allow vrf devices to change network namespaces. */ - dev->netns_local = true; + dev->netns_immutable = true;/* does not make sense for a VLAN to be added to a vrf device */ dev->features |=NETIF_F_VLAN_CHALLENGED ;
include/linux/netdevice.h +2 -2
@@ -1976,7 +1976,7 @@ enum netdev_reg_state {* regardless of source, even if those aren't * HWTSTAMP_SOURCE_NETDEV * @change_proto_down: device supports setting carrier via IFLA_PROTO_DOWN -* @netns_local: interface can't change network namespaces +* @netns_immutable: interface can't change network namespaces * @fcoe_mtu: device supports maximum FCoE MTU, 2158 bytes * * @net_notifier_list: List of per-net netdev notifier block
@@ -2373,7 +2373,7 @@ struct net_device {/* priv_flags_slow, ungrouped to save space */ unsigned long see_all_hwtstamp_requests:1; unsigned long change_proto_down:1; - unsigned long netns_local:1; + unsigned long netns_immutable:1; unsigned long fcoe_mtu:1;struct list_head net_notifier_list;
net/batman-adv/soft-interface.c +1 -1
@@ -1031,7 +1031,7 @@ static void batadv_softif_init_early(struct net_device *dev) dev->features |=NETIF_F_HW_VLAN_CTAG_FILTER ; dev->priv_flags |=IFF_NO_QUEUE ; dev->lltx = true; - dev->netns_local = true; + dev->netns_immutable = true;/* can't call min_mtu, because the needed variables * have not been initialized yet
net/bridge/br_device.c +1 -1
@@ -488,7 +488,7 @@ void br_dev_setup(struct net_device *dev)SET_NETDEV_DEVTYPE (dev, &br_type); dev->priv_flags =IFF_EBRIDGE |IFF_NO_QUEUE ; dev->lltx = true; - dev->netns_local = true; + dev->netns_immutable = true; dev->features =COMMON_FEATURES |NETIF_F_HW_VLAN_CTAG_TX |NETIF_F_HW_VLAN_STAG_TX ;
net/core/dev.c +2 -2
@@ -11749,7 +11749,7 @@ int __dev_change_net_namespace(struct net_device *dev, struct net *net,/* Don't allow namespace local devices to be moved. */ err = -EINVAL ; -if (dev->netns_local) +if (dev->netns_immutable) goto out;/* Ensure the device has been registered */
@@ -12219,7 +12219,7 @@ static void __net_exit default_device_exit_net(struct net *net)char fb_name[IFNAMSIZ ];/* Ignore unmoveable devices (i.e. loopback) */ -if (dev->netns_local) +if (dev->netns_immutable)continue ;/* Leave virtual devices for the generic cleanup */
net/hsr/hsr_device.c +1 -1
@@ -653,7 +653,7 @@ void hsr_dev_setup(struct net_device *dev)/* Not sure about this. Taken from bridge code. netdevice.h says * it means "Does not change network namespaces". */ - dev->netns_local = true; + dev->netns_immutable = true; dev->needs_free_netdev = true;
net/ieee802154/6lowpan/core.c +1 -1
@@ -116,7 +116,7 @@ static void lowpan_setup(struct net_device *ldev) ldev->netdev_ops = &lowpan_netdev_ops; ldev->header_ops = &lowpan_header_ops; ldev->needs_free_netdev = true; - ldev->netns_local = true; + ldev->netns_immutable = true; } static int lowpan_validate(struct nlattr *tb[], struct nlattr *data[],
net/ieee802154/core.c +5 -5
@@ -226,11 +226,11 @@ int cfg802154_switch_netns(struct cfg802154_registered_device *rdev,list_for_each_entry (wpan_dev, &rdev->wpan_dev_list, list) {if (!wpan_dev->netdev)continue ; - wpan_dev->netdev->netns_local = false; + wpan_dev->netdev->netns_immutable = false; err =dev_change_net_namespace (wpan_dev->netdev, net,"wpan%d" );if (err)break ; - wpan_dev->netdev->netns_local = true; + wpan_dev->netdev->netns_immutable = true; }if (err) {
@@ -242,11 +242,11 @@ int cfg802154_switch_netns(struct cfg802154_registered_device *rdev, list) {if (!wpan_dev->netdev)continue ; - wpan_dev->netdev->netns_local = false; + wpan_dev->netdev->netns_immutable = false; err =dev_change_net_namespace (wpan_dev->netdev, net,"wpan%d" );WARN_ON (err && err != -ENOMEM ); - wpan_dev->netdev->netns_local = true; + wpan_dev->netdev->netns_immutable = true; }return err;
@@ -291,7 +291,7 @@ static int cfg802154_netdev_notifier_call(struct notifier_block *nb,switch (state) {/* TODO NETDEV_DEVTYPE */ case NETDEV_REGISTER : - dev->netns_local = true; + dev->netns_immutable = true; wpan_dev->identifier = ++rdev->wpan_dev_id;list_add_rcu (&wpan_dev->list, &rdev->wpan_dev_list); rdev->devlist_generation++;
net/ipv4/ip_tunnel.c +1 -1
@@ -1148,7 +1148,7 @@ int ip_tunnel_init_net(struct net *net, unsigned int ip_tnl_net_id,* Allowing to move it to another netns is clearly unsafe. */ if (!IS_ERR (itn->fb_tunnel_dev)) { - itn->fb_tunnel_dev->netns_local = true; + itn->fb_tunnel_dev->netns_immutable = true; itn->fb_tunnel_dev->mtu =ip_tunnel_bind_dev (itn->fb_tunnel_dev);ip_tunnel_add (itn,netdev_priv (itn->fb_tunnel_dev)); itn->type = itn->fb_tunnel_dev->type;
net/ipv4/ipmr.c +1 -1
@@ -549,7 +549,7 @@ static void reg_vif_setup(struct net_device *dev) dev->flags =IFF_NOARP ; dev->netdev_ops = ®_vif_netdev_ops; dev->needs_free_netdev = true; - dev->netns_local = true; + dev->netns_immutable = true; }static struct net_device *ipmr_reg_vif (struct net *net,struct mr_table *mrt)
net/ipv6/ip6_gre.c +1 -1
@@ -1624,7 +1624,7 @@ static int __net_init ip6gre_init_net(struct net *net)/* FB netdevice is special: we have one, and only one per netns. * Allowing to move it to another netns is clearly unsafe. */ - ign->fb_tunnel_dev->netns_local = true; + ign->fb_tunnel_dev->netns_immutable = true;ip6gre_fb_tunnel_init (ign->fb_tunnel_dev); ign->fb_tunnel_dev->rtnl_link_ops = &ip6gre_link_ops;
net/ipv6/ip6_tunnel.c +1 -1
@@ -2264,7 +2264,7 @@ static int __net_init ip6_tnl_init_net(struct net *net)/* FB netdevice is special: we have one, and only one per netns. * Allowing to move it to another netns is clearly unsafe. */ - ip6n->fb_tnl_dev->netns_local = true; + ip6n->fb_tnl_dev->netns_immutable = true; err =ip6_fb_tnl_dev_init (ip6n->fb_tnl_dev);if (err <0 )
net/ipv6/ip6_vti.c +1 -1
@@ -1162,7 +1162,7 @@ static int __net_init vti6_init_net(struct net *net) goto err_alloc_dev;dev_net_set (ip6n->fb_tnl_dev, net); ip6n->fb_tnl_dev->rtnl_link_ops = &vti6_link_ops; - ip6n->fb_tnl_dev->netns_local = true; + ip6n->fb_tnl_dev->netns_immutable = true; err =vti6_fb_tnl_dev_init (ip6n->fb_tnl_dev);if (err <0 )
net/ipv6/ip6mr.c +1 -1
@@ -654,7 +654,7 @@ static void reg_vif_setup(struct net_device *dev) dev->flags =IFF_NOARP ; dev->netdev_ops = ®_vif_netdev_ops; dev->needs_free_netdev = true; - dev->netns_local = true; + dev->netns_immutable = true; }static struct net_device *ip6mr_reg_vif (struct net *net,struct mr_table *mrt)
net/ipv6/sit.c +1 -1
@@ -1861,7 +1861,7 @@ static int __net_init sit_init_net(struct net *net)/* FB netdevice is special: we have one, and only one per netns. * Allowing to move it to another netns is clearly unsafe. */ - sitn->fb_tunnel_dev->netns_local = true; + sitn->fb_tunnel_dev->netns_immutable = true; t =netdev_priv (sitn->fb_tunnel_dev); t->net = net;
net/openvswitch/vport-internal_dev.c +1 -1
@@ -149,7 +149,7 @@ static struct vport *internal_dev_create(const struct vport_parms *parms)/* Restrict bridge port to current netns. */ if (vport->port_no ==OVSP_LOCAL ) - vport->dev->netns_local = true; + vport->dev->netns_immutable = true;rtnl_lock (); err =register_netdevice (vport->dev);
net/wireless/core.c +5 -5
@@ -165,11 +165,11 @@ int cfg80211_switch_netns(struct cfg80211_registered_device *rdev,list_for_each_entry (wdev, &rdev->wiphy.wdev_list, list) {if (!wdev->netdev)continue ; - wdev->netdev->netns_local = false; + wdev->netdev->netns_immutable = false; err =dev_change_net_namespace (wdev->netdev, net,"wlan%d" );if (err)break ; - wdev->netdev->netns_local = true; + wdev->netdev->netns_immutable = true; }if (err) {
@@ -181,11 +181,11 @@ int cfg80211_switch_netns(struct cfg80211_registered_device *rdev, list) {if (!wdev->netdev)continue ; - wdev->netdev->netns_local = false; + wdev->netdev->netns_immutable = false; err =dev_change_net_namespace (wdev->netdev, net,"wlan%d" );WARN_ON (err); - wdev->netdev->netns_local = true; + wdev->netdev->netns_immutable = true; }return err;
@@ -1549,7 +1549,7 @@ static int cfg80211_netdev_notifier_call(struct notifier_block *nb,SET_NETDEV_DEVTYPE (dev, &wiphy_type); wdev->netdev = dev;/* can only change netns with wiphy */ - dev->netns_local = true; + dev->netns_immutable = true;cfg80211_init_wdev (wdev);break ;
tools/testing/selftests/net/forwarding/README +1 -1
@@ -6,7 +6,7 @@ to easily create and test complex environments. Unfortunately, these namespaces can not be used with actual switching ASICs, as their ports can not be migrated to other network namespaces -(dev->netns_local) and most of them probably do not support the +(dev->netns_immutable) and most of them probably do not support the L1-separation provided by namespaces. However, a similar kind of flexibility can be achieved by using VRFs and
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 790/869 net: plumb extack in __dev_change_net_namespace()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicolas Dichtel <[email protected]>
[ Upstream commit 12b6f7069ba5aa160f3332916408b34ae8e0b0f6 ]
It could be hard to understand why the netlink command fails. For example, if dev->netns_immutable is set, the error is "Invalid argument".
Stable-dep-of: debac3a20dec ("net: Remove conflicting altnames for dying netns in __dev_change_net_namespace().")
--- include/linux/netdevice.h | 5 +++-- net/core/dev.c | 43 +++++++++++++++++++++++++++++++-------- net/core/rtnetlink.c | 2 +- 3 files changed, 38 insertions(+), 12 deletions(-)
include/linux/netdevice.h +3 -2
@@ -4022,12 +4022,13 @@ int dev_change_flags(struct net_device *dev, unsigned int flags,int dev_set_alias (struct net_device *,const char *,size_t );int dev_get_alias (const struct net_device *,char *,size_t );int __dev_change_net_namespace (struct net_device *dev,struct net *net, -const char *pat,int new_ifindex); +const char *pat,int new_ifindex, +struct netlink_ext_ack *extack);static inline int dev_change_net_namespace (struct net_device *dev,struct net *net,const char *pat) { -return __dev_change_net_namespace (dev, net, pat,0 ); +return __dev_change_net_namespace (dev, net, pat,0 ,NULL ); }int __dev_set_mtu (struct net_device *,int );int dev_set_mtu (struct net_device *,int );
net/core/dev.c +34 -9
89 lines not on this page · raw message
net/core/rtnetlink.c +1 -1
@@ -2932,7 +2932,7 @@ static int do_setlink(const struct sk_buff *skb,else new_ifindex =0 ; - err =__dev_change_net_namespace (dev, net, pat, new_ifindex); + err =__dev_change_net_namespace (dev, net, pat, new_ifindex, extack);put_net (net);if (err) goto errout;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 791/869 net: Remove conflicting altnames for dying netns in __dev_change_net_namespace().
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
[ Upstream commit debac3a20dec524a59625cf10fa2f18571127824 ]
syzbot reported the warning in cfg80211_pernet_exit(). [0]
The repro does the following:
1. create two device in root netns and non-root netns
2. assign the same altname for the two devices
3. remove the non-root netns
Since commit 7663d522099e ("net: check for altname conflicts when changing netdev's netns"), cfg80211_switch_netns() and cfg802154_switch_netns() fail if init_net has a device with the conflicting altname.
default_device_exit_net() had the same issue and commit d09486a04f5d ("net: fix removing a namespace with conflicting altnames") fixed it.
cfg80211_pernet_exit() and cfg802154_pernet_exit() need the same fix.
Let's generalise the fix by removing conflicting altnames for dying netns in __dev_change_net_namespace().
[0]:cfg80211_switch_netns(rdev, &init_net)
WARNING: net/wireless/core.c:1871 at cfg80211_pernet_exit+0xd5/0x120 net/wireless/core.c:1871, CPU#1: kworker/u8:9/1160 Modules linked in: CPU: 1 UID: 0 PID: 1160 Comm: kworker/u8:9 Not tainted syzkaller #0 PREEMPT(full) Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/24/2026 Workqueue: netns cleanup_net RIP: 0010:cfg80211_pernet_exit+0xd5/0x120 net/wireless/core.c:1871 Code: e8 03 42 80 3c 20 00 74 08 4c 89 f7 e8 b4 ef 0e f7 4d 8b 36 49 81 fe 20 10 4a 90 74 12 e8 03 3d 9f f6 eb 85 e8 fc 3c 9f f6 90 <0f> 0b 90 eb cc e8 f1 3c 9f f6 eb 05 e8 ea 3c 9f f6 5b 41 5c 41 5e RSP: 0018:ffffc900057a78f0 EFLAGS: 00010293 RAX: ffffffff8b287154 RBX: ffff88807ba72780 RCX: ffff8880213e8000 RDX: 0000000000000000 RSI: 00000000ffffffef RDI: 0000000000000000 RBP: 00000000ffffffef R08: ffffffff9024cc67 R09: 0000000000000000 R10: fffff52000af4eb0 R11: fffffbfff204998d R12: dffffc0000000000 R13: ffffffff904a1080 R14: ffff888144ed0008 R15: ffff888144ed0e20 FS: 0000000000000000(0000) GS:ffff888124de6000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00005642de0a8a70 CR3: 000000007a40c000 CR4: 00000000003526f0 Call Trace: <TASK> ops_exit_list net/core/net_namespace.c:200 [inline] ops_undo_list+0x43d/0x8d0 net/core/net_namespace.c:253 cleanup_net+0x572/0x810 net/core/net_namespace.c:706 process_one_work kernel/workqueue.c:3387 [inline] process_scheduled_works+0xc3d/0x1630 kernel/workqueue.c:3470 worker_thread+0xa47/0xfb0 kernel/workqueue.c:3551 kthread+0x38b/0x480 kernel/kthread.c:436 ret_from_fork+0x514/0xb70 arch/x86/kernel/process.c:158 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245 </TASK>
--- net/core/dev.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-)
net/core/dev.c +13 -12
@@ -11742,7 +11742,7 @@ int __dev_change_net_namespace(struct net_device *dev, struct net *net, const char *pat, int new_ifindex, struct netlink_ext_ack *extack) { - struct netdev_name_node *name_node; + struct netdev_name_node *name_node, *tmp;struct net *net_old =dev_net (dev);char new_name[IFNAMSIZ ] = {};int err, new_nsid;
@@ -11788,13 +11788,19 @@ int __dev_change_net_namespace(struct net_device *dev, struct net *net, }/* Check that none of the altnames conflicts. */ err = -EEXIST ; -netdev_for_each_altname (dev, name_node) { -if (netdev_name_in_use (net, name_node->name)) { -NL_SET_ERR_MSG_FMT (extack, -"An interface with the altname %s exists in the target netns" , - name_node->name); - goto out; +netdev_for_each_altname_safe (dev, name_node, tmp) { +if (!netdev_name_in_use (net, name_node->name)) +continue ; + +if (!check_net (net_old)) { +__netdev_name_node_alt_destroy (name_node); +continue ; } + +NL_SET_ERR_MSG_FMT (extack, +"An interface with the altname %s exists in the target netns" , + name_node->name); + goto out; }/* Check that new_ifindex isn't used yet. */
@@ -12232,7 +12238,6 @@ static struct pernet_operations __net_initdata netdev_net_ops = { static void __net_exit default_device_exit_net(struct net *net) { -struct netdev_name_node *name_node, *tmp;struct net_device *dev, *aux;/* * Push all migratable network devices back to the
@@ -12256,10 +12261,6 @@ static void __net_exit default_device_exit_net(struct net *net)if (netdev_name_in_use (&init_net, fb_name))snprintf (fb_name,IFNAMSIZ ,"dev%%d" ); -netdev_for_each_altname_safe (dev, name_node, tmp) -if (netdev_name_in_use (&init_net, name_node->name)) -__netdev_name_node_alt_destroy (name_node); - err =dev_change_net_namespace (dev, &init_net, fb_name);if (err) { pr_emerg("%s: failed to move %s to init_net: %d\n",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 792/869 btrfs: zstd: fix lost wakeup when waiting for a workspace
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: FAN YE <[email protected]>
[ Upstream commit 2acb9f3d1cc8f65dc81ed55e238cbf8e5b60bff7 ]
A writer can sleep forever in zstd_get_workspace() even though a workspace is free. When zstd_alloc_workspace() fails, the task is queued on zwsm->wait and schedules unconditionally, never re-testing the pool. zstd_put_workspace() publishes the workspace and then calls cond_wake_up(), which only wakes when a sleeper is already visible, so a workspace returned between the failed allocation and prepare_to_wait() wakes nobody. The window is wide: zstd_alloc_workspace() goes through kvmalloc() and may enter reclaim.
Only a max level workspace triggers the wakeup and one is deliberately kept allocated as the fallback every waiter waits for, so once its wakeup is lost the writer stays in TASK_UNINTERRUPTIBLE until some other task happens to return one. Re-check the pool after prepare_to_wait() has published the waiter, and use the workspace if one turned up.
--- fs/btrfs/zstd.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
fs/btrfs/zstd.c +10 -1
@@ -290,8 +290,17 @@ struct list_head *zstd_get_workspace(unsigned int level)DEFINE_WAIT (wait);prepare_to_wait (&wsm.wait, &wait,TASK_UNINTERRUPTIBLE ); -schedule (); +/* +* Re-check after being queued: zstd_put_workspace() only wakes +* a queue that already has a sleeper, so a workspace returned +* since the failed allocation woke nobody. +*/ + ws =zstd_find_workspace (level); +if (!ws) +schedule ();finish_wait (&wsm.wait, &wait); +if (ws) +return ws; goto again; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 793/869 bpf: backtracking shouldnt clear outer frame R1-R5 for callbacks
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eduard Zingerman <[email protected]>
[ Upstream commit e3e4f66cc4b72333d0886ae2673c360248987889 ]
When processing calls to bpf_loop() verifier marks R1 (and R4) as precise. R1 tracks loop iterations number and because of the 'callback_depth < R1' mechanics in check_helper_call() must be marked precise. However, precision propagation for R1 was broken, when bpf_loop() call was verified on a second iteration.
Consider the following verification trace:
- main: bpf_loop(nr_loops, callback ...)
- callback: BPF_EXIT
- main: bpf_loop(nr_loops, callback ...)
- ...
While the first visit of the call to bpf_loop() propagated R1 precision as expected, the second call to mark_chain_precision() in the check_helper_call() set R1, but it was immediately reset when backtrack_insn() processed preceding BPF_EXIT in the loop deleted in this patch.
Because of that, the second visit of the call to bpf_loop() injected checkpoint with R1 not marked as precise. Which could trick the verifier into accepting unsafe programs. See the next patch for an example of such program.
Commit is structured in a way to minimize conflicts when 'bpf' would be eventually merged with 'bpf-next'.
--- kernel/bpf/verifier.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-)
kernel/bpf/verifier.c +17 -20
@@ -4148,37 +4148,34 @@ static int backtrack_insn(struct bpf_verifier_env *env, int idx, int subseq_idx,return -EFAULT ; } }else if (opcode ==BPF_EXIT ) { -bool r0_precise; +bool from_subprog_call, r0_precise; + +/* BPF_EXIT in subprog or callback always returns +* right after the call instruction, so by checking +* whether the instruction at subseq_idx-1 is subprog +* call or not we can distinguish actual exit from +* *subprog* from exit from *callback*. In the former +* case, we need to propagate r0 precision, if +* necessary. In the former we never do that. +*/ + from_subprog_call = subseq_idx -1 >=0 && +bpf_pseudo_call (&env->prog->insnsi[subseq_idx -1 ]); + + r0_precise = from_subprog_call &&bt_is_reg_set (bt,BPF_REG_0 );/* Backtracking to a nested function call, 'idx' is a part of * the inner frame 'subseq_idx' is a part of the outer frame. * In case of a regular function call, instructions giving * precision to registers R1-R5 should have been found already. -* In case of a callback, it is ok to have R1-R5 marked for -* backtracking, as these registers are set by the function -* invoking callback. +* In case of a callback from bpf_loop(), R{1,4} in the calling +* frame would be set as precise and that is correct. */ -if (subseq_idx >=0 &&calls_callback (env, subseq_idx)) -for (i =BPF_REG_1 ; i <=BPF_REG_5 ; i++) -bt_clear_reg (bt, i); -if (bt_reg_mask (bt) &BPF_REGMASK_ARGS ) { +if (from_subprog_call && (bt_reg_mask (bt) &BPF_REGMASK_ARGS )) {verbose (env,"BUG regs %x\n" ,bt_reg_mask (bt));WARN_ONCE (1 ,"verifier backtracking bug" );return -EFAULT ; } -/* BPF_EXIT in subprog or callback always returns -* right after the call instruction, so by checking -* whether the instruction at subseq_idx-1 is subprog -* call or not we can distinguish actual exit from -* *subprog* from exit from *callback*. In the former -* case, we need to propagate r0 precision, if -* necessary. In the former we never do that. -*/ - r0_precise = subseq_idx -1 >=0 && -bpf_pseudo_call (&env->prog->insnsi[subseq_idx -1 ]) && -bt_is_reg_set (bt,BPF_REG_0 ); -bt_clear_reg (bt,BPF_REG_0 );if (bt_subprog_enter (bt))return -EFAULT ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 794/869 bpf: backtrack_insn(): Handle ld_{abs,ind} subprog exit edge
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eduard Zingerman <[email protected]>
[ Upstream commit 387b1baefbb776e3f48dc2261e77a49213f470f7 ]
Nicholas Carlini reported a bug in precision backtracking mechanism for BPF_LD | BPF_{IND,ABS} instructions. These instructions are modelled as two branches:
- fallthrough;
- implicit exit from current subprogram.
The implicit exit case was not handled by the backtrack_insn() function. When backtracking such a path backtrack_insn() did not call bt_subprog_enter(), which meant that backtracking continued manipulating precision marks in a caller frame, while looking at instructions in a callee frame.
This lead to segmentation faults during verification (see the selftest), or unsound state pruning.
--- kernel/bpf/verifier.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
kernel/bpf/verifier.c +19 -6
@@ -4207,16 +4207,29 @@ static int backtrack_insn(struct bpf_verifier_env *env, int idx, int subseq_idx,*/ } }else if (class ==BPF_LD ) { -if (!bt_is_reg_set (bt, dreg)) -return 0 ; -bt_clear_reg (bt, dreg);/* It's ld_imm64 or ld_abs or ld_ind. * For ld_imm64 no further tracking of precision * into parent is necessary */ -if (mode ==BPF_IND || mode ==BPF_ABS ) -/* to be analyzed */ -return -ENOTSUPP ; +if (mode ==BPF_IMM ) { +bt_clear_reg (bt, dreg); +return 0 ; + } +/* +* BPF_{IND,ABS} are modelled as two branches: +* - fallthrough; +* - implicit subprogram exit. +* It is necessary to switch current frame if +* implicit subprogram exit branch is backtracked. +*/ +if (mode ==BPF_IND || mode ==BPF_ABS ) { +if (bt_is_reg_set (bt, dreg)) +return -ENOTSUPP ; +if (subseq_idx != idx +1 ) +if (bt_subprog_enter (bt)) +return -EFAULT ; +return 0 ; + } }/* Propagate precision marks to linked registers, to account for * registers marked as precise in this function.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 795/869 ipv6: mcast: use rcu_assign_pointer() for __rcu list updates
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 0c8f56c583c3250408367880c98e4d6fbc929315 ]
Several places in net/ipv6/mcast.c update RCU-protected lists (np->ipv6_mc_list, idev->mc_list, idev->mc_tomb) using direct pointer assignments instead of rcu_assign_pointer():
1. In __ipv6_dev_mc_dec(), unlinking a group from idev->mc_list did:
*map = ma->next;
without rcu_assign_pointer() while concurrent readers traverse idev->mc_list locklessly under rcu_read_lock().
2. In ipv6_sock_mc_drop() and __ipv6_sock_mc_close(), unlinking a group from np->ipv6_mc_list directly assigned *lnk = mc_lst->next and np->ipv6_mc_list = mc_lst->next without rcu_assign_pointer(), racing with lockless readers in inet6_mc_check().
3. In __ipv6_sock_mc_join(), mc_lst->next was initialized to np->ipv6_mc_list via raw assignment before publishing mc_lst.
4. In mld_del_delrec() and __ipv6_dev_mc_inc(), __rcu source pointers passed into rcu_assign_pointer() lacked explicit dereference helpers.
Fix these by consistently using rcu_assign_pointer() along with mc_dereference() / sock_dereference().
--- net/ipv6/mcast.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
net/ipv6/mcast.c +13 -7
@@ -229,7 +229,8 @@ static int __ipv6_sock_mc_join(struct sock *sk, int ifindex,return err; } - mc_lst->next = np->ipv6_mc_list; +rcu_assign_pointer (mc_lst->next, +sock_dereference (np->ipv6_mc_list, sk));rcu_assign_pointer (np->ipv6_mc_list, mc_lst);return 0 ;
@@ -289,7 +290,8 @@ int ipv6_sock_mc_drop(struct sock *sk, int ifindex, const struct in6_addr *addr) lnk = &mc_lst->next) {if ((ifindex ==0 || mc_lst->ifindex == ifindex) &&ipv6_addr_equal (&mc_lst->addr, addr)) { - *lnk = mc_lst->next; +rcu_assign_pointer (*lnk, +sock_dereference (mc_lst->next, sk));__ipv6_sock_mc_drop (sk, mc_lst);return 0 ; }
@@ -343,7 +345,8 @@ void __ipv6_sock_mc_close(struct sock *sk)while ((mc_lst =sock_dereference (np->ipv6_mc_list, sk)) !=NULL ) {struct net_device *dev; - np->ipv6_mc_list = mc_lst->next; +rcu_assign_pointer (np->ipv6_mc_list, +sock_dereference (mc_lst->next, sk)); dev =__dev_get_by_index (net, mc_lst->ifindex);if (dev) {
@@ -826,9 +829,11 @@ static void mld_del_delrec(struct inet6_dev *idev, struct ifmcaddr6 *im) }if (pmc) {if (pmc_prev) -rcu_assign_pointer (pmc_prev->next, pmc->next); +rcu_assign_pointer (pmc_prev->next, +mc_dereference (pmc->next, idev));else -rcu_assign_pointer (idev->mc_tomb, pmc->next); +rcu_assign_pointer (idev->mc_tomb, +mc_dereference (pmc->next, idev)); }if (pmc) {
@@ -986,7 +991,7 @@ static int __ipv6_dev_mc_inc(struct net_device *dev,return -ENOMEM ; } -rcu_assign_pointer (mc->next, idev->mc_list); +rcu_assign_pointer (mc->next,mc_dereference (idev->mc_list, idev));rcu_assign_pointer (idev->mc_list, mc);mca_get (mc);
@@ -1018,7 +1023,8 @@ int __ipv6_dev_mc_dec(struct inet6_dev *idev, const struct in6_addr *addr) map = &ma->next) {if (ipv6_addr_equal (&ma->mca_addr, addr)) {if (--ma->mca_users ==0 ) { - *map = ma->next; +rcu_assign_pointer (*map, +mc_dereference (ma->next, idev));igmp6_group_dropped (ma);ip6_mc_clear_src (ma);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 796/869 smb/client: invalidate fscache for fallocate range operations
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Huiwen He <[email protected]>
[ Upstream commit 448ba0ae65ca61064183564d2983c9aa59bd6ba7 ]
smb3_zero_range(), smb3_punch_hole(), smb3_insert_range(), and smb3_collapse_range() modify file contents through server-side range operations. These operations discard the affected page cache, but leave the FS-Cache cookie valid, so a later read may return data cached before the range operation.
Fix this by invalidating FS-Cache after outstanding I/O has completed and before modifying the file on the server.
Run the following as root on a CIFS mount with fsc enabled and an active CacheFiles backend:
bash -c '
MNT=/mnt/cifs
FILE="$MNT/repro"
# Generate four 1 MiB random blocks: [A][B][C][D]. dd if=/dev/urandom of=/tmp/src bs=1M count=4 status=none
# Expected contents after zeroing B: [A][zero][C][D]. cp /tmp/src /tmp/expected
dd if=/dev/zero of=/tmp/expected bs=1M seek=1 count=1 \
conv=notrunc status=none
cp /tmp/src "$FILE"
# Populate FS-Cache, then discard the page cache. sync
echo 1 > /proc/sys/vm/drop_caches
cat "$FILE" > /dev/null
sync
echo 1 > /proc/sys/vm/drop_caches
fallocate --zero-range -o 1M -l 1M "$FILE"
if cmp -s /tmp/expected "$FILE"; then
echo "readback: OK"
else
echo "readback: STALE DATA"
fi
'
Before this change, the readback differs from /tmp/expected:
readback: STALE DATA
After this change, it matches:
readback: OK
--- fs/smb/client/smb2ops.c | 7 +++++++ 1 file changed, 7 insertions(+)
fs/smb/client/smb2ops.c +7 -0
@@ -3524,6 +3524,9 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,if (keep_size == false && !CIFS_CACHE_READ (cifsi)) goto zero_range_exit; +fscache_invalidate (cifs_inode_cookie (inode),NULL , +i_size_read (inode),0 ); + rc =smb3_zero_data (file, tcon, offset, len, xid);if (rc <0 ) goto zero_range_exit;
@@ -3591,6 +3594,8 @@ static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,*/ truncate_pagecache_range (inode, offset, offset + len -1 );netfs_wait_for_outstanding_io (inode); +fscache_invalidate (cifs_inode_cookie (inode),NULL , +i_size_read (inode),0 );cifs_dbg (FYI ,"Offset %lld len %lld\n" , offset, len);
@@ -3936,6 +3941,7 @@ static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,truncate_pagecache_range (inode, off, old_eof); ictx->zero_point = old_eof;netfs_wait_for_outstanding_io (inode); +fscache_invalidate (cifs_inode_cookie (inode),NULL , old_eof,0 ); rc =__smb2_copychunk_range (xid, cfile, cfile, off + len, old_eof - off - len, off);
@@ -3998,6 +4004,7 @@ static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon, goto out_2;truncate_pagecache_range (inode, off, old_eof);netfs_wait_for_outstanding_io (inode); +fscache_invalidate (cifs_inode_cookie (inode),NULL , old_eof,0 ); rc =SMB2_set_eof (xid, tcon, cfile->fid.persistent_fid, cfile->fid.volatile_fid, cfile->pid, new_eof);
Signature · 1 line
2.53.0