Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Christoph Hellwig and committed by
Carlos Maiolino
4d8f4246 e2d62bfd

+14 -9
+14 -9
fs/xfs/xfs_error.c
··· 50 50 { 51 51 struct xfs_mount *mp = to_mp(kobject); 52 52 unsigned int error_tag = to_attr(attr)->tag; 53 + unsigned int val; 53 54 int ret; 54 55 55 56 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]; 58 58 } else { 59 - ret = kstrtouint(buf, 0, &mp->m_errortag[error_tag]); 59 + ret = kstrtouint(buf, 0, &val); 60 60 if (ret) 61 61 return ret; 62 62 } 63 63 64 + WRITE_ONCE(mp->m_errortag[error_tag], val); 64 65 return count; 65 66 } 66 67 ··· 72 71 char *buf) 73 72 { 74 73 struct xfs_mount *mp = to_mp(kobject); 75 - unsigned int error_tag = to_attr(attr)->tag; 76 74 77 - return snprintf(buf, PAGE_SIZE, "%u\n", mp->m_errortag[error_tag]); 75 + return snprintf(buf, PAGE_SIZE, "%u\n", 76 + READ_ONCE(mp->m_errortag[to_attr(attr)->tag])); 78 77 } 79 78 80 79 static const struct sysfs_ops xfs_errortag_sysfs_ops = { ··· 135 134 { 136 135 unsigned int randfactor; 137 136 138 - randfactor = mp->m_errortag[error_tag]; 137 + randfactor = READ_ONCE(mp->m_errortag[error_tag]); 139 138 if (!randfactor || get_random_u32_below(randfactor)) 140 139 return false; 141 140 ··· 152 151 int line, 153 152 unsigned int error_tag) 154 153 { 155 - unsigned int delay = mp->m_errortag[error_tag]; 154 + unsigned int delay = READ_ONCE(mp->m_errortag[error_tag]); 156 155 157 156 might_sleep(); 158 157 ··· 184 183 break; 185 184 } 186 185 187 - mp->m_errortag[error_tag] = xfs_errortag_random_default[error_tag]; 186 + WRITE_ONCE(mp->m_errortag[error_tag], 187 + xfs_errortag_random_default[error_tag]); 188 188 return 0; 189 189 } 190 190 ··· 193 191 xfs_errortag_clearall( 194 192 struct xfs_mount *mp) 195 193 { 196 - memset(mp->m_errortag, 0, sizeof(unsigned int) * XFS_ERRTAG_MAX); 194 + unsigned int i; 195 + 196 + for (i = 0; i < XFS_ERRTAG_MAX; i++) 197 + WRITE_ONCE(mp->m_errortag[i], 0); 197 198 return 0; 198 199 } 199 200 #endif /* DEBUG */