On Thu, May 6, 2021 at 3:56 PM Sergey Bugaev <[email protected]> wrote:
> - newaddr = mmap (0, newsize * sizeof (*p->pagemap),
> - PROT_READ|PROT_WRITE, MAP_ANON, 0, 0);
> + void *newaddr = reallocarray (p->pagemap, off,
> + sizeof (*p->pagemap));
It seems while fixing preexisting issues I accidentally introduces a
new one. Unlike mmap, reallocarray does not zero-initialize the newly
allocated memory; but other code expects new pagemap entries to be set
to zero. This is the cause of those tarfs hangs I've been seeing
lately.
I'm sorry, and here's a hotfix.
Sergey
-- >8 --
Subject: [PATCH] libpager: Properly zero-initialize pagemap
Unlike mmap () and calloc (), reallocarray () does not automatically
zero-fill the newly allocated memory. Do so explicitly.
---
libpager/pagemap.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/libpager/pagemap.c b/libpager/pagemap.c
index 7bbb8c56..c7c86d60 100644
--- a/libpager/pagemap.c
+++ b/libpager/pagemap.c
@@ -32,6 +32,8 @@ _pager_pagemap_resize (struct pager *p, vm_address_t off)
if (!newaddr)
return errno;
+ memset ((short *) newaddr + p->pagemapsize, 0,
+ (off - p->pagemapsize) * sizeof (*p->pagemap));
p->pagemap = newaddr;
p->pagemapsize = off;
}
--
2.31.1