Skip to contentSkip to conversation

bcache: enable big endian support for IBM s390x

RFC PATCH In review Coly Li 2 participants 3 messages Mar 15, 2018

Subsystems (2)
lore
Share & tools
lore

Coly Li

author
#0 lore raw

RFC PATCH 1/1 bcache: enable big endian support for IBM s390x

Recently I receive bug report that bcache does not work on s390x machine. A reason is from bcache-tools, the user space code does not do byte order swapping before writing struct cache_sb to storage media.

Updating user space tools is not enough, the kernel code also has several issues,
1) checksum is checked after some super block members swap their byte order by calling leXX_to_cpu(). On little endian machines, it changes nothing and works, but on big endian machines it will make checksum checking to be failed.
2) bcache code also updates super block in start/attach/detach time, but the kernel code does not call cpu_to_leXX() to all necessary structure members. On little endian machines no byte swapping happens so it is OK, but on big endian machines, that means next time when bcache reads super block in, the checksum check will failed.
3) current code checks checksum after some members of cache_sb are swapped, this is incorrect. The checksum calculation should be done when all structure members are explicitly in little endian.

This patch fixes the above issues and now bcache can be registered and attach/detached on s390x machine.

Please note in this patch I add a new macro csum_set_le64(), it calculates checksum of struct cache_sb when all multi-bytes members are explicitly in little endian.

So far csum_set_le64() is only used in super block checksum calculation, because bucket prio and journal entries checksums are still calculated by CPU byte order. It won't be a problem if the backing device is not shared among machines with different CPU endianness.

Ask for help:
My S390x vm only has 8GB storage, and I cannot find extra space for now. When I run fio on bcache device I see allocator thread blocked on waiting bucket allocating. I am not sure whether it is because I use a sparse file as loop block device and the real space is too small. And the network latency to ping this machine is 0.6 second, it is too slow for any complicated operation...
So if any of you may provide me a faster S390 machine with large enough storage devices for further testing, that will be very helpful.

Thanks in advance.

---
 drivers/md/bcache/bcache.h |  10 ++++
 drivers/md/bcache/super.c  | 124 +++++++++++++++++++++++++++++----------------
 2 files changed, 90 insertions(+), 44 deletions(-)
drivers/md/bcache/bcache.h +10 -0
index 12e5197f186c..18e5aebd27c0 100644
@@ -782,6 +782,16 @@ static inline bool ptr_available(struct cache_set *c, const struct bkey *k,
 		  ((void *) bset_bkey_last(i)) -			\
 		  (((void *) (i)) + sizeof(uint64_t)))
 
+/*
+ * Same functionality as csum_set(), the difference is that all structure
+ * members are explicitly swapped to little endian byte order.
+ */
+#define csum_set_le64(i)						\
+	cpu_to_le64(bch_crc64(						\
+		(void *)(i) + sizeof(uint64_t),				\
+		(void *)((i)->d + le16_to_cpu((i)->keys)) -		\
+		((void *)(i) + sizeof(uint64_t))))			\
+
 /* Error handling macros */
 
 #define btree_bug(b, ...)						\
drivers/md/bcache/super.c +80 -44

186 lines not on this page · raw message

Signature · 1 line
2.16.2
#1 lore raw

drivers/md/bcache/super.c struct workqueue_struct *bcache_wq; · line 75

Quoted 8 lines
drivers/md/bcache/super.c +8 -0
+static void swap_cache_sb_from_cpu(struct cache_sb *sb,
+				   struct cache_sb *out)
+{
+	int i;
+
+	out->offset		= cpu_to_le64(sb->offset);
+	out->flags		= cpu_to_le64(sb->flags);
+	out->seq		= cpu_to_le64(sb->seq);

This looks completely bogus and sparse will complain loudly about it. Please make sure you have proper endianess annotations in place.

author
#2 lore raw
Quoted 12 lines · Christoph Hellwig

drivers/md/bcache/super.c struct workqueue_struct *bcache_wq; · line 75

Quoted 8 lines
drivers/md/bcache/super.c +8 -0
+static void swap_cache_sb_from_cpu(struct cache_sb *sb,
+				   struct cache_sb *out)
+{
+	int i;
+
+	out->offset		= cpu_to_le64(sb->offset);
+	out->flags		= cpu_to_le64(sb->flags);
+	out->seq		= cpu_to_le64(sb->seq);

This looks completely bogus and sparse will complain loudly about it. Please make sure you have proper endianess annotations in place.

Hi Christoph,

Oh, you notice me, I realize currently bcache does not have an on-disk super block format, struct cache_sb is used for both on-disk and in-memory.

Thanks for the hint, I need to separate on-disk data structures from in-memory ones.

Coly Li