LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] xsk: Fix umem fill/completion queue mmap on 32-bit
@ 2018-06-07 13:37 Geert Uytterhoeven
  2018-06-07 16:34 ` Björn Töpel
  0 siblings, 1 reply; 3+ messages in thread
From: Geert Uytterhoeven @ 2018-06-07 13:37 UTC (permalink / raw)
  To: David S . Miller, Björn Töpel, Magnus Karlsson,
	Alexei Starovoitov
  Cc: Arnd Bergmann, Andrew Morton, netdev, linux-mm, linux-kernel,
	Geert Uytterhoeven

With gcc-4.1.2 on 32-bit:

    net/xdp/xsk.c:663: warning: integer constant is too large for ‘long’ type
    net/xdp/xsk.c:665: warning: integer constant is too large for ‘long’ type

Add the missing "ULL" suffixes to the large XDP_UMEM_PGOFF_*_RING values
to fix this.

    net/xdp/xsk.c:663: warning: comparison is always false due to limited range of data type
    net/xdp/xsk.c:665: warning: comparison is always false due to limited range of data type

"unsigned long" is 32-bit on 32-bit systems, hence the offset is
truncated, and can never be equal to any of the XDP_UMEM_PGOFF_*_RING
values.  Use loff_t (and the required cast) to fix this.

Fixes: 423f38329d267969 ("xsk: add umem fill queue support and mmap")
Fixes: fe2308328cd2f26e ("xsk: add umem completion queue support and mmap")
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
Compile-tested only.
---
 include/uapi/linux/if_xdp.h | 4 ++--
 net/xdp/xsk.c               | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/uapi/linux/if_xdp.h b/include/uapi/linux/if_xdp.h
index 1fa0e977ea8d0224..caed8b1614ffc0aa 100644
--- a/include/uapi/linux/if_xdp.h
+++ b/include/uapi/linux/if_xdp.h
@@ -63,8 +63,8 @@ struct xdp_statistics {
 /* Pgoff for mmaping the rings */
 #define XDP_PGOFF_RX_RING			  0
 #define XDP_PGOFF_TX_RING		 0x80000000
-#define XDP_UMEM_PGOFF_FILL_RING	0x100000000
-#define XDP_UMEM_PGOFF_COMPLETION_RING	0x180000000
+#define XDP_UMEM_PGOFF_FILL_RING	0x100000000ULL
+#define XDP_UMEM_PGOFF_COMPLETION_RING	0x180000000ULL
 
 /* Rx/Tx descriptor */
 struct xdp_desc {
diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
index c6ed2454f7ce55e8..36919a254ba370c3 100644
--- a/net/xdp/xsk.c
+++ b/net/xdp/xsk.c
@@ -643,7 +643,7 @@ static int xsk_getsockopt(struct socket *sock, int level, int optname,
 static int xsk_mmap(struct file *file, struct socket *sock,
 		    struct vm_area_struct *vma)
 {
-	unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
+	loff_t offset = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
 	unsigned long size = vma->vm_end - vma->vm_start;
 	struct xdp_sock *xs = xdp_sk(sock->sk);
 	struct xsk_queue *q = NULL;
-- 
2.7.4

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] xsk: Fix umem fill/completion queue mmap on 32-bit
  2018-06-07 13:37 [PATCH] xsk: Fix umem fill/completion queue mmap on 32-bit Geert Uytterhoeven
@ 2018-06-07 16:34 ` Björn Töpel
  2018-06-07 22:21   ` Daniel Borkmann
  0 siblings, 1 reply; 3+ messages in thread
From: Björn Töpel @ 2018-06-07 16:34 UTC (permalink / raw)
  To: geert
  Cc: David Miller, Björn Töpel, Karlsson, Magnus, ast,
	Arnd Bergmann, akpm, Netdev, linux-mm, LKML

Den tors 7 juni 2018 kl 15:37 skrev Geert Uytterhoeven <geert@linux-m68k.org>:
>
> With gcc-4.1.2 on 32-bit:
>
>     net/xdp/xsk.c:663: warning: integer constant is too large for ‘long’ type
>     net/xdp/xsk.c:665: warning: integer constant is too large for ‘long’ type
>
> Add the missing "ULL" suffixes to the large XDP_UMEM_PGOFF_*_RING values
> to fix this.
>
>     net/xdp/xsk.c:663: warning: comparison is always false due to limited range of data type
>     net/xdp/xsk.c:665: warning: comparison is always false due to limited range of data type
>
> "unsigned long" is 32-bit on 32-bit systems, hence the offset is
> truncated, and can never be equal to any of the XDP_UMEM_PGOFF_*_RING
> values.  Use loff_t (and the required cast) to fix this.
>
> Fixes: 423f38329d267969 ("xsk: add umem fill queue support and mmap")
> Fixes: fe2308328cd2f26e ("xsk: add umem completion queue support and mmap")
> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
> ---
> Compile-tested only.
> ---
>  include/uapi/linux/if_xdp.h | 4 ++--
>  net/xdp/xsk.c               | 2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/include/uapi/linux/if_xdp.h b/include/uapi/linux/if_xdp.h
> index 1fa0e977ea8d0224..caed8b1614ffc0aa 100644
> --- a/include/uapi/linux/if_xdp.h
> +++ b/include/uapi/linux/if_xdp.h
> @@ -63,8 +63,8 @@ struct xdp_statistics {
>  /* Pgoff for mmaping the rings */
>  #define XDP_PGOFF_RX_RING                        0
>  #define XDP_PGOFF_TX_RING               0x80000000
> -#define XDP_UMEM_PGOFF_FILL_RING       0x100000000
> -#define XDP_UMEM_PGOFF_COMPLETION_RING 0x180000000
> +#define XDP_UMEM_PGOFF_FILL_RING       0x100000000ULL
> +#define XDP_UMEM_PGOFF_COMPLETION_RING 0x180000000ULL
>
>  /* Rx/Tx descriptor */
>  struct xdp_desc {
> diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c
> index c6ed2454f7ce55e8..36919a254ba370c3 100644
> --- a/net/xdp/xsk.c
> +++ b/net/xdp/xsk.c
> @@ -643,7 +643,7 @@ static int xsk_getsockopt(struct socket *sock, int level, int optname,
>  static int xsk_mmap(struct file *file, struct socket *sock,
>                     struct vm_area_struct *vma)
>  {
> -       unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
> +       loff_t offset = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
>         unsigned long size = vma->vm_end - vma->vm_start;
>         struct xdp_sock *xs = xdp_sk(sock->sk);
>         struct xsk_queue *q = NULL;
> --
> 2.7.4
>

Thanks Geert!

Acked-by: Björn Töpel <bjorn.topel@intel.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] xsk: Fix umem fill/completion queue mmap on 32-bit
  2018-06-07 16:34 ` Björn Töpel
@ 2018-06-07 22:21   ` Daniel Borkmann
  0 siblings, 0 replies; 3+ messages in thread
From: Daniel Borkmann @ 2018-06-07 22:21 UTC (permalink / raw)
  To: Björn Töpel, geert
  Cc: David Miller, Björn Töpel, Karlsson, Magnus, ast,
	Arnd Bergmann, akpm, Netdev, linux-mm, LKML

On 06/07/2018 06:34 PM, Björn Töpel wrote:
> Den tors 7 juni 2018 kl 15:37 skrev Geert Uytterhoeven <geert@linux-m68k.org>:
>>
>> With gcc-4.1.2 on 32-bit:
>>
>>     net/xdp/xsk.c:663: warning: integer constant is too large for ‘long’ type
>>     net/xdp/xsk.c:665: warning: integer constant is too large for ‘long’ type
>>
>> Add the missing "ULL" suffixes to the large XDP_UMEM_PGOFF_*_RING values
>> to fix this.
>>
>>     net/xdp/xsk.c:663: warning: comparison is always false due to limited range of data type
>>     net/xdp/xsk.c:665: warning: comparison is always false due to limited range of data type
>>
>> "unsigned long" is 32-bit on 32-bit systems, hence the offset is
>> truncated, and can never be equal to any of the XDP_UMEM_PGOFF_*_RING
>> values.  Use loff_t (and the required cast) to fix this.
>>
>> Fixes: 423f38329d267969 ("xsk: add umem fill queue support and mmap")
>> Fixes: fe2308328cd2f26e ("xsk: add umem completion queue support and mmap")
>> Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
[...]
> 
> Thanks Geert!
> 
> Acked-by: Björn Töpel <bjorn.topel@intel.com>

Applied to bpf, thanks everyone!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-06-07 22:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-07 13:37 [PATCH] xsk: Fix umem fill/completion queue mmap on 32-bit Geert Uytterhoeven
2018-06-07 16:34 ` Björn Töpel
2018-06-07 22:21   ` Daniel Borkmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).