From patchwork Sat Mar 10 18:17:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andiry Xu X-Patchwork-Id: 10273803 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 09424602BD for ; Sat, 10 Mar 2018 18:20:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E61AE29106 for ; Sat, 10 Mar 2018 18:20:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D933329759; Sat, 10 Mar 2018 18:20:30 +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 D8E84299BC for ; Sat, 10 Mar 2018 18:20:29 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 2ECE12253FB7C; Sat, 10 Mar 2018 10:14:02 -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:c01::241; helo=mail-pl0-x241.google.com; envelope-from=jix024@eng.ucsd.edu; receiver=linux-nvdimm@lists.01.org Received: from mail-pl0-x241.google.com (mail-pl0-x241.google.com [IPv6:2607:f8b0:400e:c01::241]) (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 0F38321E082A6 for ; Sat, 10 Mar 2018 10:13:58 -0800 (PST) Received: by mail-pl0-x241.google.com with SMTP id f23-v6so7023447plr.10 for ; Sat, 10 Mar 2018 10:20:17 -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=kAeU2DN67lgUPB6WpNsaBBjUrvsn999/CVZoEwx/ShM=; b=bGGEM2H+2eKqtwU5aN/9cbdPPrWjsG/JPT63L9PWDT6ORZVGwYZ3H/XxWDWtL2oSBN hXCmaGSVeuyLZLlSnirUXtc8SW73gct0Xo5j6iz3BFPMc39XIBfQzZScwNBeg5CpUalD H4cvzQhHamW/QlRE/G4Zg/jAX7Xt+ezM3TM/A= 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=kAeU2DN67lgUPB6WpNsaBBjUrvsn999/CVZoEwx/ShM=; b=I7+OoTK4ARJ6FHHyLOx0OibvgV0go8ObuJIwfWly7kA7foPsNvZR9CIthlEshdmq8V ZJY2xBvTUd+E6hgzpFGDMdhq/hOle7iDd/3wpiBoTbP77o4io7mVijf66EoipPtOG4xc 0162EB2FGuLqdCv+VEc2l8ymBn6n1stC8c2ocAnJFp+GCdufOeLLMyrglsnIeiC54Jjf NZmUJOCCdhaEWti9C8KPay82z/hnQW1LY8FEJtWDwpMe33rduqb+hFLfXnd7ayfRwvOh kSOAkCOxyoa9pFhk1n14P7RdgAnxTBXUlWaZl+j+Sn2UKIpkSWFowh9eE/P7L6ywKReb p+Ew== X-Gm-Message-State: AElRT7EdO1J3fzRUjSG7PcOcIyT0AG7QEMerKQoFQsdeBvn7PYqXpy4Z XgtC9QuPOMJuBqPaef2w8KJEkw== X-Google-Smtp-Source: AG47ELvLHJeZkfC6VkGQht7NTm70TP5vhS0iZ0sEZY7gZ3MmU01vHutzS2z5GU42qS5LY0m3uQ01Ew== X-Received: by 2002:a17:902:6f17:: with SMTP id w23-v6mr2807136plk.336.1520706017374; Sat, 10 Mar 2018 10:20:17 -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.20.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 10 Mar 2018 10:20:16 -0800 (PST) From: Andiry Xu To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org Subject: [RFC v2 02/83] Add nova_def.h. Date: Sat, 10 Mar 2018 10:17:43 -0800 Message-Id: <1520705944-6723-3-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 This file defines NOVA filesystem macros and routines to persist updates by using Intel persistent memory instruction CLWB or clflush. Signed-off-by: Andiry Xu --- fs/nova/nova_def.h | 128 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 fs/nova/nova_def.h diff --git a/fs/nova/nova_def.h b/fs/nova/nova_def.h new file mode 100644 index 0000000..1cbed6f --- /dev/null +++ b/fs/nova/nova_def.h @@ -0,0 +1,128 @@ +/* + * BRIEF DESCRIPTION + * + * Definitions for the NOVA filesystem. + * + * Copyright 2015-2016 Regents of the University of California, + * UCSD Non-Volatile Systems Lab, Andiry Xu + * Copyright 2012-2013 Intel Corporation + * Copyright 2009-2011 Marco Stornelli + * Copyright 2003 Sony Corporation + * Copyright 2003 Matsushita Electric Industrial Co., Ltd. + * 2003-2004 (c) MontaVista Software, Inc. , Steve Longerbeam + * + * This file is licensed under the terms of the GNU General Public + * License version 2. This program is licensed "as is" without any + * warranty of any kind, whether express or implied. + */ +#ifndef _LINUX_NOVA_DEF_H +#define _LINUX_NOVA_DEF_H + +#include +#include + +#define NOVA_SUPER_MAGIC 0x4E4F5641 /* NOVA */ + +/* + * The NOVA filesystem constants/structures + */ + +/* + * Mount flags + */ +#define NOVA_MOUNT_XATTR_USER 0x000002 /* Extended user attributes */ +#define NOVA_MOUNT_POSIX_ACL 0x000004 /* POSIX Access Control Lists */ +#define NOVA_MOUNT_DAX 0x000008 /* Direct Access */ +#define NOVA_MOUNT_ERRORS_CONT 0x000010 /* Continue on errors */ +#define NOVA_MOUNT_ERRORS_RO 0x000020 /* Remount fs ro on errors */ +#define NOVA_MOUNT_ERRORS_PANIC 0x000040 /* Panic on errors */ +#define NOVA_MOUNT_HUGEMMAP 0x000080 /* Huge mappings with mmap */ +#define NOVA_MOUNT_HUGEIOREMAP 0x000100 /* Huge mappings with ioremap */ +#define NOVA_MOUNT_FORMAT 0x000200 /* was FS formatted on mount? */ + +/* + * Maximal count of links to a file + */ +#define NOVA_LINK_MAX 32000 + +#define NOVA_DEF_BLOCK_SIZE_4K 4096 + +#define NOVA_INODE_BITS 7 +#define NOVA_INODE_SIZE 128 /* must be power of two */ + +#define NOVA_NAME_LEN 255 + +#define MAX_CPUS 1024 + +/* NOVA supported data blocks */ +#define NOVA_BLOCK_TYPE_4K 0 +#define NOVA_BLOCK_TYPE_2M 1 +#define NOVA_BLOCK_TYPE_1G 2 +#define NOVA_BLOCK_TYPE_MAX 3 + +#define META_BLK_SHIFT 9 + +/* + * Play with this knob to change the default block type. + * By changing the NOVA_DEFAULT_BLOCK_TYPE to 2M or 1G, + * we should get pretty good coverage in testing. + */ +#define NOVA_DEFAULT_BLOCK_TYPE NOVA_BLOCK_TYPE_4K + + +/* ======================= Write ordering ========================= */ + +#define CACHELINE_SIZE (64) +#define CACHELINE_MASK (~(CACHELINE_SIZE - 1)) +#define CACHELINE_ALIGN(addr) (((addr)+CACHELINE_SIZE-1) & CACHELINE_MASK) + + +static inline bool arch_has_clwb(void) +{ + return static_cpu_has(X86_FEATURE_CLWB); +} + +extern int support_clwb; + +#define _mm_clflush(addr)\ + asm volatile("clflush %0" : "+m" (*(volatile char *)(addr))) +#define _mm_clflushopt(addr)\ + asm volatile(".byte 0x66; clflush %0" : "+m" \ + (*(volatile char *)(addr))) +#define _mm_clwb(addr)\ + asm volatile(".byte 0x66; xsaveopt %0" : "+m" \ + (*(volatile char *)(addr))) + +/* Provides ordering from all previous clflush too */ +static inline void PERSISTENT_MARK(void) +{ + /* TODO: Fix me. */ +} + +static inline void PERSISTENT_BARRIER(void) +{ + asm volatile ("sfence\n" : : ); +} + +static inline void nova_flush_buffer(void *buf, uint32_t len, bool fence) +{ + uint32_t i; + + len = len + ((unsigned long)(buf) & (CACHELINE_SIZE - 1)); + if (support_clwb) { + for (i = 0; i < len; i += CACHELINE_SIZE) + _mm_clwb(buf + i); + } else { + for (i = 0; i < len; i += CACHELINE_SIZE) + _mm_clflush(buf + i); + } + /* Do a fence only if asked. We often don't need to do a fence + * immediately after clflush because even if we get context switched + * between clflush and subsequent fence, the context switch operation + * provides implicit fence. + */ + if (fence) + PERSISTENT_BARRIER(); +} + +#endif /* _LINUX_NOVA_DEF_H */