From patchwork Tue Feb 1 08:22:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12731484 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A3122C4321E for ; Tue, 1 Feb 2022 08:23:56 +0000 (UTC) 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=sKN4A3Q5R1WJmikUp2ghwV+kBNAsTNytpzFvXQmbYUc=; b=hp+fkxassQnZl4 c0sw+N9ea7zmC73S52x7TAHDKQny8fCpFhpsD4P64fUSIq45tAb78X8XGPyGM+EP7Iegv9TYzF0XX +ndaC4qIuo4YuLNFX2hXuNJilcZTO9yz5IC3gkHgvzCYsKrB0PVZS8KcawZtdunzgrHcTiMdt06Iz nLfKfBe3sF1choZIAYyCxuxiLkJ9xOvaU4hzSrqz+1ftYF3zS8y3TonvVViLnAhw/EY5DlLx7curH JdrA1pxK5K19z2fv8ZmDrm9X+vPdZfN+Q0RDRYSr91CbcFTll/RuCIWOpoxsZ6qZwetqDDRMS45TQ 8UbB/HR5uGAhhumyLZKg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nEoS3-00BVz0-K4; Tue, 01 Feb 2022 08:23:47 +0000 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nEoS0-00BVwx-NE for linux-riscv@lists.infradead.org; Tue, 01 Feb 2022 08:23:45 +0000 Received: by mail-ej1-x634.google.com with SMTP id k25so51269772ejp.5 for ; Tue, 01 Feb 2022 00:23:43 -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=moWXwRufmzv2uumLJS/9LAZ+TSxfYh9+Zsj12AAFml0=; b=megPh/BG5oFnZ49v1LXD50Xj/andQy3srFKAFC+gMyPjfTvGoYsIG3hfLiq4hYxtIB 8iuFJWW+cp099IAO893rjhKCAI7teY/UWouMMrE7TJQehbHyaDR3nAqwlqxmsgfSwBli 9f/DFJf4yXzoSnJA0VHLwRjiWbGW8jspI/EAtajH8hxW6yn7RfRW7Xs7xN/8j5u1MRLU sneA5mmfSueXTPSQvo+Qh1VoTKL8YJLj8VRO6qzHXLnTzddiOV77AdPRdMooMWFT/Wvf Rjubq2A6dSjKTSCKaLs390u3FQ7a+IlROa9jV9cSkyXu/5MwrnSW32MKoIqsVH+LaJf5 oR3Q== 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=moWXwRufmzv2uumLJS/9LAZ+TSxfYh9+Zsj12AAFml0=; b=23TKit9Z8sNejYYlLeTOYBQTT8KI/ujfrFsxIlE4xJ1HaOahxdHGXnPNlqWSwLR1JW Q7FZD0BOKKMqwlrN0jk9cfNhW0or5vaDxSfqeofOB6eClQ/rtTTj8Xe5Lg/Q3cvzbcAr EEY0BG00rbr7xJT9qoHxpX1Godxjo+TdV42x/ZQ7mNaIfOwcHJz8WQtFC54cP9TR18f6 KpKLYj1wk/CeZk/shSVnusOVPiyOjOP7Gq00Us0pzWPX/zCpghE3iyTbMMbk3kq1rTjn bnoistVwVfAlCLpf/00V+MBh49rATrDmhFs5O5m8q/qj7g9m0hPFz3kwRP4AhEAb2xew 9dYg== X-Gm-Message-State: AOAM533oKSPH4fGoL5MmJ7YNK1Rey0Km0GIqCunMP/r8cDfBVGVjGq4S 86sWBdK4Vkgg2QAp3epVIOCcW36w6BgDbQ== X-Google-Smtp-Source: ABdhPJzlSuQ0ORHAbwDAjB4y7DcyZYYBLC+IfC2qa+oxDfgJJAX2C9+sYwnhDEYPKiloCVEXgsoaNA== X-Received: by 2002:a17:907:1b16:: with SMTP id mp22mr20683012ejc.537.1643703822407; Tue, 01 Feb 2022 00:23:42 -0800 (PST) Received: from localhost.localdomain ([122.179.76.38]) by smtp.gmail.com with ESMTPSA id w8sm14312133ejq.220.2022.02.01.00.23.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 00:23:42 -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 1/6] RISC-V: KVM: Upgrade SBI spec version to v0.3 Date: Tue, 1 Feb 2022 13:52:22 +0530 Message-Id: <20220201082227.361967-2-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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220201_002344_784581_6581D3D8 X-CRM114-Status: GOOD ( 10.49 ) X-BeenThere: linux-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: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org We upgrade SBI spec version implemented by KVM RISC-V to v0.3 so that Guest kernel can probe and use SBI extensions added by the SBI v0.3 specification. Signed-off-by: Anup Patel Reviewed-by: Atish Patra --- arch/riscv/include/asm/kvm_vcpu_sbi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/kvm_vcpu_sbi.h b/arch/riscv/include/asm/kvm_vcpu_sbi.h index 76e4e17a3e00..04cd81f2ab5b 100644 --- a/arch/riscv/include/asm/kvm_vcpu_sbi.h +++ b/arch/riscv/include/asm/kvm_vcpu_sbi.h @@ -12,7 +12,7 @@ #define KVM_SBI_IMPID 3 #define KVM_SBI_VERSION_MAJOR 0 -#define KVM_SBI_VERSION_MINOR 2 +#define KVM_SBI_VERSION_MINOR 3 struct kvm_vcpu_sbi_extension { unsigned long extid_start; From patchwork Tue Feb 1 08:22:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12731485 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D75B5C433F5 for ; Tue, 1 Feb 2022 08:24:01 +0000 (UTC) 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=eKBu1EoXmpXaTzM0Drl+/A1XAYXjScBFqdvWpzUfInM=; b=aZITF3zguRL6uj R0z2QIAijJtyzPY4vMM4tCW+vee8rPh7zL+z0TuC0Q/JF8rUw0Wbb9sr4/fe7PasSJi04FIHVbMdE Aq69lKPe4FanA4nzqJH0+KzV95B3wlHNf4OUgWNKWeCjk+V3PuM3TCbTVkZLTL/0lT3B0p4bzXe9B fpyXGI8K8pIGUxL9iBg16TVZkMpNJCKhX5QHiT03mYmoqYxEIEAohCUInXIMYn9kebvRnnndaoQT1 lLVo4MixOgai7axpaE9+ZEfJ6ZHxQqqi8F8YaJyH4B9Q/wLWE9gHv2Uyb1P3HO5JQFXrOj9464JFB dvb9DOo9gU30zniybdBA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nEoS8-00BW2E-Vv; Tue, 01 Feb 2022 08:23:53 +0000 Received: from mail-ed1-x52b.google.com ([2a00:1450:4864:20::52b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nEoS5-00BVzL-B7 for linux-riscv@lists.infradead.org; Tue, 01 Feb 2022 08:23:50 +0000 Received: by mail-ed1-x52b.google.com with SMTP id b13so32695440edn.0 for ; Tue, 01 Feb 2022 00:23:48 -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=sWXOnh6V8JfeAKPCTBsP63fO+aHlS1gzo9x3i/6GE6E=; b=ALK239EPhhbKnBQAarVre2qSAgyqxLhsur30HkoKRHTo2K0etUwzSjub/fA46wqZ3v sffzujqr51nXRa0RVA/w900IKQe/5K2nW2xeUvbM3z5HVB5Mww8SVdM9ksqaIsHamZ4F DxgZjgkJQCPX8kyilf7tT711OgwoPLhiSVk70Dcjegj9YfCfMh5+JLK84AHcj/z+mk94 Q0Hg4lUV4uGHlNIDmfMxJXAFgtaX3aHORO9Ip6O6ajm47HWzYDDWL2+FO8poRRpKctLj zc3YsSLYUvtQSpoVIGfsG/Au+zCgQDvl5B09DcBGKkJVMPlAooidYwHY9OA4Affd9kMD TlyA== 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=sWXOnh6V8JfeAKPCTBsP63fO+aHlS1gzo9x3i/6GE6E=; b=8NBR7xwQ/Pu8GYVJ4PoLZwRcImww4OTmwgYogHOs+p/OWwvbW6Cn+/8kOMSTyepXZw glG/eBhOiJAXEu7kZUA3H8l27AgLEeOHS6r3f4XCAsUUWtrzTq4PTQOVmZf5i8Mf4zfn 00uGgCpEaPQpUjSB0dp7OzjCb8z345VlgOq5inLpVdQmn3PJhCBWMsDKYVweyjdwZKgv OX+wbzTfG4zI8fJCO+FvO/YqBy9O2shC88F17JtMbiAR9MliWW4+Y4etiDkarnQ7JIJA e23TerBhqcJQUR6/UPKZAsBKqTr3xUSPk9O/o4r+paavZD9jBwz83ozy0tJJVxDEueRP flZg== X-Gm-Message-State: AOAM532t1p2J4yKvEuP/wqjJv0snZ/54UkffzUTSucg30wA+7zOYxoCk eoh2ZoAOrvT/06XiPMSjuc+nadAOF2N1VQ== X-Google-Smtp-Source: ABdhPJzTHSniruOqGDVxhjoRjtvl1bsig8Zp56bbyZf9II8QjmoSPgsxbdftBMPgMX53XpxqtcWBeQ== X-Received: by 2002:aa7:d553:: with SMTP id u19mr24595529edr.298.1643703827873; Tue, 01 Feb 2022 00:23:47 -0800 (PST) Received: from localhost.localdomain ([122.179.76.38]) by smtp.gmail.com with ESMTPSA id w8sm14312133ejq.220.2022.02.01.00.23.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 00:23:47 -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 2/6] RISC-V: KVM: Add common kvm_riscv_vcpu_sbi_system_reset() function Date: Tue, 1 Feb 2022 13:52:23 +0530 Message-Id: <20220201082227.361967-3-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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220201_002349_463165_7AEA5710 X-CRM114-Status: GOOD ( 12.35 ) X-BeenThere: linux-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: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org We rename kvm_sbi_system_shutdown() to kvm_riscv_vcpu_sbi_system_reset() and move it to vcpu_sbi.c so that it can be shared by SBI v0.1 shutdown and SBI v0.3 SRST extension. Signed-off-by: Anup Patel Reviewed-by: Atish Patra --- arch/riscv/include/asm/kvm_vcpu_sbi.h | 3 +++ arch/riscv/kvm/vcpu_sbi.c | 17 +++++++++++++++++ arch/riscv/kvm/vcpu_sbi_v01.c | 18 ++---------------- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/arch/riscv/include/asm/kvm_vcpu_sbi.h b/arch/riscv/include/asm/kvm_vcpu_sbi.h index 04cd81f2ab5b..83d6d4d2b1df 100644 --- a/arch/riscv/include/asm/kvm_vcpu_sbi.h +++ b/arch/riscv/include/asm/kvm_vcpu_sbi.h @@ -28,6 +28,9 @@ struct kvm_vcpu_sbi_extension { }; void kvm_riscv_vcpu_sbi_forward(struct kvm_vcpu *vcpu, struct kvm_run *run); +void kvm_riscv_vcpu_sbi_system_reset(struct kvm_vcpu *vcpu, + struct kvm_run *run, + u32 type, u64 flags); const struct kvm_vcpu_sbi_extension *kvm_vcpu_sbi_find_ext(unsigned long extid); #endif /* __RISCV_KVM_VCPU_SBI_H__ */ diff --git a/arch/riscv/kvm/vcpu_sbi.c b/arch/riscv/kvm/vcpu_sbi.c index 78aa3db76225..11ae4f621f0d 100644 --- a/arch/riscv/kvm/vcpu_sbi.c +++ b/arch/riscv/kvm/vcpu_sbi.c @@ -79,6 +79,23 @@ void kvm_riscv_vcpu_sbi_forward(struct kvm_vcpu *vcpu, struct kvm_run *run) run->riscv_sbi.ret[1] = cp->a1; } +void kvm_riscv_vcpu_sbi_system_reset(struct kvm_vcpu *vcpu, + struct kvm_run *run, + u32 type, u64 flags) +{ + unsigned long i; + struct kvm_vcpu *tmp; + + kvm_for_each_vcpu(i, tmp, vcpu->kvm) + tmp->arch.power_off = true; + kvm_make_all_cpus_request(vcpu->kvm, KVM_REQ_SLEEP); + + memset(&run->system_event, 0, sizeof(run->system_event)); + run->system_event.type = type; + run->system_event.flags = flags; + run->exit_reason = KVM_EXIT_SYSTEM_EVENT; +} + int kvm_riscv_vcpu_sbi_return(struct kvm_vcpu *vcpu, struct kvm_run *run) { struct kvm_cpu_context *cp = &vcpu->arch.guest_context; diff --git a/arch/riscv/kvm/vcpu_sbi_v01.c b/arch/riscv/kvm/vcpu_sbi_v01.c index 2ab52b6d9ed3..da4d6c99c2cf 100644 --- a/arch/riscv/kvm/vcpu_sbi_v01.c +++ b/arch/riscv/kvm/vcpu_sbi_v01.c @@ -14,21 +14,6 @@ #include #include -static void kvm_sbi_system_shutdown(struct kvm_vcpu *vcpu, - struct kvm_run *run, u32 type) -{ - unsigned long i; - struct kvm_vcpu *tmp; - - kvm_for_each_vcpu(i, tmp, vcpu->kvm) - tmp->arch.power_off = true; - kvm_make_all_cpus_request(vcpu->kvm, KVM_REQ_SLEEP); - - memset(&run->system_event, 0, sizeof(run->system_event)); - run->system_event.type = type; - run->exit_reason = KVM_EXIT_SYSTEM_EVENT; -} - static int kvm_sbi_ext_v01_handler(struct kvm_vcpu *vcpu, struct kvm_run *run, unsigned long *out_val, struct kvm_cpu_trap *utrap, @@ -80,7 +65,8 @@ static int kvm_sbi_ext_v01_handler(struct kvm_vcpu *vcpu, struct kvm_run *run, } break; case SBI_EXT_0_1_SHUTDOWN: - kvm_sbi_system_shutdown(vcpu, run, KVM_SYSTEM_EVENT_SHUTDOWN); + kvm_riscv_vcpu_sbi_system_reset(vcpu, run, + KVM_SYSTEM_EVENT_SHUTDOWN, 0); *exit = true; break; case SBI_EXT_0_1_REMOTE_FENCE_I: From patchwork Tue Feb 1 08:22:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12731486 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C3AC5C433F5 for ; Tue, 1 Feb 2022 08:24:07 +0000 (UTC) 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=7tYcs2LAjbU7YhQwEiQlcHoyozLswSIt/BIich+hEzE=; b=QmTyewvoDF9LGd UmwLjUpIpsO/A54vBYxb5g4kb8fR7ziGdYpAcgVMFgpQC7B40kbjSg4gHNRAsvOUSI2F9A9ErwI0H rHgROtZWpG3sC7K8C70UUyIVTYxm47Vg94UnyCScHew2K7du/GBVMWxNW2X4NUY1mNWUSM3ScjZ1k CX7EtsGMj25/R3vMrk3O2uekrXfDj2lpO+p5FkBs3yXeD44+nW+vsUWnRSDOEgBLypkk25NmIf4Ar yIwfrHj8Vx0VCe+OWrtInDsVfsMZh/vmUKNmyLeelsGmc/Oxjmn0RzqyCfYfL/XtCucdgNvcNnrcv PZ1M9ukXEE57UYbvltoQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nEoSE-00BW6w-6P; Tue, 01 Feb 2022 08:23:58 +0000 Received: from mail-ed1-x52e.google.com ([2a00:1450:4864:20::52e]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nEoSA-00BW2k-Qx for linux-riscv@lists.infradead.org; Tue, 01 Feb 2022 08:23:56 +0000 Received: by mail-ed1-x52e.google.com with SMTP id l5so32379227edv.3 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=T2QtWQHGJpAp+BLE69OTcY8WvFgYQTyK6wua8XOW11luB2huQET+A9BDLBcsoW9434 Y9iekwGcUjpCWym5QDMOA8QjAJCNbCG1LmB3235/K2vHCiWfIc3C8pCXz7UbQNIzDTit Wog1o8h+azlXjJg9BZvLBuJNid780CCDQb331uhbYRPpIoEs+jR188pAu++Cqaik0ukB a9N5uyh0caLwE6TR3EYtnPgv26/g54jdBu/XOSy4dz4SwpUAUyguqtKYDd2up5A291lN zjzNO6PunowV4nFprV/FsO4YMhqVD9UjORgciNh1Q8k8pyHmn70iLWnc71OsTS0zw2n5 6URQ== X-Gm-Message-State: AOAM5329qWK/cO7pQiyfJw0K5vYSGFCGr8jw/fbMuLMAk1mZd+mFMu1Y qobrgiHQXAMeq+pwIW7N/L7aAQ== X-Google-Smtp-Source: ABdhPJxMN4igBjnNAWqvjNJdPlsojVXp0jfP8pzdoErz1Lbcla7jF8s1hXlmk0ufOTGHDHY8aA6Zkg== 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220201_002354_919132_63A1E33D X-CRM114-Status: GOOD ( 11.41 ) X-BeenThere: linux-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: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.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 Reviewed-by: Atish Patra --- 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, +}; From patchwork Tue Feb 1 08:22:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12731487 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 00522C433F5 for ; Tue, 1 Feb 2022 08:24:11 +0000 (UTC) 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=Zn7xV80s87dQwzWoTLQn/qltFp8j3RV4/oSbqozLu6A=; b=hQggGMEpX4jp2O +beTPtudDgevmyhYEszQx1ll1Eg+ST4rn1UZKRr8C6oXAhMX9Fn6z4dwf3X3WWERQEKXMQ5gREPey MitER6ir3rs/ZrxWGcD8kDlozwHhsTDf0zw8ixkYb0W5fenGtrZJpjVcgm8beLjiGjfvLHVDu/PZ4 R859mQqsa9bQzBIr7W9+kdmaOT91Kok4sp+IWluA+EwzuOq7KcgKWlnbv6BKQFYmYUvLvYvzAfkOs rSrNHFgErIXP3EiEAgeaQ5XfGA7l28tXWIGnKodjiUSbQPd6Jv7LKIFHQche5sttBkvoJgj8ZJcoT lT9ZdU8Ore/cDqdlLU7g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nEoSI-00BWB0-Vi; Tue, 01 Feb 2022 08:24:02 +0000 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nEoSF-00BW7w-WE for linux-riscv@lists.infradead.org; Tue, 01 Feb 2022 08:24:01 +0000 Received: by mail-ej1-x634.google.com with SMTP id k25so51272008ejp.5 for ; Tue, 01 Feb 2022 00:23:59 -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=zwd/8cqd/uyZjzuw2VQObQyskOR01to1ElscGOXTIT4=; b=eC4DiGIz7XiaA9N2mXQL7I9xjW9v59lcMo3xOM1zS2qqTt/VkyB+tuaweSHrA5kejn 5RU1BDgKui2WEL+B2hxVm1uW7QYKdSwgtNyoXUAMRjAKUd4dZ40F+QJQOFFybxqyq8vj 2dg4BMMDM9vVVSpON2vnjF6NN/QnuJg/Bh2JYpa+cF1HLxl2nRkF8ylog15N/wqvvMGt EjvaWUF7iui9SmZVdHL4VFa3LeHay3Y2Fk7rHK8a9nTLxvSQ4pOhVSvOMms4Y6JcCHNr T+15e7UQ3Usi38CmXaVnBjrFS4wbDNAAZzku4LCT7OLl7seLooxbJWmh7HSVGaUkWiuq uxgg== 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=zwd/8cqd/uyZjzuw2VQObQyskOR01to1ElscGOXTIT4=; b=jTwTjCOENwXfJn360AdpHFE0LZwTm9z/6lKYN75TTh4qLFAGZmpEQTAQ7HlT8fU9kK 3zhWmvWaURKAbUNuRsK+u42AdIThzHldg0QXuUh/oCa3CWGL9JDZbd9w7rrPrEVZgW9z OJ3sR4FrcVJXqykFI0zj137BBwG7xZhFfWQzreqQ/dst5mxX68zyHXNOpEyHgFy1mnP4 ZtBc+X8C1kx4cndJ6LPWZGUVqJ1/OrLsRk7eTQYQaT4jyreit7rhQhjuNfYOKdqY7vVi aX60f6VYS2atmxJi7szuLLPWYRYi823xi3tKOBhfANiLsiXHdpe1cydCk+FBVOsp9HwL T81Q== X-Gm-Message-State: AOAM530NQESAutAv30+pcclJxGxdXNCmL+xOg473N0fmRhn7RTSGNqJO KdK7+om6dOyf4PDqUtayl6pO/Q== X-Google-Smtp-Source: ABdhPJy31giTDwE4wqN8u2biPEhaGB3Em2a9I6VCEGluXT0OlIBYWCHXDm+THh+U/KZhqQ92c9Ew+Q== X-Received: by 2002:a17:907:6ea0:: with SMTP id sh32mr21034992ejc.460.1643703838800; Tue, 01 Feb 2022 00:23:58 -0800 (PST) Received: from localhost.localdomain ([122.179.76.38]) by smtp.gmail.com with ESMTPSA id w8sm14312133ejq.220.2022.02.01.00.23.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 00:23:58 -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 4/6] RISC-V: Add SBI HSM suspend related defines Date: Tue, 1 Feb 2022 13:52:25 +0530 Message-Id: <20220201082227.361967-5-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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220201_002400_090084_4D8AF32E X-CRM114-Status: GOOD ( 12.99 ) X-BeenThere: linux-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: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org We add defines related to SBI HSM suspend call and also update HSM states naming as-per the latest SBI specification. Signed-off-by: Anup Patel Reviewed-by: Atish Patra --- arch/riscv/include/asm/sbi.h | 27 ++++++++++++++++++++++----- arch/riscv/kernel/cpu_ops_sbi.c | 2 +- arch/riscv/kvm/vcpu_sbi_hsm.c | 4 ++-- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index d1c37479d828..06133b4f8e20 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -71,15 +71,32 @@ enum sbi_ext_hsm_fid { SBI_EXT_HSM_HART_START = 0, SBI_EXT_HSM_HART_STOP, SBI_EXT_HSM_HART_STATUS, + SBI_EXT_HSM_HART_SUSPEND, }; -enum sbi_hsm_hart_status { - SBI_HSM_HART_STATUS_STARTED = 0, - SBI_HSM_HART_STATUS_STOPPED, - SBI_HSM_HART_STATUS_START_PENDING, - SBI_HSM_HART_STATUS_STOP_PENDING, +enum sbi_hsm_hart_state { + SBI_HSM_STATE_STARTED = 0, + SBI_HSM_STATE_STOPPED, + SBI_HSM_STATE_START_PENDING, + SBI_HSM_STATE_STOP_PENDING, + SBI_HSM_STATE_SUSPENDED, + SBI_HSM_STATE_SUSPEND_PENDING, + SBI_HSM_STATE_RESUME_PENDING, }; +#define SBI_HSM_SUSP_BASE_MASK 0x7fffffff +#define SBI_HSM_SUSP_NON_RET_BIT 0x80000000 +#define SBI_HSM_SUSP_PLAT_BASE 0x10000000 + +#define SBI_HSM_SUSPEND_RET_DEFAULT 0x00000000 +#define SBI_HSM_SUSPEND_RET_PLATFORM SBI_HSM_SUSP_PLAT_BASE +#define SBI_HSM_SUSPEND_RET_LAST SBI_HSM_SUSP_BASE_MASK +#define SBI_HSM_SUSPEND_NON_RET_DEFAULT SBI_HSM_SUSP_NON_RET_BIT +#define SBI_HSM_SUSPEND_NON_RET_PLATFORM (SBI_HSM_SUSP_NON_RET_BIT | \ + SBI_HSM_SUSP_PLAT_BASE) +#define SBI_HSM_SUSPEND_NON_RET_LAST (SBI_HSM_SUSP_NON_RET_BIT | \ + SBI_HSM_SUSP_BASE_MASK) + enum sbi_ext_srst_fid { SBI_EXT_SRST_RESET = 0, }; diff --git a/arch/riscv/kernel/cpu_ops_sbi.c b/arch/riscv/kernel/cpu_ops_sbi.c index dae29cbfe550..2e16f6732cdf 100644 --- a/arch/riscv/kernel/cpu_ops_sbi.c +++ b/arch/riscv/kernel/cpu_ops_sbi.c @@ -111,7 +111,7 @@ static int sbi_cpu_is_stopped(unsigned int cpuid) rc = sbi_hsm_hart_get_status(hartid); - if (rc == SBI_HSM_HART_STATUS_STOPPED) + if (rc == SBI_HSM_STATE_STOPPED) return 0; return rc; } diff --git a/arch/riscv/kvm/vcpu_sbi_hsm.c b/arch/riscv/kvm/vcpu_sbi_hsm.c index 2e383687fa48..1ac4b2e8e4ec 100644 --- a/arch/riscv/kvm/vcpu_sbi_hsm.c +++ b/arch/riscv/kvm/vcpu_sbi_hsm.c @@ -60,9 +60,9 @@ static int kvm_sbi_hsm_vcpu_get_status(struct kvm_vcpu *vcpu) if (!target_vcpu) return -EINVAL; if (!target_vcpu->arch.power_off) - return SBI_HSM_HART_STATUS_STARTED; + return SBI_HSM_STATE_STARTED; else - return SBI_HSM_HART_STATUS_STOPPED; + return SBI_HSM_STATE_STOPPED; } static int kvm_sbi_ext_hsm_handler(struct kvm_vcpu *vcpu, struct kvm_run *run, From patchwork Tue Feb 1 08:22:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12731488 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 10976C433FE for ; Tue, 1 Feb 2022 08:24:19 +0000 (UTC) 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=t0hjarM0NhbrsePZ1CQl2C/blnRT/HmOWxneS31xU64=; b=K3SONS3XQXEtII yIltg4xeQPsHfxtaZFtgJVIl2na+qNLO6rEA1fJs9B1JpoFoJ41Sc5CdLw6nnfKL6gjKhkeaoBwEi VYiZOptHk5mAZAE5lwabW/MRzCapVtcGMBE+RDWQ96Mk6GDkwDY8zE2j3L2UOR5wfAggYeJZRi05l 8q9/FSEf5K/tcQQViBUBXhTaNogoqbJWUDO0OlO/k7Kr7j8N0Q3/WTy0wkEmvPG2s6slXi4a97DHx YS/J2XpVZyXeUNbZh844wecWyAAWhAwOJd8vD4Y0RVqZTCuCD+W8/twJwrBfOeSQVL+1PlDQpK79K yChguxQ78RWYidt7eZSg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nEoSP-00BWHE-Mx; Tue, 01 Feb 2022 08:24:09 +0000 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nEoSL-00BWCK-Of for linux-riscv@lists.infradead.org; Tue, 01 Feb 2022 08:24:07 +0000 Received: by mail-ej1-x62b.google.com with SMTP id jx6so52022293ejb.0 for ; Tue, 01 Feb 2022 00:24:05 -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=l+b47qbaWpdYZN1v9p/s3UrPnbfSBgqc+qjFPZYSPg0=; b=QdDeIW90ozVxbtAs28LtZP1SR1njpEwqySsxBFUYrwcKkO/9ik8SD7e63/ORdLuKN6 HyI3LupM10HaQJNfSiNGnwUgMsJjBe6rmEY71RUCVouSgN2Ww0ih1X5/il7CocKD9jmG e5UutqWNP6FOjWmhNqdxTTF5IP65/y2m8Y7DezBkqTOkFj0jP2DTWUAHUNLzCaqt0i7s UjBVdk5uVAxkNDd3LrfDYJwUdzSiJbvQ8ICYedqx1BtTCqJrVx2FgSPFfgzmM8UPEfvd 0QPBGawu4zge1Rk2p7MyHEyooujXJtLlCTeJIQsuvkJSwOX5TavDG/J9JFJUOqdhbPrb gLzA== 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=l+b47qbaWpdYZN1v9p/s3UrPnbfSBgqc+qjFPZYSPg0=; b=oJ3uP25HDCdryU2w+Wbygjx/RPlw/vXWbH++ugOS5cAr4cVxgHW6dk3yGtgtRMfTcg NW4YzIq0XagVH6UvzRCAWNMI8SVBWLJck1pmX3bB94WYe/BEouudfXggw0vcJrnawH9i 5wqx0+ekRcwowachIrO09UTMrQLBcDT6tPorBbiSSECnILe6WnrRrvnSGypX837cDNk5 9qJyem+r2w88NhyhvcoWvj3YQVQF0TxUzwQfWNd287QdeByHxLfmkfERwPbiy0jWL7iX 7K9xjWmYwiBrZi5DZKigwbM9bygbboU4GbKC22dSkIm7SagW5zwMpyQTxWYOu/wInnG5 20yg== X-Gm-Message-State: AOAM532vNdiOlpVshbEfGzXz45duUS5wJhm9efVm8bQ6qqf1JdyXOg/J I+AZ+lepYFZL4LD7ovgM7T9yRQ== X-Google-Smtp-Source: ABdhPJyt0wfNRFp/hPqRprYBU3q50Km0sidGpnOTXlGuTS40cAb2L7ml6sR8ZEkCU0opyyQARlSJ+g== X-Received: by 2002:a17:907:6293:: with SMTP id nd19mr19620284ejc.64.1643703844251; Tue, 01 Feb 2022 00:24:04 -0800 (PST) Received: from localhost.localdomain ([122.179.76.38]) by smtp.gmail.com with ESMTPSA id w8sm14312133ejq.220.2022.02.01.00.23.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 00:24:03 -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 5/6] RISC-V: KVM: Add common kvm_riscv_vcpu_wfi() function Date: Tue, 1 Feb 2022 13:52:26 +0530 Message-Id: <20220201082227.361967-6-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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220201_002405_851931_8452953E X-CRM114-Status: GOOD ( 12.27 ) X-BeenThere: linux-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: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The wait for interrupt (WFI) instruction emulation can share the VCPU halt logic with SBI HSM suspend emulation so this patch adds a common kvm_riscv_vcpu_wfi() function for this purpose. Signed-off-by: Anup Patel Reviewed-by: Atish Patra --- arch/riscv/include/asm/kvm_host.h | 1 + arch/riscv/kvm/vcpu_exit.c | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/arch/riscv/include/asm/kvm_host.h b/arch/riscv/include/asm/kvm_host.h index 99ef6a120617..78da839657e5 100644 --- a/arch/riscv/include/asm/kvm_host.h +++ b/arch/riscv/include/asm/kvm_host.h @@ -228,6 +228,7 @@ void kvm_riscv_stage2_vmid_update(struct kvm_vcpu *vcpu); void __kvm_riscv_unpriv_trap(void); +void kvm_riscv_vcpu_wfi(struct kvm_vcpu *vcpu); unsigned long kvm_riscv_vcpu_unpriv_read(struct kvm_vcpu *vcpu, bool read_insn, unsigned long guest_addr, diff --git a/arch/riscv/kvm/vcpu_exit.c b/arch/riscv/kvm/vcpu_exit.c index 571f319e995a..aa8af129e4bb 100644 --- a/arch/riscv/kvm/vcpu_exit.c +++ b/arch/riscv/kvm/vcpu_exit.c @@ -144,12 +144,7 @@ static int system_opcode_insn(struct kvm_vcpu *vcpu, { if ((insn & INSN_MASK_WFI) == INSN_MATCH_WFI) { vcpu->stat.wfi_exit_stat++; - if (!kvm_arch_vcpu_runnable(vcpu)) { - srcu_read_unlock(&vcpu->kvm->srcu, vcpu->arch.srcu_idx); - kvm_vcpu_halt(vcpu); - vcpu->arch.srcu_idx = srcu_read_lock(&vcpu->kvm->srcu); - kvm_clear_request(KVM_REQ_UNHALT, vcpu); - } + kvm_riscv_vcpu_wfi(vcpu); vcpu->arch.guest_context.sepc += INSN_LEN(insn); return 1; } @@ -453,6 +448,21 @@ static int stage2_page_fault(struct kvm_vcpu *vcpu, struct kvm_run *run, return 1; } +/** + * kvm_riscv_vcpu_wfi -- Emulate wait for interrupt (WFI) behaviour + * + * @vcpu: The VCPU pointer + */ +void kvm_riscv_vcpu_wfi(struct kvm_vcpu *vcpu) +{ + if (!kvm_arch_vcpu_runnable(vcpu)) { + srcu_read_unlock(&vcpu->kvm->srcu, vcpu->arch.srcu_idx); + kvm_vcpu_halt(vcpu); + vcpu->arch.srcu_idx = srcu_read_lock(&vcpu->kvm->srcu); + kvm_clear_request(KVM_REQ_UNHALT, vcpu); + } +} + /** * kvm_riscv_vcpu_unpriv_read -- Read machine word from Guest memory * From patchwork Tue Feb 1 08:22:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 12731489 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0E8A4C433EF for ; Tue, 1 Feb 2022 08:24:26 +0000 (UTC) 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=SB06brhfO8YvANkU2Is8kRKRzA/cC3qcbW4q7ciQsr4=; b=YLqu6iAnif3Zxn te6R7ILU/0k+oPxSaPIDzFhQHNsHON3J8Z9sywE/AFlQPU+wFEq0lIA1s6MlBolwSlIkRQr+6JrpD fNvWOVk0o5iJQwQvEDFwq/vftDy6dKkOHW9RPbLhGbkHoPOjxtLxGR92h7EHsPIL69VLIHKYvb3fj YTe4A+6V2h9Msqd5CeMocbTmqTUPHhA//NN578JphqA1bD+RBH1RRqqL+e7OO0deuprd4HQD8h++R FY2wO3faKsC9C5d8uRvhQEqCmfcP99jbAznQfYxjK+IoyqO+uTLZHbwl38ClMWA8GETXFF8cWOqBa rJCOZEOcYJb5qZrV6seA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nEoSW-00BWMB-4t; Tue, 01 Feb 2022 08:24:16 +0000 Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nEoSR-00BWHk-8B for linux-riscv@lists.infradead.org; Tue, 01 Feb 2022 08:24:14 +0000 Received: by mail-ej1-x636.google.com with SMTP id ka4so51497039ejc.11 for ; Tue, 01 Feb 2022 00:24:10 -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=GHl1OHNEBsppykLL0FZwPbFOi9foYqykYD+EcFet6qM=; b=a7BBFEww46WyfPzbomNQG+Oqq2IlwS7J9fIC6wz4AdhnC7RyJpr/rJWZYYt2vAhObW iKEwMUG4feE/X4hSNAxQoRtiComrQv51VvEEYRla9+kWV86j1LQbU6kx+vhGqEd61/cy G2t3i2xZvnCqkVzIfZzQU2C62mnetTUKDAhzxiaYd34pcr2HvKXqAO0uOCOFqYacHePO vs923UsYq5I2ob+UgyHh5m1WF0yrD59QYadBvnneQAQcj857TlY7IXviNdvZDwFw7Noa sOmaqrashQAOt4ECeqnuo5hVWsTR85qX0g8Zx9Gh9fKZdbFMM1vrATkT2ORx5IRqOcsY mpJQ== 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=GHl1OHNEBsppykLL0FZwPbFOi9foYqykYD+EcFet6qM=; b=dGXV5+5VFaDGtG8XhclmEfdiyVXAOipcrL8wak3+whiZZmgnZq7z898/v5OdRbWhJY mnozEi+jnPUVjJpmyv/IkwmF4SUTZVS+h49xXAWGuNu3Zpw1jif/T98tuvi3xeyoCH9q kefOG/WKWV9I6eu8uWMpzhVJPQjSOJi5vBh14zMsEAL8N9Z28NK8kbKjJrNvTqRQv0Y6 1DkRU5fy4lCe9tP1h+xraYUS32Mvlds4Wy4pbhrfA2IkfGBe3CxRU3j9SAtSAb+BFakD inzWCmJ0Qsq8RkheS/VmLQCiE1C8a8ukBpH1Nm0NU/WYGp1fqhPWPnQJNWDGvQ0ul/dL enJA== X-Gm-Message-State: AOAM530+ThlQQkK+5ouh8rr1TcWPvmwPTKRisECXp2o80ByrCLWFb8Jb AeDcQtwCvqk33oSdBC1pQJnZiQ== X-Google-Smtp-Source: ABdhPJzCelwQYB0QuYOqiku+n7scTy7gUb/hHhHhs6GEaaroLB9AmfUKIaKTwSM1jvGPR/SYoABrkA== X-Received: by 2002:a17:906:58c6:: with SMTP id e6mr19318243ejs.733.1643703849679; Tue, 01 Feb 2022 00:24:09 -0800 (PST) Received: from localhost.localdomain ([122.179.76.38]) by smtp.gmail.com with ESMTPSA id w8sm14312133ejq.220.2022.02.01.00.24.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 00:24:09 -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 6/6] RISC-V: KVM: Implement SBI HSM suspend call Date: Tue, 1 Feb 2022 13:52:27 +0530 Message-Id: <20220201082227.361967-7-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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220201_002411_320269_3FD85B4D X-CRM114-Status: GOOD ( 11.07 ) X-BeenThere: linux-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: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The SBI v0.3 specification extends SBI HSM extension by adding SBI HSM suspend call and related HART states. This patch extends the KVM RISC-V HSM implementation to provide KVM guest a minimal SBI HSM suspend call which is equivalent to a WFI instruction. Signed-off-by: Anup Patel Reviewed-by: Atish Patra --- arch/riscv/kvm/vcpu_sbi_hsm.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/arch/riscv/kvm/vcpu_sbi_hsm.c b/arch/riscv/kvm/vcpu_sbi_hsm.c index 1ac4b2e8e4ec..239dec0a628a 100644 --- a/arch/riscv/kvm/vcpu_sbi_hsm.c +++ b/arch/riscv/kvm/vcpu_sbi_hsm.c @@ -61,6 +61,8 @@ static int kvm_sbi_hsm_vcpu_get_status(struct kvm_vcpu *vcpu) return -EINVAL; if (!target_vcpu->arch.power_off) return SBI_HSM_STATE_STARTED; + else if (vcpu->stat.generic.blocking) + return SBI_HSM_STATE_SUSPENDED; else return SBI_HSM_STATE_STOPPED; } @@ -91,6 +93,18 @@ static int kvm_sbi_ext_hsm_handler(struct kvm_vcpu *vcpu, struct kvm_run *run, ret = 0; } break; + case SBI_EXT_HSM_HART_SUSPEND: + switch (cp->a0) { + case SBI_HSM_SUSPEND_RET_DEFAULT: + kvm_riscv_vcpu_wfi(vcpu); + break; + case SBI_HSM_SUSPEND_NON_RET_DEFAULT: + ret = -EOPNOTSUPP; + break; + default: + ret = -EINVAL; + } + break; default: ret = -EOPNOTSUPP; }