From: mark.rutland@arm.com (Mark Rutland)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/5] arm64: mm: Add slow_virt_to_phys()
Date: Wed, 20 Jun 2018 09:06:48 +0100 [thread overview]
Message-ID: <20180620080648.yteuodd3hl7nrh35@salmiak> (raw)
In-Reply-To: <1529443395-20874-2-git-send-email-mikelley@microsoft.com>
Hi,
On Tue, Jun 19, 2018 at 02:23:11PM -0700, Michael Kelley wrote:
> Add slow_virt_to_phys() function for ARM64 that parallels the same
> function on x86/x64. This is needed by the architecture independent
> Hyper-V VMbus driver at drivers/hv/channel.c. The implementation
> directly translates the virtual address using the ARM64 'at'
> instruction.
>
> Signed-off-by: Michael Kelley <mikelley@microsoft.com>
> Reviewed-by: James Morris <james.morris@microsoft.com>
> ---
> arch/arm64/include/asm/memory.h | 6 ++++++
> arch/arm64/mm/pageattr.c | 37 +++++++++++++++++++++++++++++++++++++
> 2 files changed, 43 insertions(+)
>
> diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h
> index 49d9921..3f68dcf 100644
> --- a/arch/arm64/include/asm/memory.h
> +++ b/arch/arm64/include/asm/memory.h
> @@ -265,6 +265,12 @@ static inline void *phys_to_virt(phys_addr_t x)
> }
>
> /*
> + * For memory where the underlying physical pages may not
> + * be contiguous.
> + */
> +extern phys_addr_t slow_virt_to_phys(void *vaddr);
> +
> +/*
> * Drivers should NOT use these either.
> */
> #define __pa(x) __virt_to_phys((unsigned long)(x))
> diff --git a/arch/arm64/mm/pageattr.c b/arch/arm64/mm/pageattr.c
> index a563593..8a42cac 100644
> --- a/arch/arm64/mm/pageattr.c
> +++ b/arch/arm64/mm/pageattr.c
> @@ -19,6 +19,8 @@
> #include <asm/pgtable.h>
> #include <asm/set_memory.h>
> #include <asm/tlbflush.h>
> +#include <asm/sysreg.h>
> +#include <asm/barrier.h>
>
> struct page_change_data {
> pgprot_t set_mask;
> @@ -185,3 +187,38 @@ bool kernel_page_present(struct page *page)
> }
> #endif /* CONFIG_HIBERNATION */
> #endif /* CONFIG_DEBUG_PAGEALLOC */
> +
> +/*
> + * For virtual addresses where the underlyine physical memory may not be
> + * contiguous and the normal virt_to_phys gives the wrong result. This
> + * function does an actual translation using the 'at' instruction.
> + */
> +phys_addr_t slow_virt_to_phys(void *virt_addr)
> +{
> + phys_addr_t result;
> + unsigned long input = (unsigned long)virt_addr;
> + char touch;
> + int i;
> +
> + /* Try up to 3 times (an arbitrary number) */
> + for (i = 0; i < 3; i++) {
> + /* Do the translation and check that it worked */
> + asm volatile("at s1e1r, %0" : : "r" (input));
> + isb();
> + result = read_sysreg(par_el1);
> + if (likely(!(result & 0x1)))
> + return (result & GENMASK_ULL(51, 12)) |
> + (input & GENMASK_ULL(11, 0));
> + /*
> + * Something failed. Read the page to fault in anything
> + * that isn't resident, then try again. "Anything"
> + * could include the page itself or hypervisor page tables.
> + */
> + touch = READ_ONCE(*(char *)input);
> + dmb(sy);
> + }
> +
> + /* Let the caller sort it out. */
> + return -1;
AFAICT, callers of slow_virt_to_phys() don't check the value, so this doesn't
seem safe, and I'm concerned by the possibility of spurious failures given we
only retry a fixed number of times.
I think it would be better to walk the page tables, as x86 does, as that's
guaranteed to complete within a fixed bound (i.e. after we read all the levls
of table).
Thanks,
Mark.
next prev parent reply other threads:[~2018-06-20 8:06 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-19 21:23 [PATCH 0/5] Enable Linux guests on Hyper-V on ARM64 Michael Kelley
2018-06-19 21:23 ` [PATCH 1/5] arm64: mm: Add slow_virt_to_phys() Michael Kelley
2018-06-20 8:06 ` Mark Rutland [this message]
2018-06-19 21:23 ` [PATCH 2/5] arm64: hyperv: Add core Hyper-V include files Michael Kelley
2018-06-19 21:23 ` [PATCH 3/5] arm64: hyperv: Add support for Hyper-V as a hypervisor Michael Kelley
2018-06-19 21:23 ` [PATCH 4/5] Drivers: hv: vmbus: Add hooks for per-CPU IRQ Michael Kelley
2018-06-19 21:23 ` [PATCH 5/5] Drivers: hv: Enable CONFIG_HYPERV on ARM64 Michael Kelley
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=20180620080648.yteuodd3hl7nrh35@salmiak \
--to=mark.rutland@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