dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

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

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