qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Alexander Graf <graf@amazon.com>, qemu-devel@nongnu.org
Cc: Eduardo Habkost <eduardo@habkost.net>,
	"Daniel P . Berrange" <berrange@redhat.com>,
	Markus Armbruster <armbru@redhat.com>,
	Eric Blake <eblake@redhat.com>,
	Philippe Mathieu-Daude <philmd@linaro.org>,
	Peter Xu <peterx@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>,
	Igor Mammedov <imammedo@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Ashish Kalra <ashish.kalra@amd.com>
Subject: Re: [PATCH] hostmem-file: add offset option
Date: Fri, 3 Feb 2023 09:25:07 +0100	[thread overview]
Message-ID: <f2a2ac8a-e1f1-02ce-8dfb-72e1a09beef3@redhat.com> (raw)
In-Reply-To: <20230202225603.27559-1-graf@amazon.com>

On 02.02.23 23:56, Alexander Graf wrote:
> Add an option for hostmem-file to start the memory object at an offset
> into the target file. This is useful if multiple memory objects reside
> inside the same target file, such as a device node.
> 
> In particular, it's useful to map guest memory directly into /dev/mem
> for experimentation.
> 
> Signed-off-by: Alexander Graf <graf@amazon.com>
> ---

[...]

>   
> -    block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, 0, readonly, errp);
> +    block = qemu_ram_alloc_from_fd(size, mr, ram_flags, fd, offset, readonly,
> +                                   errp);

IIUC, the existing offset implementation is a bit broken:


(1) qemu_ram_alloc_from_fd() does not handle the offset parameter 
correctly: The "file_size > 0 && file_size < size" calculation does not 
seem to consider the offset when checking for file sizes.

(2) file_ram_alloc() most probably does not handle ftruncate() 
correctly. Especially on a yet empty file (where we set truncate=true), 
that might be insufficient.

(3) file_ram_alloc() and/or qemu_ram_alloc_from_fd() do not verify that 
the offset is properly aligned to block->page_size.


-- 
Thanks,

David / dhildenb



      parent reply	other threads:[~2023-02-03  8:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-02 22:56 [PATCH] hostmem-file: add offset option Alexander Graf
2023-02-03  6:59 ` Markus Armbruster
2023-02-03  8:25 ` David Hildenbrand [this message]

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=f2a2ac8a-e1f1-02ce-8dfb-72e1a09beef3@redhat.com \
    --to=david@redhat.com \
    --cc=armbru@redhat.com \
    --cc=ashish.kalra@amd.com \
    --cc=berrange@redhat.com \
    --cc=eblake@redhat.com \
    --cc=eduardo@habkost.net \
    --cc=graf@amazon.com \
    --cc=imammedo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.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).