All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Andreas Färber" <afaerber@suse.de>
To: Luiz Capitulino <lcapitulino@redhat.com>
Cc: pbonzini@redhat.com, qiaonuohan@cn.fujitsu.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH qom-cpu v3 9/9] memory_mapping: Change qemu_get_guest_memory_mapping() semantics
Date: Wed, 05 Jun 2013 15:48:52 +0200	[thread overview]
Message-ID: <51AF41C4.8030408@suse.de> (raw)
In-Reply-To: <20130531101405.4605417e@redhat.com>

Am 31.05.2013 16:14, schrieb Luiz Capitulino:
> On Thu, 30 May 2013 17:08:01 +0200
> Andreas Färber <afaerber@suse.de> wrote:
> 
>> Previously it would search for the first CPU with paging enabled and
>> retrieve memory mappings from this and any following CPUs or return an
>> error if that fails.
>>
>> Instead walk all CPUs and if paging is enabled retrieve the memory
>> mappings. Fail only if retrieving memory mappings on a CPU with paging
>> enabled fails.
>>
>> This not only allows to more easily use one qemu_for_each_cpu() instead
>> of open-coding two CPU loops and drops find_first_paging_enabled_cpu()
>> but removes the implicit assumption of heterogeneity between CPUs n..N
>> in having paging enabled.
>>
>> Cc: Wen Congyang <wency@cn.fujitsu.com>
>> Signed-off-by: Andreas Färber <afaerber@suse.de>
>> ---
>>  memory_mapping.c | 42 +++++++++++++++++++++++-------------------
>>  1 file changed, 23 insertions(+), 19 deletions(-)
>>
>> diff --git a/memory_mapping.c b/memory_mapping.c
>> index 481530a..55ac2b8 100644
>> --- a/memory_mapping.c
>> +++ b/memory_mapping.c
>> @@ -165,35 +165,39 @@ void memory_mapping_list_init(MemoryMappingList *list)
>>      QTAILQ_INIT(&list->head);
>>  }
>>  
>> -static CPUArchState *find_paging_enabled_cpu(CPUArchState *start_cpu)
>> +typedef struct GetGuestMemoryMappingData {
>> +    MemoryMappingList *list;
>> +    int ret;
>> +} GetGuestMemoryMappingData;
>> +
>> +static void qemu_get_one_guest_memory_mapping(CPUState *cpu, void *data)
>>  {
>> -    CPUArchState *env;
>> +    GetGuestMemoryMappingData *s = data;
>> +    int ret;
>>  
>> -    for (env = start_cpu; env != NULL; env = env->next_cpu) {
>> -        if (cpu_paging_enabled(ENV_GET_CPU(env))) {
>> -            return env;
>> -        }
>> +    if (!cpu_paging_enabled(cpu) || s->ret == -1) {
>> +        return;
>> +    }
>> +    ret = cpu_get_memory_mapping(cpu, s->list);
>> +    if (ret < 0) {
>> +        s->ret = -1;
>> +    } else {
>> +        s->ret = 0;
>>      }
> 
> Does cpu_get_memory_mapping() ever return a positive value or a negative
> value != -1 ?
> 
> It it doesn't, I'd do:
> 
> s->ret = cpu_get_memory_mapping();
> assert(s->ret == 0 || s->ret == -1);

This no longer applies after returning an Error* from
cpu_get_memory_mapping() instead. :)

> 
>> -
>> -    return NULL;
>>  }
>>  
>>  int qemu_get_guest_memory_mapping(MemoryMappingList *list)
>>  {
>> -    CPUArchState *env, *first_paging_enabled_cpu;
>> +    GetGuestMemoryMappingData s = {
>> +        .list = list,
>> +        .ret = -2,
>> +    };
>>      RAMBlock *block;
>>      ram_addr_t offset, length;
>> -    int ret;
>>  
>> -    first_paging_enabled_cpu = find_paging_enabled_cpu(first_cpu);
>> -    if (first_paging_enabled_cpu) {
>> -        for (env = first_paging_enabled_cpu; env != NULL; env = env->next_cpu) {
>> -            ret = cpu_get_memory_mapping(ENV_GET_CPU(env), list);
>> -            if (ret < 0) {
>> -                return -1;
>> -            }
>> -        }
>> -        return 0;
>> +    qemu_for_each_cpu(qemu_get_one_guest_memory_mapping, &s);
>> +    if (s.ret != -2) {
>> +        return s.ret;
>>      }
> 
> I see we ignore error in dump_init(). Doesn't matter today because
> x86_cpu_get_memory_mapping() never fails. But as you're doing this cleanup,
> shouldn't you add proper error handling?

This patch is not needed for arm/s390x, so we can easily postpone it. I
included it here for early feedback since my series building on this
still needs to be tested and tweaked for bsd-user.

I figure passing through Error** would be the logical follow-up here?
Yet s.ret is being reused to check if any CPU provided any mappings at
all - we could instead do two loops, one for checking if any CPU has
paging enabled and then one passing out any Error* and propagating that.

Thanks,
Andreas

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

  reply	other threads:[~2013-06-05 13:49 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-30 15:07 [Qemu-devel] [PATCH qom-cpu v3 0/9] dump: Build cleanups redone Andreas Färber
2013-05-30 15:07 ` [Qemu-devel] [PATCH qom-cpu v3 1/9] dump: Move stubs into libqemustub.a Andreas Färber
2013-05-30 15:07 ` [Qemu-devel] [PATCH qom-cpu v3 2/9] target-i386: Fix mask of pte index in memory mapping Andreas Färber
2013-05-30 15:07 ` [Qemu-devel] [PATCH qom-cpu v3 3/9] target-i386: walk_pml4e(): fix abort on bad PML4E/PDPTE/PDE/PTE addresses Andreas Färber
2013-05-30 15:07 ` [Qemu-devel] [PATCH qom-cpu v3 4/9] cpu: Turn cpu_paging_enabled() into a CPUState hook Andreas Färber
2013-05-31 13:33   ` Luiz Capitulino
2013-06-05 12:29     ` Andreas Färber
2013-05-30 15:07 ` [Qemu-devel] [PATCH qom-cpu v3 5/9] memory_mapping: Move MemoryMappingList typedef to qemu/typedefs.h Andreas Färber
2013-05-30 15:07 ` [Qemu-devel] [PATCH qom-cpu v3 6/9] cpu: Turn cpu_get_memory_mapping() into a CPUState hook Andreas Färber
2013-05-31 13:48   ` Luiz Capitulino
2013-06-05 13:10     ` Andreas Färber
2013-05-30 15:07 ` [Qemu-devel] [PATCH qom-cpu v3 7/9] memory_mapping: Drop qemu_get_memory_mapping() stub Andreas Färber
2013-05-30 15:08 ` [Qemu-devel] [PATCH qom-cpu v3 8/9] dump: Unconditionally compile Andreas Färber
2013-05-30 15:08 ` [Qemu-devel] [PATCH qom-cpu v3 9/9] memory_mapping: Change qemu_get_guest_memory_mapping() semantics Andreas Färber
2013-05-31 14:14   ` Luiz Capitulino
2013-06-05 13:48     ` Andreas Färber [this message]
2013-05-31 14:15 ` [Qemu-devel] [PATCH qom-cpu v3 0/9] dump: Build cleanups redone Luiz Capitulino

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=51AF41C4.8030408@suse.de \
    --to=afaerber@suse.de \
    --cc=lcapitulino@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qiaonuohan@cn.fujitsu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.