From patchwork Tue Jan 10 12:03:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 41426 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2705229wrt; Tue, 10 Jan 2023 04:05:27 -0800 (PST) X-Google-Smtp-Source: AMrXdXtW2ZZtdh5/U36qCXyE1eu0wj02/9xJZeY35ZI8tJXltQW+cCryKzZffPDnHW8LolIgFS1X X-Received: by 2002:a17:90b:104f:b0:226:fa8c:e50a with SMTP id gq15-20020a17090b104f00b00226fa8ce50amr10309494pjb.35.1673352327304; Tue, 10 Jan 2023 04:05:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673352327; cv=none; d=google.com; s=arc-20160816; b=hVQOfInL0A7eeYkQadKQcBUzzZ0DZwnLUFLq0YP5P0XbP6E3BggQ2oY0O4nS+6lR84 8R1nSkXInu7Anc0pxmyQDxWjZpFGKMbuOln6SfFaFFUYd/4yFdxewu32wgOBYsJDYFav iPwkSEzMfXWwMh/6g2M2iKyuG1H0M17ij8xEaTQGPbaQFfJEPB/pU6od00ggoZ7sRc+l piG8BubNAWg2crYzAV3JYvQft5QYDP1a2mHGlBdVEM6yOrQ0v5hiv6QbjQ9WNsvmmCPb bxj2sfQPGYrnKYzD9t8npTUYZd8Zrp+Tmsihz2FwxbmWK8iT/MJuhc8kpscNz1AljQUV mXnA== 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 header.s=2020e header.b=0KNuPmwo; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q6-20020a635046000000b004929e9090b6si10849484pgl.828.2023.01.10.04.05.15; Tue, 10 Jan 2023 04:05:27 -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 header.s=2020e header.b=0KNuPmwo; 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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750819771766311077?= X-GMAIL-MSGID: =?utf-8?q?1754637090311606418?= 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))