linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Giulio Benetti <giulio.benetti@benettiengineering.com>
To: Arnd Bergmann <arnd@arndb.de>,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Cc: Russell King <linux@armlinux.org.uk>,
	Anshuman Khandual <anshuman.khandual@arm.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Kefeng Wang <wangkefeng.wang@huawei.com>,
	Russell King <rmk+kernel@armlinux.org.uk>,
	Will Deacon <will@kernel.org>
Subject: Re: [PATCH] ARM: mm: fix no-MMU ZERO_PAGE() implementation
Date: Tue, 18 Oct 2022 19:44:11 +0200	[thread overview]
Message-ID: <972a3be7-4522-b4f0-adfa-6b42be56c52f@benettiengineering.com> (raw)
In-Reply-To: <3fb4afd1-2eea-4a71-a914-f8208b11f9f4@app.fastmail.com>

Hi Arnd,

On 18/10/22 09:03, Arnd Bergmann wrote:
> On Tue, Oct 18, 2022, at 1:37 AM, Giulio Benetti wrote:
>> Actually in no-MMU SoCs(i.e. i.MXRT) ZERO_PAGE(vaddr) expands to
>> ```
>> virt_to_page(0)
>> ```
>> that in order expands to:
>> ```
>> pfn_to_page(virt_to_pfn(0))
>> ```
>> and then virt_to_pfn(0) to:
>> ```
>> #define virt_to_pfn(0) \
>> 	((((unsigned long)(0) - PAGE_OFFSET) >> PAGE_SHIFT) + \
>> 	 PHYS_PFN_OFFSET)
>> ```
>> where PAGE_OFFSET and PHYS_PFN_OFFSET are the DRAM offset(0x80000000) and
>> PAGE_SHIFT is 12. This way we obtain 16MB(0x01000000) summed to the base of
>> DRAM(0x80000000).
>> When ZERO_PAGE(0) is then used, for example in bio_add_page(), the page
>> gets an address that is out of DRAM bounds.
>> So instead of using fake virtual page 0 let's allocate a dedicated
>> zero_page during paging_init() and assign it to a global 'struct page *
>> empty_zero_page' the same way mmu.c does. Then let's move ZERO_PAGE()
>> definition to the top of pgtable.h to be in common between mmu.c and
>> nommu.c.
>>
>> Signed-off-by: Giulio Benetti <giulio.benetti@benettiengineering.com>
> 
> Maybe mention commit dc068f462179 ("m68knommu: set ZERO_PAGE() to the
> allocated zeroed page") for the commit that fixed this first,
> as well as the previous discussion at
> https://lore.kernel.org/linux-m68k/2a462b23-5b8e-bbf4-ec7d-778434a3b9d7@google.com/T/#m1266ceb63ad140743174d6b3070364d3c9a5179b

Thanks for poiting, I was unaware of this. I'll point it for sure.

> It looks like we dropped the ball on this when it came up last.
> I'm also not sure when we started requiring this, any idea?

No to be honest. But in my case I've met ZERO_PAGE() calling in sdhci
driver. And as stated on the ML link above:
```
But I wonder if it's safe for noMMU architectures to go on without a
working ZERO_PAGE(0).  It has uses scattered throughout the tree, in
drivers, fs, crypto and more, and it's not at all obvious (to me) that
they all depend on CONFIG_MMU.
```
And I've found this driver that requires it and probably is not the last
since imxrt support is not complete.

> I can see that microblaze-nommu used BUG() in ZERO_PAGE(), so at
> whenever microblaze last worked, we clearly did not call it.

This probably means that microblaze-nommu doesn't use drivers or other
subsystems that require ZERO_PAGE().

> 
>> +#ifndef __ASSEMBLY__
>> +/*
>> + * ZERO_PAGE is a global shared page that is always zero: used
>> + * for zero-mapped memory areas etc..
>> + */
>> +extern struct page *empty_zero_page;
>> +#define ZERO_PAGE(vaddr)	(empty_zero_page)
>> +#endif
> 
> In addition to your fix, I see that arm is the only architecture
> that defines 'empty_zero_page' as a pointer to the page, when
> everything else just makes it a pointer to the data itself,
> or an 'extern char empty_zero_page[]' array, which we may want
> to change for consistency.

I was about doing it, but then I tought to move one piece at a time.
But yes, I can modify accordingly. That way we also avoid the early
allocation in pagint_init() since it would be a .bss array.

> There are three references to empty_zero_page in architecture
> independent code, and while we don't seem to use any of them
> on Arm, they would clearly be wrong if we did:
> 
> drivers/acpi/scan.c:#define INVALID_ACPI_HANDLE ((acpi_handle)empty_zero_page)
> drivers/spi/spi-fsl-cpm.c:      mspi->dma_dummy_tx = dma_map_single(dev, empty_zero_page, PAGE_SIZE,
> include/linux/raid/pq.h:# define raid6_empty_zero_page empty_zero_page

For them I can send patches to substitute with PAGE_ZERO(0) correctly 
adapted.

What do you think?

Thanks for reviewing.

Best regards
-- 
Giulio Benetti
CEO/CTO@Benetti Engineering sas

  reply	other threads:[~2022-10-18 17:44 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-17 23:37 [PATCH] ARM: mm: fix no-MMU ZERO_PAGE() implementation Giulio Benetti
2022-10-18  7:03 ` Arnd Bergmann
2022-10-18 17:44   ` Giulio Benetti [this message]
2022-10-18 18:35     ` Arnd Bergmann
2022-10-18 22:32       ` Giulio Benetti
2022-10-19  7:00         ` Arnd Bergmann
2022-10-19 16:37           ` Giulio Benetti
2022-10-19  9:09   ` Russell King (Oracle)
2022-10-19  9:32     ` Arnd Bergmann
2022-10-19 17:07     ` Giulio Benetti

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=972a3be7-4522-b4f0-adfa-6b42be56c52f@benettiengineering.com \
    --to=giulio.benetti@benettiengineering.com \
    --cc=akpm@linux-foundation.org \
    --cc=anshuman.khandual@arm.com \
    --cc=arnd@arndb.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=rmk+kernel@armlinux.org.uk \
    --cc=wangkefeng.wang@huawei.com \
    --cc=will@kernel.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).