From patchwork Mon Sep 30 20:50:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Valerio X-Patchwork-Id: 1991196 X-Patchwork-Delegate: aconole@redhat.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=iRUVCeso; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XHYC91xgVz1xsv for ; Tue, 1 Oct 2024 06:51:33 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id EF43880B7E; Mon, 30 Sep 2024 20:51:29 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id J3LMuO8MJmFB; Mon, 30 Sep 2024 20:51:29 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=140.211.9.56; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 066A480C07 Authentication-Results: smtp1.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=iRUVCeso Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id 066A480C07; Mon, 30 Sep 2024 20:51:29 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id D20FAC002B; Mon, 30 Sep 2024 20:51:28 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1FFF1C0893 for ; Mon, 30 Sep 2024 20:51:27 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 210D560767 for ; Mon, 30 Sep 2024 20:51:24 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 2hud62aQuRAn for ; Mon, 30 Sep 2024 20:51:23 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=170.10.129.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=pvalerio@redhat.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp3.osuosl.org 11C6260753 Authentication-Results: smtp3.osuosl.org; dmarc=pass (p=none dis=none) header.from=redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 11C6260753 Authentication-Results: smtp3.osuosl.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=iRUVCeso Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by smtp3.osuosl.org (Postfix) with ESMTPS id 11C6260753 for ; Mon, 30 Sep 2024 20:51:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727729481; 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=ND7SDJGE1K9bfLzZHo/eIeOOEmq6SPGxq2kYIRcXqo8=; b=iRUVCesouW7mGjIFzJuFHyy04qt2nRHoywWgZENAExaP7zHsqQEmBjj6OmjMFtnpmzlPA5 kgnYi+GDeIRY21FnfCy+GrUypDdvYpOcRjhtnr8o37e6JTqmgBXjDHnoLIIHCAegFYQQLJ MyyeVIhYMTtVlbMJ5dBI6ntG0Fy9h30= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-125-r26KkOsxMiCWwR7papgiwg-1; Mon, 30 Sep 2024 16:51:20 -0400 X-MC-Unique: r26KkOsxMiCWwR7papgiwg-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-37ce14d621aso1203235f8f.3 for ; Mon, 30 Sep 2024 13:51:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727729478; x=1728334278; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ND7SDJGE1K9bfLzZHo/eIeOOEmq6SPGxq2kYIRcXqo8=; b=ltTBckTqiuhrPBiRZABLQSYswSmLssvMide0xQEXZR8d57jRmn9aYyySKM8pr7O/DE fBVifmoxOBh2jhYbspPJNQ0ZVKa4VEs4I/w5m6eCu0nbmxfbyeLnn0mYbpenCQfmRcYU 9tb7vs9NfX7noGWCeSZDxkH+zWSecGyXIAQ9x7KKqxNloLWIAcw4ZOS1jTTGHbhT6FR8 AbQnuHwcdvz+q4D1gHAHnkmAsESJYwyd6tJaZiT9ionOZlStx05wJ8BoFBTvcSzh0+pF SBLJwU2z8rRLJ94nx9Oz2IXn/PDoSdN0fkXVlQYzqrsSTrv+EYdnsunZQLO/am8uGOaR aoqQ== X-Gm-Message-State: AOJu0YycGiSK2UbU/1t1thQtNw/0SO4EfKSxsQOwAsmC/x/1U746+7t2 pYK1gDbXmjbBrgtc8e9fLQP5XARyLD+y2aN+ozA+x7BoXV+0C+f1bO//LNa4FM6r31Esu+QCE+L jdsTe7gBej00eUHfEZw29sgaDurzaiShMhQebkWlqQ147m4BWuPzPNTs9jeDFdsMNk21OTKbgBm L9DZqfbbezokn/QjbZ+FzB3Z2MrF/V9+U3sufnco0= X-Received: by 2002:a5d:570e:0:b0:37c:ccbc:6573 with SMTP id ffacd0b85a97d-37cd5ab7301mr6384706f8f.18.1727729477933; Mon, 30 Sep 2024 13:51:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGT3cjQqeCE9347TSC4OrRiRo0keE5pCwxfUWi4bSQONT5jbLkSB/zUqQ0wuugcXLfMunw15A== X-Received: by 2002:a5d:570e:0:b0:37c:ccbc:6573 with SMTP id ffacd0b85a97d-37cd5ab7301mr6384687f8f.18.1727729477233; Mon, 30 Sep 2024 13:51:17 -0700 (PDT) Received: from localhost (net-188-216-80-179.cust.vodafonedsl.it. [188.216.80.179]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37cd564bf8bsm10233049f8f.20.2024.09.30.13.51.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 13:51:14 -0700 (PDT) From: Paolo Valerio To: ovs-dev@openvswitch.org Date: Mon, 30 Sep 2024 22:50:32 +0200 Message-ID: <20240930205034.65484-4-pvalerio@redhat.com> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20240930205034.65484-1-pvalerio@redhat.com> References: <20240930205034.65484-1-pvalerio@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH v2 4/6] conntrack: Turn zl local limit into atomic. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" while at it, changes struct zone_limit initialization in zone_limit_create() in order to use atomic init operations instead of relying on memset() which, although correctly initializes the struct, is semantically not aware of atomics. Signed-off-by: Paolo Valerio --- v2: - Fixed typo s/semantially/semantically (Aaron) --- lib/conntrack-private.h | 2 +- lib/conntrack.c | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/conntrack-private.h b/lib/conntrack-private.h index 2c625d710..2770470d1 100644 --- a/lib/conntrack-private.h +++ b/lib/conntrack-private.h @@ -201,7 +201,7 @@ enum ct_ephemeral_range { struct conntrack_zone_limit { int32_t zone; - uint32_t limit; + atomic_uint32_t limit; atomic_count count; uint32_t zone_limit_seq; /* Used to disambiguate zone limit counts. */ }; diff --git a/lib/conntrack.c b/lib/conntrack.c index 112d43216..3d19d37df 100644 --- a/lib/conntrack.c +++ b/lib/conntrack.c @@ -341,7 +341,7 @@ zone_limit_get(struct conntrack *ct, int32_t zone) struct zone_limit *zl = zone_limit_lookup_or_default(ct, zone); if (zl) { czl.zone = zl->czl.zone; - czl.limit = zl->czl.limit; + atomic_read_relaxed(&zl->czl.limit, &czl.limit); czl.count = atomic_count_get(&zl->czl.count); } return czl; @@ -358,8 +358,9 @@ zone_limit_create(struct conntrack *ct, int32_t zone, uint32_t limit) } if (zone >= DEFAULT_ZONE && zone <= MAX_ZONE) { - zl = xzalloc(sizeof *zl); - zl->czl.limit = limit; + zl = xmalloc(sizeof *zl); + atomic_init(&zl->czl.limit, limit); + atomic_count_init(&zl->czl.count, 0); zl->czl.zone = zone; zl->czl.zone_limit_seq = ct->zone_limit_seq++; uint32_t hash = zone_key_hash(zone, ct->hash_basis); @@ -376,7 +377,7 @@ zone_limit_update(struct conntrack *ct, int32_t zone, uint32_t limit) int err = 0; struct zone_limit *zl = zone_limit_lookup(ct, zone); if (zl) { - zl->czl.limit = limit; + atomic_store_relaxed(&zl->czl.limit, limit); VLOG_INFO("Changed zone limit of %u for zone %d", limit, zone); } else { ovs_mutex_lock(&ct->ct_lock); @@ -916,12 +917,16 @@ conn_not_found(struct conntrack *ct, struct dp_packet *pkt, } if (commit) { + uint32_t czl_limit; struct conn_key_node *fwd_key_node, *rev_key_node; struct zone_limit *zl = zone_limit_lookup_or_default(ct, ctx->key.zone); - if (zl && atomic_count_get(&zl->czl.count) >= zl->czl.limit) { - COVERAGE_INC(conntrack_zone_full); - return nc; + if (zl) { + atomic_read_relaxed(&zl->czl.limit, &czl_limit); + if (atomic_count_get(&zl->czl.count) >= czl_limit) { + COVERAGE_INC(conntrack_zone_full); + return nc; + } } unsigned int n_conn_limit;