Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp188199rdb; Thu, 19 Oct 2023 01:02:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGam3dNtwsvK17v5rGiTa6WfFNCyUFlD/ebO4UIJJpncYPN+h9gfaYv9b2zCh7OIMPICMhp X-Received: by 2002:a05:6602:2e10:b0:785:5917:a35f with SMTP id o16-20020a0566022e1000b007855917a35fmr1677325iow.8.1697702535717; Thu, 19 Oct 2023 01:02:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697702535; cv=none; d=google.com; s=arc-20160816; b=yJcQGggO0J5/Jkob3JTqLp7GxcHGrbdu/jfjpgeCb5TnT42Or8E2LvQHgVTRx9F734 PB10irhAzEZ6K9yLBhGAMo6Evrc+rU6Itp45rfLYB/+ueDHtCWeBDpaLDLUWGQ1DzISX SBI2v7ppPsEQtIgD3IvOLgCY0LStKh2futLJrv21ZZ4Oonv/LAq0GsQY5zpJZDcjqwww 4CaRkm47JzHjS0rLmS2oCNAegSvlzYqwLWAUufdVYUoUxJ60LmrtbQsVdBAWIQbJP/aO JQy1WXXbCzgprnbF+QTFz2Fidbd8tfjvNCJUFDVceEzgC1BINg1ciIUQhSxtIuxGeAZL oRKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=wThBUxBh7v0znNn0ZPl0WI7OQvkdGdCrZ1lZ3b6Zyy4=; fh=HphsaL+YRSr8xSEjXKGEGNHhmBU1p3niIw2svRX7Lek=; b=tMF6LprW02OS/XG5CQejOKlwc6d7//dJWL4QDrBhAcuknKmjmTmsdrGaZKHudr8Ec3 0SAkkXnxJykJOofeGA+AJ8viF+w//mZCiN1XWMsZMXJYnFp9EQIvd5vGetMub79WzeKw NzpAIp1jT54WRs+qIFvBQo7t2X/2p2Hsc1OTxwtefHIX1rCDZDiUgCZUX3hPVSGWzThR gN7FswF/D5Uq7xvXvYnMHrmS8bqZSgGi6taSnGt3fuCQKp7yhHwyvY1aO6Yf5Z2EqSVA FHleTqawXbWTB8ZJWPtLwt49bSpmOclpoF67UHJtMWG75JGrJVzZJKkKRnTT4LTCQiOY fsqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=TKDKNnH7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id c18-20020a056a00009200b0068a6f573f6asi4340636pfj.213.2023.10.19.01.02.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 01:02:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=TKDKNnH7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id EE53E8135BE4; Thu, 19 Oct 2023 01:02:12 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344867AbjJSICA (ORCPT + 99 others); Thu, 19 Oct 2023 04:02:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232829AbjJSIB7 (ORCPT ); Thu, 19 Oct 2023 04:01:59 -0400 Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B5F912F for ; Thu, 19 Oct 2023 01:01:57 -0700 (PDT) Received: by mail-lj1-x231.google.com with SMTP id 38308e7fff4ca-2c50906f941so90378131fa.2 for ; Thu, 19 Oct 2023 01:01:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1697702515; x=1698307315; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=wThBUxBh7v0znNn0ZPl0WI7OQvkdGdCrZ1lZ3b6Zyy4=; b=TKDKNnH7UEYugL3PqHv4G/pue0itDTbyzaWo4llf4Jg5vd7fKtuAYkA5nJpkma0VZV b7md8SubrS+e136mFp1dk48jczJRFHnqvLCgLIVNHiqavQUTHDVi+AIGUdQoS3g3Rkyk fsUQCSwrUcUTSIb3A5ngKK4jA83PTx8dynJkIH1iETBUXNj4KjRIXZOIpqoYM3O33pn5 S7MMRIMmwqnjtcCD8eu5bRjfCuD/tcpJpjGf9yzfI7R7+ZtDsoFoYFSq8pJe6P11Mj0/ wcxsOWxzYnjSyKbBqK1Z7dxKC2RaI6NXPJ5Igmx0c10jouzK2ddM3g4NeR74AvPTrt9X Xrbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697702515; x=1698307315; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=wThBUxBh7v0znNn0ZPl0WI7OQvkdGdCrZ1lZ3b6Zyy4=; b=QLG+pGKUXYRBoBCQ/YQYpKYq1Cz5mffhxaG0tVtPV10d9riIZA+GgP2QrhRyDIZRUs wDW7nSoMv+X8Bp6Ngo3qhxGU6buvwLcs5NckSjndXaxOpuIWEYwzLp4582Z6uHAsvura 0ViDUXf0hRt04QhN3f4ICjaWpnNjRwcNRZ4ldCcUiJGlNoIA29BFCQOjbyNYkPTKm/wl AMrZ4yAUHKcEgiJGsBB7mGACv+RqpnSNB+/sDox6XXu1w9MaD8wLebRjlFGCqRjcA13m rp7FN8GgLUaEuV6O4XggFwtFSY7jm0HQWonRdZ362AUCQPL2xRUVcmhegdNE7IU0gY87 RaSQ== X-Gm-Message-State: AOJu0YyMZklzerlJq+LKl5vkcTsgKK3RMKpuZodmCoMnnUjiU7g3RMI0 jjnic4DAhrgVPC6O4tmG8aHRTg== X-Received: by 2002:a2e:bc04:0:b0:2c5:13e8:e6dc with SMTP id b4-20020a2ebc04000000b002c513e8e6dcmr1149965ljf.31.1697702515155; Thu, 19 Oct 2023 01:01:55 -0700 (PDT) Received: from localhost (cst2-173-16.cust.vodafone.cz. [31.30.173.16]) by smtp.gmail.com with ESMTPSA id je6-20020a05600c1f8600b004063ea92492sm3790133wmb.22.2023.10.19.01.01.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 01:01:54 -0700 (PDT) Date: Thu, 19 Oct 2023 10:01:53 +0200 From: Andrew Jones To: Anup Patel Cc: Paolo Bonzini , Atish Patra , Palmer Dabbelt , Paul Walmsley , Greg Kroah-Hartman , Jiri Slaby , Conor Dooley , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-serial@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 4/8] RISC-V: KVM: Forward SBI DBCN extension to user-space Message-ID: <20231019-5e79c16a0731f60d862ddfff@orel> References: <20231012051509.738750-1-apatel@ventanamicro.com> <20231012051509.738750-5-apatel@ventanamicro.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231012051509.738750-5-apatel@ventanamicro.com> X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 19 Oct 2023 01:02:13 -0700 (PDT) On Thu, Oct 12, 2023 at 10:45:05AM +0530, Anup Patel wrote: > The frozen SBI v2.0 specification defines the SBI debug console > (DBCN) extension which replaces the legacy SBI v0.1 console > functions namely sbi_console_getchar() and sbi_console_putchar(). > > The SBI DBCN extension needs to be emulated in the KVM user-space > (i.e. QEMU-KVM or KVMTOOL) so we forward SBI DBCN calls from KVM > guest to the KVM user-space which can then redirect the console > input/output to wherever it wants (e.g. telnet, file, stdio, etc). > > The SBI debug console is simply a early console available to KVM > guest for early prints and it does not intend to replace the proper > console devices such as 8250, VirtIO console, etc. > > Signed-off-by: Anup Patel > --- > arch/riscv/include/asm/kvm_vcpu_sbi.h | 1 + > arch/riscv/include/uapi/asm/kvm.h | 1 + > arch/riscv/kvm/vcpu_sbi.c | 4 ++++ > arch/riscv/kvm/vcpu_sbi_replace.c | 32 +++++++++++++++++++++++++++ > 4 files changed, 38 insertions(+) > > diff --git a/arch/riscv/include/asm/kvm_vcpu_sbi.h b/arch/riscv/include/asm/kvm_vcpu_sbi.h > index c02bda5559d7..6a453f7f8b56 100644 > --- a/arch/riscv/include/asm/kvm_vcpu_sbi.h > +++ b/arch/riscv/include/asm/kvm_vcpu_sbi.h > @@ -73,6 +73,7 @@ extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_ipi; > extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_rfence; > extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_srst; > extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_hsm; > +extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_dbcn; > extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_experimental; > extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_vendor; > > diff --git a/arch/riscv/include/uapi/asm/kvm.h b/arch/riscv/include/uapi/asm/kvm.h > index 917d8cc2489e..60d3b21dead7 100644 > --- a/arch/riscv/include/uapi/asm/kvm.h > +++ b/arch/riscv/include/uapi/asm/kvm.h > @@ -156,6 +156,7 @@ enum KVM_RISCV_SBI_EXT_ID { > KVM_RISCV_SBI_EXT_PMU, > KVM_RISCV_SBI_EXT_EXPERIMENTAL, > KVM_RISCV_SBI_EXT_VENDOR, > + KVM_RISCV_SBI_EXT_DBCN, > KVM_RISCV_SBI_EXT_MAX, > }; > > diff --git a/arch/riscv/kvm/vcpu_sbi.c b/arch/riscv/kvm/vcpu_sbi.c > index 1b1cee86efda..bb76c3cf633f 100644 > --- a/arch/riscv/kvm/vcpu_sbi.c > +++ b/arch/riscv/kvm/vcpu_sbi.c > @@ -66,6 +66,10 @@ static const struct kvm_riscv_sbi_extension_entry sbi_ext[] = { > .ext_idx = KVM_RISCV_SBI_EXT_PMU, > .ext_ptr = &vcpu_sbi_ext_pmu, > }, > + { > + .ext_idx = KVM_RISCV_SBI_EXT_DBCN, > + .ext_ptr = &vcpu_sbi_ext_dbcn, > + }, > { > .ext_idx = KVM_RISCV_SBI_EXT_EXPERIMENTAL, > .ext_ptr = &vcpu_sbi_ext_experimental, > diff --git a/arch/riscv/kvm/vcpu_sbi_replace.c b/arch/riscv/kvm/vcpu_sbi_replace.c > index 7c4d5d38a339..23b57c931b15 100644 > --- a/arch/riscv/kvm/vcpu_sbi_replace.c > +++ b/arch/riscv/kvm/vcpu_sbi_replace.c > @@ -175,3 +175,35 @@ const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_srst = { > .extid_end = SBI_EXT_SRST, > .handler = kvm_sbi_ext_srst_handler, > }; > + > +static int kvm_sbi_ext_dbcn_handler(struct kvm_vcpu *vcpu, > + struct kvm_run *run, > + struct kvm_vcpu_sbi_return *retdata) > +{ > + struct kvm_cpu_context *cp = &vcpu->arch.guest_context; > + unsigned long funcid = cp->a6; > + > + switch (funcid) { > + case SBI_EXT_DBCN_CONSOLE_WRITE: > + case SBI_EXT_DBCN_CONSOLE_READ: > + case SBI_EXT_DBCN_CONSOLE_WRITE_BYTE: > + /* > + * The SBI debug console functions are unconditionally > + * forwarded to the userspace. > + */ > + kvm_riscv_vcpu_sbi_forward(vcpu, run); > + retdata->uexit = true; > + break; > + default: > + retdata->err_val = SBI_ERR_NOT_SUPPORTED; > + } > + > + return 0; > +} > + > +const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_dbcn = { > + .extid_start = SBI_EXT_DBCN, > + .extid_end = SBI_EXT_DBCN, > + .default_unavail = true, > + .handler = kvm_sbi_ext_dbcn_handler, > +}; > -- > 2.34.1 > Reviewed-by: Andrew Jones