Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp7682646rwl; Tue, 10 Jan 2023 04:09:54 -0800 (PST) X-Google-Smtp-Source: AMrXdXt0jThW+42NINZX8FP0Oc/PasGZFIZRfCPJjdp3mB4B+AjbGBuIJn1M5JpkIkdFkpOyVz+e X-Received: by 2002:aa7:87c7:0:b0:57a:9b14:69b7 with SMTP id i7-20020aa787c7000000b0057a9b1469b7mr65740752pfo.0.1673352594060; Tue, 10 Jan 2023 04:09:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673352594; cv=none; d=google.com; s=arc-20160816; b=OJpULmH4ZXD+udzZNxtakMLRunxVwQrnGvULZmQL1GGpVh393snokMh+XUlVWIitLG ceKR0VlunJXfhVtdS8zwwVsmTEECZTd8yzmCVhCKs10ymxz/Oh/roJhClRdn5bjuc7nt 2b6TfnUjmCMYjRqFl15AXhdklg1+CFO01qAjhubCcaoOr2aEN49sikHWs/mqOhfC1CtI eUEcqTFOvp8FxqAnQgj2mIx1b9uflGnY3S8CsC4cIXD8cAfDPbB8+dCs3zLC8Gi7+kED eeJNfjZDwdzX2hrMtGb6mKOWgZtPX8YOEh9ghKHp9Syd51lwZQ0+8VVyza0C8CzG4J7y YZKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=c9bzLMVcjlWE78ty3QzPuBu9rTI6kERleI5I9S4IWjs=; b=WME9sqqoOTr6AShVT8TskxknfuP4u9qXMiYYtO8D0lTEDIu7/D1x4PGb1Pv72w2bKm 1hH5IeJmT/tFYwQpnjRwLrg5pdELeMg9lRWf0VYMs9qG/mQZ1wVot2GgiezPgq1XNT+A QMPy11u4scygAFerWwHIae/JxVpou65lMsZQ7DzhAqJvqzrjD8Ia6Fw6qvRAtII4ayAl miKMFbtcWHMToZoubOuN36MtkSjL+7WNIlNNd6UbzV3HbPN+V66NHOrwvLuZWkkjbFTZ F8KI/mfCccR9R63SJCjGYxUY6W5yOrOxkZGufCvsoDcCiVWOcb5hTv8BGR5whp/gneWN BIfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=SW21dXGE; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ea24-20020a056a004c1800b005726e8b1cedsi10571716pfb.345.2023.01.10.04.09.47; Tue, 10 Jan 2023 04:09:54 -0800 (PST) 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=@linutronix.de header.s=2020 header.b=SW21dXGE; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238265AbjAJMDo (ORCPT + 55 others); Tue, 10 Jan 2023 07:03:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238332AbjAJMDe (ORCPT ); Tue, 10 Jan 2023 07:03:34 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3876D59323; Tue, 10 Jan 2023 04:03:31 -0800 (PST) Date: Tue, 10 Jan 2023 12:03:28 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1673352208; h=from:from:sender:sender:reply-to: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=c9bzLMVcjlWE78ty3QzPuBu9rTI6kERleI5I9S4IWjs=; b=SW21dXGE5Z2bDw/1ZClLqIa2kd9WMWmVthDvxWB4Awm42IVEi2RWS9jQPgyD8SjYvgG0sq MaePPSJgOvcTmZTiRu5Tt113dE91T4lLvRxYwu0SK7svWCERAw3hsT9+E8SLGkSyIAz+tF R6R4OvTB7Cg3D749MKu46O8KJQalm54wfNLPASVoGU0h6MgDFEyNulj4CuL7Qtn8oXbenr RRc0LmVSit22gGizpqyGCzP1oz/fr29fpDPAfygcEKoWwdmevJrv5xaIDrlPn3+YY8Lggx oZmxLxZGmhcJtUwxoyME5hua/vtWVl6uAZ9BhEdxV3zpiefTEoda9L3J0yqddA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1673352208; h=from:from:sender:sender:reply-to: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=c9bzLMVcjlWE78ty3QzPuBu9rTI6kERleI5I9S4IWjs=; b=0KNuPmwo3VsuqIQTFKb/8z94ZzknCaRYKgzKwQjzXnBbXC9StK++eQifo+Ay8cKUE0Nnru 8TXB88NNtDzj9wCQ== From: "tip-bot2 for Chuang Wang" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/core] x86/kprobes: Use switch-case for 0xFF opcodes in prepare_emulation Cc: Chuang Wang , Ingo Molnar , "Masami Hiramatsu (Google)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20221129084022.718355-1-nashuiliang@gmail.com> References: <20221129084022.718355-1-nashuiliang@gmail.com> MIME-Version: 1.0 Message-ID: <167335220802.4906.8026759221140873503.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 The following commit has been merged into the perf/core branch of tip: Commit-ID: 9fcad995c6c52cc9791f7ee9f1386a5684055f9c Gitweb: https://git.kernel.org/tip/9fcad995c6c52cc9791f7ee9f1386a5684055f9c Author: Chuang Wang AuthorDate: Tue, 29 Nov 2022 16:39:51 +08:00 Committer: Ingo Molnar CommitterDate: Tue, 10 Jan 2023 12:37:14 +01:00 x86/kprobes: Use switch-case for 0xFF opcodes in prepare_emulation For the `FF /digit` opcodes in prepare_emulation, use switch-case instead of hand-written code to make the logic easier to understand. Signed-off-by: Chuang Wang Signed-off-by: Ingo Molnar Acked-by: Masami Hiramatsu (Google) Link: https://lore.kernel.org/r/20221129084022.718355-1-nashuiliang@gmail.com --- arch/x86/kernel/kprobes/core.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c index 33390ed..fd0420a 100644 --- a/arch/x86/kernel/kprobes/core.c +++ b/arch/x86/kernel/kprobes/core.c @@ -655,17 +655,19 @@ static int prepare_emulation(struct kprobe *p, struct insn *insn) * is determined by the MOD/RM byte. */ opcode = insn->modrm.bytes[0]; - if ((opcode & 0x30) == 0x10) { - if ((opcode & 0x8) == 0x8) - return -EOPNOTSUPP; /* far call */ - /* call absolute, indirect */ + switch (X86_MODRM_REG(opcode)) { + case 0b010: /* FF /2, call near, absolute indirect */ p->ainsn.emulate_op = kprobe_emulate_call_indirect; - } else if ((opcode & 0x30) == 0x20) { - if ((opcode & 0x8) == 0x8) - return -EOPNOTSUPP; /* far jmp */ - /* jmp near absolute indirect */ + break; + case 0b100: /* FF /4, jmp near, absolute indirect */ p->ainsn.emulate_op = kprobe_emulate_jmp_indirect; - } else + break; + case 0b011: /* FF /3, call far, absolute indirect */ + case 0b101: /* FF /5, jmp far, absolute indirect */ + return -EOPNOTSUPP; + } + + if (!p->ainsn.emulate_op) break; if (insn->addr_bytes != sizeof(unsigned long))