linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: marc.zyngier@arm.com (Marc Zyngier)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v3 5/7] ARM: KVM: rework HYP page table freeing
Date: Mon, 15 Apr 2013 10:00:35 +0200	[thread overview]
Message-ID: <89815b00ef8a11e6fc7bc03497b9668a@localhost> (raw)
In-Reply-To: <CAEDV+gJAUOsi3yjwp3hmBPbLkaL_0PaUNGFLLZN0nOzya7BA-A@mail.gmail.com>

On Sun, 14 Apr 2013 23:51:55 -0700, Christoffer Dall
<cdall@cs.columbia.edu> wrote:
> On Fri, Apr 12, 2013 at 8:18 AM, Marc Zyngier <marc.zyngier@arm.com>
wrote:
>> There is no point in freeing HYP page tables differently from Stage-2.
>> They now have the same requirements, and should be dealt with the same
>> way.
>>
>> Promote unmap_stage2_range to be The One True Way, and get rid of a
>> number
>> of nasty bugs in the process (goo thing we never actually called
>> free_hyp_pmds
> 
> could you remind me, did you already point out these nasty bugs
> somewhere or did we discuss them in an older thread?

No, I decided it wasn't worth the hassle when I spotted them (specially as
we're moving away from section mapped idmap)... But for the record:

<quote>
static void free_hyp_pgd_entry(pgd_t *pgdp, unsigned long addr)
{
	pgd_t *pgd;
	pud_t *pud;
	pmd_t *pmd;

	pgd = pgdp + pgd_index(addr);
	pud = pud_offset(pgd, addr);

	if (pud_none(*pud))
		return;
	BUG_ON(pud_bad(*pud));

	pmd = pmd_offset(pud, addr);
	free_ptes(pmd, addr);
	pmd_free(NULL, pmd);
        ^^^^^^^^^^^^^^^^^^^^<-- BUG_ON(pmd not page aligned)
	pud_clear(pud);
}
</quote>

Now, if you decide to fix the above by forcing the page alignment:

<quote>
static void free_ptes(pmd_t *pmd, unsigned long addr)
{
	pte_t *pte;
	unsigned int i;

	for (i = 0; i < PTRS_PER_PMD; i++, addr += PMD_SIZE) {
             ^^^^^^^^^^^^^<-- start freeing memory outside of the
(unaligned) pmd...
		if (!pmd_none(*pmd) && pmd_table(*pmd)) {
			pte = pte_offset_kernel(pmd, addr);
			pte_free_kernel(NULL, pte);
		}
		pmd++;
	}
}
</quote>

Once you've fixed that as well, you end up noticing that if you have PTEs
pointed to by the same PMD, you need to introduce some refcounting if you
need to free one PTE and not the others.

At this point, I had enough, and decided to reuse what we already had
instead of reinventing the wheel.

> nit: s/goo/good/
> 
>> before...).

Will fix.

Thanks,

        M.
-- 
Fast, cheap, reliable. Pick two.

  reply	other threads:[~2013-04-15  8:00 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-12 15:18 [PATCH v3 0/7] ARM: KVM: Revamping the HYP init code for fun and profit Marc Zyngier
2013-04-12 15:18 ` [PATCH v3 1/7] ARM: KVM: simplify HYP mapping population Marc Zyngier
2013-04-12 15:18 ` [PATCH v3 2/7] ARM: KVM: fix HYP mapping limitations around zero Marc Zyngier
2013-04-12 15:18 ` [PATCH v3 3/7] ARM: KVM: move to a KVM provided HYP idmap Marc Zyngier
2013-04-12 15:18 ` [PATCH v3 4/7] ARM: KVM: enforce maximum size for identity mapped code Marc Zyngier
2013-04-19 13:34   ` Russell King - ARM Linux
2013-04-19 14:07     ` Marc Zyngier
2013-04-12 15:18 ` [PATCH v3 5/7] ARM: KVM: rework HYP page table freeing Marc Zyngier
2013-04-15  6:51   ` Christoffer Dall
2013-04-15  8:00     ` Marc Zyngier [this message]
     [not found]       ` <CAEDV+gJtHT7vyNLK1gNbNEzks0=ojZ7RoLGu3vW0CqVZreUnVg@mail.gmail.com>
2013-04-18  7:13         ` Marc Zyngier
2013-04-18 15:37           ` Christoffer Dall
2013-04-12 15:18 ` [PATCH v3 6/7] ARM: KVM: switch to a dual-step HYP init code Marc Zyngier
2013-04-19 13:36   ` Russell King - ARM Linux
2013-04-19 14:07     ` Marc Zyngier
2013-04-19 16:14       ` Christoffer Dall
2013-04-12 15:18 ` [PATCH v3 7/7] ARM: KVM: perform HYP initilization for hotplugged CPUs Marc Zyngier

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=89815b00ef8a11e6fc7bc03497b9668a@localhost \
    --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).