Igor,
Thank you for the pointers, I've turned the corner on the use of hostmem-file 
and am able to use it now!
I do have one question regarding hostmem-file. In the VMStateDescription, I 
used to have this for the contents
of the nvram (backed by a file):

          VMSTATE_VARRAY_UINT32(nvram, ERSTDeviceState, prop_size, 0,
            vmstate_info_uint8, uint8_t),

I've searched and I do not locate an example of passing a HostMemoryBackend 
object; how do I do that?
Thanks,
eric



________________________________
From: Igor Mammedov <imamm...@redhat.com>
Sent: Thursday, May 20, 2021 6:00 AM
To: Eric DeVolder <eric.devol...@oracle.com>
Cc: ehabk...@redhat.com <ehabk...@redhat.com>; m...@redhat.com 
<m...@redhat.com>; Konrad Wilk <konrad.w...@oracle.com>; qemu-devel@nongnu.org 
<qemu-devel@nongnu.org>; pbonz...@redhat.com <pbonz...@redhat.com>; Boris 
Ostrovsky <boris.ostrov...@oracle.com>; r...@twiddle.net <r...@twiddle.net>; 
jus...@redhat.com <jus...@redhat.com>
Subject: Re: [PATCH v2 3/7] ACPI ERST: support for ACPI ERST feature

On Tue, 18 May 2021 17:08:31 +0000
Eric DeVolder <eric.devol...@oracle.com> wrote:

> Hi Igor,
> Thanks for the information. I am primarily interested in ensuring data 
> persistence in the case of #1.
> As it stands so far, I have yet to observe any kind of write back into the 
> backing file. Just to summarize,
> what I've done thus far is:
>
> in erst_realizefn():
> ...
>     s->hostmem_obj = object_new(TYPE_MEMORY_BACKEND_FILE);
>     object_property_set_str(s->hostmem_obj, "mem-path", (const char 
> *)(TYPE_ACPI_ERST ".hostmem"), &error_fatal);
>     object_property_set_int(s->hostmem_obj, "size", s->prop_size, 
> &error_fatal);
>     user_creatable_complete(USER_CREATABLE(s->hostmem_obj), &error_fatal);
>     s->hostmem = MEMORY_BACKEND(s->hostmem_obj);

backend should be provided by user on CLI so all backend's properties are 
configured there
as user desires and frontend should access it via link property.
see how pc-dimm's memdev property is used.

> and then in erst_update_backing_file(), which is called when records are 
> created/updated:
>
> ...
>     if ((mr = host_memory_backend_get_memory(s->hostmem))) {
>         uint8_t *p = (uint8_t *)memory_region_get_ram_ptr(mr);
>         memcpy(p + offset, data, length);
>         memory_region_msync(mr, 0, s->prop_size); /* for now, the whole thing 
> */
> }
>
> I've instrumented this code, and I can see the records. I've instrumented 
> memory_region_msync() all the way down
> to qemu_msync() and it makes it into that code. But the end result has always 
> been the same, the backing file is
> never updated.
>
> I'm not really sure what else I need to do to get the hostmem contents to be 
> written back into the file.

see "man mmap"
 in particular MAP_SHARED vs MAP_PRIVATE

and there is a corresponding property for the file backend to manage that.

in case #1 no explicit sync is needed, backing file should be updated on close 
at the latest
(whether it's graceful/or forced (i.e. crash))


> Thanks,
> eric
>
>
> ________________________________
> From: Igor Mammedov <imamm...@redhat.com>
> Sent: Monday, May 17, 2021 11:31 AM
> To: Eric DeVolder <eric.devol...@oracle.com>
> Cc: ehabk...@redhat.com <ehabk...@redhat.com>; m...@redhat.com 
> <m...@redhat.com>; Konrad Wilk <konrad.w...@oracle.com>; 
> qemu-devel@nongnu.org <qemu-devel@nongnu.org>; pbonz...@redhat.com 
> <pbonz...@redhat.com>; Boris Ostrovsky <boris.ostrov...@oracle.com>; 
> r...@twiddle.net <r...@twiddle.net>; jus...@redhat.com <jus...@redhat.com>
> Subject: Re: [PATCH v2 3/7] ACPI ERST: support for ACPI ERST feature
>
> On Mon, 17 May 2021 15:01:02 +0000
> Eric DeVolder <eric.devol...@oracle.com> wrote:
>
> > Hi Igor,
> > I've been working to transition ERST to use the hostmem-file object as the 
> > backing store, as requested.
> >
> > I have the backend-file object now in ERST, and I have a question for you. 
> > This hostmem-file initializes
> > itself from a file, but in looking at the code, I do not see that it ever 
> > writes back to the file!? Furthermore,
> > I don't see a "flush" type method to force writeback of data in the object 
> > back to file?
> >
> > The original ERST code would flush/write to the backing file each record as 
> > it was created. I don't see
> > any equivalent way of doing that with hostmem-file?
>
> To force flush you can use memory_region_msync() on MemoryRegion that you get 
> from hostmem backend.
> But question is what are you trying to achieve with sync
>   1. data persistence in case of QEMU crash
>   2. data persistence in case of host crash
>
> for the former you do not need explicit sync as memory buffers should be 
> flushed to disk by kernel
> if you put backend on nvdimm, you should get 2 without sync as well (see 
> pmem=on property)
>
> just do not forget that sync is not free, so if #1 is acceptable I'd avoid 
> explicit sync.
>
>
> > Please point out where I am misunderstanding.
> >
> > Thanks,
> > eric
[...]

Reply via email to