Add support for EGM memory device model with
'path' source attribute and 'pciDev' target
attribute to denote host EGM device backing path
and PCI device alias to associate the vEGM with,
respectively.

Signed-off-by: Nathan Chen <[email protected]>
---
 docs/formatdomain.rst             | 18 +++++++++++++++++-
 src/conf/domain_conf.c            | 29 +++++++++++++++++++++++++++++
 src/conf/domain_conf.h            |  7 +++++++
 src/conf/domain_postparse.c       |  1 +
 src/conf/domain_validate.c        | 15 +++++++++++++++
 src/conf/schemas/domaincommon.rng |  6 ++++++
 6 files changed, 75 insertions(+), 1 deletion(-)

diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst
index 1467fc7e10..56fa931747 100644
--- a/docs/formatdomain.rst
+++ b/docs/formatdomain.rst
@@ -9029,6 +9029,16 @@ Example: usage of the memory devices
          <size unit='KiB'>16384</size>
        </target>
      </memory>
+     <memory model='egm' access='shared'>
+       <source>
+         <path>/dev/egm0</path>
+       </source>
+       <target>
+         <size unit='KiB'>524288</size>
+         <node>0</node>
+         <pciDev>ua-hostdev0</pciDev>
+       </target>
+     </memory>
    </devices>
    ...
 
@@ -9040,7 +9050,8 @@ Example: usage of the memory devices
    persistent memory device. :since:`Since 7.1.0` Provide ``virtio-mem`` model
    to add paravirtualized memory device. :since:`Since 7.9.0` Provide
    ``sgx-epc`` model to add a SGX enclave page cache (EPC) memory to the guest.
-   :since:`Since 8.10.0 and QEMU 7.0.0`
+   :since:`Since 8.10.0 and QEMU 7.0.0` Provide ``egm`` model to add a EGM
+   (Extended GPU Memory) device.
 
 ``access``
    An optional attribute ``access`` ( :since:`since 3.2.0` ) that provides
@@ -9175,6 +9186,11 @@ Example: usage of the memory devices
      The physical address in memory, where device is mapped.
      :since:`Since 9.4.0`
 
+   ``pciDev``
+     For ``egm`` only.
+     The PCI device that is enabled to access the system memory via
+     association with the EGM device.
+
 
 IOMMU devices
 ~~~~~~~~~~~~~
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 541dad5bdc..2cda32fa6e 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1522,6 +1522,7 @@ VIR_ENUM_IMPL(virDomainMemoryModel,
               "virtio-pmem",
               "virtio-mem",
               "sgx-epc",
+              "egm",
 );
 
 VIR_ENUM_IMPL(virDomainShmemModel,
@@ -3611,6 +3612,9 @@ void virDomainMemoryDefFree(virDomainMemoryDef *def)
     case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC:
         virBitmapFree(def->source.sgx_epc.nodes);
         break;
+    case VIR_DOMAIN_MEMORY_MODEL_EGM:
+        g_free(def->source.egm.path);
+        g_free(def->target.egm.pciDev);
     case VIR_DOMAIN_MEMORY_MODEL_NONE:
     case VIR_DOMAIN_MEMORY_MODEL_LAST:
         break;
@@ -14084,6 +14088,10 @@ virDomainMemorySourceDefParseXML(xmlNodePtr node,
         }
         break;
 
+    case VIR_DOMAIN_MEMORY_MODEL_EGM:
+        def->source.egm.path = virXPathString("string(./path)", ctxt);
+        break;
+
     case VIR_DOMAIN_MEMORY_MODEL_NONE:
     case VIR_DOMAIN_MEMORY_MODEL_LAST:
         break;
@@ -14160,6 +14168,10 @@ virDomainMemoryTargetDefParseXML(xmlNodePtr node,
         addr = &def->target.virtio_pmem.address;
         break;
 
+    case VIR_DOMAIN_MEMORY_MODEL_EGM:
+        def->target.egm.pciDev = virXPathString("string(./pciDev)", ctxt);
+        break;
+
     case VIR_DOMAIN_MEMORY_MODEL_NONE:
     case VIR_DOMAIN_MEMORY_MODEL_DIMM:
     case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC:
@@ -14381,6 +14393,7 @@ virDomainMemoryIsVirtioModel(const virDomainMemoryDef 
*def)
     case VIR_DOMAIN_MEMORY_MODEL_DIMM:
     case VIR_DOMAIN_MEMORY_MODEL_NVDIMM:
     case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC:
+    case VIR_DOMAIN_MEMORY_MODEL_EGM:
     case VIR_DOMAIN_MEMORY_MODEL_LAST:
         break;
     }
@@ -16247,6 +16260,12 @@ virDomainMemoryFindByDefInternal(virDomainDef *def,
                 continue;
             break;
 
+        case VIR_DOMAIN_MEMORY_MODEL_EGM:
+            if (STRNEQ(tmp->source.egm.path, mem->source.egm.path))
+                continue;
+            if (STRNEQ(tmp->target.egm.pciDev, mem->target.egm.pciDev))
+                continue;
+
         case VIR_DOMAIN_MEMORY_MODEL_NONE:
         case VIR_DOMAIN_MEMORY_MODEL_LAST:
             break;
@@ -22196,6 +22215,7 @@ virDomainMemoryDefCheckABIStability(virDomainMemoryDef 
*src,
 
     case VIR_DOMAIN_MEMORY_MODEL_DIMM:
     case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC:
+    case VIR_DOMAIN_MEMORY_MODEL_EGM:
     case VIR_DOMAIN_MEMORY_MODEL_NONE:
     case VIR_DOMAIN_MEMORY_MODEL_LAST:
         break;
@@ -26700,6 +26720,10 @@ virDomainMemorySourceDefFormat(virBuffer *buf,
         }
         break;
 
+    case VIR_DOMAIN_MEMORY_MODEL_EGM:
+        virBufferEscapeString(&childBuf, "<path>%s</path>\n", 
def->source.egm.path);
+        break;
+
     case VIR_DOMAIN_MEMORY_MODEL_NONE:
     case VIR_DOMAIN_MEMORY_MODEL_LAST:
         break;
@@ -26762,6 +26786,11 @@ virDomainMemoryTargetDefFormat(virBuffer *buf,
         }
         break;
 
+    case VIR_DOMAIN_MEMORY_MODEL_EGM:
+        if (def->target.egm.pciDev)
+            virBufferAsprintf(&childBuf, "<pciDev>%s</pciDev>\n", 
def->target.egm.pciDev);
+        break;
+
     case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC:
     case VIR_DOMAIN_MEMORY_MODEL_DIMM:
     case VIR_DOMAIN_MEMORY_MODEL_NONE:
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index cb35ff06bd..e38f133bcc 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2745,6 +2745,7 @@ typedef enum {
     VIR_DOMAIN_MEMORY_MODEL_VIRTIO_PMEM, /* virtio-pmem memory device */
     VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM, /* virtio-mem memory device */
     VIR_DOMAIN_MEMORY_MODEL_SGX_EPC, /* SGX enclave page cache */
+    VIR_DOMAIN_MEMORY_MODEL_EGM, /* Extended GPU memory */
 
     VIR_DOMAIN_MEMORY_MODEL_LAST
 } virDomainMemoryModel;
@@ -2777,6 +2778,9 @@ struct _virDomainMemoryDef {
         struct {
             virBitmap *nodes; /* source NUMA nodes */
         } sgx_epc;
+        struct {
+            char *path;
+        } egm;
     } source;
 
     union {
@@ -2802,6 +2806,9 @@ struct _virDomainMemoryDef {
         } virtio_mem;
         struct {
         } sgx_epc;
+        struct {
+            char *pciDev;
+        } egm;
     } target;
 
     virDomainDeviceInfo info;
diff --git a/src/conf/domain_postparse.c b/src/conf/domain_postparse.c
index 38e731348d..0181d21f0e 100644
--- a/src/conf/domain_postparse.c
+++ b/src/conf/domain_postparse.c
@@ -632,6 +632,7 @@ virDomainMemoryDefPostParse(virDomainMemoryDef *mem,
     case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM:
     case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC:
     case VIR_DOMAIN_MEMORY_MODEL_DIMM:
+    case VIR_DOMAIN_MEMORY_MODEL_EGM:
     case VIR_DOMAIN_MEMORY_MODEL_NONE:
     case VIR_DOMAIN_MEMORY_MODEL_LAST:
         break;
diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c
index 4558e7b210..4d4febfbfc 100644
--- a/src/conf/domain_validate.c
+++ b/src/conf/domain_validate.c
@@ -2494,6 +2494,7 @@ virDomainMemoryDefCheckConflict(const virDomainMemoryDef 
*mem,
         }
         break;
     case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC:
+    case VIR_DOMAIN_MEMORY_MODEL_EGM:
     case VIR_DOMAIN_MEMORY_MODEL_NONE:
     case VIR_DOMAIN_MEMORY_MODEL_LAST:
         break;
@@ -2540,6 +2541,7 @@ virDomainMemoryDefCheckConflict(const virDomainMemoryDef 
*mem,
         switch (other->model) {
         case VIR_DOMAIN_MEMORY_MODEL_NONE:
         case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC:
+        case VIR_DOMAIN_MEMORY_MODEL_EGM:
         case VIR_DOMAIN_MEMORY_MODEL_LAST:
             continue;
             break;
@@ -2720,6 +2722,19 @@ virDomainMemoryDefValidate(const virDomainMemoryDef *mem,
         }
         break;
 
+    case VIR_DOMAIN_MEMORY_MODEL_EGM:
+        if (!mem->source.egm.path) {
+            virReportError(VIR_ERR_XML_DETAIL, "%s",
+                           _("path is required for model 'egm'"));
+            return -1;
+        }
+        if (!mem->target.egm.pciDev) {
+            virReportError(VIR_ERR_XML_DETAIL, "%s",
+                           _("pciDev is required for model 'egm'"));
+            return -1;
+        }
+        break;
+
     case VIR_DOMAIN_MEMORY_MODEL_NONE:
     case VIR_DOMAIN_MEMORY_MODEL_LAST:
     default:
diff --git a/src/conf/schemas/domaincommon.rng 
b/src/conf/schemas/domaincommon.rng
index 1f9ac102a0..4ccc594659 100644
--- a/src/conf/schemas/domaincommon.rng
+++ b/src/conf/schemas/domaincommon.rng
@@ -7486,6 +7486,7 @@
           <value>virtio-pmem</value>
           <value>virtio-mem</value>
           <value>sgx-epc</value>
+          <value>egm</value>
         </choice>
       </attribute>
       <optional>
@@ -7617,6 +7618,11 @@
             </attribute>
           </element>
         </optional>
+        <optional>
+          <element name="pciDev">
+            <data type="string"/>
+          </element>
+        </optional>
       </interleave>
     </element>
   </define>
-- 
2.43.0

Reply via email to