linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: oliver <oohall@gmail.com>
To: Michael Neuling <mikey@neuling.org>
Cc: linuxppc-dev@lists.ozlabs.org, Paul Mackerras <paulus@samba.org>
Subject: Re: [PATCH 2/2] KVM: PPC: hypervisor large decrementer support
Date: Wed, 22 Jun 2016 17:30:02 +1000	[thread overview]
Message-ID: <CAOSf1CFtLotyoZtQiGLdwcOui+GUNUe0RuOD5kDGxu82Fv2o2w@mail.gmail.com> (raw)
In-Reply-To: <1464762233.30958.135.camel@neuling.org>

On Wed, Jun 1, 2016 at 4:23 PM, Michael Neuling <mikey@neuling.org> wrote:
> On Tue, 2016-05-31 at 17:16 +1000, Oliver O'Halloran wrote:
>> +#define IS_LD_ENABLED(reg)                 \
>> +     mfspr  reg,SPRN_LPCR;              \
>> +     andis. reg,reg,(LPCR_LD >> 16);
>
> FWIW you can use:
>         andis. reg,reg,(LPCR_LD)@ha
>
>> +#define GET_DEC(reg)                       \
>> +     IS_LD_ENABLED(reg);                \
>> +     mfspr reg, SPRN_DEC;               \
>> +     bne 99f;                           \
>> +     extsw reg, reg;                    \
>> +99:
>
> It's a little painful that GET_DEC() is now 2 SPR moves.  SPR moves can be
> a bit expensive.  Probably ok for now, but might be nice to store the guest
> dec LD state somewhere so we don't have to retrieve it from the LPCR SPR.

Seems reasonable. It looks like it stashes the LPCR value in the KVM vcpu
structure already


> Actually, it's probably best to do this now since checking the LD bit in
> the LPCR on P8 is a bit dodgy and unnecessary. There is a kvm->arch.lpcr
> you might be able use for this and you can add an asm-offsets for it too
> (like KVM_LPID).
>
> Is GET_DEC ever run in HV=0, where the guest couldn't read the LPCR?

It's only used in book3s_hv_rmhandlers.S, which contains the real mode h-call
handlers and none of that should be executed outside the host. Moving that
code into there from the generic exception header file is a good idea though.

> Also, this now trashes cr0... have you checked that's ok in the paths it's
> used?

It looks fine, but I'll document that.

>> +
>> +     LOAD_REG_ADDR(r6, decrementer_max);
>> +     ld      r6,0(r6);
>>       mtspr   SPRN_HDEC, r6
>>       /* and set per-LPAR registers, if doing dynamic micro-threading */
>>       ld      r6, HSTATE_SPLIT_MODE(r13)
>> @@ -897,7 +902,7 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
>>       mftb    r7
>>       subf    r3,r7,r8
>>       mtspr   SPRN_DEC,r3
>> -     stw     r3,VCPU_DEC(r4)
>> +     std     r3,VCPU_DEC(r4)
>>
>>       ld      r5, VCPU_SPRG0(r4)
>>       ld      r6, VCPU_SPRG1(r4)
>> @@ -953,8 +958,8 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
>>       isync
>>
>>       /* Check if HDEC expires soon */
>> -     mfspr   r3, SPRN_HDEC
>> -     cmpwi   r3, 512         /* 1 microsecond */
>> +     GET_HDEC(r3)
>> +     cmpdi   r3, 512         /* 1 microsecond */
>>       blt     hdec_soon
>>
>>       ld      r6, VCPU_CTR(r4)
>> @@ -990,8 +995,9 @@ deliver_guest_interrupt:
>>       beq     5f
>>       li      r0, BOOK3S_INTERRUPT_EXTERNAL
>>       bne     cr1, 12f
>> -     mfspr   r0, SPRN_DEC
>> -     cmpwi   r0, 0
>> +
>> +     GET_DEC(r0)
>> +     cmpdi   r0, 0
>
> We could just use mfspr DEC here since we are just comparing to 0.  It
> should work in any mode.

I'm not sure about that. The result of the comparison is used below:

>>       li      r0, BOOK3S_INTERRUPT_DECREMENTER
>>       bge     5f

It's checking for the DEC overflowing rather than checking if it's zero. If
LD=0 the mfspr result would not be sign extended causing the branch to be
taken even if the DEC overflowed.

Anyway I'm thinking I might drop this patch for now and let Balbir post it
as a part of his KVM series when that's ready.

  parent reply	other threads:[~2016-06-22  7:30 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-10  4:57 [PATCH v3 1/2] powerpc/timer - large decrementer support Oliver O'Halloran
2016-05-10  4:57 ` [PATCH v3 2/2] KVM: PPC: hypervisor " Oliver O'Halloran
2016-05-11  5:05 ` [PATCH v3 1/2] powerpc/timer - " Balbir Singh
2016-05-31  6:25 ` Michael Neuling
2016-05-31  7:05   ` oliver
2016-05-31  7:16   ` [PATCH " Oliver O'Halloran
2016-05-31  7:16     ` [PATCH 2/2] KVM: PPC: hypervisor " Oliver O'Halloran
2016-06-01  6:23       ` Michael Neuling
2016-06-02 21:46         ` Benjamin Herrenschmidt
2016-06-07 13:04           ` Michael Ellerman
2016-06-22  7:30         ` oliver [this message]
2016-06-01  5:28     ` [PATCH 1/2] powerpc/timer - " Michael Neuling
2016-06-03  2:01       ` Balbir Singh
  -- strict thread matches above, loose matches on Subject: below --
2016-04-12  4:38 Oliver O'Halloran
2016-04-12  4:38 ` [PATCH 2/2] KVM: PPC: hypervisor " Oliver O'Halloran
2016-04-12  4:53   ` kbuild test robot
2016-04-12  7:35   ` Balbir Singh

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=CAOSf1CFtLotyoZtQiGLdwcOui+GUNUe0RuOD5kDGxu82Fv2o2w@mail.gmail.com \
    --to=oohall@gmail.com \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mikey@neuling.org \
    --cc=paulus@samba.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).