6.18.65-rc1 review
Greg Kroah-Hartman
maintainerPATCH 922/2151 ARM: vexpress: fix device_node refcount leak in vexpress_flags_set()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weigang He <[email protected]>
[ Upstream commit 62b9ae8ae4a7f0b93efa1efa230782b37057b1e7 ]
vexpress_flags_set() obtains a reference to the "arm,vexpress-sysreg" device node via of_find_compatible_node() and passes it to of_iomap(), but never calls of_node_put() on it. of_iomap() only reads the node's reg property to create the mapping and does not take ownership, so the node reference is leaked. The function runs from the __init SMP prepare path and caches the mapping in a static, so this is a one-shot leak of a single refcount during boot, with no functional impact.
The lookup was added to drivers/mfd/vexpress-sysreg.c by the commit below and later moved here by commit 9b06fc39084e ("ARM: vexpress: Move vexpress_flags_set() into arch code").
Annotate node with the __free(device_node) cleanup attribute so the reference is released when it goes out of scope.
Found by static analysis tool CodeQL.
--- arch/arm/mach-versatile/v2m.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/mach-versatile/v2m.c +2 -2
@@ -13,8 +13,8 @@ void vexpress_flags_set(u32 data)static void __iomem *base;if (!base) { -struct device_node *node =of_find_compatible_node (NULL ,NULL , -"arm,vexpress-sysreg" ); + struct device_node *node __free(device_node) = +of_find_compatible_node (NULL ,NULL ,"arm,vexpress-sysreg" ); base =of_iomap (node,0 ); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 923/2151 ARM: vexpress: fix device_node refcount leak in vexpress_smp_dt_prepare_cpus()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weigang He <[email protected]>
[ Upstream commit 27b98d331f1dcebe088ab51a7061a387a7440cb2 ]
vexpress_smp_dt_prepare_cpus() obtains a reference to the SCU device node via of_find_matching_node() and passes it to of_iomap(), but never calls of_node_put() on it. of_iomap() does not take ownership of the node, so the reference is leaked. The function is the .smp_prepare_cpus hook invoked once from the __init SMP bring-up path, so this is a one-shot leak of a single refcount during boot, with no functional impact.
Annotate scu with the __free(device_node) cleanup attribute so the reference is released when the function returns.
Found while reviewing a CodeQL report for vexpress_flags_set() on the same SMP bring-up path.
--- arch/arm/mach-versatile/platsmp-vexpress.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/mach-versatile/platsmp-vexpress.c +2 -2
@@ -61,8 +61,8 @@ static const struct of_device_id vexpress_smp_dt_scu_match[] __initconst = {static void __init vexpress_smp_dt_prepare_cpus (unsigned int max_cpus) { -struct device_node *scu =of_find_matching_node (NULL , - vexpress_smp_dt_scu_match); + struct device_node *scu __free(device_node) = +of_find_matching_node (NULL , vexpress_smp_dt_scu_match);if (scu)scu_enable (of_iomap (scu,0 ));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 924/2151 serial: 8250: Fix section mismatch with CONFIG_MODULES=n
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Danish Khateeb <[email protected]>
[ Upstream commit c44a4925cdac02af781ebfae96df68a7bf3580b0 ]
Without CONFIG_MODULES, __init_or_module means __init, so serial8250_pnp_exit() and serial8250_hub6_exit() end up in .init.text. They are also called from serial8250_exit(), which is __exit, and modpost warns:
WARNING: modpost: vmlinux: section mismatch in reference: serial8250_exit+0x2a (section: .exit.text) -> serial8250_pnp_exit (section: .init.text)
The exit code never runs in such a kernel, so nothing breaks at runtime. But a function that is called from both __init and __exit code can't carry either annotation, so drop it.
--- drivers/tty/serial/8250/8250_hub6.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/8250/8250_hub6.c +1 -1
@@ -52,7 +52,7 @@ int __init serial8250_hub6_init(void)return platform_device_register (&hub6_device); } -void __init_or_module serial8250_hub6_exit(void) +void serial8250_hub6_exit (void ) {platform_device_unregister (&hub6_device); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 925/2151 arm64: dts: st: fix sai3b unit address on stm32mp251
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mateusz Nowicki <[email protected]>
[ Upstream commit 64a74189380955bd2d45e5e38a90947b0f63efd3 ]
The unit address of the sai3b node, 502b0024, is the address of the SAI_BCR1 register in the secure alias of SAI3. The reg property of the node translates to the non-secure address 0x402b0024, which all other SAI nodes use. Fix the unit address to match.
--- arch/arm64/boot/dts/st/stm32mp251.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/st/stm32mp251.dtsi +1 -1
@@ -1265,7 +1265,7 @@ sai3a: audio-controller@402b0004 { status = "disabled"; }; - sai3b: audio-controller@502b0024 { + sai3b: audio-controller@402b0024 { compatible = "st,stm32-sai-sub-b"; reg = <0x24 0x20>; #sound-dai-cells = <0>;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 926/2151 arm64: dts: st: fix sai3b unit address on stm32mp231
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mateusz Nowicki <[email protected]>
[ Upstream commit 4b14dbc4c636e760f5db5a2e4e1b4589d484a7d2 ]
The unit address of the sai3b node, 502b0024, is the address of the SAI_BCR1 register in the secure alias of SAI3. The reg property of the node translates to the non-secure address 0x402b0024, which all other SAI nodes use. Fix the unit address to match.
--- arch/arm64/boot/dts/st/stm32mp231.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/st/stm32mp231.dtsi +1 -1
@@ -557,7 +557,7 @@ sai3a: audio-controller@402b0004 { status = "disabled"; }; - sai3b: audio-controller@502b0024 { + sai3b: audio-controller@402b0024 { compatible = "st,stm32-sai-sub-b"; reg = <0x24 0x20>; #sound-dai-cells = <0>;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 927/2151 seg6: fix HMAC validation when an extension header precedes the SRH
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuya Kusakabe <[email protected]>
[ Upstream commit f9cb4d296d81adb0923546ca5d54fae57a81af52 ]
seg6_hmac_validate_skb() derived the SRH from skb_transport_header(). That only holds while the two coincide, which is not true on the seg6_local input path.
ip6_rcv_core() leaves the transport header just past the IPv6 header. A Hop-by-Hop options header is consumed before the route lookup and advances it, but a Destination Options header is not: the seg6_local lwtunnel is entered through an input redirect from the route lookup, which bypasses the extension header handlers. The transport header then still points at the Destination Options header while seg6_get_srh() has located the real SRH further down the chain.
The HMAC is therefore computed over the Destination Options header, and a packet carrying a valid HMAC TLV is dropped when seg6_require_hmac is set. Such a packet is legitimate: RFC 8200 allows Destination Options before a routing header, and get_srh() has walked the header chain since commit 5829d70b0b6c ("ipv6: sr: fix get_srh() to comply with IPv6 standard "RFC 8200"").
With a Fragment or an Authentication header in front of the SRH, the same mistake also reads past the data pulled by seg6_get_srh(). This happens before seg6_require_hmac is read, so the default configuration is affected.
Reproduce by giving a node a seg6local End SID with net.ipv6.conf.<dev>.seg6_require_hmac=1 and a key installed with "ip sr hmac set <keyid> sha1", then sending
IPv6 -> Destination Options -> SRH (carrying a valid HMAC TLV) -> payload
to that SID: it is dropped, while the same packet without the Destination Options header passes.
--- include/net/seg6_hmac.h | 3 ++- net/ipv6/exthdrs.c | 2 +- net/ipv6/seg6_hmac.c | 5 +---- net/ipv6/seg6_local.c | 6 +++--- 4 files changed, 7 insertions(+), 9 deletions(-)
include/net/seg6_hmac.h +2 -1
@@ -48,7 +48,8 @@ extern int seg6_hmac_info_add(struct net *net, u32 key,extern int seg6_hmac_info_del (struct net *net,u32 key);extern int seg6_push_hmac (struct net *net,struct in6_addr *saddr,struct ipv6_sr_hdr *srh); -extern bool seg6_hmac_validate_skb (struct sk_buff *skb); +extern bool seg6_hmac_validate_skb (struct sk_buff *skb, +struct ipv6_sr_hdr *srh);#ifdef CONFIG_IPV6_SEG6_HMAC extern int seg6_hmac_net_init (struct net *net);extern void seg6_hmac_net_exit (struct net *net);
net/ipv6/exthdrs.c +1 -1
@@ -390,7 +390,7 @@ static int ipv6_srh_rcv(struct sk_buff *skb, struct inet6_dev *idev) }#ifdef CONFIG_IPV6_SEG6_HMAC -if (!seg6_hmac_validate_skb (skb)) { +if (!seg6_hmac_validate_skb (skb, hdr)) {kfree_skb (skb);return -1 ; }
net/ipv6/seg6_hmac.c +1 -4
@@ -173,13 +173,12 @@ EXPORT_SYMBOL(seg6_hmac_compute);* * called with rcu_read_lock() */ -bool seg6_hmac_validate_skb (struct sk_buff *skb) +bool seg6_hmac_validate_skb (struct sk_buff *skb,struct ipv6_sr_hdr *srh) {u8 hmac_output[SEG6_HMAC_FIELD_LEN ];struct net *net =dev_net (skb->dev);struct seg6_hmac_info *hinfo;struct sr6_tlv_hmac *tlv; -struct ipv6_sr_hdr *srh;struct inet6_dev *idev;int require_hmac;
@@ -187,8 +186,6 @@ bool seg6_hmac_validate_skb(struct sk_buff *skb)if (!idev)return false; - srh = (struct ipv6_sr_hdr *)skb_transport_header (skb); - tlv =seg6_get_tlv_hmac (srh); require_hmac =READ_ONCE (idev->cnf.seg6_require_hmac);
net/ipv6/seg6_local.c +3 -3
@@ -222,7 +222,7 @@ static struct ipv6_sr_hdr *get_and_validate_srh(struct sk_buff *skb)return NULL ;#ifdef CONFIG_IPV6_SEG6_HMAC -if (!seg6_hmac_validate_skb (skb)) +if (!seg6_hmac_validate_skb (skb, srh))return NULL ;#endif
@@ -239,7 +239,7 @@ static bool decap_and_validate(struct sk_buff *skb, int proto)return false;#ifdef CONFIG_IPV6_SEG6_HMAC -if (srh && !seg6_hmac_validate_skb (skb)) +if (srh && !seg6_hmac_validate_skb (skb, srh))return false;#endif
@@ -771,7 +771,7 @@ static int end_flv8986_core(struct sk_buff *skb, struct seg6_local_lwt *slwt) srhoff = srh ? ((unsigned char *)srh - skb->data) :0 ; pinfo =seg6_get_srh_pktinfo (srh);#ifdef CONFIG_IPV6_SEG6_HMAC -if (srh && !seg6_hmac_validate_skb (skb)) +if (srh && !seg6_hmac_validate_skb (skb, srh)) goto drop;#endif flvmask = finfo->flv_ops;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 928/2151 amt: pull the AMT header behind the transport header in amt_parse_type()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Omar Ramadan <[email protected]>
[ Upstream commit eb0c18404c8943356f4aa164e5db9067b79ea93c ]
A gateway's encap socket passes ICMP errors to amt_err_lookup(), which calls amt_parse_type() on the quoted datagram to see which AMT message failed. On that path skb->data points at the quoted IP header and the transport header at the quoted UDP header, and icmp_socket_deliver() only guarantees the quoted IP header plus 8 bytes, that is, up to the end of the UDP header.
amt_parse_type() pulls sizeof(struct udphdr) + sizeof(struct amt_header) bytes from skb->data, which on this path stays inside the quoted IP header, and then reads the AMT header behind udp_hdr(skb). An ICMP error that quotes only the IP and UDP headers of a Request, the minimum RFC 792 asks for, therefore makes it read past the pulled data, and past the end of the packet when nothing follows.
Pull up to the transport header plus the UDP and AMT headers, as vxlan_err_lookup() does. amt_rcv() is called with the transport header at skb->data, so the pull on the receive path does not change.
--- drivers/net/amt.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/amt.c +6 -2
@@ -1289,8 +1289,12 @@ static int amt_parse_type(struct sk_buff *skb) {struct amt_header *amth; -if (!pskb_may_pull (skb,sizeof (struct udphdr ) + -sizeof (struct amt_header ))) +/* skb->data is the UDP header on receive, but the quoted IP header +* when amt_err_lookup() parses an ICMP error, so pull up to the +* transport header rather than from skb->data. +*/ +if (!pskb_may_pull (skb,skb_transport_offset (skb) + +sizeof (struct udphdr ) +sizeof (struct amt_header )))return -1 ; amth = (struct amt_header *)(udp_hdr (skb) +1 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 929/2151 sched: Set TIF_NEED_RESCHED before calling __trace_set_need_resched()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sechang Lim <[email protected]>
[ Upstream commit 53bc5c556b82a3ca32b62ba349c4511f91526b9f ]
set_tsk_need_resched() tests TIF_NEED_RESCHED, calls __trace_set_need_resched() if the flag is clear, then sets it via set_tsk_thread_flag(). A BPF raw_tp program attached to sched_set_need_resched executes synchronously inside __bpf_trace_run(). On return, __bpf_trace_run() drops the RCU lock with rcu_read_unlock_migrate(), which on the preempt-or-BH-disabled path calls set_need_resched_current() -> set_tsk_need_resched() again.
set_tsk_thread_flag() follows the tracepoint call, so every re-entrant frame sees TIF_NEED_RESCHED clear and calls __trace_set_need_resched() again:
BUG: TASK stack guard page was hit at ffffc9001224ff98 Oops: stack guard page: 0000 [#1] SMP KASAN PTI RIP: 0010:__bpf_trace_sched_set_need_resched_tp+0x1c/0x190 Call Trace: trace_sched_set_need_resched_tp+0x110/0x130 set_tsk_need_resched include/linux/sched.h:2076 set_need_resched_current include/linux/sched.h:2094 rcu_read_unlock_special+0x43a/0x440 __rcu_read_unlock+0x9e/0x120 rcu_read_unlock_migrate+0xa9/0x240 __bpf_trace_run+0x131/0x180 bpf_trace_run3+0x333/0x430 __bpf_trace_sched_set_need_resched_tp+0x13a/0x190 trace_sched_set_need_resched_tp+0x110/0x130 set_tsk_need_resched include/linux/sched.h:2076 ...
__resched_curr() has the same ordering, firing the tracepoint before setting the flag via set_ti_thread_flag() or set_nr_and_not_polling(). Fix it for consistency.
Replace the separate test_tsk_thread_flag() + set_tsk_thread_flag() pair in set_tsk_need_resched() with test_and_set_tsk_thread_flag(). In __resched_curr(), move the tracepoint call after the flag is set in each path.
--- include/linux/sched.h | 5 ++--- kernel/sched/core.c | 7 +++++-- 2 files changed, 7 insertions(+), 5 deletions(-)
include/linux/sched.h +2 -3
@@ -2057,10 +2057,9 @@ static inline int test_tsk_thread_flag(struct task_struct *tsk, int flag)static inline void set_tsk_need_resched (struct task_struct *tsk) { -if (tracepoint_enabled (sched_set_need_resched_tp) && - !test_tsk_thread_flag (tsk,TIF_NEED_RESCHED )) +if (!test_and_set_tsk_thread_flag (tsk,TIF_NEED_RESCHED ) && +tracepoint_enabled (sched_set_need_resched_tp))__trace_set_need_resched (tsk,TIF_NEED_RESCHED ); -set_tsk_thread_flag (tsk,TIF_NEED_RESCHED ); }static inline void clear_tsk_need_resched (struct task_struct *tsk)
kernel/sched/core.c +5 -2
@@ -1114,6 +1114,7 @@ static void __resched_curr(struct rq *rq, int tif) {struct task_struct *curr = rq->curr;struct thread_info *cti =task_thread_info (curr); +bool need_ipi;int cpu;lockdep_assert_rq_held (rq);
@@ -1130,15 +1131,17 @@ static void __resched_curr(struct rq *rq, int tif) cpu =cpu_of (rq); -trace_sched_set_need_resched_tp (curr, cpu, tif);if (cpu ==smp_processor_id ()) {set_ti_thread_flag (cti, tif);if (tif ==TIF_NEED_RESCHED )set_preempt_need_resched (); +trace_sched_set_need_resched_tp (curr, cpu, tif);return ; } -if (set_nr_and_not_polling (cti, tif)) { + need_ipi =set_nr_and_not_polling (cti, tif); +trace_sched_set_need_resched_tp (curr, cpu, tif); +if (need_ipi) {if (tif ==TIF_NEED_RESCHED )smp_send_reschedule (cpu); }else {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 930/2151 misc: enclosure: fix UAF on device_register() failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linkai Gong <[email protected]>
[ Upstream commit 0f3b12bab74e13a2b8686a49c5b83099da61e032 ]
After device_register() fails, the embedded struct device has already been initialized and must be released with put_device() so that enclosure_release() can drop the parent reference and free edev.
The error path currently does put_device(parent) + kfree(edev), which skips the device lifetime rules and can free the object while the device core still owns a reference (use-after-free).
--- drivers/misc/enclosure.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/misc/enclosure.c +1 -2
@@ -148,8 +148,7 @@ enclosure_register(struct device *dev, const char *name, int components,return edev; err: -put_device (edev->edev.parent); -kfree (edev); +put_device (&edev->edev);return ERR_PTR (err); }EXPORT_SYMBOL_GPL (enclosure_register);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 931/2151 misc: nsm: mark device ready before registering the hwrng and misc device
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jasper Wise <[email protected]>
[ Upstream commit e15596e84c818a2b727d2a7cf742a29331e44c43 ]
nsm_device_probe() registers an hwrng provider and /dev/nsm. hwrng_register() can make this the current RNG, and the hwrng fill kthread finds it through the RCU-protected get_current_rng() rather than under the rng_mutex that hwrng_register() holds, so it can be in nsm_rng_read() offering buffers and kicking the queue before probe has returned.
The driver never calls virtio_device_ready(), so DRIVER_OK is set on its behalf by virtio_dev_probe(), only once probe has returned. The virtio spec is explicit about that ordering in 3.1 Device Initialization:
| The driver MUST NOT send any buffer available notifications to the | device before setting DRIVER_OK.
A device that waits for DRIVER_OK before servicing the queue therefore leaves that read unanswered.
Set DRIVER_OK once the virtqueue exists and before either interface is registered, so that the queue is usable by the time anything that can reach it is published; commit f5866db64f34 ("virtio_console: enable VQs early") and commit 1d774589f924 ("i2c: virtio: mark device ready before registering the adapter") do the same for the same reason. The err_hwrng and err_misc paths then unwind a device that is live, so reset it before deleting the virtqueue - the core only adds VIRTIO_CONFIG_S_FAILED to the status when probe fails, it does not reset.
--- drivers/misc/nsm.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/misc/nsm.c +3 -0
@@ -440,6 +440,8 @@ static int nsm_device_probe(struct virtio_device *vdev)mutex_init (&nsm->lock); +virtio_device_ready (vdev); +/* Register as hwrng provider */ nsm->hwrng = (struct hwrng ) { .read = nsm_rng_read,
@@ -472,6 +474,7 @@ static int nsm_device_probe(struct virtio_device *vdev) err_misc:hwrng_unregister (&nsm->hwrng); err_hwrng: +virtio_reset_device (vdev); vdev->config->del_vqs (vdev); err_init_vq:return rc;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 932/2151 misc: nsm: fix CBOR short-length decoding
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ruoyu Wang <[email protected]>
[ Upstream commit 6edddc1d101bfd5cafc94ca2dffaf13e4394662d ]
CBOR encodes byte-string lengths from 0 through 23 directly in the additional-information field. cbor_object_get_array() only handles 23, so shorter byte strings leave array_len uninitialized. Reserved values 28 through 30 and the unsupported indefinite-length encoding also fall through without assigning it.
parse_resp_get_random() then uses the indeterminate value for bounds checking and as the byte count returned to the hwrng core. This can reject a valid short response or report an incorrect amount of entropy.
Decode the complete inline-length range and reject unsupported values. Extended definite-length encodings retain their existing behavior, and the existing size and INT_MAX checks continue to bound the returned slice.
This issue was found by a static analysis checker and confirmed by manual source review.
--- drivers/misc/nsm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/misc/nsm.c +3 -1
@@ -117,7 +117,7 @@ static int cbor_object_get_array(u8 *cbor_object, size_t cbor_object_size, u8 ** array_len_p = &cbor_object[1 ];switch (cbor_short_size) { -case CBOR_SHORT_SIZE_MAX_VALUE :/* short encoding */ + case 0 ... CBOR_SHORT_SIZE_MAX_VALUE: /* short encoding */ array_len = cbor_short_size;break ;case CBOR_LONG_SIZE_U8 :
@@ -132,6 +132,8 @@ static int cbor_object_get_array(u8 *cbor_object, size_t cbor_object_size, u8 **case CBOR_LONG_SIZE_U64 : array_len =be64_to_cpup ((__be64 *)array_len_p);break ; +default : +return -EFAULT ; }if (cbor_object_size < array_offset)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 933/2151 mei: vsc-tp: initialize IRQ state before requesting interrupt
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
[ Upstream commit 7754a2924604ea442ef03ed8fc12ccc9221a2e98 ]
request_threaded_irq() enables the interrupt before returning, so the threaded handler may schedule work while the probe is still initializing its mutexes and work item. Initialize that state first and only free the IRQ on paths where the request succeeded.
--- drivers/misc/mei/vsc-tp.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/misc/mei/vsc-tp.c +9 -8
@@ -496,30 +496,30 @@ static int vsc_tp_probe(struct spi_device *spi)init_waitqueue_head (&tp->xfer_wait); tp->spi = spi; +mutex_init (&tp->mutex); +mutex_init (&tp->event_notify_mutex); +INIT_WORK (&tp->event_work, vsc_tp_event_work); +irq_set_status_flags (spi->irq,IRQ_DISABLE_UNLAZY ); ret =request_threaded_irq (spi->irq,NULL , vsc_tp_isr,IRQF_TRIGGER_FALLING |IRQF_ONESHOT ,dev_name (dev), tp);if (ret) -return ret; - -mutex_init (&tp->mutex); -mutex_init (&tp->event_notify_mutex); -INIT_WORK (&tp->event_work, vsc_tp_event_work); + goto err_destroy_lock;/* only one child acpi device */ ret =acpi_dev_for_each_child (ACPI_COMPANION (dev), vsc_tp_match_any, &adev);if (!ret) { ret = -ENODEV ; - goto err_destroy_lock; + goto err_free_irq; } pinfo.fwnode =acpi_fwnode_handle (adev); pdev =platform_device_register_full (&pinfo);if (IS_ERR (pdev)) { ret =PTR_ERR (pdev); - goto err_destroy_lock; + goto err_free_irq; } tp->pdev = pdev;
@@ -527,9 +527,10 @@ static int vsc_tp_probe(struct spi_device *spi)return 0 ; -err_destroy_lock: +err_free_irq:free_irq (spi->irq, tp); +err_destroy_lock:cancel_work_sync (&tp->event_work);mutex_destroy (&tp->event_notify_mutex);mutex_destroy (&tp->mutex);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 934/2151 debugfs: make debugfs_create_str() read-only
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yichong Chen <[email protected]>
[ Upstream commit 5ec78be9552035e1e71de218f968c03c44181bf0 ]
debugfs_create_str() supports replacing the backing string from userspace. Concurrent writers can race and free the same old string twice.
All writable in-tree users have been converted to local file operations. Remove the generic write support from debugfs_create_str(), and refuse to create a file when the caller passes write permission bits.
This makes unsupported writable use visible instead of silently creating a file with different permissions.
--- fs/debugfs/file.c | 81 ++++++----------------------------------------- 1 file changed, 10 insertions(+), 71 deletions(-)
fs/debugfs/file.c +10 -71
@@ -1048,98 +1048,37 @@ ssize_t debugfs_read_file_str(struct file *file, char __user *user_buf,return ret; } -static ssize_t debugfs_write_file_str (struct file *file,const char __user *user_buf, -size_t count,loff_t *ppos) -{ -struct dentry *dentry =F_DENTRY (file); -char *old, *new =NULL ; -int pos = *ppos; -int r; - - r =debugfs_file_get (dentry); -if (unlikely (r)) -return r; - - old = *(char **)file->private_data; - -/* only allow strict concatenation */ - r = -EINVAL ; -if (pos && pos !=strlen (old)) - goto error; - - r = -E2BIG ; -if (pos + count +1 >PAGE_SIZE ) - goto error; - - r = -ENOMEM ; - new =kmalloc (pos + count +1 ,GFP_KERNEL ); -if (!new) - goto error; - -if (pos) -memcpy (new, old, pos); - - r = -EFAULT ; -if (copy_from_user (new + pos, user_buf, count)) - goto error; - - new[pos + count] ='\0' ; -strim (new); - -rcu_assign_pointer (*(char __rcu **)file->private_data, new); -synchronize_rcu (); -kfree (old); - -debugfs_file_put (dentry); -return count; - -error: -kfree (new); -debugfs_file_put (dentry); -return r; -} -static const struct file_operations fops_str = { .read = debugfs_read_file_str, - .write = debugfs_write_file_str, - .open = simple_open, - .llseek = default_llseek, -}; - -static const struct file_operations fops_str_ro = { - .read = debugfs_read_file_str, - .open = simple_open, - .llseek = default_llseek, -}; - -static const struct file_operations fops_str_wo = { - .write = debugfs_write_file_str, .open = simple_open, .llseek = default_llseek, };/** -* debugfs_create_str - create a debugfs file that is used to read and write a string value +* debugfs_create_str - create a debugfs file that is used to read a string value * @name: a pointer to a string containing the name of the file to create. * @mode: the permission that the file should have * @parent: a pointer to the parent dentry for this file. This should be a * directory dentry if set. If this parameter is %NULL, then the * file will be created in the root of the debugfs filesystem. -* @value: a pointer to the variable that the file should read to and write -* from. This pointer and the string it points to must not be %NULL. +* @value: a pointer to the variable that the file should read from. This +* pointer and the string it points to must not be %NULL. * * This function creates a file in debugfs with the given name that -* contains the value of the variable @value. If the @mode variable is so -* set, it can be read from, and written to. +* contains the value of the variable @value. The file can be read from. +* Writable files are not supported; if @mode contains write permission bits, +* no file is created. */ void debugfs_create_str (const char *name,umode_t mode,struct dentry *parent,char **value) {if (WARN_ON (!value || !*value))return ; +if (WARN (mode &0222 , +"%s() does not support writable files\n" , __func__)) +return ; -debugfs_create_mode_unsafe (name, mode, parent, value, &fops_str, - &fops_str_ro, &fops_str_wo); +debugfs_create_file_unsafe (name, mode, parent, value, &fops_str); }EXPORT_SYMBOL_GPL (debugfs_create_str);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 935/2151 ASoC: rt712: avoid duplicate reset in io_init
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shuming Fan <[email protected]>
[ Upstream commit 923ff8155ef6e83b73b852300d50f2053b969552 ]
The codec should be reset only once during io_init, regardless of whether the system performs a warm or cold reboot.
--- sound/soc/codecs/rt712-sdca.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
sound/soc/codecs/rt712-sdca.c +3 -2
@@ -1886,7 +1886,8 @@ int rt712_sdca_io_init(struct device *dev, struct sdw_slave *slave)pm_runtime_get_noresume (&slave->dev); -rt712_sdca_reset (rt712); +if (!rt712->first_hw_init) +rt712_sdca_reset (rt712);rt712_sdca_index_read (rt712,RT712_VENDOR_REG ,RT712_JD_PRODUCT_NUM , &val); rt712->hw_id = (val &0xf000 ) >>12 ;
@@ -1915,7 +1916,7 @@ int rt712_sdca_io_init(struct device *dev, struct sdw_slave *slave)* if set_jack callback occurred early than io_init, * we set up the jack detection function now */ -if (rt712->hs_jack) +if (rt712->hs_jack && (!rt712->first_hw_init))rt712_sdca_jack_init (rt712);rt712_sdca_index_write (rt712,RT712_VENDOR_REG ,RT712_SW_CONFIG1 ,0x0001 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 936/2151 pps: generators: wake up PPS_GEN_FETCHEVENT readers on unregister
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Danish Khateeb <[email protected]>
[ Upstream commit 5b864f8db0bd33216895f3fe0bb1ec245c596c8e ]
A reader sleeping in PPS_GEN_FETCHEVENT waits for the next event, but no event comes after pps_gen_unregister_source(), so the reader sleeps until it gets a signal. A PPS_GEN_FETCHEVENT issued after the unregister sleeps the same way.
Wake up the readers on unregister, and make PPS_GEN_FETCHEVENT fail with -ENODEV once the generator is gone, like the other ioctls. The wait checks info without info_lock, so clear it with WRITE_ONCE().
--- drivers/pps/generators/pps_gen.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/pps/generators/pps_gen.c +8 -2
@@ -103,11 +103,14 @@ static long pps_gen_cdev_ioctl(struct file *file,dev_dbg (&pps_gen->dev,"PPS_GEN_FETCHEVENT\n" ); ret =wait_event_interruptible (pps_gen->queue, - ev != pps_gen->last_ev); + ev != pps_gen->last_ev || + !READ_ONCE (pps_gen->info));if (ret == -ERESTARTSYS ) {dev_dbg (&pps_gen->dev,"pending signal caught\n" );return -EINTR ; } +if (!READ_ONCE (pps_gen->info)) +return -ENODEV ;spin_lock_irq (&pps_gen->lock); info.sequence = pps_gen->sequence;
@@ -238,9 +241,12 @@ static void pps_gen_unregister_cdev(struct pps_gen_device *pps_gen) pps_gen->info->enable (pps_gen, false); pps_gen->enabled = false; } - pps_gen->info =NULL ; +WRITE_ONCE (pps_gen->info,NULL ); } +/* Wake up the readers in PPS_GEN_FETCHEVENT, they fail now as well */ +wake_up_interruptible_all (&pps_gen->queue); +put_device (&pps_gen->dev); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 937/2151 perf trace: Copy sockaddr arguments by their length
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Rogers <[email protected]>
[ Upstream commit 1c443dfc3202048b2cb1d3c2534b39b28701e929 ]
The BTF augmenter copies sizeof(struct sockaddr), 16 bytes, for the sockaddr arguments of connect, bind and sendto, and runs before the sys_enter_connect and sys_enter_sendto programs that copy their length. An IPv6 address needs 24 or 28 bytes, so the rest was read from past the payload, and now that the printers are bounded only its family is shown.
Copy them as buffers sized by the length argument after them, up to the 32 bytes augmented buffers are limited to. That holds an IPv6 address and doubles the AF_LOCAL path shown.
Committer testing:
Is using BPF:
root@x2:~# strace -e bpf perf trace -e connect,bind |& head -5
bpf(BPF_TOKEN_CREATE, {token_create={flags=0, bpffs_fd=12}}, 8) = -1 EOPNOTSUPP (Operation not supported)
bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_SOCKET_FILTER, insn_cnt=2, insns=0x7ffea3054260, license="GPL", log_level=0, log_size=0, log_buf=NULL, kern_version=KERNEL_VERSION(0, 0, 0), prog_flags=0, prog_name="", prog_ifindex=0, expected_attach_type=BPF_CGROUP_INET_INGRESS, prog_btf_fd=0, func_info_rec_size=0, func_info=NULL, func_info_cnt=0, line_info_rec_size=0, line_info=NULL, line_info_cnt=0, attach_btf_id=0, attach_prog_fd=0, core_relo_cnt=0, fd_array=NULL, core_relos=NULL, core_relo_rec_size=0, log_true_size=0, prog_token_fd=0}, 148) = 12
bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_SOCKET_FILTER, insn_cnt=2, insns=0x7ffea3054390, license="GPL", log_level=0, log_size=0, log_buf=NULL, kern_version=KERNEL_VERSION(0, 0, 0), prog_flags=0, prog_name="", prog_ifindex=0, expected_attach_type=BPF_CGROUP_INET_INGRESS, prog_btf_fd=0, func_info_rec_size=0, func_info=NULL, func_info_cnt=0, line_info_rec_size=0, line_info=NULL, line_info_cnt=0, attach_btf_id=0, attach_prog_fd=0, core_relo_cnt=0, fd_array=NULL, core_relos=NULL, core_relo_rec_size=0, log_true_size=0, prog_token_fd=0, fd_array_cnt=0, signature=NULL, signature_size=0, keyring_id=0}, 168) = 12
bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_SOCKET_FILTER, insn_cnt=2, insns=0x7ffea3053f80, license="GPL", log_level=0, log_size=0, log_buf=NULL, kern_version=KERNEL_VERSION(0, 0, 0), prog_flags=0, prog_name="libbpf_nametest", prog_ifindex=0, expected_attach_type=BPF_CGROUP_INET_INGRESS, prog_btf_fd=0, func_info_rec_size=0, func_info=NULL, func_info_cnt=0, line_info_rec_size=0, line_info=NULL, line_info_cnt=0, attach_btf_id=0, attach_prog_fd=0, core_relo_cnt=0, fd_array=NULL, core_relos=NULL, core_relo_rec_size=0, log_true_size=0, prog_token_fd=0}, 148) = 12
bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_ARRAY, key_size=4, value_size=4, max_entries=1, map_flags=BPF_F_MMAPABLE, inner_map_fd=0, map_name="libbpf_mmap", map_ifindex=0, btf_fd=0, btf_key_type_id=0, btf_value_type_id=0, btf_vmlinux_value_type_id=0, map_extra=0, value_type_btf_obj_fd=0, map_token_fd=0, excl_prog_hash=NULL, excl_prog_hash_size=0}, 92) = 12
root@x2:~#And btf:
root@x2:~# strace -e openat perf trace -e connect,bind |& grep "/sys/kernel/btf/vmlinux" openat(AT_FDCWD, "/sys/kernel/btf/vmlinux", O_RDONLY) = 12 ^C root@x2:~#
And copying the sockaddr parameters according to its addrlen or the cap in the augmented bpf, that probably needs to be a bit bigger for local sockets:
⬢ [acme@toolbx perf-tools-next]$ echo -n /var/run/.heim_org.h5l.kcm-soc | wc -c 30
⬢ [acme@toolbx perf-tools-next]$ ls -la /var/run/.heim_org.h5l.kcm-socket srw-rw-rw-. 1 nobody nobody 0 Sep 14 23:13 /var/run/.heim_org.h5l.kcm-socket ⬢ [acme@toolbx perf-tools-next]$
root@x2:~# perf trace -e connect,bind --max-events 10
0.000 ( 0.717 ms): pool-0/29901 connect(fd: 9, uservaddr: { .family: LOCAL, path: /var/run/.heim_org.h5l.kcm-soc }, addrlen: 110) = 0
3.733 ( 0.059 ms): pool-0/29901 connect(fd: 10, uservaddr: { .family: LOCAL, path: /var/run/.heim_org.h5l.kcm-soc }, addrlen: 110) = 0
8.859 ( 0.054 ms): pool-0/29901 connect(fd: 9, uservaddr: { .family: LOCAL, path: /var/run/.heim_org.h5l.kcm-soc }, addrlen: 110) = 0
10.880 ( 0.053 ms): pool-0/29901 connect(fd: 9, uservaddr: { .family: LOCAL, path: /var/run/.heim_org.h5l.kcm-soc }, addrlen: 110) = 0
1225.303 ( 0.081 ms): systemd-resolv/103685 connect(fd: 30, uservaddr: { .family: INET6, port: 53, addr: fd55:6f31:c26b::1, scope_id: 4 }, addrlen: 28) = 0
1226.000 ( 0.046 ms): systemd-resolv/103685 connect(fd: 31, uservaddr: { .family: INET6, port: 53, addr: fd55:6f31:c26b::1, scope_id: 4 }, addrlen: 28) = 0
1371.972 ( 0.055 ms): systemd-resolv/103685 connect(fd: 27, uservaddr: { .family: INET6, port: 53, addr: fd55:6f31:c26b::1, scope_id: 4 }, addrlen: 28) = 0
1382.266 ( 0.260 ms): Socket Thread/2663038 connect(fd: 178, uservaddr: { .family: INET, port: 443, addr: 186.192.83.34 }, addrlen: 16) = -1 (unknown) (Operation now in progress)
5003.508 ( 0.063 ms): pool-0/29901 connect(fd: 9, uservaddr: { .family: LOCAL, path: /var/run/.heim_org.h5l.kcm-soc }, addrlen: 110) = 0
5007.007 ( 0.054 ms): pool-0/29901 connect(fd: 10, uservaddr: { .family: LOCAL, path: /var/run/.heim_org.h5l.kcm-soc }, addrlen: 110) = 0
root@x2:~#--- tools/perf/builtin-trace.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
tools/perf/builtin-trace.c +6 -1
@@ -3887,7 +3887,12 @@ static int trace__bpf_sys_enter_beauty_map(struct trace *trace, int e_machine, icontinue ; bt = sc->arg_fmt[i].type; - beauty_array[i] = bt->size; +/* Copy a sockaddr as a buffer sized by the next argument, e.g. addrlen. */ +if (strcmp (name,"sockaddr" ) ==0 && field->next && +strstr (field->next->name,"len" )) + beauty_array[i] = -((i +1 ) +1 ); +else + beauty_array[i] = bt->size; can_augment = true; } else if (field->flags & TEP_FIELD_IS_POINTER && /* string */ strcmp(field->type, "const char *") == 0 &&
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 938/2151 perf thread_map: Add thread_map__tgid()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Rogers <[email protected]>
[ Upstream commit 1fdf657871b9240edcaaf1d15caaac5b78a84317 ]
bpf-filter reads the tgid of each thread in a thread map from /proc, to key its BPF map by process, and perf trace is about to do the same. Move convert_to_tgid() to thread_map.c as thread_map__tgid(), taking the thread map and index both users have.
While moving it, fix two bugs. Match Tgid: at the start of a line, as a task can set its comm, shown on the Name: line before it, to contain "Tgid: <n>". And check the character after the number before freeing the buffer it points into, rather than after.
--- tools/perf/util/bpf-filter.c | 29 ++--------------------------- tools/perf/util/thread_map.c | 26 ++++++++++++++++++++++++++ tools/perf/util/thread_map.h | 1 + 3 files changed, 29 insertions(+), 27 deletions(-)
tools/perf/util/bpf-filter.c +2 -27
@@ -56,6 +56,7 @@#include "util/debug.h" #include "util/evsel.h" #include "util/target.h" +#include "util/thread_map.h" #include "util/bpf-utils.h" #include "util/bpf-filter.h"
@@ -202,31 +203,6 @@ static int get_filter_entries(struct evsel *evsel, struct perf_bpf_filter_entryreturn 0 ; } -static int convert_to_tgid (int tid) -{ -char path[128 ]; -char *buf, *p, *q; -int tgid; -size_t len; - -scnprintf (path,sizeof (path),"%d/status" , tid); -if (procfs__read_str (path, &buf, &len) <0 ) -return -1 ; - - p =strstr (buf,"Tgid:" ); -if (p ==NULL ) { -free (buf); -return -1 ; - } - - tgid =strtol (p +6 , &q,0 ); -free (buf); -if (*q !='\n' ) -return -1 ; - -return tgid; -} -/* * The event might be closed already so we cannot get the list of ids using FD * like in create_event_hash() below, let's iterate the event_hash map and
@@ -407,14 +383,13 @@ static int create_idx_hash(struct evsel *evsel, struct perf_bpf_filter_entry *en last =-1 ; nr =perf_thread_map__nr (threads);for (int i =0 ; i < nr; i++) { -int pid =perf_thread_map__pid (threads, i);int tgid;struct idx_hash_key key = { .evt_id = event_id, };/* it actually needs tgid, let's get tgid from /proc. */ - tgid =convert_to_tgid (pid); + tgid =thread_map__tgid (threads, i);if (tgid <0 ) {/* the thread may be dead, ignore. */ continue ;
tools/perf/util/thread_map.c +26 -0
@@ -395,3 +395,29 @@ int thread_map__remove(struct perf_thread_map *threads, int idx) threads->nr--;return 0 ; } + +/* The tgid of the thread at idx, read from /proc, or -1 if it has exited. */ +pid_t thread_map__tgid (struct perf_thread_map *threads,int idx) +{ +char path[128 ]; +char *buf, *p, *q; +pid_t tgid; +size_t len; + +snprintf (path,sizeof (path),"%d/status" ,perf_thread_map__pid (threads, idx)); +if (procfs__read_str (path, &buf, &len) <0 ) +return -1 ; + +/* From a line start, as the Name: line before it can contain "Tgid:". */ + p =strstr (buf,"\nTgid:" ); +if (p ==NULL ) { +free (buf); +return -1 ; + } + + tgid =strtol (p +6 , &q,0 ); +if (*q !='\n' ) + tgid =-1 ; +free (buf); +return tgid; +}
tools/perf/util/thread_map.h +1 -0
@@ -24,4 +24,5 @@ size_t thread_map__fprintf(struct perf_thread_map *threads, FILE *fp);void thread_map__read_comms (struct perf_thread_map *threads);bool thread_map__has (struct perf_thread_map *threads,pid_t pid);int thread_map__remove (struct perf_thread_map *threads,int idx); +pid_t thread_map__tgid (struct perf_thread_map *threads,int idx);#endif /* __PERF_THREAD_MAP_H */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 939/2151 drm/amdgpu/userq: need to unref bo
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: David (Ming Qiang) Wu <[email protected]>
[ Upstream commit b665f29a2f93a266183dc8cd5d732f203157613b ]
unref bo after amdgpu_bo_reserve() failure as it has called amdgpu_bo_ref() already
Stable-dep-of: c7ae3b204328 ("drm/amdgpu/userq: fix reading the WPTR at a non-zero BO offset")
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +1 -0
@@ -391,6 +391,7 @@ static int amdgpu_userq_fence_read_wptr(struct amdgpu_usermode_queue *queue,amdgpu_bo_unreserve (queue->vm->root.bo); r =amdgpu_bo_reserve (bo, true);if (r) { +amdgpu_bo_unref (&bo);DRM_ERROR ("Failed to reserve userqueue wptr bo" );return r; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 940/2151 drm/amdgpu/userq: use drm_exec in amdgpu_userq_fence_read_wptr
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sunil Khatri <[email protected]>
[ Upstream commit 3aab50410653fe7eb35eb6f9c2b27e3549ab09e6 ]
To access the bo from vm mapping first lock the root bo and then the object bo of the mapping to make sure both locks are taken safely.
Stable-dep-of: c7ae3b204328 ("drm/amdgpu/userq: fix reading the WPTR at a non-zero BO offset")
--- .../gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 55 +++++++++---------- 1 file changed, 26 insertions(+), 29 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +26 -29
@@ -370,51 +370,48 @@ static int amdgpu_userq_fence_read_wptr(struct amdgpu_usermode_queue *queue, {struct amdgpu_bo_va_mapping *mapping;struct amdgpu_bo *bo; +struct drm_exec exec;u64 addr, *ptr; -int r; - - r =amdgpu_bo_reserve (queue->vm->root.bo, false); -if (r) -return r; +int ret; addr = queue->userq_prop->wptr_gpu_addr; addr &=AMDGPU_GMC_HOLE_MASK ; - mapping =amdgpu_vm_bo_lookup_mapping (queue->vm, addr >>PAGE_SHIFT ); -if (!mapping) { -amdgpu_bo_unreserve (queue->vm->root.bo); -DRM_ERROR ("Failed to lookup amdgpu_bo_va_mapping\n" ); -return -EINVAL ; - } +drm_exec_init (&exec,DRM_EXEC_IGNORE_DUPLICATES ,2 ); + drm_exec_until_all_locked(&exec) { + ret =amdgpu_vm_lock_pd (queue->vm, &exec,1 ); +drm_exec_retry_on_contention (&exec); +if (unlikely (ret)) + goto lock_error; - bo =amdgpu_bo_ref (mapping->bo_va->base.bo); -amdgpu_bo_unreserve (queue->vm->root.bo); - r =amdgpu_bo_reserve (bo, true); -if (r) { -amdgpu_bo_unref (&bo); -DRM_ERROR ("Failed to reserve userqueue wptr bo" ); -return r; + mapping =amdgpu_vm_bo_lookup_mapping (queue->vm, addr >>PAGE_SHIFT ); +if (!mapping) { + ret = -EINVAL ; + goto lock_error; + } + + ret =drm_exec_lock_obj (&exec, &mapping->bo_va->base.bo->tbo.base); +drm_exec_retry_on_contention (&exec); +if (unlikely (ret)) + goto lock_error; } - r =amdgpu_bo_kmap (bo, (void **)&ptr); -if (r) { + bo = mapping->bo_va->base.bo; + ret =amdgpu_bo_kmap (bo, (void **)&ptr); +if (ret) {DRM_ERROR ("Failed mapping the userqueue wptr bo" ); - goto map_error; + goto lock_error; } *wptr =le64_to_cpu (*ptr);amdgpu_bo_kunmap (bo); -amdgpu_bo_unreserve (bo); -amdgpu_bo_unref (&bo); - +drm_exec_fini (&exec);return 0 ; -map_error: -amdgpu_bo_unreserve (bo); -amdgpu_bo_unref (&bo); - -return r; +lock_error: +drm_exec_fini (&exec); +return ret; }static void amdgpu_userq_fence_cleanup (struct dma_fence *fence)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 941/2151 drm/amdgpu/userq: fix reading the WPTR at a non-zero BO offset
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jesse Zhang <[email protected]>
[ Upstream commit c7ae3b2043282da8de92bd925c8f6bb614633181 ]
The user queue UAPI permits the WPTR at any 8-byte aligned offset within a BO. amdgpu_userq_fence_read_wptr() locates the mapping containing the WPTR address, but amdgpu_bo_kmap() returns the start of the BO, so the code read the first u64 regardless of the WPTR offset. USERQ_SIGNAL uses this value as the exported fence seqno, so a wrong read makes the fence signal early (or never), breaking dependency synchronization.
Translate the WPTR GPU address to a byte offset within the BO, accounting for the VA mapping start and the mapping's BO offset, before reading it.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c +5 -2
@@ -371,7 +371,7 @@ static int amdgpu_userq_fence_read_wptr(struct amdgpu_usermode_queue *queue,struct amdgpu_bo_va_mapping *mapping;struct amdgpu_bo *bo;struct drm_exec exec; -u64 addr, *ptr; +u64 addr, offset, *ptr;int ret; addr = queue->userq_prop->wptr_gpu_addr;
@@ -403,7 +403,10 @@ static int amdgpu_userq_fence_read_wptr(struct amdgpu_usermode_queue *queue, goto lock_error; } - *wptr =le64_to_cpu (*ptr); +/* The WPTR can be anywhere within the BO's VA mapping. */ + offset = addr - (mapping->start <<AMDGPU_GPU_PAGE_SHIFT ); + offset += mapping->offset; + *wptr =le64_to_cpu (ptr[offset /sizeof (*ptr)]);amdgpu_bo_kunmap (bo);drm_exec_fini (&exec);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 942/2151 cpufreq: amd-pstate: Restore previous mode when changing driver mode fails
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mario Limonciello <[email protected]>
[ Upstream commit f6d3cbc63935fa8911da87e91ed768824d495470 ]
amd_pstate_change_driver_mode() unregisters the currently active driver before registering the requested mode. If amd_pstate_register_driver() fails for the new mode, the function returns the error without restoring anything, leaving the system with no cpufreq scaling driver at all until a valid mode is manually re-selected.
Remember the mode that was active before the transition and, if registering the requested mode fails, register the previous mode again so the system keeps a working scaling driver. The original error is still returned to the caller so the sysfs write reports the failure.
--- drivers/cpufreq/amd-pstate.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/cpufreq/amd-pstate.c +10 -3
@@ -1582,6 +1582,7 @@ static int amd_pstate_change_mode_without_dvr_change(int mode)static int amd_pstate_change_driver_mode (int mode) { +int old_mode = cppc_state;int ret;lockdep_assert_held (&amd_pstate_driver_lock);
@@ -1591,10 +1592,16 @@ static int amd_pstate_change_driver_mode(int mode)return ret; ret =amd_pstate_register_driver (mode); -if (ret) -return ret; +if (ret) { +pr_err ("Failed to register %s mode, restoring %s mode\n" , +amd_pstate_get_mode_string (mode), +amd_pstate_get_mode_string (old_mode)); +if (amd_pstate_register_driver (old_mode)) +pr_err ("Failed to restore %s mode\n" , +amd_pstate_get_mode_string (old_mode)); + } -return 0 ; +return ret; }static cppc_mode_transition_fn mode_state_machine[AMD_PSTATE_MAX ][AMD_PSTATE_MAX ] = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 943/2151 cpufreq: amd-pstate: Propagate cppc_set_auto_sel() errors on mode change
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mario Limonciello <[email protected]>
[ Upstream commit 8de705037124dd1cd49bd8cae6536d63ec4e1807 ]
amd_pstate_change_mode_without_dvr_change() iterates over the online CPUs and calls cppc_set_auto_sel() to enable or disable hardware autonomous selection, but discards its return value and unconditionally returns 0.
If the firmware rejects the request, the failure is hidden: the cpufreq core records the mode transition as successful while the hardware stays in its previous autonomous-selection state. The software mode and the actual hardware behaviour then disagree, breaking the expected frequency scaling.
Check the return value of cppc_set_auto_sel() and propagate the first error to the caller so the sysfs write reports the failure.
--- drivers/cpufreq/amd-pstate.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/cpufreq/amd-pstate.c +4 -1
@@ -1567,6 +1567,7 @@ static int amd_pstate_unregister_driver(int dummy)static int amd_pstate_change_mode_without_dvr_change (int mode) {int cpu =0 ; +int ret; cppc_state = mode;
@@ -1574,7 +1575,9 @@ static int amd_pstate_change_mode_without_dvr_change(int mode)return 0 ;for_each_online_cpu (cpu) { -cppc_set_auto_sel (cpu, (cppc_state ==AMD_PSTATE_PASSIVE ) ?0 :1 ); + ret =cppc_set_auto_sel (cpu, (cppc_state ==AMD_PSTATE_PASSIVE ) ?0 :1 ); +if (ret) +return ret; }return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 944/2151 pinctrl: mediatek: mt7629: fix the 2.4 GHz Wi-Fi pin mode array
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuanhong Guo <[email protected]>
[ Upstream commit 0b056aef31602cd10d2b35adc4746781b4fb8609 ]
The wf0_2g group contains nine pins but only eight mux values. mtk_pinmux_set_mux() indexes the mode array once for each pin, reading past its end when configuring pin 78 (WF0_2G_HB6). This can select an unrelated mux value or fail with -EINVAL, preventing the Wi-Fi device from probing.
Add the missing mode 1 entry for WF0_2G_HB6.
--- drivers/pinctrl/mediatek/pinctrl-mt7629.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/mediatek/pinctrl-mt7629.c +1 -1
@@ -294,7 +294,7 @@ static int mt7629_pwm_1_funcs[] = { 2, };/* WF 2G */ static int mt7629_wf0_2g_pins[] = {70 ,71 ,72 ,73 ,74 ,75 ,76 ,77 ,78 , }; -static int mt7629_wf0_2g_funcs[] = {1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 , }; +static int mt7629_wf0_2g_funcs[] = {1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 , };/* WF 5G */ static int mt7629_wf0_5g_pins[] = {0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10 , };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 945/2151 drm/tegra: Fix syncobj_in wait return value check
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikko Perttunen <[email protected]>
[ Upstream commit 27836c46a3db5a7869a9f7e181136f0c4d8bc0d1 ]
dma_fence_wait_timeout() returns the remaining timeout in jiffies on success, zero on timeout, and a negative error code if interrupted. The return value was assigned to 'err' and checked as if it were an errno, the opposite of the correct logic.
Fix the code to use a properly typed variable and check each condition correctly.
--- drivers/gpu/drm/tegra/submit.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/gpu/drm/tegra/submit.c +8 -2
@@ -530,6 +530,7 @@ int tegra_drm_ioctl_channel_submit(struct drm_device *drm, void *data,if (args->syncobj_in) {struct dma_fence *fence; +long wait_err; err =drm_syncobj_find_fence (file, args->syncobj_in,0 ,0 , &fence);if (err) {
@@ -537,10 +538,15 @@ int tegra_drm_ioctl_channel_submit(struct drm_device *drm, void *data, goto unlock; } - err =dma_fence_wait_timeout (fence, true,msecs_to_jiffies (10000 )); + wait_err =dma_fence_wait_timeout (fence, true,msecs_to_jiffies (10000 ));dma_fence_put (fence); -if (err) { +if (wait_err ==0 ) {SUBMIT_ERR (context,"wait for syncobj_in timed out" ); + err = -ETIMEDOUT ; + goto unlock; + }else if (wait_err <0 ) { +/* In practice, -ERESTARTSYS */ + err = wait_err; goto unlock; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 946/2151 drm/tegra: Dont pass an ERR_PTR to drm_syncobj_replace_fence()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikko Perttunen <[email protected]>
[ Upstream commit 7fce3d34eddfff6361cb4de2c5b8789b88a552b6 ]
When host1x_fence_create() fails, avoid trying to attach the error pointer to the out syncobj.
--- drivers/gpu/drm/tegra/submit.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/tegra/submit.c +1 -0
@@ -655,6 +655,7 @@ int tegra_drm_ioctl_channel_submit(struct drm_device *drm, void *data,if (IS_ERR (fence)) { err =PTR_ERR (fence);SUBMIT_ERR (context,"failed to create postfence: %d" , err); + goto put_job; }drm_syncobj_replace_fence (syncobj, fence);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 947/2151 drm/tegra: Drop reference on postfence
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikko Perttunen <[email protected]>
[ Upstream commit 5ba3dfe724448f308ad7b28ef8d4f41bca4896ae ]
drm_syncobj_replace_fence() calls dma_fence_get() on the parameter fence, so we need to drop ours. Add a call to dma_fence_put() to do that.
--- drivers/gpu/drm/tegra/submit.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/tegra/submit.c +1 -0
@@ -659,6 +659,7 @@ int tegra_drm_ioctl_channel_submit(struct drm_device *drm, void *data, }drm_syncobj_replace_fence (syncobj, fence); +dma_fence_put (fence); } goto put_job;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 948/2151 arm64: dts: ti: k3-am62a-phycore-som: Fix wkup R5F memory region size
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Markus Schneider-Pargmann (TI) <[email protected]>
[ Upstream commit 3690b591d07a2e8863eb96e2aff740da47b8de03 ]
The wkup_r5fss0_core0_memory_region was reserved with only 0x0f00000 but the MCU SDK linker for the wkup R5F firmware on AM62A defines the DM code/data DDR footprint differently:
/* DDR for DM R5F code/data [ size 27 MiB + 364 KB ] */
DDR : ORIGIN = 0x9CAA5000 LENGTH = 0x1B5B000which results in an end at 0x9e600000. For this memory region which starts at 0x9c900000 this means a length of:
0x9e600000 - 0x9c900000 = 0x1d00000
AM62A additionally has a second DM firmware for edgeai whose highest section end address reaches 0x9e700000, so the region should end there:
0x9e700000 - 0x9c900000 = 0x1e00000
--- arch/arm64/boot/dts/ti/k3-am62a-phycore-som.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/ti/k3-am62a-phycore-som.dtsi +1 -1
@@ -67,7 +67,7 @@ wkup_r5fss0_core0_dma_memory_region: memory@9c800000 { wkup_r5fss0_core0_memory_region: memory@9c900000 { compatible = "shared-dma-pool"; - reg = <0x00 0x9c900000 0x00 0xf00000>; + reg = <0x00 0x9c900000 0x00 0x1e00000>; no-map; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 949/2151 arm64: dts: ti: k3-am62d2-evm: Fix wkup R5F memory region size
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Markus Schneider-Pargmann (TI) <[email protected]>
[ Upstream commit 5dd0e5b9d5f67276ff291f30da9bf5a17a46c48e ]
The wkup_r5fss0_core0_memory_region was reserved with only 0x0f00000 but the MCU SDK linker for the wkup R5F firmware on AM62A defines the DM code/data DDR footprint differently:
/* DDR for DM R5F code/data [ size 27 MiB + 364 KB ] */
DDR : ORIGIN = 0x9CAA5000 LENGTH = 0x1B5B000which results in an end at 0x9e600000. For this memory region which starts at 0x9c900000 this means a length of:
0x9e600000 - 0x9c900000 = 0x1d00000
AM62A additionally has a second DM firmware for edgeai whose highest section end address reaches 0x9e700000, so the region should end there:
0x9e700000 - 0x9c900000 = 0x1e00000
--- arch/arm64/boot/dts/ti/k3-am62d2-evm.dts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/ti/k3-am62d2-evm.dts +1 -1
@@ -67,7 +67,7 @@ wkup_r5fss0_core0_dma_memory_region: memory@9c800000 { wkup_r5fss0_core0_memory_region: memory@9c900000 { compatible = "shared-dma-pool"; - reg = <0x00 0x9c900000 0x00 0xf00000>; + reg = <0x00 0x9c900000 0x00 0x1e00000>; no-map; bootph-pre-ram; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 950/2151 arm64: dts: ti: k3-am62a7-sk: Fix wkup R5F memory region size
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Markus Schneider-Pargmann (TI) <[email protected]>
[ Upstream commit 8d36eb58c06b867f29a8df2f39f7fe6718c726af ]
The wkup_r5fss0_core0_memory_region was reserved with only 0x0f00000 but the MCU SDK linker for the wkup R5F firmware on AM62A defines the DM code/data DDR footprint differently:
/* DDR for DM R5F code/data [ size 27 MiB + 364 KB ] */
DDR : ORIGIN = 0x9CAA5000 LENGTH = 0x1B5B000which results in an end at 0x9e600000. For this memory region which starts at 0x9c900000 this means a length of:
0x9e600000 - 0x9c900000 = 0x1d00000
AM62A additionally has a second DM firmware for edgeai whose highest section end address reaches 0x9e700000, so the region should end there:
0x9e700000 - 0x9c900000 = 0x1e00000
--- arch/arm64/boot/dts/ti/k3-am62a7-sk.dts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/ti/k3-am62a7-sk.dts +1 -1
@@ -61,7 +61,7 @@ wkup_r5fss0_core0_dma_memory_region: memory@9c800000 { wkup_r5fss0_core0_memory_region: memory@9c900000 { compatible = "shared-dma-pool"; - reg = <0x00 0x9c900000 0x00 0xf00000>; + reg = <0x00 0x9c900000 0x00 0x1e00000>; no-map; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 951/2151 arm64: dts: ti: k3-am62p-verdin: Fix wkup R5F memory region size
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Markus Schneider-Pargmann (TI) <[email protected]>
[ Upstream commit 70c9859fcca8dd964a588a0642aed3bd71bc1dcd ]
The wkup_r5fss0_core0_memory_region was reserved with 0x01e00000 but the MCU SDK linker for the wkup R5F firmware on AM62P defines the DM code/data DDR footprint differently:
/* DDR for DM R5F code/data [ size 27 MiB + 396 KB ] */
DDR : ORIGIN = 0x9CAA5000 LENGTH = 0x1B63000which results in an end at 0x9e608000. For this memory region which starts at 0x9c900000 this means a length of:
0x9e608000 - 0x9c900000 = 0x1d08000
--- arch/arm64/boot/dts/ti/k3-am62p-verdin.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/ti/k3-am62p-verdin.dtsi +1 -1
@@ -170,7 +170,7 @@ wkup_r5fss0_core0_dma_memory_region: memory@9c800000 { wkup_r5fss0_core0_memory_region: memory@9c900000 { compatible = "shared-dma-pool"; - reg = <0x00 0x9c900000 0x00 0x01e00000>; + reg = <0x00 0x9c900000 0x00 0x01d08000>; no-map; }; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 952/2151 arm64: dts: ti: k3-am62p5-sk: Fix wkup R5F memory region size
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Markus Schneider-Pargmann (TI) <[email protected]>
[ Upstream commit 93cfb76923603ccaec3720dec065a7874458e67d ]
The wkup_r5fss0_core0_memory_region was reserved with only 0x0f00000 but the MCU SDK linker for the wkup R5F firmware on AM62P defines the DM code/data DDR footprint differently:
/* DDR for DM R5F code/data [ size 27 MiB + 396 KB ] */
DDR : ORIGIN = 0x9CAA5000 LENGTH = 0x1B63000which results in an end at 0x9e608000. For this memory region which starts at 0x9c900000 this means a length of:
0x9e608000 - 0x9c900000 = 0x1d08000
--- arch/arm64/boot/dts/ti/k3-am62p5-sk.dts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/ti/k3-am62p5-sk.dts +1 -1
@@ -57,7 +57,7 @@ wkup_r5fss0_core0_dma_memory_region: memory@9c800000 { wkup_r5fss0_core0_memory_region: memory@9c900000 { compatible = "shared-dma-pool"; - reg = <0x00 0x9c900000 0x00 0xf00000>; + reg = <0x00 0x9c900000 0x00 0x1d08000>; no-map; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 953/2151 arm64: dts: ti: var-som-am62p: Fix wkup R5F memory region size
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Markus Schneider-Pargmann (TI) <[email protected]>
[ Upstream commit c9b15cd49b3fbd54f3382655b4e898921a7adb4e ]
The wkup_r5fss0_core0_memory_region was reserved with 0x01e00000 but the MCU SDK linker for the wkup R5F firmware on AM62P defines the DM code/data DDR footprint differently:
/* DDR for DM R5F code/data [ size 27 MiB + 396 KB ] */
DDR : ORIGIN = 0x9CAA5000 LENGTH = 0x1B63000which results in an end at 0x9e608000. For this memory region which starts at 0x9c900000 this means a length of:
0x9e608000 - 0x9c900000 = 0x1d08000
--- arch/arm64/boot/dts/ti/k3-am62p5-var-som.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/ti/k3-am62p5-var-som.dtsi +1 -1
@@ -83,7 +83,7 @@ wkup_r5fss0_core0_dma_memory_region: r5f-dma-memory@9c800000 { wkup_r5fss0_core0_memory_region: r5f-memory@9c900000 { compatible = "shared-dma-pool"; - reg = <0x00 0x9c900000 0x00 0x01e00000>; + reg = <0x00 0x9c900000 0x00 0x01d08000>; no-map; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 954/2151 net: iterate online nodes in skb_defer_free_flush()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kris Pan <[email protected]>
[ Upstream commit 56fbbb662795b29f4d12a55cb1b456553a6ec3b0 ]
skb_attempt_defer_free() only queues skbs on the current CPU's node (numa_node_id() of a running CPU), which is always online, so the flush loop never needs to visit nodes that are merely possible.
for_each_node() walks node_possible_map. On machines where the possible map is much larger than the online map -- e.g. a POWER10 LPAR with 32 possible but 1 online node -- the flush loop touches 31 cold, always-empty per-node lists on every softirq pass.
Use for_each_online_node() to iterate only node_online_map. Nodes that go offline are drained by dev_cpu_dead() ("net: flush skb_defer_nodes in dev_cpu_dead()"), so the flush no longer needs to visit offline nodes.
Loopback UDP throughput in a QEMU guest with 32 possible / 1 online nodes (bench_udp, 8 senders, interleaved runs) improves by ~5%.
--- net/core/dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/dev.c +1 -1
@@ -6825,7 +6825,7 @@ static void skb_defer_free_flush(void)struct skb_defer_node *sdn;int node; -for_each_node (node) { +for_each_online_node (node) { sdn =this_cpu_ptr (net_hotdata.skb_defer_nodes) + node;if (llist_empty (&sdn->defer_list))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 955/2151 net: add address list snapshot and reconciliation infrastructure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stanislav Fomichev <[email protected]>
[ Upstream commit db9e726525e45dbd713c07897a4d20bc18333ccc ]
Introduce __hw_addr_list_snapshot() and __hw_addr_list_reconcile() for use by the upcoming ndo_set_rx_mode_async callback.
The async rx_mode path needs to snapshot the device's unicast and multicast address lists under the addr_lock, hand those snapshots to the driver (which may sleep), and then propagate any sync_cnt changes back to the real lists. Two identical snapshots are taken:
a work copy for the driver to pass to __hw_addr_sync_dev() and a reference copy to compute deltas against.
__hw_addr_list_reconcile() walks the reference snapshot comparing each entry against the work snapshot to determine what the driver synced or unsynced. It then applies those deltas to the real list, handling concurrent modifications:
- If the real entry was concurrently removed but the driver synced it to hardware (delta > 0), re-insert a stale entry so the next work run properly unsyncs it from hardware.
- If the entry still exists, apply the delta normally. An entry whose refcount drops to zero is removed.
# dev_addr_test_snapshot_benchmark: 1024 addrs x 1000 snapshots: 89872802 ns total, 89872 ns/iter # dev_addr_test_snapshot_benchmark.speed: slow
Stable-dep-of: d261a371e3b7 ("fbnic: Rework the BMC state pulled from the capabilities message")
--- include/linux/netdevice.h | 7 + net/core/dev.h | 1 + net/core/dev_addr_lists.c | 109 +++++++++- net/core/dev_addr_lists_test.c | 363 ++++++++++++++++++++++++++++++++- 4 files changed, 477 insertions(+), 3 deletions(-)
include/linux/netdevice.h +7 -0
@@ -4965,6 +4965,13 @@ void __hw_addr_unsync_dev(struct netdev_hw_addr_list *list,int (*unsync)(struct net_device *, const unsigned char *));void __hw_addr_init (struct netdev_hw_addr_list *list); +void __hw_addr_flush (struct netdev_hw_addr_list *list); +int __hw_addr_list_snapshot (struct netdev_hw_addr_list *snap, +const struct netdev_hw_addr_list *list, +int addr_len); +void __hw_addr_list_reconcile (struct netdev_hw_addr_list *real_list, +struct netdev_hw_addr_list *work, +struct netdev_hw_addr_list *ref,int addr_len);/* Functions used for device addresses handling */ void dev_addr_mod(struct net_device *dev, unsigned int offset,
net/core/dev.h +1 -0
@@ -68,6 +68,7 @@ void linkwatch_run_queue(void);void dev_addr_flush (struct net_device *dev);int dev_addr_init (struct net_device *dev);void dev_addr_check (struct net_device *dev); +void __hw_addr_flush (struct netdev_hw_addr_list *list);#if IS_ENABLED (CONFIG_NET_SHAPER )void net_shaper_flush_netdev (struct net_device *dev);
net/core/dev_addr_lists.c +108 -1
133 lines not on this page · raw message
net/core/dev_addr_lists_test.c +361 -2
411 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 956/2151 net: introduce ndo_set_rx_mode_async and netdev_rx_mode_work
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stanislav Fomichev <[email protected]>
[ Upstream commit 3554b4345d855089ab7af5e3557f5dc3262d14c9 ]
Add ndo_set_rx_mode_async callback that drivers can implement instead of the legacy ndo_set_rx_mode. The legacy callback runs under the netif_addr_lock spinlock with BHs disabled, preventing drivers from sleeping. The async variant runs from a work queue with rtnl_lock and netdev_lock_ops held, in fully sleepable context.
When __dev_set_rx_mode() sees ndo_set_rx_mode_async, it schedules netdev_rx_mode_work instead of calling the driver inline. The work function takes two snapshots of each address list (uc/mc) under the addr_lock, then drops the lock and calls the driver with the work copies. After the driver returns, it reconciles the snapshots back to the real lists under the lock.
Add netif_rx_mode_sync() to opportunistically execute the pending workqueue update inline, so that rx mode changes are committed before returning to userspace:
- dev_change_flags (SIOCSIFFLAGS / RTM_NEWLINK)
- dev_set_promiscuity
- dev_set_allmulti
- dev_ifsioc SIOCADDMULTI / SIOCDELMULTI
- do_setlink (RTM_SETLINK)
Note that some deep hierarchies still do skip the lower updates via:
- dev_uc_sync
- dev_mc_sync
If we do end up hitting user-visible issues, we can add more calls to netif_rx_mode_sync in specific places. But hopefully we should not, the actual user-visible lists are still synced, it's that just HW state that might be lagging.
Stable-dep-of: d261a371e3b7 ("fbnic: Rework the BMC state pulled from the capabilities message")
--- Documentation/networking/netdevices.rst | 9 + include/linux/netdevice.h | 18 ++ net/core/dev.c | 43 +---- net/core/dev.h | 3 + net/core/dev_addr_lists.c | 209 ++++++++++++++++++++++++ net/core/dev_api.c | 3 + net/core/dev_ioctl.c | 6 +- net/core/rtnetlink.c | 1 + 8 files changed, 249 insertions(+), 43 deletions(-)
Documentation/networking/netdevices.rst +9 -0
@@ -289,6 +289,15 @@ ndo_tx_timeout: ndo_set_rx_mode: Synchronization: netif_addr_lock spinlock. Context: BHs disabled + Notes: Deprecated in favor of ndo_set_rx_mode_async which runs + in process context. + +ndo_set_rx_mode_async: + Synchronization: rtnl_lock() semaphore. In addition, netdev instance + lock if the driver implements queue management or shaper API. + Context: process (from a work queue) + Notes: Async version of ndo_set_rx_mode which runs in process + context. Receives snapshots of the unicast and multicast address lists. ndo_setup_tc: ``TC_SETUP_BLOCK`` and ``TC_SETUP_FT`` are running under NFT locks
include/linux/netdevice.h +18 -0
@@ -1107,6 +1107,16 @@ struct netdev_net_notifier {* This function is called device changes address list filtering. * If driver handles unicast address filtering, it should set * IFF_UNICAST_FLT in its priv_flags. +* Cannot sleep, called with netif_addr_lock_bh held. +* Deprecated in favor of ndo_set_rx_mode_async. +* +* void (*ndo_set_rx_mode_async)(struct net_device *dev, +* struct netdev_hw_addr_list *uc, +* struct netdev_hw_addr_list *mc); +* Async version of ndo_set_rx_mode which runs in process context +* with rtnl_lock and netdev_lock_ops(dev) held. The uc/mc parameters +* are snapshots of the address lists - iterate with +* netdev_hw_addr_list_for_each(ha, uc). * * int (*ndo_set_mac_address)(struct net_device *dev, void *addr); * This function is called when the Media Access Control address
@@ -1427,6 +1437,10 @@ struct net_device_ops {void (*ndo_change_rx_flags)(struct net_device *dev,int flags);void (*ndo_set_rx_mode)(struct net_device *dev); +void (*ndo_set_rx_mode_async)( +struct net_device *dev, +struct netdev_hw_addr_list *uc, +struct netdev_hw_addr_list *mc);int (*ndo_set_mac_address)(struct net_device *dev,void *addr);int (*ndo_validate_addr)(struct net_device *dev);
@@ -1893,6 +1907,8 @@ enum netdev_reg_state {* has been enabled due to the need to listen to * additional unicast addresses in a device that * does not implement ndo_set_rx_mode() +* @rx_mode_node: List entry for rx_mode work processing +* @rx_mode_tracker: Refcount tracker for rx_mode work * @uc: unicast mac addresses * @mc: multicast mac addresses * @dev_addrs: list of device hw addresses
@@ -2286,6 +2302,8 @@ struct net_device {unsigned int promiscuity;unsigned int allmulti;bool uc_promisc; +struct list_head rx_mode_node; +netdevice_tracker rx_mode_tracker;#ifdef CONFIG_LOCKDEP unsigned char nested_level;#endif
net/core/dev.c +2 -41
61 lines not on this page · raw message
net/core/dev.h +3 -0
@@ -141,6 +141,9 @@ int netif_change_carrier(struct net_device *dev, bool new_carrier);int dev_change_carrier (struct net_device *dev,bool new_carrier);void __dev_set_rx_mode (struct net_device *dev); +int __dev_set_promiscuity (struct net_device *dev,int inc,bool notify); +bool netif_rx_mode_clean (struct net_device *dev); +void netif_rx_mode_sync (struct net_device *dev); void __dev_notify_flags(struct net_device *dev, unsigned int old_flags, unsigned int gchanges, u32 portid,
net/core/dev_addr_lists.c +209 -0
222 lines not on this page · raw message
net/core/dev_api.c +3 -0
@@ -66,6 +66,7 @@ int dev_change_flags(struct net_device *dev, unsigned int flags,netdev_lock_ops (dev); ret =netif_change_flags (dev, flags, extack); +netif_rx_mode_sync (dev);netdev_unlock_ops (dev);return ret;
@@ -285,6 +286,7 @@ int dev_set_promiscuity(struct net_device *dev, int inc)netdev_lock_ops (dev); ret =netif_set_promiscuity (dev, inc); +netif_rx_mode_sync (dev);netdev_unlock_ops (dev);return ret;
@@ -311,6 +313,7 @@ int dev_set_allmulti(struct net_device *dev, int inc)netdev_lock_ops (dev); ret =netif_set_allmulti (dev, inc, true); +netif_rx_mode_sync (dev);netdev_unlock_ops (dev);return ret;
net/core/dev_ioctl.c +4 -2
@@ -613,24 +613,26 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, void __user *data,return err;case SIOCADDMULTI : -if (!ops->ndo_set_rx_mode || +if ((!ops->ndo_set_rx_mode && !ops->ndo_set_rx_mode_async) || ifr->ifr_hwaddr.sa_family !=AF_UNSPEC )return -EINVAL ;if (!netif_device_present (dev))return -ENODEV ;netdev_lock_ops (dev); err =dev_mc_add_global (dev, ifr->ifr_hwaddr.sa_data); +netif_rx_mode_sync (dev);netdev_unlock_ops (dev);return err;case SIOCDELMULTI : -if (!ops->ndo_set_rx_mode || +if ((!ops->ndo_set_rx_mode && !ops->ndo_set_rx_mode_async) || ifr->ifr_hwaddr.sa_family !=AF_UNSPEC )return -EINVAL ;if (!netif_device_present (dev))return -ENODEV ;netdev_lock_ops (dev); err =dev_mc_del_global (dev, ifr->ifr_hwaddr.sa_data); +netif_rx_mode_sync (dev);netdev_unlock_ops (dev);return err;
net/core/rtnetlink.c +1 -0
@@ -3442,6 +3442,7 @@ static int do_setlink(const struct sk_buff *skb, struct net_device *dev, dev->name); } +netif_rx_mode_sync (dev);netdev_unlock_ops (dev);return err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 957/2151 fbnic: convert to ndo_set_rx_mode_async
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stanislav Fomichev <[email protected]>
[ Upstream commit 60dd9781e9b890fa4de3e8ab01f63f0fd4e332e7 ]
Convert fbnic from ndo_set_rx_mode to ndo_set_rx_mode_async. The driver's __fbnic_set_rx_mode() now takes explicit uc/mc list parameters and uses __hw_addr_sync_dev() on the snapshots instead of __dev_uc_sync/__dev_mc_sync on the netdev directly.
Update callers in fbnic_up, fbnic_fw_config_after_crash, fbnic_bmc_rpc_check and fbnic_set_mac to pass the real address lists calling __fbnic_set_rx_mode outside the async work path.
Stable-dep-of: d261a371e3b7 ("fbnic: Rework the BMC state pulled from the capabilities message")
--- .../net/ethernet/meta/fbnic/fbnic_netdev.c | 20 ++++++++++++------- .../net/ethernet/meta/fbnic/fbnic_netdev.h | 4 +++- drivers/net/ethernet/meta/fbnic/fbnic_pci.c | 4 ++-- drivers/net/ethernet/meta/fbnic/fbnic_rpc.c | 2 +- 4 files changed, 19 insertions(+), 11 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic_netdev.c +13 -7
@@ -183,7 +183,9 @@ static int fbnic_mc_unsync(struct net_device *netdev, const unsigned char *addr)return ret; } -void __fbnic_set_rx_mode (struct fbnic_dev *fbd) +void __fbnic_set_rx_mode (struct fbnic_dev *fbd, +struct netdev_hw_addr_list *uc, +struct netdev_hw_addr_list *mc) {bool uc_promisc = false, mc_promisc = false;struct net_device *netdev = fbd->netdev;
@@ -213,10 +215,10 @@ void __fbnic_set_rx_mode(struct fbnic_dev *fbd) }/* Synchronize unicast and multicast address lists */ - err =__dev_uc_sync (netdev, fbnic_uc_sync, fbnic_uc_unsync); + err =__hw_addr_sync_dev (uc, netdev, fbnic_uc_sync, fbnic_uc_unsync);if (err == -ENOSPC ) uc_promisc = true; - err =__dev_mc_sync (netdev, fbnic_mc_sync, fbnic_mc_unsync); + err =__hw_addr_sync_dev (mc, netdev, fbnic_mc_sync, fbnic_mc_unsync);if (err == -ENOSPC ) mc_promisc = true;
@@ -238,18 +240,21 @@ void __fbnic_set_rx_mode(struct fbnic_dev *fbd)fbnic_write_tce_tcam (fbd); } -static void fbnic_set_rx_mode (struct net_device *netdev) +static void fbnic_set_rx_mode (struct net_device *netdev, +struct netdev_hw_addr_list *uc, +struct netdev_hw_addr_list *mc) {struct fbnic_net *fbn =netdev_priv (netdev);struct fbnic_dev *fbd = fbn->fbd;/* No need to update the hardware if we are not running */ if (netif_running (netdev)) -__fbnic_set_rx_mode (fbd); +__fbnic_set_rx_mode (fbd, uc, mc); }static int fbnic_set_mac (struct net_device *netdev,void *p) { +struct fbnic_net *fbn =netdev_priv (netdev);struct sockaddr *addr = p;if (!is_valid_ether_addr (addr->sa_data))
@@ -257,7 +262,8 @@ static int fbnic_set_mac(struct net_device *netdev, void *p)eth_hw_addr_set (netdev, addr->sa_data); -fbnic_set_rx_mode (netdev); +if (netif_running (netdev)) +__fbnic_set_rx_mode (fbn->fbd, &netdev->uc, &netdev->mc);return 0 ; }
@@ -551,7 +557,7 @@ static const struct net_device_ops fbnic_netdev_ops = { .ndo_features_check = fbnic_features_check, .ndo_set_mac_address = fbnic_set_mac, .ndo_change_mtu = fbnic_change_mtu, - .ndo_set_rx_mode = fbnic_set_rx_mode, + .ndo_set_rx_mode_async = fbnic_set_rx_mode, .ndo_get_stats64 = fbnic_get_stats64, .ndo_bpf = fbnic_bpf, .ndo_hwtstamp_get = fbnic_hwtstamp_get,
drivers/net/ethernet/meta/fbnic/fbnic_netdev.h +3 -1
@@ -97,7 +97,9 @@ void fbnic_time_init(struct fbnic_net *fbn);int fbnic_time_start (struct fbnic_net *fbn);void fbnic_time_stop (struct fbnic_net *fbn); -void __fbnic_set_rx_mode (struct fbnic_dev *fbd); +void __fbnic_set_rx_mode (struct fbnic_dev *fbd, +struct netdev_hw_addr_list *uc, +struct netdev_hw_addr_list *mc);void fbnic_clear_rx_mode (struct fbnic_dev *fbd); void fbnic_phylink_get_pauseparam(struct net_device *netdev,
drivers/net/ethernet/meta/fbnic/fbnic_pci.c +2 -2
@@ -135,7 +135,7 @@ void fbnic_up(struct fbnic_net *fbn)fbnic_rss_reinit_hw (fbn->fbd, fbn); -__fbnic_set_rx_mode (fbn->fbd); +__fbnic_set_rx_mode (fbn->fbd, &fbn->netdev->uc, &fbn->netdev->mc);/* Enable Tx/Rx processing */ fbnic_napi_enable (fbn);
@@ -176,7 +176,7 @@ static int fbnic_fw_config_after_crash(struct fbnic_dev *fbd) }fbnic_rpc_reset_valid_entries (fbd); -__fbnic_set_rx_mode (fbd); +__fbnic_set_rx_mode (fbd, &fbd->netdev->uc, &fbd->netdev->mc);return 0 ; }
drivers/net/ethernet/meta/fbnic/fbnic_rpc.c +1 -1
@@ -244,7 +244,7 @@ void fbnic_bmc_rpc_check(struct fbnic_dev *fbd)if (fbd->fw_cap.need_bmc_tcam_reinit) {fbnic_bmc_rpc_init (fbd); -__fbnic_set_rx_mode (fbd); +__fbnic_set_rx_mode (fbd, &fbd->netdev->uc, &fbd->netdev->mc); fbd->fw_cap.need_bmc_tcam_reinit = false; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 958/2151 eth: fbnic: take netif_addr_lock_bh() around rx mode address programming
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Zahka <[email protected]>
[ Upstream commit 96e7f9122aae0ed000ee321f324b812a447906d9 ]
When __fbnic_set_rx_mode() is called from contexts other than .ndo_set_rx_mode_async(), the uc and mc addr lists are accessed without the addr lock that __hw_addr_sync_dev() and __hw_addr_unsync_dev() require. Wrap these unprotected accesses with netif_addr_lock_bh(). fbnic_clear_rx_mode() has similar issues.
Stable-dep-of: d261a371e3b7 ("fbnic: Rework the BMC state pulled from the capabilities message")
--- drivers/net/ethernet/meta/fbnic/fbnic_netdev.c | 7 ++++++- drivers/net/ethernet/meta/fbnic/fbnic_pci.c | 4 ++++ drivers/net/ethernet/meta/fbnic/fbnic_rpc.c | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-)
drivers/net/ethernet/meta/fbnic/fbnic_netdev.c +6 -1
@@ -262,8 +262,11 @@ static int fbnic_set_mac(struct net_device *netdev, void *p)eth_hw_addr_set (netdev, addr->sa_data); -if (netif_running (netdev)) +if (netif_running (netdev)) { +netif_addr_lock_bh (netdev);__fbnic_set_rx_mode (fbn->fbd, &netdev->uc, &netdev->mc); +netif_addr_unlock_bh (netdev); + }return 0 ; }
@@ -308,8 +311,10 @@ void fbnic_clear_rx_mode(struct fbnic_dev *fbd)/* Write updates to hardware */ fbnic_write_macda (fbd); +netif_addr_lock_bh (netdev);__dev_uc_unsync (netdev,NULL );__dev_mc_unsync (netdev,NULL ); +netif_addr_unlock_bh (netdev); } static int fbnic_hwtstamp_get(struct net_device *netdev,
drivers/net/ethernet/meta/fbnic/fbnic_pci.c +4 -0
@@ -135,7 +135,9 @@ void fbnic_up(struct fbnic_net *fbn)fbnic_rss_reinit_hw (fbn->fbd, fbn); +netif_addr_lock_bh (fbn->netdev);__fbnic_set_rx_mode (fbn->fbd, &fbn->netdev->uc, &fbn->netdev->mc); +netif_addr_unlock_bh (fbn->netdev);/* Enable Tx/Rx processing */ fbnic_napi_enable (fbn);
@@ -176,7 +178,9 @@ static int fbnic_fw_config_after_crash(struct fbnic_dev *fbd) }fbnic_rpc_reset_valid_entries (fbd); +netif_addr_lock_bh (fbd->netdev);__fbnic_set_rx_mode (fbd, &fbd->netdev->uc, &fbd->netdev->mc); +netif_addr_unlock_bh (fbd->netdev);return 0 ; }
drivers/net/ethernet/meta/fbnic/fbnic_rpc.c +2 -0
@@ -244,7 +244,9 @@ void fbnic_bmc_rpc_check(struct fbnic_dev *fbd)if (fbd->fw_cap.need_bmc_tcam_reinit) {fbnic_bmc_rpc_init (fbd); +netif_addr_lock_bh (fbd->netdev);__fbnic_set_rx_mode (fbd, &fbd->netdev->uc, &fbd->netdev->mc); +netif_addr_unlock_bh (fbd->netdev); fbd->fw_cap.need_bmc_tcam_reinit = false; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 959/2151 fbnic: Rework the BMC state pulled from the capabilities message
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexander Duyck <[email protected]>
[ Upstream commit d261a371e3b74c82c417b1171264dd35f6ddc615 ]
The BMC side of the RPC configuration is driven entirely out of the capabilities message: it carries the BMC presence, its MAC addresses and the all-multi request, and the reinit flag raised off it is what gets the service task to reprogram the MACDA and action TCAMs. Pull that out of fbnic_fw_parse_cap_resp() into a helper and rework the state it publishes.
The firmware reports the BMC present as soon as its NC-SI channel is enabled, before the BMC has been assigned a MAC address. Such a message carries no BMC MAC array and is rejected with -EINVAL, discarding the rest of it. Treat a present BMC with no MAC as absent instead. There is no entry to steer traffic to without one, so the BMC paths stay disabled either way, and the link speed, FEC and anti-rollback version in the same message are no longer thrown out with it.
bmc_present, need_bmc_tcam_reinit, need_bmc_macda_sync and all_multi are single bit members of one bitfield, so every write to one is a read-modify-write of all four. The mailbox writes three of them and the service task writes the other two. Move them into an unsigned long state field driven by the atomic bitops. Putting it at the top of the struct keeps the cost to the word itself: 152 bytes grows to 160, still three cachelines, with a 1 byte hole left ahead of anti_rollback_version.
Order the reinit handoff while there. The mailbox publishes the BMC state before raising the flag and the service task tests the flag before consuming it, so pair an smp_mb__before_atomic() on the raise with a test_and_clear_bit() on the consume. Claiming the flag atomically also keeps a raise that lands mid-pass instead of dropping it.
Commit all_multi unconditionally rather than only when the firmware supplied the attribute. An absent attribute means the BMC is not asking for all-multi, so holding the previous value just kept stale state. It is read out of the message only when a BMC is present, so it is never set on its own and the three callers that paired it with the presence check can test it alone.
fbnic_write_macda() tests the reinit flag to force a MACDA sync and now always sees it clear when reached from fbnic_bmc_rpc_check(). That path is unaffected, as fbnic_bmc_rpc_init() unconditionally marks the broadcast entry, so the update count is never zero while a BMC is present.
--- drivers/net/ethernet/meta/fbnic/fbnic.h | 7 +- drivers/net/ethernet/meta/fbnic/fbnic_fw.c | 78 +++++++++++++-------- drivers/net/ethernet/meta/fbnic/fbnic_fw.h | 15 ++-- drivers/net/ethernet/meta/fbnic/fbnic_rpc.c | 24 ++++--- 4 files changed, 80 insertions(+), 44 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic.h +6 -1
@@ -149,7 +149,12 @@ void fbnic_fw_wr32(struct fbnic_dev *fbd, u32 reg, u32 val);static inline bool fbnic_bmc_present (struct fbnic_dev *fbd) { -return fbd->fw_cap.bmc_present; +return test_bit (FBNIC_FW_CAP_F_BMC_PRESENT , &fbd->fw_cap.state); +} + +static inline bool fbnic_bmc_all_multi (struct fbnic_dev *fbd) +{ +return test_bit (FBNIC_FW_CAP_F_BMC_ALL_MULTI , &fbd->fw_cap.state); }static inline bool fbnic_init_failure (struct fbnic_dev *fbd)
drivers/net/ethernet/meta/fbnic/fbnic_fw.c +49 -29
97 lines not on this page · raw message
drivers/net/ethernet/meta/fbnic/fbnic_fw.h +11 -4
@@ -43,7 +43,18 @@ struct fbnic_fw_ver {char commit[FBNIC_FW_CAP_RESP_COMMIT_MAX_SIZE ]; }; +/* Bits in fbnic_fw_cap.state. The firmware mailbox publishes the BMC state +* and the service task consumes it, so they are updated with atomic bitops. +*/ +enum { +FBNIC_FW_CAP_F_BMC_PRESENT , +FBNIC_FW_CAP_F_BMC_ALL_MULTI , +FBNIC_FW_CAP_F_BMC_TCAM_REINIT , +FBNIC_FW_CAP_F_BMC_MACDA_SYNC , +}; +struct fbnic_fw_cap { +unsigned long state;struct {struct fbnic_fw_ver mgmt, bootloader; } running;
@@ -52,10 +63,6 @@ struct fbnic_fw_cap { } stored;u8 active_slot;u8 bmc_mac_addr[4 ][ETH_ALEN ]; - u8 bmc_present : 1; - u8 need_bmc_tcam_reinit : 1; - u8 need_bmc_macda_sync : 1; - u8 all_multi : 1;u8 link_speed;u8 link_fec;u32 anti_rollback_version;
drivers/net/ethernet/meta/fbnic/fbnic_rpc.c +14 -10
@@ -117,7 +117,7 @@ void fbnic_bmc_rpc_all_multi_config(struct fbnic_dev *fbd,* BMC. */ mac_addr = &fbd->mac_addr[fbd->mac_addr_boundary -1 ]; -if (fbnic_bmc_present (fbd) && fbd->fw_cap.all_multi) { +if (fbnic_bmc_all_multi (fbd)) {if (mac_addr->state !=FBNIC_TCAM_S_VALID ) {eth_zero_addr (mac_addr->value.addr8);eth_broadcast_addr (mac_addr->mask.addr8);
@@ -148,7 +148,7 @@ void fbnic_bmc_rpc_all_multi_config(struct fbnic_dev *fbd,/* If we are not enabling the rule just delete it. We will fall * back to the RSS rules that support the multicast addresses. */ -if (!fbnic_bmc_present (fbd) || !fbd->fw_cap.all_multi || enable_host) { +if (!fbnic_bmc_all_multi (fbd) || enable_host) {if (act_tcam->state ==FBNIC_TCAM_S_VALID ) act_tcam->state =FBNIC_TCAM_S_DELETE ;return ;
@@ -242,20 +242,25 @@ void fbnic_bmc_rpc_check(struct fbnic_dev *fbd) {int err; -if (fbd->fw_cap.need_bmc_tcam_reinit) { +/* Consume the flag before the state it advertises. The ordering +* implied by test_and_clear_bit() pairs with the barrier in +* fbnic_fw_parse_bmc_cap(), and claiming it atomically means a set +* racing with us is kept and retried rather than overwritten. +*/ +if (test_and_clear_bit (FBNIC_FW_CAP_F_BMC_TCAM_REINIT , + &fbd->fw_cap.state)) {fbnic_bmc_rpc_init (fbd);netif_addr_lock_bh (fbd->netdev);__fbnic_set_rx_mode (fbd, &fbd->netdev->uc, &fbd->netdev->mc);netif_addr_unlock_bh (fbd->netdev); - fbd->fw_cap.need_bmc_tcam_reinit = false; } -if (fbd->fw_cap.need_bmc_macda_sync) { +if (test_and_clear_bit (FBNIC_FW_CAP_F_BMC_MACDA_SYNC , + &fbd->fw_cap.state)) { err =fbnic_fw_xmit_rpc_macda_sync (fbd);if (err)dev_warn (fbd->dev,"Writing MACDA table to FW failed, err: %d\n" , err); - fbd->fw_cap.need_bmc_macda_sync = false; } }
@@ -488,8 +493,7 @@ void fbnic_promisc_sync(struct fbnic_dev *fbd, mac_addr->act_tcam); mac_addr->state =FBNIC_TCAM_S_ADD ; } - }else if (mc_promisc && - (!fbnic_bmc_present (fbd) || !fbd->fw_cap.all_multi)) { + }else if (mc_promisc && !fbnic_bmc_all_multi (fbd)) {/* We have to add a special handler for multicast as the * BMC may have an all-multi rule already in place. As such * adding a rule ourselves won't do any good so we will have
@@ -660,12 +664,12 @@ void fbnic_write_macda(struct fbnic_dev *fbd) }/* If reinitializing the BMC TCAM we are doing an initial update */ -if (fbd->fw_cap.need_bmc_tcam_reinit) +if (test_bit (FBNIC_FW_CAP_F_BMC_TCAM_REINIT , &fbd->fw_cap.state)) updates++;/* If needed notify firmware of changes to MACDA TCAM */ if (updates !=0 &&fbnic_bmc_present (fbd)) - fbd->fw_cap.need_bmc_macda_sync = true; +set_bit (FBNIC_FW_CAP_F_BMC_MACDA_SYNC , &fbd->fw_cap.state); }static void fbnic_clear_act_tcam (struct fbnic_dev *fbd,unsigned int idx)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 960/2151 nvdimm/pmem: Release gendisk on probe failure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hemanth Selam <[email protected]>
[ Upstream commit 855a46681e0ba601952c346e5b62d867e51ecb23 ]
pmem_attach_disk() allocates the gendisk with blk_alloc_disk() and hands it to devres only once device_add_disk() has succeeded. Until that point the probe path owns the disk itself, which is why every failure after the allocation jumps to the out: label and puts it there.
The devm_init_badblocks() failure returns directly instead, so the disk allocated a few lines earlier is never released. Nothing releases it afterwards either: the devres action that would have done so has not been registered yet, so unbinding the namespace or destroying it does not reach the disk, and it stays allocated along with its queue and its bdev inode until the machine is rebooted.
devm_init_badblocks() only fails when a single page allocation fails, so reaching this at all needs memory exhaustion during namespace probe, and because device_add_disk() has not run there is nothing user visible left
behind: no device node, no sysfs entry, only the leaked memory.
Release the gendisk through the existing cleanup path on this failure.
--- drivers/nvdimm/pmem.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/nvdimm/pmem.c +4 -2
@@ -557,8 +557,10 @@ static int pmem_attach_disk(struct device *dev,nvdimm_namespace_disk_name (ndns, disk->disk_name);set_capacity (disk, (pmem->size - pmem->pfn_pad - pmem->data_offset) /512 ); -if (devm_init_badblocks (dev, &pmem->bb)) -return -ENOMEM ; +if (devm_init_badblocks (dev, &pmem->bb)) { + rc = -ENOMEM ; + goto out; + }nvdimm_badblocks_populate (nd_region, &pmem->bb, &bb_range); disk->bb = &pmem->bb;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 961/2151 platform/chrome: cros_ec_typec: Validate SVID and mode counts in discovery data
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bartosz Szpila <[email protected]>
[ Upstream commit 317e7abcaf60b79765dcf35c014edac8b9d37a6e ]
cros_typec_register_altmodes() iterates over sop_disc->svid_count and sop_disc->svids[i].mode_count from the EC_CMD_TYPEC_DISCOVERY response without validating their bounds.
port->disc_data is allocated as a buffer of EC_PROTO2_MAX_RESPONSE_SIZE bytes, and each SVID entry contains a fixed mode_vdo[6] array. If the EC returns an out-of-bounds svid_count or mode_count, the loops read past the end of the mode_vdo array or the disc_data buffer.
Validate that the discovery response with svid_count entries fits within EC_PROTO2_MAX_RESPONSE_SIZE using struct_size(), and ensure each SVID's mode_count does not exceed ARRAY_SIZE(sop_disc->svids[i].mode_vdo) before registering altmodes.
--- drivers/platform/chrome/cros_ec_typec.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/platform/chrome/cros_ec_typec.c +10 -0
@@ -7,8 +7,10 @@*/ #include <linux/acpi.h> +#include <linux/array_size.h> #include <linux/module.h> #include <linux/of.h> +#include <linux/overflow.h> #include <linux/platform_data/cros_ec_commands.h> #include <linux/platform_data/cros_usbpd_notify.h> #include <linux/platform_device.h>
@@ -893,7 +895,15 @@ static int cros_typec_register_altmodes(struct cros_typec_data *typec, int port_int ret =0 ;int i, j; +if (struct_size (sop_disc, svids, sop_disc->svid_count) >EC_PROTO2_MAX_RESPONSE_SIZE ) +return -EINVAL ; +for (i =0 ; i < sop_disc->svid_count; i++) { +if (sop_disc->svids[i].mode_count >ARRAY_SIZE (sop_disc->svids[i].mode_vdo)) { + ret = -EINVAL ; + goto err_cleanup; + } +for (j =0 ; j < sop_disc->svids[i].mode_count; j++) {memset (&desc,0 ,sizeof (desc)); desc.svid = sop_disc->svids[i].svid;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 962/2151 crypto: atmel - handle authenc requests without plaintext
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit ccbd95b3efbc0580b6abde2a905823417ca56022 ]
Authenc permits a nonempty associated-data string with no plaintext. The Atmel driver accepts such a request, has SHA process the associated data, and then unconditionally asks AES DMA to transfer zero bytes. The Atmel DMA engines reject the zero-length descriptor, so the valid request fails, normally with -ENOMEM.
Skip the AES transfer when textlen is zero and proceed directly to SHA finalization.
Once an HMAC transform has cached its inner and outer states, SHA can complete this path synchronously. The forced ahash completion callback then invokes the AES finalizer through a void function and discards its return value. This loses -EBADMSG for a mismatched tag and reports successful decryption.
For synchronous SHA completion, release the SHA device without invoking the ahash callback and call the AES finalizer directly. Its result then propagates through the synchronous call chain. Keep the existing callback path for asynchronous completion.
On a SAM9X75, the unpatched driver failed valid AAD-only requests and returned success for a bad tag after the transform had been used once. With this change, bad tags return -EBADMSG for both fresh and reused transforms.
--- drivers/crypto/atmel-aes.c | 2 ++ drivers/crypto/atmel-sha.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+)
drivers/crypto/atmel-aes.c +2 -0
@@ -1831,6 +1831,8 @@ static int atmel_aes_authenc_transfer(struct atmel_aes_dev *dd, int err, dd->is_async = true;if (err)return atmel_aes_complete (dd, err); +if (!rctx->textlen) +return atmel_aes_authenc_digest (dd);/* Prepare src and dst scatter-lists to transfer cipher/plain texts. */ src =scatterwalk_ffwd (rctx->src, req->src, req->assoclen);
drivers/crypto/atmel-sha.c +14 -0
@@ -2395,11 +2395,25 @@ static int atmel_sha_authenc_final_done(struct atmel_sha_dev *dd) {struct ahash_request *req = dd->req;struct atmel_sha_authenc_reqctx *authctx =ahash_request_ctx (req); +atmel_aes_authenc_fn_t cb; +struct atmel_aes_dev *aes_dev;size_t i, num_words = authctx->digestlen /sizeof (u32);for (i =0 ; i < num_words; ++i) authctx->digest[i] =atmel_sha_read (dd,SHA_REG_DIGEST (i)); +if (!dd->is_async) { +/* +* Return the AES finalizer's status directly for synchronous requests. +* The ahash callback cannot propagate it. +*/ + cb = authctx->cb; + aes_dev = authctx->aes_dev; + dd->force_complete = false; + (void )atmel_sha_complete (dd,0 ); +return cb (aes_dev,0 , false); + } +return atmel_sha_complete (dd,0 ); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 963/2151 crypto: tcrypt - Avoid reading req->base after submission
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Herbert Xu <[email protected]>
[ Upstream commit 3a31a4baad6726bf974bcc58a6398f6a36d10aa0 ]
Once a request has been submitted to the Crypto API, the value of req->base.data must not be read by the caller as it may change while the request is processed.
Avoid reading it in tcrypt by combining the crypto_wait struct with the request object into a tcrypt request object and pass that around instead of the request object.
--- crypto/tcrypt.c | 182 +++++++++++++++++++++++++++--------------------- 1 file changed, 101 insertions(+), 81 deletions(-)
crypto/tcrypt.c +101 -81
@@ -56,6 +56,21 @@*/ #define get_driver_name (tfm_type, tfm) crypto_tfm_alg_driver_name(tfm_type ## _tfm(tfm)) +struct tcrypt_aead_request { +struct aead_request *req; +struct crypto_wait wait; +}; + +struct tcrypt_ahash_request { +struct ahash_request *req; +struct crypto_wait wait; +}; + +struct tcrypt_skcipher_request { +struct skcipher_request *req; +struct crypto_wait wait; +}; +/* * Used by test_cipher_speed() */
@@ -129,18 +144,15 @@ static void sg_init_aead(struct scatterlist *sg, char *xbuf[XBUFSIZE],sg_set_buf (&sg[k +1 ], xbuf[k], rem); } -static inline int do_one_aead_op (struct aead_request *req,int ret) +static inline int do_one_aead_op (struct tcrypt_aead_request *req,int ret) { -struct crypto_wait *wait = req->base.data; - -return crypto_wait_req (ret, wait); +return crypto_wait_req (ret, &req->wait); }struct test_mb_aead_data {struct scatterlist sg[XBUFSIZE ];struct scatterlist sgout[XBUFSIZE ]; -struct aead_request *req; -struct crypto_wait wait; +struct tcrypt_aead_request req;char *xbuf[XBUFSIZE ];char *xoutbuf[XBUFSIZE ];char *axbuf[XBUFSIZE ];
@@ -154,14 +166,14 @@ static int do_mult_aead_op(struct test_mb_aead_data *data, int enc,/* Fire up a bunch of concurrent requests */ for (i =0 ; i < num_mb; i++) {if (enc ==ENCRYPT ) - rc[i] =crypto_aead_encrypt (data[i].req); + rc[i] =crypto_aead_encrypt (data[i].req.req);else - rc[i] =crypto_aead_decrypt (data[i].req); + rc[i] =crypto_aead_decrypt (data[i].req.req); }/* Wait for all requests to finish */ for (i =0 ; i < num_mb; i++) { - rc[i] =crypto_wait_req (rc[i], &data[i].wait); + rc[i] =crypto_wait_req (rc[i], &data[i].req.wait);if (rc[i]) {pr_info ("concurrent request %d error %d\n" , i, rc[i]);
@@ -310,21 +322,21 @@ static void test_mb_aead_speed(const char *algo, int enc, int secs, }for (i =0 ; i < num_mb; ++i) { - data[i].req =aead_request_alloc (tfm,GFP_KERNEL ); -if (!data[i].req) { + data[i].req.req =aead_request_alloc (tfm,GFP_KERNEL ); +if (!data[i].req.req) {pr_err ("alg: aead: Failed to allocate request for %s\n" , algo);while (i--) -aead_request_free (data[i].req); +aead_request_free (data[i].req.req); goto out_free_xoutbuf; } }for (i =0 ; i < num_mb; ++i) { -crypto_init_wait (&data[i].wait); -aead_request_set_callback (data[i].req, +crypto_init_wait (&data[i].req.wait); +aead_request_set_callback (data[i].req.req,CRYPTO_TFM_REQ_MAY_BACKLOG , - crypto_req_done, &data[i].wait); + crypto_req_done, &data[i].req.wait); } pr_info("testing speed of multibuffer %s (%s) %s\n", algo,
@@ -386,16 +398,16 @@ static void test_mb_aead_speed(const char *algo, int enc, int secs, bs + (enc ? authsize :0 ), assoc, aad_size); -aead_request_set_ad (cur->req, aad_size); +aead_request_set_ad (cur->req.req, aad_size);if (!enc) { -aead_request_set_crypt (cur->req, +aead_request_set_crypt (cur->req.req, cur->sgout, cur->sg, bs, iv); - ret =crypto_aead_encrypt (cur->req); - ret =do_one_aead_op (cur->req, ret); + ret =crypto_aead_encrypt (cur->req.req); + ret =do_one_aead_op (&cur->req, ret);if (ret) { pr_err("calculating auth failed (%d)\n",
@@ -404,7 +416,7 @@ static void test_mb_aead_speed(const char *algo, int enc, int secs, } } -aead_request_set_crypt (cur->req, cur->sg, +aead_request_set_crypt (cur->req.req, cur->sg, cur->sgout, bs + (enc ?0 : authsize), iv);
@@ -432,7 +444,7 @@ static void test_mb_aead_speed(const char *algo, int enc, int secs, out:for (i =0 ; i < num_mb; ++i) -aead_request_free (data[i].req); +aead_request_free (data[i].req.req); out_free_xoutbuf:for (i =0 ; i < num_mb; ++i)testmgr_free_buf (data[i].xoutbuf);
@@ -450,9 +462,10 @@ static void test_mb_aead_speed(const char *algo, int enc, int secs,kfree (iv); } -static int test_aead_jiffies (struct aead_request *req,int enc, +static int test_aead_jiffies (struct tcrypt_aead_request *treq,int enc,int blen,int secs) { +struct aead_request *req = treq->req;unsigned long start, end;int bcount;int ret;
@@ -460,9 +473,9 @@ static int test_aead_jiffies(struct aead_request *req, int enc,for (start = jiffies, end = start + secs *HZ , bcount =0 ;time_before (jiffies, end); bcount++) {if (enc) - ret =do_one_aead_op (req,crypto_aead_encrypt (req)); + ret =do_one_aead_op (treq,crypto_aead_encrypt (req));else - ret =do_one_aead_op (req,crypto_aead_decrypt (req)); + ret =do_one_aead_op (treq,crypto_aead_decrypt (req));if (ret)return ret;
@@ -473,8 +486,9 @@ static int test_aead_jiffies(struct aead_request *req, int enc,return 0 ; } -static int test_aead_cycles (struct aead_request *req,int enc,int blen) +static int test_aead_cycles (struct tcrypt_aead_request *treq,int enc,int blen) { +struct aead_request *req = treq->req;unsigned long cycles =0 ;int ret =0 ;int i;
@@ -482,9 +496,9 @@ static int test_aead_cycles(struct aead_request *req, int enc, int blen)/* Warm-up run. */ for (i =0 ; i <4 ; i++) {if (enc) - ret =do_one_aead_op (req,crypto_aead_encrypt (req)); + ret =do_one_aead_op (treq,crypto_aead_encrypt (req));else - ret =do_one_aead_op (req,crypto_aead_decrypt (req)); + ret =do_one_aead_op (treq,crypto_aead_decrypt (req));if (ret) goto out;
@@ -496,9 +510,9 @@ static int test_aead_cycles(struct aead_request *req, int enc, int blen) start =get_cycles ();if (enc) - ret =do_one_aead_op (req,crypto_aead_encrypt (req)); + ret =do_one_aead_op (treq,crypto_aead_encrypt (req));else - ret =do_one_aead_op (req,crypto_aead_decrypt (req)); + ret =do_one_aead_op (treq,crypto_aead_decrypt (req)); end =get_cycles ();if (ret)
@@ -520,6 +534,7 @@ static void test_aead_speed(const char *algo, int enc, unsigned int secs, unsigned int tcount, u8 authsize, unsigned int aad_size, u8 *keysize) { + struct tcrypt_aead_request treq;unsigned int i, j;struct crypto_aead *tfm;int ret = -ENOMEM ;
@@ -535,7 +550,6 @@ static void test_aead_speed(const char *algo, int enc, unsigned int secs,char *axbuf[XBUFSIZE ];const int *b_size;unsigned int iv_len; -struct crypto_wait wait; iv =kzalloc (MAX_IVLEN ,GFP_KERNEL );if (!iv)
@@ -577,7 +591,7 @@ static void test_aead_speed(const char *algo, int enc, unsigned int secs, goto out_noreq; } -crypto_init_wait (&wait); +crypto_init_wait (&treq.wait);pr_info ("testing speed of %s (%s) %s\n" , algo,get_driver_name (crypto_aead, tfm), e);
@@ -587,9 +601,10 @@ static void test_aead_speed(const char *algo, int enc, unsigned int secs, algo); goto out_noreq; } + treq.req = req;aead_request_set_callback (req,CRYPTO_TFM_REQ_MAY_BACKLOG , - crypto_req_done, &wait); + crypto_req_done, &treq.wait); i =0 ; do {
@@ -650,7 +665,7 @@ static void test_aead_speed(const char *algo, int enc, unsigned int secs,*/ aead_request_set_crypt (req, sgout, sg, bs, iv); - ret =do_one_aead_op (req, + ret =do_one_aead_op (&treq,crypto_aead_encrypt (req));if (ret) {
@@ -665,11 +680,11 @@ static void test_aead_speed(const char *algo, int enc, unsigned int secs, iv);if (secs) { - ret =test_aead_jiffies (req, enc, bs, + ret =test_aead_jiffies (&treq, enc, bs, secs);cond_resched (); }else { - ret =test_aead_cycles (req, enc, bs); + ret =test_aead_cycles (&treq, enc, bs); }if (ret) {
@@ -709,23 +724,22 @@ static void test_hash_sg_init(struct scatterlist *sg) } } -static inline int do_one_ahash_op (struct ahash_request *req,int ret) +static inline int do_one_ahash_op (struct tcrypt_ahash_request *treq,int ret) { -struct crypto_wait *wait = req->base.data; - -return crypto_wait_req (ret, wait); +return crypto_wait_req (ret, &treq->wait); } -static int test_ahash_jiffies_digest (struct ahash_request *req,int blen, -char *out,int secs) +static int test_ahash_jiffies_digest (struct tcrypt_ahash_request *treq, +int blen,char *out,int secs) { +struct ahash_request *req = treq->req;unsigned long start, end;int bcount;int ret;for (start = jiffies, end = start + secs *HZ , bcount =0 ;time_before (jiffies, end); bcount++) { - ret =do_one_ahash_op (req,crypto_ahash_digest (req)); + ret =do_one_ahash_op (treq,crypto_ahash_digest (req));if (ret)return ret; }
@@ -736,28 +750,29 @@ static int test_ahash_jiffies_digest(struct ahash_request *req, int blen,return 0 ; } -static int test_ahash_jiffies (struct ahash_request *req,int blen, +static int test_ahash_jiffies (struct tcrypt_ahash_request *treq,int blen,int plen,char *out,int secs) { +struct ahash_request *req = treq->req;unsigned long start, end;int bcount, pcount;int ret;if (plen == blen) -return test_ahash_jiffies_digest (req, blen, out, secs); +return test_ahash_jiffies_digest (treq, blen, out, secs);for (start = jiffies, end = start + secs *HZ , bcount =0 ;time_before (jiffies, end); bcount++) { - ret =do_one_ahash_op (req,crypto_ahash_init (req)); + ret =do_one_ahash_op (treq,crypto_ahash_init (req));if (ret)return ret;for (pcount =0 ; pcount < blen; pcount += plen) { - ret =do_one_ahash_op (req,crypto_ahash_update (req)); + ret =do_one_ahash_op (treq,crypto_ahash_update (req));if (ret)return ret; }/* we assume there is enough space in 'out' for the result */ - ret =do_one_ahash_op (req,crypto_ahash_final (req)); + ret =do_one_ahash_op (treq,crypto_ahash_final (req));if (ret)return ret; }
@@ -768,15 +783,16 @@ static int test_ahash_jiffies(struct ahash_request *req, int blen,return 0 ; } -static int test_ahash_cycles_digest (struct ahash_request *req,int blen, -char *out) +static int test_ahash_cycles_digest (struct tcrypt_ahash_request *treq, +int blen,char *out) { +struct ahash_request *req = treq->req;unsigned long cycles =0 ;int ret, i;/* Warm-up run. */ for (i =0 ; i <4 ; i++) { - ret =do_one_ahash_op (req,crypto_ahash_digest (req)); + ret =do_one_ahash_op (treq,crypto_ahash_digest (req));if (ret) goto out; }
@@ -787,7 +803,7 @@ static int test_ahash_cycles_digest(struct ahash_request *req, int blen, start =get_cycles (); - ret =do_one_ahash_op (req,crypto_ahash_digest (req)); + ret =do_one_ahash_op (treq,crypto_ahash_digest (req));if (ret) goto out;
@@ -806,26 +822,27 @@ static int test_ahash_cycles_digest(struct ahash_request *req, int blen,return 0 ; } -static int test_ahash_cycles (struct ahash_request *req,int blen, +static int test_ahash_cycles (struct tcrypt_ahash_request *treq,int blen,int plen,char *out) { +struct ahash_request *req = treq->req;unsigned long cycles =0 ;int i, pcount, ret;if (plen == blen) -return test_ahash_cycles_digest (req, blen, out); +return test_ahash_cycles_digest (treq, blen, out);/* Warm-up run. */ for (i =0 ; i <4 ; i++) { - ret =do_one_ahash_op (req,crypto_ahash_init (req)); + ret =do_one_ahash_op (treq,crypto_ahash_init (req));if (ret) goto out;for (pcount =0 ; pcount < blen; pcount += plen) { - ret =do_one_ahash_op (req,crypto_ahash_update (req)); + ret =do_one_ahash_op (treq,crypto_ahash_update (req));if (ret) goto out; } - ret =do_one_ahash_op (req,crypto_ahash_final (req)); + ret =do_one_ahash_op (treq,crypto_ahash_final (req));if (ret) goto out; }
@@ -836,15 +853,15 @@ static int test_ahash_cycles(struct ahash_request *req, int blen, start =get_cycles (); - ret =do_one_ahash_op (req,crypto_ahash_init (req)); + ret =do_one_ahash_op (treq,crypto_ahash_init (req));if (ret) goto out;for (pcount =0 ; pcount < blen; pcount += plen) { - ret =do_one_ahash_op (req,crypto_ahash_update (req)); + ret =do_one_ahash_op (treq,crypto_ahash_update (req));if (ret) goto out; } - ret =do_one_ahash_op (req,crypto_ahash_final (req)); + ret =do_one_ahash_op (treq,crypto_ahash_final (req));if (ret) goto out;
@@ -867,7 +884,7 @@ static void test_ahash_speed_common(const char *algo, unsigned int secs, struct hash_speed *speed, unsigned mask) {struct scatterlist sg[TVMEMSIZE ]; -struct crypto_wait wait; +struct tcrypt_ahash_request treq;struct ahash_request *req;struct crypto_ahash *tfm;char *output;
@@ -896,9 +913,10 @@ static void test_ahash_speed_common(const char *algo, unsigned int secs, goto out; } -crypto_init_wait (&wait); + treq.req = req; +crypto_init_wait (&treq.wait);ahash_request_set_callback (req,CRYPTO_TFM_REQ_MAY_BACKLOG , - crypto_req_done, &wait); + crypto_req_done, &treq.wait); output =kmalloc (MAX_DIGEST_SIZE ,GFP_KERNEL );if (!output)
@@ -921,11 +939,11 @@ static void test_ahash_speed_common(const char *algo, unsigned int secs,ahash_request_set_crypt (req, sg, output, speed[i].plen);if (secs) { - ret =test_ahash_jiffies (req, speed[i].blen, + ret =test_ahash_jiffies (&treq, speed[i].blen, speed[i].plen, output, secs);cond_resched (); }else { - ret =test_ahash_cycles (req, speed[i].blen, + ret =test_ahash_cycles (&treq, speed[i].blen, speed[i].plen, output); }
@@ -1211,16 +1229,16 @@ static void test_mb_skcipher_speed(const char *algo, int enc, int secs,kfree (data); } -static inline int do_one_acipher_op (struct skcipher_request *req,int ret) +static inline int do_one_acipher_op (struct tcrypt_skcipher_request *req, +int ret) { -struct crypto_wait *wait = req->base.data; - -return crypto_wait_req (ret, wait); +return crypto_wait_req (ret, &req->wait); } -static int test_acipher_jiffies (struct skcipher_request *req,int enc, +static int test_acipher_jiffies (struct tcrypt_skcipher_request *treq,int enc,int blen,int secs) { +struct skcipher_request *req = treq->req;unsigned long start, end;int bcount;int ret;
@@ -1228,10 +1246,10 @@ static int test_acipher_jiffies(struct skcipher_request *req, int enc,for (start = jiffies, end = start + secs *HZ , bcount =0 ;time_before (jiffies, end); bcount++) {if (enc) - ret =do_one_acipher_op (req, + ret =do_one_acipher_op (treq,crypto_skcipher_encrypt (req));else - ret =do_one_acipher_op (req, + ret =do_one_acipher_op (treq,crypto_skcipher_decrypt (req));if (ret)
@@ -1243,9 +1261,10 @@ static int test_acipher_jiffies(struct skcipher_request *req, int enc,return 0 ; } -static int test_acipher_cycles (struct skcipher_request *req,int enc, +static int test_acipher_cycles (struct tcrypt_skcipher_request *treq,int enc,int blen) { +struct skcipher_request *req = treq->req;unsigned long cycles =0 ;int ret =0 ;int i;
@@ -1253,10 +1272,10 @@ static int test_acipher_cycles(struct skcipher_request *req, int enc,/* Warm-up run. */ for (i =0 ; i <4 ; i++) {if (enc) - ret =do_one_acipher_op (req, + ret =do_one_acipher_op (treq,crypto_skcipher_encrypt (req));else - ret =do_one_acipher_op (req, + ret =do_one_acipher_op (treq,crypto_skcipher_decrypt (req));if (ret)
@@ -1269,10 +1288,10 @@ static int test_acipher_cycles(struct skcipher_request *req, int enc, start =get_cycles ();if (enc) - ret =do_one_acipher_op (req, + ret =do_one_acipher_op (treq,crypto_skcipher_encrypt (req));else - ret =do_one_acipher_op (req, + ret =do_one_acipher_op (treq,crypto_skcipher_decrypt (req)); end =get_cycles ();
@@ -1294,8 +1313,8 @@ static void test_skcipher_speed(const char *algo, int enc, unsigned int secs,struct cipher_speed_template *template, unsigned int tcount, u8 *keysize, bool async) { + struct tcrypt_skcipher_request treq;unsigned int ret, i, j, k, iv_len; -struct crypto_wait wait;const char *key;char iv[128 ];struct skcipher_request *req;
@@ -1308,7 +1327,7 @@ static void test_skcipher_speed(const char *algo, int enc, unsigned int secs,else e ="decryption" ; -crypto_init_wait (&wait); +crypto_init_wait (&treq.wait); tfm =crypto_alloc_skcipher (algo,0 , async ?0 :CRYPTO_ALG_ASYNC );
@@ -1327,8 +1346,9 @@ static void test_skcipher_speed(const char *algo, int enc, unsigned int secs, goto out; } + treq.req = req;skcipher_request_set_callback (req,CRYPTO_TFM_REQ_MAY_BACKLOG , - crypto_req_done, &wait); + crypto_req_done, &treq.wait); i =0 ; do {
@@ -1395,11 +1415,11 @@ static void test_skcipher_speed(const char *algo, int enc, unsigned int secs,skcipher_request_set_crypt (req, sg, sg, bs, iv);if (secs) { - ret =test_acipher_jiffies (req, enc, + ret =test_acipher_jiffies (&treq, enc, bs, secs);cond_resched (); }else { - ret =test_acipher_cycles (req, enc, + ret =test_acipher_cycles (&treq, enc, bs); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 964/2151 hwrng: intel - return -ENOMEM when kmalloc_obj() fails
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thorsten Blum <[email protected]>
[ Upstream commit a0590c556cdbf88373d38494a23f1503d39b0ab2 ]
intel_rng_mod_init() incorrectly returns -ENODEV when kmalloc_obj() fails. Return -ENOMEM instead.
--- drivers/char/hw_random/intel-rng.c | 1 + 1 file changed, 1 insertion(+)
drivers/char/hw_random/intel-rng.c +1 -0
@@ -349,6 +349,7 @@ static int __init intel_rng_mod_init(void) intel_rng_hw =kmalloc (sizeof (*intel_rng_hw),GFP_KERNEL );if (!intel_rng_hw) {pci_dev_put (dev); + err = -ENOMEM ; goto out; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 965/2151 rtc: ftrtc010: fix integer overflow in time calculation
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Liu Dalin <[email protected]>
[ Upstream commit 32f04694fa87b8ac9fa58f9ceb2dc6cbc476e2a1 ]
In ftrtc010_rtc_read_time() and ftrtc010_rtc_set_time(), all variables (offset, days, hour, min, sec) are u32. The expression "days * 86400 + hour * 3600 + min * 60 + sec" is evaluated in 32-bit arithmetic, which silently wraps around for dates beyond approximately year 2106 (U32_MAX / 86400 ≈ 49710 days).
In ftrtc010_rtc_read_time(), perform the addition in 32-bit arithmetic first to preserve two's complement wrapping for negative offsets, then cast the result to timeu64_t. In ftrtc010_rtc_set_time(), cast individual u32 operands to timeu64_t before multiplication to prevent overflow in the right-hand side of the offset calculation.
--- drivers/rtc/rtc-ftrtc010.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/rtc/rtc-ftrtc010.c +3 -2
@@ -73,7 +73,7 @@ static int ftrtc010_rtc_read_time(struct device *dev, struct rtc_time *tm) days =readl (rtc->rtc_base +FTRTC010_RTC_DAYS ); offset =readl (rtc->rtc_base +FTRTC010_RTC_RECORD ); - time = offset + days *86400 + hour *3600 + min *60 + sec; + time = (timeu64_t)(offset + days *86400 + hour *3600 + min *60 + sec);rtc_time64_to_tm (time, tm);
@@ -93,7 +93,8 @@ static int ftrtc010_rtc_set_time(struct device *dev, struct rtc_time *tm) hour =readl (rtc->rtc_base +FTRTC010_RTC_HOUR ); day =readl (rtc->rtc_base +FTRTC010_RTC_DAYS ); - offset = time - (day *86400 + hour *3600 + min *60 + sec); + offset = time - ((timeu64_t )day *86400 + (timeu64_t )hour *3600 + + (timeu64_t )min *60 + (timeu64_t )sec);writel (offset, rtc->rtc_base +FTRTC010_RTC_RECORD );writel (0x01 , rtc->rtc_base +FTRTC010_RTC_CR );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 966/2151 ALSA: ump: Avoid dereference with max_src_size=0
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit b61a2369085fd995c8ad44245d3fbd45b1216f71 ]
safe_copy_string() refers the source pointer for a NUL terminator before verifying the source size. When max_src_size=0, it may dereference wrongly. Fix the verification order.
Only hypothetical hardening, and we see no actual issue in the current code, as they are all valid sources.
--- sound/core/ump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/core/ump.c +1 -1
@@ -66,7 +66,7 @@ static void safe_copy_string(void *dst, size_t max_dst_size,if (!max_dst_size--)return ; -for (s = src; max_dst_size && *s && max_src_size--; s++) { +for (s = src; max_dst_size && max_src_size-- && *s; s++) {if (!isascii (*s) || !isprint (*s))continue ; *d++ = *s;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 967/2151 hwrng: intel - return -ENOMEM when ioremap() fails
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thorsten Blum <[email protected]>
[ Upstream commit 4c3ca7c8c152278332590bfd3df1b0f086364759 ]
intel_init_hw_struct() incorrectly returns -EBUSY when ioremap() fails. Return -ENOMEM instead.
--- drivers/char/hw_random/intel-rng.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/char/hw_random/intel-rng.c +2 -2
@@ -318,8 +318,8 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n"; } intel_rng_hw->mem =ioremap (INTEL_FWH_ADDR ,INTEL_FWH_ADDR_LEN ); -if (intel_rng_hw->mem ==NULL ) -return -EBUSY ; +if (!intel_rng_hw->mem) +return -ENOMEM ;return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 968/2151 clocksource/drivers/dbx500-prcmu: Check timer register mapping
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Slavin Liu <[email protected]>
[ Upstream commit 8f30b035a6676e292ee8e54334711d9905dd0495 ]
Return -ENOMEM if of_iomap() fails, before reading or configuring the timer register block.
Detected by static analysis and reviewed with AI-assisted source auditing.
--- drivers/clocksource/clksrc-dbx500-prcmu.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/clocksource/clksrc-dbx500-prcmu.c +2 -0
@@ -52,6 +52,8 @@ static struct clocksource clocksource_dbx500_prcmu = {static int __init clksrc_dbx500_prcmu_init (struct device_node *node) { clksrc_dbx500_timer_base =of_iomap (node,0 ); +if (!clksrc_dbx500_timer_base) +return -ENOMEM ;/* * The A9 sub system expects the timer to be configured as
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 969/2151 riscv: dts: spacemit: set console baud rate on OrangePi RV2
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jennifer Berringer <[email protected]>
[ Upstream commit 789eed2d8bfa83d79e24d185f736b038a121b3ce ]
Set the baud rate to 115200, matching what is used by U-Boot on this platform so that the console is usable even when console options are not specified in cmdline.
--- arch/riscv/boot/dts/spacemit/k1-orangepi-rv2.dts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/boot/dts/spacemit/k1-orangepi-rv2.dts +1 -1
@@ -18,7 +18,7 @@ aliases { }; chosen { - stdout-path = "serial0"; + stdout-path = "serial0:115200n8"; }; leds {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 970/2151 isofs: return long Joliet names whole
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthias Goergens <[email protected]>
[ Upstream commit b8253bcf92d6365b20eea6465f5a93c9fc4aa029 ]
get_joliet_filename() writes into a buffer allocated by its caller but is not told how big that buffer is. It hardcodes PAGE_SIZE as the output limit for utf16s_to_utf8s() and gives uni16_to_x8() no limit at all. PAGE_SIZE was never the right bound. Before commit b2eb2e288604 ("isofs: Drop support of directory entries straddling blocks") both callers allocated a page, but only its first 1024 bytes were for the name, the rest holding a copy of a directory record that straddled a block. It could not overflow only because a directory record holds at most 222 bytes of name (255 bytes, 33 of them fixed), which no converter expands beyond 1024 bytes.
It also keeps the converted length in an unsigned char. 222 bytes of name are 111 UTF-16 units, and the UTF-8 converter, used for iocharset=utf8 and when CONFIG_NLS_DEFAULT is "utf8", needs three bytes for each CJK, Thai or Devanagari character, so such a name can take up to 333 bytes. Past 255 the length wraps. readdir then reports a short name that usually ends in the middle of a UTF-8 sequence, and lookup finds the file only under that name, never under its real one; a name that wraps to exactly 0 bytes is not listed at all.
Such names are out of spec, since Joliet allows 64 units, but common tools write them: PowerISO 9.5 and UltraISO 9.76 both keep up to 110 units by default. Windows, for which Joliet was made, returns them whole, including 111-unit names in records that leave out the padding byte.
Return them whole here too. Pass the buffer size down and have both converters respect it. utf16s_to_utf8s() stops before a character that does not fit, and uni16_to_x8() now hands uni2char() the space that actually remains and stops on -ENAMETOOLONG, as fs/hfsplus/unicode.c does. Both callers pass JOLIET_NAME_MAX + 1, room for 111 units at three bytes each plus the terminator; no character set needs more than three bytes for a UTF-16 unit, and isofs_dir_record_valid() already rejects a record whose name_len claims more than the record holds, so no name is cut. Make the length an int, which is what both converters return.
These names are longer than NAME_MAX. POSIX lets the limit vary by filesystem, reported by pathconf(_PC_NAME_MAX), and the VFS limits a name only by PATH_MAX (verify_dirent_name() in fs/readdir.c).
vfat, exfat, hfsplus and ntfs3 already return names of up to 255 UTF-16 units, 765 bytes of UTF-8, and such names break the same things there:
copying the file to a filesystem with a 255-byte limit, such as ext4 or tmpfs, fails with ENAMETOOLONG, and cp, tar, rsync and Python's shutil report that file and carry on with the rest, so the copy is incomplete but says so. glibc's readdir() returns the names, but the deprecated readdir_r() skips them and fails with ENAMETOOLONG, and an inotify reader with the buffer size inotify(7) suggests gets EINVAL. In the kernel, fanotify reports events on such a file without its name and warns once in fanotify_info_copy_name(), and a directory with such a name cannot be reconnected from a file handle, because the generic get_name() in fs/exportfs, which isofs uses, skips names longer than NAME_MAX. Cutting at NAME_MAX would avoid these, but would list names that Windows does not show and that can coincide within a directory.
Every name of at most 255 bytes is returned exactly as before.
--- fs/isofs/dir.c | 4 +++- fs/isofs/isofs.h | 11 ++++++++++- fs/isofs/joliet.c | 27 ++++++++++++++++++++------- fs/isofs/namei.c | 3 ++- 4 files changed, 35 insertions(+), 10 deletions(-)
fs/isofs/dir.c +3 -1
@@ -215,7 +215,9 @@ static int do_isofs_readdir(struct inode *inode, struct file *file,if (map) {#ifdef CONFIG_JOLIET if (sbi->s_joliet_level) { - len =get_joliet_filename (de, tmpname, inode); + len =get_joliet_filename (de, tmpname, +JOLIET_NAME_MAX +1 , + inode); p = tmpname; } else#endif
fs/isofs/isofs.h +10 -1
@@ -118,7 +118,16 @@ extern int parse_rock_ridge_inode(struct iso_directory_record *, struct inode *,extern int get_rock_ridge_filename (struct iso_directory_record *,char *,struct inode *);extern int isofs_name_translate (struct iso_directory_record *,char *,struct inode *); -int get_joliet_filename (struct iso_directory_record *,unsigned char *,struct inode *); +/* +* The longest name the Joliet converter returns, in bytes. A directory +* record is at most 255 bytes long, which leaves room for 111 UTF-16 units +* of name, and no character set needs more than three bytes for one unit. +*/ +#define JOLIET_NAME_MAX \ + ((255 - sizeof(struct iso_directory_record)) / 2 * 3) + +int get_joliet_filename (struct iso_directory_record *de,unsigned char *outname, +int outsize,struct inode *inode);int get_acorn_filename (struct iso_directory_record *,char *,struct inode *);extern struct dentry *isofs_lookup (struct inode *,struct dentry *,unsigned int flags);
fs/isofs/joliet.c +20 -7
@@ -15,19 +15,26 @@* Convert Unicode 16 to UTF-8 or ASCII. */ static int -uni16_to_x8 (unsigned char *ascii,__be16 *uni,int len,struct nls_table *nls) +uni16_to_x8 (unsigned char *ascii,__be16 *uni,int len,struct nls_table *nls, +int outsize) {__be16 *ip, ch; -unsigned char *op; +unsigned char *op, *end; ip = uni; op = ascii; + end = ascii + outsize -1 ;/* leave room for the terminator */ while ((ch =get_unaligned (ip)) && len) {int llen; - llen = nls->uni2char (be16_to_cpu (ch), op,NLS_MAX_CHARSET_SIZE ); + +if (op >= end) +break ; + llen = nls->uni2char (be16_to_cpu (ch), op, end - op);if (llen >0 ) op += llen; +else if (llen == -ENAMETOOLONG ) +break ;else *op++ ='?' ; ip++;
@@ -38,21 +45,27 @@ uni16_to_x8(unsigned char *ascii, __be16 *uni, int len, struct nls_table *nls)return (op - ascii); } +/* +* Convert the Joliet name of @de into @outname, a buffer of @outsize bytes. +* The result is at most @outsize - 1 bytes long; a longer name is cut at a +* character boundary. +*/ int -get_joliet_filename (struct iso_directory_record * de,unsigned char *outname,struct inode * inode) +get_joliet_filename (struct iso_directory_record *de,unsigned char *outname, +int outsize,struct inode *inode) {struct nls_table *nls; -unsigned char len =0 ; +int len =0 ; nls =ISOFS_SB (inode->i_sb)->s_nls_iocharset;if (!nls) { len =utf16s_to_utf8s ((const wchar_t *) de->name, de->name_len[0 ] >>1 ,UTF16_BIG_ENDIAN , - outname,PAGE_SIZE ); + outname, outsize -1 ); }else { len =uni16_to_x8 (outname, (__be16 *) de->name, - de->name_len[0 ] >>1 , nls); + de->name_len[0 ] >>1 , nls, outsize); }if ((len >2 ) && (outname[len-2 ] ==';' ) && (outname[len-1 ] =='1' )) len -=2 ;
fs/isofs/namei.c +2 -1
@@ -112,7 +112,8 @@ isofs_find_entry(struct inode *dir, struct dentry *dentry, dpnt = tmpname; #ifdef CONFIG_JOLIET }else if (sbi->s_joliet_level) { - dlen =get_joliet_filename (de, tmpname, dir); + dlen =get_joliet_filename (de, tmpname, +JOLIET_NAME_MAX +1 , dir); dpnt = tmpname;#endif }else if (sbi->s_mapping =='a' ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 971/2151 ASoC: dwc: Use OF match data again for StarFive JH7110
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuri Zaporozhets <[email protected]>
[ Upstream commit d532e2f5c288556075dc429941861391118787a0 ]
Commit d6d6c513f5d2 ("ASoC: dwc: Use ops to get platform data") made dw_i2s_probe() fetch its platform data with of_device_get_match_data(), and commit 52ea7c0543f8 ("ASoC: dwc: i2s: Add StarFive JH7110 SoC support") put the JH7110 configuration into the OF match table. Commit 9c97790a07dc ("ASoC: dwc: Fix non-DT instantiation") then went back to pdev->dev.platform_data so that non-DT users such as AMD work again.
Since then the JH7110 match data is never read. The probe runs neither the JH7110 clock and reset setup (i2s_pd_init) nor uses its capability flags; it configures the DAI from COMP_PARAM_1 instead. On the VisionFive 2, i2stx0 drives the bit and frame clocks for HDMI audio, but COMP_PARAM_1 reports it as slave-only, so the sound card fails to probe:
designware-i2s 120b0000.i2s: ASoC error (-22): at snd_soc_dai_set_fmt() on 120b0000.i2s asoc-simple-card sound-hdmi: probe with driver asoc-simple-card failed with error -22
Take the OF match data first and fall back to the platform data when there is none, so that both DT and non-DT users get their configuration.
Tested on a VisionFive 2 v1.3B (v7.0.3 with local HDMI audio patches):
the HDMI sound card now probes and plays through i2stx0. The non-DT path is build-tested only.
--- sound/soc/dwc/dwc-i2s.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
sound/soc/dwc/dwc-i2s.c +5 -1
@@ -21,6 +21,7 @@#include <linux/reset.h> #include <linux/slab.h> #include <linux/pm_runtime.h> +#include <linux/property.h> #include <sound/designware_i2s.h> #include <sound/pcm.h> #include <sound/pcm_params.h>
@@ -916,13 +917,16 @@ static int jh7110_i2stx0_clk_cfg(struct i2s_clk_config_data *config)static int dw_i2s_probe (struct platform_device *pdev) { -const struct i2s_platform_data *pdata = pdev->dev.platform_data; +const struct i2s_platform_data *pdata =device_get_match_data (&pdev->dev);struct dw_i2s_dev *dev;struct resource *res;int ret, irq;struct snd_soc_dai_driver *dw_i2s_dai;const char *clk_id; +if (!pdata) + pdata =dev_get_platdata (&pdev->dev); + dev =devm_kzalloc (&pdev->dev,sizeof (*dev),GFP_KERNEL );if (!dev)return -ENOMEM ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 972/2151 iommu/arm-smmu-v3: Ensure L2 tables are visible before L1 ptrs
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mostafa Saleh <[email protected]>
[ Upstream commit 84366fb547ed987c4857311da0e5127d95bf97e6 ]
Commit 6fabce53f6b9 ("iommu/arm-smmu-v3: Add a missing dma_wmb() for hitless STE update") adds a dma_wmb() to arm_smmu_write_entry() to make sure stream tables
and context descriptors are observed first.
However, STE L1 table descriptors are configured directly via WRITE_ONCE(), where before that they were zeroed with memset() inside dma_direct_alloc() then written to abort in via memset() also in arm_smmu_init_initial_stes() without a barrier in both cases which means that the SMMUv3 can observe the allocated table before the written descriptors causing it to fetch random data.
Similarly in arm_smmu_write_cd_l1_desc() where the L1 CD is written after dma_alloc_coherent() with no barriers.
Add dma_wmb() in both cases.
--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +6 -0
@@ -1312,6 +1312,9 @@ static void arm_smmu_write_cd_l1_desc(struct arm_smmu_cdtab_l1 *dst, {u64 val = (l2ptr_dma &CTXDESC_L1_DESC_L2PTR_MASK ) |CTXDESC_L1_DESC_V ; +/* Ensure the zero-cleared L2 table is fully visible. */ +dma_wmb (); +/* The HW has 64 bit atomicity with stores to the L2 CD table */ WRITE_ONCE (dst->l2ptr,cpu_to_le64 (val)); }
@@ -1583,6 +1586,9 @@ static void arm_smmu_write_strtab_l1_desc(struct arm_smmu_strtab_l1 *dst, val |=FIELD_PREP (STRTAB_L1_DESC_SPAN ,STRTAB_SPLIT +1 ); val |= l2ptr_dma &STRTAB_L1_DESC_L2PTR_MASK ; +/* Ensure the new L2 table is fully visible. */ +dma_wmb (); +/* The HW has 64 bit atomicity with stores to the L2 STE table */ WRITE_ONCE (dst->l2ptr,cpu_to_le64 (val)); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 973/2151 iommu/arm-smmu-v3-test: Fix arm_smmu_v3_test_debug_print_used_bits()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mostafa Saleh <[email protected]>
[ Upstream commit ce58940ccc3d1a377d238d93666c140405f8ce05 ]
arm_smmu_v3_test_debug_print_used_bits() hardcodes arm_smmu_get_ste_used() instead of using the provided writer->ops->get_used() callback. This caused Context Descriptors to be incorrectly parsed as STEs.
--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-test.c +2 -2
@@ -121,8 +121,8 @@ arm_smmu_v3_test_debug_print_used_bits(struct arm_smmu_entry_writer *writer, {__le64 used_bits[NUM_ENTRY_QWORDS ] = {}; -arm_smmu_get_ste_used (ste, used_bits); -pr_debug ("STE used bits: " ); + writer->ops->get_used (ste, used_bits); +pr_debug ("Entry used bits: " );print_hex_dump_debug (" " ,DUMP_PREFIX_NONE ,16 ,8 , used_bits,sizeof (used_bits), false); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 974/2151 perf build python: Dont leave a.out file when building with clang
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Rogers <[email protected]>
[ Upstream commit 6090e612cf24393335e709105db31b6d6e36d6ef ]
Testing clang features doesn't specify a "-o" option so an a.out file is created and left in the make directory (not the output). Fix this by specifying a "-o" of "/dev/null". Reorganize the code a little to help with readability.
Stable-dep-of: 2ed38aa8a52d ("perf python: Track linked libraries as extension dependencies")
--- tools/perf/util/setup.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
tools/perf/util/setup.py +10 -3
@@ -23,10 +23,17 @@ assert srctree, "Environment variable srctree, for the Linux sources, not set" src_feature_tests = f'{srctree}/tools/build/feature' def clang_has_option(option): - cmd = shlex.split(f"{cc} {cc_options} {option}") - cmd.append(path.join(src_feature_tests, "test-hello.c")) + error_substrings = ( + b"unknown argument", + b"is not supported", + b"unknown warning option" + ) + cmd = shlex.split(f"{cc} {cc_options} {option}") + [ + "-o", "/dev/null", + path.join(src_feature_tests, "test-hello.c") + ] cc_output = Popen(cmd, stderr=PIPE).stderr.readlines() - return [o for o in cc_output if ((b"unknown argument" in o) or (b"is not supported" in o) or (b"unknown warning option" in o))] == [ ] + return not any(any(error in line for error in error_substrings) for line in cc_output) if cc_is_clang: from sysconfig import get_config_vars
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 975/2151 perf build: Respect V=1 for Python extension builds
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jens Remus <[email protected]>
[ Upstream commit 41c1ce28bbc1d4f7a1b1b711b86448480d2838d2 ]
Make util/setup.py respect the verbose build flag (V=1) by conditionally passing --quiet only when not in verbose mode.
This eases debugging of Python extension compilation issues and aligns with the existing perf build system behavior.
Stable-dep-of: 2ed38aa8a52d ("perf python: Track linked libraries as extension dependencies")
--- tools/perf/Makefile.perf | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
tools/perf/Makefile.perf +6 -2
@@ -396,6 +396,10 @@ export PYTHON_EXTBUILD_LIB PYTHON_EXTBUILD_TMP python-clean := $(call QUIET_CLEAN, python) $(RM) -r $(PYTHON_EXTBUILD) $(OUTPUT)python/perf*.so +ifneq ($(quiet),) +python_setup_quiet=--quiet +endif + # Use the detected configuration -include $(OUTPUT).config-detected
@@ -741,7 +745,7 @@ $(OUTPUT)python/perf$(PYTHON_EXTENSION_SUFFIX): util/python.c util/setup.py $(PE $(QUIET_GEN)LDSHARED="$(CC) -pthread -shared" \ CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS) $(LIBS_PY)' \ $(PYTHON_WORD) util/setup.py \ - --quiet build_ext; \ + $(python_setup_quiet) build_ext; \ cp $(PYTHON_EXTBUILD_LIB)perf*.so $(OUTPUT)python/ python_perf_target:
@@ -1166,7 +1170,7 @@ install-bin: install-tools install-tests install: install-bin try-install-man install-python_ext: - $(PYTHON_WORD) util/setup.py --quiet install --root='/$(DESTDIR_SQ)' + $(PYTHON_WORD) util/setup.py $(python_setup_quiet) install --root='/$(DESTDIR_SQ)' # 'make install-doc' should call 'make -C Documentation install' $(INSTALL_DOC_TARGETS):
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 976/2151 perf build: Do not duplicate CFLAGS in Python extension builds
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jens Remus <[email protected]>
[ Upstream commit bcd2cc4405bdb9ac77210d0df5990d46c311be66 ]
setuptools already uses CFLAGS. Passing CFLAGS with additional flags as extra compile arguments causes CFLAGS to effectively get passed twice:
$ make -C tools/perf V=1 JOBS=1 ... building 'perf' extension gcc [CFLAGS] -fPIC -Iutil/include -I/usr/include/python3.14 \ -c /root/linux/tools/perf/util/python.c \ -o python_ext_build/tmp/root/linux/tools/perf/util/python.o \ [CFLAGS] \ -fno-strict-aliasing -Wno-write-strings -Wno-unused-parameter \ -Wno-redundant-decls -Wno-cast-function-type \ -Wno-declaration-after-statement
Stable-dep-of: 2ed38aa8a52d ("perf python: Track linked libraries as extension dependencies")
--- tools/perf/util/setup.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
tools/perf/util/setup.py +6 -7
@@ -74,18 +74,17 @@ class install_lib(_install_lib): self.build_dir = build_lib -cflags = getenv('CFLAGS', '').split() # switch off several checks (need to be at the end of cflags list) -cflags += ['-fno-strict-aliasing', '-Wno-write-strings', '-Wno-unused-parameter', '-Wno-redundant-decls' ] +extra_cflags = ['-fno-strict-aliasing', '-Wno-write-strings', '-Wno-unused-parameter', '-Wno-redundant-decls' ] if cc_is_clang: - cflags += ["-Wno-unused-command-line-argument" ] + extra_cflags += ["-Wno-unused-command-line-argument" ] if clang_has_option("-Wno-cast-function-type-mismatch"): - cflags += ["-Wno-cast-function-type-mismatch" ] + extra_cflags += ["-Wno-cast-function-type-mismatch" ] else: - cflags += ['-Wno-cast-function-type' ] + extra_cflags += ['-Wno-cast-function-type' ] # The python headers have mixed code with declarations (decls after asserts, for instance) -cflags += [ "-Wno-declaration-after-statement" ] +extra_cflags += [ "-Wno-declaration-after-statement" ] src_perf = f'{srctree}/tools/perf' build_lib = getenv('PYTHON_EXTBUILD_LIB')
@@ -94,7 +93,7 @@ build_tmp = getenv('PYTHON_EXTBUILD_TMP') perf = Extension('perf', sources = [ src_perf + '/util/python.c' ], include_dirs = ['util/include'], - extra_compile_args = cflags, + extra_compile_args = extra_cflags, ) setup(name='perf',
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 977/2151 perf python: Add perf.pyi stubs file
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Rogers <[email protected]>
[ Upstream commit fed8332b0e0ba9dec1729f0422f0b0d96f7893f2 ]
Add Python type stubs for the perf module to improve IDE support and static analysis. Includes docstrings for classes, methods, and constants derived from C source and JSON definitions.
Stable-dep-of: 2ed38aa8a52d ("perf python: Track linked libraries as extension dependencies")
--- tools/perf/Makefile.perf | 7 +- tools/perf/python/perf.pyi | 672 +++++++++++++++++++++++++++++++++++++ tools/perf/util/setup.py | 5 + 3 files changed, 682 insertions(+), 2 deletions(-) create mode 100644 tools/perf/python/perf.pyi
tools/perf/Makefile.perf +5 -2
@@ -741,12 +741,15 @@ all: shell_compatibility_test $(ALL_PROGRAMS) $(LANG_BINDINGS) $(OTHER_PROGRAMS) # Create python binding output directory if not already present $(shell [ -d '$(OUTPUT)python' ] || mkdir -p '$(OUTPUT)python') -$(OUTPUT)python/perf$(PYTHON_EXTENSION_SUFFIX): util/python.c util/setup.py $(PERFLIBS_PY) +$(OUTPUT)python/perf$(PYTHON_EXTENSION_SUFFIX): util/python.c util/setup.py python/perf.pyi $(PERFLIBS_PY) $(QUIET_GEN)LDSHARED="$(CC) -pthread -shared" \ CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS) $(LIBS_PY)' \ $(PYTHON_WORD) util/setup.py \ $(python_setup_quiet) build_ext; \ - cp $(PYTHON_EXTBUILD_LIB)perf*.so $(OUTPUT)python/ + cp $(PYTHON_EXTBUILD_LIB)perf*.so $(OUTPUT)python/; \ + if [ "$(abspath python/perf.pyi)" != "$(abspath $(OUTPUT)python/perf.pyi)" ]; then \ + cp python/perf.pyi $(OUTPUT)python/; \ + fi python_perf_target: @echo "Target is: $(OUTPUT)python/perf$(PYTHON_EXTENSION_SUFFIX)"
tools/perf/python/perf.pyi new file +672 -0
672 lines not on this page · raw message
tools/perf/util/setup.py +5 -0
@@ -2,6 +2,7 @@ from os import getenv, path from subprocess import Popen, PIPE from re import sub import shlex +import shutil cc = getenv("CC") assert cc, "Environment variable CC not set"
@@ -73,6 +74,10 @@ class install_lib(_install_lib): _install_lib.finalize_options(self) self.build_dir = build_lib + def run(self): + _install_lib.run(self) + shutil.copy2(f'{src_perf}/python/perf.pyi', self.install_dir) + # switch off several checks (need to be at the end of cflags list) extra_cflags = ['-fno-strict-aliasing', '-Wno-write-strings', '-Wno-unused-parameter', '-Wno-redundant-decls' ]
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 978/2151 perf python: Clean up and restructure setup.py
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Rogers <[email protected]>
[ Upstream commit 1fa8d81be1ebaf0393a5141c48916f335e26f2f2 ]
Clean up and restructure the python setup script to resolve pylint warnings, improve code quality, and increase robustness and readability, targeting Python 3.9+ (the Linux kernel build minimum Python version).
Changes:
- Restructure the script to use a main() function as the entry point, leaving only imports, classes, and pure functions at module level.
- Eliminate all global/module-level variables, making them local to main() or the respective classes/functions.
- Make clang_has_option a pure function by passing all necessary parameters explicitly.
- Extract clang compiler flag filtering into a new filter_clang_options helper function. This function uses a loop over a tuple of options, replacing ~30 lines of repetitive blocks and reducing branch/statement complexity in the main flow.
- Cleanly define attributes in __init__ for BuildExt and InstallLib and read environment variables dynamically within the methods (including srctree in InstallLib.run), removing their dependency on global variables.
- Replace legacy Popen with subprocess.run for safer process handling.
- Use quote-aware flag filtering (shlex.split, filter, shlex.join) on sysconfig CFLAGS and OPT instead of regex re.sub substitutions. This avoids boundary bugs and safely handles quoted arguments and options with values.
- Rely on setuptools to handle user CFLAGS from the environment directly rather than manually prepending them to extra_compile_args.
- Safely parse CC env var using shlex.split to handle quotes and pass compiler arguments as list[str] lists to helper functions, avoiding redundant string formatting and parsing.
- Remove unused import re.
- Rename setuptools command subclasses to PascalCase (BuildExt, InstallLib).
- Add type annotations to functions and methods.
- Add missing docstrings for module, functions, and classes.
- Split long lines to adhere to standard limits.
Stable-dep-of: 2ed38aa8a52d ("perf python: Track linked libraries as extension dependencies")
--- tools/perf/util/setup.py | 256 ++++++++++++++++++++++++++------------- 1 file changed, 169 insertions(+), 87 deletions(-)
tools/perf/util/setup.py +169 -87
@@ -1,112 +1,194 @@ -from os import getenv, path -from subprocess import Popen, PIPE -from re import sub +# SPDX-License-Identifier: GPL-2.0 +"""Setup script for perf python extension. + +This script is used to build and install the perf python binding. +It handles compiler-specific flags, especially for clang, and configures +the setuptools Extension. +""" + +import os import shlex import shutil +import subprocess +import sysconfig -cc = getenv("CC") -assert cc, "Environment variable CC not set" +from setuptools import setup, Extension +from setuptools.command.build_ext import build_ext as _build_ext +from setuptools.command.install_lib import install_lib as _install_lib -# Check if CC has options, as is the case in yocto, where it uses CC="cc --sysroot..." -cc_tokens = cc.split() -if len(cc_tokens) > 1: - cc = cc_tokens[0] - cc_options = " ".join([str(e) for e in cc_tokens[1:]]) + " " -else: - cc_options = "" -# ignore optional stderr could be None as it is set to PIPE to avoid that. -# mypy: disable-error-code="union-attr" -cc_is_clang = b"clang version" in Popen([cc, "-v"], stderr=PIPE).stderr.readline() +def clang_has_option(cc: str, cc_args: list[str], src_feature_tests: str, option: str) -> bool: + """Check if clang supports a specific option. -srctree = getenv('srctree') -assert srctree, "Environment variable srctree, for the Linux sources, not set" -src_feature_tests = f'{srctree}/tools/build/feature' + Args: + cc: The compiler executable. + cc_args: Compiler arguments from CC environment variable. + src_feature_tests: Path to the feature tests directory. + option: The compiler option to check (e.g., "-mcet"). -def clang_has_option(option): + Returns: + True if the option is supported, False otherwise. + """ error_substrings = ( b"unknown argument", b"is not supported", b"unknown warning option" ) - cmd = shlex.split(f"{cc} {cc_options} {option}") + [ + cmd = [cc] + cc_args + [ + option, "-o", "/dev/null", - path.join(src_feature_tests, "test-hello.c") + os.path.join(src_feature_tests, "test-hello.c") ] - cc_output = Popen(cmd, stderr=PIPE).stderr.readlines() + try: + res = subprocess.run(cmd, stderr=subprocess.PIPE, stdout=subprocess.DEVNULL, check=False) + cc_output = res.stderr.splitlines() + except OSError: + return False return not any(any(error in line for error in error_substrings) for line in cc_output) -if cc_is_clang: - from sysconfig import get_config_vars - vars = get_config_vars() + +def filter_clang_options(cc: str, cc_args: list[str], src_feature_tests: str) -> None: + """Filter out unsupported clang options from sysconfig CFLAGS and OPT. + + Args: + cc: The compiler executable. + cc_args: Compiler arguments from CC environment variable. + src_feature_tests: Path to the feature tests directory. + """ + config_vars = sysconfig.get_config_vars() for var in ('CFLAGS', 'OPT'): - vars[var] = sub("-specs=[^ ]+", "", vars[var]) - if not clang_has_option("-mcet"): - vars[var] = sub("-mcet", "", vars[var]) - if not clang_has_option("-fcf-protection"): - vars[var] = sub("-fcf-protection", "", vars[var]) - if not clang_has_option("-fstack-clash-protection"): - vars[var] = sub("-fstack-clash-protection", "", vars[var]) - if not clang_has_option("-fstack-protector-strong"): - vars[var] = sub("-fstack-protector-strong", "", vars[var]) - if not clang_has_option("-fno-semantic-interposition"): - vars[var] = sub("-fno-semantic-interposition", "", vars[var]) - if not clang_has_option("-ffat-lto-objects"): - vars[var] = sub("-ffat-lto-objects", "", vars[var]) - if not clang_has_option("-ftree-loop-distribute-patterns"): - vars[var] = sub("-ftree-loop-distribute-patterns", "", vars[var]) - if not clang_has_option("-gno-variable-location-views"): - vars[var] = sub("-gno-variable-location-views", "", vars[var]) + if var not in config_vars: + continue + + # Split into individual flags using shlex to preserve quoted arguments + flags = shlex.split(config_vars[var]) + + # Remove -specs=... + flags = [f for f in flags if not f.startswith("-specs=")] + + options = ( + "-mcet", + "-fcf-protection", + "-fstack-clash-protection", + "-fstack-protector-strong", + "-fno-semantic-interposition", + "-ffat-lto-objects", + "-ftree-loop-distribute-patterns", + "-gno-variable-location-views" + ) + for option in options: + if not clang_has_option(cc, cc_args, src_feature_tests, option): + # Remove the option and any variant (e.g. -option=...) + flags = [f for f in flags if not f.startswith(option)] + + # Re-join flags preserving quoting + config_vars[var] = shlex.join(flags) + + +class BuildExt(_build_ext): + """Custom build_ext command to set output directories.""" + + def __init__(self, *args, **kwargs): + self.build_lib = None + self.build_temp = None + super().__init__(*args, **kwargs) + + def finalize_options(self) -> None: + _build_ext.finalize_options(self) + build_lib = os.getenv('PYTHON_EXTBUILD_LIB') + build_tmp = os.getenv('PYTHON_EXTBUILD_TMP') + if build_lib: + self.build_lib = build_lib + if build_tmp: + self.build_temp = build_tmp -from setuptools import setup, Extension -from setuptools.command.build_ext import build_ext as _build_ext -from setuptools.command.install_lib import install_lib as _install_lib +class InstallLib(_install_lib): + """Custom install_lib command to set output directory.""" -class build_ext(_build_ext): - def finalize_options(self): - _build_ext.finalize_options(self) - self.build_lib = build_lib - self.build_temp = build_tmp + def __init__(self, *args, **kwargs): + self.build_dir = None + super().__init__(*args, **kwargs) -class install_lib(_install_lib): - def finalize_options(self): + def finalize_options(self) -> None: _install_lib.finalize_options(self) - self.build_dir = build_lib + build_lib = os.getenv('PYTHON_EXTBUILD_LIB') + if build_lib: + self.build_dir = build_lib def run(self): _install_lib.run(self) - shutil.copy2(f'{src_perf}/python/perf.pyi', self.install_dir) - - -# switch off several checks (need to be at the end of cflags list) -extra_cflags = ['-fno-strict-aliasing', '-Wno-write-strings', '-Wno-unused-parameter', '-Wno-redundant-decls' ] -if cc_is_clang: - extra_cflags += ["-Wno-unused-command-line-argument" ] - if clang_has_option("-Wno-cast-function-type-mismatch"): - extra_cflags += ["-Wno-cast-function-type-mismatch" ] -else: - extra_cflags += ['-Wno-cast-function-type' ] - -# The python headers have mixed code with declarations (decls after asserts, for instance) -extra_cflags += [ "-Wno-declaration-after-statement" ] - -src_perf = f'{srctree}/tools/perf' -build_lib = getenv('PYTHON_EXTBUILD_LIB') -build_tmp = getenv('PYTHON_EXTBUILD_TMP') - -perf = Extension('perf', - sources = [ src_perf + '/util/python.c' ], - include_dirs = ['util/include'], - extra_compile_args = extra_cflags, - ) - -setup(name='perf', - version='0.1', - description='Interface with the Linux profiling infrastructure', - author='Arnaldo Carvalho de Melo', - author_email='[email protected]', - license='GPLv2', - url='http://perf.wiki.kernel.org', - ext_modules=[perf], - cmdclass={'build_ext': build_ext, 'install_lib': install_lib}) + srctree = os.getenv('srctree', '.') + src_perf = os.path.join(srctree, 'tools/perf') + shutil.copy2(os.path.join(src_perf, 'python/perf.pyi'), self.install_dir) + + +def main() -> None: + """Main entry point for the setup script.""" + cc_env = os.getenv("CC") + assert cc_env, "Environment variable CC not set" + + # Safe parsing of CC environment variable which might contain options/quotes + cc_tokens = shlex.split(cc_env) + cc = cc_tokens[0] + cc_args = cc_tokens[1:] + + # Run CC -v to check if it is clang. + try: + cc_info = subprocess.run( + [cc, "-v"], stderr=subprocess.PIPE, stdout=subprocess.DEVNULL, check=False + ) + cc_is_clang = b"clang version" in cc_info.stderr + except OSError as e: + raise RuntimeError(f"Failed to execute compiler '{cc}': {e}") from e + + srctree = os.getenv('srctree') + assert srctree, "Environment variable srctree, for the Linux sources, not set" + src_feature_tests = f'{srctree}/tools/build/feature' + + if cc_is_clang: + filter_clang_options(cc, cc_args, src_feature_tests) + + # switch off several checks (need to be at the end of cflags list) + cflags = [ + '-fno-strict-aliasing', + '-Wno-write-strings', + '-Wno-unused-parameter', + '-Wno-redundant-decls' + ] + if cc_is_clang: + cflags += ["-Wno-unused-command-line-argument"] + if clang_has_option( + cc, cc_args, src_feature_tests, "-Wno-cast-function-type-mismatch" + ): + cflags += ["-Wno-cast-function-type-mismatch"] + else: + cflags += ['-Wno-cast-function-type'] + + # The python headers have mixed code with declarations (decls after asserts, for instance) + cflags += ["-Wno-declaration-after-statement"] + + src_perf = f'{srctree}/tools/perf' + + perf = Extension( + 'perf', + sources=[os.path.join(src_perf, 'util/python.c')], + include_dirs=['util/include'], + extra_compile_args=cflags, + ) + + setup( + name='perf', + version='0.1', + description='Interface with the Linux profiling infrastructure', + author='Arnaldo Carvalho de Melo', + author_email='[email protected]', + license='GPLv2', + url='http://perf.wiki.kernel.org', + ext_modules=[perf], + cmdclass={'build_ext': BuildExt, 'install_lib': InstallLib}, + ) + + +if __name__ == '__main__': + main()
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 979/2151 perf python: Track linked libraries as extension dependencies
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: James Clark <[email protected]>
[ Upstream commit 2ed38aa8a52d3e245a9f71b98825ad7f77956d50 ]
Since the Python extension switched to linking perf libraries, setup.py only lists util/python.c as a source. The libraries are supplied through LDFLAGS, which setuptools does not consider when deciding whether the extension needs to be rebuilt.
When a library changes, make invokes setup.py, but setuptools can skip the build and the recipe copies the stale cached extension back into python/. This leaves perf and its Python module running different versions of the same code.
Pass the linked library paths to setup.py and declare them as Extension dependencies so that library changes trigger a rebuild. Include EXTRA_PERFLIBS in the shared library list so that both make and setuptools track those inputs as well, preserving the existing linker order.
--- tools/perf/Makefile.perf | 5 +++-- tools/perf/util/setup.py | 1 + 2 files changed, 4 insertions(+), 2 deletions(-)
tools/perf/Makefile.perf +3 -2
@@ -482,8 +482,8 @@ endif EXTLIBS := $(call filter-out,$(EXCLUDE_EXTLIBS),$(EXTLIBS)) LIBS = -Wl,--whole-archive $(PERFLIBS) $(EXTRA_PERFLIBS) -Wl,--no-whole-archive -Wl,--start-group $(EXTLIBS) -Wl,--end-group -PERFLIBS_PY := $(call filter-out,$(LIBPERF_BENCH) $(LIBPERF_TEST),$(PERFLIBS)) -LIBS_PY = -Wl,--whole-archive $(PERFLIBS_PY) $(EXTRA_PERFLIBS) -Wl,--no-whole-archive -Wl,--start-group $(EXTLIBS) -Wl,--end-group +PERFLIBS_PY := $(call filter-out,$(LIBPERF_BENCH) $(LIBPERF_TEST),$(PERFLIBS)) $(EXTRA_PERFLIBS) +LIBS_PY = -Wl,--whole-archive $(PERFLIBS_PY) -Wl,--no-whole-archive -Wl,--start-group $(EXTLIBS) -Wl,--end-group export INSTALL SHELL_PATH
@@ -744,6 +744,7 @@ $(shell [ -d '$(OUTPUT)python' ] || mkdir -p '$(OUTPUT)python') $(OUTPUT)python/perf$(PYTHON_EXTENSION_SUFFIX): util/python.c util/setup.py python/perf.pyi $(PERFLIBS_PY) $(QUIET_GEN)LDSHARED="$(CC) -pthread -shared" \ CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS) $(LIBS_PY)' \ + PYTHON_EXT_DEPS='$(PERFLIBS_PY)' \ $(PYTHON_WORD) util/setup.py \ $(python_setup_quiet) build_ext; \ cp $(PYTHON_EXTBUILD_LIB)perf*.so $(OUTPUT)python/; \
tools/perf/util/setup.py +1 -0
@@ -173,6 +173,7 @@ def main() -> None: perf = Extension( 'perf', sources=[os.path.join(src_perf, 'util/python.c')], + depends=shlex.split(os.getenv('PYTHON_EXT_DEPS', '')), include_dirs=['util/include'], extra_compile_args=cflags, )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 980/2151 riscv: dts: starfive: Add common board dtsi for VisionFive 2 Lite variants
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hal Feng <[email protected]>
[ Upstream commit 2ad6d71a0de8b44e6803f11936398b55643c81aa ]
Add a common board dtsi for use by VisionFive 2 Lite and VisionFive 2 Lite eMMC.
Stable-dep-of: 2186ec5f59c2 ("riscv: dts: starfive: Correct pwm nodes")
--- .../jh7110-starfive-visionfive-2-lite.dtsi | 161 ++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 arch/riscv/boot/dts/starfive/jh7110-starfive-visionfive-2-lite.dtsi
arch/riscv/boot/dts/starfive/jh7110-starfive-visionfive-2-lite.dtsi new file +161 -0
@@ -0,0 +1,161 @@ +// SPDX-License-Identifier: GPL-2.0 OR MIT +/* + * Copyright (C) 2025 StarFive Technology Co., Ltd. + * Copyright (C) 2025 Hal Feng <[email protected]> + */ + +/dts-v1/; +#include "jh7110-common.dtsi" + +/ { + vcc_3v3_pcie: regulator-vcc-3v3-pcie { + compatible = "regulator-fixed"; + enable-active-high; + gpio = <&sysgpio 27 GPIO_ACTIVE_HIGH>; + regulator-name = "vcc_3v3_pcie"; + regulator-min-microvolt = <3300000>; + regulator-max-microvolt = <3300000>; + }; +}; + +&cpu_opp { + /delete-node/ opp-375000000; + /delete-node/ opp-500000000; + /delete-node/ opp-750000000; + /delete-node/ opp-1500000000; + + opp-312500000 { + opp-hz = /bits/ 64 <312500000>; + opp-microvolt = <800000>; + }; + opp-417000000 { + opp-hz = /bits/ 64 <417000000>; + opp-microvolt = <800000>; + }; + opp-625000000 { + opp-hz = /bits/ 64 <625000000>; + opp-microvolt = <800000>; + }; + opp-1250000000 { + opp-hz = /bits/ 64 <1250000000>; + opp-microvolt = <1000000>; + }; +}; + +&gmac0 { + starfive,tx-use-rgmii-clk; + assigned-clocks = <&aoncrg JH7110_AONCLK_GMAC0_TX>; + assigned-clock-parents = <&aoncrg JH7110_AONCLK_GMAC0_RMII_RTX>; + status = "okay"; +}; + +&i2c0 { + status = "okay"; +}; + +&mmc1 { + max-frequency = <50000000>; + keep-power-in-suspend; + non-removable; +}; + +&pcie1 { + vpcie3v3-supply = <&vcc_3v3_pcie>; + status = "okay"; +}; + +&phy0 { + motorcomm,tx-clk-adj-enabled; + motorcomm,tx-clk-100-inverted; + motorcomm,tx-clk-1000-inverted; + motorcomm,rx-clk-drv-microamp = <3970>; + motorcomm,rx-data-drv-microamp = <2910>; + rx-internal-delay-ps = <1500>; + tx-internal-delay-ps = <1500>; +}; + +&pwm { + status = "okay"; +}; + +&spi0 { + status = "okay"; +}; + +&syscrg { + assigned-clock-rates = <0>, <0>, <0>, <0>, <500000000>, <1250000000>; +}; + +&sysgpio { + uart1_pins: uart1-0 { + tx-pins { + pinmux = <GPIOMUX(22, GPOUT_SYS_UART1_TX, + GPOEN_ENABLE, + GPI_NONE)>; + bias-disable; + drive-strength = <12>; + input-disable; + input-schmitt-disable; + slew-rate = <0>; + }; + + rx-pins { + pinmux = <GPIOMUX(23, GPOUT_LOW, + GPOEN_DISABLE, + GPI_SYS_UART1_RX)>; + bias-pull-up; + drive-strength = <2>; + input-enable; + input-schmitt-enable; + slew-rate = <0>; + }; + + cts-pins { + pinmux = <GPIOMUX(24, GPOUT_LOW, + GPOEN_DISABLE, + GPI_SYS_UART1_CTS)>; + input-enable; + }; + + rts-pins { + pinmux = <GPIOMUX(25, GPOUT_SYS_UART1_RTS, + GPOEN_ENABLE, + GPI_NONE)>; + input-enable; + }; + }; + + usb0_pins: usb0-0 { + power-pins { + pinmux = <GPIOMUX(26, GPOUT_HIGH, + GPOEN_ENABLE, + GPI_NONE)>; + input-disable; + }; + + switch-pins { + pinmux = <GPIOMUX(62, GPOUT_LOW, + GPOEN_ENABLE, + GPI_NONE)>; + input-disable; + }; + }; +}; + +&uart1 { + pinctrl-names = "default"; + pinctrl-0 = <&uart1_pins>; + status = "okay"; +}; + +&usb0 { + dr_mode = "host"; + pinctrl-names = "default"; + pinctrl-0 = <&usb0_pins>; + status = "okay"; +}; + +&usb_cdns3 { + phys = <&usbphy0>, <&pciephy0>; + phy-names = "cdns3,usb2-phy", "cdns3,usb3-phy"; +};
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 981/2151 riscv: dts: starfive: Correct pwm nodes
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hal Feng <[email protected]>
[ Upstream commit 2186ec5f59c23fcf0bf896ca0543b6a1135d7bb5 ]
Each of the StarFive JH7100/JH7110 SoCs has 8 OpenCores PTC IP cores. One OpenCores PTC IP core can output one PWM channel. Change the register size to 0x10, since an OpenCores PTC IP has only 4 32-bit registers: CNTR, HRC, LRC and CTRL.
--- .../boot/dts/starfive/jh7100-common.dtsi | 28 ++++++-- arch/riscv/boot/dts/starfive/jh7100.dtsi | 67 ++++++++++++++++++- .../boot/dts/starfive/jh7110-common.dtsi | 27 ++++++-- .../boot/dts/starfive/jh7110-milkv-mars.dts | 6 +- .../dts/starfive/jh7110-milkv-marscm.dtsi | 6 +- .../dts/starfive/jh7110-pine64-star64.dts | 6 +- .../jh7110-starfive-visionfive-2-lite.dtsi | 6 +- .../jh7110-starfive-visionfive-2.dtsi | 6 +- arch/riscv/boot/dts/starfive/jh7110.dtsi | 67 ++++++++++++++++++- 9 files changed, 198 insertions(+), 21 deletions(-)
arch/riscv/boot/dts/starfive/jh7100-common.dtsi +22 -6
@@ -199,13 +199,23 @@ GPO_I2C2_PAD_SDA_OEN, }; }; - pwm_pins: pwm-0 { - pwm-pins { + pwm0_pins: pwm0-0 { + pwm0-pins { pinmux = <GPIOMUX(7, GPO_PWM_PAD_OUT_BIT0, GPO_PWM_PAD_OE_N_BIT0, - GPI_NONE)>, - <GPIOMUX(5, + GPI_NONE)>; + bias-disable; + drive-strength = <35>; + input-disable; + input-schmitt-disable; + slew-rate = <0>; + }; + }; + + pwm1_pins: pwm1-0 { + pwm1-pins { + pinmux = <GPIOMUX(5, GPO_PWM_PAD_OUT_BIT1, GPO_PWM_PAD_OE_N_BIT1, GPI_NONE)>;
@@ -359,9 +369,15 @@ &osc_aud { clock-frequency = <27000000>; }; -&pwm { +&pwm0 { + pinctrl-names = "default"; + pinctrl-0 = <&pwm0_pins>; + status = "okay"; +}; + +&pwm1 { pinctrl-names = "default"; - pinctrl-0 = <&pwm_pins>; + pinctrl-0 = <&pwm1_pins>; status = "okay"; };
arch/riscv/boot/dts/starfive/jh7100.dtsi +65 -2
74 lines not on this page · raw message
arch/riscv/boot/dts/starfive/jh7110-common.dtsi +21 -6
@@ -359,9 +359,14 @@ uboot@100000 { }; }; -&pwm { +&pwm0 { pinctrl-names = "default"; - pinctrl-0 = <&pwm_pins>; + pinctrl-0 = <&pwm0_pins>; +}; + +&pwm1 { + pinctrl-names = "default"; + pinctrl-0 = <&pwm1_pins>; }; &spi0 {
@@ -572,12 +577,22 @@ GPOEN_ENABLE, }; }; - pwm_pins: pwm-0 { - pwm-pins { + pwm0_pins: pwm0-0 { + pwm0-pins { pinmux = <GPIOMUX(46, GPOUT_SYS_PWM_CHANNEL0, GPOEN_SYS_PWM0_CHANNEL0, - GPI_NONE)>, - <GPIOMUX(59, GPOUT_SYS_PWM_CHANNEL1, + GPI_NONE)>; + bias-disable; + drive-strength = <12>; + input-disable; + input-schmitt-disable; + slew-rate = <0>; + }; + }; + + pwm1_pins: pwm1-0 { + pwm1-pins { + pinmux = <GPIOMUX(59, GPOUT_SYS_PWM_CHANNEL1, GPOEN_SYS_PWM0_CHANNEL1, GPI_NONE)>; bias-disable;
arch/riscv/boot/dts/starfive/jh7110-milkv-mars.dts +5 -1
@@ -41,7 +41,11 @@ &phy0 { motorcomm,tx-clk-adj-enabled; }; -&pwm { +&pwm0 { + status = "okay"; +}; + +&pwm1 { status = "okay"; };
arch/riscv/boot/dts/starfive/jh7110-milkv-marscm.dtsi +5 -1
@@ -74,7 +74,11 @@ &phy0 { motorcomm,tx-clk-adj-enabled; }; -&pwm { +&pwm0 { + status = "okay"; +}; + +&pwm1 { status = "okay"; };
arch/riscv/boot/dts/starfive/jh7110-pine64-star64.dts +5 -1
@@ -68,7 +68,11 @@ &phy1 { motorcomm,tx-clk-100-inverted; }; -&pwm { +&pwm0 { + status = "okay"; +}; + +&pwm1 { status = "okay"; };
arch/riscv/boot/dts/starfive/jh7110-starfive-visionfive-2-lite.dtsi +5 -1
@@ -74,7 +74,11 @@ &phy0 { tx-internal-delay-ps = <1500>; }; -&pwm { +&pwm0 { + status = "okay"; +}; + +&pwm1 { status = "okay"; };
arch/riscv/boot/dts/starfive/jh7110-starfive-visionfive-2.dtsi +5 -1
@@ -49,7 +49,11 @@ &pcie1 { status = "okay"; }; -&pwm { +&pwm0 { + status = "okay"; +}; + +&pwm1 { status = "okay"; };
arch/riscv/boot/dts/starfive/jh7110.dtsi +65 -2
74 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 982/2151 arm64: dts: amlogic: meson-sm1-odroid-hc4: mux the SPI NOR HOLD# and WP# pins
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Igor Velkov <[email protected]>
[ Upstream commit 0b825126590879812321cdab53786fcd906f7761 ]
The SPI NOR flash uses six lines, but nor_pins covers only four: data, clock and chip select. Nothing claims HOLD# (BOOT_3) and WP# (BOOT_7), so they keep the boot ROM setting. After a boot from SPI they are in the nor function and the flash works. After a boot from SD with the button under the board, they stay eMMC data lines pulled low, and spi-nor reports "unrecognized JEDEC id bytes: 00 00 00 00 00 00".
Add them as a separate group in meson-g12-common.dtsi rather than tonor_pins: whether HOLD# and WP# reach the SoC depends on the board. The HC4 has eMMC disabled and takes both groups.
Tested on ODROID-HC4: with BOOT_3 and BOOT_7 set back to eMMC with pull-down and spifc rebound, the flash fails as above without this patch and probes as a 16 MiB mtd0 with it.
--- arch/arm64/boot/dts/amlogic/meson-g12-common.dtsi | 9 +++++++++ arch/arm64/boot/dts/amlogic/meson-sm1-odroid-hc4.dts | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-)
arch/arm64/boot/dts/amlogic/meson-g12-common.dtsi +9 -0
@@ -615,6 +615,15 @@ mux { }; }; + nor_hold_wp_pins: nor-hold-wp { + mux { + groups = "nor_hold", + "nor_wp"; + function = "nor"; + bias-disable; + }; + }; + pdm_din0_a_pins: pdm-din0-a { mux { groups = "pdm_din0_a";
arch/arm64/boot/dts/amlogic/meson-sm1-odroid-hc4.dts +1 -1
@@ -124,7 +124,7 @@ &sd_emmc_c { &spifc { status = "okay"; - pinctrl-0 = <&nor_pins>; + pinctrl-0 = <&nor_pins>, <&nor_hold_wp_pins>; pinctrl-names = "default"; flash@0 {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 983/2151 arm64: dts: amlogic: meson-sm1-odroid-hc4: run the SPI NOR at 40 MHz
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Igor Velkov <[email protected]>
[ Upstream commit b44e2be772f866985cafdf90355285069ea68495 ]
At 104 MHz, reads return corrupted data: bit 0 of the first byte of a transfer flips from 0 to 1 part of the time. The same byte read as the second byte of a transfer was correct in all 100 reads. One 4 KiB block read 200 times came back wrong 157 times. Writes are unaffected.
flashcp verifies while it writes, so a bootloader update erases blocks it should skip and can abort halfway, with the flash half written.
The Hardkernel vendor device tree for this board uses 40 MHz. At 40 MHz the same tests pass: 200 block reads with no mismatch, and 14 flashcp runs with no block erased.
Tested on ODROID-HC4 with an XT25F128B.
--- arch/arm64/boot/dts/amlogic/meson-sm1-odroid-hc4.dts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/boot/dts/amlogic/meson-sm1-odroid-hc4.dts +1 -1
@@ -132,7 +132,7 @@ flash@0 { #size-cells = <1>; compatible = "jedec,spi-nor"; reg = <0>; - spi-max-frequency = <104000000>; + spi-max-frequency = <40000000>; }; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 984/2151 soc/tegra: flowctrl: Release OF node reference on error
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuho Choi <[email protected]>
[ Upstream commit 4eaed7ea6ab36e1160d660b05551702c36dfed6c ]
tegra_flowctrl_init() obtains a reference from of_find_matching_node() and currently releases it only after of_address_to_resource() succeeds.
Release the reference before checking the resource conversion result so the error path is balanced as well.
--- drivers/soc/tegra/flowctrl.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/soc/tegra/flowctrl.c +5 -2
@@ -195,11 +195,14 @@ static int __init tegra_flowctrl_init(void) np =of_find_matching_node (NULL , tegra_flowctrl_match);if (np) { -if (of_address_to_resource (np,0 , &res) <0 ) { +int err =of_address_to_resource (np,0 , &res); + +of_node_put (np); + +if (err <0 ) {pr_err ("failed to get flowctrl register\n" );return -ENXIO ; } -of_node_put (np); }else if (IS_ENABLED (CONFIG_ARM )) {/* * Hardcoded fallback for 32-bit Tegra
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 985/2151 drm/msm/dp: dont report link training success after a reinit
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oleg Keri <[email protected]>
[ Upstream commit a47987366e7fc2c05aeffc97f8e1f776e583f792 ]
When every training attempt fails, the retry loop in msm_dp_ctrl_on_link() ends on a successful msm_dp_ctrl_reinitialize_mainlink(), leaving rc at 0. The caller then enables the stream on an untrained link and the display stays dark.
The retry counter only reaches zero in that case, so treat it as a training failure.
Patchwork: https://patchwork.freedesktop.org/patch/756528/
--- drivers/gpu/drm/msm/dp/dp_ctrl.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpu/drm/msm/dp/dp_ctrl.c +3 -0
@@ -2361,6 +2361,9 @@ int msm_dp_ctrl_on_link(struct msm_dp_ctrl *msm_dp_ctrl)if (ctrl->link->sink_request &DP_TEST_LINK_PHY_TEST_PATTERN )return rc; +if (!link_train_max_retries) + rc = -ETIMEDOUT ; +if (rc ==0 ) {/* link train successfully */ /* * do not stop train pattern here
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 986/2151 drm/msm/dpu: disable the slave encoder before the master
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joonhoe Kim <[email protected]>
[ Upstream commit 32d04280ddebb6eb964990931b0f1001f63b35e7 ]
dpu_encoder_virt_atomic_disable() disables the physical encoders in phys_encs[] order, i.e. the master first. With a split display (two interfaces on one CTL, e.g. bonded DSI) the master's dpu_encoder_helper_phys_cleanup() then resets the shared CTL while the slave's timing engine is still running, and the source pipe is left stalled half-way through the slave's next frame.
A power collapse of the MDSS core GDSC clears the stall, so it normally goes unnoticed. When MDSS stays powered across the disable (a full modeset, or an active DP controller), the next enable scans out
nothing: black screen with the backlight on.
Disable the slave before the master, as atomic_enable() enables them in that order. The slave's cleanup still resets the CTL while the master is running, but the last reset, from the master's cleanup, now happens with both timing engines stopped.
Tested on a Lenovo Legion Tab Y700 gen 5 (SM8850, bonded DSI video-mode panel) with MDSS kept active:
echo on > /sys/bus/platform/devices/9800000.display-subsystem/power/control
DPMS off/on: black 10/10 before, picture 10/10 after. Full modesets were not retested with this version. Only tested on this device.
Patchwork: https://patchwork.freedesktop.org/patch/757684/
--- drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/gpu/drm/msm/disp/dpu1/dpu_encoder.c +4 -6
@@ -1379,7 +1379,6 @@ static void dpu_encoder_virt_atomic_disable(struct drm_encoder *drm_enc,struct dpu_encoder_virt *dpu_enc =NULL ;struct drm_crtc *crtc;struct drm_crtc_state *old_state =NULL ; -int i =0 ; dpu_enc =to_dpu_encoder_virt (drm_enc);DPU_DEBUG_ENC (dpu_enc,"\n" );
@@ -1405,12 +1404,11 @@ static void dpu_encoder_virt_atomic_disable(struct drm_encoder *drm_enc,dpu_encoder_resource_control (drm_enc,DPU_ENC_RC_EVENT_PRE_STOP ); -for (i =0 ; i < dpu_enc->num_phys_encs; i++) { -struct dpu_encoder_phys *phys = dpu_enc->phys_encs[i]; +if (dpu_enc->cur_slave && dpu_enc->cur_slave->ops.disable) + dpu_enc->cur_slave->ops.disable (dpu_enc->cur_slave); -if (phys->ops.disable) - phys->ops.disable (phys); - } +if (dpu_enc->cur_master && dpu_enc->cur_master->ops.disable) + dpu_enc->cur_master->ops.disable (dpu_enc->cur_master);/* after phys waits for frame-done, should be no more frames pending */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 987/2151 drm/msm/dpu: compute the CRTC bandwidth from the state being checked
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joonhoe Kim <[email protected]>
[ Upstream commit 480ba24aa34031c898d0a711405664cd947bbee4 ]
_dpu_core_perf_calc_bw() is called with the new CRTC state but sums plane_fetch_bw over drm_atomic_crtc_for_each_plane(), i.e. the planes of the committed state. When the CRTC is re-enabled (DPMS on, system resume) the committed state has no planes attached, so the check computes bw_ctl = 0 and the display runs without an average bandwidth vote on the MDP path until some later commit changes a plane -- which may not happen for a long time on a static screen such as a lock screen.
Seen on a Lenovo TB323FU (SM8850) through the interconnect and DPU
tracepoints: after DPMS off/on or s2idle, dpu_perf_crtc_update reported bw_ctl=0 and qnm_mdp was left at avg_bw=0 (peak 800000) instead of the 3728793 kBps voted before, until the next mode change.
Iterate the plane states of the CRTC state being checked instead. drm_atomic_crtc_state_for_each_plane_state() falls back to the current plane state for planes that are not part of the commit, so the result is unchanged for commits that do touch the planes.
With this, bw_ctl is 3728793600 right after DPMS on and after resume. Only tested on this device.
Patchwork: https://patchwork.freedesktop.org/patch/757683/
--- drivers/gpu/drm/msm/disp/dpu1/dpu_core_perf.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-)
drivers/gpu/drm/msm/disp/dpu1/dpu_core_perf.c +6 -11
@@ -54,24 +54,19 @@ u64 dpu_core_perf_adjusted_mode_clk(u64 mode_clk_rate,/** * _dpu_core_perf_calc_bw() - to calculate BW per crtc * @perf_cfg: performance configuration -* @crtc: pointer to a crtc +* @state: the CRTC state * Return: returns aggregated BW for all planes in crtc. */ static u64 _dpu_core_perf_calc_bw (const struct dpu_perf_cfg *perf_cfg, -struct drm_crtc *crtc) +struct drm_crtc_state *state) {struct drm_plane *plane; -struct dpu_plane_state *pstate; +const struct drm_plane_state *plane_state;u64 crtc_plane_bw =0 ;u32 bw_factor; -drm_atomic_crtc_for_each_plane (plane, crtc) { - pstate =to_dpu_plane_state (plane->state); -if (!pstate) -continue ; - - crtc_plane_bw += pstate->plane_fetch_bw; - } +drm_atomic_crtc_state_for_each_plane_state (plane, plane_state, state) + crtc_plane_bw +=to_dpu_plane_state (plane_state)->plane_fetch_bw; bw_factor = perf_cfg->bw_inefficiency_factor;if (bw_factor) {
@@ -131,7 +126,7 @@ static void _dpu_core_perf_calc_crtc(const struct dpu_core_perf *core_perf,return ; } - perf->bw_ctl =_dpu_core_perf_calc_bw (perf_cfg, crtc); + perf->bw_ctl =_dpu_core_perf_calc_bw (perf_cfg, state); perf->max_per_pipe_ib = perf_cfg->min_dram_ib; perf->core_clk_rate =_dpu_core_perf_calc_clk (perf_cfg, crtc, state); DRM_DEBUG_ATOMIC(
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 988/2151 coresight: Take hotplug lock in enable_source_store() for Sysfs mode
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leo Yan <[email protected]>
[ Upstream commit 2c7f786928c4319ee9c68207a28529e5226b9266 ]
The hotplug lock is acquired and released in etm{3|4}_disable_sysfs(), which are low-level functions. This prevents us from a new solution for hotplug.
Firstly, hotplug callbacks cannot invoke etm{3|4}_disable_sysfs() to disable the source; otherwise, a deadlock issue occurs. The reason is that, in the hotplug flow, the kernel acquires the hotplug lock before calling callbacks. Subsequently, if coresight_disable_source() is invoked and it calls etm{3|4}_disable_sysfs(), the hotplug lock will be acquired twice, leading to a double lock issue.
Secondly, when hotplugging a CPU on or off, if we want to manipulate all components on a path attached to the CPU, we need to maintain atomicity for the entire path. Otherwise, a race condition may occur with users setting the same path via the Sysfs knobs, ultimately causing mess states in CoreSight components.
This patch moves the hotplug locking from etm{3|4}_disable_sysfs() into enable_source_store(). As a result, when users control the Sysfs knobs, the whole flow is protected by hotplug locking, ensuring it is mutual exclusive with hotplug callbacks.
Note, the paired function etm{3|4}_enable_sysfs() does not use hotplug locking, which is why this patch does not modify it.
Stable-dep-of: 950cca5352b0 ("coresight: etm3x: fix inconsistencies with sysfs configuration")
--- drivers/hwtracing/coresight/coresight-etm3x-core.c | 8 -------- drivers/hwtracing/coresight/coresight-etm4x-core.c | 9 --------- drivers/hwtracing/coresight/coresight-sysfs.c | 7 +++++++ 3 files changed, 7 insertions(+), 17 deletions(-)
drivers/hwtracing/coresight/coresight-etm3x-core.c +0 -8
@@ -622,13 +622,6 @@ static void etm_disable_sysfs(struct coresight_device *csdev) {struct etm_drvdata *drvdata =dev_get_drvdata (csdev->dev.parent); -/* -* Taking hotplug lock here protects from clocks getting disabled -* with tracing being left on (crash scenario) if user disable occurs -* after cpu online mask indicates the cpu is offline but before the -* DYING hotplug callback is serviced by the ETM driver. -*/ -cpus_read_lock ();spin_lock (&drvdata->spinlock);/*
@@ -639,7 +632,6 @@ static void etm_disable_sysfs(struct coresight_device *csdev) drvdata, 1);spin_unlock (&drvdata->spinlock); -cpus_read_unlock ();/* * we only release trace IDs when resetting sysfs.
drivers/hwtracing/coresight/coresight-etm4x-core.c +0 -9
@@ -1117,13 +1117,6 @@ static void etm4_disable_sysfs(struct coresight_device *csdev) {struct etmv4_drvdata *drvdata =dev_get_drvdata (csdev->dev.parent); -/* -* Taking hotplug lock here protects from clocks getting disabled -* with tracing being left on (crash scenario) if user disable occurs -* after cpu online mask indicates the cpu is offline but before the -* DYING hotplug callback is serviced by the ETM driver. -*/ -cpus_read_lock ();raw_spin_lock (&drvdata->spinlock);/*
@@ -1137,8 +1130,6 @@ static void etm4_disable_sysfs(struct coresight_device *csdev)cscfg_csdev_disable_active_config (csdev); -cpus_read_unlock (); -/* * we only release trace IDs when resetting sysfs. * This permits sysfs users to read the trace ID after the trace
drivers/hwtracing/coresight/coresight-sysfs.c +7 -0
@@ -362,6 +362,13 @@ static ssize_t enable_source_store(struct device *dev,if (ret)return ret; +/* +* CoreSight hotplug callbacks in core layer control a activated path +* from its source to sink. Taking hotplug lock here protects a race +* condition with hotplug callbacks. +*/ +guard (cpus_read_lock)(); +if (val) { ret =coresight_enable_sysfs (csdev);if (ret)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 989/2151 coresight: etm3x: Set active path on target CPU
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Leo Yan <[email protected]>
[ Upstream commit bc9907750718cdaad85870c93f2c72db5c85e345 ]
Set the path pointer on the target CPU during ETM enable and disable.
This ensures the device mode and path pointer are updated together and observed atomically by the CPU PM notifier.
Stable-dep-of: 950cca5352b0 ("coresight: etm3x: fix inconsistencies with sysfs configuration")
--- .../hwtracing/coresight/coresight-etm3x-core.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/hwtracing/coresight/coresight-etm3x-core.c +14 -3
@@ -436,6 +436,7 @@ static int etm_enable_hw(struct etm_drvdata *drvdata)struct etm_enable_arg {struct etm_drvdata *drvdata; +struct coresight_path *path;int rc; };
@@ -457,8 +458,12 @@ static void etm_enable_sysfs_smp_call(void *info) arg->rc =etm_enable_hw (arg->drvdata);/* The tracer didn't start */ -if (arg->rc) +if (arg->rc) {coresight_set_mode (csdev,CS_MODE_DISABLED ); +return ; + } + + csdev->path = arg->path; }static int etm_cpu_id (struct coresight_device *csdev)
@@ -494,10 +499,13 @@ static int etm_enable_perf(struct coresight_device *csdev, ret =etm_enable_hw (drvdata);/* Failed to start tracer; roll back to DISABLED mode */ -if (ret) +if (ret) {coresight_set_mode (csdev,CS_MODE_DISABLED ); +return ret; + } -return ret; + csdev->path = path; +return 0 ; }static int etm_enable_sysfs (struct coresight_device *csdev,struct coresight_path *path)
@@ -516,6 +524,7 @@ static int etm_enable_sysfs(struct coresight_device *csdev, struct coresight_pat*/ if (cpu_online (drvdata->cpu)) { arg.drvdata = drvdata; + arg.path = path; ret =smp_call_function_single (drvdata->cpu, etm_enable_sysfs_smp_call, &arg,1 );if (!ret)
@@ -585,6 +594,7 @@ static void etm_disable_sysfs_smp_call(void *info)etm_disable_hw (drvdata); + drvdata->csdev->path =NULL ;coresight_set_mode (drvdata->csdev,CS_MODE_DISABLED ); }
@@ -609,6 +619,7 @@ static void etm_disable_perf(struct coresight_device *csdev)CS_LOCK (drvdata->csa.base); + drvdata->csdev->path =NULL ;coresight_set_mode (drvdata->csdev,CS_MODE_DISABLED );/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 990/2151 coresight: etm3x: Prohibit modifying cntr_val while session is enabled
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yeoreum Yun <[email protected]>
[ Upstream commit 88eaf963853d557957a9dcbff6b33d1626c91cb7 ]
cntr_val are overwritten with the values read from the corresponding registers by etm_disable_hw() when the session is disabled.
This means that any changes to this value made while the session is enabled would be lost when the session is disabled.
Also, reset shouldn't be called while session is enabled.
Therefore, prohibit modifying cntr_val and reset while the session is enabled.
Stable-dep-of: 950cca5352b0 ("coresight: etm3x: fix inconsistencies with sysfs configuration")
--- drivers/hwtracing/coresight/coresight-etm3x-sysfs.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +7 -0
@@ -75,6 +75,10 @@ static ssize_t reset_store(struct device *dev,if (ret)return ret; +if (IS_ERR_OR_NULL (drvdata->csdev) || +coresight_get_mode (drvdata->csdev)) +return -EBUSY ; +if (val) {spin_lock (&drvdata->spinlock);memset (config,0 ,sizeof (struct etm_config ));
@@ -744,6 +748,9 @@ static ssize_t cntr_val_store(struct device *dev, ret =kstrtoul (buf,16 , &val);if (ret)return ret; +if (IS_ERR_OR_NULL (drvdata->csdev) || +coresight_get_mode (drvdata->csdev)) +return -EBUSY ;spin_lock (&drvdata->spinlock); config->cntr_val[config->cntr_idx] = val;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 991/2151 coresight: etm3x: fix inconsistencies with sysfs configuration
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yeoreum Yun <[email protected]>
[ Upstream commit 950cca5352b009dcf8ef0ca4a2fae850d26b552f ]
The current ETM3x configuration via sysfs can lead to the following inconsistencies:
- If a configuration is modified via sysfs while a perf session is active, the running configuration may differ between before a sched-out and after a subsequent sched-in.
To resolve these issues, separate the configuration into:
- curr_config: the configuration applied to the current session
- config: the configuration set via sysfs
Additionally:
- Since curr_config and related fields are accessed only by the local CPU in etm_enable/disable_sysfs_smp_call() (similar to perf enable/disable), remove the lock/unlock from the sysfs enable/disable path and starting/dying_cpu path except when to access config fields only.
- Some of sysfs interface read etm register directly. To reduce lock scope while the etm_enable_hw()/etm_disable_hw(), handle it via IPI so that registers could be read from on proper CPU.
--- drivers/hwtracing/coresight/coresight-etm.h | 4 +- .../coresight/coresight-etm3x-core.c | 66 ++++++++------- .../coresight/coresight-etm3x-sysfs.c | 80 +++++++++++++------ 3 files changed, 98 insertions(+), 52 deletions(-)
drivers/hwtracing/coresight/coresight-etm.h +3 -1
@@ -226,7 +226,8 @@ struct etm_config {* @etmccr: value of register ETMCCR. * @etmccer: value of register ETMCCER. * @traceid: value of the current ID for this component. -* @config: structure holding configuration parameters. +* @curr_config: structure holding current running configuration. +* @config: structure holding sysfs mode configuration. */ struct etm_drvdata {struct csdev_access csa;
@@ -248,6 +249,7 @@ struct etm_drvdata {u32 etmccr;u32 etmccer;u32 traceid; +struct etm_config curr_config;struct etm_config config; };
drivers/hwtracing/coresight/coresight-etm3x-core.c +38 -28
145 lines not on this page · raw message
drivers/hwtracing/coresight/coresight-etm3x-sysfs.c +57 -23
135 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 992/2151 phy: HiSilicon: Fix error handling in hi3670_pcie_allclk_ctrl()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Akash Sukhavasi <[email protected]>
[ Upstream commit 7540fc0a4f667b6773d10753a602a42a3113087b ]
When hi3670_pcie_pll_ctrl() fails, hi3670_pcie_allclk_ctrl() returns -EINVAL directly, skipping the close_clocks cleanup path. This leaves the PLL with its power-down bit cleared.
Use goto close_clocks instead, which disables the PLL and propagates the original error code from hi3670_pcie_pll_ctrl().
Found while investigating a Smatch warning.
--- drivers/phy/hisilicon/phy-hi3670-pcie.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/phy/hisilicon/phy-hi3670-pcie.c +1 -1
@@ -481,7 +481,7 @@ static int hi3670_pcie_allclk_ctrl(struct hi3670_pcie_phy *phy, bool clk_on) ret =hi3670_pcie_pll_ctrl (phy, true);if (ret) {dev_err (dev,"Failed to enable pll\n" ); -return -EINVAL ; + goto close_clocks; }hi3670_pcie_hp_debounce_gt (phy, true);hi3670_pcie_phyref_gt (phy, true);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 993/2151 phy: rockchip: usbdp: Update mode_change after error handling
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Reichel <[email protected]>
[ Upstream commit 3f2181226d7708349c69cd4a4b21372a8049576b ]
If rk_udphy_init() or rk_udphy_setup() fails, the reinit will not be tried again. Fix this by only updating the variable after all potential errors have been handled.
Note, that no errors have been seen on real hardware and failures would most likely be fatal and require at least a full reboot as the function already asserts the PHY reset lines. So this is more of a theoretical issue.
--- drivers/phy/rockchip/phy-rockchip-usbdp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/phy/rockchip/phy-rockchip-usbdp.c +2 -2
@@ -1000,15 +1000,14 @@ static int rk_udphy_power_on(struct rk_udphy *udphy, u8 mode) }if (udphy->status ==UDPHY_MODE_NONE ) { - udphy->mode_change = false; ret =rk_udphy_setup (udphy);if (ret)return ret;if (udphy->mode &UDPHY_MODE_USB )rk_udphy_u3_port_disable (udphy, false); - }else if (udphy->mode_change) { udphy->mode_change = false; + }else if (udphy->mode_change) { udphy->status =UDPHY_MODE_NONE ;if (udphy->mode ==UDPHY_MODE_DP )rk_udphy_u3_port_disable (udphy, true);
@@ -1017,6 +1016,7 @@ static int rk_udphy_power_on(struct rk_udphy *udphy, u8 mode) ret =rk_udphy_setup (udphy);if (ret)return ret; + udphy->mode_change = false; } udphy->status |= mode;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 994/2151 phy: rockchip: usbdp: Do not lose USB3 PHY status
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Reichel <[email protected]>
[ Upstream commit b322403c294b67fd6bcf6719b4fc9f8a9e313129 ]
By default (i.e. without manually enabling runtime PM) DWC3 requests the USB3 PHY once and keeps it enabled all the time. When DisplayPort is being requested later on, a mode change is needed. This re-initializes the PHY. During re-initialization the status variable has incorrectly been cleared, which means the tracking information for USB3 is lost.
This is not an immediate problem, since the DP side keeps the PHY enabled. But once DP is toggled off, the whole PHY will be disabled. This is a problem, because the USB side still needs it powered.
Fix things by not clearing the status flags.
--- drivers/phy/rockchip/phy-rockchip-usbdp.c | 1 - 1 file changed, 1 deletion(-)
drivers/phy/rockchip/phy-rockchip-usbdp.c +0 -1
@@ -1008,7 +1008,6 @@ static int rk_udphy_power_on(struct rk_udphy *udphy, u8 mode)rk_udphy_u3_port_disable (udphy, false); udphy->mode_change = false; }else if (udphy->mode_change) { - udphy->status =UDPHY_MODE_NONE ;if (udphy->mode ==UDPHY_MODE_DP )rk_udphy_u3_port_disable (udphy, true);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 995/2151 phy: rockchip: usbdp: Fix devm_clk_bulk_get_all check
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Reichel <[email protected]>
[ Upstream commit a2ddfc60a7d3ba0f571f037371b261642f8ed208 ]
If devm_clk_bulk_get_all() returns -EPROBE_DEFER, it is replaced with -ENODEV, permanently failing the driver probe instead of allowing it to defer. Avoid masking the error code to fix the issue.
This effectively drops returning -ENODEV in case no clocks are being described in DT. This special case will now be handled by the follow-up check searching for "refclk" and exit with -EINVAL.
None of this will be hit in practice, since the driver is only used by RK3588 and RK3576 - on these platforms the DT is validated to contain the clocks and the clock driver is force probed early. Thus there is no need to backport this.
--- drivers/phy/rockchip/phy-rockchip-usbdp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/phy/rockchip/phy-rockchip-usbdp.c +2 -2
@@ -427,8 +427,8 @@ static int rk_udphy_clk_init(struct rk_udphy *udphy, struct device *dev)int i; udphy->num_clks =devm_clk_bulk_get_all (dev, &udphy->clks); -if (udphy->num_clks <1 ) -return -ENODEV ; +if (udphy->num_clks <0 ) +return udphy->num_clks;/* used for configure phy reference clock frequency */ for (i =0 ; i < udphy->num_clks; i++) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 996/2151 phy: rockchip: usbdp: Handle missing clock-names DT property gracefully
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Reichel <[email protected]>
[ Upstream commit 17cd5e026a6e806b811f915b8e02a8b9d14f6f41 ]
The rk_udphy_clk_init() function would currently try to do a strncmp for a NULL pointer, if DT specifies 'clocks' property, but no 'clock-names' property. Fix this by making sure the clock has an id string set.
Note that DT binding requires setting clock-names, so this is only a problem when booting a non-compliant device tree.
--- drivers/phy/rockchip/phy-rockchip-usbdp.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/phy/rockchip/phy-rockchip-usbdp.c +3 -0
@@ -432,6 +432,9 @@ static int rk_udphy_clk_init(struct rk_udphy *udphy, struct device *dev)/* used for configure phy reference clock frequency */ for (i =0 ; i < udphy->num_clks; i++) { +if (!udphy->clks[i].id) +continue ; +if (!strncmp (udphy->clks[i].id,"refclk" ,6 )) { udphy->refclk = udphy->clks[i].clk;break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 997/2151 phy: rockchip: usbdp: Drop seamless DP takeover
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Reichel <[email protected]>
[ Upstream commit 1ab628ce8f3ab694c28dcfcd5b1eec0cf9f499b8 ]
Right now the DRM drivers do not support seamless DP takeover and I'm I'm not aware of any bootloader implementing this feature either.
In any case this feature would be limited to boards using the USBDP PHY for a DP or eDP connection instead of the more commonly USB-C connector. With USB-C's DP AltMode a seamless DP takeover requires handing over the state of the TCPM state machine from the bootloader to the kernel. This in turn requires a huge amount of work to keep the state machine implementations synchronized. It's very unlikely we will see somebody implementing that in the foreseeable future.
As the current code is obviously buggy and untested, let's simply drop support for seamless DP takeover. It can be re-implemented cleanly once somebody adds all missing bits.
--- drivers/phy/rockchip/phy-rockchip-usbdp.c | 31 ----------------------- 1 file changed, 31 deletions(-)
drivers/phy/rockchip/phy-rockchip-usbdp.c +0 -31
@@ -452,11 +452,6 @@ static int rk_udphy_reset_assert_all(struct rk_udphy *udphy)return reset_control_bulk_assert (udphy->num_rsts, udphy->rsts); } -static int rk_udphy_reset_deassert_all (struct rk_udphy *udphy) -{ -return reset_control_bulk_deassert (udphy->num_rsts, udphy->rsts); -} -static int rk_udphy_reset_deassert (struct rk_udphy *udphy,char *name) {struct reset_control_bulk_data *list = udphy->rsts;
@@ -924,28 +919,6 @@ static int rk_udphy_parse_lane_mux_data(struct rk_udphy *udphy)return 0 ; } -static int rk_udphy_get_initial_status (struct rk_udphy *udphy) -{ -int ret; -u32 value; - - ret =clk_bulk_prepare_enable (udphy->num_clks, udphy->clks); -if (ret) { -dev_err (udphy->dev,"failed to enable clk\n" ); -return ret; - } - -rk_udphy_reset_deassert_all (udphy); - -regmap_read (udphy->pma_regmap,CMN_LANE_MUX_AND_EN_OFFSET , &value); -if (FIELD_GET (CMN_DP_LANE_MUX_ALL , value) &&FIELD_GET (CMN_DP_LANE_EN_ALL , value)) - udphy->status =UDPHY_MODE_DP ; -else -rk_udphy_disable (udphy); - -return 0 ; -} -static int rk_udphy_parse_dt (struct rk_udphy *udphy) {struct device *dev = udphy->dev;
@@ -1495,10 +1468,6 @@ static int rk_udphy_probe(struct platform_device *pdev)if (ret)return ret; - ret =rk_udphy_get_initial_status (udphy); -if (ret) -return ret; -mutex_init (&udphy->mutex);platform_set_drvdata (pdev, udphy);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 998/2151 phy: rockchip: usbdp: Limit DP lane count to muxed lanes
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Reichel <[email protected]>
[ Upstream commit 443997ca8d797375ff35e8f3ad3828799e88f71b ]
In theory the DP controller could request 4 lanes when the PHY is restricted to 2 lanes as the other half is used by USB3.
With the current user (DW-DP) this cannot happen, but as the check is cheap and users might change in the future protect things accordingly. Not doing so would corrupt USB3 usage by the following code configuring the voltages.
--- drivers/phy/rockchip/phy-rockchip-usbdp.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/phy/rockchip/phy-rockchip-usbdp.c +3 -0
@@ -1102,6 +1102,9 @@ static int rk_udphy_dp_phy_verify_link_rate(struct rk_udphy *udphy,static int rk_udphy_dp_phy_verify_lanes (struct rk_udphy *udphy,struct phy_configure_opts_dp *dp) { +if (dp->lanes > udphy->dp_lanes) +return -EINVAL ; +switch (dp->lanes) {case 1 :case 2 :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 999/2151 phy: rockchip: usbdp: Add missing mode_change update
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Reichel <[email protected]>
[ Upstream commit 5def5d61ea5ac6f391364f6fdcff13a27a52026e ]
rk_udphy_set_typec_default_mapping() updates the available modes, but does not set the mode_change as required. This results in missing re-initialization and thus non-working DisplayPort.
Fix this issue by introducing a new helper to update the available modes.
Stable-dep-of: b1ca8de219ae ("phy: rockchip: usbdp: Properly handle TYPEC_STATE_SAFE and TYPEC_STATE_USB")
--- drivers/phy/rockchip/phy-rockchip-usbdp.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
drivers/phy/rockchip/phy-rockchip-usbdp.c +11 -5
@@ -616,6 +616,15 @@ static void rk_udphy_dp_hpd_event_trigger(struct rk_udphy *udphy, bool hpd)rk_udphy_grfreg_write (udphy->vogrf, &cfg->vogrfcfg[udphy->id].hpd_trigger, hpd); } +static void rk_udphy_mode_set (struct rk_udphy *udphy,u8 mode) +{ +if (udphy->mode == mode) +return ; + + udphy->mode_change = true; + udphy->mode = mode; +} +static void rk_udphy_set_typec_default_mapping (struct rk_udphy *udphy) {if (udphy->flip) {
@@ -646,7 +655,7 @@ static void rk_udphy_set_typec_default_mapping(struct rk_udphy *udphy)gpiod_set_value_cansleep (udphy->sbu2_dc_gpio,1 ); } - udphy->mode =UDPHY_MODE_DP_USB ; +rk_udphy_mode_set (udphy,UDPHY_MODE_DP_USB ); } static int rk_udphy_orien_sw_set(struct typec_switch_dev *sw,
@@ -1364,10 +1373,7 @@ static int rk_udphy_typec_mux_set(struct typec_mux_dev *mux,usleep_range (750 ,800 );rk_udphy_dp_hpd_event_trigger (udphy, true); }else if (data->status &DP_STATUS_HPD_STATE ) { -if (udphy->mode != mode) { - udphy->mode = mode; - udphy->mode_change = true; - } +rk_udphy_mode_set (udphy, mode);rk_udphy_dp_hpd_event_trigger (udphy, true); }else {rk_udphy_dp_hpd_event_trigger (udphy, false);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1000/2151 phy: rockchip: usbdp: Support single-lane DP
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhang Yubing <[email protected]>
[ Upstream commit ae9b60ef1d626d1a4fdf8854f66d58f6ac56e37d ]
Implement support for using just a single DisplayPort line.
Stable-dep-of: b1ca8de219ae ("phy: rockchip: usbdp: Properly handle TYPEC_STATE_SAFE and TYPEC_STATE_USB")
--- drivers/phy/rockchip/phy-rockchip-usbdp.c | 64 ++++++++++------------- 1 file changed, 27 insertions(+), 37 deletions(-)
drivers/phy/rockchip/phy-rockchip-usbdp.c +27 -37
@@ -193,6 +193,7 @@ struct rk_udphy {int id;bool dp_in_use; +int dp_lanes;/* PHY const config */ const struct rk_udphy_cfg *cfgs;
@@ -534,6 +535,13 @@ static void rk_udphy_usb_bvalid_enable(struct rk_udphy *udphy, u8 enable)* <0 1> dpln0 dpln1 usbrx usbtx * <2 3> usbrx usbtx dpln0 dpln1 * --------------------------------------------------------------------------- +* if 1 lane for dp function, 2 lane for usb function, define rockchip,dp-lane-mux = <x>; +* sample as follow: +* --------------------------------------------------------------------------- +* B11-B10 A2-A3 A11-A10 B2-B3 +* rockchip,dp-lane-mux ln0(tx/rx) ln1(tx) ln2(tx/rx) ln3(tx) +* <0> dpln0 \ usbrx usbtx +* --------------------------------------------------------------------------- */ static void rk_udphy_dplane_select (struct rk_udphy *udphy)
@@ -541,18 +549,18 @@ static void rk_udphy_dplane_select(struct rk_udphy *udphy)const struct rk_udphy_cfg *cfg = udphy->cfgs;u32 value =0 ; -switch (udphy->mode) { -case UDPHY_MODE_DP : - value |=2 << udphy->dp_lane_sel[2 ] *2 ; +switch (udphy->dp_lanes) { +case 4 : value |=3 << udphy->dp_lane_sel[3 ] *2 ; + value |=2 << udphy->dp_lane_sel[2 ] *2 ; fallthrough; -case UDPHY_MODE_DP_USB : - value |=0 << udphy->dp_lane_sel[0 ] *2 ; +case 2 : value |=1 << udphy->dp_lane_sel[1 ] *2 ; -break ; + fallthrough; -case UDPHY_MODE_USB : +case 1 : + value |=0 << udphy->dp_lane_sel[0 ] *2 ;break ;default :
@@ -565,28 +573,6 @@ static void rk_udphy_dplane_select(struct rk_udphy *udphy) FIELD_PREP(DP_AUX_DOUT_SEL, udphy->dp_aux_dout_sel) | value); } -static int rk_udphy_dplane_get (struct rk_udphy *udphy) -{ -int dp_lanes; - -switch (udphy->mode) { -case UDPHY_MODE_DP : - dp_lanes =4 ; -break ; - -case UDPHY_MODE_DP_USB : - dp_lanes =2 ; -break ; - -case UDPHY_MODE_USB : -default : - dp_lanes =0 ; -break ; - } - -return dp_lanes; -} -static void rk_udphy_dplane_enable (struct rk_udphy *udphy,int dp_lanes) {u32 val =0 ;
@@ -656,6 +642,7 @@ static void rk_udphy_set_typec_default_mapping(struct rk_udphy *udphy) }rk_udphy_mode_set (udphy,UDPHY_MODE_DP_USB ); + udphy->dp_lanes =2 ; } static int rk_udphy_orien_sw_set(struct typec_switch_dev *sw,
@@ -894,7 +881,7 @@ static int rk_udphy_parse_lane_mux_data(struct rk_udphy *udphy)return 0 ; } -if (num_lanes !=2 && num_lanes !=4 ) +if (num_lanes !=1 && num_lanes !=2 && num_lanes !=4 )return dev_err_probe (udphy->dev, -EINVAL ,"invalid number of lane mux\n" );
@@ -920,9 +907,11 @@ static int rk_udphy_parse_lane_mux_data(struct rk_udphy *udphy) } udphy->mode =UDPHY_MODE_DP ; -if (num_lanes ==2 ) { + udphy->dp_lanes = num_lanes; +if (num_lanes ==1 || num_lanes ==2 ) { udphy->mode |=UDPHY_MODE_USB ; - udphy->flip = (udphy->lane_mux_sel[0 ] ==PHY_LANE_MUX_DP ); + udphy->flip = (udphy->lane_mux_sel[0 ] ==PHY_LANE_MUX_DP ) || + (udphy->lane_mux_sel[1 ] ==PHY_LANE_MUX_DP ); }return 0 ;
@@ -1050,18 +1039,17 @@ static int rk_udphy_dp_phy_exit(struct phy *phy)static int rk_udphy_dp_phy_power_on (struct phy *phy) {struct rk_udphy *udphy =phy_get_drvdata (phy); -int ret, dp_lanes; +int ret;mutex_lock (&udphy->mutex); - dp_lanes =rk_udphy_dplane_get (udphy); -phy_set_bus_width (phy, dp_lanes); +phy_set_bus_width (phy, udphy->dp_lanes); ret =rk_udphy_power_on (udphy,UDPHY_MODE_DP );if (ret) goto unlock; -rk_udphy_dplane_enable (udphy, dp_lanes); +rk_udphy_dplane_enable (udphy, udphy->dp_lanes);rk_udphy_dplane_select (udphy);
@@ -1344,6 +1332,7 @@ static int rk_udphy_typec_mux_set(struct typec_mux_dev *mux, udphy->lane_mux_sel[2 ] =PHY_LANE_MUX_DP ; udphy->lane_mux_sel[3 ] =PHY_LANE_MUX_DP ; mode =UDPHY_MODE_DP ; + udphy->dp_lanes =4 ;break ;case TYPEC_DP_STATE_D :
@@ -1360,6 +1349,7 @@ static int rk_udphy_typec_mux_set(struct typec_mux_dev *mux, udphy->lane_mux_sel[3 ] =PHY_LANE_MUX_DP ; } mode =UDPHY_MODE_DP_USB ; + udphy->dp_lanes =2 ;break ; }
@@ -1504,7 +1494,7 @@ static int rk_udphy_probe(struct platform_device *pdev) ret =PTR_ERR (udphy->phy_dp);return dev_err_probe (dev, ret,"failed to create DP phy\n" ); } -phy_set_bus_width (udphy->phy_dp,rk_udphy_dplane_get (udphy)); +phy_set_bus_width (udphy->phy_dp, udphy->dp_lanes); udphy->phy_dp->attrs.max_link_rate =8100 ;phy_set_drvdata (udphy->phy_dp, udphy);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1001/2151 phy: rockchip: usbdp: Drop DP HPD handling
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Reichel <[email protected]>
[ Upstream commit 4fd2c13cbb11f5483a43cc789cb8de1c3bd23238 ]
Drop the HPD handling logic from the USBDP PHY. The registers involved require the display controller power domain being enabled and thus the HPD signal should be handled by the displayport controller itself. Apart from that the HPD handling as it is done here is incorrect and misses hotplug events happening after the USB-C connector (e.g. when a USB-C to HDMI adapter is involved and the HDMI cable is replugged).
Proper USB-C DP HPD support requires some restructuring of the DP controller driver, which will happen independent of this patch. The mainline kernel does not yet support USB-C DP AltMode on RK3588 and RK3576, so it is fine to drop this code without adding the counterpart in the DRM in an atomic change.
Stable-dep-of: b1ca8de219ae ("phy: rockchip: usbdp: Properly handle TYPEC_STATE_SAFE and TYPEC_STATE_USB")
--- drivers/phy/rockchip/phy-rockchip-usbdp.c | 85 +++-------------------- 1 file changed, 9 insertions(+), 76 deletions(-)
drivers/phy/rockchip/phy-rockchip-usbdp.c +9 -76
@@ -127,7 +127,6 @@ struct rk_udphy_grf_cfg {struct rk_udphy_vogrf_cfg {/* vo-grf */ -struct rk_udphy_grf_reg hpd_trigger;u32 dp_lane_reg; };
@@ -185,14 +184,11 @@ struct rk_udphy {u32 dp_lane_sel[4 ];u32 dp_aux_dout_sel;u32 dp_aux_din_sel; -bool dp_sink_hpd_sel; -bool dp_sink_hpd_cfg;unsigned int link_rate;unsigned int lanes;u8 bw;int id; -bool dp_in_use;int dp_lanes;/* PHY const config */
@@ -589,19 +585,6 @@ static void rk_udphy_dplane_enable(struct rk_udphy *udphy, int dp_lanes) CMN_DP_CMN_RSTN, FIELD_PREP(CMN_DP_CMN_RSTN, 0x0)); } -static void rk_udphy_dp_hpd_event_trigger (struct rk_udphy *udphy,bool hpd) -{ -const struct rk_udphy_cfg *cfg = udphy->cfgs; - - udphy->dp_sink_hpd_sel = true; - udphy->dp_sink_hpd_cfg = hpd; - -if (!udphy->dp_in_use) -return ; - -rk_udphy_grfreg_write (udphy->vogrf, &cfg->vogrfcfg[udphy->id].hpd_trigger, hpd); -} -static void rk_udphy_mode_set (struct rk_udphy *udphy,u8 mode) {if (udphy->mode == mode)
@@ -1013,29 +996,6 @@ static void rk_udphy_power_off(struct rk_udphy *udphy, u8 mode)rk_udphy_disable (udphy); } -static int rk_udphy_dp_phy_init (struct phy *phy) -{ -struct rk_udphy *udphy =phy_get_drvdata (phy); - -mutex_lock (&udphy->mutex); - - udphy->dp_in_use = true; - -mutex_unlock (&udphy->mutex); - -return 0 ; -} - -static int rk_udphy_dp_phy_exit (struct phy *phy) -{ -struct rk_udphy *udphy =phy_get_drvdata (phy); - -mutex_lock (&udphy->mutex); - udphy->dp_in_use = false; -mutex_unlock (&udphy->mutex); -return 0 ; -} -static int rk_udphy_dp_phy_power_on (struct phy *phy) {struct rk_udphy *udphy =phy_get_drvdata (phy);
@@ -1267,8 +1227,6 @@ static int rk_udphy_dp_phy_configure(struct phy *phy, }static const struct phy_ops rk_udphy_dp_phy_ops = { - .init = rk_udphy_dp_phy_init, - .exit = rk_udphy_dp_phy_exit, .power_on = rk_udphy_dp_phy_power_on, .power_off = rk_udphy_dp_phy_power_off, .configure = rk_udphy_dp_phy_configure,
@@ -1322,6 +1280,14 @@ static int rk_udphy_typec_mux_set(struct typec_mux_dev *mux,struct rk_udphy *udphy =typec_mux_get_drvdata (mux);u8 mode; +/* +* Ignore mux events not involving DP AltMode, because +* the mode field is being reused, e.g. state->mode == 4 +* could be either TYPEC_MODE_USB4 or TYPEC_DP_STATE_C. +*/ +if (!state->alt || state->alt->svid !=USB_TYPEC_DP_SID ) +return 0 ; +mutex_lock (&udphy->mutex);switch (state->mode) {
@@ -1353,22 +1319,7 @@ static int rk_udphy_typec_mux_set(struct typec_mux_dev *mux,break ; } -if (state->alt && state->alt->svid ==USB_TYPEC_DP_SID ) { -struct typec_displayport_data *data = state->data; - -if (!data) { -rk_udphy_dp_hpd_event_trigger (udphy, false); - }else if (data->status &DP_STATUS_IRQ_HPD ) { -rk_udphy_dp_hpd_event_trigger (udphy, false); -usleep_range (750 ,800 ); -rk_udphy_dp_hpd_event_trigger (udphy, true); - }else if (data->status &DP_STATUS_HPD_STATE ) { -rk_udphy_mode_set (udphy, mode); -rk_udphy_dp_hpd_event_trigger (udphy, true); - }else { -rk_udphy_dp_hpd_event_trigger (udphy, false); - } - } +rk_udphy_mode_set (udphy, mode);mutex_unlock (&udphy->mutex);return 0 ;
@@ -1507,20 +1458,6 @@ static int rk_udphy_probe(struct platform_device *pdev)return 0 ; } -static int __maybe_unused rk_udphy_resume (struct device *dev) -{ -struct rk_udphy *udphy =dev_get_drvdata (dev); - -if (udphy->dp_sink_hpd_sel) -rk_udphy_dp_hpd_event_trigger (udphy, udphy->dp_sink_hpd_cfg); - -return 0 ; -} - -static const struct dev_pm_ops rk_udphy_pm_ops = { -SET_LATE_SYSTEM_SLEEP_PM_OPS (NULL , rk_udphy_resume) -}; -static const char *const rk_udphy_rst_list[] = {"init" ,"cmn" ,"lane" ,"pcs_apb" ,"pma_apb" };
@@ -1544,7 +1481,6 @@ static const struct rk_udphy_cfg rk3576_udphy_cfgs = { }, .vogrfcfg = { { - .hpd_trigger = RK_UDPHY_GEN_GRF_REG(0x0000, 11, 10, 1, 3), .dp_lane_reg = 0x0000, }, },
@@ -1585,11 +1521,9 @@ static const struct rk_udphy_cfg rk3588_udphy_cfgs = { }, .vogrfcfg = { { - .hpd_trigger = RK_UDPHY_GEN_GRF_REG(0x0000, 11, 10, 1, 3), .dp_lane_reg = 0x0000, }, { - .hpd_trigger = RK_UDPHY_GEN_GRF_REG(0x0008, 11, 10, 1, 3), .dp_lane_reg = 0x0008, }, },
@@ -1625,7 +1559,6 @@ static struct platform_driver rk_udphy_driver = { .driver = { .name = "rockchip-usbdp-phy", .of_match_table = rk_udphy_dt_match, - .pm = &rk_udphy_pm_ops, }, };module_platform_driver (rk_udphy_driver);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1002/2151 phy: rockchip: usbdp: Properly handle TYPEC_STATE_SAFE and TYPEC_STATE_USB
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Reichel <[email protected]>
[ Upstream commit b1ca8de219ae6e4d9eec22acfbe4357d8addd94c ]
Handle TYPEC_STATE_SAFE and TYPEC_STATE_USB Type-C state events, so that the muxing is properly updated when exiting DP AltMode.
--- drivers/phy/rockchip/phy-rockchip-usbdp.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
drivers/phy/rockchip/phy-rockchip-usbdp.c +15 -6
@@ -1274,18 +1274,27 @@ static const struct phy_ops rk_udphy_usb3_phy_ops = { .owner = THIS_MODULE, }; +static bool rk_udphy_is_supported_mode (struct typec_mux_state *state) +{ +/* Handle Safe State and USB State */ +if (state->mode <TYPEC_STATE_MODAL ) +return true; + +/* Handle DP AltMode */ +if (state->alt && state->alt->svid ==USB_TYPEC_DP_SID ) +return true; + +return false; +} +static int rk_udphy_typec_mux_set (struct typec_mux_dev *mux,struct typec_mux_state *state) {struct rk_udphy *udphy =typec_mux_get_drvdata (mux);u8 mode; -/* -* Ignore mux events not involving DP AltMode, because -* the mode field is being reused, e.g. state->mode == 4 -* could be either TYPEC_MODE_USB4 or TYPEC_DP_STATE_C. -*/ -if (!state->alt || state->alt->svid !=USB_TYPEC_DP_SID ) +/* Ignore mux events not involving USB or DP */ +if (!rk_udphy_is_supported_mode (state))return 0 ;mutex_lock (&udphy->mutex);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1003/2151 phy: rockchip: usbdp: Hold mutex in DP PHY configure
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Reichel <[email protected]>
[ Upstream commit 619233ce6b2329529c9f0ff9682d6e22d160ebd6 ]
rk_udphy_dp_phy_configure() accesses some variables from the struct rk_udphy, which are updated independently from the USB-C framework.
The USB-C mux/orientation switch functions already hold a mutex to ensure mutual exclusive access to the struct rk_udphy states, so simply hold the same one in the DP PHY configuration function.
Reproducing problems due to this on real hardware would be really hard, but could be possible when quickly re-connecting the USB-C connector.
--- drivers/phy/rockchip/phy-rockchip-usbdp.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/phy/rockchip/phy-rockchip-usbdp.c +2 -0
@@ -1136,6 +1136,8 @@ static int rk_udphy_dp_phy_configure(struct phy *phy,u32 i, val, lane;int ret; +guard (mutex)(&udphy->mutex); +if (dp->set_rate) { ret =rk_udphy_dp_phy_verify_link_rate (udphy, dp);if (ret)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1004/2151 phy: rockchip: usbdp: Rename mode_change to phy_needs_reinit
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Reichel <[email protected]>
[ Upstream commit fbce9cc28cadb24026a6c061819d42e50d3bfea0 ]
Right now the mode_change property is set whenever the mode changes between USB-only, DP-only and USB-DP. It is needed, because on any mode change the PHY needs to be re-initialized. Apparently at least DP also requires a re-init when the cable orientation is changed, which is currently not being done (except when the orientation switch also involves a mode change). Prepare for this by renaming mode_change to phy_needs_reinit.
Stable-dep-of: cf3aa34e6f07 ("phy: rockchip: usbdp: Avoid xHCI SErrors")
--- drivers/phy/rockchip/phy-rockchip-usbdp.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/phy/rockchip/phy-rockchip-usbdp.c +5 -5
@@ -170,7 +170,7 @@ struct rk_udphy {/* PHY status management */ bool flip; -bool mode_change; +bool phy_needs_reinit;u8 mode;u8 status;
@@ -590,7 +590,7 @@ static void rk_udphy_mode_set(struct rk_udphy *udphy, u8 mode)if (udphy->mode == mode)return ; - udphy->mode_change = true; + udphy->phy_needs_reinit = true; udphy->mode = mode; }
@@ -963,8 +963,8 @@ static int rk_udphy_power_on(struct rk_udphy *udphy, u8 mode)if (udphy->mode &UDPHY_MODE_USB )rk_udphy_u3_port_disable (udphy, false); - udphy->mode_change = false; - }else if (udphy->mode_change) { + udphy->phy_needs_reinit = false; + }else if (udphy->phy_needs_reinit) {if (udphy->mode ==UDPHY_MODE_DP )rk_udphy_u3_port_disable (udphy, true);
@@ -972,7 +972,7 @@ static int rk_udphy_power_on(struct rk_udphy *udphy, u8 mode) ret =rk_udphy_setup (udphy);if (ret)return ret; - udphy->mode_change = false; + udphy->phy_needs_reinit = false; } udphy->status |= mode;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1005/2151 phy: rockchip: usbdp: Avoid xHCI SErrors
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Reichel <[email protected]>
[ Upstream commit cf3aa34e6f0798544c26ad93a6c3c2231ab09738 ]
The USBDP PHY provides the PIPE clock to the USB3 controller, which means the PHY must be fully running when anything tries to access the xHCI registers.
When switching between USB3-only, USB3 + DP and DP-only mode, the PHY must be re-initialized resulting in a short period of the PHY being disabled. If the DWC3 driver decides to access the xHCI at this point the system will fail with an SError.
This patch avoids the problems by disabling the USB3 port before re-initializing it. This does a couple of things:
- forces phystatus to 0 from GRF (not from PHY)
- switches PIPE clock source from PHY to UTMI (safe fallback clock)
- num_u3_port=0
The last part will be ignored, as DWC3 already probed, but the clock re-routing will avoid the SError. There is a small delay afterwards to make sure the mux happened. The datasheet gives no hints how long it takes, so delay time is a guess.
--- drivers/phy/rockchip/phy-rockchip-usbdp.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/phy/rockchip/phy-rockchip-usbdp.c +5 -2
@@ -965,13 +965,16 @@ static int rk_udphy_power_on(struct rk_udphy *udphy, u8 mode)rk_udphy_u3_port_disable (udphy, false); udphy->phy_needs_reinit = false; }else if (udphy->phy_needs_reinit) { -if (udphy->mode ==UDPHY_MODE_DP ) -rk_udphy_u3_port_disable (udphy, true); +rk_udphy_u3_port_disable (udphy, true); +udelay (10 );rk_udphy_disable (udphy); ret =rk_udphy_setup (udphy);if (ret)return ret; + +if (!udphy->hs && udphy->mode &UDPHY_MODE_USB ) +rk_udphy_u3_port_disable (udphy, false); udphy->phy_needs_reinit = false; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1006/2151 phy: rockchip: usbdp: Handle rk_udphy_reset_deassert errors
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Reichel <[email protected]>
[ Upstream commit 35101e2f49c04bf1cfc69b8a0d3f85c742369ccc ]
Handle rk_udphy_reset_deassert returning errors to avoid theoretical (Rockchip reset controller driver does not return errors) SError.
--- drivers/phy/rockchip/phy-rockchip-usbdp.c | 25 +++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)
drivers/phy/rockchip/phy-rockchip-usbdp.c +19 -6
@@ -771,8 +771,12 @@ static int rk_udphy_init(struct rk_udphy *udphy)/* Step 1: power on pma and deassert apb rstn */ rk_udphy_grfreg_write (udphy->udphygrf, &cfg->grfcfg.low_pwrn, true); -rk_udphy_reset_deassert (udphy,"pma_apb" ); -rk_udphy_reset_deassert (udphy,"pcs_apb" ); + ret =rk_udphy_reset_deassert (udphy,"pma_apb" ); +if (ret) + goto assert_resets; + ret =rk_udphy_reset_deassert (udphy,"pcs_apb" ); +if (ret) + goto assert_resets;/* Step 2: set init sequence and phy refclk */ ret = regmap_multi_reg_write(udphy->pma_regmap, rk_udphy_init_sequence,
@@ -798,8 +802,11 @@ static int rk_udphy_init(struct rk_udphy *udphy) FIELD_PREP(CMN_DP_LANE_EN_ALL, 0));/* Step 4: deassert init rstn and wait for 200ns from datasheet */ -if (udphy->mode &UDPHY_MODE_USB ) -rk_udphy_reset_deassert (udphy,"init" ); +if (udphy->mode &UDPHY_MODE_USB ) { + ret =rk_udphy_reset_deassert (udphy,"init" ); +if (ret) + goto assert_resets; + }if (udphy->mode &UDPHY_MODE_DP ) { regmap_update_bits(udphy->pma_regmap, CMN_DP_RSTN_OFFSET,
@@ -811,8 +818,14 @@ static int rk_udphy_init(struct rk_udphy *udphy)/* Step 5: deassert cmn/lane rstn */ if (udphy->mode &UDPHY_MODE_USB ) { -rk_udphy_reset_deassert (udphy,"cmn" ); -rk_udphy_reset_deassert (udphy,"lane" ); + ret =rk_udphy_reset_deassert (udphy,"cmn" ); +if (ret) + goto assert_resets; + + ret =rk_udphy_reset_deassert (udphy,"lane" ); +if (ret) + goto assert_resets; + }/* Step 6: wait for lock done of pll */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1007/2151 phy: rockchip: usbdp: Only enable USB3 when not in high-speed mode
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Reichel <[email protected]>
[ Upstream commit fbbf6c85b08008bf68ef49931175edeaa36ba82f ]
Ensure that USB3 mode is not accidently enabled during PHY re-init for systems that are configured as high-speed only via DT.
--- drivers/phy/rockchip/phy-rockchip-usbdp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/phy/rockchip/phy-rockchip-usbdp.c +1 -1
@@ -974,7 +974,7 @@ static int rk_udphy_power_on(struct rk_udphy *udphy, u8 mode)if (ret)return ret; -if (udphy->mode &UDPHY_MODE_USB ) +if (!udphy->hs && udphy->mode &UDPHY_MODE_USB )rk_udphy_u3_port_disable (udphy, false); udphy->phy_needs_reinit = false; }else if (udphy->phy_needs_reinit) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1008/2151 scsi: scsi_debug: Refuse a negative physblk_exp
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Cassel <[email protected]>
[ Upstream commit a349876633f7a583429367daf16f9a4282118255 ]
sdebug_init() refuses a physblk_exp above 15, but the parameter is a signed int, so a negative value is accepted. The driver then shifts by it when it builds the Block Limits VPD page, which is undefined behaviour, and READ CAPACITY (16) reports an exponent of 15 for -1.
Refuse a negative value as well, and print it as a signed value.
--- drivers/scsi/scsi_debug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/scsi_debug.c +2 -2
@@ -8503,8 +8503,8 @@ static int __init scsi_debug_init(void)return -EINVAL ; } -if (sdebug_physblk_exp >15 ) { -pr_err ("invalid physblk_exp %u\n" , sdebug_physblk_exp); +if (sdebug_physblk_exp <0 || sdebug_physblk_exp >15 ) { +pr_err ("invalid physblk_exp %d\n" , sdebug_physblk_exp);return -EINVAL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1009/2151 scsi: scsi_debug: Take the zone metadata lock before the data lock
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Cassel <[email protected]>
[ Upstream commit c9aedbcbff0fe31fabdea09600609eb30e05441d ]
resp_comp_write() takes the data lock and then the zone metadata lock, while every other command that takes both takes the metadata lock first and reaches the data lock through do_device_access(). A COMPARE AND WRITE and any other write to the same store can therefore deadlock each other.
Take the locks in the same order as everywhere else.
Correct the comment above map_region() while here: the provisioning map is covered by the metadata lock rather than the data lock, which is why resp_unmap() takes only the metadata lock.
--- drivers/scsi/scsi_debug.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/scsi/scsi_debug.c +3 -3
@@ -5459,20 +5459,20 @@ static int resp_comp_write(struct scsi_cmnd *scp,"indicated=%u, IO sent=%d bytes\n" , my_name, dnum * lb_size, ret); -sdeb_data_write_lock (sip);sdeb_meta_write_lock (sip); +sdeb_data_write_lock (sip);if (!comp_write_worker (sip, lba, num, arr, false)) {mk_sense_buffer (scp,MISCOMPARE ,MISCOMPARE_VERIFY_ASC ,0 ); retval = check_condition_result; goto cleanup_unlock; } -/* Cover sip->map_storep (which map_region()) sets with data lock */ +/* Cover sip->map_storep (which map_region() sets) with the meta lock */ if (scsi_debug_lbp ())map_region (sip, lba, num); cleanup_unlock: -sdeb_meta_write_unlock (sip);sdeb_data_write_unlock (sip); +sdeb_meta_write_unlock (sip); cleanup_free:kfree (arr);return retval;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1010/2151 scsi: core: Support allocating reserved commands
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hannes Reinecke <[email protected]>
[ Upstream commit d604e1ec246d236deff57ac7e89e073dd911d60b ]
Quite some drivers are using management commands internally. These commands typically use the same tag pool as regular SCSI commands. Tags for these management commands are set aside before allocating the block-mq tag bitmap for regular SCSI commands. The block layer already supports this via the reserved tag mechanism. Add a new field 'nr_reserved_cmds' to the SCSI host template to instruct the block layer to set aside a tag space for these management commands by using reserved tags. Exclude reserved commands from .can_queue because .can_queue is visible in sysfs.
[ bvanassche: modified patch title and patch description. Left out the
following statements: "if (sht->nr_reserved_cmds)" and also
"if (sdev->host->nr_reserved_cmds) flags |= BLK_MQ_REQ_RESERVED;". Moved nr_reserved_cmds declarations and statements close to the corresponding can_queue declarations and statements. See also
https://lore.kernel.org/linux-scsi/[email protected]/ ]
Stable-dep-of: 92feb036a2d3 ("scsi: scsi_debug: Avoid 32-bit overflow in WRITE SCATTERED offsets")
--- drivers/scsi/hosts.c | 1 + drivers/scsi/scsi_lib.c | 3 ++- include/scsi/scsi_host.h | 21 ++++++++++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-)
drivers/scsi/hosts.c +1 -0
@@ -438,6 +438,7 @@ struct Scsi_Host *scsi_host_alloc(const struct scsi_host_template *sht, int priv shost->hostt = sht; shost->this_id = sht->this_id; shost->can_queue = sht->can_queue; + shost->nr_reserved_cmds = sht->nr_reserved_cmds; shost->sg_tablesize = sht->sg_tablesize; shost->sg_prot_tablesize = sht->sg_prot_tablesize; shost->cmd_per_lun = sht->cmd_per_lun;
drivers/scsi/scsi_lib.c +2 -1
@@ -2116,7 +2116,8 @@ int scsi_mq_setup_tags(struct Scsi_Host *shost) tag_set->ops = &scsi_mq_ops_no_commit; tag_set->nr_hw_queues = shost->nr_hw_queues ? :1 ; tag_set->nr_maps = shost->nr_maps ? :1 ; - tag_set->queue_depth = shost->can_queue; + tag_set->queue_depth = shost->can_queue + shost->nr_reserved_cmds; + tag_set->reserved_tags = shost->nr_reserved_cmds; tag_set->cmd_size = cmd_size; tag_set->numa_node =dev_to_node (shost->dma_dev);if (shost->hostt->tag_alloc_policy_rr)
include/scsi/scsi_host.h +20 -1
@@ -375,10 +375,19 @@ struct scsi_host_template {/* * This determines if we will use a non-interrupt driven * or an interrupt driven scheme. It is set to the maximum number -* of simultaneous commands a single hw queue in HBA will accept. +* of simultaneous commands a single hw queue in HBA will accept +* excluding internal commands. */ int can_queue; +/* +* This determines how many commands the HBA will set aside +* for internal commands. This number will be added to +* @can_queue to calculate the maximum number of simultaneous +* commands sent to the host. +*/ +int nr_reserved_cmds; +/* * In many instances, especially where disconnect / reconnect are * supported, our host also has an ID on the SCSI bus. If this is
@@ -611,7 +620,17 @@ struct Scsi_Host {unsigned short max_cmd_len;int this_id; + +/* +* Number of commands this host can handle at the same time. +* This excludes reserved commands as specified by nr_reserved_cmds. +*/ int can_queue; +/* +* Number of reserved commands to allocate, if any. +*/ +unsigned int nr_reserved_cmds; +short cmd_per_lun;short unsigned int sg_tablesize;short unsigned int sg_prot_tablesize;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1011/2151 scsi: core: Move two statements
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bart Van Assche <[email protected]>
[ Upstream commit 21008cabc5d9bf2864ff244f4f94abebe3380947 ]
Move two statements that will be needed for pseudo SCSI devices in front of code that won't be needed for pseudo SCSI devices. No functionality has been changed.
Stable-dep-of: 92feb036a2d3 ("scsi: scsi_debug: Avoid 32-bit overflow in WRITE SCATTERED offsets")
--- drivers/scsi/scsi_scan.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/scsi/scsi_scan.c +4 -3
@@ -347,6 +347,8 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget,kref_get (&sdev->host->tagset_refcnt); sdev->request_queue = q; +scsi_sysfs_device_initialize (sdev); + depth = sdev->host->cmd_per_lun ?:1 ;/*
@@ -360,8 +362,6 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget,scsi_change_queue_depth (sdev, depth); -scsi_sysfs_device_initialize (sdev); -if (shost->hostt->sdev_init) { ret = shost->hostt->sdev_init (sdev);if (ret) {
@@ -1065,6 +1065,8 @@ static int scsi_add_lun(struct scsi_device *sdev, unsigned char *inq_result,transport_configure_device (&sdev->sdev_gendev); + sdev->sdev_bflags = *bflags; +/* * No need to freeze the queue as it isn't reachable to anyone else yet. */
@@ -1110,7 +1112,6 @@ static int scsi_add_lun(struct scsi_device *sdev, unsigned char *inq_result, sdev->max_queue_depth = sdev->queue_depth;WARN_ON_ONCE (sdev->max_queue_depth > sdev->budget_map.depth); - sdev->sdev_bflags = *bflags;/* * Ok, the device is now all set up, we can
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1012/2151 scsi: core: Support allocating a pseudo SCSI device
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hannes Reinecke <[email protected]>
[ Upstream commit d630fbf6fc8ce2fc95de7784de5499387b682dc1 ]
Allocate a pseudo SCSI device if 'nr_reserved_cmds' has been set. Pseudo SCSI devices have the SCSI ID <max_id>:U64_MAX so they won't clash with any devices the LLD might create. Pseudo SCSI devices are excluded from scanning and will not show up in sysfs. Additionally, pseudo SCSI devices are skipped by shost_for_each_device(). This prevents that the SCSI error handler tries to submit a reset to a non-existent logical unit.
Do not allocate a budget map for pseudo SCSI devices since the cmd_per_lun limit does not apply to pseudo SCSI devices.
Do not perform queue depth ramp up / ramp down for pseudo SCSI devices.
Pseudo SCSI devices will be used to send internal commands to a storage device.
[ bvanassche: edited patch description / renamed host_sdev into
pseudo_sdev / unexported scsi_get_host_dev() / modified error path in scsi_get_pseudo_dev() / skip pseudo devices in __scsi_iterate_devices() and also when calling sdev_init(), sdev_configure() and sdev_destroy(). See also
https://lore.kernel.org/linux-scsi/[email protected]/ ]
Stable-dep-of: 92feb036a2d3 ("scsi: scsi_debug: Avoid 32-bit overflow in WRITE SCATTERED offsets")
--- drivers/scsi/hosts.c | 8 +++++ drivers/scsi/scsi.c | 7 ++-- drivers/scsi/scsi_priv.h | 1 + drivers/scsi/scsi_scan.c | 67 +++++++++++++++++++++++++++++++++++++- drivers/scsi/scsi_sysfs.c | 5 ++- include/scsi/scsi_device.h | 16 +++++++++ include/scsi/scsi_host.h | 6 ++++ 7 files changed, 106 insertions(+), 4 deletions(-)
drivers/scsi/hosts.c +8 -0
@@ -307,6 +307,14 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev,if (error) goto out_del_dev; +if (shost->nr_reserved_cmds) { + shost->pseudo_sdev =scsi_get_pseudo_sdev (shost); +if (!shost->pseudo_sdev) { + error = -ENOMEM ; + goto out_del_dev; + } + } +scsi_proc_host_add (shost);scsi_autopm_put_host (shost);return error;
drivers/scsi/scsi.c +5 -2
@@ -840,8 +840,11 @@ struct scsi_device *__scsi_iterate_devices(struct Scsi_Host *shost,spin_lock_irqsave (shost->host_lock, flags);while (list->next != &shost->__devices) { next = list_entry(list->next, struct scsi_device, siblings); -/* skip devices that we can't get a reference to */ -if (!scsi_device_get (next)) +/* +* Skip pseudo devices and also devices we can't get a +* reference to. +*/ +if (!scsi_device_is_pseudo_dev (next) && !scsi_device_get (next))break ; next =NULL ; list = list->next;
drivers/scsi/scsi_priv.h +1 -0
@@ -136,6 +136,7 @@ extern int scsi_complete_async_scans(void);extern int scsi_scan_host_selected (struct Scsi_Host *,unsigned int ,unsigned int ,u64 ,enum scsi_scan_mode );extern void scsi_forget_host (struct Scsi_Host *); +struct scsi_device *scsi_get_pseudo_sdev (struct Scsi_Host *);/* scsi_sysctl.c */ #ifdef CONFIG_SYSCTL
drivers/scsi/scsi_scan.c +66 -1
96 lines not on this page · raw message
drivers/scsi/scsi_sysfs.c +4 -1
@@ -1406,6 +1406,9 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev)int error;struct scsi_target *starget = sdev->sdev_target; +if (WARN_ON_ONCE (scsi_device_is_pseudo_dev (sdev))) +return -EINVAL ; + error =scsi_target_add (starget);if (error)return error;
@@ -1513,7 +1516,7 @@ void __scsi_remove_device(struct scsi_device *sdev)kref_put (&sdev->host->tagset_refcnt, scsi_mq_free_tags);cancel_work_sync (&sdev->requeue_work); -if (sdev->host->hostt->sdev_destroy) +if (!scsi_device_is_pseudo_dev (sdev) && sdev->host->hostt->sdev_destroy) sdev->host->hostt->sdev_destroy (sdev);transport_destroy_device (dev);
include/scsi/scsi_device.h +16 -0
@@ -589,6 +589,22 @@ static inline unsigned int sdev_id(struct scsi_device *sdev)#define scmd_id (scmd) sdev_id((scmd)->device)#define scmd_channel (scmd) sdev_channel((scmd)->device) +/** +* scsi_device_is_pseudo_dev() - Whether a device is a pseudo SCSI device. +* @sdev: SCSI device to examine +* +* A pseudo SCSI device can be used to allocate SCSI commands but does not show +* up in sysfs. Additionally, the logical unit information in *@sdev is made up. +* +* This function tests the LUN number instead of comparing @sdev with +* @sdev->host->pseudo_sdev because this function may be called before +* @sdev->host->pseudo_sdev has been initialized. +*/ +static inline bool scsi_device_is_pseudo_dev (struct scsi_device *sdev) +{ +return sdev->lun ==U64_MAX ; +} +/* * checks for positions of the SCSI state machine */
include/scsi/scsi_host.h +6 -0
@@ -722,6 +722,12 @@ struct Scsi_Host {/* ldm bits */ struct device shost_gendev, shost_dev; +/* +* A SCSI device structure used for sending internal commands to the +* HBA. There is no corresponding logical unit inside the SCSI device. +*/ +struct scsi_device *pseudo_sdev; +/* * Points to the transport data (if any) which is allocated * separately
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1013/2151 scsi: core: Introduce .queue_reserved_command()
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Garry <[email protected]>
[ Upstream commit 11ea1de3fc4ba94127034cb01df63a666c4c9836 ]
Reserved commands will be used by SCSI LLDs for submitting internal commands. Since the SCSI host, target and device limits do not apply to the reserved command use cases, bypass the SCSI host limit checks for reserved commands. Introduce the .queue_reserved_command() callback for reserved commands. Additionally, do not activate the SCSI error handler if a reserved command fails such that reserved commands can be submitted from inside the SCSI error handler.
[ bvanassche: modified patch title and patch description. Renamed
.reserved_queuecommand() into .queue_reserved_command(). Changed
the second argument of __blk_mq_end_request() from 0 into error
code in the completion path if cmd->result != 0. Rewrote the
scsi_queue_rq() changes. See also
https://lore.kernel.org/linux-scsi/[email protected]/ ]
Stable-dep-of: 92feb036a2d3 ("scsi: scsi_debug: Avoid 32-bit overflow in WRITE SCATTERED offsets")
--- drivers/scsi/hosts.c | 6 +++++ drivers/scsi/scsi_lib.c | 54 ++++++++++++++++++++++++++++------------ include/scsi/scsi_host.h | 6 +++++ 3 files changed, 50 insertions(+), 16 deletions(-)
drivers/scsi/hosts.c +6 -0
@@ -231,6 +231,12 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev, goto fail; } +if (shost->nr_reserved_cmds && !sht->queue_reserved_command) { +shost_printk (KERN_ERR , shost, +"nr_reserved_cmds set but no method to queue\n" ); + goto fail; + } +/* Use min_t(int, ...) in case shost->can_queue exceeds SHRT_MAX */ shost->cmd_per_lun =min_t (int, shost->cmd_per_lun, shost->can_queue);
drivers/scsi/scsi_lib.c +38 -16
75 lines not on this page · raw message
include/scsi/scsi_host.h +6 -0
@@ -86,6 +86,12 @@ struct scsi_host_template {*/ int (* queuecommand)(struct Scsi_Host *,struct scsi_cmnd *); +/* +* Queue a reserved command (BLK_MQ_REQ_RESERVED). The .queuecommand() +* documentation also applies to the .queue_reserved_command() callback. +*/ +int (*queue_reserved_command)(struct Scsi_Host *,struct scsi_cmnd *); +/* * The commit_rqs function is used to trigger a hardware * doorbell after some requests have been queued with
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1014/2151 scsi: core: Add scsi_{get,put}_internal_cmd() helpers
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hannes Reinecke <[email protected]>
[ Upstream commit a2ab4e33286de37f3fe8f28f86f5f71d6b0ae3b0 ]
Add helper functions to allow LLDDs to allocate and free internal commands.
[ bvanassche: changed the 'nowait' argument into a 'flags' argument. See also
https://lore.kernel.org/linux-scsi/[email protected]/ ]
Stable-dep-of: 92feb036a2d3 ("scsi: scsi_debug: Avoid 32-bit overflow in WRITE SCATTERED offsets")
--- drivers/scsi/scsi_lib.c | 38 ++++++++++++++++++++++++++++++++++++++ include/scsi/scsi_device.h | 4 ++++ 2 files changed, 42 insertions(+)
drivers/scsi/scsi_lib.c +38 -0
@@ -2162,6 +2162,44 @@ void scsi_mq_free_tags(struct kref *kref)complete (&shost->tagset_freed); } +/** +* scsi_get_internal_cmd() - Allocate an internal SCSI command. +* @sdev: SCSI device from which to allocate the command +* @data_direction: Data direction for the allocated command +* @flags: request allocation flags, e.g. BLK_MQ_REQ_RESERVED or +* BLK_MQ_REQ_NOWAIT. +* +* Allocates a SCSI command for internal LLDD use. +*/ +struct scsi_cmnd *scsi_get_internal_cmd (struct scsi_device *sdev, +enum dma_data_direction data_direction, +blk_mq_req_flags_t flags) +{ +enum req_op op = data_direction ==DMA_TO_DEVICE ?REQ_OP_DRV_OUT : +REQ_OP_DRV_IN ; +struct scsi_cmnd *scmd; +struct request *rq; + + rq =scsi_alloc_request (sdev->request_queue, op, flags); +if (IS_ERR (rq)) +return NULL ; + scmd =blk_mq_rq_to_pdu (rq); + scmd->device = sdev; + +return scmd; +} +EXPORT_SYMBOL_GPL (scsi_get_internal_cmd); + +/** +* scsi_put_internal_cmd() - Free an internal SCSI command. +* @scmd: SCSI command to be freed +*/ +void scsi_put_internal_cmd (struct scsi_cmnd *scmd) +{ +blk_mq_free_request (blk_mq_rq_from_pdu (scmd)); +} +EXPORT_SYMBOL_GPL (scsi_put_internal_cmd); +/** * scsi_device_from_queue - return sdev associated with a request_queue * @q: The request queue to return the sdev from
include/scsi/scsi_device.h +4 -0
@@ -558,6 +558,10 @@ int scsi_execute_cmd(struct scsi_device *sdev, const unsigned char *cmd, const struct scsi_exec_args *args);void scsi_failures_reset_retries (struct scsi_failures *failures); +struct scsi_cmnd *scsi_get_internal_cmd (struct scsi_device *sdev, +enum dma_data_direction data_direction, +blk_mq_req_flags_t flags); +void scsi_put_internal_cmd (struct scsi_cmnd *scmd);extern void sdev_disable_disk_events (struct scsi_device *sdev);extern void sdev_enable_disk_events (struct scsi_device *sdev);extern int scsi_vpd_lun_id (struct scsi_device *,char *,size_t );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1015/2151 scsi: scsi_debug: Abort SCSI commands via an internal command
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bart Van Assche <[email protected]>
[ Upstream commit 581ca490353ca5f4bee0d662595af27c06e603d4 ]
Add a .queue_reserved_command() implementation and call it from the code path that aborts SCSI commands. This ensures that the code for allocating a pseudo SCSI device and also the code for allocating and processing reserved commands gets triggered while running blktests.
Most of the code in this patch is a modified version of code from John Garry. See also
https://lore.kernel.org/linux-scsi/[email protected]/
Stable-dep-of: 92feb036a2d3 ("scsi: scsi_debug: Avoid 32-bit overflow in WRITE SCATTERED offsets")
--- drivers/scsi/scsi_debug.c | 116 ++++++++++++++++++++++++++++++++++---- 1 file changed, 105 insertions(+), 11 deletions(-)
drivers/scsi/scsi_debug.c +105 -11
@@ -6756,20 +6756,59 @@ static bool scsi_debug_stop_cmnd(struct scsi_cmnd *cmnd)return false; } +struct sdebug_abort_cmd { +u32 unique_tag; +}; + +enum sdebug_internal_cmd_type { +SCSI_DEBUG_ABORT_CMD , +}; + +struct sdebug_internal_cmd { +enum sdebug_internal_cmd_type type; + +union { +struct sdebug_abort_cmd abort_cmd; + }; +}; + +union sdebug_priv { +struct sdebug_scsi_cmd cmd; +struct sdebug_internal_cmd internal_cmd; +}; +/* -* Called from scsi_debug_abort() only, which is for timed-out cmd. +* Abort SCSI command @cmnd. Only called from scsi_debug_abort(). Although +* it would be possible to call scsi_debug_stop_cmnd() directly, an internal +* command is allocated and submitted to trigger the reserved command +* infrastructure. */ static bool scsi_debug_abort_cmnd (struct scsi_cmnd *cmnd) { -struct sdebug_scsi_cmd *sdsc =scsi_cmd_priv (cmnd); -unsigned long flags; -bool res; - -spin_lock_irqsave (&sdsc->lock, flags); - res =scsi_debug_stop_cmnd (cmnd); -spin_unlock_irqrestore (&sdsc->lock, flags); - -return res; +struct Scsi_Host *shost = cmnd->device->host; +struct request *rq =scsi_cmd_to_rq (cmnd); +u32 unique_tag =blk_mq_unique_tag (rq); +struct sdebug_internal_cmd *internal_cmd; +struct scsi_cmnd *abort_cmd; +struct request *abort_rq; +blk_status_t res; + + abort_cmd =scsi_get_internal_cmd (shost->pseudo_sdev,DMA_NONE , +BLK_MQ_REQ_RESERVED ); +if (!abort_cmd) +return false; + internal_cmd =scsi_cmd_priv (abort_cmd); + *internal_cmd = (struct sdebug_internal_cmd ) { + .type =SCSI_DEBUG_ABORT_CMD , + .abort_cmd = { + .unique_tag = unique_tag, + }, + }; + abort_rq =scsi_cmd_to_rq (abort_cmd); + abort_rq->timeout =secs_to_jiffies (3 ); + res =blk_execute_rq (abort_rq, true); +scsi_put_internal_cmd (abort_cmd); +return res ==BLK_STS_OK ; }/*
@@ -9224,6 +9263,56 @@ static int sdebug_fail_cmd(struct scsi_cmnd *cmnd, int *retval,return ret; } +/* Process @scp, a request to abort a SCSI command by tag. */ +static void scsi_debug_abort_cmd (struct Scsi_Host *shost,struct scsi_cmnd *scp) +{ +struct sdebug_internal_cmd *internal_cmd =scsi_cmd_priv (scp); +struct sdebug_abort_cmd *abort_cmd = &internal_cmd->abort_cmd; +const u32 unique_tag = abort_cmd->unique_tag; +struct scsi_cmnd *to_be_aborted_scmd = +scsi_host_find_tag (shost, unique_tag); +struct sdebug_scsi_cmd *to_be_aborted_sdsc = +scsi_cmd_priv (to_be_aborted_scmd); +bool res = false; + +if (!to_be_aborted_scmd) { +pr_err ("%s: command with tag %#x not found\n" , __func__, + unique_tag); +return ; + } + +scoped_guard (spinlock_irqsave, &to_be_aborted_sdsc->lock) + res = scsi_debug_stop_cmnd(to_be_aborted_scmd); + +if (res) +pr_info ("%s: aborted command with tag %#x\n" , + __func__, unique_tag); +else +pr_err ("%s: failed to abort command with tag %#x\n" , + __func__, unique_tag); + +set_host_byte (scp, res ?DID_OK :DID_ERROR ); +} + +static int scsi_debug_process_reserved_command (struct Scsi_Host *shost, +struct scsi_cmnd *scp) +{ +struct sdebug_internal_cmd *internal_cmd =scsi_cmd_priv (scp); + +switch (internal_cmd->type) { +case SCSI_DEBUG_ABORT_CMD : +scsi_debug_abort_cmd (shost, scp); +break ; +default : +WARN_ON_ONCE (true); +set_host_byte (scp,DID_ERROR ); +break ; + } + +scsi_done (scp); +return 0 ; +} +static int scsi_debug_queuecommand (struct Scsi_Host *shost,struct scsi_cmnd *scp) {
@@ -9424,6 +9513,9 @@ static int sdebug_init_cmd_priv(struct Scsi_Host *shost, struct scsi_cmnd *cmd)struct sdebug_scsi_cmd *sdsc =scsi_cmd_priv (cmd);struct sdebug_defer *sd_dp = &sdsc->sd_dp; +if (blk_mq_is_reserved_rq (scsi_cmd_to_rq (cmd))) +return 0 ; +spin_lock_init (&sdsc->lock);hrtimer_setup (&sd_dp->hrt, sdebug_q_cmd_hrt_complete,CLOCK_MONOTONIC ,HRTIMER_MODE_REL_PINNED );
@@ -9443,6 +9535,7 @@ static const struct scsi_host_template sdebug_driver_template = { .sdev_destroy = scsi_debug_sdev_destroy, .ioctl = scsi_debug_ioctl, .queuecommand = scsi_debug_queuecommand, + .queue_reserved_command = scsi_debug_process_reserved_command, .change_queue_depth = sdebug_change_qdepth, .map_queues = sdebug_map_queues, .mq_poll = sdebug_blk_mq_poll,
@@ -9452,6 +9545,7 @@ static const struct scsi_host_template sdebug_driver_template = { .eh_bus_reset_handler = scsi_debug_bus_reset, .eh_host_reset_handler = scsi_debug_host_reset, .can_queue = SDEBUG_CANQUEUE, + .nr_reserved_cmds = 1, .this_id = 7, .sg_tablesize = SG_MAX_SEGMENTS, .cmd_per_lun = DEF_CMD_PER_LUN,
@@ -9460,7 +9554,7 @@ static const struct scsi_host_template sdebug_driver_template = { .module = THIS_MODULE, .skip_settle_delay = 1, .track_queue_depth = 1, - .cmd_size = sizeof(struct sdebug_scsi_cmd), + .cmd_size = sizeof(union sdebug_priv), .init_cmd_priv = sdebug_init_cmd_priv, .target_alloc = sdebug_target_alloc, .target_destroy = sdebug_target_destroy,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1016/2151 scsi: scsi_debug: Stop printing extra function name in debug logs
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Garry <[email protected]>
[ Upstream commit a743b120227a371f37c46738d91cc7a9691dbcf6 ]
The driver defines as follows pr_fmt:
#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
...meaning that we already get the function name added in any debug statements.
Remove using of __func__ in debug logs to avoid the duplication.
For instances of where the function name was being printed, add some verbose comment to avoid using "" (which would be a bit silly).
It would be nicer to stop using pr_fmt(), but that would mean rewriting approx 100 debug statements to have a sensible and clear message.
Stable-dep-of: 92feb036a2d3 ("scsi: scsi_debug: Avoid 32-bit overflow in WRITE SCATTERED offsets")
--- drivers/scsi/scsi_debug.c | 101 +++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 56 deletions(-)
drivers/scsi/scsi_debug.c +45 -56
@@ -1369,8 +1369,7 @@ static void mk_sense_invalid_fld(struct scsi_cmnd *scp, sbuff = scp->sense_buffer;if (!sbuff) { -sdev_printk (KERN_ERR , scp->device, -"%s: sense_buffer is NULL\n" , __func__); +sdev_printk (KERN_ERR , scp->device,"sense_buffer is NULL\n" );return ; } asc = c_d ?INVALID_FIELD_IN_CDB :INVALID_FIELD_IN_PARAM_LIST ;
@@ -1402,8 +1401,7 @@ static void mk_sense_invalid_fld(struct scsi_cmnd *scp,static void mk_sense_buffer (struct scsi_cmnd *scp,int key,int asc,int asq) {if (!scp->sense_buffer) { -sdev_printk (KERN_ERR , scp->device, -"%s: sense_buffer is NULL\n" , __func__); +sdev_printk (KERN_ERR , scp->device,"sense_buffer is NULL\n" );return ; }memset (scp->sense_buffer,0 ,SCSI_SENSE_BUFFERSIZE );
@@ -1421,8 +1419,7 @@ static void mk_sense_info_tape(struct scsi_cmnd *scp, int key, int asc, int asq, unsigned int information, unsigned char tape_flags) {if (!scp->sense_buffer) { -sdev_printk (KERN_ERR , scp->device, -"%s: sense_buffer is NULL\n" , __func__); +sdev_printk (KERN_ERR , scp->device,"sense_buffer is NULL\n" );return ; }memset (scp->sense_buffer,0 ,SCSI_SENSE_BUFFERSIZE );
@@ -1450,15 +1447,12 @@ static int scsi_debug_ioctl(struct scsi_device *dev, unsigned int cmd, {if (sdebug_verbose) {if (0x1261 == cmd) -sdev_printk (KERN_INFO , dev, -"%s: BLKFLSBUF [0x1261]\n" , __func__); +sdev_printk (KERN_INFO , dev,"BLKFLSBUF [0x1261]\n" );else if (0x5331 == cmd)sdev_printk (KERN_INFO , dev, -"%s: CDROM_GET_CAPABILITY [0x5331]\n" , - __func__); +"CDROM_GET_CAPABILITY [0x5331]\n" );else -sdev_printk (KERN_INFO , dev,"%s: cmd=0x%x\n" , - __func__, cmd); +sdev_printk (KERN_INFO , dev,"cmd=0x%x\n" , cmd); }return -EINVAL ;/* return -ENOTTY; // correct return but upsets fdisk */
@@ -1662,8 +1656,8 @@ static int p_fill_from_dev_buffer(struct scsi_cmnd *scp, const void *arr, act_len =sg_pcopy_from_buffer (sdb->table.sgl, sdb->table.nents, arr, arr_len, skip); -pr_debug ("%s: off_dst=%u, scsi_bufflen=%u, act_len=%u, resid=%d\n" , - __func__, off_dst,scsi_bufflen (scp), act_len, +pr_debug ("off_dst=%u, scsi_bufflen=%u, act_len=%u, resid=%d\n" , + off_dst,scsi_bufflen (scp), act_len,scsi_get_resid (scp)); n =scsi_bufflen (scp) - (off_dst + act_len);scsi_set_resid (scp,min_t (u32,scsi_get_resid (scp), n));
@@ -3186,8 +3180,8 @@ static int resp_mode_select(struct scsi_cmnd *scp,return DID_ERROR <<16 ; else if (sdebug_verbose && (res < param_len)) sdev_printk(KERN_INFO, scp->device, -"%s: cdb indicated=%d, IO sent=%d bytes\n" , - __func__, param_len, res); +"cdb indicated=%d, IO sent=%d bytes\n" , + param_len, res); md_len = mselect6 ? (arr[0 ] +1 ) : (get_unaligned_be16 (arr +0 ) +2 ); bd_len = mselect6 ? arr[3 ] :get_unaligned_be16 (arr +6 ); off = (mselect6 ?4 :8 );
@@ -5123,8 +5117,7 @@ static int resp_write_scat(struct scsi_cmnd *scp,if (lbdof ==0 ) {if (sdebug_verbose)sdev_printk (KERN_INFO , scp->device, -"%s: %s: LB Data Offset field bad\n" , - my_name, __func__); +"%s: LB Data Offset field bad\n" , my_name);mk_sense_buffer (scp,ILLEGAL_REQUEST ,INVALID_FIELD_IN_CDB ,0 );return illegal_condition_result; }
@@ -5132,8 +5125,7 @@ static int resp_write_scat(struct scsi_cmnd *scp,if ((lrd_size + (num_lrd * lrd_size)) > lbdof_blen) {if (sdebug_verbose)sdev_printk (KERN_INFO , scp->device, -"%s: %s: LBA range descriptors don't fit\n" , - my_name, __func__); +"%s: LBA range descriptors don't fit\n" , my_name);mk_sense_buffer (scp,ILLEGAL_REQUEST ,INVALID_FIELD_IN_CDB ,0 );return illegal_condition_result; }
@@ -5142,8 +5134,8 @@ static int resp_write_scat(struct scsi_cmnd *scp,return SCSI_MLQUEUE_HOST_BUSY ;if (sdebug_verbose)sdev_printk (KERN_INFO , scp->device, -"%s: %s: Fetch header+scatter_list, lbdof_blen=%u\n" , - my_name, __func__, lbdof_blen); +"%s: Fetch header+scatter_list, lbdof_blen=%u\n" , + my_name, lbdof_blen); res =fetch_to_dev_buffer (scp, lrdp, lbdof_blen);if (res ==-1 ) { ret =DID_ERROR <<16 ;
@@ -5160,8 +5152,8 @@ static int resp_write_scat(struct scsi_cmnd *scp, num =get_unaligned_be32 (up +8 );if (sdebug_verbose)sdev_printk (KERN_INFO , scp->device, -"%s: %s: k=%d LBA=0x%llx num=%u sg_off=%u\n" , - my_name, __func__, k, lba, num, sg_off); +"%s: k=%d LBA=0x%llx num=%u sg_off=%u\n" , + my_name, k, lba, num, sg_off);if (num ==0 )continue ; ret =check_device_access_params (scp, lba, num, true);
@@ -5173,8 +5165,8 @@ static int resp_write_scat(struct scsi_cmnd *scp,if ((cum_lb + num) > bt_len) {if (sdebug_verbose)sdev_printk (KERN_INFO , scp->device, -"%s: %s: sum of blocks > data provided\n" , - my_name, __func__); +"%s: sum of blocks > data provided\n" , + my_name);mk_sense_buffer (scp,ILLEGAL_REQUEST ,WRITE_ERROR_ASC ,0 ); ret = illegal_condition_result;
@@ -5866,8 +5858,8 @@ static int resp_verify(struct scsi_cmnd *scp, struct sdebug_dev_info *devip) goto cleanup; }else if (sdebug_verbose && (ret < (a_num * lb_size))) {sdev_printk (KERN_INFO , scp->device, -"%s: %s: cdb indicated=%u, IO sent=%d bytes\n" , - my_name, __func__, a_num * lb_size, ret); +"%s: cdb indicated=%u, IO sent=%d bytes\n" , + my_name, a_num * lb_size, ret); }if (is_bytchk3) {for (j =1 , off = lb_size; j < vnum; ++j, off += lb_size)
@@ -6679,14 +6671,14 @@ static int scsi_debug_sdev_configure(struct scsi_device *sdp, devip->debugfs_entry =debugfs_create_dir (dev_name (&sdp->sdev_dev), sdebug_debugfs_root);if (IS_ERR_OR_NULL (devip->debugfs_entry)) -pr_info ("%s: failed to create debugfs directory for device %s\n" , - __func__,dev_name (&sdp->sdev_gendev)); +pr_info ("failed to create debugfs directory for device %s\n" , +dev_name (&sdp->sdev_gendev)); dentry =debugfs_create_file ("error" ,0600 , devip->debugfs_entry, sdp, &sdebug_error_fops);if (IS_ERR_OR_NULL (dentry)) -pr_info ("%s: failed to create error file for device %s\n" , - __func__,dev_name (&sdp->sdev_gendev)); +pr_info ("failed to create error file for device %s\n" , +dev_name (&sdp->sdev_gendev));return 0 ; }
@@ -6874,7 +6866,7 @@ static int scsi_debug_abort(struct scsi_cmnd *SCpnt)if (SDEBUG_OPT_ALL_NOISE & sdebug_opts)sdev_printk (KERN_INFO , SCpnt->device, -"%s: command%s found\n" , __func__, +"command%s found\n" , aborted ?"" :" not" );
@@ -6962,7 +6954,7 @@ static int scsi_debug_device_reset(struct scsi_cmnd *SCpnt) ++num_dev_resets;if (SDEBUG_OPT_ALL_NOISE & sdebug_opts) -sdev_printk (KERN_INFO , sdp,"%s\n" , __func__); +sdev_printk (KERN_INFO , sdp,"doing device reset" );scsi_debug_stop_all_queued (sdp);if (devip) {
@@ -7002,7 +6994,7 @@ static int scsi_debug_target_reset(struct scsi_cmnd *SCpnt) ++num_target_resets;if (SDEBUG_OPT_ALL_NOISE & sdebug_opts) -sdev_printk (KERN_INFO , sdp,"%s\n" , __func__); +sdev_printk (KERN_INFO , sdp,"doing target reset\n" );list_for_each_entry (devip, &sdbg_host->dev_info_list, dev_list) {if (devip->target == sdp->id) {
@@ -7015,7 +7007,7 @@ static int scsi_debug_target_reset(struct scsi_cmnd *SCpnt)if (SDEBUG_OPT_RESET_NOISE & sdebug_opts)sdev_printk (KERN_INFO , sdp, -"%s: %d device(s) found in target\n" , __func__, k); +"%d device(s) found in target\n" , k);if (sdebug_fail_target_reset (SCpnt)) { scmd_printk(KERN_INFO, SCpnt, "fail target reset 0x%x\n",
@@ -7036,7 +7028,7 @@ static int scsi_debug_bus_reset(struct scsi_cmnd *SCpnt) ++num_bus_resets;if (SDEBUG_OPT_ALL_NOISE & sdebug_opts) -sdev_printk (KERN_INFO , sdp,"%s\n" , __func__); +sdev_printk (KERN_INFO , sdp,"doing bus reset\n" );list_for_each_entry (devip, &sdbg_host->dev_info_list, dev_list) {set_bit (SDEBUG_UA_BUS_RESET , devip->uas_bm);
@@ -7047,7 +7039,7 @@ static int scsi_debug_bus_reset(struct scsi_cmnd *SCpnt)if (SDEBUG_OPT_RESET_NOISE & sdebug_opts)sdev_printk (KERN_INFO , sdp, -"%s: %d device(s) found in host\n" , __func__, k); +"%d device(s) found in host\n" , k);return SUCCESS ; }
@@ -7059,7 +7051,7 @@ static int scsi_debug_host_reset(struct scsi_cmnd *SCpnt) ++num_host_resets;if (SDEBUG_OPT_ALL_NOISE & sdebug_opts) -sdev_printk (KERN_INFO , SCpnt->device,"%s\n" , __func__); +sdev_printk (KERN_INFO , SCpnt->device,"doing host reset\n" );mutex_lock (&sdebug_host_list_mutex);list_for_each_entry (sdbg_host, &sdebug_host_list, host_list) { list_for_each_entry(devip, &sdbg_host->dev_info_list,
@@ -7074,7 +7066,7 @@ static int scsi_debug_host_reset(struct scsi_cmnd *SCpnt)stop_all_queued ();if (SDEBUG_OPT_RESET_NOISE & sdebug_opts)sdev_printk (KERN_INFO , SCpnt->device, -"%s: %d device(s) found\n" , __func__, k); +"%d device(s) found\n" , k);return SUCCESS ; }
@@ -7225,8 +7217,8 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip, scsi_result = device_qfull_result;if (unlikely (SDEBUG_OPT_Q_NOISE & sdebug_opts)) -sdev_printk (KERN_INFO , sdp,"%s: num_in_q=%d +1, <inject> status: TASK SET FULL\n" , - __func__, num_in_q); +sdev_printk (KERN_INFO , sdp,"num_in_q=%d +1, <inject> status: TASK SET FULL\n" , + num_in_q); } }
@@ -7252,8 +7244,8 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip, }if (unlikely (sdebug_verbose && cmnd->result)) -sdev_printk (KERN_INFO , sdp,"%s: non-zero result=0x%x\n" , - __func__, cmnd->result); +sdev_printk (KERN_INFO , sdp,"non-zero result=0x%x\n" , + cmnd->result);if (delta_jiff >0 || ndelay >0 ) {ktime_t kt;
@@ -8691,7 +8683,7 @@ static int __init scsi_debug_init(void) sdebug_debugfs_root =debugfs_create_dir ("scsi_debug" ,NULL );if (IS_ERR_OR_NULL (sdebug_debugfs_root)) -pr_info ("%s: failed to create initial debugfs directory\n" , __func__); +pr_info ("failed to create initial debugfs directory\n" );for (k =0 ; k < hosts_to_add; k++) {if (want_store && k ==0 ) {
@@ -8807,7 +8799,7 @@ static int sdebug_add_store(void)if (unlikely (res <0 )) {xa_unlock_irqrestore (per_store_ap, iflags);kfree (sip); -pr_warn ("%s: xa_alloc() errno=%d\n" , __func__, -res); +pr_warn ("xa_alloc() errno=%d\n" , -res);return res; } sdeb_most_recent_idx = n_idx;
@@ -8864,7 +8856,7 @@ static int sdebug_add_store(void)return (int )n_idx; err:sdebug_erase_store ((int )n_idx, sip); -pr_warn ("%s: failed, errno=%d\n" , __func__, -res); +pr_warn ("failed, errno=%d\n" , -res);return res; }
@@ -8923,7 +8915,7 @@ static int sdebug_add_host_helper(int per_host_idx)put_device (&sdbg_host->dev); elsekfree (sdbg_host ); -pr_warn ("%s: failed, errno=%d\n" , __func__, -error); +pr_warn ("failed, errno=%d\n" , -error);return error; }
@@ -8991,7 +8983,7 @@ static int sdebug_change_qdepth(struct scsi_device *sdev, int qdepth)if (qdepth >SDEBUG_CANQUEUE ) { qdepth =SDEBUG_CANQUEUE ; -pr_warn ("%s: requested qdepth [%d] exceeds canqueue [%d], trim\n" , __func__, +pr_warn ("requested qdepth [%d] exceeds canqueue [%d], trim\n" , qdepth,SDEBUG_CANQUEUE ); }if (qdepth <1 )
@@ -9003,7 +8995,7 @@ static int sdebug_change_qdepth(struct scsi_device *sdev, int qdepth)mutex_unlock (&sdebug_host_list_mutex);if (SDEBUG_OPT_Q_NOISE & sdebug_opts) -sdev_printk (KERN_INFO , sdev,"%s: qdepth=%d\n" , __func__, qdepth); +sdev_printk (KERN_INFO , sdev,"qdepth=%d\n" , qdepth);return sdev->queue_depth; }
@@ -9276,8 +9268,7 @@ static void scsi_debug_abort_cmd(struct Scsi_Host *shost, struct scsi_cmnd *scp)bool res = false;if (!to_be_aborted_scmd) { -pr_err ("%s: command with tag %#x not found\n" , __func__, - unique_tag); +pr_err ("command with tag %#x not found\n" , unique_tag);return ; }
@@ -9285,11 +9276,9 @@ static void scsi_debug_abort_cmd(struct Scsi_Host *shost, struct scsi_cmnd *scp) res =scsi_debug_stop_cmnd (to_be_aborted_scmd);if (res) -pr_info ("%s: aborted command with tag %#x\n" , - __func__, unique_tag); +pr_info ("aborted command with tag %#x\n" , unique_tag);else -pr_err ("%s: failed to abort command with tag %#x\n" , - __func__, unique_tag); +pr_err ("failed to abort command with tag %#x\n" , unique_tag);set_host_byte (scp, res ?DID_OK :DID_ERROR ); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1017/2151 scsi: scsi_debug: Avoid 32-bit overflow in WRITE SCATTERED offsets
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Cassel <[email protected]>
[ Upstream commit 92feb036a2d33c7b78b8daa2384f5c70d6679a91 ]
resp_write_scat() computes the length of an LBA range in bytes as a 32-bit product, num_by = num * lb_size, and adds it to sg_off, the 32-bit offset of the next range in the data-out buffer. The product wraps for a range of 4 GiB or more, which check_device_access_params() allows once the store is that large, and sg_off wraps once the ranges add up to 4 GiB, which neither their number nor their overlap prevents. The ranges that follow are then written from the wrong offset in the buffer.
Make num_by and sg_off 64-bit, and pass do_device_access() sg_off capped at the length of the buffer. An offset at the end of the buffer copies nothing, and sg_copy_buffer(), which takes it as an off_t, is never given one larger than the buffer that it copies.
--- drivers/scsi/scsi_debug.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/scsi/scsi_debug.c +8 -5
@@ -5076,7 +5076,8 @@ static int resp_write_scat(struct scsi_cmnd *scp,struct sdeb_store_info *sip =devip2sip (devip, true);u8 wrprotect;u16 lbdof, num_lrd, k; -u32 num, num_by, bt_len, lbdof_blen, sg_off, cum_lb; +u32 num, bt_len, lbdof_blen, cum_lb; +u64 num_by, sg_off;u32 lb_size = sdebug_sector_size;u32 ei_lba;u64 lba;
@@ -5152,14 +5153,14 @@ static int resp_write_scat(struct scsi_cmnd *scp, num =get_unaligned_be32 (up +8 );if (sdebug_verbose)sdev_printk (KERN_INFO , scp->device, -"%s: k=%d LBA=0x%llx num=%u sg_off=%u\n" , +"%s: k=%d LBA=0x%llx num=%u sg_off=%llu\n" , my_name, k, lba, num, sg_off);if (num ==0 )continue ; ret =check_device_access_params (scp, lba, num, true);if (ret) goto err_out_unlock; - num_by = num * lb_size; + num_by = (u64 )num * lb_size; ei_lba = is_16 ?0 :get_unaligned_be32 (up +12 );if ((cum_lb + num) > bt_len) {
@@ -5190,7 +5191,9 @@ static int resp_write_scat(struct scsi_cmnd *scp,* Write ranges atomically to keep as close to pre-atomic * writes behaviour as possible. */ - ret =do_device_access (sip, scp, sg_off, lba, num, group, true, true); + ret =do_device_access (sip, scp, +min_t (u64, sg_off,scsi_bufflen (scp)), + lba, num, group, true, true);/* If ZBC zone then bump its write pointer */ if (sdebug_dev_is_zoned (devip))zbc_inc_wp (devip, lba, num);
@@ -5201,7 +5204,7 @@ static int resp_write_scat(struct scsi_cmnd *scp, goto err_out_unlock; }else if (unlikely (sdebug_verbose && (ret < num_by)))sdev_printk (KERN_INFO , scp->device, -"%s: write: cdb indicated=%u, IO sent=%d bytes\n" , +"%s: write: cdb indicated=%llu, IO sent=%d bytes\n" , my_name, num_by, ret); if (unlikely((sdebug_opts & SDEBUG_OPT_RECOV_DIF_DIX) &&
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1018/2151 scsi: scsi_debug: Advance the write pointer over the data written
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Cassel <[email protected]>
[ Upstream commit cb2d2a7c80c62d1e5e476609706f29dd9584d0e0 ]
resp_write_dt0() and resp_write_scat() advance the write pointer of a sequential write required zone by the transfer length of the command without looking at what do_device_access() returned, which is -1 when the data direction of the command does not match the operation, and a short byte count when the data-out buffer is smaller than the transfer length. An initiator can produce both with SG_IO.
The zone then describes more data than is on the medium, and a write at the position where the data really ends is terminated with UNALIGNED WRITE COMMAND, so the zone has to be reset before it can be written to again.
Advance the write pointer over the data that was written instead. As do_device_access() does not write a partial physical block to such a zone, that leaves the write pointer where a write can end.
--- drivers/scsi/scsi_debug.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/scsi/scsi_debug.c +7 -6
@@ -5029,9 +5029,9 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)if (unlikely (scsi_debug_lbp ()))map_region (sip, lba, num); -/* If ZBC zone then bump its write pointer */ -if (sdebug_dev_is_zoned (devip)) -zbc_inc_wp (devip, lba, num); +/* If ZBC zone then bump its write pointer over the data written */ +if (sdebug_dev_is_zoned (devip) && ret >0 ) +zbc_inc_wp (devip, lba, ret >>ilog2 (sdebug_sector_size));if (meta_data_locked)sdeb_meta_write_unlock (sip);
@@ -5194,9 +5194,10 @@ static int resp_write_scat(struct scsi_cmnd *scp, ret =do_device_access (sip, scp,min_t (u64, sg_off,scsi_bufflen (scp)), lba, num, group, true, true); -/* If ZBC zone then bump its write pointer */ -if (sdebug_dev_is_zoned (devip)) -zbc_inc_wp (devip, lba, num); +/* If ZBC zone then bump its write pointer over the data written */ +if (sdebug_dev_is_zoned (devip) && ret >0 ) +zbc_inc_wp (devip, lba, + ret >>ilog2 (sdebug_sector_size));if (unlikely (scsi_debug_lbp ()))map_region (sip, lba, num);if (unlikely (-1 == ret)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1019/2151 scsi: scsi_debug: Refuse a short WRITE ATOMIC (16) before writing it
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Cassel <[email protected]>
[ Upstream commit b81608b17c5d04c797e6fc1cfb95182c842a4db9 ]
A write whose data-out buffer is shorter than its transfer length is short. An ordinary write transfers what the buffer holds and reports the rest as a residual, but an atomic write cannot be short: SBC-6 r02 (T10/BSR INCITS 587), 4.28.1, requires each atomic write operation to write either all of its data or none of it, and 4.28.2 requires one that cannot complete to leave the LBAs that it specifies unaltered.
resp_atomic_write() does fail a short WRITE ATOMIC (16) with DID_ERROR, but only after do_device_access() has returned, and do_device_access() copies one logical block at a time, so by then the blocks that the buffer did hold have been written. An eight block WRITE ATOMIC (16) with a buffer of four fails having overwritten the first four.
Check the length of the buffer before writing anything, and fail the command with the same DID_ERROR as before.
--- drivers/scsi/scsi_debug.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/scsi/scsi_debug.c +8 -0
@@ -6080,6 +6080,14 @@ static int resp_atomic_write(struct scsi_cmnd *scp, } } +/* +* Short atomic writes are not allowed: SBC-6 4.28.2 requires an +* atomic write that cannot complete to leave its LBAs unaltered, and +* do_device_access() would already have written part of it. +*/ +if (scsi_bufflen (scp) < len * sdebug_sector_size) +return DID_ERROR <<16 ; + ret =do_device_access (sip, scp,0 , lba, len,0 , true, true);if (unlikely (ret ==-1 ))return DID_ERROR <<16 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1020/2151 scsi: scsi_debug: Map the region written by WRITE ATOMIC (16)
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Cassel <[email protected]>
[ Upstream commit 491bd55c35cbb1ce059f22e7f3c6284551970fef ]
When logical block provisioning is enabled, every command that writes user data calls map_region() so that GET LBA STATUS reports the region as mapped. resp_atomic_write() does not, so GET LBA STATUS keeps reporting a region as deallocated after a WRITE ATOMIC (16) has written it.
Call map_region() the way resp_write_dt0() does, holding the zone metadata write lock across the access. That lock is what serialises the map against resp_unmap(), which does nothing unless logical block provisioning is enabled.
--- drivers/scsi/scsi_debug.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/scsi/scsi_debug.c +14 -0
@@ -4809,6 +4809,11 @@ static unsigned int map_state(struct sdeb_store_info *sip, sector_t lba,return mapped; } +/* +* Callers may map the whole range of a write without checking how much of +* it was written. SBC-6 4.7.4.6.2 allows a deallocated LBA to become mapped +* at any time, and only requires an LBA that was written to be mapped. +*/ static void map_region (struct sdeb_store_info *sip,sector_t lba,unsigned int len) {
@@ -6036,6 +6041,7 @@ static int resp_atomic_write(struct scsi_cmnd *scp,u8 *cmd = scp->cmnd;u16 boundary, len;u64 lba, lba_tmp; +bool lbp =scsi_debug_lbp ();int ret;if (!scsi_debug_atomic_write ()) {
@@ -6088,7 +6094,15 @@ static int resp_atomic_write(struct scsi_cmnd *scp,if (scsi_bufflen (scp) < len * sdebug_sector_size)return DID_ERROR <<16 ; +if (lbp) +sdeb_meta_write_lock (sip); + ret =do_device_access (sip, scp,0 , lba, len,0 , true, true); +if (lbp) { +map_region (sip, lba, len); +sdeb_meta_write_unlock (sip); + } +if (unlikely (ret ==-1 ))return DID_ERROR <<16 ;if (unlikely (ret != len * sdebug_sector_size))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1021/2151 scsi: scsi_debug: Validate the access parameters of WRITE ATOMIC (16)
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Cassel <[email protected]>
[ Upstream commit a6c339feb830daa097ccc4c50c339c1733c12d42 ]
resp_atomic_write() validates the fields that are specific to an atomic write, but never the range that the command addresses. Every other command that writes user data calls check_device_access_params() first, which rejects a transfer that ends beyond the capacity of the device, one whose length exceeds the size of the store, and any write to a write protected device.
Call check_device_access_params(). The zone checks that it ends with are unreachable, as atomic writes and ZBC emulation are mutually exclusive.
--- drivers/scsi/scsi_debug.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/scsi/scsi_debug.c +4 -0
@@ -6086,6 +6086,10 @@ static int resp_atomic_write(struct scsi_cmnd *scp, } } + ret =check_device_access_params (scp, lba, len, true); +if (ret) +return ret; +/* * Short atomic writes are not allowed: SBC-6 4.28.2 requires an * atomic write that cannot complete to leave its LBAs unaltered, and
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1022/2151 scsi: st: Restore changed drive settings after reset also for MTLOAD and MTRETEN
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Laurence Oberman <[email protected]>
[ Upstream commit 8d1cc285194dbcba88c136e1ff7c25cb10e38a5b ]
A device reset returns the drive's density and block size to their defaults. Commit 7081dc75df79 ("scsi: st: Restore some drive settings after reset") re-applies values changed by the user when the position is recovered with MTREW, MTSEEK or MTEOM. MTLOAD and MTRETEN are also allowed to clear the reset condition and also leave the same medium at BOT, but they restore nothing.
Because check_tape() reads the drive's block size with MODE SENSE on every open, the driver silently switches to the drive default after the reset. An application that set fixed-block mode with MTSETBLK and recovers with MTLOAD or MTRETEN keeps writing, but variable-length blocks, without any error.
Restore the changed density and block size for MTLOAD and MTRETEN as well. Both operations may make the drive report a new medium, and the new session started by check_tape() clears the "changed" flags and applies the mode defaults. So save the values before the operation, let check_tape() run first (do_load_unload() already calls it for MTLOAD; call it after MTRETEN), and then re-apply them. Retry the restore once in case a unit attention is still pending. Only restore when the drive is ready after the
operation: with an immediate-mode load and O_NONBLOCK, check_tape() does not wait and the drive may still be loading. In immediate mode (MT_ST_NOWAIT) MTRETEN may return before the retension has finished; do not wait for it there.
MTOFFL is not changed: the medium is unloaded and a different one may be loaded next, for which the mode defaults apply.
Reproduced with scsi_debug (which reports a new medium after MTRETEN and MTLOAD) and with IBM LTO drives on FC (which do not).
--- drivers/scsi/st.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)
drivers/scsi/st.c +51 -0
@@ -3535,6 +3535,23 @@ static int partition_tape(struct scsi_tape *STp, int size) +/* +* Re-apply a density and block size that were changed by the user before a +* device reset (a negative value means "not changed"). A unit attention +* still pending after the operation (e.g. new medium after a load) fails the +* first MODE SELECT, so retry each once. As in the other post-reset restore +* path, errors are ignored and one setting failing does not prevent +* restoring the other. +*/ +static void st_restore_changed_settings (struct scsi_tape *STp,int density, +int blksize) +{ +if (density >=0 &&st_int_ioctl (STp,MTSETDENSITY , density)) +st_int_ioctl (STp,MTSETDENSITY , density); +if (blksize >=0 &&st_int_ioctl (STp,MTSETBLK , blksize)) +st_int_ioctl (STp,MTSETBLK , blksize); +} +/* The ioctl command */ static long st_ioctl (struct file *file,unsigned int cmd_in,unsigned long arg) {
@@ -3543,6 +3560,7 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg)int retval =0 ;unsigned int blk;bool cmd_mtiocget; +int restore_density =-1 , restore_blksize =-1 ;struct scsi_tape *STp = file->private_data;struct st_modedef *STm;struct st_partstat *STps;
@@ -3680,6 +3698,17 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg)st_int_ioctl (STp,MTSETDENSITY , STp->changed_density);if (STp->blksize_changed)st_int_ioctl (STp,MTSETBLK , STp->changed_blksize); + }else if (mtc.mt_op ==MTLOAD || mtc.mt_op ==MTRETEN ) { +/* +* The same medium ends up at BOT, so the settings +* apply as with MTREW. The operation may start a +* new session, which clears the "changed" flags: +* save the values and restore them afterwards. +*/ +if (STp->density_changed) + restore_density = STp->changed_density; +if (STp->blksize_changed) + restore_blksize = STp->changed_blksize; } }
@@ -3759,6 +3788,14 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg)if (mtc.mt_op ==MTLOAD ) { retval =do_load_unload (STp, file,max (1 , mtc.mt_count)); +/* +* Restore only if the drive is ready: after an +* immediate-mode load with O_NONBLOCK, check_tape() +* does not wait and the drive may still be loading. +*/ +if (!retval && STp->ready ==ST_READY ) +st_restore_changed_settings (STp, restore_density, + restore_blksize); goto out; }
@@ -3777,6 +3814,20 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg) retval =st_compression (STp, (mtc.mt_count &1 )); else retval =st_int_ioctl (STp, mtc.mt_op, mtc.mt_count); +if (!retval && mtc.mt_op ==MTRETEN && !STp->immediate && + (restore_density >=0 || restore_blksize >=0 )) { +/* +* Retension reloads the medium and the drive may +* report a new medium. Let check_tape() start the new +* session (applying the mode defaults) now, as for +* MTLOAD; otherwise it happens at the next open and +* overrides the restored settings. +*/ +if (check_tape (STp, file) >=0 && + STp->ready ==ST_READY ) +st_restore_changed_settings (STp, restore_density, + restore_blksize); + } goto out; }if (!STm->defined) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1023/2151 scsi: st: Record the tape position after a successful MTLOAD
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Laurence Oberman <[email protected]>
[ Upstream commit 54ee0ee9bdeb7e9d3b70cc5c2bdf7e58c4423e8d ]
Commit 0b120edb37dc ("scsi: st: Add MTIOCGET and MTLOAD to ioctls allowed after device reset") allows MTLOAD to clear the reset condition because the tape location is known after MTLOAD. But the driver does not record it:reset_state() sets the file and block numbers to -1, and do_load_unload() leaves them there. check_tape() sets them to 0 only for a new session, which requires a new-medium unit attention. Drives that do not report one when the medium was already loaded (seen with IBM LTO drives) keep reporting file/block -1 in MTIOCGET and no BOT, although the tape is at the beginning.
After a successful load, reset the partition and the state of all partitions, as the new-session path in check_tape() does: partition 0, position at BOT, EOF state cleared and no pending write. Otherwise the driver may still record the previous partition, so that a later MTSETPART to that partition is not performed; a read after loading at EOD fails with EIO; and a partition left in the ST_WRITING state by a partition switch in read() or write() makes st_flush() write a filemark at the beginning of partition 0 when the device is closed.
--- drivers/scsi/st.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
drivers/scsi/st.c +24 -0
@@ -2685,6 +2685,30 @@ static int do_load_unload(struct scsi_tape *STp, struct file *filp, int load_codelse { STp->rew_at_close = STp->autorew_dev; retval =check_tape (STp, filp); +/* +* LOAD leaves the medium at the beginning of partition +* 0. check_tape() records that only for a new session; +* without a new-medium unit attention (the medium was +* already loaded) the partition and the partition state +* would be left as before the load. Reset them as a +* new session does, for all partitions: a stale +* ST_WRITING state would make st_flush() write a +* filemark at the beginning of partition 0. +*/ +if (retval ==CHKRES_READY ) { +int i; + + STp->partition = STp->new_partition =0 ; +for (i =0 ; i <ST_NBR_PARTITIONS ; i++) { + STps = &(STp->ps[i]); + STps->rw =ST_IDLE ; + STps->eof =ST_NOEOF ; + STps->at_sm =0 ; + STps->last_block_valid =0 ; + STps->drv_block =0 ; + STps->drv_file =0 ; + } + }if (retval >0 ) retval =0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1024/2151 phy: rockchip-samsung-dcphy: Enable runtime PM at PHY core level
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jason Yang <[email protected]>
[ Upstream commit 261e84f9278f4373970471ad71479df20d82ed4c ]
phy_create() only enables runtime PM on the new PHY device if the parent already has it enabled, and this driver enables it afterwards. The PHY device therefore never gets runtime PM, and phy_pm_runtime_get_sync() returns -ENOTSUPP for every phy_init() and phy_power_on(). The block is still resumed today, but only through the supplier link fw_devlink builds from the phys phandle, which fw_devlink=off and =permissive do not.
Move devm_pm_runtime_enable() before devm_phy_create(), as done for the sibling HDPTX PHY in commit 10ba8479f460 ("phy:
phy-rockchip-samsung-hdptx: Enable runtime PM at PHY core level").
--- drivers/phy/rockchip/phy-rockchip-samsung-dcphy.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/phy/rockchip/phy-rockchip-samsung-dcphy.c +4 -4
@@ -1609,16 +1609,16 @@ static int samsung_mipi_dcphy_probe(struct platform_device *pdev)return dev_err_probe (dev,PTR_ERR (samsung->grf_apb_rst),"Failed to get system grf_apb_rst control\n" ); + ret =devm_pm_runtime_enable (dev); +if (ret) +return dev_err_probe (dev, ret,"Failed to enable runtime PM\n" ); + samsung->phy =devm_phy_create (dev,NULL , &samsung_mipi_dcphy_ops);if (IS_ERR (samsung->phy))return dev_err_probe (dev,PTR_ERR (samsung->phy),"Failed to create MIPI DC-PHY\n" );phy_set_drvdata (samsung->phy, samsung); - ret =devm_pm_runtime_enable (dev); -if (ret) -return dev_err_probe (dev, ret,"Failed to enable runtime PM\n" ); - phy_provider =devm_of_phy_provider_register (dev, samsung_mipi_dcphy_xlate);if (IS_ERR (phy_provider)) return dev_err_probe(dev, PTR_ERR(phy_provider),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1025/2151 phy: rockchip: naneng-combphy: Fix TX detect RX termination errata
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shawn Lin <[email protected]>
[ Upstream commit d68e47a06c5cdc90cbd29ce2e74fa61eab5d47cc ]
Some PHY revisions may fail to detect the peer RX's termination resistor (RTERM) under certain critical temperature conditions. This causes TX detection failures on PCIe links.
Add a workaround to force the RTERM detection ready signal for affected PHY revisions. This ensures reliable TX-to-RX termination detection across all operating temperature ranges.
The fix applies to RK3562, RK3568, RK3576 and RK3588 SoCs which share the same PHY IP with this hardware errata.
--- .../rockchip/phy-rockchip-naneng-combphy.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
drivers/phy/rockchip/phy-rockchip-naneng-combphy.c +19 -0
@@ -106,6 +106,9 @@#define RK3568_PHYREG18 0x44#define RK3568_PHYREG18_PLL_LOOP 0x32 +#define RK3568_PHYREG26 0x64 +#define RK3568_PHYREG26_FORCE_RTERM_DET_RDY BIT(5) +#define RK3568_PHYREG30 0x74#define RK3568_PHYREG30_GATE_TX_PCK_SEL BIT(7)#define RK3568_PHYREG30_GATE_TX_PCK_DLY_PLL_OFF BIT(7)
@@ -193,6 +196,7 @@ struct rockchip_combphy_cfg {unsigned int num_phys;unsigned int phy_ids[3 ];const struct rockchip_combphy_grfcfg *grfcfg; +bool force_rxterm_det_rdy;int (*combphy_cfg)(struct rockchip_combphy_priv *priv); };
@@ -264,6 +268,17 @@ static int rockchip_combphy_init(struct phy *phy)switch (priv->type) {case PHY_TYPE_PCIE : +/* +* Hardware Errata: TX fails to detect peer RX termination. +* Some PHY revisions may fail to detect remote RX's RTERM +* (receiver termination resistor) under certain critical +* temperature conditions. Set force rterm detect ready to +* fix it. +*/ +if (priv->cfg->force_rxterm_det_rdy) +rockchip_combphy_updatel (priv,RK3568_PHYREG26_FORCE_RTERM_DET_RDY , +RK3568_PHYREG26_FORCE_RTERM_DET_RDY ,RK3568_PHYREG26 ); + fallthrough;case PHY_TYPE_USB3 :case PHY_TYPE_SATA :case PHY_TYPE_SGMII :
@@ -747,6 +762,7 @@ static const struct rockchip_combphy_cfg rk3562_combphy_cfgs = { }, .grfcfg = &rk3562_combphy_grfcfgs, .combphy_cfg = rk3562_combphy_cfg, + .force_rxterm_det_rdy = true, };static int rk3568_combphy_cfg (struct rockchip_combphy_priv *priv)
@@ -964,6 +980,7 @@ static const struct rockchip_combphy_cfg rk3568_combphy_cfgs = { }, .grfcfg = &rk3568_combphy_grfcfgs, .combphy_cfg = rk3568_combphy_cfg, + .force_rxterm_det_rdy = true, };static int rk3576_combphy_cfg (struct rockchip_combphy_priv *priv)
@@ -1233,6 +1250,7 @@ static const struct rockchip_combphy_cfg rk3576_combphy_cfgs = { }, .grfcfg = &rk3576_combphy_grfcfgs, .combphy_cfg = rk3576_combphy_cfg, + .force_rxterm_det_rdy = true, };static int rk3588_combphy_cfg (struct rockchip_combphy_priv *priv)
@@ -1420,6 +1438,7 @@ static const struct rockchip_combphy_cfg rk3588_combphy_cfgs = { }, .grfcfg = &rk3588_combphy_grfcfgs, .combphy_cfg = rk3588_combphy_cfg, + .force_rxterm_det_rdy = true, };static const struct of_device_id rockchip_combphy_of_match[] = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1026/2151 phy: freescale: fsl-samsung-hdmi: initialize default rate
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aristo Chen <[email protected]>
[ Upstream commit c01ccf91b257741e9edc374a465126bae9ae4711 ]
The HDMI PHY clock reports 74.25 MHz when cur_cfg is unset, but does not establish that rate in hardware. The common clock framework caches the reported rate when registering the clock and skips a first clk_set_rate(74250000) request because the rate appears unchanged.
Consequently, a display whose initial mode uses a 74.25 MHz pixel clock can leave the PHY with its bootloader register state and receive no TMDS signal. Requesting another rate first avoids the issue because the set_rate callback configures the PHY.
Program the 74.25 MHz table entry with the reference clock enabled before registering the clock provider. recalc_rate can then report the configured rate, and a skipped first rate change is safe. Also enable the reference clock when restoring that configuration on resume.
--- drivers/phy/freescale/phy-fsl-samsung-hdmi.c | 59 +++++++++++++++----- 1 file changed, 44 insertions(+), 15 deletions(-)
drivers/phy/freescale/phy-fsl-samsung-hdmi.c +44 -15
@@ -44,6 +44,8 @@#define MHZ (1000UL * 1000UL)#endif +#define PHY_DEFAULT_RATE 74250000 +#define PHY_PLL_DIV_REGS_NUM 7struct phy_config {
@@ -489,17 +491,6 @@ static int fsl_samsung_hdmi_phy_configure(struct fsl_samsung_hdmi_phy *phy,return ret; } -static unsigned long phy_clk_recalc_rate (struct clk_hw *hw, -unsigned long parent_rate) -{ -struct fsl_samsung_hdmi_phy *phy =to_fsl_samsung_hdmi_phy (hw); - -if (!phy->cur_cfg) -return 74250000 ; - -return phy->cur_cfg->pixclk; -} -/* Helper function to lookup the available fractional-divider rate */ static const struct phy_config *fsl_samsung_hdmi_phy_lookup_rate (unsigned long rate) {
@@ -520,6 +511,14 @@ static const struct phy_config *fsl_samsung_hdmi_phy_lookup_rate(unsigned long r &phy_pll_cfg[i] : &phy_pll_cfg[i+1]); } +static unsigned long phy_clk_recalc_rate (struct clk_hw *hw, +unsigned long parent_rate) +{ +struct fsl_samsung_hdmi_phy *phy =to_fsl_samsung_hdmi_phy (hw); + +return phy->cur_cfg->pixclk; +} +static void fsl_samsung_hdmi_calculate_phy (struct phy_config *cal_phy,unsigned long rate,u8 p,u16 m,u8 s) {
@@ -637,6 +636,7 @@ static int phy_clk_register(struct fsl_samsung_hdmi_phy *phy)static int fsl_samsung_hdmi_phy_probe (struct platform_device *pdev) { +const struct phy_config *default_cfg;struct fsl_samsung_hdmi_phy *phy;int ret;
@@ -661,6 +661,23 @@ static int fsl_samsung_hdmi_phy_probe(struct platform_device *pdev)return dev_err_probe (phy->dev,PTR_ERR (phy->refclk),"failed to get ref clk\n" ); +/* +* Establish the rate reported by recalc_rate() before registering the +* clock. Otherwise CCF may skip the first set_rate() when it requests +* the assumed default rate, leaving the PHY unconfigured. +*/ + ret =clk_prepare_enable (phy->refclk); +if (ret) +return dev_err_probe (phy->dev, ret, +"failed to enable ref clk\n" ); + + default_cfg =fsl_samsung_hdmi_phy_lookup_rate (PHY_DEFAULT_RATE ); + ret =fsl_samsung_hdmi_phy_configure (phy, default_cfg); +clk_disable_unprepare (phy->refclk); +if (ret) +return dev_err_probe (phy->dev, ret, +"failed to configure default rate\n" ); +pm_runtime_get_noresume (phy->dev);pm_runtime_set_active (phy->dev);pm_runtime_enable (phy->dev);
@@ -696,7 +713,7 @@ static int __maybe_unused fsl_samsung_hdmi_phy_suspend(struct device *dev)static int __maybe_unused fsl_samsung_hdmi_phy_resume (struct device *dev) {struct fsl_samsung_hdmi_phy *phy =dev_get_drvdata (dev); -int ret =0 ; +int ret; ret =clk_prepare_enable (phy->apbclk);if (ret) {
@@ -704,11 +721,23 @@ static int __maybe_unused fsl_samsung_hdmi_phy_resume(struct device *dev)return ret; } -if (phy->cur_cfg) - ret =fsl_samsung_hdmi_phy_configure (phy, phy->cur_cfg); +if (!phy->cur_cfg) +return 0 ; -return ret; + ret =clk_prepare_enable (phy->refclk); +if (ret) { +dev_err (phy->dev,"failed to enable ref clk\n" ); + goto disable_apbclk; + } + + ret =fsl_samsung_hdmi_phy_configure (phy, phy->cur_cfg); +clk_disable_unprepare (phy->refclk); +if (!ret) +return 0 ; +disable_apbclk: +clk_disable_unprepare (phy->apbclk); +return ret; } static DEFINE_RUNTIME_DEV_PM_OPS(fsl_samsung_hdmi_phy_pm_ops,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1027/2151 md: take reconfig_mutex when enabling PPL on an inactive array
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nguyen Ngoc Thang <[email protected]>
[ Upstream commit 900bf42e0ff8009f66ffd4a679c56264957019dd ]
consistency_policy_store() sets MD_HAS_PPL for an external-metadata array that is not running yet, without holding reconfig_mutex. But ->pers is only assigned after pers->run() returns, so "not running" also covers an md_run() that is in progress under the lock.
If the write lands inside raid5_run() after log_init() has decided not to set up PPL, or after a failed ppl_init_log() has cleared the flag, the flag ends up set with conf->log_private still NULL. The next idle pass of raid5d() then does:
raid5d() -> handle_active_stripes() -> log_flush_stripe_to_raid()
-> ppl_write_stripe_run()
and dereferences the NULL ppl_conf:
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000002 KASAN: null-ptr-deref in range [0x0000000000000010-0x0000000000000017] RIP: 0010:ppl_write_stripe_run+0x60/0x1320 drivers/md/raid5-ppl.c:538
Take reconfig_mutex around the update and refuse it with -EBUSY once the array is running, in which case ->change_consistency_policy() is the right interface.
--- drivers/md/md.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/md/md.c +9 -1
@@ -5870,7 +5870,15 @@ consistency_policy_store(struct mddev *mddev, const char *buf, size_t len)else err = -EBUSY ; }else if (mddev->external &&strncmp (buf,"ppl" ,3 ) ==0 ) { -set_bit (MD_HAS_PPL , &mddev->flags); +/* md_run() holds the lock until ->pers is set */ + err =mddev_lock (mddev); +if (err) +return err; +if (mddev->pers) + err = -EBUSY ; +else +set_bit (MD_HAS_PPL , &mddev->flags); +mddev_unlock (mddev); }else { err = -EINVAL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1028/2151 md/raid5: drain released_stripes before destroying the cache
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li Youhong <[email protected]>
[ Upstream commit af560e357a81964544be40c549e241b032ef7565 ]
grow_one_stripe() calls raid5_release_stripe() for each new stripe. When mddev->thread is already set, that queues the stripe on conf->released_stripes and wakes the thread. Only raid5d moves that list onto inactive_list.
Takeover calls setup_conf() while mddev->thread still belongs to the previous personality, so those stripes stay on released_stripes. If setup_conf() then fails, shrink_stripes() only frees inactive_list and kmem_cache_destroy() warns that objects remain.
Move stripes still queued on released_stripes onto inactive_list before shrink_stripes() frees them.
--- drivers/md/raid5.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
drivers/md/raid5.c +31 -0
@@ -2698,6 +2698,37 @@ static int drop_one_stripe(struct r5conf *conf)static void shrink_stripes (struct r5conf *conf) { +struct list_head temp[NR_STRIPE_HASH_LOCKS ]; +int i; + +/* +* grow_one_stripe() parks new stripes on released_stripes when +* mddev->thread is already set. Takeover leaves the previous +* personality's thread there, so raid5d never moves them to +* inactive_list. Drain them before the cache is destroyed. +* slab_cache is assigned only after device_lock and the hash +* lists exist; earlier abort paths have nothing to drain. +*/ +if (conf->slab_cache) { +for (i =0 ; i <NR_STRIPE_HASH_LOCKS ; i++) +INIT_LIST_HEAD (&temp[i]); + +spin_lock_irq (&conf->device_lock); +release_stripe_list (conf, temp); +spin_unlock_irq (&conf->device_lock); + +for (i =0 ; i <NR_STRIPE_HASH_LOCKS ; i++) { +if (list_empty (&temp[i])) +continue ; +spin_lock_irq (conf->hash_locks + i); +if (list_empty (conf->inactive_list + i)) +atomic_dec (&conf->empty_inactive_list_nr); +list_splice_tail_init (&temp[i], + conf->inactive_list + i); +spin_unlock_irq (conf->hash_locks + i); + } + } +while (conf->max_nr_stripes &&drop_one_stripe (conf)) ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1029/2151 clk: imx: composite-93: return timeout from gate enable
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linkai Gong <[email protected]>
[ Upstream commit 246d9fa6b83d2d3c524aad28de1ab5db5cecf048 ]
imx93_clk_composite_wait_ready() already reports a busy timeout, but imx93_clk_composite_gate_enable() ignores that and always returns 0. The clk framework then marks the clock enabled and lets consumers run while the CCM slice is still busy.
Propagate the timeout so enable fails instead of looking successful.
--- drivers/clk/imx/clk-composite-93.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/clk/imx/clk-composite-93.c +6 -5
@@ -43,11 +43,12 @@ static int imx93_clk_composite_wait_ready(struct clk_hw *hw, void __iomem *reg)return ret; } -static void imx93_clk_composite_gate_endisable (struct clk_hw *hw,int enable) +static int imx93_clk_composite_gate_endisable (struct clk_hw *hw,int enable) {struct clk_gate *gate =to_clk_gate (hw);unsigned long flags;u32 reg; +int ret;if (gate->lock)spin_lock_irqsave (gate->lock, flags);
@@ -61,17 +62,17 @@ static void imx93_clk_composite_gate_endisable(struct clk_hw *hw, int enable)writel (reg, gate->reg); -imx93_clk_composite_wait_ready (hw, gate->reg); + ret =imx93_clk_composite_wait_ready (hw, gate->reg);if (gate->lock)spin_unlock_irqrestore (gate->lock, flags); + +return ret; }static int imx93_clk_composite_gate_enable (struct clk_hw *hw) { -imx93_clk_composite_gate_endisable (hw,1 ); - -return 0 ; +return imx93_clk_composite_gate_endisable (hw,1 ); }static void imx93_clk_composite_gate_disable (struct clk_hw *hw)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1030/2151 md/raid5: protect big_stripe_tree lookup with RCU
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sang-Hoon Choi <[email protected]>
[ Upstream commit 73b0df929494522acf9ccc8dafea4f721166965b ]
big_stripe_tree is updated under tree_lock, and deleted radix-tree nodes are freed after an RCU grace period. r5c_big_stripe_cached() used to run under an RCU read-side critical section, but that protection was removed together with unrelated rdev lookup protection.
The lookup can now be preempted while walking the tree, allowing a concurrent deletion and grace period to complete before the walk resumes. Protect the lookup locally with rcu_read_lock(). Only the presence of the entry is used after unlocking.
--- drivers/md/raid5-cache.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/md/raid5-cache.c +2 -0
@@ -2970,7 +2970,9 @@ bool r5c_big_stripe_cached(struct r5conf *conf, sector_t sect)return false; tree_index =r5c_tree_index (conf, sect); +rcu_read_lock (); slot =radix_tree_lookup (&log->big_stripe_tree, tree_index); +rcu_read_unlock ();return slot !=NULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1031/2151 dt-bindings: media: sun4i-a10-video-engine: Fix IOMMU count for H6
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chen-Yu Tsai <[email protected]>
[ Upstream commit ca9a67831805dc788407a05f276abb6b86b1174d ]
On the H6 SoC, the Video Engine has two memory ports, thus two IOMMU connections. The secondary one that is missing is likely used for reading reference frames. The newer H616 is the same. On the other hand, the D1 only has one memory port.
Add the missing IOMMU connection for the Video Engine.
--- .../allwinner,sun4i-a10-video-engine.yaml | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/media/allwinner,sun4i-a10-video-engine.yaml +20 -1
@@ -55,7 +55,10 @@ properties: description: Phandle to the device SRAM iommus: - maxItems: 1 + minItems: 1 + items: + - description: VE port on IOMMU + - description: VE_R port on IOMMU memory-region: maxItems: 1
@@ -82,6 +85,22 @@ required: - resets - allwinner,sram +allOf: + - if: + properties: + compatible: + contains: + enum: + - allwinner,sun50i-h6-video-engine + then: + properties: + iommus: + minItems: 2 + else: + properties: + iommus: + maxItems: 1 + additionalProperties: false examples:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1032/2151 power: supply: bq24190_charger: dont reset registers across system suspend
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ryan Brue <[email protected]>
[ Upstream commit e0844bd22a9f97885882bde3c4a441710e895240 ]
bq24190_pm_suspend() calls bq24190_register_reset(), which returns every register to its power-on default, and bq24190_pm_resume() does it again before re-applying the probe-time configuration. On any board that wires the charger's interrupt this makes system suspend unusable.
The reset re-arms the chip's 40 s i2c watchdog. bq24190_set_config() turns that watchdog off at probe, deliberately: as the comment there explains, the same write also takes the part out of default mode into host mode. Nothing pets it while the system is asleep, so it expires, resets the registers again and pulses INT. The charger interrupt is a system wake source -- armed unconditionally in probe since commit f385e6e2a153 ("power:bq24190_charger: Use PM runtime autosuspend"), and still enabled by default after the conversion to the wake irq API [1] -- so the pulse wakes the machine.
Measured on an MT8173 board (Amazon Fire HD 10 2017, BQ24297) by swapping only this driver between builds with and without this change, asking for a 150 s suspend each time:
on charger, with the reset: 41-43 s, 7 runs of 7 on charger, without the reset: 150 s, 3 runs of 3 on battery, with the reset: 40-41 s, 3 runs of 3 on battery, without the reset: 150 s, 3 runs of 3
It is not a charging-only problem. The watchdog runs from VBUS or from the battery, so an unplugged tablet loses suspend in the same way.
ftrace names the wake source. Across the resume, the first device interrupt after the machine comes back is the charger:
1270.760799: suspend_resume: machine_suspend[3] end 1270.775683: irq_handler_entry: irq=25 name=bq24190-charger 1270.776156: irq_handler_entry: irq=250 name=11010000.i2c
Everything between is IPI and arch_timer from bringing the secondary CPUs back up, and no RTC interrupt appears anywhere in the trace -- the 150 s wake alarm never fired. The cause leaves nothing behind for userspace to find, because WATCHDOG_FAULT is in the latch-on-read fault register and the driver's own interrupt handler has already consumed it.
The reset also discards host configuration that nothing restores. Resume calls bq24190_set_config(), which writes only the watchdog, SYS_MIN, IPRECHG, ITERM, ICHG and VREG, so:
- IINLIM returns to its power-on default. Boards without a charger-type detector set the input limit from userspace; measured here, one ordinary suspend/resume silently took input_current_limit from 1500 mA to 500 mA, and to 100 mA when running from the battery, where the default differs.
- EN_HIZ is cleared, so a charger the host put into high-impedance mode starts drawing from VBUS again the moment the system sleeps.
There is no way to have both. Default mode is what the reset is for, and on this part default mode and a disarmed watchdog are mutually exclusive: a write to any register moves the chip into host mode, and it only returns to default mode when the watchdog times out. Parking it in default mode for the sleep therefore always leaves a timer armed that will fire, and on any board that wires INT that firing is a wake. A per-board opt-out would not be choosing between two workable configurations, only between a working suspend and a broken one.
Resetting in suspend buys nothing worth this. The part is in host mode with its watchdog off; it charges on its own, switching from constant current to constant voltage and terminating when the battery is full, and nothing in it can expire or change while the host sleeps. Resetting on resume is weaker
still: the host is awake and about to reconfigure the chip, so the reset only guarantees the loss.
The one thing the reset does guard against is a host that never comes back:
a chip in host mode keeps whatever it was last told, where default mode would revert to the power-on values. But that is the state the driver leaves it in for all of normal runtime operation already, so sleep is not special, and the part still makes its own constant-current to constant-voltage transition and terminates when the battery is full.
So drop it in both directions. The suspend callback has nothing left to do and goes away. Resume re-applies the probe-time configuration, which is idempotent and also recovers a part that did somehow fall back to default mode, since bq24190_set_config() starts by turning the watchdog off.
This has been proposed before. Hans de Goede sent the same change in 2017
[2] and Sebastian Reichel agreed with the reasoning [3], but v6 kept the reset on by default and added the "disable-reset" device property instead [4]. That property cannot answer this: it is set only from x86 platform code -- i2c-cht-wc and x86-android-tablets -- and is not in bq24190.yaml, so no DT board can reach it. Every in-tree DT user of this driver (tegra124-xiaomi-mocha, qcom-msm8974-lge-nexus5-hammerhead, qcom-msm8974pro-oneplus-bacon, rk3188-bqedison2qc) wires the charger interrupt and so has the same wake armed, with no way to opt out. If some board does want the reset, it would be better expressed the other way round.
The vendor kernel for this board does not reset across suspend either: its driver, drivers/power/mt81xx/bq24297.c, only masks the charger interrupt on suspend and unmasks it on resume.
Reproduced on a BQ24297. The reasoning applies to the family, but the other parts were not available to test.
[1] https://lore.kernel.org/all/20260908-rbrue-suez-upstreaming-bq24190_charger-use-wake-irq-api-v1-1-c3f10ae2a34a@gmail.com/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/20170323112052.ukyazi4pnji7n6st@earth/
[4] https://lore.kernel.org/all/[email protected]/
--- drivers/power/supply/bq24190_charger.c | 30 ++++++++------------------ 1 file changed, 9 insertions(+), 21 deletions(-)
drivers/power/supply/bq24190_charger.c +9 -21
@@ -2257,25 +2257,6 @@ static __maybe_unused int bq24190_runtime_resume(struct device *dev)return 0 ; } -static __maybe_unused int bq24190_pm_suspend (struct device *dev) -{ -struct i2c_client *client =to_i2c_client (dev); -struct bq24190_dev_info *bdi =i2c_get_clientdata (client); -int error; - - error =pm_runtime_resume_and_get (bdi->dev); -if (error <0 ) -dev_warn (bdi->dev,"pm_runtime_get failed: %i\n" , error); - -bq24190_register_reset (bdi); - -if (error >=0 ) { -pm_runtime_put_autosuspend (bdi->dev); - } - -return 0 ; -} -static __maybe_unused int bq24190_pm_resume (struct device *dev) {struct i2c_client *client =to_i2c_client (dev);
@@ -2289,7 +2270,14 @@ static __maybe_unused int bq24190_pm_resume(struct device *dev)if (error <0 )dev_warn (bdi->dev,"pm_runtime_get failed: %i\n" , error); -bq24190_register_reset (bdi); +/* +* The chip kept its configuration through the sleep: it is in host +* mode with the i2c watchdog off, so nothing expired and nothing was +* reset. Do not reset it here either -- a userspace setting such as +* EN_HIZ or IINLIM would otherwise be silently lost on every resume. +* Re-applying the probe-time configuration is idempotent and cheap, +* and covers a part that did somehow fall back to default mode. +*/ bq24190_set_config (bdi);bq24190_read (bdi,BQ24190_REG_SS , &bdi->ss_reg);
@@ -2308,7 +2296,7 @@ static __maybe_unused int bq24190_pm_resume(struct device *dev)static const struct dev_pm_ops bq24190_pm_ops = { SET_RUNTIME_PM_OPS(bq24190_runtime_suspend, bq24190_runtime_resume, NULL) -SET_SYSTEM_SLEEP_PM_OPS (bq24190_pm_suspend, bq24190_pm_resume) +SET_SYSTEM_SLEEP_PM_OPS (NULL , bq24190_pm_resume) };static const struct i2c_device_id bq24190_i2c_ids[] = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1033/2151 md: Fix the null-ptr-deref of mddev->private while submitting IO
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhihao Cheng <[email protected]>
[ Upstream commit 4c90b76e0198deb89376988daa8d96b48bea7fcf ]
Concurrent processes md_stop and IO submission can trigger a NULL pointer dereference of mddev->private:
BUG: kernel NULL pointer dereference, address: 0000000000000070 RIP: 0010:_wait_barrier+0x2f/0x250 Call Trace: raid1_make_request+0x150/0xf50 md_handle_request+0x104/0x530 md_submit_bio+0x76/0x130 submit_bio+0xdd/0x250 submit_bio_wait+0x1f/0x40 __blkdev_direct_IO_simple+0x1f6/0x370 blkdev_write_iter+0x3b2/0x520 ksys_write+0x7d/0x190
One process can submit I/O through an open file while a forked process uses the same file to issue STOP_ARRAY. The opener check permits this because md_open() was called only once. do_md_stop() can then clear mddev->private while the I/O is entering the personality make_request callback.
This affects raid0, raid1, raid10, and raid5. Suspend STOP_ARRAY while holding the reconfiguration lock so teardown waits for active_io references to drain. Fail I/O in md_handle_request() if mddev->pers is NULL after the array resumes.
The sysfs stopping paths are protected by mddev_set_closing_and_sync_blockdev(). Apply that protection to both clear and inactive transitions even when the array is read-only. dm-raid teardown is already invoked with the device suspended.
Fetch a reproducer in
https://bugzilla.kernel.org/show_bug.cgi?id=222020
--- drivers/md/md.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
drivers/md/md.c +17 -1
@@ -414,6 +414,20 @@ bool md_handle_request(struct mddev *mddev, struct bio *bio)if (!percpu_ref_tryget_live (&mddev->active_io)) goto check_suspended; } +if (!mddev->pers) { +/* +* The __md_stop() sets 'mddev->private' to NULL during +* the IO submitting, check 'mddev->pers' before the IO +* being processed by specific driver to avoid the +* null-ptr-deref of 'mddev-><member>'. The check is +* safe because the IO has got the 'mddev->active_io' +* reference, and all __md_stop() callers will wait for +* the reference to be zero. +*/ +bio_io_error (bio); +percpu_ref_put (&mddev->active_io); +return true; + }if (!mddev->pers->make_request (mddev, bio)) {percpu_ref_put (&mddev->active_io);if (!mddev->gendisk && mddev->pers->prepare_suspend)
@@ -4665,7 +4679,8 @@ array_state_store(struct mddev *mddev, const char *buf, size_t len)case readonly:case inactive:case read_auto: -if (!mddev->pers || !md_is_rdwr (mddev)) +if (!mddev->pers || + (st != clear && st != inactive && !md_is_rdwr (mddev)))break ;/* write sysfs will not open mddev and opener should be 0 */ err =mddev_set_closing_and_sync_blockdev (mddev,0 );
@@ -8189,6 +8204,7 @@ static bool md_ioctl_need_suspend(unsigned int cmd)case HOT_REMOVE_DISK :case SET_BITMAP_FILE :case SET_ARRAY_INFO : +case STOP_ARRAY :return true;default :return false;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1034/2151 dt-bindings: power: supply: ab8500: Add AB8505 charger
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Walleij <[email protected]>
[ Upstream commit 80d28539c1f9baab72210501729d67e3d9daa4b8 ]
AB8500 and AB8505 expose different charger interrupt sets. Add a unique AB8505 charger compatible with the AB8500 compatible as its fallback. Use the variant-specific string to require the fourteen main and USB charger interrupts on AB8500 and the nine USB charger interrupts on AB8505.
Also clarify that autopower_cfg describes the AB8500 facility, since the corresponding AB8505 register bit is reserved.
--- .../supply/stericsson,ab8500-charger.yaml | 76 ++++++++++++++----- 1 file changed, 56 insertions(+), 20 deletions(-)
Documentation/devicetree/bindings/power/supply/stericsson,ab8500-charger.yaml +56 -20
@@ -10,12 +10,13 @@ title: AB8500 Charger maintainers: - Sebastian Reichel <[email protected]> -allOf: - - $ref: power-supply.yaml# - properties: compatible: - const: stericsson,ab8500-charger + oneOf: + - const: stericsson,ab8500-charger + - items: + - const: stericsson,ab8505-charger + - const: stericsson,ab8500-charger monitored-battery: true
@@ -28,27 +29,15 @@ properties: autopower_cfg: type: boolean - description: automatic poweron after powerloss + description: AB8500 automatic poweron after powerloss interrupts: + minItems: 9 maxItems: 14 interrupt-names: - items: - - const: MAIN_CH_UNPLUG_DET - - const: MAIN_CHARGE_PLUG_DET - - const: MAIN_EXT_CH_NOT_OK - - const: MAIN_CH_TH_PROT_R - - const: MAIN_CH_TH_PROT_F - - const: VBUS_DET_F - - const: VBUS_DET_R - - const: USB_LINK_STATUS - - const: USB_CH_TH_PROT_R - - const: USB_CH_TH_PROT_F - - const: USB_CHARGER_NOT_OKR - - const: VBUS_OVV - - const: CH_WD_EXP - - const: VBUS_CH_DROP_END + minItems: 9 + maxItems: 14 io-channels: minItems: 2
@@ -75,6 +64,53 @@ required: - io-channels - io-channel-names +allOf: + - $ref: power-supply.yaml# + - if: + properties: + compatible: + contains: + const: stericsson,ab8505-charger + then: + properties: + interrupts: + minItems: 9 + maxItems: 9 + + interrupt-names: + items: + - const: VBUS_DET_F + - const: VBUS_DET_R + - const: USB_LINK_STATUS + - const: USB_CH_TH_PROT_R + - const: USB_CH_TH_PROT_F + - const: USB_CHARGER_NOT_OKR + - const: VBUS_OVV + - const: CH_WD_EXP + - const: VBUS_CH_DROP_END + else: + properties: + interrupts: + minItems: 14 + maxItems: 14 + + interrupt-names: + items: + - const: MAIN_CH_UNPLUG_DET + - const: MAIN_CHARGE_PLUG_DET + - const: MAIN_EXT_CH_NOT_OK + - const: MAIN_CH_TH_PROT_R + - const: MAIN_CH_TH_PROT_F + - const: VBUS_DET_F + - const: VBUS_DET_R + - const: USB_LINK_STATUS + - const: USB_CH_TH_PROT_R + - const: USB_CH_TH_PROT_F + - const: USB_CHARGER_NOT_OKR + - const: VBUS_OVV + - const: CH_WD_EXP + - const: VBUS_CH_DROP_END + additionalProperties: false examples:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1035/2151 power: supply: qcom_battmgr: Report capacity on X1E80100
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Liviu Nicoara <[email protected]>
[ Upstream commit f7c62ebfd9127b12a1e39f1cc7f3131cb3065886 ]
Commit 3f87baacea4d ("power: supply: qcom_battmgr: Report battery capacity") added POWER_SUPPLY_PROP_CAPACITY to the SC8280XP battery properties, computed from the firmware's charge and last-full values. When commit cc3e883a0625 ("power: supply: qcom_battmgr: Add charge control support") later gave X1E80100 a property table of its own, the table was copied without the capacity property, so X1E80100 machines expose energy_now and energy_full but no capacity.
The percentage is already computed for this variant in the shared SC8280XP callback; only the property list is missing it. Add it, in the same place it sits in the SC8280XP table.
Tested on a Dell XPS 13 9345: capacity reads 94 with energy_now 52640000 and energy_full 55540000.
--- drivers/power/supply/qcom_battmgr.c | 1 + 1 file changed, 1 insertion(+)
drivers/power/supply/qcom_battmgr.c +1 -0
@@ -834,6 +834,7 @@ static const enum power_supply_property x1e80100_bat_props[] = {POWER_SUPPLY_PROP_STATUS ,POWER_SUPPLY_PROP_PRESENT ,POWER_SUPPLY_PROP_TECHNOLOGY , +POWER_SUPPLY_PROP_CAPACITY ,POWER_SUPPLY_PROP_CYCLE_COUNT ,POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN , POWER_SUPPLY_PROP_VOLTAGE_NOW,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1036/2151 .gitignore: drop Module.markers
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jan Stancek <[email protected]>
[ Upstream commit a7d32fa14bc74d1786a2f0513b6f0815bd4be311 ]
commit fc5377668c3d ("tracing: Remove markers") deleted the marker code and the modpost output. Follow-up commit 8723eaeff59a ("Kbuild: clean up marker") removed it from clean and mrproper targets. Both are from 2009, so the file is hopefully no longer in anyone's tree, drop it from .gitignore as well.
--- .gitignore | 1 - 1 file changed, 1 deletion(-)
.gitignore +0 -1
@@ -70,7 +70,6 @@ modules.order /vmlinux-gdb.py /vmlinuz /System.map -/Module.markers /modules.builtin /modules.builtin.modinfo /modules.builtin.ranges
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1037/2151 power: supply: bq257xx: Use psy directly instead of driver data
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexey Charkov <[email protected]>
[ Upstream commit 1a64071bb30d97b75a1029943b6a3481098b254b ]
bq257xx_external_power_changed() is handed the power supply it is called for, but passes pdata->charger to power_supply_am_i_supplied(). Those are not equivalent during probe or teardown, and a supplier's changed_work can reach power_supply_external_power_changed() when pdata->charger doesn't point anywhere meaningful (e.g. freed memory during teardown).
Use the psy argument, which is valid whenever the callback runs.
--- drivers/power/supply/bq257xx_charger.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/supply/bq257xx_charger.c +1 -1
@@ -564,7 +564,7 @@ static void bq257xx_external_power_changed(struct power_supply *psy) pdata->chip->bq257xx_get_state (pdata); - pdata->supplied =power_supply_am_i_supplied (pdata->charger); + pdata->supplied =power_supply_am_i_supplied (psy);if (pdata->supplied <0 )return ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1038/2151 perf/cxl: Program the requested event group on configurable counters
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dave Jiang <[email protected]>
[ Upstream commit b22dcc11429866e07dc54299255e8ca13c26d38a ]
cxl_pmu_get_event_idx() sets *counter_idx for a configurable counter but never *event_idx. hwc->event_base stays 0, so cxl_pmu_event_start() programs event group 0 no matter which group the user asked for.
Return the matched capability's event_idx.
--- drivers/perf/cxl_pmu.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/perf/cxl_pmu.c +6 -2
@@ -513,7 +513,10 @@ static const struct attribute_group *cxl_pmu_attr_groups[] = { NULL }; -/* If counter_idx == NULL, don't try to allocate a counter. */ +/* +* If counter_idx == NULL, don't try to allocate a counter. Callers that +* allocate pass both counter_idx and event_idx. +*/ static int cxl_pmu_get_event_idx (struct perf_event *event,int *counter_idx,int *event_idx) {
@@ -541,7 +544,7 @@ static int cxl_pmu_get_event_idx(struct perf_event *event, int *counter_idx, pmu_ev =cxl_pmu_find_config_counter_ev_cap (info, vid, gid, mask);if (!IS_ERR (pmu_ev)) { -if (!counter_idx) +if (!counter_idx || !event_idx)return 0 ; bitmap_andnot(configurable_and_free, info->conf_counter_bm,
@@ -552,6 +555,7 @@ static int cxl_pmu_get_event_idx(struct perf_event *event, int *counter_idx,return -EINVAL ; *counter_idx = i; + *event_idx = pmu_ev->event_idx;return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1039/2151 perf/cxl: Clear stale event fields before reprogramming a counter
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dave Jiang <[email protected]>
[ Upstream commit 7406d6cf76b1dad53084f3988dc65ab967209344 ]
cxl_pmu_event_start() ORs the event group id, event mask, edge and invert selections into a configurable counter's config register without clearing them first, and cxl_pmu_event_stop() leaves them set. Reuse the counter for another event and the new selection lands on top of the old one, so the counter counts the wrong events with stale edge and invert behaviour.
Use FIELD_MODIFY() so each field is replaced rather than accumulated.
--- drivers/perf/cxl_pmu.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/perf/cxl_pmu.c +8 -8
@@ -646,17 +646,17 @@ static void cxl_pmu_event_start(struct perf_event *event, int flags) cfg |=FIELD_PREP (CXL_PMU_COUNTER_CFG_INT_ON_OVRFLW ,1 ); cfg |=FIELD_PREP (CXL_PMU_COUNTER_CFG_FREEZE_ON_OVRFLW ,1 ); cfg |=FIELD_PREP (CXL_PMU_COUNTER_CFG_ENABLE ,1 ); - cfg |=FIELD_PREP (CXL_PMU_COUNTER_CFG_EDGE , -cxl_pmu_config1_get_edge (event) ?1 :0 ); - cfg |=FIELD_PREP (CXL_PMU_COUNTER_CFG_INVERT , -cxl_pmu_config1_get_invert (event) ?1 :0 ); +FIELD_MODIFY (CXL_PMU_COUNTER_CFG_EDGE , &cfg, +cxl_pmu_config1_get_edge (event) ?1 :0 ); +FIELD_MODIFY (CXL_PMU_COUNTER_CFG_INVERT , &cfg, +cxl_pmu_config1_get_invert (event) ?1 :0 );/* Fixed purpose counters have next two fields RO */ if (test_bit (hwc->idx, info->conf_counter_bm)) { - cfg |=FIELD_PREP (CXL_PMU_COUNTER_CFG_EVENT_GRP_ID_IDX_MSK , - hwc->event_base); - cfg |=FIELD_PREP (CXL_PMU_COUNTER_CFG_EVENTS_MSK , -cxl_pmu_config_get_mask (event)); +FIELD_MODIFY (CXL_PMU_COUNTER_CFG_EVENT_GRP_ID_IDX_MSK , &cfg, + hwc->event_base); +FIELD_MODIFY (CXL_PMU_COUNTER_CFG_EVENTS_MSK , &cfg, +cxl_pmu_config_get_mask (event)); } cfg &= ~CXL_PMU_COUNTER_CFG_THRESHOLD_MSK ;/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1040/2151 perf/cxl: Fix the counter overflow delta fixup
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dave Jiang <[email protected]>
[ Upstream commit 0326269ed73529cdf821664b6176814cde9ca374 ]
The counter is masked to counter_width, so the subtraction in __cxl_pmu_read() throws away the bit that records the wrap. A delta of one whole period reads back as 0, the same as no events at all, and only the overflow status tells the two apart - which is why __cxl_pmu_read() takes an overflow argument.
The fixup keys off the delta rather than the operands:
delta = (new_cnt - prev_cnt) & GENMASK_ULL(counter_width - 1, 0); if (overflow && delta < GENMASK_ULL(counter_width - 1, 0)) delta += (1UL << counter_width);
so it cannot tell which of these it is looking at:
event_start polled read wrap ctr = 0 .......... ctr = P/2 ......... mask -> 0 (+r) prev = 0 prev = P/2 IRQ reads new = r
prev = 0 (no read yet): new >= prev, fell short -> add period prev = P/2 (polled): new < prev, spans wrap -> add nothing
Both rows are the same interrupt and the old guard adds a period in both, so a mid-period read makes the event over-count. 'perf stat -I' hits that.
Condition the fixup on new_cnt >= prev_cnt, the one case the subtraction cannot express. Dropping it outright would break the first row. It stays exact whatever the residual r is, which matters because some events increment by more than 1 per cycle (CXL r4.0 8.2.7.2.1, Threshold) and can step past 0 as they wrap.
Use mask + 1 for the period rather than a shift. It is 0 for a 64-bit counter, and avoids the old 1UL << counter_width - undefined for width 64, and for >= 32 on 32-bit kernels.
--- drivers/perf/cxl_pmu.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/perf/cxl_pmu.c +10 -6
@@ -689,7 +689,7 @@ static void __cxl_pmu_read(struct perf_event *event, bool overflow) {struct cxl_pmu_info *info =pmu_to_cxl_pmu_info (event->pmu);struct hw_perf_event *hwc = &event->hw; -u64 new_cnt, prev_cnt, delta; +u64 new_cnt, prev_cnt, delta, mask; do { prev_cnt = local64_read(&hwc->prev_count);
@@ -697,12 +697,16 @@ static void __cxl_pmu_read(struct perf_event *event, bool overflow) }while (local64_cmpxchg (&hwc->prev_count, prev_cnt, new_cnt) != prev_cnt);/* -* If we know an overflow occur then take that into account. -* Note counter is not reset as that would lose events +* The mask discards the bit that says the counter wrapped, so a delta of +* one whole period reads back as 0 - the same as no events at all. Only +* the overflow status separates them, and new_cnt >= prev_cnt is that +* case, so add the period back. mask + 1 is 2^counter_width, which comes +* out as 0 for a 64-bit counter and avoids an undefined 1 << 64. */ - delta = (new_cnt - prev_cnt) &GENMASK_ULL (info->counter_width -1 ,0 ); -if (overflow && delta <GENMASK_ULL (info->counter_width -1 ,0 )) - delta += (1UL << info->counter_width); + mask =GENMASK_ULL (info->counter_width -1 ,0 ); + delta = (new_cnt - prev_cnt) & mask; +if (overflow && new_cnt >= prev_cnt) + delta += mask +1 ;local64_add (delta, &event->count); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1041/2151 perf/cxl: Accept an overflow interrupt on MSI message number 0
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dave Jiang <[email protected]>
[ Upstream commit af06fba45746058ba8f983a0ac2f457a3404edba ]
cxl_pmu_probe() rejects the PMU when info->irq <= 0, but at that point the field still holds the MSI/MSI-X message number the device signals overflow on, not a Linux virq. That number is 0-based, and -1 means no interrupt support. Message number 0 is valid and pci_irq_vector() takes a 0-based index, so a compliant device signalling on the first vector fails to probe.
Reject only the no-interrupt case, matching how the CXL mailbox and event interrupts handle it.
--- drivers/perf/cxl_pmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/perf/cxl_pmu.c +1 -1
@@ -873,7 +873,7 @@ static int cxl_pmu_probe(struct device *dev) .capabilities = PERF_PMU_CAP_NO_EXCLUDE, }; -if (info->irq <=0 ) +if (info->irq <0 )return -EINVAL ; rc =pci_irq_vector (pdev, info->irq);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1042/2151 perf/cxl: Dont share the overflow interrupt, and keep it pinned
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dave Jiang <[email protected]>
[ Upstream commit b899fd3487b0d4066d60ebcf5b73e77c9617de54 ]
The PMU pins its overflow interrupt to info->on_cpu in the hotplug callbacks, but requests it with only IRQF_SHARED | IRQF_NO_THREAD. Without IRQF_NOBALANCING, irqbalance or a userspace smp_affinity write can move it elsewhere, and cxl_pmu_irq() then runs local64_cmpxchg() and local64_add() on hwc->prev_count and event->count at the same time as the managing CPU. local64_t is only atomic against same-CPU access, so the counts corrupt.
The flag alone does not fix that while the line is shared. __setup_irq() only acts on it for the first action on a line, and a co-owner has no reason to want our affinity - it would keep taking the interrupt wherever its own points, running our handler on the wrong CPU.
Drop IRQF_SHARED and add IRQF_NOBALANCING. The spec only recommends a distinct Interrupt Message Number per CPMU instance (CXL r4.0 8.2.7.1.1), so a device may put several on one vector, or share with the mailbox or event log. Such a device now loses a PMU rather than silently miscounting - and only the PMU, since the preceding patch adds the CPMUs after the event configuration.
--- drivers/perf/cxl_pmu.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/perf/cxl_pmu.c +9 -2
@@ -782,7 +782,7 @@ static irqreturn_t cxl_pmu_irq(int irq, void *data) overflowed =readq (base +CXL_PMU_OVERFLOW_REG ); -/* Interrupt may be shared, so maybe it isn't ours */ +/* Nothing overflowed, so the device did not raise this */ if (!overflowed)return IRQ_NONE ;
@@ -885,7 +885,14 @@ static int cxl_pmu_probe(struct device *dev)if (!irq_name)return -ENOMEM ; - rc =devm_request_irq (dev, irq, cxl_pmu_irq,IRQF_SHARED |IRQF_NO_THREAD , +/* +* The handler must run on info->on_cpu, so the interrupt cannot be +* shared - IRQF_NOBALANCING is only honoured for the first action on a +* line, and a co-owner would keep taking the interrupt wherever its own +* affinity points. +*/ + rc =devm_request_irq (dev, irq, cxl_pmu_irq, +IRQF_NO_THREAD |IRQF_NOBALANCING , irq_name, info);if (rc)return rc;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1043/2151 perf/cxl: Unfreeze counters after handling an overflow interrupt
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dave Jiang <[email protected]>
[ Upstream commit 2e4fe234c72d65a09bbfd421240a0cfd7c8046a2 ]
The counters run with Freeze on Overflow set, so one overflow freezes every counter in the block (CXL r4.0 8.2.7.2.1), and a frozen counter "remains frozen until explicitly unfrozen by software" (8.2.7.1.3, Table 8-183). cxl_pmu_irq() reads the overflowed counters and clears the overflow status but never unfreezes, so everything stays frozen until the next pmu_enable() and events in that window are lost.
Unfreeze after clearing the status, unless the PMU has been disabled in the meantime - cxl_pmu_disable() freezes the block deliberately. Track the enabled state and leave it frozen in that case.
--- drivers/perf/cxl_pmu.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
drivers/perf/cxl_pmu.c +19 -0
@@ -107,6 +107,8 @@ struct cxl_pmu_info {struct hlist_node node;bool filter_hdm;int irq; +/* Set between pmu_enable() and pmu_disable(), read by the IRQ handler */ +bool enabled; };#define pmu_to_cxl_pmu_info (_pmu) container_of(_pmu, struct cxl_pmu_info, pmu)
@@ -595,6 +597,7 @@ static void cxl_pmu_enable(struct pmu *pmu)void __iomem *base = info->base;/* Can assume frozen at this stage */ +WRITE_ONCE (info->enabled, true);writeq (0 , base +CXL_PMU_FREEZE_REG ); }
@@ -603,6 +606,7 @@ static void cxl_pmu_disable(struct pmu *pmu)struct cxl_pmu_info *info =pmu_to_cxl_pmu_info (pmu);void __iomem *base = info->base; +WRITE_ONCE (info->enabled, false);/* * Whilst bits above number of counters are RsvdZ * they are unlikely to be repurposed given
@@ -801,6 +805,21 @@ static irqreturn_t cxl_pmu_irq(int irq, void *data)writeq (overflowed, base +CXL_PMU_OVERFLOW_REG ); +/* +* An overflow freezes every counter in the CPMU, so unfreeze once the +* overflowed ones have been read and their status cleared. Otherwise +* they stay frozen until the next pmu_enable() and events are lost. +* +* Not while the PMU is disabled, so as not to undo an intentional freeze. +* The check is advisory, not exclusive: pmu_disable() normally runs on +* info->on_cpu with interrupts off, where the pinned handler cannot +* preempt it. In the one window where it does not - the migration in +* cxl_pmu_offline_cpu() - the counters are legitimately running again, +* so unfreezing is correct there anyway. +*/ +if (READ_ONCE (info->enabled)) +writeq (0 , base +CXL_PMU_FREEZE_REG ); +return IRQ_HANDLED ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1044/2151 perf/cxl: Validate the hardware-reported counter width
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dave Jiang <[email protected]>
[ Upstream commit 1c5499e67303a9393388197fb14b39ed06a3dc55 ]
cxl_pmu_parse_caps() takes the Counter Width straight from the CPMU Capability register without a bounds check. The Counter Data register is 64 bits wide, so a device reporting 0 or more than 64 is reporting nonsense, and GENMASK_ULL(width - 1, 0) in the read path then shifts out of range. That is undefined behaviour, and a UBSAN splat where it is enabled.
Reject a counter width outside 1..64 at probe.
--- drivers/perf/cxl_pmu.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/perf/cxl_pmu.c +9 -0
@@ -141,6 +141,15 @@ static int cxl_pmu_parse_caps(struct device *dev, struct cxl_pmu_info *info) info->num_counters =FIELD_GET (CXL_PMU_CAP_NUM_COUNTERS_MSK , val) +1 ; info->counter_width =FIELD_GET (CXL_PMU_CAP_COUNTER_WIDTH_MSK , val); +/* +* The Counter Data register is 64 bits wide, so a Counter Width of 0 or +* >64 is invalid. Reject it rather than let GENMASK_ULL(width - 1, 0) in +* the read path shift out of range. +*/ +if (info->counter_width ==0 || info->counter_width >64 ) { +dev_err (dev,"Invalid counter width %d\n" , info->counter_width); +return -ENODEV ; + } info->num_event_capabilities =FIELD_GET (CXL_PMU_CAP_NUM_EVN_CAP_REG_SUP_MSK , val) +1 ; info->filter_hdm =FIELD_GET (CXL_PMU_CAP_FILTERS_SUP_MSK , val) &CXL_PMU_FILTER_HDM ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1045/2151 perf/cxl: Dont log through pmu.dev in the overflow interrupt handler
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dave Jiang <[email protected]>
[ Upstream commit 984920c893f0e6832351bc03deeb5ef9a42fbdbb ]
perf_pmu_unregister() frees pmu->dev without clearing the pointer, and cxl_pmu_probe() orders its devm actions so that teardown runs it before free_irq(). Nothing in between masks the interrupt, and cxl_pmu_event_stop() leaves the overflow status bit set, so an overflow taken just before teardown is still delivered and still reaches the dev_dbg() in the !event branch - by which point info->pmu.dev is freed.
Log through info->pmu.parent instead, which is devm-managed and outlives every teardown action.
--- drivers/perf/cxl_pmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/perf/cxl_pmu.c +1 -1
@@ -804,7 +804,7 @@ static irqreturn_t cxl_pmu_irq(int irq, void *data)struct perf_event *event = info->hw_events[i];if (!event) { -dev_dbg (info->pmu.dev, +dev_dbg (info->pmu.parent,"overflow but on non enabled counter %d\n" , i);continue ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1046/2151 perf/cxl: Clear stale overflow status before using a counter
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dave Jiang <[email protected]>
[ Upstream commit 05d82cf377f706d0b566b572bc66e3a2057bd68e ]
cxl_pmu_event_stop() leaves the counter's bit set in the overflow status register and only cxl_pmu_irq() ever clears it, so a counter handed from one event to the next starts with the previous owner's overflow pending. The perf core stops and starts back to back with interrupts off, so an interrupt latched over the handover lands on the new event. prev_count is 0 by then, so the read path adds a full period: 2^counter_width phantom counts.
Clear the bit in cxl_pmu_event_start(), before the config write arms Interrupt on Overflow. Clear the whole register at probe too, for counters no event ever owns - the driver never touched it, so firmware or a previous kernel can leave a bit set there.
--- drivers/perf/cxl_pmu.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/perf/cxl_pmu.c +17 -0
@@ -682,6 +682,15 @@ static void cxl_pmu_event_start(struct perf_event *event, int flags)*/ cfg |=FIELD_PREP (CXL_PMU_COUNTER_CFG_THRESHOLD_MSK ,cxl_pmu_config1_get_threshold (event)); + +/* +* Drop any overflow the previous owner of this counter left pending; +* cxl_pmu_event_stop() does not. Otherwise an interrupt latched over +* the handover gets charged to this event. Do it before arming Interrupt +* on Overflow below, and note RW1C leaves the other counters alone. +*/ +writeq (BIT_ULL (hwc->idx), base +CXL_PMU_OVERFLOW_REG ); +writeq (cfg, base +CXL_PMU_COUNTER_CFG_REG (hwc->idx));local64_set (&hwc->prev_count,0 );
@@ -913,6 +922,14 @@ static int cxl_pmu_probe(struct device *dev)if (!irq_name)return -ENOMEM ; +/* +* Same for counters no event owns yet: clear whatever firmware or a +* previous kernel left set before the handler goes live. Bits above the +* implemented counters are reserved, so only write those. +*/ +writeq (GENMASK_ULL (info->num_counters -1 ,0 ), + info->base +CXL_PMU_OVERFLOW_REG ); +/* * The handler must run on info->on_cpu, so the interrupt cannot be * shared - IRQF_NOBALANCING is only honoured for the first action on a
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1047/2151 perf/dwc_pcie: Fix PCI device reference leak in probe
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ruoyu Wang <[email protected]>
[ Upstream commit 3a4067658363e34bf4e1d7039e5b52951fcb4012 ]
pci_get_domain_bus_and_slot() returns a referenced PCI device. When the subsequent RAS DES capability lookup fails, dwc_pcie_pmu_probe() returns -ENODEV without releasing that reference. Repeated failed probes can therefore keep the PCI device allocated after removal.
Declare the looked-up device with __free(pci_dev_put), so the temporary reference is released on every return path. Keeping the reference scoped to the whole probe also covers all later uses of the device during initialization.
This issue was found by a static analysis checker and confirmed by manual source review.
--- drivers/perf/dwc_pcie_pmu.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/perf/dwc_pcie_pmu.c +5 -6
@@ -694,16 +694,16 @@ static struct notifier_block dwc_pcie_pmu_nb = {static int dwc_pcie_pmu_probe (struct platform_device *plat_dev) { -struct pci_dev *pdev; +u32 sbdf = plat_dev->id; + struct pci_dev *pdev __free(pci_dev_put) = +pci_get_domain_bus_and_slot (sbdf >>16 , +PCI_BUS_NUM (sbdf &0xffff ), + sbdf &0xff );struct dwc_pcie_pmu *pcie_pmu;char *name; -u32 sbdf;u16 vsec;int ret; - sbdf = plat_dev->id; - pdev =pci_get_domain_bus_and_slot (sbdf >>16 ,PCI_BUS_NUM (sbdf &0xffff ), - sbdf &0xff );if (!pdev) {pr_err ("No pdev found for the sbdf 0x%x\n" , sbdf);return -ENODEV ;
@@ -713,7 +713,6 @@ static int dwc_pcie_pmu_probe(struct platform_device *plat_dev)if (!vsec)return -ENODEV ; -pci_dev_put (pdev); name =devm_kasprintf (&plat_dev->dev,GFP_KERNEL ,"dwc_rootport_%x" , sbdf);if (!name)return -ENOMEM ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1048/2151 spi: fsl: switch to managed controller allocation
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit 6afe041c2ce9068b2b6c64eddb5537911752050c ]
Switch to device managed controller allocation to simplify error handling and to avoid having to take another reference during deregistration.
Stable-dep-of: af1d882d421d ("spi: fsl: unmap immr_spi_cs on remove")
--- drivers/spi/spi-fsl-spi.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)
drivers/spi/spi-fsl-spi.c +2 -12
@@ -535,7 +535,7 @@ static struct spi_controller *fsl_spi_probe(struct device *dev,u32 regval;int ret =0 ; - host =spi_alloc_host (dev,sizeof (struct mpc8xxx_spi )); + host =devm_spi_alloc_host (dev,sizeof (struct mpc8xxx_spi ));if (host ==NULL ) { ret = -ENOMEM ; goto err;
@@ -559,7 +559,7 @@ static struct spi_controller *fsl_spi_probe(struct device *dev, ret =fsl_spi_cpm_init (mpc8xxx_spi);if (ret) - goto err_cpm_init; + goto err; mpc8xxx_spi->reg_base =devm_ioremap_resource (dev, mem);if (IS_ERR (mpc8xxx_spi->reg_base)) {
@@ -625,8 +625,6 @@ static struct spi_controller *fsl_spi_probe(struct device *dev, err_probe:fsl_spi_cpm_free (mpc8xxx_spi); -err_cpm_init: -spi_controller_put (host); err:return ERR_PTR (ret); }
@@ -705,13 +703,9 @@ static void of_fsl_spi_remove(struct platform_device *ofdev)struct spi_controller *host =platform_get_drvdata (ofdev);struct mpc8xxx_spi *mpc8xxx_spi =spi_controller_get_devdata (host); -spi_controller_get (host); -spi_unregister_controller (host);fsl_spi_cpm_free (mpc8xxx_spi); - -spi_controller_put (host); }static struct platform_driver of_fsl_spi_driver = {
@@ -757,13 +751,9 @@ static void plat_mpc8xxx_spi_remove(struct platform_device *pdev)struct spi_controller *host =platform_get_drvdata (pdev);struct mpc8xxx_spi *mpc8xxx_spi =spi_controller_get_devdata (host); -spi_controller_get (host); -spi_unregister_controller (host);fsl_spi_cpm_free (mpc8xxx_spi); - -spi_controller_put (host); }MODULE_ALIAS ("platform:mpc8xxx_spi" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1049/2151 spi: fsl: unmap immr_spi_cs on remove
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
[ Upstream commit af1d882d421de504a1e5fac92eb06947b6cbdd8f ]
of_fsl_spi_remove() does not unmap pinfo->immr_spi_cs after a successful probe when CONFIG_FSL_SOC is enabled and fsl,spisel_boot causes of_fsl_spi_probe() to map it with ioremap(). The probe error path already performs the matching iounmap().
Retrieve pinfo from the platform data and call iounmap() when pinfo->immr_spi_cs is present, pairing normal removal with the mapping established by of_fsl_spi_probe().
--- drivers/spi/spi-fsl-spi.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/spi/spi-fsl-spi.c +8 -0
@@ -702,10 +702,18 @@ static void of_fsl_spi_remove(struct platform_device *ofdev) {struct spi_controller *host =platform_get_drvdata (ofdev);struct mpc8xxx_spi *mpc8xxx_spi =spi_controller_get_devdata (host); +#if IS_ENABLED (CONFIG_FSL_SOC ) +struct fsl_spi_platform_data *pdata =dev_get_platdata (&ofdev->dev); +struct mpc8xxx_spi_probe_info *pinfo =to_of_pinfo (pdata); +#endif spi_unregister_controller (host);fsl_spi_cpm_free (mpc8xxx_spi); +#if IS_ENABLED (CONFIG_FSL_SOC ) +if (pinfo->immr_spi_cs) +iounmap (pinfo->immr_spi_cs); +#endif }static struct platform_driver of_fsl_spi_driver = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1050/2151 spi: bcm63xx-hsspi: Disable runtime PM on remove
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
[ Upstream commit 38232bd3cea74845c2064eb9f7eac77fa5a21d85 ]
bcm63xx_hsspi_probe() enables runtime PM before creating the sysfs
group, but bcm63xx_hsspi_remove() does not perform the matchingpm_runtime_disable() after a successful probe.
The probe error paths already disable runtime PM when sysfs group creation or controller registration fails.
Add pm_runtime_disable() to the remove path after removing the sysfs group to balance pm_runtime_enable() from bcm63xx_hsspi_probe().
--- drivers/spi/spi-bcm63xx-hsspi.c | 1 + 1 file changed, 1 insertion(+)
drivers/spi/spi-bcm63xx-hsspi.c +1 -0
@@ -888,6 +888,7 @@ static void bcm63xx_hsspi_remove(struct platform_device *pdev)clk_disable_unprepare (bs->pll_clk);clk_disable_unprepare (bs->clk);sysfs_remove_group (&pdev->dev.kobj, &bcm63xx_hsspi_group); +pm_runtime_disable (&pdev->dev); }#ifdef CONFIG_PM_SLEEP
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1051/2151 selftests/alsa: Do not take another controls event as our own
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: HyeongJun An <[email protected]>
[ Upstream commit c9b0768669976a1beb0a1537b4257bd6b76dfbac ]
The wait_for_event() skips an event for a different control with a continue inside its do-while loop. But continue goes straight to the loop condition, and that tests the mask of the event just skipped. So a value event for another control ends the wait as if it were ours.
A driver that notifies a second control from its put() queues that event first. The core only sends ours once put() returns. So the wait returns early and leaves ours in the queue. The next test then reports it as spurious. And event_missing passes for a control whose put() said nothing changed, as long as it notified a neighbour.
To fix this, clear the mask before skipping the event.
--- tools/testing/selftests/alsa/mixer-test.c | 2 ++ 1 file changed, 2 insertions(+)
tools/testing/selftests/alsa/mixer-test.c +2 -0
@@ -261,6 +261,8 @@ static int wait_for_event(struct ctl_data *ctl, int timeout)if (ev_id !=snd_ctl_elem_info_get_numid (ctl->info)) {ksft_print_msg ("Event for unexpected ctl %s\n" ,snd_ctl_event_elem_get_name (event)); +/* The loop condition must not see the other control's mask */ + mask =0 ;continue ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1052/2151 power: supply: ab8500_btemp: Fix event temperature reporting
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Walleij <[email protected]>
[ Upstream commit 95990cda8e42dda4bd3f1475d578323981bd8579 ]
The event-aware path initializes its local temperature to zero and compares that zero against the thermal thresholds. Consequently some events report the measured temperature after it crosses the event threshold, while others always report the threshold.
Start with the measured temperature, clamp it according to the active event, and convert to tenths of a degree only once. This path is used by AB8505 and later variants.
--- drivers/power/supply/ab8500_btemp.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-)
drivers/power/supply/ab8500_btemp.c +9 -19
@@ -468,39 +468,29 @@ static void ab8500_btemp_periodic(struct ab8500_btemp *di,*/ static int ab8500_btemp_get_temp (struct ab8500_btemp *di) { -int temp =0 ; +int temp = di->bat_temp;/* * The BTEMP events are not reliabe on AB8500 cut3.3 * and prior versions */ -if (is_ab8500_3p3_or_earlier (di->parent)) { - temp = di->bat_temp *10 ; - }else { +if (!is_ab8500_3p3_or_earlier (di->parent)) {if (di->events.btemp_low) {if (temp > di->btemp_ranges.btemp_low_limit) - temp = di->btemp_ranges.btemp_low_limit *10 ; -else - temp = di->bat_temp *10 ; + temp = di->btemp_ranges.btemp_low_limit; }else if (di->events.btemp_high) {if (temp < di->btemp_ranges.btemp_high_limit) - temp = di->btemp_ranges.btemp_high_limit *10 ; -else - temp = di->bat_temp *10 ; + temp = di->btemp_ranges.btemp_high_limit; }else if (di->events.btemp_lowmed) {if (temp > di->btemp_ranges.btemp_med_limit) - temp = di->btemp_ranges.btemp_med_limit *10 ; -else - temp = di->bat_temp *10 ; + temp = di->btemp_ranges.btemp_med_limit; }else if (di->events.btemp_medhigh) {if (temp < di->btemp_ranges.btemp_med_limit) - temp = di->btemp_ranges.btemp_med_limit *10 ; -else - temp = di->bat_temp *10 ; - }else - temp = di->bat_temp *10 ; + temp = di->btemp_ranges.btemp_med_limit; + } } -return temp; + +return temp *10 ; }/**
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1053/2151 power: supply: ab8500: Preserve battery termination current
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Walleij <[email protected]>
[ Upstream commit 3b33eda4067494658d51db0792377fef98787e3f ]
The battery-info parser uses a negative value for an unspecified termination current. Testing the value as a boolean instead replaces every valid positive current from the battery description with 200 mA.
Apply the default only when the property is unspecified so batteries retain their described charging termination current.
--- drivers/power/supply/ab8500_bmdata.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/supply/ab8500_bmdata.c +1 -1
@@ -174,7 +174,7 @@ int ab8500_bm_of_probe(struct power_supply *psy,if (bi->constant_charge_voltage_max_uv <0 ) bi->constant_charge_voltage_max_uv =4100000 ; -if (bi->charge_term_current_ua) +if (bi->charge_term_current_ua <0 )/* Charging stops when we drop below this current */ bi->charge_term_current_ua =200000 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1054/2151 power: supply: ab8500_charger: Fix AC charger re-enable
In reply to Greg Kroah-Hartman6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Walleij <[email protected]>
[ Upstream commit 3e1d2517347f6bb72f74e63ec77d1634385fbf21 ]
The AC check-enable callback passes the embedded USB charger object to ab8500_charger_ac_en(). That helper derives the parent with the AC charger offset, so the wrong object yields an invalid ab8500_charger pointer.
Pass the AC charger object when re-enabling AC charging.
--- drivers/power/supply/ab8500_charger.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/power/supply/ab8500_charger.c +2 -2
@@ -1778,7 +1778,7 @@ static int ab8500_charger_usb_check_enable(struct ux500_charger *charger, }/** -* ab8500_charger_ac_check_enable() - enable usb charging +* ab8500_charger_ac_check_enable() - enable AC charging * @charger: pointer to the ux500_charger structure * @vset_uv: charging voltage in microvolt * @iset_ua: charger output current in micrompere
@@ -1817,7 +1817,7 @@ static int ab8500_charger_ac_check_enable(struct ux500_charger *charger,return ret; } - ret =ab8500_charger_ac_en (&di->usb_chg, true, vset_uv, iset_ua); + ret =ab8500_charger_ac_en (&di->ac_chg, true, vset_uv, iset_ua);if (ret <0 ) {dev_err (di->dev,"failed to enable AC charger %d\n" , __LINE__);
Signature · 1 line
2.53.0