Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1030570pxj; Sat, 15 May 2021 01:28:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGWjAA7+aFSSWXNdrZ6rzLdRA3DmTZpexgSGQ4e1pKpMYy389QhRhlH65yBFcvK9KYO7cP X-Received: by 2002:a17:907:a06d:: with SMTP id ia13mr18929548ejc.484.1621067316259; Sat, 15 May 2021 01:28:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621067316; cv=none; d=google.com; s=arc-20160816; b=Ek4D6kJ95AIpwB73zbYvP0Lnx9cewqmllw7fa3HwtFDv/xsNKOyqKreEkkzgXfXTwS 2oN4lsMPnbTOsV8r/e1qr/+CToRWX46nKZrxIsd0syIp5W3tAS+hMi5T+8KGsp/Ezoda SXVbd5S5Kc62p1SwhI2kz1Y7rh+dg3kDfs9rFwPj5c6DQxrd+MJ95Vhpy47XygvJjuRX Tvl6Gd/zMDtMDvLYXgboWZHJm0NGWfaZxgcique5iJ8yLYJ8KE/nNT2K3E+xHKNcTIHz +5UScOKGsLNGw/11wUaab8w5U4PYUMEl9gUgk40LGBpuWFr72qPbq6usv0V/7mGh1JGW A7eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=uq/79t1RG8zcVHun9h9a8ABLEBIsZ26OWsg097g0/j4=; b=lEEVdz+7qDzMW/Z5qKZejfYCAAyMWLiVHCors6VMvghHWgS7Xbz6KhDc+ccRxTqVym RuunWwvjPtyk1f8hZtrx61cOWqtqtNxXMSUAKjSIgBt8vgZDx0eGEubWNqXMUJdW1i1G G9NnmhQ6vfMgXd1D3k9YR1IMW6ZNmaCAGEsIM/3Hjoc+jnlx4jFSHvY0W1TJX12pEEDd Uf6T/Y6czBvRpAmqL+piMTWgYxa8QDefeBpG3f7dZB8zo70mC12tSEaFVky5kKwku8Jl rblS/qIZE60YMGMnCDhQ6Uw2gIcs/UJnWs1PU19wW2B7wd3yxo8bz92YMPK2oUosAkma qY4Q== 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 w11si10073471ejc.285.2021.05.15.01.28.13; Sat, 15 May 2021 01:28:36 -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 S230034AbhENUXl (ORCPT + 99 others); Fri, 14 May 2021 16:23:41 -0400 Received: from smtprelay0216.hostedemail.com ([216.40.44.216]:46718 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229819AbhENUXl (ORCPT ); Fri, 14 May 2021 16:23:41 -0400 Received: from smtprelay.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by smtpgrave03.hostedemail.com (Postfix) with ESMTP id D18E318029127 for ; Fri, 14 May 2021 20:22:28 +0000 (UTC) Received: from omf11.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay01.hostedemail.com (Postfix) with ESMTP id E3F25100E7B46; Fri, 14 May 2021 20:22:27 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf11.hostedemail.com (Postfix) with ESMTPA id 7E98D20A29F; Fri, 14 May 2021 20:22:26 +0000 (UTC) Message-ID: <2c95dc4c4347b048abee283be90a9a2ae272ddbe.camel@perches.com> Subject: Re: [PATCH 2/2] x86/e820: Use pr_debug to avoid spamming dmesg log with debug messages From: Joe Perches To: Jason Baron , Heiner Kallweit , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" Cc: Linux Kernel Mailing List Date: Fri, 14 May 2021 13:22:24 -0700 In-Reply-To: References: <6d55670d-2f06-d768-699f-5a79cece6ce0@gmail.com> <59985635-665b-773f-de8f-b15fe3f60196@gmail.com> <1789b1da-7a0f-9fc9-6ed2-ff68e2306342@akamai.com> <204a99e1-de7a-4434-0932-45f1b507e9ec@gmail.com> <5a416031-ddcd-7ef4-ec33-47134bf064bb@akamai.com> <7cc30a8a6644bb60e5f3358e89253d9fc783fe54.camel@perches.com> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.38.1-1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.90 X-Rspamd-Server: rspamout05 X-Rspamd-Queue-Id: 7E98D20A29F X-Stat-Signature: nyuuzrfse7op545gcnddtf6dwk8zcj8p X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX198v5FY8IP2U8cGRMt7u4fROTj75Dg/gUo= X-HE-Tag: 1621023746-893188 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2021-05-14 at 15:56 -0400, Jason Baron wrote: > > On 5/14/21 1:38 PM, Joe Perches wrote: > > On Tue, 2021-05-11 at 17:31 -0400, Jason Baron wrote: > > > > > That said, I do see the value in not having to open code the branch stuff, and > > > making pr_debug() consistent with printk which does return a value. So that > > > makes sense to me. > > > > IMO: printk should not return a value. > > > > Ok, the issue we are trying to resolve is to control whether a 'pr_debug()' statement > is enabled and thus use that to control subsequent output. The proposed patch does: > > > + printed = pr_debug("e820: update [mem %#010Lx-%#010Lx] ", start, end - 1); > + if (printed > 0) { > + e820_print_type(old_type); > + pr_cont(" ==> "); > + e820_print_type(new_type); > + pr_cont("\n"); > + } > > I do think pr_debug() here is different from printk() b/c it can be explicitly > toggled. > > I also suggested an alternative, which is possible with the current code which > is to use DYNAMIC_DEBUG_BRANCH(). > > if (DYNAMIC_DEBUG_BRANCH(e820_debg)) { > ????printk(KERN_DEBUG "e820: update [mem %#010Lx-%#010Lx] ", start, end - 1); > ????e820_print_type(old_type); > ????pr_cont(" ==> "); > ????e820_print_type(new_type); > ????pr_cont("\n"); > } > > That however does require one to do something like this first: > > DEFINE_DYNAMIC_DEBUG_METADATA(e820_dbg, "e820 verbose mode"); > > So I don't feel too strongly either way, but maybe others do? Why not avoid the problem by using temporaries on the stack and not use pr_cont altogether? --- arch/x86/kernel/e820.c | 71 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 25 deletions(-) diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c index bc0657f0deed..a6e7ab4b522b 100644 --- a/arch/x86/kernel/e820.c +++ b/arch/x86/kernel/e820.c @@ -184,20 +184,38 @@ void __init e820__range_add(u64 start, u64 size, enum e820_type type) __e820__range_add(e820_table, start, size, type); } -static void __init e820_print_type(enum e820_type type) +static char * __init e820_fmt_type(enum e820_type type, char *buf, size_t size) { switch (type) { - case E820_TYPE_RAM: /* Fall through: */ - case E820_TYPE_RESERVED_KERN: pr_cont("usable"); break; - case E820_TYPE_RESERVED: pr_cont("reserved"); break; - case E820_TYPE_SOFT_RESERVED: pr_cont("soft reserved"); break; - case E820_TYPE_ACPI: pr_cont("ACPI data"); break; - case E820_TYPE_NVS: pr_cont("ACPI NVS"); break; - case E820_TYPE_UNUSABLE: pr_cont("unusable"); break; - case E820_TYPE_PMEM: /* Fall through: */ - case E820_TYPE_PRAM: pr_cont("persistent (type %u)", type); break; - default: pr_cont("type %u", type); break; + case E820_TYPE_RAM: + case E820_TYPE_RESERVED_KERN: + strscpy(buf, "usable", size); + break; + case E820_TYPE_RESERVED: + strscpy(buf, "reserved", size); + break; + case E820_TYPE_SOFT_RESERVED: + strscpy(buf, "soft reserved", size); + break; + case E820_TYPE_ACPI: + strscpy(buf, "ACPI data", size); + break; + case E820_TYPE_NVS: + strscpy(buf, "ACPI NVS", size); + break; + case E820_TYPE_UNUSABLE: + strscpy(buf, "unusable", size); + break; + case E820_TYPE_PMEM: + case E820_TYPE_PRAM: + scnprintf(buf, size, "persistent (type %u)", type); + break; + default: + scnprintf(buf, size, "type %u", type); + break; } + + return buf; } void __init e820__print_table(char *who) @@ -205,13 +223,14 @@ void __init e820__print_table(char *who) int i; for (i = 0; i < e820_table->nr_entries; i++) { - pr_info("%s: [mem %#018Lx-%#018Lx] ", + char type[32]; + + pr_info("%s: [mem %#018Lx-%#018Lx] %s\n", who, e820_table->entries[i].addr, - e820_table->entries[i].addr + e820_table->entries[i].size - 1); - - e820_print_type(e820_table->entries[i].type); - pr_cont("\n"); + e820_table->entries[i].addr + e820_table->entries[i].size - 1, + e820_fmt_type(e820_table->entries[i].type, + type, sizeof(type))); } } @@ -465,6 +484,8 @@ __e820__range_update(struct e820_table *table, u64 start, u64 size, enum e820_ty u64 end; unsigned int i; u64 real_updated_size = 0; + char type1[32]; + char type2[32]; BUG_ON(old_type == new_type); @@ -472,11 +493,10 @@ __e820__range_update(struct e820_table *table, u64 start, u64 size, enum e820_ty size = ULLONG_MAX - start; end = start + size; - printk(KERN_DEBUG "e820: update [mem %#010Lx-%#010Lx] ", start, end - 1); - e820_print_type(old_type); - pr_cont(" ==> "); - e820_print_type(new_type); - pr_cont("\n"); + printk(KERN_DEBUG "e820: update [mem %#010Lx-%#010Lx] %s ==> %s\n", + start, end - 1, + e820_fmt_type(old_type, type1, sizeof(type1)), + e820_fmt_type(new_type, type2, sizeof(type2))); for (i = 0; i < table->nr_entries; i++) { struct e820_entry *entry = &table->entries[i]; @@ -543,15 +563,16 @@ u64 __init e820__range_remove(u64 start, u64 size, enum e820_type old_type, bool int i; u64 end; u64 real_removed_size = 0; + char type[32]; if (size > (ULLONG_MAX - start)) size = ULLONG_MAX - start; end = start + size; - printk(KERN_DEBUG "e820: remove [mem %#010Lx-%#010Lx] ", start, end - 1); - if (check_type) - e820_print_type(old_type); - pr_cont("\n"); + printk(KERN_DEBUG "e820: remove [mem %#010Lx-%#010Lx]%s%s\n", + start, end - 1, + check_type ? " " : "", + check_type ? e820_fmt_type(old_type, type, sizeof(type)) : ""); for (i = 0; i < e820_table->nr_entries; i++) { struct e820_entry *entry = &e820_table->entries[i];