2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-28 12:58:00 +00:00

203 Commits

Author SHA1 Message Date
Joe Stringer
19c8e9c11b netdev-linux: Skip miimon execution when disabled
When dealing with a large number of ports, one of the performance
bottlenecks is that we loop through all netdevs in the main loop. Miimon
is a contributor to this, checking all devices even if it has never been
enabled.

This patch introduces a counter for the number of netdevs with miimon
configured. If this is 0, then we skip miimon_run() and miimon_wait().
In a test environment of 5000 internal ports and 50 tunnel ports with
bfd, this reduces CPU usage from about 50% to about 45%.

Signed-off-by: Joe Stringer <joestringer@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-11-02 20:53:10 -07:00
Alexandru Copot
7ba19d412a netdev: update IFF_LOOPBACK flag for linux and bsd devices
Signed-off-by: Alexandru Copot <alex.mihai.c@gmail.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-09-07 09:33:51 -07:00
Ben Pfaff
89454bf477 netdev: Fix deadlock when netdev_dump_queues() callback calls into netdev.
We have a call chain like this:

    iface_configure_qos() calls
        netdev_dump_queues(), which calls
            netdev_linux_dump_queues(), which calls back through 'cb' to
                qos_unixctl_show_cb(), which calls
                    netdev_delete_queue(), which calls
                        netdev_linux_delete_queue().

Both netdev_dump_queues() and netdev_linux_delete_queue() take the same
mutex in the same netdev, which deadlocks.

This commit fixes the problem by getting rid of the callback.

netdev_linux_dump_queue_stats() would benefit from the same treatment but
it's less urgent because I don't see any callbacks from that function that
call back into a netdev function.

Bug #19319.
Reported-by: Scott Hendricks <shendricks@vmware.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-08-27 21:50:40 -07:00
Ben Pfaff
834d6cafe4 Use "error-checking" mutexes in place of other kinds wherever possible.
We've seen a number of deadlocks in the tree since thread safety was
introduced.  So far, all of these are self-deadlocks, that is, a single
thread acquiring a lock and then attempting to re-acquire the same lock
recursively.  When this has happened, the process simply hung, and it was
somewhat difficult to find the cause.

POSIX "error-checking" mutexes check for this specific problem (and
others).  This commit switches from other types of mutexes to
error-checking mutexes everywhere that we can, that is, everywhere that
we're not using recursive mutexes.  This ought to help find problems more
quickly in the future.

There might be performance advantages to other kinds of mutexes in some
cases.  However, the existing mutex type choices were just guesses, so I'd
rather go for easy detection of errors until we know that other mutex
types actually perform better in specific cases.  Also, I did a quick
microbenchmark of glibc mutex types on my host and found that the
error checking mutexes weren't any slower than the other types, at least
when the mutex is uncontended.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-08-20 13:40:02 -07:00
Ben Pfaff
73371c09f9 netdev-linux: Fix self-deadlocks in traffic control code.
htb_parse_qdisc_details__(), which is called with the netdev mutex, called
netdev_get_mtu(), which tried to reacquire the mutex and thus deadlocked.
This commit fixes the problem and similar problems in
htb_parse_class_details__() and hfsc_parse_qdisc_details__().

Bug #19180.
Reported-by: Dhaval Badiani <dbadiani@vmware.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Andy Zhou <azhou@nicira.com>
2013-08-16 14:25:16 -07:00
Ben Pfaff
4f9f3f2135 netdev-linux: Avoid deadlock in netdev_linux_update_flags() for taps.
netdev_linux_set_etheraddr() would attempt to recursively acquire
netdev->mutex via netdev_linux_update_flags() for tap devices.

Reported-by: ZhengLingyun <konghuarukhr@163.com>
Tested-by: ZhengLingyun <konghuarukhr@163.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-08-10 20:42:50 -07:00
Ben Pfaff
38e0065b1f netdev-linux: Fix netdev leak in corner case.
Reported-by: Alex Wang <alexw@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-08-10 09:02:56 -07:00
Ben Pfaff
863838160e netdev: Make netdev access thread-safe.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Andy Zhou <azhou@nicira.com>
2013-08-09 21:34:02 -07:00
Ben Pfaff
cee8733832 netdev-linux: Use dedicated netlink notification socket.
The rtnetlink_link asynchronous netlink notifications seem somewhat
troublesome in a threaded environment.  It seems more straightforward
to have netdev-linux fend for itself.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-08-09 21:29:03 -07:00
Ben Pfaff
9dc63482bb netdev: Adopt four-step alloc/construct/destruct/dealloc lifecycle.
This is the same lifecycle used in the ofproto provider interface.
Compared to the previous netdev provider interface, it has the
advantage that the netdev top layer can control when any given
netdev becomes visible to the outside world.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-08-09 21:21:38 -07:00
Ben Pfaff
259e0b1ad1 netdev-linux, netdev-bsd: Make access to AF_INET socket thread-safe.
The only uses of 'af_inet_sock', in both drivers, were ioctls, so it seemed
like a good abstraction to write a function that just does such an ioctl,
and to factor out shared code into socket-util.

Signed-off-by: Ben Pfaff <blp@nicira.com>
CC: Ed Maste <emaste@freebsd.org>
2013-08-09 21:14:23 -07:00
Ben Pfaff
991e5fae57 netdev: Make netdev_from_name() take a reference to its returned netdev.
This API change is necessary for thread safety, to be added in an upcoming
commit.  Otherwise, the client would not be able to safely use the returned
netdev because it could already have been destroyed.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Andy Zhou <azhou@nicira.com>
2013-08-07 23:52:43 -07:00
Ben Pfaff
2f980d7417 netdev: Make netdev_get_devices() take a reference to each netdev.
This API change is necessary for thread safety, to be added in an upcoming
commit.  Otherwise, the client would not be able to actually use any of
the returned netdevs because they could already have been destroyed.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Andy Zhou <azhou@nicira.com>
2013-08-07 23:52:42 -07:00
Ben Pfaff
c22762302c netdev-linux: Move variable declaration inward in netdev_linux_cache_cb().
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Andy Zhou <azhou@nicira.com>
2013-08-07 23:40:32 -07:00
Ben Pfaff
887ed8b26f netdev-linux: Remove useless member 'peer', which was always zero.
Always, correct a comment on netdev_linux_get_features().

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Andy Zhou <azhou@nicira.com>
2013-08-07 23:40:32 -07:00
Ben Pfaff
1755ec4004 netdev-linux: Remove unused struct netdev_linux member.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Andy Zhou <azhou@nicira.com>
2013-08-07 23:40:32 -07:00
Ben Pfaff
d0d08f8aa5 netdev-linux: Remove pointless layers of indirection for tap devices.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Andy Zhou <azhou@nicira.com>
2013-08-07 23:40:31 -07:00
Ben Pfaff
15aee11695 netdev: Minor formatting improvements.
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-08-02 12:24:19 -07:00
Ben Pfaff
96172faa34 netdev-linux: Don't assume 'struct netdev' has offset 0.
The data items returned by netdev_get_devices() are "struct netdev *"s.
The code fixed up by this commit used them as "struct netdev_linux *",
which happens to work because struct netdev happens to be at offset 0 in
each struct but it's better to do a proper cast in case someday
struct netdev gets moved to a nonzero offset.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-08-02 12:24:18 -07:00
Ben Pfaff
2e5ae318d5 netdev-linux: Initialize change_seq for tap devices too.
change_seq is supposed to always be nonzero but tap devices got this wrong.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-08-02 12:24:18 -07:00
Ben Pfaff
f61d8d2931 netdev-linux: Fix fd leak on error path.
Found by inspection.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-08-02 12:24:18 -07:00
Ben Pfaff
6dc34a0dab Implement OpenFlow 1.3 queue stats duration feature.
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-07-26 10:20:04 -07:00
Alex Wang
db5a101931 clang: Fix the alignment warning.
This commit fixes the warning issued by 'clang' when pointer is casted
to one with greater alignment.

Signed-off-by: Alex Wang <alexw@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-07-23 12:34:41 -07:00
Ben Pfaff
2388211565 netdev-linux: Work on thread safety.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Andy Zhou <azhou@nicira.com>
2013-07-23 11:37:57 -07:00
Ben Pfaff
a88b4e0412 netlink-socket: Simplify use of transactions and dumps.
This disentangles "struct nl_dump" from "struct nl_sock", clearing the way
to make the use of either one thread-safe in an obviously correct manner.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-07-18 13:18:46 -07:00
ZhengLingyun
bb5c146881 netdev-linux: avoid negative value cast to non-negative in comparison
I am using a userspace OVS, there is a constant ERR message in log:
"dpif_netdev|ERR|error receiving data from ovs-netdev: Message too long"
Check the code and find there is a comparison between ssize_t and size_t type in
netdev_rx_linux_recv(). It makes the negative "retval" greater than the "size".

Change the sequence of comparison to avoid negative return value cast to
a positive and become greater then a non-negative value.

Signed-off-by: ZhengLingyun <konghuarukhr@163.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-07-18 11:13:43 -07:00
Ben Pfaff
10a89ef04d Replace all uses of strerror() by ovs_strerror(), for thread safety.
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-06-28 16:09:38 -07:00
Murphy McCauley
32383c3bd0 lib/netdev-linux.c: Prevent receiving of sent packets
Commit 796223f5 (netdev: Add new "struct netdev_rx" for capturing packets
from a netdev) refactored send and receive into separate netdevs.  As a
result, send and receive now use different socket descriptors (except for tap
interfaces which are treated specially).  An unintended side effect was that
all sent packets are looped back and received, which had previously been
avoided as the kernel specifically prevents this from happening on a single
socket descriptor.

To resolve the situation, a socket filter is added to the receive socket
so that it only accepts inbound packets.

Simon Horman co-discovered and initially reported this issue.

Signed-off-by: Murphy McCauley <murphy.mccauley@gmail.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
Tested-by: Simon Horman <horms@verge.net.au>
Reviewed-by: Simon Horman <horms@verge.net.au>
2013-06-13 14:43:29 -07:00
Ben Pfaff
bbd5b6f44b netdev-linux: Skip NETDEV_UP test in netdev_linux_set_etheraddr() for taps.
netdev_turn_flags_off() does nothing if the flags that one turns off are
already off.

Reported-by: Ethan Jackson <ethan@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-05-13 16:43:17 -07:00
Ben Pfaff
b5d57fc879 netdev: Get rid of netdev_dev.
The distinction between struct netdev_dev and struct netdev has always
been confusing.  Now that previous commits have eliminated all interesting
state from struct netdev, this commit deletes it and renames struct
netdev_dev to take its place.  Now the situation makes much more sense and
I won't have to continue making embarrassed explanations in the future.

Good riddance.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-05-10 14:46:15 -07:00
Ben Pfaff
180c6d0b44 Rename superclass members to 'up'.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-05-10 14:42:30 -07:00
Ben Pfaff
796223f5bc netdev: Add new "struct netdev_rx" for capturing packets from a netdev.
Separating packet capture from "struct netdev" means that there is no
remaining per-"struct netdev" state, which will allow us to get rid of
"struct netdev_dev" (by renaming it "struct netdev").

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-05-10 14:39:36 -07:00
Ben Pfaff
4b60911067 netdev: Factor restoring flags into new "struct netdev_saved_flags".
This gets rid of the only per-instance data in "struct netdev", which
will make it possible to merge "struct netdev_dev" into "struct netdev" in
a later commit.

Ed Maste wrote the netdev-bsd changes in this commit.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Co-authored-by: Ed Maste <emaste@freebsd.org>
Signed-off-by: Ed Maste <emaste@freebsd.org>
Tested-by: Ed Maste <emaste@freebsd.org>
2013-05-10 11:24:07 -07:00
Ben Pfaff
559eb2308b netdev-linux: Mark more static data as "const".
This makes this code more obviously thread-safe.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-05-03 13:29:47 -07:00
Ben Pfaff
c4c7a3d7a1 netdev-linux: Fix netdev_linux_send() return value in corner case.
A negative 'sock' means there was an error but netdev_linux_send() returns
a positive errno value on error.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-02-28 10:40:57 -08:00
Ben Pfaff
8450059ee8 netdev-linux: Check return value of set_nonblocking().
It's unlikely to fail but checking it can't hurt.

Found by Coverity.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-02-01 14:27:03 -08:00
Ethan Jackson
c060c4cf83 netdev-vport: Build on all platforms.
This patch removes the final bit of linux specific code which
prevents building netdev-vport everywhere.  With this, other
platforms automatically get access to patch ports, and (if their
datapath supports it), flow based tunneling.

Signed-off-by: Ethan Jackson <ethan@nicira.com>
2013-01-28 19:09:58 -08:00
Thomas Graf
e5c0801582 linux: Increase accuracy of ingress_policing_rate at low rates
The current method of calculating the ingress policer rate
can lead to inaccuracy if ingress_policing_rate is set to
a smallish values because the rate is divided by 8 first
which causes rounding errors.

Signed-off-by: Thomas Graf <tgraf@redhat.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-01-25 15:25:21 -08:00
Ben Pfaff
cb22974d77 Replace most uses of assert by ovs_assert.
This is a straight search-and-replace, except that I also removed #include
<assert.h> from each file where there were no assert calls left.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-01-16 16:03:37 -08:00
Ethan Jackson
f431bf7d78 netdev: Parse and make available tunnel configuration.
Future patches will need to know the details of a netdev's tunnel
configuration from outside the netdev library.

Signed-off-by: Ethan Jackson <ethan@nicira.com>
2013-01-15 16:21:09 -08:00
Ethan Jackson
275707c33f netdev: Rename get_drv_info() to get_status().
get_status() is a much more intuitive name since "status" is what
the database column is called.

Signed-off-by: Ethan Jackson <ethan@nicira.com>
2013-01-03 16:55:43 -08:00
Ethan Jackson
2f31a8229e netdev-vport: Remove set_stats() implementation.
The only user of netdev_set_stats() is bonding (for updating the
fake interface).  This interface is never a vport, so it seems
quite a bit cleaner to keep the relevant code in the netdev-linux
library where it's needed, instead of in netdev-vport, where it
adds needless complexity.

Signed-off-by: Ethan Jackson <ethan@nicira.com>
2012-12-26 13:01:33 -08:00
Ben Pfaff
ed36537ebf packets: Change IP_ARGS interface to take an ovs_be32 instead of a pointer.
An ovs_be32 is a more obvious way to represent an IP address than a
pointer to one.  It is also more type-safe, especially since "sparse" is
able to check that the argument is in network byte order.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2012-12-12 15:26:21 -08:00
Justin Pettit
33d82a56df netdev-linux: Use underlying tap device on netdev_linux_listen().
Commit acf608 (ofproto-dpif: Use a single underlying datapath across
multiple bridges.) broke connectivity to userspace datapath devices.
The code assumed the first caller to open a tap device with
netdev_linux_open() wanted to write to it.  This commit moves that logic
to when netdev_linux_listen() is called.

Thanks to Ben Pfaff for helping debug the issue.

Signed-off-by: Justin Pettit <jpettit@nicira.com>
Reported-by: Simon Horman <horms@verge.net.au>
Tested-by: Simon Horman <horms@verge.net.au>
2012-12-07 15:04:36 -08:00
Justin Pettit
bcb1f5a1fd netdev-linux: Don't log vport warnings when kernel datapath not loaded.
The *_get_stats functions call get_stats_via_vport(), which tries to get
information about ports attached to the kernel datapath.  When a pure
userspace switch is used (eg, the OVS kernel module isn't loaded), ports
are not attached to a kernel datapath, so warnings get logged.  This
commit handles that case and doesn't log a warning.  However, if the
kernel datapath is loaded, ports attached to a userspace datapath will
still log a warning.

Signed-off-by: Justin Pettit <jpettit@nicira.com>
2012-11-16 12:35:55 -08:00
Justin Pettit
7eb1bd8112 netdev-linux: "Down" tap devices before setting hw addr.
On Linux, it is not possible to set the mac address on "up" tap
interfaces.  This commit temporarily "down"s the interface so the
address can be set for the netdev_linux_set_etheraddr() call.

Signed-off-by: Justin Pettit <jpettit@nicira.com>
2012-11-16 12:35:55 -08:00
Ben Pfaff
d02a5f8ea4 ofproto: Report 0 Mbps when speed not available instead of 100 Mbps.
When a link is down, or when a link has no speed because it is not a
physical interface, Open vSwitch previously reported that its rate is 100
Mbps as a default.  This is counterintuitive, however, so this commit
changes Open vSwitch behavior to report 0 Mbps when a link is down or its
speed is otherwise unavailable.

Bug #13388.
Reported-by: Hiroshi Tanaka <htanaka@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-11-03 18:00:39 -07:00
Ben Pfaff
ebc56baa41 util: New macro CONST_CAST.
Casts are sometimes necessary.  One common reason that they are necessary
is for discarding a "const" qualifier.  However, this can impede
maintenance: if the type of the expression being cast changes, then the
presence of the cast can hide a necessary change in the code that does the
cast.  Using CONST_CAST, instead of a bare cast, makes these changes
visible.

Inspired by my own work elsewhere:
http://git.savannah.gnu.org/cgit/pspp.git/tree/src/libpspp/cast.h#n80

Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-08-03 13:33:13 -07:00
Ben Pfaff
ab985a77bb netdev-linux: Break ethtool coverage counter into "get" and "set" versions.
Reads and writes have difference performance implications so it's better to
separate them.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-06-21 08:00:08 -07:00
Ethan Jackson
79f1cbe9f8 lib: New data structure - smap.
A smap is a string to string hash map.  It has a cleaner interface
than shash's which were traditionally used for the same purpose.
This patch implements the data structure, and changes netdev and
its providers to use it.

Signed-off-by: Ethan Jackson <ethan@nicira.com>
2012-06-14 15:09:31 -07:00