From patchwork Sun Aug 14 14:05:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Haiyue" X-Patchwork-Id: 12942891 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 664C5C25B0F for ; Sun, 14 Aug 2022 14:05:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E44CD6B0075; Sun, 14 Aug 2022 10:05:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DD2296B0078; Sun, 14 Aug 2022 10:05:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BA9C28D0002; Sun, 14 Aug 2022 10:05:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id A4E7C6B0075 for ; Sun, 14 Aug 2022 10:05:30 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 7275B40316 for ; Sun, 14 Aug 2022 14:05:30 +0000 (UTC) X-FDA: 79798370820.14.04EB8B5 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by imf09.hostedemail.com (Postfix) with ESMTP id C0AEE1401B7 for ; Sun, 14 Aug 2022 14:05:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660485929; x=1692021929; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GYw95KnqnMAn0LnzEEb8cqb+pxBsBgkN86qaf6d0pdU=; b=bIkXpVSt4GUoicNe+sbD18yaY0xOpOrH/U70FIhrlJhUZdXcdGgu9CFd VbkT//0mc4E2EeaqPBSMixgXYrjBeqG82OPe7rZT+/hGYxDr+OaWrDPDF EnRLb9ZbcOoP+Rx23nmOikuJyRRRGraIhALknGVX3URCfG5sp+oWrAVQG Uj3NffDLpeeCz106fUnQ+6HRwtvpU+exlYSNa4Wadbkejc287npKzW+2B eXlR+vCualPAF5s27TwrBqyaBOB300mnshB9T+JYPaV+DnLWCauy0wCZi SqfxWdku1MST3ayccUxGIqZzuT0S0HOD1mkCWPFe3jqwEXTj33YuTbBRy w==; X-IronPort-AV: E=McAfee;i="6400,9594,10439"; a="378117190" X-IronPort-AV: E=Sophos;i="5.93,236,1654585200"; d="scan'208";a="378117190" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Aug 2022 07:05:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,236,1654585200"; d="scan'208";a="639385189" Received: from sse-cse-haiyue-nuc.sh.intel.com ([10.239.241.114]) by orsmga001.jf.intel.com with ESMTP; 14 Aug 2022 07:05:26 -0700 From: Haiyue Wang To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: akpm@linux-foundation.org, david@redhat.com, linmiaohe@huawei.com, ying.huang@intel.com, songmuchun@bytedance.com, naoya.horiguchi@linux.dev, alex.sierra@amd.com, Haiyue Wang Subject: [PATCH v2 2/3] mm: migration: fix the FOLL_GET failure on following huge page Date: Sun, 14 Aug 2022 22:05:33 +0800 Message-Id: <20220814140534.363348-3-haiyue.wang@intel.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220814140534.363348-1-haiyue.wang@intel.com> References: <20220812084921.409142-1-haiyue.wang@intel.com> <20220814140534.363348-1-haiyue.wang@intel.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660485930; a=rsa-sha256; cv=none; b=CM9C5vdDD/x5G3PkQXMEUADqd8LPSBr4blkK//owPrlQUlZn6NYYEUHNS1ncGZnZEHrA6w nDGZdF5Fe+vbQl6jOiAl3xjMpweuA0aBfqcqvGpcieE/qCDYudTXLgqam/rPC+a4osysbK JjkBqleFSZCkxgppSblABM7i6PzGT7Q= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=bIkXpVSt; spf=pass (imf09.hostedemail.com: domain of haiyue.wang@intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=haiyue.wang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660485930; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=OLMYkLateswpBzNpsRjhClXb3G72vfKzJMrDc8OBi/Q=; b=0w8zDX22oLn+m/6HhmBoEGh444r5gKYI2bHiDfhoTcmddrS8F036mYW3Bldgc3I001CQ3e ULNTRTnsJ9jrvq9/H9AX8zE5fnF2VtSRx9vxzbGGCS0/LNs3lPFVI+AY7nC79JOj/xfAsi b6dWzqbRsUsUJugnTTsvdr4keJ9vXII= X-Rspam-User: X-Stat-Signature: 84cagu7q4fe3hyswsc8mithakiwb3xfs X-Rspamd-Queue-Id: C0AEE1401B7 Authentication-Results: imf09.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=bIkXpVSt; spf=pass (imf09.hostedemail.com: domain of haiyue.wang@intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=haiyue.wang@intel.com; dmarc=pass (policy=none) header.from=intel.com X-Rspamd-Server: rspam01 X-HE-Tag: 1660485929-486501 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: Not all huge page APIs support FOLL_GET option, so the __NR_move_pages will fail to get the page node information for huge page. This is an temporary solution to mitigate the racing fix. After supporting follow huge page by FOLL_GET is done, this fix can be reverted safely. Fixes: 4cd614841c06 ("mm: migration: fix possible do_pages_stat_array racing with memory offline") Signed-off-by: Haiyue Wang --- mm/migrate.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 3d5f0262ab60..5d304de3950b 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1848,6 +1848,7 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages, for (i = 0; i < nr_pages; i++) { unsigned long addr = (unsigned long)(*pages); + unsigned int foll_flags = FOLL_DUMP; struct vm_area_struct *vma; struct page *page; int err = -EFAULT; @@ -1856,8 +1857,12 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages, if (!vma) goto set_status; + /* Not all huge page follow APIs support 'FOLL_GET' */ + if (!is_vm_hugetlb_page(vma)) + foll_flags |= FOLL_GET; + /* FOLL_DUMP to ignore special (like zero) pages */ - page = follow_page(vma, addr, FOLL_GET | FOLL_DUMP); + page = follow_page(vma, addr, foll_flags); err = PTR_ERR(page); if (IS_ERR(page)) @@ -1865,7 +1870,8 @@ static void do_pages_stat_array(struct mm_struct *mm, unsigned long nr_pages, if (page) { err = page_to_nid(page); - put_page(page); + if (foll_flags & FOLL_GET) + put_page(page); } else { err = -ENOENT; }