Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1880270ybz; Thu, 30 Apr 2020 07:08:14 -0700 (PDT) X-Google-Smtp-Source: APiQypJ1UUgCluuBDVEWo5ZUaB7qExZmC/7n4bIGjTyb3kxqX9/l3x7KckcjGX+whcuAahPqjGZk X-Received: by 2002:a17:907:1199:: with SMTP id uz25mr2754263ejb.131.1588255693900; Thu, 30 Apr 2020 07:08:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588255693; cv=none; d=google.com; s=arc-20160816; b=kVTx77Sp+d1sjHXWr2NXWjoYNODtHD0E0LfXoqwiLJ5vaoPQOfpPrSc3wHsPO02nG3 msX0p6jGIxOdyLP9em827d9zMUvTsZ9j6MRC0pJtwVRKlZQugJAbKrYh9PE6e/NaFOWF bpLvTaQl+7a52PPrrCUVRCR/r01SCRZANVWqJcCA3rrzpaoXN1lSlhUxToDKgVMQSgYq s0UiNq3Xo8c134VYPYRcpBghtP05puDVL0hS+YrW7taPIpx79/4uwieFMEM5Lb8usOY7 eiJM2V71poL543mPm5PdDIhTV6UOBb0/LnfdZhm6AiqnAUPR4zL4nUuDRseYSgPcK55e xhXQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1YBkcJNqHycKrPGqcMOoW1tJjs1UkosbPwZGzpmrIq0=; b=sjyQDAjit1WA24ABQezlCzYBc9kqYpLZkvRazG2kU6Qy4SD22rzdf98LqVhbBblSeV bJuHpBdAJemzSqm3XTqxEKUj2OPx5l4U9CURdSJBE1G8XXU3E7IgKvgstMNbp5wLP6Lj 18QbxHiQ4zfDD48Up3ON3138pORFnw6GzZEXrohrl85igPC2zp+bZMgfw2vPlEZbgHSg W19cBadfzmR/TwkiLT51t4UUb3l9GETQOsK2qQEo3rxcAuou6LJgXy0DPhjhsPs1fsHU 3TMmSH/zD6n4iXjHS3nyaYWekXZJHFHL6JGz+HNmjqShtF4/pl8iY9ZxHkPl/7EhyN05 MdIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KT6EplGN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id da15si5796955edb.140.2020.04.30.07.07.44; Thu, 30 Apr 2020 07:08:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KT6EplGN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728079AbgD3OFZ (ORCPT + 99 others); Thu, 30 Apr 2020 10:05:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:34506 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728586AbgD3NxB (ORCPT ); Thu, 30 Apr 2020 09:53:01 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F0B7B208DB; Thu, 30 Apr 2020 13:52:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588254780; bh=R7xIYQrlJiXMsfv9y/AFv2LM+jP7ACZzBBhPtjMf1lE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KT6EplGNYJW4ddxLTBhjJ25TOkHlHmLEk3GbjVduMzzjih8ns6CtFFZGgAHa3Yryi eaPoBnnVQQ2PbSFEvJN3CCGeIrHq1yJ2YOCROS8bld1fSzINWTNDb76AdoiXrEVnYC e71lkpuxf4DES43UUSxZO3tzWqai8rKhMum7Mn78= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= , Xiumei Mu , Alexei Starovoitov , Jesper Dangaard Brouer , Song Liu , Sasha Levin , netdev@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 37/57] cpumap: Avoid warning when CONFIG_DEBUG_PER_CPU_MAPS is enabled Date: Thu, 30 Apr 2020 09:51:58 -0400 Message-Id: <20200430135218.20372-37-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200430135218.20372-1-sashal@kernel.org> References: <20200430135218.20372-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Toke Høiland-Jørgensen [ Upstream commit bc23d0e3f717ced21fbfacab3ab887d55e5ba367 ] When the kernel is built with CONFIG_DEBUG_PER_CPU_MAPS, the cpumap code can trigger a spurious warning if CONFIG_CPUMASK_OFFSTACK is also set. This happens because in this configuration, NR_CPUS can be larger than nr_cpumask_bits, so the initial check in cpu_map_alloc() is not sufficient to guard against hitting the warning in cpumask_check(). Fix this by explicitly checking the supplied key against the nr_cpumask_bits variable before calling cpu_possible(). Fixes: 6710e1126934 ("bpf: introduce new bpf cpu map type BPF_MAP_TYPE_CPUMAP") Reported-by: Xiumei Mu Signed-off-by: Toke Høiland-Jørgensen Signed-off-by: Alexei Starovoitov Tested-by: Xiumei Mu Acked-by: Jesper Dangaard Brouer Acked-by: Song Liu Link: https://lore.kernel.org/bpf/20200416083120.453718-1-toke@redhat.com Signed-off-by: Sasha Levin --- kernel/bpf/cpumap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/bpf/cpumap.c b/kernel/bpf/cpumap.c index ef49e17ae47cb..a367fc8503933 100644 --- a/kernel/bpf/cpumap.c +++ b/kernel/bpf/cpumap.c @@ -486,7 +486,7 @@ static int cpu_map_update_elem(struct bpf_map *map, void *key, void *value, return -EOVERFLOW; /* Make sure CPU is a valid possible cpu */ - if (!cpu_possible(key_cpu)) + if (key_cpu >= nr_cpumask_bits || !cpu_possible(key_cpu)) return -ENODEV; if (qsize == 0) { -- 2.20.1