Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp71202ybp; Thu, 3 Oct 2019 10:18:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqzRXCny+OpPfN0d1jho7H8xi6D1HAhx1ShIPeI0XjRhlaxZYqp6ugXwlfJwyBb1zS1apN5M X-Received: by 2002:a50:fa83:: with SMTP id w3mr10635859edr.262.1570123132741; Thu, 03 Oct 2019 10:18:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570123132; cv=none; d=google.com; s=arc-20160816; b=P4cCCfTlvmDjyM0Y8AZNJ39LLOJxn/DHl/Cu1V/DWJp5Sqyyi4KinXCcqjLMQN9QUU TvLkoEttRzC6o8ppK0hj6L2WTCl8iD4sPTv1O+zM5P5cIrh+Cn0LmGaOtIFIh2UskJqb cFqlxQ5h/p0FVZprfWLq1H1CjwYfjpx7aE2SGZqKRcrnSLr60ITseZIR6XzJ7YlTxahe WvTrJDVWkIKIrpOjL0vjiaHNjy0XA64vRI/dZRqn6HG8LkODWMkeIB5H7JCvawi+RdkQ 53F0TEvYmYQJxdRc65tUoWlgkD4atX3yvDnYTnUqAPL6RtBiEYH67XdIb0o6KjBadHDL 8G6w== 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=h2XK/retk61+nD0r1iOBy4z5KH6H9GkDGxBRz8Fcao8=; b=P0biVo+6DhoYCNxUhdhBGEVUSraquuKkc9PgstWKi9+r9p3rGgczmZku0k6lo78Mcl enQTqO8X2mL1U9QLG1OidTbSuVt3c3yI6NBkM1I29l9iqI9KWX80o6NvD5M3LXe5uENG im6CebIfMIPHGBDEiUN67Y2vhR2tXTRUQcaxYQJdgJyGX3ur7AIQpFZPtW0AKQ/gqXYE I9eJzSqex70GCIGcTAzhGiuaRrWy8f5SYchHUBEWuyx0Jpi2QNq/HW3aeGctO83xJhNl lY5DhrBdhKki3Hc7S9UHM+TK4czwJ+Pc5KM57Nga4JK9004q+QKVcX/xiDxUnRqqlFzW JxNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=S3dh0QGT; 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 pk7si1518397ejb.216.2019.10.03.10.18.28; Thu, 03 Oct 2019 10:18:52 -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=S3dh0QGT; 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 S1731235AbfJCQX2 (ORCPT + 99 others); Thu, 3 Oct 2019 12:23:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:52388 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389247AbfJCQXZ (ORCPT ); Thu, 3 Oct 2019 12:23:25 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 3E97E222BE; Thu, 3 Oct 2019 16:23:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570119804; bh=tdrSIakgkJxkwvj9PwAtp3A0fkdY/Sa05NmNhMrFOb4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S3dh0QGTromyDCeUb3O5Qbqf/PuGeSgRC+IbHhtj8g2yyx2G4CSf/IfTrcfT2Dolt IahsWzn8CJPkgrzeA+EQYi9Pj0OUisJRaeRG99jf4/RjU50yyqWukOftVdJSaRTRBX 7jeIq9myEY42RoQa60jwTExM0OxU+stnouWGjRDs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qian Cai , Michael Ellerman , Madhavan Srinivasan , Jan Stancek Subject: [PATCH 4.19 162/211] powerpc/imc: Dont create debugfs files for cpu-less nodes Date: Thu, 3 Oct 2019 17:53:48 +0200 Message-Id: <20191003154524.920770851@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191003154447.010950442@linuxfoundation.org> References: <20191003154447.010950442@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Madhavan Srinivasan commit 41ba17f20ea835c489e77bd54e2da73184e22060 upstream. Commit <684d984038aa> ('powerpc/powernv: Add debugfs interface for imc-mode and imc') added debugfs interface for the nest imc pmu devices to support changing of different ucode modes. Primarily adding this capability for debug. But when doing so, the code did not consider the case of cpu-less nodes. So when reading the _cmd_ or _mode_ file of a cpu-less node will create this crash. Faulting instruction address: 0xc0000000000d0d58 Oops: Kernel access of bad area, sig: 11 [#1] ... CPU: 67 PID: 5301 Comm: cat Not tainted 5.2.0-rc6-next-20190627+ #19 NIP: c0000000000d0d58 LR: c00000000049aa18 CTR:c0000000000d0d50 REGS: c00020194548f9e0 TRAP: 0300 Not tainted (5.2.0-rc6-next-20190627+) MSR: 9000000000009033 CR:28022822 XER: 00000000 CFAR: c00000000049aa14 DAR: 000000000003fc08 DSISR:40000000 IRQMASK: 0 ... NIP imc_mem_get+0x8/0x20 LR simple_attr_read+0x118/0x170 Call Trace: simple_attr_read+0x70/0x170 (unreliable) debugfs_attr_read+0x6c/0xb0 __vfs_read+0x3c/0x70 vfs_read+0xbc/0x1a0 ksys_read+0x7c/0x140 system_call+0x5c/0x70 Patch fixes the issue with a more robust check for vbase to NULL. Before patch, ls output for the debugfs imc directory # ls /sys/kernel/debug/powerpc/imc/ imc_cmd_0 imc_cmd_251 imc_cmd_253 imc_cmd_255 imc_mode_0 imc_mode_251 imc_mode_253 imc_mode_255 imc_cmd_250 imc_cmd_252 imc_cmd_254 imc_cmd_8 imc_mode_250 imc_mode_252 imc_mode_254 imc_mode_8 After patch, ls output for the debugfs imc directory # ls /sys/kernel/debug/powerpc/imc/ imc_cmd_0 imc_cmd_8 imc_mode_0 imc_mode_8 Actual bug here is that, we have two loops with potentially different loop counts. That is, in imc_get_mem_addr_nest(), loop count is obtained from the dt entries. But in case of export_imc_mode_and_cmd(), loop was based on for_each_nid() count. Patch fixes the loop count in latter based on the struct mem_info. Ideally it would be better to have array size in struct imc_pmu. Fixes: 684d984038aa ('powerpc/powernv: Add debugfs interface for imc-mode and imc') Reported-by: Qian Cai Suggested-by: Michael Ellerman Signed-off-by: Madhavan Srinivasan Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20190827101635.6942-1-maddy@linux.vnet.ibm.com Cc: Jan Stancek Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/platforms/powernv/opal-imc.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) --- a/arch/powerpc/platforms/powernv/opal-imc.c +++ b/arch/powerpc/platforms/powernv/opal-imc.c @@ -57,9 +57,9 @@ static void export_imc_mode_and_cmd(stru struct imc_pmu *pmu_ptr) { static u64 loc, *imc_mode_addr, *imc_cmd_addr; - int chip = 0, nid; char mode[16], cmd[16]; u32 cb_offset; + struct imc_mem_info *ptr = pmu_ptr->mem_info; imc_debugfs_parent = debugfs_create_dir("imc", powerpc_debugfs_root); @@ -73,20 +73,20 @@ static void export_imc_mode_and_cmd(stru if (of_property_read_u32(node, "cb_offset", &cb_offset)) cb_offset = IMC_CNTL_BLK_OFFSET; - for_each_node(nid) { - loc = (u64)(pmu_ptr->mem_info[chip].vbase) + cb_offset; + while (ptr->vbase != NULL) { + loc = (u64)(ptr->vbase) + cb_offset; imc_mode_addr = (u64 *)(loc + IMC_CNTL_BLK_MODE_OFFSET); - sprintf(mode, "imc_mode_%d", nid); + sprintf(mode, "imc_mode_%d", (u32)(ptr->id)); if (!imc_debugfs_create_x64(mode, 0600, imc_debugfs_parent, imc_mode_addr)) goto err; imc_cmd_addr = (u64 *)(loc + IMC_CNTL_BLK_CMD_OFFSET); - sprintf(cmd, "imc_cmd_%d", nid); + sprintf(cmd, "imc_cmd_%d", (u32)(ptr->id)); if (!imc_debugfs_create_x64(cmd, 0600, imc_debugfs_parent, imc_cmd_addr)) goto err; - chip++; + ptr++; } return;