From: Suzuki.Poulose@arm.com (Suzuki K Poulose)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v5 5/7] KVM: arm64: Support handling access faults for PUD hugepages
Date: Wed, 11 Jul 2018 14:16:56 +0100 [thread overview]
Message-ID: <be9492ce-271c-e87f-e934-a6bb3a5ac119@arm.com> (raw)
In-Reply-To: <20180709144124.29164-5-punit.agrawal@arm.com>
On 09/07/18 15:41, Punit Agrawal wrote:
> In preparation for creating larger hugepages at Stage 2, extend the
> access fault handling at Stage 2 to support PUD hugepages when
> encountered.
>
> Provide trivial helpers for arm32 to allow sharing of code.
>
> Signed-off-by: Punit Agrawal <punit.agrawal@arm.com>
> Cc: Christoffer Dall <christoffer.dall@arm.com>
> Cc: Marc Zyngier <marc.zyngier@arm.com>
> Cc: Russell King <linux@armlinux.org.uk>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> ---
> arch/arm/include/asm/kvm_mmu.h | 8 ++++++++
> arch/arm64/include/asm/kvm_mmu.h | 7 +++++++
> arch/arm64/include/asm/pgtable.h | 6 ++++++
> virt/kvm/arm/mmu.c | 29 ++++++++++++++++-------------
> 4 files changed, 37 insertions(+), 13 deletions(-)
>
> diff --git a/arch/arm/include/asm/kvm_mmu.h b/arch/arm/include/asm/kvm_mmu.h
> index d05c8986e495..a4298d429efc 100644
> --- a/arch/arm/include/asm/kvm_mmu.h
> +++ b/arch/arm/include/asm/kvm_mmu.h
> @@ -78,6 +78,8 @@ void kvm_clear_hyp_idmap(void);
> #define kvm_pfn_pte(pfn, prot) pfn_pte(pfn, prot)
> #define kvm_pfn_pmd(pfn, prot) pfn_pmd(pfn, prot)
>
> +#define kvm_pud_pfn(pud) (((pud_val(pud) & PUD_MASK) & PHYS_MASK) >> PAGE_SHIFT)
Since we don't have PUD in arm32, it would be good to trigger a BUG()
instead of silently doing something wrong.
> @@ -102,6 +104,12 @@ static inline bool kvm_s2pud_exec(pud_t *pud)
> return false;
> }
>
> +static inline pud_t kvm_s2pud_mkyoung(pud_t pud)
> +{
> + BUG();
> + return pud;
> +}
> +
Like this. ^
> diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c
> index e73909a31e02..d2c705e31584 100644
> --- a/virt/kvm/arm/mmu.c
> +++ b/virt/kvm/arm/mmu.c
> @@ -1637,33 +1637,36 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
> */
> static void handle_access_fault(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa)
> {
> - pmd_t *pmd;
> - pte_t *pte;
> + pud_t *pud = NULL;
> + pmd_t *pmd = NULL;
> + pte_t *pte = NULL;
> kvm_pfn_t pfn;
> - bool pfn_valid = false;
> + bool found, pfn_valid = false;
nit: You could use pfn_valid instead of a new "found" variable.
>
> trace_kvm_access_fault(fault_ipa);
>
> spin_lock(&vcpu->kvm->mmu_lock);
>
> - pmd = stage2_get_pmd(vcpu->kvm, NULL, fault_ipa);
> - if (!pmd || pmd_none(*pmd)) /* Nothing there */
> + found = stage2_get_leaf_entry(vcpu->kvm, fault_ipa, &pud, &pmd, &pte);
> + if (!found)
> goto out;
>
> - if (pmd_thp_or_huge(*pmd)) { /* THP, HugeTLB */
> + if (pud) { /* HugeTLB */
> + *pud = kvm_s2pud_mkyoung(*pud);
> + pfn = kvm_pud_pfn(*pud);
> + pfn_valid = true;
> + goto out;
You don't need these goto's and the out lable anymore.
> + } else if (pmd) { /* THP, HugeTLB */
> *pmd = pmd_mkyoung(*pmd);
> pfn = pmd_pfn(*pmd);
> pfn_valid = true;
> goto out;
> + } else {
> + *pte = pte_mkyoung(*pte); /* Just a page... */
> + pfn = pte_pfn(*pte);
> + pfn_valid = true;
> }
>
> - pte = pte_offset_kernel(pmd, fault_ipa);
> - if (pte_none(*pte)) /* Nothing there either */
> - goto out;
> -
> - *pte = pte_mkyoung(*pte); /* Just a page... */
> - pfn = pte_pfn(*pte);
> - pfn_valid = true;
> out:
> spin_unlock(&vcpu->kvm->mmu_lock);
> if (pfn_valid)
>
Otherwise look good to me.
Suzuki
next prev parent reply other threads:[~2018-07-11 13:16 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-09 14:38 [PATCH v5 0/7] KVM: Support PUD hugepages at stage 2 Punit Agrawal
2018-07-09 14:38 ` Punit Agrawal
2018-07-09 14:49 ` Punit Agrawal
2018-07-09 14:41 ` [PATCH v5 1/7] KVM: arm/arm64: Share common code in user_mem_abort() Punit Agrawal
2018-07-09 14:41 ` [PATCH v5 2/7] KVM: arm/arm64: Introduce helpers to manupulate page table entries Punit Agrawal
2018-07-11 13:00 ` Suzuki K Poulose
2018-07-11 16:10 ` Punit Agrawal
2018-07-09 14:41 ` [PATCH v5 3/7] KVM: arm64: Support dirty page tracking for PUD hugepages Punit Agrawal
2018-07-11 13:03 ` Suzuki K Poulose
2018-07-09 14:41 ` [PATCH v5 4/7] KVM: arm64: Support PUD hugepage in stage2_is_exec() Punit Agrawal
2018-07-11 13:41 ` Suzuki K Poulose
2018-07-11 15:05 ` Punit Agrawal
2018-07-09 14:41 ` [PATCH v5 5/7] KVM: arm64: Support handling access faults for PUD hugepages Punit Agrawal
2018-07-11 13:16 ` Suzuki K Poulose [this message]
2018-07-09 14:41 ` [PATCH v5 6/7] KVM: arm64: Update age handlers to support " Punit Agrawal
2018-07-11 13:23 ` Suzuki K Poulose
2018-07-09 14:41 ` [PATCH v5 7/7] KVM: arm64: Add support for creating PUD hugepages at stage 2 Punit Agrawal
2018-07-11 13:38 ` Suzuki K Poulose
2018-07-11 16:05 ` Punit Agrawal
2018-07-11 16:13 ` Suzuki K Poulose
2018-07-11 16:19 ` Punit Agrawal
2018-07-11 12:59 ` [PATCH v5 1/7] KVM: arm/arm64: Share common code in user_mem_abort() Suzuki K Poulose
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=be9492ce-271c-e87f-e934-a6bb3a5ac119@arm.com \
--to=suzuki.poulose@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox