Netdev Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH 0/2] samples/bpf: xdpsock: Minor enhancements
@ 2021-08-06 12:28 Simon Horman
  2021-08-06 12:28 ` [PATCH 1/2] samples/bpf: xdpsock: Make the sample more useful outside the tree Simon Horman
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Simon Horman @ 2021-08-06 12:28 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
  Cc: netdev, bpf, oss-drivers, Niklas Söderlund, Louis Peens,
	Simon Horman

Hi,

this short series provides to minor enhancements to the
ample code in samples/bpf/xdpsock_user.c.

Each change is explained more fully in its own commit message.

Niklas Söderlund (2):
  samples/bpf: xdpsock: Make the sample more useful outside the tree
  samples/bpf: xdpsock: Remove forward declaration of ip_fast_csum()

 samples/bpf/xdpsock_user.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

-- 
2.20.1


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

* [PATCH 1/2] samples/bpf: xdpsock: Make the sample more useful outside the tree
  2021-08-06 12:28 [PATCH 0/2] samples/bpf: xdpsock: Minor enhancements Simon Horman
@ 2021-08-06 12:28 ` Simon Horman
  2021-08-06 12:28 ` [PATCH 2/2] samples/bpf: xdpsock: Remove forward declaration of ip_fast_csum() Simon Horman
  2021-08-07  0:00 ` [PATCH 0/2] samples/bpf: xdpsock: Minor enhancements patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Simon Horman @ 2021-08-06 12:28 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
  Cc: netdev, bpf, oss-drivers, Niklas Söderlund, Louis Peens,
	Simon Horman

From: Niklas Söderlund <niklas.soderlund@corigine.com>

The xdpsock sample application is a useful base for experiment's around
AF_XDP sockets. Compiling the sample outside of the kernel tree is made
harder then it has to be as the sample includes two headers and that are
not installed by 'make install_header' nor are usually part of
distributions kernel headers.

The first header asm/barrier.h is not used and can just be dropped.

The second linux/compiler.h are only needed for the decorator __force
and are only used in ip_fast_csum(), csum_fold() and
csum_tcpudp_nofold(). These functions are copied verbatim from
include/asm-generic/checksum.h and lib/checksum.c. While it's fine to
copy and use these functions in the sample application the decorator
brings no value and can be dropped together with the include.

With this change it's trivial to compile the xdpsock sample outside the
kernel tree from xdpsock_user.c and xdpsock.h.

    $ gcc -o xdpsock xdpsock_user.c -lbpf -lpthread

Signed-off-by: Niklas Söderlund <niklas.soderlund@corigine.com>
Reviewed-by: Louis Peens <louis.peens@corigine.com>
Signed-off-by: Simon Horman <simon.horman@corigine.com>
---
 samples/bpf/xdpsock_user.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/samples/bpf/xdpsock_user.c b/samples/bpf/xdpsock_user.c
index 33d0bdebbed8..7c56a7a784e1 100644
--- a/samples/bpf/xdpsock_user.c
+++ b/samples/bpf/xdpsock_user.c
@@ -1,12 +1,10 @@
 // SPDX-License-Identifier: GPL-2.0
 /* Copyright(c) 2017 - 2018 Intel Corporation. */
 
-#include <asm/barrier.h>
 #include <errno.h>
 #include <getopt.h>
 #include <libgen.h>
 #include <linux/bpf.h>
-#include <linux/compiler.h>
 #include <linux/if_link.h>
 #include <linux/if_xdp.h>
 #include <linux/if_ether.h>
@@ -663,7 +661,7 @@ __sum16 ip_fast_csum(const void *iph, unsigned int ihl);
  */
 __sum16 ip_fast_csum(const void *iph, unsigned int ihl)
 {
-	return (__force __sum16)~do_csum(iph, ihl * 4);
+	return (__sum16)~do_csum(iph, ihl * 4);
 }
 
 /*
@@ -673,11 +671,11 @@ __sum16 ip_fast_csum(const void *iph, unsigned int ihl)
  */
 static inline __sum16 csum_fold(__wsum csum)
 {
-	u32 sum = (__force u32)csum;
+	u32 sum = (u32)csum;
 
 	sum = (sum & 0xffff) + (sum >> 16);
 	sum = (sum & 0xffff) + (sum >> 16);
-	return (__force __sum16)~sum;
+	return (__sum16)~sum;
 }
 
 /*
@@ -703,16 +701,16 @@ __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
 __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
 			  __u32 len, __u8 proto, __wsum sum)
 {
-	unsigned long long s = (__force u32)sum;
+	unsigned long long s = (u32)sum;
 
-	s += (__force u32)saddr;
-	s += (__force u32)daddr;
+	s += (u32)saddr;
+	s += (u32)daddr;
 #ifdef __BIG_ENDIAN__
 	s += proto + len;
 #else
 	s += (proto + len) << 8;
 #endif
-	return (__force __wsum)from64to32(s);
+	return (__wsum)from64to32(s);
 }
 
 /*
-- 
2.20.1


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

* [PATCH 2/2] samples/bpf: xdpsock: Remove forward declaration of ip_fast_csum()
  2021-08-06 12:28 [PATCH 0/2] samples/bpf: xdpsock: Minor enhancements Simon Horman
  2021-08-06 12:28 ` [PATCH 1/2] samples/bpf: xdpsock: Make the sample more useful outside the tree Simon Horman
@ 2021-08-06 12:28 ` Simon Horman
  2021-08-07  0:00 ` [PATCH 0/2] samples/bpf: xdpsock: Minor enhancements patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Simon Horman @ 2021-08-06 12:28 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
  Cc: netdev, bpf, oss-drivers, Niklas Söderlund, Louis Peens,
	Simon Horman

From: Niklas Söderlund <niklas.soderlund@corigine.com>

There is a forward declaration of ip_fast_csum() just before its
implementation, remove the unneeded forward declaration.

While at it mark the implementation as static inline.

Signed-off-by: Niklas Söderlund <niklas.soderlund@corigine.com>
Reviewed-by: Louis Peens <louis.peens@corigine.com>
Signed-off-by: Simon Horman <simon.horman@corigine.com>
---
 samples/bpf/xdpsock_user.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/samples/bpf/xdpsock_user.c b/samples/bpf/xdpsock_user.c
index 7c56a7a784e1..49d7a6ad7e39 100644
--- a/samples/bpf/xdpsock_user.c
+++ b/samples/bpf/xdpsock_user.c
@@ -651,15 +651,13 @@ static unsigned int do_csum(const unsigned char *buff, int len)
 	return result;
 }
 
-__sum16 ip_fast_csum(const void *iph, unsigned int ihl);
-
 /*
  *	This is a version of ip_compute_csum() optimized for IP headers,
  *	which always checksum on 4 octet boundaries.
  *	This function code has been taken from
  *	Linux kernel lib/checksum.c
  */
-__sum16 ip_fast_csum(const void *iph, unsigned int ihl)
+static inline __sum16 ip_fast_csum(const void *iph, unsigned int ihl)
 {
 	return (__sum16)~do_csum(iph, ihl * 4);
 }
-- 
2.20.1


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

* Re: [PATCH 0/2] samples/bpf: xdpsock: Minor enhancements
  2021-08-06 12:28 [PATCH 0/2] samples/bpf: xdpsock: Minor enhancements Simon Horman
  2021-08-06 12:28 ` [PATCH 1/2] samples/bpf: xdpsock: Make the sample more useful outside the tree Simon Horman
  2021-08-06 12:28 ` [PATCH 2/2] samples/bpf: xdpsock: Remove forward declaration of ip_fast_csum() Simon Horman
@ 2021-08-07  0:00 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-08-07  0:00 UTC (permalink / raw)
  To: Simon Horman
  Cc: ast, daniel, andrii, netdev, bpf, oss-drivers, niklas.soderlund,
	louis.peens

Hello:

This series was applied to bpf/bpf-next.git (refs/heads/master):

On Fri,  6 Aug 2021 14:28:53 +0200 you wrote:
> Hi,
> 
> this short series provides to minor enhancements to the
> ample code in samples/bpf/xdpsock_user.c.
> 
> Each change is explained more fully in its own commit message.
> 
> [...]

Here is the summary with links:
  - [1/2] samples/bpf: xdpsock: Make the sample more useful outside the tree
    https://git.kernel.org/bpf/bpf-next/c/29f24c43cbe0
  - [2/2] samples/bpf: xdpsock: Remove forward declaration of ip_fast_csum()
    https://git.kernel.org/bpf/bpf-next/c/f4700a62c271

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2021-08-07  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-06 12:28 [PATCH 0/2] samples/bpf: xdpsock: Minor enhancements Simon Horman
2021-08-06 12:28 ` [PATCH 1/2] samples/bpf: xdpsock: Make the sample more useful outside the tree Simon Horman
2021-08-06 12:28 ` [PATCH 2/2] samples/bpf: xdpsock: Remove forward declaration of ip_fast_csum() Simon Horman
2021-08-07  0:00 ` [PATCH 0/2] samples/bpf: xdpsock: Minor enhancements patchwork-bot+netdevbpf

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).