Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3132216ybi; Thu, 18 Jul 2019 21:39:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqwkyvXPk4RAodP7egwSML/MHG5VMocBXMGA8VRH468j8Qvl3PtK/+XEwOXzoXA9bhuXWICy X-Received: by 2002:a17:90a:1aa4:: with SMTP id p33mr56118620pjp.27.1563511174831; Thu, 18 Jul 2019 21:39:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563511174; cv=none; d=google.com; s=arc-20160816; b=bLRsNnYVfz0xN8SqxLtKHcQzxdH3mUYITYOzXaS1840KqjyqLXHqf4SC/Yo7YZ/BwT HZV4L7/f91ebUpbgwAN8S3Vs97pA5MTFs3tXYMyNMSnD7uIq1jhzGxZisT5Z+au5ST0Z 0FvXc0FK8JmYDzDD1dERr6XtIlW6pOpex/cQRkt6/vrx5GlZ3AyNWggXXgB4DStmZSmx EIxhFtE3YkLiHG/eBm1I+qLM5E2qhVyIPlc7gbxdTouypaM+5pEPpCYudBjYD4x4fzg7 YfqfctjHRRqK+764khu949e//kkb6yHUm8rob+/G4KeO7VPpc7mwEYkLh59YynW1dHN7 VsMQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YvEHPnn/zpRhRupCuXxSJl3Y6LuNCXnr5gToKfaOAT8=; b=MQLHhMRUMuCAZ3TWxd16/XWsDVgAkNdy42peLaUJck94RL7mdDAP19aGibMoCj5r9Y 6qeI4nHLkO0YRvoi1lK/Yl9Iprz9Ak6yPnE/6+057DVb0AIlFw9NTOcTTb0f2g5FWLaX iFbcR3y2jal3pJx+27A9BpRX/oD9ZYVM+jJTlgNsehrBH32xmr6Nh53MsseE1XEHIWxZ 3w+PFrpDcn3mhdpVSib7spVXrhl1lgMKD3ukW8LvMbQxdQLgHy5pb51PMt7+cZ40LyDj aG9PqI3JsrDJdZrDkyCE9CdRmMiVX3XP3qglqGcaD/jxQgVRdd6IKntjQwXX+pbq6gqM VJoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wXKrDihp; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p4si281916pgh.350.2019.07.18.21.39.18; Thu, 18 Jul 2019 21:39:34 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=wXKrDihp; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726882AbfGSEAR (ORCPT + 99 others); Fri, 19 Jul 2019 00:00:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:60022 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727243AbfGSEAJ (ORCPT ); Fri, 19 Jul 2019 00:00:09 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 65DD821852; Fri, 19 Jul 2019 04:00:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563508809; bh=NGAEa7nxCla6yeOxFjos63IrCBcidctWmzU3WpluPhM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wXKrDihp/S1cVan7L4zfjmAgAIzXlz6fMWnxvGRTLBM8R1Dk3lWkTAvYLkcXDUbvS llI5C0scOH1cTUGYr8VC+JvcJHNLtbVmDeq/2JOUHnx/UwhuPELJgHtDPXdKpzRPpa 9cFOvOfWe+SrDKyVuEwpMHFmr7ukTzxcgb2ssKjs= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ira Weiny , =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , Michal Hocko , Dan Williams , John Hubbard , Jason Gunthorpe , Sasha Levin , linux-mm@kvack.org Subject: [PATCH AUTOSEL 5.2 102/171] mm/swap: fix release_pages() when releasing devmap pages Date: Thu, 18 Jul 2019 23:55:33 -0400 Message-Id: <20190719035643.14300-102-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190719035643.14300-1-sashal@kernel.org> References: <20190719035643.14300-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ira Weiny [ Upstream commit c5d6c45e90c49150670346967971e14576afd7f1 ] release_pages() is an optimized version of a loop around put_page(). Unfortunately for devmap pages the logic is not entirely correct in release_pages(). This is because device pages can be more than type MEMORY_DEVICE_PUBLIC. There are in fact 4 types, private, public, FS DAX, and PCI P2PDMA. Some of these have specific needs to "put" the page while others do not. This logic to handle any special needs is contained in put_devmap_managed_page(). Therefore all devmap pages should be processed by this function where we can contain the correct logic for a page put. Handle all device type pages within release_pages() by calling put_devmap_managed_page() on all devmap pages. If put_devmap_managed_page() returns true the page has been put and we continue with the next page. A false return of put_devmap_managed_page() means the page did not require special processing and should fall to "normal" processing. This was found via code inspection while determining if release_pages() and the new put_user_pages() could be interchangeable.[1] [1] https://lkml.kernel.org/r/20190523172852.GA27175@iweiny-DESK2.sc.intel.com Link: https://lkml.kernel.org/r/20190605214922.17684-1-ira.weiny@intel.com Cc: Jérôme Glisse Cc: Michal Hocko Reviewed-by: Dan Williams Reviewed-by: John Hubbard Signed-off-by: Ira Weiny Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- mm/swap.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mm/swap.c b/mm/swap.c index 7ede3eddc12a..607c48229a1d 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -740,15 +740,20 @@ void release_pages(struct page **pages, int nr) if (is_huge_zero_page(page)) continue; - /* Device public page can not be huge page */ - if (is_device_public_page(page)) { + if (is_zone_device_page(page)) { if (locked_pgdat) { spin_unlock_irqrestore(&locked_pgdat->lru_lock, flags); locked_pgdat = NULL; } - put_devmap_managed_page(page); - continue; + /* + * ZONE_DEVICE pages that return 'false' from + * put_devmap_managed_page() do not require special + * processing, and instead, expect a call to + * put_page_testzero(). + */ + if (put_devmap_managed_page(page)) + continue; } page = compound_head(page); -- 2.20.1