All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Zyngier <marc.zyngier@arm.com>
To: gaoyongliang <gaoyongliang@huawei.com>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"rmk+kernel@armlinux.org.uk" <rmk+kernel@armlinux.org.uk>,
	"linux@armlinux.org.uk" <linux@armlinux.org.uk>,
	"punitagrawal@gmail.com" <punitagrawal@gmail.com>,
	"rafael.j.wysocki@intel.com" <rafael.j.wysocki@intel.com>,
	"james.morse@arm.com" <james.morse@arm.com>,
	"linux-arm-kernel@lists.infradead.org" 
	<linux-arm-kernel@lists.infradead.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>,
	"Chenjie (K)" <chenjie6@huawei.com>,
	Nixiaoming <nixiaoming@huawei.com>,
	Zengweilin <zengweilin@huawei.com>,
	Shiwenlu <shiwenlu@huawei.com>
Subject: Re: [PATCH] arm: fix using smp_processor_id() in preemptible context
Date: Mon, 3 Jun 2019 16:30:45 +0100	[thread overview]
Message-ID: <a66ef5b9-19d0-2c02-8d1b-7e9c90067a76@arm.com> (raw)
In-Reply-To: <d003bd4642aa44e1a51b83cd0bf1f04e@huawei.com>

On 03/06/2019 15:44, gaoyongliang wrote:
> Hi Marc,
> 
> On 2019/6/3 18:17, Marc Zyngier wrote:
>> On 27/05/2019 10:39, Yongliang Gao wrote:
>>> harden_branch_predictor() call smp_processor_id() in preemptible
>>> context, this would cause a bug messages.
>>>
>>> The bug messages is as follows:
>>> BUG: using smp_processor_id() in preemptible [00000000] code: syz-executor0/17992
>>> caller is harden_branch_predictor arch/arm/include/asm/system_misc.h:27 [inline]
>>> caller is __do_user_fault+0x34/0x114 arch/arm/mm/fault.c:200
>>> CPU: 1 PID: 17992 Comm: syz-executor0 Tainted: G O 4.4.176 #1
>>> Hardware name: Hisilicon A9
>>> [<c0114ae4>] (unwind_backtrace) from [<c010e6fc>] (show_stack+0x18/0x1c)
>>> [<c010e6fc>] (show_stack) from [<c0379514>] (dump_stack+0xc8/0x118)
>>> [<c0379514>] (dump_stack) from [<c039b5a0>] (check_preemption_disabled+0xf4/0x138)
>>> [<c039b5a0>] (check_preemption_disabled) from [<c011abe4>] (__do_user_fault+0x34/0x114)
>>> [<c011abe4>] (__do_user_fault) from [<c053b0d0>] (do_page_fault+0x3b4/0x3d8)
>>> [<c053b0d0>] (do_page_fault) from [<c01013dc>] (do_DataAbort+0x58/0xf8)
>>> [<c01013dc>] (do_DataAbort) from [<c053a880>] (__dabt_usr+0x40/0x60)
>>>
>>> Reported-by: Jingwen Qiu <qiujingwen@huawei.com>
>>> Signed-off-by: Yongliang Gao <gaoyongliang@huawei.com>
>>> Cc: <stable@vger.kernel.org>
>>> ---
>>>  arch/arm/include/asm/system_misc.h | 3 ++-
>>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/arch/arm/include/asm/system_misc.h b/arch/arm/include/asm/system_misc.h
>>> index 66f6a3a..4a55cfb 100644
>>> --- a/arch/arm/include/asm/system_misc.h
>>> +++ b/arch/arm/include/asm/system_misc.h
>>> @@ -22,9 +22,10 @@
>>>  static inline void harden_branch_predictor(void)
>>>  {
>>>  	harden_branch_predictor_fn_t fn = per_cpu(harden_branch_predictor_fn,
>>> -						  smp_processor_id());
>>> +						  get_cpu());
>>>  	if (fn)
>>>  		fn();
>>> +	put_cpu();
>>>  }
>>>  #else
>>>  #define harden_branch_predictor() do { } while (0)
>>>
>>
>> This doesn't look like the right fix. If we're in a preemptible context,
>> then we could invalidate the branch predictor on the wrong CPU.
> 
> Sorry, my bad, thanks a lot for the good catch.
> 
>>
>> The right fix would be to move the call to a point where we haven't
>> enabled preemption yet.
> 
> I took a look at the code, and find out that the caller of
> harden_branch_predictor(), __do_user_fault(), is called by do_page_fault()
> and do_bad_area(), those two function's context are both running with
> preemption enabled, so I didn't find a good place to move the call,
> could you please give some suggestion for my next step?

Since we land here from do_page_fault, it seems natural to move the
invalidation up there, probably before we re-enable interrupts.

Thanks,

	M.
-- 
Jazz is not dead. It just smells funny...

WARNING: multiple messages have this Message-ID (diff)
From: Marc Zyngier <marc.zyngier@arm.com>
To: gaoyongliang <gaoyongliang@huawei.com>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"rmk+kernel@armlinux.org.uk" <rmk+kernel@armlinux.org.uk>,
	"linux@armlinux.org.uk" <linux@armlinux.org.uk>,
	"punitagrawal@gmail.com" <punitagrawal@gmail.com>,
	"rafael.j.wysocki@intel.com" <rafael.j.wysocki@intel.com>,
	"james.morse@arm.com" <james.morse@arm.com>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>
Cc: Shiwenlu <shiwenlu@huawei.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>,
	Zengweilin <zengweilin@huawei.com>,
	Nixiaoming <nixiaoming@huawei.com>,
	"Chenjie \(K\)" <chenjie6@huawei.com>
Subject: Re: [PATCH] arm: fix using smp_processor_id() in preemptible context
Date: Mon, 3 Jun 2019 16:30:45 +0100	[thread overview]
Message-ID: <a66ef5b9-19d0-2c02-8d1b-7e9c90067a76@arm.com> (raw)
In-Reply-To: <d003bd4642aa44e1a51b83cd0bf1f04e@huawei.com>

On 03/06/2019 15:44, gaoyongliang wrote:
> Hi Marc,
> 
> On 2019/6/3 18:17, Marc Zyngier wrote:
>> On 27/05/2019 10:39, Yongliang Gao wrote:
>>> harden_branch_predictor() call smp_processor_id() in preemptible
>>> context, this would cause a bug messages.
>>>
>>> The bug messages is as follows:
>>> BUG: using smp_processor_id() in preemptible [00000000] code: syz-executor0/17992
>>> caller is harden_branch_predictor arch/arm/include/asm/system_misc.h:27 [inline]
>>> caller is __do_user_fault+0x34/0x114 arch/arm/mm/fault.c:200
>>> CPU: 1 PID: 17992 Comm: syz-executor0 Tainted: G O 4.4.176 #1
>>> Hardware name: Hisilicon A9
>>> [<c0114ae4>] (unwind_backtrace) from [<c010e6fc>] (show_stack+0x18/0x1c)
>>> [<c010e6fc>] (show_stack) from [<c0379514>] (dump_stack+0xc8/0x118)
>>> [<c0379514>] (dump_stack) from [<c039b5a0>] (check_preemption_disabled+0xf4/0x138)
>>> [<c039b5a0>] (check_preemption_disabled) from [<c011abe4>] (__do_user_fault+0x34/0x114)
>>> [<c011abe4>] (__do_user_fault) from [<c053b0d0>] (do_page_fault+0x3b4/0x3d8)
>>> [<c053b0d0>] (do_page_fault) from [<c01013dc>] (do_DataAbort+0x58/0xf8)
>>> [<c01013dc>] (do_DataAbort) from [<c053a880>] (__dabt_usr+0x40/0x60)
>>>
>>> Reported-by: Jingwen Qiu <qiujingwen@huawei.com>
>>> Signed-off-by: Yongliang Gao <gaoyongliang@huawei.com>
>>> Cc: <stable@vger.kernel.org>
>>> ---
>>>  arch/arm/include/asm/system_misc.h | 3 ++-
>>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/arch/arm/include/asm/system_misc.h b/arch/arm/include/asm/system_misc.h
>>> index 66f6a3a..4a55cfb 100644
>>> --- a/arch/arm/include/asm/system_misc.h
>>> +++ b/arch/arm/include/asm/system_misc.h
>>> @@ -22,9 +22,10 @@
>>>  static inline void harden_branch_predictor(void)
>>>  {
>>>  	harden_branch_predictor_fn_t fn = per_cpu(harden_branch_predictor_fn,
>>> -						  smp_processor_id());
>>> +						  get_cpu());
>>>  	if (fn)
>>>  		fn();
>>> +	put_cpu();
>>>  }
>>>  #else
>>>  #define harden_branch_predictor() do { } while (0)
>>>
>>
>> This doesn't look like the right fix. If we're in a preemptible context,
>> then we could invalidate the branch predictor on the wrong CPU.
> 
> Sorry, my bad, thanks a lot for the good catch.
> 
>>
>> The right fix would be to move the call to a point where we haven't
>> enabled preemption yet.
> 
> I took a look at the code, and find out that the caller of
> harden_branch_predictor(), __do_user_fault(), is called by do_page_fault()
> and do_bad_area(), those two function's context are both running with
> preemption enabled, so I didn't find a good place to move the call,
> could you please give some suggestion for my next step?

Since we land here from do_page_fault, it seems natural to move the
invalidation up there, probably before we re-enable interrupts.

Thanks,

	M.
-- 
Jazz is not dead. It just smells funny...

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

  reply	other threads:[~2019-06-03 15:30 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-03 14:44 [PATCH] arm: fix using smp_processor_id() in preemptible context gaoyongliang
2019-06-03 15:30 ` Marc Zyngier [this message]
2019-06-03 15:30   ` Marc Zyngier
  -- strict thread matches above, loose matches on Subject: below --
2019-05-27  9:39 Yongliang Gao
2019-05-27  9:39 ` Yongliang Gao
2019-06-03 10:17 ` Marc Zyngier
2019-06-03 10:17   ` 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=a66ef5b9-19d0-2c02-8d1b-7e9c90067a76@arm.com \
    --to=marc.zyngier@arm.com \
    --cc=chenjie6@huawei.com \
    --cc=gaoyongliang@huawei.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=james.morse@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=nixiaoming@huawei.com \
    --cc=punitagrawal@gmail.com \
    --cc=rafael.j.wysocki@intel.com \
    --cc=rmk+kernel@armlinux.org.uk \
    --cc=shiwenlu@huawei.com \
    --cc=stable@vger.kernel.org \
    --cc=zengweilin@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.