Received: by 2002:ab2:2441:0:b0:1f3:1f8c:d0c6 with SMTP id k1csp216759lqe; Thu, 4 Apr 2024 04:55:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXFlHLNTYnNpt9/rPXxTxg0gP31LGhDNHbvT0WmUc4I/NkQRjFR1acvjbCRdBXTI+A+H7h+A9Xt1ToKHWK6v2UfyGvfyBkBjqePrdEpWQ== X-Google-Smtp-Source: AGHT+IGRdxGN8TtkD3oKjSkdwozwOeZhqtas0S1nU/wgI05S7n/4/tbk/BuvxoxyAbUcAYPRLauF X-Received: by 2002:a05:6a21:18f:b0:1a3:dc12:d253 with SMTP id le15-20020a056a21018f00b001a3dc12d253mr2786673pzb.46.1712231757616; Thu, 04 Apr 2024 04:55:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712231757; cv=pass; d=google.com; s=arc-20160816; b=yvgEdj6vKT9AtyD1SvLY/nSMOzDgfqengFBj+ry8y+kdqtNtwlaogIU1wF/ewhi1TZ F/ONSB3fpOqjKeOPAXivMrjm5ReaQzKGJ+YBfbOiTHQq2sFTb+/cwIP535n14pvRfFqj ea0a0l36nJHHk9fwfy+/DExdJ36W8Mp09rE9KlZSnkxlqpSoyPsoDRRicsjtuFexxQAe WGnUpxgxX8VVTc0RA+IoK+fy9cZPtkJ8/5hOVT9AFkYO+VBA711iEifW4aotB7S93S8D 1F76PFDQW6BAeY5XaltqhwH0InzAveOzm+SyRzwWAvoyuJfqXBJCD4qlGaOrtXMHp8Nf NteQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=mzV7bmg3PRLALaaFv1RRGYLnCVfom7cRGx1C8pOQ9QY=; fh=hHIxnLfR283iQL9/MU2AWnzMit7H4Wl+XysAdfCsRNU=; b=BS7WzBlnkYG7rR5TOIba2WePWYdtVyZWQeZDlrfKXU9TQ1XzXfT6zjdKRgDvBuaVDB psU/e/f16sHaUOxhVEG4YlbNGO5ZjhT8wCxP+dZoRgJfdPvO6kvHDHHpveKakDqzarxr 71SdWsHkEeALYren0vR4LX6FryVsWz5Vi4lAcBvDzqV+NVc79AUl7eh5/h8NASIXrsFY K6TNAClLxG1TwBA7z4ico5WFsClctImgSeie1DYDxAVF5L8MMKrI1WZCHG7ggNU767Z9 aM6kC6GoqPDvWOuMLrpQUvR7/fATOv2JxbG6AfPxY9+L/FirkgmnoQNnGpQx409poAxY lMfg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-131338-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131338-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id x18-20020a056a000bd200b006e8f569a4bcsi14892959pfu.63.2024.04.04.04.55.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 04:55:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-131338-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-131338-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131338-linux.lists.archive=gmail.com@vger.kernel.org" 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 91ECDB2841C for ; Thu, 4 Apr 2024 11:51:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1F8621272DC; Thu, 4 Apr 2024 11:49:57 +0000 (UTC) Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (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 9346883A09; Thu, 4 Apr 2024 11:49:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712231396; cv=none; b=X5oD/3lalvmJrJyEJUNh4BoL+9KHrW3EIUvvCzqr0enSl0w9NrSyNwJMMkU46Z3ZRvFurPuJBKsfQtpd7KmAlsYie4yWSykhoN6/SBACFshjIFODJuk/oBKOiMhjfQOzAhyQ+AywP/RoLgG5mDM1J4zTdBv1G2rsmdA+vgBl1R4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712231396; c=relaxed/simple; bh=gwO1hPaZXP+m4dVvrYPFJWjxftCBwr9ksSRyI1NV7pY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r1126pneQv+OQmgunIsCwwh3M5QMl7sCD9rLcC6cJyJQiquhM0k6fNHDsS1h4N54d6772rX6SaU/TsB8POTX6fz8yTzrlTf4fi1FflUNbfrfMDRV6D9hihHChMKlv/2y1YPyx8Y9FLXQ2jhKvCEIcjFs1Edx3v0IQycuym8hhEE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.208.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-56e1f3462caso500000a12.3; Thu, 04 Apr 2024 04:49:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712231393; x=1712836193; 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=mzV7bmg3PRLALaaFv1RRGYLnCVfom7cRGx1C8pOQ9QY=; b=mXOMrME4cD1SAERP1W4TTm2R4RWVEIzCAoaOJWoYEV6nQkdU/gnskOdz/RH8lT1P/x QnBzCB5hmlHS1qk+tsGCGQYpqOoSycKJX9EPn0mfu+zSBpF6AHfRE/hB3VbJBVtxQ0+Z iUpRwlJe5ZIT40ikCPO4r/SxZQkz4Euga2VtWyPYYtUbU8OrC9V7gT2bJQhBq7i5/28r 3eT7hE9tV+Woyk9rkwR+RNc3farWXcH/DtGdFDs4SZOTtV+dVDRqjDRZreXVcfU5WlLs L8okUTESAbypD4YXwcUdw5OjzVsOnGNIiL+0W57SwXtrrJiPOQ5ag81ago+vsViTdyum lgPg== X-Forwarded-Encrypted: i=1; AJvYcCV1yJKlPoEDSeSqlkbRYWgiIiZM3tc/goj6V8+dBwfZrwC7UgECojQTnmvu+yguKocg3RJFb4VfLYF3tLs5uX6uxH0Gz9NqwH0SBTfFJrhLKz9cq1DJYGQr1m7a2kuCwuS3qt14eIhkkfl7f1NGG+WPeXxZ6W9gS4gs X-Gm-Message-State: AOJu0YxdaN85cqe+FB/l8t+K8ziFi2yh4mar0VbR0Oot3FDQTfudDCX1 iDMbJUfEtb5keczCVKyZPY+cUqXnrgTHizV1irgwVAlHUHl1q+MR X-Received: by 2002:a17:906:3017:b0:a4e:23a1:9ede with SMTP id 23-20020a170906301700b00a4e23a19edemr1357499ejz.36.1712231392669; Thu, 04 Apr 2024 04:49:52 -0700 (PDT) Received: from localhost (fwdproxy-lla-004.fbsv.net. [2a03:2880:30ff:4::face:b00c]) by smtp.gmail.com with ESMTPSA id i3-20020a170906a28300b00a4e2f966196sm7943347ejz.86.2024.04.04.04.49.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 04:49:52 -0700 (PDT) From: Breno Leitao To: aleksander.lobakin@intel.com, kuba@kernel.org, davem@davemloft.net, pabeni@redhat.com, edumazet@google.com, elder@kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, nbd@nbd.name, sean.wang@mediatek.com, Mark-MC.Lee@mediatek.com, lorenzo@kernel.org, taras.chornyi@plvision.eu Cc: quic_jjohnson@quicinc.com, kvalo@kernel.org, leon@kernel.org, dennis.dalessandro@cornelisnetworks.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, Jiri Pirko , Simon Horman , Daniel Borkmann , Sebastian Andrzej Siewior Subject: [PATCH net-next v3 1/5] net: create a dummy net_device allocator Date: Thu, 4 Apr 2024 04:48:41 -0700 Message-ID: <20240404114854.2498663-2-leitao@debian.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240404114854.2498663-1-leitao@debian.org> References: <20240404114854.2498663-1-leitao@debian.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit It is impossible to use init_dummy_netdev together with alloc_netdev() as the 'setup' argument. This is because alloc_netdev() initializes some fields in the net_device structure, and later init_dummy_netdev() memzero them all. This causes some problems as reported here: https://lore.kernel.org/all/20240322082336.49f110cc@kernel.org/ Split the init_dummy_netdev() function in two. Create a new function called init_dummy_netdev_core() that does not memzero the net_device structure. Then have init_dummy_netdev() memzero-ing and calling init_dummy_netdev_core(), keeping the old behaviour. init_dummy_netdev_core() is the new function that could be called as an argument for alloc_netdev(). Also, create a helper to allocate and initialize dummy net devices, leveraging init_dummy_netdev_core() as the setup argument. This function basically simplify the allocation of dummy devices, by allocating and initializing it. Freeing the device continue to be done through free_netdev() Suggested-by: Jakub Kicinski Signed-off-by: Breno Leitao --- include/linux/netdevice.h | 3 +++ net/core/dev.c | 54 ++++++++++++++++++++++++++------------- 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 0c198620ac93..544767d218c0 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -4517,6 +4517,9 @@ static inline void netif_addr_unlock_bh(struct net_device *dev) void ether_setup(struct net_device *dev); +/* Allocate dummy net_device */ +struct net_device *alloc_netdev_dummy(int sizeof_priv); + /* Support for loadable net-drivers */ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name, unsigned char name_assign_type, diff --git a/net/core/dev.c b/net/core/dev.c index 818699dea9d7..4d0109f2fe80 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -10412,25 +10412,12 @@ int register_netdevice(struct net_device *dev) } EXPORT_SYMBOL(register_netdevice); -/** - * init_dummy_netdev - init a dummy network device for NAPI - * @dev: device to init - * - * This takes a network device structure and initialize the minimum - * amount of fields so it can be used to schedule NAPI polls without - * registering a full blown interface. This is to be used by drivers - * that need to tie several hardware interfaces to a single NAPI - * poll scheduler due to HW limitations. +/* Initialize the core of a dummy net device. + * This is useful if you are calling this function after alloc_netdev(), + * since it does not memset the net_device fields. */ -void init_dummy_netdev(struct net_device *dev) +static void init_dummy_netdev_core(struct net_device *dev) { - /* Clear everything. Note we don't initialize spinlocks - * are they aren't supposed to be taken by any of the - * NAPI code and this dummy netdev is supposed to be - * only ever used for NAPI polls - */ - memset(dev, 0, sizeof(struct net_device)); - /* make sure we BUG if trying to hit standard * register/unregister code path */ @@ -10451,8 +10438,28 @@ void init_dummy_netdev(struct net_device *dev) * its refcount. */ } -EXPORT_SYMBOL_GPL(init_dummy_netdev); +/** + * init_dummy_netdev - init a dummy network device for NAPI + * @dev: device to init + * + * This takes a network device structure and initialize the minimum + * amount of fields so it can be used to schedule NAPI polls without + * registering a full blown interface. This is to be used by drivers + * that need to tie several hardware interfaces to a single NAPI + * poll scheduler due to HW limitations. + */ +void init_dummy_netdev(struct net_device *dev) +{ + /* Clear everything. Note we don't initialize spinlocks + * are they aren't supposed to be taken by any of the + * NAPI code and this dummy netdev is supposed to be + * only ever used for NAPI polls + */ + memset(dev, 0, sizeof(struct net_device)); + init_dummy_netdev_core(dev); +} +EXPORT_SYMBOL_GPL(init_dummy_netdev); /** * register_netdev - register a network device @@ -11063,6 +11070,17 @@ void free_netdev(struct net_device *dev) } EXPORT_SYMBOL(free_netdev); +/** + * alloc_netdev_dummy - Allocate and initialize a dummy net device. + * @sizeof_priv: size of private data to allocate space for + */ +struct net_device *alloc_netdev_dummy(int sizeof_priv) +{ + return alloc_netdev(sizeof_priv, "dummy#", NET_NAME_UNKNOWN, + init_dummy_netdev_core); +} +EXPORT_SYMBOL_GPL(alloc_netdev_dummy); + /** * synchronize_net - Synchronize with packet receive processing * -- 2.43.0