if (!budget)
budget = BUSY_POLL_BUDGET;
- if (napi_id >= MIN_NAPI_ID && ep_busy_loop_on(ep)) {
+ if (napi_id_valid(napi_id) && ep_busy_loop_on(ep)) {
- napi_busy_loop(napi_id, nonblock ? NULL : ep_busy_loop_end,
+ napi_busy_loop(napi_id, ep_busy_loop_end,
ep, prefer_busy_poll, budget);
if (ep_events_available(ep))
return true;
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for tests of kernel library functions.
+
+# KUnit tests
+CFLAGS_bitfield_kunit.o := $(DISABLE_STRUCTLEAK_PLUGIN)
+obj-$(CONFIG_BITFIELD_KUNIT) += bitfield_kunit.o
+obj-$(CONFIG_BITS_TEST) += test_bits.o
++obj-$(CONFIG_BLACKHOLE_DEV_KUNIT_TEST) += blackhole_dev_kunit.o
+obj-$(CONFIG_CHECKSUM_KUNIT) += checksum_kunit.o
+obj-$(CONFIG_CMDLINE_KUNIT_TEST) += cmdline_kunit.o
+obj-$(CONFIG_CPUMASK_KUNIT_TEST) += cpumask_kunit.o
+obj-$(CONFIG_CRC_KUNIT_TEST) += crc_kunit.o
+CFLAGS_fortify_kunit.o += $(call cc-disable-warning, unsequenced)
+CFLAGS_fortify_kunit.o += $(call cc-disable-warning, stringop-overread)
+CFLAGS_fortify_kunit.o += $(call cc-disable-warning, stringop-truncation)
+CFLAGS_fortify_kunit.o += $(DISABLE_STRUCTLEAK_PLUGIN)
+obj-$(CONFIG_FORTIFY_KUNIT_TEST) += fortify_kunit.o
+CFLAGS_test_fprobe.o += $(CC_FLAGS_FTRACE)
+obj-$(CONFIG_FPROBE_SANITY_TEST) += test_fprobe.o
+obj-$(CONFIG_HASHTABLE_KUNIT_TEST) += hashtable_test.o
+obj-$(CONFIG_HASH_KUNIT_TEST) += test_hash.o
+obj-$(CONFIG_TEST_IOV_ITER) += kunit_iov_iter.o
+obj-$(CONFIG_IS_SIGNED_TYPE_KUNIT_TEST) += is_signed_type_kunit.o
+obj-$(CONFIG_KPROBES_SANITY_TEST) += test_kprobes.o
+obj-$(CONFIG_LIST_KUNIT_TEST) += list-test.o
+obj-$(CONFIG_KFIFO_KUNIT_TEST) += kfifo_kunit.o
+obj-$(CONFIG_TEST_LIST_SORT) += test_list_sort.o
+obj-$(CONFIG_LINEAR_RANGES_TEST) += test_linear_ranges.o
+obj-$(CONFIG_MEMCPY_KUNIT_TEST) += memcpy_kunit.o
+CFLAGS_overflow_kunit.o = $(call cc-disable-warning, tautological-constant-out-of-range-compare)
+obj-$(CONFIG_OVERFLOW_KUNIT_TEST) += overflow_kunit.o
+obj-$(CONFIG_PRINTF_KUNIT_TEST) += printf_kunit.o
+obj-$(CONFIG_SCANF_KUNIT_TEST) += scanf_kunit.o
+obj-$(CONFIG_SIPHASH_KUNIT_TEST) += siphash_kunit.o
+obj-$(CONFIG_SLUB_KUNIT_TEST) += slub_kunit.o
+obj-$(CONFIG_TEST_SORT) += test_sort.o
+CFLAGS_stackinit_kunit.o += $(call cc-disable-warning, switch-unreachable)
+obj-$(CONFIG_STACKINIT_KUNIT_TEST) += stackinit_kunit.o
+obj-$(CONFIG_STRING_KUNIT_TEST) += string_kunit.o
+obj-$(CONFIG_STRING_HELPERS_KUNIT_TEST) += string_helpers_kunit.o
+obj-$(CONFIG_USERCOPY_KUNIT_TEST) += usercopy_kunit.o
+obj-$(CONFIG_UTIL_MACROS_KUNIT) += util_macros_kunit.o
+
obj-$(CONFIG_TEST_RUNTIME_MODULE) += module/
--- /dev/null
--- /dev/null
++// SPDX-License-Identifier: GPL-2.0
++/*
++ * This tests the blackhole_dev that is created during the
++ * net subsystem initialization. The test this module performs is
++ * by injecting an skb into the stack with skb->dev as the
++ * blackhole_dev and expects kernel to behave in a sane manner
++ * (in other words, *not crash*)!
++ *
++ * Copyright (c) 2018, Mahesh Bandewar <maheshb@google.com>
++ */
++
++#include <kunit/test.h>
++#include <linux/module.h>
++#include <linux/skbuff.h>
++#include <linux/netdevice.h>
++#include <linux/udp.h>
++#include <linux/ipv6.h>
++
++#include <net/dst.h>
++
++#define SKB_SIZE 256
++#define HEAD_SIZE (14+40+8) /* Ether + IPv6 + UDP */
++#define TAIL_SIZE 32 /* random tail-room */
++
++#define UDP_PORT 1234
++
++static void test_blackholedev(struct kunit *test)
++{
++ struct ipv6hdr *ip6h;
++ struct sk_buff *skb;
++ struct udphdr *uh;
++ int data_len;
++
++ skb = alloc_skb(SKB_SIZE, GFP_KERNEL);
++ KUNIT_ASSERT_NOT_NULL(test, skb);
++
++ /* Reserve head-room for the headers */
++ skb_reserve(skb, HEAD_SIZE);
++
++ /* Add data to the skb */
++ data_len = SKB_SIZE - (HEAD_SIZE + TAIL_SIZE);
++ memset(__skb_put(skb, data_len), 0xf, data_len);
++
++ /* Add protocol data */
++ /* (Transport) UDP */
++ uh = (struct udphdr *)skb_push(skb, sizeof(struct udphdr));
++ skb_set_transport_header(skb, 0);
++ uh->source = uh->dest = htons(UDP_PORT);
++ uh->len = htons(data_len);
++ uh->check = 0;
++ /* (Network) IPv6 */
++ ip6h = (struct ipv6hdr *)skb_push(skb, sizeof(struct ipv6hdr));
++ skb_set_network_header(skb, 0);
++ ip6h->hop_limit = 32;
++ ip6h->payload_len = htons(data_len + sizeof(struct udphdr));
++ ip6h->nexthdr = IPPROTO_UDP;
++ ip6h->saddr = in6addr_loopback;
++ ip6h->daddr = in6addr_loopback;
++ /* Ether */
++ skb_push(skb, sizeof(struct ethhdr));
++ skb_set_mac_header(skb, 0);
++
++ skb->protocol = htons(ETH_P_IPV6);
++ skb->pkt_type = PACKET_HOST;
++ skb->dev = blackhole_netdev;
++
++ /* Now attempt to send the packet */
++ KUNIT_EXPECT_EQ(test, dev_queue_xmit(skb), NET_XMIT_SUCCESS);
++}
++
++static struct kunit_case blackholedev_cases[] = {
++ KUNIT_CASE(test_blackholedev),
++ {},
++};
++
++static struct kunit_suite blackholedev_suite = {
++ .name = "blackholedev",
++ .test_cases = blackholedev_cases,
++};
++
++kunit_test_suite(blackholedev_suite);
++
++MODULE_AUTHOR("Mahesh Bandewar <maheshb@google.com>");
++MODULE_DESCRIPTION("module test of the blackhole_dev");
++MODULE_LICENSE("GPL");
INIT_LIST_HEAD(&napi->poll_list);
INIT_HLIST_NODE(&napi->napi_hash_node);
- hrtimer_init(&napi->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_PINNED);
- napi->timer.function = napi_watchdog;
+ hrtimer_setup(&napi->timer, napi_watchdog, CLOCK_MONOTONIC, HRTIMER_MODE_REL_PINNED);
- init_gro_hash(napi);
+ gro_init(&napi->gro);
napi->skb = NULL;
- INIT_LIST_HEAD(&napi->rx_list);
- napi->rx_count = 0;
napi->poll = poll;
if (weight > NAPI_POLL_WEIGHT)
netdev_err_once(dev, "%s() called with weight %d\n", __func__,