Skip to contentSkip to conversation

blk-mq: fix alignment mismatch.

PATCH In review Jian Cai 5 participants 14 messages Mar 30, 2021 – Apr 8, 2021 Block layer

lore
Share & tools
lore

Jian Cai

author
#0 lore raw

PATCH 1/1 blk-mq: fix alignment mismatch.

This fixes the mismatch of alignments between csd and its use as an argument to smp_call_function_single_async, which causes build failure when -Walign-mismatch in Clang is used.

Link:
http://crrev.com/c/1193732

---
 include/linux/blkdev.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/blkdev.h +1 -1
index bc6bc8383b43..3b92330d95ad 100644
@@ -231,7 +231,7 @@ struct request {
 	unsigned long deadline;
 
 	union {
-		struct __call_single_data csd;
+		call_single_data_t csd;
 		u64 fifo_time;
 	};
 
Signature · 1 line
2.31.0.291.g576ba9dcdaf-goog
#1 lore raw
Quoted 6 lines · Jian Cai

This fixes the mismatch of alignments between csd and its use as an argument to smp_call_function_single_async, which causes build failure when -Walign-mismatch in Clang is used.

Link:
http://crrev.com/c/1193732

That link does not work. You probably meant

	http://crbug.com/1193732

You'll probably want drop the link and to copy the relevant information directly into the patch description. Generate the error with an upstream kernel and cut-and-paste the output here.

For others, the observed error message is:

block/blk-mq.c:622:44: error: passing 8-byte aligned argument to 32-byte
aligned parameter 2 of 'smp_call_function_single_async' may result in an unaligned pointer access [-Werror,-Walign-mismatch]

Thanks,
Guenter

Quoted 23 lines
---
 include/linux/blkdev.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/blkdev.h +1 -1
index bc6bc8383b43..3b92330d95ad 100644
@@ -231,7 +231,7 @@ struct request {
 	unsigned long deadline;
 
 	union {
-		struct __call_single_data csd;
+		call_single_data_t csd;
 		u64 fifo_time;
 	};
 
Signature · 1 line
2.31.0.291.g576ba9dcdaf-goog
#2 lore raw
In reply to Jian Cai

Hi Jian,

Quoted 9 lines · Jian Cai

This fixes the mismatch of alignments between csd and its use as an argument to smp_call_function_single_async, which causes build failure when -Walign-mismatch in Clang is used.

Link:
http://crrev.com/c/1193732

Thanks for the patch. This is effectively a revert of commit 4ccafe032005 ("block: unalign call_single_data in struct request"), which I had brought up in this thread:

https://lore.kernel.org/r/20210310182307.zzcbi5w5jrmveld4@archlinux-ax161/

This is obviously a correct fix, I am not just sure what the impact to 'struct request' will be.

Cheers,
Nathan

Quoted 20 lines
---
 include/linux/blkdev.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/blkdev.h +1 -1
index bc6bc8383b43..3b92330d95ad 100644
@@ -231,7 +231,7 @@ struct request {
 	unsigned long deadline;
 
 	union {
-		struct __call_single_data csd;
+		call_single_data_t csd;
 		u64 fifo_time;
 	};
 
Signature · 1 line
2.31.0.291.g576ba9dcdaf-goog
#3 lore raw
Quoted 13 lines · Nathan Chancellor

Hi Jian,

Quoted 9 lines · Jian Cai

This fixes the mismatch of alignments between csd and its use as an argument to smp_call_function_single_async, which causes build failure when -Walign-mismatch in Clang is used.

Link:
http://crrev.com/c/1193732

Quoted 9 lines

Thanks for the patch. This is effectively a revert of commit 4ccafe032005 ("block: unalign call_single_data in struct request"), which I had brought up in this thread:

https://lore.kernel.org/r/20210310182307.zzcbi5w5jrmveld4@archlinux-ax161/

This is obviously a correct fix, I am not just sure what the impact to 'struct request' will be.

As commit 4ccafe032005 states, it increases the request structure size. Given the exchange referenced above, I think we'll need to disable the warning in the block code.

Thanks,
Guenter

Quoted 23 lines

Cheers,
Nathan

Quoted 20 lines
---
 include/linux/blkdev.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/blkdev.h +1 -1
index bc6bc8383b43..3b92330d95ad 100644
@@ -231,7 +231,7 @@ struct request {
 	unsigned long deadline;
 
 	union {
-		struct __call_single_data csd;
+		call_single_data_t csd;
 		u64 fifo_time;
 	};
 
Signature · 1 line
2.31.0.291.g576ba9dcdaf-goog
author
#4 lore raw

Thanks for all the information. I'll check for similar instances and send an updated version.

Quoted 56 lines · Guenter Roeck
Quoted 13 lines · Nathan Chancellor

Hi Jian,

Quoted 9 lines · Jian Cai

This fixes the mismatch of alignments between csd and its use as an argument to smp_call_function_single_async, which causes build failure when -Walign-mismatch in Clang is used.

Link:
http://crrev.com/c/1193732

Quoted 9 lines

Thanks for the patch. This is effectively a revert of commit 4ccafe032005 ("block: unalign call_single_data in struct request"), which I had brought up in this thread:

https://lore.kernel.org/r/20210310182307.zzcbi5w5jrmveld4@archlinux-ax161/

This is obviously a correct fix, I am not just sure what the impact to 'struct request' will be.

As commit 4ccafe032005 states, it increases the request structure size. Given the exchange referenced above, I think we'll need to disable the warning in the block code.

Thanks,
Guenter

Quoted 23 lines

Cheers,
Nathan

Quoted 20 lines
---
 include/linux/blkdev.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/blkdev.h +1 -2
index bc6bc8383b43..3b92330d95ad 100644
@@ -231,7 +231,7 @@ struct request {
     unsigned long deadline;
 
     union {
-            struct __call_single_data csd;
+            call_single_data_t csd;
             u64 fifo_time;
     };
 
--

2.31.0.291.g576ba9dcdaf-goog

author
#5 lore raw

Hi Nathan,

I just realized you already proposed solutions for skipping the check
in https://lore.kernel.org/linux-block/20210310225240.4epj2mdmzt4vurr3@archlinux-ax161/#t.
Do you have any plans to send them for review?

Thanks,
Jian

Quoted 62 lines · Jian Cai

Thanks for all the information. I'll check for similar instances and send an updated version.

Quoted 56 lines · Guenter Roeck
Quoted 13 lines · Nathan Chancellor

Hi Jian,

Quoted 9 lines · Jian Cai

This fixes the mismatch of alignments between csd and its use as an argument to smp_call_function_single_async, which causes build failure when -Walign-mismatch in Clang is used.

Link:
http://crrev.com/c/1193732

Quoted 9 lines

Thanks for the patch. This is effectively a revert of commit 4ccafe032005 ("block: unalign call_single_data in struct request"), which I had brought up in this thread:

https://lore.kernel.org/r/20210310182307.zzcbi5w5jrmveld4@archlinux-ax161/

This is obviously a correct fix, I am not just sure what the impact to 'struct request' will be.

As commit 4ccafe032005 states, it increases the request structure size. Given the exchange referenced above, I think we'll need to disable the warning in the block code.

Thanks,
Guenter

Quoted 23 lines

Cheers,
Nathan

Quoted 20 lines
---
 include/linux/blkdev.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/blkdev.h +1 -2
index bc6bc8383b43..3b92330d95ad 100644
@@ -231,7 +231,7 @@ struct request {
     unsigned long deadline;
 
     union {
-            struct __call_single_data csd;
+            call_single_data_t csd;
             u64 fifo_time;
     };
 
--

2.31.0.291.g576ba9dcdaf-goog

#6 lore raw

Hi Jian,

Quoted 8 lines · Jian Cai

Hi Nathan,

I just realized you already proposed solutions for skipping the check
in https://lore.kernel.org/linux-block/20210310225240.4epj2mdmzt4vurr3@archlinux-ax161/#t.
Do you have any plans to send them for review?

Thanks,
Jian

I was hoping to gather some feedback on which option would be preferred by Jens and the other ClangBuiltLinux folks before I sent them along. I can send the first just to see what kind of feedback I can gather.

Cheers,
Nathan

Quoted 63 lines · Jian Cai
Quoted 62 lines

Thanks for all the information. I'll check for similar instances and send an updated version.

Quoted 56 lines · Guenter Roeck
Quoted 13 lines · Nathan Chancellor

Hi Jian,

Quoted 9 lines · Jian Cai

This fixes the mismatch of alignments between csd and its use as an argument to smp_call_function_single_async, which causes build failure when -Walign-mismatch in Clang is used.

Link:
http://crrev.com/c/1193732

Quoted 9 lines

Thanks for the patch. This is effectively a revert of commit 4ccafe032005 ("block: unalign call_single_data in struct request"), which I had brought up in this thread:

https://lore.kernel.org/r/20210310182307.zzcbi5w5jrmveld4@archlinux-ax161/

This is obviously a correct fix, I am not just sure what the impact to 'struct request' will be.

As commit 4ccafe032005 states, it increases the request structure size. Given the exchange referenced above, I think we'll need to disable the warning in the block code.

Thanks,
Guenter

Quoted 23 lines

Cheers,
Nathan

Quoted 20 lines
---
 include/linux/blkdev.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/blkdev.h +1 -2
index bc6bc8383b43..3b92330d95ad 100644
@@ -231,7 +231,7 @@ struct request {
     unsigned long deadline;
 
     union {
-            struct __call_single_data csd;
+            call_single_data_t csd;
             u64 fifo_time;
     };
 
--

2.31.0.291.g576ba9dcdaf-goog

#7 lore raw
Quoted 10 lines · Nathan Chancellor
Quoted 4 lines · Jian Cai

I just realized you already proposed solutions for skipping the check
in https://lore.kernel.org/linux-block/20210310225240.4epj2mdmzt4vurr3@archlinux-ax161/#t.
Do you have any plans to send them for review?

I was hoping to gather some feedback on which option would be preferred by Jens and the other ClangBuiltLinux folks before I sent them along. I can send the first just to see what kind of feedback I can gather.

Either approach is fine by me. The smaller might be easier to get accepted into stable. The larger approach will probably become more useful in the future (having the diag infra work properly with clang). I think the ball is kind of in Jens' court to decide. Would doing both be appropriate, Jens? Have the smaller patch tagged for stable disabling it for the whole file, then another commit on top not tagged for stable that adds the diag infra, and a third on top replacing the file level warning disablement with local diags to isolate this down to one case? It's a fair but small amount of churn IMO; but if Jens is not opposed it seems fine?

Signature · 2 lines
Thanks,
~Nick Desaulniers
author
#8 lore raw

So this issue is blocking the LLVM upgrading on ChromeOS. Nathan, do you mind sending out the smaller patch like Nick suggested just to see what feedback we could get? I could send it for you if you are busy, and please let me know what tags I should use in that case.

Thanks,
Jian

Quoted 26 lines · Nick Desaulniers
Quoted 10 lines · Nathan Chancellor
Quoted 4 lines · Jian Cai

I just realized you already proposed solutions for skipping the check
in https://lore.kernel.org/linux-block/20210310225240.4epj2mdmzt4vurr3@archlinux-ax161/#t.
Do you have any plans to send them for review?

I was hoping to gather some feedback on which option would be preferred by Jens and the other ClangBuiltLinux folks before I sent them along. I can send the first just to see what kind of feedback I can gather.

Either approach is fine by me. The smaller might be easier to get accepted into stable. The larger approach will probably become more useful in the future (having the diag infra work properly with clang). I think the ball is kind of in Jens' court to decide. Would doing both be appropriate, Jens? Have the smaller patch tagged for stable disabling it for the whole file, then another commit on top not tagged for stable that adds the diag infra, and a third on top replacing the file level warning disablement with local diags to isolate this down to one case? It's a fair but small amount of churn IMO; but if Jens is not opposed it seems fine?
--
Thanks,
~Nick Desaulniers

#9 lore raw

Hi Jian,

Quoted 7 lines · Jian Cai

So this issue is blocking the LLVM upgrading on ChromeOS. Nathan, do you mind sending out the smaller patch like Nick suggested just to see what feedback we could get? I could send it for you if you are busy, and please let me know what tags I should use in that case.

Thanks,
Jian

I will go ahead and send the smaller patch at some point today.

For what it's worth, Nick brought up https://reviews.llvm.org/D100037,
which may be relevant here.

Cheers,
Nathan

Quoted 28 lines
Quoted 26 lines · Nick Desaulniers
Quoted 10 lines · Nathan Chancellor
Quoted 4 lines · Jian Cai

I just realized you already proposed solutions for skipping the check
in https://lore.kernel.org/linux-block/20210310225240.4epj2mdmzt4vurr3@archlinux-ax161/#t.
Do you have any plans to send them for review?

I was hoping to gather some feedback on which option would be preferred by Jens and the other ClangBuiltLinux folks before I sent them along. I can send the first just to see what kind of feedback I can gather.

Either approach is fine by me. The smaller might be easier to get accepted into stable. The larger approach will probably become more useful in the future (having the diag infra work properly with clang). I think the ball is kind of in Jens' court to decide. Would doing both be appropriate, Jens? Have the smaller patch tagged for stable disabling it for the whole file, then another commit on top not tagged for stable that adds the diag infra, and a third on top replacing the file level warning disablement with local diags to isolate this down to one case? It's a fair but small amount of churn IMO; but if Jens is not opposed it seems fine?
--
Thanks,
~Nick Desaulniers

author
#10 lore raw

Sounds good! Thanks for the help and the link.

Quoted 48 lines · Nathan Chancellor

Hi Jian,

Quoted 7 lines · Jian Cai

So this issue is blocking the LLVM upgrading on ChromeOS. Nathan, do you mind sending out the smaller patch like Nick suggested just to see what feedback we could get? I could send it for you if you are busy, and please let me know what tags I should use in that case.

Thanks,
Jian

I will go ahead and send the smaller patch at some point today.

For what it's worth, Nick brought up https://reviews.llvm.org/D100037,
which may be relevant here.

Cheers,
Nathan

Quoted 28 lines
Quoted 26 lines · Nick Desaulniers
Quoted 10 lines · Nathan Chancellor
Quoted 4 lines · Jian Cai

I just realized you already proposed solutions for skipping the check
in https://lore.kernel.org/linux-block/20210310225240.4epj2mdmzt4vurr3@archlinux-ax161/#t.
Do you have any plans to send them for review?

I was hoping to gather some feedback on which option would be preferred by Jens and the other ClangBuiltLinux folks before I sent them along. I can send the first just to see what kind of feedback I can gather.

Either approach is fine by me. The smaller might be easier to get accepted into stable. The larger approach will probably become more useful in the future (having the diag infra work properly with clang). I think the ball is kind of in Jens' court to decide. Would doing both be appropriate, Jens? Have the smaller patch tagged for stable disabling it for the whole file, then another commit on top not tagged for stable that adds the diag infra, and a third on top replacing the file level warning disablement with local diags to isolate this down to one case? It's a fair but small amount of churn IMO; but if Jens is not opposed it seems fine?
--
Thanks,
~Nick Desaulniers

#11 lore raw

PATCH 1/1 block: Disable -Walign-mismatch for blk-mq.c

In reply to Nathan Chancellor

LLVM 13 adds a new warning, -Walign-mismatch, which has an instance in blk_mq_complete_send_ipi():

block/blk-mq.c:630:39: warning: passing 8-byte aligned argument to 32-byte aligned parameter 2 of 'smp_call_function_single_async' may result in an unaligned pointer access [-Walign-mismatch]

                smp_call_function_single_async(cpu, &rq->csd);
                                                    ^

1 warning generated.

This is expected after commit 4ccafe032005 ("block: unalign call_single_data in struct request"), which purposefully unaligned the structure to save space. Given that there is no real alignment requirement and there have been no reports of issues since that change, it should be safe to disable the warning for this one translation unit.

---
 block/Makefile | 1 +
 1 file changed, 1 insertion(+)
block/Makefile +1 -0
index 8d841f5f986f..d69ac0bd8e61 100644
@@ -10,6 +10,7 @@ obj-$(CONFIG_BLOCK) := bio.o elevator.o blk-core.o blk-sysfs.o \
 			blk-mq-sysfs.o blk-mq-cpumap.o blk-mq-sched.o ioctl.o \
 			genhd.o ioprio.o badblocks.o partitions/ blk-rq-qos.o
 
+CFLAGS_blk-mq.o := $(call cc-disable-warning, align-mismatch)
 obj-$(CONFIG_BOUNCE)		+= bounce.o
 obj-$(CONFIG_BLK_SCSI_REQUEST)	+= scsi_ioctl.o
 obj-$(CONFIG_BLK_DEV_BSG)	+= bsg.o

base-commit: e49d033bddf5b565044e2abe4241353959bc9120

Signature · 1 line
2.31.1.189.g2e36527f23
Reviewed-by on v1 1/1
#12 lore raw

Re: [PATCH] block: Disable -Walign-mismatch for blk-mq.c

Quoted 16 lines · Nathan Chancellor

LLVM 13 adds a new warning, -Walign-mismatch, which has an instance in blk_mq_complete_send_ipi():

block/blk-mq.c:630:39: warning: passing 8-byte aligned argument to 32-byte aligned parameter 2 of 'smp_call_function_single_async' may result in an unaligned pointer access [-Walign-mismatch]

                smp_call_function_single_async(cpu, &rq->csd);
                                                    ^

1 warning generated.

This is expected after commit 4ccafe032005 ("block: unalign call_single_data in struct request"), which purposefully unaligned the structure to save space. Given that there is no real alignment requirement and there have been no reports of issues since that change, it should be safe to disable the warning for this one translation unit.

Quoted 4 lines
Quoted 19 lines
---
 block/Makefile | 1 +
 1 file changed, 1 insertion(+)
block/Makefile +1 -0
index 8d841f5f986f..d69ac0bd8e61 100644
@@ -10,6 +10,7 @@ obj-$(CONFIG_BLOCK) := bio.o elevator.o blk-core.o blk-sysfs.o \
 			blk-mq-sysfs.o blk-mq-cpumap.o blk-mq-sched.o ioctl.o \
 			genhd.o ioprio.o badblocks.o partitions/ blk-rq-qos.o
 
+CFLAGS_blk-mq.o := $(call cc-disable-warning, align-mismatch)
 obj-$(CONFIG_BOUNCE)		+= bounce.o
 obj-$(CONFIG_BLK_SCSI_REQUEST)	+= scsi_ioctl.o
 obj-$(CONFIG_BLK_DEV_BSG)	+= bsg.o

base-commit: e49d033bddf5b565044e2abe4241353959bc9120

#13 lore raw
In reply to Nathan Chancellor

From: Nathan Chancellor

Quoted 15 lines

Sent: 31 March 2021 00:30

Hi Jian,

Quoted 9 lines · Jian Cai

This fixes the mismatch of alignments between csd and its use as an argument to smp_call_function_single_async, which causes build failure when -Walign-mismatch in Clang is used.

Link:
http://crrev.com/c/1193732

Quoted 8 lines

Thanks for the patch. This is effectively a revert of commit 4ccafe032005 ("block: unalign call_single_data in struct request"), which I had brought up in this thread:

https://lore.kernel.org/r/20210310182307.zzcbi5w5jrmveld4@archlinux-ax161/

This is obviously a correct fix, I am not just sure what the impact to 'struct request' will be.

If the structure is allocated on-stack then aligning it requires the compiler generate the rather horrid 'double stack frame' for the function.

Possibly the unaligned 'struct' should be used by all the code except for a few places where it makes sense to allocate an aligned item?

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)