Skip to content

Commit 12a9896

Browse files
committed
netdevice: convert private flags > BIT(31) to bitfields
JIRA: https://issues.redhat.com/browse/RHEL-59091 commit beb5a9b Author: Alexander Lobakin <aleksander.lobakin@intel.com> Date: Thu Aug 29 14:33:36 2024 +0200 netdevice: convert private flags > BIT(31) to bitfields Make dev->priv_flags `u32` back and define bits higher than 31 as bitfield booleans as per Jakub's suggestion. This simplifies code which accesses these bits with no optimization loss (testb both before/after), allows to not extend &netdev_priv_flags each time, but also scales better as bits > 63 in the future would only add a new u64 to the structure with no complications, comparing to that extending ::priv_flags would require converting it to a bitmap. Note that I picked `unsigned long :1` to not lose any potential optimizations comparing to `bool :1` etc. Suggested-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com> Conflicts: drivers/net/ethernet/microchip/lan966x/lan966x_main.c - Driver not present in RHEL 9. Signed-off-by: Michal Schmidt <mschmidt@redhat.com>
1 parent 25cd253 commit 12a9896

File tree

8 files changed

+34
-23
lines changed

8 files changed

+34
-23
lines changed

Documentation/networking/net_cachelines/net_device.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ net_device struct fast path usage breakdown
77

88
Type Name fastpath_tx_access fastpath_rx_access Comments
99
..struct ..net_device
10+
unsigned_long:32 priv_flags read_mostly - __dev_queue_xmit(tx)
1011
char name[16] - -
1112
struct_netdev_name_node* name_node
1213
struct_dev_ifalias* ifalias
@@ -23,7 +24,6 @@ struct_list_head ptype_specific
2324
struct adj_list
2425
unsigned_int flags read_mostly read_mostly __dev_queue_xmit,__dev_xmit_skb,ip6_output,__ip6_finish_output(tx);ip6_rcv_core(rx)
2526
xdp_features_t xdp_features
26-
unsigned_long_long priv_flags read_mostly - __dev_queue_xmit(tx)
2727
struct_net_device_ops* netdev_ops read_mostly - netdev_core_pick_tx,netdev_start_xmit(tx)
2828
struct_xdp_metadata_ops* xdp_metadata_ops
2929
int ifindex - read_mostly ip6_rcv_core
@@ -163,6 +163,8 @@ struct_lock_class_key* qdisc_tx_busylock
163163
bool proto_down
164164
unsigned:1 wol_enabled
165165
unsigned:1 threaded - - napi_poll(napi_enable,dev_set_threaded)
166+
unsigned_long:1 see_all_hwtstamp_requests
167+
unsigned_long:1 change_proto_down
166168
struct_list_head net_notifier_list
167169
struct_macsec_ops* macsec_ops
168170
struct_udp_tunnel_nic_info* udp_tunnel_nic_info

drivers/net/macvlan.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,8 @@ void macvlan_common_setup(struct net_device *dev)
12121212
dev->max_mtu = ETH_MAX_MTU;
12131213
dev->priv_flags &= ~IFF_TX_SKB_SHARING;
12141214
netif_keep_dst(dev);
1215-
dev->priv_flags |= IFF_UNICAST_FLT | IFF_CHANGE_PROTO_DOWN;
1215+
dev->priv_flags |= IFF_UNICAST_FLT;
1216+
dev->change_proto_down = true;
12161217
dev->netdev_ops = &macvlan_netdev_ops;
12171218
dev->needs_free_netdev = true;
12181219
dev->priv_destructor = macvlan_dev_free;

drivers/net/vxlan/vxlan_core.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3141,7 +3141,8 @@ static void vxlan_setup(struct net_device *dev)
31413141
dev->hw_features |= NETIF_F_RXCSUM;
31423142
dev->hw_features |= NETIF_F_GSO_SOFTWARE;
31433143
netif_keep_dst(dev);
3144-
dev->priv_flags |= IFF_NO_QUEUE | IFF_CHANGE_PROTO_DOWN;
3144+
dev->priv_flags |= IFF_NO_QUEUE;
3145+
dev->change_proto_down = true;
31453146

31463147
/* MTU range: 68 - 65535 */
31473148
dev->min_mtu = ETH_MIN_MTU;

include/linux/netdevice.h

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,8 @@ struct xdp_metadata_ops {
16501650
* userspace; this means that the order of these flags can change
16511651
* during any kernel release.
16521652
*
1653-
* You should have a pretty good reason to be extending these flags.
1653+
* You should add bitfield booleans after either net_device::priv_flags
1654+
* (hotpath) or ::threaded (slowpath) instead of extending these flags.
16541655
*
16551656
* @IFF_802_1Q_VLAN: 802.1Q VLAN device
16561657
* @IFF_EBRIDGE: Ethernet bridging device
@@ -1689,10 +1690,6 @@ struct xdp_metadata_ops {
16891690
* @IFF_NO_ADDRCONF: prevent ipv6 addrconf
16901691
* @IFF_TX_SKB_NO_LINEAR: device/driver is capable of xmitting frames with
16911692
* skb_headlen(skb) == 0 (data starts from frag0)
1692-
* @IFF_CHANGE_PROTO_DOWN: device supports setting carrier via IFLA_PROTO_DOWN
1693-
* @IFF_SEE_ALL_HWTSTAMP_REQUESTS: device wants to see calls to
1694-
* ndo_hwtstamp_set() for all timestamp requests regardless of source,
1695-
* even if those aren't HWTSTAMP_SOURCE_NETDEV.
16961693
*/
16971694
enum netdev_priv_flags {
16981695
IFF_802_1Q_VLAN = 1<<0,
@@ -1727,8 +1724,6 @@ enum netdev_priv_flags {
17271724
IFF_L3MDEV_RX_HANDLER = 1<<29,
17281725
IFF_NO_ADDRCONF = BIT_ULL(30),
17291726
IFF_TX_SKB_NO_LINEAR = BIT_ULL(31),
1730-
IFF_CHANGE_PROTO_DOWN = BIT_ULL(32),
1731-
IFF_SEE_ALL_HWTSTAMP_REQUESTS = BIT_ULL(33),
17321727
};
17331728

17341729
#define IFF_802_1Q_VLAN IFF_802_1Q_VLAN
@@ -1776,6 +1771,9 @@ enum netdev_ml_priv_type {
17761771
* data with strictly "high-level" data, and it has to know about
17771772
* almost every data structure used in the INET module.
17781773
*
1774+
* @priv_flags: flags invisible to userspace defined as bits, see
1775+
* enum netdev_priv_flags for the definitions
1776+
*
17791777
* @name: This is the first field of the "visible" part of this structure
17801778
* (i.e. as seen by users in the "Space.c" file). It is the name
17811779
* of the interface.
@@ -1842,8 +1840,6 @@ enum netdev_ml_priv_type {
18421840
*
18431841
* @flags: Interface flags (a la BSD)
18441842
* @xdp_features: XDP capability supported by the device
1845-
* @priv_flags: Like 'flags' but invisible to userspace,
1846-
* see if.h for the definitions
18471843
* @gflags: Global flags ( kept as legacy )
18481844
* @padded: How much padding added by alloc_netdev()
18491845
* @operstate: RFC2863 operstate
@@ -2012,6 +2008,12 @@ enum netdev_ml_priv_type {
20122008
*
20132009
* @threaded: napi threaded mode is enabled
20142010
*
2011+
* @see_all_hwtstamp_requests: device wants to see calls to
2012+
* ndo_hwtstamp_set() for all timestamp requests
2013+
* regardless of source, even if those aren't
2014+
* HWTSTAMP_SOURCE_NETDEV
2015+
* @change_proto_down: device supports setting carrier via IFLA_PROTO_DOWN
2016+
*
20152017
* @net_notifier_list: List of per-net netdev notifier block
20162018
* that follow this device when it is moved
20172019
* to another network namespace.
@@ -2060,7 +2062,9 @@ struct net_device {
20602062

20612063
/* TX read-mostly hotpath */
20622064
__cacheline_group_begin(net_device_read_tx);
2063-
unsigned long long priv_flags;
2065+
struct_group(priv_flags_fast,
2066+
unsigned long priv_flags:32;
2067+
);
20642068
const struct net_device_ops *netdev_ops;
20652069
const struct header_ops *header_ops;
20662070
struct netdev_queue *_tx;
@@ -2405,6 +2409,10 @@ struct net_device {
24052409
unsigned wol_enabled:1;
24062410
unsigned threaded:1;
24072411

2412+
/* priv_flags_slow, ungrouped to save space */
2413+
unsigned long see_all_hwtstamp_requests:1;
2414+
unsigned long change_proto_down:1;
2415+
24082416
struct list_head net_notifier_list;
24092417

24102418
#if IS_ENABLED(CONFIG_MACSEC)

net/8021q/vlanproc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,9 @@ static int vlandev_seq_show(struct seq_file *seq, void *offset)
252252

253253
stats = dev_get_stats(vlandev, &temp);
254254
seq_printf(seq,
255-
"%s VID: %d REORDER_HDR: %i dev->priv_flags: %llx\n",
255+
"%s VID: %d REORDER_HDR: %i dev->priv_flags: %x\n",
256256
vlandev->name, vlan->vlan_id,
257-
(int)(vlan->flags & 1), vlandev->priv_flags);
257+
(int)(vlan->flags & 1), (u32)vlandev->priv_flags);
258258

259259
seq_printf(seq, fmt64, "total frames received", stats->rx_packets);
260260
seq_printf(seq, fmt64, "total bytes received", stats->rx_bytes);

net/core/dev.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8986,7 +8986,7 @@ EXPORT_SYMBOL(netdev_port_same_parent_id);
89868986
*/
89878987
int dev_change_proto_down(struct net_device *dev, bool proto_down)
89888988
{
8989-
if (!(dev->priv_flags & IFF_CHANGE_PROTO_DOWN))
8989+
if (!dev->change_proto_down)
89908990
return -EOPNOTSUPP;
89918991
if (!netif_device_present(dev))
89928992
return -ENODEV;
@@ -11460,7 +11460,7 @@ static struct pernet_operations __net_initdata default_device_ops = {
1146011460
static void __init net_dev_struct_check(void)
1146111461
{
1146211462
/* TX read-mostly hotpath */
11463-
CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_tx, priv_flags);
11463+
CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_tx, priv_flags_fast);
1146411464
CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_tx, netdev_ops);
1146511465
CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_tx, header_ops);
1146611466
CACHELINE_ASSERT_GROUP_MEMBER(struct net_device, net_device_read_tx, _tx);

net/core/dev_ioctl.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,7 @@ static int dev_get_hwtstamp(struct net_device *dev, struct ifreq *ifr)
319319
* should take precedence in front of hardware timestamping provided by the
320320
* netdev. If the netdev driver needs to perform specific actions even for PHY
321321
* timestamping to work properly (a switch port must trap the timestamped
322-
* frames and not forward them), it must set IFF_SEE_ALL_HWTSTAMP_REQUESTS in
323-
* dev->priv_flags.
322+
* frames and not forward them), it must set dev->see_all_hwtstamp_requests.
324323
*/
325324
int dev_set_hwtstamp_phylib(struct net_device *dev,
326325
struct kernel_hwtstamp_config *cfg,
@@ -334,13 +333,13 @@ int dev_set_hwtstamp_phylib(struct net_device *dev,
334333

335334
cfg->source = phy_ts ? HWTSTAMP_SOURCE_PHYLIB : HWTSTAMP_SOURCE_NETDEV;
336335

337-
if (phy_ts && (dev->priv_flags & IFF_SEE_ALL_HWTSTAMP_REQUESTS)) {
336+
if (phy_ts && dev->see_all_hwtstamp_requests) {
338337
err = ops->ndo_hwtstamp_get(dev, &old_cfg);
339338
if (err)
340339
return err;
341340
}
342341

343-
if (!phy_ts || (dev->priv_flags & IFF_SEE_ALL_HWTSTAMP_REQUESTS)) {
342+
if (!phy_ts || dev->see_all_hwtstamp_requests) {
344343
err = ops->ndo_hwtstamp_set(dev, cfg, extack);
345344
if (err) {
346345
if (extack->_msg)
@@ -349,7 +348,7 @@ int dev_set_hwtstamp_phylib(struct net_device *dev,
349348
}
350349
}
351350

352-
if (phy_ts && (dev->priv_flags & IFF_SEE_ALL_HWTSTAMP_REQUESTS))
351+
if (phy_ts && dev->see_all_hwtstamp_requests)
353352
changed = kernel_hwtstamp_config_changed(&old_cfg, cfg);
354353

355354
if (phy_ts) {

net/core/rtnetlink.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2745,7 +2745,7 @@ static int do_set_proto_down(struct net_device *dev,
27452745
bool proto_down;
27462746
int err;
27472747

2748-
if (!(dev->priv_flags & IFF_CHANGE_PROTO_DOWN)) {
2748+
if (!dev->change_proto_down) {
27492749
NL_SET_ERR_MSG(extack, "Protodown not supported by device");
27502750
return -EOPNOTSUPP;
27512751
}

0 commit comments

Comments
 (0)