History

netfilter: nf_tables: remove busy mark and gc batch API

Ditch it, it has been replace it by the GC transaction API and it has no clients anymore.

Pablo Neira Ayuso committed 3 years ago

Commit a2dd0231 parent c92db302 files · +4 −142Browse files

Unified · Split

2 files
  1. include/net/netfilter/nf_tables.h +3 −95
  2. net/netfilter/nf_tables_api.c +1 −47
include/net/netfilter/nf_tables.h+3−95
@@ -599,7 +599,6 @@ struct nft_set *nft_set_lookup_global(const struct net *net, · 598 unmodified lines
599 599
600struct nft_set_ext *nft_set_catchall_lookup(const struct net *net,600struct nft_set_ext *nft_set_catchall_lookup(const struct net *net,
601 const struct nft_set *set);601 const struct nft_set *set);
602void *nft_set_catchall_gc(const struct nft_set *set);
603 602
604static inline unsigned long nft_set_gc_interval(const struct nft_set *set)603static inline unsigned long nft_set_gc_interval(const struct nft_set *set)
605{604{
@@ -816,62 +815,6 @@ void nft_set_elem_destroy(const struct nft_set *set, void *elem, · 210 unmodified lines
816void nf_tables_set_elem_destroy(const struct nft_ctx *ctx,815void nf_tables_set_elem_destroy(const struct nft_ctx *ctx,
817 const struct nft_set *set, void *elem);816 const struct nft_set *set, void *elem);
818 817
819/**
820 * struct nft_set_gc_batch_head - nf_tables set garbage collection batch
821 *
822 * @rcu: rcu head
823 * @set: set the elements belong to
824 * @cnt: count of elements
825 */
826struct nft_set_gc_batch_head {
827 struct rcu_head rcu;
828 const struct nft_set *set;
829 unsigned int cnt;
830};
831
832#define NFT_SET_GC_BATCH_SIZE ((PAGE_SIZE - \
833 sizeof(struct nft_set_gc_batch_head)) / \
834 sizeof(void *))
835
836/**
837 * struct nft_set_gc_batch - nf_tables set garbage collection batch
838 *
839 * @head: GC batch head
840 * @elems: garbage collection elements
841 */
842struct nft_set_gc_batch {
843 struct nft_set_gc_batch_head head;
844 void *elems[NFT_SET_GC_BATCH_SIZE];
845};
846
847struct nft_set_gc_batch *nft_set_gc_batch_alloc(const struct nft_set *set,
848 gfp_t gfp);
849void nft_set_gc_batch_release(struct rcu_head *rcu);
850
851static inline void nft_set_gc_batch_complete(struct nft_set_gc_batch *gcb)
852{
853 if (gcb != NULL)
854 call_rcu(&gcb->head.rcu, nft_set_gc_batch_release);
855}
856
857static inline struct nft_set_gc_batch *
858nft_set_gc_batch_check(const struct nft_set *set, struct nft_set_gc_batch *gcb,
859 gfp_t gfp)
860{
861 if (gcb != NULL) {
862 if (gcb->head.cnt + 1 < ARRAY_SIZE(gcb->elems))
863 return gcb;
864 nft_set_gc_batch_complete(gcb);
865 }
866 return nft_set_gc_batch_alloc(set, gfp);
867}
868
869static inline void nft_set_gc_batch_add(struct nft_set_gc_batch *gcb,
870 void *elem)
871{
872 gcb->elems[gcb->head.cnt++] = elem;
873}
874
875struct nft_expr_ops;818struct nft_expr_ops;
876/**819/**
877 * struct nft_expr_type - nf_tables expression type820 * struct nft_expr_type - nf_tables expression type
@@ -1560,47 +1503,12 @@ static inline void nft_set_elem_change_active(const struct net *net, · 682 unmodified lines
1560 1503
1561#endif /* IS_ENABLED(CONFIG_NF_TABLES) */1504#endif /* IS_ENABLED(CONFIG_NF_TABLES) */
1562 1505
1563/*1506#define NFT_SET_ELEM_DEAD_MASK (1 << 2)
1564 * We use a free bit in the genmask field to indicate the element
1565 * is busy, meaning it is currently being processed either by
1566 * the netlink API or GC.
1567 *
1568 * Even though the genmask is only a single byte wide, this works
1569 * because the extension structure if fully constant once initialized,
1570 * so there are no non-atomic write accesses unless it is already
1571 * marked busy.
1572 */
1573#define NFT_SET_ELEM_BUSY_MASK (1 << 2)
1574
1575#if defined(__LITTLE_ENDIAN_BITFIELD)
1576#define NFT_SET_ELEM_BUSY_BIT 2
1577#elif defined(__BIG_ENDIAN_BITFIELD)
1578#define NFT_SET_ELEM_BUSY_BIT (BITS_PER_LONG - BITS_PER_BYTE + 2)
1579#else
1580#error
1581#endif
1582
1583static inline int nft_set_elem_mark_busy(struct nft_set_ext *ext)
1584{
1585 unsigned long *word = (unsigned long *)ext;
1586
1587 BUILD_BUG_ON(offsetof(struct nft_set_ext, genmask) != 0);
1588 return test_and_set_bit(NFT_SET_ELEM_BUSY_BIT, word);
1589}
1590
1591static inline void nft_set_elem_clear_busy(struct nft_set_ext *ext)
1592{
1593 unsigned long *word = (unsigned long *)ext;
1594
1595 clear_bit(NFT_SET_ELEM_BUSY_BIT, word);
1596}
1597
1598#define NFT_SET_ELEM_DEAD_MASK (1 << 3)
1599 1507
1600#if defined(__LITTLE_ENDIAN_BITFIELD)1508#if defined(__LITTLE_ENDIAN_BITFIELD)
1601#define NFT_SET_ELEM_DEAD_BIT 31509#define NFT_SET_ELEM_DEAD_BIT 2
1602#elif defined(__BIG_ENDIAN_BITFIELD)1510#elif defined(__BIG_ENDIAN_BITFIELD)
1603#define NFT_SET_ELEM_DEAD_BIT (BITS_PER_LONG - BITS_PER_BYTE + 3)1511#define NFT_SET_ELEM_DEAD_BIT (BITS_PER_LONG - BITS_PER_BYTE + 2)
1604#else1512#else
1605#error1513#error
1606#endif1514#endif
net/netfilter/nf_tables_api.c+1−47
@@ -6296,29 +6296,6 @@ struct nft_set_ext *nft_set_catchall_lookup(const struct net *net, · 6295 unmodified lines
6296}6296}
6297EXPORT_SYMBOL_GPL(nft_set_catchall_lookup);6297EXPORT_SYMBOL_GPL(nft_set_catchall_lookup);
6298 6298
6299void *nft_set_catchall_gc(const struct nft_set *set)
6300{
6301 struct nft_set_elem_catchall *catchall, *next;
6302 struct nft_set_ext *ext;
6303 void *elem = NULL;
6304
6305 list_for_each_entry_safe(catchall, next, &set->catchall_list, list) {
6306 ext = nft_set_elem_ext(set, catchall->elem);
6307
6308 if (!nft_set_elem_expired(ext) ||
6309 nft_set_elem_mark_busy(ext))
6310 continue;
6311
6312 elem = catchall->elem;
6313 list_del_rcu(&catchall->list);
6314 kfree_rcu(catchall, rcu);
6315 break;
6316 }
6317
6318 return elem;
6319}
6320EXPORT_SYMBOL_GPL(nft_set_catchall_gc);
6321
6322static int nft_setelem_catchall_insert(const struct net *net,6299static int nft_setelem_catchall_insert(const struct net *net,
6323 struct nft_set *set,6300 struct nft_set *set,
6324 const struct nft_set_elem *elem,6301 const struct nft_set_elem *elem,
@@ -6789,7 +6766,7 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set, · 464 unmodified lines
6789 goto err_elem_free;6766 goto err_elem_free;
6790 }6767 }
6791 6768
6792 ext->genmask = nft_genmask_cur(ctx->net) | NFT_SET_ELEM_BUSY_MASK;6769 ext->genmask = nft_genmask_cur(ctx->net);
6793 6770
6794 err = nft_setelem_insert(ctx->net, set, &elem, &ext2, flags);6771 err = nft_setelem_insert(ctx->net, set, &elem, &ext2, flags);
6795 if (err) {6772 if (err) {
@@ -7181,29 +7158,6 @@ static int nf_tables_delsetelem(struct sk_buff *skb, · 385 unmodified lines
7181 return err;7158 return err;
7182}7159}
7183 7160
7184void nft_set_gc_batch_release(struct rcu_head *rcu)
7185{
7186 struct nft_set_gc_batch *gcb;
7187 unsigned int i;
7188
7189 gcb = container_of(rcu, struct nft_set_gc_batch, head.rcu);
7190 for (i = 0; i < gcb->head.cnt; i++)
7191 nft_set_elem_destroy(gcb->head.set, gcb->elems[i], true);
7192 kfree(gcb);
7193}
7194
7195struct nft_set_gc_batch *nft_set_gc_batch_alloc(const struct nft_set *set,
7196 gfp_t gfp)
7197{
7198 struct nft_set_gc_batch *gcb;
7199
7200 gcb = kzalloc(sizeof(*gcb), gfp);
7201 if (gcb == NULL)
7202 return gcb;
7203 gcb->head.set = set;
7204 return gcb;
7205}
7206
7207/*7161/*
7208 * Stateful objects7162 * Stateful objects
7209 */7163 */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t