Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5817111ybi; Tue, 28 May 2019 20:58:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqxHE7nE4VEKG0vVF9cwFANoeeQi9Xf/Oqy4PFPrNC/nB/Rg721F+A626aSkwB/ce4tfCg2V X-Received: by 2002:a63:3008:: with SMTP id w8mr12766765pgw.11.1559102301811; Tue, 28 May 2019 20:58:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559102301; cv=none; d=google.com; s=arc-20160816; b=ZIsfxlT16b8GNmYMszUa6AAmzXoYzNDIJJ0+kCk1GMooLPUxWHDGDmEOEkNkKXW3qz JXn9s1T3lMeYzCOXeI560wN5f2sjUJJ0HzbTaqJIkgvboQYVIInSOrn8zFRTVIsD4bAZ Gsy7nBr7GQp9TFhqrdjWUCtNL2sNla5eNmnK1L9pEFmuRnr+aLqqbemufdvUzxKoJcii ekOQ/UPy8+EJuvXPY8oS3+dY/LNilHgSlmWvLY32ZMHlz9Dzv6Itu1g2ge60YLIR4P3N ZFLWxGK+RujkPvbt76HuegYZnOC9AwkiJZvP1RDox5q6R7cJ0Vpf4L1btUYXDOVLNrp7 pHJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=KNtOxn49uj/4mQWINXWt7gvrmDenpcIgdufmBaNgqXQ=; b=TQI/834ugl/cfG7ZiuYWBhF5HEwHR/jvQhewFPNszFc3wfkXEYI349P+l3e8sEb9Sj lLGMq6SZ5jjDzriKrJjmErfgfeidns+eGb5jC7ik7xQv6CMAUDxhbtcCG3iclU8vTaBE QCJreXjHFrkURmN+F73gmx5t3D3tqKSQ7Zs5triOyzs3XFiGZ8iZoi63iRFAL9tGXAC0 k7fRMdcCyXnNFDwV5z4WUrXPsqnZRTcGwsI/mhOQ/TPDtaft5Rmm+/2cCGeOTIvZAAN3 RRKLG/N1hmZ2JBE48jEwcFPYtvvUrv00bIyLXcd3cicy7A8TOWx+cDKnUpzF2u07Kggs v47Q== 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 k5si25015252pfi.16.2019.05.28.20.58.06; Tue, 28 May 2019 20:58:21 -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; 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 S1726541AbfE2DzT (ORCPT + 99 others); Tue, 28 May 2019 23:55:19 -0400 Received: from mga02.intel.com ([134.134.136.20]:44796 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725832AbfE2DzT (ORCPT ); Tue, 28 May 2019 23:55:19 -0400 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 May 2019 20:55:18 -0700 X-ExtLoop1: 1 Received: from iweiny-desk2.sc.intel.com ([10.3.52.157]) by FMSMGA003.fm.intel.com with ESMTP; 28 May 2019 20:55:18 -0700 Date: Tue, 28 May 2019 20:56:19 -0700 From: Ira Weiny To: Michal Hocko Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, John Hubbard , =?iso-8859-1?B?Suly9G1l?= Glisse , Dan Williams Subject: Re: [PATCH v2] mm/swap: Fix release_pages() when releasing devmap pages Message-ID: <20190529035618.GA21745@iweiny-DESK2.sc.intel.com> References: <20190524173656.8339-1-ira.weiny@intel.com> <20190527150107.GG1658@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190527150107.GG1658@dhcp22.suse.cz> User-Agent: Mutt/1.11.1 (2018-12-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 27, 2019 at 05:01:07PM +0200, Michal Hocko wrote: > On Fri 24-05-19 10:36:56, ira.weiny@intel.com wrote: > > From: Ira Weiny > > > > Device pages can be more than type MEMORY_DEVICE_PUBLIC. > > > > Handle all device pages within release_pages() > > > > This was found via code inspection while determining if release_pages() > > and the new put_user_pages() could be interchangeable. > > Please expand more about who is such a user and why does it use > release_pages rather than put_*page API. Sorry for not being more clear. The error was discovered while discussing a proposal to change a use of release_pages() to put_user_pages()[1] [1] https://lore.kernel.org/lkml/20190523172852.GA27175@iweiny-DESK2.sc.intel.com/ In that thread John was saying that release_pages() was functionally equivalent to a loop around put_page(). He also suggested implementing put_user_pages() by using release_pages(). On the surface they did not seem the same to me so I did a deep dive to make sure they were and found this error. > > The above changelog doesn't > really help understanding what is the actual problem. I also do not > understand the fix and a failure mode from release_pages is just scary. This is not failing release_pages(). The fix is that not all devmap pages are "public" type. So previous to this change devmap pages of other types would not correctly be accounted for. The discussion about put_devmap_managed_page() "failing" is not about it failing directly but rather in how these pages should be accounted for. Only devmap pages which require pagemap ops (specifically page_free()) require put_devmap_managed_page() processing. Because of the optimized locking in release_pages() the zone device check is required to release the lock even if put_devmap_managed_page() does not handle the put. > It is basically impossible to handle the error case. So what is going on > here? I think what has happened is the code in release_pages() and put_page() diverged at some point. I think it is worth a clean up in this area but I don't see way to do it at the moment which would be any cleaner than what is there. So I've refrained from doing so. Does this help? Would you like to roll a V3 with some of this in the commit message? Ira > > > > > > Cc: J?r?me Glisse > > Cc: Michal Hocko > > Reviewed-by: Dan Williams > > Reviewed-by: John Hubbard > > Signed-off-by: Ira Weiny > > > > --- > > Changes from V1: > > Add comment clarifying that put_devmap_managed_page() can still > > fail. > > Add Reviewed-by tags. > > > > mm/swap.c | 11 +++++++---- > > 1 file changed, 7 insertions(+), 4 deletions(-) > > > > diff --git a/mm/swap.c b/mm/swap.c > > index 9d0432baddb0..f03b7b4bfb4f 100644 > > --- a/mm/swap.c > > +++ b/mm/swap.c > > @@ -740,15 +740,18 @@ 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 can still fail here and will > > + * therefore need put_page_testzero() > > + */ > > + if (put_devmap_managed_page(page)) > > + continue; > > } > > > > page = compound_head(page); > > -- > > 2.20.1 > > > > -- > Michal Hocko > SUSE Labs