Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp521298pxb; Wed, 3 Mar 2021 08:48:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJxiqYdjQhzAO/yeYQqit+RtwX+V1hM5rBx+9EhFzVWZnIxVJXl7DOftMiKBifdlaZiUxs0H X-Received: by 2002:a17:906:c081:: with SMTP id f1mr26822924ejz.97.1614790087359; Wed, 03 Mar 2021 08:48:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614790087; cv=none; d=google.com; s=arc-20160816; b=QWEQp7qmBFrnOIvf3yr56tIWRj4dFVyhY/UL27wa6uLnLPVAHV4yRFjaAu43cu0tj4 lTHEww5JgS3p4Us4YsaOxVKEMXIcNdMX6eIUwx9vtUf8ut9iyvFcxj2x/unUHM1iZv4C EEmRL619mddWKfW4JZnp7AJ7k40QS8mC6+RWDCTzi7Etl2RgKi0p+ebWliLMaHriOpBU 70D4PEhuTlmDWWs2y9b11+7/kNQ2AllL7zx8f8kcvj65iHnqf9RZqB/ENUOdU6vJsx8R CnoFdNHms4R+HnLUV3SzgHx90E78vnn1GXlcstPjNcmZvKeIqj9iCqxk7CJgaR/r3iPj 9clQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=KOrBqB0ChV7lkyshThiGgaLWIQhITHoUS2ou1dk2hJA=; b=l6RSu/gYBsqqvL6LhZK3G95ZPvllPeHVNcAeoC2RQlBTZEmKsWXzkGjrNwikPsfEQK lGeFEz7kiECcXgxP/VGox60pY0BiZRMVjUGw81zGCGXBgPQD68EMDD1E+RqasaYOfifu egV5M3r4ueZldZ/OLPQVRSb0nd0VrDHRpZn7C94P45u3xrvBISLMI47lGgvE53L4+3Um T1UNEgzsK6YnJhkTpck8RSIWM1F9Kl9NJi1WYJacX1Y0TklYfnMhQnpO+jDwpYUzgR0A ae6aCZvPgtwgOhiNo6M9R9icXUcZPyirk2k4wxOMr2qj7htFB/MCyWf1AkVdX4xJTX0e 80hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nzwaAflo; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dk18si7647195edb.178.2021.03.03.08.47.24; Wed, 03 Mar 2021 08:48:07 -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=@linuxfoundation.org header.s=korg header.b=nzwaAflo; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376389AbhCBAXT (ORCPT + 99 others); Mon, 1 Mar 2021 19:23:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:43170 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239853AbhCAS0V (ORCPT ); Mon, 1 Mar 2021 13:26:21 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 194C564F8D; Mon, 1 Mar 2021 17:20:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614619243; bh=NCB5zbz4nRNClltVQZVP2+8tDvrk2KA9cju5UkaOzIE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nzwaAfloGFswJKYtR44N6F1Eeu/mlwup7rSe86HtwKyyMkKRiQgOJYiddN5Q8aLTy j+UfYVTWMtoNaP22ulu2b+rTZ31hKAQsvc4JMxwrzdU9X2Xzbhr/8gJW/DMGnk5eVI yacwjkohq6bpYWeecILrd7ic5wZEiINa9qR2tJGY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yang Jihong , Arnaldo Carvalho de Melo , Jiri Olsa , Adrian Hunter , Alexander Shishkin , Alexey Budankov , Mark Rutland , Namhyung Kim , Peter Zijlstra , zhangjinhao2@huawei.com, Sasha Levin Subject: [PATCH 5.10 384/663] perf record: Fix continue profiling after draining the buffer Date: Mon, 1 Mar 2021 17:10:32 +0100 Message-Id: <20210301161200.862676963@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161141.760350206@linuxfoundation.org> References: <20210301161141.760350206@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yang Jihong [ Upstream commit e16c2ce7c5ed5de881066c1fd10ba5c09af69559 ] Commit da231338ec9c0987 ("perf record: Use an eventfd to wakeup when done") uses eventfd() to solve a rare race where the setting and checking of 'done' which add done_fd to pollfd. When draining buffer, revents of done_fd is 0 and evlist__filter_pollfd function returns a non-zero value. As a result, perf record does not stop profiling. The following simple scenarios can trigger this condition: # sleep 10 & # perf record -p $! After the sleep process exits, perf record should stop profiling and exit. However, perf record keeps running. If pollfd revents contains only POLLERR or POLLHUP, perf record indicates that buffer is draining and need to stop profiling. Use fdarray_flag__nonfilterable() to set done eventfd to nonfilterable objects, so that evlist__filter_pollfd() does not filter and check done eventfd. Fixes: da231338ec9c0987 ("perf record: Use an eventfd to wakeup when done") Signed-off-by: Yang Jihong Tested-by: Arnaldo Carvalho de Melo Tested-by: Jiri Olsa Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Alexey Budankov Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Cc: zhangjinhao2@huawei.com Link: http://lore.kernel.org/lkml/20210205065001.23252-1-yangjihong1@huawei.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/builtin-record.c | 2 +- tools/perf/util/evlist.c | 8 ++++++++ tools/perf/util/evlist.h | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index adf311d15d3d2..e5c938d538ee5 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -1666,7 +1666,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) status = -1; goto out_delete_session; } - err = evlist__add_pollfd(rec->evlist, done_fd); + err = evlist__add_wakeup_eventfd(rec->evlist, done_fd); if (err < 0) { pr_err("Failed to add wakeup eventfd to poll list\n"); status = err; diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 8bdf3d2c907cb..98ae432470cdd 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -508,6 +508,14 @@ int evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask) return perf_evlist__filter_pollfd(&evlist->core, revents_and_mask); } +#ifdef HAVE_EVENTFD_SUPPORT +int evlist__add_wakeup_eventfd(struct evlist *evlist, int fd) +{ + return perf_evlist__add_pollfd(&evlist->core, fd, NULL, POLLIN, + fdarray_flag__nonfilterable); +} +#endif + int evlist__poll(struct evlist *evlist, int timeout) { return perf_evlist__poll(&evlist->core, timeout); diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index e1a450322bc5b..9298fce53ea31 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -160,6 +160,10 @@ perf_evlist__find_tracepoint_by_name(struct evlist *evlist, int evlist__add_pollfd(struct evlist *evlist, int fd); int evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask); +#ifdef HAVE_EVENTFD_SUPPORT +int evlist__add_wakeup_eventfd(struct evlist *evlist, int fd); +#endif + int evlist__poll(struct evlist *evlist, int timeout); struct evsel *perf_evlist__id2evsel(struct evlist *evlist, u64 id); -- 2.27.0