From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B63F019B5B1 for ; Fri, 17 Jan 2025 18:28:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737138484; cv=none; b=tNQUHN57u/dB91GUDEa3p/mGvHux4V+5VzSGc3wn7X/0qg5IA3bqPsEjyQaYePec34iX+Qb1O2/HPckkDF6xHfFJdt9QqGQMRmTh8Ou08MCAsD2IeMl836m6z+IqesLn5RTw87OfngHPfizFKTuprkh46fNlOlUrubJj3ogvtiQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737138484; c=relaxed/simple; bh=W2Hegohm4VymXTTP8cg88ToPh1c4SV09p4bZbsV2YXo=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Cnokg8qLHBrrOfQRBkC/ACB94IxLT96oAfcfU05N5tMhVi/jfAw2d4X4R/yTD25EwLBAm0cv9Nkorbca3DpKZS/R0Gq6juk5xr/n6aBA8+wPK+230ezxi5+ECFiz1f194PqVjMdDl4e7kiew49zEaCa+RDzQf2llSNr6Sb1USLo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=I9st2OFO; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="I9st2OFO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737138481; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WpjdRvgVOToLqKIeA9/YQhrMl5I+OiQd2jnnQassonw=; b=I9st2OFOjEamElzd5clj9xCA79ALkdcBuCmO2DUr0/VQdCbtEkVi3rtqgO75N8shFZ0F+m w430H/tYX7hLvq4WdrTfkaG+O6TAoC4FleGhMC5rGoJhZSZsWTiFVFXbLvRT7jM1opUVz4 U/kb+IeqoeN2mEjuPF5ACXj5tEyV6r0= Received: from mail-il1-f198.google.com (mail-il1-f198.google.com [209.85.166.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-532-sLarm4E9MjyfDCn2yAjX4A-1; Fri, 17 Jan 2025 13:27:55 -0500 X-MC-Unique: sLarm4E9MjyfDCn2yAjX4A-1 X-Mimecast-MFC-AGG-ID: sLarm4E9MjyfDCn2yAjX4A Received: by mail-il1-f198.google.com with SMTP id e9e14a558f8ab-3cf788751a3so906355ab.3 for ; Fri, 17 Jan 2025 10:27:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737138474; x=1737743274; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=WpjdRvgVOToLqKIeA9/YQhrMl5I+OiQd2jnnQassonw=; b=uYTFLI+Q9LUEyusYCF7gul5iqL5FiAlXmq+BpOOu2n2ejcT7F/vjLplJIx9lXpBirJ hhHHJgITgii5JPscTl/rf67uVzGQOpwLPwF9amOdOA/0iM1Tc9Wem1YM7gyqhfb6dcDz xXAr+LVfABAfq3fVuZXBCu4GxRFBZ+d9gcNZa5EY2Fi6XO0VN7moi7r7ScRkHsVO2MKx q0EZgJVPKHNroF1WK0ZNqOZpYIfoEWbTG23/Kl4Q+nu4J4hFszL7sc1RJKblcx/+0/K2 80HWYUiYbv6HITq1q7vvr68xyRENImJaEzY8kERpXqm5sTk9Ptfyv4j9mJJx4sUShrsO 4drg== X-Forwarded-Encrypted: i=1; AJvYcCXx1U+/LRa1RKQw0DlFjvtefk5reIaDVztarN8ZnU0h+HDDCNEgvDH7jMF4U2NzL555Qcxyh4/ehheUspY=@vger.kernel.org X-Gm-Message-State: AOJu0YyxzBYQ2ncG5u2BuEKeoiJywD3HwP2r01Nfi2G+30/QU6gF47ck BdfHdxcCOnyUpEnBUSb8FpLOehGL+F3lSkGcSLNk7gl/aG6V6dhazCBS8rGqOdNzYMU+cZE986t 0Zj8XCD0NuT8KDbJDT9+NcSEawH42yIRSsaqhvh44mdPUZm1E5irbyux+GjTdutWk/tZ4Hg== X-Gm-Gg: ASbGncs7rLIlebLVO9uyGmp6tANXuhvzwULYPNu9X2Yz9NXwvq1zyZQoNs0Tlc1wYqv JVJSoVlEI/YsPEIiqNysa59BgRpGmxSLSJxJKXwpL2uJI5L2qYz1sNtwjdU2ynQFM9p+L6xX6Lp hWvPuXXJShitmPQkchC3V91/Msga4mfZzd3UlXSqvjtpgHXCdF6wLnisp78qGXXt4CRPKcbTS3N 0gg1LeaZ/tqNesm4Cef6bGjULnvbtoiq/rneEKa+BUOStEs7Kh7REO8uLAw X-Received: by 2002:a05:6602:81c:b0:83a:abd1:6af2 with SMTP id ca18e2360f4ac-851b62a8c7dmr65976839f.3.1737138474313; Fri, 17 Jan 2025 10:27:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IGwhnQIjfi1UjL2DLtvyebagAuwHm+XwHli4G3WUGNC5GCfGJ68AWSAHcvzyWG7Y/c2Uc3W1g== X-Received: by 2002:a05:6602:81c:b0:83a:abd1:6af2 with SMTP id ca18e2360f4ac-851b62a8c7dmr65976039f.3.1737138473961; Fri, 17 Jan 2025 10:27:53 -0800 (PST) Received: from redhat.com ([38.15.36.11]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4ea756493a7sm748724173.75.2025.01.17.10.27.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2025 10:27:53 -0800 (PST) Date: Fri, 17 Jan 2025 13:27:36 -0500 From: Alex Williamson To: Cc: , , , , , , , , , , , , , , , , , Subject: Re: [PATCH v3 3/3] vfio/nvgrace-gpu: Check the HBM training and C2C link status Message-ID: <20250117132736.408954ac.alex.williamson@redhat.com> In-Reply-To: <20250117152334.2786-4-ankita@nvidia.com> References: <20250117152334.2786-1-ankita@nvidia.com> <20250117152334.2786-4-ankita@nvidia.com> Organization: Red Hat Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 17 Jan 2025 15:23:34 +0000 wrote: > From: Ankit Agrawal > > 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. > > Signed-off-by: Ankit Agrawal > --- > drivers/vfio/pci/nvgrace-gpu/main.c | 55 +++++++++++++++++++++++++++++ > 1 file changed, 55 insertions(+) > > diff --git a/drivers/vfio/pci/nvgrace-gpu/main.c b/drivers/vfio/pci/nvgrace-gpu/main.c > index 89d38e3c0261..6298e7f0fe1a 100644 > --- a/drivers/vfio/pci/nvgrace-gpu/main.c > +++ b/drivers/vfio/pci/nvgrace-gpu/main.c > @@ -5,6 +5,8 @@ > > #include > #include > +#include > +#include > > /* > * 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. > @@ -855,6 +864,48 @@ static bool nvgrace_gpu_has_mig_hw_bug_fix(struct pci_dev *pdev) > return false; > } > > +/* > + * 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. > + */ > +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; > + > + io = pci_iomap(pdev, 0, 0); > + if (!io) > + return -ENOMEM; > + > + 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); > + return ret; We're accessing device memory here but afaict the memory enable bit of the command register is in an indeterminate state. What happens if you use setpci to clear the memory enable bit or 'echo 0 > enable' before binding the driver? Thanks, Alex > +} > + > static int nvgrace_gpu_probe(struct pci_dev *pdev, > const struct pci_device_id *id) > { > @@ -863,6 +914,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;