Received: by 10.223.164.221 with SMTP id h29csp160183wrb; Tue, 31 Oct 2017 11:42:32 -0700 (PDT) X-Google-Smtp-Source: ABhQp+QinC2BcHxAeFyD8dweaFpjegipPwvY8u22T3DngAKFyB7YmN2tuZKPKoTPCg2tsyeXTYZn X-Received: by 10.99.109.75 with SMTP id i72mr2712955pgc.268.1509475352157; Tue, 31 Oct 2017 11:42:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509475352; cv=none; d=google.com; s=arc-20160816; b=b/Fyk3GXkjevFPGWUrUtVd6P8tlGfimG9kdQYU6Kxvw/XjLQD1OLZKFqkhlbtXqL9U gqRayFYLjA2qGs+41DF5yUD6ywsoYqrUc7UgiM9n8rtORZibnK6Sd1Etj1cyOoDRAk+s qVCwHBT9x8aqlxtQNvKNY3SHrZrvPQaetWd+Hdr+p4xHxC/ouHOQRYdBXPETMgMb0sB3 VYZjerO3ZIBea8NPrV7mHhSNssvLKuCrGBq/8bbJ30IlVIdy1hHyAUuEoLMtwzmcRm0m uvKS3wjbLZc6/S0utC+lqr2eK9LCYuKnAJWH4aXdQpxfEzZM8bRy6xEyR5Nyh5CaBGlW AsIg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dmarc-filter:arc-authentication-results; bh=2y5OqVpH9kh+7nDHzFb/MAj1dMWzO/g0mB5Y7mTdL8w=; b=n3JREMCP4BrhKyJ/2PwCc5zn3xYV3yz6hjIDRJShVprvK351DjVyQVfVrNdOZsZUJd f4vkemSQu9FVbcbdRS6J152ES8D5vdw7/usLDvJ8cMjkeWtvjPffcgsS/Yw0wOq7i2b8 9JlkwOb3sQDDbHFVMFDcxNRjc6BjJuk3urX2hXsZFo7+py4YhOQDDlr155WQjLfvRRAy 8N8gxWg7DnKvVWjm5YrU5mnllzt89E+RpSjsVaWs251kwkAHvjIMa/HdJSJuz41xqqRj Q7X7m+D+0j/3SsGBnGwTI8AQhFuuB6P3MhqFvtJsomSg+t+u8KERtolyDIagkFcqgySQ VIqw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o128si2290466pfg.292.2017.10.31.11.42.16; Tue, 31 Oct 2017 11:42:32 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932877AbdJaSlT (ORCPT + 99 others); Tue, 31 Oct 2017 14:41:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43680 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932625AbdJaSlR (ORCPT ); Tue, 31 Oct 2017 14:41:17 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2804833A178; Tue, 31 Oct 2017 18:41:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2804833A178 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com Received: from localhost (ovpn-112-19.ams2.redhat.com [10.36.112.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 897B660C9B; Tue, 31 Oct 2017 18:41:13 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: aarcange@redhat.com, hughd@google.com, nyc@holomorphy.com, mike.kravetz@oracle.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PATCH 5/6] shmem: add sealing support to hugetlb-backed memfd Date: Tue, 31 Oct 2017 19:40:51 +0100 Message-Id: <20171031184052.25253-6-marcandre.lureau@redhat.com> In-Reply-To: <20171031184052.25253-1-marcandre.lureau@redhat.com> References: <20171031184052.25253-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 31 Oct 2017 18:41:17 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adapt add_seals()/get_seals() to work with hugetbfs-backed memory. Teach memfd_create() to allow sealing operations on MFD_HUGETLB. Signed-off-by: Marc-André Lureau --- mm/shmem.c | 51 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index b7811979611f..b7c59d993c19 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2717,6 +2717,19 @@ static int shmem_wait_for_pins(struct address_space *mapping) return error; } +static unsigned int *memfd_get_seals(struct file *file) +{ + if (file->f_op == &shmem_file_operations) + return &SHMEM_I(file_inode(file))->seals; + +#ifdef CONFIG_HUGETLBFS + if (file->f_op == &hugetlbfs_file_operations) + return &HUGETLBFS_I(file_inode(file))->seals; +#endif + + return NULL; +} + #define F_ALL_SEALS (F_SEAL_SEAL | \ F_SEAL_SHRINK | \ F_SEAL_GROW | \ @@ -2725,7 +2738,7 @@ static int shmem_wait_for_pins(struct address_space *mapping) static int memfd_add_seals(struct file *file, unsigned int seals) { struct inode *inode = file_inode(file); - struct shmem_inode_info *info = SHMEM_I(inode); + unsigned int *file_seals; int error; /* @@ -2758,8 +2771,6 @@ static int memfd_add_seals(struct file *file, unsigned int seals) * other file types. */ - if (file->f_op != &shmem_file_operations) - return -EINVAL; if (!(file->f_mode & FMODE_WRITE)) return -EPERM; if (seals & ~(unsigned int)F_ALL_SEALS) @@ -2767,12 +2778,18 @@ static int memfd_add_seals(struct file *file, unsigned int seals) inode_lock(inode); - if (info->seals & F_SEAL_SEAL) { + file_seals = memfd_get_seals(file); + if (!file_seals) { + error = -EINVAL; + goto unlock; + } + + if (*file_seals & F_SEAL_SEAL) { error = -EPERM; goto unlock; } - if ((seals & F_SEAL_WRITE) && !(info->seals & F_SEAL_WRITE)) { + if ((seals & F_SEAL_WRITE) && !(*file_seals & F_SEAL_WRITE)) { error = mapping_deny_writable(file->f_mapping); if (error) goto unlock; @@ -2784,7 +2801,7 @@ static int memfd_add_seals(struct file *file, unsigned int seals) } } - info->seals |= seals; + *file_seals |= seals; error = 0; unlock: @@ -2792,12 +2809,11 @@ static int memfd_add_seals(struct file *file, unsigned int seals) return error; } -static int memfd_get_seals(struct file *file) +static int memfd_fcntl_get_seals(struct file *file) { - if (file->f_op != &shmem_file_operations) - return -EINVAL; + unsigned int *seals = memfd_get_seals(file); - return SHMEM_I(file_inode(file))->seals; + return seals ? *seals : -EINVAL; } long memfd_fcntl(struct file *file, unsigned int cmd, unsigned long arg) @@ -2813,7 +2829,7 @@ long memfd_fcntl(struct file *file, unsigned int cmd, unsigned long arg) error = memfd_add_seals(file, arg); break; case F_GET_SEALS: - error = memfd_get_seals(file); + error = memfd_fcntl_get_seals(file); break; default: error = -EINVAL; @@ -3657,7 +3673,7 @@ SYSCALL_DEFINE2(memfd_create, const char __user *, uname, unsigned int, flags) { - struct shmem_inode_info *info; + unsigned int *file_seals; struct file *file; int fd, error; char *name; @@ -3667,9 +3683,6 @@ SYSCALL_DEFINE2(memfd_create, if (flags & ~(unsigned int)MFD_ALL_FLAGS) return -EINVAL; } else { - /* Sealing not supported in hugetlbfs (MFD_HUGETLB) */ - if (flags & MFD_ALLOW_SEALING) - return -EINVAL; /* Allow huge page size encoding in flags. */ if (flags & ~(unsigned int)(MFD_ALL_FLAGS | (MFD_HUGE_MASK << MFD_HUGE_SHIFT))) @@ -3722,12 +3735,8 @@ SYSCALL_DEFINE2(memfd_create, file->f_flags |= O_RDWR | O_LARGEFILE; if (flags & MFD_ALLOW_SEALING) { - /* - * flags check at beginning of function ensures - * this is not a hugetlbfs (MFD_HUGETLB) file. - */ - info = SHMEM_I(file_inode(file)); - info->seals &= ~F_SEAL_SEAL; + file_seals = memfd_get_seals(file); + *file_seals &= ~F_SEAL_SEAL; } fd_install(fd, file); -- 2.15.0.rc0.40.gaefcc5f6f From 1583525869627962200@xxx Wed Nov 08 19:05:51 +0000 2017 X-GM-THRID: 1583519426107842444 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread