From patchwork Wed Jul 5 13:43:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Nogueira X-Patchwork-Id: 13302169 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 D9BBDD30E for ; Wed, 5 Jul 2023 13:43:44 +0000 (UTC) Received: from mail-ot1-x335.google.com (mail-ot1-x335.google.com [IPv6:2607:f8b0:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8ACE6BA for ; Wed, 5 Jul 2023 06:43:43 -0700 (PDT) Received: by mail-ot1-x335.google.com with SMTP id 46e09a7af769-6b883e1e9d5so4036154a34.1 for ; Wed, 05 Jul 2023 06:43:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20221208.gappssmtp.com; s=20221208; t=1688564623; x=1691156623; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YH/+HHBZpaYq82Xv1Y/dmkD7CI2WEhzUomatclhV1OY=; b=0salLUuZUjgpspp2LveFMPCWZbzT+J6P6GMN3/cbZQ7zoQkikAcNDBnHxviQ/2SqhS BhI3v11iFf2C2PwYnSVrzPLSXoGng4r7UT19o8Gi39qbN1PQ5c+Aanw7sISETwP5PkJ4 rdBFqkGV/4dPRRuHJjgogt5r5ZEZ7rccAEUaNvc+L4YjNNF61iTarQNDH4dZTsLXh9VP 3jUigK+2L6M6XwfIeb12lLlXITsfwo1CRbqDFks+BIU3A7X2V8Gc9jELuqiusOIajDzU IXsMPOpxu9igIwG0tgOAU6tGGTT8W1tViAkOC0wiZWTS01OorfMWS8vpxyZICwN28KSL RElQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688564623; x=1691156623; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YH/+HHBZpaYq82Xv1Y/dmkD7CI2WEhzUomatclhV1OY=; b=HATgWG5bSPrY0kLzBRDJfnS8Jv0ZrT8U4xFediZ3JvjO8bXPaN7Pm2Dr5XyRV+Vf8q hOi4Hu01ZorxOLrnnF2DBLa/6jCwuaGxC36ZDCk5SvyGFaZYtv91hP6s6J74kyS0J5W6 Mqgz35NOtHTDU0DPB4UxbRwVmsw4sg8OuIcBiNeD4VT8N9B9mIIGLw2nU2uzSjRCZ0It 1X5p8J4gohZvhi3pU6D+a1jp0luaR4KUqaHvTeBZxTycEbQBbUR15Le8QPUpEPu3pM4F j0cLrGrTRWoY48/L4XrxQghoah51FgmB6oDcZjMFCINPrQ3LXAHv1zGaWMUXKqIxWdsW 7eUQ== X-Gm-Message-State: AC+VfDxNkDwg1UV61aXPlDF2MkV/orm8WROO436AaspKRn2yZpTb4WWD MlcIXxS7cn3iR+VNRxtAqGlNsU7XvxAvE+Tpnks= X-Google-Smtp-Source: ACHHUZ6Rg5H9Yadi/fUPhQm2dmrhi18NpncaB51ACMWKhhPPBYM593dSfYTUkM2/FI0n9oUk/MH2UQ== X-Received: by 2002:a05:6830:1d62:b0:6b8:80f6:5f49 with SMTP id l2-20020a0568301d6200b006b880f65f49mr12435350oti.14.1688564622818; Wed, 05 Jul 2023 06:43:42 -0700 (PDT) Received: from exu-caveira.tail33bf8.ts.net ([2804:7f1:e2c0:f126:5457:8acf:73e7:5bf2]) by smtp.gmail.com with ESMTPSA id n11-20020a9d740b000000b006b73b6b738esm4516450otk.36.2023.07.05.06.43.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 06:43:42 -0700 (PDT) From: Victor Nogueira To: netdev@vger.kernel.org Cc: jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, pctammela@mojatatu.com, simon.horman@corigine.com, kernel@mojatatu.com Subject: [PATCH net v2 1/5] net: sched: cls_bpf: Undo tcf_bind_filter in case of an error Date: Wed, 5 Jul 2023 10:43:25 -0300 Message-Id: <20230705134329.102345-2-victor@mojatatu.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230705134329.102345-1-victor@mojatatu.com> References: <20230705134329.102345-1-victor@mojatatu.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org If cls_bpf_offload errors out, we must also undo tcf_bind_filter that was done in cls_bpf_set_parms. Fix that by calling tcf_unbind_filter in errout_parms. Fixes: eadb41489fd2 ("net: cls_bpf: add support for marking filters as hardware-only") Signed-off-by: Victor Nogueira Acked-by: Jamal Hadi Salim --- net/sched/cls_bpf.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/net/sched/cls_bpf.c b/net/sched/cls_bpf.c index 466c26df853a..c45321fb3a5e 100644 --- a/net/sched/cls_bpf.c +++ b/net/sched/cls_bpf.c @@ -409,7 +409,7 @@ static int cls_bpf_prog_from_efd(struct nlattr **tb, struct cls_bpf_prog *prog, static int cls_bpf_set_parms(struct net *net, struct tcf_proto *tp, struct cls_bpf_prog *prog, unsigned long base, struct nlattr **tb, struct nlattr *est, u32 flags, - struct netlink_ext_ack *extack) + bool *bound_to_filter, struct netlink_ext_ack *extack) { bool is_bpf, is_ebpf, have_exts = false; u32 gen_flags = 0; @@ -451,6 +451,7 @@ static int cls_bpf_set_parms(struct net *net, struct tcf_proto *tp, if (tb[TCA_BPF_CLASSID]) { prog->res.classid = nla_get_u32(tb[TCA_BPF_CLASSID]); tcf_bind_filter(tp, &prog->res, base); + *bound_to_filter = true; } return 0; @@ -465,6 +466,7 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb, struct cls_bpf_head *head = rtnl_dereference(tp->root); struct cls_bpf_prog *oldprog = *arg; struct nlattr *tb[TCA_BPF_MAX + 1]; + bool bound_to_filter = false; struct cls_bpf_prog *prog; int ret; @@ -505,7 +507,7 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb, prog->handle = handle; ret = cls_bpf_set_parms(net, tp, prog, base, tb, tca[TCA_RATE], flags, - extack); + &bound_to_filter, extack); if (ret < 0) goto errout_idr; @@ -530,6 +532,8 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb, return 0; errout_parms: + if (bound_to_filter) + tcf_unbind_filter(tp, &prog->res); cls_bpf_free_parms(prog); errout_idr: if (!oldprog) From patchwork Wed Jul 5 13:43:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Nogueira X-Patchwork-Id: 13302170 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 D1E29D512 for ; Wed, 5 Jul 2023 13:43:47 +0000 (UTC) Received: from mail-ot1-x335.google.com (mail-ot1-x335.google.com [IPv6:2607:f8b0:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97CA29F for ; Wed, 5 Jul 2023 06:43:46 -0700 (PDT) Received: by mail-ot1-x335.google.com with SMTP id 46e09a7af769-6b708b97418so5623338a34.3 for ; Wed, 05 Jul 2023 06:43:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20221208.gappssmtp.com; s=20221208; t=1688564626; x=1691156626; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2fjr0w0lmzf3UreyTHM2WtjDff/EVI1BV+jgJEeWJ1w=; b=xtfacyj/Prrnk/S5mDSHOFRDKZSBj5Xm1Vl5i8MUGD2/jmke7irz66PYNE+BKi1ImK 3ZrUJZdx2XAmy8u8p5EKNyMW0SSOqR7oq9b4KBcENwQbn4SiFSn8qL6dtGWcyLzHGLd2 IASaHsI+hnJdkFhguWaAWIMc1oNIXvfSCIyyfrB6f4PY3EbfeaJj6QFRiEx4kKq67NQP EnK5FedrwPk0JtBdMch0TjxHdfTMIyIiPNARKW6Mvub5rZPbIgDFWVDIZXQPcfprHcp5 dvEQtcuwGdZ3Y8MjFPPalJd80J9Ml5HSsY6lJaVaOVU3ygMkxiaWNwAhCG/E/GHvF+Jj f1VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688564626; x=1691156626; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2fjr0w0lmzf3UreyTHM2WtjDff/EVI1BV+jgJEeWJ1w=; b=LH1A1d/zm1L5802JQbx9G93Vlm+JtUFGfg4bmQz0535pzBM7si1TOTQgjc3QcG55mh +RCEOyMZwg2/B+8bjrWrs302gSdWRtI6O5nLu/TViNZ4pfrVfufvKf8hg64KpBRaCBKz 1j+jxJv9QytcP+O5Fp2rjnl3Dz9ys5LW3kNGZ0VKaxDtvcDunHwgWU4t9mtVN0oO4vZc zVkUpeu29tNw2IFBxLUuJFKPgaAXrQS2nKbgXbaOURO3dc6c7K5iEhFoBigAiSZBalN0 qYL2K8Mv1fHyy+1ihHjgNldrq206rrMb8/jIivtrYzR9uHKGTGrB8PajYQhyUr4UcBOk /77g== X-Gm-Message-State: AC+VfDzLh50GPUHhvIwWZuPIMQKUk7Jg3+NNgjrz0OR+qZ9WAXZ727vv ruhVAREebUpFwDEca6Pc2/Giy/ay1l8vyNdl8SU= X-Google-Smtp-Source: ACHHUZ7Sp/nUppM/Jd5E/TeArpzJVEZE2SiURvRHvQkp/PoQ736bLN1QyhFSsRcO4O9cITJjtVy8gQ== X-Received: by 2002:a9d:7483:0:b0:6b7:4e97:343 with SMTP id t3-20020a9d7483000000b006b74e970343mr16529756otk.27.1688564625872; Wed, 05 Jul 2023 06:43:45 -0700 (PDT) Received: from exu-caveira.tail33bf8.ts.net ([2804:7f1:e2c0:f126:5457:8acf:73e7:5bf2]) by smtp.gmail.com with ESMTPSA id n11-20020a9d740b000000b006b73b6b738esm4516450otk.36.2023.07.05.06.43.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 06:43:45 -0700 (PDT) From: Victor Nogueira To: netdev@vger.kernel.org Cc: jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, pctammela@mojatatu.com, simon.horman@corigine.com, kernel@mojatatu.com Subject: [PATCH net v2 2/5] net: sched: cls_matchall: Undo tcf_bind_filter in case of failure after mall_set_parms Date: Wed, 5 Jul 2023 10:43:26 -0300 Message-Id: <20230705134329.102345-3-victor@mojatatu.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230705134329.102345-1-victor@mojatatu.com> References: <20230705134329.102345-1-victor@mojatatu.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org In case an error occurred after mall_set_parms executed successfully, we must undo the tcf_bind_filter call it issues. Fix that by calling tcf_unbind_filter in err_replace_hw_filter label. Fixes: ec2507d2a306 ("net/sched: cls_matchall: Fix error path") Signed-off-by: Victor Nogueira Acked-by: Jamal Hadi Salim --- net/sched/cls_matchall.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/net/sched/cls_matchall.c b/net/sched/cls_matchall.c index fa3bbd187eb9..e4b649669835 100644 --- a/net/sched/cls_matchall.c +++ b/net/sched/cls_matchall.c @@ -163,7 +163,7 @@ static int mall_set_parms(struct net *net, struct tcf_proto *tp, struct cls_mall_head *head, unsigned long base, struct nlattr **tb, struct nlattr *est, u32 flags, u32 fl_flags, - struct netlink_ext_ack *extack) + bool *bound_to_filter, struct netlink_ext_ack *extack) { int err; @@ -175,6 +175,7 @@ static int mall_set_parms(struct net *net, struct tcf_proto *tp, if (tb[TCA_MATCHALL_CLASSID]) { head->res.classid = nla_get_u32(tb[TCA_MATCHALL_CLASSID]); tcf_bind_filter(tp, &head->res, base); + *bound_to_filter = true; } return 0; } @@ -187,6 +188,7 @@ static int mall_change(struct net *net, struct sk_buff *in_skb, { struct cls_mall_head *head = rtnl_dereference(tp->root); struct nlattr *tb[TCA_MATCHALL_MAX + 1]; + bool bound_to_filter = false; struct cls_mall_head *new; u32 userflags = 0; int err; @@ -227,7 +229,7 @@ static int mall_change(struct net *net, struct sk_buff *in_skb, } err = mall_set_parms(net, tp, new, base, tb, tca[TCA_RATE], - flags, new->flags, extack); + flags, new->flags, &bound_to_filter, extack); if (err) goto err_set_parms; @@ -246,6 +248,8 @@ static int mall_change(struct net *net, struct sk_buff *in_skb, return 0; err_replace_hw_filter: + if (bound_to_filter) + tcf_unbind_filter(tp, &new->res); err_set_parms: free_percpu(new->pf); err_alloc_percpu: From patchwork Wed Jul 5 13:43:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Nogueira X-Patchwork-Id: 13302171 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 243D7D512 for ; Wed, 5 Jul 2023 13:43:51 +0000 (UTC) Received: from mail-oo1-xc2f.google.com (mail-oo1-xc2f.google.com [IPv6:2607:f8b0:4864:20::c2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C68CDBA for ; Wed, 5 Jul 2023 06:43:49 -0700 (PDT) Received: by mail-oo1-xc2f.google.com with SMTP id 006d021491bc7-56584266c41so4596725eaf.2 for ; Wed, 05 Jul 2023 06:43:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20221208.gappssmtp.com; s=20221208; t=1688564629; x=1691156629; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sCpSn7+3UdgcAnJYuktsHdgb0SDtmYa6u50lebB6KmE=; b=pu8EmGdXAwxavII1YFtmnO9/5nXSGj07VFNww2DcTvAr2T4X/o2rJl5ccwLCZrPNnK GnfUoWnHLi0/LHrzPo/ydXZC0YVAt/sC4q+atEbIrEi9zlLbBDLco+VLo/tyARf3iuGz YUANjcfF6UhI5/9TuVXS+hYHl880I/LNiC+7ykIwYtFX8bLXj1EV2PQi8FA3BwjppTvY xDMLIRqw0COcA4LKnkV1broG31aUoVQJmXSAI/MbnejnYRYY/We7f/n1QyM62opUENSn Q5sXe3jA2pSmlepli8ZwoQE8ITrvTchtdpw9ibg72YKBpt/2hhTj4ol7MfMqPWJKrabs qDSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688564629; x=1691156629; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sCpSn7+3UdgcAnJYuktsHdgb0SDtmYa6u50lebB6KmE=; b=C/MTyH63lXXCbfeh1SBdzYtbvffxLXLtve13oGuYH3r3SYL9CRwyqB5pdWMTOrtHhJ K/Gprs6XJvDDFSbw/lHTIS7MMfrjEDualM7SuOH6quS9t9FcjhVYRknK+236Z53pZRBF hWW5KEKedDyCfRxDFzTjnFG6J+tFynz4RSyePohQd75xN5H+RxCSC1Kr1IO6YgAfjEQ+ 9tpIKj9A1MDQmMZOFVdA636X332tpTOIq74DONGHqliUCZQ/GY1iAWiEHgE9SnT2VzIa vFnWAKFbZq+uvxHLZ/LGZqlW1WAyR/GP7JIQx4mqlm4S5hDO9vpXQMfdbZcfo/Xq/wbC P9xw== X-Gm-Message-State: AC+VfDwCEZPY/f0rnob3sC5WB/DTShneD4RpjDVLpgzXCeYzak+3T1ew lMjA9oESQlxC7rBaeLumCNp5m9lt1DSSFHaacMk= X-Google-Smtp-Source: ACHHUZ650/JhBqV0ZGWHRo6LvE/60nZScvh0HczP4tcMm+bhN8wkg58MR6EexSZsEtGd+20AqPvdng== X-Received: by 2002:a4a:1d81:0:b0:565:c862:ad77 with SMTP id 123-20020a4a1d81000000b00565c862ad77mr11797016oog.5.1688564628913; Wed, 05 Jul 2023 06:43:48 -0700 (PDT) Received: from exu-caveira.tail33bf8.ts.net ([2804:7f1:e2c0:f126:5457:8acf:73e7:5bf2]) by smtp.gmail.com with ESMTPSA id n11-20020a9d740b000000b006b73b6b738esm4516450otk.36.2023.07.05.06.43.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 06:43:48 -0700 (PDT) From: Victor Nogueira To: netdev@vger.kernel.org Cc: jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, pctammela@mojatatu.com, simon.horman@corigine.com, kernel@mojatatu.com Subject: [PATCH net v2 3/5] net: sched: cls_u32: Undo tcf_bind_filter if u32_replace_hw_knode Date: Wed, 5 Jul 2023 10:43:27 -0300 Message-Id: <20230705134329.102345-4-victor@mojatatu.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230705134329.102345-1-victor@mojatatu.com> References: <20230705134329.102345-1-victor@mojatatu.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org When u32_replace_hw_knode fails, we need to undo the tcf_bind_filter operation done at u32_set_parms. Fixes: d34e3e181395 ("net: cls_u32: Add support for skip-sw flag to tc u32 classifier.") Signed-off-by: Victor Nogueira Acked-by: Jamal Hadi Salim --- net/sched/cls_u32.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index d15d50de7980..7e32c018941f 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -712,11 +712,13 @@ static const struct nla_policy u32_policy[TCA_U32_MAX + 1] = { [TCA_U32_FLAGS] = { .type = NLA_U32 }, }; +#define U32_SET_FLAGS_BOUND 0x1 + static int u32_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base, struct tc_u_knode *n, struct nlattr **tb, struct nlattr *est, u32 flags, u32 fl_flags, - struct netlink_ext_ack *extack) + u8 *set_flags, struct netlink_ext_ack *extack) { int err, ifindex = -1; @@ -763,6 +765,7 @@ static int u32_set_parms(struct net *net, struct tcf_proto *tp, if (tb[TCA_U32_CLASSID]) { n->res.classid = nla_get_u32(tb[TCA_U32_CLASSID]); tcf_bind_filter(tp, &n->res, base); + *set_flags |= U32_SET_FLAGS_BOUND; } if (ifindex >= 0) @@ -859,6 +862,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, struct nlattr *opt = tca[TCA_OPTIONS]; struct nlattr *tb[TCA_U32_MAX + 1]; u32 htid, userflags = 0; + u8 set_flags = 0; size_t sel_size; int err; @@ -905,7 +909,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, err = u32_set_parms(net, tp, base, new, tb, tca[TCA_RATE], flags, new->flags, - extack); + &set_flags, extack); if (err) { __u32_destroy_key(new); @@ -914,6 +918,9 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, err = u32_replace_hw_knode(tp, new, flags, extack); if (err) { + if (set_flags & U32_SET_FLAGS_BOUND) + tcf_unbind_filter(tp, &new->res); + __u32_destroy_key(new); return err; } @@ -1075,14 +1082,14 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, #endif err = u32_set_parms(net, tp, base, n, tb, tca[TCA_RATE], - flags, n->flags, extack); + flags, n->flags, &set_flags, extack); if (err == 0) { struct tc_u_knode __rcu **ins; struct tc_u_knode *pins; err = u32_replace_hw_knode(tp, n, flags, extack); if (err) - goto errhw; + goto errunbind; if (!tc_in_hw(n->flags)) n->flags |= TCA_CLS_FLAGS_NOT_IN_HW; @@ -1100,7 +1107,10 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, return 0; } -errhw: +errunbind: + if (set_flags & U32_SET_FLAGS_BOUND) + tcf_unbind_filter(tp, &n->res); + #ifdef CONFIG_CLS_U32_MARK free_percpu(n->pcpu_success); #endif From patchwork Wed Jul 5 13:43:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Nogueira X-Patchwork-Id: 13302172 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 DD011DDB3 for ; Wed, 5 Jul 2023 13:43:53 +0000 (UTC) Received: from mail-ot1-x32a.google.com (mail-ot1-x32a.google.com [IPv6:2607:f8b0:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B120AF7 for ; Wed, 5 Jul 2023 06:43:52 -0700 (PDT) Received: by mail-ot1-x32a.google.com with SMTP id 46e09a7af769-6b44b5adfd3so5605167a34.3 for ; Wed, 05 Jul 2023 06:43:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20221208.gappssmtp.com; s=20221208; t=1688564632; x=1691156632; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DOSZmdtxdcqFdZz9feurErKzrQktfcZvPEQvUMObHoo=; b=l3AEVTQDCcFehFkpft0VCe4zpIGZ/5hpbEGBJNrzFYUAGox8N6LEpnmGLUNOmgfsfv FL6jzqYYtiJ25iPhYwfnUGr7pcttfkRItsTc3H+RRaoxIGcwAbAtpTj4GE2EHldTzzh5 dLybwViwx9UF9YAQoP+oSyCaq7P8mmUuhgIg9iacoi40WDJ9plRDhOvA0A1/2WEGE0P9 2IMHII30JlATJt50sXp/bNFEf6c2tbytZknoa+58rsuxSML77ii6+juUGnFDj9UkI4tl /oMrP6cVINAamiAm/H6YYWslnyxBJjMfugcjmWbQaZyOVkwFT1lbIG0AjJV4hFjSxm51 HoUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688564632; x=1691156632; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DOSZmdtxdcqFdZz9feurErKzrQktfcZvPEQvUMObHoo=; b=F/O4GjsLB1dQJnnK7BRPU1MsZFyhTDqEac5M0od49oq1EWym/A7+f4au02NdxcfjRs KCJyJUr1joqtYlXGgkOuJnpKhbrqLp5hXb/N1nV5DaX54xYXvYyjgCGAE4RJuhxBGF1g 4Pi4q5m2Bn+SGwQqN6wvCOPc32/Gmi64Sr4UxxaWqY00h+obY+AjWQUjkxK1LNTUpEQ1 CHFqh1+OGb1K7Hjn/Oil+3gT6mSGy7ljoXj/89cGRNAVUXipzSm12nsE4ctpTx6rEOo2 DJCwRCKpPlmlH/R7e2psxUtHGL0fvCbrLlO2345jZOIpmIrHRDOES7xan7KToNVZJSRc LU+g== X-Gm-Message-State: AC+VfDzzY3gncHtrwXdHZUHMmggcaP15lPJhASQaAMQC8M8HEHL78H2L 6H+w0Ru8O7qlSnaK7hQF+kwWlb1iME6NmkgBKsI= X-Google-Smtp-Source: ACHHUZ7XFyPAgSR9Zx/1gggUgZVybL2IooMppjkW772eA7f0Jzu2WCIhev0tF5I7/9hHF5zcrmMRMg== X-Received: by 2002:a05:6830:1e83:b0:6b8:886d:852 with SMTP id n3-20020a0568301e8300b006b8886d0852mr19155920otr.26.1688564631955; Wed, 05 Jul 2023 06:43:51 -0700 (PDT) Received: from exu-caveira.tail33bf8.ts.net ([2804:7f1:e2c0:f126:5457:8acf:73e7:5bf2]) by smtp.gmail.com with ESMTPSA id n11-20020a9d740b000000b006b73b6b738esm4516450otk.36.2023.07.05.06.43.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 06:43:51 -0700 (PDT) From: Victor Nogueira To: netdev@vger.kernel.org Cc: jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, pctammela@mojatatu.com, simon.horman@corigine.com, kernel@mojatatu.com Subject: [PATCH net v2 4/5] net: sched: cls_u32: Undo refcount decrement in case update failed Date: Wed, 5 Jul 2023 10:43:28 -0300 Message-Id: <20230705134329.102345-5-victor@mojatatu.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230705134329.102345-1-victor@mojatatu.com> References: <20230705134329.102345-1-victor@mojatatu.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org In the case of an update, when TCA_U32_LINK is set, u32_set_parms will decrement the refcount of the ht_down (struct tc_u_hnode) pointer present in the older u32 filter which we are replacing. However, if u32_replace_hw_knode errors out, the update command fails and that ht_down pointer continues decremented. To fix that, when u32_replace_hw_knode fails, check if ht_down's refcount was decremented and undo the decrement. Fixes: d34e3e181395 ("net: cls_u32: Add support for skip-sw flag to tc u32 classifier.") Signed-off-by: Victor Nogueira Acked-by: Jamal Hadi Salim --- net/sched/cls_u32.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index 7e32c018941f..12e78f81a259 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -713,6 +713,7 @@ static const struct nla_policy u32_policy[TCA_U32_MAX + 1] = { }; #define U32_SET_FLAGS_BOUND 0x1 +#define U32_SET_FLAGS_DECR_HTDOWN 0x2 static int u32_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base, @@ -759,8 +760,10 @@ static int u32_set_parms(struct net *net, struct tcf_proto *tp, ht_old = rtnl_dereference(n->ht_down); rcu_assign_pointer(n->ht_down, ht_down); - if (ht_old) + if (ht_old) { + *set_flags |= U32_SET_FLAGS_DECR_HTDOWN; ht_old->refcnt--; + } } if (tb[TCA_U32_CLASSID]) { n->res.classid = nla_get_u32(tb[TCA_U32_CLASSID]); @@ -921,6 +924,13 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, if (set_flags & U32_SET_FLAGS_BOUND) tcf_unbind_filter(tp, &new->res); + if (set_flags & U32_SET_FLAGS_DECR_HTDOWN) { + struct tc_u_hnode *ht_old; + + ht_old = rtnl_dereference(n->ht_down); + if (ht_old) + ht_old->refcnt++; + } __u32_destroy_key(new); return err; } From patchwork Wed Jul 5 13:43:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Nogueira X-Patchwork-Id: 13302173 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 1ED8D100B4 for ; Wed, 5 Jul 2023 13:43:57 +0000 (UTC) Received: from mail-ot1-x32e.google.com (mail-ot1-x32e.google.com [IPv6:2607:f8b0:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3FD41719 for ; Wed, 5 Jul 2023 06:43:55 -0700 (PDT) Received: by mail-ot1-x32e.google.com with SMTP id 46e09a7af769-6b73b839025so5626661a34.1 for ; Wed, 05 Jul 2023 06:43:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20221208.gappssmtp.com; s=20221208; t=1688564635; x=1691156635; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1ANUAhFcurjSsn3tEP4sBTjW84lEZQCuYwTyCYWeoN8=; b=rQ9JDd5XLbqrBR147PjINFhd/QJMekTwwOtWxgGztmg42iaGIn4fdweIW14lPYH9Nq DCAk54S2QYVQWlUQ5MSZ8+aIjDpGaILR6IwZYpYxcnpyMGSI7toe9sWoIDTCdmdgo1PE 3m9qw8kR5/n0+ETXXcxFbGx9Ncw54TgUOgs6WEF/EMMfOzYVlIIh0Io+kXbBOWXpthfz KkrTLZu71qkmNnnjwSh+dsMQt1yH1KXmemKxUpUqbpNOcChZgAmBdkOOD5W8/JdxhamE lvTW/SsJy6GYtDg66kuKfc48L2b3R/jAj5iWXBR/bpWnDtohTux5xzhh+03wgkcCWTsH kRkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688564635; x=1691156635; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1ANUAhFcurjSsn3tEP4sBTjW84lEZQCuYwTyCYWeoN8=; b=Mgvjp86CJebe15TNCvZxMV6q4+Q+Sam/s+nVamw4oz/E7E9hKxAOOCb45/y9TJ9RQp XgVGAEyoHlOTMUoYrEAmtkTECH5WXVmd9RvKKURd7jT5jLnsRJE13k4Wg8BnSBZecFB9 88AwpMiZ0tEpoO0+IJZrTzdLUHjVCTQqd7ag9Vfj6u9Uo7WMNmTQhc4Gg/RdggrnQfG5 XTEo8EsLpcd71ZNz75cW/Lg3U+2o7rK0bZtCpHeyGAWenJi8zjCDlFfh75VBTR4GaSEk xGIMK+yNCsXLyQXh+Ja6nwv4B1hT4G8l6msngiuoE01WL7H0HvezU2ISmFlzL8xFIFKD 7gxw== X-Gm-Message-State: AC+VfDxAvtxA2FePn6NcR9Aq+GxxwgE1MXvqToCCg4t20mda3r+XSq2m vhhYKAayzif3iRl5Bjo0hoOvYD+InH4laK1RniQ= X-Google-Smtp-Source: ACHHUZ4T6wa89oqydAuO/8gl4ul7nwnnW96mXM/a8w2hbd/h0FoEe91mbgHMn7nJ7BJg0WJENQvCeQ== X-Received: by 2002:a9d:7483:0:b0:6b7:4e97:343 with SMTP id t3-20020a9d7483000000b006b74e970343mr16530098otk.27.1688564634964; Wed, 05 Jul 2023 06:43:54 -0700 (PDT) Received: from exu-caveira.tail33bf8.ts.net ([2804:7f1:e2c0:f126:5457:8acf:73e7:5bf2]) by smtp.gmail.com with ESMTPSA id n11-20020a9d740b000000b006b73b6b738esm4516450otk.36.2023.07.05.06.43.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jul 2023 06:43:54 -0700 (PDT) From: Victor Nogueira To: netdev@vger.kernel.org Cc: jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, pctammela@mojatatu.com, simon.horman@corigine.com, kernel@mojatatu.com Subject: [PATCH net v2 5/5] net: sched: cls_flower: Undo tcf_bind_filter if fl_set_key fails Date: Wed, 5 Jul 2023 10:43:29 -0300 Message-Id: <20230705134329.102345-6-victor@mojatatu.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230705134329.102345-1-victor@mojatatu.com> References: <20230705134329.102345-1-victor@mojatatu.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org if TCA_FLOWER_CLASSID is specified in the netlink message, the code will call tcf_bind_filter. However, if any error occurs after that, the code should undo this by calling tcf_unbind_filter. When checking for TCA_FLOWER_CLASSID attribute, the code is calling for tcf_bind_fitler. Fixes: 77b9900ef53a ("tc: introduce Flower classifier") Signed-off-by: Victor Nogueira Acked-by: Jamal Hadi Salim --- net/sched/cls_flower.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c index 56065cc5a661..644b0097e6ae 100644 --- a/net/sched/cls_flower.c +++ b/net/sched/cls_flower.c @@ -2169,7 +2169,7 @@ static int fl_set_parms(struct net *net, struct tcf_proto *tp, struct nlattr *est, struct fl_flow_tmplt *tmplt, u32 flags, u32 fl_flags, - struct netlink_ext_ack *extack) + bool *bound_to_filter, struct netlink_ext_ack *extack) { int err; @@ -2185,18 +2185,20 @@ static int fl_set_parms(struct net *net, struct tcf_proto *tp, tcf_bind_filter(tp, &f->res, base); if (flags & TCA_ACT_FLAGS_NO_RTNL) rtnl_unlock(); + *bound_to_filter = true; } err = fl_set_key(net, tb, &f->key, &mask->key, extack); if (err) - return err; + goto unbind_filter; fl_mask_update_range(mask); fl_set_masked_key(&f->mkey, &f->key, mask); if (!fl_mask_fits_tmplt(tmplt, mask)) { NL_SET_ERR_MSG_MOD(extack, "Mask does not fit the template"); - return -EINVAL; + err = -EINVAL; + goto unbind_filter; } /* Enable tc skb extension if filter matches on data extracted from @@ -2208,6 +2210,17 @@ static int fl_set_parms(struct net *net, struct tcf_proto *tp, } return 0; + +unbind_filter: + if (*bound_to_filter) { + if (flags & TCA_ACT_FLAGS_NO_RTNL) + rtnl_lock(); + tcf_unbind_filter(tp, &f->res); + if (flags & TCA_ACT_FLAGS_NO_RTNL) + rtnl_unlock(); + *bound_to_filter = false; + } + return err; } static int fl_ht_insert_unique(struct cls_fl_filter *fnew, @@ -2241,6 +2254,7 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, struct cls_fl_head *head = fl_head_dereference(tp); bool rtnl_held = !(flags & TCA_ACT_FLAGS_NO_RTNL); struct cls_fl_filter *fold = *arg; + bool bound_to_filter = false; struct cls_fl_filter *fnew; struct fl_flow_mask *mask; struct nlattr **tb; @@ -2327,7 +2341,7 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, err = fl_set_parms(net, tp, fnew, mask, base, tb, tca[TCA_RATE], tp->chain->tmplt_priv, flags, fnew->flags, - extack); + &bound_to_filter, extack); if (err) goto errout_idr; @@ -2425,6 +2439,13 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, errout_mask: fl_mask_put(head, fnew->mask); errout_idr: + if (bound_to_filter) { + if (flags & TCA_ACT_FLAGS_NO_RTNL) + rtnl_lock(); + tcf_unbind_filter(tp, &fnew->res); + if (flags & TCA_ACT_FLAGS_NO_RTNL) + rtnl_unlock(); + } if (!fold) idr_remove(&head->handle_idr, fnew->handle); __fl_put(fnew);