{"id":817703,"url":"http://patchwork.ozlabs.org/api/patches/817703/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/patch/280e7c35539483d58163adab20d19a954e1b08cb.1506114055.git.pabeni@redhat.com/","project":{"id":7,"url":"http://patchwork.ozlabs.org/api/projects/7/?format=json","name":"Linux network development","link_name":"netdev","list_id":"netdev.vger.kernel.org","list_email":"netdev@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<280e7c35539483d58163adab20d19a954e1b08cb.1506114055.git.pabeni@redhat.com>","list_archive_url":null,"date":"2017-09-22T21:06:28","name":"[RFC,04/11] net: add simple socket-like dst cache helpers","commit_ref":null,"pull_url":null,"state":"rfc","archived":true,"hash":"901dee97ff090f866548ef07ce64dcd480f78391","submitter":{"id":67312,"url":"http://patchwork.ozlabs.org/api/people/67312/?format=json","name":"Paolo Abeni","email":"pabeni@redhat.com"},"delegate":{"id":34,"url":"http://patchwork.ozlabs.org/api/users/34/?format=json","username":"davem","first_name":"David","last_name":"Miller","email":"davem@davemloft.net"},"mbox":"http://patchwork.ozlabs.org/project/netdev/patch/280e7c35539483d58163adab20d19a954e1b08cb.1506114055.git.pabeni@redhat.com/mbox/","series":[{"id":4709,"url":"http://patchwork.ozlabs.org/api/series/4709/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/list/?series=4709","date":"2017-09-22T21:06:24","name":"udp: full early demux for unconnected sockets","version":1,"mbox":"http://patchwork.ozlabs.org/series/4709/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/817703/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/817703/checks/","tags":{},"related":[],"headers":{"Return-Path":"<netdev-owner@vger.kernel.org>","X-Original-To":"patchwork-incoming@ozlabs.org","Delivered-To":"patchwork-incoming@ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=netdev-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","ext-mx05.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx05.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=pabeni@redhat.com"],"Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3xzQz23fFBz9sP1\n\tfor <patchwork-incoming@ozlabs.org>;\n\tSat, 23 Sep 2017 07:07:10 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1752728AbdIVVHJ (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tFri, 22 Sep 2017 17:07:09 -0400","from mx1.redhat.com ([209.132.183.28]:48756 \"EHLO mx1.redhat.com\"\n\trhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP\n\tid S1752694AbdIVVHE (ORCPT <rfc822;netdev@vger.kernel.org>);\n\tFri, 22 Sep 2017 17:07:04 -0400","from smtp.corp.redhat.com\n\t(int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id 49E7FC9D34;\n\tFri, 22 Sep 2017 21:07:04 +0000 (UTC)","from dhcppc0.redhat.com (ovpn-116-39.ams2.redhat.com\n\t[10.36.116.39])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id 93D705D6A2;\n\tFri, 22 Sep 2017 21:07:02 +0000 (UTC)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com 49E7FC9D34","From":"Paolo Abeni <pabeni@redhat.com>","To":"netdev@vger.kernel.org","Cc":"\"David S. Miller\" <davem@davemloft.net>,\n\tPablo Neira Ayuso <pablo@netfilter.org>, Florian Westphal <fw@strlen.de>,\n\tEric Dumazet <edumazet@google.com>,\n\tHannes Frederic Sowa <hannes@stressinduktion.org>","Subject":"[RFC PATCH 04/11] net: add simple socket-like dst cache helpers","Date":"Fri, 22 Sep 2017 23:06:28 +0200","Message-Id":"<280e7c35539483d58163adab20d19a954e1b08cb.1506114055.git.pabeni@redhat.com>","In-Reply-To":"<cover.1506114055.git.pabeni@redhat.com>","References":"<cover.1506114055.git.pabeni@redhat.com>","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.15","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.29]);\n\tFri, 22 Sep 2017 21:07:04 +0000 (UTC)","Sender":"netdev-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<netdev.vger.kernel.org>","X-Mailing-List":"netdev@vger.kernel.org"},"content":"It will be used by later patches to reduce code duplication.\n\nSigned-off-by: Paolo Abeni <pabeni@redhat.com>\n---\n include/net/dst.h | 20 ++++++++++++++++++++\n net/core/dst.c    | 12 ++++++++++++\n 2 files changed, 32 insertions(+)","diff":"diff --git a/include/net/dst.h b/include/net/dst.h\nindex 93568bd0a352..4fcca0e368c6 100644\n--- a/include/net/dst.h\n+++ b/include/net/dst.h\n@@ -485,6 +485,26 @@ static inline struct dst_entry *dst_check(struct dst_entry *dst, u32 cookie)\n \treturn dst;\n }\n \n+/* update the cache with dst, assuming the latter already carries a refcount */\n+static inline bool __dst_update(struct dst_entry **cache, struct dst_entry *dst)\n+{\n+\tstruct dst_entry *old = xchg(cache, dst);\n+\n+\tdst_release(old);\n+\treturn old != dst;\n+}\n+bool dst_update(struct dst_entry **cache, struct dst_entry *dst);\n+static inline struct dst_entry *dst_access(struct dst_entry **cache,\n+\t\t\t\t\t      u32 cookie)\n+{\n+\tstruct dst_entry *dst = READ_ONCE(*cache);\n+\n+\tif (!dst)\n+\t\treturn NULL;\n+\n+\treturn dst_check(dst, cookie);\n+}\n+\n /* Flags for xfrm_lookup flags argument. */\n enum {\n \tXFRM_LOOKUP_ICMP = 1 << 0,\ndiff --git a/net/core/dst.c b/net/core/dst.c\nindex a6c47da7d0f8..4076f9af45d7 100644\n--- a/net/core/dst.c\n+++ b/net/core/dst.c\n@@ -205,6 +205,18 @@ void dst_release_immediate(struct dst_entry *dst)\n }\n EXPORT_SYMBOL(dst_release_immediate);\n \n+/* update the cache with dst, assuming the latter does not carry a refcount */\n+bool dst_update(struct dst_entry **cache, struct dst_entry *dst)\n+{\n+\tif (likely(*cache == dst))\n+\t\treturn false;\n+\n+\tif (dst_hold_safe(dst))\n+\t\treturn __dst_update(cache, dst);\n+\treturn false;\n+}\n+EXPORT_SYMBOL_GPL(dst_update);\n+\n u32 *dst_cow_metrics_generic(struct dst_entry *dst, unsigned long old)\n {\n \tstruct dst_metrics *p = kmalloc(sizeof(*p), GFP_ATOMIC);\n","prefixes":["RFC","04/11"]}