From patchwork Wed Nov 10 10:46:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Valerio X-Patchwork-Id: 1553363 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=V5LhxS+B; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.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 4Hq1kJ6J2gz9sCD for ; Wed, 10 Nov 2021 21:46:48 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 37BA760A58; Wed, 10 Nov 2021 10:46:47 +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 jeLKQ3OSwZc6; Wed, 10 Nov 2021 10:46:46 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTPS id 7CC2660A49; Wed, 10 Nov 2021 10:46:44 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 52AC1C0019; Wed, 10 Nov 2021 10:46:44 +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 2A465C0019 for ; Wed, 10 Nov 2021 10:46:43 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 01D8B40410 for ; Wed, 10 Nov 2021 10:46:42 +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 sqLkGaeADMap for ; Wed, 10 Nov 2021 10:46:42 +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.129.124]) by smtp2.osuosl.org (Postfix) with ESMTPS id E09C54021B for ; Wed, 10 Nov 2021 10:46:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636541200; 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=V5LhxS+BQsIZsEIG7naX46FW3dbipilxiWJvTr0UaY7AJVJQmQjgSJVEEdXGGP1YkpS1iC Cx48quxXZrn6do1L+LYhgVG7VwrUh+8SQ2ywopFjwaGRF0zrwKbNgmJR6ytMv+nxKZj7KV zSS5UnFGYYFXRMVg9b7QQ/1kIJH9JvA= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-285-lTYTF_TMMLeGmtDWK-cE2w-1; Wed, 10 Nov 2021 05:46:39 -0500 X-MC-Unique: lTYTF_TMMLeGmtDWK-cE2w-1 Received: by mail-wm1-f71.google.com with SMTP id b133-20020a1c808b000000b0032cdd691994so2910776wmd.1 for ; Wed, 10 Nov 2021 02:46:39 -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=cJQo2IbGw0FOLLJGEr1ByoKlca7OuY6ieF2t6Vl+y+b09iP1T9FP9Dk7oZBBE2jwfM f6rUgbzGa3asze3AA0HsaRtPIjzpkf4gTqPD1S7K5kSx5WwZUvUghMELLi2w5bLzsU7J uLEiGbOq/ph9SFr9XdVBdEX5cwlVfn+JEcRAiaeeVJLxHyksld0eAg9ABcK5XNhm30p7 Vu2BRHiLfiKPciio0t3SJ5NhEip+wofampJMd3qz1LQt1g4F+4j1XwkJNe3ppvmev681 5gON6JtathvKvg3gxWXkDZKnwDp4va1NQ0alMvX2+5mVuB6JhEuUyLGjf5cFv0/HXLO9 AkxA== X-Gm-Message-State: AOAM531GfdGHbyfEgty1sfmFnM8RD392U4EA/IDUPbbN4FVg5BvChlew emd9kMhRWqoNQmqtDf2rqwcPs+Ydw6HSjaraRWtvWQW5XHeO3WdCOt2/qAZwZNxEZnHUoR5/6tq vZkgkLei1fcGaIwtJK/P0JCdxLA3QEASFW/hvUrFU8BqokWQRfayjW2enCAuE5FvS X-Received: by 2002:a05:6000:110b:: with SMTP id z11mr18469821wrw.32.1636541198029; Wed, 10 Nov 2021 02:46:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJzyJ0nF5w7Q4PrkcH7fCQF7AcGv6CGPCfSsA6Wz0keZdi+iLJfWTpb0U5dJ1hFuzYNUziBRlw== X-Received: by 2002:a05:6000:110b:: with SMTP id z11mr18469797wrw.32.1636541197856; Wed, 10 Nov 2021 02:46:37 -0800 (PST) Received: from localhost (net-5-88-23-84.cust.vodafonedsl.it. [5.88.23.84]) by smtp.gmail.com with ESMTPSA id z6sm23051054wrm.93.2021.11.10.02.46.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Nov 2021 02:46:37 -0800 (PST) From: Paolo Valerio To: dev@openvswitch.org Date: Wed, 10 Nov 2021 11:46:36 +0100 Message-ID: <163654119685.1486166.12583796904400879442.stgit@fed.void> In-Reply-To: <163654119047.1486166.18090151938310335551.stgit@fed.void> References: <163654119047.1486166.18090151938310335551.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 v2 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 Acked-by: Flavio Leitner --- 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');