linux-kernel-mentees.lists.linuxfoundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] driver: gpu: Fixing warning directly dereferencing a rcu pointer
@ 2023-11-13  8:10 Abhinav Singh
  2023-11-13  8:24 ` Maarten Lankhorst
  0 siblings, 1 reply; 12+ messages in thread
From: Abhinav Singh @ 2023-11-13  8:10 UTC (permalink / raw)
  To: kherbst, lyude, dakr, airlied, daniel
  Cc: dri-devel, nouveau, linux-kernel, linux-kernel-mentees, Abhinav Singh

This patch fixes a sparse warning with this message 
"warning:dereference of noderef expression". In this context it means we
are dereferencing a __rcu tagged pointer directly.

We should not be directly dereferencing a rcu pointer, rather we should
be using rcu helper function rcu_dereferece() inside rcu read critical
section to get a normal pointer which can be dereferenced.

I tested with qemu with this command 
qemu-system-x86_64 \
	-m 2G \
	-smp 2 \
	-kernel bzImage \
	-append "console=ttyS0 root=/dev/sda earlyprintk=serial net.ifnames=0" \
	-drive file=bullseye.img,format=raw \
	-net user,host=10.0.2.10,hostfwd=tcp:127.0.0.1:10021-:22 \
	-net nic,model=e1000 \
	-enable-kvm \
	-nographic \
	-pidfile vm.pid \
	2>&1 | tee vm.log
with lockdep enabled.

Signed-off-by: Abhinav Singh <singhabhinav9051571833@gmail.com>
---
 drivers/gpu/drm/nouveau/nv04_fence.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/nouveau/nv04_fence.c b/drivers/gpu/drm/nouveau/nv04_fence.c
index 5b71a5a5cd85..e62bad1ac720 100644
--- a/drivers/gpu/drm/nouveau/nv04_fence.c
+++ b/drivers/gpu/drm/nouveau/nv04_fence.c
@@ -39,7 +39,9 @@ struct nv04_fence_priv {
 static int
 nv04_fence_emit(struct nouveau_fence *fence)
 {
-	struct nvif_push *push = fence->channel->chan.push;
+	rcu_read_lock();
+	struct nvif_push *push = rcu_dereference(fence->channel)->chan.push;
+	rcu_read_unlock();
 	int ret = PUSH_WAIT(push, 2);
 	if (ret == 0) {
 		PUSH_NVSQ(push, NV_SW, 0x0150, fence->base.seqno);
-- 
2.39.2


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

* Re: [PATCH] driver: gpu: Fixing warning directly dereferencing a rcu pointer
  2023-11-13  8:10 [PATCH] driver: gpu: Fixing warning directly dereferencing a rcu pointer Abhinav Singh
@ 2023-11-13  8:24 ` Maarten Lankhorst
  2023-11-13 17:10   ` Danilo Krummrich
  0 siblings, 1 reply; 12+ messages in thread
From: Maarten Lankhorst @ 2023-11-13  8:24 UTC (permalink / raw)
  To: Abhinav Singh, kherbst, lyude, dakr, airlied, daniel
  Cc: nouveau, linux-kernel-mentees, linux-kernel, dri-devel

Hey,

Den 2023-11-13 kl. 09:10, skrev Abhinav Singh:
> This patch fixes a sparse warning with this message
> "warning:dereference of noderef expression". In this context it means we
> are dereferencing a __rcu tagged pointer directly.
>
> We should not be directly dereferencing a rcu pointer, rather we should
> be using rcu helper function rcu_dereferece() inside rcu read critical
> section to get a normal pointer which can be dereferenced.
>
> I tested with qemu with this command
> qemu-system-x86_64 \
> 	-m 2G \
> 	-smp 2 \
> 	-kernel bzImage \
> 	-append "console=ttyS0 root=/dev/sda earlyprintk=serial net.ifnames=0" \
> 	-drive file=bullseye.img,format=raw \
> 	-net user,host=10.0.2.10,hostfwd=tcp:127.0.0.1:10021-:22 \
> 	-net nic,model=e1000 \
> 	-enable-kvm \
> 	-nographic \
> 	-pidfile vm.pid \
> 	2>&1 | tee vm.log
> with lockdep enabled.
>
> Signed-off-by: Abhinav Singh <singhabhinav9051571833@gmail.com>
> ---
>   drivers/gpu/drm/nouveau/nv04_fence.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/nouveau/nv04_fence.c b/drivers/gpu/drm/nouveau/nv04_fence.c
> index 5b71a5a5cd85..e62bad1ac720 100644
> --- a/drivers/gpu/drm/nouveau/nv04_fence.c
> +++ b/drivers/gpu/drm/nouveau/nv04_fence.c
> @@ -39,7 +39,9 @@ struct nv04_fence_priv {
>   static int
>   nv04_fence_emit(struct nouveau_fence *fence)
>   {
> -	struct nvif_push *push = fence->channel->chan.push;
> +	rcu_read_lock();
> +	struct nvif_push *push = rcu_dereference(fence->channel)->chan.push;
> +	rcu_read_unlock();
>   	int ret = PUSH_WAIT(push, 2);
>   	if (ret == 0) {
>   		PUSH_NVSQ(push, NV_SW, 0x0150, fence->base.seqno);

I'm not an expert in nouveau fence channel lifetime, but I'm pretty sure 
this should probably be a rcu_dereference_protected, since a fence 
likely can't lose its channel before its command to signal is submitted.

But in case it's not, I would at least advise to check for 
fence->channel lifetime before submitting a patch like this. At least 
the original code warned about it not being 100% correct.

Cheers,

~Maarten


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

* Re: [PATCH] driver: gpu: Fixing warning directly dereferencing a rcu pointer
  2023-11-13  8:24 ` Maarten Lankhorst
@ 2023-11-13 17:10   ` Danilo Krummrich
  2023-11-13 18:37     ` [PATCH v2] drivers: gpu: Fixing warning directly dereferencing a rcu pointer v2 Abhinav Singh
  2023-11-13 18:42     ` [PATCH v2] driver: gpu: Fixing warning directly dereferencing a rcu pointer Abhinav Singh
  0 siblings, 2 replies; 12+ messages in thread
From: Danilo Krummrich @ 2023-11-13 17:10 UTC (permalink / raw)
  To: Maarten Lankhorst, Abhinav Singh, kherbst, lyude, airlied, daniel
  Cc: nouveau, linux-kernel-mentees, linux-kernel, dri-devel

On 11/13/23 09:24, Maarten Lankhorst wrote:
> Hey,
> 
> Den 2023-11-13 kl. 09:10, skrev Abhinav Singh:
>> This patch fixes a sparse warning with this message
>> "warning:dereference of noderef expression". In this context it means we
>> are dereferencing a __rcu tagged pointer directly.
>>
>> We should not be directly dereferencing a rcu pointer, rather we should
>> be using rcu helper function rcu_dereferece() inside rcu read critical
>> section to get a normal pointer which can be dereferenced.
>>
>> I tested with qemu with this command
>> qemu-system-x86_64 \
>>     -m 2G \
>>     -smp 2 \
>>     -kernel bzImage \
>>     -append "console=ttyS0 root=/dev/sda earlyprintk=serial net.ifnames=0" \
>>     -drive file=bullseye.img,format=raw \
>>     -net user,host=10.0.2.10,hostfwd=tcp:127.0.0.1:10021-:22 \
>>     -net nic,model=e1000 \
>>     -enable-kvm \
>>     -nographic \
>>     -pidfile vm.pid \
>>     2>&1 | tee vm.log
>> with lockdep enabled.
>>
>> Signed-off-by: Abhinav Singh <singhabhinav9051571833@gmail.com>
>> ---
>>   drivers/gpu/drm/nouveau/nv04_fence.c | 4 +++-
>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/nouveau/nv04_fence.c b/drivers/gpu/drm/nouveau/nv04_fence.c
>> index 5b71a5a5cd85..e62bad1ac720 100644
>> --- a/drivers/gpu/drm/nouveau/nv04_fence.c
>> +++ b/drivers/gpu/drm/nouveau/nv04_fence.c
>> @@ -39,7 +39,9 @@ struct nv04_fence_priv {
>>   static int
>>   nv04_fence_emit(struct nouveau_fence *fence)
>>   {
>> -    struct nvif_push *push = fence->channel->chan.push;
>> +    rcu_read_lock();
>> +    struct nvif_push *push = rcu_dereference(fence->channel)->chan.push;
>> +    rcu_read_unlock();
>>       int ret = PUSH_WAIT(push, 2);
>>       if (ret == 0) {
>>           PUSH_NVSQ(push, NV_SW, 0x0150, fence->base.seqno);
> 
> I'm not an expert in nouveau fence channel lifetime, but I'm pretty sure this should probably be a rcu_dereference_protected, since a fence likely can't lose its channel before its command to signal is submitted.

Yes, before nouveau_fence_emit() did not add this fence to the fence context's
pending list ->channel doesn't need any protection. We can probably just use
unrcu_pointer(), as in [1].

[1] https://elixir.bootlin.com/linux/latest/source/drivers/gpu/drm/nouveau/nouveau_fence.c#L210

> 
> But in case it's not, I would at least advise to check for fence->channel lifetime before submitting a patch like this. At least the original code warned about it not being 100% correct.
> 
> Cheers,
> 
> ~Maarten
> 


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

* [PATCH v2] drivers: gpu: Fixing warning directly dereferencing a rcu pointer v2
  2023-11-13 17:10   ` Danilo Krummrich
@ 2023-11-13 18:37     ` Abhinav Singh
  2023-11-13 18:42     ` [PATCH v2] driver: gpu: Fixing warning directly dereferencing a rcu pointer Abhinav Singh
  1 sibling, 0 replies; 12+ messages in thread
From: Abhinav Singh @ 2023-11-13 18:37 UTC (permalink / raw)
  To: kherbst, lyude, dakr, airlied, daniel
  Cc: dri-devel, nouveau, linux-kernel, linux-kernel-mentees, Abhinav Singh

This patch fixes a sparse warning with this message 
"warning:dereference of noderef expression". In this context it means we
are dereferencing a __rcu tagged pointer directly.

We should not be directly dereferencing a rcu pointer, rather we should
be using rcu helper function rcu_dereferece() inside rcu read critical
section to get a normal pointer which can be dereferenced.

I tested with qemu with this command 
qemu-system-x86_64 \
	-m 2G \
	-smp 2 \
	-kernel bzImage \
	-append "console=ttyS0 root=/dev/sda earlyprintk=serial net.ifnames=0" \
	-drive file=bullseye.img,format=raw \
	-net user,host=10.0.2.10,hostfwd=tcp:127.0.0.1:10021-:22 \
	-net nic,model=e1000 \
	-enable-kvm \
	-nographic \
	-pidfile vm.pid \
	2>&1 | tee vm.log
with lockdep enabled.

Signed-off-by: Abhinav Singh <singhabhinav9051571833@gmail.com>
---
v1 -> v2 : Replaced the rcu_dereference(...) with unrcu_pointer(...) and
also removed the rcu locking and unlocking function call.

 drivers/gpu/drm/nouveau/nv04_fence.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/nouveau/nv04_fence.c b/drivers/gpu/drm/nouveau/nv04_fence.c
index 5b71a5a5cd85..cdbc75e3d1f6 100644
--- a/drivers/gpu/drm/nouveau/nv04_fence.c
+++ b/drivers/gpu/drm/nouveau/nv04_fence.c
@@ -39,7 +39,7 @@ struct nv04_fence_priv {
 static int
 nv04_fence_emit(struct nouveau_fence *fence)
 {
-	struct nvif_push *push = fence->channel->chan.push;
+	struct nvif_push *push = unrcu_pointer(fence->channel)->chan.push;
 	int ret = PUSH_WAIT(push, 2);
 	if (ret == 0) {
 		PUSH_NVSQ(push, NV_SW, 0x0150, fence->base.seqno);
-- 
2.39.2


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

* [PATCH v2] driver: gpu: Fixing warning directly dereferencing a rcu pointer
  2023-11-13 17:10   ` Danilo Krummrich
  2023-11-13 18:37     ` [PATCH v2] drivers: gpu: Fixing warning directly dereferencing a rcu pointer v2 Abhinav Singh
@ 2023-11-13 18:42     ` Abhinav Singh
  2023-11-13 18:49       ` Danilo Krummrich
  1 sibling, 1 reply; 12+ messages in thread
From: Abhinav Singh @ 2023-11-13 18:42 UTC (permalink / raw)
  To: kherbst, lyude, dakr, airlied, daniel
  Cc: dri-devel, nouveau, linux-kernel, linux-kernel-mentees, Abhinav Singh

This patch fixes a sparse warning with this message 
"warning:dereference of noderef expression". In this context it means we
are dereferencing a __rcu tagged pointer directly.

We should not be directly dereferencing a rcu pointer, rather we should
be using rcu helper function rcu_dereferece() inside rcu read critical
section to get a normal pointer which can be dereferenced.

I tested with qemu with this command 
qemu-system-x86_64 \
	-m 2G \
	-smp 2 \
	-kernel bzImage \
	-append "console=ttyS0 root=/dev/sda earlyprintk=serial net.ifnames=0" \
	-drive file=bullseye.img,format=raw \
	-net user,host=10.0.2.10,hostfwd=tcp:127.0.0.1:10021-:22 \
	-net nic,model=e1000 \
	-enable-kvm \
	-nographic \
	-pidfile vm.pid \
	2>&1 | tee vm.log
with lockdep enabled.

Signed-off-by: Abhinav Singh <singhabhinav9051571833@gmail.com>
---
v1 -> v2 : Replaced the rcu_dereference(...) with unrcu_pointer(...) and
also removed the rcu locking and unlocking function call.

 drivers/gpu/drm/nouveau/nv04_fence.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/nouveau/nv04_fence.c b/drivers/gpu/drm/nouveau/nv04_fence.c
index 5b71a5a5cd85..cdbc75e3d1f6 100644
--- a/drivers/gpu/drm/nouveau/nv04_fence.c
+++ b/drivers/gpu/drm/nouveau/nv04_fence.c
@@ -39,7 +39,7 @@ struct nv04_fence_priv {
 static int
 nv04_fence_emit(struct nouveau_fence *fence)
 {
-	struct nvif_push *push = fence->channel->chan.push;
+	struct nvif_push *push = unrcu_pointer(fence->channel)->chan.push;
 	int ret = PUSH_WAIT(push, 2);
 	if (ret == 0) {
 		PUSH_NVSQ(push, NV_SW, 0x0150, fence->base.seqno);
-- 
2.39.2


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

* Re: [PATCH v2] driver: gpu: Fixing warning directly dereferencing a rcu pointer
  2023-11-13 18:42     ` [PATCH v2] driver: gpu: Fixing warning directly dereferencing a rcu pointer Abhinav Singh
@ 2023-11-13 18:49       ` Danilo Krummrich
  2023-11-13 18:55         ` Abhinav Singh
  0 siblings, 1 reply; 12+ messages in thread
From: Danilo Krummrich @ 2023-11-13 18:49 UTC (permalink / raw)
  To: Abhinav Singh, kherbst, lyude, airlied, daniel
  Cc: dri-devel, nouveau, linux-kernel, linux-kernel-mentees

Hi,

thanks for sending a v2.

On 11/13/23 19:42, Abhinav Singh wrote:
> This patch fixes a sparse warning with this message
> "warning:dereference of noderef expression". In this context it means we
> are dereferencing a __rcu tagged pointer directly.

Better use imperative here, e.g. "Fix a sparse warning ...".

Wouldn't ask you to send a v3 for that alone...

> 
> We should not be directly dereferencing a rcu pointer, rather we should
> be using rcu helper function rcu_dereferece() inside rcu read critical
> section to get a normal pointer which can be dereferenced.

...but this doesn't seem accurate anymore as well.

- Danilo

> 
> I tested with qemu with this command
> qemu-system-x86_64 \
> 	-m 2G \
> 	-smp 2 \
> 	-kernel bzImage \
> 	-append "console=ttyS0 root=/dev/sda earlyprintk=serial net.ifnames=0" \
> 	-drive file=bullseye.img,format=raw \
> 	-net user,host=10.0.2.10,hostfwd=tcp:127.0.0.1:10021-:22 \
> 	-net nic,model=e1000 \
> 	-enable-kvm \
> 	-nographic \
> 	-pidfile vm.pid \
> 	2>&1 | tee vm.log
> with lockdep enabled.
> 
> Signed-off-by: Abhinav Singh <singhabhinav9051571833@gmail.com>
> ---
> v1 -> v2 : Replaced the rcu_dereference(...) with unrcu_pointer(...) and
> also removed the rcu locking and unlocking function call.
> 
>   drivers/gpu/drm/nouveau/nv04_fence.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/nouveau/nv04_fence.c b/drivers/gpu/drm/nouveau/nv04_fence.c
> index 5b71a5a5cd85..cdbc75e3d1f6 100644
> --- a/drivers/gpu/drm/nouveau/nv04_fence.c
> +++ b/drivers/gpu/drm/nouveau/nv04_fence.c
> @@ -39,7 +39,7 @@ struct nv04_fence_priv {
>   static int
>   nv04_fence_emit(struct nouveau_fence *fence)
>   {
> -	struct nvif_push *push = fence->channel->chan.push;
> +	struct nvif_push *push = unrcu_pointer(fence->channel)->chan.push;
>   	int ret = PUSH_WAIT(push, 2);
>   	if (ret == 0) {
>   		PUSH_NVSQ(push, NV_SW, 0x0150, fence->base.seqno);


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

* Re: [PATCH v2] driver: gpu: Fixing warning directly dereferencing a rcu pointer
  2023-11-13 18:49       ` Danilo Krummrich
@ 2023-11-13 18:55         ` Abhinav Singh
  2023-11-13 19:00           ` Danilo Krummrich
  0 siblings, 1 reply; 12+ messages in thread
From: Abhinav Singh @ 2023-11-13 18:55 UTC (permalink / raw)
  To: Danilo Krummrich, kherbst, lyude, airlied, daniel
  Cc: dri-devel, nouveau, linux-kernel, linux-kernel-mentees

On 11/14/23 00:19, Danilo Krummrich wrote:
> Hi,
> 
> thanks for sending a v2.
> 
> On 11/13/23 19:42, Abhinav Singh wrote:
>> This patch fixes a sparse warning with this message
>> "warning:dereference of noderef expression". In this context it means we
>> are dereferencing a __rcu tagged pointer directly.
> 
> Better use imperative here, e.g. "Fix a sparse warning ...".
> 
> Wouldn't ask you to send a v3 for that alone...
> 
>>
>> We should not be directly dereferencing a rcu pointer, rather we should
>> be using rcu helper function rcu_dereferece() inside rcu read critical
>> section to get a normal pointer which can be dereferenced.
> 
> ...but this doesn't seem accurate anymore as well.
> 
> - Danilo
> 
>>
>> I tested with qemu with this command
>> qemu-system-x86_64 \
>>     -m 2G \
>>     -smp 2 \
>>     -kernel bzImage \
>>     -append "console=ttyS0 root=/dev/sda earlyprintk=serial 
>> net.ifnames=0" \
>>     -drive file=bullseye.img,format=raw \
>>     -net user,host=10.0.2.10,hostfwd=tcp:127.0.0.1:10021-:22 \
>>     -net nic,model=e1000 \
>>     -enable-kvm \
>>     -nographic \
>>     -pidfile vm.pid \
>>     2>&1 | tee vm.log
>> with lockdep enabled.
>>
>> Signed-off-by: Abhinav Singh <singhabhinav9051571833@gmail.com>
>> ---
>> v1 -> v2 : Replaced the rcu_dereference(...) with unrcu_pointer(...) and
>> also removed the rcu locking and unlocking function call.
>>
>>   drivers/gpu/drm/nouveau/nv04_fence.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/nouveau/nv04_fence.c 
>> b/drivers/gpu/drm/nouveau/nv04_fence.c
>> index 5b71a5a5cd85..cdbc75e3d1f6 100644
>> --- a/drivers/gpu/drm/nouveau/nv04_fence.c
>> +++ b/drivers/gpu/drm/nouveau/nv04_fence.c
>> @@ -39,7 +39,7 @@ struct nv04_fence_priv {
>>   static int
>>   nv04_fence_emit(struct nouveau_fence *fence)
>>   {
>> -    struct nvif_push *push = fence->channel->chan.push;
>> +    struct nvif_push *push = unrcu_pointer(fence->channel)->chan.push;
>>       int ret = PUSH_WAIT(push, 2);
>>       if (ret == 0) {
>>           PUSH_NVSQ(push, NV_SW, 0x0150, fence->base.seqno);
> 
Hi maintainers thanks a lot for reviewing this patch.
I think I should fix my mistake by sending in another patch so that the 
code changes and description matches. So should I send another patch ?

Thank You,
Abhinav Singh

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

* Re: [PATCH v2] driver: gpu: Fixing warning directly dereferencing a rcu pointer
  2023-11-13 18:55         ` Abhinav Singh
@ 2023-11-13 19:00           ` Danilo Krummrich
  2023-11-13 19:13             ` [PATCH v3] " Abhinav Singh
  0 siblings, 1 reply; 12+ messages in thread
From: Danilo Krummrich @ 2023-11-13 19:00 UTC (permalink / raw)
  To: Abhinav Singh, kherbst, lyude, airlied, daniel
  Cc: dri-devel, nouveau, linux-kernel, linux-kernel-mentees

On 11/13/23 19:55, Abhinav Singh wrote:
> On 11/14/23 00:19, Danilo Krummrich wrote:
>> Hi,
>>
>> thanks for sending a v2.
>>
>> On 11/13/23 19:42, Abhinav Singh wrote:
>>> This patch fixes a sparse warning with this message
>>> "warning:dereference of noderef expression". In this context it means we
>>> are dereferencing a __rcu tagged pointer directly.
>>
>> Better use imperative here, e.g. "Fix a sparse warning ...".
>>
>> Wouldn't ask you to send a v3 for that alone...
>>
>>>
>>> We should not be directly dereferencing a rcu pointer, rather we should
>>> be using rcu helper function rcu_dereferece() inside rcu read critical
>>> section to get a normal pointer which can be dereferenced.
>>
>> ...but this doesn't seem accurate anymore as well.
>>
>> - Danilo
>>
>>>
>>> I tested with qemu with this command
>>> qemu-system-x86_64 \
>>>     -m 2G \
>>>     -smp 2 \
>>>     -kernel bzImage \
>>>     -append "console=ttyS0 root=/dev/sda earlyprintk=serial net.ifnames=0" \
>>>     -drive file=bullseye.img,format=raw \
>>>     -net user,host=10.0.2.10,hostfwd=tcp:127.0.0.1:10021-:22 \
>>>     -net nic,model=e1000 \
>>>     -enable-kvm \
>>>     -nographic \
>>>     -pidfile vm.pid \
>>>     2>&1 | tee vm.log
>>> with lockdep enabled.
>>>
>>> Signed-off-by: Abhinav Singh <singhabhinav9051571833@gmail.com>
>>> ---
>>> v1 -> v2 : Replaced the rcu_dereference(...) with unrcu_pointer(...) and
>>> also removed the rcu locking and unlocking function call.
>>>
>>>   drivers/gpu/drm/nouveau/nv04_fence.c | 2 +-
>>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/gpu/drm/nouveau/nv04_fence.c b/drivers/gpu/drm/nouveau/nv04_fence.c
>>> index 5b71a5a5cd85..cdbc75e3d1f6 100644
>>> --- a/drivers/gpu/drm/nouveau/nv04_fence.c
>>> +++ b/drivers/gpu/drm/nouveau/nv04_fence.c
>>> @@ -39,7 +39,7 @@ struct nv04_fence_priv {
>>>   static int
>>>   nv04_fence_emit(struct nouveau_fence *fence)
>>>   {
>>> -    struct nvif_push *push = fence->channel->chan.push;
>>> +    struct nvif_push *push = unrcu_pointer(fence->channel)->chan.push;
>>>       int ret = PUSH_WAIT(push, 2);
>>>       if (ret == 0) {
>>>           PUSH_NVSQ(push, NV_SW, 0x0150, fence->base.seqno);
>>
> Hi maintainers thanks a lot for reviewing this patch.
> I think I should fix my mistake by sending in another patch so that the code changes and description matches. So should I send another patch ?

Yes, please send a v3.

> 
> Thank You,
> Abhinav Singh
> 


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

* [PATCH v3] driver: gpu: Fixing warning directly dereferencing a rcu pointer
  2023-11-13 19:00           ` Danilo Krummrich
@ 2023-11-13 19:13             ` Abhinav Singh
  2023-11-13 19:31               ` Abhinav Singh
  2023-11-21  1:20               ` Danilo Krummrich
  0 siblings, 2 replies; 12+ messages in thread
From: Abhinav Singh @ 2023-11-13 19:13 UTC (permalink / raw)
  To: kherbst, lyude, dakr, airlied, daniel
  Cc: dri-devel, nouveau, linux-kernel, linux-kernel-mentees, Abhinav Singh

This patch fixes a sparse warning with this message 
"warning:dereference of noderef expression". In this context it means we
are dereferencing a __rcu tagged pointer directly.

We should not be directly dereferencing a rcu pointer. To get a normal
(non __rcu tagged pointer) from a __rcu tagged pointer we are using the
function unrcu_pointer(...). The non __rcu tagged pointer then can be
dereferenced just like a normal pointer.

I tested with qemu with this command 
qemu-system-x86_64 \
	-m 2G \
	-smp 2 \
	-kernel bzImage \
	-append "console=ttyS0 root=/dev/sda earlyprintk=serial net.ifnames=0" \
	-drive file=bullseye.img,format=raw \
	-net user,host=10.0.2.10,hostfwd=tcp:127.0.0.1:10021-:22 \
	-net nic,model=e1000 \
	-enable-kvm \
	-nographic \
	-pidfile vm.pid \
	2>&1 | tee vm.log
with lockdep enabled.

Signed-off-by: Abhinav Singh <singhabhinav9051571833@gmail.com>
---
v1 -> v2 : Replaced the rcu_dereference(...) with unrcu_pointer(...) and
           also removed the rcu locking and unlocking function call.
v2 -> v3 : Changed the description of the patch to match it with the actual
	   implementation.

 drivers/gpu/drm/nouveau/nv04_fence.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/nouveau/nv04_fence.c b/drivers/gpu/drm/nouveau/nv04_fence.c
index 5b71a5a5cd85..cdbc75e3d1f6 100644
--- a/drivers/gpu/drm/nouveau/nv04_fence.c
+++ b/drivers/gpu/drm/nouveau/nv04_fence.c
@@ -39,7 +39,7 @@ struct nv04_fence_priv {
 static int
 nv04_fence_emit(struct nouveau_fence *fence)
 {
-	struct nvif_push *push = fence->channel->chan.push;
+	struct nvif_push *push = unrcu_pointer(fence->channel)->chan.push;
 	int ret = PUSH_WAIT(push, 2);
 	if (ret == 0) {
 		PUSH_NVSQ(push, NV_SW, 0x0150, fence->base.seqno);
-- 
2.39.2


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

* Re: [PATCH v3] driver: gpu: Fixing warning directly dereferencing a rcu pointer
  2023-11-13 19:13             ` [PATCH v3] " Abhinav Singh
@ 2023-11-13 19:31               ` Abhinav Singh
  2023-11-21  1:20               ` Danilo Krummrich
  1 sibling, 0 replies; 12+ messages in thread
From: Abhinav Singh @ 2023-11-13 19:31 UTC (permalink / raw)
  To: kherbst, lyude, dakr, airlied, daniel
  Cc: dri-devel, nouveau, linux-kernel, linux-kernel-mentees

On 11/14/23 00:43, Abhinav Singh wrote:
> This patch fixes a sparse warning with this message
> "warning:dereference of noderef expression". In this context it means we
> are dereferencing a __rcu tagged pointer directly.
> 
> We should not be directly dereferencing a rcu pointer. To get a normal
> (non __rcu tagged pointer) from a __rcu tagged pointer we are using the
> function unrcu_pointer(...). The non __rcu tagged pointer then can be
> dereferenced just like a normal pointer.
> 
> I tested with qemu with this command
> qemu-system-x86_64 \
> 	-m 2G \
> 	-smp 2 \
> 	-kernel bzImage \
> 	-append "console=ttyS0 root=/dev/sda earlyprintk=serial net.ifnames=0" \
> 	-drive file=bullseye.img,format=raw \
> 	-net user,host=10.0.2.10,hostfwd=tcp:127.0.0.1:10021-:22 \
> 	-net nic,model=e1000 \
> 	-enable-kvm \
> 	-nographic \
> 	-pidfile vm.pid \
> 	2>&1 | tee vm.log
> with lockdep enabled.
> 
> Signed-off-by: Abhinav Singh <singhabhinav9051571833@gmail.com>
> ---
> v1 -> v2 : Replaced the rcu_dereference(...) with unrcu_pointer(...) and
>             also removed the rcu locking and unlocking function call.
> v2 -> v3 : Changed the description of the patch to match it with the actual
> 	   implementation.
> 
>   drivers/gpu/drm/nouveau/nv04_fence.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/nouveau/nv04_fence.c b/drivers/gpu/drm/nouveau/nv04_fence.c
> index 5b71a5a5cd85..cdbc75e3d1f6 100644
> --- a/drivers/gpu/drm/nouveau/nv04_fence.c
> +++ b/drivers/gpu/drm/nouveau/nv04_fence.c
> @@ -39,7 +39,7 @@ struct nv04_fence_priv {
>   static int
>   nv04_fence_emit(struct nouveau_fence *fence)
>   {
> -	struct nvif_push *push = fence->channel->chan.push;
> +	struct nvif_push *push = unrcu_pointer(fence->channel)->chan.push;
>   	int ret = PUSH_WAIT(push, 2);
>   	if (ret == 0) {
>   		PUSH_NVSQ(push, NV_SW, 0x0150, fence->base.seqno);
Hi, just for the sake of my own confirmation, the patch is merge ready 
right? once the CI runs successfully it will be merged right?


Thank You,
Abhinav Singh

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

* Re: [PATCH v3] driver: gpu: Fixing warning directly dereferencing a rcu pointer
  2023-11-13 19:13             ` [PATCH v3] " Abhinav Singh
  2023-11-13 19:31               ` Abhinav Singh
@ 2023-11-21  1:20               ` Danilo Krummrich
  2023-11-21  8:59                 ` Abhinav Singh
  1 sibling, 1 reply; 12+ messages in thread
From: Danilo Krummrich @ 2023-11-21  1:20 UTC (permalink / raw)
  To: Abhinav Singh, kherbst, lyude, airlied, daniel
  Cc: dri-devel, nouveau, linux-kernel, linux-kernel-mentees

On 11/13/23 20:13, Abhinav Singh wrote:
> This patch fixes a sparse warning with this message
> "warning:dereference of noderef expression". In this context it means we
> are dereferencing a __rcu tagged pointer directly.
> 
> We should not be directly dereferencing a rcu pointer. To get a normal
> (non __rcu tagged pointer) from a __rcu tagged pointer we are using the
> function unrcu_pointer(...). The non __rcu tagged pointer then can be
> dereferenced just like a normal pointer.
> 
> I tested with qemu with this command
> qemu-system-x86_64 \
> 	-m 2G \
> 	-smp 2 \
> 	-kernel bzImage \
> 	-append "console=ttyS0 root=/dev/sda earlyprintk=serial net.ifnames=0" \
> 	-drive file=bullseye.img,format=raw \
> 	-net user,host=10.0.2.10,hostfwd=tcp:127.0.0.1:10021-:22 \
> 	-net nic,model=e1000 \
> 	-enable-kvm \
> 	-nographic \
> 	-pidfile vm.pid \
> 	2>&1 | tee vm.log
> with lockdep enabled.
> 
> Signed-off-by: Abhinav Singh <singhabhinav9051571833@gmail.com>

Applied, thanks!

There are a few more such occurrences. [1][2] Plan to fix them as well?

[1] https://elixir.bootlin.com/linux/latest/source/drivers/gpu/drm/nouveau/nv10_fence.c#L35
[2] https://elixir.bootlin.com/linux/latest/source/drivers/gpu/drm/nouveau/nv84_fence.c#L88

> ---
> v1 -> v2 : Replaced the rcu_dereference(...) with unrcu_pointer(...) and
>             also removed the rcu locking and unlocking function call.
> v2 -> v3 : Changed the description of the patch to match it with the actual
> 	   implementation.
> 
>   drivers/gpu/drm/nouveau/nv04_fence.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/nouveau/nv04_fence.c b/drivers/gpu/drm/nouveau/nv04_fence.c
> index 5b71a5a5cd85..cdbc75e3d1f6 100644
> --- a/drivers/gpu/drm/nouveau/nv04_fence.c
> +++ b/drivers/gpu/drm/nouveau/nv04_fence.c
> @@ -39,7 +39,7 @@ struct nv04_fence_priv {
>   static int
>   nv04_fence_emit(struct nouveau_fence *fence)
>   {
> -	struct nvif_push *push = fence->channel->chan.push;
> +	struct nvif_push *push = unrcu_pointer(fence->channel)->chan.push;
>   	int ret = PUSH_WAIT(push, 2);
>   	if (ret == 0) {
>   		PUSH_NVSQ(push, NV_SW, 0x0150, fence->base.seqno);


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

* Re: [PATCH v3] driver: gpu: Fixing warning directly dereferencing a rcu pointer
  2023-11-21  1:20               ` Danilo Krummrich
@ 2023-11-21  8:59                 ` Abhinav Singh
  0 siblings, 0 replies; 12+ messages in thread
From: Abhinav Singh @ 2023-11-21  8:59 UTC (permalink / raw)
  To: Danilo Krummrich, kherbst, lyude, airlied, daniel
  Cc: dri-devel, nouveau, linux-kernel, linux-kernel-mentees

On 11/21/23 06:50, Danilo Krummrich wrote:
> On 11/13/23 20:13, Abhinav Singh wrote:
>> This patch fixes a sparse warning with this message
>> "warning:dereference of noderef expression". In this context it means we
>> are dereferencing a __rcu tagged pointer directly.
>>
>> We should not be directly dereferencing a rcu pointer. To get a normal
>> (non __rcu tagged pointer) from a __rcu tagged pointer we are using the
>> function unrcu_pointer(...). The non __rcu tagged pointer then can be
>> dereferenced just like a normal pointer.
>>
>> I tested with qemu with this command
>> qemu-system-x86_64 \
>>     -m 2G \
>>     -smp 2 \
>>     -kernel bzImage \
>>     -append "console=ttyS0 root=/dev/sda earlyprintk=serial 
>> net.ifnames=0" \
>>     -drive file=bullseye.img,format=raw \
>>     -net user,host=10.0.2.10,hostfwd=tcp:127.0.0.1:10021-:22 \
>>     -net nic,model=e1000 \
>>     -enable-kvm \
>>     -nographic \
>>     -pidfile vm.pid \
>>     2>&1 | tee vm.log
>> with lockdep enabled.
>>
>> Signed-off-by: Abhinav Singh <singhabhinav9051571833@gmail.com>
> 
> Applied, thanks!
> 
> There are a few more such occurrences. [1][2] Plan to fix them as well?
> 
> [1] 
> https://elixir.bootlin.com/linux/latest/source/drivers/gpu/drm/nouveau/nv10_fence.c#L35
> [2] 
> https://elixir.bootlin.com/linux/latest/source/drivers/gpu/drm/nouveau/nv84_fence.c#L88
> 
>> ---
>> v1 -> v2 : Replaced the rcu_dereference(...) with unrcu_pointer(...) and
>>             also removed the rcu locking and unlocking function call.
>> v2 -> v3 : Changed the description of the patch to match it with the 
>> actual
>>        implementation.
>>
>>   drivers/gpu/drm/nouveau/nv04_fence.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/nouveau/nv04_fence.c 
>> b/drivers/gpu/drm/nouveau/nv04_fence.c
>> index 5b71a5a5cd85..cdbc75e3d1f6 100644
>> --- a/drivers/gpu/drm/nouveau/nv04_fence.c
>> +++ b/drivers/gpu/drm/nouveau/nv04_fence.c
>> @@ -39,7 +39,7 @@ struct nv04_fence_priv {
>>   static int
>>   nv04_fence_emit(struct nouveau_fence *fence)
>>   {
>> -    struct nvif_push *push = fence->channel->chan.push;
>> +    struct nvif_push *push = unrcu_pointer(fence->channel)->chan.push;
>>       int ret = PUSH_WAIT(push, 2);
>>       if (ret == 0) {
>>           PUSH_NVSQ(push, NV_SW, 0x0150, fence->base.seqno);
> 
Thanks a lot for merging this.
Yeah sure I will submit the patch for the issues soon.

Regards,
Abhinav Singh

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

end of thread, other threads:[~2023-11-21  9:00 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-13  8:10 [PATCH] driver: gpu: Fixing warning directly dereferencing a rcu pointer Abhinav Singh
2023-11-13  8:24 ` Maarten Lankhorst
2023-11-13 17:10   ` Danilo Krummrich
2023-11-13 18:37     ` [PATCH v2] drivers: gpu: Fixing warning directly dereferencing a rcu pointer v2 Abhinav Singh
2023-11-13 18:42     ` [PATCH v2] driver: gpu: Fixing warning directly dereferencing a rcu pointer Abhinav Singh
2023-11-13 18:49       ` Danilo Krummrich
2023-11-13 18:55         ` Abhinav Singh
2023-11-13 19:00           ` Danilo Krummrich
2023-11-13 19:13             ` [PATCH v3] " Abhinav Singh
2023-11-13 19:31               ` Abhinav Singh
2023-11-21  1:20               ` Danilo Krummrich
2023-11-21  8:59                 ` Abhinav Singh

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).