Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp699896imm; Fri, 12 Oct 2018 05:25:24 -0700 (PDT) X-Google-Smtp-Source: ACcGV62jFf83uSiaaBg1cl6Kx6PmhenP5qzm6sn4oYvKD3fR1xvw2Pc8ktEhfP/3YlUaQaLVzGU1 X-Received: by 2002:a17:902:a5cc:: with SMTP id t12-v6mr5888512plq.229.1539347124575; Fri, 12 Oct 2018 05:25:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539347124; cv=none; d=google.com; s=arc-20160816; b=LM6irwCjvHX6hzpAAHobUru+01cpLKUuB2PjGZiayCw5XztQIPeQr0FCMBYpGUDCiS 2qKVD4cNtcVqW77ya9b/vBHhnr2CIxsj4a2Lksm9rHYNJS+gkUHA3pSmvmAlhqDrLsOr CHRQMT/xKF3F7iM6FCRX3e/sLUFWPyQdxXOmklEOerPGAH5YI4Qu6zhFxfckyrUJR37x l+TXgBeh8UpiIB+hbk9AwQY/XExg+oJRtlXnyOBKKoZYFfOUCUOVk6uYFf2KMm3dV42K GYKfq/EqWldf7cMayIkY/oq5y7pdu2Rd1nawCZJwiN/EKcZ7PjobzJZ39XqX8RjYwJIS pYlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:message-id:cc:to:subject:from; bh=aD4TnpIAhnenRRqCXejX8DWvujfSP8B14dLa/EXWo9U=; b=Y8kgnTdlCgjsUCUYJMDSxYiUe0YtawlRx6mfpZWX1IEEqQWZAbXNun6QnD3wF4KPOF j/mpi+sB90Fi09jMwTi1TcSGjFtSmC06NmlxYVBZIdfOFX8v+3V6r5xvhOCY6D97UEoj nwYqiUwU8AEfOPjfMSc+QNHK2MEw+UDjeQIzplY9hqfOAL5lWVYv3WYkK3ySxgLvkEkM QFTMM+bOA1Onj9O6tglBnE/5l2Fy1pAXuytfQPeQlO7jKGcIq1tWAaImKiJNQeKfJLHV vp8hRki0Nx+slNb76GqHvcIDsKTPSoTFcKDLVkVnLlEzwPqWjzJV7ip5MhxLMfFTLsKM eakA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r3-v6si1095877plb.221.2018.10.12.05.25.09; Fri, 12 Oct 2018 05:25:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728660AbeJLT5A (ORCPT + 99 others); Fri, 12 Oct 2018 15:57:00 -0400 Received: from mx2.suse.de ([195.135.220.15]:40816 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727816AbeJLT5A (ORCPT ); Fri, 12 Oct 2018 15:57:00 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 53839AE86; Fri, 12 Oct 2018 12:24:45 +0000 (UTC) Received: by unicorn.suse.cz (Postfix, from userid 1000) id 0448FA0ED9; Fri, 12 Oct 2018 14:24:44 +0200 (CEST) From: Michal Kubecek Subject: [PATCH ipsec-next] xfrm: use complete IPv6 addresses for hash To: Steffen Klassert Cc: Herbert Xu , "David S. Miller" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Message-Id: <20181012122444.0448FA0ED9@unicorn.suse.cz> Date: Fri, 12 Oct 2018 14:24:44 +0200 (CEST) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In some environments it is common that many hosts share the same lower half of their IPv6 addresses (in particular ::1). As __xfrm6_addr_hash() and __xfrm6_daddr_saddr_hash() calculate the hash only from the lower halves, as much as 1/3 of the hosts ends up in one hashtable chain which harms the performance. Use complete IPv6 addresses when calculating the hashes. Rather than just adding two more words to the xor, use jhash2() for consistency with __xfrm6_pref_hash() and __xfrm6_dpref_spref_hash(). Signed-off-by: Michal Kubecek --- net/xfrm/xfrm_hash.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/net/xfrm/xfrm_hash.h b/net/xfrm/xfrm_hash.h index 61be810389d8..ce66323102f9 100644 --- a/net/xfrm/xfrm_hash.h +++ b/net/xfrm/xfrm_hash.h @@ -13,7 +13,7 @@ static inline unsigned int __xfrm4_addr_hash(const xfrm_address_t *addr) static inline unsigned int __xfrm6_addr_hash(const xfrm_address_t *addr) { - return ntohl(addr->a6[2] ^ addr->a6[3]); + return jhash2((__force u32 *)addr->a6, 4, 0); } static inline unsigned int __xfrm4_daddr_saddr_hash(const xfrm_address_t *daddr, @@ -26,8 +26,7 @@ static inline unsigned int __xfrm4_daddr_saddr_hash(const xfrm_address_t *daddr, static inline unsigned int __xfrm6_daddr_saddr_hash(const xfrm_address_t *daddr, const xfrm_address_t *saddr) { - return ntohl(daddr->a6[2] ^ daddr->a6[3] ^ - saddr->a6[2] ^ saddr->a6[3]); + return __xfrm6_addr_hash(daddr) ^ __xfrm6_addr_hash(saddr); } static inline u32 __bits2mask32(__u8 bits) -- 2.19.1