Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7289996imu; Tue, 22 Jan 2019 03:38:37 -0800 (PST) X-Google-Smtp-Source: ALg8bN4f+FlII1jREwEROGYNhWjJKeSf2tyaGBbjSOpUxJxI1ZKrAxfIINoGrQ9iaHIibNz1yZTj X-Received: by 2002:a62:22d4:: with SMTP id p81mr34150701pfj.16.1548157117377; Tue, 22 Jan 2019 03:38:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548157117; cv=none; d=google.com; s=arc-20160816; b=V25w+ip9Vb8DvPVNVGcDfSflUxtbZ+5wSaJdZXv9qAKRen6NxiaM0OZmeoucu1tFFX HlXnNHck2WSfrya47OngTGOfsiSRPL3PcHWk9GhKijc02BatF6dNGvwPRAbSAjZXS75v Vz5mUe7bOy6QOghRSzOGkD3M0FN5Mnx28Rlji0rzvwWWhrTbVhl0h4SjLaFR2AEmTAtu ulIO0/H8BmNboLxmzmBAhb5hviWy3bfjOnmQSrxTlIo8pG+kHfkVh2xfXGrpFzEOZGaD 5Y4iRT0rHgc/mBWGNkr3L7/+k+wRpZvbVgQXVaVzwUD9+u7oocsjc1pkpRdWCXvQi8Ft XT9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date; bh=4alaSAKMIBcjvzWow8kTMKXkBs5FKkJuMudPOXaJmlY=; b=E19a4T5n52aTLIBtLoG/EixXCZMKPX2USUUBQl3lEj1eEu76CW8gX1vuxyELBDIAm2 hmR62aNbeTuKY+HgY6aPk8UdH0d7JpXkdlcyi57aTFvkyqFHCHPeZsix75QlEC/LHlTj MC1QR9mUa6HYsudu66ipICcdLsKcFa6IL0OotBaCVlreKJli1r/FrsrKtQxZoWx0S0qF MBeqULBhuGRjtpEj4dUolOx6IZNse0lJL6I7WFZV8Q+4a8t1Kuhcf9jtjIv+XhIAObjI TSYDxWRZHNUFXWhBKHtKeedOupz3alJ/ref8xvQfTkTE9yRvFECg9MBfOvAa4ypfGqyR MIWA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b7si15583693plb.234.2019.01.22.03.38.21; Tue, 22 Jan 2019 03:38:37 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728289AbfAVLg3 (ORCPT + 99 others); Tue, 22 Jan 2019 06:36:29 -0500 Received: from terminus.zytor.com ([198.137.202.136]:60727 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727777AbfAVLg3 (ORCPT ); Tue, 22 Jan 2019 06:36:29 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x0MBZGZ22929611 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 22 Jan 2019 03:35:16 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x0MBZGsp2929608; Tue, 22 Jan 2019 03:35:16 -0800 Date: Tue, 22 Jan 2019 03:35:16 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Stephane Eranian Message-ID: Cc: eranian@google.com, linux-kernel@vger.kernel.org, kan.liang@linux.intel.com, hpa@zytor.com, jolsa@kernel.org, mingo@kernel.org, peterz@infradead.org, ak@linux.intel.com, tglx@linutronix.de, acme@redhat.com Reply-To: eranian@google.com, linux-kernel@vger.kernel.org, kan.liang@linux.intel.com, hpa@zytor.com, jolsa@kernel.org, peterz@infradead.org, mingo@kernel.org, ak@linux.intel.com, tglx@linutronix.de, acme@redhat.com In-Reply-To: <1547169436-6266-1-git-send-email-eranian@google.com> References: <1547169436-6266-1-git-send-email-eranian@google.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/urgent] perf core: Fix perf_proc_update_handler() bug Git-Commit-ID: 1a51c5da5acc6c188c917ba572eebac5f8793432 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, T_DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 1a51c5da5acc6c188c917ba572eebac5f8793432 Gitweb: https://git.kernel.org/tip/1a51c5da5acc6c188c917ba572eebac5f8793432 Author: Stephane Eranian AuthorDate: Thu, 10 Jan 2019 17:17:16 -0800 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 18 Jan 2019 11:10:38 -0300 perf core: Fix perf_proc_update_handler() bug 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. Committer testing: # echo 100 > /proc/sys/kernel/perf_cpu_time_max_percent # echo 10001 > /proc/sys/kernel/perf_event_max_sample_rate -bash: echo: write error: Invalid argument # cat /proc/sys/kernel/perf_event_max_sample_rate 10001 # Signed-off-by: Stephane Eranian Reviewed-by: Andi Kleen Reviewed-by: Jiri Olsa Tested-by: Arnaldo Carvalho de Melo Cc: Kan Liang Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1547169436-6266-1-git-send-email-eranian@google.com Signed-off-by: Arnaldo Carvalho de Melo --- 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();