Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1258612 > unrolled thread
| Started by | Saurabh Sengar <saurabh.truth@gmail.com> |
|---|---|
| First post | 2015-10-29 08:30 +0100 |
| Last post | 2015-10-29 09:50 +0100 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH v2] um: net: replace GFP_KERNEL with GFP_ATOMIC when spinlock is held Saurabh Sengar <saurabh.truth@gmail.com> - 2015-10-29 08:30 +0100
Re: [PATCH v2] um: net: replace GFP_KERNEL with GFP_ATOMIC when spinlock is held Richard Weinberger <richard@nod.at> - 2015-10-29 09:50 +0100
| From | Saurabh Sengar <saurabh.truth@gmail.com> |
|---|---|
| Date | 2015-10-29 08:30 +0100 |
| Subject | [PATCH v2] um: net: replace GFP_KERNEL with GFP_ATOMIC when spinlock is held |
| Message-ID | <qoPON-5DQ-11@gated-at.bofh.it> |
replace GFP_KERNEL with GFP_ATOMIC while spinlock is held,
as code while holding a spinlock should be atomic.
GFP_KERNEL may sleep and can cause deadlock,
where as GFP_ATOMIC may fail but certainly avoids deadlock
Signed-off-by: Saurabh Sengar <saurabh.truth@gmail.com>
---
v2: correcting the subject
arch/um/drivers/net_kern.c | 31 +++++++++++++++++++++++--------
1 file changed, 23 insertions(+), 8 deletions(-)
diff --git a/arch/um/drivers/net_kern.c b/arch/um/drivers/net_kern.c
index f70dd54..7d4b709 100644
--- a/arch/um/drivers/net_kern.c
+++ b/arch/um/drivers/net_kern.c
@@ -388,16 +388,22 @@ static const struct net_device_ops uml_netdev_ops = {
static int driver_registered;
static void eth_configure(int n, void *init, char *mac,
- struct transport *transport)
+ struct transport *transport, bool atomic)
{
struct uml_net *device;
struct net_device *dev;
struct uml_net_private *lp;
int err, size;
+ int gfp_mask;
size = transport->private_size + sizeof(struct uml_net_private);
- device = kzalloc(sizeof(*device), GFP_KERNEL);
+ if (atomic)
+ gfp_mask = GFP_ATOMIC;
+ else
+ gfp_mask = GFP_KERNEL;
+
+ device = kzalloc(sizeof(*device), gfp_mask);
if (device == NULL) {
printk(KERN_ERR "eth_configure failed to allocate struct "
"uml_net\n");
@@ -568,9 +574,10 @@ static LIST_HEAD(transports);
static LIST_HEAD(eth_cmd_line);
static int check_transport(struct transport *transport, char *eth, int n,
- void **init_out, char **mac_out)
+ void **init_out, char **mac_out, bool atomic)
{
int len;
+ int gfp_mask;
len = strlen(transport->name);
if (strncmp(eth, transport->name, len))
@@ -582,7 +589,12 @@ static int check_transport(struct transport *transport, char *eth, int n,
else if (*eth != '\0')
return 0;
- *init_out = kmalloc(transport->setup_size, GFP_KERNEL);
+ if (atomic)
+ gfp_mask = GFP_ATOMIC;
+ else
+ gfp_mask = GFP_KERNEL;
+
+ *init_out = kmalloc(transport->setup_size, gfp_mask);
if (*init_out == NULL)
return 1;
@@ -600,6 +612,7 @@ void register_transport(struct transport *new)
void *init;
char *mac = NULL;
int match;
+ bool atomic = false;
spin_lock(&transports_lock);
BUG_ON(!list_empty(&new->list));
@@ -609,11 +622,11 @@ void register_transport(struct transport *new)
list_for_each_safe(ele, next, ð_cmd_line) {
eth = list_entry(ele, struct eth_init, list);
match = check_transport(new, eth->init, eth->index, &init,
- &mac);
+ &mac, atomic);
if (!match)
continue;
else if (init != NULL) {
- eth_configure(eth->index, init, mac, new);
+ eth_configure(eth->index, init, mac, new, atomic);
kfree(init);
}
list_del(ð->list);
@@ -627,14 +640,16 @@ static int eth_setup_common(char *str, int index)
void *init;
char *mac = NULL;
int found = 0;
+ bool atomic = false;
spin_lock(&transports_lock);
+ atomic = true;
list_for_each(ele, &transports) {
transport = list_entry(ele, struct transport, list);
- if (!check_transport(transport, str, index, &init, &mac))
+ if (!check_transport(transport, str, index, &init, &mac, atomic))
continue;
if (init != NULL) {
- eth_configure(index, init, mac, transport);
+ eth_configure(index, init, mac, transport, atomic);
kfree(init);
}
found = 1;
--
1.9.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | Richard Weinberger <richard@nod.at> |
|---|---|
| Date | 2015-10-29 09:50 +0100 |
| Subject | Re: [PATCH v2] um: net: replace GFP_KERNEL with GFP_ATOMIC when spinlock is held |
| Message-ID | <qoR4d-6jD-5@gated-at.bofh.it> |
| In reply to | #1258612 |
Am 29.10.2015 um 08:27 schrieb Saurabh Sengar:
> replace GFP_KERNEL with GFP_ATOMIC while spinlock is held,
> as code while holding a spinlock should be atomic.
> GFP_KERNEL may sleep and can cause deadlock,
> where as GFP_ATOMIC may fail but certainly avoids deadlock
As UML does not support SMP nor PREEMPT this is a non issue,
spinlocks are a NOP.
But for the sake of completeness you are right, the code needs
fixing.
> Signed-off-by: Saurabh Sengar <saurabh.truth@gmail.com>
> ---
> v2: correcting the subject
>
> arch/um/drivers/net_kern.c | 31 +++++++++++++++++++++++--------
> 1 file changed, 23 insertions(+), 8 deletions(-)
>
> diff --git a/arch/um/drivers/net_kern.c b/arch/um/drivers/net_kern.c
> index f70dd54..7d4b709 100644
> --- a/arch/um/drivers/net_kern.c
> +++ b/arch/um/drivers/net_kern.c
> @@ -388,16 +388,22 @@ static const struct net_device_ops uml_netdev_ops = {
> static int driver_registered;
>
> static void eth_configure(int n, void *init, char *mac,
> - struct transport *transport)
> + struct transport *transport, bool atomic)
Why do you need this atomic variable? Can't you just pass gfp_mask around?
Thanks,
//richard
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web