IB: Fix race in sa_query
PATCH 1/3 IB: Fix race in sa_query
Use a copy of the id we'll return to the consumer so that we don't dereference query->sa_query after calling send_mad(). A completion may occur very quickly and end up freeing the query before we get to do anything after send_mad().
Signed-off-by Roland Dreier <[email protected]>
---
drivers/infiniband/core/sa_query.c | 18 +++++++++++++----- 1 files changed, 13 insertions(+), 5 deletions(-)
drivers/infiniband/core/sa_query.c +13 -5
@@ -507,7 +507,13 @@spin_unlock_irqrestore (&idr_lock, flags); } -return ret; +/* +* It's not safe to dereference query any more, because the +* send may already have completed and freed the query in +* another context. So use wr.wr_id, which has a copy of the +* query's id. +*/ +return ret ? ret : wr.wr_id; } static void ib_sa_path_rec_callback(struct ib_sa_query *sa_query,
@@ -598,14 +604,15 @@ rec, query->sa_query.mad->data); *sa_query = &query->sa_query; + ret =send_mad (&query->sa_query, timeout_ms); -if (ret) { +if (ret <0 ) { *sa_query =NULL ;kfree (query->sa_query.mad);kfree (query); } -return ret ? ret : query->sa_query.id; +return ret; }EXPORT_SYMBOL (ib_sa_path_rec_get);
@@ -674,14 +681,15 @@ rec, query->sa_query.mad->data); *sa_query = &query->sa_query; + ret =send_mad (&query->sa_query, timeout_ms); -if (ret) { +if (ret <0 ) { *sa_query =NULL ;kfree (query->sa_query.mad);kfree (query); } -return ret ? ret : query->sa_query.id; +return ret; }EXPORT_SYMBOL (ib_sa_mcmember_rec_query);
PATCH 2/3 IB: Fix pack/unpack when size_bits == 64
Fix handling of fields with size_bits == 64. Pointed out by Hal Rosenstock.
Signed-off-by Roland Dreier <[email protected]>
---
drivers/infiniband/core/packer.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/core/packer.c +2 -2
@@ -96,7 +96,7 @@else val =0 ; - mask =cpu_to_be64 (((1ull << desc[i].size_bits) -1 ) << shift); + mask =cpu_to_be64 ((~0ull >> (64 - desc[i].size_bits)) << shift); addr = (__be64 *) ((__be32 *) buf + desc[i].offset_words); *addr = (*addr & ~mask) | (cpu_to_be64 (val) & mask); }else {
@@ -176,7 +176,7 @@__be64 *addr; shift =64 - desc[i].offset_bits - desc[i].size_bits; - mask = ((1ull << desc[i].size_bits) -1 ) << shift; + mask = (~0ull >> (64 - desc[i].size_bits)) << shift; addr = (__be64 *) buf + desc[i].offset_words; val = (be64_to_cpup (addr) & mask) >> shift; value_write(desc[i].struct_offset_bytes,
PATCH 3/3 MAINTAINERS: Update Roland Dreier's email
Cisco bought Topspin, so I'm now a shiny happy Cisco employee. Update my entry in MAINTAINERS.
Signed-off-by Roland Dreier <[email protected]>
MAINTAINERS +1 -1
@@ -1150,7 +1150,7 @@ INFINIBAND SUBSYSTEM P: Roland Dreier -M: [email protected] +M: [email protected] P: Sean Hefty M: [email protected] P: Hal Rosenstock