[Devel] [PATCH RHEL7 COMMIT] ms/NFSv4: Fix up RCU annotations for struct nfs_netns_client
Vasily Averin
vvs at virtuozzo.com
Tue Jan 25 12:38:47 MSK 2022
The commit is pushed to "branch-rh7-3.10.0-1160.53.1.vz7.185.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1160.53.1.vz7.185.2
------>
commit 6e2dcbfe6bce56183b3303f914d8ce251839d640
Author: Trond Myklebust <trond.myklebust at hammerspace.com>
Date: Tue Jan 25 12:38:47 2022 +0300
ms/NFSv4: Fix up RCU annotations for struct nfs_netns_client
The identifier is read as an RCU protected string. Its value may
be changed during the lifetime of the network namespace by writing
a new string into the sysfs pseudofile (at which point, we free the
old string only after a call to synchronize_rcu()).
Signed-off-by: Trond Myklebust <trond.myklebust at hammerspace.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker at Netapp.com>
(cherry-picked from ms commit 094eca37193c516106ef8ed7f60ed058ed9fc458)
https://jira.sw.ru/browse/PSBM-137154
Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
fs/nfs/sysfs.c | 11 ++++++++---
fs/nfs/sysfs.h | 2 +-
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/fs/nfs/sysfs.c b/fs/nfs/sysfs.c
index c489496..8cb7075 100644
--- a/fs/nfs/sysfs.c
+++ b/fs/nfs/sysfs.c
@@ -79,7 +79,12 @@ static ssize_t nfs_netns_identifier_show(struct kobject *kobj,
struct nfs_netns_client *c = container_of(kobj,
struct nfs_netns_client,
kobject);
- return scnprintf(buf, PAGE_SIZE, "%s\n", c->identifier);
+ ssize_t ret;
+
+ rcu_read_lock();
+ ret = scnprintf(buf, PAGE_SIZE, "%s\n", rcu_dereference(c->identifier));
+ rcu_read_unlock();
+ return ret;
}
/* Strip trailing '\n' */
@@ -107,7 +112,7 @@ static ssize_t nfs_netns_identifier_store(struct kobject *kobj,
p = kmemdup_nul(buf, len, GFP_KERNEL);
if (!p)
return -ENOMEM;
- old = xchg(&c->identifier, p);
+ old = rcu_dereference_protected(xchg(&c->identifier, (char __rcu *)p), 1);
if (old) {
synchronize_rcu();
kfree(old);
@@ -121,7 +126,7 @@ static void nfs_netns_client_release(struct kobject *kobj)
struct nfs_netns_client,
kobject);
- kfree(c->identifier);
+ kfree(rcu_dereference_raw(c->identifier));
kfree(c);
}
diff --git a/fs/nfs/sysfs.h b/fs/nfs/sysfs.h
index f1b2741..b1408e6 100644
--- a/fs/nfs/sysfs.h
+++ b/fs/nfs/sysfs.h
@@ -11,7 +11,7 @@
struct nfs_netns_client {
struct kobject kobject;
struct net *net;
- const char *identifier;
+ const char __rcu *identifier;
};
extern struct kobject *nfs_client_kobj;
More information about the Devel
mailing list