netlink: remove mmapped netlink support
Subsystems (6)
Florian Westphal
maintainercover netlink: remove mmapped netlink support
As discussed during netconf 2016 in Seville, this series removes CONFIG_NETLINK_MMAP.
Close to three years after it was merged it has retained several problems that do not appear to be fixable.
No official netfilter libmnl release contains support for mmap backed netlink sockets. No openvswitch release makes use of it either.
To use the mmap interface, userspace not only has to probe for mmap netlink support, it also has to implement a recv/socket receive path in order to handle messages that exceed the size of an rx ring element (NL_MMAP_STATUS_COPY).
So if there are odd programs out there that attempt to use MMAP netlink they should continue to work as they already need a socket based code path to work properly.
The actual revert (first patch) has a list of problems.
The followup patches remove a couple of helpers that are no longer needed after the revert.
I did a few tests with mmap vs. socket based interface on a 4.4 based kernel on an i7-4790 box and there are no performance advantages:
loopback, single nfqueue, queueing in -t filter INPUT:
traffic generated by 8 * ping -q -f localhost:
socket backend:
# time ./nfqdump -c 10000000 > /dev/null real 0m27.325s user 0m3.993s sys 0m23.292s
with mmap ring backend:
# time LD_PRELOAD=../../src/.libs/libmnl.so .libs/nf-queue 0 > /dev/null real 0m29.054s user 0m4.924s sys 0m24.127s
with single tcp stream, unidirectional, loopback mtu set at 1500 (nc localhost discard < /dev/zero > /dev/null):
socket interface:
time nfqdump -b $((8 * 1024 * 1024 * 1024)) -w /dev/null
real 0m15.960s user 0m1.756s sys 0m11.143s
mmap ring:
real 0m16.441s user 0m3.040s sys 0m13.687s
socket interface nfqdump[1] with --gso option (i.e. MTU is exceeded, no kernel-side segmentation and checksum fixups) completes in about 5s.
I also tested dumping a conntrack table with 1m entries.
On my box this takes about 2.4 seconds for both mmap and socket backend:
time LD_PRELOAD=../../src/.libs/libmnl.so ./nfct-dump-sk > /dev/nullmnl_cb_run: Success
messages: 1000000
real 0m2.485s user 0m1.085s sys 0m1.400s
time LD_PRELOAD=../../src/.libs/libmnl.so ./nfct-dump-mmap > /dev/null
messages: 1000000
real 0m2.451s user 0m1.124s sys 0m1.328s
Florian Westphal
maintainerPATCH 1/5 netlink: remove mmapped netlink support
mmapped netlink has a number of unresolved issues:
- TX zerocopy support had to be disabled more than a year ago via commit 4682a0358639b29cf ("netlink: Always copy on mmap TX.") because the content of the mmapped area can change after netlink attribute validation but before message processing.
- RX support was implemented mainly to speed up nfqueue dumping packet payload to userspace. However, since commit ae08ce0021087a5d812d2 ("netfilter: nfnetlink_queue: zero copy support") we avoid one copy with the socket-based interface too (via the skb_zerocopy helper).
The other problem is that skbs attached to mmaped netlink socket behave different from normal skbs:
- they don't have a shinfo area, so all functions that use skb_shinfo() (e.g. skb_clone) cannot be used.
- reserving headroom prevents userspace from seeing the content as it expects message to start at skb->head.
See for instance
commit aa3a022094fa ("netlink: not trim skb for mmaped socket when dump").
- skbs handed e.g. to netlink_ack must have non-NULL skb->sk, else we crash because it needs the sk to check if a tx ring is attached.
Also not obvious, leads to non-intuitive bug fixes such as 7c7bdf359 ("netfilter: nfnetlink: use original skbuff when acking batches").
mmaped netlink also didn't play nicely with the skb_zerocopy helper used by nfqueue and openvswitch. Daniel Borkmann fixed this via commit 6bb0fef489f6 ("netlink, mmap: fix edge-case leakages in nf queue zero-copy")' but at the cost of also needing to provide remaining length to the allocation function.
nfqueue also has problems when used with mmaped rx netlink:
- mmaped netlink doesn't allow use of nfqueue batch verdict messages. Problem is that in the mmap case, the allocation time also determines the ordering in which the frame will be seen by userspace (A allocating before B means that A is located in earlier ring slot, but this also means that B might get a lower sequence number then A since seqno is decided later. To fix this we would need to extend the spinlocked region to also cover the allocation and message setup which isn't desirable.
- nfqueue can now be configured to queue large (GSO) skbs to userspace. Queing GSO packets is faster than having to force a software segmentation in the kernel, so this is a desirable option. However, with a mmap based ring one has to use 64kb per ring slot element, else mmap has to fall back to the socket path (NL_MMAP_STATUS_COPY) for all large packets.
To use the mmap interface, userspace not only has to probe for mmap netlink support, it also has to implement a recv/socket receive path in order to handle messages that exceed the size of an rx ring element.
--- Documentation/networking/netlink_mmap.txt | 332 ------------- include/uapi/linux/netlink.h | 4 + include/uapi/linux/netlink_diag.h | 2 + net/netlink/Kconfig | 9 - net/netlink/af_netlink.c | 754 +----------------------------- net/netlink/af_netlink.h | 15 - net/netlink/diag.c | 39 -- 7 files changed, 15 insertions(+), 1140 deletions(-) delete mode 100644 Documentation/networking/netlink_mmap.txt
Documentation/networking/netlink_mmap.txt deleted +0 -332
@@ -1,332 +0,0 @@ -This file documents how to use memory mapped I/O with netlink. - -Author: Patrick McHardy <[email protected]> - -Overview --------- - -Memory mapped netlink I/O can be used to increase throughput and decrease -overhead of unicast receive and transmit operations. Some netlink subsystems -require high throughput, these are mainly the netfilter subsystems -nfnetlink_queue and nfnetlink_log, but it can also help speed up large -dump operations of f.i. the routing database. - -Memory mapped netlink I/O used two circular ring buffers for RX and TX which -are mapped into the processes address space. - -The RX ring is used by the kernel to directly construct netlink messages into -user-space memory without copying them as done with regular socket I/O, -additionally as long as the ring contains messages no recvmsg() or poll() -syscalls have to be issued by user-space to get more message. - -The TX ring is used to process messages directly from user-space memory, the -kernel processes all messages contained in the ring using a single sendmsg() -call. - -Usage overview --------------- - -In order to use memory mapped netlink I/O, user-space needs three main changes: - -- ring setup -- conversion of the RX path to get messages from the ring instead of recvmsg() -- conversion of the TX path to construct messages into the ring - -Ring setup is done using setsockopt() to provide the ring parameters to the -kernel, then a call to mmap() to map the ring into the processes address space: - -- setsockopt(fd, SOL_NETLINK, NETLINK_RX_RING, ¶ms, sizeof(params)); -- setsockopt(fd, SOL_NETLINK, NETLINK_TX_RING, ¶ms, sizeof(params)); -- ring = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0) - -Usage of either ring is optional, but even if only the RX ring is used the -mapping still needs to be writable in order to update the frame status after -processing. - -Conversion of the reception path involves calling poll() on the file -descriptor, once the socket is readable the frames from the ring are -processed in order until no more messages are available, as indicated by -a status word in the frame header. - -On kernel side, in order to make use of memory mapped I/O on receive, the -originating netlink subsystem needs to support memory mapped I/O, otherwise -it will use an allocated socket buffer as usual and the contents will be - copied to the ring on transmission, nullifying most of the performance gains. -Dumps of kernel databases automatically support memory mapped I/O. - -Conversion of the transmit path involves changing message construction to -use memory from the TX ring instead of (usually) a buffer declared on the -stack and setting up the frame header appropriately. Optionally poll() can -be used to wait for free frames in the TX ring. - -Structured and definitions for using memory mapped I/O are contained in -<linux/netlink.h>. - -RX and TX rings ----------------- - -Each ring contains a number of continuous memory blocks, containing frames of -fixed size dependent on the parameters used for ring setup. - -Ring: [ block 0 ] - [ frame 0 ] - [ frame 1 ] - [ block 1 ] - [ frame 2 ] - [ frame 3 ] - ... - [ block n ] - [ frame 2 * n ] - [ frame 2 * n + 1 ] - -The blocks are only visible to the kernel, from the point of view of user-space -the ring just contains the frames in a continuous memory zone. - -The ring parameters used for setting up the ring are defined as follows: - -struct nl_mmap_req { - unsigned int nm_block_size; - unsigned int nm_block_nr; - unsigned int nm_frame_size; - unsigned int nm_frame_nr; -}; - -Frames are grouped into blocks, where each block is a continuous region of memory -and holds nm_block_size / nm_frame_size frames. The total number of frames in -the ring is nm_frame_nr. The following invariants hold: - -- frames_per_block = nm_block_size / nm_frame_size - -- nm_frame_nr = frames_per_block * nm_block_nr - -Some parameters are constrained, specifically: - -- nm_block_size must be a multiple of the architectures memory page size. - The getpagesize() function can be used to get the page size. - -- nm_frame_size must be equal or larger to NL_MMAP_HDRLEN, IOW a frame must be - able to hold at least the frame header - -- nm_frame_size must be smaller or equal to nm_block_size - -- nm_frame_size must be a multiple of NL_MMAP_MSG_ALIGNMENT - -- nm_frame_nr must equal the actual number of frames as specified above. - -When the kernel can't allocate physically continuous memory for a ring block, -it will fall back to use physically discontinuous memory. This might affect -performance negatively, in order to avoid this the nm_frame_size parameter -should be chosen to be as small as possible for the required frame size and -the number of blocks should be increased instead. - -Ring frames ------------- - -Each frames contain a frame header, consisting of a synchronization word and some -meta-data, and the message itself. - -Frame: [ header message ] - -The frame header is defined as follows: - -struct nl_mmap_hdr { - unsigned int nm_status; - unsigned int nm_len; - __u32 nm_group; - /* credentials */ - __u32 nm_pid; - __u32 nm_uid; - __u32 nm_gid; -}; - -- nm_status is used for synchronizing processing between the kernel and user- - space and specifies ownership of the frame as well as the operation to perform - -- nm_len contains the length of the message contained in the data area - -- nm_group specified the destination multicast group of message - -- nm_pid, nm_uid and nm_gid contain the netlink pid, UID and GID of the sending - process. These values correspond to the data available using SOCK_PASSCRED in - the SCM_CREDENTIALS cmsg. - -The possible values in the status word are: - -- NL_MMAP_STATUS_UNUSED: - RX ring: frame belongs to the kernel and contains no message - for user-space. Approriate action is to invoke poll() - to wait for new messages. - - TX ring: frame belongs to user-space and can be used for - message construction. - -- NL_MMAP_STATUS_RESERVED: - RX ring only: frame is currently used by the kernel for message - construction and contains no valid message yet. - Appropriate action is to invoke poll() to wait for - new messages. - -- NL_MMAP_STATUS_VALID: - RX ring: frame contains a valid message. Approriate action is - to process the message and release the frame back to - the kernel by setting the status to - NL_MMAP_STATUS_UNUSED or queue the frame by setting the - status to NL_MMAP_STATUS_SKIP. - - TX ring: the frame contains a valid message from user-space to - be processed by the kernel. After completing processing - the kernel will release the frame back to user-space by - setting the status to NL_MMAP_STATUS_UNUSED. - -- NL_MMAP_STATUS_COPY: - RX ring only: a message is ready to be processed but could not be - stored in the ring, either because it exceeded the - frame size or because the originating subsystem does - not support memory mapped I/O. Appropriate action is - to invoke recvmsg() to receive the message and release - the frame back to the kernel by setting the status to - NL_MMAP_STATUS_UNUSED. - -- NL_MMAP_STATUS_SKIP: - RX ring only: user-space queued the message for later processing, but - processed some messages following it in the ring. The - kernel should skip this frame when looking for unused - frames. - -The data area of a frame begins at a offset of NL_MMAP_HDRLEN relative to the -frame header. - -TX limitations --------------- - -As of Jan 2015 the message is always copied from the ring frame to an -allocated buffer due to unresolved security concerns. -See commit 4682a0358639b29cf ("netlink: Always copy on mmap TX."). - -Example -------- - -Ring setup: - - unsigned int block_size = 16 * getpagesize(); - struct nl_mmap_req req = { - .nm_block_size = block_size, - .nm_block_nr = 64, - .nm_frame_size = 16384, - .nm_frame_nr = 64 * block_size / 16384, - }; - unsigned int ring_size; - void *rx_ring, *tx_ring; - - /* Configure ring parameters */ - if (setsockopt(fd, SOL_NETLINK, NETLINK_RX_RING, &req, sizeof(req)) < 0) - exit(1); - if (setsockopt(fd, SOL_NETLINK, NETLINK_TX_RING, &req, sizeof(req)) < 0) - exit(1) - - /* Calculate size of each individual ring */ - ring_size = req.nm_block_nr * req.nm_block_size; - - /* Map RX/TX rings. The TX ring is located after the RX ring */ - rx_ring = mmap(NULL, 2 * ring_size, PROT_READ | PROT_WRITE, - MAP_SHARED, fd, 0); - if ((long)rx_ring == -1L) - exit(1); - tx_ring = rx_ring + ring_size: - -Message reception: - -This example assumes some ring parameters of the ring setup are available. - - unsigned int frame_offset = 0; - struct nl_mmap_hdr *hdr; - struct nlmsghdr *nlh; - unsigned char buf[16384]; - ssize_t len; - - while (1) { - struct pollfd pfds[1]; - - pfds[0].fd = fd; - pfds[0].events = POLLIN | POLLERR; - pfds[0].revents = 0; - - if (poll(pfds, 1, -1) < 0 && errno != -EINTR) - exit(1); - - /* Check for errors. Error handling omitted */ - if (pfds[0].revents & POLLERR) - <handle error> - - /* If no new messages, poll again */ - if (!(pfds[0].revents & POLLIN)) - continue; - - /* Process all frames */ - while (1) { - /* Get next frame header */ - hdr = rx_ring + frame_offset; - - if (hdr->nm_status == NL_MMAP_STATUS_VALID) { - /* Regular memory mapped frame */ - nlh = (void *)hdr + NL_MMAP_HDRLEN; - len = hdr->nm_len; - - /* Release empty message immediately. May happen - * on error during message construction. - */ - if (len == 0) - goto release; - } else if (hdr->nm_status == NL_MMAP_STATUS_COPY) { - /* Frame queued to socket receive queue */ - len = recv(fd, buf, sizeof(buf), MSG_DONTWAIT); - if (len <= 0) - break; - nlh = buf; - } else - /* No more messages to process, continue polling */ - break; - - process_msg(nlh); -release: - /* Release frame back to the kernel */ - hdr->nm_status = NL_MMAP_STATUS_UNUSED; - - /* Advance frame offset to next frame */ - frame_offset = (frame_offset + frame_size) % ring_size; - } - } - -Message transmission: - -This example assumes some ring parameters of the ring setup are available. -A single message is constructed and transmitted, to send multiple messages -at once they would be constructed in consecutive frames before a final call -to sendto(). - - unsigned int frame_offset = 0; - struct nl_mmap_hdr *hdr; - struct nlmsghdr *nlh; - struct sockaddr_nl addr = { - .nl_family = AF_NETLINK, - }; - - hdr = tx_ring + frame_offset; - if (hdr->nm_status != NL_MMAP_STATUS_UNUSED) - /* No frame available. Use poll() to avoid. */ - exit(1); - - nlh = (void *)hdr + NL_MMAP_HDRLEN; - - /* Build message */ - build_message(nlh); - - /* Fill frame header: length and status need to be set */ - hdr->nm_len = nlh->nlmsg_len; - hdr->nm_status = NL_MMAP_STATUS_VALID; - - if (sendto(fd, NULL, 0, 0, &addr, sizeof(addr)) < 0) - exit(1); - - /* Advance frame offset to next frame */ - frame_offset = (frame_offset + frame_size) % ring_size;
include/uapi/linux/netlink.h +4 -0
@@ -107,8 +107,10 @@ struct nlmsgerr {#define NETLINK_PKTINFO 3#define NETLINK_BROADCAST_ERROR 4#define NETLINK_NO_ENOBUFS 5 +#ifndef __KERNEL__#define NETLINK_RX_RING 6#define NETLINK_TX_RING 7 +#endif #define NETLINK_LISTEN_ALL_NSID 8#define NETLINK_LIST_MEMBERSHIPS 9#define NETLINK_CAP_ACK 10
@@ -134,6 +136,7 @@ struct nl_mmap_hdr {__u32 nm_gid; }; +#ifndef __KERNEL__enum nl_mmap_status {NL_MMAP_STATUS_UNUSED , NL_MMAP_STATUS_RESERVED,
@@ -145,6 +148,7 @@ enum nl_mmap_status {#define NL_MMAP_MSG_ALIGNMENT NLMSG_ALIGNTO#define NL_MMAP_MSG_ALIGN (sz) __ALIGN_KERNEL(sz, NL_MMAP_MSG_ALIGNMENT)#define NL_MMAP_HDRLEN NL_MMAP_MSG_ALIGN(sizeof(struct nl_mmap_hdr)) +#endif #define NET_MAJOR 36/* Major 36 is reserved for networking */
include/uapi/linux/netlink_diag.h +2 -0
@@ -48,6 +48,8 @@ enum {#define NDIAG_SHOW_MEMINFO 0x00000001/* show memory info of a socket */ #define NDIAG_SHOW_GROUPS 0x00000002/* show groups of a netlink socket */ +#ifndef __KERNEL__#define NDIAG_SHOW_RING_CFG 0x00000004/* show ring configuration */ +#endif #endif
net/netlink/Kconfig +0 -9
@@ -2,15 +2,6 @@ # Netlink Sockets # -config NETLINK_MMAP - bool "NETLINK: mmaped IO" - ---help--- - This option enables support for memory mapped netlink IO. This - reduces overhead by avoiding copying data between kernel- and - userspace. - - If unsure, say N. - config NETLINK_DIAG tristate "NETLINK: socket monitoring interface" default n
net/netlink/af_netlink.c +9 -745
852 lines not on this page · raw message
net/netlink/af_netlink.h +0 -15
@@ -44,12 +44,6 @@ struct netlink_sock {int (*netlink_bind)(struct net *net,int group);void (*netlink_unbind)(struct net *net,int group);struct module *module; -#ifdef CONFIG_NETLINK_MMAP -struct mutex pg_vec_lock; -struct netlink_ring rx_ring; -struct netlink_ring tx_ring; -atomic_t mapped; -#endif /* CONFIG_NETLINK_MMAP */ struct rhash_head node;struct rcu_head rcu;
@@ -60,15 +54,6 @@ static inline struct netlink_sock *nlk_sk(struct sock *sk) return container_of(sk, struct netlink_sock, sk); } -static inline bool netlink_skb_is_mmaped (const struct sk_buff *skb) -{ -#ifdef CONFIG_NETLINK_MMAP -return NETLINK_CB (skb).flags &NETLINK_SKB_MMAPED ; -#else -return false; -#endif /* CONFIG_NETLINK_MMAP */ -} -struct netlink_table {struct rhashtable hash;struct hlist_head mc_list;
net/netlink/diag.c +0 -39
@@ -8,41 +8,6 @@#include "af_netlink.h" -#ifdef CONFIG_NETLINK_MMAP -static int sk_diag_put_ring (struct netlink_ring *ring,int nl_type, -struct sk_buff *nlskb) -{ -struct netlink_diag_ring ndr; - - ndr.ndr_block_size = ring->pg_vec_pages <<PAGE_SHIFT ; - ndr.ndr_block_nr = ring->pg_vec_len; - ndr.ndr_frame_size = ring->frame_size; - ndr.ndr_frame_nr = ring->frame_max +1 ; - -return nla_put (nlskb, nl_type,sizeof (ndr), &ndr); -} - -static int sk_diag_put_rings_cfg (struct sock *sk,struct sk_buff *nlskb) -{ -struct netlink_sock *nlk =nlk_sk (sk); -int ret; - -mutex_lock (&nlk->pg_vec_lock); - ret =sk_diag_put_ring (&nlk->rx_ring,NETLINK_DIAG_RX_RING , nlskb); -if (!ret) - ret =sk_diag_put_ring (&nlk->tx_ring,NETLINK_DIAG_TX_RING , - nlskb); -mutex_unlock (&nlk->pg_vec_lock); - -return ret; -} -#else -static int sk_diag_put_rings_cfg (struct sock *sk,struct sk_buff *nlskb) -{ -return 0 ; -} -#endif -static int sk_diag_dump_groups (struct sock *sk,struct sk_buff *nlskb) {struct netlink_sock *nlk =nlk_sk (sk);
@@ -87,10 +52,6 @@ static int sk_diag_fill(struct sock *sk, struct sk_buff *skb, sock_diag_put_meminfo(sk, skb, NETLINK_DIAG_MEMINFO)) goto out_nlmsg_trim; -if ((req->ndiag_show &NDIAG_SHOW_RING_CFG ) && -sk_diag_put_rings_cfg (sk, skb)) - goto out_nlmsg_trim; -nlmsg_end (skb, nlh);return 0 ;
Signature · 1 line
2.4.10
Florian Westphal
maintainerPATCH 2/5 openvswitch: Revert: "Enable memory mapped Netlink i/o"
In reply to Florian Westphalrevert commit 795449d8b846 ("openvswitch: Enable memory mapped Netlink i/o"). Following the mmaped netlink removal this code can be removed.
--- net/openvswitch/datapath.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
net/openvswitch/datapath.c +3 -7
@@ -422,10 +422,6 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb,struct sk_buff *nskb =NULL ;struct sk_buff *user_skb =NULL ;/* to be queued to userspace */ struct nlattr *nla; -struct genl_info info = { - .dst_sk =ovs_dp_get_net (dp)->genl_sock, - .snd_portid = upcall_info->portid, - };size_t len;unsigned int hlen;int err, dp_ifindex;
@@ -466,7 +462,7 @@ static int queue_userspace_packet(struct datapath *dp, struct sk_buff *skb, hlen = skb->len; len =upcall_msg_size (upcall_info, hlen); - user_skb =genlmsg_new_unicast (len, &info,GFP_ATOMIC ); + user_skb =genlmsg_new (len,GFP_ATOMIC );if (!user_skb) { err = -ENOMEM ; goto out;
@@ -876,7 +872,7 @@ static struct sk_buff *ovs_flow_cmd_alloc_info(const struct sw_flow_actions *actreturn NULL ; len =ovs_flow_cmd_msg_size (acts, sfid, ufid_flags); - skb =genlmsg_new_unicast (len, info,GFP_KERNEL ); + skb =genlmsg_new (len,GFP_KERNEL );if (!skb)return ERR_PTR (-ENOMEM );
@@ -1483,7 +1479,7 @@ error:static struct sk_buff *ovs_dp_cmd_alloc_info (struct genl_info *info) { -return genlmsg_new_unicast (ovs_dp_cmd_msg_size (), info,GFP_KERNEL ); +return genlmsg_new (ovs_dp_cmd_msg_size (),GFP_KERNEL ); }/* Called with rcu_read_lock or ovs_mutex. */
Signature · 1 line
2.4.10
Florian Westphal
maintainerPATCH 3/5 Revert "genl: Add genlmsg_new_unicast() for unicast message allocation"
In reply to Florian WestphalThis reverts commit bb9b18fb55b0 ("genl: Add genlmsg_new_unicast() for unicast message allocation")'.
Nothing wrong with it; its no longer needed since this was only for mmapped netlink support.
--- include/net/genetlink.h | 4 ---- net/netlink/genetlink.c | 21 --------------------- net/openvswitch/datapath.c | 10 +++++----- net/tipc/netlink_compat.c | 1 - 4 files changed, 5 insertions(+), 31 deletions(-)
include/net/genetlink.h +0 -4
@@ -83,7 +83,6 @@ struct genl_family {* @attrs: netlink attributes * @_net: network namespace * @user_ptr: user pointers -* @dst_sk: destination socket */ struct genl_info {u32 snd_seq;
@@ -94,7 +93,6 @@ struct genl_info {struct nlattr ** attrs;possible_net_t _net;void * user_ptr[2 ]; -struct sock * dst_sk; };static inline struct net *genl_info_net (struct genl_info *info)
@@ -188,8 +186,6 @@ int genl_unregister_family(struct genl_family *family);void genl_notify (struct genl_family *family,struct sk_buff *skb,struct genl_info *info,u32 group,gfp_t flags); -struct sk_buff *genlmsg_new_unicast (size_t payload,struct genl_info *info, -gfp_t flags);void *genlmsg_put (struct sk_buff *skb,u32 portid,u32 seq,struct genl_family *family,int flags,u8 cmd);
net/netlink/genetlink.c +0 -21
@@ -463,26 +463,6 @@ int genl_unregister_family(struct genl_family *family)EXPORT_SYMBOL (genl_unregister_family);/** -* genlmsg_new_unicast - Allocate generic netlink message for unicast -* @payload: size of the message payload -* @info: information on destination -* @flags: the type of memory to allocate -* -* Allocates a new sk_buff large enough to cover the specified payload -* plus required Netlink headers. Will check receiving socket for -* memory mapped i/o capability and use it if enabled. Will fall back -* to non-mapped skb if message size exceeds the frame size of the ring. -*/ -struct sk_buff *genlmsg_new_unicast (size_t payload,struct genl_info *info, -gfp_t flags) -{ -size_t len =nlmsg_total_size (genlmsg_total_size (payload)); - -return netlink_alloc_skb (info->dst_sk, len, info->snd_portid, flags); -} -EXPORT_SYMBOL_GPL (genlmsg_new_unicast); - -/** * genlmsg_put - Add generic netlink header to netlink message * @skb: socket buffer holding the message * @portid: netlink portid the message is addressed to
@@ -642,7 +622,6 @@ static int genl_family_rcv_msg(struct genl_family *family, info.genlhdr =nlmsg_data (nlh); info.userhdr =nlmsg_data (nlh) +GENL_HDRLEN ; info.attrs = attrbuf; - info.dst_sk = skb->sk;genl_info_net_set (&info, net);memset (&info.user_ptr,0 ,sizeof (info.user_ptr));
net/openvswitch/datapath.c +5 -5
@@ -1477,7 +1477,7 @@ error:return -EMSGSIZE ; } -static struct sk_buff *ovs_dp_cmd_alloc_info (struct genl_info *info) +static struct sk_buff *ovs_dp_cmd_alloc_info (void ) {return genlmsg_new (ovs_dp_cmd_msg_size (),GFP_KERNEL ); }
@@ -1532,7 +1532,7 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info)if (!a[OVS_DP_ATTR_NAME ] || !a[OVS_DP_ATTR_UPCALL_PID ]) goto err; - reply =ovs_dp_cmd_alloc_info (info); + reply =ovs_dp_cmd_alloc_info ();if (!reply)return -ENOMEM ;
@@ -1653,7 +1653,7 @@ static int ovs_dp_cmd_del(struct sk_buff *skb, struct genl_info *info)struct datapath *dp;int err; - reply =ovs_dp_cmd_alloc_info (info); + reply =ovs_dp_cmd_alloc_info ();if (!reply)return -ENOMEM ;
@@ -1686,7 +1686,7 @@ static int ovs_dp_cmd_set(struct sk_buff *skb, struct genl_info *info)struct datapath *dp;int err; - reply =ovs_dp_cmd_alloc_info (info); + reply =ovs_dp_cmd_alloc_info ();if (!reply)return -ENOMEM ;
@@ -1719,7 +1719,7 @@ static int ovs_dp_cmd_get(struct sk_buff *skb, struct genl_info *info)struct datapath *dp;int err; - reply =ovs_dp_cmd_alloc_info (info); + reply =ovs_dp_cmd_alloc_info ();if (!reply)return -ENOMEM ;
net/tipc/netlink_compat.c +0 -1
@@ -1104,7 +1104,6 @@ static int tipc_nl_compat_recv(struct sk_buff *skb, struct genl_info *info) req_nlh = (struct nlmsghdr *)skb->data; msg.req =nlmsg_data (req_nlh) +GENL_HDRLEN +TIPC_GENL_HDRLEN ; msg.cmd = req_userhdr->cmd; - msg.dst_sk = info->dst_sk; msg.net =genl_info_net (info);if ((msg.cmd &0xC000 ) && (!netlink_net_capable (skb,CAP_NET_ADMIN ))) {
Signature · 1 line
2.4.10
Florian Westphal
maintainerPATCH 4/5 nfnetlink: remove nfnetlink_alloc_skb
In reply to Florian WestphalFollowing mmapped netlink removal this code can be simplified by removing the alloc wrapper.
--- include/linux/netfilter/nfnetlink.h | 2 -- net/netfilter/nfnetlink.c | 7 ------- net/netfilter/nfnetlink_log.c | 5 ++--- 3 files changed, 2 insertions(+), 12 deletions(-)
include/linux/netfilter/nfnetlink.h +0 -2
@@ -34,8 +34,6 @@ int nfnetlink_subsys_register(const struct nfnetlink_subsystem *n);int nfnetlink_subsys_unregister (const struct nfnetlink_subsystem *n);int nfnetlink_has_listeners (struct net *net,unsigned int group); -struct sk_buff *nfnetlink_alloc_skb (struct net *net,unsigned int size, -u32 dst_portid,gfp_t gfp_mask);int nfnetlink_send (struct sk_buff *skb,struct net *net,u32 portid,unsigned int group,int echo,gfp_t flags);int nfnetlink_set_err (struct net *net,u32 portid,u32 group,int error);
net/netfilter/nfnetlink.c +0 -7
@@ -127,13 +127,6 @@ int nfnetlink_has_listeners(struct net *net, unsigned int group) }EXPORT_SYMBOL_GPL (nfnetlink_has_listeners); -struct sk_buff *nfnetlink_alloc_skb (struct net *net,unsigned int size, -u32 dst_portid,gfp_t gfp_mask) -{ -return netlink_alloc_skb (net->nfnl, size, dst_portid, gfp_mask); -} -EXPORT_SYMBOL_GPL (nfnetlink_alloc_skb); -int nfnetlink_send (struct sk_buff *skb,struct net *net,u32 portid,unsigned int group,int echo,gfp_t flags) {
net/netfilter/nfnetlink_log.c +2 -3
@@ -330,14 +330,13 @@ nfulnl_alloc_skb(struct net *net, u32 peer_portid, unsigned int inst_size,* message. WARNING: has to be <= 128k due to slab restrictions */ n =max (inst_size, pkt_size); - skb =nfnetlink_alloc_skb (net, n, peer_portid,GFP_ATOMIC ); + skb =alloc_skb (n,GFP_ATOMIC );if (!skb) {if (n > pkt_size) {/* try to allocate only as much as we need for current * packet */ - skb =nfnetlink_alloc_skb (net, pkt_size, - peer_portid,GFP_ATOMIC ); + skb =alloc_skb (pkt_size,GFP_ATOMIC ); } }
Signature · 1 line
2.4.10
Florian Westphal
maintainerPATCH 5/5 nfnetlink: Revert "nfnetlink: add support for memory mapped netlink"
In reply to Florian Westphalreverts commit 3ab1f683bf8b ("nfnetlink: add support for memory mapped netlink")'
Like previous commits in the series, remove wrappers that are not needed after mmapped netlink removal.
--- include/linux/netlink.h | 10 ---------- net/netfilter/nfnetlink_queue.c | 6 ++---- net/netlink/af_netlink.c | 20 ++++---------------- 3 files changed, 6 insertions(+), 30 deletions(-)
include/linux/netlink.h +0 -10
@@ -69,16 +69,6 @@ extern void __netlink_clear_multicast_users(struct sock *sk, unsigned int group)extern void netlink_ack (struct sk_buff *in_skb,struct nlmsghdr *nlh,int err);extern int netlink_has_listeners (struct sock *sk,unsigned int group); -extern struct sk_buff *__netlink_alloc_skb (struct sock *ssk,unsigned int size, -unsigned int ldiff,u32 dst_portid, -gfp_t gfp_mask); -static inline struct sk_buff * -netlink_alloc_skb (struct sock *ssk,unsigned int size,u32 dst_portid, -gfp_t gfp_mask) -{ -return __netlink_alloc_skb (ssk, size,0 , dst_portid, gfp_mask); -} -extern int netlink_unicast (struct sock *ssk,struct sk_buff *skb,__u32 portid,int nonblock);extern int netlink_broadcast (struct sock *ssk,struct sk_buff *skb,__u32 portid,__u32 group,gfp_t allocation);
net/netfilter/nfnetlink_queue.c +2 -4
@@ -301,7 +301,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, __be32 **packet_id_ptr) {size_t size; -size_t data_len =0 , cap_len =0 , rem_len =0 ; +size_t data_len =0 , cap_len =0 ;unsigned int hlen =0 ;struct sk_buff *skb;struct nlattr *nla;
@@ -361,7 +361,6 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, hlen = min_t(unsigned int, hlen, data_len); size +=sizeof (struct nlattr ) + hlen; cap_len = entskb->len; - rem_len = data_len - hlen;break ; }
@@ -386,8 +385,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, size +=nla_total_size (seclen); } - skb =__netlink_alloc_skb (net->nfnl, size, rem_len, queue->peer_portid, -GFP_ATOMIC ); + skb =alloc_skb (size,GFP_ATOMIC );if (!skb) {skb_tx_error (entskb);return NULL ;
net/netlink/af_netlink.c +4 -16
@@ -1248,14 +1248,6 @@ retry: }EXPORT_SYMBOL (netlink_unicast); -struct sk_buff *__netlink_alloc_skb (struct sock *ssk,unsigned int size, -unsigned int ldiff,u32 dst_portid, -gfp_t gfp_mask) -{ -return alloc_skb (size, gfp_mask); -} -EXPORT_SYMBOL_GPL (__netlink_alloc_skb); -int netlink_has_listeners (struct sock *sk,unsigned int group) {int res =0 ;
@@ -2082,15 +2074,12 @@ static int netlink_dump(struct sock *sk)if (alloc_min_size < nlk->max_recvmsg_len) { alloc_size = nlk->max_recvmsg_len; - skb =netlink_alloc_skb (sk, alloc_size, nlk->portid, -GFP_KERNEL | - __GFP_NOWARN | - __GFP_NORETRY); + skb =alloc_skb (alloc_size,GFP_KERNEL | + __GFP_NOWARN | __GFP_NORETRY); }if (!skb) { alloc_size = alloc_min_size; - skb =netlink_alloc_skb (sk, alloc_size, nlk->portid, -GFP_KERNEL ); + skb =alloc_skb (alloc_size,GFP_KERNEL ); }if (!skb) goto errout_skb;
@@ -2230,8 +2219,7 @@ void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err)if (!(nlk->flags &NETLINK_F_CAP_ACK ) && err) payload +=nlmsg_len (nlh); - skb =netlink_alloc_skb (in_skb->sk,nlmsg_total_size (payload), -NETLINK_CB (in_skb).portid,GFP_KERNEL ); + skb =nlmsg_new (payload,GFP_KERNEL );if (!skb) {struct sock *sk;
Signature · 1 line
2.4.10
David Miller
maintainerFrom: Florian Westphal <[email protected]>
Date: Thu, 18 Feb 2016 15:03:23 +0100
Quoted 2 lines
As discussed during netconf 2016 in Seville, this series removes
CONFIG_NETLINK_MMAP.
Series applied, thanks for following up on this so quickly.
Quoted 2 lines · Florian Westphal
As discussed during netconf 2016 in Seville, this series removes
CONFIG_NETLINK_MMAP.
Sorry for hopping in so^Wtoo late.
I always thought mmaped netlink is the way to go for userspace packet processing.
Sure, the problems you state are real but that the whole concept is now thrown away kind of surprises me.
Quoted 14 lines
Close to three years after it was merged it has retained several problems that do not appear to be fixable.
No official netfilter libmnl release contains support for mmap backed netlink sockets. No openvswitch release makes use of it either.
To use the mmap interface, userspace not only has to probe for mmap netlink support, it also has to implement a recv/socket receive path in order to handle messages that exceed the size of an rx ring element (
NL_MMAP_STATUS_COPY).So if there are odd programs out there that attempt to use MMAP netlink they should continue to work as they already need a socket based code path to work properly.
Quoted 6 lines
The actual revert (first patch) has a list of problems.
The followup patches remove a couple of helpers that are no longer needed after the revert.I did a few tests with mmap vs. socket based interface on a 4.4 based kernel on an i7-4790 box and there are no performance advantages:
Did you also test smaller devices?
i.e. stuff one would use for cheap routers.
Signature · 2 lines
Thanks, //richard