From: Avi Kivity <avi@redhat.com>
To: Jan Kiszka <jan.kiszka@web.de>
Cc: Anthony Liguori <aliguori@us.ibm.com>,
Marcelo Tosatti <mtosatti@redhat.com>,
qemu-devel <qemu-devel@nongnu.org>,
kvm@vger.kernel.org, Gleb Natapov <gleb@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 3/6] kvmvapic: Introduce TPR access optimization for Windows guests
Date: Thu, 09 Feb 2012 18:00:45 +0200 [thread overview]
Message-ID: <4F33EDAD.9020000@redhat.com> (raw)
In-Reply-To: <4F33E8C1.3070906@web.de>
On 02/09/2012 05:39 PM, Jan Kiszka wrote:
> On 2012-02-09 16:18, Avi Kivity wrote:
> > On 02/05/2012 02:39 PM, Jan Kiszka wrote:
> >> From: Jan Kiszka <jan.kiszka@siemens.com>
> >>
> >> This enables acceleration for MMIO-based TPR registers accesses of
> >> 32-bit Windows guest systems. It is mostly useful with KVM enabled,
> >> either on older Intel CPUs (without flexpriority feature, can also be
> >> manually disabled for testing) or any current AMD processor.
> >>
> >> The approach introduced here is derived from the original version of
> >> qemu-kvm. It was refactored, documented, and extended by support for
> >> user space APIC emulation, both with and without KVM acceleration.
> >
> > However, it's presented as a rewrite instead of a series of changes, so
> > we can't see what the changes are.
>
> Yes, but the original code also depends on interfaces we don't have in
> upstream.
The usual rant: patch qemu-kvm until it's suitable for upsteam, then
submit the end result for upstream. But you don't deserve this today.
> >> +
> >> + if (access == TPR_ACCESS_WRITE && kvm_enabled() &&
> >> + !kvm_irqchip_in_kernel()) {
> >> + /*
> >> + * KVM without TPR access reporting calls into the user space APIC on
> >> + * write with IP pointing after the accessing instruction. So we need
> >> + * to look backward to find the reason.
> >> + */
> >
> > Why do we need to do anything at all?
>
> We need to patch the causing instruction, so we have to know where it
> starts. Or what do you mean?
Just don't deal with this at all, no one runs on kernels without kernel
irqchip.
> >
> > I'm not sure if the ABI guarantees anything about %rip.
>
> That's indeed a point. It's likely coupled to the emulator's internals
> and when it calls out to user space for MMIO write. How to deal with it?
One way is to verify that it worked this way at least N versions back,
and then retro-doc it. The downside is that it reduces our flexibility
in the future, but I think that's a small downside.
Another way is not to do it at all.
> >> +static int get_kpcr_number(CPUState *env)
> >> +{
> >> + struct kpcr {
> >> + uint8_t fill1[0x1c];
> >> + uint32_t self;
> >> + uint8_t fill2[0x31];
> >> + uint8_t number;
> >> + } QEMU_PACKED kpcr;
> >> +
> >> + if (smp_cpus == 1) {
> >> + return 0;
> >> + }
> >> + if (cpu_memory_rw_debug(env, env->segs[R_FS].base,
> >> + (void *)&kpcr, sizeof(kpcr), 0) < 0 ||
> >> + kpcr.self != env->segs[R_FS].base) {
> >
> > Ah, so it works. We may want to do it for UP as well, as a way of
> > verifying that the guest is compatible with these hacks.
>
> I'm not sure if Windows has this properly set up for the UP HAL. I
> rather think this was a bug in the original implementation. The ROM uses
> 0 as CPU index in UP mode unconditionally, so should we in QEMU.
I mean just check kpcr.self.
The reason up and smp are so different is that for a long while smp
didn't work at all, and for some time it used even uglier hacks than we
have today (like stashing the cpu id in TR.sel), so I didn't want to
pollute th up code with the smp ugliness. It's also marginally faster
(less locked ops), though I doubt it matters on today's processors.
> >
> >> +
> >> + memory_region_init_alias(&s->rom, "kvmvapic-rom", section.mr, rom_paddr,
> >> + rom_size);
> >> + memory_region_add_subregion_overlap(as, rom_paddr, &s->rom, 1000);
> >
> > This is incredibly hacky, so at least the spirit of the original code is
> > preserved.
>
> I know, and it caused some pain to write it (not only to find out how to
> solve it technically). We would need to pass the RAM memory region down
> to this freaky device, like we do to the i440fx for PAM purposes. But,
> well, that is not straightforward right now. Better ideas welcome.
Could we make it a child<> of i440FX, and have i440FX pass it the
MemoryRegion directly?
It means we'll need to redo the glue for new chipsets, but it should be
just a few lines.
--
error compiling committee.c: too many arguments to function
next prev parent reply other threads:[~2012-02-09 16:01 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-05 12:39 [Qemu-devel] [PATCH 0/6] uq/master: TPR access optimization for Windows guests Jan Kiszka
2012-02-05 12:39 ` [Qemu-devel] [PATCH 1/6] target-i386: Add infrastructure for reporting TPR MMIO accesses Jan Kiszka
2012-02-05 12:39 ` [Qemu-devel] [PATCH 2/6] kvmvapic: Add option ROM Jan Kiszka
2012-02-05 12:39 ` [Qemu-devel] [PATCH 3/6] kvmvapic: Introduce TPR access optimization for Windows guests Jan Kiszka
2012-02-09 8:35 ` [Qemu-devel] subpages with memory region aliases (was: [PATCH 3/6] kvmvapic: Introduce TPR access optimization for Windows guests) Jan Kiszka
2012-02-09 9:32 ` [Qemu-devel] subpages with memory region aliases Avi Kivity
2012-02-09 14:23 ` Jan Kiszka
2012-02-09 15:05 ` Avi Kivity
2012-02-09 15:18 ` [Qemu-devel] [PATCH 3/6] kvmvapic: Introduce TPR access optimization for Windows guests Avi Kivity
2012-02-09 15:39 ` Jan Kiszka
2012-02-09 16:00 ` Avi Kivity [this message]
2012-02-09 16:32 ` Jan Kiszka
2012-02-09 16:47 ` Avi Kivity
2012-02-09 17:24 ` Jan Kiszka
2012-02-09 17:20 ` Paolo Bonzini
2012-02-09 18:01 ` Jan Kiszka
2012-02-05 12:39 ` [Qemu-devel] [PATCH 4/6] kvmvapic: Simplify mp/up_set_tpr Jan Kiszka
2012-02-05 12:39 ` [Qemu-devel] [PATCH 5/6] optionsrom: Reserve space for checksum Jan Kiszka
2012-02-05 12:39 ` [Qemu-devel] [PATCH 6/6] kvmvapic: Use optionrom helpers Jan Kiszka
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=4F33EDAD.9020000@redhat.com \
--to=avi@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=gleb@redhat.com \
--cc=jan.kiszka@web.de \
--cc=kvm@vger.kernel.org \
--cc=mtosatti@redhat.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).