From patchwork Fri Jun 19 09:41:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: dsatish X-Patchwork-Id: 217546 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C43ADC433DF for ; Fri, 19 Jun 2020 09:45:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9E124206D7 for ; Fri, 19 Jun 2020 09:45:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oneconvergence-com.20150623.gappssmtp.com header.i=@oneconvergence-com.20150623.gappssmtp.com header.b="qOAtmDP0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732215AbgFSJpi (ORCPT ); Fri, 19 Jun 2020 05:45:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729718AbgFSJpg (ORCPT ); Fri, 19 Jun 2020 05:45:36 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF013C06174E for ; Fri, 19 Jun 2020 02:45:36 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id 64so4194616pfv.11 for ; Fri, 19 Jun 2020 02:45:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oneconvergence-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XSVy16fU9BTMGtWMzc5ICVRz6LkcJGA7uzuj4xyvtqw=; b=qOAtmDP0BBH2CB/68DQTtvqc/1VCvRxjZ/SdRj7la/mCGeVLt8Rc/3eCwwZUjkra0X enq9eO6y0uuTk+n/0CIAb0EVZZINlosUnXqlKrH50lt5y3lswZI5JF9XMBbFZ8WSDtB4 DG8+0eX8onpVsePnJjY9S/dU1cmON0Up8ahu94JehHBli1WwGPYA4pRejC06lz+4krFG r/XD6JBdr3hpxyzoA1jFohmn6uK+NWOU/iaqBbPXzNaaG1+W+TP2us9YoCB7TsU2zpok oAn5P1NSHBYFXvJCdyM91jcpIOM5KcEiLl1zU4PJSWiaSZgGgSe1xGamTIUvG8oZgB4a sE3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XSVy16fU9BTMGtWMzc5ICVRz6LkcJGA7uzuj4xyvtqw=; b=VFsHbQUZ9zcwILoBVUU7s2VYNTaDYwewaQq7zEh23dPTSlKQiDsJHDmThdZmcL+Gmc 28OFIVE3EogkeHP7KcT5MPX5oUMIzIqBRfUWkeGBEWKlnK0HwDKTvfnCzab3BnOkQjHr nJR8mM8V4fT4fn3hsIByYTrmdgHdadDxUN6DkjqAmrWTf8qHIjDifSaVwVaIWTkF0zCD M0IM8RRBSWPioqHiYCPeuNX22Jp3mfuhP0GhD8uyXYbHAqKe+7tata8bCT5PFOg1wnug btt4By39DDnflgYUtAVzsqUjGL5DJgKawq49YG6aL22UjNHkuZTngDQygOTf7pv8s4XO 4rYQ== X-Gm-Message-State: AOAM531WzFjRm5Q3qOD/vQg3a3ex2vCPBJO5hxEzQ+QmTJYRvj1Vrqw+ K3X1GWb6CObCFkt+zKhHXqs++Q== X-Google-Smtp-Source: ABdhPJyf9V3/e7PAn78N07IN3NI7bcM2yUdzfNmnfqMvxmszh0Uj0xtE9FOCAtb/ZFzbgKcY04XyRA== X-Received: by 2002:a63:935c:: with SMTP id w28mr2364230pgm.174.1592559936385; Fri, 19 Jun 2020 02:45:36 -0700 (PDT) Received: from localhost.localdomain ([27.57.206.119]) by smtp.gmail.com with ESMTPSA id m20sm5896306pfk.52.2020.06.19.02.45.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jun 2020 02:45:36 -0700 (PDT) From: dsatish To: davem@davemloft.net Cc: jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, kuba@kernel.org, netdev@vger.kernel.org, simon.horman@netronome.com, kesavac@gmail.com, satish.d@oneconvergence.com, prathibha.nagooru@oneconvergence.com, intiyaz.basha@oneconvergence.com, jai.rana@oneconvergence.com Subject: [PATCH net-next 1/3] cls_flower: Set addr_type when ip mask is non-zero Date: Fri, 19 Jun 2020 15:11:54 +0530 Message-Id: <20200619094156.31184-2-satish.d@oneconvergence.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200619094156.31184-1-satish.d@oneconvergence.com> References: <20200619094156.31184-1-satish.d@oneconvergence.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Set the address type in the flower key and mask structure only if the mask is non-zero for IPv4 and IPv6 fields. During classifying packet, address type is set based on mask dissector of IPv4 and IPV6 keys, hence while inserting flow also addr type should be set based on the mask availability. This is required for the upcoming patch in OVS where OVS offloads all the fields that are part of the flower key irrespective of whether the mask for those fields are zero or nonzero. Signed-off-by: Chandra Kesava Signed-off-by: Prathibha Nagooru Signed-off-by: Satish Dhote --- net/sched/cls_flower.c | 66 ++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c index b2da37286082..64b70d396397 100644 --- a/net/sched/cls_flower.c +++ b/net/sched/cls_flower.c @@ -1422,6 +1422,26 @@ static int fl_set_key_ct(struct nlattr **tb, return 0; } +#define FL_KEY_MEMBER_OFFSET(member) offsetof(struct fl_flow_key, member) +#define FL_KEY_MEMBER_SIZE(member) sizeof_field(struct fl_flow_key, member) + +#define FL_KEY_IS_MASKED(mask, member) \ + memchr_inv(((char *)mask) + FL_KEY_MEMBER_OFFSET(member), \ + 0, FL_KEY_MEMBER_SIZE(member)) \ + +#define FL_KEY_SET(keys, cnt, id, member) \ + do { \ + keys[cnt].key_id = id; \ + keys[cnt].offset = FL_KEY_MEMBER_OFFSET(member); \ + cnt++; \ + } while (0) + +#define FL_KEY_SET_IF_MASKED(mask, keys, cnt, id, member) \ + do { \ + if (FL_KEY_IS_MASKED(mask, member)) \ + FL_KEY_SET(keys, cnt, id, member); \ + } while (0) + static int fl_set_key(struct net *net, struct nlattr **tb, struct fl_flow_key *key, struct fl_flow_key *mask, struct netlink_ext_ack *extack) @@ -1484,23 +1504,27 @@ static int fl_set_key(struct net *net, struct nlattr **tb, } if (tb[TCA_FLOWER_KEY_IPV4_SRC] || tb[TCA_FLOWER_KEY_IPV4_DST]) { - key->control.addr_type = FLOW_DISSECTOR_KEY_IPV4_ADDRS; - mask->control.addr_type = ~0; fl_set_key_val(tb, &key->ipv4.src, TCA_FLOWER_KEY_IPV4_SRC, &mask->ipv4.src, TCA_FLOWER_KEY_IPV4_SRC_MASK, sizeof(key->ipv4.src)); fl_set_key_val(tb, &key->ipv4.dst, TCA_FLOWER_KEY_IPV4_DST, &mask->ipv4.dst, TCA_FLOWER_KEY_IPV4_DST_MASK, sizeof(key->ipv4.dst)); + if (FL_KEY_IS_MASKED(mask, ipv4)) { + key->control.addr_type = FLOW_DISSECTOR_KEY_IPV4_ADDRS; + mask->control.addr_type = ~0; + } } else if (tb[TCA_FLOWER_KEY_IPV6_SRC] || tb[TCA_FLOWER_KEY_IPV6_DST]) { - key->control.addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS; - mask->control.addr_type = ~0; fl_set_key_val(tb, &key->ipv6.src, TCA_FLOWER_KEY_IPV6_SRC, &mask->ipv6.src, TCA_FLOWER_KEY_IPV6_SRC_MASK, sizeof(key->ipv6.src)); fl_set_key_val(tb, &key->ipv6.dst, TCA_FLOWER_KEY_IPV6_DST, &mask->ipv6.dst, TCA_FLOWER_KEY_IPV6_DST_MASK, sizeof(key->ipv6.dst)); + if (FL_KEY_IS_MASKED(mask, ipv6)) { + key->control.addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS; + mask->control.addr_type = ~0; + } } if (key->basic.ip_proto == IPPROTO_TCP) { @@ -1581,8 +1605,6 @@ static int fl_set_key(struct net *net, struct nlattr **tb, if (tb[TCA_FLOWER_KEY_ENC_IPV4_SRC] || tb[TCA_FLOWER_KEY_ENC_IPV4_DST]) { - key->enc_control.addr_type = FLOW_DISSECTOR_KEY_IPV4_ADDRS; - mask->enc_control.addr_type = ~0; fl_set_key_val(tb, &key->enc_ipv4.src, TCA_FLOWER_KEY_ENC_IPV4_SRC, &mask->enc_ipv4.src, @@ -1593,12 +1615,15 @@ static int fl_set_key(struct net *net, struct nlattr **tb, &mask->enc_ipv4.dst, TCA_FLOWER_KEY_ENC_IPV4_DST_MASK, sizeof(key->enc_ipv4.dst)); + if (FL_KEY_IS_MASKED(mask, enc_ipv4)) { + key->enc_control.addr_type = + FLOW_DISSECTOR_KEY_IPV4_ADDRS; + mask->enc_control.addr_type = ~0; + } } if (tb[TCA_FLOWER_KEY_ENC_IPV6_SRC] || tb[TCA_FLOWER_KEY_ENC_IPV6_DST]) { - key->enc_control.addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS; - mask->enc_control.addr_type = ~0; fl_set_key_val(tb, &key->enc_ipv6.src, TCA_FLOWER_KEY_ENC_IPV6_SRC, &mask->enc_ipv6.src, @@ -1609,6 +1634,11 @@ static int fl_set_key(struct net *net, struct nlattr **tb, &mask->enc_ipv6.dst, TCA_FLOWER_KEY_ENC_IPV6_DST_MASK, sizeof(key->enc_ipv6.dst)); + if (FL_KEY_IS_MASKED(mask, enc_ipv6)) { + key->enc_control.addr_type = + FLOW_DISSECTOR_KEY_IPV6_ADDRS; + mask->enc_control.addr_type = ~0; + } } fl_set_key_val(tb, &key->enc_key_id.keyid, TCA_FLOWER_KEY_ENC_KEY_ID, @@ -1667,26 +1697,6 @@ static int fl_init_mask_hashtable(struct fl_flow_mask *mask) return rhashtable_init(&mask->ht, &mask->filter_ht_params); } -#define FL_KEY_MEMBER_OFFSET(member) offsetof(struct fl_flow_key, member) -#define FL_KEY_MEMBER_SIZE(member) sizeof_field(struct fl_flow_key, member) - -#define FL_KEY_IS_MASKED(mask, member) \ - memchr_inv(((char *)mask) + FL_KEY_MEMBER_OFFSET(member), \ - 0, FL_KEY_MEMBER_SIZE(member)) \ - -#define FL_KEY_SET(keys, cnt, id, member) \ - do { \ - keys[cnt].key_id = id; \ - keys[cnt].offset = FL_KEY_MEMBER_OFFSET(member); \ - cnt++; \ - } while(0); - -#define FL_KEY_SET_IF_MASKED(mask, keys, cnt, id, member) \ - do { \ - if (FL_KEY_IS_MASKED(mask, member)) \ - FL_KEY_SET(keys, cnt, id, member); \ - } while(0); - static void fl_init_dissector(struct flow_dissector *dissector, struct fl_flow_key *mask) { From patchwork Fri Jun 19 09:41:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: dsatish X-Patchwork-Id: 217545 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A4E0C433E0 for ; Fri, 19 Jun 2020 09:46:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 70C5C2070A for ; Fri, 19 Jun 2020 09:46:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oneconvergence-com.20150623.gappssmtp.com header.i=@oneconvergence-com.20150623.gappssmtp.com header.b="07trk6qW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732239AbgFSJqL (ORCPT ); Fri, 19 Jun 2020 05:46:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729718AbgFSJqH (ORCPT ); Fri, 19 Jun 2020 05:46:07 -0400 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD967C06174E for ; Fri, 19 Jun 2020 02:46:06 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id y18so3735844plr.4 for ; Fri, 19 Jun 2020 02:46:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oneconvergence-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=U+TSRhpjMCC5R2Ooi/N/kaAswzU8zvrL1OW1HTQ1MAA=; b=07trk6qWLCW72Et1H5twjTVtT2UzikacGVNdziAkqcq4pgRHEtgsUeGo7utstzVtwO ob6pAZ05SKCWYAlblbxkL5A919xY8PGh6FfNDycU0DHChNY9iZjL8GsSmZxred0GNWcw XvvaDCPJb2pUD0FZunQ+ynWrLexBbHZswOcNqNDF9i65F9xpeFtKc2TVfCprpl3BEWvj AKQZ/GO989joGD0J9ORb0scU9rgcnDcSA78zrSaLtT2crvdY+QplNY5HW1yaXtmyji3A iS4HGbQ8Ro+wj4IbCH5Lczy4b61IiirtbzI2qRaRf0R008NeR7wpQOToD5j2aHhdDFRb J5gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=U+TSRhpjMCC5R2Ooi/N/kaAswzU8zvrL1OW1HTQ1MAA=; b=bkvkXfI6YiJGXGQmZzYYQRupEtVH8GbtB/4tmGoquZ9DNJpEHgMqwzPpFKTtPzfJ/T Nalb4Tf/HZe73yem7+fYeUoZgl0eLB8nIJ8Nc0TQ8vQu8UwkFDyIXH+aS3MyGDex8NzU ZYGRpFDKVvrBRtItL8Ww8NO4KZ7Z0Ec4CxvTp2Az1+2V6xFZuAvpYW1KjlEA0/FOXM+0 vwWCkFUP0Ievj2vv+Ycs2yGdPsVH4ih7BRqta7yszTmG4L4oBL1ykKEXf2c5/WyuAGtw dSKGxkkrB3rWmEfIIjTbQYUoYZboJyNCXSCeFxketOtlWUDfWAJuCeCw8IXI3caZRFQN 00HA== X-Gm-Message-State: AOAM532X554MOKuxf7oQTJIQ4BRM2H/dvwYDhHvH0WKCV8oDpbvhorU8 HraD0zIEwiSo/ds+Q6OYozbDKw== X-Google-Smtp-Source: ABdhPJz7+AdtbL/BQMAt6+rsOeqVv9Znq9GG7pLMNry2vLOoKws6kTZuP9WD21BTmqEc5YNf7PKeTQ== X-Received: by 2002:a17:902:b106:: with SMTP id q6mr7274724plr.23.1592559966243; Fri, 19 Jun 2020 02:46:06 -0700 (PDT) Received: from localhost.localdomain ([27.57.206.119]) by smtp.gmail.com with ESMTPSA id m20sm5896306pfk.52.2020.06.19.02.46.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jun 2020 02:46:05 -0700 (PDT) From: dsatish To: davem@davemloft.net Cc: jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, kuba@kernel.org, netdev@vger.kernel.org, simon.horman@netronome.com, kesavac@gmail.com, satish.d@oneconvergence.com, prathibha.nagooru@oneconvergence.com, intiyaz.basha@oneconvergence.com, jai.rana@oneconvergence.com Subject: [PATCH net-next 3/3] cls_flower: Allow flow offloading though masked key exist. Date: Fri, 19 Jun 2020 15:11:56 +0530 Message-Id: <20200619094156.31184-4-satish.d@oneconvergence.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200619094156.31184-1-satish.d@oneconvergence.com> References: <20200619094156.31184-1-satish.d@oneconvergence.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org A packet reaches OVS user space, only if, either there is no rule in datapath/hardware or there is race condition that the flow is added to hardware but before it is processed another packet arrives. It is possible hardware as part of its limitations/optimizations remove certain flows. To handle such cases where the hardware lost the flows, tc can offload to hardware if it receives a flow for which there exists an entry in its flow table. To handle such cases TC when it returns EEXIST error, also programs the flow in hardware, if hardware offload is enabled. Signed-off-by: Chandra Kesava Signed-off-by: Prathibha Nagooru Signed-off-by: Satish Dhote --- net/sched/cls_flower.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c index f1a5352cbb04..d718233cd5b9 100644 --- a/net/sched/cls_flower.c +++ b/net/sched/cls_flower.c @@ -431,7 +431,8 @@ static void fl_hw_destroy_filter(struct tcf_proto *tp, struct cls_fl_filter *f, static int fl_hw_replace_filter(struct tcf_proto *tp, struct cls_fl_filter *f, bool rtnl_held, - struct netlink_ext_ack *extack) + struct netlink_ext_ack *extack, + unsigned long cookie) { struct tcf_block *block = tp->chain->block; struct flow_cls_offload cls_flower = {}; @@ -444,7 +445,7 @@ static int fl_hw_replace_filter(struct tcf_proto *tp, tc_cls_common_offload_init(&cls_flower.common, tp, f->flags, extack); cls_flower.command = FLOW_CLS_REPLACE; - cls_flower.cookie = (unsigned long) f; + cls_flower.cookie = cookie; cls_flower.rule->match.dissector = &f->mask->dissector; cls_flower.rule->match.mask = &f->mask->key; cls_flower.rule->match.key = &f->mkey; @@ -2024,11 +2025,25 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, fl_init_unmasked_key_dissector(&fnew->unmasked_key_dissector); err = fl_ht_insert_unique(fnew, fold, &in_ht); - if (err) + if (err) { + /* It is possible Hardware lost the flow even though TC has it, + * and flow miss in hardware causes controller to offload flow again. + */ + if (err == -EEXIST && !tc_skip_hw(fnew->flags)) { + struct cls_fl_filter *f = + __fl_lookup(fnew->mask, &fnew->mkey); + + if (f) + fl_hw_replace_filter(tp, fnew, rtnl_held, + extack, + (unsigned long)(f)); + } goto errout_mask; + } if (!tc_skip_hw(fnew->flags)) { - err = fl_hw_replace_filter(tp, fnew, rtnl_held, extack); + err = fl_hw_replace_filter(tp, fnew, rtnl_held, extack, + (unsigned long)fnew); if (err) goto errout_ht; }