Skip to contentSkip to conversation

um: vector: use GFP_ATOMIC under spin lock

PATCH In review Wei Yongjun 4 participants 8 messages Nov 28, 2019

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 um: vector: use GFP_ATOMIC under spin lock

A spin lock is taken here so we should use GFP_ATOMIC.

Fixes 9807019a62dc ("um: Loadable BPF "Firmware" for vector drivers")
---
 arch/um/drivers/vector_kern.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/um/drivers/vector_kern.c +2 -2
index 92617e16829e..6ff0065a271d 100644
@@ -1402,7 +1402,7 @@ static int vector_net_load_bpf_flash(struct net_device *dev,
 		kfree(vp->bpf->filter);
 		vp->bpf->filter = NULL;
 	} else {
-		vp->bpf = kmalloc(sizeof(struct sock_fprog), GFP_KERNEL);
+		vp->bpf = kmalloc(sizeof(struct sock_fprog), GFP_ATOMIC);
 		if (vp->bpf = NULL) {
 			netdev_err(dev, "failed to allocate memory for firmware\n");
 			goto flash_fail;
@@ -1414,7 +1414,7 @@ static int vector_net_load_bpf_flash(struct net_device *dev,
 	if (request_firmware(&fw, efl->data, &vdevice->pdev.dev))
 		goto flash_fail;
 
-	vp->bpf->filter = kmemdup(fw->data, fw->size, GFP_KERNEL);
+	vp->bpf->filter = kmemdup(fw->data, fw->size, GFP_ATOMIC);
 	if (!vp->bpf->filter)
 		goto free_buffer;
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 25 lines · Wei Yongjun

A spin lock is taken here so we should use GFP_ATOMIC.

Fixes 9807019a62dc ("um: Loadable BPF "Firmware" for vector drivers")
---
  arch/um/drivers/vector_kern.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
arch/um/drivers/vector_kern.c +1 -1
index 92617e16829e..6ff0065a271d 100644
@@ -1402,7 +1402,7 @@ static int vector_net_load_bpf_flash(struct net_device *dev,
  		kfree(vp->bpf->filter);
  		vp->bpf->filter = NULL;
  	} else {
-		vp->bpf = kmalloc(sizeof(struct sock_fprog), GFP_KERNEL);
+		vp->bpf = kmalloc(sizeof(struct sock_fprog), GFP_ATOMIC);
  		if (vp->bpf = NULL) {
  			netdev_err(dev, "failed to allocate memory for firmware\n");
  			goto flash_fail;

arch/um/drivers/vector_kern.c static int vector_net_load_bpf_flash(struct net_device *dev, · line 1420

Quoted 8 lines
arch/um/drivers/vector_kern.c +1 -1
@@ -1414,7 +1414,7 @@ static int vector_net_load_bpf_flash(struct net_device *dev,
  	if (request_firmware(&fw, efl->data, &vdevice->pdev.dev))
  		goto flash_fail;
 
-	vp->bpf->filter = kmemdup(fw->data, fw->size, GFP_KERNEL);
+	vp->bpf->filter = kmemdup(fw->data, fw->size, GFP_ATOMIC);
  	if (!vp->bpf->filter)
  		goto free_buffer;
 
Quoted 5 lines

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

Signature · 3 lines
Anton R. Ivanov
Cambridgegreys Limited. Registered in England. Company Number 10273661
https://www.cambridgegreys.com/
#2 lore raw
In reply to Wei Yongjun
Quoted 22 lines · Wei Yongjun

A spin lock is taken here so we should use GFP_ATOMIC.

Fixes 9807019a62dc ("um: Loadable BPF "Firmware" for vector drivers")
---
 arch/um/drivers/vector_kern.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/um/drivers/vector_kern.c +1 -1
index 92617e16829e..6ff0065a271d 100644
@@ -1402,7 +1402,7 @@ static int vector_net_load_bpf_flash(struct net_device *dev,
 		kfree(vp->bpf->filter);
 		vp->bpf->filter = NULL;
 	} else {
-		vp->bpf = kmalloc(sizeof(struct sock_fprog), GFP_KERNEL);
+		vp->bpf = kmalloc(sizeof(struct sock_fprog), GFP_ATOMIC);
 		if (vp->bpf = NULL) {
 			netdev_err(dev, "failed to allocate memory for firmware\n");
 			goto flash_fail;

arch/um/drivers/vector_kern.c static int vector_net_load_bpf_flash(struct net_device *dev, · line 1414

Quoted 1 line
arch/um/drivers/vector_kern.c +0 -0
@@ -1414,7 +1414,7 @@ static int vector_net_load_bpf_flash(struct net_device *dev,
 	if (request_firmware(&fw, efl->data, &vdevice->pdev.dev))
            ^^^^^^^^^^^^^^^^

Is it really possible to call request_firmware() while holding a spin_lock? I was so sure that read from the disk.

regards,
dan carpenter

Quoted 8 lines
arch/um/drivers/vector_kern.c +1 -1
 		goto flash_fail;
 
-	vp->bpf->filter = kmemdup(fw->data, fw->size, GFP_KERNEL);
+	vp->bpf->filter = kmemdup(fw->data, fw->size, GFP_ATOMIC);
 	if (!vp->bpf->filter)
 		goto free_buffer;
 
maintainer
#3 lore raw
Quoted 26 lines · Dan Carpenter
Quoted 22 lines · Wei Yongjun

A spin lock is taken here so we should use GFP_ATOMIC.

Fixes 9807019a62dc ("um: Loadable BPF "Firmware" for vector drivers")
---
  arch/um/drivers/vector_kern.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
arch/um/drivers/vector_kern.c +1 -1
index 92617e16829e..6ff0065a271d 100644
@@ -1402,7 +1402,7 @@ static int vector_net_load_bpf_flash(struct net_device *dev,
  		kfree(vp->bpf->filter);
  		vp->bpf->filter = NULL;
  	} else {
-		vp->bpf = kmalloc(sizeof(struct sock_fprog), GFP_KERNEL);
+		vp->bpf = kmalloc(sizeof(struct sock_fprog), GFP_ATOMIC);
  		if (vp->bpf = NULL) {
  			netdev_err(dev, "failed to allocate memory for firmware\n");
  			goto flash_fail;

arch/um/drivers/vector_kern.c static int vector_net_load_bpf_flash(struct net_device *dev, · line 1414

Quoted 1 line
arch/um/drivers/vector_kern.c +0 -0
@@ -1414,7 +1414,7 @@ static int vector_net_load_bpf_flash(struct net_device *dev,
  	if (request_firmware(&fw, efl->data, &vdevice->pdev.dev))
             ^^^^^^^^^^^^^^^^
Quoted 2 lines

Is it really possible to call request_firmware() while holding a spin_lock? I was so sure that read from the disk.

Works, I tested the patch quite a few times.

Quoted 18 lines

regards,
dan carpenter

arch/um/drivers/vector_kern.c static int vector_net_load_bpf_flash(struct net_device *dev,

Quoted 8 lines
arch/um/drivers/vector_kern.c +1 -1
  		goto flash_fail;
 
-	vp->bpf->filter = kmemdup(fw->data, fw->size, GFP_KERNEL);
+	vp->bpf->filter = kmemdup(fw->data, fw->size, GFP_ATOMIC);
  	if (!vp->bpf->filter)
  		goto free_buffer;
 

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

Signature · 3 lines
Anton R. Ivanov
Cambridgegreys Limited. Registered in England. Company Number 10273661
https://www.cambridgegreys.com/
#4 lore raw
Quoted 29 lines · Anton Ivanov
Quoted 26 lines · Dan Carpenter
Quoted 22 lines · Wei Yongjun

A spin lock is taken here so we should use GFP_ATOMIC.

Fixes 9807019a62dc ("um: Loadable BPF "Firmware" for vector drivers")
---
  arch/um/drivers/vector_kern.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
arch/um/drivers/vector_kern.c +1 -1
index 92617e16829e..6ff0065a271d 100644
@@ -1402,7 +1402,7 @@ static int vector_net_load_bpf_flash(struct net_device *dev,
  		kfree(vp->bpf->filter);
  		vp->bpf->filter = NULL;
  	} else {
-		vp->bpf = kmalloc(sizeof(struct sock_fprog), GFP_KERNEL);
+		vp->bpf = kmalloc(sizeof(struct sock_fprog), GFP_ATOMIC);
  		if (vp->bpf = NULL) {
  			netdev_err(dev, "failed to allocate memory for firmware\n");
  			goto flash_fail;

arch/um/drivers/vector_kern.c static int vector_net_load_bpf_flash(struct net_device *dev, · line 1414

Quoted 1 line
arch/um/drivers/vector_kern.c +0 -0
@@ -1414,7 +1414,7 @@ static int vector_net_load_bpf_flash(struct net_device *dev,
  	if (request_firmware(&fw, efl->data, &vdevice->pdev.dev))
             ^^^^^^^^^^^^^^^^
Quoted 5 lines
Quoted 2 lines

Is it really possible to call request_firmware() while holding a spin_lock? I was so sure that read from the disk.

Works, I tested the patch quite a few times.

Do you have CONFIG_DEBUG_ATOMIC_SLEEP enabled? The GFP_KERNEL calls should have triggered a warning if so.

regards,
dan carpenter

maintainer
#5 lore raw
Quoted 30 lines · Dan Carpenter
Quoted 29 lines · Anton Ivanov
Quoted 26 lines · Dan Carpenter
Quoted 22 lines · Wei Yongjun

A spin lock is taken here so we should use GFP_ATOMIC.

Fixes 9807019a62dc ("um: Loadable BPF "Firmware" for vector drivers")
---
   arch/um/drivers/vector_kern.c | 4 ++--
   1 file changed, 2 insertions(+), 2 deletions(-)
arch/um/drivers/vector_kern.c +1 -1
index 92617e16829e..6ff0065a271d 100644
@@ -1402,7 +1402,7 @@ static int vector_net_load_bpf_flash(struct net_device *dev,
   		kfree(vp->bpf->filter);
   		vp->bpf->filter = NULL;
   	} else {
-		vp->bpf = kmalloc(sizeof(struct sock_fprog), GFP_KERNEL);
+		vp->bpf = kmalloc(sizeof(struct sock_fprog), GFP_ATOMIC);
   		if (vp->bpf = NULL) {
   			netdev_err(dev, "failed to allocate memory for firmware\n");
   			goto flash_fail;

arch/um/drivers/vector_kern.c static int vector_net_load_bpf_flash(struct net_device *dev, · line 1414

Quoted 1 line
arch/um/drivers/vector_kern.c +0 -0
@@ -1414,7 +1414,7 @@ static int vector_net_load_bpf_flash(struct net_device *dev,
   	if (request_firmware(&fw, efl->data, &vdevice->pdev.dev))
              ^^^^^^^^^^^^^^^^
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Is it really possible to call request_firmware() while holding a spin_lock? I was so sure that read from the disk.

Works, I tested the patch quite a few times.

Do you have CONFIG_DEBUG_ATOMIC_SLEEP enabled? The GFP_KERNEL calls should have triggered a warning if so.

I do not think we can use that in um.

config DEBUG_ATOMIC_SLEEP
bool "Sleep inside atomic section checking" select PREEMPT_COUNT
depends on DEBUG_KERNEL
depends on !ARCH_NO_PREEMPT

In arch/um/Kconfig

select ARCH_NO_PREEMPT

Brgds,

Quoted 10 lines

regards,
dan carpenter

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

Signature · 3 lines
Anton R. Ivanov
Cambridgegreys Limited. Registered in England. Company Number 10273661
https://www.cambridgegreys.com/
#6 lore raw
In reply to Anton Ivanov

----- Ursprüngliche Mail -----

Quoted 38 lines

Von: "anton ivanov" <[email protected]>
An: "Dan Carpenter" <[email protected]>, "Wei Yongjun" <[email protected]>
CC: "Song Liu" <[email protected]>, "Daniel Borkmann" <[email protected]>, "kernel-janitors" <[email protected]>, "richard" <[email protected]>, "Jeff Dike" <[email protected]>, "linux-um" <[email protected]>, "Alexei Starovoitov" <[email protected]>, "netdev" <[email protected]>, [email protected], "Martin KaFai Lau" <[email protected]>
Gesendet: Donnerstag, 28. November 2019 09:18:30
Betreff: Re: [PATCH -next] um: vector: use GFP_ATOMIC under spin lock

Quoted 28 lines · Dan Carpenter
Quoted 23 lines · Wei Yongjun

A spin lock is taken here so we should use GFP_ATOMIC.

Fixes 9807019a62dc ("um: Loadable BPF "Firmware" for vector drivers")
---
  arch/um/drivers/vector_kern.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
arch/um/drivers/vector_kern.c +1 -1
index 92617e16829e..6ff0065a271d 100644
@@ -1402,7 +1402,7 @@ static int vector_net_load_bpf_flash(struct net_device
 *dev,
  		kfree(vp->bpf->filter);
  		vp->bpf->filter = NULL;
  	} else {
-		vp->bpf = kmalloc(sizeof(struct sock_fprog), GFP_KERNEL);
+		vp->bpf = kmalloc(sizeof(struct sock_fprog), GFP_ATOMIC);
  		if (vp->bpf = NULL) {
  			netdev_err(dev, "failed to allocate memory for firmware\n");

goto flash_fail;

arch/um/drivers/vector_kern.c static int vector_net_load_bpf_flash(struct net_device · line 1415

Quoted 2 lines
arch/um/drivers/vector_kern.c +0 -0
@@ -1414,7 +1414,7 @@ static int vector_net_load_bpf_flash(struct net_device
 *dev,
  	if (request_firmware(&fw, efl->data, &vdevice->pdev.dev))
             ^^^^^^^^^^^^^^^^
Quoted 4 lines
Quoted 2 lines

Is it really possible to call request_firmware() while holding a spin_lock? I was so sure that read from the disk.

Works, I tested the patch quite a few times.

It works because of the nature of UML ->no SMP or PREEMPT. But better request the firmware before taking the spinlock. request_firmware() can block.
Same for the kmalloc(), just allocate the buffer before and then assign the pointer under the lock. That way you don't need GFP_ATOMIC.

Thanks,
//richard

maintainer
#7 lore raw
Quoted 42 lines · Richard Weinberger

----- Ursprüngliche Mail -----

Quoted 41 lines

Von: "anton ivanov" <[email protected]>
An: "Dan Carpenter" <[email protected]>, "Wei Yongjun" <[email protected]>
CC: "Song Liu" <[email protected]>, "Daniel Borkmann" <[email protected]>, "kernel-janitors" <[email protected]>, "richard" <[email protected]>, "Jeff Dike" <[email protected]>, "linux-um" <[email protected]>, "Alexei Starovoitov" <[email protected]>, "netdev" <[email protected]>, [email protected], "Martin KaFai Lau" <[email protected]>
Gesendet: Donnerstag, 28. November 2019 09:18:30
Betreff: Re: [PATCH -next] um: vector: use GFP_ATOMIC under spin lock

Quoted 30 lines · Dan Carpenter
Quoted 23 lines · Wei Yongjun

A spin lock is taken here so we should use GFP_ATOMIC.

Fixes 9807019a62dc ("um: Loadable BPF "Firmware" for vector drivers")
---
   arch/um/drivers/vector_kern.c | 4 ++--
   1 file changed, 2 insertions(+), 2 deletions(-)
arch/um/drivers/vector_kern.c +1 -1
index 92617e16829e..6ff0065a271d 100644
@@ -1402,7 +1402,7 @@ static int vector_net_load_bpf_flash(struct net_device
 *dev,
   		kfree(vp->bpf->filter);
   		vp->bpf->filter = NULL;
   	} else {
-		vp->bpf = kmalloc(sizeof(struct sock_fprog), GFP_KERNEL);
+		vp->bpf = kmalloc(sizeof(struct sock_fprog), GFP_ATOMIC);
   		if (vp->bpf = NULL) {
   			netdev_err(dev, "failed to allocate memory for firmware\n");
   			goto flash_fail;

arch/um/drivers/vector_kern.c static int vector_net_load_bpf_flash(struct net_device · line 1415

Quoted 2 lines
arch/um/drivers/vector_kern.c +0 -0
@@ -1414,7 +1414,7 @@ static int vector_net_load_bpf_flash(struct net_device
 *dev,
   	if (request_firmware(&fw, efl->data, &vdevice->pdev.dev))
              ^^^^^^^^^^^^^^^^

Is it really possible to call request_firmware() while holding a spin_lock? I was so sure that read from the disk.

Quoted 7 lines
Quoted 1 line

Works, I tested the patch quite a few times.

It works because of the nature of UML ->no SMP or PREEMPT. But better request the firmware before taking the spinlock. request_firmware() can block.
Same for the kmalloc(), just allocate the buffer before and then assign the pointer under the lock. That way you don't need GFP_ATOMIC.

Ack.

I will make an incremental on top of the existing patch (as that is already in -next

Brgds,

Quoted 9 lines

Thanks,
//richard

_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um

Signature · 3 lines
Anton R. Ivanov
Cambridgegreys Limited. Registered in England. Company Number 10273661
https://www.cambridgegreys.com/