qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: laurent.desnogues@gmail.com, Andreas Faerber <afaerber@suse.de>
Subject: Re: [Qemu-devel] [PATCH for-2.0] cpu: do not use QOM casts in ENV_GET_CPU
Date: Wed, 26 Mar 2014 14:55:31 +0100	[thread overview]
Message-ID: <5332DC53.5050508@redhat.com> (raw)
In-Reply-To: <1395841365-24319-1-git-send-email-pbonzini@redhat.com>

Il 26/03/2014 14:42, Paolo Bonzini ha scritto:
> QOM casts are only typesafe inasmuch as we know that the argument is
> a QOM object.  If it is not, the accesses to fields in Object can
> access invalid memory and thus cause a segfault.
>
> Using a QOM cast in ENV_GET_CPU is useless and harmful.  Useless,
> because the cast is applied to the result of container_of, which is
> type safe.  So the QOM cast is nothing but typesafety theater.
> Harmful, because ENV_GET_CPU *is* used in hot paths especially
> now that, in 2.0, the movement of fields from CPU_COMMON to
> CPUState was completed.
>
> Reported-by: Laurent Desnogues <laurent.desnogues@gmail.com>
> Cc: Andreas Faerber <afaerber@suse.de>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Andreas pointed out on IRC that this is just the tip of the iceberg, due 
to code like this:

static void vmsa_ttbcr_write(CPUARMState *env, const ARMCPRegInfo *ri,
                              uint64_t value)
{
     ARMCPU *cpu = arm_env_get_cpu(env);

     if (arm_feature(env, ARM_FEATURE_LPAE)) {
         /* With LPAE the TTBCR could result in a change of ASID
          * via the TTBCR.A1 bit, so do a TLB flush.
          */
         tlb_flush(CPU(cpu), 1);
     }
     vmsa_ttbcr_raw_write(env, ri, value);
}

(from target-arm/helper.c).  Given this, and the limited time to fix the 
problem in 2.0 where it got magnified, I think we should reconsider 
whether releases should ahve QOM cast debugging enabled.

Paolo

  reply	other threads:[~2014-03-26 13:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-26 13:42 [Qemu-devel] [PATCH for-2.0] cpu: do not use QOM casts in ENV_GET_CPU Paolo Bonzini
2014-03-26 13:55 ` Paolo Bonzini [this message]
2014-03-28 14:34   ` Laurent Desnogues
2014-03-28 13:55 ` Laurent Desnogues
2014-03-28 13:59   ` Paolo Bonzini
2014-03-28 14:52 ` Andreas Färber
2014-03-28 14:56   ` Paolo Bonzini

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=5332DC53.5050508@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=afaerber@suse.de \
    --cc=laurent.desnogues@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /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).