From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dl1-f52.google.com (mail-dl1-f52.google.com [74.125.82.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4475233F5BE for ; Sat, 28 Mar 2026 18:23:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774722223; cv=none; b=X5eGcozAMOtw2hgB9blTaIiIdTX4Uzpa/UOxzbZZexYBCyAYH7jTSCH5eEJ2m6qRwY7E+G5q/i4fXNU+uH9Z+NmFQjZKX3+KSPlF0Ofg/DZ23bSmFC2nRz4nk7u3eiHM1wUR6GqqDk/nZRI6EoUsjTuWq3DwXBMfN5/fbdcidfA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774722223; c=relaxed/simple; bh=n5gLdW55iVjWbli7Cw3KezMlHCHUoFCYKjjm71hupcw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pTdF+JP/pAS9iC/erGWfGxftMZH6l0zxV29LbZKBDVPkpiFbZnxgMeffaM2edgKhrEUwgDHYsiBbjmUJiDEFVKQzdBMAVTijlzAUmKmjRDBr2B29ZeFAwEypFBSVMRcMci6XFcATSKXP5o+wmZ7qvxn0FNRflphzyC5bmE4SPLU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=networkplumber.org; spf=pass smtp.mailfrom=networkplumber.org; dkim=pass (2048-bit key) header.d=networkplumber-org.20230601.gappssmtp.com header.i=@networkplumber-org.20230601.gappssmtp.com header.b=IJUhw0tR; arc=none smtp.client-ip=74.125.82.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=networkplumber.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=networkplumber.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=networkplumber-org.20230601.gappssmtp.com header.i=@networkplumber-org.20230601.gappssmtp.com header.b="IJUhw0tR" Received: by mail-dl1-f52.google.com with SMTP id a92af1059eb24-1274204434bso3159135c88.1 for ; Sat, 28 Mar 2026 11:23:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1774722221; x=1775327021; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tmhsDMpsd/+3K0C1t5lpdl1RPDllE8WJo/RPfumhe9A=; b=IJUhw0tRtF1FYuAn/G/852kkfp0JQFVvsghiKlVtooSGZHrd0yMuB8qZT2hwwi+fra JSiuOoYRHRnUn+UibdufNqc1U2W+u1j2klLeXqLXa+w+1WJzFFKFRNtDuqoOTT6lQ+t3 e3Kz3hDSeuDHK8amCfq/95+lok1JwAsu4eruNGpDVYwDAE+RWsNaxUW3CeiDupPpVJvM x9HNsSR5lbrGIgr1cqOOmtCuzEtCb0XfQsePJE2E2EERScZ5L7EM0czQ9Fc8UtbRdUsh COGx0EQFQDB7oc7dT0SnTYFpTzN6BjdRFYASk8KcZjd5O/ZjFzTGM1hnQC8fBEQt9ux9 aEPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774722221; x=1775327021; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=tmhsDMpsd/+3K0C1t5lpdl1RPDllE8WJo/RPfumhe9A=; b=nDKbmX1kEa3RGNUXAvl2uw7ZC4r+bb9TCxHL6zWrijDMR8uy1nd4v+slp87Nc8D0qz SyR++6cpl8H7ruq99Vy5KDaCJ4QOqi0Vzy8DYxjPCHHspLBefj2N56H331EisiR8FwcA +tK7rkXPMYEEnZA9o1vHQW5Rp/fHMIYf/qWLd5gjVZ5owN7bAR8p7Pd7LsWcUWYxoHLG HD4T4Px8C0e20QZkgdSahhKDQ2QjoCo8cxquEVp9pAPoe9RoPYm3WNaUct9kVXcIv5+m 7uxFHoZhJoD/ojuqEbW7uozbPeuYMEXD7YaZGNMWrknFXqPm5BpN2Iy/T6GMAlGUKeZp x5Gw== X-Forwarded-Encrypted: i=1; AJvYcCWBpvNMszBdt2KevfQbCDx0QqFgLD9WYW1kljrHzdZ6+JQQwShAbGqY4hBqtFLblk3EGnDNVhoZzR+tefE=@vger.kernel.org X-Gm-Message-State: AOJu0Yx2WD8eWC9908+FhCubqQzBxJLphtUzaP+FAQtzCIZ5pwtIII8l 3hpuL7g9XScnfrivf+Y5BtynVY/Zx/+dPDaDpPA35ecARSFvRotlMg+6Cnc+FIbneRY= X-Gm-Gg: ATEYQzwh1UP7NG3ke7voyVjrOJ+sMy7FqD0phxZCdJhL82TpRmuwUFuK7n0v+sA5TQj HakRXh4iLPS7PDs2SkOTP3HvTQTeIg33BUwzEgGQIzIvkYS+EBOMRimvqdvzW+43a4XuRIDnnTh KPzpUBZnrX2xn/ibPfzJWRMKPqWfEIHRioo1pBEOiHf9iHr62cM4eUnXba0I3Am84MwTTHnj2Fy ds9P9kGU1B47XV0R32XLMK7AWjn4VuFi6Ap3PZEnN3NfIFGJ0syZFospUbD3xHGP4f4BzQkRrPd jNVoYMJugvG1YygZffTe4vIqtIO6yEvPKsx6fYW8sW1Ny5h5w0g3etD+lCV36djxbmYUfBlqG1n Y53gVwRZSvyLIoWPFoZS99RmNSbUhv0qOkeXr8iMNJLYy/peKoLMNvRZbbjdIZmnvhwFCLPTjD1 0SulLfEO56f/nlT+yz+A1zJj2t3jTuqZOJ X-Received: by 2002:a05:7022:f404:b0:128:cf41:d6e4 with SMTP id a92af1059eb24-12aabc052bemr4620868c88.21.1774722221335; Sat, 28 Mar 2026 11:23:41 -0700 (PDT) Received: from phoenix.lan ([104.202.29.139]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-12aba581027sm3133008c88.4.2026.03.28.11.23.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Mar 2026 11:23:40 -0700 (PDT) From: Stephen Hemminger To: netdev@vger.kernel.org Cc: Stephen Hemminger , Jamal Hadi Salim , Jiri Pirko , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , linux-kernel@vger.kernel.org (open list) Subject: [PATCH net 1/5] net/sched: netem: fix probability gaps in 4-state loss model Date: Sat, 28 Mar 2026 11:21:45 -0700 Message-ID: <20260328182336.392817-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260328182336.392817-1-stephen@networkplumber.org> References: <20260328182336.392817-1-stephen@networkplumber.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The 4-state Markov chain in loss_4state() has gaps at the boundaries between transition probability ranges. The comparisons use: if (rnd < a4) else if (a4 < rnd && rnd < a1 + a4) When rnd equals a boundary value exactly, neither branch matches and no state transition occurs. The redundant lower-bound check (a4 < rnd) is already implied by being in the else branch. Remove the unnecessary lower-bound comparisons so the ranges are contiguous and every random value produces a transition, matching the GI (General and Intuitive) loss model specification. This bug goes back to original implementation of this model. Fixes: 661b79725fea ("netem: revised correlated loss generator") Signed-off-by: Stephen Hemminger --- net/sched/sch_netem.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net/sched/sch_netem.c b/net/sched/sch_netem.c index 5de1c932944a..2cc3acaa4068 100644 --- a/net/sched/sch_netem.c +++ b/net/sched/sch_netem.c @@ -227,10 +227,10 @@ static bool loss_4state(struct netem_sched_data *q) if (rnd < clg->a4) { clg->state = LOST_IN_GAP_PERIOD; return true; - } else if (clg->a4 < rnd && rnd < clg->a1 + clg->a4) { + } else if (rnd < clg->a1 + clg->a4) { clg->state = LOST_IN_BURST_PERIOD; return true; - } else if (clg->a1 + clg->a4 < rnd) { + } else { clg->state = TX_IN_GAP_PERIOD; } @@ -247,9 +247,9 @@ static bool loss_4state(struct netem_sched_data *q) case LOST_IN_BURST_PERIOD: if (rnd < clg->a3) clg->state = TX_IN_BURST_PERIOD; - else if (clg->a3 < rnd && rnd < clg->a2 + clg->a3) { + else if (rnd < clg->a2 + clg->a3) { clg->state = TX_IN_GAP_PERIOD; - } else if (clg->a2 + clg->a3 < rnd) { + } else { clg->state = LOST_IN_BURST_PERIOD; return true; } -- 2.53.0