Skip to content

ldv benchmarks, invalid offset in `netdev_priv` creating undefined behaviors

Function netdev_priv is used in quite a few benchmarks to return a substruct within a struct through some pointer arithmetic.

The current implementation in the benchmarks is:

 __inline static void *netdev_priv(struct net_device const *dev ) {
  return ((void *)dev + 3264U);
}

However, the offset computation is wrong, and currently results in uncaught undefined behaviors. Going back to the source code in the linux kernel (at the corresponding version of the benchmarks), we can gather:

// include/linux/netdevice.h
static inline void *netdev_priv(const struct net_device *dev)
{
    return (char *)dev + ALIGN(sizeof(struct net_device), NETDEV_ALIGN);
}
#define NETDEV_ALIGN        32

// include/linux/kernel.h
#define ALIGN(x, a)     __ALIGN_KERNEL((x), (a))

// include/uapi/linux/kernel.h
#define __ALIGN_KERNEL(x, a)        __ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1)
#define __ALIGN_KERNEL_MASK(x, mask)    (((x) + (mask)) & ~(mask))

Doing the computation, the correct offset is 3232U, not 3264U.

I have identified this issue in the benchmarks below:

  • c/ldv-linux-4.0-rc1-mav/linux-4.0-rc1---drivers--net--ethernet--qlogic--qlge--qlge.ko.cil.i. In that case, the is_zero_ether_addr bug (#1344) has to be fixed too. And btw, I am also really confused by the double return at lines 19194-19195 in ldv_alloc_etherdev_mqs_151.
  • c/ldv-linux-3.0/usb_urb-drivers-net-usb-catc.ko.cil.out.i
  • c/ldv-linux-3.12-rc1/linux-3.12-rc1.tar.xz-144_2a-drivers--net--usb--ipheth.ko-entry_point.cil.out.i
  • c/ldv-validator-v0.6/linux-stable-073676f-1-114_1a-drivers--net--b44.ko-entry_point.cil.out.i
  • c/ldv-validator-v0.8/linux-stable-073676f-1-114_1a-drivers--net--b44.ko-entry_point_ldv-val-v0.8.cil.out.i
  • c/ldv-validator-v0.8/linux-stable-468e4e3-1-204_8a-drivers--net--jme.ko-entry_point_ldv-val-v0.8.cil.out.
  • c/ldv-validator-v0.8/linux-stable-47dffc7-1-144_2a-drivers--net--usb--cdc-phonet.ko-entry_point_ldv-val-v0.8.cil.out.i
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information