From patchwork Tue Oct 25 10:22:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leon Romanovsky X-Patchwork-Id: 13019037 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7CCCEC38A2D for ; Tue, 25 Oct 2022 10:25:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232408AbiJYKZi (ORCPT ); Tue, 25 Oct 2022 06:25:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231814AbiJYKYl (ORCPT ); Tue, 25 Oct 2022 06:24:41 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECBD3181971 for ; Tue, 25 Oct 2022 03:22:41 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id AC377B81CE2 for ; Tue, 25 Oct 2022 10:22:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EABF6C433D6; Tue, 25 Oct 2022 10:22:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666693359; bh=p6zKuEFL6GMLtttde0/EyvpqXkRStUIFD60AHI/a9HU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MuKpqeE1daBNJGHNj4j7jHAafC1Xu2qZHyEmM3cQuTNpzmdVBiLUnMrpiVYq2ByfY Zg0/eACs9A2gkmUcDIwfDJvhpaFj81zv48xvwEqNixZn79oMfqIgVOuqFGMmI3sZJ/ HAi4ur0o5eMQyocFNQrlfjW6+iGxNrJHv8FpysYrjL8Ic120xvs2k+PjCDCD/xI5KB fEgKn69MauDBhe3EISwY6bvLFFd55ec17BhO5c9ziJ42rhdvzDPt+dEKlMS8HYdq3k GP782ZgQ39My3NSflrZ2rZZ2KqbnVM1ZoMBuX1EXJADcmrcm+WrxhIUrKjtvvJFPDj Zo4fSBDT8qfqQ== From: Leon Romanovsky To: Steffen Klassert Cc: Leon Romanovsky , "David S. Miller" , Eric Dumazet , Herbert Xu , Jakub Kicinski , netdev@vger.kernel.org, Paolo Abeni , Raed Salem , Saeed Mahameed , Bharat Bhushan Subject: [PATCH xfrm-next v6 6/8] xfrm: speed-up lookup of HW policies Date: Tue, 25 Oct 2022 13:22:02 +0300 Message-Id: X-Mailer: git-send-email 2.37.3 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Leon Romanovsky Devices that implement IPsec full offload mode should offload policies too. In RX path, it causes to the situation that HW will always have higher priority over any SW policies. It means that we don't need to perform any search of inexact policies and/or priority checks if HW policy was discovered. In such situation, the HW will catch the packets anyway and HW can still implement inexact lookups. In case specific policy is not found, we will continue with full lookup and check for existence of HW policies in inexact list. HW policies are added to the head of SPD to ensure fast lookup, as XFRM iterates over all policies in the loop. Signed-off-by: Leon Romanovsky --- net/xfrm/xfrm_policy.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c index b07ed169f501..cc10ee3ebafe 100644 --- a/net/xfrm/xfrm_policy.c +++ b/net/xfrm/xfrm_policy.c @@ -1562,9 +1562,12 @@ static struct xfrm_policy *xfrm_policy_insert_list(struct hlist_head *chain, break; } - if (newpos) + if (newpos && policy->xdo.type != XFRM_DEV_OFFLOAD_FULL) hlist_add_behind_rcu(&policy->bydst, &newpos->bydst); else + /* Full offload policies are enteded + * to the head to speed-up lookups. + */ hlist_add_head_rcu(&policy->bydst, chain); return delpol; @@ -2180,6 +2183,9 @@ static struct xfrm_policy *xfrm_policy_lookup_bytype(struct net *net, u8 type, break; } } + if (ret && ret->xdo.type == XFRM_DEV_OFFLOAD_FULL) + goto skip_inexact; + bin = xfrm_policy_inexact_lookup_rcu(net, type, family, dir, if_id); if (!bin || !xfrm_policy_find_inexact_candidates(&cand, bin, saddr, daddr))