Blame SOURCES/0047-super-intel-don-t-mark-structs-packed-unnecessarily.patch

2910d5
From 761e3bd9f5e3aafa95ad3ae50a637dc67c8774f0 Mon Sep 17 00:00:00 2001
2910d5
From: NeilBrown <neilb@suse.de>
2910d5
Date: Thu, 31 Oct 2019 15:15:38 +1100
2910d5
Subject: [RHEL7.8 PATCH V2 47/47] super-intel: don't mark structs 'packed'
2910d5
 unnecessarily
2910d5
2910d5
super-intel marks a number of structures 'packed', but this
2910d5
doesn't change the layout - they are already well organized.
2910d5
2910d5
This is a problem a gcc warns when code takes the address
2910d5
of a field in a packet struct - as super-intel sometimes does.
2910d5
2910d5
So remove the marking where isn't needed.
2910d5
Do ensure this does introduce a regression, add a compile-time
2910d5
assertion that the size of the structure is exactly the value
2910d5
it had before the 'packed' notation was removed.
2910d5
2910d5
Note that a couple of structure do need to be packed.
2910d5
As the address of fields is never taken, that is safe.
2910d5
2910d5
Signed-off-by: NeilBrown <neilb@suse.de>
2910d5
Acked-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
2910d5
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
2910d5
---
2910d5
 super-intel.c | 32 ++++++++++++++++++++++++++------
2910d5
 1 file changed, 26 insertions(+), 6 deletions(-)
2910d5
2910d5
diff --git a/super-intel.c b/super-intel.c
2910d5
index 713058c..a7fbed4 100644
2910d5
--- a/super-intel.c
2910d5
+++ b/super-intel.c
2910d5
@@ -96,6 +96,19 @@
2910d5
 						   * mutliple PPL area
2910d5
 						   */
2910d5
 
2910d5
+/*
2910d5
+ * This macro let's us ensure that no-one accidentally
2910d5
+ * changes the size of a struct
2910d5
+ */
2910d5
+#define ASSERT_SIZE(_struct, size) \
2910d5
+static inline void __assert_size_##_struct(void)	\
2910d5
+{							\
2910d5
+	switch (0) {					\
2910d5
+	case 0: break;					\
2910d5
+	case (sizeof(struct _struct) == size): break;	\
2910d5
+	}						\
2910d5
+}
2910d5
+
2910d5
 /* Disk configuration info. */
2910d5
 #define IMSM_MAX_DEVICES 255
2910d5
 struct imsm_disk {
2910d5
@@ -112,6 +125,7 @@ struct imsm_disk {
2910d5
 #define	IMSM_DISK_FILLERS	3
2910d5
 	__u32 filler[IMSM_DISK_FILLERS]; /* 0xF5 - 0x107 MPB_DISK_FILLERS for future expansion */
2910d5
 };
2910d5
+ASSERT_SIZE(imsm_disk, 48)
2910d5
 
2910d5
 /* map selector for map managment
2910d5
  */
2910d5
@@ -146,7 +160,8 @@ struct imsm_map {
2910d5
 	__u32 disk_ord_tbl[1];	/* disk_ord_tbl[num_members],
2910d5
 				 * top byte contains some flags
2910d5
 				 */
2910d5
-} __attribute__ ((packed));
2910d5
+};
2910d5
+ASSERT_SIZE(imsm_map, 52)
2910d5
 
2910d5
 struct imsm_vol {
2910d5
 	__u32 curr_migr_unit;
2910d5
@@ -169,7 +184,8 @@ struct imsm_vol {
2910d5
 	__u32 filler[4];
2910d5
 	struct imsm_map map[1];
2910d5
 	/* here comes another one if migr_state */
2910d5
-} __attribute__ ((packed));
2910d5
+};
2910d5
+ASSERT_SIZE(imsm_vol, 84)
2910d5
 
2910d5
 struct imsm_dev {
2910d5
 	__u8  volume[MAX_RAID_SERIAL_LEN];
2910d5
@@ -220,7 +236,8 @@ struct imsm_dev {
2910d5
 #define IMSM_DEV_FILLERS 3
2910d5
 	__u32 filler[IMSM_DEV_FILLERS];
2910d5
 	struct imsm_vol vol;
2910d5
-} __attribute__ ((packed));
2910d5
+};
2910d5
+ASSERT_SIZE(imsm_dev, 164)
2910d5
 
2910d5
 struct imsm_super {
2910d5
 	__u8 sig[MAX_SIGNATURE_LENGTH];	/* 0x00 - 0x1F */
2910d5
@@ -248,7 +265,8 @@ struct imsm_super {
2910d5
 	struct imsm_disk disk[1];	/* 0xD8 diskTbl[numDisks] */
2910d5
 	/* here comes imsm_dev[num_raid_devs] */
2910d5
 	/* here comes BBM logs */
2910d5
-} __attribute__ ((packed));
2910d5
+};
2910d5
+ASSERT_SIZE(imsm_super, 264)
2910d5
 
2910d5
 #define BBM_LOG_MAX_ENTRIES 254
2910d5
 #define BBM_LOG_MAX_LBA_ENTRY_VAL 256		/* Represents 256 LBAs */
2910d5
@@ -269,7 +287,8 @@ struct bbm_log {
2910d5
 	__u32 signature; /* 0xABADB10C */
2910d5
 	__u32 entry_count;
2910d5
 	struct bbm_log_entry marked_block_entries[BBM_LOG_MAX_ENTRIES];
2910d5
-} __attribute__ ((__packed__));
2910d5
+};
2910d5
+ASSERT_SIZE(bbm_log, 2040)
2910d5
 
2910d5
 static char *map_state_str[] = { "normal", "uninitialized", "degraded", "failed" };
2910d5
 
2910d5
@@ -323,7 +342,8 @@ struct migr_record {
2910d5
 				       * destination - high order 32 bits */
2910d5
 	__u32 num_migr_units_hi;      /* Total num migration units-of-op
2910d5
 				       * high order 32 bits */
2910d5
-} __attribute__ ((__packed__));
2910d5
+};
2910d5
+ASSERT_SIZE(migr_record, 64)
2910d5
 
2910d5
 struct md_list {
2910d5
 	/* usage marker:
2910d5
-- 
2910d5
2.7.5
2910d5