Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp843122rdb; Fri, 20 Oct 2023 00:23:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG47eiZw0rnre2WNo/sjo8YTNX2156DIxdx/wABNNPPxcixoK2vpQtpwQVdnL7tYtIWilP6 X-Received: by 2002:a05:6358:428e:b0:166:c0e6:e7c2 with SMTP id s14-20020a056358428e00b00166c0e6e7c2mr1049257rwc.22.1697786615719; Fri, 20 Oct 2023 00:23:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697786615; cv=none; d=google.com; s=arc-20160816; b=NJKaBQZMlwZO5q6n0mM2Y4twNJA8dqipZUTj20HiEWdIQBf8/H39azJ8oMEHxFaJGO rZTYPNPbXJX6+rOz5Bkg0R7HdTeO9adGXz1EW4oV7du/RI9C9PAvqg7hvo3sGD/JNIuJ unOFdPl/a9WN/BUW3PlRFTWaG4fmD4ClPRHH2qG2ZQumATFmGj6pzn9eRREbaXmlH+Xy 24gvIumfm+30Lktx9T9GLf6bPAzTQJFmbvh3GdRQlgH8cDdD0rbPTbcfhGcZr6qw6J4j sBewF5Ob7JM3t6DgfwjQPOEqjbNRN2yxWiiM84PsDOFrnypJS3Eg/Fujplgz2wi88lbf GCgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=hO8QQxSKIIq22xFRYvu7Gu8eaqjv2hPcSOTMD/z9e94=; fh=7GYORjoWw1oF4BCDuq40hd+MOEKRwzNqXwnZ/K2vS9Q=; b=GaD5JFnEh1ii3rTncZDCW8BzxBxwtMjX41XS8UedneVVc/7xpXtWvps2Fczn32iQnl J2sgdqpHNv4ZuvEAXgN8hma0RMZmaBwG3lzC/jxtohIFyLtu2VLYcjGkMCn7+PP2Rnf7 uKE5eUpDBwDpSYbXL9FEhA8HOB6RRMIEDyksFtUiQApiQW4r5fH2aDuPKOh39QZgoHRA 7k9M/JEGnqstx6My6tb432mDqT0EGHDRZLTWTQrWGf6LxgGEZ76t6u+go4VqSFH9/Z6x VaBX0aJDyMP0Uq0F/r9cEJZWAS9GUSVtD4IPfcyocxI5Y2PnA6Fpxs8NGezEanWlqX2x s3Aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=NF++K+IH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id o17-20020a639a11000000b005b87ec98b7csi476604pge.285.2023.10.20.00.23.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 00:23:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=NF++K+IH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id B3F5580AAF22; Fri, 20 Oct 2023 00:22:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376421AbjJTHWX (ORCPT + 99 others); Fri, 20 Oct 2023 03:22:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376415AbjJTHWQ (ORCPT ); Fri, 20 Oct 2023 03:22:16 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E42C10CC for ; Fri, 20 Oct 2023 00:22:08 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-6bee11456baso463223b3a.1 for ; Fri, 20 Oct 2023 00:22:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1697786528; x=1698391328; darn=vger.kernel.org; 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=hO8QQxSKIIq22xFRYvu7Gu8eaqjv2hPcSOTMD/z9e94=; b=NF++K+IHtiFmgzrSHLZgrw41LakLY8FUKgQny7rh/tQlqYxqoIAw3AKCFRiZWavtif BMMFkeFZSDxixW4/Yb0ITH9n5zesJUE1Z1JbWE7+0ZUa9LzP7dR7BxshCbs9//6+Rs4U YMotsWDeueiyVfEDFKm1T8pyaltg5uHQG2SN+fxJIWrQSIPkDH1qxonOfwBpU2WK1LUM YOMXwJQhxG6JK0bJPmX7Etl3NMvR52RLmYtSjeE2LPYNaLyqSuqaGtWIEavZ3j3j5VwN rcUiu4zoUjtplmeGYDlwe2Yuh/Cw1kPLDbCKH1PS0yqmRDHsGryReQM+2Vp2wXmLCNBc cRQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697786528; x=1698391328; 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=hO8QQxSKIIq22xFRYvu7Gu8eaqjv2hPcSOTMD/z9e94=; b=a83/uHoAqh15UoDhs4s0CoIdaDx9lQ1h3pYZ5exjp43ejlyRwbL0oiiYVyyxSgNr3l UNc6sV3unFQ95jhUScdfEcT+kHNoUOZVq83F1XcX+jyfa6aWpwUwr3E+N76FaY0kkX3v KFi535/EHOMOlOboCCEsPgpy9SKToJRFIZeBAQFjZMIyqwlHYNv46VxlXFcUtkuY2xT0 I37qSUhGE0xu1dXrTcJQTQOhgGZ7TuNKV6+0dT5JBnyWNV5mC7oGditTJo1queaZgOlg 122syQMxzU61eBAB8+oB0F+hkK2DDP70yZuv1nPjZKZuJc5kTbw6s9InUjMEyxKBcQ0s BSyA== X-Gm-Message-State: AOJu0YwQrF8T4y4tftEX/1mEIM0+BnoI5HZuvcCc2318kWxM2RK0ImEN OTq5HP9qoBI0EW1O5o/ZNeAhkg== X-Received: by 2002:aa7:9622:0:b0:68e:42c9:74e0 with SMTP id r2-20020aa79622000000b0068e42c974e0mr952140pfg.3.1697786528093; Fri, 20 Oct 2023 00:22:08 -0700 (PDT) Received: from anup-ubuntu-vm.localdomain ([171.76.83.81]) by smtp.gmail.com with ESMTPSA id v12-20020a63f20c000000b005b32d6b4f2fsm828204pgh.81.2023.10.20.00.22.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 00:22:07 -0700 (PDT) From: Anup Patel To: Paolo Bonzini , Atish Patra , Palmer Dabbelt , Paul Walmsley , Greg Kroah-Hartman , Jiri Slaby Cc: Conor Dooley , Andrew Jones , 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, Anup Patel Subject: [PATCH v3 4/9] RISC-V: KVM: Forward SBI DBCN extension to user-space Date: Fri, 20 Oct 2023 12:51:35 +0530 Message-Id: <20231020072140.900967-5-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231020072140.900967-1-apatel@ventanamicro.com> References: <20231020072140.900967-1-apatel@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 morse.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 (morse.vger.email [0.0.0.0]); Fri, 20 Oct 2023 00:22:45 -0700 (PDT) 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 Reviewed-by: Andrew Jones --- 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 bda8b0b33343..a04ff98085d9 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