Compare commits

...
Author SHA1 Message Date
YXC0915 bf0cce0e17 🐛 Update maintenance branch references [ci skip]
Keep automation and documentation aligned with the renamed branch.
The source pins and build steps stay the same.
2026-12-02 19:27:54 +08:00
YXC0915 84c33498ba runtime: enable native Windows disk AIO with the fixed QEMU 2026-12-02 00:05:46 +08:00
YXC0915 c95335699c 🆕 Ask Reims-Go to confirm Windows VM close requests
Forward managed Windows closes to the desktop client. Keep the SDL question available when the desktop instance cannot take the request.
2026-12-01 12:04:24 +08:00
YXC0915 edd66dcc12 🐛 Pin the Win32 direct-write retry fix 2026-12-01 11:57:57 +08:00
YXC0915 ff284bc497 chore: bump vendor/qemu for fast Win32 mapped-ram suspend I/O
Updates vendor/qemu to yxc0915/qemu-reims-vgpu@4c4757156a with ascending zero-page partitioning, Win32 64 KiB NTFS sparse write coalescing, and Win32 direct-io support.
2026-12-01 11:40:59 +08:00
10 changed files with 132 additions and 11 deletions

No files matched your search

+2 -2
View File
@@ -1,4 +1,4 @@
[submodule "vendor/qemu"]
path = vendor/qemu
url = https://github.com/yxc0915/qemu-reims-vgpu.git
branch = codex/intel-vm-suspend
url = https://github.com/reims-go/qemu-reims-vgpu.git
branch = intel-vm-suspend
+74 -6
View File
@@ -146,6 +146,8 @@ pub struct Ctx {
/// Whether QEMU takes `-smbios type=17`'s `memory_type`
/// ([`crate::install::smbios_takes_memory_type`]).
pub smbios_memory_type: bool,
/// Whether this Windows QEMU has the repaired native block AIO backend.
pub win32_native_aio: bool,
/// Whether QEMU's own window can open ([`crate::host::has_screen`]).
pub screen: bool,
/// The option ROM of reims-vgpu's own device, which its `romfile` names
@@ -195,14 +197,13 @@ pub fn opt(s: &str) -> String {
s.replace(',', ",,")
}
/// Compute the qcow2 L2 cache size in MiB needed to cover the full virtual disk
/// (`virtual_size / cluster_size * 8` bytes), clamped to `..=32 MiB`, returning `Some(mib)` only
/// when the image needs more than QEMU's 8 MiB non-Linux default.
/// Size the qcow2 L2 cache for the full disk, capped at 32 MiB, when it needs more
/// than QEMU's 8 MiB non-Linux default.
fn qcow2_l2_cache_mib(path: &Path) -> Option<u64> {
use std::io::Read;
let mut hdr = [0u8; 32];
let mut hdr = [0u8; 80];
let mut f = std::fs::File::open(path).ok()?;
f.read_exact(&mut hdr).ok()?;
f.read_exact(&mut hdr[..32]).ok()?;
if &hdr[0..4] != b"QFI\xfb" {
return None;
}
@@ -217,7 +218,15 @@ fn qcow2_l2_cache_mib(path: &Path) -> Option<u64> {
let virtual_size = u64::from_be_bytes(hdr[24..32].try_into().ok()?);
let cluster_size = 1u64 << cluster_bits;
let clusters = virtual_size.div_ceil(cluster_size);
let l2_bytes = clusters.saturating_mul(8);
let mut entry_bytes = 8;
if version == 3 {
f.read_exact(&mut hdr[32..]).ok()?;
let incompatible_features = u64::from_be_bytes(hdr[72..80].try_into().ok()?);
if incompatible_features & (1 << 4) != 0 {
entry_bytes = 16;
}
}
let l2_bytes = clusters.saturating_mul(entry_bytes);
let mib = l2_bytes.div_ceil(1024 * 1024).min(32);
(mib > 8).then_some(mib)
}
@@ -412,6 +421,14 @@ fn q35(vm: &Vm, ctx: &Ctx, a: &mut Vec<String>) -> Result<()> {
disk.push_str(&format!(",l2-cache-size={mib}M"));
}
}
if ctx.win32_native_aio
&& matches!(
q.disk_controller,
DiskController::Nvme | DiskController::Virtio
)
{
disk.push_str(",aio=native");
}
// An install's flushes, which the module's doc measures, are dropped while the installer is
// attached.
if q.installer.is_some() {
@@ -893,6 +910,7 @@ pub(crate) mod tests {
nested_vmx: false,
avx512_xstate: false,
smbios_memory_type: true,
win32_native_aio: false,
screen: true,
graphics_rom: "/d/firmware/ReimsGraphics-0123456789abcdef.rom".into(),
arm64: None,
@@ -1872,6 +1890,56 @@ pub(crate) mod tests {
));
}
#[test]
fn only_patched_windows_qemu_gets_native_aio_on_the_system_disk() {
let mut vm = q35_vm();
for controller in [
DiskController::Nvme,
DiskController::Virtio,
DiskController::Ahci,
] {
vm.config.q35.as_mut().unwrap().disk_controller = controller;
for supported in [false, true] {
let c = Ctx {
win32_native_aio: supported,
..ctx(Host {
os: Os::Windows,
..linux()
})
};
let args = invocation(&vm, &c).unwrap().args;
let disk = args.iter().find(|arg| arg.starts_with("id=disk,")).unwrap();
assert_eq!(
disk.split(',').any(|opt| opt == "aio=native"),
supported
&& matches!(controller, DiskController::Nvme | DiskController::Virtio),
);
assert!(args.iter().filter(|arg| arg.contains("aio=native")).count() <= 1);
assert!(!disk.contains("cache.no-flush"));
}
}
}
#[test]
fn extended_l2_uses_twice_the_cache_per_cluster() {
let path = std::env::temp_dir().join(format!(
"reims-ctl-extended-l2-{}.qcow2",
std::process::id()
));
let mut hdr = [0u8; 104];
hdr[..4].copy_from_slice(b"QFI\xfb");
hdr[4..8].copy_from_slice(&3u32.to_be_bytes());
hdr[20..24].copy_from_slice(&16u32.to_be_bytes());
hdr[24..32].copy_from_slice(&(128u64 << 30).to_be_bytes());
std::fs::write(&path, hdr).unwrap();
assert_eq!(qcow2_l2_cache_mib(&path), Some(16));
hdr[72..80].copy_from_slice(&(1u64 << 4).to_be_bytes());
std::fs::write(&path, hdr).unwrap();
let extended_size = qcow2_l2_cache_mib(&path);
std::fs::remove_file(path).unwrap();
assert_eq!(extended_size, Some(32));
}
#[test]
fn installer_disk_goes_on_its_own_port_through_an_overlay() {
let mut vm = q35_vm();
+12
View File
@@ -524,6 +524,7 @@ pub fn context(vm: &Vm, host: Host) -> Result<Ctx> {
};
let avx512_xstate = avx512_xstate(vm, host, &qemu);
let smbios_memory_type = smbios_memory_type(vm, &qemu);
let win32_native_aio = win32_native_aio(vm, host, &qemu);
Ok(Ctx {
host,
qemu,
@@ -532,6 +533,7 @@ pub fn context(vm: &Vm, host: Host) -> Result<Ctx> {
nested_vmx: crate::host::kvm_nested_vmx(),
avx512_xstate,
smbios_memory_type,
win32_native_aio,
screen,
graphics_rom: graphics_rom(vm)?,
arm64,
@@ -556,6 +558,14 @@ fn smbios_memory_type(vm: &Vm, qemu: &Path) -> bool {
vm.config.profile == Profile::Q35X86_64 && crate::install::smbios_takes_memory_type(qemu)
}
/// A version number alone does not distinguish the fixed Windows block backend.
fn win32_native_aio(vm: &Vm, host: Host, qemu: &Path) -> bool {
host.os == Os::Windows
&& vm.config.profile == Profile::Q35X86_64
&& crate::install::qemu_version(qemu)
.is_some_and(|version| version.ends_with(" [reims-win32-native-aio]"))
}
/// The option ROM of reims-vgpu's own device, written into the data directory for an x86-64 VM
/// on it ([`crate::prebuilt::graphics_rom`]); an empty path, which no command names, for another
/// VM. An arm64 VM's device has no option ROM: Ambrosia drives it with its module.
@@ -609,6 +619,7 @@ pub fn invocation_for_print(vm: &Vm, host: Host) -> Result<Invocation> {
let qemu = crate::install::qemu_binary_or_default(vm.config.profile);
let avx512_xstate = avx512_xstate(vm, host, &qemu);
let smbios_memory_type = smbios_memory_type(vm, &qemu);
let win32_native_aio = win32_native_aio(vm, host, &qemu);
Ctx {
host,
qemu,
@@ -617,6 +628,7 @@ pub fn invocation_for_print(vm: &Vm, host: Host) -> Result<Invocation> {
nested_vmx: crate::host::kvm_nested_vmx(),
avx512_xstate,
smbios_memory_type,
win32_native_aio,
screen: crate::host::has_screen(&vm.config.extra_env),
graphics_rom: graphics_rom(vm).unwrap_or_else(|_| crate::prebuilt::graphics_rom_path()),
arm64: (vm.config.profile == Profile::VmappleArm64).then(|| qemu::Arm64Boot {
+1
View File
@@ -31,6 +31,7 @@ libc.workspace = true
windows-sys = { workspace = true, features = [
"Win32_Foundation",
"Win32_System_Com",
"Win32_System_Threading",
"Win32_UI_Shell",
] }
+4 -2
View File
@@ -743,8 +743,10 @@ runtime's own device. The switches above apply, and `resolution=` too.
the host's arrow shows over the window, and a minimized window is
restored and raised. Where the window draws no more (its GPU lost, or no
swapchain), the question shows in SDL's message box instead: zenity's
where zenity is installed, else SDL's own X11 dialog. On Windows a task
dialog the window owns, Turn Off left of Cancel. Turn Off asks the host
where zenity is installed, else SDL's own X11 dialog. On Windows,
Reims-Go can handle the close in its own dialog with Shut down, Suspend
and Cancel. When the client handoff fails, SDL shows a task dialog the
window owns, Turn Off left of Cancel. Turn Off asks the host
to end the VM; Cancel, or the question dismissed, leaves the window and
the VM running, nothing held in the guest and the input released. From
the close to the answer nothing of the window's input reaches the guest:
+15
View File
@@ -4,6 +4,8 @@
//! shutdown request with the power-off action, which the guest is not asked about). So the window
//! asks first, in a question of the host OS's own over the window ([`QUESTION`], [`DETAIL`]), with
//! two answers: [`CANCEL`], the default, keeps the VM running, and [`TURN_OFF`] tells the host.
//! A Windows VM started by Reims-Go can hand the question to its client
//! instead. The client then handles the chosen action.
//!
//! **When it asks** ([`Asks::request`]): only where the host would hear of the close, while the
//! window lives (the display's release takes the host's callbacks back) and the host gave a close
@@ -55,6 +57,9 @@ pub(crate) enum Answer {
Cancel,
/// No question could show: nothing happens, as for Cancel, and the OS's side logs why.
Unshown,
/// Reims-Go's dialog handles the close.
#[cfg(target_os = "windows")]
Delegated,
}
/// The process's questions: whether one is open, and whether the person has chosen Turn Off.
@@ -108,6 +113,8 @@ pub(crate) fn answered(answer: Answer) -> bool {
Answer::TurnOff => "the person chose Turn Off: the host turns the VM off",
Answer::Cancel => "the close is cancelled, or its window ended: the host is not told",
Answer::Unshown => "no question showed: the host is not told, and the VM runs on",
#[cfg(target_os = "windows")]
Answer::Delegated => "the close question was handed to Reims-Go",
};
log::info!(target: "reims_vgpu_window", "{said}");
tell
@@ -144,5 +151,13 @@ mod tests {
assert_eq!(unshown.request(true), Step::Ask);
assert!(!unshown.answered(Answer::Unshown));
assert_eq!(unshown.request(true), Step::Ask);
#[cfg(target_os = "windows")]
{
let mut delegated = Asks::default();
assert_eq!(delegated.request(true), Step::Ask);
assert!(!delegated.answered(Answer::Delegated));
assert_eq!(delegated.request(true), Step::Ask);
}
}
}
@@ -657,6 +657,8 @@ fn ask_in_a_dialog(id: u64, ids: Vec<u64>) {
super::ui::post(move || {
let parent = shell::with_shell(id, |s| (!s.closed).then_some(s.sdl)).flatten();
let answer = match parent {
#[cfg(target_os = "windows")]
Some(_) if super::super::windows::request_client_close() => Answer::Delegated,
Some(parent) => question(parent),
None => Answer::Cancel,
};
@@ -46,6 +46,8 @@ use std::cell::Cell;
use std::ffi::c_void;
use std::io::Write;
use std::net::{SocketAddr, TcpStream};
use std::os::windows::process::CommandExt;
use std::process::Command;
use std::ptr::{NonNull, null, null_mut};
use std::sync::OnceLock;
use std::sync::mpsc::{self, RecvTimeoutError, SyncSender};
@@ -61,6 +63,7 @@ use windows_sys::Win32::System::Com::{
CLSCTX_INPROC_SERVER, COINIT_APARTMENTTHREADED, CoCreateInstance, CoInitializeEx,
CoUninitialize,
};
use windows_sys::Win32::System::Threading::CREATE_NO_WINDOW;
use windows_sys::Win32::UI::Shell::TaskbarList;
use windows_sys::core::{BOOL, GUID, HRESULT};
@@ -69,6 +72,22 @@ use crate::capture::HostOs;
/// The OS whose names the title gives the release chord's keys: Ctrl+Alt+Win (the module doc).
pub(super) const HOST_OS: HostOs = HostOs::Windows;
/// Asks the Reims-Go desktop instance that started this VM to show its
/// close dialog. A failed handoff leaves the SDL dialog available.
pub(super) fn request_client_close() -> bool {
let Some(executable) = std::env::var_os("REIMS_GO_VM_CLOSE_EXE") else {
return false;
};
let Ok(name) = std::env::var("REIMS_GO_VM_CLOSE_NAME") else {
return false;
};
Command::new(executable)
.arg(format!("--close-vm={name}"))
.creation_flags(CREATE_NO_WINDOW)
.status()
.is_ok_and(|status| status.success())
}
/// Win32 MSG layout matching winuser.h for SDL_SetWindowsMessageHook.
#[repr(C)]
struct Win32Msg {
+2
View File
@@ -1,11 +1,13 @@
{
"capabilities": [
"client-window-close",
"display-fixed-mode",
"nested-virt-nonfatal",
"vm-suspend",
"win10-compat",
"win10-startup-ipis",
"win32-coroutine-fiber",
"win32-native-aio",
"win32-unicode-input"
]
}
Vendored
+1 -1
Submodule vendor/qemu updated: c67660108a...51e8c2d3b5.