From: "Sean Hefty" <sean.hefty@intel.com>
To: "'Tetsuo Handa'" <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: <amwang@redhat.com>, <opurdila@ixiacom.com>,
<eric.dumazet@gmail.com>, <netdev@vger.kernel.org>,
<nhorman@tuxdriver.com>, <davem@davemloft.net>,
<ebiederm@xmission.com>, <linux-kernel@vger.kernel.org>,
<rolandd@cisco.com>, <linux-rdma@vger.kernel.org>
Subject: [PATCH] rdma/cm: Randomize local port allocation.
Date: Thu, 15 Apr 2010 12:55:29 -0700 [thread overview]
Message-ID: <5CE6BC7B954643FAAFFD2AD66F673CBD@amr.corp.intel.com> (raw)
In-Reply-To: <201004150229.o3F2T4dZ054768@www262.sakura.ne.jp>
From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
>Randomize local port allocation in a way sctp_get_port_local() does.
>Update rover at the end of loop since we're likely to pick a valid port
>on the first try.
>
>Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Reviewed-by: Sean Hefty <sean.hefty@intel.com>
>---
I like this version, thanks! I'm not sure which tree to merge it through.
Are you needing this for 2.6.34, or is 2.6.35 okay?
> drivers/infiniband/core/cma.c | 70 +++++++++++++++--------------------------
>-
> 1 file changed, 25 insertions(+), 45 deletions(-)
>
>--- linux-2.6.34-rc4.orig/drivers/infiniband/core/cma.c
>+++ linux-2.6.34-rc4/drivers/infiniband/core/cma.c
>@@ -79,7 +79,6 @@ static DEFINE_IDR(sdp_ps);
> static DEFINE_IDR(tcp_ps);
> static DEFINE_IDR(udp_ps);
> static DEFINE_IDR(ipoib_ps);
>-static int next_port;
>
> struct cma_device {
> struct list_head list;
>@@ -1970,47 +1969,33 @@ err1:
>
> static int cma_alloc_any_port(struct idr *ps, struct rdma_id_private *id_priv)
> {
>- struct rdma_bind_list *bind_list;
>- int port, ret, low, high;
>-
>- bind_list = kzalloc(sizeof *bind_list, GFP_KERNEL);
>- if (!bind_list)
>- return -ENOMEM;
>-
>-retry:
>- /* FIXME: add proper port randomization per like inet_csk_get_port */
>- do {
>- ret = idr_get_new_above(ps, bind_list, next_port, &port);
>- } while ((ret == -EAGAIN) && idr_pre_get(ps, GFP_KERNEL));
>-
>- if (ret)
>- goto err1;
>+ static unsigned int last_used_port;
>+ int low, high, remaining;
>+ unsigned int rover;
>
> inet_get_local_port_range(&low, &high);
>- if (port > high) {
>- if (next_port != low) {
>- idr_remove(ps, port);
>- next_port = low;
>- goto retry;
>- }
>- ret = -EADDRNOTAVAIL;
>- goto err2;
>+ remaining = (high - low) + 1;
>+ rover = net_random() % remaining + low;
>+retry:
>+ if (last_used_port != rover &&
>+ !idr_find(ps, (unsigned short) rover)) {
>+ int ret = cma_alloc_port(ps, id_priv, rover);
>+ /*
>+ * Remember previously used port number in order to avoid
>+ * re-using same port immediately after it is closed.
>+ */
>+ if (!ret)
>+ last_used_port = rover;
>+ if (ret != -EADDRNOTAVAIL)
>+ return ret;
> }
>-
>- if (port == high)
>- next_port = low;
>- else
>- next_port = port + 1;
>-
>- bind_list->ps = ps;
>- bind_list->port = (unsigned short) port;
>- cma_bind_port(bind_list, id_priv);
>- return 0;
>-err2:
>- idr_remove(ps, port);
>-err1:
>- kfree(bind_list);
>- return ret;
>+ if (--remaining) {
>+ rover++;
>+ if ((rover < low) || (rover > high))
>+ rover = low;
>+ goto retry;
>+ }
>+ return -EADDRNOTAVAIL;
> }
>
> static int cma_use_port(struct idr *ps, struct rdma_id_private *id_priv)
>@@ -2995,12 +2980,7 @@ static void cma_remove_one(struct ib_dev
>
> static int __init cma_init(void)
> {
>- int ret, low, high, remaining;
>-
>- get_random_bytes(&next_port, sizeof next_port);
>- inet_get_local_port_range(&low, &high);
>- remaining = (high - low) + 1;
>- next_port = ((unsigned int) next_port % remaining) + low;
>+ int ret;
>
> cma_wq = create_singlethread_workqueue("rdma_cm");
> if (!cma_wq)
next prev parent reply other threads:[~2010-04-15 19:55 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-12 10:03 [Patch v8 0/3] net: reserve ports for applications using fixed port numbers Amerigo Wang
2010-04-12 10:04 ` [Patch 1/3] sysctl: refactor integer handling proc code Amerigo Wang
2010-04-13 11:18 ` Alexey Dobriyan
2010-04-13 7:35 ` Cong Wang
2010-04-12 10:04 ` [Patch 2/3] sysctl: add proc_do_large_bitmap Amerigo Wang
2010-04-12 10:04 ` [Patch 3/3] net: reserve ports for applications using fixed port numbers Amerigo Wang
2010-04-13 1:21 ` Tetsuo Handa
2010-04-13 7:13 ` Cong Wang
2010-04-13 8:48 ` Cong Wang
2010-04-13 13:07 ` Tetsuo Handa
2010-04-13 16:32 ` Sean Hefty
2010-04-14 2:01 ` [PATCH] Infiniband: Randomize local port allocation penguin-kernel
2010-04-14 4:38 ` Cong Wang
2010-04-15 0:01 ` Sean Hefty
2010-04-15 2:29 ` Tetsuo Handa
2010-04-15 19:55 ` Sean Hefty [this message]
2010-04-16 2:22 ` [PATCH] rdma/cm: " Cong Wang
2010-04-16 13:54 ` Tetsuo Handa
2010-04-16 20:30 ` David Miller
2010-04-20 4:34 ` Cong Wang
2010-04-21 23:19 ` [PATCH] Infiniband: " Roland Dreier
2010-04-21 23:22 ` Roland Dreier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5CE6BC7B954643FAAFFD2AD66F673CBD@amr.corp.intel.com \
--to=sean.hefty@intel.com \
--cc=amwang@redhat.com \
--cc=davem@davemloft.net \
--cc=ebiederm@xmission.com \
--cc=eric.dumazet@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=nhorman@tuxdriver.com \
--cc=opurdila@ixiacom.com \
--cc=penguin-kernel@I-love.SAKURA.ne.jp \
--cc=rolandd@cisco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome