From: "Michael S. Tsirkin" <mst@redhat.com>
To: Cong Wang <xiyou.wangcong@gmail.com>
Cc: netdev@vger.kernel.org, virtualization@lists.linux.dev,
kvm@vger.kernel.org, Cong Wang <cwang@multikernel.io>,
Stefan Hajnoczi <stefanha@redhat.com>,
Stefano Garzarella <sgarzare@redhat.com>
Subject: Re: [Patch net] vsock: fix DMA cacheline overlap warning using coherent memory
Date: Tue, 30 Dec 2025 08:12:47 -0500 [thread overview]
Message-ID: <20251230081220-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <aVGz39EoF5ScJfIP@pop-os.localdomain>
On Sun, Dec 28, 2025 at 02:49:03PM -0800, Cong Wang wrote:
> On Sun, Dec 28, 2025 at 02:31:36PM -0500, Michael S. Tsirkin wrote:
> > On Sat, Dec 27, 2025 at 05:54:51PM -0800, Cong Wang wrote:
> > > From: Cong Wang <cwang@multikernel.io>
> > >
> > > The virtio-vsock driver triggers a DMA debug warning during probe:
> > >
> [...]
> > > This occurs because event_list[8] contains 8 struct virtio_vsock_event
> > > entries, each only 4 bytes (__le32 id). When virtio_vsock_event_fill()
> > > creates DMA mappings for all 8 events via virtqueue_add_inbuf(), these
> > > 32 bytes all fit within a single 64-byte cacheline.
> > >
> > > The DMA debug subsystem warns about this because multiple DMA_FROM_DEVICE
> > > mappings within the same cacheline can cause data corruption: if the CPU
> > > writes to one event while the device is writing another event in the same
> > > cacheline, the CPU cache writeback could overwrite device data.
> >
> > But the CPU never writes into one of these, or did I miss anything?
> >
> > The real issue is other data in the same cache line?
>
> You are right, it is misleading.
>
> The CPU never writes to the event buffers themselves, it only reads them
> after the device writes. The problem is other struct fields in the same
> cacheline.
>
> I will update the commit message.
>
> >
> > You want virtqueue_map_alloc_coherent/virtqueue_map_free_coherent
> > methinks.
> >
> > Then you can use normal inbuf/outbut and not muck around with premapped.
> >
> >
> > I prefer keeping fancy premapped APIs for perf sensitive code,
> > let virtio manage DMA API otherwise.
>
> Yes, I was not aware of these API's, they are indeed better than using
> DMA API's directly.
>
> Thanks!
> Cong
BTW I sent an RFC fixing these bugs in all drivers. Review/testing would
be appreciated.
prev parent reply other threads:[~2025-12-30 13:12 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-28 1:54 [Patch net] vsock: fix DMA cacheline overlap warning using coherent memory Cong Wang
2025-12-28 19:31 ` Michael S. Tsirkin
2025-12-28 22:49 ` Cong Wang
2025-12-30 13:12 ` Michael S. Tsirkin [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=20251230081220-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=cwang@multikernel.io \
--cc=kvm@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=sgarzare@redhat.com \
--cc=stefanha@redhat.com \
--cc=virtualization@lists.linux.dev \
--cc=xiyou.wangcong@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).