<html 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=Windows-1252">
<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:DengXian;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"\@DengXian";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:10.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.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>
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt">> On Fri, Jul 29, 2022 at 09:38:35 +0200, Michal Prívozník wrote:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > On 7/28/22 14:41, Peter Krempa wrote:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > > On Wed, Jul 27, 2022 at 12:34:57 +0200, Michal Privoznik wrote:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >> From: Lin Yang <lin.a.yang@intel.com><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">> > >> With NUMA config:<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">> > >> <devices><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">> > >>   <memory model='sgx-epc'><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >>     <source><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >>       <nodemask>0-1</nodemask><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >>     </source><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >>     <target><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >>       <size unit='KiB'>512</size><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >>       <node>0</node><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >>     </target><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >>   </memory><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">> > >> </devices><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">> > >> Without NUMA config:<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">> > >> <devices><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">> > >>   <memory model='sgx-epc'><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >>     <target><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >>       <size unit='KiB'>512</size><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >>     </target><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >>   </memory><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">> > >> </devices><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: Lin Yang <lin.a.yang@intel.com><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >> Signed-off-by: Michal Privoznik <mprivozn@redhat.com><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">> > > <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >> diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >> index 1ed969ac3e..bdd0fcea8e 100644<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >> --- a/docs/formatdomain.rst<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >> +++ b/docs/formatdomain.rst<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >> @@ -7940,6 +7940,20 @@ Example: usage of the memory devices<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >>           <current unit='KiB'>524288</current><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >>         </target><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >>       </memory><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >> +     <memory model='sgx-epc'><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >> +       <source><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >> +         <nodemask>0-1</nodemask><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >> +       </source><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >> +       <target><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >> +         <size unit='KiB'>16384</size><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >> +         <node>0</node><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >> +       </target><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >> +     </memory><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >> +     <memory model='sgx-epc'><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >> +       <target><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >> +         <size unit='KiB'>16384</size><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >> +       </target><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >> +     </memory><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >>     </devices><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">> > >> @@ -7948,7 +7962,9 @@ Example: usage of the memory devices<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >>     1.2.14` Provide ``nvdimm`` model that adds a Non-Volatile DIMM module.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >>     :since:`Since 3.2.0` Provide ``virtio-pmem`` model to add a paravirtualized<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >>     persistent memory device. :since:`Since 7.1.0` Provide ``virtio-mem`` model<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >> -   to add paravirtualized memory device. :since:`Since 7.9.0`<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >> +   to add paravirtualized memory device. :since:`Since 7.9.0` Provide<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >> +   ``sgx-epc`` model to add a SGX enclave page cache (EPC) memory to the guest.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >> +   :since:`Since 8.7.0 and QEMU 6.2.0`<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">> > > I don't quite understand from this description whether this is real<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > > memory usable by the guest OS or something for internal use by the<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > > hypervisor.<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">> > > Specifically which leads me to questioning this is that the example<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > > sizes are very tiny compared to real memory sizing.<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">> > I admit that I don't know all the details and let somebody from Intel to<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > provide them. But basically, SGX works by reserving a chunk of RAM (on<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > each NUMA node) which is then encrypted and the processor controls<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > access to it. This chunk is referred to as Processor Reserved Memory and<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > to my understanding is the maximum size of an enclave. Thus I can<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > understand why new <memory/> model was used.<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">> Even this interpretation would not sit well with the semantics of the<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> <memory> element.<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">> > But I'm not sure how QEMU<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > accounts for this memory, whether say 16KiB worth of SGX is added to<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > whatever current guest has OR it's taken from an existing memory.<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">> Note that the name expands to "enclave page cache", so even the name<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> doesn't really seem to be hinting that the memory declared like this is<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> used by the guest OS.<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">> Preferrably the documentation added in this patch will clarify that,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> because if it is not clarified by the documentation, we will be getting<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> clarification requests and it's very apparent that we can't answer them<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> since neither of us actually knows what's going on.<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">> > > Additionally in qemuDomainDefValidateMemoryHotplug you are changing the<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > > code to specifically exclude the sizing of the 'sgx-epc' memory devices<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > > from the total size of the memory, but this contrasts with the memory<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > > _not_ being excluded from the initial memory calculation in<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > > virDomainDefGetMemoryInitial which is used to format the initial memory<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > > argument ('-m size=...'). Thus at least one of them is wrong.<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">> > > If this is not guest usable memory, then the <memory> element should not<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > > be used to bolt this on, but rather add a new element similarly to what<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > > we have when AMD SEV is in use.<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">> > Alright, I'm hold off reworking these patches per your review until we<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > are clear on this.<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">Basically sgx-epc memory created here is usable by guest OS. KVM SGX creates<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">One new misc device, and QEMU will open '/dev/sgx_vepc' device node to
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">mmap() host EPC memory to guest.<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">The sgx-epc memory is a separate memory range. Its size will not change the
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">guest OS size that is initialized by ‘-m size=…’. So it should be excluded from<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">calculation in virDomainDefGetMemoryInitial. Thanks for pointing this out.<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,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Lin.<o:p></o:p></span></p>
</div>
</body>
</html>