Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp3687943ybh; Tue, 17 Mar 2020 04:51:27 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtacOWNcO9ym0u1VuZsn83DvsWUmcrWp4sp1MaxS6nhDajUU4N3rP3GkEayRxapNjRllrBx X-Received: by 2002:a9d:5381:: with SMTP id w1mr3396026otg.220.1584445887269; Tue, 17 Mar 2020 04:51:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584445887; cv=none; d=google.com; s=arc-20160816; b=jdE4HyG7BZQbB97DppygdcvyYGvPB2Or9ZhEozjIOTMSnSJ9kNjJxHpgRwPbVBtg9l TXMlPCJlvv2NgAvOvh8kUCt04bJ3hx4DHFzal7H2FftoU1pulYrtXh+J+gYs/l/SrFBz vxrNgG0AnLi2xguQWL01l8vjSIFX2qB9IR/4ITHjaf6dCULDkZ9PXii9v9d8viNQvJid 2G8+eTXbjhNfPXgHDmKDOek0Y1Nz5N97tA+qJaLfA2bT0PS/Eo+FdVCQhtoEZuuBulM3 hVk//3rz2KA0xm4a6r3/1ik70vwodzXg3Jdnhpe29f/GqWw0zBkJUnBRZfcBetJqYsjk LcyQ== 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=MMK1oa7caM4FxenuRyA9kQAaY+A0jvSFKtsdxSSnm50=; b=sf9N3TUqrr51BlCev1NezCzdRmbqXTlQ3WcIPtFYCnjGZumvFC0tK0PKjOyMAuMqZa bfzpl1iiK7C2ioQx3f1XN1ROOFFkbUFRf24cHCv/UPhEjB2vG5esA+KnW9qtB9OwcpvE oela4af6VMjOMJPhbKdpDt4ZZEkn4fcuzUedX9HtuwhHrOsu+E7qmtSlVU6PkU/U06Iq DezZCrCb/f4TPi3PwhQTeJm9/RenKGZBZrOVQXA/hKdoj1BQXONCooLYhQDgYs0Bf2U4 SN4l5r/tWIaQxpTJw2JG8JTxIstVmA/9G9exVoKmQijn2h6xAddSgL/w0qll+jH8f2++ pnpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=eWdg7Fuu; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s1si1612825oij.237.2020.03.17.04.51.14; Tue, 17 Mar 2020 04:51:27 -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=@gmail.com header.s=20161025 header.b=eWdg7Fuu; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726683AbgCQLtt (ORCPT + 99 others); Tue, 17 Mar 2020 07:49:49 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:43920 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725794AbgCQLts (ORCPT ); Tue, 17 Mar 2020 07:49:48 -0400 Received: by mail-pf1-f193.google.com with SMTP id f206so810675pfa.10 for ; Tue, 17 Mar 2020 04:49:48 -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=MMK1oa7caM4FxenuRyA9kQAaY+A0jvSFKtsdxSSnm50=; b=eWdg7FuuLGf/HHPeZutN/DYRjxENPqg+VeIJz4NbSKSfjLv6CdrPv1RzaD/qLOir2Q o+m1Vv+PqzjYMbFY9kaagOU+qtTyfg4RlKmjpWxxLEPRKSntm60Tq+pfugBkVK2eEDys mtrpofcDQ4D2Liywttc4FNG5G4izeWiVb8XhS5nyi1kdMOk+e1jPYs2EsMRyDt6E+gYd rsj0ADZq9uqh5L0OQf4YtYG2gg/gxwRktAOLGWNGKhSHWs2XEb/noOsL+84foC2leXf9 PVLStKZBVq3AdMHy3m6wjUUirFfwqhGtT1BICQOcF9oCrYFb4ncRIXiLzy6UbWZ9jZib CCTA== 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=MMK1oa7caM4FxenuRyA9kQAaY+A0jvSFKtsdxSSnm50=; b=UXMaXI8yqWnxxK2QM6WpWj1xJXdYtcXVvzsqGP0uSVzNKqnvKM9R/nQcYLm+qJFwI5 5MrstPMJ7Xpe2TsTaOLSCMGj3yoFZRlGYDiYVH2X+0LXyoyx+MQc1zS9oh0HBxuEhEfR t7WNOQsvTDtdCdKY6U7Qe/w3OpD7PbATdqx2Cs7VnumHvulUiebETYnQrRYbNKQiXsJI hmm4lx5kA7LY3LktEhTAjPaZBNpG9qxhbECMX+5D0eATTYTNdqodKNRpuvZUfeYhQUet abXdpyK00oUBZ0+P9zRpO9VjYpskRTnqcEZxYGiMrAvOpndV17naKPzX4M4pT2tZVgTc yahA== X-Gm-Message-State: ANhLgQ3xOksSaLs1mel99+R21lxdf81KVBTiIuRIi6j++XwPJFBxWS24 LIG6JBj672BOydTYVKR2Bw== X-Received: by 2002:a62:3854:: with SMTP id f81mr4823792pfa.81.1584445787852; Tue, 17 Mar 2020 04:49:47 -0700 (PDT) Received: from mylaptop.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id c62sm2214845pfc.136.2020.03.17.04.49.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Mar 2020 04:49:47 -0700 (PDT) From: Pingfan Liu To: linux-mm@kvack.org Cc: Pingfan Liu , Ira Weiny , Andrew Morton , Mike Rapoport , Dan Williams , Matthew Wilcox , John Hubbard , "Aneesh Kumar K.V" , Christoph Hellwig , Shuah Khan , Jason Gunthorpe , linux-kernel@vger.kernel.org Subject: [PATCHv7 2/3] mm/gup: fix omission of check on FOLL_LONGTERM in gup fast path Date: Tue, 17 Mar 2020 19:47:32 +0800 Message-Id: <1584445652-30064-1-git-send-email-kernelfans@gmail.com> X-Mailer: git-send-email 2.7.5 In-Reply-To: <1584333244-10480-3-git-send-email-kernelfans@gmail.com> References: <1584333244-10480-3-git-send-email-kernelfans@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org FOLL_LONGTERM is a special case of FOLL_PIN. It suggests a pin which is going to be given to hardware and can't move. It would truncate CMA permanently and should be excluded. In gup slow path, slow path, where __gup_longterm_locked->check_and_migrate_cma_pages() handles FOLL_LONGTERM, but in fast path, there lacks such a check, which means a possible leak of CMA page to longterm pinned. Place a check in try_grab_compound_head() in the fast path to fix the leak, and if FOLL_LONGTERM happens on CMA, it will fall back to slow path to migrate the page. Some note about the check: Huge page's subpages have the same migrate type due to either allocation from a free_list[] or alloc_contig_range() with param MIGRATE_MOVABLE. So it is enough to check on a single subpage by is_migrate_cma_page(subpage) Signed-off-by: Pingfan Liu Cc: Ira Weiny Cc: Andrew Morton Cc: Mike Rapoport Cc: Dan Williams Cc: Matthew Wilcox Cc: John Hubbard Cc: "Aneesh Kumar K.V" Cc: Christoph Hellwig Cc: Shuah Khan Cc: Jason Gunthorpe To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org --- v6 -> v7: fix coding style issue mm/gup.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mm/gup.c b/mm/gup.c index 9df77b1..0a536d7 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -89,6 +89,15 @@ static __maybe_unused struct page *try_grab_compound_head(struct page *page, int orig_refs = refs; /* + * Huge page's subpages have the same migrate type due to either + * allocation from a free_list[] or alloc_contig_range() with + * param MIGRATE_MOVABLE. So it is enough to check on a subpage. + */ + if (unlikely(flags & FOLL_LONGTERM) && + is_migrate_cma_page(page)) + return NULL; + + /* * When pinning a compound page of order > 1 (which is what * hpage_pincount_available() checks for), use an exact count to * track it, via hpage_pincount_add/_sub(). -- 2.7.5