Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp5519101rwb; Wed, 17 Aug 2022 20:18:43 -0700 (PDT) X-Google-Smtp-Source: AA6agR67R365a6IpOcLr00bfVj5821uA4TEd4pX90KBs9t+0lr3UgyjrdQyu/5NKjEeb+XK4aAUw X-Received: by 2002:a17:907:7f26:b0:739:651a:7c0 with SMTP id qf38-20020a1709077f2600b00739651a07c0mr584775ejc.370.1660792723013; Wed, 17 Aug 2022 20:18:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660792723; cv=none; d=google.com; s=arc-20160816; b=ahBJECVPSqxPc/6A94QmaqZLrVtsvZmTge9UNFQBb21AS2WYI/E8zOTfhedJpARGkn KgwPCwNSnzpWxrk6jPCTuBCmC425//v1l/mqvp/KeaqkbQjZU1D9YGsedS7xYqcizsJn uHnpiX9JPYyxd/H44XC35HMA8YtQRoiNjSUzC5EJ42XdEA0HfLI59uv8w+mscyzlxD2j +exBCrwFBZELHlRVo47hNr0mph4HRvEkAZESrf2qCuY1NBT6bLGw7BdKM3uF/ayVr4GO qMu+aD7Ej9eZWl55fufpy3LJ/eswx25Q7B3NmRmMX3zt0GvSlwBTtVywad710zz5UnUA +9dQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date; bh=kmFX8HdxsMtkWlknquosejeZzUEbqjnjHpOS3uzc1x4=; b=C73SULL6LkvidiLbRICHmQsPFqNT/uA6vuD0hhM97vSgTAKLYiZmw0j10WDK/VXxto ezTVFtLoTT5REOlOUQvtoYYkn97Hk0qLu63xVdGU2ne/uOnaexuYheAACxhHwRty9xrr GK6OlLGMxvfDTBPYOzYEPOaHyF+mmzjx+17jde1LGwwonCfqj81RwXi2hMuhPfeb6S1Q gctQKI9ayOf0XcIuj6rxm1B4E8U9dpHNYW8XL9HnCQfGBEddvb+WuKF/pE0R5F4PkUVj GtIk0wMtbBrbMSKewD7KeAoR12fFuR9zX4faZKSPgJk+pwlV4uLynK82T13Pne+PEjeo 5uJw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u1-20020a50a401000000b00445bd4d6989si301345edb.473.2022.08.17.20.18.02; Wed, 17 Aug 2022 20:18:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243032AbiHRDPK (ORCPT + 99 others); Wed, 17 Aug 2022 23:15:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234003AbiHRDPF (ORCPT ); Wed, 17 Aug 2022 23:15:05 -0400 Received: from smtp237.sjtu.edu.cn (smtp237.sjtu.edu.cn [202.120.2.237]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 297A5F69; Wed, 17 Aug 2022 20:14:55 -0700 (PDT) Received: from mta91.sjtu.edu.cn (unknown [10.118.0.91]) by smtp237.sjtu.edu.cn (Postfix) with ESMTPS id EAB2D1007FEC2; Thu, 18 Aug 2022 11:14:51 +0800 (CST) Received: from localhost (localhost.localdomain [127.0.0.1]) by mta91.sjtu.edu.cn (Postfix) with ESMTP id A8C7B37C83F; Thu, 18 Aug 2022 11:14:51 +0800 (CST) X-Virus-Scanned: amavisd-new at Received: from mta91.sjtu.edu.cn ([127.0.0.1]) by localhost (mta91.sjtu.edu.cn [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id LQVKrW1XeNzi; Thu, 18 Aug 2022 11:14:51 +0800 (CST) Received: from mstore105.sjtu.edu.cn (mstore101.sjtu.edu.cn [10.118.0.105]) by mta91.sjtu.edu.cn (Postfix) with ESMTP id 66A2E37C83E; Thu, 18 Aug 2022 11:14:51 +0800 (CST) Date: Thu, 18 Aug 2022 11:14:51 +0800 (CST) From: Guo Zhi To: Xuan Zhuo Cc: netdev , linux-kernel , kvm list , virtualization , eperezma , jasowang , sgarzare , Michael Tsirkin Message-ID: <740765206.8333341.1660792491216.JavaMail.zimbra@sjtu.edu.cn> In-Reply-To: <1660791937.681257-2-xuanzhuo@linux.alibaba.com> References: <20220817135718.2553-1-qtxuning1999@sjtu.edu.cn> <20220817135718.2553-6-qtxuning1999@sjtu.edu.cn> <1660791937.681257-2-xuanzhuo@linux.alibaba.com> Subject: Re: [RFC v2 5/7] virtio: unmask F_NEXT flag in desc_extra MIME-Version: 1.0 Content-Type: text/plain; charset=GB2312 Content-Transfer-Encoding: 7bit X-Originating-IP: [36.148.65.198] X-Mailer: Zimbra 8.8.15_GA_4308 (ZimbraWebClient - GC103 (Mac)/8.8.15_GA_3928) Thread-Topic: virtio: unmask F_NEXT flag in desc_extra Thread-Index: oba2ba4WyD9k9gWyXec9T2Msqu35hA== X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- Original Message ----- > From: "Xuan Zhuo" > To: "Guo Zhi" > Cc: "netdev" , "linux-kernel" , "kvm list" , > "virtualization" , "Guo Zhi" , "eperezma" > , "jasowang" , "sgarzare" , "Michael Tsirkin" > > Sent: Thursday, August 18, 2022 11:05:37 AM > Subject: Re: [RFC v2 5/7] virtio: unmask F_NEXT flag in desc_extra > On Wed, 17 Aug 2022 21:57:16 +0800, Guo Zhi wrote: >> We didn't unmask F_NEXT flag in desc_extra in the end of a chain, >> unmask it so that we can access desc_extra to get next information. > > I think we should state the purpose of this. > I have to unmask F_NEXT flag in desc_extra in this series, because if in order negotiated, the driver has to iterate the descriptor chain to get chain length from desc_extra. (The reason why we should use desc_extra is that descs may be changed by malicious hypervisors, https://lkml.org/lkml/2022/7/26/224). >> >> Signed-off-by: Guo Zhi >> --- >> drivers/virtio/virtio_ring.c | 6 ++++-- >> 1 file changed, 4 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c >> index a5ec724c01d8..1c1b3fa376a2 100644 >> --- a/drivers/virtio/virtio_ring.c >> +++ b/drivers/virtio/virtio_ring.c >> @@ -567,7 +567,7 @@ static inline int virtqueue_add_split(struct virtqueue *_vq, >> } >> /* Last one doesn't continue. */ >> desc[prev].flags &= cpu_to_virtio16(_vq->vdev, ~VRING_DESC_F_NEXT); >> - if (!indirect && vq->use_dma_api) >> + if (!indirect) >> vq->split.desc_extra[prev & (vq->split.vring.num - 1)].flags &= >> ~VRING_DESC_F_NEXT; >> >> @@ -584,6 +584,8 @@ static inline int virtqueue_add_split(struct virtqueue *_vq, >> total_sg * sizeof(struct vring_desc), >> VRING_DESC_F_INDIRECT, >> false); >> + vq->split.desc_extra[head & (vq->split.vring.num - 1)].flags &= >> + ~VRING_DESC_F_NEXT; > > This seems unnecessary. > >> } >> >> /* We're using some buffers from the free list. */ >> @@ -693,7 +695,7 @@ static void detach_buf_split(struct vring_virtqueue *vq, >> unsigned int head, >> /* Put back on free list: unmap first-level descriptors and find end */ >> i = head; >> >> - while (vq->split.vring.desc[i].flags & nextflag) { >> + while (vq->split.desc_extra[i].flags & nextflag) { > > nextflag is __virtio16 > > You can use VRING_DESC_F_NEXT directly. > > Thanks. Sorry for the mistake, I will fix it. > >> vring_unmap_one_split(vq, i); >> i = vq->split.desc_extra[i].next; >> vq->vq.num_free++; >> -- >> 2.17.1 >>