Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1115271pxb; Thu, 4 Feb 2021 05:37:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJzL5pG4Kur/P2d5QZIbVX0XHCSFZego8BMShnN7mhDfEvHq3+g7rsmLJigMkqtYURCBp57U X-Received: by 2002:a05:6402:2211:: with SMTP id cq17mr7827781edb.167.1612445831354; Thu, 04 Feb 2021 05:37:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612445815; cv=none; d=google.com; s=arc-20160816; b=I8YDIAK5DYXVeerHPJlkQXYAuNUKSaIebEMdMUC2ZpW4Nwxscijstq4Qk+aR7d8ghG c2bu1R+0VZYtCNn1zP27WrVbtGiJ6z7GRL7849W4dY6+Z4qEvXzxNYljGp/T65dUCr7z pejeCGmtdGwQG7nplfZ4F20In3pd64We8q8ER/Dvn0DSHnk1EvsDZhmWL2hb7pqxDbEA LJh/EpSlpunctaJnW/KZZ6Q1QaVBy3O4Ktn67Ge39XIsZTKtRpobrnavvZIbpY4BJyLJ jMt6ViXDWKKECY4mI3fbbOnAABb92tTPaxLp6+A7XMP40quFawGk8IAndY1uLRjaxB/P vTeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=vztDQPMe981rlmhqqOurB7P1kTPr1JQmf5lExFoESKQ=; b=hfUG4YVi+KI2QhTWIeZtXV5HtsBi3Y0PH49p1OIJ7B7RWpH9BYKV8SpDObIZ//Ngj+ xWFIC16JUkH+cjW0RdIxvbSHaolWjqUgTzJt+u10BEEoM9vINul1TVrKEAUyTcFiLCLu msV8LY2LgvGNGzFKzH7WhA2FqEyjzSIMJFdEF6z57K9NcSFfr4Se2cHIH7r2chLTMve8 rKUzNrnYweG+19VgnQ5ROC7YAjoFOlnDo/PWsBUln4Jn8WIxyldap7RPW+100YaBuyx4 DiCgRP/1nsE6Sc5CMCt3oBEIEoXZTnHU/a+DvEGRGu4SqR96kl9TA2x8G5H0aNUTMQ5J 4EYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=JWB6c60a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ly24si3190282ejb.67.2021.02.04.05.36.30; Thu, 04 Feb 2021 05:36:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=JWB6c60a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236328AbhBDNey (ORCPT + 99 others); Thu, 4 Feb 2021 08:34:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236148AbhBDNe2 (ORCPT ); Thu, 4 Feb 2021 08:34:28 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4ADBAC061573 for ; Thu, 4 Feb 2021 05:33:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=vztDQPMe981rlmhqqOurB7P1kTPr1JQmf5lExFoESKQ=; b=JWB6c60a/eNOWPZJcDGyeAh2dC AIjfGTAVeZgmYWjHlVZb7/gJqj1whZqVaNMhzkeuzzYCPfoQhj/CpB7ELuex09w7/5yCn1T0UKZsb Io6817QRJqp/jNaEvaV7slLXWfcGJRvOGFyDl2Ey2G2tyK4NmzmaksQ4AIdraD6DD3zaJEMr37t4P Ju4rZvzapBuT8VMI12Rt8FHGCpnh5Z4ZPG9UVafGfvuzIA5S9+xmcViw+q4Dv/qeu2+tSKWbO6zLV qFZQ3TMlwmig8+mWSzNeuiDxPt/y7kcc5Ur9HYfiuUtfJYDkDX0Q9z+BebUzlz0X0O8ABXLTFpVvN Lag9auPg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1l7elL-000vO1-D1; Thu, 04 Feb 2021 13:33:35 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id BDB4E301CC4; Thu, 4 Feb 2021 14:33:32 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 84EC82C0034BF; Thu, 4 Feb 2021 14:33:32 +0100 (CET) Date: Thu, 4 Feb 2021 14:33:32 +0100 From: Peter Zijlstra To: Dmitry Vyukov Cc: Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Will Deacon , LKML , Matt Morehouse Subject: Re: Process-wide watchpoints Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 04, 2021 at 01:53:59PM +0100, Dmitry Vyukov wrote: > On Thu, Feb 4, 2021 at 1:09 PM Peter Zijlstra wrote: > > What do we do then? The advantage of IOC_REFRESH is that it disables the > > event until it gets explicitly re-armed, avoiding recursion issues etc. > > Do you want those semantics? If so, we'd need to have IOC_REFRESH find > > the actual event for the current task, which should be doable I suppose. > > Frankly, I don't know. I didn't use it in my prototype, nor I fully > understand what it's doing. Does it make sense for breakpoints? > I see IOC_REFRESH has a check for !attr.inherit, so it will fail for > my use case currently. I would say we just leave it as is for now. Well, the way it works is that currently you set event_limit > 0. Then each event will decrement, when we hit 0 we disable and raise a signal. REFRESH will increment event_limit and re-enable. This means you're guaranteed not to get another signal until you're ready for it. It allows leaving the signal handler context to handle the signal. I suppose you're looking for something like this, which goes in top of that thread_only thing. --- a/include/uapi/linux/perf_event.h +++ b/include/uapi/linux/perf_event.h @@ -389,7 +389,8 @@ struct perf_event_attr { cgroup : 1, /* include cgroup events */ text_poke : 1, /* include text poke events */ thread_only : 1, /* only inherit on threads */ - __reserved_1 : 29; + sigtrap : 1, /* foo */ + __reserved_1 : 28; union { __u32 wakeup_events; /* wakeup every n events */ --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -6273,6 +6273,13 @@ static void perf_pending_event_disable(s if (cpu == smp_processor_id()) { WRITE_ONCE(event->pending_disable, -1); + + if (event->attr.sigtrap) { + atomic_inc(&event->event_limit); /* rearm */ + send_sig_info(SIGTRAP, SEND_SIG_PRIV, current); + return; + } + perf_event_disable_local(event); return; } @@ -8936,6 +8943,7 @@ static int __perf_event_overflow(struct int throttle, struct perf_sample_data *data, struct pt_regs *regs) { + perf_overflow_handler_t ovf; int events = atomic_read(&event->event_limit); int ret = 0; @@ -8961,7 +8969,15 @@ static int __perf_event_overflow(struct perf_event_disable_inatomic(event); } - READ_ONCE(event->overflow_handler)(event, data, regs); + ovf = READ_ONCE(event->overflow_handler); +#ifdef CONFIG_RETPOLINE + if (ovf == perf_event_output_forward) { + perf_event_output_forward(event, data, regs); + } else if (ovf == perf_event_output_backward) { + perf_event_output_backward(event, data, regs); + } else +#endif + ovf(event, data, regs); if (*perf_event_fasync(event) && event->pending_kill) { event->pending_wakeup = 1; @@ -11281,6 +11297,9 @@ perf_event_alloc(struct perf_event_attr event->state = PERF_EVENT_STATE_INACTIVE; + if (event->attr.sigtrap) + event->event_limit = ATOMIC_INIT(1); + if (task) { event->attach_state = PERF_ATTACH_TASK; /* @@ -11556,6 +11575,9 @@ static int perf_copy_attr(struct perf_ev if (attr->thread_only && !attr->inherit) return -EINVAL; + if (attr->sigtrap && attr->inherit && !attr->thread_only) + return -EINVAL; + out: return ret;