* [PATCH bpf-next 0/2] fixes for bpf_prog_pack
@ 2022-03-21 18:00 Song Liu
2022-03-21 18:00 ` [PATCH bpf-next 1/2] bpf: fix bpf_prog_pack for multi-node setup Song Liu
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Song Liu @ 2022-03-21 18:00 UTC (permalink / raw)
To: bpf, netdev; +Cc: ast, daniel, andrii, kernel-team, Song Liu
Two fixes for issues reported by syzbot and kernel test robot.
Song Liu (2):
bpf: fix bpf_prog_pack for multi-node setup
bpf: fix bpf_prog_pack when PMU_SIZE is not defined
kernel/bpf/core.c | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
--
2.30.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH bpf-next 1/2] bpf: fix bpf_prog_pack for multi-node setup
2022-03-21 18:00 [PATCH bpf-next 0/2] fixes for bpf_prog_pack Song Liu
@ 2022-03-21 18:00 ` Song Liu
2022-03-21 18:00 ` [PATCH bpf-next 2/2] bpf: fix bpf_prog_pack when PMU_SIZE is not defined Song Liu
2022-03-21 21:00 ` [PATCH bpf-next 0/2] fixes for bpf_prog_pack patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Song Liu @ 2022-03-21 18:00 UTC (permalink / raw)
To: bpf, netdev
Cc: ast, daniel, andrii, kernel-team, Song Liu, syzbot+c946805b5ce6ab87df0b
module_alloc requires num_online_nodes * PMD_SIZE to allocate huge pages.
bpf_prog_pack uses pack of size num_online_nodes * PMD_SIZE.
OTOH, module_alloc returns addresses that are PMD_SIZE aligned (instead of
num_online_nodes * PMD_SIZE aligned). Therefore, PMD_MASK should be used
to calculate pack_ptr in bpf_prog_pack_free().
Fixes: ef078600eec2 ("bpf: Select proper size for bpf_prog_pack")
Reported-by: syzbot+c946805b5ce6ab87df0b@syzkaller.appspotmail.com
Signed-off-by: Song Liu <song@kernel.org>
---
kernel/bpf/core.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 9d661e07e77c..f6b20fcbeb24 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -829,6 +829,7 @@ struct bpf_prog_pack {
#define BPF_PROG_SIZE_TO_NBITS(size) (round_up(size, BPF_PROG_CHUNK_SIZE) / BPF_PROG_CHUNK_SIZE)
static size_t bpf_prog_pack_size = -1;
+static size_t bpf_prog_pack_mask = -1;
static int bpf_prog_chunk_count(void)
{
@@ -850,8 +851,12 @@ static size_t select_bpf_prog_pack_size(void)
/* Test whether we can get huge pages. If not just use PAGE_SIZE
* packs.
*/
- if (!ptr || !is_vm_area_hugepages(ptr))
+ if (!ptr || !is_vm_area_hugepages(ptr)) {
size = PAGE_SIZE;
+ bpf_prog_pack_mask = PAGE_MASK;
+ } else {
+ bpf_prog_pack_mask = PMD_MASK;
+ }
vfree(ptr);
return size;
@@ -935,7 +940,7 @@ static void bpf_prog_pack_free(struct bpf_binary_header *hdr)
goto out;
}
- pack_ptr = (void *)((unsigned long)hdr & ~(bpf_prog_pack_size - 1));
+ pack_ptr = (void *)((unsigned long)hdr & bpf_prog_pack_mask);
list_for_each_entry(tmp, &pack_list, list) {
if (tmp->ptr == pack_ptr) {
--
2.30.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH bpf-next 2/2] bpf: fix bpf_prog_pack when PMU_SIZE is not defined
2022-03-21 18:00 [PATCH bpf-next 0/2] fixes for bpf_prog_pack Song Liu
2022-03-21 18:00 ` [PATCH bpf-next 1/2] bpf: fix bpf_prog_pack for multi-node setup Song Liu
@ 2022-03-21 18:00 ` Song Liu
2022-03-21 21:00 ` [PATCH bpf-next 0/2] fixes for bpf_prog_pack patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Song Liu @ 2022-03-21 18:00 UTC (permalink / raw)
To: bpf, netdev; +Cc: ast, daniel, andrii, kernel-team, Song Liu, kernel test robot
PMD_SIZE is not available in some special config, e.g. ARCH=arm with
CONFIG_MMU=n. Use bpf_prog_pack of PAGE_SIZE in these cases.
Fixes: ef078600eec2 ("bpf: Select proper size for bpf_prog_pack")
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Song Liu <song@kernel.org>
---
kernel/bpf/core.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index f6b20fcbeb24..13e9dbeeedf3 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -840,12 +840,23 @@ static int bpf_prog_chunk_count(void)
static DEFINE_MUTEX(pack_mutex);
static LIST_HEAD(pack_list);
+/* PMD_SIZE is not available in some special config, e.g. ARCH=arm with
+ * CONFIG_MMU=n. Use PAGE_SIZE in these cases.
+ */
+#ifdef PMD_SIZE
+#define BPF_HPAGE_SIZE PMD_SIZE
+#define BPF_HPAGE_MASK PMD_MASK
+#else
+#define BPF_HPAGE_SIZE PAGE_SIZE
+#define BPF_HPAGE_MASK PAGE_MASK
+#endif
+
static size_t select_bpf_prog_pack_size(void)
{
size_t size;
void *ptr;
- size = PMD_SIZE * num_online_nodes();
+ size = BPF_HPAGE_SIZE * num_online_nodes();
ptr = module_alloc(size);
/* Test whether we can get huge pages. If not just use PAGE_SIZE
@@ -855,7 +866,7 @@ static size_t select_bpf_prog_pack_size(void)
size = PAGE_SIZE;
bpf_prog_pack_mask = PAGE_MASK;
} else {
- bpf_prog_pack_mask = PMD_MASK;
+ bpf_prog_pack_mask = BPF_HPAGE_MASK;
}
vfree(ptr);
--
2.30.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH bpf-next 0/2] fixes for bpf_prog_pack
2022-03-21 18:00 [PATCH bpf-next 0/2] fixes for bpf_prog_pack Song Liu
2022-03-21 18:00 ` [PATCH bpf-next 1/2] bpf: fix bpf_prog_pack for multi-node setup Song Liu
2022-03-21 18:00 ` [PATCH bpf-next 2/2] bpf: fix bpf_prog_pack when PMU_SIZE is not defined Song Liu
@ 2022-03-21 21:00 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-03-21 21:00 UTC (permalink / raw)
To: Song Liu; +Cc: bpf, netdev, ast, daniel, andrii, kernel-team
Hello:
This series was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:
On Mon, 21 Mar 2022 11:00:07 -0700 you wrote:
> Two fixes for issues reported by syzbot and kernel test robot.
>
> Song Liu (2):
> bpf: fix bpf_prog_pack for multi-node setup
> bpf: fix bpf_prog_pack when PMU_SIZE is not defined
>
> kernel/bpf/core.c | 22 +++++++++++++++++++---
> 1 file changed, 19 insertions(+), 3 deletions(-)
>
> [...]
Here is the summary with links:
- [bpf-next,1/2] bpf: fix bpf_prog_pack for multi-node setup
https://git.kernel.org/bpf/bpf-next/c/96805674e562
- [bpf-next,2/2] bpf: fix bpf_prog_pack when PMU_SIZE is not defined
https://git.kernel.org/bpf/bpf-next/c/e581094167be
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-03-21 21:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-21 18:00 [PATCH bpf-next 0/2] fixes for bpf_prog_pack Song Liu
2022-03-21 18:00 ` [PATCH bpf-next 1/2] bpf: fix bpf_prog_pack for multi-node setup Song Liu
2022-03-21 18:00 ` [PATCH bpf-next 2/2] bpf: fix bpf_prog_pack when PMU_SIZE is not defined Song Liu
2022-03-21 21:00 ` [PATCH bpf-next 0/2] fixes for bpf_prog_pack patchwork-bot+netdevbpf
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).