From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-181.mta1.migadu.com (out-181.mta1.migadu.com [95.215.58.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7ECB62D592C for ; Mon, 13 Apr 2026 03:52:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776052366; cv=none; b=P3EFkYnd2K5JLCfV8bY4Yj7gpIldadyTOyYSoK2Sag+RMx9i80Um2tiowV6IUhwC9To3uRBvzb/JnOK4Hwai43VkZLMzczgql9t/SRW7jahOxwPLsaO/nVVIlxK3d/CXI0436W5sBD7r+nQ9gYJLx1W0WMlBBTUC6RElLaXmqOo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776052366; c=relaxed/simple; bh=Enk/7+1eOnrzFSs1c4ahC/sRpxvzwXJB4ShJvD5rx4Y=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=svBuiiCdarIJWk6r9vLdCQlYjkxwxbsHxIdNT/CGG6OjIFRFsiwOxLyoBi/hk4qjdJG2Z29xHL/qTUHppLN6qiKMp9FJjCW3rvPJLIQNHz77uhq9yTYFOmzhzAGnTmzdgPnsvhwZG8VPcqH3NAgXEJVhz36XNmtDpjxm0i7TDhs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=IzFsJXsl; arc=none smtp.client-ip=95.215.58.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="IzFsJXsl" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1776052352; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=HZfm2zw4idtXW52pQTPw8Du+65quJOdBYon2FQtTgvY=; b=IzFsJXslCGdOKopFBLAQGcvH6dKIonZPQACTCPrcW2uT+J4zdaQbO/VSTptmLjf1roXJit UgVFfZ4Z5jRRXWDVhLdq0XfdSPNpVscQaTcftHbdzG1JN2SPQ+/TJn7ZFOcmNdBawQP7a9 yWB5F5aMXqIQ90UaockeaN0S1H3m9hI= From: Qingfang Deng To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Qingfang Deng , Guillaume Nault , Kees Cook , Eric Woudstra , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next] pppoe: optimize hash with word access Date: Mon, 13 Apr 2026 11:52:10 +0800 Message-ID: <20260413035212.56566-1-qingfang.deng@linux.dev> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Currently, hash_item() processes the 6-byte Ethernet address and the 2-byte session ID byte-wise to compute a hash. Optimize this by using 16-bit word operations: XOR three 16-bit words from the Ethernet address and the 16-bit session ID, then fold the result. This reduces the total number of loads and XORs. The Ethernet addresses in a skb and struct pppoe_addr are both 2-byte aligned, so the u16 pointer cast is safe. Signed-off-by: Qingfang Deng --- drivers/net/ppp/pppoe.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/net/ppp/pppoe.c b/drivers/net/ppp/pppoe.c index d546a7af0d54..e2e70628958b 100644 --- a/drivers/net/ppp/pppoe.c +++ b/drivers/net/ppp/pppoe.c @@ -136,15 +136,15 @@ static inline int cmp_addr(struct pppoe_addr *a, __be16 sid, char *addr) #error 8 must be a multiple of PPPOE_HASH_BITS #endif -static int hash_item(__be16 sid, unsigned char *addr) +static u8 hash_item(__be16 sid, const u8 addr[ETH_ALEN]) { - unsigned char hash = 0; + const u16 *addr16 = (const u16 *)addr; unsigned int i; + u16 hash16; + u8 hash; - for (i = 0; i < ETH_ALEN; i++) - hash ^= addr[i]; - for (i = 0; i < sizeof(sid_t) * 8; i += 8) - hash ^= (__force __u32)sid >> i; + hash16 = addr16[0] ^ addr16[1] ^ addr16[2] ^ (__force u16)sid; + hash = (hash16 >> 8) ^ hash16; for (i = 8; (i >>= 1) >= PPPOE_HASH_BITS;) hash ^= hash >> i; -- 2.43.0