From nobody Mon Feb 9 11:43:55 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1665075286; cv=none; d=zohomail.com; s=zohoarc; b=TDbOc33up0vLTm66EYEM++641UePwt2tNlsxOJQrLpzgwKvfx+l0ydkEMTtjR7gXFyXjhrPSqlmUQmFY8UygQcFTB6IOEJ+SSMroZNfp93EhF3FmmUHjSEOZU8XlmC8VzzrgEpm83HcG0OlPAwDJY8GN4wP92vSgvp4aqQ+oCBY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665075286; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TVvpc/SrUvmDLkZ9chOAhp6yjjLI22kiwBGCNoZZB4s=; b=BncqplPCxNAeIp6+rUHyFk+iS8aDp9ZbjDHy6PW3bzbw1rzAK/3DSC/DHSWAnWj9sLYmEz5Byeu1lr+HLnJkstl/WyTCy0r7g7HYpTjjt0cSh+vboDLDZVoi8Ti8sharEcjj9u81uFcopOK1yAtCs/lqtJoLN6VEV3ASbqDBn9o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1665075286250769.1172248974026; Thu, 6 Oct 2022 09:54:46 -0700 (PDT) Received: from localhost ([::1]:57808 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ogU8y-0005A5-JX for importer@patchew.org; Thu, 06 Oct 2022 12:54:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37268) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ogStd-0003Op-Ls for qemu-devel@nongnu.org; Thu, 06 Oct 2022 11:34:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:51322) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ogStb-00008c-95 for qemu-devel@nongnu.org; Thu, 06 Oct 2022 11:34:49 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-441-a3lxBPbnOJetHbbjZawmqA-1; Thu, 06 Oct 2022 11:34:41 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4F28A858F17; Thu, 6 Oct 2022 15:34:40 +0000 (UTC) Received: from localhost (unknown [10.39.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 642BD403167; Thu, 6 Oct 2022 15:34:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665070486; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TVvpc/SrUvmDLkZ9chOAhp6yjjLI22kiwBGCNoZZB4s=; b=U9atOK/c5zc9Da+L7CUht/h4/LA/MiiuYxsGytbwmkuJEL9T66yhKs+wJoSp6vSyZFu0iw h6XoiIRFOOxPVB1TgQMTPoKmZA++Kl8wWuxZ8avmHXtDDPW69a/9JXoiWxiNgjNUwIIMvq z6yefs03vB/hkERshN1KTX/pvrhaGeU= X-MC-Unique: a3lxBPbnOJetHbbjZawmqA-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Richard Henderson , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Bin Meng , Daniel Henrique Barboza , qemu-ppc@nongnu.org, qemu-s390x@nongnu.org, Alistair Francis , qemu-riscv@nongnu.org, Peter Maydell , viktor.prutyanov@redhat.com, Greg Kurz , frankja@linux.ibm.com, David Hildenbrand , Palmer Dabbelt , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson , qemu-arm@nongnu.org, Cornelia Huck , Thomas Huth Subject: [PULL 01/10] dump: Replace opaque DumpState pointer with a typed one Date: Thu, 6 Oct 2022 19:34:20 +0400 Message-Id: <20221006153430.2775580-2-marcandre.lureau@redhat.com> In-Reply-To: <20221006153430.2775580-1-marcandre.lureau@redhat.com> References: <20221006153430.2775580-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1665075289027100001 From: Janosch Frank It's always better to convey the type of a pointer if at all possible. So let's add the DumpState typedef to typedefs.h and move the dump note functions from the opaque pointers to DumpState pointers. Signed-off-by: Janosch Frank CC: Peter Maydell CC: C=C3=A9dric Le Goater CC: Daniel Henrique Barboza CC: David Gibson CC: Greg Kurz CC: Palmer Dabbelt CC: Alistair Francis CC: Bin Meng CC: Cornelia Huck CC: Thomas Huth CC: Richard Henderson CC: David Hildenbrand Acked-by: Daniel Henrique Barboza Reviewed-by: Marc-Andr=C3=A9 Lureau Message-Id: <20220811121111.9878-2-frankja@linux.ibm.com> --- include/hw/core/sysemu-cpu-ops.h | 8 ++++---- include/qemu/typedefs.h | 1 + target/arm/cpu.h | 4 ++-- target/i386/cpu.h | 8 ++++---- target/ppc/cpu.h | 4 ++-- target/riscv/cpu.h | 4 ++-- target/s390x/s390x-internal.h | 2 +- target/arm/arch_dump.c | 6 ++---- target/i386/arch_dump.c | 30 +++++++++++++++--------------- target/ppc/arch_dump.c | 18 +++++++++--------- target/riscv/arch_dump.c | 6 ++---- target/s390x/arch_dump.c | 10 +++++----- 12 files changed, 49 insertions(+), 52 deletions(-) diff --git a/include/hw/core/sysemu-cpu-ops.h b/include/hw/core/sysemu-cpu-= ops.h index a9ba39e5f2..ee169b872c 100644 --- a/include/hw/core/sysemu-cpu-ops.h +++ b/include/hw/core/sysemu-cpu-ops.h @@ -53,25 +53,25 @@ typedef struct SysemuCPUOps { * 32-bit VM coredump. */ int (*write_elf32_note)(WriteCoreDumpFunction f, CPUState *cpu, - int cpuid, void *opaque); + int cpuid, DumpState *s); /** * @write_elf64_note: Callback for writing a CPU-specific ELF note to a * 64-bit VM coredump. */ int (*write_elf64_note)(WriteCoreDumpFunction f, CPUState *cpu, - int cpuid, void *opaque); + int cpuid, DumpState *s); /** * @write_elf32_qemunote: Callback for writing a CPU- and QEMU-specifi= c ELF * note to a 32-bit VM coredump. */ int (*write_elf32_qemunote)(WriteCoreDumpFunction f, CPUState *cpu, - void *opaque); + DumpState *s); /** * @write_elf64_qemunote: Callback for writing a CPU- and QEMU-specifi= c ELF * note to a 64-bit VM coredump. */ int (*write_elf64_qemunote)(WriteCoreDumpFunction f, CPUState *cpu, - void *opaque); + DumpState *s); /** * @virtio_is_big_endian: Callback to return %true if a CPU which supp= orts * runtime configurable endianness is currently big-endian. diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h index 5f95169827..6d4e6d9708 100644 --- a/include/qemu/typedefs.h +++ b/include/qemu/typedefs.h @@ -131,6 +131,7 @@ typedef struct VirtIODevice VirtIODevice; typedef struct Visitor Visitor; typedef struct VMChangeStateEntry VMChangeStateEntry; typedef struct VMStateDescription VMStateDescription; +typedef struct DumpState DumpState; =20 /* * Pointer types diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 429ed42eec..85dc263318 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -1102,9 +1102,9 @@ int arm_gen_dynamic_svereg_xml(CPUState *cpu, int bas= e_reg); const char *arm_gdb_get_dynamic_xml(CPUState *cpu, const char *xmlname); =20 int arm_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs, - int cpuid, void *opaque); + int cpuid, DumpState *s); int arm_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs, - int cpuid, void *opaque); + int cpuid, DumpState *s); =20 #ifdef TARGET_AARCH64 int aarch64_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 82004b65b9..b75108d6a3 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1938,13 +1938,13 @@ extern const VMStateDescription vmstate_x86_cpu; int x86_cpu_pending_interrupt(CPUState *cs, int interrupt_request); =20 int x86_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu, - int cpuid, void *opaque); + int cpuid, DumpState *s); int x86_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu, - int cpuid, void *opaque); + int cpuid, DumpState *s); int x86_cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu, - void *opaque); + DumpState *s); int x86_cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu, - void *opaque); + DumpState *s); =20 void x86_cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list, Error **errp); diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index 7f73e2ac81..cca6c4e51c 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -1354,9 +1354,9 @@ void ppc_gdb_gen_spr_xml(PowerPCCPU *cpu); const char *ppc_gdb_get_dynamic_xml(CPUState *cs, const char *xml_name); #endif int ppc64_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs, - int cpuid, void *opaque); + int cpuid, DumpState *s); int ppc32_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs, - int cpuid, void *opaque); + int cpuid, DumpState *s); #ifndef CONFIG_USER_ONLY void ppc_cpu_do_interrupt(CPUState *cpu); bool ppc_cpu_exec_interrupt(CPUState *cpu, int int_req); diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index b131fa8c8e..3a9e25053f 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -534,9 +534,9 @@ extern const char * const riscv_fpr_regnames[]; const char *riscv_cpu_get_trap_name(target_ulong cause, bool async); void riscv_cpu_do_interrupt(CPUState *cpu); int riscv_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs, - int cpuid, void *opaque); + int cpuid, DumpState *s); int riscv_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs, - int cpuid, void *opaque); + int cpuid, DumpState *s); int riscv_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); int riscv_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); int riscv_cpu_hviprio_index2irq(int index, int *out_irq, int *out_rdzero); diff --git a/target/s390x/s390x-internal.h b/target/s390x/s390x-internal.h index 6aba7fd0ca..b5ae0ae364 100644 --- a/target/s390x/s390x-internal.h +++ b/target/s390x/s390x-internal.h @@ -227,7 +227,7 @@ static inline hwaddr decode_basedisp_s(CPUS390XState *e= nv, uint32_t ipb, =20 /* arch_dump.c */ int s390_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs, - int cpuid, void *opaque); + int cpuid, DumpState *s); =20 =20 /* cc_helper.c */ diff --git a/target/arm/arch_dump.c b/target/arm/arch_dump.c index b1f040e69f..2d8e41ab8a 100644 --- a/target/arm/arch_dump.c +++ b/target/arm/arch_dump.c @@ -232,12 +232,11 @@ static int aarch64_write_elf64_sve(WriteCoreDumpFunct= ion f, #endif =20 int arm_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs, - int cpuid, void *opaque) + int cpuid, DumpState *s) { struct aarch64_note note; ARMCPU *cpu =3D ARM_CPU(cs); CPUARMState *env =3D &cpu->env; - DumpState *s =3D opaque; uint64_t pstate, sp; int ret, i; =20 @@ -360,12 +359,11 @@ static int arm_write_elf32_vfp(WriteCoreDumpFunction = f, CPUARMState *env, } =20 int arm_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs, - int cpuid, void *opaque) + int cpuid, DumpState *s) { struct arm_note note; ARMCPU *cpu =3D ARM_CPU(cs); CPUARMState *env =3D &cpu->env; - DumpState *s =3D opaque; int ret, i; bool fpvalid =3D cpu_isar_feature(aa32_vfp_simd, cpu); =20 diff --git a/target/i386/arch_dump.c b/target/i386/arch_dump.c index 004141fc04..c290910a04 100644 --- a/target/i386/arch_dump.c +++ b/target/i386/arch_dump.c @@ -42,7 +42,7 @@ typedef struct { =20 static int x86_64_write_elf64_note(WriteCoreDumpFunction f, CPUX86State *env, int id, - void *opaque) + DumpState *s) { x86_64_user_regs_struct regs; Elf64_Nhdr *note; @@ -94,7 +94,7 @@ static int x86_64_write_elf64_note(WriteCoreDumpFunction = f, buf +=3D descsz - sizeof(x86_64_user_regs_struct)-sizeof(target_ulong); memcpy(buf, ®s, sizeof(x86_64_user_regs_struct)); =20 - ret =3D f(note, note_size, opaque); + ret =3D f(note, note_size, s); g_free(note); if (ret < 0) { return -1; @@ -148,7 +148,7 @@ static void x86_fill_elf_prstatus(x86_elf_prstatus *prs= tatus, CPUX86State *env, } =20 static int x86_write_elf64_note(WriteCoreDumpFunction f, CPUX86State *env, - int id, void *opaque) + int id, DumpState *s) { x86_elf_prstatus prstatus; Elf64_Nhdr *note; @@ -170,7 +170,7 @@ static int x86_write_elf64_note(WriteCoreDumpFunction f= , CPUX86State *env, buf +=3D ROUND_UP(name_size, 4); memcpy(buf, &prstatus, sizeof(prstatus)); =20 - ret =3D f(note, note_size, opaque); + ret =3D f(note, note_size, s); g_free(note); if (ret < 0) { return -1; @@ -180,7 +180,7 @@ static int x86_write_elf64_note(WriteCoreDumpFunction f= , CPUX86State *env, } =20 int x86_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs, - int cpuid, void *opaque) + int cpuid, DumpState *s) { X86CPU *cpu =3D X86_CPU(cs); int ret; @@ -189,10 +189,10 @@ int x86_cpu_write_elf64_note(WriteCoreDumpFunction f,= CPUState *cs, bool lma =3D !!(first_x86_cpu->env.hflags & HF_LMA_MASK); =20 if (lma) { - ret =3D x86_64_write_elf64_note(f, &cpu->env, cpuid, opaque); + ret =3D x86_64_write_elf64_note(f, &cpu->env, cpuid, s); } else { #endif - ret =3D x86_write_elf64_note(f, &cpu->env, cpuid, opaque); + ret =3D x86_write_elf64_note(f, &cpu->env, cpuid, s); #ifdef TARGET_X86_64 } #endif @@ -201,7 +201,7 @@ int x86_cpu_write_elf64_note(WriteCoreDumpFunction f, C= PUState *cs, } =20 int x86_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs, - int cpuid, void *opaque) + int cpuid, DumpState *s) { X86CPU *cpu =3D X86_CPU(cs); x86_elf_prstatus prstatus; @@ -224,7 +224,7 @@ int x86_cpu_write_elf32_note(WriteCoreDumpFunction f, C= PUState *cs, buf +=3D ROUND_UP(name_size, 4); memcpy(buf, &prstatus, sizeof(prstatus)); =20 - ret =3D f(note, note_size, opaque); + ret =3D f(note, note_size, s); g_free(note); if (ret < 0) { return -1; @@ -329,7 +329,7 @@ static void qemu_get_cpustate(QEMUCPUState *s, CPUX86St= ate *env) =20 static inline int cpu_write_qemu_note(WriteCoreDumpFunction f, CPUX86State *env, - void *opaque, + DumpState *s, int type) { QEMUCPUState state; @@ -369,7 +369,7 @@ static inline int cpu_write_qemu_note(WriteCoreDumpFunc= tion f, buf +=3D ROUND_UP(name_size, 4); memcpy(buf, &state, sizeof(state)); =20 - ret =3D f(note, note_size, opaque); + ret =3D f(note, note_size, s); g_free(note); if (ret < 0) { return -1; @@ -379,19 +379,19 @@ static inline int cpu_write_qemu_note(WriteCoreDumpFu= nction f, } =20 int x86_cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cs, - void *opaque) + DumpState *s) { X86CPU *cpu =3D X86_CPU(cs); =20 - return cpu_write_qemu_note(f, &cpu->env, opaque, 1); + return cpu_write_qemu_note(f, &cpu->env, s, 1); } =20 int x86_cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cs, - void *opaque) + DumpState *s) { X86CPU *cpu =3D X86_CPU(cs); =20 - return cpu_write_qemu_note(f, &cpu->env, opaque, 0); + return cpu_write_qemu_note(f, &cpu->env, s, 0); } =20 int cpu_get_dump_info(ArchDumpInfo *info, diff --git a/target/ppc/arch_dump.c b/target/ppc/arch_dump.c index 1139cead9f..f58e6359d5 100644 --- a/target/ppc/arch_dump.c +++ b/target/ppc/arch_dump.c @@ -270,23 +270,23 @@ ssize_t cpu_get_note_size(int class, int machine, int= nr_cpus) static int ppc_write_all_elf_notes(const char *note_name, WriteCoreDumpFunction f, PowerPCCPU *cpu, int id, - void *opaque) + DumpState *s) { - NoteFuncArg arg =3D { .state =3D opaque }; + NoteFuncArg arg =3D { .state =3D s }; int ret =3D -1; int note_size; const NoteFuncDesc *nf; =20 for (nf =3D note_func; nf->note_contents_func; nf++) { - arg.note.hdr.n_namesz =3D cpu_to_dump32(opaque, sizeof(arg.note.na= me)); - arg.note.hdr.n_descsz =3D cpu_to_dump32(opaque, nf->contents_size); + arg.note.hdr.n_namesz =3D cpu_to_dump32(s, sizeof(arg.note.name)); + arg.note.hdr.n_descsz =3D cpu_to_dump32(s, nf->contents_size); strncpy(arg.note.name, note_name, sizeof(arg.note.name)); =20 (*nf->note_contents_func)(&arg, cpu); =20 note_size =3D sizeof(arg.note) - sizeof(arg.note.contents) + nf->contents_si= ze; - ret =3D f(&arg.note, note_size, opaque); + ret =3D f(&arg.note, note_size, s); if (ret < 0) { return -1; } @@ -295,15 +295,15 @@ static int ppc_write_all_elf_notes(const char *note_n= ame, } =20 int ppc64_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs, - int cpuid, void *opaque) + int cpuid, DumpState *s) { PowerPCCPU *cpu =3D POWERPC_CPU(cs); - return ppc_write_all_elf_notes("CORE", f, cpu, cpuid, opaque); + return ppc_write_all_elf_notes("CORE", f, cpu, cpuid, s); } =20 int ppc32_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs, - int cpuid, void *opaque) + int cpuid, DumpState *s) { PowerPCCPU *cpu =3D POWERPC_CPU(cs); - return ppc_write_all_elf_notes("CORE", f, cpu, cpuid, opaque); + return ppc_write_all_elf_notes("CORE", f, cpu, cpuid, s); } diff --git a/target/riscv/arch_dump.c b/target/riscv/arch_dump.c index 709f621d82..736a232956 100644 --- a/target/riscv/arch_dump.c +++ b/target/riscv/arch_dump.c @@ -64,12 +64,11 @@ static void riscv64_note_init(struct riscv64_note *note= , DumpState *s, } =20 int riscv_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs, - int cpuid, void *opaque) + int cpuid, DumpState *s) { struct riscv64_note note; RISCVCPU *cpu =3D RISCV_CPU(cs); CPURISCVState *env =3D &cpu->env; - DumpState *s =3D opaque; int ret, i =3D 0; const char name[] =3D "CORE"; =20 @@ -134,12 +133,11 @@ static void riscv32_note_init(struct riscv32_note *no= te, DumpState *s, } =20 int riscv_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs, - int cpuid, void *opaque) + int cpuid, DumpState *s) { struct riscv32_note note; RISCVCPU *cpu =3D RISCV_CPU(cs); CPURISCVState *env =3D &cpu->env; - DumpState *s =3D opaque; int ret, i; const char name[] =3D "CORE"; =20 diff --git a/target/s390x/arch_dump.c b/target/s390x/arch_dump.c index 08daf93ae1..f60a14920d 100644 --- a/target/s390x/arch_dump.c +++ b/target/s390x/arch_dump.c @@ -204,7 +204,7 @@ static const NoteFuncDesc note_linux[] =3D { static int s390x_write_elf64_notes(const char *note_name, WriteCoreDumpFunction f, S390CPU *cpu, int id, - void *opaque, + DumpState *s, const NoteFuncDesc *funcs) { Note note; @@ -222,7 +222,7 @@ static int s390x_write_elf64_notes(const char *note_nam= e, (*nf->note_contents_func)(¬e, cpu, id); =20 note_size =3D sizeof(note) - sizeof(note.contents) + nf->contents_= size; - ret =3D f(¬e, note_size, opaque); + ret =3D f(¬e, note_size, s); =20 if (ret < 0) { return -1; @@ -235,16 +235,16 @@ static int s390x_write_elf64_notes(const char *note_n= ame, =20 =20 int s390_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs, - int cpuid, void *opaque) + int cpuid, DumpState *s) { S390CPU *cpu =3D S390_CPU(cs); int r; =20 - r =3D s390x_write_elf64_notes("CORE", f, cpu, cpuid, opaque, note_core= ); + r =3D s390x_write_elf64_notes("CORE", f, cpu, cpuid, s, note_core); if (r) { return r; } - return s390x_write_elf64_notes("LINUX", f, cpu, cpuid, opaque, note_li= nux); + return s390x_write_elf64_notes("LINUX", f, cpu, cpuid, s, note_linux); } =20 int cpu_get_dump_info(ArchDumpInfo *info, --=20 2.37.3 From nobody Mon Feb 9 11:43:55 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1665074995; cv=none; d=zohomail.com; s=zohoarc; b=fMZRPfYi98H1yFcsNLHpLpWCQG/QUl01ZvPptDAbAH5nCnT3VL5L13SKZQ0sQG5rjVWoSThtmEfH3cGjT9cCW8NWNf037Z8mfuBCXA9kntopIHxadOv2HeP8y2xU5ms7SH/TDIRHP8F4tnZiBKhxdPgf1W3wUm0QAwdRl+8zVu8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665074995; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3ZRyp7UkxaTDSDvUxw8uUazNBUoWOOo6PFrghM0r5L0=; b=bpQBNTfYvmoScBzV538/4X7GKzxUfXD//1tY5BIeafLcvYxUOeqcMqNRmMxI652RaNPHQzLHbNf6BjFKqxyHjyO24vYTAeBqc+fEbCkst+fAtpJoKpWTJmhhTOOqz5BD8U/qxJeeWEpXjvJy80B3B4BTf2JcTEy1JT5hcclP8yg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1665074995628691.4251005825831; Thu, 6 Oct 2022 09:49:55 -0700 (PDT) Received: from localhost ([::1]:38004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ogU4I-0007QY-5q for importer@patchew.org; Thu, 06 Oct 2022 12:49:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57702) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ogStj-0003XI-Vb for qemu-devel@nongnu.org; Thu, 06 Oct 2022 11:34:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:20711) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ogSti-00009s-Hw for qemu-devel@nongnu.org; Thu, 06 Oct 2022 11:34:55 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-248-RZxaDvWSMZySUeajtMEfVg-1; Thu, 06 Oct 2022 11:34:44 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E551129324AB; Thu, 6 Oct 2022 15:34:43 +0000 (UTC) Received: from localhost (unknown [10.39.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2779A2011567; Thu, 6 Oct 2022 15:34:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665070493; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3ZRyp7UkxaTDSDvUxw8uUazNBUoWOOo6PFrghM0r5L0=; b=fPHEFNL1aOWOOnxCqZwRqKuW8BQqXhFupng1QTKVQWhrNZaWOAhH3UltaedxjcJGNnXJvN DBARDLBlp8rtNmzsKkfFixa5XW1/OPu8ojfzJqoGbRyO2x91eeh1ZFJcUZfiIU0Db1AIso VxCkmGW+jai3EUrOjkrirD7B/dzb+VA= X-MC-Unique: RZxaDvWSMZySUeajtMEfVg-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Richard Henderson , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Bin Meng , Daniel Henrique Barboza , qemu-ppc@nongnu.org, qemu-s390x@nongnu.org, Alistair Francis , qemu-riscv@nongnu.org, Peter Maydell , viktor.prutyanov@redhat.com, Greg Kurz , frankja@linux.ibm.com, David Hildenbrand , Palmer Dabbelt , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson , qemu-arm@nongnu.org, Cornelia Huck , Thomas Huth Subject: [PULL 02/10] dump: Rename write_elf_loads to write_elf_phdr_loads Date: Thu, 6 Oct 2022 19:34:21 +0400 Message-Id: <20221006153430.2775580-3-marcandre.lureau@redhat.com> In-Reply-To: <20221006153430.2775580-1-marcandre.lureau@redhat.com> References: <20221006153430.2775580-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1665074998091100001 From: Janosch Frank Let's make it a bit clearer that we write the program headers of the PT_LOAD type. Signed-off-by: Janosch Frank Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Janis Schoetterl-Glausch Reviewed-by: Steffen Eiden Message-Id: <20220811121111.9878-3-frankja@linux.ibm.com> --- dump/dump.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dump/dump.c b/dump/dump.c index 4d9658ffa2..0ed7cf9c7b 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -490,7 +490,7 @@ static void get_offset_range(hwaddr phys_addr, } } =20 -static void write_elf_loads(DumpState *s, Error **errp) +static void write_elf_phdr_loads(DumpState *s, Error **errp) { ERRP_GUARD(); hwaddr offset, filesz; @@ -573,8 +573,8 @@ static void dump_begin(DumpState *s, Error **errp) return; } =20 - /* write all PT_LOAD to vmcore */ - write_elf_loads(s, errp); + /* write all PT_LOADs to vmcore */ + write_elf_phdr_loads(s, errp); if (*errp) { return; } --=20 2.37.3 From nobody Mon Feb 9 11:43:55 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1665075549; cv=none; d=zohomail.com; s=zohoarc; b=S04CequgD8jvzDt7noZ0PK7L9rr6VJRhVr0EXQbhZrIDe9DW5P/GMpgVNNxwxSmaJHjPf1XTJSb9BCsMykCeJF1d/pxPqFje2tjBOyNLLhgzE6E85jO0HDV+8NpXO9LKxxb62v9kMYy2O9BFMDAzPt8m0zbDLzH0XvE8ZZk/D/Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665075549; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=xAq2xlqRdVIbUoDtOLarQdrR1IEKv+tZdV05JKo94l4=; b=ijndhsL/XrtXRoXdWUqj/dzEfHzcCja0XZKG89dTAxnmKEMvIwMxlSldF50/G4CE1uNkTueyJq/Z1kAv9FCCTPyAV0W2ufwSFMw7tZR7WEulKU7WIk/qr07lawRLNm9PP32E1PNwOub8CCb+cnHiwwc4LjshK65/IwugOcH1ZNE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1665075549237485.7222516327521; Thu, 6 Oct 2022 09:59:09 -0700 (PDT) Received: from localhost ([::1]:42702 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ogUDD-0002o6-93 for importer@patchew.org; Thu, 06 Oct 2022 12:59:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37274) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ogSth-0003Tn-3X for qemu-devel@nongnu.org; Thu, 06 Oct 2022 11:34:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:30827) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ogStf-00009X-Gc for qemu-devel@nongnu.org; Thu, 06 Oct 2022 11:34:52 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-531-0Qayu6ugPd-eEXtvMmJMFA-1; Thu, 06 Oct 2022 11:34:49 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A6F66185A7AA; Thu, 6 Oct 2022 15:34:48 +0000 (UTC) Received: from localhost (unknown [10.39.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F7C32166B2E; Thu, 6 Oct 2022 15:34:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665070490; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xAq2xlqRdVIbUoDtOLarQdrR1IEKv+tZdV05JKo94l4=; b=Y8qfWcfnsABWyH8CelMmcSwf3ULkcVq+aXr6FoUnEY/B1lYaEqGXD+fsxuDNUjtavSYtfJ QN/dhXRMX4ckXAq4J6saP95JMCuhaVjn6MCtLADomS2nc0Fe7DN8usVDGdb+si6aB5PjXg UI2vw0cw9Z6ow0MgllGYO+fyIISQGjs= X-MC-Unique: 0Qayu6ugPd-eEXtvMmJMFA-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Richard Henderson , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Bin Meng , Daniel Henrique Barboza , qemu-ppc@nongnu.org, qemu-s390x@nongnu.org, Alistair Francis , qemu-riscv@nongnu.org, Peter Maydell , viktor.prutyanov@redhat.com, Greg Kurz , frankja@linux.ibm.com, David Hildenbrand , Palmer Dabbelt , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson , qemu-arm@nongnu.org, Cornelia Huck , Thomas Huth Subject: [PULL 03/10] dump: Refactor dump_iterate and introduce dump_filter_memblock_*() Date: Thu, 6 Oct 2022 19:34:22 +0400 Message-Id: <20221006153430.2775580-4-marcandre.lureau@redhat.com> In-Reply-To: <20221006153430.2775580-1-marcandre.lureau@redhat.com> References: <20221006153430.2775580-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1665075551098100001 From: Janosch Frank The iteration over the memblocks in dump_iterate() is hard to understand so it's about time to clean it up. Instead of manually grabbing the next memblock we can use QTAILQ_FOREACH to iterate over all memblocks. Additionally we move the calculation of the offset and length out by introducing and using the dump_filter_memblock_*() functions. These functions will later be used to cleanup other parts of dump.c. Signed-off-by: Janosch Frank Reviewed-by: Janis Schoetterl-Glausch Reviewed-by: Marc-Andr=C3=A9 Lureau Message-Id: <20220811121111.9878-4-frankja@linux.ibm.com> --- dump/dump.c | 74 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 32 deletions(-) diff --git a/dump/dump.c b/dump/dump.c index 0ed7cf9c7b..340de5a1e7 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -591,31 +591,43 @@ static void dump_begin(DumpState *s, Error **errp) write_elf_notes(s, errp); } =20 -static int get_next_block(DumpState *s, GuestPhysBlock *block) +static int64_t dump_filtered_memblock_size(GuestPhysBlock *block, + int64_t filter_area_start, + int64_t filter_area_length) { - while (1) { - block =3D QTAILQ_NEXT(block, next); - if (!block) { - /* no more block */ - return 1; - } + int64_t size, left, right; =20 - s->start =3D 0; - s->next_block =3D block; - if (s->has_filter) { - if (block->target_start >=3D s->begin + s->length || - block->target_end <=3D s->begin) { - /* This block is out of the range */ - continue; - } + /* No filter, return full size */ + if (!filter_area_length) { + return block->target_end - block->target_start; + } =20 - if (s->begin > block->target_start) { - s->start =3D s->begin - block->target_start; - } + /* calculate the overlapped region. */ + left =3D MAX(filter_area_start, block->target_start); + right =3D MIN(filter_area_start + filter_area_length, block->target_en= d); + size =3D right - left; + size =3D size > 0 ? size : 0; + + return size; +} + +static int64_t dump_filtered_memblock_start(GuestPhysBlock *block, + int64_t filter_area_start, + int64_t filter_area_length) +{ + if (filter_area_length) { + /* return -1 if the block is not within filter area */ + if (block->target_start >=3D filter_area_start + filter_area_lengt= h || + block->target_end <=3D filter_area_start) { + return -1; } =20 - return 0; + if (filter_area_start > block->target_start) { + return filter_area_start - block->target_start; + } } + + return 0; } =20 /* write all memory to vmcore */ @@ -623,24 +635,22 @@ static void dump_iterate(DumpState *s, Error **errp) { ERRP_GUARD(); GuestPhysBlock *block; - int64_t size; - - do { - block =3D s->next_block; + int64_t memblock_size, memblock_start; =20 - size =3D block->target_end - block->target_start; - if (s->has_filter) { - size -=3D s->start; - if (s->begin + s->length < block->target_end) { - size -=3D block->target_end - (s->begin + s->length); - } + QTAILQ_FOREACH(block, &s->guest_phys_blocks.head, next) { + memblock_start =3D dump_filtered_memblock_start(block, s->begin, s= ->length); + if (memblock_start =3D=3D -1) { + continue; } - write_memory(s, block, s->start, size, errp); + + memblock_size =3D dump_filtered_memblock_size(block, s->begin, s->= length); + + /* Write the memory to file */ + write_memory(s, block, memblock_start, memblock_size, errp); if (*errp) { return; } - - } while (!get_next_block(s, block)); + } } =20 static void create_vmcore(DumpState *s, Error **errp) --=20 2.37.3 From nobody Mon Feb 9 11:43:55 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1665074284; cv=none; d=zohomail.com; s=zohoarc; b=YalYVe0kCeDvficCFlw+Sxsp2GZ+ByupFQzDkSR3u32IyqumuKpz5WjYBcuir1keRK+3GrFsyKt+upxjeA07gutVmUeklJB2agsm6NKEKqXrzUO4f+YgQaLRRaLtXvr58MvmnrwhQnHN5SSV6zIZ/33+GRAlR8RzzBtu0hTeJWs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665074284; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hOe6/bXHtInA3YwKjW6+QwwmoXeYh/XCY11FblVu8TQ=; b=Kp1zYsEL0K1/E/Xql0DjPD32he7ntiLjOx0DZlIVQWI4+NUqV/5s09gHTUZsrQdm6zQZyq4xzuMPeoPBVX1cBD5aDVl0ubTw8d0if8MJ+rWqO/e2BG67olehzj9NaJLTIIT194UytrgBjkS3QOPlHPgGmhmWrkUxHUNV3hJagIM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1665074284430831.6077967975186; Thu, 6 Oct 2022 09:38:04 -0700 (PDT) Received: from localhost ([::1]:43952 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ogTso-0005XL-79 for importer@patchew.org; Thu, 06 Oct 2022 12:38:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57734) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ogSts-0003Zi-BH for qemu-devel@nongnu.org; Thu, 06 Oct 2022 11:35:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:47119) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ogSto-0000BO-6P for qemu-devel@nongnu.org; Thu, 06 Oct 2022 11:35:04 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-606-5ZQCxANkNLennBI02oULMQ-1; Thu, 06 Oct 2022 11:34:53 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 95C1C185A7AA; Thu, 6 Oct 2022 15:34:52 +0000 (UTC) Received: from localhost (unknown [10.39.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7FA22202323C; Thu, 6 Oct 2022 15:34:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665070499; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hOe6/bXHtInA3YwKjW6+QwwmoXeYh/XCY11FblVu8TQ=; b=eHJAd3fbGAeeuKnBWpEq4gNW8YKsDrOHuz7cT0kST/p5MYy881nGTWWSDIMCec4KgNk/ae ERfETCCS/oYWnaJRrMYoSa0NWY9EycO7n5JXPYScfsizGsgWqJMdKGQ8MjJI69gaDIhF4y HBbtjG/WsiTM/HFUvXUZnaVZ37ZUJMI= X-MC-Unique: 5ZQCxANkNLennBI02oULMQ-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Richard Henderson , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Bin Meng , Daniel Henrique Barboza , qemu-ppc@nongnu.org, qemu-s390x@nongnu.org, Alistair Francis , qemu-riscv@nongnu.org, Peter Maydell , viktor.prutyanov@redhat.com, Greg Kurz , frankja@linux.ibm.com, David Hildenbrand , Palmer Dabbelt , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson , qemu-arm@nongnu.org, Cornelia Huck , Thomas Huth Subject: [PULL 04/10] dump: Rework get_start_block Date: Thu, 6 Oct 2022 19:34:23 +0400 Message-Id: <20221006153430.2775580-5-marcandre.lureau@redhat.com> In-Reply-To: <20221006153430.2775580-1-marcandre.lureau@redhat.com> References: <20221006153430.2775580-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1665074285489100001 From: Janosch Frank get_start_block() returns the start address of the first memory block or -1. With the GuestPhysBlock iterator conversion we don't need to set the start address and can therefore remove that code and the "start" DumpState struct member. The only functionality left is the validation of the start block so it only makes sense to re-name the function to validate_start_block() Signed-off-by: Janosch Frank Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Janis Schoetterl-Glausch Message-Id: <20220811121111.9878-5-frankja@linux.ibm.com> --- include/sysemu/dump.h | 2 -- dump/dump.c | 20 ++++++-------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h index ffc2ea1072..7fce1d4af6 100644 --- a/include/sysemu/dump.h +++ b/include/sysemu/dump.h @@ -166,8 +166,6 @@ typedef struct DumpState { hwaddr memory_offset; int fd; =20 - GuestPhysBlock *next_block; - ram_addr_t start; bool has_filter; int64_t begin; int64_t length; diff --git a/dump/dump.c b/dump/dump.c index 340de5a1e7..e204912a89 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -1500,30 +1500,22 @@ static void create_kdump_vmcore(DumpState *s, Error= **errp) } } =20 -static ram_addr_t get_start_block(DumpState *s) +static int validate_start_block(DumpState *s) { GuestPhysBlock *block; =20 if (!s->has_filter) { - s->next_block =3D QTAILQ_FIRST(&s->guest_phys_blocks.head); return 0; } =20 QTAILQ_FOREACH(block, &s->guest_phys_blocks.head, next) { + /* This block is out of the range */ if (block->target_start >=3D s->begin + s->length || block->target_end <=3D s->begin) { - /* This block is out of the range */ continue; } - - s->next_block =3D block; - if (s->begin > block->target_start) { - s->start =3D s->begin - block->target_start; - } else { - s->start =3D 0; - } - return s->start; - } + return 0; + } =20 return -1; } @@ -1670,8 +1662,8 @@ static void dump_init(DumpState *s, int fd, bool has_= format, goto cleanup; } =20 - s->start =3D get_start_block(s); - if (s->start =3D=3D -1) { + /* Is the filter filtering everything? */ + if (validate_start_block(s) =3D=3D -1) { error_setg(errp, QERR_INVALID_PARAMETER, "begin"); goto cleanup; } --=20 2.37.3 From nobody Mon Feb 9 11:43:55 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1665075385; cv=none; d=zohomail.com; s=zohoarc; b=QnCCEDfxBe+kFKRI16AWnkh86LUsiddbr0+tKVumNuAEe0UODm5jqmZqK6S8HyIJs8KqpKC4OJHQEFItk9+95s5upKpaLaCn2RNCiOUvZ1U5C2ve1bnT9cmYru71+oRdStTMpg9BXURPIFgLBEWcyIFnsV+1OlDLXLr7uRPdnnM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665075385; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vxoyBgRg/QRR8DJrKFWrMB45SvFGdxqWA6B8F05damA=; b=Q8mqb/bX6N3+lYq0KUWo9NAr/UI29i3sEb/dUfx2IgCJWF6ouIkxuc2ohNPJm+PvXOQsKWGsu1t7zYKiU4MCoFQDAjXuhJfwuwzCaaRRN5SkqBYLC17KK5eTcXXbq7QRK9vOqoef8R+Q9GrEeVbay0tzXFMiPeq1j7hTDTlVhBc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1665075385379875.3479464297317; Thu, 6 Oct 2022 09:56:25 -0700 (PDT) Received: from localhost ([::1]:35626 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ogUAZ-0006PP-11 for importer@patchew.org; Thu, 06 Oct 2022 12:56:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43808) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ogStu-0003Zy-Li for qemu-devel@nongnu.org; Thu, 06 Oct 2022 11:35:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:25193) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ogStp-0000Bu-Lt for qemu-devel@nongnu.org; Thu, 06 Oct 2022 11:35:05 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-312-6E1M_XQ4PXOLEn_sLAaeBQ-1; Thu, 06 Oct 2022 11:34:57 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E2B11185A79C; Thu, 6 Oct 2022 15:34:56 +0000 (UTC) Received: from localhost (unknown [10.39.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id A811B2166B2E; Thu, 6 Oct 2022 15:34:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665070500; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vxoyBgRg/QRR8DJrKFWrMB45SvFGdxqWA6B8F05damA=; b=NPtYMX+JsZX+rT7h4aPR3HHhXQ9X0ejkIe0+cA4quYqdoRoYHbKg6pzqsOQ7n2CPbsWi/J 2OqW2si2zxKMycvy3SOULzcO72/A51fhxMgs9gffas7FUAnHTaFS5fQuNycfqlsBMYLrHo sSm1m4+WsE+gpj/i4Kbyxra6OTEGBmI= X-MC-Unique: 6E1M_XQ4PXOLEn_sLAaeBQ-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Richard Henderson , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Bin Meng , Daniel Henrique Barboza , qemu-ppc@nongnu.org, qemu-s390x@nongnu.org, Alistair Francis , qemu-riscv@nongnu.org, Peter Maydell , viktor.prutyanov@redhat.com, Greg Kurz , frankja@linux.ibm.com, David Hildenbrand , Palmer Dabbelt , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson , qemu-arm@nongnu.org, Cornelia Huck , Thomas Huth Subject: [PULL 05/10] dump: Rework filter area variables Date: Thu, 6 Oct 2022 19:34:24 +0400 Message-Id: <20221006153430.2775580-6-marcandre.lureau@redhat.com> In-Reply-To: <20221006153430.2775580-1-marcandre.lureau@redhat.com> References: <20221006153430.2775580-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1665075387202100001 From: Janosch Frank While the DumpState begin and length variables directly mirror the API variable names they are not very descriptive. So let's add a "filter_area_" prefix and make has_filter a function checking length > 0. Signed-off-by: Janosch Frank Reviewed-by: Marc-Andr=C3=A9 Lureau Message-Id: <20220811121111.9878-6-frankja@linux.ibm.com> --- include/sysemu/dump.h | 13 ++++++++--- dump/dump.c | 53 +++++++++++++++++++++++++------------------ 2 files changed, 41 insertions(+), 25 deletions(-) diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h index 7fce1d4af6..b62513d87d 100644 --- a/include/sysemu/dump.h +++ b/include/sysemu/dump.h @@ -166,9 +166,16 @@ typedef struct DumpState { hwaddr memory_offset; int fd; =20 - bool has_filter; - int64_t begin; - int64_t length; + /* + * Dump filter area variables + * + * A filtered dump only contains the guest memory designated by + * the start address and length variables defined below. + * + * If length is 0, no filtering is applied. + */ + int64_t filter_area_begin; /* Start address of partial guest memory a= rea */ + int64_t filter_area_length; /* Length of partial guest memory area */ =20 uint8_t *note_buf; /* buffer for notes */ size_t note_buf_offset; /* the writing place in note_buf */ diff --git a/dump/dump.c b/dump/dump.c index e204912a89..b043337bc7 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -59,6 +59,11 @@ static inline bool dump_is_64bit(DumpState *s) return s->dump_info.d_class =3D=3D ELFCLASS64; } =20 +static inline bool dump_has_filter(DumpState *s) +{ + return s->filter_area_length > 0; +} + uint16_t cpu_to_dump16(DumpState *s, uint16_t val) { if (s->dump_info.d_endian =3D=3D ELFDATA2LSB) { @@ -443,29 +448,30 @@ static void get_offset_range(hwaddr phys_addr, *p_offset =3D -1; *p_filesz =3D 0; =20 - if (s->has_filter) { - if (phys_addr < s->begin || phys_addr >=3D s->begin + s->length) { + if (dump_has_filter(s)) { + if (phys_addr < s->filter_area_begin || + phys_addr >=3D s->filter_area_begin + s->filter_area_length) { return; } } =20 QTAILQ_FOREACH(block, &s->guest_phys_blocks.head, next) { - if (s->has_filter) { - if (block->target_start >=3D s->begin + s->length || - block->target_end <=3D s->begin) { + if (dump_has_filter(s)) { + if (block->target_start >=3D s->filter_area_begin + s->filter_= area_length || + block->target_end <=3D s->filter_area_begin) { /* This block is out of the range */ continue; } =20 - if (s->begin <=3D block->target_start) { + if (s->filter_area_begin <=3D block->target_start) { start =3D block->target_start; } else { - start =3D s->begin; + start =3D s->filter_area_begin; } =20 size_in_block =3D block->target_end - start; - if (s->begin + s->length < block->target_end) { - size_in_block -=3D block->target_end - (s->begin + s->leng= th); + if (s->filter_area_begin + s->filter_area_length < block->targ= et_end) { + size_in_block -=3D block->target_end - (s->filter_area_beg= in + s->filter_area_length); } } else { start =3D block->target_start; @@ -638,12 +644,12 @@ static void dump_iterate(DumpState *s, Error **errp) int64_t memblock_size, memblock_start; =20 QTAILQ_FOREACH(block, &s->guest_phys_blocks.head, next) { - memblock_start =3D dump_filtered_memblock_start(block, s->begin, s= ->length); + memblock_start =3D dump_filtered_memblock_start(block, s->filter_a= rea_begin, s->filter_area_length); if (memblock_start =3D=3D -1) { continue; } =20 - memblock_size =3D dump_filtered_memblock_size(block, s->begin, s->= length); + memblock_size =3D dump_filtered_memblock_size(block, s->filter_are= a_begin, s->filter_area_length); =20 /* Write the memory to file */ write_memory(s, block, memblock_start, memblock_size, errp); @@ -1504,14 +1510,14 @@ static int validate_start_block(DumpState *s) { GuestPhysBlock *block; =20 - if (!s->has_filter) { + if (!dump_has_filter(s)) { return 0; } =20 QTAILQ_FOREACH(block, &s->guest_phys_blocks.head, next) { /* This block is out of the range */ - if (block->target_start >=3D s->begin + s->length || - block->target_end <=3D s->begin) { + if (block->target_start >=3D s->filter_area_begin + s->filter_area= _length || + block->target_end <=3D s->filter_area_begin) { continue; } return 0; @@ -1550,10 +1556,10 @@ static int64_t dump_calculate_size(DumpState *s) int64_t size =3D 0, total =3D 0, left =3D 0, right =3D 0; =20 QTAILQ_FOREACH(block, &s->guest_phys_blocks.head, next) { - if (s->has_filter) { + if (dump_has_filter(s)) { /* calculate the overlapped region. */ - left =3D MAX(s->begin, block->target_start); - right =3D MIN(s->begin + s->length, block->target_end); + left =3D MAX(s->filter_area_begin, block->target_start); + right =3D MIN(s->filter_area_begin + s->filter_area_length, bl= ock->target_end); size =3D right - left; size =3D size > 0 ? size : 0; } else { @@ -1643,9 +1649,12 @@ static void dump_init(DumpState *s, int fd, bool has= _format, } =20 s->fd =3D fd; - s->has_filter =3D has_filter; - s->begin =3D begin; - s->length =3D length; + if (has_filter && !length) { + error_setg(errp, QERR_INVALID_PARAMETER, "length"); + goto cleanup; + } + s->filter_area_begin =3D begin; + s->filter_area_length =3D length; =20 memory_mapping_list_init(&s->list); =20 @@ -1778,8 +1787,8 @@ static void dump_init(DumpState *s, int fd, bool has_= format, return; } =20 - if (s->has_filter) { - memory_mapping_filter(&s->list, s->begin, s->length); + if (dump_has_filter(s)) { + memory_mapping_filter(&s->list, s->filter_area_begin, s->filter_ar= ea_length); } =20 /* --=20 2.37.3 From nobody Mon Feb 9 11:43:55 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1665075567; cv=none; d=zohomail.com; s=zohoarc; b=WYfD1oakKHAtbil1CigvGY5vkR9rYa19KdP4NuMUTYUNVnBIa/Q5AoQBAjYK+/nj6+D+JgbmXxkRHyr/pgsqW4Tc3y7UV77/uXINqCLMDGyax530ALfW62NxyfChu3AJ/GiVR39Zz0xFdMpRXcSP65xz6w3ncoRtDKEYcFRlVKU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665075567; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FvTigsGHy4bOPpaKG5ayhy8aiJm7kwertg4WzQRnVDU=; b=ViM8n58X2ncE0fJ4P7xIPYXLwEexF/ZCPI1jxHW8ikuGfbf8z3o37Xed9Dz+UmoxAhijt8t4dLPYBS0KvzUFW6GXigbEZ5x1rBPqY4G7ZJsZEel+4oZgyf+Tl9DbahlgqJPQ356zHk81pcFBK4yVBIaYkRtBZ+AVJGtV6CiLxBY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1665075567321988.4140928084137; Thu, 6 Oct 2022 09:59:27 -0700 (PDT) Received: from localhost ([::1]:52340 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ogUDW-0003s1-7D for importer@patchew.org; Thu, 06 Oct 2022 12:59:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43822) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ogStw-0003aG-SD for qemu-devel@nongnu.org; Thu, 06 Oct 2022 11:35:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:38304) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ogStt-0000OS-4X for qemu-devel@nongnu.org; Thu, 06 Oct 2022 11:35:07 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-145-4k0NM966PZuQ9TagpyIlLQ-1; Thu, 06 Oct 2022 11:35:01 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C3163185A7AB; Thu, 6 Oct 2022 15:35:00 +0000 (UTC) Received: from localhost (unknown [10.39.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id DE8DB2166B2E; Thu, 6 Oct 2022 15:34:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665070504; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FvTigsGHy4bOPpaKG5ayhy8aiJm7kwertg4WzQRnVDU=; b=A6cCMhoVVslMMfrBMO7bjjjFErmTMx002ZLff5rHHg16+O2Z7oSeFA3f/3A+Pca7+BKOne gormofZ6BcLqHOqyHyZSicLwCk3iTOViyjBdyEj7zBAZNjVnmqS97LEvm+dtETsklwg2tK ozZkpII8o6ZjL2MbdRJWuLK8Q6CkNnk= X-MC-Unique: 4k0NM966PZuQ9TagpyIlLQ-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Richard Henderson , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Bin Meng , Daniel Henrique Barboza , qemu-ppc@nongnu.org, qemu-s390x@nongnu.org, Alistair Francis , qemu-riscv@nongnu.org, Peter Maydell , viktor.prutyanov@redhat.com, Greg Kurz , frankja@linux.ibm.com, David Hildenbrand , Palmer Dabbelt , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson , qemu-arm@nongnu.org, Cornelia Huck , Thomas Huth Subject: [PULL 06/10] dump: Rework dump_calculate_size function Date: Thu, 6 Oct 2022 19:34:25 +0400 Message-Id: <20221006153430.2775580-7-marcandre.lureau@redhat.com> In-Reply-To: <20221006153430.2775580-1-marcandre.lureau@redhat.com> References: <20221006153430.2775580-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1665075569054100001 From: Janosch Frank dump_calculate_size() sums up all the sizes of the guest memory blocks. Since we already have a function that calculates the size of a single memory block (dump_get_memblock_size()) we can simply iterate over the blocks and use the function instead of calculating the size ourselves. Signed-off-by: Janosch Frank Reviewed-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Janis Schoetterl-Glausch Message-Id: <20220811121111.9878-7-frankja@linux.ibm.com> --- dump/dump.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/dump/dump.c b/dump/dump.c index b043337bc7..d82cc46d7d 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -1548,25 +1548,19 @@ bool qemu_system_dump_in_progress(void) return (qatomic_read(&state->status) =3D=3D DUMP_STATUS_ACTIVE); } =20 -/* calculate total size of memory to be dumped (taking filter into - * acoount.) */ +/* + * calculate total size of memory to be dumped (taking filter into + * account.) + */ static int64_t dump_calculate_size(DumpState *s) { GuestPhysBlock *block; - int64_t size =3D 0, total =3D 0, left =3D 0, right =3D 0; + int64_t total =3D 0; =20 QTAILQ_FOREACH(block, &s->guest_phys_blocks.head, next) { - if (dump_has_filter(s)) { - /* calculate the overlapped region. */ - left =3D MAX(s->filter_area_begin, block->target_start); - right =3D MIN(s->filter_area_begin + s->filter_area_length, bl= ock->target_end); - size =3D right - left; - size =3D size > 0 ? size : 0; - } else { - /* count the whole region in */ - size =3D (block->target_end - block->target_start); - } - total +=3D size; + total +=3D dump_filtered_memblock_size(block, + s->filter_area_begin, + s->filter_area_length); } =20 return total; --=20 2.37.3 From nobody Mon Feb 9 11:43:55 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1665076076; cv=none; d=zohomail.com; s=zohoarc; b=KmgbRpaHP0b0Axvpudd7a55vTLG8WX94EzFQk92mlAn+9Gi56M/a/H043N2tWvwRlXYmSZbit2eZNsqUdMoLFs7mlgCTdU6Z7BEM5HhoeLoM1uLu183XG4vljdKm6cSijI2VquAJuafsvlnKXa86VE6wGIHNEJ3uSjO8eL6VDbE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665076076; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dYjFVacFjH6LqJJ9EJvSjq1YMwNsnAVKlF4tFx1Ppyo=; b=S0EW9EklxB1fXlhuIVlOm3zVdPlu+S6RhJJrS+hZv70qWqd7EkpSN6k/GmRX9uNx1RFGeX1PR1BTMzaJ7n5bH5RWq08+7DEx0n+3oxood+FVFD0OmAH8/eMiNTrZizCeiWDoj3se/ls6DDs8oURX2Tjd6gwETUXE9LfTAocstjE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1665076076961175.2389132512959; Thu, 6 Oct 2022 10:07:56 -0700 (PDT) Received: from localhost ([::1]:48608 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ogULi-0001pi-DZ for importer@patchew.org; Thu, 06 Oct 2022 13:07:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34598) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ogSu4-0003cH-Mn for qemu-devel@nongnu.org; Thu, 06 Oct 2022 11:35:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:23873) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ogSty-0000Q7-Ez for qemu-devel@nongnu.org; Thu, 06 Oct 2022 11:35:13 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-350-2kTzssJPNbKu_7bUYId_Fw-1; Thu, 06 Oct 2022 11:35:06 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 46D5E3C10688; Thu, 6 Oct 2022 15:35:05 +0000 (UTC) Received: from localhost (unknown [10.39.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0D04B2166B2F; Thu, 6 Oct 2022 15:35:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665070509; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dYjFVacFjH6LqJJ9EJvSjq1YMwNsnAVKlF4tFx1Ppyo=; b=ZVwYvnoY7PvvYriEO5CHfzLqCZgxIW03vMVuOWcxuivl85e7Wa6CBQedq4pvawW/1oG+KW MCzD2fKyFWCbnPXAxzhyhlUJdqwNBNUF0Mf7klDGkjwelwLzz8rDZYjCLYa5L8/iLDLaez 5fnimOx3OMKyHrm1iMDZgtd4HfrHOR4= X-MC-Unique: 2kTzssJPNbKu_7bUYId_Fw-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Richard Henderson , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Bin Meng , Daniel Henrique Barboza , qemu-ppc@nongnu.org, qemu-s390x@nongnu.org, Alistair Francis , qemu-riscv@nongnu.org, Peter Maydell , viktor.prutyanov@redhat.com, Greg Kurz , frankja@linux.ibm.com, David Hildenbrand , Palmer Dabbelt , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson , qemu-arm@nongnu.org, Cornelia Huck , Thomas Huth Subject: [PULL 07/10] dump: Split elf header functions into prepare and write Date: Thu, 6 Oct 2022 19:34:26 +0400 Message-Id: <20221006153430.2775580-8-marcandre.lureau@redhat.com> In-Reply-To: <20221006153430.2775580-1-marcandre.lureau@redhat.com> References: <20221006153430.2775580-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1665076078316100001 From: Janosch Frank Let's split the write from the modification of the elf header so we can consolidate the write of the data in one function. Signed-off-by: Janosch Frank Reviewed-by: Janis Schoetterl-Glausch Reviewed-by: Marc-Andr=C3=A9 Lureau Message-Id: <20220811121111.9878-8-frankja@linux.ibm.com> --- dump/dump.c | 100 ++++++++++++++++++++++++++++------------------------ 1 file changed, 53 insertions(+), 47 deletions(-) diff --git a/dump/dump.c b/dump/dump.c index d82cc46d7d..8a2a97a85e 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -131,7 +131,7 @@ static int fd_write_vmcore(const void *buf, size_t size= , void *opaque) return 0; } =20 -static void write_elf64_header(DumpState *s, Error **errp) +static void prepare_elf64_header(DumpState *s, Elf64_Ehdr *elf_header) { /* * phnum in the elf header is 16 bit, if we have more segments we @@ -139,34 +139,27 @@ static void write_elf64_header(DumpState *s, Error **= errp) * special section. */ uint16_t phnum =3D MIN(s->phdr_num, PN_XNUM); - Elf64_Ehdr elf_header; - int ret; =20 - memset(&elf_header, 0, sizeof(Elf64_Ehdr)); - memcpy(&elf_header, ELFMAG, SELFMAG); - elf_header.e_ident[EI_CLASS] =3D ELFCLASS64; - elf_header.e_ident[EI_DATA] =3D s->dump_info.d_endian; - elf_header.e_ident[EI_VERSION] =3D EV_CURRENT; - elf_header.e_type =3D cpu_to_dump16(s, ET_CORE); - elf_header.e_machine =3D cpu_to_dump16(s, s->dump_info.d_machine); - elf_header.e_version =3D cpu_to_dump32(s, EV_CURRENT); - elf_header.e_ehsize =3D cpu_to_dump16(s, sizeof(elf_header)); - elf_header.e_phoff =3D cpu_to_dump64(s, s->phdr_offset); - elf_header.e_phentsize =3D cpu_to_dump16(s, sizeof(Elf64_Phdr)); - elf_header.e_phnum =3D cpu_to_dump16(s, phnum); + memset(elf_header, 0, sizeof(Elf64_Ehdr)); + memcpy(elf_header, ELFMAG, SELFMAG); + elf_header->e_ident[EI_CLASS] =3D ELFCLASS64; + elf_header->e_ident[EI_DATA] =3D s->dump_info.d_endian; + elf_header->e_ident[EI_VERSION] =3D EV_CURRENT; + elf_header->e_type =3D cpu_to_dump16(s, ET_CORE); + elf_header->e_machine =3D cpu_to_dump16(s, s->dump_info.d_machine); + elf_header->e_version =3D cpu_to_dump32(s, EV_CURRENT); + elf_header->e_ehsize =3D cpu_to_dump16(s, sizeof(elf_header)); + elf_header->e_phoff =3D cpu_to_dump64(s, s->phdr_offset); + elf_header->e_phentsize =3D cpu_to_dump16(s, sizeof(Elf64_Phdr)); + elf_header->e_phnum =3D cpu_to_dump16(s, phnum); if (s->shdr_num) { - elf_header.e_shoff =3D cpu_to_dump64(s, s->shdr_offset); - elf_header.e_shentsize =3D cpu_to_dump16(s, sizeof(Elf64_Shdr)); - elf_header.e_shnum =3D cpu_to_dump16(s, s->shdr_num); - } - - ret =3D fd_write_vmcore(&elf_header, sizeof(elf_header), s); - if (ret < 0) { - error_setg_errno(errp, -ret, "dump: failed to write elf header"); + elf_header->e_shoff =3D cpu_to_dump64(s, s->shdr_offset); + elf_header->e_shentsize =3D cpu_to_dump16(s, sizeof(Elf64_Shdr)); + elf_header->e_shnum =3D cpu_to_dump16(s, s->shdr_num); } } =20 -static void write_elf32_header(DumpState *s, Error **errp) +static void prepare_elf32_header(DumpState *s, Elf32_Ehdr *elf_header) { /* * phnum in the elf header is 16 bit, if we have more segments we @@ -174,28 +167,45 @@ static void write_elf32_header(DumpState *s, Error **= errp) * special section. */ uint16_t phnum =3D MIN(s->phdr_num, PN_XNUM); - Elf32_Ehdr elf_header; - int ret; =20 - memset(&elf_header, 0, sizeof(Elf32_Ehdr)); - memcpy(&elf_header, ELFMAG, SELFMAG); - elf_header.e_ident[EI_CLASS] =3D ELFCLASS32; - elf_header.e_ident[EI_DATA] =3D s->dump_info.d_endian; - elf_header.e_ident[EI_VERSION] =3D EV_CURRENT; - elf_header.e_type =3D cpu_to_dump16(s, ET_CORE); - elf_header.e_machine =3D cpu_to_dump16(s, s->dump_info.d_machine); - elf_header.e_version =3D cpu_to_dump32(s, EV_CURRENT); - elf_header.e_ehsize =3D cpu_to_dump16(s, sizeof(elf_header)); - elf_header.e_phoff =3D cpu_to_dump32(s, s->phdr_offset); - elf_header.e_phentsize =3D cpu_to_dump16(s, sizeof(Elf32_Phdr)); - elf_header.e_phnum =3D cpu_to_dump16(s, phnum); + memset(elf_header, 0, sizeof(Elf32_Ehdr)); + memcpy(elf_header, ELFMAG, SELFMAG); + elf_header->e_ident[EI_CLASS] =3D ELFCLASS32; + elf_header->e_ident[EI_DATA] =3D s->dump_info.d_endian; + elf_header->e_ident[EI_VERSION] =3D EV_CURRENT; + elf_header->e_type =3D cpu_to_dump16(s, ET_CORE); + elf_header->e_machine =3D cpu_to_dump16(s, s->dump_info.d_machine); + elf_header->e_version =3D cpu_to_dump32(s, EV_CURRENT); + elf_header->e_ehsize =3D cpu_to_dump16(s, sizeof(elf_header)); + elf_header->e_phoff =3D cpu_to_dump32(s, s->phdr_offset); + elf_header->e_phentsize =3D cpu_to_dump16(s, sizeof(Elf32_Phdr)); + elf_header->e_phnum =3D cpu_to_dump16(s, phnum); if (s->shdr_num) { - elf_header.e_shoff =3D cpu_to_dump32(s, s->shdr_offset); - elf_header.e_shentsize =3D cpu_to_dump16(s, sizeof(Elf32_Shdr)); - elf_header.e_shnum =3D cpu_to_dump16(s, s->shdr_num); + elf_header->e_shoff =3D cpu_to_dump32(s, s->shdr_offset); + elf_header->e_shentsize =3D cpu_to_dump16(s, sizeof(Elf32_Shdr)); + elf_header->e_shnum =3D cpu_to_dump16(s, s->shdr_num); } +} =20 - ret =3D fd_write_vmcore(&elf_header, sizeof(elf_header), s); +static void write_elf_header(DumpState *s, Error **errp) +{ + Elf32_Ehdr elf32_header; + Elf64_Ehdr elf64_header; + size_t header_size; + void *header_ptr; + int ret; + + if (dump_is_64bit(s)) { + prepare_elf64_header(s, &elf64_header); + header_size =3D sizeof(elf64_header); + header_ptr =3D &elf64_header; + } else { + prepare_elf32_header(s, &elf32_header); + header_size =3D sizeof(elf32_header); + header_ptr =3D &elf32_header; + } + + ret =3D fd_write_vmcore(header_ptr, header_size, s); if (ret < 0) { error_setg_errno(errp, -ret, "dump: failed to write elf header"); } @@ -564,11 +574,7 @@ static void dump_begin(DumpState *s, Error **errp) */ =20 /* write elf header to vmcore */ - if (dump_is_64bit(s)) { - write_elf64_header(s, errp); - } else { - write_elf32_header(s, errp); - } + write_elf_header(s, errp); if (*errp) { return; } --=20 2.37.3 From nobody Mon Feb 9 11:43:55 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1665075430; cv=none; d=zohomail.com; s=zohoarc; b=n0nMZp2aYJ6Agh3Z7CIALAR1rH+je3Elq9Mcjo2yN6ZkAtuheDS67cYctGxKsckSF8Fc8ETZjnGrG08NjHi2X38JM0ld7VrddI+DYuGFJ5OGZyUKYRDQSuekjN0Bt5NSaSa/0QzXuIyaxfnq30DFkpp4EWgw9GEEllaWLig36P0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665075430; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QODbEEu/ErPvK0BeyIXd5lDo4uskdjchNK/jc3WZeCQ=; b=Hb9pvAogNN4Uodtk8HGIcCVxN6YL6fL8OybkecUeUqqi8kUlGr6m6z3r4+WjCq5WxO+/9V4o9P7mJLPdZvOFbEjUgSaVxE/ea2yGIjVjq5xtSS5AdQdzCxmJ4/uU+5TX21XVNRFG3qOWWwPArMtF8V0Y0zDR7WAlkj87U/xNJfw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1665075430682209.7921735650326; Thu, 6 Oct 2022 09:57:10 -0700 (PDT) Received: from localhost ([::1]:52390 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ogUBJ-0008GH-NJ for importer@patchew.org; Thu, 06 Oct 2022 12:57:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37332) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ogSuG-0003jU-2i for qemu-devel@nongnu.org; Thu, 06 Oct 2022 11:35:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:50297) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ogSuB-0000TS-WC for qemu-devel@nongnu.org; Thu, 06 Oct 2022 11:35:26 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-664-SrWhGXO_PtyefPEzFciL9w-1; Thu, 06 Oct 2022 11:35:17 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EE77E29324A0; Thu, 6 Oct 2022 15:35:16 +0000 (UTC) Received: from localhost (unknown [10.39.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id D9B534EA5D; Thu, 6 Oct 2022 15:35:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665070521; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QODbEEu/ErPvK0BeyIXd5lDo4uskdjchNK/jc3WZeCQ=; b=RAWQWbuZIZOjr+z979gs9gJ0f1lcwU/Krt5QXygmJ6mgYt7Ic7IZ/aSi/crbpr1rBUt0dS q/WUXG318D1bYwkCbE6Tgy1ZLjNfAOJShRk/XOy8kJQVeTVNOOwns1czW5EhIUjzRKrNdL djQcNS+wsyc3xnA6Jd/k+pJluzXHO5s= X-MC-Unique: SrWhGXO_PtyefPEzFciL9w-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Richard Henderson , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Bin Meng , Daniel Henrique Barboza , qemu-ppc@nongnu.org, qemu-s390x@nongnu.org, Alistair Francis , qemu-riscv@nongnu.org, Peter Maydell , viktor.prutyanov@redhat.com, Greg Kurz , frankja@linux.ibm.com, David Hildenbrand , Palmer Dabbelt , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson , qemu-arm@nongnu.org, Cornelia Huck , Thomas Huth Subject: [PULL 08/10] dump: Rename write_elf*_phdr_note to prepare_elf*_phdr_note Date: Thu, 6 Oct 2022 19:34:27 +0400 Message-Id: <20221006153430.2775580-9-marcandre.lureau@redhat.com> In-Reply-To: <20221006153430.2775580-1-marcandre.lureau@redhat.com> References: <20221006153430.2775580-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1665075431487100001 From: Janosch Frank The functions in question do not actually write to the file descriptor they set up a buffer which is later written to the fd. Signed-off-by: Janosch Frank Reviewed-by: Janis Schoetterl-Glausch Reviewed-by: Marc-Andr=C3=A9 Lureau Message-Id: <20220811121111.9878-9-frankja@linux.ibm.com> --- dump/dump.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dump/dump.c b/dump/dump.c index 8a2a97a85e..a905316fe5 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -260,7 +260,7 @@ static void write_elf32_load(DumpState *s, MemoryMappin= g *memory_mapping, } } =20 -static void write_elf64_phdr_note(DumpState *s, Elf64_Phdr *phdr) +static void prepare_elf64_phdr_note(DumpState *s, Elf64_Phdr *phdr) { memset(phdr, 0, sizeof(*phdr)); phdr->p_type =3D cpu_to_dump32(s, PT_NOTE); @@ -316,7 +316,7 @@ static void write_elf64_notes(WriteCoreDumpFunction f, = DumpState *s, write_guest_note(f, s, errp); } =20 -static void write_elf32_phdr_note(DumpState *s, Elf32_Phdr *phdr) +static void prepare_elf32_phdr_note(DumpState *s, Elf32_Phdr *phdr) { memset(phdr, 0, sizeof(*phdr)); phdr->p_type =3D cpu_to_dump32(s, PT_NOTE); @@ -364,11 +364,11 @@ static void write_elf_phdr_note(DumpState *s, Error *= *errp) int ret; =20 if (dump_is_64bit(s)) { - write_elf64_phdr_note(s, &phdr64); + prepare_elf64_phdr_note(s, &phdr64); size =3D sizeof(phdr64); phdr =3D &phdr64; } else { - write_elf32_phdr_note(s, &phdr32); + prepare_elf32_phdr_note(s, &phdr32); size =3D sizeof(phdr32); phdr =3D &phdr32; } --=20 2.37.3 From nobody Mon Feb 9 11:43:55 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1665076577; cv=none; d=zohomail.com; s=zohoarc; b=YwfFe6HUqJ88ClSOn/6LBJnZKONPKbeibhBlUdI8UnR5jf+4r/w84qZWnQ/RIG3bXayZIGbyPMch6HODyb7M6+jKqrUPMvrY7Hl3y2KUScsGXNNkRrIHHyo6dUr0rWns+nbw7Dm96q/uSg07WCLAzr/9q7oSPQnk91fwYu17GxQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665076577; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FsCG6Vbibx8F7grXqAa/TVuItjcWBuxcPHcrTOOH5pA=; b=i1qKJVReivTzBhsmsji2QzPSUvN2xkHPUL7q9ojkHC1FPPUns1E2w88wo22/P7aCBwIHAMXwWRVCqOcEQTtducQ8hWWPz6Q5Q3brRepo+Y4KzRn1LllwXe5BVPg0S4G6lb6emiLT15rLFcFpEKROEgA2NCGr2iDXcwMGrSamdvY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1665076577834396.01459618293984; Thu, 6 Oct 2022 10:16:17 -0700 (PDT) Received: from localhost ([::1]:43100 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ogUTo-0005UD-JJ for importer@patchew.org; Thu, 06 Oct 2022 13:16:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37340) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ogSuH-0003kP-Rb for qemu-devel@nongnu.org; Thu, 06 Oct 2022 11:35:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:21448) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ogSuF-0000Ts-Nl for qemu-devel@nongnu.org; Thu, 06 Oct 2022 11:35:29 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-93-wPXw8IouNR-5rudImpeRFw-1; Thu, 06 Oct 2022 11:35:21 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DD00A85A59D; Thu, 6 Oct 2022 15:35:20 +0000 (UTC) Received: from localhost (unknown [10.39.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1E7DA40EFB2B; Thu, 6 Oct 2022 15:35:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665070525; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FsCG6Vbibx8F7grXqAa/TVuItjcWBuxcPHcrTOOH5pA=; b=TzTeBt4pBEsMeyIbRVpFTItkTbvBawMtxlAImenBI6yiPfA/5qe5/byBJ1WvxIWUXIp00/ 2km4SGhnl5XPGF91+at5hje6QYd1nBOFeT3u+L9zGMr/XpzD7tjltjF70mkNddp2/68w9G DvJKt0o2k/yLayP8VnV2glQTbA5SqSE= X-MC-Unique: wPXw8IouNR-5rudImpeRFw-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Richard Henderson , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Bin Meng , Daniel Henrique Barboza , qemu-ppc@nongnu.org, qemu-s390x@nongnu.org, Alistair Francis , qemu-riscv@nongnu.org, Peter Maydell , viktor.prutyanov@redhat.com, Greg Kurz , frankja@linux.ibm.com, David Hildenbrand , Palmer Dabbelt , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson , qemu-arm@nongnu.org, Cornelia Huck , Thomas Huth Subject: [PULL 09/10] dump: simplify a bit kdump get_next_page() Date: Thu, 6 Oct 2022 19:34:28 +0400 Message-Id: <20221006153430.2775580-10-marcandre.lureau@redhat.com> In-Reply-To: <20221006153430.2775580-1-marcandre.lureau@redhat.com> References: <20221006153430.2775580-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1665076578655100001 From: Marc-Andr=C3=A9 Lureau This should be functionally equivalent, but slightly easier to read, with simplified paths and checks at the end of the function. The following patch is a major rewrite to get rid of the assert(). Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: David Hildenbrand --- dump/dump.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/dump/dump.c b/dump/dump.c index a905316fe5..b55a497c42 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -1132,17 +1132,11 @@ static bool get_next_page(GuestPhysBlock **blockptr= , uint64_t *pfnptr, if (!block) { block =3D QTAILQ_FIRST(&s->guest_phys_blocks.head); *blockptr =3D block; - assert((block->target_start & ~target_page_mask) =3D=3D 0); - assert((block->target_end & ~target_page_mask) =3D=3D 0); - *pfnptr =3D dump_paddr_to_pfn(s, block->target_start); - if (bufptr) { - *bufptr =3D block->host_addr; - } - return true; + addr =3D block->target_start; + } else { + addr =3D dump_pfn_to_paddr(s, *pfnptr + 1); } - - *pfnptr =3D *pfnptr + 1; - addr =3D dump_pfn_to_paddr(s, *pfnptr); + assert(block !=3D NULL); =20 if ((addr >=3D block->target_start) && (addr + s->dump_info.page_size <=3D block->target_end)) { @@ -1154,12 +1148,13 @@ static bool get_next_page(GuestPhysBlock **blockptr= , uint64_t *pfnptr, if (!block) { return false; } - assert((block->target_start & ~target_page_mask) =3D=3D 0); - assert((block->target_end & ~target_page_mask) =3D=3D 0); - *pfnptr =3D dump_paddr_to_pfn(s, block->target_start); + addr =3D block->target_start; buf =3D block->host_addr; } =20 + assert((block->target_start & ~target_page_mask) =3D=3D 0); + assert((block->target_end & ~target_page_mask) =3D=3D 0); + *pfnptr =3D dump_paddr_to_pfn(s, addr); if (bufptr) { *bufptr =3D buf; } --=20 2.37.3 From nobody Mon Feb 9 11:43:55 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1665076345; cv=none; d=zohomail.com; s=zohoarc; b=Cnvdy3VruC/5lYDjSs8q3BnDz+nP83dkm3pIilindYEo5RTSGCbsi35V5u401DgKwjQyPUHJ4NRws97Drs5pB+SMeoG06GvkMpGx0XyoTmUQBVyx1k2/K1Nsq3RfgX82u9gukobqyfW6WFqxagn3FKfevZmfvS0ArSzWsulbxV4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665076345; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=I4h7vyx8d98MGbRX6SH6EZkNtqsv47ZRB8QWMoS6Bts=; b=oCVDsP5SO/SMGldGhQc2hU2ZTMWAgGrreOR+ybgpsY9Bpe+iZoFcCkjd25IYJ1wWaVtrCDTmvAIU7NqpDQg88N0IsQKeM4Me5WWFM419/oV9WPPb2+a6ZTf6zkRGIRKLjoxwHkvZG0je/rcMaoV0moEFqombGWIGicQlivsRJ+o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1665076345618771.072620898833; Thu, 6 Oct 2022 10:12:25 -0700 (PDT) Received: from localhost ([::1]:38738 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ogUQ1-0008Or-Fi for importer@patchew.org; Thu, 06 Oct 2022 13:12:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37346) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ogSuK-0003nJ-Up for qemu-devel@nongnu.org; Thu, 06 Oct 2022 11:35:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:29832) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ogSuJ-0000VA-0N for qemu-devel@nongnu.org; Thu, 06 Oct 2022 11:35:32 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-263-hAGTyLvDOj-3i5KL5O_Swg-1; Thu, 06 Oct 2022 11:35:26 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1529A101E14E; Thu, 6 Oct 2022 15:35:25 +0000 (UTC) Received: from localhost (unknown [10.39.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE6462166B2E; Thu, 6 Oct 2022 15:35:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665070529; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=I4h7vyx8d98MGbRX6SH6EZkNtqsv47ZRB8QWMoS6Bts=; b=aVztQq6gxGalwxGtt/qYZTBv8yl8HdC1tFfRvaOvZ557bUOJgvDZAP0e2l23ZxE6FXFNjA 9MgAMynjnlul/dFxuJZxqf4vugiRBvrJgIOjiUnyDZqNOJ7Dg6Iag/4yponm4tHt2YIhxY iERtqzC8ZP7sJm5wteUprR5LRYZDlhE= X-MC-Unique: hAGTyLvDOj-3i5KL5O_Swg-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Richard Henderson , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Bin Meng , Daniel Henrique Barboza , qemu-ppc@nongnu.org, qemu-s390x@nongnu.org, Alistair Francis , qemu-riscv@nongnu.org, Peter Maydell , viktor.prutyanov@redhat.com, Greg Kurz , frankja@linux.ibm.com, David Hildenbrand , Palmer Dabbelt , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson , qemu-arm@nongnu.org, Cornelia Huck , Thomas Huth Subject: [PULL 10/10] dump: fix kdump to work over non-aligned blocks Date: Thu, 6 Oct 2022 19:34:29 +0400 Message-Id: <20221006153430.2775580-11-marcandre.lureau@redhat.com> In-Reply-To: <20221006153430.2775580-1-marcandre.lureau@redhat.com> References: <20221006153430.2775580-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1665076346913100001 From: Marc-Andr=C3=A9 Lureau Rewrite get_next_page() to work over non-aligned blocks. When it encounters non aligned addresses, it will try to fill a page provided by the caller. This solves a kdump crash with "tpm-crb-cmd" RAM memory region, qemu-kvm: ../dump/dump.c:1162: _Bool get_next_page(GuestPhysBlock **, uint64_t *, uint8_t **, DumpState *): Assertion `(block->target_start & ~target_page_mask) =3D=3D 0' failed. because: guest_phys_block_add_section: target_start=3D00000000fed40080 target_end=3D= 00000000fed41000: added (count: 4) Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=3D2120480 Signed-off-by: Marc-Andr=C3=A9 Lureau Acked-by: David Hildenbrand --- dump/dump.c | 79 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 56 insertions(+), 23 deletions(-) diff --git a/dump/dump.c b/dump/dump.c index b55a497c42..236559b03a 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -1116,50 +1116,81 @@ static uint64_t dump_pfn_to_paddr(DumpState *s, uin= t64_t pfn) } =20 /* - * exam every page and return the page frame number and the address of the= page. - * bufptr can be NULL. note: the blocks here is supposed to reflect guest-= phys - * blocks, so block->target_start and block->target_end should be interal - * multiples of the target page size. + * Return the page frame number and the page content in *bufptr. bufptr ca= n be + * NULL. If not NULL, *bufptr must contains a target page size of pre-allo= cated + * memory. This is not necessarily the memory returned. */ static bool get_next_page(GuestPhysBlock **blockptr, uint64_t *pfnptr, uint8_t **bufptr, DumpState *s) { GuestPhysBlock *block =3D *blockptr; - hwaddr addr, target_page_mask =3D ~((hwaddr)s->dump_info.page_size - 1= ); - uint8_t *buf; + uint32_t page_size =3D s->dump_info.page_size; + uint8_t *buf =3D NULL, *hbuf; + hwaddr addr; =20 /* block =3D=3D NULL means the start of the iteration */ if (!block) { block =3D QTAILQ_FIRST(&s->guest_phys_blocks.head); *blockptr =3D block; addr =3D block->target_start; + *pfnptr =3D dump_paddr_to_pfn(s, addr); } else { - addr =3D dump_pfn_to_paddr(s, *pfnptr + 1); + *pfnptr +=3D 1; + addr =3D dump_pfn_to_paddr(s, *pfnptr); } assert(block !=3D NULL); =20 - if ((addr >=3D block->target_start) && - (addr + s->dump_info.page_size <=3D block->target_end)) { - buf =3D block->host_addr + (addr - block->target_start); - } else { - /* the next page is in the next block */ - block =3D QTAILQ_NEXT(block, next); - *blockptr =3D block; - if (!block) { - return false; + while (1) { + if (addr >=3D block->target_start && addr < block->target_end) { + size_t n =3D MIN(block->target_end - addr, page_size - addr % = page_size); + hbuf =3D block->host_addr + (addr - block->target_start); + if (!buf) { + if (n =3D=3D page_size) { + /* this is a whole target page, go for it */ + assert(addr % page_size =3D=3D 0); + buf =3D hbuf; + break; + } else if (bufptr) { + assert(*bufptr); + buf =3D *bufptr; + memset(buf, 0, page_size); + } else { + return true; + } + } + + memcpy(buf + addr % page_size, hbuf, n); + addr +=3D n; + if (addr % page_size =3D=3D 0) { + /* we filled up the page */ + break; + } + } else { + /* the next page is in the next block */ + *blockptr =3D block =3D QTAILQ_NEXT(block, next); + if (!block) { + break; + } + + addr =3D block->target_start; + /* are we still in the same page? */ + if (dump_paddr_to_pfn(s, addr) !=3D *pfnptr) { + if (buf) { + /* no, but we already filled something earlier, return= it */ + break; + } else { + /* else continue from there */ + *pfnptr =3D dump_paddr_to_pfn(s, addr); + } + } } - addr =3D block->target_start; - buf =3D block->host_addr; } =20 - assert((block->target_start & ~target_page_mask) =3D=3D 0); - assert((block->target_end & ~target_page_mask) =3D=3D 0); - *pfnptr =3D dump_paddr_to_pfn(s, addr); if (bufptr) { *bufptr =3D buf; } =20 - return true; + return buf !=3D NULL; } =20 static void write_dump_bitmap(DumpState *s, Error **errp) @@ -1297,6 +1328,7 @@ static void write_dump_pages(DumpState *s, Error **er= rp) uint8_t *buf; GuestPhysBlock *block_iter =3D NULL; uint64_t pfn_iter; + g_autofree uint8_t *page =3D NULL; =20 /* get offset of page_desc and page_data in dump file */ offset_desc =3D s->offset_page; @@ -1332,12 +1364,13 @@ static void write_dump_pages(DumpState *s, Error **= errp) } =20 offset_data +=3D s->dump_info.page_size; + page =3D g_malloc(s->dump_info.page_size); =20 /* * dump memory to vmcore page by page. zero page will all be resided i= n the * first page of page section */ - while (get_next_page(&block_iter, &pfn_iter, &buf, s)) { + for (buf =3D page; get_next_page(&block_iter, &pfn_iter, &buf, s); buf= =3D page) { /* check zero page */ if (buffer_is_zero(buf, s->dump_info.page_size)) { ret =3D write_cache(&page_desc, &pd_zero, sizeof(PageDescripto= r), --=20 2.37.3