From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755347AbZBEOWr (ORCPT ); Thu, 5 Feb 2009 09:22:47 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751368AbZBEOWi (ORCPT ); Thu, 5 Feb 2009 09:22:38 -0500 Received: from mx2.mail.elte.hu ([157.181.151.9]:52410 "EHLO mx2.mail.elte.hu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751252AbZBEOWi (ORCPT ); Thu, 5 Feb 2009 09:22:38 -0500 Date: Thu, 5 Feb 2009 15:22:29 +0100 From: Ingo Molnar To: Paul Mackerras Cc: "Zhang, Yanmin" , linux-kernel@vger.kernel.org Subject: Re: [PATCH] perf_counter: Prevent oopses from per-cpu software counters Message-ID: <20090205142229.GB28443@elte.hu> References: <18826.28805.120988.303819@drongo.ozlabs.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <18826.28805.120988.303819@drongo.ozlabs.ibm.com> User-Agent: Mutt/1.5.18 (2008-05-17) X-ELTE-VirusStatus: clean X-ELTE-SpamScore: -1.5 X-ELTE-SpamLevel: X-ELTE-SpamCheck: no X-ELTE-SpamVersion: ELTE 2.0 X-ELTE-SpamCheck-Details: score=-1.5 required=5.9 tests=BAYES_00 autolearn=no SpamAssassin version=3.2.3 -1.5 BAYES_00 BODY: Bayesian spam probability is 0 to 1% [score: 0.0000] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Paul Mackerras wrote: > Impact: oops fix > > Yanmin Zhang reported that using a PERF_COUNT_TASK_CLOCK software > counter as a per-cpu counter would reliably crash the system, because > it calls __task_delta_exec with a null pointer. And indeed, a "task > clock" counter only makes sense as a per-task counter. Similarly, > counting page faults, context switches or cpu migrations only makes > sense for a per-task counter. > > This fixes the problem by disallowing the use of the task clock, > page fault, context switch and cpu migration software counters as > per-cpu counters, since they all require a task context to obtain their > data. The only software counter that can be used as a per-cpu counter > is the cpu clock counter (PERF_COUNT_CPU_CYCLES). > > In order for sw_perf_counter_init to be able to tell whether we are > setting up a per-task or a per-cpu counter, this arranges for counter->ctx > to be initialized earlier, in perf_counter_alloc. > > The other minor change this makes is to ensure that if sw_perf_counter_init > fails, we don't try to initialize the counter as a hardware counter. > Since the user has passed a negative event type (and it isn't raw), they > clearly don't intend it to be interpreted as a hardware event. This > matters now that sw_perf_counter_init can fail for valid software event > types (because of the check that the counter is a per-task counter). Hm, i dont really think that the notion that it should not be possible to use sw counters on a per CPU basis is valid. You are right that "pagefaults" and "context switches" do get generated by tasks - but there is a per cpu and system wide notion of 'number of pagefaults', and people might be interested in monitoring that. The existence and widespread use of "vmstat", and its display of system-wide count of "context switches" (and administrator's reliance on judging a workload based on those counts) is i think ample proof that it makes sense to have those counters on a per CPU basis too. So how about fixing these sw counts to properly work as percpu counters too? Or am i misssing something subtle that makes that impossible? Ingo