Skip to contentSkip to conversation

shm: Fix unlikely() test of info->seals to test only for WRITE and GROW

PATCH Applied Steven Rostedt (VMware) 2 participants 2 messages Feb 3, 2017 – Feb 4, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 shm: Fix unlikely() test of info->seals to test only for WRITE and GROW

From: "Steven Rostedt (VMware)" <[email protected]>

Running my likely/unlikely profiler, I discovered that the test in shmem_write_begin() that tests for info->seals as unlikely, is always incorrect. This is because shmem_get_inode() sets info->seals to have F_SEAL_SEAL set by default, and it is unlikely to be cleared when shmem_write_begin() is called. Thus, the if statement is very likely.

But as the if statement block only cares about F_SEAL_WRITE and F_SEAL_GROW, change the test to only test those two bits.

---
 mm/shmem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/shmem.c +1 -1
index bb53285..ef4cdbb 100644
@@ -2194,7 +2194,7 @@ shmem_write_begin(struct file *file, struct address_space *mapping,
 	pgoff_t index = pos >> PAGE_SHIFT;
 
 	/* i_mutex is held by caller */
-	if (unlikely(info->seals)) {
+	if (unlikely(info->seals & (F_SEAL_WRITE | F_SEAL_GROW))) {
 		if (info->seals & F_SEAL_WRITE)
 			return -EPERM;
 		if ((info->seals & F_SEAL_GROW) && pos + len > inode->i_size)
Signature · 1 line
2.9.3
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Steven Rostedt (VMware)

From: "Steven Rostedt (VMware)" <[email protected]>

Running my likely/unlikely profiler, I discovered that the test in shmem_write_begin() that tests for info->seals as unlikely, is always incorrect. This is because shmem_get_inode() sets info->seals to have F_SEAL_SEAL set by default, and it is unlikely to be cleared when shmem_write_begin() is called. Thus, the if statement is very likely.

Quoted 4 lines

But as the if statement block only cares about F_SEAL_WRITE and F_SEAL_GROW, change the test to only test those two bits.

Quoted 19 lines
---
 mm/shmem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/shmem.c +1 -1
index bb53285..ef4cdbb 100644
@@ -2194,7 +2194,7 @@ shmem_write_begin(struct file *file, struct address_space *mapping,
 	pgoff_t index = pos >> PAGE_SHIFT;
 
 	/* i_mutex is held by caller */
-	if (unlikely(info->seals)) {
+	if (unlikely(info->seals & (F_SEAL_WRITE | F_SEAL_GROW))) {
 		if (info->seals & F_SEAL_WRITE)
 			return -EPERM;
 		if ((info->seals & F_SEAL_GROW) && pos + len > inode->i_size)
Signature · 1 line
2.9.3