From patchwork Mon Nov 6 21:47:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cong Wang X-Patchwork-Id: 834959 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Gm6K7G+E"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yW5lz08V5z9ryv for ; Tue, 7 Nov 2017 08:48:31 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752747AbdKFVsK (ORCPT ); Mon, 6 Nov 2017 16:48:10 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:48495 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752676AbdKFVsJ (ORCPT ); Mon, 6 Nov 2017 16:48:09 -0500 Received: by mail-pg0-f66.google.com with SMTP id v78so9300446pgb.5 for ; Mon, 06 Nov 2017 13:48:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=aF6ZLyMHJjzuCg6kn63Y5jM/MfrvuOWsT5AgUpMRj8w=; b=Gm6K7G+EG4WZbhyzlpnn718USJqb9zjcsX5f2vTg5szPgDi9wLqPAkSB40Kw4UYLsz Z82VmfUwij1oHHcYPNX9ZLAvjQp+kxIo40DBbYkFAKNJY72rAfAn73LBhZ3GbDdGU2Gz ZrA1f36RBB06ruiKwmcMUmlQsV+AQgl0a5SFBXYqU9xc/CzwZmaYw3nt5yLF5jWyYIcq KCtnr+QwQzQLaCI9H2UWgJ07Mk4YysU2ZVAvyvwHuZKv8LkXWwJ6x9Bl7LUK1oLKjayT bXUbPTpwqkupotEkJAFo+2X4dnJogGfOJY0da59riodWY8aMSCW6WS9elWy9pbYUDXG0 JZsg== 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=aF6ZLyMHJjzuCg6kn63Y5jM/MfrvuOWsT5AgUpMRj8w=; b=YY4MAPn+NSTh0vNxJ2hWaeRZmElEkQjqWEI2n6wJk+9qMe2RTHvf9lt/QTRNWZpMeg ow9RzjG8XtR5QjymhyAHqtaKiLyYhUy3MuzeFhJANM1na+yj3NslFIdM+ZZ+tMDcj8Sx SXqFnlIIv4jF57bBuEnoWxNAa395Nr1HB7NRi7S4yMBVpJMayJWWZNFm7BAOb5VVK6IB /J4Gke6+BJE1LJ3l9IrFlNe2pDD8cV7Gj9F+BkeC5/VlvsfGf241XvVj82tLmy4QlLR1 OzmXCntdx/CMTzWdRe8H0rlIYRIBs4NYp+i+cAq7Pb3AZYLVXX8TtV5b3TjgzD9ftb+3 ZDnA== X-Gm-Message-State: AMCzsaWaiC14EgyIfVMo6/ENuA2h6rcvcT/TCo3gd3OTnxYaun30Ln3Z 39+WQi8yeOvaD0U0H4TIE5nbNX4h X-Google-Smtp-Source: ABhQp+QzjjBpFiVXkl4NcI7W4kNDGnV6xtzOMTjLVrtjw1p9spHgUjpOnfOxHutgmhErNUQrWaroCQ== X-Received: by 10.84.140.129 with SMTP id 1mr15950116plt.281.1510004888499; Mon, 06 Nov 2017 13:48:08 -0800 (PST) Received: from tw-172-25-30-113.office.twttr.net ([8.25.197.25]) by smtp.gmail.com with ESMTPSA id 84sm24246799pfy.179.2017.11.06.13.48.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 06 Nov 2017 13:48:07 -0800 (PST) From: Cong Wang To: netdev@vger.kernel.org Cc: Cong Wang , Lucas Bates , Jamal Hadi Salim , Jiri Pirko Subject: [Patch net 13/13] cls_u32: use tcf_exts_get_net() before call_rcu() Date: Mon, 6 Nov 2017 13:47:30 -0800 Message-Id: <20171106214730.24421-14-xiyou.wangcong@gmail.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20171106214730.24421-1-xiyou.wangcong@gmail.com> References: <20171106214730.24421-1-xiyou.wangcong@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Hold netns refcnt before call_rcu() and release it after the tcf_exts_destroy() is done. Note, on ->destroy() path we have to respect the return value of tcf_exts_get_net(), on other paths it should always return true, so we don't need to care. Cc: Lucas Bates Cc: Jamal Hadi Salim Cc: Jiri Pirko Signed-off-by: Cong Wang --- net/sched/cls_u32.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index dadd1b344497..b58eccb21f03 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -399,6 +399,7 @@ static int u32_destroy_key(struct tcf_proto *tp, struct tc_u_knode *n, bool free_pf) { tcf_exts_destroy(&n->exts); + tcf_exts_put_net(&n->exts); if (n->ht_down) n->ht_down->refcnt--; #ifdef CONFIG_CLS_U32_PERF @@ -476,6 +477,7 @@ static int u32_delete_key(struct tcf_proto *tp, struct tc_u_knode *key) RCU_INIT_POINTER(*kp, key->next); tcf_unbind_filter(tp, &key->res); + tcf_exts_get_net(&key->exts); call_rcu(&key->rcu, u32_delete_key_freepf_rcu); return 0; } @@ -588,7 +590,10 @@ static void u32_clear_hnode(struct tcf_proto *tp, struct tc_u_hnode *ht) rtnl_dereference(n->next)); tcf_unbind_filter(tp, &n->res); u32_remove_hw_knode(tp, n->handle); - call_rcu(&n->rcu, u32_delete_key_freepf_rcu); + if (tcf_exts_get_net(&n->exts)) + call_rcu(&n->rcu, u32_delete_key_freepf_rcu); + else + u32_destroy_key(n->tp, n, true); } } } @@ -949,6 +954,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, u32_replace_knode(tp, tp_c, new); tcf_unbind_filter(tp, &n->res); + tcf_exts_get_net(&n->exts); call_rcu(&n->rcu, u32_delete_key_rcu); return 0; }