From patchwork Tue May 19 05:46:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 1292958 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49R4nB1WxNz9sTc for ; Tue, 19 May 2020 15:53:34 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=U2bjI3Ou; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 49R4nB1CCtzDqQb for ; Tue, 19 May 2020 15:53:34 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::644; helo=mail-pl1-x644.google.com; envelope-from=oohall@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=U2bjI3Ou; dkim-atps=neutral Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 49R4f94LYHzDqrq for ; Tue, 19 May 2020 15:47:29 +1000 (AEST) Received: by mail-pl1-x644.google.com with SMTP id u22so5152729plq.12 for ; Mon, 18 May 2020 22:47:29 -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 :mime-version:content-transfer-encoding; bh=72W8SjqxntklFcdK2QNeKoe8eRqtJzmEXo9haxb8le4=; b=U2bjI3OugKU3qp+k+Kqqoz8wMq/20x6abQZbdH9zUqAnh8u38y/Djpd8Qr3a3EQMLL 45z+bAjoq54+1q4j4GkWwrc5+hnINNek6lNKOv1rlITqGnzPEbZgk6i7U+tNM23xYJVb ria6w6mqeuvnB9pQKksf4nf6Xas4I7GVEYugKUDZIQKB0gI9BXsC28f7y9F1o3lU7mQQ mnCLTaRoZsUit8XtZcnn5Jpq359GwGPgYogdKkQLJ8XOAt01F6wvy7lctfEzH8vduR5m IrJ6D1fxpPFPkRDwwf5JrtNAXMcNNOBoX8GvEZ+GdyChPxDGb3FK9dn9EYf60+6eD0L0 aK+A== 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:mime-version:content-transfer-encoding; bh=72W8SjqxntklFcdK2QNeKoe8eRqtJzmEXo9haxb8le4=; b=MCV/KT5sSU4el6QKje2gvz70eKe7E05XNp32daFRgbXbI1wVkwQlmG1iY7lHn5CGh1 ykwuILWwzFz1NmmgrBEoQUT0AIgEESV1M+QViCQV3xdPPgtL4G81n3VH5O1OdPOhADA9 JZZP2pYRV59U81l+rLDqCC+5lN45/1TVL9RK5MiHTm9scB2W22aFDSKgRZqwVdLmSl5+ b/FJE38ms8+Vl8e3o8KjBEcxhiFFNNNWofJ0jKo40WfFwa7xZtWG45tTIovphGfbtVh3 z8QemDa9hccqmvqKZMsOAn5BSOqRMnV6UXknzu32n7xHVRq3Er0rfx72a8QrDVCAtfNs V/bg== X-Gm-Message-State: AOAM532yWjJKymp/zedRK6Y2BG/EMlo2Xm3PNtP77zoSdqEKjEKovQjm 8wHBarcd0oEsyJtsW5V/F7Ro0mDJ X-Google-Smtp-Source: ABdhPJyDtsEffBKj/PXESp7oLs3SdqExAH+KBo9kyHFLAOcaNFYlal+Txt6YSHv4JTK4nHg3tXSjVQ== X-Received: by 2002:a17:902:d689:: with SMTP id v9mr9702352ply.283.1589867247526; Mon, 18 May 2020 22:47:27 -0700 (PDT) Received: from 192-168-1-12.tpgi.com.au ([203.221.252.191]) by smtp.gmail.com with ESMTPSA id p12sm2798358pgj.22.2020.05.18.22.47.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2020 22:47:27 -0700 (PDT) From: Oliver O'Halloran To: skiboot@lists.ozlabs.org Date: Tue, 19 May 2020 15:46:33 +1000 Message-Id: <20200519054633.113238-13-oohall@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200519054633.113238-1-oohall@gmail.com> References: <20200519054633.113238-1-oohall@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [RFC PATCH 12/12] core/console: Add a seperate lock for the in-memory console X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" With the msglog split from the in-mem console we shouldn't be using the same lock for both. Add a seperate dummy_con_lock() which is used for the in-memory console driver. Signed-off-by: Oliver O'Halloran --- Renaming con_lock to msglog_lock would probably make sense. Folding this into the previous patch might also make sense. --- core/console.c | 64 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 18 deletions(-) diff --git a/core/console.c b/core/console.c index bfeb7aae39e0..226ed57f0d36 100644 --- a/core/console.c +++ b/core/console.c @@ -29,6 +29,7 @@ static struct con_ops *con_driver; static struct opal_con_ops *opal_con_driver = &dummy_opal_con; static struct lock con_lock = LOCK_UNLOCKED; +static struct lock dummy_con_lock = LOCK_UNLOCKED; /* The descriptors are is mapped via TCEs so we keep it alone in a page */ struct memcons_desc msglog_desc __section(".data.memcons") = { @@ -264,7 +265,17 @@ ssize_t write(int fd __unused, const void *buf, size_t count) /* flushes the msglog into the inmem_con */ static size_t msglog_glue(const char *buf, size_t len) { - return write(0, buf, len); + int i; + + lock(&dummy_con_lock); + for (i = 0; i < len; i++) + inmem_write(&inmem_con, buf[i]); +#ifdef MAMBO_DEBUG_CONSOLE + mambo_console_write(buf, len); +#endif + unlock(&dummy_con_lock); + + return len; } static struct con_ops dummy_con_glue = { @@ -286,17 +297,20 @@ static size_t inmem_read(struct memcons *mcon, char *buf, size_t req) return read; } -ssize_t read(int fd __unused, void *buf, size_t req_count) +ssize_t __noreturn read(int fd, void *buf, size_t req_count) { - bool need_unlock = lock_recursive(&con_lock); - size_t count = 0; + /* + * We keep write() around because our libc stdio functions need it, and + * there's a few bits of library code that call fprintf and friends. + * + * There's no real use case for read() inside skiboot so we should + * never hit this path. + */ + (void) fd; + (void) buf; + (void) req_count; - /* NB: we are reading the input buffer of inmem_con, *not* msglog */ - if (!count) - count = inmem_read(&inmem_con, buf, req_count); - if (need_unlock) - unlock(&con_lock); - return count; + abort(); } /* Helper function to perform a full synchronous flush */ @@ -385,14 +399,13 @@ void msglog_add_properties(void) * The default OPAL console. * * In the absence of a "real" OPAL console driver we handle the OPAL_CONSOLE_* - * calls by writing into the skiboot log buffer. Reads are a little more - * complicated since they can come from the in-memory console (BML) or from the - * internal skiboot console driver. + * calls by writing into the in-memory console. Since this is entirely in-memory + * some external tooling is required to actually read the console. */ static int64_t dummy_console_write(int64_t term_number, __be64 *length, const uint8_t *buffer) { - uint64_t l; + uint64_t i, l; if (term_number != 0) return OPAL_PARAMETER; @@ -401,7 +414,17 @@ static int64_t dummy_console_write(int64_t term_number, __be64 *length, return OPAL_PARAMETER; l = be64_to_cpu(*length); - write(0, buffer, l); + + lock(&dummy_con_lock); + + for (i = 0; i < l; i++) + inmem_write(&inmem_con, buffer[i]); +#ifdef MAMBO_DEBUG_CONSOLE + mambo_console_write(buffer, l); +#endif + + /* updating l isn't required since we used all of the buffer */ + unlock(&dummy_con_lock); return OPAL_SUCCESS; } @@ -432,11 +455,16 @@ static int64_t dummy_console_read(int64_t term_number, __be64 *length, if (!opal_addr_valid(length) || !opal_addr_valid(buffer)) return OPAL_PARAMETER; + lock(&dummy_con_lock); + l = be64_to_cpu(*length); - l = read(0, buffer, l); + l = inmem_read(&inmem_con, buffer, l); + *length = cpu_to_be64(l); opal_update_pending_evt(OPAL_EVENT_CONSOLE_INPUT, 0); + unlock(&dummy_con_lock); + return OPAL_SUCCESS; } @@ -449,7 +477,7 @@ static void dummy_console_poll(void *data __unused) { bool has_data = false; - lock(&con_lock); + lock(&dummy_con_lock); if (inmem_con.desc->in_prod != inmem_con.desc->in_cons) has_data = true; if (has_data) @@ -457,7 +485,7 @@ static void dummy_console_poll(void *data __unused) OPAL_EVENT_CONSOLE_INPUT); else opal_update_pending_evt(OPAL_EVENT_CONSOLE_INPUT, 0); - unlock(&con_lock); + unlock(&dummy_con_lock); } void dummy_console_add_nodes(void)