qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Cédric Le Goater" <clg@kaod.org>
To: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 1/3] m25p80: do not put iovec on the stack
Date: Tue, 28 Jun 2016 12:02:33 +0200	[thread overview]
Message-ID: <e3fd5510-9e2d-25b4-1a07-c21fbc173e1f@kaod.org> (raw)
In-Reply-To: <f7dae24d-f96e-f052-00df-d6148fd0467c@kaod.org>

On 06/28/2016 10:53 AM, Cédric Le Goater wrote:
> On 06/28/2016 10:39 AM, Paolo Bonzini wrote:
>> When doing a read-modify-write cycle, QEMU uses the iovec after returning
>> from blk_aio_pwritev.  m25p80 puts the iovec on the stack of blk_aio_pwritev's
>> caller, which causes trouble in this case.  This has been a problem
>> since commit 243e6f6 ("m25p80: Switch to byte-based block access",
>> 2016-05-12) started doing writes at a smaller granularity than 512 bytes.
>> In principle however it could have broken before when using -drive
>> if=mtd,cache=none on a disk with 4K native sectors.
> 
> Ah ! Thanks. That was a problem I was seeing.   
>
> 
> I was thinking we could just do synchronous writes :
> 
> 	https://github.com/legoater/qemu/commit/aef3fe4db3be632077c581541fe30b4e36b5a6f7
> 
> and enable snapshotting like  : 
> 
> 	https://github.com/legoater/qemu/commit/b90ccab7873fd3538b47396ec7c3ae35c8e13270
> 

Anyhow, I tested this patch on a P8/ppc64le system on which the 
assertion was very systematic :

	bdrv_aligned_pwritev: Assertion `!qiov || bytes == qiov->size' failed.

It is gone.

Reviewed-and-tested-by: Cédric Le Goater <clg@kaod.org>

Thanks, 

C. 
 
 
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>> ---
>>  hw/block/m25p80.c | 23 ++++++++++++++---------
>>  1 file changed, 14 insertions(+), 9 deletions(-)
>>
>> diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c
>> index 09b4767..dd6714d 100644
>> --- a/hw/block/m25p80.c
>> +++ b/hw/block/m25p80.c
>> @@ -446,6 +446,11 @@ static inline Manufacturer get_man(Flash *s)
>>  
>>  static void blk_sync_complete(void *opaque, int ret)
>>  {
>> +    QEMUIOVector *iov = opaque;
>> +
>> +    qemu_iovec_destroy(iov);
>> +    g_free(iov);
>> +
>>      /* do nothing. Masters do not directly interact with the backing store,
>>       * only the working copy so no mutexing required.
>>       */
>> @@ -453,31 +458,31 @@ static void blk_sync_complete(void *opaque, int ret)
>>  
>>  static void flash_sync_page(Flash *s, int page)
>>  {
>> -    QEMUIOVector iov;
>> +    QEMUIOVector *iov = g_new(QEMUIOVector, 1);
>>  
>>      if (!s->blk || blk_is_read_only(s->blk)) {
>>          return;
>>      }
>>  
>> -    qemu_iovec_init(&iov, 1);
>> -    qemu_iovec_add(&iov, s->storage + page * s->pi->page_size,
>> +    qemu_iovec_init(iov, 1);
>> +    qemu_iovec_add(iov, s->storage + page * s->pi->page_size,
>>                     s->pi->page_size);
>> -    blk_aio_pwritev(s->blk, page * s->pi->page_size, &iov, 0,
>> -                    blk_sync_complete, NULL);
>> +    blk_aio_pwritev(s->blk, page * s->pi->page_size, iov, 0,
>> +                    blk_sync_complete, iov);
>>  }
>>  
>>  static inline void flash_sync_area(Flash *s, int64_t off, int64_t len)
>>  {
>> -    QEMUIOVector iov;
>> +    QEMUIOVector *iov = g_new(QEMUIOVector, 1);
>>  
>>      if (!s->blk || blk_is_read_only(s->blk)) {
>>          return;
>>      }
>>  
>>      assert(!(len % BDRV_SECTOR_SIZE));
>> -    qemu_iovec_init(&iov, 1);
>> -    qemu_iovec_add(&iov, s->storage + off, len);
>> -    blk_aio_pwritev(s->blk, off, &iov, 0, blk_sync_complete, NULL);
>> +    qemu_iovec_init(iov, 1);
>> +    qemu_iovec_add(iov, s->storage + off, len);
>> +    blk_aio_pwritev(s->blk, off, iov, 0, blk_sync_complete, iov);
>>  }
>>  
>>  static void flash_erase(Flash *s, int offset, FlashCMD cmd)
>>
> 

  reply	other threads:[~2016-06-28 10:02 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-28  8:39 [Qemu-devel] [PATCH 0/3] m25p80: various fixes Paolo Bonzini
2016-06-28  8:39 ` [Qemu-devel] [PATCH 1/3] m25p80: do not put iovec on the stack Paolo Bonzini
2016-06-28  8:53   ` Cédric Le Goater
2016-06-28 10:02     ` Cédric Le Goater [this message]
2016-06-28 14:33   ` Eric Blake
2016-06-28  8:39 ` [Qemu-devel] [PATCH 2/3] m25p80: avoid out of bounds accesses Paolo Bonzini
2016-06-28  9:05   ` Cédric Le Goater
2016-06-28 11:42     ` Paolo Bonzini
2016-06-28 12:00       ` [Qemu-devel] " Krzeminski, Marcin (Nokia - PL/Wroclaw)
2016-06-28  8:39 ` [Qemu-devel] [PATCH 3/3] m25p80: change cur_addr to 32 bit integer Paolo Bonzini
2016-06-28  9:18   ` Cédric Le Goater
2016-06-28 11:41     ` Paolo Bonzini

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=e3fd5510-9e2d-25b4-1a07-c21fbc173e1f@kaod.org \
    --to=clg@kaod.org \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.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).