From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 269BA1FF15E for ; Tue, 20 Jan 2026 14:14:04 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 0F4541011C; Tue, 20 Jan 2026 14:14:14 +0100 (CET) From: Christoph Heiss To: pve-devel@lists.proxmox.com Date: Tue, 20 Jan 2026 14:13:11 +0100 Message-ID: <20260120131319.949986-4-c.heiss@proxmox.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260120131319.949986-1-c.heiss@proxmox.com> References: <20260120131319.949986-1-c.heiss@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1768914765474 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.052 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH proxmox-perl-rs 3/4] pve: add bindings for proxmox-ve-vfio X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" 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 --- 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 , 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 "\:\:\.\", + /// e.g. "0000:01:01.0". + /// + /// # See also + /// + /// [`nvidia::creatable_vgpu_types_for_dev`] + /// [`nvmlDeviceGetHandleByPciBusId_v2`]: + /// [`struct nvmlPciInto_t`]: + #[export] + fn creatable_vgpu_types_for_dev(bus_id: &str) -> Result> { + 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