Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp2197151ybh; Sun, 15 Mar 2020 21:37:51 -0700 (PDT) X-Google-Smtp-Source: ADFU+vt60oFTnFBitvfbd3PRKXtWwggakx6S/yN0MgsyLYXgcS7BgL7zmFbei92jw+GzbN3hIkYb X-Received: by 2002:a54:4396:: with SMTP id u22mr16241666oiv.128.1584333471063; Sun, 15 Mar 2020 21:37:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584333471; cv=none; d=google.com; s=arc-20160816; b=1HFADGGc+ijttThe2Xws91CHeiYqDLUrWXbU1beznmWl+xrwgNDjoyuGYAAch+qNdR Z5QAryquTA9FD9Nv+LZ5e4jlBW4EyhBllAlYLO2C+U1N9PxumDwGuQinYRtf2iGadkCD yAsIMKiI9Pv2eMxRS/pLFjLUq7doOwswbxb2TUlv/cs19fEk0MeYybAs72vlqS1+O4Xw SGoML8EhHjz2BEn2s+rNFJ6g/e0VywfTdc9wDbmHPJgClvxS/cWYplIMHbjzOATo50CY zOIyvtlLVSCe8GQ8wPiy33PLP+uckp5oEcJn01pYH0QHdQU0N2KnOs6GlzA+zQ3UNuaC 4l1w== 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=fsI1XEPfE/anfkLEVKGW8+YR1eBwmOuLro1LuQ5D+DY=; b=c+wsjIBnrRs3NOu24vVUti/TMJVZfIZ2yMUk0KwIR07n4dNGP+Rpu9Vs/vSFy6lrDW vULlGI8e/5guF8EMizj94SxxNItmMvJB94PAd1+T1piaFm7zajlzewNS6v4fOII8BgYy Lv103dNqSF7WnkNFtY7q8r5QaS8GhXNqbGKScof0vHSKkNBR42BaeP0xFDpaq3YA+rsD C0WOxC197sWbijI635oXFu5giUGcnE68QENk7wWoKl66qOhiU36Db9U6FjZRqTqYLq8b PSOQN/jPfDh1QCpI0AdQ/Hwrrn5jPXSHHSk7DpjvKz3zZoHJyTy7AKtmyUL3TfENUc3W 3i9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lY78JmHv; 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 e7si9212248otp.110.2020.03.15.21.37.37; Sun, 15 Mar 2020 21:37:51 -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=lY78JmHv; 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 S1729655AbgCPEgh (ORCPT + 99 others); Mon, 16 Mar 2020 00:36:37 -0400 Received: from mail-pj1-f66.google.com ([209.85.216.66]:32777 "EHLO mail-pj1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729423AbgCPEgh (ORCPT ); Mon, 16 Mar 2020 00:36:37 -0400 Received: by mail-pj1-f66.google.com with SMTP id dw20so3577090pjb.0 for ; Sun, 15 Mar 2020 21:36:36 -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=fsI1XEPfE/anfkLEVKGW8+YR1eBwmOuLro1LuQ5D+DY=; b=lY78JmHvz9cs070waBtw18dVt/JAt1JesCwcF86+QyxzR24E+YBrxUXkR/AK2qLJvP Gly4wGAIMmEX/DPr0ss4mghlm9pEQY8aQ7XLR3FpBNBXTvMk9LEh82wdwpP60IezSkiQ ozO2Z3LJzup6BX1xKCI70IFlsuQvq9xPgppJT6iSjQ0nAiFiVSwYzYTJBw/9gZvxLu/a C4HKd3s/riXihuFhxygEj2EIvgheh8XnlIVEDpDp3AbucwuOkJAJGfrPft0hUdqcHWHc nT07koP4VVT3QRn85cIOLvVQiAyUkrF4rb2LNMeTXeksIQSA4N8AqXkbD0wRXseQWYXn kddw== 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=fsI1XEPfE/anfkLEVKGW8+YR1eBwmOuLro1LuQ5D+DY=; b=i9lSaKdURhYpfCTDMA67TzBf8HOn5EWO1yr82qORcoLFUSvZc8tg6afxbtUCJD6Zef 8YwaW2x3pA2BCAHvsBTUNxwaXla1eHoBzaF/L+4Y9dQFFXIHkCaFcr+/aD6hD63RnEtL dAzXOAxsGgvkmpz2ILCgMTwwY8UxXW74DeKA4auYG7mgfPo97B3wDmtUBLXaOnuUq6XN v3xJDhs3ysybMb2tY2ea5HINbYB1hhQQI8FTThCWBw/LUUHNdzEJ7BBEYaZ9kuzBqjxM /zaAtxBfeOLBfNlTVcEWuzQSQleW1VpfA9qqYhhV/jNF5i4SHB6J0m+qB5/Ks1VtdFCx Zp9A== X-Gm-Message-State: ANhLgQ2u9JR9rjS9dXv7Da76fIFlbp7Vzul4fg1lrH8q7lQNGu3zbjoY 0KRR5c6ChsD6OZcmMchJYA== X-Received: by 2002:a17:90a:2:: with SMTP id 2mr23785492pja.16.1584333396201; Sun, 15 Mar 2020 21:36:36 -0700 (PDT) Received: from mylaptop.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id d6sm18544296pjz.39.2020.03.15.21.36.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Mar 2020 21:36:35 -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: [PATCHv6 2/3] mm/gup: fix omission of check on FOLL_LONGTERM in gup fast path Date: Mon, 16 Mar 2020 12:34:03 +0800 Message-Id: <1584333244-10480-3-git-send-email-kernelfans@gmail.com> X-Mailer: git-send-email 2.7.5 In-Reply-To: <1584333244-10480-1-git-send-email-kernelfans@gmail.com> References: <1584333244-10480-1-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 --- mm/gup.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mm/gup.c b/mm/gup.c index 9df77b1..78132cf 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