From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,HK_RANDOM_FROM, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7CF8C433E0 for ; Mon, 15 Mar 2021 13:54:22 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3E7D564EEC for ; Mon, 15 Mar 2021 13:54:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3E7D564EEC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bu.edu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:58870 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lLnfo-0002dT-0d for qemu-devel@archiver.kernel.org; Mon, 15 Mar 2021 09:54:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44086) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLneo-0001kg-TM for qemu-devel@nongnu.org; Mon, 15 Mar 2021 09:53:18 -0400 Received: from relay68.bu.edu ([128.197.228.73]:37360) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lLnej-0002eI-K7 for qemu-devel@nongnu.org; Mon, 15 Mar 2021 09:53:17 -0400 X-Envelope-From: alxndr@bu.edu X-BU-AUTH: mozz.bu.edu [128.197.127.33] Received: from BU-AUTH (localhost.localdomain [127.0.0.1]) (authenticated bits=0) by relay68.bu.edu (8.14.3/8.14.3) with ESMTP id 12FDqLbi016117 (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256 verify=NO); Mon, 15 Mar 2021 09:52:24 -0400 Date: Mon, 15 Mar 2021 09:52:21 -0400 From: Alexander Bulekov To: Darren Kenny Subject: Re: [PATCH v2 1/3] memory: add a sparse memory device for fuzzing Message-ID: <20210315135221.cpp6bt2v62y7y26w@mozz.bu.edu> References: <20210313231859.941263-1-alxndr@bu.edu> <20210313231859.941263-2-alxndr@bu.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=128.197.228.73; envelope-from=alxndr@bu.edu; helo=relay68.bu.edu X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, HK_RANDOM_ENVFROM=0.001, HK_RANDOM_FROM=1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Huth , "Michael S. Tsirkin" , qemu-devel@nongnu.org, f4bug@amsat.org, bsd@redhat.com, stefanha@redhat.com, Igor Mammedov , pbonzini@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On 210315 1209, Darren Kenny wrote: > Hi Alex, > > On Saturday, 2021-03-13 at 18:18:57 -05, Alexander Bulekov wrote: > > For testing, it can be useful to simulate an enormous amount of memory > > (e.g. 2^64 RAM). This adds an MMIO device that acts as sparse memory. > > When something writes a nonzero value to a sparse-mem address, we > > allocate a block of memory. This block is kept around, until all of the > > bytes within the block are zero-ed. The device has a very low priority > > I don't see code below that actually checks if a block is zero-ed and > removes it from the hash table, so is this comment correct? No.. I will update it > > > (so it can be mapped beneath actual RAM, and virtual device MMIO > > regions). > > > > Signed-off-by: Alexander Bulekov > > --- > > MAINTAINERS | 1 + > > hw/mem/meson.build | 1 + > > hw/mem/sparse-mem.c | 152 ++++++++++++++++++++++++++++++++++++ > > include/hw/mem/sparse-mem.h | 19 +++++ > > 4 files changed, 173 insertions(+) > > create mode 100644 hw/mem/sparse-mem.c > > create mode 100644 include/hw/mem/sparse-mem.h > > > > diff --git a/MAINTAINERS b/MAINTAINERS > > index f22d83c178..9e3d8b1401 100644 > > --- a/MAINTAINERS > > +++ b/MAINTAINERS > > @@ -2618,6 +2618,7 @@ R: Thomas Huth > > S: Maintained > > F: tests/qtest/fuzz/ > > F: scripts/oss-fuzz/ > > +F: hw/mem/sparse-mem.c > > F: docs/devel/fuzzing.rst > > > > Register API > > diff --git a/hw/mem/meson.build b/hw/mem/meson.build > > index 0d22f2b572..ef79e04678 100644 > > --- a/hw/mem/meson.build > > +++ b/hw/mem/meson.build > > @@ -1,5 +1,6 @@ > > mem_ss = ss.source_set() > > mem_ss.add(files('memory-device.c')) > > +mem_ss.add(when: 'CONFIG_FUZZ', if_true: files('sparse-mem.c')) > > mem_ss.add(when: 'CONFIG_DIMM', if_true: files('pc-dimm.c')) > > mem_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_mc.c')) > > mem_ss.add(when: 'CONFIG_NVDIMM', if_true: files('nvdimm.c')) > > diff --git a/hw/mem/sparse-mem.c b/hw/mem/sparse-mem.c > > new file mode 100644 > > index 0000000000..575a287f59 > > --- /dev/null > > +++ b/hw/mem/sparse-mem.c > > @@ -0,0 +1,152 @@ > > +/* > > + * A sparse memory device. Useful for fuzzing > > + * > > + * Copyright Red Hat Inc., 2021 > > + * > > + * Authors: > > + * Alexander Bulekov > > + * > > + * This work is licensed under the terms of the GNU GPL, version 2 or later. > > + * See the COPYING file in the top-level directory. > > + */ > > + > > +#include "qemu/osdep.h" > > + > > +#include "exec/address-spaces.h" > > +#include "hw/qdev-properties.h" > > +#include "hw/sysbus.h" > > +#include "qapi/error.h" > > +#include "qemu/units.h" > > +#include "sysemu/qtest.h" > > +#include "hw/mem/sparse-mem.h" > > + > > +#define SPARSE_MEM(obj) OBJECT_CHECK(SparseMemState, (obj), TYPE_SPARSE_MEM) > > +#define SPARSE_BLOCK_SIZE 0x1000 > > This is assuming a 4K block size, should that be the same as the system > pagesize is? Or will it not matter w.r.t. how this is being consumed? > It shouldn't make a difference, as long as it is a multiple of the MMIO region's alignment size. > > + > > +typedef struct SparseMemState { > > + SysBusDevice parent_obj; > > + MemoryRegion mmio; > > + uint64_t baseaddr; > > + uint64_t length; > > + uint64_t size_used; > > + uint64_t maxsize; > > + GHashTable *mapped; > > +} SparseMemState; > > + > > +typedef struct sparse_mem_block { > > + uint8_t data[SPARSE_BLOCK_SIZE]; > > +} sparse_mem_block; > > + > > +static uint64_t sparse_mem_read(void *opaque, hwaddr addr, unsigned int size) > > +{ > > + printf("SPARSEREAD %lx\n", addr); > > Should this printf() be a logging/trace call? Or do you really want it to be > printed all the time? Also seems out of place before the declaration of > the variables. No. I will remove it > > Thanks, > > Darren.