From patchwork Tue Jan 21 19:10:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Damato X-Patchwork-Id: 13946499 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A48A01F76A7 for ; Tue, 21 Jan 2025 19:11:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737486673; cv=none; b=Qta2HK7Zfewse+FBhn8K06R52IwXMvp0kvYdhUuplPWoUs0lejIHMeKXQGNyqgRcl8uPt87cO7pN4T63ervHmdSbcwqfc4oj8y/RdUo4W4ogB94E21n/irxWd88qjO5Rek4E8neCrjRUnENdAQfzPC/DbryaK4/DIPjRJQvqELE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737486673; c=relaxed/simple; bh=36m+Ryb9CJuvJR9nbvQowFH7ClbOSrNUnAqBaTNmIQY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Z9JUqUTHPh8F+uNRrc1r5XRdNN/1qlOMK5hUJBhfEUL9fymw+VSpjb6JSzQNz//ZcP3KeVgkwBmF8BBFVW+4v4OFHmAW4apiSgQJloNPO5KHVKE4epI1RXODl4XwXJfLNJqHrIlTIPo5BfqJC/iZZdhMHodEK1i7uf/XrAk761g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com; spf=pass smtp.mailfrom=fastly.com; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b=X422TL3N; arc=none smtp.client-ip=209.85.216.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fastly.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b="X422TL3N" Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-2eed82ca5b4so10396023a91.2 for ; Tue, 21 Jan 2025 11:11:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1737486669; x=1738091469; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FDwiQXOb0dtbRJ3DmhupJOiqoOo1ySphxgwOZ65b5Lc=; b=X422TL3NgiDRJB9TLcq0u5EBu2w1v5ZZuFriMvZtJRVPqlQxCpFEvdkuozAlgADo09 wrb0sKV4WC9ZNLGRbw7W4vYgPAn2rVo0JLUNJ87Fe9XyeyP9qBsPpvuz/K/ND6pG3KaF XzomIJxyA9JzADSCTyp9SgLZo2+8jQppuyxc4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737486669; x=1738091469; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FDwiQXOb0dtbRJ3DmhupJOiqoOo1ySphxgwOZ65b5Lc=; b=UkdrJOhmZ6R1qy2Yo5CojuEQUnFojPR/sm87QG+NfgwizJ2Lyt24HVvKAWS8zLNtUL gSQ3KSVmWTnKVaSjoOUm8u6UGCGul+k40rIUs0Z1UniG68upovPJY+nbWHKWLQgDtwjK G0VP3AHKHJTrX5lk0ku2NZQUhyczCyJT5bELP+w9Hyrj3UWarjDWxNN27QWbXhvvCRj0 Md1FUiWybd/xvzhESXI9WOHn3EwNRFXtQCwBAZ+2F5S9UqbeWItmStF48O/dGmTjKbB2 beuZr1/S3R5X6tfAy9OHmByLOh6KHolIyTbqIoKp966nKOr1l9HZvMQHj1o8a3T+qquY 1VVw== X-Gm-Message-State: AOJu0YzShw03Sswymf2w+wzcenIsHM/AIG52/HCSvt8fIU1EKNzP7YCL GhxURFnHC+o9cUqWNx64OKt11sCid5hfau1FUHnKxPhgElnpNnlKswIkOEolvUKUT3YhyrqCBCj YZFVZP/HF+CmGcblizq1WI/zvbj2hmhnbo0/cfwRlUWs5kBc/7m4sMMPf3kPnsN+iXuhtkOVMT7 nTh0Kxpkcj8mYMRiEWKFPLKJ5QWryTrQLnPFY= X-Gm-Gg: ASbGncvehyzVa/hFBn35cs/wFXq75hf5Xz48lNDATI1QftUoKmt3zdPeLcBWIEmDTfI 3dkZbMNcgpnUZOMOmvJw9DIqjKCTCuE+Q6BXgWnlrZsjMR5d1GQ79kogbCaTWBpKovM0g8jeBwp U/hVWbkcnpNLMojbWKV8q7ittPZLbT/7gSxvinTTDpQNNdj4BYow5E4M+s8zikc6Senu8q70WJf Bi0n/EZqCl0SKfTSGjUF5Dxb4ActLfAlYKs29m9NTa5/g6y5PQwn3XpRfPmncm4j6AZ794PVOir pg== X-Google-Smtp-Source: AGHT+IFrbRJ/R0m0SceTG3oQbb0XNatc3hOdnfunYdBKaQ+YC8e4bymwDNEoE5iJLWgFoSXDDDTmQQ== X-Received: by 2002:a17:90a:d60f:b0:2ef:31a9:95af with SMTP id 98e67ed59e1d1-2f782d32956mr26450648a91.27.1737486668611; Tue, 21 Jan 2025 11:11:08 -0800 (PST) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f7db6ab125sm1793440a91.26.2025.01.21.11.11.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jan 2025 11:11:08 -0800 (PST) From: Joe Damato To: netdev@vger.kernel.org Cc: gerhard@engleder-embedded.com, jasowang@redhat.com, leiyang@redhat.com, xuanzhuo@linux.alibaba.com, mkarsten@uwaterloo.ca, Jakub Kicinski , Joe Damato , Andrew Lunn , "David S. Miller" , Eric Dumazet , Paolo Abeni , Simon Horman , Kuniyuki Iwashima , Sebastian Andrzej Siewior , Lorenzo Bianconi , Alexander Lobakin , linux-kernel@vger.kernel.org (open list) Subject: [RFC net-next v3 1/4] net: protect queue -> napi linking with netdev_lock() Date: Tue, 21 Jan 2025 19:10:41 +0000 Message-Id: <20250121191047.269844-2-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250121191047.269844-1-jdamato@fastly.com> References: <20250121191047.269844-1-jdamato@fastly.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC From: Jakub Kicinski netdev netlink is the only reader of netdev_{,rx_}queue->napi, and it already holds netdev->lock. Switch protection of the writes to netdev->lock as well. Add netif_queue_set_napi_locked() for API completeness, but the expectation is that most current drivers won't have to worry about locking any more. Today they jump thru hoops to take rtnl_lock. Signed-off-by: Jakub Kicinski Reviewed-by: Joe Damato --- v2: - Added in v2 from Jakub. include/linux/netdevice.h | 9 +++++++-- include/net/netdev_rx_queue.h | 2 +- net/core/dev.c | 16 +++++++++++++--- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 8da4c61f97b9..4709d16bada5 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -691,7 +691,7 @@ struct netdev_queue { * slow- / control-path part */ /* NAPI instance for the queue - * Readers and writers must hold RTNL + * Readers and writers must hold netdev->lock */ struct napi_struct *napi; @@ -2467,7 +2467,8 @@ struct net_device { * Partially protects (writers must hold both @lock and rtnl_lock): * @up * - * Also protects some fields in struct napi_struct. + * Also protects some fields in: + * struct napi_struct, struct netdev_queue, struct netdev_rx_queue * * Ordering: take after rtnl_lock. */ @@ -2694,6 +2695,10 @@ static inline void *netdev_priv(const struct net_device *dev) void netif_queue_set_napi(struct net_device *dev, unsigned int queue_index, enum netdev_queue_type type, struct napi_struct *napi); +void netif_queue_set_napi_locked(struct net_device *dev, + unsigned int queue_index, + enum netdev_queue_type type, + struct napi_struct *napi); static inline void netdev_lock(struct net_device *dev) { diff --git a/include/net/netdev_rx_queue.h b/include/net/netdev_rx_queue.h index 596836abf7bf..9fcac0b43b71 100644 --- a/include/net/netdev_rx_queue.h +++ b/include/net/netdev_rx_queue.h @@ -23,7 +23,7 @@ struct netdev_rx_queue { struct xsk_buff_pool *pool; #endif /* NAPI instance for the queue - * Readers and writers must hold RTNL + * Readers and writers must hold netdev->lock */ struct napi_struct *napi; struct pp_memory_provider_params mp_params; diff --git a/net/core/dev.c b/net/core/dev.c index afa2282f2604..ab361fd9efd9 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -6842,14 +6842,24 @@ EXPORT_SYMBOL(dev_set_threaded); */ void netif_queue_set_napi(struct net_device *dev, unsigned int queue_index, enum netdev_queue_type type, struct napi_struct *napi) +{ + netdev_lock(dev); + netif_queue_set_napi_locked(dev, queue_index, type, napi); + netdev_unlock(dev); +} +EXPORT_SYMBOL(netif_queue_set_napi); + +void netif_queue_set_napi_locked(struct net_device *dev, + unsigned int queue_index, + enum netdev_queue_type type, + struct napi_struct *napi) { struct netdev_rx_queue *rxq; struct netdev_queue *txq; if (WARN_ON_ONCE(napi && !napi->dev)) return; - if (dev->reg_state >= NETREG_REGISTERED) - ASSERT_RTNL(); + netdev_assert_locked_or_invisible(dev); switch (type) { case NETDEV_QUEUE_TYPE_RX: @@ -6864,7 +6874,7 @@ void netif_queue_set_napi(struct net_device *dev, unsigned int queue_index, return; } } -EXPORT_SYMBOL(netif_queue_set_napi); +EXPORT_SYMBOL(netif_queue_set_napi_locked); static void napi_restore_config(struct napi_struct *n) { From patchwork Tue Jan 21 19:10:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Damato X-Patchwork-Id: 13946498 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F8DB1F76A6 for ; Tue, 21 Jan 2025 19:11:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737486673; cv=none; b=rcuyRnfgjxp5wkHrfj90nMpZLYOtAz6yCsKkFCrZe/bZbztClPQB+gIBfjmzGE2AgfNe+0oIu61gy3LN+eNiYldNNUyI8+aLvbSPO+GaIkZ2oMtfkMKPjojowEtwZTxTuq8euRKcDXjlpCYu+MzQaE7e5EUbQ+LWQjhwiheVo5U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737486673; c=relaxed/simple; bh=QoUuXeDBulZSbVMdrI5zM6Eg9lCr5hgBtBOzJbP8zEQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TxjbpxDjkofaXxthyGv4uVVTDUNrXqpi7I15rA5ZYfOZhamKoZfrnxSCHwUtC2t/iPJskHMolQlAzshAweWb5LqIu8yqzD0EnhalNBTNr72qSO2Nh5XhBhEGsqcF8s/QmcIl0gSl1vBjxjlmo5fgOAndk6hbyfyATco1Zh26Rd0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com; spf=pass smtp.mailfrom=fastly.com; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b=mW1YJNsK; arc=none smtp.client-ip=209.85.216.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fastly.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b="mW1YJNsK" Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-2efb17478adso10409961a91.1 for ; Tue, 21 Jan 2025 11:11:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1737486670; x=1738091470; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9sIKGTHIeBOioZLiUeQpKiV7N2jyLH+xFiew0830fKc=; b=mW1YJNsKjJg3HwaDbspcfvC0mniLoI8kV23X/hka0pO+ouLoZml9Vs7ap2X1XJHyZv fUMQGuk1ERBHcgg5+lBnmOwUNKXzD5EmnjyPV9Kz451uNgEqY3bqpKUhJNrqgxO0288+ eE9MkHE8xncJh6i0ATwM/HN9Y6Y9pdaBO3eVA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737486670; x=1738091470; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9sIKGTHIeBOioZLiUeQpKiV7N2jyLH+xFiew0830fKc=; b=aQ0sSw1akY64+LduiBJMTxbVPnblhduA9u08sGCYzmQJ2eNsbPne6vywLXtVttAH0v bHKIGC/zHff9L0OsoKVNNuCqMPRi8DbqIQtVmKv7KcCU/VqQhCGIwnNXw7z5a9+Ue0+r URVV11gDfFuTnDCGEAjL1jijG/UWqbRIVvpr/ZFRmcjadWAtQe0SKVhJECCkYjNcQBMf GQiJXEHLwEPlF5JPAqeHKeimzu++zoA0tW7UCX7hhA8jPpXEpaNhyMukhvnMZ1EZ1EjU KvWz6xJddlI3d63cQ4no4VtycCUAXUF/EA6apzCE0W5U6/Fq5Bd2DXJOdbgM/u86xZcG v4JQ== X-Gm-Message-State: AOJu0YzbbHdkzzNjhRriOss0ifLYbWv+BC8ixxGcUu2AdY8XQX11L+Bb Z7ITf1w2DswRiS+9RYndwnfxOIB5g+OZ6mJZST8DOMVi0SIYARsNqOcCG458hyjuXQqdHDqv2qw pZ9g/gmcKEQAdy9OOQ8TK2tS2Zz79lGFQph097hy3JmsrWWlybs8KkDZAqFtLzaXevN614b88ro jGFcuQPCFcpMmwEGJBuONYKZo2fsJ/fQoYAQg= X-Gm-Gg: ASbGnculRhHhPF2DBtf3z6Br5zfYPaBqmzE7NGOQKWdIs/6hfXPl8mtLE9+0NuUcNYc +8tzDNFrU6Wsj5yvf1xloYsvq6t6YIjRMacq5nu75YJBhEdVMlLn7YleO7+gC9iOG2O7msnsywZ c6t3DehLPfq0p5dS0j0chsk68FYkoz2cCI3Wre1+tOi1u7OsoN9BbB62CWYfn1OCh9ePkk35HfH iAl2IKy+evUbnoRh4kW9pCUTNRnBEddNc5ZhxKj8fvFA4z97KsPbwCv8ql9nyaCuyh0m6LVFi3m gQ== X-Google-Smtp-Source: AGHT+IE4irALDUjtpmu8CkVPCmQyuHgMI1XADWpZWozR+u77nlArMTYTrKbNpUm0btjkrguF/oTbgg== X-Received: by 2002:a17:90b:4c06:b0:2ee:7862:1b10 with SMTP id 98e67ed59e1d1-2f782c701f7mr28198326a91.11.1737486670370; Tue, 21 Jan 2025 11:11:10 -0800 (PST) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f7db6ab125sm1793440a91.26.2025.01.21.11.11.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jan 2025 11:11:09 -0800 (PST) From: Joe Damato To: netdev@vger.kernel.org Cc: gerhard@engleder-embedded.com, jasowang@redhat.com, leiyang@redhat.com, xuanzhuo@linux.alibaba.com, mkarsten@uwaterloo.ca, Joe Damato , "Michael S. Tsirkin" , =?utf-8?q?Eugenio_P=C3=A9rez?= , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , virtualization@lists.linux.dev (open list:VIRTIO CORE AND NET DRIVERS), linux-kernel@vger.kernel.org (open list) Subject: [RFC net-next v3 2/4] virtio_net: Prepare for NAPI to queue mapping Date: Tue, 21 Jan 2025 19:10:42 +0000 Message-Id: <20250121191047.269844-3-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250121191047.269844-1-jdamato@fastly.com> References: <20250121191047.269844-1-jdamato@fastly.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Slight refactor to prepare the code for NAPI to queue mapping. No functional changes. Signed-off-by: Joe Damato Reviewed-by: Gerhard Engleder Tested-by: Lei Yang Acked-by: Jason Wang --- v2: - Previously patch 1 in the v1. - Added Reviewed-by and Tested-by tags to commit message. No functional changes. drivers/net/virtio_net.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 7646ddd9bef7..cff18c66b54a 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -2789,7 +2789,8 @@ static void skb_recv_done(struct virtqueue *rvq) virtqueue_napi_schedule(&rq->napi, rvq); } -static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *napi) +static void virtnet_napi_do_enable(struct virtqueue *vq, + struct napi_struct *napi) { napi_enable(napi); @@ -2802,6 +2803,11 @@ static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *napi) local_bh_enable(); } +static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *napi) +{ + virtnet_napi_do_enable(vq, napi); +} + static void virtnet_napi_tx_enable(struct virtnet_info *vi, struct virtqueue *vq, struct napi_struct *napi) @@ -2817,7 +2823,7 @@ static void virtnet_napi_tx_enable(struct virtnet_info *vi, return; } - return virtnet_napi_enable(vq, napi); + virtnet_napi_do_enable(vq, napi); } static void virtnet_napi_tx_disable(struct napi_struct *napi) From patchwork Tue Jan 21 19:10:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Damato X-Patchwork-Id: 13946500 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ECD051F666C for ; Tue, 21 Jan 2025 19:11:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737486674; cv=none; b=bHtDG3BZefKud3k2Dk5nqsQczjAlvRNxhFix8Ubsc4NdBPSvKCG9n05gF7/muD+JY3ZxS4BAoLXEki8xg0J2E3ubYIazmatSmwWLZqGcjCvVoagzg+DK5UD13pMacRnwoJME2jR370NWw6CO1ndNR+RToAC7AShRrmANGAlvsfw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737486674; c=relaxed/simple; bh=CCW7kggp+rYbKpVhb0njIkNRisnJGwdMk+Hd84d4x2g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ERzkvF/uhNeqDJ8/Wo+SxlGT3+CjgRRSWpX0C5r4g04ND//EPiICMarJRy3RKF2AFuvWHB6RQpyGc3SnDQRPaKKVRsMX9yYeMP6lWAPGZGALYrFheK+4FKlb6fqv9kfDvw3JCP25sTNDRWfPha18bvOAnmXMjC7id1hwpinAgY0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com; spf=pass smtp.mailfrom=fastly.com; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b=MBzaNvjs; arc=none smtp.client-ip=209.85.216.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fastly.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b="MBzaNvjs" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-2ee51f8c47dso8325077a91.1 for ; Tue, 21 Jan 2025 11:11:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1737486672; x=1738091472; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BIxZmc2dYAqFea8fzwYrgwOnSbwHFqsyPk6MUVa0VxU=; b=MBzaNvjse7oevDYEBFWFKxZbDmgGUTUeZuKqKDYYq6jYzXhWxsXrb7XPPXxhnhTtKE 9sirjjKXjzShNZ3fJBquEHmrtN3LKamzoC0YboN1lcadLa21ntzmmmoL/W7hzWwutDca wU19tnULStfkBwK7iTMX/kWcBxHKbQNAML64E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737486672; x=1738091472; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BIxZmc2dYAqFea8fzwYrgwOnSbwHFqsyPk6MUVa0VxU=; b=DFFLW58y3r+reFocPOA/3BOT2B2jetd+/PteELueIyaPr4N6eR+UHeFW8ajUhMQBe3 RqMSbsrcwx3sZKbOxyG5qSjmwCzkYFNZGi5lH0B+6UBT3WTjW8/wZIRqsqTkRDfHA3JL 9r1N9oh0ndd8WI36Wi398PCboRY+l1hBEl4q/h4m0HSsKwhk0OM/xpPsb5LZBEO0iKuy 4qrh5krso4JvlhotOXhExb5RlevA5fB2hvP+/FT7gTVt2d5ODiLflGfToZxwW6rHEh6U 5qFOx/ZpSWb1qDZX+1vDW6ewFcGKrgdE5hioaDp38ooqrRC3dQfKmgeMUDWxNFEnJHAc 5KeQ== X-Gm-Message-State: AOJu0YxFLE0ApAgcC+AkPLVcc/vaEQ1Bf79QkwSvw/ctDKxXqDpIaXCw BbeWwOXWgAV3uoIO9avIoErz80P6C9GmSROcCKvXb9ZxRMQPAhMEePfwsVPcTULWQjJYTDm0oZl wTpNvK3k+HSnT3ypv0ltI329WYhUCj6U7YJwzVwgomra0DH8KDdVBNJ665evxAaosjqkvkMOFNx JDuCCeTb7ANv4xWlhPneNkKsWhrb556LMJeJc= X-Gm-Gg: ASbGncsgcjk9+n0ngA7OwT4t0ep33nL72nIZYw61m6ukMyiG3diCmDn1b1HWGjAxRId oEk15891fkGBLQM3eghnXTZIf6Gtw1odfAItw5z310er4o7K/lUlzKO1klPLBW7hDm3/nRKmuva 6q+KLaGdkz1c2f8c5CudXjTCPEje9c4Ld4B6sURjfNsDjEALGud1UErKxGknWCU9NN7SL3fT5/T UHoBxdvzGOPOuFlxIzVr0I4yWk+121eXP48Q4Jcq+pGQU+2jrtODO2nEeOUpTd//ENdLBip1l0Y yA== X-Google-Smtp-Source: AGHT+IFmMAsVqWPTr/+MdaRMifAEOsKB5cFMykGXnqvqzynVvQlUx7VWgc1M158q6rlxSpFG7RmfQw== X-Received: by 2002:a17:90b:5206:b0:2f4:f7f8:fc8b with SMTP id 98e67ed59e1d1-2f782d4ed77mr26908949a91.27.1737486672019; Tue, 21 Jan 2025 11:11:12 -0800 (PST) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f7db6ab125sm1793440a91.26.2025.01.21.11.11.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jan 2025 11:11:11 -0800 (PST) From: Joe Damato To: netdev@vger.kernel.org Cc: gerhard@engleder-embedded.com, jasowang@redhat.com, leiyang@redhat.com, xuanzhuo@linux.alibaba.com, mkarsten@uwaterloo.ca, Joe Damato , "Michael S. Tsirkin" , =?utf-8?q?Eugenio_P=C3=A9rez?= , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , virtualization@lists.linux.dev (open list:VIRTIO CORE AND NET DRIVERS), linux-kernel@vger.kernel.org (open list) Subject: [RFC net-next v3 3/4] virtio_net: Map NAPIs to queues Date: Tue, 21 Jan 2025 19:10:43 +0000 Message-Id: <20250121191047.269844-4-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250121191047.269844-1-jdamato@fastly.com> References: <20250121191047.269844-1-jdamato@fastly.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC 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='{"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 Reviewed-by: Gerhard Engleder Acked-by: Jason Wang --- rfcv3: - Eliminated XDP checks; NAPIs will always be mapped to RX queues, as Gerhard Engleder suggested. 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 | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index cff18c66b54a..c120cb2106c0 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -2805,7 +2805,11 @@ static void virtnet_napi_do_enable(struct virtqueue *vq, static void virtnet_napi_enable(struct virtqueue *vq, struct napi_struct *napi) { + struct virtnet_info *vi = vq->vdev->priv; + virtnet_napi_do_enable(vq, napi); + + netif_queue_set_napi(vi->dev, vq2rxq(vq), NETDEV_QUEUE_TYPE_RX, napi); } static void virtnet_napi_tx_enable(struct virtnet_info *vi, @@ -2826,6 +2830,16 @@ static void virtnet_napi_tx_enable(struct virtnet_info *vi, virtnet_napi_do_enable(vq, napi); } +static void virtnet_napi_disable(struct virtqueue *vq, + struct napi_struct *napi) +{ + struct virtnet_info *vi = vq->vdev->priv; + + netif_queue_set_napi(vi->dev, vq2rxq(vq), NETDEV_QUEUE_TYPE_RX, NULL); + + napi_disable(napi); +} + static void virtnet_napi_tx_disable(struct napi_struct *napi) { if (napi->weight) @@ -2842,7 +2856,8 @@ static void refill_work(struct work_struct *work) for (i = 0; i < vi->curr_queue_pairs; i++) { struct receive_queue *rq = &vi->rq[i]; - napi_disable(&rq->napi); + virtnet_napi_disable(rq->vq, &rq->napi); + still_empty = !try_fill_recv(vi, rq, GFP_KERNEL); virtnet_napi_enable(rq->vq, &rq->napi); @@ -3042,7 +3057,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 +3328,7 @@ static void virtnet_rx_pause(struct virtnet_info *vi, struct receive_queue *rq) bool running = 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 +5947,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 = 0; i < vi->max_queue_pairs; i++) { - napi_disable(&vi->rq[i].napi); + virtnet_napi_disable(vi->rq[i].vq, &vi->rq[i].napi); virtnet_napi_tx_disable(&vi->sq[i].napi); } } From patchwork Tue Jan 21 19:10:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Damato X-Patchwork-Id: 13946501 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7F571F756A for ; Tue, 21 Jan 2025 19:11:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737486677; cv=none; b=ruCm4U048S8ouwPIZ1dyGnB4qBS36zCiGhordRCYxaX+geSOkyuMdXfB5lBpRARDLDZUZ1QpGLR8Lv7hs7Rzzu2pteFQGP6ELqBn0bc7oFYoQwl8ngi9RdlnUy5TnjPgLszJh6G178m5prCUlmTKph6wB5pC/CDw2VDmrNIfojc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737486677; c=relaxed/simple; bh=ps14zeISRQUrPp/FMjIu7GyzXnHtSdfWr0SOARpLgXs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tlJz5CmE5CVJfZ8VZNCU29EgvGFBWNJ6xeHSuvv8Xfg21GK7BePIRweBcnC9xaTyu33wp1IgffLeeFiy9ygDYhu+jJvuiMRpe/p6VJG1ygmVcGK6tWulPjU7mt9PBrzYGVM0/YPgl74+VBPbVH2AJ2cC1hGSZsApsmtq90thKHg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com; spf=pass smtp.mailfrom=fastly.com; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b=pur3n1eb; arc=none smtp.client-ip=209.85.216.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fastly.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b="pur3n1eb" Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-2f78a4ca5deso5634201a91.0 for ; Tue, 21 Jan 2025 11:11:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1737486674; x=1738091474; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TDWORuj0wvWXpxW0vCuhr9iAbZl0aXjuDP2zaKtZhzU=; b=pur3n1ebv8zuooOE/arc+KlWluLbCtB9xruX4vpTQ6NiTkMzaHw7VPrDhR1BcgH4lL CyJks5qAVeGcS1LdwgW4wqbgl33qPJHesRgyUhU1NyuRtmReP5YSHMRT9AEk4EAqTlXW fvuxR4gXbTJIMd6eA5cgZQbYECsCXxwOlpMOE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737486674; x=1738091474; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TDWORuj0wvWXpxW0vCuhr9iAbZl0aXjuDP2zaKtZhzU=; b=miJCeWKQDYlaDUIvs1WSGXOqhrN4MYFERCAV77I9a/wSqX0CL0L04n33SHfUh9sq8T Y9FGAwcoiANWerSKPxDdGv7zWFNCkTQdNh7MzAotpZ+K/o+Boj3f9mETI/UzIkPCglW9 rO1J2R2OiwSkat8HSp7d1RRSJfRoWpvlVmxMo6nvijdM2RVoEpMsH7gL7xENr4mWw37K YBaV4MtWDox+yg/gheH5LPlhex4M0LHoK1Y875oRSmsq5eo243eMS7HrIk4ZGhLCZD2e wil7GZ8heaR30kCRSceVf3MvQYqpHSFg+YVLnJS8+I4xPwvp6JDgjmnRf9MsJiZbvW5/ Dz3Q== X-Gm-Message-State: AOJu0YydZY4nniU7BnXkcMWWcCYdyStaVlASPXksI7FI/Xk4mJGYqoJn Wji161isDrXCss/B5tXOftyLHyAumu9dwLoc5hW3ZFUQSbwHLoZA0MDbecswnpm2LdUmqreqZU6 XU4gvIeq9EYsbErIbfQ9MSkXQQ+EMIN00t6nniT/sWbapysKlspV+QPG5hzaI18ZBli81NkZ9Nv RtUDEsmS+5f49QNt44rhHH1GKnKseE2Cqqlco= X-Gm-Gg: ASbGncv69y8o6eHFCYD1N34Oz1E0r4hp8WTYD52ZYRTqB7cXFebPkaBvDuhYGNkdEZ9 /TXALk1laxjCVQPhBQkwINV5kC9H3bss2M6sTg66MC07nhjVRSauXjBGlWsYfdZigIru4FJ1Zyk Hnt3wv2taiBDsnAh+uiivWZHMvxA/5NYl+peHSGPpSn12BqScaZHlpAvP6+KMC7Xrorya/wHL+I 7B8rqPEhM0w1eB9iU1DQkW4tB8z6DFCh4DRVUnPvX8jrm6/7ouZHR8EUWCRJt0Jk7Q5qazzVq0a Qg== X-Google-Smtp-Source: AGHT+IEb+ow9B8HMeKsPl0hXMsb+u+xhEKMUqjLwNXvMEkGNBJdrkESWe8cbHdWnNyIQHfkYMacpPA== X-Received: by 2002:a17:90a:c888:b0:2f4:f7f8:fc8a with SMTP id 98e67ed59e1d1-2f782d8cd4emr28724895a91.33.1737486673632; Tue, 21 Jan 2025 11:11:13 -0800 (PST) Received: from localhost.localdomain ([2620:11a:c019:0:65e:3115:2f58:c5fd]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f7db6ab125sm1793440a91.26.2025.01.21.11.11.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jan 2025 11:11:13 -0800 (PST) From: Joe Damato To: netdev@vger.kernel.org Cc: gerhard@engleder-embedded.com, jasowang@redhat.com, leiyang@redhat.com, xuanzhuo@linux.alibaba.com, mkarsten@uwaterloo.ca, Joe Damato , "Michael S. Tsirkin" , =?utf-8?q?Eugenio_P=C3=A9rez?= , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , virtualization@lists.linux.dev (open list:VIRTIO CORE AND NET DRIVERS), linux-kernel@vger.kernel.org (open list) Subject: [RFC net-next v3 4/4] virtio_net: Use persistent NAPI config Date: Tue, 21 Jan 2025 19:10:44 +0000 Message-Id: <20250121191047.269844-5-jdamato@fastly.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20250121191047.269844-1-jdamato@fastly.com> References: <20250121191047.269844-1-jdamato@fastly.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Use persistent NAPI config so that NAPI IDs are not renumbered as queue counts change. $ sudo ethtool -l ens4 | tail -5 | egrep -i '(current|combined)' Current hardware settings: Combined: 4 $ ./tools/net/ynl/pyynl/cli.py \ --spec Documentation/netlink/specs/netdev.yaml \ --dump queue-get --json='{"ifindex": 2}' [{'id': 0, 'ifindex': 2, 'napi-id': 8193, 'type': 'rx'}, {'id': 1, 'ifindex': 2, 'napi-id': 8194, 'type': 'rx'}, {'id': 2, 'ifindex': 2, 'napi-id': 8195, 'type': 'rx'}, {'id': 3, 'ifindex': 2, 'napi-id': 8196, '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'}] Now adjust the queue count, note that the NAPI IDs are not renumbered: $ sudo ethtool -L ens4 combined 1 $ ./tools/net/ynl/pyynl/cli.py \ --spec Documentation/netlink/specs/netdev.yaml \ --dump queue-get --json='{"ifindex": 2}' [{'id': 0, 'ifindex': 2, 'napi-id': 8193, 'type': 'rx'}, {'id': 0, 'ifindex': 2, 'type': 'tx'}] $ sudo ethtool -L ens4 combined 8 $ ./tools/net/ynl/pyynl/cli.py \ --spec Documentation/netlink/specs/netdev.yaml \ --dump queue-get --json='{"ifindex": 2}' [{'id': 0, 'ifindex': 2, 'napi-id': 8193, 'type': 'rx'}, {'id': 1, 'ifindex': 2, 'napi-id': 8194, 'type': 'rx'}, {'id': 2, 'ifindex': 2, 'napi-id': 8195, 'type': 'rx'}, {'id': 3, 'ifindex': 2, 'napi-id': 8196, 'type': 'rx'}, {'id': 4, 'ifindex': 2, 'napi-id': 8197, 'type': 'rx'}, {'id': 5, 'ifindex': 2, 'napi-id': 8198, 'type': 'rx'}, {'id': 6, 'ifindex': 2, 'napi-id': 8199, 'type': 'rx'}, {'id': 7, 'ifindex': 2, 'napi-id': 8200, 'type': 'rx'}, [...] Signed-off-by: Joe Damato Reviewed-by: Xuan Zhuo Reviewed-by: Gerhard Engleder Acked-by: Jason Wang --- rfcv3: - Added Xuan Zhuo's Reviewed-by tag. No functional changes. 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 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index c120cb2106c0..e0752a856adf 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -6411,8 +6411,9 @@ static int virtnet_alloc_queues(struct virtnet_info *vi) INIT_DELAYED_WORK(&vi->refill, refill_work); for (i = 0; i < vi->max_queue_pairs; i++) { vi->rq[i].pages = NULL; - netif_napi_add_weight(vi->dev, &vi->rq[i].napi, virtnet_poll, - napi_weight); + netif_napi_add_config(vi->dev, &vi->rq[i].napi, virtnet_poll, + i); + vi->rq[i].napi.weight = napi_weight; netif_napi_add_tx_weight(vi->dev, &vi->sq[i].napi, virtnet_poll_tx, napi_tx ? napi_weight : 0);