From: Andi Kleen <andi@firstfloor.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, Andi Kleen <ak@linux.intel.com>
Subject: [PATCH] ipv4: Handle very small SO_SNDTIMEOs
Date: Thu, 8 Nov 2012 07:51:48 -0800 [thread overview]
Message-ID: <1352389908-28587-1-git-send-email-andi@firstfloor.org> (raw)
From: Andi Kleen <ak@linux.intel.com>
When the SO_SNDTIMEO timeout is short enough it may round down to zero
jiffies. This causes unexpected behaviour because the socket
essentially becomes always non blocking.
Round up the timeout to at least two jiffies, so that
we guarantee waiting for at least some time. With one jiffie
we could potentially still wait zero time because we might
be just at the edge of the jiffie, and if it flips over
in the middle of the check it could be still zero.
This has been observed in a real application.
Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
net/core/sock.c | 9 ++++++++-
1 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/net/core/sock.c b/net/core/sock.c
index a6000fb..93c0060 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -362,8 +362,15 @@ static int sock_set_timeout(long *timeo_p, char __user *optval, int optlen)
*timeo_p = MAX_SCHEDULE_TIMEOUT;
if (tv.tv_sec == 0 && tv.tv_usec == 0)
return 0;
- if (tv.tv_sec < (MAX_SCHEDULE_TIMEOUT/HZ - 1))
+ if (tv.tv_sec < (MAX_SCHEDULE_TIMEOUT/HZ - 1)) {
*timeo_p = tv.tv_sec*HZ + (tv.tv_usec+(1000000/HZ-1))/(1000000/HZ);
+ /* Do at least two jiffies to ensure we wait at all.
+ * Otherwise we may be on the edge of the next jiffie already,
+ * and then essentially non block.
+ */
+ if ((unsigned long)*timeo_p < 2)
+ *timeo_p = 2;
+ }
return 0;
}
--
1.7.7.6
next reply other threads:[~2012-11-08 15:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-08 15:51 Andi Kleen [this message]
2012-11-09 21:58 ` [PATCH] ipv4: Handle very small SO_SNDTIMEOs David Miller
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=1352389908-28587-1-git-send-email-andi@firstfloor.org \
--to=andi@firstfloor.org \
--cc=ak@linux.intel.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
/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).