Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp59317rwe; Thu, 13 Apr 2023 22:12:51 -0700 (PDT) X-Google-Smtp-Source: AKy350Za6Ag617ypn14cEyLF5brmjULLQHcyUpcmOLHWoQQcinVnTKNGERR140f5xuRnWQI8bU/U X-Received: by 2002:a17:90b:4a0d:b0:246:5968:43f0 with SMTP id kk13-20020a17090b4a0d00b00246596843f0mr4126518pjb.10.1681449171183; Thu, 13 Apr 2023 22:12:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681449171; cv=none; d=google.com; s=arc-20160816; b=yhv8nMU5CeUu+iBaY9jpQtKgaLtHL6nIu0Q4ZT1PQJb5TumpnWhLgQtHLOZ71vpVeL uWDLpPkLhfmAQZc1MBHoYIWpR9DP1bzRDQ7djATFWyD42+PEfIRBIwMK2Jen4sbR4P8D wdVOS1a6cKwFcCnBcenV5N9cA8GnXML4GXPdtp5Q7twmi5oyPAwn69W0SeZaq+zsYnbK 5iB7Q+Sukeyf1z5ch+BRRgw7ZutT22ujcOF+FFIoI687nf36Pd5eafhWPjamWmp3msTP NnvdmOVSY+dGcDKe0wNMtfzuwh3ljh/BQ3phHG+QKLBH/1b5POdrTTrn7JzY5ddzZDAE 6AHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=MnDvwf1R/OovgMAVg9WiYCMbtU1kpmzHDOYZjnYe0Qg=; b=WlGDDdqX7kWwvzvW9Uy2cBQ7wNkbOWDbnki63QKzNuKAVjuVe2aQaTCfGCff7Cw8tT DVZ1a+inS2aD2QM1YiBjZe7mfms4cKU/HxATVhb/ddr/eoIEDUZGVnXk5/rAHdZA4Zqb yM31p6Tcj53uizE5NLhUWwWhSahvkTVxToqFBhVste81JCpyxq3uXyT9BM+zoeIXQk5/ f/r+wVRTWmo2CNPiF/kUw/oYpOduwXT1h+w/oT3mRpOwplM3K6wJ3Sedo3CmwHocNmxT qgNfZEq5Ub6DWUq8yqLzdp2evhd/UZHGEc7ObIXFtWGlT9PiQZSsxSorfL5CJE3lBIw7 2RvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HMkAuRvn; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y16-20020a170902b49000b001a68ebc3e50si2420976plr.511.2023.04.13.22.12.40; Thu, 13 Apr 2023 22:12:51 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HMkAuRvn; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229805AbjDNFLn (ORCPT + 99 others); Fri, 14 Apr 2023 01:11:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229753AbjDNFL0 (ORCPT ); Fri, 14 Apr 2023 01:11:26 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AFDA40C0 for ; Thu, 13 Apr 2023 22:10:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681449018; 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=MnDvwf1R/OovgMAVg9WiYCMbtU1kpmzHDOYZjnYe0Qg=; b=HMkAuRvnHciF4+FHTe7MQ4Mxh6/Bt/VBJLPDW52hH+vCzcvW9Vpvn8wyPWo9n3pHvH7Wfi uZX4lfZuSaoEXLMCm4jUJ91at7z0rmwFLFxBlRH/Zw/XPCxL6VhKDxd3nvcQMGQg39PGMA i/Rw6gQfEr024e1Ty+OtuHftXiyv4nI= Received: from mail-oi1-f197.google.com (mail-oi1-f197.google.com [209.85.167.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-475-aCwe7LbqPraAtQECWJ0wAQ-1; Fri, 14 Apr 2023 01:10:12 -0400 X-MC-Unique: aCwe7LbqPraAtQECWJ0wAQ-1 Received: by mail-oi1-f197.google.com with SMTP id cd18-20020a056808319200b0038bef54e329so2309668oib.17 for ; Thu, 13 Apr 2023 22:10:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681449011; x=1684041011; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MnDvwf1R/OovgMAVg9WiYCMbtU1kpmzHDOYZjnYe0Qg=; b=OTOLk8exU+yeU5h2nLmyMlhBjrzrc9TW2duaNJXHRGyyMz9llKvuzQSQA3qYBYHcxo Vvd8sC7KlxdNch1fl4H4xQgI34Y22ri6L5GzSOCG6h04pY+WppqULz6vpXRZhZRn/wvm cllQ1DnqqSeR1r+egb9GPub+UsGRzC1RbEm49LebkNO/ij7REPQV2sl+T/ZdPNPh4Hdt Lb9XRobxHDuQrQmh6+OzBXrAEfFkL9vjC7UxQorT51GPavi5CYYDngMjgX6IIHqJ67Sg VaVFRufMUfzNc0cRDOOZo+IQPEs20vZ1W41hHFNVFwOw9hG3zkx0Ml0zCGKeUpyVPOvD nfwA== X-Gm-Message-State: AAQBX9cBcK8moj9rVbXCvT5pFh8GYL/N8vlzqfpkANkpGIunlYxPZ5Iu KZVdoh0A5jQ+OE6qDH8beELYXC6gjYclMWRflVkoFMdXV2ZvFXp6BT0hsUOC+Zo6CiwlfuzS1m5 kS5556CX8QIB/wcs5V3ed/LYEBDGbiFpmf93/VCv2 X-Received: by 2002:a05:6870:2495:b0:177:b9c0:bcba with SMTP id s21-20020a056870249500b00177b9c0bcbamr3833499oaq.3.1681449011193; Thu, 13 Apr 2023 22:10:11 -0700 (PDT) X-Received: by 2002:a05:6870:2495:b0:177:b9c0:bcba with SMTP id s21-20020a056870249500b00177b9c0bcbamr3833491oaq.3.1681449010955; Thu, 13 Apr 2023 22:10:10 -0700 (PDT) MIME-Version: 1.0 References: <20230413064027.13267-1-jasowang@redhat.com> <20230413064027.13267-3-jasowang@redhat.com> <1681370820.0675354-2-xuanzhuo@linux.alibaba.com> In-Reply-To: From: Jason Wang Date: Fri, 14 Apr 2023 13:10:00 +0800 Message-ID: Subject: Re: [PATCH net-next V2 2/2] virtio-net: sleep instead of busy waiting for cvq command To: Xuan Zhuo Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, maxime.coquelin@redhat.com, alvaro.karsz@solid-run.com, eperezma@redhat.com, david.marchand@redhat.com, mst@redhat.com, netdev Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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 Adding netdev. On Fri, Apr 14, 2023 at 1:09=E2=80=AFPM Jason Wang wr= ote: > > On Thu, Apr 13, 2023 at 3:31=E2=80=AFPM Xuan Zhuo wrote: > > > > On Thu, 13 Apr 2023 14:40:27 +0800, Jason Wang wr= ote: > > > We used to busy waiting on the cvq command this tends to be > > > problematic since there no way for to schedule another process which > > > may serve for the control virtqueue. This might be the case when the > > > control virtqueue is emulated by software. This patch switches to use > > > completion to allow the CPU to sleep instead of busy waiting for the > > > cvq command. > > > > > > Signed-off-by: Jason Wang > > > --- > > > Changes since V1: > > > - use completion for simplicity > > > - don't try to harden the CVQ command which requires more thought > > > Changes since RFC: > > > - break the device when timeout > > > - get buffer manually since the virtio core check more_used() instead > > > --- > > > drivers/net/virtio_net.c | 21 ++++++++++++++------- > > > 1 file changed, 14 insertions(+), 7 deletions(-) > > > > > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c > > > index 2e56bbf86894..d3eb8fd6c9dc 100644 > > > --- a/drivers/net/virtio_net.c > > > +++ b/drivers/net/virtio_net.c > > > @@ -19,6 +19,7 @@ > > > #include > > > #include > > > #include > > > +#include > > > #include > > > #include > > > #include > > > @@ -295,6 +296,8 @@ struct virtnet_info { > > > > > > /* failover when STANDBY feature enabled */ > > > struct failover *failover; > > > + > > > + struct completion completion; > > > }; > > > > > > struct padded_vnet_hdr { > > > @@ -1709,6 +1712,13 @@ static bool try_fill_recv(struct virtnet_info = *vi, struct receive_queue *rq, > > > return !oom; > > > } > > > > > > +static void virtnet_cvq_done(struct virtqueue *cvq) > > > +{ > > > + struct virtnet_info *vi =3D cvq->vdev->priv; > > > + > > > + complete(&vi->completion); > > > +} > > > + > > > static void skb_recv_done(struct virtqueue *rvq) > > > { > > > struct virtnet_info *vi =3D rvq->vdev->priv; > > > @@ -2169,12 +2179,8 @@ static bool virtnet_send_command(struct virtne= t_info *vi, u8 class, u8 cmd, > > > if (unlikely(!virtqueue_kick(vi->cvq))) > > > return vi->ctrl->status =3D=3D VIRTIO_NET_OK; > > > > > > - /* Spin for a response, the kick causes an ioport write, trappi= ng > > > - * into the hypervisor, so the request should be handled immedi= ately. > > > - */ > > > - while (!virtqueue_get_buf(vi->cvq, &tmp) && > > > - !virtqueue_is_broken(vi->cvq)) > > > - cpu_relax(); > > > + wait_for_completion(&vi->completion); > > > + virtqueue_get_buf(vi->cvq, &tmp); > > > > > > return vi->ctrl->status =3D=3D VIRTIO_NET_OK; > > > } > > > @@ -3672,7 +3678,7 @@ static int virtnet_find_vqs(struct virtnet_info= *vi) > > > > > > /* Parameters for control virtqueue, if any */ > > > if (vi->has_cvq) { > > > - callbacks[total_vqs - 1] =3D NULL; > > > + callbacks[total_vqs - 1] =3D virtnet_cvq_done; > > > > This depends the interrupt, right? > > Not necessarily, we have ISR for at last PCI: > > static irqreturn_t vp_interrupt(int irq, void *opaque) > { > struct virtio_pci_device *vp_dev =3D opaque; > u8 isr; > > /* reading the ISR has the effect of also clearing it so it's ver= y > * important to save off the value. */ > isr =3D ioread8(vp_dev->isr); > ... > } > > > > > I worry that there may be some devices that may not support interruptio= n on cvq. > > Is the device using INTX or MSI-X? > > > Although this may not be in line with SPEC, it may cause problem on the= devices > > that can work normally at present. > > Then the implementation is buggy, it might not work for drivers other > than Linux. Working around such buggy implementation is suboptimal. > > Thanks > > > > > Thanks. > > > > > > > names[total_vqs - 1] =3D "control"; > > > } > > > > > > @@ -4122,6 +4128,7 @@ static int virtnet_probe(struct virtio_device *= vdev) > > > if (vi->has_rss || vi->has_rss_hash_report) > > > virtnet_init_default_rss(vi); > > > > > > + init_completion(&vi->completion); > > > enable_rx_mode_work(vi); > > > > > > /* serialize netdev register + virtio_device_ready() with ndo_o= pen() */ > > > -- > > > 2.25.1 > > > > >