* [Qemu-devel] KVM/QEMU: Support executing from flash device
@ 2012-03-04 6:56 Jordan Justen
2012-03-04 8:12 ` Gleb Natapov
2012-03-04 10:44 ` Avi Kivity
0 siblings, 2 replies; 7+ messages in thread
From: Jordan Justen @ 2012-03-04 6:56 UTC (permalink / raw)
To: Avi Kivity; +Cc: Jordan Justen, qemu-devel, kvm-devel, Alexander Graf
On Tue, Oct 25, 2011 at 00:47, Avi Kivity <avi@redhat.com> wrote:
> The core issue that kvm (the kernel part) supports two styles of memory:
> read/write RAM, and read/write MMIO. ROM wants writes to be ignored,
> and rom/device wants reads serviced from memory and writes serviced by
> userspace (as MMIO).
>
> It should not be too hard to patch kvm to support these additional two
> styles. The entry point is the KVM_SET_USER_MEMORY_REGION ioctl to
> define the new attributes for the region, and kvm_mmu_page_fault() to
> map these pages as read-only and emulate writes (for ROM/device regions).
Additional context for CC'd kvm-devel: I would like to support
executing from an emulated flash memory on kvm. The flash memory
would be a CFI (Firmware Hub-like) device which is programmed via MMIO
at the same addresses in memory where the execution would occur.
What is needed is:
1. The ability to set a region to allow read/exec,
but trap to qemu on writes.
2. qemu should then be able to set the region
to trap on reads/exec/writes.
3. qemu should be able to then restore the region
to the initial state.
Here is my plan:
1. Add KVM_CAP_REGION_WRITE_TRAP
2. Add kvm_memory_region::flags
KVM_MEMSLOT_TRAP_WRITES
3. Update page table creation to trap on writes when
KVM_MEMSLOT_TRAP_WRITES is set
Is this plan heading in the right direction?
Regarding emulating ROM (as you mentioned above): I think that it can
trap to qemu and QEMU can ignore it. This would be a performance hit,
but I don't think it is expected that lots of writes to a ROM will
occur. Do you agree?
-Jordan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] KVM/QEMU: Support executing from flash device
2012-03-04 6:56 [Qemu-devel] KVM/QEMU: Support executing from flash device Jordan Justen
@ 2012-03-04 8:12 ` Gleb Natapov
2012-03-04 10:36 ` Avi Kivity
2012-03-04 10:44 ` Avi Kivity
1 sibling, 1 reply; 7+ messages in thread
From: Gleb Natapov @ 2012-03-04 8:12 UTC (permalink / raw)
To: Jordan Justen
Cc: Jordan Justen, Alexander Graf, Avi Kivity, kvm-devel, qemu-devel
On Sat, Mar 03, 2012 at 10:56:02PM -0800, Jordan Justen wrote:
> On Tue, Oct 25, 2011 at 00:47, Avi Kivity <avi@redhat.com> wrote:
> > The core issue that kvm (the kernel part) supports two styles of memory:
> > read/write RAM, and read/write MMIO. ROM wants writes to be ignored,
> > and rom/device wants reads serviced from memory and writes serviced by
> > userspace (as MMIO).
> >
> > It should not be too hard to patch kvm to support these additional two
> > styles. The entry point is the KVM_SET_USER_MEMORY_REGION ioctl to
> > define the new attributes for the region, and kvm_mmu_page_fault() to
> > map these pages as read-only and emulate writes (for ROM/device regions).
>
> Additional context for CC'd kvm-devel: I would like to support
> executing from an emulated flash memory on kvm. The flash memory
> would be a CFI (Firmware Hub-like) device which is programmed via MMIO
> at the same addresses in memory where the execution would occur.
>
> What is needed is:
> 1. The ability to set a region to allow read/exec,
> but trap to qemu on writes.
> 2. qemu should then be able to set the region
> to trap on reads/exec/writes.
Do you want to execute code from a flash while it traps on read/exec?
KVM emulator can't do that.
> 3. qemu should be able to then restore the region
> to the initial state.
>
> Here is my plan:
> 1. Add KVM_CAP_REGION_WRITE_TRAP
> 2. Add kvm_memory_region::flags
> KVM_MEMSLOT_TRAP_WRITES
> 3. Update page table creation to trap on writes when
> KVM_MEMSLOT_TRAP_WRITES is set
>
> Is this plan heading in the right direction?
>
> Regarding emulating ROM (as you mentioned above): I think that it can
> trap to qemu and QEMU can ignore it. This would be a performance hit,
> but I don't think it is expected that lots of writes to a ROM will
> occur. Do you agree?
>
> -Jordan
--
Gleb.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] KVM/QEMU: Support executing from flash device
2012-03-04 8:12 ` Gleb Natapov
@ 2012-03-04 10:36 ` Avi Kivity
2012-03-04 10:38 ` Gleb Natapov
0 siblings, 1 reply; 7+ messages in thread
From: Avi Kivity @ 2012-03-04 10:36 UTC (permalink / raw)
To: Gleb Natapov
Cc: Jordan Justen, Jordan Justen, qemu-devel, kvm-devel,
Alexander Graf
On 03/04/2012 10:12 AM, Gleb Natapov wrote:
> On Sat, Mar 03, 2012 at 10:56:02PM -0800, Jordan Justen wrote:
> > On Tue, Oct 25, 2011 at 00:47, Avi Kivity <avi@redhat.com> wrote:
> > > The core issue that kvm (the kernel part) supports two styles of memory:
> > > read/write RAM, and read/write MMIO. ROM wants writes to be ignored,
> > > and rom/device wants reads serviced from memory and writes serviced by
> > > userspace (as MMIO).
> > >
> > > It should not be too hard to patch kvm to support these additional two
> > > styles. The entry point is the KVM_SET_USER_MEMORY_REGION ioctl to
> > > define the new attributes for the region, and kvm_mmu_page_fault() to
> > > map these pages as read-only and emulate writes (for ROM/device regions).
> >
> > Additional context for CC'd kvm-devel: I would like to support
> > executing from an emulated flash memory on kvm. The flash memory
> > would be a CFI (Firmware Hub-like) device which is programmed via MMIO
> > at the same addresses in memory where the execution would occur.
> >
> > What is needed is:
> > 1. The ability to set a region to allow read/exec,
> > but trap to qemu on writes.
> > 2. qemu should then be able to set the region
> > to trap on reads/exec/writes.
> Do you want to execute code from a flash while it traps on read/exec?
> KVM emulator can't do that.
No, he wants read/exec to go to RAM, and writes to be handled as mmio.
This should work.
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] KVM/QEMU: Support executing from flash device
2012-03-04 10:36 ` Avi Kivity
@ 2012-03-04 10:38 ` Gleb Natapov
2012-03-04 10:46 ` Avi Kivity
0 siblings, 1 reply; 7+ messages in thread
From: Gleb Natapov @ 2012-03-04 10:38 UTC (permalink / raw)
To: Avi Kivity
Cc: Jordan Justen, Jordan Justen, qemu-devel, kvm-devel,
Alexander Graf
On Sun, Mar 04, 2012 at 12:36:20PM +0200, Avi Kivity wrote:
> On 03/04/2012 10:12 AM, Gleb Natapov wrote:
> > On Sat, Mar 03, 2012 at 10:56:02PM -0800, Jordan Justen wrote:
> > > On Tue, Oct 25, 2011 at 00:47, Avi Kivity <avi@redhat.com> wrote:
> > > > The core issue that kvm (the kernel part) supports two styles of memory:
> > > > read/write RAM, and read/write MMIO. ROM wants writes to be ignored,
> > > > and rom/device wants reads serviced from memory and writes serviced by
> > > > userspace (as MMIO).
> > > >
> > > > It should not be too hard to patch kvm to support these additional two
> > > > styles. The entry point is the KVM_SET_USER_MEMORY_REGION ioctl to
> > > > define the new attributes for the region, and kvm_mmu_page_fault() to
> > > > map these pages as read-only and emulate writes (for ROM/device regions).
> > >
> > > Additional context for CC'd kvm-devel: I would like to support
> > > executing from an emulated flash memory on kvm. The flash memory
> > > would be a CFI (Firmware Hub-like) device which is programmed via MMIO
> > > at the same addresses in memory where the execution would occur.
> > >
> > > What is needed is:
> > > 1. The ability to set a region to allow read/exec,
> > > but trap to qemu on writes.
> > > 2. qemu should then be able to set the region
> > > to trap on reads/exec/writes.
> > Do you want to execute code from a flash while it traps on read/exec?
> > KVM emulator can't do that.
>
> No, he wants read/exec to go to RAM, and writes to be handled as mmio.
> This should work.
>
That's mode 1 from above and will obviously work. I am asking about mode
2 from above.
--
Gleb.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] KVM/QEMU: Support executing from flash device
2012-03-04 6:56 [Qemu-devel] KVM/QEMU: Support executing from flash device Jordan Justen
2012-03-04 8:12 ` Gleb Natapov
@ 2012-03-04 10:44 ` Avi Kivity
1 sibling, 0 replies; 7+ messages in thread
From: Avi Kivity @ 2012-03-04 10:44 UTC (permalink / raw)
To: Jordan Justen
Cc: Jordan Justen, Jan Kiszka, qemu-devel, kvm-devel, Alexander Graf
On 03/04/2012 08:56 AM, Jordan Justen wrote:
> On Tue, Oct 25, 2011 at 00:47, Avi Kivity <avi@redhat.com> wrote:
> > The core issue that kvm (the kernel part) supports two styles of memory:
> > read/write RAM, and read/write MMIO. ROM wants writes to be ignored,
> > and rom/device wants reads serviced from memory and writes serviced by
> > userspace (as MMIO).
> >
> > It should not be too hard to patch kvm to support these additional two
> > styles. The entry point is the KVM_SET_USER_MEMORY_REGION ioctl to
> > define the new attributes for the region, and kvm_mmu_page_fault() to
> > map these pages as read-only and emulate writes (for ROM/device regions).
>
> Additional context for CC'd kvm-devel: I would like to support
> executing from an emulated flash memory on kvm. The flash memory
> would be a CFI (Firmware Hub-like) device which is programmed via MMIO
> at the same addresses in memory where the execution would occur.
>
> What is needed is:
> 1. The ability to set a region to allow read/exec,
> but trap to qemu on writes.
> 2. qemu should then be able to set the region
> to trap on reads/exec/writes.
> 3. qemu should be able to then restore the region
> to the initial state.
>
> Here is my plan:
> 1. Add KVM_CAP_REGION_WRITE_TRAP
> 2. Add kvm_memory_region::flags
> KVM_MEMSLOT_TRAP_WRITES
> 3. Update page table creation to trap on writes when
> KVM_MEMSLOT_TRAP_WRITES is set
>
> Is this plan heading in the right direction?
Sure. I'd name things differently, call this type of slot readonly
instead of write trapping (that is, say what works in kvm (reads)
instead of what doesn't (writes).
Note you need to update kvm_userspace_memory_region, not
kvm_memory_region, which has been deprecated since 2.6.24 or so.
> Regarding emulating ROM (as you mentioned above): I think that it can
> trap to qemu and QEMU can ignore it. This would be a performance hit,
> but I don't think it is expected that lots of writes to a ROM will
> occur. Do you agree?
I do, I don't foresee any problems in this area.
Only potential issue is vapic writing to a ROM region, but Jan's recent
work adds a hackaround for that (vapic_map_rom_writable()).
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] KVM/QEMU: Support executing from flash device
2012-03-04 10:38 ` Gleb Natapov
@ 2012-03-04 10:46 ` Avi Kivity
2012-03-04 21:11 ` Jordan Justen
0 siblings, 1 reply; 7+ messages in thread
From: Avi Kivity @ 2012-03-04 10:46 UTC (permalink / raw)
To: Gleb Natapov
Cc: Jordan Justen, Jordan Justen, qemu-devel, kvm-devel,
Alexander Graf
On 03/04/2012 12:38 PM, Gleb Natapov wrote:
> On Sun, Mar 04, 2012 at 12:36:20PM +0200, Avi Kivity wrote:
> > On 03/04/2012 10:12 AM, Gleb Natapov wrote:
> > > On Sat, Mar 03, 2012 at 10:56:02PM -0800, Jordan Justen wrote:
> > > > On Tue, Oct 25, 2011 at 00:47, Avi Kivity <avi@redhat.com> wrote:
> > > > > The core issue that kvm (the kernel part) supports two styles of memory:
> > > > > read/write RAM, and read/write MMIO. ROM wants writes to be ignored,
> > > > > and rom/device wants reads serviced from memory and writes serviced by
> > > > > userspace (as MMIO).
> > > > >
> > > > > It should not be too hard to patch kvm to support these additional two
> > > > > styles. The entry point is the KVM_SET_USER_MEMORY_REGION ioctl to
> > > > > define the new attributes for the region, and kvm_mmu_page_fault() to
> > > > > map these pages as read-only and emulate writes (for ROM/device regions).
> > > >
> > > > Additional context for CC'd kvm-devel: I would like to support
> > > > executing from an emulated flash memory on kvm. The flash memory
> > > > would be a CFI (Firmware Hub-like) device which is programmed via MMIO
> > > > at the same addresses in memory where the execution would occur.
> > > >
> > > > What is needed is:
> > > > 1. The ability to set a region to allow read/exec,
> > > > but trap to qemu on writes.
> > > > 2. qemu should then be able to set the region
> > > > to trap on reads/exec/writes.
> > > Do you want to execute code from a flash while it traps on read/exec?
> > > KVM emulator can't do that.
> >
> > No, he wants read/exec to go to RAM, and writes to be handled as mmio.
> > This should work.
> >
> That's mode 1 from above and will obviously work. I am asking about mode
> 2 from above.
>
Mode 2 is pure mmio. You're right that kvm won't run code from that.
Jordan, what's the use for mode 2? Is it just used during programming?
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] KVM/QEMU: Support executing from flash device
2012-03-04 10:46 ` Avi Kivity
@ 2012-03-04 21:11 ` Jordan Justen
0 siblings, 0 replies; 7+ messages in thread
From: Jordan Justen @ 2012-03-04 21:11 UTC (permalink / raw)
To: Avi Kivity
Cc: Jordan Justen, Alexander Graf, qemu-devel, Gleb Natapov,
kvm-devel
On Sun, Mar 4, 2012 at 02:46, Avi Kivity <avi@redhat.com> wrote:
> On 03/04/2012 12:38 PM, Gleb Natapov wrote:
>> On Sun, Mar 04, 2012 at 12:36:20PM +0200, Avi Kivity wrote:
>> > On 03/04/2012 10:12 AM, Gleb Natapov wrote:
>> > > On Sat, Mar 03, 2012 at 10:56:02PM -0800, Jordan Justen wrote:
>> > > > On Tue, Oct 25, 2011 at 00:47, Avi Kivity <avi@redhat.com> wrote:
>> > > > > The core issue that kvm (the kernel part) supports two styles of memory:
>> > > > > read/write RAM, and read/write MMIO. ROM wants writes to be ignored,
>> > > > > and rom/device wants reads serviced from memory and writes serviced by
>> > > > > userspace (as MMIO).
>> > > > >
>> > > > > It should not be too hard to patch kvm to support these additional two
>> > > > > styles. The entry point is the KVM_SET_USER_MEMORY_REGION ioctl to
>> > > > > define the new attributes for the region, and kvm_mmu_page_fault() to
>> > > > > map these pages as read-only and emulate writes (for ROM/device regions).
>> > > >
>> > > > Additional context for CC'd kvm-devel: I would like to support
>> > > > executing from an emulated flash memory on kvm. The flash memory
>> > > > would be a CFI (Firmware Hub-like) device which is programmed via MMIO
>> > > > at the same addresses in memory where the execution would occur.
>> > > >
>> > > > What is needed is:
>> > > > 1. The ability to set a region to allow read/exec,
>> > > > but trap to qemu on writes.
>> > > > 2. qemu should then be able to set the region
>> > > > to trap on reads/exec/writes.
>> > > Do you want to execute code from a flash while it traps on read/exec?
>> > > KVM emulator can't do that.
>> >
>> > No, he wants read/exec to go to RAM, and writes to be handled as mmio.
>> > This should work.
>> >
>> That's mode 1 from above and will obviously work. I am asking about mode
>> 2 from above.
>>
>
> Mode 2 is pure mmio. You're right that kvm won't run code from that.
>
> Jordan, what's the use for mode 2? Is it just used during programming?
Yes. It is the programming state for the flash, and no execution
would occur from the region while it is in that state. At least for
the flash that I'm interested in supporting (qemu:hw/pflash_cfi01.c),
it would not be possible to execute from the flash in this mode
because the entire region will no longer read-back the flash contents.
-Jordan
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-03-04 21:11 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-04 6:56 [Qemu-devel] KVM/QEMU: Support executing from flash device Jordan Justen
2012-03-04 8:12 ` Gleb Natapov
2012-03-04 10:36 ` Avi Kivity
2012-03-04 10:38 ` Gleb Natapov
2012-03-04 10:46 ` Avi Kivity
2012-03-04 21:11 ` Jordan Justen
2012-03-04 10:44 ` Avi Kivity
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).