From nobody Sun Feb 8 10:04:36 2026 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D1211DFDE for ; Wed, 28 Feb 2024 02:46:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709088368; cv=none; b=a9x6JfdhLDI5MyCV/cbprO0E9MGGfYBZA9nOA10J5gcCsyQC2vqG1uF23HvRsrQqRFsUkNCRMI9czYE3RfB3KdtgkZqJVJj9ISUfQzGDgwHbWI1cjWvNTixyTSDS5PVd9wsVKNNUnwAyUht80niPYCFrby/D7VdYzDY4aCSSFXs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709088368; c=relaxed/simple; bh=j0esSTih3HDQGZF6sZoHNfFbxuBCsmG4nJeOOvz7sfg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MJAMbAW4yjHsq7eTWlmt9xH27N8sxwXpltFrKUHWxi0O5MtWVFV9hpnCMKIqQcZ0gZRRFx66m7ftx4G3PmiHcZnOztV0qKvWEuwEbPqOp53OJ7LoGktaElQyNcmkhCrQnmOM0Pih/BrYx+URfBrSBK39jUNrJN8ptJ/gzOK9mHI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=URgjHVN3; arc=none smtp.client-ip=209.85.216.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="URgjHVN3" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-299dba8fd24so2891573a91.2 for ; Tue, 27 Feb 2024 18:46:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1709088365; x=1709693165; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YZcP2NcGO5ZtZ0U6eIwOdju/e57ADMXOAHt2kWBKkaE=; b=URgjHVN3OXlILq/zS73P865F6O1rIRFp1ebNQhamgJv/j2T0qfjP+curvoZT9UYfy/ 9+MGyYuH8SmyoLmUZoiX/z9Fi6cb9zux1wZNf/UnYXoUtWkSYXE97Wv7ov3G5ft/leui MPEay1sA+pV7c27MeVDIVySSRZEZOsCy9yXh1kQnV32vJvHr2NCbTOMAYqA8C9LHG7LJ RzJ8t+lqXkmwuQ1Dl0utPy4J4deZLFOHaK/w1wIVLTZi8bkfrVW9UsKhPLgH+Ywy81t1 +yq3JG/SCCARUjnWqxvFKayIL47S7Sa9xt6fGUd5QaHl4xWT4oweo5O/I96vl3zJbRLW rNDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709088365; x=1709693165; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YZcP2NcGO5ZtZ0U6eIwOdju/e57ADMXOAHt2kWBKkaE=; b=beFEqVzLnX5LIfMpyaeAMknhjqgxwAQq8K47VOQ3xhlSmaHK8VbO+YH3RHEMTLj+c/ XB1LxhcFo9xBtnel8czcfXXrjjOyvMBP+MKT9z/dtWjsiBHbhhGBqRNy1Tcig6DZHFEB nMw4zpN7pwr6dFCfuZvz8AEWC0QQ8WzakbXbODqr1KLC9R9u0o5Zw5NziIp8NgB5kNfA taMaTlkMcFICvCpwiajtxE1xVmJQzd5t50XCQX7Ej1zDjvBLS+VhzVPX8Pp6yr2zFYUI 1v8rOm9K2NTXiBgw0EIpgm5Cb/PQliWnxDyu5HIleXjqTfHuyRT/ovX3KntCUf8xdyMA 9pSw== X-Forwarded-Encrypted: i=1; AJvYcCXnMRUX0ToSKTglKqy6UGVuzQgb6EPc95FSIo9+djd2laYognW1yZBWgAkziHpNZUMnbVeo1j0gr1s7btzpBwo9dKyesFAx6UqZZpce X-Gm-Message-State: AOJu0Ywal87i0eUzyrEe/RPbKpUMfJcgqH07oWrBs1bM7u4QKqVNwENV lLmqWY1L1nfhOJgsJsmlsL+T+8JLJaLJ9DSaSJl4SlM8Wd2LmrzgHoXLBF85KL4= X-Google-Smtp-Source: AGHT+IE5aRguP/6spiUNpXSKcim90cEHvc+QzPlJD9JJPgHm8oKDp4OsDvgpiR9QYwrYBE0MCnDu4w== X-Received: by 2002:a17:90b:8d8:b0:299:3e54:83fe with SMTP id ds24-20020a17090b08d800b002993e5483femr9708762pjb.36.1709088365439; Tue, 27 Feb 2024 18:46:05 -0800 (PST) Received: from C02CV19DML87.bytedance.net ([240e:6b1:c0:120::1:d]) by smtp.gmail.com with ESMTPSA id 9-20020a631249000000b005dcbb699abfsm6489072pgs.34.2024.02.27.18.45.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 18:46:05 -0800 (PST) From: Rui Qi To: bp@alien8.de, mingo@redhat.com, tglx@linutronix.de, hpa@zytor.com, jpoimboe@redhat.com, peterz@infradead.org, mbenes@suse.cz, gregkh@linuxfoundation.org, stable@vger.kernel.org, alexandre.chartre@oracle.com Cc: x86@kernel.org, linux-kernel@vger.kernel.org, yuanzhu@bytedance.com, Rui Qi Subject: [PATCH v2 1/3] objtool: is_fentry_call() crashes if call has no destination Date: Wed, 28 Feb 2024 10:45:33 +0800 Message-Id: <20240228024535.79980-2-qirui.001@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20240228024535.79980-1-qirui.001@bytedance.com> References: <20240228024535.79980-1-qirui.001@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Alexandre Chartre commit 87cf61fe848ca8ddf091548671e168f52e8a718e upstream. Fix is_fentry_call() so that it works if a call has no destination set (call_dest). This needs to be done in order to support intra- function calls. Signed-off-by: Alexandre Chartre Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Miroslav Benes Acked-by: Josh Poimboeuf Link: https://lkml.kernel.org/r/20200414103618.12657-2-alexandre.chartre@or= acle.com Signed-off-by: Rui Qi --- tools/objtool/check.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index dfd67243faac..71a24fd46dbd 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1367,7 +1367,7 @@ static int decode_sections(struct objtool_file *file) =20 static bool is_fentry_call(struct instruction *insn) { - if (insn->type =3D=3D INSN_CALL && + if (insn->type =3D=3D INSN_CALL && insn->call_dest && insn->call_dest->type =3D=3D STT_NOTYPE && !strcmp(insn->call_dest->name, "__fentry__")) return true; --=20 2.39.2 (Apple Git-143) From nobody Sun Feb 8 10:04:36 2026 Received: from mail-ot1-f41.google.com (mail-ot1-f41.google.com [209.85.210.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35589200C3 for ; Wed, 28 Feb 2024 02:46:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709088374; cv=none; b=vBa6uxEWbWpIEz2dTBoA+XljzM5S8isytL5q7rTHF1ib4pA6gqN709O5L1bECGWpSRTSlSxLkjezXtuFEAKwm4h7z24/Z+XLun6N9fF26cIQkY+1YkiBNstBlybxImWAXOyn8hPmFjmtemyezF2WcJOLFjwCdUWToCFybePOTNc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709088374; c=relaxed/simple; bh=abhzLrMcAo73itQJFRf9PngJ2NfPzbHIHmMJXMFZsec=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=X+sOvR/Oj+pt0B4FnURDCeFWSQN915GwRFIgW6Aii2sZeXUasyF9sl2oUV+H4lceKCRkRX2C0N4+PEnsRNDk2BLj/xVUtfRo2MvRygobCgyaIofDcrncTBAJDQvIsCNN7CIpIqKuJt2WiJhHt4uFusz6+lJqIyuPF9CiqsH64j8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=Zab5itUG; arc=none smtp.client-ip=209.85.210.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="Zab5itUG" Received: by mail-ot1-f41.google.com with SMTP id 46e09a7af769-6e49812ba77so1652232a34.2 for ; Tue, 27 Feb 2024 18:46:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1709088372; x=1709693172; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4Xvb2DA8xzihP7Mzi/v0EMpx+00b5U5crlo4mSn4zeU=; b=Zab5itUGCPvAlQrjJy0TWTfijq60dXxVpV1rCh4oGw61rTSZcwrh1z1mPTzUufbYPm 5UDndPTkQQAfhPl6inPDKm/vRPHrnvtLACoHsImxuSodljQI6D+eP3k8hVDL0L+7XBUw 9RT3QZUkYWq7u+toLo46SAwvw6xCbAMM8Z9uVnKIVkcyYQMkUQQp2KIbkkDIQ/zML0Y6 EaZQEWCj5jCTMmFxu5p7SiBtuEhdZBzj8IMCeGukyHI3moHuLui5Mmc/REB5u4KRWIaD gMeiZFK63t6qKTXA2TBVazoLlzR+xGt3hdFGODjzNzW0IxghNspagDAZEIec50Sra+Vf mRBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709088372; x=1709693172; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4Xvb2DA8xzihP7Mzi/v0EMpx+00b5U5crlo4mSn4zeU=; b=oafZSLaSoDtUSDeMhi5js79BCgHSKg2lTp5mo7OPE6o7rrStT5Gi0mwV+Wn6ycKcIk 3qG+8BNXoyzq3VQF4eSZkbEkm9yCh6VrTQpmq0ccP/Z9NLUPuaA6Yz5oGQC4wBGwvnfI UGnBMG90fct+MzfyDKPWSbmlv5F5gTFigYyxjnE4n83WF3jA1X2lCHGxxX5LVbZrL+Uj txqb6IssBbgRPdnEtdzxb6ZemMrbfAF3nZO8HisODuRcU1Z45uUHAxPeenbCJkanjb7N eypMLLosVDTca8XBq6RGqn1kxQiPiyfBiCzykKK1XNtu/HqCsCFkSIpCMW3Q/g2cLZbs Sk7w== X-Forwarded-Encrypted: i=1; AJvYcCW7N2WAHwxAbzOMQCE1ut4OzoiSu/QC8MIisJuAMCj0j8NlYu7V980p0B/QtZhna1NGNGGpFG7MN+vpL18VjtFpEt/GyeKKsCbgmga0 X-Gm-Message-State: AOJu0YxLt0rcXBMSi9Lg4gd4wU1vF+c2ioJ73x6V8eFKGPIGTD5l1rrv Usr7SRNG2nk3KzWEYrD+28sBZmOZxjO8Awc7EzXpoZFFxgNCb9iuKoK/X1NOFqY= X-Google-Smtp-Source: AGHT+IE/uRJXmSDsmVcdvvQtha1dgj/hFQ8X8ftxAxzYl4tzNY8SQCryfk2c7wi8S6k4aalqlMt/mQ== X-Received: by 2002:a05:6830:120c:b0:6e4:7be4:393a with SMTP id r12-20020a056830120c00b006e47be4393amr14448289otp.5.1709088372243; Tue, 27 Feb 2024 18:46:12 -0800 (PST) Received: from C02CV19DML87.bytedance.net ([240e:6b1:c0:120::1:d]) by smtp.gmail.com with ESMTPSA id 9-20020a631249000000b005dcbb699abfsm6489072pgs.34.2024.02.27.18.46.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 18:46:11 -0800 (PST) From: Rui Qi To: bp@alien8.de, mingo@redhat.com, tglx@linutronix.de, hpa@zytor.com, jpoimboe@redhat.com, peterz@infradead.org, mbenes@suse.cz, gregkh@linuxfoundation.org, stable@vger.kernel.org, alexandre.chartre@oracle.com Cc: x86@kernel.org, linux-kernel@vger.kernel.org, yuanzhu@bytedance.com, Rui Qi Subject: [PATCH v2 2/3] objtool: Add support for intra-function calls Date: Wed, 28 Feb 2024 10:45:34 +0800 Message-Id: <20240228024535.79980-3-qirui.001@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20240228024535.79980-1-qirui.001@bytedance.com> References: <20240228024535.79980-1-qirui.001@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Alexandre Chartre commit 8aa8eb2a8f5b3305a95f39957dd2b715fa668e21 upstream. Change objtool to support intra-function calls. On x86, an intra-function call is represented in objtool as a push onto the stack (of the return address), and a jump to the destination address. That way the stack information is correctly updated and the call flow is still accurate. Signed-off-by: Alexandre Chartre Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Miroslav Benes Acked-by: Josh Poimboeuf Link: https://lkml.kernel.org/r/20200414103618.12657-4-alexandre.chartre@or= acle.com Signed-off-by: Rui Qi --- include/linux/frame.h | 11 ++++ .../Documentation/stack-validation.txt | 8 +++ tools/objtool/arch/x86/decode.c | 6 ++ tools/objtool/check.c | 62 +++++++++++++++++-- 4 files changed, 83 insertions(+), 4 deletions(-) diff --git a/include/linux/frame.h b/include/linux/frame.h index 02d3ca2d9598..303cda600e56 100644 --- a/include/linux/frame.h +++ b/include/linux/frame.h @@ -15,9 +15,20 @@ static void __used __section(.discard.func_stack_frame_non_standard) \ *__func_stack_frame_non_standard_##func =3D func =20 +/* + * This macro indicates that the following intra-function call is valid. + * Any non-annotated intra-function call will cause objtool to issue a war= ning. + */ +#define ANNOTATE_INTRA_FUNCTION_CALL \ + 999: \ + .pushsection .discard.intra_function_calls; \ + .long 999b; \ + .popsection; + #else /* !CONFIG_STACK_VALIDATION */ =20 #define STACK_FRAME_NON_STANDARD(func) +#define ANNOTATE_INTRA_FUNCTION_CALL =20 #endif /* CONFIG_STACK_VALIDATION */ =20 diff --git a/tools/objtool/Documentation/stack-validation.txt b/tools/objto= ol/Documentation/stack-validation.txt index de094670050b..ee26bb382b70 100644 --- a/tools/objtool/Documentation/stack-validation.txt +++ b/tools/objtool/Documentation/stack-validation.txt @@ -290,6 +290,14 @@ they mean, and suggestions for how to fix them. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D70646 =20 =20 +11. file.o: warning: unannotated intra-function call + + This warning means that a direct call is done to a destination which + is not at the beginning of a function. If this is a legit call, you + can remove this warning by putting the ANNOTATE_INTRA_FUNCTION_CALL + directive right before the call. + + If the error doesn't seem to make sense, it could be a bug in objtool. Feel free to ask the objtool maintainer for help. =20 diff --git a/tools/objtool/arch/x86/decode.c b/tools/objtool/arch/x86/decod= e.c index a62e032863a8..c3ff62c085c8 100644 --- a/tools/objtool/arch/x86/decode.c +++ b/tools/objtool/arch/x86/decode.c @@ -437,6 +437,12 @@ int arch_decode_instruction(struct elf *elf, struct se= ction *sec, =20 case 0xe8: *type =3D INSN_CALL; + /* + * For the impact on the stack, a CALL behaves like + * a PUSH of an immediate value (the return address). + */ + op->src.type =3D OP_SRC_CONST; + op->dest.type =3D OP_DEST_PUSH; break; =20 case 0xfc: diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 71a24fd46dbd..0fa414869f45 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -645,6 +645,7 @@ static int add_jump_destinations(struct objtool_file *f= ile) return 0; } =20 + /* * Find the destination instructions for all calls. */ @@ -666,10 +667,7 @@ static int add_call_destinations(struct objtool_file *= file) dest_off); =20 if (!insn->call_dest && !insn->ignore) { - WARN_FUNC("unsupported intra-function call", - insn->sec, insn->offset); - if (retpoline) - WARN("If this is a retpoline, please patch it in with alternatives an= d annotate it with ANNOTATE_NOSPEC_ALTERNATIVE."); + WARN_FUNC("unannotated intra-function call", insn->sec, insn->offset); return -1; } =20 @@ -1291,6 +1289,58 @@ static int read_retpoline_hints(struct objtool_file = *file) return 0; } =20 + +static int read_intra_function_calls(struct objtool_file *file) +{ + struct instruction *insn; + struct section *sec; + struct rela *rela; + + sec =3D find_section_by_name(file->elf, ".rela.discard.intra_function_cal= ls"); + if (!sec) + return 0; + + list_for_each_entry(rela, &sec->rela_list, list) { + unsigned long dest_off; + + if (rela->sym->type !=3D STT_SECTION) { + WARN("unexpected relocation symbol type in %s", + sec->name); + return -1; + } + + insn =3D find_insn(file, rela->sym->sec, rela->addend); + if (!insn) { + WARN("bad .discard.intra_function_call entry"); + return -1; + } + + if (insn->type !=3D INSN_CALL) { + WARN_FUNC("intra_function_call not a direct call", + insn->sec, insn->offset); + return -1; + } + + /* + * Treat intra-function CALLs as JMPs, but with a stack_op. + * See add_call_destinations(), which strips stack_ops from + * normal CALLs. + */ + insn->type =3D INSN_JUMP_UNCONDITIONAL; + + dest_off =3D insn->offset + insn->len + insn->immediate; + insn->jump_dest =3D find_insn(file, insn->sec, dest_off); + if (!insn->jump_dest) { + WARN_FUNC("can't find call dest at %s+0x%lx", + insn->sec, insn->offset, + insn->sec->name, dest_off); + return -1; + } + } + + return 0; +} + static void mark_rodata(struct objtool_file *file) { struct section *sec; @@ -1346,6 +1396,10 @@ static int decode_sections(struct objtool_file *file) if (ret) return ret; =20 + ret =3D read_intra_function_calls(file); + if (ret) + return ret; + ret =3D add_call_destinations(file); if (ret) return ret; --=20 2.39.2 (Apple Git-143) From nobody Sun Feb 8 10:04:36 2026 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8EAA4208D3 for ; Wed, 28 Feb 2024 02:46:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709088381; cv=none; b=AGZlbW3EZ2FIE2+r2sEuAB7Nfs6NWG+JPDTOmxQz7K09rnUBKe01Vf2jsEdR+EfGOFmLQ/TUNkTHp5Owlr7cPIHZrtXiy25DvyKe6SF1qEObnt+Q5KYYQuZDsK8B2/sdizrUA/YOQIkcS9xVxBsU5UonOiA6rtVBRxaKuz5iPM4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709088381; c=relaxed/simple; bh=mQFH/SJP37/K0A+bzRwDW5rArc1AI8HylzyhxGDcshA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=D91JLMDQ2G5EtVzrp7XDJnwIa0OhvczCmStBZY6dUrUXuKw05a8XhJsfel070fmSEOu7+71m4tWHUJ8zry7OpVgwm5xL+ys7NUPYBBvvi2XYsSMSeMJCizqUwTrkppvvhqNaJX3a7MaUz8f0ojSN2jYo5iSpVEeWB0Dty6+vfBA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=lpxQv5Wy; arc=none smtp.client-ip=209.85.210.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="lpxQv5Wy" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-6e56787e691so21391b3a.0 for ; Tue, 27 Feb 2024 18:46:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1709088379; x=1709693179; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=83r4EAUoTO5ZvgsfPp7swXodejXzXtH9eGtsARrhgv4=; b=lpxQv5WyDQS4nhy+Fa4qPpO5Y8GBEmL7icgkvkbgAPWKIzNAWss7vbfnY3yesoxNhb WHelhMQt6jI4Im7acXl4SQK41KMGMI6n0sWF4AfT0WiZkFmCAmzM34iK2qwDTTmcjSh0 Kezt4wE65acTJ/yO2zQeX0You+kcO1wwny1ybvJdfmDhSuoPWqr5e5G7aD9nhS7CQMN7 jUMyqmv1Sa4FeUc3QoUK0I5XaRROuQJCVOSZCvYNdnfwBKlAcYOhRtgFI60NsW9Gzk4T SyjR9X2gfpsgJ6TzVaj0pu+M2K3uGYQc7dp6jCDeKlWGrdJpeSslWDRWIVAMUbVmLcJQ fCsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709088379; x=1709693179; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=83r4EAUoTO5ZvgsfPp7swXodejXzXtH9eGtsARrhgv4=; b=vy6MAyZxS2AXf/dHu8Qoby95fhK7xfK7ld/5IKtWficrp4FRJzjjXQe6e/3jn5V9MQ RAG3vGiBOCEszLsOALzkwBEyq5JBXhJ8KKI+YNVPejFUi3gTNPVOVwuamA4Fbg3X5+mX iT4vWu/aLOxl2/+/cz6GsaCr70q2B29kSpgARNC9VKzsIlN5BVmo9UPorBWbjDgPX2Rh C7s+f7DU3xCrBb3jbC4ft8h/B0TENmZd3skacCOLzVy0h1anHEtz198GEQTfeEUb9MBw utsQv171tyoKhkRNA2x68ocN8PKLCvvBMg+Wn+nJbOUdNfVUFQDAN/a0jef+Jb85g06j pPBg== X-Forwarded-Encrypted: i=1; AJvYcCVCwdFfl5JRgbcRSYjqmvvRdPIPuY/nOjhB34j9Gn7fh0nIdqha8apWev+r+6wtPQ8tiNz0IrHraWNBkpBbcYCq1AS7wcrmGLKrpJ9t X-Gm-Message-State: AOJu0YziJEojP9bxwBzoxlMQba9OyG1BT/f94Qy0rtRJ3XxdOVYKuk4P WTqNGIN0P2IG7J5jZCEMlCGI9tlXuk3O4pCasWrDVwQOm2uuAlXZ60yhwdWuZkA= X-Google-Smtp-Source: AGHT+IEy7061izEiARgGqc03Y4bU0MeVp4lQZod32fmca+lUIcc+h7BUudY1MtuW9QrEAQLNJql5ZA== X-Received: by 2002:a05:6a20:93a7:b0:1a0:e6c6:fa with SMTP id x39-20020a056a2093a700b001a0e6c600famr1843559pzh.7.1709088378981; Tue, 27 Feb 2024 18:46:18 -0800 (PST) Received: from C02CV19DML87.bytedance.net ([240e:6b1:c0:120::1:d]) by smtp.gmail.com with ESMTPSA id 9-20020a631249000000b005dcbb699abfsm6489072pgs.34.2024.02.27.18.46.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 18:46:18 -0800 (PST) From: Rui Qi To: bp@alien8.de, mingo@redhat.com, tglx@linutronix.de, hpa@zytor.com, jpoimboe@redhat.com, peterz@infradead.org, mbenes@suse.cz, gregkh@linuxfoundation.org, stable@vger.kernel.org, alexandre.chartre@oracle.com Cc: x86@kernel.org, linux-kernel@vger.kernel.org, yuanzhu@bytedance.com, Rui Qi Subject: [PATCH v2 3/3] x86/speculation: Support intra-function call validation Date: Wed, 28 Feb 2024 10:45:35 +0800 Message-Id: <20240228024535.79980-4-qirui.001@bytedance.com> X-Mailer: git-send-email 2.39.2 (Apple Git-143) In-Reply-To: <20240228024535.79980-1-qirui.001@bytedance.com> References: <20240228024535.79980-1-qirui.001@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" commit 8afd1c7da2b0 ("x86/speculation: Change FILL_RETURN_BUFFER to work with objtool") does not support intra-function call stack validation, which causes kernel live patching to fail. This commit adds support for this, and after testing, the kernel live patching feature is restored to normal. Fixes: 8afd1c7da2b0 ("x86/speculation: Change FILL_RETURN_BUFFER to work wi= th objtool") Cc: # v5.4.250+ Signed-off-by: Rui Qi --- arch/x86/include/asm/nospec-branch.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/no= spec-branch.h index c8819358a332..a88135c358c0 100644 --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -13,6 +13,8 @@ #include #include =20 +#include +#include /* * This should be used immediately before a retpoline alternative. It tells * objtool where the retpolines are so that it can make sense of the contr= ol @@ -51,14 +53,18 @@ #define __FILL_RETURN_BUFFER(reg, nr, sp) \ mov $(nr/2), reg; \ 771: \ + ANNOTATE_INTRA_FUNCTION_CALL; \ call 772f; \ 773: /* speculation trap */ \ + UNWIND_HINT_EMPTY; \ pause; \ lfence; \ jmp 773b; \ 772: \ + ANNOTATE_INTRA_FUNCTION_CALL; \ call 774f; \ 775: /* speculation trap */ \ + UNWIND_HINT_EMPTY; \ pause; \ lfence; \ jmp 775b; \ @@ -152,6 +158,7 @@ .endm =20 .macro ISSUE_UNBALANCED_RET_GUARD + ANNOTATE_INTRA_FUNCTION_CALL; call .Lunbalanced_ret_guard_\@ int3 .Lunbalanced_ret_guard_\@: --=20 2.39.2 (Apple Git-143)