RE: [RFC PATCH v9 7/8] ptp: arm64: Enable ptp_kvm for arm64

2020-01-08 Thread Jianyong Wu
Hi Marc, > -Original Message- > From: Marc Zyngier > Sent: Tuesday, January 7, 2020 5:29 PM > To: Jianyong Wu > Cc: net...@vger.kernel.org; yangbo...@nxp.com; john.stu...@linaro.org; > t...@linutronix.de; pbonz...@redhat.com; sean.j.christopher...@intel.com; > richardcoch...@gmail.com; M

RE: [RFC PATCH v9 6/8] psci: Add hvc call service for ptp_kvm.

2020-01-08 Thread Jianyong Wu
Hi Marc, > -Original Message- > From: Marc Zyngier > Sent: Tuesday, January 7, 2020 5:16 PM > To: Jianyong Wu > Cc: net...@vger.kernel.org; yangbo...@nxp.com; john.stu...@linaro.org; > t...@linutronix.de; pbonz...@redhat.com; sean.j.christopher...@intel.com; > richardcoch...@gmail.com; M

Re: [PATCH 1/1] arm/arm64: add support for folded p4d page tables

2020-01-08 Thread Anshuman Khandual
On 12/30/2019 01:57 PM, Mike Rapoport wrote: > From: Mike Rapoport > > Implement primitives necessary for the 4th level folding, add walks of p4d > level where appropriate, replace 5level-fixup.h with pgtable-nop4d.h and > remove __ARCH_USE_5LEVEL_HACK. > > Since arm and arm64 share kvm memor

Re: [PATCH 0/1] arm/arm64: add support for folded p4d page tables

2020-01-08 Thread Anshuman Khandual
On 12/30/2019 01:57 PM, Mike Rapoport wrote: > From: Mike Rapoport > > Hi, Hello Mike, > > This is a part of clean up of the page table manipulation code that aims to > remove asm-generic/5level-fixup.h and asm-generic/pgtable-nop4d-hack.h > > There is a single patch for both arm and arm64

[PATCH 07/14] KVM: x86/mmu: Walk host page tables to find THP mappings

2020-01-08 Thread Sean Christopherson
Explicitly walk the host page tables to identify THP mappings instead of relying solely on the metadata in struct page. This sets the stage for using a common method of identifying huge mappings regardless of the underlying implementation (HugeTLB vs THB vs DAX), and hopefully avoids the pitfalls

[PATCH 00/14] KVM: x86/mmu: Huge page fixes, cleanup, and DAX

2020-01-08 Thread Sean Christopherson
This series is a mix of bug fixes, cleanup and new support in KVM's handling of huge pages. The series initially stemmed from a syzkaller bug report[1], which is fixed by patch 02, "mm: thp: KVM: Explicitly check for THP when populating secondary MMU". While investigating options for fixing the s

[PATCH 04/14] KVM: Play nice with read-only memslots when querying host page size

2020-01-08 Thread Sean Christopherson
Open code an equivalent of kvm_vcpu_gfn_to_memslot() when querying the host page size to avoid the "writable" check in __gfn_to_hva_many(), which will always fail on read-only memslots due to gfn_to_hva() assuming writes. Functionally, this allows x86 to create large mappings for read-only memslot

[PATCH 06/14] KVM: x86/mmu: Refactor THP adjust to prep for changing query

2020-01-08 Thread Sean Christopherson
Refactor transparent_hugepage_adjust() in preparation for walking the host page tables to identify hugepage mappings, initially for THP pages, and eventualy for HugeTLB and DAX-backed pages as well. The latter cases support 1gb pages, i.e. the adjustment logic needs access to the max allowed level

[PATCH 02/14] mm: thp: KVM: Explicitly check for THP when populating secondary MMU

2020-01-08 Thread Sean Christopherson
Add a helper, is_transparent_hugepage(), to explicitly check whether a compound page is a THP and use it when populating KVM's secondary MMU. The explicit check fixes a bug where a remapped compound page, e.g. for an XDP Rx socket, is mapped into a KVM guest and is mistaken for a THP, which results

[PATCH 10/14] KVM: x86/mmu: Remove obsolete gfn restoration in FNAME(fetch)

2020-01-08 Thread Sean Christopherson
Remove logic to retrieve the original gfn now that HugeTLB mappings are are identified in FNAME(fetch), i.e. FNAME(page_fault) no longer adjusts the level or gfn. Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/paging_tmpl.h | 13 +++-- 1 file changed, 3 insertions(+), 10 deletio

[PATCH 09/14] KVM: x86/mmu: Rely on host page tables to find HugeTLB mappings

2020-01-08 Thread Sean Christopherson
Remove KVM's HugeTLB specific logic and instead rely on walking the host page tables (already done for THP) to identify HugeTLB mappings. Eliminating the HugeTLB-only logic avoids taking mmap_sem and calling find_vma() for all hugepage compatible page faults, and simplifies KVM's page fault code by

[PATCH 03/14] KVM: Use vcpu-specific gva->hva translation when querying host page size

2020-01-08 Thread Sean Christopherson
Use kvm_vcpu_gfn_to_hva() when retrieving the host page size so that the correct set of memslots is used when handling x86 page faults in SMM. Fixes: 54bf36aac520 ("KVM: x86: use vcpu-specific functions to read/write/translate GFNs") Cc: sta...@vger.kernel.org Signed-off-by: Sean Christopherson

[PATCH 01/14] KVM: x86/mmu: Enforce max_level on HugeTLB mappings

2020-01-08 Thread Sean Christopherson
Limit KVM's mapping level for HugeTLB based on its calculated max_level. The max_level check prior to invoking host_mapping_level() only filters out the case where KVM cannot create a 2mb mapping, it doesn't handle the scenario where KVM can create a 2mb but not 1gb mapping, and the host is using a

[PATCH 05/14] x86/mm: Introduce lookup_address_in_mm()

2020-01-08 Thread Sean Christopherson
Add a helper, lookup_address_in_mm(), to traverse the page tables of a given mm struct. KVM will use the helper to retrieve the host mapping level, e.g. 4k vs. 2mb vs. 1gb, of a compound (or DAX-backed) page without having to resort to implementation specific metadata. E.g. KVM currently uses dif

[PATCH 13/14] KVM: x86/mmu: Remove lpage_is_disallowed() check from set_spte()

2020-01-08 Thread Sean Christopherson
Remove the late "lpage is disallowed" check from set_spte() now that the initial check is performed after acquiring mmu_lock. Fold the guts of the remaining helper, __mmu_gfn_lpage_is_disallowed(), into kvm_mmu_hugepage_adjust() to eliminate the unnecessary slot !NULL check. Signed-off-by: Sean C

[PATCH 08/14] KVM: x86/mmu: Drop level optimization from fast_page_fault()

2020-01-08 Thread Sean Christopherson
Remove fast_page_fault()'s optimization to stop the shadow walk if the iterator level drops below the intended map level. The intended map level is only acccurate for HugeTLB mappings (THP mappings are detected after fast_page_fault()), i.e. it's not required for correctness, and a future patch wi

[PATCH 14/14] KVM: x86/mmu: Use huge pages for DAX-backed files

2020-01-08 Thread Sean Christopherson
Walk the host page tables to identify hugepage mappings for ZONE_DEVICE pfns, i.e. DAX pages. Explicitly query kvm_is_zone_device_pfn() when deciding whether or not to bother walking the host page tables, as DAX pages do not set up the head/tail infrastructure, i.e. will return false for PageCompo

[PATCH 11/14] KVM: x86/mmu: Zap any compound page when collapsing sptes

2020-01-08 Thread Sean Christopherson
Zap any compound page, e.g. THP or HugeTLB pages, when zapping sptes that can potentially be converted to huge sptes after disabling dirty logging on the associated memslot. Note, this approach could result in false positives, e.g. if a random compound page is mapped into the guest, but mapping no

[PATCH 12/14] KVM: x86/mmu: Fold max_mapping_level() into kvm_mmu_hugepage_adjust()

2020-01-08 Thread Sean Christopherson
Fold max_mapping_level() into kvm_mmu_hugepage_adjust() now that HugeTLB mappings are handled in kvm_mmu_hugepage_adjust(), i.e. there isn't a need to pre-calculate the max mapping level. Co-locating all hugepage checks eliminates a memslot lookup, at the cost of performing the __mmu_gfn_lpage_is_

[PATCH kvmtool] Add emulation for CFI compatible flash memory

2020-01-08 Thread Andre Przywara
From: Raphael Gault The EDK II UEFI firmware implementation requires some storage for the EFI variables, which is typically some flash storage. Since this is already supported on the EDK II side, we add a CFI flash emulation to kvmtool. This is backed by a file, specified via the --flash or -F co

Re: [PATCHv2 2/3] KVM: arm/arm64: correct CPSR on exception entry

2020-01-08 Thread Mark Rutland
On Wed, Jan 08, 2020 at 02:41:04PM +, Alexandru Elisei wrote: > On 1/8/20 1:43 PM, Mark Rutland wrote: > > When KVM injects an exception into a guest, it generates the CPSR value > > from scratch, configuring CPSR.{M,A,I,T,E}, and setting all other > > bits to zero. > > > > This isn't correct,

Re: [PATCHv2 2/3] KVM: arm/arm64: correct CPSR on exception entry

2020-01-08 Thread Alexandru Elisei
Hello, On 1/8/20 1:43 PM, Mark Rutland wrote: > When KVM injects an exception into a guest, it generates the CPSR value > from scratch, configuring CPSR.{M,A,I,T,E}, and setting all other > bits to zero. > > This isn't correct, as the architecture specifies that some CPSR bits > are (conditionally

Re: [PATCHv2 1/3] KVM: arm64: correct PSTATE on exception entry

2020-01-08 Thread Alexandru Elisei
Hello, On 1/8/20 1:43 PM, Mark Rutland wrote: > When KVM injects an exception into a guest, it generates the PSTATE > value from scratch, configuring PSTATE.{M[4:0],DAIF}, and setting all > other bits to zero. > > This isn't correct, as the architecture specifies that some PSTATE bits > are (condi

Re: [PATCHv2 0/3] KVM: arm/arm64: exception injection fixes

2020-01-08 Thread Mark Rutland
On Wed, Jan 08, 2020 at 01:43:21PM +, Mark Rutland wrote: > Since v1 [2]: > * Fix host_spsr_to_spsr32() bit preservation > * Fix SPAN polarity; tested with a modified arm64 guest > * Fix DIT preservation on 32-bit hosts > * Add Alex's Reviewed-by to patch 3 > > Thanks, > Mark. > > [1] > http

[PATCHv2 2/3] KVM: arm/arm64: correct CPSR on exception entry

2020-01-08 Thread Mark Rutland
When KVM injects an exception into a guest, it generates the CPSR value from scratch, configuring CPSR.{M,A,I,T,E}, and setting all other bits to zero. This isn't correct, as the architecture specifies that some CPSR bits are (conditionally) cleared or set upon an exception, and others are unchang

[PATCHv2 1/3] KVM: arm64: correct PSTATE on exception entry

2020-01-08 Thread Mark Rutland
When KVM injects an exception into a guest, it generates the PSTATE value from scratch, configuring PSTATE.{M[4:0],DAIF}, and setting all other bits to zero. This isn't correct, as the architecture specifies that some PSTATE bits are (conditionally) cleared or set upon an exception, and others are

[PATCHv2 3/3] KVM: arm/arm64: correct AArch32 SPSR on exception entry

2020-01-08 Thread Mark Rutland
Confusingly, there are three SPSR layouts that a kernel may need to deal with: (1) An AArch64 SPSR_ELx view of an AArch64 pstate (2) An AArch64 SPSR_ELx view of an AArch32 pstate (3) An AArch32 SPSR_* view of an AArch32 pstate When the KVM AArch32 support code deals with SPSR_{EL2,HYP}, it's eith

[PATCHv2 0/3] KVM: arm/arm64: exception injection fixes

2020-01-08 Thread Mark Rutland
Hi, While looking at the KVM code, I realised that our exception injection handling isn't quite right, as it generates the target PSTATE/CPSR from scratch, and doesn't handle all bits which need to be (conditionally) cleared or set upon taking an exception. The first two patches address this for

Re: [PATCH v2 09/18] arm64: KVM: enable conditional save/restore full SPE profiling buffer controls

2020-01-08 Thread Will Deacon
On Wed, Jan 08, 2020 at 12:36:11PM +, Marc Zyngier wrote: > On 2020-01-08 11:58, Will Deacon wrote: > > On Wed, Jan 08, 2020 at 11:17:16AM +, Marc Zyngier wrote: > > > On 2020-01-07 15:13, Andrew Murray wrote: > > > > Looking at the vcpu_load and related code, I don't see a way of saying >

Re: [PATCH 1/3] KVM: arm64: correct PSTATE on exception entry

2020-01-08 Thread Alexandru Elisei
Hi, On 1/8/20 11:12 AM, Mark Rutland wrote: > Hi Alex, > > On Fri, Dec 27, 2019 at 01:01:57PM +, Alexandru Elisei wrote: >> On 12/20/19 3:05 PM, Mark Rutland wrote: >>> When KVM injects an exception into a guest, it generates the PSTATE >>> value from scratch, configuring PSTATE.{M[4:0],DAIF},

Re: [PATCH v2 09/18] arm64: KVM: enable conditional save/restore full SPE profiling buffer controls

2020-01-08 Thread Marc Zyngier
On 2020-01-08 11:58, Will Deacon wrote: On Wed, Jan 08, 2020 at 11:17:16AM +, Marc Zyngier wrote: On 2020-01-07 15:13, Andrew Murray wrote: > On Sat, Dec 21, 2019 at 02:13:25PM +, Marc Zyngier wrote: > > On Fri, 20 Dec 2019 14:30:16 + > > Andrew Murray wrote: > > > > [somehow manage

Re: [PATCH v2 09/18] arm64: KVM: enable conditional save/restore full SPE profiling buffer controls

2020-01-08 Thread Will Deacon
On Wed, Jan 08, 2020 at 11:17:16AM +, Marc Zyngier wrote: > On 2020-01-07 15:13, Andrew Murray wrote: > > On Sat, Dec 21, 2019 at 02:13:25PM +, Marc Zyngier wrote: > > > On Fri, 20 Dec 2019 14:30:16 + > > > Andrew Murray wrote: > > > > > > [somehow managed not to do a reply all, re-se

Re: [PATCH 2/3] KVM: arm/arm64: correct CPSR on exception entry

2020-01-08 Thread Mark Rutland
On Fri, Dec 27, 2019 at 03:42:34PM +, Alexandru Elisei wrote: > Hi, > > On 12/20/19 3:05 PM, Mark Rutland wrote: > > When KVM injects an exception into a guest, it generates the CPSR value > > from scratch, configuring CPSR.{M,A,I,T,E}, and setting all other > > bits to zero. > > > > This isn'

Re: [PATCH v2 09/18] arm64: KVM: enable conditional save/restore full SPE profiling buffer controls

2020-01-08 Thread Marc Zyngier
On 2020-01-07 15:13, Andrew Murray wrote: On Sat, Dec 21, 2019 at 02:13:25PM +, Marc Zyngier wrote: On Fri, 20 Dec 2019 14:30:16 + Andrew Murray wrote: [somehow managed not to do a reply all, re-sending] > From: Sudeep Holla > > Now that we can save/restore the full SPE controls, we

Re: [PATCH 1/3] KVM: arm64: correct PSTATE on exception entry

2020-01-08 Thread Mark Rutland
On Sun, Dec 29, 2019 at 03:17:40PM +, Marc Zyngier wrote: > On Fri, 27 Dec 2019 13:01:57 +, > Alexandru Elisei wrote: > > On 12/20/19 3:05 PM, Mark Rutland wrote: > > > + // PSTATE.PAN is unchanged unless overridden by SCTLR_ELx.SPAN > > > + // See ARM DDI 0487E.a, page D5-2578. > > > + ne

Re: [PATCH 1/3] KVM: arm64: correct PSTATE on exception entry

2020-01-08 Thread Mark Rutland
Hi Alex, On Fri, Dec 27, 2019 at 01:01:57PM +, Alexandru Elisei wrote: > On 12/20/19 3:05 PM, Mark Rutland wrote: > > When KVM injects an exception into a guest, it generates the PSTATE > > value from scratch, configuring PSTATE.{M[4:0],DAIF}, and setting all > > other bits to zero. > > > > Th