[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] os: don't corrupt pre-existing memory-backend d
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH] os: don't corrupt pre-existing memory-backend data with prealloc |
Date: |
Fri, 24 Feb 2017 13:04:26 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 |
On 02/24/2017 11:27 AM, Daniel P. Berrange wrote:
> When using a memory-backend object with prealloc turned on, QEMU
> will memset() the first byte in every memory page to zero. While
> this might have been acceptable for memory backends associated
> with RAM, this corrupts application data for NVDIMMs.
>
> Instead of setting every page to zero, read the current byte
> value and then just write that same value back, so we are not
> corrupting the original data. Directly write the value instead
> of memset()ing it, since there's no benefit to memset for a
> single byte write.
>
> Signed-off-by: Daniel P. Berrange <address@hidden>
> ---
>
> /* MAP_POPULATE silently ignores failures */
> for (i = 0; i < numpages; i++) {
> - memset(area + (hpagesize * i), 0, 1);
> + /*
> + * Read & write back the same value, so we don't
> + * corrupt existinng user/app data that might be
s/existinng/existing/
> + * stored.
> + *
> + * 'volatile' to stop compiler optimizing this away
> + * to a no-op
> + *
> + * TODO: get a better solution from kernel so we
> + * don't need to write at all so we don't cause
> + * wear on the storage backing the region...
> + */
> + volatile char val = *(area + (hpagesize * i));
> + *(area + (hpagesize * i)) = val;
> }
> }
>
>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
- Re: [Qemu-devel] [PATCH] os: don't corrupt pre-existing memory-backend data with prealloc, (continued)
Re: [Qemu-devel] [PATCH] os: don't corrupt pre-existing memory-backend data with prealloc, Stefan Hajnoczi, 2017/02/27
[Qemu-devel] [PATCH] os: don't corrupt pre-existing memory-backend data with prealloc, Daniel P. Berrange, 2017/02/24