From patchwork Fri Jul 31 23:07:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 247301 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp3726897ilg; Fri, 31 Jul 2020 16:08:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzq+XTvbD6IeKlwQ8j4D590vPCUTC7Hm9ykFbE8DMtf6EpOHldN68QjXMJi6/55Lf1Ajd6z X-Received: by 2002:a50:d75e:: with SMTP id i30mr6286264edj.246.1596236928833; Fri, 31 Jul 2020 16:08:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596236928; cv=none; d=google.com; s=arc-20160816; b=u0UrWGrV0Fx9UOM00PLiUQ98gKC7Rwuz2HF89cVVr7WAkooitaPuUhbk1y4gcc6owW 49ucQXjzfTe+C//G5xf+5nkz0nqhT2Qv34uMFoc6l8ubsV4VSYdFw/zdMLjXtLE7fjfV pkT+gtvwEgof5uPiU4ljQwEZrLOfeFMmFxlLLNXNe+9a8nieOgXiQjnyHuSYbL/5m4wh v3c0uQcvuTDeBr2eYBz1l8uOUld/tuvfiLumV5bTLvdastj3ni0Lsu0+ZnA53nCutbw5 61ZBLLs/FEUjQf0yWRMtiGsKnHBw9sIE8iK6GtwAK+k2DeiZQB5v2l1r4gPmGz2HK8GX TVpg== 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=wsZ5gbKBfJpS0kEAhEgSsyY+vol7k0zdc2IVxjvZo+s=; b=dB7a/v1qUa8zQbDtQ5a3DEVYT1Vp26AUAKii8R6TF+Lp4sgTIsVhN1Ct+K/7M8lMIl G9C3wft4UDqjMKF/1aOzFzD4bfw5Nz1HeEJOK/8KeAJj6cZMfVDfGtPBPma53aAVU+4l aCbJNu1Gi5Foe6mw/g1VdG7gWRBNxYid3Nvq3nn5Sr2gJTbIN86OVSMi865J8sqxRoHR BTrtgJenV+N2PUW6BFLd2wqznJ89F7DZLQy8HOtcfGOoooI8ftFp6A+LfJQIgwblgbWw EtenUHINj7zNRF+iEHTOHSMB2b9rtK5jRpWWeDHBZM1QV3J/nkpwxlPuFD2BtmakcHyF eZ9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=IPdfxoRv; spf=pass (google.com: domain of linux-efi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-efi-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 x4si5771010eju.496.2020.07.31.16.08.48; Fri, 31 Jul 2020 16:08:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-efi-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=IPdfxoRv; spf=pass (google.com: domain of linux-efi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-efi-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 S1727098AbgGaXIr (ORCPT + 2 others); Fri, 31 Jul 2020 19:08:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727878AbgGaXIp (ORCPT ); Fri, 31 Jul 2020 19:08:45 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2771FC0617A2 for ; Fri, 31 Jul 2020 16:08:45 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id s15so5237216pgc.8 for ; Fri, 31 Jul 2020 16:08:45 -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=wsZ5gbKBfJpS0kEAhEgSsyY+vol7k0zdc2IVxjvZo+s=; b=IPdfxoRvS6R1x5paoBrA7xxYsYLtGQVxRFU7dvuKabenpplKg1IEjvbhFySTmU+Zh2 pNWc8NWMXSOA09JW8gD/0su2yMzSuM6k8hmeNUhvpGyiw2SmpiBLNR4PFrXPpgojBRMR hbzjAFfKzFOv7KayapCPYkLupuCPvPBt2/X9g= 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=wsZ5gbKBfJpS0kEAhEgSsyY+vol7k0zdc2IVxjvZo+s=; b=iNxxPQCX3yiDhRqRs/o6JhmsSero9ja5EMGYrQ+nR6G85iB8jeli6ZVDNyXJlHh2uC LEWYulp3U4xe/wufdYlK+ksJaJjmp0Ub0nS/4igj/z6l/oh6rXW9e4zL6sIhd42wfHah 5N/WRLcAcGS60UoGPy9qrGRiLMkN5uJ5ggCXFAzgwKEm9KGY+bySsLrHymKSVUicH+V7 F6604fZ4OpgBxu2te+NG8inqoYFipczOjt2vlsMS8/ARTRCeXcSqAEf8uJapD8BxSLJy D9CoIdnyqIaKkNXTWIFQigsYtFdyGUOz4quRU9JD4c/6t1rT2/EnI4F93712e+y7+Hqr ePLA== X-Gm-Message-State: AOAM533EL7hoB//WNI+4WTwx+dU5jINaNYEXuDnBWLZWqMZ93G4doByi ZcG2xQJYa7DGkGpRn6sogaBADA== X-Received: by 2002:a63:9246:: with SMTP id s6mr5522207pgn.22.1596236924597; Fri, 31 Jul 2020 16:08:44 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id x9sm10524734pgr.57.2020.07.31.16.08.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2020 16:08:39 -0700 (PDT) From: Kees Cook To: Thomas Gleixner , Will Deacon Cc: Kees Cook , Nick Desaulniers , Jian Cai , =?utf-8?b?RsSBbmctcnXDrCBTw7Ju?= =?utf-8?q?g?= , 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 v5 13/36] vmlinux.lds.h: add PGO and AutoFDO input sections Date: Fri, 31 Jul 2020 16:07:57 -0700 Message-Id: <20200731230820.1742553-14-keescook@chromium.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200731230820.1742553-1-keescook@chromium.org> References: <20200731230820.1742553-1-keescook@chromium.org> MIME-Version: 1.0 Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@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(-) -- 2.25.1 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 2593957f6e8b..af5211ca857c 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -561,7 +561,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) \