[Devel] [PATCH RH7] cifs: use kvcalloc for high-order-page allocations

Vasily Averin vvs at virtuozzo.com
Fri Jun 4 11:52:26 MSK 2021


smb2_unlock_range() and smb2_push_mandatory_locks() allocates
temporal buffer which  consumes 3+ order pages.

WARNING: CPU: 3 PID: 127055 at mm/page_alloc.c:3532 __alloc_pages_nodemask+0x1b1/0x600
    order 4 >= 3, gfp 0xc0d0
    Call Trace:
     [<ffffffff89dbd00f>] dump_stack+0x19/0x1b
     [<ffffffff89db5f86>] panic+0xe8/0x21f
     [<ffffffff8969d6ca>] __warn+0xfa/0x100
     [<ffffffff8969d72f>] warn_slowpath_fmt+0x5f/0x80
     [<ffffffff897e09d1>] __alloc_pages_nodemask+0x1b1/0x600
     [<ffffffff89837018>] alloc_pages_current+0x98/0x110
     [<ffffffff89800298>] kmalloc_order+0x18/0x40
     [<ffffffff898002e6>] kmalloc_order_trace+0x26/0xa0
     [<ffffffff898467c1>] __kmalloc+0x281/0x2a0
     [<ffffffffc0a829aa>] smb2_unlock_range+0xaa/0x340 [cifs]
     [<ffffffffc0a5a221>] cifs_lock+0x3f1/0x1210 [cifs]
     [<ffffffff898d54d5>] vfs_lock_file+0x35/0x60
     [<ffffffff898d5654>] do_lock_file_wait.part.31+0x54/0x100
     [<ffffffff898d6f64>] fcntl_setlk+0x114/0x2d0
     [<ffffffff898878cb>] SyS_fcntl+0x3cb/0x6f0
     [<ffffffff89dd0052>] system_call_fastpath+0x25/0x2a

Let's switch it to kvmalloc to avoid user-triggered disruptive
actions like OOM killer in case of high-order memory shortage.

https://jira.sw.ru/browse/PSBM-130341
Signed-off-by: Vasily Averin <vvs at virtuozzo.com>
---
 fs/cifs/smb2file.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/cifs/smb2file.c b/fs/cifs/smb2file.c
index 885d7c31d76c..ce6681d4ecc0 100644
--- a/fs/cifs/smb2file.c
+++ b/fs/cifs/smb2file.c
@@ -128,7 +128,7 @@ smb2_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock,
 		return -EINVAL;
 
 	max_num = max_buf / sizeof(struct smb2_lock_element);
-	buf = kcalloc(max_num, sizeof(struct smb2_lock_element), GFP_KERNEL);
+	buf = kvcalloc(max_num, sizeof(struct smb2_lock_element), GFP_KERNEL);
 	if (!buf)
 		return -ENOMEM;
 
@@ -197,7 +197,7 @@ smb2_unlock_range(struct cifsFileInfo *cfile, struct file_lock *flock,
 	}
 	up_write(&cinode->lock_sem);
 
-	kfree(buf);
+	kvfree(buf);
 	return rc;
 }
 
@@ -264,7 +264,7 @@ smb2_push_mandatory_locks(struct cifsFileInfo *cfile)
 	}
 
 	max_num = max_buf / sizeof(struct smb2_lock_element);
-	buf = kcalloc(max_num, sizeof(struct smb2_lock_element), GFP_KERNEL);
+	buf = kvcalloc(max_num, sizeof(struct smb2_lock_element), GFP_KERNEL);
 	if (!buf) {
 		free_xid(xid);
 		return -ENOMEM;
@@ -276,7 +276,7 @@ smb2_push_mandatory_locks(struct cifsFileInfo *cfile)
 			rc = stored_rc;
 	}
 
-	kfree(buf);
+	kvfree(buf);
 	free_xid(xid);
 	return rc;
 }
-- 
2.25.1



More information about the Devel mailing list