Grant table address, xen_hvm_resume_frames, is a phys_addr not a pfn
Subsystems (3)
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.
--- arch/arm/xen/enlighten.c | 4 ++-- drivers/xen/grant-table.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
arch/arm/xen/enlighten.c +2 -2
@@ -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 ();
drivers/xen/grant-table.c +1 -1
@@ -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 ; } }
Ian Campbell
Acked-byQuoted 22 lines · Eric Trudeau
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.ctreats thexen_hvm_resume_framesvariable 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 is0x000B0000.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 aphys_addrnot a pfn
xen_hvm_resume_framesstores the physical address of the grant table.englighten.cwas 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.
Quoted 4 lines
Additionally, a warning is improved to include the grant table address which failed in
xen_remap.Signed-off-by Eric Trudeau <[email protected]>
Agreed.
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.
Quoted 42 lines
--- arch/arm/xen/enlighten.c | 4 ++-- drivers/xen/grant-table.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)arch/arm/xen/enlighten.c +2
-2@@ -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 ();drivers/xen/grant-table.c +1
-1@@ -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
[email protected]
http://lists.xen.org/xen-devel
Quoted 23 lines · Ian Campbell
Quoted 22 lines · Eric Trudeau
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.ctreats thexen_hvm_resume_framesvariable 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 is0x000B0000.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 aphys_addrnot a pfn
xen_hvm_resume_framesstores the physical address of the grant table.englighten.cwas 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.
Quoted 8 lines
Quoted 4 lines
Additionally, a warning is improved to include the grant table address which failed in
xen_remap.Signed-off-by Eric Trudeau <[email protected]>Agreed.
Acked-by Ian Campbell <[email protected]>
Right, I'll add it to xentip.
Quoted 6 lines
I also think that
xen_hvm_resume_frameshas a confusing name and an incorrect type (unsigned long). The name makes it sound like a frame number and the type should be either apaddr_tor aresource_size_t(a typedef topaddr_t, not obvious to me what the distinction is). Using unsigned long risks truncation of large MMIO addresses on 32-bit kernels.
indeed
Quoted 44 lines
Quoted 42 lines
--- arch/arm/xen/enlighten.c | 4 ++-- drivers/xen/grant-table.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)arch/arm/xen/enlighten.c +2
-2@@ -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 ();drivers/xen/grant-table.c +1
-1@@ -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
[email protected]
http://lists.xen.org/xen-devel