public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH proxmox-perl-rs 3/4] pve: add bindings for proxmox-ve-vfio
Date: Tue, 20 Jan 2026 14:13:11 +0100	[thread overview]
Message-ID: <20260120131319.949986-4-c.heiss@proxmox.com> (raw)
In-Reply-To: <20260120131319.949986-1-c.heiss@proxmox.com>

Adds some basic perl binding for the proxmox-ve-vfio, in particular to
retrieve information about creatable vGPU typos for Nvidia host devices.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
 pve-rs/Cargo.toml                          |  1 +
 pve-rs/Makefile                            |  3 +-
 pve-rs/debian/control                      |  1 +
 pve-rs/examples/nv-list-creatable-vgpus.pl | 20 ++++++++++++
 pve-rs/src/lib.rs                          |  1 +
 pve-rs/src/vfio/mod.rs                     |  6 ++++
 pve-rs/src/vfio/nvidia.rs                  | 38 ++++++++++++++++++++++
 7 files changed, 69 insertions(+), 1 deletion(-)
 create mode 100755 pve-rs/examples/nv-list-creatable-vgpus.pl
 create mode 100644 pve-rs/src/vfio/mod.rs
 create mode 100644 pve-rs/src/vfio/nvidia.rs

diff --git a/pve-rs/Cargo.toml b/pve-rs/Cargo.toml
index 527fcae..4e88942 100644
--- a/pve-rs/Cargo.toml
+++ b/pve-rs/Cargo.toml
@@ -49,6 +49,7 @@ proxmox-sys = "1"
 proxmox-tfa = { version = "6.0.3", features = ["api"] }
 proxmox-time = "2"
 proxmox-ve-config = { version = "0.4.5", features = [ "frr" ] }
+proxmox-ve-vfio = { version = "0.1.0" }
 
 # [patch.crates-io]
 # pbs-api-types = { path = "../../proxmox/pbs-api-types" }
diff --git a/pve-rs/Makefile b/pve-rs/Makefile
index aa7181e..45ee12a 100644
--- a/pve-rs/Makefile
+++ b/pve-rs/Makefile
@@ -31,7 +31,8 @@ PERLMOD_PACKAGES := \
 	  PVE::RS::OpenId \
 	  PVE::RS::ResourceScheduling::Static \
 	  PVE::RS::SDN::Fabrics \
-	  PVE::RS::TFA
+	  PVE::RS::TFA \
+	  PVE::RS::VFIO::Nvidia
 
 PERLMOD_PACKAGE_FILES := $(addsuffix .pm,$(subst ::,/,$(PERLMOD_PACKAGES)))
 
diff --git a/pve-rs/debian/control b/pve-rs/debian/control
index 2743712..ec815f2 100644
--- a/pve-rs/debian/control
+++ b/pve-rs/debian/control
@@ -40,6 +40,7 @@ Build-Depends: cargo:native <!nocheck>,
                librust-proxmox-time-2+default-dev,
                librust-proxmox-ve-config-0.4+default-dev (>= 0.4.5-~~),
                librust-proxmox-ve-config-0.4+frr-dev (>= 0.4.5-~~),
+               librust-proxmox-ve-vfio-dev,
                librust-serde-1+default-dev,
                librust-serde-bytes-0.11+default-dev,
                librust-serde-json-1+default-dev,
diff --git a/pve-rs/examples/nv-list-creatable-vgpus.pl b/pve-rs/examples/nv-list-creatable-vgpus.pl
new file mode 100755
index 0000000..2814860
--- /dev/null
+++ b/pve-rs/examples/nv-list-creatable-vgpus.pl
@@ -0,0 +1,20 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+use Data::Dumper;
+
+use PVE::RS::VFIO::Nvidia;
+
+my $bus_id = shift;
+
+die "vGPU bus id expected as first argument, e.g. 00:01.0\n"
+    if !defined($bus_id);
+
+my $creatable =
+    PVE::RS::VFIO::Nvidia::creatable_vgpu_types_for_dev($bus_id);
+
+foreach my $vgpu (@$creatable) {
+    print Dumper(\$vgpu);
+}
diff --git a/pve-rs/src/lib.rs b/pve-rs/src/lib.rs
index b32b061..2e337da 100644
--- a/pve-rs/src/lib.rs
+++ b/pve-rs/src/lib.rs
@@ -14,6 +14,7 @@ use proxmox_notify::{Config, Notification, Severity};
 mod common;
 
 mod sdn;
+mod vfio;
 
 pub mod bindings;
 
diff --git a/pve-rs/src/vfio/mod.rs b/pve-rs/src/vfio/mod.rs
new file mode 100644
index 0000000..4c40a8d
--- /dev/null
+++ b/pve-rs/src/vfio/mod.rs
@@ -0,0 +1,6 @@
+//! Exposes an interface for accessing and handling VFIO host devices such as NVIDIA vGPU devices,
+//! to e.g. extract information about them for preparing passthrough.
+
+#![deny(missing_docs)]
+
+pub mod nvidia;
diff --git a/pve-rs/src/vfio/nvidia.rs b/pve-rs/src/vfio/nvidia.rs
new file mode 100644
index 0000000..5dc5730
--- /dev/null
+++ b/pve-rs/src/vfio/nvidia.rs
@@ -0,0 +1,38 @@
+//! Provides access to the state of NVIDIA (v)GPU devices connected to the system.
+
+#[perlmod::package(name = "PVE::RS::VFIO::Nvidia", lib = "pve_rs")]
+mod export {
+    use anyhow::{Result, anyhow};
+    use perlmod::Value;
+    use proxmox_ve_vfio::nvidia;
+
+    /// Retrieves a list of *creatable* vGPU types for the specified GPU by bus id.
+    ///
+    /// The [`bus_id`] is of format "\<domain\>:\<bus\>:\<device\>.\<function\>",
+    /// e.g. "0000:01:01.0".
+    ///
+    /// # See also
+    ///
+    /// [`nvidia::creatable_vgpu_types_for_dev`]
+    /// [`nvmlDeviceGetHandleByPciBusId_v2`]: <https://docs.nvidia.com/deploy/nvml-api/group__nvmlDeviceQueries.html#group__nvmlDeviceQueries_1gea7484bb9eac412c28e8a73842254c05>
+    /// [`struct nvmlPciInto_t`]: <https://docs.nvidia.com/deploy/nvml-api/structnvmlPciInfo__t.html#structnvmlPciInfo__t_1a4d54ad9b596d7cab96ecc34613adbe4>
+    #[export]
+    fn creatable_vgpu_types_for_dev(bus_id: &str) -> Result<Vec<Value>> {
+        let vgpu_types = nvidia::creatable_vgpu_types_for_dev(bus_id)?;
+
+        let mut result = Vec::with_capacity(vgpu_types.len());
+        for vgpu in vgpu_types {
+            let mut value: Value = perlmod::to_value(&vgpu)?
+                .dereference()
+                .ok_or_else(|| anyhow!("expected reference"))?;
+
+            if let Some(hash) = value.as_hash_mut() {
+                hash.insert("description", Value::new_string(&vgpu.description()));
+            }
+
+            result.push(Value::new_ref(&value));
+        }
+
+        Ok(result)
+    }
+}
-- 
2.52.0



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


  parent reply	other threads:[~2026-01-20 13:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-20 13:13 [pve-devel] [PATCH proxmox-{ve, perl}-rs/common 0/4] use native libnvidia-ml library for vGPU info Christoph Heiss
2026-01-20 13:13 ` [pve-devel] [PATCH proxmox-ve-rs 1/4] vfio: add crate for interacting with vfio host devices Christoph Heiss
2026-01-20 13:13 ` [pve-devel] [PATCH proxmox-ve-rs 2/4] vfio: add rust-native interface for accessing NVIDIA vGPU info Christoph Heiss
2026-01-20 13:13 ` Christoph Heiss [this message]
2026-01-20 13:13 ` [pve-devel] [PATCH common 4/4] sysfs: use new PVE::RS::VFIO::Nvidia module to retrieve " Christoph Heiss
2026-01-20 15:00   ` 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=20260120131319.949986-4-c.heiss@proxmox.com \
    --to=c.heiss@proxmox.com \
    --cc=pve-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