All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] gve: fix the wrong AdminQ buffer queue index check
@ 2022-01-28  7:38 Haiyue Wang
  2022-01-28 10:47 ` [PATCH v2] " Haiyue Wang
  0 siblings, 1 reply; 3+ messages in thread
From: Haiyue Wang @ 2022-01-28  7:38 UTC (permalink / raw)
  To: netdev
  Cc: Haiyue Wang, Jeroen de Borst, Catherine Sullivan,
	David Awogbemila, David S. Miller, Jakub Kicinski,
	Willem de Bruijn, Bailey Forrest, Shailend Chand, Sagi Shahar,
	Yangchun Fu, open list

The 'tail' and 'head' are 'unsigned int' type free-running count, when
'head' is overflow, the 'int i (= tail) < u32 head' will be false:

Only '- loop 0: idx = 63' result is shown, so it needs to use 'int' type
to compare, it can handle the overflow correctly.

typedef uint32_t u32;

int main()
{
        u32 tail, head;
        int stail, shead;
        int i, loop;

        tail = 0xffffffff;
        head = 0x00000000;

        for (i = tail, loop = 0; i < head; i++) {
                unsigned int idx = i & 63;

                printf("+ loop %d: idx = %u\n", loop++, idx);
        }

        stail = tail;
        shead = head;
        for (i = stail, loop = 0; i < shead; i++) {
                unsigned int idx = i & 63;

                printf("- loop %d: idx = %u\n", loop++, idx);
        }

        return 0;
}

Fixes: 5cdad90de62c ("gve: Batch AQ commands for creating and destroying queues.")

Signed-off-by: Haiyue Wang <haiyue.wang@intel.com>
---
 drivers/net/ethernet/google/gve/gve_adminq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/google/gve/gve_adminq.c b/drivers/net/ethernet/google/gve/gve_adminq.c
index 2ad7f57f7e5b..f7621ab672b9 100644
--- a/drivers/net/ethernet/google/gve/gve_adminq.c
+++ b/drivers/net/ethernet/google/gve/gve_adminq.c
@@ -301,7 +301,7 @@ static int gve_adminq_parse_err(struct gve_priv *priv, u32 status)
  */
 static int gve_adminq_kick_and_wait(struct gve_priv *priv)
 {
-	u32 tail, head;
+	int tail, head;
 	int i;
 
 	tail = ioread32be(&priv->reg_bar0->adminq_event_counter);
-- 
2.35.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v2] gve: fix the wrong AdminQ buffer queue index check
  2022-01-28  7:38 [PATCH v1] gve: fix the wrong AdminQ buffer queue index check Haiyue Wang
@ 2022-01-28 10:47 ` Haiyue Wang
  2022-01-28 15:10   ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 3+ messages in thread
From: Haiyue Wang @ 2022-01-28 10:47 UTC (permalink / raw)
  To: netdev
  Cc: Haiyue Wang, Jeroen de Borst, Catherine Sullivan,
	David Awogbemila, David S. Miller, Jakub Kicinski,
	Bailey Forrest, Willem de Bruijn, Shailend Chand, Yangchun Fu,
	Sagi Shahar, open list

The 'tail' and 'head' are 'unsigned int' type free-running count, when
'head' is overflow, the 'int i (= tail) < u32 head' will be false:

Only '- loop 0: idx = 63' result is shown, so it needs to use 'int' type
to compare, it can handle the overflow correctly.

typedef uint32_t u32;

int main()
{
        u32 tail, head;
        int stail, shead;
        int i, loop;

        tail = 0xffffffff;
        head = 0x00000000;

        for (i = tail, loop = 0; i < head; i++) {
                unsigned int idx = i & 63;

                printf("+ loop %d: idx = %u\n", loop++, idx);
        }

        stail = tail;
        shead = head;
        for (i = stail, loop = 0; i < shead; i++) {
                unsigned int idx = i & 63;

                printf("- loop %d: idx = %u\n", loop++, idx);
        }

        return 0;
}

Fixes: 5cdad90de62c ("gve: Batch AQ commands for creating and destroying queues.")
Signed-off-by: Haiyue Wang <haiyue.wang@intel.com>
---
v2: Fix empty lines surround the Fixes tag
---
 drivers/net/ethernet/google/gve/gve_adminq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/google/gve/gve_adminq.c b/drivers/net/ethernet/google/gve/gve_adminq.c
index 2ad7f57f7e5b..f7621ab672b9 100644
--- a/drivers/net/ethernet/google/gve/gve_adminq.c
+++ b/drivers/net/ethernet/google/gve/gve_adminq.c
@@ -301,7 +301,7 @@ static int gve_adminq_parse_err(struct gve_priv *priv, u32 status)
  */
 static int gve_adminq_kick_and_wait(struct gve_priv *priv)
 {
-	u32 tail, head;
+	int tail, head;
 	int i;
 
 	tail = ioread32be(&priv->reg_bar0->adminq_event_counter);
-- 
2.35.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] gve: fix the wrong AdminQ buffer queue index check
  2022-01-28 10:47 ` [PATCH v2] " Haiyue Wang
@ 2022-01-28 15:10   ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-01-28 15:10 UTC (permalink / raw)
  To: Haiyue Wang
  Cc: netdev, jeroendb, csully, awogbemila, davem, kuba, bcf, willemb,
	shailend, yangchun, sagis, linux-kernel

Hello:

This patch was applied to netdev/net.git (master)
by David S. Miller <davem@davemloft.net>:

On Fri, 28 Jan 2022 18:47:14 +0800 you wrote:
> The 'tail' and 'head' are 'unsigned int' type free-running count, when
> 'head' is overflow, the 'int i (= tail) < u32 head' will be false:
> 
> Only '- loop 0: idx = 63' result is shown, so it needs to use 'int' type
> to compare, it can handle the overflow correctly.
> 
> typedef uint32_t u32;
> 
> [...]

Here is the summary with links:
  - [v2] gve: fix the wrong AdminQ buffer queue index check
    https://git.kernel.org/netdev/net/c/1f84a9450d75

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-01-28 15:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-28  7:38 [PATCH v1] gve: fix the wrong AdminQ buffer queue index check Haiyue Wang
2022-01-28 10:47 ` [PATCH v2] " Haiyue Wang
2022-01-28 15:10   ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.