From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 495892038CF for ; Tue, 12 Nov 2024 05:39:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731389953; cv=none; b=qry88Hrb/pRJJ5H5QXN3xSE5ECH2onlLL5i7ZpIdfMZ82VLo88bu0/q/M9gdsuIgNLsnrz4slDVKiS6d3reRIMEAiyO1Ii+C4sk5ajhaybBhs/aAFajsUGXMkMlYUy6IEuA/K0QeW43D6wB3WfPhrOKhqky3MNdQMZqqqWBmb70= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731389953; c=relaxed/simple; bh=uPqiSb8byFUHmsowxYv/8nM0c5ourBGwRMRpZWMY6HE=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=plWa3NEC7dbFYzJd4LiOoQ/4Tf+NSk2qlTvVymbLp1/NLHbcU5px/VG0zeFMiOg5z8c29KYBW5j/RTjwtPJysrytlLLbDqCjB2/GTOAd0G/2Uk8gaHv9W5CVE+DP5XRqKGwySunSRgFNLFyCr5h0dtknAqZia475ztLLbJbvfPQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=qH4ebDfP; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="qH4ebDfP" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-20c87b0332cso76655ad.1 for ; Mon, 11 Nov 2024 21:39:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731389950; x=1731994750; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=55eFBaAwUzqb5NuE4EUBIHlElwP7vcU1g64jX0opSSs=; b=qH4ebDfP6ijqYgnuViO6dxQZ1g5HT0JMc6WfG7oeyAReFbvJmPewjIBI8zXgjP12n+ 4hR9BaHgXwuLNsunJ7vWkt0k/ogRKxc3zsmX7NVYWuYuZ2JaIM5aLJPd8D78F7JSBQ2X MM1Ns9wop/HsMXVq6O3WgJwiLbvoHYqY74xSb2TO9FPOUZ9Q1bXtHQAB73/he06JPma9 BznC2rCQHEHPJtyUtzRUkYwsf5GpSMDYQeIN2RHOlhciQVSTVJPAAOYyyEEuP2iFV/XK 1Gd67jbVXblgwcBEyxfrMjiwPyPwPFoNGeoiFcD6BArPXaHGzD7GNKr2grz5bmSL51uP VjzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731389950; x=1731994750; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=55eFBaAwUzqb5NuE4EUBIHlElwP7vcU1g64jX0opSSs=; b=g0Sga7laAudyayXBj50VrCf8pk/VOwQKwNc979TJ5ZFF+aBFXF49UxPsZWS+0546Sf WGW3my5X/6vUNq88DYkAqTkNNyndyErcIL1S6CETg8b9oECF4EnlJFtRNv4ge2BrqZMx ikOSGlFvB9H1qRvNFmwHbwKhPRdMeSZF6jcijFBtUzxAMhT8hufU//Vx6kAHhFrLT8iQ eLjupzfbJ4hpl2FXvEoTE8yudCCePXDCYSji0Abuh3405InvMQu2t755BQQpGT+MDR7J 2HFEL3AvDZrh6l6/3Qp41ePaHAKaGVqAgnsfuBMyOU2AKXtjZchwSPqc0X2OvJ4ER5Xr mijA== X-Forwarded-Encrypted: i=1; AJvYcCWt7CQqTSqPaGZTb7JOgYOM3YEfu/KO2f2Y3jpUAjowCHDRxxFYv0LfR7JlgpBZjqBOimi/Qm2CuyI=@vger.kernel.org X-Gm-Message-State: AOJu0YycseG01PDEE0CbdAGGTlBEvKIRbkv5ep+YudJBKDB9hmmGgr7i LEENCP6ESWaU6IUbfa71f2zruUuhuXgMzsWJlphK/UHkYdrwueO5tun89PrDq5dypVy1hcmB0Wb WgNYnimV/4gdq3KWKQv+EAkJY+Zd2cSj2hV5y X-Gm-Gg: ASbGncvxFX++/PEMUTLdVfdvKLyfKHSEUHGtnNP+EppobuEIcgC1eCYZgw8EMuJGJG+ gATyPYkUWI6kbA5uyhfeoYHXpYouV7Mc9IsRH77zl8GCgV2glbVhnc6XGILM= X-Google-Smtp-Source: AGHT+IFsphJ8eFdvWIvqWQJAgfm/UGMVMERlMSqtsqzVfe10VnOKJwtxRF+0T1N3Dqc2Vm4wT9mbQhx6mGE7tRGz4Fc= X-Received: by 2002:a17:902:d2cc:b0:1fc:548f:6533 with SMTP id d9443c01a7336-211ace77d55mr809315ad.3.1731389949340; Mon, 11 Nov 2024 21:39:09 -0800 (PST) Precedence: bulk X-Mailing-List: workflows@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20241026051410.2819338-1-xur@google.com> <20241026051410.2819338-4-xur@google.com> <44193ca7-9d31-4b58-99cc-3300a6ad5289@gmail.com> In-Reply-To: From: Rong Xu Date: Mon, 11 Nov 2024 21:38:57 -0800 Message-ID: Subject: Re: [PATCH v6 3/7] Adjust symbol ordering in text output section To: Klara Modin Cc: Alice Ryhl , Andrew Morton , Arnd Bergmann , Bill Wendling , Borislav Petkov , Breno Leitao , Brian Gerst , Dave Hansen , David Li , Han Shen , Heiko Carstens , "H. Peter Anvin" , Ingo Molnar , Jann Horn , Jonathan Corbet , Josh Poimboeuf , Juergen Gross , Justin Stitt , Kees Cook , Masahiro Yamada , "Mike Rapoport (IBM)" , Nathan Chancellor , Nick Desaulniers , Nicolas Schier , "Paul E. McKenney" , Peter Zijlstra , Sami Tolvanen , Thomas Gleixner , Wei Yang , workflows@vger.kernel.org, Miguel Ojeda , Maksim Panchenko , "David S. Miller" , Andreas Larsson , Yonghong Song , Yabin Cui , Krzysztof Pszeniczny , Sriraman Tallam , Stephane Eranian , x86@kernel.org, linux-arch@vger.kernel.org, sparclinux@vger.kernel.org, linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I compared the System.map files from Klara Modin. The linker script is doing what I expected: relocating the unlikely executed functions to the beginning of the .text section. However, the problem is with the _stext symbol. It belongs to the .text section, so it is positioned after the unlikely (or hot) functions. But it really needs to be the start of the text section. I checked all vmlinux.lds.S in arch/, I found that most archs explicitly assign _stext to the same address as _text, with the following 3 exceptions: arch/sh/kernel/vmlinux.lds.S arch/mips/kernel/vmlinux.lds.S arch/sparc/kernel/vmlinux.lds.S Note that we already partially handled arch/sparc/kernel/vmlinux.lds.S for sparc64. But we need to handle sparc32 also. Additionally, the boot/compressed/vmlinux.lds.S also the TEXT_TEXT template. However, I presume these files do not generate the .text.unlikely. or .text.hot.* sections. I sent the following patch to Klara because I don't have an environment to build and test. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.= S index 9ff55cb80a64..5f130af44247 100644 --- a/arch/mips/kernel/vmlinux.lds.S +++ b/arch/mips/kernel/vmlinux.lds.S @@ -61,6 +61,7 @@ SECTIONS /* read-only */ _text =3D .; /* Text and read-only data */ .text : { + _stext =3D .; TEXT_TEXT SCHED_TEXT LOCK_TEXT =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D If Klara confirms the fix, I will send the patch for review. Thanks, -Rong On Mon, Nov 11, 2024 at 2:39=E2=80=AFPM Rong Xu wrote: > > In the new System.map, we have: > ffffffff81112400 T _stext > > This looks wrong. It should point to the beginning of the text, like > ffffffff81100400 T _stext > > I'll do some debugging on this. > > -Rong > > On Mon, Nov 11, 2024 at 1:32=E2=80=AFPM Klara Modin wrote: > > > > On 2024-11-11 21:43, Rong Xu wrote: > > > Thanks for reporting this issue! > > > > > > I'm assuming your kernel build enables dead code elimination and > > > uses the --ffunction-sections compiler flag. Without this patch, all > > > the functions > > > -- I think there are only .text.unlikely.* and .text.* are grouped > > > together in the > > > final vmlinux. This patch modifies the linker script to place > > > .text.unlikely.* functions > > > before .text.* functions. I've examined arch/mips/kernel/vmlinux.ld= s.S, and > > > haven't found any obvious issue. > > > > > > Can you send me the following? > > > (1) the kernel build command > > > (2) System.map without the patch > > > (3) System.map with the patch > > > > > > Best regards, > > > > > > -Rong > > > > > I don't set -ffunction-sections explicitly but it seems to be used when > > I look at the .cmd files. The build command is nothing fancy, I just se= t > > ARCH=3Dmips CROSS_COMPILE=3Dmips64-unknown-linux-gnuabin32- and build w= ith > > make -j24. > > > > I've attached the System.map, built on next-20241111 as well as it with > > this series reverted. > > > > Regards, > > Klara Modin