From patchwork Tue Jul 4 15:14:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Nogueira X-Patchwork-Id: 13301377 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 057F46AA4 for ; Tue, 4 Jul 2023 15:15:10 +0000 (UTC) Received: from mail-ot1-x336.google.com (mail-ot1-x336.google.com [IPv6:2607:f8b0:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9611E6D for ; Tue, 4 Jul 2023 08:15:09 -0700 (PDT) Received: by mail-ot1-x336.google.com with SMTP id 46e09a7af769-6b71cdb47e1so4738303a34.2 for ; Tue, 04 Jul 2023 08:15:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20221208.gappssmtp.com; s=20221208; t=1688483709; x=1691075709; 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=vKmtpqIhXSx8wadQszqTZuxelRNDNDAGxDUQa+qcRfw=; b=faB8ugSv8pnCSpjfun6cKQvb2sYUIBVyF+wq3C3iAUMwIWbQs6d4f6jlLlyrtcyDa3 I+4IwmxxBjqmF5xUmPO2pCbxFiRlhMJ5FqJ2Dob3aUbSarUpbr0q/YpRzUCAcRbcBR25 DqnZqv5KNG27IlvRLPRyGGLl3UZd78q/hFVDtMleliKivd+SyRPdgdHAZyQU32uJX6YF UgkvVixLbMN8JsIshCsocx7bPZWInv9Ct2mYsutWSz0zJYB5sEVQR7Tp24CE6c20zbo8 rgb0xZPyn1JQbO60cYghvcx17AUxSQQSALPbqx5PyagMjlmqgelIOsMIiErhvuybph+f +1wQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688483709; x=1691075709; 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=vKmtpqIhXSx8wadQszqTZuxelRNDNDAGxDUQa+qcRfw=; b=OmDXTWFJaW8dVoAYx8c9zrMCNUrV7b7+Vo3P/waU0oc4W+5ZxRePKl8Sq1Rp4NVifR SQY97sx5NobNHvAqsrVmnaRSSmrM3AuLNu7y01QMffHIPsoTxqVYDl9bo/7oWlf0pY7X sWn6+FaqxepEVGxOv5FF15Lw9vfI7FqbdToL4H00QA923BjiCArfFO5OSKRRrcmE3tiJ /Pd8ojLnWFTT1DQPPh3fG9tnWsN3i9otduFIxE5DjZK3dWvUnhiqZCLjJgtAw8ZIpBCZ fuDGTOmJzx41inGdb5vwMJ7ck+jU8Um+u4+67TuLCkwdS3jvxeQX3CyZAreiSne5vsEy zXDA== X-Gm-Message-State: AC+VfDzCTSKaTcuWG4QGw7w308nJG8Owv6PaCvjZ68ySzwHApWzkkSqQ RJ/lTcKBBlxiuUd1FC6MkRje4LjdST3k8Jf8oh4= X-Google-Smtp-Source: ACHHUZ4656Sl9Hgy32VhaMfx5/2vR86xKfZdIYwrCZqCPihBuZACNxQFvIO5JGBqYtKXJId2o6jGlw== X-Received: by 2002:a05:6830:1ce:b0:6b8:9547:a64 with SMTP id r14-20020a05683001ce00b006b895470a64mr14682672ota.3.1688483709006; Tue, 04 Jul 2023 08:15:09 -0700 (PDT) Received: from exu-caveira.tail33bf8.ts.net ([2804:7f1:e2c0:f126:5457:8acf:73e7:5bf2]) by smtp.gmail.com with ESMTPSA id s1-20020a9d7581000000b006b8abc7a738sm3946146otk.69.2023.07.04.08.15.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jul 2023 08:15:08 -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, kernel@mojatatu.com Subject: [PATCH net 1/5] net: sched: cls_bpf: Undo tcf_bind_filter in case of an error Date: Tue, 4 Jul 2023 12:14:52 -0300 Message-Id: <20230704151456.52334-2-victor@mojatatu.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230704151456.52334-1-victor@mojatatu.com> References: <20230704151456.52334-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 Reviewed-by: Pedro Tammela --- 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..4d9974b1b29d 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; @@ -464,6 +465,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; + bool bound_to_filter = false; struct nlattr *tb[TCA_BPF_MAX + 1]; 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 Tue Jul 4 15:14:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Nogueira X-Patchwork-Id: 13301378 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 280AC6AA4 for ; Tue, 4 Jul 2023 15:15:14 +0000 (UTC) Received: from mail-ot1-x32d.google.com (mail-ot1-x32d.google.com [IPv6:2607:f8b0:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E629BE6D for ; Tue, 4 Jul 2023 08:15:12 -0700 (PDT) Received: by mail-ot1-x32d.google.com with SMTP id 46e09a7af769-6b73c2b6dcfso3401539a34.2 for ; Tue, 04 Jul 2023 08:15:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20221208.gappssmtp.com; s=20221208; t=1688483712; x=1691075712; 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=2leKZ3yL9UO2V7GrVLbVDJCzI/nN3a1it0oG3ZCpbl0=; b=wexMa+jJPD1ckeEbjUV5GjJsBOtQs9B6ajcINpizKr56k93onXeB3QxQ1wqD67i9LZ C9FsD6LDzSe+rhWII+7fDY6xUkELKs5tWT+gM7P+F7Iqke3SlrhszjPO6IQNWI3okUIS OXHAagwdEmJSfS7QBUibBs1DzC7g6feT+ZOCiHcAvogl4v4oXkdhNEF1ENeEADrcTZLW Q6QjVXUi4lYL47msoo8whaiM3fUwGIUamVCJY7WmuII2rwXy9V7MiJMtASLC8K3lj+hm Gh2GMzJ5lkrnnN1cPXW3rdpeeuY/hlKaS/rtR5v8PwweoNj1g1v/MBr3zqS2gwNJvutR 4Bsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688483712; x=1691075712; 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=2leKZ3yL9UO2V7GrVLbVDJCzI/nN3a1it0oG3ZCpbl0=; b=Sl0z1rCT3LqCv5ofODFynwt59v1f2yU0HbUDdmd65P3Ld2wW8+wKne0vuN50H9yY0q h0L+S/Rr9IqL/+EBTF222+PKikIH1hPA0QBs1wISqjibA+h4YO2r/LHiGMJHy7xHhbCs If0hp0Pj9iyLfkcOB8BHyF/snjAi+P02H5Hghg6JxEh35RgLBmZf+fBbaz6EztHXBXXw Mg0TBdJUn3YygvEuTzN/gD8tS0Q7aBxvpCXUf0/ynkC6qO3cBCkAohwgXUWHjlD/Y7bl mp0ryn+GpWKd68CMYCvULJ0r6LGRtjKGF9SKfUs+zdRVWxci2IWYdTA1bseurZ71jIsZ /3Wg== X-Gm-Message-State: AC+VfDwPgcyynQv3k+zSoEcczCDw3OVxxiaAuyQZgxN8tZixMLTqqDG+ VEm4jImQ0psbw7+UxnHSXPeC8wpWfhS0Gy+P2iw= X-Google-Smtp-Source: ACHHUZ697jqZ/5+Uom4BXRM8Hpln2I5dhsEERp1ZXOUFEYtZ7Hm8JRcpN8M2tkftzeYOLl5Z4KSjHQ== X-Received: by 2002:a05:6830:11:b0:6b7:2f39:3a93 with SMTP id c17-20020a056830001100b006b72f393a93mr10143598otp.0.1688483711983; Tue, 04 Jul 2023 08:15:11 -0700 (PDT) Received: from exu-caveira.tail33bf8.ts.net ([2804:7f1:e2c0:f126:5457:8acf:73e7:5bf2]) by smtp.gmail.com with ESMTPSA id s1-20020a9d7581000000b006b8abc7a738sm3946146otk.69.2023.07.04.08.15.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jul 2023 08:15:11 -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, kernel@mojatatu.com Subject: [PATCH net 2/5] net: sched: cls_matchall: Undo tcf_bind_filter in case of failure after mall_set_parms Date: Tue, 4 Jul 2023 12:14:53 -0300 Message-Id: <20230704151456.52334-3-victor@mojatatu.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230704151456.52334-1-victor@mojatatu.com> References: <20230704151456.52334-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 Reviewed-by: Pedro Tammela --- 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..02830409e013 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; } @@ -186,6 +187,7 @@ static int mall_change(struct net *net, struct sk_buff *in_skb, struct netlink_ext_ack *extack) { struct cls_mall_head *head = rtnl_dereference(tp->root); + bool bound_to_filter = false; struct nlattr *tb[TCA_MATCHALL_MAX + 1]; struct cls_mall_head *new; u32 userflags = 0; @@ -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 Tue Jul 4 15:14:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Nogueira X-Patchwork-Id: 13301379 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 DBD776AA4 for ; Tue, 4 Jul 2023 15:15:16 +0000 (UTC) Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C63B3E6D for ; Tue, 4 Jul 2023 08:15:15 -0700 (PDT) Received: by mail-ot1-x329.google.com with SMTP id 46e09a7af769-6b8b6f7399aso2708280a34.1 for ; Tue, 04 Jul 2023 08:15:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20221208.gappssmtp.com; s=20221208; t=1688483715; x=1691075715; 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=jkcs2uqOK1YLIQFLRBJYOV4viM2JPisuB2yz4G0LUz0=; b=ZLcH84fwj2VQz16eYLooBFUH80fd5KOm9II4KTKPnaaUxd56wNo4DBVmAqO8lHpc8x 9cwXikiWF/F2/+vOffXryxVOOT+PCzSr9YBwA+LDTKLPPoRZ95iVjWfEgYzzQ7foLRmR SdJovwvsNl7ZhYYfdcQQjXZYw/TJ0f0P+YSj2q+KwoFvKFr4cPjP9sqq+EfzePt6WmCg UkoxbM2z6llSxRDV0k3hpBmneX9CFdPACvDsbphLodi2dSf+VHGPOWB4DWUEOnGaRIxt 3l9HPfIjrZCNnOjBmjrwTbhdOpee0d60xKDoU8c3Pr1gvXD9GtbdHYylqPUQkdaanNOZ aafA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688483715; x=1691075715; 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=jkcs2uqOK1YLIQFLRBJYOV4viM2JPisuB2yz4G0LUz0=; b=KKx7z79Ij7vOPWXgchT+NZ0v1F8dlfmJoumzVXHOye0LdVxWw3Jq6QqvCIrVn3AgFR dYQrEH73AbZN5KK0lKl0qkgOgtCcN7F6KH3+SjGj+NqrIiEQgbZBKtSxzgGOcaarUr3L pW+wK++GMaGUIeQMHNka1U60YnVC+F25JgSry6p2buSa5zZaObewwEpSf9pYezDb6rCa HqaTivsvTnQpcSh7rDt2aPOy4LR8cBdqrwu5u+hS4jXGmT3U1UpcIkSNNDXzX5yqw98z ucYaTtOsXGr6MA/ihMt2z8R7/fxFMkW4O/UBm7V3M6sU5ZoqU2mAnng+HG+9+dzFvO21 nSgA== X-Gm-Message-State: AC+VfDxSfT84LVTtLEjMOhx3aAfxisyQr9QY/pqRqI+T+03t2mGtYkXz zJfZYoCh+q08GXP8TseBGyxzcufZ9TMRHpKFdVo= X-Google-Smtp-Source: ACHHUZ4K65UmG41YyyUvLfGZAUEQdW8175+IEzpiJGrXH7c8Sqnfik753aV9Jo4VXbtW0hhDmfFy4Q== X-Received: by 2002:a9d:7cc8:0:b0:6b8:7a64:cedc with SMTP id r8-20020a9d7cc8000000b006b87a64cedcmr12939040otn.14.1688483715045; Tue, 04 Jul 2023 08:15:15 -0700 (PDT) Received: from exu-caveira.tail33bf8.ts.net ([2804:7f1:e2c0:f126:5457:8acf:73e7:5bf2]) by smtp.gmail.com with ESMTPSA id s1-20020a9d7581000000b006b8abc7a738sm3946146otk.69.2023.07.04.08.15.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jul 2023 08:15:14 -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, kernel@mojatatu.com Subject: [PATCH net 3/5] net: sched: cls_u32: Undo tcf_bind_filter if u32_replace_hw_knode Date: Tue, 4 Jul 2023 12:14:54 -0300 Message-Id: <20230704151456.52334-4-victor@mojatatu.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230704151456.52334-1-victor@mojatatu.com> References: <20230704151456.52334-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 Reviewed-by: Pedro Tammela --- 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..e193db39bee2 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) @@ -853,6 +856,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, struct netlink_ext_ack *extack) { struct tc_u_common *tp_c = tp->data; + u8 set_flags = 0; struct tc_u_hnode *ht; struct tc_u_knode *n; struct tc_u32_sel *s; @@ -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 Tue Jul 4 15:14:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Nogueira X-Patchwork-Id: 13301380 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 D633D6FA8 for ; Tue, 4 Jul 2023 15:15:19 +0000 (UTC) Received: from mail-ot1-x334.google.com (mail-ot1-x334.google.com [IPv6:2607:f8b0:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB48510CF for ; Tue, 4 Jul 2023 08:15:18 -0700 (PDT) Received: by mail-ot1-x334.google.com with SMTP id 46e09a7af769-6b5d1498670so4525902a34.1 for ; Tue, 04 Jul 2023 08:15:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20221208.gappssmtp.com; s=20221208; t=1688483718; x=1691075718; 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=Fa92uouHaP//RU+Bd2IOoGN0WdyRO3Fdk5xN14EG3dg=; b=PzQTotYi6914jcILhN+vcsXZE7ZKsHCtWmqhdx8ET5M6piwyLnVURlbnYs4gQScs0C 2VrAdMjdAQBqizBEC7WdKzqRitSdCQjXobFsrD/xkfMxAME6csznAWXQhj3EFthPBxrW zQR/rFUJjzzFR8ifLoITW/mcsVwDWH9X0S7PZevTST7Yvuy5xLFC99pVyi275StSS6LF 7zGng+dVp2LJQtbKAnpivqzWYMLv7N/FhjoXqTHO638UGxfTiX9PzQhoT6sQ1b5Sy24p hpdphjgxd0DyJCCjzdmNsSjX2Ol90KGtP1O3uFMAMWiQjQuFQf92bfTJr9FTfweVsfCQ p+nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688483718; x=1691075718; 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=Fa92uouHaP//RU+Bd2IOoGN0WdyRO3Fdk5xN14EG3dg=; b=iyUhlDnRbDX55q6YPjxLNUGRbsafMb148qF9A75NOkDEA/zF9hfsgNz5KAR1WSjPkL NbFEhypZhtVyLX7ibQauhT/qzHOzHTjJhXukkhpVYXQH0dJ6icH/hsjSfkQ0tPOnNW41 one4J7lxba2wN81VuzquVHxEqF2QpxHPKhggseMih+JTxRaRYgSF1ZLzcY+YkNLQRc9f gLFZoirS98gsuvjRqMsRahW3GQ/D0LAcnjJf8Ux1gtoDRXzhJwnXjy0oyOMCptYYzyzs f9mHtIOhqJ6gcCS4YqYodawHOV2ewmdvWEqZn1cxu39DcGJBBhtXebEY+BYL526osqwg QNLw== X-Gm-Message-State: AC+VfDyTmoBZvyHUJ3JspQa/wdnCcg2ryft9WOvff48izMnNcl2/3bCS rZ/N4CL10FNJBlnJSPMza8PN/E500NW/IAH7csI= X-Google-Smtp-Source: ACHHUZ6i54qfWfc5B/trVlvTWsSzDWnkC7IJ3SQU62Zg6SWgae5SM2rs8mDQWLDgO45/FP1+ppQLBA== X-Received: by 2002:a05:6830:1315:b0:6b8:8c15:5249 with SMTP id p21-20020a056830131500b006b88c155249mr12099790otq.24.1688483718108; Tue, 04 Jul 2023 08:15:18 -0700 (PDT) Received: from exu-caveira.tail33bf8.ts.net ([2804:7f1:e2c0:f126:5457:8acf:73e7:5bf2]) by smtp.gmail.com with ESMTPSA id s1-20020a9d7581000000b006b8abc7a738sm3946146otk.69.2023.07.04.08.15.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jul 2023 08:15:17 -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, kernel@mojatatu.com Subject: [PATCH net 4/5] net: sched: cls_u32: Undo refcount decrement in case update failed Date: Tue, 4 Jul 2023 12:14:55 -0300 Message-Id: <20230704151456.52334-5-victor@mojatatu.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230704151456.52334-1-victor@mojatatu.com> References: <20230704151456.52334-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 Reviewed-by: Pedro Tammela --- 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 e193db39bee2..5dc401e4baa6 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 Tue Jul 4 15:14:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Nogueira X-Patchwork-Id: 13301381 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 91FCB6FA8 for ; Tue, 4 Jul 2023 15:15:23 +0000 (UTC) Received: from mail-oa1-x2f.google.com (mail-oa1-x2f.google.com [IPv6:2001:4860:4864:20::2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58B8210CF for ; Tue, 4 Jul 2023 08:15:22 -0700 (PDT) Received: by mail-oa1-x2f.google.com with SMTP id 586e51a60fabf-19a427d7b57so3804407fac.2 for ; Tue, 04 Jul 2023 08:15:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20221208.gappssmtp.com; s=20221208; t=1688483721; x=1691075721; 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=AufVbI+LN53/9t1CzZTIXtKk+s0F8FuozdcaUzNd83U=; b=t/JbsdRVOLNUkUNVeeYr5S7zTNMWiYtz/dEMIe6fD2fdof2FOSWNnfYuKJechqdoIb qBml2Yjb32ghB2EkUNzZAsY/9ETjhhiPWXRZFhipFHbBi1KI33/saNpYOommhPr5Vlke sAinyQlGGfSoIKlVD2p01js4l+W+a5s5d2i7lMQSBX0PkRN/F7wpU+29Xe2Ss3MRLxlB mMfbjhhp3bCVDbHFwOayuaDGJuJzSdxgmpjisXxPjEjgPpx/Pp2/XxRrrbjC/pOLSu1P 51/A4qRLjVvZvZgsNOHlLm+0dBeOK9fCvJZWiCMuQgKMwqO+ndroFGcfBo7op09k6j2b 7L7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688483721; x=1691075721; 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=AufVbI+LN53/9t1CzZTIXtKk+s0F8FuozdcaUzNd83U=; b=U9KHOYMrMHgjA0kq1CcYpbbjhAavTFTGvBdptv6kBpDBYdCCaZL0lNAVnpPyKOZR68 scAcs0ohH5YQYOJfwANoxxi0gFXgyE5cnui1s8XekZ1hmfFZnrcv+wzwsVthiapG6kK6 wn8WpfQK74ZMkvOpRMy4ft5wMMfBHLC9+CYxVe2ssmjBmLw8OVLFl8LuargwS1BnWMqA 4R6+RTU9uUTMNwBkNcspzZbBxnscQtjKIvnjOCh1QIuUlwEejWR+kMBcrswadmQKjbd1 jR1pGFoQCCsdjwWczkSdZFwdkPCv7DyrQkCXvR5jUFHSZzH8N6iaRhQTrC9UvfYicZnc YCHQ== X-Gm-Message-State: ABy/qLb/uicAPOTqLqEbSsWitTKATUUUgzh9oCkLURm531QIB6xX9Iit 2JfNelL2/fjpcluzjImn3PkcCl8syn3zPlVapCE= X-Google-Smtp-Source: APBJJlEfY0rU536f5gzWl03zNiWikZ1mP4EPbP94IL7y7hzKg0YeiM8mP69BMZCxTi3RX1u3mlOPmA== X-Received: by 2002:a05:6871:84c7:b0:1b0:454b:1c3d with SMTP id sw7-20020a05687184c700b001b0454b1c3dmr10083409oab.36.1688483721151; Tue, 04 Jul 2023 08:15:21 -0700 (PDT) Received: from exu-caveira.tail33bf8.ts.net ([2804:7f1:e2c0:f126:5457:8acf:73e7:5bf2]) by smtp.gmail.com with ESMTPSA id s1-20020a9d7581000000b006b8abc7a738sm3946146otk.69.2023.07.04.08.15.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jul 2023 08:15:20 -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, kernel@mojatatu.com Subject: [PATCH net 5/5] net: sched: cls_flower: Undo tcf_bind_filter if fl_set_key fails Date: Tue, 4 Jul 2023 12:14:56 -0300 Message-Id: <20230704151456.52334-6-victor@mojatatu.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230704151456.52334-1-victor@mojatatu.com> References: <20230704151456.52334-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 Reviewed-by: Pedro Tammela --- 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);