Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1525396ybi; Wed, 17 Jul 2019 17:04:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqzFbkeKtaxAHUrS8FsxmLcEoUt83xe61bBFTVE6CmJYYyRwTZVTRb8QNm+ShnjDIDJ6Dhu9 X-Received: by 2002:a17:90a:eb04:: with SMTP id j4mr44841832pjz.103.1563408277227; Wed, 17 Jul 2019 17:04:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563408277; cv=none; d=google.com; s=arc-20160816; b=EFaM2lsVEG1ApIy8YiH30bfazyJnyB/LNtkZlv5cypAe2OVNqtspy6m2l37GSDQ00S LGC/bP5rubE9H8C5wCQ3lV18zGV5MRqMXVvGZSSvjkr56mkV5x6c8ayNoy51Ce5SOpqL nc+Ne4lZYHVoccib5YrdpSWU5bT9kpvu0DRMzt4TOw6b/Hu/VSVOIAFbNtdpFM0fdFZc zjUH/ojv7xaCKE+Zj8h35EE9zEXBqfJ4Z9dKsKcu7KdEcE5LMyACgy6xW+OdcHjp9C6x CWZ3eFwlC7XmQFRMRwR5DfUEH0r2ywgfvBv0i1rjrMwywHZLVrrVO6UTitQyg6Ndy5Nw Tr6g== 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=L/78IskbmRc+SAnYRdHcj67j75qZnnMK6y2VOBnfvrk=; b=UXF4ttKNhbtVBazru6yB6+gQntwv8sbYpyo7g8m48r+HbVqhOvkh/jXIiYsHweGJDv SBMoyYn/94cIJSDAzhD5ivuyQsaPJfetfNv3YwyCZmfxybfff888zJO/S8qKJ9T6lni3 iARKUxq4mV/aIc/iVFC2lpTgVEGk6nS7fM58nhpSppOdtX2zj06gk1b3DB28adT+p9jc Eh272jA8S/q9NRkt2Vts+LD9G6LBudDtYx4Pn40C8bNmqTgU0oEGN0DXGEapX7d8pKOL ifbp0YPtNyq7AOFuNBHcGviLMPMLpUjX9HeaTlmWrREkOUAghBkiU8Q8oyKpEpvOveL7 ygOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=S8Yba5Km; 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 f25si300818pfd.157.2019.07.17.17.04.20; Wed, 17 Jul 2019 17:04:37 -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=S8Yba5Km; 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 S1731162AbfGRACx (ORCPT + 99 others); Wed, 17 Jul 2019 20:02:53 -0400 Received: from mail-pl1-f202.google.com ([209.85.214.202]:48289 "EHLO mail-pl1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728538AbfGRACx (ORCPT ); Wed, 17 Jul 2019 20:02:53 -0400 Received: by mail-pl1-f202.google.com with SMTP id i33so12887955pld.15 for ; Wed, 17 Jul 2019 17:02:53 -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=L/78IskbmRc+SAnYRdHcj67j75qZnnMK6y2VOBnfvrk=; b=S8Yba5KmalqdPks1VNH9Uyedt6+Y0i8sR5GaZllNlSzySnf0g7KcoIn18+QvPtf/WD MM5Mg0oIBJuvXHnYUYYmRhp8YmbmiRc8jWCfu+WjoGaWtBjA7HVQcBvT9p8RTOVA2CHA TrQMZkRmwvtTgWXBQP9clKU1DLLCKnxp8Wdb6CGLX+c9GN0KFiEX6dM5dDTUEfh1PhY/ mcJpXHhxb0jFOlv4MFKCbUnDNhzPhM9oqsPzNzcAwZX4aGB5Xz3Vym6xL34fBePCXP1e 6/Z0Ppls3PoFbzBk1QA6O924jzTypnc7pko3pScKOISaEdoQ1VhUb3HR6nqMZQ0/TikG g/EA== 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=L/78IskbmRc+SAnYRdHcj67j75qZnnMK6y2VOBnfvrk=; b=nrNraLpSzdAo4/6A4ZvSEgJtSiGIIO0Oyahyl8rN/R5Mr75Iops+phjARJwt6ah16/ Ufyya/WcuTWbs7ZMMv0Sh9MnioHdk2OS24rQNEAHg8jAtLGDIb+kQKhCOSSIECMXnL6d FepLnACZ/xerFQMy9hlvD0HRRvrMfh6/j3804OtU2EHoV7i1y/kVO1cF88eiRnQ9SN6N Q0FcKRR9q6XHQ1gJaf6K1etNCsbqBaRfgkV6FA0V9VE6XcvgYmL0ezit1GEaCE0lYjAH 3QrwLYgfNn9Yauc0T/JjClzTko/jFz6h39wotALltTTiYWHea9x7dqgdwl0EixZA4Ycr E9tA== X-Gm-Message-State: APjAAAV/hajZ7SFvYmns872N3d4oofFbxttdlP2B5FFwC7h9yJv108N+ Oz8xZ/tHdHinSGyLNkzhj4tqZdsnEshhUg98+tWJ9w== X-Received: by 2002:a63:714a:: with SMTP id b10mr9682287pgn.25.1563408172263; Wed, 17 Jul 2019 17:02:52 -0700 (PDT) Date: Wed, 17 Jul 2019 17:02:06 -0700 In-Reply-To: <20190718000206.121392-1-vaibhavrustagi@google.com> Message-Id: <20190718000206.121392-3-vaibhavrustagi@google.com> Mime-Version: 1.0 References: <20190718000206.121392-1-vaibhavrustagi@google.com> X-Mailer: git-send-email 2.22.0.510.g264f2c817a-goog Subject: [PATCH 2/2] x86/purgatory: do not use __builtin_memcpy and __builtin_memset. From: Vaibhav Rustagi To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" Cc: x86@kernel.org, linux-kernel@vger.kernel.org, Vivek Goyal , Vaibhav Rustagi , Nick Desaulniers , stable@vger.kernel.org, Manoj Gupta , Alistair Delva Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nick Desaulniers 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. 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 --- 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 diff --git a/arch/x86/purgatory/Makefile b/arch/x86/purgatory/Makefile index 3589ec4a28c7..84b8314ddb2d 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); -} -- 2.22.0.510.g264f2c817a-goog