net/netfilter/nft_set_pipapo_avx2.c
Source file repositories/reference/linux-study-clean/net/netfilter/nft_set_pipapo_avx2.c
File Facts
- System
- Linux kernel
- Corpus path
net/netfilter/nft_set_pipapo_avx2.c- Extension
.c- Size
- 42269 bytes
- Lines
- 1282
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: implementation source
- Status
- source implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/init.hlinux/module.hlinux/netlink.hlinux/netfilter.hlinux/netfilter/nf_tables.hnet/netfilter/nf_tables_core.huapi/linux/netfilter/nf_tables.hlinux/bitmap.hlinux/bitops.hlinux/compiler.hasm/fpu/api.hnft_set_pipapo_avx2.hnft_set_pipapo.h
Detected Declarations
function volatilefunction nft_pipapo_avx2_fillfunction nft_pipapo_avx2_refillfunction nft_pipapo_avx2_lookup_4b_2function nft_pipapo_avx2_lookup_4b_4function nft_pipapo_avx2_lookup_4b_8function nft_pipapo_avx2_lookup_4b_12function nft_pipapo_avx2_lookup_4b_32function nft_pipapo_avx2_lookup_8b_1function nft_pipapo_avx2_lookup_8b_2function nft_pipapo_avx2_lookup_8b_4function nft_pipapo_avx2_lookup_8b_6function nft_pipapo_avx2_lookup_8b_16function nft_pipapo_avx2_lookup_slowfunction nft_pipapo_avx2_estimatefunction pipapo_resmap_init_avx2function pipapo_get_avx2function nft_pipapo_for_each_fieldfunction nft_pipapo_avx2_lookup
Annotated Snippet
if (likely(len + offset <= BITS_PER_LONG)) {
*data |= GENMASK(len - 1 + offset, offset);
return;
}
*data |= ~0UL << offset;
len -= BITS_PER_LONG - offset;
data++;
if (len <= BITS_PER_LONG) {
mask = ~0UL >> (BITS_PER_LONG - len);
*data |= mask;
return;
}
}
memset(data, 0xff, len / BITS_PER_BYTE);
data += len / BITS_PER_LONG;
len %= BITS_PER_LONG;
if (len)
*data |= ~0UL >> (BITS_PER_LONG - len);
}
/**
* nft_pipapo_avx2_refill() - Scan bitmap, select mapping table item, set bits
* @offset: Start from given bitmap (equivalent to bucket) offset, in longs
* @map: Bitmap to be scanned for set bits
* @dst: Destination bitmap
* @mt: Mapping table containing bit set specifiers
* @last: Return index of first set bit, if this is the last field
*
* This is an alternative implementation of pipapo_refill() suitable for usage
* with AVX2 lookup routines: we know there are four words to be scanned, at
* a given offset inside the map, for each matching iteration.
* The caller must ensure at least one bit in the four words is set.
*
* This function doesn't actually use any AVX2 instruction.
*
* Return: first set bit index if @last, index of first filled word otherwise.
*/
static int nft_pipapo_avx2_refill(int offset, unsigned long *map,
unsigned long *dst,
union nft_pipapo_map_bucket *mt, bool last)
{
int ret = -1;
#define NFT_PIPAPO_AVX2_REFILL_ONE_WORD(x) \
do { \
while (map[(x)]) { \
int r = __builtin_ctzl(map[(x)]); \
int i = (offset + (x)) * BITS_PER_LONG + r; \
\
if (last) \
return i; \
\
nft_pipapo_avx2_fill(dst, mt[i].to, mt[i].n); \
\
if (ret == -1) \
ret = mt[i].to; \
\
map[(x)] &= ~(1UL << r); \
} \
} while (0)
NFT_PIPAPO_AVX2_REFILL_ONE_WORD(0);
NFT_PIPAPO_AVX2_REFILL_ONE_WORD(1);
NFT_PIPAPO_AVX2_REFILL_ONE_WORD(2);
NFT_PIPAPO_AVX2_REFILL_ONE_WORD(3);
#undef NFT_PIPAPO_AVX2_REFILL_ONE_WORD
DEBUG_NET_WARN_ON_ONCE(ret < 0);
return ret;
}
/**
* nft_pipapo_avx2_lookup_4b_2() - AVX2-based lookup for 2 four-bit groups
* @map: Previous match result, used as initial bitmap
* @fill: Destination bitmap to be filled with current match result
* @f: Field, containing lookup and mapping tables
* @offset: Ignore buckets before the given index, no bits are filled there
* @pkt: Packet data, pointer to input nftables register
* @first: If this is the first field, don't source previous result
* @last: Last field: stop at the first match and return bit index
*
* Load buckets from lookup table corresponding to the values of each 4-bit
* group of packet bytes, and perform a bitwise intersection between them. If
* this is the first field in the set, simply AND the buckets together
* (equivalent to using an all-ones starting bitmap), use the provided starting
* bitmap otherwise. Then call nft_pipapo_avx2_refill() to generate the next
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/init.h`, `linux/module.h`, `linux/netlink.h`, `linux/netfilter.h`, `linux/netfilter/nf_tables.h`, `net/netfilter/nf_tables_core.h`, `uapi/linux/netfilter/nf_tables.h`.
- Detected declarations: `function volatile`, `function nft_pipapo_avx2_fill`, `function nft_pipapo_avx2_refill`, `function nft_pipapo_avx2_lookup_4b_2`, `function nft_pipapo_avx2_lookup_4b_4`, `function nft_pipapo_avx2_lookup_4b_8`, `function nft_pipapo_avx2_lookup_4b_12`, `function nft_pipapo_avx2_lookup_4b_32`, `function nft_pipapo_avx2_lookup_8b_1`, `function nft_pipapo_avx2_lookup_8b_2`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.