Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2406951ybl; Mon, 19 Aug 2019 01:21:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqzjA3IvuqxI/YRQR4QXkgMzYad+M0Gbs9ybDiMI0RSsgBhESXbgtls31FCOxtvZDPA3HbFG X-Received: by 2002:a17:90a:d343:: with SMTP id i3mr20379060pjx.15.1566202913617; Mon, 19 Aug 2019 01:21:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566202913; cv=none; d=google.com; s=arc-20160816; b=M+kWSCxj5u9XY2zdtjEKeSjmu8j4UXtWppE7YzAGJCxyIlsWZyZyPMqbbHILtuSq2b qczkI3vnDeSdA/tPDbul61DB0DwwgH7m8KUEfdr3JXRoeaziSPK3PBMWOiKsZMYf5/wq fWRmV5I5Gl9eEbiUXHdisT6LDmUwZ3x2OCseA9EpASxTfmBWJXlLO9Aye+E5SvyiDlYP jc6Kx+BLnGjQbq0Bk2Llh5G/fEEaH/WSff2D6eMtPjR5FEeN4AfeObLNGP+t7w42O9qY 26GE+581qNqzY7D2xxzckZyArrzG/jFV2eOMWQ3QUjuiTQfSLo4msASQpVxC14q+Yw+x 2C+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:mime-version:user-agent:date:message-id :subject:from:cc:to:dkim-signature; bh=hyz93VlF5VshkA7JRIXDWBACAMKFyp3ax7zG4J+d8HU=; b=HSeqCkcNODlWHzMhIubJg/eyVG+Z4/pnUjNqyunYhhwU3EpY7e7qstQ9Kjryi2hR0K kkKXtWUjjYX5mT4HviCHMhGcvDMLHpyQd/4QjhmKvn2PTahZyoKuHYL+Kl3/v3jwfymq KGRVYMLqv4Ear0WoVhpkcr6qROJmZcULUtxQNWjSL89Rfvu7cBLPU2mM+PDvof6lC9iq 3/3lwqeIx1K/CIaRivLE5w8fi/fuZ+YrgKlvMaoDhY1W1Qu9SBIuc0xo+iKEoG2QY/KO 7OC6Sj9McQSmYiWE5BL7mHoMitBjlZNxbQCOIcv4kQNr9ex1uPbhyfcAInCI3/Nb9xQg a3Wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b="fY/mLi0C"; 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 185si9387681pgc.522.2019.08.19.01.21.38; Mon, 19 Aug 2019 01:21:53 -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; dkim=pass header.i=@c-s.fr header.s=mail header.b="fY/mLi0C"; 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 S1727217AbfHSITP (ORCPT + 99 others); Mon, 19 Aug 2019 04:19:15 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:20462 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727068AbfHSITO (ORCPT ); Mon, 19 Aug 2019 04:19:14 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 46Bmzb5Gbfz9tyQN; Mon, 19 Aug 2019 10:19:07 +0200 (CEST) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=fY/mLi0C; dkim-adsp=pass; dkim-atps=neutral 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 x0jL0orQOV5N; Mon, 19 Aug 2019 10:19:07 +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 46Bmzb4Bhhz9tyQK; Mon, 19 Aug 2019 10:19:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1566202747; bh=hyz93VlF5VshkA7JRIXDWBACAMKFyp3ax7zG4J+d8HU=; h=To:Cc:From:Subject:Date:From; b=fY/mLi0CeO6g1zbGf3ZPOwk7euPagRZjBZMSmU68iBy6WUlZlmjKNMeZLv7A9BkFK qMQ4CdjsDnM/tAYIQ3MCCiLrC4vGCuPuQGFgQUbmmU1+bve8RmkJM0/bFAMFZtmjX6 bT1nS6ofNuD4rJRyejsBcKID1yF9OH923kktfTAQ= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id A79588B79C; Mon, 19 Aug 2019 10:19:12 +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 rRWjh1eTtjhR; Mon, 19 Aug 2019 10:19:12 +0200 (CEST) Received: from [172.25.230.101] (po15451.idsi0.si.c-s.fr [172.25.230.101]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 73DB18B778; Mon, 19 Aug 2019 10:19:12 +0200 (CEST) To: Drew Davenport Cc: Andrew Morton , "linuxppc-dev@lists.ozlabs.org" , "linux-kernel@vger.kernel.org" , Kees Cook From: Christophe Leroy Subject: WARN_ON(1) generates ugly code since commit 6b15f678fb7d Message-ID: <1d4fcfcf-e0b1-5af7-a54d-a5a3bbcedb89@c-s.fr> Date: Mon, 19 Aug 2019 10:18:57 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: fr Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Drew, I recently noticed gcc suddenly generating ugly code for WARN_ON(1). It looks like commit 6b15f678fb7d ("include/asm-generic/bug.h: fix "cut here" for WARN_ON for __WARN_TAINT architectures") is the culprit. unsigned long test_mul1(unsigned long a, unsigned long b) {     unsigned long long r = (unsigned long long)a * (unsigned long long)b;     if (r > 0xffffffff)         WARN_ON(1);     return r; } Before that patch, I was getting the following code: 00000008 :    8:    7d 23 20 16     mulhwu  r9,r3,r4    c:    7c 63 21 d6     mullw   r3,r3,r4   10:    2f 89 00 00     cmpwi   cr7,r9,0   14:    4d 9e 00 20     beqlr   cr7   18:    0f e0 00 00     twui    r0,0   1c:    4e 80 00 20     blr Now I get: 0000002c :   2c:    7d 23 20 16     mulhwu  r9,r3,r4   30:    94 21 ff f0     stwu    r1,-16(r1)   34:    7c 08 02 a6     mflr    r0   38:    93 e1 00 0c     stw     r31,12(r1)   3c:    90 01 00 14     stw     r0,20(r1)   40:    7f e3 21 d6     mullw   r31,r3,r4   44:    2f 89 00 00     cmpwi   cr7,r9,0   48:    40 9e 00 1c     bne     cr7,64   4c:    80 01 00 14     lwz     r0,20(r1)   50:    7f e3 fb 78     mr      r3,r31   54:    83 e1 00 0c     lwz     r31,12(r1)   58:    7c 08 03 a6     mtlr    r0   5c:    38 21 00 10     addi    r1,r1,16   60:    4e 80 00 20     blr   64:    3c 60 00 00     lis     r3,0             66: R_PPC_ADDR16_HA    .rodata.str1.4   68:    38 63 00 00     addi    r3,r3,0             6a: R_PPC_ADDR16_LO    .rodata.str1.4   6c:    48 00 00 01     bl      6c             6c: R_PPC_REL24    printk   70:    0f e0 00 00     twui    r0,0   74:    4b ff ff d8     b       4c As you can see, a call to printk() is added, which means setting up a stack frame, saving volatile registers, etc ... That's all the things we want to avoid when using WARN_ON(). And digging a bit more, I see that you are only adding this 'cut here' to calls like WARN_ON(1), ie where the condition is a constant. For calls where the condition is not a constant, there is no change and no 'cut here' line added: unsigned long test_mul2(unsigned long a, unsigned long b) {     unsigned long long r = (unsigned long long)a * (unsigned long long)b;     WARN_ON(r > 0xffffffff);     return r; } Before and after your patch, the code is clean and no call to add any 'cut here' line. 00000078 :   78:    7d 43 20 16     mulhwu  r10,r3,r4   7c:    7c 63 21 d6     mullw   r3,r3,r4   80:    31 2a ff ff     addic   r9,r10,-1   84:    7d 29 51 10     subfe   r9,r9,r10   88:    0f 09 00 00     twnei   r9,0   8c:    4e 80 00 20     blr Was it your intention to modify the behaviour and kill the lightweight implementations of WARN_ON() ? Looking into arch/powerpc/include/bug.h, I see that when the condition is constant, WARN_ON() uses __WARN(), which itself calls __WARN_FLAGS() with relevant flags. In the old days, __WARN() was implemented in arch/powerpc/include/bug.h Commit b2be05273a17 ("panic: Allow warnings to set different taint flags") replaced __WARN() by __WARN_TAINT() and added a generic definition of __WARN() In the begining I thought the __WARN() call in arch/powerpc/include/bug.h was forgotten, but looking into the commit in full, it looks like it was intentional to make __WARN() generic and have arches use it. Then commit 19d436268dde ("debug: Add _ONCE() logic to report_bug()") replaced __WARN_TAINT() by __WARN_FLAGS(). So by changing the generic __WARN() you are impacting all users include those using 'trap' like instruction in order to avoid function calls. What is to be done for getting back a clean code which doesn't call printk() on the hot path ? Thanks, Christophe