Skip to content

Commit 4d8f424

Browse files
Christoph Hellwigcmaiolino
authored andcommitted
xfs: use WRITE_ONCE/READ_ONCE for m_errortag
There is no synchronization for updating m_errortag, which is fine as it's just a debug tool. It would still be nice to fully avoid the theoretical case of torn values, so use WRITE_ONCE and READ_ONCE to access the members. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Hans Holmberg <hans.holmberg@wdc.com> Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Carlos Maiolino <cem@kernel.org>
1 parent e2d62bf commit 4d8f424

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

fs/xfs/xfs_error.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,18 @@ xfs_errortag_attr_store(
5050
{
5151
struct xfs_mount *mp = to_mp(kobject);
5252
unsigned int error_tag = to_attr(attr)->tag;
53+
unsigned int val;
5354
int ret;
5455

5556
if (strcmp(buf, "default") == 0) {
56-
mp->m_errortag[error_tag] =
57-
xfs_errortag_random_default[error_tag];
57+
val = xfs_errortag_random_default[error_tag];
5858
} else {
59-
ret = kstrtouint(buf, 0, &mp->m_errortag[error_tag]);
59+
ret = kstrtouint(buf, 0, &val);
6060
if (ret)
6161
return ret;
6262
}
6363

64+
WRITE_ONCE(mp->m_errortag[error_tag], val);
6465
return count;
6566
}
6667

@@ -71,9 +72,9 @@ xfs_errortag_attr_show(
7172
char *buf)
7273
{
7374
struct xfs_mount *mp = to_mp(kobject);
74-
unsigned int error_tag = to_attr(attr)->tag;
7575

76-
return snprintf(buf, PAGE_SIZE, "%u\n", mp->m_errortag[error_tag]);
76+
return snprintf(buf, PAGE_SIZE, "%u\n",
77+
READ_ONCE(mp->m_errortag[to_attr(attr)->tag]));
7778
}
7879

7980
static const struct sysfs_ops xfs_errortag_sysfs_ops = {
@@ -134,7 +135,7 @@ xfs_errortag_test(
134135
{
135136
unsigned int randfactor;
136137

137-
randfactor = mp->m_errortag[error_tag];
138+
randfactor = READ_ONCE(mp->m_errortag[error_tag]);
138139
if (!randfactor || get_random_u32_below(randfactor))
139140
return false;
140141

@@ -151,7 +152,7 @@ xfs_errortag_delay(
151152
int line,
152153
unsigned int error_tag)
153154
{
154-
unsigned int delay = mp->m_errortag[error_tag];
155+
unsigned int delay = READ_ONCE(mp->m_errortag[error_tag]);
155156

156157
might_sleep();
157158

@@ -183,15 +184,19 @@ xfs_errortag_add(
183184
break;
184185
}
185186

186-
mp->m_errortag[error_tag] = xfs_errortag_random_default[error_tag];
187+
WRITE_ONCE(mp->m_errortag[error_tag],
188+
xfs_errortag_random_default[error_tag]);
187189
return 0;
188190
}
189191

190192
int
191193
xfs_errortag_clearall(
192194
struct xfs_mount *mp)
193195
{
194-
memset(mp->m_errortag, 0, sizeof(unsigned int) * XFS_ERRTAG_MAX);
196+
unsigned int i;
197+
198+
for (i = 0; i < XFS_ERRTAG_MAX; i++)
199+
WRITE_ONCE(mp->m_errortag[i], 0);
195200
return 0;
196201
}
197202
#endif /* DEBUG */

0 commit comments

Comments
 (0)