mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alok Kumar <alkumar@nvidia.com>
To: <dakr@kernel.org>, <acourbot@nvidia.com>, <kvm@vger.kernel.org>,
	<rust-for-linux@vger.kernel.org>, <nova-gpu@lists.linux.dev>,
	<linux-pci@vger.kernel.org>
Cc: <alex@shazbot.org>, <jgg@nvidia.com>, <yishaih@nvidia.com>,
	<skolothumtho@nvidia.com>, <kevin.tian@intel.com>,
	<airlied@gmail.com>, <simona@ffwll.ch>, <ojeda@kernel.org>,
	<alex.gaynor@gmail.com>, <boqun.feng@gmail.com>,
	<gary@garyguo.net>, <bjorn3_gh@protonmail.com>,
	<lossin@kernel.org>, <a.hindborg@kernel.org>,
	<aliceryhl@google.com>, <tmgross@umich.edu>,
	<markus.probst@posteo.de>, <jhubbard@nvidia.com>,
	<apopple@nvidia.com>, <joelagnelf@nvidia.com>,
	<ecourtney@nvidia.com>, <cjia@nvidia.com>, <smitra@nvidia.com>,
	<kjaju@nvidia.com>, <alkumar@nvidia.com>, <ankita@nvidia.com>,
	<aniketa@nvidia.com>, <kwankhede@nvidia.com>,
	<targupta@nvidia.com>, <linux-kernel@vger.kernel.org>,
	<zhiwang@kernel.org>, <zhiw@nvidia.com>, <boqun@kernel.org>,
	<daniel.almeida@collabora.com>, <tamird@kernel.org>,
	<work@onurozkan.dev>, <jgg@ziepe.ca>, <bhelgaas@google.com>,
	<kwilczynski@kernel.org>, <dri-devel@lists.freedesktop.org>,
	<peter@colberg.org>, <xinmengs@nvidia.com>
Subject: [PATCH v6 21/34] gpu: nova-core: vgpu: query VF assignments and properties
Date: Wed, 2 Dec 2026 13:58:45 +0530	[thread overview]
Message-ID: <3c007bb2a13cd7120a30a03e40007b1902b4e527.1796191007.git.alkumar@nvidia.com> (raw)
In-Reply-To: <cover.1796191007.git.alkumar@nvidia.com>

From: Zhi Wang <zhiw@nvidia.com>

Creating an instance requires its VF assignment and the corresponding
vGPU properties before reserving resources.

Decode the VF assignment and NVKV property replies at their query entry
points. Validate the returned type ID and nonzero instance limit, and
initialize the decoded properties on the heap.

Co-developed-by: Eliot Courtney <ecourtney@nvidia.com>
Signed-off-by: Eliot Courtney <ecourtney@nvidia.com>
Co-developed-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Zhi Wang <zhiw@nvidia.com>
Signed-off-by: Alok Kumar <alkumar@nvidia.com>
---
 drivers/gpu/nova-core/gsp.rs              |   1 +
 drivers/gpu/nova-core/gsp/fw.rs           |   2 +-
 drivers/gpu/nova-core/sbuffer.rs          |   7 ++
 drivers/gpu/nova-core/vgpu.rs             |  11 ++
 drivers/gpu/nova-core/vgpu/commands.rs    | 126 ++++++++++++++++++++++
 drivers/gpu/nova-core/vgpu/fw.rs          |   6 ++
 drivers/gpu/nova-core/vgpu/fw/commands.rs |  75 +++++++++++++
 7 files changed, 227 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/nova-core/vgpu/commands.rs
 create mode 100644 drivers/gpu/nova-core/vgpu/fw/commands.rs

diff --git a/drivers/gpu/nova-core/gsp.rs b/drivers/gpu/nova-core/gsp.rs
index 84a76c1c39cd..66e08cbb75a8 100644
--- a/drivers/gpu/nova-core/gsp.rs
+++ b/drivers/gpu/nova-core/gsp.rs
@@ -29,6 +29,7 @@
 pub(crate) use logbuffer::RetainedLogs;
 
 pub(crate) use fw::{
+    GmcCommandId,
     GspFmcBootParams,
     GspFwWprMeta,
     LibosMemoryRegionInitArgument,
diff --git a/drivers/gpu/nova-core/gsp/fw.rs b/drivers/gpu/nova-core/gsp/fw.rs
index 7a2a45192c9a..0ea27cb547b4 100644
--- a/drivers/gpu/nova-core/gsp/fw.rs
+++ b/drivers/gpu/nova-core/gsp/fw.rs
@@ -2,7 +2,7 @@
 // SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 
 pub(crate) mod commands;
-mod r000_00;
+pub(crate) mod r000_00;
 
 // Alias to avoid repeating the version number with every use.
 use r000_00 as bindings;
diff --git a/drivers/gpu/nova-core/sbuffer.rs b/drivers/gpu/nova-core/sbuffer.rs
index b8c01104c255..fd410aef2a1f 100644
--- a/drivers/gpu/nova-core/sbuffer.rs
+++ b/drivers/gpu/nova-core/sbuffer.rs
@@ -161,6 +161,13 @@ pub(crate) fn read_exact(&mut self, mut dst: &mut [u8]) -> Result {
         Ok(())
     }
 
+    pub(crate) fn read<T: FromBytes + IntoBytes>(&mut self) -> Result<T> {
+        let mut ret = T::new_zeroed();
+        self.read_exact(ret.as_mut_bytes())?;
+
+        Ok(ret)
+    }
+
     /// Read all the remaining data into a [`KVec`].
     ///
     /// `self` will be empty after this operation.
diff --git a/drivers/gpu/nova-core/vgpu.rs b/drivers/gpu/nova-core/vgpu.rs
index bf5d00a9e1cf..5688d6bf1e08 100644
--- a/drivers/gpu/nova-core/vgpu.rs
+++ b/drivers/gpu/nova-core/vgpu.rs
@@ -4,6 +4,7 @@
 use core::num::NonZero;
 
 use kernel::{
+    bitfield,
     device,
     pci,
     prelude::*, //
@@ -21,10 +22,20 @@
     gsp::commands::FifoEngineList, //
 };
 
+mod commands;
 mod fw;
 mod hal;
 mod vram;
 
+bitfield! {
+    struct Dbdf(u32) {
+        2:0 function;
+        7:3 device;
+        15:8 bus;
+        31:16 domain;
+    }
+}
+
 /// vGPU state detected during GPU construction.
 #[derive(Debug, Clone, Copy)]
 pub(crate) enum VgpuState {
diff --git a/drivers/gpu/nova-core/vgpu/commands.rs b/drivers/gpu/nova-core/vgpu/commands.rs
new file mode 100644
index 000000000000..66669948230a
--- /dev/null
+++ b/drivers/gpu/nova-core/vgpu/commands.rs
@@ -0,0 +1,126 @@
+// SPDX-License-Identifier: GPL-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+//! vGPU firmware command operations.
+//!
+//! Sends requests, checks responses and coordinates the firmware command
+//! sequences used by instance lifecycle operations.
+
+use core::convert::Infallible;
+
+use kernel::{
+    device,
+    prelude::*, //
+};
+
+use crate::{
+    gsp::{
+        cmdq::{
+            gmc::{
+                CommandToGsp,
+                MessageFromGsp,
+                MessagePayload, //
+            },
+            Cmdq,
+        },
+        nvkv::{
+            nvkv_words,
+            Decoder,
+            Schema,
+            UnknownKeyPolicy, //
+        },
+        GmcCommandId,
+        GSP_PAGE_SIZE, //
+    },
+    vgpu::{
+        fw::commands::{
+            AssignedVfVgpuType,
+            VgpuProperties,
+            VgpuPropertiesSchema, //
+        },
+        Dbdf,
+    },
+};
+
+struct QueryAssignedVfVgpuType(Dbdf);
+
+impl CommandToGsp for QueryAssignedVfVgpuType {
+    const COMMAND: GmcCommandId = GmcCommandId::QueryAssignedVfVgpuType;
+    type Command = u64;
+    type Reply = AssignedVfVgpuType;
+    const MAX_REPLY_SIZE: u32 = cv!(size_of::<AssignedVfVgpuType>());
+    type InitError = Infallible;
+
+    fn init(&self) -> impl Init<Self::Command, Self::InitError> {
+        u64::from(self.0.into_raw()).to_le()
+    }
+}
+
+impl MessageFromGsp for AssignedVfVgpuType {
+    type InitError = Error;
+
+    fn read(payload: &mut MessagePayload<'_>) -> Result<Self, Self::InitError> {
+        payload.read()
+    }
+}
+
+/// Query the vGPU type assigned to a VF by its DBDF.
+#[expect(dead_code)]
+pub(super) fn query_assigned_vf_type(
+    _dev: &device::Device,
+    cmdq: &Cmdq<'_>,
+    dbdf: Dbdf,
+) -> Result<u32> {
+    let reply = cmdq
+        .send_gmc_command(QueryAssignedVfVgpuType(dbdf), |_| Ok(()))?
+        .map_err(|_| EIO)?;
+
+    Ok(reply.vgpu_type_id)
+}
+
+struct QueryVgpuProperties(u32);
+
+impl CommandToGsp for QueryVgpuProperties {
+    const COMMAND: GmcCommandId = GmcCommandId::QueryVgpuProperties;
+    type Command = u32;
+    type Reply = KBox<VgpuProperties>;
+    /// The reply is NVKV-encoded and varies in length.
+    const MAX_REPLY_SIZE: u32 = cv!(GSP_PAGE_SIZE);
+    type InitError = Infallible;
+
+    fn init(&self) -> impl Init<Self::Command, Self::InitError> {
+        self.0.to_le()
+    }
+}
+
+impl MessageFromGsp for KBox<VgpuProperties> {
+    type InitError = Error;
+
+    fn read(payload: &mut MessagePayload<'_>) -> Result<Self, Self::InitError> {
+        let bytes = payload.flush_into_kvec(GFP_KERNEL)?;
+        let words = nvkv_words(&bytes, &[])?;
+        let decoder = Decoder::new(&words, UnknownKeyPolicy::Ignore);
+        let mut schema = KBox::init(VgpuPropertiesSchema::init(), GFP_KERNEL)?;
+        let properties = KBox::try_init(decoder.decode(&mut *schema)?, GFP_KERNEL)?;
+
+        Ok(properties)
+    }
+}
+
+/// Query and decode the firmware properties of one vGPU type.
+#[expect(dead_code)]
+pub(super) fn query_vgpu_properties(
+    _dev: &device::Device,
+    cmdq: &Cmdq<'_>,
+    type_id: u32,
+) -> Result<KBox<VgpuProperties>> {
+    let properties = cmdq
+        .send_gmc_command(QueryVgpuProperties(type_id), |_| Ok(()))?
+        .map_err(|_| EIO)?;
+
+    if properties.type_id != type_id || properties.max_instance == 0 {
+        Err(EINVAL)
+    } else {
+        Ok(properties)
+    }
+}
diff --git a/drivers/gpu/nova-core/vgpu/fw.rs b/drivers/gpu/nova-core/vgpu/fw.rs
index e4571cfe11a3..2d32e196a771 100644
--- a/drivers/gpu/nova-core/vgpu/fw.rs
+++ b/drivers/gpu/nova-core/vgpu/fw.rs
@@ -1,4 +1,10 @@
 // SPDX-License-Identifier: GPL-2.0
 // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 
+//! vGPU firmware interface.
+//!
+//! Exposes command constants and communication buffer layout types from
+//! raw firmware bindings.
+
+pub(super) mod commands;
 mod r000_00;
diff --git a/drivers/gpu/nova-core/vgpu/fw/commands.rs b/drivers/gpu/nova-core/vgpu/fw/commands.rs
new file mode 100644
index 000000000000..d1864d7ab530
--- /dev/null
+++ b/drivers/gpu/nova-core/vgpu/fw/commands.rs
@@ -0,0 +1,75 @@
+// SPDX-License-Identifier: GPL-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+//! Wire types and codecs for vGPU commands.
+//!
+//! Defines request encoders and response schemas independently of command
+//! submission and instance lifecycle operations.
+
+use kernel::{
+    alloc::ArrayVec,
+    prelude::*, //
+};
+
+use crate::{
+    gsp::nvkv::{
+        nvkv_decode,
+        Array,
+        Key,
+        Required, //
+    }, //
+};
+
+nvkv_decode! {
+    pub(crate) struct VgpuPropertiesSchema => VgpuProperties {
+        // TODO: `name`/`class` required?
+        name: Array<u8, { VgpuProperties::STRING_LEN }, 0x3100>,
+        class: Array<u8, { VgpuProperties::STRING_LEN }, 0x3101>,
+        type_id: Required<Key<u32, 0x3102>>,
+        bar1_length: Required<Key<u64, 0x3103>>,
+        max_instance: Required<Key<u32, 0x3104>>,
+        ecc: Key<u32, 0x3105>,
+        profile_size: Required<Key<u64, 0x3106>>,
+        max_fps: Key<u32, 0x3107>,
+        num_heads: Key<u32, 0x3108>,
+        max_res_x: Key<u32, 0x3109>,
+        max_res_y: Key<u32, 0x310A>,
+        dev_id: Required<Key<u32, 0x310B>>,
+        subsystem_id: Required<Key<u32, 0x310C>>,
+        fb_length: Required<Key<u64, 0x310D>>,
+        gsp_heap_size: Required<Key<u64, 0x310E>>,
+        fb_reservation: Required<Key<u64, 0x310F>>,
+    }
+}
+
+pub(crate) struct VgpuProperties {
+    name: ArrayVec<u8, { Self::STRING_LEN }>,
+    class: ArrayVec<u8, { Self::STRING_LEN }>,
+    pub(crate) type_id: u32,
+    pub(crate) bar1_length: u64,
+    pub(crate) max_instance: u32,
+    ecc: u32,
+    profile_size: u64,
+    max_fps: u32,
+    num_heads: u32,
+    max_res_x: u32,
+    max_res_y: u32,
+    pub(crate) dev_id: u32,
+    pub(crate) subsystem_id: u32,
+    pub(crate) fb_length: u64,
+    pub(crate) gsp_heap_size: u64,
+    fb_reservation: u64,
+}
+
+impl VgpuProperties {
+    const STRING_LEN: usize = 64;
+}
+
+// TODO: extract from bindings
+#[repr(C)]
+#[derive(FromBytes, IntoBytes)]
+pub(crate) struct AssignedVfVgpuType {
+    pub(crate) vgpu_type_id: u32,
+    _swizz_id: u32,
+    _placement_id: u32,
+}

  parent reply	other threads:[~2026-12-02  8:37 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  8:28 [PATCH v6 00/34] Introduce NVIDIA vGPU manager Alok Kumar
2026-12-02  8:28 ` [PATCH v6 01/34] gpu: nova-core: populate VF information in GSP_INIT Alok Kumar
2026-12-02  8:28 ` [PATCH v6 02/34] gpu: nova-core: gsp: pass boot context through setup helpers Alok Kumar
2026-12-02  8:28 ` [PATCH v6 03/34] gpu: nova-core: vgpu: decouple boot state from the manager Alok Kumar
2026-12-02  8:28 ` [PATCH v6 04/34] gpu: nova-core: gpu: add a channel ID pool for vGPU Alok Kumar
2026-12-02  8:28 ` [PATCH v6 05/34] gpu: nova-core: gsp: decode the FIFO engine table Alok Kumar
2026-12-02  8:28 ` [PATCH v6 06/34] gpu: nova-core: vgpu: initialize runtime parameters after GSP boot Alok Kumar
2026-12-02  8:28 ` [PATCH v6 07/34] gpu: nova-core: vgpu: reserve the 48-VM WPR2 heap Alok Kumar
2026-12-02  8:28 ` [PATCH v6 08/34] gpu: nova-core: mm: replace BarUserAccess accessors with typed MMIO view Alok Kumar
2026-12-02  8:28 ` [PATCH v6 09/34] gpu: nova-core: mm: retain BAR1 reservations after unmap failure Alok Kumar
2026-12-02  8:28 ` [PATCH v6 10/34] gpu: nova-core: mm: borrow BarUser for temporary BAR1 access Alok Kumar
2026-12-02  8:28 ` [PATCH v6 11/34] gpu: nova-core: mm: add VramBlock Alok Kumar
2026-12-02  8:28 ` [PATCH v6 12/34] gpu: nova-core: mm: add VramRegion Alok Kumar
2026-12-02  8:28 ` [PATCH v6 13/34] gpu: nova-core: mm: add BarMapping Alok Kumar
2026-12-02  8:28 ` [PATCH v6 14/34] gpu: nova-core: mm: add SharedGpuMm Alok Kumar
2026-12-02  8:28 ` [PATCH v6 15/34] gpu: nova-core: gsp: cmdq: gmc: add types for variable-length payloads Alok Kumar
2026-12-02  8:28 ` [PATCH v6 16/34] gpu: nova-core: gsp: add the vGPU commands to GmcCommandId Alok Kumar
2026-12-02  8:28 ` [PATCH v6 17/34] gpu: nova-core: gsp: cmdq: add send_gmc_command_await_event Alok Kumar
2026-12-02  8:28 ` [PATCH v6 18/34] gpu: nova-core: vgpu: add r000 plugin bindings Alok Kumar
2026-12-02  8:28 ` [PATCH v6 19/34] gpu: nova-core: gsp: factor out NVKV payload conversion Alok Kumar
2026-12-02  8:28 ` [PATCH v6 20/34] gpu: nova-core: vgpu: add VRAM slot pool Alok Kumar
2026-12-02  8:28 ` Alok Kumar [this message]
2026-12-02  8:28 ` [PATCH v6 22/34] gpu: nova-core: vgpu: add instance create/destroy Alok Kumar
2026-12-02  8:28 ` [PATCH v6 23/34] gpu: nova-core: vgpu: encode vGPU boot requests Alok Kumar
2026-12-02  8:28 ` [PATCH v6 24/34] gpu: nova-core: vgpu: add GSP plugin communication buffer Alok Kumar
2026-12-02  8:28 ` [PATCH v6 25/34] gpu: nova-core: vgpu: add instance boot Alok Kumar
2026-12-02  8:28 ` [PATCH v6 26/34] gpu: nova-core: vgpu: add instance shutdown Alok Kumar
2026-12-02  8:28 ` [PATCH v6 27/34] gpu: nova-core: vgpu: add GSP plugin RPC transactions Alok Kumar
2026-12-02  8:28 ` [PATCH v6 28/34] gpu: nova-core: vgpu: negotiate the GSP plugin RPC version Alok Kumar
2026-12-02  8:28 ` [PATCH v6 29/34] gpu: nova-core: vgpu: send GSP plugin configuration parameters Alok Kumar
2026-12-02  8:28 ` [PATCH v6 30/34] gpu: nova-core: vgpu: update the GSP plugin BME state Alok Kumar
2026-12-02  8:28 ` [PATCH v6 31/34] gpu: nova-core: vgpu: add CeUtils commands Alok Kumar
2026-12-02  8:28 ` [PATCH v6 32/34] gpu: nova-core: vgpu: scrub guest VRAM with CeUtils Alok Kumar
2026-12-02  8:28 ` [PATCH v6 33/34] gpu: nova-core: vgpu: introduce SR-IOV PF APIs Alok Kumar
2026-12-02  8:28 ` [PATCH v6 34/34] gpu: nova-core: mm: keep BAR1 self-test page tables alive Alok Kumar

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=3c007bb2a13cd7120a30a03e40007b1902b4e527.1796191007.git.alkumar@nvidia.com \
    --to=alkumar@nvidia.com \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=airlied@gmail.com \
    --cc=alex.gaynor@gmail.com \
    --cc=alex@shazbot.org \
    --cc=aliceryhl@google.com \
    --cc=aniketa@nvidia.com \
    --cc=ankita@nvidia.com \
    --cc=apopple@nvidia.com \
    --cc=bhelgaas@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=boqun@kernel.org \
    --cc=cjia@nvidia.com \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=ecourtney@nvidia.com \
    --cc=gary@garyguo.net \
    --cc=jgg@nvidia.com \
    --cc=jgg@ziepe.ca \
    --cc=jhubbard@nvidia.com \
    --cc=joelagnelf@nvidia.com \
    --cc=kevin.tian@intel.com \
    --cc=kjaju@nvidia.com \
    --cc=kvm@vger.kernel.org \
    --cc=kwankhede@nvidia.com \
    --cc=kwilczynski@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=markus.probst@posteo.de \
    --cc=nova-gpu@lists.linux.dev \
    --cc=ojeda@kernel.org \
    --cc=peter@colberg.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=simona@ffwll.ch \
    --cc=skolothumtho@nvidia.com \
    --cc=smitra@nvidia.com \
    --cc=tamird@kernel.org \
    --cc=targupta@nvidia.com \
    --cc=tmgross@umich.edu \
    --cc=work@onurozkan.dev \
    --cc=xinmengs@nvidia.com \
    --cc=yishaih@nvidia.com \
    --cc=zhiw@nvidia.com \
    --cc=zhiwang@kernel.org \
    /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

all inboxes | Powered by JetHome®