Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp4072246rwi; Mon, 17 Oct 2022 00:39:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5AZHPrR/HFlHRnTHZT5Dc6pxazWYZSyw8wuLHMzruJfVXFcMHt93sKZr9LSPbD/9sJ2LTq X-Received: by 2002:a17:90b:1c0e:b0:20d:8cc5:23e5 with SMTP id oc14-20020a17090b1c0e00b0020d8cc523e5mr12449334pjb.111.1665992386188; Mon, 17 Oct 2022 00:39:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665992386; cv=none; d=google.com; s=arc-20160816; b=TAdjem4g4fadKflkK0JnDtemcG/WWwG5QCXiBtMArnNBTjZHxgkSRmVSrQuhoHNOgm pgnEOpnyqzM+XQkyWDUi9SwDbLmV/r7aH9IOAnIq9kSEsL9WTSlwY783J/j+BvaC4Seu eYz/6dhrxZr6Vm+x62zcKJsOqmBsDWl2WWBAFzGwK94okHpsyIXwQaPxPEt6H6wMZlAY DtR3QRVxGf24uo7ohrlRiCJM5gv1xn31VTRcNBtfDgCuL36vZWdrQ8PXpifq6V+R18Lj KdqPHwexNaKrEiJb5ytOdH5P48dLU39ko1lJrAQXulCXJc+cQe8hNWaNvReR2CTjm5H7 uajg== 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=iPJ0zMzH+/+WqE+Q9hXMqr+6tdiNkx5DCmG8+/nVPjA=; b=TX1sz9xXSRI4TamggL6S4K/CsoWQW28fj+HFhcDg45jOGR21Kz8PHUnNsvX+9EX90O LmJw8UOD3GAJtJH+gl3aPOqM5T1yx3nc+Thgx8oKSs+Jr0V+Xwq32hkUwBaCohPRstQi v1mS29F30kQIwziRKxOlDNi4CorhUwHxZa/dh2OswXMECWoaFOD0Umx0tv3PuvJEFDXO zqCwTk3iwSnK6W4BDCZ6N8qjVLv5oMqVjYYKirt/IEEtBviNeqy+fN3yoWM7fzYsF26c zH7z9bAKCFi9A6PPtsZDSADjyvcOPVUzYFKR4W+bQBAJWpCSUaUNYi2LqprhjZGZHjiw EYDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PpVQNCUf; 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 v22-20020a17090a899600b0020a5121be54si15313485pjn.23.2022.10.17.00.39.33; Mon, 17 Oct 2022 00:39:46 -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=PpVQNCUf; 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 S230047AbiJQHPc (ORCPT + 99 others); Mon, 17 Oct 2022 03:15:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230026AbiJQHPa (ORCPT ); Mon, 17 Oct 2022 03:15:30 -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 DB94010541 for ; Mon, 17 Oct 2022 00:15:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665990926; 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=iPJ0zMzH+/+WqE+Q9hXMqr+6tdiNkx5DCmG8+/nVPjA=; b=PpVQNCUfenkyJKX1EWLMzbY7PmoCvMPw8b4dKomzk430mHmsNFcMGC9u+X3MQRqMjUiMr+ 6Wd0yjMDZHqmkx0749w9xEDHg8SAd3XZFMYjx4HFQmh28KG2cAdhr1uF5kdcxYmGfc2sZW t/6VpNX+oh0d2Kv/x+ZgdvrjatEuaDE= Received: from mail-ot1-f69.google.com (mail-ot1-f69.google.com [209.85.210.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-267-HoumJp6vMkOUHxsDvQ2T3A-1; Mon, 17 Oct 2022 03:15:25 -0400 X-MC-Unique: HoumJp6vMkOUHxsDvQ2T3A-1 Received: by mail-ot1-f69.google.com with SMTP id z22-20020a05683020d600b00661bd353d87so4645516otq.16 for ; Mon, 17 Oct 2022 00:15:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=iPJ0zMzH+/+WqE+Q9hXMqr+6tdiNkx5DCmG8+/nVPjA=; b=OBEQSkeZS8UcO7Y9o0LOkI/yGM0vFYR6Ay3EhDdAoEAiaYuH1EsFWbnUNeTz5n42fK NbdwstTSE1q419loY0NCHQFcOJXpDphPC53nRcCc6sznYjbLE01DSyajh3kBk62J0P7T 6ELGkCPMc1kIouBJr1Cs/f2xA+Av3sUeWVcJn1Druh88UAvQEYUZq6g8UkdcsC7CMMmO xZxgb95tGLwhybMZon7skOh55I/vWjoDBS+F2DAw9RAcGDlJz1xRb/NQQSUKLq3dB8tv KqDA8D3SasNbXdQSD8i/nygoYngC4jBVCAblUsEd39Hw36FJi9r4MOxBxbuWgogrspiV ugxA== X-Gm-Message-State: ACrzQf2vBWeeR76j27JBYE0g8tT2XAJC/gUMjuEMBNI4sB2Cio2wd8hN GVZdoGxHxNdC6YQ2JDFqeSjErk/esiOO84rn/G5LQdzDqAfbj8PnQUXSDXWlsdbf3cZJe8nNDlH Gv+Ej6dx2HiTVdgu+WsGOLuP0kVoTP1MbOvw3dDwI X-Received: by 2002:a9d:7dcf:0:b0:661:dc25:ba0 with SMTP id k15-20020a9d7dcf000000b00661dc250ba0mr4363912otn.201.1665990924506; Mon, 17 Oct 2022 00:15:24 -0700 (PDT) X-Received: by 2002:a9d:7dcf:0:b0:661:dc25:ba0 with SMTP id k15-20020a9d7dcf000000b00661dc250ba0mr4363898otn.201.1665990924270; Mon, 17 Oct 2022 00:15:24 -0700 (PDT) MIME-Version: 1.0 References: <20220905045341.66191-1-jasowang@redhat.com> <20220905031405-mutt-send-email-mst@kernel.org> <056ba905a2579903a372258383afdf6579767ad0.camel@redhat.com> <20220907034407-mutt-send-email-mst@kernel.org> <20220908011858-mutt-send-email-mst@kernel.org> <20221009160520-mutt-send-email-mst@kernel.org> In-Reply-To: From: Jason Wang Date: Mon, 17 Oct 2022 15:15:12 +0800 Message-ID: Subject: Re: [PATCH net] virtio-net: add cond_resched() to the command waiting loop To: "Michael S. Tsirkin" Cc: Jakub Kicinski , Paolo Abeni , netdev , linux-kernel , virtualization , Eric Dumazet , Gautam Dawar , davem Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.4 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=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 On Wed, Oct 12, 2022 at 11:19 AM Jason Wang wrote: > > On Tue, Oct 11, 2022 at 1:11 AM Michael S. Tsirkin wrote= : > > > > On Sun, Oct 09, 2022 at 01:58:53PM +0800, Jason Wang wrote: > > > > > > =E5=9C=A8 2022/9/8 13:19, Michael S. Tsirkin =E5=86=99=E9=81=93: > > > > On Thu, Sep 08, 2022 at 10:21:45AM +0800, Jason Wang wrote: > > > > > =E5=9C=A8 2022/9/7 15:46, Michael S. Tsirkin =E5=86=99=E9=81=93: > > > > > > On Wed, Sep 07, 2022 at 09:07:20AM +0200, Paolo Abeni wrote: > > > > > > > On Wed, 2022-09-07 at 10:09 +0800, Jason Wang wrote: > > > > > > > > On Tue, Sep 6, 2022 at 6:56 PM Paolo Abeni wrote: > > > > > > > > > On Mon, 2022-09-05 at 15:49 +0800, Jason Wang wrote: > > > > > > > > > > On Mon, Sep 5, 2022 at 3:15 PM Michael S. Tsirkin wrote: > > > > > > > > > > > On Mon, Sep 05, 2022 at 12:53:41PM +0800, Jason Wang = wrote: > > > > > > > > > > > > Adding cond_resched() to the command waiting loop f= or a better > > > > > > > > > > > > co-operation with the scheduler. This allows to giv= e CPU a breath to > > > > > > > > > > > > run other task(workqueue) instead of busy looping w= hen preemption is > > > > > > > > > > > > not allowed. > > > > > > > > > > > > > > > > > > > > > > > > What's more important. This is a must for some vDPA= parent to work > > > > > > > > > > > > since control virtqueue is emulated via a workqueue= for those parents. > > > > > > > > > > > > > > > > > > > > > > > > Fixes: bda324fd037a ("vdpasim: control virtqueue su= pport") > > > > > > > > > > > That's a weird commit to fix. so it fixes the simulat= or? > > > > > > > > > > Yes, since the simulator is using a workqueue to handle= control virtueue. > > > > > > > > > Uhmm... touching a driver for a simulator's sake looks a = little weird. > > > > > > > > Simulator is not the only one that is using a workqueue (bu= t should be > > > > > > > > the first). > > > > > > > > > > > > > > > > I can see that the mlx5 vDPA driver is using a workqueue a= s well (see > > > > > > > > mlx5_vdpa_kick_vq()). > > > > > > > > > > > > > > > > And in the case of VDUSE, it needs to wait for the response= from the > > > > > > > > userspace, this means cond_resched() is probably a must for= the case > > > > > > > > like UP. > > > > > > > > > > > > > > > > > Additionally, if the bug is vdpasim, I think it's better = to try to > > > > > > > > > solve it there, if possible. > > > > > > > > > > > > > > > > > > Looking at vdpasim_net_work() and vdpasim_blk_work() it l= ooks like > > > > > > > > > neither needs a process context, so perhaps you could rew= ork it to run > > > > > > > > > the work_fn() directly from vdpasim_kick_vq(), at least f= or the control > > > > > > > > > virtqueue? > > > > > > > > It's possible (but require some rework on the simulator cor= e). But > > > > > > > > considering we have other similar use cases, it looks bette= r to solve > > > > > > > > it in the virtio-net driver. > > > > > > > I see. > > > > > > > > > > > > > > > Additionally, this may have better behaviour when using for= the buggy > > > > > > > > hardware (e.g the control virtqueue takes too long to respo= nd). We may > > > > > > > > consider switching to use interrupt/sleep in the future (bu= t not > > > > > > > > suitable for -net). > > > > > > > Agreed. Possibly a timeout could be useful, too. > > > > > > > > > > > > > > Cheers, > > > > > > > > > > > > > > Paolo > > > > > > Hmm timeouts are kind of arbitrary. > > > > > > regular drivers basically derive them from hardware > > > > > > behaviour but with a generic driver like virtio it's harder. > > > > > > I guess we could add timeout as a config field, have > > > > > > device make a promise to the driver. > > > > > > > > > > > > Making the wait interruptible seems more reasonable. > > > > > > > > > > Yes, but I think we still need this patch for -net and -stable. > > > > > > > > > > Thanks > > > > I was referring to Paolo's idea of having a timeout. > > > > > > > > > Ok, I think we're fine with this patch. Any chance to merge this or d= o I > > > need to resend? > > > > > > Thanks > > > > Last question: do we want cpu_relax here now? Or is cond_resched > > sufficient? > > (Have answered in another thread) > > I think we need cpu_relax() since there could be no high priority task > in the current cpu so we still need to relax. > > Thanks Michael, does this answer make sense? If yes, would you like to ack the pat= ch? Thanks > > > > > > > > > > > >