public inbox for pdm-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Arthur Bied-Charreton <a.bied-charreton@proxmox.com>
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	[thread overview]
Message-ID: <20261130104716.329802-4-a.bied-charreton@proxmox.com> (raw)
In-Reply-To: <20261130104716.329802-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.

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 <a.bied-charreton@proxmox.com>
---
 .../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<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>,
+}
 
 impl Default for QemuCpuFlags {
     fn default() -> Self {
@@ -34,6 +51,7 @@ impl QemuCpuFlags {
 
 pub enum Msg {
     Set(String, Option<bool>),
+    Loaded(Result<Vec<QemuCpuFlag>, 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<String, FlagEntry>,
+    error: Option<String>,
+}
+
+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<FlagEntry> {
+    [
+        ("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::<proxmox_client::Error>(),
+        Some(proxmox_client::Error::Api(status, _))
+            if *status == http::StatusCode::NOT_IMPLEMENTED || *status == http::StatusCode::NOT_FOUND
+    )
 }
 
 fn parse_flags(flags: &str) -> HashMap<String, bool> {
@@ -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>) -> 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,
         }
     }
 
@@ -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<String> = self
@@ -166,6 +229,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()
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<AttrValue>,
+    _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<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





  parent reply	other threads:[~2026-11-30 10:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 10:47 [PATCH datacenter-manager/proxmox{,-yew-comp} 0/3] load VM-specific CPU flags from the remote Arthur Bied-Charreton
2026-11-30 10:47 ` [PATCH proxmox 1/3] pve-api-types: add VM-specific CPU flags endpoint Arthur Bied-Charreton
2026-11-30 10:47 ` [PATCH datacenter-manager 2/3] api: pve: " Arthur Bied-Charreton
2026-11-30 10:47 ` Arthur Bied-Charreton [this message]
2026-11-30 14:12 ` superseded: [PATCH datacenter-manager/proxmox{,-yew-comp} 0/3] load VM-specific CPU flags from the remote Arthur Bied-Charreton
2026-12-01 13:56 ` Thomas Lamprecht

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=20261130104716.329802-4-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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal