Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1624814pxa; Thu, 6 Aug 2020 11:51:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfWI53PmSIx/qLFhc70Z+vo7lvB7kc1F4ZHXujIC1aDZ5fFJHIVLFK1odNDpSpwSd0U8IX X-Received: by 2002:a05:6402:3121:: with SMTP id dd1mr5504490edb.72.1596739917433; Thu, 06 Aug 2020 11:51:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596739917; cv=none; d=google.com; s=arc-20160816; b=ay+estS9oXUBz6vDyx14Fn930F/lgxzOWcfFS37yNi1PpBhAN+gGlKSebfHLvm8aqF wff2sjusFdqLRk1Jhu/hU/eR/VFVma//+w58dqqyDH7DaU96nWIxA80V7dxvglZnbRuD HzazGoH4oqWjf6FN1AMAvGBe/le+UvLpVyyHPxxy0BDwYafnsDUocbN+zdk0DijPsLMg urJoFLaflk2fEx+hjpkzK2m10wUD20yt+nCcqt201WQSYoYvxotyDjw8ob6NM9ogqNGc FZTXvHpvbkNq3wEl/uCddqh4SrdEEduqw5AF9oTTywByfIrS0xvFV5jwEVSsSEuM+mNN CP0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=q96l39vKYd7IRXWt1EwDmgBCl4Rsm+1NIezF6mciM4E=; b=yRJeYexirSlg0wEqVG2KZ2q/PACTJBw41je83qZtar4fbtdn9NfPdRYAyKmrKTPEpP aL6bfhz7n73Yl3fPG4bo+tOx5ql9QpyY+WglYWsePvBXZc8x6w54lY7/PIoFvnQgnvUq WXvHzfYT7ximIDlye6A5v93VkPEIltnn5w1cODJXI7Wos5EZUIYSZ4LCq+sGPHp6XSmO FLK8QnFjYaMnDFBST7nyZpuO6Por8iQF/LP+VY/md8kE0FDLQ20tTFp3Cn/7fRieCVA6 98RsGHz6VtSa3D/Yxb3dNiHPz7TUl9Vc52LJqrrfGPywg1TFSvo4QG6bQIjm7p8vnfn5 xHGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=E9dW3ysc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p6si3720629ejd.617.2020.08.06.11.51.34; Thu, 06 Aug 2020 11:51:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=E9dW3ysc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729459AbgHFSuS (ORCPT + 99 others); Thu, 6 Aug 2020 14:50:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726923AbgHFSuH (ORCPT ); Thu, 6 Aug 2020 14:50:07 -0400 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89EF4C061574 for ; Thu, 6 Aug 2020 11:50:07 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id r4so17607654pls.2 for ; Thu, 06 Aug 2020 11:50:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=q96l39vKYd7IRXWt1EwDmgBCl4Rsm+1NIezF6mciM4E=; b=E9dW3yscPVP6RVcDUq47mGdZrysJ2Y2xuRGdoD91TZWH5t/JUh2muJuwL694zqkPC0 DEH4YDFqsrDR1qX670wy1moZlPfDElRst8R7BtycOLc2ZLIzhpqHtwMGjtyOkSLBdl88 mWF6Jux0286C+SZ2QRRURZfTdnxMVVFbbU/BS6dtYSRLI5cfmFUp/Qq/X9QxGxixAeCs KZ+iv3V8/T55lk/nBJiwiRDxgQWKPikmr70iHQ8zj/EdKUdY0ooz/NJN/H/R8B0Dthri HoCuq/IViLUTM9H3sSPr0QRuQFc6PXmcEvo+JydfIwT1u5Ud2hn4ck9uaHZxk6BGHQVd +lTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=q96l39vKYd7IRXWt1EwDmgBCl4Rsm+1NIezF6mciM4E=; b=lsWBbhw8UtWA2LP57whjyfGjbFMMJyQZf8cpAxS1C9+yacvHcjGqtoeV1exJY8royz +19DlLAu2fTEAjbJQF2Vpcfw15NLilUfhaERAnRfwapNFQAegUaKlgJ906cupbvFbOPv Vc9PC9AJvhO2jFV6IQkTAcEm9eL60kSOhaWef08OENZog4e/24TeSXcbLIFQNdACHn8Z LCKcI8AVl3/OxyIdbd62N1ccCwReWGcUf+hlrlbh4baTUc3pEnm1Jpj32Hx2gWOGMR9H obHfn7A7uakdjyROG+pvq/VgSbj7dz1LAPe6NIHL6djKhMaLcduXHQp0597g6b0czXe4 so8A== X-Gm-Message-State: AOAM530YeNYRvuYxevu9ps4I4wI9AW7Veu0m4YOE9npnI7Y2QM1ql9xR 4+CsfFMWfZuoZ27bQAzfaw== X-Received: by 2002:a17:90a:1fca:: with SMTP id z10mr9642021pjz.209.1596739807113; Thu, 06 Aug 2020 11:50:07 -0700 (PDT) Received: from ip-172-31-41-194.ap-northeast-1.compute.internal (ec2-52-199-21-241.ap-northeast-1.compute.amazonaws.com. [52.199.21.241]) by smtp.gmail.com with ESMTPSA id u24sm9096730pfm.20.2020.08.06.11.50.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Aug 2020 11:50:06 -0700 (PDT) From: nao.horiguchi@gmail.com To: linux-mm@kvack.org Cc: mhocko@kernel.org, akpm@linux-foundation.org, mike.kravetz@oracle.com, osalvador@suse.de, tony.luck@intel.com, david@redhat.com, aneesh.kumar@linux.vnet.ibm.com, zeil@yandex-team.ru, cai@lca.pw, naoya.horiguchi@nec.com, linux-kernel@vger.kernel.org Subject: [PATCH v6 12/12] mm,hwpoison: double-check page count in __get_any_page() Date: Thu, 6 Aug 2020 18:49:23 +0000 Message-Id: <20200806184923.7007-13-nao.horiguchi@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200806184923.7007-1-nao.horiguchi@gmail.com> References: <20200806184923.7007-1-nao.horiguchi@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Naoya Horiguchi Soft offlining could fail with EIO due to the race condition with hugepage migration. This issuse became visible due to the change by previous patch that makes soft offline handler take page refcount by its own. We have no way to directly pin zero refcount page, and the page considered as a zero refcount page could be allocated just after the first check. This patch adds the second check to find the race and gives us chance to handle it more reliably. Reported-by: Qian Cai Signed-off-by: Naoya Horiguchi --- mm/memory-failure.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git v5.8-rc7-mmotm-2020-07-27-18-18/mm/memory-failure.c v5.8-rc7-mmotm-2020-07-27-18-18_patched/mm/memory-failure.c index bed4b6aac9a0..e6f6559d573e 100644 --- v5.8-rc7-mmotm-2020-07-27-18-18/mm/memory-failure.c +++ v5.8-rc7-mmotm-2020-07-27-18-18_patched/mm/memory-failure.c @@ -1700,6 +1700,9 @@ static int __get_any_page(struct page *p, unsigned long pfn, int flags) } else if (is_free_buddy_page(p)) { pr_info("%s: %#lx free buddy page\n", __func__, pfn); ret = 0; + } else if (page_count(p)) { + /* raced with allocation */ + ret = -EBUSY; } else { pr_info("%s: %#lx: unknown zero refcount page type %lx\n", __func__, pfn, p->flags); @@ -1716,6 +1719,9 @@ static int get_any_page(struct page *page, unsigned long pfn, int flags) { int ret = __get_any_page(page, pfn, flags); + if (ret == -EBUSY) + ret = __get_any_page(page, pfn, flags); + if (ret == 1 && !PageHuge(page) && !PageLRU(page) && !__PageMovable(page)) { /* -- 2.17.1