Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1825781pxj; Sun, 16 May 2021 05:32:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMSE+Y1o/0mwhYEW6StISWmgB/UhxVSgrosmXLC7BQOQosGndypzV494AeRWcSUNcG5Emu X-Received: by 2002:a17:906:b816:: with SMTP id dv22mr57440187ejb.193.1621168341826; Sun, 16 May 2021 05:32:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621168341; cv=none; d=google.com; s=arc-20160816; b=zO8crHzlT7f19fEogeW8b2yJW50pDQe58uWN8pPJXgaULtdNuhfMFqAmJEqKBT0uJo jKYYktYWmG6zqj4Pq9aErM6Sw4OUSck+l2vtiUFQuleMGQ8SNxQAeTX/3NLElRoCn2J6 bRjr6H5VFTowgL7T2SI6hsTCg4gMaq2vvN7M8V1DmvbIW7L6XxtlBPSMZcLLazLlFp3q 9DuAfOVKFGXl0U7odbubUnDBjNKyArvKloD4PsE8v0U++WdrB7M0dXvVpmksyqXAfS/O WQzonsZW1i13YMsnCP6O8piEQZ0EguUa3kN9vL55HD6isZmu6hpwWCDc05RI2G1txVpw qGnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=aQhBm9uhx0+AC7Lkjdb2sh7M5sq4850Q5TjkRI2Bv0Q=; b=ax9/RawjQYcOkmbfhGnXiqmHm8p5FOOT2oGpR5AYsaNcy+X5wFBq0g8abSxXHmpmTL 5Dfq6vmdzBbVKkusAX14UvPHk/tqe/XFbGrbe4HzzyA1xGk4SplNSvQtxFQf1rWDNbZx d9AfC1gSNjYynUTQ86/duRa4g7lNp88cw+nFnWwzB32knjrjo9m6ewGNzi98fkt4dUFP RhS+FNwX5IjtfFf/5h2KcmP9YyOgfxXp8FvtIwyFxLt/Md/TDfdPpLguIgGtBCsRq/bm //6E6Wtrsoe/unA6j1lfUkasdzHCk8Ykmo606cKAMnhMsUCY117VY7TLa9bXYIpznxaV XLFg== ARC-Authentication-Results: i=1; mx.google.com; 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 r2si11117922eju.410.2021.05.16.05.31.44; Sun, 16 May 2021 05:32:21 -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; 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 S235103AbhEOV0A (ORCPT + 99 others); Sat, 15 May 2021 17:26:00 -0400 Received: from mx2.suse.de ([195.135.220.15]:45974 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229938AbhEOVZ6 (ORCPT ); Sat, 15 May 2021 17:25:58 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 66417AC36; Sat, 15 May 2021 21:24:44 +0000 (UTC) Subject: Re: [PATCH v3] mm, slub: change run-time assertion in kmalloc_index() to compile-time To: Hyeonggon Yoo <42.hyeyoo@gmail.com>, akpm@linux-foundation.org, iamjoonsoo.kim@lge.com, rientjes@google.com, penberg@kernel.org, cl@linux.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, nathan@kernel.org, naresh.kamboju@linaro.org, clang-built-linux@googlegroups.com, linux-next@vger.kernel.org, ndesaulniers@google.com, lkft-triage@lists.linaro.org, sfr@canb.auug.org.au, arnd@arndb.de, Marco Elver References: <20210511173448.GA54466@hyeyoo> <20210515210950.GA52841@hyeyoo> From: Vlastimil Babka Message-ID: <41c65455-a35b-3ad3-54f9-49ca7105bfa9@suse.cz> Date: Sat, 15 May 2021 23:24:25 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: <20210515210950.GA52841@hyeyoo> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/15/21 11:09 PM, Hyeonggon Yoo wrote: > Hello Vlastimil, recently kbuild-all test bot reported compile error on > clang 10.0.1, with defconfig. Hm yes, catching some compiler bug was something that was noted to be possible to happen. > Nathan Chancellor wrote: >> I think this happens because arch_prepare_optimized_kprobe() calls kzalloc() >> with a size of MAX_OPTINSN_SIZE, which is >> >> #define MAX_OPTINSN_SIZE \ >> (((unsigned long)optprobe_template_end - \ >> (unsigned long)optprobe_template_entry) + \ >> MAX_OPTIMIZED_LENGTH + JMP32_INSN_SIZE) > >> and the optprobe_template_{end,entry} are not evaluated as constants. >> >> I am not sure what the solution is. There seem to be a growing list of issues >> with LLVM 10 that were fixed in LLVM 11, which might necessitate requiring >> LLVM 11 and newer to build the kernel, given this affects a defconfig. >> Cheers, >> Nathan > > > I think it's because kmalloc compiles successfully when size is constant, > and kmalloc_index isn't. so I think compiler seems to be confused. > > currently if size is non-constant, kmalloc calls dummy function __kmalloc, > which always returns NULL. That's a misunderstanding. __kmalloc() is not a dummy function, you probably found only the header declaration. > so what about changing kmalloc to do compile-time assertion too, and track > all callers that are calling kmalloc with non-constant argument. kmalloc() is expected to be called with both constant and non-constant size. __builtin_constant_p() is used to determine which implementation to use. One based on kmalloc_index(), other on __kmalloc(). It appears clang 10.0.1 is mistakenly evaluating __builtin_constant_p() as true. Probably something to do with LTO, because MAX_OPTINSN_SIZE seems it could be a "link-time constant". Maybe we could extend Marco Elver's followup patch that uses BUILD_BUG_ON vs BUG() depending on size_is_constant parameter. It could use BUG() also if the compiler is LLVM < 11 or something. What would be the proper code for this condition? > How do you think? If you think it is the solution, I'll do that work. >