From patchwork Wed Jun 22 17:06:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12891169 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29BF5CCA47D for ; Wed, 22 Jun 2022 17:06:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 05D2E6B00CC; Wed, 22 Jun 2022 13:06:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F28656B00CD; Wed, 22 Jun 2022 13:06:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CDE768E00C9; Wed, 22 Jun 2022 13:06:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id B03AA6B00CC for ; Wed, 22 Jun 2022 13:06:51 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 7056D20589 for ; Wed, 22 Jun 2022 17:06:51 +0000 (UTC) X-FDA: 79606501422.11.AA78E51 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf18.hostedemail.com (Postfix) with ESMTP id A8E991C0096 for ; Wed, 22 Jun 2022 17:06:48 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4LSqWk2dxzzkWhM; Thu, 23 Jun 2022 01:05:22 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 23 Jun 2022 01:06:34 +0800 From: Miaohe Lin To: CC: , , , , , Subject: [PATCH 16/16] mm/huge_memory: comment the subtle logic in __split_huge_pmd Date: Thu, 23 Jun 2022 01:06:27 +0800 Message-ID: <20220622170627.19786-17-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220622170627.19786-1-linmiaohe@huawei.com> References: <20220622170627.19786-1-linmiaohe@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655917609; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MXKxAKOOK4Q84o2hJ8b0bTNW9kwJDI1+cDgfu++r/Bk=; b=EWsJswosB5x639iXjpJyzTe2VFBRxVTQcmHVuAdKvc5LRCWmDZn80NPodGQT73RE5ME8b8 F+uVZ3vCMvyCqneJjonjdu9gxxCFp8q3mgEVHbjv+YE7++l7C/wi8nMu65TYeFX81hN7xU DRH+tYdIDnr5THjYEfrg7G31VQgvW38= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655917609; a=rsa-sha256; cv=none; b=YX1Frgjrke5YdKRqkXLN57XocsuqdD6y5A+cB3l+CogP3x4eRUNXTA1S/Med1X2aqECPHw zu2T1VYCtafeWAvGtnSn6cqUZONgFWf11sCsjnUnvgmhzIMhPvMBdXNTzmOHqgrOdXInng fPNN0YjCqmkPHqFU+BYgzAOto+4swUc= X-Stat-Signature: gibaukzd831oxm4o4fmdpqk5uk55m6sr X-Rspam-User: X-Rspamd-Server: rspam07 Authentication-Results: imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Rspamd-Queue-Id: A8E991C0096 X-HE-Tag: 1655917608-687030 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 dangerous and wrong to call page_folio(pmd_page(*pmd)) when pmd isn't present. But the caller guarantees pmd is present when folio is set. So we should be safe here. Add comment to make it clear. Signed-off-by: Miaohe Lin --- mm/huge_memory.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 8bd937cc1f74..b98b97592bd3 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2234,6 +2234,10 @@ void __split_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd, if (pmd_trans_huge(*pmd) || pmd_devmap(*pmd) || is_pmd_migration_entry(*pmd)) { + /* + * It's safe to call pmd_page when folio is set because it's + * guaranteed that pmd is present. + */ if (folio && folio != page_folio(pmd_page(*pmd))) goto out; __split_huge_pmd_locked(vma, pmd, range.start, freeze);