public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* Correct way of tracking reads on given gfn ?
@ 2013-09-09  9:45 Sunil
  2013-09-09 10:08 ` Paolo Bonzini
  0 siblings, 1 reply; 7+ messages in thread
From: Sunil @ 2013-09-09  9:45 UTC (permalink / raw)
  To: kvm@vger.kernel.org

Hello List,

(1) What is the correct way of tracking reads on given gfn ?

Looks like functions rmap_write_protect(kvm, gfn) and
kvm_mmu_rmap_write_protect(kvm, gfn, slot) removes the write
permission for the given page, by flipping write bit using
PT_WRITABLE_MASK. Thus trapping writes.

For trapping reads, are there similar routines ? If not, I see
equivalent flag PM_PRESENT_MASK. Thus one way probably is writing
wrapper routines similar to above to flip both read(present) and write
bits. Or would it be just enough to drop the spte instead using
function drop_spte() ?

(2) Is kvm_flush_remote_tlbs() required after either of above approaches ?
Is kvm_flush_remote_tlbs() correct function to flush tlbs ?

--

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

* Re: Correct way of tracking reads on given gfn ?
  2013-09-09  9:45 Correct way of tracking reads on given gfn ? Sunil
@ 2013-09-09 10:08 ` Paolo Bonzini
  2013-09-09 10:22   ` SPA
  0 siblings, 1 reply; 7+ messages in thread
From: Paolo Bonzini @ 2013-09-09 10:08 UTC (permalink / raw)
  To: Sunil; +Cc: kvm@vger.kernel.org

Il 09/09/2013 11:45, Sunil ha scritto:
> Hello List,
> 
> (1) What is the correct way of tracking reads on given gfn ?
> 
> Looks like functions rmap_write_protect(kvm, gfn) and
> kvm_mmu_rmap_write_protect(kvm, gfn, slot) removes the write
> permission for the given page, by flipping write bit using
> PT_WRITABLE_MASK. Thus trapping writes.
> 
> For trapping reads, are there similar routines ? If not, I see
> equivalent flag PM_PRESENT_MASK. Thus one way probably is writing
> wrapper routines similar to above to flip both read(present) and write
> bits. Or would it be just enough to drop the spte instead using
> function drop_spte() ?

If you are using EPT and your processor has the accessed and dirty bits
for EPT page tables (cat /sys/module/kvm_intel/parameters/eptad), you
could use the accessed bit to track reads.  They wouldn't trap, but you
would be able to poll the EPT page tables.

Paolo

> (2) Is kvm_flush_remote_tlbs() required after either of above approaches ?
> Is kvm_flush_remote_tlbs() correct function to flush tlbs ?
> 
> --
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


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

* Re: Correct way of tracking reads on given gfn ?
  2013-09-09 10:08 ` Paolo Bonzini
@ 2013-09-09 10:22   ` SPA
  2013-09-09 10:53     ` Paolo Bonzini
  0 siblings, 1 reply; 7+ messages in thread
From: SPA @ 2013-09-09 10:22 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: kvm@vger.kernel.org

Thanks Paolo.

Is there a way where reads would trap ?

I explored a bit on PM_PRESENT_MASK.  Though its not READ bit, but a
PRESENT bit,  it looks like it should generate traps on reads if this
bit is reset. From code, looks like rmap_write_protect() like function
I stated in previous mail should do. Would this approach work ? Are
there any glaring problems with this approach ?

--
Sunil

On Mon, Sep 9, 2013 at 3:08 AM, Paolo Bonzini <pbonzini@redhat.com> wrote:
> Il 09/09/2013 11:45, Sunil ha scritto:
>> Hello List,
>>
>> (1) What is the correct way of tracking reads on given gfn ?
>>
>> Looks like functions rmap_write_protect(kvm, gfn) and
>> kvm_mmu_rmap_write_protect(kvm, gfn, slot) removes the write
>> permission for the given page, by flipping write bit using
>> PT_WRITABLE_MASK. Thus trapping writes.
>>
>> For trapping reads, are there similar routines ? If not, I see
>> equivalent flag PM_PRESENT_MASK. Thus one way probably is writing
>> wrapper routines similar to above to flip both read(present) and write
>> bits. Or would it be just enough to drop the spte instead using
>> function drop_spte() ?
>
> If you are using EPT and your processor has the accessed and dirty bits
> for EPT page tables (cat /sys/module/kvm_intel/parameters/eptad), you
> could use the accessed bit to track reads.  They wouldn't trap, but you
> would be able to poll the EPT page tables.
>
> Paolo
>
>> (2) Is kvm_flush_remote_tlbs() required after either of above approaches ?
>> Is kvm_flush_remote_tlbs() correct function to flush tlbs ?
>>
>> --
>> --
>> To unsubscribe from this list: send the line "unsubscribe kvm" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>
>
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: Correct way of tracking reads on given gfn ?
  2013-09-09 10:22   ` SPA
@ 2013-09-09 10:53     ` Paolo Bonzini
  2013-09-09 12:29       ` Gleb Natapov
  0 siblings, 1 reply; 7+ messages in thread
From: Paolo Bonzini @ 2013-09-09 10:53 UTC (permalink / raw)
  To: SPA; +Cc: kvm@vger.kernel.org

Il 09/09/2013 12:22, SPA ha scritto:
> Thanks Paolo.
> 
> Is there a way where reads would trap ?
> 
> I explored a bit on PM_PRESENT_MASK.  Though its not READ bit, but a
> PRESENT bit,  it looks like it should generate traps on reads if this
> bit is reset. From code, looks like rmap_write_protect() like function
> I stated in previous mail should do. Would this approach work ? Are
> there any glaring problems with this approach ?

I cannot say right away.  Another way could be to set reserved bits to
generate EPT misconfigurations.  See ept_set_mmio_spte_mask and
is_mmio_spte.

This would trap both reads and writes.

Paolo

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

* Re: Correct way of tracking reads on given gfn ?
  2013-09-09 10:53     ` Paolo Bonzini
@ 2013-09-09 12:29       ` Gleb Natapov
  2013-09-10  1:12         ` Arthur Chunqi Li
  0 siblings, 1 reply; 7+ messages in thread
From: Gleb Natapov @ 2013-09-09 12:29 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: SPA, kvm@vger.kernel.org

On Mon, Sep 09, 2013 at 12:53:02PM +0200, Paolo Bonzini wrote:
> Il 09/09/2013 12:22, SPA ha scritto:
> > Thanks Paolo.
> > 
> > Is there a way where reads would trap ?
> > 
> > I explored a bit on PM_PRESENT_MASK.  Though its not READ bit, but a
> > PRESENT bit,  it looks like it should generate traps on reads if this
> > bit is reset. From code, looks like rmap_write_protect() like function
> > I stated in previous mail should do. Would this approach work ? Are
> > there any glaring problems with this approach ?
> 
> I cannot say right away.  Another way could be to set reserved bits to
> generate EPT misconfigurations.  See ept_set_mmio_spte_mask and
> is_mmio_spte.
> 
> This would trap both reads and writes.
> 
Dropping all sptes will also work, but trapping each read access will be dog slow. QEMU
emulation will be much faster.

--
			Gleb.

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

* Re: Correct way of tracking reads on given gfn ?
  2013-09-09 12:29       ` Gleb Natapov
@ 2013-09-10  1:12         ` Arthur Chunqi Li
  2013-09-10  6:08           ` Gleb Natapov
  0 siblings, 1 reply; 7+ messages in thread
From: Arthur Chunqi Li @ 2013-09-10  1:12 UTC (permalink / raw)
  To: Gleb Natapov; +Cc: Paolo Bonzini, SPA, kvm@vger.kernel.org

On Mon, Sep 9, 2013 at 8:29 PM, Gleb Natapov <gleb@redhat.com> wrote:
> On Mon, Sep 09, 2013 at 12:53:02PM +0200, Paolo Bonzini wrote:
>> Il 09/09/2013 12:22, SPA ha scritto:
>> > Thanks Paolo.
>> >
>> > Is there a way where reads would trap ?
>> >
>> > I explored a bit on PM_PRESENT_MASK.  Though its not READ bit, but a
>> > PRESENT bit,  it looks like it should generate traps on reads if this
>> > bit is reset. From code, looks like rmap_write_protect() like function
>> > I stated in previous mail should do. Would this approach work ? Are
>> > there any glaring problems with this approach ?
>>
>> I cannot say right away.  Another way could be to set reserved bits to
>> generate EPT misconfigurations.  See ept_set_mmio_spte_mask and
>> is_mmio_spte.
>>
>> This would trap both reads and writes.
>>
> Dropping all sptes will also work, but trapping each read access will be dog slow. QEMU
> emulation will be much faster.
Hi Gleb,
I'm interested in this topic, what do you mean by QEMU emulation? Do
you mean the functions in arch/x86/kvm/emulate.c? In what scenario
will KVM call these functions?

Thanks,
Arthur
>
> --
>                         Gleb.
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: Correct way of tracking reads on given gfn ?
  2013-09-10  1:12         ` Arthur Chunqi Li
@ 2013-09-10  6:08           ` Gleb Natapov
  0 siblings, 0 replies; 7+ messages in thread
From: Gleb Natapov @ 2013-09-10  6:08 UTC (permalink / raw)
  To: Arthur Chunqi Li; +Cc: Paolo Bonzini, SPA, kvm@vger.kernel.org

On Tue, Sep 10, 2013 at 09:12:11AM +0800, Arthur Chunqi Li wrote:
> On Mon, Sep 9, 2013 at 8:29 PM, Gleb Natapov <gleb@redhat.com> wrote:
> > On Mon, Sep 09, 2013 at 12:53:02PM +0200, Paolo Bonzini wrote:
> >> Il 09/09/2013 12:22, SPA ha scritto:
> >> > Thanks Paolo.
> >> >
> >> > Is there a way where reads would trap ?
> >> >
> >> > I explored a bit on PM_PRESENT_MASK.  Though its not READ bit, but a
> >> > PRESENT bit,  it looks like it should generate traps on reads if this
> >> > bit is reset. From code, looks like rmap_write_protect() like function
> >> > I stated in previous mail should do. Would this approach work ? Are
> >> > there any glaring problems with this approach ?
> >>
> >> I cannot say right away.  Another way could be to set reserved bits to
> >> generate EPT misconfigurations.  See ept_set_mmio_spte_mask and
> >> is_mmio_spte.
> >>
> >> This would trap both reads and writes.
> >>
> > Dropping all sptes will also work, but trapping each read access will be dog slow. QEMU
> > emulation will be much faster.
> Hi Gleb,
> I'm interested in this topic, what do you mean by QEMU emulation? Do
> you mean the functions in arch/x86/kvm/emulate.c? In what scenario
> will KVM call these functions?
> 
No, I mean don't use KVM at all.

--
			Gleb.

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

end of thread, other threads:[~2013-09-10  6:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-09  9:45 Correct way of tracking reads on given gfn ? Sunil
2013-09-09 10:08 ` Paolo Bonzini
2013-09-09 10:22   ` SPA
2013-09-09 10:53     ` Paolo Bonzini
2013-09-09 12:29       ` Gleb Natapov
2013-09-10  1:12         ` Arthur Chunqi Li
2013-09-10  6:08           ` Gleb Natapov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox