linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: kernel test robot <oliver.sang@intel.com>
Cc: oe-lkp@lists.linux.dev, lkp@intel.com,
	linux-kernel@vger.kernel.org, x86@kernel.org,
	Max Ramanouski <max8rr8@gmail.com>,
	Alistair Popple <apopple@nvidia.com>,
	Dan Williams <dan.j.williams@intel.com>,
	Kees Cook <kees@kernel.org>,
	linux-mm@kvack.org, oliver.sang@intel.com
Subject: Re: [tip:x86/urgent] [x86/kaslr]  dfb3911c36: kernel_BUG_at_arch/x86/mm/physaddr.c
Date: Tue, 20 Aug 2024 13:57:35 +0200	[thread overview]
Message-ID: <877ccbl840.ffs@tglx> (raw)
In-Reply-To: <202408201529.498d4d4d-lkp@intel.com>

On Tue, Aug 20 2024 at 15:16, kernel test robot wrote:
> commit: dfb3911c3692e45b027f13c7dca3230921533953 ("x86/kaslr: Expose and use the end of the physical memory address space")
>
> [    0.010309][    T0] ------------[ cut here ]------------
> [    0.011020][    T0] kernel BUG at arch/x86/mm/physaddr.c:28!
> [ 0.026951][ T0] ? __phys_addr (ld-temp.o:?) 
> [ 0.027298][ T0] ? kernel_randomize_memory (ld-temp.o:?)

Sigh. I'm a moron. This obviously needs the fix below.

The end of the region is start + size - 1. So there are two bugs:

    1) It needs to be done before jumping forward to the next PUD.

    2) If the direct map covers the full address space, then
       __pa(vaddr) is wrong because that's the next PUD already.

I'll amend the commit and force push it. Thankfully I did not have time
on sunday to send it to Linus :)

Thanks,

        tglx
---
diff --git a/arch/x86/mm/kaslr.c b/arch/x86/mm/kaslr.c
index 0f2a3a4a1078..230f1dee4f09 100644
--- a/arch/x86/mm/kaslr.c
+++ b/arch/x86/mm/kaslr.c
@@ -141,19 +141,19 @@ void __init kernel_randomize_memory(void)
 		vaddr += entropy;
 		*kaslr_regions[i].base = vaddr;
 
-		/*
-		 * Jump the region and add a minimum padding based on
-		 * randomization alignment.
-		 */
+		/* Calculate the end of the region */
 		vaddr += get_padding(&kaslr_regions[i]);
-		vaddr = round_up(vaddr + 1, PUD_SIZE);
-
 		/*
 		 * KASLR trims the maximum possible size of the
 		 * direct-map. Update the physmem_end boundary.
+		 * No rounding required as the region starts
+		 * PUD aligned and size is in units of TB.
 		 */
 		if (kaslr_regions[i].end)
-			*kaslr_regions[i].end = __pa(vaddr) - 1;
+			*kaslr_regions[i].end = __pa_nodebug(vaddr - 1);
+
+		/* Add a minimum padding based on randomization alignment. */
+		vaddr = round_up(vaddr + 1, PUD_SIZE);
 		remain_entropy -= entropy;
 	}
 }




  reply	other threads:[~2024-08-20 11:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-20  7:16 kernel test robot
2024-08-20 11:57 ` Thomas Gleixner [this message]
2024-08-20 14:37   ` Thomas Gleixner

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=877ccbl840.ffs@tglx \
    --to=tglx@linutronix.de \
    --cc=apopple@nvidia.com \
    --cc=dan.j.williams@intel.com \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lkp@intel.com \
    --cc=max8rr8@gmail.com \
    --cc=oe-lkp@lists.linux.dev \
    --cc=oliver.sang@intel.com \
    --cc=x86@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