public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xen: xenbus: Fix a possible data race in xs_request_enter
@ 2018-05-08  3:34 Jia-Ju Bai
  2018-05-08  7:02 ` Juergen Gross
  0 siblings, 1 reply; 3+ messages in thread
From: Jia-Ju Bai @ 2018-05-08  3:34 UTC (permalink / raw)
  To: boris.ostrovsky, jgross, simon, joao.m.martins
  Cc: xen-devel, linux-kernel, Jia-Ju Bai

The read operation to "req->type" is protected by
the lock on line 128, but the write operation to
this data on line 118 is not protected by the lock.
Thus, there may exist a data race for "req->type".

To fix this data race, the write operation to "req->type" 
should be also protected by the lock.

Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
 drivers/xen/xenbus/xenbus_xs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/xen/xenbus/xenbus_xs.c b/drivers/xen/xenbus/xenbus_xs.c
index 49a3874ae6bb..274cdfee08b1 100644
--- a/drivers/xen/xenbus/xenbus_xs.c
+++ b/drivers/xen/xenbus/xenbus_xs.c
@@ -115,10 +115,10 @@ static uint32_t xs_request_enter(struct xb_req_data *req)
 {
 	uint32_t rq_id;
 
-	req->type = req->msg.type;
-
 	spin_lock(&xs_state_lock);
 
+	req->type = req->msg.type;
+
 	while (!xs_state_users && xs_suspend_active) {
 		spin_unlock(&xs_state_lock);
 		wait_event(xs_state_enter_wq, xs_suspend_active == 0);
-- 
2.17.0

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

* Re: [PATCH] xen: xenbus: Fix a possible data race in xs_request_enter
  2018-05-08  3:34 [PATCH] xen: xenbus: Fix a possible data race in xs_request_enter Jia-Ju Bai
@ 2018-05-08  7:02 ` Juergen Gross
  2018-05-08  7:04   ` Jia-Ju Bai
  0 siblings, 1 reply; 3+ messages in thread
From: Juergen Gross @ 2018-05-08  7:02 UTC (permalink / raw)
  To: Jia-Ju Bai, boris.ostrovsky, simon, joao.m.martins
  Cc: xen-devel, linux-kernel

On 08/05/18 05:34, Jia-Ju Bai wrote:
> The read operation to "req->type" is protected by
> the lock on line 128, but the write operation to
> this data on line 118 is not protected by the lock.
> Thus, there may exist a data race for "req->type".
> 
> To fix this data race, the write operation to "req->type" 
> should be also protected by the lock.

No, xs_request_enter() is never called for a request already visible to
another thread or processor. So no race exists.


Juergen

> 
> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
> ---
>  drivers/xen/xenbus/xenbus_xs.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/xen/xenbus/xenbus_xs.c b/drivers/xen/xenbus/xenbus_xs.c
> index 49a3874ae6bb..274cdfee08b1 100644
> --- a/drivers/xen/xenbus/xenbus_xs.c
> +++ b/drivers/xen/xenbus/xenbus_xs.c
> @@ -115,10 +115,10 @@ static uint32_t xs_request_enter(struct xb_req_data *req)
>  {
>  	uint32_t rq_id;
>  
> -	req->type = req->msg.type;
> -
>  	spin_lock(&xs_state_lock);
>  
> +	req->type = req->msg.type;
> +
>  	while (!xs_state_users && xs_suspend_active) {
>  		spin_unlock(&xs_state_lock);
>  		wait_event(xs_state_enter_wq, xs_suspend_active == 0);
> 

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

* Re: [PATCH] xen: xenbus: Fix a possible data race in xs_request_enter
  2018-05-08  7:02 ` Juergen Gross
@ 2018-05-08  7:04   ` Jia-Ju Bai
  0 siblings, 0 replies; 3+ messages in thread
From: Jia-Ju Bai @ 2018-05-08  7:04 UTC (permalink / raw)
  To: Juergen Gross, boris.ostrovsky, simon, joao.m.martins
  Cc: xen-devel, linux-kernel



On 2018/5/8 15:02, Juergen Gross wrote:
> On 08/05/18 05:34, Jia-Ju Bai wrote:
>> The read operation to "req->type" is protected by
>> the lock on line 128, but the write operation to
>> this data on line 118 is not protected by the lock.
>> Thus, there may exist a data race for "req->type".
>>
>> To fix this data race, the write operation to "req->type"
>> should be also protected by the lock.
> No, xs_request_enter() is never called for a request already visible to
> another thread or processor. So no race exists.

Okay, thanks for your reply.


Best wishes,
Jia-Ju Bai

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

end of thread, other threads:[~2018-05-08  7:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-05-08  3:34 [PATCH] xen: xenbus: Fix a possible data race in xs_request_enter Jia-Ju Bai
2018-05-08  7:02 ` Juergen Gross
2018-05-08  7:04   ` Jia-Ju Bai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox