From patchwork Wed Jun 22 17:15:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 9193387 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EDA0A601C0 for ; Wed, 22 Jun 2016 17:18:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D9ADA2840A for ; Wed, 22 Jun 2016 17:18:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CEA8028417; Wed, 22 Jun 2016 17:18:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7D2482840A for ; Wed, 22 Jun 2016 17:18:59 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bFllU-0004lv-BK; Wed, 22 Jun 2016 17:16:36 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bFllT-0004lI-3s for xen-devel@lists.xen.org; Wed, 22 Jun 2016 17:16:35 +0000 Received: from [193.109.254.147] by server-9.bemta-14.messagelabs.com id 07/CC-32749-2F7CA675; Wed, 22 Jun 2016 17:16:34 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprAIsWRWlGSWpSXmKPExsXitHRDpO7H41n hBr0fjSyWfFzM4sDocXT3b6YAxijWzLyk/IoE1oyFTx8yFryQqFg+/ypjA2OvUBcjJ4eEgL/E zl33mEBsNgEDiRXTrzKC2CICshKru+awdzFycTALHGGUuHXzJ1hCGKhh7oGL7CA2i4CqxItnH WxdjBwcvAJ2Entv1kHMlJNoOH+fGcTmBAove9XDBmILCdhK3F6wgBHCVpO4sXAZC4jNKyAocX LmEzCbWUBC4uCLF8wQc7glbp+eyjyBkW8WkrJZSMoWMDKtYlQvTi0qSy3SNddLKspMzyjJTcz M0TU0NNHLTS0uTkxPzUlMKtZLzs/dxAgMKQYg2MH4ZYnzIUZJDiYlUV7GbVnhQnxJ+SmVGYnF GfFFpTmpxYcYZTg4lCR4k44C5QSLUtNTK9Iyc4DBDZOW4OBREuHNBEnzFhck5hZnpkOkTjEqS onzVoAkBEASGaV5cG2wiLrEKCslzMsIdIgQT0FqUW5mCar8K0ZxDkYlYd48kCk8mXklcNNfAS 1mAlq8rD8dZHFJIkJKqoGxQ9D6hjvXUmm5nsez/+81PvMiXTr+5OSTdi6f+X+6vWQ/uv9E7oV j7jE+xYwvbT1XaE7+9f4M66KYZ5s2pF+7/SM07lT5OWU1F9Xnc/gWbtVl3X7Bh1+tZdKX6yK7 U/8JV72QkPnq+lVKd4VG8gLvOo6JJ54EXb/6atmU2edPXmlK4Z9/OU/uvBJLcUaioRZzUXEiA COlJp+jAgAA X-Env-Sender: prvs=9742ee4c2=anthony.perard@citrix.com X-Msg-Ref: server-8.tower-27.messagelabs.com!1466615792!45609305!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 18227 invoked from network); 22 Jun 2016 17:16:33 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-8.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 22 Jun 2016 17:16:33 -0000 X-IronPort-AV: E=Sophos;i="5.26,509,1459814400"; d="scan'208";a="362146213" From: Anthony PERARD To: Date: Wed, 22 Jun 2016 18:15:40 +0100 Message-ID: <20160622171545.5304-10-anthony.perard@citrix.com> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160622171545.5304-1-anthony.perard@citrix.com> References: <20160622171545.5304-1-anthony.perard@citrix.com> MIME-Version: 1.0 X-DLP: MIA2 Cc: Anthony PERARD , Andrew Cooper , Ian Jackson , Wei Liu , Jan Beulich Subject: [Xen-devel] [PATCH v5 09/14] hvmloader: Check modules whereabouts in perform_tests X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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 | 53 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tools/firmware/hvmloader/tests.c b/tools/firmware/hvmloader/tests.c index fea3ad3..bf3aa01 100644 --- a/tools/firmware/hvmloader/tests.c +++ b/tools/firmware/hvmloader/tests.c @@ -20,6 +20,7 @@ */ #include "util.h" +#include "config.h" #define TEST_FAIL 0 #define TEST_PASS 1 @@ -189,6 +190,15 @@ 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, + 4ul << 20, + (PT_START + 4 * PAGE_SIZE) - (4ul << 20)); + return false; +} + void perform_tests(void) { int i, passed, skipped; @@ -210,6 +220,49 @@ void perform_tests(void) return; } + /* Check that tests does not use memory where modules are stored */ + if ( check_test_overlap((uint32_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 = + (struct hvm_modlist_entry *)(uint32_t)hvm_start_info->modlist_paddr; + uint64_t cmdline_paddr = modlist[i].cmdline_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 ( cmdline_paddr && cmdline_paddr < UINT_MAX && + check_test_overlap(cmdline_paddr, + strlen((char*)(uint32_t)cmdline_paddr)) ) + { + printf("Skipping tests due to memory used by" + " module[%d]'s cmdline\n", i); + return; + } + } + if ( hvm_start_info->cmdline_paddr && + hvm_start_info->cmdline_paddr < UINT_MAX && + check_test_overlap(hvm_start_info->cmdline_paddr, + strlen((char*)(uint32_t)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++ ) {