Skip to contentSkip to conversation

Map guest (ts,tid) to individual shadow tid

PATCH In review Liu Yu 3 participants 10 messages Apr 7, 2009 – Apr 10, 2009

Subsystems (2)
lore
Share & tools
lore

Liu Yu

author
#0 lore raw

PATCH 1/1 Map guest (ts,tid) to individual shadow tid

Hi guys,

Thanks to Hollis's idea.
This patch help to make KVMPPC be more friendly to OSes other than Linux.

Any (ts,tid) combination will be mapped to an individual shadow tid(stid). Whenever the stid is exhausted, it needs to reset of stid and flush host TLB.

To simplify the code, guest tid=0 will always be mapped to stid=0. And I don't think any OS uses tid=0 in userspace, does it?

In the case that run Linux in guest, the stid won't be exhausted. So that there is no extra overhead comparing to old code.

Any comment?

---
 arch/powerpc/include/asm/kvm_e500.h |    3 ++
 arch/powerpc/kvm/e500_tlb.c         |   67 ++++++++++++++++++++++++++++++++++-
 2 files changed, 69 insertions(+), 1 deletions(-)
arch/powerpc/include/asm/kvm_e500.h +3 -0
index 9d497ce..a62dd27 100644
@@ -37,6 +37,9 @@ struct kvmppc_vcpu_e500 {
 	/* Pages which are referenced in the shadow TLB. */
 	struct page **shadow_pages[E500_TLB_NUM];
 
+	/* tid mapping table */
+	void *tid_mapping;
+
 	unsigned int guest_tlb_size[E500_TLB_NUM];
 	unsigned int shadow_tlb_size[E500_TLB_NUM];
 	unsigned int guest_tlb_nv[E500_TLB_NUM];
arch/powerpc/kvm/e500_tlb.c +66 -1

101 lines not on this page · raw message

Signature · 1 line
1.5.4
#1 lore raw
Quoted 4 lines · Liu Yu

Hi guys,

Thanks to Hollis's idea.
This patch help to make KVMPPC be more friendly to OSes other than Linux.

Wow, that was quick. :)

Have you tested this code? Doesn't this break the assumption in kvmppc_e500_tlb1_invalidate() (and probably elsewhere) that stid = gtid?

Quoted 2 lines

Any (ts,tid) combination will be mapped to an individual shadow tid(stid). Whenever the stid is exhausted, it needs to reset of stid and flush host TLB.

What I was thinking was that KVM would participate in the host's normal PID allocation policy. Specifically, guest activity could cause the host to invoke steal_context_up/smp() (see switch_mmu_context() for reference).

When you do that, there is no need for KVM to explicitly flush the TLB ever -- it's done as needed by steal_context*(). That's actually better than what we do today, because today we must flush all guest mappings every time we de-schedule a guest. In the new scheme, when (guest PIDs + host PIDs) < 255, we would never need to flush the TLB due to PID pressure.

(Also, rather than an array, I would have created a hash table using include/linux/hash.h and include/linux/list.h. I haven't thought it through all the way though... I mean the tradeoffs of an array vs hash table here.)

Signature · 2 lines
Hollis Blanchard
IBM Linux Technology Center
#2 lore raw
In reply to Liu Yu
Quoted 14 lines

-----Original Message-----
From: Hollis Blanchard [mailto:[email protected]]
Sent: Tuesday, April 07, 2009 11:41 PM
To: Liu Yu-B13201
Cc: [email protected]
Subject: Re: [PATCH] Map guest (ts,tid) to individual shadow tid

Quoted 4 lines · Liu Yu

Hi guys,

Thanks to Hollis's idea.
This patch help to make KVMPPC be more friendly to OSes

Quoted 7 lines

other than Linux.

Wow, that was quick. :)

Have you tested this code? Doesn't this break the assumption in kvmppc_e500_tlb1_invalidate() (and probably elsewhere) that stid = gtid?

Yes, have taken a simple test.
Good catch, it needs to handle it here in kvmppc_e500_tlb1_invalidate(). Thanks.
But it's ok for now, because TLB1 only contains tid=0 entries, and tid=0 always be mapped to stid=0.
That's why the test is fine...

Quoted 4 lines
Quoted 2 lines

Any (ts,tid) combination will be mapped to an individual

shadow tid(stid).

Quoted 1 line

Whenever the stid is exhausted, it needs to reset of stid

Quoted 8 lines

and flush host TLB.

What I was thinking was that KVM would participate in the host's normal
PID allocation policy. Specifically, guest activity could cause the host
to invoke steal_context_up/smp() (see switch_mmu_context() for reference).

Host only use AS=0 space and the context only have 255 PIDs. But we use AS=1 space then we have another 255 PIDs.
If we participate in host, how could we utilize the PIDs under condition AS=1 without consume host PIDs?

Quoted 9 lines

When you do that, there is no need for KVM to explicitly flush the TLB ever -- it's done as needed by steal_context*(). That's actually better
than what we do today, because today we must flush all guest mappings every time we de-schedule a guest. In the new scheme, when (guest PIDs +
host PIDs) < 255, we would never need to flush the TLB due to PID pressure.

No. we only need to flush TLB when additional 255 PIDs are exhausted. And it's nothing to do with host PIDs.
For Linux running in guest, PIDs won't be exhausted so no TLB flush is needed.

Quoted 6 lines

(Also, rather than an array, I would have created a hash table using include/linux/hash.h and include/linux/list.h. I haven't thought it through all the way though... I mean the tradeoffs of an array vs hash table here.)

Hmm. What do you think we can benefit from hash table?

#3 lore raw
In reply to Liu Yu
Quoted 15 lines · On Tuesday 07 April 2009 21:11:11 Liu Yu-B13201 wrote:
Quoted 15 lines

-----Original Message-----
From: Hollis Blanchard [mailto:[email protected]]
Sent: Tuesday, April 07, 2009 11:41 PM
To: Liu Yu-B13201
Cc: [email protected]
Subject: Re: [PATCH] Map guest (ts,tid) to individual shadow tid

Quoted 4 lines · Liu Yu

Hi guys,

Thanks to Hollis's idea.
This patch help to make KVMPPC be more friendly to OSes

other than Linux.

Quoted 7 lines
Quoted 5 lines

Wow, that was quick. :)

Have you tested this code? Doesn't this break the assumption in kvmppc_e500_tlb1_invalidate() (and probably elsewhere) that stid = gtid?

Yes, have taken a simple test.

Once we can reduce the number of TLB flushes (see below) it will be interesting to see if there's a performance impact.

Quoted 5 lines

Good catch, it needs to handle it here in kvmppc_e500_tlb1_invalidate(). Thanks.
But it's ok for now, because TLB1 only contains tid=0 entries, and tid=0 always be mapped to stid=0.
That's why the test is fine...

OK. Still, it makes me nervous to break such a simple assumption. We should introduce nice accessors to make it difficult to code it wrong in the future. I'm honestly surprised that kvmppc_e500_tlb1_invalidate() is the only affected site.

Quoted 12 lines
Quoted 11 lines
Quoted 1 line

Any (ts,tid) combination will be mapped to an individual

shadow tid(stid).

Quoted 1 line

Whenever the stid is exhausted, it needs to reset of stid

and flush host TLB.

What I was thinking was that KVM would participate in the host's normal
PID allocation policy. Specifically, guest activity could cause the host
to invoke steal_context_up/smp() (see switch_mmu_context() for reference).

Quoted 4 lines

Host only use AS=0 space and the context only have 255 PIDs. But we use AS=1 space then we have another 255 PIDs.
If we participate in host, how could we utilize the PIDs under condition AS=1 without consume host PIDs?

I'm suggesting we not use AS=0. We can't use AS=0 and AS=1 PIDs interchangeably anyways.

Quoted 9 lines
Quoted 8 lines

When you do that, there is no need for KVM to explicitly flush the TLB ever -- it's done as needed by steal_context*(). That's actually better
than what we do today, because today we must flush all guest mappings every time we de-schedule a guest. In the new scheme, when (guest PIDs +
host PIDs) < 255, we would never need to flush the TLB due to PID pressure.

Quoted 4 lines

No. we only need to flush TLB when additional 255 PIDs are exhausted. And it's nothing to do with host PIDs.
For Linux running in guest, PIDs won't be exhausted so no TLB flush is needed.

I think this isn't true when using normal (AS=0) host PIDs.

That said, I guess throwing away the AS trick on Linux hosts wouldn't be a great idea. Since it's available (on Book E), we might as well take advantage of it.

So the only question then is about supporting *guest* use of AS, which I see now is what your patch is about. The one big change I would make is to have the AS=1 PID allocator be host-global rather than per-vcpu. That way we can avoid the unnecessary TLB flushes on every guest deschedule I mentioned before. (Imagine guest A using two host AS=1 PIDs, and guest B using five: we never need to flush the TLB due to PID pressure.)

That would also put the new PID management code into booke code instead of e500 code.

Quoted 7 lines
Quoted 5 lines

(Also, rather than an array, I would have created a hash table using include/linux/hash.h and include/linux/list.h. I haven't thought it through all the way though... I mean the tradeoffs of an array vs hash table here.)

Hmm. What do you think we can benefit from hash table?

Lower memory consumption. You know it's going to be sparse, since not every guest AS|PID will have a corresponding host PID. However, 512 bytes isn't bad, especially if it's shared by all vcpus. Don't worry about it.

Signature · 2 lines
Hollis Blanchard
IBM Linux Technology Center
#4 lore raw
In reply to Liu Yu
Quoted 43 lines

-----Original Message-----
From: Hollis Blanchard [mailto:[email protected]]
Sent: Thursday, April 09, 2009 12:43 AM
To: Liu Yu-B13201
Cc: [email protected]
Subject: Re: [PATCH] Map guest (ts,tid) to individual shadow tid

Quoted 11 lines · On Tuesday 07 April 2009 21:11:11 Liu Yu-B13201 wrote:
Quoted 11 lines

-----Original Message-----
From: Hollis Blanchard [mailto:[email protected]]
Sent: Tuesday, April 07, 2009 11:41 PM
To: Liu Yu-B13201
Cc: [email protected]
Subject: Re: [PATCH] Map guest (ts,tid) to individual shadow tid

Quoted 2 lines · Liu Yu

Hi guys,

Quoted 8 lines
Quoted 8 lines
Quoted 2 lines

Thanks to Hollis's idea.
This patch help to make KVMPPC be more friendly to OSes

other than Linux.

Wow, that was quick. :)

Have you tested this code? Doesn't this break the assumption in kvmppc_e500_tlb1_invalidate() (and probably elsewhere)

that stid =

Quoted 3 lines
Quoted 1 line

gtid?

Yes, have taken a simple test.

Once we can reduce the number of TLB flushes (see below) it will be interesting to see if there's a performance impact.

Quoted 1 line

Good catch, it needs to handle it here in

kvmppc_e500_tlb1_invalidate().

Quoted 2 lines

Thanks.
But it's ok for now, because TLB1 only contains tid=0

entries, and tid=0

Quoted 2 lines

always be mapped to stid=0.
That's why the test is fine...

Quoted 7 lines

OK. Still, it makes me nervous to break such a simple assumption. We should
introduce nice accessors to make it difficult to code it wrong in the future.
I'm honestly surprised that kvmppc_e500_tlb1_invalidate() is the only affected
site.

It is the only site. We don't pay much attention on shadow tid.
For 500, shadow tid is inherit from guest tid.
As guest tlb1 mapping is broken into 4K shadow mappings,
the kvmppc_e500_tlb1_invalidate() need to check tid to find all 4k shadow mappings related to an guest mapping.

Actually, I have been thinking about remove all shadow tlb like 440 did. This maybe helpful to succedent work such as huge tlb mapping. After doing that, kvmppc_e500_tlb1_invalidate() won't has this assumption.

Anyway, the patch is an RFC, not aimed at getting applied. Just make something to discuss. :)

Quoted 48 lines
Quoted 13 lines
Quoted 4 lines
Quoted 2 lines

Any (ts,tid) combination will be mapped to an individual

shadow tid(stid).

Quoted 1 line

Whenever the stid is exhausted, it needs to reset of stid

Quoted 8 lines

and flush host TLB.

What I was thinking was that KVM would participate in the host's normal
PID allocation policy. Specifically, guest activity could cause the host
to invoke steal_context_up/smp() (see switch_mmu_context() for reference).

Quoted 3 lines

Host only use AS=0 space and the context only have 255 PIDs. But we use AS=1 space then we have another 255 PIDs. If we participate in host, how could we utilize the PIDs

under condition

Quoted 1 line

AS=1 without consume host PIDs?

I'm suggesting we not use AS=0. We can't use AS=0 and AS=1 PIDs interchangeably anyways.

Quoted 1 line
Quoted 1 line

When you do that, there is no need for KVM to explicitly

flush the TLB

Quoted 3 lines
Quoted 3 lines

ever -- it's done as needed by steal_context*(). That's actually better
than what we do today, because today we must flush all

guest mappings

Quoted 6 lines
Quoted 4 lines

every time we de-schedule a guest. In the new scheme, when (guest PIDs +
host PIDs) < 255, we would never need to flush the TLB due to PID pressure.

No. we only need to flush TLB when additional 255 PIDs are

exhausted.

Quoted 2 lines

And it's nothing to do with host PIDs.
For Linux running in guest, PIDs won't be exhausted so no

TLB flush is

Quoted 1 line

needed.

I think this isn't true when using normal (AS=0) host PIDs.

That said, I guess throwing away the AS trick on Linux hosts wouldn't be a
great idea. Since it's available (on Book E), we might as well take advantage
of it.

Quoted 11 lines

So the only question then is about supporting *guest* use of AS, which I see
now is what your patch is about. The one big change I would make is to have
the AS=1 PID allocator be host-global rather than per-vcpu. That way we can
avoid the unnecessary TLB flushes on every guest deschedule I mentioned
before. (Imagine guest A using two host AS=1 PIDs, and guest B using five: we
never need to flush the TLB due to PID pressure.)

Yes, I remember you once mentioned it.
Then we don't need to flush tlb on every vcpu_get()/put().
I've thought of it, and it should be simple to make make the allocator host-global. And I'd like to put it into a separate performance improving patch.

But there is one thing I haven't thought through.
That is how should we handle guest kernel mapping (tid=0) after apply this trick? As it's supposed to share by all PIDs.
Any suggestion?

Quoted 4 lines

That would also put the new PID management code into booke code instead of
e500 code.

Certainly.

Quoted 10 lines
Quoted 2 lines
Quoted 2 lines

(Also, rather than an array, I would have created a hash

table using

Quoted 1 line
Quoted 1 line

include/linux/hash.h and include/linux/list.h. I haven't

thought it

Quoted 1 line
Quoted 1 line

through all the way though... I mean the tradeoffs of an

array vs hash

Quoted 3 lines
Quoted 2 lines

table here.)

Quoted 7 lines
Quoted 1 line

Hmm. What do you think we can benefit from hash table?

Lower memory consumption. You know it's going to be sparse, since not every
guest AS|PID will have a corresponding host PID. However, 512 bytes isn't bad,
especially if it's shared by all vcpus. Don't worry about it.

Ah I see.
For the design in this patch, we can put the allocate count global to reduce the tlb flush on guest schedule, but we can't put the mappings global. If we do, we need to identify different vcpu from each mapping entry.

#5 lore raw
In reply to Liu Yu
Quoted 66 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Liu Yu-B13201
Sent: Thursday, April 09, 2009 11:45 AM
To: Hollis Blanchard
Cc: [email protected]
Subject: RE: [PATCH] Map guest (ts,tid) to individual shadow tid

Quoted 43 lines

-----Original Message-----
From: Hollis Blanchard [mailto:[email protected]]
Sent: Thursday, April 09, 2009 12:43 AM
To: Liu Yu-B13201
Cc: [email protected]
Subject: Re: [PATCH] Map guest (ts,tid) to individual shadow tid

Quoted 11 lines · On Tuesday 07 April 2009 21:11:11 Liu Yu-B13201 wrote:
Quoted 11 lines

-----Original Message-----
From: Hollis Blanchard [mailto:[email protected]]
Sent: Tuesday, April 07, 2009 11:41 PM
To: Liu Yu-B13201
Cc: [email protected]
Subject: Re: [PATCH] Map guest (ts,tid) to individual shadow tid

Quoted 2 lines · Liu Yu

Hi guys,

Quoted 8 lines
Quoted 8 lines
Quoted 2 lines

Thanks to Hollis's idea.
This patch help to make KVMPPC be more friendly to OSes

other than Linux.

Wow, that was quick. :)

Have you tested this code? Doesn't this break the assumption in kvmppc_e500_tlb1_invalidate() (and probably elsewhere)

that stid =

Quoted 3 lines
Quoted 1 line

gtid?

Yes, have taken a simple test.

Once we can reduce the number of TLB flushes (see below) it will be interesting to see if there's a performance impact.

Quoted 1 line

Good catch, it needs to handle it here in

kvmppc_e500_tlb1_invalidate().

Quoted 2 lines

Thanks.
But it's ok for now, because TLB1 only contains tid=0

entries, and tid=0

Quoted 2 lines

always be mapped to stid=0.
That's why the test is fine...

Quoted 7 lines

OK. Still, it makes me nervous to break such a simple assumption. We should
introduce nice accessors to make it difficult to code it wrong in the future.
I'm honestly surprised that kvmppc_e500_tlb1_invalidate() is the only affected
site.

It is the only site. We don't pay much attention on shadow tid. For 500, shadow tid is inherit from guest tid.
As guest tlb1 mapping is broken into 4K shadow mappings, the kvmppc_e500_tlb1_invalidate() need to check tid to find all 4k shadow mappings related to an guest mapping.

Quoted 9 lines

Actually, I have been thinking about remove all shadow tlb like 440 did.
This maybe helpful to succedent work such as huge tlb mapping. After doing that, kvmppc_e500_tlb1_invalidate() won't has this assumption.

Anyway, the patch is an RFC, not aimed at getting applied. Just make something to discuss. :)

Well, I missed another site...
Host pid should be updated to stid in two case:
1. guest accesses to SPRN_PID
2. guest switch btween kernel and userspace. (if we map guest kernel [tid=0] to non zero stid)

#6 lore raw
In reply to Liu Yu
Quoted 57 lines · On Thu, 2009-04-09 at 11:44 +0800, Liu Yu-B13201 wrote:
Quoted 43 lines

-----Original Message-----
From: Hollis Blanchard [mailto:[email protected]]
Sent: Thursday, April 09, 2009 12:43 AM
To: Liu Yu-B13201
Cc: [email protected]
Subject: Re: [PATCH] Map guest (ts,tid) to individual shadow tid

Quoted 11 lines · On Tuesday 07 April 2009 21:11:11 Liu Yu-B13201 wrote:
Quoted 11 lines

-----Original Message-----
From: Hollis Blanchard [mailto:[email protected]]
Sent: Tuesday, April 07, 2009 11:41 PM
To: Liu Yu-B13201
Cc: [email protected]
Subject: Re: [PATCH] Map guest (ts,tid) to individual shadow tid

Quoted 2 lines · Liu Yu

Hi guys,

Quoted 8 lines
Quoted 8 lines
Quoted 2 lines

Thanks to Hollis's idea.
This patch help to make KVMPPC be more friendly to OSes

other than Linux.

Wow, that was quick. :)

Have you tested this code? Doesn't this break the assumption in kvmppc_e500_tlb1_invalidate() (and probably elsewhere)

that stid =

Quoted 3 lines
Quoted 1 line

gtid?

Yes, have taken a simple test.

Once we can reduce the number of TLB flushes (see below) it will be interesting to see if there's a performance impact.

Quoted 1 line

Good catch, it needs to handle it here in

kvmppc_e500_tlb1_invalidate().

Quoted 2 lines

Thanks.
But it's ok for now, because TLB1 only contains tid=0

entries, and tid=0

Quoted 2 lines

always be mapped to stid=0.
That's why the test is fine...

Quoted 7 lines

OK. Still, it makes me nervous to break such a simple assumption. We should
introduce nice accessors to make it difficult to code it wrong in the future.
I'm honestly surprised that kvmppc_e500_tlb1_invalidate() is the only affected
site.

It is the only site. We don't pay much attention on shadow tid. For 500, shadow tid is inherit from guest tid.
As guest tlb1 mapping is broken into 4K shadow mappings, the kvmppc_e500_tlb1_invalidate() need to check tid to find all 4k shadow mappings related to an guest mapping.

Quoted 6 lines

Actually, I have been thinking about remove all shadow tlb like 440 did. This maybe helpful to succedent work such as huge tlb mapping. After doing that, kvmppc_e500_tlb1_invalidate() won't has this assumption.

Anyway, the patch is an RFC, not aimed at getting applied. Just make something to discuss. :)

It's a very good discussion. :)

Quoted 4 lines

But there is one thing I haven't thought through.
That is how should we handle guest kernel mapping (tid=0) after apply this trick? As it's supposed to share by all PIDs.
Any suggestion?

Hmm, that's a good question.

On e500, you could use the PID1 register, but that doesn't appear in 440, and won't be available in future implementations anyways.

In general, I don't know... I'm reluctant to sacrifice the other PID hack we use, which allows us to flip between guest user and guest kernel without flushing the TLB. Since that's probably way more frequent than context switches, maybe it's worth suffering the TLB flush on context switch.

It would be OK to map gPID 0 to another arbitrary host PID, except we need copy_to_user() to work in the guest. To elaborate, if we had this address space:

0 0xc 0xf
| gTID 3 | gTID 0 | gPID=3

we could implement it like this:

0 0xc 0xf
| sTID 27 | sTID 9 |

and switch sPID between 9 and 27 when jumping between guest user and guest kernel. However, if we're in the guest kernel (sTID=9 mappings) with sPID=9, copy_to_user() will fault because sTID' mappings aren't visible.

When those faults occur, we could create a new userspace mapping with sTID 9, aliasing the sTID 27 mappings. Would that work? Odds are we won't get more than 1 or 2 of these at a time, but we'd need to track these mappings so that guest updates to the sTID' mappings also modify or flush our extra sTID=9 mappings.

That might be the only complexity, and might not be that bad. I don't know, what do you think? If e500 can selectively flush by PID, maybe that's better, but 440 can't so we'd want some scheme like I described.

Signature · 2 lines
Hollis Blanchard
IBM Linux Technology Center
#7 lore raw
In reply to Liu Yu
Quoted 122 lines

-----Original Message-----
From: Hollis Blanchard [mailto:[email protected]]
Sent: Friday, April 10, 2009 4:16 AM
To: Liu Yu-B13201
Cc: [email protected]
Subject: RE: [PATCH] Map guest (ts,tid) to individual shadow tid

Quoted 7 lines · On Thu, 2009-04-09 at 11:44 +0800, Liu Yu-B13201 wrote:
Quoted 7 lines

-----Original Message-----
From: Hollis Blanchard [mailto:[email protected]]
Sent: Thursday, April 09, 2009 12:43 AM
To: Liu Yu-B13201
Cc: [email protected]
Subject: Re: [PATCH] Map guest (ts,tid) to individual shadow tid

Quoted 8 lines
Quoted 8 lines · On Tuesday 07 April 2009 21:11:11 Liu Yu-B13201 wrote:
Quoted 7 lines
Quoted 7 lines

-----Original Message-----
From: Hollis Blanchard [mailto:[email protected]]
Sent: Tuesday, April 07, 2009 11:41 PM
To: Liu Yu-B13201
Cc: [email protected]
Subject: Re: [PATCH] Map guest (ts,tid) to individual

shadow tid

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines · Liu Yu
Quoted 4 lines

Hi guys,

Thanks to Hollis's idea.
This patch help to make KVMPPC be more friendly to OSes

other than Linux.

Wow, that was quick. :)

Have you tested this code? Doesn't this break the

assumption in

Quoted 7 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line

kvmppc_e500_tlb1_invalidate() (and probably elsewhere)

that stid =

Quoted 3 lines
Quoted 1 line

gtid?

Yes, have taken a simple test.

Once we can reduce the number of TLB flushes (see below)

it will be

Quoted 18 lines
Quoted 10 lines

interesting to see if there's a performance impact.

Quoted 1 line

Good catch, it needs to handle it here in

kvmppc_e500_tlb1_invalidate().

Quoted 2 lines

Thanks.
But it's ok for now, because TLB1 only contains tid=0

entries, and tid=0

Quoted 2 lines

always be mapped to stid=0.
That's why the test is fine...

Quoted 7 lines

OK. Still, it makes me nervous to break such a simple assumption. We should
introduce nice accessors to make it difficult to code it wrong in the future.
I'm honestly surprised that kvmppc_e500_tlb1_invalidate() is the only affected
site.

Quoted 7 lines

It is the only site. We don't pay much attention on shadow tid. For 500, shadow tid is inherit from guest tid.
As guest tlb1 mapping is broken into 4K shadow mappings, the kvmppc_e500_tlb1_invalidate() need to check tid to find all 4k shadow mappings related to an guest mapping.

Actually, I have been thinking about remove all shadow tlb

like 440 did.

Quoted 2 lines

This maybe helpful to succedent work such as huge tlb mapping. After doing that, kvmppc_e500_tlb1_invalidate() won't has

this assumption.

Quoted 3 lines

Anyway, the patch is an RFC, not aimed at getting applied. Just make something to discuss. :)

It's a very good discussion. :)

Quoted 2 lines

But there is one thing I haven't thought through. That is how should we handle guest kernel mapping (tid=0)

after apply this trick?

Quoted 2 lines

As it's supposed to share by all PIDs.
Any suggestion?

Hmm, that's a good question.

On e500, you could use the PID1 register, but that doesn't appear in 440, and won't be available in future implementations anyways.

In general, I don't know... I'm reluctant to sacrifice the other PID hack we use, which allows us to flip between guest user and guest kernel
without flushing the TLB. Since that's probably way more frequent than context switches, maybe it's worth suffering the TLB flush on context switch.

It would be OK to map gPID 0 to another arbitrary host PID, except we need copy_to_user() to work in the guest. To elaborate, if we had this address space:

0 0xc 0xf
| gTID 3 | gTID 0 | gPID=3

we could implement it like this:

0 0xc 0xf
| sTID 27 | sTID 9 |

and switch sPID between 9 and 27 when jumping between guest user and guest kernel. However, if we're in the guest kernel (sTID=9 mappings) with sPID=9, copy_to_user() will fault because sTID' mappings aren't visible.

When those faults occur, we could create a new userspace mapping with sTID 9, aliasing the sTID 27 mappings. Would that work? Odds are we won't get more than 1 or 2 of these at a time, but we'd need to track these mappings so that guest updates to the sTID' mappings also modify
or flush our extra sTID=9 mappings.

Quoted 5 lines

That might be the only complexity, and might not be that bad. I don't know, what do you think? If e500 can selectively flush by PID, maybe that's better, but 440 can't so we'd want some scheme like I described.

E500 cannot selectively flush by PID either... Seems e500mc could. It's a good idea that use PID1 to map guest kernel's stid for e500, but there is another problem that how to handle guest mapping access privilege.

I think we should apart this problem into two to make it clear. 1). how to handle guest share mapping(tid=0).
2). how to handle guest mapping without user access privilege. What I mean is there may be non-zero tid mapping without user access privilege,
Although this seems don't exist in Linux.

I have two different ways in mind to solve it.

1. utilize e500 PID1 as you mentioned
We can set PID1 when enter guest kernel and clear PID1 when enter guest userspace.

Pro.
this method can minimize TLB flush.
Con.
it's based on the assumption that all guest access limited mappings
always have tid=0,
or non-zero mappings always have user access bits.
It's fine for Linux but not sure for other OSes.

2. utilize e500 duel TLBs, put different kind of guest mappings into different TLBs
Only chosen mappings go into TLB1, while others go into TLB0. If a flush is inavoidable, only need to flush TLB1.
As TLB1 just has 16 entry, the flush don't cost much.
The main cost will be how many circles the flushing take, instead of endless tlb miss after flush.

For example, to solve method 1 con.
if we meet an non-zero mapping without user access bits, We could put it into TLB1, then when enter guest userspace, we only flush TLB1,
while TLB0 still keep most of mappings.

If large tlb trick is applied, then large mappings have no choise but go into TLB1.
But flushing TLB1 still doesn't cost much.
In most cases, if we flush TLB1 when enter userspace, we will meet one tlb miss when enter in kernel again.

Pro.
It could help to provide a universal solution. (not sure we want it)
Con.
Need flush TLB1 under certain cases.

Moreover when guest large mapping is broken into 4K shadow mappings, Put them into TLB0 instead of TLB1 may be helpful to reduce the tlb miss.
As TLB1 is too small while TLB0 has a big room.

#8 lore raw
In reply to Liu Yu
Quoted 54 lines · On Friday 10 April 2009 04:13:26 Liu Yu-B13201 wrote:
Quoted 43 lines
Quoted 3 lines

But there is one thing I haven't thought through. That is how should we handle guest kernel mapping (tid=0)

after apply this trick?

Quoted 2 lines

As it's supposed to share by all PIDs.
Any suggestion?

Hmm, that's a good question.

On e500, you could use the PID1 register, but that doesn't appear in 440, and won't be available in future implementations anyways.

In general, I don't know... I'm reluctant to sacrifice the other PID hack we use, which allows us to flip between guest user and guest kernel
without flushing the TLB. Since that's probably way more frequent than context switches, maybe it's worth suffering the TLB flush on context switch.

It would be OK to map gPID 0 to another arbitrary host PID, except we need copy_to_user() to work in the guest. To elaborate, if we had this address space:

0 0xc 0xf
| gTID 3 | gTID 0 | gPID=3

we could implement it like this:

0 0xc 0xf
| sTID 27 | sTID 9 |

and switch sPID between 9 and 27 when jumping between guest user and guest kernel. However, if we're in the guest kernel (sTID=9 mappings) with sPID=9, copy_to_user() will fault because sTID' mappings aren't visible.

When those faults occur, we could create a new userspace mapping with sTID 9, aliasing the sTID 27 mappings. Would that work? Odds are we won't get more than 1 or 2 of these at a time, but we'd need to track these mappings so that guest updates to the sTID' mappings also modify
or flush our extra sTID=9 mappings.

Quoted 5 lines

That might be the only complexity, and might not be that bad. I don't know, what do you think? If e500 can selectively flush by PID, maybe that's better, but 440 can't so we'd want some scheme like I described.

E500 cannot selectively flush by PID either... Seems e500mc could. It's a good idea that use PID1 to map guest kernel's stid for e500, but there is another problem that how to handle guest mapping access privilege.

Quoted 6 lines

I think we should apart this problem into two to make it clear. 1). how to handle guest share mapping(tid=0).
2). how to handle guest mapping without user access privilege. What I mean is there may be non-zero tid mapping without user access privilege,
Although this seems don't exist in Linux.

Yeah, I can't think of how this would be used. Maybe some microkernel? I don't think I want to worry about this case right now...

Quoted 6 lines

I have two different ways in mind to solve it.

1. utilize e500 PID1 as you mentioned
We can set PID1 when enter guest kernel and clear PID1 when enter guest userspace.

Quoted 7 lines

Pro.
this method can minimize TLB flush.
Con.
it's based on the assumption that all guest access limited mappings
always have tid=0,
or non-zero mappings always have user access bits.
It's fine for Linux but not sure for other OSes.

Con:
- Only works on e500v1/v2. :) But that's where the immediate need is, and I don't see a better general-purpose solution, so I think it's OK.

That reminds me...

Rahul, how does NetBSD handle copy_to_user() from AS=0, since userspace TLB mappings have TS=1? (I tried to find source myself, but it looks like the only port was done by Wasabi Systems, which apparently abruptly closed down recently.) Does it just fault in a new TLB entry as needed?

Signature · 2 lines
Hollis Blanchard
IBM Linux Technology Center
#9 lore raw
In reply to Liu Yu
Quoted 92 lines

-----Original Message-----
From: Hollis Blanchard [mailto:[email protected]]
Sent: Friday, April 10, 2009 11:06 AM
To: Liu Yu-B13201
Cc: [email protected]; Rahul Kulkarni
Subject: Re: [PATCH] Map guest (ts,tid) to individual shadow tid

Quoted 54 lines · On Friday 10 April 2009 04:13:26 Liu Yu-B13201 wrote:
Quoted 43 lines
Quoted 3 lines

But there is one thing I haven't thought through. That is how should we handle guest kernel mapping (tid=0)

after apply this trick?

Quoted 2 lines

As it's supposed to share by all PIDs.
Any suggestion?

Hmm, that's a good question.

On e500, you could use the PID1 register, but that doesn't appear in 440, and won't be available in future implementations anyways.

In general, I don't know... I'm reluctant to sacrifice the other PID hack we use, which allows us to flip between guest user and guest kernel
without flushing the TLB. Since that's probably way more frequent than context switches, maybe it's worth suffering the TLB flush on context switch.

It would be OK to map gPID 0 to another arbitrary host PID, except we need copy_to_user() to work in the guest. To elaborate, if we had this address space:

0 0xc 0xf
| gTID 3 | gTID 0 | gPID=3

we could implement it like this:

0 0xc 0xf
| sTID 27 | sTID 9 |

and switch sPID between 9 and 27 when jumping between guest user and guest kernel. However, if we're in the guest kernel (sTID=9 mappings) with sPID=9, copy_to_user() will fault because sTID' mappings aren't visible.

When those faults occur, we could create a new userspace mapping with sTID 9, aliasing the sTID 27 mappings. Would that work? Odds are we won't get more than 1 or 2 of these at a time, but we'd need to track these mappings so that guest updates to the sTID' mappings also modify
or flush our extra sTID=9 mappings.

Quoted 5 lines

That might be the only complexity, and might not be that bad. I don't know, what do you think? If e500 can selectively flush by PID, maybe that's better, but 440 can't so we'd want some scheme like I described.

E500 cannot selectively flush by PID either... Seems e500mc could. It's a good idea that use PID1 to map guest kernel's stid for e500, but there is another problem that how to handle guest mapping access privilege.

Quoted 6 lines

I think we should apart this problem into two to make it clear. 1). how to handle guest share mapping(tid=0).
2). how to handle guest mapping without user access privilege. What I mean is there may be non-zero tid mapping without user access privilege,
Although this seems don't exist in Linux.

Yeah, I can't think of how this would be used. Maybe some microkernel? I don't think I want to worry about this case right now...

Quoted 6 lines

I have two different ways in mind to solve it.

1. utilize e500 PID1 as you mentioned
We can set PID1 when enter guest kernel and clear PID1 when enter guest userspace.

Quoted 7 lines

Pro.
this method can minimize TLB flush.
Con.
it's based on the assumption that all guest access limited mappings
always have tid=0,
or non-zero mappings always have user access bits.
It's fine for Linux but not sure for other OSes.

Con:
- Only works on e500v1/v2. :) But that's where the immediate need is, and I don't see a better general-purpose solution, so I think it's OK.

Quoted 7 lines

That reminds me...

Rahul, how does NetBSD handle copy_to_user() from AS=0, since userspace TLB mappings have TS=1? (I tried to find source myself, but it looks like the only port was done by Wasabi Systems, which apparently abruptly closed down recently.) Does it just fault in a new TLB entry as needed?

Yes for smaller copies < 256 bytes, it simply switches between AS 0 and AS 1 and would fault for a new TLB entry if needed for TS=1.(regular fault path) (I would think the odds for this happen to be low since the TS=1 entry should be present ?) For bigger copies the user pa range(extracted from the user va range) is mapped into the kernel address space (kernel pmap) and then simply memcpy'd

Quoted 3 lines

--
Hollis Blanchard
IBM Linux Technology Center