Skip to content

Commit 2eff9fa

Browse files
Eliminate use of _Static_assert
Instead, use BUILD_BUG_ON statements in homa_load (can't use BUILD_BUG_ON in header files).
1 parent c2259e0 commit 2eff9fa

File tree

4 files changed

+41
-49
lines changed

4 files changed

+41
-49
lines changed

homa.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,6 @@ struct homa_sendmsg_args {
7474
__u32 reserved;
7575
};
7676

77-
#if !defined(__cplusplus)
78-
_Static_assert(sizeof(struct homa_sendmsg_args) >= 24,
79-
"homa_sendmsg_args shrunk");
80-
_Static_assert(sizeof(struct homa_sendmsg_args) <= 24,
81-
"homa_sendmsg_args grew");
82-
#endif
83-
8477
/* Flag bits for homa_sendmsg_args.flags (see man page for documentation):
8578
*/
8679
#define HOMA_SENDMSG_PRIVATE 0x01
@@ -125,13 +118,6 @@ struct homa_recvmsg_args {
125118
__u32 bpage_offsets[HOMA_MAX_BPAGES];
126119
};
127120

128-
#if !defined(__cplusplus)
129-
_Static_assert(sizeof(struct homa_recvmsg_args) >= 88,
130-
"homa_recvmsg_args shrunk");
131-
_Static_assert(sizeof(struct homa_recvmsg_args) <= 88,
132-
"homa_recvmsg_args grew");
133-
#endif
134-
135121
#ifndef __STRIP__ /* See strip.py */
136122
/**
137123
* struct homa_abort_args - Structure that passes arguments and results
@@ -153,11 +139,6 @@ struct homa_abort_args {
153139
/** @_pad2: Reserved. */
154140
__u64 _pad2[2];
155141
};
156-
157-
#if !defined(__cplusplus)
158-
_Static_assert(sizeof(struct homa_abort_args) >= 32, "homa_abort_args shrunk");
159-
_Static_assert(sizeof(struct homa_abort_args) <= 32, "homa_abort_args grew");
160-
#endif
161142
#endif /* See strip.py */
162143

163144
/** define SO_HOMA_RCVBUF: setsockopt option for specifying buffer region. */

homa_plumbing.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,45 @@ int __init homa_load(void)
455455
struct homa *homa = global_homa;
456456
int status;
457457

458+
/* Compile-time validations that no packet header is longer
459+
* than HOMA_MAX_HEADER.
460+
*/
461+
BUILD_BUG_ON(sizeof(struct homa_data_hdr) > HOMA_MAX_HEADER);
462+
#ifndef __STRIP__ /* See strip.py */
463+
BUILD_BUG_ON(sizeof(struct homa_grant_hdr) > HOMA_MAX_HEADER);
464+
#endif /* See strip.py */
465+
BUILD_BUG_ON(sizeof(struct homa_resend_hdr) > HOMA_MAX_HEADER);
466+
BUILD_BUG_ON(sizeof(struct homa_rpc_unknown_hdr) > HOMA_MAX_HEADER);
467+
BUILD_BUG_ON(sizeof(struct homa_busy_hdr) > HOMA_MAX_HEADER);
468+
#ifndef __STRIP__ /* See strip.py */
469+
BUILD_BUG_ON(sizeof(struct homa_cutoffs_hdr) > HOMA_MAX_HEADER);
470+
#endif /* See strip.py */
471+
#ifndef __UPSTREAM__ /* See strip.py */
472+
BUILD_BUG_ON(sizeof(struct homa_freeze_hdr) > HOMA_MAX_HEADER);
473+
#endif /* See strip.py */
474+
BUILD_BUG_ON(sizeof(struct homa_need_ack_hdr) > HOMA_MAX_HEADER);
475+
BUILD_BUG_ON(sizeof(struct homa_ack_hdr) > HOMA_MAX_HEADER);
476+
477+
/* Extra constraints on data packets:
478+
* - Ensure minimum header length so Homa doesn't have to worry about
479+
* padding data packets.
480+
* - Make sure data packet headers are a multiple of 4 bytes (needed
481+
* for TCP/TSO compatibility).
482+
*/
483+
BUILD_BUG_ON(sizeof(struct homa_data_hdr) < HOMA_MIN_PKT_LENGTH);
484+
BUILD_BUG_ON((sizeof(struct homa_data_hdr) -
485+
sizeof(struct homa_seg_hdr)) & 0x3);
486+
487+
/* Homa requires at least 8 priority levels. */
488+
BUILD_BUG_ON(HOMA_MAX_PRIORITIES < 8);
489+
490+
/* Detect size changes in uAPI structs. */
491+
BUILD_BUG_ON(sizeof(struct homa_sendmsg_args) != 24);
492+
BUILD_BUG_ON(sizeof(struct homa_recvmsg_args) != 88);
493+
#ifndef __STRIP__ /* See strip.py */
494+
BUILD_BUG_ON(sizeof(struct homa_abort_args) != 32);
495+
#endif /* See strip.py */
496+
458497
pr_err("Homa module loading\n");
459498
#ifndef __STRIP__ /* See strip.py */
460499
pr_notice("Homa structure sizes: homa_data_hdr %lu, homa_seg_hdr %lu, ack %lu, peer %lu, ip_hdr %lu flowi %lu ipv6_hdr %lu, flowi6 %lu tcp_sock %lu homa_rpc %lu sk_buff %lu rcvmsg_control %lu union sockaddr_in_union %lu HOMA_MAX_BPAGES %u NR_CPUS %u nr_cpu_ids %u, MAX_NUMNODES %d\n",

homa_utils.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,7 @@
2828
int homa_init(struct homa *homa)
2929
{
3030
int err;
31-
#ifndef __STRIP__ /* See strip.py */
32-
int i;
33-
34-
_Static_assert(HOMA_MAX_PRIORITIES >= 8,
35-
"Homa requires at least 8 priority levels");
36-
#endif /* See strip.py */
31+
IF_NO_STRIP(int i);
3732

3833
memset(homa, 0, sizeof(*homa));
3934

homa_wire.h

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,6 @@ struct homa_data_hdr {
350350
/** @seg: First of possibly many segments. */
351351
struct homa_seg_hdr seg;
352352
} __packed;
353-
_Static_assert(sizeof(struct homa_data_hdr) <= HOMA_MAX_HEADER,
354-
"homa_data_hdr too large for HOMA_MAX_HEADER; must adjust HOMA_MAX_HEADER");
355-
_Static_assert(sizeof(struct homa_data_hdr) >= HOMA_MIN_PKT_LENGTH,
356-
"homa_data_hdr too small: Homa doesn't currently have code to pad data packets");
357-
_Static_assert(((sizeof(struct homa_data_hdr) - sizeof(struct homa_seg_hdr)) &
358-
0x3) == 0,
359-
" homa_data_hdr length not a multiple of 4 bytes (required for TCP/TSO compatibility");
360353

361354
/**
362355
* homa_data_len() - Returns the total number of bytes in a DATA packet
@@ -403,8 +396,6 @@ struct homa_grant_hdr {
403396
*/
404397
__u8 resend_all;
405398
} __packed;
406-
_Static_assert(sizeof(struct homa_grant_hdr) <= HOMA_MAX_HEADER,
407-
"homa_grant_hdr too large for HOMA_MAX_HEADER; must adjust HOMA_MAX_HEADER");
408399
#endif /* See strip.py */
409400

410401
/**
@@ -444,8 +435,6 @@ struct homa_resend_hdr {
444435
__u8 priority;
445436
#endif /* See strip.py */
446437
} __packed;
447-
_Static_assert(sizeof(struct homa_resend_hdr) <= HOMA_MAX_HEADER,
448-
"homa_resend_hdr too large for HOMA_MAX_HEADER; must adjust HOMA_MAX_HEADER");
449438

450439
/**
451440
* struct homa_rpc_unknown_hdr - Wire format for RPC_UNKNOWN packets.
@@ -460,8 +449,6 @@ struct homa_rpc_unknown_hdr {
460449
/** @common: Fields common to all packet types. */
461450
struct homa_common_hdr common;
462451
} __packed;
463-
_Static_assert(sizeof(struct homa_rpc_unknown_hdr) <= HOMA_MAX_HEADER,
464-
"homa_rpc_unknown_hdr too large for HOMA_MAX_HEADER; must adjust HOMA_MAX_HEADER");
465452

466453
/**
467454
* struct homa_busy_hdr - Wire format for BUSY packets.
@@ -473,8 +460,6 @@ struct homa_busy_hdr {
473460
/** @common: Fields common to all packet types. */
474461
struct homa_common_hdr common;
475462
} __packed;
476-
_Static_assert(sizeof(struct homa_busy_hdr) <= HOMA_MAX_HEADER,
477-
"homa_busy_hdr too large for HOMA_MAX_HEADER; must adjust HOMA_MAX_HEADER");
478463

479464
#ifndef __STRIP__ /* See strip.py */
480465
/**
@@ -501,9 +486,7 @@ struct homa_cutoffs_hdr {
501486
*/
502487
__be16 cutoff_version;
503488
} __packed;
504-
_Static_assert(sizeof(struct homa_cutoffs_hdr) <= HOMA_MAX_HEADER,
505-
"homa_cutoffs_hdr too large for HOMA_MAX_HEADER; must adjust HOMA_MAX_HEADER");
506-
#endif /* See strip.py */
489+
#endif /* See strip.py */
507490

508491
#ifndef __UPSTREAM__ /* See strip.py */
509492
/**
@@ -516,8 +499,6 @@ struct homa_freeze_hdr {
516499
/** @common: Fields common to all packet types. */
517500
struct homa_common_hdr common;
518501
} __packed;
519-
_Static_assert(sizeof(struct homa_freeze_hdr) <= HOMA_MAX_HEADER,
520-
"homa_freeze_hdr too large for HOMA_MAX_HEADER; must adjust HOMA_MAX_HEADER");
521502
#endif /* See strip.py */
522503

523504
/**
@@ -530,8 +511,6 @@ struct homa_need_ack_hdr {
530511
/** @common: Fields common to all packet types. */
531512
struct homa_common_hdr common;
532513
} __packed;
533-
_Static_assert(sizeof(struct homa_need_ack_hdr) <= HOMA_MAX_HEADER,
534-
"homa_need_ack_hdr too large for HOMA_MAX_HEADER; must adjust HOMA_MAX_HEADER");
535514

536515
/**
537516
* struct homa_ack_hdr - Wire format for ACK packets.
@@ -551,8 +530,6 @@ struct homa_ack_hdr {
551530
/** @acks: Info about RPCs that are no longer active. */
552531
struct homa_ack acks[HOMA_MAX_ACKS_PER_PKT];
553532
} __packed;
554-
_Static_assert(sizeof(struct homa_ack_hdr) <= HOMA_MAX_HEADER,
555-
"homa_ack_hdr too large for HOMA_MAX_HEADER; must adjust HOMA_MAX_HEADER");
556533

557534
/**
558535
* homa_local_id(): given an RPC identifier from an input packet (which

0 commit comments

Comments
 (0)