From patchwork Mon Jul 22 21:32:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 169428 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp8005555ilk; Mon, 22 Jul 2019 14:33:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqzTQHcyTo73/G1koXgbZpEIYNAniakOrrCz8irMwDW6DBgsHoQvckC7BdgUsw3A7aTNmMPr X-Received: by 2002:a63:2744:: with SMTP id n65mr60351044pgn.277.1563831222072; Mon, 22 Jul 2019 14:33:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563831222; cv=none; d=google.com; s=arc-20160816; b=q2uK6z4I6Y9Tn67bcGHPGcPKYgFIKZp+r8/oa4vaJ/VBMMxTv3G7/vCQxI9YgHbrxt Kp8zkrQXCXiUKeNRLFP61Wpgg2rynmFMAO0cU3u/VWq1vo4Kat0ZaA/4/cHgjv/SRs4l G+Wx6OVPgIFgjcFmo39oDMBe9P80i8PuJ2IoEAEg3Z7CuVZOr4Cx8P4yi91jy30mBSZD ln7VPm0+OR0g6G8r0Al1XwfN3yxhXpd217dgn6/buzGJbQPB/yVb945xVh3ShCWWgXbV V3LrxjVA2H0KwFVRXHgafKeN5QmzahVNwz8yLVsEpGAC/873/0yLgVWcOa9Aa1OubqgS SV1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature; bh=rVOg24+M5qJa9OkZXsdMYSLJniYg2tsuNVu94YuzcEo=; b=KZZ2fowLO4/1d95X9PdsZ1qDL+NyBIseK2P41DX5nsPZFCPlHr0GSVdh/S0YBZXwBu USmenqQLwU1BBePuC0gWQsYCEcgnfdIl8mwq1PBMbYlhXt+JUlejaJm643N/9pV3T5et ELRU0KE2nEwx88C/ELJ+vvnIkIuRsWF79944HL07S/K5XmXuOlFURlZwAGIVEirdXVD9 OXN7yOBTAUtYhfufhwTxMH4fInsJDNRf7k/KXSqMGZD3oxhtLMvtgOIS0dzEggG317E7 wlGMxkYDazzy3tlZMAMBsjJz2WC13I2EQMoXAN6oL6bs1u7f7lp5UQ2h1NKRRbpWaUWU i2Yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Afs+F9ie; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a89si11507053pla.60.2019.07.22.14.33.41; Mon, 22 Jul 2019 14:33:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Afs+F9ie; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732746AbfGVVdk (ORCPT + 29 others); Mon, 22 Jul 2019 17:33:40 -0400 Received: from mail-pl1-f201.google.com ([209.85.214.201]:54458 "EHLO mail-pl1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729004AbfGVVdk (ORCPT ); Mon, 22 Jul 2019 17:33:40 -0400 Received: by mail-pl1-f201.google.com with SMTP id u10so20606940plq.21 for ; Mon, 22 Jul 2019 14:33:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=rVOg24+M5qJa9OkZXsdMYSLJniYg2tsuNVu94YuzcEo=; b=Afs+F9ieOa/EPV1dzQyvuiFqLf2MUxuSTxxTY5avgW5jl0yYZ3oLeorckrrFuUDbHK UJ64F4gEzWc6mUvllYnymQLfp2a9+3XmoFawqasnXzeWbE9itSbdrmIDjZI71kY26zTg bXOKJ8HNTUIVcm8Eipi+ugx0PEg3c/1eQ0dBLu4bHy7VpwSegvZCMW4IBtdyKt+ieIbS L/s8bfV/CkShj/5CgmrKlr8hoOBRBJzB+ISlEcxgZAA4RZqk0ByEcemfVkQBkkoHLZWy UwyMvWq2sW9LXZp5bUCdhhhu1tPcmLjaNWMZOyg5Jhf0ATcwihm2XMmY6nX2+0N0xzzD RRPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=rVOg24+M5qJa9OkZXsdMYSLJniYg2tsuNVu94YuzcEo=; b=S0pNSxC+W2lkThWxG7lno3mCKL1/Ze4CGEcUnKbnkdtWfqQ8zS3HuQTL48jJJQAzeT kss3cyS17Cpz0YJcs7u5FaIPC/Bq59JYiGafJvXfzcdbeLdLGwBKCnufRjDdhcySsiXX uNJg39HWkUb4qJMcpXhFcv0PIHGNMdLoH8OWQoYN2z5+rnl6o6djBq1UJKkqfCKyAjmj 0qxz+U+hat7lg6Pu4pG+Mn2+L4w1hOTUm2qMit+pMtYIEvrQtppFgEhG6KXIypZzJRww XRyZJrAvISvffFkvPuCMiEHvEKqDPrKtuOJnHZ0aSS/Mr2PMReagz9kqw3G+lQmnwwEh +Jpw== X-Gm-Message-State: APjAAAWtihpKPM8d9CmvyQhKHRhyd1geRhPw1Yhssh7Lrq9tyY/fgegO pbSCFY3G7GFVGc1/RazGlB6qc8ijOb+Y6O5y1vY= X-Received: by 2002:a63:724f:: with SMTP id c15mr75142798pgn.257.1563831218735; Mon, 22 Jul 2019 14:33:38 -0700 (PDT) Date: Mon, 22 Jul 2019 14:32:44 -0700 Message-Id: <20190722213250.238685-1-ndesaulniers@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.22.0.657.g960e92d24f-goog Subject: [PATCH v2 1/2] x86/purgatory: do not use __builtin_memcpy and __builtin_memset From: Nick Desaulniers To: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de Cc: peterz@infradead.org, clang-built-linux@googlegroups.com, Nick Desaulniers , Vaibhav Rustagi , Manoj Gupta , Alistair Delva , "H. Peter Anvin" , x86@kernel.org, Allison Randal , Alexios Zavras , Enrico Weigelt , Greg Kroah-Hartman , linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Implementing memcpy and memset in terms of __builtin_memcpy and __builtin_memset is problematic. GCC at -O2 will replace calls to the builtins with calls to memcpy and memset (but will generate an inline implementation at -Os). Clang will replace the builtins with these calls regardless of optimization level. $ llvm-objdump -dr arch/x86/purgatory/string.o | tail 0000000000000339 memcpy: 339: 48 b8 00 00 00 00 00 00 00 00 movabsq $0, %rax 000000000000033b: R_X86_64_64 memcpy 343: ff e0 jmpq *%rax 0000000000000345 memset: 345: 48 b8 00 00 00 00 00 00 00 00 movabsq $0, %rax 0000000000000347: R_X86_64_64 memset 34f: ff e0 Such code results in infinite recursion at runtime. This is observed when doing kexec. Instead, reuse an implementation from arch/x86/boot/compressed/string.c if we define warn as a symbol. Fixes: 8fc5b4d4121c ("purgatory: core purgatory functionality") Link: https://bugs.chromium.org/p/chromium/issues/detail?id=984056 Reported-by: Vaibhav Rustagi Tested-by: Vaibhav Rustagi Debugged-by: Vaibhav Rustagi Debugged-by: Manoj Gupta Suggested-by: Alistair Delva Signed-off-by: Vaibhav Rustagi Signed-off-by: Nick Desaulniers --- Changes v1 -> v2: * Add Fixes tag. * Move this patch to first in the series. arch/x86/purgatory/Makefile | 3 +++ arch/x86/purgatory/purgatory.c | 6 ++++++ arch/x86/purgatory/string.c | 23 ----------------------- 3 files changed, 9 insertions(+), 23 deletions(-) delete mode 100644 arch/x86/purgatory/string.c -- 2.22.0.657.g960e92d24f-goog diff --git a/arch/x86/purgatory/Makefile b/arch/x86/purgatory/Makefile index 3cf302b26332..91ef244026d2 100644 --- a/arch/x86/purgatory/Makefile +++ b/arch/x86/purgatory/Makefile @@ -6,6 +6,9 @@ purgatory-y := purgatory.o stack.o setup-x86_$(BITS).o sha256.o entry64.o string targets += $(purgatory-y) PURGATORY_OBJS = $(addprefix $(obj)/,$(purgatory-y)) +$(obj)/string.o: $(srctree)/arch/x86/boot/compressed/string.c FORCE + $(call if_changed_rule,cc_o_c) + $(obj)/sha256.o: $(srctree)/lib/sha256.c FORCE $(call if_changed_rule,cc_o_c) diff --git a/arch/x86/purgatory/purgatory.c b/arch/x86/purgatory/purgatory.c index 6d8d5a34c377..b607bda786f6 100644 --- a/arch/x86/purgatory/purgatory.c +++ b/arch/x86/purgatory/purgatory.c @@ -68,3 +68,9 @@ void purgatory(void) } copy_backup_region(); } + +/* + * Defined in order to reuse memcpy() and memset() from + * arch/x86/boot/compressed/string.c + */ +void warn(const char *msg) {} diff --git a/arch/x86/purgatory/string.c b/arch/x86/purgatory/string.c deleted file mode 100644 index 01ad43873ad9..000000000000 --- a/arch/x86/purgatory/string.c +++ /dev/null @@ -1,23 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * Simple string functions. - * - * Copyright (C) 2014 Red Hat Inc. - * - * Author: - * Vivek Goyal - */ - -#include - -#include "../boot/string.c" - -void *memcpy(void *dst, const void *src, size_t len) -{ - return __builtin_memcpy(dst, src, len); -} - -void *memset(void *dst, int c, size_t len) -{ - return __builtin_memset(dst, c, len); -} From patchwork Mon Jul 22 21:32:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Desaulniers X-Patchwork-Id: 169429 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp8005679ilk; Mon, 22 Jul 2019 14:33:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqxpni8BLsPtYBScPoqxaxP0GrMgNGv4kp9y6T8v279cYRu+cFhIfxm3iJe45SblY9TSOWgQ X-Received: by 2002:a63:f048:: with SMTP id s8mr45382577pgj.26.1563831228494; Mon, 22 Jul 2019 14:33:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563831228; cv=none; d=google.com; s=arc-20160816; b=cY6Lx4ROIYM51jodPDVAamZkJRU/84K2Ww0idhsm6OZG8RW83ruRDKesMvbD84rbpr 8sa7zxdj+nvlOcuVpVmCGKEKU4pE5yb5DIy0AcuG3YAMqtLMmhLfA65HyKL/AnHkY0wQ qlsIJTyI+oCZp4gg/30APKheTsImnydiNOy6o/BTjf2EkSlabQJdEZq/smIbjOOHVXbh tvGivh2d8TeZXdZis268ap8zaXQWWoekBNfqHFNRWiVzSGuCun6YVki+VWe2GGNUfZ8D Qd8R73BBVsfM59kNAgEHqrTwOXzgc7F2c2M2H7EOsctsewByGkknJhT1Q5Jj5rulhLkA uZ4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=lRY0zisiksIF5oLsqk7SdFjADDPWr38y9Kmpdd3lLF8=; b=Wh6jhvW16X+EOglGNrtW7DP8K3pOTvlJS1t5/O12LRl48ksiHgScOEpzCmKIK53/mX UNrqdlH1m30ocRoXvjhF0waTr1UTrUkb29Xv0cPsqrD6VHkkmBDyFb+o9arTTMiw9DlE ePGuunlKmkTPWp/Fr82hcg+iuTEkky4PumrbyhCbAD5dNl5lCwxI+w5AClMaRYS5pDCP rw2PUFUIIkwOCVsR50ihrUYl6sQDTTMPW4CFH5WHiTR5Kwlv5bob7uVtaMzE+HzunY7U mnfeihA0TZY0qruXlFuTEU/3D/KE9jHDemDqnUrr0rq5KFNWCB9qwW/bZDQBbnKS1o/V iWGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=M5sBWcpB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a89si11507053pla.60.2019.07.22.14.33.48; Mon, 22 Jul 2019 14:33:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=M5sBWcpB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732758AbfGVVdr (ORCPT + 29 others); Mon, 22 Jul 2019 17:33:47 -0400 Received: from mail-pl1-f201.google.com ([209.85.214.201]:36783 "EHLO mail-pl1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729004AbfGVVdq (ORCPT ); Mon, 22 Jul 2019 17:33:46 -0400 Received: by mail-pl1-f201.google.com with SMTP id a5so20620208pla.3 for ; Mon, 22 Jul 2019 14:33:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=lRY0zisiksIF5oLsqk7SdFjADDPWr38y9Kmpdd3lLF8=; b=M5sBWcpBd2bTR6EdJX1ZTfns6OrNG5/wUzgqOKykycN9ggYpd0DCEnzUcr7zlTRkID krH5qM8cY9GKF1awcF4kNgRYDn5cOrTTHAMYFgdOtZAkCRJWhmYJi9vhzQVk8JYZzlGO A4PxoOUbmnZdRhEzicMJg2lRXanY234OsACFhdboH06Z/BfUC9YVYYxPHyf4TaB8ush5 qLFqrmPahyS22GDG0bQkIzdE6EFBy3vjMSWbpHYINyxRyhbOJxhvV43HgxvprYosTi+D 0nW+Q9WMdczgo5ouvIYIyIt0XI3+eJx0ZprRyT4ZzLkNQDcXYO9RYFUq2bybvwxtBV7/ KRyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=lRY0zisiksIF5oLsqk7SdFjADDPWr38y9Kmpdd3lLF8=; b=I8S0S/MXPYXmo/UOZg8wkFm4gDckLITRbvcTEYb+pWhxP4u46cQVEkaxHcDtgENUsF oTtoL7V6CpZeuZv6OFhBQT3nQBFaR1IUQFenmSAZPMDiPNWmOrtPFB5VbVoTcZD6QcL2 Ws9RfHOZO5ytrCHSTUc5MY1nUSfWH94dCMp5bayNRZKR18y+2nqQCEKpArxnBTS7Q6j0 7dqgrfvslYuXPoPzalRYlUUle612KRBEPJqW2/9WoQtvxfgyydTMrpwG63m6MolhCpAO hG0ptmm5i6b/TVs/Uik2KPsNMDAlgPcwdtqptqRh0aNtRjVH/EdX2uzifAaxHDqTbYWr GJpg== X-Gm-Message-State: APjAAAVmGUKxSeBg0Pmx+6MKDcgvhT2yeQPCq8Go9jMj77QNDpPI9uQH qA9Ur5LzTwdMLg0u5gk76iQOWTqcumxBHF034wk= X-Received: by 2002:a63:f50d:: with SMTP id w13mr73259220pgh.411.1563831225390; Mon, 22 Jul 2019 14:33:45 -0700 (PDT) Date: Mon, 22 Jul 2019 14:32:45 -0700 In-Reply-To: <20190722213250.238685-1-ndesaulniers@google.com> Message-Id: <20190722213250.238685-2-ndesaulniers@google.com> Mime-Version: 1.0 References: <20190722213250.238685-1-ndesaulniers@google.com> X-Mailer: git-send-email 2.22.0.657.g960e92d24f-goog Subject: [PATCH v2 2/2] x86/purgatory: use CFLAGS_REMOVE rather than reset KBUILD_CFLAGS From: Nick Desaulniers To: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de Cc: peterz@infradead.org, clang-built-linux@googlegroups.com, Nick Desaulniers , Vaibhav Rustagi , "H. Peter Anvin" , x86@kernel.org, linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org KBUILD_CFLAGS is very carefully built up in the top level Makefile, particularly when cross compiling or using different build tools. Resetting KBUILD_CFLAGS via := assignment is an antipattern. The comment above the reset mentions that -pg is problematic. Other Makefiles like arch/x86/xen/vdso/Makefile use `CFLAGS_REMOVE_file.o = -pg` when CONFIG_FUNCTION_TRACER is set. Prefer that pattern to wiping out all of the important KBUILD_CFLAGS then manually having to re-add them. Fixes: 8fc5b4d4121c ("purgatory: core purgatory functionality") Reported-by: Vaibhav Rustagi Suggested-by: Peter Zijlstra Signed-off-by: Nick Desaulniers --- Rather than manually add -mno-sse, -mno-mmx, -mno-sse2, prefer to filter -pg flags. arch/x86/purgatory/Makefile | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) -- 2.22.0.657.g960e92d24f-goog diff --git a/arch/x86/purgatory/Makefile b/arch/x86/purgatory/Makefile index 91ef244026d2..56bcabca283f 100644 --- a/arch/x86/purgatory/Makefile +++ b/arch/x86/purgatory/Makefile @@ -20,11 +20,13 @@ KCOV_INSTRUMENT := n # Default KBUILD_CFLAGS can have -pg option set when FTRACE is enabled. That # in turn leaves some undefined symbols like __fentry__ in purgatory and not -# sure how to relocate those. Like kexec-tools, use custom flags. - -KBUILD_CFLAGS := -fno-strict-aliasing -Wall -Wstrict-prototypes -fno-zero-initialized-in-bss -fno-builtin -ffreestanding -c -Os -mcmodel=large -KBUILD_CFLAGS += -m$(BITS) -KBUILD_CFLAGS += $(call cc-option,-fno-PIE) +# sure how to relocate those. +ifdef CONFIG_FUNCTION_TRACER +CFLAGS_REMOVE_sha256.o = -pg +CFLAGS_REMOVE_purgatory.o = -pg +CFLAGS_REMOVE_string.o = -pg +CFLAGS_REMOVE_kexec-purgatory.o = -pg +endif $(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE $(call if_changed,ld)