Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2651797ybb; Sun, 22 Mar 2020 04:36:47 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvLdaUYg5OZOmKqUt7wi/0RoZdoJwe6uJM5T8q27/PA+Z7nU6W39w/CIHPqX63xo78UP0yu X-Received: by 2002:a9d:719a:: with SMTP id o26mr14563710otj.290.1584877007860; Sun, 22 Mar 2020 04:36:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584877007; cv=none; d=google.com; s=arc-20160816; b=OJM5yGpE3BHRDuH55OByWowBolqS8TtfVwbImvKeAMqURDGnS0S03EVG2Zj4MNBKTs X5CD7WFk/aDTnF6xV13GpGlMYwoM9fRzDE+JO1oMdC0InGMIp6VAjIKVix0KFHJD5uWv zqzzqIvGpWLem6AGPvCgAjSFxbtnByn+HyWoMl6uyOGaFZBexKz/jtaA/JpQfTCpu8RZ Wz4P6bV4MCrVmrxfAmLuzURCF+0AKNhXeLUk/s6P95jH26U5YBUBgIvhJuuG2PQx9IOy U9tGmgI844Nrys2Jv/i4Kka/kwNi9gz8xg5fNJcmEpR0Y4jbWblzpwTbjroVRRbgwWcI nGLQ== 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=/1SM3867y5SxnAk5W+nCWfh5uFmnZCup8fknvMevl8I=; b=So6seIjWcwoTtnpnp5BhgtdKbYqcOHss4pGeq/Q3RRc9e294mgpFCaKG44rPfcGWFM z/Jy+xdH9L8aEj0FBd8qRZBC3lf7LccrWAYpF/PXCmCk6uSYIOnlAGMGT2qTxgBcpvLO BP0+Bzh13uJH0LnNJ6fyJ/nUVOV5RIwaTms4ZhGR3lNGJ849rRnmsc9QOjVC0jdkaXiC PuQ6nzCgLOC4Cfuqq3prTBWisSZLToWQf+uifFNq5x6XDlpBdG7o7KBgrBsJIiXaUehv SYg81Y9tw1UmsBmD5kcj9F7jjjbYjNW09EZcWXL2rqUVFn/hKeVWDkVIh+uwyVxJM2kv xgkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="ZCgbAm/i"; 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 x66si5805836ota.244.2020.03.22.04.36.36; Sun, 22 Mar 2020 04:36:47 -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="ZCgbAm/i"; 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 S1727032AbgCVLer (ORCPT + 99 others); Sun, 22 Mar 2020 07:34:47 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:43656 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726896AbgCVLer (ORCPT ); Sun, 22 Mar 2020 07:34:47 -0400 Received: by mail-pg1-f196.google.com with SMTP id u12so5632932pgb.10 for ; Sun, 22 Mar 2020 04:34:46 -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=/1SM3867y5SxnAk5W+nCWfh5uFmnZCup8fknvMevl8I=; b=ZCgbAm/iPixhzfGPOch7scTLnnbNH0Ce/QnnMs3JENoqXF8vBILnIV1dIn7EILxnTk /WOGRkxPYmqz+eb7gUU0jx0g3JN8FGy49bJdoGQBqCSMcXdfjO3i04D/V9LGkeJCqUZo HR4ISjeBbOCKuX9PYVLMInFsw7kMt4iiHEy/MMyi5n3uOlYSsTlnEhnhkI2p6iyLpeD1 k6zkgSjySq8VK3DAd2P7+Q+HwhzrhwqE1eDX1Unf32kwsA++x/a9IizdDHpyMBje1kc1 cv5Xhub/coe6nHFJOa7R2yacoJlYTd3Ac/BbvT7UZbPZ/FSPEUEZv3nxM0ZffXwy6APt UeSA== 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=/1SM3867y5SxnAk5W+nCWfh5uFmnZCup8fknvMevl8I=; b=SfSaxhk5OBheCFb/UundaeCgK/2zm2icJZjjaPxglT5pTk26cVM224aZSo7AI4nLfm swKWSC5nOZfV5EZMLRFwIX9VInPSzcJd+hVvvZtpWExsVkuDlcknYNJX5hi+Yi6XPOhD HDthV8SEO3Zsrp7y5+HEcGvRljus7qq3Th4JudNvuPHtWIVRrCXOiM2Uu3+jTa4n/tnv C+j30dtFnTRK15C+BhKBLOorbaze/xRCkuQdJOZY0Nhi3Knt6sjmoO9mHhuqr4LFYeNW 3FV3xcGKr+c4DH/x8LovyVzIoksSgoCGWDi2NFK23gzSP6smNwkaIv5ZokndK0vKGvlw qhtg== X-Gm-Message-State: ANhLgQ2wHcdAMhLgpARzv91OleJYhQPAEFhJopUjB6fVg0rDG0jiSmAV YUpL2VSnpXqN+W+FngEWjw== X-Received: by 2002:aa7:8bda:: with SMTP id s26mr18467747pfd.142.1584876886209; Sun, 22 Mar 2020 04:34:46 -0700 (PDT) Received: from mylaptop.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id i23sm10474445pfq.157.2020.03.22.04.34.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 22 Mar 2020 04:34:45 -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: [PATCHv8 2/2] mm/gup: fix omission of check on FOLL_LONGTERM in gup fast path Date: Sun, 22 Mar 2020 19:32:13 +0800 Message-Id: <1584876733-17405-3-git-send-email-kernelfans@gmail.com> X-Mailer: git-send-email 2.7.5 In-Reply-To: <1584876733-17405-1-git-send-email-kernelfans@gmail.com> References: <1584876733-17405-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, 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 Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe 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 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mm/gup.c b/mm/gup.c index 02a95b1..3fe75c4 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -89,6 +89,14 @@ static __maybe_unused struct page *try_grab_compound_head(struct page *page, int orig_refs = refs; /* + * Can't do FOLL_LONGTERM + FOLL_PIN with CMA in the gup fast + * path, so fail and let the caller fall back to the slow path. + */ + 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