Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2941051imu; Fri, 18 Jan 2019 01:54:48 -0800 (PST) X-Google-Smtp-Source: ALg8bN5TowA20AuMhphNHrUXSf45B9yvWfkw9LIZsutr+GWCVTfNNYRjhdowozS3hc5kvIH4hs6t X-Received: by 2002:a63:d547:: with SMTP id v7mr16671423pgi.339.1547805287987; Fri, 18 Jan 2019 01:54:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547805287; cv=none; d=google.com; s=arc-20160816; b=ctRWnN6Itgo52S4IqhT3n29UaPRLETLAkYDSZlcDwh0j74vyVXwFcEqBlz/tgG79IX 6VFeb/lyu6UCd9iTHpN9weBGC4xxl0QM4DoA65sXzQO5KziDnkSyROVPA7c3XvUOGxHM fe9wgjn6GpTybRc1OsDtAUaaOTFH+SS9ueTY0DDkXFLfgvekL3gGgWyobgzj5Tkg2EVE kPGuasntuvYZAQiUDoYiOjg7X8q321F6HD/LhJ+yjlfj8Cj1sJHIwAxGKkEArB0FuPgA 9zMzsCLisZDw6AeIn7ABh5Lj+swxrBEX9Ng5p3mPSRh2aRvbSfS0DvpltgQPSCn0G+Zs KDLw== 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; bh=PPmoRrM1b4HsdZzKBH/VTrbYRu7kPpu+mljwvtfeb7Y=; b=qmzKtRRay0KZtJUrilcRhA364GtKxzyHay536UBWb7ycnMd4a0l0JfqwCwPDayvnt+ 4st5YHWqKdCOvPMZV2JRzl5Oy8NEEqesJzjCAQU5ECNl7n3KD5m9UcHjvy9GUMP4mtNY P1zxQrXU6b60KYp6INlFDN0OpF7NVkAdKA87zR0Fn4iWrTh1taUi1YJuQs3SbtJtdOQF 05J8Vm9FKaXmAGBdBPTGIRaj8aHPRUYNCnQBgbcczp4XkNVUpshtbMEiwZB8b9lcZjaK ocrPFddzqrmJjShYuae8a4m5eujrycaUo5z9N7ysqzGTagHGsUyhsSUrNQJ4db7/fgyp p0Ww== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y6si3917532plr.186.2019.01.18.01.54.30; Fri, 18 Jan 2019 01:54:47 -0800 (PST) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726922AbfARJw4 (ORCPT + 99 others); Fri, 18 Jan 2019 04:52:56 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58826 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726351AbfARJwz (ORCPT ); Fri, 18 Jan 2019 04:52:55 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 25EE5A091F; Fri, 18 Jan 2019 09:52:55 +0000 (UTC) Received: from krava (unknown [10.40.205.176]) by smtp.corp.redhat.com (Postfix) with SMTP id BD08260BE8; Fri, 18 Jan 2019 09:52:52 +0000 (UTC) Date: Fri, 18 Jan 2019 10:52:51 +0100 From: Jiri Olsa To: Stephane Eranian Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@elte.hu, ak@linux.intel.com, kan.liang@intel.com, acme@redhat.com Subject: Re: [PATCH] perf/core: fix perf_proc_update_handler() bug Message-ID: <20190118095251.GB28346@krava> References: <1547169436-6266-1-git-send-email-eranian@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1547169436-6266-1-git-send-email-eranian@google.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 18 Jan 2019 09:52:55 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 10, 2019 at 05:17:16PM -0800, Stephane Eranian wrote: > The perf_proc_update_handler() handles /proc/sys/kernel/perf_event_max_sample_rate > syctl variable. When the PMU IRQ handler timing monitoring is disabled, i.e, > when /proc/sys/kernel/perf_cpu_time_max_percent is equal to 0 or 100, > then no modification to sysctl_perf_event_sample_rate is allowed to prevent > possible hang from wrong values. > > The problem is that the test to prevent modification is made after the > sysctl variable is modified in perf_proc_update_handler(). > > You get an error: > > $ echo 10001 >/proc/sys/kernel/perf_event_max_sample_rate > echo: write error: invalid argument > > But the value is still modified causing all sorts of inconsistencies: > > $ cat /proc/sys/kernel/perf_event_max_sample_rate > 10001 > > This patch fixes the problem by moving the parsing of the value after > the test. > > Signed-off-by: Stephane Eranian Reviewed-by: Jiri Olsa jirka > --- > kernel/events/core.c | 14 +++++++------- > 1 file changed, 7 insertions(+), 7 deletions(-) > > diff --git a/kernel/events/core.c b/kernel/events/core.c > index 3cd13a30f732..e5ede6918050 100644 > --- a/kernel/events/core.c > +++ b/kernel/events/core.c > @@ -436,18 +436,18 @@ int perf_proc_update_handler(struct ctl_table *table, int write, > void __user *buffer, size_t *lenp, > loff_t *ppos) > { > - int ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos); > - > - if (ret || !write) > - return ret; > - > + int ret; > + int perf_cpu = sysctl_perf_cpu_time_max_percent; > /* > * If throttling is disabled don't allow the write: > */ > - if (sysctl_perf_cpu_time_max_percent == 100 || > - sysctl_perf_cpu_time_max_percent == 0) > + if (write && (perf_cpu == 100 || perf_cpu == 0)) > return -EINVAL; > > + ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos); > + if (ret || !write) > + return ret; > + > max_samples_per_tick = DIV_ROUND_UP(sysctl_perf_event_sample_rate, HZ); > perf_sample_period_ns = NSEC_PER_SEC / sysctl_perf_event_sample_rate; > update_perf_cpu_limits(); > -- > 2.7.4 >