qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: QEMU Developers <qemu-devel@nongnu.org>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Peter Xu" <peterx@redhat.com>,
	"Philippe Mathieu-Daudé" <philippe.mathieu-daude@linaro.org>,
	"Peter Maydell" <peter.maydell@linaro.org>
Subject: should ioapic_service really be modelling cpu writes?
Date: Thu, 10 Nov 2022 17:01:38 +0000	[thread overview]
Message-ID: <874jv6enct.fsf@linaro.org> (raw)

Hi,

I've been trying to remove current_cpu hacks from our hw/ emulation and
replace them with an explicit cpu_index derived from MemTxAttrs. So far
this has been going mostly ok but I've run into problems on x86 due to
the way the apic/ioapic are modelled. It comes down to the function
ioapic_service() which eventually does:

   /* No matter whether IR is enabled, we translate
    * the IOAPIC message into a MSI one, and its
    * address space will decide whether we need a
    * translation. */
   stl_le_phys(ioapic_as, info.addr, info.data);

Which essentially calls the memory API to simulate a memory write.
However to generate a properly formed MemTxAttrs we need to know what
CPU we are running on. In the case of ioapic_service() we may well be in
the main thread either for an expiring timer:

 hpet_timer->qemu_set_irq->ioapic_set_irq

or for reset handling:

 pc_machine_reset->hpet_reset->qemu_set_irq->ioapic_set_irq

neither of which can get a associated CPU. I assume if the actual writes
are triggered we never actually actioned stuff because we had:

  DeviceState *cpu_get_current_apic(void)
  {
      if (current_cpu) {
          X86CPU *cpu = X86_CPU(current_cpu);
          return cpu->apic_state;
      } else {
          return NULL;
      }
  }

which basically causes the updates to be dropped on the floor. However
during the conversion I went with something like:

  if (attrs.requester_type != MTRT_CPU) {
      return MEMTX_ACCESS_ERROR;
  }
  dev = cpu_get_current_apic(attrs.requester_id);

but that breaks current behaviour. It makes me wonder if the modelling
of the APIC is really representative of what the real HW does or if the
memory writes are simply a shortcut that happens to work?

-- 
Alex Bennée


             reply	other threads:[~2022-11-10 17:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-10 17:01 Alex Bennée [this message]
2022-11-10 17:55 ` should ioapic_service really be modelling cpu writes? Alex Bennée
2022-11-10 22:42   ` Peter Xu
2022-11-11 11:08     ` Paolo Bonzini
2022-11-11 12:26     ` Alex Bennée
2022-11-11 13:14       ` Paolo Bonzini
2022-11-11 14:00         ` Alex Bennée
2022-11-11 15:57           ` 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=874jv6enct.fsf@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=peterx@redhat.com \
    --cc=philippe.mathieu-daude@linaro.org \
    --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).