Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp1364598imi; Sat, 23 Jul 2022 03:44:58 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sGLXefItow8v4nGz/uyTUqe8d148bF3Dy/qP6Q7PV8U6gr+vgvG8vkttFA6ajNAdwN35km X-Received: by 2002:a17:906:58c8:b0:6fe:91d5:18d2 with SMTP id e8-20020a17090658c800b006fe91d518d2mr3181819ejs.190.1658573097732; Sat, 23 Jul 2022 03:44:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658573097; cv=none; d=google.com; s=arc-20160816; b=kQ7hKUo5DOMR0taTxJTD59gpSWaM0H0o6iYvDEYYD2mp4A4QTlMD2siNpbWR45RJqI aZFXWlXm3hK/5WmfBfi5Y3op8SrE408Y4ZWnQF6ppuH93lye9XY7E8AFjPp9I3hpm/cx UakkcRrN5GWMmzZjsAN0+WR/j11BI7QVq3VaHrDXbiyF91p2g633rZy6L9/7GFMwzZ8W 7CnguefoyTvqjrVtBuaufiGCDmpysG2GfqJZHJ5YfNCjTHeumEttIZ4+MNKbf1k0atSR GkcfavPfx0MekcwWQlbHb6xT9YsWQg9lMZY7ZwU/4i4JqVduMP2yzbDPmg9UsBadq622 zo+w== 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=ACt+mQndtjy5g2Nscj5fSgcsdVBTRkJV0xFL+GOZRu91tA7sZiYdclvBjoTlihpVjG jJymAPsXAenWEIS+ULsiYuoulCYOsp80nyOqefRs2Nr5l3byZw2Vls2p2b48Ph11zMSj Ai846nKE9xM5cuTpqYPhDFMFkh0pgm9I1KAwQKM6eKW86JHVJhIVlDzK5cn4parbUoJU TFzmIRJxGIedDgO1W1tjJFDmrIt9dw8G/4UuDt4kVsMxfFdBFDQlkk3Fo+gA6BpI6nRS qoyc6G6p4tm8Q7VTSwP97zCUtmATgoaMlZ8FMfd83sQzVJkTx1OgghnDhxvmmY1BIbWN puVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eMiu8dTB; 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 w23-20020a1709062f9700b0072a4b4fb1e0si2343354eji.911.2022.07.23.03.44.32; Sat, 23 Jul 2022 03:44:57 -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=eMiu8dTB; 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 S236329AbiGWKHF (ORCPT + 99 others); Sat, 23 Jul 2022 06:07:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238112AbiGWKGk (ORCPT ); Sat, 23 Jul 2022 06:06:40 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CE8376955; Sat, 23 Jul 2022 03:00:59 -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 6F082B82C22; Sat, 23 Jul 2022 10:00:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C2DF6C341C0; Sat, 23 Jul 2022 10:00:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658570456; bh=BFyioED30kwJD9PGGxY9ZF6TW0CFgre5ZqlPuYrWpL8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eMiu8dTBqOz0iMWuu4dmBRinvClG07BErClAeVmQw7ZbOCibktUK1n8UX8JWY3HHq Jgkwnk9VQoj547b+Tzn2GYv5GlbIR43kgj6yBF3pTHsyZ8bTnOvMF2gEgZ3QJfCmxi BqVA5qCaubz/vScT65dy0lnrLhyhdcWoO+C9uUHI= 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/148] x86: Use return-thunk in asm code Date: Sat, 23 Jul 2022 11:55:05 +0200 Message-Id: <20220723095250.449568556@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220723095224.302504400@linuxfoundation.org> References: <20220723095224.302504400@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.8 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 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)