netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: Vadim Fedorenko <vadfed@meta.com>
Cc: Vadim Fedorenko <vfedorenko@novek.ru>,
	Aya Levin <ayal@nvidia.com>, Saeed Mahameed <saeedm@nvidia.com>,
	Gal Pressman <gal@nvidia.com>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: Re: [PATCH net v2 1/2] mlx5: fix possible ptp queue fifo overflow
Date: Wed, 25 Jan 2023 14:02:02 -0800	[thread overview]
Message-ID: <20230125140202.44744390@kernel.org> (raw)
In-Reply-To: <85fe01df-e194-2f3c-f20a-99a71051d1d9@meta.com>

On Tue, 24 Jan 2023 16:03:42 +0000 Vadim Fedorenko wrote:
> > Are you sure this works for all cases?
> > Directly comparing indexes of a ring buffer seems dangerous.
> > We'd need to compare like this:
> > 
> > 	(s16)(skb_cc - skb_id) < 0
> >  
> 
> Here I would like to count (and skip re-syncing) all the packets that 
> are not going to be in FIFO. Your suggestion will not work for the 
> simplest example. Imagine we have FIFO for 16 elements, and current 
> counters are:
>   (consumer) skb_cc = 13, (producer) skb_pc = 15, so 3 packets are in.
> Then skb_id = 10 arrives out-of-order. It will be counted because of 
> (skb_cc > skb_id), but will not be catched by (skb_cc - skb_id) < 0.

Oh, I may be confused about what the producer and consumer are.
The point I was trying to make is that comparing indexes on rings is
hard. Instead of writing:

	if (a < b)

you need to write:

	if ((signed)(a - b) < 0)

"mathematically" it's the same, but in "wrapping logic" it works
because if you're further than half a ring around then it counts 
as a second negation..

  reply	other threads:[~2023-01-25 22:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-24  0:08 [PATCH net v2 0/2] mlx5: bugfixes for ptp fifo queue Vadim Fedorenko
2023-01-24  0:08 ` [PATCH net v2 1/2] mlx5: fix possible ptp queue fifo overflow Vadim Fedorenko
2023-01-24  2:05   ` Rahul Rameshbabu
2023-01-24  4:19   ` Jakub Kicinski
2023-01-24 16:03     ` Vadim Fedorenko
2023-01-25 22:02       ` Jakub Kicinski [this message]
2023-01-24  0:08 ` [PATCH net v2 2/2] mlx5: fix skb leak while fifo resync Vadim Fedorenko

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=20230125140202.44744390@kernel.org \
    --to=kuba@kernel.org \
    --cc=ayal@nvidia.com \
    --cc=gal@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=saeedm@nvidia.com \
    --cc=vadfed@meta.com \
    --cc=vfedorenko@novek.ru \
    /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).