Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753885AbbHaSrV (ORCPT ); Mon, 31 Aug 2015 14:47:21 -0400 Received: from mail-qk0-f196.google.com ([209.85.220.196]:36779 "EHLO mail-qk0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751901AbbHaSrU (ORCPT ); Mon, 31 Aug 2015 14:47:20 -0400 MIME-Version: 1.0 In-Reply-To: <1440426780-27227-2-git-send-email-alexander.shishkin@linux.intel.com> References: <1440426780-27227-1-git-send-email-alexander.shishkin@linux.intel.com> <1440426780-27227-2-git-send-email-alexander.shishkin@linux.intel.com> Date: Mon, 31 Aug 2015 21:47:19 +0300 Message-ID: Subject: Re: [PATCH v2 1/6] perf: Introduce extended syscall error reporting From: Andy Shevchenko To: Alexander Shishkin Cc: Peter Zijlstra , Ingo Molnar , "linux-kernel@vger.kernel.org" , Adrian Hunter , Arnaldo Carvalho de Melo , Vince Weaver , Stephane Eranian , Johannes Berg Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2389 Lines: 79 On Mon, Aug 24, 2015 at 5:32 PM, Alexander Shishkin wrote: One small comment below. > --- a/kernel/events/core.c > +++ b/kernel/events/core.c > @@ -49,6 +49,79 @@ > > #include > > +static bool extended_reporting_enabled(struct perf_event_attr *attr) > +{ > + if (attr->size >= PERF_ATTR_SIZE_VER6 && > + attr->perf_err_size > 0) > + return true; > + > + return false; > +} > + > +/* > + * Provide a JSON formatted error report to the user if they asked for it. > + */ > +static void perf_error_report_site(struct perf_event_attr *attr, > + const struct perf_err_site *site) > +{ > + unsigned long len; > + char *buffer; > + > + if (!site || !extended_reporting_enabled(attr)) > + return; > + > + /* in case of nested perf_err()s, which you shouldn't really do */ > + while (site->code <= -PERF_ERRNO) > + site = perf_errno_to_site(site->code); > + > + buffer = kasprintf(GFP_KERNEL, > + "{\n" > + "\t\"code\": %d,\n" > + "\t\"module\": \"%s\",\n" > + "\t\"message\": \"%s\"\n" > + "}\n", > + site->code, site->owner, site->message > + ); > + if (!buffer) > + return; > + > + /* trim the buffer to the supplied boundary */ > + len = strlen(buffer); > + if (len >= attr->perf_err_size) { > + len = attr->perf_err_size - 1; > + buffer[len] = 0; > + } len = strnlen(buffer, attr->perf_err_size); buffer[len] = 0; And perhaps perf_err_size has to be length (perf_err_len) ? > + > + if (copy_to_user((void __user *)attr->perf_err, buffer, len + 1)) { > + /* if we failed to copy once, don't bother later */ > + attr->perf_err_size = 0; Kaboom next time on buffer[-1] = 0; since len >= 0? > + } > + > + kfree(buffer); > +} -- With Best Regards, Andy Shevchenko -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/