aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/netmap
Commit message (Collapse)AuthorAgeFilesLines
* netmap: Make memory pools NUMA-awareMark Johnston2024-10-284-25/+64
| | | | | | | | | | | | | | | | | | | | | | | | | | | Each netmap adapter associated with a physical adapter is attached to a netmap memory pool. contigmalloc() is used to allocate physically contiguous memory for the pool, but ideally we would ensure that all such memory is allocated from the NUMA domain local to the adapter. Augment netmap's memory pools with a NUMA domain ID, similar to how IOMMU groups are handled in the Linux port. That is, when attaching to a physical adapter, ensure that the associated memory pools are local to the adapter's associated memory domain, creating new pools as needed. Some types of ifnets do not have any defined NUMA affinity; in this case the domain ID in question is the sentinel value -1. Add a sysctl, dev.netmap.port_numa_affinity, which can be used to enable the new behaviour. Keep it disabled by now to avoid surprises in case netmap applications are relying on zero-copy optimizations to forward packets between ports belonging to different NUMA domains. Reviewed by: vmaffione MFC after: 2 weeks Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D46666 (cherry picked from commit 1bae9dc584272dd75dc4e04cb5d73be0e9fb562a)
* netmap: Make the memory ops function pointer table constMark Johnston2024-10-041-4/+4
| | | | | | | | | | | No functional change intended. Reviewed by: vmaffione MFC after: 2 weeks Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D46664 (cherry picked from commit 1ae4951ba7bb203d9a29892792960f0869759d35)
* net: Remove unneeded NULL check for the allocated ifnetZhenlei Huang2024-07-122-10/+0
| | | | | | | | | | | | | Change 4787572d0580 made if_alloc_domain() never fail, then also do the wrappers if_alloc(), if_alloc_dev(), and if_gethandle(). No functional change intended. Reviewed by: kp, imp, glebius, stevek MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D45740 (cherry picked from commit aa3860851b9f6a6002d135b1cac7736e0995eedc)
* netmap: Use device_set_descf()Mark Johnston2024-06-271-5/+1
| | | | | | | | No functional change intended. MFC after: 1 week (cherry picked from commit 44d36c9731c172977ad8a95a09c0d6fbddcc9b2f)
* netmap: Ignore errors in CSB_WRITE()Mark Johnston2024-01-041-2/+13
| | | | | | | | | | | | | | | | The CSB_WRITE() and _READ() macros respectively write to and read from userspace memory and so can in principle fault. However, we do not check for errors and will proceed blindly if they fail. Add assertions to verify that they do not. This is in preparation for annotating copyin() and related functions with __result_use_check. Reviewed by: vmaffione MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D43200 (cherry picked from commit 99efa2c88d93c6272a8f54b18d18d0fd9d60f137)
* sys: Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-164-8/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* sys: Remove $FreeBSD$: one-line .c comment patternWarner Losh2023-08-165-5/+0
| | | | Remove /^/[*/]\s*\$FreeBSD\$.*\n/
* sys: Remove $FreeBSD$: one-line .h patternWarner Losh2023-08-168-8/+0
| | | | Remove /^\s*\*+\s*\$FreeBSD\$.*$\n/
* sys: Remove $FreeBSD$: two-line .h patternWarner Losh2023-08-163-6/+0
| | | | Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-1214-14/+14
| | | | | | | | | The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch up to that fact and revert to their recommended match of BSD-2-Clause. Discussed with: pfg MFC After: 3 days Sponsored by: Netflix
* netmap: Handle packet batches in generic modeMark Johnston2023-04-051-4/+11
| | | | | | | | | | | | ifnets are allowed to pass batches of multiple packets to if_input, linked by the m_nextpkt pointer. iflib_rxeof() sometimes does this, for example. Netmap's generic mode did not handle this and would only deliver the first packet in the batch, leaking the rest. PR: 270636 Reviewed by: vmaffione MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D39426
* netmap: Fix queue stalls with generic interfacesMark Johnston2023-04-053-39/+107
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In emulated mode, the FreeBSD netmap port attempts to perform zero-copy transmission. This works as follows: the kernel ring is populated with mbuf headers to which netmap buffers are attached. When transmitting, the mbuf refcount is initialized to 2, and when the counter value has been decremented to 1 netmap infers that the driver has freed the mbuf and thus transmission is complete. This scheme does not generalize to the situation where netmap is attaching to a software interface which may transmit packets among multiple "queues", as is the case with bridge or lagg interfaces. In that case, we would be relying on backing hardware drivers to free transmitted mbufs promptly, but this isn't guaranteed; a driver may reasonably defer freeing a small number of transmitted buffers indefinitely. If such a buffer ends up at the tail of a netmap transmit ring, further transmits can end up blocked indefinitely. Fix the problem by removing the zero-copy scheme (which is also not implemented in the Linux port of netmap). Instead, the kernel ring is populated with regular mbuf clusters into which netmap buffers are copied by nm_os_generic_xmit_frame(). The refcounting scheme is preserved, and this lets us avoid allocating a fresh cluster per transmitted packet in the common case. If the transmit ring is full, a callout is used to free the "stuck" mbuf, avoiding the queue deadlock described above. Furthermore, when recycling mbuf clusters, be sure to fully reinitialize the mbuf header instead of simply re-setting M_PKTHDR. Some software interfaces, like if_vlan, may set fields in the header which should be reset before the mbuf is reused. Reviewed by: vmaffione MFC after: 1 month Sponsored by: Zenarmor Sponsored by: OPNsense Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D38065
* netmap: fix copyin/copyout of nmreq options listVincenzo Maffione2023-03-211-27/+42
| | | | | | | | | | | | | | | | | | | The previous code unsuccesfully attempted to report a precise error for each option in the user list. Moreover, commit 253b2ec199b broke some ctrl-api-test (see https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=260547). With this patch we bail out as soon as an unrecoverable error is detected and we properly check for copy boundaries. EOPNOTSUPP no longer immediately returns an error, so that any other option in the list may be examined by the caller code and a precise report of the (un)supported options can be returned to the user. With this patch, all ctrl-api-test unit tests pass again. PR: 260547 Submitted by: giuseppe.lettieri@unipi.it Reviewed by: vmaffione MFC after: 14 days
* netmap: get rid of save_if_input for emulated adaptersVincenzo Maffione2023-03-142-21/+2
| | | | | | | | | | | | | The save_if_input function pointer was meant to save the previous value of ifp->if_input before replacing it with the emulated adapter hook. However, the same pointer value is already stored in the if_input field of the netmap_adapter struct, to be used for host TX ring processing. Reuse the netmap_adapter if_input field to simplify the code and save some space. MFC after: 14 days
* netmap: get rid of WNA() macroVincenzo Maffione2023-03-112-9/+4
| | | | MFC after: 7 days
* netmap: Remove obsolete compatibility definesMark Johnston2023-03-091-5/+0
| | | | | | | | No functional change intended. Reviewed by: vmaffione MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D39001
* Mechanically convert netmap(4) to IfAPIJustin Hibbits2023-02-1416-196/+194
| | | | | | Reviewed by: vmaffione, zlei Sponsored by: Juniper Networks, Inc. Differential Revision: https://reviews.freebsd.org/D37814
* netmap: drop redundant if_mtu assignmentVincenzo Maffione2023-02-081-1/+0
| | | | | Reported by: zlei MFC after 3 days
* netmap: Try to count packet drops in emulated modeMark Johnston2023-01-232-1/+5
| | | | | | | | | | | | | | | Right now we have little visibility into packet drops within netmap. Start trying to make packet loss issues more visible by counting queue drops in the transmit path, and in the input path for interfaces running in emulated mode, where we place received packets in a bounded software queue that is processed by rxsync. Reviewed by: vmaffione MFC after: 1 week Sponsored by: Zenarmor Sponsored by: OPNsense Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D38064
* netmap: Correct a commentMark Johnston2023-01-231-1/+1
| | | | | | | | | Reviewed by: vmaffione MFC after: 1 week Sponsored by: Zenarmor Sponsored by: OPNsense Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D38063
* netmap: Fix a queue length check in the generic port rx pathMark Johnston2023-01-231-1/+1
| | | | | | | | | | | | | The check is ok by default, since the default value of netmap_generic_ringsize is 1024. But we should check against the configured "ring" size. Reviewed by: vmaffione MFC after: 1 week Sponsored by: Zenarmor Sponsored by: OPNsense Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D38062
* netmap: Tell the compiler to avoid reloading ring indicesMark Johnston2023-01-231-4/+4
| | | | | | | | | | | | | | | Per the removed comments these fields should be loaded only once, since they can in principle be modified concurrently, though this would be a violation of the userspace contract with netmap. No functional change intended. Reviewed by: vmaffione MFC after: 1 week Sponsored by: Zenarmor Sponsored by: OPNsense Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D38061
* if_lagg: Allow lagg interfaces to be used with netmapTom Jones2023-01-131-0/+4
| | | | | | | | Reviewed by: zlei Sponsored by: Zenarmor Sponsored by: OPNsense Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D37436
* netmap: monitor: add missing netmap_adapter_put()Vincenzo Maffione2022-12-241-0/+2
| | | | MFC after: 7 days
* debug_put_get: don't crash on null pointersVincenzo Maffione2022-12-241-3/+6
| | | | MFC after: 7 days
* monitor: fix cb restore when monitored adapter unregistersVincenzo Maffione2022-12-241-6/+6
| | | | | | | | netmap_monitor_stop() called nm_monitor_none() after the head of the zero-copy monitors had been reset, thus thinking that there was nothing left to do. MFC after: 7 days
* netmap: drop compatibility FreeBSD codeVincenzo Maffione2022-12-244-117/+1
| | | | | | | | | Netmap users on FreeBSD are not supposed to import code from the github netmap repository anymore. They should use the code that is available in the src repo. We can therefore drop the compatibility code. MFC after: 7 days
* netmap_update_config: update na->name to cope with reconfigurationsVincenzo Maffione2022-12-033-1/+6
| | | | MFC after: 1 week
* sys: Nuke double-semicolonsElliott Mitchell2022-11-021-1/+1
| | | | | | | | | A distinct number of double-semicolons have ended up in FreeBSD. Take a pass at getting rid of many of these harmless typos. Reviewed by: emaste, rrs Pull Request: https://github.com/freebsd/freebsd-src/pull/609 Differential Revision: https://reviews.freebsd.org/D31716
* netmap(4): Remove a double word in a source code commentGordon Bergling2022-09-041-1/+1
| | | | | | - s/the the/the/ MFC after: 3 days
* Fix unused variable warning in if_re_netmap.hDimitry Andric2022-07-211-2/+1
| | | | | | | | | | | | | With clang 15, the following -Werror warning is produced: sys/dev/netmap/if_re_netmap.h:179:8: error: variable 'n' set but not used [-Werror,-Wunused-but-set-variable] u_int n; ^ The 'n' variable appears to have been a debugging aid that has never been used for anything, so remove it. MFC after: 3 days
* netmap: Remove unused devclass arguments to DRIVER_MODULE.John Baldwin2022-05-102-6/+4
|
* netmap: Move more_txspace and some_recvd under #ifdef SYNC_KLOOP_POLL.John Baldwin2022-04-091-0/+8
|
* netmap: Fix TOCTOU vulnerability in nmreq_copyinVincenzo Maffione2022-03-161-34/+17
| | | | | | | | | | The total size of the user-provided nmreq was first computed and then trusted during the copyin. This might lead to kernel memory corruption and escape from jails/containers. Reported by: Lucas Leong (@_wmliang_) of Trend Micro Zero Day Initiative Security: CVE-2022-23084 MFC after: 3 days
* netmap: Fix integer overflow in nmreq_copyinVincenzo Maffione2022-03-161-2/+12
| | | | | | | | | | An unsanitized field in an option could be abused, causing an integer overflow followed by kernel memory corruption. This might be used to escape jails/containers. Reported by: Reno Robert and Lucas Leong (@_wmliang_) of Trend Micro Zero Day Initiative Security: CVE-2022-23085
* netmap: add a tunable for the maximum number of VALE switchesVincenzo Maffione2022-03-063-7/+14
| | | | | | | | The new dev.netmap.max_bridges sysctl tunable can be set in loader.conf(5) to change the default maximum number of VALE switches that can be created. Current defaults is 8. MFC after: 2 weeks
* netmap: fix refcount bug in netmap allocatorVincenzo Maffione2022-03-062-5/+7
| | | | | | | | | | | | | Symptom: when a single extmem memory region is provided to netmap multiple times, for multiple interfaces, the memory region is never released by netmap once all the existing file descriptors are closed. Fix the relevant condition in netmap_mem_drop(): release the memory when the last user of netmap_adapter is gone, rather then when the last user of netmap_mem_d is gone. MFC after: 2 weeks
* netmap: fix uint32_t overflow in pool size calculationVincenzo Maffione2021-09-261-1/+1
| | | | MFC after: 1 week
* netmap: monitor: support offsets in copy modeVincenzo Maffione2021-09-261-5/+7
|
* netmap: import changes from upstreamVincenzo Maffione2021-08-223-18/+35
| | | | | | | | | | | | | | | | - make sure rings are disabled during resets - introduce netmap_update_hostrings_mode(), with support for multiple host rings - always initialize ni_bufs_head in netmap_if ni_bufs_head was not properly initialized when no external buffers were requestedx and contained the ni_bufs_head from the last request. This was causing spurious buffer frees when alternating between apps that used external buffers and apps that did not use them. - check na validitity under lock on detach - netmap_mem: fix leak on error path - nm_dispatch: fix compilation on Raspberry Pi MFC after: 2 weeks
* netmap: use safer defaults for hwbuf_lenVincenzo Maffione2021-04-181-14/+32
| | | | | | | | | | | | | | | | | | | | | | | We must make sure that incoming packets will never overflow the netmap buffers, even when the user is using the offset feature. In the typical scenario, the netmap buffer is 2KiB and, with an MTU of 1500, there are ~500 bytes available for user offsets. Unfortunately, some NICs accept incoming packets even when they are larger then the MTU. This means that the only way to stop DMA from overflowing the netmap buffers, when offsets are allowed, is to choose a hardware buffer length which is smaller than the netmap buffer length. For most NICs and for 2KiB netmap buffers, this means 1024 bytes, which is unconveniently small. The current code will select the small hardware buf size even when offsets are not in use. The main purpose of this change is to fix this bug by returning to the normal behavior for the no-offsets case. At the same time, the patch pushes the handling of the offset case to the lower level driver code, so that it can be made NIC-specific (in future patches).
* wpa: Import wpa_supplicant/hostapd commit f91680c15Cy Schubert2021-04-172-30/+12
| | | | | | | | | | | | This is the April update to vendor/wpa committed upstream 2021/04/07. This is MFV efec8223892b3e677acb46eae84ec3534989971f. Suggested by: philip Reviewed by: philip MFC after: 2 months Differential Revision: https://reviews.freebsd.org/D29744
* netmap: make sure rings are disabled during resetsVincenzo Maffione2021-04-172-12/+30
| | | | | | | | Explicitly disable ring synchronization before calling callbacks that may result in a hardware reset. Before this patch we relied on capturing the down/up events which, however, may not be issued by all drivers.
* netmap: don't use linux type struct device *Vincenzo Maffione2021-04-111-2/+2
| | | | | | | | | Such type cannot be used in code that is in common between FreeBSD and Linux. Use the FreeBSD type instead. MFC after: 3 days Reported by: markj Differential Revision: https://reviews.freebsd.org/D29677
* netmap: vtnet: remove unused variableVincenzo Maffione2021-04-091-2/+1
| | | | Reported by: bdragon
* netmap: vtnet: add support for netmap offsetsVincenzo Maffione2021-04-071-6/+10
| | | | | Follow-up change to a6d768d845c173823785c71bb18b40074e7a8998. This change adds support for netmap offsets.
* netmap: several typo fixesVincenzo Maffione2021-04-0211-37/+37
| | | | No functional changes intended.
* netmap: fix typo bug in netmap_compute_buf_lenVincenzo Maffione2021-04-022-2/+2
|
* netmap: monitor: add a flag to distinguish packet directionVincenzo Maffione2021-03-291-2/+6
| | | | | | | | The netmap monitor intercepts any TX/RX packets on the monitored port. However, before this change there was no way to tell whether an intercepted packet was being transmitted or received on the monitored port. A TXMON flag in the netmap slot has been added for this purpose.
* netmap: add kernel support for the "offsets" featureVincenzo Maffione2021-03-2911-325/+853
| | | | | | | | | | | | | This feature enables applications to ask netmap to transmit or receive packets starting at a user-specified offset from the beginning of the netmap buffer. This is meant to ease those packet manipulation operations such as pushing or popping packet headers, that may be useful to implement software switches, routers and other packet processors. To use the feature, drivers (e.g., iflib, vtnet, etc.) must have explicit support. This change does not add support for any driver, but introduces the necessary kernel changes. However, offsets support is already included for VALE ports and pipes.