Skip to contentSkip to conversation

x86/domain: restrict context switch hooks for the idle domain

PATCH Superseded Roger Pau Monne 4 participants 12 messages Oct 1 – Oct 2

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/domain: restrict context switch hooks for the idle domain

From: Grygorii Strashko <[email protected]>

The arch_init_idle_domain() initializes struct arch_csw idle_csw as:

static const struct arch_csw idle_csw = {
.from = paravirt_ctxt_switch_from,
.to = paravirt_ctxt_switch_to,
.tail = idle_loop,
};

but only place where d->arch.ctxt_switch->{to,from}() are used is __context_switch() where they are both guarded by !is_idle_domain(pd) which makes the callbacks in idle_csw unreachable.

Drop to/from() callbacks initialization in idle_csw.

---
I don't think there's a suitable Fixes candidate here. The idle domain hooks used to piggyback on the PV ones, and commit ab914e04a6272 split those out into it's own structure. At that point the to/from hooks could have been left zeroed, but that wasn't the point of that commit anyway.

---
 xen/arch/x86/domain.c | 2 --
 1 file changed, 2 deletions(-)
xen/arch/x86/domain.c +0 -2
index 996b50af7a17..464ca6f39026 100644
@@ -813,8 +813,6 @@ static bool emulation_flags_ok(const struct domain *d, uint32_t emflags)
 void __init arch_init_idle_domain(struct domain *d)
 {
     static const struct arch_csw idle_csw = {
-        .from = paravirt_ctxt_switch_from,
-        .to   = paravirt_ctxt_switch_to,
         .tail = idle_loop,
     };
 
Signature · 1 line
2.55.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Roger Pau Monne

From: Grygorii Strashko <[email protected]>

The arch_init_idle_domain() initializes struct arch_csw idle_csw as:

static const struct arch_csw idle_csw = {
.from = paravirt_ctxt_switch_from,
.to = paravirt_ctxt_switch_to,
.tail = idle_loop,
};

Quoted 8 lines

but only place where d->arch.ctxt_switch->{to,from}() are used is __context_switch() where they are both guarded by !is_idle_domain(pd) which makes the callbacks in idle_csw unreachable.

Drop to/from() callbacks initialization in idle_csw.

Juergen

Reviewed-by on v1 1/1
#2 lore raw
In reply to Roger Pau Monne
Quoted 10 lines · Roger Pau Monne

From: Grygorii Strashko <[email protected]>

The arch_init_idle_domain() initializes struct arch_csw idle_csw as:

static const struct arch_csw idle_csw = {
.from = paravirt_ctxt_switch_from,
.to = paravirt_ctxt_switch_to,
.tail = idle_loop,
};

Quoted 8 lines

but only place where d->arch.ctxt_switch->{to,from}() are used is __context_switch() where they are both guarded by !is_idle_domain(pd) which makes the callbacks in idle_csw unreachable.

Drop to/from() callbacks initialization in idle_csw.

Thanks,
Jason

#3 lore raw
In reply to Roger Pau Monne

xen/arch/x86/domain.c static bool emulation_flags_ok(const struct domain *d, uint32_t emflags) · line 817

Quoted 10 lines · Roger Pau Monne
xen/arch/x86/domain.c +0 -2
@@ -813,8 +813,6 @@ static bool emulation_flags_ok(const struct domain *d, uint32_t emflags)
 void __init arch_init_idle_domain(struct domain *d)
 {
     static const struct arch_csw idle_csw = {
-        .from = paravirt_ctxt_switch_from,
-        .to   = paravirt_ctxt_switch_to,
         .tail = idle_loop,
     };

Leaving NULL pointers around isn't a good thing, though. May I suggest to at least poison the pointers then?

Jan

#4 lore raw
Quoted 14 lines · Jan Beulich

xen/arch/x86/domain.c static bool emulation_flags_ok(const struct domain *d, uint32_t emflags) · line 817

Quoted 10 lines · Roger Pau Monne
xen/arch/x86/domain.c +0 -2
@@ -813,8 +813,6 @@ static bool emulation_flags_ok(const struct domain *d, uint32_t emflags)
 void __init arch_init_idle_domain(struct domain *d)
 {
     static const struct arch_csw idle_csw = {
-        .from = paravirt_ctxt_switch_from,
-        .to   = paravirt_ctxt_switch_to,
         .tail = idle_loop,
     };

Leaving NULL pointers around isn't a good thing, though. May I suggest to at least poison the pointers then?

I don't mind doing so, but I don't think we usually do that for other hook structures, ie: hvm_function_table for example doesn't poison unset hooks (and it possibly can't, because there are .hook != NULL checks).

TBH I'm missing a benefit of the poisoning here. Using NULL or a poisoned value will both trigger a page-fault, and NULL has the benefit of callers easily checking whether the hook is set.

Thanks, Roger.

#5 lore raw
Quoted 16 lines · Roger Pau Monné
Quoted 14 lines · Jan Beulich

xen/arch/x86/domain.c static bool emulation_flags_ok(const struct domain *d, uint32_t emflags) · line 817

Quoted 10 lines · Roger Pau Monne
xen/arch/x86/domain.c +0 -2
@@ -813,8 +813,6 @@ static bool emulation_flags_ok(const struct domain *d, uint32_t emflags)
 void __init arch_init_idle_domain(struct domain *d)
 {
     static const struct arch_csw idle_csw = {
-        .from = paravirt_ctxt_switch_from,
-        .to   = paravirt_ctxt_switch_to,
         .tail = idle_loop,
     };

Leaving NULL pointers around isn't a good thing, though. May I suggest to at least poison the pointers then?

Quoted 8 lines

I don't mind doing so, but I don't think we usually do that for other hook structures, ie: hvm_function_table for example doesn't poison unset hooks (and it possibly can't, because there are .hook != NULL checks).

TBH I'm missing a benefit of the poisoning here. Using NULL or a poisoned value will both trigger a page-fault, and NULL has the benefit of callers easily checking whether the hook is set.

NULL in the context of a HVM vCPU will #PF. NULL in the context of a PV one may not, depending on what the guest may have put there.

Jan

#6 lore raw
Quoted 22 lines · Jan Beulich
Quoted 21 lines · Roger Pau Monné
Quoted 14 lines · Jan Beulich

xen/arch/x86/domain.c static bool emulation_flags_ok(const struct domain *d, uint32_t emflags) · line 817

Quoted 10 lines · Roger Pau Monne
xen/arch/x86/domain.c +0 -2
@@ -813,8 +813,6 @@ static bool emulation_flags_ok(const struct domain *d, uint32_t emflags)
 void __init arch_init_idle_domain(struct domain *d)
 {
     static const struct arch_csw idle_csw = {
-        .from = paravirt_ctxt_switch_from,
-        .to   = paravirt_ctxt_switch_to,
         .tail = idle_loop,
     };

Leaving NULL pointers around isn't a good thing, though. May I suggest to at least poison the pointers then?

I don't mind doing so, but I don't think we usually do that for other hook structures, ie: hvm_function_table for example doesn't poison unset hooks (and it possibly can't, because there are .hook != NULL checks).

Quoted 6 lines
Quoted 3 lines

TBH I'm missing a benefit of the poisoning here. Using NULL or a poisoned value will both trigger a page-fault, and NULL has the benefit of callers easily checking whether the hook is set.

NULL in the context of a HVM vCPU will #PF. NULL in the context of a PV one may not, depending on what the guest may have put there.

It still feels a bit arbitrary to do here but not in other places, but never mind, I will adjust and send v2.

Thanks, Roger.

#7 lore raw
Quoted 23 lines · Roger Pau Monné
Quoted 22 lines · Jan Beulich
Quoted 21 lines · Roger Pau Monné
Quoted 14 lines · Jan Beulich

xen/arch/x86/domain.c static bool emulation_flags_ok(const struct domain *d, uint32_t emflags) · line 817

Quoted 10 lines · Roger Pau Monne
xen/arch/x86/domain.c +0 -2
@@ -813,8 +813,6 @@ static bool emulation_flags_ok(const struct domain *d, uint32_t emflags)
 void __init arch_init_idle_domain(struct domain *d)
 {
     static const struct arch_csw idle_csw = {
-        .from = paravirt_ctxt_switch_from,
-        .to   = paravirt_ctxt_switch_to,
         .tail = idle_loop,
     };

Leaving NULL pointers around isn't a good thing, though. May I suggest to at least poison the pointers then?

I don't mind doing so, but I don't think we usually do that for other hook structures, ie: hvm_function_table for example doesn't poison unset hooks (and it possibly can't, because there are .hook != NULL checks).

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

TBH I'm missing a benefit of the poisoning here. Using NULL or a poisoned value will both trigger a page-fault, and NULL has the benefit of callers easily checking whether the hook is set.

NULL in the context of a HVM vCPU will #PF. NULL in the context of a PV one may not, depending on what the guest may have put there.

It still feels a bit arbitrary to do here but not in other places,

We should imo resolve this by replacing NULLs wherever hooks could, due to other issues, end up "in sight" on paths reachable for PV guests. This would then also cover potential speculation along such paths.

Quoted 1 line

but never mind, I will adjust and send v2.

Thanks.

Jan

#8 lore raw
Quoted 28 lines · Jan Beulich
Quoted 27 lines · Roger Pau Monné
Quoted 26 lines · Jan Beulich
Quoted 24 lines · Roger Pau Monné
Quoted 14 lines · Jan Beulich

xen/arch/x86/domain.c static bool emulation_flags_ok(const struct domain *d, uint32_t emflags) · line 817

Quoted 10 lines · Roger Pau Monne
xen/arch/x86/domain.c +0 -2
@@ -813,8 +813,6 @@ static bool emulation_flags_ok(const struct domain *d, uint32_t emflags)
 void __init arch_init_idle_domain(struct domain *d)
 {
     static const struct arch_csw idle_csw = {
-        .from = paravirt_ctxt_switch_from,
-        .to   = paravirt_ctxt_switch_to,
         .tail = idle_loop,
     };

Leaving NULL pointers around isn't a good thing, though. May I suggest to at least poison the pointers then?

I don't mind doing so, but I don't think we usually do that for other hook structures, ie: hvm_function_table for example doesn't poison unset hooks (and it possibly can't, because there are .hook != NULL checks).

TBH I'm missing a benefit of the poisoning here. Using NULL or a poisoned value will both trigger a page-fault, and NULL has the benefit of callers easily checking whether the hook is set.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

NULL in the context of a HVM vCPU will #PF. NULL in the context of a PV one may not, depending on what the guest may have put there.

It still feels a bit arbitrary to do here but not in other places,

We should imo resolve this by replacing NULLs wherever hooks could, due to other issues, end up "in sight" on paths reachable for PV guests. This would then also cover potential speculation along such paths.

FTAOD, I plan to introduce a poison value using a non-canonical address, ie:

#define POINTER_POISON ((void *)0xDEAD0000DEAD0000UL)

in asm/config.h.

Would that be acceptable?

Thanks, Roger.

#9 lore raw
Quoted 34 lines · Roger Pau Monné
Quoted 33 lines · Jan Beulich
Quoted 31 lines · Roger Pau Monné
Quoted 22 lines · Jan Beulich
Quoted 21 lines · Roger Pau Monné
Quoted 14 lines · Jan Beulich

xen/arch/x86/domain.c static bool emulation_flags_ok(const struct domain *d, uint32_t emflags) · line 817

Quoted 10 lines · Roger Pau Monne
xen/arch/x86/domain.c +0 -2
@@ -813,8 +813,6 @@ static bool emulation_flags_ok(const struct domain *d, uint32_t emflags)
 void __init arch_init_idle_domain(struct domain *d)
 {
     static const struct arch_csw idle_csw = {
-        .from = paravirt_ctxt_switch_from,
-        .to   = paravirt_ctxt_switch_to,
         .tail = idle_loop,
     };

Leaving NULL pointers around isn't a good thing, though. May I suggest to at least poison the pointers then?

I don't mind doing so, but I don't think we usually do that for other hook structures, ie: hvm_function_table for example doesn't poison unset hooks (and it possibly can't, because there are .hook != NULL checks).

Quoted 6 lines
Quoted 3 lines

TBH I'm missing a benefit of the poisoning here. Using NULL or a poisoned value will both trigger a page-fault, and NULL has the benefit of callers easily checking whether the hook is set.

NULL in the context of a HVM vCPU will #PF. NULL in the context of a PV one may not, depending on what the guest may have put there.

It still feels a bit arbitrary to do here but not in other places,

Quoted 8 lines
Quoted 3 lines

We should imo resolve this by replacing NULLs wherever hooks could, due to other issues, end up "in sight" on paths reachable for PV guests. This would then also cover potential speculation along such paths.

FTAOD, I plan to introduce a poison value using a non-canonical address, ie:

#define POINTER_POISON ((void *)0xDEAD0000DEAD0000UL)

s/POINTER_POISON/FUNCTION_POISON/

#10 lore raw
Quoted 39 lines · Roger Pau Monné
Quoted 38 lines · Roger Pau Monné
Quoted 36 lines · Jan Beulich
Quoted 23 lines · Roger Pau Monné
Quoted 22 lines · Jan Beulich
Quoted 21 lines · Roger Pau Monné
Quoted 14 lines · Jan Beulich

xen/arch/x86/domain.c static bool emulation_flags_ok(const struct domain *d, uint32_t emflags) · line 817

Quoted 10 lines · Roger Pau Monne
xen/arch/x86/domain.c +0 -2
@@ -813,8 +813,6 @@ static bool emulation_flags_ok(const struct domain *d, uint32_t emflags)
 void __init arch_init_idle_domain(struct domain *d)
 {
     static const struct arch_csw idle_csw = {
-        .from = paravirt_ctxt_switch_from,
-        .to   = paravirt_ctxt_switch_to,
         .tail = idle_loop,
     };

Leaving NULL pointers around isn't a good thing, though. May I suggest to at least poison the pointers then?

I don't mind doing so, but I don't think we usually do that for other hook structures, ie: hvm_function_table for example doesn't poison unset hooks (and it possibly can't, because there are .hook != NULL checks).

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

TBH I'm missing a benefit of the poisoning here. Using NULL or a poisoned value will both trigger a page-fault, and NULL has the benefit of callers easily checking whether the hook is set.

NULL in the context of a HVM vCPU will #PF. NULL in the context of a PV one may not, depending on what the guest may have put there.

It still feels a bit arbitrary to do here but not in other places,

We should imo resolve this by replacing NULLs wherever hooks could, due to other issues, end up "in sight" on paths reachable for PV guests. This would then also cover potential speculation along such paths.

Quoted 6 lines
Quoted 4 lines

FTAOD, I plan to introduce a poison value using a non-canonical address, ie:

#define POINTER_POISON ((void *)0xDEAD0000DEAD0000UL)

s/POINTER_POISON/FUNCTION_POISON/

Sure, if you think none of the present poisoning values we have is good to reuse here.

Jan

#11 lore raw
Quoted 43 lines · Jan Beulich
Quoted 42 lines · Roger Pau Monné
Quoted 41 lines · Roger Pau Monné
Quoted 28 lines · Jan Beulich
Quoted 27 lines · Roger Pau Monné
Quoted 26 lines · Jan Beulich
Quoted 24 lines · Roger Pau Monné
Quoted 14 lines · Jan Beulich

xen/arch/x86/domain.c static bool emulation_flags_ok(const struct domain *d, uint32_t emflags) · line 817

Quoted 10 lines · Roger Pau Monne
xen/arch/x86/domain.c +0 -2
@@ -813,8 +813,6 @@ static bool emulation_flags_ok(const struct domain *d, uint32_t emflags)
 void __init arch_init_idle_domain(struct domain *d)
 {
     static const struct arch_csw idle_csw = {
-        .from = paravirt_ctxt_switch_from,
-        .to   = paravirt_ctxt_switch_to,
         .tail = idle_loop,
     };

Leaving NULL pointers around isn't a good thing, though. May I suggest to at least poison the pointers then?

I don't mind doing so, but I don't think we usually do that for other hook structures, ie: hvm_function_table for example doesn't poison unset hooks (and it possibly can't, because there are .hook != NULL checks).

TBH I'm missing a benefit of the poisoning here. Using NULL or a poisoned value will both trigger a page-fault, and NULL has the benefit of callers easily checking whether the hook is set.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

NULL in the context of a HVM vCPU will #PF. NULL in the context of a PV one may not, depending on what the guest may have put there.

It still feels a bit arbitrary to do here but not in other places,

We should imo resolve this by replacing NULLs wherever hooks could, due to other issues, end up "in sight" on paths reachable for PV guests. This would then also cover potential speculation along such paths.

FTAOD, I plan to introduce a poison value using a non-canonical address, ie:

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

#define POINTER_POISON ((void *)0xDEAD0000DEAD0000UL)

s/POINTER_POISON/FUNCTION_POISON/

Sure, if you think none of the present poisoning values we have is good to reuse here.

They maybe could, but I assumed we wanted differentiation between this usage and ZERO_BLOCK_PTR for example.

Thanks, Roger.