linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Maciej Bielski <m.bielski@virtualopensystems.com>
To: Mark Rutland <mark.rutland@arm.com>
Cc: Andrea Reale <ar@linux.vnet.ibm.com>,
	linux-arm-kernel@lists.infradead.org, f.fainelli@gmail.com,
	scott.branden@broadcom.com, will.deacon@arm.com,
	linux-kernel@vger.kernel.org, qiuxishi@huawei.com,
	a.rigo@virtualopensystems.com
Subject: Re: [PATCH 3/5] Memory hotplug support for arm64 platform (v2)
Date: Mon, 24 Apr 2017 18:44:39 +0200	[thread overview]
Message-ID: <20170424164439.GA7477@tpad> (raw)
In-Reply-To: <20170411155843.GC32267@leverpostej>

[-- Attachment #1: /tmp/mutt_random_response_name --]
[-- Type: text/plain, Size: 3941 bytes --]

Hi Mark,

Thank you for having a look on the code and providing comments. Same to others
that replied to the whole patchset. To the large extent, first purpose of this code
was to just to implement the functionality and I am totally aware that it may
be suboptimal at some places and therefore your feedback is very much
appreciated.

More answers below.

On Tue, Apr 11, 2017 at 04:58:43PM +0100, Mark Rutland wrote:
> Hi,
> 
> On Tue, Apr 11, 2017 at 03:55:22PM +0100, Andrea Reale wrote:
> > From: Maciej Bielski <m.bielski@virtualopensystems.com>
> > 
> > This is a second and improved version of the patch previously released
> > in [3].
> > 
> > It builds on the work by Scott Branden [2] and, henceforth,
> > it needs to be applied on top of Scott's patches [2].
> > Comments are very welcome.
> > 
> > Changes from the original patchset and known issues:
> > 
> > - Compared to Scott's original patchset, this work adds the mapping of
> >   the new hotplugged pages into the kernel page tables. This is done by
> >   copying the old swapper_pg_dir over a new page, adding the new mappings,
> >   and then switching to the newly built pg_dir (see `hotplug_paging` in
> >   arch/arm64/mmu.c). There might be better ways to to this: suggestions
> >   are more than welcome.
> 
> For this reply, I'm just going to focus on the PGD replacement.
> 
> It's not clear to me if we need to swap the PGD, since everything we do
> here is strictly additive and non-conflicting, and it should be safe to
> add things to the swapper_pg_dir live.
> 
> However, assuming there's something I've missed, I have some comments
> below.
> 
> [...]

For one CPU it should work, I have quickly checked on QEMU. More concerns
regarding multiple CPUs below(*).

> 
> > +#ifdef CONFIG_MEMORY_HOTPLUG
> > +
> > +/*
> > + * hotplug_paging() is used by memory hotplug to build new page tables
> > + * for hot added memory.
> > + */
> > +void hotplug_paging(phys_addr_t start, phys_addr_t size)
> > +{
> > +
> > +	struct page *pg;
> > +	phys_addr_t pgd_phys = pgd_pgtable_alloc();
> > +	pgd_t *pgd = pgd_set_fixmap(pgd_phys);
> > +
> > +	memcpy(pgd, swapper_pg_dir, PAGE_SIZE);
> 
> s/PAGE_SIZE/PGD_SIZE/ (and below, too).
> 
> See commit 12f043ff2b28fa64 ("arm64: fix warning about swapper_pg_dir
> overflow").
> 

Noted, thanks.

> > +
> > +	__create_pgd_mapping(pgd, start, __phys_to_virt(start), size,
> > +		PAGE_KERNEL, pgd_pgtable_alloc, false);
> > +
> > +	cpu_replace_ttbr1(__va(pgd_phys));
> 
> Other CPUs may be online at this point, and cpu_replace_ttbr1() was only
> intended for UP operation. Other CPUs will still have swapper_pg_dir in
> their TTBR1_EL1 at this point in time...
> 
> > +	memcpy(swapper_pg_dir, pgd, PAGE_SIZE);
> 
> ... which this will alter, in an unsafe fashion.
> 
> The other CPUs are live, and might be altering swapper. e.g. one might
> be using the fixmap to alter code. We will need some stop_machine()-like
> machinery here to synchronise with other CPUs, ensuring that they don't
> have swapper_pg_dir live.

(*)
I am familiar with stop_machine(), for example it is done at later stage, when
pages are onlined (inside build_all_zonelists). But do you think that we should
check if swapper_pg_dir is under modification before stopping (and optionally
wait until this modification is finished)? Is there a mechanism to serialize
the write access to swapper_pg_dir?

> 
> Unfortunately, we can't change other to the temporary pgdir in a cross
> call, then fix things up, then do another cross call. If any exception
> is taken when we're in the temporary pgdir, __uaccess_ttbr0_disable will
> install junk into TTBR0, and we risk the usual set of pain junk TLBs
> entail.
> 
> We appear to have a latent bug at boot time along those lines, when
> setting up the page tables and initialising KASAN. I'll see about
> cleaning that up.

Great, thank you for any hints.

> 
> Thanks,
> Mark.

Best regards,

-- 
Maciej Bielski

  reply	other threads:[~2017-04-24 16:44 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-11 14:54 [PATCH 0/5] Memory hotplug support for arm64 - complete patchset Andrea Reale
2017-04-11 14:54 ` [PATCH 1/5] arm64: memory-hotplug: Add MEMORY_HOTPLUG, MEMORY_HOTREMOVE, MEMORY_PROBE Andrea Reale
2017-04-12  0:20   ` kbuild test robot
2017-04-11 14:54 ` [PATCH 2/5] arm64: defconfig: enable MEMORY_HOTPLUG config options Andrea Reale
2017-04-11 14:55 ` [PATCH 3/5] Memory hotplug support for arm64 platform (v2) Andrea Reale
2017-04-11 15:58   ` Mark Rutland
2017-04-24 16:44     ` Maciej Bielski [this message]
2017-04-24 17:35     ` Maciej Bielski
2017-04-11 14:55 ` [PATCH 4/5] Hot-remove implementation for arm64 Andrea Reale
2017-04-11 17:12   ` Mark Rutland
2017-04-14 14:01     ` Andrea Reale
2017-04-18 18:21       ` Mark Rutland
2017-04-18 18:48         ` Ard Biesheuvel
2017-04-19 15:53           ` Laura Abbott
2017-04-21 10:05             ` Andrea Reale
2017-04-24 23:59               ` Laura Abbott
2017-04-21 10:02         ` Andrea Reale
2017-04-11 14:56 ` [PATCH 5/5] Add "remove" probe driver for memory hot-remove Andrea Reale

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=20170424164439.GA7477@tpad \
    --to=m.bielski@virtualopensystems.com \
    --cc=a.rigo@virtualopensystems.com \
    --cc=ar@linux.vnet.ibm.com \
    --cc=f.fainelli@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=qiuxishi@huawei.com \
    --cc=scott.branden@broadcom.com \
    --cc=will.deacon@arm.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).