Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1864771rwb; Fri, 19 Aug 2022 10:39:51 -0700 (PDT) X-Google-Smtp-Source: AA6agR7TkFJhCEgCDNEVa7H3QDI8YJMjGJwBJB59MCKidAV8mEcrUQVRrM8u8Vp13JURFEPfRSNo X-Received: by 2002:a63:fe12:0:b0:42a:e57:7464 with SMTP id p18-20020a63fe12000000b0042a0e577464mr6202924pgh.552.1660930790901; Fri, 19 Aug 2022 10:39:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660930790; cv=none; d=google.com; s=arc-20160816; b=I90TURY8EppFKd+SECHTz1plCin0Ej68sXCnBYbSHxU4+qMKLLctEFeAPTueQb//Va 6wqlyR0rFkkLeHV+nqrKzTRWUTnHgKJ3ekoILKXhlsrcP2XbDXnSYbFcYd35Y5JS3zSh 14dIBkzerTbDyJv2wiVSWItFowmug+Ab6byGh0gi5xwdgA34cpG6rHKSIwYcHQXUFb34 Dz9sxg6V9UjVVAPfMrBEaUdaE37RCJ7g1QyEuD8698YhtzSHjV+vEN6DwmNsCSr40tSZ O34uXbBvcYykpULPjCKdV0SL7JihVNwiVMgqQB8/z6igFI3gV9AEqY7VGa+QS3ldn9RT VROQ== 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=UJ2WRcjV9w4TXkfkxtj3dsD2dkCR3zLfCMEvQwe7wkc=; b=beY8li4tMgQcFZl6nXGR5OVmj4HQPbpKRz/THdKHRbqXs4H5N6vvZGU6Gus0qOmLeq w6e/fJIsumGg7rcvTubcSsnHpJYis5muS+0fnMzqtmOofqiZtwvG40DiziYYR1q2OxNC 8gyvoAkjY4p9WnxpccbEwjQpF/teX92T+guuJGZTI4glDlpiyiJiEGyeekGABoyXr49V BCmOP0lzcLFXBJRWoR+EVP1rMhcnwKR7NKP5aC/cdCpOQd4NTYhBnbW2d8aWs4KpopEJ naV5Bi4m4oeFsP3P7uyrG1Pt0xek+uw/8HOi/sOec1M+1Kulatlm9HL1n6uCeaAtgZrO Yb5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=iGg3XuMu; 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 s12-20020a056a0008cc00b0052f0fa0c853si2094680pfu.241.2022.08.19.10.39.40; Fri, 19 Aug 2022 10:39:50 -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=iGg3XuMu; 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 S1350113AbiHSPm5 (ORCPT + 99 others); Fri, 19 Aug 2022 11:42:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349951AbiHSPmN (ORCPT ); Fri, 19 Aug 2022 11:42:13 -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 D4F7D101C76; Fri, 19 Aug 2022 08:41:26 -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 AC8E9B8277D; Fri, 19 Aug 2022 15:41:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01B22C433C1; Fri, 19 Aug 2022 15:41:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660923683; bh=diXNHA+nES9RnYc+jkOrZvmAJAKsH+GdidFUo88bBoU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iGg3XuMuVjO2/gtfwRfhDgRG6wnFcnvb0gFVkLXpaCs2xazYhYQXrqdC+MkOQCuh3 iO+xrqwk1RdUhKtpx5i3OlvGOJLQ5kTPms+3Mie+vQn5m9fm+7ErsXAA8JfnnrfKNw XKZeJgwLq40Fg+7ijf3nEl5YRkimcHP3lyUtNKSc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , "Peter Zijlstra (Intel)" , Borislav Petkov , Josh Poimboeuf , Thadeu Lima de Souza Cascardo Subject: [PATCH 5.15 08/14] x86/ftrace: Use alternative RET encoding Date: Fri, 19 Aug 2022 17:40:24 +0200 Message-Id: <20220819153711.948887870@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819153711.658766010@linuxfoundation.org> References: <20220819153711.658766010@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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 1f001e9da6bbf482311e45e48f53c2bd2179e59c upstream. Use the return thunk in ftrace trampolines, if needed. Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Borislav Petkov Reviewed-by: Josh Poimboeuf Signed-off-by: Borislav Petkov [cascardo: use memcpy(text_gen_insn) as there is no __text_gen_insn] Signed-off-by: Thadeu Lima de Souza Cascardo Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/ftrace.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) --- a/arch/x86/kernel/ftrace.c +++ b/arch/x86/kernel/ftrace.c @@ -309,7 +309,7 @@ union ftrace_op_code_union { } __attribute__((packed)); }; -#define RET_SIZE 1 + IS_ENABLED(CONFIG_SLS) +#define RET_SIZE (IS_ENABLED(CONFIG_RETPOLINE) ? 5 : 1 + IS_ENABLED(CONFIG_SLS)) static unsigned long create_trampoline(struct ftrace_ops *ops, unsigned int *tramp_size) @@ -365,7 +365,12 @@ create_trampoline(struct ftrace_ops *ops goto fail; ip = trampoline + size; - memcpy(ip, retq, RET_SIZE); + + /* The trampoline ends with ret(q) */ + if (cpu_feature_enabled(X86_FEATURE_RETHUNK)) + memcpy(ip, text_gen_insn(JMP32_INSN_OPCODE, ip, &__x86_return_thunk), JMP32_INSN_SIZE); + else + memcpy(ip, retq, sizeof(retq)); /* No need to test direct calls on created trampolines */ if (ops->flags & FTRACE_OPS_FL_SAVE_REGS) {