From 2039635543fb2f8a270d506df88327e4c9e02e7b Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Sun, 23 Apr 2023 08:16:42 +0000 Subject: [PATCH] Revert "raw: use net_hash_mix() in hash function" This reverts commit 53a0031217c9b8d7a53edfb70d1633a1935c4395. It breaks the current Android kernel abi. It will be brought back at the next KABI break update. Bug: 161946584 Change-Id: I7fd2655234ff38dfe11a528e71c7772458a36328 Signed-off-by: Greg Kroah-Hartman --- include/net/raw.h | 13 ++----------- net/ipv4/raw.c | 13 ++++++------- net/ipv6/raw.c | 4 ++-- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/include/net/raw.h b/include/net/raw.h index 2c004c20ed99..5e665934ebc7 100644 --- a/include/net/raw.h +++ b/include/net/raw.h @@ -15,8 +15,6 @@ #include #include -#include -#include #include extern struct proto raw_prot; @@ -31,20 +29,13 @@ int raw_local_deliver(struct sk_buff *, int); int raw_rcv(struct sock *, struct sk_buff *); -#define RAW_HTABLE_LOG 8 -#define RAW_HTABLE_SIZE (1U << RAW_HTABLE_LOG) +#define RAW_HTABLE_SIZE MAX_INET_PROTOS struct raw_hashinfo { spinlock_t lock; - - struct hlist_nulls_head ht[RAW_HTABLE_SIZE] ____cacheline_aligned; + struct hlist_nulls_head ht[RAW_HTABLE_SIZE]; }; -static inline u32 raw_hashfunc(const struct net *net, u32 proto) -{ - return hash_32(net_hash_mix(net) ^ proto, RAW_HTABLE_LOG); -} - static inline void raw_hashinfo_init(struct raw_hashinfo *hashinfo) { int i; diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c index 2a53a0bf2923..006c1f0ed8b4 100644 --- a/net/ipv4/raw.c +++ b/net/ipv4/raw.c @@ -93,7 +93,7 @@ int raw_hash_sk(struct sock *sk) struct raw_hashinfo *h = sk->sk_prot->h.raw_hash; struct hlist_nulls_head *hlist; - hlist = &h->ht[raw_hashfunc(sock_net(sk), inet_sk(sk)->inet_num)]; + hlist = &h->ht[inet_sk(sk)->inet_num & (RAW_HTABLE_SIZE - 1)]; spin_lock(&h->lock); __sk_nulls_add_node_rcu(sk, hlist); @@ -160,9 +160,9 @@ static int icmp_filter(const struct sock *sk, const struct sk_buff *skb) * RFC 1122: SHOULD pass TOS value up to the transport layer. * -> It does. And not only TOS, but all IP header. */ -static int raw_v4_input(struct net *net, struct sk_buff *skb, - const struct iphdr *iph, int hash) +static int raw_v4_input(struct sk_buff *skb, const struct iphdr *iph, int hash) { + struct net *net = dev_net(skb->dev); struct hlist_nulls_head *hlist; struct hlist_nulls_node *hnode; int sdif = inet_sdif(skb); @@ -193,10 +193,9 @@ static int raw_v4_input(struct net *net, struct sk_buff *skb, int raw_local_deliver(struct sk_buff *skb, int protocol) { - struct net *net = dev_net(skb->dev); + int hash = protocol & (RAW_HTABLE_SIZE - 1); - return raw_v4_input(net, skb, ip_hdr(skb), - raw_hashfunc(net, protocol)); + return raw_v4_input(skb, ip_hdr(skb), hash); } static void raw_err(struct sock *sk, struct sk_buff *skb, u32 info) @@ -272,7 +271,7 @@ void raw_icmp_error(struct sk_buff *skb, int protocol, u32 info) struct sock *sk; int hash; - hash = raw_hashfunc(net, protocol); + hash = protocol & (RAW_HTABLE_SIZE - 1); hlist = &raw_v4_hashinfo.ht[hash]; rcu_read_lock(); diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c index 350fb81eda14..8ffeac745656 100644 --- a/net/ipv6/raw.c +++ b/net/ipv6/raw.c @@ -152,7 +152,7 @@ static bool ipv6_raw_deliver(struct sk_buff *skb, int nexthdr) saddr = &ipv6_hdr(skb)->saddr; daddr = saddr + 1; - hash = raw_hashfunc(net, nexthdr); + hash = nexthdr & (RAW_HTABLE_SIZE - 1); hlist = &raw_v6_hashinfo.ht[hash]; rcu_read_lock(); sk_nulls_for_each(sk, hnode, hlist) { @@ -338,7 +338,7 @@ void raw6_icmp_error(struct sk_buff *skb, int nexthdr, struct sock *sk; int hash; - hash = raw_hashfunc(net, nexthdr); + hash = nexthdr & (RAW_HTABLE_SIZE - 1); hlist = &raw_v6_hashinfo.ht[hash]; rcu_read_lock(); sk_nulls_for_each(sk, hnode, hlist) {