-
Notifications
You must be signed in to change notification settings - Fork 0
/
wprotect.h
146 lines (125 loc) · 3.78 KB
/
wprotect.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
* BRIEF DESCRIPTION
*
* Memory protection definitions for the NOVA filesystem.
*
* Copyright 2015-2016 Regents of the University of California,
* UCSD Non-Volatile Systems Lab, Andiry Xu <[email protected]>
* Copyright 2012-2013 Intel Corporation
* Copyright 2009-2011 Marco Stornelli <[email protected]>
* Copyright 2003 Sony Corporation
* Copyright 2003 Matsushita Electric Industrial Co., Ltd.
* 2003-2004 (c) MontaVista Software, Inc. , Steve Longerbeam
*
* This program is free software; you can redistribute it and/or modify it
*
* 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 __WPROTECT_H
#define __WPROTECT_H
#include <linux/fs.h>
#include "nova_def.h"
/* nova_memunlock_super() before calling! */
static inline void nova_sync_super(struct nova_super_block *ps)
{
u16 crc = 0;
ps->s_wtime = cpu_to_le32(get_seconds());
ps->s_sum = 0;
crc = crc16(~0, (__u8 *)ps + sizeof(__le16),
NOVA_SB_STATIC_SIZE(ps) - sizeof(__le16));
ps->s_sum = cpu_to_le16(crc);
/* Keep sync redundant super block */
memcpy((void *)ps + NOVA_SB_SIZE, (void *)ps,
sizeof(struct nova_super_block));
}
#if 0
/* nova_memunlock_inode() before calling! */
static inline void nova_sync_inode(struct nova_inode *pi)
{
u16 crc = 0;
pi->i_sum = 0;
crc = crc16(~0, (__u8 *)pi + sizeof(__le16), NOVA_INODE_SIZE -
sizeof(__le16));
pi->i_sum = cpu_to_le16(crc);
}
#endif
extern int nova_writeable(void *vaddr, unsigned long size, int rw);
extern int nova_dax_mem_protect(struct super_block *sb,
void *vaddr, unsigned long size, int rw);
static inline int nova_is_protected(struct super_block *sb)
{
struct nova_sb_info *sbi = (struct nova_sb_info *)sb->s_fs_info;
return sbi->s_mount_opt & NOVA_MOUNT_PROTECT;
}
static inline int nova_is_wprotected(struct super_block *sb)
{
return nova_is_protected(sb);
}
static inline void
__nova_memunlock_range(void *p, unsigned long len)
{
/*
* NOTE: Ideally we should lock all the kernel to be memory safe
* and avoid to write in the protected memory,
* obviously it's not possible, so we only serialize
* the operations at fs level. We can't disable the interrupts
* because we could have a deadlock in this path.
*/
nova_writeable(p, len, 1);
}
static inline void
__nova_memlock_range(void *p, unsigned long len)
{
nova_writeable(p, len, 0);
}
static inline void nova_memunlock_range(struct super_block *sb, void *p,
unsigned long len)
{
if (nova_is_protected(sb))
__nova_memunlock_range(p, len);
}
static inline void nova_memlock_range(struct super_block *sb, void *p,
unsigned long len)
{
if (nova_is_protected(sb))
__nova_memlock_range(p, len);
}
static inline void nova_memunlock_super(struct super_block *sb,
struct nova_super_block *ps)
{
if (nova_is_protected(sb))
__nova_memunlock_range(ps, NOVA_SB_SIZE);
}
static inline void nova_memlock_super(struct super_block *sb,
struct nova_super_block *ps)
{
nova_sync_super(ps);
if (nova_is_protected(sb))
__nova_memlock_range(ps, NOVA_SB_SIZE);
}
static inline void nova_memunlock_inode(struct super_block *sb,
struct nova_inode *pi)
{
if (nova_is_protected(sb))
__nova_memunlock_range(pi, NOVA_SB_SIZE);
}
static inline void nova_memlock_inode(struct super_block *sb,
struct nova_inode *pi)
{
/* nova_sync_inode(pi); */
if (nova_is_protected(sb))
__nova_memlock_range(pi, NOVA_SB_SIZE);
}
static inline void nova_memunlock_block(struct super_block *sb, void *bp)
{
if (nova_is_protected(sb))
__nova_memunlock_range(bp, sb->s_blocksize);
}
static inline void nova_memlock_block(struct super_block *sb, void *bp)
{
if (nova_is_protected(sb))
__nova_memlock_range(bp, sb->s_blocksize);
}
#endif