From patchwork Wed Jul 26 14:52:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcel Apfelbaum X-Patchwork-Id: 9865225 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3F923602B1 for ; Wed, 26 Jul 2017 14:53:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 43F0328628 for ; Wed, 26 Jul 2017 14:53:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 38AAA2861B; Wed, 26 Jul 2017 14:53:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF1AF2861B for ; Wed, 26 Jul 2017 14:53:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751756AbdGZOxr (ORCPT ); Wed, 26 Jul 2017 10:53:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47812 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751753AbdGZOxq (ORCPT ); Wed, 26 Jul 2017 10:53:46 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 444EFC081F2D; Wed, 26 Jul 2017 14:53:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 444EFC081F2D Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcel@redhat.com Received: from localhost.localdomain (unknown [10.35.206.42]) by smtp.corp.redhat.com (Postfix) with ESMTP id C1028934E9; Wed, 26 Jul 2017 14:52:52 +0000 (UTC) From: Marcel Apfelbaum To: linux-rdma@vger.kernel.org Cc: linux-kernel@vger.kernel.org, monis@mellanox.com, dledford@redhat.com, sean.hefty@intel.com, hal.rosenstock@gmail.com, marcel@redhat.com, yuval.shaia@oracle.com Subject: [PATCH] drivers/rxe: improve rxe loopback Date: Wed, 26 Jul 2017 17:52:48 +0300 Message-Id: <20170726145248.21677-1-marcel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 26 Jul 2017 14:53:46 +0000 (UTC) Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently a packet is marked for loopback only if the source and destination address match. This is not enough when multiple gids are present in rxe's gid table and the traffic is from one gid to another. Fix it by marking the packet for loopback if the destination address appears in rxe's gid table. Signed-off-by: Marcel Apfelbaum Reviewed-by: Yuval Shaia Tested-by: Yuval Shaia --- drivers/infiniband/sw/rxe/rxe_net.c | 47 +++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_net.c b/drivers/infiniband/sw/rxe/rxe_net.c index c3a140e..b76a9a3 100644 --- a/drivers/infiniband/sw/rxe/rxe_net.c +++ b/drivers/infiniband/sw/rxe/rxe_net.c @@ -351,6 +351,27 @@ static void prepare_ipv6_hdr(struct dst_entry *dst, struct sk_buff *skb, ip6h->payload_len = htons(skb->len - sizeof(*ip6h)); } +static inline bool addr4_same_rxe(struct rxe_dev *rxe, struct in_addr *daddr) +{ + struct in_device *in_dev; + bool same_rxe = false; + + rcu_read_lock(); + in_dev = __in_dev_get_rcu(rxe->ndev); + if (!in_dev) + goto out; + + for_ifa(in_dev) + if (!memcmp(&ifa->ifa_address, daddr, sizeof(*daddr))) { + same_rxe = true; + goto out; + } + endfor_ifa(in_dev); +out: + rcu_read_unlock(); + return same_rxe; +} + static int prepare4(struct rxe_dev *rxe, struct rxe_pkt_info *pkt, struct sk_buff *skb, struct rxe_av *av) { @@ -367,7 +388,7 @@ static int prepare4(struct rxe_dev *rxe, struct rxe_pkt_info *pkt, return -EHOSTUNREACH; } - if (!memcmp(saddr, daddr, sizeof(*daddr))) + if (addr4_same_rxe(rxe, daddr)) pkt->mask |= RXE_LOOPBACK_MASK; prepare_udp_hdr(skb, htons(RXE_ROCE_V2_SPORT), @@ -384,6 +405,28 @@ static int prepare4(struct rxe_dev *rxe, struct rxe_pkt_info *pkt, return 0; } +static inline bool addr6_same_rxe(struct rxe_dev *rxe, struct in6_addr *daddr) +{ + struct inet6_dev *in6_dev; + struct inet6_ifaddr *ifp; + bool same_rxe = false; + + in6_dev = in6_dev_get(rxe->ndev); + if (!in6_dev) + return false; + + read_lock_bh(&in6_dev->lock); + list_for_each_entry(ifp, &in6_dev->addr_list, if_list) + if (!memcmp(&ifp->addr, daddr, sizeof(*daddr))) { + same_rxe = true; + goto out; + } +out: + read_unlock_bh(&in6_dev->lock); + in6_dev_put(in6_dev); + return same_rxe; +} + static int prepare6(struct rxe_dev *rxe, struct rxe_pkt_info *pkt, struct sk_buff *skb, struct rxe_av *av) { @@ -398,7 +441,7 @@ static int prepare6(struct rxe_dev *rxe, struct rxe_pkt_info *pkt, return -EHOSTUNREACH; } - if (!memcmp(saddr, daddr, sizeof(*daddr))) + if (addr6_same_rxe(rxe, daddr)) pkt->mask |= RXE_LOOPBACK_MASK; prepare_udp_hdr(skb, htons(RXE_ROCE_V2_SPORT),