From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MIME_HTML_ONLY,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C21D3C433DB for ; Wed, 20 Jan 2021 20:53:54 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EFF8D233FC for ; Wed, 20 Jan 2021 20:53:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EFF8D233FC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.vnet.ibm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4DLd6P3LyKzDqkj for ; Thu, 21 Jan 2021 07:53:49 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=atrajeev@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=NoeHWcji; dkim-atps=neutral Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4DLYk04fwzzDqLZ for ; Thu, 21 Jan 2021 05:20:55 +1100 (AEDT) Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 10KI3Htm010653 for ; Wed, 20 Jan 2021 13:20:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=subject : mime-version : content-type : from : in-reply-to : date : cc : content-transfer-encoding : message-id : references : to; s=pp1; bh=cIIB8y1P/hZd5eRbbjMR9K3EawScybNRNspfy+u9B0M=; b=NoeHWcjikeln1PdbftwPiOAoGQWyIefbSlHyt030+G0QiIQ7qZ+7Ixk9ieZU7Pz3Fbqw Y5slaTWMXWXH+Gs4do3tGEtiBC+nivKKfvoXSXm8aX9YDc+gi4iQDDNUJQkw5JLfYeQ/ qPij1oncwX8I/LbBLZZlebBwoS99COcdxYsPco4py/fHoEyAFT7snMJ1bg9KdxycbB34 D2MzQ183HKChzsSZFpcdaN40uXMxgx13sJohzBs8k16aFSnBUBHuAK5kl/0Wgs/Ddww7 nVEOleJfxOfCSxs7fTVO6eYUAkdE5EO5C+z/O0nTDJIe1HG0Wh2PZxELb7VXX1CS59Uz Bw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 366s7trqnj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 20 Jan 2021 13:20:49 -0500 Received: from m0098413.ppops.net (m0098413.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 10KI3Ulc012271 for ; Wed, 20 Jan 2021 13:20:49 -0500 Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0b-001b2d01.pphosted.com with ESMTP id 366s7trqn5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 20 Jan 2021 13:20:49 -0500 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 10KIGf7p000872; Wed, 20 Jan 2021 18:20:47 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma06ams.nl.ibm.com with ESMTP id 3668nwrwpd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 20 Jan 2021 18:20:47 +0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 10KIKjGl41419254 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 20 Jan 2021 18:20:45 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4EE1142042; Wed, 20 Jan 2021 18:20:45 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3F54642045; Wed, 20 Jan 2021 18:20:44 +0000 (GMT) Received: from [9.79.237.231] (unknown [9.79.237.231]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Wed, 20 Jan 2021 18:20:43 +0000 (GMT) Subject: Re: [PATCH] powerpc/64: prevent replayed interrupt handlers from running softirqs Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) Content-Type: text/html; charset=utf-8 X-Apple-Auto-Saved: 1 X-Apple-Mail-Plain-Text-Draft: yes From: Athira Rajeev X-Apple-Mail-Remote-Attachments: YES X-Apple-Base-Url: x-msg://6/ In-Reply-To: <20210120075005.1678565-1-npiggin@gmail.com> X-Apple-Windows-Friendly: 1 Date: Wed, 20 Jan 2021 23:42:21 +0530 X-Apple-Mail-Signature: SKIP_SIGNATURE Content-Transfer-Encoding: quoted-printable Message-Id: References: <20210120075005.1678565-1-npiggin@gmail.com> X-Uniform-Type-Identifier: com.apple.mail-draft To: Nicholas Piggin X-Mailer: Apple Mail (2.3608.120.23.2.4) X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.343, 18.0.737 definitions=2021-01-20_10:2021-01-20, 2021-01-20 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 adultscore=0 suspectscore=0 phishscore=0 priorityscore=1501 impostorscore=0 clxscore=1015 mlxlogscore=999 malwarescore=0 bulkscore=0 mlxscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101200102 X-Mailman-Approved-At: Thu, 21 Jan 2021 07:49:58 +1100 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev"


On = 20-Jan-2021, at 1:20 PM, Nicholas Piggin <npiggin@gmail.com> = wrote:

Running softirqs enables interrupts, which can then end up = recursing
into the irq soft-mask code we're adjusting, including = replaying
interrupts itself, which might be theoretically = unbounded.

This abridged trace shows how this can occur:

! = NIP replay_soft_interrupts
LR =  interrupt_exit_kernel_prepare
Call Trace:
=   interrupt_exit_kernel_prepare (unreliable)
=   interrupt_return
--- interrupt: ea0 at = __rb_reserve_next
NIP __rb_reserve_next
LR __rb_reserve_next
= Call Trace:
  ring_buffer_lock_reserve
=   trace_function
  function_trace_call
=   ftrace_call
  __do_softirq
=   irq_exit
  timer_interrupt
! =   replay_soft_interrupts
=   interrupt_exit_kernel_prepare
=   interrupt_return
--- interrupt: ea0 at = arch_local_irq_restore

Fix this by disabling bhs (softirqs) = around the interrupt replay.

I don't know that commit = 3282a3da25bd ("powerpc/64: Implement soft
interrupt replay in C") = actually introduced the problem. Prior to that
change, the interrupt = replay seems like it should still be subect to
this recusion, however = it's done after all the irq state has been fixed
up at the end of the = replay, so it seems reasonable to fix back to = this
commit.

Fixes: 3282a3da25bd ("powerpc/64: Implement soft = interrupt replay in C")
Signed-off-by: Nicholas Piggin = <npiggin@gmail.com>

Thanks for the fix = Nick.

Tested this below scenario where previously it was = resulting in soft lockup=E2=80=99s with the trace described in the = commit message.
With the patch, I don=E2=80=99t see soft = lockup=E2=80=99s.

Test scenario: My test kernel module below = tries to create one of performance monitor
counter ( PMC6 ) overflow = between local_irq_save/local_irq_restore. I am also configuring = ftrace.

Environment :One CPU online and Bare Metal = system
prerequisite for ftrace:
# cd = /sys/kernel/debug/tracing
# echo 100 > buffer_percent
# echo = 200000 > buffer_size_kb
# echo ppc-tb > trace_clock
# echo = function > current_tracer

Part of sample kernel test module to = trigger a PMI between
local_irq_save and = local_irq_restore:

<<>>
static ulong delay =3D = 1;
static void busy_wait(ulong time)
{
=       udelay(delay);
}
static = __always_inline void irq_test(void)
{
=       unsigned long flags;
=       local_irq_save(flags);
=       trace_printk("IN IRQ TEST\n");
=       mtspr(SPRN_MMCR0, 0x80000000);
=       mtspr(SPRN_PMC6, 0x80000000 - = 100);
      mtspr(SPRN_MMCR0, = 0x6004000);
=       busy_wait(delay);
=       trace_printk("IN IRQ TEST = DONE\n");
=       local_irq_restore(flags);
=       mtspr(SPRN_MMCR0, 0x80000000);
=       mtspr(SPRN_PMC6, = 0);
}
<<>>

With the patch, there is no soft = lockup=E2=80=99s.

Tested-by: Athira Rajeev = <atrajeev@linux.vnet.ibm.com>

---
arch/powerpc/kernel/irq.c | 14 ++++++++++++++
1 = file changed, 14 insertions(+)

diff --git = a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
index = 6b1eca53e36c..7064135f9dc3 100644
--- = a/arch/powerpc/kernel/irq.c
+++ b/arch/powerpc/kernel/irq.c
@@ = -188,6 +188,18 @@ void replay_soft_interrupts(void)
unsigned = char happened =3D local_paca->irq_happened;
struct = pt_regs regs;

+ /*
+ * = Prevent softirqs from being run when an interrupt handler = returns
+ = * and calls irq_exit(), because softirq processing enables = interrupts.
+ = * If an interrupt is taken, it may then call = replay_soft_interrupts
+ * on its way out, which gets = messy and recursive.
+ *
+ * = softirqs created by replayed interrupts will be run at the end = of
+ = * this function when bhs are enabled (if they were enabled in = our
+ = * caller).
+ */
+ = local_bh_disable();
+
= ppc_save_regs(&regs);
regs.softe =3D = IRQS_ENABLED;

@@ -263,6 +275,8 @@ void = replay_soft_interrupts(void)
trace_hardirqs_off();
goto = again;
= }
+
+ = local_bh_enable();
}

notrace void = arch_local_irq_restore(unsigned long mask)
-- =
2.23.0


=