All of lore.kernel.org
 help / color / mirror / Atom feed
From: Will Deacon <will.deacon@arm.com>
To: Kees Cook <keescook@chromium.org>
Cc: Rabin Vincent <rabin@rab.in>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Laura Abbott <lauraa@codeaurora.org>,
	Rob Herring <robh@kernel.org>,
	Leif Lindholm <leif.lindholm@linaro.org>,
	"msalter@redhat.com" <msalter@redhat.com>,
	Liu hua <sdu.liu@huawei.com>,
	Nikolay Borisov <Nikolay.Borisov@arm.com>,
	Nicolas Pitre <nicolas.pitre@linaro.org>,
	Doug Anderson <dianders@google.com>,
	Jason Wessel <jason.wessel@windriver.com>,
	Catalin Marinas <Catalin.Marinas@arm.com>,
	Russell King - ARM Linux <linux@arm.linux.org.uk>,
	"linux-arm-kernel@lists.infradead.org" 
	<linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH v5 3/8] arm: fixmap: implement __set_fixmap()
Date: Thu, 11 Sep 2014 17:16:36 +0100	[thread overview]
Message-ID: <20140911161636.GU6158@arm.com> (raw)
In-Reply-To: <CAGXu5jJ_wLsKOuVgbS7cb+k-nyA=8XpaMYwov0o3hdFdyjaCmA@mail.gmail.com>

On Thu, Sep 11, 2014 at 05:05:14PM +0100, Kees Cook wrote:
> Actually, this doesn't make sense. If we're using
> local_flush_tlb_kernel_range() in set_fixmap, we must always run under
> stop_machine. The needs-broadcast case is solved by using
> local_flush_tlb_kernel_range(), and the TLB-miss-on-other-CPU case is
> solved by using stop_machine(). This is how the ftrace case work,
> though not via fixmap.
> 
> Since we need to flush the TLB on each fixmap change during
> patch_text(), if we want to make the local_flush_tlb_... optionally
> use flush_tlb_... to avoid calling stop_machine in the
> does't-need-broadcast case, then we'd be checking in multiple places,
> making this code overly complex for this rare operation. Is there a
> good reason to complicate this code to avoid stop_machine()?
> 
> I think we should just do this:
> 
> diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
> index 07314af47733..5038960e3c55 100644
> --- a/arch/arm/kernel/patch.c
> +++ b/arch/arm/kernel/patch.c
> @@ -60,16 +125,5 @@ void __kprobes patch_text(void *addr, unsigned int insn)
>                 .insn = insn,
>         };
> 
> -       if (cache_ops_need_broadcast()) {
> -               stop_machine(patch_text_stop_machine, &patch, cpu_online_mask);
> -       } else {
> -               bool straddles_word = IS_ENABLED(CONFIG_THUMB2_KERNEL)
> -                                     && __opcode_is_thumb32(insn)
> -                                     && ((uintptr_t)addr & 2);
> -
> -               if (straddles_word)
> -                       stop_machine(patch_text_stop_machine, &patch, NULL);
> -               else
> -                       __patch_text(addr, insn);
> -       }
> +       stop_machine(patch_text_stop_machine, &patch, NULL);

The reason not to use stop machine is that it's very expensive and the
architecture does provide some guarantees that mean it's not always
required...

... however, as I pointed out in a kprobes thread the other day, the code
you remove above is actually broken, so I wouldn't be against replacing it
all with stop_machine.

Is there any way to you can WARN_ON(!called_under_stop_machine) in
set_fixmap before doing the local TLBI?

Will

P.S. If you plan on doing an equivalent series for arm64, you should do it
before we have any broken CPUs, then you can use TLBI without worry ;)

WARNING: multiple messages have this Message-ID (diff)
From: will.deacon@arm.com (Will Deacon)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v5 3/8] arm: fixmap: implement __set_fixmap()
Date: Thu, 11 Sep 2014 17:16:36 +0100	[thread overview]
Message-ID: <20140911161636.GU6158@arm.com> (raw)
In-Reply-To: <CAGXu5jJ_wLsKOuVgbS7cb+k-nyA=8XpaMYwov0o3hdFdyjaCmA@mail.gmail.com>

On Thu, Sep 11, 2014 at 05:05:14PM +0100, Kees Cook wrote:
> Actually, this doesn't make sense. If we're using
> local_flush_tlb_kernel_range() in set_fixmap, we must always run under
> stop_machine. The needs-broadcast case is solved by using
> local_flush_tlb_kernel_range(), and the TLB-miss-on-other-CPU case is
> solved by using stop_machine(). This is how the ftrace case work,
> though not via fixmap.
> 
> Since we need to flush the TLB on each fixmap change during
> patch_text(), if we want to make the local_flush_tlb_... optionally
> use flush_tlb_... to avoid calling stop_machine in the
> does't-need-broadcast case, then we'd be checking in multiple places,
> making this code overly complex for this rare operation. Is there a
> good reason to complicate this code to avoid stop_machine()?
> 
> I think we should just do this:
> 
> diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
> index 07314af47733..5038960e3c55 100644
> --- a/arch/arm/kernel/patch.c
> +++ b/arch/arm/kernel/patch.c
> @@ -60,16 +125,5 @@ void __kprobes patch_text(void *addr, unsigned int insn)
>                 .insn = insn,
>         };
> 
> -       if (cache_ops_need_broadcast()) {
> -               stop_machine(patch_text_stop_machine, &patch, cpu_online_mask);
> -       } else {
> -               bool straddles_word = IS_ENABLED(CONFIG_THUMB2_KERNEL)
> -                                     && __opcode_is_thumb32(insn)
> -                                     && ((uintptr_t)addr & 2);
> -
> -               if (straddles_word)
> -                       stop_machine(patch_text_stop_machine, &patch, NULL);
> -               else
> -                       __patch_text(addr, insn);
> -       }
> +       stop_machine(patch_text_stop_machine, &patch, NULL);

The reason not to use stop machine is that it's very expensive and the
architecture does provide some guarantees that mean it's not always
required...

... however, as I pointed out in a kprobes thread the other day, the code
you remove above is actually broken, so I wouldn't be against replacing it
all with stop_machine.

Is there any way to you can WARN_ON(!called_under_stop_machine) in
set_fixmap before doing the local TLBI?

Will

P.S. If you plan on doing an equivalent series for arm64, you should do it
before we have any broken CPUs, then you can use TLBI without worry ;)

  reply	other threads:[~2014-09-11 16:16 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-03 21:57 [PATCH v5 0/8] arm: support CONFIG_RODATA Kees Cook
2014-09-03 21:57 ` Kees Cook
2014-09-03 21:57 ` [PATCH v5 1/8] arm: use generic fixmap.h Kees Cook
2014-09-03 21:57   ` Kees Cook
2014-09-03 21:57 ` [PATCH v5 2/8] ARM: expand fixmap region to 3MB Kees Cook
2014-09-03 21:57   ` Kees Cook
2014-09-03 21:57 ` [PATCH v5 3/8] arm: fixmap: implement __set_fixmap() Kees Cook
2014-09-03 21:57   ` Kees Cook
2014-09-04 17:03   ` Will Deacon
2014-09-04 17:03     ` Will Deacon
2014-09-04 17:23     ` Kees Cook
2014-09-04 17:23       ` Kees Cook
2014-09-04 17:27       ` Will Deacon
2014-09-04 17:27         ` Will Deacon
2014-09-05 19:41         ` Kees Cook
2014-09-05 19:41           ` Kees Cook
2014-09-08 10:39           ` Will Deacon
2014-09-08 10:39             ` Will Deacon
2014-09-08 18:38             ` Kees Cook
2014-09-08 18:38               ` Kees Cook
2014-09-08 19:16         ` Kees Cook
2014-09-08 19:16           ` Kees Cook
2014-09-08 21:55           ` Rabin Vincent
2014-09-08 21:55             ` Rabin Vincent
2014-09-08 22:40             ` Kees Cook
2014-09-08 22:40               ` Kees Cook
2014-09-09 12:38               ` Will Deacon
2014-09-09 12:38                 ` Will Deacon
2014-09-09 14:33                 ` Kees Cook
2014-09-09 14:33                   ` Kees Cook
2014-09-10 17:51                   ` Will Deacon
2014-09-10 17:51                     ` Will Deacon
2014-09-11 15:27                     ` Kees Cook
2014-09-11 15:27                       ` Kees Cook
2014-09-11 16:05                       ` Kees Cook
2014-09-11 16:05                         ` Kees Cook
2014-09-11 16:16                         ` Will Deacon [this message]
2014-09-11 16:16                           ` Will Deacon
2014-09-11 16:27                           ` Kees Cook
2014-09-11 16:27                             ` Kees Cook
2014-09-03 21:57 ` [PATCH v5 4/8] arm: use fixmap for text patching when text is RO Kees Cook
2014-09-03 21:57   ` Kees Cook
2014-09-03 21:57 ` [PATCH v5 5/8] ARM: kexec: Make .text R/W in machine_kexec Kees Cook
2014-09-03 21:57   ` Kees Cook
2014-09-03 21:57 ` [PATCH v5 6/8] arm: kgdb: Handle read-only text / modules Kees Cook
2014-09-03 21:57   ` Kees Cook
2014-09-03 21:57 ` [PATCH v5 7/8] ARM: mm: allow non-text sections to be non-executable Kees Cook
2014-09-03 21:57   ` Kees Cook
2014-09-03 21:57 ` [PATCH v5 8/8] ARM: mm: allow text and rodata sections to be read-only Kees Cook
2014-09-03 21:57   ` Kees Cook

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=20140911161636.GU6158@arm.com \
    --to=will.deacon@arm.com \
    --cc=Catalin.Marinas@arm.com \
    --cc=Nikolay.Borisov@arm.com \
    --cc=dianders@google.com \
    --cc=jason.wessel@windriver.com \
    --cc=keescook@chromium.org \
    --cc=lauraa@codeaurora.org \
    --cc=leif.lindholm@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=msalter@redhat.com \
    --cc=nicolas.pitre@linaro.org \
    --cc=rabin@rab.in \
    --cc=robh@kernel.org \
    --cc=sdu.liu@huawei.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 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.