From patchwork Mon Sep 9 04:55:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Pattrick X-Patchwork-Id: 1982309 X-Patchwork-Delegate: echaudro@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=RzwzTvIy; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (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 4X2Dzk2rXrz1y1l for ; Mon, 9 Sep 2024 14:55:30 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 6E4E5404F5; Mon, 9 Sep 2024 04:55:28 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id CJh0Ikd8UzJf; Mon, 9 Sep 2024 04:55:27 +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 smtp4.osuosl.org 73212404E3 Authentication-Results: smtp4.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=RzwzTvIy Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp4.osuosl.org (Postfix) with ESMTPS id 73212404E3; Mon, 9 Sep 2024 04:55:26 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id A0BFBC0011; Mon, 9 Sep 2024 04:55:25 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) by lists.linuxfoundation.org (Postfix) with ESMTP id B4380C0014 for ; Mon, 9 Sep 2024 04:55:21 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 86FC240568 for ; Mon, 9 Sep 2024 04:55:21 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id ZiTQe45V0DOZ for ; Mon, 9 Sep 2024 04:55:20 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=170.10.129.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=mkp@redhat.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp2.osuosl.org 8EBB34052F Authentication-Results: smtp2.osuosl.org; dmarc=pass (p=none dis=none) header.from=redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 8EBB34052F Authentication-Results: smtp2.osuosl.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=RzwzTvIy 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 8EBB34052F for ; Mon, 9 Sep 2024 04:55:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1725857719; 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=Q773kjgbDuDYohw7ytWJm31bwakFP26ekZiLiRMm7/k=; b=RzwzTvIytVOX6D82YSKw4sMwylEIAQyiLgIKtFbwb3iCLjD9x2R/amqM0A8sdjE6JDkxiD TxQDTKN9JOEDMDeDZcc8jbvS83zuKMS1gv2sKZLPbWM1W2lX67QhbSpV1nHaea943WsHcw 0EVysVfilct4aQovq3ZjqgkIytjGkW8= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-271-doTTqKl5MVGU0hsP6_oMDg-1; Mon, 09 Sep 2024 00:55:18 -0400 X-MC-Unique: doTTqKl5MVGU0hsP6_oMDg-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 37B331956096 for ; Mon, 9 Sep 2024 04:55:17 +0000 (UTC) Received: from mpattric.remote.csb (unknown [10.22.9.170]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 14AD41956048; Mon, 9 Sep 2024 04:55:15 +0000 (UTC) From: Mike Pattrick To: dev@openvswitch.org Date: Mon, 9 Sep 2024 00:55:02 -0400 Message-ID: <20240909045505.236657-6-mkp@redhat.com> In-Reply-To: <20240909045505.236657-1-mkp@redhat.com> References: <20240909045505.236657-1-mkp@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH v3 5/8] classifier: Store n_indices between usage. 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" Currently the Clang analyzer will complain about usage of an uninitialized variable in the classifier. This is a false positive, but not for a reason that could easily be detectable by clang. The classifier is not safe for multiple writer threads to use simultaneously so all callers protect these functions from simultaneous writes. However, this is not so clear from the code's static analysis alone. To help Clang out here, the n_indicies count is saved onto the stack instead of accessed from the subtables struct repeatedly. Acked-by: Eelco Chaudron Signed-off-by: Mike Pattrick Acked-by: Eelco Chaudron Acked-by: Simon Horman --- lib/classifier.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/classifier.c b/lib/classifier.c index 0729bd190..55f23b976 100644 --- a/lib/classifier.c +++ b/lib/classifier.c @@ -527,6 +527,7 @@ classifier_replace(struct classifier *cls, const struct cls_rule *rule, struct cls_match *head; unsigned int mask_offset; size_t n_rules = 0; + uint8_t n_indices; uint32_t basis; uint32_t hash; unsigned int i; @@ -543,7 +544,8 @@ classifier_replace(struct classifier *cls, const struct cls_rule *rule, /* Compute hashes in segments. */ basis = 0; mask_offset = 0; - for (i = 0; i < subtable->n_indices; i++) { + n_indices = subtable->n_indices; + for (i = 0; i < n_indices; i++) { ihash[i] = minimatch_hash_range(&rule->match, subtable->index_maps[i], &mask_offset, &basis); } @@ -575,7 +577,7 @@ classifier_replace(struct classifier *cls, const struct cls_rule *rule, } /* Add new node to segment indices. */ - for (i = 0; i < subtable->n_indices; i++) { + for (i = 0; i < n_indices; i++) { ccmap_inc(&subtable->indices[i], ihash[i]); } n_rules = cmap_insert(&subtable->rules, &new->cmap_node, hash); @@ -713,6 +715,7 @@ classifier_remove(struct classifier *cls, const struct cls_rule *cls_rule) struct cls_subtable *subtable; uint32_t basis = 0, hash, ihash[CLS_MAX_INDICES]; unsigned int mask_offset; + uint8_t n_indices; size_t n_rules; unsigned int i; @@ -730,7 +733,8 @@ classifier_remove(struct classifier *cls, const struct cls_rule *cls_rule) ovs_assert(subtable); mask_offset = 0; - for (i = 0; i < subtable->n_indices; i++) { + n_indices = subtable->n_indices; + for (i = 0; i < n_indices; i++) { ihash[i] = minimatch_hash_range(&cls_rule->match, subtable->index_maps[i], &mask_offset, &basis); @@ -783,7 +787,7 @@ classifier_remove(struct classifier *cls, const struct cls_rule *cls_rule) } /* Remove rule node from indices. */ - for (i = 0; i < subtable->n_indices; i++) { + for (i = 0; i < n_indices; i++) { ccmap_dec(&subtable->indices[i], ihash[i]); } n_rules = cmap_remove(&subtable->rules, &rule->cmap_node, hash);