Received: by 10.192.165.148 with SMTP id m20csp3881547imm; Mon, 30 Apr 2018 07:59:18 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp1EPIT5Mau7UwSSLY8PN5+gdXe5TbcTA3c9AsPYMnkVSi2aJe4L5JQ8PuvnUFGmUd6o0vz X-Received: by 2002:a17:902:d882:: with SMTP id b2-v6mr12639585plz.381.1525100358312; Mon, 30 Apr 2018 07:59:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525100358; cv=none; d=google.com; s=arc-20160816; b=LgTJ8k/+Ec/0U1o3gwo0cJYQtpe6BaEAI83SgrK9HMezH3Levi33vPEBHztGVvK0v7 +Yx66yuNyLeLIhBOOVdAC1NNAbuK4EWT6M6lBCeGfit9cu9D/u6/VfMmhvYm6uVO9IHR YKZM+FzJmvueQLvGfuWF44HDM45yOiMPXWCeFnMPKQflfVEA4Zk6kKIrIQ48pEXcTQp6 4TeMXD7WWA/rafN0gRPyuLephv66/yPU3/jZZfRxYAE7aOxgYaZuSrrLBqkyR9d+ZXXK 1l6IK21wA8HExCpNn4tT9F6LZNP8YApUN9OSTcVsYAXA3FPen5SsHMKwmH4FoJsp+EtF Exjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=9A9yJP8KTu1HlwBS06mSZVmty0mRd6rd0ELqr53RIYA=; b=V34WfhIJcYlN4Ash9TNtc0gYNgFhAeROWTXwUq4dDs/h+rCNUBNu04gL6EA+Ld+UD3 Z7sT7l8F+W/wcXV3UitiSI0YRYkfTnTv/pqvTx8fupGvFqcrI2pXSHegb5IC+ZgAmDi1 q1Vz+8kQIuaIMrQZAQn86dJzMO5A2y/jRs4XHQOx2HpCUcYeYaBK6HtP1OckcHGYJG3M Lh9MefVnlbfysufCecu+LQrpBeTZ3J63/9hRKNDf0L+IUYEv/C2TuSTTWJX4LYZ5Pnzs nf2IQWulOgQV4fRzEhyeIX7eo6PmxPesPj5xcCQOqWHNgANNq6vxxUkvwilJl+XVDfZE vgzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=FTY42b+S; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v2-v6si7775875plo.138.2018.04.30.07.59.04; Mon, 30 Apr 2018 07:59:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=FTY42b+S; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754810AbeD3O6V (ORCPT + 99 others); Mon, 30 Apr 2018 10:58:21 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:39341 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754690AbeD3O4r (ORCPT ); Mon, 30 Apr 2018 10:56:47 -0400 Received: by mail-pf0-f196.google.com with SMTP id z9so6925154pfe.6 for ; Mon, 30 Apr 2018 07:56:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=9A9yJP8KTu1HlwBS06mSZVmty0mRd6rd0ELqr53RIYA=; b=FTY42b+SzM1wbTUHMSZyZf4N7+7FyTgQkODXGbg4NuwEBrOAGSnizjV8vsgd9u83PP VfYaW2AXhm9BPb+IO9AHyMsrVCWJYVnzE6bEclHNlOaxCA8bFEgcFVshHpSmFCjbbWL0 d6T89LVgMoKgCJOSvf9cwhGH90wUPtrKqDufl1mLv5QL3vFDb7zySNdoDXi0STHD9Bky d1kGkU/mKmCepMMsviJY96P2y7DIxRgX7DixDbI9NKdJbNa0pThnqNbYrGFHpHfXIE/i KXsAXAGveaZggyZqdQgCoV7HwVHGJzQuQh3680VRycoMolvVgfIRGsWrTp+suM0rTQ0L 02PA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=9A9yJP8KTu1HlwBS06mSZVmty0mRd6rd0ELqr53RIYA=; b=GIF7vIIXH+kmmsIddAUhZYri2ahnqUTfhknWeotRYZ1BL2VtPKm9+/xf/s4YKf+2Am +uc+PAnEgB9ulanjTPn2ZrZ1XhNQ0WDRJv5eTZZATwgcnCurVGe81kymMAdEBef3ePpz x8/DCFhybTS8/zlH4nYXuCbhKCdcLsWHlsvu39ABiheBcKkrS/pkO+S/34/ABdBBX+s6 9U9ZZ+7jj3rdgnibCxy7PTsOYfttKIqMLQfzz408L+IZxSs2+dHkHwPwX8rni8Ls1qOK UJ0iMrmd2u/cYy2Ta/NgTL8v3KcFg7HwMJk2We5NTUEl0Xt1fcc8lIOF2wzMbz8dWq8S Kcpw== X-Gm-Message-State: ALQs6tAgb8IN0CfUnKvcxgLHGlOeVw2fdExua0zpQS9aTxmkMJ4dUtaU ulmvGV7UaYL8efRB9Z5RyKs= X-Received: by 2002:a63:8dc1:: with SMTP id z184-v6mr10330961pgd.114.1525100206950; Mon, 30 Apr 2018 07:56:46 -0700 (PDT) Received: from roar.au.ibm.com (59-102-70-78.tpgi.com.au. [59.102.70.78]) by smtp.gmail.com with ESMTPSA id a12sm19132534pfe.78.2018.04.30.07.56.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Apr 2018 07:56:46 -0700 (PDT) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Cc: Nicholas Piggin , Benjamin Herrenschmidt , Greg Kroah-Hartman , Jiri Slaby , linux-kernel@vger.kernel.org Subject: [PATCH 10/15] tty: hvc: use mutex instead of spinlock for hvc_structs lock Date: Tue, 1 May 2018 00:55:53 +1000 Message-Id: <20180430145558.4308-11-npiggin@gmail.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430145558.4308-1-npiggin@gmail.com> References: <20180430145558.4308-1-npiggin@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This allows hvc operations to sleep under the lock. Signed-off-by: Nicholas Piggin --- drivers/tty/hvc/hvc_console.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c index 7709fcc707f4..fddb63322c67 100644 --- a/drivers/tty/hvc/hvc_console.c +++ b/drivers/tty/hvc/hvc_console.c @@ -73,7 +73,7 @@ static LIST_HEAD(hvc_structs); * Protect the list of hvc_struct instances from inserts and removals during * list traversal. */ -static DEFINE_SPINLOCK(hvc_structs_lock); +static DEFINE_MUTEX(hvc_structs_mutex); /* * This value is used to assign a tty->index value to a hvc_struct based @@ -83,7 +83,7 @@ static DEFINE_SPINLOCK(hvc_structs_lock); static int last_hvc = -1; /* - * Do not call this function with either the hvc_structs_lock or the hvc_struct + * Do not call this function with either the hvc_structs_mutex or the hvc_struct * lock held. If successful, this function increments the kref reference * count against the target hvc_struct so it should be released when finished. */ @@ -92,25 +92,24 @@ static struct hvc_struct *hvc_get_by_index(int index) struct hvc_struct *hp; unsigned long flags; - spin_lock(&hvc_structs_lock); + mutex_lock(&hvc_structs_mutex); list_for_each_entry(hp, &hvc_structs, next) { spin_lock_irqsave(&hp->lock, flags); if (hp->index == index) { tty_port_get(&hp->port); spin_unlock_irqrestore(&hp->lock, flags); - spin_unlock(&hvc_structs_lock); + mutex_unlock(&hvc_structs_mutex); return hp; } spin_unlock_irqrestore(&hp->lock, flags); } hp = NULL; + mutex_unlock(&hvc_structs_mutex); - spin_unlock(&hvc_structs_lock); return hp; } - /* * Initial console vtermnos for console API usage prior to full console * initialization. Any vty adapter outside this range will not have usable @@ -224,13 +223,13 @@ static void hvc_port_destruct(struct tty_port *port) struct hvc_struct *hp = container_of(port, struct hvc_struct, port); unsigned long flags; - spin_lock(&hvc_structs_lock); + mutex_lock(&hvc_structs_mutex); spin_lock_irqsave(&hp->lock, flags); list_del(&(hp->next)); spin_unlock_irqrestore(&hp->lock, flags); - spin_unlock(&hvc_structs_lock); + mutex_unlock(&hvc_structs_mutex); kfree(hp); } @@ -733,11 +732,11 @@ static int khvcd(void *unused) try_to_freeze(); wmb(); if (!cpus_are_in_xmon()) { - spin_lock(&hvc_structs_lock); + mutex_lock(&hvc_structs_mutex); list_for_each_entry(hp, &hvc_structs, next) { poll_mask |= hvc_poll(hp); } - spin_unlock(&hvc_structs_lock); + mutex_unlock(&hvc_structs_mutex); } else poll_mask |= HVC_POLL_READ; if (hvc_kicked) @@ -871,7 +870,7 @@ struct hvc_struct *hvc_alloc(uint32_t vtermno, int data, INIT_WORK(&hp->tty_resize, hvc_set_winsz); spin_lock_init(&hp->lock); - spin_lock(&hvc_structs_lock); + mutex_lock(&hvc_structs_mutex); /* * find index to use: @@ -891,7 +890,7 @@ struct hvc_struct *hvc_alloc(uint32_t vtermno, int data, vtermnos[i] = vtermno; list_add_tail(&(hp->next), &hvc_structs); - spin_unlock(&hvc_structs_lock); + mutex_unlock(&hvc_structs_mutex); /* check if we need to re-register the kernel console */ hvc_check_console(i); -- 2.17.0