<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
p.msipheaderdf3d92d6, li.msipheaderdf3d92d6, div.msipheaderdf3d92d6
{mso-style-name:msipheaderdf3d92d6;
mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="msipheaderdf3d92d6" style="margin:0in"><span style="font-size:10.0pt;font-family:"Arial",sans-serif;color:blue">[AMD Official Use Only - General]</span><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">This seems to have broken CRIU restore. After I revert this, I can get CRIU restore working.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> amd-gfx <amd-gfx-bounces@lists.freedesktop.org>
<b>On Behalf Of </b>Russell, Kent<br>
<b>Sent:</b> Tuesday, August 23, 2022 8:07 AM<br>
<b>To:</b> Kuehling, Felix <Felix.Kuehling@amd.com>; amd-gfx@lists.freedesktop.org<br>
<b>Subject:</b> Re: [PATCH] drm/amdkfd: Allocate doorbells only when needed<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">No one else seems to have any thoughts on it, so Reviewed-by: Kent Russell <<a href="mailto:kent.Russell@amd.com">kent.Russell@amd.com</a>><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"> Kent<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div class="MsoNormal" align="center" style="text-align:center">
<hr size="1" width="98%" align="center">
</div>
<div id="divRplyFwdMsg">
<p class="MsoNormal"><b><span style="color:black">From:</span></b><span style="color:black"> amd-gfx <<a href="mailto:amd-gfx-bounces@lists.freedesktop.org">amd-gfx-bounces@lists.freedesktop.org</a>> on behalf of Russell, Kent <<a href="mailto:Kent.Russell@amd.com">Kent.Russell@amd.com</a>><br>
<b>Sent:</b> Monday, August 22, 2022 10:10 AM<br>
<b>To:</b> Kuehling, Felix <<a href="mailto:Felix.Kuehling@amd.com">Felix.Kuehling@amd.com</a>>;
<a href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a> <<a href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a>><br>
<b>Subject:</b> RE: [PATCH] drm/amdkfd: Allocate doorbells only when needed</span>
<o:p></o:p></p>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal">[AMD Official Use Only - General]<br>
<br>
I can throw an Acked-by: Kent Russell <<a href="mailto:kent.russell@amd.com">kent.russell@amd.com</a>> since we don't have an RB yet.<br>
<br>
Kent<br>
<br>
> -----Original Message-----<br>
> From: amd-gfx <<a href="mailto:amd-gfx-bounces@lists.freedesktop.org">amd-gfx-bounces@lists.freedesktop.org</a>> On Behalf Of Felix<br>
> Kuehling<br>
> Sent: Wednesday, August 3, 2022 2:56 PM<br>
> To: <a href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a><br>
> Subject: [PATCH] drm/amdkfd: Allocate doorbells only when needed<br>
> <br>
> Only allocate doorbells when the first queue is created on a GPU or the<br>
> doorbells need to be mapped into CPU or GPU virtual address space. This<br>
> avoids allocating doorbells unnecessarily and can allow more processes<br>
> to use KFD on multi-GPU systems.<br>
> <br>
> Signed-off-by: Felix Kuehling <<a href="mailto:Felix.Kuehling@amd.com">Felix.Kuehling@amd.com</a>><br>
> ---<br>
> drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 13 +++++++++++++<br>
> drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c | 9 +++++++++<br>
> drivers/gpu/drm/amd/amdkfd/kfd_process.c | 5 -----<br>
> 3 files changed, 22 insertions(+), 5 deletions(-)<br>
> <br>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c<br>
> b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c<br>
> index 2b3d8bc8f0aa..907f4711abce 100644<br>
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c<br>
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c<br>
> @@ -327,6 +327,12 @@ static int kfd_ioctl_create_queue(struct file *filep,<br>
> struct kfd_process *p,<br>
> goto err_bind_process;<br>
> }<br>
> <br>
> + if (!pdd->doorbell_index &&<br>
> + kfd_alloc_process_doorbells(dev, &pdd->doorbell_index) < 0) {<br>
> + err = -ENOMEM;<br>
> + goto err_alloc_doorbells;<br>
> + }<br>
> +<br>
> /* Starting with GFX11, wptr BOs must be mapped to GART for MES to<br>
> determine work<br>
> * on unmapped queues for usermode queue oversubscription (no<br>
> aggregated doorbell)<br>
> */<br>
> @@ -404,6 +410,7 @@ static int kfd_ioctl_create_queue(struct file *filep, struct<br>
> kfd_process *p,<br>
> if (wptr_bo)<br>
> amdgpu_amdkfd_free_gtt_mem(dev->adev, wptr_bo);<br>
> err_wptr_map_gart:<br>
> +err_alloc_doorbells:<br>
> err_bind_process:<br>
> err_pdd:<br>
> mutex_unlock(&p->mutex);<br>
> @@ -1092,6 +1099,10 @@ static int kfd_ioctl_alloc_memory_of_gpu(struct file<br>
> *filep,<br>
> goto err_unlock;<br>
> }<br>
> offset = kfd_get_process_doorbells(pdd);<br>
> + if (!offset) {<br>
> + err = -ENOMEM;<br>
> + goto err_unlock;<br>
> + }<br>
> } else if (flags & KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP) {<br>
> if (args->size != PAGE_SIZE) {<br>
> err = -EINVAL;<br>
> @@ -2173,6 +2184,8 @@ static int criu_restore_memory_of_gpu(struct<br>
> kfd_process_device *pdd,<br>
> return -EINVAL;<br>
> <br>
> offset = kfd_get_process_doorbells(pdd);<br>
> + if (!offset)<br>
> + return -ENOMEM;<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Looks like this is causing CRIU restore failure.<o:p></o:p></p>
<p class="MsoNormal"><br>
> } else if (bo_bucket->alloc_flags &<br>
> KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP) {<br>
> /* MMIO BOs need remapped bus address */<br>
> if (bo_bucket->size != PAGE_SIZE) {<br>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c<br>
> b/drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c<br>
> index cb3d2ccc5100..b33798f89ef0 100644<br>
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c<br>
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c<br>
> @@ -157,6 +157,8 @@ int kfd_doorbell_mmap(struct kfd_dev *dev, struct<br>
> kfd_process *process,<br>
> <br>
> /* Calculate physical address of doorbell */<br>
> address = kfd_get_process_doorbells(pdd);<br>
> + if (!address)<br>
> + return -ENOMEM;<br>
> vma->vm_flags |= VM_IO | VM_DONTCOPY | VM_DONTEXPAND |<br>
> VM_NORESERVE |<br>
> VM_DONTDUMP | VM_PFNMAP;<br>
> <br>
> @@ -275,6 +277,13 @@ uint64_t kfd_get_number_elems(struct kfd_dev *kfd)<br>
> <br>
> phys_addr_t kfd_get_process_doorbells(struct kfd_process_device *pdd)<br>
> {<br>
> + if (!pdd->doorbell_index) {<br>
> + int r = kfd_alloc_process_doorbells(pdd->dev,<br>
> + &pdd->doorbell_index);<br>
> + if (r)<br>
> + return 0;<br>
> + }<br>
> +<br>
> return pdd->dev->doorbell_base +<br>
> pdd->doorbell_index * kfd_doorbell_process_slice(pdd->dev);<br>
> }<br>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c<br>
> b/drivers/gpu/drm/amd/amdkfd/kfd_process.c<br>
> index 6c83a519b3a1..951b63677248 100644<br>
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c<br>
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c<br>
> @@ -1499,11 +1499,6 @@ struct kfd_process_device<br>
> *kfd_create_process_device_data(struct kfd_dev *dev,<br>
> if (!pdd)<br>
> return NULL;<br>
> <br>
> - if (kfd_alloc_process_doorbells(dev, &pdd->doorbell_index) < 0) {<br>
> - pr_err("Failed to alloc doorbell for pdd\n");<br>
> - goto err_free_pdd;<br>
> - }<br>
> -<br>
> if (init_doorbell_bitmap(&pdd->qpd, dev)) {<br>
> pr_err("Failed to init doorbell for process\n");<br>
> goto err_free_pdd;<br>
> --<br>
> 2.32.0<o:p></o:p></p>
</div>
</div>
</div>
</body>
</html>