Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1110260rbb; Sun, 25 Feb 2024 21:08:40 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW2r/iS/fUHZHhh6Xh4hq+38kI0zfKyGsE1YPl+JLLrg3lfD6uOPmYI3L/A8ArjWgt/2ZYy1ViV1A2upzZjc757+rB9trKcz7P3Fk1Gqg== X-Google-Smtp-Source: AGHT+IGERODDdRBW2/iYgWmGtipB1k9YSY9J+TmvCWSF5ucia1rMp0VdsWOqAit7hWptyUPV31Oi X-Received: by 2002:a17:90a:6542:b0:299:8ff:40c0 with SMTP id f2-20020a17090a654200b0029908ff40c0mr3546496pjs.28.1708924120318; Sun, 25 Feb 2024 21:08:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708924120; cv=pass; d=google.com; s=arc-20160816; b=ifK3ObE3G29LoPm0XTBzYqE3Z9dl+mt4cbp52O6a88h55hmmlURJeqGU0D9zCrELNI k4zbaILXR6Ixd6PIHM80B09K8CNb+I0N1NpzaMALTQZSsJ861NWk3Cd28Dsp+9Umv0oU IfEGcwk9wj+AOYAo8lm0hxpTbOSAyvrRVU2hEJEAh3gSZow/6fGYEbQDcY9TmDRfnEG9 w/jch7QYAAEWfExMTxqUFOR5tthrNR4OSzKhEL+j4lOJJ4vR5TzI7GnLItMk7eNxWyyH IPe65MRUBTkx5RAjs7WZPrJJyrL2XzyFNzKvDl4PxgjCNifiP1/QSJRrUqv44iBfhvs0 FQZQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=d0IX1RHQfM6abvabBeCW943C4eGRN4zTgrwGo510uTA=; fh=9HVyGC3U42M8VtpsAfocS1/+uaHFdyBM6h7ZqfByKk4=; b=WWaIwdEamJj2bOUa5uQA/7T/iJzs/2reRAoHv3Q91EIPNlAQfdz3DwGCm08TL9OtFU FZKcyxUpx85ZZuR76GR4MXgzBGzBfwmnUkal/7y0nYTcZ2kh0gYlun1CU7igqcB/H1lF 32t6ISQmw33bsnPLz/dDIVRLbDeO8kc29W80PczSrIsfDdGLh0TBE8ayPvPJelNOGoj4 QfXCxJjKmv3q1WuEEyP2SC0/dR3pfayXtpHHWLqTg1rNTSWEH60yxO33P1yJRbmbrQ6O VFP5gA3pH8O0Oti1yKQHxe8ZV6l1KTZuHd3YEZfHMTFcGlHZQ7b+7pd1GQlKHif3hok0 au0w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RmYCNUXy; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-80561-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80561-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id b12-20020a6541cc000000b005e46be657e9si1588176pgq.424.2024.02.25.21.08.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 21:08:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80561-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RmYCNUXy; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-80561-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80561-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 058F3281286 for ; Mon, 26 Feb 2024 05:08:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A99A41B968; Mon, 26 Feb 2024 05:08:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RmYCNUXy" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 883811B81C for ; Mon, 26 Feb 2024 05:08:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708924113; cv=none; b=Zn5Qh+u9tAJIf/Rb4lahDMfws1bvaIauQrbXCtXWWzE6cu+Ft/ikfPcVnsSVxGJ0VJYyC0UHjXY1BjGEARsgueiX9hc2I3gOdAGOt1+509TNrnNwahzjTF4EhCSdUwwGQ3RkhOLwfixe2mZ0a2wIjepKqM7pShsVeoGbFVoMTsU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708924113; c=relaxed/simple; bh=E88zUaazKWvIhjWloT5l/8WyHuvQl96BzJs4ChOIkvc=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=n0pEGesH3jRIjGAj9PAYwnNmEDXdF9oYaE9rsduTX/vVoW/Gysh80d0/2QBjo9E6dJ0XPXOgjGUEdebtyfnq1PuxH1wp4+4dxpQZ2/b5L82o2dPqTwAQV/Hj/9QebDvMaZDEKp29wtU+b8OZZhNdas8h6zj4pD1fNjslYwydaNg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=RmYCNUXy; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1708924110; 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=d0IX1RHQfM6abvabBeCW943C4eGRN4zTgrwGo510uTA=; b=RmYCNUXylhNixz5PKIaKZ+8LS5Wha5BkdO4fz62zsfeNhqeEI2djCk1leFvfzqtnHo+hCw q8wf4tvgHRrK6ScoxEFJkYq4esNBgAVWWhPGKD8sLP5h2ExJbfErei3GrENmH7VUol0P2z XgutJ0FnIQXtMAHAGjWUn1ulbs4Y3Zw= Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-443-1Dh2yYWVPo2GT0hAdRQ4Ng-1; Mon, 26 Feb 2024 00:08:18 -0500 X-MC-Unique: 1Dh2yYWVPo2GT0hAdRQ4Ng-1 Received: by mail-pj1-f69.google.com with SMTP id 98e67ed59e1d1-29a9f042643so371853a91.0 for ; Sun, 25 Feb 2024 21:08:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708924097; x=1709528897; 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=d0IX1RHQfM6abvabBeCW943C4eGRN4zTgrwGo510uTA=; b=gqXNXjD7sITLJJPL1v0iGV4lEzqnS4Ww5zTwp/1bByQDZSz75ByQ+GeTCnAB4Txf6U r/I447kM30TvHPYuRgWViCTwG/ikOSDzpVZwmqxqmCmT8SbIUjeks6/+V+akYmce4Fmw ddijH1wLd/FPE/bu5u6mGUZ7mLKXImkOEUAJZJF+sY/naB87giBtaCS7Kd4H+ziitxc4 lPDGC/YOuOSt2ykSRBQkVw7pfW4zvvKqIj6W2ek6kQwDFCzdOzSI4rmOu2X/dtv7ZvcQ +y9Z14Srcp/WUuseWPT/CDNPqv8iB0QgpIg0Yu0AmoPVa5ZFsA/aqAnSI0O8ax2yuyYo igWA== X-Forwarded-Encrypted: i=1; AJvYcCVZZFhCpWxOFdLbX1VcK84OfH7aIpzDx4zhhZZ/xPXjeiGMBQCno8DqF2LQ3a3jaMoFZUFze/AUdAOYuC1MI7ZaYyYYi4GQt1Gwzpif X-Gm-Message-State: AOJu0YwBhYxKlt2XQO9shKayasPJMtlbVcBP/Jg4ORPjdPOyLNgx2KHO wbV+InSZBrGrvysII/pZedvbLao6ElNI++tacHB+FnM7abA534jpaufFm7BFre4642SSBmH47tY LxA0NuN7wk+GW/bQNwsTS/iYTpGEDXStknUqFW5VASTfbbEjzKgYDGgUdwJfxN/t3o2mvMqAGWG hbxs/0at564GH75MTqKprBxJghlUPVWADkNEsY X-Received: by 2002:a17:90a:f682:b0:29a:a3e1:7ab4 with SMTP id cl2-20020a17090af68200b0029aa3e17ab4mr2087473pjb.20.1708924097516; Sun, 25 Feb 2024 21:08:17 -0800 (PST) X-Received: by 2002:a17:90a:f682:b0:29a:a3e1:7ab4 with SMTP id cl2-20020a17090af68200b0029aa3e17ab4mr2087458pjb.20.1708924097198; Sun, 25 Feb 2024 21:08:17 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <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> <20230724031732-mutt-send-email-mst@kernel.org> <20240222142056-mutt-send-email-mst@kernel.org> In-Reply-To: <20240222142056-mutt-send-email-mst@kernel.org> From: Jason Wang Date: Mon, 26 Feb 2024 13:08:06 +0800 Message-ID: Subject: Re: [PATCH net-next v4 2/2] virtio-net: add cond_resched() to the command waiting loop To: "Michael S. Tsirkin" Cc: Maxime Coquelin , Shannon Nelson , xuanzhuo@linux.alibaba.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Feb 23, 2024 at 3:22=E2=80=AFAM Michael S. Tsirkin = wrote: > > On Tue, Jul 25, 2023 at 11:03:11AM +0800, Jason Wang wrote: > > On Mon, Jul 24, 2023 at 3:18=E2=80=AFPM Michael S. Tsirkin wrote: > > > > > > On Mon, Jul 24, 2023 at 02:52:49PM +0800, Jason Wang wrote: > > > > On Mon, Jul 24, 2023 at 2:46=E2=80=AFPM Michael S. Tsirkin wrote: > > > > > > > > > > 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 wro= te: > > > > > > > > > > > > > > > > > > > > > > > > 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 Nel= son 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 g= ive CPU a breath to > > > > > > > > > > > > > run other task(workqueue) instead of busy looping= when preemption 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 d= oesn't pin the 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 stat= us? > > > > > > > > > > > > > > > > > > virtio spec does not set any limits on the timing of vq > > > > > > > > > processing. > > > > > > > > > > > > > > > > Indeed, but I thought the driver could decide it is too lon= g for it. > > > > > > > > > > > > > > > > The issue is we keep waiting with rtnl locked, it can quick= ly make the > > > > > > > > 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 reconfig= uration is > > > > > > performed when the VDUSE device is added, and when a MLX5 devic= e is > > > > > > in the same bridge, it ends up doing an ioctl() that tries to t= ake the > > > > > > rtnl lock. In this configuration, it is not possible to kill OV= S because > > > > > > it is stuck trying to acquire rtnl lock for mlx5 that is held b= y virtio- > > > > > > net. > > > > > > > > > > So for sure, we can queue up the work and process it later. > > > > > The somewhat tricky part is limiting the memory consumption. > > > > > > > > And it needs to sync with rtnl somehow, e.g device unregistering wh= ich > > > > seems not easy. > > > > > > > > Thanks > > > > > > since when does device unregister need to send cvq commands? > > > > It doesn't do this now. But if we don't process the work under rtnl, > > we need to synchronize with device unregistering. > > > > Thanks > > But what's not easy about it? Yes, so I'm wondering if we can simply have the cond_resched() merged as the first step. And leave the indefinite wait for future investigation? Thanks > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > 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/n= et/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_c= ommand(struct virtnet_info *vi, u8 class, u8 cmd, > > > > > > > > > > > > > * into the hypervisor, so the reques= t should be handled immediately. > > > > > > > > > > > > > */ > > > > > > > > > > > > > while (!virtqueue_get_buf(vi->cvq, &t= mp) && > > > > > > > > > > > > > - !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/listinf= o/virtualization > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >