From patchwork Sat Mar 10 18:18:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andiry Xu X-Patchwork-Id: 10273985 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D66D2605D2 for ; Sat, 10 Mar 2018 18:21:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C523B29106 for ; Sat, 10 Mar 2018 18:21:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B9E31296E5; Sat, 10 Mar 2018 18:21:59 +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=-1.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE,T_DKIM_INVALID autolearn=no version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7700B2974F for ; Sat, 10 Mar 2018 18:21:59 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 245EC22631497; Sat, 10 Mar 2018 10:15:30 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:400e:c05::243; helo=mail-pg0-x243.google.com; envelope-from=jix024@eng.ucsd.edu; receiver=linux-nvdimm@lists.01.org Received: from mail-pg0-x243.google.com (mail-pg0-x243.google.com [IPv6:2607:f8b0:400e:c05::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 711C72258AEF1 for ; Sat, 10 Mar 2018 10:15:27 -0800 (PST) Received: by mail-pg0-x243.google.com with SMTP id s13so1927081pgn.12 for ; Sat, 10 Mar 2018 10:21:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eng.ucsd.edu; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=HfvZqUeOPlkUUvhdndEHM3LiLj04yJY2/JR640YH4Tw=; b=bI0RKDi/z7MR88UF9VlkSF/Fz7PjGk6/dRaIgnVSLc10BmiSMlxrwgj2f6G4Vmv69P oGny5BDc3hIrNKG+CS5QWeW6u8WDNhzShgVy6Elm7m46oZkR4D6jqi3vam+01FZY+Vbv yWJ77TuYJ3Dh+3oeLN672MhzLHUSaWCloLtOA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=HfvZqUeOPlkUUvhdndEHM3LiLj04yJY2/JR640YH4Tw=; b=iQxyPWPFIgTOZXkP8lXosL+ZnBBqGumjua0Mh06uShty3nj5T6WtSG6hF4GQ0fER5M Cmzp1QWQYq+V0pU3rOwe1ARYSn6Ut91pcR9q1EcIKswDrlfsW+BHFEdCkuPrPWSLzi0O t93TtKBDKQnz7DsO0AbjLbypJ9L7eDtwgdqm8NwEZH3UTedseAHmye3A7I5vl3sk4lTw GZTxarIer20yBgd3BjjrB40f/kcdyKI5yS7R+e6wq1pzCjJZXqh61Pf6AQ6SRg2l2/2g Bbuau1UkXO+UWKlyZeCqaOJIzfvWzhrL2Ag6Kxdny4WMHMbrT8BaM7Iakx0I/bLII52E lIhg== X-Gm-Message-State: AElRT7F3H8zOxzfu8rDGyeWTOFBjnB+ym9mveTBC+Ruw/SF/Rr+7VCi8 MnisKy6IY3eJ7ATnigxgUxfaOQ== X-Google-Smtp-Source: AG47ELu8lJaGyE06A4cwh6akC+kFJn0VtXqYXkA7kPb8mL3lmxCdIxb/TPLL4jHScxPPhnijwZWIPw== X-Received: by 10.99.119.130 with SMTP id s124mr2246875pgc.64.1520706105893; Sat, 10 Mar 2018 10:21:45 -0800 (PST) Received: from brienza-desktop.8.8.4.4 (andxu.ucsd.edu. [132.239.17.134]) by smtp.gmail.com with ESMTPSA id h80sm9210167pfj.181.2018.03.10.10.21.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Mar 2018 10:21:45 -0800 (PST) From: Andiry Xu To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org Subject: [RFC v2 74/83] File operation: Mmap. Date: Sat, 10 Mar 2018 10:18:55 -0800 Message-Id: <1520705944-6723-75-git-send-email-jix024@eng.ucsd.edu> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1520705944-6723-1-git-send-email-jix024@eng.ucsd.edu> References: <1520705944-6723-1-git-send-email-jix024@eng.ucsd.edu> X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: coughlan@redhat.com, miklos@szeredi.hu, Andiry Xu , david@fromorbit.com, jack@suse.com, swanson@cs.ucsd.edu, swhiteho@redhat.com, andiry.xu@gmail.com MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP From: Andiry Xu NOVA uses the iomap framework to support mmap operation. Currently it does not support huge page mmap. Signed-off-by: Andiry Xu --- fs/nova/dax.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/nova/file.c | 25 +++++++++++++++++++++++++ fs/nova/nova.h | 1 + 3 files changed, 79 insertions(+) diff --git a/fs/nova/dax.c b/fs/nova/dax.c index e639b23..fa424b1 100644 --- a/fs/nova/dax.c +++ b/fs/nova/dax.c @@ -915,3 +915,56 @@ const struct iomap_ops nova_iomap_ops = { .iomap_begin = nova_iomap_begin, .iomap_end = nova_iomap_end, }; + + +/* TODO: Hugemap mmap */ +static int nova_dax_huge_fault(struct vm_fault *vmf, + enum page_entry_size pe_size) +{ + int ret = 0; + timing_t fault_time; + struct address_space *mapping = vmf->vma->vm_file->f_mapping; + struct inode *inode = mapping->host; + + NOVA_START_TIMING(pmd_fault_t, fault_time); + + nova_dbgv("%s: inode %lu, pgoff %lu\n", + __func__, inode->i_ino, vmf->pgoff); + + if (vmf->flags & FAULT_FLAG_WRITE) + file_update_time(vmf->vma->vm_file); + + ret = dax_iomap_fault(vmf, pe_size, NULL, NULL, &nova_iomap_ops); + + NOVA_END_TIMING(pmd_fault_t, fault_time); + return ret; +} + +static int nova_dax_fault(struct vm_fault *vmf) +{ + struct address_space *mapping = vmf->vma->vm_file->f_mapping; + struct inode *inode = mapping->host; + + nova_dbgv("%s: inode %lu, pgoff %lu, flags 0x%x\n", + __func__, inode->i_ino, vmf->pgoff, vmf->flags); + + return nova_dax_huge_fault(vmf, PE_SIZE_PTE); +} + +static int nova_dax_pfn_mkwrite(struct vm_fault *vmf) +{ + struct address_space *mapping = vmf->vma->vm_file->f_mapping; + struct inode *inode = mapping->host; + + nova_dbgv("%s: inode %lu, pgoff %lu, flags 0x%x\n", + __func__, inode->i_ino, vmf->pgoff, vmf->flags); + + return nova_dax_huge_fault(vmf, PE_SIZE_PTE); +} + +const struct vm_operations_struct nova_dax_vm_ops = { + .fault = nova_dax_fault, + .huge_fault = nova_dax_huge_fault, + .page_mkwrite = nova_dax_fault, + .pfn_mkwrite = nova_dax_pfn_mkwrite, +}; diff --git a/fs/nova/file.c b/fs/nova/file.c index a6b5bd3..0ae0333 100644 --- a/fs/nova/file.c +++ b/fs/nova/file.c @@ -617,10 +617,35 @@ static ssize_t nova_dax_file_write(struct file *filp, const char __user *buf, } +static int nova_dax_file_mmap(struct file *file, struct vm_area_struct *vma) +{ + struct inode *inode = file->f_mapping->host; + + file_accessed(file); + + vma->vm_flags |= VM_MIXEDMAP; + + vma->vm_ops = &nova_dax_vm_ops; + + nova_dbg_mmap4k("[%s:%d] inode %lu, MMAP 4KPAGE vm_start(0x%lx), " + "vm_end(0x%lx), vm pgoff %lu, %lu blocks, " + "vm_flags(0x%lx), vm_page_prot(0x%lx)\n", + __func__, __LINE__, + inode->i_ino, vma->vm_start, vma->vm_end, + vma->vm_pgoff, + (vma->vm_end - vma->vm_start) >> PAGE_SHIFT, + vma->vm_flags, + pgprot_val(vma->vm_page_prot)); + + return 0; +} + + const struct file_operations nova_dax_file_operations = { .llseek = nova_llseek, .read = nova_dax_file_read, .write = nova_dax_file_write, + .mmap = nova_dax_file_mmap, .open = nova_open, .fsync = nova_fsync, .flush = nova_flush, diff --git a/fs/nova/nova.h b/fs/nova/nova.h index 0d62c47..d209cfc 100644 --- a/fs/nova/nova.h +++ b/fs/nova/nova.h @@ -488,6 +488,7 @@ ssize_t do_nova_inplace_file_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos); extern const struct iomap_ops nova_iomap_ops; +extern const struct vm_operations_struct nova_dax_vm_ops; /* dir.c */