From patchwork Thu Dec 23 08:11:39 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 429191 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oBNJ5f3u026223 for ; Thu, 23 Dec 2010 19:06:00 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751820Ab0LWIH0 (ORCPT ); Thu, 23 Dec 2010 03:07:26 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:53784 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1751774Ab0LWIH0 (ORCPT ); Thu, 23 Dec 2010 03:07:26 -0500 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 47386170D29; Thu, 23 Dec 2010 16:07:25 +0800 (CST) Received: from mailserver.fnst.cn.fujitus.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id oBN82ULR026410; Thu, 23 Dec 2010 16:02:30 +0800 Received: from [10.167.225.99] ([10.167.225.99]) by mailserver.fnst.cn.fujitus.com (Lotus Domino Release 8.5.1FP4) with ESMTP id 2010122316071779-35507 ; Thu, 23 Dec 2010 16:07:17 +0800 Message-ID: <4D13043B.1040904@cn.fujitsu.com> Date: Thu, 23 Dec 2010 16:11:39 +0800 From: Xiao Guangrong User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.11) Gecko/20100713 Thunderbird/3.0.6 MIME-Version: 1.0 To: Avi Kivity CC: Marcelo Tosatti , KVM Subject: [PATCH 2/2] KVM: test: dump page mapping if test fail References: <4D1303FC.9070404@cn.fujitsu.com> In-Reply-To: <4D1303FC.9070404@cn.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2010-12-23 16:07:17, Serialize by Router on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2010-12-23 16:07:18, Serialize complete at 2010-12-23 16:07:18 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Thu, 23 Dec 2010 19:06:00 +0000 (UTC) diff --git a/x86/access.c b/x86/access.c index f43f7f1..709d1a6 100644 --- a/x86/access.c +++ b/x86/access.c @@ -35,6 +35,9 @@ typedef unsigned long pt_element_t; #define MSR_EFER 0xc0000080 #define EFER_NX_MASK (1ull << 11) +#define PT_INDEX(address, level) \ + ((address) >> (12 + ((level)-1) * 9)) & 511 + /* * page table access check tests */ @@ -420,7 +423,7 @@ void __ac_setup_specific_pages(ac_test_t *at, ac_pool_t *pool, u64 pd_page, at->ptep = 0; for (int i = 4; i >= 1 && (i >= 2 || !at->flags[AC_PDE_PSE]); --i) { pt_element_t *vroot = va(root & PT_BASE_ADDR_MASK); - unsigned index = ((unsigned long)at->virt >> (12 + (i-1) * 9)) & 511; + unsigned index = PT_INDEX((unsigned long)at->virt, i); pt_element_t pte = 0; switch (i) { case 4: @@ -487,6 +490,22 @@ static void ac_setup_specific_pages(ac_test_t *at, ac_pool_t *pool, return __ac_setup_specific_pages(at, pool, pd_page, pt_page); } +static void dump_mapping(ac_test_t *at) +{ + unsigned long root = read_cr3(); + int i; + + printf("Dump mapping: address: %llx\n", at->virt); + for (i = 4; i >= 1 && (i >= 2 || !at->flags[AC_PDE_PSE]); --i) { + pt_element_t *vroot = va(root & PT_BASE_ADDR_MASK); + unsigned index = PT_INDEX((unsigned long)at->virt, i); + pt_element_t pte = vroot[index]; + + printf("------L%d: %llx\n", i, pte); + root = vroot[index]; + } +} + static void ac_test_check(ac_test_t *at, _Bool *success_ret, _Bool cond, const char *fmt, ...) { @@ -511,6 +530,7 @@ static void ac_test_check(ac_test_t *at, _Bool *success_ret, _Bool cond, vsnprintf(buf, sizeof(buf), fmt, ap); va_end(ap); printf("FAIL: %s\n", buf); + dump_mapping(at); } static int pt_match(pt_element_t pte1, pt_element_t pte2, pt_element_t ignore)