Received: by 10.192.165.148 with SMTP id m20csp3880016imm; Mon, 30 Apr 2018 07:57:41 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp4VfS8+PsjulWM5VZcwzIW7YI+ssihcZcFYywBZ8kEg5EdJ12yzbv/ji+uqRFIFit9i/ZF X-Received: by 2002:a17:902:bcc4:: with SMTP id o4-v6mr1742819pls.308.1525100261731; Mon, 30 Apr 2018 07:57:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525100261; cv=none; d=google.com; s=arc-20160816; b=RwFuk5GcRbQHvBczGvSYNnGf0oonYMmcqC9obcx6dvTJLKRpdfQR5khT+gjUXsvXjI axZlTvS4ajaEutCvi8/9lC0XvhYY/xxTWIt2yi55oQrYlRC2DxGKFTPFLJwycFt+vz/W Xev7YWRfkKub7XG9GVj6J4Rmvr6G0ypu5QdvXeMKgLwKHIpbt4P+nUfoSPt+b1D/TK6N AQxI1DMIN8jJzJ7TFYqkM+D4hjYcBtqGAVbnz6oKx6uoibSQzUDDTdIJnQ9fNbPX2Ghq jGr/9asm9V9KMcyIpu1Ci+1CUzHgQ7n7YGQoUSDzunsLSKzmTwgGA8F4UBkp1eTNbpDQ c1kA== 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=fjmC+kPlGE91uLgJT33jj6nSucLu36EYujTmEQhL5nY=; b=VNxByj5yhtW2TpDBoUSkMMMCgxuMly3lPEW8tutjh3wUOR/uwIHnfCv4lZVAhAQzgO dkVHdeMAAwc34dN5tdQCJnKqLKzuyTIqQXa5O0sF3xgG3T9dlA/34wZ6+ftb+xKcS9r4 hViByPa+wnj2oqsCe+zjRau4/nO5V58+XoaFEvjk5zoXfkFBeeLd6Rvy40igdkwCTvuS AbscMhlKmqYE8Xd2ohtqMuk8RQwbcANggTu5wAQfmaKjEQZF1Zh/i6prN/9BZoAn8wWo mI8EP6FWEijqTm7XV1dD6NJqjFuO0tCUln/t8UCST07wWXW5ww2B5Gj/g0lf4tMQnt4H kaQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=GBPOoj/g; 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 p85si7784868pfk.77.2018.04.30.07.57.27; Mon, 30 Apr 2018 07:57:41 -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=GBPOoj/g; 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 S1754736AbeD3O5E (ORCPT + 99 others); Mon, 30 Apr 2018 10:57:04 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:33644 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754354AbeD3O46 (ORCPT ); Mon, 30 Apr 2018 10:56:58 -0400 Received: by mail-pg0-f67.google.com with SMTP id i194-v6so6482952pgd.0 for ; Mon, 30 Apr 2018 07:56:58 -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=fjmC+kPlGE91uLgJT33jj6nSucLu36EYujTmEQhL5nY=; b=GBPOoj/gy7VwxfL3pbk3P77iHbh/Wopl/DU3sVWY390iMyAYxVKgaXdIzm/2rDg8tp /Tuob1OKysBBdt4viHO1ionPR55r8D1WJDYLyDyFSzijHBVj4jHM9/Y8EjLQ5t6rlTwo 5FoVB/iBqeWGIQb5LRRzglNKXT9WntJjKf6LuUQZbICdyiDkgYiYYc6JzqKPu8n7+4T2 0M6zMX+rWorVN4gHtwU0wJrJiOttE7YePShaQkjJdmBrpZwIcUuLM6oqR7Coedo2D9Lp OElkozStoUS+c1maKy2vNRydorvXbMshn/8t7mlFF4zZitl3w+aNEovtV27+tMeFzUs7 JfNw== 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=fjmC+kPlGE91uLgJT33jj6nSucLu36EYujTmEQhL5nY=; b=tRjsgX0NK74/BPQ1G+jrTA93bao1soCYtOI1j7xDXcBzXBlPpRoPJJaBkSuw/AjnEo OR0Yl+LZf4TpeYLGtziDAOpFH+MYbO/dMxEc7Mn1jjWWj5GdTlONPMYxu7LPnt+By7sb OJkNY+SQipfFCJDCmGOxgQbcGk5CwtLRk0s/RmweS+cjFEuAzr9382S6ymNxrlzAN/8z YkMKajFSa+oaw+xSaXFyFUcZUl/OkAm6rKREJKZKiPPQBrgAnOQPklZzzRWASKSRaZd0 9Ay0IJ1zFZa6tXmJYW59wtqVyu5L4yhJbVXKYzVqAB2ircNFH2255yO40cfk9Xk9YoHb ekeQ== X-Gm-Message-State: ALQs6tBsjP+9wInajzh1uvtnwC43KAguf1jiFFLFx03j8JMgdpWSjoZ4 sEr4S0nzqJLRpR/Q5bVBw+acXg== X-Received: by 10.167.128.141 with SMTP id v13mr12197534pff.147.1525100218384; Mon, 30 Apr 2018 07:56:58 -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.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Apr 2018 07:56:57 -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 13/15] tty: hvc: hvc_write may sleep Date: Tue, 1 May 2018 00:55:56 +1000 Message-Id: <20180430145558.4308-14-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 Rework the hvc_write loop to drop and re-take the spinlock on each iteration, add a cond_resched. Don't bother with an initial hvc_push initially, which makes the logic simpler -- just do a hvc_push on each time around the loop. Signed-off-by: Nicholas Piggin --- drivers/tty/hvc/hvc_console.c | 36 ++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c index 2abfc0b15fbb..6131d5084c42 100644 --- a/drivers/tty/hvc/hvc_console.c +++ b/drivers/tty/hvc/hvc_console.c @@ -493,23 +493,29 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count if (hp->port.count <= 0) return -EIO; - spin_lock_irqsave(&hp->lock, flags); + while (count > 0) { + spin_lock_irqsave(&hp->lock, flags); - /* Push pending writes */ - if (hp->n_outbuf > 0) - hvc_push(hp); - - while (count > 0 && (rsize = hp->outbuf_size - hp->n_outbuf) > 0) { - if (rsize > count) - rsize = count; - memcpy(hp->outbuf + hp->n_outbuf, buf, rsize); - count -= rsize; - buf += rsize; - hp->n_outbuf += rsize; - written += rsize; - hvc_push(hp); + rsize = hp->outbuf_size - hp->n_outbuf; + + if (rsize) { + if (rsize > count) + rsize = count; + memcpy(hp->outbuf + hp->n_outbuf, buf, rsize); + count -= rsize; + buf += rsize; + hp->n_outbuf += rsize; + written += rsize; + } + + if (hp->n_outbuf > 0) + hvc_push(hp); + + spin_unlock_irqrestore(&hp->lock, flags); + + if (count) + cond_resched(); } - spin_unlock_irqrestore(&hp->lock, flags); /* * Racy, but harmless, kick thread if there is still pending data. -- 2.17.0