diff mbox series

[01/10] hw/sparse-mem: clear memory on reset

Message ID 20230205042951.3570008-2-alxndr@bu.edu (mailing list archive)
State New, archived
Headers show
Series Retire Fork-Based Fuzzing | expand

Commit Message

Alexander Bulekov Feb. 5, 2023, 4:29 a.m. UTC
We use sparse-mem for fuzzing. For long-running fuzzing processes, we
eventually end up with many allocated sparse-mem pages. To avoid this,
clear the allocated pages on system-reset.

Signed-off-by: Alexander Bulekov <alxndr@bu.edu>
---
 hw/mem/sparse-mem.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

Comments

Philippe Mathieu-Daudé Feb. 5, 2023, 10:40 a.m. UTC | #1
On 5/2/23 05:29, Alexander Bulekov wrote:
> We use sparse-mem for fuzzing. For long-running fuzzing processes, we
> eventually end up with many allocated sparse-mem pages. To avoid this,
> clear the allocated pages on system-reset.
> 
> Signed-off-by: Alexander Bulekov <alxndr@bu.edu>
> ---
>   hw/mem/sparse-mem.c | 13 ++++++++++++-
>   1 file changed, 12 insertions(+), 1 deletion(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Darren Kenny Feb. 13, 2023, 2:15 p.m. UTC | #2
On Sunday, 2023-02-05 at 11:40:55 +01, Philippe Mathieu-Daudé wrote:
> On 5/2/23 05:29, Alexander Bulekov wrote:
>> We use sparse-mem for fuzzing. For long-running fuzzing processes, we
>> eventually end up with many allocated sparse-mem pages. To avoid this,
>> clear the allocated pages on system-reset.
>> 
>> Signed-off-by: Alexander Bulekov <alxndr@bu.edu>
>> ---
>>   hw/mem/sparse-mem.c | 13 ++++++++++++-
>>   1 file changed, 12 insertions(+), 1 deletion(-)
>
> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Reviewed-by: Darren Kenny <darren.kenny@oracle.com>

Thanks,

Darren.
diff mbox series

Patch

diff --git a/hw/mem/sparse-mem.c b/hw/mem/sparse-mem.c
index e6640eb8e7..72f038d47d 100644
--- a/hw/mem/sparse-mem.c
+++ b/hw/mem/sparse-mem.c
@@ -77,6 +77,13 @@  static void sparse_mem_write(void *opaque, hwaddr addr, uint64_t v,
 
 }
 
+static void sparse_mem_enter_reset(Object *obj, ResetType type)
+{
+    SparseMemState *s = SPARSE_MEM(obj);
+    g_hash_table_remove_all(s->mapped);
+    return;
+}
+
 static const MemoryRegionOps sparse_mem_ops = {
     .read = sparse_mem_read,
     .write = sparse_mem_write,
@@ -123,7 +130,8 @@  static void sparse_mem_realize(DeviceState *dev, Error **errp)
 
     assert(s->baseaddr + s->length > s->baseaddr);
 
-    s->mapped = g_hash_table_new(NULL, NULL);
+    s->mapped = g_hash_table_new_full(NULL, NULL, NULL,
+                                      (GDestroyNotify)g_free);
     memory_region_init_io(&s->mmio, OBJECT(s), &sparse_mem_ops, s,
                           "sparse-mem", s->length);
     sysbus_init_mmio(sbd, &s->mmio);
@@ -131,12 +139,15 @@  static void sparse_mem_realize(DeviceState *dev, Error **errp)
 
 static void sparse_mem_class_init(ObjectClass *klass, void *data)
 {
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
 
     device_class_set_props(dc, sparse_mem_properties);
 
     dc->desc = "Sparse Memory Device";
     dc->realize = sparse_mem_realize;
+
+    rc->phases.enter = sparse_mem_enter_reset;
 }
 
 static const TypeInfo sparse_mem_types[] = {