From: Anthony PERARD <anthony.perard@citrix.com>
To: xen-devel@lists.xen.org
Cc: Anthony PERARD <anthony.perard@citrix.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Ian Jackson <ian.jackson@eu.citrix.com>,
Wei Liu <wei.liu2@citrix.com>, Jan Beulich <jbeulich@suse.com>
Subject: [PATCH v6 09/14] hvmloader: Check modules whereabouts in perform_tests
Date: Tue, 12 Jul 2016 15:42:46 +0100 [thread overview]
Message-ID: <20160712144251.558-10-anthony.perard@citrix.com> (raw)
In-Reply-To: <20160712144251.558-1-anthony.perard@citrix.com>
As perform_tests() is going to clear memory past 4MB, we check that the
memory can be use or we skip the tests.
Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
---
Changes in V6:
- define and use TEST_START and PT_END.
- cast addresses to uintptr_t instead of uint32_t.
- use UINTPTR_MAX for upper limit checks, instead of UINT_MAX.
- fix typos
- include xen/arch-x86/hvm/start_info.h
- better check for the cmdlines, now check if a string would cross the
4GB boundary.
Changes in V5:
- also account for the pages table
- fix coding style
- also check modules cmdline and main cmdline
and modlist_paddr
- make use of check_overlap.
Changes in v4:
- move the check into the perform_test() function.
- skip tests instead of using BUG.
New in V3
---
tools/firmware/hvmloader/tests.c | 76 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 75 insertions(+), 1 deletion(-)
diff --git a/tools/firmware/hvmloader/tests.c b/tools/firmware/hvmloader/tests.c
index fea3ad3..4b5cb93 100644
--- a/tools/firmware/hvmloader/tests.c
+++ b/tools/firmware/hvmloader/tests.c
@@ -20,6 +20,8 @@
*/
#include "util.h"
+#include "config.h"
+#include <xen/arch-x86/hvm/start_info.h>
#define TEST_FAIL 0
#define TEST_PASS 1
@@ -32,8 +34,10 @@
* 4 page table pages reside at 8MB+4kB to 8MB+20kB.
* Pagetables identity-map 0-16MB, except 4kB at va 6MB maps to pa 5MB.
*/
+#define TEST_START (4ul << 20)
#define PD_START (8ul << 20)
#define PT_START (PD_START + 4096)
+#define PT_END (PT_START + 4 * PAGE_SIZE)
static void setup_paging(void)
{
@@ -189,6 +193,37 @@ static int shadow_gs_test(void)
return (ebx == 2) ? TEST_PASS : TEST_FAIL;
}
+static bool check_test_overlap(uint64_t start, uint64_t size)
+{
+ if ( start )
+ return check_overlap(start, size,
+ TEST_START,
+ PT_END - TEST_START);
+ return false;
+}
+
+/* Only return true if the string overlap with the TEST_START,PT_END */
+static bool check_string_overlap_with_test(uint64_t paddr)
+{
+ unsigned len = 0;
+ const char *s;
+
+ if ( !paddr || paddr > UINTPTR_MAX )
+ return false;
+
+ s = (char *)(uintptr_t)paddr;
+ while ( *s && (uintptr_t)s < UINTPTR_MAX )
+ s++;
+
+ /* Not valid string, ignore it. */
+ if ( (uintptr_t)s == UINTPTR_MAX && *s )
+ return false;
+
+ len = (uintptr_t)s - paddr;
+
+ return check_test_overlap(paddr, len);
+}
+
void perform_tests(void)
{
int i, passed, skipped;
@@ -210,11 +245,50 @@ void perform_tests(void)
return;
}
+ /* Check that tests does not use memory where modules are stored */
+ if ( check_test_overlap((uintptr_t)hvm_start_info,
+ sizeof(*hvm_start_info)) )
+ {
+ printf("Skipping tests due to memory used by hvm_start_info\n");
+ return;
+ }
+ if ( check_test_overlap(hvm_start_info->modlist_paddr,
+ hvm_start_info->nr_modules *
+ sizeof(struct hvm_modlist_entry)) )
+ {
+ printf("Skipping tests due to memory used by"
+ " hvm_start_info->modlist\n");
+ return;
+ }
+ for ( i = 0; i < hvm_start_info->nr_modules; i++ )
+ {
+ const struct hvm_modlist_entry *modlist =
+ (void *)(uintptr_t)hvm_start_info->modlist_paddr;
+
+ if ( check_test_overlap(modlist[i].paddr, modlist[i].size) )
+ {
+ printf("Skipping tests due to memory used by module[%d]\n", i);
+ return;
+ }
+ if ( check_string_overlap_with_test(modlist[i].cmdline_paddr) )
+ {
+ printf("Skipping tests due to memory used by"
+ " module[%d]'s cmdline\n", i);
+ return;
+ }
+ }
+ if ( check_string_overlap_with_test(hvm_start_info->cmdline_paddr) )
+ {
+ printf("Skipping tests due to memory used by the"
+ " hvm_start_info->cmdline\n");
+ return;
+ }
+
passed = skipped = 0;
for ( i = 0; tests[i].test; i++ )
{
printf(" - %s ... ", tests[i].description);
- memset((char *)(4ul << 20), 0, 4ul << 20);
+ memset((char *)TEST_START, 0, 4ul << 20);
setup_paging();
switch ( (*tests[i].test)() )
{
--
Anthony PERARD
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-07-12 14:42 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-12 14:42 [PATCH v6 00/14] Load BIOS via toolstack instead of been embedded in hvmloader Anthony PERARD
2016-07-12 14:42 ` [PATCH v6 01/14] libxc: Rework extra module initialisation Anthony PERARD
2016-07-12 15:01 ` Wei Liu
2016-07-12 14:42 ` [PATCH v6 02/14] libxc: Prepare a start info structure for hvmloader Anthony PERARD
2016-07-12 15:01 ` Wei Liu
2016-07-12 14:42 ` [PATCH v6 03/14] configure: #define SEABIOS_PATH and OVMF_PATH Anthony PERARD
2016-07-12 14:42 ` [PATCH v6 04/14] firmware/makefile: install BIOS blob Anthony PERARD
2016-07-12 14:42 ` [PATCH v6 05/14] libxl: Load guest BIOS from file Anthony PERARD
2016-07-12 15:01 ` Wei Liu
2016-07-12 14:42 ` [PATCH v6 06/14] xen: Move the hvm_start_info C representation from libxc to public/xen.h Anthony PERARD
2016-07-12 14:57 ` Wei Liu
2016-07-12 15:09 ` Andrew Cooper
2016-07-12 15:36 ` Anthony PERARD
2016-07-12 16:07 ` Andrew Cooper
2016-07-14 15:55 ` Anthony PERARD
2016-07-12 14:42 ` [PATCH v6 07/14] hvmloader: Grab the hvm_start_info pointer Anthony PERARD
2016-07-12 14:42 ` [PATCH v6 08/14] hvmloader: Locate the BIOS blob Anthony PERARD
2016-07-12 14:42 ` Anthony PERARD [this message]
2016-07-12 14:42 ` [PATCH v6 10/14] hvmloader: Load SeaBIOS from hvm_start_info modules Anthony PERARD
2016-07-12 14:42 ` [PATCH v6 11/14] hvmloader: Load OVMF from modules Anthony PERARD
2016-07-12 14:42 ` [PATCH v6 12/14] hvmloader: bios->bios_load() now needs to be defined Anthony PERARD
2016-07-12 14:42 ` [PATCH v6 13/14] hvmloader: Always build-in SeaBIOS and OVMF loader Anthony PERARD
2016-07-12 14:42 ` [PATCH v6 14/14] configure: do not depend on SEABIOS_PATH or OVMF_PATH Anthony PERARD
2016-07-12 15:03 ` [PATCH v6 00/14] Load BIOS via toolstack instead of been embedded in hvmloader Wei Liu
2016-07-12 15:04 ` Wei Liu
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=20160712144251.558-10-anthony.perard@citrix.com \
--to=anthony.perard@citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=jbeulich@suse.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.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).