From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 7123E18C31 for ; Mon, 20 Jan 2025 01:58:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737338312; cv=none; b=P1EpE7B7UAI5dAQ/u0dODq3T3ojtE7ySqSGeDSz+AwHxMYUICO8NSw0iaFbmBs4PYttvaiX6+cxhNL5rPYBOSiBNXmFk4TZymMX/S3AfNFdkp3gvoI1EJjhZZkx0Q489Nl2yIwgKV3hrlfM56ggDSGI5CWc60YEQgpwOlfFZFM4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737338312; c=relaxed/simple; bh=yuBc5+h/9lwzieCgUsFLqW7znh5vXegnrIKqqEjuQzU=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=K4HoLCF9w6syTxn4K+hJ98cXRikTdxUKpLh0DYhgjc5lSd42GTbyvzqqFyd30udGN4lRwkvPEk4BBHzCLobqNnTdOdZBVsCQJ2ceplcuvBkPaBxZwsUkqHdEifTIupoF1v7mNC/afvBrt+6cl7xAU+DOM6NyDMXOukKt6IdmERw= 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=QPx2S4gX; arc=none smtp.client-ip=170.10.133.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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="QPx2S4gX" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737338309; 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=vs03IIGJhVXqCXgVeBmydwl5duKVva078mHRQk4T/Vo=; b=QPx2S4gXvSD8RjYsshD3PG/iACjtUml4Oxpnq+AkYQFpzd4GGXFXB4XPAEB++VKWUpStb4 MgauW51ouKmThxgZ5GuG59vf0kTAGtTVKC1aN4HTXyLxhSpBSgG1dazp8ojI6FREkT5wnO mqBIaEcRLNLa87CjpcY6dd0+BORNX3g= Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-460-4hoqrPSyNSakHwRQxPvglQ-1; Sun, 19 Jan 2025 20:58:27 -0500 X-MC-Unique: 4hoqrPSyNSakHwRQxPvglQ-1 X-Mimecast-MFC-AGG-ID: 4hoqrPSyNSakHwRQxPvglQ Received: by mail-pj1-f72.google.com with SMTP id 98e67ed59e1d1-2ef909597d9so11283109a91.3 for ; Sun, 19 Jan 2025 17:58:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737338306; x=1737943106; 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=vs03IIGJhVXqCXgVeBmydwl5duKVva078mHRQk4T/Vo=; b=KjEE4y8FEkzckmdXZBLzcG38JwHBnzfZGOTqeWin0Ahd6Hzvx4i80CEh6j5fTSVUTW KhhmF48gAit3XSMScrYcX+0LQbYJO3lzj3w9iO+ntDzdWN+A1HKGiIUY+zuQOkmq49WF 12tTRKZGjT+LPugfnVUyQnnXQYgu16U3ah+9dTeHkdgNxoEx0k4IMA9zoS2Sf1Z12Ksp aNAmgqusZhPxPAepkzuKntmU2Ofiml0plVMV7FiKLmh4oq3UO/4yKkyt2eGZDHVT2h8e 4EX5Ca1OQX0ZTEAT063z/330DQiXT7rByHey6S0/9BmbgECgb3xbbblEOnYPKcwL35Bb VrHw== X-Forwarded-Encrypted: i=1; AJvYcCUlGamL/UjJrd1lYGaiav83QKTKw5N+ccBxQbuAXSICLsCRK8X1PPIH6lBFSCaksfS9OG4AhsytY6Dy5r8=@vger.kernel.org X-Gm-Message-State: AOJu0YyU813eh0ZsozI+qH9xyHGzXcqsWZsdxwMSO7Xy3/3znzuSKPi6 ZVammVSr2Yo5RRmpeFVQEC/nilPwm9MJDUll+f6FYj99smp90dgfFtgYxqj5I8OmCmDWhBopvGY Ex1hOGIXh1mnqN6rl77y1RukcHyvzp1QPDHgymL58YHtOVzdobG1iyG7452yOjoHox3wmQ3EDD2 AqpWrH7MF9IlOhzYwLSKLkn/5BBefEyduZcGUW X-Gm-Gg: ASbGncunZj8464MZGJE4RhvgYLB1JGcMS3u6QIn9lnhkkx8tUQiX/TzViTVxMZwmLyk BZ2a5GlRuZFdWLXa8rOtnlcSmu3qvTxSs4tkrWk5YpKynqAMPqrpj X-Received: by 2002:a17:90b:2750:b0:2ee:aef4:2c5d with SMTP id 98e67ed59e1d1-2f782d32bdcmr14441682a91.26.1737338306238; Sun, 19 Jan 2025 17:58:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IGxcO+gcU6GGpItpVaST+mP+lotfH8ALDufTNkb6YlviJFAQ1S+ZPqhw8EXYw//ooixqAGk20ku9VsIkuS7U5A= X-Received: by 2002:a17:90b:2750:b0:2ee:aef4:2c5d with SMTP id 98e67ed59e1d1-2f782d32bdcmr14441654a91.26.1737338305832; Sun, 19 Jan 2025 17:58:25 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20250116055302.14308-1-jdamato@fastly.com> <20250116055302.14308-4-jdamato@fastly.com> <1737013994.1861002-1-xuanzhuo@linux.alibaba.com> In-Reply-To: <1737013994.1861002-1-xuanzhuo@linux.alibaba.com> From: Jason Wang Date: Mon, 20 Jan 2025 09:58:13 +0800 X-Gm-Features: AbW1kvarckGogeshrcvCGai-_wdzjzim8Cy3XTbYBj63sr-Fx1KKQaClUhGQeVc Message-ID: Subject: Re: [PATCH net-next v2 3/4] virtio_net: Map NAPIs to queues To: Xuan Zhuo Cc: Joe Damato , gerhard@engleder-embedded.com, leiyang@redhat.com, mkarsten@uwaterloo.ca, "Michael S. Tsirkin" , =?UTF-8?Q?Eugenio_P=C3=A9rez?= , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , "open list:VIRTIO CORE AND NET DRIVERS" , open list , "open list:XDP (eXpress Data Path):Keyword:(?:b|_)xdp(?:b|_)" , netdev@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Jan 16, 2025 at 3:57=E2=80=AFPM Xuan Zhuo wrote: > > On Thu, 16 Jan 2025 05:52:58 +0000, Joe Damato wrote= : > > Use netif_queue_set_napi to map NAPIs to queue IDs so that the mapping > > can be accessed by user apps. > > > > $ ethtool -i ens4 | grep driver > > driver: virtio_net > > > > $ sudo ethtool -L ens4 combined 4 > > > > $ ./tools/net/ynl/pyynl/cli.py \ > > --spec Documentation/netlink/specs/netdev.yaml \ > > --dump queue-get --json=3D'{"ifindex": 2}' > > [{'id': 0, 'ifindex': 2, 'napi-id': 8289, 'type': 'rx'}, > > {'id': 1, 'ifindex': 2, 'napi-id': 8290, 'type': 'rx'}, > > {'id': 2, 'ifindex': 2, 'napi-id': 8291, 'type': 'rx'}, > > {'id': 3, 'ifindex': 2, 'napi-id': 8292, 'type': 'rx'}, > > {'id': 0, 'ifindex': 2, 'type': 'tx'}, > > {'id': 1, 'ifindex': 2, 'type': 'tx'}, > > {'id': 2, 'ifindex': 2, 'type': 'tx'}, > > {'id': 3, 'ifindex': 2, 'type': 'tx'}] > > > > Note that virtio_net has TX-only NAPIs which do not have NAPI IDs, so > > the lack of 'napi-id' in the above output is expected. > > > > Signed-off-by: Joe Damato > > --- > > v2: > > - Eliminate RTNL code paths using the API Jakub introduced in patch = 1 > > of this v2. > > - Added virtnet_napi_disable to reduce code duplication as > > suggested by Jason Wang. > > > > drivers/net/virtio_net.c | 34 +++++++++++++++++++++++++++++----- > > 1 file changed, 29 insertions(+), 5 deletions(-) > > > > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c > > index cff18c66b54a..c6fda756dd07 100644 > > --- a/drivers/net/virtio_net.c > > +++ b/drivers/net/virtio_net.c > > @@ -2803,9 +2803,18 @@ static void virtnet_napi_do_enable(struct virtqu= eue *vq, > > local_bh_enable(); > > } > > > > -static void virtnet_napi_enable(struct virtqueue *vq, struct napi_stru= ct *napi) > > +static void virtnet_napi_enable(struct virtqueue *vq, > > + struct napi_struct *napi) > > { > > + struct virtnet_info *vi =3D vq->vdev->priv; > > + int q =3D vq2rxq(vq); > > + u16 curr_qs; > > + > > virtnet_napi_do_enable(vq, napi); > > + > > + curr_qs =3D vi->curr_queue_pairs - vi->xdp_queue_pairs; > > + if (!vi->xdp_enabled || q < curr_qs) > > + netif_queue_set_napi(vi->dev, q, NETDEV_QUEUE_TYPE_RX, na= pi); > > So what case the check of xdp_enabled is for? +1 and I think the XDP related checks should be done by the caller not here= . > > And I think we should merge this to last commit. > > Thanks. > Thanks > > } > > > > static void virtnet_napi_tx_enable(struct virtnet_info *vi, > > @@ -2826,6 +2835,20 @@ static void virtnet_napi_tx_enable(struct virtne= t_info *vi, > > virtnet_napi_do_enable(vq, napi); > > } > > > > +static void virtnet_napi_disable(struct virtqueue *vq, > > + struct napi_struct *napi) > > +{ > > + struct virtnet_info *vi =3D vq->vdev->priv; > > + int q =3D vq2rxq(vq); > > + u16 curr_qs; > > + > > + curr_qs =3D vi->curr_queue_pairs - vi->xdp_queue_pairs; > > + if (!vi->xdp_enabled || q < curr_qs) > > + netif_queue_set_napi(vi->dev, q, NETDEV_QUEUE_TYPE_RX, NU= LL); > > + > > + napi_disable(napi); > > +} > > + > > static void virtnet_napi_tx_disable(struct napi_struct *napi) > > { > > if (napi->weight) > > @@ -2842,7 +2865,8 @@ static void refill_work(struct work_struct *work) > > for (i =3D 0; i < vi->curr_queue_pairs; i++) { > > struct receive_queue *rq =3D &vi->rq[i]; > > > > - napi_disable(&rq->napi); > > + virtnet_napi_disable(rq->vq, &rq->napi); > > + > > still_empty =3D !try_fill_recv(vi, rq, GFP_KERNEL); > > virtnet_napi_enable(rq->vq, &rq->napi); > > > > @@ -3042,7 +3066,7 @@ static int virtnet_poll(struct napi_struct *napi,= int budget) > > static void virtnet_disable_queue_pair(struct virtnet_info *vi, int qp= _index) > > { > > virtnet_napi_tx_disable(&vi->sq[qp_index].napi); > > - napi_disable(&vi->rq[qp_index].napi); > > + virtnet_napi_disable(vi->rq[qp_index].vq, &vi->rq[qp_index].napi)= ; > > xdp_rxq_info_unreg(&vi->rq[qp_index].xdp_rxq); > > } > > > > @@ -3313,7 +3337,7 @@ static void virtnet_rx_pause(struct virtnet_info = *vi, struct receive_queue *rq) > > bool running =3D netif_running(vi->dev); > > > > if (running) { > > - napi_disable(&rq->napi); > > + virtnet_napi_disable(rq->vq, &rq->napi); > > virtnet_cancel_dim(vi, &rq->dim); > > } > > } > > @@ -5932,7 +5956,7 @@ static int virtnet_xdp_set(struct net_device *dev= , struct bpf_prog *prog, > > /* Make sure NAPI is not using any XDP TX queues for RX. */ > > if (netif_running(dev)) { > > for (i =3D 0; i < vi->max_queue_pairs; i++) { > > - napi_disable(&vi->rq[i].napi); > > + virtnet_napi_disable(vi->rq[i].vq, &vi->rq[i].nap= i); > > virtnet_napi_tx_disable(&vi->sq[i].napi); > > } > > } > > -- > > 2.25.1 > > >