Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp303296ybb; Tue, 31 Mar 2020 23:52:54 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtyXQk6ykSVa27sINuyQna2uxKakt9aZFJ5DXRo76/9Rk+rBZyd1f+PuzgbRlY6zYuDj6DN X-Received: by 2002:a05:6830:1556:: with SMTP id l22mr16822493otp.61.1585723973946; Tue, 31 Mar 2020 23:52:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585723973; cv=none; d=google.com; s=arc-20160816; b=LVFIrEefE/RIg6C7hXemUdGlrC1wJGbLGxDbKSW316G7DmYfmq7qyfD2DtHL4HmmXF SNoylEDEjwhoSHlmhpzfj5crjoobqvfQ+nivf60VqD62IL8JdoeFM4eWgraTSfHDJ737 5TD9hVQoavVWTQfaZLE15/8/1mZup21Ey7gXD4X3sg0Hlv7+pAFoqh5MI2nFKVHrCxGu fNnMaeDB6jNlkjHorH1Gpxe/WPpfXUv/6BE9cHfqKeEHVGQR860MEmTiNthEstl6f83o irx9Uum5QCEOsbjv2ZjOHkHcYn9bm9B7/H1sV5qDocEgrlbiIUEA5hosklwO1O408lLq 3yEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=7IkbZ0/SJ5cqCbVKE4dlHc2ETYKSRoSACmPbMq5apUI=; b=SUbRc6/IEyLiSv+3f0e5j5Fg+zKAQKcRljgpka2BL+Abeufn/0l9aPiDna/eD49cV7 l0tGZAkp59e8RTKVEXvCsv+3oPMpEMQbJoeUms0J5ZW8r9p7Snibz4MoECHh0OMui0RP VeWvSsFt/gPbPsk40fCiuTl+iU1dWMFmjaJMN6DDk9ZD4RwHcOIwJ1ns+JNvfmQqCsa/ AuR8ucBt74E7wSeW1j+tZl2YPMulfoDDpdsdLbwSH4z2ZvTSWQL9PUQ1Vcfk2eAfbfuu kdkRb8hESXBRt+9QE0xZzxDqZFHVJyiq5nB0C1a49GMU237BZRqf+hedPDbeDqbfBQbY RHkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=uKCtURhk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 94si436642otb.114.2020.03.31.23.52.42; Tue, 31 Mar 2020 23:52:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=uKCtURhk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731830AbgDAGwX (ORCPT + 99 others); Wed, 1 Apr 2020 02:52:23 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:60353 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730426AbgDAGwW (ORCPT ); Wed, 1 Apr 2020 02:52:22 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 48scM75K1Yz9v9vR; Wed, 1 Apr 2020 08:52:19 +0200 (CEST) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=uKCtURhk; dkim-adsp=pass; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id pkk-w7syNar8; Wed, 1 Apr 2020 08:52:19 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 48scM74Dztz9v9vQ; Wed, 1 Apr 2020 08:52:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1585723939; bh=7IkbZ0/SJ5cqCbVKE4dlHc2ETYKSRoSACmPbMq5apUI=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=uKCtURhk9VySMoUKC7IdGaSLslnuD04Hc/f1wvirLysE+LofPSqG4Ru+oy1X584OA Ho5LjEXmoS9Iy/7OhPK0b6FtP4ICffUTwbPdBj1pxzeSbKS4puywcwgMLUTDUz5tpQ zJJWxoiAP6KGUeKkQHvQ+9eJpJk3GWKXL8OZz9AU= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 2A7C58B7B5; Wed, 1 Apr 2020 08:52:20 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id Kh4vKqmamd0L; Wed, 1 Apr 2020 08:52:20 +0200 (CEST) Received: from [192.168.4.90] (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id A21438B778; Wed, 1 Apr 2020 08:52:18 +0200 (CEST) Subject: Re: [PATCH v2 14/16] powerpc/watchpoint: Don't allow concurrent perf and ptrace events To: Ravi Bangoria , mpe@ellerman.id.au, mikey@neuling.org Cc: apopple@linux.ibm.com, paulus@samba.org, npiggin@gmail.com, naveen.n.rao@linux.vnet.ibm.com, peterz@infradead.org, jolsa@kernel.org, oleg@redhat.com, fweisbec@gmail.com, mingo@kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org References: <20200401061309.92442-1-ravi.bangoria@linux.ibm.com> <20200401061309.92442-15-ravi.bangoria@linux.ibm.com> From: Christophe Leroy Message-ID: Date: Wed, 1 Apr 2020 08:52:16 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <20200401061309.92442-15-ravi.bangoria@linux.ibm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 01/04/2020 à 08:13, Ravi Bangoria a écrit : > With Book3s DAWR, ptrace and perf watchpoints on powerpc behaves > differently. Ptrace watchpoint works in one-shot mode and generates > signal before executing instruction. It's ptrace user's job to > single-step the instruction and re-enable the watchpoint. OTOH, in > case of perf watchpoint, kernel emulates/single-steps the instruction > and then generates event. If perf and ptrace creates two events with > same or overlapping address ranges, it's ambiguous to decide who > should single-step the instruction. Because of this issue, don't > allow perf and ptrace watchpoint at the same time if their address > range overlaps. > > Signed-off-by: Ravi Bangoria > --- > arch/powerpc/include/asm/hw_breakpoint.h | 2 + > arch/powerpc/kernel/hw_breakpoint.c | 222 +++++++++++++++++++++++ > kernel/events/hw_breakpoint.c | 16 ++ > 3 files changed, 240 insertions(+) > > diff --git a/arch/powerpc/include/asm/hw_breakpoint.h b/arch/powerpc/include/asm/hw_breakpoint.h > index abc4603c0efe..9d3bd1169591 100644 > --- a/arch/powerpc/include/asm/hw_breakpoint.h > +++ b/arch/powerpc/include/asm/hw_breakpoint.h > @@ -70,6 +70,8 @@ extern int hw_breakpoint_exceptions_notify(struct notifier_block *unused, > unsigned long val, void *data); > int arch_install_hw_breakpoint(struct perf_event *bp); > void arch_uninstall_hw_breakpoint(struct perf_event *bp); > +int arch_reserve_bp_slot(struct perf_event *bp); > +void arch_release_bp_slot(struct perf_event *bp); > void arch_unregister_hw_breakpoint(struct perf_event *bp); > void hw_breakpoint_pmu_read(struct perf_event *bp); > extern void flush_ptrace_hw_breakpoint(struct task_struct *tsk); > diff --git a/arch/powerpc/kernel/hw_breakpoint.c b/arch/powerpc/kernel/hw_breakpoint.c > index 07a6cdea84ed..f813acb0d9f0 100644 > --- a/arch/powerpc/kernel/hw_breakpoint.c > +++ b/arch/powerpc/kernel/hw_breakpoint.c > @@ -123,6 +123,228 @@ static bool is_ptrace_bp(struct perf_event *bp) > return bp->overflow_handler == ptrace_triggered; > } > > +struct breakpoint { > + struct list_head list; > + struct perf_event *bp; > + bool ptrace_bp; > +}; > + > +static DEFINE_PER_CPU(struct breakpoint *, cpu_bps[HBP_NUM_MAX]); > +static LIST_HEAD(task_bps); > + > +static struct breakpoint *alloc_breakpoint(struct perf_event *bp) > +{ > + struct breakpoint *tmp; > + > + tmp = kzalloc(sizeof(*tmp), GFP_KERNEL); > + if (!tmp) > + return ERR_PTR(-ENOMEM); > + tmp->bp = bp; > + tmp->ptrace_bp = is_ptrace_bp(bp); > + return tmp; > +} > + > +static bool bp_addr_range_overlap(struct perf_event *bp1, struct perf_event *bp2) > +{ > + __u64 bp1_saddr, bp1_eaddr, bp2_saddr, bp2_eaddr; > + > + bp1_saddr = ALIGN_DOWN(bp1->attr.bp_addr, HW_BREAKPOINT_SIZE); > + bp1_eaddr = ALIGN(bp1->attr.bp_addr + bp1->attr.bp_len, HW_BREAKPOINT_SIZE) - 1; > + bp2_saddr = ALIGN_DOWN(bp2->attr.bp_addr, HW_BREAKPOINT_SIZE); > + bp2_eaddr = ALIGN(bp2->attr.bp_addr + bp2->attr.bp_len, HW_BREAKPOINT_SIZE) - 1; > + > + return (bp1_saddr <= bp2_eaddr && bp1_eaddr >= bp2_saddr); Could avoid the - 1 on bp1_eaddr and bp2_eaddr by doing: return (bp1_saddr < bp2_eaddr && bp1_eaddr > bp2_saddr); Christophe