Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp1105035imj; Thu, 7 Feb 2019 17:52:22 -0800 (PST) X-Google-Smtp-Source: AHgI3IYnaQz1tvEcu5H80f1pT7z/uJx0d/w+95N4gdFf0dp24KMKibO1rSKlD8sn8pqpng7/jQtX X-Received: by 2002:a62:178f:: with SMTP id 137mr19264521pfx.226.1549590742516; Thu, 07 Feb 2019 17:52:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549590742; cv=none; d=google.com; s=arc-20160816; b=KgafITyJ1lw9ywOs4Ojmenzz+THU30GYLqpOz7u7nORxuVlXyjQAl78m8tW7OdGhR7 43RkUKnYUHGfu7RmjctNsdsckBv/J2HHktZsYBddJ+LZL24QutBXSXmEJ3bjRPkTibRX EuDMl19XXzK7B8f0ifoMeALWd8CBIK1xzmYxXtMnTVZHvWXMd+aZ/apmSZ4kyijiaToW vxwi6f92yWMjcg4zXHbYVwZ+HeiSAPD6VAjiczMD6Yzc8jcE9J8cBl00dr+b6sDXI+/M pLqBp50KArrnzRnmKGV+BV+x24hXmzo5vvCQY4UoC/OxTVyxtlOx/lxOWm72FDUDIMu0 oCLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=FJFKGKbsFbV8kb9ahceoJHd0v8IsDiR8SQPJHiBqhjc=; b=cNSGJji09lmaKiF+3AJrRe8O50zKjgWHXR7Qa8SDOh3EhJFkFJSOOEN5ULdrs05Xuu n79CXslqMgnlD2IViPFVkT6j7QkZiaitU0oxZA45not9V6/DsbFWs0MnL8zZTyeiMOfF JG7w49IurZVrbTgQLIJ+wHGxv4DAM2bjDpGyPWTH1lAKokO/ZBz2c3yRV9Y6iHvqorMU r3FYy0O1lKOrVM4++YJaHRtv0szDEGW3ziD+15Ql1Iy/m3fqb1SkUC4CBaVS9mcbTc3O 377qb1yq/rk/S9lf1o8aOsNEfneKZkyBFrJW/cxdCEaoj5Ylo6Mfu3LKBst1Ck/6kQun uhcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=YMlmDMgL; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o6si650291pgv.451.2019.02.07.17.52.07; Thu, 07 Feb 2019 17:52:22 -0800 (PST) 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=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=YMlmDMgL; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727257AbfBHBvl (ORCPT + 99 others); Thu, 7 Feb 2019 20:51:41 -0500 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:13347 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727213AbfBHBvh (ORCPT ); Thu, 7 Feb 2019 20:51:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1549590698; x=1581126698; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=a5eO8iqcCF0fX5LzHmEyvUks9ILPsjzZwae5L7sLHgs=; b=YMlmDMgLSLNEow0MtomAs0Q5NT23MFgayYpl1E5CIICzi7VphNvfPO/i zIzs6EW7sYZvK1oUaucNpXzYs28rvA7qo/JfE1oNKNqaoHKd6LVrWg6oY MeF1C9nS0C90T3Gi+Hga6PB8geg+taG0ciZuX5V5mwFTfObu25uNjf+bi 5PH/pmz2n4Ymuaqs3u7i6VWLculDjyWzjd+RkhZ8CaUpOsOz8cFyklM5H bd8wom3eAky9e9pVgXa9mHOCdEvqSKezft/QHfgnM+/mrIufRjNv9CkoW 6yrADrvhom56iS1vLabyEnlf8wLOg7aGTlLDcLn7wm8Z3f6HAR6zHEXIx w==; X-IronPort-AV: E=Sophos;i="5.58,346,1544457600"; d="scan'208";a="100752808" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 08 Feb 2019 09:51:37 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP; 07 Feb 2019 17:32:20 -0800 Received: from jedi-01.sdcorp.global.sandisk.com (HELO jedi-01.int.fusionio.com) ([10.11.143.218]) by uls-op-cesaip02.wdc.com with ESMTP; 07 Feb 2019 17:51:36 -0800 From: Atish Patra To: linux-riscv@lists.infradead.org Cc: Atish Patra , Alan Kao , Albert Ou , Andreas Schwab , Anup Patel , Daniel Lezcano , Dmitriy Cherkasov , Jason Cooper , linux-kernel@vger.kernel.org, Marc Zyngier , Palmer Dabbelt , =?UTF-8?q?Patrick=20St=C3=A4hlin?= , Paul Walmsley , Thomas Gleixner , Zong Li , Damien Le Moal Subject: [v3 PATCH 5/8] RISC-V: Compare cpuid with NR_CPUS before mapping. Date: Thu, 7 Feb 2019 17:51:18 -0800 Message-Id: <1549590681-24125-6-git-send-email-atish.patra@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1549590681-24125-1-git-send-email-atish.patra@wdc.com> References: <1549590681-24125-1-git-send-email-atish.patra@wdc.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We should never have a cpuid greater that NR_CPUS. Compare with NR_CPUS before creating the mapping between logical and physical CPU ids. This is also mandatory as NR_CPUS check is removed from riscv_of_processor_hartid. Signed-off-by: Atish Patra Reviewed-by: Anup Patel Reviewed-by: Christoph Hellwig --- arch/riscv/kernel/smpboot.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c index 669eb332..f120d325 100644 --- a/arch/riscv/kernel/smpboot.c +++ b/arch/riscv/kernel/smpboot.c @@ -66,6 +66,11 @@ void __init setup_smp(void) found_boot_cpu = 1; continue; } + if (cpuid >= NR_CPUS) { + pr_warn("Invalid cpuid [%d] for hartid [%d]\n", + cpuid, hart); + break; + } cpuid_to_hartid_map(cpuid) = hart; set_cpu_possible(cpuid, true); -- 2.7.4