From: Auger Eric <eric.auger@redhat.com>
To: Alexandru Elisei <alexandru.elisei@arm.com>,
kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu
Cc: pbonzini@redhat.com, Andrew Jones <drjones@redhat.com>
Subject: Re: [kvm-unit-tests RFC PATCH v2 4/5] lib: arm/arm64: Add function to unmap a page
Date: Fri, 30 Oct 2020 16:46:14 +0100 [thread overview]
Message-ID: <a4ea8427-2894-12b3-7b63-e551eec57a96@redhat.com> (raw)
In-Reply-To: <20201027171944.13933-5-alexandru.elisei@arm.com>
Hi Alexandru,
On 10/27/20 6:19 PM, Alexandru Elisei wrote:
> Being able to cause a stage 1 data abort might be useful for future tests.
> Add a function that unmaps a page from the translation tables.
>
> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
> ---
> lib/arm/asm/mmu-api.h | 1 +
> lib/arm/mmu.c | 32 ++++++++++++++++++++++++++++++++
> 2 files changed, 33 insertions(+)
>
> diff --git a/lib/arm/asm/mmu-api.h b/lib/arm/asm/mmu-api.h
> index 2bbe1faea900..305f77c6501f 100644
> --- a/lib/arm/asm/mmu-api.h
> +++ b/lib/arm/asm/mmu-api.h
> @@ -23,4 +23,5 @@ extern void mmu_set_range_ptes(pgd_t *pgtable, uintptr_t virt_offset,
> phys_addr_t phys_start, phys_addr_t phys_end,
> pgprot_t prot);
> extern void mmu_clear_user(pgd_t *pgtable, unsigned long vaddr);
> +extern void mmu_unmap_page(pgd_t *pgtable, unsigned long vaddr);
> #endif
> diff --git a/lib/arm/mmu.c b/lib/arm/mmu.c
> index 540a1e842d5b..72ac0be8d146 100644
> --- a/lib/arm/mmu.c
> +++ b/lib/arm/mmu.c
> @@ -232,3 +232,35 @@ void mmu_clear_user(pgd_t *pgtable, unsigned long vaddr)
> out_flush_tlb:
> flush_tlb_page(vaddr);
> }
> +
> +void mmu_unmap_page(pgd_t *pgtable, unsigned long vaddr)
> +{
> + pgd_t *pgd;
> + pmd_t *pmd;
> + pte_t *pte;
> +
> + if (!mmu_enabled())
> + return;
> +
> + pgd = pgd_offset(pgtable, vaddr);
> + if (!pgd_valid(*pgd))
> + return;
> +
> + pmd = pmd_offset(pgd, vaddr);
> + if (!pmd_valid(*pmd))
> + return;
> +
> + if (pmd_huge(*pmd)) {
> + WRITE_ONCE(*pmd, 0);
> + goto out_flush_tlb;
> + } else {
is the else needed?
> + pte = pte_offset(pmd, vaddr);
> + if (!pte_valid(*pte))
> + return;
> + WRITE_ONCE(*pte, 0);
> + goto out_flush_tlb;
> + }
> +
> +out_flush_tlb:
> + flush_tlb_page(vaddr);
> +}
>
This code is very similar to mmu_clear_user() besides the bit to invalidate
Just wondering if we couldn't use the same code and pass a bit offset.
It seems the offsets in PMD and PTE are same for USER bit and valid bit.
But maybe this is far-fetched and not worth the sharing.
I see Drew is not in CC, + Drew
Besides
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Thanks
Eric
next prev parent reply other threads:[~2020-10-30 15:46 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-27 17:19 [kvm-unit-tests RFC PATCH v2 0/5] arm64: Statistical Profiling Extension Tests Alexandru Elisei
2020-10-27 17:19 ` [kvm-unit-tests RFC PATCH v2 1/5] arm64: Move get_id_aa64dfr0() in processor.h Alexandru Elisei
2020-10-27 17:19 ` [kvm-unit-tests RFC PATCH v2 2/5] lib/{bitops,alloc_page}.h: Add missing headers Alexandru Elisei
2020-10-30 15:29 ` [kvm-unit-tests RFC PATCH v2 2/5] lib/{bitops, alloc_page}.h: " Auger Eric
2020-10-30 15:58 ` Alexandru Elisei
2020-10-27 17:19 ` [kvm-unit-tests RFC PATCH v2 3/5] arm64: spe: Add introspection test Alexandru Elisei
2020-10-30 15:29 ` Auger Eric
2020-10-30 15:59 ` Alexandru Elisei
2020-10-30 17:09 ` Auger Eric
2020-10-30 17:50 ` Alexandru Elisei
2020-10-30 17:52 ` Auger Eric
2020-11-02 10:47 ` Andrew Jones
2020-10-27 17:19 ` [kvm-unit-tests RFC PATCH v2 4/5] lib: arm/arm64: Add function to unmap a page Alexandru Elisei
2020-10-30 15:46 ` Auger Eric [this message]
2020-10-30 16:00 ` Alexandru Elisei
2020-10-27 17:19 ` [kvm-unit-tests RFC PATCH v2 5/5] am64: spe: Add buffer test Alexandru Elisei
2020-10-30 17:59 ` Auger Eric
2020-10-30 16:02 ` [kvm-unit-tests RFC PATCH v2 0/5] arm64: Statistical Profiling Extension Tests Alexandru Elisei
2020-10-30 18:17 ` Auger Eric
2020-10-30 22:31 ` Alexandru Elisei
2020-11-02 12:19 ` Auger Eric
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=a4ea8427-2894-12b3-7b63-e551eec57a96@redhat.com \
--to=eric.auger@redhat.com \
--cc=alexandru.elisei@arm.com \
--cc=drjones@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=pbonzini@redhat.com \
/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;
as well as URLs for NNTP newsgroup(s).