From patchwork Tue Nov 9 22:29:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Valerio X-Patchwork-Id: 1553183 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=SrgsBWRA; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HpjNH5lbyz9sPf for ; Wed, 10 Nov 2021 09:30:07 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 83CEC608F4; Tue, 9 Nov 2021 22:30:05 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yImqGJ77ZyoO; Tue, 9 Nov 2021 22:30:04 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp3.osuosl.org (Postfix) with ESMTPS id B4DF0608EC; Tue, 9 Nov 2021 22:30:03 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 7F033C0012; Tue, 9 Nov 2021 22:30:03 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 57F66C000E for ; Tue, 9 Nov 2021 22:30:02 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 44486401B1 for ; Tue, 9 Nov 2021 22:30:02 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp2.osuosl.org (amavisd-new); dkim=pass (1024-bit key) header.d=redhat.com Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id q7-mxOdM9cXu for ; Tue, 9 Nov 2021 22:30:01 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp2.osuosl.org (Postfix) with ESMTPS id 58722403CD for ; Tue, 9 Nov 2021 22:30:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636496999; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OuFf0D93tTmnCQO6B0dC4xS65tTvdFbbOTKY0bGugtY=; b=SrgsBWRA5WeBZJvskmGEpj+i61JfZY3PFfK16aLrfb4cR61ZKjOC3jObDnj8EnFEsL6fQ0 Z5Nd9bU3qEa0hWLKXY97G/kTfkpehKJgmcQzcBBJxpCqaziP+RmbPVdjXaXOPXQyaTT9y1 iqpglEV/oZnblhNHj7g+A0Sg4HbIryQ= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-600-TZU7-u1HOiKx7ZRQl1fFdg-1; Tue, 09 Nov 2021 17:29:58 -0500 X-MC-Unique: TZU7-u1HOiKx7ZRQl1fFdg-1 Received: by mail-wr1-f71.google.com with SMTP id y4-20020adfd084000000b00186b16950f3so39119wrh.14 for ; Tue, 09 Nov 2021 14:29:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=OuFf0D93tTmnCQO6B0dC4xS65tTvdFbbOTKY0bGugtY=; b=QiTNOgqfTOZiIKzIm/LJ2HJfuMjIpJbntc1Bjb+04fswm5C/XdAO8Pv3WIHqWvwgVK 8TG7qEhH1Aa0FJjqlOsOfYMzdwDhB0Mb1odEbOKEDhN6hQoCtU0f3EfuWId7NRqFqhaF 0cGrV++VKknp6PJ/LfQdrAhqtn+gCPHmJk3lapZtg8dm3HEwrQfNjOI766/Xar+Ha5Qn KWDQ6DJPcLFL24KrOLVfSTAQJQyS/ZAT4S4aaGvTkAoQiwB8hajpgJoamZr0SiZpO6tV lWZRdJKnqyXMlP2JdF0wAaq0obmi+RPq6rimRnbI1V4/5Maoxo/bG7rLwskbJWnOTilC PM2w== X-Gm-Message-State: AOAM532DP9f8ooYSouLoPvf//FeoYfGByqrVUE8mKUW4ThPkLWR/8SDd CenvBNKm5/smO9ZXBaMtVd9zxwuRUMkob7PMRSpYnG0nmZ71Ys5XGEcHc57mKugDtLnFTsuSD8r YhJXQhDiuQtvFZBJQMcYLi8UZvIyI6CXnRZAr4aHWgJqfD/HwCVaW+uzStnyt28ls X-Received: by 2002:a5d:530e:: with SMTP id e14mr13849787wrv.12.1636496997131; Tue, 09 Nov 2021 14:29:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJwLZRBClDKqkGg1O455AWktceGewMeyKDirmnKBk3qBBhJuhyENpSMDHAMPa9AIofZbyW2YUQ== X-Received: by 2002:a5d:530e:: with SMTP id e14mr13849760wrv.12.1636496996903; Tue, 09 Nov 2021 14:29:56 -0800 (PST) Received: from localhost (net-5-88-23-84.cust.vodafonedsl.it. [5.88.23.84]) by smtp.gmail.com with ESMTPSA id t8sm3563585wmn.44.2021.11.09.14.29.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Nov 2021 14:29:56 -0800 (PST) From: Paolo Valerio To: dev@openvswitch.org Date: Tue, 09 Nov 2021 23:29:55 +0100 Message-ID: <163649699558.1456179.16443930785440726574.stgit@fed.void> In-Reply-To: <163649698390.1456179.6935508376718804388.stgit@fed.void> References: <163649698390.1456179.6935508376718804388.stgit@fed.void> User-Agent: StGit/0.23 MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pvalerio@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: fbl@redhat.com, i.maximets@ovn.org Subject: [ovs-dev] [PATCH 1/4] Native tunnel: Read/write expires atomically. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Expires is modified in different threads (revalidator, pmd-rx, bfd-tx). It's better to use atomics for such potentially parallel write. Signed-off-by: Paolo Valerio --- v2: - modified commit description - added _MS suffix to NEIGH_ENTRY_DEFAULT_IDLE_TIME - renamed local variable expired -> expires - turned relaxed load/store to acq/rel --- lib/tnl-neigh-cache.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/lib/tnl-neigh-cache.c b/lib/tnl-neigh-cache.c index 5bda4af7e..1e6cc31db 100644 --- a/lib/tnl-neigh-cache.c +++ b/lib/tnl-neigh-cache.c @@ -32,6 +32,7 @@ #include "errno.h" #include "flow.h" #include "netdev.h" +#include "ovs-atomic.h" #include "ovs-thread.h" #include "packets.h" #include "openvswitch/poll-loop.h" @@ -44,14 +45,13 @@ #include "openvswitch/vlog.h" -/* In seconds */ -#define NEIGH_ENTRY_DEFAULT_IDLE_TIME (15 * 60) +#define NEIGH_ENTRY_DEFAULT_IDLE_TIME_MS (15 * 60 * 1000) struct tnl_neigh_entry { struct cmap_node cmap_node; struct in6_addr ip; struct eth_addr mac; - time_t expires; /* Expiration time. */ + atomic_llong expires; /* Expiration time in ms. */ char br_name[IFNAMSIZ]; }; @@ -64,6 +64,16 @@ tnl_neigh_hash(const struct in6_addr *ip) return hash_bytes(ip->s6_addr, 16, 0); } +static bool +tnl_neigh_expired(struct tnl_neigh_entry *neigh) +{ + long long expires; + + atomic_read_explicit(&neigh->expires, &expires, memory_order_acquire); + + return expires <= time_msec(); +} + static struct tnl_neigh_entry * tnl_neigh_lookup__(const char br_name[IFNAMSIZ], const struct in6_addr *dst) { @@ -73,11 +83,13 @@ tnl_neigh_lookup__(const char br_name[IFNAMSIZ], const struct in6_addr *dst) hash = tnl_neigh_hash(dst); CMAP_FOR_EACH_WITH_HASH (neigh, cmap_node, hash, &table) { if (ipv6_addr_equals(&neigh->ip, dst) && !strcmp(neigh->br_name, br_name)) { - if (neigh->expires <= time_now()) { + if (tnl_neigh_expired(neigh)) { return NULL; } - neigh->expires = time_now() + NEIGH_ENTRY_DEFAULT_IDLE_TIME; + atomic_store_explicit(&neigh->expires, time_msec() + + NEIGH_ENTRY_DEFAULT_IDLE_TIME_MS, + memory_order_release); return neigh; } } @@ -121,7 +133,8 @@ tnl_neigh_set__(const char name[IFNAMSIZ], const struct in6_addr *dst, struct tnl_neigh_entry *neigh = tnl_neigh_lookup__(name, dst); if (neigh) { if (eth_addr_equals(neigh->mac, mac)) { - neigh->expires = time_now() + NEIGH_ENTRY_DEFAULT_IDLE_TIME; + atomic_store_relaxed(&neigh->expires, time_msec() + + NEIGH_ENTRY_DEFAULT_IDLE_TIME_MS); ovs_mutex_unlock(&mutex); return; } @@ -133,7 +146,8 @@ tnl_neigh_set__(const char name[IFNAMSIZ], const struct in6_addr *dst, neigh->ip = *dst; neigh->mac = mac; - neigh->expires = time_now() + NEIGH_ENTRY_DEFAULT_IDLE_TIME; + atomic_store_relaxed(&neigh->expires, time_msec() + + NEIGH_ENTRY_DEFAULT_IDLE_TIME_MS); ovs_strlcpy(neigh->br_name, name, sizeof neigh->br_name); cmap_insert(&table, &neigh->cmap_node, tnl_neigh_hash(&neigh->ip)); ovs_mutex_unlock(&mutex); @@ -208,7 +222,7 @@ tnl_neigh_cache_run(void) ovs_mutex_lock(&mutex); CMAP_FOR_EACH(neigh, cmap_node, &table) { - if (neigh->expires <= time_now()) { + if (tnl_neigh_expired(neigh)) { tnl_neigh_delete(neigh); changed = true; } @@ -319,7 +333,7 @@ tnl_neigh_cache_show(struct unixctl_conn *conn, int argc OVS_UNUSED, ds_put_format(&ds, ETH_ADDR_FMT" %s", ETH_ADDR_ARGS(neigh->mac), neigh->br_name); - if (neigh->expires <= time_now()) { + if (tnl_neigh_expired(neigh)) { ds_put_format(&ds, " STALE"); } ds_put_char(&ds, '\n');