From patchwork Mon Apr 1 12:15:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladislav Odintsov X-Patchwork-Id: 1918452 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" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=VVe6wgJF; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) (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 4V7VMm0P5Kz1yYH for ; Mon, 1 Apr 2024 23:15:31 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 28BB44058F; Mon, 1 Apr 2024 12:15:30 +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 otCJ2_rLRe8a; Mon, 1 Apr 2024 12:15:29 +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 smtp2.osuosl.org 16B5F402F3 Authentication-Results: smtp2.osuosl.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=VVe6wgJF Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp2.osuosl.org (Postfix) with ESMTPS id 16B5F402F3; Mon, 1 Apr 2024 12:15:28 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 972C2C0072; Mon, 1 Apr 2024 12:15:28 +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 D8D8DC0037 for ; Mon, 1 Apr 2024 12:15:26 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id D54104031C for ; Mon, 1 Apr 2024 12:15:26 +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 hMjijimN0JqP for ; Mon, 1 Apr 2024 12:15:21 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=2a00:1450:4864:20::134; helo=mail-lf1-x134.google.com; envelope-from=odivlad@gmail.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp2.osuosl.org 3804F402F3 Authentication-Results: smtp2.osuosl.org; dmarc=pass (p=none dis=none) header.from=gmail.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 3804F402F3 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by smtp2.osuosl.org (Postfix) with ESMTPS id 3804F402F3 for ; Mon, 1 Apr 2024 12:15:21 +0000 (UTC) Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-513d247e3c4so3671812e87.0 for ; Mon, 01 Apr 2024 05:15:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711973718; x=1712578518; darn=openvswitch.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=GeB2+s7iLBImXam5XlWu4EnL720H9aYcVDaj5p27Amc=; b=VVe6wgJFcSsJz6mPsODgncxmxYCVQtO4noDhv7Iq328SqJ6MOOnga48el7+eeTtuq3 0lGjyY957lYu8R6+OaHM3Yj0jfGQSFS/cNrqp7rSrO02HAiASfeOQvbu0Jyb0RLui6Vx uTtRLayJedot7CDFKJr9W/2dOPixa+bVcWEiXvQO+/5vW4GU4PJnUdmetvs1h97eK7ps qWU3jlSxSfHdWdbN4XQ/Z/oTs3O31iqN1RweKeCqv/3kNM5NCcrRyqiGXxeRxt+p/9xc EAodvl5HdwN4ccXJXwqC9kYbvAnMbpltoEFrk388Ci8DIb+0InThgBPUiV3uoGtFiL04 5hPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711973718; x=1712578518; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=GeB2+s7iLBImXam5XlWu4EnL720H9aYcVDaj5p27Amc=; b=SIWeHamHwK1clpsM9j3+r9ilkpjEIvLb64PShHmSHYK8aceE2wBHWocNNPMN3XW3aJ IpDys8P3xa2NlG4IYi7NcY7xaOJAHMmojJfqN7j03RW2KgoylnfpiEeWCkv2DcN5xK14 bOYXbt4DrVBvKLm29mkfvOOAg6HLeUPzXNXrt50X0HmTQ0yF3JdHxqX1ISEv09+bNT6E 55+NRoVw3XfTIgR/WCPAsre8n7TdfXdfe+3Cbaiqg4tPIJe1f5LOmkuIWX55/BK8E+hH 0KwEyNplKrxxqUYvOUvbKDlHzpkvkO+Qbwmay8Qb7zipS1Hq6kvIS+XK6pEpZsImEubI 1uag== X-Gm-Message-State: AOJu0Ywsij9gbTu+bCi05prc3p/IRs6/0/xITCFBhjshqZDzlCn7XEMQ Kx0+QGkFmhMKclpk0051lF57VIBM9GH2zOs7sq8s5u29Z/VrpQGTq5wJMjQY X-Google-Smtp-Source: AGHT+IFxr1OvTSiz5vGdK0fOa42rE3Z/IOgXu1MYmVKU8b2WWSpkTjJ6IyPErn8AR+JBpnBXIMEMqQ== X-Received: by 2002:ac2:4844:0:b0:516:9f11:6f6f with SMTP id 4-20020ac24844000000b005169f116f6fmr1821410lfy.11.1711973718376; Mon, 01 Apr 2024 05:15:18 -0700 (PDT) Received: from ip-10-70-112-12.vpc-1e810be1.internal (c2-185-102-122-48.elastic.cloud.croc.ru. [185.102.122.48]) by smtp.gmail.com with ESMTPSA id h18-20020a056512221200b00516b061e091sm36032lfu.4.2024.04.01.05.15.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Apr 2024 05:15:18 -0700 (PDT) From: Vladislav Odintsov To: dev@openvswitch.org Date: Mon, 1 Apr 2024 15:15:08 +0300 Message-ID: <20240401121510.758326-1-odivlad@gmail.com> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 Cc: Vladislav Odintsov Subject: [ovs-dev] [PATCH ovn] northd: fix infinite loop in ovn_allocate_tnlid() 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" In case if all tunnel ids are exhausted, ovn_allocate_tnlid() function iterates over tnlids indefinitely when *hint is outside of [min, max]. This is because when tnlid reaches max, next tnlid is min and for-loop never reaches exit condition for tnlid != *hint. This patch fixes mentioned issue and adds a testcase. Signed-off-by: Vladislav Odintsov Acked-by: Mark Michelson --- lib/ovn-util.c | 10 +++++++--- tests/ovn-northd.at | 26 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/lib/ovn-util.c b/lib/ovn-util.c index ee5cbcdc3..9f97ae2ca 100644 --- a/lib/ovn-util.c +++ b/lib/ovn-util.c @@ -693,13 +693,17 @@ uint32_t ovn_allocate_tnlid(struct hmap *set, const char *name, uint32_t min, uint32_t max, uint32_t *hint) { - for (uint32_t tnlid = next_tnlid(*hint, min, max); tnlid != *hint; - tnlid = next_tnlid(tnlid, min, max)) { + /* Normalize hint, because it can be outside of [min, max]. */ + *hint = next_tnlid(*hint, min, max); + + uint32_t tnlid = *hint; + do { if (ovn_add_tnlid(set, tnlid)) { *hint = tnlid; return tnlid; } - } + tnlid = next_tnlid(tnlid, min, max); + } while (tnlid != *hint); static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1); VLOG_WARN_RL(&rl, "all %s tunnel ids exhausted", name); diff --git a/tests/ovn-northd.at b/tests/ovn-northd.at index cd53755b2..174dbacda 100644 --- a/tests/ovn-northd.at +++ b/tests/ovn-northd.at @@ -2822,6 +2822,32 @@ AT_CHECK([test $lsp02 = 3 && test $ls1 = 123]) AT_CLEANUP ]) +OVN_FOR_EACH_NORTHD_NO_HV([ +AT_SETUP([check tunnel ids exhaustion]) +ovn_start + +# Create a fake chassis with vxlan encap to lower MAX DP tunnel key to 2^12 +ovn-sbctl \ + --id=@e create encap chassis_name=hv1 ip="192.168.0.1" type="vxlan" \ + -- --id=@c create chassis name=hv1 encaps=@e + +cmd="ovn-nbctl --wait=sb" + +for i in {1..4097..1}; do + cmd="${cmd} -- ls-add lsw-${i}" +done + +eval $cmd + +check_row_count nb:Logical_Switch 4097 +wait_row_count sb:Datapath_Binding 4095 + +OVS_WAIT_UNTIL([grep "all datapath tunnel ids exhausted" northd/ovn-northd.log]) + +AT_CLEANUP +]) + + OVN_FOR_EACH_NORTHD_NO_HV([ AT_SETUP([Logical Flow Datapath Groups]) ovn_start