All of lore.kernel.org
 help / color / mirror / Atom feed
* Initialize data memory in user space emulation
@ 2019-09-20  9:15 Libo Zhou
  2019-09-20 10:36 ` Peter Maydell
  0 siblings, 1 reply; 8+ messages in thread
From: Libo Zhou @ 2019-09-20  9:15 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 339 bytes --]

Hi all,


I need a way to manipulate data saved in a reserved memory region in linux user space emulation. I found the -B option very promising.  Documentation says it is useful when the address region required by guest applications is reserved on the host.


But how can I initialize that memory with data?



Thanks,
Libo Zhou

[-- Attachment #2: Type: text/html, Size: 662 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Initialize data memory in user space emulation
  2019-09-20  9:15 Initialize data memory in user space emulation Libo Zhou
@ 2019-09-20 10:36 ` Peter Maydell
  2019-09-20 14:49   ` Libo Zhou
  0 siblings, 1 reply; 8+ messages in thread
From: Peter Maydell @ 2019-09-20 10:36 UTC (permalink / raw)
  To: Libo Zhou; +Cc: qemu-devel

On Fri, 20 Sep 2019 at 10:25, Libo Zhou <zhlb29@foxmail.com> wrote:
>
> Hi all,
>
> I need a way to manipulate data saved in a reserved memory region in linux user space emulation. I found the -B option very promising.  Documentation says it is useful when the address region required by guest applications is reserved on the host.
>
> But how can I initialize that memory with data?

Hi -- this isn't really what the -B option does. What -B does
is set the 'guest base', which is the offset between what the
guest sees as its address 0 and what the host's address is. So
if you use -B to set the guest_base to 0x10000000, then when the
guest tries to mmap() a file to address 0x20000000 then we will
put the file at host address 0x30000000 (the address the guest
asks for plus the guest_base).

There is no way at all for the guest to access any data below the
guest_base address. The reason this option exists is in case the
default value QEMU chooses for guest_base would result in the guest
trying to mmap files in places that are already used by the host
QEMU binary or libraries. It's almost never an option users need
to set.

I'm not really sure what you mean by "a reserved memory region",
so it's a bit hard to say what might be the best way to do what
you want to do.

thanks
-- PMM


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re:  Initialize data memory in user space emulation
  2019-09-20 10:36 ` Peter Maydell
@ 2019-09-20 14:49   ` Libo Zhou
  2019-09-20 14:55     ` Peter Maydell
  0 siblings, 1 reply; 8+ messages in thread
From: Libo Zhou @ 2019-09-20 14:49 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel

Hi Peter,

Thanks for your explanation. Please let me add more details about what I need to do.

I need to emulate a Digital Signal Processor. The DSP essentially has only basic MIPS ISA, and it manipulates the data stored in a "data memory". I can run an ELF with user space emulation, what I need to additionally do is to initialize the "data memory" first, then run an ELF that manipulates the data in the "data memory", and finally see if the resulting data are correct or not.

Do you have any suggestions?

Cheers,
Libo Zhou

------------------ Original ------------------
From:  "Peter Maydell";<peter.maydell@linaro.org>;
Send time: Friday, Sep 20, 2019 6:36 PM
To: "Libo Zhou"<zhlb29@foxmail.com>; 
Cc: "qemu-devel"<qemu-devel@nongnu.org>; 
Subject:  Re: Initialize data memory in user space emulation

On Fri, 20 Sep 2019 at 10:25, Libo Zhou <zhlb29@foxmail.com> wrote:
>
> Hi all,
>
> I need a way to manipulate data saved in a reserved memory region in linux user space emulation. I found the -B option very promising.  Documentation says it is useful when the address region required by guest applications is reserved on the host.
>
> But how can I initialize that memory with data?

Hi -- this isn't really what the -B option does. What -B does
is set the 'guest base', which is the offset between what the
guest sees as its address 0 and what the host's address is. So
if you use -B to set the guest_base to 0x10000000, then when the
guest tries to mmap() a file to address 0x20000000 then we will
put the file at host address 0x30000000 (the address the guest
asks for plus the guest_base).

There is no way at all for the guest to access any data below the
guest_base address. The reason this option exists is in case the
default value QEMU chooses for guest_base would result in the guest
trying to mmap files in places that are already used by the host
QEMU binary or libraries. It's almost never an option users need
to set.

I'm not really sure what you mean by "a reserved memory region",
so it's a bit hard to say what might be the best way to do what
you want to do.

thanks
-- PMM

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Initialize data memory in user space emulation
  2019-09-20 14:49   ` Libo Zhou
@ 2019-09-20 14:55     ` Peter Maydell
  2019-09-20 15:26       ` Libo Zhou
  0 siblings, 1 reply; 8+ messages in thread
From: Peter Maydell @ 2019-09-20 14:55 UTC (permalink / raw)
  To: Libo Zhou; +Cc: qemu-devel

On Fri, 20 Sep 2019 at 15:49, Libo Zhou <zhlb29@foxmail.com> wrote:
> I need to emulate a Digital Signal Processor. The DSP essentially has only basic MIPS ISA, and it manipulates the data stored in a "data memory". I can run an ELF with user space emulation, what I need to additionally do is to initialize the "data memory" first, then run an ELF that manipulates the data in the "data memory", and finally see if the resulting data are correct or not.

QEMU doesn't really support doing that kind of thing, because
actual Linux binaries don't execute in an environment like that.
You could probably hack QEMU to mmap a file into the guest's
memory before we start to run the userspace process, but there's
nothing that will do what you want out of the box.

thanks
-- PMM


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re:  Initialize data memory in user space emulation
  2019-09-20 14:55     ` Peter Maydell
@ 2019-09-20 15:26       ` Libo Zhou
  2019-09-20 16:08         ` Peter Maydell
  0 siblings, 1 reply; 8+ messages in thread
From: Libo Zhou @ 2019-09-20 15:26 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel

I actually thought about hacking it to mmap from file into guest memory before running ELF. In include/exec/memory.h, the function memory_region_init_ram_from_file sounds like what I need. But the entire memory.h source file is wrapped by #ifndef CONFIG_USER_ONLY, I cannot use that API in user space emulation, right?

------------------ Original ------------------
From:  "Peter Maydell";<peter.maydell@linaro.org>;
Send time: Friday, Sep 20, 2019 10:55 PM
To: "Libo Zhou"<zhlb29@foxmail.com>; 
Cc: "qemu-devel"<qemu-devel@nongnu.org>; 
Subject:  Re: Initialize data memory in user space emulation

On Fri, 20 Sep 2019 at 15:49, Libo Zhou <zhlb29@foxmail.com> wrote:
> I need to emulate a Digital Signal Processor. The DSP essentially has only basic MIPS ISA, and it manipulates the data stored in a "data memory". I can run an ELF with user space emulation, what I need to additionally do is to initialize the "data memory" first, then run an ELF that manipulates the data in the "data memory", and finally see if the resulting data are correct or not.

QEMU doesn't really support doing that kind of thing, because
actual Linux binaries don't execute in an environment like that.
You could probably hack QEMU to mmap a file into the guest's
memory before we start to run the userspace process, but there's
nothing that will do what you want out of the box.

thanks
-- PMM

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Initialize data memory in user space emulation
  2019-09-20 15:26       ` Libo Zhou
@ 2019-09-20 16:08         ` Peter Maydell
  2019-09-20 16:29           ` Libo Zhou
  0 siblings, 1 reply; 8+ messages in thread
From: Peter Maydell @ 2019-09-20 16:08 UTC (permalink / raw)
  To: Libo Zhou; +Cc: qemu-devel

On Fri, 20 Sep 2019 at 16:26, Libo Zhou <zhlb29@foxmail.com> wrote:
>
> I actually thought about hacking it to mmap from file into guest memory before running ELF. In include/exec/memory.h, the function memory_region_init_ram_from_file sounds like what I need. But the entire memory.h source file is wrapped by #ifndef CONFIG_USER_ONLY, I cannot use that API in user space emulation, right?

Correct, you don't want to use that. You want
to put some code in linux-user/main.c, probably
just after the call to signal_init(), which opens
the host file and then calls target_mmap() to mmap
it into the host.

If you happen to have the source for the guest program,
you could also just make it do the open and mmap() itself
as the first thing it does in main() -- this is basically
equivalent. Or if the guest program is dynamically linked
then you can use QEMU's -E option to set the LD_PRELOAD
environment variable for the guest to make it load a guest
shared library that has a constructor function that does
the open/mmap before the guest main() gets control.

thanks
-- PMM


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re:  Initialize data memory in user space emulation
  2019-09-20 16:08         ` Peter Maydell
@ 2019-09-20 16:29           ` Libo Zhou
  0 siblings, 0 replies; 8+ messages in thread
From: Libo Zhou @ 2019-09-20 16:29 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel

Thanks for your insightful input. I will come back to this thread after I tried all the options.

Cheers,
Libo Zhou




------------------ Original ------------------
From:  "Peter Maydell";<peter.maydell@linaro.org>;
Send time: Saturday, Sep 21, 2019 0:08 AM
To: "Libo Zhou"<zhlb29@foxmail.com>; 
Cc: "qemu-devel"<qemu-devel@nongnu.org>; 
Subject:  Re: Initialize data memory in user space emulation



On Fri, 20 Sep 2019 at 16:26, Libo Zhou <zhlb29@foxmail.com> wrote:
>
> I actually thought about hacking it to mmap from file into guest memory before running ELF. In include/exec/memory.h, the function memory_region_init_ram_from_file sounds like what I need. But the entire memory.h source file is wrapped by #ifndef CONFIG_USER_ONLY, I cannot use that API in user space emulation, right?

Correct, you don't want to use that. You want
to put some code in linux-user/main.c, probably
just after the call to signal_init(), which opens
the host file and then calls target_mmap() to mmap
it into the host.

If you happen to have the source for the guest program,
you could also just make it do the open and mmap() itself
as the first thing it does in main() -- this is basically
equivalent. Or if the guest program is dynamically linked
then you can use QEMU's -E option to set the LD_PRELOAD
environment variable for the guest to make it load a guest
shared library that has a constructor function that does
the open/mmap before the guest main() gets control.

thanks
-- PMM

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Initialize data memory in user space emulation
@ 2019-09-20  9:40 Libo Zhou
  0 siblings, 0 replies; 8+ messages in thread
From: Libo Zhou @ 2019-09-20  9:40 UTC (permalink / raw)
  To: qemu-devel

Hi all,

I need a way to manipulate data saved in a reserved memory region in linux user space emulation. I found the -B option very promising.  Documentation says it is useful when the address region required by guest applications is reserved on the host.

But how can I initialize that memory with data?

Thanks,
Libo Zhou

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-09-20 16:33 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-20  9:15 Initialize data memory in user space emulation Libo Zhou
2019-09-20 10:36 ` Peter Maydell
2019-09-20 14:49   ` Libo Zhou
2019-09-20 14:55     ` Peter Maydell
2019-09-20 15:26       ` Libo Zhou
2019-09-20 16:08         ` Peter Maydell
2019-09-20 16:29           ` Libo Zhou
2019-09-20  9:40 Libo Zhou

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.