From patchwork Fri Sep 22 08:58:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?6buE5p2w?= X-Patchwork-Id: 143416 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5549495vqi; Fri, 22 Sep 2023 05:58:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFGmZjawCfnf2AxvFvbgVsqcGTYNrePqMgb5/rKZ1VwXBx2Hr/GwqB/PQTcFG69LoaNy+Yc X-Received: by 2002:a05:6a00:2d12:b0:68b:a137:373d with SMTP id fa18-20020a056a002d1200b0068ba137373dmr3568646pfb.17.1695387533166; Fri, 22 Sep 2023 05:58:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695387533; cv=none; d=google.com; s=arc-20160816; b=YtZwnhaBc3E25CpMKYzZDxkuRNdMrSshEftw+ROppwxLui7hyFvnMnDKDM5prp0MaD 5M3Vs91VeCq3VVgxJr0h0iypyYmyjd2JImbb2fFDWL8iWmg53dAkM+oXC9ZyorjVkhKC MRcT5dktvLICXKvU5G41I71oNwzBjs9iwb6yERZ9PpQAXU6Eim+/fp+I1BDWYPG6HtHJ tZBoHz37MdKqI0WQDnPsMbPrusBCJB/L6x4ygDDVWcSLkeBdXsXp9Y61WjRKkwc5I72l U8YKbSW6SvDfcI+FtAdcp3v6850XgmBn9dSblIYQzjl2o+7wzKdbOtI7L/6kudyhhbUZ zFtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=dzmBYOC+iwFysYemk8kdLeE2Dt2aHmz4Un9SzH6Y5Wg=; fh=s8xMp3kzpiUjeINEqu73Ew84A+8WsDBlOLgplhfx0vo=; b=cmRVFESGhi1OUSdM9k/wC+JWXfJfOpF69XkhdWiZr3oJrQ2t84jXvJiGaQziowrXYm jp5mfa6GrbKaMuQ58Xf/v06eIFNyMrZNWbHkLwrcEU377fjq+HxFmLWqyzaRC0b3aEy6 rcG75NVDvc8cxsWUGTftD0pSBJ7if62hvELNkZoEdCFhaULanwQN2o57yqSocN8aFLm6 tkSnIOAs/Y7TCwa/ZHgNCpGhPaQt3t3xrKc3BeSFf/amuXhhjf6pYwhu6wGKF3SE25NP 3f+I3VSTkdHshD7TPUOF+PGoReyN/Xnpm18IPBW+VQoIzUCeYEyUcU5pOtT6v8rDAC9g r3iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=lyjSFPQx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id s16-20020a656450000000b0056c4189d6d9si3691054pgv.836.2023.09.22.05.58.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 05:58:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=lyjSFPQx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id E6B20831F261; Fri, 22 Sep 2023 01:59:37 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232693AbjIVI7Y (ORCPT + 30 others); Fri, 22 Sep 2023 04:59:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229495AbjIVI7W (ORCPT ); Fri, 22 Sep 2023 04:59:22 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17DD39E for ; Fri, 22 Sep 2023 01:59:16 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1c5db4925f9so11969455ad.1 for ; Fri, 22 Sep 2023 01:59:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1695373155; x=1695977955; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=dzmBYOC+iwFysYemk8kdLeE2Dt2aHmz4Un9SzH6Y5Wg=; b=lyjSFPQxZerMNiYrZXuVliZlWmFh5LIAThvgjhB3iNeC2Mt94o5pZiJQOqlMqRn1bs ySPwySrva3vkCafEMyxVcC9fFZlQdIgG20ESS5iy3XTsM6TPRgT8lbC3CDv8aH7zeBft iClF+8PEJbi3B69yQ9yWNzvzXlT6D+URoPD/MrmMm1KvavKZaiaSsy3Op9TTAzjBqaXo dePXMsATFG25vtsCXTUxgR35tlqa7jHhkxc+9ggrabEdfNvP1U82OaoMh28hB/GZMMth Fv077mS2yvRl6I/d3/nbZF1HdQ1lH+ks67H4HOXlN1CNLZjnefldRModOTbDxXPZczKV QkOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695373155; x=1695977955; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=dzmBYOC+iwFysYemk8kdLeE2Dt2aHmz4Un9SzH6Y5Wg=; b=tQu+hTM028wMSOBZskxoHMLy01RVKcxgDHMin6NAhnvnEfuz9jeKLTRAhcrdzYlK0f jbairCllWrnV4PNG3IjjeQZ+uEon/ylOZ7/tMU2I+UN8ZISPYVzjqc0lM1fR//LGr81G f3/iya0R7GIlK+0C01yWr66UxCSgvGDrfbyevFjKZN4G86TzfQYIh/Q3tzU9k0O+xsFh TQhPUvJsCEHZOzx61cZPCOhzLuEX7C7iFRzdqlkldSokZuY+cTRmwMQJBD+UV10vAlzD k/DEjB/5lh5ymrFuQbnLpn9uEJf9z51/KVxGruLkpraiN28A8KKtF/T3uKVrmT0TIlVH OyPQ== X-Gm-Message-State: AOJu0YyVh5dxL76JfYZMJ2hVgebOzYN8OHVipsOrD/9ViX/Q/iNDcdqL FEq6yNv4rvKL2Ksyo9C5EfGSrg== X-Received: by 2002:a17:902:e84e:b0:1bf:193a:70b6 with SMTP id t14-20020a170902e84e00b001bf193a70b6mr3278217plg.5.1695373155445; Fri, 22 Sep 2023 01:59:15 -0700 (PDT) Received: from C02FG34NMD6R.bytedance.net ([240e:6b1:c0:120::2:d]) by smtp.gmail.com with ESMTPSA id l19-20020a170902d35300b001bf5e24b2a8sm2927604plk.174.2023.09.22.01.59.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 01:59:14 -0700 (PDT) From: Albert Huang To: Karsten Graul , Wenjia Zhang , Jan Karcher Cc: Albert Huang , "D. Wythe" , Tony Lu , Wen Gu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-s390@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] net/smc: add support for netdevice in containers. Date: Fri, 22 Sep 2023 16:58:57 +0800 Message-Id: <20230922085858.94747-1-huangjie.albert@bytedance.com> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Fri, 22 Sep 2023 01:59:38 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777731941054322918 X-GMAIL-MSGID: 1777742677845915013 If the netdevice is within a container and communicates externally through network technologies like VXLAN, we won't be able to find routing information in the init_net namespace. To address this issue, we need to add a struct net parameter to the smc_ib_find_route function. This allow us to locate the routing information within the corresponding net namespace, ensuring the correct completion of the SMC CLC interaction. Signed-off-by: Albert Huang --- net/smc/af_smc.c | 3 ++- net/smc/smc_ib.c | 7 ++++--- net/smc/smc_ib.h | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c index bacdd971615e..7a874da90c7f 100644 --- a/net/smc/af_smc.c +++ b/net/smc/af_smc.c @@ -1201,6 +1201,7 @@ static int smc_connect_rdma_v2_prepare(struct smc_sock *smc, (struct smc_clc_msg_accept_confirm_v2 *)aclc; struct smc_clc_first_contact_ext *fce = smc_get_clc_first_contact_ext(clc_v2, false); + struct net *net = sock_net(&smc->sk); int rc; if (!ini->first_contact_peer || aclc->hdr.version == SMC_V1) @@ -1210,7 +1211,7 @@ static int smc_connect_rdma_v2_prepare(struct smc_sock *smc, memcpy(ini->smcrv2.nexthop_mac, &aclc->r0.lcl.mac, ETH_ALEN); ini->smcrv2.uses_gateway = false; } else { - if (smc_ib_find_route(smc->clcsock->sk->sk_rcv_saddr, + if (smc_ib_find_route(net, smc->clcsock->sk->sk_rcv_saddr, smc_ib_gid_to_ipv4(aclc->r0.lcl.gid), ini->smcrv2.nexthop_mac, &ini->smcrv2.uses_gateway)) diff --git a/net/smc/smc_ib.c b/net/smc/smc_ib.c index 9b66d6aeeb1a..89981dbe46c9 100644 --- a/net/smc/smc_ib.c +++ b/net/smc/smc_ib.c @@ -193,7 +193,7 @@ bool smc_ib_port_active(struct smc_ib_device *smcibdev, u8 ibport) return smcibdev->pattr[ibport - 1].state == IB_PORT_ACTIVE; } -int smc_ib_find_route(__be32 saddr, __be32 daddr, +int smc_ib_find_route(struct net *net, __be32 saddr, __be32 daddr, u8 nexthop_mac[], u8 *uses_gateway) { struct neighbour *neigh = NULL; @@ -205,7 +205,7 @@ int smc_ib_find_route(__be32 saddr, __be32 daddr, if (daddr == cpu_to_be32(INADDR_NONE)) goto out; - rt = ip_route_output_flow(&init_net, &fl4, NULL); + rt = ip_route_output_flow(net, &fl4, NULL); if (IS_ERR(rt)) goto out; if (rt->rt_uses_gateway && rt->rt_gw_family != AF_INET) @@ -235,6 +235,7 @@ static int smc_ib_determine_gid_rcu(const struct net_device *ndev, if (smcrv2 && attr->gid_type == IB_GID_TYPE_ROCE_UDP_ENCAP && smc_ib_gid_to_ipv4((u8 *)&attr->gid) != cpu_to_be32(INADDR_NONE)) { struct in_device *in_dev = __in_dev_get_rcu(ndev); + struct net *net = dev_net(ndev); const struct in_ifaddr *ifa; bool subnet_match = false; @@ -248,7 +249,7 @@ static int smc_ib_determine_gid_rcu(const struct net_device *ndev, } if (!subnet_match) goto out; - if (smcrv2->daddr && smc_ib_find_route(smcrv2->saddr, + if (smcrv2->daddr && smc_ib_find_route(net, smcrv2->saddr, smcrv2->daddr, smcrv2->nexthop_mac, &smcrv2->uses_gateway)) diff --git a/net/smc/smc_ib.h b/net/smc/smc_ib.h index 4df5f8c8a0a1..ef8ac2b7546d 100644 --- a/net/smc/smc_ib.h +++ b/net/smc/smc_ib.h @@ -112,7 +112,7 @@ void smc_ib_sync_sg_for_device(struct smc_link *lnk, int smc_ib_determine_gid(struct smc_ib_device *smcibdev, u8 ibport, unsigned short vlan_id, u8 gid[], u8 *sgid_index, struct smc_init_info_smcrv2 *smcrv2); -int smc_ib_find_route(__be32 saddr, __be32 daddr, +int smc_ib_find_route(struct net *net, __be32 saddr, __be32 daddr, u8 nexthop_mac[], u8 *uses_gateway); bool smc_ib_is_valid_local_systemid(void); int smcr_nl_get_device(struct sk_buff *skb, struct netlink_callback *cb);