From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: Tiejun Chen <tiejun.chen@intel.com>
Cc: kevin.tian@intel.com, wei.liu2@citrix.com,
ian.campbell@citrix.com, stefano.stabellini@eu.citrix.com,
tim@xen.org, ian.jackson@eu.citrix.com, xen-devel@lists.xen.org,
jbeulich@suse.com, yang.z.zhang@intel.com
Subject: Re: [v8][PATCH 09/17] hvmloader/ram: check if guest memory is out of reserved device memory maps
Date: Tue, 2 Dec 2014 15:17:44 -0500 [thread overview]
Message-ID: <20141202201744.GH357@laptop.dumpdata.com> (raw)
In-Reply-To: <1417425875-9634-10-git-send-email-tiejun.chen@intel.com>
On Mon, Dec 01, 2014 at 05:24:27PM +0800, Tiejun Chen wrote:
> We need to check to reserve all reserved device memory maps in e820
> to avoid any potential guest memory conflict.
>
> Currently, if we can't insert RDM entries directly, we may need to handle
> several ranges as follows:
s/several/two/
s/follows/follow/
> a. Fixed Ranges --> BUG()
> lowmem_reserved_base-0xA0000: reserved by BIOS implementation,
> BIOS region,
> RESERVED_MEMBASE ~ 0x100000000,
I am not sure what you are trying to say here. Could you explain it
a bit more please?
> b. RAM or RAM:Hole -> Try to reserve
Reading the beginning of the 'Currently'.. this says:
we may need to handle RAM or RAM:Hole -> Try to reserve.
I don't know what 'RAM:Hole' means. And instead of using '->' you can
say: we will try to reserve.
But what are we reserving ? Are we reserving it as an E820_RSV or just
as an hole? What about the RAM behind it? Are we gulping up the RAM regions
(as in losing them) or are we moving the RAM regions (GPFNs) to somewhere else?
>
> Signed-off-by: Tiejun Chen <tiejun.chen@intel.com>
> ---
> tools/firmware/hvmloader/e820.c | 168 ++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 168 insertions(+)
>
> diff --git a/tools/firmware/hvmloader/e820.c b/tools/firmware/hvmloader/e820.c
> index 2e05e93..ef87e41 100644
> --- a/tools/firmware/hvmloader/e820.c
> +++ b/tools/firmware/hvmloader/e820.c
> @@ -22,6 +22,7 @@
>
> #include "config.h"
> #include "util.h"
> +#include <xen/memory.h>
>
> void dump_e820_table(struct e820entry *e820, unsigned int nr)
> {
> @@ -68,12 +69,173 @@ void dump_e820_table(struct e820entry *e820, unsigned int nr)
> }
> }
>
> +extern struct xen_reserved_device_memory *rdm_map;
> +static unsigned int construct_rdm_e820_maps(unsigned int next_e820_entry_index,
s/next_e820_entry_index/next_entry/ ?
> + uint32_t nr_map,
> + struct xen_reserved_device_memory *map,
> + struct e820entry *e820,
> + unsigned int lowmem_reserved_base,
> + unsigned int bios_image_base)
> +{
> + unsigned int i, j, sum_nr;
> + uint64_t start, end, next_start, rdm_start, rdm_end;
> + uint32_t type;
> + int err = 0;
> +
> + for ( i = 0; i < nr_map; i++ )
> + {
> + rdm_start = (uint64_t)map[i].start_pfn << PAGE_SHIFT;
> + rdm_end = rdm_start + ((uint64_t)map[i].nr_pages << PAGE_SHIFT);
> +
> + for ( j = 0; j < next_e820_entry_index - 1; j++ )
> + {
> + sum_nr = next_e820_entry_index + nr_map;
> + start = e820[j].addr;
> + end = e820[j].addr + e820[j].size;
> + type = e820[j].type;
> + next_start = e820[j+1].addr;
> +
> + if ( rdm_start >= start && rdm_start <= end )
> + {
> + /*
> + * lowmem_reserved_base-0xA0000: reserved by BIOS
> + * implementation.
> + * Or BIOS region.
> + */
> + if ( (lowmem_reserved_base < 0xA0000 &&
> + start == lowmem_reserved_base) ||
> + start == bios_image_base )
something is off with your spaces.
> + {
> + err = -1;
> + break;
Keep in mind we will just break out of this loop. Do you want to add
at the end of this loop:
if (err)
break;
> + }
> + }
> +
> + /* Just amid those remaining e820 entries. */
> + if ( (rdm_start > end) && (rdm_end < next_start) )
> + {
> + memmove(&e820[j+2], &e820[j+1],
> + (sum_nr - j - 1) * sizeof(struct e820entry));
What if there is something at j+2? Should we have an
j-2 < E820_MAX check somewhere?
This whole 'memmove' logic is making me a bit worried.
Would it be easier to have this logic inside build_e820_table so
that it could construct the e820 with this information right away?
Or if that was deemed incorrect could you explain that in the
commit description?
> +
> + /* Then fill RMRR into that entry. */
> + e820[j+1].addr = rdm_start;
> + e820[j+1].size = rdm_end - rdm_start;
> + e820[j+1].type = E820_RESERVED;
> + next_e820_entry_index++;
> + continue;
> + }
> +
> + /* Already at the end. */
> + if ( (rdm_start > end) && !next_start )
> + {
> + e820[next_e820_entry_index].addr = rdm_start;
> + e820[next_e820_entry_index].size = rdm_end - rdm_start;
> + e820[next_e820_entry_index].type = E820_RESERVED;
> + next_e820_entry_index++;
> + continue;
> + }
> +
> + if ( type == E820_RAM )
> + {
> + /* If coincide with one RAM range. */
> + if ( rdm_start == start && rdm_end == end)
> + {
> + e820[j].type = E820_RESERVED;
> + continue;
> + }
> +
> + /* If we're just aligned with start of one RAM range. */
> + if ( rdm_start == start && rdm_end < end )
> + {
> + memmove(&e820[j+1], &e820[j],
> + (sum_nr - j) * sizeof(struct e820entry));
> +
> + e820[j+1].addr = rdm_end;
> + e820[j+1].size = e820[j].addr + e820[j].size - rdm_end;
> + e820[j+1].type = E820_RAM;
> + next_e820_entry_index++;
> +
> + e820[j].addr = rdm_start;
> + e820[j].size = rdm_end - rdm_start;
> + e820[j].type = E820_RESERVED;
> + continue;
> + }
> +
> + /* If we're just aligned with end of one RAM range. */
> + if ( rdm_start > start && rdm_end == end )
> + {
> + memmove(&e820[j+1], &e820[j],
> + (sum_nr - j) * sizeof(struct e820entry));
> +
> + e820[j].size = rdm_start - e820[j].addr;
> + e820[j].type = E820_RAM;
> +
> + e820[j+1].addr = rdm_start;
> + e820[j+1].size = rdm_end - rdm_start;
> + e820[j+1].type = E820_RESERVED;
> + next_e820_entry_index++;
> + continue;
> + }
> +
> + /* If we're just in of one RAM range */
> + if ( rdm_start > start && rdm_end < end )
> + {
> + memmove(&e820[j+2], &e820[j],
> + (sum_nr - j) * sizeof(struct e820entry));
> +
> + e820[j+2].addr = rdm_end;
> + e820[j+2].size = e820[j].addr + e820[j].size - rdm_end;
> + e820[j+2].type = E820_RAM;
> + next_e820_entry_index++;
> +
> + e820[j+1].addr = rdm_start;
> + e820[j+1].size = rdm_end - rdm_start;
> + e820[j+1].type = E820_RESERVED;
> + next_e820_entry_index++;
> +
> + e820[j].size = rdm_start - e820[j].addr;
> + e820[j].type = E820_RAM;
> + continue;
> + }
> +
> + /* If we're going last RAM:Hole range */
> + if ( end < next_start && rdm_start > start &&
> + rdm_end < next_start )
> + {
> + memmove(&e820[j+1], &e820[j],
> + (sum_nr - j) * sizeof(struct e820entry));
> +
> + e820[j].size = rdm_start - e820[j].addr;
> + e820[j].type = E820_RAM;
> +
> + e820[j+1].addr = rdm_start;
> + e820[j+1].size = rdm_end - rdm_start;
> + e820[j+1].type = E820_RESERVED;
> + next_e820_entry_index++;
> + continue;
> + }
> + }
> + }
> + }
> +
> + /* These overlap may issue guest can't work well. */
> + if ( err )
> + {
> + printf("Guest can't work with some reserved device memory overlap!\n");
> + BUG();
> + }
> +
> + /* Fine to construct RDM mappings into e820. */
> + return next_e820_entry_index;
> +}
> +
> /* Create an E820 table based on memory parameters provided in hvm_info. */
> int build_e820_table(struct e820entry *e820,
> unsigned int lowmem_reserved_base,
> unsigned int bios_image_base)
> {
> unsigned int nr = 0;
> + unsigned int nr_entries = 0;
>
> if ( !lowmem_reserved_base )
> lowmem_reserved_base = 0xA0000;
> @@ -169,6 +331,12 @@ int build_e820_table(struct e820entry *e820,
> nr++;
> }
>
> + nr_entries = hvm_get_reserved_device_memory_map();
> + if ( nr_entries )
> + nr = construct_rdm_e820_maps(nr, nr_entries, rdm_map, e820,
> + lowmem_reserved_base,
> + bios_image_base);
> +
> return nr;
> }
>
> --
> 1.9.1
>
next prev parent reply other threads:[~2014-12-02 20:17 UTC|newest]
Thread overview: 106+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-01 9:24 [v8][PATCH 00/17] xen: RMRR fix Tiejun Chen
2014-12-01 9:24 ` [v8][PATCH 01/17] tools/hvmloader: link errno.h from xen internal Tiejun Chen
2014-12-01 9:24 ` [v8][PATCH 02/17] introduce XEN_DOMCTL_set_rdm Tiejun Chen
2014-12-02 8:33 ` Tian, Kevin
2014-12-08 1:30 ` Chen, Tiejun
2014-12-02 19:39 ` Konrad Rzeszutek Wilk
2014-12-08 3:16 ` Chen, Tiejun
2014-12-08 15:57 ` Konrad Rzeszutek Wilk
2014-12-09 1:06 ` Chen, Tiejun
2014-12-09 8:33 ` Jan Beulich
2014-12-09 16:36 ` Konrad Rzeszutek Wilk
2014-12-04 15:33 ` Jan Beulich
2014-12-05 6:13 ` Tian, Kevin
2014-12-08 6:06 ` Chen, Tiejun
2014-12-08 8:43 ` Jan Beulich
2014-12-09 2:38 ` Chen, Tiejun
2014-12-09 7:29 ` Jan Beulich
2014-12-01 9:24 ` [v8][PATCH 03/17] introduce XENMEM_reserved_device_memory_map Tiejun Chen
2014-12-02 19:47 ` Konrad Rzeszutek Wilk
2014-12-08 6:17 ` Chen, Tiejun
2014-12-08 10:00 ` Jan Beulich
2014-12-08 16:45 ` Daniel De Graaf
2014-12-08 16:54 ` Jan Beulich
2014-12-01 9:24 ` [v8][PATCH 04/17] update the existing hypercall to support XEN_DOMCTL_set_rdm Tiejun Chen
2014-12-02 8:46 ` Tian, Kevin
2014-12-08 6:22 ` Chen, Tiejun
2014-12-04 15:50 ` Jan Beulich
2014-12-08 7:11 ` Chen, Tiejun
2014-12-08 8:51 ` Jan Beulich
2014-12-09 7:47 ` Chen, Tiejun
2014-12-09 8:19 ` Jan Beulich
2014-12-09 9:12 ` Chen, Tiejun
2014-12-09 9:21 ` Jan Beulich
2014-12-09 9:35 ` Chen, Tiejun
2014-12-09 10:11 ` Tim Deegan
2014-12-09 10:22 ` Jan Beulich
2014-12-10 1:59 ` Chen, Tiejun
2014-12-10 20:21 ` Konrad Rzeszutek Wilk
2014-12-10 3:39 ` Tian, Kevin
2014-12-10 9:01 ` Jan Beulich
2014-12-10 9:57 ` Tian, Kevin
2014-12-10 11:12 ` Tim Deegan
2014-12-11 2:03 ` Tian, Kevin
2014-12-11 13:09 ` Tim Deegan
2014-12-18 16:13 ` Tim Deegan
2014-12-19 1:03 ` Chen, Tiejun
2014-12-01 9:24 ` [v8][PATCH 05/17] tools/libxc: introduce hypercall for xc_reserved_device_memory_map Tiejun Chen
2014-12-02 8:46 ` Tian, Kevin
2014-12-02 19:50 ` Konrad Rzeszutek Wilk
2014-12-08 7:25 ` Chen, Tiejun
2014-12-08 15:52 ` Konrad Rzeszutek Wilk
2014-12-01 9:24 ` [v8][PATCH 06/17] tools/libxc: check if modules space is overlapping with reserved device memory Tiejun Chen
2014-12-02 8:54 ` Tian, Kevin
2014-12-02 19:55 ` Konrad Rzeszutek Wilk
2014-12-08 7:49 ` Chen, Tiejun
2014-12-01 9:24 ` [v8][PATCH 07/17] hvmloader/util: get reserved device memory maps Tiejun Chen
2014-12-02 8:59 ` Tian, Kevin
2014-12-08 7:55 ` Chen, Tiejun
2014-12-02 20:01 ` Konrad Rzeszutek Wilk
2014-12-08 8:09 ` Chen, Tiejun
2014-12-08 8:45 ` Chen, Tiejun
2014-12-04 15:52 ` Jan Beulich
2014-12-08 8:52 ` Chen, Tiejun
2014-12-08 9:18 ` Jan Beulich
2014-12-01 9:24 ` [v8][PATCH 08/17] hvmloader/mmio: reconcile guest mmio with reserved device memory Tiejun Chen
2014-12-02 9:11 ` Tian, Kevin
2014-12-08 9:04 ` Chen, Tiejun
2014-12-04 16:04 ` Jan Beulich
2014-12-08 9:10 ` Chen, Tiejun
2014-12-01 9:24 ` [v8][PATCH 09/17] hvmloader/ram: check if guest memory is out of reserved device memory maps Tiejun Chen
2014-12-02 9:42 ` Tian, Kevin
2014-12-02 20:17 ` Konrad Rzeszutek Wilk [this message]
2014-12-04 16:20 ` Jan Beulich
2014-12-05 6:23 ` Tian, Kevin
2014-12-05 7:43 ` Jan Beulich
2014-12-01 9:24 ` [v8][PATCH 10/17] hvmloader/mem_hole_alloc: skip any overlap with reserved device memory Tiejun Chen
2014-12-02 9:48 ` Tian, Kevin
2014-12-02 20:23 ` Konrad Rzeszutek Wilk
2014-12-04 16:28 ` Jan Beulich
2014-12-05 6:24 ` Tian, Kevin
2014-12-05 7:46 ` Jan Beulich
2014-12-01 9:24 ` [v8][PATCH 11/17] xen/x86/p2m: reject populating for reserved device memory mapping Tiejun Chen
2014-12-02 9:57 ` Tian, Kevin
2014-12-04 16:42 ` Jan Beulich
2014-12-01 9:24 ` [v8][PATCH 12/17] xen/x86/ept: handle reserved device memory in ept_handle_violation Tiejun Chen
2014-12-02 9:59 ` Tian, Kevin
2014-12-02 20:26 ` Konrad Rzeszutek Wilk
2014-12-04 16:46 ` Jan Beulich
2014-12-01 9:24 ` [v8][PATCH 13/17] xen/mem_access: don't allow accessing reserved device memory Tiejun Chen
2014-12-02 14:54 ` Julien Grall
2014-12-18 22:56 ` Tamas K Lengyel
2014-12-02 20:27 ` Konrad Rzeszutek Wilk
2014-12-04 16:51 ` Jan Beulich
2014-12-01 9:24 ` [v8][PATCH 14/17] xen/x86/p2m: introduce set_identity_p2m_entry Tiejun Chen
2014-12-02 10:00 ` Tian, Kevin
2014-12-02 20:29 ` Konrad Rzeszutek Wilk
2014-12-01 9:24 ` [v8][PATCH 15/17] xen:vtd: create RMRR mapping Tiejun Chen
2014-12-02 10:02 ` Tian, Kevin
2014-12-02 20:30 ` Konrad Rzeszutek Wilk
2014-12-01 9:24 ` [v8][PATCH 16/17] xen/vtd: group assigned device with RMRR Tiejun Chen
2014-12-02 10:11 ` Tian, Kevin
2014-12-02 20:40 ` Konrad Rzeszutek Wilk
2014-12-04 17:05 ` Jan Beulich
2014-12-01 9:24 ` [v8][PATCH 17/17] xen/vtd: re-enable USB device assignment if enable pci_force Tiejun Chen
2014-12-05 16:12 ` Konrad Rzeszutek Wilk
2014-12-02 19:17 ` [v8][PATCH 00/17] xen: RMRR fix Konrad Rzeszutek Wilk
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=20141202201744.GH357@laptop.dumpdata.com \
--to=konrad.wilk@oracle.com \
--cc=ian.campbell@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=jbeulich@suse.com \
--cc=kevin.tian@intel.com \
--cc=stefano.stabellini@eu.citrix.com \
--cc=tiejun.chen@intel.com \
--cc=tim@xen.org \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.org \
--cc=yang.z.zhang@intel.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.