2012-11-30 18:09:55

by Andy Adamson

[permalink] [raw]
Subject: [PATCH 1/1] SUNRPC: release clear_bit memory barrier

From: Andy Adamson <[email protected]>

Signed-off-by: Andy Adamson <[email protected]>
---
A cleanup patch.

net/sunrpc/auth.c | 1 +
net/sunrpc/auth_gss/auth_gss.c | 1 +
2 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c
index b5c067b..8b76753 100644
--- a/net/sunrpc/auth.c
+++ b/net/sunrpc/auth.c
@@ -225,6 +225,7 @@ rpcauth_unhash_cred_locked(struct rpc_cred *cred)
hlist_del_rcu(&cred->cr_hash);
smp_mb__before_clear_bit();
clear_bit(RPCAUTH_CRED_HASHED, &cred->cr_flags);
+ smp_mb__after_clear_bit();
}

static int
diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c
index 909dc0c..92a7d6d 100644
--- a/net/sunrpc/auth_gss/auth_gss.c
+++ b/net/sunrpc/auth_gss/auth_gss.c
@@ -126,6 +126,7 @@ gss_cred_set_ctx(struct rpc_cred *cred, struct gss_cl_ctx *ctx)
set_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags);
smp_mb__before_clear_bit();
clear_bit(RPCAUTH_CRED_NEW, &cred->cr_flags);
+ smp_mb__after_clear_bit();
}

static const void *
--
1.7.7.6



2012-12-10 20:02:25

by Myklebust, Trond

[permalink] [raw]
Subject: Re: [PATCH 1/1] SUNRPC: release clear_bit memory barrier

T24gRnJpLCAyMDEyLTExLTMwIGF0IDEzOjA5IC0wNTAwLCBhbmRyb3NAbmV0YXBwLmNvbSB3cm90
ZToNCj4gRnJvbTogQW5keSBBZGFtc29uIDxhbmRyb3NAbmV0YXBwLmNvbT4NCj4gDQo+IFNpZ25l
ZC1vZmYtYnk6IEFuZHkgQWRhbXNvbiA8YW5kcm9zQG5ldGFwcC5jb20+DQo+IC0tLQ0KPiBBIGNs
ZWFudXAgcGF0Y2guDQo+IA0KPi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ZXIgYm90aCBvciBub3RoaW5nLiBJdCBzYXlzIHRoYXQgaWYgeW91IGNhbGwNCnNt
cF9tYl9fYWZ0ZXJfY2xlYXJfYml0KCksIHRoZW4gdGhlIGNsZWFyX2JpdCgpIHdpbGwgYmUgc3Ry
b25nbHkgb3JkZXJlZA0Kdy5yLnQuIGZ1dHVyZSBtZW1vcnkgb3BlcmF0aW9ucyBkb25lIGJ5IHRo
aXMgdGhyZWFkLiBNeSBxdWVzdGlvbiBpcyB3aHkNCndlIG5lZWQgdGhpcyBzdHJvbmcgb3JkZXJp
bmc/DQoNClRoZSBjdXJyZW50IGNvZGUgYWxyZWFkeSBvcmRlcnMgdGhlIGhsaXN0X2RlbF9yY3Uo
KSBhbmQgdGhlDQpzZXRfYml0KFJQQ0FVVEhfQ1JFRF9VUFRPREFURSkgdy5yLnQuIHRoZSBjbGVh
cl9iaXQoKSwgc28gYW55IHRocmVhZA0KdGhhdCBzZWVzIHRoZSBSUENBVVRIX0NSRURfSEFTSEVE
L1JQQ0FVVEhfQ1JFRF9ORVcgYml0cyBjbGVhcmVkIHdpbGwNCmFsc28gc2VlIHRoZSBsaXN0IHJl
bW92YWwvdXB0b2RhdGUgY3JlZC4NCg0KLS0gDQpUcm9uZCBNeWtsZWJ1c3QNCkxpbnV4IE5GUyBj
bGllbnQgbWFpbnRhaW5lcg0KDQpOZXRBcHANClRyb25kLk15a2xlYnVzdEBuZXRhcHAuY29tDQp3
d3cubmV0YXBwLmNvbQ0K

2012-12-11 15:33:15

by Adamson, Andy

[permalink] [raw]
Subject: Re: [PATCH 1/1] SUNRPC: release clear_bit memory barrier


On Dec 10, 2012, at 3:02 PM, "Myklebust, Trond" <[email protected]> wrote:

> On Fri, 2012-11-30 at 13:09 -0500, [email protected] wrote:
>> From: Andy Adamson <[email protected]>
>>
>> Signed-off-by: Andy Adamson <[email protected]>
>> ---
>> A cleanup patch.
>>
>> net/sunrpc/auth.c | 1 +
>> net/sunrpc/auth_gss/auth_gss.c | 1 +
>> 2 files changed, 2 insertions(+), 0 deletions(-)
>>
>> diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c
>> index b5c067b..8b76753 100644
>> --- a/net/sunrpc/auth.c
>> +++ b/net/sunrpc/auth.c
>> @@ -225,6 +225,7 @@ rpcauth_unhash_cred_locked(struct rpc_cred *cred)
>> hlist_del_rcu(&cred->cr_hash);
>> smp_mb__before_clear_bit();
>> clear_bit(RPCAUTH_CRED_HASHED, &cred->cr_flags);
>> + smp_mb__after_clear_bit();
>> }
>>
>> static int
>> diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c
>> index 909dc0c..92a7d6d 100644
>> --- a/net/sunrpc/auth_gss/auth_gss.c
>> +++ b/net/sunrpc/auth_gss/auth_gss.c
>> @@ -126,6 +126,7 @@ gss_cred_set_ctx(struct rpc_cred *cred, struct gss_cl_ctx *ctx)
>> set_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags);
>> smp_mb__before_clear_bit();
>> clear_bit(RPCAUTH_CRED_NEW, &cred->cr_flags);
>> + smp_mb__after_clear_bit();
>> }
>>
>> static const void *
>
> Why are these needed?

AFAICS the documentation says to either call both smp_mb__before_clear_bit and smp_mp__after_clear_bit to ensure that memory operations before and after the clear_bit call are strongly ordered, or don't call either. Since there can be multiple threads looking at a gss_cred cr_flags, it seems to me that we want the memory barriers to get the correct value of the bit.

-->Andy


from Documentation/atomic_ops.txt:

If explicit memory barriers are required around clear_bit() (which
does not return a value, and thus does not need to provide memory
barrier semantics), two interfaces are provided:

void smp_mb__before_clear_bit(void);
void smp_mb__after_clear_bit(void);

They are used as follows, and are akin to their atomic_t operation
brothers:

/* All memory operations before this call will
* be globally visible before the clear_bit().
*/
smp_mb__before_clear_bit();
clear_bit( ... );

/* The clear_bit() will be visible before all
* subsequent memory operations.
*/
smp_mb__after_clear_bit();

>
> --
> Trond Myklebust
> Linux NFS client maintainer
>
> NetApp
> [email protected]
> http://www.netapp.com