Commit graph

45 commits

Author SHA1 Message Date
Franco Fichtner
ab3b8b4794 netmap: bump ring size, still too small in FreeBSD
PR: https://forum.opnsense.org/index.php?topic=13436.0
2019-07-10 09:18:48 +02:00
rpokala
015fbd019e MFC r339683:
Remove redundant redeclaration of netmap_vp_reg().
This should unbreak sparc64 and powerpc LINT builds.

-- While this does fix that error, powerpc.LINT, powerpc.LINT64, and
-- sparc64.LINT are broken in stable/11 for other reasons. --rpokala

Sponsored by:	Panasas
2019-07-02 19:14:55 +02:00
vmaffione
4ea457eb7b MFC r344510
netmap: remove redundant call to nm_set_native_flags()

This redundant call was introduced by mistake in r343772.

Sponsored by:   Sunny Valley Networks
2019-03-10 08:44:09 +01:00
vmaffione
8cadbe89af MFC r343579, r344253
netmap: fix lock order reversal related to kqueue usage

When using poll(), select() or kevent() on netmap file descriptors,
netmap executes the equivalent of NIOCTXSYNC and NIOCRXSYNC commands,
before collecting the events that are ready. In other words, the
poll/kevent callback has side effects. This is done to avoid the
overhead of two system call per iteration (e.g., poll() + ioctl(NIOC*XSYNC)).

When the kqueue subsystem invokes the kqueue(9) f_event callback
(netmap_knrw), it holds the lock of the struct knlist object associated
to the netmap port (the lock is provided at initialization, by calling
knlist_init_mtx).
However, netmap_knrw() may need to wake up another netmap port (or even
the same one), which means that it may need to call knote().
Since knote() needs the lock of the struct knlist object associated to
the to-be-wake-up netmap port, it is possible to have a lock order reversal
problem (AB/BA deadlock).

This change prevents the deadlock by executing the knote() call in a
per-selinfo taskqueue, where it is possible to hold a mutex.
The change also adds a counter (kqueue_users) to keep track of how many
kqueue users are referencing a given struct nm_selinfo.
In this way, nm_os_selwakeup() can schedule the kevent notification
task only when kqueue is actually being used.
This is important to avoid wasting CPU in the common case where
kqueue is not used.

Reviewed by:    aleksandr.fedorov_itglobal.com
Differential Revision:  https://reviews.freebsd.org/D18956
2019-03-10 08:43:54 +01:00
vmaffione
e51189db04 MFC r343772, r343867
netmap: refactor logging macros and pipes

Changelist:
    - Replace ND, D and RD macros with nm_prdis, nm_prinf, nm_prerr
      and nm_prlim, to avoid possible naming conflicts.
    - Add netmap_krings_mode_commit() helper function and use that
      to reduce code duplication.
    - Refactor pipes control code to export some functions that
      can be reused by the veth driver (on Linux) and epair(4).
    - Add check to reject API requests with version less than 11.
    - Small code refactoring for the null adapter.

Conflicts:
	sys/dev/netmap/netmap.c
2019-03-10 08:42:47 +01:00
vmaffione
b9df35cc0c MFC r343689
netmap: upgrade sync-kloop support

Add SYNC_KLOOP_MODE option, and add support for direct mode, where application
executes the TXSYNC and RXSYNC in the context of the ioeventfd wake up callback.
2019-03-10 08:41:01 +01:00
vmaffione
5ca174880d MFC r343549
netmap: add notifications on kloop stop

On sync-kloop stop, send a wake-up signal to the kloop, so that
waiting for the timeout is not needed.
Also, improve logging in netmap_freebsd.c.
2019-03-10 08:40:39 +01:00
vmaffione
c11d725d2f MFC r343346
netmap: improvements to the netmap kloop (CSB mode)

Changelist:
    - Add the proper memory barriers in the kloop ring processing
      functions.
    - Fix memory barriers usage in the user helpers (nm_sync_kloop_appl_write,
      nm_sync_kloop_appl_read).
    - Fix nm_kr_txempty() helper to look at rhead rather than rcur. This
      is important since the kloop can read a value of rcur which is ahead
      of the value of rhead (see explanation in nm_sync_kloop_appl_write)
    - Remove obsolete ptnetmap_guest_write_kring_csb() and
      ptnet_guest_read_kring_csb().
    - Prepare in advance the arguments for netmap_sync_kloop_[tr]x_ring(),
      to make the kloop faster.
    - Provide kernel and user implementation for nm_ldld_barrier() and
      nm_ldst_barrier()
2019-03-10 08:39:56 +01:00
vmaffione
01059ca75f MFC r343344
netmap: fix knote() argument to match the mutex state

The nm_os_selwakeup function needs to call knote() to wake up kqueue(9)
users. However, this function can be called from different code paths,
with different lock requirements.
This patch fixes the knote() call argument to match the relavant lock state.
Also, comments have been updated to reflect current code.

PR:     https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=219846
Reported by:    Aleksandr Fedorov <aleksandr.fedorov@itglobal.com>
Reviewed by:    markj
Differential Revision:  https://reviews.freebsd.org/D18876
2019-03-10 08:39:31 +01:00
vmaffione
5359fd13f7 netmap: small cleanup on em, lem, igb, ixgbe
Replace D, ND and RD macros with the corresponding nm_pr* ones.
2019-03-10 08:39:08 +01:00
vmaffione
dc1a6e67b9 ixl: remove unnecessary limitations related to netmap
Netmap supports the case where TX rings and RX rings have different size.
Remove unnecessary limitations related to netmap support, making the code
simpler.
Also, check that the value of the hw head index written back from the NIC
is valid.

Reviewed by:	erj
Differential Revision:	https://reviews.freebsd.org/D18984
2019-03-10 08:38:26 +01:00
vmaffione
0a8fd4f9e2 MFC r343413
netmap: fix crash with monitors and VALE ports

Crash report described here:
    https://github.com/luigirizzo/netmap/issues/583
Fixed by providing dummy sync callback in case it is missing.
2019-03-10 08:36:00 +01:00
Franco Fichtner
85f6989b62 netmap: disable this notice again
If it's full it's full.  No use telling dmesg on every other packet.
2019-01-08 11:21:24 +01:00
vmaffione
0ac334369c MFC r342368, r342369
netmap: fix bug in netmap_poll() optimization

The bug was introduced by r339639, although it is present in the upstream
netmap code since 2015. It is due to resetting the want_rx variable to
POLLIN, rather than resetting it to POLLIN|POLLRDNORM.
It only affects select(), which uses POLLRDNORM. poll() is not affected,
because it uses POLLIN.
Also, it only affects FreeBSD, because Linux skips the optimization
implemented by the piece of code where the bug occurs.
To check if txsync can be skipped, it is necessary to look for
unseen TX space. However, this means comparing ring->cur
against ring->tail, rather than ring->head against ring->tail
(like nm_ring_empty() does).

Sponsored by:   Sunny Valley Networks
2019-01-07 22:11:19 +01:00
vmaffione
63bafd88cb MFC r342300
netmap: move buf_size validation code to its own function

This code validates the netmap buf_size against the interface MTU
and maximum descriptor size, to make sure the values are consistent.
Moving this functionality to its own function is needed because this
function is also called by Linux-specific code.
2019-01-07 22:10:13 +01:00
vmaffione
b3e0b7b62c MFC r342299
netmap: pipes: make sure both ends use the same number of slots
2019-01-07 22:09:39 +01:00
vmaffione
ba193f3aa6 MFC r341992
netmap: fix warning in netmap_kloop.c

Reported by:    markj
2019-01-07 22:08:48 +01:00
vmaffione
72fc511079 MFC r341624
netmap: netmap_transmit should honor bpf packet tap hook

This allows tcpdump to capture outbound kernel packets while
in netmap mode

Submitted by:   Marc de la Gueronniere <mdelagueronniere@verisign.com>
Reviewed by:    vmaffione
MFC after:      1 week
Sponsored by:   Verisign, Inc.
Differential Revision:  https://reviews.freebsd.org/D17896
2019-01-07 22:08:09 +01:00
vmaffione
f7502f71c1 MFC r341516, r341589
netmap: align codebase to the current upstream (760279cfb2730a585)

Changelist:
  - Replace netmap passthrough host support with a more general
    mechanism to call TXSYNC/RXSYNC from an in-kernel event-loop.
    No kernel threads are used to use this feature: the application
    is required to spawn a thread (or a process) and issue a
    SYNC_KLOOP_START (NIOCCTRL) command in the thread body. The
    kernel loop is executed by the ioctl implementation, which returns
    to userspace only when a different thread calls SYNC_KLOOP_STOP
    or the netmap file descriptor is closed.
  - Update the if_ptnet driver to cope with the new data structures,
    and prune all the obsolete ptnetmap code.
  - Add support for "null" netmap ports, useful to allocate netmap_if,
    netmap_ring and netmap buffers to be used by specialized applications
    (e.g. hypervisors). TXSYNC/RXSYNC on these ports have no effect.
  - Various fixes and code refactoring.

Sponsored by:   Sunny Valley Networks
Differential Revision:  https://reviews.freebsd.org/D18015
2019-01-07 22:06:51 +01:00
vmaffione
cef293906e MFC r341144
netmap: set IFCAP_NETMAP in if_capabilities

Revision r307394 removed (by mistake) the code that sets IFCAP_NETMAP
in if_capabilities on netmap_attach. This patch reverts this change.

Reviewed by:    np
Approved by:    gnn (mentor)
Differential Revision:  https://reviews.freebsd.org/D17987
2019-01-07 22:02:51 +01:00
vmaffione
39c0abd7b2 MFC r340436
vtnet: fix netmap support

netmap(4) support for vtnet(4) was incomplete and had multiple bugs.
This commit fixes those bugs to bring netmap on vtnet in a functional state.

Changelist:
  - handle errors returned by virtqueue_enqueue() properly (they were
    previously ignored)
  - make sure netmap XOR rest of the kernel access each virtqueue.
  - compute the number of netmap slots for TX and RX separately, according to
    whether indirect descriptors are used or not for a given virtqueue.
  - make sure sglist are freed according to their type (mbufs or netmap
    buffers)
  - add support for mulitiqueue and netmap host (aka sw) rings.
  - intercept VQ interrupts directly instead of intercepting them in txq_eof
    and rxq_eof. This simplifies the code and makes it easier to make sure
    taskqueues are not running for a VQ while it is in netmap mode.
  - implement vntet_netmap_config() to cope with changes in the number of queues.

Reviewed by:    bryanv
Approved by:    gnn (mentor)
Sponsored by:   Sunny Valley Networks
Differential Revision:  https://reviews.freebsd.org/D17916
2019-01-07 22:02:06 +01:00
vmaffione
55c8ba7476 MFC r339639
netmap: align codebase to the current upstream (sha 8374e1a7e6941)

Changelist:
    - Move large parts of VALE code to a new file and header netmap_bdg.[ch].
      This is useful to reuse the code within upcoming projects.
    - Improvements and bug fixes to pipes and monitors.
    - Introduce nm_os_onattach(), nm_os_onenter() and nm_os_onexit() to
      handle differences between FreeBSD and Linux.
    - Introduce some new helper functions to handle more host rings and fake
      rings (netmap_all_rings(), netmap_real_rings(), ...)
    - Added new sysctl to enable/disable hw checksum in emulated netmap mode.
    - nm_inject: add support for NS_MOREFRAG

Approved by:    gnn (mentor)
Differential Revision:  https://reviews.freebsd.org/D17364
2019-01-07 22:01:23 +01:00
Franco Fichtner
d563ccc6e0 Revert "netmap: ring size limit not enough for multi-queue em(4)"
This reverts commit cd1c670224.
2019-01-07 22:00:14 +01:00
Franco Fichtner
8af5eb60dd Revert "pull https://reviews.freebsd.org/D17896 to fix netmap tx / bpf packet tap hook, closes https://github.com/opnsense/core/issues/1632"
This reverts commit b91790ab56.

t #
2019-01-07 21:59:48 +01:00
dab
4be144400d MFC r337812,r337814,r337820,r341068:
r337812 also fixed a bug in the netmap kevent code. The inclusion of
that fix was an oversight that I didn't notice until this
MFC. Reference the code review and PR here in the MFC for
completeness.

PR:  206053
Differential Revision:    https://reviews.freebsd.org/D16531
Sponsored by:	Dell EMC Isilon
2019-01-07 21:54:43 +01:00
Ad Schellevis
b91790ab56 pull https://reviews.freebsd.org/D17896 to fix netmap tx / bpf packet tap hook, closes https://github.com/opnsense/core/issues/1632
tested locally with intel igb driver, seems to be working fine, lets give this some time in our dev version.
2018-12-12 22:57:04 +01:00
Franco Fichtner
cd1c670224 netmap: ring size limit not enough for multi-queue em(4)
Also mutes a spammy message.  Bravely going where no man
has gone before.  :)
2018-10-07 17:34:21 +02:00
Franco Fichtner
0dc4b34cbd src: switch to release/11.2.0
Taken from: FreeBSD commit 62a489e1688b21b7cbdab9ffdb449a67bacc770c
2018-10-07 14:26:34 +02:00
Franco Fichtner
b59bcb97ec re: it looks like re(4) does not have this issue at all 2018-09-23 12:24:37 +02:00
Franco Fichtner
6fcf512a07 re: allow bpf listener to see outgoing packet
PR: https://github.com/opnsense/core/issues/1632
2018-09-23 01:39:22 +02:00
Franco Fichtner
00bed2565c netmap: ring size limit not enough for multi-queue em(4)
Also mutes a spammy message.  Bravely going where no man
has gone before.  :)
2017-08-20 14:05:07 +02:00
Franco Fichtner
3c09b4c3de src: clean-cut move to release/11.1.0
Taken from: FreeBSD
Commit ref: 2f4b735c66d
2017-08-20 13:44:58 +02:00
Franco Fichtner
175886459b netmap: manually backport multiple fixes
o Restore netmap emulation mode to working order, including
  fixing the destructor panics on detach.
o Omit pipe additions to these fixes, likely problematic for
  Suricata to pass traffic like it does on 11.0 without this
  patch.
o Allow to build the module without errors in the tree.

Many thanks to Vincenzo Maffione for assistance and review!  :)

From b497fe34fd275da6b850bf271f510d02b888b8bc Mon Sep 17 00:00:00 2001
From: Giuseppe Lettieri <g.lettieri@iet.unipi.it>
Date: Thu, 2 Jun 2016 00:21:40 +0200
Subject: [PATCH] allocate only the rings requested by the user

From 09936864fa5b67b82ef4a9907819b7018e9a38f2 Mon Sep 17 00:00:00 2001
From: Giuseppe Lettieri <g.lettieri@iet.unipi.it>
Date: Wed, 20 Jul 2016 20:35:12 +0000
Subject: [PATCH] freebsd: fix const-related warning

From ab90c6c10224fefbb6a6c6e0b92e6ba80e5b694d Mon Sep 17 00:00:00 2001
From: Vincenzo Maffione <v.maffione@gmail.com>
Date: Wed, 28 Sep 2016 18:39:55 +0200
Subject: [PATCH] freebsd: generic: change mbuf allocation management

From fe811e11b2c37fc274a1134e1c10b2f6ada1a91c Mon Sep 17 00:00:00 2001
From: Vincenzo Maffione <v.maffione@gmail.com>
Date: Thu, 29 Sep 2016 08:54:52 +0200
Subject: [PATCH] freebsd: generic: call m_extadd() only once for each mbuf
2017-01-16 10:47:49 +01:00
sbruno
850e1e9622 The buffer address is always overwritten in the extended descriptor format,
we have to refresh it ... always.  This fixes problems reported in NetMap
with em(4) devices after conversion to extended descriptor format in
svn r293331.

Submitted by:	luigi@
Reported by:	franco@opnsense.org
MFC after:	2 days
2016-10-28 16:06:33 +02:00
Franco Fichtner
ef7057cc39 netmap: ring size limit not enough for multi-queue em(4)
Also mutes a spammy message.  Bravely going where no man
has gone before.  :)
2016-10-03 12:46:32 +02:00
Franco Fichtner
eb99233983 src: clean-cut move to release/11.0.0
Taken from: FreeBSD
Commit ref: d508cb8c8f
2016-10-03 12:28:21 +02:00
np
fdc22de28e MFC r297298:
Plug leak in m_unshare.

m_unshare passes on the source mbuf's flags as-is to m_getcl and this
results in a leak if the flags include M_NOFREE.  The fix is to clear
the bits not listed in M_COPYALL before calling m_getcl.  M_RDONLY
should probably be filtered out too but that's outside the scope of this
fix.

Add assertions in the zone_mbuf and zone_pack ctors to catch similar
bugs.

Update netmap_get_mbuf to not pass M_NOFREE to m_getcl.  It's not clear
what the original code was trying to do but it's likely incorrect.
Updated code is no different functionally but it avoids the newly added
assertions.

Sponsored by:	Chelsio Communications
2016-08-02 07:18:48 +02:00
Ad Schellevis
11586afbb7 revert extended descr format for intel em(4), breaks netmap for some chipsets 2016-08-01 03:24:16 +02:00
Franco Fichtner
f9d373c94a netmap: ring size limit not enough for multi-queue em(4)
Also mutes a spammy message.  Bravely going where no man
has gone before.  :)
2016-05-21 08:42:02 +02:00
Franco Fichtner
51aeb3f459 src: clean-cut move to release/10.3.0
Taken from: FreeBSD
Commit ref: b62280e683e2
2016-05-21 08:25:57 +02:00
Franco Fichtner
3f30d7b3bf netmap: ring size limit not enough for multi-queue em(4)
Bravely going where no man has gone before.  :)
2016-01-28 12:29:34 +01:00
Franco Fichtner
453fe71bf8 netmap: mute a spammy netmap message 2015-11-20 11:48:34 +01:00
Franco Fichtner
cd6ee62847 src: clean-cut move to 10.2-RELEASE
Start fresh on master, only apply needed patches on top now.

Upstream commit:	56279fdef34eb28a4655b489b992c651bd8379fc
Taken from:		FreeBSD
2015-08-14 14:15:00 +02:00
Franco Fichtner
87f480af48 *: upgrade to 10.1 as a bulk commit
Taken from: freebsd.git@29f4af53a2c8248b634f48923da8eb35f5ed0515
2015-02-10 19:21:02 +01:00
Franco Fichtner
402e7dde73 src: initial commit based on FreeBSD-10.0
Taken from:	https://github.com/freebsd/freebsd.git
Commit id:	d44ce30d3054a38723f89a161c5e003e64d1aaae
2014-11-09 09:30:14 +01:00