From: Ian Campbell Subject: Re: [Xen-ARM: Linux] Grant table address, xen_hvm_resume_frames, is a phys_addr not a pfn Date: Tue, 3 Dec 2013 10:04:23 +0000 Message-ID: <1386065063.16012.52.camel@kazak.uk.xensource.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1VnmqB-0001vt-R3 for xen-devel@lists.xenproject.org; Tue, 03 Dec 2013 10:04:28 +0000 In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Eric Trudeau Cc: "xen-devel@lists.xenproject.org" , Stefano Stabellini , David Vrabel List-Id: xen-devel@lists.xenproject.org On Mon, 2013-12-02 at 21:25 +0000, Eric Trudeau wrote: > While working on our embedded ARM platform, we discovered a bug in the XEN > Linux ARM code where the grant table is being mapped into guest physical > memory at the wrong address because enlighten.c treats the > xen_hvm_resume_frames variable as if it was a pfn when, in fact, it is a physical > address. Thus, instead of the address specified in the hypervisor node of the > device tree, e.g. 0xB0000000, the actual guest physical address is 0x000B0000. > > Below is a _possible_ patch a developer from the Xen Linux team could try or > at least start from. The kernel that we are using is based on an > older version, but I have made this suggested patch on recent linux-stable code. > It is not tested on the latest linux-stable code, but it has been tested on linux as > of commit bee980d9e9642e96351fa3ca9077b853ecf62f57. > > Eric Trudeau > --- > XEN: Grant table address, xen_hvm_resume_frames, is a phys_addr not a pfn > > xen_hvm_resume_frames stores the physical address of the grant table. > englighten.c was incorrectly setting it as if it was a page frame number. > This caused the table to be mapped into the guest at an unexpected physical > address. > > Additionally, a warning is improved to include the grant table address which > failed in xen_remap. > > Signed-off-by: Eric Trudeau Agreed. Acked-by: Ian Campbell I also think that xen_hvm_resume_frames has a confusing name and an incorrect type (unsigned long). The name makes it sound like a frame number and the type should be either a paddr_t or a resource_size_t (a typedef to paddr_t, not obvious to me what the distinction is). Using unsigned long risks truncation of large MMIO addresses on 32-bit kernels. > --- > arch/arm/xen/enlighten.c | 4 ++-- > drivers/xen/grant-table.c | 2 +- > 2 files changed, 3 insertions(+), 3 deletions(-) > > diff --git a/arch/arm/xen/enlighten.c b/arch/arm/xen/enlighten.c > index 83e4f95..ceaf9d5 100644 > --- a/arch/arm/xen/enlighten.c > +++ b/arch/arm/xen/enlighten.c > @@ -224,10 +224,10 @@ static int __init xen_guest_init(void) > } > if (of_address_to_resource(node, GRANT_TABLE_PHYSADDR, &res)) > return 0; > - xen_hvm_resume_frames = res.start >> PAGE_SHIFT; > + xen_hvm_resume_frames = res.start; > xen_events_irq = irq_of_parse_and_map(node, 0); > pr_info("Xen %s support found, events_irq=%d gnttab_frame_pfn=%lx\n", > - version, xen_events_irq, xen_hvm_resume_frames); > + version, xen_events_irq, (xen_hvm_resume_frames >> PAGE_SHIFT)); > xen_domain_type = XEN_HVM_DOMAIN; > > xen_setup_features(); > diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c > index 62ccf54..0b4a741 100644 > --- a/drivers/xen/grant-table.c > +++ b/drivers/xen/grant-table.c > @@ -1174,7 +1174,7 @@ static int gnttab_setup(void) > gnttab_shared.addr = xen_remap(xen_hvm_resume_frames, > PAGE_SIZE * max_nr_gframes); > if (gnttab_shared.addr == NULL) { > - pr_warn("Failed to ioremap gnttab share frames!\n"); > + pr_warn("Failed to ioremap gnttab share frames (addr=0x%08lx)!\n", xen_hvm_resume_frames); > return -ENOMEM; > } > } > > > > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xen.org > http://lists.xen.org/xen-devel