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; }