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=-7.8 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 9900FC07E96 for ; Thu, 8 Jul 2021 12:03:26 +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 F39C46146E for ; Thu, 8 Jul 2021 12:03:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F39C46146E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:52750 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m1SkW-0002hU-76 for qemu-devel@archiver.kernel.org; Thu, 08 Jul 2021 08:03:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54604) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1Sih-0000h1-F0 for qemu-devel@nongnu.org; Thu, 08 Jul 2021 08:01:34 -0400 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]:34323) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m1Sif-0003rz-GX for qemu-devel@nongnu.org; Thu, 08 Jul 2021 08:01:31 -0400 Received: by mail-ej1-x634.google.com with SMTP id hr1so9199403ejc.1 for ; Thu, 08 Jul 2021 05:01:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=HVGcFNKQ/QamG8kWYFUwsfWKyMVDXAQQ5DmGd//lFQk=; b=bfNy3RbYIz0xuTnF0ps5UgmtmivQs67DPiuzEdRntcvi2hJhDcZqx0YZGNUgDjXpaR GZh1aNh60IHwut9T8IHpySCXLE0noG/LplaU8grkmoSq/YruqV/dOSCb63EKFQ8b/HFy fOQnYBwJQVtuqENUrH2MPut1uFvToHp0cnach2aamJ9jMaR85kMVawBRARzW8/4j7dm9 G4zga2+mx746qblhTWDAsF7V6b1tLHB+phrIYs/m/fcsgg2vZkk8rudx8pA/xOIsMv5o 36EsqclaJsyrLLjVt5jgaZ+2orYYFzKcox8cBFghR3syCZtn8oMwIFsu6OotHYuKglkm Y1rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=HVGcFNKQ/QamG8kWYFUwsfWKyMVDXAQQ5DmGd//lFQk=; b=mbjtPP0DGIvTActF/o+XHR147Mu4livKPKDWVuLjp9qnJpbKXREAEmZbTQiZ37hYJz 0a7yPaUTCxQBcZ1S8bpFEsnehIFfwJPqJmJPGMUYLzuVImA/MtZ8xTS00cQGTSUwP3d4 IYViYnWWYPsIZ9gDi3gODPsIm7jIEd3BIdKtDr2ncWrQgA/9T/pDAcmqTkSJk+0wnse7 rO0pX4g2CCqWzSSJsg6mFPQHCGNvAOImnarn/FkHgYMXMUnGdfpob0w+IqpAC9Qe7QGO daYz7V8KemHsNnFsBcTV+EVz0OeNjNJWNW3r0OXOCJCzMDntFCRijZJdKhanu1FB72Qs k5hw== X-Gm-Message-State: AOAM533fnMyNiD4Xe19MyZZ6Rxla5KxUz2U8zLHhUSjn+zkgPNq/YDmH a0nVeZjjAnKWtd5JA9+L6l5piQta0WW6XMdCRgM= X-Google-Smtp-Source: ABdhPJx5E7fBBDDYnrgENeK6H5SGiBfXjOVs6BFUexfbZQlwRSelfFyW1VucOSY5h22BXJTHew3lEOCgIgaVYdeLWE8= X-Received: by 2002:a17:907:ea5:: with SMTP id ho37mr30431251ejc.109.1625745686992; Thu, 08 Jul 2021 05:01:26 -0700 (PDT) MIME-Version: 1.0 References: <1625678434-240960-1-git-send-email-steven.sistare@oracle.com> <1625678434-240960-2-git-send-email-steven.sistare@oracle.com> In-Reply-To: <1625678434-240960-2-git-send-email-steven.sistare@oracle.com> From: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= Date: Thu, 8 Jul 2021 16:01:15 +0400 Message-ID: Subject: Re: [PATCH V5 01/25] qemu_ram_volatile To: Steve Sistare Content-Type: multipart/alternative; boundary="0000000000002b1be505c69b6a5d" Received-SPF: pass client-ip=2a00:1450:4864:20::634; envelope-from=marcandre.lureau@gmail.com; helo=mail-ej1-x634.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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: Jason Zeng , Juan Quintela , Eric Blake , "Michael S. Tsirkin" , QEMU , "Dr. David Alan Gilbert" , Alex Williamson , Stefan Hajnoczi , Paolo Bonzini , "Daniel P. Berrange" , =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= , =?UTF-8?B?QWxleCBCZW5uw6ll?= , Markus Armbruster Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" --0000000000002b1be505c69b6a5d Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi On Wed, Jul 7, 2021 at 9:35 PM Steve Sistare wrote: > Add a function that returns true if any ram_list block represents > volatile memory. > > Signed-off-by: Steve Sistare > --- > include/exec/memory.h | 8 ++++++++ > softmmu/memory.c | 30 ++++++++++++++++++++++++++++++ > 2 files changed, 38 insertions(+) > > diff --git a/include/exec/memory.h b/include/exec/memory.h > index b116f7c..7ad63f8 100644 > --- a/include/exec/memory.h > +++ b/include/exec/memory.h > @@ -2649,6 +2649,14 @@ bool ram_block_discard_is_disabled(void); > */ > bool ram_block_discard_is_required(void); > > +/** > + * qemu_ram_volatile: return true if any memory regions are writable and > not > + * backed by shared memory. > + * > + * @errp: returned error message identifying the bad region. > + */ > +bool qemu_ram_volatile(Error **errp); > Usually, bool-value functions with an error return true on success. If it deviates from the recommendation, it should at least be documented. Also, we have a preference for using _is_ in the function name for such tests. + > #endif > > #endif > diff --git a/softmmu/memory.c b/softmmu/memory.c > index f016151..e9536bc 100644 > --- a/softmmu/memory.c > +++ b/softmmu/memory.c > @@ -2714,6 +2714,36 @@ void memory_global_dirty_log_stop(void) > memory_global_dirty_log_do_stop(); > } > > +/* > + * Return true if any memory regions are writable and not backed by shar= ed > + * memory. > + */ > Let's not duplicate API comments. +bool qemu_ram_volatile(Error **errp) > +{ > + RAMBlock *block; > + MemoryRegion *mr; > + bool ret =3D false; > + > + rcu_read_lock(); > RCU_READ_LOCK_GUARD() > + QLIST_FOREACH_RCU(block, &ram_list.blocks, next) { > RAMBLOCK_FOREACH() should do. Or rather use the qemu_ram_foreach_block() helper. + mr =3D block->mr; > + if (mr && > + memory_region_is_ram(mr) && > + !memory_region_is_ram_device(mr) && > + !memory_region_is_rom(mr) && > + (block->fd =3D=3D -1 || !qemu_ram_is_shared(block))) { > + > + error_setg(errp, "Memory region %s is volatile", > + memory_region_name(mr)); > + ret =3D true; > + break; > + } > + } > + > + rcu_read_unlock(); > + return ret; > +} > + > static void listener_add_address_space(MemoryListener *listener, > AddressSpace *as) > { > -- > 1.8.3.1 > > > --=20 Marc-Andr=C3=A9 Lureau --0000000000002b1be505c69b6a5d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi

On Wed, Jul 7, 2021 at 9:35 PM Stev= e Sistare <steven.sistare@o= racle.com> wrote:
Add a function that returns true if any ram_list block represent= s
volatile memory.

Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
=C2=A0include/exec/memory.h |=C2=A0 8 ++++++++
=C2=A0softmmu/memory.c=C2=A0 =C2=A0 =C2=A0 | 30 +++++++++++++++++++++++++++= +++
=C2=A02 files changed, 38 insertions(+)

diff --git a/include/exec/memory.h b/include/exec/memory.h
index b116f7c..7ad63f8 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -2649,6 +2649,14 @@ bool ram_block_discard_is_disabled(void);
=C2=A0 */
=C2=A0bool ram_block_discard_is_required(void);

+/**
+ * qemu_ram_volatile: return true if any memory regions are writable and n= ot
+ * backed by shared memory.
+ *
+ * @errp: returned error message identifying the bad region.
+ */
+bool qemu_ram_volatile(Error **errp);

= Usually, bool-value functions with an error return true on success. If it d= eviates from the recommendation, it should at least be documented.

Also, we have a preference for using _is_ in the funct= ion name for such tests.

+
=C2=A0#endif

=C2=A0#endif
diff --git a/softmmu/memory.c b/softmmu/memory.c
index f016151..e9536bc 100644
--- a/softmmu/memory.c
+++ b/softmmu/memory.c
@@ -2714,6 +2714,36 @@ void memory_global_dirty_log_stop(void)
=C2=A0 =C2=A0 =C2=A0memory_global_dirty_log_do_stop();
=C2=A0}

+/*
+ * Return true if any memory regions are writable and not backed by shared=
+ * memory.
+ */

Let's not duplicate API commen= ts.

+bool qemu_ram_volatile(Error **errp)
+{
+=C2=A0 =C2=A0 RAMBlock *block;
+=C2=A0 =C2=A0 MemoryRegion *mr;
+=C2=A0 =C2=A0 bool ret =3D false;
+
+=C2=A0 =C2=A0 rcu_read_lock();

RCU_READ_LOCK_GUARD()
=C2=A0=
+=C2=A0 =C2=A0 QLIS= T_FOREACH_RCU(block, &ram_list.blocks, next) {
RAMBLOCK_FOREACH() should do.

Or r= ather use the qemu_ram_foreach_block() helper.


+=C2=A0 =C2=A0 =C2=A0 =C2=A0 mr =3D block->mr;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (mr &&
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 memory_region_is_ram(mr) &&a= mp;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 !memory_region_is_ram_device(mr)= &&
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 !memory_region_is_rom(mr) &&= amp;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (block->fd =3D=3D -1 || !qemu= _ram_is_shared(block))) {
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 error_setg(errp, "Memory re= gion %s is volatile",
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0memory_region_name(mr));
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ret =3D true;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 break;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+=C2=A0 =C2=A0 }
+
+=C2=A0 =C2=A0 rcu_read_unlock();
+=C2=A0 =C2=A0 return ret;
+}
+
=C2=A0static void listener_add_address_space(MemoryListener *listener,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 AddressS= pace *as)
=C2=A0{
--
1.8.3.1




--
Marc-Andr=C3=A9 Lureau
--0000000000002b1be505c69b6a5d--