mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Woodhouse <dwmw2@infradead.org>
To: Chengfeng Ye <nicoyip.dev@gmail.com>,
	paul@xen.org, seanjc@google.com,  pbonzini@redhat.com
Cc: tglx@kernel.org, mingo@redhat.com, bp@alien8.de,
	dave.hansen@linux.intel.com, 	x86@kernel.org, hpa@zytor.com,
	boris.ostrovsky@oracle.com, kvm@vger.kernel.org,
	 linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] KVM: x86/xen: Fix data race on poll event channel
Date: Tue, 25 Aug 2026 19:21:47 +0100	[thread overview]
Message-ID: <dc0deaf8f867a4a4e2306e3f390cd432ff35ea72.camel@infradead.org> (raw)
In-Reply-To: <20260824114305.198732-1-nicoyip.dev@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2261 bytes --]

On Mon, 2026-08-24 at 19:43 +0800, Chengfeng Ye wrote:
> Use READ_ONCE() and WRITE_ONCE() for runtime accesses to poll_evtchn.
> This marks the intentionally concurrent scalar accesses and prevents the
> compiler from splitting, merging, or inventing accesses.
> 
> kvm_xen_schedop_poll() publishes the single port, or -1 for multiple
> ports, before setting poll_mask and halting the vCPU.  Event delivery can
> call kvm_xen_check_poller() on another CPU while the vCPU thread publishes
> that value or resets the field to zero after returning from
> kvm_vcpu_halt():
> 
>   vCPU thread                         event delivery thread
>   -----------                         ---------------------
>   poll_evtchn = port
>   set_bit(poll_mask)
>   kvm_vcpu_halt()
>                                       poll_evtchn = READ
>   poll_evtchn = 0
>   clear_bit(poll_mask)
> 
> The plain read and writes therefore race.  KCSAN reported:
> 
>   BUG: KCSAN: data-race in kvm_xen_hypercall / kvm_xen_set_evtchn_fast
> 
>   read to 0xffff888112f55af0 of 4 bytes by task 98:
>    kvm_xen_set_evtchn_fast+0x204/0x7c0
>    kvm_xen_hvm_evtchn_send+0xab/0x100
>    kvm_arch_vm_ioctl+0xb31/0xd90
>    kvm_vm_ioctl+0xf42/0x16c0
> 
>   write to 0xffff888112f55af0 of 4 bytes by task 96:
>    kvm_xen_hypercall+0xd8d/0xf50
>    kvm_emulate_hypercall+0x157/0x1d0
>    vmx_handle_exit+0x40f/0xae0
>    vcpu_run+0x137f/0x27d0
>    kvm_arch_vcpu_ioctl_run+0x5a5/0x970
> 
> The field is an aligned int on x86.  Access annotations preserve the
> existing matching, callback, and poll-mask control flow while making the
> single-copy access requirement explicit.
> 
> Fixes: 1a65105a5aba ("KVM: x86/xen: handle PV spinlocks slowpath")
> Cc: stable@vger.kernel.org
> Signed-off-by: Chengfeng Ye <nicoyip.dev@gmail.com>

LGTM, thanks. I don't think we need Cc:stable for a KCSAN splat, and
possibly not even the Fixes: tag. I'll roll it into my series at
https://lore.kernel.org/all/20260811094829.98794-1-dwmw2@infradead.org/
now sitting at
https://git.infradead.org/?p=users/dwmw2/linux.git;a=shortlog;h=refs/heads/xen-v3

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 6179 bytes --]

      reply	other threads:[~2026-08-25 18:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-24 11:43 Chengfeng Ye
2026-08-25 18:21 ` David Woodhouse [this message]

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=dc0deaf8f867a4a4e2306e3f390cd432ff35ea72.camel@infradead.org \
    --to=dwmw2@infradead.org \
    --cc=boris.ostrovsky@oracle.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=nicoyip.dev@gmail.com \
    --cc=paul@xen.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=stable@vger.kernel.org \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®