linux-stable/Documentation
Jakub Kicinski 1cf0b558cb netlink: add variable-length / auto integers
[ Upstream commit 374d345d9b ]

We currently push everyone to use padding to align 64b values
in netlink. Un-padded nla_put_u64() doesn't even exist any more.

The story behind this possibly start with this thread:
https://lore.kernel.org/netdev/20121204.130914.1457976839967676240.davem@davemloft.net/
where DaveM was concerned about the alignment of a structure
containing 64b stats. If user space tries to access such struct
directly:

	struct some_stats *stats = nla_data(attr);
	printf("A: %llu", stats->a);

lack of alignment may become problematic for some architectures.
These days we most often put every single member in a separate
attribute, meaning that the code above would use a helper like
nla_get_u64(), which can deal with alignment internally.
Even for arches which don't have good unaligned access - access
aligned to 4B should be pretty efficient.
Kernel and well known libraries deal with unaligned input already.

Padded 64b is quite space-inefficient (64b + pad means at worst 16B
per attr vs 32b which takes 8B). It is also more typing:

    if (nla_put_u64_pad(rsp, NETDEV_A_SOMETHING_SOMETHING,
                        value, NETDEV_A_SOMETHING_PAD))

Create a new attribute type which will use 32 bits at netlink
level if value is small enough (probably most of the time?),
and (4B-aligned) 64 bits otherwise. Kernel API is just:

    if (nla_put_uint(rsp, NETDEV_A_SOMETHING_SOMETHING, value))

Calling this new type "just" sint / uint with no specific size
will hopefully also make people more comfortable with using it.
Currently telling people "don't use u8, you may need the bits,
and netlink will round up to 4B, anyway" is the #1 comment
we give to newcomers.

In terms of netlink layout it looks like this:

         0       4       8       12      16
32b:     [nlattr][ u32  ]
64b:     [  pad ][nlattr][     u64      ]
uint(32) [nlattr][ u32  ]
uint(64) [nlattr][     u64      ]

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Acked-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Stable-dep-of: 030e1c4566 ("macsec: read MACSEC_SA_ATTR_PN with nla_get_uint")
Signed-off-by: Sasha Levin <sashal@kernel.org>
2025-09-09 18:56:22 +02:00
..
ABI x86/bugs: Add a Transient Scheduler Attacks mitigation 2025-07-10 16:03:21 +02:00
accel
accounting
admin-guide x86/bugs: Add a Transient Scheduler Attacks mitigation 2025-07-10 16:03:21 +02:00
arch x86/bugs: Rename MDS machinery to something more generic 2025-07-10 16:03:21 +02:00
block
bpf bpf: Adjust free target to avoid global starvation of LRU map 2025-07-17 18:35:21 +02:00
cdrom
core-api module: Provide EXPORT_SYMBOL_GPL_FOR_MODULES() helper 2025-07-10 16:03:18 +02:00
cpu-freq
crypto
dev-tools
devicetree dt-bindings: display/msm: qcom,mdp5: drop lut clock 2025-09-04 15:30:22 +02:00
doc-guide
driver-api serial: mctrl_gpio: split disable_ms into sync and no_sync APIs 2025-06-04 14:42:07 +02:00
fault-injection
fb
features
filesystems fscrypt: Don't use problematic non-inline crypto engines 2025-08-28 16:28:40 +02:00
firmware_class
firmware-guide Documentation: ACPI: Fix parent device references 2025-08-28 16:28:12 +02:00
fpga
gpu
hid
hwmon hwmon: (dell-smm) Increment the number of fans 2025-06-04 14:42:00 +02:00
i2c
iio
images
infiniband
input
isdn
kbuild
kernel-hacking
leds
litmus-tests
livepatch
locking
maintainer
mhi
misc-devices
mm
netlabel
netlink netlink: specs: ethtool: fix module EEPROM input/output arguments 2025-08-15 12:09:02 +02:00
networking bonding: Add independent control state machine 2025-08-28 16:28:49 +02:00
nvdimm
nvme
PCI
pcmcia
peci
power PM: runtime: Simplify pm_runtime_get_if_active() usage 2025-08-28 16:28:42 +02:00
powerpc
process
RCU
riscv
rust
scheduler sched/topology: Consolidate and clean up access to a CPU's max compute capacity 2025-05-02 07:50:41 +02:00
scsi
security
sound
sphinx
sphinx-static
spi
staging
target
timers sched/isolation: Prevent boot crash when the boot CPU is nohz_full 2025-03-22 12:50:37 -07:00
tools
trace
translations
usb
userspace-api netlink: add variable-length / auto integers 2025-09-09 18:56:22 +02:00
virt
w1
watchdog
wmi
.gitignore
atomic_bitops.txt
atomic_t.txt
Changes
CodingStyle
conf.py
docutils.conf
dontdiff
index.rst
Kconfig
Makefile
memory-barriers.txt
SubmittingPatches
subsystem-apis.rst