From: anton.ivanov@cambridgegreys.com
To: linux-um@lists.infradead.org
Cc: richard@nod.at, dan.carpenter@oracle.com, weiyongjun1@huawei.com,
kernel-janitors@vger.kernel.org, songliubraving@fb.com,
daniel@iogearbox.net, ast@kernel.org, netdev@vger.kernel.org,
bpf@vger.kernel.org, kafai@fb.com,
Anton Ivanov <anton.ivanov@cambridgegreys.com>
Subject: [PATCH] um: vector: fix BPF loading in vector drivers
Date: Thu, 28 Nov 2019 17:44:05 +0000 [thread overview]
Message-ID: <20191128174405.4244-1-anton.ivanov@cambridgegreys.com> (raw)
From: Anton Ivanov <anton.ivanov@cambridgegreys.com>
This fixes a possible hang in bpf firmware loading in the
UML vector io drivers due to use of GFP_KERNEL while holding
a spinlock.
Based on a prposed fix by weiyongjun1@huawei.com and suggestions for
improving it by dan.carpenter@oracle.com
Signed-off-by: Anton Ivanov <anton.ivanov@cambridgegreys.com>
---
arch/um/drivers/vector_kern.c | 38 ++++++++++++++++++-----------------
1 file changed, 20 insertions(+), 18 deletions(-)
diff --git a/arch/um/drivers/vector_kern.c b/arch/um/drivers/vector_kern.c
index 92617e16829e..dbbc6e850fdd 100644
--- a/arch/um/drivers/vector_kern.c
+++ b/arch/um/drivers/vector_kern.c
@@ -1387,6 +1387,7 @@ static int vector_net_load_bpf_flash(struct net_device *dev,
struct vector_private *vp = netdev_priv(dev);
struct vector_device *vdevice;
const struct firmware *fw;
+ void *new_filter;
int result = 0;
if (!(vp->options & VECTOR_BPF_FLASH)) {
@@ -1394,6 +1395,15 @@ static int vector_net_load_bpf_flash(struct net_device *dev,
return -1;
}
+ vdevice = find_device(vp->unit);
+
+ if (request_firmware(&fw, efl->data, &vdevice->pdev.dev))
+ return -1;
+
+ new_filter = kmemdup(fw->data, fw->size, GFP_KERNEL);
+ if (!new_filter)
+ goto free_buffer;
+
spin_lock(&vp->lock);
if (vp->bpf != NULL) {
@@ -1402,41 +1412,33 @@ 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;
+ goto apply_flash_fail;
}
}
- vdevice = find_device(vp->unit);
-
- if (request_firmware(&fw, efl->data, &vdevice->pdev.dev))
- goto flash_fail;
-
- vp->bpf->filter = kmemdup(fw->data, fw->size, GFP_KERNEL);
- if (!vp->bpf->filter)
- goto free_buffer;
-
+ vp->bpf->filter = new_filter;
vp->bpf->len = fw->size / sizeof(struct sock_filter);
- release_firmware(fw);
if (vp->opened)
result = uml_vector_attach_bpf(vp->fds->rx_fd, vp->bpf);
spin_unlock(&vp->lock);
- return result;
-
-free_buffer:
release_firmware(fw);
-flash_fail:
+ return result;
+
+apply_flash_fail:
spin_unlock(&vp->lock);
- if (vp->bpf != NULL)
+ if (vp->bpf)
kfree(vp->bpf->filter);
kfree(vp->bpf);
- vp->bpf = NULL;
+
+free_buffer:
+ release_firmware(fw);
return -1;
}
--
2.20.1
next reply other threads:[~2019-11-28 17:44 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-28 17:44 anton.ivanov [this message]
2019-11-29 9:15 ` [PATCH] um: vector: fix BPF loading in vector drivers Daniel Borkmann
2019-11-29 11:54 ` Anton Ivanov
2019-11-29 23:12 ` Daniel Borkmann
2019-11-30 7:29 ` Anton Ivanov
2019-12-02 9:33 ` Anton Ivanov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191128174405.4244-1-anton.ivanov@cambridgegreys.com \
--to=anton.ivanov@cambridgegreys.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=dan.carpenter@oracle.com \
--cc=daniel@iogearbox.net \
--cc=kafai@fb.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-um@lists.infradead.org \
--cc=netdev@vger.kernel.org \
--cc=richard@nod.at \
--cc=songliubraving@fb.com \
--cc=weiyongjun1@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).