Re: [PATCH v2] virtio_ring: Add READ_ONCE annotations for device-writable fields
From: Michael S. Tsirkin
Date: Fri Jan 30 2026 - 02:44:02 EST
On Fri, Jan 30, 2026 at 10:03:23AM +0800, Jason Wang wrote:
> On Thu, Jan 29, 2026 at 8:16 PM Johannes Thumshirn
> <johannes.thumshirn@xxxxxxx> wrote:
> >
> > From: Alexander Graf <graf@xxxxxxxxxx>
> >
> > KCSAN reports data races when accessing virtio ring fields that are
> > concurrently written by the device (host). These are legitimate
> > concurrent accesses where the CPU reads fields that the device updates
> > via DMA-like mechanisms.
>
> Technically, the device can write to the descriptor ring as well, do
> we need to care about this case or not?
Why would we?
> >
> > Add accessor functions that use READ_ONCE() to properly annotate these
> > device-writable fields and prevent compiler optimizations that could in
> > theory break the code. This also serves as documentation showing which
> > fields are shared with the device.
> >
> > The affected fields are:
> > - Split ring: used->idx, used->ring[].id, used->ring[].len
> > - Packed ring: desc[].flags, desc[].id, desc[].len
> >
> > Signed-off-by: Alexander Graf <graf@xxxxxxxxxx>
> > [jth: Add READ_ONCE in virtqueue_kick_prepare_split ]
> > Co-developed-by: Johannes Thumshirn <johannes.thumshirn@xxxxxxx>
> > Signed-off-by: Johannes Thumshirn <johannes.thumshirn@xxxxxxx>
> >
>
> Thanks