[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen staging] x86/domain: restrict context switch hooks for the idle domain



commit 0d3bb3c98bc99ec1c84ebb3df71b6e18daebff4f
Author:     Grygorii Strashko <grygorii_strashko@xxxxxxxx>
AuthorDate: Thu Oct 1 15:23:22 2026 +0200
Commit:     Roger Pau Monne <roger@xxxxxxxxxxxxxx>
CommitDate: Wed Oct 7 15:21:40 2026 +0200

    x86/domain: restrict context switch hooks for the idle domain
    
    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.
    
    Introduce a new poison value to be used in unreachable function hooks, and
    set the from/to fields of idle_csw to it.  Use a different value from the
    currently defined ones for easy differentiation.
    
    Signed-off-by: Grygorii Strashko <grygorii_strashko@xxxxxxxx>
    Signed-off-by: Roger Pau Monné <roger@xxxxxxxxxxxxxx>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
---
 xen/arch/x86/domain.c             | 4 ++--
 xen/arch/x86/include/asm/config.h | 3 +++
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index 996b50af7a..6ebe6c5052 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -813,8 +813,8 @@ 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,
+        .from = FUNCTION_POISON,
+        .to   = FUNCTION_POISON,
         .tail = idle_loop,
     };
 
diff --git a/xen/arch/x86/include/asm/config.h 
b/xen/arch/x86/include/asm/config.h
index 1b28349a42..bf82cd082a 100644
--- a/xen/arch/x86/include/asm/config.h
+++ b/xen/arch/x86/include/asm/config.h
@@ -56,6 +56,9 @@
 #define LIST_POISON1  ((void *)0x0100100100100100UL)
 #define LIST_POISON2  ((void *)0x0200200200200200UL)
 
+/* Poison unreachable function hooks with a non-canonical value. */
+#define FUNCTION_POISON ((void *)0xDEAD0000DEAD0000UL)
+
 #include <xen/const.h>
 
 #define PML4_ENTRY_BITS  39
--
generated by git-patchbot for /home/xen/git/xen.git#staging



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.