diff mbox

[05/17] ppc: Fix hreg_store_msr() so that non-HV mode cannot alter MSR:HV

Message ID 1457974600-13828-6-git-send-email-clg@fr.ibm.com (mailing list archive)
State New, archived
Headers show

Commit Message

Cédric Le Goater March 14, 2016, 4:56 p.m. UTC
From: Benjamin Herrenschmidt <benh@kernel.crashing.org>

This helper is only used by the various instructions that can alter
MSR and not interrupts. Add a comment to that effect to the interrupt
code as well in case somebody wants to change this

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
---
 target-ppc/excp_helper.c | 8 ++++++--
 target-ppc/helper_regs.h | 4 ++--
 2 files changed, 8 insertions(+), 4 deletions(-)

Comments

Thomas Huth March 14, 2016, 7:29 p.m. UTC | #1
On 14.03.2016 17:56, Cédric Le Goater wrote:
> From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> 
> This helper is only used by the various instructions that can alter
> MSR and not interrupts. Add a comment to that effect to the interrupt
> code as well in case somebody wants to change this
> 
> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> ---
>  target-ppc/excp_helper.c | 8 ++++++--
>  target-ppc/helper_regs.h | 4 ++--
>  2 files changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/target-ppc/excp_helper.c b/target-ppc/excp_helper.c
> index c890853d861b..37d4721db63b 100644
> --- a/target-ppc/excp_helper.c
> +++ b/target-ppc/excp_helper.c
> @@ -666,8 +666,12 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int excp_model, int excp)
>          }
>      }
>  #endif
> -    /* XXX: we don't use hreg_store_msr here as already have treated
> -     *      any special case that could occur. Just store MSR and update hflags
> +    /* We don't use hreg_store_msr here as already have treated
> +     * any special case that could occur. Just store MSR and update hflags
> +     *
> +     * Note: We *MUST* not use hreg_store_msr() as-is anyway because it
> +     * will prevent setting of the HV bit which some exceptions might need
> +     * to do.
>       */
>      env->msr = new_msr & env->msr_mask;
>      hreg_compute_hflags(env);
> diff --git a/target-ppc/helper_regs.h b/target-ppc/helper_regs.h
> index 271fddf17f0a..844240d1a755 100644
> --- a/target-ppc/helper_regs.h
> +++ b/target-ppc/helper_regs.h
> @@ -75,8 +75,8 @@ static inline int hreg_store_msr(CPUPPCState *env, target_ulong value,
>      excp = 0;
>      value &= env->msr_mask;
>  #if !defined(CONFIG_USER_ONLY)
> -    if (!alter_hv) {
> -        /* mtmsr cannot alter the hypervisor state */
> +    /* Neither mtmsr nor guest state can alter HV */
> +    if (!alter_hv || !(env->msr & MSR_HVB)) {
>          value &= ~MSR_HVB;
>          value |= env->msr & MSR_HVB;
>      }

Reviewed-by: Thomas Huth <thuth@redhat.com>
David Gibson March 15, 2016, 9:47 a.m. UTC | #2
On Mon, Mar 14, 2016 at 08:29:10PM +0100, Thomas Huth wrote:
> On 14.03.2016 17:56, Cédric Le Goater wrote:
> > From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> > 
> > This helper is only used by the various instructions that can alter
> > MSR and not interrupts. Add a comment to that effect to the interrupt
> > code as well in case somebody wants to change this
> > 
> > Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> > Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> > ---
> >  target-ppc/excp_helper.c | 8 ++++++--
> >  target-ppc/helper_regs.h | 4 ++--
> >  2 files changed, 8 insertions(+), 4 deletions(-)
> > 
> > diff --git a/target-ppc/excp_helper.c b/target-ppc/excp_helper.c
> > index c890853d861b..37d4721db63b 100644
> > --- a/target-ppc/excp_helper.c
> > +++ b/target-ppc/excp_helper.c
> > @@ -666,8 +666,12 @@ static inline void powerpc_excp(PowerPCCPU *cpu, int excp_model, int excp)
> >          }
> >      }
> >  #endif
> > -    /* XXX: we don't use hreg_store_msr here as already have treated
> > -     *      any special case that could occur. Just store MSR and update hflags
> > +    /* We don't use hreg_store_msr here as already have treated
> > +     * any special case that could occur. Just store MSR and update hflags
> > +     *
> > +     * Note: We *MUST* not use hreg_store_msr() as-is anyway because it
> > +     * will prevent setting of the HV bit which some exceptions might need
> > +     * to do.
> >       */
> >      env->msr = new_msr & env->msr_mask;
> >      hreg_compute_hflags(env);
> > diff --git a/target-ppc/helper_regs.h b/target-ppc/helper_regs.h
> > index 271fddf17f0a..844240d1a755 100644
> > --- a/target-ppc/helper_regs.h
> > +++ b/target-ppc/helper_regs.h
> > @@ -75,8 +75,8 @@ static inline int hreg_store_msr(CPUPPCState *env, target_ulong value,
> >      excp = 0;
> >      value &= env->msr_mask;
> >  #if !defined(CONFIG_USER_ONLY)
> > -    if (!alter_hv) {
> > -        /* mtmsr cannot alter the hypervisor state */
> > +    /* Neither mtmsr nor guest state can alter HV */
> > +    if (!alter_hv || !(env->msr & MSR_HVB)) {
> >          value &= ~MSR_HVB;
> >          value |= env->msr & MSR_HVB;
> >      }
> 
> Reviewed-by: Thomas Huth <thuth@redhat.com>

This looks correct, but I'm not seeing a strong case for including it
before 2.6.
diff mbox

Patch

diff --git a/target-ppc/excp_helper.c b/target-ppc/excp_helper.c
index c890853d861b..37d4721db63b 100644
--- a/target-ppc/excp_helper.c
+++ b/target-ppc/excp_helper.c
@@ -666,8 +666,12 @@  static inline void powerpc_excp(PowerPCCPU *cpu, int excp_model, int excp)
         }
     }
 #endif
-    /* XXX: we don't use hreg_store_msr here as already have treated
-     *      any special case that could occur. Just store MSR and update hflags
+    /* We don't use hreg_store_msr here as already have treated
+     * any special case that could occur. Just store MSR and update hflags
+     *
+     * Note: We *MUST* not use hreg_store_msr() as-is anyway because it
+     * will prevent setting of the HV bit which some exceptions might need
+     * to do.
      */
     env->msr = new_msr & env->msr_mask;
     hreg_compute_hflags(env);
diff --git a/target-ppc/helper_regs.h b/target-ppc/helper_regs.h
index 271fddf17f0a..844240d1a755 100644
--- a/target-ppc/helper_regs.h
+++ b/target-ppc/helper_regs.h
@@ -75,8 +75,8 @@  static inline int hreg_store_msr(CPUPPCState *env, target_ulong value,
     excp = 0;
     value &= env->msr_mask;
 #if !defined(CONFIG_USER_ONLY)
-    if (!alter_hv) {
-        /* mtmsr cannot alter the hypervisor state */
+    /* Neither mtmsr nor guest state can alter HV */
+    if (!alter_hv || !(env->msr & MSR_HVB)) {
         value &= ~MSR_HVB;
         value |= env->msr & MSR_HVB;
     }