Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3938283imm; Mon, 8 Oct 2018 12:00:46 -0700 (PDT) X-Google-Smtp-Source: ACcGV61m0bCuejZa1vuf6dUoPM0vXLB/Va14PAb/u0/P7HngfxDDxB0Dt3yHEhTORNlAlOhWWsvp X-Received: by 2002:a62:7d8d:: with SMTP id y135-v6mr26323410pfc.245.1539025246589; Mon, 08 Oct 2018 12:00:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539025246; cv=none; d=google.com; s=arc-20160816; b=t7POwIJZJ00Qp7ZSM6fZciDkzsCg0zEro7L+fp40qmzydOu5TshZJHTGNBIwBLytNR v76Tfp6C28YY1l8rNGIjGvLCKC7GzQoQr2E+oEqCflFb2k6GDZC0oRZ2KgZyZnuxYQBd jSA2p+wUDSlJ8IMd6lRdzlcjnL6jFNPuOjYCcWTCtNPbE4/O6MYbn7X+CgkjZ0M/jyms VxyQXnCFktc1tzrZg2PuQIp7z9ZGv2wpNMaUiVSw01eB6lamjWyOZ2vBEeg/qBGU9g5j bi+L3344jdUieNaN6KdhUBvi/4niwEOyR2Y8NkLZv/lP3hSlJTg2mV8RBENaxuCmzJyn x8WA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Qm31E0nanYbmbYj4baY4kN7hsOKQkdLVeLMujt1KwJA=; b=RkJ+R6NBAup+RfkLOBD6jsFNEOtviywUXQ4Bl7HkynUZBvBlIqrseeRK/Bzo+eRiVb tzcHY84O9sOgCcIINGF6mSuLQq1CwwsPnsbBd9qsKnMiczhOmuy2MlxZVZhlj6yS3SsV 0d4ljxnZvzoDilQU6E6uJr+jSpkPHyM1F5faUVuD1W1kA38Jn3cIdVi+RMo9e4DUAeLc y5XQuo0RHNPEKc1LKQEmcTcIqSUrTKW6R5BbxWgthRX2dB/44Dcs8EmRmcYFs0EPpWe3 qZ3/QeHXbEpuAHJOLha8TP85iqj4RDcmpdN8ahKuAS1I75Jv1XUEM50fZy4g4PfNFwyF XKLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XPjRkdo5; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k185-v6si18400251pgk.183.2018.10.08.12.00.31; Mon, 08 Oct 2018 12:00:46 -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=@kernel.org header.s=default header.b=XPjRkdo5; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731816AbeJICCU (ORCPT + 99 others); Mon, 8 Oct 2018 22:02:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:51526 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726991AbeJICCT (ORCPT ); Mon, 8 Oct 2018 22:02:19 -0400 Received: from localhost (ip-213-127-77-176.ip.prioritytelecom.net [213.127.77.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B8950204FD; Mon, 8 Oct 2018 18:49:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539024551; bh=Xy0NDSMalLyLLwv3RLLTJ9gpHv6Inln2N0MoaCIfkhA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XPjRkdo5zdMczxVBso8WHcCY13/r2HMnSJR+7jCE9fMAKLORPtxDBYOj2ssAhMj/i +I/EncKVLeNLC8HWwwjGJR03EzTtwD7I+nzbtuYrZ6kBfkBDQs6cLhtO6EVZLNeHzF 4qB/sCGjUZ8pjfOFm/oyM4ZRDR9s0llmnXLVnmCc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kenneth Penza , Daniel Black , Mike Kravetz , Konstantin Khlebnikov , Andrew Morton Subject: [PATCH 4.18 077/168] mm: madvise(MADV_DODUMP): allow hugetlbfs pages Date: Mon, 8 Oct 2018 20:30:57 +0200 Message-Id: <20181008175622.996113321@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181008175620.043587728@linuxfoundation.org> References: <20181008175620.043587728@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Daniel Black commit d41aa5252394c065d1f04d1ceea885b70d00c9c6 upstream. Reproducer, assuming 2M of hugetlbfs available: Hugetlbfs mounted, size=2M and option user=testuser # mount | grep ^hugetlbfs hugetlbfs on /dev/hugepages type hugetlbfs (rw,pagesize=2M,user=dan) # sysctl vm.nr_hugepages=1 vm.nr_hugepages = 1 # grep Huge /proc/meminfo AnonHugePages: 0 kB ShmemHugePages: 0 kB HugePages_Total: 1 HugePages_Free: 1 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB Hugetlb: 2048 kB Code: #include #include #define SIZE 2*1024*1024 int main() { void *ptr; ptr = mmap(NULL, SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_HUGETLB | MAP_ANONYMOUS, -1, 0); madvise(ptr, SIZE, MADV_DONTDUMP); madvise(ptr, SIZE, MADV_DODUMP); } Compile and strace: mmap(NULL, 2097152, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_HUGETLB, -1, 0) = 0x7ff7c9200000 madvise(0x7ff7c9200000, 2097152, MADV_DONTDUMP) = 0 madvise(0x7ff7c9200000, 2097152, MADV_DODUMP) = -1 EINVAL (Invalid argument) hugetlbfs pages have VM_DONTEXPAND in the VmFlags driver pages based on author testing with analysis from Florian Weimer[1]. The inclusion of VM_DONTEXPAND into the VM_SPECIAL defination was a consequence of the large useage of VM_DONTEXPAND in device drivers. A consequence of [2] is that VM_DONTEXPAND marked pages are unable to be marked DODUMP. A user could quite legitimately madvise(MADV_DONTDUMP) their hugetlbfs memory for a while and later request that madvise(MADV_DODUMP) on the same memory. We correct this omission by allowing madvice(MADV_DODUMP) on hugetlbfs pages. [1] https://stackoverflow.com/questions/52548260/madvisedodump-on-the-same-ptr-size-as-a-successful-madvisedontdump-fails-wit [2] commit 0103bd16fb90 ("mm: prepare VM_DONTDUMP for using in drivers") Link: http://lkml.kernel.org/r/20180930054629.29150-1-daniel@linux.ibm.com Link: https://lists.launchpad.net/maria-discuss/msg05245.html Fixes: 0103bd16fb90 ("mm: prepare VM_DONTDUMP for using in drivers") Reported-by: Kenneth Penza Signed-off-by: Daniel Black Reviewed-by: Mike Kravetz Cc: Konstantin Khlebnikov Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman Signed-off-by: Greg Kroah-Hartman --- mm/madvise.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/mm/madvise.c +++ b/mm/madvise.c @@ -96,7 +96,7 @@ static long madvise_behavior(struct vm_a new_flags |= VM_DONTDUMP; break; case MADV_DODUMP: - if (new_flags & VM_SPECIAL) { + if (!is_vm_hugetlb_page(vma) && new_flags & VM_SPECIAL) { error = -EINVAL; goto out; }