<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)">
<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:0cm;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
span.EmailStyle18
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
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-GB" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D;mso-fareast-language:EN-US">What happens when the Nvidia GPU driver kernel callback occurs to invalidate the pinned GPU memory region?  Doesn’t the NIC need to cease all DMA transfers to/from
 that region before the kernel callback can complete?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:11.0pt">From:</span></b><span lang="EN-US" style="font-size:11.0pt"> Elena Agostini <eagostini@nvidia.com>
<br>
<b>Sent:</b> 04 January 2022 13:55<br>
<b>To:</b> NBU-Contact-Thomas Monjalon (EXTERNAL) <thomas@monjalon.net><br>
<b>Cc:</b> dev@dpdk.org<br>
<b>Subject:</b> Re: [PATCH v2] gpudev: pin GPU memory<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:solid #9C6500 1.0pt;padding:2.0pt 2.0pt 2.0pt 2.0pt">
<p class="MsoNormal" style="line-height:12.0pt;background:#FFEB9C"><b><span style="color:#9C6500">CAUTION:</span></b><span style="color:black"> This email originated from outside of the organization. Do not click links or open attachments unless you recognize
 the sender and know the content is safe.<o:p></o:p></span></p>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">> 04/01/2022 03:41, <a href="mailto:eagostini@nvidia.com">
eagostini@nvidia.com</a>:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > From: Elena Agostini <<a href="mailto:eagostini@nvidia.com">eagostini@nvidia.com</a>><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> ><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > Enable the possibility to make a GPU memory area accessible from<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > the CPU.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> ><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > GPU memory has to be allocated via rte_gpu_mem_alloc().<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> ><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > This patch allows the gpudev library to pin, through the GPU driver,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > a chunk of GPU memory and to return a memory pointer usable<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > by the CPU to access the GPU memory area.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> ><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > Signed-off-by: Elena Agostini <<a href="mailto:eagostini@nvidia.com">eagostini@nvidia.com</a>><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> [...]<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > +/**<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > + * @warning<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > + * @b EXPERIMENTAL: this API may change without prior notice.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > + *<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > + * Pin a chunk of GPU memory to make it accessible from the CPU<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> You should define what means "pin" exactly.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> Which properties should we expect?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Thanks for reviewing, this is the kind of discussion I wanted to have.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Maybe "pin" is too GDRCopy specific oriented.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Here I want to make a GPU memory buffer visible from the CPU. In case<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">of NVIDIA, this means the GPU memory address has to be pinned (virtual address<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">doesn't change) and dma-mapped.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Maybe the name should be more like rte_gpu_mem_to_cpu() that's more<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">explicative and generic.<span style="color:#1F497D"><o:p></o:p></span></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > + * using the memory pointer returned by the function.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> Which function should return the pointer?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> rte_gpu_mem_pin is returning an int.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Oversight, will fix it.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > + * GPU memory has to be allocated via rte_gpu_mem_alloc().<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> Why pinning is not done by rte_gpu_mem_alloc()?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> Should it be a flag?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">rte_gpu_mem_alloc() allocate virtual memory on the GPU that doesn't have<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">to be necessarily shared (pinned) to make it visible from CPU.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > + *<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > + * @param dev_id<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > + *   Device ID requiring pinned memory.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > + * @param size<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > + *   Number of bytes to pin.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > + *   Requesting 0 will do nothing.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > + * @param ptr<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > + *   Pointer to the GPU memory area to be pinned.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > + *   NULL is a no-op accepted value.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > +<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > + * @return<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > + *   A pointer to the pinned GPU memory usable by the CPU, otherwise NULL and rte_errno is set:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > + *   - ENODEV if invalid dev_id<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > + *   - EINVAL if reserved flags<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> Which reserved flags?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > + *   - ENOTSUP if operation not supported by the driver<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > + *   - E2BIG if size is higher than limit<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > + *   - ENOMEM if out of space<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> Is out of space relevant for pinning?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Yes, let me add it<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > + *   - EPERM if driver error<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > + */<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > +__rte_experimental<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > +int rte_gpu_mem_pin(int16_t dev_id, size_t size, void *ptr);<o:p></o:p></span></p>
</div>
</div>
</div>
</div>
</body>
</html>