From owner-svn-src-all@freebsd.org Tue Jul 28 21:59:54 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id BF4A69AD24C; Tue, 28 Jul 2015 21:59:54 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: from mail-qk0-x233.google.com (mail-qk0-x233.google.com [IPv6:2607:f8b0:400d:c09::233]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 75F7BD8F; Tue, 28 Jul 2015 21:59:54 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: by qkdv3 with SMTP id v3so57652048qkd.3; Tue, 28 Jul 2015 14:59:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=XPScGfGj7qKF2O1NwKpit3MBrvqOSKJOJUDIPCVjWnA=; b=OkdvR5FqH96NjEvOH+vn/6Itg6yb2FAm33cjG7X+Y6ufBKAeV3AC+NhuGE/snR1TJF 9vGND0tltmYgvig4KjKj30IPuYiRhY1uFQ7CXHWcLYZjt4s5RAOHwlUD80GoBxFBlZ09 TrtWu4FXBa1UZgJw662dB4py33BDBADFrtCGg98tVNxTHcFxJeBHfOGbIII+9dIrlPWi tJr2w1OvS1C9n0A+3wEN2Ps1phGjnbziTootWl3t+k0qL7VVLss3vvTmMTOK6AaL7D67 +bxAZcwIrh0oU9GulXUPJ1WwRcLfxHjeeZPYSHGRnbc0lbM7hwft+7giFZ7yY2Fa4eu0 fp5g== X-Received: by 10.55.23.151 with SMTP id 23mr52169740qkx.1.1438120793690; Tue, 28 Jul 2015 14:59:53 -0700 (PDT) Received: from muskytusk ([104.236.250.12]) by smtp.gmail.com with ESMTPSA id i36sm12142450qkh.36.2015.07.28.14.59.52 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Jul 2015 14:59:52 -0700 (PDT) Sender: Mark Johnston Date: Tue, 28 Jul 2015 21:59:12 +0000 From: Mark Johnston To: Gleb Smirnoff Cc: Jason Unovitch , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r285782 - head/usr.bin/netstat Message-ID: <20150728184104.GA94463@muskytusk> References: <201507212357.t6LNvd7K023794@repo.freebsd.org> <20150728143106.GY72729@FreeBSD.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150728143106.GY72729@FreeBSD.org> User-Agent: Mutt/1.5.23 (2014-03-12) X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Jul 2015 21:59:54 -0000 On Tue, Jul 28, 2015 at 05:31:06PM +0300, Gleb Smirnoff wrote: > Mark, Jason, > > On Tue, Jul 21, 2015 at 11:57:39PM +0000, Mark Johnston wrote: > M> Fix counter reads on platforms where sizeof(uint64_t) != sizeof(uint64_t *). > M> > M> In the kernel, structs such as tcpstat are manipulated as an array of > M> counter_u64_t (uint64_t *), but made visible to userland as an array of > M> uint64_t. kread_counters() was previously copying the counter array into > M> user space and sequentially overwriting each counter with its value. This > M> mostly affects IPsec counters, as other counters are exported via sysctl. > M> > M> PR: 201700 > M> Tested by: Jason Unovitch > > Thanks for fixing the bug after me. > > One question, though: why do you use sizeof(u_long) instead of size of a > pointer? kvm_counter_u64_fetch(3) takes a u_long for the KVA of the counter, so it seemed natural to read an array of counter addresses into an array of u_long. > > M> ============================================================================== > M> --- head/usr.bin/netstat/main.c Tue Jul 21 23:44:36 2015 (r285781) > M> +++ head/usr.bin/netstat/main.c Tue Jul 21 23:57:38 2015 (r285782) > M> @@ -776,19 +776,31 @@ kread_counter(u_long addr) > M> int > M> kread_counters(u_long addr, void *buf, size_t size) > M> { > M> - uint64_t *c = buf; > M> + uint64_t *c; > M> + u_long *counters; > M> + size_t i, n; > M> > M> if (kvmd_init() < 0) > M> return (-1); > M> > M> - if (kread(addr, buf, size) < 0) > M> + if (size % sizeof(uint64_t) != 0) { > M> + xo_warnx("kread_counters: invalid counter set size"); > M> return (-1); > M> + } > M> > M> - while (size != 0) { > M> - *c = kvm_counter_u64_fetch(kvmd, *c); > M> - size -= sizeof(*c); > M> - c++; > M> + n = size / sizeof(uint64_t); > M> + if ((counters = malloc(n * sizeof(u_long))) == NULL) > M> + xo_err(-1, "malloc"); > M> + if (kread(addr, counters, n * sizeof(u_long)) < 0) { > M> + free(counters); > M> + return (-1); > M> } > M> + > M> + c = buf; > M> + for (i = 0; i < n; i++) > M> + c[i] = kvm_counter_u64_fetch(kvmd, counters[i]); > M> + > M> + free(counters); > M> return (0); > M> } > > -- > Totus tuus, Glebius.