Skip to contentSkip to conversation

Add support for rmnet driver

PATCH Superseded Subash Abhinov Kasiviswanathan 3 participants 9 messages Aug 21, 2017 – Aug 24, 2017

Subsystems (4)

v7 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

v7 cover Add support for rmnet driver

This patch adds support for the rmnet driver which is required to support recent chipsets using Qualcomm Technologies, Inc. modems. The data from hardware follows the multiplexing and aggregation protocol (MAP).

This driver can be used to register onto any physical network device in IP mode. Physical transports include USB, HSIC, PCIe and IP accelerator.

rmnet driver helps to decode these packets and queue them to network stack (and encode and transmit it to the physical device).

--
v1: Same as the RFC patch with some minor fixes for issues reported by kbuild test robot.

v1->v2: Change datatypes and remove config IOCTL as mentioned by David. Also fix checkpatch issues and remove some unused code.

v2->v3: Move location to drivers/net and rename to rmnet. Change the userspace - netlink communication from custom netlink to rtnl_link_ops. Refactor some code. Use a fixed config for ingress and egress.

v3->v4: Move location to drivers/net/ethernet/qualcomm/. Fix comments from Stephen and Jiri -
Split the ether and arp type changes into seperate patches. Remove debug and custom logging and switch to standard netdevice log. Remove module parameters. Refactor and change some code style issues.

v4->v5: Rename some structs and variables. Move the initializer before the for loop start. Put the arp type in correct sequence.

v5->v6: Fix comments from Dan -
Use the upper link API. As a result, remove all the refcounting logic. Device refcount is explicitly held on real_dev on rx_handler registration only. Modifiy the flow control struct. Remove the unused ethernet mode handling.

v6->v7: Fix comments from David - Add newline to end of Makefile. Remove inline from .c files. Move the module init/exit to rmnet config. Fix an error reported by kbuild test robot for an unused file.

Subash Abhinov Kasiviswanathan (3):
net: ether: Add support for multiplexing and aggregation type
net: arp: Add support for raw IP device
drivers: net: ethernet: qualcomm: rmnet: Initial implementation

 Documentation/networking/rmnet.txt                 |  82 ++++
 drivers/net/ethernet/qualcomm/Kconfig              |   2 +
 drivers/net/ethernet/qualcomm/Makefile             |   2 +
 drivers/net/ethernet/qualcomm/rmnet/Kconfig        |  12 +
 drivers/net/ethernet/qualcomm/rmnet/Makefile       |  12 +
 drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c | 418 +++++++++++++++++++++
 drivers/net/ethernet/qualcomm/rmnet/rmnet_config.h |  54 +++
 .../net/ethernet/qualcomm/rmnet/rmnet_handlers.c   | 276 ++++++++++++++
 .../net/ethernet/qualcomm/rmnet/rmnet_handlers.h   |  26 ++
 drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h    |  88 +++++
 .../ethernet/qualcomm/rmnet/rmnet_map_command.c    | 116 ++++++
 .../net/ethernet/qualcomm/rmnet/rmnet_map_data.c   | 105 ++++++
 .../net/ethernet/qualcomm/rmnet/rmnet_private.h    |  45 +++
 drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c    | 263 +++++++++++++
 drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.h    |  32 ++
 include/uapi/linux/if_arp.h                        |   1 +
 include/uapi/linux/if_ether.h                      |   4 +-
 17 files changed, 1537 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/networking/rmnet.txt
 create mode 100644 drivers/net/ethernet/qualcomm/rmnet/Kconfig
 create mode 100644 drivers/net/ethernet/qualcomm/rmnet/Makefile
 create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c
 create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_config.h
 create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c
 create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.h
 create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h
 create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c
 create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
 create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_private.h
 create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c
 create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.h
Signature · 1 line
1.9.1
#1 lore raw

PATCH v7 1/3 net: ether: Add support for multiplexing and aggregation type

Define the multiplexing and aggregation (MAP) ether type 0xDA1A. This is needed for receiving data in the MAP protocol like RMNET. This is not an officially registered ID.

---
 include/uapi/linux/if_ether.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
include/uapi/linux/if_ether.h +3 -1
index 5bc9bfd..e80b03f 100644
@@ -104,7 +104,9 @@
 #define ETH_P_QINQ3	0x9300		/* deprecated QinQ VLAN [ NOT AN OFFICIALLY REGISTERED ID ] */
 #define ETH_P_EDSA	0xDADA		/* Ethertype DSA [ NOT AN OFFICIALLY REGISTERED ID ] */
 #define ETH_P_AF_IUCV   0xFBFB		/* IBM af_iucv [ NOT AN OFFICIALLY REGISTERED ID ] */
-
+#define ETH_P_MAP       0xDA1A          /* Multiplexing and Aggregation Protocol
+					 *  NOT AN OFFICIALLY REGISTERED ID ]
+					 */
 #define ETH_P_802_3_MIN	0x0600		/* If the value in the ethernet type is less than this value
 					 * then the frame is Ethernet II. Else it is 802.3 */
 
Signature · 1 line
1.9.1
#2 lore raw

Re: [PATCH net-next 1/3 v7] net: ether: Add support for multiplexing and aggregation type

Quoted 14 lines · Subash Abhinov Kasiviswanathan

Define the multiplexing and aggregation (MAP) ether type 0xDA1A. This is needed for receiving data in the MAP protocol like RMNET. This is not an officially registered ID.

---
 include/uapi/linux/if_ether.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
include/uapi/linux/if_ether.h +0 -0
index 5bc9bfd..e80b03f 100644

include/uapi/linux/if_ether.h line 109

Quoted 7 lines
include/uapi/linux/if_ether.h +3 -1
@@ -104,7 +104,9 @@
 #define ETH_P_QINQ3	0x9300		/* deprecated QinQ VLAN [ NOT AN OFFICIALLY REGISTERED ID ] */
 #define ETH_P_EDSA	0xDADA		/* Ethertype DSA [ NOT AN OFFICIALLY REGISTERED ID ] */
 #define ETH_P_AF_IUCV   0xFBFB		/* IBM af_iucv [ NOT AN OFFICIALLY REGISTERED ID ] */
-
+#define ETH_P_MAP       0xDA1A          /* Multiplexing and Aggregation Protocol
+					 *  NOT AN OFFICIALLY REGISTERED ID ]
+					 */

Hi Subash

This list is sorted. So this entry should go earlier.

Andrew

#3 lore raw

Re: [PATCH net-next 1/3 v7] net: ether: Add support for multiplexing and aggregation type

Quoted 7 lines

include/uapi/linux/if_ether.h line 109

Quoted 4 lines

+#define ETH_P_MAP 0xDA1A /* Multiplexing and
Aggregation Protocol

include/uapi/linux/if_ether.h +2 -0
+					 *  NOT AN OFFICIALLY REGISTERED ID ]
+					 */

Hi Subash

Quoted 7 lines

This list is sorted. So this entry should go earlier.

Review

Quoted 1 line
(quoted diff) +1 -0
+	netdev_info(real_dev, "Removed from rmnet\n");

I would probably turn all your netdev_info()s into netdev_dbg()s. You seem to be spamming the kernel log quite a bit.

Hi Andrew

I'll make these changes and post v8.

#4 lore raw

PATCH v7 2/3 net: arp: Add support for raw IP device

In reply to Subash Abhinov Kasiviswanathan

Define the raw IP type. This is needed for raw IP net devices like rmnet.

---
 include/uapi/linux/if_arp.h | 1 +
 1 file changed, 1 insertion(+)
include/uapi/linux/if_arp.h +1 -0
index cf73510..a2a6356 100644
@@ -59,6 +59,7 @@
 #define ARPHRD_LAPB	516		/* LAPB				*/
 #define ARPHRD_DDCMP    517		/* Digital's DDCMP protocol     */
 #define ARPHRD_RAWHDLC	518		/* Raw HDLC			*/
+#define ARPHRD_RAWIP    519		/* Raw IP                       */
 
 #define ARPHRD_TUNNEL	768		/* IPIP tunnel			*/
 #define ARPHRD_TUNNEL6	769		/* IP6IP6 tunnel       		*/
Signature · 1 line
1.9.1
#5 lore raw

PATCH v7 3/3 drivers: net: ethernet: qualcomm: rmnet: Initial implementation

In reply to Subash Abhinov Kasiviswanathan

RmNet driver provides a transport agnostic MAP (multiplexing and aggregation protocol) support in embedded module. Module provides virtual network devices which can be attached to any IP-mode physical device. This will be used to provide all MAP functionality on future hardware in a single consistent location.

---
 Documentation/networking/rmnet.txt                 |  82 ++++
 drivers/net/ethernet/qualcomm/Kconfig              |   2 +
 drivers/net/ethernet/qualcomm/Makefile             |   2 +
 drivers/net/ethernet/qualcomm/rmnet/Kconfig        |  12 +
 drivers/net/ethernet/qualcomm/rmnet/Makefile       |  12 +
 drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c | 418 +++++++++++++++++++++
 drivers/net/ethernet/qualcomm/rmnet/rmnet_config.h |  54 +++
 .../net/ethernet/qualcomm/rmnet/rmnet_handlers.c   | 276 ++++++++++++++
 .../net/ethernet/qualcomm/rmnet/rmnet_handlers.h   |  26 ++
 drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h    |  88 +++++
 .../ethernet/qualcomm/rmnet/rmnet_map_command.c    | 116 ++++++
 .../net/ethernet/qualcomm/rmnet/rmnet_map_data.c   | 105 ++++++
 .../net/ethernet/qualcomm/rmnet/rmnet_private.h    |  45 +++
 drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c    | 263 +++++++++++++
 drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.h    |  32 ++
 15 files changed, 1533 insertions(+)
 create mode 100644 Documentation/networking/rmnet.txt
 create mode 100644 drivers/net/ethernet/qualcomm/rmnet/Kconfig
 create mode 100644 drivers/net/ethernet/qualcomm/rmnet/Makefile
 create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c
 create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_config.h
 create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c
 create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.h
 create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h
 create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c
 create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c
 create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_private.h
 create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c
 create mode 100644 drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.h
Documentation/networking/rmnet.txt new file +82 -0
new file mode 100644
index 0000000..6b341ea
@@ -0,0 +1,82 @@
+1. Introduction
+
+rmnet driver is used for supporting the Multiplexing and aggregation
+Protocol (MAP). This protocol is used by all recent chipsets using Qualcomm
+Technologies, Inc. modems.
+
+This driver can be used to register onto any physical network device in
+IP mode. Physical transports include USB, HSIC, PCIe and IP accelerator.
+
+Multiplexing allows for creation of logical netdevices (rmnet devices) to
+handle multiple private data networks (PDN) like a default internet, tethering,
+multimedia messaging service (MMS) or IP media subsystem (IMS). Hardware sends
+packets with MAP headers to rmnet. Based on the multiplexer id, rmnet
+routes to the appropriate PDN after removing the MAP header.
+
+Aggregation is required to achieve high data rates. This involves hardware
+sending aggregated bunch of MAP frames. rmnet driver will de-aggregate
+these MAP frames and send them to appropriate PDN's.
+
+2. Packet format
+
+a. MAP packet (data / control)
+
+MAP header has the same endianness of the IP packet.
+
+Packet format -
+
+Bit             0             1           2-7      8 - 15           16 - 31
+Function   Command / Data   Reserved     Pad   Multiplexer ID    Payload length
+Bit            32 - x
+Function     Raw  Bytes
+
+Command (1)/ Data (0) bit value is to indicate if the packet is a MAP command
+or data packet. Control packet is used for transport level flow control. Data
+packets are standard IP packets.
+
+Reserved bits are usually zeroed out and to be ignored by receiver.
+
+Padding is number of bytes to be added for 4 byte alignment if required by
+hardware.
+
+Multiplexer ID is to indicate the PDN on which data has to be sent.
+
+Payload length includes the padding length but does not include MAP header
+length.
+
+b. MAP packet (command specific)
+
+Bit             0             1           2-7      8 - 15           16 - 31
+Function   Command         Reserved     Pad   Multiplexer ID    Payload length
+Bit          32 - 39        40 - 45    46 - 47       48 - 63
+Function   Command name    Reserved   Command Type   Reserved
+Bit          64 - 95
+Function   Transaction ID
+Bit          96 - 127
+Function   Command data
+
+Command 1 indicates disabling flow while 2 is enabling flow
+
+Command types -
+0 for MAP command request
+1 is to acknowledge the receipt of a command
+2 is for unsupported commands
+3 is for error during processing of commands
+
+c. Aggregation
+
+Aggregation is multiple MAP packets (can be data or command) delivered to
+rmnet in a single linear skb. rmnet will process the individual
+packets and either ACK the MAP command or deliver the IP packet to the
+network stack as needed
+
+MAP header|IP Packet|Optional padding|MAP header|IP Packet|Optional padding....
+MAP header|IP Packet|Optional padding|MAP header|Command Packet|Optional pad...
+
+3. Userspace configuration
+
+rmnet userspace configuration is done through netlink library librmnetctl
+and command line utility rmnetcli. Utility is hosted in codeaurora forum git.
+The driver uses rtnl_link_ops for communication.
+
+https://source.codeaurora.org/quic/la/platform/vendor/qcom-opensource/dataservices/tree/rmnetctl
drivers/net/ethernet/qualcomm/Kconfig +2 -0
index 877675a..f520071 100644
@@ -59,4 +59,6 @@ config QCOM_EMAC
 	  low power, Receive-Side Scaling (RSS), and IEEE 1588-2008
 	  Precision Clock Synchronization Protocol.
 
+source "drivers/net/ethernet/qualcomm/rmnet/Kconfig"
+
 endif # NET_VENDOR_QUALCOMM
drivers/net/ethernet/qualcomm/Makefile +2 -0
index 92fa7c4..1847350 100644
@@ -9,3 +9,5 @@ obj-$(CONFIG_QCA7000_UART) += qcauart.o
 qcauart-objs := qca_uart.o
 
 obj-y += emac/
+
+obj-$(CONFIG_RMNET) += rmnet/
drivers/net/ethernet/qualcomm/rmnet/Kconfig new file +12 -0
new file mode 100644
index 0000000..4948f14
@@ -0,0 +1,12 @@
+#
+# RMNET MAP driver
+#
+
+menuconfig RMNET
+	depends on NETDEVICES
+	bool "RmNet MAP driver"
+	default n
+	---help---
+	  If you say Y here, then the rmnet module will be statically
+	  compiled into the kernel. The rmnet module provides MAP
+	  functionality for embedded and bridged traffic.
drivers/net/ethernet/qualcomm/rmnet/Makefile new file +12 -0
new file mode 100644
index 0000000..1c43e2f
@@ -0,0 +1,12 @@
+#
+# Makefile for the RMNET module
+#
+
+rmnet-y		 := rmnet_config.o
+rmnet-y		 += rmnet_vnd.o
+rmnet-y		 += rmnet_handlers.o
+rmnet-y		 += rmnet_map_data.o
+rmnet-y		 += rmnet_map_command.o
+obj-$(CONFIG_RMNET) += rmnet.o
+
+CFLAGS_rmnet.o := -I$(src)
drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c new file +418 -0

418 lines not on this page · raw message

drivers/net/ethernet/qualcomm/rmnet/rmnet_config.h new file +54 -0

54 lines not on this page · raw message

drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.c new file +276 -0

276 lines not on this page · raw message

drivers/net/ethernet/qualcomm/rmnet/rmnet_handlers.h new file +26 -0
new file mode 100644
index 0000000..f2638cf
@@ -0,0 +1,26 @@
+/* Copyright (c) 2013, 2016-2017 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
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * RMNET Data ingress/egress handler
+ *
+ */
+
+#ifndef _RMNET_HANDLERS_H_
+#define _RMNET_HANDLERS_H_
+
+#include "rmnet_config.h"
+
+void rmnet_egress_handler(struct sk_buff *skb,
+			  struct rmnet_endpoint *ep);
+
+rx_handler_result_t rmnet_rx_handler(struct sk_buff **pskb);
+
+#endif /* _RMNET_HANDLERS_H_ */
drivers/net/ethernet/qualcomm/rmnet/rmnet_map.h new file +88 -0

88 lines not on this page · raw message

drivers/net/ethernet/qualcomm/rmnet/rmnet_map_command.c new file +116 -0

116 lines not on this page · raw message

drivers/net/ethernet/qualcomm/rmnet/rmnet_map_data.c new file +105 -0

105 lines not on this page · raw message

drivers/net/ethernet/qualcomm/rmnet/rmnet_private.h new file +45 -0

45 lines not on this page · raw message

drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.c new file +263 -0

263 lines not on this page · raw message

drivers/net/ethernet/qualcomm/rmnet/rmnet_vnd.h new file +32 -0
new file mode 100644
index 0000000..3020646
@@ -0,0 +1,32 @@
+/* Copyright (c) 2013-2017, 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
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * RMNET Data Virtual Network Device APIs
+ *
+ */
+
+#ifndef _RMNET_VND_H_
+#define _RMNET_VND_H_
+
+int rmnet_vnd_do_flow_control(struct rmnet_real_dev_info *rdinfo,
+			      struct net_device *dev, int enable);
+struct rmnet_endpoint *rmnet_vnd_get_endpoint(struct net_device *dev);
+int rmnet_vnd_free_dev(struct net_device *real_dev, int id);
+int rmnet_vnd_remove_ref_dev(struct net_device *real_dev, int id);
+int rmnet_vnd_rx_fixup(struct sk_buff *skb, struct net_device *dev);
+int rmnet_vnd_tx_fixup(struct sk_buff *skb, struct net_device *dev);
+int rmnet_vnd_get_mux(struct net_device *real_dev,
+		      struct net_device *rmnet_dev);
+struct net_device *rmnet_vnd_get_by_id(struct net_device *real_dev, int id);
+void rmnet_vnd_setup(struct net_device *dev);
+int rmnet_vnd_newlink(struct net_device *real_dev, int id,
+		      struct net_device *new_device);
+#endif /* _RMNET_VND_H_ */
Signature · 1 line
1.9.1
#6 lore raw

Re: [PATCH net-next 3/3 v7] drivers: net: ethernet: qualcomm: rmnet: Initial implementation

Quoted 10 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c new file +10 -0
+static int rmnet_unregister_real_device(struct net_device *real_dev)
+{
+	struct rmnet_real_dev_info *rdinfo;
+	struct list_head *iter;
+
+	ASSERT_RTNL();
+
+	if (!rmnet_is_real_dev_registered(real_dev) ||
+	    netdev_lower_get_next(real_dev, &iter))
+		return -EINVAL;

drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c line 93

Quoted 10 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c new file +10 -0
+
+	rdinfo = __rmnet_get_real_dev_info(real_dev);
+	kfree(rdinfo);
+
+	netdev_rx_handler_unregister(real_dev);
+
+	/* release reference on real_dev */
+	dev_put(real_dev);
+
+	netdev_info(real_dev, "Removed from rmnet\n");

I would probably turn all your netdev_info()s into netdev_dbg()s. You seem to be spamming the kernel log quite a bit.

Andrew

maintainer
#7 lore raw

Re: [PATCH net-next 3/3 v7] drivers: net: ethernet: qualcomm: rmnet: Initial implementation

In reply to Subash Abhinov Kasiviswanathan

From: Subash Abhinov Kasiviswanathan <[email protected]>
Date: Mon, 21 Aug 2017 16:36:59 -0600

Quoted 8 lines
drivers/net/ethernet/qualcomm/rmnet/Makefile new file +2 -0
new file mode 100644
index 0000000..1c43e2f
@@ -0,0 +1,12 @@
+#
+# Makefile for the RMNET module

drivers/net/ethernet/qualcomm/rmnet/Makefile line 12

Quoted 10 lines
drivers/net/ethernet/qualcomm/rmnet/Makefile new file +10 -0
+#
+
+rmnet-y		 := rmnet_config.o
+rmnet-y		 += rmnet_vnd.o
+rmnet-y		 += rmnet_handlers.o
+rmnet-y		 += rmnet_map_data.o
+rmnet-y		 += rmnet_map_command.o
+obj-$(CONFIG_RMNET) += rmnet.o
+
+CFLAGS_rmnet.o := -I$(src)

You do not need this CFLAGS rule, the local include files are included using "" double quotes so it uses the local directory always.

drivers/net/ethernet/qualcomm/rmnet/Makefile

Quoted 12 lines
drivers/net/ethernet/qualcomm/rmnet/Makefile new file +12 -0
+static void rmnet_free_later(struct work_struct *work)
+{
+	struct rmnet_free_work *fwork;
+
+	fwork = container_of(work, struct rmnet_free_work, work);
+
+	rtnl_lock();
+	rmnet_delink(fwork->rmnet_dev, NULL);
+	rtnl_unlock();
+
+	kfree(fwork);
+}

This is racy and doesn't work properly.

When you schedule this work, the RTNL mutex is dropped. Meanwhile another request can come in the associate this device.

Your work function will still run and erroneously unlink the object.

Furthermore, during this time that the RTNL mutex is dropped, people will see the unassociated device in the lists.

You have to atomically remove the object from all possible locations which provide external visibility of that object, before the RTNL mutex is dropped.

So you can defer the freeing, but you cannot defer the unlink operation.

You probably need to move to RCU as well in order for all of this to work properly since scans of the lists occur in the data path which is completely asynchronous and not protected by the RTNL mutex.

#8 lore raw

Re: [PATCH net-next 3/3 v7] drivers: net: ethernet: qualcomm: rmnet: Initial implementation

Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+CFLAGS_rmnet.o := -I$(src)

You do not need this CFLAGS rule, the local include files are included using "" double quotes so it uses the local directory always.

Hi David

I'll remove this.

Quoted 23 lines

drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c line 298

Quoted 12 lines
drivers/net/ethernet/qualcomm/rmnet/rmnet_config.c new file +12 -0
+static void rmnet_free_later(struct work_struct *work)
+{
+	struct rmnet_free_work *fwork;
+
+	fwork = container_of(work, struct rmnet_free_work, work);
+
+	rtnl_lock();
+	rmnet_delink(fwork->rmnet_dev, NULL);
+	rtnl_unlock();
+
+	kfree(fwork);
+}

This is racy and doesn't work properly.

When you schedule this work, the RTNL mutex is dropped. Meanwhile another request can come in the associate this device.

Your work function will still run and erroneously unlink the object.

Furthermore, during this time that the RTNL mutex is dropped, people will see the unassociated device in the lists.

Quoted 6 lines

You have to atomically remove the object from all possible locations which provide external visibility of that object, before the RTNL mutex is dropped.

So you can defer the freeing, but you cannot defer the unlink operation.

I had incorrectly assumed earlier that the check in rtnl_newlink for NLM_F_EXCL would guard against the scenario of re-associating a device which was unlinked.

Quoted 4 lines

You probably need to move to RCU as well in order for all of this to work properly since scans of the lists occur in the data path which is completely asynchronous and not protected by the RTNL mutex.

I'll remove all the rtnl locks and checks and switch to rcu and post an update.