From patchwork Mon Mar 22 17:51:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12155733 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18709C433C1 for ; Mon, 22 Mar 2021 17:51:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B6FF76196E for ; Mon, 22 Mar 2021 17:51:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B6FF76196E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 271F86B00AA; Mon, 22 Mar 2021 13:51:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 221C56B00AD; Mon, 22 Mar 2021 13:51:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 09BF46B00AF; Mon, 22 Mar 2021 13:51:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0195.hostedemail.com [216.40.44.195]) by kanga.kvack.org (Postfix) with ESMTP id DDCAF6B00AA for ; Mon, 22 Mar 2021 13:51:50 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 42F2118045D09 for ; Mon, 22 Mar 2021 17:51:50 +0000 (UTC) X-FDA: 77948253180.23.688889A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf05.hostedemail.com (Postfix) with ESMTP id 8A5BCE037DBA for ; Mon, 22 Mar 2021 17:51:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616435497; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=3sv2VL5jzl43MssQXHzJqdRATLzbsdNryCBU0FqXXE4=; b=H8aEliN1Ag5o88/nVcRexLvMdpBHA8Wlyh1AC60qdndBQHzeMmcA/3tD0QtKu93Z7BBQEB q94Wsz8ZXjD1cV1p6JuoQjRJ+lxFXLbTf4ZhpFPYHj5WeqTWO/aNv8/7GqbONwZj4OmIlS QlATvbAtz/6CYAEi28pmgrBfv+9Nf9A= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-396-uySfDTxNNcCSCfmuhBcbJQ-1; Mon, 22 Mar 2021 13:51:36 -0400 X-MC-Unique: uySfDTxNNcCSCfmuhBcbJQ-1 Received: by mail-qv1-f72.google.com with SMTP id iy2so37510642qvb.22 for ; Mon, 22 Mar 2021 10:51:36 -0700 (PDT) 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:mime-version :content-transfer-encoding; bh=3sv2VL5jzl43MssQXHzJqdRATLzbsdNryCBU0FqXXE4=; b=Wgbd5JaIp/1x/3qkNk71q4ySeQ3GiG3XBJwxSmWuV/GxX2kTlacJXElhSIfE0tj45N WaeYudP5+F4MGYMbuSDzI2HZXGso7NVDrvH8Ywt0SybrBuCV7AIO+e3xS0gq70nzoXop YYYTXY3+G7fiuKK6cztpQp2FhmaFye7/4KzI+dMTZpkw6w2AxM0YYRnna5eiYNETF2zK EOO+5PvChxUbOGYD6AHDnXLkr/MtXprC9RPXm6TfzLM83zYBD1PtN7lSPFx9RnF6FMNv GfYDT4278PAd6T4FC5USEklBSFw7IZ0LtE7XiZIbZnH+aNs6K3BC58GkepnqKE0ZbFLG WGGQ== X-Gm-Message-State: AOAM533iBP7UEYRiyE0kD91rIaYHLJXNtpSdq+Gm3Yov7539i+pCd6io 4uJe5f4j30nUtE6YhSyv2MRMcwz88UsT8Id+/8uxkQ+2m9azN19okX7rRlWwsDfroSqNfLlkhCH hd7ktB3yIoTysxws7AvBIPBCEp5rQC2uM4Yb22fXL/zSDOB+qW3yimvYunFHT X-Received: by 2002:a05:620a:1292:: with SMTP id w18mr1184707qki.400.1616435495486; Mon, 22 Mar 2021 10:51:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwuB+/kei1bAz1c4Jk2mymH+0CIIyij9CrmBXu26SxRX4WsPXOOt7e4pDsLHAq0e7+JMC9sPw== X-Received: by 2002:a05:620a:1292:: with SMTP id w18mr1184675qki.400.1616435495103; Mon, 22 Mar 2021 10:51:35 -0700 (PDT) Received: from xz-x1.redhat.com (bras-base-toroon474qw-grc-82-174-91-135-175.dsl.bell.ca. [174.91.135.175]) by smtp.gmail.com with ESMTPSA id e14sm11272584qka.56.2021.03.22.10.51.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 10:51:34 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Andrew Morton , peterx@redhat.com, Axel Rasmussen , Andrea Arcangeli , Mike Kravetz , Mike Rapoport Subject: [PATCH] userfaultfd/hugetlbfs: Fix minor fault page leak Date: Mon, 22 Mar 2021 13:51:32 -0400 Message-Id: <20210322175132.36659-1-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 8A5BCE037DBA X-Stat-Signature: qby5m5j795mac16zdcbwux8huyxwmqzd Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf05; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=63.128.21.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1616435498-55746 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: When uffd-minor enabled, we need to put the page cache before handling the userfault in hugetlb_no_page(), otherwise the page refcount got leaked. This can be reproduced by running userfaultfd selftest with hugetlb_shared mode, then cat /proc/meminfo. Cc: Axel Rasmussen Cc: Andrea Arcangeli Cc: Mike Kravetz Cc: Mike Rapoport Cc: Andrew Morton Fixes: f2bf15fb0969 ("userfaultfd: add minor fault registration mode") Signed-off-by: Peter Xu Reviewed-by: Mike Kravetz Reviewed-by: Axel Rasmussen --- mm/hugetlb.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 408dbc08298a..56b78a206913 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4449,6 +4449,7 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm, /* Check for page in userfault range. */ if (userfaultfd_minor(vma)) { unlock_page(page); + put_page(page); ret = hugetlb_handle_userfault(vma, mapping, idx, flags, haddr, VM_UFFD_MINOR);