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 388431FF0B7 for ; Mon, 30 Nov 2026 11:47:42 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 142F5216B3; Mon, 30 Nov 2026 11:47:42 +0100 (CET) From: Arthur Bied-Charreton To: pdm-devel@lists.proxmox.com Subject: [PATCH proxmox-yew-comp 3/3] qemu: cpu flags: load the CPU flags from the node Date: Mon, 30 Nov 2026 11:47:16 +0100 Message-ID: <20261130104716.329802-4-a.bied-charreton@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261130104716.329802-1-a.bied-charreton@proxmox.com> References: <20261130104716.329802-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: 1796035645345 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.530 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) 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: KLGNWCCKPDA3HOU77KCOXD5BLGG6DBJ6 X-Message-ID-Hash: KLGNWCCKPDA3HOU77KCOXD5BLGG6DBJ6 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. Nodes before qemu-server 9.0.26 and PDM witohut the proxied call do not have that endpoint. Fall back to the hardcoded list for them. Show other errors so an unreachable node or a missing privilege is visible. Signed-off-by: Arthur Bied-Charreton --- .../pve/qemu_hardware_panel/mobile.rs | 6 +- src/form/pve/qemu_cpu_flags_list.rs | 135 +++++++++++++----- .../qemu_property/qemu_processor_property.rs | 25 +++- 3 files changed, 126 insertions(+), 40 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..e688bc7 100644 --- a/src/form/pve/qemu_cpu_flags_list.rs +++ b/src/form/pve/qemu_cpu_flags_list.rs @@ -4,21 +4,38 @@ 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, List, ListTile, 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, +} impl Default for QemuCpuFlags { fn default() -> Self { @@ -34,6 +51,7 @@ impl QemuCpuFlags { pub enum Msg { Set(String, Option), + Loaded(Result, Error>), } #[derive(Clone, Debug, Serialize, Deserialize)] @@ -46,7 +64,58 @@ struct FlagEntry { #[doc(hidden)] pub struct QemuCpuFlagsField { state: ManagedFieldState, - flag_list: IndexMap<&'static str, FlagEntry>, + flag_list: IndexMap, + error: Option, +} + +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), + ), + }; + Msg::Loaded(http_get(url, None).await) +} + +/// The VM-specific flags of nodes that predate the cpu-flags API endpoint (qemu-server 9.0.26). +fn fallback_flags() -> Vec { + [ + ("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() +} + +/// Nodes before qemu-server 9.0.26 answer 501, PDM servers without the proxied call answer 404. +fn is_endpoint_missing(err: &Error) -> bool { + matches!( + err.downcast_ref::(), + Some(proxmox_client::Error::Api(status, _)) + if *status == http::StatusCode::NOT_IMPLEMENTED || *status == http::StatusCode::NOT_FOUND + ) } fn parse_flags(flags: &str) -> HashMap { @@ -73,7 +142,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,38 +162,12 @@ 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, } } @@ -137,6 +180,26 @@ impl ManagedField for QemuCpuFlagsField { Msg::Set(flag, enabled) => { self.flag_list[flag.as_str()].enabled = enabled; } + Msg::Loaded(result) => { + let flags = match result { + Ok(flags) => flags + .into_iter() + .map(|flag| FlagEntry { + enabled: None, + name: flag.name, + descr: flag.description.unwrap_or_default(), + }) + .collect(), + Err(err) if is_endpoint_missing(&err) => fallback_flags(), + 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 +229,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() diff --git a/src/form/pve/qemu_property/qemu_processor_property.rs b/src/form/pve/qemu_property/qemu_processor_property.rs index 0ba24a0..3f606ba 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,29 @@ 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 |_| { + QemuCpuFlags::new() + .node(node.clone()) + .remote(remote.clone()) + .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