diff mbox series

[RFC,bpf-next,23/52] net, skbuff: constify the @skb argument of skb_hwtstamps()

Message ID 20220628194812.1453059-24-alexandr.lobakin@intel.com (mailing list archive)
State RFC
Delegated to: BPF
Headers show
Series bpf, xdp: introduce and use Generic Hints/metadata | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR fail PR summary
bpf/vmtest-bpf-next-VM_Test-1 fail Logs for Kernel LATEST on ubuntu-latest with gcc
bpf/vmtest-bpf-next-VM_Test-2 fail Logs for Kernel LATEST on ubuntu-latest with llvm-15
bpf/vmtest-bpf-next-VM_Test-3 fail Logs for Kernel LATEST on z15 with gcc
netdev/tree_selection success Clearly marked for bpf-next, async
netdev/apply fail Patch does not apply to bpf-next

Commit Message

Alexander Lobakin June 28, 2022, 7:47 p.m. UTC
The @skb argument only dereferences the &skb_shared_info pointer,
so it doesn't need a writable pointer. Constify it to be able to
pass const pointers to the code which uses this function and give
the compilers a little more room for optimization.
As an example, constify the @skb argument of tpacket_get_timestamp()
and __packet_set_timestamp() of the AF_PACKET core code. There are
lot more places in the kernel where the similar micro-opts can be
done in the future.

Signed-off-by: Alexander Lobakin <alexandr.lobakin@intel.com>
---
 include/linux/skbuff.h | 3 ++-
 net/packet/af_packet.c | 8 ++++----
 2 files changed, 6 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 1c308511acbb..0a95f753c1d9 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -1617,7 +1617,8 @@  int skb_zerocopy_iter_stream(struct sock *sk, struct sk_buff *skb,
 /* Internal */
 #define skb_shinfo(SKB)	((struct skb_shared_info *)(skb_end_pointer(SKB)))
 
-static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
+static inline struct skb_shared_hwtstamps *
+skb_hwtstamps(const struct sk_buff *skb)
 {
 	return &skb_shinfo(skb)->hwtstamps;
 }
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index d08c4728523b..20eac049e69e 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -449,10 +449,10 @@  static int __packet_get_status(const struct packet_sock *po, void *frame)
 	}
 }
 
-static __u32 tpacket_get_timestamp(struct sk_buff *skb, struct timespec64 *ts,
-				   unsigned int flags)
+static __u32 tpacket_get_timestamp(const struct sk_buff *skb,
+				   struct timespec64 *ts, unsigned int flags)
 {
-	struct skb_shared_hwtstamps *shhwtstamps = skb_hwtstamps(skb);
+	const struct skb_shared_hwtstamps *shhwtstamps = skb_hwtstamps(skb);
 
 	if (shhwtstamps &&
 	    (flags & SOF_TIMESTAMPING_RAW_HARDWARE) &&
@@ -467,7 +467,7 @@  static __u32 tpacket_get_timestamp(struct sk_buff *skb, struct timespec64 *ts,
 }
 
 static __u32 __packet_set_timestamp(struct packet_sock *po, void *frame,
-				    struct sk_buff *skb)
+				    const struct sk_buff *skb)
 {
 	union tpacket_uhdr h;
 	struct timespec64 ts;