Skip to contentSkip to conversation

i386 (TCG, TDX), Rust changes for 2025-06-20

GIT PULL Paolo Bonzini 5 participants 36 messages Jun 20, 2025 – Jun 24, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

The following changes since commit a6f02277595136832c9e9bcaf447ab574f7b1128:

Merge tag 'block-pull-request' of https://gitlab.com/stefanha/qemu into staging (2025-06-12 14:16:11 -0400)

are available in the Git repository at:

https://gitlab.com/bonzini/qemu.git tags/for-upstream

for you to fetch changes up to 40da501d8989913935660dc24953ece02c9e98b8:

i386/tdx: handle TDG.VP.VMCALL<GetQuote> (2025-06-20 13:25:59 +0200)

----------------------------------------------------------------
* cleanups for distributed DTB files
* scripts/meson-buildoptions: Sort coroutine_backend choices lexicographically
* rust/qemu-api: Add initial logging support
: rust: pl011: Implement logging
* target/i386: fix Win98
* meson: cleanup win32 library detection
* rust: safe(r) instance_init
* rust: prepare for multiple bindgen invocations
* rust: fix new warning
* target/i386: Warn about why CPUID_EXT_PDCM is not available
* target/i386: small TDX fixes and clarifications
* target/i386: support for TDX quote generation

----------------------------------------------------------------
Bernhard Beschow (5):
hw: Fix type constant for DTB files pc-bios/dtb/meson: Prefer target name to be outfile, not infile rust/qemu-api: Add initial logging support based on C API
rust: pl011: Implement logging
rust: pl011: Add missing logging to match C version

Binbin Wu (1):
i386/tdx: handle TDG.VP.VMCALL<GetTdVmCallInfo>

Isaku Yamahata (1):
i386/tdx: handle TDG.VP.VMCALL<GetQuote>

Mark Cave-Ayland (1):
target/i386: fix TB exit logic in gen_movl_seg() when writing to SS

Paolo Bonzini (10):
meson: cleanup win32 library detection
rust: qemu_api: introduce MaybeUninit field projection
rust: hpet: fully initialize object during instance_init
rust: qom: introduce ParentInit
rust: qom: make ParentInit lifetime-invariant
rust: qom: change instance_init to take a ParentInit<>
rust: prepare variable definitions for multiple bindgen invocations
rust: move rust.bindgen to qemu-api crate
rust: hpet: fix new warning
update Linux headers to v6.16-rc3

Xiaoyao Li (6):
i386/cpu: Move adjustment of CPUID_EXT_PDCM before feature_dependencies[] check i386/cpu: Warn about why CPUID_EXT_PDCM is not available i386/tdx: Error and exit when named cpu model is requested i386/cpu: Rename enable_cpuid_0x1f to force_cpuid_0x1f
i386/tdx: Fix the typo of the comment of struct TdxGuest i386/tdx: Clarify the error message of mrconfigid/mrowner/mrownerconfig

 docs/devel/rust.rst                                |   1 +
 meson.build                                        |  65 +----
 qapi/qom.json                                      |   8 +-
 include/standard-headers/asm-x86/setup_data.h      |  13 +-
 include/standard-headers/drm/drm_fourcc.h          |  45 ++++
 include/standard-headers/linux/ethtool.h           | 124 ++++-----
 include/standard-headers/linux/fuse.h              |   6 +-
 include/standard-headers/linux/input-event-codes.h |   3 +-
 include/standard-headers/linux/pci_regs.h          |  12 +-
 include/standard-headers/linux/virtio_gpu.h        |   3 +-
 include/standard-headers/linux/virtio_pci.h        |   1 +
 linux-headers/asm-arm64/kvm.h                      |   9 +-
 linux-headers/asm-x86/kvm.h                        |   1 +
 linux-headers/linux/bits.h                         |   4 +-
 linux-headers/linux/kvm.h                          |  25 ++
 linux-headers/linux/vhost.h                        |   4 +-
 rust/{ => qemu-api}/wrapper.h                      |   2 +
 target/i386/cpu.h                                  |   4 +-
 target/i386/kvm/tdx-quote-generator.h              |  82 ++++++
 target/i386/kvm/tdx.h                              |  25 +-
 hw/arm/boot.c                                      |   2 +-
 hw/ppc/e500.c                                      |   2 +-
 target/i386/cpu.c                                  |  10 +-
 target/i386/kvm/kvm.c                              |  15 ++
 target/i386/kvm/tdx-quote-generator.c              | 300 +++++++++++++++++++++
 target/i386/kvm/tdx-stub.c                         |   8 +
 target/i386/kvm/tdx.c                              | 206 +++++++++++++-
 target/i386/tcg/translate.c                        |   7 +-
 pc-bios/dtb/meson.build                            |   2 +-
 rust/hw/char/pl011/src/device.rs                   |  52 ++--
 rust/hw/timer/hpet/src/device.rs                   |  58 ++--
 rust/meson.build                                   |   4 +-
 rust/qemu-api/build.rs                             |   2 +-
 rust/qemu-api/meson.build                          |  45 +++-
 rust/qemu-api/src/lib.rs                           |   2 +
 rust/qemu-api/src/log.rs                           |  73 +++++
 rust/qemu-api/src/memory.rs                        |  12 +-
 rust/qemu-api/src/prelude.rs                       |   2 +
 rust/qemu-api/src/qdev.rs                          |  49 ++--
 rust/qemu-api/src/qom.rs                           | 186 ++++++++++++-
 rust/qemu-api/src/uninit.rs                        |  85 ++++++
 target/i386/kvm/meson.build                        |   2 +-
 42 files changed, 1334 insertions(+), 227 deletions(-)
 rename rust/{ => qemu-api}/wrapper.h (97%)
 create mode 100644 target/i386/kvm/tdx-quote-generator.h
 create mode 100644 target/i386/kvm/tdx-quote-generator.c
 create mode 100644 rust/qemu-api/src/log.rs
 create mode 100644 rust/qemu-api/src/uninit.rs
Signature · 1 line
2.49.0
#1 lore raw

[PULL 10/24] rust: prepare variable definitions for multiple bindgen invocations

When splitting the QEMU Rust bindings into multiple crates, the bindgen-generated structs also have to be split so that it's possible to add "impl" blocks (e.g. for Sync/Send or Default, or even for utility methods in cases such as VMStateFlags).

Tweak various variable definitions in meson.build, to avoid naming conflicts once there will be multiple bindgen invocations.

---
 meson.build               | 21 ++++++++++++---------
 rust/meson.build          |  2 +-
 rust/qemu-api/meson.build |  2 +-
 3 files changed, 14 insertions(+), 11 deletions(-)
meson.build +12 -9
index ed60be2a2d0..19ffa9cb34c 100644
@@ -4200,10 +4200,11 @@ foreach target_base_arch, config_base_arch : config_base_arch_mak
 endforeach
 
 if have_rust
+  bindings_incdir = include_directories('.', 'include')
   # We would like to use --generate-cstr, but it is only available
   # starting with bindgen 0.66.0.  The oldest supported versions
   # is 0.60.x (Debian 12 has 0.60.1) which introduces --allowlist-file.
-  bindgen_args = [
+  bindgen_args_common = [
     '--disable-header-comment',
     '--raw-line', '// @generated',
     '--ctypes-prefix', 'std::os::raw',
@@ -4219,20 +4220,22 @@ if have_rust
     ]
   if not rustfmt.found()
     if bindgen.version().version_compare('<0.65.0')
-      bindgen_args += ['--no-rustfmt-bindings']
+      bindgen_args_common += ['--no-rustfmt-bindings']
     else
-      bindgen_args += ['--formatter', 'none']
+      bindgen_args_common += ['--formatter', 'none']
     endif
   endif
   if bindgen.version().version_compare('>=0.66.0')
-    bindgen_args += ['--rust-target', '1.59']
+    bindgen_args_common += ['--rust-target', '1.59']
   endif
   if bindgen.version().version_compare('<0.61.0')
     # default in 0.61+
-    bindgen_args += ['--size_t-is-usize']
+    bindgen_args_common += ['--size_t-is-usize']
   else
-    bindgen_args += ['--merge-extern-blocks']
+    bindgen_args_common += ['--merge-extern-blocks']
   endif
+
+  bindgen_args = []
   c_enums = [
     'DeviceCategory',
     'GpioPolarity',
@@ -4264,13 +4267,13 @@ if have_rust
   # this case you must pass the path to `clang` and `libclang` to your build
   # command invocation using the environment variables CLANG_PATH and
   # LIBCLANG_PATH
-  bindings_rs = rust.bindgen(
+  _qemu_api_bindings_inc_rs = rust.bindgen(
     input: 'rust/wrapper.h',
     dependencies: common_ss.all_dependencies(),
     output: 'bindings.inc.rs',
-    include_directories: include_directories('.', 'include'),
+    include_directories: bindings_incdir,
     bindgen_version: ['>=0.60.0'],
-    args: bindgen_args,
+    args: bindgen_args_common + bindgen_args,
     )
   subdir('rust')
 endif
rust/meson.build +1 -1
index 99ae7956cd0..e9f0879e296 100644
@@ -33,5 +33,5 @@ if cargo.found()
     command: [config_host['MESON'], 'devenv',
               '--workdir', '@CURRENT_SOURCE_DIR@',
               cargo, 'fmt'],
-    depends: bindings_rs)
+    depends: _qemu_api_bindings_inc_rs)
 endif
rust/qemu-api/meson.build +1 -1
index 33653b4a28e..64c04dfd74b 100644
@@ -32,7 +32,7 @@ _qemu_api_rs = static_library(
       'src/vmstate.rs',
       'src/zeroable.rs',
     ],
-    {'.' : bindings_rs},
+    {'.' : _qemu_api_bindings_inc_rs},
   ),
   override_options: ['rust_std=2021', 'build.rust_std=2021'],
   rust_abi: 'rust',
Signature · 1 line
2.49.0
#2 lore raw

[PULL 03/24] hw: Fix type constant for DTB files

In reply to Paolo Bonzini

From: Bernhard Beschow <[email protected]>

Commit fcb1ad456c58 ("system/datadir: Add new type constant for DTB files") introduced a new type constant for DTB files and converted the boards with bundled device trees to use it. Convert the other boards for consistency.

Fixes fcb1ad456c58 ("system/datadir: Add new type constant for DTB files")
---
 hw/arm/boot.c | 2 +-
 hw/ppc/e500.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
hw/arm/boot.c +1 -1
index 79afb51b8a5..64040504a1e 100644
@@ -527,7 +527,7 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
 
     if (binfo->dtb_filename) {
         char *filename;
-        filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, binfo->dtb_filename);
+        filename = qemu_find_file(QEMU_FILE_TYPE_DTB, binfo->dtb_filename);
         if (!filename) {
             fprintf(stderr, "Couldn't open dtb file %s\n", binfo->dtb_filename);
             goto fail;
hw/ppc/e500.c +1 -1
index 6899802bedd..723c97fad2e 100644
@@ -408,7 +408,7 @@ static int ppce500_load_device_tree(PPCE500MachineState *pms,
 
     if (dtb_file) {
         char *filename;
-        filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, dtb_file);
+        filename = qemu_find_file(QEMU_FILE_TYPE_DTB, dtb_file);
         if (!filename) {
             goto out;
         }
Signature · 1 line
2.49.0
#3 lore raw

[PULL 04/24] pc-bios/dtb/meson: Prefer target name to be outfile, not infile

In reply to Paolo Bonzini

From: Bernhard Beschow <[email protected]>

Makes this custom_target() usage consistent with other ones in QEMU.

Fixes 6e0dc9d2a88a ("meson: compile bundled device trees")
---
 pc-bios/dtb/meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
pc-bios/dtb/meson.build +1 -1
index 7a71835bca7..993032949fe 100644
@@ -9,7 +9,7 @@ dtc = find_program('dtc', required: false)
 if dtc.found()
   foreach out : dtbs
     f = fs.replace_suffix(out, '.dts')
-    custom_target(f,
+    custom_target(out,
         build_by_default: have_system,
         input: files(f),
         output: out,
Signature · 1 line
2.49.0
#4 lore raw

[PULL 05/24] rust: qemu_api: introduce MaybeUninit field projection

In reply to Paolo Bonzini

Add a macro that makes it possible to convert a MaybeUninit<> into another MaybeUninit<> for a single field within it. Furthermore, it is possible to use the resulting MaybeUninitField<> in APIs that take the parent object, such as memory_region_init_io().

This allows removing some of the undefined behavior from instance_init() functions, though this may not be the definitive implementation.

---
 rust/qemu-api/meson.build   |  1 +
 rust/qemu-api/src/lib.rs    |  1 +
 rust/qemu-api/src/uninit.rs | 85 +++++++++++++++++++++++++++++++++++++
 3 files changed, 87 insertions(+)
 create mode 100644 rust/qemu-api/src/uninit.rs
rust/qemu-api/meson.build +1 -0
index cac8595a148..33653b4a28e 100644
@@ -28,6 +28,7 @@ _qemu_api_rs = static_library(
       'src/qom.rs',
       'src/sysbus.rs',
       'src/timer.rs',
+      'src/uninit.rs',
       'src/vmstate.rs',
       'src/zeroable.rs',
     ],
rust/qemu-api/src/lib.rs +1 -0
index 93902fc94bc..c78198f0f41 100644
@@ -27,6 +27,7 @@
 pub mod qom;
 pub mod sysbus;
 pub mod timer;
+pub mod uninit;
 pub mod vmstate;
 pub mod zeroable;
 
rust/qemu-api/src/uninit.rs new file +85 -0

85 lines not on this page · raw message

Signature · 1 line
2.49.0
#5 lore raw

[PULL 08/24] rust: qom: make ParentInit lifetime-invariant

In reply to Paolo Bonzini

This is the trick that allows the parent-field initializer to be used only for the object that it's meant to be initialized. This way, the owner of a MemoryRegion must be the object that embeds it.

More information is in the comments; it's best explained with a simplified example.

---
 rust/qemu-api/src/qom.rs | 89 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 85 insertions(+), 4 deletions(-)
rust/qemu-api/src/qom.rs +85 -4
index ef966e570ca..04d102591dc 100644
@@ -95,6 +95,7 @@
 use std::{
     ffi::{c_void, CStr},
     fmt,
+    marker::PhantomData,
     mem::{ManuallyDrop, MaybeUninit},
     ops::{Deref, DerefMut},
     ptr::NonNull,
@@ -208,12 +209,92 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
 
 /// This struct knows that the superclasses of the object have already been
 /// initialized.
-pub struct ParentInit<'a, T>(&'a mut MaybeUninit<T>);
+///
+/// The declaration of `ParentInit` is.. *"a kind of magic"*.  It uses a
+/// technique that is found in several crates, the main ones probably being
+/// `ghost-cell` (in fact it was introduced by the [`GhostCell` paper](https://plv.mpi-sws.org/rustbelt/ghostcell/))
+/// and `generativity`.
+///
+/// The `PhantomData` makes the `ParentInit` type *invariant* with respect to
+/// the lifetime argument `'init`.  This, together with the `for<'...>` in
+/// `[ParentInit::with]`, block any attempt of the compiler to be creative when
+/// operating on types of type `ParentInit` and to extend their lifetimes.  In
+/// particular, it ensures that the `ParentInit` cannot be made to outlive the
+/// `rust_instance_init()` function that creates it, and therefore that the
+/// `&'init T` reference is valid.
+///
+/// This implementation of the same concept, without the QOM baggage, can help
+/// understanding the effect:
+///
+/// ```
+/// use std::marker::PhantomData;
+///
+/// #[derive(PartialEq, Eq)]
+/// pub struct Jail<'closure, T: Copy>(&'closure T, PhantomData<fn(&'closure ()) -> &'closure ()>);
+///
+/// impl<'closure, T: Copy> Jail<'closure, T> {
+///     fn get(&self) -> T {
+///         *self.0
+///     }
+///
+///     #[inline]
+///     fn with<U>(v: T, f: impl for<'id> FnOnce(Jail<'id, T>) -> U) -> U {
+///         let parent_init = Jail(&v, PhantomData);
+///         f(parent_init)
+///     }
+/// }
+/// ```
+///
+/// It's impossible to escape the `Jail`; `token1` cannot be moved out of the
+/// closure:
+///
+/// ```ignore
+/// let x = 42;
+/// let escape = Jail::with(&x, |token1| {
+///     println!("{}", token1.get());
+///     // fails to compile...
+///     token1
+/// });
+/// // ... so you cannot do this:
+/// println!("{}", escape.get());
+/// ```
+///
+/// Likewise, in the QOM case the `ParentInit` cannot be moved out of
+/// `instance_init()`. Without this trick it would be possible to stash a
+/// `ParentInit` and use it later to access uninitialized memory.
+///
+/// Here is another example, showing how separately-created "identities" stay
+/// isolated:
+///
+/// ```ignore
+/// impl<'closure, T: Copy> Clone for Jail<'closure, T> {
+///     fn clone(&self) -> Jail<'closure, T> {
+///         Jail(self.0, PhantomData)
+///     }
+/// }
+///
+/// fn main() {
+///     Jail::with(42, |token1| {
+///         // this works and returns true: the clone has the same "identity"
+///         println!("{}", token1 == token1.clone());
+///         Jail::with(42, |token2| {
+///             // here the outer token remains accessible...
+///             println!("{}", token1.get());
+///             // ... but the two are separate: this fails to compile:
+///             println!("{}", token1 == token2);
+///         });
+///     });
+/// }
+/// ```
+pub struct ParentInit<'init, T>(
+    &'init mut MaybeUninit<T>,
+    PhantomData<fn(&'init ()) -> &'init ()>,
+);
 
-impl<'a, T> ParentInit<'a, T> {
+impl<'init, T> ParentInit<'init, T> {
     #[inline]
-    pub fn with(obj: &'a mut MaybeUninit<T>, f: impl FnOnce(ParentInit<'a, T>)) {
-        let parent_init = ParentInit(obj);
+    pub fn with(obj: &'init mut MaybeUninit<T>, f: impl for<'id> FnOnce(ParentInit<'id, T>)) {
+        let parent_init = ParentInit(obj, PhantomData);
         f(parent_init)
     }
 }
Signature · 1 line
2.49.0
#6 lore raw

[PULL 14/24] rust: pl011: Add missing logging to match C version

In reply to Paolo Bonzini

From: Bernhard Beschow <[email protected]>

---
 rust/hw/char/pl011/src/device.rs | 6 ++++++
 1 file changed, 6 insertions(+)
rust/hw/char/pl011/src/device.rs +6 -0
index 92dc295540e..5b53f2649f1 100644
@@ -305,6 +305,12 @@ fn read_data_register(&mut self, update: &mut bool) -> u32 {
     }
 
     fn write_data_register(&mut self, value: u32) -> bool {
+        if !self.control.enable_uart() {
+            log_mask_ln!(Log::GuestError, "PL011 data written to disabled UART");
+        }
+        if !self.control.enable_transmit() {
+            log_mask_ln!(Log::GuestError, "PL011 data written to disabled TX UART");
+        }
         // interrupts always checked
         let _ = self.loopback_tx(value.into());
         self.int_level |= Interrupt::TX;
Signature · 1 line
2.49.0
#7 lore raw

[PULL 09/24] rust: qom: change instance_init to take a ParentInit<>

In reply to Paolo Bonzini

This removes undefined behavior associated to writing to uninitialized fields, and makes it possible to remove "unsafe" from the instance_init implementation.

However, the init function itself is still unsafe, because it must promise (as a sort as MaybeUninit::assume_init) that all fields have been initialized.

---
 rust/hw/char/pl011/src/device.rs | 34 ++++++++++------------
 rust/hw/timer/hpet/src/device.rs | 16 ++++-------
 rust/qemu-api/src/memory.rs      | 12 ++++----
 rust/qemu-api/src/qdev.rs        | 49 +++++++++++++++++++-------------
 rust/qemu-api/src/qom.rs         |  9 ++++--
 5 files changed, 63 insertions(+), 57 deletions(-)
rust/hw/char/pl011/src/device.rs +15 -19
index be8387f6f2d..2d416cd9a3c 100644
@@ -2,7 +2,7 @@
 // Author(s): Manos Pitsidianakis <[email protected]>
 // SPDX-License-Identifier: GPL-2.0-or-later
 
-use std::{ffi::CStr, mem::size_of, ptr::addr_of_mut};
+use std::{ffi::CStr, mem::size_of};
 
 use qemu_api::{
     chardev::{CharBackend, Chardev, Event},
@@ -11,9 +11,10 @@
     memory::{hwaddr, MemoryRegion, MemoryRegionOps, MemoryRegionOpsBuilder},
     prelude::*,
     qdev::{Clock, ClockEvent, DeviceImpl, DeviceState, Property, ResetType, ResettablePhasesImpl},
-    qom::{ObjectImpl, Owned, ParentField},
+    qom::{ObjectImpl, Owned, ParentField, ParentInit},
     static_assert,
     sysbus::{SysBusDevice, SysBusDeviceImpl},
+    uninit_field_mut,
     vmstate::VMStateDescription,
 };
 
@@ -163,7 +164,7 @@ impl PL011Impl for PL011State {
 impl ObjectImpl for PL011State {
     type ParentType = SysBusDevice;
 
-    const INSTANCE_INIT: Option<unsafe fn(&mut Self)> = Some(Self::init);
+    const INSTANCE_INIT: Option<unsafe fn(ParentInit<Self>)> = Some(Self::init);
     const INSTANCE_POST_INIT: Option<fn(&Self)> = Some(Self::post_init);
     const CLASS_INIT: fn(&mut Self::Class) = Self::Class::class_init::<Self>;
 }
@@ -488,7 +489,7 @@ impl PL011State {
     /// `PL011State` type. It must not be called more than once on the same
     /// location/instance. All its fields are expected to hold uninitialized
     /// values with the sole exception of `parent_obj`.
-    unsafe fn init(&mut self) {
+    unsafe fn init(mut this: ParentInit<Self>) {
         static PL011_OPS: MemoryRegionOps<PL011State> = MemoryRegionOpsBuilder::<PL011State>::new()
             .read(&PL011State::read)
             .write(&PL011State::write)
@@ -496,28 +497,23 @@ unsafe fn init(&mut self) {
             .impl_sizes(4, 4)
             .build();
 
-        // SAFETY:
-        //
-        // self and self.iomem are guaranteed to be valid at this point since callers
-        // must make sure the `self` reference is valid.
+        // SAFETY: this and this.iomem are guaranteed to be valid at this point
         MemoryRegion::init_io(
-            unsafe { &mut *addr_of_mut!(self.iomem) },
-            addr_of_mut!(*self),
+            &mut uninit_field_mut!(*this, iomem),
             &PL011_OPS,
             "pl011",
             0x1000,
         );
 
-        self.regs = Default::default();
+        uninit_field_mut!(*this, regs).write(Default::default());
 
-        // SAFETY:
-        //
-        // self.clock is not initialized at this point; but since `Owned<_>` is
-        // not Drop, we can overwrite the undefined value without side effects;
-        // it's not sound but, because for all PL011State instances are created
-        // by QOM code which calls this function to initialize the fields, at
-        // leastno code is able to access an invalid self.clock value.
-        self.clock = self.init_clock_in("clk", &Self::clock_update, ClockEvent::ClockUpdate);
+        let clock = DeviceState::init_clock_in(
+            &mut this,
+            "clk",
+            &Self::clock_update,
+            ClockEvent::ClockUpdate,
+        );
+        uninit_field_mut!(*this, clock).write(clock);
     }
 
     const fn clock_update(&self, _event: ClockEvent) {
rust/hw/timer/hpet/src/device.rs +6 -10
index 340ca1d355d..a281927781e 100644
@@ -21,8 +21,8 @@
         hwaddr, MemoryRegion, MemoryRegionOps, MemoryRegionOpsBuilder, MEMTXATTRS_UNSPECIFIED,
     },
     prelude::*,
-    qdev::{DeviceImpl, DeviceMethods, DeviceState, Property, ResetType, ResettablePhasesImpl},
-    qom::{ObjectImpl, ObjectType, ParentField},
+    qdev::{DeviceImpl, DeviceState, Property, ResetType, ResettablePhasesImpl},
+    qom::{ObjectImpl, ObjectType, ParentField, ParentInit},
     qom_isa,
     sysbus::{SysBusDevice, SysBusDeviceImpl},
     timer::{Timer, CLOCK_VIRTUAL, NANOSECONDS_PER_SECOND},
@@ -697,7 +697,7 @@ fn set_counter_reg(&self, shift: u32, len: u32, val: u64) {
             .set(self.counter.get().deposit(shift, len, val));
     }
 
-    unsafe fn init(&mut self) {
+    unsafe fn init(mut this: ParentInit<Self>) {
         static HPET_RAM_OPS: MemoryRegionOps<HPETState> =
             MemoryRegionOpsBuilder::<HPETState>::new()
                 .read(&HPETState::read)
@@ -707,18 +707,14 @@ unsafe fn init(&mut self) {
                 .impl_sizes(4, 8)
                 .build();
 
-        // SAFETY:
-        // self and self.iomem are guaranteed to be valid at this point since callers
-        // must make sure the `self` reference is valid.
         MemoryRegion::init_io(
-            unsafe { &mut *addr_of_mut!(self.iomem) },
-            addr_of_mut!(*self),
+            &mut uninit_field_mut!(*this, iomem),
             &HPET_RAM_OPS,
             "hpet",
             HPET_REG_SPACE_LEN,
         );
 
-        Self::init_timers(unsafe { &mut *((self as *mut Self).cast::<MaybeUninit<Self>>()) });
+        Self::init_timers(&mut this);
     }
 
     fn post_init(&self) {
@@ -900,7 +896,7 @@ unsafe impl ObjectType for HPETState {
 impl ObjectImpl for HPETState {
     type ParentType = SysBusDevice;
 
-    const INSTANCE_INIT: Option<unsafe fn(&mut Self)> = Some(Self::init);
+    const INSTANCE_INIT: Option<unsafe fn(ParentInit<Self>)> = Some(Self::init);
     const INSTANCE_POST_INIT: Option<fn(&Self)> = Some(Self::post_init);
     const CLASS_INIT: fn(&mut Self::Class) = Self::Class::class_init::<Self>;
 }
rust/qemu-api/src/memory.rs +6 -6
index 9ef2694bd62..e40fad6cf19 100644
@@ -16,6 +16,7 @@
     callbacks::FnCall,
     cell::Opaque,
     prelude::*,
+    uninit::MaybeUninitField,
     zeroable::Zeroable,
 };
 
@@ -147,7 +148,7 @@ impl MemoryRegion {
     #[inline(always)]
     unsafe fn do_init_io(
         slot: *mut bindings::MemoryRegion,
-        owner: *mut Object,
+        owner: *mut bindings::Object,
         ops: &'static bindings::MemoryRegionOps,
         name: &'static str,
         size: u64,
@@ -156,7 +157,7 @@ unsafe fn do_init_io(
             let cstr = CString::new(name).unwrap();
             memory_region_init_io(
                 slot,
-                owner.cast::<bindings::Object>(),
+                owner,
                 ops,
                 owner.cast::<c_void>(),
                 cstr.as_ptr(),
@@ -166,16 +167,15 @@ unsafe fn do_init_io(
     }
 
     pub fn init_io<T: IsA<Object>>(
-        &mut self,
-        owner: *mut T,
+        this: &mut MaybeUninitField<'_, T, Self>,
         ops: &'static MemoryRegionOps<T>,
         name: &'static str,
         size: u64,
     ) {
         unsafe {
             Self::do_init_io(
-                self.0.as_mut_ptr(),
-                owner.cast::<Object>(),
+                this.as_mut_ptr().cast(),
+                MaybeUninitField::parent_mut(this).cast(),
                 &ops.0,
                 name,
                 size,
rust/qemu-api/src/qdev.rs +30 -19

102 lines not on this page · raw message

rust/qemu-api/src/qom.rs +6 -3
index 04d102591dc..e20ee014cb1 100644
@@ -382,12 +382,15 @@ fn deref_mut(&mut self) -> &mut Self::Target {
 }
 
 unsafe extern "C" fn rust_instance_init<T: ObjectImpl>(obj: *mut bindings::Object) {
-    let mut state = NonNull::new(obj).unwrap().cast::<T>();
+    let mut state = NonNull::new(obj).unwrap().cast::<MaybeUninit<T>>();
+
     // SAFETY: obj is an instance of T, since rust_instance_init<T>
     // is called from QOM core as the instance_init function
     // for class T
     unsafe {
-        T::INSTANCE_INIT.unwrap()(state.as_mut());
+        ParentInit::with(state.as_mut(), |parent_init| {
+            T::INSTANCE_INIT.unwrap()(parent_init);
+        });
     }
 }
 
@@ -654,7 +657,7 @@ pub trait ObjectImpl: ObjectType + IsA<Object> {
     ///
     /// FIXME: The argument is not really a valid reference. `&mut
     /// MaybeUninit<Self>` would be a better description.
-    const INSTANCE_INIT: Option<unsafe fn(&mut Self)> = None;
+    const INSTANCE_INIT: Option<unsafe fn(ParentInit<Self>)> = None;
 
     /// Function that is called to finish initialization of an object, once
     /// `INSTANCE_INIT` functions have been called.
Signature · 1 line
2.49.0
#8 lore raw

[PULL 01/24] meson: cleanup win32 library detection

In reply to Paolo Bonzini

As pointed out by Akihiko Odaki, all Win32 libraries in MinGW have lowercase names. This means that on (case-insensitive) Windows you can use the mixed-case names suggested by Microsoft or all-lowercase names, while on Linux you need to make them lowercase.

QEMU was already using lowercase names, so there is no need to test the mixed-case name version of libSynchronization. Remove the unnecessary test and while at it make all the tests use "required: true".

---
 meson.build | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
meson.build +5 -8
index 34729c2a3dd..ed60be2a2d0 100644
@@ -843,15 +843,12 @@ host_dsosuf = '.so'
 if host_os == 'windows'
   midl = find_program('midl', required: false)
   widl = find_program('widl', required: false)
-  pathcch = cc.find_library('pathcch')
-  synchronization = cc.find_library('Synchronization', required: false)
-  if not synchronization.found()
-    # The library name is lowercase on mingw
-    synchronization = cc.find_library('synchronization', required: true)
-  endif
 
-  socket = cc.find_library('ws2_32')
-  winmm = cc.find_library('winmm')
+  # MinGW uses lowercase for library names
+  pathcch = cc.find_library('pathcch', required: true)
+  synchronization = cc.find_library('synchronization', required: true)
+  socket = cc.find_library('ws2_32', required: true)
+  winmm = cc.find_library('winmm', required: true)
 
   win = import('windows')
   version_res = win.compile_resources('version.rc',
Signature · 1 line
2.49.0
#9 lore raw

[PULL 06/24] rust: hpet: fully initialize object during instance_init

In reply to Paolo Bonzini

The array of BqlRefCell<HPETTimer> is not initialized yet at the end of instance_init. In particular, the "state" field is NonNull and therefore it is invalid to have it as zero bytes.

Note that MaybeUninit is necessary because assigning to self.timers[index] would trigger Drop of the old value.

---
 rust/hw/timer/hpet/src/device.rs | 42 +++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 17 deletions(-)
rust/hw/timer/hpet/src/device.rs +25 -17
index 735b2fbef79..340ca1d355d 100644
@@ -4,6 +4,7 @@
 
 use std::{
     ffi::{c_int, c_void, CStr},
+    mem::MaybeUninit,
     pin::Pin,
     ptr::{addr_of_mut, null_mut, NonNull},
     slice::from_ref,
@@ -25,6 +26,7 @@
     qom_isa,
     sysbus::{SysBusDevice, SysBusDeviceImpl},
     timer::{Timer, CLOCK_VIRTUAL, NANOSECONDS_PER_SECOND},
+    uninit_field_mut,
     vmstate::VMStateDescription,
     vmstate_fields, vmstate_of, vmstate_struct, vmstate_subsections, vmstate_validate,
     zeroable::Zeroable,
@@ -212,13 +214,13 @@ pub struct HPETTimer {
 }
 
 impl HPETTimer {
-    fn init(&mut self, index: u8, state: &HPETState) {
-        *self = HPETTimer {
+    fn new(index: u8, state: *const HPETState) -> HPETTimer {
+        HPETTimer {
             index,
             // SAFETY: the HPETTimer will only be used after the timer
             // is initialized below.
             qemu_timer: unsafe { Timer::new() },
-            state: NonNull::new((state as *const HPETState).cast_mut()).unwrap(),
+            state: NonNull::new(state.cast_mut()).unwrap(),
             config: 0,
             cmp: 0,
             fsb: 0,
@@ -226,19 +228,15 @@ fn init(&mut self, index: u8, state: &HPETState) {
             period: 0,
             wrap_flag: 0,
             last: 0,
-        };
+        }
+    }
 
+    fn init_timer_with_cell(cell: &BqlRefCell<Self>) {
+        let mut timer = cell.borrow_mut();
         // SAFETY: HPETTimer is only used as part of HPETState, which is
         // always pinned.
-        let qemu_timer = unsafe { Pin::new_unchecked(&mut self.qemu_timer) };
-        qemu_timer.init_full(
-            None,
-            CLOCK_VIRTUAL,
-            Timer::NS,
-            0,
-            timer_handler,
-            &state.timers[self.index as usize],
-        )
+        let qemu_timer = unsafe { Pin::new_unchecked(&mut timer.qemu_timer) };
+        qemu_timer.init_full(None, CLOCK_VIRTUAL, Timer::NS, 0, timer_handler, cell);
     }
 
     fn get_state(&self) -> &HPETState {
@@ -607,9 +605,18 @@ fn handle_legacy_irq(&self, irq: u32, level: u32) {
         }
     }
 
-    fn init_timer(&self) {
-        for (index, timer) in self.timers.iter().enumerate() {
-            timer.borrow_mut().init(index.try_into().unwrap(), self);
+    fn init_timers(this: &mut MaybeUninit<Self>) {
+        let state = this.as_ptr();
+        for index in 0..HPET_MAX_TIMERS {
+            let mut timer = uninit_field_mut!(*this, timers[index]);
+
+            // Initialize in two steps, to avoid calling Timer::init_full on a
+            // temporary that can be moved.
+            let timer = timer.write(BqlRefCell::new(HPETTimer::new(
+                index.try_into().unwrap(),
+                state,
+            )));
+            HPETTimer::init_timer_with_cell(timer);
         }
     }
 
@@ -710,6 +717,8 @@ unsafe fn init(&mut self) {
             "hpet",
             HPET_REG_SPACE_LEN,
         );
+
+        Self::init_timers(unsafe { &mut *((self as *mut Self).cast::<MaybeUninit<Self>>()) });
     }
 
     fn post_init(&self) {
@@ -731,7 +740,6 @@ fn realize(&self) -> qemu_api::Result<()> {
 
         self.hpet_id.set(HPETFwConfig::assign_hpet_id()?);
 
-        self.init_timer();
         // 64-bit General Capabilities and ID Register; LegacyReplacementRoute.
         self.capability.set(
             HPET_CAP_REV_ID_VALUE << HPET_CAP_REV_ID_SHIFT |
Signature · 1 line
2.49.0
#10 lore raw

[PULL 18/24] i386/tdx: Error and exit when named cpu model is requested

In reply to Paolo Bonzini

From: Xiaoyao Li <[email protected]>

Currently, it gets below error when requesting any named cpu model with "-cpu" to boot a TDX VM:

qemu-system-x86_64: KVM_TDX_INIT_VM failed: Invalid argument

It misleads people to think it's the bug of KVM or QEMU. It is just that current QEMU doesn't support named cpu model for TDX.

To support named cpu models for TDX guest, there are opens to be finalized and needs a mount of additional work.

For now, explicitly check the case when named cpu model is requested. Error report a hint and exit.

---
 target/i386/kvm/tdx.c | 6 ++++++
 1 file changed, 6 insertions(+)
target/i386/kvm/tdx.c +6 -0
index 820ca3614e2..2b52de9d71b 100644
@@ -739,8 +739,14 @@ static int tdx_kvm_type(X86ConfidentialGuest *cg)
 
 static void tdx_cpu_instance_init(X86ConfidentialGuest *cg, CPUState *cpu)
 {
+    X86CPUClass *xcc = X86_CPU_GET_CLASS(cpu);
     X86CPU *x86cpu = X86_CPU(cpu);
 
+    if (xcc->model) {
+        error_report("Named cpu model is not supported for TDX yet!");
+        exit(1);
+    }
+
     object_property_set_bool(OBJECT(cpu), "pmu", false, &error_abort);
 
     /* invtsc is fixed1 for TD guest */
Signature · 1 line
2.49.0
#11 lore raw

[PULL 22/24] update Linux headers to v6.16-rc3

In reply to Paolo Bonzini
---
 include/standard-headers/asm-x86/setup_data.h |  13 +-
 include/standard-headers/drm/drm_fourcc.h     |  45 +++++++
 include/standard-headers/linux/ethtool.h      | 124 +++++++++---------
 include/standard-headers/linux/fuse.h         |   6 +-
 .../linux/input-event-codes.h                 |   3 +-
 include/standard-headers/linux/pci_regs.h     |  12 +-
 include/standard-headers/linux/virtio_gpu.h   |   3 +-
 include/standard-headers/linux/virtio_pci.h   |   1 +
 linux-headers/asm-arm64/kvm.h                 |   9 +-
 linux-headers/asm-x86/kvm.h                   |   1 +
 linux-headers/linux/bits.h                    |   4 +-
 linux-headers/linux/kvm.h                     |  25 ++++
 linux-headers/linux/vhost.h                   |   4 +-
 13 files changed, 177 insertions(+), 73 deletions(-)
include/standard-headers/asm-x86/setup_data.h +12 -1
index a483d72f428..2e446c1d858 100644
@@ -13,7 +13,8 @@
 #define SETUP_CC_BLOB			7
 #define SETUP_IMA			8
 #define SETUP_RNG_SEED			9
-#define SETUP_ENUM_MAX			SETUP_RNG_SEED
+#define SETUP_KEXEC_KHO			10
+#define SETUP_ENUM_MAX			SETUP_KEXEC_KHO
 
 #define SETUP_INDIRECT			(1<<31)
 #define SETUP_TYPE_MAX			(SETUP_ENUM_MAX | SETUP_INDIRECT)
@@ -78,6 +79,16 @@ struct ima_setup_data {
 	uint64_t size;
 } QEMU_PACKED;
 
+/*
+ * Locations of kexec handover metadata
+ */
+struct kho_data {
+	uint64_t fdt_addr;
+	uint64_t fdt_size;
+	uint64_t scratch_addr;
+	uint64_t scratch_size;
+} QEMU_PACKED;
+
 #endif /* __ASSEMBLER__ */
 
 #endif /* _ASM_X86_SETUP_DATA_H */
include/standard-headers/drm/drm_fourcc.h +45 -0

57 lines not on this page · raw message

include/standard-headers/linux/ethtool.h +64 -60

135 lines not on this page · raw message

include/standard-headers/linux/fuse.h +5 -1
index a2b5815d890..d8b2fd67e16 100644
@@ -232,6 +232,9 @@
  *
  *  7.43
  *  - add FUSE_REQUEST_TIMEOUT
+ *
+ *  7.44
+ *  - add FUSE_NOTIFY_INC_EPOCH
  */
 
 #ifndef _LINUX_FUSE_H
@@ -263,7 +266,7 @@
 #define FUSE_KERNEL_VERSION 7
 
 /** Minor version number of this interface */
-#define FUSE_KERNEL_MINOR_VERSION 43
+#define FUSE_KERNEL_MINOR_VERSION 44
 
 /** The node ID of the root inode */
 #define FUSE_ROOT_ID 1
@@ -667,6 +670,7 @@ enum fuse_notify_code {
 	FUSE_NOTIFY_RETRIEVE = 5,
 	FUSE_NOTIFY_DELETE = 6,
 	FUSE_NOTIFY_RESEND = 7,
+	FUSE_NOTIFY_INC_EPOCH = 8,
 	FUSE_NOTIFY_CODE_MAX,
 };
 
include/standard-headers/linux/input-event-codes.h +2 -1
index 09ba0ad8783..a82ff795e06 100644
@@ -925,7 +925,8 @@
 #define SW_MUTE_DEVICE		0x0e  /* set = device disabled */
 #define SW_PEN_INSERTED		0x0f  /* set = pen inserted */
 #define SW_MACHINE_COVER	0x10  /* set = cover closed */
-#define SW_MAX_			0x10
+#define SW_USB_INSERT		0x11  /* set = USB audio device connected */
+#define SW_MAX_			0x11
 #define SW_CNT			(SW_MAX_+1)
 
 /*
include/standard-headers/linux/pci_regs.h +11 -1
index ba326710f9c..a3a3e942ded 100644
@@ -750,7 +750,8 @@
 #define PCI_EXT_CAP_ID_NPEM	0x29	/* Native PCIe Enclosure Management */
 #define PCI_EXT_CAP_ID_PL_32GT  0x2A    /* Physical Layer 32.0 GT/s */
 #define PCI_EXT_CAP_ID_DOE	0x2E	/* Data Object Exchange */
-#define PCI_EXT_CAP_ID_MAX	PCI_EXT_CAP_ID_DOE
+#define PCI_EXT_CAP_ID_PL_64GT	0x31	/* Physical Layer 64.0 GT/s */
+#define PCI_EXT_CAP_ID_MAX	PCI_EXT_CAP_ID_PL_64GT
 
 #define PCI_EXT_CAP_DSN_SIZEOF	12
 #define PCI_EXT_CAP_MCAST_ENDPOINT_SIZEOF 40
@@ -1144,12 +1145,21 @@
 #define PCI_DLF_CAP		0x04	/* Capabilities Register */
 #define  PCI_DLF_EXCHANGE_ENABLE	0x80000000  /* Data Link Feature Exchange Enable */
 
+/* Secondary PCIe Capability 8.0 GT/s */
+#define PCI_SECPCI_LE_CTRL	0x0c /* Lane Equalization Control Register */
+
 /* Physical Layer 16.0 GT/s */
 #define PCI_PL_16GT_LE_CTRL	0x20	/* Lane Equalization Control Register */
 #define  PCI_PL_16GT_LE_CTRL_DSP_TX_PRESET_MASK		0x0000000F
 #define  PCI_PL_16GT_LE_CTRL_USP_TX_PRESET_MASK		0x000000F0
 #define  PCI_PL_16GT_LE_CTRL_USP_TX_PRESET_SHIFT	4
 
+/* Physical Layer 32.0 GT/s */
+#define PCI_PL_32GT_LE_CTRL	0x20	/* Lane Equalization Control Register */
+
+/* Physical Layer 64.0 GT/s */
+#define PCI_PL_64GT_LE_CTRL	0x20	/* Lane Equalization Control Register */
+
 /* Native PCIe Enclosure Management */
 #define PCI_NPEM_CAP     0x04 /* NPEM capability register */
 #define  PCI_NPEM_CAP_CAPABLE     0x00000001 /* NPEM Capable */
include/standard-headers/linux/virtio_gpu.h +2 -1
index 6459fdb9fb5..00cd3f04af9 100644
@@ -309,8 +309,9 @@ struct virtio_gpu_cmd_submit {
 
 #define VIRTIO_GPU_CAPSET_VIRGL 1
 #define VIRTIO_GPU_CAPSET_VIRGL2 2
-/* 3 is reserved for gfxstream */
+#define VIRTIO_GPU_CAPSET_GFXSTREAM_VULKAN 3
 #define VIRTIO_GPU_CAPSET_VENUS 4
+#define VIRTIO_GPU_CAPSET_CROSS_DOMAIN 5
 #define VIRTIO_GPU_CAPSET_DRM 6
 
 /* VIRTIO_GPU_CMD_GET_CAPSET_INFO */
include/standard-headers/linux/virtio_pci.h +1 -0
index 91fec6f5029..09e964e6eee 100644
@@ -246,6 +246,7 @@ struct virtio_pci_cfg_cap {
 #define VIRTIO_ADMIN_CMD_LIST_USE	0x1
 
 /* Admin command group type. */
+#define VIRTIO_ADMIN_GROUP_TYPE_SELF	0x0
 #define VIRTIO_ADMIN_GROUP_TYPE_SRIOV	0x1
 
 /* Transitional device admin command. */
linux-headers/asm-arm64/kvm.h +5 -4
index 4e6aff08df8..f4d9baafa1c 100644
@@ -419,10 +419,11 @@ enum {
 
 /* Device Control API on vcpu fd */
 #define KVM_ARM_VCPU_PMU_V3_CTRL	0
-#define   KVM_ARM_VCPU_PMU_V3_IRQ	0
-#define   KVM_ARM_VCPU_PMU_V3_INIT	1
-#define   KVM_ARM_VCPU_PMU_V3_FILTER	2
-#define   KVM_ARM_VCPU_PMU_V3_SET_PMU	3
+#define   KVM_ARM_VCPU_PMU_V3_IRQ		0
+#define   KVM_ARM_VCPU_PMU_V3_INIT		1
+#define   KVM_ARM_VCPU_PMU_V3_FILTER		2
+#define   KVM_ARM_VCPU_PMU_V3_SET_PMU		3
+#define   KVM_ARM_VCPU_PMU_V3_SET_NR_COUNTERS	4
 #define KVM_ARM_VCPU_TIMER_CTRL		1
 #define   KVM_ARM_VCPU_TIMER_IRQ_VTIMER		0
 #define   KVM_ARM_VCPU_TIMER_IRQ_PTIMER		1
linux-headers/asm-x86/kvm.h +1 -0
index 7fb57ccb2a7..cd275ae76d2 100644
@@ -843,6 +843,7 @@ struct kvm_sev_snp_launch_start {
 };
 
 /* Kept in sync with firmware values for simplicity. */
+#define KVM_SEV_PAGE_TYPE_INVALID		0x0
 #define KVM_SEV_SNP_PAGE_TYPE_NORMAL		0x1
 #define KVM_SEV_SNP_PAGE_TYPE_ZERO		0x3
 #define KVM_SEV_SNP_PAGE_TYPE_UNMEASURED	0x4
linux-headers/linux/bits.h +2 -2
index 58596d18f43..9243f389751 100644
@@ -4,9 +4,9 @@
 #ifndef _LINUX_BITS_H
 #define _LINUX_BITS_H
 
-#define __GENMASK(h, l) (((~_UL(0)) << (l)) & (~_UL(0) >> (BITS_PER_LONG - 1 - (h))))
+#define __GENMASK(h, l) (((~_UL(0)) << (l)) & (~_UL(0) >> (__BITS_PER_LONG - 1 - (h))))
 
-#define __GENMASK_ULL(h, l) (((~_ULL(0)) << (l)) & (~_ULL(0) >> (BITS_PER_LONG_LONG - 1 - (h))))
+#define __GENMASK_ULL(h, l) (((~_ULL(0)) << (l)) & (~_ULL(0) >> (__BITS_PER_LONG_LONG - 1 - (h))))
 
 #define __GENMASK_U128(h, l) \
 	((_BIT128((h)) << 1) - (_BIT128(l)))
linux-headers/linux/kvm.h +25 -0
index 99cc82a275c..0690743944b 100644
@@ -178,6 +178,7 @@ struct kvm_xen_exit {
 #define KVM_EXIT_NOTIFY           37
 #define KVM_EXIT_LOONGARCH_IOCSR  38
 #define KVM_EXIT_MEMORY_FAULT     39
+#define KVM_EXIT_TDX              40
 
 /* For KVM_EXIT_INTERNAL_ERROR */
 /* Emulate instruction failed. */
@@ -439,6 +440,27 @@ struct kvm_run {
 			__u64 gpa;
 			__u64 size;
 		} memory_fault;
+		/* KVM_EXIT_TDX */
+		struct {
+			__u64 flags;
+			__u64 nr;
+			union {
+				struct {
+					__u64 ret;
+					__u64 data[5];
+				} unknown;
+				struct {
+					__u64 ret;
+					__u64 gpa;
+					__u64 size;
+				} get_quote;
+				struct {
+					__u64 ret;
+					__u64 leaf;
+					__u64 r11, r12, r13, r14;
+				} get_tdvmcall_info;
+			};
+		} tdx;
 		/* Fix the size of the union. */
 		char padding[256];
 	};
@@ -923,6 +945,9 @@ struct kvm_enable_cap {
 #define KVM_CAP_X86_APIC_BUS_CYCLES_NS 237
 #define KVM_CAP_X86_GUEST_MODE 238
 #define KVM_CAP_ARM_WRITABLE_IMP_ID_REGS 239
+#define KVM_CAP_ARM_EL2 240
+#define KVM_CAP_ARM_EL2_E2H0 241
+#define KVM_CAP_RISCV_MP_STATE_RESET 242
 
 struct kvm_irq_routing_irqchip {
 	__u32 irqchip;
linux-headers/linux/vhost.h +2 -2
index b95dd84eef2..d4b3e2ae131 100644
@@ -28,10 +28,10 @@
 
 /* Set current process as the (exclusive) owner of this file descriptor.  This
  * must be called before any other vhost command.  Further calls to
- * VHOST_OWNER_SET fail until VHOST_OWNER_RESET is called. */
+ * VHOST_SET_OWNER fail until VHOST_RESET_OWNER is called. */
 #define VHOST_SET_OWNER _IO(VHOST_VIRTIO, 0x01)
 /* Give up ownership, and reset the device to default values.
- * Allows subsequent call to VHOST_OWNER_SET to succeed. */
+ * Allows subsequent call to VHOST_SET_OWNER to succeed. */
 #define VHOST_RESET_OWNER _IO(VHOST_VIRTIO, 0x02)
 
 /* Set up/modify memory layout */
Signature · 1 line
2.49.0
#12 lore raw

[PULL 15/24] rust: hpet: fix new warning

In reply to Paolo Bonzini

Nightly rustc complains that HPETAddrDecode has a lifetime but it is not clearly noted that it comes from &self. Apply the compiler's suggestion to shut it up.

---
 rust/hw/timer/hpet/src/device.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
rust/hw/timer/hpet/src/device.rs +1 -1
index a281927781e..acf7251029e 100644
@@ -771,7 +771,7 @@ fn reset_hold(&self, _type: ResetType) {
         self.rtc_irq_level.set(0);
     }
 
-    fn decode(&self, mut addr: hwaddr, size: u32) -> HPETAddrDecode {
+    fn decode(&self, mut addr: hwaddr, size: u32) -> HPETAddrDecode<'_> {
         let shift = ((addr & 4) * 8) as u32;
         let len = std::cmp::min(size * 8, 64 - shift);
 
Signature · 1 line
2.49.0
#13 lore raw

[PULL 21/24] i386/tdx: Clarify the error message of mrconfigid/mrowner/mrownerconfig

In reply to Paolo Bonzini

From: Xiaoyao Li <[email protected]>

The error message is misleading - we successfully decoded the data, the decoded data was simply with the wrong length.

Change the error message to show it is an length check failure with both the received and expected values.

---
 target/i386/kvm/tdx.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
target/i386/kvm/tdx.c +9 -3
index acbe7497543..2284167141a 100644
@@ -1032,7 +1032,9 @@ int tdx_pre_create_vcpu(CPUState *cpu, Error **errp)
             return -1;
         }
         if (data_len != QCRYPTO_HASH_DIGEST_LEN_SHA384) {
-            error_setg(errp, "TDX: failed to decode mrconfigid");
+            error_setg(errp, "TDX 'mrconfigid' sha384 digest was %ld bytes, "
+                             "expected %d bytes", data_len,
+                             QCRYPTO_HASH_DIGEST_LEN_SHA384);
             return -1;
         }
         memcpy(init_vm->mrconfigid, data, data_len);
@@ -1045,7 +1047,9 @@ int tdx_pre_create_vcpu(CPUState *cpu, Error **errp)
             return -1;
         }
         if (data_len != QCRYPTO_HASH_DIGEST_LEN_SHA384) {
-            error_setg(errp, "TDX: failed to decode mrowner");
+            error_setg(errp, "TDX 'mrowner' sha384 digest was %ld bytes, "
+                             "expected %d bytes", data_len,
+                             QCRYPTO_HASH_DIGEST_LEN_SHA384);
             return -1;
         }
         memcpy(init_vm->mrowner, data, data_len);
@@ -1058,7 +1062,9 @@ int tdx_pre_create_vcpu(CPUState *cpu, Error **errp)
             return -1;
         }
         if (data_len != QCRYPTO_HASH_DIGEST_LEN_SHA384) {
-            error_setg(errp, "TDX: failed to decode mrownerconfig");
+            error_setg(errp, "TDX 'mrownerconfig' sha384 digest was %ld bytes, "
+                             "expected %d bytes", data_len,
+                             QCRYPTO_HASH_DIGEST_LEN_SHA384);
             return -1;
         }
         memcpy(init_vm->mrownerconfig, data, data_len);
Signature · 1 line
2.49.0
#14 lore raw

[PULL 17/24] i386/cpu: Warn about why CPUID_EXT_PDCM is not available

In reply to Paolo Bonzini

From: Xiaoyao Li <[email protected]>

When user requests PDCM explicitly via "+pdcm" without PMU enabled, emit a warning to inform the user.

---
 target/i386/cpu.c | 3 +++
 1 file changed, 3 insertions(+)
target/i386/cpu.c +3 -0
index 29bce67c3a1..0d35e95430f 100644
@@ -8339,6 +8339,9 @@ void x86_cpu_expand_features(X86CPU *cpu, Error **errp)
     }
 
     if (!cpu->enable_pmu) {
+        mark_unavailable_features(cpu, FEAT_1_ECX,
+                                  env->user_features[FEAT_1_ECX] & CPUID_EXT_PDCM,
+                                  "This feature is not available due to PMU being disabled");
         env->features[FEAT_1_ECX] &= ~CPUID_EXT_PDCM;
     }
 
Signature · 1 line
2.49.0
#15 lore raw

[PULL 12/24] rust/qemu-api: Add initial logging support based on C API

In reply to Paolo Bonzini

From: Bernhard Beschow <[email protected]>

A log_mask_ln!() macro is provided which expects similar arguments as the C version. However, the formatting works as one would expect from Rust.

To maximize code reuse the macro is just a thin wrapper around qemu_log(). Also, just the bare minimum of logging masks is provided which should suffice for the current use case of Rust in QEMU.

---
 docs/devel/rust.rst          |  1 +
 rust/qemu-api/wrapper.h      |  2 +
 rust/qemu-api/meson.build    |  1 +
 rust/qemu-api/src/lib.rs     |  1 +
 rust/qemu-api/src/log.rs     | 73 ++++++++++++++++++++++++++++++++++++
 rust/qemu-api/src/prelude.rs |  2 +
 6 files changed, 80 insertions(+)
 create mode 100644 rust/qemu-api/src/log.rs
docs/devel/rust.rst +1 -0
index 47e9677fcb0..dc8c44109e1 100644
@@ -162,6 +162,7 @@ module           status
 ``errno``        complete
 ``error``        stable
 ``irq``          complete
+``log``          proof of concept
 ``memory``       stable
 ``module``       complete
 ``qdev``         stable
rust/qemu-api/wrapper.h +2 -0
index 6060d3ba1ab..15a1b19847f 100644
@@ -48,6 +48,8 @@ typedef enum memory_order {
 #endif /* __CLANG_STDATOMIC_H */
 
 #include "qemu/osdep.h"
+#include "qemu/log.h"
+#include "qemu/log-for-trace.h"
 #include "qemu/module.h"
 #include "qemu-io.h"
 #include "system/system.h"
rust/qemu-api/meson.build +1 -0
index 5b8c7e5e8d5..a090297c458 100644
@@ -62,6 +62,7 @@ _qemu_api_rs = static_library(
       'src/errno.rs',
       'src/error.rs',
       'src/irq.rs',
+      'src/log.rs',
       'src/memory.rs',
       'src/module.rs',
       'src/prelude.rs',
rust/qemu-api/src/lib.rs +1 -0
index c78198f0f41..86dcd8ef17a 100644
@@ -21,6 +21,7 @@
 pub mod errno;
 pub mod error;
 pub mod irq;
+pub mod log;
 pub mod memory;
 pub mod module;
 pub mod qdev;
rust/qemu-api/src/log.rs new file +73 -0

73 lines not on this page · raw message

rust/qemu-api/src/prelude.rs +2 -0
index 43bfcd5fcab..8f9e23ee2c5 100644
@@ -11,6 +11,8 @@
 
 pub use crate::errno;
 
+pub use crate::log_mask_ln;
+
 pub use crate::qdev::DeviceMethods;
 
 pub use crate::qom::InterfaceType;
Signature · 1 line
2.49.0
#16 lore raw

[PULL 19/24] i386/cpu: Rename enable_cpuid_0x1f to force_cpuid_0x1f

In reply to Paolo Bonzini

From: Xiaoyao Li <[email protected]>

The name of "enable_cpuid_0x1f" isn't right to its behavior because the leaf 0x1f can be enabled even when "enable_cpuid_0x1f" is false.

Rename it to "force_cpuid_0x1f" to better reflect its behavior.

---
 target/i386/cpu.h     | 4 ++--
 target/i386/kvm/tdx.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
target/i386/cpu.h +2 -2
index 5910dcf74d4..51e10139dfd 100644
@@ -2269,7 +2269,7 @@ struct ArchCPU {
     bool enable_cpuid_0xb;
 
     /* Force to enable cpuid 0x1f */
-    bool enable_cpuid_0x1f;
+    bool force_cpuid_0x1f;
 
     /* Enable auto level-increase for all CPUID leaves */
     bool full_cpuid_auto_level;
@@ -2539,7 +2539,7 @@ void mark_forced_on_features(X86CPU *cpu, FeatureWord w, uint64_t mask,
 
 static inline bool x86_has_cpuid_0x1f(X86CPU *cpu)
 {
-    return cpu->enable_cpuid_0x1f ||
+    return cpu->force_cpuid_0x1f ||
            x86_has_extended_topo(cpu->env.avail_cpu_topo);
 }
 
target/i386/kvm/tdx.c +1 -1
index 2b52de9d71b..acbe7497543 100644
@@ -752,7 +752,7 @@ static void tdx_cpu_instance_init(X86ConfidentialGuest *cg, CPUState *cpu)
     /* invtsc is fixed1 for TD guest */
     object_property_set_bool(OBJECT(cpu), "invtsc", true, &error_abort);
 
-    x86cpu->enable_cpuid_0x1f = true;
+    x86cpu->force_cpuid_0x1f = true;
 }
 
 static uint32_t tdx_adjust_cpuid_features(X86ConfidentialGuest *cg,
Signature · 1 line
2.49.0
#17 lore raw

[PULL 11/24] rust: move rust.bindgen to qemu-api crate

In reply to Paolo Bonzini

Once qemu-api is split in multiple crates, each of them will have its own invocation of bindgen. There cannot be only one, because there are occasional "impl" blocks for the bindgen-generated structs (e.g. VMStateFlags or QOM classes) that have to reside in the same crate as the bindgen-generated code.

For now, prepare for this new organization by invoking bindgen within the qemu-api crate's build definitions; it's also a much better place to list enums that need specific treatment from bindgen.

---
 meson.build                   | 41 -----------------------------------
 rust/{ => qemu-api}/wrapper.h |  0
 rust/meson.build              |  4 +++-
 rust/qemu-api/build.rs        |  2 +-
 rust/qemu-api/meson.build     | 41 +++++++++++++++++++++++++++++++++++
 5 files changed, 45 insertions(+), 43 deletions(-)
 rename rust/{ => qemu-api}/wrapper.h (100%)
meson.build +0 -41
index 19ffa9cb34c..4676908dbb2 100644
@@ -4234,47 +4234,6 @@ if have_rust
   else
     bindgen_args_common += ['--merge-extern-blocks']
   endif
-
-  bindgen_args = []
-  c_enums = [
-    'DeviceCategory',
-    'GpioPolarity',
-    'MachineInitPhase',
-    'MemoryDeviceInfoKind',
-    'MigrationPolicy',
-    'MigrationPriority',
-    'QEMUChrEvent',
-    'QEMUClockType',
-    'ResetType',
-    'device_endian',
-    'module_init_type',
-  ]
-  foreach enum : c_enums
-    bindgen_args += ['--rustified-enum', enum]
-  endforeach
-  c_bitfields = [
-    'ClockEvent',
-    'VMStateFlags',
-  ]
-  foreach enum : c_bitfields
-    bindgen_args += ['--bitfield-enum', enum]
-  endforeach
-
-  # TODO: Remove this comment when the clang/libclang mismatch issue is solved.
-  #
-  # Rust bindings generation with `bindgen` might fail in some cases where the
-  # detected `libclang` does not match the expected `clang` version/target. In
-  # this case you must pass the path to `clang` and `libclang` to your build
-  # command invocation using the environment variables CLANG_PATH and
-  # LIBCLANG_PATH
-  _qemu_api_bindings_inc_rs = rust.bindgen(
-    input: 'rust/wrapper.h',
-    dependencies: common_ss.all_dependencies(),
-    output: 'bindings.inc.rs',
-    include_directories: bindings_incdir,
-    bindgen_version: ['>=0.60.0'],
-    args: bindgen_args_common + bindgen_args,
-    )
   subdir('rust')
 endif
 
rust/qemu-api/wrapper.h renamed from rust/wrapper.h +0 -0
similarity index 100%
rename from rust/wrapper.h
rename to rust/qemu-api/wrapper.h
rust/meson.build +3 -1
index e9f0879e296..331f11b7e72 100644
@@ -20,6 +20,8 @@ proc_macro2_rs_native = dependency('proc-macro2-1-rs', native: true)
 
 qemuutil_rs = qemuutil.partial_dependency(link_args: true, links: true)
 
+genrs = []
+
 subdir('qemu-api-macros')
 subdir('bits')
 subdir('qemu-api')
@@ -33,5 +35,5 @@ if cargo.found()
     command: [config_host['MESON'], 'devenv',
               '--workdir', '@CURRENT_SOURCE_DIR@',
               cargo, 'fmt'],
-    depends: _qemu_api_bindings_inc_rs)
+    depends: genrs)
 endif
rust/qemu-api/build.rs +1 -1
index 1e720641d2b..7849486c1ba 100644
@@ -14,7 +14,7 @@ fn main() -> Result<()> {
     let path = env::var("MESON_BUILD_ROOT")
         .unwrap_or_else(|_| format!("{}/src", env!("CARGO_MANIFEST_DIR")));
 
-    let file = format!("{path}/bindings.inc.rs");
+    let file = format!("{path}/rust/qemu-api/bindings.inc.rs");
     let file = Path::new(&file);
     if !Path::new(&file).exists() {
         panic!(concat!(
rust/qemu-api/meson.build +41 -0

47 lines not on this page · raw message

Signature · 1 line
2.49.0
#18 lore raw

[PULL 16/24] i386/cpu: Move adjustment of CPUID_EXT_PDCM before feature_dependencies[] check

In reply to Paolo Bonzini

From: Xiaoyao Li <[email protected]>

There is one entry relates to CPUID_EXT_PDCM in feature_dependencies[]. So it needs to get correct value of CPUID_EXT_PDCM before using feature_dependencies[] to apply dependencies.

Besides, it also ensures CPUID_EXT_PDCM value is tracked in env->features[FEAT_1_ECX].

---
 target/i386/cpu.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
target/i386/cpu.c +4 -3
index 40aefb38f6d..29bce67c3a1 100644
@@ -7349,9 +7349,6 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
         if (threads_per_pkg > 1) {
             *ebx |= threads_per_pkg << 16;
         }
-        if (!cpu->enable_pmu) {
-            *ecx &= ~CPUID_EXT_PDCM;
-        }
         break;
     case 2:
         /* cache info: needed for Pentium Pro compatibility */
@@ -8341,6 +8338,10 @@ void x86_cpu_expand_features(X86CPU *cpu, Error **errp)
         }
     }
 
+    if (!cpu->enable_pmu) {
+        env->features[FEAT_1_ECX] &= ~CPUID_EXT_PDCM;
+    }
+
     for (i = 0; i < ARRAY_SIZE(feature_dependencies); i++) {
         FeatureDep *d = &feature_dependencies[i];
         if (!(env->features[d->from.index] & d->from.mask)) {
Signature · 1 line
2.49.0
#19 lore raw

[PULL 02/24] target/i386: fix TB exit logic in gen_movl_seg() when writing to SS

In reply to Paolo Bonzini

From: Mark Cave-Ayland <[email protected]>

Before commit e54ef98c8a ("target/i386: do not trigger IRQ shadow for LSS"), any write to SS in gen_movl_seg() would cause a TB exit. The changes introduced by this commit were intended to restrict the DISAS_EOB_INHIBIT_IRQ exit to the case where inhibit_irq is true, but missed that a DISAS_EOB_NEXT exit can still be required when writing to SS and inhibit_irq is false.

Comparing the PE(s) && !VM86(s) section with the logic in x86_update_hflags(), we can see that the DISAS_EOB_NEXT exit is still required for the !CODE32 case when writing to SS in gen_movl_seg() because any change to the SS flags can affect hflags. Similarly we can see that the existing CODE32 case is still correct since a change to any of DS, ES and SS can affect hflags. Finally for the gen_op_movl_seg_real() case an explicit TB exit is not needed because the segment register selector does not affect hflags.

Update the logic in gen_movl_seg() so that a write to SS with inhibit_irq set to false where PE(s) && !VM86(s) will generate a DISAS_EOB_NEXT exit along with the inline comment. This has the effect of allowing Win98SE to boot in QEMU once again.

Fixes e54ef98c8a ("target/i386: do not trigger IRQ shadow for LSS")

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2987

---
 target/i386/tcg/translate.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
target/i386/tcg/translate.c +5 -2
index 0fcddc2ec08..0cb87d02012 100644
@@ -2033,8 +2033,11 @@ static void gen_movl_seg(DisasContext *s, X86Seg seg_reg, TCGv src, bool inhibit
         tcg_gen_trunc_tl_i32(sel, src);
         gen_helper_load_seg(tcg_env, tcg_constant_i32(seg_reg), sel);
 
-        /* For move to DS/ES/SS, the addseg or ss32 flags may change.  */
-        if (CODE32(s) && seg_reg < R_FS) {
+        /*
+         * For moves to SS, the SS32 flag may change. For CODE32 only, changes
+         * to SS, DS and ES may change the ADDSEG flags.
+         */
+        if (seg_reg == R_SS || (CODE32(s) && seg_reg < R_FS)) {
             s->base.is_jmp = DISAS_EOB_NEXT;
         }
     } else {
Signature · 1 line
2.49.0
#20 lore raw

[PULL 13/24] rust: pl011: Implement logging

In reply to Paolo Bonzini

From: Bernhard Beschow <[email protected]>

Now that there is logging support in Rust for QEMU, use it in the pl011 device.

---
 rust/hw/char/pl011/src/device.rs | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
rust/hw/char/pl011/src/device.rs +8 -4
index 2d416cd9a3c..92dc295540e 100644
@@ -8,6 +8,8 @@
     chardev::{CharBackend, Chardev, Event},
     impl_vmstate_forward,
     irq::{IRQState, InterruptSource},
+    log::Log,
+    log_mask_ln,
     memory::{hwaddr, MemoryRegion, MemoryRegionOps, MemoryRegionOpsBuilder},
     prelude::*,
     qdev::{Clock, ClockEvent, DeviceImpl, DeviceState, Property, ResetType, ResettablePhasesImpl},
@@ -276,8 +278,7 @@ pub(self) fn write(
             DMACR => {
                 self.dmacr = value;
                 if value & 3 > 0 {
-                    // qemu_log_mask(LOG_UNIMP, "pl011: DMA not implemented\n");
-                    eprintln!("pl011: DMA not implemented");
+                    log_mask_ln!(Log::Unimp, "pl011: DMA not implemented");
                 }
             }
         }
@@ -534,7 +535,7 @@ fn read(&self, offset: hwaddr, _size: u32) -> u64 {
                 u64::from(device_id[(offset - 0xfe0) >> 2])
             }
             Err(_) => {
-                // qemu_log_mask(LOG_GUEST_ERROR, "pl011_read: Bad offset 0x%x\n", (int)offset);
+                log_mask_ln!(Log::GuestError, "PL011State::read: Bad offset {offset}");
                 0
             }
             Ok(field) => {
@@ -566,7 +567,10 @@ fn write(&self, offset: hwaddr, value: u64, _size: u32) {
                 .borrow_mut()
                 .write(field, value as u32, &self.char_backend);
         } else {
-            eprintln!("write bad offset {offset} value {value}");
+            log_mask_ln!(
+                Log::GuestError,
+                "PL011State::write: Bad offset {offset} value {value}"
+            );
         }
         if update_irq {
             self.update();
Signature · 1 line
2.49.0
#21 lore raw

[PULL 23/24] i386/tdx: handle TDG.VP.VMCALL<GetTdVmCallInfo>

In reply to Paolo Bonzini

From: Binbin Wu <[email protected]>

---
 target/i386/kvm/tdx.h      |  9 +++++++++
 target/i386/kvm/kvm.c      | 12 ++++++++++++
 target/i386/kvm/tdx-stub.c |  4 ++++
 target/i386/kvm/tdx.c      | 12 ++++++++++++
 4 files changed, 37 insertions(+)
target/i386/kvm/tdx.h +9 -0
index 8dd66e90149..0dd41d5811a 100644
@@ -21,6 +21,14 @@ typedef struct TdxGuestClass {
 /* TDX requires bus frequency 25MHz */
 #define TDX_APIC_BUS_CYCLES_NS 40
 
+#define TDVMCALL_GET_TD_VM_CALL_INFO    0x10000
+
+#define TDG_VP_VMCALL_SUCCESS           0x0000000000000000ULL
+#define TDG_VP_VMCALL_RETRY             0x0000000000000001ULL
+#define TDG_VP_VMCALL_INVALID_OPERAND   0x8000000000000000ULL
+#define TDG_VP_VMCALL_GPA_INUSE         0x8000000000000001ULL
+#define TDG_VP_VMCALL_ALIGN_ERROR       0x8000000000000002ULL
+
 enum TdxRamType {
     TDX_RAM_UNACCEPTED,
     TDX_RAM_ADDED,
@@ -61,5 +69,6 @@ int tdx_pre_create_vcpu(CPUState *cpu, Error **errp);
 void tdx_set_tdvf_region(MemoryRegion *tdvf_mr);
 int tdx_parse_tdvf(void *flash_ptr, int size);
 int tdx_handle_report_fatal_error(X86CPU *cpu, struct kvm_run *run);
+void tdx_handle_get_tdvmcall_info(X86CPU *cpu, struct kvm_run *run);
 
 #endif /* QEMU_I386_TDX_H */
target/i386/kvm/kvm.c +12 -0
index 56a6b9b6381..8ef29fc1fb1 100644
@@ -6170,6 +6170,18 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
             break;
         }
         break;
+    case KVM_EXIT_TDX:
+        /*
+         * run->tdx is already set up for the case where userspace
+         * does not handle the TDVMCALL.
+         */
+        switch (run->tdx.nr) {
+        case TDVMCALL_GET_TD_VM_CALL_INFO:
+            tdx_handle_get_tdvmcall_info(cpu, run);
+            break;
+        }
+        ret = 0;
+        break;
     default:
         fprintf(stderr, "KVM: unknown exit reason %d\n", run->exit_reason);
         ret = -1;
target/i386/kvm/tdx-stub.c +4 -0
index 720a4ff046e..62a12a06775 100644
@@ -18,3 +18,7 @@ int tdx_handle_report_fatal_error(X86CPU *cpu, struct kvm_run *run)
 {
     return -EINVAL;
 }
+
+void tdx_handle_get_tdvmcall_info(X86CPU *cpu, struct kvm_run *run)
+{
+}
target/i386/kvm/tdx.c +12 -0
index 2284167141a..ef10a193474 100644
@@ -1120,6 +1120,18 @@ int tdx_parse_tdvf(void *flash_ptr, int size)
     return tdvf_parse_metadata(&tdx_guest->tdvf, flash_ptr, size);
 }
 
+void tdx_handle_get_tdvmcall_info(X86CPU *cpu, struct kvm_run *run)
+{
+    if (run->tdx.get_tdvmcall_info.leaf != 1) {
+	return;
+    }
+
+    run->tdx.get_tdvmcall_info.r11 = 0;
+    run->tdx.get_tdvmcall_info.r12 = 0;
+    run->tdx.get_tdvmcall_info.r13 = 0;
+    run->tdx.get_tdvmcall_info.r14 = 0;
+}
+
 static void tdx_panicked_on_fatal_error(X86CPU *cpu, uint64_t error_code,
                                         char *message, uint64_t gpa)
 {
Signature · 1 line
2.49.0
#22 lore raw

[PULL 24/24] i386/tdx: handle TDG.VP.VMCALL<GetQuote>

In reply to Paolo Bonzini

From: Isaku Yamahata <[email protected]>

Add property "quote-generation-socket" to tdx-guest, which is a property of type SocketAddress to specify Quote Generation Service(QGS).

On request of GetQuote, it connects to the QGS socket, read request data from shared guest memory, send the request data to the QGS, and store the response into shared guest memory, at last notify TD guest by interrupt.

command line example:

  qemu-system-x86_64 \
    -object '{"qom-type":"tdx-guest","id":"tdx0","quote-generation-socket":{"type":"unix", "path":"/var/run/tdx-qgs/qgs.socket"}}' \
    -machine confidential-guest-support=tdx0

Note, above example uses the unix socket. It can be other types, like vsock, which depends on the implementation of QGS.

To avoid no response from QGS server, setup a timer for the transaction. If timeout, make it an error and interrupt guest. Define the threshold of time to 30s at present, maybe change to other value if not appropriate.

---
 qapi/qom.json                         |   8 +-
 target/i386/kvm/tdx-quote-generator.h |  82 +++++++
 target/i386/kvm/tdx.h                 |  10 +
 target/i386/kvm/kvm.c                 |   3 +
 target/i386/kvm/tdx-quote-generator.c | 300 ++++++++++++++++++++++++++
 target/i386/kvm/tdx-stub.c            |   4 +
 target/i386/kvm/tdx.c                 | 176 ++++++++++++++-
 target/i386/kvm/meson.build           |   2 +-
 8 files changed, 582 insertions(+), 3 deletions(-)
 create mode 100644 target/i386/kvm/tdx-quote-generator.h
 create mode 100644 target/i386/kvm/tdx-quote-generator.c
qapi/qom.json +7 -1
index 3e8debf78c2..b133b064471 100644
@@ -1071,6 +1071,11 @@
 #     e.g., specific to the workload rather than the run-time or OS
 #     (base64 encoded SHA384 digest).  Defaults to all zeros.
 #
+# @quote-generation-socket: socket address for Quote Generation
+#     Service (QGS).  QGS is a daemon running on the host.  Without
+#     it, the guest will not be able to get a TD quote for
+#     attestation.
+#
 # Since: 10.1
 ##
 { 'struct': 'TdxGuestProperties',
@@ -1078,7 +1083,8 @@
             '*sept-ve-disable': 'bool',
             '*mrconfigid': 'str',
             '*mrowner': 'str',
-            '*mrownerconfig': 'str' } }
+            '*mrownerconfig': 'str',
+            '*quote-generation-socket': 'SocketAddress' } }
 
 ##
 # @ThreadContextProperties:
target/i386/kvm/tdx-quote-generator.h new file +82 -0

82 lines not on this page · raw message

target/i386/kvm/tdx.h +10 -0
index 0dd41d5811a..35a09c19c52 100644
@@ -11,6 +11,8 @@
 #include "cpu.h"
 #include "hw/i386/tdvf.h"
 
+#include "tdx-quote-generator.h"
+
 #define TYPE_TDX_GUEST "tdx-guest"
 #define TDX_GUEST(obj)  OBJECT_CHECK(TdxGuest, (obj), TYPE_TDX_GUEST)
 
@@ -22,6 +24,7 @@ typedef struct TdxGuestClass {
 #define TDX_APIC_BUS_CYCLES_NS 40
 
 #define TDVMCALL_GET_TD_VM_CALL_INFO    0x10000
+#define TDVMCALL_GET_QUOTE		 0x10002
 
 #define TDG_VP_VMCALL_SUCCESS           0x0000000000000000ULL
 #define TDG_VP_VMCALL_RETRY             0x0000000000000001ULL
@@ -29,6 +32,8 @@ typedef struct TdxGuestClass {
 #define TDG_VP_VMCALL_GPA_INUSE         0x8000000000000001ULL
 #define TDG_VP_VMCALL_ALIGN_ERROR       0x8000000000000002ULL
 
+#define TDG_VP_VMCALL_SUBFUNC_GET_QUOTE 0x0000000000000001ULL
+
 enum TdxRamType {
     TDX_RAM_UNACCEPTED,
     TDX_RAM_ADDED,
@@ -57,6 +62,10 @@ typedef struct TdxGuest {
 
     uint32_t nr_ram_entries;
     TdxRamEntry *ram_entries;
+
+    /* GetQuote */
+    SocketAddress *qg_sock_addr;
+    int num;
 } TdxGuest;
 
 #ifdef CONFIG_TDX
@@ -69,6 +78,7 @@ int tdx_pre_create_vcpu(CPUState *cpu, Error **errp);
 void tdx_set_tdvf_region(MemoryRegion *tdvf_mr);
 int tdx_parse_tdvf(void *flash_ptr, int size);
 int tdx_handle_report_fatal_error(X86CPU *cpu, struct kvm_run *run);
+void tdx_handle_get_quote(X86CPU *cpu, struct kvm_run *run);
 void tdx_handle_get_tdvmcall_info(X86CPU *cpu, struct kvm_run *run);
 
 #endif /* QEMU_I386_TDX_H */
target/i386/kvm/kvm.c +3 -0
index 8ef29fc1fb1..234878c613f 100644
@@ -6176,6 +6176,9 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run)
          * does not handle the TDVMCALL.
          */
         switch (run->tdx.nr) {
+        case TDVMCALL_GET_QUOTE:
+            tdx_handle_get_quote(cpu, run);
+            break;
         case TDVMCALL_GET_TD_VM_CALL_INFO:
             tdx_handle_get_tdvmcall_info(cpu, run);
             break;
target/i386/kvm/tdx-quote-generator.c new file +300 -0

300 lines not on this page · raw message

target/i386/kvm/tdx-stub.c +4 -0
index 62a12a06775..76fee49eff0 100644
@@ -19,6 +19,10 @@ int tdx_handle_report_fatal_error(X86CPU *cpu, struct kvm_run *run)
     return -EINVAL;
 }
 
+void tdx_handle_get_quote(X86CPU *cpu, struct kvm_run *run)
+{
+}
+
 void tdx_handle_get_tdvmcall_info(X86CPU *cpu, struct kvm_run *run)
 {
 }
target/i386/kvm/tdx.c +175 -1

218 lines not on this page · raw message

target/i386/kvm/meson.build +1 -1
index 3f44cdedb75..2675bf89027 100644
@@ -8,7 +8,7 @@ i386_kvm_ss.add(files(
 
 i386_kvm_ss.add(when: 'CONFIG_XEN_EMU', if_true: files('xen-emu.c'))
 
-i386_kvm_ss.add(when: 'CONFIG_TDX', if_true: files('tdx.c'), if_false: files('tdx-stub.c'))
+i386_kvm_ss.add(when: 'CONFIG_TDX', if_true: files('tdx.c', 'tdx-quote-generator.c'), if_false: files('tdx-stub.c'))
 
 i386_system_ss.add(when: 'CONFIG_HYPERV', if_true: files('hyperv.c'), if_false: files('hyperv-stub.c'))
 
Signature · 1 line
2.49.0
#23 lore raw

Re: [PULL 24/24] i386/tdx: handle TDG.VP.VMCALL<GetQuote>

Hello,

Quoted 39 lines · Paolo Bonzini

From: Isaku Yamahata <[email protected]>

Add property "quote-generation-socket" to tdx-guest, which is a property of type SocketAddress to specify Quote Generation Service(QGS).

On request of GetQuote, it connects to the QGS socket, read request data from shared guest memory, send the request data to the QGS, and store the response into shared guest memory, at last notify TD guest by interrupt.

command line example:

   qemu-system-x86_64 \
     -object '{"qom-type":"tdx-guest","id":"tdx0","quote-generation-socket":{"type":"unix", "path":"/var/run/tdx-qgs/qgs.socket"}}' \
     -machine confidential-guest-support=tdx0

Note, above example uses the unix socket. It can be other types, like vsock, which depends on the implementation of QGS.

To avoid no response from QGS server, setup a timer for the transaction. If timeout, make it an error and interrupt guest. Define the threshold of time to 30s at present, maybe change to other value if not appropriate.

---
  qapi/qom.json                         |   8 +-
  target/i386/kvm/tdx-quote-generator.h |  82 +++++++
  target/i386/kvm/tdx.h                 |  10 +
  target/i386/kvm/kvm.c                 |   3 +
  target/i386/kvm/tdx-quote-generator.c | 300 ++++++++++++++++++++++++++
  target/i386/kvm/tdx-stub.c            |   4 +
  target/i386/kvm/tdx.c                 | 176 ++++++++++++++-
  target/i386/kvm/meson.build           |   2 +-
  8 files changed, 582 insertions(+), 3 deletions(-)
Quoted 2 lines

create mode 100644 target/i386/kvm/tdx-quote-generator.h create mode 100644 target/i386/kvm/tdx-quote-generator.c

These changes broke the build on 32-bit host.

Could you please send a patch to avoid compiling TDX in such environment ?

Thanks,

C.

#24 lore raw

Re: [PULL 24/24] i386/tdx: handle TDG.VP.VMCALL<GetQuote>

Quoted 45 lines · Cédric Le Goater

Hello,

Quoted 38 lines · Paolo Bonzini

From: Isaku Yamahata <[email protected]>

Add property "quote-generation-socket" to tdx-guest, which is a property of type SocketAddress to specify Quote Generation Service(QGS).

On request of GetQuote, it connects to the QGS socket, read request data from shared guest memory, send the request data to the QGS, and store the response into shared guest memory, at last notify TD guest by interrupt.

command line example:
   qemu-system-x86_64 \
     -object '{"qom-type":"tdx-guest","id":"tdx0","quote-generation- socket":{"type":"unix", "path":"/var/run/tdx-qgs/qgs.socket"}}' \
     -machine confidential-guest-support=tdx0

Note, above example uses the unix socket. It can be other types, like vsock, which depends on the implementation of QGS.

To avoid no response from QGS server, setup a timer for the transaction. If timeout, make it an error and interrupt guest. Define the threshold of time to 30s at present, maybe change to other value if not appropriate.

---
  qapi/qom.json                         |   8 +- target/i386/kvm/tdx-quote-generator.h |  82 +++++++ target/i386/kvm/tdx.h                 |  10 + target/i386/kvm/kvm.c                 |   3 + target/i386/kvm/tdx-quote-generator.c | 300 ++++++++++++++++++++++++++ target/i386/kvm/tdx-stub.c            |   4 + target/i386/kvm/tdx.c                 | 176 ++++++++++++++- target/i386/kvm/meson.build           |   2 +-

Quoted 3 lines
  8 files changed, 582 insertions(+), 3 deletions(-)

  create mode 100644 target/i386/kvm/tdx-quote-generator.h create mode 100644 target/i386/kvm/tdx-quote-generator.c

Quoted 3 lines

These changes broke the build on 32-bit host.

Could you please send a patch to avoid compiling TDX in such environment ?

Paolo is on vacation.

I would like to help, but I don't have 32-bit host environment on hand. Do you know how to set up such environment quickly? (I tried to set up within a 32-bit VM but the 32-bit OS is too old and I didn't get it work to install the required package for building QEMU)

Quoted 3 lines

Thanks,

C.

#25 lore raw

Re: [PULL 24/24] i386/tdx: handle TDG.VP.VMCALL<GetQuote>

Quoted 46 lines · Xiaoyao Li
Quoted 45 lines · Cédric Le Goater

Hello,

Quoted 41 lines · Paolo Bonzini

From: Isaku Yamahata <[email protected]>

Add property "quote-generation-socket" to tdx-guest, which is a property of type SocketAddress to specify Quote Generation Service(QGS).

On request of GetQuote, it connects to the QGS socket, read request data from shared guest memory, send the request data to the QGS, and store the response into shared guest memory, at last notify TD guest by interrupt.

command line example:
   qemu-system-x86_64 \
     -object '{"qom-type":"tdx-guest","id":"tdx0","quote-generation- socket":{"type":"unix", "path":"/var/run/tdx-qgs/qgs.socket"}}' \
     -machine confidential-guest-support=tdx0

Note, above example uses the unix socket. It can be other types, like vsock, which depends on the implementation of QGS.

To avoid no response from QGS server, setup a timer for the transaction. If timeout, make it an error and interrupt guest. Define the threshold of time to 30s at present, maybe change to other value if not appropriate.

---
  qapi/qom.json                         |   8 +- target/i386/kvm/tdx-quote-generator.h |  82 +++++++ target/i386/kvm/tdx.h                 |  10 + target/i386/kvm/kvm.c                 |   3 + target/i386/kvm/tdx-quote-generator.c | 300 ++++++++++++++++++++++++++ target/i386/kvm/tdx-stub.c            |   4 + target/i386/kvm/tdx.c                 | 176 ++++++++++++++- target/i386/kvm/meson.build           |   2 +-

  8 files changed, 582 insertions(+), 3 deletions(-)

  create mode 100644 target/i386/kvm/tdx-quote-generator.h create mode 100644 target/i386/kvm/tdx-quote-generator.c

Quoted 6 lines
Quoted 3 lines

These changes broke the build on 32-bit host.

Could you please send a patch to avoid compiling TDX in such environment ?

Paolo is on vacation.

Quoted 1 line

I would like to help, but I don't have 32-bit host environment on hand. Do you know how to set up such environment quickly? (I tried to set up within a 32-bit VM but the 32-bit OS is too old and I didn't get it work to install the required package for building QEMU)

debian should work fine :

  $ uname -a
  Linux vm15 6.10.12-686-pae #1 SMP PREEMPT_DYNAMIC Debian 6.10.12-1 (2024-10-01) i686 GNU/Linux
  $ cat /etc/os-release
  PRETTY_NAME="Debian GNU/Linux trixie/sid"
  NAME="Debian GNU/Linux"
  ...

Thanks,

C.

#26 lore raw

Re: [PULL 24/24] i386/tdx: handle TDG.VP.VMCALL<GetQuote>

In reply to Xiaoyao Li
Quoted 50 lines · Xiaoyao Li
Quoted 49 lines · Cédric Le Goater

Hello,

Quoted 40 lines · Paolo Bonzini

From: Isaku Yamahata <[email protected]>

Add property "quote-generation-socket" to tdx-guest, which is a property of type SocketAddress to specify Quote Generation Service(QGS).

On request of GetQuote, it connects to the QGS socket, read request data from shared guest memory, send the request data to the QGS, and store the response into shared guest memory, at last notify TD guest by interrupt.

command line example:
   qemu-system-x86_64 \
     -object '{"qom-type":"tdx-guest","id":"tdx0","quote-generation- socket":{"type":"unix", "path":"/var/run/tdx-qgs/qgs.socket"}}' \
     -machine confidential-guest-support=tdx0

Note, above example uses the unix socket. It can be other types, like vsock,
which depends on the implementation of QGS.

To avoid no response from QGS server, setup a timer for the transaction. If timeout, make it an error and interrupt guest. Define the threshold of time to 30s at present, maybe change to other value if not appropriate.

---
  qapi/qom.json                         |   8 +- target/i386/kvm/tdx-quote-generator.h |  82 +++++++ target/i386/kvm/tdx.h                 |  10 + target/i386/kvm/kvm.c                 |   3 + target/i386/kvm/tdx-quote-generator.c | 300 ++++++++++++++++++++++++++ target/i386/kvm/tdx-stub.c            |   4 + target/i386/kvm/tdx.c                 | 176 ++++++++++++++- target/i386/kvm/meson.build           |   2 +-

Quoted 3 lines
  8 files changed, 582 insertions(+), 3 deletions(-)

  create mode 100644 target/i386/kvm/tdx-quote-generator.h create mode 100644 target/i386/kvm/tdx-quote-generator.c

These changes broke the build on 32-bit host.

Quoted 8 lines
Quoted 1 line

Could you please send a patch to avoid compiling TDX in such environment ?

Paolo is on vacation.

I would like to help, but I don't have 32-bit host environment on hand. Do you know how to set up such environment quickly? (I tried to set up within a 32-bit VM but the 32-bit OS is too old and I didn't get it work to install the required package for building QEMU)

You should be able to use QEMU's docker containers to get yourself a Debian i386 container, on a x86_64 host.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#27 lore raw

Re: [PULL 24/24] i386/tdx: handle TDG.VP.VMCALL<GetQuote>

Quoted 56 lines · Daniel P. Berrangé
Quoted 54 lines · Xiaoyao Li
Quoted 47 lines · Cédric Le Goater

Hello,

Quoted 41 lines · Paolo Bonzini

From: Isaku Yamahata <[email protected]>

Add property "quote-generation-socket" to tdx-guest, which is a property of type SocketAddress to specify Quote Generation Service(QGS).

On request of GetQuote, it connects to the QGS socket, read request data from shared guest memory, send the request data to the QGS, and store the response into shared guest memory, at last notify TD guest by interrupt.

command line example:

   qemu-system-x86_64 \
     -object '{"qom-type":"tdx-guest","id":"tdx0","quote-generation-

socket":{"type":"unix", "path":"/var/run/tdx-qgs/qgs.socket"}}' \
-machine confidential-guest-support=tdx0

Note, above example uses the unix socket. It can be other types, like vsock,
which depends on the implementation of QGS.

To avoid no response from QGS server, setup a timer for the transaction. If timeout, make it an error and interrupt guest. Define the threshold of time to 30s at present, maybe change to other value if not appropriate.

---
  qapi/qom.json                         |   8 +-
  target/i386/kvm/tdx-quote-generator.h |  82 +++++++
  target/i386/kvm/tdx.h                 |  10 +
  target/i386/kvm/kvm.c                 |   3 +
  target/i386/kvm/tdx-quote-generator.c | 300 ++++++++++++++++++++++++++
  target/i386/kvm/tdx-stub.c            |   4 +
  target/i386/kvm/tdx.c                 | 176 ++++++++++++++-
  target/i386/kvm/meson.build           |   2 +-
  8 files changed, 582 insertions(+), 3 deletions(-)
Quoted 2 lines

create mode 100644 target/i386/kvm/tdx-quote-generator.h create mode 100644 target/i386/kvm/tdx-quote-generator.c

Quoted 3 lines

These changes broke the build on 32-bit host.

Could you please send a patch to avoid compiling TDX in such environment ?

Paolo is on vacation.

Quoted 7 lines
Quoted 4 lines

I would like to help, but I don't have 32-bit host environment on hand. Do you know how to set up such environment quickly? (I tried to set up within a 32-bit VM but the 32-bit OS is too old and I didn't get it work to install the required package for building QEMU)

You should be able to use QEMU's docker containers to get yourself a Debian i386 container, on a x86_64 host.

The cross-i686-system (Debian) build CI job succeeded:
https://gitlab.com/qemu-project/qemu/-/jobs/10423776600

I wonder why the CI didn't catch the issue?

Stefan

#28 lore raw

Re: [PULL 24/24] i386/tdx: handle TDG.VP.VMCALL<GetQuote>

Quoted 62 lines · Stefan Hajnoczi
Quoted 61 lines · Daniel P. Berrangé
Quoted 58 lines · Xiaoyao Li
Quoted 47 lines · Cédric Le Goater

Hello,

Quoted 41 lines · Paolo Bonzini

From: Isaku Yamahata <[email protected]>

Add property "quote-generation-socket" to tdx-guest, which is a property of type SocketAddress to specify Quote Generation Service(QGS).

On request of GetQuote, it connects to the QGS socket, read request data from shared guest memory, send the request data to the QGS, and store the response into shared guest memory, at last notify TD guest by interrupt.

command line example:

   qemu-system-x86_64 \
     -object '{"qom-type":"tdx-guest","id":"tdx0","quote-generation-

socket":{"type":"unix", "path":"/var/run/tdx-qgs/qgs.socket"}}' \
-machine confidential-guest-support=tdx0

Note, above example uses the unix socket. It can be other types, like vsock,
which depends on the implementation of QGS.

To avoid no response from QGS server, setup a timer for the transaction. If timeout, make it an error and interrupt guest. Define the threshold of time to 30s at present, maybe change to other value if not appropriate.

---
  qapi/qom.json                         |   8 +-
  target/i386/kvm/tdx-quote-generator.h |  82 +++++++
  target/i386/kvm/tdx.h                 |  10 +
  target/i386/kvm/kvm.c                 |   3 +
  target/i386/kvm/tdx-quote-generator.c | 300 ++++++++++++++++++++++++++
  target/i386/kvm/tdx-stub.c            |   4 +
  target/i386/kvm/tdx.c                 | 176 ++++++++++++++-
  target/i386/kvm/meson.build           |   2 +-
  8 files changed, 582 insertions(+), 3 deletions(-)
Quoted 2 lines

create mode 100644 target/i386/kvm/tdx-quote-generator.h create mode 100644 target/i386/kvm/tdx-quote-generator.c

Quoted 3 lines

These changes broke the build on 32-bit host.

Could you please send a patch to avoid compiling TDX in such environment ?

Paolo is on vacation.

I would like to help, but I don't have 32-bit host environment on hand. Do you know how to set up such environment quickly? (I tried to set up within a 32-bit VM but the 32-bit OS is too old and I didn't get it work to install the required package for building QEMU)

Quoted 7 lines
Quoted 2 lines

You should be able to use QEMU's docker containers to get yourself a Debian i386 container, on a x86_64 host.

The cross-i686-system (Debian) build CI job succeeded:
https://gitlab.com/qemu-project/qemu/-/jobs/10423776600

I wonder why the CI didn't catch the issue?

It didn't build the x86_64 target:

--target-list-exclude="arm-softmmu i386-softmmu microblaze-softmmu mips-softmmu mipsel-softmmu mips64-softmmu ppc-softmmu riscv32-softmmu sh4-softmmu sparc-softmmu xtensa-softmmu $CROSS_SKIP_TARGETS"

so in turn didn't build any TDX code

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#29 lore raw

Re: [PULL 24/24] i386/tdx: handle TDG.VP.VMCALL<GetQuote>

Quoted 70 lines · Daniel P. Berrangé
Quoted 68 lines · Stefan Hajnoczi
Quoted 56 lines · Daniel P. Berrangé
Quoted 54 lines · Xiaoyao Li
Quoted 47 lines · Cédric Le Goater

Hello,

Quoted 41 lines · Paolo Bonzini

From: Isaku Yamahata <[email protected]>

Add property "quote-generation-socket" to tdx-guest, which is a property of type SocketAddress to specify Quote Generation Service(QGS).

On request of GetQuote, it connects to the QGS socket, read request data from shared guest memory, send the request data to the QGS, and store the response into shared guest memory, at last notify TD guest by interrupt.

command line example:

   qemu-system-x86_64 \
     -object '{"qom-type":"tdx-guest","id":"tdx0","quote-generation-

socket":{"type":"unix", "path":"/var/run/tdx-qgs/qgs.socket"}}' \
-machine confidential-guest-support=tdx0

Note, above example uses the unix socket. It can be other types, like vsock,
which depends on the implementation of QGS.

To avoid no response from QGS server, setup a timer for the transaction. If timeout, make it an error and interrupt guest. Define the threshold of time to 30s at present, maybe change to other value if not appropriate.

---
  qapi/qom.json                         |   8 +-
  target/i386/kvm/tdx-quote-generator.h |  82 +++++++
  target/i386/kvm/tdx.h                 |  10 +
  target/i386/kvm/kvm.c                 |   3 +
  target/i386/kvm/tdx-quote-generator.c | 300 ++++++++++++++++++++++++++
  target/i386/kvm/tdx-stub.c            |   4 +
  target/i386/kvm/tdx.c                 | 176 ++++++++++++++-
  target/i386/kvm/meson.build           |   2 +-
  8 files changed, 582 insertions(+), 3 deletions(-)
Quoted 2 lines

create mode 100644 target/i386/kvm/tdx-quote-generator.h create mode 100644 target/i386/kvm/tdx-quote-generator.c

Quoted 3 lines

These changes broke the build on 32-bit host.

Could you please send a patch to avoid compiling TDX in such environment ?

Paolo is on vacation.

Quoted 7 lines
Quoted 4 lines

I would like to help, but I don't have 32-bit host environment on hand. Do you know how to set up such environment quickly? (I tried to set up within a 32-bit VM but the 32-bit OS is too old and I didn't get it work to install the required package for building QEMU)

You should be able to use QEMU's docker containers to get yourself a Debian i386 container, on a x86_64 host.

The cross-i686-system (Debian) build CI job succeeded:
https://gitlab.com/qemu-project/qemu/-/jobs/10423776600

Quoted 7 lines
Quoted 1 line

I wonder why the CI didn't catch the issue?

It didn't build the x86_64 target:

--target-list-exclude="arm-softmmu i386-softmmu microblaze-softmmu mips-softmmu mipsel-softmmu mips64-softmmu ppc-softmmu riscv32-softmmu sh4-softmmu sparc-softmmu xtensa-softmmu $CROSS_SKIP_TARGETS"

so in turn didn't build any TDX code

Here are the targets that were built by the CI job:

target list : avr-softmmu m68k-softmmu microblazeel-softmmu
or1k-softmmu rx-softmmu sh4eb-softmmu tricore-softmmu xtensaeb-softmmu

64-bit targets are not supported on 32-bit hosts since commit acce728cbc6c ("meson: Disallow 64-bit on 32-bit emulation"). I don't think the x86_64 target can be built on 32-bit hosts.

But notice that i386-softmmu is missing from the target list. That could be why the CI job succeeded.

Cédric: What were your ./configure options?

Stefan

Quoted 8 lines

With regards,
Daniel
--

|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#30 lore raw

Re: [PULL 24/24] i386/tdx: handle TDG.VP.VMCALL<GetQuote>

Quoted 84 lines · Stefan Hajnoczi
Quoted 70 lines · Daniel P. Berrangé
Quoted 68 lines · Stefan Hajnoczi
Quoted 56 lines · Daniel P. Berrangé
Quoted 54 lines · Xiaoyao Li
Quoted 47 lines · Cédric Le Goater

Hello,

Quoted 41 lines · Paolo Bonzini

From: Isaku Yamahata <[email protected]>

Add property "quote-generation-socket" to tdx-guest, which is a property of type SocketAddress to specify Quote Generation Service(QGS).

On request of GetQuote, it connects to the QGS socket, read request data from shared guest memory, send the request data to the QGS, and store the response into shared guest memory, at last notify TD guest by interrupt.

command line example:

    qemu-system-x86_64 \
      -object '{"qom-type":"tdx-guest","id":"tdx0","quote-generation-

socket":{"type":"unix", "path":"/var/run/tdx-qgs/qgs.socket"}}' \
-machine confidential-guest-support=tdx0

Note, above example uses the unix socket. It can be other types, like vsock,
which depends on the implementation of QGS.

To avoid no response from QGS server, setup a timer for the transaction. If timeout, make it an error and interrupt guest. Define the threshold of time to 30s at present, maybe change to other value if not appropriate.

---
   qapi/qom.json                         |   8 +-
   target/i386/kvm/tdx-quote-generator.h |  82 +++++++
   target/i386/kvm/tdx.h                 |  10 +
   target/i386/kvm/kvm.c                 |   3 +
   target/i386/kvm/tdx-quote-generator.c | 300 ++++++++++++++++++++++++++
   target/i386/kvm/tdx-stub.c            |   4 +
   target/i386/kvm/tdx.c                 | 176 ++++++++++++++-
   target/i386/kvm/meson.build           |   2 +-
   8 files changed, 582 insertions(+), 3 deletions(-)
Quoted 2 lines

create mode 100644 target/i386/kvm/tdx-quote-generator.h create mode 100644 target/i386/kvm/tdx-quote-generator.c

Quoted 3 lines

These changes broke the build on 32-bit host.

Could you please send a patch to avoid compiling TDX in such environment ?

Paolo is on vacation.

Quoted 7 lines
Quoted 4 lines

I would like to help, but I don't have 32-bit host environment on hand. Do you know how to set up such environment quickly? (I tried to set up within a 32-bit VM but the 32-bit OS is too old and I didn't get it work to install the required package for building QEMU)

You should be able to use QEMU's docker containers to get yourself a Debian i386 container, on a x86_64 host.

The cross-i686-system (Debian) build CI job succeeded:
https://gitlab.com/qemu-project/qemu/-/jobs/10423776600

Quoted 7 lines
Quoted 1 line

I wonder why the CI didn't catch the issue?

It didn't build the x86_64 target:

--target-list-exclude="arm-softmmu i386-softmmu microblaze-softmmu mips-softmmu mipsel-softmmu mips64-softmmu ppc-softmmu riscv32-softmmu sh4-softmmu sparc-softmmu xtensa-softmmu $CROSS_SKIP_TARGETS"

so in turn didn't build any TDX code

Here are the targets that were built by the CI job:

target list : avr-softmmu m68k-softmmu microblazeel-softmmu
or1k-softmmu rx-softmmu sh4eb-softmmu tricore-softmmu xtensaeb-softmmu

Quoted 8 lines

64-bit targets are not supported on 32-bit hosts since commit acce728cbc6c ("meson: Disallow 64-bit on 32-bit emulation"). I don't think the x86_64 target can be built on 32-bit hosts.

But notice that i386-softmmu is missing from the target list. That could be why the CI job succeeded.

Cédric: What were your ./configure options?

Just :

--target-list=arm-softmmu,ppc-softmmu,i386-softmmu

C.

#31 lore raw

Re: [PULL 24/24] i386/tdx: handle TDG.VP.VMCALL<GetQuote>

Quoted 90 lines · Cédric Le Goater
Quoted 88 lines · Stefan Hajnoczi
Quoted 70 lines · Daniel P. Berrangé
Quoted 68 lines · Stefan Hajnoczi
Quoted 56 lines · Daniel P. Berrangé
Quoted 54 lines · Xiaoyao Li
Quoted 47 lines · Cédric Le Goater

Hello,

Quoted 41 lines · Paolo Bonzini

From: Isaku Yamahata <[email protected]>

Add property "quote-generation-socket" to tdx-guest, which is a property of type SocketAddress to specify Quote Generation Service(QGS).

On request of GetQuote, it connects to the QGS socket, read request data from shared guest memory, send the request data to the QGS, and store the response into shared guest memory, at last notify TD guest by interrupt.

command line example:

    qemu-system-x86_64 \
      -object '{"qom-type":"tdx-guest","id":"tdx0","quote-generation-

socket":{"type":"unix", "path":"/var/run/tdx-qgs/qgs.socket"}}' \
-machine confidential-guest-support=tdx0

Note, above example uses the unix socket. It can be other types, like vsock,
which depends on the implementation of QGS.

To avoid no response from QGS server, setup a timer for the transaction. If timeout, make it an error and interrupt guest. Define the threshold of time to 30s at present, maybe change to other value if not appropriate.

---
   qapi/qom.json                         |   8 +-
   target/i386/kvm/tdx-quote-generator.h |  82 +++++++
   target/i386/kvm/tdx.h                 |  10 +
   target/i386/kvm/kvm.c                 |   3 +
   target/i386/kvm/tdx-quote-generator.c | 300 ++++++++++++++++++++++++++
   target/i386/kvm/tdx-stub.c            |   4 +
   target/i386/kvm/tdx.c                 | 176 ++++++++++++++-
   target/i386/kvm/meson.build           |   2 +-
   8 files changed, 582 insertions(+), 3 deletions(-)
Quoted 2 lines

create mode 100644 target/i386/kvm/tdx-quote-generator.h create mode 100644 target/i386/kvm/tdx-quote-generator.c

Quoted 3 lines

These changes broke the build on 32-bit host.

Could you please send a patch to avoid compiling TDX in such environment ?

Paolo is on vacation.

Quoted 7 lines
Quoted 4 lines

I would like to help, but I don't have 32-bit host environment on hand. Do you know how to set up such environment quickly? (I tried to set up within a 32-bit VM but the 32-bit OS is too old and I didn't get it work to install the required package for building QEMU)

You should be able to use QEMU's docker containers to get yourself a Debian i386 container, on a x86_64 host.

The cross-i686-system (Debian) build CI job succeeded:
https://gitlab.com/qemu-project/qemu/-/jobs/10423776600

Quoted 7 lines
Quoted 1 line

I wonder why the CI didn't catch the issue?

It didn't build the x86_64 target:

--target-list-exclude="arm-softmmu i386-softmmu microblaze-softmmu mips-softmmu mipsel-softmmu mips64-softmmu ppc-softmmu riscv32-softmmu sh4-softmmu sparc-softmmu xtensa-softmmu $CROSS_SKIP_TARGETS"

so in turn didn't build any TDX code

Here are the targets that were built by the CI job:

target list : avr-softmmu m68k-softmmu microblazeel-softmmu
or1k-softmmu rx-softmmu sh4eb-softmmu tricore-softmmu xtensaeb-softmmu

64-bit targets are not supported on 32-bit hosts since commit acce728cbc6c ("meson: Disallow 64-bit on 32-bit emulation"). I don't think the x86_64 target can be built on 32-bit hosts.

Quoted 8 lines
Quoted 4 lines

But notice that i386-softmmu is missing from the target list. That could be why the CI job succeeded.

Cédric: What were your ./configure options?

Just :

--target-list=arm-softmmu,ppc-softmmu,i386-softmmu

cross-i686-tci builds i386-softmmu on debian-i686-cross with --disable-kvm, but the TDX code isn't compiled:
https://gitlab.com/qemu-project/qemu/-/jobs/10440424393

A new CI job could be added to cover TDX on 32-bit hosts if you think it's worthwhile. Maybe it's a corner case and not worth spending CI cycles on?

Stefan

#32 lore raw

Re: [PULL 24/24] i386/tdx: handle TDG.VP.VMCALL<GetQuote>

Quoted 100 lines · Stefan Hajnoczi
Quoted 90 lines · Cédric Le Goater
Quoted 88 lines · Stefan Hajnoczi
Quoted 70 lines · Daniel P. Berrangé
Quoted 68 lines · Stefan Hajnoczi
Quoted 56 lines · Daniel P. Berrangé
Quoted 54 lines · Xiaoyao Li
Quoted 47 lines · Cédric Le Goater

Hello,

Quoted 41 lines · Paolo Bonzini

From: Isaku Yamahata <[email protected]>

Add property "quote-generation-socket" to tdx-guest, which is a property of type SocketAddress to specify Quote Generation Service(QGS).

On request of GetQuote, it connects to the QGS socket, read request data from shared guest memory, send the request data to the QGS, and store the response into shared guest memory, at last notify TD guest by interrupt.

command line example:

    qemu-system-x86_64 \
      -object '{"qom-type":"tdx-guest","id":"tdx0","quote-generation-

socket":{"type":"unix", "path":"/var/run/tdx-qgs/qgs.socket"}}' \
-machine confidential-guest-support=tdx0

Note, above example uses the unix socket. It can be other types, like vsock,
which depends on the implementation of QGS.

To avoid no response from QGS server, setup a timer for the transaction. If timeout, make it an error and interrupt guest. Define the threshold of time to 30s at present, maybe change to other value if not appropriate.

---
   qapi/qom.json                         |   8 +-
   target/i386/kvm/tdx-quote-generator.h |  82 +++++++
   target/i386/kvm/tdx.h                 |  10 +
   target/i386/kvm/kvm.c                 |   3 +
   target/i386/kvm/tdx-quote-generator.c | 300 ++++++++++++++++++++++++++
   target/i386/kvm/tdx-stub.c            |   4 +
   target/i386/kvm/tdx.c                 | 176 ++++++++++++++-
   target/i386/kvm/meson.build           |   2 +-
   8 files changed, 582 insertions(+), 3 deletions(-)
Quoted 2 lines

create mode 100644 target/i386/kvm/tdx-quote-generator.h create mode 100644 target/i386/kvm/tdx-quote-generator.c

Quoted 3 lines

These changes broke the build on 32-bit host.

Could you please send a patch to avoid compiling TDX in such environment ?

Paolo is on vacation.

Quoted 7 lines
Quoted 4 lines

I would like to help, but I don't have 32-bit host environment on hand. Do you know how to set up such environment quickly? (I tried to set up within a 32-bit VM but the 32-bit OS is too old and I didn't get it work to install the required package for building QEMU)

You should be able to use QEMU's docker containers to get yourself a Debian i386 container, on a x86_64 host.

The cross-i686-system (Debian) build CI job succeeded:
https://gitlab.com/qemu-project/qemu/-/jobs/10423776600

Quoted 7 lines
Quoted 1 line

I wonder why the CI didn't catch the issue?

It didn't build the x86_64 target:

--target-list-exclude="arm-softmmu i386-softmmu microblaze-softmmu mips-softmmu mipsel-softmmu mips64-softmmu ppc-softmmu riscv32-softmmu sh4-softmmu sparc-softmmu xtensa-softmmu $CROSS_SKIP_TARGETS"

so in turn didn't build any TDX code

Here are the targets that were built by the CI job:

target list : avr-softmmu m68k-softmmu microblazeel-softmmu
or1k-softmmu rx-softmmu sh4eb-softmmu tricore-softmmu xtensaeb-softmmu

64-bit targets are not supported on 32-bit hosts since commit acce728cbc6c ("meson: Disallow 64-bit on 32-bit emulation"). I don't think the x86_64 target can be built on 32-bit hosts.

Quoted 8 lines
Quoted 4 lines

But notice that i386-softmmu is missing from the target list. That could be why the CI job succeeded.

Cédric: What were your ./configure options?

Just :

--target-list=arm-softmmu,ppc-softmmu,i386-softmmu

Quoted 7 lines

cross-i686-tci builds i386-softmmu on debian-i686-cross with --disable-kvm, but the TDX code isn't compiled:
https://gitlab.com/qemu-project/qemu/-/jobs/10440424393

A new CI job could be added to cover TDX on 32-bit hosts if you think it's worthwhile. Maybe it's a corner case and not worth spending CI cycles on?

We should not set any expectation of support for TDX on 32-bit host or guest emulator. IMHO the only right answer here is to disable build of TDX for anything other than x86_64-softmmu w/ KVM.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#33 lore raw

Re: [PULL 24/24] i386/tdx: handle TDG.VP.VMCALL<GetQuote>

Quoted 105 lines · Daniel P. Berrangé
Quoted 104 lines · Stefan Hajnoczi
Quoted 90 lines · Cédric Le Goater
Quoted 88 lines · Stefan Hajnoczi
Quoted 70 lines · Daniel P. Berrangé
Quoted 68 lines · Stefan Hajnoczi
Quoted 56 lines · Daniel P. Berrangé
Quoted 54 lines · Xiaoyao Li
Quoted 47 lines · Cédric Le Goater

Hello,

Quoted 31 lines · Paolo Bonzini

From: Isaku Yamahata <[email protected]>

Add property "quote-generation-socket" to tdx-guest, which is a property of type SocketAddress to specify Quote Generation Service(QGS).

On request of GetQuote, it connects to the QGS socket, read request data from shared guest memory, send the request data to the QGS, and store the response into shared guest memory, at last notify TD guest by interrupt.

command line example:

     qemu-system-x86_64 \
       -object '{"qom-type":"tdx-guest","id":"tdx0","quote-generation-

socket":{"type":"unix", "path":"/var/run/tdx-qgs/qgs.socket"}}' \
-machine confidential-guest-support=tdx0

Note, above example uses the unix socket. It can be other types, like vsock,
which depends on the implementation of QGS.

To avoid no response from QGS server, setup a timer for the transaction. If timeout, make it an error and interrupt guest. Define the threshold of time to 30s at present, maybe change to other value if not appropriate.

Quoted 12 lines
---
    qapi/qom.json                         |   8 +-
    target/i386/kvm/tdx-quote-generator.h |  82 +++++++
    target/i386/kvm/tdx.h                 |  10 +
    target/i386/kvm/kvm.c                 |   3 +
    target/i386/kvm/tdx-quote-generator.c | 300 ++++++++++++++++++++++++++
    target/i386/kvm/tdx-stub.c            |   4 +
    target/i386/kvm/tdx.c                 | 176 ++++++++++++++-
    target/i386/kvm/meson.build           |   2 +-
    8 files changed, 582 insertions(+), 3 deletions(-)
    create mode 100644 target/i386/kvm/tdx-quote-generator.h
    create mode 100644 target/i386/kvm/tdx-quote-generator.c
Quoted 3 lines

These changes broke the build on 32-bit host.

Could you please send a patch to avoid compiling TDX in such environment ?

Paolo is on vacation.

Quoted 7 lines
Quoted 4 lines

I would like to help, but I don't have 32-bit host environment on hand. Do you know how to set up such environment quickly? (I tried to set up within a 32-bit VM but the 32-bit OS is too old and I didn't get it work to install the required package for building QEMU)

You should be able to use QEMU's docker containers to get yourself a Debian i386 container, on a x86_64 host.

The cross-i686-system (Debian) build CI job succeeded:
https://gitlab.com/qemu-project/qemu/-/jobs/10423776600

Quoted 7 lines
Quoted 1 line

I wonder why the CI didn't catch the issue?

It didn't build the x86_64 target:

--target-list-exclude="arm-softmmu i386-softmmu microblaze-softmmu mips-softmmu mipsel-softmmu mips64-softmmu ppc-softmmu riscv32-softmmu sh4-softmmu sparc-softmmu xtensa-softmmu $CROSS_SKIP_TARGETS"

so in turn didn't build any TDX code

Here are the targets that were built by the CI job:

target list : avr-softmmu m68k-softmmu microblazeel-softmmu
or1k-softmmu rx-softmmu sh4eb-softmmu tricore-softmmu xtensaeb-softmmu

64-bit targets are not supported on 32-bit hosts since commit acce728cbc6c ("meson: Disallow 64-bit on 32-bit emulation"). I don't think the x86_64 target can be built on 32-bit hosts.

Quoted 8 lines
Quoted 4 lines

But notice that i386-softmmu is missing from the target list. That could be why the CI job succeeded.

Cédric: What were your ./configure options?

Just :

--target-list=arm-softmmu,ppc-softmmu,i386-softmmu

cross-i686-tci builds i386-softmmu on debian-i686-cross with --disable-kvm, but the TDX code isn't compiled:
https://gitlab.com/qemu-project/qemu/-/jobs/10440424393

Quoted 7 lines
Quoted 3 lines

A new CI job could be added to cover TDX on 32-bit hosts if you think it's worthwhile. Maybe it's a corner case and not worth spending CI cycles on?

We should not set any expectation of support for TDX on 32-bit host or guest emulator. IMHO the only right answer here is to disable build of TDX for anything other than x86_64-softmmu w/ KVM.

yes. This is what I was reminding the developers.

Thanks,

C.

#34 lore raw

[PULL 20/24] i386/tdx: Fix the typo of the comment of struct TdxGuest

In reply to Paolo Bonzini

From: Xiaoyao Li <[email protected]>

Change sha348 to sha384.

---
 target/i386/kvm/tdx.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
target/i386/kvm/tdx.h +3 -3
index 04b5afe199f..8dd66e90149 100644
@@ -40,9 +40,9 @@ typedef struct TdxGuest {
     bool initialized;
     uint64_t attributes;    /* TD attributes */
     uint64_t xfam;
-    char *mrconfigid;       /* base64 encoded sha348 digest */
-    char *mrowner;          /* base64 encoded sha348 digest */
-    char *mrownerconfig;    /* base64 encoded sha348 digest */
+    char *mrconfigid;       /* base64 encoded sha384 digest */
+    char *mrowner;          /* base64 encoded sha384 digest */
+    char *mrownerconfig;    /* base64 encoded sha384 digest */
 
     MemoryRegion *tdvf_mr;
     TdxFirmware tdvf;
Signature · 1 line
2.49.0
#35 lore raw

[PULL 07/24] rust: qom: introduce ParentInit

In reply to Paolo Bonzini

This is a smart pointer for MaybeUninit; it can be upcasted to the already-initialized parent classes, or dereferenced to a MaybeUninit for the class that is being initialized.

---
 rust/qemu-api/src/qom.rs | 96 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 95 insertions(+), 1 deletion(-)
rust/qemu-api/src/qom.rs +95 -1
index 14f98fee60a..ef966e570ca 100644
@@ -95,7 +95,7 @@
 use std::{
     ffi::{c_void, CStr},
     fmt,
-    mem::ManuallyDrop,
+    mem::{ManuallyDrop, MaybeUninit},
     ops::{Deref, DerefMut},
     ptr::NonNull,
 };
@@ -206,6 +206,100 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
     }
 }
 
+/// This struct knows that the superclasses of the object have already been
+/// initialized.
+pub struct ParentInit<'a, T>(&'a mut MaybeUninit<T>);
+
+impl<'a, T> ParentInit<'a, T> {
+    #[inline]
+    pub fn with(obj: &'a mut MaybeUninit<T>, f: impl FnOnce(ParentInit<'a, T>)) {
+        let parent_init = ParentInit(obj);
+        f(parent_init)
+    }
+}
+
+impl<T: ObjectType> ParentInit<'_, T> {
+    /// Return the receiver as a mutable raw pointer to Object.
+    ///
+    /// # Safety
+    ///
+    /// Fields beyond `Object` could be uninitialized and it's your
+    /// responsibility to avoid that they're used when the pointer is
+    /// dereferenced, either directly or through a cast.
+    pub fn as_object_mut_ptr(&self) -> *mut bindings::Object {
+        self.as_object_ptr().cast_mut()
+    }
+
+    /// Return the receiver as a mutable raw pointer to Object.
+    ///
+    /// # Safety
+    ///
+    /// Fields beyond `Object` could be uninitialized and it's your
+    /// responsibility to avoid that they're used when the pointer is
+    /// dereferenced, either directly or through a cast.
+    pub fn as_object_ptr(&self) -> *const bindings::Object {
+        self.0.as_ptr().cast()
+    }
+}
+
+impl<'a, T: ObjectImpl> ParentInit<'a, T> {
+    /// Convert from a derived type to one of its parent types, which
+    /// have already been initialized.
+    ///
+    /// # Safety
+    ///
+    /// Structurally this is always a safe operation; the [`IsA`] trait
+    /// provides static verification trait that `Self` dereferences to `U` or
+    /// a child of `U`, and only parent types of `T` are allowed.
+    ///
+    /// However, while the fields of the resulting reference are initialized,
+    /// calls might use uninitialized fields of the subclass.  It is your
+    /// responsibility to avoid this.
+    pub unsafe fn upcast<U: ObjectType>(&self) -> &'a U
+    where
+        T::ParentType: IsA<U>,
+    {
+        // SAFETY: soundness is declared via IsA<U>, which is an unsafe trait;
+        // the parent has been initialized before `instance_init `is called
+        unsafe { &*(self.0.as_ptr().cast::<U>()) }
+    }
+
+    /// Convert from a derived type to one of its parent types, which
+    /// have already been initialized.
+    ///
+    /// # Safety
+    ///
+    /// Structurally this is always a safe operation; the [`IsA`] trait
+    /// provides static verification trait that `Self` dereferences to `U` or
+    /// a child of `U`, and only parent types of `T` are allowed.
+    ///
+    /// However, while the fields of the resulting reference are initialized,
+    /// calls might use uninitialized fields of the subclass.  It is your
+    /// responsibility to avoid this.
+    pub unsafe fn upcast_mut<U: ObjectType>(&mut self) -> &'a mut U
+    where
+        T::ParentType: IsA<U>,
+    {
+        // SAFETY: soundness is declared via IsA<U>, which is an unsafe trait;
+        // the parent has been initialized before `instance_init `is called
+        unsafe { &mut *(self.0.as_mut_ptr().cast::<U>()) }
+    }
+}
+
+impl<T> Deref for ParentInit<'_, T> {
+    type Target = MaybeUninit<T>;
+
+    fn deref(&self) -> &Self::Target {
+        self.0
+    }
+}
+
+impl<T> DerefMut for ParentInit<'_, T> {
+    fn deref_mut(&mut self) -> &mut Self::Target {
+        self.0
+    }
+}
+
 unsafe extern "C" fn rust_instance_init<T: ObjectImpl>(obj: *mut bindings::Object) {
     let mut state = NonNull::new(obj).unwrap().cast::<T>();
     // SAFETY: obj is an instance of T, since rust_instance_init<T>
Signature · 1 line
2.49.0