<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;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:10.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>
</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 11/8/22, 5:16 AM, "Peter Krempa" <pkrempa@redhat.com> wrote:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> On Tue, Nov 08, 2022 at 12:25:26 +0000, Daniel P. Berrangé wrote:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > On Fri, Oct 14, 2022 at 01:12:28PM +0200, Michal Prívozník wrote:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > > On 10/8/22 06:00, Lin Yang wrote:<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">> > > # ./qemu-system-x86_64 -S -nographic -nodefaults -m 128 \<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > > -machine pc,sgx-epc.0.memdev=memepc0,sgx-epc.0.node=0 \<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > > -object '{"qom-type":"memory-backend-epc","id":"memepc0","prealloc":true,"size":67108864,"host-nodes":[0],"policy":"bind"}' \<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > > -monitor stdio<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > > QEMU 7.1.50 monitor - type 'help' for more information<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > > (qemu) info memory-devices
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > > Memory device [sgx-epc]: ""<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >   memaddr: 0x100000000<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >   size: 67108864<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >   node: 0<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > >   memdev: /objects/memepc0<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > > (qemu) info memory_size_summary
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > > base memory: 134217728<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > > plugged memory: 0<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > > (qemu)<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'm not sure this check is showing us the truth.<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">> > In backends/hostmem-epc.c, sgx_epc_backend_memory_alloc is<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > opening /dev/sgx_vepc and mmap()ing the requested size from<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > that file. IOW that's clearly in addition to whatever has<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > been mapped as the main RAM.<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">> > In hw/i386/sgx-epc.c, sgx_epc_md_get_plugged_size is  hardcoded<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > to always return 0, which is why 'plugged memory' is reported<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > as zero above. I don't know what it is reporting zero.<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 this because the SGX RAM is not accessible to the guest OS<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > as "normal" RAM perhaps, and thus to be reported differently.<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">> So even if the memory is not accessible as normal RAM, but still is<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> usable by the guest OS, the use of an <devices><memory> element is okay,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> but the total memory size of a VM should account for 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">> So in fact all the hacks which exclude it from the total memory size<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> should be removed.<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">QEMU reports zero 'plugged memory' for SGX RAM because it will not<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">add more normal RAM to guest OS and it cannot be hotplug/unplug on<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">the fly, since it is realized through CPUID and has to be initialized before<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">vcpu.<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">One the host, BIOS reserves part of RAM as SGX RAM, which cannot be<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">directly accessed by other application or kernel. The host OS only
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">see RAM size = physical memory size – SGX RAM.<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">Does “total memory size” here means all memory device size, like all<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">physical memory size on host, not normal RAM size? If not, it might
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">give confusing info to user since guset OS shows a different normal RAM<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">size.<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">Really appreciated all your reviewing.<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">Regards,<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>