Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp500803pxa; Fri, 21 Aug 2020 12:48:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwCqpeDo3zYiznf/VxM3ZUAt5EqIPh9vA0LomUg98zogBvASp9VZiBsoTV3tfhxck3dNIC6 X-Received: by 2002:a05:6402:1845:: with SMTP id v5mr4627911edy.66.1598039284721; Fri, 21 Aug 2020 12:48:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598039284; cv=none; d=google.com; s=arc-20160816; b=zcBXZyiiEkJUWqny4LpAHwPwbVe7OevC/d358vN3K1gmVsT6uIAR91h8m9trTdJu1U DSP1CSFuH3zPr+R5RkNK1JZJUOvrS+vkiMDz5dEWp/E4374Y3hoTDYP1SiehtqB+0DBx AR92YzXsPlVr4tvkp0ML8rts10Z/hcJp5iYhpxpcm44yPa/bNtU91zp7B2XoIe6U0R70 Y8/rS9Hy9P9tOMEXx5GEib44N7SHWfi902238DpoYBHAUKNy+zn9SC+W2abe40bVzauh tuZOEpsCmtPKg9j8jv32cWa66oYIlKEwdj2hS2Da77GMKV5nXgbZV7CWeu5YP56kY9oM 6dDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LhHa8hwizWicyR7AmABsSaI963QK2ejKgNvGzEzQJyI=; b=UWbcSCXYtrcSZrXnuya4FGOgvM0i4dBsqSRIpC9upsRIWMZkAvUirUq3uBgHOT0VLH cB7om5OPytmB+Nt1pqkvHUwL83PGxpIcqZw2usKJm8muG/RdLFDtUQrwwgqttjBYLhIc i7bNx/6zC1K6jqLtrKRgkYr5Pt0APipUqZ6l6y5wV2K7qQrOzSOtdW3j+7DbI+8yo/kb qvgHrF0kMpGaETjvXZ4G5vs+Z/9w/BxDbOJ3vSBUCm89Gqozl1iYLBc9U5OTZOGe+PUh 63Ir2EwOlcHWq6hHN2lDCmAJmB/PU3EuY7ac5ju3BBsjaMORwD5pEtfUbcSUJuyTFRsA Si0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=S9JWqqSo; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i2si2028454ejp.201.2020.08.21.12.47.41; Fri, 21 Aug 2020 12:48:04 -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; dkim=pass header.i=@chromium.org header.s=google header.b=S9JWqqSo; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727043AbgHUTqU (ORCPT + 99 others); Fri, 21 Aug 2020 15:46:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726727AbgHUTob (ORCPT ); Fri, 21 Aug 2020 15:44:31 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 976E1C0617A4 for ; Fri, 21 Aug 2020 12:44:25 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id d4so1245936pjx.5 for ; Fri, 21 Aug 2020 12:44:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LhHa8hwizWicyR7AmABsSaI963QK2ejKgNvGzEzQJyI=; b=S9JWqqSou1s/FK9u3DQ4o9uu0Z66hNrndmRM9lwRys0IRRdCU3reoSB3x/0i4D3/0d FE38SPzh4Sjdcmnpux/wEu2YEvs49KaQ4x96TdKBVxMC1MQo/Pu6aF3uTjn2T4WoNN1/ 69NCo9CYct3Ga+OFZvqV0/uxV0gjNFTPm/uUo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LhHa8hwizWicyR7AmABsSaI963QK2ejKgNvGzEzQJyI=; b=F+sbVotFKhZ+MnTlccLkI9y4uGJ19MytuFr+ayierGFcKpzitczjPziSD2j8/eJ/Rz zbOE/O26jJqFBKS0h0edqP0d24MZf9galup0WrpmrGNTZIYLbBc6/uKuGqu4eiyI1CjJ zZ7BrXVTjOYv7RYvhyjSEiyd+XTzC5E4E21mtOdjVkAo8WewdjRwa+x85IaeXNPeU0vu /UjVSLVFqO0RsEJbbFuRAnYPaF/JhWSe4gdOSUQR10FgBAqSVtDd2rxy8MPcA0rRHG1k +zljYedtLdBfUu/BqLWrcHGivNeXOD2hs+nu/OCONd9c06QpdqHCzA0GtbKdN3ZZFiES NH5g== X-Gm-Message-State: AOAM533djQe749V9WGIikL2JAkXKAKZQX/NMtaF+W4kjuH2wy6JbIhaH MOqtyj2VBwKheAfBYEB+bbUAaQ== X-Received: by 2002:a17:902:b70e:: with SMTP id d14mr3365610pls.253.1598039065065; Fri, 21 Aug 2020 12:44:25 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id a193sm3460814pfa.105.2020.08.21.12.44.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2020 12:44:21 -0700 (PDT) From: Kees Cook To: Ingo Molnar Cc: Kees Cook , Nick Desaulniers , Jian Cai , =?UTF-8?q?F=C4=81ng-ru=C3=AC=20S=C3=B2ng?= , Luis Lozano , Manoj Gupta , stable@vger.kernel.org, Catalin Marinas , Mark Rutland , Ard Biesheuvel , Peter Collingbourne , James Morse , Borislav Petkov , Ingo Molnar , Russell King , Masahiro Yamada , Arvind Sankar , Nathan Chancellor , Arnd Bergmann , x86@kernel.org, clang-built-linux@googlegroups.com, linux-arch@vger.kernel.org, linux-efi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 06/29] vmlinux.lds.h: add PGO and AutoFDO input sections Date: Fri, 21 Aug 2020 12:42:47 -0700 Message-Id: <20200821194310.3089815-7-keescook@chromium.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200821194310.3089815-1-keescook@chromium.org> References: <20200821194310.3089815-1-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nick Desaulniers Basically, consider .text.{hot|unlikely|unknown}.* part of .text, too. When compiling with profiling information (collected via PGO instrumentations or AutoFDO sampling), Clang will separate code into .text.hot, .text.unlikely, or .text.unknown sections based on profiling information. After D79600 (clang-11), these sections will have a trailing `.` suffix, ie. .text.hot., .text.unlikely., .text.unknown.. When using -ffunction-sections together with profiling infomation, either explicitly (FGKASLR) or implicitly (LTO), code may be placed in sections following the convention: .text.hot., .text.unlikely., .text.unknown. where , , and are functions. (This produces one section per function; we generally try to merge these all back via linker script so that we don't have 50k sections). For the above cases, we need to teach our linker scripts that such sections might exist and that we'd explicitly like them grouped together, otherwise we can wind up with code outside of the _stext/_etext boundaries that might not be mapped properly for some architectures, resulting in boot failures. If the linker script is not told about possible input sections, then where the section is placed as output is a heuristic-laiden mess that's non-portable between linkers (ie. BFD and LLD), and has resulted in many hard to debug bugs. Kees Cook is working on cleaning this up by adding --orphan-handling=warn linker flag used in ARCH=powerpc to additional architectures. In the case of linker scripts, borrowing from the Zen of Python: explicit is better than implicit. Also, ld.bfd's internal linker script considers .text.hot AND .text.hot.* to be part of .text, as well as .text.unlikely and .text.unlikely.*. I didn't see support for .text.unknown.*, and didn't see Clang producing such code in our kernel builds, but I see code in LLVM that can produce such section names if profiling information is missing. That may point to a larger issue with generating or collecting profiles, but I would much rather be safe and explicit than have to debug yet another issue related to orphan section placement. Reported-by: Jian Cai Suggested-by: Fāng-ruì Sòng Tested-by: Luis Lozano Tested-by: Manoj Gupta Acked-by: Kees Cook Cc: stable@vger.kernel.org Link: https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=add44f8d5c5c05e08b11e033127a744d61c26aee Link: https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=1de778ed23ce7492c523d5850c6c6dbb34152655 Link: https://reviews.llvm.org/D79600 Link: https://bugs.chromium.org/p/chromium/issues/detail?id=1084760 Debugged-by: Luis Lozano Signed-off-by: Nick Desaulniers Signed-off-by: Kees Cook --- include/asm-generic/vmlinux.lds.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 98d013dcc11a..91dcfb91ac45 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -581,7 +581,10 @@ */ #define TEXT_TEXT \ ALIGN_FUNCTION(); \ - *(.text.hot TEXT_MAIN .text.fixup .text.unlikely) \ + *(.text.hot .text.hot.*) \ + *(TEXT_MAIN .text.fixup) \ + *(.text.unlikely .text.unlikely.*) \ + *(.text.unknown .text.unknown.*) \ NOINSTR_TEXT \ *(.text..refcount) \ *(.ref.text) \ -- 2.25.1