From patchwork Thu Dec 23 08:10:36 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 429181 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 oBNJ5f3t026223 for ; Thu, 23 Dec 2010 19:06:00 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751738Ab0LWIGZ (ORCPT ); Thu, 23 Dec 2010 03:06:25 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:49862 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1751655Ab0LWIGY (ORCPT ); Thu, 23 Dec 2010 03:06:24 -0500 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id E1B5A170CB3; Thu, 23 Dec 2010 16:06:22 +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 oBN81Sp1026385; Thu, 23 Dec 2010 16:01:28 +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 2010122316061533-35493 ; Thu, 23 Dec 2010 16:06:15 +0800 Message-ID: <4D1303FC.9070404@cn.fujitsu.com> Date: Thu, 23 Dec 2010 16:10:36 +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 1/2] KVM: test: add the test case to check PFEC on prefetch pte path X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2010-12-23 16:06:15, Serialize by Router on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2010-12-23 16:06:15, Serialize complete at 2010-12-23 16:06:15 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 067565b..f43f7f1 100644 --- a/x86/access.c +++ b/x86/access.c @@ -408,7 +408,9 @@ fault: at->expected_error &= ~PFERR_FETCH_MASK; } -void ac_test_setup_pte(ac_test_t *at, ac_pool_t *pool) +void __ac_setup_specific_pages(ac_test_t *at, ac_pool_t *pool, u64 pd_page, + u64 pt_page) + { unsigned long root = read_cr3(); @@ -423,13 +425,12 @@ void ac_test_setup_pte(ac_test_t *at, ac_pool_t *pool) switch (i) { case 4: case 3: - pte = vroot[index]; - pte = ac_test_alloc_pt(pool) | PT_PRESENT_MASK; - pte |= PT_WRITABLE_MASK | PT_USER_MASK; + pte = pd_page ? pd_page : ac_test_alloc_pt(pool); + pte |= PT_PRESENT_MASK | PT_WRITABLE_MASK | PT_USER_MASK; break; case 2: if (!at->flags[AC_PDE_PSE]) - pte = ac_test_alloc_pt(pool); + pte = pt_page ? pt_page : ac_test_alloc_pt(pool); else { pte = at->phys & PT_PSE_BASE_ADDR_MASK; pte |= PT_PSE_MASK; @@ -475,6 +476,17 @@ void ac_test_setup_pte(ac_test_t *at, ac_pool_t *pool) ac_set_expected_status(at); } +static void ac_test_setup_pte(ac_test_t *at, ac_pool_t *pool) +{ + __ac_setup_specific_pages(at, pool, 0, 0); +} + +static void ac_setup_specific_pages(ac_test_t *at, ac_pool_t *pool, + u64 pd_page, u64 pt_page) +{ + return __ac_setup_specific_pages(at, pool, pd_page, pt_page); +} + static void ac_test_check(ac_test_t *at, _Bool *success_ret, _Bool cond, const char *fmt, ...) { @@ -663,6 +675,43 @@ err: return 0; } +/* + * This test case is used to triger the bug which is fixed by + * commit 3ddf6c06e13e in the kvm tree + */ +static int check_pfec_on_prefetch_pte(ac_pool_t *pool) +{ + ac_test_t at1, at2; + + ac_test_init(&at1, (void *)(0x123406001000)); + ac_test_init(&at2, (void *)(0x123406003000)); + + at1.flags[AC_PDE_PRESENT] = 1; + at1.flags[AC_PTE_PRESENT] = 1; + ac_setup_specific_pages(&at1, pool, 30 * 1024 * 1024, 30 * 1024 * 1024); + + at2.flags[AC_PDE_PRESENT] = 1; + at2.flags[AC_PTE_NX] = 1; + at2.flags[AC_PTE_PRESENT] = 1; + ac_setup_specific_pages(&at2, pool, 30 * 1024 * 1024, 30 * 1024 * 1024); + + if (!ac_test_do_access(&at1)) { + printf("%s: prepare fail\n", __FUNCTION__); + goto err; + } + + if (!ac_test_do_access(&at2)) { + printf("%s: check PFEC on prefetch pte path fail\n", + __FUNCTION__); + goto err; + } + + return 1; + +err: + return 0; +} + int ac_test_exec(ac_test_t *at, ac_pool_t *pool) { int r; @@ -675,11 +724,18 @@ int ac_test_exec(ac_test_t *at, ac_pool_t *pool) return r; } +typedef int (*ac_test_fn)(ac_pool_t *pool); +const ac_test_fn ac_test_cases[] = +{ + corrupt_hugepage_triger, + check_pfec_on_prefetch_pte, +}; + int ac_test_run(void) { ac_test_t at; ac_pool_t pool; - int tests, successes; + int i, tests, successes; printf("run\n"); tests = successes = 0; @@ -690,8 +746,10 @@ int ac_test_run(void) successes += ac_test_exec(&at, &pool); } while (ac_test_bump(&at)); - ++tests; - successes += corrupt_hugepage_triger(&pool); + for (i = 0; i < ARRAY_SIZE(ac_test_cases); i++) { + ++tests; + successes += ac_test_cases[i](&pool); + } printf("\n%d tests, %d failures\n", tests, tests - successes);