From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B3483ECAAD3 for ; Thu, 15 Sep 2022 11:25:33 +0000 (UTC) Received: from localhost ([::1]:38534 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oYmzr-0004ia-NH for qemu-devel@archiver.kernel.org; Thu, 15 Sep 2022 07:25:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53956) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oYmxv-0003yz-11 for qemu-devel@nongnu.org; Thu, 15 Sep 2022 07:23:33 -0400 Received: from out30-133.freemail.mail.aliyun.com ([115.124.30.133]:43679) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oYmxj-0007c3-Ga for qemu-devel@nongnu.org; Thu, 15 Sep 2022 07:23:22 -0400 X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R241e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=ay29a033018045168; MF=xuanzhuo@linux.alibaba.com; NM=1; PH=DS; RN=6; SR=0; TI=SMTPD_---0VPsv-qW_1663240684; Received: from localhost(mailfrom:xuanzhuo@linux.alibaba.com fp:SMTPD_---0VPsv-qW_1663240684) by smtp.aliyun-inc.com; Thu, 15 Sep 2022 19:18:05 +0800 Message-ID: <1663240650.2765737-1-xuanzhuo@linux.alibaba.com> Subject: Re: [PATCH v2 3/6] vhost-net: vhost-user: update vhost_net_virtqueue_reset() Date: Thu, 15 Sep 2022 19:17:30 +0800 From: Xuan Zhuo To: Jason Wang Cc: mst , "Gonglei (Arei)" , Heng Qi , Kangjie Xu , "qemu-devel" References: <1663136320.6336615-1-xuanzhuo@linux.alibaba.com> In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=115.124.30.133; envelope-from=xuanzhuo@linux.alibaba.com; helo=out30-133.freemail.mail.aliyun.com X-Spam_score_int: -98 X-Spam_score: -9.9 X-Spam_bar: --------- X-Spam_report: (-9.9 / 5.0 requ) BAYES_00=-1.9, ENV_AND_HDR_SPF_MATCH=-0.5, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UNPARSEABLE_RELAY=0.001, USER_IN_DEF_SPF_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On Thu, 15 Sep 2022 10:12:11 +0800, Jason Wang wrote: > On Wed, Sep 14, 2022 at 2:21 PM Xuan Zhuo wr= ote: > > > > On Wed, 14 Sep 2022 11:13:29 +0800, Jason Wang wr= ote: > > > > > > =E5=9C=A8 2022/9/12 11:10, Kangjie Xu =E5=86=99=E9=81=93: > > > > Update vhost_net_virtqueue_reset() for vhost-user scenario. > > > > > > > > In order to reuse some functions, we process the idx for > > > > vhost-user scenario because vhost_get_vq_index behave > > > > differently for vhost-user. > > > > > > > > Signed-off-by: Kangjie Xu > > > > Signed-off-by: Xuan Zhuo > > > > --- > > > > hw/net/vhost_net.c | 3 +++ > > > > 1 file changed, 3 insertions(+) > > > > > > > > diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c > > > > index ea896ea75b..25e5665489 100644 > > > > --- a/hw/net/vhost_net.c > > > > +++ b/hw/net/vhost_net.c > > > > @@ -545,6 +545,9 @@ void vhost_net_virtqueue_reset(VirtIODevice *vd= ev, NetClientState *nc, > > > > assert(vhost_ops); > > > > > > > > idx =3D vhost_ops->vhost_get_vq_index(&net->dev, vq_index); > > > > + if (net->nc->info->type =3D=3D NET_CLIENT_DRIVER_VHOST_USER) { > > > > + idx -=3D net->dev.vq_index; > > > > + } > > > > > > > > > This looks tricky. Any reason we can't simply use vq_index for both > > > vhost-user and vhost-net? > > > > > > static int vhost_user_get_vq_index(struct vhost_dev *dev, int idx) > > { > > assert(idx >=3D dev->vq_index && idx < dev->vq_index + dev->nvqs); > > > > return idx; > > } > > > > > > static int vhost_kernel_get_vq_index(struct vhost_dev *dev, int idx) > > { > > assert(idx >=3D dev->vq_index && idx < dev->vq_index + dev->nvqs); > > > > return idx - dev->vq_index; > > } > > > > The implementation of these two callbacks is different. The structure o= f the two > > scenarios is different. We may need to do some optimizations in the fut= ure. > > Yes, but what I meant is, you do > > idx -=3D net->dev.vq_index; > > and then > > net->dev.vq_index + idx > > This is a hint that we should have a better organization of the code. I see. Will fix this. Thanks. > > Thanks > > > > > Thanks. > > > > > > > > > > Thanks > > > > > > > > > > > > > > if (net->nc->info->type =3D=3D NET_CLIENT_DRIVER_TAP) { > > > > file.index =3D idx; > > > > > >