Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp2267852pxb; Thu, 3 Feb 2022 03:07:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJzomfDc/RhUTzoipIxbOtv2BhYZeggpsq3K6lKiFabPJwQ78+6mVzlWwLT7/gKQRTqJL1Od X-Received: by 2002:a63:1655:: with SMTP id 21mr27560938pgw.498.1643886458979; Thu, 03 Feb 2022 03:07:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643886458; cv=none; d=google.com; s=arc-20160816; b=TMDoNL7drgaMwL3tl+ZoqAsJqPNiBtqgvrJNY93RkM1zjTSmfTFrA4e3H/VqlCEfiN Sj9ZWiqh52GKmsMw7XLGgh4Jxbot4cHGafoMMOgdQF/N42gTVUfl15E9ovxCczqpVHah JmSifT37zS2jMW3VgYY11L1L9H4kZzKSHtMoZj61S9Tq7DzdjKLnLlsqSayhjxNX+0iF FWjBUdPC5B1SGwTW1ti/RiPYnN7++Npa9exu4kyb6Is2zgt1/Ma0V17m+v+bxwUJEvaB GZtfZhkgF3RH8GvPQXpvbL8cFkINrKaJZuAWEH6PsFY8xPJBSeW9GKuUh9ZF7Z3XXfjB 8V0w== 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=T8jkwpaTNUs5ESeTMvPF9Tbpyy5JKY953H6W28s28Gw=; b=m1JdTsF/YEi1BJH3AJcRa4o68dMGiJ/c7iDaMqpQOzWDciZcahwjv0kJa36QLyoAzZ t8f4AUs1KjxOxEKICMBadQwExaydquHRe79ne1x+9ow9sdc2sW58ywuvWlVghNgwau8V A0OQVZwOux6yDl50ahZC2WNFl7lVgE+OqhrKyh7a97Tpn+JzkmHMe/ZwU7h8Yg3tPdrz oanb2t9E7WNP5fokYF8LF5rmt6NIXlvU708x00Ui0OI5wUrAZajb+wCat05qHfgFiE7j k4FmkkzPucQxR+jDK2oZw9GFX6XM/XfIDKhZXRnhXmu3wiNVKjlfReGdytZgM3pChaE9 uzWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=ngcy4rQ1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a22si7131526pjq.61.2022.02.03.03.07.25; Thu, 03 Feb 2022 03:07:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=ngcy4rQ1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235465AbiBAIX4 (ORCPT + 99 others); Tue, 1 Feb 2022 03:23:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235461AbiBAIXz (ORCPT ); Tue, 1 Feb 2022 03:23:55 -0500 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB4D8C061714 for ; Tue, 1 Feb 2022 00:23:54 -0800 (PST) Received: by mail-ed1-x531.google.com with SMTP id u24so32244786eds.11 for ; Tue, 01 Feb 2022 00:23:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=T8jkwpaTNUs5ESeTMvPF9Tbpyy5JKY953H6W28s28Gw=; b=ngcy4rQ1Tpgrp9QzjvjPpqlVgEEEjqUKlV9f6VgLlo3oZPaCeQ7cPAESbm6F2HSzDM paNnr/LcQOSSotljA3esNoziLPThU5dSkiW4AQT1KrCJ9zkf1JDCYAN6aKYxd8akcqcX jvZxUF3iKLDGyAi9OE7LyyWgCLx3i7/oiQWaRChkSaQ1gOBdS9wRWZz6Ptio+n8+qEr8 9X1Np23oxzKTJSrFLRSmuLariV7eZqgzOOOkc4O9OgvbIc36GNjHYi4hXo/br2l0I8Aa y3IYbsaAGoRHvL+OFw2J90Y6uFAA+dp+NYQxTJ6hzTuVNihOXwkIQevryg1IPiuLIAC/ Dn1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=T8jkwpaTNUs5ESeTMvPF9Tbpyy5JKY953H6W28s28Gw=; b=HJYP2JhST8I4hMewHWUaTC6bKv4k5mhjsnz7Inkq3kTROYQxqAEO/Wh8QcUw8LBKZA js/mgNLkHv2zuLJeUMeLHX91jYqcdoVrhVC5vqMqZ6Kcd4nlCQXB8/0NdnjB6r4kcSXO IjYqDJwuhVLpp2GuosW62qIqHGtFm92EChTkyDQ1zUZD0TMDePCU6IcCXozW/dTDaA4d 9XoIMqOXlb6a3Upjljsbr3dUmW9UTETiA+LQ9+ziFUVoecJe/tAPoe/KAdiqQhF44h04 cVR8NbOaXWVFI568YhS1PXuqTavwDptPikstG1Uv1lBnKaQc7ccafq4x0gcSD8Bytn7n H6Vg== X-Gm-Message-State: AOAM533I/D3Mw1lZ7YSeEgzFiCxbUcvRCDBicLtqHt4jL5n6xkStZkBc LcNO3y76jSKWvqvUCPG5Jd3BCw== X-Received: by 2002:a05:6402:1774:: with SMTP id da20mr24004748edb.372.1643703833389; Tue, 01 Feb 2022 00:23:53 -0800 (PST) Received: from localhost.localdomain ([122.179.76.38]) by smtp.gmail.com with ESMTPSA id w8sm14312133ejq.220.2022.02.01.00.23.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 00:23:52 -0800 (PST) From: Anup Patel To: Paolo Bonzini , Atish Patra Cc: Palmer Dabbelt , Paul Walmsley , Albert Ou , Alistair Francis , Anup Patel , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Anup Patel Subject: [PATCH 3/6] RISC-V: KVM: Implement SBI v0.3 SRST extension Date: Tue, 1 Feb 2022 13:52:24 +0530 Message-Id: <20220201082227.361967-4-apatel@ventanamicro.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220201082227.361967-1-apatel@ventanamicro.com> References: <20220201082227.361967-1-apatel@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The SBI v0.3 specification defines SRST (System Reset) extension which provides a standard poweroff and reboot interface. This patch implements SRST extension for the KVM Guest. Signed-off-by: Anup Patel --- arch/riscv/kvm/vcpu_sbi.c | 2 ++ arch/riscv/kvm/vcpu_sbi_replace.c | 44 +++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/arch/riscv/kvm/vcpu_sbi.c b/arch/riscv/kvm/vcpu_sbi.c index 11ae4f621f0d..a09ecb97b890 100644 --- a/arch/riscv/kvm/vcpu_sbi.c +++ b/arch/riscv/kvm/vcpu_sbi.c @@ -45,6 +45,7 @@ extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_base; extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_time; 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_experimental; extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_vendor; @@ -55,6 +56,7 @@ static const struct kvm_vcpu_sbi_extension *sbi_ext[] = { &vcpu_sbi_ext_time, &vcpu_sbi_ext_ipi, &vcpu_sbi_ext_rfence, + &vcpu_sbi_ext_srst, &vcpu_sbi_ext_hsm, &vcpu_sbi_ext_experimental, &vcpu_sbi_ext_vendor, diff --git a/arch/riscv/kvm/vcpu_sbi_replace.c b/arch/riscv/kvm/vcpu_sbi_replace.c index 1bc0608a5bfd..0f217365c287 100644 --- a/arch/riscv/kvm/vcpu_sbi_replace.c +++ b/arch/riscv/kvm/vcpu_sbi_replace.c @@ -130,3 +130,47 @@ const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_rfence = { .extid_end = SBI_EXT_RFENCE, .handler = kvm_sbi_ext_rfence_handler, }; + +static int kvm_sbi_ext_srst_handler(struct kvm_vcpu *vcpu, + struct kvm_run *run, + unsigned long *out_val, + struct kvm_cpu_trap *utrap, bool *exit) +{ + struct kvm_cpu_context *cp = &vcpu->arch.guest_context; + unsigned long funcid = cp->a6; + u32 reason = cp->a1; + u32 type = cp->a0; + int ret = 0; + + switch (funcid) { + case SBI_EXT_SRST_RESET: + switch (type) { + case SBI_SRST_RESET_TYPE_SHUTDOWN: + kvm_riscv_vcpu_sbi_system_reset(vcpu, run, + KVM_SYSTEM_EVENT_SHUTDOWN, + reason); + *exit = true; + break; + case SBI_SRST_RESET_TYPE_COLD_REBOOT: + case SBI_SRST_RESET_TYPE_WARM_REBOOT: + kvm_riscv_vcpu_sbi_system_reset(vcpu, run, + KVM_SYSTEM_EVENT_RESET, + reason); + *exit = true; + break; + default: + ret = -EOPNOTSUPP; + } + break; + default: + ret = -EOPNOTSUPP; + } + + return ret; +} + +const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_srst = { + .extid_start = SBI_EXT_SRST, + .extid_end = SBI_EXT_SRST, + .handler = kvm_sbi_ext_srst_handler, +}; -- 2.25.1