From patchwork Wed Apr 10 13:13:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 789294 Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.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 AD14015EFB3; Wed, 10 Apr 2024 13:17:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712755077; cv=none; b=q86/dEKbp5u3iG7jq6TVRYYJT1qCJZaHbhmaTt2KHTfRHsqlFQQIGLD39OJmr+N6T6DVLm0oACbA0QyO6ob/qoemeKiClhnLI51MWMj+wAKTfx6gWo4xfNppNtfspxVw9G1L6wOjKjbjaKudHLX042DlXQpDTioWl5I43397EJ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712755077; c=relaxed/simple; bh=Z9XshNGeaDkZA4YdqrH2pphdBGw4s2CGo/Ima80EU2Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cG/jy08gKFH3/jWndZTTDlIDAv51Eg6T8ako5QGQVXXLHK18CfQQQsyeajKN0RQ9KOTSQP3bmNu5JKyTstJGdBtmM0a+p9/bKJWdRkTiWBqq3ZbFbzfIGGQNpjhH0m2cR9bdLM/xylw5qJw7rBx3tKJZx8O81h2joQlifom78UM= 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.50 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-f50.google.com with SMTP id 4fb4d7f45d1cf-56e1bbdb362so8242941a12.1; Wed, 10 Apr 2024 06:17:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712755074; x=1713359874; 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=WCSWo+cbTjbJqU2UMVUeUJFNUS6Yf5iPYegXsbIUp/M=; b=E8vKbu6Keyv/TpBvb/tB0MO1y+Wb41cVv5magZIhIBDTmumdpQn5FWTb8UOOYJAIyw J5tYAgji1OEM90t7rf2lJf4NGJMIplpDHqDLovTsbQxdwONywZR+AbJ4woOFyh1rIQJC jLnSOqiOW52rrAtsJanywZAauMW/qKliIXRssU6JE689umFGd+GnZIkYm6k4izCfmkDi SS/3bYinq+qwrDqKlp5u0RBFZV2DSx6CqEoPYvZRRdziK4EFSgoEfKYzLVOClnkhaLaJ ORevlV/UR2qTmO1tVMezhTr4uEDpX89sLHaxJULUEOgGuddMjLryBEPeENKkb161Z9eq U1uQ== X-Forwarded-Encrypted: i=1; AJvYcCVSRs5V5OCAxiD+Of6bcuUFilR/5BdidkmMVTyIjzNKnY0v6P3tCiEKDiyxQngavJvkHdMJ79391LAnU3buN0EjqxhzWFCq3ZCtdjghK9JCOCxqZ0utcX3zqnTB2K+Qe9BGxtwJE5azM0V15TX6HFqX2cJC+JQcP7CAd8O04z6W1bGXWfKe1FwRuDJO48eP1VITOtyX1CnWcDM= X-Gm-Message-State: AOJu0YzqeR5DgPvePQ+9A0dnvxoIhQp8VWe+HkEPFKR/l4Zi1NHFSecg 8mEygi9tCOU6keYT2cxWdlDW7S949MO6ktszX8OMK/xcR69Lsjdg X-Google-Smtp-Source: AGHT+IFzohQ8nifeoYK9ng+dXMVkUWT33vP4drtn7UGXanZmNkg0eJxYz4rgtTa24o9nG26otr90ng== X-Received: by 2002:a50:baa4:0:b0:568:9d31:2a75 with SMTP id x33-20020a50baa4000000b005689d312a75mr2097283ede.4.1712755073613; Wed, 10 Apr 2024 06:17:53 -0700 (PDT) Received: from localhost (fwdproxy-lla-006.fbsv.net. [2a03:2880:30ff:6::face:b00c]) by smtp.gmail.com with ESMTPSA id y9-20020a056402440900b0056e3707323bsm5689027eda.97.2024.04.10.06.17.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 06:17: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, ath11k@lists.infradead.org, ath10k@lists.infradead.org, linux-wireless@vger.kernel.org, geomatsi@gmail.com, kvalo@kernel.org Cc: quic_jjohnson@quicinc.com, leon@kernel.org, dennis.dalessandro@cornelisnetworks.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, idosch@idosch.org, leitao@debian.org, Ido Schimmel , Jiri Pirko , Simon Horman , Daniel Borkmann , Sebastian Andrzej Siewior Subject: [PATCH net-next v5 01/10] net: core: Fix documentation Date: Wed, 10 Apr 2024 06:13:42 -0700 Message-ID: <20240410131407.3897251-2-leitao@debian.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240410131407.3897251-1-leitao@debian.org> References: <20240410131407.3897251-1-leitao@debian.org> Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Fix bad grammer in description of init_dummy_netdev() functio. This topic showed up in the review of the "allocate dummy device dynamically" patchset. Suggested-by: Ido Schimmel Signed-off-by: Breno Leitao --- net/core/dev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index 854a3a28a8d8..987039ffa63c 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -10418,7 +10418,7 @@ 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 + * This takes a network device structure and initializes 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 @@ -10427,7 +10427,7 @@ EXPORT_SYMBOL(register_netdevice); 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 + * as 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 */ From patchwork Wed Apr 10 13:13:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 787907 Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (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 D72AC15F326; Wed, 10 Apr 2024 13:17:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712755081; cv=none; b=cxxMOTQOf/R0Fkb1Vvd4ODZozZ5dIZZulmE0zenykarWN5gYXsW0l8H210RtyoWmxefSHUR65DOKRGV+kV6yVyjxgRpJjkOaXxzCsTKuLEhXNq1JJV0JnvGcf7+z4eLhOBCSNyHhnrZQyCfM/bB0KpBm/qK3isiin96Sfz2/l9s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712755081; c=relaxed/simple; bh=IjSM+bnQOTa8MUkSmM1LUl9F5EDiZx+DiNz4nR4/uGA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WAAraEWnxn+pOEFdqOoC30bFBE5l1ZPd2+HMPFa44hKuH/jxbws44rsqwnxocxPNo2X4QPGsQanfnqjGH4YzqmzZ+eEAlAQVGp4dNFQ3lT5MZc6TuwHkUIzb9JYcmtY70Q7tZkmfuHIqi8XHSgsIF0i3OItkJ/JnTGn+KCb652g= 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.42 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-f42.google.com with SMTP id 4fb4d7f45d1cf-56e2c1650d8so5218645a12.0; Wed, 10 Apr 2024 06:17:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712755078; x=1713359878; 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=occnMuVDkr0AXBDmVEHk6wT/diJ6dvMaufRR7UkwoZc=; b=IXYyc9iD5aRrmdVaCuuvq7slx5lGdSLxzVzUMZZtZhaIO9dZ04IKT7XegS5zs+cNb/ rXobiHZoJT2hXe8Lv5y2sWOY2m7VBrWujFB0yU0dAIOmFHj26qAvyAy4tf2exa6AxFi0 ZZmrY08qYPPFtWyvvSzjAMrlVPBtQM2v3tjpAxvhjiGawYFVaMGDlvAV97spONA/55F4 vJ9Nh2Dvx2JPm9H5LFoV0rO+QwUJ9ml1kKP68s1Z8ce/QM4PlFSn/GIHfK6Ti1l0pkms 4Bn9qKNz418LwY4xWqec7BioslgACcNI0MHgzlvnPQ3gNtZ8knEf7oIuxFgOuXasZicq UD/Q== X-Forwarded-Encrypted: i=1; AJvYcCVz0FBVRlUkj0bitS1GIGjdsBGJUVa9qxwt6lIX9Ihr10hliDJgL1jZeOwjV2vnour/MRmQDVwlgFU/CY+pMGZskFL4xdQ6+Vv73p+4uhqGWaVFm6crsQ5XcgPLnXGaDX5jVNmRF/VQ3apBY7CWCeF+uV8dbMSj4alveOFdWoVk432ZyErrf6QcAeOXcV61JPRTYGrqeoj6IRM= X-Gm-Message-State: AOJu0YzV1C0DxGKQrmdRs6npGC282tA9/lj8UCaOC72daxHDwpFnY/Qh escVPFe/WnkTgE8C8hHmYliV+lFF8nNX7xGXurOkizW+3EQ+dmUZ X-Google-Smtp-Source: AGHT+IFYz6nezPO0nvcRaOh3691IM+U3aDTWAVz3mLdQiEXd+y4Shu3fXDmKe+RO4EdGoiCoIVd5pg== X-Received: by 2002:a50:8e50:0:b0:56d:f3a7:60e with SMTP id 16-20020a508e50000000b0056df3a7060emr1782120edx.22.1712755077926; Wed, 10 Apr 2024 06:17:57 -0700 (PDT) Received: from localhost (fwdproxy-lla-006.fbsv.net. [2a03:2880:30ff:6::face:b00c]) by smtp.gmail.com with ESMTPSA id ij6-20020a056402158600b0056ddd9427d2sm6504617edb.58.2024.04.10.06.17.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 06:17:57 -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, ath11k@lists.infradead.org, ath10k@lists.infradead.org, linux-wireless@vger.kernel.org, geomatsi@gmail.com, kvalo@kernel.org Cc: quic_jjohnson@quicinc.com, leon@kernel.org, dennis.dalessandro@cornelisnetworks.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, idosch@idosch.org, leitao@debian.org, Jiri Pirko , Simon Horman , Daniel Borkmann , Sebastian Andrzej Siewior Subject: [PATCH net-next v5 02/10] net: free_netdev: exit earlier if dummy Date: Wed, 10 Apr 2024 06:13:43 -0700 Message-ID: <20240410131407.3897251-3-leitao@debian.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240410131407.3897251-1-leitao@debian.org> References: <20240410131407.3897251-1-leitao@debian.org> Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 For dummy devices, exit earlier at free_netdev() instead of executing the whole function. This is necessary, because dummy devices are special, and shouldn't have the second part of the function executed. Otherwise reg_state, which is NETREG_DUMMY, will be overwritten and there will be no way to identify that this is a dummy device. Also, this device do not need the final put_device(), since dummy devices are not registered (through register_netdevice()), where the device reference is increased (at netdev_register_kobject()/device_add()). Suggested-by: Jakub Kicinski Signed-off-by: Breno Leitao Reviewed-by: Ido Schimmel --- net/core/dev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/core/dev.c b/net/core/dev.c index 987039ffa63c..c74b42bc6888 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -11060,7 +11060,8 @@ void free_netdev(struct net_device *dev) phy_link_topo_destroy(dev->link_topo); /* Compatibility with error handling in drivers */ - if (dev->reg_state == NETREG_UNINITIALIZED) { + if (dev->reg_state == NETREG_UNINITIALIZED || + dev->reg_state == NETREG_DUMMY) { netdev_freemem(dev); return; } From patchwork Wed Apr 10 13:13:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 789293 Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.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 558EE160883; Wed, 10 Apr 2024 13:18:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712755086; cv=none; b=U50ZZofmOThHJErJSC+UcOLPvU8Oel4HPdYfp2Gu8C2ADhuFRzXVD1YVtLskokoGqG5S0P7yAsGZOVhAhKCeEe49cZrMsbNq1CNfpDhqP9YsXX3c9vhqPYEYs0buYIyLNTqF5pUTflbgu4yW7l4eEdhYtyu34ycjPa0VcpRyH08= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712755086; c=relaxed/simple; bh=mpHu4d4Q4JeZIMZ5puvyvVG8jptaMTEuga2ont41Wdo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bBK8EiPZpNPfw5ebERvPXOWCkmmLyXuiy4ShcEX2XBqr4u+Sb9O1x23i/PYEQ4OE+31omrnCEqog4dkO5zw/OCJ2whs1FugzjcSb5fswt2mU6Ts0i66eutQ5Hi9BL1kbK4CZAZXa+9vSoyDx8n5pi0l9zeUwXnG9Q0qCtE8eSP4= 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.48 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-f48.google.com with SMTP id 4fb4d7f45d1cf-56e477db7fbso6342071a12.3; Wed, 10 Apr 2024 06:18:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712755082; x=1713359882; 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=2GDpaKQ90WYO0sLid+cb+1t26hG02cHYGSR1vXVItmw=; b=kCaXD1h8MepT4SdSmf6YlZIZc7Kf/4EQswck/0z2ANPgAC6LDO2YHohfakDjoNVis4 fwK+GdvkJAmaZcA5CST0C2+a7j+Y3Kk4U9op4MBcq4BjSvCSwGx5Bsigtz+xCceqyOXy UfvAsH3oHqeNJ1fhVTyIJxsxm9Q/ltr6tuTjf51FxONxMhpCZl2XOdPjL3bBTtmP5RTC B+dE+TUermaerSXIA87uHQJj+x4N+a/mUhQyRtmQtbJZ585NEUdZPF3lkFUzVz7xElke 2exuLaBgkW+hTN62FeyYQSp44tFcs7NVbtEj9u1/rY57AK9GOFdv0oh6W/agcqfmrk/v 80Wg== X-Forwarded-Encrypted: i=1; AJvYcCXZQR++eU99T0FsjCbYat/XSlnFv+ZUBYFpDmwkYhCP9j24ZnOlWf41DZIs0ovhnu/u598n62NnvV/PXev4HAZ+dr1Ol8tmtR19mKN+bZDdMiOGvewCdtD2BFdq6Z4NZ5Gqzbk9BDLnScZ02XEr6fV7Kf+QhKz/hXrfO7anRx5WKYJ5Pa9CLZJL56UJyN0njetiLeVYeYjSC90= X-Gm-Message-State: AOJu0YwMioqvOKe7wPSsiRmyNKI4BLkM9fAMwcOePVZ5N47mBzkARhIl JwcFptIkXHfSqkLrEgECwIuIJ30UnMlU06dyH3Qrf9a2d83ax7yS X-Google-Smtp-Source: AGHT+IFB2h2wj+pUhlzhaGoVNqqjo/9uYytmBm9+9zCMtIRWllNip2uVE2aeJZshA4tzxKRVhkpMvw== X-Received: by 2002:a50:ab18:0:b0:56d:c4eb:6328 with SMTP id s24-20020a50ab18000000b0056dc4eb6328mr1697426edc.29.1712755082627; Wed, 10 Apr 2024 06:18:02 -0700 (PDT) Received: from localhost (fwdproxy-lla-118.fbsv.net. [2a03:2880:30ff:76::face:b00c]) by smtp.gmail.com with ESMTPSA id cf27-20020a0564020b9b00b0056e59d747b0sm3937051edb.40.2024.04.10.06.18.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 06:18:01 -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, ath11k@lists.infradead.org, ath10k@lists.infradead.org, linux-wireless@vger.kernel.org, geomatsi@gmail.com, kvalo@kernel.org Cc: quic_jjohnson@quicinc.com, leon@kernel.org, dennis.dalessandro@cornelisnetworks.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, idosch@idosch.org, leitao@debian.org, Ido Schimmel , Jiri Pirko , Simon Horman , Daniel Borkmann , Sebastian Andrzej Siewior Subject: [PATCH net-next v5 03/10] net: create a dummy net_device allocator Date: Wed, 10 Apr 2024 06:13:44 -0700 Message-ID: <20240410131407.3897251-4-leitao@debian.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240410131407.3897251-1-leitao@debian.org> References: <20240410131407.3897251-1-leitao@debian.org> Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 Reviewed-by: Ido Schimmel --- 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 d45f330d083d..f849e7d110ed 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -4519,6 +4519,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 c74b42bc6888..417abfd12871 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -10414,25 +10414,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 initializes 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 - * as 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 */ @@ -10453,8 +10440,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 initializes 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 + * as 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 @@ -11074,6 +11081,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 * From patchwork Wed Apr 10 13:13:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 787906 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (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 D0BEC16C44D; Wed, 10 Apr 2024 13:18:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712755088; cv=none; b=tB0rcFFWn6Mc3/sYQsY7xDaDsGx5EjklPkHjIKd5eocqLkOorrBurR3/vS/nK/WJBUg/dMPofwp00EZBcpTYqiPHA+hhDRNEObS7fNPCFvD3aNOMD0Z7oKwB4QikV9ZlWhp2oGzQYgmGy3sUp7OnVHr9QqGfHv4pMykFlpgEtUY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712755088; c=relaxed/simple; bh=eBWqs9fv+T+1bqH2rncgTX0O81pwgTdfA92I++Mu2wQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K0asKMrQU0vBXgc+/34otbccElvj3qcK0MuKf79GDEBbVt6flyHyS0A9gZj9tb5Ng0IbiyN7wAW18UuY93G89nB+2cZe2zbI4pvvGfyTwez7LR1/njaD4YfJKnJPjkKKiolkGkK95z3EZ9vxmNKng6YX6uh/UJ4+2BHrjfzD1wc= 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.218.41 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-ej1-f41.google.com with SMTP id a640c23a62f3a-a44ad785a44so787288266b.3; Wed, 10 Apr 2024 06:18:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712755085; x=1713359885; 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=E0v0jOuLRJCnWd0s0TIZZ1gZgekQUwAKs2R0RJj3DsM=; b=rjlXcVuiCnAa66Q2OVgR3UA0OD6Pq78H62Efl54tX9EYIvel9sBetVAUBXtHgeDVlc wSIN8TGU6U+oWnCBeLUIHmY2MbbmLoUi6FbQPfF1nSd6Z50S6nbgYd6Ckx07HPAVf1JJ dyqJ/qLnaXTiD7m3Ljn48LzVwIHGjWYnXeRya23ouhcViF1b16ksrtW5t/DXmJCtE4vR yKE8jYPgqi+SQj0O6W/kRCg5A6IoZv0o1ZmJSAWjUYfzxuUBdeoRYzkynDm6lM8uNlnf R3v5BtXYi2AbyXrION9psVe/M99v2xEAdGWB3XPUtkHIQF2wSqBb4lo5YjCXcacyNfXc NyaQ== X-Forwarded-Encrypted: i=1; AJvYcCXOZMGCemM6sg2vU2FItIFfN8WGmX1aGLZ6g3tjQ1mvrKxzSGGJ1S5+kJYKm+hh72UUqdFNvfKvK/WnFeNfCSCIHrr7x/EwZchQfVX4+30Ppuf3unO1lnUYmcOlsdl4U0CiGHY32XMfoW+ufVbBpq4FJgi2tg+ELDFXKsdvW3uXEYPQ6b9OHJe/HeG69R1x2ICzgLt3+MoMJsY= X-Gm-Message-State: AOJu0Yy/uSxcg9BKqYkjwM4sl/PDxDWQlLSAIQrmAAnF68n5WZKUFjp4 hqVcKY8x3YJ6PbsPvqFrL5UmMvl4PVVOPbWnHVx9g3WUvBfi3uFs X-Google-Smtp-Source: AGHT+IH7+U+qW5DuChVaZ9Yjnr/uILgb+IAUK0IN9pp6hNnY+Ion9hpWvWwXtUxP7oAsdllTb4QHyw== X-Received: by 2002:a17:907:20e8:b0:a50:e067:e211 with SMTP id rh8-20020a17090720e800b00a50e067e211mr1583949ejb.36.1712755085041; Wed, 10 Apr 2024 06:18:05 -0700 (PDT) Received: from localhost (fwdproxy-lla-116.fbsv.net. [2a03:2880:30ff:74::face:b00c]) by smtp.gmail.com with ESMTPSA id gs44-20020a1709072d2c00b00a46a3ad035esm6986256ejc.179.2024.04.10.06.18.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 06:18:04 -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, ath11k@lists.infradead.org, ath10k@lists.infradead.org, linux-wireless@vger.kernel.org, geomatsi@gmail.com, kvalo@kernel.org Cc: quic_jjohnson@quicinc.com, leon@kernel.org, dennis.dalessandro@cornelisnetworks.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, idosch@idosch.org, leitao@debian.org, Elad Nachman Subject: [PATCH net-next v5 04/10] net: marvell: prestera: allocate dummy net_device dynamically Date: Wed, 10 Apr 2024 06:13:45 -0700 Message-ID: <20240410131407.3897251-5-leitao@debian.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240410131407.3897251-1-leitao@debian.org> References: <20240410131407.3897251-1-leitao@debian.org> Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Embedding net_device into structures prohibits the usage of flexible arrays in the net_device structure. For more details, see the discussion at [1]. Un-embed the net_device from the private struct by converting it into a pointer. Then use the leverage the new alloc_netdev_dummy() helper to allocate and initialize dummy devices. [1] https://lore.kernel.org/all/20240229225910.79e224cf@kernel.org/ Signed-off-by: Breno Leitao Acked-by: Elad Nachman --- .../net/ethernet/marvell/prestera/prestera_rxtx.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/marvell/prestera/prestera_rxtx.c b/drivers/net/ethernet/marvell/prestera/prestera_rxtx.c index cc2a9ae794be..39d9bf82c115 100644 --- a/drivers/net/ethernet/marvell/prestera/prestera_rxtx.c +++ b/drivers/net/ethernet/marvell/prestera/prestera_rxtx.c @@ -96,7 +96,7 @@ struct prestera_sdma { struct dma_pool *desc_pool; struct work_struct tx_work; struct napi_struct rx_napi; - struct net_device napi_dev; + struct net_device *napi_dev; u32 map_addr; u64 dma_mask; /* protect SDMA with concurrent access from multiple CPUs */ @@ -654,13 +654,21 @@ static int prestera_sdma_switch_init(struct prestera_switch *sw) if (err) goto err_evt_register; - init_dummy_netdev(&sdma->napi_dev); + sdma->napi_dev = alloc_netdev_dummy(0); + if (!sdma->napi_dev) { + dev_err(dev, "not able to initialize dummy device\n"); + err = -ENOMEM; + goto err_alloc_dummy; + } - netif_napi_add(&sdma->napi_dev, &sdma->rx_napi, prestera_sdma_rx_poll); + netif_napi_add(sdma->napi_dev, &sdma->rx_napi, prestera_sdma_rx_poll); napi_enable(&sdma->rx_napi); return 0; +err_alloc_dummy: + prestera_hw_event_handler_unregister(sw, PRESTERA_EVENT_TYPE_RXTX, + prestera_rxtx_handle_event); err_evt_register: err_tx_init: prestera_sdma_tx_fini(sdma); @@ -677,6 +685,7 @@ static void prestera_sdma_switch_fini(struct prestera_switch *sw) napi_disable(&sdma->rx_napi); netif_napi_del(&sdma->rx_napi); + free_netdev(sdma->napi_dev); prestera_hw_event_handler_unregister(sw, PRESTERA_EVENT_TYPE_RXTX, prestera_rxtx_handle_event); prestera_sdma_tx_fini(sdma); From patchwork Wed Apr 10 13:13:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 789292 Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.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 F38EA16D9AB; Wed, 10 Apr 2024 13:18:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712755090; cv=none; b=Obp2TIOn1IU/qAPkALYoEAuPAXSfYQgY32d6tGHvFAKhMyNHyp+HV9T+IHloYvFct/BiYaShKMX8Fx+dr3kpO29yAJps6uZO4tlHj7zWS0dhhG8uXjo3Hvty4JNiw//yoJjXF/u0cZ6TawBeEQGGGE/49dPlX+y0BRHiD/K97IA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712755090; c=relaxed/simple; bh=thNNGA+Buyv1A48P5cMpc4XXfCvRQSFmpwoRUX9PFQs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NyKBAbOsKGnVJJuRiKGXMjiOkFB1LrxTIEFjXlxR37RQ1VORJKYtgt0xSE8JNveh2pqOBLruEhwLNpCsNFnUpcH0Y8mcc84NI/Yw3o8DAWBdY3t7HQpHQRx7zu9kAa9aoGA2xM3ITcfnChjNvY+3/5jptEjETUec6y+zYFzPPRk= 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.48 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-f48.google.com with SMTP id 4fb4d7f45d1cf-56e2ac1c16aso6858175a12.0; Wed, 10 Apr 2024 06:18:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712755087; x=1713359887; 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=bGHHnAjzHXOHKZAHNwNt7Xm//rgfn0lSUB+nM5VysgU=; b=T9XWF/GSmbwTBbB6ryoVLwfFrd4VekxTEsHkKXYrre3vkNNrQx6OuOk8GpMAwe6l+H uYjhbE29RMlUpf0EtuUn5LziwLWlbzCwFEePZIcF7nEnCWji8mcV1n7Q5r2nr+RKVoXq cNwHhcOdi2Mit1dKQdVtpl81rOaB+L1pDv1FEnuQEXDVH8lGO97rkXPJjNObc2V4viy9 EXW970WFyNJZr1UhepVSIRk61G4klHbMCHrdEgbsYVs6a4sALIohzwq33veeZGHxjphz WJpShdKVXwQoOlCBjILdjz9AC3NMCYnwbxz1vPCQp63XX9aXHDUVsoIoNRa/oa7CS6+x DeyA== X-Forwarded-Encrypted: i=1; AJvYcCUCJL7XRQw8z6X9C2ijkiwV09xu8GFVob8mKhmEcRpvhwyQTDmb/wxMqJeUIXo2ugReQ0Jt5h5Jgz+O/MUEekEZGrGWL5qHk3eRPyW+c2UjhrW9bsYzmPVCqDWLNBzE/k52FbWHMZm8ZC/1yg8nCMBnjBPN6Mblw8dm+e3BwH9bUWgFt8AYZXBIiP4OdorBxkvZ+awpWJJGYtY= X-Gm-Message-State: AOJu0Yyvaa+VqmZVJ1y5KdNh08c/QHQA22zklXhZJsg85IhBFbxmqEy4 C9Wq8WITVlTrUnL5RIUgsW4oYSndYJQ0+Qp/32GJMsHwhBizSinX X-Google-Smtp-Source: AGHT+IHfRDKViblgpUPyWrUAnhST+TBB6wSl0qe87VqUsLBU1kMLXMG9TkoSj5KDLOwo8qX+Dgkttg== X-Received: by 2002:a50:9e27:0:b0:56e:23e3:bdc3 with SMTP id z36-20020a509e27000000b0056e23e3bdc3mr434260ede.16.1712755087472; Wed, 10 Apr 2024 06:18:07 -0700 (PDT) Received: from localhost (fwdproxy-lla-118.fbsv.net. [2a03:2880:30ff:76::face:b00c]) by smtp.gmail.com with ESMTPSA id h1-20020a0564020e8100b005682a0e915fsm6433736eda.76.2024.04.10.06.18.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 06:18:06 -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, ath11k@lists.infradead.org, ath10k@lists.infradead.org, linux-wireless@vger.kernel.org, geomatsi@gmail.com, kvalo@kernel.org, Matthias Brugger , AngeloGioacchino Del Regno , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend Cc: quic_jjohnson@quicinc.com, leon@kernel.org, dennis.dalessandro@cornelisnetworks.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, idosch@idosch.org, leitao@debian.org Subject: [PATCH net-next v5 05/10] net: mediatek: mtk_eth_sock: allocate dummy net_device dynamically Date: Wed, 10 Apr 2024 06:13:46 -0700 Message-ID: <20240410131407.3897251-6-leitao@debian.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240410131407.3897251-1-leitao@debian.org> References: <20240410131407.3897251-1-leitao@debian.org> Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Embedding net_device into structures prohibits the usage of flexible arrays in the net_device structure. For more details, see the discussion at [1]. Un-embed the net_device from the private struct by converting it into a pointer. Then use the leverage the new alloc_netdev_dummy() helper to allocate and initialize dummy devices. [1] https://lore.kernel.org/all/20240229225910.79e224cf@kernel.org/ Signed-off-by: Breno Leitao --- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 17 +++++++++++++---- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c index caa13b9cedff..d7a96dc11c07 100644 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c @@ -1710,7 +1710,7 @@ static struct page_pool *mtk_create_page_pool(struct mtk_eth *eth, if (IS_ERR(pp)) return pp; - err = __xdp_rxq_info_reg(xdp_q, ð->dummy_dev, id, + err = __xdp_rxq_info_reg(xdp_q, eth->dummy_dev, id, eth->rx_napi.napi_id, PAGE_SIZE); if (err < 0) goto err_free_pp; @@ -4188,6 +4188,8 @@ static int mtk_free_dev(struct mtk_eth *eth) metadata_dst_free(eth->dsa_meta[i]); } + free_netdev(eth->dummy_dev); + return 0; } @@ -4983,9 +4985,14 @@ static int mtk_probe(struct platform_device *pdev) /* we run 2 devices on the same DMA ring so we need a dummy device * for NAPI to work */ - init_dummy_netdev(ð->dummy_dev); - netif_napi_add(ð->dummy_dev, ð->tx_napi, mtk_napi_tx); - netif_napi_add(ð->dummy_dev, ð->rx_napi, mtk_napi_rx); + eth->dummy_dev = alloc_netdev_dummy(0); + if (!eth->dummy_dev) { + err = -ENOMEM; + dev_err(eth->dev, "failed to allocated dummy device\n"); + goto err_unreg_netdev; + } + netif_napi_add(eth->dummy_dev, ð->tx_napi, mtk_napi_tx); + netif_napi_add(eth->dummy_dev, ð->rx_napi, mtk_napi_rx); platform_set_drvdata(pdev, eth); schedule_delayed_work(ð->reset.monitor_work, @@ -4993,6 +5000,8 @@ static int mtk_probe(struct platform_device *pdev) return 0; +err_unreg_netdev: + mtk_unreg_dev(eth); err_deinit_ppe: mtk_ppe_deinit(eth); mtk_mdio_cleanup(eth); diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h index 9ae3b8a71d0e..723fc637027c 100644 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h @@ -1242,7 +1242,7 @@ struct mtk_eth { spinlock_t page_lock; spinlock_t tx_irq_lock; spinlock_t rx_irq_lock; - struct net_device dummy_dev; + struct net_device *dummy_dev; struct net_device *netdev[MTK_MAX_DEVS]; struct mtk_mac *mac[MTK_MAX_DEVS]; int irq[3]; From patchwork Wed Apr 10 13:13:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 787905 Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (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 C686D16E86B; Wed, 10 Apr 2024 13:18:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712755093; cv=none; b=CR0ctiFTkhAUw9E8n50ZQtXlOoMtxnxJI2ohsbI05svDSWyV+HS9ivaXCymLn+eYE8baCt3SNBJs4K1RqfSJoy1sxhj7bbNOOuDYkDdzsY2RafVeq9UriBnY276e6P7xwuledvw4+qLDlI75Zcxd37mLv6wyMSJmeqAe7C3bm+o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712755093; c=relaxed/simple; bh=QtQ6sHpbu3QCkabgr6hTrp4OmZME1Hi0HLc2rVVa08A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HWCA+O0mtCooZ36HyOyagS7yDn7v5shr6fMlBEFhNVXwIjP/4Ub9QDCKG+qDiUmio4Lfp0XRTVf4SaOMkR3pwlr15Dl+tnqafJTaKvDGi0Hz6olpOclfxpXbHSe64AZkqH2ZCTYADcm+fwdaJhqPALZacaEQZUQXkWckKSEndsM= 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.42 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-f42.google.com with SMTP id 4fb4d7f45d1cf-56e69888a36so4121065a12.3; Wed, 10 Apr 2024 06:18:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712755090; x=1713359890; 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=Ui1DJxKv+GCSubTCimqVqNTb9BwhV0yVlSdcCwIQq1A=; b=Gb7kxmpnPS+LFuQaqmkfyY/4f1oPz2t34A9pBT5MLpaqqRx09XY/W737hJolN798tm rex6hJSdMIU05gpsS96zUZM3qWUyLHXdVHHV9SbtUd0zFkRDEjvGpRcOZ8EAr929WU6q Vzi1H68KiwBm2YYf62S7sHiO2wvkBEztMnfiyOnOIF7OcpazlA+3YH1DICtMm1JwNBYM Il3qVwXKSEWkRnjJkJs9X4temEIwFmuf9kYuzwV7JgAkZhak+sFtsHC6oKYgo+fvxOe4 BNrFx2pAnNXdTgNEG5kdEYXqGqhOEdvpdmtLlP2/Sz/IqPJLCLiyKUm0PiXvcCS25UTF J1og== X-Forwarded-Encrypted: i=1; AJvYcCW8lKrZIcMWzdQDp6lfW3HwpJdPSmr1Ku2IiEVtO61PoP5JTcFHiBnXbduUqqyxkKv6pVgDqtAa8JapA7aSIi1Pk/MTrFJDlicSGCKCpsIxtAZqbCrnf8E+ANftfHtCOqrG7pRGdWX1FQxLzEEV7h0fQ4tgzqpfRycg118JJAeOZUDQPnh7Pg3Fu8MnQEcGb4+YaK+NYu1A9S4= X-Gm-Message-State: AOJu0YzIr2CRuFXy9GNRLfF28fFQcnXzPYl51EuxaGpUj6FlaeCUXVRE 4aYl3kfCWqp1VU3kiiWT6XLBtltskwnqspkco0pIOAHrhrRwMtal X-Google-Smtp-Source: AGHT+IGftURUiLhae3IWuo+JgModGLFYkH2l8Vww82aSVu0SYVtXrmdtfM8lFQGJV5CM4+6FNOQ1pQ== X-Received: by 2002:a50:d49c:0:b0:568:32cc:f808 with SMTP id s28-20020a50d49c000000b0056832ccf808mr1310263edi.15.1712755090031; Wed, 10 Apr 2024 06:18:10 -0700 (PDT) Received: from localhost (fwdproxy-lla-002.fbsv.net. [2a03:2880:30ff:2::face:b00c]) by smtp.gmail.com with ESMTPSA id fi9-20020a056402550900b0056bdc4a5cd6sm6359853edb.62.2024.04.10.06.18.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 06:18:09 -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, ath11k@lists.infradead.org, ath10k@lists.infradead.org, linux-wireless@vger.kernel.org, geomatsi@gmail.com, kvalo@kernel.org Cc: quic_jjohnson@quicinc.com, leon@kernel.org, dennis.dalessandro@cornelisnetworks.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, idosch@idosch.org, leitao@debian.org Subject: [PATCH net-next v5 06/10] net: ipa: allocate dummy net_device dynamically Date: Wed, 10 Apr 2024 06:13:47 -0700 Message-ID: <20240410131407.3897251-7-leitao@debian.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240410131407.3897251-1-leitao@debian.org> References: <20240410131407.3897251-1-leitao@debian.org> Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Embedding net_device into structures prohibits the usage of flexible arrays in the net_device structure. For more details, see the discussion at [1]. Un-embed the net_device from the private struct by converting it into a pointer. Then use the leverage the new alloc_netdev_dummy() helper to allocate and initialize dummy devices. [1] https://lore.kernel.org/all/20240229225910.79e224cf@kernel.org/ Signed-off-by: Breno Leitao --- drivers/net/ipa/gsi.c | 12 ++++++++---- drivers/net/ipa/gsi.h | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/net/ipa/gsi.c b/drivers/net/ipa/gsi.c index 9a0b1fe4a93a..d70be15e95a6 100644 --- a/drivers/net/ipa/gsi.c +++ b/drivers/net/ipa/gsi.c @@ -1730,10 +1730,10 @@ static int gsi_channel_setup_one(struct gsi *gsi, u32 channel_id) gsi_channel_program(channel, true); if (channel->toward_ipa) - netif_napi_add_tx(&gsi->dummy_dev, &channel->napi, + netif_napi_add_tx(gsi->dummy_dev, &channel->napi, gsi_channel_poll); else - netif_napi_add(&gsi->dummy_dev, &channel->napi, + netif_napi_add(gsi->dummy_dev, &channel->napi, gsi_channel_poll); return 0; @@ -2369,12 +2369,14 @@ int gsi_init(struct gsi *gsi, struct platform_device *pdev, /* GSI uses NAPI on all channels. Create a dummy network device * for the channel NAPI contexts to be associated with. */ - init_dummy_netdev(&gsi->dummy_dev); + gsi->dummy_dev = alloc_netdev_dummy(0); + if (!gsi->dummy_dev) + return -ENOMEM; init_completion(&gsi->completion); ret = gsi_reg_init(gsi, pdev); if (ret) - return ret; + goto err_reg_exit; ret = gsi_irq_init(gsi, pdev); /* No matching exit required */ if (ret) @@ -2389,6 +2391,7 @@ int gsi_init(struct gsi *gsi, struct platform_device *pdev, return 0; err_reg_exit: + free_netdev(gsi->dummy_dev); gsi_reg_exit(gsi); return ret; @@ -2399,6 +2402,7 @@ void gsi_exit(struct gsi *gsi) { mutex_destroy(&gsi->mutex); gsi_channel_exit(gsi); + free_netdev(gsi->dummy_dev); gsi_reg_exit(gsi); } diff --git a/drivers/net/ipa/gsi.h b/drivers/net/ipa/gsi.h index 42063b227c18..6b7ec2a39676 100644 --- a/drivers/net/ipa/gsi.h +++ b/drivers/net/ipa/gsi.h @@ -155,7 +155,7 @@ struct gsi { struct mutex mutex; /* protects commands, programming */ struct gsi_channel channel[GSI_CHANNEL_COUNT_MAX]; struct gsi_evt_ring evt_ring[GSI_EVT_RING_COUNT_MAX]; - struct net_device dummy_dev; /* needed for NAPI */ + struct net_device *dummy_dev; /* needed for NAPI */ }; /** From patchwork Wed Apr 10 13:13:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 789291 Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) (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 46EA815ECF9; Wed, 10 Apr 2024 13:18:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712755099; cv=none; b=si4Sp13SnX5QyQatBc0GMPeCQbr3ESpmeJMduy5dmpCRKLeLxsCKTz2xePPkL24+OYDeBO/V6QHB29q7Pf4L7r5kbAsJihOIaC5lMPrN5HLn8DSRGRT93eiqxb4ATlClTlswjQsKpg9oaekhw55sXOsL6vsB+SHq1BvtqVLHqHw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712755099; c=relaxed/simple; bh=MB8+/MFHOEltGh7GM7e6UBLJe+yCPGpUyEgMI44tcDQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U5aGu5udhrfkyiygo5msSTmjSxfDHYOCHPgm/wc+RF3CUSDMSwKXjm5gLzbhCJgX4CdImilfNPaOZgQTyC95YfCis7iuBUQbqc1sS+6WCMkmyI2O3yKKr1aO3s0hH7ZaN6iSed5L6v0WIGWK7HINKEYtAW8YwMx8p4PhsyQ+c8g= 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.173 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-lj1-f173.google.com with SMTP id 38308e7fff4ca-2d485886545so118035971fa.2; Wed, 10 Apr 2024 06:18:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712755096; x=1713359896; 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=CsBGQlMm+F00sLCL/qlkhF4TnT6nst/CdHn7pOQlov8=; b=pMZu6TFWP0mpo7OQ7GGc5Bju9UXHSPYkO/uhj+6xHUO8mjXZolvF16dVAVIiO+lCI1 OFE+Kmj4IgzvKj6sMqdjK89gMPrv+dqrEOw9/I8KgGK6YvIr38bk9y5AvMQ1vdLbgTx/ vqho6uzaFgIFSK7heAB3JE4yn/8IW9pjlKuDPDXyi+yj/F+Hz0jcszqvB8qWrCZA8Hmu 9ep0+2zGY/i6OjXl0S+3pbAVSN2oyRthmxgDeRHRveLLwzF4Hr7ZZUm6dXsQ5FChiqpJ 1+Hy98H2NfF8Si2Y1oOV8pIE1FQNiiklY6JxtA27wftIx8eRrwci0ivGKoklqCMJBxFD yJ6Q== X-Forwarded-Encrypted: i=1; AJvYcCVLlS9JzUI4J4nhio74G2dYkT7zkp4A6Xq96iD2kjNmyV7yxjPiYV3S/YGVcIKuELBuUnra7gUyBWZkM9C2JXZzf/n8vwXW9bK4x0/9J6YQ64r/ZAETvIWwlNf6t3ap9AuEbtssZ42JLearonvP2KSFzIXasyUAoJ+Kloq6+5tCJllhGU0qpcXJKf/IPruGqPhUGrkzKyArX88= X-Gm-Message-State: AOJu0YyY5d3fc/WNplcQqaBHynzaSsYUItg5jt2O6P4zsQZ8lN2+E+iA OnfAckyN4BimtTX0LFE/nafoIEwIVkl7QhzthGDpCYmIlSzqHOfj X-Google-Smtp-Source: AGHT+IGPO9wT0OKbwO/gx4+xhRnOuGA7eN0JCfBeTdRn7c+VdXyJ56ZmoGT8+49f0mI/Xs97HLpwLQ== X-Received: by 2002:a05:651c:4ce:b0:2d4:49d1:38e with SMTP id e14-20020a05651c04ce00b002d449d1038emr3242747lji.28.1712755096217; Wed, 10 Apr 2024 06:18:16 -0700 (PDT) Received: from localhost (fwdproxy-lla-119.fbsv.net. [2a03:2880:30ff:77::face:b00c]) by smtp.gmail.com with ESMTPSA id n10-20020a170906b30a00b00a4e08e81e7esm6881397ejz.27.2024.04.10.06.18.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 06:18:15 -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, ath11k@lists.infradead.org, ath10k@lists.infradead.org, linux-wireless@vger.kernel.org, geomatsi@gmail.com, kvalo@kernel.org Cc: quic_jjohnson@quicinc.com, leon@kernel.org, dennis.dalessandro@cornelisnetworks.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, idosch@idosch.org, leitao@debian.org, Marc Kleine-Budde , Nick Child , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Christian Marangi , Rob Herring Subject: [PATCH net-next v5 07/10] net: ibm/emac: allocate dummy net_device dynamically Date: Wed, 10 Apr 2024 06:13:48 -0700 Message-ID: <20240410131407.3897251-8-leitao@debian.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240410131407.3897251-1-leitao@debian.org> References: <20240410131407.3897251-1-leitao@debian.org> Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Embedding net_device into structures prohibits the usage of flexible arrays in the net_device structure. For more details, see the discussion at [1]. Un-embed the net_device from the private struct by converting it into a pointer. Then use the leverage the new alloc_netdev_dummy() helper to allocate and initialize dummy devices. [1] https://lore.kernel.org/all/20240229225910.79e224cf@kernel.org/ Signed-off-by: Breno Leitao --- drivers/net/ethernet/ibm/emac/mal.c | 14 +++++++++++--- drivers/net/ethernet/ibm/emac/mal.h | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/ibm/emac/mal.c b/drivers/net/ethernet/ibm/emac/mal.c index 2439f7e96e05..d92dd9c83031 100644 --- a/drivers/net/ethernet/ibm/emac/mal.c +++ b/drivers/net/ethernet/ibm/emac/mal.c @@ -605,9 +605,13 @@ static int mal_probe(struct platform_device *ofdev) INIT_LIST_HEAD(&mal->list); spin_lock_init(&mal->lock); - init_dummy_netdev(&mal->dummy_dev); + mal->dummy_dev = alloc_netdev_dummy(0); + if (!mal->dummy_dev) { + err = -ENOMEM; + goto fail_unmap; + } - netif_napi_add_weight(&mal->dummy_dev, &mal->napi, mal_poll, + netif_napi_add_weight(mal->dummy_dev, &mal->napi, mal_poll, CONFIG_IBM_EMAC_POLL_WEIGHT); /* Load power-on reset defaults */ @@ -637,7 +641,7 @@ static int mal_probe(struct platform_device *ofdev) GFP_KERNEL); if (mal->bd_virt == NULL) { err = -ENOMEM; - goto fail_unmap; + goto fail_dummy; } for (i = 0; i < mal->num_tx_chans; ++i) @@ -703,6 +707,8 @@ static int mal_probe(struct platform_device *ofdev) free_irq(mal->serr_irq, mal); fail2: dma_free_coherent(&ofdev->dev, bd_size, mal->bd_virt, mal->bd_dma); + fail_dummy: + free_netdev(mal->dummy_dev); fail_unmap: dcr_unmap(mal->dcr_host, 0x100); fail: @@ -734,6 +740,8 @@ static void mal_remove(struct platform_device *ofdev) mal_reset(mal); + free_netdev(mal->dummy_dev); + dma_free_coherent(&ofdev->dev, sizeof(struct mal_descriptor) * (NUM_TX_BUFF * mal->num_tx_chans + diff --git a/drivers/net/ethernet/ibm/emac/mal.h b/drivers/net/ethernet/ibm/emac/mal.h index d212373a72e7..e0ddc41186a2 100644 --- a/drivers/net/ethernet/ibm/emac/mal.h +++ b/drivers/net/ethernet/ibm/emac/mal.h @@ -205,7 +205,7 @@ struct mal_instance { int index; spinlock_t lock; - struct net_device dummy_dev; + struct net_device *dummy_dev; unsigned int features; }; From patchwork Wed Apr 10 13:13:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 787904 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (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 401D315ECF9; Wed, 10 Apr 2024 13:18:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712755103; cv=none; b=fZncUUE5PfwPqOxmd7YOdtGmlfNaIsw2CXsG+xYwfSVV3IymDEXuKTc1z3ony9OEg2Z24l3gNL+JZGK4j8iKUr8jkOviwSNpNnd7NTksPs5+8INjP6NoYlyuwhxQz6Qw2lRosWRAqg5IKWgGL71KBR+0C4FeCy0zVCUGzV8Q5T4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712755103; c=relaxed/simple; bh=UfsEjeHUgOR27rtbE3M4PujzAfOxibpW7ixsPpbhaI0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jc5yeOxffcY2SeB7LYFoKcqkGMBkiz1achTbHhkVQMp02BloKISJXCgm/YFl0W1KAf8qsFjk/MsbRtzoNRHtCAcuQ14TRPaVrfY6LtLmEUnDbXeGzRAKOnWMeuWhPC1Jx5pjunx/irlcmBAfaJZg42hwXDuGp+9jmQkiJSRElIw= 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.218.52 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-ej1-f52.google.com with SMTP id a640c23a62f3a-a51d05c50b2so438055466b.0; Wed, 10 Apr 2024 06:18:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712755100; x=1713359900; 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=9uOh18J18K7IiJjOdRTp7+wBD9ghOrm4r66dFYnU+6Y=; b=JRisMv84zLx1NK6e88XL+oaCntppGWwIPJS53o5EAS6Q7+vZVpfkfRTWsds4+bKHpV 8LL3jdbZ9s0xK0Y4bb+w2Ndyh3C3sJGqUPR4Yn1fElh4USJkuOZLNHpOI4TjYety3V6z Q5zog/7duoyDYxtem1fpYadmOCh9coSzjDfFiI8bA1LqdGwP44mJvGgfCnwWpDTqtKVC +Nl1hxkEfDKz+nuQlGB4H+Xenq51WuNAzZaZ8A2USUHPMgDFbplSF7WMcbpjn0Ckg7j+ lF9Fxgx6tmRDfbGIOzbchsa92wXEmbr5Zw/fAJ+xczPW1cB4E0F4x1pQwDaKq/czKTov wE9A== X-Forwarded-Encrypted: i=1; AJvYcCUGihqV51Ek3VqQQkJYqUmZVYAiB4cT+l65tcRncMN6TbWUnu4c5DcXIvgkGeeFUNqM22uwVhLhS0SevvEMxg5yEey7pAuWIGO/+CZ+jIpbPS/XEhdLvrPVMYyzx96NWd25XkS29b12XPSpkk/lTbkqYnm9cVudatgPgyBriwS14CVH0ir+VXWZ/ltzSI73rxXNc7OzC0dwqTw= X-Gm-Message-State: AOJu0Yxc7ea5oIRgIVVJKiUqsI495uKnC7747mY5iAgjES4lMm/RCDHz L5G7mPJCGrG+4rB/h0vAYGh91OutgFZoaZ2KaU6yhQobllduIsg6 X-Google-Smtp-Source: AGHT+IFr2S2LI08jI8XIroOmyyE/85QrJ6Hsd+T5Ighzae4CMX/NDkh7+a/IOM6kncoda2BU+ME9hQ== X-Received: by 2002:a17:907:7ea0:b0:a4e:6957:de25 with SMTP id qb32-20020a1709077ea000b00a4e6957de25mr2199693ejc.57.1712755100549; Wed, 10 Apr 2024 06:18:20 -0700 (PDT) Received: from localhost (fwdproxy-lla-116.fbsv.net. [2a03:2880:30ff:74::face:b00c]) by smtp.gmail.com with ESMTPSA id qf15-20020a1709077f0f00b00a47439647efsm6935601ejc.133.2024.04.10.06.18.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 06:18:19 -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, ath11k@lists.infradead.org, ath10k@lists.infradead.org, linux-wireless@vger.kernel.org, geomatsi@gmail.com, kvalo@kernel.org, Igor Mitsyanko Cc: quic_jjohnson@quicinc.com, leon@kernel.org, dennis.dalessandro@cornelisnetworks.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, idosch@idosch.org, leitao@debian.org Subject: [PATCH net-next v5 08/10] wifi: qtnfmac: Use netdev dummy allocator helper Date: Wed, 10 Apr 2024 06:13:49 -0700 Message-ID: <20240410131407.3897251-9-leitao@debian.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240410131407.3897251-1-leitao@debian.org> References: <20240410131407.3897251-1-leitao@debian.org> Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 There is a new dummy netdev allocator, use it instead of alloc_netdev()/init_dummy_netdev combination. Using alloc_netdev() with init_dummy_netdev might cause some memory corruption at the driver removal side. Fixes: 61cdb09ff760 ("wifi: qtnfmac: allocate dummy net_device dynamically") Signed-off-by: Breno Leitao --- drivers/net/wireless/quantenna/qtnfmac/pcie/pcie.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/net/wireless/quantenna/qtnfmac/pcie/pcie.c b/drivers/net/wireless/quantenna/qtnfmac/pcie/pcie.c index f8f55db2f454..f66eb43094d4 100644 --- a/drivers/net/wireless/quantenna/qtnfmac/pcie/pcie.c +++ b/drivers/net/wireless/quantenna/qtnfmac/pcie/pcie.c @@ -372,8 +372,7 @@ static int qtnf_pcie_probe(struct pci_dev *pdev, const struct pci_device_id *id) goto error; } - bus->mux_dev = alloc_netdev(0, "dummy", NET_NAME_UNKNOWN, - init_dummy_netdev); + bus->mux_dev = alloc_netdev_dummy(0); if (!bus->mux_dev) { ret = -ENOMEM; goto error; From patchwork Wed Apr 10 13:13:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 789290 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (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 BAC3416F914; Wed, 10 Apr 2024 13:18:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712755107; cv=none; b=rfrfKgl1hK4LXltUXDTPw0T0oOAV+uQeuvzODC1U/xrcFin2dYHNvIztJ7M7dpeqlzaqSG4eEwCATGjLZCTbCb5i6T4Dg8WI0B9mUhAq44+zKPwDrB78ShvQz6Sg3SjQJeXeYRZbEZ4K0x/U4ek+Ww3vNHuldxqBA6d650MCbnQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712755107; c=relaxed/simple; bh=3jqcHKzZ3GD9fOOuNtL+5tC5x7Sajb0fEea0j4mcf2c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tNcydT42E+l5/7bTdoCvTMX3oZkNmd9FSP3+vGPZISDXAKP2S82CtjtISuqO6NW+AGcyUHfl+6nPdiwYa2JqPOJf4ZM3qqyVmQJMnn9do0lwXfv5D0h6uT28O28d6vmnoix2yle542MnoEcQf8Q10HE6f3B4lxnA8GF/uHYJyMQ= 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.167.52 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-lf1-f52.google.com with SMTP id 2adb3069b0e04-516d04fc04bso10377465e87.2; Wed, 10 Apr 2024 06:18:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712755104; x=1713359904; 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=/BGqPmC8OttnSs/eU7zOpIE4pu3ScGIxqadvcYRpWVY=; b=Qextt6Lm2sUy0ej6P0pH6gWW/nKcPUMRdtFLUr/LiraYMGOSoT/awkZTXqOO2nb7+O PQsysFMyDhtlMWM26G2sC0Ube1X2TQwtoVkOoK/VzvoQm9ccQ3BvSgFAG0Y8m39qRiVN ZzMOq+U9ZcoxjAeGgtOSSMnQRc/Bd8c14meLnvfS+HJtXQYKBd/jd1U7ZmoG03hvmPEG OPkIkoj7zTFU8RD7DMFMX8ebDumMdy2yYtaUO+uvi/ZZPa+d3bVlyDczI1Xio3SFeaFc tR1ft0NEaO/kzgLJLu0xIx9xZUCUDiACC0+dRZUFyCkCKAnKuLYNjaKQUjIZqm+sOoiB Tn/w== X-Forwarded-Encrypted: i=1; AJvYcCVxlcAZtx1wbLHIvHwAuRVPOqcq2b3ng1HA5H2cz7JAQ/FUqC/ALe4LtZ8kDjRHSicy6bA2nFHPzZIeINo5/o3crk3p1yXdw8yc38x0fLsF2OWXMTgy+np6cm/65DILmgJKkc/FRWcWgmF/mmFkWqFrnRVxpnHrl5CqhkgmcCafZo6rZsre+QdBmHUW65revae9obzQX+1BmNk= X-Gm-Message-State: AOJu0YyO1Wh6hM/aan3IW+HvaSRtPjSsKMCLnl6ICd6Kfknt/ZxWNTMH 8qLktqv/SrzNUt+VmqzruAjOw1Im6Xz7s0jI/acF9jj9VglyMru5 X-Google-Smtp-Source: AGHT+IHviCjCyxPLZMtL2RkyGuzaeGtDraBYTh6IkEObOiNwMifG9KcbhjesJ0nZLyGLu2godkApfw== X-Received: by 2002:a05:6512:b95:b0:512:fe25:550b with SMTP id b21-20020a0565120b9500b00512fe25550bmr2904940lfv.47.1712755103739; Wed, 10 Apr 2024 06:18:23 -0700 (PDT) Received: from localhost (fwdproxy-lla-120.fbsv.net. [2a03:2880:30ff:78::face:b00c]) by smtp.gmail.com with ESMTPSA id kn6-20020a170906aa4600b00a4e238e46edsm6961222ejb.223.2024.04.10.06.18.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 06:18:22 -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, ath11k@lists.infradead.org, ath10k@lists.infradead.org, linux-wireless@vger.kernel.org, geomatsi@gmail.com, kvalo@kernel.org, Jeff Johnson Cc: quic_jjohnson@quicinc.com, leon@kernel.org, dennis.dalessandro@cornelisnetworks.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, idosch@idosch.org, leitao@debian.org Subject: [PATCH net-next v5 09/10] wifi: ath10k: allocate dummy net_device dynamically Date: Wed, 10 Apr 2024 06:13:50 -0700 Message-ID: <20240410131407.3897251-10-leitao@debian.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240410131407.3897251-1-leitao@debian.org> References: <20240410131407.3897251-1-leitao@debian.org> Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Embedding net_device into structures prohibits the usage of flexible arrays in the net_device structure. For more details, see the discussion at [1]. Un-embed the net_device from struct ath10k by converting it into a pointer. Then use the leverage alloc_netdev() to allocate the net_device object at ath10k_core_create(). The free of the device occurs at ath10k_core_destroy(). [1] https://lore.kernel.org/all/20240229225910.79e224cf@kernel.org/ Signed-off-by: Breno Leitao --- drivers/net/wireless/ath/ath10k/core.c | 9 +++++++-- drivers/net/wireless/ath/ath10k/core.h | 2 +- drivers/net/wireless/ath/ath10k/pci.c | 2 +- drivers/net/wireless/ath/ath10k/sdio.c | 2 +- drivers/net/wireless/ath/ath10k/snoc.c | 4 ++-- drivers/net/wireless/ath/ath10k/usb.c | 2 +- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/drivers/net/wireless/ath/ath10k/core.c b/drivers/net/wireless/ath/ath10k/core.c index 9ce6f49ab261..8663822e0b8d 100644 --- a/drivers/net/wireless/ath/ath10k/core.c +++ b/drivers/net/wireless/ath/ath10k/core.c @@ -3673,11 +3673,13 @@ struct ath10k *ath10k_core_create(size_t priv_size, struct device *dev, INIT_WORK(&ar->set_coverage_class_work, ath10k_core_set_coverage_class_work); - init_dummy_netdev(&ar->napi_dev); + ar->napi_dev = alloc_netdev_dummy(0); + if (!ar->napi_dev) + goto err_free_tx_complete; ret = ath10k_coredump_create(ar); if (ret) - goto err_free_tx_complete; + goto err_free_netdev; ret = ath10k_debug_create(ar); if (ret) @@ -3687,6 +3689,8 @@ struct ath10k *ath10k_core_create(size_t priv_size, struct device *dev, err_free_coredump: ath10k_coredump_destroy(ar); +err_free_netdev: + free_netdev(ar->napi_dev); err_free_tx_complete: destroy_workqueue(ar->workqueue_tx_complete); err_free_aux_wq: @@ -3708,6 +3712,7 @@ void ath10k_core_destroy(struct ath10k *ar) destroy_workqueue(ar->workqueue_tx_complete); + free_netdev(ar->napi_dev); ath10k_debug_destroy(ar); ath10k_coredump_destroy(ar); ath10k_htt_tx_destroy(&ar->htt); diff --git a/drivers/net/wireless/ath/ath10k/core.h b/drivers/net/wireless/ath/ath10k/core.h index c110d15528bd..26003b519574 100644 --- a/drivers/net/wireless/ath/ath10k/core.h +++ b/drivers/net/wireless/ath/ath10k/core.h @@ -1269,7 +1269,7 @@ struct ath10k { struct ath10k_per_peer_tx_stats peer_tx_stats; /* NAPI */ - struct net_device napi_dev; + struct net_device *napi_dev; struct napi_struct napi; struct work_struct set_coverage_class_work; diff --git a/drivers/net/wireless/ath/ath10k/pci.c b/drivers/net/wireless/ath/ath10k/pci.c index 5c34b156b4ff..558bec96ae40 100644 --- a/drivers/net/wireless/ath/ath10k/pci.c +++ b/drivers/net/wireless/ath/ath10k/pci.c @@ -3217,7 +3217,7 @@ static void ath10k_pci_free_irq(struct ath10k *ar) void ath10k_pci_init_napi(struct ath10k *ar) { - netif_napi_add(&ar->napi_dev, &ar->napi, ath10k_pci_napi_poll); + netif_napi_add(ar->napi_dev, &ar->napi, ath10k_pci_napi_poll); } static int ath10k_pci_init_irq(struct ath10k *ar) diff --git a/drivers/net/wireless/ath/ath10k/sdio.c b/drivers/net/wireless/ath/ath10k/sdio.c index 0ab5433f6cf6..e28f2fe1101b 100644 --- a/drivers/net/wireless/ath/ath10k/sdio.c +++ b/drivers/net/wireless/ath/ath10k/sdio.c @@ -2532,7 +2532,7 @@ static int ath10k_sdio_probe(struct sdio_func *func, return -ENOMEM; } - netif_napi_add(&ar->napi_dev, &ar->napi, ath10k_sdio_napi_poll); + netif_napi_add(ar->napi_dev, &ar->napi, ath10k_sdio_napi_poll); ath10k_dbg(ar, ATH10K_DBG_BOOT, "sdio new func %d vendor 0x%x device 0x%x block 0x%x/0x%x\n", diff --git a/drivers/net/wireless/ath/ath10k/snoc.c b/drivers/net/wireless/ath/ath10k/snoc.c index 2c39bad7ebfb..0449b9ffc32d 100644 --- a/drivers/net/wireless/ath/ath10k/snoc.c +++ b/drivers/net/wireless/ath/ath10k/snoc.c @@ -935,7 +935,7 @@ static int ath10k_snoc_hif_start(struct ath10k *ar) bitmap_clear(ar_snoc->pending_ce_irqs, 0, CE_COUNT_MAX); - dev_set_threaded(&ar->napi_dev, true); + dev_set_threaded(ar->napi_dev, true); ath10k_core_napi_enable(ar); ath10k_snoc_irq_enable(ar); ath10k_snoc_rx_post(ar); @@ -1253,7 +1253,7 @@ static int ath10k_snoc_napi_poll(struct napi_struct *ctx, int budget) static void ath10k_snoc_init_napi(struct ath10k *ar) { - netif_napi_add(&ar->napi_dev, &ar->napi, ath10k_snoc_napi_poll); + netif_napi_add(ar->napi_dev, &ar->napi, ath10k_snoc_napi_poll); } static int ath10k_snoc_request_irq(struct ath10k *ar) diff --git a/drivers/net/wireless/ath/ath10k/usb.c b/drivers/net/wireless/ath/ath10k/usb.c index 3c482baacec1..3b51b7f52130 100644 --- a/drivers/net/wireless/ath/ath10k/usb.c +++ b/drivers/net/wireless/ath/ath10k/usb.c @@ -1014,7 +1014,7 @@ static int ath10k_usb_probe(struct usb_interface *interface, return -ENOMEM; } - netif_napi_add(&ar->napi_dev, &ar->napi, ath10k_usb_napi_poll); + netif_napi_add(ar->napi_dev, &ar->napi, ath10k_usb_napi_poll); usb_get_dev(dev); vendor_id = le16_to_cpu(dev->descriptor.idVendor);