qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kurz <groug@kaod.org>
To: Laurent Vivier <lvivier@redhat.com>
Cc: qemu-devel@nongnu.org, Peter Maydell <peter.maydell@linaro.org>,
	Thomas Huth <thuth@redhat.com>,
	"Daniel P . Berrange" <berrange@redhat.com>,
	Cornelia Huck <cohuck@redhat.com>,
	"Dr . David Alan Gilbert" <dgilbert@redhat.com>,
	qemu-arm@nongnu.org, qemu-ppc@nongnu.org,
	David Gibson <david@gibson.dropbear.id.au>
Subject: Re: [Qemu-devel] [Qemu-ppc] [PATCH v2 2/3] hmp: fix "dump-quest-memory" segfault (arm)
Date: Mon, 11 Sep 2017 17:38:25 +0200	[thread overview]
Message-ID: <20170911173825.0a4bd1a3@bahia.lan> (raw)
In-Reply-To: <5b7621f0-072f-9bf0-c4bb-23f85a8faaec@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 4482 bytes --]

On Mon, 11 Sep 2017 17:25:23 +0200
Laurent Vivier <lvivier@redhat.com> wrote:

> On 11/09/2017 17:08, Greg Kurz wrote:
> > On Mon, 11 Sep 2017 16:20:55 +0200
> > Laurent Vivier <lvivier@redhat.com> wrote:
> >   
> >> Commit fd5d23babf (hmp: fix "dump-quest-memory" segfault)
> >> fixes the problem for i386, do the same for arm.
> >>
> >> Running QEMU with
> >>     qemu-system-aarch64 -M none -nographic -m 256
> >> and executing
> >>     dump-guest-memory /dev/null 0 8192
> >> results in segfault
> >>
> >> Fix by checking if we have CPU.
> >>
> >> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
> >> ---
> >>  target/arm/arch_dump.c | 52 +++++++++++++++++++++++++++++++++-----------------
> >>  1 file changed, 34 insertions(+), 18 deletions(-)
> >>
> >> diff --git a/target/arm/arch_dump.c b/target/arm/arch_dump.c
> >> index 1a9861f69b..1f58cff256 100644
> >> --- a/target/arm/arch_dump.c
> >> +++ b/target/arm/arch_dump.c
> >> @@ -273,8 +273,6 @@ int arm_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs,
> >>  int cpu_get_dump_info(ArchDumpInfo *info,
> >>                        const GuestPhysBlockList *guest_phys_blocks)
> >>  {
> >> -    ARMCPU *cpu = ARM_CPU(first_cpu);
> >> -    CPUARMState *env = &cpu->env;
> >>      GuestPhysBlock *block;
> >>      hwaddr lowest_addr = ULLONG_MAX;
> >>  
> >> @@ -290,13 +288,32 @@ int cpu_get_dump_info(ArchDumpInfo *info,
> >>          }
> >>      }
> >>  
> >> -    if (arm_feature(env, ARM_FEATURE_AARCH64)) {
> >> -        info->d_machine = EM_AARCH64;
> >> -        info->d_class = ELFCLASS64;
> >> -        info->page_size = (1 << 16); /* aarch64 max pagesize */
> >> -        if (lowest_addr != ULLONG_MAX) {
> >> -            info->phys_base = lowest_addr;
> >> +    if (first_cpu) {
> >> +        ARMCPU *cpu = ARM_CPU(first_cpu);
> >> +        CPUARMState *env = &cpu->env;
> >> +        if (arm_feature(env, ARM_FEATURE_AARCH64)) {
> >> +            info->d_machine = EM_AARCH64;
> >> +            info->d_class = ELFCLASS64;
> >> +            info->page_size = (1 << 16); /* aarch64 max pagesize */
> >> +            if (lowest_addr != ULLONG_MAX) {
> >> +                info->phys_base = lowest_addr;
> >> +            }
> >> +        } else {
> >> +            info->d_machine = EM_ARM;
> >> +            info->d_class = ELFCLASS32;
> >> +            info->page_size = (1 << 12);
> >> +            if (lowest_addr < UINT_MAX) {
> >> +                info->phys_base = lowest_addr;
> >> +            }
> >>          }
> >> +
> >> +        /* We assume the relevant endianness is that of EL1; this is right
> >> +         * for kernels, but might give the wrong answer if you're trying to
> >> +         * dump a hypervisor that happens to be running an opposite-endian
> >> +         * kernel.
> >> +         */
> >> +        info->d_endian = (env->cp15.sctlr_el[1] & SCTLR_EE) != 0
> >> +                         ? ELFDATA2MSB : ELFDATA2LSB;
> >>      } else {
> >>          info->d_machine = EM_ARM;
> >>          info->d_class = ELFCLASS32;
> >> @@ -304,25 +321,24 @@ int cpu_get_dump_info(ArchDumpInfo *info,
> >>          if (lowest_addr < UINT_MAX) {
> >>              info->phys_base = lowest_addr;
> >>          }
> >> +        info->d_endian = ELFDATA2LSB;
> >>      }
> >>  
> >> -    /* We assume the relevant endianness is that of EL1; this is right
> >> -     * for kernels, but might give the wrong answer if you're trying to
> >> -     * dump a hypervisor that happens to be running an opposite-endian
> >> -     * kernel.
> >> -     */
> >> -    info->d_endian = (env->cp15.sctlr_el[1] & SCTLR_EE) != 0
> >> -                     ? ELFDATA2MSB : ELFDATA2LSB;
> >> -
> >>      return 0;
> >>  }
> >>  
> >>  ssize_t cpu_get_note_size(int class, int machine, int nr_cpus)
> >>  {
> >> -    ARMCPU *cpu = ARM_CPU(first_cpu);
> >> -    CPUARMState *env = &cpu->env;
> >> +    ARMCPU *cpu;
> >> +    CPUARMState *env;
> >>      size_t note_size;
> >>  
> >> +    if (first_cpu == NULL) {
> >> +        return 0;
> >> +    }
> >> +  
> > 
> > Looking at the function's code, it seems that env is only needed if
> > class != ELFCLASS64... I guess that all the code dealing with first_cpu
> > should go to the else block.  
> 
> if first_cpu is NULL, nr_cpus is 0 and the function always returns 0.
> 

True.

Reviewed-by: Greg Kurz <groug@kaod.org>

> Thanks,
> Laurent


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

  reply	other threads:[~2017-09-11 15:38 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-11 14:20 [Qemu-devel] [PATCH v2 0/3] hmp: fix "dump-quest-memory" segfault Laurent Vivier
2017-09-11 14:20 ` [Qemu-devel] [PATCH v2 1/3] hmp: fix "dump-quest-memory" segfault (ppc) Laurent Vivier
2017-09-11 14:20 ` [Qemu-devel] [PATCH v2 2/3] hmp: fix "dump-quest-memory" segfault (arm) Laurent Vivier
2017-09-11 14:39   ` Peter Maydell
2017-09-11 14:45     ` Thomas Huth
2017-09-11 16:40       ` Peter Maydell
2017-09-11 17:06         ` Thomas Huth
2017-09-12  8:11         ` Laurent Vivier
2017-09-11 15:35     ` Laurent Vivier
2017-09-11 15:08   ` [Qemu-devel] [Qemu-ppc] " Greg Kurz
2017-09-11 15:25     ` Laurent Vivier
2017-09-11 15:38       ` Greg Kurz [this message]
2017-09-11 14:20 ` [Qemu-devel] [PATCH v2 3/3] tests/hmp: test "none" machine with memory Laurent Vivier
2017-09-11 14:51   ` Thomas Huth
2017-09-11 15:39     ` Laurent Vivier
2017-09-12 12:15   ` [Qemu-devel] [Qemu-arm] " Philippe Mathieu-Daudé
2017-09-11 14:34 ` [Qemu-devel] [PATCH v2 0/3] hmp: fix "dump-quest-memory" segfault no-reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170911173825.0a4bd1a3@bahia.lan \
    --to=groug@kaod.org \
    --cc=berrange@redhat.com \
    --cc=cohuck@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=dgilbert@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).