From patchwork Wed Dec 7 23:25:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balazs Nemeth X-Patchwork-Id: 1713481 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) 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=EN490NA9; dkim-atps=neutral Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NSD1G35yKz23ys for ; Thu, 8 Dec 2022 10:25:54 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 22580418CF; Wed, 7 Dec 2022 23:25:52 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 22580418CF 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=EN490NA9 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Hwnhn2IslmDS; Wed, 7 Dec 2022 23:25:51 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp4.osuosl.org (Postfix) with ESMTPS id E6EED41755; Wed, 7 Dec 2022 23:25:49 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org E6EED41755 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 990F8C0033; Wed, 7 Dec 2022 23:25:49 +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 ECD21C002D for ; Wed, 7 Dec 2022 23:25:47 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id C460081378 for ; Wed, 7 Dec 2022 23:25:47 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org C460081378 Authentication-Results: smtp1.osuosl.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=EN490NA9 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vt87ETzEbY2Z for ; Wed, 7 Dec 2022 23:25:46 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 6EBFB81322 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp1.osuosl.org (Postfix) with ESMTPS id 6EBFB81322 for ; Wed, 7 Dec 2022 23:25:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670455545; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/qN7q7rbscLW0JdMLX9Fn9PoqH5s1IVZcQTWCwPDfBQ=; b=EN490NA9ePcGjQSLPFvE23qYJejwRlMWXxSrEkhhi6cEULfU7WvDXr+YAKrvFygcPqMoI8 KKB6KVxhrld6DfRXbSefinMvVOwYp1079f6S+v/eO9ZdTa23q9OBj21pNeFLLKKNtfR7/K q641DhXID+cX98wyQMtCa5oTB129gIY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-342-foYL8xK9O5uYm4TOpaJeTw-1; Wed, 07 Dec 2022 18:25:44 -0500 X-MC-Unique: foYL8xK9O5uYm4TOpaJeTw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3562F85A59D for ; Wed, 7 Dec 2022 23:25:44 +0000 (UTC) Received: from bnemeth.users.ipa.redhat.com (unknown [10.39.192.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id E4509C15BA5; Wed, 7 Dec 2022 23:25:42 +0000 (UTC) From: Balazs Nemeth To: ovs-dev@openvswitch.org, bnemeth@redhat.com, echaudro@redhat.com, wizhao@redhat.com, mleitner@redhat.com, aconole@redhat.com Date: Thu, 8 Dec 2022 00:25:38 +0100 Message-Id: <0ef0ffb69b0b2a97528502d7225a05788c8bc638.1670455538.git.bnemeth@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH v4] ofproto-dpif-upcall: fix unintended side effect of statistics workaround 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" Besides the unrealistic case of an overflow, stats->n_packets can become less than ukey->stats.n_packets only when incorrect statistics were read. For that reason, the condition that the code employed is a workaround to avoid large jumps in statistics simply by assuming no packets were read. However, if this happens while the revalidator is under heavy load, the workaround has an unintended side effect where should_revalidate returns false because the metric it calculates is based on a bogus value. Therefore, this patch makes it explicit that the workaround has been triggered and consequently skipping should_revalidate assuming it should have returned true. Note also that the workaround is only triggered if stats->n_packets is _strictly_ less than ukey->stats.n_packets. Not receiving any packets is a valid scenario where should_revalidate should not be skipped. Signed-off-by: Balazs Nemeth Acked-by: Roi Dayan --- ofproto/ofproto-dpif-upcall.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ofproto/ofproto-dpif-upcall.c b/ofproto/ofproto-dpif-upcall.c index ad9635496..f0078e3c1 100644 --- a/ofproto/ofproto-dpif-upcall.c +++ b/ofproto/ofproto-dpif-upcall.c @@ -2327,6 +2327,7 @@ revalidate_ukey(struct udpif *udpif, struct udpif_key *ukey, OVS_REQUIRES(ukey->mutex) { bool need_revalidate = ukey->reval_seq != reval_seq; + bool stats_workaround; enum reval_result result = UKEY_DELETE; struct dpif_flow_stats push; @@ -2334,7 +2335,8 @@ revalidate_ukey(struct udpif *udpif, struct udpif_key *ukey, push.used = stats->used; push.tcp_flags = stats->tcp_flags; - push.n_packets = (stats->n_packets > ukey->stats.n_packets + stats_workaround = stats->n_packets < ukey->stats.n_packets; + push.n_packets = (!stats_workaround ? stats->n_packets - ukey->stats.n_packets : 0); push.n_bytes = (stats->n_bytes > ukey->stats.n_bytes @@ -2342,7 +2344,8 @@ revalidate_ukey(struct udpif *udpif, struct udpif_key *ukey, : 0); if (need_revalidate) { - if (should_revalidate(udpif, push.n_packets, ukey->stats.used)) { + if (stats_workaround || + should_revalidate(udpif, push.n_packets, ukey->stats.used)) { if (!ukey->xcache) { ukey->xcache = xlate_cache_new(); } else {