[RFC v2 12/14] arm64/lib: asid: Allow user to update the context under the lock

2019-06-20 Thread Julien Grall
Some users of the ASID allocator (e.g VMID) will require to update the context when a new ASID is generated. This has to be protected by a lock to prevent concurrent modification. Rather than introducing yet another lock, it is possible to re-use the allocator lock for that purpose. This patch

[RFC v2 13/14] arm/kvm: Introduce a new VMID allocator

2019-06-20 Thread Julien Grall
A follow-up patch will replace the KVM VMID allocator with the arm64 ASID allocator. To avoid as much as possible duplication, the arm KVM code will directly compile arch/arm64/lib/asid.c. The header is a verbatim to copy to avoid breaking the assumption that architecture port has self-containers

[RFC v2 10/14] arm64/mm: Introduce a callback to flush the local context

2019-06-20 Thread Julien Grall
Flushing the local context will vary depending on the actual user of the ASID allocator. Introduce a new callback to flush the local context and move the call to flush local TLB in it. Signed-off-by: Julien Grall --- arch/arm64/mm/context.c | 16 +--- 1 file changed, 13

[RFC v2 08/14] arm64/mm: Split asid_inits in 2 parts

2019-06-20 Thread Julien Grall
Move out the common initialization of the ASID allocator in a separate function. Signed-off-by: Julien Grall --- arch/arm64/mm/context.c | 43 +++ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/arch/arm64/mm/context.c

[RFC v2 11/14] arm64: Move the ASID allocator code in a separate file

2019-06-20 Thread Julien Grall
We will want to re-use the ASID allocator in a separate context (e.g allocating VMID). So move the code in a new file. The function asid_check_context has been moved in the header as a static inline function because we want to avoid add a branch when checking if the ASID is still valid.

[RFC v2 14/14] kvm/arm: Align the VMID allocation with the arm64 ASID one

2019-06-20 Thread Julien Grall
At the moment, the VMID algorithm will send an SGI to all the CPUs to force an exit and then broadcast a full TLB flush and I-Cache invalidation. This patch re-use the new ASID allocator. The benefits are: - CPUs are not forced to exit at roll-over. Instead the VMID will be marked

[RFC v2 05/14] arm64/mm: Remove dependency on MM in new_context

2019-06-20 Thread Julien Grall
The function new_context will be part of a generic ASID allocator. At the moment, the MM structure is only used to fetch the ASID. To remove the dependency on MM, it is possible to just pass a pointer to the current ASID. Signed-off-by: Julien Grall --- arch/arm64/mm/context.c | 6 +++--- 1

[RFC v2 02/14] arm64/mm: Move active_asids and reserved_asids to asid_info

2019-06-20 Thread Julien Grall
The variables active_asids and reserved_asids hold information for a given ASID allocator. So move them to the structure asid_info. At the same time, introduce wrappers to access the active and reserved ASIDs to make the code clearer. Signed-off-by: Julien Grall --- arch/arm64/mm/context.c |

[RFC v2 09/14] arm64/mm: Split the function check_and_switch_context in 3 parts

2019-06-20 Thread Julien Grall
The function check_and_switch_context is used to: 1) Check whether the ASID is still valid 2) Generate a new one if it is not valid 3) Switch the context While the latter is specific to the MM subsystem, the rest could be part of the generic ASID allocator. After this patch, the

[RFC v2 03/14] arm64/mm: Move bits to asid_info

2019-06-20 Thread Julien Grall
The variable bits hold information for a given ASID allocator. So move it to the asid_info structure. Because most of the macros were relying on bits, they are now taking an extra parameter that is a pointer to the asid_info structure. Signed-off-by: Julien Grall --- arch/arm64/mm/context.c |

[RFC v2 07/14] arm64/mm: Introduce NUM_ASIDS

2019-06-20 Thread Julien Grall
At the moment ASID_FIRST_VERSION is used to know the number of ASIDs supported. As we are going to move the ASID allocator in a separate, it would be better to use a different name for external users. This patch adds NUM_ASIDS and implements ASID_FIRST_VERSION using it. Signed-off-by: Julien

[RFC v2 04/14] arm64/mm: Move the variable lock and tlb_flush_pending to asid_info

2019-06-20 Thread Julien Grall
The variables lock and tlb_flush_pending holds information for a given ASID allocator. So move them to the asid_info structure. Signed-off-by: Julien Grall --- arch/arm64/mm/context.c | 17 + 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/arch/arm64/mm/context.c

[RFC v2 06/14] arm64/mm: Store the number of asid allocated per context

2019-06-20 Thread Julien Grall
Currently the number of ASID allocated per context is determined at compilation time. As the algorithm is becoming generic, the user may want to instantiate the ASID allocator multiple time with different number of ASID allocated. Add a field in asid_info to track the number ASID allocated per

[RFC v2 01/14] arm64/mm: Introduce asid_info structure and move asid_generation/asid_map to it

2019-06-20 Thread Julien Grall
In an attempt to make the ASID allocator generic, create a new structure asid_info to store all the information necessary for the allocator. For now, move the variables asid_generation and asid_map to the new structure asid_info. Follow-up patches will move more variables. Note to avoid more

[RFC v2 00/14] kvm/arm: Align the VMID allocation with the arm64 ASID one

2019-06-20 Thread Julien Grall
Hi all, This patch series is moving out the ASID allocator in a separate file in order to re-use it for the VMID. The benefits are: - CPUs are not forced to exit on a roll-over. - Context invalidation is now per-CPU rather than broadcasted. There are no performance regression on

Re: [GIT PULL] KVM/arm fixes for 5.2-rc6

2019-06-20 Thread Paolo Bonzini
On 20/06/19 13:22, Marc Zyngier wrote: > git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git > tags/kvmarm-fixes-for-5.2-2 Pulled, thanks. Paolo ___ kvmarm mailing list kvmarm@lists.cs.columbia.edu

[PATCH 4/4] KVM: arm/arm64: Fix emulated ptimer irq injection

2019-06-20 Thread Marc Zyngier
From: Andrew Jones The emulated ptimer needs to track the level changes, otherwise the the interrupt will never get deasserted, resulting in the guest getting stuck in an interrupt storm if it enables ptimer interrupts. This was found with kvm-unit-tests; the ptimer tests hung as soon as

[PATCH 3/4] KVM: arm/arm64: vgic: Fix kvm_device leak in vgic_its_destroy

2019-06-20 Thread Marc Zyngier
From: Dave Martin kvm_device->destroy() seems to be supposed to free its kvm_device struct, but vgic_its_destroy() is not currently doing this, resulting in a memory leak, resulting in kmemleak reports such as the following: unreferenced object 0x800aeddfe280 (size 128): comm

[GIT PULL] KVM/arm fixes for 5.2-rc6

2019-06-20 Thread Marc Zyngier
Paolo, Radim, Here's the second (and hopefully last) set of fixes for v5.2. We have our usual timer fix (we obviously will never get it right), a memory leak plug, a sysreg reporting fix, and an small SVE cleanup. Please pull. M. The following changes since commit

[PATCH 2/4] KVM: arm64: Filter out invalid core register IDs in KVM_GET_REG_LIST

2019-06-20 Thread Marc Zyngier
From: Dave Martin Since commit d26c25a9d19b ("arm64: KVM: Tighten guest core register access from userspace"), KVM_{GET,SET}_ONE_REG rejects register IDs that do not correspond to a single underlying architectural register. KVM_GET_REG_LIST was not changed to match however: instead, it simply

[PATCH 1/4] KVM: arm64: Implement vq_present() as a macro

2019-06-20 Thread Marc Zyngier
From: Viresh Kumar This routine is a one-liner and doesn't really need to be function and can be implemented as a macro. Suggested-by: Dave Martin Reviewed-by: Dave Martin Signed-off-by: Viresh Kumar Signed-off-by: Marc Zyngier --- arch/arm64/kvm/guest.c | 12 +++- 1 file changed,

Re: [PATCH RFC 11/14] arm64: Move the ASID allocator code in a separate file

2019-06-20 Thread Guo Ren
On Wed, Jun 19, 2019 at 8:39 PM Will Deacon wrote: > > On Wed, Jun 19, 2019 at 08:18:04PM +0800, Guo Ren wrote: > > On Wed, Jun 19, 2019 at 5:12 PM Will Deacon wrote: > > > This is one place where I'd actually prefer not to go down the route of > > > making the code generic. Context-switching