From patchwork Wed Feb 12 12:03:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Richter X-Patchwork-Id: 11378465 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0A6E7924 for ; Wed, 12 Feb 2020 12:04:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D401A20848 for ; Wed, 12 Feb 2020 12:04:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="sDpM0KUM"; dkim=pass (1024-bit key) header.d=marvell.onmicrosoft.com header.i=@marvell.onmicrosoft.com header.b="SWYMlTvK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727675AbgBLMEf (ORCPT ); Wed, 12 Feb 2020 07:04:35 -0500 Received: from mx0b-0016f401.pphosted.com ([67.231.156.173]:37472 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727535AbgBLMEf (ORCPT ); Wed, 12 Feb 2020 07:04:35 -0500 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01CC0KXV008063; Wed, 12 Feb 2020 04:04:21 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=pfpt0818; bh=ZmuyD3r3TiH1jVbJvMRegp/SV8TVnvHKsQgDMUG0nuQ=; b=sDpM0KUMazBqEtAPkm5rQDqSewU/cfTcvy2qeOykuRvTTadMDbhcKY8wFnOondqLfy+x +F38fdBje/bClCD/EMP279wqojXIbxvkTqftqAlIvwIzLqjKmT1VbcBvmRasCTqY+8cG 4+NufUqVDd5rQUPaCvgvckzMUhK5dwFCaBfi2xw+ygW0ncM6dqSDsZ8pAipT+SXWFP7l QtS0ck2PZUo+B6IT845JQnbWilf/Wlt4XiG6L29A4PiDH2wqhS8+mAwdXEhaAIqqL9xE V1+wBrlZ5VMSp4NpXb0l6NZCQbZtfpKeUFFlOPvpB3dDRz1bXHkWDSDkpQCNJQzgq45o Bw== Received: from sc-exch04.marvell.com ([199.233.58.184]) by mx0b-0016f401.pphosted.com with ESMTP id 2y1wcsqyw3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 12 Feb 2020 04:04:20 -0800 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by SC-EXCH04.marvell.com (10.93.176.84) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 12 Feb 2020 04:04:18 -0800 Received: from SC-EXCH03.marvell.com (10.93.176.83) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 12 Feb 2020 04:04:18 -0800 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (104.47.58.104) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Wed, 12 Feb 2020 04:04:17 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IdmkHTZ6U8YlYYKU+146LhulED1nBIP+YuVGDLn8261VdrWOtS6XVOGPsGG1aPTtMEahKV1Dhm3HYLJ+uFGLiS+iO4ftp5LU6KF0S51WP47UdNsgxkKQjHZQ1ombnyQ73fkp66KK1MKo0Dl8dYCjh8G4JQP5YlZTDI2M1baVSLsBd2uTEsfzJ0twyzjPC3X/R5GTCVIfdUzXANr7UyVZ6MPnoqaMRVOxU+osounIwApqwKPzbBW+FZpD9iB9gLOp+hNT2Qf8mwmGvClwH9XwJ+bnJUhysn/s/79/8iUgW9dYGhsWmZx2yJA+LAUGRycOUwn2sh+DM3e7CqVhWXR+rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZmuyD3r3TiH1jVbJvMRegp/SV8TVnvHKsQgDMUG0nuQ=; b=aHqJHaDk3f90ZKbeSFEjfaAH3f+yUgsb7Q2c3SxBa4mveZ3KZi8hgYI4rXhQOpIRA0TcR+54jO0mzEdQlgHLg31ovt/z8ox3BpHjJIrfNLoPGSeyEXzSUArt5Pqlrmtts67f5M7hEy7Fd6Hl36rLhD0za2p6fASJiPNHj/ILpTxkkrJzMHC0295i23prUixAzxAqKgiCWLW5+rPw0GijPHg/mUKH8b7ARAK+e5feGdRW9poXLc+81E2dUwtj0ys5z16+v8FHdz9zSRvm5VFeKkY6a0a0u0odWdn9y02NTxIUdrx1bjbw4rKtUy52koR9Pit9jd231Z2Y1pcJJ25Bww== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=marvell.com; dmarc=pass action=none header.from=marvell.com; dkim=pass header.d=marvell.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.onmicrosoft.com; s=selector1-marvell-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZmuyD3r3TiH1jVbJvMRegp/SV8TVnvHKsQgDMUG0nuQ=; b=SWYMlTvKjaVXzfjtRozQkagP+xncFHdbvdl1iZV46/FadIgT2V2MQeuSlMW/vezIOAZfbnbXjj5DUCLuq/MdJv3lCFKa7w/vLYil5tAJ02DLSRgQUhVCE9jjmH2t2ISA6Mp5t1/U5BlgiYdm7wFmUUQwwWT8wKcouT8WnAHFyMI= Received: from MN2PR18MB3408.namprd18.prod.outlook.com (10.255.237.10) by MN2PR18MB3512.namprd18.prod.outlook.com (20.180.247.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2707.27; Wed, 12 Feb 2020 12:04:17 +0000 Received: from MN2PR18MB3408.namprd18.prod.outlook.com ([fe80::b96d:5663:6402:82ea]) by MN2PR18MB3408.namprd18.prod.outlook.com ([fe80::b96d:5663:6402:82ea%7]) with mapi id 15.20.2707.030; Wed, 12 Feb 2020 12:04:17 +0000 From: Robert Richter To: Borislav Petkov , Mauro Carvalho Chehab , Tony Luck CC: James Morse , Aristeu Rozanski , Robert Richter , , Subject: [PATCH v3 1/4] Revert parts of "EDAC/mc_sysfs: Make debug messages consistent" Date: Wed, 12 Feb 2020 13:03:37 +0100 Message-ID: <20200212120340.4764-2-rrichter@marvell.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200212120340.4764-1-rrichter@marvell.com> References: <20200212120340.4764-1-rrichter@marvell.com> X-ClientProxiedBy: HE1PR05CA0226.eurprd05.prod.outlook.com (2603:10a6:3:fa::26) To MN2PR18MB3408.namprd18.prod.outlook.com (2603:10b6:208:165::10) MIME-Version: 1.0 Received: from rric.localdomain (31.208.96.227) by HE1PR05CA0226.eurprd05.prod.outlook.com (2603:10a6:3:fa::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2729.22 via Frontend Transport; Wed, 12 Feb 2020 12:04:15 +0000 X-Mailer: git-send-email 2.20.1 X-Originating-IP: [31.208.96.227] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2c02f96d-83a0-43dc-884a-08d7afb3af41 X-MS-TrafficTypeDiagnostic: MN2PR18MB3512: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:62; X-Forefront-PRVS: 0311124FA9 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4636009)(366004)(136003)(376002)(39860400002)(346002)(396003)(189003)(199004)(8676002)(66476007)(66556008)(36756003)(66946007)(1076003)(6506007)(81156014)(81166006)(6666004)(186003)(2906002)(478600001)(52116002)(8936002)(16526019)(5660300002)(26005)(6512007)(4326008)(6486002)(110136005)(54906003)(86362001)(316002)(2616005)(956004);DIR:OUT;SFP:1101;SCL:1;SRVR:MN2PR18MB3512;H:MN2PR18MB3408.namprd18.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; Received-SPF: None (protection.outlook.com: marvell.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: V4G38hreeuIIOSVtVOdROFpUhqbf9dyIFlUZVxygDCb/fmIZGO7lXxtP3Z/4GF4brkeCxnx+fsg5bVScHdzZ2NT3Q82VUXOmyT75wqZK+qHJjFkEKGxSLP+Pw6R7AGKg/sIEKtcqdS6CSztvnwusGC3ZgpwbOjFA7ZK/O2AAJNnCoxQX8ykCOvvks8fsLnLOD1rruAWzCEHg7ptu/QNpnFce/PWKrNRPY3eE1m/ygfN3vKVwGXk+uIZ2gJ+xaNYQOtVOoK5MkyBeT8rVuiR38kK0wgnc2FgDpsDTVt/GkjbhxZBZtDdqkGwvvUXM2ezHH9o8SML6iKBBw1uc6P9Hqy1epl2I3XgXmq8z6JPhXugb99t92BVXMQwXgHoPlehwzRtheYsbk0ImkMpNGKaHHa9Yrqw86q1IbxvMgG5zMmNqSXq+G4HcxvAukM3fo3JL X-MS-Exchange-AntiSpam-MessageData: GxiMat+jR2LSjE2rdQ7nZQI1pv/KajAJecYRSdVIfzH6+ESBuJ6Ah2+THXpXwAzHB+DbW8lCtmBjhQBXF1III6ztpf3xZBzOsxJCStS3dj4ytmF5+C5LBGcsxJqpzGT2xGIsOS+flpUyxrHoK8vgeg== X-MS-Exchange-CrossTenant-Network-Message-Id: 2c02f96d-83a0-43dc-884a-08d7afb3af41 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Feb 2020 12:04:17.2227 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 70e1fb47-1155-421d-87fc-2e58f638b6e0 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: xFj/Y+giq4PsoH8hMLVghkO+BF3cwa5hXE7SfVEQP96Qad+u03zkBEk7Bf60QcU5GO16GJQUsC3EMvvqllI+0w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR18MB3512 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-12_06:2020-02-11,2020-02-12 signatures=0 Sender: linux-edac-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org This reverts parts of commit e701f412030ec3783f1c30c7741492693d6213e3. Revert a couple of changes to ease stable backports of the next fix on top of this commit. Due to this revert the next patch will apply without conflicts on 5.3 based or earlier kernels. As the code introduced by the revert will be removed, the resulting code of the fix will be the same as without the revert. Signed-off-by: Robert Richter --- drivers/edac/edac_mc_sysfs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c index 0367554e7437..ba0937140fe4 100644 --- a/drivers/edac/edac_mc_sysfs.c +++ b/drivers/edac/edac_mc_sysfs.c @@ -278,7 +278,7 @@ static void csrow_attr_release(struct device *dev) { struct csrow_info *csrow = container_of(dev, struct csrow_info, dev); - edac_dbg(1, "device %s released\n", dev_name(dev)); + edac_dbg(1, "Releasing csrow device %s\n", dev_name(dev)); kfree(csrow); } @@ -610,7 +610,7 @@ static void dimm_attr_release(struct device *dev) { struct dimm_info *dimm = container_of(dev, struct dimm_info, dev); - edac_dbg(1, "device %s released\n", dev_name(dev)); + edac_dbg(1, "Releasing dimm device %s\n", dev_name(dev)); kfree(dimm); } @@ -895,7 +895,7 @@ static void mci_attr_release(struct device *dev) { struct mem_ctl_info *mci = container_of(dev, struct mem_ctl_info, dev); - edac_dbg(1, "device %s released\n", dev_name(dev)); + edac_dbg(1, "Releasing csrow device %s\n", dev_name(dev)); kfree(mci); } From patchwork Wed Feb 12 12:03:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Richter X-Patchwork-Id: 11378457 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 95C96924 for ; Wed, 12 Feb 2020 12:04:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 614472082F for ; Wed, 12 Feb 2020 12:04:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="sKaPBMJo"; dkim=pass (1024-bit key) header.d=marvell.onmicrosoft.com header.i=@marvell.onmicrosoft.com header.b="LNyzlbAB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728049AbgBLMEq (ORCPT ); Wed, 12 Feb 2020 07:04:46 -0500 Received: from mx0b-0016f401.pphosted.com ([67.231.156.173]:37916 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728092AbgBLMEp (ORCPT ); Wed, 12 Feb 2020 07:04:45 -0500 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01CC0WuL008149; Wed, 12 Feb 2020 04:04:23 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=pfpt0818; bh=Qq2H3AB4e14/RebfiF7Vy1u8BhrrKY416MyJRIw1wwM=; b=sKaPBMJo6esSwc9JhDWdOYlKLj3dWrwf/3g2J84STrLbIa7udOmVUqhgiyWivGWm1XSG U0+3jEKFKGsUdp7eBMiTBAJZDEhQlulwH+A8FciHRKaBaeOeTSoL08d1vlVyJPJTG/1q YnIo+QRy2Zw2qQoVxGqQ577lSI9e6EU5T/gPlXypIHi+e6pJSM6albjnexQNqkO3aWEj 79CNJE7987V+Vq9QxI86dtJ7oF4etakKWQhVq7CNo2on5Ct5jDOcgXMcCdavn52kg5li q91qEvKPDpUjfQVW4VYRe5oEnr+747M8unkEYVfNsK6FEGIppPowSn2kTGR4273XnXPv 4w== Received: from sc-exch03.marvell.com ([199.233.58.183]) by mx0b-0016f401.pphosted.com with ESMTP id 2y1wcsqyw8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 12 Feb 2020 04:04:22 -0800 Received: from SC-EXCH01.marvell.com (10.93.176.81) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 12 Feb 2020 04:04:20 -0800 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (104.47.58.102) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Wed, 12 Feb 2020 04:04:20 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f7FJgtzwnGX4yVU4hDFTl9sDUYGKXLHSGLbPQ96O4v00+d6lzQlZR/YgfhZcN61yRZhgKGN6x/0Qfba84ad39CGSZcP/jbr+ykvZrd2/48s9GM1TcetHNLdkvKLeFWzns/100gHTQSiUeB+oWIOwz62WeAQh8qI0dSRYB5Cd+HfE+HGUhta3QCBOOGfaSxw/5xxhUnePTRrqOY7MBSqYJNqPidqt0viWHdXp3pVJ2Di3yRIivez2vviSS9oy/Xc3Z2LOFlFyICf+2p3VusH5eflMYprWiOYSOYLfS1SuYa+1+co6oKGIgerW87gm6ucwFtCNRzX9yxFWDiiaxaZG6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Qq2H3AB4e14/RebfiF7Vy1u8BhrrKY416MyJRIw1wwM=; b=aDKNKaZ+kgsbDdUzGrqX1sYa+FFgtyZu5TgCJv2jSipF+8TNsz6lejpAqSIEJBo9+jm0yRoFht2YCX+b7osEJvrmRxE25f7EPLLMRPEO+vQQqjLj4OrR1qI9lMXfAu9Y6rZPQjecpn5xIDyFGPKPsU3xwFEMKlYftWhhXVrFcUZtC00svqhP2pER9CDmGl3YH9WxGW2yvjZrmV2GrmPRXq+hXfscLgwzMDTbDDOsAfJg61HWoC5CUAPJneAiLkCNlueZtsE4ExA5FKDKWgggqNRkotvQCjrl+c0pZBYCfu6lZnOsmDjNf1uvEdbZb+W2X1lFJodVOohQ0noa/t8gZw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=marvell.com; dmarc=pass action=none header.from=marvell.com; dkim=pass header.d=marvell.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.onmicrosoft.com; s=selector1-marvell-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Qq2H3AB4e14/RebfiF7Vy1u8BhrrKY416MyJRIw1wwM=; b=LNyzlbAB7D4Y1OO3qkwE2nB6OplILRm87aKGRPS+2PKQZGA6IQAPnIviJ05KycmA7xz0iGJbRaZ5oens8OW+gGv8bVYkRsr+q7w4ucXowzZGR3M1a66Vz69M4x7GX7Gf+GwgYfaydVabRo7Fp8h3k8+C/yUPvzVLU9+AnXomlC0= Received: from MN2PR18MB3408.namprd18.prod.outlook.com (10.255.237.10) by MN2PR18MB3512.namprd18.prod.outlook.com (20.180.247.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2707.27; Wed, 12 Feb 2020 12:04:19 +0000 Received: from MN2PR18MB3408.namprd18.prod.outlook.com ([fe80::b96d:5663:6402:82ea]) by MN2PR18MB3408.namprd18.prod.outlook.com ([fe80::b96d:5663:6402:82ea%7]) with mapi id 15.20.2707.030; Wed, 12 Feb 2020 12:04:19 +0000 From: Robert Richter To: Borislav Petkov , Mauro Carvalho Chehab , Tony Luck CC: James Morse , Aristeu Rozanski , Robert Richter , , , John Garry Subject: [PATCH v3 2/4] EDAC/mc: Fix use-after-free and memleaks during device removal Date: Wed, 12 Feb 2020 13:03:38 +0100 Message-ID: <20200212120340.4764-3-rrichter@marvell.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200212120340.4764-1-rrichter@marvell.com> References: <20200212120340.4764-1-rrichter@marvell.com> X-ClientProxiedBy: HE1PR05CA0226.eurprd05.prod.outlook.com (2603:10a6:3:fa::26) To MN2PR18MB3408.namprd18.prod.outlook.com (2603:10b6:208:165::10) MIME-Version: 1.0 Received: from rric.localdomain (31.208.96.227) by HE1PR05CA0226.eurprd05.prod.outlook.com (2603:10a6:3:fa::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2729.22 via Frontend Transport; Wed, 12 Feb 2020 12:04:17 +0000 X-Mailer: git-send-email 2.20.1 X-Originating-IP: [31.208.96.227] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d331fab5-6ca2-432a-7960-08d7afb3b093 X-MS-TrafficTypeDiagnostic: MN2PR18MB3512: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:632; X-Forefront-PRVS: 0311124FA9 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4636009)(366004)(136003)(376002)(39860400002)(346002)(396003)(189003)(199004)(8676002)(66476007)(66556008)(36756003)(66946007)(1076003)(6506007)(81156014)(53546011)(81166006)(6666004)(186003)(2906002)(478600001)(52116002)(8936002)(16526019)(5660300002)(26005)(6512007)(4326008)(6486002)(110136005)(54906003)(86362001)(316002)(2616005)(956004);DIR:OUT;SFP:1101;SCL:1;SRVR:MN2PR18MB3512;H:MN2PR18MB3408.namprd18.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; Received-SPF: None (protection.outlook.com: marvell.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /ZXEmFuhnJ93870+dfYA/IwRv9c6WeC1vESUWErjSteMgnSQVO8mQwC7e0JbkbALeVB3L54raBI2HaVtyUa5uyv0URNESVWNmAFrJ4Jb7HXNDUqFROYc4tBOrQWfVKSmED7r7RkEaZufJGT/qfTD4Vf/9fDVfK6aMWf3+Thbf5ifQ1+xof/VgGwDS0pC4AOa1fTvrNbRMHzCRkZbfT1lORhhu4XhRLfpMTqgc/paqYh1W3o247pm8eQ0l0SYpV30cXu0Zl1exejo/P+HFN4Q/hbd/OnwW94iqsG1K5Doay4A+yxw70bjXKPBR2ReQ5YAtof2wfRqNO1O3Gd9G5Xw0596PYlx1rE6c+DWShVeN59ZAz2Eue7aTZWgo8AKSmsmaVukPEOnu/pCRQ4J2P65ohdzUrnxOK6Z//2/a7n0yfJr7qt81PUeipRCOFv89jkT X-MS-Exchange-AntiSpam-MessageData: 7OM1pXJBqEaF8n+fpCe5mNTnlyOT5GCJ2xrj9hjs5DysrPkocVLjZML974ul4T5Ve6igLTWhWZePRYnp6Jaaf8JLOlEskLMzq50SxDtCeqazw5kTTZzrEjWTivRC25ipSnLgJvb3lUz6CitIHppNRw== X-MS-Exchange-CrossTenant-Network-Message-Id: d331fab5-6ca2-432a-7960-08d7afb3b093 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Feb 2020 12:04:19.5374 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 70e1fb47-1155-421d-87fc-2e58f638b6e0 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ybKwpSuEwY3faordwgt5Z6CfhBr5d4PMhc62YlJ4hK7Hmn80fHtspL5Suibz/DOC8z/p8pIdTrrpU9ov2rWjHw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR18MB3512 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-12_06:2020-02-11,2020-02-12 signatures=0 Sender: linux-edac-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org A test kernel with the options set below revealed several issues when removing a mci device: DEBUG_TEST_DRIVER_REMOVE KASAN DEBUG_KMEMLEAK Issues seen: 1) Use-after-free: On 27.11.19 17:07:33, John Garry wrote: > [ 22.104498] BUG: KASAN: use-after-free in > edac_remove_sysfs_mci_device+0x148/0x180 The use-after-free is caused by the mci_for_each_dimm() iterator that is called in edac_remove_sysfs_mci_device(). The iterator was introduced with commit c498afaf7df8 ("EDAC: Introduce an mci_for_each_dimm() iterator"). The iterator loop calls function device_unregister(&dimm->dev), which removes the sysfs entry of the device, but also frees the dimm struct in dimm_attr_release(). When incrementing the loop in mci_for_each_dimm(), the dimm struct is accessed again, but it is already freed. The fix is to free all the mci device's subsequent dimm and csrow objects at a later point in _edac_mc_free() when the mci device is freed. This keeps the data structures intact and the mci device can be fully used until its removal. The change allows the save usage of mci_for_each_dimm() to release dimm devices from sysfs. 2) Memory leaks: Following memory leaks have been detected: # grep edac /sys/kernel/debug/kmemleak | sort | uniq -c 1 [<000000003c0f58f9>] edac_mc_alloc+0x3bc/0x9d0 # mci->csrows 16 [<00000000bb932dc0>] edac_mc_alloc+0x49c/0x9d0 # csr->channels 16 [<00000000e2734dba>] edac_mc_alloc+0x518/0x9d0 # csr->channels[chn] 1 [<00000000eb040168>] edac_mc_alloc+0x5c8/0x9d0 # mci->dimms 34 [<00000000ef737c29>] ghes_edac_register+0x1c8/0x3f8 # see edac_mc_alloc() All leaks are from memory created by edac_mc_alloc(). Note: The test above shows that edac_mc_alloc() was called here from ghes_edac_register(), thus both functions show up in the stack dump, but the driver causing the leaks is edac_mc. The comments with the data structures involved were made manually by analyzing the objdump. The data structures listed above and created by edac_mc_alloc() are not properly removed during device removal, which is done in edac_mc_free(). There are two paths implemented to remove the device depending on device registration, _edac_mc_free() is called if the device is not registered and edac_unregister_sysfs() otherwise. The implemenations differ. For the sysfs case the mci device removal lacks the removal of subsequent data structures (csrows, channels, dimms). This causes the memory leaks (see mci_attr_release()). Fixing this as follows: Unify code and use the _edac_mc_free() code path to free the mci struct and subsequent memory allocations. An effect of this is that no data is freed in edac_mc_sysfs.c (except the "mc" sysfs root node). The patch has been tested with the above kernel options, no issues seen any longer. To backport this patch to 5.4+ kernels, the previous revert patch needs to be applied too or squashed with this patch to avoid conflicts. Reported-by: John Garry Fixes: c498afaf7df8 ("EDAC: Introduce an mci_for_each_dimm() iterator") Fixes: faa2ad09c01c ("edac_mc: edac_mc_free() cannot assume mem_ctl_info is registered in sysfs.") Fixes: 7a623c039075 ("edac: rewrite the sysfs code to use struct device") Signed-off-by: Robert Richter --- drivers/edac/edac_mc.c | 12 +++--------- drivers/edac/edac_mc_sysfs.c | 15 +++------------ 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c index 7243b88f81d8..69e0d90460e6 100644 --- a/drivers/edac/edac_mc.c +++ b/drivers/edac/edac_mc.c @@ -505,16 +505,10 @@ void edac_mc_free(struct mem_ctl_info *mci) { edac_dbg(1, "\n"); - /* If we're not yet registered with sysfs free only what was allocated - * in edac_mc_alloc(). - */ - if (!device_is_registered(&mci->dev)) { - _edac_mc_free(mci); - return; - } + if (device_is_registered(&mci->dev)) + edac_unregister_sysfs(mci); - /* the mci instance is freed here, when the sysfs object is dropped */ - edac_unregister_sysfs(mci); + _edac_mc_free(mci); } EXPORT_SYMBOL_GPL(edac_mc_free); diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c index ba0937140fe4..1c9c6a7b9f66 100644 --- a/drivers/edac/edac_mc_sysfs.c +++ b/drivers/edac/edac_mc_sysfs.c @@ -276,10 +276,7 @@ static const struct attribute_group *csrow_attr_groups[] = { static void csrow_attr_release(struct device *dev) { - struct csrow_info *csrow = container_of(dev, struct csrow_info, dev); - - edac_dbg(1, "Releasing csrow device %s\n", dev_name(dev)); - kfree(csrow); + /* release device with _edac_mc_free() */ } static const struct device_type csrow_attr_type = { @@ -608,10 +605,7 @@ static const struct attribute_group *dimm_attr_groups[] = { static void dimm_attr_release(struct device *dev) { - struct dimm_info *dimm = container_of(dev, struct dimm_info, dev); - - edac_dbg(1, "Releasing dimm device %s\n", dev_name(dev)); - kfree(dimm); + /* release device with _edac_mc_free() */ } static const struct device_type dimm_attr_type = { @@ -893,10 +887,7 @@ static const struct attribute_group *mci_attr_groups[] = { static void mci_attr_release(struct device *dev) { - struct mem_ctl_info *mci = container_of(dev, struct mem_ctl_info, dev); - - edac_dbg(1, "Releasing csrow device %s\n", dev_name(dev)); - kfree(mci); + /* release device with _edac_mc_free() */ } static const struct device_type mci_attr_type = { From patchwork Wed Feb 12 12:03:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Richter X-Patchwork-Id: 11378463 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0F459924 for ; Wed, 12 Feb 2020 12:04:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E31E321734 for ; Wed, 12 Feb 2020 12:04:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="OPqUZIJ6"; dkim=pass (1024-bit key) header.d=marvell.onmicrosoft.com header.i=@marvell.onmicrosoft.com header.b="AlaBSCSv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727933AbgBLMEh (ORCPT ); Wed, 12 Feb 2020 07:04:37 -0500 Received: from mx0a-0016f401.pphosted.com ([67.231.148.174]:42960 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727860AbgBLMEg (ORCPT ); Wed, 12 Feb 2020 07:04:36 -0500 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01CC2R4Q006246; Wed, 12 Feb 2020 04:04:24 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=pfpt0818; bh=KYPxeYe5iUXkUsLpwcrTvWlhZhiK9RMaGy1e6FE4u04=; b=OPqUZIJ68pRG8c/I1wnbeimjYEUhcYy1X2w/c4sjoFyLs9kZhihGu6zPm+MjDcoffy95 uTxFDD6JgPAEPaG9eJHnvkmXhtCxQArPbXT3p4GGYs9l9eoWBT9xm0bw/xlRj8xvTi2k YT6fBylf60qCRg48XHjesAZTgLku66Pl1rRMA4SaraQuuU8muw40fNSddEU9c6YQrdW1 Fn4HK+DgRTNONmDgeKBfMva4JzQWpVl51UHplu+WGCk2kB3mBxhvLgucmAG8ZyYD2ikL qyPCLp4ZPzI53V1gj0kbJrAtbKd3yjjJj596nX/0T95wo6WOLXgPYt/dNTz8slQYJMzU qw== Received: from sc-exch04.marvell.com ([199.233.58.184]) by mx0a-0016f401.pphosted.com with ESMTP id 2y4be29cm6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 12 Feb 2020 04:04:24 -0800 Received: from SC-EXCH03.marvell.com (10.93.176.83) by SC-EXCH04.marvell.com (10.93.176.84) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 12 Feb 2020 04:04:22 -0800 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (104.47.58.103) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Wed, 12 Feb 2020 04:04:22 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AxRpe2PPRjx2VyUcYGzpVr0Dd/GacUXa0O8032Yi/x+sadHlDmmTJOVzA3mJAwysrWVl+aLUlqMl35/18lz8+I6Gju/YTzn8ykI2lr1YYZUnGQHdRrt7w+vrOTuOxBbEkttVUmJDXjFijHKEH957b7UbTPicP6UdSsNXCE3OhRLHPFTxs8TY2Pri0GuiK19dDV/FWaYZkHTRUK7hHvwIN1zjLgTyh/NVDXlqHLdQF/LsgUuk3LpPcPIMisOv07xhFucrHIV4w8V+MjMlfK/45fKQ7YUkE0dJ0un2/YQFep5nOCgj0JFBPhK+fxh8iR5fjn3KqNKC+weKCAcgIO2Kuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KYPxeYe5iUXkUsLpwcrTvWlhZhiK9RMaGy1e6FE4u04=; b=LEwT8eQYBwNjO2GA2KEwLRe6B8bfFiefomFaibpVAc6J5MoZRQQvKv6Psk0fo8Zfj8w0QVAXINwW2YZO0IDP3bD6rGYYad22JUGNLPfF9z+qpncK2IvIjucV6Psnua0bMP7XVciHKrQOzQ9Bw1XzOKzVRsWwXV5WFY3JzBR77zDK5XILsx4+nTgHEOyigUue0pDjP9U899Xzj96LXrSGMv8M+Jvrl5GELw/f9pCRqMezHG1MKQjLSNzqkH1/1mJ4v5FzRqhfiWEeg0IcZgEbzyO9BJ5hKrZXEq7ZX0yCV6R0TVZORqJ3+f8uanOTGPuDgx/irjS7zO/tcv1lFxds3w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=marvell.com; dmarc=pass action=none header.from=marvell.com; dkim=pass header.d=marvell.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.onmicrosoft.com; s=selector1-marvell-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KYPxeYe5iUXkUsLpwcrTvWlhZhiK9RMaGy1e6FE4u04=; b=AlaBSCSvW09US+xXtetsoYP1YxQVA0I6cXsrXXqZ7U8Nldy9KMOsjErs35xmOdCFFzUhmLQiwJ8hw2rTcl7KZ46DWUzIkzCCXq3A62uUXfvtXfGFAMDOLhUmaUr5s2gneQlMY/IYeBar0M2SF1sUbh5yhOVjpg2Kgu1oxPe4IRc= Received: from MN2PR18MB3408.namprd18.prod.outlook.com (10.255.237.10) by MN2PR18MB3512.namprd18.prod.outlook.com (20.180.247.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2707.27; Wed, 12 Feb 2020 12:04:21 +0000 Received: from MN2PR18MB3408.namprd18.prod.outlook.com ([fe80::b96d:5663:6402:82ea]) by MN2PR18MB3408.namprd18.prod.outlook.com ([fe80::b96d:5663:6402:82ea%7]) with mapi id 15.20.2707.030; Wed, 12 Feb 2020 12:04:21 +0000 From: Robert Richter To: Borislav Petkov , Mauro Carvalho Chehab , Tony Luck CC: James Morse , Aristeu Rozanski , Robert Richter , , , Subject: [PATCH v3 3/4] EDAC/sysfs: Remove csrow objects on errors Date: Wed, 12 Feb 2020 13:03:39 +0100 Message-ID: <20200212120340.4764-4-rrichter@marvell.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200212120340.4764-1-rrichter@marvell.com> References: <20200212120340.4764-1-rrichter@marvell.com> X-ClientProxiedBy: HE1PR05CA0226.eurprd05.prod.outlook.com (2603:10a6:3:fa::26) To MN2PR18MB3408.namprd18.prod.outlook.com (2603:10b6:208:165::10) MIME-Version: 1.0 Received: from rric.localdomain (31.208.96.227) by HE1PR05CA0226.eurprd05.prod.outlook.com (2603:10a6:3:fa::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2729.22 via Frontend Transport; Wed, 12 Feb 2020 12:04:20 +0000 X-Mailer: git-send-email 2.20.1 X-Originating-IP: [31.208.96.227] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fbe6e404-7498-42fa-47dc-08d7afb3b1e3 X-MS-TrafficTypeDiagnostic: MN2PR18MB3512: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-Forefront-PRVS: 0311124FA9 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4636009)(366004)(136003)(376002)(39860400002)(346002)(396003)(189003)(199004)(8676002)(66476007)(66556008)(36756003)(66946007)(1076003)(6506007)(81156014)(81166006)(6666004)(186003)(2906002)(478600001)(52116002)(8936002)(16526019)(5660300002)(26005)(6512007)(4326008)(6486002)(110136005)(54906003)(86362001)(316002)(2616005)(956004);DIR:OUT;SFP:1101;SCL:1;SRVR:MN2PR18MB3512;H:MN2PR18MB3408.namprd18.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; Received-SPF: None (protection.outlook.com: marvell.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nTGU0gXiQh5EmIXcFPXtuKxNc724yJW43OaNnQ0tfJ2BL6nb9xpKcL32sbdh+YHbR2Qwn60+NOHJ3nKhFNMgU9hdSK5m1vs/f2QVV48pENLZWUQ2//KJITcl/CTJ0YZSvHZmkFQpBKv/oqtVxPPeboB0h0PkIwH24WoaIqreccpmza8N9kZP6htJK4xT9RsCp458DNKU5+JYDP/rCBCy52b2XqUiXyTfbvsTDi13FAxDpRQL7sfPL/LE3f0YIlTxAOgWNNj+XFtZ9dEpLjp56dUv/gxmap6s0utX5M5l6r/kSk5Q568M30LWzXGnqTcdbLpPoJmzH7CPmc0l+v8q4K7lbCNKouyeGF8odT/YKTaJiLQX/aApqMeblQYO+9UZZb/ewRMbBguv7EW8AFYeUyE98xP3H3LE7w10F9qf6FfJWcI7VnLhehHHdizJHEXt X-MS-Exchange-AntiSpam-MessageData: 28YZx4fcDUYV/oq89PDZmxlB64Q0jXvDnVY9L8bJA0M5B1Kj29mrqMIGsVJ6tc6/aVBfrA8ZShdLUn3OQOSH83zEhWMQM+VsWPV8Y2hBjo3oePKSsmV26TPK8mO8irpEXWZhIFvD2oaoRb6SxwLh8Q== X-MS-Exchange-CrossTenant-Network-Message-Id: fbe6e404-7498-42fa-47dc-08d7afb3b1e3 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Feb 2020 12:04:21.7961 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 70e1fb47-1155-421d-87fc-2e58f638b6e0 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: iydOlmDAB9+yXCjhqLIB/RGWPlJnxFvHa0LvYLCdzorUS0oN98E6bfAeojwg24wJXqB2fbZIAmtjLvEBviPYhQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR18MB3512 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-12_06:2020-02-11,2020-02-12 signatures=0 Sender: linux-edac-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org All created csrow objects must be removed in the error path of edac_create_csrow_objects(). The objects have been added as devices. They need to be removed by doing a device_del() *and* put_device() call to also free their memory. The misssing put_device() leaves a memory leak. Use device_unregister() instead of device_del() which properly unregisters the device doing both. Fixes: 7adc05d2dc3a ("EDAC/sysfs: Drop device references properly") Cc: Signed-off-by: Robert Richter --- drivers/edac/edac_mc_sysfs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c index 1c9c6a7b9f66..c70ec0a306d8 100644 --- a/drivers/edac/edac_mc_sysfs.c +++ b/drivers/edac/edac_mc_sysfs.c @@ -444,8 +444,7 @@ static int edac_create_csrow_objects(struct mem_ctl_info *mci) csrow = mci->csrows[i]; if (!nr_pages_per_csrow(csrow)) continue; - - device_del(&mci->csrows[i]->dev); + device_unregister(&mci->csrows[i]->dev); } return err; From patchwork Wed Feb 12 12:03:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Richter X-Patchwork-Id: 11378459 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D8410109A for ; Wed, 12 Feb 2020 12:04:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B803420848 for ; Wed, 12 Feb 2020 12:04:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=marvell.com header.i=@marvell.com header.b="xwhN96O3"; dkim=pass (1024-bit key) header.d=marvell.onmicrosoft.com header.i=@marvell.onmicrosoft.com header.b="B49OeBvK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728422AbgBLMEj (ORCPT ); Wed, 12 Feb 2020 07:04:39 -0500 Received: from mx0b-0016f401.pphosted.com ([67.231.156.173]:65008 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727860AbgBLMEj (ORCPT ); Wed, 12 Feb 2020 07:04:39 -0500 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01CC0XRB008156; Wed, 12 Feb 2020 04:04:28 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=pfpt0818; bh=zRW39pdfvVU/VZSxrN8MhBFxcE6XufYRgiKMVH6kxpM=; b=xwhN96O3T9nKOtcpUSaHwRvO1mHrrrVWlB4OmL6Qggxi1Jolvg+LzfU472VozPNPEv3r PSToLkaIZcbUfG00Y7o8QnVfAqrysDmzMjJs7zD7wY++Bb4iY8Mn+I5VxZouJvZWH5bi HNsxPYa7eCNjh0G0fyTXsPGgqjd0GSYrz822MTaXRyr+YUIGi2afDHc4fylM1gKVADle ip3/dlCp+ebpRCx19xJJTRZf+gCwXrFx8Kt+keJcufzDpVZMb488l4AHAoh3c2bjpVnx jW6vxOg7/2ifK6q0SjJXw5gu+48/JlQc4QrxbtAPCLcDlmMZRCyBgR4huM8f0Enws3H5 jw== Received: from sc-exch04.marvell.com ([199.233.58.184]) by mx0b-0016f401.pphosted.com with ESMTP id 2y1wcsqywj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 12 Feb 2020 04:04:28 -0800 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by SC-EXCH04.marvell.com (10.93.176.84) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 12 Feb 2020 04:04:26 -0800 Received: from SC-EXCH04.marvell.com (10.93.176.84) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 12 Feb 2020 04:04:25 -0800 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (104.47.58.103) by SC-EXCH04.marvell.com (10.93.176.84) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Wed, 12 Feb 2020 04:04:24 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Xsd5qhx1spKQs1vMXwbVE0zvOvqo2QuBODJ99ICCFI/tYDzOeDPnjtR+J9kaAB/97ww7LqnkJ24vfgD7wzXx6NaMgtUtZlkX2cBsbsVoZvZDTzcjiQ5fPsy4Z/PJ57y1Mw0/D8nixUMbYtJH0zA2yEfOAZbKmNRtzLRuJhxiOgahY8/UyLf0g9rYD1NIBIltXY8LJFWjKq1GLiKmeEc7pEw/qt0KEz/RUDpMv17xlczvrv0tnez97u/q1vhseXE4LPBPCTzJxh8k9XgGHCML4zxZ9pf+ZGh1bFT9+/qs4dhsYUkkYAI6BeLUxHZlLYs6szjHId2eOyF7Hyy1u6BzAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zRW39pdfvVU/VZSxrN8MhBFxcE6XufYRgiKMVH6kxpM=; b=TpGp6EQ0OcvyoETXz9E0eujhjwr3CrWukEGj6/9ePSLdh2oJSLVdqr5r2UP0YHtsFvCG9bi2oWBTYWXhFG47+zqiT+yuvAu1/iUDg2+VcrQY9J1bpfUAdzoqDqFDBgmtPco6hd1rwp+qsHdheeOZIhEHyQcWRlXEWRKhrfXFzTSu8NetzmSpOEXvljtLAc65wCtQ4OnKDFhceZtbpBobt6YmVRnZUwyOgIgVX+JXsCFBkBD9NNHswnUlLbAPCOZ9RIW1A+ipRkjYc7gTXXW5yTspb3sp4zKhlX4D5M3S6DngY1/zeQ+8xvkYEhQc7bnZz7RrXHcyz985tiS/bUNtXg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=marvell.com; dmarc=pass action=none header.from=marvell.com; dkim=pass header.d=marvell.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.onmicrosoft.com; s=selector1-marvell-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zRW39pdfvVU/VZSxrN8MhBFxcE6XufYRgiKMVH6kxpM=; b=B49OeBvK2lrF98wAW8M8dBVIwxU7EhauGlxd9Ykrqnl/N9En4q6UOzaB8wwhTJezx78aSB+fAH6uRJEfZ9+lxLgUhuvyPFtfEheYNp4sPeiFoYibUJH1RuDAT3ZNHn1ih0KPvJx1im23ENMLcRXp998K+EbzCtkYNU5vdkncMI8= Received: from MN2PR18MB3408.namprd18.prod.outlook.com (10.255.237.10) by MN2PR18MB3512.namprd18.prod.outlook.com (20.180.247.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2707.27; Wed, 12 Feb 2020 12:04:24 +0000 Received: from MN2PR18MB3408.namprd18.prod.outlook.com ([fe80::b96d:5663:6402:82ea]) by MN2PR18MB3408.namprd18.prod.outlook.com ([fe80::b96d:5663:6402:82ea%7]) with mapi id 15.20.2707.030; Wed, 12 Feb 2020 12:04:24 +0000 From: Robert Richter To: Borislav Petkov , Mauro Carvalho Chehab , Tony Luck CC: James Morse , Aristeu Rozanski , Robert Richter , , Subject: [PATCH v3 4/4] EDAC/mc: Change mci device removal to use put_device() Date: Wed, 12 Feb 2020 13:03:40 +0100 Message-ID: <20200212120340.4764-5-rrichter@marvell.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200212120340.4764-1-rrichter@marvell.com> References: <20200212120340.4764-1-rrichter@marvell.com> X-ClientProxiedBy: HE1PR05CA0226.eurprd05.prod.outlook.com (2603:10a6:3:fa::26) To MN2PR18MB3408.namprd18.prod.outlook.com (2603:10b6:208:165::10) MIME-Version: 1.0 Received: from rric.localdomain (31.208.96.227) by HE1PR05CA0226.eurprd05.prod.outlook.com (2603:10a6:3:fa::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2729.22 via Frontend Transport; Wed, 12 Feb 2020 12:04:22 +0000 X-Mailer: git-send-email 2.20.1 X-Originating-IP: [31.208.96.227] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d4a859b6-1bcd-41aa-a3dc-08d7afb3b34b X-MS-TrafficTypeDiagnostic: MN2PR18MB3512: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-Forefront-PRVS: 0311124FA9 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4636009)(366004)(136003)(376002)(39860400002)(346002)(396003)(189003)(199004)(8676002)(66476007)(66556008)(36756003)(66946007)(1076003)(6506007)(81156014)(81166006)(6666004)(186003)(2906002)(478600001)(52116002)(8936002)(16526019)(5660300002)(26005)(6512007)(4326008)(6486002)(110136005)(54906003)(86362001)(316002)(2616005)(956004);DIR:OUT;SFP:1101;SCL:1;SRVR:MN2PR18MB3512;H:MN2PR18MB3408.namprd18.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; Received-SPF: None (protection.outlook.com: marvell.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: g81x1N57+IiX7d3j0hx3raaDP6Jl+pC+B4gt/QmiND+ZrBrb+dMnczWecVab5FV0wMn/VFe/nZotm1Ve2avchQlstFoTJwDJR1hQzu6Lk/4eIg7BWee50tKOHgBmb8MrG9CQB2Ac54HjLoAAu/3Xdh+EVcNXsL8mdHpWZ2V8skUGmg3LsuC3xoE0c6VZlWLaPcrZS+976D+tnk9QdJUZHgwYYZNMdXF6sjdDO3fomCK0nvz8hqZ1gLXquqC26vho9ykQLQsSmikQKy344Nf6pGsrKQ/FHUbaU1PQQ6pEm+dqgjcygG2efPBS3BlUYSBKNBNhBqilL+mM13TW5umP1sPS9LTB1FRTCqWUZSLGUiuTN2TnQZ/jpfDpdDAV/kle3hbih6EQ9i077+c65xZIWHbVnSjau7sxWirssuNhBK0WPVjdyJ9oNybeT3jYUSU+ X-MS-Exchange-AntiSpam-MessageData: 3wUTp3aEBEj7N1xVXyFVz/GMbXkO3JKWIO5SWfw3aYUiIUYkoD4JG258Jn/d6BUahnZzW4Kc+7g9/aLr5xbYU9bUfRn+QyIk7v+mmyHWJmnB11iasV5lL9F3+QCx2vZsxuGF2j91O3bKnUl2PgLInA== X-MS-Exchange-CrossTenant-Network-Message-Id: d4a859b6-1bcd-41aa-a3dc-08d7afb3b34b X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Feb 2020 12:04:23.9929 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 70e1fb47-1155-421d-87fc-2e58f638b6e0 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: uG6sBaVHVDX2/FbXvcMOQg0meJindsEspL0BuOHAoUA5XxHkO1f0QN3CksxP5XU65XWEbFZOkApPIYMejsxIzw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR18MB3512 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.572 definitions=2020-02-12_06:2020-02-11,2020-02-12 signatures=0 Sender: linux-edac-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org There are dimm and csrow devices linked to the mci device esp. to show up in sysfs. It must be granted that children devices are removed before its mci parent. Thus, the release functions must be called in the correct order and may not miss any child before releasing its parent. In current implementation this is only granted by the correct order of release functions. A much better approach is to use put_device() that releases the device only after all users are gone. It is the recommended way to release a device and free its memory. The function uses the device's refcount and only frees it if there are no users of it anymore such as children. So implement a mci_release() function to remove mci devices, use put_device() to free it and early initialize the mci device right after its struct was allocated. Change the release function so that it can be universally used no matter if the device is registered or not. Since subsequent dimm and csrow sysfs links are implemented as children devices, their refcounts will keep the parent mci device from being removed as long as sysfs entries exist and until all users have been unregistered in edac_remove_sysfs_mci_device(). Remove edac_unregister_sysfs() and merge mci sysfs removal into edac_remove_sysfs_mci_device(). There is only a single instance now that removes the sysfs entries. The function can now being used in the error paths for cleanup. Also, create device release functions for all involved devices (dev->release), remove device_type release functions (dev_type-> release) and also use dev->init_name instead of dev_set_name(). Signed-off-by: Robert Richter Acked-by: Aristeu Rozanski --- drivers/edac/edac_mc.c | 12 +++-- drivers/edac/edac_mc_sysfs.c | 90 +++++++++++++++--------------------- drivers/edac/edac_module.h | 1 - 3 files changed, 47 insertions(+), 56 deletions(-) diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c index 69e0d90460e6..64785e644482 100644 --- a/drivers/edac/edac_mc.c +++ b/drivers/edac/edac_mc.c @@ -278,6 +278,12 @@ void *edac_align_ptr(void **p, unsigned int size, int n_elems) static void _edac_mc_free(struct mem_ctl_info *mci) { + put_device(&mci->dev); +} + +static void mci_release(struct device *dev) +{ + struct mem_ctl_info *mci = container_of(dev, struct mem_ctl_info, dev); struct csrow_info *csr; int i, chn, row; @@ -371,6 +377,9 @@ struct mem_ctl_info *edac_mc_alloc(unsigned int mc_num, if (mci == NULL) return NULL; + mci->dev.release = mci_release; + device_initialize(&mci->dev); + /* Adjust pointers so they point within the memory we just allocated * rather than an imaginary chunk of memory located at address 0. */ @@ -505,9 +514,6 @@ void edac_mc_free(struct mem_ctl_info *mci) { edac_dbg(1, "\n"); - if (device_is_registered(&mci->dev)) - edac_unregister_sysfs(mci); - _edac_mc_free(mci); } EXPORT_SYMBOL_GPL(edac_mc_free); diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c index c70ec0a306d8..408bace699dc 100644 --- a/drivers/edac/edac_mc_sysfs.c +++ b/drivers/edac/edac_mc_sysfs.c @@ -274,14 +274,8 @@ static const struct attribute_group *csrow_attr_groups[] = { NULL }; -static void csrow_attr_release(struct device *dev) -{ - /* release device with _edac_mc_free() */ -} - static const struct device_type csrow_attr_type = { .groups = csrow_attr_groups, - .release = csrow_attr_release, }; /* @@ -387,6 +381,14 @@ static const struct attribute_group *csrow_dev_groups[] = { NULL }; +static void csrow_release(struct device *dev) +{ + /* + * Nothing to do. We just unregister sysfs here. The mci + * device owns the data and will also release it. + */ +} + static inline int nr_pages_per_csrow(struct csrow_info *csrow) { int chan, nr_pages = 0; @@ -405,6 +407,7 @@ static int edac_create_csrow_object(struct mem_ctl_info *mci, csrow->dev.type = &csrow_attr_type; csrow->dev.groups = csrow_dev_groups; + csrow->dev.release = csrow_release; device_initialize(&csrow->dev); csrow->dev.parent = &mci->dev; csrow->mci = mci; @@ -441,10 +444,8 @@ static int edac_create_csrow_objects(struct mem_ctl_info *mci) error: for (--i; i >= 0; i--) { - csrow = mci->csrows[i]; - if (!nr_pages_per_csrow(csrow)) - continue; - device_unregister(&mci->csrows[i]->dev); + if (device_is_registered(&mci->csrows[i]->dev)) + device_unregister(&mci->csrows[i]->dev); } return err; @@ -453,15 +454,13 @@ static int edac_create_csrow_objects(struct mem_ctl_info *mci) static void edac_delete_csrow_objects(struct mem_ctl_info *mci) { int i; - struct csrow_info *csrow; - for (i = mci->nr_csrows - 1; i >= 0; i--) { - csrow = mci->csrows[i]; - if (!nr_pages_per_csrow(csrow)) - continue; - device_unregister(&mci->csrows[i]->dev); + for (i = 0; i < mci->nr_csrows; i++) { + if (device_is_registered(&mci->csrows[i]->dev)) + device_unregister(&mci->csrows[i]->dev); } } + #endif /* @@ -602,16 +601,18 @@ static const struct attribute_group *dimm_attr_groups[] = { NULL }; -static void dimm_attr_release(struct device *dev) -{ - /* release device with _edac_mc_free() */ -} - static const struct device_type dimm_attr_type = { .groups = dimm_attr_groups, - .release = dimm_attr_release, }; +static void dimm_release(struct device *dev) +{ + /* + * Nothing to do. We just unregister sysfs here. The mci + * device owns the data and will also release it. + */ +} + /* Create a DIMM object under specifed memory controller device */ static int edac_create_dimm_object(struct mem_ctl_info *mci, struct dimm_info *dimm) @@ -620,6 +621,7 @@ static int edac_create_dimm_object(struct mem_ctl_info *mci, dimm->mci = mci; dimm->dev.type = &dimm_attr_type; + dimm->dev.release = dimm_release; device_initialize(&dimm->dev); dimm->dev.parent = &mci->dev; @@ -884,14 +886,8 @@ static const struct attribute_group *mci_attr_groups[] = { NULL }; -static void mci_attr_release(struct device *dev) -{ - /* release device with _edac_mc_free() */ -} - static const struct device_type mci_attr_type = { .groups = mci_attr_groups, - .release = mci_attr_release, }; /* @@ -910,8 +906,6 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci, /* get the /sys/devices/system/edac subsys reference */ mci->dev.type = &mci_attr_type; - device_initialize(&mci->dev); - mci->dev.parent = mci_pdev; mci->dev.groups = groups; dev_set_name(&mci->dev, "mc%d", mci->mc_idx); @@ -921,7 +915,7 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci, err = device_add(&mci->dev); if (err < 0) { edac_dbg(1, "failure: create device %s\n", dev_name(&mci->dev)); - put_device(&mci->dev); + /* no put_device() here, free mci with _edac_mc_free() */ return err; } @@ -937,24 +931,20 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci, err = edac_create_dimm_object(mci, dimm); if (err) - goto fail_unregister_dimm; + goto fail; } #ifdef CONFIG_EDAC_LEGACY_SYSFS err = edac_create_csrow_objects(mci); if (err < 0) - goto fail_unregister_dimm; + goto fail; #endif edac_create_debugfs_nodes(mci); return 0; -fail_unregister_dimm: - mci_for_each_dimm(mci, dimm) { - if (device_is_registered(&dimm->dev)) - device_unregister(&dimm->dev); - } - device_unregister(&mci->dev); +fail: + edac_remove_sysfs_mci_device(mci); return err; } @@ -966,6 +956,9 @@ void edac_remove_sysfs_mci_device(struct mem_ctl_info *mci) { struct dimm_info *dimm; + if (!device_is_registered(&mci->dev)) + return; + edac_dbg(0, "\n"); #ifdef CONFIG_EDAC_DEBUG @@ -976,17 +969,14 @@ void edac_remove_sysfs_mci_device(struct mem_ctl_info *mci) #endif mci_for_each_dimm(mci, dimm) { - if (dimm->nr_pages == 0) + if (!device_is_registered(&dimm->dev)) continue; edac_dbg(1, "unregistering device %s\n", dev_name(&dimm->dev)); device_unregister(&dimm->dev); } -} -void edac_unregister_sysfs(struct mem_ctl_info *mci) -{ - edac_dbg(1, "unregistering device %s\n", dev_name(&mci->dev)); - device_unregister(&mci->dev); + /* only remove the device, but keep mci */ + device_del(&mci->dev); } static void mc_attr_release(struct device *dev) @@ -1000,9 +990,6 @@ static void mc_attr_release(struct device *dev) kfree(dev); } -static const struct device_type mc_attr_type = { - .release = mc_attr_release, -}; /* * Init/exit code for the module. Basically, creates/removes /sys/class/rc */ @@ -1015,11 +1002,10 @@ int __init edac_mc_sysfs_init(void) return -ENOMEM; mci_pdev->bus = edac_get_sysfs_subsys(); - mci_pdev->type = &mc_attr_type; - device_initialize(mci_pdev); - dev_set_name(mci_pdev, "mc"); + mci_pdev->release = mc_attr_release; + mci_pdev->init_name = "mc"; - err = device_add(mci_pdev); + err = device_register(mci_pdev); if (err < 0) { edac_dbg(1, "failure: create device %s\n", dev_name(mci_pdev)); put_device(mci_pdev); diff --git a/drivers/edac/edac_module.h b/drivers/edac/edac_module.h index 388427d378b1..aa1f91688eb8 100644 --- a/drivers/edac/edac_module.h +++ b/drivers/edac/edac_module.h @@ -28,7 +28,6 @@ void edac_mc_sysfs_exit(void); extern int edac_create_sysfs_mci_device(struct mem_ctl_info *mci, const struct attribute_group **groups); extern void edac_remove_sysfs_mci_device(struct mem_ctl_info *mci); -void edac_unregister_sysfs(struct mem_ctl_info *mci); extern int edac_get_log_ue(void); extern int edac_get_log_ce(void); extern int edac_get_panic_on_ue(void);