public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH installer 0/3] export hvm support flag through runtime env
@ 2023-07-03  7:34 Christoph Heiss
  2023-07-03  7:34 ` [pve-devel] [PATCH installer 1/3] run env: add hardware-accelerated virtualization support flag Christoph Heiss
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Christoph Heiss @ 2023-07-03  7:34 UTC (permalink / raw)
  To: pve-devel

Currently, the logic to check whether hardware-accelerated
virtualization is supported or not by the host cpu is duplicated.

This adds a `hvm_supported` flag to the runtime environment info,
indicating whether it is supported or not, which can then be used by the
graphical and console installer to display a message to the user as
appropriate.

pve-installer:

Christoph Heiss (3):
  run env: add hardware-accelerated virtualization support flag
  proxinstall: check hvm support through runtime env info
  tui: check hvm support through runtime env info instead of open-coding

 Proxmox/Install/RunEnv.pm          | 25 +++++++++++++++++++++++++
 proxinstall                        | 13 +++++--------
 proxmox-tui-installer/Cargo.toml   |  2 --
 proxmox-tui-installer/src/main.rs  | 25 ++++++++++---------------
 proxmox-tui-installer/src/setup.rs |  4 ++++
 5 files changed, 44 insertions(+), 25 deletions(-)

--
2.40.1





^ permalink raw reply	[flat|nested] 6+ messages in thread

* [pve-devel] [PATCH installer 1/3] run env: add hardware-accelerated virtualization support flag
  2023-07-03  7:34 [pve-devel] [PATCH installer 0/3] export hvm support flag through runtime env Christoph Heiss
@ 2023-07-03  7:34 ` Christoph Heiss
  2023-07-03  7:34 ` [pve-devel] [PATCH installer 2/3] proxinstall: check hvm support through runtime env info Christoph Heiss
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Christoph Heiss @ 2023-07-03  7:34 UTC (permalink / raw)
  To: pve-devel

Can later be used by the installer frontends, as well as nicely alinging
with the 'single source of truth' "policy".

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
 Proxmox/Install/RunEnv.pm | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/Proxmox/Install/RunEnv.pm b/Proxmox/Install/RunEnv.pm
index b9fb139..9878f55 100644
--- a/Proxmox/Install/RunEnv.pm
+++ b/Proxmox/Install/RunEnv.pm
@@ -35,6 +35,25 @@ sub query_total_memory : prototype() {
     return $mem_total;
 }
 
+my $cpu_hvm_support = undef;
+sub query_cpu_hvm_support : prototype() {
+    return $cpu_hvm_support if defined($cpu_hvm_support);
+
+    open (my $CPUINFO, '<', '/proc/cpuinfo');
+
+    my $res = 0;
+    while (my $line = <$CPUINFO>) {
+	if ($line =~ /^flags\s*:.*(vmx|svm)/m) {
+	    $res = 1;
+	    last;
+	}
+    }
+    close($CPUINFO);
+
+    $cpu_hvm_support = $res;
+    return $cpu_hvm_support;
+}
+
 # Returns a hash.
 #
 # {
@@ -207,6 +226,11 @@ my sub detect_country_tracing_to : prototype($$) {
 # Returns the entire environment as a hash.
 # {
 #     country => <short country>,
+#     ipconf = <see Proxmox::Sys::Net::get_ip_config()>,
+#     kernel_cmdline = <contents of /proc/cmdline>,
+#     total_memory = <memory size in MiB>,
+#     hvm_supported = <1 if the CPU supports hardware-accelerated virtualization>,
+#     boot_type = <either 'efi' or 'bios'>,
 #     disks => <see Proxmox::Sys::Block::hd_list()>,
 #     network => {
 #         interfaces => <see query_netdevs()>,
@@ -246,6 +270,7 @@ sub query_installation_environment : prototype() {
 
     $output->{kernel_cmdline} = file_read_firstline("/proc/cmdline");
     $output->{total_memory} = query_total_memory();
+    $output->{hvm_supported} = query_cpu_hvm_support();
     $output->{boot_type} = -d '/sys/firmware/efi' ? 'efi' : 'bios';
 
     my $err;
-- 
2.40.1





^ permalink raw reply	[flat|nested] 6+ messages in thread

* [pve-devel] [PATCH installer 2/3] proxinstall: check hvm support through runtime env info
  2023-07-03  7:34 [pve-devel] [PATCH installer 0/3] export hvm support flag through runtime env Christoph Heiss
  2023-07-03  7:34 ` [pve-devel] [PATCH installer 1/3] run env: add hardware-accelerated virtualization support flag Christoph Heiss
@ 2023-07-03  7:34 ` Christoph Heiss
  2023-07-03  7:35 ` [pve-devel] [PATCH installer 3/3] tui: check hvm support through runtime env info instead of open-coding Christoph Heiss
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Christoph Heiss @ 2023-07-03  7:34 UTC (permalink / raw)
  To: pve-devel

As that info is now available through the runtime environment info, use
it and avoid duplicating logic.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
 proxinstall | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/proxinstall b/proxinstall
index 274f39c..d5b2565 100755
--- a/proxinstall
+++ b/proxinstall
@@ -1583,14 +1583,11 @@ sub create_intro_view {
 	    "See 'System Requirements' in the $iso_env->{cfg}->{fullname} documentation.");
     }
 
-    if ($iso_env->{product} eq 'pve') {
-	my $cpuinfo = eval { file_read_all('/proc/cpuinfo') };
-	if (!$cpuinfo || $cpuinfo !~ /^flags\s*:.*(vmx|svm)/m) {
-	    Proxmox::UI::error(
-		"No support for hardware-accelerated KVM virtualization detected.\n\n"
-		."Check BIOS settings for Intel VT / AMD-V / SVM."
-	    );
-	}
+    if ($iso_env->{product} eq 'pve' && !$run_env->{hvm_supported}) {
+	Proxmox::UI::error(
+	    "No support for hardware-accelerated KVM virtualization detected.\n\n"
+	    ."Check BIOS settings for Intel VT / AMD-V / SVM."
+	);
     }
 
     Proxmox::UI::display_html('license.htm', sub {
-- 
2.40.1





^ permalink raw reply	[flat|nested] 6+ messages in thread

* [pve-devel] [PATCH installer 3/3] tui: check hvm support through runtime env info instead of open-coding
  2023-07-03  7:34 [pve-devel] [PATCH installer 0/3] export hvm support flag through runtime env Christoph Heiss
  2023-07-03  7:34 ` [pve-devel] [PATCH installer 1/3] run env: add hardware-accelerated virtualization support flag Christoph Heiss
  2023-07-03  7:34 ` [pve-devel] [PATCH installer 2/3] proxinstall: check hvm support through runtime env info Christoph Heiss
@ 2023-07-03  7:35 ` Christoph Heiss
  2023-07-04  8:27 ` [pve-devel] [PATCH installer 4/4] d/control: drop unused librust-proxmox-sys-dev build dependency Christoph Heiss
  2023-07-13 13:50 ` [pve-devel] applied-series: [PATCH installer 0/3] export hvm support flag through runtime env Thomas Lamprecht
  4 siblings, 0 replies; 6+ messages in thread
From: Christoph Heiss @ 2023-07-03  7:35 UTC (permalink / raw)
  To: pve-devel

As the runtime environment now exports that info, use it. In turn, this
allows us to drop the dependency on `proxmox-sys`, as that check was its
only user.

The dependency graph drops from 107 to 88 crates from this, which
definitively is a nice change.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
 proxmox-tui-installer/Cargo.toml   |  2 --
 proxmox-tui-installer/src/main.rs  | 25 ++++++++++---------------
 proxmox-tui-installer/src/setup.rs |  4 ++++
 3 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/proxmox-tui-installer/Cargo.toml b/proxmox-tui-installer/Cargo.toml
index 5a50c69..8a6eba8 100644
--- a/proxmox-tui-installer/Cargo.toml
+++ b/proxmox-tui-installer/Cargo.toml
@@ -12,5 +12,3 @@ cursive = { version = "0.20.0", default-features = false, features = ["termion-b
 serde = { version = "1.0", features = ["derive"] }
 serde_json = "1.0"
 regex = "1.7"
-
-proxmox-sys = "0.5.0"
diff --git a/proxmox-tui-installer/src/main.rs b/proxmox-tui-installer/src/main.rs
index 64f21fa..109def3 100644
--- a/proxmox-tui-installer/src/main.rs
+++ b/proxmox-tui-installer/src/main.rs
@@ -25,13 +25,11 @@ use cursive::{

 use regex::Regex;

-use proxmox_sys::linux::procfs;
-
 mod options;
 use options::*;

 mod setup;
-use setup::{InstallConfig, LocaleInfo, RuntimeInfo, SetupInfo};
+use setup::{InstallConfig, LocaleInfo, ProxmoxProduct, RuntimeInfo, SetupInfo};

 mod system;

@@ -255,7 +253,7 @@ fn installer_setup(in_test_mode: bool) -> Result<(LocaleInfo, RuntimeInfo), Stri

 /// Anything that can be done late in the setup and will not result in fatal errors.
 fn installer_setup_late(siv: &mut Cursive) {
-    let state = siv.user_data::<InstallerState>().unwrap();
+    let state = siv.user_data::<InstallerState>().cloned().unwrap();

     if !state.in_test_mode {
         let kmap_id = &state.options.timezone.kb_layout;
@@ -266,17 +264,14 @@ fn installer_setup_late(siv: &mut Cursive) {
         }
     }

-    if setup_info().config.product == setup::ProxmoxProduct::PVE {
-        let cpu_hvm = procfs::read_cpuinfo().map(|info| info.hvm).unwrap_or(false);
-        if !cpu_hvm {
-            display_setup_warning(
-                siv,
-                concat!(
-                    "No support for hardware-accelerated KVM virtualization detected.\n\n",
-                    "Check BIOS settings for Intel VT / AMD-V / SVM."
-                ),
-            );
-        }
+    if state.setup_info.config.product == ProxmoxProduct::PVE && !state.runtime_info.hvm_supported {
+        display_setup_warning(
+            siv,
+            concat!(
+                "No support for hardware-accelerated KVM virtualization detected.\n\n",
+                "Check BIOS settings for Intel VT / AMD-V / SVM."
+            ),
+        );
     }
 }

diff --git a/proxmox-tui-installer/src/setup.rs b/proxmox-tui-installer/src/setup.rs
index 68207c8..9d14cf8 100644
--- a/proxmox-tui-installer/src/setup.rs
+++ b/proxmox-tui-installer/src/setup.rs
@@ -367,6 +367,10 @@ pub struct RuntimeInfo {

     /// Total memory of the system in MiB.
     pub total_memory: usize,
+
+    /// Whether the CPU supports hardware-accelerated virtualization
+    #[serde(deserialize_with = "deserialize_bool_from_int")]
+    pub hvm_supported: bool,
 }

 #[derive(Clone, Deserialize)]
--
2.40.1





^ permalink raw reply	[flat|nested] 6+ messages in thread

* [pve-devel] [PATCH installer 4/4] d/control: drop unused librust-proxmox-sys-dev build dependency
  2023-07-03  7:34 [pve-devel] [PATCH installer 0/3] export hvm support flag through runtime env Christoph Heiss
                   ` (2 preceding siblings ...)
  2023-07-03  7:35 ` [pve-devel] [PATCH installer 3/3] tui: check hvm support through runtime env info instead of open-coding Christoph Heiss
@ 2023-07-04  8:27 ` Christoph Heiss
  2023-07-13 13:50 ` [pve-devel] applied-series: [PATCH installer 0/3] export hvm support flag through runtime env Thomas Lamprecht
  4 siblings, 0 replies; 6+ messages in thread
From: Christoph Heiss @ 2023-07-04  8:27 UTC (permalink / raw)
  To: pve-devel

Since the TUI installer does not use it anymore, we can drop it from
here as well.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
Missed that while sending the original patch series.

 debian/control | 1 -
 1 file changed, 1 deletion(-)

diff --git a/debian/control b/debian/control
index ef231ba..3d13019 100644
--- a/debian/control
+++ b/debian/control
@@ -8,7 +8,6 @@ Build-Depends: cargo:native,
                libpve-common-perl,
                librsvg2-bin,
                librust-cursive+termion-backend-dev (>= 0.20.0),
-               librust-proxmox-sys-dev (>= 0.5.0),
                librust-regex-1+default-dev (>= 1.7~~),
                librust-serde-1+default-dev,
                librust-serde-json-1+default-dev,
--
2.40.1





^ permalink raw reply	[flat|nested] 6+ messages in thread

* [pve-devel] applied-series: [PATCH installer 0/3] export hvm support flag through runtime env
  2023-07-03  7:34 [pve-devel] [PATCH installer 0/3] export hvm support flag through runtime env Christoph Heiss
                   ` (3 preceding siblings ...)
  2023-07-04  8:27 ` [pve-devel] [PATCH installer 4/4] d/control: drop unused librust-proxmox-sys-dev build dependency Christoph Heiss
@ 2023-07-13 13:50 ` Thomas Lamprecht
  4 siblings, 0 replies; 6+ messages in thread
From: Thomas Lamprecht @ 2023-07-13 13:50 UTC (permalink / raw)
  To: Proxmox VE development discussion, Christoph Heiss

Am 03/07/2023 um 09:34 schrieb Christoph Heiss:
> Currently, the logic to check whether hardware-accelerated
> virtualization is supported or not by the host cpu is duplicated.
> 
> This adds a `hvm_supported` flag to the runtime environment info,
> indicating whether it is supported or not, which can then be used by the
> graphical and console installer to display a message to the user as
> appropriate.
> 
> pve-installer:
> 
> Christoph Heiss (3):
>   run env: add hardware-accelerated virtualization support flag
>   proxinstall: check hvm support through runtime env info
>   tui: check hvm support through runtime env info instead of open-coding
> 
>  Proxmox/Install/RunEnv.pm          | 25 +++++++++++++++++++++++++
>  proxinstall                        | 13 +++++--------
>  proxmox-tui-installer/Cargo.toml   |  2 --
>  proxmox-tui-installer/src/main.rs  | 25 ++++++++++---------------
>  proxmox-tui-installer/src/setup.rs |  4 ++++
>  5 files changed, 44 insertions(+), 25 deletions(-)
> 

applied, thanks!




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-07-13 13:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-03  7:34 [pve-devel] [PATCH installer 0/3] export hvm support flag through runtime env Christoph Heiss
2023-07-03  7:34 ` [pve-devel] [PATCH installer 1/3] run env: add hardware-accelerated virtualization support flag Christoph Heiss
2023-07-03  7:34 ` [pve-devel] [PATCH installer 2/3] proxinstall: check hvm support through runtime env info Christoph Heiss
2023-07-03  7:35 ` [pve-devel] [PATCH installer 3/3] tui: check hvm support through runtime env info instead of open-coding Christoph Heiss
2023-07-04  8:27 ` [pve-devel] [PATCH installer 4/4] d/control: drop unused librust-proxmox-sys-dev build dependency Christoph Heiss
2023-07-13 13:50 ` [pve-devel] applied-series: [PATCH installer 0/3] export hvm support flag through runtime env Thomas Lamprecht

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