Avoid declaring ALIGN() and __aligned() in include/uapi/linux/mic_common.h since they pollute user space namespace. Also, mic_aligned_size() can be simply replaced simply by sizeof() since all structures where mic_aligned_size() is used are declared using __attribute__ ((aligned(8))); -- >From mail from H Peter Anvin about this: On Fri, Nov 08, 2013 H Peter Anvin <h.peter.anvin@intel.com> wrote: Subject: Namespace pollution in mic_common.h This puts two macros, ALIGN() and __aligned(), into arbitrary user space namespace. This really isn't safe or acceptable, especially since those symbols are highly generic. ... When these structures are forced-aligned, they will in fact have padding automatically added by the compiler to an 8-byte boundary anyway, so mic_aligned_size() does nothing. ...
Showing the changes to include/uapi/linux (1 of 5 files). Show all
Unified · Split
| @@ -23,12 +23,7 @@ · 22 unmodified lines | ||
| 23 | 23 | |
| 24 | 24 | #include <linux/virtio_ring.h> |
| 25 | 25 | |
| 26 | −#ifndef __KERNEL__ | |
| 27 | −#define ALIGN(a, x) (((a) + (x) - 1) & ~((x) - 1)) | |
| 28 | −#define __aligned(x) __attribute__ ((aligned(x))) | |
| 29 | −#endif | |
| 30 | − | |
| 31 | −#define mic_aligned_size(x) ALIGN(sizeof(x), 8) | |
| 26 | +#define __mic_align(a, x) (((a) + (x) - 1) & ~((x) - 1)) | |
| 32 | 27 | |
| 33 | 28 | /** |
| 34 | 29 | * struct mic_device_desc: Virtio device information shared between the |
| @@ -49,7 +44,7 @@ struct mic_device_desc { · 14 unmodified lines | ||
| 49 | 44 | __u8 config_len; |
| 50 | 45 | __u8 status; |
| 51 | 46 | __u64 config[0]; |
| 52 | −} __aligned(8); | |
| 47 | +} __attribute__ ((aligned(8))); | |
| 53 | 48 | |
| 54 | 49 | /** |
| 55 | 50 | * struct mic_device_ctrl: Per virtio device information in the device page |
| @@ -74,7 +69,7 @@ struct mic_device_ctrl { · 18 unmodified lines | ||
| 74 | 69 | __u8 used_address_updated; |
| 75 | 70 | __s8 c2h_vdev_db; |
| 76 | 71 | __s8 h2c_vdev_db; |
| 77 | −} __aligned(8); | |
| 72 | +} __attribute__ ((aligned(8))); | |
| 78 | 73 | |
| 79 | 74 | /** |
| 80 | 75 | * struct mic_bootparam: Virtio device independent information in device page |
| @@ -93,7 +88,7 @@ struct mic_bootparam { · 12 unmodified lines | ||
| 93 | 88 | __s8 h2c_config_db; |
| 94 | 89 | __u8 shutdown_status; |
| 95 | 90 | __u8 shutdown_card; |
| 96 | −} __aligned(8); | |
| 91 | +} __attribute__ ((aligned(8))); | |
| 97 | 92 | |
| 98 | 93 | /** |
| 99 | 94 | * struct mic_device_page: High level representation of the device page |
| @@ -119,7 +114,7 @@ struct mic_vqconfig { · 19 unmodified lines | ||
| 119 | 114 | __u64 address; |
| 120 | 115 | __u64 used_address; |
| 121 | 116 | __u16 num; |
| 122 | −} __aligned(8); | |
| 117 | +} __attribute__ ((aligned(8))); | |
| 123 | 118 | |
| 124 | 119 | /* |
| 125 | 120 | * The alignment to use between consumer and producer parts of vring. |
| @@ -173,15 +168,13 @@ struct mic_vring { · 47 unmodified lines | ||
| 173 | 168 | int len; |
| 174 | 169 | }; |
| 175 | 170 | |
| 176 | −#define mic_aligned_desc_size(d) ALIGN(mic_desc_size(d), 8) | |
| 171 | +#define mic_aligned_desc_size(d) __mic_align(mic_desc_size(d), 8) | |
| 177 | 172 | |
| 178 | 173 | #ifndef INTEL_MIC_CARD |
| 179 | 174 | static inline unsigned mic_desc_size(const struct mic_device_desc *desc) |
| 180 | 175 | { |
| 181 | − return mic_aligned_size(*desc) | |
| 182 | − + desc->num_vq * mic_aligned_size(struct mic_vqconfig) | |
| 183 | − + desc->feature_len * 2 | |
| 184 | − + desc->config_len; | |
| 176 | + return sizeof(*desc) + desc->num_vq * sizeof(struct mic_vqconfig) | |
| 177 | + + desc->feature_len * 2 + desc->config_len; | |
| 185 | 178 | } |
| 186 | 179 | |
| 187 | 180 | static inline struct mic_vqconfig * |
| @@ -201,8 +194,7 @@ static inline __u8 *mic_vq_configspace(const struct mic_device_desc *desc) · 13 unmodified lines | ||
| 201 | 194 | } |
| 202 | 195 | static inline unsigned mic_total_desc_size(struct mic_device_desc *desc) |
| 203 | 196 | { |
| 204 | − return mic_aligned_desc_size(desc) + | |
| 205 | − mic_aligned_size(struct mic_device_ctrl); | |
| 197 | + return mic_aligned_desc_size(desc) + sizeof(struct mic_device_ctrl); | |
| 206 | 198 | } |
| 207 | 199 | #endif |
| 208 | 200 | |