qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Peter Xu <peterx@redhat.com>
Cc: qemu-devel@nongnu.org, "Paolo Bonzini" <pbonzini@redhat.com>,
	"Igor Mammedov" <imammedo@redhat.com>,
	"Thiner Logoer" <logoerthiner1@163.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: Re: [PATCH v1 1/3] softmmu/physmem: fallback to opening guest RAM file as readonly in a MAP_PRIVATE mapping
Date: Thu, 10 Aug 2023 16:19:45 +0200	[thread overview]
Message-ID: <e9c53fbd-369c-2605-1470-e67a765f923b@redhat.com> (raw)
In-Reply-To: <ZNOti1OKN79t68jP@x1n>

>> Most importantly, we won't be corrupting/touching the original file in any
>> case, because it is R/O.
>>
>> If we really want to be careful, we could clue that behavior to compat
>> machines. I'm not really sure yet if we really have to go down that path.
>>
>> Any other alternatives? I'd like to avoid new flags where not really
>> required.
> 
> I was just thinking of a new flag. :) So have you already discussed that
> possibility and decided that not a good idea?

Not really. I was briefly playing with that idea but already struggled 
to come up with a reasonable name :)

Less toggles and just have it working nice, if possible.

> 
> The root issue to me here is we actually have two resources (memory map of
> the process, and the file) but we only have one way to describe the
> permissions upon the two objects.  I'd think it makes a lot more sense if a
> new flag is added, when there's a need to differentiate the two.
> 
> Consider if you see a bunch of qemu instances with:
> 
>    -mem-path $RAM_FILE
> 
> On the same host, which can be as weird as it could be to me.. At least
> '-mem-path' looks still like a way to exclusively own a ram file for an
> instance. I hesitate the new fallback can confuse people too, while that's
> so far not the major use case.

Once I learned that this is not a MAP_SHARED mapping, I was extremely 
confused. For example, vhost-user with "-mem-path" will absolutely not 
work with "-mem-path", even though the documentation explicitly spells 
that out (I still have to send a patch to fix that).

I guess "-mem-path" was primarily only used to consume hugetlb. Even for 
tmpfs it will already result in a double memory consumption, just like 
when using -memory-backend-memfd,share=no.

I guess deprecating it was the right decision.

But memory-backend-file also defaults to "share=no" ... so the same 
default behavior unfortunately.

> 
> Nobody may really rely on any existing behavior of the failure, but
> changing existing behavior is just always not wanted.  The guideline here
> to me is: whether we want existing "-mem-path XXX" users to start using the
> fallback in general?  If it's "no", then maybe it implies a new flag is
> better?

I think we have the following options (there might be more)

1) This patch.

2) New flag for memory-backend-file. We already have "readonly" and 
"share=". I'm having a hard time coming up with a good name that really 
describes the subtle difference.

3) Glue behavior to the QEMU machine


For 3), one option would be to always open a COW file readonly (as 
Thiner originally proposed). We could leave "-mem-path" behavior alone 
and only change memory-backend-file semantics. If the COW file does 
*not* exist yet, we would refuse to create the file like patch 2+3 do. 
Therefore, no ftruncate() errors, and fallocate() errors would always 
happen.


What are your thoughts?

[...]

>>
>> [I'm curious at what point a filesystem will actually break COW. if it's
>> wired up to the writenotify infrastructure, it would happen when actually
>> writing to a page, not at mmap time. I know that filesystems use writenotify
>> for lazy allocation of disk blocks on file holes, maybe they also do that
>> for lazy allocation of disk blocks on COW]
> 
> I don't know either, but it definitely looks more promising and reasonable
> if the CoW only happens until being written, rather than being mapped RW.

That would be my best guess. But then, we have multiple pagecache pages 
point at the same disk block until COW happens ... maybe that's how it 
already works. Once I have some spare time, I might play with that.

-- 
Cheers,

David / dhildenb



  reply	other threads:[~2023-08-10 14:20 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-07 19:07 [PATCH v1 0/3] softmmu/physmem: file_ram_open() readonly improvements David Hildenbrand
2023-08-07 19:07 ` [PATCH v1 1/3] softmmu/physmem: fallback to opening guest RAM file as readonly in a MAP_PRIVATE mapping David Hildenbrand
2023-08-08 21:01   ` Peter Xu
2023-08-09  5:39     ` ThinerLogoer
2023-08-09  9:20     ` David Hildenbrand
2023-08-09 15:15       ` Peter Xu
2023-08-10 14:19         ` David Hildenbrand [this message]
2023-08-10 17:06           ` ThinerLogoer
2023-08-10 21:24             ` Peter Xu
2023-08-11  5:49               ` ThinerLogoer
2023-08-11 14:31                 ` Peter Xu
2023-08-12  6:21                   ` ThinerLogoer
2023-08-22 13:35                     ` David Hildenbrand
2023-08-11 19:00                 ` David Hildenbrand
2023-08-12  5:18                   ` ThinerLogoer
2023-08-17  9:07                     ` David Hildenbrand
2023-08-17 14:30                       ` David Hildenbrand
2023-08-17 14:37                         ` Daniel P. Berrangé
2023-08-17 14:37                           ` David Hildenbrand
2023-08-17 14:45                             ` Daniel P. Berrangé
2023-08-17 14:47                               ` David Hildenbrand
2023-08-17 14:41                       ` Peter Xu
2023-08-17 15:02                         ` David Hildenbrand
2023-08-17 15:13                       ` Stefan Hajnoczi
2023-08-17 15:15                         ` David Hildenbrand
2023-08-17 15:25                           ` David Hildenbrand
2023-08-17 15:31                           ` Peter Xu
2023-08-17 15:43                             ` David Hildenbrand
2023-08-17 13:46                   ` Daniel P. Berrangé
2023-08-17 13:48                     ` David Hildenbrand
2023-08-11 14:59               ` David Hildenbrand
2023-08-11 15:26                 ` David Hildenbrand
2023-08-11 16:16                   ` Peter Xu
2023-08-11 16:17                     ` David Hildenbrand
2023-08-11 16:22                       ` Peter Xu
2023-08-11 16:25                         ` David Hildenbrand
2023-08-11 16:54                           ` Peter Xu
2023-08-11 17:39                             ` David Hildenbrand
2023-08-11 21:07                               ` Peter Xu
2023-08-21 12:20                   ` Igor Mammedov
2023-08-11 15:47                 ` Peter Xu
2023-08-17 13:42           ` Daniel P. Berrangé
2023-08-17 13:45             ` David Hildenbrand
2023-08-17 13:37   ` Daniel P. Berrangé
2023-08-17 13:44     ` David Hildenbrand
2023-08-07 19:07 ` [PATCH v1 2/3] softmmu/physmem: fail creation of new files in file_ram_open() with readonly=true David Hildenbrand
2023-08-07 19:07 ` [PATCH v1 3/3] softmmu/physmem: never return directories from file_ram_open() David Hildenbrand
2023-08-08 17:26 ` Re:[PATCH v1 0/3] softmmu/physmem: file_ram_open() readonly improvements ThinerLogoer
2023-08-10 11:11   ` [PATCH " Philippe Mathieu-Daudé
2023-08-10 16:35     ` ThinerLogoer

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=e9c53fbd-369c-2605-1470-e67a765f923b@redhat.com \
    --to=david@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=logoerthiner1@163.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=philmd@linaro.org \
    --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).