From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DA417C3DA41 for ; Tue, 9 Jul 2024 10:05:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=KQrMhlVBL3z8RrJgNHSkFa1QtVXsnFbCCfDGQ3WjGvo=; b=VkJnnYM437WwbYa9xiMtcG38u4 vWROcANzLItrgZzyzQOYly6+RN3UwRnNvyS3tJidWQBudyaMgyt1rwuEPUukIM7Iaqz8mG6O6Wq8p Gk9zFrpolNNR1mAmXVUrw4rm6B+0KYfF+FxN1/B/lVQ4e3mCn0ZLNUBhrcwUCrFUTiQrn6DbHZMkr lgWCimUcyvMVZVAAeCbHMtT/nRsqz1UC3kBxDNlbGy5dY8XowOjVo6OzzsNnAC0iZH1SWYi4YZgFV NU+Dd5hw+wDx1yt5lYQejSK8CToJGGzPB+LyG1sOAZO4hd4iq5UDLBDEhmthz6xteyiDScOCbCiM5 B9zN8TcQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sR7j8-00000006jRN-3eE1; Tue, 09 Jul 2024 10:05:38 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sR7is-00000006jMu-1z5R for linux-arm-kernel@lists.infradead.org; Tue, 09 Jul 2024 10:05:23 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id D4DF360F80; Tue, 9 Jul 2024 10:05:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 60963C3277B; Tue, 9 Jul 2024 10:05:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720519521; bh=adwdFXqIUIzPu8uQo4yWNR59n+TVdE5/QzTHYlgT4Z8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=axsmg7yf+1yjLnsJh8Jj6P1cLgosBDQI5K0LjNBSjXcZXDhgpoaBRBAFzByzXJjgU wPV75u4MMWyGxzd9MIHgjZQJcttfLicyP8qNwh8FTMFPhOJYpuRXwJh4Af0n4j71kX FhxBzEFxZYP2fWAJwkMEcOulo4aONV6c2O3nFzZgJoiQ9VnHxdKg5OW+tq9AH2JHOW jiY3f3jf3D0rYlsK+hvL/L4+dkOrS5EwsbxZAP9oDyC0J5bAZtltH7BafOEPV2CC8g uga47XTb1fB+U+N6IzpG6nR8VMDBIFWECs+URBBkurw/c6vLLpN47GOP/huLpRlBbP OPwoMK4ZqvyVw== Date: Tue, 9 Jul 2024 11:05:16 +0100 From: Will Deacon To: Tiezhu Yang Cc: Mark Rutland , Russell King , Catalin Marinas , Oleg Nesterov , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 3/3] arm64: hw_breakpoint: Save privilege of access control via ptrace Message-ID: <20240709100515.GB12978@willie-the-truck> References: <20240709095506.9691-1-yangtiezhu@loongson.cn> <20240709095506.9691-4-yangtiezhu@loongson.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240709095506.9691-4-yangtiezhu@loongson.cn> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240709_030522_616625_7497784E X-CRM114-Status: GOOD ( 26.20 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Jul 09, 2024 at 05:55:06PM +0800, Tiezhu Yang wrote: > In the current code, decode_ctrl_reg() saves the privilege of access > control passed by the ptrace user data, but it is not used anymore, > arch_build_bp_info() checks whether bp virtual address is in kernel > space to construct hw->ctrl.privilege, it seems not reasonable. > > The value of ctrl->privilege saved in decode_ctrl_reg() can be used > in arch_build_bp_info(), there is no need to check bp virtual address > to assign value for hw->ctrl.privilege, just make use of "bp_priv" in > the struct perf_event_attr to save the privilege of access control via > ptrace for hardware breakpoint. > > Signed-off-by: Tiezhu Yang > --- > arch/arm64/kernel/hw_breakpoint.c | 11 ++--------- > arch/arm64/kernel/ptrace.c | 2 ++ > 2 files changed, 4 insertions(+), 9 deletions(-) > > diff --git a/arch/arm64/kernel/hw_breakpoint.c b/arch/arm64/kernel/hw_breakpoint.c > index 722ac45f9f7b..06e34bcdcf92 100644 > --- a/arch/arm64/kernel/hw_breakpoint.c > +++ b/arch/arm64/kernel/hw_breakpoint.c > @@ -486,15 +486,8 @@ static int arch_build_bp_info(struct perf_event *bp, > /* Address */ > hw->address = attr->bp_addr; > > - /* > - * Privilege > - * Note that we disallow combined EL0/EL1 breakpoints because > - * that would complicate the stepping code. > - */ Just because you remove the comment doesn't mean that constraint no longer applies. > - if (arch_check_bp_in_kernelspace(hw)) > - hw->ctrl.privilege = AARCH64_BREAKPOINT_EL1; > - else > - hw->ctrl.privilege = AARCH64_BREAKPOINT_EL0; > + /* Privilege */ > + hw->ctrl.privilege = attr->bp_priv; > > /* Enabled? */ > hw->ctrl.enabled = !attr->disabled; > diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c > index 0d022599eb61..3b37c4a2e0d4 100644 > --- a/arch/arm64/kernel/ptrace.c > +++ b/arch/arm64/kernel/ptrace.c > @@ -309,6 +309,7 @@ static struct perf_event *ptrace_hbp_create(unsigned int note_type, > attr.bp_addr = 0; > attr.bp_len = HW_BREAKPOINT_LEN_4; > attr.bp_type = type; > + attr.bp_priv = AARCH64_BREAKPOINT_EL0; > attr.disabled = 1; > > bp = register_user_hw_breakpoint(&attr, ptrace_hbptriggered, NULL, tsk); > @@ -352,6 +353,7 @@ static int ptrace_hbp_fill_attr_ctrl(unsigned int note_type, > attr->bp_len = len; > attr->bp_type = type; > attr->bp_addr += offset; > + attr->bp_priv = ctrl.privilege; Wait, so ptrace can now set breakpoints with arbitrary privileges? Will