6.12.120-rc1 review
Subsystems (3)
Greg Kroah-Hartman
maintainerPATCH 358/816 tracing: skip boot kprobe setup when no events were requested
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wenwen Fu <[email protected]>
[ Upstream commit 2388a673e9276de30c7e917fce50830e497d46cc ]
setup_boot_kprobe_events() calls enable_boot_kprobe_events() even when the kprobe_event= boot parameter was not supplied. That call takes event_mutex without any command-line probes to enable.
Asynchronous eval-map updates also hold event_mutex. A normal boot can therefore wait in init_kprobe_trace() for this background work despite having no boot probes to set up.
Return early when the boot-event buffer is empty. Keep the mutex protection in trace_event_update_all() and retain setup for explicit kprobe_event= parameters. Bootconfig handles its own probe enablement, and the existing trace_eval_sync() still waits for background work before init memory is freed.
--- kernel/trace/trace_kprobe.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/trace/trace_kprobe.c +3 -0
@@ -1985,6 +1985,9 @@ static __init void setup_boot_kprobe_events(void)char *p, *cmd = kprobe_boot_events_buf;int ret; +if (!kprobe_boot_events_buf[0 ]) +return ; +strreplace (kprobe_boot_events_buf,',' ,' ' );while (cmd && *cmd !='\0' ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 359/816 docs, kprobes: Fix bracket
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Manuel Ebner <[email protected]>
[ Upstream commit b91a5c16996d089cd07ceaf33b5a621cb94c2c2f ]
Remove needless ')'
--- Documentation/trace/kprobes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/trace/kprobes.rst +1 -1
@@ -31,7 +31,7 @@ can trap at almost any kernel code address [1]_, specifying a handler routine to be invoked when the breakpoint is hit. .. [1] some parts of the kernel code can not be trapped, see - :ref:`kprobes_blacklist`) + :ref:`kprobes_blacklist` There are currently two types of probes: kprobes, and kretprobes (also called return probes). A kprobe can be inserted on virtually
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 360/816 KEYS: do not let an unmatched key decide the search result
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guixiong Wei <[email protected]>
[ Upstream commit 143fe160178c73e43575bff4890d23f84e37146d ]
With the dns_resolver key type available, put a key named "foo" in a fresh session keyring, revoke it, and search for "bar":
keyctl new_session >/dev/null A=$(printf '127.0.0.1\0' | keyctl padd dns_resolver foo @s) keyctl revoke "$A" keyctl search @s dns_resolver bar
Results:
keyctl_search: Key has been revoked
The search returns -EKEYREVOKED even though there is no key named "bar". It should return -ENOKEY.
A dns_resolver search walks the keys in the keyring and uses dns_resolver_cmp() to compare their descriptions with the requested name. When keyring_search_iterator() sees the revoked "foo" key, it records -EKEYREVOKED in ctx->result and skips the key before comparing its description. The search continues, but without a match it returns the error recorded for "foo".
Call the match callback before checking for invalidated, revoked or expired keys. A nonmatching key then leaves ctx->result alone.
--- security/keys/keyring.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
security/keys/keyring.c +6 -6
@@ -598,6 +598,12 @@ static int keyring_search_iterator(const void *object, void *iterator_data)return 0 ; } +/* A key the caller did not ask for must not decide the result. */ +if (!ctx->match_data.cmp (key, &ctx->match_data)) { +kleave (" = 0 [!match]" ); +return 0 ; + } +/* skip invalidated, revoked and expired keys */ if (ctx->flags &KEYRING_SEARCH_DO_STATE_CHECK ) {time64_t expiry =READ_ONCE (key->expiry);
@@ -617,12 +623,6 @@ static int keyring_search_iterator(const void *object, void *iterator_data) } } -/* keys that don't match */ -if (!ctx->match_data.cmp (key, &ctx->match_data)) { -kleave (" = 0 [!match]" ); -return 0 ; - } -/* key must have search permissions */ if (!(ctx->flags &KEYRING_SEARCH_NO_CHECK_PERM ) && key_task_permission(make_key_ref(key, ctx->possessed),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 361/816 ALSA: aw2-alsa: select SND_PCM
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jude Gyimah <[email protected]>
[ Upstream commit bca568589ad118a9b0bac086760baee2a41976a5 ]
Several stanzas in sound/pci/Kconfig select SND_PCM. SND_AW2 selects nothing at all.
aw2-alsa calls snd_pcm_new, which sound/core/pcm.c provides under SND_PCM.
aw2-alsa.c:(.text+0x554): undefined reference to `snd_pcm_new'
4 symbols are undefined in all.
The driver can be built into vmlinux while SND_PCM is a module, in which case the symbols are not there at link time.
Select rather than depend on: SND_PCM has no prompt of its own and is only ever enabled by a select, so a depends on would leave SND_AW2 unselectable.
Reproduced on v7.3, arm64, with CONFIG_SND_AW2=y and CONFIG_SND_PCM=m.
Found with kreach, a static check that compares what Kconfig allows against the symbols the compiled objects actually reference.
--- sound/pci/Kconfig | 1 + 1 file changed, 1 insertion(+)
sound/pci/Kconfig +1 -0
@@ -141,6 +141,7 @@ config SND_AU8830 config SND_AW2 tristate "Emagic Audiowerk 2" + select SND_PCM help Say Y here to include support for Emagic Audiowerk 2 soundcards.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 362/816 Xen/gnttab: improve error handling in gnttab_dma_{alloc,free}_pages()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jan Beulich <[email protected]>
[ Upstream commit 2b66f2cc753243a6adb3e9a5c038b0fc59ba7ec9 ]
Both decrease-reservation and populate-physmap can succeed partially. For the former this may be pretty unlikely, but clearly the latter can hit both out-of-memory conditions in the hypervisor or denial because of the allocation exceeding the domain's allowance (there's no interaction with the balloon driver here either).
In gnttab_dma_free_pages() we simply can't give back to the system what hasn't been re-filled with backing memory. For gnttab_dma_alloc_pages() both parts of the overall region need dealing with differently.
While no present caller of gnttab_dma_free_pages() checks its return value, also don't use -EFAULT there: It really is an out-of-memory condition. (In gnttab_dma_alloc_pages() -EFAULT doesn't look quite right either, but I couldn't think of a clearly better error code there.)
Message-ID: <[email protected]>
--- drivers/xen/grant-table.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)
drivers/xen/grant-table.c +24 -1
@@ -1096,6 +1096,24 @@ int gnttab_dma_alloc_pages(struct gnttab_dma_alloc_args *args) ret =xenmem_reservation_decrease (args->nr_pages, args->frames);if (ret != args->nr_pages) {pr_debug ("Failed to decrease reservation for DMA buffer\n" ); +if (ret >=0 ) { +/* Free the part where decrease didn't work. */ +size_t done = ret <<PAGE_SHIFT ; + +if (args->coherent) +dma_free_coherent (args->dev, size - done, + args->vaddr + done, + args->dev_bus_addr + done); +else +dma_free_wc (args->dev, size - done, + args->vaddr + done, + args->dev_bus_addr + done); + +if (!ret)/* Nothing else to do? */ +return -EFAULT ; + + args->nr_pages = ret; + } ret = -EFAULT ; goto fail; }
@@ -1129,7 +1147,12 @@ int gnttab_dma_free_pages(struct gnttab_dma_alloc_args *args) ret =xenmem_reservation_increase (args->nr_pages, args->frames);if (ret != args->nr_pages) {pr_debug ("Failed to increase reservation for DMA buffer\n" ); - ret = -EFAULT ; +/* Can only free what has been re-filled. */ +if (!ret) +return -ENOMEM ; +if (ret >0 ) + args->nr_pages = ret; + ret = -ENOMEM ; }else { ret =0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 363/816 coredump: prevent TIF_NOTIFY_SIGNAL from interrupting coredumps
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit a58d647acfdc62561f3570d114025b3bf38ae41b ]
TIF_NOTIFY_SIGNAL is used to kick a task in uninterruptible sleep to return to userspace and run task work and then go back to sleep. This mechanism works well but breaks coredumps. dump_interrupted() only allows fatal signals to interrupt a coredump and the whole regular write path going to actual filesystems is impervious to TIF_NOTIFY_SIGNAL as well.
However, both the usermodehelper pipe and the coredump socket will bail early on TIF_NOTIFY_SIGNAL. This affects the following codepaths:
- coredump_sock_recv() -> unix_stream_read_generic()
The request/ack handshake is abandoned before any coredump data is sent.
- anon_pipe_write() returning -ERESTARTSYS Once the pipe is full this truncates the coredump.
- unix_stream_sendmsg() returning -ERESTARTSYS Once the send buffer is full this truncates the coredump.
- coredump_sock_wait() -> __kernel_read()
This reports a failure that didn't happen.
- wait_for_dump_helpers() -> wait_event_interruptible() This stops waiting for the coredump helpers.
Such truncation is entirely invisible to userspace and all uapi bits still indicate that a successful coredump happened. A crashing process with a bunch of file backed mappings and io_uring thrown in loses most of the coredump data. If the NT_FILE note goes past PAGE_SIZE mappings it's gonzo.
TIF_NOTIFY_SIGNAL is sent by io_uring for the common case. And it uses poll without sleeping so a completion callback runs task_work_add() from interrupt context against the task that submitted the request. This is the task that is running the coredump. Since that task hasn't set work_exited (it hasn't exited yet after all) TIF_NOTIFY_SIGNAL keeps reappearing.
A coredumping task doesn't return to userspace. The task work is run at exit. So interrupting it doesn't buy anything and just loses the coredump which is quite valuable.
Note that this isn't specific to io_uring. There's also klp_send_signals(), bpf_task_work_schedule_signal(), landlock's tsync and then technically, kthread_stop() and the printk kunit test set the bit raw.
--- fs/coredump.c | 5 +++++ 1 file changed, 5 insertions(+)
fs/coredump.c +5 -0
@@ -582,6 +582,7 @@ void do_coredump(const kernel_siginfo_t *siginfo)struct linux_binfmt * binfmt;const struct cred *old_cred;struct cred *cred; +unsigned int notify_flags;int retval =0 ;int ispipe;size_t *argv =NULL ;
@@ -630,6 +631,9 @@ void do_coredump(const kernel_siginfo_t *siginfo)if (retval <0 ) goto fail_creds; +/* Task work must not cut the dump short, see signal_pending(). */ + notify_flags =no_notify_signal_save (); + old_cred =override_creds (cred); ispipe =format_corename (&cn, &cprm, &argv, &argc);
@@ -836,6 +840,7 @@ void do_coredump(const kernel_siginfo_t *siginfo)kfree (cn.corename);coredump_finish (core_dumped);revert_creds (old_cred); +no_notify_signal_restore (notify_flags); fail_creds:put_cred (cred); fail:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 364/816 s390/zcrypt: Make apfs a real unsigned int field
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Harald Freudenberger <[email protected]>
[ Upstream commit ecd2fd113e89978ca750a81dea033a2e9f3347df ]
Slight rework on the apfs field: Instead of unsigned char[4] make this a real 32 bit unsigned int field. With that done, some assignments and some printouts can be simplified. With that comes a slight move of the anonymous struct covering the message type 86 header to dedupe some code lines.
Stable-dep-of: 5e9b339f3232 ("s390/zcrypt: Fix and improve zcrypt reply message verification checks")
--- drivers/s390/crypto/zcrypt_error.h | 28 ++++++++++----------------- drivers/s390/crypto/zcrypt_msgtype6.c | 2 +- drivers/s390/crypto/zcrypt_msgtype6.h | 4 ++-- 3 files changed, 13 insertions(+), 21 deletions(-)
drivers/s390/crypto/zcrypt_error.h +10 -18
@@ -78,9 +78,13 @@ struct error_hdr {static inline int convert_error (struct zcrypt_queue *zq,struct ap_message *reply) { -struct error_hdr *ehdr = reply->msg; -int card =AP_QID_CARD (zq->queue->qid);int queue =AP_QID_QUEUE (zq->queue->qid); +int card =AP_QID_CARD (zq->queue->qid); +struct error_hdr *ehdr = reply->msg; +struct { +struct type86_hdr hdr; +struct type86_fmt2_ext fmt2; + } __packed * t86hdr = reply->msg;switch (ehdr->reply_code) {case REP82_ERROR_INVALID_MSG_LEN :/* 0x23 */
@@ -100,19 +104,12 @@ static inline int convert_error(struct zcrypt_queue *zq,/* RY indicates malformed request */ if (ehdr->reply_code ==REP82_ERROR_FILTERED_BY_HYPERVISOR && ehdr->type ==TYPE86_RSP_CODE ) { -struct { -struct type86_hdr hdr; -struct type86_fmt2_ext fmt2; - } __packed * head = reply->msg; -unsigned int apfs = *((u32 *)head->fmt2.apfs); -ZCRYPT_DBF_WARN ("%s dev=%02x.%04x RY=0x%02x apfs=0x%x => rc=EINVAL\n" , __func__, card, queue, - ehdr->reply_code, apfs); + ehdr->reply_code, t86hdr->fmt2.apfs); }else {ZCRYPT_DBF_WARN ("%s dev=%02x.%04x RY=0x%02x => rc=EINVAL\n" , - __func__, card, queue, - ehdr->reply_code); + __func__, card, queue, ehdr->reply_code); }return -EINVAL ;case REP82_ERROR_MACHINE_FAILURE :/* 0x10 */
@@ -125,15 +122,10 @@ static inline int convert_error(struct zcrypt_queue *zq,/* For type 86 response show the apfs value (failure reason) */ if (ehdr->reply_code ==REP82_ERROR_TRANSPORT_FAIL && ehdr->type ==TYPE86_RSP_CODE ) { -struct { -struct type86_hdr hdr; -struct type86_fmt2_ext fmt2; - } __packed * head = reply->msg; -unsigned int apfs = *((u32 *)head->fmt2.apfs); -ZCRYPT_DBF_WARN ("%s dev=%02x.%04x RY=0x%02x apfs=0x%x => bus rescan, rc=EAGAIN\n" , - __func__, card, queue, ehdr->reply_code, apfs); + __func__, card, queue, ehdr->reply_code, + t86hdr->fmt2.apfs); }else { ZCRYPT_DBF_WARN("%s dev=%02x.%04x RY=0x%02x => bus rescan, rc=EAGAIN\n", __func__, card, queue,
drivers/s390/crypto/zcrypt_msgtype6.c +1 -1
@@ -754,7 +754,7 @@ static int convert_response_xcrb(bool userspace, struct zcrypt_queue *zq,return convert_error (zq, reply);case TYPE86_RSP_CODE :if (msg->hdr.reply_code) { -memcpy (&xcrb->status, msg->fmt2.apfs,sizeof (u32)); + xcrb->status = msg->fmt2.apfs;return convert_error (zq, reply); }if (msg->cprbx.cprb_ver_id ==0x02 )
drivers/s390/crypto/zcrypt_msgtype6.h +2 -2
@@ -34,7 +34,7 @@ struct type6_hdr {unsigned char right[4 ];/* 0x00000000 */ unsigned char reserved3[2 ];/* 0x0000 */ unsigned char reserved4[2 ];/* 0x0000 */ -unsigned char apfs[4 ];/* 0x00000000 */ +unsigned int apfs;/* 0x00000000 */ unsigned int offset1;/* 0x00000058 (offset to CPRB) */ unsigned int offset2;/* 0x00000000 */ unsigned int offset3;/* 0x00000000 */
@@ -83,7 +83,7 @@ struct type86_hdr {struct type86_fmt2_ext {unsigned char reserved[4 ];/* 0x00000000 */ -unsigned char apfs[4 ];/* final status */ +unsigned int apfs;/* final status */ unsigned int count1;/* length of CPRB + parameters */ unsigned int offset1;/* offset to CPRB */ unsigned int count2;/* 0x00000000 */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 365/816 s390/zcrypt: Fix and improve zcrypt reply message verification checks
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Harald Freudenberger <[email protected]>
[ Upstream commit 5e9b339f323216d71f3ede8a0a427abf7859c486 ]
Add or improve checks related to buffer sizes and reply sizes to the handling of replies from the crypto cards for CCA, EP11 (AP message type 6) and ICA (AP type 50) messages. The verification code related to reply field length was not designed well and thus firmware deficiencies could lead to unexpected behavior in the zcrypt device driver. Thus improve the code to more closely inspect especially length fields at message replies.
Add length validation before accessing reply message structures in zcrypt_msgtype6_receive(), zcrypt_msgtype6_receive_ep11(), and zcrypt_msgtype50_receive() to prevent out-of-bounds reads and potential kernel memory disclosure.
Also rework these three functions to validate reply lengths more carefully before copying data back into the request buffer. Use size_t for length calculations, reject inconsistent reply sizes, and add defensive handling for short invalid replies. For XCRB replies, validate both reply segments and derive the effective message length from the covered range instead of trusting only the second segment.
Additionally improve some of the later invoked evaluation functions which further check the payload. Add comments about length assumptions and for the type50 processing rework the payload processing completely with removing a misplaced BUG_ON().
--- drivers/s390/crypto/zcrypt_msgtype50.c | 95 ++++++++---- drivers/s390/crypto/zcrypt_msgtype6.c | 202 ++++++++++++++++++------- 2 files changed, 218 insertions(+), 79 deletions(-)
drivers/s390/crypto/zcrypt_msgtype50.c +68 -27
@@ -153,6 +153,11 @@ struct type80_hdr {unsigned char reserved3[8 ]; } __packed; +struct type80_reply { +struct type80_hdr hdr; +char data[]; +} __packed; +int get_rsa_modex_fc (struct ica_rsa_modexpo *mex,int *fcode) {if (!mex->inputdatalength)
@@ -341,32 +346,43 @@ static int ICACRT_msg_to_type50CRT_msg(struct zcrypt_queue *zq,* @data: pointer to user output data * @length: size of user output data * -* Returns 0 on success or -EFAULT. +* Returns 0 on success or neg. errno value on failure. */ static int convert_type80 (struct zcrypt_queue *zq,struct ap_message *reply,char __user *outputdata,unsigned int outputdatalength) { -struct type80_hdr *t80h = reply->msg; -unsigned char *data; +struct type80_reply *msg = reply->msg; +size_t payload_len; + +/* +* reply->len is always >= sizeof(struct type80_reply) here and +* outputdatalength (the modulus size) is guaranteed to be equal to +* inputdatalength and 0 < outputdatalength <= CEX3A_MAX_MOD_SIZE, +* also payload size may be >= outputdatalength. +*/ + + payload_len = reply->len -sizeof (msg->hdr); -if (t80h->len <sizeof (*t80h) + outputdatalength) { -/* The result is too short, the CEXxA card may not do that.. */ +if (outputdatalength > payload_len) { +/* We expect at least outputdatalength bytes, broken card ? */ zq->online =0 ;pr_err ("Crypto dev=%02x.%04x code=0x%02x => online=0 rc=EAGAIN\n" ,AP_QID_CARD (zq->queue->qid), -AP_QID_QUEUE (zq->queue->qid), t80h->code); +AP_QID_QUEUE (zq->queue->qid), msg->hdr.code);ZCRYPT_DBF_ERR ("%s dev=%02x.%04x code=0x%02x => online=0 rc=EAGAIN\n" , __func__,AP_QID_CARD (zq->queue->qid), -AP_QID_QUEUE (zq->queue->qid), t80h->code); +AP_QID_QUEUE (zq->queue->qid), msg->hdr.code);ap_send_online_uevent (&zq->queue->ap_dev, zq->online);return -EAGAIN ; } -BUG_ON (t80h->len >CEX3A_MAX_RESPONSE_SIZE ); - data = reply->msg + t80h->len - outputdatalength; -if (copy_to_user (outputdata, data, outputdatalength)) + +if (copy_to_user (outputdata, + msg->data + payload_len - outputdatalength, + outputdatalength))return -EFAULT ; +return 0 ; }
@@ -375,14 +391,19 @@ static int convert_response(struct zcrypt_queue *zq,char __user *outputdata, unsigned int outputdatalength) { -/* Response type byte is the second byte in the response. */ -unsigned char rtype = ((unsigned char *)reply->msg)[1 ]; + struct type80_reply *msg = reply->msg; + +/* reply->len is always >= sizeof(struct error_hdr) here */ -switch (rtype) { +switch (msg->hdr.type) {case TYPE82_RSP_CODE :case TYPE88_RSP_CODE :return convert_error (zq, reply);case TYPE80_RSP_CODE : +if (msg->hdr.code) +return convert_error (zq, reply); +if (reply->len <sizeof (struct type80_reply )) +return -EINVAL ;return convert_type80 (zq, reply, outputdata, outputdatalength);default :/* Unknown response type, this should NEVER EVER happen */
@@ -390,11 +411,11 @@ static int convert_response(struct zcrypt_queue *zq,pr_err ("Crypto dev=%02x.%04x unknown response type 0x%02x => online=0 rc=EAGAIN\n" ,AP_QID_CARD (zq->queue->qid),AP_QID_QUEUE (zq->queue->qid), - (int )rtype); + (int )msg->hdr.type);ZCRYPT_DBF_ERR ("%s dev=%02x.%04x unknown response type 0x%02x => online=0 rc=EAGAIN\n" , __func__,AP_QID_CARD (zq->queue->qid), -AP_QID_QUEUE (zq->queue->qid), (int )rtype); +AP_QID_QUEUE (zq->queue->qid), (int )msg->hdr.type);ap_send_online_uevent (&zq->queue->ap_dev, zq->online);return -EAGAIN ; }
@@ -417,26 +438,46 @@ static void zcrypt_msgtype50_receive(struct ap_queue *aq, .reply_code = REP82_ERROR_MACHINE_FAILURE, };struct type80_hdr *t80h; -int len; +size_t len;/* Copy the reply message to the request message buffer. */ if (!reply) goto out;/* ap_msg->rc indicates the error */ + t80h = reply->msg; -if (t80h->type ==TYPE80_RSP_CODE ) { - len = t80h->len; -if (len > reply->bufsize || len > msg->bufsize || - len != reply->len) { -pr_debug ("len mismatch => EMSGSIZE\n" ); - msg->rc = -EMSGSIZE ; + +if (reply->len <sizeof (*t80h) || + t80h->type !=TYPE80_RSP_CODE ) { +if (reply->len <sizeof (error_reply)) { +/* total broken reply, use static error reply instead */ +memcpy (msg->msg, &error_reply,sizeof (error_reply)); + msg->len =sizeof (error_reply); goto out; + }else { +/* malformed reply, convert function will handle this */ + len = reply->len; + goto copy_len_and_out; } -memcpy (msg->msg, reply->msg, len); - msg->len = len; - }else { -memcpy (msg->msg, reply->msg,sizeof (error_reply)); - msg->len =sizeof (error_reply); } + + len = t80h->len; + +copy_len_and_out: +if (len != reply->len) { + msg->rc = -EMSGSIZE ; +pr_debug ("len %zu rpl.len %zu mismatch, msg.rc=%d\n" , + len, reply->len, msg->rc); + goto out; + } +if (len > reply->bufsize || len > msg->bufsize) { + msg->rc = -EMSGSIZE ; +pr_debug ("len %zu exceeds buf %zu/%zu, msg.rc=%d\n" , + len, reply->bufsize, msg->bufsize, msg->rc); + goto out; + } +memcpy (msg->msg, reply->msg, len); + msg->len = len; + out:complete (&msg->response.work); }
drivers/s390/crypto/zcrypt_msgtype6.c +150 -52
296 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 366/816 mm: khugepaged: fix folio is used after pte_unmap_unlock()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vernon Yang <[email protected]>
[ Upstream commit ba2f1f92ddfabd340c9248fd2380104f717ee8b1 ]
After the page table lock has dropped, the folio can be freed concurrently. The trace_mm_khugepaged_scan_pmd() is left with a dangling folio pointer.
So using the folio_pfn() before dropping the page table lock, closing use-after-free window.
And other pre-existing bug, When the for (i = 0; i < HPAGE_PMD_NR; i++) iteration to terminate and the folio operation preceding is normal, but pfn will be incorrect. so we really only trace the PFN if it really was problematic.
--- include/trace/events/huge_memory.h | 6 +++--- mm/khugepaged.c | 9 ++++++++- 2 files changed, 11 insertions(+), 4 deletions(-)
include/trace/events/huge_memory.h +3 -3
@@ -55,10 +55,10 @@ SCAN_STATUS TRACE_EVENT(mm_khugepaged_scan_pmd, - TP_PROTO(struct mm_struct *mm, struct page *page, bool writable, + TP_PROTO(struct mm_struct *mm, unsigned long pfn, bool writable, int referenced, int none_or_zero, int status, int unmapped), - TP_ARGS(mm, page, writable, referenced, none_or_zero, status, unmapped), + TP_ARGS(mm, pfn, writable, referenced, none_or_zero, status, unmapped), TP_STRUCT__entry( __field(struct mm_struct *, mm)
@@ -72,7 +72,7 @@ TRACE_EVENT(mm_khugepaged_scan_pmd,TP_fast_assign ( __entry->mm = mm; - __entry->pfn = page ?page_to_pfn (page) :-1 ; + __entry->pfn = pfn; __entry->writable = writable; __entry->referenced = referenced; __entry->none_or_zero = none_or_zero;
mm/khugepaged.c +8 -1
@@ -1265,6 +1265,7 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm,int none_or_zero =0 , shared =0 ;struct page *page =NULL ;struct folio *folio =NULL ; +unsigned long failed_pfn =-1 ;unsigned long _address;spinlock_t *ptl;int node =NUMA_NO_NODE , unmapped =0 ;
@@ -1344,6 +1345,7 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm,if (!folio_test_anon (folio)) { result =SCAN_PAGE_ANON ; + failed_pfn =folio_pfn (folio); goto out_unmap; }
@@ -1358,6 +1360,7 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm,if (cc->is_khugepaged && shared > khugepaged_max_ptes_shared) { result =SCAN_EXCEED_SHARED_PTE ; + failed_pfn =folio_pfn (folio);count_vm_event (THP_SCAN_EXCEED_SHARED_PTE ); goto out_unmap; }
@@ -1372,15 +1375,18 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm, node =folio_nid (folio);if (hpage_collapse_scan_abort (node, cc)) { result =SCAN_SCAN_ABORT ; + failed_pfn =folio_pfn (folio); goto out_unmap; } cc->node_load[node]++;if (!folio_test_lru (folio)) { result =SCAN_PAGE_LRU ; + failed_pfn =folio_pfn (folio); goto out_unmap; }if (folio_test_locked (folio)) { result =SCAN_PAGE_LOCK ; + failed_pfn =folio_pfn (folio); goto out_unmap; }
@@ -1396,6 +1402,7 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm,*/ if (!is_refcount_suitable (folio)) { result =SCAN_PAGE_COUNT ; + failed_pfn =folio_pfn (folio); goto out_unmap; }
@@ -1427,7 +1434,7 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm, *mmap_locked = false; } out: -trace_mm_khugepaged_scan_pmd (mm, &folio->page, writable, referenced, +trace_mm_khugepaged_scan_pmd (mm, failed_pfn, writable, referenced, none_or_zero, result, unmapped);return result; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 367/816 smb: client: reclaim credits for decrypted reads with no matching mid
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
[ Upstream commit 78f73985846465a25a7bd1d89904053661f3ca92 ]
When a decrypted SMB2 READ response carries a MessageId that matches no outstanding request, both the inline receive_encrypted_read() and the offloaded smb2_decrypt_offload() paths drop the frame without accounting the credits the server granted in it. The plaintext unknown-frame path in cifs_demultiplex_thread() already reclaims them with smb2_add_credits_from_hdr(), so encrypted reads leak credits that the plaintext path would not.
This also happens for legitimate frames - e.g. a reply that arrives after the client has timed out and dropped the mid - so over a long-lived connection the client's credit count drifts down and can eventually starve it of the ability to issue requests. The frame is AEAD-authenticated, so the granted credits in the decrypted header come from the real server and are safe to apply.
Reclaim the credits from the decrypted header before dropping the frame, and export smb2_add_credits_from_hdr() so the SMB2 receive paths can use it.
--- fs/smb/client/cifsproto.h | 1 + fs/smb/client/connect.c | 3 +-- fs/smb/client/smb2ops.c | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-)
fs/smb/client/cifsproto.h +1 -0
@@ -145,6 +145,7 @@ cifs_mark_tcp_ses_conns_for_reconnect(struct TCP_Server_Info *server, bool mark_smb_session);extern int cifs_reconnect (struct TCP_Server_Info *server,bool mark_smb_session); +void smb2_add_credits_from_hdr (char *buffer,struct TCP_Server_Info *server);extern int checkSMB (char *buf,unsigned int len,struct TCP_Server_Info *srvr);extern bool is_valid_oplock_break (char *,struct TCP_Server_Info *);extern bool backup_cred (struct cifs_sb_info *);
fs/smb/client/connect.c +1 -2
@@ -1153,8 +1153,7 @@ cifs_handle_standard(struct TCP_Server_Info *server, struct mid_q_entry *mid)return 0 ; } -static void -smb2_add_credits_from_hdr (char *buffer,struct TCP_Server_Info *server) +void smb2_add_credits_from_hdr (char *buffer,struct TCP_Server_Info *server) {struct smb2_hdr *shdr = (struct smb2_hdr *)buffer;int scredits, in_flight;
fs/smb/client/smb2ops.c +4 -2
@@ -5165,9 +5165,10 @@ static void smb2_decrypt_offload(struct work_struct *work) dw->server->lstrp = jiffies; mid =smb2_find_dequeue_mid (dw->server, dw->buf); -if (mid ==NULL ) +if (mid ==NULL ) {cifs_dbg (FYI ,"mid not found\n" ); -else { +smb2_add_credits_from_hdr (dw->buf, dw->server); + }else { mid->decrypted = true; rc = handle_read_data(dw->server, mid, dw->buf, dw->server->vals->read_rsp_size,
@@ -5290,6 +5291,7 @@ receive_encrypted_read(struct TCP_Server_Info *server, struct mid_q_entry **mid, *mid =smb2_find_mid (server, buf);if (*mid ==NULL ) {cifs_dbg (FYI ,"mid not found\n" ); +smb2_add_credits_from_hdr (buf, server); rc =-1 ; }else {cifs_dbg (FYI ,"mid found\n" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 368/816 smb: client: validate NT transaction response layout and offsets
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ratnaker Gautam <[email protected]>
[ Upstream commit 83d0d5e0ca22233c75daf139ec0063b9d2ff1ac7 ]
validate_ntransact() assumes that the response uses the fixed 18-word NT transaction layout. A different WordCount makes get_bcc() locate the byte count at a different offset from pSMBr->ByteCount, allowing the subsequent bounds checks to use inconsistent response boundaries.
The function also turns the 32-bit ParameterOffset and DataOffset fields into pointers before checking their bounds. On a 32-bit client, a large offset can wrap the pointer below end_of_smb and pass the one-sided pointer comparison. The caller then dereferences the parameter pointer or copies from the data pointer.
Require the expected WordCount before reading the byte count. Check each offset and count against the received SMB length as integers before forming either pointer. Use subtraction after validating the offset so that the range checks cannot overflow.
--- fs/smb/client/cifssmb.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-)
fs/smb/client/cifssmb.c +19 -13
@@ -3408,9 +3408,10 @@ static intvalidate_ntransact (char *buf, char **ppparm, char **ppdata, __u32 *pparmlen, __u32 *pdatalen) { -char *end_of_smb;__u32 data_count, data_offset, parm_count, parm_offset;struct smb_com_ntransact_rsp *pSMBr; +size_t buflen; +char *end_buf;u16 bcc; *pdatalen =0 ;
@@ -3421,37 +3422,42 @@ validate_ntransact(char *buf, char **ppparm, char **ppdata, pSMBr = (struct smb_com_ntransact_rsp *)buf; +if (pSMBr->hdr.WordCount !=18 ) { +cifs_dbg (FYI ,"invalid NT transaction WordCount %u\n" , + pSMBr->hdr.WordCount); +return -EINVAL ; + } + bcc =get_bcc (&pSMBr->hdr); - end_of_smb =2 /* sizeof byte count */ + bcc + - (char *)&pSMBr->ByteCount; + end_buf =2 /* sizeof byte count */ + bcc + (char *)&pSMBr->ByteCount; + buflen = end_buf - buf; data_offset =le32_to_cpu (pSMBr->DataOffset); data_count =le32_to_cpu (pSMBr->DataCount); parm_offset =le32_to_cpu (pSMBr->ParameterOffset); parm_count =le32_to_cpu (pSMBr->ParameterCount); - *ppparm = (char *)&pSMBr->hdr.Protocol + parm_offset; - *ppdata = (char *)&pSMBr->hdr.Protocol + data_offset; -/* should we also check that parm and data areas do not overlap? */ -if (*ppparm > end_of_smb) { +if (parm_offset > buflen) {cifs_dbg (FYI ,"parms start after end of smb\n" );return -EINVAL ; - }else if (parm_count + *ppparm > end_of_smb) { + }else if (parm_count > buflen - parm_offset) {cifs_dbg (FYI ,"parm end after end of smb\n" );return -EINVAL ; - }else if (*ppdata > end_of_smb) { + }else if (data_offset > buflen) {cifs_dbg (FYI ,"data starts after end of smb\n" );return -EINVAL ; - }else if (data_count + *ppdata > end_of_smb) { -cifs_dbg (FYI ,"data %p + count %d (%p) past smb end %p start %p\n" , - *ppdata, data_count, (data_count + *ppdata), - end_of_smb, pSMBr); + }else if (data_count > buflen - data_offset) { +cifs_dbg (FYI ,"data offset %u + count %u past smb length %zu\n" , + data_offset, data_count, buflen);return -EINVAL ; }else if (parm_count + data_count > bcc) {cifs_dbg (FYI ,"parm count and data count larger than SMB\n" );return -EINVAL ; } + + *ppparm = buf + parm_offset; + *ppdata = buf + data_offset; *pdatalen = data_count; *pparmlen = parm_count;return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 369/816 rxrpc: Fix lack of short-send handling in rxrpc_kernel_send_data()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit af208f36ae22440cf6011a43cb3064fd525d85b4 ]
Fix rxrpc_kernel_send_data() to loop around if it detects a short send. David Laight suggested doing it here rather than wrapping all the calls in loops. Further, remove the len argument and use the iterator count instead and return 0 on success, not the amount copied.
Note this is also a prerequisite for changing the way rxrpc_send_data() works to return a short send rather than an error if some data was buffered.
--- Documentation/networking/rxrpc.rst | 8 +++++--- fs/afs/rxrpc.c | 8 +++----- include/net/af_rxrpc.h | 5 ++--- net/rxrpc/rxperf.c | 25 ++++++++++--------------- net/rxrpc/sendmsg.c | 27 +++++++++++++++++++-------- 5 files changed, 39 insertions(+), 34 deletions(-)
Documentation/networking/rxrpc.rst +5 -3
@@ -873,7 +873,6 @@ The kernel interface functions are as follows: int rxrpc_kernel_send_data(struct socket *sock, struct rxrpc_call *call, struct msghdr *msg, - size_t len, rxrpc_notify_end_tx_t notify_end_rx); This is used to supply either the request part of a client call or the
@@ -882,14 +881,17 @@ The kernel interface functions are as follows: exclusively to in-kernel virtual addresses. msg.msg_flags may be given MSG_MORE if there will be subsequent data sends for this call. - The msg must not specify a destination address, control data or any flags - other than MSG_MORE. len is the total amount of data to transmit. + msg must not specify a destination address, control data or any flags + other than MSG_MORE or MSG_WAITALL. notify_end_rx can be NULL or it can be used to specify a function to be called when the call changes state to end the Tx phase. This function is called with a spinlock held to prevent the last DATA packet from being transmitted until the function returns. + It returns 0 if all the provided data has been buffered and a negative + error code on failure. + (#) Receive data from a call:: int rxrpc_kernel_recv_data(struct socket *sock,
fs/afs/rxrpc.c +3 -5
@@ -411,8 +411,7 @@ void afs_make_call(struct afs_call *call, gfp_t gfp) msg.msg_controllen =0 ; msg.msg_flags =MSG_WAITALL | (call->write_iter ?MSG_MORE :0 ); - ret =rxrpc_kernel_send_data (call->net->socket, rxcall, - &msg, call->request_size, + ret =rxrpc_kernel_send_data (call->net->socket, rxcall, &msg, afs_notify_end_request_tx);if (ret <0 ) goto error_do_abort;
@@ -424,7 +423,6 @@ void afs_make_call(struct afs_call *call, gfp_t gfp) ret =rxrpc_kernel_send_data (call->net->socket, call->rxcall, &msg, -iov_iter_count (&msg.msg_iter), afs_notify_end_request_tx); *call->write_iter = msg.msg_iter;
@@ -864,7 +862,7 @@ void afs_send_empty_reply(struct afs_call *call) msg.msg_controllen =0 ; msg.msg_flags =0 ; - ret =rxrpc_kernel_send_data (net->socket, call->rxcall, &msg,0 , + ret =rxrpc_kernel_send_data (net->socket, call->rxcall, &msg, afs_notify_end_reply_tx);if (ret <0 ) { rxrpc_kernel_abort_call(net->socket, call->rxcall,
@@ -897,7 +895,7 @@ void afs_send_simple_reply(struct afs_call *call, const void *buf, size_t len) msg.msg_controllen =0 ; msg.msg_flags =0 ; - ret =rxrpc_kernel_send_data (net->socket, call->rxcall, &msg, len, + ret =rxrpc_kernel_send_data (net->socket, call->rxcall, &msg, afs_notify_end_reply_tx);if (ret <0 ) { rxrpc_kernel_abort_call(net->socket, call->rxcall,
include/net/af_rxrpc.h +2 -3
@@ -58,9 +58,8 @@ struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock,bool upgrade, enum rxrpc_interruptibility interruptibility, unsigned int debug_id); -int rxrpc_kernel_send_data (struct socket *,struct rxrpc_call *, -struct msghdr *,size_t , -rxrpc_notify_end_tx_t ); +int rxrpc_kernel_send_data (struct socket *sock,struct rxrpc_call *call, +struct msghdr *msg,rxrpc_notify_end_tx_t notify_end_tx);int rxrpc_kernel_recv_data (struct socket *,struct rxrpc_call *,struct iov_iter *,size_t *,bool ,u32 *,u16 *); bool rxrpc_kernel_abort_call(struct socket *, struct rxrpc_call *,
net/rxrpc/rxperf.c +10 -15
@@ -512,8 +512,8 @@ static int rxperf_process_call(struct rxperf_call *call)struct msghdr msg = {};struct bio_vec bv;struct kvec iov[1 ]; -ssize_t n;size_t reply_len = call->reply_len, len; +int ret;rxrpc_kernel_set_tx_length (rxperf_socket, call->rxcall, reply_len +sizeof (rxperf_magic_cookie));
@@ -523,13 +523,11 @@ static int rxperf_process_call(struct rxperf_call *call)bvec_set_page (&bv,ZERO_PAGE (0 ), len,0 );iov_iter_bvec (&msg.msg_iter,WRITE , &bv,1 , len); msg.msg_flags =MSG_MORE ; - n =rxrpc_kernel_send_data (rxperf_socket, call->rxcall, &msg, - len, rxperf_notify_end_reply_tx); -if (n <0 ) -return n; -if (n ==0 ) -return -EIO ; - reply_len -= n; + ret =rxrpc_kernel_send_data (rxperf_socket, call->rxcall, &msg, + rxperf_notify_end_reply_tx); +if (ret <0 ) +return ret; + reply_len -= len; } len =sizeof (rxperf_magic_cookie);
@@ -537,16 +535,13 @@ static int rxperf_process_call(struct rxperf_call *call) iov[0 ].iov_len = len;iov_iter_kvec (&msg.msg_iter,WRITE , iov,1 , len); msg.msg_flags =0 ; - n =rxrpc_kernel_send_data (rxperf_socket, call->rxcall, &msg, len, - rxperf_notify_end_reply_tx); -if (n >=0 ) -return 0 ;/* Success */ - -if (n == -ENOMEM ) + ret =rxrpc_kernel_send_data (rxperf_socket, call->rxcall, &msg, + rxperf_notify_end_reply_tx); +if (ret == -ENOMEM )rxrpc_kernel_abort_call (rxperf_socket, call->rxcall,RXGEN_SS_MARSHAL , -ENOMEM , rxperf_abort_oom); -return n; +return ret; }/*
net/rxrpc/sendmsg.c +19 -8
@@ -737,7 +737,6 @@ int rxrpc_do_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, size_t len)* @sock: The socket the call is on * @call: The call to send data through * @msg: The data to send -* @len: The amount of data to send * @notify_end_tx: Notification that the last packet is queued. * * Allow a kernel service to send data on a call. The call must be in an state
@@ -748,8 +747,7 @@ int rxrpc_do_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, size_t len)* Return: %0 if successful and a negative error code otherwise. */ int rxrpc_kernel_send_data (struct socket *sock,struct rxrpc_call *call, -struct msghdr *msg,size_t len, -rxrpc_notify_end_tx_t notify_end_tx) +struct msghdr *msg,rxrpc_notify_end_tx_t notify_end_tx) {int ret;
@@ -758,12 +756,25 @@ int rxrpc_kernel_send_data(struct socket *sock, struct rxrpc_call *call, ASSERTCMP(msg->msg_name, ==, NULL); ASSERTCMP(msg->msg_control, ==, NULL); -mutex_lock (&call->user_mutex); +for (;;) { +mutex_lock (&call->user_mutex); + + ret =rxrpc_send_data (rxrpc_sk (sock->sk), call, msg, +msg_data_left (msg), notify_end_tx); +if (ret == -ESHUTDOWN ) + ret = call->error; +if (ret <0 ) +break ; +if (msg_data_left (msg) ==0 ) { + ret =0 ; +break ; + } +if (ret ==0 ) { + ret = -EIO ; +break ; + } + } - ret =rxrpc_send_data (rxrpc_sk (sock->sk), call, msg, len, - notify_end_tx); -if (ret == -ESHUTDOWN ) - ret = call->error;_leave (" = %d" , ret);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 370/816 x86/cpuid: Mark CPUID function 0x23 as being indexed
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit 108775fa28fe04a16f19a828a779689f3d0ea9f0 ]
Add function 0x23 to the set of CPUID functions that are indexed, as per the SDM and the many sub-leafs defined in leaf_types.h.
--- arch/x86/include/asm/cpuid.h | 1 + 1 file changed, 1 insertion(+)
arch/x86/include/asm/cpuid.h +1 -0
@@ -179,6 +179,7 @@ static __always_inline bool cpuid_function_is_indexed(u32 function)case 0x1d :case 0x1e :case 0x1f : +case 0x23 :case 0x24 :case 0x8000001d :return true;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 371/816 media: rc: Replace open coded krealloc() for keymap
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Young <[email protected]>
[ Upstream commit e4b4aa413cc2e48a261c8c513ced964a3390c0cf ]
Replace open coded krealloc() and remove superfluous member of struct rc_map - we don't need to track both the size in bytes and entries.
Stable-dep-of: ab9567336171 ("media: rc: Add missing locking for keymap")
--- drivers/media/rc/rc-main.c | 45 +++++++++++++++++++------------------- include/media/rc-map.h | 2 -- 2 files changed, 22 insertions(+), 25 deletions(-)
drivers/media/rc/rc-main.c +22 -23
@@ -17,9 +17,8 @@#include <linux/module.h> #include "rc-core-priv.h" -/* Sizes are in bytes, 256 bytes allows for 32 entries on x64 */ -#define IR_TAB_MIN_SIZE 256 -#define IR_TAB_MAX_SIZE 8192 +#define IR_TAB_MIN_ENTRIES 32 +#define IR_TAB_MAX_ENTRIES 1024 static const struct { const char *name;
@@ -214,21 +213,23 @@ static int scancode_to_u64(const struct input_keymap_entry *ke, u64 *scancode)static int ir_create_table (struct rc_dev *dev,struct rc_map *rc_map,const char *name,u64 rc_proto,size_t size) { +unsigned int alloc; rc_map->name =kstrdup (name,GFP_KERNEL );if (!rc_map->name)return -ENOMEM ; + alloc =roundup_pow_of_two (size); rc_map->rc_proto = rc_proto; - rc_map->alloc =roundup_pow_of_two (size *sizeof (struct rc_map_table )); - rc_map->size = rc_map->alloc /sizeof (struct rc_map_table ); - rc_map->scan =kmalloc (rc_map->alloc,GFP_KERNEL ); + rc_map->len =0 ; + rc_map->size = alloc; + rc_map->scan = kmalloc_objs(struct rc_map_table, alloc, GFP_KERNEL);if (!rc_map->scan) {kfree (rc_map->name); rc_map->name =NULL ;return -ENOMEM ; } -dev_dbg (&dev->dev,"Allocated space for %u keycode entries (%u bytes)\n" , - rc_map->size, rc_map->alloc); +dev_dbg (&dev->dev,"Allocated space for %u keycode entries (%zu bytes)\n" , + alloc, alloc *sizeof (struct rc_map_table ));return 0 ; }
@@ -262,38 +263,36 @@ static void ir_free_table(struct rc_map *rc_map)static int ir_resize_table (struct rc_dev *dev,struct rc_map *rc_map,gfp_t gfp_flags) { -unsigned int oldalloc = rc_map->alloc; -unsigned int newalloc = oldalloc; -struct rc_map_table *oldscan = rc_map->scan; +unsigned int newsize = rc_map->size;struct rc_map_table *newscan;if (rc_map->size == rc_map->len) {/* All entries in use -> grow keytable */ -if (rc_map->alloc >=IR_TAB_MAX_SIZE ) +if (newsize >=IR_TAB_MAX_ENTRIES )return -ENOMEM ; - newalloc *=2 ; -dev_dbg (&dev->dev,"Growing table to %u bytes\n" , newalloc); + newsize *=2 ; + +dev_dbg (&dev->dev,"Growing table to %u entries\n" , newsize); } -if ((rc_map->len *3 < rc_map->size) && (oldalloc >IR_TAB_MIN_SIZE )) { +if (rc_map->len *3 < rc_map->size && rc_map->size >IR_TAB_MIN_ENTRIES ) {/* Less than 1/3 of entries in use -> shrink keytable */ - newalloc /=2 ; -dev_dbg (&dev->dev,"Shrinking table to %u bytes\n" , newalloc); + newsize /=2 ; +dev_dbg (&dev->dev,"Shrinking table to %u entries\n" , newsize); } -if (newalloc == oldalloc) +if (newsize == rc_map->size)return 0 ; - newscan =kmalloc (newalloc, gfp_flags); + newscan =krealloc_array (rc_map->scan, newsize, +sizeof (struct rc_map_table ), gfp_flags);if (!newscan)return -ENOMEM ; -memcpy (newscan, rc_map->scan, rc_map->len *sizeof (struct rc_map_table )); rc_map->scan = newscan; - rc_map->alloc = newalloc; - rc_map->size = rc_map->alloc /sizeof (struct rc_map_table ); -kfree (oldscan); + rc_map->size = newsize; +return 0 ; }
include/media/rc-map.h +0 -2
@@ -148,7 +148,6 @@ struct rc_map_table {* @scan: pointer to struct &rc_map_table * @size: Max number of entries * @len: Number of entries that are in use -* @alloc: size of \*scan, in bytes * @rc_proto: type of the remote controller protocol, as defined at * enum &rc_proto * @name: name of the key map table
@@ -158,7 +157,6 @@ struct rc_map {struct rc_map_table *scan;unsigned int size;unsigned int len; -unsigned int alloc;enum rc_proto rc_proto;const char *name;spinlock_t lock;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 372/816 media: rc: Add missing locking for keymap
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Young <[email protected]>
[ Upstream commit ab9567336171e46ce9e03ee126902b3fd7901baa ]
When the rc_map for an rc_dev gets updated, locking is required but is missing in places. A concurrent scancode lookup and a call to rc_{register,unregistered}_device() could result in a use-after-free; this could happen if IR is decoded during those function calls.
Add lockdep assertions where locks are required.
ir_free_table() should only be called for non-TX devices else we will use a spinlock without iniitializing it.
--- drivers/media/rc/rc-main.c | 86 +++++++++++++++++++++++++------------- 1 file changed, 57 insertions(+), 29 deletions(-)
drivers/media/rc/rc-main.c +57 -29
@@ -104,7 +104,6 @@ static struct rc_map_list *seek_rc_map(const char *name)struct rc_map *rc_map_get (const char *name) { -struct rc_map_list *map; map =seek_rc_map (name);
@@ -201,7 +200,7 @@ static int scancode_to_u64(const struct input_keymap_entry *ke, u64 *scancode)* ir_create_table() - initializes a scancode table * @dev: the rc_dev device * @rc_map: the rc_map to initialize -* @name: name to assign to the table +* @map_name: name to assign to the table * @rc_proto: ir type to assign to the new table * @size: initial size of the table *
@@ -211,23 +210,31 @@ static int scancode_to_u64(const struct input_keymap_entry *ke, u64 *scancode)* return: zero on success or a negative error code */ static int ir_create_table (struct rc_dev *dev,struct rc_map *rc_map, -const char *name,u64 rc_proto,size_t size) +const char *map_name,u64 rc_proto,size_t size) { +struct rc_map_table *scan;unsigned int alloc; - rc_map->name =kstrdup (name,GFP_KERNEL ); -if (!rc_map->name) +char *name; + + name =kstrdup (map_name,GFP_KERNEL ); +if (!name)return -ENOMEM ; + alloc =roundup_pow_of_two (size); - rc_map->rc_proto = rc_proto; - rc_map->len =0 ; - rc_map->size = alloc; - rc_map->scan = kmalloc_objs(struct rc_map_table, alloc, GFP_KERNEL); -if (!rc_map->scan) { -kfree (rc_map->name); - rc_map->name =NULL ; + scan = kmalloc_objs(struct rc_map_table, alloc, GFP_KERNEL); +if (!scan) { +kfree (name);return -ENOMEM ; } + scoped_guard(spinlock_irqsave, &rc_map->lock) { + rc_map->name = name; + rc_map->scan = scan; + rc_map->rc_proto = rc_proto; + rc_map->len =0 ; + rc_map->size = alloc; + } +dev_dbg (&dev->dev,"Allocated space for %u keycode entries (%zu bytes)\n" , alloc, alloc *sizeof (struct rc_map_table ));return 0 ;
@@ -237,16 +244,26 @@ static int ir_create_table(struct rc_dev *dev, struct rc_map *rc_map,* ir_free_table() - frees memory allocated by a scancode table * @rc_map: the table whose mappings need to be freed * -* This routine will free memory alloctaed for key mappings used by given +* This routine will free memory allocated for key mappings used by given * scancode table. */ static void ir_free_table (struct rc_map *rc_map) { - rc_map->size =0 ; -kfree (rc_map->name); - rc_map->name =NULL ; -kfree (rc_map->scan); - rc_map->scan =NULL ; +struct rc_map_table *scan; +const char *name; + + scoped_guard(spinlock_irqsave, &rc_map->lock) { + name = rc_map->name; + scan = rc_map->scan; + + rc_map->size =0 ; + rc_map->len =0 ; + rc_map->name =NULL ; + rc_map->scan =NULL ; + } + +kfree (name); +kfree (scan); }/**
@@ -266,6 +283,8 @@ static int ir_resize_table(struct rc_dev *dev, struct rc_map *rc_map,unsigned int newsize = rc_map->size;struct rc_map_table *newscan; +lockdep_assert_held (&rc_map->lock); +if (rc_map->size == rc_map->len) {/* All entries in use -> grow keytable */ if (newsize >=IR_TAB_MAX_ENTRIES )
@@ -317,6 +336,8 @@ static unsigned int ir_update_mapping(struct rc_dev *dev,int old_keycode = rc_map->scan[index].keycode;int i; +lockdep_assert_held (&rc_map->lock); +/* Did the user wish to remove the mapping? */ if (new_keycode ==KEY_RESERVED || new_keycode ==KEY_UNKNOWN ) { dev_dbg(&dev->dev, "#%d: Deleting scan 0x%04llx\n",
@@ -372,6 +393,8 @@ static unsigned int ir_establish_scancode(struct rc_dev *dev, {unsigned int i; +lockdep_assert_held (&rc_map->lock); +/* * Unfortunately, some hardware-based IR decoders don't provide * all bits for the complete IR code. In general, they provide only
@@ -396,7 +419,7 @@ static unsigned int ir_establish_scancode(struct rc_dev *dev,/* No previous mapping found, we might need to grow the table */ if (rc_map->size == rc_map->len) {if (!resize ||ir_resize_table (dev, rc_map,GFP_ATOMIC )) -return -1U ; +return UINT_MAX ; }/* i is the proper index to insert our new keycode */
@@ -478,16 +501,18 @@ static int ir_setkeytable(struct rc_dev *dev, const struct rc_map *from)if (rc)return rc; -for (i =0 ; i < from->size; i++) { - index =ir_establish_scancode (dev, rc_map, - from->scan[i].scancode, false); -if (index >= rc_map->len) { - rc = -ENOMEM ; -break ; - } + scoped_guard(spinlock_irqsave, &rc_map->lock) { +for (i =0 ; i < from->size; i++) { + index =ir_establish_scancode (dev, rc_map, + from->scan[i].scancode, false); +if (index >= rc_map->len) { + rc = -ENOMEM ; +break ; + } -ir_update_mapping (dev, rc_map, index, - from->scan[i].keycode); +ir_update_mapping (dev, rc_map, index, + from->scan[i].keycode); + } }if (rc)
@@ -523,6 +548,8 @@ static unsigned int ir_lookup_by_scancode(const struct rc_map *rc_map, {struct rc_map_table *res; +lockdep_assert_held (&rc_map->lock); + res =bsearch (&scancode, rc_map->scan, rc_map->len,sizeof (struct rc_map_table ), rc_map_cmp);if (!res)
@@ -1988,7 +2015,8 @@ int rc_register_device(struct rc_dev *dev)scoped_guard (mutex, &dev->lock) dev->registered = false; out_free_table: -ir_free_table (&dev->rc_map); +if (dev->driver_type !=RC_DRIVER_IR_RAW_TX ) +ir_free_table (&dev->rc_map); out_raw:ir_raw_event_free (dev); out_minor:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 373/816 wifi: mt76: take rcu_read_lock in the USB/SDIO tx completion path
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Devin Wittmayer <[email protected]>
[ Upstream commit a7871a7ae5a8625f0ba0a89454ac734c383dd538 ]
The USB and SDIO completion path reads a station pointer that RCU protects, without holding the read lock. Lockdep catches it on the first association:
mt76.h:1305 suspicious rcu_dereference_check() usage! no locks held by mt76-usb-status/1254.
mt7925_usb_sdio_tx_complete_skb+0x119/0x130 [mt7925_common] mt76_queue_tx_complete+0x27/0x60 [mt76] mt76u_status_worker+0xed/0x1e0 [mt76_usb]
mt7925/mac.c:856 suspicious rcu_dereference_check() usage!
mt7925_tx_check_aggr.part.0+0xc2/0xe0 [mt7925_common] mt7925_usb_sdio_tx_complete_skb+0xa0/0x130 [mt7925_common]
mt7921 does the same, and warns once instead of twice because its aggregation check reads the default link directly. The DMA path makes the same reads but completes from softirq, so it stays quiet.
Take the read lock around the lookup and the check.
Tested on 7.2-rc5 with lockdep, fresh module load per arm, 4000 packets each and no change to the link:
splats before after
MT7925 Netgear A9000 2 0
MT7921 Alfa 1 0
mt7921e same kernel 0 0
--- drivers/net/wireless/mediatek/mt76/mt7921/mac.c | 3 +++ drivers/net/wireless/mediatek/mt76/mt7925/mac.c | 3 +++ 2 files changed, 6 insertions(+)
drivers/net/wireless/mediatek/mt76/mt7921/mac.c +3 -0
@@ -832,11 +832,14 @@ void mt7921_usb_sdio_tx_complete_skb(struct mt76_dev *mdev,u16 idx; idx =le32_get_bits (txwi[1 ],MT_TXD1_WLAN_IDX ); + +rcu_read_lock (); wcid =rcu_dereference (mdev->wcid[idx]); sta =wcid_to_sta (wcid);if (sta &&likely (e->skb->protocol !=cpu_to_be16 (ETH_P_PAE )))mt76_connac2_tx_check_aggr (sta, txwi); +rcu_read_unlock ();skb_pull (e->skb, headroom);mt76_tx_complete_skb (mdev, e->wcid, e->skb);
drivers/net/wireless/mediatek/mt76/mt7925/mac.c +3 -0
@@ -1482,11 +1482,14 @@ void mt7925_usb_sdio_tx_complete_skb(struct mt76_dev *mdev,u16 idx; idx =le32_get_bits (txwi[1 ],MT_TXD1_WLAN_IDX ); + +rcu_read_lock (); wcid =rcu_dereference (mdev->wcid[idx]); sta =wcid_to_sta (wcid);if (sta &&likely (e->skb->protocol !=cpu_to_be16 (ETH_P_PAE )))mt7925_tx_check_aggr (sta, e->skb, wcid); +rcu_read_unlock ();skb_pull (e->skb, headroom);mt76_tx_complete_skb (mdev, e->wcid, e->skb);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 374/816 misc: fastrpc: Allocate entire reserved memory for Audio PD in probe
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jianping Li <[email protected]>
[ Upstream commit 9e47ad9c562e82cabfbb9afa6c2b0dcdf2702a39 ]
Allocating and freeing Audio PD memory from userspace is unsafe because the kernel cannot reliably determine when the DSP has finished using the memory. Userspace may free buffers while they are still in use by the DSP, and remote free requests cannot be safely trusted.
Additionally, the current implementation allows userspace to repeatedly grow the Audio PD heap, but does not support shrinking it. This can lead to unbounded memory usage over time, effectively causing a memory leak.
Fix this by allocating the entire Audio PD reserved-memory region during rpmsg probe and tying its lifetime to the rpmsg channel. This removes userspace-controlled alloc/free and ensures that memory is reclaimed only when the DSP process is torn down.
The reserved-memory region is now mandatory for the Audio PD domain. Rather than failing rpmsg probe when it is missing, validate it in fastrpc_init_create_static_process() and reject only the static-process creation. This keeps the fastrpc device probing for all other domains even on a misconfigured device tree.
--- drivers/misc/fastrpc.c | 198 ++++++++++++++++++++++------------------- 1 file changed, 106 insertions(+), 92 deletions(-)
drivers/misc/fastrpc.c +106 -92
@@ -47,8 +47,6 @@#define ADSP_MMAP_HEAP_ADDR 4/* MAP static DMA buffer on DSP User PD */ #define ADSP_MMAP_DMA_BUFFER 6 -/* Add memory to static PD pool protection thru hypervisor */ -#define ADSP_MMAP_REMOTE_HEAP_ADDR 8/* Add memory to userPD pool, for user heap */ #define ADSP_MMAP_ADD_PAGES 0x1000/* Add memory to userPD pool, for LLC heap */
@@ -273,10 +271,14 @@ struct fastrpc_channel_ctx {struct kref refcount;/* Flag if dsp attributes are cached */ bool valid_attributes; +/* Flag if audio PD init mem was allocated */ +bool audio_init_mem; +/* Audio PD reserved remote heap region */ +phys_addr_t remote_heap_addr; +u64 remote_heap_size;u32 dsp_attributes[FASTRPC_MAX_DSP_ATTRIBUTES ];struct fastrpc_device *secure_fdevice;struct fastrpc_device *fdevice; -struct fastrpc_buf *remote_heap;struct list_head invoke_interrupted_mmaps;bool secure;bool unsigned_support;
@@ -1320,15 +1322,24 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl,struct fastrpc_init_create_static init;struct fastrpc_invoke_args *args;struct fastrpc_phy_page pages[1 ]; +struct fastrpc_channel_ctx *cctx = fl->cctx;char *name;int err; -bool scm_done = false;struct {int pgid;u32 namelen;u32 pageslen; } inbuf;u32 sc; +unsigned long flags; +bool sent_heap = false; + +if (!cctx->remote_heap_addr || !cctx->remote_heap_size) { + err = -ENOMEM ; +dev_err (fl->sctx->dev, +"remote heap memory region is not added\n" ); +return err; + } args =kcalloc (FASTRPC_CREATE_STATIC_PROCESS_NARGS ,sizeof (*args),GFP_KERNEL );if (!args)
@@ -1350,31 +1361,6 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl, goto err; } -if (!fl->cctx->remote_heap) { - err =fastrpc_remote_heap_alloc (fl, fl->sctx->dev, init.memlen, - &fl->cctx->remote_heap); -if (err) - goto err_name; - -/* Map if we have any heap VMIDs associated with this ADSP Static Process. */ -if (fl->cctx->vmcount) { -u64 src_perms =BIT (QCOM_SCM_VMID_HLOS ); - - err =qcom_scm_assign_mem (fl->cctx->remote_heap->dma_addr, - (u64 )fl->cctx->remote_heap->size, - &src_perms, - fl->cctx->vmperms, fl->cctx->vmcount); -if (err) { -dev_err (fl->sctx->dev, -"Failed to assign memory with dma_addr %pad size 0x%llx err %d\n" , - &fl->cctx->remote_heap->dma_addr, - fl->cctx->remote_heap->size, err); - goto err_map; - } - scm_done = true; - } - } - inbuf.pgid = fl->tgid; inbuf.namelen = init.namelen; inbuf.pageslen =0 ;
@@ -1388,8 +1374,25 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl, args[1 ].length = inbuf.namelen; args[1 ].fd =-1 ; - pages[0 ].addr = fl->cctx->remote_heap->dma_addr; - pages[0 ].size = fl->cctx->remote_heap->size; +/* +* Audio PD is a static PD and retains the remote heap +* information across daemon restarts. Therefore only +* the first attach should provide heap information to +* DSP. Subsequent attaches reuse the previously +* initialized memory pool. +*/ +spin_lock_irqsave (&cctx->lock, flags); +if (!cctx->audio_init_mem) { + pages[0 ].addr = cctx->remote_heap_addr; + pages[0 ].size = cctx->remote_heap_size; + cctx->audio_init_mem = true; + inbuf.pageslen =1 ; + sent_heap = true; + }else { + pages[0 ].addr =0 ; + pages[0 ].size =0 ; + } +spin_unlock_irqrestore (&cctx->lock, flags); args[2 ].ptr = (u64 )(uintptr_t ) pages; args[2 ].length =sizeof (*pages);
@@ -1407,27 +1410,11 @@ static int fastrpc_init_create_static_process(struct fastrpc_user *fl,return 0 ; err_invoke: -if (fl->cctx->vmcount && scm_done) { -u64 src_perms =0 ; -struct qcom_scm_vmperm dst_perms; -u32 i; - -for (i =0 ; i < fl->cctx->vmcount; i++) - src_perms |=BIT (fl->cctx->vmperms[i].vmid); - - dst_perms.vmid =QCOM_SCM_VMID_HLOS ; - dst_perms.perm =QCOM_SCM_PERM_RWX ; - err =qcom_scm_assign_mem (fl->cctx->remote_heap->dma_addr, - (u64 )fl->cctx->remote_heap->size, - &src_perms, &dst_perms,1 ); -if (err) -dev_err (fl->sctx->dev,"Failed to assign memory dma_addr %pad size 0x%llx err %d\n" , - &fl->cctx->remote_heap->dma_addr, fl->cctx->remote_heap->size, err); +if (sent_heap) { +spin_lock_irqsave (&cctx->lock, flags); + cctx->audio_init_mem = false; +spin_unlock_irqrestore (&cctx->lock, flags); } -err_map: -fastrpc_buf_free (fl->cctx->remote_heap); - fl->cctx->remote_heap =NULL ; -err_name:kfree (name); err:kfree (args);
@@ -1937,7 +1924,7 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)if (copy_from_user (&req, argp,sizeof (req)))return -EFAULT ; -if (req.flags !=ADSP_MMAP_ADD_PAGES && req.flags !=ADSP_MMAP_REMOTE_HEAP_ADDR ) { +if (req.flags !=ADSP_MMAP_ADD_PAGES ) {dev_err (dev,"flag not supported 0x%x\n" , req.flags);return -EINVAL ;
@@ -1948,10 +1935,7 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)return -EINVAL ; } -if (req.flags ==ADSP_MMAP_REMOTE_HEAP_ADDR ) - err =fastrpc_remote_heap_alloc (fl, dev, req.size, &buf); -else - err =fastrpc_buf_alloc (fl, dev, req.size, &buf); + err =fastrpc_buf_alloc (fl, dev, req.size, &buf);if (err) {dev_err (dev,"failed to allocate buffer\n" );
@@ -1990,20 +1974,6 @@ static int fastrpc_req_mmap(struct fastrpc_user *fl, char __user *argp)/* let the client know the address to use */ req.vaddrout = rsp_msg.vaddr; -/* Add memory to static PD pool, protection thru hypervisor */ -if (req.flags ==ADSP_MMAP_REMOTE_HEAP_ADDR && fl->cctx->vmcount) { -u64 src_perms =BIT (QCOM_SCM_VMID_HLOS ); - - err =qcom_scm_assign_mem (buf->dma_addr, (u64 )buf->size, - &src_perms, fl->cctx->vmperms, fl->cctx->vmcount); -if (err) { -dev_err (fl->sctx->dev, -"Failed to assign memory dma_addr %pad size 0x%llx err %d" , - &buf->dma_addr, buf->size, err); - goto err_assign; - } - } -spin_lock (&fl->lock);list_add_tail (&buf->node, &fl->mmaps);spin_unlock (&fl->lock);
@@ -2323,6 +2293,50 @@ static int fastrpc_device_register(struct device *dev, struct fastrpc_channel_ctreturn err; } +static int fastrpc_init_reserved_mem (struct fastrpc_channel_ctx *cctx, +struct device *rdev,u32 domain_id) +{ +struct device_node *rmem_node; +struct reserved_mem *rmem; +u64 src_perms; + +/* Only SDSP and ADSP domains use a reserved remote heap region */ +if (domain_id !=SDSP_DOMAIN_ID && domain_id !=ADSP_DOMAIN_ID ) +return 0 ; + + rmem_node =of_parse_phandle (rdev->of_node,"memory-region" ,0 ); +if (!rmem_node) { +/* +* The reserved-memory region is optional at probe time. For +* the Audio PD (ADSP) domain its absence is validated later in +* fastrpc_init_create_static_process(), so keep probing here. +*/ +return 0 ; + } + + rmem =of_reserved_mem_lookup (rmem_node); +of_node_put (rmem_node); +if (!rmem) +return 0 ; + +/* +* Audio PD (ADSP) is a static PD: cache the region so its lifetime +* is tied to the rpmsg channel instead of being controlled by +* userspace. +*/ +if (domain_id ==ADSP_DOMAIN_ID ) { + cctx->remote_heap_addr = rmem->base; + cctx->remote_heap_size = rmem->size; + } + +if (!cctx->vmcount) +return 0 ; + + src_perms =BIT (QCOM_SCM_VMID_HLOS ); +return qcom_scm_assign_mem (rmem->base, rmem->size, &src_perms, + cctx->vmperms, cctx->vmcount); +} +static int fastrpc_rpmsg_probe (struct rpmsg_device *rpdev) {struct device *rdev = &rpdev->dev;
@@ -2330,8 +2344,6 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev)int i, err, domain_id =-1 , vmcount;const char *domain;bool secure_dsp; -struct device_node *rmem_node; -struct reserved_mem *rmem;unsigned int vmids[FASTRPC_MAX_VMIDS ]; err =of_property_read_string (rdev->of_node,"label" , &domain);
@@ -2374,24 +2386,9 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev) } } - rmem_node =of_parse_phandle (rdev->of_node,"memory-region" ,0 ); -if (domain_id ==SDSP_DOMAIN_ID && rmem_node) { -u64 src_perms; - - rmem =of_reserved_mem_lookup (rmem_node); -if (!rmem) { - err = -EINVAL ; - goto fdev_error; - } - - src_perms =BIT (QCOM_SCM_VMID_HLOS ); - - err =qcom_scm_assign_mem (rmem->base, rmem->size, &src_perms, - data->vmperms, data->vmcount); -if (err) - goto fdev_error; - - } + err =fastrpc_init_reserved_mem (data, rdev, domain_id); +if (err) + goto fdev_error; secure_dsp = !(of_property_read_bool (rdev->of_node,"qcom,non-secure-domain" )); data->secure = secure_dsp;
@@ -2487,8 +2484,25 @@ static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev)list_for_each_entry_safe (buf, b, &cctx->invoke_interrupted_mmaps, node)list_del (&buf->node); -if (cctx->remote_heap) -fastrpc_buf_free (cctx->remote_heap); +if (cctx->remote_heap_size && cctx->vmcount) { +u64 src_perms =0 ; +int err, i; +struct qcom_scm_vmperm dst_perms; + +for (i =0 ; i < cctx->vmcount; i++) + src_perms |=BIT (cctx->vmperms[i].vmid); + + dst_perms.vmid =QCOM_SCM_VMID_HLOS ; + dst_perms.perm =QCOM_SCM_PERM_RWX ; + + err =qcom_scm_assign_mem (cctx->remote_heap_addr, + cctx->remote_heap_size, &src_perms, + &dst_perms,1 ); +if (err) +dev_err (&rpdev->dev, +"Failed to assign memory back to HLOS: addr %pa size %#llx err %d\n" , + &cctx->remote_heap_addr, cctx->remote_heap_size, err); + }of_platform_depopulate (&rpdev->dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 375/816 power: supply: Correct multiple typos in comments
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shen Lichuan <[email protected]>
[ Upstream commit 570c2234d5d62d52be7e8e35169b96d98378a7ce ]
Fixed some spelling errors, the details are as follows:
-in the code comments:
dettached->detached meausered->measured meausurement->measurement sholuld->should Tempreture->Temperature measuremnts->measurements detecing->detecting persent->percent Parallell->Parallel
Stable-dep-of: 1fba78714201 ("power: supply: qcom_smbx: set the charge enable after software control")
--- drivers/power/supply/88pm860x_battery.c | 4 ++-- drivers/power/supply/ab8500_btemp.c | 2 +- drivers/power/supply/charger-manager.c | 2 +- drivers/power/supply/da9030_battery.c | 4 ++-- drivers/power/supply/max8925_power.c | 2 +- drivers/power/supply/qcom_battmgr.c | 2 +- drivers/power/supply/qcom_smbx.c | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-)
drivers/power/supply/88pm860x_battery.c +2 -2
@@ -422,7 +422,7 @@ static irqreturn_t pm860x_batt_handler(int irq, void *data) info->temp_type =PM860X_TEMP_TINT ; }mutex_unlock (&info->lock); -/* clear ccnt since battery is attached or dettached */ +/* clear ccnt since battery is attached or detached */ clear_ccnt (info, &ccnt_data);return IRQ_HANDLED ; }
@@ -566,7 +566,7 @@ static int measure_temp(struct pm860x_battery_info *info, int *data) ret =measure_12bit_voltage (info,PM8607_GPADC1_MEAS1 , data);if (ret)return ret; -/* meausered Vtbat(mV) / Ibias_current(11uA)*/ +/* measured Vtbat(mV) / Ibias_current(11uA)*/ *data = (*data *1000 ) /GPBIAS2_GPADC1_UA ;if (*data >TBAT_NEG_25D ) {
drivers/power/supply/ab8500_btemp.c +1 -1
@@ -283,7 +283,7 @@ static void ab8500_btemp_periodic_work(struct work_struct *work)dev_warn (di->dev,"failed to identify the battery\n" ); } -/* Failover if a reading is erroneous, use last meausurement */ +/* Failover if a reading is erroneous, use last measurement */ ret =thermal_zone_get_temp (di->tz, &bat_temp);if (ret) {dev_err (di->dev,"error reading temperature\n" );
drivers/power/supply/charger-manager.c +1 -1
@@ -221,7 +221,7 @@ static bool is_charging(struct charger_manager *cm)/* If at least one of the charger is charging, return yes */ for (i =0 ; cm->desc->psy_charger_stat[i]; i++) { -/* 1. The charger sholuld not be DISABLED */ +/* 1. The charger should not be DISABLED */ if (cm->emergency_stop)continue ;if (!cm->charger_enabled)
drivers/power/supply/da9030_battery.c +2 -2
@@ -269,7 +269,7 @@ static void da9030_charger_check_state(struct da9030_charger *charger) }if (charger->adc.vchmax_res > charger->thresholds.vcharge_max || charger->adc.vchmin_res < charger->thresholds.vcharge_min || -/* Tempreture readings are negative */ +/* Temperature readings are negative */ charger->adc.tbat_res < charger->thresholds.tbat_high || charger->adc.tbat_res > charger->thresholds.tbat_low) {/* disable charger */
@@ -470,7 +470,7 @@ static int da9030_battery_charger_init(struct da9030_charger *charger)if (ret)return ret; -/* enable auto ADC measuremnts */ +/* enable auto ADC measurements */ return da903x_write(charger->master, DA9030_ADC_AUTO_CONTROL, DA9030_ADC_TBAT_ENABLE | DA9030_ADC_VBAT_IN_TXON | DA9030_ADC_VCH_ENABLE | DA9030_ADC_ICH_ENABLE |
drivers/power/supply/max8925_power.c +1 -1
@@ -73,7 +73,7 @@ struct max8925_power_info { unsigned usb_online:1; unsigned bat_online:1; unsigned chg_mode:2; - unsigned batt_detect:1; /* detecing MB by ID pin */ + unsigned batt_detect:1; /* detecting MB by ID pin */ unsigned topoff_threshold:2; unsigned fast_charge:3; unsigned no_temp_support:1;
drivers/power/supply/qcom_battmgr.c +1 -1
@@ -153,7 +153,7 @@ struct qcom_battmgr_message {__le32 capacity_low;__le32 capacity_warning;__le32 cycle_count; -/* thousandth of persent */ +/* thousandth of percent */ __le32 accuracy;__le32 max_sample_time_ms;__le32 min_sample_time_ms;
drivers/power/supply/qcom_smbx.c +1 -1
@@ -837,7 +837,7 @@ static const struct smb_init_register smb_init_seq[] = {AUTO_RECHG_BIT |EN_ANALOG_DROP_IN_VBATT_BIT | CHARGER_INHIBIT_BIT, .val = CHARGER_INHIBIT_BIT }, - /* STAT pin software override, match downstream. Parallell charging? */ + /* STAT pin software override, match downstream. Parallel charging? */ { .addr = STAT_CFG, .mask = STAT_SW_OVERRIDE_CFG_BIT, .val = STAT_SW_OVERRIDE_CFG_BIT },
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 376/816 power: supply: qcom_smbx: set the charge enable after software control
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fabricio Akio <[email protected]>
[ Upstream commit 1fba787142011145e1071cee9448b3677fb2323d ]
The init sequence sets CHARGING_ENABLE_CMD before CHGR_CFG2 selects software control of the charge enable.
The Motorola Moto X4's bootloader leaves the charger watchdog armed to disable charging when it bites, which it does after a few minutes in fastboot. Charging then stays disabled in the next boot until the cable is replugged. Setting the command after CHGR_CFG2 re-enables it.
--- drivers/power/supply/qcom_smbx.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/power/supply/qcom_smbx.c +7 -4
@@ -812,11 +812,7 @@ static const struct smb_init_register smb_init_seq[] = { .mask = SOC_LT_CHG_RECHARGE_THRESH_SEL_BIT | VBT_LT_CHG_RECHARGE_THRESH_SEL_BIT, .val = VBT_LT_CHG_RECHARGE_THRESH_SEL_BIT }, -/* Enable charging */ { .addr = USBIN_OPTIONS_1_CFG, .mask = HVDCP_EN_BIT, .val = 0 }, - { .addr = CHARGING_ENABLE_CMD, - .mask = CHARGING_ENABLE_CMD_BIT, - .val = CHARGING_ENABLE_CMD_BIT },/* * Match downstream defaults * CHG_EN_SRC_BIT - charger enable is controlled by software
@@ -837,6 +833,13 @@ static const struct smb_init_register smb_init_seq[] = { AUTO_RECHG_BIT | EN_ANALOG_DROP_IN_VBATT_BIT | CHARGER_INHIBIT_BIT, .val = CHARGER_INHIBIT_BIT }, +/* +* Set the enable command only once CHGR_CFG2 has selected software +* control, or a charger its watchdog has disabled stays disabled. +*/ + { .addr = CHARGING_ENABLE_CMD, + .mask = CHARGING_ENABLE_CMD_BIT, + .val = CHARGING_ENABLE_CMD_BIT }, /* STAT pin software override, match downstream. Parallel charging? */ { .addr = STAT_CFG, .mask = STAT_SW_OVERRIDE_CFG_BIT,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 377/816 ALSA: ua101: Bound packet copies by the PCM buffer size
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sinan Turunc <[email protected]>
[ Upstream commit 493a77a9f20fca07ca5654f61c1b03bef035df25 ]
copy_capture_data() and copy_playback_data() wrap the ring buffer position once and split the memcpy() in two at the buffer end, which is only correct when one packet holds at most buffer_size frames. The capture packet size is the device's (actual_length up to wMaxPacketSize, divided by 3 * bNrChannels from its own descriptor), the playback packet size is taken from the capture packets, and set_stream_hw() lets the PCM client pick period_bytes_min 1, periods_min 2 and a period time of 1.5 packet intervals: 9 frames at 44.1 kHz high speed, an 18-frame buffer. A device sending 672-byte mono 24-bit packets delivers 224 frames per packet.
After the first packet buffer_pos is 206 and stays beyond buffer_size. On the next packet frames1 = buffer_size - buffer_pos wraps and memcpy() runs away:
snd-ua101 2-1:1.0: invalid position: , pos = 206, buffer size = 18,
period size = 9
BUG: KASAN: slab-out-of-bounds in capture_urb_complete+0x9eb/0xcb0 Read of size 4294966732 at addr ffff88800d73e7e0 by task vhci_rx/81
and for playback:
BUG: KASAN: vmalloc-out-of-bounds in playback_work+0x789/0xac0 Read of size 4294966732 at addr ffffc9000002626a by task kworker/0:1H/80
Clamp the capture copy to buffer_size. On playback, copy at most one buffer and fill the rest of the packet with silence, so the URB length, the delay accounting and the data sent stay consistent. With that bound the single wrap and both memcpy() halves stay inside the buffer. A device whose packets do not fit the buffer never played correctly anyway.
Reproduced on 7.3-rc7 with a USB/IP device presenting the UA-101 interface layout and a 672-byte isochronous endpoint.
--- sound/usb/misc/ua101.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-)
sound/usb/misc/ua101.c +26 -3
@@ -285,13 +285,29 @@ static void playback_work(struct work_struct *work)/* fill packet with data or silence */ urb->urb.iso_frame_desc[0 ].length = frames * ua->playback.frame_bytes; -if (test_bit (ALSA_PLAYBACK_RUNNING , &ua->states)) +if (test_bit (ALSA_PLAYBACK_RUNNING , &ua->states)) { +/* +* The packet size comes from the capture stream, +* i.e. from the device, while the ring buffer can +* be as small as two tiny periods. The single wrap +* in copy_playback_data() is only valid for +* frames <= buffer_size, so copy at most one +* buffer and send silence for the rest. +*/ +unsigned int copy_frames =min (frames, + ua->playback.substream->runtime->buffer_size); + do_period_elapsed |=copy_playback_data (&ua->playback, &urb->urb, - frames); -else + copy_frames); +memset (urb->urb.transfer_buffer + + copy_frames * ua->playback.frame_bytes,0 , + (frames - copy_frames) * + ua->playback.frame_bytes); + }else {memset (urb->urb.transfer_buffer,0 , urb->urb.iso_frame_desc[0 ].length); + }/* and off you go ... */ err =usb_submit_urb (&urb->urb,GFP_ATOMIC );
@@ -320,6 +336,13 @@ static bool copy_capture_data(struct ua101_stream *stream, struct urb *urb, runtime = stream->substream->runtime; frame_bytes = stream->frame_bytes; +/* +* A packet can carry up to max_packet_bytes, the device's +* wMaxPacketSize, which may exceed the whole ring buffer; keep what +* fits so the single wrap below stays valid. +*/ +if (unlikely (frames > runtime->buffer_size)) + frames = runtime->buffer_size; dest = runtime->dma_area + stream->buffer_pos * frame_bytes;if (stream->buffer_pos + frames <= runtime->buffer_size) {memcpy (dest, urb->transfer_buffer, frames * frame_bytes);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 378/816 nvmet-tcp: validate the TLS handshake timeout
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yingjie Wang <[email protected]>
[ Upstream commit e3e7a85730a4b17efa1e2ff4088443c4753be683 ]
tls_handshake_timeout is writable but stored as a signed int. Multiplying the value by MSEC_PER_SEC and HZ therefore uses signed arithmetic.
With HZ=1000, setting it to 2147484 overflows both multiplications. If the handshake request is accepted and remains pending, the timer wheel treats the jiffies delay as already expired and queues the timeout work on its next advance, while the handshake agent was given about 24.9 days. Negative values such as -1 cause the same immediate kernel-side timeout.
Store the parameter as an unsigned int and reject values that cannot be represented both by tls_handshake_args::ta_timeout_ms and by a safe jiffies delay. Take one snapshot so a concurrent parameter update cannot give the handshake agent and delayed work different timeouts. Document the accepted range for built-in use.
Negative and oversized values now fail with -EINVAL. Keep zero valid, preserving the existing immediate-timeout behavior.
--- .../admin-guide/kernel-parameters.txt | 5 ++++ drivers/nvme/target/tcp.c | 26 ++++++++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +5 -0
@@ -4219,6 +4219,11 @@ Valid values range from 0 to the smaller of UINT_MAX / 1000 and MAX_JIFFY_OFFSET / HZ. Default: 10 + nvmet_tcp.tls_handshake_timeout= + [NVME] NVMe/TCP target TLS handshake timeout in seconds. + Valid values range from 0 to the smaller of + UINT_MAX / 1000 and MAX_JIFFY_OFFSET / HZ. Default: 10 + ohci1394_dma=early [HW,EARLY] enable debugging via the ohci1394 driver. See Documentation/core-api/debugging-via-ohci1394.rst for more info.
drivers/nvme/target/tcp.c +22 -4
@@ -6,6 +6,7 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt#include <linux/module.h> #include <linux/init.h> +#include <linux/jiffies.h> #include <linux/slab.h> #include <linux/err.h> #include <linux/key.h>
@@ -77,8 +78,24 @@ MODULE_PARM_DESC(idle_poll_period_usecs,/* * TLS handshake timeout */ -static int tls_handshake_timeout =10 ; -module_param (tls_handshake_timeout, int,0644 ); +static unsigned int tls_handshake_timeout =10 ; + +static int tls_handshake_timeout_set (const char *val, +const struct kernel_param *kp) +{ +return param_set_uint_minmax (val, kp,0 , + min_t(unsigned long, UINT_MAX / MSEC_PER_SEC, +MAX_JIFFY_OFFSET /HZ )); +} + +static const struct kernel_param_ops tls_handshake_timeout_ops = { + .set = tls_handshake_timeout_set, + .get = param_get_uint, +}; + +module_param_cb (tls_handshake_timeout, &tls_handshake_timeout_ops, + &tls_handshake_timeout,0644 ); +__MODULE_PARM_TYPE (tls_handshake_timeout,"uint" );MODULE_PARM_DESC (tls_handshake_timeout,"nvme TLS handshake timeout in seconds (default 10)" );#endif
@@ -1948,6 +1965,7 @@ static int nvmet_tcp_tls_handshake(struct nvmet_tcp_queue *queue) {int ret = -EOPNOTSUPP ;struct tls_handshake_args args; +unsigned int timeout =READ_ONCE (tls_handshake_timeout);if (queue->state !=NVMET_TCP_Q_TLS_HANDSHAKE ) {pr_warn ("cannot start TLS in state %d\n" , queue->state);
@@ -1961,7 +1979,7 @@ static int nvmet_tcp_tls_handshake(struct nvmet_tcp_queue *queue) args.ta_done = nvmet_tcp_tls_handshake_done; args.ta_data = queue; args.ta_keyring =key_serial (queue->port->nport->keyring); - args.ta_timeout_ms = tls_handshake_timeout *1000 ; + args.ta_timeout_ms = timeout *MSEC_PER_SEC ; ret =tls_server_hello_psk (&args,GFP_KERNEL );if (ret) {
@@ -1969,7 +1987,7 @@ static int nvmet_tcp_tls_handshake(struct nvmet_tcp_queue *queue)pr_err ("failed to start TLS, err=%d\n" , ret); }else {queue_delayed_work (nvmet_wq, &queue->tls_handshake_tmo_work, - tls_handshake_timeout *HZ ); + (unsigned long )timeout *HZ ); }return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 379/816 drm/i915/psr: Disable linked plane sel fetch as well
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jouni Högander <[email protected]>
[ Upstream commit b56721c32eb3ad0f086fdc0f33479be395e43bb9 ]
Currently we are not setting linked plane selective area when selective fetch is about to be disabled for the UV plane. Fix this by simplifying the loop by just handling plane selective fetch disable and area setting same way.
Also set the update_planes bit based on comparing old and new plane selective fetch area. This way both the plane and its linked Y plane are updated only when their selective fetch area changed.
--- drivers/gpu/drm/i915/display/intel_psr.c | 27 ++++++++++++------------ 1 file changed, 13 insertions(+), 14 deletions(-)
drivers/gpu/drm/i915/display/intel_psr.c +13 -14
@@ -2724,21 +2724,14 @@ int intel_psr2_sel_fetch_update(struct intel_atomic_state *state, inter = crtc_state->psr2_su_area; sel_fetch_area = &new_plane_state->psr2_sel_fetch_area; -if (!drm_rect_intersect (&inter, &new_plane_state->uapi.dst)) { -/* -* if plane sel fetch was previously enabled -> -* disable it -*/ -if (drm_rect_height (&old_plane_state->psr2_sel_fetch_area) >0 ) - crtc_state->update_planes |=BIT (plane->id); - -continue ; +if (drm_rect_intersect (&inter, &new_plane_state->uapi.dst)) { + sel_fetch_area->y1 = inter.y1 - new_plane_state->uapi.dst.y1; + sel_fetch_area->y2 = inter.y2 - new_plane_state->uapi.dst.y1; } - sel_fetch_area = &new_plane_state->psr2_sel_fetch_area; - sel_fetch_area->y1 = inter.y1 - new_plane_state->uapi.dst.y1; - sel_fetch_area->y2 = inter.y2 - new_plane_state->uapi.dst.y1; - crtc_state->update_planes |=BIT (plane->id); +if (!drm_rect_equals (&old_plane_state->psr2_sel_fetch_area, + sel_fetch_area)) + crtc_state->update_planes |=BIT (plane->id);/* * Sel_fetch_area is calculated for UV plane. Use
@@ -2746,16 +2739,22 @@ int intel_psr2_sel_fetch_update(struct intel_atomic_state *state,*/ if (linked) {struct intel_plane_state *linked_new_plane_state; +struct intel_plane_state *linked_old_plane_state;struct drm_rect *linked_sel_fetch_area; linked_new_plane_state =intel_atomic_get_new_plane_state (state, linked);if (!linked_new_plane_state)return -EINVAL ; + linked_old_plane_state =intel_atomic_get_old_plane_state (state, linked); + linked_sel_fetch_area = &linked_new_plane_state->psr2_sel_fetch_area; linked_sel_fetch_area->y1 = sel_fetch_area->y1; linked_sel_fetch_area->y2 = sel_fetch_area->y2; - crtc_state->update_planes |=BIT (linked->id); + +if (!drm_rect_equals (&linked_old_plane_state->psr2_sel_fetch_area, + linked_sel_fetch_area)) + crtc_state->update_planes |=BIT (linked->id); } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 380/816 xfs: refuse a pNFS LAYOUTCOMMIT of a range without blocks
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daejun Park <[email protected]>
[ Upstream commit bcf0b7f18ad11e1d410e82ffef678705eff0a317 ]
A client can commit a hole in a LAYOUTCOMMIT, because nfsd does not check the extents against its layouts. xfs_iomap_write_unwritten() then allocates written blocks there. A large hole overruns the block reservation and shuts XFS down. A small one exposes stale data.
Refuse such a range with -EIO, using XFS_BMAPI_CONVERT_ONLY.
--- fs/xfs/xfs_aops.c | 2 +- fs/xfs/xfs_file.c | 2 +- fs/xfs/xfs_iomap.c | 20 +++++++++++++++++--- fs/xfs/xfs_iomap.h | 3 ++- fs/xfs/xfs_pnfs.c | 9 ++++++++- 5 files changed, 29 insertions(+), 7 deletions(-)
fs/xfs/xfs_aops.c +1 -1
@@ -129,7 +129,7 @@ xfs_end_ioend(if (ioend->io_flags &IOMAP_F_SHARED ) error =xfs_reflink_end_cow (ip, offset, size);else if (ioend->io_type ==IOMAP_UNWRITTEN ) - error =xfs_iomap_write_unwritten (ip, offset, size, false); + error =xfs_iomap_write_unwritten (ip, offset, size, false,0 );if (!error &&xfs_ioend_is_append (ioend)) error =xfs_setfilesize (ip, ioend->io_offset, ioend->io_size);
fs/xfs/xfs_file.c +1 -1
@@ -539,7 +539,7 @@ xfs_dio_write_end_io(* they are converted. */ if (flags &IOMAP_DIO_UNWRITTEN ) { - error =xfs_iomap_write_unwritten (ip, offset, size, true); + error =xfs_iomap_write_unwritten (ip, offset, size, true,0 ); goto out; }
fs/xfs/xfs_iomap.c +17 -3
@@ -571,7 +571,8 @@ xfs_iomap_write_unwritten(xfs_inode_t *ip, xfs_off_t offset, xfs_off_t count, - bool update_isize) + bool update_isize, + uint32_t bmapi_flags) { xfs_mount_t *mp = ip->i_mount;xfs_fileoff_t offset_fsb;
@@ -633,8 +634,21 @@ xfs_iomap_write_unwritten(*/ nimaps =1 ; error =xfs_bmapi_write (tp, ip, offset_fsb, count_fsb, -XFS_BMAPI_CONVERT , resblks, &imap, - &nimaps); +XFS_BMAPI_CONVERT | bmapi_flags, + resblks, &imap, &nimaps); +if (error == -ENOSR && (bmapi_flags &XFS_BMAPI_CONVERT_ONLY )) { +/* +* Nothing was mapped: the rest of the range starts +* with a hole or a delalloc extent. Nothing was +* changed either, but xfs_iext_count_extend() may +* have logged the inode, and cancelling a dirty +* transaction shuts the filesystem down. Commit it, +* as xfs_alloc_file_space() does on -ENOSR. +*/ + error =xfs_trans_commit (tp); +xfs_iunlock (ip,XFS_ILOCK_EXCL ); +return error ? error : -EIO ; + }if (error) goto error_on_bmapi_transaction;
fs/xfs/xfs_iomap.h +2 -1
@@ -14,7 +14,8 @@ struct xfs_bmbt_irec;int xfs_iomap_write_direct (struct xfs_inode *ip,xfs_fileoff_t offset_fsb,xfs_fileoff_t count_fsb,unsigned int flags,struct xfs_bmbt_irec *imap,u64 *sequence); -int xfs_iomap_write_unwritten (struct xfs_inode *,xfs_off_t ,xfs_off_t ,bool ); +int xfs_iomap_write_unwritten (struct xfs_inode *ip,xfs_off_t offset, +xfs_off_t count,bool update_isize,uint32_t bmapi_flags);xfs_fileoff_t xfs_iomap_eof_align_last_fsb (struct xfs_inode *ip,xfs_fileoff_t end_fsb);
fs/xfs/xfs_pnfs.c +8 -1
@@ -315,7 +315,14 @@ xfs_fs_commit_blocks( (end - 1) >> PAGE_SHIFT);WARN_ON_ONCE (error); - error =xfs_iomap_write_unwritten (ip, start, length, false); +/* +* A client may only write to blocks that a layout handed out, +* and xfs_fs_map_blocks() allocates blocks for any hole in a +* write layout, so refuse to allocate blocks for a hole or a +* delalloc extent in the committed range. +*/ + error =xfs_iomap_write_unwritten (ip, start, length, false, +XFS_BMAPI_CONVERT_ONLY );if (error) goto out_drop_iolock; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 381/816 can: skb: make echo skb freeing safe in any IRQ context
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cunhao Lu <[email protected]>
[ Upstream commit d743071964920c92af598c87a9e6f4369263ee09 ]
can_put_echo_skb() can be called with hardware interrupts disabled. Its direct drop paths use kfree_skb(), while can_create_echo_skb() uses kfree_skb() when cloning fails and consume_skb() after a successful clone. None of these helpers is safe in every IRQ context.
Use dev_kfree_skb_any() for all drop paths and dev_consume_skb_any() when consuming a successfully cloned skb. This preserves the respective skb drop and consumed semantics regardless of the caller IRQ context.
--- drivers/net/can/dev/skb.c | 6 +++--- include/linux/can/dev.h | 2 +- include/linux/can/skb.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-)
drivers/net/can/dev/skb.c +3 -3
@@ -61,7 +61,7 @@ int can_put_echo_skb(struct sk_buff *skb, struct net_device *dev, (skb->protocol != htons(ETH_P_CAN) && skb->protocol != htons(ETH_P_CANFD) && skb->protocol != htons(ETH_P_CANXL))) { -kfree_skb (skb); +dev_kfree_skb_any (skb);return 0 ; }
@@ -87,7 +87,7 @@ int can_put_echo_skb(struct sk_buff *skb, struct net_device *dev, }else {/* locking problem with netif_stop_queue() ?? */ netdev_err (dev,"%s: BUG! echo_skb %d is occupied!\n" , __func__, idx); -kfree_skb (skb); +dev_kfree_skb_any (skb);return -EBUSY ; }
@@ -368,7 +368,7 @@ bool can_dropped_invalid_skb(struct net_device *dev, struct sk_buff *skb)return false; inval_skb: -kfree_skb (skb); +dev_kfree_skb_any (skb); dev->stats.tx_dropped++;return true; }
include/linux/can/dev.h +1 -1
@@ -160,7 +160,7 @@ static inline bool can_dev_dropped_skb(struct net_device *dev, struct sk_buff *sif (priv->ctrlmode &CAN_CTRLMODE_LISTENONLY ) {netdev_info_once (dev,"interface in listen only mode, dropping skb\n" ); -kfree_skb (skb); +dev_kfree_skb_any (skb); dev->stats.tx_dropped++;return true; }
include/linux/can/skb.h +2 -2
@@ -92,12 +92,12 @@ static inline struct sk_buff *can_create_echo_skb(struct sk_buff *skb) nskb =skb_clone (skb,GFP_ATOMIC );if (unlikely (!nskb)) { -kfree_skb (skb); +dev_kfree_skb_any (skb);return NULL ; }can_skb_set_owner (nskb, skb->sk); -consume_skb (skb); +dev_consume_skb_any (skb);return nskb; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 382/816 mm/userfaultfd: wake all waiters on unregister
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 3afb19d68cc5e7851fdb1069c8094af97bd80417 ]
UFFDIO_UNREGISTER only wakes pending faults if VM_UFFD_MISSING is set. Threads waiting on write-protect, minor or RWP faults can therefore remain asleep after unregistering a range that does not track missing faults.
Wake pending faults regardless of the registration mode so they can retry without an explicit UFFDIO_WAKE or closing the userfaultfd. This matches the existing behavior for missing faults, including removing unread fault messages for the woken waiters.
Fix generated by an LLM and sent by Josef Bacik in private.
--- fs/userfaultfd.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)
fs/userfaultfd.c +10 -12
@@ -1491,6 +1491,8 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx, ret =0 ;for_each_vma_range (vmi, vma, end) { +struct userfaultfd_wake_range range; +cond_resched ();BUG_ON (!vma_can_userfault (vma, vma->vm_flags, wp_async));
@@ -1511,18 +1513,14 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx,/* Prevent new userfaults from being queued after the wakeup. */ vma_start_write (vma); -if (userfaultfd_missing (vma)) { -/* -* Wake any concurrent pending userfault while -* we unregister, so they will not hang -* permanently and it avoids userland to call -* UFFDIO_WAKE explicitly. -*/ -struct userfaultfd_wake_range range; - range.start = start; - range.len = vma_end - start; -wake_userfault (vma->vm_userfaultfd_ctx.ctx, &range); - } +/* +* Wake any concurrent pending userfault while we unregister, +* so they will not hang permanently and it avoids userland to +* call UFFDIO_WAKE explicitly. +*/ + range.start = start; + range.len = vma_end - start; +wake_userfault (vma->vm_userfaultfd_ctx.ctx, &range); vma =userfaultfd_clear_vma (&vmi, prev, vma, start, vma_end);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 383/816 ALSA: hda/realtek: Enable mute and mic-mute LEDs on HP ENVY 17-cr0xxx
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexandr <[email protected]>
[ Upstream commit cf79cc4996bf936fe159af2a600519b3ebd4ccb7 ]
The HP ENVY Laptop 17-cr0xxx (subsystem ID 103c:8a2e) has mute and mic-mute LEDs on the F8 and F5 keys that never light up on Linux: the existing quirk entry only sets up the CS35L41 amplifiers.
The board uses the same LED wiring as the HP ENVY x360 15-ey0xxx (103c:8a31): the mute LED is driven by COEF 0x0b bits 3:2 and the mic-mute LED by GPIO2 with inverted polarity. Both were verified with hda-verb on the actual hardware. Switch the entry to ALC287_FIXUP_CS35L41_I2C_2_HP_MUTE_LEDS, which chains the amplifier setup with ALC245_FIXUP_HP_X360_MUTE_LEDS, and use the DMI product name of the board.
--- sound/pci/hda/patch_realtek.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/pci/hda/patch_realtek.c +1 -1
@@ -11089,7 +11089,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = {SND_PCI_QUIRK (0x103c ,0x8a2b ,"HP Envy 15" ,ALC287_FIXUP_CS35L41_I2C_2 ),SND_PCI_QUIRK (0x103c ,0x8a2c ,"HP Envy 16" ,ALC287_FIXUP_CS35L41_I2C_2 ),SND_PCI_QUIRK (0x103c ,0x8a2d ,"HP Envy 16" ,ALC287_FIXUP_CS35L41_I2C_2 ), -SND_PCI_QUIRK (0x103c ,0x8a2e ,"HP Envy 16" ,ALC287_FIXUP_CS35L41_I2C_2 ), +SND_PCI_QUIRK (0x103c ,0x8a2e ,"HP ENVY Laptop 17-cr0xxx" ,ALC287_FIXUP_CS35L41_I2C_2_HP_MUTE_LEDS ),SND_PCI_QUIRK (0x103c ,0x8a30 ,"HP Envy 17" ,ALC287_FIXUP_CS35L41_I2C_2 ),SND_PCI_QUIRK (0x103c ,0x8a31 ,"HP Envy 15" ,ALC287_FIXUP_CS35L41_I2C_2 ), SND_PCI_QUIRK(0x103c, 0x8a4f, "HP Victus 15-fa0xxx (MB 8A4F)", ALC245_FIXUP_HP_MUTE_LED_COEFBIT),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 384/816 mm/page_alloc: avoid direct reclaim and compaction for costly __GFP_NORETRY allocations
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Salvatore Dipietro <[email protected]>
[ Upstream commit 0e05a469c29400eb6e35448ce7318581688a1806 ]
Commit 5d8edfb900d5 ("iomap: Copy larger chunks from userspace") introduced high-order folio allocations in the iomap buffered write path. When memory is fragmented, each failed costly-order allocation enters __alloc_pages_slowpath() which runs direct reclaim, direct compaction and drain_all_pages(), causing a 0.38x throughput drop on PostgreSQL pgbench (simple-update) with 1024 clients on a 96-vCPU arm64 system.
The root issue is that direct reclaim and direct compaction are too expensive for hot allocation paths that have fallbacks to smaller allocations. __filemap_get_folio_mpol() already marks higher-order allocations with __GFP_NORETRY | __GFP_NOWARN, signalling that the caller can handle failure. However, the page allocator still enters the full blocking slowpath for costly orders with __GFP_NORETRY, which is unnecessarily aggressive when the caller will simply retry at a lower order.
For costly-order allocations with __GFP_NORETRY, clear __GFP_DIRECT_RECLAIM at the very start of the slowpath, before can_direct_reclaim, can_compact and the nofail checks are evaluated. This makes the entire slowpath treat the request as non-blocking: no direct reclaim, no direct compaction and no drain_all_pages() IPI across every CPU. Reclaim and compaction move to the background instead: kswapd is still woken for reclaim, and it wakes kcompactd for defragmentation. The system keeps its long-term health while the latency-critical direct allocation path no longer stalls.
Allocations that also request __GFP_THISNODE are exempted. That flag pairing identifies the local-node-first THP attempt issued by alloc_pages_mpol() (mempolicy.c), which relies on direct compaction to form transparent huge pages.
Clearing __GFP_DIRECT_RECLAIM makes these allocations reach the !can_direct_reclaim bailout, which since commit 4c0ed883e051 ("mm/page_alloc: fix defrag_mode for non-reclaimable allocations") drops ALLOC_NOFRAGMENT and retries instead of failing when defrag_mode is on. With vm.defrag_mode=1 a __GFP_NORETRY allocation could therefore succeed by fragmenting another migratetype's pageblock. That is the wrong trade for a caller that has already communicated it can handle failure and has a cheap lower-order fallback, so exclude __GFP_NORETRY from the relaxation. The exclusion is not restricted to costly orders: any __GFP_NORETRY caller has said it can cope with failure, so failing is preferable to fragmenting for all of them.
Test environment:
Hardware: AWS EC2 m8g.24xlarge (96 vCPU, arm64)
12x 1TB IO2 32000 IOPS RAID0 XFS OS: AL2023 Kernel: v7.3-rc1 Database: PostgreSQL 18.4 Workload: pgbench simple-update, 1024 clients, 96 threads, 1200s
Results (average of 3 runs, TPS):
Config Avg TPS % vs baseline
v7.3-rc1 baseline (vm.defrag_mode=0) 58,602 -
v7.3-rc1 + this patch (vm.defrag_mode=0) 157,246 +168.3% v7.3-rc1 baseline (vm.defrag_mode=1) 109,012 - v7.3-rc1 + this patch (vm.defrag_mode=1) 157,778 +44.7%
introduced high-order folio allocations in the iomap buffered write path. When memory is fragmented, each failed costly-order allocation enters __alloc_pages_slowpath() which runs direct reclaim, direct compaction and drain_all_pages(), causing a 0.38x throughput drop on PostgreSQL pgbench (simple-update) with 1024 clients on a 96-vCPU arm64 system.
The root issue is that direct reclaim and direct compaction are too expensive for hot allocation paths that have fallbacks to smaller allocations. __filemap_get_folio_mpol() already marks higher-order allocations with __GFP_NORETRY | __GFP_NOWARN, signalling that the caller can handle failure. However, the page allocator still enters the full blocking slowpath for costly orders with __GFP_NORETRY, which is unnecessarily aggressive when the caller will simply retry at a lower order.
For costly-order allocations with __GFP_NORETRY, clear __GFP_DIRECT_RECLAIM at the very start of the slowpath, before can_direct_reclaim, can_compact and the nofail checks are evaluated. This makes the entire slowpath treat the request as non-blocking: no direct reclaim, no direct compaction and no drain_all_pages() IPI across every CPU. Reclaim and compaction move to the background instead: kswapd is still woken for reclaim, and it wakes kcompactd for defragmentation. The system keeps its long-term health while the latency-critical direct allocation path no longer stalls.
Allocations that also request __GFP_THISNODE are exempted. That flag pairing identifies the local-node-first THP attempt issued by alloc_pages_mpol() (mempolicy.c), which relies on direct compaction to form transparent huge pages.
Clearing __GFP_DIRECT_RECLAIM makes these allocations reach the !can_direct_reclaim bailout, which since commit 4c0ed883e051 ("mm/page_alloc: fix defrag_mode for non-reclaimable allocations") drops ALLOC_NOFRAGMENT and retries instead of failing when defrag_mode is on. With vm.defrag_mode=1 a __GFP_NORETRY allocation could therefore succeed by fragmenting another migratetype's pageblock. That is the wrong trade for a caller that has already communicated it can handle failure and has a cheap lower-order fallback, so exclude __GFP_NORETRY from the relaxation.
--- mm/page_alloc.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
mm/page_alloc.c +15 -3
@@ -4291,10 +4291,10 @@ static inline struct page * __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, struct alloc_context *ac) { - bool can_direct_reclaim = gfp_mask & __GFP_DIRECT_RECLAIM; -bool can_compact =gfp_compaction_allowed (gfp_mask); -bool nofail = gfp_mask & __GFP_NOFAIL; const bool costly_order = order > PAGE_ALLOC_COSTLY_ORDER; +bool can_direct_reclaim; +bool can_compact; +bool nofail;struct page *page =NULL ;unsigned int alloc_flags;unsigned long did_some_progress;
@@ -4306,6 +4306,18 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,unsigned int zonelist_iter_cookie;int reserve_flags; +/* +* Costly __GFP_NORETRY callers have a cheap fallback, so don't stall +* them in reclaim or compaction. __GFP_THISNODE callers are exempt. +*/ +if (costly_order && (gfp_mask & __GFP_NORETRY) && + !(gfp_mask & __GFP_THISNODE)) + gfp_mask &= ~__GFP_DIRECT_RECLAIM; + + can_direct_reclaim = gfp_mask & __GFP_DIRECT_RECLAIM; + can_compact =gfp_compaction_allowed (gfp_mask); + nofail = gfp_mask & __GFP_NOFAIL; +if (unlikely (nofail)) {/* * We most definitely don't want callers attempting to
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 385/816 perf evsel: Restrict incremental open error unwind
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hui Su <[email protected]>
[ Upstream commit d023b2110d0d7232ba952a486c497ba8817f6f66 ]
evsel__open_cpu(), evsel__tool_pmu_open() and evsel__hwmon_pmu_open() support opening a subrange of a CPU map, bounded by [start_cpu_map_idx, end_cpu_map_idx).
Their error paths, however, unwind using "while (--idx >= 0)" all the way back to CPU index 0 regardless of start_cpu_map_idx. If lower CPU indices were opened by an earlier invocation, a later incremental open failure therefore closes those existing file descriptors and overwrites their slots with -1.
Before this fix, running the new incremental open test demonstrates this corruption:
$ perf test -v "Tool PMU"
12: Tool PMU:
12.1: Tool PMU : Ok
12.2: Tool PMU leader : Ok
12.3: Incremental open error unwind boundary:
FAILED: CPU 0 FD overwritten: FD(evsel, 0, 0)=-1, expected 4
FAILED!Stop the unwind at start_cpu_map_idx so that only file descriptors opened by the current invocation are rolled back.
After this fix:
$ perf test -v "Tool PMU" 12: Tool PMU: 12.1: Tool PMU : Ok 12.2: Tool PMU leader : Ok 12.3: Incremental open error unwind boundary : Ok
--- tools/perf/util/evsel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/evsel.c +1 -1
@@ -2483,7 +2483,7 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus,FD (evsel, idx, thread) =-1 ; } thread = nthreads; - }while (--idx >=0 ); + }while (--idx >= start_cpu_map_idx); errno = old_errno;return err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 386/816 nvme-tcp: Validate the queue state under the queue lock in the address attribute
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guixin Liu <[email protected]>
[ Upstream commit 2eeeaa9c1ff0c429096acc2947c296db6a56f96d ]
Reading the "address" sysfs attribute calls kernel_getsockname() on the admin queue socket, which can race with the queue teardown during connection error recovery: a reader can observe NVME_TCP_Q_LIVE set, then block on the queue lock while nvme_tcp_free_queue() releases the socket and clears queue->sock without holding the lock. Once the reader acquires the lock it dereferences the NULL socket pointer.
Commit 76d54bf20cdc ("nvme-tcp: don't access released socket during error recovery") had the queue liveness check inside the lock. Commit 782373ba2766 ("nvme: tcp: avoid race between queue_lock lock and destroy") moved it back out because the lock itself is destroyed in nvme_tcp_free_queue(), so a reader arriving late trips mutex_destroy().
Check the queue liveness inside the queue lock, and clear queue->sock under the same lock. The teardown clears NVME_TCP_Q_LIVE under the lock well before the socket is released, so a reader either sees the bit cleared or a socket that cannot be released while it holds the lock. To also close the lock lifetime race, the queue locks are now owned by the controller: they are initialized with the queue array and only destroyed when the controller is freed, which cannot happen while a sysfs attribute read is still in progress. The queue count is computed by the NVME_TCP_OPT_NR_QUEUES() macro from the original connect options for both initialization and destruction, as reconnects may shrink ctrl->queue_count.
--- drivers/nvme/host/tcp.c | 53 ++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 16 deletions(-)
drivers/nvme/host/tcp.c +37 -16
@@ -155,6 +155,9 @@ enum nvme_tcp_queue_flags { NVME_TCP_Q_IO_CPU_SET = 3, }; +#define NVME_TCP_OPT_NR_QUEUES (opts) ((opts)->nr_io_queues + \ + (opts)->nr_write_queues + (opts)->nr_poll_queues + 1) +enum nvme_tcp_recv_state {NVME_TCP_RECV_PDU =0 ,NVME_TCP_RECV_DATA ,
@@ -1581,14 +1584,22 @@ static void nvme_tcp_free_queue(struct nvme_ctrl *nctrl, int qid)page_frag_cache_drain (&queue->pf_cache); noreclaim_flag =memalloc_noreclaim_save (); +/* +* Clear queue->sock under the queue lock so that a sysfs reader in +* nvme_tcp_get_address() either observes the NVME_TCP_Q_LIVE bit +* cleared or a still valid socket. The queue lock itself is owned +* by the controller and only destroyed when the controller is +* freed, so readers blocked on it cannot race its teardown. +*/ +mutex_lock (&queue->queue_lock);/* ->sock will be released by fput() */ fput (queue->sock->file); queue->sock =NULL ; +mutex_unlock (&queue->queue_lock);memalloc_noreclaim_restore (noreclaim_flag);kfree (queue->pdu);mutex_destroy (&queue->send_mutex); -mutex_destroy (&queue->queue_lock);mutex_destroy (&queue->pf_cache_lock); }
@@ -2020,7 +2031,6 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid,int ret, rcv_pdu_size;struct file *sock_file; -mutex_init (&queue->queue_lock); queue->ctrl = ctrl;init_llist_head (&queue->req_list);INIT_LIST_HEAD (&queue->send_list);
@@ -2168,7 +2178,6 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid, queue->sock =NULL ; err_destroy_mutex:mutex_destroy (&queue->send_mutex); -mutex_destroy (&queue->queue_lock);mutex_destroy (&queue->pf_cache_lock);return ret; }
@@ -2773,6 +2782,9 @@ static void nvme_tcp_stop_ctrl(struct nvme_ctrl *ctrl)static void nvme_tcp_free_ctrl (struct nvme_ctrl *nctrl) {struct nvme_tcp_ctrl *ctrl =to_tcp_ctrl (nctrl); +/* the same count used to size and initialize the queue array */ +unsigned int nr_queues =NVME_TCP_OPT_NR_QUEUES (nctrl->opts); +unsigned int i;if (list_empty (&ctrl->list)) goto free_ctrl;
@@ -2784,6 +2796,8 @@ static void nvme_tcp_free_ctrl(struct nvme_ctrl *nctrl)nvmf_free_options (nctrl->opts); free_ctrl:put_net (ctrl->net); +for (i =0 ; i < nr_queues; i++) +mutex_destroy (&ctrl->queues[i].queue_lock);kfree (ctrl->queues);kfree (ctrl); }
@@ -3036,17 +3050,18 @@ static int nvme_tcp_get_address(struct nvme_ctrl *ctrl, char *buf, int size) len =nvmf_get_address (ctrl, buf, size); -if (!test_bit (NVME_TCP_Q_LIVE , &queue->flags)) -return len; -mutex_lock (&queue->queue_lock); - ret =kernel_getsockname (queue->sock, (struct sockaddr *)&src_addr); -if (ret >0 ) { -if (len >0 ) - len--;/* strip trailing newline */ - len +=scnprintf (buf + len, size - len,"%ssrc_addr=%pISc\n" , - (len) ?"," :"" , &src_addr); +if (test_bit (NVME_TCP_Q_LIVE , &queue->flags)) { + ret =kernel_getsockname (queue->sock, + (struct sockaddr *)&src_addr); +if (ret >0 ) { +if (len >0 ) + len--;/* strip trailing newline */ + len +=scnprintf (buf + len, size - len, +"%ssrc_addr=%pISc\n" , + (len) ?"," :"" , &src_addr); + } }mutex_unlock (&queue->queue_lock);
@@ -3111,7 +3126,7 @@ static struct nvme_tcp_ctrl *nvme_tcp_alloc_ctrl(struct device *dev, struct nvmf_ctrl_options *opts) {struct nvme_tcp_ctrl *ctrl; -int ret; +int i, ret; ctrl =kzalloc (sizeof (*ctrl),GFP_KERNEL );if (!ctrl)
@@ -3119,8 +3134,7 @@ static struct nvme_tcp_ctrl *nvme_tcp_alloc_ctrl(struct device *dev,INIT_LIST_HEAD (&ctrl->list); ctrl->ctrl.opts = opts; - ctrl->ctrl.queue_count = opts->nr_io_queues + opts->nr_write_queues + - opts->nr_poll_queues +1 ; + ctrl->ctrl.queue_count =NVME_TCP_OPT_NR_QUEUES (opts); ctrl->ctrl.sqsize = opts->queue_size -1 ; ctrl->ctrl.kato = opts->kato;
@@ -3179,8 +3193,15 @@ static struct nvme_tcp_ctrl *nvme_tcp_alloc_ctrl(struct device *dev, goto out_free_ctrl; } - ctrl->net =get_net (current->nsproxy->net_ns); +/* +* The queue locks are owned by the controller, not the queues: +* they outlive the per-queue connect/disconnect cycles so that +* sysfs readers can never race their destruction. +*/ +for (i =0 ; i < ctrl->ctrl.queue_count; i++) +mutex_init (&ctrl->queues[i].queue_lock); + ctrl->net =get_net (current->nsproxy->net_ns); ret =nvme_init_ctrl (&ctrl->ctrl, dev, &nvme_tcp_ctrl_ops,0 );if (ret) goto out_kfree_queues;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 387/816 nvme-tcp: fix use-after-free in nvme_tcp_free_ctrl()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Aurich Zanettini Martins <[email protected]>
[ Upstream commit b1d1f6b1ee03285690f12c2ebf23616416e6d881 ]
nvme_tcp_free_ctrl() reads ctrl->ctrl.opts to know how many queue mutexes to destroy. When creating the controller fails, nvmf_create_ctrl() frees opts as soon as nvme_tcp_create_ctrl() returns, but a concurrent open of the character device can hold the last reference to the controller. With CONFIG_DEBUG_KOBJECT_RELEASE, which delays the release, every failed connect reads freed memory:
BUG: KASAN: slab-use-after-free in nvme_tcp_free_ctrl+0x38b/0x430 Read of size 4 at addr ffff888005b93740 by task kworker/2:1/51
Keep the size of the queue array in the controller and use it instead.
--- drivers/nvme/host/tcp.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/nvme/host/tcp.c +5 -5
@@ -225,6 +225,7 @@ struct nvme_tcp_ctrl {struct delayed_work connect_work;struct nvme_tcp_request async_req;u32 io_queues[HCTX_MAX_TYPES ]; +unsigned int nr_allocated_queues;struct net *net; };
@@ -2782,8 +2783,6 @@ static void nvme_tcp_stop_ctrl(struct nvme_ctrl *ctrl)static void nvme_tcp_free_ctrl (struct nvme_ctrl *nctrl) {struct nvme_tcp_ctrl *ctrl =to_tcp_ctrl (nctrl); -/* the same count used to size and initialize the queue array */ -unsigned int nr_queues =NVME_TCP_OPT_NR_QUEUES (nctrl->opts);unsigned int i;if (list_empty (&ctrl->list))
@@ -2796,7 +2795,7 @@ static void nvme_tcp_free_ctrl(struct nvme_ctrl *nctrl)nvmf_free_options (nctrl->opts); free_ctrl:put_net (ctrl->net); -for (i =0 ; i < nr_queues; i++) +for (i =0 ; i < ctrl->nr_allocated_queues; i++)mutex_destroy (&ctrl->queues[i].queue_lock);kfree (ctrl->queues);kfree (ctrl);
@@ -3186,7 +3185,8 @@ static struct nvme_tcp_ctrl *nvme_tcp_alloc_ctrl(struct device *dev, goto out_free_ctrl; } - ctrl->queues =kcalloc (ctrl->ctrl.queue_count,sizeof (*ctrl->queues), + ctrl->nr_allocated_queues = ctrl->ctrl.queue_count; + ctrl->queues =kcalloc (ctrl->nr_allocated_queues,sizeof (*ctrl->queues),GFP_KERNEL );if (!ctrl->queues) { ret = -ENOMEM ;
@@ -3198,7 +3198,7 @@ static struct nvme_tcp_ctrl *nvme_tcp_alloc_ctrl(struct device *dev,* they outlive the per-queue connect/disconnect cycles so that * sysfs readers can never race their destruction. */ -for (i =0 ; i < ctrl->ctrl.queue_count; i++) +for (i =0 ; i < ctrl->nr_allocated_queues; i++)mutex_init (&ctrl->queues[i].queue_lock); ctrl->net =get_net (current->nsproxy->net_ns);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 388/816 drm/panthor: Revisit reqs_lock handling in flush/reset paths
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicolas Frattaroli <[email protected]>
[ Upstream commit 4fd08b3d1da78e33cb5939f0086e61f9d660cd6c ]
panthor_gpu_flush_caches() and panthor_gpu_soft_reset() acquire their reqs_lock spinlock with the IRQ-disabling variants of the spinlocking functions. This isn't necessary, as the lock is never taken from an atomic context, as Panthor uses threaded interrupt handlers. The result of this overly strict locking is that IRQs may be disabled more frequently and for longer than they should be, resulting in increased system latency.
Switch the locking to use non-IRQ-disabling scoped_guard statements for locking. The wait_event_timeout read of pending_reqs outside of the spinlock is fine as wait_event_timeout is a memory barrier according to the Linux Memory Model.
--- drivers/gpu/drm/panthor/panthor_gpu.c | 61 ++++++++++++--------------- 1 file changed, 28 insertions(+), 33 deletions(-)
drivers/gpu/drm/panthor/panthor_gpu.c +28 -33
@@ -384,34 +384,30 @@ int panthor_gpu_l2_power_on(struct panthor_device *ptdev)int panthor_gpu_flush_caches (struct panthor_device *ptdev,u32 l2,u32 lsc,u32 other) { -unsigned long flags;int ret =0 ;/* Serialize cache flush operations. */ guard (mutex)(&ptdev->gpu->cache_flush_lock); -spin_lock_irqsave (&ptdev->gpu->reqs_lock, flags); -if (!(ptdev->gpu->pending_reqs &GPU_IRQ_CLEAN_CACHES_COMPLETED )) { - ptdev->gpu->pending_reqs |=GPU_IRQ_CLEAN_CACHES_COMPLETED ; -gpu_write (ptdev,GPU_CMD ,GPU_FLUSH_CACHES (l2, lsc, other)); - }else { - ret = -EIO ; + scoped_guard(spinlock, &ptdev->gpu->reqs_lock) { +if (!(ptdev->gpu->pending_reqs &GPU_IRQ_CLEAN_CACHES_COMPLETED )) { + ptdev->gpu->pending_reqs |=GPU_IRQ_CLEAN_CACHES_COMPLETED ; +gpu_write (ptdev,GPU_CMD ,GPU_FLUSH_CACHES (l2, lsc, other)); + }else { +return -EIO ; + } } -spin_unlock_irqrestore (&ptdev->gpu->reqs_lock, flags); - -if (ret) -return ret;if (!wait_event_timeout (ptdev->gpu->reqs_acked, !(ptdev->gpu->pending_reqs &GPU_IRQ_CLEAN_CACHES_COMPLETED ),msecs_to_jiffies (100 ))) { -spin_lock_irqsave (&ptdev->gpu->reqs_lock, flags); -if ((ptdev->gpu->pending_reqs &GPU_IRQ_CLEAN_CACHES_COMPLETED ) !=0 && - !(gpu_read (ptdev,GPU_INT_RAWSTAT ) &GPU_IRQ_CLEAN_CACHES_COMPLETED )) - ret = -ETIMEDOUT ; -else - ptdev->gpu->pending_reqs &= ~GPU_IRQ_CLEAN_CACHES_COMPLETED ; -spin_unlock_irqrestore (&ptdev->gpu->reqs_lock, flags); + scoped_guard(spinlock, &ptdev->gpu->reqs_lock) { +if ((ptdev->gpu->pending_reqs &GPU_IRQ_CLEAN_CACHES_COMPLETED ) !=0 && + !(gpu_read (ptdev,GPU_INT_RAWSTAT ) &GPU_IRQ_CLEAN_CACHES_COMPLETED )) + ret = -ETIMEDOUT ; +else + ptdev->gpu->pending_reqs &= ~GPU_IRQ_CLEAN_CACHES_COMPLETED ; + } }if (ret) {
@@ -431,27 +427,26 @@ int panthor_gpu_flush_caches(struct panthor_device *ptdev,int panthor_gpu_soft_reset (struct panthor_device *ptdev) {bool timedout = false; -unsigned long flags; -spin_lock_irqsave (&ptdev->gpu->reqs_lock, flags); -if (!drm_WARN_ON (&ptdev->base, - ptdev->gpu->pending_reqs &GPU_IRQ_RESET_COMPLETED )) { - ptdev->gpu->pending_reqs |=GPU_IRQ_RESET_COMPLETED ; -gpu_write (ptdev,GPU_INT_CLEAR ,GPU_IRQ_RESET_COMPLETED ); -gpu_write (ptdev,GPU_CMD ,GPU_SOFT_RESET ); + scoped_guard(spinlock, &ptdev->gpu->reqs_lock) { +if (!drm_WARN_ON (&ptdev->base, + ptdev->gpu->pending_reqs &GPU_IRQ_RESET_COMPLETED )) { + ptdev->gpu->pending_reqs |=GPU_IRQ_RESET_COMPLETED ; +gpu_write (ptdev,GPU_INT_CLEAR ,GPU_IRQ_RESET_COMPLETED ); +gpu_write (ptdev,GPU_CMD ,GPU_SOFT_RESET ); + } } -spin_unlock_irqrestore (&ptdev->gpu->reqs_lock, flags);if (!wait_event_timeout (ptdev->gpu->reqs_acked, !(ptdev->gpu->pending_reqs &GPU_IRQ_RESET_COMPLETED ),msecs_to_jiffies (100 ))) { -spin_lock_irqsave (&ptdev->gpu->reqs_lock, flags); -if ((ptdev->gpu->pending_reqs &GPU_IRQ_RESET_COMPLETED ) !=0 && - !(gpu_read (ptdev,GPU_INT_RAWSTAT ) &GPU_IRQ_RESET_COMPLETED )) - timedout = true; -else - ptdev->gpu->pending_reqs &= ~GPU_IRQ_RESET_COMPLETED ; -spin_unlock_irqrestore (&ptdev->gpu->reqs_lock, flags); + scoped_guard(spinlock, &ptdev->gpu->reqs_lock) { +if ((ptdev->gpu->pending_reqs &GPU_IRQ_RESET_COMPLETED ) !=0 && + !(gpu_read (ptdev,GPU_INT_RAWSTAT ) &GPU_IRQ_RESET_COMPLETED )) + timedout = true; +else + ptdev->gpu->pending_reqs &= ~GPU_IRQ_RESET_COMPLETED ; + } }if (timedout) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 389/816 cxl/test: Map mock device nodes to an online node
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Davidlohr Bueso <[email protected]>
[ Upstream commit 6f057dea152574dd044382fd0ba5ed19e3ecba25 ]
cxl_type3_mem_init() and cxl_type2_mem_init() assign alternating NUMA nodes to the mock memdevs to model multi-node topologies. On a single-node host node 1 has no pgdat, and the first node-aware allocation in an odd device's probe faults on a NULL zonelist:
Oops: general protection fault, probably for non-canonical address 0xdffffc00000006e3 KASAN: probably user-memory-access in range [0x0000000000003718-0x000000000000371f] Workqueue: async async_run_entry_fn RIP: __alloc_frozen_pages_noprof+0x288 new_slab ___slab_alloc __kmalloc_node_track_caller_noprof devm_kmalloc cxl_mock_mem_probe
Map the requested node to an online one, as dax_hmem already does for its target node.
--- tools/testing/cxl/test/cxl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/testing/cxl/test/cxl.c +3 -3
@@ -1274,7 +1274,7 @@ static int cxl_mem_init(void)if (!pdev) goto err_mem; pdev->dev.parent = &dport->dev; -set_dev_node (&pdev->dev, i %2 ); +set_dev_node (&pdev->dev,numa_map_to_online_node (i %2 )); rc =cxl_mock_platform_device_add (pdev, &cxl_mem[i]);if (rc)
@@ -1289,7 +1289,7 @@ static int cxl_mem_init(void)if (!pdev) goto err_single; pdev->dev.parent = &dport->dev; -set_dev_node (&pdev->dev, i %2 ); +set_dev_node (&pdev->dev,numa_map_to_online_node (i %2 )); rc =cxl_mock_platform_device_add (pdev, &cxl_mem_single[i]);if (rc)
@@ -1305,7 +1305,7 @@ static int cxl_mem_init(void)if (!pdev) goto err_rcd; pdev->dev.parent = &rch->dev; -set_dev_node (&pdev->dev, i %2 ); +set_dev_node (&pdev->dev,numa_map_to_online_node (i %2 )); rc =cxl_mock_platform_device_add (pdev, &cxl_rcd[i]);if (rc)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 390/816 fuse: dont bump attr_version for async direct read completion
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jingbo Xu <[email protected]>
[ Upstream commit fc60668db85584da911e5d0a65c8698628f98bba ]
The attr_version counter should only be incremented when cached attributes are actually modified (as documented in commit 1fb69e781729 ("fuse: fix race between getattr and write")). Async direct reads do not modify any cached inode attributes (size, mtime, ctime), so bumping attr_version in fuse_aio_complete() for reads is incorrect.
This unconditional bump causes a livelock when auto_inval_data is enabled together with writeback_cache: fuse_cache_read_iter() issues a FUSE_GETATTR before every read, but by the time the response arrives, an async DIO read completion has already incremented fi->attr_version past the snapshot taken before the request. The GETATTR result is then discarded (attr_version race), fi->i_time is never refreshed, and every subsequent read triggers yet another GETATTR -- creating an infinite loop of useless round-trips.
Fix this by only bumping attr_version for write completions, consistent with the synchronous DIO write path (fuse_write_update_attr) and the cached write path.
--- fs/fuse/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/fuse/file.c +1 -1
@@ -735,7 +735,7 @@ static void fuse_aio_complete(struct fuse_io_priv *io, int err, ssize_t pos)if (!left && !io->blocking) {ssize_t res =fuse_get_res_by_io (io); -if (res >=0 ) { +if (res >=0 && io->write) {struct inode *inode =file_inode (io->iocb->ki_filp);struct fuse_conn *fc =get_fuse_conn (inode);struct fuse_inode *fi =get_fuse_inode (inode);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 391/816 wifi: ath11k: fix NULL dereference in ahb remove when QMI init incomplete
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Miaoqing Pan <[email protected]>
[ Upstream commit 1a7bcf5324c8e2de6512eca5b028b6b283181d3f ]
On WCN6750, if QMI messages never arrive (for example when qrtr_smd is not ready), WLAN initialization stops before the device is fully registered. In this case ATH11K_FLAG_QMI_FAIL is not set because no QMI event handler is executed.
When the driver is removed, ath11k_ahb_remove() still calls ath11k_core_deinit(), which eventually triggers ath11k_ce_cleanup_pipes() on uninitialized CE pipes and results in a NULL pointer dereference in ath11k_hal_srng_access_begin():
ath11k_hal_srng_access_begin+0x14/0x68 [ath11k] ath11k_ce_cleanup_pipes+0x184/0x190 [ath11k] ath11k_pcic_stop+0x24/0x38 [ath11k] ath11k_core_deinit+0xfc/0x1c0 [ath11k] ath11k_ahb_remove+0x38/0xa0 [ath11k_ahb]
Fix this by invoking ath11k_ahb_remove_prepare() before the state check and skipping ath11k_core_deinit() if ATH11K_FLAG_REGISTERED is not set, core initialization did not complete and CE pipes may remain uninitialized, making ath11k_core_deinit() unsafe.
Tested-on: WCN6750 hw1.0 AHB WLAN.MSL.2.0.c2-00204-QCAMSLSWPLZ-1
--- drivers/net/wireless/ath/ath11k/ahb.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/wireless/ath/ath11k/ahb.c +3 -2
@@ -1310,14 +1310,15 @@ static void ath11k_ahb_remove(struct platform_device *pdev) {struct ath11k_base *ab =platform_get_drvdata (pdev); -if (test_bit (ATH11K_FLAG_QMI_FAIL , &ab->dev_flags)) { +ath11k_ahb_remove_prepare (ab); + +if (!test_bit (ATH11K_FLAG_REGISTERED , &ab->dev_flags)) {ath11k_ahb_power_down (ab);ath11k_debugfs_soc_destroy (ab);ath11k_qmi_deinit_service (ab); goto qmi_fail; } -ath11k_ahb_remove_prepare (ab);ath11k_core_deinit (ab); qmi_fail:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 392/816 wifi: mac80211: dont seed an S1G stas last_rate
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lachlan Hodges <[email protected]>
[ Upstream commit 00f623647c331d31df8629af958f7582a7fc874c ]
When initialising the rate control system, ieee80211_s1g_sta_rate_init() is called for S1G stations during association where it initialises a last rate of type STA_STATS_RATE_TYPE_S1G but does not initialise nss, mcs bw etc. Since the last_rate no longer has a value equivalent to STA_STATS_RATE_INVALID, the invalid rate will be decoded and the NL80211_STA_INFO_RX_BITRATE flag will be set.
As a result, there is a period during association before the first data frame is rx'ed where the seeded value is overwritten by ieee80211_rx_h_sta_process() while this invalid last_rate lives. If the sta is desroyed during this process, nl80211_put_sta_rate() will call into cfg80211_calculate_bitrate() and attempt to calculate the bitrate using the invalid last_rate leading to a WARN:
4,336,675067400,-;------------[ cut here ]------------
4,337,675067524,-;WARNING: net/wireless/util.c:1960 at cfg80211_calculate_bitrate+0x4d8/0x8b0 [cfg80211], CPU#3: kworker/u16:3/874 4,338,675068176,-;invalid rate bw=0, mcs=0, nss=0
[snip loaded modules]
4,341,675068954,-;Hardware name: BCM2711
4,342,675068961,-;Workqueue: events_unbound cfg80211_wiphy_work [cfg80211]
4,343,675069386,-;Call trace:
4,344,675069392,-; unwind_backtrace from show_stack+0x10/0x14
4,345,675069440,-; show_stack from dump_stack_lvl+0xa8/0xb8
4,346,675069475,-; dump_stack_lvl from __warn+0x90/0x224
4,347,675069517,-; __warn from warn_slowpath_fmt+0x130/0x1a8
4,348,675069559,-; warn_slowpath_fmt from cfg80211_calculate_bitrate+0x4d8/0x8b0 [cfg80211] 4,349,675070005,-; cfg80211_calculate_bitrate [cfg80211] from nl80211_put_sta_rate+0x48/0x590 [cfg80211] 4,350,675070819,-; nl80211_put_sta_rate [cfg80211] from nl80211_put_sta_info_common+0x4f4/0xd50 [cfg80211] 4,351,675071616,-; nl80211_put_sta_info_common [cfg80211] from nl80211_send_station.constprop.0+0x114/0x424 [cfg80211] 4,352,675072427,-; nl80211_send_station.constprop.0 [cfg80211] from cfg80211_del_sta_sinfo+0xc4/0x368 [cfg80211] 4,353,675073222,-; cfg80211_del_sta_sinfo [cfg80211] from __sta_info_destroy_part2+0x108/0x2c0 [mac80211] 4,354,675074178,-; __sta_info_destroy_part2 [mac80211] from sta_info_destroy_addr+0x4c/0x88 [mac80211] 4,355,675075243,-; sta_info_destroy_addr [mac80211] from ieee80211_destroy_assoc_data+0x194/0x2d8 [mac80211] 4,356,675075920,-; ieee80211_destroy_assoc_data [mac80211] from ieee80211_rx_mgmt_assoc_resp+0x220/0x1d4c [mac80211] 4,357,675076558,-; ieee80211_rx_mgmt_assoc_resp [mac80211] from ieee80211_iface_work+0x1c0/0x5d0 [mac80211] 4,358,675077187,-; ieee80211_iface_work [mac80211] from cfg80211_wiphy_work+0x110/0x368 [cfg80211] 4,359,675077763,-; cfg80211_wiphy_work [cfg80211] from process_one_work+0x260/0x868
4,360,675078022,-; process_one_work from worker_thread+0x1bc/0x3ec
4,361,675078042,-; worker_thread from kthread+0x120/0x154
4,362,675078060,-; kthread from ret_from_fork+0x14/0x20
4,363,675078074,-;Exception stack(0xf0ac1fb0 to 0xf0ac1ff8)
4,364,675078081,-;1fa0: 00000000 00000000 00000000 00000000
4,365,675078088,-;1fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 4,366,675078093,-;1fe0: 00000000 00000000 00000000 00000000 00000013 00000000
4,367,675080226,-;irq event stamp: 15780967
4,368,675080287,-;hardirqs last enabled at (15780975): [<c050c154>] __up_console_sem+0x50/0x60 4,369,675080395,-;hardirqs last disabled at (15780982): [<c050c140>] __up_console_sem+0x3c/0x60 4,370,675080497,-;softirqs last enabled at (15780966): [<c0476f14>] handle_softirqs+0x398/0x650 4,371,675080608,-;softirqs last disabled at (15780939): [<c0477388>] __irq_exit_rcu+0x150/0x1f0 4,372,675080715,-;---[ end trace 0000000000000000 ]---
To fix, we can simply not seed this psuedo rate. It was originally implemented to avoid errornous paths that S1G shouldn't take, but those have since been fixed / cleaned up. While we are here, we also don't need to initialise the tx side's last rate with IEEE80211_TX_RC_S1G_MCS (which is equivalent to IEEE80211_TX_RC_VHT_MCS). The entire tx reporting side does not support S1G widths and is assumed to be handled by the driver so we can just remove the entire function.
--- net/mac80211/ieee80211_i.h | 1 - net/mac80211/mlme.c | 12 ++++-------- net/mac80211/rate.c | 1 - net/mac80211/s1g.c | 8 -------- 4 files changed, 4 insertions(+), 18 deletions(-)
net/mac80211/ieee80211_i.h +0 -1
@@ -2250,7 +2250,6 @@ ieee80211_he_op_ie_to_bss_conf(struct ieee80211_vif *vif, const struct ieee80211_he_operation *he_op_ie_elem);/* S1G */ -void ieee80211_s1g_sta_rate_init (struct sta_info *sta);bool ieee80211_s1g_is_twt_setup (struct sk_buff *skb);void ieee80211_s1g_rx_twt_action (struct ieee80211_sub_if_data *sdata,struct sk_buff *skb);
net/mac80211/mlme.c +4 -8
@@ -5044,7 +5044,6 @@ static bool ieee80211_assoc_config_link(struct ieee80211_link_data *link, }static int ieee80211_mgd_setup_link_sta (struct ieee80211_link_data *link, -struct sta_info *sta,struct link_sta_info *link_sta,struct cfg80211_bss *cbss) {
@@ -5059,11 +5058,9 @@ static int ieee80211_mgd_setup_link_sta(struct ieee80211_link_data *link,memcpy (link_sta->addr, cbss->bssid,ETH_ALEN );memcpy (link_sta->pub->addr, cbss->bssid,ETH_ALEN ); -/* TODO: S1G Basic Rate Set is expressed elsewhere */ -if (cbss->channel->band ==NL80211_BAND_S1GHZ ) { -ieee80211_s1g_sta_rate_init (sta); +/* S1G does not use basic rates */ +if (cbss->channel->band ==NL80211_BAND_S1GHZ )return 0 ; - } sband = local->hw.wiphy->bands[cbss->channel->band];
@@ -5676,7 +5673,7 @@ static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata, } } - err =ieee80211_mgd_setup_link_sta (link, sta, link_sta, + err =ieee80211_mgd_setup_link_sta (link, link_sta, assoc_data->link[link_id].bss);if (err) goto out_err;
@@ -8270,8 +8267,7 @@ static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata, goto out_err; } - err =ieee80211_mgd_setup_link_sta (link, new_sta, - link_sta, cbss); + err =ieee80211_mgd_setup_link_sta (link, link_sta, cbss);if (err) {rcu_read_unlock ();sta_info_free (local, new_sta);
net/mac80211/rate.c +0 -1
@@ -54,7 +54,6 @@ void rate_control_rate_init(struct sta_info *sta)/* TODO: check for minstrel_s1g ? */ if (sband->band ==NL80211_BAND_S1GHZ ) { -ieee80211_s1g_sta_rate_init (sta);rcu_read_unlock ();return ; }
net/mac80211/s1g.c +0 -8
@@ -9,14 +9,6 @@#include "ieee80211_i.h" #include "driver-ops.h" -void ieee80211_s1g_sta_rate_init (struct sta_info *sta) -{ -/* avoid indicating legacy bitrates for S1G STAs */ - sta->deflink.tx_stats.last_rate.flags |=IEEE80211_TX_RC_S1G_MCS ; - sta->deflink.rx_stats.last_rate = -STA_STATS_FIELD (TYPE ,STA_STATS_RATE_TYPE_S1G ); -} -bool ieee80211_s1g_is_twt_setup (struct sk_buff *skb) {struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 393/816 ACPI: APEI: GHES: Validate memory error section length before payload access
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dave Jiang <[email protected]>
[ Upstream commit 10338c9085b4939a428a8dc78d2bbf62c161278b ]
ghes_do_proc() hands the CPER_SEC_PLATFORM_MEM payload to the report chain, arch_apei_report_mem_error() and ghes_handle_memory_failure() without checking gdata->error_data_length. All three read validation_bits and physical_addr, at offsets 0 and 16, so a shorter section reads past the record.
Check the length once in ghes_do_proc(), before any consumer runs. Take the 73-byte struct cper_sec_mem_err_old as the floor: older firmware legitimately emits that UEFI 2.1/2.2 layout, and it makes validation_bits safe to read.
The fields from "extended" on are absent from that layout, so also require whatever length the validation bits claim. Derive it per field rather than demanding the full 80 bytes: rank needs only 76, and the BANK_GROUP and BANK_ADDRESS bits describe "bank" at offset 38, which every record carries. Testing the whole mask against one size, as cper_print_mem() does, gets it wrong both ways.
--- drivers/acpi/apei/ghes.c | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
drivers/acpi/apei/ghes.c +41 -0
@@ -787,6 +787,28 @@ int cxl_cper_kfifo_get(struct cxl_cper_work_data *wd) }EXPORT_SYMBOL_NS_GPL (cxl_cper_kfifo_get,CXL ); +/* +* The fields from "extended" on are absent from the 73-byte UEFI 2.1/2.2 +* layout that older firmware still emits. Return the length needed for the +* fields the validation bits claim, so over-claiming is rejected without +* rejecting an honest short record. +*/ +static u32 ghes_mem_err_min_len (u64 validation_bits) +{ +u32 len =sizeof (struct cper_sec_mem_err_old ); + +if (validation_bits & (CPER_MEM_VALID_ROW_EXT |CPER_MEM_VALID_CHIP_ID )) + len = offsetof(struct cper_sec_mem_err , rank); +if (validation_bits &CPER_MEM_VALID_RANK_NUMBER ) + len = offsetof(struct cper_sec_mem_err , mem_array_handle); +if (validation_bits &CPER_MEM_VALID_CARD_HANDLE ) + len = offsetof(struct cper_sec_mem_err , mem_dev_handle); +if (validation_bits &CPER_MEM_VALID_MODULE_HANDLE ) + len =sizeof (struct cper_sec_mem_err ); + +return len; +} +static bool ghes_do_proc (struct ghes *ghes,const struct acpi_hest_generic_status *estatus) {
@@ -811,6 +833,25 @@ static bool ghes_do_proc(struct ghes *ghes,if (guid_equal (sec_type, &CPER_SEC_PLATFORM_MEM )) {struct cper_sec_mem_err *mem_err =acpi_hest_get_payload (gdata); +/* +* Check once for all three consumers below. The 73-byte +* UEFI 2.1/2.2 layout is the floor, matching +* cper_estatus_print_section() and making +* validation_bits safe to read. +*/ +if (gdata->error_data_length < +sizeof (struct cper_sec_mem_err_old )) +continue ; + +/* Then require what the claimed fields actually need. */ +if (gdata->error_data_length < +ghes_mem_err_min_len (mem_err->validation_bits)) { + pr_warn_ratelimited(FW_WARN GHES_PFX +"memory error section too small (%u) for the fields it claims\n" , + gdata->error_data_length); +continue ; + } +atomic_notifier_call_chain (&ghes_report_chain, sev, mem_err);arch_apei_report_mem_error (sev, mem_err);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 394/816 ASoC: sta32x: make power restoration transactional
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit 3e71dc4508bc84862dc3644e3b6a5b966bff22ad ]
sta32x_set_bias_level() enables the codec supplies, restores the coefficient and register state, and then starts the watchdog. Register access errors in the mute and coefficient helpers and the cache replay are discarded, allowing DAPM to publish STANDBY for a partially restored codec.
Propagate every operation in the local restore transaction, including the final standby-state write. Start the watchdog only after that write succeeds. On failure, hold reset, mark the cache dirty, disable the supplies and report a cleanup failure while preserving the primary error. The DAPM bias callback consumes the returned error independently of component resume handling.
--- sound/soc/codecs/sta32x.c | 101 +++++++++++++++++++++++++++++--------- 1 file changed, 77 insertions(+), 24 deletions(-)
sound/soc/codecs/sta32x.c +77 -24
@@ -345,27 +345,48 @@ static int sta32x_sync_coef_shadow(struct snd_soc_component *component) {struct sta32x_priv *sta32x =snd_soc_component_get_drvdata (component);unsigned int cfud; -int i; +int i, ret;/* preserve reserved bits in STA32X_CFUD */ -regmap_read (sta32x->regmap,STA32X_CFUD , &cfud); + ret =regmap_read (sta32x->regmap,STA32X_CFUD , &cfud); +if (ret) +return ret; + cfud &=0xf0 ;for (i =0 ; i <STA32X_COEF_COUNT ; i++) { -regmap_write (sta32x->regmap,STA32X_CFADDR2 , i); -regmap_write (sta32x->regmap,STA32X_B1CF1 , - (sta32x->coef_shadow[i] >>16 ) &0xff ); -regmap_write (sta32x->regmap,STA32X_B1CF2 , - (sta32x->coef_shadow[i] >>8 ) &0xff ); -regmap_write (sta32x->regmap,STA32X_B1CF3 , - (sta32x->coef_shadow[i]) &0xff ); + ret =regmap_write (sta32x->regmap,STA32X_CFADDR2 , i); +if (ret) +return ret; + + ret =regmap_write (sta32x->regmap,STA32X_B1CF1 , + (sta32x->coef_shadow[i] >>16 ) &0xff ); +if (ret) +return ret; + + ret =regmap_write (sta32x->regmap,STA32X_B1CF2 , + (sta32x->coef_shadow[i] >>8 ) &0xff ); +if (ret) +return ret; + + ret =regmap_write (sta32x->regmap,STA32X_B1CF3 , + sta32x->coef_shadow[i] &0xff ); +if (ret) +return ret; +/* * chip documentation does not say if the bits are * self-clearing, so do it explicitly */ -regmap_write (sta32x->regmap,STA32X_CFUD , cfud); -regmap_write (sta32x->regmap,STA32X_CFUD , cfud |0x01 ); + ret =regmap_write (sta32x->regmap,STA32X_CFUD , cfud); +if (ret) +return ret; + + ret =regmap_write (sta32x->regmap,STA32X_CFUD , cfud |0x01 ); +if (ret) +return ret; } +return 0 ; }
@@ -373,15 +394,24 @@ static int sta32x_cache_sync(struct snd_soc_component *component) {struct sta32x_priv *sta32x =snd_soc_component_get_drvdata (component);unsigned int mute; -int rc; +int restore_ret, ret;/* mute during register sync */ -regmap_read (sta32x->regmap,STA32X_MMUTE , &mute); -regmap_write (sta32x->regmap,STA32X_MMUTE , mute |STA32X_MMUTE_MMUTE ); -sta32x_sync_coef_shadow (component); - rc =regcache_sync (sta32x->regmap); -regmap_write (sta32x->regmap,STA32X_MMUTE , mute); -return rc; + ret =regmap_read (sta32x->regmap,STA32X_MMUTE , &mute); +if (ret) +return ret; + + ret =regmap_write (sta32x->regmap,STA32X_MMUTE , + mute |STA32X_MMUTE_MMUTE ); +if (ret) +return ret; + + ret =sta32x_sync_coef_shadow (component); +if (!ret) + ret =regcache_sync (sta32x->regmap); + + restore_ret =regmap_write (sta32x->regmap,STA32X_MMUTE , mute); +return ret ?: restore_ret; }/* work around ESD issue where sta32x resets and loses all configuration */
@@ -797,8 +827,8 @@ static int sta32x_startup_sequence(struct sta32x_priv *sta32x)static int sta32x_set_bias_level (struct snd_soc_component *component,enum snd_soc_bias_level level) { -int ret;struct sta32x_priv *sta32x =snd_soc_component_get_drvdata (component); +int cleanup_ret, ret;dev_dbg (component->dev,"level = %d\n" , level);switch (level) {
@@ -822,15 +852,28 @@ static int sta32x_set_bias_level(struct snd_soc_component *component,return ret; } -sta32x_startup_sequence (sta32x); -sta32x_cache_sync (component); + ret =sta32x_startup_sequence (sta32x); +if (!ret) + ret =sta32x_cache_sync (component); +if (ret) + goto restore_failed; + + ret =regmap_update_bits (sta32x->regmap,STA32X_CONFF , +STA32X_CONFF_PWDN |STA32X_CONFF_EAPD , +0 ); +if (ret) + goto restore_failed; +sta32x_watchdog_start (sta32x); +break ; }/* Power down */ -regmap_update_bits (sta32x->regmap,STA32X_CONFF , -STA32X_CONFF_PWDN |STA32X_CONFF_EAPD , -0 ); + ret =regmap_update_bits (sta32x->regmap,STA32X_CONFF , +STA32X_CONFF_PWDN |STA32X_CONFF_EAPD , +0 ); +if (ret) +return ret;break ;
@@ -848,6 +891,16 @@ static int sta32x_set_bias_level(struct snd_soc_component *component,break ; }return 0 ; + +restore_failed: +gpiod_set_value (sta32x->gpiod_nreset,0 ); +regcache_mark_dirty (sta32x->regmap); + cleanup_ret =regulator_bulk_disable (ARRAY_SIZE (sta32x->supplies), + sta32x->supplies); +if (cleanup_ret) +dev_warn (component->dev,"Failed to disable supplies: %d\n" , + cleanup_ret); +return ret; }static const struct snd_soc_dai_ops sta32x_dai_ops = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 395/816 dmaengine: zynqmp_dma: Fix PM rollback on sw_desc_pool alloc failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Golla Nagendra <[email protected]>
[ Upstream commit f2f44b952ea6e0c600e92ea21fcaa83cafeedf6e ]
If sw_desc_pool allocation fails after pm_runtime_resume_and_get() succeeds in zynqmp_dma_alloc_chan_resources(), the error path returns without dropping the runtime PM reference.
Route that failure path through err_pm so the runtime PM reference is balanced before returning the error.
--- drivers/dma/xilinx/zynqmp_dma.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/dma/xilinx/zynqmp_dma.c +8 -2
@@ -484,8 +484,10 @@ static int zynqmp_dma_alloc_chan_resources(struct dma_chan *dchan) chan->sw_desc_pool =kcalloc (ZYNQMP_DMA_NUM_DESCS ,sizeof (*desc),GFP_KERNEL ); -if (!chan->sw_desc_pool) -return -ENOMEM ; +if (!chan->sw_desc_pool) { + ret = -ENOMEM ; + goto err_pm; + } chan->idle = true; chan->desc_free_cnt =ZYNQMP_DMA_NUM_DESCS ;
@@ -517,6 +519,10 @@ static int zynqmp_dma_alloc_chan_resources(struct dma_chan *dchan) }return ZYNQMP_DMA_NUM_DESCS ; + +err_pm: +pm_runtime_put_autosuspend (chan->dev); +return ret; }/**
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 396/816 dmaengine: zynqmp_dma: Free sw_desc_pool on desc_pool_v alloc failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Golla Nagendra <[email protected]>
[ Upstream commit 4ea99b14b3bd955d768666941e2e03ba186b52f5 ]
In zynqmp_dma_alloc_chan_resources(), sw_desc_pool is allocated before desc_pool_v. If dma_alloc_coherent() for desc_pool_v fails, the function currently exits through the runtime PM rollback path but leaves the already allocated sw_desc_pool behind.
Add a dedicated err_free_sw_desc_pool label for the desc_pool_v failure path, free sw_desc_pool there, then fall through to err_pm for pm_runtime_put_autosuspend().
This keeps the error unwind symmetric and avoids leaking the software descriptor pool on coherent descriptor allocation failure.
--- drivers/dma/xilinx/zynqmp_dma.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/dma/xilinx/zynqmp_dma.c +7 -2
@@ -505,8 +505,10 @@ static int zynqmp_dma_alloc_chan_resources(struct dma_chan *dchan) (2 *ZYNQMP_DMA_DESC_SIZE (chan) *ZYNQMP_DMA_NUM_DESCS ), &chan->desc_pool_p, GFP_KERNEL); -if (!chan->desc_pool_v) -return -ENOMEM ; +if (!chan->desc_pool_v) { + ret = -ENOMEM ; + goto err_free_sw_desc_pool; + }for (i =0 ; i <ZYNQMP_DMA_NUM_DESCS ; i++) { desc = chan->sw_desc_pool + i;
@@ -520,6 +522,9 @@ static int zynqmp_dma_alloc_chan_resources(struct dma_chan *dchan)return ZYNQMP_DMA_NUM_DESCS ; +err_free_sw_desc_pool: +kfree (chan->sw_desc_pool); + chan->sw_desc_pool =NULL ; err_pm:pm_runtime_put_autosuspend (chan->dev);return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 397/816 wifi: ath12k: fix truncated TX buffer DMA address in MSDU ext descriptor
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Baochen Qiang <[email protected]>
[ Upstream commit 979ecb88ed3528e08dd7f87b90b029374226ca84 ]
ath12k_wifi7_hal_tx_cmd_ext_desc_setup() programs the low 32 bits of the TX buffer physical address into HAL_TX_MSDU_EXT_INFO0_BUF_PTR_LO but hardcodes the high bits field HAL_TX_MSDU_EXT_INFO1_BUF_PTR_HI to 0x0.
dma_addr_t is 64-bit on platforms with CONFIG_ARCH_DMA_ADDR_T_64BIT, so whenever a TX buffer is mapped above the 4 GB boundary the upper bits of paddr are dropped and the firmware is handed a truncated address, leading to potential TX failures.
Write the upper bits of paddr into BUF_PTR_HI to fix this issue.
Issue found during code review, compile tested only.
--- drivers/net/wireless/ath/ath12k/dp_tx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ath/ath12k/dp_tx.c +1 -1
@@ -111,7 +111,7 @@ static void ath12k_hal_tx_cmd_ext_desc_setup(struct ath12k_base *ab, { tcl_ext_cmd->info0 =le32_encode_bits (ti->paddr,HAL_TX_MSDU_EXT_INFO0_BUF_PTR_LO ); - tcl_ext_cmd->info1 =le32_encode_bits (0x0 , + tcl_ext_cmd->info1 =le32_encode_bits ((u64 )ti->paddr >>HAL_ADDR_MSB_REG_SHIFT ,HAL_TX_MSDU_EXT_INFO1_BUF_PTR_HI ) |le32_encode_bits (ti->data_len,HAL_TX_MSDU_EXT_INFO1_BUF_LEN );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 398/816 sit: charge ip_tunnel_prl_entry allocations to memcg
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 40a2b90f5190fcc7b083809fa93f2799abefeeb1 ]
ipip6_tunnel_add_prl() allocates struct ip_tunnel_prl_entry for each potential router entry added via SIOCADDPRL.
An unprivileged user with CAP_NET_ADMIN in a user namespace can add an unbounded number of entries, consuming uncharged kernel memory.
Commit 1b51d8271973 ("memcg: ipv6/sit: account and don't WARN on ip_tunnel_prl structs allocation") added accounting to the temporary buffer in ipip6_tunnel_get_prl(), but missed the entry allocations in ipip6_tunnel_add_prl().
Use GFP_KERNEL_ACCOUNT when allocating struct ip_tunnel_prl_entry.
--- net/ipv6/sit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/sit.c +1 -1
@@ -394,7 +394,7 @@ ipip6_tunnel_add_prl(struct ip_tunnel *t, struct ip_tunnel_prl *a, int chg) goto out; } - p =kzalloc (sizeof (struct ip_tunnel_prl_entry ),GFP_KERNEL ); + p =kzalloc (sizeof (struct ip_tunnel_prl_entry ),GFP_KERNEL_ACCOUNT );if (!p) { err = -ENOBUFS ; goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 399/816 crypto: inside-secure - Zeroize temporary arrays on stack with sensitive data
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Huth <[email protected]>
[ Upstream commit 5c87bcb2f98dbfe08efa016af037b0f9701ba381 ]
key_tmp[] in safexcel_xcbcmac_setkey() and consts[] / _const[] in safexcel_cmac_setkey() contain crypto key material that should not get exposed to the outside once the function is done. Scrub the arrays with memzero_explicit() to avoid that the data could leak via the stack.
--- drivers/crypto/inside-secure/safexcel_hash.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/crypto/inside-secure/safexcel_hash.c +3 -0
@@ -2081,6 +2081,7 @@ static int safexcel_xcbcmac_setkey(struct crypto_ahash *tfm, const u8 *key, ret =aes_expandkey (ctx->aes, (u8 *)key_tmp +2 *AES_BLOCK_SIZE ,AES_MIN_KEY_SIZE ); +memzero_explicit (key_tmp,sizeof (key_tmp));if (ret)return ret;
@@ -2192,6 +2193,8 @@ static int safexcel_cmac_setkey(struct crypto_ahash *tfm, const u8 *key, } ctx->cbcmac = false; +memzero_explicit (consts,sizeof (consts)); +memzero_explicit (_const,sizeof (_const));return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 400/816 ACPI: glue: Reduce debug noise from acpi_device_notify()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rafael J. Wysocki <[email protected]>
[ Upstream commit 5bc1e72f80da4c20ce8b57851be4fad67e855ebd ]
When debug is enabled in the ACPI glue code that handles binding devices to ACPI companions, acpi_device_notify() produces a lot of message noise related to devices that have no ACPI companions.
Reduce that noise by checking the most obvious case, ACPI device objects, directly and returning from acpi_device_notify() in that case without printing any debug messages. Also avoid printing a debug message when there is no matching ACPI bus type definition for the given device, which is the case for the vast majority of devices.
Additionally, make the debug messages that get printed more informative.
Stable-dep-of: c94619c8a5b5 ("ACPI: glue: Carry out companion lookup under bus_type_sem")
--- drivers/acpi/glue.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/acpi/glue.c +10 -10
@@ -356,22 +356,27 @@ void acpi_device_notify(struct device *dev)struct acpi_device *adev;int ret; +/* ACPI devices have no ACPI companions. */ +if (dev->bus == &acpi_bus_type) +return ; + ret =acpi_bind_one (dev,NULL );if (ret) {struct acpi_bus_type *type =acpi_get_bus_type (dev);if (!type) - goto err; +return ; adev = type->find_companion (dev);if (!adev) {dev_dbg (dev,"ACPI companion not found\n" ); - goto err; +return ; } ret =acpi_bind_one (dev, adev); -if (ret) - goto err; - +if (ret) { +dev_dbg (dev,"Binding to ACPI companion failed\n" ); +return ; + }if (type->setup) { type->setup (dev); goto done;
@@ -393,11 +398,6 @@ void acpi_device_notify(struct device *dev) done:acpi_handle_debug (ACPI_HANDLE (dev),"Bound to device %s\n" ,dev_name (dev)); - -return ; - -err: -dev_dbg (dev,"No ACPI support\n" ); }void acpi_device_notify_remove (struct device *dev)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 401/816 ACPI: glue: Rework the success message in acpi_device_notify()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rafael J. Wysocki <[email protected]>
[ Upstream commit aef7792cddcac7ab400912c2947a595401d4a7e8 ]
Using an ACPI handle in the acpi_device_notify() success message is somewhat misleading because the "physical" device is not bound to an ACPI namespace object in that function, but to an ACPI device object attached to it. Moreover, the message is outright confusing for the "physical" devices bound to ACPI devices without ACPI namespace objects (for example, fixed event buttons).
Address this by turning that message into a dev_dbg() one printed for the "physical" device and mentioning the name of the ACPI companion.
Stable-dep-of: c94619c8a5b5 ("ACPI: glue: Carry out companion lookup under bus_type_sem")
--- drivers/acpi/glue.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/acpi/glue.c +1 -2
@@ -396,8 +396,7 @@ void acpi_device_notify(struct device *dev) adev->handler->bind (dev); done: -acpi_handle_debug (ACPI_HANDLE (dev),"Bound to device %s\n" , -dev_name (dev)); +dev_dbg (dev,"Bound to ACPI device %s\n" ,acpi_dev_name (adev)); }void acpi_device_notify_remove (struct device *dev)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 402/816 ACPI: glue: Carry out companion lookup under bus_type_sem
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rafael J. Wysocki <[email protected]>
[ Upstream commit c94619c8a5b5d3b980433d247ac87a2d1c827cb6 ]
When acpi_device_notify() looks up an ACPI companion for the given device, it invokes callbacks from struct acpi_bus_type() without synchronization which may lead to a use-after-free if the driver module containing those callbacks is unloaded at the same time.
Address this by holding bus_type_sem throughout the entire ACPI companion lookup and the execution of the .setup() callback in struct acpi_bus_type (if present) instead of dropping the semaphore (prematurely) after finding a matching struct acpi_bus_type.
For this purpose, rename acpi_get_bus_type() to acpi_companion_lookup(), make it return a struct acpi_device pointer, and move the relevant code from acpi_device_notify() to it.
Also notice that the only case in which the .bind() callback from an ACPI scan handler may need to be invoked is when the given device is a platform one, so adjust acpi_device_notify() accordingly and drop the "done" label that is not used any more from it.
--- drivers/acpi/glue.c | 61 +++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 32 deletions(-)
drivers/acpi/glue.c +29 -32
@@ -59,19 +59,34 @@ int unregister_acpi_bus_type(struct acpi_bus_type *type) }EXPORT_SYMBOL_GPL (unregister_acpi_bus_type); -static struct acpi_bus_type *acpi_get_bus_type (struct device *dev) +static struct acpi_device *acpi_companion_lookup (struct device *dev) { -struct acpi_bus_type *tmp, *ret =NULL ; +struct acpi_bus_type *type; -down_read (&bus_type_sem); -list_for_each_entry (tmp, &bus_type_list, list) { -if (tmp->match (dev)) { - ret = tmp; -break ; +guard (rwsem_read)(&bus_type_sem); + +list_for_each_entry (type, &bus_type_list, list) { +struct acpi_device *adev; + +if (!type->match (dev)) +continue ; + + adev = type->find_companion (dev); +if (!adev) { +dev_dbg (dev,"ACPI companion not found\n" ); +return NULL ; } +if (acpi_bind_one (dev, adev)) { +dev_dbg (dev,"Binding to ACPI companion failed\n" ); +return NULL ; + } +if (type->setup) + type->setup (dev); + +return adev; } -up_read (&bus_type_sem); -return ret; + +return NULL ; }#define FIND_CHILD_MIN_SCORE 1
@@ -362,40 +377,22 @@ void acpi_device_notify(struct device *dev) ret =acpi_bind_one (dev,NULL );if (ret) { -struct acpi_bus_type *type =acpi_get_bus_type (dev); - -if (!type) + adev =acpi_companion_lookup (dev); +if (!adev)return ; - - adev = type->find_companion (dev); -if (!adev) { -dev_dbg (dev,"ACPI companion not found\n" ); -return ; - } - ret =acpi_bind_one (dev, adev); -if (ret) { -dev_dbg (dev,"Binding to ACPI companion failed\n" ); -return ; - } -if (type->setup) { - type->setup (dev); - goto done; - } }else { adev =ACPI_COMPANION (dev);if (dev_is_pci (dev)) {pci_acpi_setup (dev, adev); - goto done; }else if (dev_is_platform (dev)) {acpi_configure_pmsi_domain (dev); + +if (adev->handler && adev->handler->bind) + adev->handler->bind (dev); } } -if (adev->handler && adev->handler->bind) - adev->handler->bind (dev); - -done:dev_dbg (dev,"Bound to ACPI device %s\n" ,acpi_dev_name (adev)); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 403/816 ACPI: glue: Rearrange acpi_bind_one() to avoid breakage
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rafael J. Wysocki <[email protected]>
[ Upstream commit fcfb2b562115632e0a60a0928dca495f98eb335c ]
Rearange the code in acpi_bind_one() to avoid situations in which the existing ACPI companion of the given device would be replaced with NULL due to a memory allocation error or because somebody tries to bind a physical device with an ACPI companion to a different ACPI device erroneously.
--- drivers/acpi/glue.c | 58 +++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 34 deletions(-)
drivers/acpi/glue.c +24 -34
@@ -243,31 +243,25 @@ static void acpi_physnode_link_name(char *buf, unsigned int node_id)int acpi_bind_one (struct device *dev,struct acpi_device *acpi_dev) {struct acpi_device_physical_node *physical_node, *pn; +struct acpi_device *comp_dev =ACPI_COMPANION (dev);char physical_node_name[PHYSICAL_NODE_NAME_SIZE ];struct list_head *physnode_list;unsigned int node_id;int retval = -EINVAL ; -if (has_acpi_companion (dev)) { -if (acpi_dev) { -dev_warn (dev,"ACPI companion already set\n" ); +if (!acpi_dev) { +if (!comp_dev)return -EINVAL ; - }else { - acpi_dev =ACPI_COMPANION (dev); - } - } -if (!acpi_dev) -return -EINVAL ; -acpi_dev_get (acpi_dev); -get_device (dev); - physical_node =kzalloc (sizeof (*physical_node),GFP_KERNEL ); -if (!physical_node) { - retval = -ENOMEM ; - goto err; +/* If the companion has been set upfront, pick it up. */ + acpi_dev = comp_dev; + }else if (comp_dev && acpi_dev != comp_dev) { +dev_warn (dev,"ACPI companion already set to %s which is not %s\n" , +acpi_dev_name (comp_dev),acpi_dev_name (acpi_dev)); +return -EEXIST ; } -mutex_lock (&acpi_dev->physical_node_lock); +guard (mutex)(&acpi_dev->physical_node_lock);/* * Keep the list sorted by node_id so that the IDs of removed nodes can
@@ -278,15 +272,12 @@ int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev)list_for_each_entry (pn, &acpi_dev->physical_node_list, node) {/* Sanity check. */ if (pn->dev == dev) { -mutex_unlock (&acpi_dev->physical_node_lock); - -dev_warn (dev,"Already associated with ACPI node\n" ); -kfree (physical_node); -if (ACPI_COMPANION (dev) != acpi_dev) - goto err; - -put_device (dev); -acpi_dev_put (acpi_dev); +if (!comp_dev) { +/* Really unexpected. */ +ACPI_COMPANION_SET (dev, acpi_dev); +dev_warn (&acpi_dev->dev, +"Physical device list corruption fixed up\n" ); + }return 0 ; }if (pn->node_id == node_id) {
@@ -295,12 +286,19 @@ int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev) } } + physical_node =kzalloc (sizeof (*physical_node),GFP_KERNEL ); +if (!physical_node) +return -ENOMEM ; + +acpi_dev_get (acpi_dev); +get_device (dev); + physical_node->node_id = node_id; physical_node->dev = dev;list_add (&physical_node->node, physnode_list); acpi_dev->physical_node_count++; -if (!has_acpi_companion (dev)) +if (!comp_dev)ACPI_COMPANION_SET (dev, acpi_dev);acpi_physnode_link_name (physical_node_name, node_id);
@@ -316,18 +314,10 @@ int acpi_bind_one(struct device *dev, struct acpi_device *acpi_dev)dev_err (dev,"Failed to create link firmware_node (%d)\n" , retval); -mutex_unlock (&acpi_dev->physical_node_lock); -if (acpi_dev->wakeup.flags.valid)device_set_wakeup_capable (dev, true);return 0 ; - - err: -ACPI_COMPANION_SET (dev,NULL ); -put_device (dev); -acpi_dev_put (acpi_dev); -return retval; }EXPORT_SYMBOL_GPL (acpi_bind_one);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 404/816 phy: samsung: usbdrd: propagate GS101 PIPE3 lock failures
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit 2ef1e78ef7223eb16d9cf20814a1b2873456f671 ]
The GS101 PIPE3 initialization checks the PMA PLL lock and then checks the CDR lock. The PLL helper returns an error, but the GS101 PIPE3 init path dropped that result. The CDR helper only logged a timeout. PHY initialization could therefore still return success after either the PLL or the selected receive lane had not locked.
Make the in-file SoC-specific phy_init hook return an int so helpers with real failure results can propagate them through the existing PHY init paths. Keep the register-only helpers returning success and use the new return path to report the GS101 CDR wait failure. Other SoC helper paths keep their previous success behavior.
--- drivers/phy/samsung/phy-exynos5-usbdrd.c | 51 +++++++++++++++++------- 1 file changed, 37 insertions(+), 14 deletions(-)
drivers/phy/samsung/phy-exynos5-usbdrd.c +37 -14
@@ -355,7 +355,7 @@ struct exynos5_usbdrd_phy;struct exynos5_usbdrd_phy_config {u32 id;void (*phy_isol)(struct phy_usb_instance *inst,bool isolate); -void (*phy_init)(struct exynos5_usbdrd_phy *phy_drd); +int (*phy_init)(struct exynos5_usbdrd_phy *phy_drd);unsigned int (*set_refclk)(struct phy_usb_instance *inst); };
@@ -579,7 +579,7 @@ exynos5_usbdrd_apply_phy_tunes(struct exynos5_usbdrd_phy *phy_drd, } } -static void exynos5_usbdrd_pipe3_init (struct exynos5_usbdrd_phy *phy_drd) +static int exynos5_usbdrd_pipe3_init (struct exynos5_usbdrd_phy *phy_drd) {u32 reg;
@@ -592,6 +592,8 @@ static void exynos5_usbdrd_pipe3_init(struct exynos5_usbdrd_phy *phy_drd) reg =readl (phy_drd->reg_phy +EXYNOS5_DRD_PHYTEST ); reg &= ~PHYTEST_POWERDOWN_SSP ;writel (reg, phy_drd->reg_phy +EXYNOS5_DRD_PHYTEST ); + +return 0 ; } static void
@@ -686,7 +688,7 @@ exynos5_usbdrd_usbdp_g2_v4_pma_check_pll_lock(struct exynos5_usbdrd_phy *phy_drdreturn err; } -static void +static int exynos5_usbdrd_usbdp_g2_v4_pma_check_cdr_lock (struct exynos5_usbdrd_phy *phy_drd) {static const unsigned int timeout_us =40000 ;
@@ -703,7 +705,7 @@ exynos5_usbdrd_usbdp_g2_v4_pma_check_cdr_lock(struct exynos5_usbdrd_phy *phy_drd phy_drd->reg_pma +EXYNOS9_PMA_USBDP_TRSV_REG03C3 , reg, (reg & locked) == locked, sleep_us, timeout_us);if (!err) -return ; +return 0 ;dev_err (phy_drd->dev,"timed out waiting for CDR lock (l0): %#.8x, retrying\n" , reg);
@@ -715,9 +717,11 @@ exynos5_usbdrd_usbdp_g2_v4_pma_check_cdr_lock(struct exynos5_usbdrd_phy *phy_drdif (err)dev_err (phy_drd->dev,"timed out waiting for CDR lock (l2): %#.8x\n" , reg); + +return err; } -static void exynos5_usbdrd_utmi_init (struct exynos5_usbdrd_phy *phy_drd) +static int exynos5_usbdrd_utmi_init (struct exynos5_usbdrd_phy *phy_drd) {u32 reg;
@@ -739,6 +743,8 @@ static void exynos5_usbdrd_utmi_init(struct exynos5_usbdrd_phy *phy_drd) reg =readl (phy_drd->reg_phy +EXYNOS5_DRD_PHYTEST ); reg &= ~PHYTEST_POWERDOWN_HSP ;writel (reg, phy_drd->reg_phy +EXYNOS5_DRD_PHYTEST ); + +return 0 ; }static int exynos5_usbdrd_phy_init (struct phy *phy)
@@ -775,7 +781,9 @@ static int exynos5_usbdrd_phy_init(struct phy *phy)writel (reg, phy_drd->reg_phy +EXYNOS5_DRD_PHYUTMICLKSEL );/* UTMI or PIPE3 specific init */ - inst->phy_cfg->phy_init (phy_drd); + ret = inst->phy_cfg->phy_init (phy_drd); +if (ret) + goto disable_clks;/* reference clock settings */ reg = inst->phy_cfg->set_refclk (inst);
@@ -798,9 +806,10 @@ static int exynos5_usbdrd_phy_init(struct phy *phy) reg &= ~PHYCLKRST_PORTRESET ;writel (reg, phy_drd->reg_phy +EXYNOS5_DRD_PHYCLKRST ); +disable_clks:clk_bulk_disable_unprepare (phy_drd->drv_data->n_clks, phy_drd->clks); -return 0 ; +return ret; }static int exynos5_usbdrd_phy_exit (struct phy *phy)
@@ -1067,7 +1076,7 @@ exynos5_usbdrd_usb_v3p1_pipe_override(struct exynos5_usbdrd_phy *phy_drd)writel (reg, regs_base +EXYNOS850_DRD_SECPMACTL ); } -static void exynos850_usbdrd_utmi_init (struct exynos5_usbdrd_phy *phy_drd) +static int exynos850_usbdrd_utmi_init (struct exynos5_usbdrd_phy *phy_drd) {void __iomem *regs_base = phy_drd->reg_phy;u32 reg;
@@ -1171,6 +1180,8 @@ static void exynos850_usbdrd_utmi_init(struct exynos5_usbdrd_phy *phy_drd)if (ss_ports)exynos5_usbdrd_usb_v3p1_pipe_override (phy_drd); + +return 0 ; }static int exynos850_usbdrd_phy_init (struct phy *phy)
@@ -1184,11 +1195,11 @@ static int exynos850_usbdrd_phy_init(struct phy *phy)return ret;/* UTMI or PIPE3 specific init */ - inst->phy_cfg->phy_init (phy_drd); + ret = inst->phy_cfg->phy_init (phy_drd);clk_bulk_disable_unprepare (phy_drd->drv_data->n_clks, phy_drd->clks); -return 0 ; +return ret; }static int exynos850_usbdrd_phy_exit (struct phy *phy)
@@ -1235,11 +1246,12 @@ static const struct phy_ops exynos850_usbdrd_phy_ops = { .owner = THIS_MODULE, }; -static void exynos5_usbdrd_gs101_pipe3_init (struct exynos5_usbdrd_phy *phy_drd) +static int exynos5_usbdrd_gs101_pipe3_init (struct exynos5_usbdrd_phy *phy_drd) {void __iomem *regs_pma = phy_drd->reg_pma;void __iomem *regs_phy = phy_drd->reg_phy;u32 reg; +int ret;exynos5_usbdrd_usbdp_g2_v4_ctrl_pma_ready (phy_drd);
@@ -1261,8 +1273,11 @@ static void exynos5_usbdrd_gs101_pipe3_init(struct exynos5_usbdrd_phy *phy_drd) SECPMACTL_PMA_INIT_SW_RST);writel (reg, regs_phy +EXYNOS850_DRD_SECPMACTL ); -if (!exynos5_usbdrd_usbdp_g2_v4_pma_check_pll_lock (phy_drd)) -exynos5_usbdrd_usbdp_g2_v4_pma_check_cdr_lock (phy_drd); + ret =exynos5_usbdrd_usbdp_g2_v4_pma_check_pll_lock (phy_drd); +if (ret) +return ret; + +return exynos5_usbdrd_usbdp_g2_v4_pma_check_cdr_lock (phy_drd); }static int exynos5_usbdrd_gs101_phy_init (struct phy *phy)
@@ -1287,7 +1302,15 @@ static int exynos5_usbdrd_gs101_phy_init(struct phy *phy)*/ exynos5_usbdrd_phy_isol (inst, false); -return exynos850_usbdrd_phy_init (phy); + ret =exynos850_usbdrd_phy_init (phy); +if (ret) { +exynos5_usbdrd_phy_isol (inst, true); +if (inst->phy_cfg->id ==EXYNOS5_DRDPHY_UTMI ) +regulator_bulk_disable (phy_drd->drv_data->n_regulators, + phy_drd->regulators); + } + +return ret; }static int exynos5_usbdrd_gs101_phy_exit (struct phy *phy)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 405/816 cxl/hdm: Restore commit_end when decoder enumeration fails
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alison Schofield <[email protected]>
[ Upstream commit 7dae18c39e99813461db6ef3fc13f077452109ce ]
commit_end tracks the highest committed decoder on a port. It gets advanced before decoder enumeration is complete, so a later failure leaves it pointing at a decoder that was never added. The next probe then rejects decoder0 as out of order and enumeration fails.
Reset commit_end to the uncommitted baseline once the decoders are torn down, so a subsequent probe rebuilds it from scratch. Register the reset before the decoders are added so that on unwind it runs after every decoder has been unregistered. This prevents commit_end from dropping below the highest committed decoder still registered and exposing an inconsistent value to a concurrent reader.
Protect the commit_end advance in the DVSEC emulation path against concurrent readers, matching the register-programmed path.
--- drivers/cxl/core/hdm.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)
drivers/cxl/core/hdm.c +20 -3
@@ -808,7 +808,8 @@ static int cxl_setup_hdm_decoder_from_dvsec(* change the range registers at run time. */ cxld->flags |=CXL_DECODER_F_ENABLE |CXL_DECODER_F_LOCK ; - port->commit_end = cxld->id; +scoped_guard (rwsem_write, &cxl_region_rwsem) + port->commit_end = cxld->id; rc =devm_cxl_dpa_reserve (cxled, *dpa_base, len,0 );if (rc) {
@@ -1011,6 +1012,14 @@ static void cxl_settle_decoders(struct cxl_hdm *cxlhdm)msleep (20 ); } +static void cxl_reset_commit_end (void *data) +{ +struct cxl_port *port = data; + +guard (rwsem_write)(&cxl_region_rwsem); + port->commit_end =-1 ; +} +/** * devm_cxl_enumerate_decoders - add decoder objects per HDM register set * @cxlhdm: Structure to populate with HDM capabilities
@@ -1021,8 +1030,8 @@ int devm_cxl_enumerate_decoders(struct cxl_hdm *cxlhdm, {void __iomem *hdm = cxlhdm->regs.hdm_decoder;struct cxl_port *port = cxlhdm->port; -int i;u64 dpa_base =0 ; +int i, rc;/* * Per CXL 4.0 8.2.4.20.1 Target Count is the number of target ports
@@ -1038,8 +1047,16 @@ int devm_cxl_enumerate_decoders(struct cxl_hdm *cxlhdm,cxl_settle_decoders (cxlhdm); +/* +* Reset commit_end after all decoders have been torn down so a +* subsequent probe rebuilds it from scratch. +*/ + rc =devm_add_action (&port->dev, cxl_reset_commit_end, port); +if (rc) +return rc; +for (i =0 ; i < cxlhdm->decoder_count; i++) { -int rc, target_count = cxlhdm->target_count; +int target_count = cxlhdm->target_count;struct cxl_decoder *cxld;if (is_cxl_endpoint (port)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 406/816 cxl/port: Bound switch decoder target array access by nr_targets
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alison Schofield <[email protected]>
[ Upstream commit 4e42c398af136d62fac8c19c9f410ec83a8dd34a ]
Switch decoder target lookups walk the target array using interleave ways as the bound. The array is allocated with nr_targets entries, so a decoder whose interleave ways exceeds nr_targets reads and writes past the end of it. That happens during dport activation, during decoder target population, and when userspace reads the target_list attribute.
Bounding by nr_targets alone is not correct either. Commit d6488fee6647 ("cxl/port: Fix decoder initialization when nr_targets > interleave_ways") moved target population to interleave ways precisely so that targets a decoder does not use are left unpopulated. Neither field alone is a safe bound, so add a helper that returns the minimum of the two and use it at every walk of the target array.
Valid configurations keep interleave ways within nr_targets, so this is not a behavior change for them.
--- drivers/cxl/core/port.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
drivers/cxl/core/port.c +15 -5
@@ -144,20 +144,29 @@ static ssize_t target_type_show(struct device *dev, }static DEVICE_ATTR_RO (target_type); +/* +* Interleave ways selects how many targets a decoder uses, but the target +* array is only nr_targets long. Bound array access by both. +*/ +static int cxlsd_nr_used_targets (struct cxl_switch_decoder *cxlsd) +{ +return min (cxlsd->cxld.interleave_ways, cxlsd->nr_targets); +} +static ssize_t emit_target_list (struct cxl_switch_decoder *cxlsd,char *buf) { -struct cxl_decoder *cxld = &cxlsd->cxld; +int nr_used =cxlsd_nr_used_targets (cxlsd);ssize_t offset =0 ;int i, rc =0 ; -for (i =0 ; i < cxld->interleave_ways; i++) { +for (i =0 ; i < nr_used; i++) {struct cxl_dport *dport = cxlsd->target[i];struct cxl_dport *next =NULL ;if (!dport)break ; -if (i +1 < cxld->interleave_ways) +if (i +1 < nr_used) next = cxlsd->target[i +1 ]; rc =sysfs_emit_at (buf, offset,"%d%s" , dport->port_id, next ?"," :"" );
@@ -1718,7 +1727,7 @@ static int decoder_populate_targets(struct cxl_switch_decoder *cxlsd, struct cxl_port *port) {struct cxl_decoder *cxld = &cxlsd->cxld; -int i; +int i, nr_used;device_lock_assert (&port->dev);
@@ -1726,7 +1735,8 @@ static int decoder_populate_targets(struct cxl_switch_decoder *cxlsd,return -EINVAL ;guard (rwsem_write)(&cxl_region_rwsem); -for (i =0 ; i < cxlsd->cxld.interleave_ways; i++) { + nr_used =cxlsd_nr_used_targets (cxlsd); +for (i =0 ; i < nr_used; i++) {struct cxl_dport *dport =find_dport (port, cxld->target_map[i]);if (!dport)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 407/816 ASoC: rt1015: make control calibration failures observable
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit 98fe8aab04cec6fcadeb10a757235225d550be36 ]
The bypass-boost control runs a hardware calibration while bypassing the register cache. It ignores every register access and cache restore failure, then publishes both the requested mode and calibration completion.
Return failures from the complete calibration sequence, always restore normal cache operation and unlock DAPM, and only publish the control state after the calibration and final mode write both succeed. The mixer control callback is an effective error consumer, independent of deferred component resume.
--- sound/soc/codecs/rt1015.c | 81 +++++++++++++++++++++++++++++++-------- 1 file changed, 65 insertions(+), 16 deletions(-)
sound/soc/codecs/rt1015.c +65 -16
@@ -491,34 +491,71 @@ static int rt1015_bypass_boost_get(struct snd_kcontrol *kcontrol,return 0 ; } -static void rt1015_calibrate (struct rt1015_priv *rt1015) +static int rt1015_calibrate (struct rt1015_priv *rt1015) {struct snd_soc_component *component = rt1015->component;struct regmap *regmap = rt1015->regmap; +int ret, sync_ret;snd_soc_dapm_mutex_lock (&component->dapm);regcache_cache_bypass (regmap, true); -regmap_write (regmap,RT1015_CLK_DET ,0x0000 ); -regmap_write (regmap,RT1015_PWR4 ,0x00B2 ); -regmap_write (regmap,RT1015_PWR_STATE_CTRL ,0x0009 ); + ret =regmap_write (regmap,RT1015_CLK_DET ,0x0000 ); +if (ret) + goto restore_cache; + + ret =regmap_write (regmap,RT1015_PWR4 ,0x00B2 ); +if (ret) + goto restore_cache; + + ret =regmap_write (regmap,RT1015_PWR_STATE_CTRL ,0x0009 ); +if (ret) + goto restore_cache; +msleep (100 ); -regmap_write (regmap,RT1015_PWR_STATE_CTRL ,0x000A ); + ret =regmap_write (regmap,RT1015_PWR_STATE_CTRL ,0x000A ); +if (ret) + goto restore_cache; +msleep (100 ); -regmap_write (regmap,RT1015_PWR_STATE_CTRL ,0x000C ); + ret =regmap_write (regmap,RT1015_PWR_STATE_CTRL ,0x000C ); +if (ret) + goto restore_cache; +msleep (100 ); -regmap_write (regmap,RT1015_CLSD_INTERNAL8 ,0x2028 ); -regmap_write (regmap,RT1015_CLSD_INTERNAL9 ,0x0140 ); -regmap_write (regmap,RT1015_PWR_STATE_CTRL ,0x000D ); + ret =regmap_write (regmap,RT1015_CLSD_INTERNAL8 ,0x2028 ); +if (ret) + goto restore_cache; + + ret =regmap_write (regmap,RT1015_CLSD_INTERNAL9 ,0x0140 ); +if (ret) + goto restore_cache; + + ret =regmap_write (regmap,RT1015_PWR_STATE_CTRL ,0x000D ); +if (ret) + goto restore_cache; +msleep (300 ); -regmap_write (regmap,RT1015_PWR_STATE_CTRL ,0x0008 ); -regmap_write (regmap,RT1015_SYS_RST1 ,0x05F5 ); -regmap_write (regmap,RT1015_CLK_DET ,0x8000 ); + ret =regmap_write (regmap,RT1015_PWR_STATE_CTRL ,0x0008 ); +if (ret) + goto restore_cache; + + ret =regmap_write (regmap,RT1015_SYS_RST1 ,0x05F5 ); +if (ret) + goto restore_cache; + + ret =regmap_write (regmap,RT1015_CLK_DET ,0x8000 ); + +restore_cache:regcache_cache_bypass (regmap, false);regcache_mark_dirty (regmap); -regcache_sync (regmap); + sync_ret =regcache_sync (regmap); +if (!ret) + ret = sync_ret;snd_soc_dapm_mutex_unlock (&component->dapm); + +return ret; } static int rt1015_bypass_boost_put(struct snd_kcontrol *kcontrol,
@@ -528,6 +565,8 @@ static int rt1015_bypass_boost_put(struct snd_kcontrol *kcontrol,snd_soc_kcontrol_component (kcontrol);struct rt1015_priv *rt1015 =snd_soc_component_get_drvdata (component); +int bypass_boost = rt1015->bypass_boost; +int ret;if (rt1015->dac_is_used) {dev_err (component->dev,"DAC is being used!\n" );
@@ -537,13 +576,23 @@ static int rt1015_bypass_boost_put(struct snd_kcontrol *kcontrol, rt1015->bypass_boost = ucontrol->value.integer.value[0 ];if (rt1015->bypass_boost == RT1015_Bypass_Boost && !rt1015->cali_done) { -rt1015_calibrate (rt1015); - rt1015->cali_done =1 ; + ret =rt1015_calibrate (rt1015); +if (ret) + goto restore_boost; + + ret =regmap_write (rt1015->regmap,RT1015_MONO_DYNA_CTRL , +0x0010 ); +if (ret) + goto restore_boost; -regmap_write (rt1015->regmap,RT1015_MONO_DYNA_CTRL ,0x0010 ); + rt1015->cali_done =1 ; }return 0 ; + +restore_boost: + rt1015->bypass_boost = bypass_boost; +return ret; }static const char *const rt1015_dac_output_vol_select[] = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 408/816 kernfs: dont repeat or skip an entry when readdir resumes
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shakeel Butt <[email protected]>
[ Upstream commit 5ebcb578adeec7407dd501108ab2f423ca8e3e55 ]
readdir keeps its place as a name hash in ctx->pos and pins the entry in file->private_data. If that entry is gone when the listing comes back, kernfs_dir_pos() searches the rbtree for the hash and keeps whatever node the descent stopped on. That is the entry before or after the missing one, depending on the shape of the tree.
Landing before it repeats an entry the previous getdents(2) call already reported. Landing after it, kernfs_dir_next_pos() calls rb_next() and steps over an unreported entry.
With children A(10), B(20), C(30):
report A, ctx->pos = 10
A removed
kernfs_dir_next_pos(10, A)
A is gone, the search for 10 stops at B
rb_next(B) -> C, so B is never reported
Only the repeat happens today, between two getdents(2) calls. The skip needs the pinned entry to go away inside one call, which the next patch allows when it drops kernfs_rwsem around dir_emit().
Before the commit 4e4d6d860b93 the descent kept a node only on the way left, which is a search for the first entry at or after the hash. That commit moved the assignment to the top of the loop, where it runs on right turns too. Restore that search, and step forward only when the pinned entry is still there rather than when the hash matches, since two entries in one directory can share a hash.
While here, kernfs_dir_next_pos() called the hash @ino. It is never an inode number, so name it @hash.
--- fs/kernfs/dir.c | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-)
fs/kernfs/dir.c +28 -10
@@ -1796,27 +1796,42 @@ static int kernfs_dir_fop_release(struct inode *inode, struct file *filp)return 0 ; } +/* +* Find where a listing left off. @resumed says whether @pos is still that +* entry; if not, the first entry at or after @hash is returned instead. +*/ static struct kernfs_node *kernfs_dir_pos (const void *ns, -struct kernfs_node *parent,loff_t hash,struct kernfs_node *pos) +struct kernfs_node *parent,loff_t hash,struct kernfs_node *pos, +bool *resumed) { +if (resumed) + *resumed = false;if (pos) {int valid =kernfs_active (pos) && pos->parent == parent && hash == pos->hash;kernfs_put (pos);if (!valid) pos =NULL ; +else if (resumed) + *resumed = true; }if (!pos && (hash >1 ) && (hash <INT_MAX )) {struct rb_node *node = parent->dir.children.rb_node; + +/* +* Keep a node only on the way left, so the search ends on the +* first entry at or after @hash. The empty name sorts before +* every entry sharing the hash, so it lands on the first. +*/ while (node) { - pos =rb_to_kn (node); +struct kernfs_node *kn =rb_to_kn (node); -if (hash < pos->hash) +if (kernfs_name_compare (hash,"" , ns, kn) <0 ) { + pos = kn; node = node->rb_left; -else if (hash > pos->hash) + }else { node = node->rb_right; -else -break ; + } } }/* Skip over entries which are dying/dead or in the wrong namespace */
@@ -1831,10 +1846,13 @@ static struct kernfs_node *kernfs_dir_pos(const void *ns, }static struct kernfs_node *kernfs_dir_next_pos (const void *ns, -struct kernfs_node *parent,ino_t ino,struct kernfs_node *pos) +struct kernfs_node *parent,loff_t hash,struct kernfs_node *pos) { - pos =kernfs_dir_pos (ns, parent, ino, pos); -if (pos) { +bool resumed; + + pos =kernfs_dir_pos (ns, parent, hash, pos, &resumed); +/* Step over @pos only if it survived; two entries can share a hash. */ +if (pos && resumed) { do { struct rb_node *node = rb_next(&pos->rb); if (!node)
@@ -1863,7 +1881,7 @@ static int kernfs_fop_readdir(struct file *file, struct dir_context *ctx)if (kernfs_ns_enabled (parent)) ns =kernfs_info (dentry->d_sb)->ns; -for (pos =kernfs_dir_pos (ns, parent, ctx->pos, pos); +for (pos =kernfs_dir_pos (ns, parent, ctx->pos, pos,NULL ); pos; pos =kernfs_dir_next_pos (ns, parent, ctx->pos, pos)) {const char *name = pos->name;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 409/816 ASoC: SOF: amd: fix amd_sof_acp_remove() teardown ordering
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vijendar Mukunda <[email protected]>
[ Upstream commit db2167f2e3f72db64d01356cc9f2924d32fd5a51 ]
Call free_irq() before amd_sof_sdw_exit() in amd_sof_acp_remove(). amd_sof_sdw_exit() sets adata->sdw to NULL; if an IRQ fires between that point and the subsequent free_irq(), acp_irq_handler() may dereference the now-NULL pdev[] pointer, causing a use-after-free.
--- sound/soc/sof/amd/acp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
sound/soc/sof/amd/acp.c +3 -3
@@ -970,12 +970,12 @@ void amd_sof_acp_remove(struct snd_sof_dev *sdev)if (adata->smn_dev)pci_dev_put (adata->smn_dev); -if (adata->sdw) -amd_sof_sdw_exit (sdev); -if (sdev->ipc_irq)free_irq (sdev->ipc_irq, sdev); +if (adata->sdw) +amd_sof_sdw_exit (sdev); +if (adata->dmic_dev)platform_device_unregister (adata->dmic_dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 410/816 ASoC: SOF: amd: fix amd_sof_acp_probe() error unwind ordering
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vijendar Mukunda <[email protected]>
[ Upstream commit b6aaef8ca8c305170de83e621c7e16d56731312a ]
Call amd_sof_sdw_exit() after free_irq() in the free_ipc_irq error label of amd_sof_acp_probe(). Without this, an IRQ that fires between sdw context teardown and free_irq() can dereference freed SoundWire resources.
--- sound/soc/sof/amd/acp.c | 2 ++ 1 file changed, 2 insertions(+)
sound/soc/sof/amd/acp.c +2 -0
@@ -955,6 +955,8 @@ int amd_sof_acp_probe(struct snd_sof_dev *sdev) free_ipc_irq:free_irq (sdev->ipc_irq, sdev); +if (adata->sdw) +amd_sof_sdw_exit (sdev); free_smn_dev:pci_dev_put (adata->smn_dev); unregister_dev:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 411/816 cxl/cdat: Fix uninitialized stack use in bandwidth gathering
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guixin Liu <[email protected]>
[ Upstream commit 97b74de26c81885a6447f5fe87641a2a136f8c7c ]
cxl_endpoint_gather_bandwidth() and cxl_switch_gather_bandwidth() declare access_coordinate arrays on the stack and rely on their helpers to fill them. The helpers assign only the bandwidth members, and the combine step assigns even those only when both inputs are non-zero. The latency members are summed from stack residue on every call, and the bandwidth members keep that residue into the region access coordinate sysfs attributes when the endpoint CDAT reports no bandwidth.
Zero initialize the arrays. Zero is the value this code already uses for "not reported", so an unset member now reads back as unknown rather than as a plausible number.
Found by code inspection. Tested on a QEMU CXL topology with two endpoints sharing a switch upstream link and HMAT generic-port coordinates for the host bridge, which the calculation requires to run at all: with temporary printk at the combine sites, the unpatched kernel summed 0xfefefefe, the CONFIG_INIT_STACK_ALL_PATTERN stack filler, into the latency members, while the patched kernel reports the CDAT latency values there.
--- drivers/cxl/core/cdat.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/cxl/core/cdat.c +4 -4
@@ -629,9 +629,9 @@ static int cxl_endpoint_gather_bandwidth(struct cxl_region *cxlr,struct cxl_port *endpoint =to_cxl_port (cxled->cxld.dev.parent);struct cxl_port *parent_port =to_cxl_port (endpoint->dev.parent);struct cxl_port *gp_port =to_cxl_port (parent_port->dev.parent); -struct access_coordinate pci_coord[ACCESS_COORDINATE_MAX ]; -struct access_coordinate sw_coord[ACCESS_COORDINATE_MAX ]; -struct access_coordinate ep_coord[ACCESS_COORDINATE_MAX ]; +struct access_coordinate pci_coord[ACCESS_COORDINATE_MAX ] = { }; +struct access_coordinate sw_coord[ACCESS_COORDINATE_MAX ] = { }; +struct access_coordinate ep_coord[ACCESS_COORDINATE_MAX ] = { };struct cxl_memdev *cxlmd =cxled_to_memdev (cxled);struct cxl_dev_state *cxlds = cxlmd->cxlds;struct pci_dev *pdev =to_pci_dev (cxlds->dev);
@@ -754,7 +754,7 @@ static struct xarray *cxl_switch_gather_bandwidth(struct cxl_region *cxlr, { struct xarray *res_xa __free(free_perf_xa) =kzalloc (sizeof (*res_xa),GFP_KERNEL ); -struct access_coordinate coords[ACCESS_COORDINATE_MAX ]; +struct access_coordinate coords[ACCESS_COORDINATE_MAX ] = { };struct cxl_perf_ctx *ctx, *us_ctx;unsigned long index, us_index;int dev_count =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 412/816 cxl/region: Unregister the pmem region when the bridge is unbound
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guixin Liu <[email protected]>
[ Upstream commit bb26797c08d408ea7e8d3625045f0fe28714a425 ]
Removing cxl_acpi unbinds the nvdimm bridge before the regions it serves. A region probe can therefore register its cxl_pmem_region and only then find the bridge unbound, which leaves the new device with nothing to remove it.
The orphan outlives the teardown and pins its region and its memdevs, so a later cxl_acpi bind renumbers the root port, ports, endpoints, decoders and the memdev.
Unregister the cxl_pmem_region when the bridge is unbound.
Found by code inspection. Racing a cxl_region bind against a cxl_acpi unbind leaked a pmem_region device on 12 of 12 attempts, and none with this patch.
--- drivers/cxl/core/region.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/cxl/core/region.c +4 -2
@@ -3170,12 +3170,14 @@ static int devm_cxl_add_pmem_region(struct cxl_region *cxlr) dev_name(dev)); scoped_guard(device, &cxl_nvb->dev) { -if (cxl_nvb->dev.driver) +if (cxl_nvb->dev.driver) { rc =devm_add_action_or_reset (&cxl_nvb->dev, cxlr_pmem_unregister, cxlr_pmem); -else + }else { rc = -ENXIO ; +cxlr_pmem_unregister (cxlr_pmem); + } }if (rc)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 413/816 drm/connector: hdmi: Handle reset() state allocation failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cristian Ciocaltea <[email protected]>
[ Upstream commit 54acd0c74eba2a2c9a726856f5fdc6f9e74ea2e1 ]
In drmm_connector_hdmi_init(), if the reset callback fails to allocate memory, e.g. inside drm_atomic_helper_connector_reset(), connector->state will remain NULL. This is unconditionally passed to drm_connector_attach_max_bpc_property(), leading to a NULL pointer dereference.
Bail out with -ENOMEM if the reset callback leaves connector->state unset.
--- drivers/gpu/drm/drm_connector.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_connector.c +4 -1
@@ -526,8 +526,11 @@ int drmm_connector_hdmi_init(struct drm_device *dev,* drm_connector_attach_max_bpc_property() requires the * connector to have a state. */ -if (connector->funcs->reset) +if (connector->funcs->reset) { connector->funcs->reset (connector); +if (!connector->state) +return -ENOMEM ; + }drm_connector_attach_max_bpc_property (connector,8 , max_bpc); connector->max_bpc = max_bpc;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 414/816 i3c: mipi-i3c-hci: Process multiple IBIs per interrupt
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Hunter <[email protected]>
[ Upstream commit 5fbd0790af9484c251341e3ba2ebbb2887c570c8 ]
INTR_IBI_READY indicates that one or more IBI Status Descriptors are present in the IBI ring. After clearing interrupt status, the interrupt handler processes only a single IBI even though additional IBIs may already be queued.
The controller does not reassert INTR_IBI_READY solely because entries remain in the ring after interrupt status has been cleared. Consequently, the remaining IBIs are not processed until some later interrupt occurs, and can accumulate if IBIs arrive more often than the interrupt handler runs.
Process all IBIs that are pending when the handler runs: capture the IBI enqueue pointer up front and continue until the dequeue pointer reaches that position.
--- drivers/i3c/master/mipi-i3c-hci/dma.c | 40 +++++++++++++++++---------- 1 file changed, 26 insertions(+), 14 deletions(-)
drivers/i3c/master/mipi-i3c-hci/dma.c +26 -14
@@ -603,24 +603,23 @@ static void hci_dma_recycle_ibi_slot(struct i3c_hci *hci,i3c_generic_ibi_recycle_slot (dev_ibi->pool, slot); } -static void hci_dma_process_ibi (struct i3c_hci *hci,struct hci_rh_data *rh) +static bool hci_dma_process_ibi (struct i3c_hci *hci,struct hci_rh_data *rh, +u32 *op1_val,unsigned int enq_ptr) {struct i3c_dev_desc *dev;struct i3c_hci_dev_data *dev_data;struct hci_dma_dev_ibi_data *dev_ibi;struct i3c_ibi_slot *slot; -u32 op1_val, op2_val, ibi_status_error; -unsigned int ptr, enq_ptr, deq_ptr; +u32 ibi_status_error; +unsigned int ptr, deq_ptr;unsigned int ibi_size, ibi_chunks, ibi_data_offset, first_part;int ibi_addr, last_ptr;void *ring_ibi_data;dma_addr_t ring_ibi_data_dma; - op1_val =rh_reg_read (RING_OPERATION1 ); - deq_ptr =FIELD_GET (RING_OP1_IBI_DEQ_PTR , op1_val); - - op2_val =rh_reg_read (RING_OPERATION2 ); - enq_ptr =FIELD_GET (RING_OP2_IBI_ENQ_PTR , op2_val); + deq_ptr =FIELD_GET (RING_OP1_IBI_DEQ_PTR , *op1_val); +if (deq_ptr == enq_ptr) +return false; ibi_status_error =0 ; ibi_addr =-1 ;
@@ -668,7 +667,7 @@ static void hci_dma_process_ibi(struct i3c_hci *hci, struct hci_rh_data *rh)if (last_ptr ==-1 ) {/* this IBI sequence is not yet complete */ DBG ("no LAST_STATUS available (e=%d d=%d)" , enq_ptr, deq_ptr); -return ; +return false; } deq_ptr = last_ptr +1 ; deq_ptr %= rh->ibi_status_entries;
@@ -741,10 +740,10 @@ static void hci_dma_process_ibi(struct i3c_hci *hci, struct hci_rh_data *rh) done:/* take care to update the ibi dequeue pointer atomically */ spin_lock (&rh->lock); - op1_val =rh_reg_read (RING_OPERATION1 ); - op1_val &= ~RING_OP1_IBI_DEQ_PTR ; - op1_val |=FIELD_PREP (RING_OP1_IBI_DEQ_PTR , deq_ptr); -rh_reg_write (RING_OPERATION1 , op1_val); + *op1_val =rh_reg_read (RING_OPERATION1 ); + *op1_val &= ~RING_OP1_IBI_DEQ_PTR ; + *op1_val |=FIELD_PREP (RING_OP1_IBI_DEQ_PTR , deq_ptr); +rh_reg_write (RING_OPERATION1 , *op1_val);spin_unlock (&rh->lock);/* update the chunk pointer */
@@ -753,6 +752,19 @@ static void hci_dma_process_ibi(struct i3c_hci *hci, struct hci_rh_data *rh)/* and tell the hardware about freed chunks */ rh_reg_write (CHUNK_CONTROL ,rh_reg_read (CHUNK_CONTROL ) + ibi_chunks); + +return true; +} + +static void hci_dma_drain_ibi_ring (struct i3c_hci *hci,struct hci_rh_data *rh) +{ +u32 op1_val =rh_reg_read (RING_OPERATION1 ); +u32 op2_val =rh_reg_read (RING_OPERATION2 ); +unsigned int enq_ptr =FIELD_GET (RING_OP2_IBI_ENQ_PTR , op2_val); + +/* Loop is bounded by enq_ptr. Further IBIs will re-assert INTR_IBI_READY */ +while (hci_dma_process_ibi (hci, rh, &op1_val, enq_ptr)) + ; }static bool hci_dma_irq_handler (struct i3c_hci *hci,unsigned int mask)
@@ -777,7 +789,7 @@ static bool hci_dma_irq_handler(struct i3c_hci *hci, unsigned int mask)rh_reg_write (INTR_STATUS , status);if (status &INTR_IBI_READY ) -hci_dma_process_ibi (hci, rh); +hci_dma_drain_ibi_ring (hci, rh);if (status & (INTR_TRANSFER_COMPLETION |INTR_TRANSFER_ERR ))hci_dma_xfer_done (hci, rh);if (status &INTR_RING_OP )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 415/816 mm/gup: honour FOLL_PIN in NOMMU __get_user_pages_locked()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Greg Kroah-Hartman <[email protected]>
[ Upstream commit da01399b90a73cd00b502f7903fa5acbfac4a103 ]
The !CONFIG_MMU implementation of __get_user_pages_locked() takes a bare get_page() reference for each page regardless of foll_flags:
if (pages[i]) get_page(pages[i]);
This is reached from pin_user_pages*() with FOLL_PIN set. unpin_user_page() is shared between MMU and NOMMU configurations and unconditionally calls gup_put_folio(..., FOLL_PIN), which subtracts GUP_PIN_COUNTING_BIAS (1024) from the folio refcount.
This means that pin adds 1, and then unpin will subtract 1024.
If a user maps a page (refcount 1), registers it 1023 times as an io_uring fixed buffer (1023 pin_user_pages calls -> refcount 1024), then
unregisters: the first unpin_user_page subtracts 1024, refcount hits 0, the page is freed and returned to the buddy allocator. The remaining 1022 unpins write into whatever was reallocated, and the user's VMA still maps the freed page (NOMMU has no MMU to invalidate it). Reallocating the page for an io_uring pbuf_ring then lets userspace corrupt the new owner's data through the stale mapping.
Use try_grab_folio() which adds GUP_PIN_COUNTING_BIAS for FOLL_PIN and 1 for FOLL_GET, mirroring the CONFIG_MMU path so pin and unpin are symmetric. Keep supporting the traditional behavior where users specify a pages array but don't set FOLL_GET.
While at it, don't return NULL pointers in the page array,
as this is really not expected for GUP users; instead, just fail and return -EFAULT.
[ david: support traditional behavior with no FOLL_GET, extend
description ]
--- mm/gup.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
mm/gup.c +14 -3
@@ -2058,6 +2058,7 @@ static long __get_user_pages_locked(struct mm_struct *mm, unsigned long start,struct vm_area_struct *vma;bool must_unlock = false;unsigned long vm_flags; +int ret, err = -EFAULT ;long i;if (!nr_pages)
@@ -2074,6 +2075,10 @@ static long __get_user_pages_locked(struct mm_struct *mm, unsigned long start, *locked =1 ; } +/* See the MMU variant: support the traditional behavior. */ +if (pages && !(foll_flags &FOLL_PIN )) + foll_flags |=FOLL_GET ; +/* calculate required read or write permissions. * If FOLL_FORCE is set, we only require the "MAY" flags. */
@@ -2094,8 +2099,14 @@ static long __get_user_pages_locked(struct mm_struct *mm, unsigned long start,if (pages) { pages[i] =virt_to_page ((void *)start); -if (pages[i]) -get_page (pages[i]); +if (!pages[i]) +break ; + ret =try_grab_folio (page_folio (pages[i]),1 , foll_flags); +if (unlikely (ret)) { + pages[i] =NULL ; + err = ret; +break ; + } } start = (start +PAGE_SIZE ) &PAGE_MASK ;
@@ -2106,7 +2117,7 @@ static long __get_user_pages_locked(struct mm_struct *mm, unsigned long start, *locked = 0; } -return i ? : -EFAULT ; +return i ? : err; }#endif /* !CONFIG_MMU */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 416/816 wifi: rtl8xxxu: unwind incomplete receive startup
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kim Wooseok <[email protected]>
[ Upstream commit 4c58fb8944a2cfbe5506534de0cf58646408d31a ]
rtl8xxxu_start() allocates and submits RX URBs one at a time. If a later allocation fails, the error path frees the TX pool but leaves earlier RX requests active. A partial TX or RX allocation failure can also leave ret at zero, so start reports success despite the incomplete setup.
Allocate the RX pool before submitting any of it, and return ENOMEM whenever a pool allocation fails. Pass start errors through rtl8xxxu_stop(), including interrupt URB submission failures, so the existing stop path cancels work and releases both active requests and partially allocated pools.
Share the submission loop with the RX worker. Both callers keep requests that fail with ENOMEM/EAGAIN. For a fatal error during startup, free the rest of the unsubmitted batch and return the error so start can unwind. In the worker, free only the failed request and continue with the rest of the batch.
Keep the allocation loop in a small helper so the setup and error paths in start remain easy to follow.
On an RTL8192EU, I exercised every error exit in rtl8xxxu_start() except interrupt-URB allocation and submission failures, which this adapter does not use.
--- drivers/net/wireless/realtek/rtl8xxxu/core.c | 96 +++++++++++--------- 1 file changed, 54 insertions(+), 42 deletions(-)
drivers/net/wireless/realtek/rtl8xxxu/core.c +54 -42
@@ -61,6 +61,7 @@ MODULE_PARM_DESC(dma_agg_pages, "Set DMA aggregation pages (range 1-127, 0 to di#define RTL8XXXU_TX_URB_LOW_WATER 25#define RTL8XXXU_TX_URB_HIGH_WATER 32 +static void rtl8xxxu_stop (struct ieee80211_hw *hw,bool suspend);static int rtl8xxxu_submit_rx_urb (struct rtl8xxxu_priv *priv,struct rtl8xxxu_rx_urb *rx_urb);
@@ -5858,6 +5859,28 @@ static void rtl8xxxu_free_rx_resources(struct rtl8xxxu_priv *priv)spin_unlock_irqrestore (&priv->rx_urb_lock, flags); } +static int rtl8xxxu_alloc_rx_urbs (struct rtl8xxxu_priv *priv) +{ +struct rtl8xxxu_rx_urb *rx_urb; +int i; + +/* No RX work is active until the complete pool has been allocated. */ +for (i =0 ; i <RTL8XXXU_RX_URBS ; i++) { + rx_urb =kmalloc (sizeof (struct rtl8xxxu_rx_urb ),GFP_KERNEL ); +if (!rx_urb) +return -ENOMEM ; + +usb_init_urb (&rx_urb->urb); +INIT_LIST_HEAD (&rx_urb->list); + rx_urb->hw = priv->hw; + +list_add_tail (&rx_urb->list, &priv->rx_urb_pending_list); + priv->rx_urb_pending_count++; + } + +return 0 ; +} +static void rtl8xxxu_queue_rx_urb (struct rtl8xxxu_priv *priv,struct rtl8xxxu_rx_urb *rx_urb) {
@@ -5885,32 +5908,21 @@ static void rtl8xxxu_queue_rx_urb(struct rtl8xxxu_priv *priv,spin_unlock_irqrestore (&priv->rx_urb_lock, flags); } -static void rtl8xxxu_rx_urb_work (struct work_struct *work) +static int rtl8xxxu_submit_rx_urbs (struct rtl8xxxu_priv *priv,bool startup) { -struct rtl8xxxu_priv *priv;struct rtl8xxxu_rx_urb *rx_urb, *tmp; -struct list_head local;unsigned long flags; +LIST_HEAD (local);int ret; - priv = container_of(work, struct rtl8xxxu_priv, rx_urb_wq); -INIT_LIST_HEAD (&local); -spin_lock_irqsave (&priv->rx_urb_lock, flags); -list_splice_init (&priv->rx_urb_pending_list, &local); priv->rx_urb_pending_count =0 ; -spin_unlock_irqrestore (&priv->rx_urb_lock, flags);list_for_each_entry_safe (rx_urb, tmp, &local, list) {list_del_init (&rx_urb->list); ret =rtl8xxxu_submit_rx_urb (priv, rx_urb); -/* -* If out of memory or temporary error, put it back on the -* queue and try again. Otherwise the device is dead/gone -* and we should drop it. -*/ switch (ret) {case 0 :break ;
@@ -5919,11 +5931,29 @@ static void rtl8xxxu_rx_urb_work(struct work_struct *work)rtl8xxxu_queue_rx_urb (priv, rx_urb);break ;default : +usb_free_urb (&rx_urb->urb); +if (startup) + goto free_remaining;dev_warn (&priv->udev->dev,"failed to requeue urb with error %i\n" , ret); -usb_free_urb (&rx_urb->urb); } } + +return 0 ; + +free_remaining: +list_for_each_entry_safe (rx_urb, tmp, &local, list) { +list_del (&rx_urb->list); +usb_free_urb (&rx_urb->urb); + } +return ret; +} + +static void rtl8xxxu_rx_urb_work (struct work_struct *work) +{ + struct rtl8xxxu_priv *priv = container_of(work, struct rtl8xxxu_priv, rx_urb_wq); + +rtl8xxxu_submit_rx_urbs (priv, false); }/*
@@ -7429,7 +7459,6 @@ static void rtl8xxxu_watchdog_callback(struct work_struct *work)static int rtl8xxxu_start (struct ieee80211_hw *hw) {struct rtl8xxxu_priv *priv = hw->priv; -struct rtl8xxxu_rx_urb *rx_urb;struct rtl8xxxu_tx_urb *tx_urb;unsigned long flags;int ret, i;
@@ -7444,14 +7473,13 @@ static int rtl8xxxu_start(struct ieee80211_hw *hw)if (priv->usb_interrupts) { ret =rtl8xxxu_submit_int_urb (hw);if (ret) - goto exit; + goto error_out; }for (i =0 ; i <RTL8XXXU_TX_URBS ; i++) { tx_urb =kmalloc (sizeof (struct rtl8xxxu_tx_urb ),GFP_KERNEL );if (!tx_urb) { -if (!i) - ret = -ENOMEM ; + ret = -ENOMEM ; goto error_out; }
@@ -7462,31 +7490,21 @@ static int rtl8xxxu_start(struct ieee80211_hw *hw) priv->tx_urb_free_count++; } + ret =rtl8xxxu_alloc_rx_urbs (priv); +if (ret) + goto error_out; + priv->tx_stopped = false;spin_lock_irqsave (&priv->rx_urb_lock, flags); priv->shutdown = false;spin_unlock_irqrestore (&priv->rx_urb_lock, flags); -for (i =0 ; i <RTL8XXXU_RX_URBS ; i++) { - rx_urb =kmalloc (sizeof (struct rtl8xxxu_rx_urb ),GFP_KERNEL ); -if (!rx_urb) { -if (!i) - ret = -ENOMEM ; - - goto error_out; - } -usb_init_urb (&rx_urb->urb); -INIT_LIST_HEAD (&rx_urb->list); - rx_urb->hw = hw; - - ret =rtl8xxxu_submit_rx_urb (priv, rx_urb); -if (ret) -rtl8xxxu_queue_rx_urb (priv, rx_urb); - } + ret =rtl8xxxu_submit_rx_urbs (priv, true); +if (ret) + goto error_out;schedule_delayed_work (&priv->ra_watchdog,2 *HZ ); -exit:/* * Accept all data and mgmt frames */
@@ -7499,13 +7517,7 @@ static int rtl8xxxu_start(struct ieee80211_hw *hw)return ret; error_out: -rtl8xxxu_free_tx_resources (priv); -/* -* Disable all data and mgmt frames -*/ -rtl8xxxu_write16 (priv,REG_RXFLTMAP2 ,0x0000 ); -rtl8xxxu_write16 (priv,REG_RXFLTMAP0 ,0x0000 ); - +rtl8xxxu_stop (hw, false);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 417/816 wifi: rtl8xxxu: preserve RX requests across recoverable transfer errors
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kim Wooseok <[email protected]>
[ Upstream commit 2f77c66694108785a1f6ae6c5de06453e7f7a91f ]
rtl8xxxu resubmits completed RX requests when more than eight URBs are waiting on the pending list. It starts with 32 URBs, but frees them on completion errors. After enough errors, the remaining pool can no longer reach the submission threshold. Reception then stays stopped even after the errors end. Temporary submission failures can leave a small batch waiting with no further work scheduled, too.
Keep the URB when a completion reports EPROTO, EILSEQ, ETIME, EOVERFLOW, ECOMM or ENOSR. Free its receive buffer and return the request to the same pending list used by normal completions. ENOMEM/EAGAIN from startup or worker submission uses this path as well, so a submission failure cannot strand a request during recovery.
Use one delayed work item to submit the pending requests. An error queues a retry after 100 ms without moving an existing reservation back. If a normal completion takes the pending count above eight, mod_delayed_work(..., 0) brings the work forward. This limits repeated retries when reception is not progressing, while allowing normal traffic to replenish the pool promptly. The 100 ms delay is therefore not a minimum wait for each failed URB.
Keep the shutdown check, queue insertion and scheduling under the RX lock. Stop sets shutdown under that lock, cancels the delayed work synchronously, then drains active and pending requests. Cancellation and device removal continue to free their URBs.
--- drivers/net/wireless/realtek/rtl8xxxu/core.c | 46 ++++++++++++------- .../net/wireless/realtek/rtl8xxxu/rtl8xxxu.h | 2 +- 2 files changed, 30 insertions(+), 18 deletions(-)
drivers/net/wireless/realtek/rtl8xxxu/core.c +29 -17
@@ -57,6 +57,7 @@ MODULE_PARM_DESC(dma_agg_pages, "Set DMA aggregation pages (range 1-127, 0 to di#define USB_VENDOR_ID_REALTEK 0x0bda#define RTL8XXXU_RX_URBS 32#define RTL8XXXU_RX_URB_PENDING_WATER 8 +#define RTL8XXXU_RX_URB_RETRY_DELAY_MS 100#define RTL8XXXU_TX_URBS 64#define RTL8XXXU_TX_URB_LOW_WATER 25#define RTL8XXXU_TX_URB_HIGH_WATER 32
@@ -5882,9 +5883,8 @@ static int rtl8xxxu_alloc_rx_urbs(struct rtl8xxxu_priv *priv) }static void rtl8xxxu_queue_rx_urb (struct rtl8xxxu_priv *priv, -struct rtl8xxxu_rx_urb *rx_urb) +struct rtl8xxxu_rx_urb *rx_urb,bool defer_schedule) { -struct sk_buff *skb;unsigned long flags;spin_lock_irqsave (&priv->rx_urb_lock, flags);
@@ -5892,16 +5892,13 @@ static void rtl8xxxu_queue_rx_urb(struct rtl8xxxu_priv *priv,if (!priv->shutdown) {list_add_tail (&rx_urb->list, &priv->rx_urb_pending_list); priv->rx_urb_pending_count++; -/* -* Arm the worker under rx_urb_lock so this is atomic with the -* shutdown check: moving it out of the lock would let a -* completion arm the work after rtl8xxxu_stop() canceled it. -*/ -if (priv->rx_urb_pending_count >RTL8XXXU_RX_URB_PENDING_WATER ) -schedule_work (&priv->rx_urb_wq); +/* Serialize scheduling with the shutdown check and cancellation. */ +if (defer_schedule) +schedule_delayed_work (&priv->rx_urb_wq, +msecs_to_jiffies (RTL8XXXU_RX_URB_RETRY_DELAY_MS )); +else if (priv->rx_urb_pending_count >RTL8XXXU_RX_URB_PENDING_WATER ) +mod_delayed_work (system_percpu_wq, &priv->rx_urb_wq,0 ); }else { - skb = (struct sk_buff *)rx_urb->urb.context; -dev_kfree_skb_irq (skb);usb_free_urb (&rx_urb->urb); }
@@ -5928,7 +5925,7 @@ static int rtl8xxxu_submit_rx_urbs(struct rtl8xxxu_priv *priv, bool startup)break ;case -ENOMEM :case -EAGAIN : -rtl8xxxu_queue_rx_urb (priv, rx_urb); +rtl8xxxu_queue_rx_urb (priv, rx_urb, true);break ;default :usb_free_urb (&rx_urb->urb);
@@ -5951,7 +5948,8 @@ static int rtl8xxxu_submit_rx_urbs(struct rtl8xxxu_priv *priv, bool startup)static void rtl8xxxu_rx_urb_work (struct work_struct *work) { - struct rtl8xxxu_priv *priv = container_of(work, struct rtl8xxxu_priv, rx_urb_wq); +struct rtl8xxxu_priv *priv =container_of (to_delayed_work (work), + struct rtl8xxxu_priv, rx_urb_wq);rtl8xxxu_submit_rx_urbs (priv, false); }
@@ -6607,10 +6605,24 @@ static void rtl8xxxu_rx_complete(struct urb *urb) skb =NULL ; rx_urb->urb.context =NULL ; -rtl8xxxu_queue_rx_urb (priv, rx_urb); +rtl8xxxu_queue_rx_urb (priv, rx_urb, false); }else {dev_dbg (dev,"%s: status %i\n" , __func__, urb->status); - goto cleanup; + +switch (urb->status) { +case -EPROTO : +case -EILSEQ : +case -ETIME : +case -EOVERFLOW : +case -ECOMM : +case -ENOSR : +dev_kfree_skb (skb); + urb->context =NULL ; +rtl8xxxu_queue_rx_urb (priv, rx_urb, true); +return ; +default : + goto cleanup; + } }return ;
@@ -7540,7 +7552,7 @@ static void rtl8xxxu_stop(struct ieee80211_hw *hw, bool suspend)* it drained via rtl8xxxu_submit_rx_urb(), so a worker still running * after the kill could submit a URB that escapes it. */ -cancel_work_sync (&priv->rx_urb_wq); +cancel_delayed_work_sync (&priv->rx_urb_wq);usb_kill_anchored_urbs (&priv->rx_anchor);usb_kill_anchored_urbs (&priv->tx_anchor);
@@ -7853,7 +7865,7 @@ static int rtl8xxxu_probe(struct usb_interface *interface,spin_lock_init (&priv->tx_urb_lock);INIT_LIST_HEAD (&priv->rx_urb_pending_list);spin_lock_init (&priv->rx_urb_lock); -INIT_WORK (&priv->rx_urb_wq, rtl8xxxu_rx_urb_work); +INIT_DELAYED_WORK (&priv->rx_urb_wq, rtl8xxxu_rx_urb_work);INIT_DELAYED_WORK (&priv->ra_watchdog, rtl8xxxu_watchdog_callback);INIT_DELAYED_WORK (&priv->update_beacon_work, rtl8xxxu_update_beacon_work_callback);skb_queue_head_init (&priv->c2hcmd_queue);
drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h +1 -1
@@ -1803,7 +1803,7 @@ struct rtl8xxxu_priv {struct list_head rx_urb_pending_list;int rx_urb_pending_count;bool shutdown; -struct work_struct rx_urb_wq; +struct delayed_work rx_urb_wq;u8 mac_addr[ETH_ALEN ];char chip_name[8 ];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 418/816 crypto: qat - hold cfg->lock when accessing config sections
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ahsan Atta <[email protected]>
[ Upstream commit cb3a1364fed9ea7b063e3ae026177a145abb5940 ]
adf_cfg_sec_find() walks the per-device section list without holding cfg->lock, and the returned section pointer is used later under the lock. A concurrent section deletion under cfg->lock (adf_cfg_del_all_except() on device down, or adf_cfg_dev_remove() on removal) can free the section first, leading to a use-after-free.
The debugfs dev_cfg reader has the same problem: qat_dev_cfg_show() walks both the section list and each section's param_head under the global qat_cfg_read_lock mutex, not the per-device cfg->lock used by the add and delete paths, so the two do not serialise. Updating an existing key frees the old key_val under cfg->lock, so even a config write concurrent with an open dev_cfg read can free an entry mid-walk, a wider window than section deletion alone.
Take cfg->lock around the section lookup in adf_cfg_add_key_value_param() and around the lookup and insert in adf_cfg_section_add(), and use down_read()/up_read(&cfg->lock) in the debugfs start/stop callbacks. Remove the now-unused qat_cfg_read_lock.
While here, return -ENOENT rather than -EFAULT when the section is not found; EFAULT (bad userspace address) is not meaningful for this case.
--- drivers/crypto/intel/qat/qat_common/adf_cfg.c | 49 +++++++++++-------- 1 file changed, 29 insertions(+), 20 deletions(-)
drivers/crypto/intel/qat/qat_common/adf_cfg.c +29 -20
@@ -1,6 +1,5 @@// SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0-only) /* Copyright(c) 2014 - 2020 Intel Corporation */ -#include <linux/mutex.h> #include <linux/slab.h> #include <linux/list.h> #include <linux/seq_file.h>
@@ -8,13 +7,11 @@#include "adf_cfg.h" #include "adf_common_drv.h" -static DEFINE_MUTEX (qat_cfg_read_lock); -static void *qat_dev_cfg_start (struct seq_file *sfile,loff_t *pos) {struct adf_cfg_device_data *dev_cfg = sfile->private; -mutex_lock (&qat_cfg_read_lock); +down_read (&dev_cfg->lock);return seq_list_start (&dev_cfg->sec_list, *pos); }
@@ -42,7 +39,9 @@ static void *qat_dev_cfg_next(struct seq_file *sfile, void *v, loff_t *pos)static void qat_dev_cfg_stop (struct seq_file *sfile,void *v) { -mutex_unlock (&qat_cfg_read_lock); +struct adf_cfg_device_data *dev_cfg = sfile->private; + +up_read (&dev_cfg->lock); }static const struct seq_operations qat_dev_cfg_sops = {
@@ -271,13 +270,10 @@ int adf_cfg_add_key_value_param(struct adf_accel_dev *accel_dev, enum adf_cfg_val_type type) {struct adf_cfg_device_data *cfg = accel_dev->cfg; +struct adf_cfg_section *section;struct adf_cfg_key_val *key_val; -struct adf_cfg_section *section =adf_cfg_sec_find (accel_dev, - section_name);char temp_val[ADF_CFG_MAX_VAL_LEN_IN_BYTES ]; - -if (!section) -return -EFAULT ; +int ret =0 ; key_val =kzalloc (sizeof (*key_val),GFP_KERNEL );if (!key_val)
@@ -310,20 +306,28 @@ int adf_cfg_add_key_value_param(struct adf_accel_dev *accel_dev,* anything (the newly created key_val is freed). */ down_write (&cfg->lock); + + section =adf_cfg_sec_find (accel_dev, section_name); +if (!section) { +kfree (key_val); + ret = -ENOENT ; + goto unlock; + } +if (!adf_cfg_key_val_get (accel_dev, section_name, key, temp_val)) {if (strncmp (temp_val, key_val->val,sizeof (temp_val))) {adf_cfg_keyval_remove (key, section); }else {kfree (key_val); - goto out; + goto unlock; } }adf_cfg_keyval_add (key_val, section); -out: +unlock:up_write (&cfg->lock); -return 0 ; +return ret; }EXPORT_SYMBOL_GPL (adf_cfg_add_key_value_param);
@@ -341,21 +345,26 @@ EXPORT_SYMBOL_GPL(adf_cfg_add_key_value_param);int adf_cfg_section_add (struct adf_accel_dev *accel_dev,const char *name) {struct adf_cfg_device_data *cfg = accel_dev->cfg; -struct adf_cfg_section *sec =adf_cfg_sec_find (accel_dev, name); +struct adf_cfg_section *sec; +int ret =0 ; -if (sec) -return 0 ; +down_write (&cfg->lock); + +if (adf_cfg_sec_find (accel_dev, name)) + goto unlock; sec =kzalloc (sizeof (*sec),GFP_KERNEL ); -if (!sec) -return -ENOMEM ; +if (!sec) { + ret = -ENOMEM ; + goto unlock; + }strscpy (sec->name, name,sizeof (sec->name));INIT_LIST_HEAD (&sec->param_head); -down_write (&cfg->lock);list_add_tail (&sec->list, &cfg->sec_list); +unlock:up_write (&cfg->lock); -return 0 ; +return ret; }EXPORT_SYMBOL_GPL (adf_cfg_section_add);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 419/816 serial: sh-sci: Unregister UART on sysfs setup failure
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
[ Upstream commit c5b33c86d86da3ccff8c05e2a28719e3ec933f70 ]
sci_probe_single() registers the UART port before sci_probe() creates the RX FIFO tuning attributes. If either device_create_file() call fails, probe returns an error without removing the port from the serial core. Device-managed resources are then released while the port remains registered.
Unregister the UART port before returning either sysfs creation error. If the second attribute fails, remove the first attribute before unregistering the port. Keep the existing probe failure policy and leave the successful initialization path unchanged.
This issue was identified during our ongoing static-analysis research while reviewing kernel code.
--- drivers/tty/serial/sh-sci.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/tty/serial/sh-sci.c +6 -2
@@ -3542,7 +3542,7 @@ static int sci_probe(struct platform_device *dev)if (sp->port.fifosize >1 ) { ret =device_create_file (&dev->dev, &dev_attr_rx_fifo_trigger);if (ret) -return ret; + goto err_remove_port; }if (sp->port.type ==PORT_SCIFA || sp->port.type ==PORT_SCIFB || sp->port.type ==PORT_HSCIF ) {
@@ -3552,7 +3552,7 @@ static int sci_probe(struct platform_device *dev)device_remove_file (&dev->dev, &dev_attr_rx_fifo_trigger); } -return ret; + goto err_remove_port; } }
@@ -3562,6 +3562,10 @@ static int sci_probe(struct platform_device *dev) sci_ports_in_use |=BIT (dev_id);return 0 ; + +err_remove_port: +uart_remove_one_port (&sci_uart_driver, &sp->port); +return ret; }static void sci_console_save (struct sci_port *s)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 420/816 bpf: Keep target extended until its last freplace link detaches
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuan Chen <[email protected]>
[ Upstream commit c43c348a84460b003fa757dd43d8c89848ae220d ]
The is_extended / prog_array_member_cnt protocol introduced by commit d6083f040d5d ("bpf: Prevent tailcall infinite loop caused by freplace") keeps a prog extended by a freplace program out of prog_array maps, and vice versa: once a tail call re-enters an extended subprogram, its tail_call_cnt resets on every execution and the loop never terminates.
But is_extended is a plain boolean, while one target prog can carry several freplace links at the same time, one on its entry and one on a global subprogram. __bpf_trampoline_unlink_prog() cleared is_extended whenever *any* freplace link detached, so detaching one of two links re-armed the unbounded loop through the remaining one.
Replace the is_extended boolean with a count of the freplace links attached to each target prog, so the target stays extended until its last link detaches. Also rename bpf_freplace_check_tgt_prog() to bpf_freplace_link_tgt_prog(), as the helper has never been a pure
check: it reserves the target prog on success.
--- include/linux/bpf.h | 4 ++-- kernel/bpf/arraymap.c | 2 +- kernel/bpf/trampoline.c | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-)
include/linux/bpf.h +2 -2
@@ -1513,10 +1513,9 @@ struct bpf_prog_aux {bool xdp_has_frags;bool exception_cb;bool exception_boundary; -bool is_extended;/* true if extended by freplace program */ bool changes_pkt_data;u64 prog_array_member_cnt;/* counts how many times as member of prog_array */ -struct mutex ext_mutex;/* mutex for is_extended and prog_array_member_cnt */ +struct mutex ext_mutex;/* mutex for freplace_link_cnt and prog_array_member_cnt */ struct bpf_arena *arena;/* BTF_KIND_FUNC_PROTO for valid attach_btf_id */ const struct btf_type *attach_func_proto;
@@ -1544,6 +1543,7 @@ struct bpf_prog_aux {struct bpf_map *cgroup_storage[MAX_BPF_CGROUP_STORAGE_TYPE ];char name[BPF_OBJ_NAME_LEN ];u64 (*bpf_exception_cb)(u64 cookie,u64 sp,u64 bp,u64 ,u64 ); +u16 freplace_link_cnt;/* counts freplace links extending this prog */ #ifdef CONFIG_SECURITY void *security;#endif
kernel/bpf/arraymap.c +1 -1
@@ -957,7 +957,7 @@ static void *prog_fd_array_get_ptr(struct bpf_map *map, }mutex_lock (&prog->aux->ext_mutex); - is_extended = prog->aux->is_extended; + is_extended = prog->aux->freplace_link_cnt >0 ;if (!is_extended) prog->aux->prog_array_member_cnt++;mutex_unlock (&prog->aux->ext_mutex);
kernel/bpf/trampoline.c +4 -4
@@ -532,7 +532,7 @@ static enum bpf_tramp_prog_type bpf_attach_type_to_tramp(struct bpf_prog *prog) } } -static int bpf_freplace_check_tgt_prog (struct bpf_prog *tgt_prog) +static int bpf_freplace_link_tgt_prog (struct bpf_prog *tgt_prog) {struct bpf_prog_aux *aux = tgt_prog->aux;
@@ -546,7 +546,7 @@ static int bpf_freplace_check_tgt_prog(struct bpf_prog *tgt_prog)*/ return -EBUSY ; - aux->is_extended = true; + aux->freplace_link_cnt++;return 0 ; }
@@ -573,7 +573,7 @@ static int __bpf_trampoline_link_prog(struct bpf_tramp_link *link,/* Cannot attach extension if fentry/fexit are in use. */ if (cnt)return -EBUSY ; - err =bpf_freplace_check_tgt_prog (tgt_prog); + err =bpf_freplace_link_tgt_prog (tgt_prog);if (err)return err; tr->extension_prog = link->link.prog;
@@ -628,7 +628,7 @@ static int __bpf_trampoline_unlink_prog(struct bpf_tramp_link *link, tr->extension_prog->bpf_func, NULL); tr->extension_prog =NULL ;guard (mutex)(&tgt_prog->aux->ext_mutex); - tgt_prog->aux->is_extended = false; + tgt_prog->aux->freplace_link_cnt--;return err; }hlist_del_init (&link->tramp_hlist);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 421/816 bpf: Check fastcall stack contract once for all stack accesses
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kumar Kartikeya Dwivedi <[email protected]>
[ Upstream commit ec3a69e7c021cd826be8886ba6af4ee3147788fb ]
When the verifier inlines a bpf_fastcall helper or kfunc, it removes the spill/fill pairs that clang emitted around the call and lowers the subprogram's stack depth so that their slots are no longer part of the frame. This is only safe if nothing else accesses those slots or any slot below them. check_fastcall_stack_contract() enforces this: an access to that region from outside a fastcall pattern disables the rewrite for the subprogram. It is called from the four stack load and store paths, and two kinds of access escape it.
Stack buffers passed to helpers and kfuncs are validated by check_stack_range_initialized(), which does not call it. If such a buffer is the only other access to the region, the rewrite is still applied, the JIT reserves a frame that does not contain the buffer, and the helper reads or writes live kernel stack below the program's frame. For example, without CAP_PERFMON:
*(u64 *)(r10 - 8) = r1; call bpf_get_smp_processor_id; r1 = *(u64 *)(r10 - 8); r2 = 0; r3 = r10; r3 += -64; r4 = 8; call bpf_skb_load_bytes;
is accepted with a stack depth of 0 instead of 64.
Some buffers got the check indirectly. For constant-sized outputs in raw mode, mark_raw_stack() marks the buffer initialized through ordinary byte stores, which call the check. Commit 5da4a9f26fca ("bpf: Preserve stack initialization for generic output buffers") limited raw mode to programs that may read uninitialized stack, so outputs of programs without CAP_PERFMON lost the check, as in the example above. Buffers that never used raw mode have lacked the check since fastcall support was added: helper inputs such as a map key whose only store is a fastcall spill, variable-sized outputs, and buffers at a variable stack offset.
check_stack_read_fixed_off() applies the check to the current frame, even when the pointer targets a caller's stack. A callee can therefore read a caller's fastcall spill slot without disabling the caller's rewrite:
caller: r1 = 1; *(u64 *)(r10 - 8) = r1; call bpf_get_smp_processor_id; r1 = *(u64 *)(r10 - 8); r1 = r10; r1 += -8; call callee; callee: r0 = *(u64 *)(r1 + 0);
The caller's spill and fill are removed and its stack depth drops to 0, but the verifier still tracks the slot as holding the spilled constant. The callee's load then reads kernel stack outside the caller's frame, while the verifier assumes r0 is 1.
Every stack access first goes through check_stack_access_within_bounds():
loads and stores from check_mem_access(), helper and kfunc buffers from check_stack_range_initialized(), and the dynptr, iterator and irq flag slots that kfuncs initialize, whose handlers use check_mem_access(). It resolves the frame that owns the slots and the lowest offset the access can touch, and it is the only place where a frame's stack depth grows. Check the contract there, once for every access, and drop the calls from the stack read and write paths. Zero-sized buffers touch no stack and leave the rewrite enabled.
--- kernel/bpf/verifier.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
kernel/bpf/verifier.c +9 -4
@@ -4853,7 +4853,6 @@ static int check_stack_write_fixed_off(struct bpf_verifier_env *env,if (err)return err; -check_fastcall_stack_contract (env, state, insn_idx, off);mark_stack_slot_scratched (env, spi);if (reg && !(off %BPF_REG_SIZE ) && reg->type ==SCALAR_VALUE && env->bpf_capable) {bool reg_value_fits;
@@ -4983,7 +4982,6 @@ static int check_stack_write_var_off(struct bpf_verifier_env *env,return err; } -check_fastcall_stack_contract (env, state, insn_idx, min_off);/* Variable offset writes destroy any spilled pointers in range. */ for (i = min_off; i < max_off; i++) {u8 new_type, *stype;
@@ -5127,7 +5125,6 @@ static int check_stack_read_fixed_off(struct bpf_verifier_env *env, reg = ®_state->stack[spi].spilled_ptr;mark_stack_slot_scratched (env, spi); -check_fastcall_stack_contract (env, state, env->insn_idx, off);if (is_spilled_reg (®_state->stack[spi])) {u8 spill_size =1 ;
@@ -5288,7 +5285,6 @@ static int check_stack_read_var_off(struct bpf_verifier_env *env, min_off = reg->smin_value + off; max_off = reg->smax_value + off;mark_reg_stack_read (env, ptr_state, min_off, max_off + size, dst_regno); -check_fastcall_stack_contract (env, ptr_state, env->insn_idx, min_off);return 0 ; }
@@ -7228,6 +7224,15 @@ static int check_stack_access_within_bounds(return err; } +/* +* Every stack access passes through here, including buffers passed to +* helpers and kfuncs and accesses into a caller's frame, so check the +* fastcall contract of the frame that owns the slots once for all of +* them. Zero-sized accesses touch no stack and keep the rewrite enabled. +*/ +if (access_size) +check_fastcall_stack_contract (env, state, env->insn_idx, min_off); +/* Note that there is no stack access with offset zero, so the needed stack * size is -min_off, not -min_off+1. */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 422/816 bpf: Look at frame 0 when telling async callback entries apart
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Puranjay Mohan <[email protected]>
[ Upstream commit e55220162aae99622d9e80d4700e51c13a6f2a16 ]
push_async_cb() sets in_async_callback_fn and async_entry_cnt on the callback's own frame, which is frame 0 of the fresh state it starts, and setup_func_entry() copies neither, so a subprog called by the callback carries neither. Two places read them from the innermost frame instead.
is_state_visited() skips the infinite loop check when two states differ in async_entry_cnt, because seeing the same state on a second entry into an async callback is not a loop. A callback which re-arms itself and calls a subprog therefore compares the two entries at a loop inside that subprog, where the innermost frame is the subprog's and has no flag set, and the state is rejected:
infinite loop detected at insn 60
push_callback_call() numbers a new entry as the caller's count plus one. When the callback re-arms itself from a subprog, the caller is that subprog's frame with a count of 0, so every entry is numbered 1, the check above never sees a difference, and a loop anywhere in such a callback is rejected the same way.
Read the flag and the count from frame 0 in both places. A loop within a single entry still has a matching count and is still caught, and frame 0 of a non-async state does not have the flag set, so nothing else changes.
The two other readers are already correct: check_return_code() reads frame[0], and the one in do_check() is reached only after an early return for curframe != 0.
--- kernel/bpf/verifier.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/bpf/verifier.c +3 -3
@@ -10164,7 +10164,7 @@ static int push_callback_call(struct bpf_verifier_env *env, struct bpf_insn *insif (IS_ERR (async_cb))return PTR_ERR (async_cb); callee = async_cb->frame[0 ]; - callee->async_entry_cnt = caller->async_entry_cnt +1 ; + callee->async_entry_cnt = state->frame[0 ]->async_entry_cnt +1 ;/* Convert bpf_timer_set_callback() args into timer callback args */ err =set_callee_state_cb (env, caller, callee, insn_idx);
@@ -18604,10 +18604,10 @@ static int is_state_visited(struct bpf_verifier_env *env, int insn_idx) goto next;if (sl->state.branches) { -struct bpf_func_state *frame = sl->state.frame[sl->state.curframe]; +struct bpf_func_state *frame = sl->state.frame[0 ];if (frame->in_async_callback_fn && - frame->async_entry_cnt != cur->frame[cur->curframe]->async_entry_cnt) { + frame->async_entry_cnt != cur->frame[0 ]->async_entry_cnt) {/* Different async_entry_cnt means that the verifier is * processing another entry into async callback. * Seeing the same state is not an indication of infinite
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 423/816 ASoC: mediatek: mt8188: fix clk leak on error in audsys_clk_register
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit 6cddf6e56d2539fd13c0ee9dd817c4e06a967173 ]
devm_add_action_or_reset() is called after the loop that registers gate clocks. If kzalloc() fails mid-loop, the function returns -ENOMEM before that call, so cleanup is never registered and all previously registered clocks leak permanently.
Move devm_add_action_or_reset() before the loop so cleanup is always scheduled. The clock from the current (failing) iteration is not yet stored in afe_priv->lookup[i], so it still needs an explicit clk_unregister_gate() call.
--- sound/soc/mediatek/mt8188/mt8188-audsys-clk.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
sound/soc/mediatek/mt8188/mt8188-audsys-clk.c +9 -3
@@ -166,7 +166,7 @@ int mt8188_audsys_clk_register(struct mtk_base_afe *afe)struct mt8188_afe_private *afe_priv = afe->platform_priv;struct clk *clk;struct clk_lookup *cl; -int i; +int i, ret; afe_priv->lookup = devm_kcalloc(afe->dev, CLK_AUD_NR_CLK, sizeof(*afe_priv->lookup),
@@ -175,6 +175,10 @@ int mt8188_audsys_clk_register(struct mtk_base_afe *afe)if (!afe_priv->lookup)return -ENOMEM ; + ret =devm_add_action_or_reset (afe->dev, mt8188_audsys_clk_unregister, afe); +if (ret) +return ret; +for (i =0 ; i <ARRAY_SIZE (aud_clks); i++) {const struct afe_gate *gate = &aud_clks[i];
@@ -190,8 +194,10 @@ int mt8188_audsys_clk_register(struct mtk_base_afe *afe)/* add clk_lookup for devm_clk_get(SND_SOC_DAPM_CLOCK_SUPPLY) */ cl =kzalloc (sizeof (*cl),GFP_KERNEL ); -if (!cl) +if (!cl) { +clk_unregister_gate (clk);return -ENOMEM ; + } cl->clk = clk; cl->con_id = gate->name;
@@ -202,5 +208,5 @@ int mt8188_audsys_clk_register(struct mtk_base_afe *afe) afe_priv->lookup[i] = cl; } -return devm_add_action_or_reset (afe->dev, mt8188_audsys_clk_unregister, afe); +return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 424/816 bpf: Adjust pc-relative insn copied into its own patch
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexei Starovoitov <[email protected]>
[ Upstream commit 67a3b916a7ae7c1a6bed08555417d444de6f5838 ]
bpf_do_misc_fixups() inits may_goto count by patching the first insn of a subprog with [ST, ST, first insn]. bpf_convert_ctx_accesses() patches insn that needs a barrier with [nospec, insn]. bpf_adj_branches() doesn't adjust insns inside the patch, so when the copy is a call, ld_imm64 of a func or a jump that points backward its target is off by the number of insns in front of it:
static int A(void) { return 1; }
static int A2(void) { return 2; }
static int B(void)
{
int i, ret = A(); for (i = 0; i < 10 && can_loop; i++)
...
return ret;}
When A is placed in front of B and may_goto is timed 'call A' becomes call of A + 2. B returns 2 when A + 2 is the start of A2. Otherwise the prog is rejected with "verifier bug: No program to jit at insn".
Add bpf_adj_moved_insn() and use it for both copies.
--- kernel/bpf/verifier.c | 44 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)
kernel/bpf/verifier.c +44 -0
@@ -19952,6 +19952,44 @@ static struct bpf_prog *bpf_patch_insn_data(struct bpf_verifier_env *env, u32 ofreturn new_prog; } +/* +* insn was moved down by delta insns inside its own patch. Operands relative +* to the pc that point in front of the old position did not move with it. +*/ +static int bpf_adj_moved_insn (struct bpf_insn *insn,u32 delta) +{ +u8 class =BPF_CLASS (insn->code), op =BPF_OP (insn->code); +s64 off = insn->imm, off_min =S32_MIN ; +bool is_imm = true; + +if (bpf_pseudo_func (insn) ||bpf_pseudo_call (insn)) { +/* subprog that started at the old position starts with the patch */ +if (off >=0 ) +return 0 ; + }else if ((class ==BPF_JMP || class ==BPF_JMP32 ) && + op !=BPF_CALL && op !=BPF_EXIT ) { +if (insn->code != (BPF_JMP32 |BPF_JA )) { + off = insn->off; + off_min =S16_MIN ; + is_imm = false; + } +/* jump to itself stays */ +if (off >=-1 ) +return 0 ; + }else { +return 0 ; + } + + off -= delta; +if (off < off_min) +return -ERANGE ; +if (is_imm) + insn->imm = off; +else + insn->off = off; +return 0 ; +} +/* * For all jmp insns in a given 'prog' that point to 'tgt_idx' insn adjust the * jump offset by 'delta'.
@@ -21959,6 +21997,12 @@ static int do_misc_fixups(struct bpf_verifier_env *env) -subprogs[i].stack_depth, BPF_MAX_LOOPS);/* Copy first actual insn to preserve it */ insn_buf[1 ] = env->prog->insnsi[subprog_start]; + ret =bpf_adj_moved_insn (&insn_buf[1 ],1 ); +if (ret) { +verbose (env,"insn %d cannot be patched due to 16-bit range\n" , + env->insn_aux_data[subprog_start].orig_idx); +return ret; + } new_prog =bpf_patch_insn_data (env, subprog_start, insn_buf,2 );if (!new_prog)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 425/816 bpf: Fix overflow of jump offset in may_goto expansion
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexei Starovoitov <[email protected]>
[ Upstream commit 8a12a00f6c5dba70a6d908fe27a3c980d42b9515 ]
may_goto is expanded into 'if AX == 0 goto off + 5' when it's timed, off + 2 when it's not and off - 1 when it jumps backward. The sum is stored into 16-bit off without a range check, so may_goto +32763 turns into:
if r12 == 0x0 goto pc-32768
and the prog jumps backward when may_goto expires.
Emit 'if AX != 0 goto +1; gotol' when the offset doesn't fit and compute the offset from the number of insns in the expansion. JITs that don't support gotol will reject such prog.
--- kernel/bpf/verifier.c | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-)
kernel/bpf/verifier.c +30 -8
@@ -21156,6 +21156,30 @@ static int add_hidden_subprog(struct bpf_verifier_env *env, struct bpf_insn *patreturn 0 ; } +/* +* Expand may_goto: load the count from the stack, jump to the target of +* may_goto when it is zero, then the tail that updates the count. +* Use gotol when the target is too far for 16-bit offset of a conditional jump. +*/ +static int may_goto_expand (struct bpf_insn *insn_buf,int off,int stack_off, +const struct bpf_insn *tail,int tail_cnt) +{ +int cnt =0 ; + +/* Forward jump has to step over the tail */ + off = off >=0 ? off + tail_cnt : off -1 ; + + insn_buf[cnt++] =BPF_LDX_MEM (BPF_DW ,BPF_REG_AX ,BPF_REG_10 , stack_off); +if (off == (s16 )off) { + insn_buf[cnt++] =BPF_JMP_IMM (BPF_JEQ ,BPF_REG_AX ,0 , off); + }else { + insn_buf[cnt++] =BPF_JMP_IMM (BPF_JNE ,BPF_REG_AX ,0 ,1 ); + insn_buf[cnt++] =BPF_JMP32_A (off >=0 ? off : off -1 ); + } +memcpy (insn_buf + cnt, tail, tail_cnt *sizeof (*tail)); +return cnt + tail_cnt; +} +/* Do various post-verification rewrites in a single program pass. * These rewrites simplify JIT and interpreter implementations. */
@@ -21443,16 +21467,14 @@ static int do_misc_fixups(struct bpf_verifier_env *env)if (is_may_goto_insn (insn)) {int stack_off = -stack_depth -8 ; +struct bpf_insn tail[] = { +BPF_ALU64_IMM (BPF_SUB ,BPF_REG_AX ,1 ), +BPF_STX_MEM (BPF_DW ,BPF_REG_10 ,BPF_REG_AX , stack_off), + }; stack_depth_extra =8 ; - insn_buf[0 ] =BPF_LDX_MEM (BPF_DW ,BPF_REG_AX ,BPF_REG_10 , stack_off); -if (insn->off >=0 ) - insn_buf[1 ] =BPF_JMP_IMM (BPF_JEQ ,BPF_REG_AX ,0 , insn->off +2 ); -else - insn_buf[1 ] =BPF_JMP_IMM (BPF_JEQ ,BPF_REG_AX ,0 , insn->off -1 ); - insn_buf[2 ] =BPF_ALU64_IMM (BPF_SUB ,BPF_REG_AX ,1 ); - insn_buf[3 ] =BPF_STX_MEM (BPF_DW ,BPF_REG_10 ,BPF_REG_AX , stack_off); - cnt =4 ; + cnt =may_goto_expand (insn_buf, insn->off, stack_off, + tail,ARRAY_SIZE (tail)); new_prog =bpf_patch_insn_data (env, i + delta, insn_buf, cnt);if (!new_prog)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 426/816 bpf: Dont converge a loop on an iterator that was created anew
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexei Starovoitov <[email protected]>
[ Upstream commit 6f3ee3516305da3043f1787e3890381a54151730 ]
When the verifier reaches bpf_iter_*_next() in a state that is equal to a state that is still being explored it concludes that the loop converged, since an active iterator will be drained eventually. states_equal() matches ids through idmap, so the same is concluded for an iterator that was destroyed and created again since the old state:
bpf_iter_num_new(&it, 0, 10);
loop:
if (bpf_ktime_get_ns())
goto remake;
next:
if (!bpf_iter_num_next(&it))
goto out;
goto loop;
remake:
bpf_iter_num_destroy(&it);
bpf_iter_num_new(&it, 0, 10);
goto next;Such prog is accepted when the call of bpf_iter_num_next() is the first prune point after bpf_iter_num_new() and it never returns. Otherwise it's rejected with "infinite loop detected".
Require the iterator to have the same id in both states.
--- kernel/bpf/verifier.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
kernel/bpf/verifier.c +12 -2
@@ -18659,8 +18659,9 @@ static int is_state_visited(struct bpf_verifier_env *env, int insn_idx)*/ if (is_iter_next_insn (env, insn_idx)) {if (states_equal (env, &sl->state, cur,RANGE_WITHIN )) { -struct bpf_func_state *cur_frame; +struct bpf_func_state *cur_frame, *old_frame;struct bpf_reg_state *iter_state, *iter_reg; +struct bpf_reg_state *old_iter;int spi; cur_frame = cur->frame[cur->curframe];
@@ -18674,7 +18675,16 @@ static int is_state_visited(struct bpf_verifier_env *env, int insn_idx)*/ spi =__get_spi (iter_reg->off + iter_reg->var_off.value); iter_state = &func (env, iter_reg)->stack[spi].spilled_ptr; -if (iter_state->iter.state ==BPF_ITER_STATE_ACTIVE ) { + old_frame = sl->state.frame[iter_reg->frameno]; + old_iter = &old_frame->stack[spi].spilled_ptr; +/* +* states_equal() matches ids through idmap. +* The loop converged only if it's the same +* iterator. The one that was destroyed and +* created again starts from the beginning. +*/ +if (iter_state->iter.state ==BPF_ITER_STATE_ACTIVE && + iter_state->ref_obj_id == old_iter->ref_obj_id) {update_loop_entry (cur, &sl->state); goto hit; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 427/816 bpf: Fix uninit read for non-fetch atomics on partially spilled slots
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hao Sun <[email protected]>
[ Upstream commit 5a84b4424db8ae07f0ac682ab031c37a91dce50b ]
check_stack_read_fixed_off() skips partial spill checks for non-fetch atomics; the following prog can be loaded:
0: (b7) r1 = 1 ; R1=1 1: (63) *(u32 *)(r10 -8) = r1 ; R1=1 R10=fp0 fp-8=????1 2: (db) lock *(u64 *)(r10 -8) += r1 ; R1=1 R10=fp0 fp-8=mmmmmmmm 3: (79) r0 = *(u64 *)(r10 -8) ; R0=scalar() R10=fp0 fp-8=mmmmmmmm 4: (77) r0 >>= 32 ; R0=scalar(smin=0,smax=umax=0xffffffff,var_off=(0x0; 0xffffffff))
5: (95) exit
When test run:
retval=4294967295
Note fp-8 is ????1 at #1, yet it becomes fp-8=mmmmmmmm after the non-fetching atomic add at #2; hence the high 32 bits are leaked.
Fix by applying the partial load check; after the patch, the prog is rejected:
Verification failed: Memory Safety: Uninitialized stack read
Reason:
This rejected read uses 8 bytes at stack offset -8, but byte 4 in that range is uninitialized on this path. Programs loaded with CAP_PERFMON can be allowed to read uninitialized stack bytes, but this program is being rejected without that allowance.
At:
...
0 | (b7) r1 = 1
1 | (63) *(u32 *)(r10 -8) = r1
>>> 2 | (db) lock *(u64 *)(r10 -8) += r1
3 | (79) r0 = *(u64 *)(r10 -8)
4 | (77) r0 >>= 32This affects CAP_BPF only.
--- kernel/bpf/verifier.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
kernel/bpf/verifier.c +9 -3
@@ -5140,15 +5140,18 @@ static int check_stack_read_fixed_off(struct bpf_verifier_env *env, }mark_reg_read (env, reg, reg->parent,REG_LIVE_READ64 ); -if (dst_regno <0 ) -return 0 ;if (size <= spill_size &&bpf_stack_narrow_access_ok (off, size, spill_size)) { +s32 subreg_def; + +if (dst_regno <0 ) +return 0 ; +/* The earlier check_reg_arg() has decided the * subreg_def for this insn. Save it first. */ -s32 subreg_def = state->regs[dst_regno].subreg_def; + subreg_def = state->regs[dst_regno].subreg_def;copy_register_state (&state->regs[dst_regno], reg); state->regs[dst_regno].subreg_def = subreg_def;
@@ -5180,6 +5183,9 @@ static int check_stack_read_fixed_off(struct bpf_verifier_env *env,return -EACCES ; } +if (dst_regno <0 ) +return 0 ; +if (spill_cnt == size &&tnum_is_const (reg->var_off) && reg->var_off.value ==0 ) {__mark_reg_const_zero (env, &state->regs[dst_regno]);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 428/816 bpf: Fix uninit read for helper mem args on partially spilled slots
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hao Sun <[email protected]>
[ Upstream commit b3861495d2b2f7459cddf49e63fa0758ba430583 ]
check_stack_range_initialized() takes the spilled register path when bpf_is_spilled_reg(ss) holds, which, however, only looks at the last byte of the slot. Hence, a partially spilled scalar (on the lower part) bypasses the check and the following loads:
0: (b7) r1 = 1 ; R1=1 1: (63) *(u32 *)(r10 -8) = r1 ; R1=1 R10=fp0 fp-8=????1 2: (18) r1 = 0x0 ; R1=map_ptr(map=rb,ks=0,vs=0) 4: (bf) r2 = r10 ; R2=fp0 R10=fp0 5: (07) r2 += -8 ; R2=fp-8 6: (b7) r3 = 8 ; R3=8 7: (b7) r4 = 0 ; R4=0
8: (85) call bpf_ringbuf_output#130
...
When executed, it dumps the uninit four bytes:
RINGBUF: 01 00 00 00 ff ff ff ff
This is the same root cause as the non-fetch atomic case fixed in commit 5a84b4424db8 ("bpf: Fix uninit read for non-fetch atomics on partially spilled slots").
Fix by only taking the spilled register path for the bytes marked STACK_SPILL, so the rest of the slot goes through the usual checks.
--- kernel/bpf/verifier.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/bpf/verifier.c +6 -1
@@ -7812,7 +7812,12 @@ static int check_stack_range_initialized( goto mark; } -if (is_spilled_reg (&state->stack[spi]) && +/* +* Only the bytes marked STACK_SPILL hold the spilled register. +* The rest of a narrowly spilled slot keeps its previous type +* and must be initialized on its own. +*/ +if (*stype ==STACK_SPILL && (state->stack[spi].spilled_ptr.type ==SCALAR_VALUE || env->allow_ptr_leaks)) {if (clobber) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 429/816 perf llvm: Fix memory leak of args->fileloc in symbol__disassemble_llvm()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tengda Wu <[email protected]>
[ Upstream commit fe529886843f451ad6da7e65d53325432e0f80fb ]
In symbol__disassemble_llvm(), after calling llvm_addr2line(), if the subsequent disasm_line__new() fails, the code directly jumps to 'err' without freeing args->fileloc, leading to a memory leak.
Fix this by explicitly calling free(args->fileloc) before jumping to the error handling path when disasm_line__new() fails.
--- tools/perf/util/disasm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/util/disasm.c +3 -1
@@ -1980,8 +1980,10 @@ static int symbol__disassemble_llvm(char *filename, struct symbol *sym, (unsigned int *)&args->line_nr, false, NULL); dl =disasm_line__new (args); -if (dl ==NULL ) +if (dl ==NULL ) { +free (args->fileloc); goto err; + }annotation_line__add (&dl->al, ¬es->src->source);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 430/816 sysctl: unregister tables before freeing bitmap
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yibo Tan <[email protected]>
[ Upstream commit 238dfe02fb0a9f72d7fd275d74ce80f13923ef31 ]
The table registered for bitmap_0001 retains a pointer to test_data.bitmap_0001. unregister_sysctl_table() prevents new handlers from starting and waits for active handlers to finish.
test_sysctl_exit() currently frees the bitmap before unregistering the table. A concurrent read during module removal can therefore enter proc_do_large_bitmap() while the bitmap is freed. KASAN reports a slab-use-after-free in _find_next_bit().
Unregister all tables before freeing the bitmap so the unregister rundown provides the required lifetime boundary.
The unmodified module reproduced the use-after-free in three KASAN runs. With this change, three runs each completed 100 load, read and unload race rounds without a kernel diagnostic.
--- lib/test_sysctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/test_sysctl.c +1 -1
@@ -264,7 +264,6 @@ module_init(test_sysctl_init); static void __exit test_sysctl_exit(void) { -kfree (test_data.bitmap_0001);if (sysctl_test_headers.test_h_setup_node)unregister_sysctl_table (sysctl_test_headers.test_h_setup_node);if (sysctl_test_headers.test_h_mnt)
@@ -275,6 +274,7 @@ static void __exit test_sysctl_exit(void)unregister_sysctl_table (sysctl_test_headers.empty);if (sysctl_test_headers.empty_add)unregister_sysctl_table (sysctl_test_headers.empty_add); +kfree (test_data.bitmap_0001); }module_exit (test_sysctl_exit);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 431/816 arm64: dts: qcom: x1-crd: Mark the EC reset gpio as reserved
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abel Vesa <[email protected]>
[ Upstream commit 099cd579fa73c142fde2f7e3ea473f334792a249 ]
GPIO 65 from TLMM is connected to the embedded controller's active-high reset line. Asserting it causes the fans to run at full speed during reset and leaves the keyboard non-functional afterwards.
Reserve it to prevent Linux from requesting or reconfiguring it.
--- arch/arm64/boot/dts/qcom/x1e80100-crd.dts | 1 + 1 file changed, 1 insertion(+)
arch/arm64/boot/dts/qcom/x1e80100-crd.dts +1 -0
@@ -1000,6 +1000,7 @@ right_tweeter: speaker@0,1 { &tlmm { gpio-reserved-ranges = <34 2>, /* Unused */ <44 4>, /* SPI (TPM) */ + <65 1>, /* EC reset */ <238 1>; /* UFS Reset */ edp_reg_en: edp-reg-en-state {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 432/816 arm64: dts: qcom: x1e78100-t14s: Mark the EC reset gpio as reserved
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abel Vesa <[email protected]>
[ Upstream commit 07321595ce693eea5854120869a8b1560d7b14d6 ]
GPIO 65 from TLMM is used by the embedded controller as its reset line.
On some devices, toggling the embedded controller reset line makes the device not power up at all, unless the battery is unplugged.
So reserve it in order to prevent Linux from requesting or reconfiguring it.
[ sashal: Applied the one-line gpio-reserved-ranges addition to the T14s board file, since the shared include file the original patch edits doesn't exist here. ]
--- arch/arm64/boot/dts/qcom/x1e78100-lenovo-thinkpad-t14s.dts | 1 + 1 file changed, 1 insertion(+)
arch/arm64/boot/dts/qcom/x1e78100-lenovo-thinkpad-t14s.dts +1 -0
@@ -641,6 +641,7 @@ &smb2360_1_eusb2_repeater { &tlmm { gpio-reserved-ranges = <34 2>, /* Unused */ <44 4>, /* SPI (TPM) */ + <65 1>, /* EC reset */ <72 2>, /* Secure EC I2C connection (?) */ <238 1>; /* UFS Reset */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 433/816 arm64: dts: qcom: x1-asus-vivobook-s15: Mark the EC reset gpio as reserved
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abel Vesa <[email protected]>
[ Upstream commit 94a0d3a2595821878de98d495e89691f694a2083 ]
GPIO 65 from TLMM is used by the embedded controller as its reset line.
On some devices, toggling the embedded controller reset line makes the device not power up at all, unless the battery is unplugged.
So reserve it in order to prevent Linux from requesting or reconfiguring it.
--- arch/arm64/boot/dts/qcom/x1e80100-asus-vivobook-s15.dts | 1 + 1 file changed, 1 insertion(+)
arch/arm64/boot/dts/qcom/x1e80100-asus-vivobook-s15.dts +1 -0
@@ -506,6 +506,7 @@ &smb2360_1_eusb2_repeater { &tlmm { gpio-reserved-ranges = <34 2>, /* Unused */ <44 4>, /* SPI (TPM) */ + <65 1>, /* EC reset */ <238 1>; /* UFS Reset */ edp_reg_en: edp-reg-en-state {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 434/816 ACPI: PCC: Free channel on OpRegion deactivation
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sudeep Holla <[email protected]>
[ Upstream commit fa9c7ee692988edddc1da74bc5257d53dd3c7130 ]
ACPICA calls the address space setup callback with ACPI_REGION_DEACTIVATE when a PCC OperationRegion is torn down.
The PCC setup callback currently allocates a fresh pcc_data and requests the mailbox channel before looking at the function argument. If ACPICA deactivates a region, this can leave the existing region context and mailbox channel unreleased, and may also request a channel during teardown.
Handle ACPI_REGION_DEACTIVATE before allocation. Free the PCC mailbox channel, release the region context and clear the context pointer.
--- drivers/acpi/acpi_pcc.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/acpi/acpi_pcc.c +13 -0
@@ -55,6 +55,19 @@ acpi_pcc_address_space_setup(acpi_handle region_handle, u32 function,struct pcc_mbox_chan *pcc_chan;acpi_status ret; +if (function ==ACPI_REGION_DEACTIVATE ) { + data = *region_context; +if (data) { +pcc_mbox_free_channel (data->pcc_chan); +kfree (data); + *region_context =NULL ; + } +return AE_OK ; + } + +if (function !=ACPI_REGION_ACTIVATE ) +return AE_BAD_PARAMETER ; + data =kzalloc (sizeof (*data),GFP_KERNEL );if (!data)return AE_NO_MEMORY ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 435/816 x86/fpu: Fix potential underflow in xstate_calculate_size()
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrei Vagin <[email protected]>
[ Upstream commit f1751b220bc8a9bd2dc38ecf61f5c29f3826ace0 ]
xstate_calculate_size() calculates the size required for a given set of xfeatures. It determines the topmost feature by finding the most significant bit in xfeatures using fls64(xfeatures) - 1.
If xfeatures is 0, fls64(0) returns 0, and topmost becomes -1. Previously, topmost was unsigned int, so -1 underflowed to UINT_MAX. This caused the subsequent check topmost <= XFEATURE_SSE to fail, and the code proceeded to access xstate arrays using topmost (UINT_MAX) as an index, leading to an out-of-bounds access.
[ bp: Remove text explaining what the patch does. ]
--- arch/x86/kernel/fpu/xstate.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
arch/x86/kernel/fpu/xstate.c +5 -3
@@ -562,12 +562,14 @@ static bool __init check_xstate_against_struct(int nr)static unsigned int xstate_calculate_size (u64 xfeatures,bool compacted) { -unsigned int topmost =fls64 (xfeatures) -1 ; -unsigned int offset = xstate_offsets[topmost]; +unsigned int topmost, offset; -if (topmost <=XFEATURE_SSE ) +if (!(xfeatures & ~XFEATURE_MASK_FPSSE ))return sizeof (struct xregs_state ); + topmost =fls64 (xfeatures) -1 ; + offset = xstate_offsets[topmost]; +if (compacted) offset =xfeature_get_offset (xfeatures, topmost);return offset + xstate_sizes[topmost];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 436/816 bpf: Rebase the exception callback subprog when dead subprogs are removed
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Borkmann <[email protected]>
[ Upstream commit 8608ec8e981974b18834e2d67ed39638a9ec2e63 ]
adjust_subprog_starts_after_remove() compacts subprog_info[] and the func_info when whole subprograms are removed as dead code, but leaves env->exception_callback_subprog alone, so an exception callback declared through the exception_callback decl tag which sits behind a removed subprogram keeps its old index. jit_subprogs() then takes the exception callback from func[] at that index, which is past the end when the callback was the last subprogram, or another subprogram otherwise.
Rebase the index along with the entries it refers to.
--- kernel/bpf/verifier.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/bpf/verifier.c +3 -0
@@ -20092,6 +20092,9 @@ static int adjust_subprog_starts_after_remove(struct bpf_verifier_env *env,* in adjust_btf_func() - no need to adjust */ } +/* The exception callback is live, so it cannot sit inside the removed range. */ +if (env->exception_callback_subprog >= j) + env->exception_callback_subprog -= j - i; }else {/* convert i from "first prog to remove" to "first to adjust" */ if (env->subprog_info[i].start == off)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 437/816 tools/nolibc: fix FD_SET(), FD_CLR() and FD_ISSET() on 64-bit
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Danish Khateeb <[email protected]>
[ Upstream commit 929ea5b3481fdbbb419f3986703280fb2b819504 ]
Since commit feaf75658783 ("nolibc: fix fd_set type"), an fd_set is an array of unsigned long, but the FD_* macros still build their masks as an int or an unsigned int: 1 << n in FD_SET(), 1U << n in FD_CLR() and FD_ISSET(), where n is the fd modulo 64 on 64-bit architectures. So:
- FD_SET() of an fd with n == 31 sets the bits for n = 31-63, as 1 << 31 is negative and gets sign-extended.
- For n >= 32 the shifts are undefined. x86-64, for instance, masks the shift count, so FD_SET(40) and FD_ISSET(40) use the bit of fd 8.
- FD_CLR() zero-extends ~(1U << n), so it also clears the bits for n = 32-63, whichever fd it is given.
select() on fd 40, for instance, fails with EBADF, or watches fd 8 instead if that one is open.
Build the masks from 1UL.
--- tools/include/nolibc/types.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tools/include/nolibc/types.h +3 -3
@@ -127,7 +127,7 @@ typedef struct {int __fd = (fd); \if (__fd >=0 ) \ __set->fds[__fd /FD_SETIDXMASK ] &= \ - ~(1U << (__fd &FD_SETBITMASK )); \ + ~(1UL << (__fd &FD_SETBITMASK )); \ } while (0)#define FD_SET (fd, set) do { \
@@ -135,7 +135,7 @@ typedef struct {int __fd = (fd); \if (__fd >=0 ) \ __set->fds[__fd /FD_SETIDXMASK ] |= \ -1 << (__fd &FD_SETBITMASK ); \ +1UL << (__fd &FD_SETBITMASK ); \ } while (0) #define FD_ISSET(fd, set) ({ \
@@ -144,7 +144,7 @@ typedef struct {int __r =0 ; \if (__fd >=0 ) \ __r = !!(__set->fds[__fd /FD_SETIDXMASK ] & \ -1U << (__fd &FD_SETBITMASK )); \ +1UL << (__fd &FD_SETBITMASK )); \ __r; \ })
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 438/816 netfilter: nfnetlink: Fix for interrupted hook dumps
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Phil Sutter <[email protected]>
[ Upstream commit d3950004ba90350bcdf414c5f804da277178564a ]
Handling of concurrent hook changes with a dump in progress was problematic in nfnl_hook_dump and entirely broken in nfnl_hook_dump_nat. Address all issues in a single patch to please the review LLM.
Introduce sequence numbers in struct netns_nf to replace pointer value-based modification detection which may fail due to memory buffer reuse. This also eliminates the need for most manual cb->seq updates and excessive array index value checks.
Since nat hook updates are protected by a different mutex than others, they have to bump their own sequence number. nfnl_hook_dump_nat therefore open-codes what nl_dump_check_consistent does but bumps cb->seq instead of setting NLM_F_DUMP_INTR flag.
Dumps of many nat hooks was entirely broken since the array index was not (re)stored. Use cb->args[1] for that and make sure it is reset upon completion as the same dump may loop over multiple arrays of nat hooks.
In nfnl_hook_dump, don't signal NLM_F_DUMP_INTR if nfnl_hook_entries_head returns error: This is a permanent condition which does not change during a dump. It is already caught by nfnl_hook_dump_start though, so should not happen anyway.
In general, access ops array pointer values using READ_ONCE since they are assigned to using WRITE_ONCE.
Avoid setting NLM_F_DUMP_INTR flag in garbage memory by calling nl_dump_check_consistent only for non-empty skbs. If not a single netlink message was created, nfnetlink code will take care of setting the flag.
--- include/net/netns/netfilter.h | 1 + net/netfilter/core.c | 17 ++++++++++++++++- net/netfilter/nfnetlink_hook.c | 20 +++++--------------- 3 files changed, 22 insertions(+), 16 deletions(-)
include/net/netns/netfilter.h +1 -0
@@ -33,5 +33,6 @@ struct netns_nf {#if IS_ENABLED (CONFIG_NF_DEFRAG_IPV6 )unsigned int defrag_ipv6_users;#endif + unsigned int hook_base_seq; };#endif
net/netfilter/core.c +16 -1
@@ -393,6 +393,15 @@ static void nf_static_key_dec(const struct nf_hook_ops *reg, int pf)#endif } +static void bump_hook_base_seq (struct net *net) +{ +unsigned int base_seq =READ_ONCE (net->nf.hook_base_seq); + +while (++base_seq ==0 ) + ; +smp_store_release (&net->nf.hook_base_seq, base_seq); +} +static int __nf_register_net_hook (struct net *net,int pf,const struct nf_hook_ops *reg) {
@@ -437,6 +446,7 @@ static int __nf_register_net_hook(struct net *net, int pf,if (!IS_ERR (new_hooks)) {hooks_validate (new_hooks);rcu_assign_pointer (*pp, new_hooks); +bump_hook_base_seq (net); }mutex_unlock (&nf_hook_mutex);
@@ -490,6 +500,7 @@ static void __nf_unregister_net_hook(struct net *net, int pf, {struct nf_hook_entries __rcu **pp;struct nf_hook_entries *p; +bool found; pp =nf_hook_entry_head (net, pf, reg->hooknum, reg->dev);if (!pp)
@@ -503,7 +514,8 @@ static void __nf_unregister_net_hook(struct net *net, int pf,return ; } -if (nf_remove_net_hook (p, reg)) { + found =nf_remove_net_hook (p, reg); +if (found) {#ifdef CONFIG_NETFILTER_INGRESS if (nf_ingress_hook (reg, pf))net_dec_ingress_queue ();
@@ -518,6 +530,8 @@ static void __nf_unregister_net_hook(struct net *net, int pf, } p =__nf_hook_entries_try_shrink (p, pp); +if (found) +bump_hook_base_seq (net);mutex_unlock (&nf_hook_mutex);if (!p)return ;
@@ -791,6 +805,7 @@ static int __net_init netfilter_net_init(struct net *net) return -ENOMEM; }#endif + net->nf.hook_base_seq =1 ;return 0 ; }
net/netfilter/nfnetlink_hook.c +5 -15
@@ -54,7 +54,6 @@ static int nf_netlink_dump_start_rcu(struct sock *nlsk, struct sk_buff *skb,struct nfnl_dump_hook_data {char devname[IFNAMSIZ ]; -unsigned long headv;u8 hook; };
@@ -311,30 +310,24 @@ static int nfnl_hook_dump(struct sk_buff *nlskb,unsigned int i = cb->args[0 ];rcu_read_lock (); + cb->seq =smp_load_acquire (&net->nf.hook_base_seq); e =nfnl_hook_entries_head (family, ctx->hook, net, ctx->devname); -if (!e) +if (!e ||IS_ERR (e)) goto done; -if (IS_ERR (e)) { - cb->seq++; - goto done; - } - -if ((unsigned long )e != ctx->headv || i >= e->num_hook_entries) - cb->seq++; - ops =nf_hook_entries_get_hook_ops (e);for (; i < e->num_hook_entries; i++) { - err =nfnl_hook_dump_one (nlskb, ctx, ops[i], family, + err =nfnl_hook_dump_one (nlskb, ctx,READ_ONCE (ops[i]), family, cb->nlh->nlmsg_seq);if (err)break ; } done: -nl_dump_check_consistent (cb,nlmsg_hdr (nlskb)); +if (nlskb->len >0 ) +nl_dump_check_consistent (cb,nlmsg_hdr (nlskb));rcu_read_unlock (); cb->args[0 ] = i;return nlskb->len;
@@ -375,10 +368,7 @@ static int nfnl_hook_dump_start(struct netlink_callback *cb)return -ENOMEM ;strscpy (ctx->devname, name,sizeof (ctx->devname)); - ctx->headv = (unsigned long )head; ctx->hook = hooknum; - - cb->seq =1 ; cb->data = ctx;return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 439/816 RDMA/vmw_pvrdma: Pin QP and SRQ rings writable to match device DMA write access
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yishai Hadas <[email protected]>
[ Upstream commit 89abac4b60b708037595255ea2614b6967c86ee5 ]
pvrdma embeds a pvrdma_ring_state header directly inside the QP and SRQ ring buffers, and the hypervisor writes cons_head into that header. Pinning with access=0 does not force a private page copy (no FOLL_WRITE), so the hypervisor may write into a shared page.
Pass IB_ACCESS_LOCAL_WRITE for all three rings. The SRQ ring_state is not currently used by the driver but is pinned writable for consistency.
--- drivers/infiniband/hw/vmw_pvrdma/pvrdma_qp.c | 6 ++++-- drivers/infiniband/hw/vmw_pvrdma/pvrdma_srq.c | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-)
drivers/infiniband/hw/vmw_pvrdma/pvrdma_qp.c +4 -2
@@ -270,7 +270,8 @@ int pvrdma_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *init_attr,/* set qp->sq.wqe_cnt, shift, buf_size.. */ qp->rumem =ib_umem_get (ibqp->device, ucmd.rbuf_addr, - ucmd.rbuf_size,0 ); + ucmd.rbuf_size, +IB_ACCESS_LOCAL_WRITE );if (IS_ERR (qp->rumem)) { ret =PTR_ERR (qp->rumem); goto err_qp;
@@ -282,7 +283,8 @@ int pvrdma_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *init_attr, } qp->sumem =ib_umem_get (ibqp->device, ucmd.sbuf_addr, - ucmd.sbuf_size,0 ); + ucmd.sbuf_size, +IB_ACCESS_LOCAL_WRITE );if (IS_ERR (qp->sumem)) {if (!is_srq)ib_umem_release (qp->rumem);
drivers/infiniband/hw/vmw_pvrdma/pvrdma_srq.c +2 -1
@@ -146,7 +146,8 @@ int pvrdma_create_srq(struct ib_srq *ibsrq, struct ib_srq_init_attr *init_attr, goto err_srq; } - srq->umem =ib_umem_get (ibsrq->device, ucmd.buf_addr, ucmd.buf_size,0 ); + srq->umem =ib_umem_get (ibsrq->device, ucmd.buf_addr, ucmd.buf_size, +IB_ACCESS_LOCAL_WRITE );if (IS_ERR (srq->umem)) { ret =PTR_ERR (srq->umem); goto err_srq;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 440/816 RDMA/mlx5: Fix mlx5_ib_dev_res_init() failure when XRC cap is absent
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yishai Hadas <[email protected]>
[ Upstream commit 4354ab7a85d1ddd45a8a3337227fad5b37b44902 ]
mlx5_ib_dev_res_init() returns -EOPNOTSUPP when the firmware XRC capability is absent, failing driver probe on XRC-less devices.
Make XRC optional throughout the devr resource path: initialize cq_lock and srq_lock unconditionally (needed for every QP creation), skip xrcd allocation and the XRC-type placeholder SRQ (s0) when xrc=0, and guard their cleanup paths accordingly.
--- drivers/infiniband/hw/mlx5/main.c | 52 +++++++++++++++++++------------ 1 file changed, 32 insertions(+), 20 deletions(-)
drivers/infiniband/hw/mlx5/main.c +32 -20
@@ -3101,7 +3101,7 @@ int mlx5_ib_dev_res_srq_init(struct mlx5_ib_dev *dev) {struct mlx5_ib_resources *devr = &dev->devr;struct ib_srq_init_attr attr; -struct ib_srq *s0, *s1; +struct ib_srq *s0 =NULL , *s1;int ret =0 ;/*
@@ -3119,17 +3119,25 @@ int mlx5_ib_dev_res_srq_init(struct mlx5_ib_dev *dev)if (ret) goto unlock; -memset (&attr,0 ,sizeof (attr)); - attr.attr.max_sge =1 ; - attr.attr.max_wr =1 ; - attr.srq_type =IB_SRQT_XRC ; - attr.ext.cq = devr->c0; - - s0 =ib_create_srq (devr->p0, &attr); -if (IS_ERR (s0)) { - ret =PTR_ERR (s0); -mlx5_ib_err (dev,"Couldn't create SRQ 0 for res init, err=%d\n" , ret); - goto unlock; +/* +* s0 is an XRC-type placeholder SRQ used as the default XRQN for +* XRC QPs. Skip it when XRC is absent; all devr->s0 accesses in +* qp.c are inside XRC QP paths that the verbs layer blocks before +* reaching this driver when xrc=0, so NULL is safe. +*/ +if (MLX5_CAP_GEN (dev->mdev, xrc)) { +memset (&attr,0 ,sizeof (attr)); + attr.attr.max_sge =1 ; + attr.attr.max_wr =1 ; + attr.srq_type =IB_SRQT_XRC ; + attr.ext.cq = devr->c0; + + s0 =ib_create_srq (devr->p0, &attr); +if (IS_ERR (s0)) { + ret =PTR_ERR (s0); +mlx5_ib_err (dev,"Couldn't create SRQ 0 for res init, err=%d\n" , ret); + goto unlock; + } }memset (&attr,0 ,sizeof (attr));
@@ -3141,7 +3149,8 @@ int mlx5_ib_dev_res_srq_init(struct mlx5_ib_dev *dev)if (IS_ERR (s1)) { ret =PTR_ERR (s1);mlx5_ib_err (dev,"Couldn't create SRQ 1 for res init, err=%d\n" , ret); -ib_destroy_srq (s0); +if (s0) +ib_destroy_srq (s0); goto unlock; }
@@ -3158,8 +3167,11 @@ static int mlx5_ib_dev_res_init(struct mlx5_ib_dev *dev)struct mlx5_ib_resources *devr = &dev->devr;int ret; +mutex_init (&devr->cq_lock); +mutex_init (&devr->srq_lock); +if (!MLX5_CAP_GEN (dev->mdev, xrc)) -return -EOPNOTSUPP ; +return 0 ; ret =mlx5_cmd_xrcd_alloc (dev->mdev, &devr->xrcdn0,0 );if (ret)
@@ -3171,9 +3183,6 @@ static int mlx5_ib_dev_res_init(struct mlx5_ib_dev *dev)return ret; } -mutex_init (&devr->cq_lock); -mutex_init (&devr->srq_lock); -return 0 ; }
@@ -3184,10 +3193,13 @@ static void mlx5_ib_dev_res_cleanup(struct mlx5_ib_dev *dev)/* After s0/s1 init, they are not unset during the device lifetime. */ if (devr->s1) {ib_destroy_srq (devr->s1); -ib_destroy_srq (devr->s0); +if (devr->s0) +ib_destroy_srq (devr->s0); + } +if (MLX5_CAP_GEN (dev->mdev, xrc)) { +mlx5_cmd_xrcd_dealloc (dev->mdev, devr->xrcdn1,0 ); +mlx5_cmd_xrcd_dealloc (dev->mdev, devr->xrcdn0,0 ); } -mlx5_cmd_xrcd_dealloc (dev->mdev, devr->xrcdn1,0 ); -mlx5_cmd_xrcd_dealloc (dev->mdev, devr->xrcdn0,0 );/* After p0/c0 init, they are not unset during the device lifetime. */ if (devr->c0) {ib_destroy_cq (devr->c0);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 441/816 RDMA/mlx5: Set QP event handler before firmware QPC insertion
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yishai Hadas <[email protected]>
[ Upstream commit 05a078c97eb0bb7158526dae414b853737692485 ]
Four QP creation paths assigned base->container_mibqp and base->mqp.event after the firmware create call that inserts the QP into dev->qp_table.tree. A firmware error EQE in that window reaches qp->event() with a NULL pointer.
Move both assignments before the firmware call.
Also set ibqp.qp_num inside mlx5_qpc_create_qp() before create_resource_common() so an EQE arriving early does not observe qp_num==0.
In addition, add a WARN_ON_ONCE(!qp->event) guard in rsc_event_notifier() as a safeguard for future regressions.
--- drivers/infiniband/hw/mlx5/qp.c | 22 ++++++++++------------ drivers/infiniband/hw/mlx5/qpc.c | 10 ++++++++++ 2 files changed, 20 insertions(+), 12 deletions(-)
drivers/infiniband/hw/mlx5/qp.c +10 -12
@@ -1599,6 +1599,8 @@ static int create_raw_packet_qp(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp,if (err)return err; + sq->base.container_mibqp = qp; + sq->base.mqp.event = mlx5_ib_qp_event; err =create_raw_packet_qp_sq (dev, udata, sq, in, pd,to_mcq (init_attr->send_cq));if (err)
@@ -1610,9 +1612,6 @@ static int create_raw_packet_qp(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp, resp->sqn = sq->base.mqp.qpn; resp->comp_mask |=MLX5_IB_CREATE_QP_RESP_MASK_SQN ; } - - sq->base.container_mibqp = qp; - sq->base.mqp.event = mlx5_ib_qp_event; }if (qp->rq.wqe_cnt) {
@@ -2058,13 +2057,13 @@ static int create_xrc_tgt_qp(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp, } base = &qp->trans_qp.base; + base->container_mibqp = qp; + base->mqp.event = mlx5_ib_qp_event; err =mlx5_qpc_create_qp (dev, &base->mqp, in, inlen, out);kvfree (in);if (err)return err; - base->container_mibqp = qp; - base->mqp.event = mlx5_ib_qp_event;if (MLX5_CAP_GEN (mdev, ece_support)) params->resp.ece_options =MLX5_GET (create_qp_out, out, ece);
@@ -2202,14 +2201,14 @@ static int create_dci(struct mlx5_ib_dev *dev, struct ib_pd *pd, qp->flags &= ~IB_QP_CREATE_PCI_WRITE_END_PADDING ; } + base->container_mibqp = qp; + base->mqp.event = mlx5_ib_qp_event; err =mlx5_qpc_create_qp (dev, &base->mqp, in, inlen, out);kvfree (in);if (err) goto err_create; - base->container_mibqp = qp; - base->mqp.event = mlx5_ib_qp_event;if (MLX5_CAP_GEN (mdev, ece_support)) params->resp.ece_options =MLX5_GET (create_qp_out, out, ece);
@@ -2398,6 +2397,8 @@ static int create_user_qp(struct mlx5_ib_dev *dev, struct ib_pd *pd, qp->flags &= ~IB_QP_CREATE_PCI_WRITE_END_PADDING ; } + base->container_mibqp = qp; + base->mqp.event = mlx5_ib_qp_event;if (init_attr->qp_type ==IB_QPT_RAW_PACKET || qp->flags &IB_QP_CREATE_SOURCE_QPN ) { qp->raw_packet_qp.sq.ubuffer.buf_addr = ucmd->sq_buf_addr;
@@ -2411,8 +2412,6 @@ static int create_user_qp(struct mlx5_ib_dev *dev, struct ib_pd *pd,if (err) goto err_create; - base->container_mibqp = qp; - base->mqp.event = mlx5_ib_qp_event;if (MLX5_CAP_GEN (mdev, ece_support)) params->resp.ece_options =MLX5_GET (create_qp_out, out, ece);
@@ -2541,14 +2540,13 @@ static int create_kernel_qp(struct mlx5_ib_dev *dev, struct ib_pd *pd, MLX5_CAP_GEN(mdev, go_back_n))MLX5_SET (qpc, qpc, retry_mode,MLX5_QP_RM_GO_BACK_N ); + base->container_mibqp = qp; + base->mqp.event = mlx5_ib_qp_event; err =mlx5_qpc_create_qp (dev, &base->mqp, in, inlen, out);kvfree (in);if (err) goto err_create; - base->container_mibqp = qp; - base->mqp.event = mlx5_ib_qp_event; -get_cqs (qp->type, attr->send_cq, attr->recv_cq, &send_cq, &recv_cq);spin_lock_irqsave (&dev->reset_flow_resource_lock, flags);
drivers/infiniband/hw/mlx5/qpc.c +10 -0
@@ -146,6 +146,8 @@ static int rsc_event_notifier(struct notifier_block *nb,case MLX5_RES_RQ :case MLX5_RES_SQ : qp = (struct mlx5_core_qp *)common; +if (WARN_ON_ONCE (!qp->event)) + goto out; qp->event (qp, event_type);/* Need to put resource in event handler */ return NOTIFY_OK ;
@@ -258,6 +260,14 @@ int mlx5_qpc_create_qp(struct mlx5_ib_dev *dev, struct mlx5_core_qp *qp, qp->uid =MLX5_GET (create_qp_in, in, uid); qp->qpn =MLX5_GET (create_qp_out, out, qpn); +/* Set ibqp.qp_num before create_resource_common() inserts the QP into +* the radix tree and makes it visible to EQE processing. The +* assignment in create_qp() happens only after this function returns, +* leaving a window where an arriving EQE would observe qp_num == 0. +* create_qp() still overrides this with 0/1 for QP0/QP1, and sets it +* independently for DCT (which does not go through this function). +*/ +to_mibqp (qp)->ibqp.qp_num = qp->qpn; err =create_resource_common (dev, qp,MLX5_RES_QP );if (err)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 442/816 powerpc/interrupt: Use early_radix_enabled() in NMI real-mode guard
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Venkat Rao Bagalkote <[email protected]>
[ Upstream commit 644ffb02746690c0ebfe143e066f81c9bde2975e ]
radix_enabled() uses a jump label which is only valid after setup_feature_keys() is called. Before that point, on a pSeries hash guest, early_check_vec5() clears MMU_FTR_TYPE_RADIX in cur_cpu_spec->mmu_features, but the jump label has not yet been patched, so radix_enabled() incorrectly returns true.
The dangerous usage window where it goes wrong in early_setup():
early_setup:
configure_exceptions();
<exceptions can happen now, and handler enter/exit can be invoked> <those could use radix_enabled(), which returns stale true> setup_feature_keys();
<jump labels set up; post this it is safe to use radix_enabled()>
If an NMI occurs in this window, !radix_enabled() evaluates to false in DEFINE_INTERRUPT_HANDLER_NMI. The handler fails to skip NMI entry in real mode and attempts to access memory outside the Real Mode Area (RMA), hanging the boot.
Since common interrupt wrappers do not have the context of early or late, using early_radix_enabled() is the safer option. It does a plain bitmask check against cur_cpu_spec->mmu_features and is correct at all times.
Console logs from a pSeries HASH guest showing values across boot stages:
[ 0.000000] DEBUG: after early_init_devtree: early_radix_enabled=0 radix_enabled=1 (mismatch means NMI real-mode check is unsafe!) [ 0.000000] DEBUG: after configure_exceptions (DANGEROUS WINDOW): early_radix_enabled=0 radix_enabled=1 [ 0.000000] DEBUG: after setup_feature_keys (jump labels initialized): early_radix_enabled=0 radix_enabled=0 (should now match!) [ 0.057124] DEBUG: post secondary CPU bringup: early_radix_enabled=0 radix_enabled=0 (should match!)
Console logs from a RADIX guest showing values across boot stages:
[ 0.000000] DEBUG: after early_init_devtree: early_radix_enabled=1 radix_enabled=1 (mismatch means NMI real-mode check is unsafe!) [ 0.000000] DEBUG: after configure_exceptions (DANGEROUS WINDOW): early_radix_enabled=1 radix_enabled=1 [ 0.000000] DEBUG: after setup_feature_keys (jump labels initialized): early_radix_enabled=1 radix_enabled=1 (should now match!) [ 0.057016] DEBUG: post secondary CPU bringup: early_radix_enabled=1 radix_enabled=1 (should match!)
Add the missing #include <asm/mmu.h> in alphabetical order since early_radix_enabled() is declared there.
--- arch/powerpc/include/asm/interrupt.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/interrupt.h +3 -2
@@ -72,6 +72,7 @@#include <asm/firmware.h> #include <asm/ftrace.h> #include <asm/kprobes.h> +#include <asm/mmu.h> #include <asm/runlatch.h> #ifdef CONFIG_PPC_IRQ_SOFT_MASK_DEBUG
@@ -326,7 +327,7 @@ static inline void interrupt_nmi_enter_prepare(struct pt_regs *regs, struct inte*/ if (IS_ENABLED (CONFIG_PPC_BOOK3S_64 ) &&firmware_has_feature (FW_FEATURE_LPAR ) && - !radix_enabled ()) + !early_radix_enabled ())return ;/*
@@ -355,7 +356,7 @@ static inline void interrupt_nmi_exit_prepare(struct pt_regs *regs, struct internmi_exit (); }else if (IS_ENABLED (CONFIG_PPC_BOOK3S_64 ) &&firmware_has_feature (FW_FEATURE_LPAR ) && - !radix_enabled ()) { + !early_radix_enabled ()) {// no nmi_exit for a pseries hash guest taking a real mode exception }else if (IS_ENABLED (CONFIG_KASAN )) {// no nmi_exit for KASAN in real mode
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 443/816 perf evsel: Clamp sample_id size for ksymbol, bpf, and text_poke events
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Rogers <[email protected]>
[ Upstream commit 7c89ea1bd4c612eb5cc2e6c01f77ebfc21d5c95d ]
On kernels without the fix ("perf/core: Restore header fields in sideband output callbacks") to restore event_id.header.size in perf_event_ksymbol_output(), perf_event_bpf_output(), and perf_event_text_poke_output(), concurrent perf sessions cause those sideband records to be emitted with header.size inflated by multiple id_header_size increments while the single id_sample is written immediately after the event payload. Indexing backwards from event->header.size reads uninitialized ring-buffer bytes at the end of the record, causing evlist__event2evsel() to fail with -EFAULT.
Add evsel__event_size() to clamp the effective size used to locate the trailing id_sample for PERF_RECORD_KSYMBOL, PERF_RECORD_BPF_EVENT, and PERF_RECORD_TEXT_POKE to payload + id_hdr_size while leaving event->header.size intact for advancing the ring-buffer/file stream.
--- tools/perf/util/evlist.c | 6 ++-- tools/perf/util/evsel.c | 59 +++++++++++++++++++++++++++++++++++++++- tools/perf/util/evsel.h | 1 + 3 files changed, 63 insertions(+), 3 deletions(-)
tools/perf/util/evlist.c +4 -2
@@ -701,13 +701,15 @@ static int evlist__event2id(struct evlist *evlist, union perf_event *event, u64const __u64 *array = event->sample.array;ssize_t n; - n = (event->header.size -sizeof (event->header)) >>3 ; -if (event->header.type ==PERF_RECORD_SAMPLE ) { + n = (event->header.size -sizeof (event->header)) >>3 ;if (evlist->id_pos >= n)return -1 ; *id = array[evlist->id_pos]; }else { +u16 size =evsel__event_size (evlist__first (evlist), event); + + n = (size -sizeof (event->header)) >>3 ;if (evlist->is_pos > n)return -1 ; n -= evlist->is_pos;
tools/perf/util/evsel.c +58 -1
71 lines not on this page · raw message
tools/perf/util/evsel.h +1 -0
@@ -435,6 +435,7 @@ int evsel__parse_sample_timestamp(struct evsel *evsel, union perf_event *event, u64 *timestamp);u16 evsel__id_hdr_size (const struct evsel *evsel); +u16 evsel__event_size (const struct evsel *evsel,const union perf_event *event);static inline struct evsel *evsel__next (struct evsel *evsel) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 444/816 ALSA: usb-audio: Fix UAC2 mixer unit request handling
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit 0458d97859840506c3688a963dcd4f72b4a23083 ]
For a request for a Mixer Unit on UAC2 (also UAC3), the wValue is different from UAC1 and an incompatible value must be passed. Namely, UAC1 takes a word consisting of 1-based input channel in the high byte and 1-based output channel in the low byte. Meanwhile, UAC2/3 takes UAC2_MU_MIXER in the high byte and a MCN (0-based bit position of input/output channels) in the low byte. The current driver implementation blindly assumes the UAC1 way, hence it would cause a firmware error.
This patch attempts to implement the conversion to UAC2 MCN at get_ctl_value_v2() and snd_usb_mixer_set_ctl_value() for mixer units. At the points above, the old wValue containing ICN and OCN is converted to the corresponding MCN, and it's used as the proper wValue.
--- sound/usb/mixer.c | 23 +++++++++++++++++++++++ sound/usb/mixer.h | 2 ++ 2 files changed, 25 insertions(+)
sound/usb/mixer.c +23 -0
@@ -340,6 +340,17 @@ static int get_ctl_value_v1(struct usb_mixer_elem_info *cval, int request,return err; } +/* convert the given UAC1 wValue (ICN|OCN) to UAC2 MCN */ +static unsigned char to_mcn (const struct usb_mixer_elem_info *cval, +unsigned int validx) +{ +unsigned char m = (validx >>8 ) &0xff ;/* 1-based input channel */ +unsigned char v = validx &0xff ;/* 1-based output channel */ + +/* num_inputs * num_outputs is guaranteed to be < 256 */ +return (m -1 ) * cval->num_outputs + (v -1 ); +} +static int get_ctl_value_v2 (struct usb_mixer_elem_info *cval,int request,int validx,int *value_ret) {
@@ -352,6 +363,10 @@ static int get_ctl_value_v2(struct usb_mixer_elem_info *cval, int request, val_size =uac2_ctl_value_size (cval->val_type); +/* correct wValue for UAC2 mixer control with MCN */ +if (cval->v2_mixer) + validx = (UAC2_MU_MIXER <<8 ) |to_mcn (cval, validx); +if (request ==UAC_GET_CUR ) { bRequest =UAC2_CS_CUR ; size = val_size;
@@ -476,6 +491,10 @@ int snd_usb_mixer_set_ctl_value(struct usb_mixer_elem_info *cval, } request =UAC2_CS_CUR ; + +/* correct wValue for UAC2 mixer control with MCN */ +if (cval->v2_mixer) + validx = (UAC2_MU_MIXER <<8 ) |to_mcn (cval, validx); } value_set =convert_bytes_value (cval, value_set);
@@ -2208,6 +2227,10 @@ static void build_mixer_unit_ctl(struct mixer_build *state,snd_usb_mixer_elem_init_std (&cval->head, state->mixer, unitid); cval->control = in_ch +1 ;/* based on 1 */ +if (state->mixer->protocol ==UAC_VERSION_2 || + state->mixer->protocol ==UAC_VERSION_3 ) + cval->v2_mixer = true; + cval->num_outputs = num_outs; cval->val_type =USB_MIXER_S16 ;for (i =0 ; i < num_outs; i++) {__u8 *c =uac_mixer_unit_bmControls (desc, state->mixer->protocol);
sound/usb/mixer.h +2 -0
@@ -97,6 +97,8 @@ struct usb_mixer_elem_info {int cache_val[MAX_CHANNELS ];u8 initialized;u8 min_mute; +u8 num_outputs; +bool v2_mixer;void *private_data; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 445/816 s390/ism: Zerorize dmb at allocation
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexandra Winter <[email protected]>
[ Upstream commit a0227fa24e8a2a0397cc4eb669731ff8d9161bbd ]
Sashiko reported [1] that 'Missing __GFP_ZERO in folio_alloc() causes uninitialized kernel memory to be exposed in the receive message buffer'. An ism dmb is receive-only, so the data is not leaked to a remote peer. In general the smc kernel module (dibs client) will only push newly received data to userspace. We still should not have uninitialized data in a receive buffer.
Since
commit 750afb08ca71 ("cross-tree: phase out dma_zalloc_coherent()") dma_alloc_coherent no longer required the __GFP_ZERO flag, but when commit 83781384a96b ("s390/ism: Properly fix receive message buffer allocation") switched to folio_alloc(), it should have added back the __GFP_ZERO flag.
Add __GFP_ZERO flag and state in dibs.h that register_dbm() provides a zerorized buffer (dibs_lo already does).
--- drivers/s390/net/ism_drv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/s390/net/ism_drv.c +2 -1
@@ -328,7 +328,8 @@ static int ism_alloc_dmb(struct ism_dev *ism, struct ism_dmb *dmb)return -EINVAL ; folio =folio_alloc (GFP_KERNEL | __GFP_NOWARN | __GFP_NOMEMALLOC | - __GFP_NORETRY,get_order (dmb->dmb_len)); + __GFP_NORETRY | __GFP_ZERO, +get_order (dmb->dmb_len));if (!folio) { rc = -ENOMEM ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 446/816 mei: vsc-tp: initialize IRQ state before requesting interrupt
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
[ Upstream commit 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 | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/misc/mei/vsc-tp.c +8 -7
@@ -527,29 +527,29 @@ 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); +irq_set_status_flags (spi->irq,IRQ_DISABLE_UNLAZY ); ret =request_threaded_irq (spi->irq, vsc_tp_isr, vsc_tp_thread_isr,IRQF_TRIGGER_FALLING |IRQF_ONESHOT ,dev_name (dev), tp);if (ret) -return ret; - -mutex_init (&tp->mutex); -mutex_init (&tp->event_notify_mutex); + 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;
@@ -557,9 +557,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:mutex_destroy (&tp->event_notify_mutex);mutex_destroy (&tp->mutex);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 447/816 debugfs: make debugfs_create_str() read-only
In reply to Greg Kroah-Hartman6.12-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
@@ -992,98 +992,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 448/816 riscv: dts: starfive: jh7110-common: revised device node
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guodong Xu <[email protected]>
[ Upstream commit 5a5001d27065126d815eb54e12744b08322e3d31 ]
Earlier this year a new DTSI file was created to define common properties for the StarFive VisionFive 2 and Milk-V Mars boards, both of which use the StarFive JH7110 SoC. The Pine64 Star64 board has also been added since that time.
Some of the nodes defined in "jh7110-common.dtsi" are enabled in that file because all of the boards including it "want" them enabled.
An upcoming patch enables another JH7110 board, but for that board not all of these common nodes should be enabled. Prepare for supporting the new board by avoiding enabling these nodes in "jh7110-common.dtsi", and enable them instead in these files:
jh7110-milkv-mars.dts
jh7110-pine64-star64.dts jh7110-starfive-visionfive-2.dtsi
Stable-dep-of: 2186ec5f59c2 ("riscv: dts: starfive: Correct pwm nodes")
--- .../boot/dts/starfive/jh7110-common.dtsi | 5 ----- .../boot/dts/starfive/jh7110-milkv-mars.dts | 17 ++++++++++++++++ .../dts/starfive/jh7110-pine64-star64.dts | 17 ++++++++++++++++ .../jh7110-starfive-visionfive-2.dtsi | 20 +++++++++++++++++++ 4 files changed, 54 insertions(+), 5 deletions(-)
arch/riscv/boot/dts/starfive/jh7110-common.dtsi +0 -5
@@ -174,7 +174,6 @@ csi2rx_to_camss: endpoint { &gmac0 { phy-handle = <&phy0>; phy-mode = "rgmii-id"; - status = "okay"; mdio { #address-cells = <1>;
@@ -194,7 +193,6 @@ &i2c0 { i2c-scl-falling-time-ns = <510>; pinctrl-names = "default"; pinctrl-0 = <&i2c0_pins>; - status = "okay"; }; &i2c2 {
@@ -309,7 +307,6 @@ &pcie1 { &pwmdac { pinctrl-names = "default"; pinctrl-0 = <&pwmdac_pins>; - status = "okay"; }; &qspi {
@@ -348,13 +345,11 @@ uboot@100000 { &pwm { pinctrl-names = "default"; pinctrl-0 = <&pwm_pins>; - status = "okay"; }; &spi0 { pinctrl-names = "default"; pinctrl-0 = <&spi0_pins>; - status = "okay"; spi_dev0: spi@0 { compatible = "rohm,dh2228fv";
arch/riscv/boot/dts/starfive/jh7110-milkv-mars.dts +17 -0
@@ -15,6 +15,11 @@ &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"; }; &pcie0 {
@@ -35,3 +40,15 @@ &phy0 { rx-internal-delay-ps = <1500>; tx-internal-delay-ps = <1500>; }; + +&pwm { + status = "okay"; +}; + +&pwmdac { + status = "okay"; +}; + +&spi0 { + status = "okay"; +};
arch/riscv/boot/dts/starfive/jh7110-pine64-star64.dts +17 -0
@@ -18,6 +18,7 @@ &gmac0 { starfive,tx-use-rgmii-clk; assigned-clocks = <&aoncrg JH7110_AONCLK_GMAC0_TX>; assigned-clock-parents = <&aoncrg JH7110_AONCLK_GMAC0_RMII_RTX>; + status = "okay"; }; &gmac1 {
@@ -39,6 +40,10 @@ phy1: ethernet-phy@1 { }; }; +&i2c0 { + status = "okay"; +}; + &pcie1 { status = "okay"; };
@@ -62,3 +67,15 @@ &phy1 { motorcomm,tx-clk-10-inverted; motorcomm,tx-clk-100-inverted; }; + +&pwm { + status = "okay"; +}; + +&pwmdac { + status = "okay"; +}; + +&spi0 { + status = "okay"; +};
arch/riscv/boot/dts/starfive/jh7110-starfive-visionfive-2.dtsi +20 -0
@@ -13,6 +13,10 @@ aliases { }; }; +&gmac0 { + status = "okay"; +}; + &gmac1 { phy-handle = <&phy1>; phy-mode = "rgmii-id";
@@ -29,6 +33,10 @@ phy1: ethernet-phy@1 { }; }; +&i2c0 { + status = "okay"; +}; + &mmc0 { non-removable; };
@@ -40,3 +48,15 @@ &pcie0 { &pcie1 { status = "okay"; }; + +&pwm { + status = "okay"; +}; + +&pwmdac { + status = "okay"; +}; + +&spi0 { + status = "okay"; +};
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 449/816 riscv: dts: starfive: Correct pwm nodes
In reply to Greg Kroah-Hartman6.12-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-pine64-star64.dts | 6 +- .../jh7110-starfive-visionfive-2.dtsi | 6 +- arch/riscv/boot/dts/starfive/jh7110.dtsi | 67 ++++++++++++++++++- 7 files changed, 188 insertions(+), 19 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
@@ -342,9 +342,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 {
@@ -550,12 +555,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 { tx-internal-delay-ps = <1500>; }; -&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.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 450/816 bpf: Roll back freplace link state when bpf_arch_text_poke() fails
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuan Chen <[email protected]>
[ Upstream commit 5ec398d9ec8fe13f8058af9a2e5f5e8f46e0a35a ]
A freplace attach claims the target prog by bumping tgt_prog->aux->freplace_link_cnt and setting tr->extension_prog. bpf_arch_text_poke() then makes the extension take effect. If the poke fails, the claims are never released: the attach unwinds through bpf_link_cleanup(), which clears link->prog, so bpf_trampoline_unlink_prog() never runs.
Drop the link count under ext_mutex on the error path, and set tr->extension_prog only after the poke succeeded. The count is still bumped before the poke: it blocks prog_array updates while the entry is patched.
--- kernel/bpf/trampoline.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
kernel/bpf/trampoline.c +9 -2
@@ -576,9 +576,16 @@ static int __bpf_trampoline_link_prog(struct bpf_tramp_link *link, err =bpf_freplace_link_tgt_prog (tgt_prog);if (err)return err; + err =bpf_arch_text_poke (tr->func.addr,BPF_MOD_JUMP ,NULL , + link->link.prog->bpf_func); +if (err) { +/* Undo the claim from bpf_freplace_link_tgt_prog(). */ +guard (mutex)(&tgt_prog->aux->ext_mutex); + tgt_prog->aux->freplace_link_cnt--; +return err; + } tr->extension_prog = link->link.prog; -return bpf_arch_text_poke (tr->func.addr,BPF_MOD_JUMP ,NULL , - link->link.prog->bpf_func); +return 0 ; }if (cnt >=BPF_MAX_TRAMP_LINKS )return -E2BIG ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 451/816 scsi: scsi_debug: Avoid 32-bit overflow in WRITE SCATTERED offsets
In reply to Greg Kroah-Hartman6.12-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
@@ -4613,7 +4613,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;
@@ -4691,14 +4692,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: %s: k=%d LBA=0x%llx num=%u sg_off=%u\n" , +"%s: %s: k=%d LBA=0x%llx num=%u sg_off=%llu\n" , my_name, __func__, 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) {
@@ -4729,7 +4730,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);
@@ -4740,7 +4743,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 452/816 scsi: scsi_debug: Enforce physical block alignment of zoned writes
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Cassel <[email protected]>
[ Upstream commit 63cb3900be261fccc05cadcf3402058418a5fada ]
ZBC-3 r06 (T10/BSR INCITS 579), 4.5.3.3.2, requires a write to a sequential write required zone to be terminated with ILLEGAL REQUEST / UNALIGNED WRITE COMMAND both when it does not start at the write pointer and when it does not end on a physical block boundary. That is why sd_zbc_read_zones() sets the zone_write_granularity queue limit to the physical block size of a host-managed device.
check_zbc_access_params() implements the first condition but not the second. So with zbc=managed sector_size=512 physblk_exp=3, a write of a single logical block at the write pointer is accepted and advances the write pointer by one logical block, leaving it off the granularity that was
advertised: nothing can write at it any more, and the zone can only be used again after being reset.
Check the ending LBA as well, with the same sense data, as the standard gives both conditions the same. An entire medium write same command, which the standard excludes, needs no special case: the preceding check already terminates it with WRITE BOUNDARY VIOLATION. Sequential write preferred zones are left alone, as writes to them need not be sequential, and with the default physblk_exp=0 the check is a no-op.
--- drivers/scsi/scsi_debug.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/scsi/scsi_debug.c +11 -0
@@ -3571,6 +3571,17 @@ static int check_zbc_access_params(struct scsi_cmnd *scp, UNALIGNED_WRITE_ASCQ);return check_condition_result; } +/* +* Writes must end on a physical block boundary, that is, the +* transfer length must be a multiple of the physical block +* size. +*/ +if (!IS_ALIGNED (lba + num,1U << sdebug_physblk_exp)) { +mk_sense_buffer (scp,ILLEGAL_REQUEST , +LBA_OUT_OF_RANGE , +UNALIGNED_WRITE_ASCQ ); +return check_condition_result; + } }/* Handle implicit open of closed and empty zones */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 453/816 scsi: scsi_debug: Advance the write pointer over the data written
In reply to Greg Kroah-Hartman6.12-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
@@ -4577,9 +4577,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);
@@ -4744,9 +4744,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 454/816 phy: rockchip: naneng-combphy: Add SoC prefix to register definitions
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yao Zi <[email protected]>
[ Upstream commit b3bbc6afcff50e2fd4d51dd64929e62d66fdc814 ]
All supported variants of naneng-combphy follow a register layout similar to the RK3568 variant with some exceptions of SoC-specific registers.
Add RK3568 prefix for the common set of registers and the corresponding SoC prefix for SoC-specific registers, making usage of definitions clear and preparing for future COMBPHY variants with a different register layout.
Stable-dep-of: d68e47a06c5c ("phy: rockchip: naneng-combphy: Fix TX detect RX termination errata")
--- .../rockchip/phy-rockchip-naneng-combphy.c | 301 +++++++++--------- 1 file changed, 151 insertions(+), 150 deletions(-)
drivers/phy/rockchip/phy-rockchip-naneng-combphy.c +151 -150
@@ -21,64 +21,65 @@#define REF_CLOCK_100MHz (100 * HZ_PER_MHZ)/* COMBO PHY REG */ -#define PHYREG6 0x14 -#define PHYREG6_PLL_DIV_MASK GENMASK(7, 6) -#define PHYREG6_PLL_DIV_SHIFT 6 -#define PHYREG6_PLL_DIV_2 1 - -#define PHYREG7 0x18 -#define PHYREG7_TX_RTERM_MASK GENMASK(7, 4) -#define PHYREG7_TX_RTERM_SHIFT 4 -#define PHYREG7_TX_RTERM_50OHM 8 -#define PHYREG7_RX_RTERM_MASK GENMASK(3, 0) -#define PHYREG7_RX_RTERM_SHIFT 0 -#define PHYREG7_RX_RTERM_44OHM 15 - -#define PHYREG8 0x1C -#define PHYREG8_SSC_EN BIT(4) - -#define PHYREG11 0x28 -#define PHYREG11_SU_TRIM_0_7 0xF0 - -#define PHYREG12 0x2C -#define PHYREG12_PLL_LPF_ADJ_VALUE 4 - -#define PHYREG13 0x30 -#define PHYREG13_RESISTER_MASK GENMASK(5, 4) -#define PHYREG13_RESISTER_SHIFT 0x4 -#define PHYREG13_RESISTER_HIGH_Z 3 -#define PHYREG13_CKRCV_AMP0 BIT(7) - -#define PHYREG14 0x34 -#define PHYREG14_CKRCV_AMP1 BIT(0) - -#define PHYREG15 0x38 -#define PHYREG15_CTLE_EN BIT(0) -#define PHYREG15_SSC_CNT_MASK GENMASK(7, 6) -#define PHYREG15_SSC_CNT_SHIFT 6 -#define PHYREG15_SSC_CNT_VALUE 1 - -#define PHYREG16 0x3C -#define PHYREG16_SSC_CNT_VALUE 0x5f - -#define PHYREG18 0x44 -#define PHYREG18_PLL_LOOP 0x32 - -#define PHYREG27 0x6C -#define PHYREG27_RX_TRIM_RK3588 0x4C - -#define PHYREG32 0x7C -#define PHYREG32_SSC_MASK GENMASK(7, 4) -#define PHYREG32_SSC_DIR_SHIFT 4 -#define PHYREG32_SSC_UPWARD 0 -#define PHYREG32_SSC_DOWNWARD 1 -#define PHYREG32_SSC_OFFSET_SHIFT 6 -#define PHYREG32_SSC_OFFSET_500PPM 1 - -#define PHYREG33 0x80 -#define PHYREG33_PLL_KVCO_MASK GENMASK(4, 2) -#define PHYREG33_PLL_KVCO_SHIFT 2 -#define PHYREG33_PLL_KVCO_VALUE 2 +#define RK3568_PHYREG6 0x14 +#define RK3568_PHYREG6_PLL_DIV_MASK GENMASK(7, 6) +#define RK3568_PHYREG6_PLL_DIV_SHIFT 6 +#define RK3568_PHYREG6_PLL_DIV_2 1 + +#define RK3568_PHYREG7 0x18 +#define RK3568_PHYREG7_TX_RTERM_MASK GENMASK(7, 4) +#define RK3568_PHYREG7_TX_RTERM_SHIFT 4 +#define RK3568_PHYREG7_TX_RTERM_50OHM 8 +#define RK3568_PHYREG7_RX_RTERM_MASK GENMASK(3, 0) +#define RK3568_PHYREG7_RX_RTERM_SHIFT 0 +#define RK3568_PHYREG7_RX_RTERM_44OHM 15 + +#define RK3568_PHYREG8 0x1C +#define RK3568_PHYREG8_SSC_EN BIT(4) + +#define RK3568_PHYREG11 0x28 +#define RK3568_PHYREG11_SU_TRIM_0_7 0xF0 + +#define RK3568_PHYREG12 0x2C +#define RK3568_PHYREG12_PLL_LPF_ADJ_VALUE 4 + +#define RK3568_PHYREG13 0x30 +#define RK3568_PHYREG13_RESISTER_MASK GENMASK(5, 4) +#define RK3568_PHYREG13_RESISTER_SHIFT 0x4 +#define RK3568_PHYREG13_RESISTER_HIGH_Z 3 +#define RK3568_PHYREG13_CKRCV_AMP0 BIT(7) + +#define RK3568_PHYREG14 0x34 +#define RK3568_PHYREG14_CKRCV_AMP1 BIT(0) + +#define RK3568_PHYREG15 0x38 +#define RK3568_PHYREG15_CTLE_EN BIT(0) +#define RK3568_PHYREG15_SSC_CNT_MASK GENMASK(7, 6) +#define RK3568_PHYREG15_SSC_CNT_SHIFT 6 +#define RK3568_PHYREG15_SSC_CNT_VALUE 1 + +#define RK3568_PHYREG16 0x3C +#define RK3568_PHYREG16_SSC_CNT_VALUE 0x5f + +#define RK3568_PHYREG18 0x44 +#define RK3568_PHYREG18_PLL_LOOP 0x32 + +#define RK3568_PHYREG32 0x7C +#define RK3568_PHYREG32_SSC_MASK GENMASK(7, 4) +#define RK3568_PHYREG32_SSC_DIR_SHIFT 4 +#define RK3568_PHYREG32_SSC_UPWARD 0 +#define RK3568_PHYREG32_SSC_DOWNWARD 1 +#define RK3568_PHYREG32_SSC_OFFSET_SHIFT 6 +#define RK3568_PHYREG32_SSC_OFFSET_500PPM 1 + +#define RK3568_PHYREG33 0x80 +#define RK3568_PHYREG33_PLL_KVCO_MASK GENMASK(4, 2) +#define RK3568_PHYREG33_PLL_KVCO_SHIFT 2 +#define RK3568_PHYREG33_PLL_KVCO_VALUE 2 + +/* RK3588 COMBO PHY registers */ +#define RK3588_PHYREG27 0x6C +#define RK3588_PHYREG27_RX_TRIM 0x4Cstruct rockchip_combphy_priv ;
@@ -392,9 +393,9 @@ static int rk3568_combphy_cfg(struct rockchip_combphy_priv *priv)switch (priv->type) {case PHY_TYPE_PCIE :/* Set SSC downward spread spectrum. */ -rockchip_combphy_updatel (priv,PHYREG32_SSC_MASK , -PHYREG32_SSC_DOWNWARD <<PHYREG32_SSC_DIR_SHIFT , -PHYREG32 ); +rockchip_combphy_updatel (priv,RK3568_PHYREG32_SSC_MASK , +RK3568_PHYREG32_SSC_DOWNWARD <<RK3568_PHYREG32_SSC_DIR_SHIFT , +RK3568_PHYREG32 );rockchip_combphy_param_write (priv->phy_grf, &cfg->con0_for_pcie, true);rockchip_combphy_param_write (priv->phy_grf, &cfg->con1_for_pcie, true);
@@ -404,30 +405,30 @@ static int rk3568_combphy_cfg(struct rockchip_combphy_priv *priv)case PHY_TYPE_USB3 :/* Set SSC downward spread spectrum. */ -rockchip_combphy_updatel (priv,PHYREG32_SSC_MASK , -PHYREG32_SSC_DOWNWARD <<PHYREG32_SSC_DIR_SHIFT , -PHYREG32 ); +rockchip_combphy_updatel (priv,RK3568_PHYREG32_SSC_MASK , +RK3568_PHYREG32_SSC_DOWNWARD <<RK3568_PHYREG32_SSC_DIR_SHIFT , +RK3568_PHYREG32 );/* Enable adaptive CTLE for USB3.0 Rx. */ - val =readl (priv->mmio +PHYREG15 ); - val |=PHYREG15_CTLE_EN ; -writel (val, priv->mmio +PHYREG15 ); + val =readl (priv->mmio +RK3568_PHYREG15 ); + val |=RK3568_PHYREG15_CTLE_EN ; +writel (val, priv->mmio +RK3568_PHYREG15 );/* Set PLL KVCO fine tuning signals. */ -rockchip_combphy_updatel (priv,PHYREG33_PLL_KVCO_MASK , -PHYREG33_PLL_KVCO_VALUE <<PHYREG33_PLL_KVCO_SHIFT , -PHYREG33 ); +rockchip_combphy_updatel (priv,RK3568_PHYREG33_PLL_KVCO_MASK , +RK3568_PHYREG33_PLL_KVCO_VALUE <<RK3568_PHYREG33_PLL_KVCO_SHIFT , +RK3568_PHYREG33 );/* Enable controlling random jitter. */ -writel (PHYREG12_PLL_LPF_ADJ_VALUE , priv->mmio +PHYREG12 ); +writel (RK3568_PHYREG12_PLL_LPF_ADJ_VALUE , priv->mmio +RK3568_PHYREG12 );/* Set PLL input clock divider 1/2. */ -rockchip_combphy_updatel (priv,PHYREG6_PLL_DIV_MASK , -PHYREG6_PLL_DIV_2 <<PHYREG6_PLL_DIV_SHIFT , -PHYREG6 ); +rockchip_combphy_updatel (priv,RK3568_PHYREG6_PLL_DIV_MASK , +RK3568_PHYREG6_PLL_DIV_2 <<RK3568_PHYREG6_PLL_DIV_SHIFT , +RK3568_PHYREG6 ); -writel (PHYREG18_PLL_LOOP , priv->mmio +PHYREG18 ); -writel (PHYREG11_SU_TRIM_0_7 , priv->mmio +PHYREG11 ); +writel (RK3568_PHYREG18_PLL_LOOP , priv->mmio +RK3568_PHYREG18 ); +writel (RK3568_PHYREG11_SU_TRIM_0_7 , priv->mmio +RK3568_PHYREG11 );rockchip_combphy_param_write (priv->phy_grf, &cfg->pipe_sel_usb, true);rockchip_combphy_param_write (priv->phy_grf, &cfg->pipe_txcomp_sel, false);
@@ -445,16 +446,16 @@ static int rk3568_combphy_cfg(struct rockchip_combphy_priv *priv)case PHY_TYPE_SATA :/* Enable adaptive CTLE for SATA Rx. */ - val =readl (priv->mmio +PHYREG15 ); - val |=PHYREG15_CTLE_EN ; -writel (val, priv->mmio +PHYREG15 ); + val =readl (priv->mmio +RK3568_PHYREG15 ); + val |=RK3568_PHYREG15_CTLE_EN ; +writel (val, priv->mmio +RK3568_PHYREG15 );/* * Set tx_rterm=50ohm and rx_rterm=44ohm for SATA. * 0: 60ohm, 8: 50ohm 15: 44ohm (by step abort 1ohm) */ - val =PHYREG7_TX_RTERM_50OHM <<PHYREG7_TX_RTERM_SHIFT ; - val |=PHYREG7_RX_RTERM_44OHM <<PHYREG7_RX_RTERM_SHIFT ; -writel (val, priv->mmio +PHYREG7 ); + val =RK3568_PHYREG7_TX_RTERM_50OHM <<RK3568_PHYREG7_TX_RTERM_SHIFT ; + val |=RK3568_PHYREG7_RX_RTERM_44OHM <<RK3568_PHYREG7_RX_RTERM_SHIFT ; +writel (val, priv->mmio +RK3568_PHYREG7 );rockchip_combphy_param_write (priv->phy_grf, &cfg->con0_for_sata, true);rockchip_combphy_param_write (priv->phy_grf, &cfg->con1_for_sata, true);
@@ -489,11 +490,11 @@ static int rk3568_combphy_cfg(struct rockchip_combphy_priv *priv)case REF_CLOCK_24MHz:if (priv->type ==PHY_TYPE_USB3 || priv->type ==PHY_TYPE_SATA ) {/* Set ssc_cnt[9:0]=0101111101 & 31.5KHz. */ - val =PHYREG15_SSC_CNT_VALUE <<PHYREG15_SSC_CNT_SHIFT ; -rockchip_combphy_updatel (priv,PHYREG15_SSC_CNT_MASK , - val,PHYREG15 ); + val =RK3568_PHYREG15_SSC_CNT_VALUE <<RK3568_PHYREG15_SSC_CNT_SHIFT ; +rockchip_combphy_updatel (priv,RK3568_PHYREG15_SSC_CNT_MASK , + val,RK3568_PHYREG15 ); -writel (PHYREG16_SSC_CNT_VALUE , priv->mmio +PHYREG16 ); +writel (RK3568_PHYREG16_SSC_CNT_VALUE , priv->mmio +RK3568_PHYREG16 ); }break ;
@@ -505,24 +506,24 @@ static int rk3568_combphy_cfg(struct rockchip_combphy_priv *priv)rockchip_combphy_param_write (priv->phy_grf, &cfg->pipe_clk_100m, true);if (priv->type ==PHY_TYPE_PCIE ) {/* PLL KVCO fine tuning. */ - val =PHYREG33_PLL_KVCO_VALUE <<PHYREG33_PLL_KVCO_SHIFT ; -rockchip_combphy_updatel (priv,PHYREG33_PLL_KVCO_MASK , - val,PHYREG33 ); + val =RK3568_PHYREG33_PLL_KVCO_VALUE <<RK3568_PHYREG33_PLL_KVCO_SHIFT ; +rockchip_combphy_updatel (priv,RK3568_PHYREG33_PLL_KVCO_MASK , + val,RK3568_PHYREG33 );/* Enable controlling random jitter. */ -writel (PHYREG12_PLL_LPF_ADJ_VALUE , priv->mmio +PHYREG12 ); +writel (RK3568_PHYREG12_PLL_LPF_ADJ_VALUE , priv->mmio +RK3568_PHYREG12 ); - val =PHYREG6_PLL_DIV_2 <<PHYREG6_PLL_DIV_SHIFT ; -rockchip_combphy_updatel (priv,PHYREG6_PLL_DIV_MASK , - val,PHYREG6 ); + val =RK3568_PHYREG6_PLL_DIV_2 <<RK3568_PHYREG6_PLL_DIV_SHIFT ; +rockchip_combphy_updatel (priv,RK3568_PHYREG6_PLL_DIV_MASK , + val,RK3568_PHYREG6 ); -writel (PHYREG18_PLL_LOOP , priv->mmio +PHYREG18 ); -writel (PHYREG11_SU_TRIM_0_7 , priv->mmio +PHYREG11 ); +writel (RK3568_PHYREG18_PLL_LOOP , priv->mmio +RK3568_PHYREG18 ); +writel (RK3568_PHYREG11_SU_TRIM_0_7 , priv->mmio +RK3568_PHYREG11 ); }else if (priv->type ==PHY_TYPE_SATA ) {/* downward spread spectrum +500ppm */ - val =PHYREG32_SSC_DOWNWARD <<PHYREG32_SSC_DIR_SHIFT ; - val |=PHYREG32_SSC_OFFSET_500PPM <<PHYREG32_SSC_OFFSET_SHIFT ; -rockchip_combphy_updatel (priv,PHYREG32_SSC_MASK , val,PHYREG32 ); + val =RK3568_PHYREG32_SSC_DOWNWARD <<RK3568_PHYREG32_SSC_DIR_SHIFT ; + val |=RK3568_PHYREG32_SSC_OFFSET_500PPM <<RK3568_PHYREG32_SSC_OFFSET_SHIFT ; +rockchip_combphy_updatel (priv,RK3568_PHYREG32_SSC_MASK , val,RK3568_PHYREG32 ); }break ;
@@ -534,20 +535,20 @@ static int rk3568_combphy_cfg(struct rockchip_combphy_priv *priv)if (priv->ext_refclk) {rockchip_combphy_param_write (priv->phy_grf, &cfg->pipe_clk_ext, true);if (priv->type ==PHY_TYPE_PCIE && rate == REF_CLOCK_100MHz) { - val =PHYREG13_RESISTER_HIGH_Z <<PHYREG13_RESISTER_SHIFT ; - val |=PHYREG13_CKRCV_AMP0 ; -rockchip_combphy_updatel (priv,PHYREG13_RESISTER_MASK , val,PHYREG13 ); + val =RK3568_PHYREG13_RESISTER_HIGH_Z <<RK3568_PHYREG13_RESISTER_SHIFT ; + val |=RK3568_PHYREG13_CKRCV_AMP0 ; +rockchip_combphy_updatel (priv,RK3568_PHYREG13_RESISTER_MASK , val,RK3568_PHYREG13 ); - val =readl (priv->mmio +PHYREG14 ); - val |=PHYREG14_CKRCV_AMP1 ; -writel (val, priv->mmio +PHYREG14 ); + val =readl (priv->mmio +RK3568_PHYREG14 ); + val |=RK3568_PHYREG14_CKRCV_AMP1 ; +writel (val, priv->mmio +RK3568_PHYREG14 ); } }if (priv->enable_ssc) { - val =readl (priv->mmio +PHYREG8 ); - val |=PHYREG8_SSC_EN ; -writel (val, priv->mmio +PHYREG8 ); + val =readl (priv->mmio +RK3568_PHYREG8 ); + val |=RK3568_PHYREG8_SSC_EN ; +writel (val, priv->mmio +RK3568_PHYREG8 ); }return 0 ;
@@ -622,30 +623,30 @@ static int rk3588_combphy_cfg(struct rockchip_combphy_priv *priv)break ;case PHY_TYPE_USB3 :/* Set SSC downward spread spectrum */ -rockchip_combphy_updatel (priv,PHYREG32_SSC_MASK , -PHYREG32_SSC_DOWNWARD <<PHYREG32_SSC_DIR_SHIFT , -PHYREG32 ); +rockchip_combphy_updatel (priv,RK3568_PHYREG32_SSC_MASK , +RK3568_PHYREG32_SSC_DOWNWARD <<RK3568_PHYREG32_SSC_DIR_SHIFT , +RK3568_PHYREG32 );/* Enable adaptive CTLE for USB3.0 Rx. */ - val =readl (priv->mmio +PHYREG15 ); - val |=PHYREG15_CTLE_EN ; -writel (val, priv->mmio +PHYREG15 ); + val =readl (priv->mmio +RK3568_PHYREG15 ); + val |=RK3568_PHYREG15_CTLE_EN ; +writel (val, priv->mmio +RK3568_PHYREG15 );/* Set PLL KVCO fine tuning signals. */ -rockchip_combphy_updatel (priv,PHYREG33_PLL_KVCO_MASK , -PHYREG33_PLL_KVCO_VALUE <<PHYREG33_PLL_KVCO_SHIFT , -PHYREG33 ); +rockchip_combphy_updatel (priv,RK3568_PHYREG33_PLL_KVCO_MASK , +RK3568_PHYREG33_PLL_KVCO_VALUE <<RK3568_PHYREG33_PLL_KVCO_SHIFT , +RK3568_PHYREG33 );/* Enable controlling random jitter. */ -writel (PHYREG12_PLL_LPF_ADJ_VALUE , priv->mmio +PHYREG12 ); +writel (RK3568_PHYREG12_PLL_LPF_ADJ_VALUE , priv->mmio +RK3568_PHYREG12 );/* Set PLL input clock divider 1/2. */ -rockchip_combphy_updatel (priv,PHYREG6_PLL_DIV_MASK , -PHYREG6_PLL_DIV_2 <<PHYREG6_PLL_DIV_SHIFT , -PHYREG6 ); +rockchip_combphy_updatel (priv,RK3568_PHYREG6_PLL_DIV_MASK , +RK3568_PHYREG6_PLL_DIV_2 <<RK3568_PHYREG6_PLL_DIV_SHIFT , +RK3568_PHYREG6 ); -writel (PHYREG18_PLL_LOOP , priv->mmio +PHYREG18 ); -writel (PHYREG11_SU_TRIM_0_7 , priv->mmio +PHYREG11 ); +writel (RK3568_PHYREG18_PLL_LOOP , priv->mmio +RK3568_PHYREG18 ); +writel (RK3568_PHYREG11_SU_TRIM_0_7 , priv->mmio +RK3568_PHYREG11 );rockchip_combphy_param_write (priv->phy_grf, &cfg->pipe_txcomp_sel, false);rockchip_combphy_param_write (priv->phy_grf, &cfg->pipe_txelec_sel, false);
@@ -653,16 +654,16 @@ static int rk3588_combphy_cfg(struct rockchip_combphy_priv *priv)break ;case PHY_TYPE_SATA :/* Enable adaptive CTLE for SATA Rx. */ - val =readl (priv->mmio +PHYREG15 ); - val |=PHYREG15_CTLE_EN ; -writel (val, priv->mmio +PHYREG15 ); + val =readl (priv->mmio +RK3568_PHYREG15 ); + val |=RK3568_PHYREG15_CTLE_EN ; +writel (val, priv->mmio +RK3568_PHYREG15 );/* * Set tx_rterm=50ohm and rx_rterm=44ohm for SATA. * 0: 60ohm, 8: 50ohm 15: 44ohm (by step abort 1ohm) */ - val =PHYREG7_TX_RTERM_50OHM <<PHYREG7_TX_RTERM_SHIFT ; - val |=PHYREG7_RX_RTERM_44OHM <<PHYREG7_RX_RTERM_SHIFT ; -writel (val, priv->mmio +PHYREG7 ); + val =RK3568_PHYREG7_TX_RTERM_50OHM <<RK3568_PHYREG7_TX_RTERM_SHIFT ; + val |=RK3568_PHYREG7_RX_RTERM_44OHM <<RK3568_PHYREG7_RX_RTERM_SHIFT ; +writel (val, priv->mmio +RK3568_PHYREG7 );rockchip_combphy_param_write (priv->phy_grf, &cfg->con0_for_sata, true);rockchip_combphy_param_write (priv->phy_grf, &cfg->con1_for_sata, true);
@@ -684,11 +685,11 @@ static int rk3588_combphy_cfg(struct rockchip_combphy_priv *priv)case REF_CLOCK_24MHz:if (priv->type ==PHY_TYPE_USB3 || priv->type ==PHY_TYPE_SATA ) {/* Set ssc_cnt[9:0]=0101111101 & 31.5KHz. */ - val =PHYREG15_SSC_CNT_VALUE <<PHYREG15_SSC_CNT_SHIFT ; -rockchip_combphy_updatel (priv,PHYREG15_SSC_CNT_MASK , - val,PHYREG15 ); + val =RK3568_PHYREG15_SSC_CNT_VALUE <<RK3568_PHYREG15_SSC_CNT_SHIFT ; +rockchip_combphy_updatel (priv,RK3568_PHYREG15_SSC_CNT_MASK , + val,RK3568_PHYREG15 ); -writel (PHYREG16_SSC_CNT_VALUE , priv->mmio +PHYREG16 ); +writel (RK3568_PHYREG16_SSC_CNT_VALUE , priv->mmio +RK3568_PHYREG16 ); }break ;
@@ -699,23 +700,23 @@ static int rk3588_combphy_cfg(struct rockchip_combphy_priv *priv)rockchip_combphy_param_write (priv->phy_grf, &cfg->pipe_clk_100m, true);if (priv->type ==PHY_TYPE_PCIE ) {/* PLL KVCO fine tuning. */ - val =4 <<PHYREG33_PLL_KVCO_SHIFT ; -rockchip_combphy_updatel (priv,PHYREG33_PLL_KVCO_MASK , - val,PHYREG33 ); + val =4 <<RK3568_PHYREG33_PLL_KVCO_SHIFT ; +rockchip_combphy_updatel (priv,RK3568_PHYREG33_PLL_KVCO_MASK , + val,RK3568_PHYREG33 );/* Enable controlling random jitter. */ -writel (PHYREG12_PLL_LPF_ADJ_VALUE , priv->mmio +PHYREG12 ); +writel (RK3568_PHYREG12_PLL_LPF_ADJ_VALUE , priv->mmio +RK3568_PHYREG12 );/* Set up rx_trim: PLL LPF C1 85pf R1 1.25kohm */ -writel (PHYREG27_RX_TRIM_RK3588 , priv->mmio +PHYREG27 ); +writel (RK3588_PHYREG27_RX_TRIM , priv->mmio +RK3588_PHYREG27 );/* Set up su_trim: */ -writel (PHYREG11_SU_TRIM_0_7 , priv->mmio +PHYREG11 ); +writel (RK3568_PHYREG11_SU_TRIM_0_7 , priv->mmio +RK3568_PHYREG11 ); }else if (priv->type ==PHY_TYPE_SATA ) {/* downward spread spectrum +500ppm */ - val =PHYREG32_SSC_DOWNWARD <<PHYREG32_SSC_DIR_SHIFT ; - val |=PHYREG32_SSC_OFFSET_500PPM <<PHYREG32_SSC_OFFSET_SHIFT ; -rockchip_combphy_updatel (priv,PHYREG32_SSC_MASK , val,PHYREG32 ); + val =RK3568_PHYREG32_SSC_DOWNWARD <<RK3568_PHYREG32_SSC_DIR_SHIFT ; + val |=RK3568_PHYREG32_SSC_OFFSET_500PPM <<RK3568_PHYREG32_SSC_OFFSET_SHIFT ; +rockchip_combphy_updatel (priv,RK3568_PHYREG32_SSC_MASK , val,RK3568_PHYREG32 ); }break ;default :
@@ -726,20 +727,20 @@ static int rk3588_combphy_cfg(struct rockchip_combphy_priv *priv)if (priv->ext_refclk) {rockchip_combphy_param_write (priv->phy_grf, &cfg->pipe_clk_ext, true);if (priv->type ==PHY_TYPE_PCIE && rate == REF_CLOCK_100MHz) { - val =PHYREG13_RESISTER_HIGH_Z <<PHYREG13_RESISTER_SHIFT ; - val |=PHYREG13_CKRCV_AMP0 ; -rockchip_combphy_updatel (priv,PHYREG13_RESISTER_MASK , val,PHYREG13 ); + val =RK3568_PHYREG13_RESISTER_HIGH_Z <<RK3568_PHYREG13_RESISTER_SHIFT ; + val |=RK3568_PHYREG13_CKRCV_AMP0 ; +rockchip_combphy_updatel (priv,RK3568_PHYREG13_RESISTER_MASK , val,RK3568_PHYREG13 ); - val =readl (priv->mmio +PHYREG14 ); - val |=PHYREG14_CKRCV_AMP1 ; -writel (val, priv->mmio +PHYREG14 ); + val =readl (priv->mmio +RK3568_PHYREG14 ); + val |=RK3568_PHYREG14_CKRCV_AMP1 ; +writel (val, priv->mmio +RK3568_PHYREG14 ); } }if (priv->enable_ssc) { - val =readl (priv->mmio +PHYREG8 ); - val |=PHYREG8_SSC_EN ; -writel (val, priv->mmio +PHYREG8 ); + val =readl (priv->mmio +RK3568_PHYREG8 ); + val |=RK3568_PHYREG8_SSC_EN ; +writel (val, priv->mmio +RK3568_PHYREG8 ); }return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 455/816 phy: rockchip: naneng-combphy: Fix TX detect RX termination errata
In reply to Greg Kroah-Hartman6.12-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.
--- .../phy/rockchip/phy-rockchip-naneng-combphy.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/phy/rockchip/phy-rockchip-naneng-combphy.c +17 -0
@@ -64,6 +64,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_PHYREG32 0x7C#define RK3568_PHYREG32_SSC_MASK GENMASK(7, 4)#define RK3568_PHYREG32_SSC_DIR_SHIFT 4
@@ -131,6 +134,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); };
@@ -202,6 +206,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 :
@@ -598,6 +613,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 rk3588_combphy_cfg (struct rockchip_combphy_priv *priv)
@@ -784,6 +800,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 456/816 iommu/arm-smmu-v3: Dont rb_erase() a never-inserted stream node
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicolin Chen <[email protected]>
[ Upstream commit 2888520bdcbe0599cfc77b2fad8dc6c95505a3cb ]
arm_smmu_insert_master() skips inserting a stream whose StreamID duplicates one the same master already owns (bridged PCI devices can present duplicate IDs), leaving that master->streams[i].node zeroed and unlinked from the smmu->streams rb-tree.
Both the insert error-rollback loop and arm_smmu_remove_master() then call rb_erase() on every master->streams[i].node unconditionally. rb_erase() on a zeroed node sees a NULL parent, treats the node as the tree root and sets root->rb_node = NULL, silently emptying the whole SID tree and breaking SID lookups (and DMA) for every other master on the SMMU.
Mark each node with RB_CLEAR_NODE() after sort_nonatomic() reorders the array, since sorting relocates the entries and would leave the earlier self-referential RB_CLEAR_NODE() pointer stale. An un-inserted node then stays RB_EMPTY_NODE() and is skipped in both erase loops; inserted nodes are linked by rb_find_add() and erased as before.
--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +8 -2
@@ -3242,6 +3242,9 @@ static int arm_smmu_insert_master(struct arm_smmu_device *smmu,return -ENOMEM ; master->num_streams = fwspec->num_ids; +for (i =0 ; i < fwspec->num_ids; i++) +RB_CLEAR_NODE (&master->streams[i].node); +mutex_lock (&smmu->streams_mutex);for (i =0 ; i < fwspec->num_ids; i++) {struct arm_smmu_stream *new_stream = &master->streams[i];
@@ -3277,7 +3280,9 @@ static int arm_smmu_insert_master(struct arm_smmu_device *smmu,if (ret) {for (i--; i >=0 ; i--) -rb_erase (&master->streams[i].node, &smmu->streams); +if (!RB_EMPTY_NODE (&master->streams[i].node)) +rb_erase (&master->streams[i].node, + &smmu->streams);kfree (master->streams); }mutex_unlock (&smmu->streams_mutex);
@@ -3296,7 +3301,8 @@ static void arm_smmu_remove_master(struct arm_smmu_master *master)mutex_lock (&smmu->streams_mutex);for (i =0 ; i < fwspec->num_ids; i++) -rb_erase (&master->streams[i].node, &smmu->streams); +if (!RB_EMPTY_NODE (&master->streams[i].node)) +rb_erase (&master->streams[i].node, &smmu->streams);mutex_unlock (&smmu->streams_mutex);kfree (master->streams);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 457/816 ASoC: aw88399: skip BSTS check when boost converter is bypassed
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marco Giunta <[email protected]>
[ Upstream commit 664824782df63013ba8686b649c625cac4793248 ]
The sysst check in aw_dev_check_sysst() requires BSTS (boost finished) to assert, but on hardware where the boost converter is bypassed via external power supply (BSTCTRL10 register 0x69, EN_HVBAT bit 2 set), BSTS (SYSST register 0x01, bit 9) will never assert.
The vendor's generic driver (aw883xx) handles this by reading EN_HVBAT and conditionally masking out BSTS from the sysst check. The in-tree driver missed this logic when the original code was ported upstream.
Add the same conditional check, matching the vendor driver's aw_dev_sysst_check() implementation.
--- sound/soc/codecs/aw88399.c | 13 +++++++++++++ sound/soc/codecs/aw88399.h | 5 +++++ 2 files changed, 18 insertions(+)
sound/soc/codecs/aw88399.c +13 -0
@@ -285,6 +285,19 @@ static int aw_dev_check_sysst(struct aw_device *aw_dev)else check_val =AW88399_BIT_SYSST_SWS_CHECK ; +/* +* When an external power supply (EPS) is used to feed the amplifier +* (EN_HVBAT bit in BSTCTRL10 set), the boost converter is bypassed, +* and BSTS (boost finished) will never assert. Skip the BSTS check in +* this case, matching the vendor driver's behavior. +*/ + ret =regmap_read (aw_dev->regmap,AW88399_BSTCTRL10_REG , ®_val); +if (ret) +return ret; + +if (reg_val & (~AW88399_EPS_EN_MASK )) + check_val &= ~AW88399_BSTS_FINISHED_VALUE ; +for (i =0 ; i <AW88399_DEV_SYSST_CHECK_MAX ; i++) { ret =regmap_read (aw_dev->regmap,AW88399_SYSST_REG , ®_val);if (ret)
sound/soc/codecs/aw88399.h +5 -0
@@ -446,6 +446,11 @@#define AW88399_NOISE_GATE_EN_MASK \ (~(((1<<AW88399_NOISE_GATE_EN_BITS_LEN)-1) << AW88399_NOISE_GATE_EN_START_BIT)) +#define AW88399_EPS_EN_START_BIT (2) +#define AW88399_EPS_EN_BITS_LEN (1) +#define AW88399_EPS_EN_MASK \ + (~(((1 << AW88399_EPS_EN_BITS_LEN) - 1) << AW88399_EPS_EN_START_BIT)) +#define AW88399_WDT_CNT_START_BIT (0)#define AW88399_WDT_CNT_BITS_LEN (8)#define AW88399_WDT_CNT_MASK \
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 458/816 drm/msm/a5xx: dont read the GPMU registers on GPUs without a GPMU
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Baryshkov <[email protected]>
[ Upstream commit 77e3ffcf69065c4ce92c725540e0b4db14f43ad7 ]
Only a530/a540 have a GPMU. On the other a5xx parts, reading the 0xa800-0xac60 GPMU aperture during a crashdump resets the board -- on sda660 (a512) a GPU hang thus reboots the SoC instead of recovering.
Split the GPMU block into its own array and collect it only when a GPMU is present.
Patchwork: https://patchwork.freedesktop.org/patch/754867/
Message-ID: <[email protected]>
--- drivers/gpu/drm/msm/adreno/a5xx_gpu.c | 49 +++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-)
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +46 -3
@@ -1336,9 +1336,14 @@ static const u32 a5xx_registers[] = {0xE800 ,0xE806 ,0xE810 ,0xE89A ,0xE8A0 ,0xE8A4 ,0xE8AA ,0xE8EB ,0xE900 ,0xE905 ,0xEB80 ,0xEB8F ,0xEBB0 ,0xEBB0 ,0xEC00 ,0xEC05 ,0xEC08 ,0xECE9 ,0xECF0 ,0xECF0 ,0xEA80 ,0xEA80 ,0xEA82 ,0xEAA3 , -0xEAA5 ,0xEAC2 ,0xA800 ,0xA800 ,0xA820 ,0xA828 ,0xA840 ,0xA87D , -0XA880 ,0xA88D ,0xA890 ,0xA8A3 ,0xA8D0 ,0xA8D8 ,0xA8E0 ,0xA8F5 , - 0xAC60, 0xAC60, ~0, + 0xEAA5, 0xEAC2, ~0, +}; + +/* GPMU registers, only valid on parts with a GPMU (a530/a540) */ +static const u32 a5xx_gpmu_registers[] = { +0xA800 ,0xA800 ,0xA820 ,0xA828 ,0xA840 ,0xA87D ,0xA880 ,0xA88D , +0xA890 ,0xA8A3 ,0xA8D0 ,0xA8D8 ,0xA8E0 ,0xA8F5 ,0xAC60 ,0xAC60 , + ~0 , };static void a5xx_dump (struct msm_gpu *gpu)
@@ -1449,6 +1454,7 @@ struct a5xx_crashdumper {struct a5xx_gpu_state {struct msm_gpu_state base;u32 *hlsqregs; +u32 *gpmuregs; }; static int a5xx_crashdumper_init(struct msm_gpu *gpu,
@@ -1566,8 +1572,30 @@ static void a5xx_gpu_state_get_hlsq_regs(struct msm_gpu *gpu,msm_gem_kernel_put (dumper.bo, gpu->aspace); } +static void a5xx_gpu_state_get_gpmu_regs (struct msm_gpu *gpu, +struct a5xx_gpu_state *a5xx_state) +{ +u32 count =0 , pos =0 ; +int i; + +for (i =0 ; a5xx_gpmu_registers[i] != ~0 ; i +=2 ) + count += a5xx_gpmu_registers[i +1 ] - a5xx_gpmu_registers[i] +1 ; + + a5xx_state->gpmuregs =kcalloc (count,sizeof (u32),GFP_KERNEL ); +if (!a5xx_state->gpmuregs) +return ; + +for (i =0 ; a5xx_gpmu_registers[i] != ~0 ; i +=2 ) { +u32 addr; + +for (addr = a5xx_gpmu_registers[i]; addr <= a5xx_gpmu_registers[i +1 ]; addr++) + a5xx_state->gpmuregs[pos++] =gpu_read (gpu, addr); + } +} +static struct msm_gpu_state *a5xx_gpu_state_get (struct msm_gpu *gpu) { +struct adreno_gpu *adreno_gpu =to_adreno_gpu (gpu);struct a5xx_gpu_state *a5xx_state =kzalloc (sizeof (*a5xx_state),GFP_KERNEL );bool stalled = !!(gpu_read (gpu,REG_A5XX_RBBM_STATUS3 ) &BIT (24 ));
@@ -1583,6 +1611,9 @@ static struct msm_gpu_state *a5xx_gpu_state_get(struct msm_gpu *gpu) a5xx_state->base.rbbm_status =gpu_read (gpu,REG_A5XX_RBBM_STATUS ); +if (adreno_is_a530 (adreno_gpu) ||adreno_is_a540 (adreno_gpu)) +a5xx_gpu_state_get_gpmu_regs (gpu, a5xx_state); +/* * Get the HLSQ regs with the help of the crashdumper, but only if * we are not stalled in an iommu fault (in which case the crashdumper
@@ -1604,6 +1635,7 @@ static void a5xx_gpu_state_destroy(struct kref *kref) struct a5xx_gpu_state, base);kfree (a5xx_state->hlsqregs); +kfree (a5xx_state->gpmuregs);adreno_gpu_state_destroy (state);kfree (a5xx_state);
@@ -1632,6 +1664,17 @@ static void a5xx_show(struct msm_gpu *gpu, struct msm_gpu_state *state,adreno_show (gpu, state, p); +if (a5xx_state->gpmuregs) { +u32 o, pos =0 ; + +drm_printf (p,"registers-gpmu:\n" ); + +for (i =0 ; a5xx_gpmu_registers[i] != ~0 ; i +=2 ) +for (o = a5xx_gpmu_registers[i]; o <= a5xx_gpmu_registers[i +1 ]; o++) +drm_printf (p," - { offset: 0x%04x, value: 0x%08x }\n" , + o <<2 , a5xx_state->gpmuregs[pos++]); + } +/* Dump the additional a5xx HLSQ registers */ if (!a5xx_state->hlsqregs)return ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 459/816 dlm: validate node weights before building member array
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qing Ming <[email protected]>
[ Upstream commit 7f662eb1807ed732ac7d5e119753c8185f241bb8 ]
DLM node weights are parsed as signed integers and copied into the member list. make_member_array() uses their sum as the allocation count, but only positive weights contribute entries to the array. A negative weight can therefore reduce the allocation without reducing the number of writes.
The issue was found through static analysis of the configfs input and member array construction. With two recovery members weighted -31 and 32, the sum is 1, so recovery allocates one int and then writes the positive member's node ID 32 times. A reproducer using dlm_controld and dlm_tool triggered the same report on a KASAN kernel:
BUG: KASAN: slab-out-of-bounds in dlm_recover_members [dlm] Write of size 4 by task dlm_recoverd Call Trace: dlm_recover_members dlm_recoverd kthread ret_from_fork
Reject negative weights at the configfs input boundary. Also detect overflow when adding non-negative weights to the signed allocation count, and propagate array construction errors to the recovery path.
--- fs/dlm/config.c | 9 ++++++++- fs/dlm/member.c | 17 +++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-)
fs/dlm/config.c +8 -1
@@ -823,10 +823,17 @@ static ssize_t node_weight_show(struct config_item *item, char *buf)static ssize_t node_weight_store (struct config_item *item,const char *buf,size_t len) { -int rc =kstrtoint (buf,0 , &config_item_to_node (item)->weight); +struct dlm_node *node =config_item_to_node (item); +int weight; +int rc; + rc =kstrtoint (buf,0 , &weight);if (rc)return rc; +if (weight <0 ) +return -EINVAL ; + + node->weight = weight;return len; }
fs/dlm/member.c +11 -6
@@ -406,7 +406,7 @@ void dlm_clear_members_gone(struct dlm_ls *ls)clear_memb_list (&ls->ls_nodes_gone,NULL ); } -static void make_member_array (struct dlm_ls *ls) +static int make_member_array (struct dlm_ls *ls) {struct dlm_member *memb;int i, w, x =0 , total =0 , all_zero =0 , *array;
@@ -415,8 +415,8 @@ static void make_member_array(struct dlm_ls *ls) ls->ls_node_array =NULL ;list_for_each_entry (memb, &ls->ls_nodes, list) { -if (memb->weight) - total += memb->weight; +if (check_add_overflow (total, memb->weight, &total)) +return -EOVERFLOW ; }/* all nodes revert to weight of 1 if all have weight 0 */
@@ -426,10 +426,9 @@ static void make_member_array(struct dlm_ls *ls) all_zero =1 ; } - ls->ls_total_weight = total; array =kmalloc_array (total,sizeof (*array),GFP_NOFS );if (!array) -return ; +return -ENOMEM ;list_for_each_entry (memb, &ls->ls_nodes, list) {if (!all_zero && !memb->weight)
@@ -446,7 +445,10 @@ static void make_member_array(struct dlm_ls *ls) array[x++] = memb->nodeid; } + ls->ls_total_weight = total; ls->ls_node_array = array; + +return 0 ; }/* send a status request to all members just to establish comms connections */
@@ -606,7 +608,10 @@ int dlm_recover_members(struct dlm_ls *ls, struct dlm_recover *rv, int *neg_out) } ls->ls_low_nodeid = low; -make_member_array (ls); + error =make_member_array (ls); +if (error) +return error; + *neg_out = neg; error =ping_members (ls, rv->seq);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 460/816 drm/msm/a6xx: check pm_runtime_resume_and_get during resume
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Roman Demidov <[email protected]>
[ Upstream commit e2f57c576f14f96449cfee840860cb9707501d23 ]
The return values of pm_runtime_resume_and_get() calls in a6xx_pm_resume() are not checked, which can lead to hardware access on suspended devices and PM reference underflows.
Fix this by checking the return value of each pm_runtime_resume_and_get() call and properly unwinding the previously acquired resources on failure.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Patchwork: https://patchwork.freedesktop.org/patch/757106/
Message-ID: <[email protected]>
--- drivers/gpu/drm/msm/adreno/a6xx_gpu.c | 33 +++++++++++++++------------ 1 file changed, 19 insertions(+), 14 deletions(-)
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +19 -14
@@ -1877,36 +1877,41 @@ static int a6xx_pm_resume(struct msm_gpu *gpu) opp =dev_pm_opp_find_freq_ceil (&gpu->pdev->dev, &freq);if (IS_ERR (opp)) { ret =PTR_ERR (opp); - goto err_set_opp; + goto err_unlock; }/* Set the core clock and bus bw, having VDD scaling in mind */ dev_pm_opp_set_opp (&gpu->pdev->dev, opp);dev_pm_opp_put (opp); -pm_runtime_resume_and_get (gmu->dev); -pm_runtime_resume_and_get (gmu->gxpd); + ret =pm_runtime_resume_and_get (gmu->dev); +if (ret <0 ) + goto err_opp_clear; + ret =pm_runtime_resume_and_get (gmu->gxpd); +if (ret <0 ) + goto err_put_dev; ret =clk_bulk_prepare_enable (gpu->nr_clocks, gpu->grp_clks);if (ret) - goto err_bulk_clk; + goto err_put_gxpd;if (adreno_is_a619_holi (adreno_gpu))a6xx_sptprac_enable (gmu); -/* If anything goes south, tear the GPU down piece by piece.. */ -if (ret) { -err_bulk_clk: -pm_runtime_put (gmu->gxpd); -pm_runtime_put (gmu->dev); -dev_pm_opp_set_opp (&gpu->pdev->dev,NULL ); - } -err_set_opp:mutex_unlock (&a6xx_gpu->gmu.lock); +msm_devfreq_resume (gpu); -if (!ret) -msm_devfreq_resume (gpu); +return 0 ; +/* If anything goes south, tear the GPU down piece by piece.. */ +err_put_gxpd: +pm_runtime_put (gmu->gxpd); +err_put_dev: +pm_runtime_put (gmu->dev); +err_opp_clear: +dev_pm_opp_set_opp (&gpu->pdev->dev,NULL ); +err_unlock: +mutex_unlock (&a6xx_gpu->gmu.lock);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 461/816 dmaengine: ste_dma40: Fix cyclic transfer residue
In reply to Greg Kroah-Hartman6.12-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Walleij <[email protected]>
[ Upstream commit c80edceff29ee212987c2d2c851b2cb2eb4b477a ]
DMA40 reads residue from the element count of the currently active LLI. For a cyclic transfer this reports at most one period, not the bytes remaining until the cyclic buffer wraps.
Once DMA40 advertises burst granularity, DMAengine PCM uses this residue directly. For a four-period PCM buffer it consequently reports the hardware pointer near three periods after every period interrupt. ALSA eventually stops playback with -EIO although DMA period callbacks continue.
Calculate cyclic residue from the current memory-side hardware pointer instead. Read the destination pointer for capture and the source pointer for playback. Sample the split logical channel pointer coherently and retain the last valid residue during relink transitions.
Make at most three residue sampling attempts: one initial read plus two retries. The retries let transient split-register updates or LLI relink windows settle, while the limit prevents unbounded polling if hardware does not yield a valid pointer.
This avoids counting terminal-count interrupts, which races with hardware advancing to the next LLI and cannot account for coalesced interrupt status. Also reject cyclic periods that expand into multiple LLIs because logical cyclic LLIs each request a terminal-count interrupt and would generate more than one callback per period.
Reject invalid cyclic geometries before dividing or constructing the scatterlist as well.
--- drivers/dma/ste_dma40.c | 106 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 101 insertions(+), 5 deletions(-)
drivers/dma/ste_dma40.c +101 -5
@@ -69,6 +69,9 @@ struct stedma40_platform_data {/* Maximum iterations taken before giving up suspending a channel */ #define D40_SUSPEND_MAX_IT 500 +/* Maximum attempts to sample a stable cyclic residue position */ +#define D40_RESIDUE_MAX_ATTEMPTS 3 +/* Milliseconds */ #define DMA40_AUTOSUSPEND_DELAY 100
@@ -368,6 +371,9 @@ struct d40_lli_pool {* @lli_len: Number of llis of current descriptor. * @lli_current: Number of transferred llis. * @lcla_alloc: Number of LCLA entries allocated. +* @cyclic_dma_addr: Start address of the cyclic buffer. +* @cyclic_buf_len: Length of the cyclic buffer. +* @cyclic_residue: Last valid cyclic residue sample. * @txd: DMA engine struct. Used for among other things for communication * during a transfer. * @node: List entry.
@@ -386,6 +392,9 @@ struct d40_desc {int lli_len;int lli_current;int lcla_alloc; +dma_addr_t cyclic_dma_addr; +size_t cyclic_buf_len; +size_t cyclic_residue;struct dma_async_tx_descriptor txd;struct list_head node;
@@ -1412,6 +1421,64 @@ static u32 d40_residue(struct d40_chan *d40c)return num_elt * d40c->dma_cfg.dst_info.data_width; } +static bool d40_current_addr (struct d40_chan *d40c,dma_addr_t *addr) +{ +bool dst = d40c->dma_cfg.dir ==DMA_DEV_TO_MEM ; +void __iomem *high_reg; +void __iomem *low_reg; +u32 low; +u32 high; +u32 check; +int i; + +if (chan_is_physical (d40c)) { + *addr =readl (chan_base (d40c) + + (dst ?D40_CHAN_REG_SDPTR :D40_CHAN_REG_SSPTR )); +return true; + } + +if (dst) { + low_reg = &d40c->lcpa->lcsp2; + high_reg = &d40c->lcpa->lcsp3; + }else { + low_reg = &d40c->lcpa->lcsp0; + high_reg = &d40c->lcpa->lcsp1; + } + +for (i =0 ; i <D40_RESIDUE_MAX_ATTEMPTS ; i++) { + high =readl (high_reg) &D40_MEM_LCSP1_SPTR_MASK ; + low =readl (low_reg) &D40_MEM_LCSP0_SPTR_MASK ; + check =readl (high_reg) &D40_MEM_LCSP1_SPTR_MASK ; +if (high == check) { + *addr = low | high; +return true; + } + } + +return false; +} + +static bool d40_cyclic_offset (struct d40_chan *d40c,struct d40_desc *d40d, +size_t *offset) +{ +dma_addr_t current_addr; +dma_addr_t current_offset; +int i; + +for (i =0 ; i <D40_RESIDUE_MAX_ATTEMPTS ; i++) { +if (!d40_current_addr (d40c, ¤t_addr)) +continue ; + + current_offset = current_addr - d40d->cyclic_dma_addr; +if (current_offset <= d40d->cyclic_buf_len) { + *offset = current_offset; +return true; + } + } + +return false; +} +static bool d40_tx_is_linked (struct d40_chan *d40c) {bool is_link;
@@ -2202,15 +2269,26 @@ static bool d40_is_paused(struct d40_chan *d40c) } -static u32 stedma40_residue (struct dma_chan *chan) +static u32 stedma40_residue (struct dma_chan *chan,dma_cookie_t cookie) {struct d40_chan *d40c = container_of(chan, struct d40_chan, chan); +struct d40_desc *d40d; +size_t offset;u32 bytes_left;unsigned long flags;spin_lock_irqsave (&d40c->lock, flags); - bytes_left =d40_residue (d40c); + d40d =d40_first_active_get (d40c); +if (d40d && d40d->txd.cookie == cookie && d40d->cyclic && + d40d->cyclic_buf_len) { +if (d40_cyclic_offset (d40c, d40d, &offset)) + d40d->cyclic_residue = d40d->cyclic_buf_len - offset; + bytes_left = d40d->cyclic_residue; + }else { + bytes_left =d40_residue (d40c); + } +spin_unlock_irqrestore (&d40c->lock, flags);return bytes_left;
@@ -2346,8 +2424,13 @@ d40_prep_sg(struct dma_chan *dchan, struct scatterlist *sg_src,if (desc ==NULL ) goto unlock; -if (sg_next (&sg_src[sg_len -1 ]) == sg_src) +if (sg_next (&sg_src[sg_len -1 ]) == sg_src) { desc->cyclic = true; +if (desc->lli_len != sg_len) { +chan_err (chan,"Cyclic periods must fit in one LLI\n" ); + goto free_desc; + } + } src_dev_addr =0 ; dst_dev_addr =0 ;
@@ -2630,11 +2713,18 @@ dma40_prep_dma_cyclic(struct dma_chan *chan, dma_addr_t dma_addr, size_t buf_len, size_t period_len, enum dma_transfer_direction direction, unsigned long flags) { - unsigned int periods = buf_len / period_len; + unsigned int periods;struct dma_async_tx_descriptor *txd; +struct d40_desc *desc;struct scatterlist *sg; +dma_addr_t buf_addr = dma_addr;int i; +if (!buf_len || !period_len || buf_len % period_len) +return NULL ; + + periods = buf_len / period_len; + sg =kcalloc (periods +1 ,sizeof (struct scatterlist ),GFP_NOWAIT );if (!sg)return NULL ;
@@ -2649,6 +2739,12 @@ dma40_prep_dma_cyclic(struct dma_chan *chan, dma_addr_t dma_addr, txd =d40_prep_sg (chan, sg, sg, periods, direction,DMA_PREP_INTERRUPT ); +if (txd) { + desc = container_of(txd, struct d40_desc, txd); + desc->cyclic_dma_addr = buf_addr; + desc->cyclic_buf_len = buf_len; + desc->cyclic_residue = buf_len; + }kfree (sg);
@@ -2669,7 +2765,7 @@ static enum dma_status d40_tx_status(struct dma_chan *chan, ret =dma_cookie_status (chan, cookie, txstate);if (ret !=DMA_COMPLETE && txstate) -dma_set_residue (txstate,stedma40_residue (chan)); +dma_set_residue (txstate,stedma40_residue (chan, cookie));if (d40_is_paused (d40c)) ret =DMA_PAUSED ;
Signature · 1 line
2.53.0