From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) (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 192D3238159 for ; Wed, 3 Jun 2026 01:12:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780449157; cv=none; b=WBkhtgyEn7EYSZqJUxFnnhU8ESLxmvnvYC9l7/ySY4a96CjWsM1epI8xI3tOqeFzMkrHc92KDUvSbuGa046OHZa0aet57UjFVEVGPqTbbFQ6P78gt3hxQi3dBkyvIkWWBhSeaVpklWt3SfznV360UxnQFCflEp2/dcvKbMQxBgI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780449157; c=relaxed/simple; bh=hew4HRz7gzgRJeKz628QCtAAjpVgxSwsN73kAg0Vknc=; h=Message-ID:Subject:Date:From:To:Cc:References:In-Reply-To: Content-Type; b=MabuuB/1F+bjfMLfgIhCcLP0q0DRFF7mlNmCFW6ofIg2lwW/+uZMYDoup/YA06XnY/k9yOpaz4qx7QnyCr++200uoZTrD1vxLKXOPKcoXro1zIScPvWTFJY6AMsrN4M7Uv8YA1ePSUToc521DwxBkR/aRdYI6jjS41pXtadrb+Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=nWx6jPZI; arc=none smtp.client-ip=115.124.30.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="nWx6jPZI" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1780449152; h=Message-ID:Subject:Date:From:To:Content-Type; bh=0eHa6yckhgnZ2thl9UQcY+7GqF4vYCBdsjgDzs/ErJM=; b=nWx6jPZIW115OadpZije4gNv5zYz7p9c7id7UxJgRl4E1S1+GP+K+Cgmx3ri0v4DJJ+4lj0vwFsUcfXYTHfX7uzg+5wVBsh0uSx+dEchpjivTUUm8xRnWGHG/YVMZsMfS7ZTyuIr8oyIXp8WjGERQbo0EAhpAZ8bgq7/0rvwX1M= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R101e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033032089153;MF=xuanzhuo@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0X45YUKy_1780449151; Received: from localhost(mailfrom:xuanzhuo@linux.alibaba.com fp:SMTPD_---0X45YUKy_1780449151 cluster:ay36) by smtp.aliyun-inc.com; Wed, 03 Jun 2026 09:12:32 +0800 Message-ID: <1780448985.5299122-1-xuanzhuo@linux.alibaba.com> Subject: Re: [PATCH] VIRTIO: Update the desc 'flag' fied last in packed ring. Date: Wed, 3 Jun 2026 09:09:45 +0800 From: Xuan Zhuo To: yangjiale Cc: Jason Wang , =?utf-8?q?Eugenio_P=C3=A9rez?= , virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, yangjiale , "Michael S . Tsirkin" References: <20260602043123.10207-1-yangjiale133@163.com> In-Reply-To: <20260602043123.10207-1-yangjiale133@163.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: On Tue, 2 Jun 2026 12:31:23 +0800, 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=E2=80=94resulting in invalid values. > Therefore, the flag field must be updated last. Are you raising this based on your code review, or did you actually encount= er an issue during testing? I don't think there is a problem here, as all operations are protected by t= he head desc flag. Even if cacheline effects cause data to be written prematur= ely, it shouldn't be an issue. The device must wait until the head desc flags are updated before it can start any subsequent work. Thanks. > > 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 vrin= g_virtqueue *vq, > &addr, &len, premapped, attr)) > goto unmap_release; > > + desc[i].addr =3D cpu_to_le64(addr); > + desc[i].len =3D cpu_to_le32(len); > + desc[i].id =3D cpu_to_le16(id); > + > flags =3D cpu_to_le16(vq->packed.avail_used_flags | > (++c =3D=3D 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 vrin= g_virtqueue *vq, > else > desc[i].flags =3D flags; > > - desc[i].addr =3D cpu_to_le64(addr); > - desc[i].len =3D cpu_to_le32(len); > - desc[i].id =3D cpu_to_le16(id); > - > if (unlikely(vq->use_map_api)) { > vq->packed.desc_extra[curr].addr =3D premapped ? > DMA_MAPPING_ERROR : addr; > -- > 2.25.1 >