Skip to content

Commit d862a66

Browse files
committed
netfilter: nf_conntrack: use is_vmalloc_addr()
Use is_vmalloc_addr() in nf_ct_free_hashtable() and get rid of the vmalloc flags to indicate that a hash table has been allocated using vmalloc(). Signed-off-by: Patrick McHardy <kaber@trash.net>
1 parent 0134e89 commit d862a66

7 files changed

Lines changed: 19 additions & 39 deletions

File tree

‎include/net/netfilter/nf_conntrack.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ extern void nf_ct_l3proto_module_put(unsigned short l3proto);
202202
* Allocate a hashtable of hlist_head (if nulls == 0),
203203
* or hlist_nulls_head (if nulls == 1)
204204
*/
205-
extern void *nf_ct_alloc_hashtable(unsigned int *sizep, int *vmalloced, int nulls);
205+
extern void *nf_ct_alloc_hashtable(unsigned int *sizep, int nulls);
206206

207-
extern void nf_ct_free_hashtable(void *hash, int vmalloced, unsigned int size);
207+
extern void nf_ct_free_hashtable(void *hash, unsigned int size);
208208

209209
extern struct nf_conntrack_tuple_hash *
210210
__nf_conntrack_find(struct net *net, u16 zone,

‎include/net/netns/conntrack.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ struct netns_ct {
2828
struct ctl_table_header *acct_sysctl_header;
2929
struct ctl_table_header *event_sysctl_header;
3030
#endif
31-
int hash_vmalloc;
32-
int expect_vmalloc;
3331
char *slabname;
3432
};
3533
#endif

‎include/net/netns/ipv4.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ struct netns_ipv4 {
4343
struct xt_table *nat_table;
4444
struct hlist_head *nat_bysource;
4545
unsigned int nat_htable_size;
46-
int nat_vmalloced;
4746
#endif
4847

4948
int sysctl_icmp_echo_ignore_all;

‎net/ipv4/netfilter/nf_nat_core.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -682,8 +682,7 @@ static int __net_init nf_nat_net_init(struct net *net)
682682
{
683683
/* Leave them the same for the moment. */
684684
net->ipv4.nat_htable_size = net->ct.htable_size;
685-
net->ipv4.nat_bysource = nf_ct_alloc_hashtable(&net->ipv4.nat_htable_size,
686-
&net->ipv4.nat_vmalloced, 0);
685+
net->ipv4.nat_bysource = nf_ct_alloc_hashtable(&net->ipv4.nat_htable_size, 0);
687686
if (!net->ipv4.nat_bysource)
688687
return -ENOMEM;
689688
return 0;
@@ -705,8 +704,7 @@ static void __net_exit nf_nat_net_exit(struct net *net)
705704
{
706705
nf_ct_iterate_cleanup(net, &clean_nat, NULL);
707706
synchronize_rcu();
708-
nf_ct_free_hashtable(net->ipv4.nat_bysource, net->ipv4.nat_vmalloced,
709-
net->ipv4.nat_htable_size);
707+
nf_ct_free_hashtable(net->ipv4.nat_bysource, net->ipv4.nat_htable_size);
710708
}
711709

712710
static struct pernet_operations nf_nat_net_ops = {

‎net/netfilter/nf_conntrack_core.c‎

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,9 +1202,9 @@ static int kill_all(struct nf_conn *i, void *data)
12021202
return 1;
12031203
}
12041204

1205-
void nf_ct_free_hashtable(void *hash, int vmalloced, unsigned int size)
1205+
void nf_ct_free_hashtable(void *hash, unsigned int size)
12061206
{
1207-
if (vmalloced)
1207+
if (is_vmalloc_addr(hash))
12081208
vfree(hash);
12091209
else
12101210
free_pages((unsigned long)hash,
@@ -1271,8 +1271,7 @@ static void nf_conntrack_cleanup_net(struct net *net)
12711271
goto i_see_dead_people;
12721272
}
12731273

1274-
nf_ct_free_hashtable(net->ct.hash, net->ct.hash_vmalloc,
1275-
net->ct.htable_size);
1274+
nf_ct_free_hashtable(net->ct.hash, net->ct.htable_size);
12761275
nf_conntrack_ecache_fini(net);
12771276
nf_conntrack_acct_fini(net);
12781277
nf_conntrack_expect_fini(net);
@@ -1301,21 +1300,18 @@ void nf_conntrack_cleanup(struct net *net)
13011300
}
13021301
}
13031302

1304-
void *nf_ct_alloc_hashtable(unsigned int *sizep, int *vmalloced, int nulls)
1303+
void *nf_ct_alloc_hashtable(unsigned int *sizep, int nulls)
13051304
{
13061305
struct hlist_nulls_head *hash;
13071306
unsigned int nr_slots, i;
13081307
size_t sz;
13091308

1310-
*vmalloced = 0;
1311-
13121309
BUILD_BUG_ON(sizeof(struct hlist_nulls_head) != sizeof(struct hlist_head));
13131310
nr_slots = *sizep = roundup(*sizep, PAGE_SIZE / sizeof(struct hlist_nulls_head));
13141311
sz = nr_slots * sizeof(struct hlist_nulls_head);
13151312
hash = (void *)__get_free_pages(GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO,
13161313
get_order(sz));
13171314
if (!hash) {
1318-
*vmalloced = 1;
13191315
printk(KERN_WARNING "nf_conntrack: falling back to vmalloc.\n");
13201316
hash = __vmalloc(sz, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
13211317
PAGE_KERNEL);
@@ -1331,7 +1327,7 @@ EXPORT_SYMBOL_GPL(nf_ct_alloc_hashtable);
13311327

13321328
int nf_conntrack_set_hashsize(const char *val, struct kernel_param *kp)
13331329
{
1334-
int i, bucket, vmalloced, old_vmalloced;
1330+
int i, bucket;
13351331
unsigned int hashsize, old_size;
13361332
struct hlist_nulls_head *hash, *old_hash;
13371333
struct nf_conntrack_tuple_hash *h;
@@ -1348,7 +1344,7 @@ int nf_conntrack_set_hashsize(const char *val, struct kernel_param *kp)
13481344
if (!hashsize)
13491345
return -EINVAL;
13501346

1351-
hash = nf_ct_alloc_hashtable(&hashsize, &vmalloced, 1);
1347+
hash = nf_ct_alloc_hashtable(&hashsize, 1);
13521348
if (!hash)
13531349
return -ENOMEM;
13541350

@@ -1370,15 +1366,13 @@ int nf_conntrack_set_hashsize(const char *val, struct kernel_param *kp)
13701366
}
13711367
}
13721368
old_size = init_net.ct.htable_size;
1373-
old_vmalloced = init_net.ct.hash_vmalloc;
13741369
old_hash = init_net.ct.hash;
13751370

13761371
init_net.ct.htable_size = nf_conntrack_htable_size = hashsize;
1377-
init_net.ct.hash_vmalloc = vmalloced;
13781372
init_net.ct.hash = hash;
13791373
spin_unlock_bh(&nf_conntrack_lock);
13801374

1381-
nf_ct_free_hashtable(old_hash, old_vmalloced, old_size);
1375+
nf_ct_free_hashtable(old_hash, old_size);
13821376
return 0;
13831377
}
13841378
EXPORT_SYMBOL_GPL(nf_conntrack_set_hashsize);
@@ -1491,8 +1485,7 @@ static int nf_conntrack_init_net(struct net *net)
14911485
}
14921486

14931487
net->ct.htable_size = nf_conntrack_htable_size;
1494-
net->ct.hash = nf_ct_alloc_hashtable(&net->ct.htable_size,
1495-
&net->ct.hash_vmalloc, 1);
1488+
net->ct.hash = nf_ct_alloc_hashtable(&net->ct.htable_size, 1);
14961489
if (!net->ct.hash) {
14971490
ret = -ENOMEM;
14981491
printk(KERN_ERR "Unable to create nf_conntrack_hash\n");
@@ -1515,8 +1508,7 @@ static int nf_conntrack_init_net(struct net *net)
15151508
err_acct:
15161509
nf_conntrack_expect_fini(net);
15171510
err_expect:
1518-
nf_ct_free_hashtable(net->ct.hash, net->ct.hash_vmalloc,
1519-
net->ct.htable_size);
1511+
nf_ct_free_hashtable(net->ct.hash, net->ct.htable_size);
15201512
err_hash:
15211513
kmem_cache_destroy(net->ct.nf_conntrack_cachep);
15221514
err_cache:

‎net/netfilter/nf_conntrack_expect.c‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -639,8 +639,7 @@ int nf_conntrack_expect_init(struct net *net)
639639
}
640640

641641
net->ct.expect_count = 0;
642-
net->ct.expect_hash = nf_ct_alloc_hashtable(&nf_ct_expect_hsize,
643-
&net->ct.expect_vmalloc, 0);
642+
net->ct.expect_hash = nf_ct_alloc_hashtable(&nf_ct_expect_hsize, 0);
644643
if (net->ct.expect_hash == NULL)
645644
goto err1;
646645

@@ -662,8 +661,7 @@ int nf_conntrack_expect_init(struct net *net)
662661
if (net_eq(net, &init_net))
663662
kmem_cache_destroy(nf_ct_expect_cachep);
664663
err2:
665-
nf_ct_free_hashtable(net->ct.expect_hash, net->ct.expect_vmalloc,
666-
nf_ct_expect_hsize);
664+
nf_ct_free_hashtable(net->ct.expect_hash, nf_ct_expect_hsize);
667665
err1:
668666
return err;
669667
}
@@ -675,6 +673,5 @@ void nf_conntrack_expect_fini(struct net *net)
675673
rcu_barrier(); /* Wait for call_rcu() before destroy */
676674
kmem_cache_destroy(nf_ct_expect_cachep);
677675
}
678-
nf_ct_free_hashtable(net->ct.expect_hash, net->ct.expect_vmalloc,
679-
nf_ct_expect_hsize);
676+
nf_ct_free_hashtable(net->ct.expect_hash, nf_ct_expect_hsize);
680677
}

‎net/netfilter/nf_conntrack_helper.c‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ static DEFINE_MUTEX(nf_ct_helper_mutex);
3333
static struct hlist_head *nf_ct_helper_hash __read_mostly;
3434
static unsigned int nf_ct_helper_hsize __read_mostly;
3535
static unsigned int nf_ct_helper_count __read_mostly;
36-
static int nf_ct_helper_vmalloc;
3736

3837

3938
/* Stupid hash, but collision free for the default registrations of the
@@ -267,8 +266,7 @@ int nf_conntrack_helper_init(void)
267266
int err;
268267

269268
nf_ct_helper_hsize = 1; /* gets rounded up to use one page */
270-
nf_ct_helper_hash = nf_ct_alloc_hashtable(&nf_ct_helper_hsize,
271-
&nf_ct_helper_vmalloc, 0);
269+
nf_ct_helper_hash = nf_ct_alloc_hashtable(&nf_ct_helper_hsize, 0);
272270
if (!nf_ct_helper_hash)
273271
return -ENOMEM;
274272

@@ -279,14 +277,12 @@ int nf_conntrack_helper_init(void)
279277
return 0;
280278

281279
err1:
282-
nf_ct_free_hashtable(nf_ct_helper_hash, nf_ct_helper_vmalloc,
283-
nf_ct_helper_hsize);
280+
nf_ct_free_hashtable(nf_ct_helper_hash, nf_ct_helper_hsize);
284281
return err;
285282
}
286283

287284
void nf_conntrack_helper_fini(void)
288285
{
289286
nf_ct_extend_unregister(&helper_extend);
290-
nf_ct_free_hashtable(nf_ct_helper_hash, nf_ct_helper_vmalloc,
291-
nf_ct_helper_hsize);
287+
nf_ct_free_hashtable(nf_ct_helper_hash, nf_ct_helper_hsize);
292288
}

0 commit comments

Comments
 (0)