• Stefan Hajnoczi's avatar
    vfio: align capability structures · a881b496
    Stefan Hajnoczi authored
    The VFIO_DEVICE_GET_INFO, VFIO_DEVICE_GET_REGION_INFO, and
    VFIO_IOMMU_GET_INFO ioctls fill in an info struct followed by capability
    structs:
    
      +------+---------+---------+-----+
      | info | caps[0] | caps[1] | ... |
      +------+---------+---------+-----+
    
    Both the info and capability struct sizes are not always multiples of
    sizeof(u64), leaving u64 fields in later capability structs misaligned.
    
    Userspace applications currently need to handle misalignment manually in
    order to support CPU architectures and programming languages with strict
    alignment requirements.
    
    Make life easier for userspace by ensuring alignment in the kernel. This
    is done by padding info struct definitions and by copying out zeroes
    after capability structs that are not aligned.
    
    The new layout is as follows:
    
      +------+---------+---+---------+-----+
      | info | caps[0] | 0 | caps[1] | ... |
      +------+---------+---+---------+-----+
    
    In this example caps[0] has a size that is not multiples of sizeof(u64),
    ...
    a881b496
vfio_compat.c 14.2 KB