Skip to contentSkip to conversation

drivers: hv: vmbus: Fix build on Clang 12 failed by DMA_BIT_MASK(64) expansion

PATCH Superseded Vitaly Chikunov 3 participants 4 messages Feb 4, 2022

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 drivers: hv: vmbus: Fix build on Clang 12 failed by DMA_BIT_MASK(64) expansion

Clang 12.0.1 cannot understand that value 64 is excluded from the shift at compile time (for use in global context) resulting in build error[1]:

drivers/hv/vmbus_drv.c:2082:29: error: shift count >= width of type [-Werror,-Wshift-count-overflow]

  static u64 vmbus_dma_mask = DMA_BIT_MASK(64);
			      ^~~~~~~~~~~~~~~~
  ./include/linux/dma-mapping.h:76:54: note: expanded from macro 'DMA_BIT_MASK'
  #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
						       ^ ~~~

Avoid using DMA_BIT_MASK macro for that corner case.

---
Changes since v1:
- Patch description updated, s/GCC 11/Clang 12/.

 drivers/hv/vmbus_drv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hv/vmbus_drv.c +1 -1
index 17bf55fe3169..2376ee484362 100644
@@ -2079,7 +2079,7 @@ struct hv_device *vmbus_device_create(const guid_t *type,
 	return child_device_obj;
 }
 
-static u64 vmbus_dma_mask = DMA_BIT_MASK(64);
+static u64 vmbus_dma_mask = ~0ULL;
 /*
  * vmbus_device_register - Register the child device
  */
Signature · 1 line
2.33.0
#1 lore raw
Quoted 11 lines · Vitaly Chikunov

Clang 12.0.1 cannot understand that value 64 is excluded from the shift at compile time (for use in global context) resulting in build error[1]:

drivers/hv/vmbus_drv.c:2082:29: error: shift count >= width of type [-Werror,-Wshift-count-overflow]

  static u64 vmbus_dma_mask = DMA_BIT_MASK(64);
			      ^~~~~~~~~~~~~~~~
  ./include/linux/dma-mapping.h:76:54: note: expanded from macro 'DMA_BIT_MASK'
  #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
						       ^ ~~~

Avoid using DMA_BIT_MASK macro for that corner case.

Was this reported to Clang already? It looks like a clear bug on their side.

Quoted 27 lines

---
Changes since v1:
- Patch description updated, s/GCC 11/Clang 12/.

 drivers/hv/vmbus_drv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hv/vmbus_drv.c +1 -1
index 17bf55fe3169..2376ee484362 100644
@@ -2079,7 +2079,7 @@ struct hv_device *vmbus_device_create(const guid_t *type,
 	return child_device_obj;
 }
 
-static u64 vmbus_dma_mask = DMA_BIT_MASK(64);
+static u64 vmbus_dma_mask = ~0ULL;
 /*
  * vmbus_device_register - Register the child device
  */
Signature · 1 line
Vitaly
maintainer
#2 lore raw
Quoted 12 lines · Vitaly Kuznetsov
Quoted 10 lines · Vitaly Chikunov

Clang 12.0.1 cannot understand that value 64 is excluded from the shift at compile time (for use in global context) resulting in build error[1]:

drivers/hv/vmbus_drv.c:2082:29: error: shift count >= width of type [-Werror,-Wshift-count-overflow]

  static u64 vmbus_dma_mask = DMA_BIT_MASK(64);
			      ^~~~~~~~~~~~~~~~
  ./include/linux/dma-mapping.h:76:54: note: expanded from macro 'DMA_BIT_MASK'
  #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
						       ^ ~~~
Quoted 3 lines
Quoted 1 line

Avoid using DMA_BIT_MASK macro for that corner case.

Was this reported to Clang already? It looks like a clear bug on their side.

This is already known.

I dealt with a similar report before. At the time I decided nothing's wrong with the code.

https://lore.kernel.org/linux-kernel/YcC1CobR%2Fn0tJhdV@archlinux-ax161/
https://github.com/ClangBuiltLinux/linux/issues/92

I can certainly live with a workaround like this.

Quoted 23 lines
Quoted 23 lines

---
Changes since v1:
- Patch description updated, s/GCC 11/Clang 12/.

 drivers/hv/vmbus_drv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hv/vmbus_drv.c +0 -0
index 17bf55fe3169..2376ee484362 100644
@@ -2079,7 +2079,7 @@ struct hv_device *vmbus_device_create(const guid_t *type,
 	return child_device_obj;
 }
 
Quoted 1 line

drivers/hv/vmbus_drv.c struct hv_device *vmbus_device_create(const guid_t *type, · line 2082

Quoted 1 line
drivers/hv/vmbus_drv.c +0 -1
-static u64 vmbus_dma_mask = DMA_BIT_MASK(64);

Please add a comment here

// Use ~0ULL instead of DMA_BIT_MASK(64) to work around a bug in Clang.

Quoted 8 lines
Quoted 4 lines
drivers/hv/vmbus_drv.c +1 -0
+static u64 vmbus_dma_mask = ~0ULL;
 /*
  * vmbus_device_register - Register the child device
  */
Signature · 1 line
Vitaly
maintainer
#3 lore raw
In reply to Vitaly Chikunov
Quoted 10 lines · Vitaly Chikunov

Clang 12.0.1 cannot understand that value 64 is excluded from the shift at compile time (for use in global context) resulting in build error[1]:

drivers/hv/vmbus_drv.c:2082:29: error: shift count >= width of type [-Werror,-Wshift-count-overflow]

  static u64 vmbus_dma_mask = DMA_BIT_MASK(64);
			      ^~~~~~~~~~~~~~~~
  ./include/linux/dma-mapping.h:76:54: note: expanded from macro 'DMA_BIT_MASK'
  #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
						       ^ ~~~
Quoted 7 lines

Avoid using DMA_BIT_MASK macro for that corner case.

BTW there is no need to put in a Link tag here. The tool I use (b4) handles this automatically.

Wei.