From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966302AbaFSXdN (ORCPT ); Thu, 19 Jun 2014 19:33:13 -0400 Received: from smtprelay0001.hostedemail.com ([216.40.44.1]:45103 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S965786AbaFSXdM (ORCPT ); Thu, 19 Jun 2014 19:33:12 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 30,2,0,,d41d8cd98f00b204,joe@perches.com,:::::::::,RULES_HIT:41:355:379:541:599:966:981:982:988:989:1260:1261:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:1963:2196:2199:2393:2553:2559:2562:2691:2693:2828:3138:3139:3140:3141:3142:3355:3622:3743:3865:3866:3867:3868:3870:3871:3872:3873:3874:4250:4321:4385:4605:5007:6119:6120:7652:7903:8531:8603:8957:9010:9040:10010:10400:10848:11026:11232:11473:11658:11914:12043:12438:12517:12519:12663:12740,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:1:0 X-HE-Tag: cough60_730c28aa1253d X-Filterd-Recvd-Size: 3786 Message-ID: <1403220789.2753.32.camel@joe-AO725> Subject: Re: [RFC PATCH] use snprintf instead of sprintf in rcu_torture_printk From: Joe Perches To: Pranith Kumar Cc: paulmck@linux.vnet.ibm.com, LKML , romanov.arya@gmail.com, Josh Triplett Date: Thu, 19 Jun 2014 16:33:09 -0700 In-Reply-To: <53A37140.3020003@gmail.com> References: <1402419340.30479.18.camel@joe-AO725> <20140611074704.GS5015@mwanda> <1402502500.6169.5.camel@joe-AO725> <20140618193345.GR4669@linux.vnet.ibm.com> <1403120982.3839.25.camel@joe-AO725> <20140619210031.GN4904@linux.vnet.ibm.com> <53A37140.3020003@gmail.com> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.10.4-0ubuntu1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2014-06-19 at 19:24 -0400, Pranith Kumar wrote: > (dropping some CCs) > > On 06/19/2014 05:00 PM, Paul E. McKenney wrote: > > On Wed, Jun 18, 2014 at 12:49:42PM -0700, Joe Perches wrote: > >> > >> I believe the function doesn't work well. > >> > >> static void > >> rcu_torture_stats_print(void) > >> { > >> int size = nr_cpu_ids * 200 + 8192; > >> char *buf; > >> > >> buf = kmalloc(size, GFP_KERNEL); > >> if (!buf) { > >> pr_err("rcu-torture: Out of memory, need: %d\n", size); > >> return; > >> } > >> rcu_torture_printk(buf); > >> pr_alert("%s", buf); > >> kfree(buf); > >> } > >> > >> rcu_torture_printk simply fills buf > >> > >> btw: I believe the arguments should pass size and > >> rcu_torture_printk should use snprintf/size > >> > >> but all printks are limited to a maximum of 1024 > >> bytes so the large allocation is senseless and > >> would even if it worked, would likely need to be > >> vmalloc/vfree > > > > Fair point! > > > > Pranith, Romanov, if you would like part of RCU that is less touchy > > about random hacking, this would be a good place to start. Scripts in > > tools/testing/selftests/rcutorture/bin do care about some of the format, > > but the variable-length portion generated by cur_ops->stats() is as far > > as I know only parsed by human eyes. > > > > Here is a first run of the change. Please let me know if I am totally off. RFC. :) > > Three things on Todo list: > > * We need to check that we are using less than the allocated size of the buffer (used > size). (we are allocating a big buffer, so not sure if necessary) > * Need to check with the scripts if they are working. > * I used a loop for pr_alert(). I am not sure this is right, there should be a better way for printing large buffers > > If the overall structure is ok I will go ahead and check how the scripts are handling these changes. [] > diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c [] > @@ -1130,17 +1134,23 @@ rcu_torture_printk(char *page) > static void > rcu_torture_stats_print(void) > { [] > + /* printk can print only print LOG_LINE_MAX chars at a time */ > + while (used > 0) { > + size_pr = pr_alert("%s", buf); > + used -= size_pr; > + buf += size_pr; > + } > + vfree(buf); > } You can't increment buf then vfree it. Try a char *tmpbuf = buf, and increment it. I suggest you check by strcspn(tmpbuf, "\n") save the byte after, replace it with 0, print, replace the 0 with saved byte, and loop until end of buffer.