From patchwork Thu Oct 18 16:25:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Changbin Du X-Patchwork-Id: 10647585 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C47A41057 for ; Thu, 18 Oct 2018 16:26:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B867F28E09 for ; Thu, 18 Oct 2018 16:26:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC46C28E47; Thu, 18 Oct 2018 16:26:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5FB6D28E15 for ; Thu, 18 Oct 2018 16:26:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728433AbeJSA2B (ORCPT ); Thu, 18 Oct 2018 20:28:01 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:40341 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727402AbeJSA2A (ORCPT ); Thu, 18 Oct 2018 20:28:00 -0400 Received: by mail-pg1-f194.google.com with SMTP id n31-v6so14426611pgm.7; Thu, 18 Oct 2018 09:26:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Qow+btamVg2OjyXBN/mPuA69PAgVb9M9/11WsfNvrQ0=; b=JBZo7hFFlLcDjNjQ9qsGb9IID5ORZzi7Cx3aVf4sQMbkZ4zyjhl07DK2Ay909dMUbW 987MBCyx9jyyCnuVtZPDaLfdNDCHgod1shuS5ZC0w4ZZKThpGNEmLCg2OLOjPB/V5Zla PoIaV+ICwKr6gC6GmJPY8QKsC/kJ0NbbPNI07/EU9iHgWo7JEvMalOdBaxwihIf+BOaj wUZKQvCiUwEcRWYaXhkzSSVUVdDhy9SsIpXyQlefSblqYLj9J5q6+1LziorAtg1RL+pU xJCFKS7ZrPvkmhIaIEeu6BkYee3JyfLvZJKjbKBMC93aSzYADNTXoU0ubYksXddfe0k8 w4Hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Qow+btamVg2OjyXBN/mPuA69PAgVb9M9/11WsfNvrQ0=; b=S2zwxbkiUdIfrNJwYk+o99MzghjjcdxMymNGi7blJbD9fbyNYx7PJsXUtAV/pYJRYq nAKFW5TWlFUbl901HBVO4zynb86qc4idIrb3t7MupMeBFRxgddCuoKHaZU7H0WS2deR1 bUDG/5xDNLtfuIYDjhkzjiasnV+zuIdCaB7MXbkUpKpMgVv3rOn/YHitczaYajmCBdRR B4v51WdIxLHV14cppl67lta3GvRoKuQ9ErmDdO5Vzk3Q5mqK6C/N8WXRk7QiEa7I8Jet XE8ZmWhoabvSC4WYQRdKuzulpaaAHf/iyyqTAIjh1hRr9jqyCjjfhMCvhgLE2j4pHqhU IgJg== X-Gm-Message-State: ABuFfojjGTMTCrBBigvMe0c02K0Qt95lqh5rPOJXpjQ7lbeT+2VBuSDa XHRwNH7UVfDUtijSVjScgys= X-Google-Smtp-Source: ACcGV63aTkB9Z/jGEUXZStVEAN5xhexA2ayr04PfL/fVuyfDasVUGKrICBasHtCiHWrSshUoKUm/IQ== X-Received: by 2002:a63:6c4a:: with SMTP id h71-v6mr28829004pgc.326.1539879975557; Thu, 18 Oct 2018 09:26:15 -0700 (PDT) Received: from vultr.guest ([2001:19f0:6001:4ff6:5400:1ff:feb7:a195]) by smtp.gmail.com with ESMTPSA id 5-v6sm27813420pgt.83.2018.10.18.09.26.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 09:26:14 -0700 (PDT) From: Du Changbin To: yamada.masahiro@socionext.com, michal.lkml@markovi.net, tglx@linutronix.de, mingo@redhat.com, linux@armlinux.org.uk, akpm@linux-foundation.org Cc: rostedt@goodmis.org, x86@kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sparse@vger.kernel.org, Changbin Du Subject: [PATCH 1/4] x86/mm: surround level4_kernel_pgt with #ifdef CONFIG_X86_5LEVEL...#endif Date: Thu, 18 Oct 2018 16:25:45 +0000 Message-Id: <20181018162548.6399-2-changbin.du@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181018162548.6399-1-changbin.du@gmail.com> References: <20181018162548.6399-1-changbin.du@gmail.com> Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Changbin Du The level4_kernel_pgt is only defined when X86_5LEVEL is enabled. So surround level4_kernel_pgt with #ifdef CONFIG_X86_5LEVEL...#endif to make code correct. Signed-off-by: Changbin Du Acked-by: Steven Rostedt (VMware) --- arch/x86/include/asm/pgtable_64.h | 2 ++ arch/x86/kernel/head64.c | 13 ++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h index 9c85b54bf03c..9333f7fa5bdb 100644 --- a/arch/x86/include/asm/pgtable_64.h +++ b/arch/x86/include/asm/pgtable_64.h @@ -16,7 +16,9 @@ #include #include +#ifdef CONFIG_X86_5LEVEL extern p4d_t level4_kernel_pgt[512]; +#endif extern p4d_t level4_ident_pgt[512]; extern pud_t level3_kernel_pgt[512]; extern pud_t level3_ident_pgt[512]; diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c index ddee1f0870c4..4a59ef93c258 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c @@ -151,16 +151,15 @@ unsigned long __head __startup_64(unsigned long physaddr, pgd = fixup_pointer(&early_top_pgt, physaddr); p = pgd + pgd_index(__START_KERNEL_map); - if (la57) - *p = (unsigned long)level4_kernel_pgt; - else - *p = (unsigned long)level3_kernel_pgt; - *p += _PAGE_TABLE_NOENC - __START_KERNEL_map + load_delta; - +#ifdef CONFIG_X86_5LEVEL if (la57) { + *p = (unsigned long)level4_kernel_pgt; p4d = fixup_pointer(&level4_kernel_pgt, physaddr); p4d[511] += load_delta; - } + } else +#endif + *p = (unsigned long)level3_kernel_pgt; + *p += _PAGE_TABLE_NOENC - __START_KERNEL_map + load_delta; pud = fixup_pointer(&level3_kernel_pgt, physaddr); pud[510] += load_delta; From patchwork Thu Oct 18 16:25:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Changbin Du X-Patchwork-Id: 10647587 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A8E321057 for ; Thu, 18 Oct 2018 16:26:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B16428DAA for ; Thu, 18 Oct 2018 16:26:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F19728E09; Thu, 18 Oct 2018 16:26:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2D3A228DAA for ; Thu, 18 Oct 2018 16:26:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728437AbeJSA2D (ORCPT ); Thu, 18 Oct 2018 20:28:03 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:41841 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727402AbeJSA2C (ORCPT ); Thu, 18 Oct 2018 20:28:02 -0400 Received: by mail-pg1-f194.google.com with SMTP id 23-v6so14419657pgc.8; Thu, 18 Oct 2018 09:26:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0hktjCZJ2dqRy2QJwHBnkarA09c1smLgcR1htixFWS0=; b=T2xFXCnFJSDwACvOM4jAnuW9am2LBNodpOwLcwDVkznJNd7WWJWEYK2bC2eLBKAeJe s3k/FJ5J3l5+CpTSDi99CXmHkhW+qk8d9/6W7NKzzFxAHfAYKoqjnkYC0RVppVUotII6 oBYzHu/0Dxp1Si24WLbBO4SX+qPBuaYW8VoI/9CBtQRnJFkE5eyiJB2iy5owmI6YSO/+ 9POds5Y6yhKHAPnDI1u8Uh1VewdB95Ng51L70wc+CaNzuG8I3jBlwGACpC+jQW814yW1 8TXtvCHmKMjHk9vQR/xVAOzPKsTnoVGCae+vHevzYKNkHuTq4MYsFp6JBjZKWqU/fFIv 6ZgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=0hktjCZJ2dqRy2QJwHBnkarA09c1smLgcR1htixFWS0=; b=Hgu9DFpoXKP523iwt/NUj2Wlayl9c/mL/xK+hmiPnPIyoKPqLSh558eIKf91u6PDcW YbC+y1QLs2cn92NLaxhY5WqVc/WPllB/L9ts7BHqbPKrAqjeBDMz9Zb7yLk32jPcl8iW GG0b5VojplvtrTQ5PQv3f/BnkoaYDkvCC87j2dA2HuI8JasS/YWwfNYXddulKtMskerN NiInf3FBSyZFVzU3AjcRX8ni6lfB8KmkmfInc+Of4XECUbQLFz84P/w8LoEoS5A6wjTo 2Dgf7ivJ1JYZls/rM0QaOCoIc6Y33r1i1ZVqJIHPkL8DE22zI4FWwUBsX1mklHWTjOsG JnQg== X-Gm-Message-State: ABuFfoh5XjFsmnAPrMrk8jWyePWTK/MDHZ2asOYbqnJ9A5FEpfqzY0Ui uq221GNId8vQ8Tk3WTQ0DXw= X-Google-Smtp-Source: ACcGV62sgfwcwopmBgSgQjtntve/8dNwdOYl35Y4pL2fFgCLCaZRln+rZVS329JSlPL7lCRxGg4EHQ== X-Received: by 2002:a63:5b14:: with SMTP id p20-v6mr28912816pgb.56.1539879978004; Thu, 18 Oct 2018 09:26:18 -0700 (PDT) Received: from vultr.guest ([2001:19f0:6001:4ff6:5400:1ff:feb7:a195]) by smtp.gmail.com with ESMTPSA id 5-v6sm27813420pgt.83.2018.10.18.09.26.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 09:26:17 -0700 (PDT) From: Du Changbin To: yamada.masahiro@socionext.com, michal.lkml@markovi.net, tglx@linutronix.de, mingo@redhat.com, linux@armlinux.org.uk, akpm@linux-foundation.org Cc: rostedt@goodmis.org, x86@kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sparse@vger.kernel.org, Changbin Du Subject: [PATCH 2/4] kernel hacking: new config NO_AUTO_INLINE to disable compiler auto-inline optimizations Date: Thu, 18 Oct 2018 16:25:46 +0000 Message-Id: <20181018162548.6399-3-changbin.du@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181018162548.6399-1-changbin.du@gmail.com> References: <20181018162548.6399-1-changbin.du@gmail.com> Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Changbin Du This patch add a new kernel hacking option NO_AUTO_INLINE. Selecting this option will prevent the compiler from optimizing the kernel by auto-inlining functions not marked with the inline keyword. With this option, only functions explicitly marked with "inline" will be inlined. This will allow the function tracer to trace more functions because it only traces functions that the compiler has not inlined. Signed-off-by: Changbin Du Acked-by: Steven Rostedt (VMware) --- Makefile | 6 ++++++ lib/Kconfig.debug | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/Makefile b/Makefile index e8b599b4dcde..757d6507cb5c 100644 --- a/Makefile +++ b/Makefile @@ -749,6 +749,12 @@ KBUILD_CFLAGS += $(call cc-option, -femit-struct-debug-baseonly) \ $(call cc-option,-fno-var-tracking) endif +ifdef CONFIG_NO_AUTO_INLINE +KBUILD_CFLAGS += $(call cc-option, -fno-inline-functions) \ + $(call cc-option, -fno-inline-small-functions) \ + $(call cc-option, -fno-inline-functions-called-once) +endif + ifdef CONFIG_FUNCTION_TRACER ifdef CONFIG_FTRACE_MCOUNT_RECORD # gcc 5 supports generating the mcount tables directly diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 4966c4fbe7f7..0f9b4fa78b1c 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -211,6 +211,31 @@ config GDB_SCRIPTS instance. See Documentation/dev-tools/gdb-kernel-debugging.rst for further details. +config NO_AUTO_INLINE + bool "Disable compiler auto-inline optimizations" + help + This will prevent the compiler from optimizing the kernel by + auto-inlining functions not marked with the inline keyword. + With this option, only functions explicitly marked with + "inline" will be inlined. This will allow the function tracer + to trace more functions because it only traces functions that + the compiler has not inlined. + + Enabling this function can help debugging a kernel if using + the function tracer. But it can also change how the kernel + works, because inlining functions may change the timing, + which could make it difficult while debugging race conditions. + + If unsure, select N. + +config ENABLE_WARN_DEPRECATED + bool "Enable __deprecated logic" + default y + help + Enable the __deprecated logic in the kernel build. + Disable this to suppress the "warning: 'foo' is deprecated + (declared at kernel/power/somefile.c:1234)" messages. + config ENABLE_MUST_CHECK bool "Enable __must_check logic" default y From patchwork Thu Oct 18 16:25:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Changbin Du X-Patchwork-Id: 10647593 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E6C1B1057 for ; Thu, 18 Oct 2018 16:26:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D8C7228DF7 for ; Thu, 18 Oct 2018 16:26:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CAAE528E42; Thu, 18 Oct 2018 16:26:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E752E28DF7 for ; Thu, 18 Oct 2018 16:26:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728495AbeJSA2F (ORCPT ); Thu, 18 Oct 2018 20:28:05 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:44408 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727402AbeJSA2E (ORCPT ); Thu, 18 Oct 2018 20:28:04 -0400 Received: by mail-pg1-f195.google.com with SMTP id g2-v6so14414931pgu.11; Thu, 18 Oct 2018 09:26:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3FKV7PguVhGaaFT83abrxfobePyuJ/ZBdvJ6x8a5cqo=; b=OcMIVvUF0GMfsZrF86d8yWroo+jUju7bdcmKhW2WHFItvRzBbiDUbAc22FlA/fZvU6 UACA3b3wIs9U/54RNw+OW2DfKwfqP4IiycD25C4e0kCuu9ZK2vLHGKLOUgKGYF4r2Z8n /7E7+Gp35Y0rdLvyVZKdq71WZVggR/2xYaZq675XRmSlBTS3N3B0Kn8qqhygDDLqp4Yz eqQkQHKVvrYCCxiAPH1lMDp8fLbgEEkFDZIN5tZviQovcS6HW41SoHaVhYY38N5iFxgD AMTE8O2Q0TAatjfK5Rfv3cyRtL5cGfm+RDJ/Dl7wf9Juz6hCUcuM9AkCLs1e8LUuevhO teuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=3FKV7PguVhGaaFT83abrxfobePyuJ/ZBdvJ6x8a5cqo=; b=DqIuq+uOQB+CvqbHLlJDd2/Ym6vOYHsJMdsVm5Or1BckZn8qNXPW1Ys6eJs1859RKN Gj7SlJ3nE2MMWMmYEDkrE0y8QG7SlFdMXIcuU5W8vo38nekJnzsM5fuUJPqygMMxbsvp dhN2zWD/28BacKN2ZyAdbsMSuq0GkvzCm0J/9aNPYHe73D3i7j2AlpzqMBOE1SUCqBbu mN1M/7/k7HlWDznWYq9MrGDApYK4cekRaJooprj+wkykCD/V7+LfCVpqy9WqyTJW6vxU hSdsHJcxfpyWfF2rPNZT+Q6pj/wsYlOQVXsJRidxTtdZFFXKCvM09T0zfnw75Cfb3Qzp 8Afg== X-Gm-Message-State: ABuFfoggHcoFiF138wHFm/5iU3NkhxzJGVUrQ9cghtto7O3zUE1plyfE aVScM+5qtPBw7pXRcWQmvgg= X-Google-Smtp-Source: ACcGV60fGQ3vI6QAckWY02jxNLZN0sfT01xEM3j1WUqCQxDk1bHd8eMxfH/HYDQ2rjNo3i4tbr2klw== X-Received: by 2002:a65:44c6:: with SMTP id g6-v6mr28329113pgs.350.1539879979903; Thu, 18 Oct 2018 09:26:19 -0700 (PDT) Received: from vultr.guest ([2001:19f0:6001:4ff6:5400:1ff:feb7:a195]) by smtp.gmail.com with ESMTPSA id 5-v6sm27813420pgt.83.2018.10.18.09.26.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 09:26:19 -0700 (PDT) From: Du Changbin To: yamada.masahiro@socionext.com, michal.lkml@markovi.net, tglx@linutronix.de, mingo@redhat.com, linux@armlinux.org.uk, akpm@linux-foundation.org Cc: rostedt@goodmis.org, x86@kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sparse@vger.kernel.org, Changbin Du Subject: [PATCH 3/4] ARM: mm: fix build error in fix_to_virt with CONFIG_CC_OPTIMIZE_FOR_DEBUGGING Date: Thu, 18 Oct 2018 16:25:47 +0000 Message-Id: <20181018162548.6399-4-changbin.du@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181018162548.6399-1-changbin.du@gmail.com> References: <20181018162548.6399-1-changbin.du@gmail.com> Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Changbin Du With '-Og' optimization level, GCC would not optimize a count for a loop as a constant value. But BUILD_BUG_ON() only accept compile-time constant values. Let's use __fix_to_virt() to avoid the error. arch/arm/mm/mmu.o: In function `fix_to_virt': /home/changbin/work/linux/./include/asm-generic/fixmap.h:31: undefined reference to `__compiletime_assert_31' Makefile:1051: recipe for target 'vmlinux' failed make: *** [vmlinux] Error 1 Signed-off-by: Changbin Du Acked-by: Steven Rostedt (VMware) --- arch/arm/mm/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c index e46a6a446cdd..c08d74e76714 100644 --- a/arch/arm/mm/mmu.c +++ b/arch/arm/mm/mmu.c @@ -1599,7 +1599,7 @@ static void __init early_fixmap_shutdown(void) pte_t *pte; struct map_desc map; - map.virtual = fix_to_virt(i); + map.virtual = __fix_to_virt(i); pte = pte_offset_early_fixmap(pmd_off_k(map.virtual), map.virtual); /* Only i/o device mappings are supported ATM */ From patchwork Thu Oct 18 16:25:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Changbin Du X-Patchwork-Id: 10647589 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D32CA14E2 for ; Thu, 18 Oct 2018 16:26:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C456828DAA for ; Thu, 18 Oct 2018 16:26:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B77FB28E09; Thu, 18 Oct 2018 16:26:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 945B528DF7 for ; Thu, 18 Oct 2018 16:26:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728549AbeJSA2I (ORCPT ); Thu, 18 Oct 2018 20:28:08 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:40798 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727402AbeJSA2G (ORCPT ); Thu, 18 Oct 2018 20:28:06 -0400 Received: by mail-pf1-f196.google.com with SMTP id g21-v6so8119348pfi.7; Thu, 18 Oct 2018 09:26:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=9eCcFwClc/5D+HmPAfHoHvl09JbyYIVvefaSqD/YOyI=; b=fFRvCw1hiJEZweCIp0gv9a3Zk4dga6dxB4jIE6EV2Brch+GvTEs3vxnMCI41hbRRGB wp9yzOF+mIzPvC9EEeG/PjEsqGv8hpIeXljLcfq5zCpOZKUk/DSA7g7EFoNxXwe1K7jy NLljTQoATWRyjHLdK6K+vy7qklRbSBX77I+0rZlEKUKs7SOT8sQeZhNSpLLolP1JC+6g BG7EHQSUU1nMv9tRLm8tczRHP1dnA1gm5azOlvXie4FuJKcyr2VR8nS8Nvo79JWjzqik MEiBhhiqsiFI0E4Ew9YnAsZTXr0nSM0XtkDMyEXVzHaQ6CukQoRB4VsSITeovEHGfaPy oR3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=9eCcFwClc/5D+HmPAfHoHvl09JbyYIVvefaSqD/YOyI=; b=rG+gva3xXruxKXZjWnIrA/XkaKkTw65fR9WlUJWUAcuVAxWa+iT1am1XHEuW0382Gx ImnOc1an0dpuRKe4otwqS98FqfqGKLYjm7P4o7TmlC9/TGJx85zyttxTBZQM+FqAMMhW mW8klUbGTgAG0qNw4coJ5KMKhT+WgHTRY44UDwBSet3zkaX9ICGl1ntRZXx1j3lEABAq OZUc22XjfdAZEFLhb5bTkzAfZRO/i6bW5/ir4Di3UKvPZ4TviU1D6kdLVSxWco4VPejc gh/iWLML0JtLaHZN95HUwCn6Yv3NW1zc24UhNlg0lHUb6IfEns6dnCr+YZ5tn+BIdLfP CApQ== X-Gm-Message-State: ABuFfogKMNE555sh7y/XER5PgPn828dhBs00K4W2Jba/xu/0fDvwP1OM 3otg1tqINDDFnDcbwbjELDU= X-Google-Smtp-Source: ACcGV62iJNPxQPazmNAibcbEa9bGAYUqtlH3ywUPDs9QfLOd4ZQ7dvKyzknAFCLw4rGYzHvSISD07g== X-Received: by 2002:a63:f448:: with SMTP id p8-v6mr28973391pgk.124.1539879981819; Thu, 18 Oct 2018 09:26:21 -0700 (PDT) Received: from vultr.guest ([2001:19f0:6001:4ff6:5400:1ff:feb7:a195]) by smtp.gmail.com with ESMTPSA id 5-v6sm27813420pgt.83.2018.10.18.09.26.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 09:26:21 -0700 (PDT) From: Du Changbin To: yamada.masahiro@socionext.com, michal.lkml@markovi.net, tglx@linutronix.de, mingo@redhat.com, linux@armlinux.org.uk, akpm@linux-foundation.org Cc: rostedt@goodmis.org, x86@kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sparse@vger.kernel.org, Changbin Du Subject: [PATCH 4/4] kernel hacking: new config CC_OPTIMIZE_FOR_DEBUGGING to apply GCC -Og optimization Date: Thu, 18 Oct 2018 16:25:48 +0000 Message-Id: <20181018162548.6399-5-changbin.du@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181018162548.6399-1-changbin.du@gmail.com> References: <20181018162548.6399-1-changbin.du@gmail.com> Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Changbin Du This will apply GCC '-Og' optimization level which is supported since GCC 4.8. This optimization level offers a reasonable level of optimization while maintaining fast compilation and a good debugging experience. It is similar to '-O1' while perferring to keep debug ability over runtime speed. If enabling this option breaks your kernel, you should either disable this or find a fix (mostly in the arch code). Currently this option has only been tested on x86_64 and arm platform. This option can satisfy people who was searching for a method to disable compiler optimizations so to achieve better kernel debugging experience with kgdb or qemu. The main problem of '-Og' is we must not use __attribute__((error(msg))). The compiler will report error though the call to error function still can be optimize out. So we must fallback to array tricky. Comparison of vmlinux size: a bit smaller. w/o CONFIG_CC_OPTIMIZE_FOR_DEBUGGING $ size vmlinux text data bss dec hex filename 22665554 9709674 2920908 35296136 21a9388 vmlinux w/ CONFIG_CC_OPTIMIZE_FOR_DEBUGGING $ size vmlinux text data bss dec hex filename 21499032 10102758 2920908 34522698 20ec64a vmlinux Comparison of system performance: a bit drop (~6%). This benchmark of kernel compilation is suggested by Ingo Molnar. https://lkml.org/lkml/2018/5/2/74 Preparation: Set cpufreq to 'performance'. for ((cpu=0; cpu<120; cpu++)); do G=/sys/devices/system/cpu/cpu$cpu/cpufreq/scaling_governor [ -f $G ] && echo performance > $G done w/o CONFIG_CC_OPTIMIZE_FOR_DEBUGGING $ perf stat --repeat 5 --null --pre '\ cp -a kernel ../kernel.copy.$(date +%s); \ rm -rf *; \ git checkout .; \ echo 1 > /proc/sys/vm/drop_caches; \ find ../kernel* -type f | xargs cat >/dev/null; \ make -j kernel >/dev/null; \ make clean >/dev/null 2>&1; \ sync '\ \ make -j8 >/dev/null Performance counter stats for 'make -j8' (5 runs): 219.764246652 seconds time elapsed ( +- 0.78% ) w/ CONFIG_CC_OPTIMIZE_FOR_DEBUGGING $ perf stat --repeat 5 --null --pre '\ cp -a kernel ../kernel.copy.$(date +%s); \ rm -rf *; \ git checkout .; \ echo 1 > /proc/sys/vm/drop_caches; \ find ../kernel* -type f | xargs cat >/dev/null; \ make -j kernel >/dev/null; \ make clean >/dev/null 2>&1; \ sync '\ \ make -j8 >/dev/null Performance counter stats for 'make -j8' (5 runs): 233.574187771 seconds time elapsed ( +- 0.19% ) Signed-off-by: Changbin Du Acked-by: Steven Rostedt (VMware) --- Makefile | 5 +++++ include/linux/compiler-gcc.h | 2 +- include/linux/compiler.h | 2 +- init/Kconfig | 19 +++++++++++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 757d6507cb5c..0e747fafb53b 100644 --- a/Makefile +++ b/Makefile @@ -657,6 +657,10 @@ KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation) KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow) KBUILD_CFLAGS += $(call cc-disable-warning, int-in-bool-context) +ifdef CONFIG_CC_OPTIMIZE_FOR_DEBUGGING +KBUILD_CFLAGS += $(call cc-option, -Og) +KBUILD_CFLAGS += $(call cc-disable-warning,maybe-uninitialized,) +else ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE KBUILD_CFLAGS += $(call cc-option,-Oz,-Os) KBUILD_CFLAGS += $(call cc-disable-warning,maybe-uninitialized,) @@ -667,6 +671,7 @@ else KBUILD_CFLAGS += -O2 endif endif +endif KBUILD_CFLAGS += $(call cc-ifversion, -lt, 0409, \ $(call cc-disable-warning,maybe-uninitialized,)) diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h index 4d36b27214fd..2a76f7c64b54 100644 --- a/include/linux/compiler-gcc.h +++ b/include/linux/compiler-gcc.h @@ -85,7 +85,7 @@ #define __compiletime_object_size(obj) __builtin_object_size(obj, 0) -#ifndef __CHECKER__ +#if !defined(__CHECKER__) && !defined(CONFIG_CC_OPTIMIZE_FOR_DEBUGGING) #define __compiletime_warning(message) __attribute__((warning(message))) #define __compiletime_error(message) __attribute__((error(message))) diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 681d866efb1e..9385c62e9f00 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -320,7 +320,7 @@ static inline void *offset_to_ptr(const int *off) * sparse see a constant array size without breaking compiletime_assert on old * versions of GCC (e.g. 4.2.4), so hide the array from sparse altogether. */ -# ifndef __CHECKER__ +# if !defined(__CHECKER__) && !defined(CONFIG_CC_OPTIMIZE_FOR_DEBUGGING) # define __compiletime_error_fallback(condition) \ do { ((void)sizeof(char[1 - 2 * condition])); } while (0) # endif diff --git a/init/Kconfig b/init/Kconfig index 1e234e2f1cba..b01c7c654570 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1081,6 +1081,25 @@ config CC_OPTIMIZE_FOR_SIZE If unsure, say N. +config CC_OPTIMIZE_FOR_DEBUGGING + bool "Optimize for better debugging experience (-Og)" + select NO_AUTO_INLINE + help + This will apply GCC '-Og' optimization level which is supported + since GCC 4.8. This optimization level offers a reasonable level + of optimization while maintaining fast compilation and a good + debugging experience. It is similar to '-O1' while preferring to + keep debug ability over runtime speed. The overall performance + will drop a bit (~6%). + + Use only if you want to debug the kernel, especially if you want + to have better kernel debugging experience with gdb facilities + like kgdb or qemu. If enabling this option breaks your kernel, + you should either disable this or find a fix (mostly in the arch + code). + + If unsure, select N. + endchoice config HAVE_LD_DEAD_CODE_DATA_ELIMINATION