From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id D93AA1FF0B7 for ; Mon, 30 Nov 2026 15:11:21 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 21DB221745; Mon, 30 Nov 2026 15:11:19 +0100 (CET) From: Arthur Bied-Charreton 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 Message-ID: <20261130141054.556314-5-a.bied-charreton@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261130141054.556314-1-a.bied-charreton@proxmox.com> References: <20261130141054.556314-1-a.bied-charreton@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1796047861459 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.476 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) PROLO_LEO1 0.1 Meta Catches all Leo drug variations so far RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: V3ERERLPLQVAF62Q5SUBKDLVTNIUGNFV X-Message-ID-Hash: V3ERERLPLQVAF62Q5SUBKDLVTNIUGNFV X-MailFrom: a.bied-charreton@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- .../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; #[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, + + /// Use Proxmox Datacenter Manager API endpoints + #[builder(IntoPropValue, into_prop_value)] + #[prop_or_default] + pub remote: Option, + + /// The guest's architecture, defaults to the node's architecture. + #[builder(IntoPropValue, into_prop_value)] + #[prop_or_default] + pub arch: Option, +} 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), + Loaded(QemuCpuFlags, Result, 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, + error: Option, + 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 { + 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::(), + Some(proxmox_client::Error::Api(err_status, _)) if *err_status == status + ) } fn parse_flags(flags: &str) -> HashMap { @@ -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 { - // 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 { + 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, 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) { @@ -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 = self @@ -166,6 +270,10 @@ impl ManagedField for QemuCpuFlagsField { } fn view(&self, ctx: &ManagedFieldContext) -> Html { + if let Some(err) = &self.error { + return error_message(err).padding(2).into(); + } + let tiles: Vec = 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, + _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, + 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::(&mut record, "cpu")?; Ok(record) -- 2.47.3