Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2361770iog; Sun, 26 Jun 2022 13:50:27 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u/Ka8f0Lb9vbXwjM3cmunoglptlHDHo2J7upJjAjYtVDpPs9H3DERU+KLLCZwvP0JQyCcu X-Received: by 2002:a17:906:14d:b0:711:ff36:b1af with SMTP id 13-20020a170906014d00b00711ff36b1afmr9624651ejh.422.1656276627270; Sun, 26 Jun 2022 13:50:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656276627; cv=none; d=google.com; s=arc-20160816; b=SMtrHtEsbzWhnhv8Jexr8tK7OvgeCPyvyROqqgS/Jl6WNEGuF4DT8ZdwdaglsiMHN5 0hkIhQguzTJFi0ukW4EEBzcHMTgetHnZ0Cxh0aZVbu9rhZCfjPKkhsANxEnE3l15wmVD nT+1SbxTIE4yet/KakKLLIz8jJHwkqRXDEELMi41/3FFWfqcLFMolOGvJrx3iayUiwKD Y0EXoNW0lJ7aeWVIlUzdRx9IJGNcMKOCT6aDz7Ic/Nzhjj5jnv8mV7+N/LSKQ3tc07JD 9TR76Hp9xOtYDyOhNMjCP1Ot41xFUvnuGdDwNFlpzj79kn4Rw04+LtflfWYcMxEXM4xY 33Eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=nu9/GNmE/6Ec+yjhAIVpoKG+URCXP5VRgR+sJEJG8es=; b=g/VxebnmDDekoAhp76+9qXPiQZd0b716iJeYMYtVZBHGMse2cR88C9pwQ7C93xjS48 0Mox9w1XFfaMFIB9o754SJFDA966gqL8i7dHqVn9u/JO9MKj+LAI6sIVN23B7cmrqS4P y8LP9mdK/CyMAgKxbhiXQDmOLW31psgM0rh56avy5tcqvuvao4TlPVz2J00NSA6OfYqY br9dM8HIH6lndFL1zi/ngpxxicneYlABbbPzRGl5chdJFZeggp1QGf7jeROY/9j3U3KN Qfupf7OVLemEPVYjAbj8i2pduTnwSa9HwGhNiMladqM/a7k4p6VEP1X4U5uSlYb8jAtK YVuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=GS6ies+w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u18-20020a50a412000000b00435ccbb2a3dsi11392112edb.334.2022.06.26.13.49.59; Sun, 26 Jun 2022 13:50:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=GS6ies+w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231514AbiFZUTo (ORCPT + 99 others); Sun, 26 Jun 2022 16:19:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229955AbiFZUTm (ORCPT ); Sun, 26 Jun 2022 16:19:42 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9814EEA8 for ; Sun, 26 Jun 2022 13:19:41 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id sb34so14946766ejc.11 for ; Sun, 26 Jun 2022 13:19:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=nu9/GNmE/6Ec+yjhAIVpoKG+URCXP5VRgR+sJEJG8es=; b=GS6ies+w8dks9EOoUgtl81vz5KmxCBNl3MtTNDunbS5G09OfLVE9+pe01sIcgRSP7j y2J+Vbd+0ANVyGZFeU9/mcuuqzKgarpxGzeqzj4N4+QeDP5xIp9KeumK23Th9eQALYwY J7gFRWMFWHj8uHEIQIbQ+W5/Q2J/F6JU3i8qs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=nu9/GNmE/6Ec+yjhAIVpoKG+URCXP5VRgR+sJEJG8es=; b=BiTheDpoRCESFJZORJqcVg0uf+ZbC7aoqBcz67SykDx7rTuNItPWMFxL9oF4spbJEb 2KtFvOybiF38ks+5EZ51+2d5bRBFZh0sHP58cOLvx4uDOt2jRvNuuuFJUSXKyGczWB/j atKF+G8ppvLNMNU2jmt7YuUv04Ft06sdi+KMVyQu+AdHZM17zGentrx+y+tHpaqDxAbm WaL6/hNaxLBgDw9f+H4xP2IaIrt+y7ygvb+QcHch3BymwgeBn8ZFHfBUMduhjBQqSw26 J8RqG/MHDyFWnqFIuPpQrNDG0nS0VXbA85RiMq4DFLg6CKOkBo89AKwz34KNTZqZwi+Z 6r8w== X-Gm-Message-State: AJIora9gqwpSSb18pERxKBjKzxjm2kfa8p5f8lTGs9Whd8VpWYRnEEoh lDh0pLS9X58tLRxif+hs56ZfIev6KM/2pqDf X-Received: by 2002:a17:907:6e06:b0:726:29f0:78d5 with SMTP id sd6-20020a1709076e0600b0072629f078d5mr9622225ejc.186.1656274779880; Sun, 26 Jun 2022 13:19:39 -0700 (PDT) Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com. [209.85.128.48]) by smtp.gmail.com with ESMTPSA id bl24-20020a170906c25800b00704757b1debsm4105751ejb.9.2022.06.26.13.19.38 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 26 Jun 2022 13:19:38 -0700 (PDT) Received: by mail-wm1-f48.google.com with SMTP id h14-20020a1ccc0e000000b0039eff745c53so4418747wmb.5 for ; Sun, 26 Jun 2022 13:19:38 -0700 (PDT) X-Received: by 2002:a05:600c:681:b0:3a0:2da6:d173 with SMTP id a1-20020a05600c068100b003a02da6d173mr15926468wmn.68.1656274777880; Sun, 26 Jun 2022 13:19:37 -0700 (PDT) MIME-Version: 1.0 References: <20220620004233.3805-1-kent.overstreet@gmail.com> <0a5901f8460f452a89c9b0cda32fb833@AcuMS.aculab.com> <20220620150514.3tjy5dv7pv5frcwd@moria.home.lan> <53d77ae6101a0f24cfb694174d4c7699424c57e8.camel@perches.com> <20220621005752.ohiq5besmy3r5rjo@moria.home.lan> <355e912490dbaef8fe4e12df0201c3f5b439565d.camel@perches.com> In-Reply-To: <355e912490dbaef8fe4e12df0201c3f5b439565d.camel@perches.com> From: Linus Torvalds Date: Sun, 26 Jun 2022 13:19:21 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC[ Alloc in vsprintf To: Joe Perches Cc: Andrew Morton , David Laight , Petr Mladek , Steven Rostedt , Sergey Senozhatsky , Rasmus Villemoes , Matthew Wilcox , Miguel Ojeda , Kent Overstreet , Andy Shevchenko , LKML , linux-mm Content-Type: multipart/mixed; boundary="000000000000c9d81005e25f851c" X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --000000000000c9d81005e25f851c Content-Type: text/plain; charset="UTF-8" On Sun, Jun 26, 2022 at 12:53 PM Joe Perches wrote: > > In a reply to the printbufs thread, I wrote a proposal to use an > alloc to reduce stack in vsprintf when CONFIG_KALLSYMS is enabled. > > No one has replied to this but I think it's somewhat sensible. I think that's a bad idea. Those things are *literally* called from panic situations, which may be while holding core memory allocation locks, or similar. The last thing we want to do is make a hard-to-debug panic be even *harder* to debug because you get a deadlock when oopsing. (And yes, I realize that the symbol name lookup can have problems too, but thats' kind of fundamental to %pS, while a kzmalloc isn't. Now, you are correct that the stack buffer is annoying. But I think the proper way to fix that is to say "we already *have* the target buffer, let's use it". That does require teaching the sprint_symbol() functions that they need to take a "length of buffer" and return how much they used, but that would seem to be a sensible thing anyway, and what the code should always have done? It's bad policy to just pass in a buffer without length, and I think it was always broken. Nasty. That KSYM_SYMBOL_LEN is magically taking care of it all, but it's ugly as heck, wouldn't you say? NOTE! The attached patch is completely broken. I did not do that interface change to the kallsyms code. The patch is literally meant to be just an explanation of what I mean, not a working patch. Linus --000000000000c9d81005e25f851c Content-Type: text/x-patch; charset="US-ASCII"; name="patch.diff" Content-Disposition: attachment; filename="patch.diff" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_l4vr87ma0 IGxpYi92c3ByaW50Zi5jIHwgMTggKysrKysrKysrKystLS0tLS0tCiAxIGZpbGUgY2hhbmdlZCwg MTEgaW5zZXJ0aW9ucygrKSwgNyBkZWxldGlvbnMoLSkKCmRpZmYgLS1naXQgYS9saWIvdnNwcmlu dGYuYyBiL2xpYi92c3ByaW50Zi5jCmluZGV4IDNjMTg1M2E5ZDFjMC4uMDMyZmE4YmM1NzUyIDEw MDY0NAotLS0gYS9saWIvdnNwcmludGYuYworKysgYi9saWIvdnNwcmludGYuYwpAQCAtOTgxLDcg Kzk4MSw3IEBAIGNoYXIgKnN5bWJvbF9zdHJpbmcoY2hhciAqYnVmLCBjaGFyICplbmQsIHZvaWQg KnB0ciwKIHsKIAl1bnNpZ25lZCBsb25nIHZhbHVlOwogI2lmZGVmIENPTkZJR19L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