public inbox for virtualization@lists.linux-foundation.org
 help / color / mirror / Atom feed
From: Stefano Garzarella <sgarzare@redhat.com>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: linux-kernel@vger.kernel.org,
	"Cong Wang" <xiyou.wangcong@gmail.com>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Olivia Mackall" <olivia@selenic.com>,
	"Herbert Xu" <herbert@gondor.apana.org.au>,
	"Jason Wang" <jasowang@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Eugenio Pérez" <eperezma@redhat.com>,
	"James E.J. Bottomley" <James.Bottomley@hansenpartnership.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
	"Marek Szyprowski" <m.szyprowski@samsung.com>,
	"Robin Murphy" <robin.murphy@arm.com>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@google.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Simon Horman" <horms@kernel.org>,
	"Petr Tesarik" <ptesarik@suse.com>,
	"Leon Romanovsky" <leon@kernel.org>,
	"Jason Gunthorpe" <jgg@ziepe.ca>,
	"Bartosz Golaszewski" <brgl@kernel.org>,
	linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org,
	virtualization@lists.linux.dev, linux-scsi@vger.kernel.org,
	iommu@lists.linux.dev, kvm@vger.kernel.org,
	netdev@vger.kernel.org
Subject: Re: [PATCH v2 13/15] vsock/virtio: reorder fields to reduce padding
Date: Thu, 8 Jan 2026 15:27:04 +0100	[thread overview]
Message-ID: <aV-9F42fMfKGP4Rg@sgarzare-redhat> (raw)
In-Reply-To: <20260108091514-mutt-send-email-mst@kernel.org>

On Thu, Jan 08, 2026 at 09:17:49AM -0500, Michael S. Tsirkin wrote:
>On Thu, Jan 08, 2026 at 03:11:36PM +0100, Stefano Garzarella wrote:
>> On Mon, Jan 05, 2026 at 03:23:41AM -0500, Michael S. Tsirkin wrote:
>> > Reorder struct virtio_vsock fields to place the DMA buffer (event_list)
>> > last. This eliminates the padding from aligning the struct size on
>> > ARCH_DMA_MINALIGN.
>> >
>> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
>> > ---
>> > net/vmw_vsock/virtio_transport.c | 8 +++++---
>> > 1 file changed, 5 insertions(+), 3 deletions(-)
>> >
>> > diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c
>> > index ef983c36cb66..964d25e11858 100644
>> > --- a/net/vmw_vsock/virtio_transport.c
>> > +++ b/net/vmw_vsock/virtio_transport.c
>> > @@ -60,9 +60,7 @@ struct virtio_vsock {
>> > 	 */
>> > 	struct mutex event_lock;
>> > 	bool event_run;
>> > -	__dma_from_device_group_begin();
>> > -	struct virtio_vsock_event event_list[8];
>> > -	__dma_from_device_group_end();
>> > +
>> > 	u32 guest_cid;
>> > 	bool seqpacket_allow;
>> >
>> > @@ -76,6 +74,10 @@ struct virtio_vsock {
>> > 	 */
>> > 	struct scatterlist *out_sgs[MAX_SKB_FRAGS + 1];
>> > 	struct scatterlist out_bufs[MAX_SKB_FRAGS + 1];
>> > +
>>
>> IIUC we would like to have these fields always on the bottom of this struct,
>> so would be better to add a comment here to make sure we will not add other
>> fields in the future after this?
>
>not necessarily - you can add fields after, too - it's just that
>__dma_from_device_group_begin already adds a bunch of padding, so adding
>fields in this padding is cheaper.
>

Okay, I see.

>
>do we really need to add comments to teach people about the art of
>struct packing?

I can do it later if you prefer, I don't want to block this work, but 
yes, I'd prefer to have a comment because otherwise I'll have to ask 
every time to avoid, especially for new contributors xD

>
>> Maybe we should also add a comment about the `ev`nt_lock` requirement 
>> we
>> have in the section above.
>>
>> Thanks,
>> Stefano
>
>hmm which requirement do you mean?

That `event_list` must be accessed with `event_lock`.

So maybe we can move also `event_lock` and `event_run`, so we can just 
move that comment. I mean something like this:


@@ -74,6 +67,15 @@ struct virtio_vsock {
          */
         struct scatterlist *out_sgs[MAX_SKB_FRAGS + 1];
         struct scatterlist out_bufs[MAX_SKB_FRAGS + 1];
+
+       /* The following fields are protected by event_lock.
+        * vqs[VSOCK_VQ_EVENT] must be accessed with event_lock held.
+        */
+       struct mutex event_lock;
+       bool event_run;
+       __dma_from_device_group_begin();
+       struct virtio_vsock_event event_list[8];
+       __dma_from_device_group_end();
  };

  static u32 virtio_transport_get_local_cid(void)


Thanks,
Stefano


  reply	other threads:[~2026-01-08 14:27 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-05  8:22 [PATCH v2 00/15] fix DMA aligment issues around virtio Michael S. Tsirkin
2026-01-05  8:22 ` [PATCH v2 01/15] dma-mapping: add __dma_from_device_group_begin()/end() Michael S. Tsirkin
2026-01-05  9:40   ` Petr Tesarik
2026-01-05 18:27   ` Marek Szyprowski
2026-01-05  8:22 ` [PATCH v2 02/15] docs: dma-api: document __dma_from_device_group_begin()/end() Michael S. Tsirkin
2026-01-05  9:48   ` Petr Tesarik
2026-01-05 18:28   ` Marek Szyprowski
2026-01-05  8:23 ` [PATCH v2 03/15] dma-mapping: add DMA_ATTR_CPU_CACHE_CLEAN Michael S. Tsirkin
2026-01-05  9:50   ` Petr Tesarik
2026-01-08 13:57   ` Marek Szyprowski
2026-01-05  8:23 ` [PATCH v2 04/15] docs: dma-api: document DMA_ATTR_CPU_CACHE_CLEAN Michael S. Tsirkin
2026-01-05  9:51   ` Petr Tesarik
2026-01-08 13:59   ` Marek Szyprowski
2026-01-05  8:23 ` [PATCH v2 05/15] dma-debug: track cache clean flag in entries Michael S. Tsirkin
2026-01-05  9:54   ` Petr Tesarik
2026-01-05 12:37     ` Michael S. Tsirkin
2026-01-05 13:40       ` Petr Tesarik
2026-01-05  8:23 ` [PATCH v2 06/15] virtio: add virtqueue_add_inbuf_cache_clean API Michael S. Tsirkin
2026-01-05  8:23 ` [PATCH v2 07/15] vsock/virtio: fix DMA alignment for event_list Michael S. Tsirkin
2026-01-08 14:04   ` Stefano Garzarella
2026-01-08 14:07     ` Michael S. Tsirkin
2026-01-08 14:18       ` Stefano Garzarella
2026-01-05  8:23 ` [PATCH v2 08/15] vsock/virtio: use virtqueue_add_inbuf_cache_clean for events Michael S. Tsirkin
2026-01-08 14:08   ` Stefano Garzarella
2026-01-05  8:23 ` [PATCH v2 09/15] virtio_input: fix DMA alignment for evts Michael S. Tsirkin
2026-01-05  8:23 ` [PATCH v2 10/15] virtio_scsi: fix DMA cacheline issues for events Michael S. Tsirkin
2026-01-05 18:19   ` Stefan Hajnoczi
2026-01-06 14:50     ` Michael S. Tsirkin
2026-01-07 16:29       ` Stefan Hajnoczi
2026-01-06 14:51     ` Michael S. Tsirkin
2026-01-05  8:23 ` [PATCH v2 11/15] virtio-rng: fix DMA alignment for data buffer Michael S. Tsirkin
2026-01-05  8:23 ` [PATCH v2 12/15] virtio_input: use virtqueue_add_inbuf_cache_clean for events Michael S. Tsirkin
2026-01-05  8:23 ` [PATCH v2 13/15] vsock/virtio: reorder fields to reduce padding Michael S. Tsirkin
2026-01-08 14:11   ` Stefano Garzarella
2026-01-08 14:17     ` Michael S. Tsirkin
2026-01-08 14:27       ` Stefano Garzarella [this message]
2026-01-08 14:32         ` Michael S. Tsirkin
2026-01-08 14:45           ` Stefano Garzarella
2026-01-05  8:23 ` [PATCH v2 14/15] gpio: virtio: fix DMA alignment Michael S. Tsirkin
2026-01-05  9:48   ` Bartosz Golaszewski
2026-01-05  8:23 ` [PATCH v2 15/15] gpio: virtio: reorder fields to reduce struct padding Michael S. Tsirkin
2026-01-05  9:49   ` Bartosz Golaszewski
2026-01-28 20:31   ` [PATCH v3 15/15] vsock/virtio: reorder fields to reduce padding Michael S. Tsirkin
2026-01-29  8:42     ` Stefano Garzarella

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=aV-9F42fMfKGP4Rg@sgarzare-redhat \
    --to=sgarzare@redhat.com \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=brgl@kernel.org \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=eperezma@redhat.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=horms@kernel.org \
    --cc=iommu@lists.linux.dev \
    --cc=jasowang@redhat.com \
    --cc=jgg@ziepe.ca \
    --cc=kraxel@redhat.com \
    --cc=kuba@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=martin.petersen@oracle.com \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=olivia@selenic.com \
    --cc=pabeni@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=ptesarik@suse.com \
    --cc=robin.murphy@arm.com \
    --cc=stefanha@redhat.com \
    --cc=virtualization@lists.linux.dev \
    --cc=xiyou.wangcong@gmail.com \
    --cc=xuanzhuo@linux.alibaba.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