From nobody Thu Nov 6 12:12:22 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1540929500828751.1351992466826; Tue, 30 Oct 2018 12:58:20 -0700 (PDT) Received: from localhost ([::1]:55246 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHa9b-0006cJ-S1 for importer@patchew.org; Tue, 30 Oct 2018 15:58:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48221) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHa28-00082O-VP for qemu-devel@nongnu.org; Tue, 30 Oct 2018 15:50:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHa26-0002IZ-AC for qemu-devel@nongnu.org; Tue, 30 Oct 2018 15:50:36 -0400 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:53799) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gHa26-0002GJ-0j for qemu-devel@nongnu.org; Tue, 30 Oct 2018 15:50:34 -0400 Received: by mail-wm1-x343.google.com with SMTP id v24-v6so3155240wmh.3 for ; Tue, 30 Oct 2018 12:50:31 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id g76-v6sm17480094wmd.25.2018.10.30.12.50.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Oct 2018 12:50:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Gc1z+R5p9nu4b50hsOyd0BA3dM1YQdCwZMOFJPDkMmA=; b=gGk1DRfYltTz8Y/9H5x5jCVzDWxgZXWJGIQQt3jru3IKTa6Lti3l8YBe5s6YDQCVb4 GlG8cZqzTFAo655LjdP40zMrN0qgXDmxTfyE6fIj9nMUPmEoErhbx9WEviBxBvVV39kL Qu3O7qK1dz2XJxXZZIuLFawfvLEkMCrxiVjEo6jHVHOzP0XtdylGb2MGBLWLzhQgavNT Bq1CHYduVsqfa0jlXDQUqv42VdaTjIa0CBKAdZfig7pY0SKAQbmIjwpoMg5TNAMrFF1h dtsi2+Pj8cSOPIykag4uPVACUExQ+FBP31nqatsoWwEMmwAudgrc7YtMWjq5/EZxyaQW xFsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=Gc1z+R5p9nu4b50hsOyd0BA3dM1YQdCwZMOFJPDkMmA=; b=L3bggHgISO/XrbAGrS4FyI5YmMQ63TOmWQ4SX0pQipZKShhJbXZ4tKKd4kOMs79E43 JMWMjnMSbJxC6flqbHajc7mk8YqYJkPCJRQ1YxnLlVe3m0Ifzl4sjwHSbf+UOjZ75563 USqvS6LEpLs2D04JbmQKhCMbehofDYCebw/GLfiqGHoFnGOFp0IgSHCUnC9wMxKMjBtB hl72MjzurjmokYqYwjiHLzJ96/r8LlaLr8A2E6U+0OXbNdqLGNjM6lUtNr9w/LbHmfFm yPVtR+wcPGkEnizK/UjHFEwsZ/JtCZogA4WCKyF7dwFuP6uHKBFxzBYvAX9c4oUBpmKB IOZw== X-Gm-Message-State: AGRZ1gI5zniJTiKz+4yB7kKzb0lsEgKpX5UOlgDa5yqPmW2GA4LKXg+6 z68Ch/4fYF1H2KwCodIVcp6iGcDt X-Google-Smtp-Source: AJdET5eJD6/NvVi7zjcdjk2htjLB6roEzrcwq05sKJ6WueHquSUjsIv/YN4AZZUR6gleDBqDvdyvpw== X-Received: by 2002:a1c:b7c4:: with SMTP id h187-v6mr75845wmf.70.1540929029981; Tue, 30 Oct 2018 12:50:29 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 30 Oct 2018 20:50:07 +0100 Message-Id: <1540929011-19894-7-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1540929011-19894-1-git-send-email-pbonzini@redhat.com> References: <1540929011-19894-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::343 Subject: [Qemu-devel] [PULL 06/10] memory: learn about non-volatile memory region X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: guangrong.xiao@linux.intel.com, xiaoguangrong.eric@gmail.com, mst@redhat.com, dgilbert@redhat.com, imammedo@redhat.com, pbonzini@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Marc-Andr=C3=A9 Lureau Add a new flag to mark memory region that are used as non-volatile, by NVDIMM for example. That bit is propagated down to the flat view, and reflected in HMP info mtree with a "nv-" prefix on the memory type. This way, guest_phys_blocks_region_add() can skip the NV memory regions for dumps and TCG memory clear in a following patch. Cc: dgilbert@redhat.com Cc: imammedo@redhat.com Cc: pbonzini@redhat.com Cc: guangrong.xiao@linux.intel.com Cc: mst@redhat.com Cc: xiaoguangrong.eric@gmail.com Signed-off-by: Marc-Andr=C3=A9 Lureau Message-Id: <20181003114454.5662-2-marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini --- docs/devel/migration.rst | 1 + include/exec/memory.h | 25 +++++++++++++++++++++++++ memory.c | 45 +++++++++++++++++++++++++++++++++++---------- 3 files changed, 61 insertions(+), 10 deletions(-) diff --git a/docs/devel/migration.rst b/docs/devel/migration.rst index 6875707..e7658ab 100644 --- a/docs/devel/migration.rst +++ b/docs/devel/migration.rst @@ -435,6 +435,7 @@ Examples of such memory API functions are: - memory_region_add_subregion() - memory_region_del_subregion() - memory_region_set_readonly() + - memory_region_set_nonvolatile() - memory_region_set_enabled() - memory_region_set_address() - memory_region_set_alias_offset() diff --git a/include/exec/memory.h b/include/exec/memory.h index d0c7f0d..8e61450 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -355,6 +355,7 @@ struct MemoryRegion { bool ram; bool subpage; bool readonly; /* For RAM regions */ + bool nonvolatile; bool rom_device; bool flush_coalesced_mmio; bool global_locking; @@ -480,6 +481,7 @@ static inline FlatView *address_space_to_flatview(Addre= ssSpace *as) * @offset_within_address_space: the address of the first byte of the sect= ion * relative to the region's address space * @readonly: writes to this section are ignored + * @nonvolatile: this section is non-volatile */ struct MemoryRegionSection { MemoryRegion *mr; @@ -488,6 +490,7 @@ struct MemoryRegionSection { Int128 size; hwaddr offset_within_address_space; bool readonly; + bool nonvolatile; }; =20 /** @@ -1170,6 +1173,17 @@ static inline bool memory_region_is_rom(MemoryRegion= *mr) return mr->ram && mr->readonly; } =20 +/** + * memory_region_is_nonvolatile: check whether a memory region is non-vola= tile + * + * Returns %true is a memory region is non-volatile memory. + * + * @mr: the memory region being queried + */ +static inline bool memory_region_is_nonvolatile(MemoryRegion *mr) +{ + return mr->nonvolatile; +} =20 /** * memory_region_get_fd: Get a file descriptor backing a RAM memory region. @@ -1342,6 +1356,17 @@ void memory_region_reset_dirty(MemoryRegion *mr, hwa= ddr addr, void memory_region_set_readonly(MemoryRegion *mr, bool readonly); =20 /** + * memory_region_set_nonvolatile: Turn a memory region non-volatile + * + * Allows a memory region to be marked as non-volatile. + * only useful on RAM regions. + * + * @mr: the region being updated. + * @nonvolatile: whether rhe region is to be non-volatile. + */ +void memory_region_set_nonvolatile(MemoryRegion *mr, bool nonvolatile); + +/** * memory_region_rom_device_set_romd: enable/disable ROMD mode * * Allows a ROM device (initialized with memory_region_init_rom_device() to diff --git a/memory.c b/memory.c index 51204aa..d14c6de 100644 --- a/memory.c +++ b/memory.c @@ -216,6 +216,7 @@ struct FlatRange { uint8_t dirty_log_mask; bool romd_mode; bool readonly; + bool nonvolatile; }; =20 #define FOR_EACH_FLAT_RANGE(var, view) \ @@ -231,6 +232,7 @@ section_from_flat_range(FlatRange *fr, FlatView *fv) .size =3D fr->addr.size, .offset_within_address_space =3D int128_get64(fr->addr.start), .readonly =3D fr->readonly, + .nonvolatile =3D fr->nonvolatile, }; } =20 @@ -240,7 +242,8 @@ static bool flatrange_equal(FlatRange *a, FlatRange *b) && addrrange_equal(a->addr, b->addr) && a->offset_in_region =3D=3D b->offset_in_region && a->romd_mode =3D=3D b->romd_mode - && a->readonly =3D=3D b->readonly; + && a->readonly =3D=3D b->readonly + && a->nonvolatile =3D=3D b->nonvolatile; } =20 static FlatView *flatview_new(MemoryRegion *mr_root) @@ -312,7 +315,8 @@ static bool can_merge(FlatRange *r1, FlatRange *r2) int128_make64(r2->offset_in_region)) && r1->dirty_log_mask =3D=3D r2->dirty_log_mask && r1->romd_mode =3D=3D r2->romd_mode - && r1->readonly =3D=3D r2->readonly; + && r1->readonly =3D=3D r2->readonly + && r1->nonvolatile =3D=3D r2->nonvolatile; } =20 /* Attempt to simplify a view by merging adjacent ranges */ @@ -592,7 +596,8 @@ static void render_memory_region(FlatView *view, MemoryRegion *mr, Int128 base, AddrRange clip, - bool readonly) + bool readonly, + bool nonvolatile) { MemoryRegion *subregion; unsigned i; @@ -608,6 +613,7 @@ static void render_memory_region(FlatView *view, =20 int128_addto(&base, int128_make64(mr->addr)); readonly |=3D mr->readonly; + nonvolatile |=3D mr->nonvolatile; =20 tmp =3D addrrange_make(base, mr->size); =20 @@ -620,13 +626,15 @@ static void render_memory_region(FlatView *view, if (mr->alias) { int128_subfrom(&base, int128_make64(mr->alias->addr)); int128_subfrom(&base, int128_make64(mr->alias_offset)); - render_memory_region(view, mr->alias, base, clip, readonly); + render_memory_region(view, mr->alias, base, clip, + readonly, nonvolatile); return; } =20 /* Render subregions in priority order. */ QTAILQ_FOREACH(subregion, &mr->subregions, subregions_link) { - render_memory_region(view, subregion, base, clip, readonly); + render_memory_region(view, subregion, base, clip, + readonly, nonvolatile); } =20 if (!mr->terminates) { @@ -641,6 +649,7 @@ static void render_memory_region(FlatView *view, fr.dirty_log_mask =3D memory_region_get_dirty_log_mask(mr); fr.romd_mode =3D mr->romd_mode; fr.readonly =3D readonly; + fr.nonvolatile =3D nonvolatile; =20 /* Render the region itself into any gaps left by the current view. */ for (i =3D 0; i < view->nr && int128_nz(remain); ++i) { @@ -726,7 +735,8 @@ static FlatView *generate_memory_topology(MemoryRegion = *mr) =20 if (mr) { render_memory_region(view, mr, int128_zero(), - addrrange_make(int128_zero(), int128_2_64()),= false); + addrrange_make(int128_zero(), int128_2_64()), + false, false); } flatview_simplify(view); =20 @@ -2039,6 +2049,16 @@ void memory_region_set_readonly(MemoryRegion *mr, bo= ol readonly) } } =20 +void memory_region_set_nonvolatile(MemoryRegion *mr, bool nonvolatile) +{ + if (mr->nonvolatile !=3D nonvolatile) { + memory_region_transaction_begin(); + mr->nonvolatile =3D nonvolatile; + memory_region_update_pending |=3D mr->enabled; + memory_region_transaction_commit(); + } +} + void memory_region_rom_device_set_romd(MemoryRegion *mr, bool romd_mode) { if (mr->romd_mode !=3D romd_mode) { @@ -2489,6 +2509,7 @@ static MemoryRegionSection memory_region_find_rcu(Mem= oryRegion *mr, ret.size =3D range.size; ret.offset_within_address_space =3D int128_get64(range.start); ret.readonly =3D fr->readonly; + ret.nonvolatile =3D fr->nonvolatile; return ret; } =20 @@ -2839,10 +2860,11 @@ static void mtree_print_mr(fprintf_function mon_pri= ntf, void *f, QTAILQ_INSERT_TAIL(alias_print_queue, ml, mrqueue); } mon_printf(f, TARGET_FMT_plx "-" TARGET_FMT_plx - " (prio %d, %s): alias %s @%s " TARGET_FMT_plx + " (prio %d, %s%s): alias %s @%s " TARGET_FMT_plx "-" TARGET_FMT_plx "%s", cur_start, cur_end, mr->priority, + mr->nonvolatile ? "nv-" : "", memory_region_type((MemoryRegion *)mr), memory_region_name(mr), memory_region_name(mr->alias), @@ -2854,9 +2876,10 @@ static void mtree_print_mr(fprintf_function mon_prin= tf, void *f, } } else { mon_printf(f, - TARGET_FMT_plx "-" TARGET_FMT_plx " (prio %d, %s): %s%s= ", + TARGET_FMT_plx "-" TARGET_FMT_plx " (prio %d, %s%s): %s= %s", cur_start, cur_end, mr->priority, + mr->nonvolatile ? "nv-" : "", memory_region_type((MemoryRegion *)mr), memory_region_name(mr), mr->enabled ? "" : " [disabled]"); @@ -2941,19 +2964,21 @@ static void mtree_print_flatview(gpointer key, gpoi= nter value, mr =3D range->mr; if (range->offset_in_region) { p(f, MTREE_INDENT TARGET_FMT_plx "-" - TARGET_FMT_plx " (prio %d, %s): %s @" TARGET_FMT_plx, + TARGET_FMT_plx " (prio %d, %s%s): %s @" TARGET_FMT_plx, int128_get64(range->addr.start), int128_get64(range->addr.start) + MR_SIZE(range->addr.size), mr->priority, + range->nonvolatile ? "nv-" : "", range->readonly ? "rom" : memory_region_type(mr), memory_region_name(mr), range->offset_in_region); } else { p(f, MTREE_INDENT TARGET_FMT_plx "-" - TARGET_FMT_plx " (prio %d, %s): %s", + TARGET_FMT_plx " (prio %d, %s%s): %s", int128_get64(range->addr.start), int128_get64(range->addr.start) + MR_SIZE(range->addr.size), mr->priority, + range->nonvolatile ? "nv-" : "", range->readonly ? "rom" : memory_region_type(mr), memory_region_name(mr)); } --=20 1.8.3.1