diff mbox

[08/12] spapr-rtas: use hypercall interface and remove special vty interfaces

Message ID 1371674435-14973-9-git-send-email-aliguori@us.ibm.com
State New
Headers show

Commit Message

Anthony Liguori June 19, 2013, 8:40 p.m. UTC
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
 hw/char/spapr_vty.c        | 36 ++++++++++++++++++------------------
 hw/ppc/spapr_rtas.c        | 18 ++++++++++--------
 include/hw/ppc/spapr_vio.h |  2 --
 3 files changed, 28 insertions(+), 28 deletions(-)

Comments

Alexander Graf June 19, 2013, 9:24 p.m. UTC | #1
On 19.06.2013, at 22:40, Anthony Liguori wrote:

> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
> ---
> hw/char/spapr_vty.c        | 36 ++++++++++++++++++------------------
> hw/ppc/spapr_rtas.c        | 18 ++++++++++--------
> include/hw/ppc/spapr_vio.h |  2 --
> 3 files changed, 28 insertions(+), 28 deletions(-)
> 
> diff --git a/hw/char/spapr_vty.c b/hw/char/spapr_vty.c
> index ecc2bb5..4bac79e 100644
> --- a/hw/char/spapr_vty.c
> +++ b/hw/char/spapr_vty.c
> @@ -63,7 +63,7 @@ static int vty_getchars(VIOsPAPRDevice *sdev, uint8_t *buf, int max)
>     return n;
> }
> 
> -void vty_putchars(VIOsPAPRDevice *sdev, uint8_t *buf, int len)
> +static void vty_putchars(VIOsPAPRDevice *sdev, uint8_t *buf, int len)
> {
>     VIOsPAPRVTYDevice *dev = VIO_SPAPR_VTY_DEVICE(sdev);
> 
> @@ -86,6 +86,23 @@ static int spapr_vty_init(VIOsPAPRDevice *sdev)
>     return 0;
> }
> 
> +static VIOsPAPRDevice *vty_lookup(sPAPREnvironment *spapr, target_ulong reg)
> +{
> +    VIOsPAPRDevice *sdev;
> +
> +    sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
> +    if (!sdev && reg == 0) {
> +        /* Hack for kernel early debug, which always specifies reg==0.
> +         * We search all VIO devices, and grab the vty with the lowest
> +         * reg.  This attempts to mimic existing PowerVM behaviour
> +         * (early debug does work there, despite having no vty with
> +         * reg==0. */
> +        return spapr_vty_get_default(spapr->vio_bus);
> +    }
> +
> +    return sdev;
> +}
> +
> /* Forward declaration */
> static target_ulong h_put_term_char(PowerPCCPU *cpu, sPAPREnvironment *spapr,
>                                     target_ulong opcode, target_ulong *args)
> @@ -211,23 +228,6 @@ VIOsPAPRDevice *spapr_vty_get_default(VIOsPAPRBus *bus)
>     return selected;
> }
> 
> -VIOsPAPRDevice *vty_lookup(sPAPREnvironment *spapr, target_ulong reg)
> -{
> -    VIOsPAPRDevice *sdev;
> -
> -    sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
> -    if (!sdev && reg == 0) {
> -        /* Hack for kernel early debug, which always specifies reg==0.
> -         * We search all VIO devices, and grab the vty with the lowest
> -         * reg.  This attempts to mimic existing PowerVM behaviour
> -         * (early debug does work there, despite having no vty with
> -         * reg==0. */
> -        return spapr_vty_get_default(spapr->vio_bus);
> -    }
> -
> -    return sdev;
> -}
> -
> static void spapr_vty_register_types(void)
> {
>     spapr_register_hypercall(H_PUT_TERM_CHAR, h_put_term_char);
> diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c
> index 5887e04..019aed5 100644
> --- a/hw/ppc/spapr_rtas.c
> +++ b/hw/ppc/spapr_rtas.c
> @@ -44,14 +44,16 @@ static void rtas_display_character(PowerPCCPU *cpu, sPAPREnvironment *spapr,
>                                    uint32_t nret, target_ulong rets)
> {
>     uint8_t c = rtas_ld(args, 0);
> -    VIOsPAPRDevice *sdev = vty_lookup(spapr, 0);
> -
> -    if (!sdev) {
> -        rtas_st(rets, 0, -1);
> -    } else {
> -        vty_putchars(sdev, &c, sizeof(c));
> -        rtas_st(rets, 0, 0);
> -    }
> +    target_ulong hargs[4] = {

This is too small. I believe it works with today's code, but the hypercall ABI allows for more registers to be accessed, so we should at least pad the array to not run into potential buffer overflows:

    The general purpose registers r0 and r3-r12, the CTR and XER registers are volatile along with the condition register fields 0 and 1 plus 5-7.

> +        0, /* reg=0 */
> +        1, /* len=1 */
> +        (uint64_t)c << 56, /* data */

Ugh. So the interface really is that broken? Oh well ....


Alex

> +        0 /* data */
> +    };
> +    target_ulong ret;
> +
> +    ret = spapr_hypercall(cpu, H_PUT_TERM_CHAR, hargs);
> +    rtas_st(rets, 0, ret);
> }
> 
> static void rtas_get_time_of_day(PowerPCCPU *cpu, sPAPREnvironment *spapr,
> diff --git a/include/hw/ppc/spapr_vio.h b/include/hw/ppc/spapr_vio.h
> index f98ec0a..817f5ff 100644
> --- a/include/hw/ppc/spapr_vio.h
> +++ b/include/hw/ppc/spapr_vio.h
> @@ -123,8 +123,6 @@ static inline int spapr_vio_dma_set(VIOsPAPRDevice *dev, uint64_t taddr,
> 
> int spapr_vio_send_crq(VIOsPAPRDevice *dev, uint8_t *crq);
> 
> -VIOsPAPRDevice *vty_lookup(sPAPREnvironment *spapr, target_ulong reg);
> -void vty_putchars(VIOsPAPRDevice *sdev, uint8_t *buf, int len);
> void spapr_vty_create(VIOsPAPRBus *bus, CharDriverState *chardev);
> void spapr_vlan_create(VIOsPAPRBus *bus, NICInfo *nd);
> void spapr_vscsi_create(VIOsPAPRBus *bus);
> -- 
> 1.8.0
>
Anthony Liguori June 19, 2013, 9:45 p.m. UTC | #2
Alexander Graf <agraf@suse.de> writes:

> On 19.06.2013, at 22:40, Anthony Liguori wrote:
>
>> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
>> ---
>> hw/char/spapr_vty.c        | 36 ++++++++++++++++++------------------
>> hw/ppc/spapr_rtas.c        | 18 ++++++++++--------
>> include/hw/ppc/spapr_vio.h |  2 --
>> 3 files changed, 28 insertions(+), 28 deletions(-)
>> 
>> diff --git a/hw/char/spapr_vty.c b/hw/char/spapr_vty.c
>> index ecc2bb5..4bac79e 100644
>> --- a/hw/char/spapr_vty.c
>> +++ b/hw/char/spapr_vty.c
>> @@ -63,7 +63,7 @@ static int vty_getchars(VIOsPAPRDevice *sdev, uint8_t *buf, int max)
>>     return n;
>> }
>> 
>> -void vty_putchars(VIOsPAPRDevice *sdev, uint8_t *buf, int len)
>> +static void vty_putchars(VIOsPAPRDevice *sdev, uint8_t *buf, int len)
>> {
>>     VIOsPAPRVTYDevice *dev = VIO_SPAPR_VTY_DEVICE(sdev);
>> 
>> @@ -86,6 +86,23 @@ static int spapr_vty_init(VIOsPAPRDevice *sdev)
>>     return 0;
>> }
>> 
>> +static VIOsPAPRDevice *vty_lookup(sPAPREnvironment *spapr, target_ulong reg)
>> +{
>> +    VIOsPAPRDevice *sdev;
>> +
>> +    sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
>> +    if (!sdev && reg == 0) {
>> +        /* Hack for kernel early debug, which always specifies reg==0.
>> +         * We search all VIO devices, and grab the vty with the lowest
>> +         * reg.  This attempts to mimic existing PowerVM behaviour
>> +         * (early debug does work there, despite having no vty with
>> +         * reg==0. */
>> +        return spapr_vty_get_default(spapr->vio_bus);
>> +    }
>> +
>> +    return sdev;
>> +}
>> +
>> /* Forward declaration */
>> static target_ulong h_put_term_char(PowerPCCPU *cpu, sPAPREnvironment *spapr,
>>                                     target_ulong opcode, target_ulong *args)
>> @@ -211,23 +228,6 @@ VIOsPAPRDevice *spapr_vty_get_default(VIOsPAPRBus *bus)
>>     return selected;
>> }
>> 
>> -VIOsPAPRDevice *vty_lookup(sPAPREnvironment *spapr, target_ulong reg)
>> -{
>> -    VIOsPAPRDevice *sdev;
>> -
>> -    sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
>> -    if (!sdev && reg == 0) {
>> -        /* Hack for kernel early debug, which always specifies reg==0.
>> -         * We search all VIO devices, and grab the vty with the lowest
>> -         * reg.  This attempts to mimic existing PowerVM behaviour
>> -         * (early debug does work there, despite having no vty with
>> -         * reg==0. */
>> -        return spapr_vty_get_default(spapr->vio_bus);
>> -    }
>> -
>> -    return sdev;
>> -}
>> -
>> static void spapr_vty_register_types(void)
>> {
>>     spapr_register_hypercall(H_PUT_TERM_CHAR, h_put_term_char);
>> diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c
>> index 5887e04..019aed5 100644
>> --- a/hw/ppc/spapr_rtas.c
>> +++ b/hw/ppc/spapr_rtas.c
>> @@ -44,14 +44,16 @@ static void rtas_display_character(PowerPCCPU *cpu, sPAPREnvironment *spapr,
>>                                    uint32_t nret, target_ulong rets)
>> {
>>     uint8_t c = rtas_ld(args, 0);
>> -    VIOsPAPRDevice *sdev = vty_lookup(spapr, 0);
>> -
>> -    if (!sdev) {
>> -        rtas_st(rets, 0, -1);
>> -    } else {
>> -        vty_putchars(sdev, &c, sizeof(c));
>> -        rtas_st(rets, 0, 0);
>> -    }
>> +    target_ulong hargs[4] = {
>
> This is too small. I believe it works with today's code, but the
> hypercall ABI allows for more registers to be accessed,

Not for this hypercall, but I can introduce spapr_hypercall[0-9] calls
if it makes you feel better about it :-)

> so we should at least pad the array to not run into potential buffer overflows:
>
>     The general purpose registers r0 and r3-r12, the CTR and XER registers are volatile along with the condition register fields 0 and 1 plus 5-7.
>
>> +        0, /* reg=0 */
>> +        1, /* len=1 */
>> +        (uint64_t)c << 56, /* data */
>
> Ugh. So the interface really is that broken? Oh well ....

It is.  There must have been some mighty powerful crack that the lads
that designed this interface had been smoking...

Regards,

Anthony Liguori

>
>
> Alex
>
>> +        0 /* data */
>> +    };
>> +    target_ulong ret;
>> +
>> +    ret = spapr_hypercall(cpu, H_PUT_TERM_CHAR, hargs);
>> +    rtas_st(rets, 0, ret);
>> }
>> 
>> static void rtas_get_time_of_day(PowerPCCPU *cpu, sPAPREnvironment *spapr,
>> diff --git a/include/hw/ppc/spapr_vio.h b/include/hw/ppc/spapr_vio.h
>> index f98ec0a..817f5ff 100644
>> --- a/include/hw/ppc/spapr_vio.h
>> +++ b/include/hw/ppc/spapr_vio.h
>> @@ -123,8 +123,6 @@ static inline int spapr_vio_dma_set(VIOsPAPRDevice *dev, uint64_t taddr,
>> 
>> int spapr_vio_send_crq(VIOsPAPRDevice *dev, uint8_t *crq);
>> 
>> -VIOsPAPRDevice *vty_lookup(sPAPREnvironment *spapr, target_ulong reg);
>> -void vty_putchars(VIOsPAPRDevice *sdev, uint8_t *buf, int len);
>> void spapr_vty_create(VIOsPAPRBus *bus, CharDriverState *chardev);
>> void spapr_vlan_create(VIOsPAPRBus *bus, NICInfo *nd);
>> void spapr_vscsi_create(VIOsPAPRBus *bus);
>> -- 
>> 1.8.0
>>
Alexander Graf June 19, 2013, 9:48 p.m. UTC | #3
On 19.06.2013, at 23:45, Anthony Liguori wrote:

> Alexander Graf <agraf@suse.de> writes:
> 
>> On 19.06.2013, at 22:40, Anthony Liguori wrote:
>> 
>>> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
>>> ---
>>> hw/char/spapr_vty.c        | 36 ++++++++++++++++++------------------
>>> hw/ppc/spapr_rtas.c        | 18 ++++++++++--------
>>> include/hw/ppc/spapr_vio.h |  2 --
>>> 3 files changed, 28 insertions(+), 28 deletions(-)
>>> 
>>> diff --git a/hw/char/spapr_vty.c b/hw/char/spapr_vty.c
>>> index ecc2bb5..4bac79e 100644
>>> --- a/hw/char/spapr_vty.c
>>> +++ b/hw/char/spapr_vty.c
>>> @@ -63,7 +63,7 @@ static int vty_getchars(VIOsPAPRDevice *sdev, uint8_t *buf, int max)
>>>    return n;
>>> }
>>> 
>>> -void vty_putchars(VIOsPAPRDevice *sdev, uint8_t *buf, int len)
>>> +static void vty_putchars(VIOsPAPRDevice *sdev, uint8_t *buf, int len)
>>> {
>>>    VIOsPAPRVTYDevice *dev = VIO_SPAPR_VTY_DEVICE(sdev);
>>> 
>>> @@ -86,6 +86,23 @@ static int spapr_vty_init(VIOsPAPRDevice *sdev)
>>>    return 0;
>>> }
>>> 
>>> +static VIOsPAPRDevice *vty_lookup(sPAPREnvironment *spapr, target_ulong reg)
>>> +{
>>> +    VIOsPAPRDevice *sdev;
>>> +
>>> +    sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
>>> +    if (!sdev && reg == 0) {
>>> +        /* Hack for kernel early debug, which always specifies reg==0.
>>> +         * We search all VIO devices, and grab the vty with the lowest
>>> +         * reg.  This attempts to mimic existing PowerVM behaviour
>>> +         * (early debug does work there, despite having no vty with
>>> +         * reg==0. */
>>> +        return spapr_vty_get_default(spapr->vio_bus);
>>> +    }
>>> +
>>> +    return sdev;
>>> +}
>>> +
>>> /* Forward declaration */
>>> static target_ulong h_put_term_char(PowerPCCPU *cpu, sPAPREnvironment *spapr,
>>>                                    target_ulong opcode, target_ulong *args)
>>> @@ -211,23 +228,6 @@ VIOsPAPRDevice *spapr_vty_get_default(VIOsPAPRBus *bus)
>>>    return selected;
>>> }
>>> 
>>> -VIOsPAPRDevice *vty_lookup(sPAPREnvironment *spapr, target_ulong reg)
>>> -{
>>> -    VIOsPAPRDevice *sdev;
>>> -
>>> -    sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
>>> -    if (!sdev && reg == 0) {
>>> -        /* Hack for kernel early debug, which always specifies reg==0.
>>> -         * We search all VIO devices, and grab the vty with the lowest
>>> -         * reg.  This attempts to mimic existing PowerVM behaviour
>>> -         * (early debug does work there, despite having no vty with
>>> -         * reg==0. */
>>> -        return spapr_vty_get_default(spapr->vio_bus);
>>> -    }
>>> -
>>> -    return sdev;
>>> -}
>>> -
>>> static void spapr_vty_register_types(void)
>>> {
>>>    spapr_register_hypercall(H_PUT_TERM_CHAR, h_put_term_char);
>>> diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c
>>> index 5887e04..019aed5 100644
>>> --- a/hw/ppc/spapr_rtas.c
>>> +++ b/hw/ppc/spapr_rtas.c
>>> @@ -44,14 +44,16 @@ static void rtas_display_character(PowerPCCPU *cpu, sPAPREnvironment *spapr,
>>>                                   uint32_t nret, target_ulong rets)
>>> {
>>>    uint8_t c = rtas_ld(args, 0);
>>> -    VIOsPAPRDevice *sdev = vty_lookup(spapr, 0);
>>> -
>>> -    if (!sdev) {
>>> -        rtas_st(rets, 0, -1);
>>> -    } else {
>>> -        vty_putchars(sdev, &c, sizeof(c));
>>> -        rtas_st(rets, 0, 0);
>>> -    }
>>> +    target_ulong hargs[4] = {
>> 
>> This is too small. I believe it works with today's code, but the
>> hypercall ABI allows for more registers to be accessed,
> 
> Not for this hypercall, but I can introduce spapr_hypercall[0-9] calls
> if it makes you feel better about it :-)

I think it's a lot easier to merely always pass an array of 9 args into the helper function. It's what the guest facing hypercall code does too. It just passes &env->gprs[4].


Alex
diff mbox

Patch

diff --git a/hw/char/spapr_vty.c b/hw/char/spapr_vty.c
index ecc2bb5..4bac79e 100644
--- a/hw/char/spapr_vty.c
+++ b/hw/char/spapr_vty.c
@@ -63,7 +63,7 @@  static int vty_getchars(VIOsPAPRDevice *sdev, uint8_t *buf, int max)
     return n;
 }
 
-void vty_putchars(VIOsPAPRDevice *sdev, uint8_t *buf, int len)
+static void vty_putchars(VIOsPAPRDevice *sdev, uint8_t *buf, int len)
 {
     VIOsPAPRVTYDevice *dev = VIO_SPAPR_VTY_DEVICE(sdev);
 
@@ -86,6 +86,23 @@  static int spapr_vty_init(VIOsPAPRDevice *sdev)
     return 0;
 }
 
+static VIOsPAPRDevice *vty_lookup(sPAPREnvironment *spapr, target_ulong reg)
+{
+    VIOsPAPRDevice *sdev;
+
+    sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
+    if (!sdev && reg == 0) {
+        /* Hack for kernel early debug, which always specifies reg==0.
+         * We search all VIO devices, and grab the vty with the lowest
+         * reg.  This attempts to mimic existing PowerVM behaviour
+         * (early debug does work there, despite having no vty with
+         * reg==0. */
+        return spapr_vty_get_default(spapr->vio_bus);
+    }
+
+    return sdev;
+}
+
 /* Forward declaration */
 static target_ulong h_put_term_char(PowerPCCPU *cpu, sPAPREnvironment *spapr,
                                     target_ulong opcode, target_ulong *args)
@@ -211,23 +228,6 @@  VIOsPAPRDevice *spapr_vty_get_default(VIOsPAPRBus *bus)
     return selected;
 }
 
-VIOsPAPRDevice *vty_lookup(sPAPREnvironment *spapr, target_ulong reg)
-{
-    VIOsPAPRDevice *sdev;
-
-    sdev = spapr_vio_find_by_reg(spapr->vio_bus, reg);
-    if (!sdev && reg == 0) {
-        /* Hack for kernel early debug, which always specifies reg==0.
-         * We search all VIO devices, and grab the vty with the lowest
-         * reg.  This attempts to mimic existing PowerVM behaviour
-         * (early debug does work there, despite having no vty with
-         * reg==0. */
-        return spapr_vty_get_default(spapr->vio_bus);
-    }
-
-    return sdev;
-}
-
 static void spapr_vty_register_types(void)
 {
     spapr_register_hypercall(H_PUT_TERM_CHAR, h_put_term_char);
diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c
index 5887e04..019aed5 100644
--- a/hw/ppc/spapr_rtas.c
+++ b/hw/ppc/spapr_rtas.c
@@ -44,14 +44,16 @@  static void rtas_display_character(PowerPCCPU *cpu, sPAPREnvironment *spapr,
                                    uint32_t nret, target_ulong rets)
 {
     uint8_t c = rtas_ld(args, 0);
-    VIOsPAPRDevice *sdev = vty_lookup(spapr, 0);
-
-    if (!sdev) {
-        rtas_st(rets, 0, -1);
-    } else {
-        vty_putchars(sdev, &c, sizeof(c));
-        rtas_st(rets, 0, 0);
-    }
+    target_ulong hargs[4] = {
+        0, /* reg=0 */
+        1, /* len=1 */
+        (uint64_t)c << 56, /* data */
+        0 /* data */
+    };
+    target_ulong ret;
+
+    ret = spapr_hypercall(cpu, H_PUT_TERM_CHAR, hargs);
+    rtas_st(rets, 0, ret);
 }
 
 static void rtas_get_time_of_day(PowerPCCPU *cpu, sPAPREnvironment *spapr,
diff --git a/include/hw/ppc/spapr_vio.h b/include/hw/ppc/spapr_vio.h
index f98ec0a..817f5ff 100644
--- a/include/hw/ppc/spapr_vio.h
+++ b/include/hw/ppc/spapr_vio.h
@@ -123,8 +123,6 @@  static inline int spapr_vio_dma_set(VIOsPAPRDevice *dev, uint64_t taddr,
 
 int spapr_vio_send_crq(VIOsPAPRDevice *dev, uint8_t *crq);
 
-VIOsPAPRDevice *vty_lookup(sPAPREnvironment *spapr, target_ulong reg);
-void vty_putchars(VIOsPAPRDevice *sdev, uint8_t *buf, int len);
 void spapr_vty_create(VIOsPAPRBus *bus, CharDriverState *chardev);
 void spapr_vlan_create(VIOsPAPRBus *bus, NICInfo *nd);
 void spapr_vscsi_create(VIOsPAPRBus *bus);