Repository navigation
drivers/note: noteram, noterpmsg and note driver fixes - #22250
Merged
xiaoxiang781216 merged 17 commits intoNov 25, 2026
Merged
Conversation
sched_note_event_ip() caps the note at sizeof(data) - 1 bytes and then passes length - SIZEOF_NOTE_EVENT(0) to memcpy(). Static analysis reports that argument as a possible integer overflow, because nothing ties the size of the stack buffer to the size of the note header. Name the buffer size BUFFER_SIZE, use it for the buffers of sched_note_event_ip() and sched_note_vprintf_ip(), and check at build time that it is at least sizeof(struct note_event_s). Assisted-by: Kiro:claude-opus-5-5 Signed-off-by: guanyi <guanyi@xiaomi.com>
In binary mode noteram_read() returned one note per call, whatever the size of the caller's buffer, so reading out the buffer took one read() per note. Copy as many whole notes as fit into the buffer, taking the lock only once, and return the number of bytes copied. Assisted-by: Kiro:claude-opus-5-5 Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
nxstyle wants a blank line after the declaration of nread. No functional change. Assisted-by: Kiro:claude-opus-5-5 Signed-off-by: huojianchao <huojianchao@xiaomi.com>
The size of the structure is padded by default, but the data in noteram is not padded Mixing sizeof and nc_length in the code will cause errors during binary parsing Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
If there is not enough space left when reading data, data will be lost. Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
notestream_driver.c is missing from CMakeLists.txt. Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
Need to specifiy the section noteram resides in. This is done in Makefile but not cmake. Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
All the rpmsg services should depend on RPMSG instead of RPTUN after the rpmsg framework was refactored, as most of them already do. Assisted-by: Kiro:claude-opus-5-5 Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
Solve the problem of address misalignment exception triggered when sched_note_add parses note data. Assisted-by: Kiro:claude-opus-5-5 Signed-off-by: yukangzhi <yukangzhi@xiaomi.com>
noterpmsg buffer will be overflow when send rpmsg fail, So need release noterpmsg buffer before overwrite. Signed-off-by: zhangyuan29 <zhangyuan29@xiaomi.com>
noterpmsg_transfer() runs with drv->lock held and interrupts disabled. Until the remote side binds the endpoint, rpmsg_send_nocopy() polls is_rpmsg_ept_ready() and sleeps between the polls (openamp patch 0004), which must not happen there. Check the endpoint first and return false while it is not ready: noterpmsg_work() retries after NOTE_RPMSG_WORK_DELAY and noterpmsg_add() makes room by overwriting the oldest notes. Assisted-by: Kiro:claude-opus-5-5 Signed-off-by: zhangyuan29 <zhangyuan29@xiaomi.com>
noterpmsg_add() called noterpmsg_transfer(drv, true) with drv->lock held and interrupts disabled, and noterpmsg_work() held the lock around the whole transfer. With wait set, rpmsg_get_tx_payload_buffer() sleeps until the remote side returns a buffer, so the task could switch out inside the critical section. Take drv->lock in noterpmsg_transfer() only after getting the tx buffer, drop it in noterpmsg_add() around the transfer, and queue the work after the unlock. Assisted-by: Kiro:claude-opus-5-5 Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
g_noterpmsg_driver has initializers, so the CONFIG_DRIVERS_NOTERPMSG_BUFSIZE bytes of buffer embedded in it go to .data and take the same space in the flash image. Move the buffer to a static array of its own, which goes to .bss, and point the driver at it. Assisted-by: Kiro:claude-opus-5-5 Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
buffer is converted to pointer to struct note_common_note *, thus needs to be aligned. Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
The spinlock callback of notelog is the only notelog callback without the notelog_ prefix, and it has the name of the note_spinlock() macro of note_driver.c. Rename it to notelog_spinlock to match the other notelog_* callbacks. No functional change. Assisted-by: Kiro:claude-opus-5-5 Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
noterpmsg_transfer() fills an rpmsg payload with as many whole notes as fit. It tested the unaligned nc_length against the space left while accumulating the padded stride, so len could end up to seven bytes past the payload it was measured against, and both the memcpy and the rpmsg_send_nocopy() that follow run on that oversized len. space=36 with a 33-byte note is enough: the test passes at 33 and len becomes 40. Simulating the ring over random note lengths and payload capacities trips an assertion on len <= space within a few thousand records. Test the padded stride instead, which is what len accumulates. Assisted-by: Kiro Signed-off-by: huojianchao <huojianchao@xiaomi.com>
0184bd1 ported this change to sched_note_add() at a time when the notes on the rpmsg wire were not padded, so it compares nc_length with what is left of the packet. Since "drivers/note: Fix data address alignment trap cause by sched_note_add." the walk steps by NOTE_ALIGN(notelen), and a last note that comes without its padding passes that test, then wraps len around. Compare the padded length, as the original change does. Assisted-by: Kiro:claude-opus-5-5 Signed-off-by: huojianchao <huojianchao@xiaomi.com>
huojianchaoyy
requested review from
anchao,
jerpelea and
xiaoxiang781216
as code owners
November 24, 2026 08:58
huojianchaoyy
force-pushed
the
nx-tr-note-driver-fixes-v2
branch
from
November 24, 2026 09:11
6b12dec to
aa60b67
Compare
jerpelea
approved these changes
Nov 24, 2026
xiaoxiang781216
approved these changes
Nov 24, 2026
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note: Please adhere to Contributing Guidelines.
Summary
Note driver fixes from Xiaomi Vela: noteram, the rpmsg note client (noterpmsg) and server, and the note core.
noteram:
read()returns as many whole notes as fit in the buffer instead of one note per call. note: avoid data loss when reading binary data then keeps a note that does not fit for the nextread()instead of dropping it.struct note_common_s.CONFIG_DRIVERS_NOTERAM_SECTIONasMake.defsdoes.noterpmsg and the rpmsg note server:
NOTE_ALIGN()offsets andsched_note_add()steps over them byNOTE_ALIGN(), so the server reads every note from an aligned address. The patch keeps theuintptr_tpointer arithmetic of master insched_note_add().rpmsg_send_nocopy()would poll and sleep for it withdrv->lockheld.drv->lockand with interrupts enabled.g_noterpmsg_driver(.data).note core and build:
BUFFER_SIZEand astatic_assertfor the stack buffers ofsched_note_event_ip()andsched_note_vprintf_ip().note_add()gets thenc_lengthof the note.notestream_driver.cforDRIVERS_NOTEFILE/DRIVERS_NOTELOWEROUT; master fails to link with CMake andCONFIG_DRIVERS_NOTEFILE=y(see Testing).sched_note_add()while the notes on the wire were not padded, so it compares the unpaddednc_lengthwith what is left. With the padded stride a last note without its padding passed that test and wrappedlenaround; the check now uses the padded length, as the original change does.One follow-up commit: drivers/note: add the missing blank line in noteram_read() (nxstyle), right after the noteram read change.
Impact
NOTE_ALIGN(): noterpmsg and the note server both need this PR, a client and a server built from trees on different sides of it do not understand each other.read(): several notes per call, still back to back (system/trace writes them out as they come,tools/parsetrace.pywalks them bync_length). Aread()whose buffer cannot hold the next note returns 0 instead of-EFBIG, and the note stays in the buffer.DRIVERS_NOTERPMSGandDRIVERS_NOTERPMSG_SERVERdepend onRPMSGinstead ofRPTUN.RPTUNselectsRPMSGthroughRPMSG_VIRTIO, so existing configurations keep them.Testing
Host: Ubuntu 22.04 x86_64, GCC 13.4.0 (sim), Arm GNU Toolchain 13.2.rel1, aarch64-none-elf GCC 13.4.0, CMake 3.23 + Ninja 1.10, QEMU 10.2.1. Base: master 91dd24b. The tests below ran on the same patches on master c890786 (
git range-diffshows no change; the 9 commits in between touch arch/arm, i2c and virtio), and the head builds were repeated on 91dd24b (sim:noteSMP,sim:rpproxy,sim:rpserver,qemu-armv7a:nsh,mps3-an547:nsh)../tools/checkpatch.sh -c -u -m -g HEAD~17..HEADpasses.Every commit builds (CMake, incremental) with no new warning:
sim:note;sim:notewithoutDRIVERS_NOTERAM_TEXT_DUMP;sim:notewithSMP,DRIVERS_NOTEFILEandDRIVERS_NOTERAM_SECTION=".bss.noteram": master and the commits before "cmake: fix note cmake compile error" fail withundefined reference to 'notefile_register', the later ones build, andg_ramnote_bufferis in.bss.noteraminnoteram_driver.c.o;sim:rpproxywithDRIVERS_NOTERPMSG,sim:rpserverwithDRIVERS_NOTERPMSG_SERVERandDRIVERS_NOTERAM.The head also builds for
qemu-armv7a:nsh(noteram, switch and dump notes, filter),qemu-armv8a:nsh_smp(noteram, notelog, spinlock notes), and with Make forsim:note(SMP, NOTEFILE, NOTERAM_SECTION) andsim:rpproxy(NOTERPMSG).sim:note,trace start; sleep 1; trace stop; trace dump -b /host/a.bin, then walking the file on the host bync_length:trace dump(text) prints the same kind of output on both (2882 lines).sim:rpserver+sim:rpproxy, with switch notes on the proxy and the local notes of the server filtered out (SCHED_INSTRUMENTATION_FILTER_DEFAULT_MODE=0):cat /dev/note/ramon the server shows the notes of the proxy (1820sched_switchlines andsched_wakeup_new: comm=netinit pid=9in one run, 3098sched_switchlines in another). On master the proxy crashed at boot in 5 runs out of 5 (SIGSEGV), with this PR in none of 5 runs; an earlier test of the branch saw one such crash in 5 runs, which is not investigated here.Not tested: real hardware,
DRIVERS_NOTELOWEROUTat run time (sim and qemu-armv7a have noup_lowputc()).