Linux-mm Archive on lore.kernel.org
 help / color / Atom feed
* [Question-kvm] Can hva_to_pfn_fast be executed in interrupt context?
@ 2019-08-13 19:14 Bharath Vedartham
  2019-08-13 20:17 ` Paolo Bonzini
  0 siblings, 1 reply; 5+ messages in thread
From: Bharath Vedartham @ 2019-08-13 19:14 UTC (permalink / raw)
  To: pbonzini, rkrcmar; +Cc: kvm, linux-kernel, linux-mm, khalid.aziz

Hi all,

I was looking at the function hva_to_pfn_fast(in virt/kvm/kvm_main) which is 
executed in an atomic context(even in non-atomic context, since
hva_to_pfn_fast is much faster than hva_to_pfn_slow).

My question is can this be executed in an interrupt context? 

The motivation for this question is that in an interrupt context, we cannot
assume "current" to be the task_struct of the process of interest.
__get_user_pages_fast assume current->mm when walking the process page
tables. 

So if this function hva_to_pfn_fast can be executed in an
interrupt context, it would not be safe to retrive the pfn with
__get_user_pages_fast. 

Thoughts on this?

Thank you
Bharath


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

* Re: [Question-kvm] Can hva_to_pfn_fast be executed in interrupt context?
  2019-08-13 19:14 [Question-kvm] Can hva_to_pfn_fast be executed in interrupt context? Bharath Vedartham
@ 2019-08-13 20:17 ` Paolo Bonzini
  2019-08-15 17:18   ` Bharath Vedartham
  0 siblings, 1 reply; 5+ messages in thread
From: Paolo Bonzini @ 2019-08-13 20:17 UTC (permalink / raw)
  To: Bharath Vedartham, rkrcmar; +Cc: kvm, linux-kernel, linux-mm, khalid.aziz

On 13/08/19 21:14, Bharath Vedartham wrote:
> Hi all,
> 
> I was looking at the function hva_to_pfn_fast(in virt/kvm/kvm_main) which is 
> executed in an atomic context(even in non-atomic context, since
> hva_to_pfn_fast is much faster than hva_to_pfn_slow).
> 
> My question is can this be executed in an interrupt context? 

No, it cannot for the reason you mention below.

Paolo

> The motivation for this question is that in an interrupt context, we cannot
> assume "current" to be the task_struct of the process of interest.
> __get_user_pages_fast assume current->mm when walking the process page
> tables. 
> 
> So if this function hva_to_pfn_fast can be executed in an
> interrupt context, it would not be safe to retrive the pfn with
> __get_user_pages_fast. 
> 
> Thoughts on this?
> 
> Thank you
> Bharath
> 



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

* Re: [Question-kvm] Can hva_to_pfn_fast be executed in interrupt context?
  2019-08-13 20:17 ` Paolo Bonzini
@ 2019-08-15 17:18   ` Bharath Vedartham
  2019-08-15 18:26     ` Paolo Bonzini
  0 siblings, 1 reply; 5+ messages in thread
From: Bharath Vedartham @ 2019-08-15 17:18 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: rkrcmar, kvm, linux-kernel, linux-mm, khalid.aziz

On Tue, Aug 13, 2019 at 10:17:09PM +0200, Paolo Bonzini wrote:
> On 13/08/19 21:14, Bharath Vedartham wrote:
> > Hi all,
> > 
> > I was looking at the function hva_to_pfn_fast(in virt/kvm/kvm_main) which is 
> > executed in an atomic context(even in non-atomic context, since
> > hva_to_pfn_fast is much faster than hva_to_pfn_slow).
> > 
> > My question is can this be executed in an interrupt context? 
> 
> No, it cannot for the reason you mention below.
> 
> Paolo
hmm.. Well I expected the answer to be kvm specific. 
Because I observed a similar use-case for a driver (sgi-gru) where 
we want to retrive the physical address of a virtual address. This was
done in atomic and non-atomic context similar to hva_to_pfn_fast and
hva_to_pfn_slow. __get_user_pages_fast(for atomic case) 
would not work as the driver could execute in interrupt context.

The driver manually walked the page tables to handle this issue.

Since kvm is a widely used piece of code, I asked this question to know
how kvm handled this issue. 

Thank you for your time.

Thank you
Bharath
> > The motivation for this question is that in an interrupt context, we cannot
> > assume "current" to be the task_struct of the process of interest.
> > __get_user_pages_fast assume current->mm when walking the process page
> > tables. 
> > 
> > So if this function hva_to_pfn_fast can be executed in an
> > interrupt context, it would not be safe to retrive the pfn with
> > __get_user_pages_fast. 
> > 
> > Thoughts on this?
> > 
> > Thank you
> > Bharath
> > 
> 


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

* Re: [Question-kvm] Can hva_to_pfn_fast be executed in interrupt context?
  2019-08-15 17:18   ` Bharath Vedartham
@ 2019-08-15 18:26     ` Paolo Bonzini
  2019-08-20 16:08       ` Bharath Vedartham
  0 siblings, 1 reply; 5+ messages in thread
From: Paolo Bonzini @ 2019-08-15 18:26 UTC (permalink / raw)
  To: Bharath Vedartham; +Cc: Radim Krcmar, kvm, linux-kernel, linux-mm, khalid.aziz

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

Oh, I see. Sorry I didn't understand the question. In the case of KVM,
there's simply no code that runs in interrupt context and needs to use
virtual addresses.

In fact, there's no code that runs in interrupt context at all. The only
code that deals with host interrupts in a virtualization host is in VFIO,
but all it needs to do is signal an eventfd.

Paolo


Il gio 15 ago 2019, 19:18 Bharath Vedartham <linux.bhar@gmail.com> ha
scritto:

> On Tue, Aug 13, 2019 at 10:17:09PM +0200, Paolo Bonzini wrote:
> > On 13/08/19 21:14, Bharath Vedartham wrote:
> > > Hi all,
> > >
> > > I was looking at the function hva_to_pfn_fast(in virt/kvm/kvm_main)
> which is
> > > executed in an atomic context(even in non-atomic context, since
> > > hva_to_pfn_fast is much faster than hva_to_pfn_slow).
> > >
> > > My question is can this be executed in an interrupt context?
> >
> > No, it cannot for the reason you mention below.
> >
> > Paolo
> hmm.. Well I expected the answer to be kvm specific.
> Because I observed a similar use-case for a driver (sgi-gru) where
> we want to retrive the physical address of a virtual address. This was
> done in atomic and non-atomic context similar to hva_to_pfn_fast and
> hva_to_pfn_slow. __get_user_pages_fast(for atomic case)
> would not work as the driver could execute in interrupt context.
>
> The driver manually walked the page tables to handle this issue.
>
> Since kvm is a widely used piece of code, I asked this question to know
> how kvm handled this issue.
>
> Thank you for your time.
>
> Thank you
> Bharath
> > > The motivation for this question is that in an interrupt context, we
> cannot
> > > assume "current" to be the task_struct of the process of interest.
> > > __get_user_pages_fast assume current->mm when walking the process page
> > > tables.
> > >
> > > So if this function hva_to_pfn_fast can be executed in an
> > > interrupt context, it would not be safe to retrive the pfn with
> > > __get_user_pages_fast.
> > >
> > > Thoughts on this?
> > >
> > > Thank you
> > > Bharath
> > >
> >
>

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

<div dir="auto">Oh, I see. Sorry I didn&#39;t understand the question. In the case of KVM, there&#39;s simply no code that runs in interrupt context and needs to use virtual addresses.<div dir="auto"><br></div><div dir="auto">In fact, there&#39;s no code that runs in interrupt context at all. The only code that deals with host interrupts in a virtualization host is in VFIO, but all it needs to do is signal an eventfd.</div><div dir="auto"><br></div><div dir="auto">Paolo</div><div dir="auto"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Il gio 15 ago 2019, 19:18 Bharath Vedartham &lt;<a href="mailto:linux.bhar@gmail.com">linux.bhar@gmail.com</a>&gt; ha scritto:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Tue, Aug 13, 2019 at 10:17:09PM +0200, Paolo Bonzini wrote:<br>
&gt; On 13/08/19 21:14, Bharath Vedartham wrote:<br>
&gt; &gt; Hi all,<br>
&gt; &gt; <br>
&gt; &gt; I was looking at the function hva_to_pfn_fast(in virt/kvm/kvm_main) which is <br>
&gt; &gt; executed in an atomic context(even in non-atomic context, since<br>
&gt; &gt; hva_to_pfn_fast is much faster than hva_to_pfn_slow).<br>
&gt; &gt; <br>
&gt; &gt; My question is can this be executed in an interrupt context? <br>
&gt; <br>
&gt; No, it cannot for the reason you mention below.<br>
&gt; <br>
&gt; Paolo<br>
hmm.. Well I expected the answer to be kvm specific. <br>
Because I observed a similar use-case for a driver (sgi-gru) where <br>
we want to retrive the physical address of a virtual address. This was<br>
done in atomic and non-atomic context similar to hva_to_pfn_fast and<br>
hva_to_pfn_slow. __get_user_pages_fast(for atomic case) <br>
would not work as the driver could execute in interrupt context.<br>
<br>
The driver manually walked the page tables to handle this issue.<br>
<br>
Since kvm is a widely used piece of code, I asked this question to know<br>
how kvm handled this issue. <br>
<br>
Thank you for your time.<br>
<br>
Thank you<br>
Bharath<br>
&gt; &gt; The motivation for this question is that in an interrupt context, we cannot<br>
&gt; &gt; assume &quot;current&quot; to be the task_struct of the process of interest.<br>
&gt; &gt; __get_user_pages_fast assume current-&gt;mm when walking the process page<br>
&gt; &gt; tables. <br>
&gt; &gt; <br>
&gt; &gt; So if this function hva_to_pfn_fast can be executed in an<br>
&gt; &gt; interrupt context, it would not be safe to retrive the pfn with<br>
&gt; &gt; __get_user_pages_fast. <br>
&gt; &gt; <br>
&gt; &gt; Thoughts on this?<br>
&gt; &gt; <br>
&gt; &gt; Thank you<br>
&gt; &gt; Bharath<br>
&gt; &gt; <br>
&gt; <br>
</blockquote></div>

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

* Re: [Question-kvm] Can hva_to_pfn_fast be executed in interrupt context?
  2019-08-15 18:26     ` Paolo Bonzini
@ 2019-08-20 16:08       ` Bharath Vedartham
  0 siblings, 0 replies; 5+ messages in thread
From: Bharath Vedartham @ 2019-08-20 16:08 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Radim Krcmar, kvm, linux-kernel, linux-mm, khalid.aziz

On Thu, Aug 15, 2019 at 08:26:43PM +0200, Paolo Bonzini wrote:
> Oh, I see. Sorry I didn't understand the question. In the case of KVM,
> there's simply no code that runs in interrupt context and needs to use
> virtual addresses.
> 
> In fact, there's no code that runs in interrupt context at all. The only
> code that deals with host interrupts in a virtualization host is in VFIO,
> but all it needs to do is signal an eventfd.
> 
> Paolo
Great, answers my question. Thank you for your time.

Thank you
Bharath
> 
> Il gio 15 ago 2019, 19:18 Bharath Vedartham <linux.bhar@gmail.com> ha
> scritto:
> 
> > On Tue, Aug 13, 2019 at 10:17:09PM +0200, Paolo Bonzini wrote:
> > > On 13/08/19 21:14, Bharath Vedartham wrote:
> > > > Hi all,
> > > >
> > > > I was looking at the function hva_to_pfn_fast(in virt/kvm/kvm_main)
> > which is
> > > > executed in an atomic context(even in non-atomic context, since
> > > > hva_to_pfn_fast is much faster than hva_to_pfn_slow).
> > > >
> > > > My question is can this be executed in an interrupt context?
> > >
> > > No, it cannot for the reason you mention below.
> > >
> > > Paolo
> > hmm.. Well I expected the answer to be kvm specific.
> > Because I observed a similar use-case for a driver (sgi-gru) where
> > we want to retrive the physical address of a virtual address. This was
> > done in atomic and non-atomic context similar to hva_to_pfn_fast and
> > hva_to_pfn_slow. __get_user_pages_fast(for atomic case)
> > would not work as the driver could execute in interrupt context.
> >
> > The driver manually walked the page tables to handle this issue.
> >
> > Since kvm is a widely used piece of code, I asked this question to know
> > how kvm handled this issue.
> >
> > Thank you for your time.
> >
> > Thank you
> > Bharath
> > > > The motivation for this question is that in an interrupt context, we
> > cannot
> > > > assume "current" to be the task_struct of the process of interest.
> > > > __get_user_pages_fast assume current->mm when walking the process page
> > > > tables.
> > > >
> > > > So if this function hva_to_pfn_fast can be executed in an
> > > > interrupt context, it would not be safe to retrive the pfn with
> > > > __get_user_pages_fast.
> > > >
> > > > Thoughts on this?
> > > >
> > > > Thank you
> > > > Bharath
> > > >
> > >
> >


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

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-13 19:14 [Question-kvm] Can hva_to_pfn_fast be executed in interrupt context? Bharath Vedartham
2019-08-13 20:17 ` Paolo Bonzini
2019-08-15 17:18   ` Bharath Vedartham
2019-08-15 18:26     ` Paolo Bonzini
2019-08-20 16:08       ` Bharath Vedartham

Linux-mm Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-mm/0 linux-mm/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-mm linux-mm/ https://lore.kernel.org/linux-mm \
		linux-mm@kvack.org linux-mm@archiver.kernel.org
	public-inbox-index linux-mm


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kvack.linux-mm


AGPL code for this site: git clone https://public-inbox.org/ public-inbox