From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DCACC169C4 for ; Thu, 31 Jan 2019 08:57:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E1EC02184D for ; Thu, 31 Jan 2019 08:57:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="eIuj7ka8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727313AbfAaI5M (ORCPT ); Thu, 31 Jan 2019 03:57:12 -0500 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:57909 "EHLO out1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725932AbfAaI5M (ORCPT ); Thu, 31 Jan 2019 03:57:12 -0500 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 22F1122071; Thu, 31 Jan 2019 03:57:11 -0500 (EST) Received: from web6 ([10.202.2.216]) by compute6.internal (MEProxy); Thu, 31 Jan 2019 03:57:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=k/JYto+xURqOSt7EMLwB8Xqvh/bn2kfsklcEtIdjG 3I=; b=eIuj7ka8Qj0CwiZWMLW6ItuaCQZ+oRdCEqxPIfZCVoseTV99x/05frhOT zq/oc/MmoD75SpaDA1oHbqtPcLYeRSoN7Cf9kKnugIMhbLKt42e/WFNbjZziBxFh 0Ll4wpxlvgWisiZUjhzAUhhdf53qeeRDoRIM12PE+SD42w34cmNMBQaV1TZgAGet Pl9bErWjp0+Qos3hvz/SiPQHJzq/g/ahy+VZJ3Mhcya97m4JQAPxkaTXH32dBbI7 TCoaDfdz+2tzfmOy8Ke7at8DsyoQXQjoAQdm9cPzu6K8lgAgAO21H68F/cs+i3dO UaEPBtg/pwKEuAci9rHU5ABW1RYlA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedtledrjeehgdduvdeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfquhhtnecuuegrihhlohhuthemucef tddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefkhffvggfgtg fofffujghfsehtjeertdertdejnecuhfhrohhmpeforghrthihnhgrshcuoehmsehlrghm sggurgdrlhhtqeenucffohhmrghinhepghhithhhuhgsrdgtohhmnecurfgrrhgrmhepmh grihhlfhhrohhmpehmsehlrghmsggurgdrlhhtnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 99) id 61EB241C6; Thu, 31 Jan 2019 03:57:10 -0500 (EST) Message-Id: <1548925030.2449932.1647631648.68AFD94B@webmail.messagingengine.com> From: Martynas To: Y Song Cc: netdev , Alexei Starovoitov , Daniel Borkmann MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" X-Mailer: MessagingEngine.com Webmail Interface - ajax-ec01da05 Date: Thu, 31 Jan 2019 10:57:10 +0200 Subject: Re: [PATCH] bpf: selftests: handle sparse CPU allocations In-Reply-To: References: <20190130091900.4044-1-m@lambda.lt> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Oops, thanks for noticing the issue with strlen in the for loop. Changing to "int len = strlen(buff); for (i = 0; i < len; i++) <..>" should fix the issue. I'm going to re-submit the patch. Also, I put some testing results: https://gist.github.com/brb/5369b5cfd08babb80cf2c4081dc19762 On Thu, Jan 31, 2019, at 7:25 AM, Y Song wrote: > [ My reply somehow rejected by netdev, this is to send it again. ] > > On Wed, Jan 30, 2019 at 1:19 AM Martynas Pumputis wrote: > > > > Previously, bpf_num_possible_cpus() had a bug when calculating a > > number of possible CPUs in the case of sparse CPU allocations, as > > it was considering only the first range or element of > > /sys/devices/system/cpu/possible. > > > > E.g. in the case of "0,2-3" (CPU 1 is not available), the function > > returned 1 instead of 3. > > > > This patch fixes the function by making it parse all CPU ranges and > > elements. > > > > Signed-off-by: Martynas Pumputis > > --- > > tools/testing/selftests/bpf/bpf_util.h | 29 +++++++++++++++++--------- > > 1 file changed, 19 insertions(+), 10 deletions(-) > > > > diff --git a/tools/testing/selftests/bpf/bpf_util.h b/tools/testing/selftests/bpf/bpf_util.h > > index 315a44fa32af..8cab50408204 100644 > > --- a/tools/testing/selftests/bpf/bpf_util.h > > +++ b/tools/testing/selftests/bpf/bpf_util.h > > @@ -13,7 +13,7 @@ static inline unsigned int bpf_num_possible_cpus(void) > > unsigned int start, end, possible_cpus = 0; > > char buff[128]; > > FILE *fp; > > - int n; > > + int n, i, j = 0; > > > > fp = fopen(fcpu, "r"); > > if (!fp) { > > @@ -21,17 +21,26 @@ static inline unsigned int bpf_num_possible_cpus(void) > > exit(1); > > } > > > > - while (fgets(buff, sizeof(buff), fp)) { > > - n = sscanf(buff, "%u-%u", &start, &end); > > - if (n == 0) { > > - printf("Failed to retrieve # possible CPUs!\n"); > > - exit(1); > > - } else if (n == 1) { > > - end = start; > > + if (!fgets(buff, sizeof(buff), fp)) { > > + printf("Failed to read %s!\n", fcpu); > > + exit(1); > > + } > > + > > + for (i = 0; i <= strlen(buff); i++) { > > + if (buff[i] == ',' || buff[i] == '\0') { > > + buff[i] = '\0'; > > This does not sound right. For example, the cpu list "0,2-3", > you will change "," to '\0" so buffer becomes "0\02-3". > The next iteration you will get strlen(buff) = 1. > The "2-3" will be skipped. > > > + n = sscanf(&buff[j], "%u-%u", &start, &end); > > + if (n <= 0) { > > + printf("Failed to retrieve # possible CPUs!\n"); > > + exit(1); > > + } else if (n == 1) { > > + end = start; > > + } > > + possible_cpus += end - start + 1; > > + j = i + 1; > > } > > - possible_cpus = start == 0 ? end + 1 : 0; > > - break; > > } > > + > > fclose(fp); > > > > return possible_cpus; > > -- > > 2.20.1 > >