From patchwork Sun Sep 30 05:46:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Black X-Patchwork-Id: 10621155 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A8795112B for ; Sun, 30 Sep 2018 05:46:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9824929AEE for ; Sun, 30 Sep 2018 05:46:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8BF9829AF2; Sun, 30 Sep 2018 05:46:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 941B229AEE for ; Sun, 30 Sep 2018 05:46:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C96FB8E0002; Sun, 30 Sep 2018 01:46:53 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C456B8E0001; Sun, 30 Sep 2018 01:46:53 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B10108E0002; Sun, 30 Sep 2018 01:46:53 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f69.google.com (mail-ot1-f69.google.com [209.85.210.69]) by kanga.kvack.org (Postfix) with ESMTP id 83C588E0001 for ; Sun, 30 Sep 2018 01:46:53 -0400 (EDT) Received: by mail-ot1-f69.google.com with SMTP id k18-v6so11803802otl.16 for ; Sat, 29 Sep 2018 22:46:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:mime-version:content-transfer-encoding:message-id; bh=hz7P5dgHnAmVUeVGgW6VMv+F4mqtAXnYbtoD7eu2anQ=; b=pOrKPWDn6PbHjKSzBgsBaAEGQUJD+6pbfCxmGno5cFhcBHrhvcSsAzddix0S9nzG9H Wnyhyv4r6o9IRhD5+bDnV3So5ssd8Wvu9cvEcScFcQGSiMXs73p2lfF8KQfJbc9emHv3 EWllt7e7Co6018ikADXO1rUeS5iSqspEVfB4IDuqiwrnNIeBvMw7G17Pg/0hlVX10hzY I3PcvTz96Or5V8QnENRok0XfWgkR5TN4VUvHE8MImADDqUJtQgSJwXYMMrhPjzIYTxfE cT2/W2SvL5QlSsDLbaPAhcy6y4IzJdNIHe9sHy2O6R9BkngirGlSJ9YCQhTkD9MQmEmn QqQw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of daniel@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=daniel@linux.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com X-Gm-Message-State: ABuFfogxnBqFhUjFuxfRXXDo2XCJ6vQN33jGJppTYSDl2ASnT7J1b/vV LrGpqitJ0kpcuM89TFoJySSf6vxlN+CH1Vd6qzi6BzyPMZ7c/h8jjBWrCcLrONblBnLKZl2Kck4 5ZbnPwb0wUKbsTpzLbVsLM7TKeC5qxEpg4sYxTtsFZCw39jyZF4gBZDyidrWf/+rFow== X-Received: by 2002:aca:5905:: with SMTP id n5-v6mr2638139oib.232.1538286413295; Sat, 29 Sep 2018 22:46:53 -0700 (PDT) X-Google-Smtp-Source: ACcGV63kuK3Z1l3eJjGLtq5xfIFvLC9fPif1kpQHf0xU8SW+LG+QfgWqpx7Tg1iRK9x31AnCPwbZ X-Received: by 2002:aca:5905:: with SMTP id n5-v6mr2638123oib.232.1538286412519; Sat, 29 Sep 2018 22:46:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538286412; cv=none; d=google.com; s=arc-20160816; b=y5Fd1Yebkyn1vzayt6xsLSeKfvZK/pnJ0uymKzHnzymzoK12HrNh92JGt8qIIO8Xkx YW2T3gfWuHLx5b2DZmjJiCgvmNvgsFFTAiDcm6fV0pm6rZ9L43MMTX5eKWZIb1DwyJ9n WAwiv+ImAD09d4z13qZrBxXrYqdkySsSWWrMtor4/Yrkn8mHM/M8mS4xTZQXEcW17zJB CazgKzpLVcZjbOAxlv4cSY3PTZrHbuFcputMSCjSWCYGfttlCZ8DucfZvSyrV+PWAbVD ipEYWcZefmdYsP+u7cdiBa6YVMJPaPVcvHhuNbWXN4PNNV1KJA0YLoq6jwf7NLYVLiv+ xZdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:content-transfer-encoding:mime-version:date:subject:cc :to:from; bh=hz7P5dgHnAmVUeVGgW6VMv+F4mqtAXnYbtoD7eu2anQ=; b=Sn6m7xOnxZlrQpiOc3NFaWrm5TxO+Ghdt2YahTfHcax9govWLXdC+PXHl7tl/y5yYY OMQ9AMENLuGfwLhDIq6qdAw3MIiuXZks8KjLKD529RGYjNH+RAVGjkbsi3yn3VD1c+mE NOqnHzrvudy0fWrU7QEc1xotexs9CoxS2QQ3T/lvXjQYDp0QMBztSs4Iz+QaYvDZPmQb CZ1DOmvjG4gIzo8lo0HVwuIoDhW+GUenvcwGqShCIIrniMUMI76YEK67MTFWDrz49WIz 0UDi4Lv7RcnC9rS9L5HrC9J1052YusDM2gpi0VnVMXrCOvRijQd6w3DgielTyADrDW9i dXnQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of daniel@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=daniel@linux.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com. [148.163.156.1]) by mx.google.com with ESMTPS id n15-v6si771461otb.212.2018.09.29.22.46.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 29 Sep 2018 22:46:52 -0700 (PDT) Received-SPF: pass (google.com: domain of daniel@linux.ibm.com designates 148.163.156.1 as permitted sender) client-ip=148.163.156.1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of daniel@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=daniel@linux.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w8U5hbkK096829 for ; Sun, 30 Sep 2018 01:46:51 -0400 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 2mtpc036x6-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sun, 30 Sep 2018 01:46:51 -0400 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sun, 30 Sep 2018 06:46:49 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp03.uk.ibm.com (192.168.101.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Sun, 30 Sep 2018 06:46:47 +0100 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w8U5kkFt63242262 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Sun, 30 Sep 2018 05:46:46 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9B71811C054; Sun, 30 Sep 2018 08:46:25 +0100 (BST) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 48AE911C04A; Sun, 30 Sep 2018 08:46:25 +0100 (BST) Received: from ozlabs.au.ibm.com (unknown [9.192.253.14]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Sun, 30 Sep 2018 08:46:25 +0100 (BST) Received: from volution.fritz.box (unknown [9.81.198.156]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.au.ibm.com (Postfix) with ESMTPSA id 1BF2AA0212; Sun, 30 Sep 2018 15:46:42 +1000 (AEST) From: Daniel Black To: linux-mm@kvack.org, mike.kravetz@oracle.com, khlebnikov@openvz.org Cc: Daniel Black Subject: [PATCH] mm: madvise(MADV_DODUMP) allow hugetlbfs pages Date: Sun, 30 Sep 2018 15:46:29 +1000 X-Mailer: git-send-email 2.19.0 MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 18093005-0012-0000-0000-000002B05901 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18093005-0013-0000-0000-000020E48166 Message-Id: <20180930054629.29150-1-daniel@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-09-30_04:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1809300062 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: X-Virus-Scanned: ClamAV using ClamSMTP 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") Fixes: 0103bd16fb90 ("mm: prepare VM_DONTDUMP for using in drivers") Reported-by: Kenneth Penza Signed-off-by: Daniel Black Buglink: https://lists.launchpad.net/maria-discuss/msg05245.html Cc: linux-mm@kvack.org Cc: Mike Kravetz Cc: Konstantin Khlebnikov Reviewed-by: Mike Kravetz --- mm/madvise.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/madvise.c b/mm/madvise.c index 972a9eaa898b..71d21df2a3f3 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -96,7 +96,7 @@ static long madvise_behavior(struct vm_area_struct *vma, 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; }