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

Re: [PATCH] x86emul: allow ->write_msr() to distinguish origins of writes


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Fri, 30 Jan 2026 11:00:47 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=MAG0Y3HFPg+G9GbM4LfSgPa/2Fv0rpz07T57JiD+Oys=; b=IC6CTTVPFM1sJSOO/CZXmSZEHTxLTnvUF6GTNXk3xyT6ISk91Opg3Js/7IC8UsvXs2d5f8tN5imucUf1icCbne4wW16Kub1+CkUheQfFJuLvUwCzZXQfHWOh/RT4HZjHPtASU0nwMuqEPUDzuZcO6iXjhJPHDl3TWWB72gThLGybxttYq2djkvU43Df6Tncusk7w9fkrZ30ulPisI3ehxxEHH4oPWZnkIXZrn30IGN6jE8TNMfVgsB5WkU8+WtC3hMQeR21lnZgRYgWiOx9GC+eoJaCIuYceoUm0H4lvlNfIEkCPok8tixXMat59CX7E2+aGFM6vT8n/UGZ68QT2Ug==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=LtflugoFJq5ZWb/WcPpN9HQiIHaWMnTrDmsJR/9zA6GacvO31xxFGKKxKXDjyFe0RV21KGJksZCugzfRvBAk+5/ECTIvTM+oO12QF4lCtMi1atMjaHYe6rZiGLsgMd15PZHCkUt2NVLcE+NNrurC4W0ZydgSNS3AgL6gUwFqIRsKVESIrfK8nWqqqYgh78Lvq4A/47rVCaRyUq81u/SatUAmfVAFvdtig4EX5bl4rgiFkSZydw7RENRb8lPRaIhRLtwx5dUkYaAs1bKick8Qq8Yb2y/5ZxogRt0TBpNIW7FCEX7kEfDnv2/J1A5lSxgyaI2ggbRp/VPxeqpRlwQM0w==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Delivery-date: Fri, 30 Jan 2026 10:01:15 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Tue, Jan 27, 2026 at 11:21:06AM +0100, Jan Beulich wrote:
> Only explicit writes are subject to e.g. the checking of the MSR intercept
> bitmap, which extends to VM-event's hvm_monitor_msr(). Indicate, by way of
> a new boolean parameter, to the hook functions which variant it is.
> 
> Fixes: 6eb43fcf8a0b ("x86emul: support SWAPGS")
> Reported-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>

Acked-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>

> ---
> Later, in particular for nested, ->read_msr() may need to gain a similar
> parameter.
> 
> Prior to nested making use of it, the new parameter is effectively dead
> code with VM_EVENT=n. If we accepted Misra rule 2.2, something would
> likely need doing about this.

Hm, yes, it propagates into hvm_msr_write_intercept() which then turns
into `if ( may_defer && false )` in the VM_EVENT=n.  But then you
could say the same about the code inside the if block above for the
VM_EVENT=n, it's also effectively unreachable code.

> I've suitably re-based "x86emul: misc additions" on top of this, but I
> don't think I'll re-post it just for that.
> 
> --- a/tools/fuzz/x86_instruction_emulator/fuzz-emul.c
> +++ b/tools/fuzz/x86_instruction_emulator/fuzz-emul.c
> @@ -569,7 +569,8 @@ static int fuzz_read_msr(
>  static int fuzz_write_msr(
>      unsigned int reg,
>      uint64_t val,
> -    struct x86_emulate_ctxt *ctxt)
> +    struct x86_emulate_ctxt *ctxt,
> +    bool explicit)
>  {
>      struct fuzz_state *s = ctxt->data;
>      struct fuzz_corpus *c = s->corpus;
> --- a/xen/arch/x86/hvm/emulate.c
> +++ b/xen/arch/x86/hvm/emulate.c
> @@ -1705,7 +1705,8 @@ static int cf_check hvmemul_write_io_dis
>  static int cf_check hvmemul_write_msr_discard(
>      unsigned int reg,
>      uint64_t val,
> -    struct x86_emulate_ctxt *ctxt)
> +    struct x86_emulate_ctxt *ctxt,
> +    bool explicit)
>  {
>      return X86EMUL_OKAY;
>  }
> @@ -2427,9 +2428,10 @@ static int cf_check hvmemul_read_msr(
>  static int cf_check hvmemul_write_msr(
>      unsigned int reg,
>      uint64_t val,
> -    struct x86_emulate_ctxt *ctxt)
> +    struct x86_emulate_ctxt *ctxt,
> +    bool explicit)
>  {
> -    int rc = hvm_msr_write_intercept(reg, val, true);
> +    int rc = hvm_msr_write_intercept(reg, val, explicit);

I've wondered whether we also want to rename the parameter of
hvm_msr_write_intercept() into something different than may_defer.  It
feels weird to translate a parameter that denotes an explicit MSR
access into one that signals whether it's fine to defer the operation
or not.

Thanks, Roger.



 


Rackspace

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