Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4993491imm; Tue, 18 Sep 2018 02:34:55 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbpoeiR7iHvrcSuyNn/vJuXMaAt6e+v3JuBeH0XXWota4/gAwo/N93znE92ZtuH0W1ENIx5 X-Received: by 2002:a17:902:aa49:: with SMTP id c9-v6mr28149351plr.195.1537263295459; Tue, 18 Sep 2018 02:34:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537263295; cv=none; d=google.com; s=arc-20160816; b=zqUFSCGetHZsMm4tOiTCf3G2d3K6XQWcav+Gx6kRTjB3DsiIlvmUE4wNVE77D4YA0r 75SVVcuxAUk/58M/1m/Fw6AiGjzNKQDcq25/gi8ZkNjReenWqaVq3q1CvzjsVzvkfpCr efoGaGpoQ5k04JTsv4IUZG417XX3y1M84Jihn12ZCj+muiTmLfRiMSM5O6SER4mx4h3J QvHWIhmZv61zRz2sJJGb/Njlyi7xxK6xAuzgbfiJzZt02siM3okiiTpR9f0hebq8bmxf 69K0IawhupX8Gqf58TEmtAfM904iIG2TQHOW7MgGiQJkrz0/A80RVATSy10t3Tdp289d QfIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:from:subject; bh=K/n7R2oZIaaOt3O5cGJglaJ1FAXM5Ts4QJtllLgOp2Y=; b=D2QQDTrc2nB+3dxBzNFmusK/5rjIBkRMGYP93jLoxqEOLCXA2vUjey+qKq+n2V/6aj 6gcHJQ4ZeonfUosXvBNRx9sNSFumJaEnC2XLHc1At9anKkbHHQjDMb0H/YPD9mRZdDEQ whF2r4PQiqMLD1Uwv8RtW09RFnvotkWcGCbxIGp/G3IkuDi6bVJlHSlLuTNjF4eOmDWq oop0Ul0WJnHSqjJekdzvy8MiHZCHZaRBD+tt6M+IvWcB9p/fx32rPswqBE5Rov5xyc37 HlVM4SWmbZPJRXCfYa2EoJXWek2YWz4wHEVKG4+sCGoXuMX1EN4msPGXbBvBTizCA6Zw 6T8g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g205-v6si18583524pfb.294.2018.09.18.02.34.39; Tue, 18 Sep 2018 02:34:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729242AbeIRPFk (ORCPT + 99 others); Tue, 18 Sep 2018 11:05:40 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:31645 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726838AbeIRPFk (ORCPT ); Tue, 18 Sep 2018 11:05:40 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 42DyVF5tjlz9ttC9; Tue, 18 Sep 2018 11:33:41 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id 7-1R2oRSNf_1; Tue, 18 Sep 2018 11:33:41 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 42DyVF5L3bz9ttBY; Tue, 18 Sep 2018 11:33:41 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 925468B7DE; Tue, 18 Sep 2018 11:33:52 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id uzEipEIdKS98; Tue, 18 Sep 2018 11:33:52 +0200 (CEST) Received: from pc16082vm.idsi0.si.c-s.fr (unknown [192.168.232.3]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 0D0A28B74C; Tue, 18 Sep 2018 11:33:52 +0200 (CEST) Subject: Checkpatch bad Warning (Re: [PATCH] powerpc/kgdb: add kgdb_arch_set/remove_breakpoint()) From: Christophe Leroy To: Joe Perches , Andy Whitcroft Cc: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org References: <872199441fd43b05fc1c7d049098ef7c0e83f4c5.1537262646.git.christophe.leroy@c-s.fr> Message-ID: <2f5f572a-a28c-9d17-844b-9e1961febf64@c-s.fr> Date: Tue, 18 Sep 2018 09:33:48 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <872199441fd43b05fc1c7d049098ef7c0e83f4c5.1537262646.git.christophe.leroy@c-s.fr> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On the below patch, checkpatch reports WARNING: struct kgdb_arch should normally be const #127: FILE: arch/powerpc/kernel/kgdb.c:480: +struct kgdb_arch arch_kgdb_ops; But when I add 'const', I get compilation failure CC arch/powerpc/kernel/kgdb.o arch/powerpc/kernel/kgdb.c:480:24: error: conflicting type qualifiers for ‘arch_kgdb_ops’ const struct kgdb_arch arch_kgdb_ops; ^ In file included from arch/powerpc/kernel/kgdb.c:18:0: ./include/linux/kgdb.h:284:26: note: previous declaration of ‘arch_kgdb_ops’ was here extern struct kgdb_arch arch_kgdb_ops; ^ make[1]: *** [arch/powerpc/kernel/kgdb.o] Error 1 Christophe On 09/18/2018 09:26 AM, Christophe Leroy wrote: > Generic implementation fails to remove breakpoints after init > when CONFIG_STRICT_KERNEL_RWX is selected: > > [ 13.251285] KGDB: BP remove failed: c001c338 > [ 13.259587] kgdbts: ERROR PUT: end of test buffer on 'do_fork_test' line 8 expected OK got $E14#aa > [ 13.268969] KGDB: re-enter exception: ALL breakpoints killed > [ 13.275099] CPU: 0 PID: 1 Comm: init Not tainted 4.18.0-g82bbb913ffd8 #860 > [ 13.282836] Call Trace: > [ 13.285313] [c60e1ba0] [c0080ef0] kgdb_handle_exception+0x6f4/0x720 (unreliable) > [ 13.292618] [c60e1c30] [c000e97c] kgdb_handle_breakpoint+0x3c/0x98 > [ 13.298709] [c60e1c40] [c000af54] program_check_exception+0x104/0x700 > [ 13.305083] [c60e1c60] [c000e45c] ret_from_except_full+0x0/0x4 > [ 13.310845] [c60e1d20] [c02a22ac] run_simple_test+0x2b4/0x2d4 > [ 13.316532] [c60e1d30] [c0081698] put_packet+0xb8/0x158 > [ 13.321694] [c60e1d60] [c00820b4] gdb_serial_stub+0x230/0xc4c > [ 13.327374] [c60e1dc0] [c0080af8] kgdb_handle_exception+0x2fc/0x720 > [ 13.333573] [c60e1e50] [c000e928] kgdb_singlestep+0xb4/0xcc > [ 13.339068] [c60e1e70] [c000ae1c] single_step_exception+0x90/0xac > [ 13.345100] [c60e1e80] [c000e45c] ret_from_except_full+0x0/0x4 > [ 13.350865] [c60e1f40] [c000e11c] ret_from_syscall+0x0/0x38 > [ 13.356346] Kernel panic - not syncing: Recursive entry to debugger > > This patch creates powerpc specific version of > kgdb_arch_set_breakpoint() and kgdb_arch_remove_breakpoint() > using patch_instruction() > > Fixes: 1e0fc9d1eb2b ("powerpc/Kconfig: Enable STRICT_KERNEL_RWX for some configs") > Signed-off-by: Christophe Leroy > --- > arch/powerpc/include/asm/kgdb.h | 5 ++++- > arch/powerpc/kernel/kgdb.c | 43 +++++++++++++++++++++++++++++++++-------- > 2 files changed, 39 insertions(+), 9 deletions(-) > > diff --git a/arch/powerpc/include/asm/kgdb.h b/arch/powerpc/include/asm/kgdb.h > index 9db24e77b9f4..a9e098a3b881 100644 > --- a/arch/powerpc/include/asm/kgdb.h > +++ b/arch/powerpc/include/asm/kgdb.h > @@ -26,9 +26,12 @@ > #define BREAK_INSTR_SIZE 4 > #define BUFMAX ((NUMREGBYTES * 2) + 512) > #define OUTBUFMAX ((NUMREGBYTES * 2) + 512) > + > +#define BREAK_INSTR 0x7d821008 /* twge r2, r2 */ > + > static inline void arch_kgdb_breakpoint(void) > { > - asm(".long 0x7d821008"); /* twge r2, r2 */ > + asm(stringify_in_c(.long BREAK_INSTR)); > } > #define CACHE_FLUSH_IS_SAFE 1 > #define DBG_MAX_REG_NUM 70 > diff --git a/arch/powerpc/kernel/kgdb.c b/arch/powerpc/kernel/kgdb.c > index 35e240a0a408..59c578f865aa 100644 > --- a/arch/powerpc/kernel/kgdb.c > +++ b/arch/powerpc/kernel/kgdb.c > @@ -24,6 +24,7 @@ > #include > #include > #include > +#include > #include > > /* > @@ -144,7 +145,7 @@ static int kgdb_handle_breakpoint(struct pt_regs *regs) > if (kgdb_handle_exception(1, SIGTRAP, 0, regs) != 0) > return 0; > > - if (*(u32 *) (regs->nip) == *(u32 *) (&arch_kgdb_ops.gdb_bpt_instr)) > + if (*(u32 *)regs->nip == BREAK_INSTR) > regs->nip += BREAK_INSTR_SIZE; > > return 1; > @@ -441,16 +442,42 @@ int kgdb_arch_handle_exception(int vector, int signo, int err_code, > return -1; > } > > +int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt) > +{ > + int err; > + unsigned int instr; > + unsigned int *addr = (unsigned int *)bpt->bpt_addr; > + > + err = probe_kernel_address(addr, instr); > + if (err) > + return err; > + > + err = patch_instruction(addr, BREAK_INSTR); > + if (err) > + return -EFAULT; > + > + *(unsigned int *)bpt->saved_instr = instr; > + > + return 0; > +} > + > +int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt) > +{ > + int err; > + unsigned int instr = *(unsigned int *)bpt->saved_instr; > + unsigned int *addr = (unsigned int *)bpt->bpt_addr; > + > + err = patch_instruction(addr, instr); > + if (err) > + return -EFAULT; > + > + return 0; > +} > + > /* > * Global data > */ > -struct kgdb_arch arch_kgdb_ops = { > -#ifdef __LITTLE_ENDIAN__ > - .gdb_bpt_instr = {0x08, 0x10, 0x82, 0x7d}, > -#else > - .gdb_bpt_instr = {0x7d, 0x82, 0x10, 0x08}, > -#endif > -}; > +struct kgdb_arch arch_kgdb_ops; > > static int kgdb_not_implemented(struct pt_regs *regs) > { >