qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: Xiao Guangrong <xiaoguangrong.eric@gmail.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Julio Montes <julio.montes@intel.com>,
	qemu-devel@nongnu.org, Igor Mammedov <imammedo@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Richard Henderson <rth@twiddle.net>,
	Eduardo Habkost <ehabkost@redhat.com>
Subject: Re: [PATCH 1/3] memory: add readonly support to memory_region_init_ram_from_file()
Date: Tue, 4 Aug 2020 15:57:32 +0200	[thread overview]
Message-ID: <ac5b358e-ac12-1979-f254-323e6fa2de99@redhat.com> (raw)
In-Reply-To: <20200804134756.GA1287869@stefanha-x1.localdomain>

On 8/4/20 3:47 PM, Stefan Hajnoczi wrote:
> On Tue, Aug 04, 2020 at 02:26:22PM +0200, Philippe Mathieu-Daudé wrote:
>> On 8/4/20 2:25 PM, Philippe Mathieu-Daudé wrote:
>>> Hi Stefan,
>>>
>>> On 8/4/20 12:12 PM, Stefan Hajnoczi wrote:
>>>> There is currently no way to open(O_RDONLY) and mmap(PROT_READ) when
>>>> creating a memory region from a file. This functionality is needed since
>>>> the underlying host file may not allow writing.
>>>>
>>>> Add a bool readonly argument to memory_region_init_ram_from_file() and
>>>> the APIs it calls.
>>>>
>>>> Extend memory_region_init_ram_from_file() rather than introducing a
>>>> memory_region_init_rom_from_file() API so that callers can easily make a
>>>> choice between read/write and read-only at runtime without calling
>>>> different APIs.
>>>
>>> What happens if we call:
>>>
>>>  memory_region_init_ram_from_file(mr, ..., readonly=false, ...);
>>>  memory_region_set_readonly(mr, false);
>>
>> In case my error is not obvious, I meant:
>>
>>    memory_region_init_ram_from_file(mr, ..., readonly=true, ...);
>>    memory_region_set_readonly(mr, false);
> 
> Since the mmap was made using PROT_READ any store instructions to the
> memory will fault.
> 
> Is there some scenario where memory_region_set_readonly() is called? I
> can't find one.

Not in the current code base, but I was wondering about the API abuses.

I see in the next patch the property is protected:

    if (host_memory_backend_mr_inited(backend)) {
        error_setg(errp, "cannot change property 'readonly' of %s.",
                   object_get_typename(o));
        return;
    }

By using memory_region_set_readonly() you bypass this protection.

Maybe not something to worry.

Anyway for the patch:
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> 
> Stefan
> 



  reply	other threads:[~2020-08-04 13:58 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-04 10:12 [PATCH 0/3] nvdimm: read-only file support Stefan Hajnoczi
2020-08-04 10:12 ` [PATCH 1/3] memory: add readonly support to memory_region_init_ram_from_file() Stefan Hajnoczi
2020-08-04 12:25   ` Philippe Mathieu-Daudé
2020-08-04 12:26     ` Philippe Mathieu-Daudé
2020-08-04 13:47       ` Stefan Hajnoczi
2020-08-04 13:57         ` Philippe Mathieu-Daudé [this message]
2020-08-04 10:12 ` [PATCH 2/3] hostmem-file: add readonly=on|off option Stefan Hajnoczi
2020-08-21 12:50   ` Philippe Mathieu-Daudé
2020-09-16  9:31     ` Stefan Hajnoczi
2020-09-16 10:17       ` Philippe Mathieu-Daudé
2020-08-04 10:12 ` [PATCH 3/3] nvdimm: honor -object memory-backend-file, readonly=on option Stefan Hajnoczi
2020-08-21 13:03   ` Philippe Mathieu-Daudé
2020-09-16  9:39     ` Stefan Hajnoczi
2020-08-04 12:28 ` [PATCH 0/3] nvdimm: read-only file support Michael S. Tsirkin
2020-08-21 12:18 ` Stefan Hajnoczi

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=ac5b358e-ac12-1979-f254-323e6fa2de99@redhat.com \
    --to=philmd@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=julio.montes@intel.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    --cc=stefanha@redhat.com \
    --cc=xiaoguangrong.eric@gmail.com \
    /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).