From nobody Mon May 11 07:03:15 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F098DC433EF for ; Mon, 11 Apr 2022 23:11:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231983AbiDKXNX (ORCPT ); Mon, 11 Apr 2022 19:13:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231137AbiDKXNT (ORCPT ); Mon, 11 Apr 2022 19:13:19 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E5AE813F44 for ; Mon, 11 Apr 2022 16:11:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649718662; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2as6mtjudVOiULeslyVkRAt6GRQ4WTx58TIfrx090XI=; b=HPydSBjRNEtMxMXCC+lPuVm81zRcbV1qpSXRuy0oo7Ue+C4cEGN2YPWV4kGZ7jqhaUlNYG dwItw9uf6FTeD2kHzAXLWOkS6CEDx7Z/0eNtE8+/PfSIUGj4zUZLFlGkjsRaoJXlm9mkAf Ch1wFVnaUMQ105PnYx57wx0KMBhqvQU= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-349-L5lcuskKNQORyQZ7aEA89g-1; Mon, 11 Apr 2022 19:11:01 -0400 X-MC-Unique: L5lcuskKNQORyQZ7aEA89g-1 Received: by mail-qv1-f69.google.com with SMTP id 33-20020a0c8024000000b0043d17ffb0bdso16897174qva.18 for ; Mon, 11 Apr 2022 16:11:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2as6mtjudVOiULeslyVkRAt6GRQ4WTx58TIfrx090XI=; b=Vg/vUDm2lXdmiSiVaTUOy1FqQngO5/5v80OMMMlVtQYczn0vJRdN+tqHavztsvGOkQ sWb9xu7Klu81+njP/n02DueaAxUppgeI7cEoYgv98JZ8F0pSbtKfuU8NK1cPsrAWmRJ4 /MecldN3rLvlDbNMHn44mGOx4A7OLrAurxJUpZ7wEECTUwOwDyyStodu8dr5sA45YmFV hcnyFABSNqvl4xixy8w4VeJwjGQUhMeCFjS3PMEos7AW3+CtQNw+a6t3Lmyt2/QfR6b6 BwT6eyJdb3TpiXKii1/c0eEHHhXR1Po/mRod1Z3rivpdt01qfuLG66aX9e9KnaEVuGPl 1iLg== X-Gm-Message-State: AOAM531meWu8fbUePqdVnz2p2rr+BKNn3AQo6NPxf109VdOCnwIDZLLr nMXBncNWKnxnYUb4cij032zeb0NsQtWRJIGy8DFB1uAFSTbfReQV/5gne6d4Wp5OwpmA/F1MpVY NBsliT/xedNalLzY38olZyTpY X-Received: by 2002:a05:6214:508e:b0:444:4ab8:46db with SMTP id kk14-20020a056214508e00b004444ab846dbmr1455411qvb.0.1649718661225; Mon, 11 Apr 2022 16:11:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJymsLIMM/jbDt0gr1oxX5KokLO47ucantSDt21T0Cp0XuLxwvfQI1z1zCHOWVD5L23xVhaX8w== X-Received: by 2002:a05:6214:508e:b0:444:4ab8:46db with SMTP id kk14-20020a056214508e00b004444ab846dbmr1455397qvb.0.1649718661029; Mon, 11 Apr 2022 16:11:01 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::15]) by smtp.gmail.com with ESMTPSA id c3-20020ac87d83000000b002e1d1b3df15sm27243500qtd.44.2022.04.11.16.10.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Apr 2022 16:11:00 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org Subject: [PATCH 1/4] x86/uaccess: Don't jump between functions Date: Mon, 11 Apr 2022 16:10:29 -0700 Message-Id: <9519e4853148b765e047967708f2b61e56c93186.1649718562.git.jpoimboe@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" For unwinding sanity, a function shouldn't jump to the middle of another function. Move the short string user copy code out to a separate non-function code snippet. Signed-off-by: Josh Poimboeuf --- arch/x86/lib/copy_user_64.S | 87 ++++++++++++++++++++++--------------- 1 file changed, 52 insertions(+), 35 deletions(-) diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S index 8ca5ecf16dc4..9dec1b38a98f 100644 --- a/arch/x86/lib/copy_user_64.S +++ b/arch/x86/lib/copy_user_64.S @@ -53,12 +53,12 @@ SYM_FUNC_START(copy_user_generic_unrolled) ASM_STAC cmpl $8,%edx - jb 20f /* less then 8 bytes, go to byte copy loop */ + jb .Lcopy_user_short_string_bytes ALIGN_DESTINATION movl %edx,%ecx andl $63,%edx shrl $6,%ecx - jz .L_copy_short_string + jz copy_user_short_string 1: movq (%rsi),%r8 2: movq 1*8(%rsi),%r9 3: movq 2*8(%rsi),%r10 @@ -79,37 +79,11 @@ SYM_FUNC_START(copy_user_generic_unrolled) leaq 64(%rdi),%rdi decl %ecx jnz 1b -.L_copy_short_string: - movl %edx,%ecx - andl $7,%edx - shrl $3,%ecx - jz 20f -18: movq (%rsi),%r8 -19: movq %r8,(%rdi) - leaq 8(%rsi),%rsi - leaq 8(%rdi),%rdi - decl %ecx - jnz 18b -20: andl %edx,%edx - jz 23f - movl %edx,%ecx -21: movb (%rsi),%al -22: movb %al,(%rdi) - incq %rsi - incq %rdi - decl %ecx - jnz 21b -23: xor %eax,%eax - ASM_CLAC - RET + jmp copy_user_short_string =20 30: shll $6,%ecx addl %ecx,%edx - jmp 60f -40: leal (%rdx,%rcx,8),%edx - jmp 60f -50: movl %ecx,%edx -60: jmp .Lcopy_user_handle_tail /* ecx is zerorest also */ + jmp .Lcopy_user_handle_tail =20 _ASM_EXTABLE_CPY(1b, 30b) _ASM_EXTABLE_CPY(2b, 30b) @@ -127,10 +101,6 @@ SYM_FUNC_START(copy_user_generic_unrolled) _ASM_EXTABLE_CPY(14b, 30b) _ASM_EXTABLE_CPY(15b, 30b) _ASM_EXTABLE_CPY(16b, 30b) - _ASM_EXTABLE_CPY(18b, 40b) - _ASM_EXTABLE_CPY(19b, 40b) - _ASM_EXTABLE_CPY(21b, 50b) - _ASM_EXTABLE_CPY(22b, 50b) SYM_FUNC_END(copy_user_generic_unrolled) EXPORT_SYMBOL(copy_user_generic_unrolled) =20 @@ -191,7 +161,7 @@ EXPORT_SYMBOL(copy_user_generic_string) SYM_FUNC_START(copy_user_enhanced_fast_string) ASM_STAC /* CPUs without FSRM should avoid rep movsb for short copies */ - ALTERNATIVE "cmpl $64, %edx; jb .L_copy_short_string", "", X86_FEATURE_FS= RM + ALTERNATIVE "cmpl $64, %edx; jb copy_user_short_string", "", X86_FEATURE_= FSRM movl %edx,%ecx 1: rep movsb xorl %eax,%eax @@ -243,6 +213,53 @@ SYM_CODE_START_LOCAL(.Lcopy_user_handle_tail) =20 SYM_CODE_END(.Lcopy_user_handle_tail) =20 +/* + * Finish memcpy of less than 64 bytes. #AC should already be set. + * + * Input: + * rdi destination + * rsi source + * rdx count (< 64) + * + * Output: + * eax uncopied bytes or 0 if successful. + */ +SYM_CODE_START_LOCAL(copy_user_short_string) + movl %edx,%ecx + andl $7,%edx + shrl $3,%ecx + jz .Lcopy_user_short_string_bytes +18: movq (%rsi),%r8 +19: movq %r8,(%rdi) + leaq 8(%rsi),%rsi + leaq 8(%rdi),%rdi + decl %ecx + jnz 18b +.Lcopy_user_short_string_bytes: + andl %edx,%edx + jz 23f + movl %edx,%ecx +21: movb (%rsi),%al +22: movb %al,(%rdi) + incq %rsi + incq %rdi + decl %ecx + jnz 21b +23: xor %eax,%eax + ASM_CLAC + RET + +40: leal (%rdx,%rcx,8),%edx + jmp 60f +50: movl %ecx,%edx /* ecx is zerorest also */ +60: jmp .Lcopy_user_handle_tail + + _ASM_EXTABLE_CPY(18b, 40b) + _ASM_EXTABLE_CPY(19b, 40b) + _ASM_EXTABLE_CPY(21b, 50b) + _ASM_EXTABLE_CPY(22b, 50b) +SYM_CODE_END(copy_user_short_string) + /* * copy_user_nocache - Uncached memory copy with exception handling * This will force destination out of cache for more performance. --=20 2.34.1 From nobody Mon May 11 07:03:15 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6A4AC433EF for ; Mon, 11 Apr 2022 23:11:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232132AbiDKXN0 (ORCPT ); Mon, 11 Apr 2022 19:13:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230399AbiDKXNU (ORCPT ); Mon, 11 Apr 2022 19:13:20 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5959D12ACD for ; Mon, 11 Apr 2022 16:11:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649718664; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4qxd8LkJbqRmTlrpNwb0bYhE4UOJkR+dpIlYlWKMwvE=; b=Se0FeB65wqRD572r5aAdQMnP+R/q9sivkgbiGxzYc1zcI5R98uG95B5XZse+ZR7miD2/pt Uu+lGCVMi0IM0uGJ/Oq2V5V7zNr1Xi/FbOknsZt3JB13IxQmTktSDQxBLOoW9l88K9lLsB yqogFxa2jhSdmfDc1fu1zOG17pPNyGY= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-610-E-tkDJwnNwyOklcKMgeH_A-1; Mon, 11 Apr 2022 19:11:03 -0400 X-MC-Unique: E-tkDJwnNwyOklcKMgeH_A-1 Received: by mail-qt1-f197.google.com with SMTP id bt12-20020ac8690c000000b002ee65af14d0so2814013qtb.22 for ; Mon, 11 Apr 2022 16:11:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4qxd8LkJbqRmTlrpNwb0bYhE4UOJkR+dpIlYlWKMwvE=; b=33Y16/RbI0UFJZnG8Oe1dPTucuBL3ix4fJ1xiZfVkjZR9IO7Y9/oXhCsQMqoUwIgpj ms+jgDcIQC3uVqw+akugEtXDyDXf9Z3XM3qR6hW5ZtDio6yop8ORlH/zfShfXXYgh6mR 5KLGDZ7VknesQ2dtXsDUsr2nDHy/3lM0YzWM/GCfqlrwQfVQGeRc98EVwhCtFY9Q5h7s t8AddfoFzV54z4VJacLMs9JskRdeJAhrsOcGnBK0CcrzlQl/uo2bq+C62wLFdte3tLbC 1l5icVopP58mfmL/GmVxAbGgKoojGOJNyfY03RNd+ImuCFMeBJR9RFMTJhCneucxodU3 3OzA== X-Gm-Message-State: AOAM532G2ZjjLAfGX3ntC+N4hyv73H3VSZ8XiAVt9+5DrW+W3LsTsoFx 65+UGdztMyPObUdrvovtlgoEyc1Ihq2nCi/Ga6IC++7jRzIRbFPFVAm+eDTj87IBEp2CIn8KJZh ByIo45+FECJTxUvyttWTkwoq/ X-Received: by 2002:a05:6214:c85:b0:441:2bb9:92fa with SMTP id r5-20020a0562140c8500b004412bb992famr28637612qvr.21.1649718662588; Mon, 11 Apr 2022 16:11:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy63Vwyu9MBCFvXLU0Sen/ZfLPul69mtbVqD6AuObTlGEj1Z+4I0OXSSDVjydPBmpXqzoz82w== X-Received: by 2002:a05:6214:c85:b0:441:2bb9:92fa with SMTP id r5-20020a0562140c8500b004412bb992famr28637593qvr.21.1649718662285; Mon, 11 Apr 2022 16:11:02 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::15]) by smtp.gmail.com with ESMTPSA id c3-20020ac87d83000000b002e1d1b3df15sm27243500qtd.44.2022.04.11.16.11.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Apr 2022 16:11:01 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org Subject: [PATCH 2/4] objtool: Don't set 'jump_dest' for sibling calls Date: Mon, 11 Apr 2022 16:10:30 -0700 Message-Id: <8737d6b9d1691831aed73375f444f0f42da3e2c9.1649718562.git.jpoimboe@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" For most sibling calls, 'jump_dest' is NULL because objtool treats the jump like a call and sets 'call_dest'. But there are a few edge cases where that's not true. Make it consistent to avoid unexpected behavior. Signed-off-by: Josh Poimboeuf --- tools/objtool/check.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index bd0c2c828940..6f492789c8c0 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1271,7 +1271,7 @@ static bool is_first_func_insn(struct objtool_file *f= ile, struct instruction *in */ static int add_jump_destinations(struct objtool_file *file) { - struct instruction *insn; + struct instruction *insn, *jump_dest; struct reloc *reloc; struct section *dest_sec; unsigned long dest_off; @@ -1291,7 +1291,10 @@ static int add_jump_destinations(struct objtool_file= *file) add_retpoline_call(file, insn); continue; } else if (insn->func) { - /* internal or external sibling call (with reloc) */ + /* + * External sibling call or internal sibling call with + * STT_FUNC reloc. + */ add_call_dest(file, insn, reloc->sym, true); continue; } else if (reloc->sym->sec->idx) { @@ -1303,8 +1306,8 @@ static int add_jump_destinations(struct objtool_file = *file) continue; } =20 - insn->jump_dest =3D find_insn(file, dest_sec, dest_off); - if (!insn->jump_dest) { + jump_dest =3D find_insn(file, dest_sec, dest_off); + if (!jump_dest) { =20 /* * This is a special case where an alt instruction @@ -1323,8 +1326,8 @@ static int add_jump_destinations(struct objtool_file = *file) /* * Cross-function jump. */ - if (insn->func && insn->jump_dest->func && - insn->func !=3D insn->jump_dest->func) { + if (insn->func && jump_dest->func && + insn->func !=3D jump_dest->func) { =20 /* * For GCC 8+, create parent/child links for any cold @@ -1342,16 +1345,22 @@ static int add_jump_destinations(struct objtool_fil= e *file) * subfunction is through a jump table. */ if (!strstr(insn->func->name, ".cold") && - strstr(insn->jump_dest->func->name, ".cold")) { - insn->func->cfunc =3D insn->jump_dest->func; - insn->jump_dest->func->pfunc =3D insn->func; + strstr(jump_dest->func->name, ".cold")) { + insn->func->cfunc =3D jump_dest->func; + jump_dest->func->pfunc =3D insn->func; =20 - } else if (!same_function(insn, insn->jump_dest) && - is_first_func_insn(file, insn->jump_dest)) { - /* internal sibling call (without reloc) */ - add_call_dest(file, insn, insn->jump_dest->func, true); + } else if (!same_function(insn, jump_dest) && + is_first_func_insn(file, jump_dest)) { + /* + * Internal sibling call without reloc or with + * STT_SECTION reloc. + */ + add_call_dest(file, insn, jump_dest->func, true); + continue; } } + + insn->jump_dest =3D jump_dest; } =20 return 0; --=20 2.34.1 From nobody Mon May 11 07:03:15 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C99D6C433F5 for ; Mon, 11 Apr 2022 23:11:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232390AbiDKXNd (ORCPT ); Mon, 11 Apr 2022 19:13:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231752AbiDKXNW (ORCPT ); Mon, 11 Apr 2022 19:13:22 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8BFC212ACD for ; Mon, 11 Apr 2022 16:11:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649718665; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0ZCQd9ke2KAWwc19bl0zzlVfHby01VezJ6qx5ncoRec=; b=WQIMFIZxcJN/KX+OdPdpSmYw1iDX3Rgz+/jmZnjPAdpPcM7YTDy60CS7Y9EXlY7vVQO4yp kbvLOg6BYc6d2vdO3UU7hIxC4NjtFiVxiVNGmkhcxjYRsgELl9SDg5BMyOjeCuOV3aLdNc Jr3iL8SkeBWoa/N5dUxFCDJsPOzgps4= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-184-_SeYdMwzN0ubioKLE2ifIA-1; Mon, 11 Apr 2022 19:11:04 -0400 X-MC-Unique: _SeYdMwzN0ubioKLE2ifIA-1 Received: by mail-qv1-f69.google.com with SMTP id ke15-20020a056214300f00b00443efe3fe65so16908304qvb.14 for ; Mon, 11 Apr 2022 16:11:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0ZCQd9ke2KAWwc19bl0zzlVfHby01VezJ6qx5ncoRec=; b=lNkJnDf0FJ3G7bFwFMbcKnUhSc2b0rOgI7LiE0nmBkFQU8vOiWjwvK7ZK1x3mpgvNK K6KwSde5CgZAREkMo5v+inPjSrNLYo7PZ3ZrR6sh6CggKzPMB9lWBvsmoZl5JM7t3bU+ 0Z4QSpS1Kp1M344PYaqXgA+LMh+KpCmoqNH3BHyZyFYWntdWAiGhB4lputwekhniG51A FPqwtXNbxO9ANJophKZJPF5Akr5nzeMhlGh6pLqjMEZ/04G/jQUz392GKQBEXYRd2lBu tfzlQ7OsgTw2fO9/jIznutiBJNyyn+77PPteHaA5vt4ddxXJHxDUvcTepoVGEPVtIeBk DzvQ== X-Gm-Message-State: AOAM531O3exl+a6NLx7Ne1hfpcF859i8WUTebGxgR5JyXjWO3L6qm/vE HqDUG1dJ7auUBejVXfrao6LDAIAoCG4HJXsnbA7tJnrkbP6fMN/xTiagUpYtao4Pg47YguVIReX THlJtgbDjcW1nnJT7O4G2LVEu X-Received: by 2002:ac8:4c9a:0:b0:2ed:f0a:77c4 with SMTP id j26-20020ac84c9a000000b002ed0f0a77c4mr1350331qtv.376.1649718663874; Mon, 11 Apr 2022 16:11:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwyDp3MjtsqHgRu/Usu7o4b+HfnrxhC+MSZPW3gRfG7MKn4igSsZZTAsstnRNG/fRkx69Vwrw== X-Received: by 2002:ac8:4c9a:0:b0:2ed:f0a:77c4 with SMTP id j26-20020ac84c9a000000b002ed0f0a77c4mr1350318qtv.376.1649718663554; Mon, 11 Apr 2022 16:11:03 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::15]) by smtp.gmail.com with ESMTPSA id c3-20020ac87d83000000b002e1d1b3df15sm27243500qtd.44.2022.04.11.16.11.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Apr 2022 16:11:03 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org Subject: [PATCH 3/4] objtool: Fix sibling call detection in alternatives Date: Mon, 11 Apr 2022 16:10:31 -0700 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In add_jump_destinations(), sibling call detection requires 'insn->func' to be valid. But alternative instructions get their 'func' set in handle_group_alt(), which runs *after* add_jump_destinations(). So sibling calls in alternatives code don't get properly detected. Fix that by changing the initialization order: call add_special_section_alts() *before* add_jump_destinations(). This also means the special case for a missing 'jump_dest' in add_jump_destinations() can be removed, as it has already been dealt with. Signed-off-by: Josh Poimboeuf --- tools/objtool/check.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 6f492789c8c0..0f5d3de30e0d 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1277,6 +1277,13 @@ static int add_jump_destinations(struct objtool_file= *file) unsigned long dest_off; =20 for_each_insn(file, insn) { + if (insn->jump_dest) { + /* + * handle_group_alt() may have previously set + * 'jump_dest' for some alternatives. + */ + continue; + } if (!is_static_jump(insn)) continue; =20 @@ -1308,15 +1315,6 @@ static int add_jump_destinations(struct objtool_file= *file) =20 jump_dest =3D find_insn(file, dest_sec, dest_off); if (!jump_dest) { - - /* - * This is a special case where an alt instruction - * jumps past the end of the section. These are - * handled later in handle_group_alt(). - */ - if (!strcmp(insn->sec->name, ".altinstr_replacement")) - continue; - WARN_FUNC("can't find jump dest instruction at %s+0x%lx", insn->sec, insn->offset, dest_sec->name, dest_off); @@ -1549,13 +1547,13 @@ static int handle_group_alt(struct objtool_file *fi= le, continue; =20 dest_off =3D arch_jump_destination(insn); - if (dest_off =3D=3D special_alt->new_off + special_alt->new_len) + if (dest_off =3D=3D special_alt->new_off + special_alt->new_len) { insn->jump_dest =3D next_insn_same_sec(file, last_orig_insn); - - if (!insn->jump_dest) { - WARN_FUNC("can't find alternative jump destination", - insn->sec, insn->offset); - return -1; + if (!insn->jump_dest) { + WARN_FUNC("can't find alternative jump destination", + insn->sec, insn->offset); + return -1; + } } } =20 @@ -2254,14 +2252,14 @@ static int decode_sections(struct objtool_file *fil= e) return ret; =20 /* - * Must be before add_special_section_alts() as that depends on - * jump_dest being set. + * Must be before add_jump_destinations(), which depends on 'func' + * being set for alternatives, to enable proper sibling call detection. */ - ret =3D add_jump_destinations(file); + ret =3D add_special_section_alts(file); if (ret) return ret; =20 - ret =3D add_special_section_alts(file); + ret =3D add_jump_destinations(file); if (ret) return ret; =20 --=20 2.34.1 From nobody Mon May 11 07:03:15 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0AC46C433EF for ; Mon, 11 Apr 2022 23:11:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232482AbiDKXNi (ORCPT ); Mon, 11 Apr 2022 19:13:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231964AbiDKXNX (ORCPT ); Mon, 11 Apr 2022 19:13:23 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 394891D309 for ; Mon, 11 Apr 2022 16:11:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649718667; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zufRQemY0tMoebS+JfwFg0YIcxjRVmfAUD4mEizZNlQ=; b=HpxB/47uPNBhYAJSMQ50n+0rE6T9IA15C9biVB/BuhzZbkFAfUvX1rlVVYBFbOkYB+XziX 1EIVsxtTFX2DGM+lf0M2M4JY5x9UxKDE79aRhcnkjaYgdhTzUZ9WEYeCPc5dDGlKcdhPBH qAhalL1Som9zJIQ6kPFOVGFSY8WmaVQ= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-672-uKoFZ2jCN8qEWiLK1GVCEg-1; Mon, 11 Apr 2022 19:11:06 -0400 X-MC-Unique: uKoFZ2jCN8qEWiLK1GVCEg-1 Received: by mail-qt1-f199.google.com with SMTP id a24-20020ac81098000000b002e1e06a72aeso13690850qtj.6 for ; Mon, 11 Apr 2022 16:11:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zufRQemY0tMoebS+JfwFg0YIcxjRVmfAUD4mEizZNlQ=; b=UbA/9yBoXoZfPoxRiCZSTyaHawaCxShnJLvOdPB4PxD86wVssMbKVVahspM6Q9gZHd 2NOyuPZJ4hRJ2sb5mG23g1mSg3ZQ7T/l0cUMpZVUsqfW/BpepMUMxiOft391mKTyVqYn qKre6D+qJ8xOC/ZSe3FfP/OxR8MiLAKcNzmsfpcth/0hRHSpZMZJAg0MF4H3AKYb/3Q+ Sp57QuyWZimFcM+X871QdKC0U/za+FBBb+RTAEPs+1y0dwsIqZMmPTb5Vb9taTeygAD3 NyvpJxgTJk/buzJ8BJl3krgtteS1UADnL99fSqqWTOwKXbnAsNXQu3jriT277MPwKIwR r4Rw== X-Gm-Message-State: AOAM5300oAGKmFXjE8KltE7ckEf8h5g5K2L6Xf2RJ/1arkGTEoAARFGt +X74omMm2Z9SLbGX9bTHKiUG+KgA0dNCq9IJsJVZKsyji3OF9aUbsGXKjpxoHzR7qm5s9CBO3T6 e5S0HMuGvcrQupa3q/+l7VBtV X-Received: by 2002:a05:622a:1990:b0:2e1:a7bf:9222 with SMTP id u16-20020a05622a199000b002e1a7bf9222mr1349199qtc.230.1649718665431; Mon, 11 Apr 2022 16:11:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOChGI1LFSjIQBIXC7Y4dhktK0iomYjZxyQ1lT6EauFoXAynzxuFpju/Kdc7JhFpP3U56Naw== X-Received: by 2002:a05:622a:1990:b0:2e1:a7bf:9222 with SMTP id u16-20020a05622a199000b002e1a7bf9222mr1349187qtc.230.1649718665180; Mon, 11 Apr 2022 16:11:05 -0700 (PDT) Received: from treble.redhat.com ([2600:1700:6e32:6c00::15]) by smtp.gmail.com with ESMTPSA id c3-20020ac87d83000000b002e1d1b3df15sm27243500qtd.44.2022.04.11.16.11.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Apr 2022 16:11:04 -0700 (PDT) From: Josh Poimboeuf To: x86@kernel.org Cc: Peter Zijlstra , linux-kernel@vger.kernel.org Subject: [PATCH 4/4] objtool: Fix function fallthrough detection for vmlinux Date: Mon, 11 Apr 2022 16:10:32 -0700 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Objtool's function fallthrough detection only works on C objects. The distinction between C and assembly objects no longer makes sense with objtool running on vmlinux.o. Now that copy_user_64.S has been fixed up, and an objtool sibling call detection bug has been fixed, the asm code is in "compliance" and this hack is no longer needed. Remove it. Signed-off-by: Josh Poimboeuf --- tools/objtool/check.c | 2 +- tools/objtool/include/objtool/objtool.h | 2 +- tools/objtool/objtool.c | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 0f5d3de30e0d..5f10653eb5c2 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -3310,7 +3310,7 @@ static int validate_branch(struct objtool_file *file,= struct symbol *func, while (1) { next_insn =3D next_insn_to_validate(file, insn); =20 - if (file->c_file && func && insn->func && func !=3D insn->func->pfunc) { + if (func && insn->func && func !=3D insn->func->pfunc) { WARN("%s() falls through to next function %s()", func->name, insn->func->name); return 1; diff --git a/tools/objtool/include/objtool/objtool.h b/tools/objtool/includ= e/objtool/objtool.h index 7a5c13a78f87..a6e72d916807 100644 --- a/tools/objtool/include/objtool/objtool.h +++ b/tools/objtool/include/objtool/objtool.h @@ -27,7 +27,7 @@ struct objtool_file { struct list_head static_call_list; struct list_head mcount_loc_list; struct list_head endbr_list; - bool ignore_unreachables, c_file, hints, rodata; + bool ignore_unreachables, hints, rodata; =20 unsigned int nr_endbr; unsigned int nr_endbr_int; diff --git a/tools/objtool/objtool.c b/tools/objtool/objtool.c index b09946f4e1d6..843ff3c2f28e 100644 --- a/tools/objtool/objtool.c +++ b/tools/objtool/objtool.c @@ -129,7 +129,6 @@ struct objtool_file *objtool_open_read(const char *_obj= name) INIT_LIST_HEAD(&file.static_call_list); INIT_LIST_HEAD(&file.mcount_loc_list); INIT_LIST_HEAD(&file.endbr_list); - file.c_file =3D !vmlinux && find_section_by_name(file.elf, ".comment"); file.ignore_unreachables =3D no_unreachable; file.hints =3D false; =20 --=20 2.34.1