All of lore.kernel.org
 help / color / mirror / Atom feed
* Problems about Stage-2 translation
@ 2021-10-16 12:21 Chenxu Wang
  2021-10-16 21:19 ` Marc Zyngier
  0 siblings, 1 reply; 6+ messages in thread
From: Chenxu Wang @ 2021-10-16 12:21 UTC (permalink / raw)
  To: kvmarm


[-- Attachment #1.1: Type: text/plain, Size: 896 bytes --]

Hi all,

I am facing two problems with the Stage-2 translation in KVM.

(1)
I reserve a memory region (e.g., 0xa000_0000 ~ 0xa020_0000) from DRAM space
of HostOS, and fill it with some values. Then ask a GuestVM to access this
region.

void __iomem *region=ioremap(0xa0000000, 0x1000);
uint32_t val=ioread32(region);

But I get value 0, which is not the expected value.
I guess the reason is that the Stage-2 translation of the GuestVM does not
map the reserved region, but it should return a translation fault, rather
than 0. So I feel confused, could you provide some helpful explanation?

(2)
I consider mapping a region with the Stage-2 translation. I find that KVM
create the stage-2 table with kvm_alloc_stage2_pgd(). But I could not find
a function that can "arbitrarily add a stage-2 mapping to the physical
address in HostOS" when the VM is activated.

Could you provide such functions?

[-- Attachment #1.2: Type: text/html, Size: 1119 bytes --]

[-- Attachment #2: Type: text/plain, Size: 151 bytes --]

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

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

* Re: Problems about Stage-2 translation
  2021-10-16 12:21 Problems about Stage-2 translation Chenxu Wang
@ 2021-10-16 21:19 ` Marc Zyngier
  2021-10-18  8:36   ` Chenxu Wang
  0 siblings, 1 reply; 6+ messages in thread
From: Marc Zyngier @ 2021-10-16 21:19 UTC (permalink / raw)
  To: Chenxu Wang; +Cc: kvmarm

On Sat, 16 Oct 2021 13:21:01 +0100,
Chenxu Wang <irakatz51@gmail.com> wrote:
> 
> Hi all,
> 
> I am facing two problems with the Stage-2 translation in KVM.
> 
> (1)
> I reserve a memory region (e.g., 0xa000_0000 ~ 0xa020_0000) from DRAM space
> of HostOS, and fill it with some values. Then ask a GuestVM to access this
> region.
> 
> void __iomem *region=ioremap(0xa0000000, 0x1000);
> uint32_t val=ioread32(region);
> 
> But I get value 0, which is not the expected value.

It is the expected behaviour.

> I guess the reason is that the Stage-2 translation of the GuestVM does not
> map the reserved region, but it should return a translation fault, rather
> than 0. So I feel confused, could you provide some helpful explanation?

Why should the guest see a translation fault? After all, the whole
point of KVM is to transparently handle the translation fault and map
a page on demand.

> (2)
> I consider mapping a region with the Stage-2 translation. I find that KVM
> create the stage-2 table with kvm_alloc_stage2_pgd(). But I could not find
> a function that can "arbitrarily add a stage-2 mapping to the physical
> address in HostOS" when the VM is activated.
> 
> Could you provide such functions?

Follow the translation fault path in KVM, and you will find what you
are asking for.

	M.

-- 
Without deviation from the norm, progress is not possible.
_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

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

* Re: Problems about Stage-2 translation
  2021-10-16 21:19 ` Marc Zyngier
@ 2021-10-18  8:36   ` Chenxu Wang
  2021-10-18 10:06     ` Marc Zyngier
  0 siblings, 1 reply; 6+ messages in thread
From: Chenxu Wang @ 2021-10-18  8:36 UTC (permalink / raw)
  To: Marc Zyngier; +Cc: kvmarm


[-- Attachment #1.1: Type: text/plain, Size: 2156 bytes --]

Hi Marc,

Thanks for your help. I studied the kvm_handle_guest_abort() handler, and
basically know the reason for "return 0".
But I still cannot solve the mapping problem.

I want to find a function or APIs, whose input parameters are (1) region
base IPA and size (2) mapped PA in Host (if IPA=PA, it could be better) (3)
R/W/X attributes.
Then, when I call the func(IPA start, IPA end, PA start, attr), I can get
the map.

Where should I follow? Should I follow the "translation fault path" again?
Or create the mapping function by myself?

Sincerely,
Wang

Marc Zyngier <maz@kernel.org> 于2021年10月17日周日 上午5:19写道:

> On Sat, 16 Oct 2021 13:21:01 +0100,
> Chenxu Wang <irakatz51@gmail.com> wrote:
> >
> > Hi all,
> >
> > I am facing two problems with the Stage-2 translation in KVM.
> >
> > (1)
> > I reserve a memory region (e.g., 0xa000_0000 ~ 0xa020_0000) from DRAM
> space
> > of HostOS, and fill it with some values. Then ask a GuestVM to access
> this
> > region.
> >
> > void __iomem *region=ioremap(0xa0000000, 0x1000);
> > uint32_t val=ioread32(region);
> >
> > But I get value 0, which is not the expected value.
>
> It is the expected behaviour.
>
> > I guess the reason is that the Stage-2 translation of the GuestVM does
> not
> > map the reserved region, but it should return a translation fault, rather
> > than 0. So I feel confused, could you provide some helpful explanation?
>
> Why should the guest see a translation fault? After all, the whole
> point of KVM is to transparently handle the translation fault and map
> a page on demand.
>
> > (2)
> > I consider mapping a region with the Stage-2 translation. I find that KVM
> > create the stage-2 table with kvm_alloc_stage2_pgd(). But I could not
> find
> > a function that can "arbitrarily add a stage-2 mapping to the physical
> > address in HostOS" when the VM is activated.
> >
> > Could you provide such functions?
>
> Follow the translation fault path in KVM, and you will find what you
> are asking for.
>
>         M.
>
> --
> Without deviation from the norm, progress is not possible.
>

[-- Attachment #1.2: Type: text/html, Size: 2795 bytes --]

[-- Attachment #2: Type: text/plain, Size: 151 bytes --]

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

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

* Re: Problems about Stage-2 translation
  2021-10-18  8:36   ` Chenxu Wang
@ 2021-10-18 10:06     ` Marc Zyngier
  2021-10-18 19:01       ` Chenxu Wang
  0 siblings, 1 reply; 6+ messages in thread
From: Marc Zyngier @ 2021-10-18 10:06 UTC (permalink / raw)
  To: Chenxu Wang; +Cc: kvmarm

Wang,

Please don't top-post, and stick to plain text instead of HTML.

On Mon, 18 Oct 2021 09:36:05 +0100,
Chenxu Wang <irakatz51@gmail.com> wrote:
> 
> Hi Marc,
> 
> Thanks for your help. I studied the kvm_handle_guest_abort() handler, and
> basically know the reason for "return 0".
> But I still cannot solve the mapping problem.
> 
> I want to find a function or APIs, whose input parameters are (1) region
> base IPA and size (2) mapped PA in Host (if IPA=PA, it could be better) (3)
> R/W/X attributes.
> Then, when I call the func(IPA start, IPA end, PA start, attr), I can get
> the map.

There is no such function, because that's not how KVM works.

> Where should I follow? Should I follow the "translation fault path" again?
> Or create the mapping function by myself?

Neither. You cannot directly map random physical ranges into a VM.
Memory that gets mapped into a VM needs to be exposed by userspace in
the form of a memslot. KVM will then map that memory on demand as the
guest accesses it.

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.
_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

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

* Re: Problems about Stage-2 translation
  2021-10-18 10:06     ` Marc Zyngier
@ 2021-10-18 19:01       ` Chenxu Wang
  2021-10-18 19:31         ` Marc Zyngier
  0 siblings, 1 reply; 6+ messages in thread
From: Chenxu Wang @ 2021-10-18 19:01 UTC (permalink / raw)
  To: Marc Zyngier; +Cc: kvmarm

Hi Marc,

Sorry, but I could not find the bottom posting mode in Gmail.

Also, thanks for your reply, I continue to discover how the Stage-2
translation works in KVM.
But, when I read the HCR_EL2 register in Host  (it is v5.3.0) , its
value is 0x4_8800_0000. So
(1) I am in VHE mode.
(2) The Stage-2 translation is disabled.

I am sure that I have run a Non-Secure VM with QEMU, so is it correct
that the S-2 translation is disabled in VHE mode? If so, how it
handles the memory management for Guest?


Confused,
Wang


Marc Zyngier <maz@kernel.org> 于2021年10月18日周一 下午6:06写道:
>
> Wang,
>
> Please don't top-post, and stick to plain text instead of HTML.
>
> On Mon, 18 Oct 2021 09:36:05 +0100,
> Chenxu Wang <irakatz51@gmail.com> wrote:
> >
> > Hi Marc,
> >
> > Thanks for your help. I studied the kvm_handle_guest_abort() handler, and
> > basically know the reason for "return 0".
> > But I still cannot solve the mapping problem.
> >
> > I want to find a function or APIs, whose input parameters are (1) region
> > base IPA and size (2) mapped PA in Host (if IPA=PA, it could be better) (3)
> > R/W/X attributes.
> > Then, when I call the func(IPA start, IPA end, PA start, attr), I can get
> > the map.
>
> There is no such function, because that's not how KVM works.
>
> > Where should I follow? Should I follow the "translation fault path" again?
> > Or create the mapping function by myself?
>
> Neither. You cannot directly map random physical ranges into a VM.
> Memory that gets mapped into a VM needs to be exposed by userspace in
> the form of a memslot. KVM will then map that memory on demand as the
> guest accesses it.
>
> Thanks,
>
>         M.
>
> --
> Without deviation from the norm, progress is not possible.
_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

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

* Re: Problems about Stage-2 translation
  2021-10-18 19:01       ` Chenxu Wang
@ 2021-10-18 19:31         ` Marc Zyngier
  0 siblings, 0 replies; 6+ messages in thread
From: Marc Zyngier @ 2021-10-18 19:31 UTC (permalink / raw)
  To: Chenxu Wang; +Cc: kvmarm

Wang,

On Mon, 18 Oct 2021 20:01:23 +0100,
Chenxu Wang <irakatz51@gmail.com> wrote:
> 
> Hi Marc,
> 
> Sorry, but I could not find the bottom posting mode in Gmail.

Easy. You click on the '...' button at the bottom left of the reply
window, scroll down and place your cursor at the right location.

> Also, thanks for your reply, I continue to discover how the Stage-2
> translation works in KVM.
> But, when I read the HCR_EL2 register in Host  (it is v5.3.0) , its
> value is 0x4_8800_0000. So
> (1) I am in VHE mode.
> (2) The Stage-2 translation is disabled.
> 
> I am sure that I have run a Non-Secure VM with QEMU, so is it correct
> that the S-2 translation is disabled in VHE mode? If so, how it
> handles the memory management for Guest?

By switching stage-2 on when required. HCR_EL2 isn't a static setting,
and gets updated at run-time. Also, HCR_EL2.VM means exactly nothing
when HCR_EL2.{E2H,TGE}={1,1}.

	M.

-- 
Without deviation from the norm, progress is not possible.
_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

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

end of thread, other threads:[~2021-10-18 19:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-16 12:21 Problems about Stage-2 translation Chenxu Wang
2021-10-16 21:19 ` Marc Zyngier
2021-10-18  8:36   ` Chenxu Wang
2021-10-18 10:06     ` Marc Zyngier
2021-10-18 19:01       ` Chenxu Wang
2021-10-18 19:31         ` Marc Zyngier

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.