From patchwork Sat Jun 19 09:31:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12332835 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 124B7C2B9F4 for ; Sat, 19 Jun 2021 09:32:56 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CD150611CE for ; Sat, 19 Jun 2021 09:32:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CD150611CE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B43C66B0075; Sat, 19 Jun 2021 05:32:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AF49E6B0078; Sat, 19 Jun 2021 05:32:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8D49D6B007B; Sat, 19 Jun 2021 05:32:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0241.hostedemail.com [216.40.44.241]) by kanga.kvack.org (Postfix) with ESMTP id 41A176B0074 for ; Sat, 19 Jun 2021 05:32:50 -0400 (EDT) Received: from smtpin38.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id C8B068249980 for ; Sat, 19 Jun 2021 09:32:49 +0000 (UTC) X-FDA: 78269958858.38.C8CF8E0 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf30.hostedemail.com (Postfix) with ESMTP id 3F68AE0004E2 for ; Sat, 19 Jun 2021 09:32:48 +0000 (UTC) Received: from dggeme703-chm.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4G6Vpf54kwz6wK5; Sat, 19 Jun 2021 17:28:42 +0800 (CST) Received: from huawei.com (10.175.104.170) by dggeme703-chm.china.huawei.com (10.1.199.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Sat, 19 Jun 2021 17:32:44 +0800 From: Miaohe Lin To: CC: , , , Subject: [PATCH 1/6] mm/z3fold: define macro NCHUNKS as TOTAL_CHUNKS - ZHDR_CHUNKS Date: Sat, 19 Jun 2021 17:31:46 +0800 Message-ID: <20210619093151.1492174-2-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20210619093151.1492174-1-linmiaohe@huawei.com> References: <20210619093151.1492174-1-linmiaohe@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.104.170] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggeme703-chm.china.huawei.com (10.1.199.99) X-CFilter-Loop: Reflected Authentication-Results: imf30.hostedemail.com; dkim=none; spf=pass (imf30.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=none) header.from=huawei.com X-Stat-Signature: azdnzzs1xx8trcdza64k5z78rthcbtwg X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 3F68AE0004E2 X-HE-Tag: 1624095168-165618 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: To improve the code readability, we could define macro NCHUNKS as TOTAL_CHUNKS - ZHDR_CHUNKS. No functional change intended. Signed-off-by: Miaohe Lin --- mm/z3fold.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/z3fold.c b/mm/z3fold.c index 56321bf37d56..04d0e493bd2e 100644 --- a/mm/z3fold.c +++ b/mm/z3fold.c @@ -62,7 +62,7 @@ #define ZHDR_SIZE_ALIGNED round_up(sizeof(struct z3fold_header), CHUNK_SIZE) #define ZHDR_CHUNKS (ZHDR_SIZE_ALIGNED >> CHUNK_SHIFT) #define TOTAL_CHUNKS (PAGE_SIZE >> CHUNK_SHIFT) -#define NCHUNKS ((PAGE_SIZE - ZHDR_SIZE_ALIGNED) >> CHUNK_SHIFT) +#define NCHUNKS (TOTAL_CHUNKS - ZHDR_CHUNKS) #define BUDDY_MASK (0x3) #define BUDDY_SHIFT 2 From patchwork Sat Jun 19 09:31:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12332831 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C1FDC49EA2 for ; Sat, 19 Jun 2021 09:32:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CCC4F60FDC for ; Sat, 19 Jun 2021 09:32:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CCC4F60FDC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 154426B0070; Sat, 19 Jun 2021 05:32:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D639C6B0075; Sat, 19 Jun 2021 05:32:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AF2CD6B0078; Sat, 19 Jun 2021 05:32:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0190.hostedemail.com [216.40.44.190]) by kanga.kvack.org (Postfix) with ESMTP id 5D0606B006E for ; Sat, 19 Jun 2021 05:32:49 -0400 (EDT) Received: from smtpin33.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id E180D19B32 for ; Sat, 19 Jun 2021 09:32:48 +0000 (UTC) X-FDA: 78269958816.33.FD7A21E Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf28.hostedemail.com (Postfix) with ESMTP id 3CA6C200110A for ; Sat, 19 Jun 2021 09:32:46 +0000 (UTC) Received: from dggeme703-chm.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4G6Vqv3qKNzZcvB; Sat, 19 Jun 2021 17:29:47 +0800 (CST) Received: from huawei.com (10.175.104.170) by dggeme703-chm.china.huawei.com (10.1.199.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Sat, 19 Jun 2021 17:32:45 +0800 From: Miaohe Lin To: CC: , , , Subject: [PATCH 2/6] mm/z3fold: avoid possible underflow in z3fold_alloc() Date: Sat, 19 Jun 2021 17:31:47 +0800 Message-ID: <20210619093151.1492174-3-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20210619093151.1492174-1-linmiaohe@huawei.com> References: <20210619093151.1492174-1-linmiaohe@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.104.170] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggeme703-chm.china.huawei.com (10.1.199.99) X-CFilter-Loop: Reflected Authentication-Results: imf28.hostedemail.com; dkim=none; spf=pass (imf28.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=none) header.from=huawei.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 3CA6C200110A X-Stat-Signature: dii4i8kie8jjit8bjncc5xcjs7ichi76 X-HE-Tag: 1624095166-75526 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: It is not enough to just make sure the z3fold header is not larger than the page size. When z3fold header is equal to PAGE_SIZE, we would underflow when check alloc size against PAGE_SIZE - ZHDR_SIZE_ALIGNED - CHUNK_SIZE in z3fold_alloc(). Make sure there has remaining spaces for its buddy to fix this theoretical issue. Signed-off-by: Miaohe Lin --- This causes the below checkpatch warning: WARNING: Comparisons should place the constant on the right side of the test #31: FILE: mm/z3fold.c:1812: + BUILD_BUG_ON(ZHDR_SIZE_ALIGNED > PAGE_SIZE - CHUNK_SIZE); But I think the error is false positives as all members are constant. --- mm/z3fold.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/z3fold.c b/mm/z3fold.c index 04d0e493bd2e..e261e14b7753 100644 --- a/mm/z3fold.c +++ b/mm/z3fold.c @@ -1805,8 +1805,11 @@ static int __init init_z3fold(void) { int ret; - /* Make sure the z3fold header is not larger than the page size */ - BUILD_BUG_ON(ZHDR_SIZE_ALIGNED > PAGE_SIZE); + /* + * Make sure the z3fold header is not larger than the page size and + * there has remaining spaces for its buddy. + */ + BUILD_BUG_ON(ZHDR_SIZE_ALIGNED > PAGE_SIZE - CHUNK_SIZE); ret = z3fold_mount(); if (ret) return ret; From patchwork Sat Jun 19 09:31:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12332833 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9615EC48BE5 for ; Sat, 19 Jun 2021 09:32:54 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5945560FDC for ; Sat, 19 Jun 2021 09:32:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5945560FDC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3A10B6B0072; Sat, 19 Jun 2021 05:32:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 095D06B0078; Sat, 19 Jun 2021 05:32:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B8F476B0072; Sat, 19 Jun 2021 05:32:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0072.hostedemail.com [216.40.44.72]) by kanga.kvack.org (Postfix) with ESMTP id 855B66B0073 for ; Sat, 19 Jun 2021 05:32:49 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 0BA821A4D4 for ; Sat, 19 Jun 2021 09:32:49 +0000 (UTC) X-FDA: 78269958858.14.D857B01 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf26.hostedemail.com (Postfix) with ESMTP id 516074202A3C for ; Sat, 19 Jun 2021 09:32:48 +0000 (UTC) Received: from dggeme703-chm.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4G6VnS557Hz1BK5R; Sat, 19 Jun 2021 17:27:40 +0800 (CST) Received: from huawei.com (10.175.104.170) by dggeme703-chm.china.huawei.com (10.1.199.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Sat, 19 Jun 2021 17:32:45 +0800 From: Miaohe Lin To: CC: , , , Subject: [PATCH 3/6] mm/z3fold: remove magic number in z3fold_create_pool() Date: Sat, 19 Jun 2021 17:31:48 +0800 Message-ID: <20210619093151.1492174-4-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20210619093151.1492174-1-linmiaohe@huawei.com> References: <20210619093151.1492174-1-linmiaohe@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.104.170] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggeme703-chm.china.huawei.com (10.1.199.99) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 516074202A3C X-Stat-Signature: csy6pf4t9h4p1zbbwdx8fre4p3n5yj1g Authentication-Results: imf26.hostedemail.com; dkim=none; spf=pass (imf26.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=none) header.from=huawei.com X-HE-Tag: 1624095168-166686 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: It's meaningless to pass a magic number 2 to __alloc_percpu() as there is a minimum alignment size of PCPU_MIN_ALLOC_SIZE (> 2) in it. Also there is no special alignment requirement for unbuddied. So we could replace this magic number with nature alignment, i.e. __alignof__(struct list_head), to improve readability. Signed-off-by: Miaohe Lin --- mm/z3fold.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/z3fold.c b/mm/z3fold.c index e261e14b7753..988d57c143fd 100644 --- a/mm/z3fold.c +++ b/mm/z3fold.c @@ -1000,7 +1000,8 @@ static struct z3fold_pool *z3fold_create_pool(const char *name, gfp_t gfp, goto out_c; spin_lock_init(&pool->lock); spin_lock_init(&pool->stale_lock); - pool->unbuddied = __alloc_percpu(sizeof(struct list_head)*NCHUNKS, 2); + pool->unbuddied = __alloc_percpu(sizeof(struct list_head) * NCHUNKS, + __alignof__(struct list_head)); if (!pool->unbuddied) goto out_pool; for_each_possible_cpu(cpu) { From patchwork Sat Jun 19 09:31:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12332827 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B458C2B9F4 for ; Sat, 19 Jun 2021 09:32:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 349C4610A7 for ; Sat, 19 Jun 2021 09:32:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 349C4610A7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B94D36B0073; Sat, 19 Jun 2021 05:32:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B416D6B006E; Sat, 19 Jun 2021 05:32:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 96D826B0075; Sat, 19 Jun 2021 05:32:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0002.hostedemail.com [216.40.44.2]) by kanga.kvack.org (Postfix) with ESMTP id 60D9A6B0072 for ; Sat, 19 Jun 2021 05:32:49 -0400 (EDT) Received: from smtpin35.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 097CE98BA for ; Sat, 19 Jun 2021 09:32:49 +0000 (UTC) X-FDA: 78269958858.35.56965FF Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf23.hostedemail.com (Postfix) with ESMTP id 67D2AA001A5A for ; Sat, 19 Jun 2021 09:32:48 +0000 (UTC) Received: from dggeme703-chm.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4G6VnT0plNz1BP8L; Sat, 19 Jun 2021 17:27:41 +0800 (CST) Received: from huawei.com (10.175.104.170) by dggeme703-chm.china.huawei.com (10.1.199.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Sat, 19 Jun 2021 17:32:45 +0800 From: Miaohe Lin To: CC: , , , Subject: [PATCH 4/6] mm/z3fold: remove unused function handle_to_z3fold_header() Date: Sat, 19 Jun 2021 17:31:49 +0800 Message-ID: <20210619093151.1492174-5-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20210619093151.1492174-1-linmiaohe@huawei.com> References: <20210619093151.1492174-1-linmiaohe@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.104.170] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggeme703-chm.china.huawei.com (10.1.199.99) X-CFilter-Loop: Reflected Authentication-Results: imf23.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=huawei.com; spf=pass (imf23.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Rspamd-Server: rspam02 X-Stat-Signature: nh3cnt13dnte633cdsk9mirwbs9r3x46 X-Rspamd-Queue-Id: 67D2AA001A5A X-HE-Tag: 1624095168-407325 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: handle_to_z3fold_header() is unused now. So we can remove it. As a result, get_z3fold_header() becomes the only caller of __get_z3fold_header() and the argument lock is always true. Therefore we could further fold the __get_z3fold_header() into get_z3fold_header() with lock = true. Signed-off-by: Miaohe Lin --- mm/z3fold.c | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/mm/z3fold.c b/mm/z3fold.c index 988d57c143fd..bab08c08bf19 100644 --- a/mm/z3fold.c +++ b/mm/z3fold.c @@ -255,9 +255,8 @@ static inline void z3fold_page_unlock(struct z3fold_header *zhdr) spin_unlock(&zhdr->page_lock); } - -static inline struct z3fold_header *__get_z3fold_header(unsigned long handle, - bool lock) +/* return locked z3fold page if it's not headless */ +static inline struct z3fold_header *get_z3fold_header(unsigned long handle) { struct z3fold_buddy_slots *slots; struct z3fold_header *zhdr; @@ -271,13 +270,12 @@ static inline struct z3fold_header *__get_z3fold_header(unsigned long handle, read_lock(&slots->lock); addr = *(unsigned long *)handle; zhdr = (struct z3fold_header *)(addr & PAGE_MASK); - if (lock) - locked = z3fold_page_trylock(zhdr); + locked = z3fold_page_trylock(zhdr); read_unlock(&slots->lock); if (locked) break; cpu_relax(); - } while (lock); + } while (true); } else { zhdr = (struct z3fold_header *)(handle & PAGE_MASK); } @@ -285,18 +283,6 @@ static inline struct z3fold_header *__get_z3fold_header(unsigned long handle, return zhdr; } -/* Returns the z3fold page where a given handle is stored */ -static inline struct z3fold_header *handle_to_z3fold_header(unsigned long h) -{ - return __get_z3fold_header(h, false); -} - -/* return locked z3fold page if it's not headless */ -static inline struct z3fold_header *get_z3fold_header(unsigned long h) -{ - return __get_z3fold_header(h, true); -} - static inline void put_z3fold_header(struct z3fold_header *zhdr) { struct page *page = virt_to_page(zhdr); From patchwork Sat Jun 19 09:31:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12332837 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8452C48BE5 for ; Sat, 19 Jun 2021 09:32:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 697E6613E2 for ; Sat, 19 Jun 2021 09:32:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 697E6613E2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E553A6B0078; Sat, 19 Jun 2021 05:32:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CF8526B007E; Sat, 19 Jun 2021 05:32:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A579D6B007D; Sat, 19 Jun 2021 05:32:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0023.hostedemail.com [216.40.44.23]) by kanga.kvack.org (Postfix) with ESMTP id 6BD676B0075 for ; Sat, 19 Jun 2021 05:32:50 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 06429482A for ; Sat, 19 Jun 2021 09:32:50 +0000 (UTC) X-FDA: 78269958900.24.82D5448 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf29.hostedemail.com (Postfix) with ESMTP id 471D17BB for ; Sat, 19 Jun 2021 09:32:49 +0000 (UTC) Received: from dggeme703-chm.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4G6Vqw5jBDzZdyB; Sat, 19 Jun 2021 17:29:48 +0800 (CST) Received: from huawei.com (10.175.104.170) by dggeme703-chm.china.huawei.com (10.1.199.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Sat, 19 Jun 2021 17:32:46 +0800 From: Miaohe Lin To: CC: , , , Subject: [PATCH 5/6] mm/z3fold: fix potential memory leak in z3fold_destroy_pool() Date: Sat, 19 Jun 2021 17:31:50 +0800 Message-ID: <20210619093151.1492174-6-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20210619093151.1492174-1-linmiaohe@huawei.com> References: <20210619093151.1492174-1-linmiaohe@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.104.170] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggeme703-chm.china.huawei.com (10.1.199.99) X-CFilter-Loop: Reflected Authentication-Results: imf29.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=huawei.com; spf=pass (imf29.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Rspamd-Server: rspam02 X-Stat-Signature: jne1qhtntjhxp1hoxr4arz39t6aajnuw X-Rspamd-Queue-Id: 471D17BB X-HE-Tag: 1624095169-157457 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: There is a memoryleak in z3fold_destroy_pool() as it forgets to free_percpu pool->unbuddied. Call free_percpu for pool->unbuddied to fix this issue. Fixes: d30561c56f41 ("z3fold: use per-cpu unbuddied lists") Signed-off-by: Miaohe Lin --- mm/z3fold.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/z3fold.c b/mm/z3fold.c index bab08c08bf19..196d886a3436 100644 --- a/mm/z3fold.c +++ b/mm/z3fold.c @@ -1048,6 +1048,7 @@ static void z3fold_destroy_pool(struct z3fold_pool *pool) destroy_workqueue(pool->compact_wq); destroy_workqueue(pool->release_wq); z3fold_unregister_migration(pool); + free_percpu(pool->unbuddied); kfree(pool); } From patchwork Sat Jun 19 09:31:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12332839 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DAE07C2B9F4 for ; Sat, 19 Jun 2021 09:32:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A590360FDC for ; Sat, 19 Jun 2021 09:32:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A590360FDC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 37BF06B0074; Sat, 19 Jun 2021 05:32:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 32F4E6B007B; Sat, 19 Jun 2021 05:32:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 160E06B007D; Sat, 19 Jun 2021 05:32:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0238.hostedemail.com [216.40.44.238]) by kanga.kvack.org (Postfix) with ESMTP id 8E7586B0074 for ; Sat, 19 Jun 2021 05:32:50 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 2944E180AD81F for ; Sat, 19 Jun 2021 09:32:50 +0000 (UTC) X-FDA: 78269958900.26.1E1BB2B Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf27.hostedemail.com (Postfix) with ESMTP id 4877D801934D for ; Sat, 19 Jun 2021 09:32:48 +0000 (UTC) Received: from dggeme703-chm.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4G6VnT4w16zXhV7; Sat, 19 Jun 2021 17:27:41 +0800 (CST) Received: from huawei.com (10.175.104.170) by dggeme703-chm.china.huawei.com (10.1.199.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Sat, 19 Jun 2021 17:32:46 +0800 From: Miaohe Lin To: CC: , , , Subject: [PATCH 6/6] mm/z3fold: use release_z3fold_page_locked() to release locked z3fold page Date: Sat, 19 Jun 2021 17:31:51 +0800 Message-ID: <20210619093151.1492174-7-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20210619093151.1492174-1-linmiaohe@huawei.com> References: <20210619093151.1492174-1-linmiaohe@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.104.170] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggeme703-chm.china.huawei.com (10.1.199.99) X-CFilter-Loop: Reflected Authentication-Results: imf27.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=huawei.com; spf=pass (imf27.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Stat-Signature: mph4ggyopxy9thjoumzqrg5cahrbyr9h X-Rspamd-Queue-Id: 4877D801934D X-Rspamd-Server: rspam06 X-HE-Tag: 1624095168-296385 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: We should use release_z3fold_page_locked() to release z3fold page when it's locked, although it looks harmless to use release_z3fold_page() now. Fixes: dcf5aedb24f8 ("z3fold: stricter locking and more careful reclaim") Signed-off-by: Miaohe Lin --- mm/z3fold.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/z3fold.c b/mm/z3fold.c index 196d886a3436..b3c0577b8095 100644 --- a/mm/z3fold.c +++ b/mm/z3fold.c @@ -1372,7 +1372,7 @@ static int z3fold_reclaim_page(struct z3fold_pool *pool, unsigned int retries) if (zhdr->foreign_handles || test_and_set_bit(PAGE_CLAIMED, &page->private)) { if (kref_put(&zhdr->refcount, - release_z3fold_page)) + release_z3fold_page_locked)) atomic64_dec(&pool->pages_nr); else z3fold_page_unlock(zhdr);