From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.9 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C3E9C43381 for ; Sat, 23 Feb 2019 02:45:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C66C620685 for ; Sat, 23 Feb 2019 02:45:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mAaauyOt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727651AbfBWCpP (ORCPT ); Fri, 22 Feb 2019 21:45:15 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:44169 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725821AbfBWCpP (ORCPT ); Fri, 22 Feb 2019 21:45:15 -0500 Received: by mail-pf1-f195.google.com with SMTP id a3so1909112pff.11 for ; Fri, 22 Feb 2019 18:45:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=FqCj2V8rEltL6yuzxmac0NmYaLtFUcU9qFgHc4wd+Qw=; b=mAaauyOtqOik0uIC3NI4rxyn5GLa3GnXREPtY1Xq62yGOkp8GZ5XSg9cx/AJasnBxf HZrsOqUpEUH7uX8GFzx/L8GwT7IIA1XLyPuBh8u0RNLsWdo2+Xr0ts7U0NDZRiJkr5A2 GG1nYjnheWDhI5eb4Wm7bqoL3CsqTpLoS9V0SrMNtJoX1RdTgKv79PrdJ5xTlowNAxP5 YAyESeUoawxrf4Gce6HPzfzYPAnURMrKhTZMK/GkHygPm6hiH0HwFrLAHO2KpECJAS1s dgVIa7J4VMowr9/kI6d/N23/Jn+QCJtviaswL3Y+DvhdBKrd1MwvQluw5yVgCsS3Lg2R VW0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=FqCj2V8rEltL6yuzxmac0NmYaLtFUcU9qFgHc4wd+Qw=; b=bivK9Ld/3T5U/OO/k4VDVLwGDK61Jr6TWvvwfzZiSqCsHznj9lImuxgdvXt+/19myL Fxmf4TJjlVVChAYAIb1EQ0C2sYJZMQloBjyXe/spjJawfyl73levUKIYIeP7gP8kk2GU hZNS9P2A1T04DV41MkCDaAIQpqM6/bevlowbx/4HiCg15Qeg45OF1iJc5awdUSoRJIrt jQslvccViVboXvmOTnV1o0Urt2rhdQLYNAWZLjiQ5JIxyfJCZcKVvNfgaTX8Pqv4goL4 BYa5fzbfMP1jE2YSfoF+AOO2iWvFN+Cu/8wZK3VnOZDTyCEbKmOZlMiPhne2XRlNlhgv Tuzg== X-Gm-Message-State: AHQUAub3ml7Iaci4Wm8MnjHRv14jSGOcgwivXRmelNpPbOSdr/zbDVzC PgPTj4wumbdZTQfzp1Xph2K3vnAp X-Google-Smtp-Source: AHgI3Iael1ifZZg6sffAXdI2xA+6S79+cV+8KURohy9w5vhdaYR1RFQhLVx4s/k72d5De98oeHKx8g== X-Received: by 2002:a65:6298:: with SMTP id f24mr6987864pgv.183.1550889913408; Fri, 22 Feb 2019 18:45:13 -0800 (PST) Received: from [172.27.227.138] ([216.129.126.118]) by smtp.googlemail.com with ESMTPSA id b197sm5109361pga.89.2019.02.22.18.45.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Feb 2019 18:45:12 -0800 (PST) Subject: Re: [PATCH net-next v3] ip_tunnel: Add dst_cache support in lwtunnel_state of ip tunnel To: wenxu@ucloud.cn, davem@davemloft.net Cc: netdev@vger.kernel.org References: <1550881979-12589-1-git-send-email-wenxu@ucloud.cn> From: David Ahern Message-ID: Date: Fri, 22 Feb 2019 21:45:09 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <1550881979-12589-1-git-send-email-wenxu@ucloud.cn> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On 2/22/19 7:32 PM, wenxu@ucloud.cn wrote: > diff --git a/net/core/lwtunnel.c b/net/core/lwtunnel.c > index 0b17175..f6301af 100644 > --- a/net/core/lwtunnel.c > +++ b/net/core/lwtunnel.c > @@ -123,17 +123,18 @@ int lwtunnel_build_state(u16 encap_type, > rcu_read_lock(); > ops = rcu_dereference(lwtun_encaps[encap_type]); > if (likely(ops && ops->build_state && try_module_get(ops->owner))) { > + rcu_read_unlock(); > found = true; > ret = ops->build_state(encap, family, cfg, lws, extack); > if (ret) > module_put(ops->owner); > } > - rcu_read_unlock(); > > /* don't rely on -EOPNOTSUPP to detect match as build_state > * handlers could return it > */ > if (!found) { > + rcu_read_unlock(); I was thinking something much simpler ... like: rcu_read_lock(); ops = rcu_dereference(lwtun_encaps[encap_type]); if (likely(ops && ops->build_state && try_module_get(ops->owner))) { found = true; rcu_read_unlock(); if (found) { ret = ops->build_state(encap, family, cfg, lws, extack); if (ret) module_put(ops->owner); } else { NL_SET_ERR_MSG_ATTR(...); } > > NL_SET_ERR_MSG_ATTR(extack, encap, > "LWT encapsulation type not supported"); > } > diff --git a/net/ipv4/ip_tunnel_core.c b/net/ipv4/ip_tunnel_core.c > index 9a0e67b..334e77a 100644 > --- a/net/ipv4/ip_tunnel_core.c > +++ b/net/ipv4/ip_tunnel_core.c > @@ -252,6 +252,14 @@ static int ip_tun_build_state(struct nlattr *attr, > > tun_info = lwt_tun_info(new_state); > > +#ifdef CONFIG_DST_CACHE > + err = dst_cache_init(&tun_info->dst_cache, GFP_KERNEL); > + if (err) { > + lwtstate_free(new_state); > + return err; > + } > +#endif > + > if (tb[LWTUNNEL_IP_ID]) > tun_info->key.tun_id = nla_get_be64(tb[LWTUNNEL_IP_ID]); > > @@ -278,6 +286,15 @@ static int ip_tun_build_state(struct nlattr *attr, > return 0; > } > > +#ifdef CONFIG_DST_CACHE > +static void ip_tun_destroy_state(struct lwtunnel_state *lwtstate) > +{ > + struct ip_tunnel_info *tun_info = lwt_tun_info(lwtstate); > + > + dst_cache_destroy(&tun_info->dst_cache); > +}> +#endif > + > static int ip_tun_fill_encap_info(struct sk_buff *skb, > struct lwtunnel_state *lwtstate) > { > @@ -313,6 +330,9 @@ static int ip_tun_cmp_encap(struct lwtunnel_state *a, struct lwtunnel_state *b) > > static const struct lwtunnel_encap_ops ip_tun_lwt_ops = { > .build_state = ip_tun_build_state, > +#ifdef CONFIG_DST_CACHE > + .destroy_state = ip_tun_destroy_state, > +#endif Define ip_tun_destroy_state when DST_CACHE is not enabled so you don't need this ifdef as well. e.g., move the ifdef around dst_cache_destroy and its local arg to mirror the init.