From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-189.mta0.migadu.com (out-189.mta0.migadu.com [91.218.175.189]) (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 B59217E792 for ; Wed, 29 Apr 2026 02:38:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.189 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777430340; cv=none; b=PZc/M4IzWazcgz0GIkTc6QmxRsobqGgM5JABxiL5jLuYyk+KmtNIMOScoNZ6Fa+7PHphCeJEdLHb3f59QQFjdKxmTymroWNiiUQQPJnBFVqDyz56LbDCD56WQuV7TQo9OPmkTtmPqLCpHAKRGhfUPWf1W6fC25tGWmF0UcuMdO0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777430340; c=relaxed/simple; bh=tBTl0xy/hsAnsGtM9aM9rgIMKM5lR9x96oX01UJaZhw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=T8F405gx6VaSI7XcN1HHDNYKh+5xerktKxZu8FWahve/CRWfpvmiUVXP+SmfFHRXw/kBv6bN+9f7lYjx4fhirO0pvGTMbhLpelLcyPdL7DgeAwsqCWLWNdnh6B3bGBhM/RBfLa/6JU6kGjEihjqpVHavuAYL8AVFOeEEOFcCguM= 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=ICQbjVnb; arc=none smtp.client-ip=91.218.175.189 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="ICQbjVnb" 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=1777430336; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=hAPC6BiCdcdMi/R6MIQssFNU/RXbhO7b3nUEqaGcP+A=; b=ICQbjVnb0pdUszF0cqjpr0cI6MkztFk2PR+q9Zm8CAWJZwVV1+bthhWYuorT0zptB+Zt36 dr0fZMT53rl1DX/jSkov98bxY0Olh4WMq9/g1/cOLEvEd8WkSv9jZWLDWAi7yxq0gwLk9Z 41IYta/RmDxBjXrzkAf7hfDXtWQGUwc= 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 Cc: linux-ppp@vger.kernel.org Subject: [PATCH net-next v2] pppoe: optimize hash with word access Date: Wed, 29 Apr 2026 10:38:46 +0800 Message-ID: <20260429023848.153425-1-qingfang.deng@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@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 --- v2: repost after net-next opens v1: https://lore.kernel.org/netdev/20260413035212.56566-1-qingfang.deng@linux.dev 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 bdd61c504a1c..ad5bb98c1579 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