[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH v5 4/8] mm: introduce a helper to get the memory type of a page



The type is only returned if the full page has the same type. This
function is unimplemented for ARM.

Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>
Cc: Julien Grall <julien.grall@xxxxxxx>
Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
Cc: George Dunlap <George.Dunlap@xxxxxxxxxxxxx>
Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Cc: Jan Beulich <jbeulich@xxxxxxxx>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>
Cc: Tim Deegan <tim@xxxxxxx>
Cc: Wei Liu <wei.liu2@xxxxxxxxxx>
---
 xen/arch/arm/mm.c    |  6 ++++++
 xen/arch/x86/mm.c    | 34 ++++++++++++++++++++++++++++++++++
 xen/include/xen/mm.h |  2 ++
 3 files changed, 42 insertions(+)

diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c
index d234c46e41..f734b9287a 100644
--- a/xen/arch/arm/mm.c
+++ b/xen/arch/arm/mm.c
@@ -1181,6 +1181,12 @@ int page_is_ram_type(unsigned long mfn, unsigned long 
mem_type)
     return 0;
 }
 
+int page_get_type(unsigned long mfn)
+{
+    ASSERT_UNREACHABLE();
+    return -1;
+}
+
 unsigned long domain_get_maximum_gpfn(struct domain *d)
 {
     return gfn_x(d->arch.p2m.max_mapped_gfn);
diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index a1a1f5f3c3..cb4b68b2a9 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -430,6 +430,40 @@ int page_is_ram_type(unsigned long mfn, unsigned long 
mem_type)
     return 0;
 }
 
+int page_get_type(unsigned long mfn)
+{
+    uint64_t maddr = pfn_to_paddr(mfn);
+    unsigned int i;
+
+    for ( i = 0; i < e820.nr_map; i++ )
+    {
+        /* Test the range. */
+        if ( (e820.map[i].addr <= maddr) &&
+             ((e820.map[i].addr + e820.map[i].size) >= (maddr + PAGE_SIZE)) )
+            switch ( e820.map[i].type )
+            {
+            case E820_RAM:
+                return RAM_TYPE_CONVENTIONAL;
+
+            case E820_RESERVED:
+                return RAM_TYPE_RESERVED;
+
+            case E820_UNUSABLE:
+                return RAM_TYPE_UNUSABLE;
+
+            case E820_ACPI:
+            case E820_NVS:
+                return RAM_TYPE_ACPI;
+
+            default:
+                ASSERT_UNREACHABLE();
+                return -1;
+            }
+    }
+
+    return -1;
+}
+
 unsigned long domain_get_maximum_gpfn(struct domain *d)
 {
     if ( is_hvm_domain(d) )
diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h
index 24654e8e22..9584fe3a77 100644
--- a/xen/include/xen/mm.h
+++ b/xen/include/xen/mm.h
@@ -597,6 +597,8 @@ int __must_check donate_page(struct domain *d, struct 
page_info *page,
 #define RAM_TYPE_ACPI         0x00000008
 /* TRUE if the whole page at @mfn is of the requested RAM type(s) above. */
 int page_is_ram_type(unsigned long mfn, unsigned long mem_type);
+/* Returns the page type if the whole page is of the same type. */
+int page_get_type(unsigned long mfn);
 
 /* Prepare/destroy a ring for a dom0 helper. Helper with talk
  * with Xen on behalf of this domain. */
-- 
2.18.0


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.