All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: Penny Zheng <Penny.Zheng@amd.com>
Cc: ray.huang@amd.com, oleksii.kurochko@gmail.com,
	"Andrew Cooper" <andrew.cooper3@citrix.com>,
	"Roger Pau Monné" <roger.pau@citrix.com>,
	"Tamas K Lengyel" <tamas@tklengyel.com>,
	"Alexandru Isaila" <aisaila@bitdefender.com>,
	"Petre Pircalabu" <ppircalabu@bitdefender.com>,
	xen-devel@lists.xenproject.org
Subject: Re: [PATCH v3 08/28] xen/vm_event: introduce vm_event_is_enabled()
Date: Wed, 29 Oct 2025 16:02:22 +0100	[thread overview]
Message-ID: <23426fe7-533a-4ffc-9ad5-a620f2ac0cfc@suse.com> (raw)
In-Reply-To: <20251013101540.3502842-9-Penny.Zheng@amd.com>

On 13.10.2025 12:15, Penny Zheng wrote:
> @@ -2340,6 +2341,7 @@ int hvm_set_cr0(unsigned long value, bool may_defer)
>           (value & (X86_CR0_PE | X86_CR0_PG)) == X86_CR0_PG )
>          return X86EMUL_EXCEPTION;
>  
> +    may_defer &= vm_event_is_enabled(v);

I think this wants to move to the very top of the function, so that it's clear
that all uses (current and future) in the function are covered. Same for the
sibling functions, of course.

> @@ -3544,6 +3548,7 @@ int hvm_vmexit_cpuid(struct cpu_user_regs *regs, unsigned int inst_len)
>      struct vcpu *curr = current;
>      unsigned int leaf = regs->eax, subleaf = regs->ecx;
>      struct cpuid_leaf res;
> +    int ret = 0;
>  
>      if ( curr->arch.msrs->misc_features_enables.cpuid_faulting &&
>           hvm_get_cpl(curr) > 0 )
> @@ -3560,7 +3565,10 @@ int hvm_vmexit_cpuid(struct cpu_user_regs *regs, unsigned int inst_len)
>      regs->rcx = res.c;
>      regs->rdx = res.d;
>  
> -    return hvm_monitor_cpuid(inst_len, leaf, subleaf);
> +    if ( vm_event_is_enabled(curr) )
> +        ret = hvm_monitor_cpuid(inst_len, leaf, subleaf);
> +
> +    return ret;

Just to mention, could also do without a new local variable:

    return vm_event_is_enabled(curr)
           ? hvm_monitor_cpuid(inst_len, leaf, subleaf)
           : 0;

> @@ -3860,9 +3869,11 @@ int hvm_descriptor_access_intercept(uint64_t exit_info,
>      struct vcpu *curr = current;
>      struct domain *currd = curr->domain;
>  
> -    if ( currd->arch.monitor.descriptor_access_enabled )
> +    if ( currd->arch.monitor.descriptor_access_enabled &&
> +         vm_event_is_enabled(curr) )

While functionally it won't matter, logically this looks the wrong way round.
In principle I'd expect the "monitor" field to also disappear when VM_EVENT=n,
at which point the order will need to be the other way around anyway (as the
explicit CONFIG_VM_EVENT then needs to come first).

>      {
>          ASSERT(curr->arch.vm_event);
> +
>          hvm_monitor_descriptor_access(exit_info, vmx_exit_qualification,
>                                        descriptor, is_write);
>      }

Stray change (especially in an already big patch)?

> @@ -2551,7 +2552,7 @@ void asmlinkage svm_vmexit_handler(void)
>      uint64_t exit_reason;
>      struct vcpu *v = current;
>      struct vmcb_struct *vmcb = v->arch.hvm.svm.vmcb;
> -    int insn_len, rc;
> +    int insn_len, rc = 0;

This is almost 200 lines apart from ...

> @@ -2720,11 +2721,14 @@ void asmlinkage svm_vmexit_handler(void)
>                      break;
>              }
>  
> -            rc = hvm_monitor_debug(regs->rip,
> -                                   HVM_MONITOR_DEBUG_EXCEPTION,
> -                                   trap_type, insn_len, 0);
> -            if ( rc < 0 )
> -                goto unexpected_exit_type;
> +            if ( vm_event_is_enabled(v) )
> +            {
> +                rc = hvm_monitor_debug(regs->rip,
> +                                       HVM_MONITOR_DEBUG_EXCEPTION,
> +                                       trap_type, insn_len, 0);
> +                if ( rc < 0 )
> +                    goto unexpected_exit_type;
> +            }
>              if ( !rc )
>                  hvm_inject_exception(X86_EXC_DB,
>                                       trap_type, insn_len, X86_EVENT_NO_EC);

... where it first comes into play. I wonder whether the initialization
wouldn't better move closer, also for the code to be less fragile going
forward (where a new earlier use of rc might easily appear). Or, like VMX
code has it, limit the scope of "rc" (requiring several instances then in
relatively narrow scopes).

> --- a/xen/arch/x86/include/asm/vm_event.h
> +++ b/xen/arch/x86/include/asm/vm_event.h
> @@ -45,4 +45,13 @@ void vm_event_sync_event(struct vcpu *v, bool value);
>  
>  void vm_event_reset_vmtrace(struct vcpu *v);
>  
> +static inline bool vm_event_is_enabled(struct vcpu *v)

Pointer-to-const please for (almost?) all predicate-like functions.

> +{
> +#ifdef CONFIG_VM_EVENT
> +    return v->arch.vm_event != NULL;
> +#else
> +    return false;
> +#endif
> +}

As long a vm_event is always a member of struct arch_vcpu, IS_ENABLED() should
be sufficient here? Or did you merely forget to add an #ifdef around the field
as well? Albeit I realize that would break with e.g. the use in
hvmemul_rep_outs_set_context(). Otoh that function (and likely others there)
should be compiled out when VM_EVENT=n. Maybe that's the subject of the next
patch ...

Jan


  parent reply	other threads:[~2025-10-29 15:02 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-13 10:15 [PATCH v3 00/28] Disable domctl-op via CONFIG_MGMT_HYPERCALLS Penny Zheng
2025-10-13 10:15 ` [PATCH v3 01/28] xen/xsm: remove redundant xsm_iomem_mapping() Penny Zheng
2025-10-13 11:18   ` Jan Beulich
2025-10-13 10:15 ` [PATCH v3 02/28] xen/mem_sharing: wrap hvm_copy_context_and_params() with CONFIG_MEM_SHARING Penny Zheng
2025-10-14 14:43   ` Grygorii Strashko
2025-10-28 17:01   ` Jan Beulich
2025-10-13 10:15 ` [PATCH v3 03/28] xen/altp2m: move p2m_set_suppress_ve_multi() forward Penny Zheng
2025-10-28 17:03   ` Jan Beulich
2025-10-13 10:15 ` [PATCH v3 04/28] xen/sched: remove vcpu_set_soft_affinity() Penny Zheng
2025-10-13 10:24   ` Jürgen Groß
2025-10-13 10:15 ` [PATCH v3 05/28] xen/sysctl: replace CONFIG_SYSCTL with CONFIG_MGMT_DOMCTL Penny Zheng
2025-10-13 10:41   ` Jürgen Groß
2025-10-29 14:30   ` Jan Beulich
2025-10-29 21:26   ` Stewart Hildebrand
2025-11-19  6:33     ` Penny, Zheng
2025-10-13 10:15 ` [PATCH v3 06/28] xen/x86: move domctl.o out of PV_SHIM_EXCLUSIVE Penny Zheng
2025-10-29 14:33   ` Jan Beulich
2025-10-13 10:15 ` [PATCH v3 07/28] xen/domctl: make MGMT_HYPERCALLS transiently def_bool Penny Zheng
2025-10-29 14:37   ` Jan Beulich
2025-10-13 10:15 ` [PATCH v3 09/28] xen/vm_event: consolidate CONFIG_VM_EVENT Penny Zheng
2025-10-21 13:24   ` Grygorii Strashko
2025-10-29 15:57   ` Jan Beulich
2025-11-11  7:08     ` Penny, Zheng
2025-11-11  8:13       ` Jan Beulich
2025-11-11  9:46         ` Penny, Zheng
2025-10-13 10:15 ` [PATCH v3 10/28] xen/vm_event: make VM_EVENT depend on CONFIG_MGMT_HYPERCALLS Penny Zheng
2025-10-13 10:15 ` [PATCH v3 11/28] xen/xsm: wrap xsm_vm_event_control() with CONFIG_VM_EVENT Penny Zheng
2025-10-13 10:15 ` [PATCH v3 12/28] xen/domctl: wrap domain_pause_by_systemcontroller() with MGMT_HYPERCALLS Penny Zheng
2025-10-30 11:28   ` Jan Beulich
2025-10-13 10:15 ` [PATCH v3 13/28] xen/domctl: wrap domain_soft_reset() with CONFIG_MGMT_HYPERCALLS Penny Zheng
2025-10-30 12:14   ` Jan Beulich
2025-10-13 10:15 ` [PATCH v3 14/28] xen/domctl: wrap domain_resume() " Penny Zheng
2025-10-13 10:15 ` [PATCH v3 15/28] xen/domctl: wrap domain_kill() " Penny Zheng
2025-10-30 12:43   ` Jan Beulich
2025-11-12  8:58     ` Penny, Zheng
2025-11-12 10:02       ` Jan Beulich
2025-11-13  4:11         ` Penny, Zheng
2025-11-13  4:40     ` Penny, Zheng
2025-10-13 10:15 ` [PATCH v3 16/28] xen/domctl: wrap domain_set_node_affinity() " Penny Zheng
2025-10-13 10:15 ` [PATCH v3 17/28] xen/domctl: wrap vcpu_affinity_domctl() " Penny Zheng
2025-10-13 10:44   ` Jürgen Groß
2025-10-13 10:15 ` [PATCH v3 18/28] xen/domctl: wrap sched_adjust() " Penny Zheng
2025-10-13 11:03   ` Jürgen Groß
2025-10-13 11:13     ` Jan Beulich
2025-10-13 10:15 ` [PATCH v3 19/28] xen/domctl: wrap xsm_irq_permission " Penny Zheng
2025-10-13 10:15 ` [PATCH v3 20/28] xen/domctl: wrap arch-specific domain_set_time_offset() " Penny Zheng
2025-10-13 10:15 ` [PATCH v3 21/28] xen/domctl: wrap xsm_set_target() " Penny Zheng
2025-10-13 10:15 ` [PATCH v3 22/28] xen/domctl: wrap iommu-related domctl op " Penny Zheng
2025-10-30 13:09   ` Jan Beulich
2025-10-13 10:15 ` [PATCH v3 23/28] xen/domctl: wrap arch_{get,set}_paging_mempool_size() " Penny Zheng
2025-10-13 10:15 ` [PATCH v3 24/28] xen/domctl: make CONFIG_X86_PSR depend on CONFIG_MGMT_HYPERCALLS Penny Zheng
2025-10-13 10:15 ` [PATCH v3 25/28] xen/domctl: avoid unreachable codes when both MGMT_HYPERCALLS and MEM_SHARING unset Penny Zheng
2025-10-30 13:13   ` Jan Beulich
2025-10-13 10:15 ` [PATCH v3 26/28] xen/domctl: wrap arch-specific domctl-op with CONFIG_MGMT_HYPERCALLS Penny Zheng
2025-10-30 13:24   ` Jan Beulich
2025-10-13 10:15 ` [PATCH v3 27/28] xen/domctl: make HVM_PARAM_IDENT_PT conditional upon CONFIG_MGMT_HYPERCALLS Penny Zheng
2025-10-30 13:34   ` Jan Beulich
2025-11-18  6:45     ` Penny, Zheng
2025-11-18  7:12       ` Jan Beulich
2025-10-13 10:15 ` [PATCH v3 28/28] xen/domctl: wrap common/domctl.c with CONFIG_MGMT_HYPERCALLS Penny Zheng
2025-10-30 13:40   ` Jan Beulich
2025-11-18  6:43     ` Penny, Zheng
2025-11-18  7:14       ` Jan Beulich
2025-11-18  7:51         ` Penny, Zheng
2025-11-18 19:29           ` Jason Andryuk
2025-11-20  4:09             ` Penny, Zheng
     [not found] ` <20251013101540.3502842-9-Penny.Zheng@amd.com>
2025-10-29 15:02   ` Jan Beulich [this message]
2025-10-30 11:10     ` [PATCH v3 08/28] xen/vm_event: introduce vm_event_is_enabled() Grygorii Strashko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=23426fe7-533a-4ffc-9ad5-a620f2ac0cfc@suse.com \
    --to=jbeulich@suse.com \
    --cc=Penny.Zheng@amd.com \
    --cc=aisaila@bitdefender.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=oleksii.kurochko@gmail.com \
    --cc=ppircalabu@bitdefender.com \
    --cc=ray.huang@amd.com \
    --cc=roger.pau@citrix.com \
    --cc=tamas@tklengyel.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.