Skip to contentSkip to conversation

smb3: Miscellaneous fixes

PATCH New David Howells 1 participant 3 messages Feb 27, 2023

Subsystems (3)
lore
Share & tools
lore

David Howells

author maintainer
#0 lore raw

cover smb3: Miscellaneous fixes

Hi Steve,

Here are a couple more fix patches for you.

David

David Howells (2):
cifs: Fix cifs_write_back_from_locked_folio()
iov: Fix netfs_extract_user_to_sg()

 fs/cifs/file.c      | 1 +
 fs/netfs/iterator.c | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
author maintainer
#1 lore raw

PATCH 1/2 cifs: Fix cifs_write_back_from_locked_folio()

cifs_write_back_from_locked_folio() should return the number of bytes read, but returns the result of ->async_writev(), which will be 0 on success. As it happens, this doesn't prevent cifs_writepages_region() from working as it will then examine and ignore the pages that are no longer dirty rather than just skipping over them.

Fixes d08089f649a0 ("cifs: Change the I/O paths to use an iterator rather than a page list")
cc Steve French <[email protected]>
cc Shyam Prasad N <[email protected]>
cc Rohith Surabattula <[email protected]>
cc Tom Talpey <[email protected]>
cc Jeff Layton <[email protected]>
---
 fs/cifs/file.c | 1 +
 1 file changed, 1 insertion(+)
fs/cifs/file.c +1 -0
index ebfcaae8c437..f8cc68ce9d8a 100644
@@ -2839,6 +2839,7 @@ static ssize_t cifs_write_back_from_locked_folio(struct address_space *mapping,
 	free_xid(xid);
 	if (rc == 0) {
 		wbc->nr_to_write = count;
+		rc = len;
 	} else if (is_retryable_error(rc)) {
 		cifs_pages_write_redirty(inode, start, len);
 	} else {
author maintainer
#2 lore raw

PATCH 2/2 iov: Fix netfs_extract_user_to_sg()

In reply to David Howells

Fix the loop check in netfs_extract_user_to_sg() for extraction from user-backed iterators to do the body if npages > 0, not if npages < 0 (which it can never be).

This isn't currently used by cifs, which only ever extracts data from BVEC, KVEC and XARRAY iterators at this level, user-backed iterators having being decanted into BVEC iterators at a higher level to accommodate the work being done in a kernel thread.

Found by smatch:
fs/netfs/iterator.c:139 netfs_extract_user_to_sg() warn: unsigned 'npages' is never less than zero.

Fixes 018584697533 ("netfs: Add a function to extract an iterator into a scatterlist")
cc Steve French <[email protected]>
cc Jeff Layton <[email protected]>
---
 fs/netfs/iterator.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/netfs/iterator.c +1 -1
index f00d43b8ac0a..e9a45dea748a 100644
@@ -134,7 +134,7 @@ static ssize_t netfs_extract_user_to_sg(struct iov_iter *iter,
 		npages = DIV_ROUND_UP(off + len, PAGE_SIZE);
 		sg_max -= npages;
 
-		for (; npages < 0; npages--) {
+		for (; npages > 0; npages--) {
 			struct page *page = *pages;
 			size_t seg = min_t(size_t, PAGE_SIZE - off, len);