Received: by 10.223.164.221 with SMTP id h29csp295048wrb; Fri, 3 Nov 2017 09:14:17 -0700 (PDT) X-Google-Smtp-Source: ABhQp+TrugI04tm1zUwzKRvnZozmbH1rTu9UwoH0Kwaw9RgHf5AFL1CU9HWnwhxPOrOWLN2xwJ+m X-Received: by 10.99.45.67 with SMTP id t64mr7534167pgt.108.1509725657129; Fri, 03 Nov 2017 09:14:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509725657; cv=none; d=google.com; s=arc-20160816; b=dRTygkx4s0BC7jYHV9AALbfJ8KncWAHcWJN0VD91RZdtGxrC8G4jnhWU8JLZqgH7Or rbi9DjX5jlzqTfDb0AbZGKyu8J2Hfb6yuJrLiNNKW9lJKQPF3cJcm9ax40iun3T/YPGn 73jgieqBAkFt2ibRt26ERhG5MmHuyCafffgaWPMgv/0i8goO44RrkvkbbT7CQ1J91/pa IdQvCkBqZp9ZNT1GeKR3LR1UqSwEOAj1N2twYN0VwzJ5W6ljEfHZ0d5y6FnWhvH7w6M0 WhYyK6WrKWaxCp5gkwn8LXX7Xk3VO/WCcByYXNTHzK5uW2ZXl2Py0TDX28dJeVEdyCM+ w/Ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:dmarc-filter :arc-authentication-results; bh=cG/G2OrWmKx1PzRsw2IuWls6Act1ZmmhlJkVZRuNjm4=; b=xYujkx1Kgquw3y9Af/F3czwG9Qen+d5VtSzZVbaFb2KKZoQvlOY38p7WOVRDYaAoY3 0figP21lnqIw/9YKyNnBTIgKyCV8lKb5mSPtQSzel5DdE06EFJhM/Es9J11B1WvxihPB DfB6K8PHuE0dqtEQr5/ZoWCMifiFwvrwTfmSPV1GVrLUsy5GUxS/0l3pTr5H0gPL7Pq+ KYuMd+IFMzi6H5vw/op7w5lw5fFFpYgO5q8NbTGLUtq8siQPBwYfowrckp3YN08m/7EL yZiREpAwzcj2lq828welwX/BVlWt4BqHOn5vzeFIiqfPVCkeq1Ks0sVrHt8IaVoWMq23 Z6DA== 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 q13si6384759pgr.170.2017.11.03.09.13.45; Fri, 03 Nov 2017 09:14:17 -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 S1755320AbdKCQNH convert rfc822-to-8bit (ORCPT + 94 others); Fri, 3 Nov 2017 12:13:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54752 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752253AbdKCQNG (ORCPT ); Fri, 3 Nov 2017 12:13:06 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E798315DF; Fri, 3 Nov 2017 16:13:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E798315DF Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=mlureau@redhat.com Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DEA9C5BD67; Fri, 3 Nov 2017 16:13:05 +0000 (UTC) Received: from zmail17.collab.prod.int.phx2.redhat.com (zmail17.collab.prod.int.phx2.redhat.com [10.5.83.19]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D2DC74BB78; Fri, 3 Nov 2017 16:13:05 +0000 (UTC) Date: Fri, 3 Nov 2017 12:13:05 -0400 (EDT) From: =?utf-8?Q?Marc-Andr=C3=A9?= Lureau To: Mike Kravetz Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, aarcange@redhat.com, hughd@google.com, nyc@holomorphy.com Message-ID: <1255476707.35881664.1509725585691.JavaMail.zimbra@redhat.com> In-Reply-To: References: <20171031184052.25253-1-marcandre.lureau@redhat.com> <20171031184052.25253-6-marcandre.lureau@redhat.com> Subject: Re: [PATCH 5/6] shmem: add sealing support to hugetlb-backed memfd MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT X-Originating-IP: [10.36.112.63, 10.4.195.4] Thread-Topic: shmem: add sealing support to hugetlb-backed memfd Thread-Index: oiD8kdEfNTRqJQON1fZf5w6FnpFOAg== X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 03 Nov 2017 16:13:06 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi ----- Original Message ----- > On 10/31/2017 11:40 AM, Marc-André Lureau wrote: > > 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) > > I would have named this something like 'memfd_file_seal_ptr', and not > changed the name of memfd_get_seals below. Just my preference, and it > does not carry as much weight as Hugh who originally write this code. > agreed and changed, thanks > > +{ > > + 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; > > +} > > + > > As mentioned in patch 2, I think this code will need to be restructured > so that hugetlbfs file sealing will work even is CONFIG_TMPFS is not > defined. The above routine is behind #ifdef CONFIG_TMPFS. > > In general the code looks fine, but this config issue needs to be addressed. See discussion in patch 2 > -- > Mike Kravetz > > > #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); > > > > -- > To unsubscribe, send a message with 'unsubscribe linux-mm' in > the body to majordomo@kvack.org. For more info on Linux MM, > see: http://www.linux-mm.org/ . > Don't email: email@kvack.org > From 1582911436601810203@xxx Thu Nov 02 00:19:42 +0000 2017 X-GM-THRID: 1582799627131079120 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread