From: Roger Pau Monne <roger.pau@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: Stefano Stabellini <sstabellini@kernel.org>,
Wei Liu <wei.liu2@citrix.com>,
George Dunlap <George.Dunlap@eu.citrix.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Ian Jackson <ian.jackson@eu.citrix.com>, Tim Deegan <tim@xen.org>,
Julien Grall <julien.grall@arm.com>,
Jan Beulich <jbeulich@suse.com>,
Roger Pau Monne <roger.pau@citrix.com>
Subject: [PATCH v7 4/6] mm: introduce a helper to get the memory type of a page
Date: Wed, 22 Aug 2018 09:51:58 +0200 [thread overview]
Message-ID: <20180822075200.50278-5-roger.pau@citrix.com> (raw)
In-Reply-To: <20180822075200.50278-1-roger.pau@citrix.com>
Returns all the memory types applicable to a page.
This function is unimplemented for ARM.
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
---
Changes since v5:
- Return all types that apply to a page, since the types themselves
are flags that can be or'ed together.
---
Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: Julien Grall <julien.grall@arm.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: George Dunlap <George.Dunlap@eu.citrix.com>
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Tim Deegan <tim@xen.org>
Cc: Wei Liu <wei.liu2@citrix.com>
---
xen/arch/x86/mm.c | 42 ++++++++++++++++++++++++++++++++++++++++++
xen/include/xen/mm.h | 3 +++
2 files changed, 45 insertions(+)
diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index 8ac4412554..fcf4bb0afc 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -430,6 +430,48 @@ int page_is_ram_type(unsigned long mfn, unsigned long mem_type)
return 0;
}
+unsigned int page_get_ram_type(unsigned long mfn)
+{
+ uint64_t last = 0, maddr = pfn_to_paddr(mfn);
+ unsigned int i, type = 0;
+
+ for ( i = 0; i < e820.nr_map;
+ last = e820.map[i].addr + e820.map[i].size, i++ )
+ {
+ if ( (maddr + PAGE_SIZE) > last && maddr < e820.map[i].addr )
+ type |= RAM_TYPE_UNKNOWN;
+
+ if ( (maddr + PAGE_SIZE) <= e820.map[i].addr ||
+ maddr >= (e820.map[i].addr + e820.map[i].size) )
+ continue;
+
+ switch ( e820.map[i].type )
+ {
+ case E820_RAM:
+ type |= RAM_TYPE_CONVENTIONAL;
+ break;
+
+ case E820_RESERVED:
+ type |= RAM_TYPE_RESERVED;
+ break;
+
+ case E820_UNUSABLE:
+ type |= RAM_TYPE_UNUSABLE;
+ break;
+
+ case E820_ACPI:
+ case E820_NVS:
+ type |= RAM_TYPE_ACPI;
+ break;
+
+ default:
+ ASSERT_UNREACHABLE();
+ }
+ }
+
+ return type ?: RAM_TYPE_UNKNOWN;
+}
+
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..dbaf10495a 100644
--- a/xen/include/xen/mm.h
+++ b/xen/include/xen/mm.h
@@ -595,8 +595,11 @@ int __must_check donate_page(struct domain *d, struct page_info *page,
#define RAM_TYPE_RESERVED 0x00000002
#define RAM_TYPE_UNUSABLE 0x00000004
#define RAM_TYPE_ACPI 0x00000008
+#define RAM_TYPE_UNKNOWN 0x00000010
/* 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(s). */
+unsigned int page_get_ram_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@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2018-08-22 7:52 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-22 7:51 [PATCH v7 0/6] x86/iommu: PVH Dom0 workarounds for missing RMRR entries Roger Pau Monne
2018-08-22 7:51 ` [PATCH v7 1/6] iommu: rename iommu_dom0_strict and iommu_passthrough Roger Pau Monne
2018-08-22 9:45 ` Wei Liu
2018-08-22 7:51 ` [PATCH v7 2/6] iommu: introduce dom0-iommu option Roger Pau Monne
2018-08-22 9:45 ` Wei Liu
2018-08-22 7:51 ` [PATCH v7 3/6] iommu: make iommu_inclusive_mapping a suboption of dom0-iommu Roger Pau Monne
2018-08-22 9:45 ` Wei Liu
2018-08-24 10:30 ` Roger Pau Monné
2018-08-22 15:07 ` Julien Grall
2018-08-22 15:22 ` Roger Pau Monné
2018-08-22 15:24 ` Julien Grall
2018-08-22 7:51 ` Roger Pau Monne [this message]
2018-08-22 9:45 ` [PATCH v7 4/6] mm: introduce a helper to get the memory type of a page Wei Liu
2018-08-24 10:49 ` Roger Pau Monné
2018-08-22 7:51 ` [PATCH v7 5/6] x86/iommu: switch the hwdom mapping function to use page_get_type Roger Pau Monne
2018-08-22 9:45 ` Wei Liu
2018-08-22 7:52 ` [PATCH v7 6/6] x86/iommu: add map-reserved dom0-iommu option to map reserved memory ranges Roger Pau Monne
2018-08-22 9:45 ` Wei Liu
2018-08-22 15:08 ` Julien Grall
2018-08-28 15:18 ` Jan Beulich
2018-08-27 9:29 ` [PATCH v7 0/6] x86/iommu: PVH Dom0 workarounds for missing RMRR entries Jan Beulich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180822075200.50278-5-roger.pau@citrix.com \
--to=roger.pau@citrix.com \
--cc=George.Dunlap@eu.citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=jbeulich@suse.com \
--cc=julien.grall@arm.com \
--cc=sstabellini@kernel.org \
--cc=tim@xen.org \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).