From patchwork Wed Apr 19 22:17:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 1770918 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=tmSLiVho; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=casper.20170209 header.b=aJDIsxHy; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=rivosinc-com.20221208.gappssmtp.com header.i=@rivosinc-com.20221208.gappssmtp.com header.a=rsa-sha256 header.s=20221208 header.b=g8HGuVmD; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q1wf10F5Nz23tD for ; Thu, 20 Apr 2023 08:37:28 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=BtlAOTd4YPL+n2UHsTlVfsQ0q7fvoM6lflV3IzA5mpo=; b=tmSLiVhoHjq/MI cm1iholb6DQPLpAGewBh7AbKpQwby5Rt+P6pXqGPUmilhYVDMLGxMZiLpm31mbmLs0MH26JNsqyti k0iUwbm252Cca8qC3OCcFkQ7++Hc87U5gDC0AxeLVmJtQp5D83He3l3g1As7OkiLNh9CAT02cnsdb 5SeWYpiOuGMkNpxqB+w3iKzcfYZfmxaDXXXKF9wcgq1yBp/o8+0CMv/iJ6oQX5FpwLBL6jKgt7SBN zRMkzcHf+pCP8iiFa/dJuIEyF2GOa0ZdPmB1I6SVF+6rzGt1/zRUWJIeJIHSrcQLMOFxrFql3z7yI wXMpFasQRNBN1Kya8msA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1ppGQX-006WYi-01; Wed, 19 Apr 2023 22:37:25 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1ppGQV-006WXV-2C for kvm-riscv@bombadil.infradead.org; Wed, 19 Apr 2023 22:37:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=8fg2apWNkO7XMTsfLYU3rTZlWorsx4wHesUuN9ZGrN4=; b=aJDIsxHy0U90TaB85Ab8FjtZHN pwCf4+Epj+7Q1SkYK7Bq35l84iPjYgb+LAak8KB3BBxevrGeCadB+PzPYDv8M6L4cpSlAKvh9QxOK Xanp9ysa8per7nP5RKwEdDM1woWXDCcpB4GKMA53osNmZO7i82gK+extSsAQW1nglJJM0rdUmro1E 3junK28evu/rGDATHKAUzHvfetdAhdYWQqOC70t9Vmgg9o3KWfijmpd+PGOIv8NzA+/TGgEfHrrab IHLWnLo5dmKgkCpJs2kPusle2nPc+YEW1jpot71UfgJ2muFnHytRDaJ/H4R5tk5DK26dMGz23Ohql 3iDDF1Rw==; Received: from mail-pl1-f169.google.com ([209.85.214.169]) by casper.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ppG8y-00DeQ1-TI for kvm-riscv@lists.infradead.org; Wed, 19 Apr 2023 22:19:18 +0000 Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1a686260adcso5390815ad.0 for ; Wed, 19 Apr 2023 15:19:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1681942754; x=1684534754; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8fg2apWNkO7XMTsfLYU3rTZlWorsx4wHesUuN9ZGrN4=; b=g8HGuVmDd6hY+lMcoFR1p/zerf1IBaVcRH5kNxjG8cnb+FPy7JiKlP8xFMLawWOJHX 8MxTVIaCIdLr6Ccp55qIHAejxBF5J0nZ/QJIh66AwlqKb1gy2DUEWlLH+BzQR5o+T67+ kKooYcWWcij0NvxWxb05YPJbKR63uF1OQBv02Tg7GGtGx4ZWKWirSARZVPhbGcCUYnPY 6NUmTXcNFvsNN28a27iL5OcLCC76rPHgwAm1ISi/TugfdDtHR47w4bW7o0MafWBEn9ey E/SyyfLa4ioudzzGIw9EwQwg7+Rg1abk6H2BVftGz286pLz6P5MCHu2QYJA07cO/VmFG Q9lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681942754; x=1684534754; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8fg2apWNkO7XMTsfLYU3rTZlWorsx4wHesUuN9ZGrN4=; b=XITEX9CedrdVJzabAtC7zhaN9N4M3+1b/ciQxxqWozeE7Mn0rq9sYx4zqvPXGqF0qL yPSm2VkYdpEl1XNhMwcINVE7CbcNWOUUc218Cds7fwiipeZUHCba7LV1u5wjOVmpLXap WvBqArXH6SDtvvuU3kmCEc5fzttMZm4W/m80OAv7nGMwDmmmtT8udpuaeO5HDEWQXWYp zsliEf85aGeNChVpZaqTwIkaALsYPAFWYKvyVVIIwj5Trk0MqyuKZ3Q/n7hejqHRMXoW DCbKCp22990Hv162+TcDOXK9P1gH6f5qny5TVMI9LDfbWaFPvcl3YtELZzK+Sq3B58by XTNA== X-Gm-Message-State: AAQBX9eL4AGSmWZDjJkb0ou76P3jnK8YMcgZ0TjV3GX0g0p1BHAonITi Q3fVmaJJTXymD4bRyIVVkjUlZw== X-Google-Smtp-Source: AKy350bcbgE/EJ3Ej08OUUDHS562dStL1nY59dRLyQva3UBkO8qD2X/slMFNk57ZH7aSQKcUf51qPw== X-Received: by 2002:a17:902:a504:b0:1a1:be45:9857 with SMTP id s4-20020a170902a50400b001a1be459857mr6646673plq.1.1681942754165; Wed, 19 Apr 2023 15:19:14 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id jn11-20020a170903050b00b00196807b5189sm11619190plb.292.2023.04.19.15.19.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 15:19:13 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Rajnesh Kanwal , Atish Patra , Alexandre Ghiti , Andrew Jones , Andrew Morton , Anup Patel , Atish Patra , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Suzuki K Poulose , Will Deacon , Marc Zyngier , Sean Christopherson , linux-coco@lists.linux.dev, Dylan Reid , abrestic@rivosinc.com, Samuel Ortiz , Christoph Hellwig , Conor Dooley , Greg Kroah-Hartman , Guo Ren , Heiko Stuebner , Jiri Slaby , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, Mayuresh Chitale , Palmer Dabbelt , Paolo Bonzini , Paul Walmsley , Uladzislau Rezki Subject: [RFC 47/48] RISC-V: Add shared bounce buffer to support DBCN for CoVE Guest. Date: Wed, 19 Apr 2023 15:17:15 -0700 Message-Id: <20230419221716.3603068-48-atishp@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230419221716.3603068-1-atishp@rivosinc.com> References: <20230419221716.3603068-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230419_231917_006190_49DC9A59 X-CRM114-Status: GOOD ( 16.27 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.4.6 on casper.infradead.org summary: Content analysis details: (-1.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.214.169 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [209.85.214.169 listed in list.dnswl.org] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 T_SCC_BODY_TEXT_LINE No description available. 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Rajnesh Kanwal Early console buffer needs to be shared with the host for CoVE Guest. Signed-off-by: Rajnesh Kanwal Signed-off-by: Atish Patra --- drivers/tty/serial/earlycon-riscv-sbi.c | 51 ++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/earlycon-riscv-sbi.c b/drivers/tty/serial/earlycon-riscv-sbi.c index 311a4f8..9033cca 100644 --- a/drivers/tty/serial/earlycon-riscv-sbi.c +++ b/drivers/tty/serial/earlycon-riscv-sbi.c @@ -9,6 +9,14 @@ #include #include #include +#include +#include +#include + +#ifdef CONFIG_RISCV_COVE_GUEST +#define DBCN_BOUNCE_BUF_SIZE (PAGE_SIZE) +static char dbcn_buf[DBCN_BOUNCE_BUF_SIZE] __aligned(PAGE_SIZE); +#endif #ifdef CONFIG_RISCV_SBI_V01 static void sbi_putc(struct uart_port *port, unsigned char c) @@ -24,6 +32,33 @@ static void sbi_0_1_console_write(struct console *con, } #endif +#ifdef CONFIG_RISCV_COVE_GUEST +static void sbi_dbcn_console_write_cove(struct console *con, const char *s, + unsigned int n) +{ + phys_addr_t pa = __pa(dbcn_buf); + unsigned int off = 0; + + while (off < n) { + const unsigned int rem = n - off; + const unsigned int size = + rem > DBCN_BOUNCE_BUF_SIZE ? DBCN_BOUNCE_BUF_SIZE : rem; + + memcpy(dbcn_buf, &s[off], size); + + sbi_ecall(SBI_EXT_DBCN, SBI_EXT_DBCN_CONSOLE_WRITE, +#ifdef CONFIG_32BIT + size, pa, (u64)pa >> 32, +#else + size, pa, 0, +#endif + 0, 0, 0); + + off += size; + } +} +#endif + static void sbi_dbcn_console_write(struct console *con, const char *s, unsigned n) { @@ -45,14 +80,26 @@ static int __init early_sbi_setup(struct earlycon_device *device, /* TODO: Check for SBI debug console (DBCN) extension */ if ((sbi_spec_version >= sbi_mk_version(1, 0)) && - (sbi_probe_extension(SBI_EXT_DBCN) > 0)) + (sbi_probe_extension(SBI_EXT_DBCN) > 0)) { +#ifdef CONFIG_RISCV_COVE_GUEST + if (is_cove_guest()) { + ret = sbi_covg_share_memory(__pa(dbcn_buf), + DBCN_BOUNCE_BUF_SIZE); + if (ret) + return ret; + + device->con->write = sbi_dbcn_console_write_cove; + return 0; + } +#endif device->con->write = sbi_dbcn_console_write; - else + } else { #ifdef CONFIG_RISCV_SBI_V01 device->con->write = sbi_0_1_console_write; #else ret = -ENODEV; #endif + } return ret; }