@@ -54,11 +54,12 @@ static inline void monitor_ctrlreg_disable_traps(struct domain *d)
int monitor_init_domain(struct domain *d)
{
- if ( !d->arch.monitor.msr_bitmap )
+ if ( likely(!d->arch.monitor.msr_bitmap) )
+ {
d->arch.monitor.msr_bitmap = xzalloc(struct monitor_msr_bitmap);
-
- if ( !d->arch.monitor.msr_bitmap )
- return -ENOMEM;
+ if ( unlikely(!d->arch.monitor.msr_bitmap) )
+ return -ENOMEM;
+ }
return 0;
}
@@ -66,6 +67,7 @@ int monitor_init_domain(struct domain *d)
void monitor_cleanup_domain(struct domain *d)
{
xfree(d->arch.monitor.msr_bitmap);
+ d->arch.monitor.msr_bitmap = NULL;
monitor_ctrlreg_disable_traps(d);
Fix: set d->arch.monitor.msr_bitmap to NULL after xfree, as the equivalence of it being NULL and xfreed is repeatedly presumed in the codebase. Along with this change, also properly reposition an 'if' targeting the aforementioned msr_bitmap when it is allocated and add likely/unlikely accordingly. Signed-off-by: Corneliu ZUZU <czuzu@bitdefender.com> --- xen/arch/x86/monitor.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)