Received: by 10.192.165.148 with SMTP id m20csp3881810imm; Mon, 30 Apr 2018 07:59:36 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqN+SktToIvwaWGPXbaGCqOqP1CA35Y5N8TPGomXWx4V5KzvOxQ6bbwFwGIrmDgnpcr+5UK X-Received: by 2002:a17:902:1681:: with SMTP id h1-v6mr12666849plh.145.1525100376067; Mon, 30 Apr 2018 07:59:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525100376; cv=none; d=google.com; s=arc-20160816; b=go+e+pHzODRCVgkPRwKb2M6fKyMzAlglHrZvineRkXXYzkqWhywlDplbBSQUQJgeVO 2lcs/tPfn/PwNTp/tU7tG6Llths2SmL5aQPyzHApYtgdmKctFTyrUF/icHX2uW5fQn4t BsRXaEBnW5gSwEk2U3GnUvJnf+t2MH7qWMDklO5rQXAJaMC0b6XK7tgFtIzPKSCpY3YQ 6QyONBAE2NADEDFFHR60QNrEcm3USKb0y/azkpTaZpG4g8QZ43gMCpGgHOyBtBv7SoOn OeAzonOSRgmU3bX9S7g/J2gCcik4gcOECjn+dxyr9wT+fzZbCO3tn/bc4i5zAjIL+BxN uIIg== 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=xU4YAUY7831TMun2OjClGonxrJ8++MJr7uL1RG44wpQ=; b=H0EGdnpB6MAwDBlpFm8hSnCEkpCVyi509Zfc7qyOEs6w5aIS1dHlbsnbalBHLm0cBK /uf3nhyS05AXvsUonerXSVH4Rw4ofbH+VJG5At3Fq3MEv7Ox3dTRCe3K3dAoBLAy1XwK slwNIFALSW53Eftlbq/bwfwA6zBWvc0N2OXo6tf1eggZq2NUk0RrJcyAcWMUSo+hA6/j USbZwiBVzU5kYkCPN/r5y69NB6f5wmeWuVE6EDN5EaMWeVb3/1nkiiEjo1txzECGnSDQ NRQ5/GX054Boj9zozrNIDzCZvpeJFyAZGj+mXvp6vy9P40U5FUpXOXIjJ8VV6vA2oJ/5 0uNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=d9QP7/xN; 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 4-v6si6367731pgf.684.2018.04.30.07.59.22; Mon, 30 Apr 2018 07:59:36 -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=d9QP7/xN; 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 S1754683AbeD3O4l (ORCPT + 99 others); Mon, 30 Apr 2018 10:56:41 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:35014 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754670AbeD3O4j (ORCPT ); Mon, 30 Apr 2018 10:56:39 -0400 Received: by mail-pf0-f193.google.com with SMTP id j5so6939066pfh.2 for ; Mon, 30 Apr 2018 07:56:39 -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=xU4YAUY7831TMun2OjClGonxrJ8++MJr7uL1RG44wpQ=; b=d9QP7/xN8EA0TEL10ZcQNeM8agRO/B1orF+wg4dA5MPQnwjUIYhP7EA3CQgHKqfNu3 v0rDk+8OmC8UGqIPHGuGiry4twR7OIg85aejU7y/nzOrvEBzFPW/vq3VtAegE+UCLFX7 5hU8PwwxRaUkiFGdxyg4/NtSxlrdDyw000qROwivfxAa6J/PX7qC9KF6yth/IcfuRP12 3an6j5zemnNOD/UEfMTVAwieoXEAN91zb8CTeIfmNBVwt7hykfLfXetRPfJPKq+JE/SI r3qhvU3PaF2QaGNTxoxxpw9lb/G1/sVZfW8V/vUlO88SBmeECBRIiDxySXsKnhMBOjMk a1nw== 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=xU4YAUY7831TMun2OjClGonxrJ8++MJr7uL1RG44wpQ=; b=dtNylQsOsEKqwkBR6+gle5RpJPpRx4xNzLVpScC87zYo9pXjjfX7ZTsIkV2gdCZqtP aqlHbyy4p9GEfyxAKVxce+D8KVIC1uxZ+NJXcWnRHXxhkCXtExlDQpHU6zLJ13AX7eEF C5zs3r/saBJ8VDawbEbFpnh9uzj3PYAGRC2gDOGDIfBxZEyjBmS+qDiqJaADkPiMcl6z Z8ks71flFLapegIQW5UfBWWhViwX9mG4Gr2jSL5BESH6/VavrZ8bVnaeuD/8rpaKSwvu EMrykcswAjDNE+fwedwLKe3q/U0c+wiLdPWlw2pFUKZBIBh3rf7NdMusjJ8gFNUhhxXG Q2nA== X-Gm-Message-State: ALQs6tAfsplC7Ud2Zk625NdpkJw4fDDxLeuhtnEBfOGi29TMQINlBOCA MS1g2YAEu/IfqV4Gj19JrVZi7A== X-Received: by 10.98.74.136 with SMTP id c8mr12306068pfj.23.1525100199373; Mon, 30 Apr 2018 07:56:39 -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.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 30 Apr 2018 07:56:38 -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 08/15] powerpc/powernv: implement opal_put_chars_atomic Date: Tue, 1 May 2018 00:55:51 +1000 Message-Id: <20180430145558.4308-9-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 The RAW console does not need writes to be atomic, so relax opal_put_chars to be able to do partial writes, and implement an _atomic variant which does not take a spinlock. This API is used in xmon, so the less locking that is used, the better chance there is that a crash can be debugged. Cc: Benjamin Herrenschmidt Signed-off-by: Nicholas Piggin --- arch/powerpc/include/asm/opal.h | 1 + arch/powerpc/platforms/powernv/opal.c | 37 +++++++++++++++++++-------- drivers/tty/hvc/hvc_opal.c | 18 +++++++++---- 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/arch/powerpc/include/asm/opal.h b/arch/powerpc/include/asm/opal.h index bbff49fab0e5..5d7072411561 100644 --- a/arch/powerpc/include/asm/opal.h +++ b/arch/powerpc/include/asm/opal.h @@ -303,6 +303,7 @@ extern void opal_configure_cores(void); extern int opal_get_chars(uint32_t vtermno, char *buf, int count); extern int opal_put_chars(uint32_t vtermno, const char *buf, int total_len); +extern int opal_put_chars_atomic(uint32_t vtermno, const char *buf, int total_len); extern int opal_flush_console(uint32_t vtermno); extern void hvc_opal_init_early(void); diff --git a/arch/powerpc/platforms/powernv/opal.c b/arch/powerpc/platforms/powernv/opal.c index 55d4b1983110..bcdb90ada938 100644 --- a/arch/powerpc/platforms/powernv/opal.c +++ b/arch/powerpc/platforms/powernv/opal.c @@ -344,9 +344,9 @@ int opal_get_chars(uint32_t vtermno, char *buf, int count) return 0; } -int opal_put_chars(uint32_t vtermno, const char *data, int total_len) +static int __opal_put_chars(uint32_t vtermno, const char *data, int total_len, bool atomic) { - unsigned long flags; + unsigned long flags = 0 /* shut up gcc */; int written; __be64 olen; s64 rc; @@ -354,11 +354,8 @@ int opal_put_chars(uint32_t vtermno, const char *data, int total_len) if (!opal.entry) return -ENODEV; - /* We want put_chars to be atomic to avoid mangling of hvsi - * packets. To do that, we first test for room and return - * -EAGAIN if there isn't enough. - */ - spin_lock_irqsave(&opal_write_lock, flags); + if (atomic) + spin_lock_irqsave(&opal_write_lock, flags); rc = opal_console_write_buffer_space(vtermno, &olen); if (rc || be64_to_cpu(olen) < total_len) { /* Closed -> drop characters */ @@ -391,14 +388,18 @@ int opal_put_chars(uint32_t vtermno, const char *data, int total_len) written = be64_to_cpu(olen); if (written < total_len) { - /* Should not happen */ - pr_warn("atomic console write returned partial len=%d written=%d\n", total_len, written); + if (atomic) { + /* Should not happen */ + pr_warn("atomic console write returned partial " + "len=%d written=%d\n", total_len, written); + } if (!written) written = -EAGAIN; } out: - spin_unlock_irqrestore(&opal_write_lock, flags); + if (atomic) + spin_unlock_irqrestore(&opal_write_lock, flags); /* In the -EAGAIN case, callers loop, so we have to flush the console * here in case they have interrupts off (and we don't want to wait @@ -412,6 +413,22 @@ int opal_put_chars(uint32_t vtermno, const char *data, int total_len) return written; } +int opal_put_chars(uint32_t vtermno, const char *data, int total_len) +{ + return __opal_put_chars(vtermno, data, total_len, false); +} + +/* + * opal_put_chars_atomic will not perform partial-writes. Data will be + * atomically written to the terminal or not at all. This is not strictly + * true at the moment because console space can race with OPAL's console + * writes. + */ +int opal_put_chars_atomic(uint32_t vtermno, const char *data, int total_len) +{ + return __opal_put_chars(vtermno, data, total_len, true); +} + int opal_flush_console(uint32_t vtermno) { s64 rc; diff --git a/drivers/tty/hvc/hvc_opal.c b/drivers/tty/hvc/hvc_opal.c index af122ad7f06d..0a72f98ee082 100644 --- a/drivers/tty/hvc/hvc_opal.c +++ b/drivers/tty/hvc/hvc_opal.c @@ -183,9 +183,15 @@ static int hvc_opal_probe(struct platform_device *dev) return -ENOMEM; pv->proto = proto; hvc_opal_privs[termno] = pv; - if (proto == HV_PROTOCOL_HVSI) - hvsilib_init(&pv->hvsi, opal_get_chars, opal_put_chars, + if (proto == HV_PROTOCOL_HVSI) { + /* + * We want put_chars to be atomic to avoid mangling of + * hvsi packets. + */ + hvsilib_init(&pv->hvsi, + opal_get_chars, opal_put_chars_atomic, termno, 0); + } /* Instanciate now to establish a mapping index==vtermno */ hvc_instantiate(termno, termno, ops); @@ -376,8 +382,9 @@ void __init hvc_opal_init_early(void) else if (of_device_is_compatible(stdout_node,"ibm,opal-console-hvsi")) { hvc_opal_boot_priv.proto = HV_PROTOCOL_HVSI; ops = &hvc_opal_hvsi_ops; - hvsilib_init(&hvc_opal_boot_priv.hvsi, opal_get_chars, - opal_put_chars, index, 1); + hvsilib_init(&hvc_opal_boot_priv.hvsi, + opal_get_chars, opal_put_chars_atomic, + index, 1); /* HVSI, perform the handshake now */ hvsilib_establish(&hvc_opal_boot_priv.hvsi); pr_devel("hvc_opal: Found HVSI console\n"); @@ -409,7 +416,8 @@ void __init udbg_init_debug_opal_hvsi(void) hvc_opal_privs[index] = &hvc_opal_boot_priv; hvc_opal_boot_termno = index; udbg_init_opal_common(); - hvsilib_init(&hvc_opal_boot_priv.hvsi, opal_get_chars, opal_put_chars, + hvsilib_init(&hvc_opal_boot_priv.hvsi, + opal_get_chars, opal_put_chars_atomic, index, 1); hvsilib_establish(&hvc_opal_boot_priv.hvsi); } -- 2.17.0