linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: LAPIC: ARBPRI is a reserved register for x2APIC
@ 2019-07-05 12:14 Paolo Bonzini
  2019-07-05 12:37 ` Liran Alon
  2019-07-05 13:37 ` Nadav Amit
  0 siblings, 2 replies; 6+ messages in thread
From: Paolo Bonzini @ 2019-07-05 12:14 UTC (permalink / raw)
  To: linux-kernel, kvm

kvm-unit-tests were adjusted to match bare metal behavior, but KVM
itself was not doing what bare metal does; fix that.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 arch/x86/kvm/lapic.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index d6ca5c4f29f1..2e4470f2685a 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -1318,7 +1318,7 @@ int kvm_lapic_reg_read(struct kvm_lapic *apic, u32 offset, int len,
 	unsigned char alignment = offset & 0xf;
 	u32 result;
 	/* this bitmask has a bit cleared for each reserved register */
-	static const u64 rmask = 0x43ff01ffffffe70cULL;
+	u64 rmask = 0x43ff01ffffffe70cULL;
 
 	if ((alignment + len) > 4) {
 		apic_debug("KVM_APIC_READ: alignment error %x %d\n",
@@ -1326,6 +1326,10 @@ int kvm_lapic_reg_read(struct kvm_lapic *apic, u32 offset, int len,
 		return 1;
 	}
 
+	/* ARBPRI is also reserved on x2APIC */
+	if (apic_x2apic_mode(apic))
+		rmask &= ~(1 << (APIC_ARBPRI >> 4));
+
 	if (offset > 0x3f0 || !(rmask & (1ULL << (offset >> 4)))) {
 		apic_debug("KVM_APIC_READ: read reserved register %x\n",
 			   offset);
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] KVM: LAPIC: ARBPRI is a reserved register for x2APIC
  2019-07-05 12:14 [PATCH] KVM: LAPIC: ARBPRI is a reserved register for x2APIC Paolo Bonzini
@ 2019-07-05 12:37 ` Liran Alon
  2019-07-05 12:46   ` Paolo Bonzini
  2019-07-05 13:37 ` Nadav Amit
  1 sibling, 1 reply; 6+ messages in thread
From: Liran Alon @ 2019-07-05 12:37 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: linux-kernel, kvm



> On 5 Jul 2019, at 15:14, Paolo Bonzini <pbonzini@redhat.com> wrote:
> 
> kvm-unit-tests were adjusted to match bare metal behavior, but KVM
> itself was not doing what bare metal does; fix that.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> arch/x86/kvm/lapic.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
> index d6ca5c4f29f1..2e4470f2685a 100644
> --- a/arch/x86/kvm/lapic.c
> +++ b/arch/x86/kvm/lapic.c
> @@ -1318,7 +1318,7 @@ int kvm_lapic_reg_read(struct kvm_lapic *apic, u32 offset, int len,
> 	unsigned char alignment = offset & 0xf;
> 	u32 result;
> 	/* this bitmask has a bit cleared for each reserved register */
> -	static const u64 rmask = 0x43ff01ffffffe70cULL;
> +	u64 rmask = 0x43ff01ffffffe70cULL;

Why not rename this to “used_bits_mask” and calculate it properly by macros?
It seems a lot nicer than having a pre-calculated magic.

-Liran

> 
> 	if ((alignment + len) > 4) {
> 		apic_debug("KVM_APIC_READ: alignment error %x %d\n",
> @@ -1326,6 +1326,10 @@ int kvm_lapic_reg_read(struct kvm_lapic *apic, u32 offset, int len,
> 		return 1;
> 	}
> 
> +	/* ARBPRI is also reserved on x2APIC */
> +	if (apic_x2apic_mode(apic))
> +		rmask &= ~(1 << (APIC_ARBPRI >> 4));
> +
> 	if (offset > 0x3f0 || !(rmask & (1ULL << (offset >> 4)))) {
> 		apic_debug("KVM_APIC_READ: read reserved register %x\n",
> 			   offset);
> -- 
> 1.8.3.1
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] KVM: LAPIC: ARBPRI is a reserved register for x2APIC
  2019-07-05 12:37 ` Liran Alon
@ 2019-07-05 12:46   ` Paolo Bonzini
  0 siblings, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2019-07-05 12:46 UTC (permalink / raw)
  To: Liran Alon; +Cc: linux-kernel, kvm

On 05/07/19 14:37, Liran Alon wrote:
>> +	u64 rmask = 0x43ff01ffffffe70cULL;
> Why not rename this to “used_bits_mask” and calculate it properly by macros?
> It seems a lot nicer than having a pre-calculated magic.

Yes, I wanted to do the same but I didn't have time right now.  I am
planning to cleanup after the merge window, but if a patch comes soon I
can apply it instead of course. :)

Something like

#define APIC_VALID_REG_MASK(reg)	(1ull << ((reg) >> 4))
#define APIC_VALID_REGS_MASK(first, count) \
	(APIC_VALID_REG_MASK(first) * (1ull << ((count) - 1)))

followed by

	if (offset > 0x3f0 ||
	    !(valid_regs_mask & APIC_VALID_REG_MASK(offset))

Paolo

> -Liran
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] KVM: LAPIC: ARBPRI is a reserved register for x2APIC
  2019-07-05 12:14 [PATCH] KVM: LAPIC: ARBPRI is a reserved register for x2APIC Paolo Bonzini
  2019-07-05 12:37 ` Liran Alon
@ 2019-07-05 13:37 ` Nadav Amit
  2019-07-05 13:43   ` Paolo Bonzini
  1 sibling, 1 reply; 6+ messages in thread
From: Nadav Amit @ 2019-07-05 13:37 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: LKML, kvm

> On Jul 5, 2019, at 5:14 AM, Paolo Bonzini <pbonzini@redhat.com> wrote:
> 
> kvm-unit-tests were adjusted to match bare metal behavior, but KVM
> itself was not doing what bare metal does; fix that.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Reported-by ?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] KVM: LAPIC: ARBPRI is a reserved register for x2APIC
  2019-07-05 13:37 ` Nadav Amit
@ 2019-07-05 13:43   ` Paolo Bonzini
  2019-07-05 13:47     ` Nadav Amit
  0 siblings, 1 reply; 6+ messages in thread
From: Paolo Bonzini @ 2019-07-05 13:43 UTC (permalink / raw)
  To: Nadav Amit; +Cc: LKML, kvm

On 05/07/19 15:37, Nadav Amit wrote:
>> On Jul 5, 2019, at 5:14 AM, Paolo Bonzini <pbonzini@redhat.com> wrote:
>>
>> kvm-unit-tests were adjusted to match bare metal behavior, but KVM
>> itself was not doing what bare metal does; fix that.
>>
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> 
> Reported-by ?

I found it myself while running the tests, was there a report too?

Paolo

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] KVM: LAPIC: ARBPRI is a reserved register for x2APIC
  2019-07-05 13:43   ` Paolo Bonzini
@ 2019-07-05 13:47     ` Nadav Amit
  0 siblings, 0 replies; 6+ messages in thread
From: Nadav Amit @ 2019-07-05 13:47 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: LKML, kvm

> On Jul 5, 2019, at 6:43 AM, Paolo Bonzini <pbonzini@redhat.com> wrote:
> 
> On 05/07/19 15:37, Nadav Amit wrote:
>>> On Jul 5, 2019, at 5:14 AM, Paolo Bonzini <pbonzini@redhat.com> wrote:
>>> 
>>> kvm-unit-tests were adjusted to match bare metal behavior, but KVM
>>> itself was not doing what bare metal does; fix that.
>>> 
>>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>> 
>> Reported-by ?
> 
> I found it myself while running the tests, was there a report too?

Perhaps it is in my mind. I thought that fixing a test is equivalent to a
bug report.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-07-05 13:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-05 12:14 [PATCH] KVM: LAPIC: ARBPRI is a reserved register for x2APIC Paolo Bonzini
2019-07-05 12:37 ` Liran Alon
2019-07-05 12:46   ` Paolo Bonzini
2019-07-05 13:37 ` Nadav Amit
2019-07-05 13:43   ` Paolo Bonzini
2019-07-05 13:47     ` Nadav Amit

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).