From patchwork Tue Aug 20 13:14:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Pattrick X-Patchwork-Id: 1974416 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=RfDKfS/I; dkim-atps=neutral Authentication-Results: legolas.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=patchwork.ozlabs.org) 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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wp91V734lz1yXf for ; Tue, 20 Aug 2024 23:15:10 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id D2FAD60A3B; Tue, 20 Aug 2024 13:15:08 +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 A2H9tgSnVHDi; Tue, 20 Aug 2024 13:15:06 +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 smtp3.osuosl.org C284D608F4 Authentication-Results: smtp3.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=RfDKfS/I Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp3.osuosl.org (Postfix) with ESMTPS id C284D608F4; Tue, 20 Aug 2024 13:15:05 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id ABF1FC1029; Tue, 20 Aug 2024 13:15:04 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 767E6C102A for ; Tue, 20 Aug 2024 13:15:00 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 20792405F7 for ; Tue, 20 Aug 2024 13:15:00 +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 LFz4dQc5r5uD for ; Tue, 20 Aug 2024 13:14:59 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=170.10.133.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=mkp@redhat.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp4.osuosl.org CE4DE405D5 Authentication-Results: smtp4.osuosl.org; dmarc=pass (p=none dis=none) header.from=redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org CE4DE405D5 Authentication-Results: smtp4.osuosl.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=RfDKfS/I Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp4.osuosl.org (Postfix) with ESMTPS id CE4DE405D5 for ; Tue, 20 Aug 2024 13:14:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724159697; 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=Vi6o/HuvZU6f4pIkVI3TwqWJHu5BI62k06IkJ0/ZnDY=; b=RfDKfS/ImPa6SVKignnIzbyKl4bYzNu2KvgL0iQi92LaOCWGx5AsgHTnvaSCShM7L8zPUR l34OOGOrKQj9rkiu8xnHt+4xDFVEEnlL+iRrPhfK5Hp/+CNh8/YxYzODiiVeV1p9/0+Zg9 yr293wnUvGnKKEt3g0K7xrU/jgUHw/s= Received: from mx-prod-mc-04.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-216-03HxiTb9OiiAeo7CDqqqVw-1; Tue, 20 Aug 2024 09:14:56 -0400 X-MC-Unique: 03HxiTb9OiiAeo7CDqqqVw-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C13C41955D45 for ; Tue, 20 Aug 2024 13:14:55 +0000 (UTC) Received: from mpattric.remote.csb (unknown [10.22.33.24]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E217F1955DD6; Tue, 20 Aug 2024 13:14:54 +0000 (UTC) From: Mike Pattrick To: dev@openvswitch.org Date: Tue, 20 Aug 2024 09:14:41 -0400 Message-ID: <20240820131444.1724438-6-mkp@redhat.com> In-Reply-To: <20240820131444.1724438-1-mkp@redhat.com> References: <20240820131444.1724438-1-mkp@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH 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 simultaniously so all callers protect these functions from simultanious 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. Signed-off-by: Mike Pattrick 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);