From patchwork Mon Sep 17 03:04:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 146830 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp3272095ljw; Sun, 16 Sep 2018 20:07:08 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbjZN1qInC0aNtZd/ZTm4qnGYp/zGwFvwyL1pi0whn5E6osp9ZpnQmrBD+AoYm9cTG4QI5s X-Received: by 2002:a62:a6cc:: with SMTP id r73-v6mr23801005pfl.60.1537153628289; Sun, 16 Sep 2018 20:07:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537153628; cv=none; d=google.com; s=arc-20160816; b=cqFnMDvGHJ8okb2GanX1n9Si67g7e1yuzSvY69fFJzCDwN8jEU9kTBD4ruNXKVys5G HjjV/L8HljjkcDIqno4LyN2EDdxhER7UzCrZiz7f/ju3xXuDK5g2jHqaR+DNyut+Nr5z Wlbpmc+5MnEHrlAnPEydygMweJcpJrR/YktfpCgLnEGz8Uiv0+wbsRf9YUt2EC1mzVE6 87zVQ0UqOqtf+Se4y/F8O0YisoYPN7aNXlkrpvxOmzsHEibk6QTNac9Xdbm5qm9XYvss Zejs6JK6SJpVXIujBw/x0YDvFJG1cCMtlUK6APIn9yqbj8C2OsImsROCI65x6VMCqQAA UG7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature; bh=RocoyjXW8KHfkvBSgBQRn5LR+teywWJUGFzXncryNI8=; b=g3kbEb62V067xYfipiWvFC7E2m7kP6og+lneioxzPw5JlyenVIXnXAkFDOewd2PMZD Ioy9K12Z68erMo9FAE3F3A0mFD/iNkrOnmKeKB+z6VmmaN7WXTbFTaTcxcHrETx9ppY4 NWoSxPViX0XvOFwUKMkxOVXJB6oNHo/JjzzEzb31OBAO7XpJLx2lugrRb2haCwb+Q3Tx mcOy/8/X5PCLw9S++6TAGwWIMsb3akp2gdJGcIaYTSl0UeDYpu/DjGmFFGwXI9uxo49O bMtLcTz12Z0WID/kPHr+dvwNewUuMGmAOn7uzYNgD6/fGVActJZv5h2tDt0uMqwvWbmk quiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=Pz3kZxDW; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d130-v6si13937758pga.657.2018.09.16.20.07.07; Sun, 16 Sep 2018 20:07:08 -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=@microsoft.com header.s=selector1 header.b=Pz3kZxDW; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731137AbeIQIcW (ORCPT + 32 others); Mon, 17 Sep 2018 04:32:22 -0400 Received: from mail-eopbgr690120.outbound.protection.outlook.com ([40.107.69.120]:6882 "EHLO NAM04-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729631AbeIQIcV (ORCPT ); Mon, 17 Sep 2018 04:32:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RocoyjXW8KHfkvBSgBQRn5LR+teywWJUGFzXncryNI8=; b=Pz3kZxDW8DLX7JFog57yo7G/d9V/GDRrv7dyrXlAzipeeCuiJa6RL5nVy8/U6qWEtgKAaooZ4EKqOX1OK3Idg8EPu750twRBKIC7fLDuL2EFIvIh84/yeq95pcj45vSqj5IQXEf8YFcUOrS6iuLBe3aIYt/qWI/sswzZ9PvlGsU= Received: from CY4PR21MB0776.namprd21.prod.outlook.com (10.173.192.22) by CY4PR21MB0166.namprd21.prod.outlook.com (10.173.192.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1164.12; Mon, 17 Sep 2018 03:07:02 +0000 Received: from CY4PR21MB0776.namprd21.prod.outlook.com ([fe80::54e2:88e0:b622:b36]) by CY4PR21MB0776.namprd21.prod.outlook.com ([fe80::54e2:88e0:b622:b36%5]) with mapi id 15.20.1185.003; Mon, 17 Sep 2018 03:07:02 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Sudeep Holla , Sebastian Reichel , Sebastian Reichel , Sasha Levin Subject: [PATCH AUTOSEL 4.4 07/43] power: vexpress: fix corruption in notifier registration Thread-Topic: [PATCH AUTOSEL 4.4 07/43] power: vexpress: fix corruption in notifier registration Thread-Index: AQHUTjM0SJZWIkKXmk2yzPEK/OUNqQ== Date: Mon, 17 Sep 2018 03:04:52 +0000 Message-ID: <20180917030445.484-7-alexander.levin@microsoft.com> References: <20180917030445.484-1-alexander.levin@microsoft.com> In-Reply-To: <20180917030445.484-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; CY4PR21MB0166; 6:/c2X3HHSa8F0pwtSdBWrt8YD8jTHmC+wvk/kmW4WanKrFAvKEivqtT5s6TM4Y5R3Yw3gu3tTKuKGucempAuSEh6NsvkUeXZuhem4qoEng1FadcHtaPakwDxb3At0w4qISgSDmPbcTbD5s9GhOa/qKzhg0AubORVU2s/fvv1JZxmEsUZX91c1o3lU8ujPxYpCN5sy4ZOfbdhXmvJ2HvS8rhP2hpRNCJltRaYu710KbRj8KX/8wcsjLHgcvYXnvP16boToOFrxXueZz7FGNID83S+d3sX9PUtyAkwzbvLKk0Qz4m/RnzK1TLKMPFV5g8R61cL0QCJj2XtxLccHJ7jnokygdBovlZQUdsZiz3zFYhZ0VYRR+7MlOf+rIuxgs8NWdQm+8u2PbdwRA2mUKkO2KjU4gJRlPjzaVVmZvggo35yLdhQVbO40YB98fpcOsmFSW1PeXKWeAwHzVR8CBAlvjQ==; 5:t4o2bSKFecS8ZZbOYLrmj5SajkBYeYnoKeahuyqaWgu0/QSLqQPImiZCn+54o+9DUti2wiEg/AfCSpdAwaFjGWk8RwOvWudWouXxPjmaizWhKKaSWIXTHs5nL2sfYIcvpgWXV7m3MhPaevIqalRP4miBhYRMSYDkZONuF0ZkYco=; 7:MDs3uLrJD4f8ZwpkDQmjtCAq3op19Vay8NQjKyZcawHn326gz5DqZ+JjR2YaVCxxpvkut9QON0AOgy42qr/OyH6AT0Hip+OX5z6QW/Rl7EWK+RKr9tdQj+a9H05bD0KyxpjmQmOjvfiGLRK3fj9GUMLMuwEZ9+9JAIAXxM8yBboUlTgFEMZDexSlRdJTUsRI25a0JK5QlFfMfS+5xM6x8hDE91CDU84dMNHncTMjUJvvMIvgYza7HANWXAKC0sqQ x-ms-office365-filtering-correlation-id: d1abfbab-700b-465c-827c-08d61c4aa454 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989137)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(4618075)(2017052603328)(7193020); SRVR:CY4PR21MB0166; x-ms-traffictypediagnostic: CY4PR21MB0166: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(180628864354917)(28532068793085)(89211679590171); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3002001)(10201501046)(93006095)(93001095)(3231355)(944501410)(52105095)(2018427008)(6055026)(149027)(150027)(6041310)(20161123560045)(20161123558120)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699050)(76991041); SRVR:CY4PR21MB0166; BCL:0; PCL:0; RULEID:; SRVR:CY4PR21MB0166; x-forefront-prvs: 0798146F16 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(376002)(136003)(346002)(366004)(39860400002)(396003)(189003)(199004)(305945005)(256004)(14444005)(217873002)(486006)(186003)(86612001)(66066001)(7736002)(6486002)(102836004)(6512007)(2900100001)(25786009)(14454004)(6666003)(2616005)(476003)(1076002)(575784001)(97736004)(86362001)(6436002)(5660300001)(6346003)(316002)(2501003)(6116002)(76176011)(6506007)(105586002)(8676002)(478600001)(3846002)(106356001)(53936002)(68736007)(72206003)(446003)(22452003)(5250100002)(81156014)(8936002)(36756003)(10090500001)(107886003)(4326008)(110136005)(11346002)(99286004)(81166006)(2906002)(26005)(54906003)(10290500003); DIR:OUT; SFP:1102; SCL:1; SRVR:CY4PR21MB0166; H:CY4PR21MB0776.namprd21.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-message-info: HKxOCCfvqxFIGZZ/dwk97dEQ3K4nD7ghs4bEkxpgZFg+33deTiu/h9lzbTS+WP18jy65nFTmOt5G7AK/Lvc1Jwe2MMo8sipE+uz2Y2tsc5Huj99M/jiL6AlnA56HU8OPA6OiYfdHJ7oZRY43yW09nC0zWndkIMjzRmsF+pHYUv2qyuAJPbSEl9Qe7Uy2x9ewcqzl5Jdp2bN6Uq1uB52/NzwIC6ZGKbU6sjcJI++blUMdT1kDi7I159T/y2KofBXXIq14oiYjpmdbFtmpFK+LjR1X5os5B+kRD37EgjY480NQbxx2CMEMQM2/rfMgOordCuQ1YhCLsrBsFWtiu/iYymmvX8e7ybSPgSw0D6WQYTo= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: d1abfbab-700b-465c-827c-08d61c4aa454 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Sep 2018 03:04:52.9924 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR21MB0166 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sudeep Holla [ Upstream commit 09bebb1adb21ecd04adf7ccb3b06f73e3a851e93 ] Vexpress platforms provide two different restart handlers: SYS_REBOOT that restart the entire system, while DB_RESET only restarts the daughter board containing the CPU. DB_RESET is overridden by SYS_REBOOT if it exists. notifier_chain_register used in register_restart_handler by design relies on notifiers to be registered once only, however vexpress restart notifier can get registered twice. When this happen it corrupts list of notifiers, as result some notifiers can be not called on proper event, traverse on list can be cycled forever, and second unregister can access already freed memory. So far, since this was the only restart handler in the system, no issue was observed even if the same notifier was registered twice. However commit 6c5c0d48b686 ("watchdog: sp805: add restart handler") added support for SP805 restart handlers and since the system under test contains two vexpress restart and two SP805 watchdog instances, it was observed that during the boot traversing the restart handler list looped forever as there's a cycle in that list resulting in boot hang. This patch fixes the issues by ensuring that the notifier is installed only once. Cc: Sebastian Reichel Signed-off-by: Sudeep Holla Fixes: 46c99ac66222 ("power/reset: vexpress: Register with kernel restart handler") Signed-off-by: Sebastian Reichel Signed-off-by: Sasha Levin --- drivers/power/reset/vexpress-poweroff.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) -- 2.17.1 diff --git a/drivers/power/reset/vexpress-poweroff.c b/drivers/power/reset/vexpress-poweroff.c index 6a9bf7089373..ccb619632e46 100644 --- a/drivers/power/reset/vexpress-poweroff.c +++ b/drivers/power/reset/vexpress-poweroff.c @@ -35,6 +35,7 @@ static void vexpress_reset_do(struct device *dev, const char *what) } static struct device *vexpress_power_off_device; +static atomic_t vexpress_restart_nb_refcnt = ATOMIC_INIT(0); static void vexpress_power_off(void) { @@ -99,10 +100,13 @@ static int _vexpress_register_restart_handler(struct device *dev) int err; vexpress_restart_device = dev; - err = register_restart_handler(&vexpress_restart_nb); - if (err) { - dev_err(dev, "cannot register restart handler (err=%d)\n", err); - return err; + if (atomic_inc_return(&vexpress_restart_nb_refcnt) == 1) { + err = register_restart_handler(&vexpress_restart_nb); + if (err) { + dev_err(dev, "cannot register restart handler (err=%d)\n", err); + atomic_dec(&vexpress_restart_nb_refcnt); + return err; + } } device_create_file(dev, &dev_attr_active);