Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp3520945ybg; Mon, 28 Oct 2019 14:15:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqy3AMAimVnOR4ONdKQJ/2qq0C3AVYypGWCtGRyBTw3PYuiIHok11RAUYNRA379kjgHQvf1e X-Received: by 2002:a17:906:c28c:: with SMTP id r12mr18742423ejz.163.1572297355534; Mon, 28 Oct 2019 14:15:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572297355; cv=none; d=google.com; s=arc-20160816; b=Q88FobZY6D6dgkv75GA+JlnZdOq1oK3A0v8kd3YkYkTyoWMnzrs0WJdVyul9nDmESu VE94ITiZvVo8Bp+xEnLrefP8o1NYawzq6z0+rAIcD1tQxAPpPPcwbjQiMSB6UBnqNBR5 Qlyr7Op458B9yopQLKr4q7m3v2YukshGWnOrA4WRoxCr2C7M/WjvppEqGS0qRFAtEH+v vN0NvRhQfuIC+TVRrJb/98sbSVvg1X7jDcIXHy00OxyanJugK5ztb4A6fvbIzKE1XwBY fMGE50RF3dR7QKiJFyBEEdhFBMeDaiB5TC2+tYZYkjloxgJypR1bgrxf8nE9TQB5eRlh EDNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=hl7EeV1e87EvWLPBta0t1ffcGVSzWnGjvGSEpK+Qbwc=; b=b5fMBIGJJTDp6y7+EJnuzor4kAgMsSRJFD7cRCH2+gVcFkDujPd/8+WqPPyccprzbW jjEotIsqcyQ9xDwjnALoG6+R+MI5fWs8dInEY66aJd6SMLZcqLqLRvcr+1EFH8DueupQ mP6udyJjAmU8mSzXeSkA2k4W0wuxY7cOV5EHwKWv3j29tsxxQu1saxmPC91eRP1TuiuP 0Al02bVZxlGSsGlf0M//6C4+/7uK0eKTlyAfJ881hHiwOJqDss2S9SjN7kJzyQJMlFoJ urMBlXuscDZGfylILvtUV7+dJ/yUpQXNr1a5onuz+fhOSw8KGOIJTYHwtQwQGP994SUk koHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=akOX48pc; 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 d6si8077201ede.119.2019.10.28.14.15.31; Mon, 28 Oct 2019 14:15:55 -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=fail header.i=@infradead.org header.s=merlin.20170209 header.b=akOX48pc; 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 S2390958AbfJ1Q10 (ORCPT + 99 others); Mon, 28 Oct 2019 12:27:26 -0400 Received: from merlin.infradead.org ([205.233.59.134]:59722 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732424AbfJ1Q10 (ORCPT ); Mon, 28 Oct 2019 12:27:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.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:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=hl7EeV1e87EvWLPBta0t1ffcGVSzWnGjvGSEpK+Qbwc=; b=akOX48pcg2u9uFGaUBrMmqiiH qxJcwCaBvyqnFfUn22T0j6NhK3bbuKwZe400E2uTtr+52mBobX7FX0gFRyP8WLZExBc/SNvIjYE2S 0KOfr3wnRBPhHHSVfi3TlHfnhD1AdMpZzomyv9drq/n2ftVtcShekupF+/JWaeMoW9L/p4lapcrAx 19DajV/HhiMrGyjSN40gpxaP+faiJRu7WExuCEYd2qvgm5uBy6zLJVZIt8HXWeEDizGF36cZCrEz7 FGID6hL7nO/UJgWpBnVv3Dv3dThZYN7Ibhv4BZPqBCAUO2/2IQzGPL7Ty283N5tOGQsMU2ISZ6H16 hxXGoa6jg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1iP7rQ-0004dn-0W; Mon, 28 Oct 2019 16:27:16 +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 4978D3002B0; Mon, 28 Oct 2019 17:26:12 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 7C97A2B400AB4; Mon, 28 Oct 2019 17:27:12 +0100 (CET) Date: Mon, 28 Oct 2019 17:27:12 +0100 From: Peter Zijlstra To: Alexander Shishkin Cc: Arnaldo Carvalho de Melo , Ingo Molnar , linux-kernel@vger.kernel.org, jolsa@redhat.com, adrian.hunter@intel.com, mathieu.poirier@linaro.org, mark.rutland@arm.com Subject: Re: [PATCH v3 1/3] perf: Allow using AUX data in perf samples Message-ID: <20191028162712.GH4097@hirez.programming.kicks-ass.net> References: <20191025140835.53665-1-alexander.shishkin@linux.intel.com> <20191025140835.53665-2-alexander.shishkin@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191025140835.53665-2-alexander.shishkin@linux.intel.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 25, 2019 at 05:08:33PM +0300, Alexander Shishkin wrote: > +static void perf_aux_sample_output(struct perf_event *event, > + struct perf_output_handle *handle, > + struct perf_sample_data *data) > +{ > + struct perf_event *sampler = event->aux_event; > + unsigned long pad; > + struct ring_buffer *rb; > + long size; > + > + if (WARN_ON_ONCE(!sampler || !data->aux_size)) > + return; > + > + rb = ring_buffer_get(sampler->parent ? sampler->parent : sampler); > + if (!rb) > + return; > + > + /* > + * Guard against NMI hits inside the critical section; > + * see also perf_aux_sample_size(). > + */ > + WRITE_ONCE(rb->aux_in_sampling, 1); > + > + size = perf_pmu_aux_sample_output(sampler, handle, data->aux_size); > + > + /* > + * An error here means that perf_output_copy() failed (returned a > + * non-zero surplus that it didn't copy), which in its current > + * enlightened implementation is not possible. If that changes, we'd > + * like to know. > + */ > + if (WARN_ON_ONCE(size < 0)) > + goto out_clear; > + > + /* > + * The pad comes from ALIGN()ing data->aux_size up to u64 in > + * perf_aux_sample_size(), so should not be more than that. > + */ > + pad = data->aux_size - size; > + if (WARN_ON_ONCE(pad >= sizeof(u64))) > + pad = 8; > + > + if (pad) { > + u64 zero = 0; > + perf_output_copy(handle, &zero, pad); > + } > + > +out_clear: > + WRITE_ONCE(rb->aux_in_sampling, 0); > + > + ring_buffer_put(rb); > +} I have the below delta on top of this patch. And while I get why we need recursion protection for pmu::snapshot_aux, I'm a little puzzled on why it is over the padding, that is, why isn't the whole of aux_in_sampling inside (the newly minted) perf_pmu_snapshot_aux() ? --- --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -6237,7 +6237,7 @@ perf_output_sample_ustack(struct perf_ou } } -static unsigned long perf_aux_sample_size(struct perf_event *event, +static unsigned long perf_prepare_sample_aux(struct perf_event *event, struct perf_sample_data *data, size_t size) { @@ -6275,9 +6275,9 @@ static unsigned long perf_aux_sample_siz return data->aux_size; } -long perf_pmu_aux_sample_output(struct perf_event *event, - struct perf_output_handle *handle, - unsigned long size) +long perf_pmu_snapshot_aux(struct perf_event *event, + struct perf_output_handle *handle, + unsigned long size) { unsigned long flags; long ret; @@ -6318,11 +6318,12 @@ static void perf_aux_sample_output(struc /* * Guard against NMI hits inside the critical section; - * see also perf_aux_sample_size(). + * see also perf_prepare_sample_aux(). */ WRITE_ONCE(rb->aux_in_sampling, 1); + barrier(); - size = perf_pmu_aux_sample_output(sampler, handle, data->aux_size); + size = perf_pmu_snapshot_aux(sampler, handle, data->aux_size); /* * An error here means that perf_output_copy() failed (returned a @@ -6335,7 +6336,7 @@ static void perf_aux_sample_output(struc /* * The pad comes from ALIGN()ing data->aux_size up to u64 in - * perf_aux_sample_size(), so should not be more than that. + * perf_prepare_sample_aux(), so should not be more than that. */ pad = data->aux_size - size; if (WARN_ON_ONCE(pad >= sizeof(u64))) @@ -6347,6 +6348,7 @@ static void perf_aux_sample_output(struc } out_clear: + barrier(); WRITE_ONCE(rb->aux_in_sampling, 0); ring_buffer_put(rb); @@ -6881,7 +6883,7 @@ void perf_prepare_sample(struct perf_eve size = min_t(size_t, U16_MAX - header->size, event->attr.aux_sample_size); size = rounddown(size, 8); - size = perf_aux_sample_size(event, data, size); + size = perf_prepare_sample_aux(event, data, size); WARN_ON_ONCE(size + header->size > U16_MAX); header->size += size;