Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1262460rdb; Sat, 7 Oct 2023 22:28:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEfTD0Sr/T6InMGaEGciOe5IvCZV8pU1a2sKbBMmyfEKivVaGGXiFR9IGyMj18aCJmsCVib X-Received: by 2002:a9d:6a02:0:b0:6c4:a036:cc1b with SMTP id g2-20020a9d6a02000000b006c4a036cc1bmr12575448otn.35.1696742933158; Sat, 07 Oct 2023 22:28:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696742933; cv=none; d=google.com; s=arc-20160816; b=HWJxIpYhvhPm7AkcNj31qlZ4NrVUyBbFXyxbMKhn3xE9OEHQIoqSrPe0hmrPhYzPZo 85Mnkn/zGgt8d2Xm3DOppREGqPNUUO60zWpy2ASzWJxSbsY2OcSOZjpAXcmaG1Msobl8 qvEyUU/PuiqXQjOQIq1JoEf5x3294JTmBF2u9bQND9XdhOF0LfJ0zC3DqHT5vM14ejmx pEu+7EwzISr8QjqG2iZqKup37+djbMe8sYX7uDvNyZh6zXi8xpBH8Ss8FwnNc8raKkRQ z/YlCE42n8cfZUoBvvphKQ2CnCZ+MW+0Af7ZaYzj8X49nVaJFYIY0EKdtXNtjUVfLkna IMyA== 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=R3DuPJ39xeiBlF91sjgXQDqI4pW2tcIwSz1HEGAz2Ig=; fh=Tqyy6QLxupa6zeGmlt4zWublQXYrCsOeVCTcb2I0eP4=; b=bTb6BrGhSV4/cBsXWESd18IaFudDtRiwjFqr6ESWMeBLWNbfR5uMeIE4+77u4tN+yn ZAL162kcW15A9q73+SN1HmsK+mvhS/L8h8TaFvCld48BPzgokMRON8c6ld8Cw6i7RfbV vBXWkMDNkGPeSVNiq5ipid1UcJlqWKsOQf8FQFwV0Uovl7MQhcZ+9J+Qx+x1w0BPN6qn QxQz0mo9l0D2W3pxIlsXPsXM2ONIocGMDyABj9wqnQbHcVjPF9k7kyrGS6zf+XM7OjnL GKhd8HJsBVpbuT7156V4VFVWUzw95dIhidVT5vNQIBVvuGzK8Ssc1nX7/bxTz9bBDvIc V6Zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Wy9o6+LY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id u134-20020a63798c000000b00578c9144913si6931808pgc.364.2023.10.07.22.28.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Oct 2023 22:28:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Wy9o6+LY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 3C0C28050603; Sat, 7 Oct 2023 22:28:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344382AbjJHF2U (ORCPT + 99 others); Sun, 8 Oct 2023 01:28:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344322AbjJHF2T (ORCPT ); Sun, 8 Oct 2023 01:28:19 -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 CC5E5B6 for ; Sat, 7 Oct 2023 22:27:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696742851; 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=R3DuPJ39xeiBlF91sjgXQDqI4pW2tcIwSz1HEGAz2Ig=; b=Wy9o6+LYQGrCuhJdwCrHGopxSX3GIIRUO1mTrZGQvxOlOf324TseZUcKghUt6+dO8SkDW/ drfyXsDBsx8pfLy5hbbzaMDwVIgFbfGSsh3U8hZhMAQaBZo0JQKdFHihnLymHg+Wa8o+px K968EHrnqo6BhlVUneoNGX2h3WxUR/Q= Received: from mail-lf1-f71.google.com (mail-lf1-f71.google.com [209.85.167.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-677-CW919gnrMcm_EKVSIq110w-1; Sun, 08 Oct 2023 01:27:19 -0400 X-MC-Unique: CW919gnrMcm_EKVSIq110w-1 Received: by mail-lf1-f71.google.com with SMTP id 2adb3069b0e04-50483ed1172so285924e87.2 for ; Sat, 07 Oct 2023 22:27:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696742838; x=1697347638; 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=R3DuPJ39xeiBlF91sjgXQDqI4pW2tcIwSz1HEGAz2Ig=; b=pqmdHdjgcsMg6xcMRN8Dzg51VXA1aXLIWWCDwRzj/sE3NloQg7AZElR+aWNXtsy5Si vVVvTMkCFEloeuWVodPX1ZhhHdrpwMC+nMOXwI/3S2R2L57GHMYKHIkrmgEEXSzyui7F mtbK2GLV3+bTz0w08/0eCq9ErQKhTSH5lHSiTJmcwzwLQyNhDzaT3tn2+rEjEEGrZnev ufCbyaTB4Rkdaau5eJx5GZ8jojVSNnuSNsabLf7+rczjMfQ3+gNnfq6zEBhIc4owlcpt tVYkZ7bMh0kHYLGh8PDe7/Eq8X9ScuWyF2G6el0AmoYHm/E0hhnPR2X1Fg81RaMkd/Rd RCPQ== X-Gm-Message-State: AOJu0YxJGjzu0GoX8SYAbZ6Lp9LN5rgDD95QiX7EdG+WEZsHMeSVHqaa xkylqnWfs+k3qK86qopNo3WhmsRCClyffM+GU6qKKooqaN7+Ry2yj/iUlXgov9o2D5vqMh/FW4d TIW0Dcm7vgDyiUv2dP6iOETWjPo0SQjYChIygBC9N X-Received: by 2002:a05:6512:368f:b0:503:985:92c4 with SMTP id d15-20020a056512368f00b00503098592c4mr7934099lfs.52.1696742837926; Sat, 07 Oct 2023 22:27:17 -0700 (PDT) X-Received: by 2002:a05:6512:368f:b0:503:985:92c4 with SMTP id d15-20020a056512368f00b00503098592c4mr7934089lfs.52.1696742837587; Sat, 07 Oct 2023 22:27:17 -0700 (PDT) MIME-Version: 1.0 References: <20230720083839.481487-1-jasowang@redhat.com> <20230720083839.481487-3-jasowang@redhat.com> <20230720170001-mutt-send-email-mst@kernel.org> <263a5ad7-1189-3be3-70de-c38a685bebe0@redhat.com> <20230721104445-mutt-send-email-mst@kernel.org> <6278a4aa-8901-b0e3-342f-5753a4bf32af@redhat.com> <20230721110925-mutt-send-email-mst@kernel.org> <20230723053441-mutt-send-email-mst@kernel.org> <4d025b89-fa7a-df4b-37d0-96814a2d2bcb@nvidia.com> In-Reply-To: <4d025b89-fa7a-df4b-37d0-96814a2d2bcb@nvidia.com> From: Jason Wang Date: Sun, 8 Oct 2023 13:27:06 +0800 Message-ID: Subject: Re: [PATCH net-next v4 2/2] virtio-net: add cond_resched() to the command waiting loop To: Feng Liu Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, kuba@kernel.org, Bodong Wang Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=2.7 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Sat, 07 Oct 2023 22:28:50 -0700 (PDT) X-Spam-Level: ** On Fri, Oct 6, 2023 at 3:35=E2=80=AFAM Feng Liu wrote: > > > > On 2023-07-24 a.m.2:46, Michael S. Tsirkin wrote: > > External email: Use caution opening links or attachments > > > > > > On Fri, Jul 21, 2023 at 10:18:03PM +0200, Maxime Coquelin wrote: > >> > >> > >> On 7/21/23 17:10, Michael S. Tsirkin wrote: > >>> On Fri, Jul 21, 2023 at 04:58:04PM +0200, Maxime Coquelin wrote: > >>>> > >>>> > >>>> On 7/21/23 16:45, Michael S. Tsirkin wrote: > >>>>> On Fri, Jul 21, 2023 at 04:37:00PM +0200, Maxime Coquelin wrote: > >>>>>> > >>>>>> > >>>>>> On 7/20/23 23:02, Michael S. Tsirkin wrote: > >>>>>>> On Thu, Jul 20, 2023 at 01:26:20PM -0700, Shannon Nelson wrote: > >>>>>>>> On 7/20/23 1:38 AM, Jason Wang wrote: > >>>>>>>>> > >>>>>>>>> Adding cond_resched() to the command waiting loop for a better > >>>>>>>>> co-operation with the scheduler. This allows to give CPU a brea= th to > >>>>>>>>> run other task(workqueue) instead of busy looping when preempti= on is > >>>>>>>>> not allowed on a device whose CVQ might be slow. > >>>>>>>>> > >>>>>>>>> Signed-off-by: Jason Wang > >>>>>>>> > >>>>>>>> This still leaves hung processes, but at least it doesn't pin th= e CPU any > >>>>>>>> more. Thanks. > >>>>>>>> Reviewed-by: Shannon Nelson > >>>>>>>> > >>>>>>> > >>>>>>> I'd like to see a full solution > >>>>>>> 1- block until interrupt > >>>>>> > >>>>>> Would it make sense to also have a timeout? > >>>>>> And when timeout expires, set FAILED bit in device status? > >>>>> > >>>>> virtio spec does not set any limits on the timing of vq > >>>>> processing. > >>>> > >>>> Indeed, but I thought the driver could decide it is too long for it. > >>>> > >>>> The issue is we keep waiting with rtnl locked, it can quickly make t= he > >>>> system unusable. > >>> > >>> if this is a problem we should find a way not to keep rtnl > >>> locked indefinitely. > >> > >> From the tests I have done, I think it is. With OVS, a reconfiguratio= n is > >> performed when the VDUSE device is added, and when a MLX5 device is > >> in the same bridge, it ends up doing an ioctl() that tries to take the > >> rtnl lock. In this configuration, it is not possible to kill OVS becau= se > >> it is stuck trying to acquire rtnl lock for mlx5 that is held by virti= o- > >> net. > > > > So for sure, we can queue up the work and process it later. > > The somewhat tricky part is limiting the memory consumption. > > > > > > > Hi Jason > > Excuse me, is there any plan for when will v5 patch series be sent out? > Will the v5 patches solve the problem of ctrlvq's infinite poll for > buggy devices? We agree to harden VDUSE and, It would be hard if we try to solve it at the virtio-net level, see the discussions before. It might require support from various layers (e.g networking core etc). We can use workqueue etc as a mitigation. If Michael is fine with this, I can post v5. Thanks > > Thanks > Feng > > >>> > >>>>>>> 2- still handle surprise removal correctly by waking in that case > >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>>>> --- > >>>>>>>>> drivers/net/virtio_net.c | 4 +++- > >>>>>>>>> 1 file changed, 3 insertions(+), 1 deletion(-) > >>>>>>>>> > >>>>>>>>> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.= c > >>>>>>>>> index 9f3b1d6ac33d..e7533f29b219 100644 > >>>>>>>>> --- a/drivers/net/virtio_net.c > >>>>>>>>> +++ b/drivers/net/virtio_net.c > >>>>>>>>> @@ -2314,8 +2314,10 @@ static bool virtnet_send_command(struct = virtnet_info *vi, u8 class, u8 cmd, > >>>>>>>>> * into the hypervisor, so the request should be h= andled immediately. > >>>>>>>>> */ > >>>>>>>>> while (!virtqueue_get_buf(vi->cvq, &tmp) && > >>>>>>>>> - !virtqueue_is_broken(vi->cvq)) > >>>>>>>>> + !virtqueue_is_broken(vi->cvq)) { > >>>>>>>>> + cond_resched(); > >>>>>>>>> cpu_relax(); > >>>>>>>>> + } > >>>>>>>>> > >>>>>>>>> return vi->ctrl->status =3D=3D VIRTIO_NET_OK; > >>>>>>>>> } > >>>>>>>>> -- > >>>>>>>>> 2.39.3 > >>>>>>>>> > >>>>>>>>> _______________________________________________ > >>>>>>>>> Virtualization mailing list > >>>>>>>>> Virtualization@lists.linux-foundation.org > >>>>>>>>> https://lists.linuxfoundation.org/mailman/listinfo/virtualizati= on > >>>>>>> > >>>>> > >>> > > > > _______________________________________________ > > Virtualization mailing list > > Virtualization@lists.linux-foundation.org > > https://lists.linuxfoundation.org/mailman/listinfo/virtualization >