Nvethernet: Bug in SICGHWTSTAMP ioctl

Jetson AGX Orin devkit with Jetpack 7.2, stock BSP installed.

The following sequence initializing PTP timestamping by linuxptp fails: linuxptp/sk.c at e312b959a7dd3e8db0c6c8e282917c89909f8f76 · nwtime/linuxptp · GitHub .

What happens is that the program calls SIOCGHWTSTAMP with cfg.flags = HWTSTAMP_FLAG_BONDED_PHC_INDEX. However, the nvethernet driver doesn’t respond with EOPNOTSUPP (which would mean VLAN over bond is not supported on this interface). The nvethernet driver code in ether_linux.c , function ether_ioctl() does just this:

case SIOCGHWTSTAMP:
		config = &pdata->ptp_config;
		ret = copy_to_user(rq->ifr_data, config, sizeof(*config)) ? -EFAULT : 0;
		break;

So it does not check the cfg.flags at all. This means linuxptp thinks that HWTSTAMP_FLAG_BONDED_PHC_INDEX flag is supported.

In the next round, linuxptp tries to set the timestamping mode with SIOCSHWTSTAMP with cfg.flags set to HWTSTAMP_FLAG_BONDED_PHC_INDEX.

However, in nvethernet driver, file ptp.c, function ether_handle_hwtstamp_ioctl(), this is what happens:

/* reserved for future extensions */
	if (config.flags) {
		return -EINVAL;
	}

So linuxptp is unhappy because GHWTSTAMP told it that the flag is supported, but SHWTSTAMP fails when it is set.

The driver should be fixed to either correctly implement the VLAN over bond behavior, or to at least not pretend it support it.

One possible solution could be (I didn’t check this compiles):

case SIOCGHWTSTAMP:
        struct hwtstamp_config in_config;
        if (copy_from_user(&in_config, ifr->ifr_data, sizeof(struct hwtstamp_config))) {
    		return -EFAULT;
	    }
        if (in_config.flags > 0)
            return -EOPNOTSUPP;

		config = &pdata->ptp_config;
		ret = copy_to_user(rq->ifr_data, config, sizeof(*config)) ? -EFAULT : 0;
		break;

Hmm, maybe it could be something else. linuxptp receives error value -1 which would be EPERM and not EINVAL. However, maybe something mangles this error on its way, because when I set flags = 0, the call succeeds and timestamping is set up.