History

RDMA/siw: Fix passive connection establishment

Holding the rtnl_lock while iterating a devices interface address list potentially causes deadlocks with the cma_netdev_callback. While this was implemented to limit the scope of a wildcard listen to addresses of the current device only, a better solution limits the scope of the socket to the device. This completely avoiding locking, and also results in significant code simplification.

Bernard Metzler committed 6 years ago

Commit 33fb27f1 parent 79db7841 file · +31 −106Browse files

Unified · Split

drivers/infiniband/sw/siw/siw_cm.c+31−106
@@ -1769,14 +1769,23 @@ int siw_reject(struct iw_cm_id *id, const void *pdata, u8 pd_len) · 1768 unmodified lines
17691769 return 0;
17701770 }
17711771
1772−static int siw_listen_address(struct iw_cm_id *id, int backlog,
1773− struct sockaddr *laddr, int addr_family)
1772+/*
1773+ * siw_create_listen - Create resources for a listener's IWCM ID @id
1774+ *
1775+ * Starts listen on the socket address id->local_addr.
1776+ *
1777+ */
1778+int siw_create_listen(struct iw_cm_id *id, int backlog)
17741779 {
17751780 struct socket *s;
17761781 struct siw_cep *cep = NULL;
17771782 struct siw_device *sdev = to_siw_dev(id->device);
1783+ int addr_family = id->local_addr.ss_family;
17781784 int rv = 0, s_val;
17791785
1786+ if (addr_family != AF_INET && addr_family != AF_INET6)
1787+ return -EAFNOSUPPORT;
1788+
17801789 rv = sock_create(addr_family, SOCK_STREAM, IPPROTO_TCP, &s);
17811790 if (rv < 0)
17821791 return rv;
@@ -1791,9 +1800,25 @@ static int siw_listen_address(struct iw_cm_id *id, int backlog, · 8 unmodified lines
17911800 siw_dbg(id->device, "setsockopt error: %d\n", rv);
17921801 goto error;
17931802 }
1794− rv = s->ops->bind(s, laddr, addr_family == AF_INET ?
1795− sizeof(struct sockaddr_in) :
1796− sizeof(struct sockaddr_in6));
1803+ if (addr_family == AF_INET) {
1804+ struct sockaddr_in *laddr = &to_sockaddr_in(id->local_addr);
1805+
1806+ /* For wildcard addr, limit binding to current device only */
1807+ if (ipv4_is_zeronet(laddr->sin_addr.s_addr))
1808+ s->sk->sk_bound_dev_if = sdev->netdev->ifindex;
1809+
1810+ rv = s->ops->bind(s, (struct sockaddr *)laddr,
1811+ sizeof(struct sockaddr_in));
1812+ } else {
1813+ struct sockaddr_in6 *laddr = &to_sockaddr_in6(id->local_addr);
1814+
1815+ /* For wildcard addr, limit binding to current device only */
1816+ if (ipv6_addr_any(&laddr->sin6_addr))
1817+ s->sk->sk_bound_dev_if = sdev->netdev->ifindex;
1818+
1819+ rv = s->ops->bind(s, (struct sockaddr *)laddr,
1820+ sizeof(struct sockaddr_in6));
1821+ }
17971822 if (rv) {
17981823 siw_dbg(id->device, "socket bind error: %d\n", rv);
17991824 goto error;
@@ -1852,7 +1877,7 @@ static int siw_listen_address(struct iw_cm_id *id, int backlog, · 52 unmodified lines
18521877 list_add_tail(&cep->listenq, (struct list_head *)id->provider_data);
18531878 cep->state = SIW_EPSTATE_LISTENING;
18541879
1855− siw_dbg(id->device, "Listen at laddr %pISp\n", laddr);
1880+ siw_dbg(id->device, "Listen at laddr %pISp\n", &id->local_addr);
18561881
18571882 return 0;
18581883
@@ -1910,106 +1935,6 @@ static void siw_drop_listeners(struct iw_cm_id *id) · 51 unmodified lines
19101935 }
19111936 }
19121937
1913−/*
1914− * siw_create_listen - Create resources for a listener's IWCM ID @id
1915− *
1916− * Listens on the socket address id->local_addr.
1917− *
1918− * If the listener's @id provides a specific local IP address, at most one
1919− * listening socket is created and associated with @id.
1920− *
1921− * If the listener's @id provides the wildcard (zero) local IP address,
1922− * a separate listen is performed for each local IP address of the device
1923− * by creating a listening socket and binding to that local IP address.
1924− *
1925− */
1926−int siw_create_listen(struct iw_cm_id *id, int backlog)
1927−{
1928− struct net_device *dev = to_siw_dev(id->device)->netdev;
1929− int rv = 0, listeners = 0;
1930−
1931− siw_dbg(id->device, "backlog %d\n", backlog);
1932−
1933− /*
1934− * For each attached address of the interface, create a
1935− * listening socket, if id->local_addr is the wildcard
1936− * IP address or matches the IP address.
1937− */
1938− if (id->local_addr.ss_family == AF_INET) {
1939− struct in_device *in_dev = in_dev_get(dev);
1940− struct sockaddr_in s_laddr;
1941− const struct in_ifaddr *ifa;
1942−
1943− if (!in_dev) {
1944− rv = -ENODEV;
1945− goto out;
1946− }
1947− memcpy(&s_laddr, &id->local_addr, sizeof(s_laddr));
1948−
1949− siw_dbg(id->device, "laddr %pISp\n", &s_laddr);
1950−
1951− rtnl_lock();
1952− in_dev_for_each_ifa_rtnl(ifa, in_dev) {
1953− if (ipv4_is_zeronet(s_laddr.sin_addr.s_addr) ||
1954− s_laddr.sin_addr.s_addr == ifa->ifa_address) {
1955− s_laddr.sin_addr.s_addr = ifa->ifa_address;
1956−
1957− rv = siw_listen_address(id, backlog,
1958− (struct sockaddr *)&s_laddr,
1959− AF_INET);
1960− if (!rv)
1961− listeners++;
1962− }
1963− }
1964− rtnl_unlock();
1965− in_dev_put(in_dev);
1966− } else if (id->local_addr.ss_family == AF_INET6) {
1967− struct inet6_dev *in6_dev = in6_dev_get(dev);
1968− struct inet6_ifaddr *ifp;
1969− struct sockaddr_in6 *s_laddr = &to_sockaddr_in6(id->local_addr);
1970−
1971− if (!in6_dev) {
1972− rv = -ENODEV;
1973− goto out;
1974− }
1975− siw_dbg(id->device, "laddr %pISp\n", &s_laddr);
1976−
1977− rtnl_lock();
1978− list_for_each_entry(ifp, &in6_dev->addr_list, if_list) {
1979− if (ifp->flags & (IFA_F_TENTATIVE | IFA_F_DEPRECATED))
1980− continue;
1981− if (ipv6_addr_any(&s_laddr->sin6_addr) ||
1982− ipv6_addr_equal(&s_laddr->sin6_addr, &ifp->addr)) {
1983− struct sockaddr_in6 bind_addr = {
1984− .sin6_family = AF_INET6,
1985− .sin6_port = s_laddr->sin6_port,
1986− .sin6_flowinfo = 0,
1987− .sin6_addr = ifp->addr,
1988− .sin6_scope_id = dev->ifindex };
1989−
1990− rv = siw_listen_address(id, backlog,
1991− (struct sockaddr *)&bind_addr,
1992− AF_INET6);
1993− if (!rv)
1994− listeners++;
1995− }
1996− }
1997− rtnl_unlock();
1998− in6_dev_put(in6_dev);
1999− } else {
2000− rv = -EAFNOSUPPORT;
2001− }
2002−out:
2003− if (listeners)
2004− rv = 0;
2005− else if (!rv)
2006− rv = -EINVAL;
2007−
2008− siw_dbg(id->device, "%s\n", rv ? "FAIL" : "OK");
2009−
2010− return rv;
2011−}
2012−
20131938 int siw_destroy_listen(struct iw_cm_id *id)
20141939 {
20151940 if (!id->provider_data) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t