Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4702042imw; Tue, 12 Jul 2022 12:42:02 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vFLcGE8LluEiJJAv3VnVTvP+kX1Yz0sYczy8uTvyKHf4P3D5vOkuPerYoTC6eN/mQi+d9T X-Received: by 2002:a17:902:a70d:b0:15e:da68:b1b1 with SMTP id w13-20020a170902a70d00b0015eda68b1b1mr25339905plq.53.1657654921811; Tue, 12 Jul 2022 12:42:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657654921; cv=none; d=google.com; s=arc-20160816; b=STTIP2JHERQgMNK5GGe6ug9i5ohmHCf6ElFn3MxR7yHBoXxroSpDzBvmWR5iuayekD nDRnaEVk2IPiQBABjK6riJukOs/zVmWVhISRQYlgc7ic2O+4ymlmPAdcwRysIzNugd8z 1wCVOGq+U0a1rTn243lOAL5FIvbisKEOH2HZRFRgF0qiTJaM4lksonkjeHhNLnwua8Is Xpo0BPTzHreinjC/D06TFHzR7d5ebDhU6hhaQQiIVor2u3Sus5DuOkaju7J7JdTBhSr9 jC+zYrdItgKp+iHFW2rlIc00Bmz74Oc5/CDiHK+wP7hX2vS9EguSKJZUBA12xzfLgyCE 8GMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=g2mTaEnpYV3HCA7bbcEaxDQv3jKQKMdkRFXSQOAZFGQ=; b=gn37WN2Sg14Z0MKS6665YqylytBG8i+rfOhDT/6oAKSjvLpihXTnVtRerk90FONLKn f5X/Vu9f87JQQY2jqgjgDPrZOYW2vOc/x5LI5yFIlWGqZK5JVd8wLGMRDQ7olR71GdDW VmaaqVhURqniAkuneF/d1EtmLBNNy0LyKWKjJyHHszFQcum8c32/tX8KHTyutJj3Swlr g+O2zPqIVNRdJKNJW6Jr8rzvlQ1fCdXppbFy6fp9i0FsR8nKgreBRPYOriA2HtD6NRZ7 +uJIFVduZgitph6Gy6llkeBGVdl6Uj3ITpIulXgEEAhrPcvSctztGDdI5i13EwhuFyzI /3AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vllPcmRs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d11-20020a170902728b00b0016bdf4bb1f9si12450291pll.202.2022.07.12.12.41.49; Tue, 12 Jul 2022 12:42:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vllPcmRs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234737AbiGLSxN (ORCPT + 99 others); Tue, 12 Jul 2022 14:53:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234646AbiGLSwc (ORCPT ); Tue, 12 Jul 2022 14:52:32 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FA51DA0E4; Tue, 12 Jul 2022 11:45:08 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 69763B81BBB; Tue, 12 Jul 2022 18:44:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9A49C3411C; Tue, 12 Jul 2022 18:44:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657651495; bh=BFyioED30kwJD9PGGxY9ZF6TW0CFgre5ZqlPuYrWpL8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vllPcmRsJzbogyCvHz6x0VkXzTnRaggOi/NPTI+jWrYZuongHs7g82kMm44pl9d1T iL2X19+KZQrZjugnA/rsNiCFjzVew004SKvqZ0x3TbbDO1dPqJSjVe2GO6YFrJjcLE Xr1MZ+0pjnzIxIOiy2CSgv0s/xxbVlCu+cB7kNCA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Peter Zijlstra (Intel)" , Borislav Petkov , Josh Poimboeuf , Thadeu Lima de Souza Cascardo , Ben Hutchings Subject: [PATCH 5.10 093/130] x86: Use return-thunk in asm code Date: Tue, 12 Jul 2022 20:38:59 +0200 Message-Id: <20220712183250.755673482@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220712183246.394947160@linuxfoundation.org> References: <20220712183246.394947160@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Zijlstra commit aa3d480315ba6c3025a60958e1981072ea37c3df upstream. Use the return thunk in asm code. If the thunk isn't needed, it will get patched into a RET instruction during boot by apply_returns(). Since alternatives can't handle relocations outside of the first instruction, putting a 'jmp __x86_return_thunk' in one is not valid, therefore carve out the memmove ERMS path into a separate label and jump to it. Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Borislav Petkov Reviewed-by: Josh Poimboeuf Signed-off-by: Borislav Petkov [cascardo: no RANDSTRUCT_CFLAGS] Signed-off-by: Thadeu Lima de Souza Cascardo [bwh: Backported to 5.10: adjust context] Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- arch/x86/entry/vdso/Makefile | 1 + arch/x86/include/asm/linkage.h | 8 ++++++++ arch/x86/lib/memmove_64.S | 7 ++++++- 3 files changed, 15 insertions(+), 1 deletion(-) --- a/arch/x86/entry/vdso/Makefile +++ b/arch/x86/entry/vdso/Makefile @@ -91,6 +91,7 @@ endif endif $(vobjs): KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS) $(RETPOLINE_CFLAGS),$(KBUILD_CFLAGS)) $(CFL) +$(vobjs): KBUILD_AFLAGS += -DBUILD_VDSO # # vDSO code runs in userspace and -pg doesn't help with profiling anyway. --- a/arch/x86/include/asm/linkage.h +++ b/arch/x86/include/asm/linkage.h @@ -18,19 +18,27 @@ #define __ALIGN_STR __stringify(__ALIGN) #endif +#if defined(CONFIG_RETPOLINE) && !defined(__DISABLE_EXPORTS) && !defined(BUILD_VDSO) +#define RET jmp __x86_return_thunk +#else /* CONFIG_RETPOLINE */ #ifdef CONFIG_SLS #define RET ret; int3 #else #define RET ret #endif +#endif /* CONFIG_RETPOLINE */ #else /* __ASSEMBLY__ */ +#if defined(CONFIG_RETPOLINE) && !defined(__DISABLE_EXPORTS) && !defined(BUILD_VDSO) +#define ASM_RET "jmp __x86_return_thunk\n\t" +#else /* CONFIG_RETPOLINE */ #ifdef CONFIG_SLS #define ASM_RET "ret; int3\n\t" #else #define ASM_RET "ret\n\t" #endif +#endif /* CONFIG_RETPOLINE */ #endif /* __ASSEMBLY__ */ --- a/arch/x86/lib/memmove_64.S +++ b/arch/x86/lib/memmove_64.S @@ -40,7 +40,7 @@ SYM_FUNC_START(__memmove) /* FSRM implies ERMS => no length checks, do the copy directly */ .Lmemmove_begin_forward: ALTERNATIVE "cmp $0x20, %rdx; jb 1f", "", X86_FEATURE_FSRM - ALTERNATIVE "", __stringify(movq %rdx, %rcx; rep movsb; RET), X86_FEATURE_ERMS + ALTERNATIVE "", "jmp .Lmemmove_erms", X86_FEATURE_ERMS /* * movsq instruction have many startup latency @@ -206,6 +206,11 @@ SYM_FUNC_START(__memmove) movb %r11b, (%rdi) 13: RET + +.Lmemmove_erms: + movq %rdx, %rcx + rep movsb + RET SYM_FUNC_END(__memmove) SYM_FUNC_END_ALIAS(memmove) EXPORT_SYMBOL(__memmove)