All of lore.kernel.org
 help / color / mirror / Atom feed
From: mark.rutland@arm.com (Mark Rutland)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCHv4 05/10] arm64: Use __pa_symbol for kernel symbols
Date: Tue, 6 Dec 2016 16:08:00 +0000	[thread overview]
Message-ID: <20161206160800.GD24177@leverpostej> (raw)
In-Reply-To: <584011CB.3050505@arm.com>

On Thu, Dec 01, 2016 at 12:04:27PM +0000, James Morse wrote:
> On 29/11/16 18:55, Laura Abbott wrote:
> > diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.c
> > index d55a7b0..4f0c77d 100644
> > --- a/arch/arm64/kernel/hibernate.c
> > +++ b/arch/arm64/kernel/hibernate.c
> > @@ -484,7 +481,7 @@ int swsusp_arch_resume(void)
> >  	 * Since we only copied the linear map, we need to find restore_pblist's
> >  	 * linear map address.
> >  	 */
> > -	lm_restore_pblist = LMADDR(restore_pblist);
> > +	lm_restore_pblist = lm_alias(restore_pblist);
> >  
> >  	/*
> >  	 * We need a zero page that is zero before & after resume in order to
> 
> This change causes resume from hibernate to panic in:
> > VIRTUAL_BUG_ON(x < (unsigned long) KERNEL_START ||
> > 		x > (unsigned long) KERNEL_END);
> 
> It looks like kaslr's relocation code has already fixed restore_pblist, so your
> debug virtual check catches this doing the wrong thing. My bug.
> 
> readelf -s vmlinux | grep ...
> > 103495: ffff000008080000     0 NOTYPE  GLOBAL DEFAULT    1 _text
> >  92104: ffff000008e43860     8 OBJECT  GLOBAL DEFAULT   24 restore_pblist
> > 105442: ffff000008e85000     0 NOTYPE  GLOBAL DEFAULT   24 _end
> 
> But restore_pblist == 0xffff800971b7f998 when passed to __phys_addr_symbol().

I think KASLR's a red herring; it shouldn't change the distance between
the restore_pblist symbol and {_text,_end}.

Above, ffff000008e43860 is the location of the pointer in the kernel
image (i.e. it's &restore_pblist). 0xffff800971b7f998 is the pointer
that was assigned to restore_pblist. For KASLR, the low bits (at least
up to a page boundary) shouldn't change across relocation.

Assuming it's only ever assigned a dynamic allocation, which should fall
in the linear map, the LMADDR() dance doesn't appear to be necessary.

> This fixes the problem:
> ----------------%<----------------
> diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.c
> index 4f0c77d2ff7a..8bed26a2d558 100644
> --- a/arch/arm64/kernel/hibernate.c
> +++ b/arch/arm64/kernel/hibernate.c
> @@ -457,7 +457,6 @@ int swsusp_arch_resume(void)
>         void *zero_page;
>         size_t exit_size;
>         pgd_t *tmp_pg_dir;
> -       void *lm_restore_pblist;
>         phys_addr_t phys_hibernate_exit;
>         void __noreturn (*hibernate_exit)(phys_addr_t, phys_addr_t, void *,
>                                           void *, phys_addr_t, phys_addr_t);
> @@ -478,12 +477,6 @@ int swsusp_arch_resume(void)
>                 goto out;
> 
>         /*
> -        * Since we only copied the linear map, we need to find restore_pblist's
> -        * linear map address.
> -        */
> -       lm_restore_pblist = lm_alias(restore_pblist);
> -
> -       /*
>          * We need a zero page that is zero before & after resume in order to
>          * to break before make on the ttbr1 page tables.
>          */
> @@ -534,7 +527,7 @@ int swsusp_arch_resume(void)
>         }
> 
>         hibernate_exit(virt_to_phys(tmp_pg_dir), resume_hdr.ttbr1_el1,
> -                      resume_hdr.reenter_kernel, lm_restore_pblist,
> +                      resume_hdr.reenter_kernel, restore_pblist,
>                        resume_hdr.__hyp_stub_vectors, virt_to_phys(zero_page));
> 
>  out:
> ----------------%<----------------

Folding that in (or having it as a preparatory cleanup patch) makes
sense to me. AFAICT the logic was valid (albeit confused) until now, so
it's not strictly a fix.

Thanks,
Mark.

WARNING: multiple messages have this Message-ID (diff)
From: Mark Rutland <mark.rutland@arm.com>
To: James Morse <james.morse@arm.com>
Cc: Laura Abbott <labbott@redhat.com>,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	Will Deacon <will.deacon@arm.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Christoffer Dall <christoffer.dall@linaro.org>,
	Marc Zyngier <marc.zyngier@arm.com>,
	Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	x86@kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	Joonsoo Kim <iamjoonsoo.kim@lge.com>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCHv4 05/10] arm64: Use __pa_symbol for kernel symbols
Date: Tue, 6 Dec 2016 16:08:00 +0000	[thread overview]
Message-ID: <20161206160800.GD24177@leverpostej> (raw)
In-Reply-To: <584011CB.3050505@arm.com>

On Thu, Dec 01, 2016 at 12:04:27PM +0000, James Morse wrote:
> On 29/11/16 18:55, Laura Abbott wrote:
> > diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.c
> > index d55a7b0..4f0c77d 100644
> > --- a/arch/arm64/kernel/hibernate.c
> > +++ b/arch/arm64/kernel/hibernate.c
> > @@ -484,7 +481,7 @@ int swsusp_arch_resume(void)
> >  	 * Since we only copied the linear map, we need to find restore_pblist's
> >  	 * linear map address.
> >  	 */
> > -	lm_restore_pblist = LMADDR(restore_pblist);
> > +	lm_restore_pblist = lm_alias(restore_pblist);
> >  
> >  	/*
> >  	 * We need a zero page that is zero before & after resume in order to
> 
> This change causes resume from hibernate to panic in:
> > VIRTUAL_BUG_ON(x < (unsigned long) KERNEL_START ||
> > 		x > (unsigned long) KERNEL_END);
> 
> It looks like kaslr's relocation code has already fixed restore_pblist, so your
> debug virtual check catches this doing the wrong thing. My bug.
> 
> readelf -s vmlinux | grep ...
> > 103495: ffff000008080000     0 NOTYPE  GLOBAL DEFAULT    1 _text
> >  92104: ffff000008e43860     8 OBJECT  GLOBAL DEFAULT   24 restore_pblist
> > 105442: ffff000008e85000     0 NOTYPE  GLOBAL DEFAULT   24 _end
> 
> But restore_pblist == 0xffff800971b7f998 when passed to __phys_addr_symbol().

I think KASLR's a red herring; it shouldn't change the distance between
the restore_pblist symbol and {_text,_end}.

Above, ffff000008e43860 is the location of the pointer in the kernel
image (i.e. it's &restore_pblist). 0xffff800971b7f998 is the pointer
that was assigned to restore_pblist. For KASLR, the low bits (at least
up to a page boundary) shouldn't change across relocation.

Assuming it's only ever assigned a dynamic allocation, which should fall
in the linear map, the LMADDR() dance doesn't appear to be necessary.

> This fixes the problem:
> ----------------%<----------------
> diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.c
> index 4f0c77d2ff7a..8bed26a2d558 100644
> --- a/arch/arm64/kernel/hibernate.c
> +++ b/arch/arm64/kernel/hibernate.c
> @@ -457,7 +457,6 @@ int swsusp_arch_resume(void)
>         void *zero_page;
>         size_t exit_size;
>         pgd_t *tmp_pg_dir;
> -       void *lm_restore_pblist;
>         phys_addr_t phys_hibernate_exit;
>         void __noreturn (*hibernate_exit)(phys_addr_t, phys_addr_t, void *,
>                                           void *, phys_addr_t, phys_addr_t);
> @@ -478,12 +477,6 @@ int swsusp_arch_resume(void)
>                 goto out;
> 
>         /*
> -        * Since we only copied the linear map, we need to find restore_pblist's
> -        * linear map address.
> -        */
> -       lm_restore_pblist = lm_alias(restore_pblist);
> -
> -       /*
>          * We need a zero page that is zero before & after resume in order to
>          * to break before make on the ttbr1 page tables.
>          */
> @@ -534,7 +527,7 @@ int swsusp_arch_resume(void)
>         }
> 
>         hibernate_exit(virt_to_phys(tmp_pg_dir), resume_hdr.ttbr1_el1,
> -                      resume_hdr.reenter_kernel, lm_restore_pblist,
> +                      resume_hdr.reenter_kernel, restore_pblist,
>                        resume_hdr.__hyp_stub_vectors, virt_to_phys(zero_page));
> 
>  out:
> ----------------%<----------------

Folding that in (or having it as a preparatory cleanup patch) makes
sense to me. AFAICT the logic was valid (albeit confused) until now, so
it's not strictly a fix.

Thanks,
Mark.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

WARNING: multiple messages have this Message-ID (diff)
From: Mark Rutland <mark.rutland@arm.com>
To: James Morse <james.morse@arm.com>
Cc: Laura Abbott <labbott@redhat.com>,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	Will Deacon <will.deacon@arm.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Christoffer Dall <christoffer.dall@linaro.org>,
	Marc Zyngier <marc.zyngier@arm.com>,
	Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	x86@kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	Joonsoo Kim <iamjoonsoo.kim@lge.com>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCHv4 05/10] arm64: Use __pa_symbol for kernel symbols
Date: Tue, 6 Dec 2016 16:08:00 +0000	[thread overview]
Message-ID: <20161206160800.GD24177@leverpostej> (raw)
In-Reply-To: <584011CB.3050505@arm.com>

On Thu, Dec 01, 2016 at 12:04:27PM +0000, James Morse wrote:
> On 29/11/16 18:55, Laura Abbott wrote:
> > diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.c
> > index d55a7b0..4f0c77d 100644
> > --- a/arch/arm64/kernel/hibernate.c
> > +++ b/arch/arm64/kernel/hibernate.c
> > @@ -484,7 +481,7 @@ int swsusp_arch_resume(void)
> >  	 * Since we only copied the linear map, we need to find restore_pblist's
> >  	 * linear map address.
> >  	 */
> > -	lm_restore_pblist = LMADDR(restore_pblist);
> > +	lm_restore_pblist = lm_alias(restore_pblist);
> >  
> >  	/*
> >  	 * We need a zero page that is zero before & after resume in order to
> 
> This change causes resume from hibernate to panic in:
> > VIRTUAL_BUG_ON(x < (unsigned long) KERNEL_START ||
> > 		x > (unsigned long) KERNEL_END);
> 
> It looks like kaslr's relocation code has already fixed restore_pblist, so your
> debug virtual check catches this doing the wrong thing. My bug.
> 
> readelf -s vmlinux | grep ...
> > 103495: ffff000008080000     0 NOTYPE  GLOBAL DEFAULT    1 _text
> >  92104: ffff000008e43860     8 OBJECT  GLOBAL DEFAULT   24 restore_pblist
> > 105442: ffff000008e85000     0 NOTYPE  GLOBAL DEFAULT   24 _end
> 
> But restore_pblist == 0xffff800971b7f998 when passed to __phys_addr_symbol().

I think KASLR's a red herring; it shouldn't change the distance between
the restore_pblist symbol and {_text,_end}.

Above, ffff000008e43860 is the location of the pointer in the kernel
image (i.e. it's &restore_pblist). 0xffff800971b7f998 is the pointer
that was assigned to restore_pblist. For KASLR, the low bits (at least
up to a page boundary) shouldn't change across relocation.

Assuming it's only ever assigned a dynamic allocation, which should fall
in the linear map, the LMADDR() dance doesn't appear to be necessary.

> This fixes the problem:
> ----------------%<----------------
> diff --git a/arch/arm64/kernel/hibernate.c b/arch/arm64/kernel/hibernate.c
> index 4f0c77d2ff7a..8bed26a2d558 100644
> --- a/arch/arm64/kernel/hibernate.c
> +++ b/arch/arm64/kernel/hibernate.c
> @@ -457,7 +457,6 @@ int swsusp_arch_resume(void)
>         void *zero_page;
>         size_t exit_size;
>         pgd_t *tmp_pg_dir;
> -       void *lm_restore_pblist;
>         phys_addr_t phys_hibernate_exit;
>         void __noreturn (*hibernate_exit)(phys_addr_t, phys_addr_t, void *,
>                                           void *, phys_addr_t, phys_addr_t);
> @@ -478,12 +477,6 @@ int swsusp_arch_resume(void)
>                 goto out;
> 
>         /*
> -        * Since we only copied the linear map, we need to find restore_pblist's
> -        * linear map address.
> -        */
> -       lm_restore_pblist = lm_alias(restore_pblist);
> -
> -       /*
>          * We need a zero page that is zero before & after resume in order to
>          * to break before make on the ttbr1 page tables.
>          */
> @@ -534,7 +527,7 @@ int swsusp_arch_resume(void)
>         }
> 
>         hibernate_exit(virt_to_phys(tmp_pg_dir), resume_hdr.ttbr1_el1,
> -                      resume_hdr.reenter_kernel, lm_restore_pblist,
> +                      resume_hdr.reenter_kernel, restore_pblist,
>                        resume_hdr.__hyp_stub_vectors, virt_to_phys(zero_page));
> 
>  out:
> ----------------%<----------------

Folding that in (or having it as a preparatory cleanup patch) makes
sense to me. AFAICT the logic was valid (albeit confused) until now, so
it's not strictly a fix.

Thanks,
Mark.

  reply	other threads:[~2016-12-06 16:08 UTC|newest]

Thread overview: 130+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-29 18:55 [PATCHv4 00/10] CONFIG_DEBUG_VIRTUAL for arm64 Laura Abbott
2016-11-29 18:55 ` Laura Abbott
2016-11-29 18:55 ` Laura Abbott
2016-11-29 18:55 ` Laura Abbott
2016-11-29 18:55 ` [PATCHv4 01/10] lib/Kconfig.debug: Add ARCH_HAS_DEBUG_VIRTUAL Laura Abbott
2016-11-29 18:55   ` Laura Abbott
2016-11-29 18:55   ` Laura Abbott
2016-11-29 18:55 ` [PATCHv4 02/10] mm/cma: Cleanup highmem check Laura Abbott
2016-11-29 18:55   ` Laura Abbott
2016-11-29 18:55   ` Laura Abbott
2016-11-29 18:55 ` [PATCHv4 03/10] arm64: Move some macros under #ifndef __ASSEMBLY__ Laura Abbott
2016-11-29 18:55   ` Laura Abbott
2016-11-29 18:55   ` Laura Abbott
2016-11-29 18:55 ` [PATCHv4 04/10] arm64: Add cast for virt_to_pfn Laura Abbott
2016-11-29 18:55   ` Laura Abbott
2016-11-29 18:55   ` Laura Abbott
2016-11-29 18:55 ` [PATCHv4 05/10] arm64: Use __pa_symbol for kernel symbols Laura Abbott
2016-11-29 18:55   ` Laura Abbott
2016-11-29 18:55   ` Laura Abbott
2016-11-30 17:17   ` Catalin Marinas
2016-11-30 17:17     ` Catalin Marinas
2016-11-30 17:17     ` Catalin Marinas
2016-12-01 12:04   ` James Morse
2016-12-01 12:04     ` James Morse
2016-12-01 12:04     ` James Morse
2016-12-06 16:08     ` Mark Rutland [this message]
2016-12-06 16:08       ` Mark Rutland
2016-12-06 16:08       ` Mark Rutland
2016-12-06  0:50   ` Florian Fainelli
2016-12-06  0:50     ` Florian Fainelli
2016-12-06  0:50     ` Florian Fainelli
2016-12-06 11:46     ` Catalin Marinas
2016-12-06 11:46       ` Catalin Marinas
2016-12-06 11:46       ` Catalin Marinas
2016-12-06 17:02   ` Mark Rutland
2016-12-06 17:02     ` Mark Rutland
2016-12-06 17:02     ` Mark Rutland
2016-12-06 19:12     ` Laura Abbott
2016-12-06 19:12       ` Laura Abbott
2016-12-06 19:12       ` Laura Abbott
2016-11-29 18:55 ` [PATCHv4 06/10] xen: Switch to using __pa_symbol Laura Abbott
2016-11-29 18:55 ` Laura Abbott
2016-11-29 18:55   ` Laura Abbott
2016-11-29 18:55   ` Laura Abbott
2016-11-29 22:26   ` Boris Ostrovsky
2016-11-29 22:26     ` Boris Ostrovsky
2016-11-29 22:26     ` Boris Ostrovsky
2016-11-29 22:42     ` Laura Abbott
2016-11-29 22:42       ` Laura Abbott
2016-11-29 22:42       ` Laura Abbott
2016-11-29 22:42     ` Laura Abbott
2016-11-29 22:26   ` Boris Ostrovsky
2016-11-29 18:55 ` [PATCHv4 07/10] kexec: Switch to __pa_symbol Laura Abbott
2016-11-29 18:55   ` Laura Abbott
2016-11-29 18:55   ` Laura Abbott
2016-11-29 18:55   ` Laura Abbott
2016-12-01  2:41   ` Dave Young
2016-12-01  2:41     ` Dave Young
2016-12-01  2:41     ` Dave Young
2016-12-01  2:41     ` Dave Young
2016-12-01  3:13     ` Eric W. Biederman
2016-12-01  3:13       ` Eric W. Biederman
2016-12-01  3:13       ` Eric W. Biederman
2016-12-01  3:13       ` Eric W. Biederman
2016-12-01  4:27       ` Dave Young
2016-12-01  4:27         ` Dave Young
2016-12-01  4:27         ` Dave Young
2016-12-01  4:27         ` Dave Young
2016-11-29 18:55 ` [PATCHv4 08/10] mm/kasan: Switch to using __pa_symbol and lm_alias Laura Abbott
2016-11-29 18:55   ` Laura Abbott
2016-11-29 18:55   ` Laura Abbott
2016-12-01 11:36   ` Andrey Ryabinin
2016-12-01 11:36     ` Andrey Ryabinin
2016-12-01 11:36     ` Andrey Ryabinin
2016-12-01 19:10     ` Laura Abbott
2016-12-01 19:10       ` Laura Abbott
2016-12-01 19:10       ` Laura Abbott
2016-12-06 17:25     ` Mark Rutland
2016-12-06 17:25       ` Mark Rutland
2016-12-06 17:25       ` Mark Rutland
2016-12-06 17:44   ` Mark Rutland
2016-12-06 17:44     ` Mark Rutland
2016-12-06 17:44     ` Mark Rutland
2016-12-06 19:18   ` Mark Rutland
2016-12-06 19:18     ` Mark Rutland
2016-12-06 19:18     ` Mark Rutland
2016-11-29 18:55 ` [PATCHv4 09/10] mm/usercopy: Switch to using lm_alias Laura Abbott
2016-11-29 18:55   ` Laura Abbott
2016-11-29 18:55   ` Laura Abbott
2016-11-29 19:39   ` Kees Cook
2016-11-29 19:39     ` Kees Cook
2016-11-29 19:39     ` Kees Cook
2016-12-06 18:18     ` Mark Rutland
2016-12-06 18:18       ` Mark Rutland
2016-12-06 18:18       ` Mark Rutland
2016-12-06 20:10       ` Kees Cook
2016-12-06 20:10         ` Kees Cook
2016-12-06 20:10         ` Kees Cook
2016-12-07 13:57         ` Mark Rutland
2016-12-07 13:57           ` Mark Rutland
2016-12-07 13:57           ` Mark Rutland
2016-12-06 18:20   ` Mark Rutland
2016-12-06 18:20     ` Mark Rutland
2016-12-06 18:20     ` Mark Rutland
2016-11-29 18:55 ` [PATCHv4 10/10] arm64: Add support for CONFIG_DEBUG_VIRTUAL Laura Abbott
2016-11-29 18:55   ` Laura Abbott
2016-11-29 18:55   ` Laura Abbott
2016-12-06 18:58   ` Mark Rutland
2016-12-06 18:58     ` Mark Rutland
2016-12-06 18:58     ` Mark Rutland
2016-12-06 19:53 ` [PATCH 0/3] ARM: " Florian Fainelli
2016-12-06 19:53   ` Florian Fainelli
2016-12-06 19:53   ` [PATCH 1/3] ARM: Define KERNEL_START and KERNEL_END Florian Fainelli
2016-12-06 19:53     ` Florian Fainelli
2016-12-06 22:43     ` Chris Brandt
2016-12-06 22:43       ` Chris Brandt
2016-12-06 22:47       ` Florian Fainelli
2016-12-06 22:47         ` Florian Fainelli
2016-12-07  6:11     ` kbuild test robot
2016-12-07  6:11       ` kbuild test robot
2016-12-06 19:53   ` [PATCH 2/3] ARM: Utilize __pa_symbol in lieu of __pa Florian Fainelli
2016-12-06 19:53     ` Florian Fainelli
2016-12-06 19:53   ` [PATCH 3/3] ARM: Add support for CONFIG_DEBUG_VIRTUAL Florian Fainelli
2016-12-06 19:53     ` Florian Fainelli
2016-12-06 20:42     ` Florian Fainelli
2016-12-06 20:42       ` Florian Fainelli
2016-12-07  2:00     ` Laura Abbott
2016-12-07  2:00       ` Laura Abbott
2016-12-07  2:24       ` Florian Fainelli
2016-12-07  2:24         ` Florian Fainelli

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=20161206160800.GD24177@leverpostej \
    --to=mark.rutland@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.