From patchwork Tue Jun 26 07:59:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 934708 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@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; dmarc=none (p=none dis=none) header.from=resnulli.us Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=resnulli-us.20150623.gappssmtp.com header.i=@resnulli-us.20150623.gappssmtp.com header.b="dkx+m+iE"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41FJQc22Tnz9ryk for ; Tue, 26 Jun 2018 18:01:28 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752793AbeFZIB0 (ORCPT ); Tue, 26 Jun 2018 04:01:26 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:36547 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752708AbeFZIBY (ORCPT ); Tue, 26 Jun 2018 04:01:24 -0400 Received: by mail-wr0-f193.google.com with SMTP id f16-v6so16200858wrm.3 for ; Tue, 26 Jun 2018 01:01:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=We0KcyAG8FISfs355CQ1QAksEboPCRQ4sicrnZIx5Gc=; b=dkx+m+iEkbO9g+JJfopK0GIz2M8PfxSmhR+XZqKD3ACU3YRpgsl070Dfni88JPhqUZ qHdkIzqFndRUkayMaiyFGCZvZN2yRJk6VrbB9m4gqtOUGye7faJc4BiJhTCGPeTcwGvV +e4BKcCgMpYhdBDWAewLYxi5G3WmyPUUochBVXuWPylWamuo63f/l9T5JlZskXmfKwdQ cCKsrTOzlv1H6GWl18Xjt/B3JV6NSHVSHgjLxK6FN21T1awoPGuzAK0i0nPjcLqs9u+4 TwHpThBlAd0yGxw/1NKDArsnl6309jQ5vYDNDHtlFa2aHLgdZz8d8mO4yobAjUkxJNfw 4llA== 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=We0KcyAG8FISfs355CQ1QAksEboPCRQ4sicrnZIx5Gc=; b=A4H8XOLl5ZaIFhE+8AVdOjw1MekUTpwBRkQZO24SJOa9As7zftxlVlIoKWpZTylBzb 2E0ybfVZdiIouTBjZv8RqoLR3sIEojSYQe7EAedSbhHVvjf8dEVqgH9lyn1Iy+MZ4V7R cc8SwflyEqsMB06M8Pslfd0U/qAKc+nOoqZV/oVAdpNIX00q/V6iXwy8I7R9rO9SLWnv YsFp/CfFBwn0F6oxzfnX+VIAdM5Us2vjV1O1tLMJcxFY0kJ+lwLJDehCwRsu0i2g3U4u O1se6rjHmNbw1JbEOE1tJH3XsZ8V+ChgREQPGORXqrCQ2lI+4jMGphVmXEp1vDrN75VR PcOQ== X-Gm-Message-State: APt69E3YJb+54sDUFZRcQGV8U3Og+jAv2qRb45zeQMy1jy8VCdhEdpua toKlb1KZG0RDSOrVzr72g/7JwBnU X-Google-Smtp-Source: AAOMgpdSfeqY1GeQlHIyRbZJmlIVvK6aswtM5mHN9BQzDr7Q16ivq1lv0l1PcAeSWfq3tT8BYqWbWQ== X-Received: by 2002:adf:ebc3:: with SMTP id v3-v6mr475220wrn.33.1530000083150; Tue, 26 Jun 2018 01:01:23 -0700 (PDT) Received: from localhost (jirka.pirko.cz. [84.16.102.26]) by smtp.gmail.com with ESMTPSA id e63-v6sm1417496wma.46.2018.06.26.01.01.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 Jun 2018 01:01:22 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, jhs@mojatatu.com, xiyou.wangcong@gmail.com, jakub.kicinski@netronome.com, simon.horman@netronome.com, john.hurley@netronome.com, dsahern@gmail.com, mlxsw@mellanox.com Subject: [patch net-next v2 1/9] net: sched: push ops lookup bits into tcf_proto_lookup_ops() Date: Tue, 26 Jun 2018 09:59:52 +0200 Message-Id: <20180626080000.12964-2-jiri@resnulli.us> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180626080000.12964-1-jiri@resnulli.us> References: <20180626080000.12964-1-jiri@resnulli.us> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jiri Pirko Push all bits that take care of ops lookup, including module loading outside tcf_proto_create() function, into tcf_proto_lookup_ops() Signed-off-by: Jiri Pirko --- net/sched/cls_api.c | 53 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c index cdc3c87c53e6..db45931bbada 100644 --- a/net/sched/cls_api.c +++ b/net/sched/cls_api.c @@ -39,7 +39,7 @@ static DEFINE_RWLOCK(cls_mod_lock); /* Find classifier type by string name */ -static const struct tcf_proto_ops *tcf_proto_lookup_ops(const char *kind) +static const struct tcf_proto_ops *__tcf_proto_lookup_ops(const char *kind) { const struct tcf_proto_ops *t, *res = NULL; @@ -57,6 +57,33 @@ static const struct tcf_proto_ops *tcf_proto_lookup_ops(const char *kind) return res; } +static const struct tcf_proto_ops * +tcf_proto_lookup_ops(const char *kind, struct netlink_ext_ack *extack) +{ + const struct tcf_proto_ops *ops; + + ops = __tcf_proto_lookup_ops(kind); + if (ops) + return ops; +#ifdef CONFIG_MODULES + rtnl_unlock(); + request_module("cls_%s", kind); + rtnl_lock(); + ops = __tcf_proto_lookup_ops(kind); + /* We dropped the RTNL semaphore in order to perform + * the module load. So, even if we succeeded in loading + * the module we have to replay the request. We indicate + * this using -EAGAIN. + */ + if (ops) { + module_put(ops->owner); + return ERR_PTR(-EAGAIN); + } +#endif + NL_SET_ERR_MSG(extack, "TC classifier not found"); + return ERR_PTR(-ENOENT); +} + /* Register(unregister) new classifier type */ int register_tcf_proto_ops(struct tcf_proto_ops *ops) @@ -133,27 +160,9 @@ static struct tcf_proto *tcf_proto_create(const char *kind, u32 protocol, if (!tp) return ERR_PTR(-ENOBUFS); - err = -ENOENT; - tp->ops = tcf_proto_lookup_ops(kind); - if (!tp->ops) { -#ifdef CONFIG_MODULES - rtnl_unlock(); - request_module("cls_%s", kind); - rtnl_lock(); - tp->ops = tcf_proto_lookup_ops(kind); - /* We dropped the RTNL semaphore in order to perform - * the module load. So, even if we succeeded in loading - * the module we have to replay the request. We indicate - * this using -EAGAIN. - */ - if (tp->ops) { - module_put(tp->ops->owner); - err = -EAGAIN; - } else { - NL_SET_ERR_MSG(extack, "TC classifier not found"); - err = -ENOENT; - } -#endif + tp->ops = tcf_proto_lookup_ops(kind, extack); + if (IS_ERR(tp->ops)) { + err = PTR_ERR(tp->ops); goto errout; } tp->classify = tp->ops->classify;