Skip to contentSkip to conversation

NFS: Fix a bug in nfs_fscache_release_page()

PATCH In review Trond Myklebust 4 participants 15 messages Feb 5, 2010 – Feb 9, 2010 3 messages not in the archive

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

PATCH 1/2 NFS: Fix a bug in nfs_fscache_release_page()

Not having an fscache cookie is perfectly valid if the user didn't mount with the fscache option.

This patch fixes http://bugzilla.kernel.org/show_bug.cgi?id=15234

---
 fs/nfs/fscache.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
fs/nfs/fscache.c +3 -3
index fa58800..534adb8 100644
@@ -355,11 +355,11 @@ void nfs_fscache_reset_inode_cookie(struct inode *inode)
 int nfs_fscache_release_page(struct page *page, gfp_t gfp)
 {
 	struct nfs_inode *nfsi = NFS_I(page->mapping->host);
-	struct fscache_cookie *cookie = nfsi->fscache;
-
-	BUG_ON(!cookie);
 
 	if (PageFsCache(page)) {
+		struct fscache_cookie *cookie = nfsi->fscache;
+
+		BUG_ON(!cookie);
 		dfprintk(FSCACHE, "NFS: fscache releasepage (0x%p/0x%p/0x%p)\n",
 			 cookie, page, nfsi);
 
Signature · 1 line
1.6.6
#1 lore raw

PATCH 2/2 NFS: Fix the mapping of the NFSERR_SERVERFAULT error

It was recently pointed out that the NFSERR_SERVERFAULT error, which is designed to inform the user of a serious internal error on the server, was being mapped to an error value that is internal to the kernel.

This patch maps it to the error EREMOTEIO, which is exported to userland through errno.h.

---
 fs/nfs/mount_clnt.c |    2 +-
 fs/nfs/nfs2xdr.c    |    2 +-
 fs/nfs/nfs4xdr.c    |    6 +++---
 3 files changed, 5 insertions(+), 5 deletions(-)
fs/nfs/mount_clnt.c +1 -1
index 0adefc4..59047f8 100644
@@ -120,7 +120,7 @@ static struct {
 	{ .status = MNT3ERR_INVAL,		.errno = -EINVAL,	},
 	{ .status = MNT3ERR_NAMETOOLONG,	.errno = -ENAMETOOLONG,	},
 	{ .status = MNT3ERR_NOTSUPP,		.errno = -ENOTSUPP,	},
-	{ .status = MNT3ERR_SERVERFAULT,	.errno = -ESERVERFAULT,	},
+	{ .status = MNT3ERR_SERVERFAULT,	.errno = -EREMOTEIO,	},
 };
 
 struct mountres {
fs/nfs/nfs2xdr.c +1 -1
index 5e078b2..7bc2da8 100644
@@ -699,7 +699,7 @@ static struct {
 	{ NFSERR_BAD_COOKIE,	-EBADCOOKIE	},
 	{ NFSERR_NOTSUPP,	-ENOTSUPP	},
 	{ NFSERR_TOOSMALL,	-ETOOSMALL	},
-	{ NFSERR_SERVERFAULT,	-ESERVERFAULT	},
+	{ NFSERR_SERVERFAULT,	-EREMOTEIO	},
 	{ NFSERR_BADTYPE,	-EBADTYPE	},
 	{ NFSERR_JUKEBOX,	-EJUKEBOX	},
 	{ -1,			-EIO		}
fs/nfs/nfs4xdr.c +3 -3
index e437fd6..5cd5184 100644
@@ -4631,7 +4631,7 @@ static int decode_sequence(struct xdr_stream *xdr,
 	 * If the server returns different values for sessionID, slotID or
 	 * sequence number, the server is looney tunes.
 	 */
-	status = -ESERVERFAULT;
+	status = -EREMOTEIO;
 
 	if (memcmp(id.data, res->sr_session->sess_id.data,
 		   NFS4_MAX_SESSIONID_LEN)) {
@@ -5774,7 +5774,7 @@ static struct {
 	{ NFS4ERR_BAD_COOKIE,	-EBADCOOKIE	},
 	{ NFS4ERR_NOTSUPP,	-ENOTSUPP	},
 	{ NFS4ERR_TOOSMALL,	-ETOOSMALL	},
-	{ NFS4ERR_SERVERFAULT,	-ESERVERFAULT	},
+	{ NFS4ERR_SERVERFAULT,	-EREMOTEIO	},
 	{ NFS4ERR_BADTYPE,	-EBADTYPE	},
 	{ NFS4ERR_LOCKED,	-EAGAIN		},
 	{ NFS4ERR_SYMLINK,	-ELOOP		},
@@ -5801,7 +5801,7 @@ nfs4_stat_to_errno(int stat)
 	}
 	if (stat <= 10000 || stat > 10100) {
 		/* The server is looney tunes. */
-		return -ESERVERFAULT;
+		return -EREMOTEIO;
 	}
 	/* If we cannot translate the error, the recovery routines should
 	 * handle it.
Signature · 1 line
1.6.6
#2 lore raw

Re: [PATCH 2/2] NFS: Fix the mapping of the NFSERR_SERVERFAULT error

Quoted 20 lines · Trond Myklebust

It was recently pointed out that the NFSERR_SERVERFAULT error, which is designed to inform the user of a serious internal error on the server, was being mapped to an error value that is internal to the kernel.

This patch maps it to the error EREMOTEIO, which is exported to userland through errno.h.

---
  fs/nfs/mount_clnt.c |    2 +-
  fs/nfs/nfs2xdr.c    |    2 +-
  fs/nfs/nfs4xdr.c    |    6 +++---
  3 files changed, 5 insertions(+), 5 deletions(-)
fs/nfs/mount_clnt.c +0 -0
index 0adefc4..59047f8 100644

fs/nfs/mount_clnt.c static struct { · line 126

Quoted 8 lines
fs/nfs/mount_clnt.c +1 -1
@@ -120,7 +120,7 @@ static struct {
  	{ .status = MNT3ERR_INVAL,		.errno = -EINVAL,	},
  	{ .status = MNT3ERR_NAMETOOLONG,	.errno = -ENAMETOOLONG,	},
  	{ .status = MNT3ERR_NOTSUPP,		.errno = -ENOTSUPP,	},
-	{ .status = MNT3ERR_SERVERFAULT,	.errno = -ESERVERFAULT,	},
+	{ .status = MNT3ERR_SERVERFAULT,	.errno = -EREMOTEIO,	},
  };
 
  struct mountres {

The decode_status() and decode_fhs_status() functions return -EACCES if they don't recognize the server's error code. Should they return -EREMOTEIO instead?

Otherwise, looks good.

Quoted 44 lines
fs/nfs/nfs2xdr.c +1 -1
index 5e078b2..7bc2da8 100644
@@ -699,7 +699,7 @@ static struct {
  	{ NFSERR_BAD_COOKIE,	-EBADCOOKIE	},
  	{ NFSERR_NOTSUPP,	-ENOTSUPP	},
  	{ NFSERR_TOOSMALL,	-ETOOSMALL	},
-	{ NFSERR_SERVERFAULT,	-ESERVERFAULT	},
+	{ NFSERR_SERVERFAULT,	-EREMOTEIO	},
  	{ NFSERR_BADTYPE,	-EBADTYPE	},
  	{ NFSERR_JUKEBOX,	-EJUKEBOX	},
  	{ -1,			-EIO		}
fs/nfs/nfs4xdr.c +3 -3
index e437fd6..5cd5184 100644
@@ -4631,7 +4631,7 @@ static int decode_sequence(struct xdr_stream *xdr,
  	 * If the server returns different values for sessionID, slotID or
  	 * sequence number, the server is looney tunes.
  	 */
-	status = -ESERVERFAULT;
+	status = -EREMOTEIO;
 
  	if (memcmp(id.data, res->sr_session->sess_id.data,
  		   NFS4_MAX_SESSIONID_LEN)) {
@@ -5774,7 +5774,7 @@ static struct {
  	{ NFS4ERR_BAD_COOKIE,	-EBADCOOKIE	},
  	{ NFS4ERR_NOTSUPP,	-ENOTSUPP	},
  	{ NFS4ERR_TOOSMALL,	-ETOOSMALL	},
-	{ NFS4ERR_SERVERFAULT,	-ESERVERFAULT	},
+	{ NFS4ERR_SERVERFAULT,	-EREMOTEIO	},
  	{ NFS4ERR_BADTYPE,	-EBADTYPE	},
  	{ NFS4ERR_LOCKED,	-EAGAIN		},
  	{ NFS4ERR_SYMLINK,	-ELOOP		},
@@ -5801,7 +5801,7 @@ nfs4_stat_to_errno(int stat)
  	}
  	if (stat<= 10000 || stat>  10100) {
  		/* The server is looney tunes. */
-		return -ESERVERFAULT;
+		return -EREMOTEIO;
  	}
  	/* If we cannot translate the error, the recovery routines should
  	 * handle it.
Signature · 1 line
chuck[dot]lever[at]oracle[dot]com
#3 lore raw

Re: [PATCH 2/2] NFS: Fix the mapping of the NFSERR_SERVERFAULT error

Quoted 28 lines · Chuck Lever
Quoted 27 lines · Trond Myklebust

It was recently pointed out that the NFSERR_SERVERFAULT error, which is designed to inform the user of a serious internal error on the server, was being mapped to an error value that is internal to the kernel.

This patch maps it to the error EREMOTEIO, which is exported to userland through errno.h.

---
  fs/nfs/mount_clnt.c |    2 +-
  fs/nfs/nfs2xdr.c    |    2 +-
  fs/nfs/nfs4xdr.c    |    6 +++---
  3 files changed, 5 insertions(+), 5 deletions(-)
fs/nfs/mount_clnt.c +1 -1
index 0adefc4..59047f8 100644
@@ -120,7 +120,7 @@ static struct {
  	{ .status = MNT3ERR_INVAL,		.errno = -EINVAL,	},
  	{ .status = MNT3ERR_NAMETOOLONG,	.errno = -ENAMETOOLONG,	},
  	{ .status = MNT3ERR_NOTSUPP,		.errno = -ENOTSUPP,	},
-	{ .status = MNT3ERR_SERVERFAULT,	.errno = -ESERVERFAULT,	},
+	{ .status = MNT3ERR_SERVERFAULT,	.errno = -EREMOTEIO,	},
  };
 
Quoted 5 lines

fs/nfs/mount_clnt.c static struct { · line 126

Quoted 1 line
fs/nfs/mount_clnt.c +0 -0
  struct mountres {

The decode_status() and decode_fhs_status() functions return -EACCES if they don't recognize the server's error code. Should they return -EREMOTEIO instead?

It might possibly be a bit more enlightening to the user, but that would be a separate patch. I wouldn't see that fix as being particularly
critical: EACCES is a valid error code that can be returned to userland.

Cheers
Trond

#4 lore raw
In reply to Trond Myklebust
Quoted 20 lines · Trond Myklebust

Not having an fscache cookie is perfectly valid if the user didn't mount with the fscache option.

This patch fixes http://bugzilla.kernel.org/show_bug.cgi?id=15234

---
 fs/nfs/fscache.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
fs/nfs/fscache.c +0 -1
index fa58800..534adb8 100644
@@ -355,11 +355,11 @@ void nfs_fscache_reset_inode_cookie(struct inode *inode)
 int nfs_fscache_release_page(struct page *page, gfp_t gfp)
 {
 	struct nfs_inode *nfsi = NFS_I(page->mapping->host);
-	struct fscache_cookie *cookie = nfsi->fscache;

fs/nfs/fscache.c void nfs_fscache_reset_inode_cookie(struct inode *inode) · line 365

Quoted 10 lines
fs/nfs/fscache.c +3 -2
-
-	BUG_ON(!cookie);
 
 	if (PageFsCache(page)) {
+		struct fscache_cookie *cookie = nfsi->fscache;
+
+		BUG_ON(!cookie);
 		dfprintk(FSCACHE, "NFS: fscache releasepage (0x%p/0x%p/0x%p)\n",
 			 cookie, page, nfsi);
 

There are only two callers for nfs_fscache_release_page() - nfs_release_page() and nfs_migrate_page(). nfs_migrate_page already does this:

       if (PageFsCache(page))
                nfs_fscache_release_page(page, GFP_KERNEL);

and the assumption in nfs_release_page() is that the page should have either PG_private set or PG_fscache set and nfs_fscache_release_page gets called only if PG_private is not set.

I think the idea is that nfs_fscache_release_page should not get called if fsc option is not used. So it appears to me this patch is fixing the symptom not the actual issue. Perhaps, this the assumption in nfs_release_page is wrong or the PageFsCache() check should be moved to nfs_release_page?

Thanks,

Signature · 1 line
Suresh Jayaraman
#5 lore raw
Quoted 36 lines · Suresh Jayaraman
Quoted 20 lines · Trond Myklebust

Not having an fscache cookie is perfectly valid if the user didn't mount with the fscache option.

This patch fixes http://bugzilla.kernel.org/show_bug.cgi?id=15234

---
 fs/nfs/fscache.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
fs/nfs/fscache.c +0 -1
index fa58800..534adb8 100644
@@ -355,11 +355,11 @@ void nfs_fscache_reset_inode_cookie(struct inode *inode)
 int nfs_fscache_release_page(struct page *page, gfp_t gfp)
 {
 	struct nfs_inode *nfsi = NFS_I(page->mapping->host);
-	struct fscache_cookie *cookie = nfsi->fscache;

fs/nfs/fscache.c void nfs_fscache_reset_inode_cookie(struct inode *inode) · line 365

Quoted 10 lines
fs/nfs/fscache.c +3 -2
-
-	BUG_ON(!cookie);
 
 	if (PageFsCache(page)) {
+		struct fscache_cookie *cookie = nfsi->fscache;
+
+		BUG_ON(!cookie);
 		dfprintk(FSCACHE, "NFS: fscache releasepage (0x%p/0x%p/0x%p)\n",
 			 cookie, page, nfsi);
 

There are only two callers for nfs_fscache_release_page() - nfs_release_page() and nfs_migrate_page(). nfs_migrate_page already does this:

Quoted 6 lines
       if (PageFsCache(page))
                nfs_fscache_release_page(page, GFP_KERNEL);

and the assumption in nfs_release_page() is that the page should have either PG_private set or PG_fscache set and nfs_fscache_release_page gets called only if PG_private is not set.

...or if it gets cleared.

Quoted 5 lines

I think the idea is that nfs_fscache_release_page should not get called if fsc option is not used. So it appears to me this patch is fixing the symptom not the actual issue. Perhaps, this the assumption in nfs_release_page is wrong or the PageFsCache() check should be moved to nfs_release_page?

No. We should rather get rid of the redundant check for PageFsCache() in nfs_migrate_page. PageFsCache() is particular to fscache, so the test belongs in the fscache code.

Trond

#6 lore raw
Quoted 5 lines · Trond Myklebust
Quoted 4 lines · Suresh Jayaraman

There are only two callers for nfs_fscache_release_page() - nfs_release_page() and nfs_migrate_page(). nfs_migrate_page already does this:

Quoted 8 lines
Quoted 6 lines
       if (PageFsCache(page))
                nfs_fscache_release_page(page, GFP_KERNEL);

and the assumption in nfs_release_page() is that the page should have either PG_private set or PG_fscache set and nfs_fscache_release_page gets called only if PG_private is not set.

...or if it gets cleared.

To be more precise, even before we put call to nfs_wb_page() in nfs_release_page(), it was possible for the PG_private bit to be set when doing the test in shrink_page_list(), but for an outstanding commit operation to complete before the second test in nfs_release_page.

In this case, nfs_fscache_release_page would get called with neither PG_private nor PG_fscache being set, and the Oops could occur.

Quoted 9 lines
Quoted 5 lines

I think the idea is that nfs_fscache_release_page should not get called if fsc option is not used. So it appears to me this patch is fixing the symptom not the actual issue. Perhaps, this the assumption in nfs_release_page is wrong or the PageFsCache() check should be moved to nfs_release_page?

No. We should rather get rid of the redundant check for PageFsCache() in nfs_migrate_page. PageFsCache() is particular to fscache, so the test belongs in the fscache code.

I've added a cleanup patch (which will not go to [email protected]) to do this.

Trond

#7 lore raw
Quoted 9 lines · Trond Myklebust
Quoted 8 lines · Trond Myklebust
Quoted 7 lines · Suresh Jayaraman

There are only two callers for nfs_fscache_release_page() - nfs_release_page() and nfs_migrate_page(). nfs_migrate_page already does this:

       if (PageFsCache(page))
                nfs_fscache_release_page(page, GFP_KERNEL);
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

and the assumption in nfs_release_page() is that the page should have either PG_private set or PG_fscache set and nfs_fscache_release_page gets called only if PG_private is not set.

...or if it gets cleared.

To be more precise, even before we put call to nfs_wb_page() in nfs_release_page(), it was possible for the PG_private bit to be set

Yes, I have seen a similar bug report before we added nfs_wb_page on a 2.6.32 kernel too.

Quoted 6 lines

when doing the test in shrink_page_list(), but for an outstanding commit operation to complete before the second test in nfs_release_page.

In this case, nfs_fscache_release_page would get called with neither PG_private nor PG_fscache being set, and the Oops could occur.

We seem to ensure that we're holding a page lock in try_to_release_page. Even if the outstanding commit is complete by the time we are in nfs_releage_page, page flags should not have been modified, right?

Quoted 9 lines
Quoted 9 lines
Quoted 5 lines

I think the idea is that nfs_fscache_release_page should not get called if fsc option is not used. So it appears to me this patch is fixing the symptom not the actual issue. Perhaps, this the assumption in nfs_release_page is wrong or the PageFsCache() check should be moved to nfs_release_page?

No. We should rather get rid of the redundant check for PageFsCache() in nfs_migrate_page. PageFsCache() is particular to fscache, so the test belongs in the fscache code.

yes, make sense.

Thanks,

Signature · 1 line
Suresh Jayaraman
#8 lore raw
Quoted 3 lines · Suresh Jayaraman

We seem to ensure that we're holding a page lock in try_to_release_page. Even if the outstanding commit is complete by the time we are in nfs_releage_page, page flags should not have been modified, right?

No. PG_private may be cleared while another process is holding the page lock (just like PG_writeback may).

Once cleared, PG_private cannot be set again without grabbing the page lock.

Trond

#9 lore raw
Quoted 11 lines · Trond Myklebust
Quoted 3 lines · Suresh Jayaraman

We seem to ensure that we're holding a page lock in try_to_release_page. Even if the outstanding commit is complete by the time we are in nfs_releage_page, page flags should not have been modified, right?

No. PG_private may be cleared while another process is holding the page lock (just like PG_writeback may).

Once cleared, PG_private cannot be set again without grabbing the page lock.

Ah, ok. I got stuck there. Thanks for the clarifying.

Signature · 1 line
Suresh Jayaraman
#10 lore raw

cover Fix for the nfs_release_page() bug

In reply to Trond Myklebust

Here are the two proposed patches. The first is needed for both mainline and [email protected]. The second, being a cleanup, will be send to mainline only.

Cheers
Trond

---

Trond Myklebust (2):
NFS: Remove a redundant check for PageFsCache in nfs_migrate_page()
NFS: Fix a bug in nfs_fscache_release_page()

 fs/nfs/fscache.c |    9 ++++-----
 fs/nfs/write.c   |    3 +--
 2 files changed, 5 insertions(+), 7 deletions(-)
Signature · 1 line
Signature

A message that is not in the archive (sent off-list or not yet received): 20100208145942.17581.81775.stgit-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]

#12 lore raw

PATCH 1/2 NFS: Fix a bug in nfs_fscache_release_page()

Not having an fscache cookie is perfectly valid if the user didn't mount with the fscache option.

This patch fixes http://bugzilla.kernel.org/show_bug.cgi?id=15234

---

 fs/nfs/fscache.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)
fs/nfs/fscache.c +4 -5
index fa58800..237874f 100644
@@ -354,12 +354,11 @@ void nfs_fscache_reset_inode_cookie(struct inode *inode)
  */
 int nfs_fscache_release_page(struct page *page, gfp_t gfp)
 {
-	struct nfs_inode *nfsi = NFS_I(page->mapping->host);
-	struct fscache_cookie *cookie = nfsi->fscache;
-
-	BUG_ON(!cookie);
-
 	if (PageFsCache(page)) {
+		struct nfs_inode *nfsi = NFS_I(page->mapping->host);
+		struct fscache_cookie *cookie = nfsi->fscache;
+
+		BUG_ON(!cookie);
 		dfprintk(FSCACHE, "NFS: fscache releasepage (0x%p/0x%p/0x%p)\n",
 			 cookie, page, nfsi);
 
#13 lore raw

PATCH 2/2 NFS: Remove a redundant check for PageFsCache in nfs_migrate_page()

In reply to a message not in the archive

---

 fs/nfs/write.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
fs/nfs/write.c +1 -2
index 7b54b8b..d63d964 100644
@@ -1598,8 +1598,7 @@ int nfs_migrate_page(struct address_space *mapping, struct page *newpage,
 	struct nfs_page *req;
 	int ret;
 
-	if (PageFsCache(page))
-		nfs_fscache_release_page(page, GFP_KERNEL);
+	nfs_fscache_release_page(page, GFP_KERNEL);
 
 	req = nfs_find_and_lock_request(page);
 	ret = PTR_ERR(req);

A message that is not in the archive (sent off-list or not yet received): 20100208145942.17581.83842.stgit-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]

A message that is not in the archive (sent off-list or not yet received): 20100208145942.17581.12206.stgit-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]