<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hello Hao,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Thanks for the clarification. I have made the changes and submitted a new patch. Also, in case the IOMMU PPI does not exist, we are now allocating the memory and adjust return pointers to be aligned. There is no freeing of unaligned pages here as PEI framework
 does not provide a mechanism for that.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Thanks</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Ashish</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Wu, Hao A <hao.a.wu@intel.com><br>
<b>Sent:</b> Monday, October 14, 2019 7:21 PM<br>
<b>To:</b> Ashish Singhal <ashishsingha@nvidia.com>; devel@edk2.groups.io <devel@edk2.groups.io>; Ni, Ray <ray.ni@intel.com><br>
<b>Subject:</b> RE: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Fix Aligned Page Allocation</font>
<div> </div>
</div>
<style>
<!--
@font-face
        {font-family:SimSun}
@font-face
        {font-family:SimSun}
@font-face
        {font-family:Calibri}
@font-face
        {font-family:Tahoma}
p.x_MsoNormal, li.x_MsoNormal, div.x_MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif"}
a:link, span.x_MsoHyperlink
        {color:blue;
        text-decoration:underline}
a:visited, span.x_MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline}
p
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif"}
p.x_xxmsonormal, li.x_xxmsonormal, div.x_xxmsonormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif"}
p.x_xxmsonormal0, li.x_xxmsonormal0, div.x_xxmsonormal0
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif"}
p.x_xxmsochpdefault, li.x_xxmsochpdefault, div.x_xxmsochpdefault
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Times New Roman","serif"}
span.x_xxmsohyperlink
        {color:blue;
        text-decoration:underline}
span.x_xxmsohyperlinkfollowed
        {color:purple;
        text-decoration:underline}
span.x_xxemailstyle18
        {font-family:"Calibri","sans-serif";
        color:#1F497D}
span.x_xxemailstyle19
        {font-family:"Calibri","sans-serif";
        color:windowtext}
span.x_xxemailstyle21
        {font-family:"Calibri","sans-serif";
        color:#1F497D}
span.x_xxspelle
        {}
span.x_EmailStyle27
        {font-family:"Calibri","sans-serif";
        color:#1F497D}
span.x_SpellE
        {}
.x_MsoChpDefault
        {font-size:10.0pt}
@page WordSection1
        {margin:1.0in 1.0in 1.0in 1.0in}
div.x_WordSection1
        {}
-->
</style>
<div lang="EN-US" link="blue" vlink="purple" style="">
<div class="x_WordSection1">
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">Hello,</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">Sorry for the delayed response.</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">For the PEI changes, I found that when using the function
<span class="x_SpellE">IoMmuFreeBuffer</span>() to</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">free the first/last unaligned page(s), the below operations related to 'Mapping':</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">>|<span style=""> 
</span>Status = <span class="x_SpellE">mIoMmu</span>-><span class="x_SpellE">SetAttribute</span> (<span class="x_SpellE">mIoMmu</span>, Mapping, 0);</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">>|<span style=""> 
</span>Status = <span class="x_SpellE">mIoMmu</span>-><span class="x_SpellE">Unmap</span> (<span class="x_SpellE">mIoMmu</span>, Mapping);</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">will be done multiple times. I think they should only be done once and should</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">happen when freeing the aligned buffer.</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">Hence, I would suggest to add a new helper function called</span></p>
<p class="x_MsoNormal"><span class="x_SpellE"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">IoMmuAllocateAlignedBuffer</span></span><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">(), which
 will be similar to the existing</span></p>
<p class="x_MsoNormal"><span class="x_SpellE"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">IoMmuAllocateBuffer</span></span><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">() but with a
 couple of additional things to handle:</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">1. If the IOMMU PPI exists:</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">a. Allocate the buffer according to the real number of pages needed;</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">b. (New) Free the first & last unaligned pages;</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">c. Map the allocated aligned buffer;</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">d. Set the IOMMU attribute for the buffer.</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">2. If the IOMMU PPI does not exist:</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">a. Allocate the buffer according to the real number of pages needed;</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">b. (New) Free the first & last unaligned pages.</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D"> </span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">Also, could you help to separate the change for
<span class="x_SpellE">XhciPei</span> into a separate patch?</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">It will be helpful to locate the exact commit made to
<span class="x_SpellE">XhciPei</span> and <span class="x_SpellE">XhciDxe</span> in</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">the future.</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D"> </span></p>
<div>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">Best Regards,</span></p>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">Hao Wu</span></p>
</div>
<p class="x_MsoNormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D"> </span></p>
<div style="border:none; border-left:solid blue 1.5pt; padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none; border-top:solid #B5C4DF 1.0pt; padding:3.0pt 0in 0in 0in">
<p class="x_MsoNormal"><b><span style="font-size:10.0pt; font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt; font-family:"Tahoma","sans-serif""> Ashish Singhal [mailto:ashishsingha@nvidia.com]
<br>
<b>Sent:</b> Tuesday, October 15, 2019 2:17 AM<br>
<b>To:</b> Wu, Hao A; devel@edk2.groups.io; Ni, Ray<br>
<b>Subject:</b> Re: [edk2-devel] [PATCH] MdeModulePkg/<span class="x_SpellE">XhciDxe</span>: Fix Aligned Page Allocation</span></p>
</div>
</div>
<p class="x_MsoNormal"> </p>
<div>
<p class="x_MsoNormal"><span style="font-family:"Calibri","sans-serif"; color:black">Hello Hao,</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-family:"Calibri","sans-serif"; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-family:"Calibri","sans-serif"; color:black">Were you able to validate the PEI change I sent last week?</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-family:"Calibri","sans-serif"; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-family:"Calibri","sans-serif"; color:black">Thanks</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-family:"Calibri","sans-serif"; color:black">Ashish</span></p>
</div>
<div class="x_MsoNormal" align="center" style="text-align:center"><span style="">
<hr size="2" width="98%" align="center">
</span></div>
<div id="x_divRplyFwdMsg">
<p class="x_MsoNormal"><b><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:black">From:</span></b><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:black"> Ashish Singhal <ashishsingha@nvidia.com><br>
<b>Sent:</b> Friday, October 11, 2019 12:07 PM<br>
<b>To:</b> Wu, Hao A <hao.a.wu@intel.com>; devel@edk2.groups.io <devel@edk2.groups.io>; Ni, Ray <ray.ni@intel.com><br>
<b>Subject:</b> Re: [edk2-devel] [PATCH] MdeModulePkg/<span class="x_SpellE">XhciDxe</span>: Fix Aligned Page Allocation</span><span style="">
</span></p>
<div>
<p class="x_MsoNormal"><span style=""> </span></p>
</div>
</div>
<div>
<div>
<p class="x_MsoNormal"><span style="font-family:"Calibri","sans-serif"; color:black">Patch set 2 has been submitted for review.</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-family:"Calibri","sans-serif"; color:black"> </span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-family:"Calibri","sans-serif"; color:black">Thanks</span></p>
</div>
<div>
<p class="x_MsoNormal"><span style="font-family:"Calibri","sans-serif"; color:black">Ashish</span></p>
</div>
<div class="x_MsoNormal" align="center" style="text-align:center"><span style="">
<hr size="2" width="98%" align="center">
</span></div>
<div id="x_x_divRplyFwdMsg">
<p class="x_MsoNormal"><b><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:black">From:</span></b><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:black"> Wu, Hao A <hao.a.wu@intel.com><br>
<b>Sent:</b> Thursday, October 10, 2019 11:53 PM<br>
<b>To:</b> devel@edk2.groups.io <devel@edk2.groups.io>; Ashish Singhal <ashishsingha@nvidia.com>; Ni, Ray <ray.ni@intel.com><br>
<b>Subject:</b> RE: [edk2-devel] [PATCH] MdeModulePkg/<span class="x_SpellE">XhciDxe</span>: Fix Aligned Page Allocation</span><span style="">
</span></p>
<div>
<p class="x_MsoNormal"><span style=""> </span></p>
</div>
</div>
<div>
<div>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">Hello Ashish,</span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D"> </span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">I think the IOMMU feature is added for the protection of FW integrity against</span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">HW devices, which is the motivation to use IOMMU PPI for memory allocation.</span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D"> </span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">The fix is easy for the DXE part since the IOMMU part has been integrated to the</span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">implementation of the
<span class="x_SpellE"><span class="x_xxspelle">PciIo</span></span> protocol.</span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D"> </span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">As for the
<span class="x_SpellE"><span class="x_xxspelle">XhciPei</span></span> case, my thought is that a new helper function (maybe called
</span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">'<span class="x_SpellE"><span class="x_xxspelle">IoMmuAllocateAlignedBuffer</span></span>') can be added in
<span class="x_SpellE"><span class="x_xxspelle">DmaMem.c</span></span> file. The main
<span class="x_SpellE"><span class="x_xxspelle">differece</span></span></span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">between
<span class="x_SpellE"><span class="x_xxspelle">IoMmuAllocateAlignedBuffer</span></span>() and existing
<span class="x_SpellE"><span class="x_xxspelle">IoMmuAllocateBuffer</span></span>() will be:</span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D"> </span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">1. If IOMMU PPI exists,
<span class="x_SpellE"><span class="x_xxspelle">mIoMmu</span></span>-><span class="x_SpellE"><span class="x_xxspelle">AllocateBuffer</span></span>() should be called with bigger</span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">number of pages for alignment and
<span class="x_SpellE"><span class="x_xxspelle">mIoMmu</span></span>-><span class="x_SpellE"><span class="x_xxspelle">FreeBuffer</span></span>() can be called right after</span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">to free the unused pages.</span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D"> </span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">2. If IOMMU PPI does not exist, this case will fall back to a similar fix for</span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">the DXE case.</span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D"> </span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">Ideally,
<span class="x_SpellE"><span class="x_xxspelle">IoMmuFreeBuffer</span></span>() can be reused to free the aligned buffer.</span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">Please help to raise if you observe any open for the above proposal, thanks.</span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D"> </span></p>
<div>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">Best Regards,</span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">Hao Wu</span></p>
</div>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D"> </span></p>
<div>
<div style="border:none; border-top:solid #B5C4DF 1.0pt; padding:3.0pt 0in 0in 0in">
<p class="x_xxmsonormal"><b><span style="font-size:10.0pt; font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt; font-family:"Tahoma","sans-serif""> devel@edk2.groups.io [mailto:devel@edk2.groups.io]
<b>On Behalf Of </b>Ashish Singhal<br>
<b>Sent:</b> Friday, October 11, 2019 11:30 AM<br>
<b>To:</b> Wu, Hao A; devel@edk2.groups.io; Ni, Ray<br>
<b>Subject:</b> Re: [edk2-devel] [PATCH] MdeModulePkg/<span class="x_SpellE"><span class="x_xxspelle">XhciDxe</span></span>: Fix Aligned Page Allocation</span></p>
</div>
</div>
<p class="x_xxmsonormal"> </p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"">Hello Hao,</span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif""> </span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"">What is your motivation towards using
<span class="x_SpellE"><span class="x_xxspelle">IoMMUPei</span></span> for memory allocation now instead of Pei Services? The fix would be simple if we just change the number of pages needed to accommodate for the alignment. The call to free the pages would
 not do anything.</span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif""> </span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"">If we use
<span class="x_SpellE"><span class="x_xxspelle">IoMMUPei</span></span>, we may need to change function definition for allocate to return how many pages were allocated for each call so that freeing can be done correctly as well. This may need more refactoring
 of the code that initially thought of.</span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif""> </span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"">Thanks</span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"">Ashish</span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif""> </span></p>
<div>
<div style="border:none; border-top:solid #E1E1E1 1.0pt; padding:3.0pt 0in 0in 0in">
<p class="x_xxmsonormal"><b><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"">From:</span></b><span style="font-size:11.0pt; font-family:"Calibri","sans-serif""> Wu, Hao A <hao.a.wu@intel.com>
<br>
<b>Sent:</b> Thursday, October 10, 2019 9:00 PM<br>
<b>To:</b> devel@edk2.groups.io; Ashish Singhal <ashishsingha@nvidia.com>; Ni, Ray <ray.ni@intel.com><br>
<b>Subject:</b> RE: [edk2-devel] [PATCH] MdeModulePkg/<span class="x_SpellE"><span class="x_xxspelle">XhciDxe</span></span>: Fix Aligned Page Allocation</span></p>
</div>
</div>
<p class="x_xxmsonormal"> </p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">Thanks Ashish,</span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D"> </span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">Please help to send out the fix for
<span class="x_SpellE"><span class="x_xxspelle">XhciPei</span></span> in a separate patch as well.</span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">I can help to see if verification can be done on my side.</span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D"> </span></p>
<div>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">Best Regards,</span></p>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D">Hao Wu</span></p>
</div>
<p class="x_xxmsonormal"><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:#1F497D"> </span></p>
<div>
<div style="border:none; border-top:solid #B5C4DF 1.0pt; padding:3.0pt 0in 0in 0in">
<p class="x_xxmsonormal"><b><span style="font-size:10.0pt; font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt; font-family:"Tahoma","sans-serif"">
<a href="mailto:devel@edk2.groups.io">devel@edk2.groups.io</a> [<a href="mailto:devel@edk2.groups.io">mailto:devel@edk2.groups.io</a>]
<b>On Behalf Of </b>Ashish Singhal<br>
<b>Sent:</b> Friday, October 11, 2019 1:51 AM<br>
<b>To:</b> Wu, Hao A; <a href="mailto:devel@edk2.groups.io">devel@edk2.groups.io</a>; Ni, Ray<br>
<b>Subject:</b> Re: [edk2-devel] [PATCH] MdeModulePkg/<span class="x_SpellE"><span class="x_xxspelle">XhciDxe</span></span>: Fix Aligned Page Allocation</span></p>
</div>
</div>
<p class="x_xxmsonormal"> </p>
<div>
<p class="x_xxmsonormal"><span style="font-family:"Calibri","sans-serif"; color:black">Hello Hao,</span></p>
</div>
<div>
<p class="x_xxmsonormal"><span style="font-family:"Calibri","sans-serif"; color:black"> </span></p>
</div>
<div>
<p class="x_xxmsonormal"><span style="font-family:"Calibri","sans-serif"; color:black">I agree that for completeness we should fix the issue in both DXE as well as PEI but on my target, we do not have any PEI phase for me to be able to verify any change that
 I will be making. If you still want, I can still make the change so that someone else can verify or we can have someone else fix PEI and push my change meanwhile to fix the issue in DXE.</span></p>
</div>
<div>
<p class="x_xxmsonormal"><span style="font-family:"Calibri","sans-serif"; color:black"> </span></p>
</div>
<div>
<p class="x_xxmsonormal"><span style="font-family:"Calibri","sans-serif"; color:black">Thanks</span></p>
</div>
<div>
<p class="x_xxmsonormal"><span style="font-family:"Calibri","sans-serif"; color:black">Ashish</span></p>
</div>
<div class="x_MsoNormal" align="center" style="text-align:center"><span style="">
<hr size="1" width="98%" align="center">
</span></div>
<div id="x_x_x_divRplyFwdMsg">
<p class="x_xxmsonormal"><b><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:black">From:</span></b><span style="font-size:11.0pt; font-family:"Calibri","sans-serif"; color:black"> Wu, Hao A <<a href="mailto:hao.a.wu@intel.com">hao.a.wu@intel.com</a>><br>
<b>Sent:</b> Wednesday, October 9, 2019 8:09 PM<br>
<b>To:</b> Ashish Singhal <<a href="mailto:ashishsingha@nvidia.com">ashishsingha@nvidia.com</a>>;
<a href="mailto:devel@edk2.groups.io">devel@edk2.groups.io</a> <<a href="mailto:devel@edk2.groups.io">devel@edk2.groups.io</a>>; Ni, Ray <<a href="mailto:ray.ni@intel.com">ray.ni@intel.com</a>><br>
<b>Subject:</b> RE: [PATCH] MdeModulePkg/<span class="x_SpellE"><span class="x_xxspelle">XhciDxe</span></span>: Fix Aligned Page Allocation</span>
</p>
<div>
<p class="x_xxmsonormal"> </p>
</div>
</div>
<div>
<div>
<p class="x_xxmsonormal"><span style="font-size:11.0pt">> -----Original Message-----<br>
> From: Ashish Singhal [<a href="mailto:ashishsingha@nvidia.com">mailto:ashishsingha@nvidia.com</a>]<br>
> Sent: Thursday, October 10, 2019 9:58 AM<br>
> To: Wu, Hao A; <a href="mailto:devel@edk2.groups.io">devel@edk2.groups.io</a>; Ni, Ray<br>
> Subject: RE: [PATCH] MdeModulePkg/<span class="x_SpellE"><span class="x_xxspelle">XhciDxe</span></span>: Fix Aligned Page Allocation<br>
> <br>
> Hello Hao,<br>
> <br>
> I can see that the PEI also has the same issue and take a look at that as well<br>
> but I have no way to verify that as we are not using it. For the change I have<br>
> made in DXE, I have verified it with an alignment of 4K and 64K.<br>
<br>
<br>
Is it possible for you to verify the PEI case with a test PEI module that<br>
performs read operation to a USB storage device? I think this will trigger<br>
the affecting codes.<br>
<br>
In my opinion, it would be better for the fix to be complete.<br>
<br>
Best Regards,<br>
Hao Wu<br>
<br>
<br>
> <br>
> Thanks<br>
> Ashish<br>
> <br>
> -----Original Message-----<br>
> From: Wu, Hao A <<a href="mailto:hao.a.wu@intel.com">hao.a.wu@intel.com</a>><br>
> Sent: Wednesday, October 9, 2019 7:33 PM<br>
> To: Ashish Singhal <<a href="mailto:ashishsingha@nvidia.com">ashishsingha@nvidia.com</a>>;
<a href="mailto:devel@edk2.groups.io">devel@edk2.groups.io</a>; Ni,<br>
> Ray <<a href="mailto:ray.ni@intel.com">ray.ni@intel.com</a>><br>
> Subject: RE: [PATCH] MdeModulePkg/<span class="x_SpellE"><span class="x_xxspelle">XhciDxe</span></span>: Fix Aligned Page Allocation<br>
> <br>
> > -----Original Message-----<br>
> > From: Ashish Singhal [<a href="mailto:ashishsingha@nvidia.com">mailto:ashishsingha@nvidia.com</a>]<br>
> > Sent: Thursday, October 10, 2019 1:02 AM<br>
> > To: <a href="mailto:devel@edk2.groups.io">devel@edk2.groups.io</a>; Wu, Hao A; Ni, Ray<br>
> > Cc: Ashish Singhal<br>
> > Subject: [PATCH] MdeModulePkg/<span class="x_SpellE"><span class="x_xxspelle">XhciDxe</span></span>: Fix Aligned Page Allocation<br>
> ><br>
> > While allocating pages aligned at an alignment higher than 4K,<br>
> > allocate memory taking into consideration the padding required for<br>
> > that alignment. The calls to free pages takes care of this already.<br>
> ><br>
> > Signed-off-by: Ashish Singhal <<a href="mailto:ashishsingha@nvidia.com">ashishsingha@nvidia.com</a>><br>
> > ---<br>
> >  MdeModulePkg/Bus/<span class="x_SpellE"><span class="x_xxspelle">Pci</span></span>/<span class="x_SpellE"><span class="x_xxspelle">XhciDxe</span></span>/<span class="x_SpellE"><span class="x_xxspelle">UsbHcMem.c</span></span> | 2 +-<br>
> >  1 file changed, 1 insertion(+), 1 deletion(-)<br>
> ><br>
> > diff --<span class="x_SpellE"><span class="x_xxspelle">git</span></span> a/MdeModulePkg/Bus/<span class="x_SpellE"><span class="x_xxspelle">Pci</span></span>/<span class="x_SpellE"><span class="x_xxspelle">XhciDxe</span></span>/<span class="x_SpellE"><span class="x_xxspelle">UsbHcMem.c</span></span><br>
> > b/MdeModulePkg/Bus/<span class="x_SpellE"><span class="x_xxspelle">Pci</span></span>/<span class="x_SpellE"><span class="x_xxspelle">XhciDxe</span></span>/<span class="x_SpellE"><span class="x_xxspelle">UsbHcMem.c</span></span><br>
> > index fd79988..aa69c47 100644<br>
> > --- a/MdeModulePkg/Bus/<span class="x_SpellE"><span class="x_xxspelle">Pci</span></span>/<span class="x_SpellE"><span class="x_xxspelle">XhciDxe</span></span>/<span class="x_SpellE"><span class="x_xxspelle">UsbHcMem.c</span></span><br>
> > +++ b/MdeModulePkg/Bus/<span class="x_SpellE"><span class="x_xxspelle">Pci</span></span>/<span class="x_SpellE"><span class="x_xxspelle">XhciDxe</span></span>/<span class="x_SpellE"><span class="x_xxspelle">UsbHcMem.c</span></span><br>
> > @@ -656,7 +656,7 @@ <span class="x_SpellE"><span class="x_xxspelle">UsbHcAllocateAlignedPages</span></span> (<br>
> >                        <span class="x_SpellE"><span class="x_xxspelle">PciIo</span></span>,<br>
> >                        <span class="x_SpellE"><span class="x_xxspelle">AllocateAnyPages</span></span>,<br>
> >                        <span class="x_SpellE"><span class="x_xxspelle">EfiBootServicesData</span></span>,<br>
> > -                      Pages,<br>
> > +                      <span class="x_SpellE"><span class="x_xxspelle">RealPages</span></span>,<br>
> >                        &Memory,<br>
> >                        0<br>
> >                        );<br>
> <br>
> <br>
> Hello,<br>
> <br>
> The change looks good to me.<br>
> <br>
> Just a couple of things to confirm:<br>
> <br>
> 1. I think there is a similar case within the <span class="x_SpellE"><span class="x_xxspelle">XhciPei</span></span> driver Could you help to<br>
> resolve it as well?<br>
> <br>
> I think for the PEI counterpart you may need to update both<br>
> <span class="x_SpellE"><span class="x_xxspelle">UsbHcAllocateAlignedPages</span></span>() and
<span class="x_SpellE"><span class="x_xxspelle">UsbHcFreeAlignedPages</span></span>(), since the<br>
> IOMMU helper functions like <span class="x_SpellE"><span class="x_xxspelle">IoMmuAllocateBuffer</span></span>() and
<span class="x_SpellE"><span class="x_xxspelle">IoMmuFreeBuffer</span></span>()<br>
> might not be suitable now. Instead, I think services in the <span class="x_SpellE">
<span class="x_xxspelle">IoMmu</span></span> PPI can be<br>
> used.<br>
> <br>
> 2. Could you help to provide the information on what test has been done for<br>
> the proposed patch?<br>
> <br>
> Thanks in advance.<br>
> <br>
> Best Regards,<br>
> Hao Wu<br>
> <br>
> <br>
> > --<br>
> > 2.7.4<br>
> <br>
> -----------------------------------------------------------------------------------<br>
> This email message is for the sole use of the intended recipient(s) and may<br>
> contain<br>
> confidential information.  Any unauthorized review, use, disclosure or<br>
> distribution<br>
> is prohibited.  If you are not the intended recipient, please contact the<br>
> sender by<br>
> reply email and destroy all copies of the original message.<br>
> -----------------------------------------------------------------------------------</span></p>
</div>
</div>
<div>
<p class="x_xxmsonormal"></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

<div width="1" style="color:white;clear:both">_._,_._,_</div>
<hr>
Groups.io Links:<p>

You receive all messages sent to this group.


<p>

<a target="_blank" href="https://edk2.groups.io/g/devel/message/49020">View/Reply Online (#49020)</a> |


  


|


  
    <a target="_blank" href="https://groups.io/mt/34465466/1813853">Mute This Topic</a>
  

| <a href="https://edk2.groups.io/g/devel/post">New Topic</a><br>



<br>

<a href="https://edk2.groups.io/g/devel/editsub/1813853">Your Subscription</a> |
<a href="mailto:devel+owner@edk2.groups.io">Contact Group Owner</a> |

<a href="https://edk2.groups.io/g/devel/unsub">Unsubscribe</a>

 [edk2-devel-archive@redhat.com]<br>
<div width="1" style="color:white;clear:both">_._,_._,_</div>