Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp2957029ybf; Mon, 2 Mar 2020 19:37:25 -0800 (PST) X-Google-Smtp-Source: ADFU+vsuR1sHjQxwCIxqYjA9C6aJYk1kn9AwuTssUzQyaB2vAljGvAQRz0CwDDTklz8M8w10K6FS X-Received: by 2002:a9d:4d8f:: with SMTP id u15mr1877805otk.261.1583206645144; Mon, 02 Mar 2020 19:37:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583206645; cv=none; d=google.com; s=arc-20160816; b=dHU2jpqvZOh8npp41xBHB/udm7dAgud7ld0+mfJQu693OnzN8KFMhcO7uGeM5d7xBG 0vf7Ih5Xy/KH6wwGxhoKgr+AgkIbi/7O2YhyphyNjiSLhq471UH5VU8Wgx+KSchPUmjN cEvTHGT9OnxjvwlBXOaZ5zcrGaReeMtFy1bsPrP4PIV9OcsBVcFwPF2KM0/KGO7imJKk eVg77Xr5fue4OiNiwgnZVFzmbqHPyU6KeQ7o2XBRHEVJ8MeVYvJ6IUoglrKEsriQMaSG jlWFPJjYukbnrPMli4468/hyWZfdna3l8SBA2DEvAETPa5dbHuVJ2NP/FAIl6J+tdmKp l85Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=uK5K8Q/LJiHQAnlLVCojigmsFGLwtR4XApK99/lsuZQ=; b=hcxip6aPCXyZoAdGXJykI41Nkp7sdJczl6Dc999ebtSYdzqAeiQ7mP9FUrNksuoczF 7OsNl+pq+TzRRHKMz1VPDtqcdA7Vyn6pK0RiX/jDxYmByKPgH3iG1WsziyQnu+UDZPho k3GtBVZ2u5S6udXGo6hv1rU6jgiKppFlXoHb3wd1plyII8vIVay7ZcBEuCEVFa5PGic1 84axFdomzjrXLm2zktqx47WzsToMBRPfqExmEcRf7d4krL69nH0wAOfNCzcpgR3dJriz wAiHcWeCpVQmDcteN7AQNvoE6/5rYXICiWKZ3ItUjYMPKiSNjj4y9lzqoCGwFeJMPtEV iBWg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z15si1429188oto.191.2020.03.02.19.37.11; Mon, 02 Mar 2020 19:37:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726979AbgCCDhC (ORCPT + 99 others); Mon, 2 Mar 2020 22:37:02 -0500 Received: from mga11.intel.com ([192.55.52.93]:16422 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726947AbgCCDhB (ORCPT ); Mon, 2 Mar 2020 22:37:01 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Mar 2020 19:37:01 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,509,1574150400"; d="scan'208";a="232132380" Received: from yhuang-dev.sh.intel.com ([10.239.159.23]) by fmsmga007.fm.intel.com with ESMTP; 02 Mar 2020 19:36:58 -0800 From: "Huang, Ying" To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , Dave Hansen , David Hildenbrand , Mel Gorman , Vlastimil Babka , Zi Yan , Michal Hocko , Minchan Kim , Johannes Weiner , Hugh Dickins Subject: [PATCH] mm, migrate: Check return value of try_to_unmap() Date: Tue, 3 Mar 2020 11:36:45 +0800 Message-Id: <20200303033645.280694-1-ying.huang@intel.com> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Huang Ying During the page migration, try_to_unmap() is called to replace the page table entries with the migration entries. Now its return value is ignored, that is generally OK in most cases. But in theory, it's possible that try_to_unmap() return false (failure) for the page migration after arch_unmap_one() is called in unmap code. Even if without arch_unmap_one(), it makes code more robust for the future code changing to check the return value. Known issue: I don't know what is the appropriate error code for try_to_unmap() failure. Whether EIO is OK? Signed-off-by: "Huang, Ying" Cc: Dave Hansen Cc: David Hildenbrand Cc: Mel Gorman Cc: Vlastimil Babka Cc: Zi Yan Cc: Michal Hocko Cc: Minchan Kim Cc: Johannes Weiner Cc: Hugh Dickins --- mm/migrate.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 3900044cfaa6..981f8374a6ef 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1116,8 +1116,11 @@ static int __unmap_and_move(struct page *page, struct page *newpage, /* Establish migration ptes */ VM_BUG_ON_PAGE(PageAnon(page) && !PageKsm(page) && !anon_vma, page); - try_to_unmap(page, - TTU_MIGRATION|TTU_IGNORE_MLOCK|TTU_IGNORE_ACCESS); + if (!try_to_unmap(page, + TTU_MIGRATION|TTU_IGNORE_MLOCK|TTU_IGNORE_ACCESS)) { + rc = -EIO; + goto out_unlock_both; + } page_was_mapped = 1; } @@ -1337,8 +1340,11 @@ static int unmap_and_move_huge_page(new_page_t get_new_page, goto put_anon; if (page_mapped(hpage)) { - try_to_unmap(hpage, - TTU_MIGRATION|TTU_IGNORE_MLOCK|TTU_IGNORE_ACCESS); + if (!try_to_unmap(hpage, + TTU_MIGRATION|TTU_IGNORE_MLOCK|TTU_IGNORE_ACCESS)) { + rc = -EIO; + goto unlock_both; + } page_was_mapped = 1; } @@ -1349,6 +1355,7 @@ static int unmap_and_move_huge_page(new_page_t get_new_page, remove_migration_ptes(hpage, rc == MIGRATEPAGE_SUCCESS ? new_hpage : hpage, false); +unlock_both: unlock_page(new_hpage); put_anon: @@ -2558,8 +2565,7 @@ static void migrate_vma_unmap(struct migrate_vma *migrate) continue; if (page_mapped(page)) { - try_to_unmap(page, flags); - if (page_mapped(page)) + if (!try_to_unmap(page, flags)) goto restore; } -- 2.25.0