From patchwork Wed Apr 5 14:53:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Razvan Cojocaru X-Patchwork-Id: 9664405 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 BED2160353 for ; Wed, 5 Apr 2017 14:56:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF75620243 for ; Wed, 5 Apr 2017 14:56:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A41AC25223; Wed, 5 Apr 2017 14:56:20 +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 126D820243 for ; Wed, 5 Apr 2017 14:56:20 +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 1cvmKA-0004l0-UL; Wed, 05 Apr 2017 14:54:18 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cvmK9-0004kt-N0 for xen-devel@lists.xen.org; Wed, 05 Apr 2017 14:54:17 +0000 Received: from [85.158.137.68] by server-6.bemta-3.messagelabs.com id 30/7B-08534-81505E85; Wed, 05 Apr 2017 14:54:16 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprLIsWRWlGSWpSXmKPExsUSfTxjoa4469M IgwXHVC2WfFzM4sDocXT3b6YAxijWzLyk/IoE1oyOs3wFt/gq1h56wtLA+IS7i5GTQ0jAXWLF x1+MXYxcQPYaRok9LTuZIBLXGCUu3DKHKZp9YjFU0T5Gid7ji1lAEmwChhKrN7awgdgiAtIS1 z5fZgSxmQUmMEp8umkMYgsL2Er83bcGbCiLgKrEob/NzCA2r4CnxMJ5v8F6JQTkJE4em8wKYe dIbO14AxTnALKlJP63KoHslRDoZZH4emMOE0SNjMSjiTfZJjAKLGBkWMWoXpxaVJZapGukl1S UmZ5RkpuYmaNraGCsl5taXJyYnpqTmFSsl5yfu4kRGFT1DAyMOxhPNTsfYpTkYFIS5VXweRIh xJeUn1KZkVicEV9UmpNafIhRhoNDSYL3FPPTCCHBotT01Iq0zBxgeMOkJTh4lER4m0DSvMUFi bnFmekQqVOMuhxzZu9+wyTEkpeflyolzvsdpEgApCijNA9uBCzWLjHKSgnzMjIwMAjxFKQW5W aWoMq/YhTnYFQS5mVhAZrCk5lXArfpFdARTEBHPLnzEOSIkkSElFQDo8RaWXvnpYcun1f7YrK C60B12ZvK89UWandj+B6ff7X/zX6Z2Qe1n23xN/9gHXVto85l7qAXCzWePIquW+D+jLUulnu+ 3ulH11X+XlPoustnuHGyxs74mCWHHgSG2gpvdshPvyLDVf1vV2TJUu/eloS1C6d+3R33v8yw1 Oit7q6bdVO81kydm6jEUpyRaKjFXFScCAC0GxywsAIAAA== X-Env-Sender: rcojocaru@bitdefender.com X-Msg-Ref: server-11.tower-31.messagelabs.com!1491404055!63480972!1 X-Originating-IP: [91.199.104.161] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 5807 invoked from network); 5 Apr 2017 14:54:15 -0000 Received: from mx01.bbu.dsd.mx.bitdefender.com (HELO mx01.bbu.dsd.mx.bitdefender.com) (91.199.104.161) by server-11.tower-31.messagelabs.com with DHE-RSA-AES128-GCM-SHA256 encrypted SMTP; 5 Apr 2017 14:54:15 -0000 Received: (qmail 31267 invoked from network); 5 Apr 2017 17:54:14 +0300 Received: from unknown (HELO mx-sr.buh.bitdefender.com) (10.17.80.103) by mx01.bbu.dsd.mx.bitdefender.com with AES256-GCM-SHA384 encrypted SMTP; 5 Apr 2017 17:54:14 +0300 Received: from smtp02.buh.bitdefender.net (smtp.bitdefender.biz [10.17.80.76]) by mx-sr.buh.bitdefender.com (Postfix) with ESMTP id D59907FC40 for ; Wed, 5 Apr 2017 17:54:13 +0300 (EEST) Received: (qmail 11418 invoked from network); 5 Apr 2017 17:54:13 +0300 Received: from xen.dsd.ro (HELO xen.dsd.bitdefender.biz) (rcojocaru@bitdefender.com@10.10.14.109) by smtp02.buh.bitdefender.net with AES128-SHA256 encrypted SMTP; 5 Apr 2017 17:54:13 +0300 From: Razvan Cojocaru To: xen-devel@lists.xen.org Date: Wed, 5 Apr 2017 17:53:53 +0300 Message-Id: <1491404033-14458-1-git-send-email-rcojocaru@bitdefender.com> X-Mailer: git-send-email 1.9.1 X-BitDefender-Scanner: Clean, Agent: BitDefender qmail 3.1.6 on smtp02.buh.bitdefender.net, sigver: 7.70632 X-BitDefender-Spam: No (0) X-BitDefender-SpamStamp: Build: [Engines: 2.15.8.1074, Dats: 445331, Stamp: 3], Multi: [Enabled, t: (0.000008, 0.005903)], BW: [Enabled, t: (0.000007)], RBL DNSBL: [Disabled], APM: [Enabled, Score: 500, t: (0.002885), Flags: 85D2ED72; NN_NO_CONTENT_TYPE; NN_NO_LINK_NMD; NN_LEGIT_BITDEFENDER; NN_LEGIT_S_SQARE_BRACKETS; NN_LEGIT_MAILING_LIST_TO], SGN: [Enabled, t: (0.009412,0.000073)], URL: [Enabled, t: (0.000005)], RTDA: [Enabled, t: (0.198903), Hit: No, Details: v2.4.6; Id: 11.5eun05.1bcsfnrq3.u1p9], total: 0(775) X-BitDefender-CF-Stamp: none Cc: wei.liu2@citrix.com, ian.jackson@eu.citrix.com, Razvan Cojocaru , Cristian-Bogdan Sirb Subject: [Xen-devel] [PATCH V2] libxc: fix xc_translate_foreign_address() 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: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Currently xc_translate_foreign_address() only checks for the PSE bit on level 2 entries (that's 2 MB pages on x64 and 32-bit with PAE, and 4 MB pages on 32-bit). But the Linux kernel sometimes uses 1 GB pages. This patch fixes that, by checking the PSE bit on level 3 entries if the guest has 4 translation levels (that means 64-bit guests only). Signed-off-by: Cristian-Bogdan Sirb Acked-by: Wei Liu Signed-off-by: Razvan Cojocaru --- Changes since V1: - Added header comment. --- tools/libxc/include/xenctrl.h | 3 +++ tools/libxc/xc_pagetab.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index 2d97d36..ca4bb6c 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -1460,6 +1460,9 @@ int xc_lockprof_query(xc_interface *xch, void *xc_memalign(xc_interface *xch, size_t alignment, size_t size); /** + * Avoid using this function, as it does not work for all cases (such + * as 4M superpages, or guests using PSE36). Only used for debugging. + * * Translates a virtual address in the context of a given domain and * vcpu returning the GFN containing the address (that is, an MFN for * PV guests, a PFN for HVM guests). Returns 0 for failure. diff --git a/tools/libxc/xc_pagetab.c b/tools/libxc/xc_pagetab.c index 92eebd6..db25c20 100644 --- a/tools/libxc/xc_pagetab.c +++ b/tools/libxc/xc_pagetab.c @@ -93,7 +93,7 @@ unsigned long xc_translate_foreign_address(xc_interface *xch, uint32_t dom, return 0; } paddr = pte & 0x000ffffffffff000ull; - if (level == 2 && (pte & PTE_PSE)) { + if ((level == 2 || (level == 3 && pt_levels == 4)) && (pte & PTE_PSE)) { mask = ((mask ^ ~-mask) >> 1); /* All bits below first set bit */ return ((paddr & ~mask) | (virt & mask)) >> PAGE_SHIFT; }