From patchwork Thu Jun 7 14:38:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu-cheng Yu X-Patchwork-Id: 10452335 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6437F60375 for ; Thu, 7 Jun 2018 14:42:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 54AB3294DF for ; Thu, 7 Jun 2018 14:42:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 495C029510; Thu, 7 Jun 2018 14:42:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B3494294DF for ; Thu, 7 Jun 2018 14:42:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4D8966B029B; Thu, 7 Jun 2018 10:42:33 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3C64B6B029E; Thu, 7 Jun 2018 10:42:33 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 12DB96B0299; Thu, 7 Jun 2018 10:42:32 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f197.google.com (mail-pf0-f197.google.com [209.85.192.197]) by kanga.kvack.org (Postfix) with ESMTP id 9EE086B0293 for ; Thu, 7 Jun 2018 10:42:32 -0400 (EDT) Received: by mail-pf0-f197.google.com with SMTP id y21-v6so4668949pfm.4 for ; Thu, 07 Jun 2018 07:42:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to :subject:date:message-id:in-reply-to:references; bh=DOgawqD+76spzWzpXCTifnKLD5UOFZwfBnn9OV3YNhA=; b=n3Wts5HGoOvolImUtvOoAO/rmvS7Ke0QKDu+8IiYYaMtjjZ7FMlsI5pisb6mEvEotu S2f0Zjdr0uOcTSpK1Veg1q3cAcU/EijwjCojTppQF//aFUYXIIMsD4yc6SqFqmEZWYq5 gRyze0K+8HMh9+9wZuW4w1+c5k8NFKvCvNQzdGCIssO13w5Is/7UStuQSos9rH9mJunE 7HWWaQ7e/X0PS5KbPgAzlYkt+C2BeBfGJguZLQZOYn4F7tHmQmIP9udV4e+Yb7FZJHxN prLGPv/kPcpsITX3HFORWAlQeN5ODuiKXR/s4AQkwNeKsBWuu1tHymK1dqxsG0W33LOW CSHA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of yu-cheng.yu@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=yu-cheng.yu@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: APt69E2RPqXFgwmrXqijiTou452Hm5wSJkRAH80C6js89SeicI0JK3Q5 QWyhTus2ntPirF+K6uu0wgrmczSmJwqQECIAAsvL4Fyrzw6oD0cG6MwUVZEx2nVPdwjo6tf27bB 13fYe1L/PkOf4e5u1jx9xYLKHzPUhdcBYvB/SLHDcFShpn33oHlRcBPJznRe+11AXrg== X-Received: by 2002:a17:902:1002:: with SMTP id b2-v6mr2322521pla.344.1528382552329; Thu, 07 Jun 2018 07:42:32 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKUXvolC6DGPx5XR+FlF+qqrzky7x+NdYs9lE005ZbUWlsB31sBQNEdgeOvTSfzg8IJZJXe X-Received: by 2002:a17:902:1002:: with SMTP id b2-v6mr2322462pla.344.1528382551396; Thu, 07 Jun 2018 07:42:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528382551; cv=none; d=google.com; s=arc-20160816; b=bRvZtIJf28AjCxlhk3RnqBvNOAOMAD3TfqiyegTB0UEb/6xGn0tI2Z0VG6YMHnfAMX uimCtaT57ZHG6djxJilwFh5uoR37yD2mpGvN4cAg94K66efwqLFuTdb6GbyAMW/2T7Vn GKuByxBAUIq5ZMlZyVgbfPcV3fH3xl8CvN/qWpEcKhgaA50x7lS2BF10OohMydUYou8G jCFz1MVwUCoQIVYkyrK5F2yKwuIbhuqundsjJ+VtS4RlCcC2IeWd15abDB6AeJ8NydQn +iafkXPXxYPtMrzUTAjAJGkbJkkVmoqvcFb1sEM1D1nlQrpLoNF4Ie3SzziQROFHBXt7 VTgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:to:from :arc-authentication-results; bh=DOgawqD+76spzWzpXCTifnKLD5UOFZwfBnn9OV3YNhA=; b=yWFMyDMatMxsDnUrzV8uhfokrRyvxSM9eB8TZfOnMN7p3glmxIHOy495Uxks47Il1u OkQbSF0hDjoCcoE+lQ1OACWSDz7Iy75MgNPWyyEcddgawCZ9YDz1ksfbcu/yl4cxs17H 7aamo9mK1rI0kP3oWqyckEfV1jcZLArp0TDn0PhziMhGFhSlfdtNpRKcZ8T5YCmdsBIW kFtYHs+tHX0oisBGLWgeXnUdeqEenszbuVYSysj/UVEjGkBvRcmb+gwKuPtPWwmNqRIJ wyq7mH1A8ZTfi3xu/0UYmH+T492/7FWb4imx5D/2PpAA0s+jAG9Adv7JPHy7O89vpMUg Gd4g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of yu-cheng.yu@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=yu-cheng.yu@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga03.intel.com (mga03.intel.com. [134.134.136.65]) by mx.google.com with ESMTPS id l22-v6si26243115pgu.353.2018.06.07.07.42.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Jun 2018 07:42:31 -0700 (PDT) Received-SPF: pass (google.com: domain of yu-cheng.yu@intel.com designates 134.134.136.65 as permitted sender) client-ip=134.134.136.65; Authentication-Results: mx.google.com; spf=pass (google.com: domain of yu-cheng.yu@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=yu-cheng.yu@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.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> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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"