Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bf0cce0e17 | ||
|
|
84c33498ba |
No files matched your search
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
[submodule "vendor/qemu"]
|
[submodule "vendor/qemu"]
|
||||||
path = vendor/qemu
|
path = vendor/qemu
|
||||||
url = https://github.com/yxc0915/qemu-reims-vgpu.git
|
url = https://github.com/reims-go/qemu-reims-vgpu.git
|
||||||
branch = codex/intel-vm-suspend
|
branch = intel-vm-suspend
|
||||||
@@ -146,6 +146,8 @@ pub struct Ctx {
|
|||||||
/// Whether QEMU takes `-smbios type=17`'s `memory_type`
|
/// Whether QEMU takes `-smbios type=17`'s `memory_type`
|
||||||
/// ([`crate::install::smbios_takes_memory_type`]).
|
/// ([`crate::install::smbios_takes_memory_type`]).
|
||||||
pub smbios_memory_type: bool,
|
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`]).
|
/// Whether QEMU's own window can open ([`crate::host::has_screen`]).
|
||||||
pub screen: bool,
|
pub screen: bool,
|
||||||
/// The option ROM of reims-vgpu's own device, which its `romfile` names
|
/// 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(',', ",,")
|
s.replace(',', ",,")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compute the qcow2 L2 cache size in MiB needed to cover the full virtual disk
|
/// Size the qcow2 L2 cache for the full disk, capped at 32 MiB, when it needs more
|
||||||
/// (`virtual_size / cluster_size * 8` bytes), clamped to `..=32 MiB`, returning `Some(mib)` only
|
/// than QEMU's 8 MiB non-Linux default.
|
||||||
/// when the image needs more than QEMU's 8 MiB non-Linux default.
|
|
||||||
fn qcow2_l2_cache_mib(path: &Path) -> Option<u64> {
|
fn qcow2_l2_cache_mib(path: &Path) -> Option<u64> {
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
let mut hdr = [0u8; 32];
|
let mut hdr = [0u8; 80];
|
||||||
let mut f = std::fs::File::open(path).ok()?;
|
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" {
|
if &hdr[0..4] != b"QFI\xfb" {
|
||||||
return None;
|
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 virtual_size = u64::from_be_bytes(hdr[24..32].try_into().ok()?);
|
||||||
let cluster_size = 1u64 << cluster_bits;
|
let cluster_size = 1u64 << cluster_bits;
|
||||||
let clusters = virtual_size.div_ceil(cluster_size);
|
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);
|
let mib = l2_bytes.div_ceil(1024 * 1024).min(32);
|
||||||
(mib > 8).then_some(mib)
|
(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"));
|
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
|
// An install's flushes, which the module's doc measures, are dropped while the installer is
|
||||||
// attached.
|
// attached.
|
||||||
if q.installer.is_some() {
|
if q.installer.is_some() {
|
||||||
@@ -893,6 +910,7 @@ pub(crate) mod tests {
|
|||||||
nested_vmx: false,
|
nested_vmx: false,
|
||||||
avx512_xstate: false,
|
avx512_xstate: false,
|
||||||
smbios_memory_type: true,
|
smbios_memory_type: true,
|
||||||
|
win32_native_aio: false,
|
||||||
screen: true,
|
screen: true,
|
||||||
graphics_rom: "/d/firmware/ReimsGraphics-0123456789abcdef.rom".into(),
|
graphics_rom: "/d/firmware/ReimsGraphics-0123456789abcdef.rom".into(),
|
||||||
arm64: None,
|
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]
|
#[test]
|
||||||
fn installer_disk_goes_on_its_own_port_through_an_overlay() {
|
fn installer_disk_goes_on_its_own_port_through_an_overlay() {
|
||||||
let mut vm = q35_vm();
|
let mut vm = q35_vm();
|
||||||
|
|||||||
@@ -524,6 +524,7 @@ pub fn context(vm: &Vm, host: Host) -> Result<Ctx> {
|
|||||||
};
|
};
|
||||||
let avx512_xstate = avx512_xstate(vm, host, &qemu);
|
let avx512_xstate = avx512_xstate(vm, host, &qemu);
|
||||||
let smbios_memory_type = smbios_memory_type(vm, &qemu);
|
let smbios_memory_type = smbios_memory_type(vm, &qemu);
|
||||||
|
let win32_native_aio = win32_native_aio(vm, host, &qemu);
|
||||||
Ok(Ctx {
|
Ok(Ctx {
|
||||||
host,
|
host,
|
||||||
qemu,
|
qemu,
|
||||||
@@ -532,6 +533,7 @@ pub fn context(vm: &Vm, host: Host) -> Result<Ctx> {
|
|||||||
nested_vmx: crate::host::kvm_nested_vmx(),
|
nested_vmx: crate::host::kvm_nested_vmx(),
|
||||||
avx512_xstate,
|
avx512_xstate,
|
||||||
smbios_memory_type,
|
smbios_memory_type,
|
||||||
|
win32_native_aio,
|
||||||
screen,
|
screen,
|
||||||
graphics_rom: graphics_rom(vm)?,
|
graphics_rom: graphics_rom(vm)?,
|
||||||
arm64,
|
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)
|
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
|
/// 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
|
/// 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.
|
/// 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 qemu = crate::install::qemu_binary_or_default(vm.config.profile);
|
||||||
let avx512_xstate = avx512_xstate(vm, host, &qemu);
|
let avx512_xstate = avx512_xstate(vm, host, &qemu);
|
||||||
let smbios_memory_type = smbios_memory_type(vm, &qemu);
|
let smbios_memory_type = smbios_memory_type(vm, &qemu);
|
||||||
|
let win32_native_aio = win32_native_aio(vm, host, &qemu);
|
||||||
Ctx {
|
Ctx {
|
||||||
host,
|
host,
|
||||||
qemu,
|
qemu,
|
||||||
@@ -617,6 +628,7 @@ pub fn invocation_for_print(vm: &Vm, host: Host) -> Result<Invocation> {
|
|||||||
nested_vmx: crate::host::kvm_nested_vmx(),
|
nested_vmx: crate::host::kvm_nested_vmx(),
|
||||||
avx512_xstate,
|
avx512_xstate,
|
||||||
smbios_memory_type,
|
smbios_memory_type,
|
||||||
|
win32_native_aio,
|
||||||
screen: crate::host::has_screen(&vm.config.extra_env),
|
screen: crate::host::has_screen(&vm.config.extra_env),
|
||||||
graphics_rom: graphics_rom(vm).unwrap_or_else(|_| crate::prebuilt::graphics_rom_path()),
|
graphics_rom: graphics_rom(vm).unwrap_or_else(|_| crate::prebuilt::graphics_rom_path()),
|
||||||
arm64: (vm.config.profile == Profile::VmappleArm64).then(|| qemu::Arm64Boot {
|
arm64: (vm.config.profile == Profile::VmappleArm64).then(|| qemu::Arm64Boot {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
"win10-compat",
|
"win10-compat",
|
||||||
"win10-startup-ipis",
|
"win10-startup-ipis",
|
||||||
"win32-coroutine-fiber",
|
"win32-coroutine-fiber",
|
||||||
|
"win32-native-aio",
|
||||||
"win32-unicode-input"
|
"win32-unicode-input"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
Vendored
+1
-1
Submodule vendor/qemu updated: fa8e2e4b9e...51e8c2d3b5.
Reference in new issue
Block a user