From: Alex Williamson <alex.williamson@redhat.com>
To: <ankita@nvidia.com>
Cc: <jgg@nvidia.com>, <yishaih@nvidia.com>,
<shameerali.kolothum.thodi@huawei.com>, <kevin.tian@intel.com>,
<zhiw@nvidia.com>, <aniketa@nvidia.com>, <cjia@nvidia.com>,
<kwankhede@nvidia.com>, <targupta@nvidia.com>,
<vsethi@nvidia.com>, <acurrid@nvidia.com>, <apopple@nvidia.com>,
<jhubbard@nvidia.com>, <danw@nvidia.com>, <kjaju@nvidia.com>,
<anuaggarwal@nvidia.com>, <mochs@nvidia.com>,
<kvm@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v5 3/3] vfio/nvgrace-gpu: Check the HBM training and C2C link status
Date: Fri, 24 Jan 2025 09:24:59 -0700 [thread overview]
Message-ID: <20250124092459.7ef4df51.alex.williamson@redhat.com> (raw)
In-Reply-To: <20250123174854.3338-4-ankita@nvidia.com>
On Thu, 23 Jan 2025 17:48:54 +0000
<ankita@nvidia.com> wrote:
> From: Ankit Agrawal <ankita@nvidia.com>
>
> In contrast to Grace Hopper systems, the HBM training has been moved
> out of the UEFI on the Grace Blackwell systems. This reduces the system
> bootup time significantly.
>
> The onus of checking whether the HBM training has completed thus falls
> on the module.
>
> The HBM training status can be determined from a BAR0 register.
> Similarly, another BAR0 register exposes the status of the CPU-GPU
> chip-to-chip (C2C) cache coherent interconnect.
>
> Based on testing, 30s is determined to be sufficient to ensure
> initialization completion on all the Grace based systems. Thus poll
> these register and check for 30s. If the HBM training is not complete
> or if the C2C link is not ready, fail the probe.
>
> While the time is not required on Grace Hopper systems, it is
> beneficial to make the check to ensure the device is in an
> expected state. Hence keeping it generalized to both the generations.
>
> Ensure that the BAR0 is enabled before accessing the registers.
>
> CC: Alex Williamson <alex.williamson@redhat.com>
> CC: Kevin Tian <kevin.tian@intel.com>
> CC: Jason Gunthorpe <jgg@nvidia.com>
> Signed-off-by: Ankit Agrawal <ankita@nvidia.com>
> ---
> drivers/vfio/pci/nvgrace-gpu/main.c | 72 +++++++++++++++++++++++++++++
> 1 file changed, 72 insertions(+)
>
> diff --git a/drivers/vfio/pci/nvgrace-gpu/main.c b/drivers/vfio/pci/nvgrace-gpu/main.c
> index f4f23c0c95c7..fc480ea32c11 100644
> --- a/drivers/vfio/pci/nvgrace-gpu/main.c
> +++ b/drivers/vfio/pci/nvgrace-gpu/main.c
> @@ -5,6 +5,8 @@
>
> #include <linux/sizes.h>
> #include <linux/vfio_pci_core.h>
> +#include <linux/delay.h>
> +#include <linux/jiffies.h>
>
> /*
> * The device memory usable to the workloads running in the VM is cached
> @@ -25,6 +27,13 @@
>
> #define GPU_CAP_DVSEC_REGISTER 3
>
> +#define C2C_LINK_BAR0_OFFSET 0x1498
> +#define HBM_TRAINING_BAR0_OFFSET 0x200BC
> +#define STATUS_READY 0xFF
> +
> +#define POLL_QUANTUM_MS 1000
> +#define POLL_TIMEOUT_MS (30 * 1000)
> +
> /*
> * The state of the two device memory region - resmem and usemem - is
> * saved as struct mem_region.
> @@ -861,6 +870,65 @@ static bool nvgrace_gpu_has_mig_hw_bug(struct pci_dev *pdev)
> return true;
> }
>
> +/*
> + * To reduce the system bootup time, the HBM training has
> + * been moved out of the UEFI on the Grace-Blackwell systems.
> + *
> + * The onus of checking whether the HBM training has completed
> + * thus falls on the module. The HBM training status can be
> + * determined from a BAR0 register.
> + *
> + * Similarly, another BAR0 register exposes the status of the
> + * CPU-GPU chip-to-chip (C2C) cache coherent interconnect.
> + *
> + * Poll these register and check for 30s. If the HBM training is
> + * not complete or if the C2C link is not ready, fail the probe.
> + *
> + * While the wait is not required on Grace Hopper systems, it
> + * is beneficial to make the check to ensure the device is in an
> + * expected state.
> + *
> + * Ensure that the BAR0 region is enabled before accessing the
> + * registers.
> + */
> +static int nvgrace_gpu_wait_device_ready(struct pci_dev *pdev)
> +{
> + unsigned long timeout = jiffies + msecs_to_jiffies(POLL_TIMEOUT_MS);
> + void __iomem *io;
> + int ret = -ETIME;
> +
> + ret = pci_enable_device(pdev);
> + if (ret)
> + return ret;
> +
> + ret = pci_request_selected_regions(pdev, 1 << 0, "vfio-pci");
All the overhead of enabling the device and requesting the region, only
to undo it around this simple test is unfortunate, but I think correct.
Even though this is only briefly taken, I'd suggest using KBUILD_MODNAME
there rather than "vfio-pci" to differentiate from the core code.
Thanks,
Alex
> + if (ret)
> + goto request_region_exit;
> +
> + io = pci_iomap(pdev, 0, 0);
> + if (!io) {
> + ret = -ENOMEM;
> + goto iomap_exit;
> + }
> +
> + do {
> + if ((ioread32(io + C2C_LINK_BAR0_OFFSET) == STATUS_READY) &&
> + (ioread32(io + HBM_TRAINING_BAR0_OFFSET) == STATUS_READY)) {
> + ret = 0;
> + goto reg_check_exit;
> + }
> + msleep(POLL_QUANTUM_MS);
> + } while (!time_after(jiffies, timeout));
> +
> +reg_check_exit:
> + pci_iounmap(pdev, io);
> +iomap_exit:
> + pci_release_selected_regions(pdev, 1 << 0);
> +request_region_exit:
> + pci_disable_device(pdev);
> + return ret;
> +}
> +
> static int nvgrace_gpu_probe(struct pci_dev *pdev,
> const struct pci_device_id *id)
> {
> @@ -869,6 +937,10 @@ static int nvgrace_gpu_probe(struct pci_dev *pdev,
> u64 memphys, memlength;
> int ret;
>
> + ret = nvgrace_gpu_wait_device_ready(pdev);
> + if (ret)
> + return ret;
> +
> ret = nvgrace_gpu_fetch_memory_property(pdev, &memphys, &memlength);
> if (!ret)
> ops = &nvgrace_gpu_pci_ops;
next prev parent reply other threads:[~2025-01-24 16:25 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-23 17:48 [PATCH v5 0/3] vfio/nvgrace-gpu: Enable grace blackwell boards ankita
2025-01-23 17:48 ` [PATCH v5 1/3] vfio/nvgrace-gpu: Read dvsec register to determine need for uncached resmem ankita
2025-01-24 16:24 ` Alex Williamson
2025-01-24 17:51 ` Ankit Agrawal
2025-01-23 17:48 ` [PATCH v5 2/3] vfio/nvgrace-gpu: Expose the blackwell device PF BAR1 to the VM ankita
2025-01-23 17:48 ` [PATCH v5 3/3] vfio/nvgrace-gpu: Check the HBM training and C2C link status ankita
2025-01-24 16:24 ` Alex Williamson [this message]
2025-01-24 17:53 ` Ankit Agrawal
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=20250124092459.7ef4df51.alex.williamson@redhat.com \
--to=alex.williamson@redhat.com \
--cc=acurrid@nvidia.com \
--cc=aniketa@nvidia.com \
--cc=ankita@nvidia.com \
--cc=anuaggarwal@nvidia.com \
--cc=apopple@nvidia.com \
--cc=cjia@nvidia.com \
--cc=danw@nvidia.com \
--cc=jgg@nvidia.com \
--cc=jhubbard@nvidia.com \
--cc=kevin.tian@intel.com \
--cc=kjaju@nvidia.com \
--cc=kvm@vger.kernel.org \
--cc=kwankhede@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mochs@nvidia.com \
--cc=shameerali.kolothum.thodi@huawei.com \
--cc=targupta@nvidia.com \
--cc=vsethi@nvidia.com \
--cc=yishaih@nvidia.com \
--cc=zhiw@nvidia.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
all inboxes | Powered by JetHome®