From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.codeaurora.org by pdx-caf-mail.web.codeaurora.org (Dovecot) with LMTP id dc2qESdRGVujDQAAmS7hNA ; Thu, 07 Jun 2018 15:37:23 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 8C5966074D; Thu, 7 Jun 2018 15:37:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.0 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by smtp.codeaurora.org (Postfix) with ESMTP id 64EA460590; Thu, 7 Jun 2018 15:37:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 64EA460590 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935284AbeFGPhT (ORCPT + 25 others); Thu, 7 Jun 2018 11:37:19 -0400 Received: from mga17.intel.com ([192.55.52.151]:61234 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933818AbeFGOmb (ORCPT ); Thu, 7 Jun 2018 10:42:31 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Jun 2018 07:42:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,486,1520924400"; d="scan'208";a="235505951" Received: from 2b52.sc.intel.com ([143.183.136.51]) by fmsmga006.fm.intel.com with ESMTP; 07 Jun 2018 07:42:30 -0700 From: Yu-cheng Yu To: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , "H.J. Lu" , Vedvyas Shanbhogue , "Ravi V. Shankar" , Dave Hansen , Andy Lutomirski , Jonathan Corbet , Oleg Nesterov , Arnd Bergmann , Mike Kravetz Subject: [PATCH 5/7] x86: Insert endbr32/endbr64 to vDSO Date: Thu, 7 Jun 2018 07:38:53 -0700 Message-Id: <20180607143855.3681-6-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180607143855.3681-1-yu-cheng.yu@intel.com> References: <20180607143855.3681-1-yu-cheng.yu@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "H.J. Lu" When Intel indirect branch tracking is enabled, functions in vDSO which may be called indirectly should have endbr32 or endbr64 as the first instruction. We try to compile vDSO with -fcf-protection=branch -mibt if possible. Otherwise, we insert endbr32 or endbr64 by hand to assembly codes generated by the compiler. Signed-off-by: H.J. Lu --- arch/x86/entry/vdso/.gitignore | 4 ++++ arch/x86/entry/vdso/Makefile | 34 ++++++++++++++++++++++++++++++++++ arch/x86/entry/vdso/endbr.sh | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 arch/x86/entry/vdso/endbr.sh diff --git a/arch/x86/entry/vdso/.gitignore b/arch/x86/entry/vdso/.gitignore index aae8ffdd5880..552941fdfae0 100644 --- a/arch/x86/entry/vdso/.gitignore +++ b/arch/x86/entry/vdso/.gitignore @@ -5,3 +5,7 @@ vdso32-sysenter-syms.lds vdso32-int80-syms.lds vdso-image-*.c vdso2c +vclock_gettime.S +vgetcpu.S +vclock_gettime.asm +vgetcpu.asm diff --git a/arch/x86/entry/vdso/Makefile b/arch/x86/entry/vdso/Makefile index d998a487c9b1..cccafc36a831 100644 --- a/arch/x86/entry/vdso/Makefile +++ b/arch/x86/entry/vdso/Makefile @@ -118,6 +118,40 @@ $(obj)/%-x32.o: $(obj)/%.o FORCE targets += vdsox32.lds $(vobjx32s-y) +ifdef CONFIG_X86_INTEL_BRANCH_TRACKING_USER + ifeq ($(call cc-option-yn, -fcf-protection=branch -mibt), y) + $(obj)/vclock_gettime.o $(obj)/vgetcpu.o $(obj)/vdso32/vclock_gettime.o: KBUILD_CFLAGS += -fcf-protection=branch -mibt + else + endbr := $(srctree)/$(src)/endbr.sh + quiet_cmd_endbr = ENDBR $@ + cmd_endbr = $(CONFIG_SHELL) '$(endbr)' $< $@ + + quiet_cmd_cc_asm_c = CC $(quiet_modtag) $@ + cmd_cc_asm_c = $(CC) $(c_flags) $(DISABLE_LTO) -S -o $@ $< + +$(obj)/%.asm: $(src)/%.c + $(call if_changed_dep,cc_asm_c) + +$(obj)/vclock_gettime.S: $(obj)/vclock_gettime.asm + $(call if_changed,endbr) + +$(obj)/vgetcpu.S: $(obj)/vgetcpu.asm + $(call if_changed,endbr) + +$(obj)/vclock_gettime.o: $(obj)/vclock_gettime.S + $(call if_changed_rule,as_o_S) + +$(obj)/vgetcpu.o: $(obj)/vgetcpu.S + $(call if_changed_rule,as_o_S) + +$(obj)/vdso32/vclock_gettime.S: $(obj)/vdso32/vclock_gettime.asm + $(call if_changed,endbr) + +$(obj)/vdso32/vclock_gettime.o: $(obj)/vdso32/vclock_gettime.S + $(call if_changed_rule,as_o_S) + endif +endif + $(obj)/%.so: OBJCOPYFLAGS := -S $(obj)/%.so: $(obj)/%.so.dbg $(call if_changed,objcopy) diff --git a/arch/x86/entry/vdso/endbr.sh b/arch/x86/entry/vdso/endbr.sh new file mode 100644 index 000000000000..983dbec182f2 --- /dev/null +++ b/arch/x86/entry/vdso/endbr.sh @@ -0,0 +1,32 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 + +in="$1" +out="$2" + +case "$in" in +*/vdso32/*) + endbr=".byte 0xf3,0x0f,0x1e,0xfb" + ;; +*) + endbr=".byte 0xf3,0x0f,0x1e,0xfa" + ;; +esac + +need_endbr=no +while IFS= read line ; do + case "$line" in + __vdso_clock_gettime:|__vdso_getcpu:|__vdso_gettimeofday:|__vdso_time:) + need_endbr=yes + ;; + " ."*) + ;; + " "*) + if [ "$need_endbr" = "yes" ]; then + need_endbr=no + echo " $endbr" + fi + ;; + esac + echo "$line" +done < "$in" > "$out" -- 2.15.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on archive.lwn.net X-Spam-Level: X-Spam-Status: No, score=-5.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham autolearn_force=no version=3.4.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by archive.lwn.net (Postfix) with ESMTP id 7442F7DF8B for ; Thu, 7 Jun 2018 15:37:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933177AbeFGPhR (ORCPT ); Thu, 7 Jun 2018 11:37:17 -0400 Received: from mga17.intel.com ([192.55.52.151]:61234 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933818AbeFGOmb (ORCPT ); Thu, 7 Jun 2018 10:42:31 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Jun 2018 07:42:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,486,1520924400"; d="scan'208";a="235505951" Received: from 2b52.sc.intel.com ([143.183.136.51]) by fmsmga006.fm.intel.com with ESMTP; 07 Jun 2018 07:42:30 -0700 From: Yu-cheng Yu To: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , "H.J. Lu" , Vedvyas Shanbhogue , "Ravi V. Shankar" , Dave Hansen , Andy Lutomirski , Jonathan Corbet , Oleg Nesterov , Arnd Bergmann , Mike Kravetz Subject: [PATCH 5/7] x86: Insert endbr32/endbr64 to vDSO Date: Thu, 7 Jun 2018 07:38:53 -0700 Message-Id: <20180607143855.3681-6-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180607143855.3681-1-yu-cheng.yu@intel.com> References: <20180607143855.3681-1-yu-cheng.yu@intel.com> Sender: linux-doc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-doc@vger.kernel.org From: "H.J. Lu" When Intel indirect branch tracking is enabled, functions in vDSO which may be called indirectly should have endbr32 or endbr64 as the first instruction. We try to compile vDSO with -fcf-protection=branch -mibt if possible. Otherwise, we insert endbr32 or endbr64 by hand to assembly codes generated by the compiler. Signed-off-by: H.J. Lu --- arch/x86/entry/vdso/.gitignore | 4 ++++ arch/x86/entry/vdso/Makefile | 34 ++++++++++++++++++++++++++++++++++ arch/x86/entry/vdso/endbr.sh | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 arch/x86/entry/vdso/endbr.sh diff --git a/arch/x86/entry/vdso/.gitignore b/arch/x86/entry/vdso/.gitignore index aae8ffdd5880..552941fdfae0 100644 --- a/arch/x86/entry/vdso/.gitignore +++ b/arch/x86/entry/vdso/.gitignore @@ -5,3 +5,7 @@ vdso32-sysenter-syms.lds vdso32-int80-syms.lds vdso-image-*.c vdso2c +vclock_gettime.S +vgetcpu.S +vclock_gettime.asm +vgetcpu.asm diff --git a/arch/x86/entry/vdso/Makefile b/arch/x86/entry/vdso/Makefile index d998a487c9b1..cccafc36a831 100644 --- a/arch/x86/entry/vdso/Makefile +++ b/arch/x86/entry/vdso/Makefile @@ -118,6 +118,40 @@ $(obj)/%-x32.o: $(obj)/%.o FORCE targets += vdsox32.lds $(vobjx32s-y) +ifdef CONFIG_X86_INTEL_BRANCH_TRACKING_USER + ifeq ($(call cc-option-yn, -fcf-protection=branch -mibt), y) + $(obj)/vclock_gettime.o $(obj)/vgetcpu.o $(obj)/vdso32/vclock_gettime.o: KBUILD_CFLAGS += -fcf-protection=branch -mibt + else + endbr := $(srctree)/$(src)/endbr.sh + quiet_cmd_endbr = ENDBR $@ + cmd_endbr = $(CONFIG_SHELL) '$(endbr)' $< $@ + + quiet_cmd_cc_asm_c = CC $(quiet_modtag) $@ + cmd_cc_asm_c = $(CC) $(c_flags) $(DISABLE_LTO) -S -o $@ $< + +$(obj)/%.asm: $(src)/%.c + $(call if_changed_dep,cc_asm_c) + +$(obj)/vclock_gettime.S: $(obj)/vclock_gettime.asm + $(call if_changed,endbr) + +$(obj)/vgetcpu.S: $(obj)/vgetcpu.asm + $(call if_changed,endbr) + +$(obj)/vclock_gettime.o: $(obj)/vclock_gettime.S + $(call if_changed_rule,as_o_S) + +$(obj)/vgetcpu.o: $(obj)/vgetcpu.S + $(call if_changed_rule,as_o_S) + +$(obj)/vdso32/vclock_gettime.S: $(obj)/vdso32/vclock_gettime.asm + $(call if_changed,endbr) + +$(obj)/vdso32/vclock_gettime.o: $(obj)/vdso32/vclock_gettime.S + $(call if_changed_rule,as_o_S) + endif +endif + $(obj)/%.so: OBJCOPYFLAGS := -S $(obj)/%.so: $(obj)/%.so.dbg $(call if_changed,objcopy) diff --git a/arch/x86/entry/vdso/endbr.sh b/arch/x86/entry/vdso/endbr.sh new file mode 100644 index 000000000000..983dbec182f2 --- /dev/null +++ b/arch/x86/entry/vdso/endbr.sh @@ -0,0 +1,32 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 + +in="$1" +out="$2" + +case "$in" in +*/vdso32/*) + endbr=".byte 0xf3,0x0f,0x1e,0xfb" + ;; +*) + endbr=".byte 0xf3,0x0f,0x1e,0xfa" + ;; +esac + +need_endbr=no +while IFS= read line ; do + case "$line" in + __vdso_clock_gettime:|__vdso_getcpu:|__vdso_gettimeofday:|__vdso_time:) + need_endbr=yes + ;; + " ."*) + ;; + " "*) + if [ "$need_endbr" = "yes" ]; then + need_endbr=no + echo " $endbr" + fi + ;; + esac + echo "$line" +done < "$in" > "$out" -- 2.15.1 -- To unsubscribe from this list: send the line "unsubscribe linux-doc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html