| 0/0 |
2026/08/19 01:51 |
flow |
assessment-security |
15m
Results: map[DenialOfService:true Explanation:**Bug Analysis & Trigger Mechanism**
The bug is a lockdep warning (`INFO: trying to register non-static key`)
occurring in `start_wakeup_event()` within the `virtio_balloon` driver. This
happens because `spin_lock_irqsave(&vb->wakeup_lock, flags)` is called before
the lock has been initialized via `spin_lock_init()`.
During the device probe (`virtballoon_probe`), the driver calls `init_vqs()` to
initialize the virtqueues. For the statistics virtqueue (`stats_vq`), it primes
the queue with a buffer and immediately kicks it (`virtqueue_kick()`), notifying
the device (hypervisor). However, `spin_lock_init(&vb->wakeup_lock)` is called
*after* `init_vqs()`. If the device responds extremely quickly (or is malicious
and sends an interrupt immediately), the guest's interrupt handler will invoke
the `stats_request()` callback. This callback calls `start_wakeup_event()`,
which attempts to acquire the uninitialized `wakeup_lock`.
**Exploitability**
The `virtio_balloon` structure is allocated using `kzalloc`, meaning the
uninitialized `wakeup_lock` is filled with zeroes. On almost all major
architectures (x86, ARM, ARM64, PowerPC, etc.), a zero-initialized spinlock is
structurally valid and represents an *unlocked* state. Consequently, the lock
operations will succeed normally without causing memory corruption,
out-of-bounds accesses, or use-after-free conditions. The bug is purely a
functional race condition and is **not exploitable** for privilege escalation or
information leaks.
**Denial of Service**
While benign on most architectures, on PA-RISC, a zero-initialized spinlock is
considered *locked* (the unlocked value is `0x1a46`). Attempting to acquire a
zeroed lock on PA-RISC will cause the CPU to spin indefinitely, resulting in a
hard hang (Denial of Service). Furthermore, in environments where
`panic_on_warn` is enabled (common in fuzzing and some strict production
setups), the lockdep warning itself will crash the system.
**Trigger Vectors**
* **VM Host Trigger in Confidential Computing Context**: The bug resides in the
guest kernel and is triggered by the host (hypervisor) sending an early
interrupt. A malicious or compromised host can reliably trigger this against a
guest VM (including Confidential VMs like AMD SEV or Intel TDX).
* **Peripheral Trigger**: A malicious physical PCIe device (e.g., plugged in via
Thunderbolt) can spoof a virtio-balloon PCI device, bind to the driver, and send
the early interrupt to trigger the bug on the host machine.
* **Unprivileged / User Namespace**: The bug cannot be triggered by unprivileged
users or from within user namespaces, as it strictly requires controlling the
virtio device's hardware/hypervisor responses. Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:true RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:true]
|
| 1/1 |
2026/08/19 01:51 |
action |
syz-repro-to-c-repro |
0m
Results:
|
| 2/1 |
2026/08/19 01:51 |
action |
kernel-checkouter |
0m
Results: map[KernelSrc:/app/workdir/cache/src/b5692495be56e63dd0879dd861d23f69899ae44d]
|
| 3/1 |
2026/08/19 01:51 |
action |
kernel-builder |
0m
Results: map[KernelObj:/app/workdir/cache/build/67073d3d26f00f0310b5d27ca01a221c8cbb8099]
|
| 4/1 |
2026/08/19 01:51 |
action |
codesearch-prepare |
0m
Results: map[Index:codesearch-index]
|
| 5/1 |
2026/08/19 01:51 |
agent |
expert |
14m
Model:
Results: map[DenialOfService:true Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:true RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:true]
Instruction: You are an experienced Linux kernel security engineer. Your task is to analyze given kernel bug report
and determine its security impact based on the following dimensions.
Use the provided tools to examine the source code, check for capability checks (e.g., capable(), ns_capable()),
and understand the nature of the bug. Analyze the given kernel build and configuration.
You can check the kernel config by grepping ".config" file; you can check kernel cmdline by grepping
".config" file for "CONFIG_CMDLINE=". Assume sysctl parameters have default values.
But analyze for the corresponding production build w/o debugging tools enabled (like KASAN, KMSAN, UBSAN).
Try different strategies when analyzing the bug:
- think of ways in which the vulnerable code is unreachable
- or the other way around: try to come up with different ideas of how an unprivileged user can reach the bug
If still unsure err on the side of the bug being non-exploitable/not-accessible.
In the final reply, provide a reasoning for your assessment.
Analysis dimensions:
* Exploitable:
Determine if the bug can result in memory corruption, elevated privileges, or an information leak.
Memory safety issues are almost always exploitable (KASAN or UBSAN reports for use-after-free, out-of-bounds;
refcounting issues, corrupted lists, etc). When kernel is crashing on a completely wild pointer access
(e.g. user-space address, or non-canonical address, but not on NULL or address corresponding to KASAN shadow
for NULL address), including both data accesses and control transfers, that also usually implies possibility
of exploitation. Such reports usually say "unable to handle kernel paging request".
Uses of uninitialized values detected by KMSAN may be exploitable b/c attacker frequently can affect uninit
values with spraying techniques. However, for these exploitability depends on how exactly the uninit value
is used in the code, and what it affects.
Information leaks are exploitable on their own and should be classified as such. A bug that copies kernel
memory contents to userspace (e.g. an out-of-bounds read whose result is returned to the caller, or
uninitialized stack/heap bytes written to a user buffer) is exploitable: it can reveal kernel pointer
values and defeat KASLR, expose sensitive data such as cryptographic keys or other processes' memory, and
serves as a necessary building block in most modern kernel privilege-escalation exploit chains. Do not classify
an information leak as non-exploitable solely because it does not directly cause a memory write or control-flow
hijack; the leak itself is the exploit primitive.
Think of what happens after the bug is triggered. Some bugs cause kernel panic and halt execution,
they are harder to exploit. For example, BUG reports halts the kernel. However, WARNING reports don't halt
execution in production builds. Debug bug detection tools (like KASAN, KMSAN, KCSAN, UBSAN) are also not enabled
in production builds, so attacker can freely exploit these bugs w/o being detected by these tools.
If you see an integer overflow, think how the overflowed value used later (if it's used as allocation size,
or an array index). If you see an out-of-bounds read, think if it's followed by an out-of-bounds write as well.
Some KCSAN data-races may be exploitable by skilled attackers as well. Think what data structures got corrupted
as the result of data races and how. However, note that kernel has lots of "benign" data races that don't lead
to any runtime misbehavior at all.
* Denial Of Service:
Determine if the bug can result in denial-of-service. Most bugs can, since they cause system crash,
hangs, deadlocks, or resource leaks. This is mostly applicable to WARNING bugs that won't cause system crash
in production. For these think what will be consequences of the violation of the kernel assumptions flagged
by the WARNING. In some cases the unexpected condition is also properly handled by the normal control flow
(e.g. with "if (WARN_ON(...))"), these won't cause denial-of-service. If the condition is not handled,
then it may or may not cause denial-of-service.
* Accessible From Unprivileged Processes:
Determine if the bug can be reached from a typical (non-root) user process that does NOT have any special capabilities
(like CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON) or access to device nodes restricted to root.
Assume that unprivileged_bpf_disabled=1, that is eBPF loading is not accessible. However, cBPF (classical BPF)
is still accessible to non-root processes.
Assume that user namespaces are not accessible, that is, the process cannot get the mentioned capabilities even
within a new user namespace (checked by ns_capable() function in the kernel sources).
* Accessible From User Namespaces:
Determine if the bug can be reached within a user-namespace where the process has all capabilities
(including CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON). Such capabilities are checked with ns_capable()
function in the kernel sources.
* VM Guest Trigger:
Determine if the bug can be triggered from the context of a typical KVM guest (e.g., set up by a QEMU VMM).
Consider accesses to standard Linux host paravirtualized features (virtio-blk, virtio-net, etc.),
and handling of VM exits in the KVM code.
* VM Host Trigger in The Confidential Computing Context:
Determine if the bug can be triggered in a confidential computing guest kernel from the context of a KVM host.
Consider access to standard Linux guest paravirtualized features (virtio-blk, virtio-net, etc.).
* Ethernet Network Trigger:
Determine if the bug can be triggered by processing ingress network Ethernet traffic, either directly (network stack)
or via drivers exposed to network data.
* Other Remote Trigger:
Determine if the bug can be triggered by processing remote traffic other than Ethernet (Wifi, Bluetooth, NFC, etc).
* Peripheral Trigger:
Determine if the bug can be triggered via an untrusted peripheral device that can be physically plugged
into a system, such as a USB device or a niche hardware driver handling external hardware inputs.
This is particularly important for mobile and desktop environments where users can plug in unknown devices.
* Malicious Filesystem Trigger:
Determine if the bug can be triggered by the kernel mounting and parsing a malicious filesystem image.
This is highly critical for Desktop and Mobile environments where external media or downloaded images
might be auto-mounted.
Don't make assumptions about the kernel source code (it may be different from what you assume it is).
Extensively use the provided code access tools (codesearch-*, git-*, grepper, etc)
to examine the actual source code, and confirm any assumptions.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt:
The kernel bug report is:
INFO: trying to register non-static key.
The code is fine but needs lockdep annotation, or maybe
you didn't initialize this object before use?
turning off the locking correctness validator.
CPU: 0 UID: 0 PID: 20235 Comm: irq/10-virtio2 Tainted: G L syzkaller #0 PREEMPT_{RT,(full)}
Tainted: [L]=SOFTLOCKUP
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/24/2026
Call Trace:
<TASK>
dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120
assign_lock_key+0x133/0x150 kernel/locking/lockdep.c:984
register_lock_class+0xcc/0x2e0 kernel/locking/lockdep.c:1299
__lock_acquire+0xab/0x2ce0 kernel/locking/lockdep.c:5112
lock_acquire+0x106/0x350 kernel/locking/lockdep.c:5868
rt_spin_lock+0x83/0x400 kernel/locking/spinlock_rt.c:56
spin_lock include/linux/spinlock_rt.h:45 [inline]
start_wakeup_event drivers/virtio/virtio_balloon.c:150 [inline]
stats_request+0xa5/0x1f0 drivers/virtio/virtio_balloon.c:435
vring_interrupt+0x408/0x680 drivers/virtio/virtio_ring.c:3297
vp_vring_interrupt drivers/virtio/virtio_pci_common.c:92 [inline]
vp_interrupt+0x183/0x200 drivers/virtio/virtio_pci_common.c:123
irq_thread_fn kernel/irq/manage.c:1143 [inline]
irq_forced_thread_fn+0x98/0x120 kernel/irq/manage.c:1165
irq_thread+0x455/0x690 kernel/irq/manage.c:1271
kthread+0x388/0x470 kernel/kthread.c:436
ret_from_fork+0x514/0xb70 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
</TASK>
Reply: **Bug Analysis & Trigger Mechanism**
The bug is a lockdep warning (`INFO: trying to register non-static key`) occurring in `start_wakeup_event()` within the `virtio_balloon` driver. This happens because `spin_lock_irqsave(&vb->wakeup_lock, flags)` is called before the lock has been initialized via `spin_lock_init()`.
During the device probe (`virtballoon_probe`), the driver calls `init_vqs()` to initialize the virtqueues. For the statistics virtqueue (`stats_vq`), it primes the queue with a buffer and immediately kicks it (`virtqueue_kick()`), notifying the device (hypervisor). However, `spin_lock_init(&vb->wakeup_lock)` is called *after* `init_vqs()`. If the device responds extremely quickly (or is malicious and sends an interrupt immediately), the guest's interrupt handler will invoke the `stats_request()` callback. This callback calls `start_wakeup_event()`, which attempts to acquire the uninitialized `wakeup_lock`.
**Exploitability**
The `virtio_balloon` structure is allocated using `kzalloc`, meaning the uninitialized `wakeup_lock` is filled with zeroes. On almost all major architectures (x86, ARM, ARM64, PowerPC, etc.), a zero-initialized spinlock is structurally valid and represents an *unlocked* state. Consequently, the lock operations will succeed normally without causing memory corruption, out-of-bounds accesses, or use-after-free conditions. The bug is purely a functional race condition and is **not exploitable** for privilege escalation or information leaks.
**Denial of Service**
While benign on most architectures, on PA-RISC, a zero-initialized spinlock is considered *locked* (the unlocked value is `0x1a46`). Attempting to acquire a zeroed lock on PA-RISC will cause the CPU to spin indefinitely, resulting in a hard hang (Denial of Service). Furthermore, in environments where `panic_on_warn` is enabled (common in fuzzing and some strict production setups), the lockdep warning itself will crash the system.
**Trigger Vectors**
* **VM Host Trigger in Confidential Computing Context**: The bug resides in the guest kernel and is triggered by the host (hypervisor) sending an early interrupt. A malicious or compromised host can reliably trigger this against a guest VM (including Confidential VMs like AMD SEV or Intel TDX).
* **Peripheral Trigger**: A malicious physical PCIe device (e.g., plugged in via Thunderbolt) can spoof a virtio-balloon PCI device, bind to the driver, and send the early interrupt to trigger the bug on the host machine.
* **Unprivileged / User Namespace**: The bug cannot be triggered by unprivileged users or from within user namespaces, as it strictly requires controlling the virtio device's hardware/hypervisor responses.
|
| 6/2 |
2026/08/19 01:51 |
llm |
expert |
0m
Model:
Tokens:
input: 6474
output: 40
thoughts: 277
Thoughts: **Debugging a Virtio Balloon Device Bug**
Okay, so I've got this bug report: "INFO: trying to register non-static key." Right away, I see it's buried in the `stats_request` function within `drivers/virtio/virtio_balloon.c`. That's my starting point. The trace is pointing directly at this, so let's check it.
I'm seeing that the stack trace is: `start_wakeup_event` -> `stats_request` -> `vring_interrupt` -> `vp_vring_interrupt` -> `vp_interrupt`. Alright, that confirms this is happening within an interrupt handler, specifically for the virtio balloon device.
The "non-static key" message is a red flag. It tells me someone's trying to acquire a spinlock, but the lock either hasn't been properly initialized or it's dynamically allocated without using `spin_lock_init()`. Time to dive into `drivers/virtio/virtio_balloon.c` and hunt down that uninitialized lock. It's almost certainly the root cause. Let's see if we can find it.
|
| 7/2 |
2026/08/19 01:51 |
tool |
read-file |
0m
Args: map[File:drivers/virtio/virtio_balloon.c FirstLine:130 LineCount:100]
Results: map[Contents: 130: #define VIRTIO_BALLOON_WAKEUP_SIGNAL_STATS (1 << 1)
131:
132: static const struct virtio_device_id id_table[] = {
133: { VIRTIO_ID_BALLOON, VIRTIO_DEV_ANY_ID },
134: { 0 },
135: };
136:
137: static u32 page_to_balloon_pfn(struct page *page)
138: {
139: unsigned long pfn = page_to_pfn(page);
140:
141: BUILD_BUG_ON(PAGE_SHIFT < VIRTIO_BALLOON_PFN_SHIFT);
142: /* Convert pfn from Linux page size to balloon page size. */
143: return pfn * VIRTIO_BALLOON_PAGES_PER_PAGE;
144: }
145:
146: static void start_wakeup_event(struct virtio_balloon *vb, u32 mask)
147: {
148: unsigned long flags;
149:
150: spin_lock_irqsave(&vb->wakeup_lock, flags);
151: vb->wakeup_signal_mask |= mask;
152: if (!vb->processing_wakeup_event) {
153: vb->processing_wakeup_event = true;
154: pm_stay_awake(&vb->vdev->dev);
155: }
156: spin_unlock_irqrestore(&vb->wakeup_lock, flags);
157: }
158:
159: static void process_wakeup_event(struct virtio_balloon *vb, u32 mask)
160: {
161: spin_lock_irq(&vb->wakeup_lock);
162: vb->wakeup_signal_mask &= ~mask;
163: spin_unlock_irq(&vb->wakeup_lock);
164: }
165:
166: static void finish_wakeup_event(struct virtio_balloon *vb)
167: {
168: spin_lock_irq(&vb->wakeup_lock);
169: if (!vb->wakeup_signal_mask && vb->processing_wakeup_event) {
170: vb->processing_wakeup_event = false;
171: pm_relax(&vb->vdev->dev);
172: }
173: spin_unlock_irq(&vb->wakeup_lock);
174: }
175:
176: static void balloon_ack(struct virtqueue *vq)
177: {
178: struct virtio_balloon *vb = vq->vdev->priv;
179:
180: wake_up(&vb->acked);
181: }
182:
183: static void tell_host(struct virtio_balloon *vb, struct virtqueue *vq)
184: {
185: struct scatterlist sg;
186: unsigned int len;
187:
188: sg_init_one(&sg, vb->pfns, sizeof(vb->pfns[0]) * vb->num_pfns);
189:
190: /* We should always be able to add one buffer to an empty queue. */
191: virtqueue_add_outbuf(vq, &sg, 1, vb, GFP_KERNEL);
192: virtqueue_kick(vq);
193:
194: /* When host has read buffer, this completes via balloon_ack */
195: wait_event(vb->acked, virtqueue_get_buf(vq, &len));
196:
197: }
198:
199: static int virtballoon_free_page_report(struct page_reporting_dev_info *pr_dev_info,
200: struct scatterlist *sg, unsigned int nents)
201: {
202: struct virtio_balloon *vb =
203: container_of(pr_dev_info, struct virtio_balloon, pr_dev_info);
204: struct virtqueue *vq = vb->reporting_vq;
205: unsigned int unused, err;
206:
207: /* We should always be able to add these buffers to an empty queue. */
208: err = virtqueue_add_inbuf(vq, sg, nents, vb, GFP_NOWAIT);
209:
210: /*
211: * In the extremely unlikely case that something has occurred and we
212: * are able to trigger an error we will simply display a warning
213: * and exit without actually processing the pages.
214: */
215: if (WARN_ON_ONCE(err))
216: return err;
217:
218: virtqueue_kick(vq);
219:
220: /* When host has read buffer, this completes via balloon_ack */
221: wait_event(vb->acked, virtqueue_get_buf(vq, &unused));
222:
223: return 0;
224: }
225:
226: static void set_page_pfns(struct virtio_balloon *vb,
227: __virtio32 pfns[], struct page *page)
228: {
229: unsigned int i;
]
|
| 8/2 |
2026/08/19 01:51 |
llm |
expert |
0m
Model:
Tokens:
input: 8317
output: 40
thoughts: 510
Thoughts: **Debugging a Lockdep Issue**
Okay, so I'm looking at this bug report: "INFO: trying to register non-static key." Right away, lockdep is screaming at me. The code itself *should* be fine, but it seems like there's either a missing `lockdep` annotation somewhere, or perhaps an uninitialized object is being used before the lock is set. I'm seeing this message, so I'm going to have to temporarily disable the locking correctness validator to move forward.
The call trace is right here, and it looks like the issue is originating with `register_lock_class`, which is being called from `assign_lock_key`. This then branches to `rt_spin_lock`, indicating a potential real-time spinlock issue, and that's likely the key. Going through the trace, I can see the issue is happening in `stats_request`, which calls `start_wakeup_event`. The lock in question seems to be `vb->wakeup_lock`.
Time to dig into `drivers/virtio/virtio_balloon.c` and specifically line 435 β that's where `stats_request` is defined. I'll take a look at the code there to see how the lock is being used and whether it's being properly initialized and annotated. It's probably a classic case of a lock being used before being properly registered with lockdep. I'll look for any missing `____read_lock`, `____write_lock`, or `lockdep_assert` calls, and verify the initialization path. Let's see what's actually going on.
|
| 9/2 |
2026/08/19 01:52 |
tool |
read-file |
0m
Args: map[File:drivers/virtio/virtio_balloon.c FirstLine:400 LineCount:100]
Results: map[Contents: 400: long available;
401: unsigned long caches;
402:
403: idx = update_balloon_vm_stats(vb);
404:
405: si_meminfo(&i);
406: available = si_mem_available();
407: caches = global_node_page_state(NR_FILE_PAGES);
408: update_stat(vb, idx++, VIRTIO_BALLOON_S_MEMFREE,
409: pages_to_bytes(i.freeram));
410: update_stat(vb, idx++, VIRTIO_BALLOON_S_MEMTOT,
411: pages_to_bytes(i.totalram));
412: update_stat(vb, idx++, VIRTIO_BALLOON_S_AVAIL,
413: pages_to_bytes(available));
414: update_stat(vb, idx++, VIRTIO_BALLOON_S_CACHES,
415: pages_to_bytes(caches));
416:
417: return idx;
418: }
419:
420: /*
421: * While most virtqueues communicate guest-initiated requests to the hypervisor,
422: * the stats queue operates in reverse. The driver initializes the virtqueue
423: * with a single buffer. From that point forward, all conversations consist of
424: * a hypervisor request (a call to this function) which directs us to refill
425: * the virtqueue with a fresh stats buffer. Since stats collection can sleep,
426: * we delegate the job to a freezable workqueue that will do the actual work via
427: * stats_handle_request().
428: */
429: static void stats_request(struct virtqueue *vq)
430: {
431: struct virtio_balloon *vb = vq->vdev->priv;
432:
433: spin_lock(&vb->stop_update_lock);
434: if (!vb->stop_update) {
435: start_wakeup_event(vb, VIRTIO_BALLOON_WAKEUP_SIGNAL_STATS);
436: queue_work(system_freezable_wq, &vb->update_balloon_stats_work);
437: }
438: spin_unlock(&vb->stop_update_lock);
439: }
440:
441: static void stats_handle_request(struct virtio_balloon *vb)
442: {
443: struct virtqueue *vq;
444: struct scatterlist sg;
445: unsigned int len, num_stats;
446:
447: num_stats = update_balloon_stats(vb);
448:
449: vq = vb->stats_vq;
450: if (!virtqueue_get_buf(vq, &len))
451: return;
452: sg_init_one(&sg, vb->stats, sizeof(vb->stats[0]) * num_stats);
453: virtqueue_add_outbuf(vq, &sg, 1, vb, GFP_KERNEL);
454: virtqueue_kick(vq);
455: }
456:
457: static inline s64 towards_target(struct virtio_balloon *vb)
458: {
459: s64 target;
460: u32 num_pages;
461:
462: /* Legacy balloon config space is LE, unlike all other devices. */
463: virtio_cread_le(vb->vdev, struct virtio_balloon_config, num_pages,
464: &num_pages);
465:
466: /*
467: * Aligned up to guest page size to avoid inflating and deflating
468: * balloon endlessly.
469: */
470: target = ALIGN(num_pages, VIRTIO_BALLOON_PAGES_PER_PAGE);
471: return target - vb->num_pages;
472: }
473:
474: /* Gives back @num_to_return blocks of free pages to mm. */
475: static unsigned long return_free_pages_to_mm(struct virtio_balloon *vb,
476: unsigned long num_to_return)
477: {
478: unsigned long num_returned = 0;
479: struct page *page, *next;
480:
481: if (unlikely(!num_to_return))
482: return 0;
483:
484: spin_lock_irq(&vb->free_page_list_lock);
485:
486: list_for_each_entry_safe(page, next, &vb->free_page_list, lru) {
487: list_del(&page->lru);
488: __free_pages(page, VIRTIO_BALLOON_HINT_BLOCK_ORDER);
489: if (++num_returned == num_to_return)
490: break;
491: }
492: vb->num_free_page_blocks -= num_returned;
493: spin_unlock_irq(&vb->free_page_list_lock);
494:
495: return num_returned;
496: }
497:
498: static void virtio_balloon_queue_free_page_work(struct virtio_balloon *vb)
499: {
]
|
| 10/2 |
2026/08/19 01:52 |
llm |
expert |
0m
Model:
Tokens:
input: 10300
output: 21
thoughts: 240
Thoughts: **Debugging a Spinlock Initialization Issue**
Okay, so I'm looking at this bug report and the core of the problem seems to be this "INFO: trying to register non-static key" message. Itβs popping up in `start_wakeup_event` when it calls `spin_lock_irqsave(&vb->wakeup_lock, flags)`. The stack trace confirms this, pointing to line 150 in `drivers/virtio/virtio_balloon.c`, right where the lock is taken.
The report also mentions `rt_spin_lock` which has me wondering if it is related.
The lockdep warning about an uninitialized lock or a non-static key is what's really catching my attention. That strongly suggests that `vb->wakeup_lock` isn't properly initialized *before* it's being used. So, the next logical step is to trace where `vb->wakeup_lock` is actually initialized to confirm or deny this. I need to find the definition of the `virtio_balloon` structure and understand where the lock itself gets set up. Itβs most likely a race condition in the initialization.
|
| 11/2 |
2026/08/19 01:52 |
tool |
codesearch-find-references |
0m
Error:
Args:
Results: map[References:<nil> TruncatedOutput:false]
|
| 12/2 |
2026/08/19 01:52 |
llm |
expert |
0m
Model:
Tokens:
input: 10588
output: 22
thoughts: 0
|
| 13/2 |
2026/08/19 01:52 |
tool |
codesearch-struct-layout |
0m
Args:
Results: map[Fields:[map[Name:vdev OffsetBits:0 SizeBits:64] map[Name:inflate_vq OffsetBits:64 SizeBits:64] map[Name:deflate_vq OffsetBits:128 SizeBits:64] map[Name:stats_vq OffsetBits:192 SizeBits:64] map[Name:free_page_vq OffsetBits:256 SizeBits:64] map[Name:balloon_wq OffsetBits:320 SizeBits:64] map[Name:report_free_page_work OffsetBits:384 SizeBits:576] map[Name:update_balloon_stats_work OffsetBits:960 SizeBits:576] map[Name:update_balloon_size_work OffsetBits:1536 SizeBits:576] map[Name:stop_update_lock OffsetBits:2112 SizeBits:1024] map[Name:stop_update OffsetBits:3136 SizeBits:8] map[Name:config_read_bitmap OffsetBits:3200 SizeBits:64] map[Name:free_page_list OffsetBits:3264 SizeBits:128] map[Name:free_page_list_lock OffsetBits:3392 SizeBits:1024] map[Name:num_free_page_blocks OffsetBits:4416 SizeBits:64] map[Name:cmd_id_received_cache OffsetBits:4480 SizeBits:32] map[Name:cmd_id_active OffsetBits:4512 SizeBits:32] map[Name:cmd_id_stop OffsetBits:4544 SizeBits:32] map[Name:acked OffsetBits:4608 SizeBits:1152] map[Name:num_pages OffsetBits:5760 SizeBits:32] map[Name:vb_dev_info OffsetBits:5824 SizeBits:320] map[Name:balloon_lock OffsetBits:6144 SizeBits:1024] map[Name:num_pfns OffsetBits:7168 SizeBits:32] map[Name:pfns OffsetBits:7200 SizeBits:8192] map[Name:stats OffsetBits:15392 SizeBits:1280] map[Name:shrinker OffsetBits:16704 SizeBits:64] map[Name:oom_nb OffsetBits:16768 SizeBits:192] map[Name:reporting_vq OffsetBits:16960 SizeBits:64] map[Name:pr_dev_info OffsetBits:17024 SizeBits:1536] map[Name:wakeup_lock OffsetBits:18560 SizeBits:1024] map[Name:processing_wakeup_event OffsetBits:19584 SizeBits:8] map[Name:wakeup_signal_mask OffsetBits:19616 SizeBits:32]]]
|
| 14/2 |
2026/08/19 01:52 |
llm |
expert |
0m
Model:
Tokens:
input: 11384
output: 26
thoughts: 0
|
| 15/2 |
2026/08/19 01:52 |
tool |
codesearch-find-references |
0m
Args: map[Name:virtio_balloon::wakeup_lock]
Results: map[References:[map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:finish_wakeup_event SourceFile:drivers/virtio/virtio_balloon.c SourceLine:168] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:finish_wakeup_event SourceFile:drivers/virtio/virtio_balloon.c SourceLine:173] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:process_wakeup_event SourceFile:drivers/virtio/virtio_balloon.c SourceLine:161] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:process_wakeup_event SourceFile:drivers/virtio/virtio_balloon.c SourceLine:163] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:start_wakeup_event SourceFile:drivers/virtio/virtio_balloon.c SourceLine:150] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:start_wakeup_event SourceFile:drivers/virtio/virtio_balloon.c SourceLine:156] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:virtballoon_probe SourceFile:drivers/virtio/virtio_balloon.c SourceLine:1046] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:virtballoon_probe SourceFile:drivers/virtio/virtio_balloon.c SourceLine:1046]] TruncatedOutput:false]
|
| 16/2 |
2026/08/19 01:52 |
llm |
expert |
0m
Model:
Tokens:
input: 11886
output: 41
thoughts: 0
|
| 17/2 |
2026/08/19 01:52 |
tool |
read-file |
0m
Args: map[File:drivers/virtio/virtio_balloon.c FirstLine:1000 LineCount:100]
Results: map[Contents:1000: * Let the hypervisor know that we are expecting a
1001: * specific value to be written back in balloon pages.
1002: *
1003: * If the PAGE_POISON value was larger than a byte we would
1004: * need to byte swap poison_val here to guarantee it is
1005: * little-endian. However for now it is a single byte so we
1006: * can pass it as-is.
1007: */
1008: if (!want_init_on_free())
1009: memset(&poison_val, PAGE_POISON, sizeof(poison_val));
1010:
1011: virtio_cwrite_le(vb->vdev, struct virtio_balloon_config,
1012: poison_val, &poison_val);
1013: }
1014:
1015: vb->pr_dev_info.report = virtballoon_free_page_report;
1016: if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_REPORTING)) {
1017: unsigned int capacity;
1018:
1019: capacity = virtqueue_get_vring_size(vb->reporting_vq);
1020:
1021: vb->pr_dev_info.order = PAGE_REPORTING_ORDER_UNSPECIFIED;
1022:
1023: /*
1024: * The default page reporting order is @pageblock_order, which
1025: * corresponds to 512MB in size on ARM64 when 64KB base page
1026: * size is used. The page reporting won't be triggered if the
1027: * freeing page can't come up with a free area like that huge.
1028: * So we specify the page reporting order to 5, corresponding
1029: * to 2MB. It helps to avoid THP splitting if 4KB base page
1030: * size is used by host.
1031: *
1032: * Ideally, the page reporting order is selected based on the
1033: * host's base page size. However, it needs more work to report
1034: * that value. The hard-coded order would be fine currently.
1035: */
1036: #if defined(CONFIG_ARM64) && defined(CONFIG_ARM64_64K_PAGES)
1037: vb->pr_dev_info.order = 5;
1038: #endif
1039:
1040: vb->pr_dev_info.capacity = capacity;
1041: err = page_reporting_register(&vb->pr_dev_info);
1042: if (err)
1043: goto out_unregister_oom;
1044: }
1045:
1046: spin_lock_init(&vb->wakeup_lock);
1047:
1048: /*
1049: * The virtio balloon itself can't wake up the device, but it is
1050: * responsible for processing wakeup events passed up from the transport
1051: * layer. Wakeup sources don't support nesting/chaining calls, so we use
1052: * our own wakeup source to ensure wakeup events are properly handled
1053: * without trampling on the transport layer's wakeup source.
1054: */
1055: device_set_wakeup_capable(&vb->vdev->dev, true);
1056:
1057: virtio_device_ready(vdev);
1058:
1059: if (towards_target(vb))
1060: virtballoon_changed(vdev);
1061: return 0;
1062:
1063: out_unregister_oom:
1064: if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_DEFLATE_ON_OOM))
1065: unregister_oom_notifier(&vb->oom_nb);
1066: out_unregister_shrinker:
1067: if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_FREE_PAGE_HINT))
1068: virtio_balloon_unregister_shrinker(vb);
1069: out_del_balloon_wq:
1070: if (virtio_has_feature(vdev, VIRTIO_BALLOON_F_FREE_PAGE_HINT))
1071: destroy_workqueue(vb->balloon_wq);
1072: out_del_vqs:
1073: vdev->config->del_vqs(vdev);
1074: out_free_vb:
1075: mutex_destroy(&vb->balloon_lock);
1076: kfree(vb);
1077: out:
1078: return err;
1079: }
1080:
1081: static void remove_common(struct virtio_balloon *vb)
1082: {
1083: /* There might be pages left in the balloon: free them. */
1084: while (vb->num_pages)
1085: leak_balloon(vb, vb->num_pages);
1086: update_balloon_size(vb);
1087:
1088: /* There might be free pages that are being reported: release them. */
1089: if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_FREE_PAGE_HINT))
1090: return_free_pages_to_mm(vb, ULONG_MAX);
1091:
1092: /* Now we reset the device so we can clean up the queues. */
1093: virtio_reset_device(vb->vdev);
1094:
1095: vb->vdev->config->del_vqs(vb->vdev);
1096: }
1097:
1098: static void virtballoon_remove(struct virtio_device *vdev)
1099: {
]
|
| 18/2 |
2026/08/19 01:52 |
llm |
expert |
0m
Model:
Tokens:
input: 13605
output: 40
thoughts: 745
Thoughts: **Debugging a Locking Issue in the Virtio Balloon Driver**
Okay, here's what's running through my head. The kernel is complaining about a "non-static key" registration during a lock acquisition, specifically when trying to register a non-static key. The stack trace points to `start_wakeup_event`, which is pretty low-level. I see it starts with `assign_lock_key`, which is a classic lockdep function. That narrows down the problem to a locking issue, obviously.
Now, let's trace where `start_wakeup_event` is being called. It looks like it's within `stats_request`, which makes sense. `stats_request` is a callback function for a `virtqueue`, specifically the stats virtqueue. Okay, a little more context - `stats_request` is using `start_wakeup_event` inside a conditional based on `vb->stop_update`. It's protecting access with `vb->stop_update_lock`.
Here's the interesting part: `start_wakeup_event` takes `vb->wakeup_lock`. I need to understand when and how this is initialized. Looking at the code for the `start_wakeup_event`, it protects `vb->wakeup_signal_mask` with `spin_lock_irqsave(&vb->wakeup_lock, flags)`. Now, I need to check where `vb->wakeup_lock` is initialized. Okay, the code shows `spin_lock_init(&vb->wakeup_lock)` in `virtballoon_probe`.
Aha! Now I see a potential race condition! Is it possible that `stats_request` is being called *before* `virtballoon_probe` has a chance to initialize `vb->wakeup_lock`? If `stats_request` is triggered during device initialization, then the `spin_lock_init` would not have been executed, and the `spin_lock` call inside `start_wakeup_event` would be operating on an uninitialized lock, which is a guaranteed recipe for lockdep errors.
I'm pretty sure I need to dig into the timing of the probe and interrupt handling. That's where I'll focus my investigation. I need to figure out the exact call chain leading to `stats_request` and ensure that `virtballoon_probe` completes initialization of `vb->wakeup_lock` *before* `stats_request` is ever invoked.
|
| 19/2 |
2026/08/19 01:52 |
tool |
read-file |
0m
Args: map[File:drivers/virtio/virtio_balloon.c FirstLine:900 LineCount:100]
Results: map[Contents: 900: {
901: shrinker_free(vb->shrinker);
902: }
903:
904: static int virtio_balloon_register_shrinker(struct virtio_balloon *vb)
905: {
906: vb->shrinker = shrinker_alloc(0, "virtio-balloon");
907: if (!vb->shrinker)
908: return -ENOMEM;
909:
910: vb->shrinker->scan_objects = virtio_balloon_shrinker_scan;
911: vb->shrinker->count_objects = virtio_balloon_shrinker_count;
912: vb->shrinker->private_data = vb;
913:
914: shrinker_register(vb->shrinker);
915:
916: return 0;
917: }
918:
919: static int virtballoon_probe(struct virtio_device *vdev)
920: {
921: struct virtio_balloon *vb;
922: int err;
923:
924: if (!vdev->config->get) {
925: dev_err(&vdev->dev, "%s failure: config access disabled\n",
926: __func__);
927: return -EINVAL;
928: }
929:
930: vdev->priv = vb = kzalloc_obj(*vb);
931: if (!vb) {
932: err = -ENOMEM;
933: goto out;
934: }
935:
936: INIT_WORK(&vb->update_balloon_stats_work, update_balloon_stats_func);
937: INIT_WORK(&vb->update_balloon_size_work, update_balloon_size_func);
938: spin_lock_init(&vb->stop_update_lock);
939: mutex_init(&vb->balloon_lock);
940: init_waitqueue_head(&vb->acked);
941: vb->vdev = vdev;
942:
943: balloon_devinfo_init(&vb->vb_dev_info);
944:
945: err = init_vqs(vb);
946: if (err)
947: goto out_free_vb;
948:
949: if (!virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_DEFLATE_ON_OOM))
950: vb->vb_dev_info.adjust_managed_page_count = true;
951: #ifdef CONFIG_BALLOON_MIGRATION
952: vb->vb_dev_info.migratepage = virtballoon_migratepage;
953: #endif
954: if (virtio_has_feature(vdev, VIRTIO_BALLOON_F_FREE_PAGE_HINT)) {
955: /*
956: * There is always one entry reserved for cmd id, so the ring
957: * size needs to be at least two to report free page hints.
958: */
959: if (virtqueue_get_vring_size(vb->free_page_vq) < 2) {
960: err = -ENOSPC;
961: goto out_del_vqs;
962: }
963: vb->balloon_wq = alloc_workqueue("balloon-wq",
964: WQ_FREEZABLE | WQ_CPU_INTENSIVE | WQ_PERCPU,
965: 0);
966: if (!vb->balloon_wq) {
967: err = -ENOMEM;
968: goto out_del_vqs;
969: }
970: INIT_WORK(&vb->report_free_page_work, report_free_page_func);
971: vb->cmd_id_received_cache = VIRTIO_BALLOON_CMD_ID_STOP;
972: vb->cmd_id_active = cpu_to_virtio32(vb->vdev,
973: VIRTIO_BALLOON_CMD_ID_STOP);
974: vb->cmd_id_stop = cpu_to_virtio32(vb->vdev,
975: VIRTIO_BALLOON_CMD_ID_STOP);
976: spin_lock_init(&vb->free_page_list_lock);
977: INIT_LIST_HEAD(&vb->free_page_list);
978: /*
979: * We're allowed to reuse any free pages, even if they are
980: * still to be processed by the host.
981: */
982: err = virtio_balloon_register_shrinker(vb);
983: if (err)
984: goto out_del_balloon_wq;
985: }
986:
987: if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_DEFLATE_ON_OOM)) {
988: vb->oom_nb.notifier_call = virtio_balloon_oom_notify;
989: vb->oom_nb.priority = VIRTIO_BALLOON_OOM_NOTIFY_PRIORITY;
990: err = register_oom_notifier(&vb->oom_nb);
991: if (err < 0)
992: goto out_unregister_shrinker;
993: }
994:
995: if (virtio_has_feature(vdev, VIRTIO_BALLOON_F_PAGE_POISON)) {
996: /* Start with poison val of 0 representing general init */
997: __u32 poison_val = 0;
998:
999: /*
]
|
| 20/2 |
2026/08/19 01:52 |
llm |
expert |
0m
Model:
Tokens:
input: 15828
output: 22
thoughts: 0
|
| 21/2 |
2026/08/19 01:52 |
tool |
codesearch-find-references |
0m
Args: map[Name:virtballoon_probe]
Results: map[References:[map[ReferenceKind:takes-address-of ReferencingEntityKind:global_variable ReferencingEntityName:virtio_balloon_driver SourceFile:drivers/virtio/virtio_balloon.c SourceLine:1187]] TruncatedOutput:false]
|
| 22/2 |
2026/08/19 01:52 |
llm |
expert |
0m
Model:
Tokens:
input: 15931
output: 41
thoughts: 0
|
| 23/2 |
2026/08/19 01:52 |
tool |
read-file |
0m
Args: map[File:drivers/virtio/virtio_balloon.c FirstLine:1150 LineCount:100]
Results: map[Contents:1150: update_balloon_size(vb);
1151: return 0;
1152: }
1153: #endif
1154:
1155: static int virtballoon_validate(struct virtio_device *vdev)
1156: {
1157: /*
1158: * Inform the hypervisor that our pages are poisoned or
1159: * initialized. If we cannot do that then we should disable
1160: * page reporting as it could potentially change the contents
1161: * of our free pages.
1162: */
1163: if (!want_init_on_free() && !page_poisoning_enabled_static())
1164: __virtio_clear_bit(vdev, VIRTIO_BALLOON_F_PAGE_POISON);
1165: else if (!virtio_has_feature(vdev, VIRTIO_BALLOON_F_PAGE_POISON))
1166: __virtio_clear_bit(vdev, VIRTIO_BALLOON_F_REPORTING);
1167:
1168: __virtio_clear_bit(vdev, VIRTIO_F_ACCESS_PLATFORM);
1169: return 0;
1170: }
1171:
1172: static unsigned int features[] = {
1173: VIRTIO_BALLOON_F_MUST_TELL_HOST,
1174: VIRTIO_BALLOON_F_STATS_VQ,
1175: VIRTIO_BALLOON_F_DEFLATE_ON_OOM,
1176: VIRTIO_BALLOON_F_FREE_PAGE_HINT,
1177: VIRTIO_BALLOON_F_PAGE_POISON,
1178: VIRTIO_BALLOON_F_REPORTING,
1179: };
1180:
1181: static struct virtio_driver virtio_balloon_driver = {
1182: .feature_table = features,
1183: .feature_table_size = ARRAY_SIZE(features),
1184: .driver.name = KBUILD_MODNAME,
1185: .id_table = id_table,
1186: .validate = virtballoon_validate,
1187: .probe = virtballoon_probe,
1188: .remove = virtballoon_remove,
1189: .config_changed = virtballoon_changed,
1190: #ifdef CONFIG_PM_SLEEP
1191: .freeze = virtballoon_freeze,
1192: .restore = virtballoon_restore,
1193: #endif
1194: };
1195:
1196: module_virtio_driver(virtio_balloon_driver);
1197: MODULE_DEVICE_TABLE(virtio, id_table);
1198: MODULE_DESCRIPTION("Virtio balloon driver");
1199: MODULE_LICENSE("GPL");
]
|
| 24/2 |
2026/08/19 01:52 |
llm |
expert |
0m
Model:
Tokens:
input: 16803
output: 35
thoughts: 0
|
| 25/2 |
2026/08/19 01:52 |
tool |
git-log |
10m
Error:
Args: map[CodeRegexp:spin_lock_init\(&vb->wakeup_lock\) Count:10]
Results:
|
| 26/2 |
2026/08/19 02:02 |
llm |
expert |
0m
Model:
Tokens:
input: 16873
output: 52
thoughts: 0
|
| 27/2 |
2026/08/19 02:02 |
tool |
git-log |
0m
Args: map[CodeRegexp:spin_lock_init\(&vb->wakeup_lock\) Count:10 PathPrefix:drivers/virtio/virtio_balloon.c]
Results: map[Output:c578123e63da virtio_balloon: Treat stats requests as wakeup events
]
|
| 28/2 |
2026/08/19 02:02 |
llm |
expert |
0m
Model:
Tokens:
input: 16961
output: 26
thoughts: 0
|
| 29/2 |
2026/08/19 02:03 |
tool |
git-show |
0m
Args:
Results: map[Output:commit c578123e63da31d9d3876c33a8e3415597288e7d
Author: David Stevens <stevensd@chromium.org>
Date: Thu Mar 21 10:24:45 2024 +0900
virtio_balloon: Treat stats requests as wakeup events
Treat stats requests as wakeup events to ensure that the driver responds
to device requests in a timely manner.
Signed-off-by: David Stevens <stevensd@chromium.org>
Acked-by: David Hildenbrand <david@redhat.com>
Message-Id: <20240321012445.1593685-3-stevensd@google.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 89bc8da80519..b09e8e3c62e5 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -121,11 +121,14 @@ struct virtio_balloon {
struct page_reporting_dev_info pr_dev_info;
/* State for keeping the wakeup_source active while adjusting the balloon */
- spinlock_t adjustment_lock;
- bool adjustment_signal_pending;
- bool adjustment_in_progress;
+ spinlock_t wakeup_lock;
+ bool processing_wakeup_event;
+ u32 wakeup_signal_mask;
};
+#define VIRTIO_BALLOON_WAKEUP_SIGNAL_ADJUST (1 << 0)
+#define VIRTIO_BALLOON_WAKEUP_SIGNAL_STATS (1 << 1)
+
static const struct virtio_device_id id_table[] = {
{ VIRTIO_ID_BALLOON, VIRTIO_DEV_ANY_ID },
{ 0 },
@@ -140,6 +143,36 @@ static u32 page_to_balloon_pfn(struct page *page)
return pfn * VIRTIO_BALLOON_PAGES_PER_PAGE;
}
+static void start_wakeup_event(struct virtio_balloon *vb, u32 mask)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&vb->wakeup_lock, flags);
+ vb->wakeup_signal_mask |= mask;
+ if (!vb->processing_wakeup_event) {
+ vb->processing_wakeup_event = true;
+ pm_stay_awake(&vb->vdev->dev);
+ }
+ spin_unlock_irqrestore(&vb->wakeup_lock, flags);
+}
+
+static void process_wakeup_event(struct virtio_balloon *vb, u32 mask)
+{
+ spin_lock_irq(&vb->wakeup_lock);
+ vb->wakeup_signal_mask &= ~mask;
+ spin_unlock_irq(&vb->wakeup_lock);
+}
+
+static void finish_wakeup_event(struct virtio_balloon *vb)
+{
+ spin_lock_irq(&vb->wakeup_lock);
+ if (!vb->wakeup_signal_mask && vb->processing_wakeup_event) {
+ vb->processing_wakeup_event = false;
+ pm_relax(&vb->vdev->dev);
+ }
+ spin_unlock_irq(&vb->wakeup_lock);
+}
+
static void balloon_ack(struct virtqueue *vq)
{
struct virtio_balloon *vb = vq->vdev->priv;
@@ -370,8 +403,10 @@ static void stats_request(struct virtqueue *vq)
struct virtio_balloon *vb = vq->vdev->priv;
spin_lock(&vb->stop_update_lock);
- if (!vb->stop_update)
+ if (!vb->stop_update) {
+ start_wakeup_event(vb, VIRTIO_BALLOON_WAKEUP_SIGNAL_STATS);
queue_work(system_freezable_wq, &vb->update_balloon_stats_work);
+ }
spin_unlock(&vb->stop_update_lock);
}
@@ -444,29 +479,10 @@ static void virtio_balloon_queue_free_page_work(struct virtio_balloon *vb)
static void start_update_balloon_size(struct virtio_balloon *vb)
{
- unsigned long flags;
-
- spin_lock_irqsave(&vb->adjustment_lock, flags);
- vb->adjustment_signal_pending = true;
- if (!vb->adjustment_in_progress) {
- vb->adjustment_in_progress = true;
- pm_stay_awake(&vb->vdev->dev);
- }
- spin_unlock_irqrestore(&vb->adjustment_lock, flags);
-
+ start_wakeup_event(vb, VIRTIO_BALLOON_WAKEUP_SIGNAL_ADJUST);
queue_work(system_freezable_wq, &vb->update_balloon_size_work);
}
-static void end_update_balloon_size(struct virtio_balloon *vb)
-{
- spin_lock_irq(&vb->adjustment_lock);
- if (!vb->adjustment_signal_pending && vb->adjustment_in_progress) {
- vb->adjustment_in_progress = false;
- pm_relax(&vb->vdev->dev);
- }
- spin_unlock_irq(&vb->adjustment_lock);
-}
-
static void virtballoon_changed(struct virtio_device *vdev)
{
struct virtio_balloon *vb = vdev->priv;
@@ -495,7 +511,10 @@ static void update_balloon_stats_func(struct work_struct *work)
vb = container_of(work, struct virtio_balloon,
update_balloon_stats_work);
+
+ process_wakeup_event(vb, VIRTIO_BALLOON_WAKEUP_SIGNAL_STATS);
stats_handle_request(vb);
+ finish_wakeup_event(vb);
}
static void update_balloon_size_func(struct work_struct *work)
@@ -506,9 +525,7 @@ static void update_balloon_size_func(struct work_struct *work)
vb = container_of(work, struct virtio_balloon,
update_balloon_size_work);
- spin_lock_irq(&vb->adjustment_lock);
- vb->adjustment_signal_pending = false;
- spin_unlock_irq(&vb->adjustment_lock);
+ process_wakeup_event(vb, VIRTIO_BALLOON_WAKEUP_SIGNAL_ADJUST);
diff = towards_target(vb);
@@ -523,7 +540,7 @@ static void update_balloon_size_func(struct work_struct *work)
if (diff)
queue_work(system_freezable_wq, work);
else
- end_update_balloon_size(vb);
+ finish_wakeup_event(vb);
}
static int init_vqs(struct virtio_balloon *vb)
@@ -1027,7 +1044,7 @@ static int virtballoon_probe(struct virtio_device *vdev)
goto out_unregister_oom;
}
- spin_lock_init(&vb->adjustment_lock);
+ spin_lock_init(&vb->wakeup_lock);
/*
* The virtio balloon itself can't wake up the device, but it is
]
|
| 30/2 |
2026/08/19 02:03 |
llm |
expert |
0m
Model:
Tokens:
input: 18990
output: 52
thoughts: 0
|
| 31/2 |
2026/08/19 02:03 |
tool |
git-log |
0m
Args: map[CodeRegexp:spin_lock_init\(&vb->wakeup_lock\) Count:10 PathPrefix:drivers/virtio/virtio_balloon.c]
Results: map[Output:c578123e63da virtio_balloon: Treat stats requests as wakeup events
]
|
| 32/2 |
2026/08/19 02:03 |
llm |
expert |
0m
Model:
Tokens:
input: 19078
output: 26
thoughts: 0
|
| 33/2 |
2026/08/19 02:03 |
tool |
git-show |
0m
Args:
Results: map[Output:commit c578123e63da31d9d3876c33a8e3415597288e7d
Author: David Stevens <stevensd@chromium.org>
Date: Thu Mar 21 10:24:45 2024 +0900
virtio_balloon: Treat stats requests as wakeup events
Treat stats requests as wakeup events to ensure that the driver responds
to device requests in a timely manner.
Signed-off-by: David Stevens <stevensd@chromium.org>
Acked-by: David Hildenbrand <david@redhat.com>
Message-Id: <20240321012445.1593685-3-stevensd@google.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 89bc8da80519..b09e8e3c62e5 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -121,11 +121,14 @@ struct virtio_balloon {
struct page_reporting_dev_info pr_dev_info;
/* State for keeping the wakeup_source active while adjusting the balloon */
- spinlock_t adjustment_lock;
- bool adjustment_signal_pending;
- bool adjustment_in_progress;
+ spinlock_t wakeup_lock;
+ bool processing_wakeup_event;
+ u32 wakeup_signal_mask;
};
+#define VIRTIO_BALLOON_WAKEUP_SIGNAL_ADJUST (1 << 0)
+#define VIRTIO_BALLOON_WAKEUP_SIGNAL_STATS (1 << 1)
+
static const struct virtio_device_id id_table[] = {
{ VIRTIO_ID_BALLOON, VIRTIO_DEV_ANY_ID },
{ 0 },
@@ -140,6 +143,36 @@ static u32 page_to_balloon_pfn(struct page *page)
return pfn * VIRTIO_BALLOON_PAGES_PER_PAGE;
}
+static void start_wakeup_event(struct virtio_balloon *vb, u32 mask)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(&vb->wakeup_lock, flags);
+ vb->wakeup_signal_mask |= mask;
+ if (!vb->processing_wakeup_event) {
+ vb->processing_wakeup_event = true;
+ pm_stay_awake(&vb->vdev->dev);
+ }
+ spin_unlock_irqrestore(&vb->wakeup_lock, flags);
+}
+
+static void process_wakeup_event(struct virtio_balloon *vb, u32 mask)
+{
+ spin_lock_irq(&vb->wakeup_lock);
+ vb->wakeup_signal_mask &= ~mask;
+ spin_unlock_irq(&vb->wakeup_lock);
+}
+
+static void finish_wakeup_event(struct virtio_balloon *vb)
+{
+ spin_lock_irq(&vb->wakeup_lock);
+ if (!vb->wakeup_signal_mask && vb->processing_wakeup_event) {
+ vb->processing_wakeup_event = false;
+ pm_relax(&vb->vdev->dev);
+ }
+ spin_unlock_irq(&vb->wakeup_lock);
+}
+
static void balloon_ack(struct virtqueue *vq)
{
struct virtio_balloon *vb = vq->vdev->priv;
@@ -370,8 +403,10 @@ static void stats_request(struct virtqueue *vq)
struct virtio_balloon *vb = vq->vdev->priv;
spin_lock(&vb->stop_update_lock);
- if (!vb->stop_update)
+ if (!vb->stop_update) {
+ start_wakeup_event(vb, VIRTIO_BALLOON_WAKEUP_SIGNAL_STATS);
queue_work(system_freezable_wq, &vb->update_balloon_stats_work);
+ }
spin_unlock(&vb->stop_update_lock);
}
@@ -444,29 +479,10 @@ static void virtio_balloon_queue_free_page_work(struct virtio_balloon *vb)
static void start_update_balloon_size(struct virtio_balloon *vb)
{
- unsigned long flags;
-
- spin_lock_irqsave(&vb->adjustment_lock, flags);
- vb->adjustment_signal_pending = true;
- if (!vb->adjustment_in_progress) {
- vb->adjustment_in_progress = true;
- pm_stay_awake(&vb->vdev->dev);
- }
- spin_unlock_irqrestore(&vb->adjustment_lock, flags);
-
+ start_wakeup_event(vb, VIRTIO_BALLOON_WAKEUP_SIGNAL_ADJUST);
queue_work(system_freezable_wq, &vb->update_balloon_size_work);
}
-static void end_update_balloon_size(struct virtio_balloon *vb)
-{
- spin_lock_irq(&vb->adjustment_lock);
- if (!vb->adjustment_signal_pending && vb->adjustment_in_progress) {
- vb->adjustment_in_progress = false;
- pm_relax(&vb->vdev->dev);
- }
- spin_unlock_irq(&vb->adjustment_lock);
-}
-
static void virtballoon_changed(struct virtio_device *vdev)
{
struct virtio_balloon *vb = vdev->priv;
@@ -495,7 +511,10 @@ static void update_balloon_stats_func(struct work_struct *work)
vb = container_of(work, struct virtio_balloon,
update_balloon_stats_work);
+
+ process_wakeup_event(vb, VIRTIO_BALLOON_WAKEUP_SIGNAL_STATS);
stats_handle_request(vb);
+ finish_wakeup_event(vb);
}
static void update_balloon_size_func(struct work_struct *work)
@@ -506,9 +525,7 @@ static void update_balloon_size_func(struct work_struct *work)
vb = container_of(work, struct virtio_balloon,
update_balloon_size_work);
- spin_lock_irq(&vb->adjustment_lock);
- vb->adjustment_signal_pending = false;
- spin_unlock_irq(&vb->adjustment_lock);
+ process_wakeup_event(vb, VIRTIO_BALLOON_WAKEUP_SIGNAL_ADJUST);
diff = towards_target(vb);
@@ -523,7 +540,7 @@ static void update_balloon_size_func(struct work_struct *work)
if (diff)
queue_work(system_freezable_wq, work);
else
- end_update_balloon_size(vb);
+ finish_wakeup_event(vb);
}
static int init_vqs(struct virtio_balloon *vb)
@@ -1027,7 +1044,7 @@ static int virtballoon_probe(struct virtio_device *vdev)
goto out_unregister_oom;
}
- spin_lock_init(&vb->adjustment_lock);
+ spin_lock_init(&vb->wakeup_lock);
/*
* The virtio balloon itself can't wake up the device, but it is
]
|
| 34/2 |
2026/08/19 02:03 |
llm |
expert |
0m
Model:
Tokens:
input: 21107
output: 52
thoughts: 0
|
| 35/2 |
2026/08/19 02:03 |
tool |
git-log |
0m
Args: map[CodeRegexp:spin_lock_init\(&vb->wakeup_lock\) Count:10 PathPrefix:drivers/virtio/virtio_balloon.c]
Results: map[Output:c578123e63da virtio_balloon: Treat stats requests as wakeup events
]
|
| 36/2 |
2026/08/19 02:03 |
llm |
expert |
0m
Model:
Tokens:
input: 21195
output: 52
thoughts: 0
|
| 37/2 |
2026/08/19 02:03 |
tool |
git-log |
0m
Error:
Args: map[CodeRegexp:spin_lock_init\(&vb->wakeup_lock\) Count:10 PathPrefix:drivers/virtio/virtio_balloon.c]
|
| 38/2 |
2026/08/19 02:03 |
llm |
expert |
0m
Model:
Tokens:
input: 23153
output: 40
thoughts: 36
Thoughts: **My Initial Concerns Regarding Initialization Order**
Okay, hold on a minute. I'm seeing something that's making me pause. The code is calling `init_vqs` *before* `spin_lock_init(&vb->wakeup_lock)`. That feels... off. My gut is telling me the order is potentially significant here, and I need to verify that everything is being properly initialized before anything that depends on it. I need to dig into the `init_vqs` function immediately and understand what it's doing. What variables, locks, or structures is it setting up? Does it, by chance, depend on the state of `vb->wakeup_lock`? This could be a race condition waiting to happen. Time to dive into the details.
|
| 39/2 |
2026/08/19 02:03 |
tool |
read-file |
0m
Args: map[File:drivers/virtio/virtio_balloon.c FirstLine:540 LineCount:100]
Results: map[Contents: 540: {
541: struct virtio_balloon *vb;
542:
543: vb = container_of(work, struct virtio_balloon,
544: update_balloon_stats_work);
545:
546: process_wakeup_event(vb, VIRTIO_BALLOON_WAKEUP_SIGNAL_STATS);
547: stats_handle_request(vb);
548: finish_wakeup_event(vb);
549: }
550:
551: static void update_balloon_size_func(struct work_struct *work)
552: {
553: struct virtio_balloon *vb;
554: s64 diff;
555:
556: vb = container_of(work, struct virtio_balloon,
557: update_balloon_size_work);
558:
559: process_wakeup_event(vb, VIRTIO_BALLOON_WAKEUP_SIGNAL_ADJUST);
560:
561: diff = towards_target(vb);
562:
563: if (diff) {
564: if (diff > 0)
565: diff -= fill_balloon(vb, diff);
566: else
567: diff += leak_balloon(vb, -diff);
568: update_balloon_size(vb);
569: }
570:
571: if (diff)
572: queue_work(system_freezable_wq, work);
573: else
574: finish_wakeup_event(vb);
575: }
576:
577: static int init_vqs(struct virtio_balloon *vb)
578: {
579: struct virtqueue_info vqs_info[VIRTIO_BALLOON_VQ_MAX] = {};
580: struct virtqueue *vqs[VIRTIO_BALLOON_VQ_MAX];
581: int err;
582:
583: /*
584: * Inflateq and deflateq are used unconditionally. The names[]
585: * will be NULL if the related feature is not enabled, which will
586: * cause no allocation for the corresponding virtqueue in find_vqs.
587: */
588: vqs_info[VIRTIO_BALLOON_VQ_INFLATE].callback = balloon_ack;
589: vqs_info[VIRTIO_BALLOON_VQ_INFLATE].name = "inflate";
590: vqs_info[VIRTIO_BALLOON_VQ_DEFLATE].callback = balloon_ack;
591: vqs_info[VIRTIO_BALLOON_VQ_DEFLATE].name = "deflate";
592:
593: if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ)) {
594: vqs_info[VIRTIO_BALLOON_VQ_STATS].name = "stats";
595: vqs_info[VIRTIO_BALLOON_VQ_STATS].callback = stats_request;
596: }
597:
598: if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_FREE_PAGE_HINT))
599: vqs_info[VIRTIO_BALLOON_VQ_FREE_PAGE].name = "free_page_vq";
600:
601: if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_REPORTING)) {
602: vqs_info[VIRTIO_BALLOON_VQ_REPORTING].name = "reporting_vq";
603: vqs_info[VIRTIO_BALLOON_VQ_REPORTING].callback = balloon_ack;
604: }
605:
606: err = virtio_find_vqs(vb->vdev, VIRTIO_BALLOON_VQ_MAX, vqs,
607: vqs_info, NULL);
608: if (err)
609: return err;
610:
611: vb->inflate_vq = vqs[VIRTIO_BALLOON_VQ_INFLATE];
612: vb->deflate_vq = vqs[VIRTIO_BALLOON_VQ_DEFLATE];
613: if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ)) {
614: struct scatterlist sg;
615: unsigned int num_stats;
616: vb->stats_vq = vqs[VIRTIO_BALLOON_VQ_STATS];
617:
618: /*
619: * Prime this virtqueue with one buffer so the hypervisor can
620: * use it to signal us later (it can't be broken yet!).
621: */
622: num_stats = update_balloon_stats(vb);
623:
624: sg_init_one(&sg, vb->stats, sizeof(vb->stats[0]) * num_stats);
625: err = virtqueue_add_outbuf(vb->stats_vq, &sg, 1, vb,
626: GFP_KERNEL);
627: if (err) {
628: dev_warn(&vb->vdev->dev, "%s: add stat_vq failed\n",
629: __func__);
630: return err;
631: }
632: virtqueue_kick(vb->stats_vq);
633: }
634:
635: if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_FREE_PAGE_HINT))
636: vb->free_page_vq = vqs[VIRTIO_BALLOON_VQ_FREE_PAGE];
637:
638: if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_REPORTING))
639: vb->reporting_vq = vqs[VIRTIO_BALLOON_VQ_REPORTING];
]
|
| 40/2 |
2026/08/19 02:03 |
llm |
expert |
0m
Model:
Tokens:
input: 25153
output: 40
thoughts: 1028
Thoughts: **Analyzing a Potential Race Condition in Virtio Balloon Driver Initialization**
Okay, so I'm digging into this Virtio Balloon driver initialization, specifically `init_vqs`. I see that if the `VIRTIO_BALLOON_F_STATS_VQ` feature is present, a statistics virtqueue (`vb->stats_vq`) is initialized. A buffer is added to this virtqueue using `virtqueue_add_outbuf`, and then `virtqueue_kick` is called. This `kick` signals the hypervisor that a buffer is ready. The hypervisor can then immediately process it and potentially send an interrupt. This interrupt, handled by `vring_interrupt`, leads to a call to `stats_request`, which, in turn, calls `start_wakeup_event`.
Now, the interesting part. `start_wakeup_event` attempts to take a spinlock, `vb->wakeup_lock`. The crucial point is that `spin_lock_init(&vb->wakeup_lock)` is called *after* `init_vqs(vb)` during the `virtballoon_probe` process, leading me to believe this is a race condition. If the hypervisor is quick enough, or if it is malicious and quickly sends the interrupt, or we are using a tool like Syzkaller, then it can trigger an interrupt before `spin_lock_init` is called. This early interrupt leads to the attempt to acquire an uninitialized lock. Lockdep, correctly, flags this as an issue, complaining about "trying to register non-static key" because the lock's class key hasn't been set.
Now, the question is, is this actually exploitable? Let's see what happens if the lock is uninitialized. `kzalloc_obj(*vb)` zeros out the memory. So `vb->wakeup_lock` ends up as all zeros. On x86, a zeroed `spinlock_t` *is* actually unlocked because its value (`val`) is zero. Lockdep complains because the lock key isn't initialized, but without lockdep, `spin_lock_init` on x86 just sets the `val` to zero, which is what `kzalloc` already did! So, without lockdep, it functions exactly like a valid lock! No bug!
I need to confirm this. The definition of `spinlock_t` confirms that without `CONFIG_DEBUG_LOCK_ALLOC`, it's just a `struct raw_spinlock`, which on x86 is a `qspinlock` β effectively an `atomic_t val`. `spin_lock_init` sets `val` to 0, which `kzalloc` already did. So, the lock *is* valid and functional, just not according to lockdep.
Okay, let's keep digging. Are there any other uninitialized fields in this structure? `vb->wakeup_signal_mask` is zero, and so is `vb->processing_wakeup_event`. Both of these are correctly zero-initialized.
Now, is there another issue with `pm_stay_awake(&vb->vdev->dev)` being called *before* `device_set_wakeup_capable(&vb->vdev->dev, true)`? I'll need to check the function to see what this does.
|
| 41/2 |
2026/08/19 02:03 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/virtio/virtio_balloon.c Name:pm_stay_awake]
Results: map[SourceCode: 615: /**
616: * pm_stay_awake - Notify the PM core that a wakeup event is being processed.
617: * @dev: Device the wakeup event is related to.
618: *
619: * Notify the PM core of a wakeup event (signaled by @dev) by calling
620: * __pm_stay_awake for the @dev's wakeup source object.
621: *
622: * Call this function after detecting of a wakeup event if pm_relax() is going
623: * to be called directly after processing the event (and possibly passing it to
624: * user space for further processing).
625: */
626: void pm_stay_awake(struct device *dev)
627: {
628: unsigned long flags;
629:
630: if (!dev)
631: return;
632:
633: spin_lock_irqsave(&dev->power.lock, flags);
634: __pm_stay_awake(dev->power.wakeup);
635: spin_unlock_irqrestore(&dev->power.lock, flags);
636: }
SourceFile:drivers/base/power/wakeup.c]
|
| 42/2 |
2026/08/19 02:03 |
llm |
expert |
0m
Model:
Tokens:
input: 27282
output: 39
thoughts: 12
Thoughts: Okay, here's my interpretation of that thought process, assuming I'm deep in my domain expertise:
**Checking the `__pm_stay_awake` Variable**
Alright, time to dig in. The mention of `__pm_stay_awake` immediately flags a specific area for me β power management, specifically the interaction of a system or process with the power management subsystem. I'm likely thinking about a situation where a particular task, application, or perhaps even the entire device, needs to override the default power-saving behaviors. My immediate thought is, "What's the context? What am I trying to achieve?" Is this about ensuring a background process completes, preventing a display from dimming during a critical operation, or something even more nuanced?
Checking that variable is the first thing I do to understand if I am correctly making sure my code is working. If I am dealing with power and need to run properly, this is the first thing I would check. I'm going to want to confirm its current value and understand *why* it's set the way it is. I'll need to know: Is it correctly initialized? Is it being modified as expected? And most importantly, is it actually having the intended effect within the larger power management framework of the system? I'll probably look for where this variable is defined, where it's being read from, and where it's being written to. My goal is to understand the complete control flow related to this setting. Basically, I'm trying to ensure there are no surprises that could cause an unwanted power state or other error. The goal is to ensure the process runs optimally.
|
| 43/2 |
2026/08/19 02:03 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/base/power/wakeup.c Name:__pm_stay_awake]
Results: map[SourceCode: 592: /**
593: * __pm_stay_awake - Notify the PM core of a wakeup event.
594: * @ws: Wakeup source object associated with the source of the event.
595: *
596: * It is safe to call this function from interrupt context.
597: */
598: void __pm_stay_awake(struct wakeup_source *ws)
599: {
600: unsigned long flags;
601:
602: if (!ws)
603: return;
604:
605: spin_lock_irqsave(&ws->lock, flags);
606:
607: wakeup_source_report_event(ws, false);
608: timer_delete(&ws->timer);
609: ws->timer_expires = 0;
610:
611: spin_unlock_irqrestore(&ws->lock, flags);
612: }
SourceFile:drivers/base/power/wakeup.c]
|
| 44/2 |
2026/08/19 02:03 |
llm |
expert |
0m
Model:
Tokens:
input: 27987
output: 42
thoughts: 40
Thoughts: **Checking Wakeup Capability**
Okay, so I'm diving into this power management code and I need to be careful about potential race conditions. If `device_set_wakeup_capable` hasn't been called, then that `dev->power.wakeup` pointer could very well be null. That's a classic null pointer dereference waiting to happen, and we can't have that. My first thought is to just go check that function; let's verify how it behaves and then, perhaps, determine the correct mitigation.
|
| 45/2 |
2026/08/19 02:03 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/virtio/virtio_balloon.c Name:device_set_wakeup_capable]
Results: map[SourceCode: 459: /**
460: * device_set_wakeup_capable - Set/reset device wakeup capability flag.
461: * @dev: Device to handle.
462: * @capable: Whether or not @dev is capable of waking up the system from sleep.
463: *
464: * If @capable is set, set the @dev's power.can_wakeup flag and add its
465: * wakeup-related attributes to sysfs. Otherwise, unset the @dev's
466: * power.can_wakeup flag and remove its wakeup-related attributes from sysfs.
467: *
468: * This function may sleep and it can't be called from any context where
469: * sleeping is not allowed.
470: */
471: void device_set_wakeup_capable(struct device *dev, bool capable)
472: {
473: if (!!dev->power.can_wakeup == !!capable)
474: return;
475:
476: dev->power.can_wakeup = capable;
477: if (device_is_registered(dev) && !list_empty(&dev->power.entry)) {
478: if (capable) {
479: int ret = wakeup_sysfs_add(dev);
480:
481: if (ret)
482: dev_info(dev, "Wakeup sysfs attributes not added\n");
483: } else {
484: wakeup_sysfs_remove(dev);
485: }
486: }
487: }
SourceFile:drivers/base/power/wakeup.c]
|
| 46/2 |
2026/08/19 02:03 |
llm |
expert |
0m
Model:
Tokens:
input: 28664
output: 38
thoughts: 45
Thoughts: Okay, here's my take on those thoughts, framed as my own mental process:
**Wakeup Capability Allocation - Digging Deeper**
Alright, hang on a second. I'm looking at this `device_set_wakeup_capable` function, and something's just not sitting right. I'm pretty sure it *sets* the wakeup capability flag, but I'm having a nagging feeling that it doesn't actually handle the allocation of the `dev->power.wakeup` structure itself. It just assumes it's already there, or that someone else creates it. Now, that's not necessarily a problem, but it means I need to track down exactly *where* that `dev->power.wakeup` memory is being allocated. I mean, it's critical, right? If it's not set up correctly, the whole wakeup mechanism is going to be a disaster.
So, where do I start? Let's go straight to the source. The natural place to look is `device_wakeup_enable`. That function *sounds* like it should be involved in setting up the wakeup functionality, including potentially allocating that structure. It's the logical place to check. Time to dive into the code and see what that function does. I need to figure out the whole picture here.
|
| 47/2 |
2026/08/19 02:03 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/base/power/wakeup.c Name:device_wakeup_enable]
Results: map[SourceCode: 319: /**
320: * device_wakeup_enable - Enable given device to be a wakeup source.
321: * @dev: Device to handle.
322: *
323: * Create a wakeup source object, register it and attach it to @dev.
324: */
325: int device_wakeup_enable(struct device *dev)
326: {
327: struct wakeup_source *ws;
328: int ret;
329:
330: if (!dev || !dev->power.can_wakeup)
331: return -EINVAL;
332:
333: if (pm_sleep_transition_in_progress())
334: dev_dbg(dev, "Suspicious %s() during system transition!\n", __func__);
335:
336: ws = wakeup_source_register(dev, dev_name(dev));
337: if (!ws)
338: return -ENOMEM;
339:
340: ret = device_wakeup_attach(dev, ws);
341: if (ret)
342: wakeup_source_unregister(ws);
343:
344: return ret;
345: }
SourceFile:drivers/base/power/wakeup.c]
|
| 48/2 |
2026/08/19 02:03 |
llm |
expert |
0m
Model:
Tokens:
input: 29413
output: 30
thoughts: 1207
Thoughts: **Analyzing Potential Race Conditions in Virtballoon Driver**
Okay, so I'm looking at this `virtballoon` code and I see that if `dev->power.wakeup` is NULL, then `pm_stay_awake` simply won't do anything, which seems perfectly safe, and `__pm_stay_awake` is designed to handle a null wakeup pointer, so that's good.
The only immediate concern is the lockdep warning. But is there anything *else* to worry about? I see this `wakeup_lock`, and since `vb` is `kzalloc`'d, the lock is initialized to zero. On x86, using an uninitialized spinlock like this works, but just acquires the lock. So with lockdep disabled, there's no problem. It's a false positive, and everything works.
Wait, though, `spin_lock_init` *is* called later in `virtballoon_probe`. That's where it's called. So what happens if the lock has been used before it's initialized? That's definitely bad. Re-initializing a held lock clears the lock state, leading to a race. But `virtballoon_probe` runs in a thread context, and the interrupt handler `vring_interrupt` is in an IRQ context. There's a chance `spin_lock_init` could be called *while* the lock is held in the interrupt handler.
If that happens, `spin_lock_init` will essentially reset the lock. Another thread could then acquire the lock while the first thread still *thinks* it holds it. The code that calls `pm_stay_awake` only holds the lock for a very short period. But it's long enough to potentially cause corruption in `vb->wakeup_signal_mask` if two threads modify it concurrently, or `vb->processing_wakeup_event` gets clobbered. However, the probability is minute, as it's just a bitmask and boolean. It's not memory corruption or anything serious.
And, `spin_lock_init` is called *once* at probe. So the chance of a race is extremely low. Even if it hits, it just messes up one wakeup event. But it will *not* corrupt memory or cause a crash.
Wait, another thought... what if `spin_lock_init` is called while `spin_unlock_irqrestore` is running? But the x86 `spin_unlock_irqrestore` just sets the lock to 0, and `spin_lock_init` also sets the lock to 0. So no problem there.
Are there any other uninitialized locks? Let me check. The other locks are initialized before `init_vqs(vb)`. So those are fine. What about `vb->free_page_list_lock`? Ah, that's initialized *after* `init_vqs(vb)`. Let's check where `free_page_list_lock` is used...
|
| 49/2 |
2026/08/19 02:04 |
tool |
codesearch-find-references |
0m
Args: map[Name:virtio_balloon::free_page_list_lock]
Results: map[References:[map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:get_free_page_and_send SourceFile:drivers/virtio/virtio_balloon.c SourceLine:724] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:get_free_page_and_send SourceFile:drivers/virtio/virtio_balloon.c SourceLine:727] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:return_free_pages_to_mm SourceFile:drivers/virtio/virtio_balloon.c SourceLine:484] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:return_free_pages_to_mm SourceFile:drivers/virtio/virtio_balloon.c SourceLine:493] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:virtballoon_probe SourceFile:drivers/virtio/virtio_balloon.c SourceLine:976] map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:virtballoon_probe SourceFile:drivers/virtio/virtio_balloon.c SourceLine:976]] TruncatedOutput:false]
|
| 50/2 |
2026/08/19 02:04 |
llm |
expert |
0m
Model:
Tokens:
input: 31670
output: 39
thoughts: 0
|
| 51/2 |
2026/08/19 02:04 |
tool |
read-file |
0m
Args: map[File:drivers/virtio/virtio_balloon.c FirstLine:700 LineCount:50]
Results: map[Contents: 700:
701: /* Detach all the used buffers from the vq */
702: while (virtqueue_get_buf(vq, &unused))
703: ;
704:
705: page = alloc_pages(VIRTIO_BALLOON_FREE_PAGE_ALLOC_FLAG,
706: VIRTIO_BALLOON_HINT_BLOCK_ORDER);
707: /*
708: * When the allocation returns NULL, it indicates that we have got all
709: * the possible free pages, so return -EINTR to stop.
710: */
711: if (!page)
712: return -EINTR;
713:
714: p = page_address(page);
715: sg_init_one(&sg, p, VIRTIO_BALLOON_HINT_BLOCK_BYTES);
716: /* There is always 1 entry reserved for the cmd id to use. */
717: if (vq->num_free > 1) {
718: err = virtqueue_add_inbuf(vq, &sg, 1, p, GFP_KERNEL);
719: if (unlikely(err)) {
720: __free_pages(page, VIRTIO_BALLOON_HINT_BLOCK_ORDER);
721: return err;
722: }
723: virtqueue_kick(vq);
724: spin_lock_irq(&vb->free_page_list_lock);
725: list_add(&page->lru, &vb->free_page_list);
726: vb->num_free_page_blocks++;
727: spin_unlock_irq(&vb->free_page_list_lock);
728: } else {
729: /*
730: * The vq has no available entry to add this page block, so
731: * just free it.
732: */
733: __free_pages(page, VIRTIO_BALLOON_HINT_BLOCK_ORDER);
734: }
735:
736: return 0;
737: }
738:
739: static int send_free_pages(struct virtio_balloon *vb)
740: {
741: int err;
742: u32 cmd_id_active;
743:
744: while (1) {
745: /*
746: * If a stop id or a new cmd id was just received from host,
747: * stop the reporting.
748: */
749: cmd_id_active = virtio32_to_cpu(vb->vdev, vb->cmd_id_active);
]
|
| 52/2 |
2026/08/19 02:04 |
llm |
expert |
0m
Model:
Tokens:
input: 32502
output: 49
thoughts: 1442
Thoughts: **Analysis of a Spinlock Initialization Race Condition in Virtio Balloon Driver**
Okay, so I'm digging into this code, starting with how `get_free_page_and_send` is called β it seems to trace back through a workqueue function (`report_free_page_func`). The workqueue is queued via `virtio_balloon_queue_free_page_work`, triggered by either `virtballoon_changed` or `balloon_ack`. Now, `free_page_vq` is involved here, but hold on, the `free_page_vq` callback is not `balloon_ack`. Let's check `init_vqs`: and it has NO callback! That's odd. So, `free_page_vq` doesn't seem to trigger an interrupt and call a function.
`balloon_ack` is the callback for `inflate_vq`, `deflate_vq`, and `reporting_vq` β those use the `wake_up(&vb->acked)` function. And `vb->acked` is initialized before `init_vqs(vb)` which is good, so `balloon_ack` seems safe.
But what about `stats_request`? It's the callback for `stats_vq` and this calls `start_wakeup_event`, which uses `vb->wakeup_lock`. Then I see that `vb->wakeup_lock` is initialized *after* `init_vqs(vb)`. So, the bug is right here: `stats_request` can be called before `vb->wakeup_lock` is initialized.
Is this exploitable? I remember that `vb` is allocated with `kzalloc`. So, `vb->wakeup_lock` will be initialized to 0. On x86, a 0-initialized `spinlock_t` is a valid, unlocked spinlock. So, `spin_lock_irqsave` will just acquire the lock. `spin_unlock_irqrestore` will release it. There's no memory corruption, no out-of-bounds access, and no use-after-free. It's just a lockdep warning because the lock class key isn't registered. In a production kernel (without lockdep), this code will run perfectly fine, so no issues there.
Wait, what if `spin_lock_init` is called *while* the lock is held? Let's trace it back to `spin_lock_init(&vb->wakeup_lock)`. `spin_lock_init` expands to `raw_spin_lock_init`. `raw_spin_lock_init` just writes a 0 to the lock. If the lock is held, it will unlock it. But, `start_wakeup_event` holds the lock for just a few instructions. The chance of `spin_lock_init` being called between `spin_lock_irqsave` and `spin_unlock_irqrestore` is extremely small. And even if it happens, the lock is just unlocked early. The critical section modifies `vb->wakeup_signal_mask` and `vb->processing_wakeup_event`, and calls `pm_stay_awake`. So the worst that can happen is a race condition on `vb->wakeup_signal_mask` and `vb->processing_wakeup_event`. This might cause a wakeup event to be missed or processed twice.
I don't see any real security vulnerability here. This seems not exploitable.
Now, wait... are there other architectures where a 0-initialized spinlock is NOT a valid unlocked spinlock? I remember that some architectures, had a non-zero value for unlocked. PA-RISC used 1 for unlocked. Wait, PA-RISC `arch_spinlock_t` uses an array of 4 ints, and it uses `__ARCH_SPIN_LOCK_UNLOCKED` which is `{ { 1, 1, 1, 1 } }`. Looks like I have to go check PA-RISC spinlock to be sure.
|
| 53/2 |
2026/08/19 02:04 |
tool |
codesearch-definition-source |
0m
Error:
Args: map[ContextFile:arch/parisc/include/asm/spinlock_types.h Name:__ARCH_SPIN_LOCK_UNLOCKED]
Results: map[SourceCode: SourceFile:]
|
| 54/2 |
2026/08/19 02:04 |
llm |
expert |
0m
Model:
Tokens:
input: 34876
output: 35
thoughts: 0
|
| 55/2 |
2026/08/19 02:04 |
tool |
grepper |
0m
Args: map[Expression:__ARCH_SPIN_LOCK_UNLOCKED PathPrefix:arch/parisc]
Results: map[Output:arch/parisc/include/asm/spinlock.h=10=static inline void arch_spin_val_check(int lock_val)
--
arch/parisc/include/asm/spinlock.h-14- ".word %2\n"
arch/parisc/include/asm/spinlock.h:15: : : "r" (lock_val), "r" (__ARCH_SPIN_LOCK_UNLOCKED_VAL),
arch/parisc/include/asm/spinlock.h-16- "i" (SPINLOCK_BREAK_INSN));
--
arch/parisc/include/asm/spinlock.h=49=static inline void arch_spin_unlock(arch_spinlock_t *x)
--
arch/parisc/include/asm/spinlock.h-55- __asm__ __volatile__("stw,ma %0,0(%1)"
arch/parisc/include/asm/spinlock.h:56: : : "r"(__ARCH_SPIN_LOCK_UNLOCKED_VAL), "r"(a) : "memory");
arch/parisc/include/asm/spinlock.h-57-}
--
arch/parisc/include/asm/spinlock_types.h-4-
arch/parisc/include/asm/spinlock_types.h:5:#define __ARCH_SPIN_LOCK_UNLOCKED_VAL 0x1a46
arch/parisc/include/asm/spinlock_types.h-6-
--
arch/parisc/include/asm/spinlock_types.h=11=typedef struct {
arch/parisc/include/asm/spinlock_types.h-12- volatile unsigned int lock[4];
arch/parisc/include/asm/spinlock_types.h:13:# define __ARCH_SPIN_LOCK_UNLOCKED \
arch/parisc/include/asm/spinlock_types.h:14: { { __ARCH_SPIN_LOCK_UNLOCKED_VAL, __ARCH_SPIN_LOCK_UNLOCKED_VAL, \
arch/parisc/include/asm/spinlock_types.h:15: __ARCH_SPIN_LOCK_UNLOCKED_VAL, __ARCH_SPIN_LOCK_UNLOCKED_VAL } }
arch/parisc/include/asm/spinlock_types.h-16-} arch_spinlock_t;
--
arch/parisc/include/asm/spinlock_types.h=24=typedef struct {
--
arch/parisc/include/asm/spinlock_types.h-31-#define __ARCH_RW_LOCK_UNLOCKED__ 0x01000000
arch/parisc/include/asm/spinlock_types.h:32:#define __ARCH_RW_LOCK_UNLOCKED { .lock_mutex = __ARCH_SPIN_LOCK_UNLOCKED, \
arch/parisc/include/asm/spinlock_types.h-33- .counter = __ARCH_RW_LOCK_UNLOCKED__ }
--
arch/parisc/kernel/entry.S-442-98: get_ptl \tmp
arch/parisc/kernel/entry.S:443: ldi __ARCH_SPIN_LOCK_UNLOCKED_VAL, \tmp2
arch/parisc/kernel/entry.S-444- or,COND(=) %r0,\spc,%r0
--
arch/parisc/kernel/syscall.S=29=registers).
--
arch/parisc/kernel/syscall.S-70- /* raise exception if spinlock content is not zero or
arch/parisc/kernel/syscall.S:71: * __ARCH_SPIN_LOCK_UNLOCKED_VAL */
arch/parisc/kernel/syscall.S-72- .macro spinlock_check spin_val,tmpreg
arch/parisc/kernel/syscall.S-73-#ifdef CONFIG_LIGHTWEIGHT_SPINLOCK_CHECK
arch/parisc/kernel/syscall.S:74: ldi __ARCH_SPIN_LOCK_UNLOCKED_VAL, \tmpreg
arch/parisc/kernel/syscall.S-75- andcm,= \spin_val, \tmpreg, %r0
--
arch/parisc/kernel/syscall.S=520=lws_exit_noerror:
arch/parisc/kernel/syscall.S-521- lws_pagefault_enable %r1,%r21
arch/parisc/kernel/syscall.S:522: ldi __ARCH_SPIN_LOCK_UNLOCKED_VAL, %r21
arch/parisc/kernel/syscall.S-523- stw,ma %r21, 0(%sr2,%r20)
--
arch/parisc/kernel/syscall.S=534=lws_pagefault:
arch/parisc/kernel/syscall.S-535- lws_pagefault_enable %r1,%r21
arch/parisc/kernel/syscall.S:536: ldi __ARCH_SPIN_LOCK_UNLOCKED_VAL, %r21
arch/parisc/kernel/syscall.S-537- stw,ma %r21, 0(%sr2,%r20)
--
arch/parisc/kernel/syscall.S=1363=ENTRY(lws_lock_start)
--
arch/parisc/kernel/syscall.S-1366- /* Keep locks aligned at 16-bytes */
arch/parisc/kernel/syscall.S:1367: .word __ARCH_SPIN_LOCK_UNLOCKED_VAL
arch/parisc/kernel/syscall.S-1368- .word 0
--
arch/parisc/lib/bitops.c=15=arch_spinlock_t __atomic_hash[ATOMIC_HASH_SIZE] __lock_aligned = {
arch/parisc/lib/bitops.c:16: [0 ... (ATOMIC_HASH_SIZE-1)] = __ARCH_SPIN_LOCK_UNLOCKED
arch/parisc/lib/bitops.c-17-};
]
|
| 56/2 |
2026/08/19 02:04 |
llm |
expert |
0m
Model:
Tokens:
input: 36408
output: 41
thoughts: 83
Thoughts: **PA-RISC Spinlock Investigation**
Okay, so I'm digging into PA-RISC spinlocks. Right off the bat, I see something potentially tricky. The value of `__ARCH_SPIN_LOCK_UNLOCKED_VAL` is `0x1a46`. That's not what I'd expect for an unlocked state, especially since a 0-initialized spinlock is the common starting point. This immediately throws up a red flag. If a freshly initialized spinlock isn't actually unlocked, that changes the whole game. Now, the question is, *does* a zero value mean locked? I need to verify what `arch_spin_lock` actually does on PA-RISC. I'm going to consult the implementation, because I need to understand what state means a "lock", and what state means "unlocked" so that the code works correctly.
|
| 57/2 |
2026/08/19 02:04 |
tool |
codesearch-definition-source |
0m
Error:
Args: map[ContextFile:arch/parisc/include/asm/spinlock.h Name:arch_spin_lock]
Results: map[SourceCode: SourceFile:]
|
| 58/2 |
2026/08/19 02:04 |
llm |
expert |
0m
Model:
Tokens:
input: 36743
output: 29
thoughts: 0
|
| 59/2 |
2026/08/19 02:04 |
tool |
grepper |
0m
Args: map[Expression:arch_spin_lock PathPrefix:arch/parisc]
Results: map[Output:arch/parisc/include/asm/atomic.h=32=extern arch_spinlock_t __atomic_hash[ATOMIC_HASH_SIZE] __lock_aligned;
--
arch/parisc/include/asm/atomic.h-38- local_irq_save(f); \
arch/parisc/include/asm/atomic.h:39: arch_spin_lock(s); \
arch/parisc/include/asm/atomic.h-40-} while(0)
--
arch/parisc/include/asm/futex.h=21=_futex_spin_lock_irqsave(arch_spinlock_t *s, unsigned long *flags)
--
arch/parisc/include/asm/futex.h-23- local_irq_save(*flags);
arch/parisc/include/asm/futex.h:24: arch_spin_lock(s);
arch/parisc/include/asm/futex.h-25-}
--
arch/parisc/include/asm/spinlock.h=19=static inline int arch_spin_is_locked(arch_spinlock_t *x)
--
arch/parisc/include/asm/spinlock.h-29-
arch/parisc/include/asm/spinlock.h:30:static inline void arch_spin_lock(arch_spinlock_t *x)
arch/parisc/include/asm/spinlock.h-31-{
--
arch/parisc/include/asm/spinlock.h=79=static inline int arch_read_trylock(arch_rwlock_t *rw)
--
arch/parisc/include/asm/spinlock.h-84- local_irq_save(flags);
arch/parisc/include/asm/spinlock.h:85: arch_spin_lock(&(rw->lock_mutex));
arch/parisc/include/asm/spinlock.h-86-
--
arch/parisc/include/asm/spinlock.h=103=static inline int arch_write_trylock(arch_rwlock_t *rw)
--
arch/parisc/include/asm/spinlock.h-108- local_irq_save(flags);
arch/parisc/include/asm/spinlock.h:109: arch_spin_lock(&(rw->lock_mutex));
arch/parisc/include/asm/spinlock.h-110-
--
arch/parisc/include/asm/spinlock.h=139=static inline void arch_read_unlock(arch_rwlock_t *rw)
--
arch/parisc/include/asm/spinlock.h-143- local_irq_save(flags);
arch/parisc/include/asm/spinlock.h:144: arch_spin_lock(&(rw->lock_mutex));
arch/parisc/include/asm/spinlock.h-145- rw->counter++;
--
arch/parisc/include/asm/spinlock.h=150=static inline void arch_write_unlock(arch_rwlock_t *rw)
--
arch/parisc/include/asm/spinlock.h-154- local_irq_save(flags);
arch/parisc/include/asm/spinlock.h:155: arch_spin_lock(&(rw->lock_mutex));
arch/parisc/include/asm/spinlock.h-156- rw->counter = __ARCH_RW_LOCK_UNLOCKED__;
]
|
| 60/2 |
2026/08/19 02:04 |
llm |
expert |
0m
Model:
Tokens:
input: 37619
output: 39
thoughts: 0
|
| 61/2 |
2026/08/19 02:04 |
tool |
read-file |
0m
Args: map[File:arch/parisc/include/asm/spinlock.h FirstLine:20 LineCount:50]
Results: map[Contents: 20: {
21: volatile unsigned int *a;
22: int lock_val;
23:
24: a = __ldcw_align(x);
25: lock_val = READ_ONCE(*a);
26: arch_spin_val_check(lock_val);
27: return (lock_val == 0);
28: }
29:
30: static inline void arch_spin_lock(arch_spinlock_t *x)
31: {
32: volatile unsigned int *a;
33:
34: a = __ldcw_align(x);
35: do {
36: int lock_val_old;
37:
38: lock_val_old = __ldcw(a);
39: arch_spin_val_check(lock_val_old);
40: if (lock_val_old)
41: return; /* got lock */
42:
43: /* wait until we should try to get lock again */
44: while (*a == 0)
45: continue;
46: } while (1);
47: }
48:
49: static inline void arch_spin_unlock(arch_spinlock_t *x)
50: {
51: volatile unsigned int *a;
52:
53: a = __ldcw_align(x);
54: /* Release with ordered store. */
55: __asm__ __volatile__("stw,ma %0,0(%1)"
56: : : "r"(__ARCH_SPIN_LOCK_UNLOCKED_VAL), "r"(a) : "memory");
57: }
58:
59: static inline int arch_spin_trylock(arch_spinlock_t *x)
60: {
61: volatile unsigned int *a;
62: int lock_val;
63:
64: a = __ldcw_align(x);
65: lock_val = __ldcw(a);
66: arch_spin_val_check(lock_val);
67: return lock_val != 0;
68: }
69:
]
|
| 62/2 |
2026/08/19 02:04 |
llm |
expert |
0m
Model:
Tokens:
input: 38294
output: 34
thoughts: 244
Thoughts: **PA-RISC Spinlock Deadlock Investigation**
Okay, so I'm thinking through this PA-RISC spinlock issue. It's becoming clear. On PA-RISC, the `__ldcw` instruction is the key to acquiring the lock. It's an atomic read-and-clear operation, perfect for the job. You read the old value, and if it was non-zero, bingo, you got the lock. If it was zero, someone else has it, and you're stuck waiting.
The problem, as I see it, is with how `kzalloc` initializes the memory. Because it sets the lock to zero initially, `arch_spin_lock` on PA-RISC will immediately see `lock_val_old == 0`. That means I'll get stuck right in that `while (*a == 0) continue;` loop! It's going to hang indefinitely. So, an uninitialized (zeroed) spinlock on PA-RISC is a guaranteed deadlock when someone tries to grab it. And if this happens in an interrupt handler? Boom! Denial of Service. That's a serious bug.
Wait, the more I think about it... does PA-RISC even support virtio? Let's see. Virtio is usually PCI-based or MMIO-based, right? PA-RISC *does* have PCI. Okay, so yes, PA-RISC *can* use virtio. That could be a problem.
Now, I'm already thinking about other architectures. This isn't PA-RISC specific... Let's check Alpha...
|
| 63/2 |
2026/08/19 02:04 |
tool |
grepper |
0m
Args: map[Expression:__ARCH_SPIN_LOCK_UNLOCKED PathPrefix:arch/alpha]
Results: map[Output:arch/alpha/include/asm/spinlock_types.h=9=typedef struct {
--
arch/alpha/include/asm/spinlock_types.h-12-
arch/alpha/include/asm/spinlock_types.h:13:#define __ARCH_SPIN_LOCK_UNLOCKED { 0 }
arch/alpha/include/asm/spinlock_types.h-14-
]
|
| 64/2 |
2026/08/19 02:04 |
llm |
expert |
0m
Model:
Tokens:
input: 39023
output: 34
thoughts: 10
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Initial Assessment: Variable Parameters**
Okay, so the initial state indicates Alpha is zero. That's a key starting point. But the situation is obviously more complex than just a static zero value. I need to understand the implications of this starting point in the context of the larger problem.
That's the baseline. The real question that immediately pops up is, what about ARM? Is ARM the variable I am actually interested in? Is it linked to the Alpha variable, or an orthogonal component? This isn't just a simple value; the immediate need is to understand the other variables at play. And most importantly, how do they interrelate? Let's assume that there is a relationship between these variables.
|
| 65/2 |
2026/08/19 02:04 |
tool |
grepper |
0m
Args: map[Expression:__ARCH_SPIN_LOCK_UNLOCKED PathPrefix:arch/arm]
Results: map[Output:arch/arm/common/mcpm_entry.c=175=EXPORT_SYMBOL_GPL(mcpm_is_available);
--
arch/arm/common/mcpm_entry.c-182- */
arch/arm/common/mcpm_entry.c:183:static arch_spinlock_t mcpm_lock = __ARCH_SPIN_LOCK_UNLOCKED;
arch/arm/common/mcpm_entry.c-184-
--
arch/arm/include/asm/spinlock_types.h=11=typedef struct {
--
arch/arm/include/asm/spinlock_types.h-25-
arch/arm/include/asm/spinlock_types.h:26:#define __ARCH_SPIN_LOCK_UNLOCKED { { 0 } }
arch/arm/include/asm/spinlock_types.h-27-
--
arch/arm/kernel/traps.c=272=static int __die(const char *str, int err, struct pt_regs *regs)
--
arch/arm/kernel/traps.c-302-
arch/arm/kernel/traps.c:303:static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
arch/arm/kernel/traps.c-304-static int die_owner = -1;
]
|
| 66/2 |
2026/08/19 02:04 |
llm |
expert |
0m
Model:
Tokens:
input: 39574
output: 36
thoughts: 12
Thoughts: Okay, here's my interpretation of those thoughts, tailored for an expert audience, presented in the first person:
**ARM Analysis**
Alright, the initial assessment is: ARM is at the baseline β zero. A good starting point, but a bit simplistic. It immediately prompts a question, of course, the ever-relevant and increasingly critical: What about ARM64? I can't just stop at a generic ARM classification. That's a huge oversight. The evolution and capabilities of 64-bit ARM architectures are where the real interest and performance benchmarks lie these days. Focusing only on "ARM" is like saying "CPU" β it's just not specific enough to be useful for any real analysis. I need to dig deeper into the 64-bit implications for any meaningful conclusion.
|
| 67/2 |
2026/08/19 02:05 |
tool |
grepper |
0m
Error:
Args: map[Expression:__ARCH_SPIN_LOCK_UNLOCKED PathPrefix:arch/arm64]
Results:
|
| 68/2 |
2026/08/19 02:05 |
llm |
expert |
0m
Model:
Tokens:
input: 39803
output: 35
thoughts: 14
Thoughts: Okay, here's my take on those quick thoughts, assuming I'm well-versed in system architecture and concurrency:
**Quick Concurrency Thoughts**
Alright, so the immediate thought that pops up when considering lock implementations is likely ARM64 and qspinlock. That seems like a pretty standard choice these days, given its performance characteristics. But then, as soon as that is solidifying in my mind, a tangential thought arises: what about PowerPC? I need to quickly recall the typical lock implementations on that architecture β are they similar, or do they lean towards something different, perhaps spinlock variants or something tailored to its specific memory model? It's easy to get caught in the ARM64 mindset since it's so pervasive, but I need to make sure I'm not overlooking architectural nuances. Need to do a quick mental review, if only to solidify my own recall.
|
| 69/2 |
2026/08/19 02:05 |
tool |
grepper |
0m
Args: map[Expression:__ARCH_SPIN_LOCK_UNLOCKED PathPrefix:arch/powerpc]
Results: map[Output:arch/powerpc/include/asm/qspinlock_types.h=8=typedef struct qspinlock {
--
arch/powerpc/include/asm/qspinlock_types.h-25-
arch/powerpc/include/asm/qspinlock_types.h:26:#define __ARCH_SPIN_LOCK_UNLOCKED { { .val = 0 } }
arch/powerpc/include/asm/qspinlock_types.h-27-
--
arch/powerpc/include/asm/simple_spinlock_types.h=9=typedef struct {
--
arch/powerpc/include/asm/simple_spinlock_types.h-12-
arch/powerpc/include/asm/simple_spinlock_types.h:13:#define __ARCH_SPIN_LOCK_UNLOCKED { 0 }
arch/powerpc/include/asm/simple_spinlock_types.h-14-
--
arch/powerpc/kernel/traps.c=142=bool die_will_crash(void)
--
arch/powerpc/kernel/traps.c-154-
arch/powerpc/kernel/traps.c:155:static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
arch/powerpc/kernel/traps.c-156-static int die_owner = -1;
]
|
| 70/2 |
2026/08/19 02:05 |
llm |
expert |
0m
Model:
Tokens:
input: 40375
output: 35
thoughts: 12
Thoughts: Okay, here's my interpretation of those thoughts, crafted with the understanding that I'm speaking to a fellow expert:
**Architecture Analysis: A Quick Mental Audit**
Okay, so we're starting with a baseline. PowerPC is essentially a non-factor in the current landscape. We've moved past that era. Given the context, I'm already mentally shifting gears, trying to quickly assess the relevant alternatives. My mind is already moving on to think about other CPU architectures that might be more relevant. Given that PowerPC is so little used, in any current environment, what about SPARC? Is that relevant in the current problem? This is a quick mental check β are there any lingering considerations I need to keep in mind, or can I safely dismiss it and move on?
|
| 71/2 |
2026/08/19 02:05 |
tool |
grepper |
0m
Args: map[Expression:__ARCH_SPIN_LOCK_UNLOCKED PathPrefix:arch/sparc]
Results: map[Output:arch/sparc/include/asm/spinlock_types.h=9=typedef struct {
--
arch/sparc/include/asm/spinlock_types.h-12-
arch/sparc/include/asm/spinlock_types.h:13:#define __ARCH_SPIN_LOCK_UNLOCKED { 0 }
arch/sparc/include/asm/spinlock_types.h-14-#endif /* CONFIG_QUEUED_SPINLOCKS */
]
|
| 72/2 |
2026/08/19 02:05 |
llm |
expert |
0m
Model:
Tokens:
input: 40706
output: 35
thoughts: 12
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Considering Instruction Set Architectures**
Okay, so SPARC is clearly irrelevant in this context β it's at a zero state. My mind immediately jumps to a comparison. Given where we are, what about MIPS? Is there any relevance to that? I need to quickly assess if there's any value in considering MIPS as a potential point of comparison or if it's equally outside the scope of the problem. Time to dig deeper into the problem's details...
|
| 73/2 |
2026/08/19 02:05 |
tool |
grepper |
0m
Args: map[Expression:__ARCH_SPIN_LOCK_UNLOCKED PathPrefix:arch/mips]
Results: map[Output:arch/mips/kernel/sync-r4k.c=31=static atomic_t test_runs;
--
arch/mips/kernel/sync-r4k.c-37- */
arch/mips/kernel/sync-r4k.c:38:static arch_spinlock_t sync_lock = __ARCH_SPIN_LOCK_UNLOCKED;
arch/mips/kernel/sync-r4k.c-39-
--
arch/mips/sgi-ip27/ip27-nmi.c=25=typedef unsigned long machreg_t;
arch/mips/sgi-ip27/ip27-nmi.c-26-
arch/mips/sgi-ip27/ip27-nmi.c:27:static arch_spinlock_t nmi_lock = __ARCH_SPIN_LOCK_UNLOCKED;
arch/mips/sgi-ip27/ip27-nmi.c-28-static void nmi_dump(void);
]
|
| 74/2 |
2026/08/19 02:05 |
llm |
expert |
0m
Model:
Tokens:
input: 41133
output: 23
thoughts: 1286
Thoughts: **Analyzing the virtio_balloon Lock Initialization and Potential Vulnerabilities**
Okay, let's break this down. First, it looks like `virtio_balloon` uses either a qspinlock or a ticket lock, probably initialized to 0. On most architectures, a zero-initialized spinlock is unlocked, which is what we expect. However, on PA-RISC, a zero-initialized spinlock is *locked*, which is a problem. This means it will hang there. Wait, I remember `virtio_balloon` is used in virtual machines. Does QEMU even support PA-RISC? Yes, I see 'qemu-system-hppa'. And it supports virtio via PCI. So, on PA-RISC, this is a definite hang, a Denial of Service. On other architectures, itβs just a lockdep warning, which could trigger a panic if `panic_on_warn` is set, but that's not the usual definition of DoS. But the PA-RISC hang is a real DoS, that is clear.
Now, wait, is there another issue? What if `spin_lock_init` gets called *while* the lock is held? On x86, it simply sets the lock to 0, which makes it unlocked. If the lock is held and then reinitialized, it becomes unlocked. If another thread tries to acquire it, it will succeed. But the critical section, specifically within the `start_wakeup_event` function, only holds the lock for a few instructions. This looks like a race condition:
```c
vb->wakeup_signal_mask |= mask;
if (!vb->processing_wakeup_event) {
vb->processing_wakeup_event = true;
pm_stay_awake(&vb->vdev->dev);
}
```
If two threads execute this at the same time, we could have a corrupted `vb->wakeup_signal_mask`. Bits could be lost. The `mask` is either `VIRTIO_BALLOON_WAKEUP_SIGNAL_STATS` or `VIRTIO_BALLOON_WAKEUP_SIGNAL_ADJUST`. If a bit is lost, the wakeup event might not be processed correctly, but this isn't a security issue, just a functional bug.
Okay, let's be thorough. Is there any other uninitialized lock? No, we checked all of them.
Now, can an unprivileged user trigger `virtio_balloon`? This bug is triggered by the hypervisor sending an interrupt to the guest. The guest kernel processes it and calls `stats_request`, which is automatic when the hypervisor requests stats. Can an unprivileged user *in the guest* trigger this? No, it's the hypervisor (host). However, a *malicious* hypervisor can trigger this. It could send the interrupt immediately after `virtqueue_kick(vb->stats_vq)` in `init_vqs`. This is exactly what syzkaller does, fuzzing the virtio device from the host side or the virtio ring. So, this is a "VM Guest Trigger". This is a bug in the guest kernel, triggered by the host (hypervisor). Now, can it be triggered from the host in a Confidential Computing context? Yes, if the guest is a confidential VM (e.g., AMD SEV or Intel TDX), the host is untrusted. A malicious host can trigger this. So "VM Host Trigger in The Confidential Computing Context" is True.
Wait, is this actually exploitable? On x86, it's just a lockdep warning. On PA-RISC, it's a hang (DoS). Is there any memory corruption? No. So, **Exploitable = False**. **DenialOfService = True** because of the PA-RISC hang, and even the lockdep warning could lead to a panic. But wait a minute, the prompt says lockdep warnings usually don't count unless they cause a crash or hang. In production, lockdep is disabled, so there won't be a lockdep warning. On x86, it'll just work fine. On PA-RISC, it will hang in `arch_spin_lock`. So, on PA-RISC, it's a hang in production. So, **DenialOfService = True**.
Finally, let's make sure there's no other way this is exploitable. What if `vb->wakeup_lock` isn't zero? `vb` is allocated with `kzalloc_obj(*vb)`, which uses `kzalloc`. So, it's guaranteed to be 0. What if `kzalloc` fails? It returns `-ENOMEM`, and the probe fails. So it's *always* 0
|
| 75/2 |
2026/08/19 02:05 |
tool |
codesearch-find-references |
0m
Args: map[Name:device_wakeup_enable]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:c67x00_hcd_probe SourceFile:drivers/usb/c67x00/c67x00-hcd.c SourceLine:373] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:cdns2_pci_probe SourceFile:drivers/usb/gadget/udc/cdns2/cdns2-pci.c SourceLine:79] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:device_init_wakeup SourceFile:include/linux/pm_wakeup.h SourceLine:238] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:device_set_wakeup_enable SourceFile:drivers/base/power/wakeup.c SourceLine:498] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:dwc2_hcd_init SourceFile:drivers/usb/dwc2/hcd.c SourceLine:5334] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:dwc3_gadget_start SourceFile:drivers/usb/dwc3/gadget.c SourceLine:3032] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:e1000_probe SourceFile:drivers/net/ethernet/intel/e1000e/netdev.c SourceLine:7672] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ehci_platform_probe SourceFile:drivers/usb/host/ehci-platform.c SourceLine:386] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:fsl_ehci_drv_probe SourceFile:drivers/usb/host/ehci-fsl.c SourceLine:143] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:isp116x_probe SourceFile:drivers/usb/host/isp116x-hcd.c SourceLine:1635] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:isp1760_hcd_register SourceFile:drivers/usb/isp1760/isp1760-hcd.c SourceLine:2602] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:musb_host_setup SourceFile:drivers/usb/musb/musb_host.c SourceLine:2749] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:nhi_probe SourceFile:drivers/thunderbolt/nhi.c SourceLine:1251] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:ohci_platform_probe SourceFile:drivers/usb/host/ohci-platform.c SourceLine:216] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:oxu_create SourceFile:drivers/usb/host/oxu210hp-hcd.c SourceLine:4138] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:pci_acpi_setup SourceFile:drivers/pci/pci-acpi.c SourceLine:1453] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:r8a66597_probe SourceFile:drivers/usb/host/r8a66597-hcd.c SourceLine:2494] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:sl811h_probe SourceFile:drivers/usb/host/sl811-hcd.c SourceLine:1715] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:usb_hcd_pci_probe SourceFile:drivers/usb/core/hcd-pci.c SourceLine:277] map[ReferenceKind:takes-address-of ReferencingEntityKind:global_variable ReferencingEntityName:__UNIQUE_ID_addressable_device_wakeup_enable_1225 SourceFile:drivers/base/power/wakeup.c SourceLine:346] map[ReferenceKind:takes-address-of ReferencingEntityKind:global_variable ReferencingEntityName:__gendwarfksyms_ptr_device_wakeup_enable SourceFile:drivers/base/power/wakeup.c SourceLine:346] map[ReferenceKind:takes-address-of ReferencingEntityKind:global_variable ReferencingEntityName:__gendwarfksyms_ptr_device_wakeup_enable SourceFile:drivers/base/power/wakeup.c SourceLine:346]] TruncatedOutput:false]
|
| 76/2 |
2026/08/19 02:05 |
llm |
expert |
0m
Model:
Tokens:
input: 44818
output: 40
thoughts: 72
Thoughts: **Examining Device Wakeup Capabilities**
Okay, hold on a second. I'm looking at this `virtballoon_probe` function and it's calling `device_set_wakeup_capable` on the `vdev->dev` structure, specifically setting it to `true`. My initial thought is, does this call actually allocate the `dev->power.wakeup` member? It's been a while since I looked at the specifics of how the power management framework handles these details. I need to be absolutely certain of the underlying behavior here, so let me just take a quick second and re-familiarize myself with what `device_set_wakeup_capable` does, exactly. It's crucial to understand if this call initiates allocation or assumes it already exists. This will have implications down the line. I'll need to re-examine the function and how it works to ensure no memory issues are lurking.
|
| 77/2 |
2026/08/19 02:05 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/base/power/wakeup.c Name:device_set_wakeup_capable]
Results: map[SourceCode: 459: /**
460: * device_set_wakeup_capable - Set/reset device wakeup capability flag.
461: * @dev: Device to handle.
462: * @capable: Whether or not @dev is capable of waking up the system from sleep.
463: *
464: * If @capable is set, set the @dev's power.can_wakeup flag and add its
465: * wakeup-related attributes to sysfs. Otherwise, unset the @dev's
466: * power.can_wakeup flag and remove its wakeup-related attributes from sysfs.
467: *
468: * This function may sleep and it can't be called from any context where
469: * sleeping is not allowed.
470: */
471: void device_set_wakeup_capable(struct device *dev, bool capable)
472: {
473: if (!!dev->power.can_wakeup == !!capable)
474: return;
475:
476: dev->power.can_wakeup = capable;
477: if (device_is_registered(dev) && !list_empty(&dev->power.entry)) {
478: if (capable) {
479: int ret = wakeup_sysfs_add(dev);
480:
481: if (ret)
482: dev_info(dev, "Wakeup sysfs attributes not added\n");
483: } else {
484: wakeup_sysfs_remove(dev);
485: }
486: }
487: }
SourceFile:drivers/base/power/wakeup.c]
|
| 78/2 |
2026/08/19 02:05 |
llm |
expert |
0m
Model:
Tokens:
input: 45604
output: 21
thoughts: 1063
Thoughts: **Analysis of the Potential Vulnerability**
Okay, let's break this down systematically. Initially, I was concerned about a potential NULL pointer dereference related to `dev->power.wakeup`. But it turns out that `dev->power.wakeup` is indeed NULL in the described scenario, and the checks within `__pm_stay_awake` prevent any such dereference. So, that's a non-issue. I also checked for a race condition between `device_set_wakeup_capable` and `pm_stay_awake`, but `device_set_wakeup_capable` only modifies `can_wakeup` and calls `wakeup_sysfs_add` - it doesn't touch `wakeup` pointer, so it's fine.
Now, let's get to the heart of the matter. This is a lockdep warning, arising because a spinlock is used before it is properly initialized with `spin_lock_init`. The spinlock itself is zero-initialized via `kzalloc`. On x86, this zero-initialization results in a valid, unlocked spinlock. However, on PA-RISC, a zero-initialized spinlock is considered *locked*. This causes the CPU to hang when someone tries to acquire the spinlock, resulting in a Denial of Service (DoS). The trigger for this DoS is the hypervisor (host) sending an interrupt to the guest. A malicious host in a Confidential Computing context could trigger this. Importantly, an unprivileged user within the guest cannot exploit this directly, nor can network traffic, peripheral devices, or malicious filesystems within the guest. This isn't exploitable for privilege escalation or information leakage.
I need to confirm the architecture issue is only PA-RISC. I'm double-checking if any other architectures might have the same behaviour. Ticket locks and qspinlocks, in general, are usually initialized with zero values for both ticket owner and next values. So it is very unlikely other architectures will present the same problem. This means PA-RISC's behavior is unique in this respect. That said, the PA-RISC hang is a real DoS, so we have to treat it seriously. Even the lockdep warning itself could trigger a panic if `panic_on_warn` is set, which is common in some environments. Still, we are evaluating for production builds, where this isn't usually the case, but the PA-RISC hang is a real concern in production.
Now, let's fill in the results.
* **Exploitable: False** - No privilege escalation or information leak.
* **DenialOfService: True (PA-RISC hang)** - The CPU will hang on PA-RISC systems.
* **Unprivileged: False** - Requires host-level action to trigger the issue.
* **UserNamespace: False** - The guest user cannot directly trigger this.
* **VMGuestTrigger: False** - This is where the nuance is.
* **VMHostTrigger: True** - Okay, this is the crucial part. "VM Guest Trigger" implies that the guest user triggers the issue, but, the prompt describes "Determine if the bug can be triggered from the context of a typical KVM guest (e.g., set up by a QEMU VMM). Consider accesses to standard Linux host paravirtualized features (virtio-blk, virtio-net, etc.), and handling of VM exits in the KVM code." This usually means that a vulnerability in the HOST can be triggered by the GUEST. But here the bug is in the GUEST kernel (`virtio_balloon` driver). The host triggers the issue. So this is exactly what the prompt means with "VMHostTrigger". "Determine if the bug can be triggered in a confidential computing guest kernel from the context of a KVM host. Consider access to standard Linux guest paravirtualized features (virtio-blk, virtio-net, etc.).".
* Now, `VMGuestTrigger`? No, because the guest user can't trigger the host to send the interrupt. The host decides when the interrupt happens. The guest *might* be able to write to a virtio balloon sysfs to trigger something? I need to check if there is any guest user trigger available.
So, the key takeaway is that while the bug is within the guest, it's triggered by host actions (interrupts in the context of confidential computing). This makes it a `VMHostTrigger`, not a `VMGuestTrigger`. The PA-RISC DoS is the main concern.
|
| 79/2 |
2026/08/19 02:05 |
tool |
codesearch-find-references |
0m
Args:
Results: map[References:[map[ReferenceKind:takes-address-of ReferencingEntityKind:function ReferencingEntityName:init_vqs SourceFile:drivers/virtio/virtio_balloon.c SourceLine:595]] TruncatedOutput:false]
|
| 80/2 |
2026/08/19 02:05 |
llm |
expert |
0m
Model:
Tokens:
input: 47731
output: 23
thoughts: 64
Thoughts: Here's my summary, as though I'm thinking through this process:
**Analyzing `stats_request` Triggering**
Okay, so `stats_request` is definitely tied to the virtqueue, that much is clear. And the virtqueue itself is *only* interrupted by the host. That's a key observation. The guest, the user code within the VM, has no direct mechanism to force the interrupt. That means, definitively, `VMGuestTrigger` has to be `False`. We're not dealing with a situation where the guest is independently triggering the stats update.
But, hold on. I need to be absolutely certain here. I need to be 100% sure I'm not missing something subtle. Is there *any* other possible path to call `start_wakeup_event`? Any hidden code path, edge case, or interaction I'm overlooking? This conclusion hinges on the assumption that the virtqueue interrupt is *the only* trigger, so I have to be exhaustive in my review. Need to double-check everything, just to make sure.
|
| 81/2 |
2026/08/19 02:05 |
tool |
codesearch-find-references |
0m
Args: map[Name:start_wakeup_event]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:start_update_balloon_size SourceFile:drivers/virtio/virtio_balloon.c SourceLine:513] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:stats_request SourceFile:drivers/virtio/virtio_balloon.c SourceLine:435]] TruncatedOutput:false]
|
| 82/2 |
2026/08/19 02:05 |
llm |
expert |
0m
Model:
Tokens:
input: 48173
output: 25
thoughts: 30
Thoughts: Here's my thinking process:
**Tracing the Origins of a Balloon Size Update**
Okay, so I see `start_update_balloon_size` triggers a `start_wakeup_event`. That makes sense; when the balloon size changes, something needs to wake up and respond. My immediate question, though, is *where* does this `start_update_balloon_size` call originate? It's the key to understanding the whole update sequence. I need to trace back from that function call. Who is responsible for initiating the balloon size update in the first place? Is it a timer? Is it a user action? Is it driven by resource constraints? Knowing the caller is absolutely crucial for debugging, performance analysis, or any future modifications to this system. This call graph is where I need to start my investigation.
|
| 83/2 |
2026/08/19 02:06 |
tool |
codesearch-find-references |
0m
Args: map[Name:start_update_balloon_size]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:virtballoon_changed SourceFile:drivers/virtio/virtio_balloon.c SourceLine:524]] TruncatedOutput:false]
|
| 84/2 |
2026/08/19 02:06 |
llm |
expert |
0m
Model:
Tokens:
input: 48471
output: 22
thoughts: 26
Thoughts: Here's my take on the situation:
**Investigating the Balloon Size Update Trigger**
Okay, so `virtballoon_changed` is the function that kicks off the process of updating the balloon size. My initial thought is, "Right, good, it's the trigger. But *what* is triggering *it*?" I need to understand the call graph β who's responsible for calling `virtballoon_changed`? I need to trace back from that function to identify the upstream events or conditions that initiate the balloon size update. Knowing this will give me the crucial context I need. This trace will tell me how the balloon size reacts to external events.
|
| 85/2 |
2026/08/19 02:06 |
tool |
codesearch-find-references |
0m
Args: map[Name:virtballoon_changed]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:virtballoon_probe SourceFile:drivers/virtio/virtio_balloon.c SourceLine:1060] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:virtballoon_restore SourceFile:drivers/virtio/virtio_balloon.c SourceLine:1149] map[ReferenceKind:takes-address-of ReferencingEntityKind:global_variable ReferencingEntityName:virtio_balloon_driver SourceFile:drivers/virtio/virtio_balloon.c SourceLine:1189]] TruncatedOutput:false]
|
| 86/2 |
2026/08/19 02:06 |
llm |
expert |
0m
Model:
Tokens:
input: 48844
output: 66
thoughts: 1016
Thoughts: **Analyzing the Virtio Balloon Driver Vulnerability**
Okay, so I'm looking at this `virtballoon_changed` function, and it seems like the key here is when it gets called. Initially, I thought it was purely a response to the host changing the balloon configuration. This makes sense; the host modifies something, and the guest reacts. But then I see that it's also called from within `virtballoon_probe`.
Specifically, it's called *after* `spin_lock_init(&vb->wakeup_lock)`. So, that call within `virtballoon_probe` is safe; the lock is initialized before it's used. The potential issue arises from the host-triggered interrupts. These interrupts, from before the lock is initialized, are the vulnerability. This implies a VMHostTrigger.
Now, let's break down the impact. I'm not seeing any memory corruption here, so the bug isn't exploitable in a classic sense. It is a Denial of Service though; a lockdep warning or even a complete hang on PA-RISC is a pretty significant issue. Since the bug depends on host-initiated actions, it's not user-space exploitable, and not user-namespace exploitable. It's triggered by the host (VMHostTrigger = True).
But wait... can a malicious PCI device trigger this? Virtio devices *can* be implemented in hardware. I mean, we've seen virtio-net, virtio-blk, and similar interfaces be hardware implementations. Now, virtio-balloon is normally a VM-specific thing, but a malicious PCIe device could spoof itself and claim to be a virtio-balloon device (Vendor ID 0x1AF4, Device ID 0x1002 or similar). The kernel would load `virtio_pci`, then `virtio_balloon`, and the device could immediately start sending interrupts.
The threat model says: "Determine if the bug can be triggered via an untrusted peripheral device that can be physically plugged into a system, such as a USB device or a niche hardware driver handling external hardware inputs. This is particularly important for mobile and desktop environments where users can plug in unknown devices." So, a malicious Thunderbolt or PCIe device is a definite possibility. It can definitely trigger this condition. So, PeripheralTrigger = True.
Let's confirm this by double-checking how the PCI binding works. `virtio_pci` happily binds to any PCI device with the virtio vendor ID, and if the device ID matches, `virtio_balloon` binds to it. This malicious device scenario is totally realistic.
So, the core issue is that `stats_request` is called before `spin_lock_init`. This `stats_request` calls `start_wakeup_event`, which calls `spin_lock_irqsave(&vb->wakeup_lock, flags)`. Now, because `vb` is `kzalloc`'d, `vb->wakeup_lock` is zero. On x86, it's an unlocked lock. But on PA-RISC, that's a *locked* lock, and boom, it hangs. This is a denial of service. The device (host *or* malicious peripheral) sends an interrupt too early. So, it's VMHostTrigger = True, and PeripheralTrigger = True. It's not exploitable for code execution.
Okay, let's move on to setting the results.
|
| 87/2 |
2026/08/19 02:06 |
tool |
set-results |
0m
Args: map[DenialOfService:true Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:true RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:true]
Results: map[DenialOfService:true Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:true RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:true]
|
| 88/2 |
2026/08/19 02:06 |
llm |
expert |
0m
Model:
Tokens:
input: 50720
output: 617
thoughts: 543
Thoughts: **My Analysis of the `virtio_balloon` Lockdep Warning**
Okay, the dust has settled, and the results are in. It's time to craft the final explanation. I've got a lockdep warning: "trying to register non-static key" deep inside the `start_wakeup_event` function within the `virtio_balloon` driver. This boils down to a classic initialization issue. Basically, I'm trying to use `spin_lock_irqsave(&vb->wakeup_lock, flags)` *before* the lock itself, `vb->wakeup_lock`, has been initialized by `spin_lock_init(&vb->wakeup_lock)`. That's a textbook race condition waiting to happen.
The trigger is interesting. During `virtballoon_probe`, I call `init_vqs` before properly initializing that lock. `init_vqs` primes the `stats_vq` and kicks the virtqueue, which notifies the hypervisor or device. If the device, eager as it is, immediately responds with an interrupt, boom, the interrupt handler, `vring_interrupt`, gets called. This then calls the callback, `stats_request`, which, in turn, calls `start_wakeup_event` and tries to acquire this uninitialized lock.
Now, let's talk about the exploitability, or lack thereof, in the typical case. Because the `virtio_balloon` struct is allocated with `kzalloc`, the uninitialized `wakeup_lock` ends up being filled with zeros. On most architectures I know β x86, ARM, PowerPC β a zero-initialized spinlock is perfectly valid and represents an unlocked state. Therefore, the lock operations will succeed without corrupting memory or causing an out-of-bounds access. So, no privilege escalation or information leakage is possible, at least on the architectures I'm used to.
However, the Denial of Service (DoS) angle is more alarming. On some architectures, PA-RISC for example, a zero-initialized spinlock is actually considered *locked*, and a spinlock is set at a value that is NOT zero. Attempting to acquire that zeroed lock will make the CPU spin indefinitely, resulting in a hard hang. That's a very effective DoS, potentially exacerbated on kernels with `panic_on_warn` enabled, because the lockdep warning itself could cause the system to crash.
Finally, the trigger vectors. This bug is fundamentally triggered by the host (hypervisor) sending an early interrupt. A malicious host can reliably trigger this against a Confidential VM guest. The same applies with a physical PCIe device β a malicious device, maybe plugged in via Thunderbolt, could spoof a virtio-balloon device and send that early interrupt. The good news is that, this isn't something unprivileged users or those within user namespaces can trigger. You need to control the virtio device's hardware or hypervisor responses to even touch it.
|
| 89/1 |
2026/08/19 02:06 |
action |
format-explanation |
0m
Results: map[Explanation:**Bug Analysis & Trigger Mechanism**
The bug is a lockdep warning (`INFO: trying to register non-static key`)
occurring in `start_wakeup_event()` within the `virtio_balloon` driver. This
happens because `spin_lock_irqsave(&vb->wakeup_lock, flags)` is called before
the lock has been initialized via `spin_lock_init()`.
During the device probe (`virtballoon_probe`), the driver calls `init_vqs()` to
initialize the virtqueues. For the statistics virtqueue (`stats_vq`), it primes
the queue with a buffer and immediately kicks it (`virtqueue_kick()`), notifying
the device (hypervisor). However, `spin_lock_init(&vb->wakeup_lock)` is called
*after* `init_vqs()`. If the device responds extremely quickly (or is malicious
and sends an interrupt immediately), the guest's interrupt handler will invoke
the `stats_request()` callback. This callback calls `start_wakeup_event()`,
which attempts to acquire the uninitialized `wakeup_lock`.
**Exploitability**
The `virtio_balloon` structure is allocated using `kzalloc`, meaning the
uninitialized `wakeup_lock` is filled with zeroes. On almost all major
architectures (x86, ARM, ARM64, PowerPC, etc.), a zero-initialized spinlock is
structurally valid and represents an *unlocked* state. Consequently, the lock
operations will succeed normally without causing memory corruption,
out-of-bounds accesses, or use-after-free conditions. The bug is purely a
functional race condition and is **not exploitable** for privilege escalation or
information leaks.
**Denial of Service**
While benign on most architectures, on PA-RISC, a zero-initialized spinlock is
considered *locked* (the unlocked value is `0x1a46`). Attempting to acquire a
zeroed lock on PA-RISC will cause the CPU to spin indefinitely, resulting in a
hard hang (Denial of Service). Furthermore, in environments where
`panic_on_warn` is enabled (common in fuzzing and some strict production
setups), the lockdep warning itself will crash the system.
**Trigger Vectors**
* **VM Host Trigger in Confidential Computing Context**: The bug resides in the
guest kernel and is triggered by the host (hypervisor) sending an early
interrupt. A malicious or compromised host can reliably trigger this against a
guest VM (including Confidential VMs like AMD SEV or Intel TDX).
* **Peripheral Trigger**: A malicious physical PCIe device (e.g., plugged in via
Thunderbolt) can spoof a virtio-balloon PCI device, bind to the driver, and send
the early interrupt to trigger the bug on the host machine.
* **Unprivileged / User Namespace**: The bug cannot be triggered by unprivileged
users or from within user namespaces, as it strictly requires controlling the
virtio device's hardware/hypervisor responses.]
|