2018-01-29 13:11:34 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
* Copyright 2017 6WIND S.A.
|
2018-03-20 19:20:35 +00:00
|
|
|
* Copyright 2017 Mellanox Technologies, Ltd
|
2017-07-18 12:48:14 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _RTE_ETH_FAILSAFE_PRIVATE_H_
|
|
|
|
#define _RTE_ETH_FAILSAFE_PRIVATE_H_
|
|
|
|
|
2018-08-31 09:01:07 +00:00
|
|
|
#include <stdint.h>
|
2017-07-18 12:48:17 +00:00
|
|
|
#include <sys/queue.h>
|
net/failsafe: fix hotplug races
Fail-safe uses a periodic alarm mechanism, running from the host
thread, to manage the hot-plug events of its sub-devices. This
management requires a lot of sub-devices PMDs operations
(stop, close, start, configure, etc.).
While the hot-plug alarm runs in the host thread, the application may
call fail-safe operations, which directly trigger the sub-devices PMDs
operations as well. This call may occur from any thread decided by the
application (probably the master thread).
Thus, more than one operation can be executed to a sub-device at the
same time. This can initiate a lot of races in the sub-PMDs.
Moreover, some control operations update the fail-safe internal
databases, which can be used by the alarm mechanism at the same time.
This can also initiate races and crashes.
Fail-safe is the owner of its sub-devices and must synchronize their
use according to the ETHDEV ownership rules.
Synchronize hot-plug management by a new lock mechanism uses a mutex to
atomically defend each critical section in the fail-safe hot-plug
mechanism and control operations to prevent any races between them.
Fixes: a46f8d5 ("net/failsafe: add fail-safe PMD")
Cc: stable@dpdk.org
Signed-off-by: Matan Azrad <matan@mellanox.com>
Acked-by: Gaetan Rivet <gaetan.rivet@6wind.com>
2018-02-12 20:51:42 +00:00
|
|
|
#include <pthread.h>
|
2017-07-18 12:48:17 +00:00
|
|
|
|
2017-07-18 12:48:20 +00:00
|
|
|
#include <rte_atomic.h>
|
2017-07-18 12:48:14 +00:00
|
|
|
#include <rte_dev.h>
|
2018-01-22 00:16:22 +00:00
|
|
|
#include <rte_ethdev_driver.h>
|
2017-07-18 12:48:14 +00:00
|
|
|
#include <rte_devargs.h>
|
2018-08-31 09:01:07 +00:00
|
|
|
#include <rte_flow.h>
|
2018-01-25 16:19:30 +00:00
|
|
|
#include <rte_interrupts.h>
|
2017-07-18 12:48:14 +00:00
|
|
|
|
|
|
|
#define FAILSAFE_DRIVER_NAME "Fail-safe PMD"
|
2018-01-22 16:38:22 +00:00
|
|
|
#define FAILSAFE_OWNER_NAME "Fail-safe"
|
2017-07-18 12:48:14 +00:00
|
|
|
|
|
|
|
#define PMD_FAILSAFE_MAC_KVARG "mac"
|
2017-07-18 12:48:15 +00:00
|
|
|
#define PMD_FAILSAFE_HOTPLUG_POLL_KVARG "hotplug_poll"
|
2017-07-18 12:48:14 +00:00
|
|
|
#define PMD_FAILSAFE_PARAM_STRING \
|
|
|
|
"dev(<ifc>)," \
|
2017-07-18 12:48:16 +00:00
|
|
|
"exec(<shell command>)," \
|
2018-01-18 13:51:40 +00:00
|
|
|
"fd(<fd number>)," \
|
2017-07-18 12:48:15 +00:00
|
|
|
"mac=mac_addr," \
|
|
|
|
"hotplug_poll=u64" \
|
2017-07-18 12:48:14 +00:00
|
|
|
""
|
|
|
|
|
2017-07-18 12:48:15 +00:00
|
|
|
#define FAILSAFE_HOTPLUG_DEFAULT_TIMEOUT_MS 2000
|
|
|
|
|
2017-07-18 12:48:14 +00:00
|
|
|
#define FAILSAFE_MAX_ETHPORTS 2
|
|
|
|
#define FAILSAFE_MAX_ETHADDR 128
|
|
|
|
|
2018-01-18 13:51:41 +00:00
|
|
|
#define DEVARGS_MAXLEN 4096
|
|
|
|
|
2018-01-25 16:19:32 +00:00
|
|
|
enum rxp_service_state {
|
|
|
|
SS_NO_SERVICE = 0,
|
|
|
|
SS_REGISTERED,
|
|
|
|
SS_READY,
|
|
|
|
SS_RUNNING,
|
|
|
|
};
|
|
|
|
|
2017-07-18 12:48:14 +00:00
|
|
|
/* TYPES */
|
|
|
|
|
2018-01-25 16:19:31 +00:00
|
|
|
struct rx_proxy {
|
|
|
|
/* epoll file descriptor */
|
|
|
|
int efd;
|
|
|
|
/* event vector to be used by epoll */
|
|
|
|
struct rte_epoll_event *evec;
|
2018-01-25 16:19:32 +00:00
|
|
|
/* rte service id */
|
|
|
|
uint32_t sid;
|
|
|
|
/* service core id */
|
|
|
|
uint32_t scid;
|
|
|
|
enum rxp_service_state sstate;
|
2018-01-25 16:19:31 +00:00
|
|
|
};
|
|
|
|
|
2017-07-18 12:48:14 +00:00
|
|
|
struct rxq {
|
|
|
|
struct fs_priv *priv;
|
|
|
|
uint16_t qid;
|
2017-12-19 17:14:29 +00:00
|
|
|
/* next sub_device to poll */
|
|
|
|
struct sub_device *sdev;
|
2017-07-18 12:48:14 +00:00
|
|
|
unsigned int socket_id;
|
2018-01-25 16:19:30 +00:00
|
|
|
int event_fd;
|
|
|
|
unsigned int enable_events:1;
|
2017-07-18 12:48:14 +00:00
|
|
|
struct rte_eth_rxq_info info;
|
2017-07-18 12:48:20 +00:00
|
|
|
rte_atomic64_t refcnt[];
|
2017-07-18 12:48:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct txq {
|
|
|
|
struct fs_priv *priv;
|
|
|
|
uint16_t qid;
|
|
|
|
unsigned int socket_id;
|
|
|
|
struct rte_eth_txq_info info;
|
2017-07-18 12:48:20 +00:00
|
|
|
rte_atomic64_t refcnt[];
|
2017-07-18 12:48:14 +00:00
|
|
|
};
|
|
|
|
|
2017-07-18 12:48:17 +00:00
|
|
|
struct rte_flow {
|
|
|
|
TAILQ_ENTRY(rte_flow) next;
|
|
|
|
/* sub_flows */
|
|
|
|
struct rte_flow *flows[FAILSAFE_MAX_ETHPORTS];
|
|
|
|
/* flow description for synchronization */
|
2018-08-31 09:01:07 +00:00
|
|
|
struct rte_flow_conv_rule rule;
|
|
|
|
uint8_t rule_data[];
|
2017-07-18 12:48:17 +00:00
|
|
|
};
|
|
|
|
|
2017-07-18 12:48:14 +00:00
|
|
|
enum dev_state {
|
|
|
|
DEV_UNDEFINED,
|
|
|
|
DEV_PARSED,
|
|
|
|
DEV_PROBED,
|
|
|
|
DEV_ACTIVE,
|
|
|
|
DEV_STARTED,
|
|
|
|
};
|
|
|
|
|
2017-10-21 20:54:46 +00:00
|
|
|
struct fs_stats {
|
|
|
|
struct rte_eth_stats stats;
|
|
|
|
uint64_t timestamp;
|
|
|
|
};
|
|
|
|
|
2017-07-18 12:48:14 +00:00
|
|
|
struct sub_device {
|
|
|
|
/* Exhaustive DPDK device description */
|
2017-12-19 17:14:29 +00:00
|
|
|
struct sub_device *next;
|
2017-07-18 12:48:14 +00:00
|
|
|
struct rte_devargs devargs;
|
|
|
|
struct rte_bus *bus;
|
|
|
|
struct rte_device *dev;
|
|
|
|
struct rte_eth_dev *edev;
|
2017-07-18 12:48:17 +00:00
|
|
|
uint8_t sid;
|
2017-07-18 12:48:14 +00:00
|
|
|
/* Device state machine */
|
|
|
|
enum dev_state state;
|
2017-09-07 11:31:13 +00:00
|
|
|
/* Last stats snapshot passed to user */
|
2017-10-21 20:54:46 +00:00
|
|
|
struct fs_stats stats_snapshot;
|
2017-07-18 12:48:16 +00:00
|
|
|
/* Some device are defined as a command line */
|
|
|
|
char *cmdline;
|
2018-01-18 13:51:40 +00:00
|
|
|
/* Others are retrieved through a file descriptor */
|
|
|
|
char *fd_str;
|
2017-07-18 12:48:20 +00:00
|
|
|
/* fail-safe device backreference */
|
2019-03-18 16:05:26 +00:00
|
|
|
uint16_t fs_port_id; /* shared between processes */
|
2017-07-18 12:48:20 +00:00
|
|
|
/* flag calling for recollection */
|
|
|
|
volatile unsigned int remove:1;
|
2017-07-18 12:48:22 +00:00
|
|
|
/* flow isolation state */
|
|
|
|
int flow_isolated:1;
|
2018-05-22 12:38:46 +00:00
|
|
|
/* RMV callback registration state */
|
|
|
|
unsigned int rmv_callback:1;
|
|
|
|
/* LSC callback registration state */
|
|
|
|
unsigned int lsc_callback:1;
|
2017-07-18 12:48:14 +00:00
|
|
|
};
|
|
|
|
|
2019-03-18 16:05:25 +00:00
|
|
|
/*
|
|
|
|
* This is referenced by eth_dev->data->dev_private
|
|
|
|
* This is shared between processes.
|
|
|
|
*/
|
2017-07-18 12:48:14 +00:00
|
|
|
struct fs_priv {
|
2019-03-18 16:05:25 +00:00
|
|
|
struct rte_eth_dev_data *data; /* backreference to shared data. */
|
2017-07-18 12:48:14 +00:00
|
|
|
/*
|
|
|
|
* Set of sub_devices.
|
|
|
|
* subs[0] is the preferred device
|
|
|
|
* any other is just another slave
|
|
|
|
*/
|
|
|
|
struct sub_device *subs;
|
|
|
|
uint8_t subs_head; /* if head == tail, no subs */
|
|
|
|
uint8_t subs_tail; /* first invalid */
|
|
|
|
uint8_t subs_tx; /* current emitting device */
|
|
|
|
uint8_t current_probed;
|
2017-07-18 12:48:17 +00:00
|
|
|
/* flow mapping */
|
|
|
|
TAILQ_HEAD(sub_flows, rte_flow) flow_list;
|
2017-07-18 12:48:14 +00:00
|
|
|
/* current number of mac_addr slots allocated. */
|
|
|
|
uint32_t nb_mac_addr;
|
|
|
|
struct ether_addr mac_addrs[FAILSAFE_MAX_ETHADDR];
|
|
|
|
uint32_t mac_addr_pool[FAILSAFE_MAX_ETHADDR];
|
2018-09-21 15:36:22 +00:00
|
|
|
uint32_t nb_mcast_addr;
|
|
|
|
struct ether_addr *mcast_addrs;
|
2017-07-18 12:48:14 +00:00
|
|
|
/* current capabilities */
|
|
|
|
struct rte_eth_dev_info infos;
|
2018-01-22 16:38:22 +00:00
|
|
|
struct rte_eth_dev_owner my_owner; /* Unique owner. */
|
2018-01-25 16:19:30 +00:00
|
|
|
struct rte_intr_handle intr_handle; /* Port interrupt handle. */
|
2017-07-18 12:48:15 +00:00
|
|
|
/*
|
|
|
|
* Fail-safe state machine.
|
|
|
|
* This level will be tracking state of the EAL and eth
|
|
|
|
* layer at large as defined by the user application.
|
|
|
|
* It will then steer the sub_devices toward the same
|
|
|
|
* synchronized state.
|
|
|
|
*/
|
|
|
|
enum dev_state state;
|
2017-09-07 11:31:13 +00:00
|
|
|
struct rte_eth_stats stats_accumulator;
|
2018-01-25 16:19:31 +00:00
|
|
|
/*
|
|
|
|
* Rx interrupts/events proxy.
|
|
|
|
* The PMD issues Rx events to the EAL on behalf of its subdevices,
|
|
|
|
* it does that by registering an event-fd for each of its queues with
|
2018-01-25 16:19:32 +00:00
|
|
|
* the EAL. A PMD service thread listens to all the Rx events from the
|
|
|
|
* subdevices, when an Rx event is issued by a subdevice it will be
|
|
|
|
* caught by this service with will trigger an Rx event in the
|
|
|
|
* appropriate failsafe Rx queue.
|
2018-01-25 16:19:31 +00:00
|
|
|
*/
|
|
|
|
struct rx_proxy rxp;
|
net/failsafe: fix hotplug races
Fail-safe uses a periodic alarm mechanism, running from the host
thread, to manage the hot-plug events of its sub-devices. This
management requires a lot of sub-devices PMDs operations
(stop, close, start, configure, etc.).
While the hot-plug alarm runs in the host thread, the application may
call fail-safe operations, which directly trigger the sub-devices PMDs
operations as well. This call may occur from any thread decided by the
application (probably the master thread).
Thus, more than one operation can be executed to a sub-device at the
same time. This can initiate a lot of races in the sub-PMDs.
Moreover, some control operations update the fail-safe internal
databases, which can be used by the alarm mechanism at the same time.
This can also initiate races and crashes.
Fail-safe is the owner of its sub-devices and must synchronize their
use according to the ETHDEV ownership rules.
Synchronize hot-plug management by a new lock mechanism uses a mutex to
atomically defend each critical section in the fail-safe hot-plug
mechanism and control operations to prevent any races between them.
Fixes: a46f8d5 ("net/failsafe: add fail-safe PMD")
Cc: stable@dpdk.org
Signed-off-by: Matan Azrad <matan@mellanox.com>
Acked-by: Gaetan Rivet <gaetan.rivet@6wind.com>
2018-02-12 20:51:42 +00:00
|
|
|
pthread_mutex_t hotplug_mutex;
|
|
|
|
/* Hot-plug mutex is locked by the alarm mechanism. */
|
|
|
|
volatile unsigned int alarm_lock:1;
|
2017-07-18 12:48:15 +00:00
|
|
|
unsigned int pending_alarm:1; /* An alarm is pending */
|
2017-07-18 12:48:22 +00:00
|
|
|
/* flow isolation state */
|
|
|
|
int flow_isolated:1;
|
2017-07-18 12:48:14 +00:00
|
|
|
};
|
|
|
|
|
2018-01-25 16:19:30 +00:00
|
|
|
/* FAILSAFE_INTR */
|
|
|
|
|
|
|
|
int failsafe_rx_intr_install(struct rte_eth_dev *dev);
|
|
|
|
void failsafe_rx_intr_uninstall(struct rte_eth_dev *dev);
|
2018-01-25 16:19:31 +00:00
|
|
|
int failsafe_rx_intr_install_subdevice(struct sub_device *sdev);
|
|
|
|
void failsafe_rx_intr_uninstall_subdevice(struct sub_device *sdev);
|
2018-01-25 16:19:30 +00:00
|
|
|
|
2017-07-18 12:48:15 +00:00
|
|
|
/* MISC */
|
|
|
|
|
|
|
|
int failsafe_hotplug_alarm_install(struct rte_eth_dev *dev);
|
|
|
|
int failsafe_hotplug_alarm_cancel(struct rte_eth_dev *dev);
|
|
|
|
|
2017-07-18 12:48:14 +00:00
|
|
|
/* RX / TX */
|
|
|
|
|
2018-10-08 22:31:40 +00:00
|
|
|
void failsafe_set_burst_fn(struct rte_eth_dev *dev, int force_safe);
|
2017-07-18 12:48:19 +00:00
|
|
|
|
2017-07-18 12:48:14 +00:00
|
|
|
uint16_t failsafe_rx_burst(void *rxq,
|
|
|
|
struct rte_mbuf **rx_pkts, uint16_t nb_pkts);
|
|
|
|
uint16_t failsafe_tx_burst(void *txq,
|
|
|
|
struct rte_mbuf **tx_pkts, uint16_t nb_pkts);
|
|
|
|
|
2017-07-18 12:48:19 +00:00
|
|
|
uint16_t failsafe_rx_burst_fast(void *rxq,
|
|
|
|
struct rte_mbuf **rx_pkts, uint16_t nb_pkts);
|
|
|
|
uint16_t failsafe_tx_burst_fast(void *txq,
|
|
|
|
struct rte_mbuf **tx_pkts, uint16_t nb_pkts);
|
|
|
|
|
2017-07-18 12:48:14 +00:00
|
|
|
/* ARGS */
|
|
|
|
|
|
|
|
int failsafe_args_parse(struct rte_eth_dev *dev, const char *params);
|
|
|
|
void failsafe_args_free(struct rte_eth_dev *dev);
|
|
|
|
int failsafe_args_count_subdevice(struct rte_eth_dev *dev, const char *params);
|
2017-07-18 12:48:16 +00:00
|
|
|
int failsafe_args_parse_subs(struct rte_eth_dev *dev);
|
2017-07-18 12:48:14 +00:00
|
|
|
|
|
|
|
/* EAL */
|
|
|
|
|
|
|
|
int failsafe_eal_init(struct rte_eth_dev *dev);
|
|
|
|
int failsafe_eal_uninit(struct rte_eth_dev *dev);
|
|
|
|
|
2017-07-18 12:48:15 +00:00
|
|
|
/* ETH_DEV */
|
|
|
|
|
|
|
|
int failsafe_eth_dev_state_sync(struct rte_eth_dev *dev);
|
2018-05-22 12:38:46 +00:00
|
|
|
void failsafe_eth_dev_unregister_callbacks(struct sub_device *sdev);
|
2017-07-18 12:48:20 +00:00
|
|
|
void failsafe_dev_remove(struct rte_eth_dev *dev);
|
2017-09-07 11:31:13 +00:00
|
|
|
void failsafe_stats_increment(struct rte_eth_stats *to,
|
|
|
|
struct rte_eth_stats *from);
|
2017-09-29 07:17:24 +00:00
|
|
|
int failsafe_eth_rmv_event_callback(uint16_t port_id,
|
2017-07-18 12:48:20 +00:00
|
|
|
enum rte_eth_event_type type,
|
|
|
|
void *arg, void *out);
|
2017-09-29 07:17:24 +00:00
|
|
|
int failsafe_eth_lsc_event_callback(uint16_t port_id,
|
2017-07-18 12:48:21 +00:00
|
|
|
enum rte_eth_event_type event,
|
|
|
|
void *cb_arg, void *out);
|
2018-05-10 23:58:35 +00:00
|
|
|
int failsafe_eth_new_event_callback(uint16_t port_id,
|
|
|
|
enum rte_eth_event_type event,
|
|
|
|
void *cb_arg, void *out);
|
2017-07-18 12:48:15 +00:00
|
|
|
|
2017-07-18 12:48:14 +00:00
|
|
|
/* GLOBALS */
|
|
|
|
|
|
|
|
extern const char pmd_failsafe_driver_name[];
|
|
|
|
extern const struct eth_dev_ops failsafe_ops;
|
2017-07-18 12:48:17 +00:00
|
|
|
extern const struct rte_flow_ops fs_flow_ops;
|
2018-10-28 23:57:39 +00:00
|
|
|
extern uint64_t failsafe_hotplug_poll;
|
|
|
|
extern int failsafe_mac_from_arg;
|
2017-07-18 12:48:14 +00:00
|
|
|
|
|
|
|
/* HELPERS */
|
|
|
|
|
|
|
|
/* dev: (struct rte_eth_dev *) fail-safe device */
|
|
|
|
#define PRIV(dev) \
|
|
|
|
((struct fs_priv *)(dev)->data->dev_private)
|
|
|
|
|
|
|
|
/* sdev: (struct sub_device *) */
|
|
|
|
#define ETH(sdev) \
|
|
|
|
((sdev)->edev)
|
|
|
|
|
|
|
|
/* sdev: (struct sub_device *) */
|
|
|
|
#define PORT_ID(sdev) \
|
|
|
|
(ETH(sdev)->data->port_id)
|
|
|
|
|
2017-07-18 12:48:17 +00:00
|
|
|
/* sdev: (struct sub_device *) */
|
|
|
|
#define SUB_ID(sdev) \
|
|
|
|
((sdev)->sid)
|
|
|
|
|
2017-07-18 12:48:14 +00:00
|
|
|
/**
|
|
|
|
* Stateful iterator construct over fail-safe sub-devices:
|
|
|
|
* s: (struct sub_device *), iterator
|
|
|
|
* i: (uint8_t), increment
|
|
|
|
* dev: (struct rte_eth_dev *), fail-safe ethdev
|
|
|
|
* state: (enum dev_state), minimum acceptable device state
|
|
|
|
*/
|
2017-08-23 13:05:30 +00:00
|
|
|
#define FOREACH_SUBDEV_STATE(s, i, dev, state) \
|
|
|
|
for (s = fs_find_next((dev), 0, state, &i); \
|
|
|
|
s != NULL; \
|
|
|
|
s = fs_find_next((dev), i + 1, state, &i))
|
2017-07-18 12:48:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Iterator construct over fail-safe sub-devices:
|
|
|
|
* s: (struct sub_device *), iterator
|
|
|
|
* i: (uint8_t), increment
|
|
|
|
* dev: (struct rte_eth_dev *), fail-safe ethdev
|
|
|
|
*/
|
|
|
|
#define FOREACH_SUBDEV(s, i, dev) \
|
|
|
|
FOREACH_SUBDEV_STATE(s, i, dev, DEV_UNDEFINED)
|
|
|
|
|
|
|
|
/* dev: (struct rte_eth_dev *) fail-safe device */
|
|
|
|
#define PREFERRED_SUBDEV(dev) \
|
|
|
|
(&PRIV(dev)->subs[0])
|
|
|
|
|
|
|
|
/* dev: (struct rte_eth_dev *) fail-safe device */
|
|
|
|
#define TX_SUBDEV(dev) \
|
|
|
|
(PRIV(dev)->subs_tx >= PRIV(dev)->subs_tail ? NULL \
|
|
|
|
: (PRIV(dev)->subs[PRIV(dev)->subs_tx].state < DEV_PROBED ? NULL \
|
|
|
|
: &PRIV(dev)->subs[PRIV(dev)->subs_tx]))
|
|
|
|
|
|
|
|
/**
|
|
|
|
* s: (struct sub_device *)
|
|
|
|
* ops: (struct eth_dev_ops) member
|
|
|
|
*/
|
|
|
|
#define SUBOPS(s, ops) \
|
|
|
|
(ETH(s)->dev_ops->ops)
|
|
|
|
|
2017-07-18 12:48:20 +00:00
|
|
|
/**
|
|
|
|
* Atomic guard
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* a: (rte_atomic64_t)
|
|
|
|
*/
|
|
|
|
#define FS_ATOMIC_P(a) \
|
2017-12-19 17:14:28 +00:00
|
|
|
rte_atomic64_set(&(a), 1)
|
2017-07-18 12:48:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* a: (rte_atomic64_t)
|
|
|
|
*/
|
|
|
|
#define FS_ATOMIC_V(a) \
|
2017-12-19 17:14:28 +00:00
|
|
|
rte_atomic64_set(&(a), 0)
|
2017-07-18 12:48:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* s: (struct sub_device *)
|
|
|
|
* i: uint16_t qid
|
|
|
|
*/
|
|
|
|
#define FS_ATOMIC_RX(s, i) \
|
|
|
|
rte_atomic64_read( \
|
2019-03-18 16:05:26 +00:00
|
|
|
&((struct rxq *) \
|
|
|
|
(fs_dev(s)->data->rx_queues[i]))->refcnt[(s)->sid])
|
2017-07-18 12:48:20 +00:00
|
|
|
/**
|
|
|
|
* s: (struct sub_device *)
|
|
|
|
* i: uint16_t qid
|
|
|
|
*/
|
|
|
|
#define FS_ATOMIC_TX(s, i) \
|
|
|
|
rte_atomic64_read( \
|
2019-03-18 16:05:26 +00:00
|
|
|
&((struct txq *) \
|
|
|
|
(fs_dev(s)->data->tx_queues[i]))->refcnt[(s)->sid])
|
2017-07-18 12:48:20 +00:00
|
|
|
|
2019-03-06 16:22:40 +00:00
|
|
|
#ifdef RTE_EXEC_ENV_FREEBSD
|
2018-02-13 21:23:35 +00:00
|
|
|
#define FS_THREADID_TYPE void*
|
|
|
|
#define FS_THREADID_FMT "p"
|
|
|
|
#else
|
|
|
|
#define FS_THREADID_TYPE unsigned long
|
|
|
|
#define FS_THREADID_FMT "lu"
|
|
|
|
#endif
|
|
|
|
|
2018-04-25 15:56:42 +00:00
|
|
|
extern int failsafe_logtype;
|
|
|
|
|
|
|
|
#define LOG__(l, m, ...) \
|
|
|
|
rte_log(RTE_LOG_ ## l, failsafe_logtype, \
|
|
|
|
"net_failsafe: " m "%c", __VA_ARGS__)
|
|
|
|
|
2017-07-18 12:48:14 +00:00
|
|
|
#define LOG_(level, ...) LOG__(level, __VA_ARGS__, '\n')
|
|
|
|
#define DEBUG(...) LOG_(DEBUG, __VA_ARGS__)
|
|
|
|
#define INFO(...) LOG_(INFO, __VA_ARGS__)
|
|
|
|
#define WARN(...) LOG_(WARNING, __VA_ARGS__)
|
|
|
|
#define ERROR(...) LOG_(ERR, __VA_ARGS__)
|
|
|
|
|
|
|
|
/* inlined functions */
|
|
|
|
|
2017-08-23 13:05:30 +00:00
|
|
|
static inline struct sub_device *
|
|
|
|
fs_find_next(struct rte_eth_dev *dev,
|
|
|
|
uint8_t sid,
|
|
|
|
enum dev_state min_state,
|
|
|
|
uint8_t *sid_out)
|
2017-07-18 12:48:14 +00:00
|
|
|
{
|
2017-08-23 13:05:30 +00:00
|
|
|
struct sub_device *subs;
|
|
|
|
uint8_t tail;
|
|
|
|
|
|
|
|
subs = PRIV(dev)->subs;
|
|
|
|
tail = PRIV(dev)->subs_tail;
|
|
|
|
while (sid < tail) {
|
|
|
|
if (subs[sid].state >= min_state)
|
2017-07-18 12:48:14 +00:00
|
|
|
break;
|
|
|
|
sid++;
|
|
|
|
}
|
2017-08-23 13:05:30 +00:00
|
|
|
*sid_out = sid;
|
|
|
|
if (sid >= tail)
|
|
|
|
return NULL;
|
|
|
|
return &subs[sid];
|
2017-07-18 12:48:14 +00:00
|
|
|
}
|
|
|
|
|
2019-03-18 16:05:26 +00:00
|
|
|
static inline struct rte_eth_dev *
|
|
|
|
fs_dev(struct sub_device *sdev) {
|
|
|
|
return &rte_eth_devices[sdev->fs_port_id];
|
|
|
|
}
|
|
|
|
|
net/failsafe: fix hotplug races
Fail-safe uses a periodic alarm mechanism, running from the host
thread, to manage the hot-plug events of its sub-devices. This
management requires a lot of sub-devices PMDs operations
(stop, close, start, configure, etc.).
While the hot-plug alarm runs in the host thread, the application may
call fail-safe operations, which directly trigger the sub-devices PMDs
operations as well. This call may occur from any thread decided by the
application (probably the master thread).
Thus, more than one operation can be executed to a sub-device at the
same time. This can initiate a lot of races in the sub-PMDs.
Moreover, some control operations update the fail-safe internal
databases, which can be used by the alarm mechanism at the same time.
This can also initiate races and crashes.
Fail-safe is the owner of its sub-devices and must synchronize their
use according to the ETHDEV ownership rules.
Synchronize hot-plug management by a new lock mechanism uses a mutex to
atomically defend each critical section in the fail-safe hot-plug
mechanism and control operations to prevent any races between them.
Fixes: a46f8d5 ("net/failsafe: add fail-safe PMD")
Cc: stable@dpdk.org
Signed-off-by: Matan Azrad <matan@mellanox.com>
Acked-by: Gaetan Rivet <gaetan.rivet@6wind.com>
2018-02-12 20:51:42 +00:00
|
|
|
/*
|
|
|
|
* Lock hot-plug mutex.
|
|
|
|
* is_alarm means that the caller is, for sure, the hot-plug alarm mechanism.
|
|
|
|
*/
|
|
|
|
static inline int
|
|
|
|
fs_lock(struct rte_eth_dev *dev, unsigned int is_alarm)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (is_alarm) {
|
|
|
|
ret = pthread_mutex_trylock(&PRIV(dev)->hotplug_mutex);
|
|
|
|
if (ret) {
|
|
|
|
DEBUG("Hot-plug mutex lock trying failed(%s), will try"
|
|
|
|
" again later...", strerror(ret));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
PRIV(dev)->alarm_lock = 1;
|
|
|
|
} else {
|
|
|
|
ret = pthread_mutex_lock(&PRIV(dev)->hotplug_mutex);
|
|
|
|
if (ret) {
|
|
|
|
ERROR("Cannot lock mutex(%s)", strerror(ret));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unlock hot-plug mutex.
|
|
|
|
* is_alarm means that the caller is, for sure, the hot-plug alarm mechanism.
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
fs_unlock(struct rte_eth_dev *dev, unsigned int is_alarm)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (is_alarm) {
|
|
|
|
RTE_ASSERT(PRIV(dev)->alarm_lock == 1);
|
|
|
|
PRIV(dev)->alarm_lock = 0;
|
|
|
|
}
|
|
|
|
ret = pthread_mutex_unlock(&PRIV(dev)->hotplug_mutex);
|
|
|
|
if (ret)
|
|
|
|
ERROR("Cannot unlock hot-plug mutex(%s)", strerror(ret));
|
|
|
|
}
|
|
|
|
|
2017-07-18 12:48:20 +00:00
|
|
|
/*
|
|
|
|
* Switch emitting device.
|
|
|
|
* If banned is set, banned must not be considered for
|
|
|
|
* the role of emitting device.
|
|
|
|
*/
|
2017-07-18 12:48:15 +00:00
|
|
|
static inline void
|
2017-07-18 12:48:20 +00:00
|
|
|
fs_switch_dev(struct rte_eth_dev *dev,
|
|
|
|
struct sub_device *banned)
|
2017-07-18 12:48:15 +00:00
|
|
|
{
|
2017-07-18 12:48:20 +00:00
|
|
|
struct sub_device *txd;
|
2017-07-18 12:48:15 +00:00
|
|
|
enum dev_state req_state;
|
|
|
|
|
|
|
|
req_state = PRIV(dev)->state;
|
2017-07-18 12:48:20 +00:00
|
|
|
txd = TX_SUBDEV(dev);
|
|
|
|
if (PREFERRED_SUBDEV(dev)->state >= req_state &&
|
|
|
|
PREFERRED_SUBDEV(dev) != banned) {
|
|
|
|
if (txd != PREFERRED_SUBDEV(dev) &&
|
|
|
|
(txd == NULL ||
|
2017-07-18 12:48:15 +00:00
|
|
|
(req_state == DEV_STARTED) ||
|
2017-07-18 12:48:20 +00:00
|
|
|
(txd && txd->state < DEV_STARTED))) {
|
2017-07-18 12:48:15 +00:00
|
|
|
DEBUG("Switching tx_dev to preferred sub_device");
|
|
|
|
PRIV(dev)->subs_tx = 0;
|
|
|
|
}
|
2017-07-18 12:48:20 +00:00
|
|
|
} else if ((txd && txd->state < req_state) ||
|
|
|
|
txd == NULL ||
|
|
|
|
txd == banned) {
|
2017-08-16 14:19:28 +00:00
|
|
|
struct sub_device *sdev = NULL;
|
2017-07-18 12:48:15 +00:00
|
|
|
uint8_t i;
|
|
|
|
|
|
|
|
/* Using acceptable device */
|
|
|
|
FOREACH_SUBDEV_STATE(sdev, i, dev, req_state) {
|
2017-07-18 12:48:20 +00:00
|
|
|
if (sdev == banned)
|
|
|
|
continue;
|
2017-07-18 12:48:15 +00:00
|
|
|
DEBUG("Switching tx_dev to sub_device %d",
|
|
|
|
i);
|
|
|
|
PRIV(dev)->subs_tx = i;
|
|
|
|
break;
|
|
|
|
}
|
2017-08-16 14:19:28 +00:00
|
|
|
if (i >= PRIV(dev)->subs_tail || sdev == NULL) {
|
|
|
|
DEBUG("No device ready, deactivating tx_dev");
|
|
|
|
PRIV(dev)->subs_tx = PRIV(dev)->subs_tail;
|
|
|
|
}
|
2017-07-18 12:48:15 +00:00
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
2018-10-08 22:31:40 +00:00
|
|
|
failsafe_set_burst_fn(dev, 0);
|
2017-07-18 12:48:15 +00:00
|
|
|
rte_wmb();
|
|
|
|
}
|
|
|
|
|
2018-01-20 21:12:24 +00:00
|
|
|
/*
|
|
|
|
* Adjust error value and rte_errno to the fail-safe actual error value.
|
|
|
|
*/
|
|
|
|
static inline int
|
|
|
|
fs_err(struct sub_device *sdev, int err)
|
|
|
|
{
|
|
|
|
/* A device removal shouldn't be reported as an error. */
|
|
|
|
if (sdev->remove == 1 || err == -EIO)
|
|
|
|
return rte_errno = 0;
|
|
|
|
return err;
|
|
|
|
}
|
2017-07-18 12:48:14 +00:00
|
|
|
#endif /* _RTE_ETH_FAILSAFE_PRIVATE_H_ */
|