Danilo Krummrich
2023-Nov-13 18:49 UTC
[Nouveau] [PATCH v2] driver: gpu: Fixing warning directly dereferencing a rcu pointer
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 at 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);
Abhinav Singh
2023-Nov-13 18:55 UTC
[PATCH v2] driver: gpu: Fixing warning directly dereferencing a rcu pointer
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 at 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
Danilo Krummrich
2023-Nov-13 19:00 UTC
[Nouveau] [PATCH v2] driver: gpu: Fixing warning directly dereferencing a rcu pointer
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 at 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 >