Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10416925ybi; Wed, 24 Jul 2019 22:50:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqwE3ZH92QT7TrlEPX6IVEo2fqcVlb5l4ViLoaK1BzxApiKxPesw8tzERYukkt0NE25yVdsk X-Received: by 2002:a17:902:7686:: with SMTP id m6mr89175471pll.239.1564033849913; Wed, 24 Jul 2019 22:50:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564033849; cv=none; d=google.com; s=arc-20160816; b=Ozc2z+IAAQQbSTSRDcZZamfGCM06GTDdr6E7e89L2GddDUvytB0o0E5GZoC2TwpEIa sGKRsTWrsMH6gpCVl8VHyp3trxVcKRBuEz/sOQlvPwxem0Oe9QVUzEhmQOcb9GoaHtBo sK5SX3cvbmqKayt3rtJv3HMRxzQLaj8ik9hG2Ts7rahAmWOc9x/78ncqcekbHGw1ZTtv q6/mIhDEIijZj+mCxyZLjDGYcyxvn0Lhl04AFANuy/0GR8IiXDkL5VRrOap6Sma/Bepw x1aJjRxkGqQEDjcZldQT3JWrUIjuh6wHC52eF08EyN0jsOuyQhqo4/zCGZp4oTsJrfWe yEkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=YJ1aMEs74UNhuCKOoREVlxCR5HtwdPtwGYYolQWtluU=; b=hccWC1W0ouckqjZska6QfXitQknK4rUfBQnP99GqodJ5qYDLQf4Zl4ZD5x4DLm/uPh mM+yx/Td8Mi6BvWC56FLV5CjBJfWxT9tawh5OGgkmBnT04pRXMmeQlbjRpUiLsEJ3uEh O6qt3MV8tsVQHel557hv9EIemK8tlygLvwNFaZ87oD3OBFz3czRZvPeT6H6M//p25Mi+ bue1h8HU84oOihcxvLFcpqvFHT9xXS/8KdvAXDSO5wexjnpUEfq3ar+JzqP0rGvmczxs 83Ivqr/ccipOKhRn6achNR9tEvzQt8OFj866FF2ckMbASUoR2dMN/BkVI06q8R4vZksW OoIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=JE6IcczQ; 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 o4si15301435pgv.157.2019.07.24.22.50.35; Wed, 24 Jul 2019 22:50:49 -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=JE6IcczQ; 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 S2388591AbfGXXt3 (ORCPT + 99 others); Wed, 24 Jul 2019 19:49:29 -0400 Received: from mail-io1-f67.google.com ([209.85.166.67]:34711 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726431AbfGXXt3 (ORCPT ); Wed, 24 Jul 2019 19:49:29 -0400 Received: by mail-io1-f67.google.com with SMTP id k8so93411097iot.1 for ; Wed, 24 Jul 2019 16:49:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=YJ1aMEs74UNhuCKOoREVlxCR5HtwdPtwGYYolQWtluU=; b=JE6IcczQ5f/hbM3+uOk5DeF3km0i6S1v2qMN2hLOmzWuIMvRmmkzxoUyYuIRqOqJcj 4n9clhqmquxRucZo683IIpTaTRlqTT2vpQC3jw0mNe3WuL/gdTVK5AY1fFm4NDN36ggu DOwapZjU5ow4QNQkazEqvMBksYoS88ckhmbKFzPFmJpLJ4dWSKmg1+LnaSBHEEBQApYa 4yXdBCL+OiNRV6A5YFSJuAhNnWWPW3q3JeoHeKx6VarHPJR2PvjOjs6K4mUh+NzH7+cX f+cub60d8J0eSSbBy7u+mUwCPgeuB+IHJUH5/N62c3EdssLAXUegH/t5Gs2fP2T1ZGWO yG/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=YJ1aMEs74UNhuCKOoREVlxCR5HtwdPtwGYYolQWtluU=; b=Mm+mRnuJV2TvcL280XX7IuA6t+po4VTtZI4j8Ii6DsX9ERgBtiyL06xU+pMnDgTAqW WwOuU7Kn6cCRl9S1B/IKznDd55P7yEzDzk05ED9KfkTyP3YRQQHi/HUTUSQN4lX/ffwY unx+knOIplCg57E0lZZCsrWBzuslnUVrO1GsM2Abzvzgzufarbbst/raKIiXB5Q24u/k eZbeD81kDjcAobRSYZ40lW0mprf5te4UZsK9kIVEUsJ+6XIoH8rKJdYL0XF5ANWmfUrp vyjeVUKmV2Ij5i4qEgzSAkLbkSx32SQpv7/3k337yOvfyTdtPopdeF/Xl4qwPXMnWN80 8TvQ== X-Gm-Message-State: APjAAAU72brZRgThOJbJkAjyKdi6N9HX3Nh8FZf/7Qns5U3tWUKeYoJk sJx5vf3y64239CKSZRG6hsd/EsAEimL4jmRTA53SyQ== X-Received: by 2002:a5d:8b52:: with SMTP id c18mr14203913iot.89.1564012167930; Wed, 24 Jul 2019 16:49:27 -0700 (PDT) MIME-Version: 1.0 References: <20190723212418.36379-1-ndesaulniers@google.com> <20190723212418.36379-2-ndesaulniers@google.com> In-Reply-To: <20190723212418.36379-2-ndesaulniers@google.com> From: Vaibhav Rustagi Date: Wed, 24 Jul 2019 16:49:16 -0700 Message-ID: Subject: Re: [PATCH v3 2/2] x86/purgatory: use CFLAGS_REMOVE rather than reset KBUILD_CFLAGS To: Nick Desaulniers Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Peter Zijlstra , clang-built-linux , LKML , yamada.masahiro@socionext.com, stable@vger.kernel.org, "H. Peter Anvin" , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" 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 On Tue, Jul 23, 2019 at 2:24 PM Nick Desaulniers wrote: > > 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 use `CFLAGS_REMOVE_file.o = $(CC_FLAGS_FTRACE)` 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. Seems > also that __stack_chk_fail references are generated when using > CONFIG_STACKPROTECTOR or CONFIG_STACKPROTECTOR_STRONG. > > Cc: stable@vger.kernel.org > Fixes: 8fc5b4d4121c ("purgatory: core purgatory functionality") > Reported-by: Vaibhav Rustagi > Suggested-by: Peter Zijlstra > Signed-off-by: Nick Desaulniers > --- > Alternatively, we could put these in all in one variable and remove it > without any conditional checks (I think that's ok to do so with > CFLAGS_REMOVE). > > Changes v2 -> v3: > * Prefer $(CC_FLAGS_FTRACE) which is exported to -pg. > * Also check CONFIG_STACKPROTECTOR and CONFIG_STACKPROTECTOR_STRONG. > * Cc stable. > Changes v1 -> v2: > Rather than manually add -mno-sse, -mno-mmx, -mno-sse2, prefer to filter > -pg flags. > > arch/x86/purgatory/Makefile | 26 +++++++++++++++++++++----- > 1 file changed, 21 insertions(+), 5 deletions(-) > > diff --git a/arch/x86/purgatory/Makefile b/arch/x86/purgatory/Makefile > index 91ef244026d2..6ef0ced59b9c 100644 > --- a/arch/x86/purgatory/Makefile > +++ b/arch/x86/purgatory/Makefile > @@ -20,11 +20,27 @@ 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 += $(CC_FLAGS_FTRACE) > +CFLAGS_REMOVE_purgatory.o += $(CC_FLAGS_FTRACE) > +CFLAGS_REMOVE_string.o += $(CC_FLAGS_FTRACE) > +CFLAGS_REMOVE_kexec-purgatory.o += $(CC_FLAGS_FTRACE) > +endif > + > +ifdef CONFIG_STACKPROTECTOR > +CFLAGS_REMOVE_sha256.o += -fstack-protector > +CFLAGS_REMOVE_purgatory.o += -fstack-protector > +CFLAGS_REMOVE_string.o += -fstack-protector > +CFLAGS_REMOVE_kexec-purgatory.o += -fstack-protector > +endif > + > +ifdef CONFIG_STACKPROTECTOR_STRONG > +CFLAGS_REMOVE_sha256.o += -fstack-protector-strong > +CFLAGS_REMOVE_purgatory.o += -fstack-protector-strong > +CFLAGS_REMOVE_string.o += -fstack-protector-strong > +CFLAGS_REMOVE_kexec-purgatory.o += -fstack-protector-strong > +endif > > $(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE > $(call if_changed,ld) > -- > 2.22.0.709.g102302147b-goog > Tested-by: Vaibhav Rustagi I tested the v3 patch series with clang compiled kernel for below scenarios: 1. kexec'ing into a new kernel. 2. Purposely crashing the running kernel to generate kdump logs. Thanks, Vaibhav