From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 376B3C433F5 for ; Sun, 6 Feb 2022 01:08:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381496AbiBFBIL (ORCPT ); Sat, 5 Feb 2022 20:08:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345823AbiBFBIL (ORCPT ); Sat, 5 Feb 2022 20:08:11 -0500 X-Greylist: delayed 348 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Sat, 05 Feb 2022 17:08:09 PST Received: from vmicros1.altlinux.org (vmicros1.altlinux.org [194.107.17.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B65DDC061348 for ; Sat, 5 Feb 2022 17:08:09 -0800 (PST) Received: from imap.altlinux.org (imap.altlinux.org [194.107.17.38]) by vmicros1.altlinux.org (Postfix) with ESMTP id F250E72C905; Sun, 6 Feb 2022 04:02:19 +0300 (MSK) Received: from altlinux.org (sole.flsd.net [185.75.180.6]) by imap.altlinux.org (Postfix) with ESMTPSA id CADA34A46F0; Sun, 6 Feb 2022 04:02:19 +0300 (MSK) Date: Sun, 6 Feb 2022 04:02:19 +0300 From: Vitaly Chikunov To: "Michael Kelley (LINUX)" Cc: "linux-hyperv@vger.kernel.org" , KY Srinivasan , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui , Jakub Kicinski , Tianyu Lan , Long Li Subject: Re: [PATCH v3] drivers: hv: vmbus: Fix build on Clang 12 failed by DMA_BIT_MASK(64) expansion Message-ID: <20220206010219.ol6wy7svem644l4g@altlinux.org> References: <20220204130503.76738-1-vt@altlinux.org> <20220205040552.fnshfhin3fij67t6@altlinux.org> MIME-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-hyperv@vger.kernel.org Michael, On Sat, Feb 05, 2022 at 02:41:31PM +0000, Michael Kelley (LINUX) wrote: > From: Vitaly Chikunov Sent: Friday, February 4, 2022 8:06 PM > > > > On Fri, Feb 04, 2022 at 04:10:49PM +0000, Michael Kelley (LINUX) wrote: > > > From: Vitaly Chikunov Sent: Friday, February 4, 2022 5:05 AM > > > > > > > > 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: > > > > > > > > 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. > > > > > > > > Cc: Tianyu Lan > > > > Cc: Michael Kelley > > > > Cc: Long Li > > > > Cc: Wei Liu > > > > Signed-off-by: Vitaly Chikunov > > > > --- > > > > drivers/hv/vmbus_drv.c | 3 ++- > > > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > > > > > diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c > > > > index 17bf55fe3169..a1306ca15d3f 100644 > > > > --- a/drivers/hv/vmbus_drv.c > > > > +++ b/drivers/hv/vmbus_drv.c > > > > @@ -2079,7 +2079,8 @@ struct hv_device *vmbus_device_create(const guid_t *type, > > > > return child_device_obj; > > > > } > > > > > > > > -static u64 vmbus_dma_mask = DMA_BIT_MASK(64); > > > > +/* Use ~0ULL instead of DMA_BIT_MASK(64) to work around a bug in Clang. */ > > > > +static u64 vmbus_dma_mask = ~0ULL; > > > > /* > > > > * vmbus_device_register - Register the child device > > > > */ > > > > -- > > > > 2.33.0 > > > > > > Instead of the hack approach, does the following code rearrangement solve > > > the problem by eliminating the use of DMA_BIT_MASK(64) in a static initializer? > > > I don't have Clang handy to try it. > > > > Yes this compiles well on Clang. > > > > Vitaly, > > > > Do you want to submit a patch with my approach, or should I do it? I'm > happy to do it, but I don't want to pre-empt what you have already > started without your OK. I'm OK if you send it! Thanks, > > Michael > > > > > > > This approach also more closely follows the pattern used in other device types. > > > > > > Michael > > > > > > > > > diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c > > > index 17bf55f..0d96634 100644 > > > --- a/drivers/hv/vmbus_drv.c > > > +++ b/drivers/hv/vmbus_drv.c > > > @@ -2079,7 +2079,6 @@ struct hv_device *vmbus_device_create(const guid_t > > *type, > > > return child_device_obj; > > > } > > > > > > -static u64 vmbus_dma_mask = DMA_BIT_MASK(64); > > > /* > > > * vmbus_device_register - Register the child device > > > */ > > > @@ -2120,8 +2119,9 @@ int vmbus_device_register(struct hv_device > > *child_device_obj) > > > } > > > hv_debug_add_dev_dir(child_device_obj); > > > > > > - child_device_obj->device.dma_mask = &vmbus_dma_mask; > > > child_device_obj->device.dma_parms = &child_device_obj->dma_parms; > > > + child_device_obj->device.dma_mask = &child_device_obj->dma_mask; > > > + dma_set_mask(&child_device_obj->device, DMA_BIT_MASK(64)); > > > return 0; > > > > > > err_kset_unregister: > > > diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h > > > index f565a89..fe2e017 100644 > > > --- a/include/linux/hyperv.h > > > +++ b/include/linux/hyperv.h > > > @@ -1262,6 +1262,7 @@ struct hv_device { > > > struct vmbus_channel *channel; > > > struct kset *channels_kset; > > > struct device_dma_parameters dma_parms; > > > + u64 dma_mask; > > > > > > /* place holder to keep track of the dir for hv device in debugfs */ > > > struct dentry *debug_dir;