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=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 77503C4724C for ; Thu, 30 Apr 2020 13:51:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4923124953 for ; Thu, 30 Apr 2020 13:51:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588254718; bh=wrABUCT+G08Y7AeY04cIYcN7RrLyYK0q03babfo1+tI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=S4qgObAR52p0JexoJWhQn7tFpflhEkk+F7fPuCh80F2wYxUhJCdSSD0T9Rg8VBpgq OtAT9R1NrMyEKV4DYFQvMMATkTk+towlIEL5S/+lx+2K74hk4DBoCkvr/mSBnvhNO8 O9ey/X6wFoRGk64ZfEzpsNTee61tiUCM4lthIe+E= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726971AbgD3Nv5 (ORCPT ); Thu, 30 Apr 2020 09:51:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:60280 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728163AbgD3Nvm (ORCPT ); Thu, 30 Apr 2020 09:51:42 -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 65046208DB; Thu, 30 Apr 2020 13:51:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588254702; bh=wrABUCT+G08Y7AeY04cIYcN7RrLyYK0q03babfo1+tI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NsLEYb7PhT70nWZdHielVv6+48YS6cNW3KqRJkQC+u96O6K8IJe6XkFptPUmRBw8M ggXFGOZBvFJR5O+Qx7XuR8yEt1Y6cQD4+Rfmf92b2g3cD6uqcL/nZ0CPVQbzOcbBbM fzmV9tc/aht2Q9WrVfMdBTcm52GD0aUxCfeuMwes= 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.6 51/79] cpumap: Avoid warning when CONFIG_DEBUG_PER_CPU_MAPS is enabled Date: Thu, 30 Apr 2020 09:50:15 -0400 Message-Id: <20200430135043.19851-51-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200430135043.19851-1-sashal@kernel.org> References: <20200430135043.19851-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 70f71b154fa57..3fe0b006d2d2e 100644 --- a/kernel/bpf/cpumap.c +++ b/kernel/bpf/cpumap.c @@ -469,7 +469,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