Received: by 2002:a05:7412:9c07:b0:fa:6e18:a558 with SMTP id lr7csp521690rdb; Sat, 27 Jan 2024 18:22:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IGmvU3p01xi2N9Bi8xV54BXehK3mxyXLt3kQ1u9hA3FPZx7cZxuKHDusJBT88mcpF2kFvfW X-Received: by 2002:a17:906:7117:b0:a35:3624:7f91 with SMTP id x23-20020a170906711700b00a3536247f91mr1632751ejj.11.1706408551094; Sat, 27 Jan 2024 18:22:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706408551; cv=pass; d=google.com; s=arc-20160816; b=nVYbwR5I73v6Yi2BD/UYOyQatD63rD1dYGvtlqcn3DRBLk/3ujvBOBmMnCwcJgbtll YjNYHnXuvoLTEMCMtFRvIA1p+BMRNoqQlDu5Gb+vNT4sRpdMiruZq5ettCu991B6+KUF ebKw5hWOo85JLHJkfgFM0QTEgg0s9ATHDE/1oB3XXCp9GLKN/1TEAKpE4CAA/dYD3ez6 +wBMHxwHFRx1x46nfbUnPTaRMxc7xlYiAUO0tjI2ufC/2J5b2kKFLY4fVJIdvGeXKqUl BbGtarwD+OuMmCUyLWVbWIGH/ECLYCcINxcCkWBafg+5/RGdkxukKAMxueeV5m9hNTrZ N29A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=ssULbmnVlsXEwC0hazMK5XPIkWQ7KnNS+o1eANK0Aok=; fh=aQ6xdtKm40b9V1iEDYhFPH4GPq1qi4o5cLJf1fitBXQ=; b=OMJ+yDvZU4kHCWMNvRlkx/0R28vg2v/OoBTRuEmj+j02mJfX6XQBzoM/fmXaK9Oc1I BiWRw2/DfOfliCrL6xvOkUzj/7kpiEyIOeCjj1x8iueDC1NL/Dl7qDxwig0rB/J9/Jqz MHyn19zJehxsMvIAZu4fiTal4FYVJ3/EgZVU2WY8hEwn6O8XlYCctr/9f8lq8y56glFE XrVRMvSL5aE/LXkB/nkmr4er1N2BS/FKfVkYJL30OnSYoLFBPoP7diyQHiEyk5/1fbAY 3w7umCJSNqYRgs/BmQC2FaXRkgBE+Leq6S2kYkSSW9aGJfHnIrNmwqb7uq+l6BFsVqK9 21xQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hRwawFlS; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-41511-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-41511-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id l11-20020a1709066b8b00b00a31a3b06524si2034376ejr.284.2024.01.27.18.22.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Jan 2024 18:22:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-41511-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hRwawFlS; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-41511-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-41511-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D7BDB1F22324 for ; Sun, 28 Jan 2024 02:22:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 78C63D529; Sun, 28 Jan 2024 02:22:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hRwawFlS" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B73ED50F; Sun, 28 Jan 2024 02:22:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706408543; cv=none; b=TV2ObwjKNCl7Izg06/OOBiv+Kl4fcGpw622LduvkYUxkwF2vHoxnHDRVuDm728DMDbIBo3qSfa5hYVgB5ccEhOUOjQ7vEK/XeL6qYHNbe3KEe0gyUWHfbIsfz80ookG/Td5KagKYIEl9V+lfaAhrBA/nWRYRKj72x0W30p0X/+0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706408543; c=relaxed/simple; bh=fmpywCD1VwV5A7MN7G8XJu/ucLi0MClww0i57yZt/Wo=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=usFH9Tiz60rQsaWI8K1/+02Vur2SdS1q/WeXb8ehPCUQB3gIkb7LUfOuSyzSgfs2lAH0oPW5Z1Wt5N9LM8lAeyeGs1HE1FFXZZMR2zLbwS1mnJPrVAJ+YMcvBqVXHgWSyExb76S49SmYuKdCO0DU9ZiICV2ig77vW9FuOWtDhmg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hRwawFlS; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 828BBC433C7; Sun, 28 Jan 2024 02:22:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706408543; bh=fmpywCD1VwV5A7MN7G8XJu/ucLi0MClww0i57yZt/Wo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=hRwawFlSEhrC1j7FlEsG1+1Cb/nAbSliSYlnPdDkoPMf0dnOQruOjOpJ/zuVN9VIN G0eQREik3zrYXqDuxKkyvLsB7TA8u7ef/AbhYBsCzuyw0xD6rRtFO0UCk9Rh2nr1Li xzkotVVPPqSOSX04hNqjVVrf2nTZCFQjy9ENiuRQaVDCRW38hFZonG4TI4NrNTdXui PwmLKAL0dYrgcNffrPP6deDBgmTPthHtgJ7uJBitNLCM7naZdDq5JdEeWLs97WoMze MwYjRpB/VjDg2nOHpmnPXlMRUUzAZoXH5R5mkJ0bqU6R4PpUHRF4Q7HeadqKWjkNc3 VcqHP2jpwqWxg== Date: Sun, 28 Jan 2024 11:22:18 +0900 From: Masami Hiramatsu (Google) To: Jinghao Jia Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Peter Zijlstra , linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH 2/2] x86/kprobes: boost more instructions from grp2/3/4/5 Message-Id: <20240128112218.5501726d17ac2fde2502da44@kernel.org> In-Reply-To: <20240127044124.57594-3-jinghao7@illinois.edu> References: <20240127044124.57594-1-jinghao7@illinois.edu> <20240127044124.57594-3-jinghao7@illinois.edu> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 26 Jan 2024 22:41:24 -0600 Jinghao Jia wrote: > With the instruction decoder, we are now able to decode and recognize > instructions with opcode extensions. There are more instructions in > these groups that can be boosted: > > Group 2: ROL, ROR, RCL, RCR, SHL/SAL, SHR, SAR > Group 3: TEST, NOT, NEG, MUL, IMUL, DIV, IDIV > Group 4: INC, DEC (byte operation) > Group 5: INC, DEC (word/doubleword/quadword operation) > > These instructions are not boosted previously because there are reserved > opcodes within the groups, e.g., group 2 with ModR/M.nnn == 110 is > unmapped. As a result, kprobes attached to them requires two int3 traps > as being non-boostable also prevents jump-optimization. > > Some simple tests on QEMU show that after boosting and jump-optimization > a single kprobe on these instructions with an empty pre-handler runs 10x > faster (~1000 cycles vs. ~100 cycles). > > Since these instructions are mostly ALU operations and do not touch > special registers like RIP, let's boost them so that we get the > performance benefit. > As far as we check the ModR/M byte, I think we can safely run these instructions on trampoline buffer without adjusting results (this means it can be "boosted"). I just have a minor comment, but basically this looks good to me. Reviewed-by: Masami Hiramatsu (Google) > Signed-off-by: Jinghao Jia > --- > arch/x86/kernel/kprobes/core.c | 21 +++++++++++++++------ > 1 file changed, 15 insertions(+), 6 deletions(-) > > diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c > index 792b38d22126..f847bd9cc91b 100644 > --- a/arch/x86/kernel/kprobes/core.c > +++ b/arch/x86/kernel/kprobes/core.c > @@ -169,22 +169,31 @@ int can_boost(struct insn *insn, void *addr) > case 0x62: /* bound */ > case 0x70 ... 0x7f: /* Conditional jumps */ > case 0x9a: /* Call far */ > - case 0xc0 ... 0xc1: /* Grp2 */ > case 0xcc ... 0xce: /* software exceptions */ > - case 0xd0 ... 0xd3: /* Grp2 */ > case 0xd6: /* (UD) */ > case 0xd8 ... 0xdf: /* ESC */ > case 0xe0 ... 0xe3: /* LOOP*, JCXZ */ > case 0xe8 ... 0xe9: /* near Call, JMP */ > case 0xeb: /* Short JMP */ > case 0xf0 ... 0xf4: /* LOCK/REP, HLT */ > - case 0xf6 ... 0xf7: /* Grp3 */ > - case 0xfe: /* Grp4 */ > /* ... are not boostable */ > return 0; > + case 0xc0 ... 0xc1: /* Grp2 */ > + case 0xd0 ... 0xd3: /* Grp2 */ > + /* ModR/M nnn == 110 is reserved */ > + return X86_MODRM_REG(insn->modrm.bytes[0]) != 6; > + case 0xf6 ... 0xf7: /* Grp3 */ > + /* ModR/M nnn == 001 is reserved */ /* AMD uses nnn == 001 as TEST, but Intel makes it reserved. */ > + return X86_MODRM_REG(insn->modrm.bytes[0]) != 1; > + case 0xfe: /* Grp4 */ > + /* Only inc and dec are boostable */ > + return X86_MODRM_REG(insn->modrm.bytes[0]) == 0 || > + X86_MODRM_REG(insn->modrm.bytes[0]) == 1; > case 0xff: /* Grp5 */ > - /* Only indirect jmp is boostable */ > - return X86_MODRM_REG(insn->modrm.bytes[0]) == 4; > + /* Only inc, dec, and indirect jmp are boostable */ > + return X86_MODRM_REG(insn->modrm.bytes[0]) == 0 || > + X86_MODRM_REG(insn->modrm.bytes[0]) == 1 || > + X86_MODRM_REG(insn->modrm.bytes[0]) == 4; > default: > return 1; > } > -- > 2.43.0 > Thamnk you, -- Masami Hiramatsu (Google)