Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3890594imu; Mon, 10 Dec 2018 09:23:22 -0800 (PST) X-Google-Smtp-Source: AFSGD/UMSDp+tKIQuYbYg72gVrXBzTlQgg9Vufa7mynFnbyjys5EogxOVedtMVKGnlkazHuuXauI X-Received: by 2002:a63:fc49:: with SMTP id r9mr11250301pgk.209.1544462602426; Mon, 10 Dec 2018 09:23:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544462602; cv=none; d=google.com; s=arc-20160816; b=vaxxowyLH/KPVgExo2e66Vv/Q9Bai4u0pURFiUnidFudPSkO4n6otRd3wnXfYffIYH BNbsdr46UBtBCvSbwtANTDO/6ZjEWlreJlVcmBnhTBpgZUX+Qe2KCrIxY8+et6DY8G6S 8TYybNRaO/1H8LMmAfln578K//oSmULzeC85WlIFOnqrIMReeJ2ol+loKcYd/NDqJfVB +ikX1lne6gKOYT6a/N027xDN1noyBTexGkqyRCSgE/Ydcvk2QwO//gqnUsDwrAJBU2B7 EQsnR+u9eM+3tXM11uf/1KcORfjcTTBAPivoqm/KUc6fajjnJnsqDpWWJcaB8g7Kd5l8 5JBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=KKSk4MCitjj3kXv8U608pjGl6ZAA6wlQrPV8gJmD7T4=; b=Jd//kc2gK60+dMR+jjM7u8C1aDjfJGENeJXoIjjNcbkzpdtbJtUCxDuaNdoXhAq/l3 2Ji+TjvlezsaajrM6jlOUuz5Xcoc5Y8o9pnsvPzVxTCtCZeFcLjYdu6tR7Amaychiqxy +97VvemRI9/ZSC0j9pRhF26Xne2biQPiMTp2xt0C8kK7PvVly0XFS91KFyTFzFhTBTQv gMiOFiVzw4fC0B8pEPJK+mI0wiYhxGmHh1G7DNj041u/1QZAentTrekYMjK6c0qdC+M+ A8o157oPLQ36fJj+3JcYFpPWoFoMsupoz0cdUDv/5O9KVsEN3prGaY9/u3KFwpfzbJI8 IgQg== 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 b65si9426888pgc.259.2018.12.10.09.23.07; Mon, 10 Dec 2018 09:23:22 -0800 (PST) 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 S1728647AbeLJRTQ (ORCPT + 99 others); Mon, 10 Dec 2018 12:19:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36998 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728377AbeLJRNf (ORCPT ); Mon, 10 Dec 2018 12:13:35 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 331E93164672; Mon, 10 Dec 2018 17:13:35 +0000 (UTC) Received: from horse.redhat.com (unknown [10.18.25.234]) by smtp.corp.redhat.com (Postfix) with ESMTP id 033061054FD2; Mon, 10 Dec 2018 17:13:34 +0000 (UTC) Received: by horse.redhat.com (Postfix, from userid 10451) id 79352224268; Mon, 10 Dec 2018 12:13:30 -0500 (EST) From: Vivek Goyal To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: vgoyal@redhat.com, miklos@szeredi.hu, stefanha@redhat.com, dgilbert@redhat.com, sweil@redhat.com, swhiteho@redhat.com Subject: [PATCH 29/52] fuse: add DAX mmap support Date: Mon, 10 Dec 2018 12:12:55 -0500 Message-Id: <20181210171318.16998-30-vgoyal@redhat.com> In-Reply-To: <20181210171318.16998-1-vgoyal@redhat.com> References: <20181210171318.16998-1-vgoyal@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Mon, 10 Dec 2018 17:13:35 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Stefan Hajnoczi Add DAX mmap() support. Signed-off-by: Stefan Hajnoczi --- fs/fuse/file.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 41d773ba2c72..5230f2d84a14 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -2501,9 +2501,65 @@ static int fuse_direct_mmap(struct file *file, struct vm_area_struct *vma) return generic_file_mmap(file, vma); } +static int __fuse_dax_fault(struct vm_fault *vmf, enum page_entry_size pe_size, + bool write) +{ + int ret; + struct inode *inode = file_inode(vmf->vma->vm_file); + struct super_block *sb = inode->i_sb; + pfn_t pfn; + + if (write) + sb_start_pagefault(sb); + + /* TODO inode semaphore to protect faults vs truncate */ + + ret = dax_iomap_fault(vmf, pe_size, &pfn, NULL, &fuse_iomap_ops); + + if (ret & VM_FAULT_NEEDDSYNC) + ret = dax_finish_sync_fault(vmf, pe_size, pfn); + + if (write) + sb_end_pagefault(sb); + + return ret; +} + +static int fuse_dax_fault(struct vm_fault *vmf) +{ + return __fuse_dax_fault(vmf, PE_SIZE_PTE, + vmf->flags & FAULT_FLAG_WRITE); +} + +static int fuse_dax_huge_fault(struct vm_fault *vmf, + enum page_entry_size pe_size) +{ + return __fuse_dax_fault(vmf, pe_size, vmf->flags & FAULT_FLAG_WRITE); +} + +static int fuse_dax_page_mkwrite(struct vm_fault *vmf) +{ + return __fuse_dax_fault(vmf, PE_SIZE_PTE, true); +} + +static int fuse_dax_pfn_mkwrite(struct vm_fault *vmf) +{ + return __fuse_dax_fault(vmf, PE_SIZE_PTE, true); +} + +static const struct vm_operations_struct fuse_dax_vm_ops = { + .fault = fuse_dax_fault, + .huge_fault = fuse_dax_huge_fault, + .page_mkwrite = fuse_dax_page_mkwrite, + .pfn_mkwrite = fuse_dax_pfn_mkwrite, +}; + static int fuse_dax_mmap(struct file *file, struct vm_area_struct *vma) { - return -EINVAL; /* TODO */ + file_accessed(file); + vma->vm_ops = &fuse_dax_vm_ops; + vma->vm_flags |= VM_MIXEDMAP | VM_HUGEPAGE; + return 0; } static int convert_fuse_file_lock(struct fuse_conn *fc, -- 2.13.6