Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp197862iol; Thu, 9 Jun 2022 01:53:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyzaqMNYkFryp0Il+QXodm3AXMT6tHSXqPUuN8kJNy6PShx+URN1zBSmjjzOUQpYrxRwRzI X-Received: by 2002:a17:902:da87:b0:164:395:71d7 with SMTP id j7-20020a170902da8700b00164039571d7mr38642054plx.81.1654764792767; Thu, 09 Jun 2022 01:53:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654764792; cv=none; d=google.com; s=arc-20160816; b=dQI0tSrfuVHTXM4e6TWGbaWyAEyM0zfkFPgrCRwEO/mITfWC/LVy+IU68Qu5wnlD1L Gq17uXI2orYtdoBAkCH3K3yoW3wxalCwJaJWOXKMRbCifQHlY2sImqBH9/c4vARKg98f sVdDPi8AH8loCqFh/kBgHh0SIjB6UcZ3VZP3Dr4yl9SMYyvvqeMtIiv43VpqbJ1v7Eq4 m/J+FJn23JbU2rmV8J1wPOoWHPYDRToCr8keHJ13qDGMBHc8lSDw0ZTLUio7SSE67ewN 0t+plyt576gh4jqbmvfXQ5wB7usA52h1INK4uXsY7SXezSwWxAJoH4QsvEbOEoU6A/gb 2Q+g== 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=kfk3WjPXEkjxxu8199TyQcaEYE4ZTR9Ij1w+1/8nPfw=; b=G+OzaSj8S7iszh93aoFrwZDl5TK8m8DVLaHGZkxm7vyEUavD2GiLM6zPwXYkI2JVVQ WqA6pD/QEUdXDKQghOE6BsY/cUvW58fj6QO5NRjFpyZa/OxERI04xgNAoryNmpmn69OE x36gwvoljl0XPaqucfimklyF78Tcz0mXhH9JQmEet0JSAu5HcRcJLklXxcywd8+w8+4o J6t+50wyFs6Q4vwSZqELstipgAE2K2PgNFccAedCLxbTDLxz0VWcLPLtuwYJamyOXFof QGRlqAO2+pif5dLUO8X7F2ndrlE+fLqGrQqU3IvnLPgLBpz6dOoN4yKULKWzsdYndwPB T6cQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fastly.com header.s=google header.b=LsALkFV6; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fastly.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w204-20020a627bd5000000b0050d4f5ccb83si17429045pfc.311.2022.06.09.01.53.00; Thu, 09 Jun 2022 01:53:12 -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=@fastly.com header.s=google header.b=LsALkFV6; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fastly.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239848AbiFIIDw (ORCPT + 99 others); Thu, 9 Jun 2022 04:03:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238638AbiFIIDs (ORCPT ); Thu, 9 Jun 2022 04:03:48 -0400 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1EE1A454 for ; Thu, 9 Jun 2022 01:03:46 -0700 (PDT) Received: by mail-lj1-x232.google.com with SMTP id l18so17929579lje.13 for ; Thu, 09 Jun 2022 01:03:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=kfk3WjPXEkjxxu8199TyQcaEYE4ZTR9Ij1w+1/8nPfw=; b=LsALkFV6VbtPklOu7SFGbvJSWR0eapJzOWoVO2c8Mytbz4CYteeu9GKfcMSNSkXiDN F7Cgy5hOsIv+hceHHfp4pz4+TtdpwgQU1ZZrHLxz5Ww396C7V0+4gZfML6NiJsXGX0ee JH8ev5P9ETSKfg23MYMZk0+wCfdkXaB6ZdCxA= 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=kfk3WjPXEkjxxu8199TyQcaEYE4ZTR9Ij1w+1/8nPfw=; b=aeN5bNV5sw0fqS8zozv7WcQRCpDa4JhZph0hHhjEb86Yk5uvChR9gRE+HM9byxSFsg GlPiF0qp+X09E0QBFUtNEzAhu2scjn8TaLxTcMgMLdGFGFtej3bjnqUgSLIEKdhjQq+1 WvCUKIoLlFjsOzsfwVk/Voiie72Nwpq4Ey+zFmLlNh3iKaLq/aXWoMjvlP0tSokekton FnnZ6WwOq7nFbFMdHrnCwxe3mZqoxhqISjsiwLaOVT2eOLlaX+UDkF0fjNDrfbkb0zJ5 1OyF7Lo6BesXHh96Tu6zigoJ4cUkxWoRKoYC06dQ0MCCYv2TC6Y6gQuD5DXxUhwvOZdT ksDw== X-Gm-Message-State: AOAM531uL1jNHZs4mD9wiSSo0Gho/YRVLntNJXAxJPFmGcaytof4N17y s/Q0cYkv7IQh8v/Kf39QluA0skrXjyIpfunxvDOrfg== X-Received: by 2002:a2e:b0d6:0:b0:255:7d62:d75c with SMTP id g22-20020a2eb0d6000000b002557d62d75cmr17775894ljl.118.1654761825131; Thu, 09 Jun 2022 01:03:45 -0700 (PDT) MIME-Version: 1.0 References: <22d07a44c80d8e8e1e82b9a806ddc8c6bbb2606e.1654759036.git.jpoimboe@kernel.org> In-Reply-To: <22d07a44c80d8e8e1e82b9a806ddc8c6bbb2606e.1654759036.git.jpoimboe@kernel.org> From: Joe Damato Date: Thu, 9 Jun 2022 11:03:33 +0300 Message-ID: Subject: Re: [PATCH v2] x86/mm: Fix RESERVE_BRK() for older binutils To: Josh Poimboeuf Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Peter Zijlstra , Andrew Cooper , jiangshanlai@gmail.com, bp@suse.de, brgerst@gmail.com, Byungchul Park Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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 On Thu, Jun 09, 2022 at 12:17:32AM -0700, Josh Poimboeuf wrote: > With binutils 2.26, RESERVE_BRK() causes a build failure: > > /tmp/ccnGOKZ5.s: Assembler messages: > /tmp/ccnGOKZ5.s:98: Error: missing ')' > /tmp/ccnGOKZ5.s:98: Error: missing ')' > /tmp/ccnGOKZ5.s:98: Error: missing ')' > /tmp/ccnGOKZ5.s:98: Error: junk at end of line, first unrecognized > character is `U' > > The problem is this line: > > RESERVE_BRK(early_pgt_alloc, INIT_PGT_BUF_SIZE) > > Specifically, the INIT_PGT_BUF_SIZE macro which (via PAGE_SIZE's use > _AC()) has a "1UL", which makes older versions of the assembler unhappy. > Unfortunately the _AC() macro doesn't work for inline asm. > > Inline asm was only needed here to convince the toolchain to add the > STT_NOBITS flag. However, if a C variable is placed in a section whose > name is prefixed with ".bss", GCC and Clang automatically set > STT_NOBITS. In fact, ".bss..page_aligned" already relies on this trick. > > So fix the build failure (and simplify the macro) by allocating the > variable in C. > > Also, add NOLOAD to the ".brk" output section clause in the linker > script. This is a failsafe in case the ".bss" prefix magic trick ever > stops working somehow. If there's a section type mismatch, the GNU > linker will force the ".brk" output section to be STT_NOBITS. The LLVM > linker will fail with a "section type mismatch" error. > > Note this also changes the name of the variable from .brk.##name to > __brk_##name. The variable names aren't actually used anywhere, so it's > harmless. > > Reported-by: Joe Damato > Reported-by: Byungchul Park > Fixes: a1e2c031ec39 ("x86/mm: Simplify RESERVE_BRK()") > Signed-off-by: Josh Poimboeuf > --- > arch/x86/include/asm/setup.h | 38 +++++++++++++++++++---------------- > arch/x86/kernel/setup.c | 5 ----- > arch/x86/kernel/vmlinux.lds.S | 4 ++-- > 3 files changed, 23 insertions(+), 24 deletions(-) > > diff --git a/arch/x86/include/asm/setup.h b/arch/x86/include/asm/setup.h > index 7590ac2570b9..f8b9ee97a891 100644 > --- a/arch/x86/include/asm/setup.h > +++ b/arch/x86/include/asm/setup.h > @@ -108,19 +108,16 @@ extern unsigned long _brk_end; > void *extend_brk(size_t size, size_t align); > > /* > - * Reserve space in the brk section. The name must be unique within the file, > - * and somewhat descriptive. The size is in bytes. > + * Reserve space in the .brk section, which is a block of memory from which the > + * caller is allowed to allocate very early (before even memblock is available) > + * by calling extend_brk(). All allocated memory will be eventually converted > + * to memblock. Any leftover unallocated memory will be freed. > * > - * The allocation is done using inline asm (rather than using a section > - * attribute on a normal variable) in order to allow the use of @nobits, so > - * that it doesn't take up any space in the vmlinux file. > + * The size is in bytes. > */ > -#define RESERVE_BRK(name, size) \ > - asm(".pushsection .brk_reservation,\"aw\",@nobits\n\t" \ > - ".brk." #name ":\n\t" \ > - ".skip " __stringify(size) "\n\t" \ > - ".size .brk." #name ", " __stringify(size) "\n\t" \ > - ".popsection\n\t") > +#define RESERVE_BRK(name, size) \ > + __section(".bss..brk") __aligned(1) __used \ > + static char __brk_##name[size] > > extern void probe_roms(void); > #ifdef __i386__ > @@ -133,12 +130,19 @@ asmlinkage void __init x86_64_start_reservations(char *real_mode_data); > > #endif /* __i386__ */ > #endif /* _SETUP */ > -#else > -#define RESERVE_BRK(name,sz) \ > - .pushsection .brk_reservation,"aw",@nobits; \ > -.brk.name: \ > -1: .skip sz; \ > - .size .brk.name,.-1b; \ > + > +#else /* __ASSEMBLY */ > + > +.macro __RESERVE_BRK name, size > + .pushsection .bss..brk, "aw" > +SYM_DATA_START(__brk_\name) > + .skip \size > +SYM_DATA_END(__brk_\name) > .popsection > +.endm > + > +#define RESERVE_BRK(name, size) __RESERVE_BRK name, size > + > #endif /* __ASSEMBLY__ */ > + > #endif /* _ASM_X86_SETUP_H */ > diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c > index 3ebb85327edb..bd6c6fd373ae 100644 > --- a/arch/x86/kernel/setup.c > +++ b/arch/x86/kernel/setup.c > @@ -67,11 +67,6 @@ RESERVE_BRK(dmi_alloc, 65536); > #endif > > > -/* > - * Range of the BSS area. The size of the BSS area is determined > - * at link time, with RESERVE_BRK() facility reserving additional > - * chunks. > - */ > unsigned long _brk_start = (unsigned long)__brk_base; > unsigned long _brk_end = (unsigned long)__brk_base; > > diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S > index f5f6dc2e8007..81aba718ecd5 100644 > --- a/arch/x86/kernel/vmlinux.lds.S > +++ b/arch/x86/kernel/vmlinux.lds.S > @@ -385,10 +385,10 @@ SECTIONS > __end_of_kernel_reserve = .; > > . = ALIGN(PAGE_SIZE); > - .brk : AT(ADDR(.brk) - LOAD_OFFSET) { > + .brk (NOLOAD) : AT(ADDR(.brk) - LOAD_OFFSET) { > __brk_base = .; > . += 64 * 1024; /* 64k alignment slop space */ > - *(.brk_reservation) /* areas brk users have reserved */ > + *(.bss..brk) /* areas brk users have reserved */ > __brk_limit = .; > } > > -- > 2.34.3 > I applied the v2 patch on top of commit 58f9d52ff689 ("Merge tag 'net-5.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net") and the kernel builds successfully for me. The resulting kernel boots fine on the machine, as well. I built the kernel with: - gcc (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609 - binutils 2.26.1-1ubuntu1~16.04.8+esm1 I have not tested with any other build toolchains. Tested-by: Joe Damato