* [PATCH v1 1/1] platform/mellanox: fix potential race in mlxbf-tmfifo driver
@ 2023-04-26 14:23 Liming Sun
2023-05-09 8:38 ` Hans de Goede
2023-05-09 9:35 ` Vadim Pasternak
0 siblings, 2 replies; 4+ messages in thread
From: Liming Sun @ 2023-04-26 14:23 UTC (permalink / raw)
To: Vadim Pasternak, David Thompson, Hans de Goede, Mark Gross
Cc: Liming Sun, platform-driver-x86, linux-kernel
This commit adds memory barrier for the 'vq' update in function
mlxbf_tmfifo_virtio_find_vqs() to avoid potential race due to
out-of-order memory write. It also adds barrier for the 'is_ready'
flag to make sure the initializations are visible before this flag
is checked.
Signed-off-by: Liming Sun <limings@nvidia.com>
---
drivers/platform/mellanox/mlxbf-tmfifo.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/platform/mellanox/mlxbf-tmfifo.c b/drivers/platform/mellanox/mlxbf-tmfifo.c
index 91a077c35b8b..a79318e90a13 100644
--- a/drivers/platform/mellanox/mlxbf-tmfifo.c
+++ b/drivers/platform/mellanox/mlxbf-tmfifo.c
@@ -784,7 +784,7 @@ static void mlxbf_tmfifo_rxtx(struct mlxbf_tmfifo_vring *vring, bool is_rx)
fifo = vring->fifo;
/* Return if vdev is not ready. */
- if (!fifo->vdev[devid])
+ if (!fifo || !fifo->vdev[devid])
return;
/* Return if another vring is running. */
@@ -980,9 +980,13 @@ static int mlxbf_tmfifo_virtio_find_vqs(struct virtio_device *vdev,
vq->num_max = vring->num;
+ vq->priv = vring;
+
+ /* Make vq update visible before using it. */
+ virtio_mb(false);
+
vqs[i] = vq;
vring->vq = vq;
- vq->priv = vring;
}
return 0;
@@ -1302,6 +1306,9 @@ static int mlxbf_tmfifo_probe(struct platform_device *pdev)
mod_timer(&fifo->timer, jiffies + MLXBF_TMFIFO_TIMER_INTERVAL);
+ /* Make all updates visible before setting the 'is_ready' flag. */
+ virtio_mb(false);
+
fifo->is_ready = true;
return 0;
--
2.30.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1 1/1] platform/mellanox: fix potential race in mlxbf-tmfifo driver
2023-04-26 14:23 [PATCH v1 1/1] platform/mellanox: fix potential race in mlxbf-tmfifo driver Liming Sun
@ 2023-05-09 8:38 ` Hans de Goede
2023-05-09 9:35 ` Vadim Pasternak
1 sibling, 0 replies; 4+ messages in thread
From: Hans de Goede @ 2023-05-09 8:38 UTC (permalink / raw)
To: Liming Sun, Vadim Pasternak, David Thompson, Mark Gross
Cc: platform-driver-x86, linux-kernel
Vadim,
On 4/26/23 16:23, Liming Sun wrote:
> This commit adds memory barrier for the 'vq' update in function
> mlxbf_tmfifo_virtio_find_vqs() to avoid potential race due to
> out-of-order memory write. It also adds barrier for the 'is_ready'
> flag to make sure the initializations are visible before this flag
> is checked.
>
> Signed-off-by: Liming Sun <limings@nvidia.com>
Can you review this patch please ?
Regards,
Hans
> ---
> drivers/platform/mellanox/mlxbf-tmfifo.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/platform/mellanox/mlxbf-tmfifo.c b/drivers/platform/mellanox/mlxbf-tmfifo.c
> index 91a077c35b8b..a79318e90a13 100644
> --- a/drivers/platform/mellanox/mlxbf-tmfifo.c
> +++ b/drivers/platform/mellanox/mlxbf-tmfifo.c
> @@ -784,7 +784,7 @@ static void mlxbf_tmfifo_rxtx(struct mlxbf_tmfifo_vring *vring, bool is_rx)
> fifo = vring->fifo;
>
> /* Return if vdev is not ready. */
> - if (!fifo->vdev[devid])
> + if (!fifo || !fifo->vdev[devid])
> return;
>
> /* Return if another vring is running. */
> @@ -980,9 +980,13 @@ static int mlxbf_tmfifo_virtio_find_vqs(struct virtio_device *vdev,
>
> vq->num_max = vring->num;
>
> + vq->priv = vring;
> +
> + /* Make vq update visible before using it. */
> + virtio_mb(false);
> +
> vqs[i] = vq;
> vring->vq = vq;
> - vq->priv = vring;
> }
>
> return 0;
> @@ -1302,6 +1306,9 @@ static int mlxbf_tmfifo_probe(struct platform_device *pdev)
>
> mod_timer(&fifo->timer, jiffies + MLXBF_TMFIFO_TIMER_INTERVAL);
>
> + /* Make all updates visible before setting the 'is_ready' flag. */
> + virtio_mb(false);
> +
> fifo->is_ready = true;
> return 0;
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [PATCH v1 1/1] platform/mellanox: fix potential race in mlxbf-tmfifo driver
2023-04-26 14:23 [PATCH v1 1/1] platform/mellanox: fix potential race in mlxbf-tmfifo driver Liming Sun
2023-05-09 8:38 ` Hans de Goede
@ 2023-05-09 9:35 ` Vadim Pasternak
2023-05-09 9:56 ` Hans de Goede
1 sibling, 1 reply; 4+ messages in thread
From: Vadim Pasternak @ 2023-05-09 9:35 UTC (permalink / raw)
To: Liming Sun, David Thompson, Hans de Goede, Mark Gross
Cc: platform-driver-x86, linux-kernel
> -----Original Message-----
> From: Liming Sun <limings@nvidia.com>
> Sent: Wednesday, 26 April 2023 17:24
> To: Vadim Pasternak <vadimp@nvidia.com>; David Thompson
> <davthompson@nvidia.com>; Hans de Goede <hdegoede@redhat.com>;
> Mark Gross <markgross@kernel.org>
> Cc: Liming Sun <limings@nvidia.com>; platform-driver-x86@vger.kernel.org;
> linux-kernel@vger.kernel.org
> Subject: [PATCH v1 1/1] platform/mellanox: fix potential race in mlxbf-tmfifo
> driver
>
> This commit adds memory barrier for the 'vq' update in function
> mlxbf_tmfifo_virtio_find_vqs() to avoid potential race due to out-of-order
> memory write. It also adds barrier for the 'is_ready'
> flag to make sure the initializations are visible before this flag is checked.
>
> Signed-off-by: Liming Sun <limings@nvidia.com>
Reviewed-by: Vadim Pasternak <vadimp@nvidia.com>
> ---
> drivers/platform/mellanox/mlxbf-tmfifo.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/platform/mellanox/mlxbf-tmfifo.c
> b/drivers/platform/mellanox/mlxbf-tmfifo.c
> index 91a077c35b8b..a79318e90a13 100644
> --- a/drivers/platform/mellanox/mlxbf-tmfifo.c
> +++ b/drivers/platform/mellanox/mlxbf-tmfifo.c
> @@ -784,7 +784,7 @@ static void mlxbf_tmfifo_rxtx(struct
> mlxbf_tmfifo_vring *vring, bool is_rx)
> fifo = vring->fifo;
>
> /* Return if vdev is not ready. */
> - if (!fifo->vdev[devid])
> + if (!fifo || !fifo->vdev[devid])
> return;
>
> /* Return if another vring is running. */ @@ -980,9 +980,13 @@
> static int mlxbf_tmfifo_virtio_find_vqs(struct virtio_device *vdev,
>
> vq->num_max = vring->num;
>
> + vq->priv = vring;
> +
> + /* Make vq update visible before using it. */
> + virtio_mb(false);
> +
> vqs[i] = vq;
> vring->vq = vq;
> - vq->priv = vring;
> }
>
> return 0;
> @@ -1302,6 +1306,9 @@ static int mlxbf_tmfifo_probe(struct
> platform_device *pdev)
>
> mod_timer(&fifo->timer, jiffies + MLXBF_TMFIFO_TIMER_INTERVAL);
>
> + /* Make all updates visible before setting the 'is_ready' flag. */
> + virtio_mb(false);
> +
> fifo->is_ready = true;
> return 0;
>
> --
> 2.30.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v1 1/1] platform/mellanox: fix potential race in mlxbf-tmfifo driver
2023-05-09 9:35 ` Vadim Pasternak
@ 2023-05-09 9:56 ` Hans de Goede
0 siblings, 0 replies; 4+ messages in thread
From: Hans de Goede @ 2023-05-09 9:56 UTC (permalink / raw)
To: Vadim Pasternak, Liming Sun, David Thompson, Mark Gross
Cc: platform-driver-x86, linux-kernel
Hi,
On 5/9/23 11:35, Vadim Pasternak wrote:
>
>
>> -----Original Message-----
>> From: Liming Sun <limings@nvidia.com>
>> Sent: Wednesday, 26 April 2023 17:24
>> To: Vadim Pasternak <vadimp@nvidia.com>; David Thompson
>> <davthompson@nvidia.com>; Hans de Goede <hdegoede@redhat.com>;
>> Mark Gross <markgross@kernel.org>
>> Cc: Liming Sun <limings@nvidia.com>; platform-driver-x86@vger.kernel.org;
>> linux-kernel@vger.kernel.org
>> Subject: [PATCH v1 1/1] platform/mellanox: fix potential race in mlxbf-tmfifo
>> driver
>>
>> This commit adds memory barrier for the 'vq' update in function
>> mlxbf_tmfifo_virtio_find_vqs() to avoid potential race due to out-of-order
>> memory write. It also adds barrier for the 'is_ready'
>> flag to make sure the initializations are visible before this flag is checked.
>>
>> Signed-off-by: Liming Sun <limings@nvidia.com>
>
> Reviewed-by: Vadim Pasternak <vadimp@nvidia.com>
Thank you for your patch, I've applied this patch to my fixes
branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=fixes
Note it will show up in my fixes branch once I've pushed my
local branch there, which might take a while.
I will include this patch in my next fixes pull-req to Linus
for the current kernel development cycle.
Regards,
Hans
>> ---
>> drivers/platform/mellanox/mlxbf-tmfifo.c | 11 +++++++++--
>> 1 file changed, 9 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/platform/mellanox/mlxbf-tmfifo.c
>> b/drivers/platform/mellanox/mlxbf-tmfifo.c
>> index 91a077c35b8b..a79318e90a13 100644
>> --- a/drivers/platform/mellanox/mlxbf-tmfifo.c
>> +++ b/drivers/platform/mellanox/mlxbf-tmfifo.c
>> @@ -784,7 +784,7 @@ static void mlxbf_tmfifo_rxtx(struct
>> mlxbf_tmfifo_vring *vring, bool is_rx)
>> fifo = vring->fifo;
>>
>> /* Return if vdev is not ready. */
>> - if (!fifo->vdev[devid])
>> + if (!fifo || !fifo->vdev[devid])
>> return;
>>
>> /* Return if another vring is running. */ @@ -980,9 +980,13 @@
>> static int mlxbf_tmfifo_virtio_find_vqs(struct virtio_device *vdev,
>>
>> vq->num_max = vring->num;
>>
>> + vq->priv = vring;
>> +
>> + /* Make vq update visible before using it. */
>> + virtio_mb(false);
>> +
>> vqs[i] = vq;
>> vring->vq = vq;
>> - vq->priv = vring;
>> }
>>
>> return 0;
>> @@ -1302,6 +1306,9 @@ static int mlxbf_tmfifo_probe(struct
>> platform_device *pdev)
>>
>> mod_timer(&fifo->timer, jiffies + MLXBF_TMFIFO_TIMER_INTERVAL);
>>
>> + /* Make all updates visible before setting the 'is_ready' flag. */
>> + virtio_mb(false);
>> +
>> fifo->is_ready = true;
>> return 0;
>>
>> --
>> 2.30.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-05-09 9:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-26 14:23 [PATCH v1 1/1] platform/mellanox: fix potential race in mlxbf-tmfifo driver Liming Sun
2023-05-09 8:38 ` Hans de Goede
2023-05-09 9:35 ` Vadim Pasternak
2023-05-09 9:56 ` Hans de Goede
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®