DPDK patches and discussions
 help / color / mirror / Atom feed
From: Marat Khalili <marat.khalili@huawei.com>
To: Bruce Richardson <bruce.richardson@intel.com>
Cc: "stable@dpdk.org" <stable@dpdk.org>, "dev@dpdk.org" <dev@dpdk.org>
Subject: RE: [PATCH v2 02/10] app/test: fix undefined behaviour in red autotest
Date: Fri, 5 Dec 2025 10:25:26 +0000	[thread overview]
Message-ID: <53551dad6ae64dcf9dc2111293481620@huawei.com> (raw)
In-Reply-To: <20251204182047.3154429-3-bruce.richardson@intel.com>

> -----Original Message-----
> From: Bruce Richardson <bruce.richardson@intel.com>
> Sent: Thursday 4 December 2025 18:21
> To: dev@dpdk.org
> Cc: Bruce Richardson <bruce.richardson@intel.com>; stable@dpdk.org
> Subject: [PATCH v2 02/10] app/test: fix undefined behaviour in red autotest
> 
> The shift of a negative number (or very large positive) is undefined
> behaviour which causes errors when run with UBSan. Fix this by making
> the behaviour explicit for the edge case of n being zero in the
> calculation.
> 
> Fixes: de3cfa2c9823 ("sched: initial import")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> ---
>  lib/sched/rte_red.h | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/sched/rte_red.h b/lib/sched/rte_red.h
> index e62abb9295..3b90cc46a9 100644
> --- a/lib/sched/rte_red.h
> +++ b/lib/sched/rte_red.h
> @@ -172,8 +172,15 @@ __rte_red_calc_qempty_factor(uint8_t wq_log2, uint16_t m)
>  	f = (n >> 6) & 0xf;
>  	n >>= 10;
> 
> -	if (n < RTE_RED_SCALING)
> +	if (n < RTE_RED_SCALING) {
> +		/* When n == 0, no rounding or shifting needed.
> +		 * For n > 0, add 2^(n-1) for rounding before right shift.
> +		 * This avoids UB from (1 << -1) when n == 0.
> +		 */
> +		if (n == 0)
> +			return (uint16_t) rte_red_pow2_frac_inv[f];
>  		return (uint16_t) ((rte_red_pow2_frac_inv[f] + (1 << (n - 1))) >> n);
> +	}
> 
>  	return 0;
>  }
> --
> 2.51.0

Acked-by: Marat Khalili <marat.khalili@huawei.com>

  reply	other threads:[~2025-12-05 10:25 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-02 15:49 [PATCH 0/2] improve fast-tests suite Bruce Richardson
2025-12-02 15:49 ` [PATCH 1/2] app/test: add some unattached tests to fast-test suite Bruce Richardson
2025-12-02 15:49 ` [PATCH 2/2] app/test: make parameters clearer when adding fast tests Bruce Richardson
2025-12-02 16:53   ` Marat Khalili
2025-12-02 18:16     ` Bruce Richardson
2025-12-04 18:20 ` [PATCH v2 00/10] Assign all unit tests to suites Bruce Richardson
2025-12-04 18:20   ` [PATCH v2 01/10] app/test: make parameters clearer when adding fast tests Bruce Richardson
2025-12-05 10:10     ` Marat Khalili
2025-12-05 10:17       ` Bruce Richardson
2025-12-04 18:20   ` [PATCH v2 02/10] app/test: fix undefined behaviour in red autotest Bruce Richardson
2025-12-05 10:25     ` Marat Khalili [this message]
2025-12-04 18:20   ` [PATCH v2 03/10] app/test: reduce duration of secondary timer test Bruce Richardson
2025-12-04 18:20   ` [PATCH v2 04/10] app/test: fix timer loop hang on secondary process failure Bruce Richardson
2025-12-04 18:20   ` [PATCH v2 05/10] eal: add internal APIs to query loaded driver paths Bruce Richardson
2025-12-04 18:20   ` [PATCH v2 06/10] app/test: pass loaded driver info to secondary procs Bruce Richardson
2025-12-04 18:20   ` [PATCH v2 07/10] app/test: skip power capabilities test if unsupported Bruce Richardson
2025-12-04 18:20   ` [PATCH v2 08/10] app/test: add some unattached tests to fast-test suite Bruce Richardson
2025-12-05 12:37     ` David Marchand
2025-12-05 12:43       ` Bruce Richardson
2025-12-05 12:50         ` David Marchand
2025-12-05 12:53           ` Bruce Richardson
2025-12-05 13:08             ` David Marchand
2025-12-04 18:20   ` [PATCH v2 09/10] app/test: add tests to driver test suite Bruce Richardson
2025-12-04 18:20   ` [PATCH v2 10/10] buildtools/get-test-suites: suppress empty output Bruce Richardson
2025-12-05 10:29     ` Marat Khalili

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=53551dad6ae64dcf9dc2111293481620@huawei.com \
    --to=marat.khalili@huawei.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=stable@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).