From patchwork Fri Apr 2 09:32: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: 12180583 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 9DEC9C433B4 for ; Fri, 2 Apr 2021 09:33:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2341E61103 for ; Fri, 2 Apr 2021 09:33:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2341E61103 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 424A36B0071; Fri, 2 Apr 2021 05:33:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3D5646B0072; Fri, 2 Apr 2021 05:33:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 29CAD6B0073; Fri, 2 Apr 2021 05:33:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0043.hostedemail.com [216.40.44.43]) by kanga.kvack.org (Postfix) with ESMTP id 0E9E76B0071 for ; Fri, 2 Apr 2021 05:33:45 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id B4A7110EF1 for ; Fri, 2 Apr 2021 09:33:44 +0000 (UTC) X-FDA: 77986914768.07.01C92B5 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf11.hostedemail.com (Postfix) with ESMTP id 0E1752000254 for ; Fri, 2 Apr 2021 09:33:41 +0000 (UTC) Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4FBZYJ4bH1znYFG; Fri, 2 Apr 2021 17:31:00 +0800 (CST) Received: from huawei.com (10.175.104.175) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.498.0; Fri, 2 Apr 2021 17:33:34 +0800 From: Miaohe Lin To: , CC: , , , , Subject: [PATCH 1/4] mm/hugeltb: remove redundant VM_BUG_ON() in region_add() Date: Fri, 2 Apr 2021 05:32:46 -0400 Message-ID: <20210402093249.25137-2-linmiaohe@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20210402093249.25137-1-linmiaohe@huawei.com> References: <20210402093249.25137-1-linmiaohe@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.104.175] X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 0E1752000254 X-Stat-Signature: yjomirzxpo1p8xtapr6o885p3ndqsudk X-Rspamd-Server: rspam02 Received-SPF: none (huawei.com>: No applicable sender policy available) receiver=imf11; identity=mailfrom; envelope-from=""; helo=szxga04-in.huawei.com; client-ip=45.249.212.190 X-HE-DKIM-Result: none/none X-HE-Tag: 1617356021-253640 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: The same VM_BUG_ON() check is already done in the callee. Remove this extra one to simplify the code slightly. Signed-off-by: Miaohe Lin Reviewed-by: Mike Kravetz --- mm/hugetlb.c | 1 - 1 file changed, 1 deletion(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index c22111f3da20..a03a50b7c410 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -556,7 +556,6 @@ static long region_add(struct resv_map *resv, long f, long t, resv->adds_in_progress -= in_regions_needed; spin_unlock(&resv->lock); - VM_BUG_ON(add < 0); return add; } From patchwork Fri Apr 2 09:32: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: 12180587 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 DD08EC433B4 for ; Fri, 2 Apr 2021 09:33:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6E29860FED for ; Fri, 2 Apr 2021 09:33:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6E29860FED 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 C3BB06B0073; Fri, 2 Apr 2021 05:33:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C12916B0074; Fri, 2 Apr 2021 05:33:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ADC306B0075; Fri, 2 Apr 2021 05:33:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0184.hostedemail.com [216.40.44.184]) by kanga.kvack.org (Postfix) with ESMTP id 9094D6B0073 for ; Fri, 2 Apr 2021 05:33:48 -0400 (EDT) Received: from smtpin40.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 5AB1AFB73 for ; Fri, 2 Apr 2021 09:33:48 +0000 (UTC) X-FDA: 77986914936.40.0B3024A Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) by imf03.hostedemail.com (Postfix) with ESMTP id 53405C0001F7 for ; Fri, 2 Apr 2021 09:33:46 +0000 (UTC) Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4FBZYx5dv0z9vvM; Fri, 2 Apr 2021 17:31:33 +0800 (CST) Received: from huawei.com (10.175.104.175) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.498.0; Fri, 2 Apr 2021 17:33:34 +0800 From: Miaohe Lin To: , CC: , , , , Subject: [PATCH 2/4] mm/hugeltb: simplify the return code of __vma_reservation_common() Date: Fri, 2 Apr 2021 05:32:47 -0400 Message-ID: <20210402093249.25137-3-linmiaohe@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20210402093249.25137-1-linmiaohe@huawei.com> References: <20210402093249.25137-1-linmiaohe@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.104.175] X-CFilter-Loop: Reflected X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 53405C0001F7 X-Stat-Signature: tc48i1zhzb67tfyy3gyq4z9pz8oo9ujz Received-SPF: none (huawei.com>: No applicable sender policy available) receiver=imf03; identity=mailfrom; envelope-from=""; helo=szxga07-in.huawei.com; client-ip=45.249.212.35 X-HE-DKIM-Result: none/none X-HE-Tag: 1617356026-187721 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 guaranteed that the vma is associated with a resv_map, i.e. either VM_MAYSHARE or HPAGE_RESV_OWNER, when the code reaches here or we would have returned via !resv check above. So ret must be less than 0 in the 'else' case. Simplify the return code to make this clear. Signed-off-by: Miaohe Lin --- mm/hugetlb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index a03a50b7c410..b7864abded3d 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2183,7 +2183,7 @@ static long __vma_reservation_common(struct hstate *h, return 1; } else - return ret < 0 ? ret : 0; + return ret; } static long vma_needs_reservation(struct hstate *h, From patchwork Fri Apr 2 09:32: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: 12180589 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 CACFDC43461 for ; Fri, 2 Apr 2021 09:33:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4CCAC61103 for ; Fri, 2 Apr 2021 09:33:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4CCAC61103 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 70C966B0074; Fri, 2 Apr 2021 05:33:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6E3828D0002; Fri, 2 Apr 2021 05:33:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5AB156B0078; Fri, 2 Apr 2021 05:33:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0164.hostedemail.com [216.40.44.164]) by kanga.kvack.org (Postfix) with ESMTP id 413236B0074 for ; Fri, 2 Apr 2021 05:33:49 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id EA98E10EF6 for ; Fri, 2 Apr 2021 09:33:48 +0000 (UTC) X-FDA: 77986914936.02.B4B8360 Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) by imf26.hostedemail.com (Postfix) with ESMTP id 1ED3940002C1 for ; Fri, 2 Apr 2021 09:33:47 +0000 (UTC) Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4FBZZ25mBJz9vtR; Fri, 2 Apr 2021 17:31:38 +0800 (CST) Received: from huawei.com (10.175.104.175) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.498.0; Fri, 2 Apr 2021 17:33:35 +0800 From: Miaohe Lin To: , CC: , , , , Subject: [PATCH 3/4] mm/hugeltb: fix potential wrong gbl_reserve value for hugetlb_acct_memory() Date: Fri, 2 Apr 2021 05:32:48 -0400 Message-ID: <20210402093249.25137-4-linmiaohe@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20210402093249.25137-1-linmiaohe@huawei.com> References: <20210402093249.25137-1-linmiaohe@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.104.175] X-CFilter-Loop: Reflected X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 1ED3940002C1 X-Stat-Signature: r9n8hagy45skdui4noqbf51zrbxqixgm Received-SPF: none (huawei.com>: No applicable sender policy available) receiver=imf26; identity=mailfrom; envelope-from=""; helo=szxga07-in.huawei.com; client-ip=45.249.212.35 X-HE-DKIM-Result: none/none X-HE-Tag: 1617356027-197061 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: The resv_map could be NULL since this routine can be called in the evict inode path for all hugetlbfs inodes. So we could have chg = 0 and this would result in a negative value when chg - freed. This is unexpected for hugepage_subpool_put_pages() and hugetlb_acct_memory(). Fixes: b5cec28d36f5 ("hugetlbfs: truncate_hugepages() takes a range of pages") Signed-off-by: Miaohe Lin --- mm/hugetlb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index b7864abded3d..bdff8d23803f 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5413,6 +5413,7 @@ long hugetlb_unreserve_pages(struct inode *inode, long start, long end, long chg = 0; struct hugepage_subpool *spool = subpool_inode(inode); long gbl_reserve; + long delta; /* * Since this routine can be called in the evict inode path for all @@ -5437,7 +5438,8 @@ long hugetlb_unreserve_pages(struct inode *inode, long start, long end, * If the subpool has a minimum size, the number of global * reservations to be released may be adjusted. */ - gbl_reserve = hugepage_subpool_put_pages(spool, (chg - freed)); + delta = chg > 0 ? chg - freed : freed; + gbl_reserve = hugepage_subpool_put_pages(spool, delta); hugetlb_acct_memory(h, -gbl_reserve); return 0; From patchwork Fri Apr 2 09:32: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: 12180591 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 CFC37C43460 for ; Fri, 2 Apr 2021 09:33:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6B29860FED for ; Fri, 2 Apr 2021 09:33:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6B29860FED 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 E85B46B0075; Fri, 2 Apr 2021 05:33:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E60A26B0078; Fri, 2 Apr 2021 05:33:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C152E6B007D; Fri, 2 Apr 2021 05:33:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0218.hostedemail.com [216.40.44.218]) by kanga.kvack.org (Postfix) with ESMTP id A4D396B0075 for ; Fri, 2 Apr 2021 05:33:50 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 4C0C1824559C for ; Fri, 2 Apr 2021 09:33:50 +0000 (UTC) X-FDA: 77986915020.16.BC80991 Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) by imf10.hostedemail.com (Postfix) with ESMTP id 4AA8340002D3 for ; Fri, 2 Apr 2021 09:33:48 +0000 (UTC) Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4FBZZ263Nsz9vvQ; Fri, 2 Apr 2021 17:31:38 +0800 (CST) Received: from huawei.com (10.175.104.175) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.498.0; Fri, 2 Apr 2021 17:33:36 +0800 From: Miaohe Lin To: , CC: , , , , Subject: [PATCH 4/4] mm/hugeltb: handle the error case in hugetlb_fix_reserve_counts() Date: Fri, 2 Apr 2021 05:32:49 -0400 Message-ID: <20210402093249.25137-5-linmiaohe@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20210402093249.25137-1-linmiaohe@huawei.com> References: <20210402093249.25137-1-linmiaohe@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.104.175] X-CFilter-Loop: Reflected X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 4AA8340002D3 X-Stat-Signature: jck36kgsxt6ssx5geyhuzddh3cydtwhj Received-SPF: none (huawei.com>: No applicable sender policy available) receiver=imf10; identity=mailfrom; envelope-from=""; helo=szxga07-in.huawei.com; client-ip=45.249.212.35 X-HE-DKIM-Result: none/none X-HE-Tag: 1617356028-59433 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: A rare out of memory error would prevent removal of the reserve map region for a page. hugetlb_fix_reserve_counts() handles this rare case to avoid dangling with incorrect counts. Unfortunately, hugepage_subpool_get_pages and hugetlb_acct_memory could possibly fail too. We should correctly handle these cases. Fixes: b5cec28d36f5 ("hugetlbfs: truncate_hugepages() takes a range of pages") Signed-off-by: Miaohe Lin --- mm/hugetlb.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index bdff8d23803f..ca5464ed04b7 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -745,13 +745,20 @@ void hugetlb_fix_reserve_counts(struct inode *inode) { struct hugepage_subpool *spool = subpool_inode(inode); long rsv_adjust; + bool reserved = false; rsv_adjust = hugepage_subpool_get_pages(spool, 1); - if (rsv_adjust) { + if (rsv_adjust > 0) { struct hstate *h = hstate_inode(inode); - hugetlb_acct_memory(h, 1); + if (!hugetlb_acct_memory(h, 1)) + reserved = true; + } else if (!rsv_adjust) { + reserved = true; } + + if (!reserved) + pr_warn("hugetlb: fix reserve count failed\n"); } /*