Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Will Deacon <will@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Sasha Levin <sashal@kernel.org>,
	"kernelci.org bot" <bot@kernelci.org>,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	Kevin Hilman <khilman@baylibre.com>,
	Will Deacon <will.deacon@arm.com>,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH AUTOSEL 4.19 031/219] arm64: preempt: Fix big-endian when checking preempt count in assembly
Date: Mon, 16 Dec 2019 09:45:24 +0000	[thread overview]
Message-ID: <20191216094523.GA9938@willie-the-truck> (raw)
In-Reply-To: <20191214021403.GA1357@home.goodmis.org>

On Fri, Dec 13, 2019 at 09:14:03PM -0500, Steven Rostedt wrote:
> On Fri, Nov 22, 2019 at 12:46:03AM -0500, Sasha Levin wrote:
> > From: Will Deacon <will.deacon@arm.com>
> > 
> > [ Upstream commit 7faa313f05cad184e8b17750f0cbe5216ac6debb ]
> > 
> > Commit 396244692232 ("arm64: preempt: Provide our own implementation of
> > asm/preempt.h") extended the preempt count field in struct thread_info
> > to 64 bits, so that it consists of a 32-bit count plus a 32-bit flag
> > indicating whether or not the current task needs rescheduling.
> > 
> > Whilst the asm-offsets definition of TSK_TI_PREEMPT was updated to point
> > to this new field, the assembly usage was left untouched meaning that a
> > 32-bit load from TSK_TI_PREEMPT on a big-endian machine actually returns
> > the reschedule flag instead of the count.
> > 
> > Whilst we could fix this by pointing TSK_TI_PREEMPT at the count field,
> > we're actually better off reworking the two assembly users so that they
> > operate on the whole 64-bit value in favour of inspecting the thread
> > flags separately in order to determine whether a reschedule is needed.
> > 
> > Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> > Reported-by: "kernelci.org bot" <bot@kernelci.org>
> > Tested-by: Kevin Hilman <khilman@baylibre.com>
> > Signed-off-by: Will Deacon <will.deacon@arm.com>
> > Signed-off-by: Sasha Levin <sashal@kernel.org>
> > ---
> >  arch/arm64/include/asm/assembler.h | 8 +++-----
> >  arch/arm64/kernel/entry.S          | 6 ++----
> >  2 files changed, 5 insertions(+), 9 deletions(-)
> > 
> > diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h
> > index 5a97ac8531682..0c100506a29aa 100644
> > --- a/arch/arm64/include/asm/assembler.h
> > +++ b/arch/arm64/include/asm/assembler.h
> > @@ -683,11 +683,9 @@ USER(\label, ic	ivau, \tmp2)			// invalidate I line PoU
> >  	.macro		if_will_cond_yield_neon
> >  #ifdef CONFIG_PREEMPT
> >  	get_thread_info	x0
> > -	ldr		w1, [x0, #TSK_TI_PREEMPT]
> > -	ldr		x0, [x0, #TSK_TI_FLAGS]
> > -	cmp		w1, #PREEMPT_DISABLE_OFFSET
> > -	csel		x0, x0, xzr, eq
> > -	tbnz		x0, #TIF_NEED_RESCHED, .Lyield_\@	// needs rescheduling?
> > +	ldr		x0, [x0, #TSK_TI_PREEMPT]
> > +	sub		x0, x0, #PREEMPT_DISABLE_OFFSET
> > +	cbz		x0, .Lyield_\@
> >  	/* fall through to endif_yield_neon */
> >  	.subsection	1
> >  .Lyield_\@ :
> > diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
> > index 5f800384cb9a8..bb68323530458 100644
> > --- a/arch/arm64/kernel/entry.S
> > +++ b/arch/arm64/kernel/entry.S
> > @@ -622,10 +622,8 @@ el1_irq:
> >  	irq_handler
> >  
> >  #ifdef CONFIG_PREEMPT
> > -	ldr	w24, [tsk, #TSK_TI_PREEMPT]	// get preempt count
> > -	cbnz	w24, 1f				// preempt count != 0
> > -	ldr	x0, [tsk, #TSK_TI_FLAGS]	// get flags
> > -	tbz	x0, #TIF_NEED_RESCHED, 1f	// needs rescheduling?
> > +	ldr	x24, [tsk, #TSK_TI_PREEMPT]	// get preempt count
> > +	cbnz	x24, 1f				// preempt count != 0
> >  	bl	el1_preempt
> 
> While updating 4.19-rt, I stumbled on this change to arm64 backport. And was
> confused by it, but looking deeper, this is something that breaks without
> having 396244692232f ("arm64: preempt: Provide our own implementation of
> asm/preempt.h").
> 
> That commit inverts the TIF_NEED_RESCHED meaning where set means we don't need
> to resched, and clear means we need to resched. This way we can combine the
> preempt count with the need resched flag test as they share the same 64bit
> word. A 0 means we need to preempt (as NEED_RESCHED being zero means we need
> to resched, and this also means preempt_count is zero). If the
> TIF_NEED_RESCHED bit is set, that means we don't need to resched, and if
> preempt count is something other than zero, we don't need to resched, and
> since those two are together by commit 396244692232f, we can just test
> #TSK_TI_PREEMPT. But because that commit does not exist in 4.19, we can't
> remove the TIF_NEED_RESCHED check, that this backport does, and then breaks
> the kernel!

Yup, without 396244692232 this commit makes no sense. That's why I didn't CC
stable or add a Fixes tag :(

Will

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2019-12-16  9:45 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-22  5:45 [PATCH AUTOSEL 4.19 008/219] ARM: dts: imx51: Fix memory node duplication Sasha Levin
2019-11-22  5:45 ` [PATCH AUTOSEL 4.19 009/219] ARM: dts: imx53: " Sasha Levin
2019-11-22  5:45 ` [PATCH AUTOSEL 4.19 010/219] ARM: dts: imx31: " Sasha Levin
2019-11-22  5:45 ` [PATCH AUTOSEL 4.19 011/219] ARM: dts: imx35: " Sasha Levin
2019-11-22  5:45 ` [PATCH AUTOSEL 4.19 012/219] ARM: dts: imx7: " Sasha Levin
2019-11-22  5:45 ` [PATCH AUTOSEL 4.19 013/219] ARM: dts: imx6ul: " Sasha Levin
2019-11-22  5:45 ` [PATCH AUTOSEL 4.19 014/219] ARM: dts: imx6sx: " Sasha Levin
2019-11-22  5:45 ` [PATCH AUTOSEL 4.19 015/219] ARM: dts: imx6sl: " Sasha Levin
2019-11-22  5:45 ` [PATCH AUTOSEL 4.19 016/219] ARM: dts: imx50: " Sasha Levin
2019-11-22  5:45 ` [PATCH AUTOSEL 4.19 017/219] ARM: dts: imx23: " Sasha Levin
2019-11-22  5:45 ` [PATCH AUTOSEL 4.19 018/219] ARM: dts: imx1: " Sasha Levin
2019-11-22  5:45 ` [PATCH AUTOSEL 4.19 019/219] ARM: dts: imx27: " Sasha Levin
2019-11-22  5:45 ` [PATCH AUTOSEL 4.19 020/219] ARM: dts: imx25: " Sasha Levin
2019-11-22  5:45 ` [PATCH AUTOSEL 4.19 021/219] ARM: dts: imx53-voipac-dmm-668: " Sasha Levin
2019-11-22  5:45 ` [PATCH AUTOSEL 4.19 025/219] arm64: mm: Prevent mismatched 52-bit VA support Sasha Levin
2019-11-22  5:45 ` [PATCH AUTOSEL 4.19 026/219] arm64: smp: Handle errors reported by the firmware Sasha Levin
2019-11-22  5:46 ` [PATCH AUTOSEL 4.19 029/219] ARM: OMAP1: fix USB configuration for device-only setups Sasha Levin
2019-11-22  5:46 ` [PATCH AUTOSEL 4.19 031/219] arm64: preempt: Fix big-endian when checking preempt count in assembly Sasha Levin
2019-12-14  2:14   ` Steven Rostedt
2019-12-16  9:45     ` Will Deacon [this message]
2019-12-18 15:38       ` Steven Rostedt
2019-12-18 20:11         ` Greg Kroah-Hartman
2019-12-18 15:40       ` Steven Rostedt
2019-12-18 16:03         ` Will Deacon
2019-11-22  5:46 ` [PATCH AUTOSEL 4.19 035/219] ARM: ks8695: fix section mismatch warning Sasha Levin
2019-11-22  5:46 ` [PATCH AUTOSEL 4.19 068/219] mmc: meson-gx: make sure the descriptor is stopped on errors Sasha Levin
2019-11-22  5:46 ` [PATCH AUTOSEL 4.19 069/219] mtd: rawnand: sunxi: Write pageprog related opcodes to WCMD_SET Sasha Levin
2019-11-22  5:47 ` [PATCH AUTOSEL 4.19 136/219] MIPS: BCM63XX: fix switch core reset on BCM6368 Sasha Levin
2019-11-22  5:47 ` [PATCH AUTOSEL 4.19 137/219] pwm: clps711x: Fix period calculation Sasha Levin
2019-11-22  5:47 ` [PATCH AUTOSEL 4.19 146/219] net: stmicro: fix a missing check of clk_prepare Sasha Levin
2019-11-22  5:48 ` [PATCH AUTOSEL 4.19 162/219] firmware: arm_sdei: fix wrong of_node_put() in init function Sasha Levin
2019-11-22  5:48 ` [PATCH AUTOSEL 4.19 163/219] firmware: arm_sdei: Fix DT platform device creation Sasha Levin

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=20191216094523.GA9938@willie-the-truck \
    --to=will@kernel.org \
    --cc=ard.biesheuvel@linaro.org \
    --cc=bot@kernelci.org \
    --cc=khilman@baylibre.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.org \
    --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