diff mbox

[02/10] cuda: don't allow writes to port output pins

Message ID 20180203103727.26457-3-mark.cave-ayland@ilande.co.uk (mailing list archive)
State New, archived
Headers show

Commit Message

Mark Cave-Ayland Feb. 3, 2018, 10:37 a.m. UTC
Use the direction registers as a mask to ensure that only input pins are
updated upon write.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/misc/macio/cuda.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Laurent Vivier Feb. 5, 2018, 2:27 p.m. UTC | #1
On 03/02/2018 11:37, Mark Cave-Ayland wrote:
> Use the direction registers as a mask to ensure that only input pins are
> updated upon write.
> 
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> ---
>  hw/misc/macio/cuda.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/misc/macio/cuda.c b/hw/misc/macio/cuda.c
> index 23b7e0f5b0..7214e7adcb 100644
> --- a/hw/misc/macio/cuda.c
> +++ b/hw/misc/macio/cuda.c
> @@ -359,11 +359,11 @@ static void cuda_write(void *opaque, hwaddr addr, uint64_t val, unsigned size)
>  
>      switch(addr) {
>      case CUDA_REG_B:
> -        s->b = val;
> +        s->b = (s->b & ~s->dirb) | (val & s->dirb);
>          cuda_update(s);
>          break;
>      case CUDA_REG_A:
> -        s->a = val;
> +        s->a = (s->a & ~s->dira) | (val & s->dira);
>          break;
>      case CUDA_REG_DIRB:
>          s->dirb = val;
> 

Reviewed-by: Laurent Vivier <lvivier@redhat.com>
Philippe Mathieu-Daudé Feb. 5, 2018, 7:53 p.m. UTC | #2
On 02/03/2018 07:37 AM, Mark Cave-Ayland wrote:
> Use the direction registers as a mask to ensure that only input pins are
> updated upon write.
> 
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> ---
>  hw/misc/macio/cuda.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/misc/macio/cuda.c b/hw/misc/macio/cuda.c
> index 23b7e0f5b0..7214e7adcb 100644
> --- a/hw/misc/macio/cuda.c
> +++ b/hw/misc/macio/cuda.c
> @@ -359,11 +359,11 @@ static void cuda_write(void *opaque, hwaddr addr, uint64_t val, unsigned size)
>  
>      switch(addr) {
>      case CUDA_REG_B:
> -        s->b = val;
> +        s->b = (s->b & ~s->dirb) | (val & s->dirb);

I personally find it easier to read in 2 lines (&=~, |=)

It might be useful to log invalid guest values:

           if (val & ~s->dirb) {
               GUEST_ERROR();
               val &= s->dirb;
           }
           s->b |= val;

>          cuda_update(s);
>          break;
>      case CUDA_REG_A:
> -        s->a = val;
> +        s->a = (s->a & ~s->dira) | (val & s->dira);

Ditto.

Regardless:
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

>          break;
>      case CUDA_REG_DIRB:
>          s->dirb = val;
>
diff mbox

Patch

diff --git a/hw/misc/macio/cuda.c b/hw/misc/macio/cuda.c
index 23b7e0f5b0..7214e7adcb 100644
--- a/hw/misc/macio/cuda.c
+++ b/hw/misc/macio/cuda.c
@@ -359,11 +359,11 @@  static void cuda_write(void *opaque, hwaddr addr, uint64_t val, unsigned size)
 
     switch(addr) {
     case CUDA_REG_B:
-        s->b = val;
+        s->b = (s->b & ~s->dirb) | (val & s->dirb);
         cuda_update(s);
         break;
     case CUDA_REG_A:
-        s->a = val;
+        s->a = (s->a & ~s->dira) | (val & s->dira);
         break;
     case CUDA_REG_DIRB:
         s->dirb = val;