[Qemu-devel] [PATCH v2 03/11] pflash_cfi01: Log use of flawed "write to buffer"

Markus Armbruster posted 11 patches 6 years, 8 months ago
Maintainers: Aleksandar Markovic <amarkovic@wavecomp.com>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Andrzej Zaborowski <balrogg@gmail.com>, Kevin Wolf <kwolf@redhat.com>, Jan Kiszka <jan.kiszka@web.de>, Aleksandar Rikalo <arikalo@wavecomp.com>, Peter Maydell <peter.maydell@linaro.org>, Max Filippov <jcmvbkbc@gmail.com>, Richard Henderson <rth@twiddle.net>, Alistair Francis <alistair@alistair23.me>, BALATON Zoltan <balaton@eik.bme.hu>, Paolo Bonzini <pbonzini@redhat.com>, "Philippe Mathieu-Daudé" <f4bug@amsat.org>, Michael Walle <michael@walle.cc>, Max Reitz <mreitz@redhat.com>, Magnus Damm <magnus.damm@gmail.com>, Aurelien Jarno <aurelien@aurel32.net>, David Gibson <david@gibson.dropbear.id.au>, Antony Pavlov <antonynpavlov@gmail.com>, "Michael S. Tsirkin" <mst@redhat.com>, Eduardo Habkost <ehabkost@redhat.com>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>
There is a newer version of this series
[Qemu-devel] [PATCH v2 03/11] pflash_cfi01: Log use of flawed "write to buffer"
Posted by Markus Armbruster 6 years, 8 months ago
Our implementation of "write to buffer" (command 0xE8) is flawed.
LOG_UNIMP its use, and add some FIXME comments.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/block/pflash_cfi01.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
index e6d933a06d..d381f14e3c 100644
--- a/hw/block/pflash_cfi01.c
+++ b/hw/block/pflash_cfi01.c
@@ -502,6 +502,10 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
             break;
         case 0xe8: /* Write to buffer */
             DPRINTF("%s: Write to buffer\n", __func__);
+            /* FIXME should save @offset, @width for case 1+ */
+            qemu_log_mask(LOG_UNIMP,
+                          "%s: Write to buffer emulation is flawed\n",
+                          __func__);
             pfl->status |= 0x80; /* Ready! */
             break;
         case 0xf0: /* Probe for AMD flash */
@@ -545,6 +549,7 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
             /* Mask writeblock size based on device width, or bank width if
              * device width not specified.
              */
+            /* FIXME check @offset, @width */
             if (pfl->device_width) {
                 value = extract32(value, 0, pfl->device_width * 8);
             } else {
@@ -582,7 +587,13 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
     case 2:
         switch (pfl->cmd) {
         case 0xe8: /* Block write */
+            /* FIXME check @offset, @width */
             if (!pfl->ro) {
+                /*
+                 * FIXME writing straight to memory is *wrong*.  We
+                 * should write to a buffer, and flush it to memory
+                 * only on confirm command (see below).
+                 */
                 pflash_data_write(pfl, offset, value, width, be);
             } else {
                 pfl->status |= 0x10; /* Programming error */
@@ -598,6 +609,7 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
                 pfl->wcycle++;
                 if (!pfl->ro) {
                     /* Flush the entire write buffer onto backing storage.  */
+                    /* FIXME premature! */
                     pflash_update(pfl, offset & mask, pfl->writeblock_size);
                 } else {
                     pfl->status |= 0x10; /* Programming error */
@@ -614,6 +626,7 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
         switch (pfl->cmd) {
         case 0xe8: /* Block write */
             if (cmd == 0xd0) {
+                /* FIXME this is where we should write out the buffer */
                 pfl->wcycle = 0;
                 pfl->status |= 0x80;
             } else {
-- 
2.17.2


Re: [Qemu-devel] [PATCH v2 03/11] pflash_cfi01: Log use of flawed "write to buffer"
Posted by Philippe Mathieu-Daudé 6 years, 8 months ago
On 2/26/19 8:34 PM, Markus Armbruster wrote:
> Our implementation of "write to buffer" (command 0xE8) is flawed.
> LOG_UNIMP its use, and add some FIXME comments.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  hw/block/pflash_cfi01.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
> index e6d933a06d..d381f14e3c 100644
> --- a/hw/block/pflash_cfi01.c
> +++ b/hw/block/pflash_cfi01.c
> @@ -502,6 +502,10 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
>              break;
>          case 0xe8: /* Write to buffer */
>              DPRINTF("%s: Write to buffer\n", __func__);
> +            /* FIXME should save @offset, @width for case 1+ */
> +            qemu_log_mask(LOG_UNIMP,
> +                          "%s: Write to buffer emulation is flawed\n",
> +                          __func__);
>              pfl->status |= 0x80; /* Ready! */
>              break;
>          case 0xf0: /* Probe for AMD flash */
> @@ -545,6 +549,7 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
>              /* Mask writeblock size based on device width, or bank width if
>               * device width not specified.
>               */
> +            /* FIXME check @offset, @width */
>              if (pfl->device_width) {
>                  value = extract32(value, 0, pfl->device_width * 8);
>              } else {
> @@ -582,7 +587,13 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
>      case 2:
>          switch (pfl->cmd) {
>          case 0xe8: /* Block write */
> +            /* FIXME check @offset, @width */
>              if (!pfl->ro) {
> +                /*
> +                 * FIXME writing straight to memory is *wrong*.  We
> +                 * should write to a buffer, and flush it to memory
> +                 * only on confirm command (see below).
> +                 */
>                  pflash_data_write(pfl, offset, value, width, be);
>              } else {
>                  pfl->status |= 0x10; /* Programming error */
> @@ -598,6 +609,7 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
>                  pfl->wcycle++;
>                  if (!pfl->ro) {
>                      /* Flush the entire write buffer onto backing storage.  */
> +                    /* FIXME premature! */
>                      pflash_update(pfl, offset & mask, pfl->writeblock_size);
>                  } else {
>                      pfl->status |= 0x10; /* Programming error */
> @@ -614,6 +626,7 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
>          switch (pfl->cmd) {
>          case 0xe8: /* Block write */
>              if (cmd == 0xd0) {
> +                /* FIXME this is where we should write out the buffer */

Thanks for all those comments.

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

BTW I'm OK to fix that during next dev window.

Regards,

Phil.

>                  pfl->wcycle = 0;
>                  pfl->status |= 0x80;
>              } else {
> 

Re: [Qemu-devel] [PATCH v2 03/11] pflash_cfi01: Log use of flawed "write to buffer"
Posted by Alex Bennée 6 years, 8 months ago
Markus Armbruster <armbru@redhat.com> writes:

> Our implementation of "write to buffer" (command 0xE8) is flawed.
> LOG_UNIMP its use, and add some FIXME comments.
>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>


> ---
>  hw/block/pflash_cfi01.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
>
> diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
> index e6d933a06d..d381f14e3c 100644
> --- a/hw/block/pflash_cfi01.c
> +++ b/hw/block/pflash_cfi01.c
> @@ -502,6 +502,10 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
>              break;
>          case 0xe8: /* Write to buffer */
>              DPRINTF("%s: Write to buffer\n", __func__);
> +            /* FIXME should save @offset, @width for case 1+ */
> +            qemu_log_mask(LOG_UNIMP,
> +                          "%s: Write to buffer emulation is flawed\n",
> +                          __func__);
>              pfl->status |= 0x80; /* Ready! */
>              break;
>          case 0xf0: /* Probe for AMD flash */
> @@ -545,6 +549,7 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
>              /* Mask writeblock size based on device width, or bank width if
>               * device width not specified.
>               */
> +            /* FIXME check @offset, @width */
>              if (pfl->device_width) {
>                  value = extract32(value, 0, pfl->device_width * 8);
>              } else {
> @@ -582,7 +587,13 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
>      case 2:
>          switch (pfl->cmd) {
>          case 0xe8: /* Block write */
> +            /* FIXME check @offset, @width */
>              if (!pfl->ro) {
> +                /*
> +                 * FIXME writing straight to memory is *wrong*.  We
> +                 * should write to a buffer, and flush it to memory
> +                 * only on confirm command (see below).
> +                 */
>                  pflash_data_write(pfl, offset, value, width, be);
>              } else {
>                  pfl->status |= 0x10; /* Programming error */
> @@ -598,6 +609,7 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
>                  pfl->wcycle++;
>                  if (!pfl->ro) {
>                      /* Flush the entire write buffer onto backing storage.  */
> +                    /* FIXME premature! */
>                      pflash_update(pfl, offset & mask, pfl->writeblock_size);
>                  } else {
>                      pfl->status |= 0x10; /* Programming error */
> @@ -614,6 +626,7 @@ static void pflash_write(PFlashCFI01 *pfl, hwaddr offset,
>          switch (pfl->cmd) {
>          case 0xe8: /* Block write */
>              if (cmd == 0xd0) {
> +                /* FIXME this is where we should write out the buffer */
>                  pfl->wcycle = 0;
>                  pfl->status |= 0x80;
>              } else {


--
Alex Bennée