connection: make attach_flags atomic
authorDavid Herrmann <dh.herrmann@gmail.com>
Mon, 20 Oct 2014 13:41:49 +0000 (15:41 +0200)
committerDavid Herrmann <dh.herrmann@gmail.com>
Mon, 20 Oct 2014 13:45:02 +0000 (15:45 +0200)
Instead of requiring connection locks, make conn->attach_flags a 64bit
atomic. This isn't particularly fast on archs that don't optimize
atomic64, but it simplifies the locking in kdbus. Requiring the connection
lock is just annoying. Furthermore, most 'real' archs should provide 64bit
atomics, anyway.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
connection.c
connection.h

index 8210d1d9ca95a85d553cb7bb9dd2b2a96e16aa8c..6093c133dc67f7933951092ebf4b811ed0ba4d23 100644 (file)
@@ -549,9 +549,7 @@ static int kdbus_kmsg_attach_metadata(struct kdbus_kmsg *kmsg,
         * conn_src->owner_meta, and we only attach the connection's name and
         * currently owned names on top of that.
         */
-       mutex_lock(&conn_dst->lock);
-       attach_flags = conn_dst->attach_flags;
-       mutex_unlock(&conn_dst->lock);
+       attach_flags = atomic64_read(&conn_dst->attach_flags);
 
        if (conn_src->owner_meta)
                attach_flags &= KDBUS_ATTACH_NAMES | KDBUS_ATTACH_CONN_NAME;
@@ -1372,11 +1370,8 @@ int kdbus_cmd_conn_update(struct kdbus_conn *conn,
                        return ret;
        }
 
-       if (flags_provided) {
-               mutex_lock(&conn->lock);
-               conn->attach_flags = attach_flags;
-               mutex_unlock(&conn->lock);
-       }
+       if (flags_provided)
+               atomic64_set(&conn->attach_flags, attach_flags);
 
        return 0;
 }
@@ -1545,7 +1540,7 @@ int kdbus_conn_new(struct kdbus_ep *ep,
        memcpy(hello->id128, bus->id128, sizeof(hello->id128));
 
        conn->flags = hello->conn_flags;
-       conn->attach_flags = hello->attach_flags;
+       atomic64_set(&conn->attach_flags, hello->attach_flags);
 
        if (is_activator) {
                u64 flags = KDBUS_NAME_ACTIVATOR;
index 6a9c557024c3f8e42f398eaafdb3ffee01fab2cd..4fdf334dacd8f08b036d8fb9efe0151d7ab2c5fb 100644 (file)
@@ -15,6 +15,7 @@
 #ifndef __KDBUS_CONNECTION_H
 #define __KDBUS_CONNECTION_H
 
+#include <linux/atomic.h>
 #include <linux/lockdep.h>
 #include "limits.h"
 #include "metadata.h"
@@ -72,7 +73,7 @@ struct kdbus_conn {
 #endif
        u64 id;
        u64 flags;
-       u64 attach_flags;
+       atomic64_t attach_flags;
        const char *name;
        struct kdbus_bus *bus;
        struct kdbus_ep *ep;