netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Cong Wang <amwang@redhat.com>
To: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: linux-kernel@vger.kernel.org, opurdila@ixiacom.com,
	eric.dumazet@gmail.com, netdev@vger.kernel.org,
	nhorman@tuxdriver.com, davem@davemloft.net,
	ebiederm@xmission.com
Subject: Re: [Patch 3/3] net: reserve ports for applications using fixed port numbers
Date: Mon, 12 Apr 2010 14:52:59 +0800	[thread overview]
Message-ID: <4BC2C34B.50109@redhat.com> (raw)
In-Reply-To: <201004092221.GEE32059.FHMOFVLJOFSOtQ@I-love.SAKURA.ne.jp>

Tetsuo Handa wrote:
> Hello.
> 
> Amerigo Wang wrote:
>> Index: linux-2.6/drivers/infiniband/core/cma.c
>> ===================================================================
>> --- linux-2.6.orig/drivers/infiniband/core/cma.c
>> +++ linux-2.6/drivers/infiniband/core/cma.c
>> @@ -1980,6 +1980,8 @@ retry:
>>  	/* FIXME: add proper port randomization per like inet_csk_get_port */
>>  	do {
>>  		ret = idr_get_new_above(ps, bind_list, next_port, &port);
>> +		if (inet_is_reserved_local_port(port))
>> +			ret = -EAGAIN;
> 
> You should not overwrite ret with -EAGAIN when idr_get_new_above() returned
> -ENOSPC. I don't know about idr, thus I don't know whether
> 
> 		if (!ret && inet_is_reserved_local_port(port))
> 			ret = -EAGAIN;
> 
> is correct or not.

Hmm, good catch! I think it is correct.



> 
>>  	} while ((ret == -EAGAIN) && idr_pre_get(ps, GFP_KERNEL));
>>  
>>  	if (ret)
>> @@ -2996,10 +2998,13 @@ 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);
>> +again:
>> +	get_random_bytes(&next_port, sizeof next_port);
>>  	remaining = (high - low) + 1;
>>  	next_port = ((unsigned int) next_port % remaining) + low;
>> +	if (inet_is_reserved_local_port(next_port))
>> +		goto again;
>>  
> 
> You should not unconditionally "goto again;".
> If all ports were reserved, it will loop forever (CPU stalls).
> 

Yeah, how about:

	int tries = 10;
	...
again:
	...
	if (inet_is_reserved_local_port(next_port)) {
		if (tries--)
			goto again;
		else
			return -EBUSY;
	}

?


>>  	cma_wq = create_singlethread_workqueue("rdma_cm");
>>  	if (!cma_wq)
> 
> 
>> Index: linux-2.6/net/sctp/socket.c
>> ===================================================================
>> --- linux-2.6.orig/net/sctp/socket.c
>> +++ linux-2.6/net/sctp/socket.c
>> @@ -5436,6 +5436,8 @@ static long sctp_get_port_local(struct s
>>  			rover++;
>>  			if ((rover < low) || (rover > high))
>>  				rover = low;
>> +			if (inet_is_reserved_local_port(rover))
>> +				continue;
> 
> This one needs to be
> 
> 			if (inet_is_reserved_local_port(rover))
> 				goto next_nolock;
> 
>>  			index = sctp_phashfn(rover);
>>  			head = &sctp_port_hashtable[index];
>>  			sctp_spin_lock(&head->lock);
> 
>  next:
> 			sctp_spin_unlock(&head->lock);
> +next_nolock:
> 		} while (--remaining > 0);
> 
> otherwise, it will loop forever if all ports were reserved.

Sorry, doesn't 'continue' jump to exactly where 'next_nolock' is??
Or I am missing something?


Thanks for your review!

  reply	other threads:[~2010-04-12  6:52 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-09 10:10 [Patch v7 0/3] net: reserve ports for applications using fixed port numbers Amerigo Wang
2010-04-09 10:11 ` [Patch 1/3] sysctl: refactor integer handling proc code Amerigo Wang
2010-04-09 10:49   ` Changli Gao
2010-04-09 13:40     ` Octavian Purdila
2010-04-12  6:30       ` Cong Wang
2010-04-09 10:11 ` [Patch 2/3] sysctl: add proc_do_large_bitmap Amerigo Wang
2010-04-09 10:33   ` Changli Gao
2010-04-09 12:35     ` Octavian Purdila
2010-04-12  6:32     ` Cong Wang
2010-04-09 10:11 ` [Patch 3/3] net: reserve ports for applications using fixed port numbers Amerigo Wang
2010-04-09 13:21   ` Tetsuo Handa
2010-04-12  6:52     ` Cong Wang [this message]
2010-04-12  7:06       ` Tetsuo Handa
  -- strict thread matches above, loose matches on Subject: below --
2010-04-12 10:03 [Patch v8 0/3] " Amerigo Wang
2010-04-12 10:04 ` [Patch 3/3] " 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-30  8:25 [Patch v9 0/3] " Amerigo Wang
2010-04-30  8:25 ` [Patch 3/3] " Amerigo Wang
2010-05-05 10:26 [Patch v10 0/3] " Amerigo Wang
2010-05-05 10:27 ` [Patch 3/3] " Amerigo Wang

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=4BC2C34B.50109@redhat.com \
    --to=amwang@redhat.com \
    --cc=davem@davemloft.net \
    --cc=ebiederm@xmission.com \
    --cc=eric.dumazet@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nhorman@tuxdriver.com \
    --cc=opurdila@ixiacom.com \
    --cc=penguin-kernel@I-love.SAKURA.ne.jp \
    /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;
as well as URLs for NNTP newsgroup(s).