netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Asias He <asias@redhat.com>
To: netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
	Andy King <acking@vmware.com>, Dmitry Torokhov <dtor@vmware.com>,
	Reilly Grant <grantr@vmware.com>, Asias He <asias@redhat.com>
Subject: [PATCH 4/4] VSOCK: Fix VSOCK_HASH and VSOCK_CONN_HASH
Date: Thu, 20 Jun 2013 17:20:33 +0800	[thread overview]
Message-ID: <1371720033-19714-5-git-send-email-asias@redhat.com> (raw)
In-Reply-To: <1371720033-19714-1-git-send-email-asias@redhat.com>

If we mod with VSOCK_HASH_SIZE -1, we get 0, 1, .... 249.  Actually, we
have vsock_bind_table[0 ... 250] and vsock_connected_table[0 .. 250].
In this case the last entry will never be used.

We should mod with VSOCK_HASH_SIZE instead.

Signed-off-by: Asias He <asias@redhat.com>
---
 net/vmw_vsock/af_vsock.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index b0b362a..593071d 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -144,18 +144,18 @@ EXPORT_SYMBOL_GPL(vm_sockets_get_local_cid);
  * VSOCK_HASH_SIZE + 1 so that vsock_bind_table[0] through
  * vsock_bind_table[VSOCK_HASH_SIZE - 1] are for bound sockets and
  * vsock_bind_table[VSOCK_HASH_SIZE] is for unbound sockets.  The hash function
- * mods with VSOCK_HASH_SIZE - 1 to ensure this.
+ * mods with VSOCK_HASH_SIZE to ensure this.
  */
 #define VSOCK_HASH_SIZE         251
 #define MAX_PORT_RETRIES        24
 
-#define VSOCK_HASH(addr)        ((addr)->svm_port % (VSOCK_HASH_SIZE - 1))
+#define VSOCK_HASH(addr)        ((addr)->svm_port % VSOCK_HASH_SIZE)
 #define vsock_bound_sockets(addr) (&vsock_bind_table[VSOCK_HASH(addr)])
 #define vsock_unbound_sockets     (&vsock_bind_table[VSOCK_HASH_SIZE])
 
 /* XXX This can probably be implemented in a better way. */
 #define VSOCK_CONN_HASH(src, dst)				\
-	(((src)->svm_cid ^ (dst)->svm_port) % (VSOCK_HASH_SIZE - 1))
+	(((src)->svm_cid ^ (dst)->svm_port) % VSOCK_HASH_SIZE)
 #define vsock_connected_sockets(src, dst)		\
 	(&vsock_connected_table[VSOCK_CONN_HASH(src, dst)])
 #define vsock_connected_sockets_vsk(vsk)				\
-- 
1.8.1.4

  parent reply	other threads:[~2013-06-20  9:21 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-20  9:20 [PATCH 0/4] VSOCK fix and cleanup Asias He
2013-06-20  9:20 ` [PATCH 1/4] VSOCK: Introduce vsock_auto_bind helper Asias He
2013-06-20 15:16   ` Andy King
2013-06-20  9:20 ` [PATCH 2/4] VSOCK: Return VMCI_ERROR_NO_MEM when fails to allocate skb Asias He
2013-06-20 15:15   ` Andy King
2013-06-20  9:20 ` [PATCH 3/4] VSOCK: Remove unnecessary label Asias He
2013-06-20 15:13   ` Andy King
2013-06-20  9:20 ` Asias He [this message]
2013-06-20 15:12   ` [PATCH 4/4] VSOCK: Fix VSOCK_HASH and VSOCK_CONN_HASH Andy King
2013-06-21  0:22     ` Asias He
2013-06-21 12:48       ` Andy King
2013-06-24  6:52 ` [PATCH 0/4] VSOCK fix and cleanup 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=1371720033-19714-5-git-send-email-asias@redhat.com \
    --to=asias@redhat.com \
    --cc=acking@vmware.com \
    --cc=davem@davemloft.net \
    --cc=dtor@vmware.com \
    --cc=grantr@vmware.com \
    --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).