Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp2288802imc; Tue, 12 Mar 2019 10:39:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqygEQfeqOgDme+Hxc4+f/MlHW1I6hhF2FG/8b9qOuti/KtL7g9TbySkDKO7fehmDe+xe0lM X-Received: by 2002:a65:648f:: with SMTP id e15mr21858741pgv.249.1552412368345; Tue, 12 Mar 2019 10:39:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552412368; cv=none; d=google.com; s=arc-20160816; b=tiHvvHEMvJyPlQq1Lu58KdKGRhshiVZ2QphWlnUHOVh5U46+raP0miJ29RSnD/wIn1 uwcDtN8rT74zeb59ICY8eLFaGSi4nmmtzAi/W1MA2OXuK0xcV2UEca7x6itnKtIjQZwH HzZuTHUCdxtZEghPbkT1EjDN5g4MMcT2jYtuNAIu7cwVMWoFCEED2LZA1r34h8MdAD5s AOtWy41hpLqnCQfGJmIeAhiPjrNTQeKbnv8OqaKn2NBr1aitWhXCIKH4yLJG+b4drUUD 2lCZ+yWIlfLCbpfRz/1pV6W/VlsIKrm0piWm/JNZtcQbt0J+SukXx5ax3bKJRJlMhfyk 8k1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PDeed42bB9CAppc9A59JJ0NdVtKlfDGSsRYB8OVn+jU=; b=tW83bPn00TRSCs9siCQYOPFT/HjcdC3EArn6Ux0AR5Gq4KGcaKMRaaUMZv4qxBnfYX 1hrgCy9qtMrssLZapqlo0CFImg+phnYLFvZbKdXQyOcMiuPLul1bPohelQUhGFG2pl0f ZrFJXLXNc3zUCZ5RnnFFPLPEOzkahr+Y8NaSL0dEMrOruiOObdn6iTKP5m1L0lVCgLpF hu31RWwMdQxNvS0XEF7UWXzMOf7wWgu0I9xXi3OMK8Ur0fKRGySso3iyk+0ZG8PVZHqd +vwaMWUGq4PEYcz6krvvHBK36Jo85tM4L+2RFh/bmJzJJqXdxWKG8N9IJc86smxXT+SD M1qQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yaPha1uK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u5si7994280pgh.221.2019.03.12.10.39.12; Tue, 12 Mar 2019 10:39:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yaPha1uK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729370AbfCLRgv (ORCPT + 99 others); Tue, 12 Mar 2019 13:36:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:59132 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729247AbfCLRQl (ORCPT ); Tue, 12 Mar 2019 13:16:41 -0400 Received: from localhost (unknown [104.133.8.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D9ADD206DF; Tue, 12 Mar 2019 17:16:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552411001; bh=uW6YNtrzL4IoEdhZ93o1IBsXh+OFmvejpFNusd+sJRw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yaPha1uKzaFA/opIjHG9sJZbau7cBp/axlNf4I5jRptM/98DhtB0dC2JRi02sCDxB EN+74ZOstcpg0WERglIWXWhyTkOpVnv5mvYv0K6Mi+x6l+izVcBt4n3IrCAwiuQOM6 oObodztLoYAQg2CK4ygDTGMyXhrq14uRG1Hv1kPM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Martynas Pumputis , Yonghong Song , Daniel Borkmann , Sasha Levin Subject: [PATCH 4.14 101/135] bpf, selftests: fix handling of sparse CPU allocations Date: Tue, 12 Mar 2019 10:09:08 -0700 Message-Id: <20190312170350.476476039@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190312170341.127810985@linuxfoundation.org> References: <20190312170341.127810985@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 1bb54c4071f585ebef56ce8fdfe6026fa2cbcddd ] 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 Acked-by: Yonghong Song Signed-off-by: Daniel Borkmann Signed-off-by: Sasha Levin --- tools/testing/selftests/bpf/bpf_util.h | 30 +++++++++++++++++--------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/bpf/bpf_util.h b/tools/testing/selftests/bpf/bpf_util.h index d0811b3d6a6f..4bf720364934 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 len, n, i, j = 0; fp = fopen(fcpu, "r"); if (!fp) { @@ -21,17 +21,27 @@ 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); + } + + len = strlen(buff); + for (i = 0; i <= len; i++) { + if (buff[i] == ',' || buff[i] == '\0') { + buff[i] = '\0'; + 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.19.1