From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C923533DEC2 for ; Fri, 5 Jun 2026 17:43:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780681418; cv=none; b=dMDITwTTvMdSjX+yaJ+uQdNiuIcqzfdNRgISBrklKKpnDVy/i4Auw2Lrz83vHL0VUk4XE8CtIrtDIm0fc3fv4OQT9qaGv/A0RGIsvkL6ujw0Z1XsnKzON5kpYj53ICtzVdedz3L5WKMlD4iwXKQUE6njIcvHTd/YwKT2QcFnDho= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780681418; c=relaxed/simple; bh=xNvpHZWuLTFXifz2OTwSBTgpatv1/x92dWcx9K1NRUQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=GGc+UZi17hML4FKhe4ks7XdLQgruZMpNnc0rM0bJ4tBgs0elrp3mT4p01YIMrXclqD4RttovPE6x0SzEUEcMG+cZzbD7Ls07eTGetLqFCYaUFWGr9n4zDcaFj3JrlAAPuI9YsLi2cnRzWoowdxZfgSV9aaCB/5UXIqkoUMOQkHE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=VC2jRr5p; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=MkRa5FAn; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="VC2jRr5p"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="MkRa5FAn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780681405; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cS4LK8y+wuXywD2/Nv3NzFYo7N64GVpkm4CNJMS1g3g=; b=VC2jRr5pbNlWPKEzL6o/2gAMA3iWiobGuwgXa80EXpgisDJEgCvqAPjGtT66O2p4AcGItg ZbtTdFpXAdmk4hA1lw56qn9VLxtmi0LEUDRK7rhd/MZEFmaVep50n/LhlFp4J8N2LPybjo be3Ig53x8OsntBB4u8gCWuv7A/HxVVg= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-339-qOfVFcESOLCRRTJBFD6OZg-1; Fri, 05 Jun 2026 13:43:24 -0400 X-MC-Unique: qOfVFcESOLCRRTJBFD6OZg-1 X-Mimecast-MFC-AGG-ID: qOfVFcESOLCRRTJBFD6OZg_1780681403 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-490a786f987so26707595e9.3 for ; Fri, 05 Jun 2026 10:43:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1780681403; x=1781286203; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=cS4LK8y+wuXywD2/Nv3NzFYo7N64GVpkm4CNJMS1g3g=; b=MkRa5FAn9yqXgsF3733kSy7TXu42cIoF7vCnKoxzui4/ZH/LvT7gXuG1d9694aqXk/ hBYJAeI6kfG5TkhWVhm8ySiAZcSzMEAxHKdZuMmy+LyZ4f3xOn0MwrgN2xVnDcfPhzET C31RvKqCzggOVOu8iNkP4j2PVJ9tBMOkw35PmiW1JQ40tvKKIXpCXKJ7Kv/iSSI3tlAX kBZQO+xxo5e2gMNJ5dGZHwqR7vF/O1N5iaKtix+w3Um9nHeaXZXZqGiGdT1bcIN9+xlE 3HyjSyLKjiMA+YJ4pzfo00ktpdCS8TjdgIGXRo0KtAPpHafD5qThTGszMQ3C4DUM4oW2 zcUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780681403; x=1781286203; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cS4LK8y+wuXywD2/Nv3NzFYo7N64GVpkm4CNJMS1g3g=; b=KZSw3diG1Q0Qhw45R/vzW0Q482v+ekCjPfGxAMbhzJ3HRjZql7Qplgp8otz7Bb5eSm oC405rGzjlHN5VzOsFhYf/D5KLZ9VacIanAA33X/3YDh/996TntP71rABU6pBLkWFot+ ayq7gdbcqmaXtd6Tj8frhvTHBJdAwR/M4ZUYe7zORORJlkz9+h5UWiAfPaqXWbVxV/fS ucQ+LBZLB/3BKfgThCzkn7qfiSFRYlQrzi9u70TgvZ6mXGqqdz+gnlzUjq9ycGmMsA1e 48Ni19pxU5zYoyafpueB2t5x44NVL64qtrzkgCp0BcVmmIfVJeYoLDkRn+THY1/+PfU6 Im3A== X-Forwarded-Encrypted: i=1; AFNElJ9EGMkLcYd+Xhw7DV1ZWczpggHzTiiCncwYOjj11eqId5yBs9H02w1Zqa+PUDU1vu7JUxyfx0sDS0nYlwA=@vger.kernel.org X-Gm-Message-State: AOJu0YzQDtdFiB8uvEUv2AobB5uh0lXBPNStV1PuANvsrkMty/lJ+ZxZ wZG8dLxyAb9NIb2ZcSnaAEdVFYjS+d03gdQuDo99hGXq+dWI95y+0pn5rM9552ZoptJC00D3HHh OxBQtAA/zIMteylK2hkhjd5oLZ2B5Sh2HfXqPTCyZqub2nYz+vU+g3AMnTFxG2IdO4A== X-Gm-Gg: Acq92OGsg5nTHXOX1r3oxG0ZmL1zuLzu4j1UFKmP9vvu7a5T85jmr9OTUC+XXSVnN0g 5qWgH1Au24DvGMYFQqMHXPlN3cawxKHazF9JURtoyA2XTeuhbadw/NU633HW5lrEFaDw8OVaVyV 2vb7KDYxd7eiQyIOKrQSDM3Ee+zAt5Ixppp1BO5gj7dOU9IRX/2a4FFD9fcg9+o//gPv6yxDpih jVxG5ZEBkpaTLLpBEDoa5CBhbMQ/nYr3Al6rAgkGEOuIGQkDXCkLsnzN8MMUHPwe1nqspSsHpiD zpb1AqWhqafDTq0exGB/7+qdm7Wy7TEs4BXPXlnkab84+I5n4m78wwhvbljhMySRPuLlkLulINL zlTXpvF4Nb08yNc+2nSorYEDegIpt4dXrQJwt2cSfzW3IoRgh0YGtOZg= X-Received: by 2002:a05:600c:1394:b0:490:b0f1:c27e with SMTP id 5b1f17b1804b1-490c25f1ad2mr81592835e9.24.1780681402788; Fri, 05 Jun 2026 10:43:22 -0700 (PDT) X-Received: by 2002:a05:600c:1394:b0:490:b0f1:c27e with SMTP id 5b1f17b1804b1-490c25f1ad2mr81592195e9.24.1780681402265; Fri, 05 Jun 2026 10:43:22 -0700 (PDT) Received: from redhat.com (ppp-94-66-118-61.home.otenet.gr. [94.66.118.61]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490bc3fd502sm168343035e9.11.2026.06.05.10.43.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jun 2026 10:43:21 -0700 (PDT) Date: Fri, 5 Jun 2026 13:43:18 -0400 From: "Michael S. Tsirkin" To: Si-Wei Liu Cc: Eugenio Perez Martin , yangjiale , Jason Wang , Xuan Zhuo , virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, Andrew.Boyer@amd.com Subject: Re: [PATCH] VIRTIO: Update the desc 'flag' fied last in packed ring. Message-ID: <20260605134252-mutt-send-email-mst@kernel.org> References: <20260602043123.10207-1-yangjiale133@163.com> <6035a8f3-e225-45b0-9f48-55de953bff15@oracle.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <6035a8f3-e225-45b0-9f48-55de953bff15@oracle.com> On Fri, Jun 05, 2026 at 09:03:36AM -0700, Si-Wei Liu wrote: > > > On 6/1/2026 11:04 PM, Eugenio Perez Martin wrote: > > On Tue, Jun 2, 2026 at 6:34 AM yangjiale wrote: > > > When a descriptor list spans across cache lines, > > > updating the flag first can lead to a scenario where the device side > > > perceives the flag as valid, yet the corresponding address and length > > > fields remain unupdated—resulting in invalid values. > > > Therefore, the flag field must be updated last. > > > > > > Signed-off-by: yangjiale > > > --- > > > drivers/virtio/virtio_ring.c | 8 ++++---- > > > 1 file changed, 4 insertions(+), 4 deletions(-) > > > > > > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c > > > index fbca7ce1c6bf..036b4f90d30f 100644 > > > --- a/drivers/virtio/virtio_ring.c > > > +++ b/drivers/virtio/virtio_ring.c > > > @@ -1688,6 +1688,10 @@ static inline int virtqueue_add_packed(struct vring_virtqueue *vq, > > > &addr, &len, premapped, attr)) > > > goto unmap_release; > > > > > > + desc[i].addr = cpu_to_le64(addr); > > > + desc[i].len = cpu_to_le32(len); > > > + desc[i].id = cpu_to_le16(id); > > > + > > > flags = cpu_to_le16(vq->packed.avail_used_flags | > > > (++c == total_sg ? 0 : VRING_DESC_F_NEXT) | > > > (n < out_sgs ? 0 : VRING_DESC_F_WRITE)); > > > @@ -1696,10 +1700,6 @@ static inline int virtqueue_add_packed(struct vring_virtqueue *vq, > > > else > > > desc[i].flags = flags; > > > > > > - desc[i].addr = cpu_to_le64(addr); > > > - desc[i].len = cpu_to_le32(len); > > > - desc[i].id = cpu_to_le16(id); > > > - > > > if (unlikely(vq->use_map_api)) { > > > vq->packed.desc_extra[curr].addr = premapped ? > > > DMA_MAPPING_ERROR : addr; > > These flags are updated before the flags of the head descriptor at the > > end of the function, at "vq->packed.vring.desc[head].flags = > > head_flags", so the device should not see these. Because of that, the > > relative order between the rest of the fields of the same descriptor > > or other descriptors' fields, except for the head descriptor's flags, > > should not matter. There is a write memory barrier just before > > updating the head's flags. > The above analysis is absolutely correct. Though one hardware vendor told me > that this driver implementation kinda stops them from reading ahead of > descriptors already posted beyond the available index., ending up with > suboptimal performance that is hard to make up by other means. Would it be a > bad idea to go with this change and add write barrier in a gentle way for a > small flit in the batch, e.g. commit to memory after every cache line size > worth of descriptors are posted? Would the memory barrier have negative > performance overhead to other backend implementation variants than real > hardware PCI device? > > -Siwei this would need a new feature bit, won't it? > > > > Also, I don't get why the cache line matters here. Can you expand? Am > > I missing something? > me too.