Skip to content

Commit

Permalink
s390/qeth: relax locking for ipato config data
Browse files Browse the repository at this point in the history
card->ipato is currently protected by the conf_mutex. But most users
also hold the ip_lock - in particular qeth_l3_add_ip().

So slightly expand the sections under ip_lock in a few places (to
effectively cover a few error & no-op cases), and then drop the
conf_mutex where it's no longer needed.

Signed-off-by: Julian Wiedmann <jwi@linux.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Julian Wiedmann authored and David S. Miller committed Sep 23, 2020
1 parent 668e225 commit d6e6426
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
7 changes: 5 additions & 2 deletions drivers/s390/net/qeth_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -814,20 +814,23 @@ struct qeth_card {
struct workqueue_struct *event_wq;
struct workqueue_struct *cmd_wq;
wait_queue_head_t wait_q;

struct mutex ip_lock;
/* protected by ip_lock: */
DECLARE_HASHTABLE(ip_htable, 4);
struct qeth_ipato ipato;

DECLARE_HASHTABLE(local_addrs4, 4);
DECLARE_HASHTABLE(local_addrs6, 4);
spinlock_t local_addrs4_lock;
spinlock_t local_addrs6_lock;
struct mutex ip_lock;
DECLARE_HASHTABLE(rx_mode_addrs, 4);
struct work_struct rx_mode_work;
struct work_struct kernel_thread_starter;
spinlock_t thread_mask_lock;
unsigned long thread_start_mask;
unsigned long thread_allowed_mask;
unsigned long thread_running_mask;
struct qeth_ipato ipato;
struct list_head cmd_waiter_list;
/* QDIO buffer handling */
struct qeth_qdio_info qdio;
Expand Down
4 changes: 0 additions & 4 deletions drivers/s390/net/qeth_l3_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,6 @@ int qeth_l3_add_ipato_entry(struct qeth_card *card,

QETH_CARD_TEXT(card, 2, "addipato");

mutex_lock(&card->conf_mutex);
mutex_lock(&card->ip_lock);

list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
Expand All @@ -556,7 +555,6 @@ int qeth_l3_add_ipato_entry(struct qeth_card *card,
}

mutex_unlock(&card->ip_lock);
mutex_unlock(&card->conf_mutex);

return rc;
}
Expand All @@ -570,7 +568,6 @@ int qeth_l3_del_ipato_entry(struct qeth_card *card,

QETH_CARD_TEXT(card, 2, "delipato");

mutex_lock(&card->conf_mutex);
mutex_lock(&card->ip_lock);

list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
Expand All @@ -587,7 +584,6 @@ int qeth_l3_del_ipato_entry(struct qeth_card *card,
}

mutex_unlock(&card->ip_lock);
mutex_unlock(&card->conf_mutex);

return rc;
}
Expand Down
22 changes: 11 additions & 11 deletions drivers/s390/net/qeth_l3_sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,19 +301,21 @@ static ssize_t qeth_l3_dev_ipato_enable_store(struct device *dev,
goto out;
}

mutex_lock(&card->ip_lock);
if (sysfs_streq(buf, "toggle")) {
enable = !card->ipato.enabled;
} else if (kstrtobool(buf, &enable)) {
rc = -EINVAL;
goto out;
goto unlock_ip;
}

if (card->ipato.enabled != enable) {
card->ipato.enabled = enable;
mutex_lock(&card->ip_lock);
qeth_l3_update_ipato(card);
mutex_unlock(&card->ip_lock);
}

unlock_ip:
mutex_unlock(&card->ip_lock);
out:
mutex_unlock(&card->conf_mutex);
return rc ? rc : count;
Expand All @@ -339,7 +341,7 @@ static ssize_t qeth_l3_dev_ipato_invert4_store(struct device *dev,
bool invert;
int rc = 0;

mutex_lock(&card->conf_mutex);
mutex_lock(&card->ip_lock);
if (sysfs_streq(buf, "toggle")) {
invert = !card->ipato.invert4;
} else if (kstrtobool(buf, &invert)) {
Expand All @@ -349,12 +351,11 @@ static ssize_t qeth_l3_dev_ipato_invert4_store(struct device *dev,

if (card->ipato.invert4 != invert) {
card->ipato.invert4 = invert;
mutex_lock(&card->ip_lock);
qeth_l3_update_ipato(card);
mutex_unlock(&card->ip_lock);
}

out:
mutex_unlock(&card->conf_mutex);
mutex_unlock(&card->ip_lock);
return rc ? rc : count;
}

Expand Down Expand Up @@ -510,7 +511,7 @@ static ssize_t qeth_l3_dev_ipato_invert6_store(struct device *dev,
bool invert;
int rc = 0;

mutex_lock(&card->conf_mutex);
mutex_lock(&card->ip_lock);
if (sysfs_streq(buf, "toggle")) {
invert = !card->ipato.invert6;
} else if (kstrtobool(buf, &invert)) {
Expand All @@ -520,12 +521,11 @@ static ssize_t qeth_l3_dev_ipato_invert6_store(struct device *dev,

if (card->ipato.invert6 != invert) {
card->ipato.invert6 = invert;
mutex_lock(&card->ip_lock);
qeth_l3_update_ipato(card);
mutex_unlock(&card->ip_lock);
}

out:
mutex_unlock(&card->conf_mutex);
mutex_unlock(&card->ip_lock);
return rc ? rc : count;
}

Expand Down

0 comments on commit d6e6426

Please sign in to comment.