From patchwork Thu Aug 20 14:30:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhen Lei X-Patchwork-Id: 11726369 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 292F214F6 for ; Thu, 20 Aug 2020 14:30:58 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 11FC72078D for ; Thu, 20 Aug 2020 14:30:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 11FC72078D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id C0515134A64A1; Thu, 20 Aug 2020 07:30:57 -0700 (PDT) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=45.249.212.35; helo=huawei.com; envelope-from=thunder.leizhen@huawei.com; receiver= Received: from huawei.com (szxga07-in.huawei.com [45.249.212.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 50489134A649A for ; Thu, 20 Aug 2020 07:30:55 -0700 (PDT) Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id CD1104045911F351B0E0; Thu, 20 Aug 2020 22:30:51 +0800 (CST) Received: from DESKTOP-C3MD9UG.china.huawei.com (10.174.177.253) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.487.0; Thu, 20 Aug 2020 22:30:41 +0800 From: Zhen Lei To: Oliver O'Halloran , Dan Williams , Vishal Verma , "Dave Jiang" , Ira Weiny , linux-nvdimm , linux-kernel Subject: [PATCH 1/4] libnvdimm: remove redundant list_empty() check in badrange.c Date: Thu, 20 Aug 2020 22:30:24 +0800 Message-ID: <20200820143027.3241-2-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20200820143027.3241-1-thunder.leizhen@huawei.com> References: <20200820143027.3241-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.177.253] X-CFilter-Loop: Reflected Message-ID-Hash: WYRGLBRIFVTROJNTDQUGA2JKGUN4AQTE X-Message-ID-Hash: WYRGLBRIFVTROJNTDQUGA2JKGUN4AQTE X-MailFrom: thunder.leizhen@huawei.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation CC: Zhen Lei X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: In add_badrange() or badblocks_populate(), the list_empty() branch does the same things as the code after list_for_each_entry(). And the list_for_each_entry() will do noting when list_empty(). So the list_empty() branch can be removed without functional change, let the code after list_for_each_entry() to do it. Signed-off-by: Zhen Lei --- drivers/nvdimm/badrange.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/drivers/nvdimm/badrange.c b/drivers/nvdimm/badrange.c index b9eeefa27e3a507..9fdba8c43e8605e 100644 --- a/drivers/nvdimm/badrange.c +++ b/drivers/nvdimm/badrange.c @@ -53,13 +53,6 @@ static int add_badrange(struct badrange *badrange, u64 addr, u64 length) bre_new = kzalloc(sizeof(*bre_new), GFP_KERNEL); spin_lock(&badrange->lock); - if (list_empty(&badrange->list)) { - if (!bre_new) - return -ENOMEM; - append_badrange_entry(badrange, bre_new, addr, length); - return 0; - } - /* * There is a chance this is a duplicate, check for those first. * This will be the common case as ARS_STATUS returns all known @@ -215,9 +208,6 @@ static void badblocks_populate(struct badrange *badrange, { struct badrange_entry *bre; - if (list_empty(&badrange->list)) - return; - list_for_each_entry(bre, &badrange->list, list) { u64 bre_end = bre->start + bre->length - 1; From patchwork Thu Aug 20 14:30:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhen Lei X-Patchwork-Id: 11726375 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 E1EA5618 for ; Thu, 20 Aug 2020 14:31:01 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C8A02207BB for ; Thu, 20 Aug 2020 14:31:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C8A02207BB Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 2C68C134A64A8; Thu, 20 Aug 2020 07:31:00 -0700 (PDT) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=45.249.212.35; helo=huawei.com; envelope-from=thunder.leizhen@huawei.com; receiver= Received: from huawei.com (szxga07-in.huawei.com [45.249.212.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 29F56134A6496 for ; Thu, 20 Aug 2020 07:30:56 -0700 (PDT) Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 99608B060FFF36059465; Thu, 20 Aug 2020 22:30:51 +0800 (CST) Received: from DESKTOP-C3MD9UG.china.huawei.com (10.174.177.253) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.487.0; Thu, 20 Aug 2020 22:30:42 +0800 From: Zhen Lei To: Oliver O'Halloran , Dan Williams , Vishal Verma , "Dave Jiang" , Ira Weiny , linux-nvdimm , linux-kernel Subject: [PATCH 2/4] libnvdimm: eliminate a meaningless spinlock operation Date: Thu, 20 Aug 2020 22:30:25 +0800 Message-ID: <20200820143027.3241-3-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20200820143027.3241-1-thunder.leizhen@huawei.com> References: <20200820143027.3241-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.177.253] X-CFilter-Loop: Reflected Message-ID-Hash: UFEM2EECSPH6YWZX2OTGFTWD36YAERJ5 X-Message-ID-Hash: UFEM2EECSPH6YWZX2OTGFTWD36YAERJ5 X-MailFrom: thunder.leizhen@huawei.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation CC: Zhen Lei X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: badrange_add() take the lock "badrange->lock", but it's released immediately in add_badrange(), protect nothing. Because the static function add_badrange() is only called by badrange_add(), so spread its content into badrange_add(), and move "kfree(bre_new)" out of the lock protection. Fixes: b3b454f694db ("libnvdimm: fix clear poison locking with spinlock ...") Signed-off-by: Zhen Lei --- drivers/nvdimm/badrange.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/drivers/nvdimm/badrange.c b/drivers/nvdimm/badrange.c index 9fdba8c43e8605e..7f78b659057902d 100644 --- a/drivers/nvdimm/badrange.c +++ b/drivers/nvdimm/badrange.c @@ -45,12 +45,12 @@ static int alloc_and_append_badrange_entry(struct badrange *badrange, return 0; } -static int add_badrange(struct badrange *badrange, u64 addr, u64 length) +int badrange_add(struct badrange *badrange, u64 addr, u64 length) { struct badrange_entry *bre, *bre_new; - spin_unlock(&badrange->lock); bre_new = kzalloc(sizeof(*bre_new), GFP_KERNEL); + spin_lock(&badrange->lock); /* @@ -63,6 +63,7 @@ static int add_badrange(struct badrange *badrange, u64 addr, u64 length) /* If length has changed, update this list entry */ if (bre->length != length) bre->length = length; + spin_unlock(&badrange->lock); kfree(bre_new); return 0; } @@ -72,22 +73,15 @@ static int add_badrange(struct badrange *badrange, u64 addr, u64 length) * as any overlapping ranges will get resolved when the list is consumed * and converted to badblocks */ - if (!bre_new) + if (!bre_new) { + spin_unlock(&badrange->lock); return -ENOMEM; - append_badrange_entry(badrange, bre_new, addr, length); - - return 0; -} - -int badrange_add(struct badrange *badrange, u64 addr, u64 length) -{ - int rc; + } - spin_lock(&badrange->lock); - rc = add_badrange(badrange, addr, length); + append_badrange_entry(badrange, bre_new, addr, length); spin_unlock(&badrange->lock); - return rc; + return 0; } EXPORT_SYMBOL_GPL(badrange_add); From patchwork Thu Aug 20 14:30:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhen Lei X-Patchwork-Id: 11726367 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 032F9618 for ; Thu, 20 Aug 2020 14:30:58 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C27502078D for ; Thu, 20 Aug 2020 14:30:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C27502078D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id A36D5134A649C; Thu, 20 Aug 2020 07:30:57 -0700 (PDT) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=45.249.212.35; helo=huawei.com; envelope-from=thunder.leizhen@huawei.com; receiver= Received: from huawei.com (szxga07-in.huawei.com [45.249.212.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 4DFB8134A6496 for ; Thu, 20 Aug 2020 07:30:55 -0700 (PDT) Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id C998F799B7358370849E; Thu, 20 Aug 2020 22:30:51 +0800 (CST) Received: from DESKTOP-C3MD9UG.china.huawei.com (10.174.177.253) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.487.0; Thu, 20 Aug 2020 22:30:43 +0800 From: Zhen Lei To: Oliver O'Halloran , Dan Williams , Vishal Verma , "Dave Jiang" , Ira Weiny , linux-nvdimm , linux-kernel Subject: [PATCH 3/4] libnvdimm: eliminate two unnecessary zero initializations in badrange.c Date: Thu, 20 Aug 2020 22:30:26 +0800 Message-ID: <20200820143027.3241-4-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20200820143027.3241-1-thunder.leizhen@huawei.com> References: <20200820143027.3241-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.177.253] X-CFilter-Loop: Reflected Message-ID-Hash: UD2TJEL6VSD3YA2IOBISFO4EYD4KQXNQ X-Message-ID-Hash: UD2TJEL6VSD3YA2IOBISFO4EYD4KQXNQ X-MailFrom: thunder.leizhen@huawei.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation CC: Zhen Lei X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Currently, the "struct badrange_entry" has three members: start, length, list. In append_badrange_entry(), "start" and "length" will be assigned later, and "list" does not need to be initialized before calling list_add_tail(). That means, the kzalloc() in badrange_add() or alloc_and_append_badrange_entry() can be replaced with kmalloc(), because the zero initialization is not required. Signed-off-by: Zhen Lei --- drivers/nvdimm/badrange.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/nvdimm/badrange.c b/drivers/nvdimm/badrange.c index 7f78b659057902d..13145001c52ff39 100644 --- a/drivers/nvdimm/badrange.c +++ b/drivers/nvdimm/badrange.c @@ -37,7 +37,7 @@ static int alloc_and_append_badrange_entry(struct badrange *badrange, { struct badrange_entry *bre; - bre = kzalloc(sizeof(*bre), flags); + bre = kmalloc(sizeof(*bre), flags); if (!bre) return -ENOMEM; @@ -49,7 +49,7 @@ int badrange_add(struct badrange *badrange, u64 addr, u64 length) { struct badrange_entry *bre, *bre_new; - bre_new = kzalloc(sizeof(*bre_new), GFP_KERNEL); + bre_new = kmalloc(sizeof(*bre_new), GFP_KERNEL); spin_lock(&badrange->lock); From patchwork Thu Aug 20 14:30:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhen Lei X-Patchwork-Id: 11726371 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 922B114F6 for ; Thu, 20 Aug 2020 14:30:59 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7A2B52078D for ; Thu, 20 Aug 2020 14:30:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7A2B52078D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id DFB64134A64A2; Thu, 20 Aug 2020 07:30:58 -0700 (PDT) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=45.249.212.35; helo=huawei.com; envelope-from=thunder.leizhen@huawei.com; receiver= Received: from huawei.com (szxga07-in.huawei.com [45.249.212.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 93B63134A649B for ; Thu, 20 Aug 2020 07:30:55 -0700 (PDT) Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id A0524680DFEFE3E90D12; Thu, 20 Aug 2020 22:30:51 +0800 (CST) Received: from DESKTOP-C3MD9UG.china.huawei.com (10.174.177.253) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.487.0; Thu, 20 Aug 2020 22:30:43 +0800 From: Zhen Lei To: Oliver O'Halloran , Dan Williams , Vishal Verma , "Dave Jiang" , Ira Weiny , linux-nvdimm , linux-kernel Subject: [PATCH 4/4] libnvdimm: avoid unnecessary judgments in nvdimm_namespace_disk_name() Date: Thu, 20 Aug 2020 22:30:27 +0800 Message-ID: <20200820143027.3241-5-thunder.leizhen@huawei.com> X-Mailer: git-send-email 2.26.0.windows.1 In-Reply-To: <20200820143027.3241-1-thunder.leizhen@huawei.com> References: <20200820143027.3241-1-thunder.leizhen@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.177.253] X-CFilter-Loop: Reflected Message-ID-Hash: TTTPW35D7QRO3V32P7F62DELVHUJX4U4 X-Message-ID-Hash: TTTPW35D7QRO3V32P7F62DELVHUJX4U4 X-MailFrom: thunder.leizhen@huawei.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation CC: Zhen Lei X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: suffix ? suffix : "" appears three times, it's easy to get rid of it by initialize the local variable "suffix" to empty string. To avoid having rows that exceed 80 columns, add a new local variable "region_id". No functional change, but it can reduce the code size. Before: text data bss dec hex filename 41749 3697 16 45462 b196 drivers/nvdimm/namespace_devs.o After: text data bss dec hex filename 41653 3697 16 45366 b136 drivers/nvdimm/namespace_devs.o Signed-off-by: Zhen Lei --- drivers/nvdimm/namespace_devs.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_devs.c index 6da67f4d641a27c..ef2800c5da4c99c 100644 --- a/drivers/nvdimm/namespace_devs.c +++ b/drivers/nvdimm/namespace_devs.c @@ -157,7 +157,8 @@ const char *nvdimm_namespace_disk_name(struct nd_namespace_common *ndns, char *name) { struct nd_region *nd_region = to_nd_region(ndns->dev.parent); - const char *suffix = NULL; + const char *suffix = ""; + int region_id = nd_region->id; if (ndns->claim && is_nd_btt(ndns->claim)) suffix = "s"; @@ -173,17 +174,14 @@ const char *nvdimm_namespace_disk_name(struct nd_namespace_common *ndns, } if (nsidx) - sprintf(name, "pmem%d.%d%s", nd_region->id, nsidx, - suffix ? suffix : ""); + sprintf(name, "pmem%d.%d%s", region_id, nsidx, suffix); else - sprintf(name, "pmem%d%s", nd_region->id, - suffix ? suffix : ""); + sprintf(name, "pmem%d%s", region_id, suffix); } else if (is_namespace_blk(&ndns->dev)) { struct nd_namespace_blk *nsblk; nsblk = to_nd_namespace_blk(&ndns->dev); - sprintf(name, "ndblk%d.%d%s", nd_region->id, nsblk->id, - suffix ? suffix : ""); + sprintf(name, "ndblk%d.%d%s", region_id, nsblk->id, suffix); } else { return NULL; }