From: Arthur Bied-Charreton <a.bied-charreton@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [PATCH proxmox-yew-comp v2 4/4] qemu: cpu flags: load the CPU flags from the node
Date: Mon, 30 Nov 2026 15:10:54 +0100 [thread overview]
Message-ID: <20261130141054.556314-5-a.bied-charreton@proxmox.com> (raw)
In-Reply-To: <20261130141054.556314-1-a.bied-charreton@proxmox.com>
The CPU flags editor used a hardcoded list that fell behind
qemu-server, e.g. it misses the nested-virt alias.
Load the flags from the guest's node instead. The guest's arch is
passed if set explicitly so an emulated aarch64 guest does not get
the x86 flags, otherwise the node just defaults to its own arch.
Nodes before qemu-server 9.1.5 reject the arch parameter with a 400 and
only know x86 flags, so retry without it for x86_64.
Use the hardcoded list as a fallback for nodes without the endpoint,
which return 501. It only has x86 flags, so it is empty for guests with
another explicit arch. Other errors are shown.
Signed-off-by: Arthur Bied-Charreton <a.bied-charreton@proxmox.com>
---
.../pve/qemu_hardware_panel/mobile.rs | 6 +-
src/form/pve/qemu_cpu_flags_list.rs | 192 ++++++++++++++----
.../qemu_property/qemu_processor_property.rs | 26 ++-
3 files changed, 182 insertions(+), 42 deletions(-)
diff --git a/src/configuration/pve/qemu_hardware_panel/mobile.rs b/src/configuration/pve/qemu_hardware_panel/mobile.rs
index bc958b9..c9ccff0 100644
--- a/src/configuration/pve/qemu_hardware_panel/mobile.rs
+++ b/src/configuration/pve/qemu_hardware_panel/mobile.rs
@@ -768,7 +768,11 @@ impl PendingPropertyView for PveQemuHardwarePanel {
mobile,
),
kernel_scheduler_property: qemu_kernel_scheduler_property(user_is_root, mobile),
- cpu_flags_property: qemu_cpu_flags_property(mobile),
+ cpu_flags_property: qemu_cpu_flags_property(
+ props.node.clone(),
+ props.remote.clone(),
+ mobile,
+ ),
display_property: qemu_display_property(mobile),
machine_property: qemu_machine_property(mobile),
scsihw_property: qemu_scsihw_property(mobile),
diff --git a/src/form/pve/qemu_cpu_flags_list.rs b/src/form/pve/qemu_cpu_flags_list.rs
index bfcac50..37ef899 100644
--- a/src/form/pve/qemu_cpu_flags_list.rs
+++ b/src/form/pve/qemu_cpu_flags_list.rs
@@ -4,21 +4,43 @@ use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::collections::HashMap;
+use yew::html::IntoPropValue;
+
use pwt::prelude::*;
use pwt::widget::form::{
ManagedField, ManagedFieldContext, ManagedFieldMaster, ManagedFieldScopeExt, ManagedFieldState,
RadioButton,
};
-use pwt::widget::{Column, List, ListTile, Row};
+use pwt::widget::{error_message, Column, Container, List, ListTile, Mask, Row};
use pwt_macros::{builder, widget};
+use pve_api_types::QemuCpuFlag;
+
+use crate::http_get;
+use crate::percent_encoding::percent_encode_component;
+
pub type QemuCpuFlagsComp = ManagedFieldMaster<QemuCpuFlagsField>;
#[widget(comp=QemuCpuFlagsComp, @input)]
#[derive(Clone, PartialEq, Properties)]
#[builder]
-pub struct QemuCpuFlags {}
+pub struct QemuCpuFlags {
+ /// The node to query for available flags.
+ #[builder(IntoPropValue, into_prop_value)]
+ #[prop_or_default]
+ pub node: Option<AttrValue>,
+
+ /// Use Proxmox Datacenter Manager API endpoints
+ #[builder(IntoPropValue, into_prop_value)]
+ #[prop_or_default]
+ pub remote: Option<AttrValue>,
+
+ /// The guest's architecture, defaults to the node's architecture.
+ #[builder(IntoPropValue, into_prop_value)]
+ #[prop_or_default]
+ pub arch: Option<AttrValue>,
+}
impl Default for QemuCpuFlags {
fn default() -> Self {
@@ -30,10 +52,15 @@ impl QemuCpuFlags {
pub fn new() -> Self {
yew::props!(Self {})
}
+
+ fn same_query(&self, other: &Self) -> bool {
+ self.node == other.node && self.remote == other.remote && self.arch == other.arch
+ }
}
pub enum Msg {
Set(String, Option<bool>),
+ Loaded(QemuCpuFlags, Result<Vec<QemuCpuFlag>, Error>),
}
#[derive(Clone, Debug, Serialize, Deserialize)]
@@ -46,7 +73,72 @@ struct FlagEntry {
#[doc(hidden)]
pub struct QemuCpuFlagsField {
state: ManagedFieldState,
- flag_list: IndexMap<&'static str, FlagEntry>,
+ flag_list: IndexMap<String, FlagEntry>,
+ error: Option<String>,
+ loading: bool,
+}
+
+async fn load_flags(props: QemuCpuFlags) -> Msg {
+ let node = props.node.as_deref().unwrap_or("localhost");
+ let url = match &props.remote {
+ Some(remote) => format!(
+ "/pve/remotes/{}/nodes/{}/capabilities/qemu/cpu-flags",
+ percent_encode_component(remote),
+ percent_encode_component(node),
+ ),
+ None => format!(
+ "/nodes/{}/capabilities/qemu/cpu-flags",
+ percent_encode_component(node),
+ ),
+ };
+ let Some(arch) = props.arch.clone() else {
+ return Msg::Loaded(props, http_get(url, None).await);
+ };
+ let mut result = http_get(&url, Some(serde_json::json!({ "arch": arch.as_str() }))).await;
+ if matches!(&result, Err(err) if has_status(err, http::StatusCode::BAD_REQUEST)) {
+ // nodes before qemu-server 9.1.5 reject arch and only know x86 flags
+ result = if arch == "x86_64" {
+ http_get(url, None).await
+ } else {
+ Ok(Vec::new())
+ };
+ }
+ Msg::Loaded(props, result)
+}
+
+/// The VM-specific x86 flags of nodes without the cpu-flags API endpoint.
+fn fallback_flags(arch: Option<&str>) -> Vec<FlagEntry> {
+ if arch.is_some_and(|arch| arch != "x86_64") {
+ return Vec::new();
+ }
+ [
+ ("md-clear", tr!("Required to let the guest OS know if MDS is mitigated correctly")),
+ ("pcid", tr!("Meltdown fix cost reduction on Westmere, Sandy-, and IvyBridge Intel CPUs")),
+ ("spec-ctrl", tr!("Allows improved Spectre mitigation with Intel CPUs")),
+ ("ssbd", tr!("Protection for \"Speculative Store Bypass\" for Intel models")),
+ ("ibpb", tr!("Allows improved Spectre mitigation with AMD CPUs")),
+ ("virt-ssbd", tr!("Basis for \"Speculative Store Bypass\" protection for AMD models")),
+ ("amd-ssbd", tr!("Improves Spectre mitigation performance with AMD CPUs, best used with \"virt-ssbd\"")),
+ ("amd-no-ssb", tr!("Notifies guest OS that host is not vulnerable for Spectre on AMD CPUs")),
+ ("pdpe1gb", tr!("Allow guest OS to use 1GB size pages, if host HW supports it")),
+ ("hv-tlbflush", tr!("Improve performance in overcommitted Windows guests. May lead to guest bluescreens on old CPUs.")),
+ ("hv-evmcs", tr!("Improve performance for nested virtualization. Only supported on Intel CPUs.")),
+ ("aes", tr!("Activate AES instruction set for HW acceleration.")),
+ ]
+ .into_iter()
+ .map(|(name, descr)| FlagEntry {
+ enabled: None,
+ name: name.to_string(),
+ descr,
+ })
+ .collect()
+}
+
+fn has_status(err: &Error, status: http::StatusCode) -> bool {
+ matches!(
+ err.downcast_ref::<proxmox_client::Error>(),
+ Some(proxmox_client::Error::Api(err_status, _)) if *err_status == status
+ )
}
fn parse_flags(flags: &str) -> HashMap<String, bool> {
@@ -73,7 +165,7 @@ impl QemuCpuFlagsField {
pub fn update_flag_list(&mut self, value: Value) {
let current_flags = parse_flags(value.as_str().unwrap_or(""));
for (name, item) in self.flag_list.iter_mut() {
- if let Some(value) = current_flags.get(*name) {
+ if let Some(value) = current_flags.get(name) {
item.enabled = Some(*value);
} else {
item.enabled = None;
@@ -93,39 +185,23 @@ impl ManagedField for QemuCpuFlagsField {
Ok(value.clone())
}
- fn create(_ctx: &ManagedFieldContext<Self>) -> Self {
- // TODO: let qemu-server host this and autogenerate or get from API call??
- let all_flags = [
- ("md-clear", tr!("Required to let the guest OS know if MDS is mitigated correctly")),
- ("pcid", tr!("Meltdown fix cost reduction on Westmere, Sandy-, and IvyBridge Intel CPUs")),
- ("spec-ctrl", tr!("Allows improved Spectre mitigation with Intel CPUs")),
- ("ssbd", tr!("Protection for \"Speculative Store Bypass\" for Intel models")),
- ("ibpb", tr!("Allows improved Spectre mitigation with AMD CPUs")),
- ("virt-ssbd", tr!("Basis for \"Speculative Store Bypass\" protection for AMD models")),
- ("amd-ssbd", tr!("Improves Spectre mitigation performance with AMD CPUs, best used with \"virt-ssbd\"")),
- ("amd-no-ssb", tr!("Notifies guest OS that host is not vulnerable for Spectre on AMD CPUs")),
- ("pdpe1gb", tr!("Allow guest OS to use 1GB size pages, if host HW supports it")),
- ("hv-tlbflush", tr!("Improve performance in overcommitted Windows guests. May lead to guest bluescreens on old CPUs.")),
- ("hv-evmcs", tr!("Improve performance for nested virtualization. Only supported on Intel CPUs.")),
- ("aes", tr!("Activate AES instruction set for HW acceleration.")),
- ];
-
- let mut flag_list = IndexMap::new();
- flag_list.extend(all_flags.into_iter().map(|(flag, descr)| {
- (
- flag,
- FlagEntry {
- name: flag.to_string(),
- descr,
- enabled: None,
- },
- )
- }));
-
+ fn create(ctx: &ManagedFieldContext<Self>) -> Self {
+ ctx.link().send_future(load_flags(ctx.props().clone()));
Self {
state: ManagedFieldState::new(Value::Null, Value::Null),
- flag_list,
+ flag_list: IndexMap::new(),
+ error: None,
+ loading: true,
+ }
+ }
+
+ fn changed(&mut self, ctx: &ManagedFieldContext<Self>, old_props: &Self::Properties) -> bool {
+ if !ctx.props().same_query(old_props) {
+ self.loading = true;
+ self.error = None;
+ ctx.link().send_future(load_flags(ctx.props().clone()));
}
+ true
}
fn value_changed(&mut self, _ctx: &ManagedFieldContext<Self>) {
@@ -137,6 +213,34 @@ impl ManagedField for QemuCpuFlagsField {
Msg::Set(flag, enabled) => {
self.flag_list[flag.as_str()].enabled = enabled;
}
+ Msg::Loaded(props, result) => {
+ if !props.same_query(ctx.props()) {
+ return false; // stale response for previous properties
+ }
+ self.error = None;
+ self.loading = false;
+ let flags = match result {
+ Ok(flags) => flags
+ .into_iter()
+ .map(|flag| FlagEntry {
+ enabled: None,
+ name: flag.name,
+ descr: flag.description.unwrap_or_default(),
+ })
+ .collect(),
+ // nodes without the route answer 501
+ Err(err) if has_status(&err, http::StatusCode::NOT_IMPLEMENTED) => {
+ fallback_flags(props.arch.as_deref())
+ }
+ Err(err) => {
+ self.error = Some(err.to_string());
+ Vec::new()
+ }
+ };
+ self.flag_list = flags.into_iter().map(|f| (f.name.clone(), f)).collect();
+ self.update_flag_list(self.state.value.clone());
+ return true;
+ }
}
let mut new_flags: Vec<String> = self
@@ -166,6 +270,10 @@ impl ManagedField for QemuCpuFlagsField {
}
fn view(&self, ctx: &ManagedFieldContext<Self>) -> Html {
+ if let Some(err) = &self.error {
+ return error_message(err).padding(2).into();
+ }
+
let tiles: Vec<ListTile> = self
.flag_list
.iter()
@@ -223,9 +331,21 @@ impl ManagedField for QemuCpuFlagsField {
.key(item.name.clone())
})
.collect();
- List::from_tiles(tiles)
+ let content: Html = if tiles.is_empty() && !self.loading {
+ Container::new()
+ .padding(2)
+ .with_child(tr!("No CPU flags available"))
+ .into()
+ } else {
+ List::from_tiles(tiles)
+ .class(pwt::css::FlexFit)
+ .grid_template_columns("1fr auto")
+ .into()
+ };
+ Mask::new(content)
.class(pwt::css::FlexFit)
- .grid_template_columns("1fr auto")
+ .style("min-height", self.loading.then_some("4em"))
+ .visible(self.loading)
.into()
}
}
diff --git a/src/form/pve/qemu_property/qemu_processor_property.rs b/src/form/pve/qemu_property/qemu_processor_property.rs
index 0ba24a0..cfcc3bc 100644
--- a/src/form/pve/qemu_property/qemu_processor_property.rs
+++ b/src/form/pve/qemu_property/qemu_processor_property.rs
@@ -133,7 +133,8 @@ fn processor_input_panel(
let main_view =
socket_cores_input_panel(node.clone(), remote.clone(), false).apply(state.clone());
- let flags_view = cpu_flags_input_panel(false).apply(state.clone());
+ let flags_view =
+ cpu_flags_input_panel(node.clone(), remote.clone(), false).apply(state.clone());
let scheduler_view = kernel_scheduler_input_panel(user_is_root, false).apply(state.clone());
Column::new()
@@ -229,15 +230,30 @@ pub fn qemu_sockets_cores_property(
})
}
-fn cpu_flags_input_panel(_mobile: bool) -> RenderPropertyInputPanelFn {
- RenderPropertyInputPanelFn::new(move |_| QemuCpuFlags::new().name("_flags").into())
+fn cpu_flags_input_panel(
+ node: AttrValue,
+ remote: Option<AttrValue>,
+ _mobile: bool,
+) -> RenderPropertyInputPanelFn {
+ RenderPropertyInputPanelFn::new(move |state: PropertyEditorState| {
+ QemuCpuFlags::new()
+ .node(node.clone())
+ .remote(remote.clone())
+ .arch(state.record["arch"].as_str().map(String::from))
+ .name("_flags")
+ .into()
+ })
}
-pub fn qemu_cpu_flags_property(mobile: bool) -> EditableProperty {
+pub fn qemu_cpu_flags_property(
+ node: AttrValue,
+ remote: Option<AttrValue>,
+ mobile: bool,
+) -> EditableProperty {
EditableProperty::new("cpu", tr!("CPU flags"))
.required(true)
.renderer(renderer)
- .render_input_panel(cpu_flags_input_panel(mobile))
+ .render_input_panel(cpu_flags_input_panel(node, remote, mobile))
.load_hook(move |mut record: Value| {
flatten_property_string::<PveVmCpuConf>(&mut record, "cpu")?;
Ok(record)
--
2.47.3
prev parent reply other threads:[~2026-11-30 14:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 14:10 [PATCH datacenter-manager/proxmox{,-yew-comp}/qemu-server v2 0/4] load VM-specific CPU flags from the remote Arthur Bied-Charreton
2026-11-30 14:10 ` [PATCH qemu-server v2 1/4] api: cpu flags: proxy the request to the given node Arthur Bied-Charreton
2026-11-30 14:10 ` [PATCH proxmox v2 2/4] pve-api-types: add VM-specific CPU flags endpoint Arthur Bied-Charreton
2026-11-30 14:10 ` [PATCH datacenter-manager v2 3/4] api: pve: " Arthur Bied-Charreton
2026-11-30 14:10 ` Arthur Bied-Charreton [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261130141054.556314-5-a.bied-charreton@proxmox.com \
--to=a.bied-charreton@proxmox.com \
--cc=pdm-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox