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 <[email protected]> > --- >
> /* 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
