From patchwork Tue Aug 8 13:24:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 9888157 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 546D860352 for ; Tue, 8 Aug 2017 13:27:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 46ACB28911 for ; Tue, 8 Aug 2017 13:27:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3B8F828915; Tue, 8 Aug 2017 13:27:13 +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 ABE6028918 for ; Tue, 8 Aug 2017 13:27:12 +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 1df4Um-0001WM-VW; Tue, 08 Aug 2017 13:24:28 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1df4Ul-0001WG-0C for xen-devel@lists.xenproject.org; Tue, 08 Aug 2017 13:24:27 +0000 Received: from [85.158.137.68] by server-11.bemta-3.messagelabs.com id 7F/28-01724-A8BB9895; Tue, 08 Aug 2017 13:24:26 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprPIsWRWlGSWpSXmKPExsVysyfVTbdzd2e kwfHJchbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8badcdZCy6LVZw+85epgfGaYBcjF4eQwGZG iUkLZzJBOLsZJVb8+cHexcjJISyQL/H95GkmEFtEoEbiy5yTzBBFHUwSy7+uZgZJsAloStz5/ AmoiIODV8BKYtafWJAwi4CKxPXTb8B6RQXCJd42HmEBsXkFBCVOznwCZnMKWEvs610IZjMLqE v8mXeJGcKWl9j+dg7zBEbeWUhaZiEpm4WkbAEj8ypGjeLUorLUIl1jA72kosz0jJLcxMwcXUM DY73c1OLixPTUnMSkYr3k/NxNjMDAqmdgYNzB2HnC7xCjJAeTkijvJu3OSCG+pPyUyozE4oz4 otKc1OJDjBocHAJXDh6ZzSjFkpefl6okwau1C6hOsCg1PbUiLTMHGPowpRIcPEoivAIgad7ig sTc4sx0iNQpRkUpcd4AkIQASCKjNA+uDRZvlxhlpYR5GRkYGIR4ClKLcjNLUOVfMYpzMCoJ8w qDTOHJzCuBm/4KaDET0OIIX7DFJYkIKakGxgXBB2qnHztV531l8a/fq/5zp7jbbHt4MeXJ58t ftDKTs5wZ9rinKrBvO+/9IPDes1cftmyQ3XbuE+e3Uw2iD9a5dnSc2LT031ORjMw1t23b1mbk Si5I//yGsfJK3IOOrmCltokeSy/+NLl66cLbP+5aGUJf7h/9vHqRecyM9v/TZCIW2beY5pgrs RRnJBpqMRcVJwIA8hbZybICAAA= X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-12.tower-31.messagelabs.com!1502198664!92294583!1 X-Originating-IP: [217.140.101.70] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 44216 invoked from network); 8 Aug 2017 13:24:25 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-12.tower-31.messagelabs.com with SMTP; 8 Aug 2017 13:24:25 -0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 92B1F13D5; Tue, 8 Aug 2017 06:24:24 -0700 (PDT) Received: from [10.1.206.53] (e108454-lin.cambridge.arm.com [10.1.206.53]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E90103F577; Tue, 8 Aug 2017 06:24:23 -0700 (PDT) To: Sergej Proskurin , xen-devel@lists.xenproject.org, Stefano Stabellini References: <20170718122507.11873-1-proskurin@sec.in.tum.de> <79db1022-aa46-45cb-8fb6-b9e26af1678f@arm.com> <1175c88c-876e-fe5c-ed5f-c8f53b2703f3@sec.in.tum.de> From: Julien Grall Message-ID: <0c80dc19-8f01-3561-aa05-9b34001faeb4@arm.com> Date: Tue, 8 Aug 2017 14:24:22 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: Subject: Re: [Xen-devel] [PATCH v7 00/14] arm/mem_access: Walk guest page tables in SW if mem_access is active 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 On 08/08/17 13:33, Julien Grall wrote: > > > On 08/08/17 13:17, Sergej Proskurin wrote: >>>> diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c >>>> index c07999b518..904abafcae 100644 >>>> --- a/xen/arch/arm/traps.c >>>> +++ b/xen/arch/arm/traps.c >>>> @@ -2688,6 +2688,8 @@ static bool try_map_mmio(gfn_t gfn) >>>> return !map_regions_p2mt(d, gfn, 1, mfn, p2m_mmio_direct_c); >>>> } >>>> >>>> +#include >>>> + >>>> static void do_trap_data_abort_guest(struct cpu_user_regs *regs, >>>> const union hsr hsr) >>>> { >>>> @@ -2725,6 +2727,17 @@ static void do_trap_data_abort_guest(struct >>>> cpu_user_regs *regs, >>>> return; /* Try again */ >>>> } >>>> >>>> + { >>>> + paddr_t ipa, pipa; >>>> + rc = gva_to_ipa(info.gva, &info.ipa, GV2M_READ); >> >> There is no ipa field in mmio_info_t. But even if you used info.gpa >> instead, the test that you have provided is unfortunately flawed: > > Well, I copied the wrong code... info.ipa should be replaced by pipa. > >>>> + BUG_ON(rc); >>>> + printk("guest_walk_tables: gva 0x%x pipa 0x%llx\n", >>>> + info.gva, pipa); >>>> + rc = guest_walk_tables(current, info.gva, &ipa, NULL); >>>> + BUG_ON(rc); >>>> + BUG_ON(ipa != pipa); >> >> In your test-case you don't initialize pipa at all, however you test for >> it in BUG_ON, which is the reason why it fails. I have adopted your test >> case and it runs on ARMv7 (non-LPAE guest) and ARMv8 (LPAE guest) >> without any issues. It would be great if you would verify this behaviour >> by applying the following patch to the arm-gpt-walk-v7 patch [0] as >> before: > > I am afraid that whilst there was a bug in the code to compare ipa != > pipa. If you looked at the log I provided, it was failing before: > > d0: guestcopy: failed to get table entry. > > And this does not even involve pipa... If you wonder your patch below > does not help it also. The patch belows solve my problem: This is because pte.walk.base is encoded on unsigned int:22 bits. A shift by 10 will not fit an integer, and my compiler seems to promote it to "signed long long". Hence the bogus address. Cheers, diff --git a/xen/arch/arm/guest_walk.c b/xen/arch/arm/guest_walk.c index b258248322..6ca994e438 100644 --- a/xen/arch/arm/guest_walk.c +++ b/xen/arch/arm/guest_walk.c @@ -112,7 +112,7 @@ static int guest_walk_sd(const struct vcpu *v, * level translation table does not need to be page aligned. */ mask = GENMASK(19, 12); - paddr = (pte.walk.base << 10) | ((gva & mask) >> 10); + paddr = ((paddr_t)pte.walk.base << 10) | ((gva & mask) >> 10); /* Access the guest's memory to read only one PTE. */ ret = access_guest_memory_by_ipa(d, paddr, &pte, sizeof(short_desc_t), false);