[PATCH] kernel/resource: Fix use of ternary condition in release_mem_region_adjustable

2020-09-22 Thread Nathan Chancellor
Clang warns:

kernel/resource.c:1281:53: warning: operator '?:' has lower precedence
than '|'; '|' will be evaluated first
[-Wbitwise-conditional-parentheses]
new_res = alloc_resource(GFP_KERNEL | alloc_nofail ? __GFP_NOFAIL : 0);
 ~ ^
kernel/resource.c:1281:53: note: place parentheses around the '|'
expression to silence this warning
new_res = alloc_resource(GFP_KERNEL | alloc_nofail ? __GFP_NOFAIL : 0);
 ~ ^
kernel/resource.c:1281:53: note: place parentheses around the '?:'
expression to evaluate it first
new_res = alloc_resource(GFP_KERNEL | alloc_nofail ? __GFP_NOFAIL : 0);
   ^
  (  )
1 warning generated.

Add the parentheses as it was clearly intended for the ternary condition
to be evaluated first.

Fixes: 5fd23bd0d739 ("kernel/resource: make release_mem_region_adjustable() 
never fail")
Link: https://github.com/ClangBuiltLinux/linux/issues/1159
Signed-off-by: Nathan Chancellor 
---

Presumably, this will be squashed but I included a fixes tag
nonetheless. Apologies if this has already been noticed and fixed
already, I did not find anything on LKML.

 kernel/resource.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/resource.c b/kernel/resource.c
index ca2a666e4317..3ae2f56cc79d 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -1278,7 +1278,7 @@ void release_mem_region_adjustable(resource_size_t start, 
resource_size_t size)
 * similarly).
 */
 retry:
-   new_res = alloc_resource(GFP_KERNEL | alloc_nofail ? __GFP_NOFAIL : 0);
+   new_res = alloc_resource(GFP_KERNEL | (alloc_nofail ? __GFP_NOFAIL : 
0));
 
p = >child;
write_lock(_lock);

base-commit: 40ee82f47bf297e31d0c47547cd8f24ede52415a
-- 
2.28.0

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


Re: [PATCH] vdpa/mlx5: Avoid warnings about shifts on 32-bit platforms

2020-08-21 Thread Nathan Chancellor
On Fri, Aug 21, 2020 at 04:13:19PM -0700, Randy Dunlap wrote:
> On 8/21/20 3:50 PM, Nathan Chancellor wrote:
> > Clang warns several times when building for 32-bit ARM along the lines
> > of:
> > 
> > drivers/vdpa/mlx5/net/mlx5_vnet.c:1462:31: warning: shift count >= width
> > of type [-Wshift-count-overflow]
> > ndev->mvdev.mlx_features |= BIT(VIRTIO_F_VERSION_1);
> > ^~~
> > 
> > This is related to the BIT macro, which uses an unsigned long literal,
> > which is 32-bit on ARM so having a shift equal to or larger than 32 will
> > cause this warning, such as the above, where VIRTIO_F_VERSION_1 is 32.
> > To avoid this, use BIT_ULL, which will be an unsigned long long. This
> > matches the size of the features field throughout this driver, which is
> > u64 so there should be no functional change.
> > 
> > Fixes: 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 
> > devices")
> > Link: https://github.com/ClangBuiltLinux/linux/issues/1140
> > Signed-off-by: Nathan Chancellor 
> 
> Reported-by: Randy Dunlap 
> on 2020-AUG-10 for i386:
> https://lore.kernel.org/linux-next/5a7a0e6d-842a-78f6-aeac-c5b4c27b7...@infradead.org/
> :(

Sorry, I saw this in my own build tests and was not aware of the
previous report since I have not really been paying attention to
the mailing lists as of late :(

Should I need to do a v2, I will be sure to include that tag; otherwise,
it would be great if it could be picked up along with the below.

> Acked-by: Randy Dunlap  # build-tested

Thank you for testing!

> Thanks.
> 
> > ---
> >  drivers/vdpa/mlx5/net/mlx5_vnet.c | 50 +++
> >  1 file changed, 25 insertions(+), 25 deletions(-)
> > 
> > diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c 
> > b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> > index 9df69d5efe8c..70676a6d1691 100644
> > --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> > +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> > @@ -16,19 +16,19 @@
> >  #define to_mvdev(__vdev) container_of((__vdev), struct mlx5_vdpa_dev, vdev)
> >  
> >  #define VALID_FEATURES_MASK
> > \
> > -   (BIT(VIRTIO_NET_F_CSUM) | BIT(VIRTIO_NET_F_GUEST_CSUM) |
> >\
> > -BIT(VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) | BIT(VIRTIO_NET_F_MTU) | 
> > BIT(VIRTIO_NET_F_MAC) |   \
> > -BIT(VIRTIO_NET_F_GUEST_TSO4) | BIT(VIRTIO_NET_F_GUEST_TSO6) |  
> >\
> > -BIT(VIRTIO_NET_F_GUEST_ECN) | BIT(VIRTIO_NET_F_GUEST_UFO) | 
> > BIT(VIRTIO_NET_F_HOST_TSO4) | \
> > -BIT(VIRTIO_NET_F_HOST_TSO6) | BIT(VIRTIO_NET_F_HOST_ECN) | 
> > BIT(VIRTIO_NET_F_HOST_UFO) |   \
> > -BIT(VIRTIO_NET_F_MRG_RXBUF) | BIT(VIRTIO_NET_F_STATUS) | 
> > BIT(VIRTIO_NET_F_CTRL_VQ) |  \
> > -BIT(VIRTIO_NET_F_CTRL_RX) | BIT(VIRTIO_NET_F_CTRL_VLAN) |  
> >\
> > -BIT(VIRTIO_NET_F_CTRL_RX_EXTRA) | BIT(VIRTIO_NET_F_GUEST_ANNOUNCE) |   
> >\
> > -BIT(VIRTIO_NET_F_MQ) | BIT(VIRTIO_NET_F_CTRL_MAC_ADDR) | 
> > BIT(VIRTIO_NET_F_HASH_REPORT) |  \
> > -BIT(VIRTIO_NET_F_RSS) | BIT(VIRTIO_NET_F_RSC_EXT) | 
> > BIT(VIRTIO_NET_F_STANDBY) |   \
> > -BIT(VIRTIO_NET_F_SPEED_DUPLEX) | BIT(VIRTIO_F_NOTIFY_ON_EMPTY) |   
> >\
> > -BIT(VIRTIO_F_ANY_LAYOUT) | BIT(VIRTIO_F_VERSION_1) | 
> > BIT(VIRTIO_F_ACCESS_PLATFORM) |  \
> > -BIT(VIRTIO_F_RING_PACKED) | BIT(VIRTIO_F_ORDER_PLATFORM) | 
> > BIT(VIRTIO_F_SR_IOV))
> > +   (BIT_ULL(VIRTIO_NET_F_CSUM) | BIT_ULL(VIRTIO_NET_F_GUEST_CSUM) |
> >\
> > +BIT_ULL(VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) | BIT_ULL(VIRTIO_NET_F_MTU) 
> > | BIT_ULL(VIRTIO_NET_F_MAC) |   \
> > +BIT_ULL(VIRTIO_NET_F_GUEST_TSO4) | BIT_ULL(VIRTIO_NET_F_GUEST_TSO6) |  
> >\
> > +BIT_ULL(VIRTIO_NET_F_GUEST_ECN) | BIT_ULL(VIRTIO_NET_F_GUEST_UFO) | 
> > BIT_ULL(VIRTIO_NET_F_HOST_TSO4) | \
> > +BIT_ULL(VIRTIO_NET_F_HOST_TSO6) | BIT_ULL(VIRTIO_NET_F_HOST_ECN) | 
> > BIT_ULL(VIRTIO_NET_F_HOST_UFO) |   \
> > +BIT_ULL(VIRTIO_NET_F_MRG_RXBUF) | BIT_ULL(VIRTIO_NET_F_STATUS) | 
> > BIT_ULL(VIRTIO_NET_F_CTRL_VQ) |  \
> > +BIT_ULL(VIRTIO_NET_F_CTRL_RX) | BIT_ULL(VIRTIO_NET_F_CTRL_VLAN) |  
> >\
> > +BIT_ULL(VIRTIO_NET_F_CTRL_RX_EXTRA) | 
> > BIT_ULL(VIRTIO_NET_F_GUEST_ANNOUNCE) |   

[PATCH] vdpa/mlx5: Avoid warnings about shifts on 32-bit platforms

2020-08-21 Thread Nathan Chancellor
Clang warns several times when building for 32-bit ARM along the lines
of:

drivers/vdpa/mlx5/net/mlx5_vnet.c:1462:31: warning: shift count >= width
of type [-Wshift-count-overflow]
ndev->mvdev.mlx_features |= BIT(VIRTIO_F_VERSION_1);
^~~

This is related to the BIT macro, which uses an unsigned long literal,
which is 32-bit on ARM so having a shift equal to or larger than 32 will
cause this warning, such as the above, where VIRTIO_F_VERSION_1 is 32.
To avoid this, use BIT_ULL, which will be an unsigned long long. This
matches the size of the features field throughout this driver, which is
u64 so there should be no functional change.

Fixes: 1a86b377aa21 ("vdpa/mlx5: Add VDPA driver for supported mlx5 devices")
Link: https://github.com/ClangBuiltLinux/linux/issues/1140
Signed-off-by: Nathan Chancellor 
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 50 +++
 1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c 
b/drivers/vdpa/mlx5/net/mlx5_vnet.c
index 9df69d5efe8c..70676a6d1691 100644
--- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
+++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
@@ -16,19 +16,19 @@
 #define to_mvdev(__vdev) container_of((__vdev), struct mlx5_vdpa_dev, vdev)
 
 #define VALID_FEATURES_MASK
\
-   (BIT(VIRTIO_NET_F_CSUM) | BIT(VIRTIO_NET_F_GUEST_CSUM) |
   \
-BIT(VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) | BIT(VIRTIO_NET_F_MTU) | 
BIT(VIRTIO_NET_F_MAC) |   \
-BIT(VIRTIO_NET_F_GUEST_TSO4) | BIT(VIRTIO_NET_F_GUEST_TSO6) |  
   \
-BIT(VIRTIO_NET_F_GUEST_ECN) | BIT(VIRTIO_NET_F_GUEST_UFO) | 
BIT(VIRTIO_NET_F_HOST_TSO4) | \
-BIT(VIRTIO_NET_F_HOST_TSO6) | BIT(VIRTIO_NET_F_HOST_ECN) | 
BIT(VIRTIO_NET_F_HOST_UFO) |   \
-BIT(VIRTIO_NET_F_MRG_RXBUF) | BIT(VIRTIO_NET_F_STATUS) | 
BIT(VIRTIO_NET_F_CTRL_VQ) |  \
-BIT(VIRTIO_NET_F_CTRL_RX) | BIT(VIRTIO_NET_F_CTRL_VLAN) |  
   \
-BIT(VIRTIO_NET_F_CTRL_RX_EXTRA) | BIT(VIRTIO_NET_F_GUEST_ANNOUNCE) |   
   \
-BIT(VIRTIO_NET_F_MQ) | BIT(VIRTIO_NET_F_CTRL_MAC_ADDR) | 
BIT(VIRTIO_NET_F_HASH_REPORT) |  \
-BIT(VIRTIO_NET_F_RSS) | BIT(VIRTIO_NET_F_RSC_EXT) | 
BIT(VIRTIO_NET_F_STANDBY) |   \
-BIT(VIRTIO_NET_F_SPEED_DUPLEX) | BIT(VIRTIO_F_NOTIFY_ON_EMPTY) |   
   \
-BIT(VIRTIO_F_ANY_LAYOUT) | BIT(VIRTIO_F_VERSION_1) | 
BIT(VIRTIO_F_ACCESS_PLATFORM) |  \
-BIT(VIRTIO_F_RING_PACKED) | BIT(VIRTIO_F_ORDER_PLATFORM) | 
BIT(VIRTIO_F_SR_IOV))
+   (BIT_ULL(VIRTIO_NET_F_CSUM) | BIT_ULL(VIRTIO_NET_F_GUEST_CSUM) |
   \
+BIT_ULL(VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) | BIT_ULL(VIRTIO_NET_F_MTU) 
| BIT_ULL(VIRTIO_NET_F_MAC) |   \
+BIT_ULL(VIRTIO_NET_F_GUEST_TSO4) | BIT_ULL(VIRTIO_NET_F_GUEST_TSO6) |  
   \
+BIT_ULL(VIRTIO_NET_F_GUEST_ECN) | BIT_ULL(VIRTIO_NET_F_GUEST_UFO) | 
BIT_ULL(VIRTIO_NET_F_HOST_TSO4) | \
+BIT_ULL(VIRTIO_NET_F_HOST_TSO6) | BIT_ULL(VIRTIO_NET_F_HOST_ECN) | 
BIT_ULL(VIRTIO_NET_F_HOST_UFO) |   \
+BIT_ULL(VIRTIO_NET_F_MRG_RXBUF) | BIT_ULL(VIRTIO_NET_F_STATUS) | 
BIT_ULL(VIRTIO_NET_F_CTRL_VQ) |  \
+BIT_ULL(VIRTIO_NET_F_CTRL_RX) | BIT_ULL(VIRTIO_NET_F_CTRL_VLAN) |  
   \
+BIT_ULL(VIRTIO_NET_F_CTRL_RX_EXTRA) | 
BIT_ULL(VIRTIO_NET_F_GUEST_ANNOUNCE) |  \
+BIT_ULL(VIRTIO_NET_F_MQ) | BIT_ULL(VIRTIO_NET_F_CTRL_MAC_ADDR) | 
BIT_ULL(VIRTIO_NET_F_HASH_REPORT) |  \
+BIT_ULL(VIRTIO_NET_F_RSS) | BIT_ULL(VIRTIO_NET_F_RSC_EXT) | 
BIT_ULL(VIRTIO_NET_F_STANDBY) |   \
+BIT_ULL(VIRTIO_NET_F_SPEED_DUPLEX) | BIT_ULL(VIRTIO_F_NOTIFY_ON_EMPTY) 
|  \
+BIT_ULL(VIRTIO_F_ANY_LAYOUT) | BIT_ULL(VIRTIO_F_VERSION_1) | 
BIT_ULL(VIRTIO_F_ACCESS_PLATFORM) |  \
+BIT_ULL(VIRTIO_F_RING_PACKED) | BIT_ULL(VIRTIO_F_ORDER_PLATFORM) | 
BIT_ULL(VIRTIO_F_SR_IOV))
 
 #define VALID_STATUS_MASK  
\
(VIRTIO_CONFIG_S_ACKNOWLEDGE | VIRTIO_CONFIG_S_DRIVER | 
VIRTIO_CONFIG_S_DRIVER_OK |\
@@ -149,7 +149,7 @@ static bool mlx5_vdpa_debug;
 
 #define MLX5_LOG_VIO_FLAG(_feature)
\
do {
   \
-   if (features & BIT(_feature))   
   \
+   if (features & BIT_ULL(_feature))   
   \
mlx5_vdpa_info(mvdev, "%s\n", #_feature);   
   

Re: [PATCH] virtio_balloon: Adjust label in virtballoon_probe

2020-02-15 Thread Nathan Chancellor
On Sun, Feb 16, 2020 at 08:36:45AM +0100, David Hildenbrand wrote:
> 
> 
> > Am 16.02.2020 um 01:41 schrieb Nathan Chancellor :
> > 
> > Clang warns when CONFIG_BALLOON_COMPACTION is unset:
> > 
> > ../drivers/virtio/virtio_balloon.c:963:1: warning: unused label
> > 'out_del_vqs' [-Wunused-label]
> > out_del_vqs:
> > ^~~~
> > 1 warning generated.
> > 
> 
> Thanks, there is already „ [PATCH] virtio_balloon: Fix unused label warning“ 
> from Boris on the list.
> 
> Cheers!
> 

Sorry for the noise, I thought I did a search for duplicate patches but
seems I missed it :/ I've commented on that patch.

Cheers,
Nathan
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Re: [PATCH] virtio_balloon: Fix unused label warning

2020-02-15 Thread Nathan Chancellor
On Mon, Feb 10, 2020 at 10:33:28AM +0100, Borislav Petkov wrote:
> From: Borislav Petkov 
> 
> Fix
> 
>   drivers/virtio/virtio_balloon.c: In function ‘virtballoon_probe’:
>   drivers/virtio/virtio_balloon.c:963:1: warning: label ‘out_del_vqs’ defined 
> but not used [-Wunused-label]
> 963 | out_del_vqs:
> | ^~
> 
> The CONFIG_BALLOON_COMPACTION ifdeffery should enclose it too.
> 
> Signed-off-by: Borislav Petkov 
> Cc: David Hildenbrand 
> ---
>  drivers/virtio/virtio_balloon.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
> index 7bfe365d9372..b6ed5f8bccb1 100644
> --- a/drivers/virtio/virtio_balloon.c
> +++ b/drivers/virtio/virtio_balloon.c
> @@ -959,9 +959,9 @@ static int virtballoon_probe(struct virtio_device *vdev)
>   iput(vb->vb_dev_info.inode);
>  out_kern_unmount:
>   kern_unmount(balloon_mnt);
> -#endif
>  out_del_vqs:
>   vdev->config->del_vqs(vdev);
> +#endif

I noticed the same issue and sent an almost identical patch [1] but I
kept the call to del_vqs outside of the CONFIG_BALLOON_COMPACTION guard
since it seems like that should still be called when that config is
unset, as that was the case before commit 1ad6f58ea936 ("virtio_balloon:
Fix memory leaks on errors in virtballoon_probe()"). Is this patch fully
correct? I am not a virtio expert at all, just noticing from a brief
reading of this function.

[1]: 
https://lore.kernel.org/lkml/20200216004039.23464-1-natechancel...@gmail.com/

Cheers,
Nathan

>  out_free_vb:
>   kfree(vb);
>  out:
> -- 
> 2.21.0
> 
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

[PATCH] virtio_balloon: Adjust label in virtballoon_probe

2020-02-15 Thread Nathan Chancellor
Clang warns when CONFIG_BALLOON_COMPACTION is unset:

../drivers/virtio/virtio_balloon.c:963:1: warning: unused label
'out_del_vqs' [-Wunused-label]
out_del_vqs:
^~~~
1 warning generated.

Move the label within the preprocessor block since it is only used when
CONFIG_BALLOON_COMPACTION is set.

Fixes: 1ad6f58ea936 ("virtio_balloon: Fix memory leaks on errors in 
virtballoon_probe()")
Link: https://github.com/ClangBuiltLinux/linux/issues/886
Signed-off-by: Nathan Chancellor 
---
 drivers/virtio/virtio_balloon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 7bfe365d9372..341458fd95ca 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -959,8 +959,8 @@ static int virtballoon_probe(struct virtio_device *vdev)
iput(vb->vb_dev_info.inode);
 out_kern_unmount:
kern_unmount(balloon_mnt);
-#endif
 out_del_vqs:
+#endif
vdev->config->del_vqs(vdev);
 out_free_vb:
kfree(vb);
-- 
2.25.0

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


Re: [PATCH net-next v9 1/3] netdev: pass the stuck queue to the timeout handler

2019-12-09 Thread Nathan Chancellor
Hi Michael,

On Mon, Dec 09, 2019 at 11:29:03AM -0500, Michael S. Tsirkin wrote:
> This allows incrementing the correct timeout statistic without any mess.
> Down the road, devices can learn to reset just the specific queue.
> 
> The patch was generated with the following script:
> 

> 
> where the list of files and functions is simply from:
> 
> git grep ndo_tx_timeout, with manual addition of headers
> in the rare cases where the function is from a header,
> then manually changing the few places which actually
> call ndo_tx_timeout.
> 
> Signed-off-by: Michael S. Tsirkin 
> Acked-by: Heiner Kallweit 
> Acked-by: Jakub Kicinski 
> Acked-by: Shannon Nelson 
> Reviewed-by: Martin Habets 
> 
> changes from v8:
>   fix up a missing direct call to timeout
>   rebased on net-next
> changes from v7:
>   fixup leftovers from v3 change
> changes from v6:
>   fix typo in rtl driver
> changes from v5:
>   add missing files (allow any net device argument name)
> changes from v4:
>   add a missing driver header
> changes from v3:
> change queue # to unsigned
> Changes from v2:
> added headers
> Changes from v1:
> Fix errors found by kbuild:
> generalize the pattern a bit, to pick up
> a couple of instances missed by the previous
> version.
> ---

> diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c 
> b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
> index 6a9d12dad5d9..ad0ecebb1b34 100644
> --- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
> +++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
> @@ -288,7 +288,7 @@ static int dpaa_stop(struct net_device *net_dev)
>   return err;
>  }
>  
> -static void dpaa_tx_timeout(struct net_device *net_dev)
> +static void dpaa_tx_timeout(struct net_device *net_dev, int txqueue)

This needs to be unsigned int, otherwise there is a build error:

../drivers/net/ethernet/freescale/dpaa/dpaa_eth.c:2622:20: error: incompatible 
pointer types initializing 'void (*)(struct net_device *, unsigned int)' with 
an expression of type 'void (struct net_device *, int)' 
[-Werror,-Wincompatible-pointer-types]
.ndo_tx_timeout = dpaa_tx_timeout,
  ^~~
1 error generated.

Cheers,
Nathan
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


Re: [PATCH] vhost: Don't use defined in VHOST_ARCH_CAN_ACCEL_UACCESS definition

2019-07-24 Thread Nathan Chancellor
On Thu, Jun 06, 2019 at 02:28:55PM -0400, Michael S. Tsirkin wrote:
> I'd prefer just changing the definition.
> ifdefs have a disadvantage that it's easy to get
> wrong code if you forget to include a header.
> 
> I queued the below - pls confirm it works for you.

Fine by me, I figured that might be preferred (since clang will warn if
VHOST_ARCH_CAN_ACCEL_UACCESS is not defined so you'd know if the header
was forgotten). Thank you for the fix :)

Reviewed-by: Nathan Chancellor 
Tested-by: Nathan Chancellor 

> 
> 
> diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h
> index c5d950cf7627..819296332913 100644
> --- a/drivers/vhost/vhost.h
> +++ b/drivers/vhost/vhost.h
> @@ -95,8 +95,11 @@ struct vhost_uaddr {
>   bool write;
>  };
>  
> -#define VHOST_ARCH_CAN_ACCEL_UACCESS defined(CONFIG_MMU_NOTIFIER) && \
> - ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE == 0
> +#if defined(CONFIG_MMU_NOTIFIER) && ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE == 0
> +#define VHOST_ARCH_CAN_ACCEL_UACCESS 1
> +#else
> +#define VHOST_ARCH_CAN_ACCEL_UACCESS 0
> +#endif
>  
>  /* The virtqueue structure describes a queue attached to a device. */
>  struct vhost_virtqueue {
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH] vhost: Don't use defined in VHOST_ARCH_CAN_ACCEL_UACCESS definition

2019-07-24 Thread Nathan Chancellor
Clang warns:

  drivers/vhost/vhost.c:2085:5: warning: macro expansion producing
  'defined' has undefined behavior [-Wexpansion-to-defined]
  #if VHOST_ARCH_CAN_ACCEL_UACCESS
  ^
  drivers/vhost/vhost.h:98:38: note: expanded from macro
  'VHOST_ARCH_CAN_ACCEL_UACCESS'
  #define VHOST_ARCH_CAN_ACCEL_UACCESS defined(CONFIG_MMU_NOTIFIER) && \
   ^

Rework VHOST_ARCH_CAN_ACCEL_UACCESS to be defined under those conditions
so that the meaning of the code doesn't change and clang no longer
warns.

Fixes: 7f466032dc9e ("vhost: access vq metadata through kernel virtual address")
Link: https://github.com/ClangBuiltLinux/linux/issues/508
Signed-off-by: Nathan Chancellor 
---
 drivers/vhost/vhost.c | 44 +--
 drivers/vhost/vhost.h |  7 ---
 2 files changed, 26 insertions(+), 25 deletions(-)

diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index dc9301d31f12..cc56d08b4275 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -299,7 +299,7 @@ static void vhost_vq_meta_reset(struct vhost_dev *d)
__vhost_vq_meta_reset(d->vqs[i]);
 }
 
-#if VHOST_ARCH_CAN_ACCEL_UACCESS
+#ifdef VHOST_ARCH_CAN_ACCEL_UACCESS
 static void vhost_map_unprefetch(struct vhost_map *map)
 {
kfree(map->pages);
@@ -483,7 +483,7 @@ static void vhost_vq_reset(struct vhost_dev *dev,
vq->iotlb = NULL;
vq->invalidate_count = 0;
__vhost_vq_meta_reset(vq);
-#if VHOST_ARCH_CAN_ACCEL_UACCESS
+#ifdef VHOST_ARCH_CAN_ACCEL_UACCESS
vhost_reset_vq_maps(vq);
 #endif
 }
@@ -635,7 +635,7 @@ void vhost_dev_init(struct vhost_dev *dev,
INIT_LIST_HEAD(>read_list);
INIT_LIST_HEAD(>pending_list);
spin_lock_init(>iotlb_lock);
-#if VHOST_ARCH_CAN_ACCEL_UACCESS
+#ifdef VHOST_ARCH_CAN_ACCEL_UACCESS
vhost_init_maps(dev);
 #endif
 
@@ -726,7 +726,7 @@ long vhost_dev_set_owner(struct vhost_dev *dev)
if (err)
goto err_cgroup;
 
-#if VHOST_ARCH_CAN_ACCEL_UACCESS
+#ifdef VHOST_ARCH_CAN_ACCEL_UACCESS
err = mmu_notifier_register(>mmu_notifier, dev->mm);
if (err)
goto err_mmu_notifier;
@@ -734,7 +734,7 @@ long vhost_dev_set_owner(struct vhost_dev *dev)
 
return 0;
 
-#if VHOST_ARCH_CAN_ACCEL_UACCESS
+#ifdef VHOST_ARCH_CAN_ACCEL_UACCESS
 err_mmu_notifier:
vhost_dev_free_iovecs(dev);
 #endif
@@ -828,7 +828,7 @@ static void vhost_clear_msg(struct vhost_dev *dev)
spin_unlock(>iotlb_lock);
 }
 
-#if VHOST_ARCH_CAN_ACCEL_UACCESS
+#ifdef VHOST_ARCH_CAN_ACCEL_UACCESS
 static void vhost_setup_uaddr(struct vhost_virtqueue *vq,
  int index, unsigned long uaddr,
  size_t size, bool write)
@@ -959,12 +959,12 @@ void vhost_dev_cleanup(struct vhost_dev *dev)
dev->worker = NULL;
}
if (dev->mm) {
-#if VHOST_ARCH_CAN_ACCEL_UACCESS
+#ifdef VHOST_ARCH_CAN_ACCEL_UACCESS
mmu_notifier_unregister(>mmu_notifier, dev->mm);
 #endif
mmput(dev->mm);
}
-#if VHOST_ARCH_CAN_ACCEL_UACCESS
+#ifdef VHOST_ARCH_CAN_ACCEL_UACCESS
for (i = 0; i < dev->nvqs; i++)
vhost_uninit_vq_maps(dev->vqs[i]);
 #endif
@@ -1196,7 +1196,7 @@ static inline void __user *__vhost_get_user(struct 
vhost_virtqueue *vq,
 
 static inline int vhost_put_avail_event(struct vhost_virtqueue *vq)
 {
-#if VHOST_ARCH_CAN_ACCEL_UACCESS
+#ifdef VHOST_ARCH_CAN_ACCEL_UACCESS
struct vhost_map *map;
struct vring_used *used;
 
@@ -1224,7 +1224,7 @@ static inline int vhost_put_used(struct vhost_virtqueue 
*vq,
 struct vring_used_elem *head, int idx,
 int count)
 {
-#if VHOST_ARCH_CAN_ACCEL_UACCESS
+#ifdef VHOST_ARCH_CAN_ACCEL_UACCESS
struct vhost_map *map;
struct vring_used *used;
size_t size;
@@ -1252,7 +1252,7 @@ static inline int vhost_put_used(struct vhost_virtqueue 
*vq,
 static inline int vhost_put_used_flags(struct vhost_virtqueue *vq)
 
 {
-#if VHOST_ARCH_CAN_ACCEL_UACCESS
+#ifdef VHOST_ARCH_CAN_ACCEL_UACCESS
struct vhost_map *map;
struct vring_used *used;
 
@@ -1278,7 +1278,7 @@ static inline int vhost_put_used_flags(struct 
vhost_virtqueue *vq)
 static inline int vhost_put_used_idx(struct vhost_virtqueue *vq)
 
 {
-#if VHOST_ARCH_CAN_ACCEL_UACCESS
+#ifdef VHOST_ARCH_CAN_ACCEL_UACCESS
struct vhost_map *map;
struct vring_used *used;
 
@@ -1342,7 +1342,7 @@ static void vhost_dev_unlock_vqs(struct vhost_dev *d)
 static inline int vhost_get_avail_idx(struct vhost_virtqueue *vq,
  __virtio16 *idx)
 {
-#if VHOST_ARCH_CAN_ACCEL_UACCESS
+#ifdef VHOST_ARCH_CAN_ACCEL_UACCESS
struct vhost_map *map;
struct vring_avail *avail;
 
@@ -1367,7 +1367,7 @@ static inline int vhost_get_avail_idx(str