Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,5 @@ git diff --stat ORIG_HEAD -- src/versions.env src/patches # anything here: reb
./macbox backup before-xcode-27 # a copy of the disk (instant on XFS/Btrfs reflinks), the VM stopped
./macbox build && ./macbox down && ./macbox up # a newer build
```

The VM configuration enables QEMU's `usb-kbd.x-ignore-idle` property to avoid unchanged keyboard reports at idle. Before rolling back to a QEMU build without patch 0015, remove `-global usb-kbd.x-ignore-idle=on` from the VM configuration (`vm.toml`) and from the scripts that regenerate it; older builds cannot start with that flag.
2 changes: 2 additions & 0 deletions macbox
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ qemu_extra() { # the network (passt, SSH forwarded by Docker) and the disk's op
-set "drive.disk.cache=$MACBOX_DISK_CACHE" -set drive.disk.discard=unmap; do
out+=("$(printf '%q' "$a")")
done
# QEMU 0015: do not send unchanged keyboard reports at idle.
out+=(-global usb-kbd.x-ignore-idle=on)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Gate the keyboard property on QEMU support

When using macbox build --upstream or switching qemu/current to a pre-0015 build, this unconditional argument prevents the VM from starting: as the added docs/setup.md warning states, “older builds cannot start with that flag.” The upstream branch of src/container/build-reims.sh explicitly skips the patches, while cmd_up() rewrites --extra-args using qemu_extra() before every stopped-VM start, so removing the argument from vm.toml does not resolve it. This also breaks the documented rollback-by-symlink procedure unless users edit the launcher itself. Check the selected QEMU's capabilities before adding the property so upstream builds and rollback remain usable.

AGENTS.md reference: AGENTS.md:L108-L110

Useful? React with 👍 / 👎.

# Reims's VideoToolbox and M2 scaler devices, in the slots reims-ctl gives them (after the mapper)
[ "$MACBOX_VIDEO" = on ] && out+=(-device apple-videotoolbox-pci,id=video,bus=pcie.0,addr=0x8 \
-device apple-m2scaler-pci,id=scaler,bus=pcie.0,addr=0x9)
Expand Down
3 changes: 2 additions & 1 deletion src/patches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,15 @@ is in [docs/performance.md](../../docs/performance.md#gpu-tuning-switches).
| 0034, 0035 the detach check | Every submission is checked, on metal2vulkan's scheduler thread, against the objects detached now. That list is now made once per change (a detach, an attach or a release), sorted, and asked by binary search (metal2vulkan 0100). Before, it was made again for every check and scanned: 18–24% of that thread's time. On by default. Live `detached_sorted=0` brings back the check as before, for an A/B in one boot. Measured: 1 simulator +3.5%, 3 simulators +5.3% ([performance.md](../../docs/performance.md#several-simulators-at-once-and-the-desktop-under-load)). |
| 0036 `REIMS_VGPU_WINDOW_COMPOSITOR_FILE` | the windows move to another Wayland compositor while the VM runs: the file names the socket. Reims connects to it itself and hands SDL the connection; when the file changes, each window lets its input go, its render thread lets the swapchain and surface go, SDL's video restarts on the new socket, and the windows open there. On failure they go back. `<file>.on` says where they are. Off unless set; `MACBOX_VIEW_SWITCH=on` sets it. |

## QEMU (`vendor/qemu` at bd95509, github.com/steelbrain/qemu-reims-vgpu), 14 patches
## QEMU (`vendor/qemu` at bd95509, github.com/steelbrain/qemu-reims-vgpu), 15 patches

| Patches | What they do |
|---|---|
| 0001–0003, 0006–0009 the census | memslots move to a second mapping of guest RAM that only KVM uses, and userfaultfd markers there report the guest CPU's touches of tracked pages (`UFFD_USER_MODE_ONLY`: no capability or `/dev/userfaultfd` needed). QEMU's own loads, stores and DMA reach it too. Off unless `REIMS_VGPU_CENSUS` is set. |
| 0004, 0005 coherent pages | with `REIMS_VGPU_COHERENT=1` the same markers serve metal2vulkan's trap-coherent surfaces. A run that doesn't end well leaves `coherent.running` in the census directory, and every later start boots without coherent pages until it's removed (`macbox coherent reset`), so a fault there costs one crash, not a crash loop. |
| 0010–0013 KVM shortcuts for the GPU device | `x-irqfd` (interrupts through a KVM irqfd), `x-halt-poll-ns`, `x-ioeventfd` (doorbells through KVM ioeventfds): device properties, all off unless set |
| 0014 the video devices | upstream's own 4895365e5b (on `steelbrain/reims-vgpu`, after bd95509), unchanged: `apple-videotoolbox-pci` (106b:1a03) and `apple-m2scaler-pci` (106b:1a0b), the transports of Reims's VideoToolbox and scaler devices. Without it the build can't attach them. Drop it when `QEMU_REF` moves past 4895365e5b. The devices stay detached unless `MACBOX_VIDEO=on` |
| 0015 `x-ignore-idle` | usb-kbd can ignore the guest's idle timer and send reports only on key changes. The property defaults to off; macbox enables it with `-global usb-kbd.x-ignore-idle=on`. |

## Licenses

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: macbox <macbox>
Date: Sun, 15 Nov 2026 01:20:04 +0200
Subject: [PATCH 15/15] usb-kbd: x-ignore-idle, an idle keyboard reports only on key
changes

Allow usb-kbd to ignore the HID idle timer while preserving the idle value
reported to the guest. The property defaults to off and can be changed live.
The guest idle value is reset on device reset and is not migrated.

---
hw/usb/dev-hid.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 54 insertions(+), 1 deletion(-)

diff --git a/hw/usb/dev-hid.c b/hw/usb/dev-hid.c
index ae19d60203..1d0e36d405 100644
--- a/hw/usb/dev-hid.c
+++ b/hw/usb/dev-hid.c
@@ -43,6 +43,19 @@ struct USBHIDState {
uint32_t usb_version;
char *display;
uint32_t head;
+ /*
+ * x-ignore-idle (usb-kbd only, off by default). macOS sets
+ * the keyboard's idle rate to 24 ms, so an idle keyboard sends a report
+ * every 24 ms (41.6/s: 2026-11-15, QEMU's usb_xhci_xfer_success trace)
+ * and the guest's HID driver wakes for each. With it on, SET_IDLE is
+ * accepted and GET_IDLE answers it, but the keyboard reports only when
+ * a key changes, as it does at idle rate 0. macOS repeats held keys
+ * itself. Live: qom-set turns it on or off in a running VM (an A/B in
+ * one boot); -global usb-kbd.x-ignore-idle=on sets it at start. Not
+ * migrated.
+ */
+ bool ignore_idle;
+ uint8_t guest_idle;
};

#define TYPE_USB_HID "usb-hid"
@@ -570,6 +583,7 @@ static void usb_hid_handle_reset(USBDevice *dev)
USBHIDState *us = USB_HID(dev);

hid_reset(&us->hid);
+ us->guest_idle = 0;
}

static void usb_hid_handle_control(USBDevice *dev, USBPacket *p,
@@ -635,10 +649,14 @@ static void usb_hid_handle_control(USBDevice *dev, USBPacket *p,
hs->protocol = value;
break;
case HID_GET_IDLE:
- data[0] = hs->idle;
+ data[0] = us->ignore_idle ? us->guest_idle : hs->idle;
p->actual_length = 1;
break;
case HID_SET_IDLE:
+ if (us->ignore_idle) {
+ us->guest_idle = (uint8_t) (value >> 8);
+ break;
+ }
hs->idle = (uint8_t) (value >> 8);
hid_set_next_idle(hs);
if (hs->kind == HID_MOUSE || hs->kind == HID_TABLET) {
@@ -844,6 +862,35 @@ static const Property usb_keyboard_properties[] = {
DEFINE_PROP_STRING("display", USBHIDState, display),
};

+static bool usb_kbd_get_ignore_idle(Object *obj, Error **errp)
+{
+ return USB_HID(obj)->ignore_idle;
+}
+
+/*
+ * On: the idle rate the guest set is kept aside and the keyboard's is 0, so
+ * its timer goes. Off: the guest's rate is the keyboard's again.
+ */
+static void usb_kbd_set_ignore_idle(Object *obj, bool value, Error **errp)
+{
+ USBHIDState *us = USB_HID(obj);
+ HIDState *hs = &us->hid;
+
+ if (value == us->ignore_idle) {
+ return;
+ }
+ if (value) {
+ us->guest_idle = hs->idle;
+ hs->idle = 0;
+ } else {
+ hs->idle = us->guest_idle;
+ }
+ us->ignore_idle = value;
+ if (hs->event) {
+ hid_set_next_idle(hs);
+ }
+}
+
static void usb_keyboard_class_initfn(ObjectClass *klass, const void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
@@ -853,6 +900,12 @@ static void usb_keyboard_class_initfn(ObjectClass *klass, const void *data)
uc->product_desc = "QEMU USB Keyboard";
dc->vmsd = &vmstate_usb_kbd;
device_class_set_props(dc, usb_keyboard_properties);
+ object_class_property_add_bool(klass, "x-ignore-idle",
+ usb_kbd_get_ignore_idle,
+ usb_kbd_set_ignore_idle);
+ object_class_property_set_description(klass, "x-ignore-idle",
+ "Report only on key changes, whatever idle rate the "
+ "guest sets (live)");
set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
}

--
2.53.0

Loading