* @data:      Key data to be matched against existing elements
  * @genmask:   If set, check that element is active in given genmask
  * @tstamp:    timestamp to check for expired elements
+ * @gfp:       the type of memory to allocate (see kmalloc).
  *
  * This is essentially the same as the lookup function, except that it matches
  * key data against the uncommitted copy and doesn't use preallocated maps for
 static struct nft_pipapo_elem *pipapo_get(const struct net *net,
                                          const struct nft_set *set,
                                          const u8 *data, u8 genmask,
-                                         u64 tstamp)
+                                         u64 tstamp, gfp_t gfp)
 {
        struct nft_pipapo_elem *ret = ERR_PTR(-ENOENT);
        struct nft_pipapo *priv = nft_set_priv(set);
        if (m->bsize_max == 0)
                return ret;
 
-       res_map = kmalloc_array(m->bsize_max, sizeof(*res_map), GFP_ATOMIC);
+       res_map = kmalloc_array(m->bsize_max, sizeof(*res_map), gfp);
        if (!res_map) {
                ret = ERR_PTR(-ENOMEM);
                goto out;
        }
 
-       fill_map = kcalloc(m->bsize_max, sizeof(*res_map), GFP_ATOMIC);
+       fill_map = kcalloc(m->bsize_max, sizeof(*res_map), gfp);
        if (!fill_map) {
                ret = ERR_PTR(-ENOMEM);
                goto out;
        struct nft_pipapo_elem *e;
 
        e = pipapo_get(net, set, (const u8 *)elem->key.val.data,
-                      nft_genmask_cur(net), get_jiffies_64());
+                      nft_genmask_cur(net), get_jiffies_64(),
+                      GFP_ATOMIC);
        if (IS_ERR(e))
                return ERR_CAST(e);
 
        else
                end = start;
 
-       dup = pipapo_get(net, set, start, genmask, tstamp);
+       dup = pipapo_get(net, set, start, genmask, tstamp, GFP_KERNEL);
        if (!IS_ERR(dup)) {
                /* Check if we already have the same exact entry */
                const struct nft_data *dup_key, *dup_end;
 
        if (PTR_ERR(dup) == -ENOENT) {
                /* Look for partially overlapping entries */
-               dup = pipapo_get(net, set, end, nft_genmask_next(net), tstamp);
+               dup = pipapo_get(net, set, end, nft_genmask_next(net), tstamp,
+                                GFP_KERNEL);
        }
 
        if (PTR_ERR(dup) != -ENOENT) {
 {
        struct nft_pipapo_elem *e;
 
-       e = pipapo_get(net, set, data, nft_genmask_next(net), nft_net_tstamp(net));
+       e = pipapo_get(net, set, data, nft_genmask_next(net),
+                      nft_net_tstamp(net), GFP_KERNEL);
        if (IS_ERR(e))
                return NULL;