Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 19e94bbc authored by Subash Abhinov Kasiviswanathan's avatar Subash Abhinov Kasiviswanathan
Browse files

net: rmnet_data: Remove the NAPI context for rmnet_data devices



Commit 28207b51 ("net: rmnet_data: Add NAPI context for rmnet_data
devices") added a NAPI struct per rmnet_data device. This was to
ensure that the NAPI struct is always available even if there was a
hotplug. However, this seems to be leading to some races where the
NAPI struct is accessed concurrently across cores.

The race here is between napi_gro_receive on one core with
napi_complete running on the other accessing the same NAPI struct.
If napi_gro_receive runs slightly earlier, napi_complete would see
that the napi->gro_list would be non NULL in __napi_complete even
though it had cleared earlier and would lead to a BUG.
If napi_complete runs slightly earlier, napi_gro_receive would
dereference a NULL pointer even though it had assigned an skb to
napi->gro_list.

Fix this by using the per cpu backlog struct as the NAPI struct for
queuing packets to GRO engine. Access across cores would not be a
problem in case of hotplug as they would use core specific structures.

CRs-Fixed: 966095
Change-Id: I831df5b93cc6ee77355f2e98af89efcffe825bd8
Signed-off-by: default avatarSubash Abhinov Kasiviswanathan <subashab@codeaurora.org>
parent d1701bc2
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
/*
 * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
 * Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -250,14 +250,14 @@ static rx_handler_result_t __rmnet_deliver_skb(struct sk_buff *skb,
		case RX_HANDLER_PASS:
			skb->pkt_type = PACKET_HOST;
			rmnet_reset_mac_header(skb);

			if (rmnet_check_skb_can_gro(skb)) {
				if (skb->dev->features & NETIF_F_GRO) {
					napi = rmnet_vnd_get_napi(skb->dev);
					napi_schedule(napi);
			if (rmnet_check_skb_can_gro(skb) &&
			    (skb->dev->features & NETIF_F_GRO)) {
				napi = get_current_napi_context();
				if (napi != NULL) {
					gro_res = napi_gro_receive(napi, skb);
					trace_rmnet_gro_downlink(gro_res);
				} else {
					WARN_ONCE(1, "current napi is NULL\n");
					netif_receive_skb(skb);
				}
			} else {
+2 −40
Original line number Diff line number Diff line
/*
 * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
 * Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -19,7 +19,6 @@
#include <linux/rmnet_data.h>
#include <linux/msm_rmnet.h>
#include <linux/etherdevice.h>
#include <linux/netdevice.h>
#include <linux/if_arp.h>
#include <linux/spinlock.h>
#include <net/pkt_sched.h>
@@ -38,9 +37,6 @@ RMNET_LOG_MODULE(RMNET_DATA_LOGMASK_VND);
#define RMNET_MAP_FLOW_NUM_TC_HANDLE 3
#define RMNET_VND_UF_ACTION_ADD 0
#define RMNET_VND_UF_ACTION_DEL 1
#define RMNET_DATA_NAPI_WEIGHT 1
#define RMNET_DATA_NAPI_WORK 0

enum {
	RMNET_VND_UPDATE_FLOW_OK,
	RMNET_VND_UPDATE_FLOW_NO_ACTION,
@@ -62,7 +58,7 @@ struct rmnet_map_flow_mapping_s {
struct rmnet_vnd_private_s {
	uint32_t qos_version;
	struct rmnet_logical_ep_conf_s local_ep;
	struct napi_struct napi;

	rwlock_t flow_map_lock;
	struct list_head flow_head;
	struct rmnet_map_flow_mapping_s root_flow;
@@ -507,19 +503,6 @@ static void rmnet_vnd_setup(struct net_device *dev)
	INIT_LIST_HEAD(&dev_conf->flow_head);
}

/**
 * rmnet_data_napi_poll() - NAPI poll function
 * @napi:      NAPI struct
 *
 * Called by net_rx_action() when NAPI is scheduled. Since we have already
 * queued packets to network stack, we just flush and return here.
 */
static int rmnet_data_napi_poll(struct napi_struct *napi, int budget)
{
	napi_complete(napi);
	return RMNET_DATA_NAPI_WORK;
}

/* ***************** Exposed API ******************************************** */

/**
@@ -574,7 +557,6 @@ int rmnet_vnd_create_dev(int id, struct net_device **new_device,
	struct net_device *dev;
	char dev_prefix[IFNAMSIZ];
	int p, rc = 0;
	struct napi_struct *n;

	if (id < 0 || id >= RMNET_DATA_MAX_VND) {
		*new_device = 0;
@@ -634,10 +616,6 @@ int rmnet_vnd_create_dev(int id, struct net_device **new_device,
		*new_device = dev;
	}

	n = rmnet_vnd_get_napi(dev);
	netif_napi_add(dev, n, rmnet_data_napi_poll, RMNET_DATA_NAPI_WEIGHT);
	napi_enable(n);

	LOGM("Registered device %s", dev->name);
	return rc;
}
@@ -681,10 +659,6 @@ int rmnet_vnd_free_dev(int id)
	rtnl_unlock();

	if (dev) {
		struct napi_struct *n = rmnet_vnd_get_napi(dev);

		napi_disable(n);
		netif_napi_del(n);
		unregister_netdev(dev);
		free_netdev(dev);
		return 0;
@@ -1125,15 +1099,3 @@ struct net_device *rmnet_vnd_get_by_id(int id)
	}
	return rmnet_devices[id];
}

/**
 * rmnet_vnd_get_napi() - Get NAPI struct from the device
 * @dev: Virtual network device
 *
 * Return:
 *      - napi struct corresponding to the netdevice
 */
struct napi_struct *rmnet_vnd_get_napi(struct net_device *dev)
{
	return &(((struct rmnet_vnd_private_s *)netdev_priv(dev))->napi);
}
+1 −2
Original line number Diff line number Diff line
/*
 * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
 * Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -37,6 +37,5 @@ int rmnet_vnd_del_tc_flow(uint32_t id, uint32_t map_flow, uint32_t tc_flow);
int rmnet_vnd_init(void);
void rmnet_vnd_exit(void);
struct net_device *rmnet_vnd_get_by_id(int id);
struct napi_struct *rmnet_vnd_get_napi(struct net_device *dev);

#endif /* _RMNET_DATA_VND_H_ */