From patchwork Mon Jul 1 12:27:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Valerio X-Patchwork-Id: 1954655 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=ZPPQvXhY; 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 4WCQK80QWtz1xpN for ; Mon, 1 Jul 2024 22:27:07 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 4EB4881D7C; Mon, 1 Jul 2024 12:27:06 +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 SzzL-UfeBoO7; Mon, 1 Jul 2024 12:27:05 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=2605:bc80:3010:104::8cd3:938; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 464F181772 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=ZPPQvXhY Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp1.osuosl.org (Postfix) with ESMTPS id 464F181772; Mon, 1 Jul 2024 12:27:05 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id F38F5C002B; Mon, 1 Jul 2024 12:27:04 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 17672C0033 for ; Mon, 1 Jul 2024 12:27:04 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 17162819F8 for ; Mon, 1 Jul 2024 12:27:01 +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 hVjAP-QRuH2B for ; Mon, 1 Jul 2024 12:27:00 +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 smtp1.osuosl.org 4C7F2818C9 Authentication-Results: smtp1.osuosl.org; dmarc=pass (p=none dis=none) header.from=redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 4C7F2818C9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by smtp1.osuosl.org (Postfix) with ESMTPS id 4C7F2818C9 for ; Mon, 1 Jul 2024 12:27:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719836819; 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=5cl4P2x95nFGJVZizv81KbJ+nAxs7tyW/dpra8mzg0Y=; b=ZPPQvXhYCUpRUYrS8pJX/vNvrC6+tdAXhBRrILlYNdAS6OZXakbhJ5fEZaUVZOr/2jTLuK W9WSch725ktsgerhbICfIfcc1myVUVGsnY4aYe1cZiqoq7rIw63opcNJ4CXRyL/fUNZ3x6 eUgAOAvPTzzFN/BxgJ5FPQ+7RJ2h/Nc= Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-571--3-QhEZYNo67P5rorvQSxA-1; Mon, 01 Jul 2024 08:26:58 -0400 X-MC-Unique: -3-QhEZYNo67P5rorvQSxA-1 Received: by mail-lf1-f70.google.com with SMTP id 2adb3069b0e04-52e7fe18878so526641e87.0 for ; Mon, 01 Jul 2024 05:26:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719836816; x=1720441616; 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=5cl4P2x95nFGJVZizv81KbJ+nAxs7tyW/dpra8mzg0Y=; b=ZshLkMhmDNSLWwfIno5PFc3dt0D9Tc7I+Mvl7Tb+4GYWE/p0UT6sTusktz/VXAIGG1 vqnGMplSiAcPs1SKEawvdMKvFCYU0jpNu2U/yXz14yAZM+IRMWULk3EUglGZu09Ksoq3 paf/0caFCFldqmfEQBETz7NJLGPAKNr259n3hE3LnwZmBaeqziDariLYKSA/uXafgFy0 h9zrGg1c8HlzmKWoIAKSHqocU34TshUOCrpdKQ7cpzvh9rwLUG+jsm+qLQLm212zSI30 z3sFUsY4W83a2z9Ek4hk7H4NODYXcXe8Zf9Alik0rU5bu8u+pjMTVeca8gHBy1lUr7hK JdyA== X-Gm-Message-State: AOJu0YyqxQbVTejacdF6MS1yOvrsnecnXzsIN+U76P2JHTGhXpR1NHXz udSvTObGoWZv4r6NVf9aoCrl+5Ilxco9kxJLRkTa9/z/U0bODwgYBjc+4Bg1X1SZxRTXhCGA7Q/ /YcUFeOFB/SHrEMmYfn4pJdqYsXppSLKCO8SvYeuHFol6HtXnl99WT5aKJEWWoQoEyzUL+MDQiT SRbXxpm2N1z3aPypFbmDmtGsjZgqfaVlDAkyMY39A= X-Received: by 2002:a05:6512:280a:b0:52e:7bb4:942d with SMTP id 2adb3069b0e04-52e82641bc5mr3445871e87.1.1719836816280; Mon, 01 Jul 2024 05:26:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH/BcywN3iRIgJhKyOaI+LQQoV34jXmaB/T0OfoW9fzWdlWXbRDx4JG1A1IRnMHM50jBM8NNg== X-Received: by 2002:a05:6512:280a:b0:52e:7bb4:942d with SMTP id 2adb3069b0e04-52e82641bc5mr3445861e87.1.1719836815851; Mon, 01 Jul 2024 05:26:55 -0700 (PDT) Received: from localhost (net-2-35-92-161.cust.vodafonedsl.it. [2.35.92.161]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a72ab0657b1sm326442266b.133.2024.07.01.05.26.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Jul 2024 05:26:54 -0700 (PDT) From: Paolo Valerio To: ovs-dev@openvswitch.org Date: Mon, 1 Jul 2024 14:27:19 +0200 Message-ID: <20240701122721.622994-5-pvalerio@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240701122721.622994-1-pvalerio@redhat.com> References: <20240701122721.622994-1-pvalerio@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH 4/5] 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 semantially not aware of atomics. Signed-off-by: Paolo Valerio --- 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 0481a8c8a..ac0790e11 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;