From: marc.zyngier@arm.com (Marc Zyngier)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC PATCH 06/20] arm64: mm: place empty_zero_page in bss
Date: Thu, 10 Dec 2015 15:40:08 +0000 [thread overview]
Message-ID: <56699CD8.2010009@arm.com> (raw)
In-Reply-To: <20151210152957.GD495@leverpostej>
On 10/12/15 15:29, Mark Rutland wrote:
> On Thu, Dec 10, 2015 at 02:11:08PM +0000, Will Deacon wrote:
>> On Wed, Dec 09, 2015 at 12:44:41PM +0000, Mark Rutland wrote:
>>> Currently the zero page is set up in paging_init, and thus we cannot use
>>> the zero page earlier. We use the zero page as a reserved TTBR value
>>> from which no TLB entries may be allocated (e.g. when uninstalling the
>>> idmap). To enable such usage earlier (as may be required for invasive
>>> changes to the kernel page tables), and to minimise the time that the
>>> idmap is active, we need to be able to use the zero page before
>>> paging_init.
>>>
>>> This patch follows the example set by x86, by allocating the zero page
>>> at compile time, in .bss. This means that the zero page itself is
>>> available immediately upon entry to start_kernel (as we zero .bss before
>>> this), and also means that the zero page takes up no space in the raw
>>> Image binary. The associated struct page is allocated in bootmem_init,
>>> and remains unavailable until this time.
>>>
>>> Outside of arch code, the only users of empty_zero_page assume that the
>>> empty_zero_page symbol refers to the zeroed memory itself, and that
>>> ZERO_PAGE(x) must be used to acquire the associated struct page,
>>> following the example of x86. This patch also brings arm64 inline with
>>> these assumptions.
>>>
>>> Signed-off-by: Mark Rutland <mark.rutland@arm.com>
>>> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
>>> Cc: Catalin Marinas <catalin.marinas@arm.com>
>>> Cc: Jeremy Linton <jeremy.linton@arm.com>
>>> Cc: Laura Abbott <labbott@fedoraproject.org>
>>> Cc: Will Deacon <will.deacon@arm.com>
>>> ---
>>> arch/arm64/include/asm/mmu_context.h | 2 +-
>>> arch/arm64/include/asm/pgtable.h | 4 ++--
>>> arch/arm64/mm/mmu.c | 9 +--------
>>> 3 files changed, 4 insertions(+), 11 deletions(-)
>>
>> [...]
>>
>>> diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
>>> index 304ff23..7559c22 100644
>>> --- a/arch/arm64/mm/mmu.c
>>> +++ b/arch/arm64/mm/mmu.c
>>> @@ -48,7 +48,7 @@ u64 idmap_t0sz = TCR_T0SZ(VA_BITS);
>>> * Empty_zero_page is a special page that is used for zero-initialized data
>>> * and COW.
>>> */
>>> -struct page *empty_zero_page;
>>> +unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)] __page_aligned_bss;
>>> EXPORT_SYMBOL(empty_zero_page);
>>
>> I've been looking at this, and it was making me feel uneasy because it's
>> full of junk before the bss is zeroed. Working that through, it's no
>> worse than what we currently have but I then realised that (a) we don't
>> have a dsb after zeroing the zero page (which we need to make sure the
>> zeroes are visible to the page table walker and (b) the zero page is
>> never explicitly cleaned to the PoC.
>
> Ouch; that's scary.
>
>> There may be cases where the zero-page is used to back read-only,
>> non-cacheable mappings (something to do with KVM?), so I'd sleep better
>> if we made sure that it was clean.
>
> From a grep around for uses of ZERO_PAGE, in most places the zero page
> is simply used as an empty buffer for I/O. In these cases it's either
> accessed coherently or goes via the usual machinery for non-coherent DMA
> kicks in.
>
> I don't believe that we usually give userspace the ability to create
> non-cacheable mappings, and I couldn't spot any paths it could do so via
> some driver-specific IOCTL applied to the zero page.
>
> Looking around, kvm_clear_guest_page seemed problematic, but isn't used
> on arm64. I can imagine the zero page being mapped into guests in other
> situations when mirroring the userspace mapping.
>
> Marc, Christoffer, I thought we cleaned pages to the PoC before mapping
> them into a guest? Is that right? Or do we have potential issues there?
I think we're OK. Looking at __coherent_cache_guest_page (which is
called when transitioning from an invalid to valid mapping), we do flush
things to PoC if the vcpu has its cache disabled (or if we know that the
IPA shouldn't be cached - the whole NOR flash emulation horror story).
Does it answer your question?
M.
--
Jazz is not dead. It just smells funny...
next prev parent reply other threads:[~2015-12-10 15:40 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-09 12:44 [RFC PATCH 00/20] arm64: mm: rework page table creation Mark Rutland
2015-12-09 12:44 ` [RFC PATCH 01/20] arm64: mm: remove pointless PAGE_MASKing Mark Rutland
2015-12-09 12:44 ` [RFC PATCH 02/20] arm64: Remove redundant padding from linker script Mark Rutland
2015-12-09 12:44 ` [RFC PATCH 03/20] arm64: mm: fold alternatives into .init Mark Rutland
2015-12-09 12:44 ` [RFC PATCH 04/20] arm64: mm: assume PAGE SIZE for page table allocator Mark Rutland
2015-12-10 14:08 ` Will Deacon
2015-12-10 14:23 ` Mark Rutland
2015-12-09 12:44 ` [RFC PATCH 05/20] asm-generic: make __set_fixmap_offset a static inline Mark Rutland
2015-12-09 12:44 ` [RFC PATCH 06/20] arm64: mm: place empty_zero_page in bss Mark Rutland
2015-12-10 14:11 ` Will Deacon
2015-12-10 15:29 ` Mark Rutland
2015-12-10 15:40 ` Marc Zyngier [this message]
2015-12-10 15:51 ` Mark Rutland
2015-12-10 16:01 ` Marc Zyngier
2015-12-09 12:44 ` [RFC PATCH 07/20] arm64: unify idmap removal Mark Rutland
2015-12-09 12:44 ` [RFC PATCH 08/20] arm64: unmap idmap earlier Mark Rutland
2015-12-09 12:44 ` [RFC PATCH 09/20] arm64: add function to install the idmap Mark Rutland
2015-12-09 12:44 ` [RFC PATCH 10/20] arm64: mm: add code to safely replace TTBR1_EL1 Mark Rutland
2015-12-09 12:44 ` [RFC PATCH 11/20] arm64: mm: move pte_* macros Mark Rutland
2015-12-09 12:44 ` [RFC PATCH 12/20] arm64: mm: add functions to walk page tables by PA Mark Rutland
2015-12-09 12:44 ` [RFC PATCH 13/20] arm64: mm: avoid redundant __pa(__va(x)) Mark Rutland
2015-12-09 12:44 ` [RFC PATCH 14/20] arm64: mm: add __{pud,pgd}_populate Mark Rutland
2015-12-09 12:44 ` [RFC PATCH 15/20] arm64: mm: add functions to walk tables in fixmap Mark Rutland
2015-12-09 12:44 ` [RFC PATCH 16/20] arm64: mm: use fixmap when creating page tables Mark Rutland
2015-12-09 12:44 ` [RFC PATCH 17/20] arm64: mm: allocate pagetables anywhere Mark Rutland
2015-12-09 12:44 ` [RFC PATCH 18/20] arm64: mm: allow passing a pgdir to alloc_init_* Mark Rutland
2015-12-09 12:44 ` [RFC PATCH 19/20] arm64: ensure _stext and _etext are page-aligned Mark Rutland
2015-12-09 12:44 ` [RFC PATCH 20/20] arm64: mm: create new fine-grained mappings at boot Mark Rutland
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=56699CD8.2010009@arm.com \
--to=marc.zyngier@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;
as well as URLs for NNTP newsgroup(s).