Skip to contentSkip to conversation

xen/arm: Init traps very early

PATCH Superseded Julien Grall 3 participants 7 messages May 28, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/arm: Init traps very early

The function init_traps setups the handler taken when Xen hits a BUG_ON/ASSERT.

If an error happen before init_traps is called, we loose the backtrace.

As the function doesn't require any specific setup, we can call it just after Xen has jumped in C code.

---
 xen/arch/arm/setup.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
xen/arch/arm/setup.c +1 -2
index b9ce7a9..5bf8686 100644
@@ -666,6 +666,7 @@ void __init start_xen(unsigned long boot_phys_offset,
     struct domain *dom0;
 
     setup_cache();
+    init_traps();
 
     percpu_init_areas();
     set_processor_id(0); /* needed early, for smp_processor_id() */
@@ -709,8 +710,6 @@ void __init start_xen(unsigned long boot_phys_offset,
     set_current((struct vcpu *)0xfffff000); /* debug sanity */
     idle_vcpu[0] = current;
 
-    init_traps();
-
     setup_virt_paging();
 
     p2m_vmid_allocator_init();
Signature · 1 line
1.7.10.4
#1 lore raw

Tested/Acked by: Naresh Bhat <[email protected]>

Quoted 35 lines · Julien Grall

The function init_traps setups the handler taken when Xen hits a BUG_ON/ASSERT.

If an error happen before init_traps is called, we loose the backtrace.

As the function doesn't require any specific setup, we can call it just after Xen has jumped in C code.

---
 xen/arch/arm/setup.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
xen/arch/arm/setup.c +1 -3
index b9ce7a9..5bf8686 100644
@@ -666,6 +666,7 @@ void __init start_xen(unsigned long boot_phys_offset,
     struct domain *dom0;
 
     setup_cache();
+    init_traps();
 
     percpu_init_areas();
     set_processor_id(0); /* needed early, for smp_processor_id() */
@@ -709,8 +710,6 @@ void __init start_xen(unsigned long boot_phys_offset,
     set_current((struct vcpu *)0xfffff000); /* debug sanity */
     idle_vcpu[0] = current;
 
-    init_traps();
-
     setup_virt_paging();
 
     p2m_vmid_allocator_init();
--
Quoted 3 lines

1.7.10.4

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#2 lore raw
In reply to Julien Grall
Quoted 17 lines · Julien Grall

The function init_traps setups the handler taken when Xen hits a BUG_ON/ASSERT.

If an error happen before init_traps is called, we loose the backtrace.

As the function doesn't require any specific setup, we can call it just after Xen has jumped in C code.

---
 xen/arch/arm/setup.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
xen/arch/arm/setup.c +0 -0
index b9ce7a9..5bf8686 100644

xen/arch/arm/setup.c void __init start_xen(unsigned long boot_phys_offset, · line 669

Quoted 4 lines
xen/arch/arm/setup.c +1 -0
@@ -666,6 +666,7 @@ void __init start_xen(unsigned long boot_phys_offset,
     struct domain *dom0;
 
     setup_cache();
+    init_traps();

Having recently redone this in x86, it must be after set_processor_id(0), set_current() for debug sanity, and after percpu_init_areas() for future proofing.

~Andrew

Quoted 12 lines
xen/arch/arm/setup.c +0 -2
     percpu_init_areas();
     set_processor_id(0); /* needed early, for smp_processor_id() */
@@ -709,8 +710,6 @@ void __init start_xen(unsigned long boot_phys_offset,
     set_current((struct vcpu *)0xfffff000); /* debug sanity */
     idle_vcpu[0] = current;
 
-    init_traps();
-
     setup_virt_paging();
 
     p2m_vmid_allocator_init();
#3 lore raw

Hi Andrew,

Quoted 20 lines · Andrew Cooper
Quoted 19 lines · Julien Grall

The function init_traps setups the handler taken when Xen hits a BUG_ON/ASSERT.

If an error happen before init_traps is called, we loose the backtrace.

As the function doesn't require any specific setup, we can call it just after Xen has jumped in C code.

---
 xen/arch/arm/setup.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
xen/arch/arm/setup.c +0 -0
index b9ce7a9..5bf8686 100644
@@ -666,6 +666,7 @@ void __init start_xen(unsigned long boot_phys_offset,
     struct domain *dom0;
 
Quoted 6 lines

xen/arch/arm/setup.c void __init start_xen(unsigned long boot_phys_offset, · line 669

Quoted 2 lines
xen/arch/arm/setup.c +1 -0
     setup_cache();
+    init_traps();

Having recently redone this in x86, it must be after set_processor_id(0), set_current() for debug sanity, and after percpu_init_areas() for future proofing.

Even though it doesn't harm to call before (the stack will be corrupted), I agree to call init_traps after set_processor_id(0), and therefore percpu_init_areas.

But we don't need to have set_current correctly set up. The trap entries won't save anything about the guest if the exception are taken from HYP mode.

Signature · 1 line
Julien Grall
#4 lore raw
Quoted 28 lines · Julien Grall

Hi Andrew,

Quoted 20 lines · Andrew Cooper
Quoted 19 lines · Julien Grall

The function init_traps setups the handler taken when Xen hits a BUG_ON/ASSERT.

If an error happen before init_traps is called, we loose the backtrace.

As the function doesn't require any specific setup, we can call it just after Xen has jumped in C code.

---
 xen/arch/arm/setup.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
xen/arch/arm/setup.c +0 -0
index b9ce7a9..5bf8686 100644
@@ -666,6 +666,7 @@ void __init start_xen(unsigned long boot_phys_offset,
     struct domain *dom0;
 
Quoted 5 lines

xen/arch/arm/setup.c void __init start_xen(unsigned long boot_phys_offset, · line 669

Quoted 2 lines
xen/arch/arm/setup.c +1 -0
     setup_cache();
+    init_traps();

Having recently redone this in x86, it must be after set_processor_id(0), set_current() for debug sanity, and after percpu_init_areas() for future proofing.

Quoted 8 lines

Even though it doesn't harm to call before (the stack will be corrupted), I agree to call init_traps after set_processor_id(0), and therefore percpu_init_areas.

But we don't need to have set_current correctly set up. The trap entries won't save anything about the guest if the exception are taken from HYP mode.

set_current((struct vcpu *)0xfffff000); /* debug sanity */

This is designed to force a pagefault if a trap handler tries to use current before current is a valid vcpu. It is a debugging measure rather than a functional one, and does pick up issues.

~Andrew

#5 lore raw
Quoted 38 lines · Andrew Cooper
Quoted 28 lines · Julien Grall

Hi Andrew,

Quoted 20 lines · Andrew Cooper
Quoted 19 lines · Julien Grall

The function init_traps setups the handler taken when Xen hits a BUG_ON/ASSERT.

If an error happen before init_traps is called, we loose the backtrace.

As the function doesn't require any specific setup, we can call it just after Xen has jumped in C code.

---
 xen/arch/arm/setup.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
xen/arch/arm/setup.c +0 -0
index b9ce7a9..5bf8686 100644
@@ -666,6 +666,7 @@ void __init start_xen(unsigned long boot_phys_offset,
     struct domain *dom0;
 
Quoted 5 lines

xen/arch/arm/setup.c void __init start_xen(unsigned long boot_phys_offset, · line 669

Quoted 2 lines
xen/arch/arm/setup.c +1 -0
     setup_cache();
+    init_traps();

Having recently redone this in x86, it must be after set_processor_id(0), set_current() for debug sanity, and after percpu_init_areas() for future proofing.

Quoted 8 lines

Even though it doesn't harm to call before (the stack will be corrupted), I agree to call init_traps after set_processor_id(0), and therefore percpu_init_areas.

But we don't need to have set_current correctly set up. The trap entries won't save anything about the guest if the exception are taken from HYP mode.

Quoted 5 lines

set_current((struct vcpu *)0xfffff000); /* debug sanity */

This is designed to force a pagefault if a trap handler tries to use current before current is a valid vcpu. It is a debugging measure rather than a functional one, and does pick up issues.

At this stage if we hit a trap it's mostly for a data abort, alignment issue, undefined instruction. *none* of them if using current.

I prefer to move init_traps earlier and get useful call stack 95% of the time, rather than loosing it for the sack of debug sanity.

It's very painful to debug when the ASSERT is in the header and can be called on multiple place.

Regards,

Signature · 1 line
Julien Grall
#6 lore raw
Quoted 46 lines · Julien Grall
Quoted 37 lines · Andrew Cooper
Quoted 28 lines · Julien Grall

Hi Andrew,

Quoted 20 lines · Andrew Cooper
Quoted 19 lines · Julien Grall

The function init_traps setups the handler taken when Xen hits a BUG_ON/ASSERT.

If an error happen before init_traps is called, we loose the backtrace.

As the function doesn't require any specific setup, we can call it just after Xen has jumped in C code.

---
 xen/arch/arm/setup.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
xen/arch/arm/setup.c +0 -0
index b9ce7a9..5bf8686 100644
@@ -666,6 +666,7 @@ void __init start_xen(unsigned long boot_phys_offset,
     struct domain *dom0;
 
Quoted 5 lines

xen/arch/arm/setup.c void __init start_xen(unsigned long boot_phys_offset, · line 669

Quoted 2 lines
xen/arch/arm/setup.c +1 -0
     setup_cache();
+    init_traps();

Having recently redone this in x86, it must be after set_processor_id(0), set_current() for debug sanity, and after percpu_init_areas() for future proofing.

Quoted 8 lines

Even though it doesn't harm to call before (the stack will be corrupted), I agree to call init_traps after set_processor_id(0), and therefore percpu_init_areas.

But we don't need to have set_current correctly set up. The trap entries won't save anything about the guest if the exception are taken from HYP mode.

Quoted 5 lines

set_current((struct vcpu *)0xfffff000); /* debug sanity */

This is designed to force a pagefault if a trap handler tries to use current before current is a valid vcpu. It is a debugging measure rather than a functional one, and does pick up issues.

At this stage if we hit a trap it's mostly for a data abort, alignment issue, undefined instruction. *none* of them if using current.

Quoted 8 lines

I prefer to move init_traps earlier and get useful call stack 95% of the time, rather than loosing it for the sack of debug sanity.

It's very painful to debug when the ASSERT is in the header and can be called on multiple place.

Regards,

You are guarding against changes in the future, not the current behaviour.

Having correctly set up per_cpu areas, processor IDs and 'current' are crucial before the trap handlers can be safely run in general.

In the end, set_processor_id(), set_current() and percpu_init_areas() are trivial operations which will not fault.

~Andrew