Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp344435pxt; Thu, 5 Aug 2021 00:48:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzm8YIwNOLi4w2lx5RGBC7JHLg/Uk9cLFoX5+SggKX6brL7mDU3YdFjSIaMfxg4DPsborvb X-Received: by 2002:a05:6e02:1d89:: with SMTP id h9mr238558ila.46.1628149688176; Thu, 05 Aug 2021 00:48:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628149688; cv=none; d=google.com; s=arc-20160816; b=e/Mhqs2J92v4vu1bsCOWG60SZI4X264AfRQeZzvU7bLSuvrgtmZop3HU6KDEzndBjx QARB21M7zCNpNoJHCDoTRc4XfGyFn7RoE+THphz361CH2l+Jsd/Fta3mA9eUvWAUOWD9 0sdt0AqIx+77XYk1ndd0S4QNDMreb0xcP8hAQR0kuVzekCgt0LGjrnhqk0s//Ok+14W4 9Qt1EBnhLdTyfamQFMt5slwiup+4q24f4f8XDnf8xtTx1p1y28BkF0sJDhaIF5fdLdCk OfmNaWg92/f10CWxYYLWsHBs1k01TtxR7cAIH1NvsOwgchvzeO3OyztRWYBlUSJAgUiN YPEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=AaeKzUY4cQd9+YNvX25PrxBV+zlU6inRR6HWZxDBVmU=; b=J8Waugf4DZPwQcldwcwta2LCastG0yBgij+PCMuO19HB/mdcDI9XM59ceq/iYTnbMK /7c9grCEuTPU2irbb8JQ5DskM13huWqBSCtOQmAqEc46DSQUMa4/rr8Vthmjg8QbyeWL yZ7DfZnKMzlvNA5FCvkis/elmsq4AHPOxh7S12MiCFhmrtkFG3QdT8fWzSNoljPRsoVI UOvVY1io3fc5EsW6q180lTTz8pBD4k8UIcujBhkYoPQNpCjpRX97b0rzoqj4MOAAHSWY EUI0/G1VTT6VcpcJjoY332v7y1KV0S1BG3r2Gt3vbx0oL4jMomi3D2mQB2enCXnkLb5A ZBEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=LOp9N8lI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p6si5488331ilo.37.2021.08.05.00.47.57; Thu, 05 Aug 2021 00:48:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=LOp9N8lI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236102AbhHEGOE (ORCPT + 99 others); Thu, 5 Aug 2021 02:14:04 -0400 Received: from bilbo.ozlabs.org ([203.11.71.1]:36425 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230445AbhHEGOD (ORCPT ); Thu, 5 Aug 2021 02:14:03 -0400 Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4GgJG20Slyz9sRR; Thu, 5 Aug 2021 16:13:45 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ellerman.id.au; s=201909; t=1628144028; bh=AaeKzUY4cQd9+YNvX25PrxBV+zlU6inRR6HWZxDBVmU=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=LOp9N8lIe4VUmzG6DfvicD53CAUxPORkm0XJwE1a9xANkRb/+6ME4NuygO5GE8Mej ExH/jDhSMfhJXv4+iCYoZm0MPeG7qykHijpoR2O2QiyMoSZ54CKlTFyxl8Pb/HjWTj ojQtOwC8qzNZsF3BVu9cV8r0TbyqhcXzkroai6KiQ6XpKlPgwXHkQTQ24tBc6GKh0g gRcpOsuZYX4n2Qi4o2bDcTv2R8lmsHwCGjYXvrXvvDJDeomLdE66gJSKrCjtqDsR9R VNv3dEHvkny4A2J7R6e5KHPZaqJzpf5ARTAhbmU0E6cXiQUp5xJhiqNrhNiRpAk+3c Ea2XEXcIqSnaw== From: Michael Ellerman To: Pu Lehui , oleg@redhat.com, benh@kernel.crashing.org, paulus@samba.org, naveen.n.rao@linux.vnet.ibm.com, mhiramat@kernel.org, christophe.leroy@csgroup.eu, peterz@infradead.org, npiggin@gmail.com, ruscur@russell.cc Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, zhangjinhao2@huawei.com, xukuohai@huawei.com, pulehui@huawei.com Subject: Re: [PATCH] powerpc/kprobes: Fix kprobe Oops happens in booke In-Reply-To: <20210804143735.148547-1-pulehui@huawei.com> References: <20210804143735.148547-1-pulehui@huawei.com> Date: Thu, 05 Aug 2021 16:13:41 +1000 Message-ID: <87fsvoo1uy.fsf@mpe.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Pu Lehui writes: > When using kprobe on powerpc booke series processor, Oops happens > as show bellow: > > [ 35.861352] Oops: Exception in kernel mode, sig: 5 [#1] > [ 35.861676] BE PAGE_SIZE=4K SMP NR_CPUS=24 QEMU e500 > [ 35.861905] Modules linked in: > [ 35.862144] CPU: 0 PID: 76 Comm: sh Not tainted 5.14.0-rc3-00060-g7e96bf476270 #18 > [ 35.862610] NIP: c0b96470 LR: c00107b4 CTR: c0161c80 > [ 35.862805] REGS: c387fe70 TRAP: 0700 Not tainted (5.14.0-rc3-00060-g7e96bf476270) > [ 35.863198] MSR: 00029002 CR: 24022824 XER: 20000000 > [ 35.863577] > [ 35.863577] GPR00: c0015218 c387ff20 c313e300 c387ff50 00000004 40000002 40000000 0a1a2cce > [ 35.863577] GPR08: 00000000 00000004 00000000 59764000 24022422 102490c2 00000000 00000000 > [ 35.863577] GPR16: 00000000 00000000 00000040 10240000 10240000 10240000 10240000 10220000 > [ 35.863577] GPR24: ffffffff 10240000 00000000 00000000 bfc655e8 00000800 c387ff50 00000000 > [ 35.865367] NIP [c0b96470] schedule+0x0/0x130 > [ 35.865606] LR [c00107b4] interrupt_exit_user_prepare_main+0xf4/0x100 > [ 35.865974] Call Trace: > [ 35.866142] [c387ff20] [c0053224] irq_exit+0x114/0x120 (unreliable) > [ 35.866472] [c387ff40] [c0015218] interrupt_return+0x14/0x13c > [ 35.866728] --- interrupt: 900 at 0x100af3dc > [ 35.866963] NIP: 100af3dc LR: 100de020 CTR: 00000000 > [ 35.867177] REGS: c387ff50 TRAP: 0900 Not tainted (5.14.0-rc3-00060-g7e96bf476270) > [ 35.867488] MSR: 0002f902 CR: 20022422 XER: 20000000 > [ 35.867808] > [ 35.867808] GPR00: c001509c bfc65570 1024b4d0 00000000 100de020 20022422 bfc655a8 100af3dc > [ 35.867808] GPR08: 0002f902 00000000 00000000 00000000 72656773 102490c2 00000000 00000000 > [ 35.867808] GPR16: 00000000 00000000 00000040 10240000 10240000 10240000 10240000 10220000 > [ 35.867808] GPR24: ffffffff 10240000 00000000 00000000 bfc655e8 10245910 ffffffff 00000001 > [ 35.869406] NIP [100af3dc] 0x100af3dc > [ 35.869578] LR [100de020] 0x100de020 > [ 35.869751] --- interrupt: 900 > [ 35.870001] Instruction dump: > [ 35.870283] 40c20010 815e0518 714a0100 41e2fd04 39200000 913e00c0 3b1e0450 4bfffd80 > [ 35.870666] 0fe00000 92a10024 4bfff1a9 60000000 <7fe00008> 7c0802a6 93e1001c 7c5f1378 > [ 35.871339] ---[ end trace 23ff848139efa9b9 ]--- > > There is no real mode for booke arch and the MMU translation is > always on. The corresponding MSR_IS/MSR_DS bit in booke is used > to switch the address space, but not for real mode judgment. > > Fixes: 21f8b2fa3ca5 ("powerpc/kprobes: Ignore traps that happened in real mode") > Signed-off-by: Pu Lehui > --- > arch/powerpc/include/asm/ptrace.h | 6 ++++++ > arch/powerpc/kernel/kprobes.c | 5 +---- > 2 files changed, 7 insertions(+), 4 deletions(-) > > diff --git a/arch/powerpc/include/asm/ptrace.h b/arch/powerpc/include/asm/ptrace.h > index 3e5d470a6155..4aec1a97024b 100644 > --- a/arch/powerpc/include/asm/ptrace.h > +++ b/arch/powerpc/include/asm/ptrace.h > @@ -187,6 +187,12 @@ static inline unsigned long frame_pointer(struct pt_regs *regs) > #define user_mode(regs) (((regs)->msr & MSR_PR) != 0) > #endif > > +#ifdef CONFIG_BOOKE > +#define real_mode(regs) 0 > +#else > +#define real_mode(regs) (!((regs)->msr & MSR_IR) || !((regs)->msr & MSR_DR)) > +#endif I'm not sure about this helper. Arguably it should only return true if both MSR_IR and MSR_DR are clear. > diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c > index cbc28d1a2e1b..fac9a5974718 100644 > --- a/arch/powerpc/kernel/kprobes.c > +++ b/arch/powerpc/kernel/kprobes.c > @@ -289,10 +289,7 @@ int kprobe_handler(struct pt_regs *regs) > unsigned int *addr = (unsigned int *)regs->nip; > struct kprobe_ctlblk *kcb; > > - if (user_mode(regs)) > - return 0; > - > - if (!(regs->msr & MSR_IR) || !(regs->msr & MSR_DR)) > + if (user_mode(regs) || real_mode(regs)) > return 0; I think just adding an IS_ENABLED(CONFIG_BOOKE) here might be better. cheers