From patchwork Thu Apr 18 14:26:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 13634994 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 9E747C04FF8 for ; Thu, 18 Apr 2024 15:31:44 +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=G5PLPjKZmL5t+3Q/INm6qSfYFfRU5KOrsRxMKXpvrU8=; b=QGWWnUZdPLw2CO gDxjKR5omsuz0DYqgnQpuYRvGQsQzTSXLFWVAryPkFC0n/TgOKDzP0kfoOXTc5vo8Aev9TWaHaPIE 9v6JjTYcQEqbqSAc7xZGEKmqdrnKaVDevO1UgnKKzy9YIWKHbemJxJbNsSjj5Pzrg9tf83vuohVvR Msg9Eons0Di6zuOtMUe/7UlU66kTRa0NQtsV8EQGVhDPPZmG4RRjgdmq6mnnH3llJAPKryAP7MhfU jj5rcL6tsYd+Gd288C7MyTAGKVLr+SqyhotzIXzzB4yzLpj4rgZwo5Up1kD+cHz98k5R1vsOHEYwc 6W1bAM105hPDzLb2hMAQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxTjf-00000002nqK-2yHk; Thu, 18 Apr 2024 15:31:39 +0000 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxSjI-00000002cUb-3jll for linux-riscv@lists.infradead.org; Thu, 18 Apr 2024 14:27:14 +0000 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-345606e8ac0so124132f8f.0 for ; Thu, 18 Apr 2024 07:27:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1713450431; x=1714055231; darn=lists.infradead.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=pjYeEsui4m5xv1lGH5o6mH+W8BXsONKsbiY648bn26Q=; b=pWiBDltWStBv3aLGMSulCoNwdd09Z6iZ/l0/ypNJ/N/9Whenxp188oiqqFaaZwk80z BVmA5+g4dSqKA/vWDglKmuDJDjSUSkypWQ0ilunXRTe5fLXtRoUaBI7ZrpbRV7wQaFF3 WhDfl/UWT49RZjWWipzeiruOu+D6WmtaK5lihxtok91fKoivC1j0RLxrCR6X+e8lspi9 NVsrptZBjsUl3akPc5Yf/ZBl/2O+hvUSfSIhNJNdjT1M3oHD8XOIyKmOnbYvLBu1GMqZ voeXGbjsWHARD4QCjNOVnkojWDOSV0SM6Rn0yMESeVw8BtSyVc5fRg7rpJ9E8Lz+vR4D 4aBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713450431; x=1714055231; 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=pjYeEsui4m5xv1lGH5o6mH+W8BXsONKsbiY648bn26Q=; b=VH60Atrpcp6lPf0b77Zrb1ZLzui68bhBm3nDzZ1JjRfgIPGyHglPY3jakz5VfysbEQ iKuQd6crZT7lhGokZgMZanBgLKOc51xcsWCSfXhz0SgFRiNXkQ0aQMlRGmzSr0YczVrW WXsAYUDfEeyskJfgzV0pqEDT1AES2Fg3913fo3oQcvi6BG+7zt7CiZzVKlH6zns0gFPh zh4bGogqdB+pVE6LK0TYbkL3qrFMBTyha0eZUojXE6fmfqfnFJtll7r1MVBOw47CSRn7 /+kpXTQUE6kNyRt9n+6svmy6L2Td+vcgapfIlOO9USAcv76QRhTr8fJOtbRJ9aLrIfu+ 2XLg== X-Forwarded-Encrypted: i=1; AJvYcCXlsY2GJTdaTGDzHYO3N9spxAOGNbofLhlpuDDHOaIakiFkFXfZIpQCVhThrNvdtTfB1AmteRlW7Q/Y4MrQmm7VRucqrh5AZ4YKwVAzXQtc X-Gm-Message-State: AOJu0Yzt+sNv3yl4UXBW06qBZ5Y6pux1Z34CNVptFho+Ee1mYpXf8ed3 EYvdPdmNzwtHsDX8ow1X/OPwQNNMmrq7O0i/keehBIIL0wfe2Hf9tZ+VmC2BuOc= X-Google-Smtp-Source: AGHT+IFFwaascQCVwSoWuecZs0QNk4WI1qD1KbtUyisTXBvH15F7tw1GRlm2dKuVmVzvSHfB6Uh8Ag== X-Received: by 2002:a05:600c:3554:b0:416:7b2c:df05 with SMTP id i20-20020a05600c355400b004167b2cdf05mr2100856wmq.1.1713450431422; Thu, 18 Apr 2024 07:27:11 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:999:a3a0:7b64:4d1d:16d8:e38b]) by smtp.gmail.com with ESMTPSA id v10-20020a05600c470a00b00418a386c059sm2873645wmo.42.2024.04.18.07.27.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 07:27:10 -0700 (PDT) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Conor Dooley , Rob Herring , Krzysztof Kozlowski , Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Atish Patra Cc: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, Ved Shanbhogue Subject: [RFC PATCH 1/7] riscv: kvm: add support for FWFT SBI extension Date: Thu, 18 Apr 2024 16:26:40 +0200 Message-ID: <20240418142701.1493091-2-cleger@rivosinc.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240418142701.1493091-1-cleger@rivosinc.com> References: <20240418142701.1493091-1-cleger@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240418_072712_981299_4F55412B X-CRM114-Status: GOOD ( 24.78 ) 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 Add support for FWFT extension in KVM Signed-off-by: Clément Léger --- arch/riscv/include/asm/kvm_host.h | 5 + arch/riscv/include/asm/kvm_vcpu_sbi.h | 1 + arch/riscv/include/asm/kvm_vcpu_sbi_fwft.h | 37 ++++++ arch/riscv/include/uapi/asm/kvm.h | 1 + arch/riscv/kvm/Makefile | 1 + arch/riscv/kvm/vcpu.c | 5 + arch/riscv/kvm/vcpu_sbi.c | 4 + arch/riscv/kvm/vcpu_sbi_fwft.c | 136 +++++++++++++++++++++ 8 files changed, 190 insertions(+) create mode 100644 arch/riscv/include/asm/kvm_vcpu_sbi_fwft.h create mode 100644 arch/riscv/kvm/vcpu_sbi_fwft.c diff --git a/arch/riscv/include/asm/kvm_host.h b/arch/riscv/include/asm/kvm_host.h index 484d04a92fa6..be60aaa07f57 100644 --- a/arch/riscv/include/asm/kvm_host.h +++ b/arch/riscv/include/asm/kvm_host.h @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -169,6 +170,7 @@ struct kvm_vcpu_csr { struct kvm_vcpu_config { u64 henvcfg; u64 hstateen0; + u64 hedeleg; }; struct kvm_vcpu_smstateen_csr { @@ -261,6 +263,9 @@ struct kvm_vcpu_arch { /* Performance monitoring context */ struct kvm_pmu pmu_context; + /* Firmware feature SBI extension context */ + struct kvm_sbi_fwft fwft_context; + /* 'static' configurations which are set only once */ struct kvm_vcpu_config cfg; diff --git a/arch/riscv/include/asm/kvm_vcpu_sbi.h b/arch/riscv/include/asm/kvm_vcpu_sbi.h index b96705258cf9..3a33bbacc233 100644 --- a/arch/riscv/include/asm/kvm_vcpu_sbi.h +++ b/arch/riscv/include/asm/kvm_vcpu_sbi.h @@ -86,6 +86,7 @@ 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_sta; +extern const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_fwft; 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/asm/kvm_vcpu_sbi_fwft.h b/arch/riscv/include/asm/kvm_vcpu_sbi_fwft.h new file mode 100644 index 000000000000..7dc1b80c7e6c --- /dev/null +++ b/arch/riscv/include/asm/kvm_vcpu_sbi_fwft.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2023 Rivos Inc + * + * Authors: + * Atish Patra + */ + +#ifndef __KVM_VCPU_RISCV_FWFT_H +#define __KVM_VCPU_RISCV_FWFT_H + +#include + +#define KVM_SBI_FWFT_FEATURE_COUNT 1 + +struct kvm_sbi_fwft_config; +struct kvm_vcpu; + +struct kvm_sbi_fwft_feature { + enum sbi_fwft_feature_t id; + int (*set)(struct kvm_vcpu *vcpu, struct kvm_sbi_fwft_config *conf, unsigned long value); + int (*get)(struct kvm_vcpu *vcpu, struct kvm_sbi_fwft_config *conf, unsigned long *value); +}; + +struct kvm_sbi_fwft_config { + const struct kvm_sbi_fwft_feature *feature; + unsigned long flags; +}; + +/* FWFT data structure per vcpu */ +struct kvm_sbi_fwft { + struct kvm_sbi_fwft_config configs[KVM_SBI_FWFT_FEATURE_COUNT]; +}; + +#define vcpu_to_fwft(vcpu) (&(vcpu)->arch.fwft_context) + +#endif /* !__KVM_VCPU_RISCV_FWFT_H */ diff --git a/arch/riscv/include/uapi/asm/kvm.h b/arch/riscv/include/uapi/asm/kvm.h index 7499e88a947c..fa3097da91c0 100644 --- a/arch/riscv/include/uapi/asm/kvm.h +++ b/arch/riscv/include/uapi/asm/kvm.h @@ -185,6 +185,7 @@ enum KVM_RISCV_SBI_EXT_ID { KVM_RISCV_SBI_EXT_VENDOR, KVM_RISCV_SBI_EXT_DBCN, KVM_RISCV_SBI_EXT_STA, + KVM_RISCV_SBI_EXT_FWFT, KVM_RISCV_SBI_EXT_MAX, }; diff --git a/arch/riscv/kvm/Makefile b/arch/riscv/kvm/Makefile index c9646521f113..19175bd5b40a 100644 --- a/arch/riscv/kvm/Makefile +++ b/arch/riscv/kvm/Makefile @@ -27,6 +27,7 @@ kvm-y += vcpu_sbi_base.o kvm-y += vcpu_sbi_replace.o kvm-y += vcpu_sbi_hsm.o kvm-y += vcpu_sbi_sta.o +kvm-y += vcpu_sbi_fwft.o kvm-y += vcpu_timer.o kvm-$(CONFIG_RISCV_PMU_SBI) += vcpu_pmu.o vcpu_sbi_pmu.o kvm-y += aia.o diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c index b5ca9f2e98ac..461ef60d4eda 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -505,6 +505,8 @@ static void kvm_riscv_vcpu_setup_config(struct kvm_vcpu *vcpu) if (riscv_isa_extension_available(isa, SMSTATEEN)) cfg->hstateen0 |= SMSTATEEN0_SSTATEEN0; } + + cfg->hedeleg = csr_read(CSR_HEDELEG); } void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) @@ -521,6 +523,7 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) csr_write(CSR_VSTVAL, csr->vstval); csr_write(CSR_HVIP, csr->hvip); csr_write(CSR_VSATP, csr->vsatp); + csr_write(CSR_HEDELEG, cfg->hedeleg); csr_write(CSR_HENVCFG, cfg->henvcfg); if (IS_ENABLED(CONFIG_32BIT)) csr_write(CSR_HENVCFGH, cfg->henvcfg >> 32); @@ -551,6 +554,7 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) { struct kvm_vcpu_csr *csr = &vcpu->arch.guest_csr; + struct kvm_vcpu_config *cfg = &vcpu->arch.cfg; vcpu->cpu = -1; @@ -574,6 +578,7 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) csr->vstval = csr_read(CSR_VSTVAL); csr->hvip = csr_read(CSR_HVIP); csr->vsatp = csr_read(CSR_VSATP); + cfg->hedeleg = csr_read(CSR_HEDELEG); } static void kvm_riscv_check_vcpu_requests(struct kvm_vcpu *vcpu) diff --git a/arch/riscv/kvm/vcpu_sbi.c b/arch/riscv/kvm/vcpu_sbi.c index 72a2ffb8dcd1..76901f0f34b7 100644 --- a/arch/riscv/kvm/vcpu_sbi.c +++ b/arch/riscv/kvm/vcpu_sbi.c @@ -74,6 +74,10 @@ static const struct kvm_riscv_sbi_extension_entry sbi_ext[] = { .ext_idx = KVM_RISCV_SBI_EXT_STA, .ext_ptr = &vcpu_sbi_ext_sta, }, + { + .ext_idx = KVM_RISCV_SBI_EXT_FWFT, + .ext_ptr = &vcpu_sbi_ext_fwft, + }, { .ext_idx = KVM_RISCV_SBI_EXT_EXPERIMENTAL, .ext_ptr = &vcpu_sbi_ext_experimental, diff --git a/arch/riscv/kvm/vcpu_sbi_fwft.c b/arch/riscv/kvm/vcpu_sbi_fwft.c new file mode 100644 index 000000000000..b9b7f8fa6d22 --- /dev/null +++ b/arch/riscv/kvm/vcpu_sbi_fwft.c @@ -0,0 +1,136 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2021 Western Digital Corporation or its affiliates. + * + * Authors: + * Atish Patra + */ + +#include +#include +#include +#include +#include +#include + +#define MIS_DELEG (1UL << EXC_LOAD_MISALIGNED | 1UL << EXC_STORE_MISALIGNED) + +static int kvm_sbi_fwft_set_misaligned_delegation(struct kvm_vcpu *vcpu, + struct kvm_sbi_fwft_config *conf, + unsigned long value) +{ + if (value) + csr_set(CSR_HEDELEG, MIS_DELEG); + else + csr_clear(CSR_HEDELEG, MIS_DELEG); + + return SBI_SUCCESS; +} + +static int kvm_sbi_fwft_get_misaligned_delegation(struct kvm_vcpu *vcpu, + struct kvm_sbi_fwft_config *conf, + unsigned long *value) +{ + *value = (csr_read(CSR_HEDELEG) & MIS_DELEG) != 0; + + return SBI_SUCCESS; +} + +static struct kvm_sbi_fwft_config * +kvm_sbi_fwft_get_config(struct kvm_vcpu *vcpu, enum sbi_fwft_feature_t feature) +{ + int i = 0; + struct kvm_sbi_fwft *fwft = vcpu_to_fwft(vcpu); + + for (i = 0; i < KVM_SBI_FWFT_FEATURE_COUNT; i++) { + if (fwft->configs[i].feature->id == feature) + return &fwft->configs[i]; + } + + return NULL; +} + +static int kvm_sbi_fwft_set(struct kvm_vcpu *vcpu, + enum sbi_fwft_feature_t feature, + unsigned long value, unsigned long flags) +{ + struct kvm_sbi_fwft_config *conf = kvm_sbi_fwft_get_config(vcpu, + feature); + if (!conf) + return SBI_ERR_DENIED; + + if ((flags & ~SBI_FWFT_SET_FLAG_LOCK) != 0) + return SBI_ERR_INVALID_PARAM; + + if (conf->flags & SBI_FWFT_SET_FLAG_LOCK) + return SBI_ERR_DENIED; + + conf->flags = flags; + + return conf->feature->set(vcpu, conf, value); +} + +static int kvm_sbi_fwft_get(struct kvm_vcpu *vcpu, + enum sbi_fwft_feature_t feature, + unsigned long *value) +{ + struct kvm_sbi_fwft_config *conf = kvm_sbi_fwft_get_config(vcpu, + feature); + if (!conf) + return SBI_ERR_DENIED; + + return conf->feature->get(vcpu, conf, value); +} + +static int kvm_sbi_ext_fwft_handler(struct kvm_vcpu *vcpu, struct kvm_run *run, + struct kvm_vcpu_sbi_return *retdata) +{ + int ret = 0; + struct kvm_cpu_context *cp = &vcpu->arch.guest_context; + unsigned long funcid = cp->a6; + + switch (funcid) { + case SBI_EXT_FWFT_SET: + ret = kvm_sbi_fwft_set(vcpu, cp->a0, cp->a1, cp->a2); + break; + case SBI_EXT_FWFT_GET: + ret = kvm_sbi_fwft_get(vcpu, cp->a0, &retdata->out_val); + break; + default: + ret = SBI_ERR_NOT_SUPPORTED; + break; + } + + retdata->err_val = ret; + + return 0; +} + +static const struct kvm_sbi_fwft_feature features[] = { + { + .id = SBI_FWFT_MISALIGNED_DELEG, + .set = kvm_sbi_fwft_set_misaligned_delegation, + .get = kvm_sbi_fwft_get_misaligned_delegation, + } +}; + +static_assert(ARRAY_SIZE(features) == KVM_SBI_FWFT_FEATURE_COUNT); + + +static unsigned long kvm_sbi_ext_fwft_probe(struct kvm_vcpu *vcpu) +{ + struct kvm_sbi_fwft *fwft = vcpu_to_fwft(vcpu); + int i; + + for (i = 0; i < ARRAY_SIZE(features); i++) + fwft->configs[i].feature = &features[i]; + + return 1; +} + +const struct kvm_vcpu_sbi_extension vcpu_sbi_ext_fwft = { + .extid_start = SBI_EXT_FWFT, + .extid_end = SBI_EXT_FWFT, + .handler = kvm_sbi_ext_fwft_handler, + .probe = kvm_sbi_ext_fwft_probe, +}; From patchwork Thu Apr 18 14:26:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 13634995 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 3CC29C4345F for ; Thu, 18 Apr 2024 15:31:48 +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=RJ0nWZyxbywIMcJASQQehxZeiOAzb0PppjrlpAStALA=; b=qzWUB3+VHqvvgm tJ8G3LFQ/PASMkxwZRuEeCsNpvWTcC+0xxOTqzA/3jW6jGbcoQrTpm+KlJyQygKMmnOed8Ho0Uo/p f/oEvHCtUw8utvaB/xWGU9kq7x4OcjM/JPInKEhwXJQ86QPZgVMzip66JRCTa+QZaDtw9xC2bKNlW sxM251co87jz30arf4+kD8Y8k7mY4f6+PZDORC4Li1b0oj3wwxObyuEjojnaQgtTsmsp4otrMJMhq LwgEOiZVh0XDC8HCpuIEF8kdrZINTZJcs7JfZlT35m6vdow1q5P4WGItYDVX9TMVbsa6ON2dIJb1R 65oTiDTe/PXynnNACMiA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxTji-00000002nsZ-1KfY; Thu, 18 Apr 2024 15:31:42 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxSjN-00000002cXR-2Vgd for linux-riscv@bombadil.infradead.org; Thu, 18 Apr 2024 14:27:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:Content-Type :MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=cdC41mYpitxeoerTPG3yyRH/m087Cg7WhfTha8ba/eQ=; b=pTucYq8aKtN3vZf8UPqZix7Rz/ d+hi6AdBZyG0Ecuu9cTRO0C1VZEbhdJa+pxya2O3m+E3SjmBX+ZynuHqnJgdWQ7uNfdq0n6LWL1XN C9irR1FR/k1zejUihChfD4BmdY1sc0OgyL0/7kujD4Qznxdi9JD1puCvh22QO6oetgaVTJDii3R9R MSR5QCLR6ByY+h07UXE5a2EdvzKqfkav1+6Ne9SgEbxXAkTVW6T2gUIteq7cbPIDG1kXa5yGj3NUf zysK1Yz2pYXjiEUuPXCJC7M0pHK35ILgeK+oR20ag07v7tbFNJtsv0ap+qdhzRtPy3ya7tQhg4F90 Gse9u1Hw==; Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxSjK-0000000C2Ou-0j9G for linux-riscv@lists.infradead.org; Thu, 18 Apr 2024 14:27:16 +0000 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-349bd110614so164231f8f.3 for ; Thu, 18 Apr 2024 07:27:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1713450432; x=1714055232; darn=lists.infradead.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=cdC41mYpitxeoerTPG3yyRH/m087Cg7WhfTha8ba/eQ=; b=CdEqqG5HV75M53C1n8WBG2cR+FAu3W6yIUMdUqtgTEajm3jI5sZf+WNhCuOgbGgf4W hOTpPq8AZqHEMWm/apDyZ0y+yg8AfUJ8vQDNPywGURxE0IUxjkYeDSAHca9cBqPq+jmv 8ZA0XZdMqDD/P/pan5ax4GrA8G0Wa4myEyjshjtTR4fLwelBW6ccaLxuwEKD1WrDSP1Z rfkOWP+8owi81Q57TtdSGgrkQPEcdm9+RhKozXiRhxfpbxVG9E68PCmrdVxHLJah28Id WjktD8fWPkHpcApCcrsmKBg2BL9hdGLjoNkRRHYjMVnYwkEeu7oe3vJOy5D028bkRg8z 5ArQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713450432; x=1714055232; 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=cdC41mYpitxeoerTPG3yyRH/m087Cg7WhfTha8ba/eQ=; b=vQE/YEDxwGkRi5QgFlJWxIdGuCmM4vTqoHa8jzTvmzna2SOQgDDFMbAsQ9V5EraDDK 2MYt0lSzARdiPncto2MVDfF4x1Z63WPEAzwvAg5g3oFzE0tgAv/LfkQJIcmB6oMD72yD T0YZaBb8WItaBHYlPNKSShZc238lL2tUr7WghghGqtoX/14Yo+p7ODnKJVOsh8Yv+CpN Am3WyCvsBJsCaoNKFZdF4eF1VdH2fK6Yc/hf8zq8PuksFRQkEX/Xo8ZYbpxGGVKlP37G KpatnH5DsWLl7z8P/rP/ezzyoH+xCqwFYRmpFhOQ4LMdBtOJUOK8ItykBKuG9DKdTZ8Z g7Tw== X-Forwarded-Encrypted: i=1; AJvYcCVSDsKg2eaWxf20U8ejo36bG3qpMwyLYHNp8zpN+lGNqDREjNGXi3QjeKX6pDso05WCXT8u9GWnDWI49XHeCiIZrMlcCgVnY8BextU7q187 X-Gm-Message-State: AOJu0Yx4o3dpYENMc71zkVi3ncyzth7YUXp1esXg/zgsYtHKj7+oi0JF KD6QaKns/2l86OVvDL0vp3yv4QJYwCGirY16V96FcC0sHIZbk6x+erdO1oi5LjM= X-Google-Smtp-Source: AGHT+IG+7UAmdiY0BoZwG9iLOw0KtSyypeYXnsCe7CYjI2xbi4A4G8xboXK1Q/fcCptfkBlEV51ecg== X-Received: by 2002:a05:600c:4f51:b0:418:73d1:94e9 with SMTP id m17-20020a05600c4f5100b0041873d194e9mr2017672wmq.4.1713450432345; Thu, 18 Apr 2024 07:27:12 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:999:a3a0:7b64:4d1d:16d8:e38b]) by smtp.gmail.com with ESMTPSA id v10-20020a05600c470a00b00418a386c059sm2873645wmo.42.2024.04.18.07.27.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 07:27:11 -0700 (PDT) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Conor Dooley , Rob Herring , Krzysztof Kozlowski , Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Atish Patra Cc: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, Ved Shanbhogue Subject: [RFC PATCH 2/7] dt-bindings: riscv: add Ssdbltrp ISA extension description Date: Thu, 18 Apr 2024 16:26:41 +0200 Message-ID: <20240418142701.1493091-3-cleger@rivosinc.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240418142701.1493091-1-cleger@rivosinc.com> References: <20240418142701.1493091-1-cleger@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240418_152714_459990_36714E8D X-CRM114-Status: UNSURE ( 7.90 ) X-CRM114-Notice: Please train this message. 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 Add description for the Ssdbltrp ISA extension which is not yet ratified. Signed-off-by: Clément Léger --- Documentation/devicetree/bindings/riscv/extensions.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/riscv/extensions.yaml b/Documentation/devicetree/bindings/riscv/extensions.yaml index 63d81dc895e5..ce7021dbb556 100644 --- a/Documentation/devicetree/bindings/riscv/extensions.yaml +++ b/Documentation/devicetree/bindings/riscv/extensions.yaml @@ -147,6 +147,12 @@ properties: and mode-based filtering as ratified at commit 01d1df0 ("Add ability to manually trigger workflow. (#2)") of riscv-count-overflow. + - const: ssdbltrp + description: | + The standard Ssdbltrp supervisor-level extension for double trap + handling as currently defined by commit e85847b ("Merge pull request + #32 from ved-rivos/0415_1 ") of riscv-double-trap. + - const: sstc description: | The standard Sstc supervisor-level extension for time compare as From patchwork Thu Apr 18 14:26:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 13634996 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 9493DC04FF8 for ; Thu, 18 Apr 2024 15:31:50 +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=fknYDcSHZFw+964Sq+ow+exQlWaTW7e+pptNA5fgid0=; b=xsveh4pFe8Uqho j0Mak96EmxBYavhcP8H913SrYyPxXvtnGOxHURhtL3Qo8RkBWoXSxMQX+1zkx/0T0hQBC9JJPLaiP /CAuc+KFqILsabFz4wJ/FufJZceJRpyxO+BaZ4Or7wAhmxDVU+x51nMbVTvOoQeWD2EpTj9s6mGot ySKJpVF816/+utcfFOfrrcw/aNYHUASwZ3RwptxBq4ZWwSLaX2URYy4vM0cnBd0yMdaLd2Lpw2je4 h5JeAnjr2lYZui5r7Y2QZqCOXedk5WoF1ufhCrTFgqXWX+fdhMIUmb2iZT7+aVyrZrAvpB101Y6S3 C/XxaevYs1i+g5OAN/7Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxTjl-00000002nun-0cQM; Thu, 18 Apr 2024 15:31:45 +0000 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxSjL-00000002cVh-09Qf for linux-riscv@lists.infradead.org; Thu, 18 Apr 2024 14:27:17 +0000 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-346407b8c9aso257186f8f.0 for ; Thu, 18 Apr 2024 07:27:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1713450433; x=1714055233; darn=lists.infradead.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=2hh6e2GF78oUYrxH7UeTADA8qs5jCuVhRAdsmr48k94=; b=oZYLE9zHIWJJo9jBN0XS0b5MXA84NO43k6hseAS2sV99vDG0unecJ+ou04YD67DdnT ydKPXsW6Cy3st8HiqjgdszZ30xOKO7Wxlz0B3nV8J3cUZzuSrnlsa9ClL5U4v52SJmfO PaNbQy3X5hxM6OP5u5yxot1MHp5rwvaRfxpOe7aRsqWBFdYQpdvfn/6lsaQo2nGXBq1T LqgFqCV7T0ee3O6t5wUY43Rv/zjaqEFZgpo4aV6xUXZGFQZOt4zdKyPyp1fC74nGKMVV gFhRxtnecguWCuX2nnCTKyXyEO0TVEVocrFymvEo9doKHWXpBrDfWTgV6BpuWgNvIyIB 1zrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713450433; x=1714055233; 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=2hh6e2GF78oUYrxH7UeTADA8qs5jCuVhRAdsmr48k94=; b=QLZwnnTuQAVZjUjYglwTCdQFCsqIxi7d0QdLEemzfA9ItTVgiQGol465cfIdpNL3cw arIxNSqJfQYkNQPquqM4d6Qy4r+/1lg2P/uTxZgEEj838OyDiWk7A0PAHdxGbpkqmbsx tO7ErGCugblc3urKGYjKl/y7c5//cm6sF6rIisJblPQH2lsheHo96zLfvGcsZfLfm2tl /fFJfJ2TdxfSZk6NDFB4tPLiw9oc9gbavNgWSf40OYdjG5nwMP+StwgucjCFrz1acoWa JBKu34WpBkgGccCrw2geP5jSH6NPWJHG9KxZgYc8Flg7r53+Fe+Sylrc2ymIJSrE5/72 xfdQ== X-Forwarded-Encrypted: i=1; AJvYcCWLLtTbn1d7euHjJt7fF0heEII36JjwXIIszxP7rM1aFln5ELsEK72Rgyw0k3XQHkO0mI5Cz21wbhhZCNI7F+bcM7VatJWJtjUj6DtHU6I8 X-Gm-Message-State: AOJu0YyQCqzDOszjaeSJbLjKJKAfxuL0MTZ+B+3yQvjxbrnhOvyukwxQ IR/CpCJBsQFjulCGH/fTiLwI2ep94E+QZi+PlbFWCU/ZJsTesPMyTWGPw+pqqK4= X-Google-Smtp-Source: AGHT+IHtDtcO4AoiryjW0Pig9lF2J1fPpYbAE7uetQUD4j2yMmH3o1hOU+m/bZxddoy6PQKmq3VrHg== X-Received: by 2002:a05:600c:55d7:b0:418:ef65:4b5f with SMTP id jq23-20020a05600c55d700b00418ef654b5fmr1037961wmb.3.1713450433361; Thu, 18 Apr 2024 07:27:13 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:999:a3a0:7b64:4d1d:16d8:e38b]) by smtp.gmail.com with ESMTPSA id v10-20020a05600c470a00b00418a386c059sm2873645wmo.42.2024.04.18.07.27.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 07:27:12 -0700 (PDT) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Conor Dooley , Rob Herring , Krzysztof Kozlowski , Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Atish Patra Cc: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, Ved Shanbhogue Subject: [RFC PATCH 3/7] riscv: add Ssdbltrp ISA extension parsing Date: Thu, 18 Apr 2024 16:26:42 +0200 Message-ID: <20240418142701.1493091-4-cleger@rivosinc.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240418142701.1493091-1-cleger@rivosinc.com> References: <20240418142701.1493091-1-cleger@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240418_072715_117601_D30F52FB X-CRM114-Status: UNSURE ( 8.93 ) X-CRM114-Notice: Please train this message. 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 Handle Ssdbltrp extension at isa parsing level. Signed-off-by: Clément Léger --- arch/riscv/include/asm/csr.h | 1 + arch/riscv/include/asm/hwcap.h | 1 + arch/riscv/kernel/cpufeature.c | 1 + 3 files changed, 3 insertions(+) diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h index 510014051f5d..5528159b3d5d 100644 --- a/arch/riscv/include/asm/csr.h +++ b/arch/riscv/include/asm/csr.h @@ -102,6 +102,7 @@ #define EXC_INST_PAGE_FAULT 12 #define EXC_LOAD_PAGE_FAULT 13 #define EXC_STORE_PAGE_FAULT 15 +#define EXC_DOUBLE_TRAP 16 #define EXC_INST_GUEST_PAGE_FAULT 20 #define EXC_LOAD_GUEST_PAGE_FAULT 21 #define EXC_VIRTUAL_INST_FAULT 22 diff --git a/arch/riscv/include/asm/hwcap.h b/arch/riscv/include/asm/hwcap.h index 5340f818746b..16d2ad7ca9b2 100644 --- a/arch/riscv/include/asm/hwcap.h +++ b/arch/riscv/include/asm/hwcap.h @@ -80,6 +80,7 @@ #define RISCV_ISA_EXT_ZFA 71 #define RISCV_ISA_EXT_ZTSO 72 #define RISCV_ISA_EXT_ZACAS 73 +#define RISCV_ISA_EXT_SSDBLTRP 74 #define RISCV_ISA_EXT_MAX 128 #define RISCV_ISA_EXT_INVALID U32_MAX diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index 89920f84d0a3..5cff21adf2c4 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -303,6 +303,7 @@ const struct riscv_isa_ext_data riscv_isa_ext[] = { __RISCV_ISA_EXT_DATA(smstateen, RISCV_ISA_EXT_SMSTATEEN), __RISCV_ISA_EXT_DATA(ssaia, RISCV_ISA_EXT_SSAIA), __RISCV_ISA_EXT_DATA(sscofpmf, RISCV_ISA_EXT_SSCOFPMF), + __RISCV_ISA_EXT_DATA(ssdbltrp, RISCV_ISA_EXT_SSDBLTRP), __RISCV_ISA_EXT_DATA(sstc, RISCV_ISA_EXT_SSTC), __RISCV_ISA_EXT_DATA(svinval, RISCV_ISA_EXT_SVINVAL), __RISCV_ISA_EXT_DATA(svnapot, RISCV_ISA_EXT_SVNAPOT), From patchwork Thu Apr 18 14:26:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 13634997 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 24B19C4345F for ; Thu, 18 Apr 2024 15:31: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=BJOq/s2swcdAaUtNaQACS2q99BaAEkvOU5lSQpzbz0Q=; b=PBCw9uXID+LQLJ py+uZcIvOd8bPLGaIXZnBGc/6Toc5DNYoz3Zaaz68CtNbF6nEu/U689B9QKBOaMGHfyXvGGIHwEWk rYTctt3Gny0H/mt4cj+GQAuyWcb4UvvY+PLPBQJeJ0J5tNaK1hbX10mxyFhQa5w/ACxAoiIFFAvfe 1HEy97tAKSRn1L73EzwXhHPUCxxP4VqsinbnXWuxvcI91IYTZlcAvKFgbemJB51xNFcQOkVHzTg0a Px5YrY2vHxqr1L7TzESkym7zsoH1TOfINPh88gCQHDI1n9xX0GFPJyTuv9DBlzhi9+jobABB1Jnz3 ka1OflxLM0dNZnRuRJhA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxTjq-00000002nzM-42Py; Thu, 18 Apr 2024 15:31:50 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxSjP-00000002cY4-1zaz for linux-riscv@bombadil.infradead.org; Thu, 18 Apr 2024 14:27:19 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:Content-Type :MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=m/abrO6aRdYSwYEiniLJTSjXDsMHpzNjwZUI0bHiQJI=; b=LG6GtYafBkxrgqHArbSmWKcvY/ SE5uH3zmOC+w8j8WcEdV4u0FvmRHqvnYtqcto1E0ApP9O6Mwnpwz1lPeCJ1XxdrGnYvbsV0J6zVHE 8UMboMLqjn+bzIF4EKbEZdEsGSt/FESPQaM9KTeq6XmFnkArjjc7uj9ViBlzXpYCfNVAF7kBdf/5R x3/9hSW1SU7MFyek+d+LisdEwRItH+eHQrSnYmpcmCrnwQeZnzuqTfuwt6Pm0W2JFUt4Fsm+wuFqw y4ZYieJtqoXnB/i+4QF4466jZU9e9z+KwYfQZU2lAcIIdCk/VxKKTEIKqWvLfOzRypPKGbo8/HWrz zai7ZBeA==; Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxSjM-0000000C2PM-17cl for linux-riscv@lists.infradead.org; Thu, 18 Apr 2024 14:27:18 +0000 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-349a35aba9dso167608f8f.3 for ; Thu, 18 Apr 2024 07:27:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1713450434; x=1714055234; darn=lists.infradead.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=m/abrO6aRdYSwYEiniLJTSjXDsMHpzNjwZUI0bHiQJI=; b=Uz77sTkw5q9geby3ck94PZzmiOCVVLrWvczIqA+VM2y0X9SkoMgfc3YwgJuTMzRN8+ 9Ly/TiQlukai6hsXhbjorXuNnWeC86gwEEbNaKd9v6RL7pRP/D/TrsG8WpCVfsFz/+CG 4obNyf085rSi6y9Via9u3apeDfvfsRsGkjr+p3jsJ/xMgvn424bn6ohZA3IhND0sq9aM 22eZo2E9ZlXGp7djq049zFjMleRcqX4iE4LOn4SlzDPGaaHISNIDdF4thrTqRpou5Er6 e5246HPTKV4+BRL69ITwv56yle+61M0tHXdiGfmldqkn4Eq3LHxoLDyaZeAzEegdYvS9 c5qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713450434; x=1714055234; 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=m/abrO6aRdYSwYEiniLJTSjXDsMHpzNjwZUI0bHiQJI=; b=MC5lO39xLmnGjWCUUtWu9P52h7LOoF6wPP1vS+YjLujxNqxHyzfGZl4UTvU+gCw3oC KKJhXMlEZiL3+u+N+vzo2UP4qQdiTkfv08GH6WFv+uJVnb/HFB8hUH41xKrT/FyonST+ yoxPqgpd7y+eGFZbX8HaWhnaDd1imoywKS2brAqNUWaEjlbsMFHmEJTkCsNxFJJyUWZj guNFTWUqx0L0v3tTTrM5Iz+wMnWpwHEWbyFGFq4KI49RWpfQ1VOUDeQNWD5+KfF+xvBd +SNfBHKA/d9YP3HT8fBWQiwf7FOuX4W/7f9HGtHio3iZIsyE1ouOC93IsFLXET7bfftj HDdg== X-Forwarded-Encrypted: i=1; AJvYcCVRAkcUGYLpBL0yHpVjIXCAqEGiSqhvJekJj/5Viy8zhkJ5pSxdHrWqg8fZNsOi+pzzRVbye13Tw2t8kTqXQdaT1zKQkzKcC4TOWyRLKomu X-Gm-Message-State: AOJu0YwuqHX7mHffwkXhM4G6j7NW2nqqSgQ/S3MTQK7g5QvrRddNXQ3d juC98mCg796uCtGTlSagwuXsyBhqVoWHmxMJnBgjVSM6HWQb4/Ky3Yo4y5AdZxs= X-Google-Smtp-Source: AGHT+IEkGDIAezbeIVZmmrT9rlRCJjcxopA8THm4S/C75RtVNLUvN35X394KK2J0KQ/iPXZ6II3FvA== X-Received: by 2002:a05:600c:4f8a:b0:418:f770:ba0 with SMTP id n10-20020a05600c4f8a00b00418f7700ba0mr505923wmq.0.1713450434242; Thu, 18 Apr 2024 07:27:14 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:999:a3a0:7b64:4d1d:16d8:e38b]) by smtp.gmail.com with ESMTPSA id v10-20020a05600c470a00b00418a386c059sm2873645wmo.42.2024.04.18.07.27.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 07:27:13 -0700 (PDT) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Conor Dooley , Rob Herring , Krzysztof Kozlowski , Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Atish Patra Cc: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, Ved Shanbhogue Subject: [RFC PATCH 4/7] riscv: handle Ssdbltrp mstatus SDT bit Date: Thu, 18 Apr 2024 16:26:43 +0200 Message-ID: <20240418142701.1493091-5-cleger@rivosinc.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240418142701.1493091-1-cleger@rivosinc.com> References: <20240418142701.1493091-1-cleger@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240418_152716_426701_08D905F7 X-CRM114-Status: GOOD ( 15.01 ) 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 When Ssdbltrp is enabled, we must take care of clearing SDT after sensitive phases are over to avoid generating a double trap. This is mainly about exceptions handling so clear SDT once we have saved enough information (critical CSRs) but also clears it during SATP mode detection which generates an "inline" trap and thus sets SDT implicitely. Signed-off-by: Clément Léger --- arch/riscv/include/asm/csr.h | 1 + arch/riscv/kernel/entry.S | 52 ++++++++++++++++++++--------------- arch/riscv/kernel/head.S | 4 +++ arch/riscv/kernel/sse_entry.S | 4 +-- 4 files changed, 37 insertions(+), 24 deletions(-) diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h index 5528159b3d5d..905cdf894a57 100644 --- a/arch/riscv/include/asm/csr.h +++ b/arch/riscv/include/asm/csr.h @@ -17,6 +17,7 @@ #define SR_SPP _AC(0x00000100, UL) /* Previously Supervisor */ #define SR_MPP _AC(0x00001800, UL) /* Previously Machine */ #define SR_SUM _AC(0x00040000, UL) /* Supervisor User Memory Access */ +#define SR_SDT _AC(0x01000000, UL) /* Supervisor Double Trap */ #define SR_FS _AC(0x00006000, UL) /* Floating-point Status */ #define SR_FS_OFF _AC(0x00000000, UL) diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S index 1591e0781569..07da91080839 100644 --- a/arch/riscv/kernel/entry.S +++ b/arch/riscv/kernel/entry.S @@ -49,23 +49,12 @@ SYM_CODE_START(handle_exception) REG_S x5, PT_T0(sp) save_from_x6_to_x31 - /* - * Disable user-mode memory access as it should only be set in the - * actual user copy routines. - * - * Disable the FPU/Vector to detect illegal usage of floating point - * or vector in kernel space. - */ - li t0, SR_SUM | SR_FS_VS - REG_L s0, TASK_TI_USER_SP(tp) - csrrc s1, CSR_STATUS, t0 csrr s2, CSR_EPC csrr s3, CSR_TVAL csrr s4, CSR_CAUSE csrr s5, CSR_SCRATCH REG_S s0, PT_SP(sp) - REG_S s1, PT_STATUS(sp) REG_S s2, PT_EPC(sp) REG_S s3, PT_BADADDR(sp) REG_S s4, PT_CAUSE(sp) @@ -77,6 +66,21 @@ SYM_CODE_START(handle_exception) */ csrw CSR_SCRATCH, x0 + /* + * Disable user-mode memory access as it should only be set in the + * actual user copy routines. + * + * Disable the FPU/Vector to detect illegal usage of floating point + * or vector in kernel space. + * + * Clear supervisor double trap bit as all trap context is saved and we + * can handle another one + */ + li t0, SR_SUM | SR_FS_VS | SR_SDT + + csrrc s1, CSR_STATUS, t0 + REG_S s1, PT_STATUS(sp) + /* Load the global pointer */ load_global_pointer @@ -123,15 +127,25 @@ SYM_CODE_START_NOALIGN(ret_from_exception) #ifdef CONFIG_RISCV_M_MODE /* the MPP value is too large to be used as an immediate arg for addi */ li t0, SR_MPP - and s0, s0, t0 + and t1, s0, t0 #else - andi s0, s0, SR_SPP + andi t1, s0, SR_SPP +#endif + +#ifdef CONFIG_RISCV_ISA_V_PREEMPTIVE + move a0, sp + call riscv_v_context_nesting_end #endif - bnez s0, 1f + /* + * Restore STATUS now to set supervisor double trap bit which means that + * from now on, we can not handle an exception up to "sret" + */ + csrw CSR_STATUS, s0 + bnez t1, 1f /* Save unwound kernel stack pointer in thread_info */ - addi s0, sp, PT_SIZE_ON_STACK - REG_S s0, TASK_TI_KERNEL_SP(tp) + addi t1, sp, PT_SIZE_ON_STACK + REG_S t1, TASK_TI_KERNEL_SP(tp) /* Save the kernel shadow call stack pointer */ scs_save_current @@ -142,11 +156,6 @@ SYM_CODE_START_NOALIGN(ret_from_exception) */ csrw CSR_SCRATCH, tp 1: -#ifdef CONFIG_RISCV_ISA_V_PREEMPTIVE - move a0, sp - call riscv_v_context_nesting_end -#endif - REG_L a0, PT_STATUS(sp) /* * The current load reservation is effectively part of the processor's * state, in the sense that load reservations cannot be shared between @@ -167,7 +176,6 @@ SYM_CODE_START_NOALIGN(ret_from_exception) REG_L a2, PT_EPC(sp) REG_SC x0, a2, PT_EPC(sp) - csrw CSR_STATUS, a0 csrw CSR_EPC, a2 REG_L x1, PT_RA(sp) diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S index 4236a69c35cb..bcc2b6678f40 100644 --- a/arch/riscv/kernel/head.S +++ b/arch/riscv/kernel/head.S @@ -106,6 +106,10 @@ relocate_enable_mmu: csrw CSR_SATP, a0 .align 2 1: + /* A trap potentially set the SDT flag, clear it */ + li t0, SR_SDT + csrc CSR_STATUS, t0 + /* Set trap vector to spin forever to help debug */ la a0, .Lsecondary_park csrw CSR_TVEC, a0 diff --git a/arch/riscv/kernel/sse_entry.S b/arch/riscv/kernel/sse_entry.S index d3c7286f3372..e69d386e36e9 100644 --- a/arch/riscv/kernel/sse_entry.S +++ b/arch/riscv/kernel/sse_entry.S @@ -65,7 +65,7 @@ SYM_CODE_START(handle_sse) REG_S a4, PT_SP(sp) /* Disable user memory access and floating/vector computing */ - li t0, SR_SUM | SR_FS_VS + li t0, SR_SUM | SR_FS_VS | SR_SDT csrc CSR_STATUS, t0 load_global_pointer @@ -131,8 +131,8 @@ SYM_CODE_START(handle_sse) SYM_INNER_LABEL(ret_from_sse, SYM_L_GLOBAL) /* Restore saved CSRs */ - csrw CSR_SSCRATCH, s4 csrw CSR_SSTATUS, s5 + csrw CSR_SSCRATCH, s4 #ifdef CONFIG_FRAME_POINTER /* Frame pointer is created only when kernel is interrupted */ From patchwork Thu Apr 18 14:26:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 13634998 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 639A8C4345F for ; Thu, 18 Apr 2024 15:32: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=tgiqXKcC034axXg50Y0HtV9wpRKSeAXfDLoVFgzR5n4=; b=xUbCoAKE3I/CkH 7OkgFhjLUQpr7qGewtAsamGnkKKaM6vFHVokQybc4Nh8yBlgLqx9JkXr6KDDmeImZivmn3TtLEnWS YRjz99WqKiac8aFXhuulKUz+a02JwszXYcLD7Et55OC4nZOVdln5tYHOoFllPotxVOf+cChu10RA5 hIgyoRRoMAL1dpAbcvYYDcEeKiCFeHwL4O2FWY4as3UBmxUmS+WaTFSQOC8QDXufugxlGhMV6Yxnn LAC478ridalAsQwG46HBNyG8DCPst4eY/KazwBheLJOElPypG7lRpDzgJbz8MJ1/faRM4wS1JrRyT gS7MT6BWs/dUSjyfbAfQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxTjw-00000002o3a-1SqF; Thu, 18 Apr 2024 15:31:56 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxSjR-00000002cYl-2C0r for linux-riscv@bombadil.infradead.org; Thu, 18 Apr 2024 14:27:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:Content-Type :MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=/AvdB3u3xfYtOVc85K9gr+w0O/Mfoyuz+qydkV22p5c=; b=Xu7sqDaQAsKGTZJkfnVNbExYa2 sCEhNogcE7RarBKb96cSoiT9kyG/SjbHGQnKR36NUEsbMfIUnmOK3pFMYmv1pfcPSOhF1B2MkZOTF whDZ41Z/T2njXnbPTnJYVjjPC26D2JM3tYYE7TDOtu1CHnwa47cIxvlHkwTIW2f0n38oJ0trCanCm XXHE+cdZMxid5EB5eUEJ9EV6yjaiqbnb3O0A3JBs+fUtcvNi7EUzodfoUWnznCOo6f7xUAEM6B7j4 yVFRVFUxwqc1v1ybAQOWc+J6wJf6AdS0GXHBlZ3wHRrSG4J8alWyBWb1+X2A9DfXJzpx3Z6N+kT/y QaXJ3iuw==; Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxSjN-0000000C2Pa-0NVd for linux-riscv@lists.infradead.org; Thu, 18 Apr 2024 14:27:19 +0000 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-346407b8c9aso257200f8f.0 for ; Thu, 18 Apr 2024 07:27:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1713450435; x=1714055235; darn=lists.infradead.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=/AvdB3u3xfYtOVc85K9gr+w0O/Mfoyuz+qydkV22p5c=; b=PM/u6q1OdFkCQf1GXofsvfbkVOWm1kQ62dllCGZBAX+0rpD7iRejofC+vqE/Mk+EUs cgTEzo7TOnZDLGDmuT709BoNy2rcFWh3QOhMGROQY2Pt1aB6/b1QE1AG/wkV3vgYUpj7 y9URkYPQFwE7UOwWWVrX2k8chjUD3L7+0El9jhAMJuZTlM2P5+5UnUbcDSfm7/BUXypu HMtEcH3baPbXC13ZCtvrsPdqMyZyHHpKwTcSSQYYjQRiEiOvJVQ5mFwnbDUrZHjnti4B dkPSi77vlk9agW2TJpOO9y9KZ6vWyyWgYKpnQmdO0yHiL951gJoFRtYkjoUXkf+NQw7K RrNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713450435; x=1714055235; 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=/AvdB3u3xfYtOVc85K9gr+w0O/Mfoyuz+qydkV22p5c=; b=g7Fa7GuygYUzq4+2BOc88ME2eNuNsl7MU/QiSIvGd/ettehug2HNlSPZvxQgh13ZAJ 1LP5TzOdOlrPDs/O+x5/IHCB8iD02Krq12PVQAblWjBekYuu2tccDCWX1p1xVcJY6vKo jfaY3rOILmYoKiCj0gdUFhy+4PlFyTjfmOkaikPzdLb4Jsspz1Lr4z+++F2Sym1D3NsB aiJHG4e1+C5jXJtAKiNvghRaHC3JucUB5zkZ/McTV4BpCpOh0d70xjkluldO0vnCtWl5 G+cPxRRLxqy66irg2NZWkjAdbiHiwy7+GFmcFlUMhjFYxVtMOrkVaeqeARrbk+5y7c1Z oouw== X-Forwarded-Encrypted: i=1; AJvYcCXXhRxCBCCE24Tqq9f77C0UDYLTPhIyBKbqHPBGQQEziO5qfTVT96qqLYKIBjjYzS6IBTzZ81lLVjAsLWMfeEAosufQAHpd9HYDb6DNArLZ X-Gm-Message-State: AOJu0Yz/ETJz6YWqGg7cvVI4HeKfXxO9DcFIeZavLR411xB0n120Mkbd bRIAizdiWyhypDIEngM/12+49PMky9Yyp1VfEm0N5Q6JcOskYmXsiw8uMuU/wh2PIQ1MtkQFjTz 6haw= X-Google-Smtp-Source: AGHT+IEwlQ04KaJP3EVY+XCohGbQqha8fE09E68ZNltKaQxFJ4YDXOPGuVd4fVf/pEkQ78VT8bcTuA== X-Received: by 2002:a05:600c:35ca:b0:418:9941:ca28 with SMTP id r10-20020a05600c35ca00b004189941ca28mr2125666wmq.2.1713450435180; Thu, 18 Apr 2024 07:27:15 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:999:a3a0:7b64:4d1d:16d8:e38b]) by smtp.gmail.com with ESMTPSA id v10-20020a05600c470a00b00418a386c059sm2873645wmo.42.2024.04.18.07.27.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 07:27:14 -0700 (PDT) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Conor Dooley , Rob Herring , Krzysztof Kozlowski , Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Atish Patra Cc: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, Ved Shanbhogue Subject: [RFC PATCH 5/7] riscv: add double trap driver Date: Thu, 18 Apr 2024 16:26:44 +0200 Message-ID: <20240418142701.1493091-6-cleger@rivosinc.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240418142701.1493091-1-cleger@rivosinc.com> References: <20240418142701.1493091-1-cleger@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240418_152718_047130_63EA020F X-CRM114-Status: GOOD ( 18.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 Add a small driver to request double trap enabling as well as registering a SSE handler for double trap. This will also be used by KVM SBI FWFT extension support to detect if it is possible to enable double trap in VS-mode. Signed-off-by: Clément Léger --- arch/riscv/include/asm/sbi.h | 1 + drivers/firmware/Kconfig | 7 +++ drivers/firmware/Makefile | 1 + drivers/firmware/riscv_dbltrp.c | 95 +++++++++++++++++++++++++++++++++ include/linux/riscv_dbltrp.h | 19 +++++++ 5 files changed, 123 insertions(+) create mode 100644 drivers/firmware/riscv_dbltrp.c create mode 100644 include/linux/riscv_dbltrp.h diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index 744aa1796c92..9cd4ca66487c 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -314,6 +314,7 @@ enum sbi_sse_attr_id { #define SBI_SSE_ATTR_INTERRUPTED_FLAGS_SPIE (1 << 2) #define SBI_SSE_EVENT_LOCAL_RAS 0x00000000 +#define SBI_SSE_EVENT_LOCAL_DOUBLE_TRAP 0x00000001 #define SBI_SSE_EVENT_GLOBAL_RAS 0x00008000 #define SBI_SSE_EVENT_LOCAL_PMU 0x00010000 #define SBI_SSE_EVENT_LOCAL_SOFTWARE 0xffff0000 diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig index 59f611288807..a037f6e89942 100644 --- a/drivers/firmware/Kconfig +++ b/drivers/firmware/Kconfig @@ -197,6 +197,13 @@ config RISCV_SSE_TEST Select if you want to enable SSE extension testing at boot time. This will run a series of test which verifies SSE sanity. +config RISCV_DBLTRP + bool "Enable Double trap handling" + depends on RISCV_SSE && RISCV_SBI + default n + help + Select if you want to enable SSE double trap handler. + config SYSFB bool select BOOT_VESA_SUPPORT diff --git a/drivers/firmware/Makefile b/drivers/firmware/Makefile index fb7b0c08c56d..ad67a1738c0f 100644 --- a/drivers/firmware/Makefile +++ b/drivers/firmware/Makefile @@ -18,6 +18,7 @@ obj-$(CONFIG_RASPBERRYPI_FIRMWARE) += raspberrypi.o obj-$(CONFIG_FW_CFG_SYSFS) += qemu_fw_cfg.o obj-$(CONFIG_RISCV_SSE) += riscv_sse.o obj-$(CONFIG_RISCV_SSE_TEST) += riscv_sse_test.o +obj-$(CONFIG_RISCV_DBLTRP) += riscv_dbltrp.o obj-$(CONFIG_SYSFB) += sysfb.o obj-$(CONFIG_SYSFB_SIMPLEFB) += sysfb_simplefb.o obj-$(CONFIG_TI_SCI_PROTOCOL) += ti_sci.o diff --git a/drivers/firmware/riscv_dbltrp.c b/drivers/firmware/riscv_dbltrp.c new file mode 100644 index 000000000000..72f9a067e87a --- /dev/null +++ b/drivers/firmware/riscv_dbltrp.c @@ -0,0 +1,95 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2023 Rivos Inc. + */ + +#define pr_fmt(fmt) "riscv-dbltrp: " fmt + +#include +#include +#include +#include + +#include + +static bool double_trap_enabled; + +static int riscv_sse_dbltrp_handle(uint32_t evt, void *arg, + struct pt_regs *regs) +{ + __show_regs(regs); + panic("Double trap !\n"); + + return 0; +} + +struct cpu_dbltrp_data { + int error; +}; + +static void +sbi_cpu_enable_double_trap(void *data) +{ + struct sbiret ret; + struct cpu_dbltrp_data *cdd = data; + + ret = sbi_ecall(SBI_EXT_FWFT, SBI_EXT_FWFT_SET, + SBI_FWFT_DOUBLE_TRAP_ENABLE, 1, 0, 0, 0, 0); + + if (ret.error) { + cdd->error = 1; + pr_err("Failed to enable double trap on cpu %d\n", smp_processor_id()); + } +} + +static int sbi_enable_double_trap(void) +{ + struct cpu_dbltrp_data cdd = {0}; + + on_each_cpu(sbi_cpu_enable_double_trap, &cdd, 1); + if (cdd.error) + return -1; + + double_trap_enabled = true; + + return 0; +} + +bool riscv_double_trap_enabled(void) +{ + return double_trap_enabled; +} +EXPORT_SYMBOL(riscv_double_trap_enabled); + +static int __init riscv_dbltrp(void) +{ + struct sse_event *evt; + + if (!riscv_has_extension_unlikely(RISCV_ISA_EXT_SSDBLTRP)) { + pr_err("Ssdbltrp extension not available\n"); + return 1; + } + + if (!sbi_probe_extension(SBI_EXT_FWFT)) { + pr_err("Can not enable double trap, SBI_EXT_FWFT is not available\n"); + return 1; + } + + if (sbi_enable_double_trap()) { + pr_err("Failed to enable double trap on all cpus\n"); + return 1; + } + + evt = sse_event_register(SBI_SSE_EVENT_LOCAL_DOUBLE_TRAP, 0, + riscv_sse_dbltrp_handle, NULL); + if (IS_ERR(evt)) { + pr_err("SSE double trap register failed\n"); + return PTR_ERR(evt); + } + + sse_event_enable(evt); + pr_info("Double trap handling registered\n"); + + return 0; +} +device_initcall(riscv_dbltrp); diff --git a/include/linux/riscv_dbltrp.h b/include/linux/riscv_dbltrp.h new file mode 100644 index 000000000000..6de4f43fae6b --- /dev/null +++ b/include/linux/riscv_dbltrp.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2023 Rivos Inc. + */ + +#ifndef __LINUX_RISCV_DBLTRP_H +#define __LINUX_RISCV_DBLTRP_H + +#if defined(CONFIG_RISCV_DBLTRP) +bool riscv_double_trap_enabled(void); +#else + +static inline bool riscv_double_trap_enabled(void) +{ + return false; +} +#endif + +#endif /* __LINUX_RISCV_DBLTRP_H */ From patchwork Thu Apr 18 14:26:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 13634929 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 70D6CC04FFF for ; Thu, 18 Apr 2024 14:27:42 +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=a14bx2KM5zOOjpNjaJOuSOBJhiWBH60SMOeCH4F9pSc=; b=vMqp6++EkPPEK+ 8cCgPTREVJh5yLbBs4b82dkwo1KomKV59bpAkJ5foZ8OU5W4uzwzNKAMUO3ZtfoNBj0uAX73/SrwO pd4h0XRsPrW3Ml1OmQbKesr6dyaEOi8p9Um9HZqoKCDDmVMd5VPohIvP9+l/IXnIJH6RmaiDURLnw ceGeft64lqI+Rs6SVxB1ZdT1fjZRzTYPJNUGkfZgC0ASg3KgTg5A7vSIeh9c6Hu35TGQ0OjDXmSfd TZXdrNVN/ajCc8zhoZG26WJhnjxv1BSNFUUZ3WDss8317GV9AUJPMO6k4iTbKp1iqkcJMZKEM5jq7 OGy4UEvyXd8OnWlqpVmw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxSjf-00000002cdD-0aqz; Thu, 18 Apr 2024 14:27:35 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxSjR-00000002cYz-3yyb for linux-riscv@bombadil.infradead.org; Thu, 18 Apr 2024 14:27:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:Content-Type :MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=JY0qCZAt1G9FqrirGdQPEL//dx+I/VeYeDHijBAzwaE=; b=Qro7cHd3fC+Dkn+BgdtiHMkZNx 0nhRdA2wE/tJPQN4fqr5fO2GXqSYW1cjNtVIZ6G40/4uCKJAhEdlGVNnpWTJi4j6L+5KACHi2REmT Fa1k7cGqF6wcXm6yRrigIwz97MMgm/L+UL5rvJKlVZzLswJsFfi9u1UdFJ76nlC4QTfsfFM2FL78d CcAFzPtELlvEjxoZ8Kif51bsfGiaLyvmoAJszCmBSi12w9SpZiHDqMY7/QoyDKzzd+eLxJts8uy/m Epzwb6CUFMcFxusjujaY3sF5FpUCs6y7GRb5pMLnlOzey+cwTLN/Q+Jh2rKazRtrDZOA+OuZ0VMKC f8C7cinQ==; Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxSjN-0000000C2Pk-2ovD for linux-riscv@lists.infradead.org; Thu, 18 Apr 2024 14:27:19 +0000 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-349a35aba9dso167616f8f.3 for ; Thu, 18 Apr 2024 07:27:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1713450436; x=1714055236; darn=lists.infradead.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=JY0qCZAt1G9FqrirGdQPEL//dx+I/VeYeDHijBAzwaE=; b=ARG4KZEShLKzSSE9s4vbuISuP7kCYtUb85M/J5mhftVZXIDH9uLn9Da+EqCMZ4yxKI beroNeh8VJaWrKpaYesms4/NVZtodywiZUj4Sx+bMvoBJ6WtSlDc3HODNyyzqdS4lPnG dTBfPNruy9jOr9A5k6tzus/dkZNuMG3MDkpISTcSY9E9w6o1j+rHNYdRhTVBlfxbOf5J xy4HZBBSQxLO5yrw69tCMCk6EmSbPBU8dlroh141wwrhjLO1hh0o35wUCaJkKsFh3Wlq shK/nYTYPJjldrG5hVyUiuUxAz7ScOt2CamY10PJMGro63Q+gS3Qykt5bh21KEHAMheY FpCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713450436; x=1714055236; 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=JY0qCZAt1G9FqrirGdQPEL//dx+I/VeYeDHijBAzwaE=; b=ddrLVNpQBMS45OHgukLFjCXoedKlPG3H7+WfEVePqdZ3Z/lEX7I9o3c9SZjgvSOICT TouwIORCPSn8d3izLamoLOBsmL56LkWU1YJZHki0MC+coJCtpxmQj32TqHiK4BlJ+7jU UjCxkzMKrnV/5sGwCdtBJ+lL6IouzFqjhojICMMhBERrkA87XbTeNJh5vL944qBwLI+x zUviy4ud4VZB+yImsK72NsJUKwYwyAUxqlJfgWF3dxLYcGyKj9P5lQhtx5pvZ8xVhaI6 zDa8oUBFLTVhcatfBn1hLCe9I38PPLhgn260X4DOIqTRsMvlJS1Yrwa8cuxJQHOtMr2D B2FQ== X-Forwarded-Encrypted: i=1; AJvYcCVu1ji11xQ3LlAuPFBLXddHsuRpHMsVZ1Dx7MHWafp0IVnRBshykPQeqCq/Yj42JuK1m44BOTzNqzpxVxsyXIf15fnYi3EnmS6cEBOyx5Ws X-Gm-Message-State: AOJu0Yz7nr/CI8zWGMomgBztNkyvDlTY+CKojqi7ZDpvPWfdId+535TH F9ZpPm0HErXfcTAkZYGUcDXe1c0Av9fqSfJYYWjM00zypynIAiRbLq0NHTaljMU= X-Google-Smtp-Source: AGHT+IG9QM4RObWosVaHJ2Bu9iGsOImG7zvYuk0PErpgTMOYFhKXz5bCpwhT6ZoBg0yBf1Ld4kG3yA== X-Received: by 2002:a05:600c:3554:b0:416:7b2c:df05 with SMTP id i20-20020a05600c355400b004167b2cdf05mr2101037wmq.1.1713450436400; Thu, 18 Apr 2024 07:27:16 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:999:a3a0:7b64:4d1d:16d8:e38b]) by smtp.gmail.com with ESMTPSA id v10-20020a05600c470a00b00418a386c059sm2873645wmo.42.2024.04.18.07.27.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 07:27:15 -0700 (PDT) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Conor Dooley , Rob Herring , Krzysztof Kozlowski , Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Atish Patra Cc: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, Ved Shanbhogue Subject: [RFC PATCH 6/7] riscv: kvm: add SBI FWFT support for SBI_FWFT_DOUBLE_TRAP_ENABLE Date: Thu, 18 Apr 2024 16:26:45 +0200 Message-ID: <20240418142701.1493091-7-cleger@rivosinc.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240418142701.1493091-1-cleger@rivosinc.com> References: <20240418142701.1493091-1-cleger@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240418_152718_108785_4570171D X-CRM114-Status: GOOD ( 15.46 ) 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 Add support in KVM SBI FWFT extension to allow VS-mode to request double trap enabling. Double traps can then be generated by VS-mode, allowing M-mode to redirect them to S-mode. Signed-off-by: Clément Léger --- arch/riscv/include/asm/csr.h | 1 + arch/riscv/include/asm/kvm_vcpu_sbi_fwft.h | 2 +- arch/riscv/kvm/vcpu_sbi_fwft.c | 41 ++++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h index 905cdf894a57..ee1b73655bec 100644 --- a/arch/riscv/include/asm/csr.h +++ b/arch/riscv/include/asm/csr.h @@ -196,6 +196,7 @@ /* xENVCFG flags */ #define ENVCFG_STCE (_AC(1, ULL) << 63) #define ENVCFG_PBMTE (_AC(1, ULL) << 62) +#define ENVCFG_DTE (_AC(1, ULL) << 59) #define ENVCFG_CBZE (_AC(1, UL) << 7) #define ENVCFG_CBCFE (_AC(1, UL) << 6) #define ENVCFG_CBIE_SHIFT 4 diff --git a/arch/riscv/include/asm/kvm_vcpu_sbi_fwft.h b/arch/riscv/include/asm/kvm_vcpu_sbi_fwft.h index 7dc1b80c7e6c..a9e20d655126 100644 --- a/arch/riscv/include/asm/kvm_vcpu_sbi_fwft.h +++ b/arch/riscv/include/asm/kvm_vcpu_sbi_fwft.h @@ -11,7 +11,7 @@ #include -#define KVM_SBI_FWFT_FEATURE_COUNT 1 +#define KVM_SBI_FWFT_FEATURE_COUNT 2 struct kvm_sbi_fwft_config; struct kvm_vcpu; diff --git a/arch/riscv/kvm/vcpu_sbi_fwft.c b/arch/riscv/kvm/vcpu_sbi_fwft.c index b9b7f8fa6d22..9e8e397eb02f 100644 --- a/arch/riscv/kvm/vcpu_sbi_fwft.c +++ b/arch/riscv/kvm/vcpu_sbi_fwft.c @@ -9,10 +9,19 @@ #include #include #include +#include #include #include #include +#ifdef CONFIG_32BIT +# define CSR_HENVCFG_DBLTRP CSR_HENVCFGH +# define DBLTRP_DTE (ENVCFG_DTE >> 32) +#else +# define CSR_HENVCFG_DBLTRP CSR_HENVCFG +# define DBLTRP_DTE ENVCFG_DTE +#endif + #define MIS_DELEG (1UL << EXC_LOAD_MISALIGNED | 1UL << EXC_STORE_MISALIGNED) static int kvm_sbi_fwft_set_misaligned_delegation(struct kvm_vcpu *vcpu, @@ -36,6 +45,33 @@ static int kvm_sbi_fwft_get_misaligned_delegation(struct kvm_vcpu *vcpu, return SBI_SUCCESS; } +static int kvm_sbi_fwft_set_double_trap(struct kvm_vcpu *vcpu, + struct kvm_sbi_fwft_config *conf, + unsigned long value) +{ + if (!riscv_double_trap_enabled()) + return SBI_ERR_NOT_SUPPORTED; + + if (value) + csr_set(CSR_HENVCFG_DBLTRP, DBLTRP_DTE); + else + csr_clear(CSR_HENVCFG_DBLTRP, DBLTRP_DTE); + + return SBI_SUCCESS; +} + +static int kvm_sbi_fwft_get_double_trap(struct kvm_vcpu *vcpu, + struct kvm_sbi_fwft_config *conf, + unsigned long *value) +{ + if (!riscv_double_trap_enabled()) + return SBI_ERR_NOT_SUPPORTED; + + *value = (csr_read(CSR_HENVCFG_DBLTRP) & DBLTRP_DTE) != 0; + + return SBI_SUCCESS; +} + static struct kvm_sbi_fwft_config * kvm_sbi_fwft_get_config(struct kvm_vcpu *vcpu, enum sbi_fwft_feature_t feature) { @@ -111,6 +147,11 @@ static const struct kvm_sbi_fwft_feature features[] = { .id = SBI_FWFT_MISALIGNED_DELEG, .set = kvm_sbi_fwft_set_misaligned_delegation, .get = kvm_sbi_fwft_get_misaligned_delegation, + }, + { + .id = SBI_FWFT_DOUBLE_TRAP_ENABLE, + .set = kvm_sbi_fwft_set_double_trap, + .get = kvm_sbi_fwft_get_double_trap, } }; From patchwork Thu Apr 18 14:26:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 13634928 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 E672EC4345F for ; Thu, 18 Apr 2024 14:27:41 +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=pvfdJbzxVanZOUNqd0HFsAuARsFl2BcjusZBCehIx3Y=; b=QbbZs0hcdlC4ot Gdwv0YyROolw3eS/3CiWNvJyowcu0kihtVc14tWtkjx4ogr+Ark5Vs4fyThFVax+1oy1kYLwF3TV0 0SaK0KSKpoadvo1waSj5vfHykC/fOpflDU0I77o62M0as1mpMjt9eD+xbLNEKoyVF3iw8uQKMpyr6 4FR+zzK/izvIZRDgzZ5ubEGUg/Cwqua7SfkXt9IJPdzlvotjd4Lcj5kwHDYAVV5n6UVLNpJcV0UqV BXh3B/YY0Xu44Naf0gd8XY0sBtOps9EuALFpjODZhQwJyP3HxLGw4rRei8llgnddXKH3OuQKYp9Mh OuVOZc+9FhIZsMPbpkvA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxSjg-00000002cdv-30Iv; Thu, 18 Apr 2024 14:27:36 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxSjT-00000002cZO-0jBq for linux-riscv@bombadil.infradead.org; Thu, 18 Apr 2024 14:27:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:Content-Type :MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=ux6Z0dvHS0AaHNoD8WJhlnEKIxWvWWXWdBe+6rPnELc=; b=dpuEvc1ay+sXAHXwbRXliJzdmj HVsgeCEn9tkkHAVPWEImPbwe/ZZbBlFQh9o2/G9p+NoNqfuiHQLRLWu0ixVuiNTptspYCrrsdbjBP xR9YWeHIU7EntcqKOy2dVAEU5cdngMhxeHf2taMIN0r/mLx0sOl4/GIQEJRI7BFG+CjAemTxIpKvk tp8aCK1dU/FxTHaqbMbDBSVheVpNF45ufoL7MMG6R5LFlGJN6vWrV6dzSbs17/aPorUdi0/FX+b0u 7EJBt8zzLrLX+GqoLwti2jQxotGWoMOO88lbO4LNL2+QwnzQGKqOayyvxYpa08S7MG5nNmgp1RtvU TQU2I4+A==; Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxSjO-0000000C2Qn-2EUf for linux-riscv@lists.infradead.org; Thu, 18 Apr 2024 14:27:22 +0000 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-349a31b2babso113860f8f.2 for ; Thu, 18 Apr 2024 07:27:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1713450437; x=1714055237; darn=lists.infradead.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=ux6Z0dvHS0AaHNoD8WJhlnEKIxWvWWXWdBe+6rPnELc=; b=1KRAWWUQeZvdXssoSeEqxlbXWdYKtBY069p++k346MVhpI2Sc6hRMlHgLzVOz+95kt ySdaGQK15SAOJMspJaI44+IrsLJscvS9QekK10o6J0U7T6bD8jI8UAxBK1Sg+V+S1nva mZ+WB886dTzRFR0mJIiW9Km886CHqFm4hrIRmYtN5xr5s3BRPNViDVC3pD1MA5w8K6tE 6wI2STGRZnlT/L69C1xN5y72nsEjm+x7zF7SDsGMiHqr2nut76wMNqhE2zWxIHrENRHs R79Gd7DYzNnVI3Cu4/re7k+/ngQGsyv9voE8RrVBWskr6diaom7PnnRfU0v7XV1f94Ur LAzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713450437; x=1714055237; 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=ux6Z0dvHS0AaHNoD8WJhlnEKIxWvWWXWdBe+6rPnELc=; b=mZulHEhm7Ng20Q3B5nDXxtdbunUxhpqHIXPsylPoCLhucUzDgzimNtbJrpaT3Ea5Td T8ky++9ao9frYv+bQsdX75ei1ktKNhxBGebKlU2CQbUqc24fHDOsniXaI+29uI6ygihW mKsCeHr3zRpuMSrTNeq7RglzJVTbc0WP0ybCR8sncP7pYFudZ5WPIEdklmLz9mafCG3l Op+/1iXfW8OC+OLq7o/prrTVe/YjNgSeluPY95cYZGiwI5B1uCGOtaMTReYR3Kvv6GOJ omrEzSutys5pHMMHkXp/Dh7jtiZHdxGZPI84f/n8BEC8lkriiylciqlLWZ1wB2bUII/T lUhg== X-Forwarded-Encrypted: i=1; AJvYcCXqh1mMdCbt0iuYzFSRgNAcF4QSZwVdlu6dK5FRjQmxGgUr7kp4zSpLXnHlJDKtMP8tlO7AoHm3KFQ231M7APsJQq2PMtoa4qTcHEzjbvky X-Gm-Message-State: AOJu0YxS4HK231inja4veCrKusohJidsSjx8PvsKcSGmG/nTxVoNfLVY 9n7AhKjG83z3KgbS63L7tPkJupbIM/+kYAHQl6jlQ7lxqK0sITo3ZlEGx1tXVhg= X-Google-Smtp-Source: AGHT+IGBKkRXPRGYPrNf2xynAaVp5CuMPioqb/sz3tcbUIZ90ojHCdGDsQ+aqJS0cvtdtDhHjXauZw== X-Received: by 2002:a05:600c:5101:b0:416:a773:7d18 with SMTP id o1-20020a05600c510100b00416a7737d18mr2062486wms.0.1713450437373; Thu, 18 Apr 2024 07:27:17 -0700 (PDT) Received: from carbon-x1.. ([2a01:e0a:999:a3a0:7b64:4d1d:16d8:e38b]) by smtp.gmail.com with ESMTPSA id v10-20020a05600c470a00b00418a386c059sm2873645wmo.42.2024.04.18.07.27.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 07:27:16 -0700 (PDT) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Conor Dooley , Rob Herring , Krzysztof Kozlowski , Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Atish Patra Cc: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= , linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, Ved Shanbhogue Subject: [RFC PATCH 7/7] RISC-V: KVM: add support for double trap exception Date: Thu, 18 Apr 2024 16:26:46 +0200 Message-ID: <20240418142701.1493091-8-cleger@rivosinc.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240418142701.1493091-1-cleger@rivosinc.com> References: <20240418142701.1493091-1-cleger@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240418_152718_751386_FED9EB8F X-CRM114-Status: GOOD ( 19.36 ) 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 When a double trap exception is generated from VS-mode, it should be delivered to M-mode which might redirect it to S-mode. Currently, the kvm double trap exception handling simply prints an error and returns -EOPNOTSUPP to stop VM execution. In future, this might use KVM SBI SSE extension implementation to actually send an SSE event to the guest VM. Signed-off-by: Clément Léger --- arch/riscv/include/asm/kvm_host.h | 7 ++++--- arch/riscv/include/uapi/asm/kvm.h | 1 + arch/riscv/kvm/vcpu.c | 23 +++++++++------------ arch/riscv/kvm/vcpu_exit.c | 33 +++++++++++++++++++++++++------ arch/riscv/kvm/vcpu_insn.c | 15 +++++--------- arch/riscv/kvm/vcpu_onereg.c | 2 ++ arch/riscv/kvm/vcpu_sbi.c | 4 +--- arch/riscv/kvm/vcpu_switch.S | 19 +++++++++++++++--- 8 files changed, 65 insertions(+), 39 deletions(-) diff --git a/arch/riscv/include/asm/kvm_host.h b/arch/riscv/include/asm/kvm_host.h index be60aaa07f57..1d699bf44c45 100644 --- a/arch/riscv/include/asm/kvm_host.h +++ b/arch/riscv/include/asm/kvm_host.h @@ -358,12 +358,13 @@ unsigned long kvm_riscv_vcpu_unpriv_read(struct kvm_vcpu *vcpu, bool read_insn, unsigned long guest_addr, struct kvm_cpu_trap *trap); -void kvm_riscv_vcpu_trap_redirect(struct kvm_vcpu *vcpu, - struct kvm_cpu_trap *trap); +int kvm_riscv_vcpu_trap_redirect(struct kvm_vcpu *vcpu, + struct kvm_cpu_trap *trap); int kvm_riscv_vcpu_exit(struct kvm_vcpu *vcpu, struct kvm_run *run, struct kvm_cpu_trap *trap); -void __kvm_riscv_switch_to(struct kvm_vcpu_arch *vcpu_arch); +void __kvm_riscv_switch_to(struct kvm_vcpu_arch *vcpu_arch, + struct kvm_cpu_trap *trap); void kvm_riscv_vcpu_setup_isa(struct kvm_vcpu *vcpu); unsigned long kvm_riscv_vcpu_num_regs(struct kvm_vcpu *vcpu); diff --git a/arch/riscv/include/uapi/asm/kvm.h b/arch/riscv/include/uapi/asm/kvm.h index fa3097da91c0..323f4e8380d2 100644 --- a/arch/riscv/include/uapi/asm/kvm.h +++ b/arch/riscv/include/uapi/asm/kvm.h @@ -166,6 +166,7 @@ enum KVM_RISCV_ISA_EXT_ID { KVM_RISCV_ISA_EXT_ZVFH, KVM_RISCV_ISA_EXT_ZVFHMIN, KVM_RISCV_ISA_EXT_ZFA, + KVM_RISCV_ISA_EXT_SSDBLTRP, KVM_RISCV_ISA_EXT_MAX, }; diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c index 461ef60d4eda..89e663defe14 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -121,6 +121,8 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu) /* Setup reset state of shadow SSTATUS and HSTATUS CSRs */ cntx = &vcpu->arch.guest_reset_context; cntx->sstatus = SR_SPP | SR_SPIE; + if (riscv_isa_extension_available(vcpu->arch.isa, SSDBLTRP)) + cntx->sstatus |= SR_SDT; cntx->hstatus = 0; cntx->hstatus |= HSTATUS_VTW; cntx->hstatus |= HSTATUS_SPVP; @@ -579,6 +581,9 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) csr->hvip = csr_read(CSR_HVIP); csr->vsatp = csr_read(CSR_VSATP); cfg->hedeleg = csr_read(CSR_HEDELEG); + cfg->henvcfg = csr_read(CSR_HENVCFG); + if (IS_ENABLED(CONFIG_32BIT)) + cfg->henvcfg = csr_read(CSR_HENVCFGH) << 32; } static void kvm_riscv_check_vcpu_requests(struct kvm_vcpu *vcpu) @@ -670,11 +675,12 @@ static __always_inline void kvm_riscv_vcpu_swap_in_host_state(struct kvm_vcpu *v * This must be noinstr as instrumentation may make use of RCU, and this is not * safe during the EQS. */ -static void noinstr kvm_riscv_vcpu_enter_exit(struct kvm_vcpu *vcpu) +static void noinstr kvm_riscv_vcpu_enter_exit(struct kvm_vcpu *vcpu, + struct kvm_cpu_trap *trap) { kvm_riscv_vcpu_swap_in_guest_state(vcpu); guest_state_enter_irqoff(); - __kvm_riscv_switch_to(&vcpu->arch); + __kvm_riscv_switch_to(&vcpu->arch, trap); vcpu->arch.last_exit_cpu = vcpu->cpu; guest_state_exit_irqoff(); kvm_riscv_vcpu_swap_in_host_state(vcpu); @@ -789,22 +795,11 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) guest_timing_enter_irqoff(); - kvm_riscv_vcpu_enter_exit(vcpu); + kvm_riscv_vcpu_enter_exit(vcpu, &trap); vcpu->mode = OUTSIDE_GUEST_MODE; vcpu->stat.exits++; - /* - * Save SCAUSE, STVAL, HTVAL, and HTINST because we might - * get an interrupt between __kvm_riscv_switch_to() and - * local_irq_enable() which can potentially change CSRs. - */ - trap.sepc = vcpu->arch.guest_context.sepc; - trap.scause = csr_read(CSR_SCAUSE); - trap.stval = csr_read(CSR_STVAL); - trap.htval = csr_read(CSR_HTVAL); - trap.htinst = csr_read(CSR_HTINST); - /* Syncup interrupts state with HW */ kvm_riscv_vcpu_sync_interrupts(vcpu); diff --git a/arch/riscv/kvm/vcpu_exit.c b/arch/riscv/kvm/vcpu_exit.c index 2415722c01b8..892c6df97eaf 100644 --- a/arch/riscv/kvm/vcpu_exit.c +++ b/arch/riscv/kvm/vcpu_exit.c @@ -126,17 +126,34 @@ unsigned long kvm_riscv_vcpu_unpriv_read(struct kvm_vcpu *vcpu, return val; } +static int kvm_riscv_double_trap(struct kvm_vcpu *vcpu, + struct kvm_cpu_trap *trap) +{ + pr_err("Guest double trap"); + /* TODO: Implement SSE support */ + + return -EOPNOTSUPP; +} + /** * kvm_riscv_vcpu_trap_redirect -- Redirect trap to Guest * * @vcpu: The VCPU pointer * @trap: Trap details */ -void kvm_riscv_vcpu_trap_redirect(struct kvm_vcpu *vcpu, - struct kvm_cpu_trap *trap) +int kvm_riscv_vcpu_trap_redirect(struct kvm_vcpu *vcpu, + struct kvm_cpu_trap *trap) { unsigned long vsstatus = csr_read(CSR_VSSTATUS); + if (riscv_isa_extension_available(vcpu->arch.isa, SSDBLTRP)) { + if (vsstatus & SR_SDT) + return kvm_riscv_double_trap(vcpu, trap); + + /* Set Double Trap bit to enable double trap detection */ + vsstatus |= SR_SDT; + } + /* Change Guest SSTATUS.SPP bit */ vsstatus &= ~SR_SPP; if (vcpu->arch.guest_context.sstatus & SR_SPP) @@ -163,6 +180,8 @@ void kvm_riscv_vcpu_trap_redirect(struct kvm_vcpu *vcpu, /* Set Guest privilege mode to supervisor */ vcpu->arch.guest_context.sstatus |= SR_SPP; + + return 1; } /* @@ -185,10 +204,8 @@ int kvm_riscv_vcpu_exit(struct kvm_vcpu *vcpu, struct kvm_run *run, case EXC_INST_ILLEGAL: case EXC_LOAD_MISALIGNED: case EXC_STORE_MISALIGNED: - if (vcpu->arch.guest_context.hstatus & HSTATUS_SPV) { - kvm_riscv_vcpu_trap_redirect(vcpu, trap); - ret = 1; - } + if (vcpu->arch.guest_context.hstatus & HSTATUS_SPV) + ret = kvm_riscv_vcpu_trap_redirect(vcpu, trap); break; case EXC_VIRTUAL_INST_FAULT: if (vcpu->arch.guest_context.hstatus & HSTATUS_SPV) @@ -204,6 +221,10 @@ int kvm_riscv_vcpu_exit(struct kvm_vcpu *vcpu, struct kvm_run *run, if (vcpu->arch.guest_context.hstatus & HSTATUS_SPV) ret = kvm_riscv_vcpu_sbi_ecall(vcpu, run); break; + case EXC_DOUBLE_TRAP: + if (vcpu->arch.guest_context.hstatus & HSTATUS_SPV) + ret = kvm_riscv_double_trap(vcpu, trap); + break; default: break; } diff --git a/arch/riscv/kvm/vcpu_insn.c b/arch/riscv/kvm/vcpu_insn.c index 7a6abed41bc1..050e811204f2 100644 --- a/arch/riscv/kvm/vcpu_insn.c +++ b/arch/riscv/kvm/vcpu_insn.c @@ -159,9 +159,8 @@ static int truly_illegal_insn(struct kvm_vcpu *vcpu, struct kvm_run *run, utrap.stval = insn; utrap.htval = 0; utrap.htinst = 0; - kvm_riscv_vcpu_trap_redirect(vcpu, &utrap); - return 1; + return kvm_riscv_vcpu_trap_redirect(vcpu, &utrap); } static int truly_virtual_insn(struct kvm_vcpu *vcpu, struct kvm_run *run, @@ -175,9 +174,8 @@ static int truly_virtual_insn(struct kvm_vcpu *vcpu, struct kvm_run *run, utrap.stval = insn; utrap.htval = 0; utrap.htinst = 0; - kvm_riscv_vcpu_trap_redirect(vcpu, &utrap); - return 1; + return kvm_riscv_vcpu_trap_redirect(vcpu, &utrap); } /** @@ -422,8 +420,7 @@ int kvm_riscv_vcpu_virtual_insn(struct kvm_vcpu *vcpu, struct kvm_run *run, &utrap); if (utrap.scause) { utrap.sepc = ct->sepc; - kvm_riscv_vcpu_trap_redirect(vcpu, &utrap); - return 1; + return kvm_riscv_vcpu_trap_redirect(vcpu, &utrap); } } if (INSN_IS_16BIT(insn)) @@ -478,8 +475,7 @@ int kvm_riscv_vcpu_mmio_load(struct kvm_vcpu *vcpu, struct kvm_run *run, if (utrap.scause) { /* Redirect trap if we failed to read instruction */ utrap.sepc = ct->sepc; - kvm_riscv_vcpu_trap_redirect(vcpu, &utrap); - return 1; + return kvm_riscv_vcpu_trap_redirect(vcpu, &utrap); } insn_len = INSN_LEN(insn); } @@ -604,8 +600,7 @@ int kvm_riscv_vcpu_mmio_store(struct kvm_vcpu *vcpu, struct kvm_run *run, if (utrap.scause) { /* Redirect trap if we failed to read instruction */ utrap.sepc = ct->sepc; - kvm_riscv_vcpu_trap_redirect(vcpu, &utrap); - return 1; + return kvm_riscv_vcpu_trap_redirect(vcpu, &utrap); } insn_len = INSN_LEN(insn); } diff --git a/arch/riscv/kvm/vcpu_onereg.c b/arch/riscv/kvm/vcpu_onereg.c index 5f7355e96008..fece0043871c 100644 --- a/arch/riscv/kvm/vcpu_onereg.c +++ b/arch/riscv/kvm/vcpu_onereg.c @@ -36,6 +36,7 @@ static const unsigned long kvm_isa_ext_arr[] = { /* Multi letter extensions (alphabetically sorted) */ KVM_ISA_EXT_ARR(SMSTATEEN), KVM_ISA_EXT_ARR(SSAIA), + KVM_ISA_EXT_ARR(SSDBLTRP), KVM_ISA_EXT_ARR(SSTC), KVM_ISA_EXT_ARR(SVINVAL), KVM_ISA_EXT_ARR(SVNAPOT), @@ -153,6 +154,7 @@ static bool kvm_riscv_vcpu_isa_disable_allowed(unsigned long ext) case KVM_RISCV_ISA_EXT_ZVKSED: case KVM_RISCV_ISA_EXT_ZVKSH: case KVM_RISCV_ISA_EXT_ZVKT: + case KVM_RISCV_ISA_EXT_SSDBLTRP: return false; /* Extensions which can be disabled using Smstateen */ case KVM_RISCV_ISA_EXT_SSAIA: diff --git a/arch/riscv/kvm/vcpu_sbi.c b/arch/riscv/kvm/vcpu_sbi.c index 76901f0f34b7..b839d578dc26 100644 --- a/arch/riscv/kvm/vcpu_sbi.c +++ b/arch/riscv/kvm/vcpu_sbi.c @@ -456,10 +456,8 @@ int kvm_riscv_vcpu_sbi_ecall(struct kvm_vcpu *vcpu, struct kvm_run *run) /* Handle special error cases i.e trap, exit or userspace forward */ if (sbi_ret.utrap->scause) { - /* No need to increment sepc or exit ioctl loop */ - ret = 1; sbi_ret.utrap->sepc = cp->sepc; - kvm_riscv_vcpu_trap_redirect(vcpu, sbi_ret.utrap); + ret = kvm_riscv_vcpu_trap_redirect(vcpu, sbi_ret.utrap); next_sepc = false; goto ecall_done; } diff --git a/arch/riscv/kvm/vcpu_switch.S b/arch/riscv/kvm/vcpu_switch.S index 0c26189aa01c..94d5eb9da788 100644 --- a/arch/riscv/kvm/vcpu_switch.S +++ b/arch/riscv/kvm/vcpu_switch.S @@ -154,7 +154,6 @@ SYM_FUNC_START(__kvm_riscv_switch_to) REG_L t2, (KVM_ARCH_HOST_SSCRATCH)(a0) REG_L t3, (KVM_ARCH_HOST_SCOUNTEREN)(a0) REG_L t4, (KVM_ARCH_HOST_HSTATUS)(a0) - REG_L t5, (KVM_ARCH_HOST_SSTATUS)(a0) /* Save Guest SEPC */ csrr t0, CSR_SEPC @@ -171,8 +170,8 @@ SYM_FUNC_START(__kvm_riscv_switch_to) /* Save Guest and Restore Host HSTATUS */ csrrw t4, CSR_HSTATUS, t4 - /* Save Guest and Restore Host SSTATUS */ - csrrw t5, CSR_SSTATUS, t5 + /* Save Guest SSTATUS */ + csrr t5, CSR_SSTATUS /* Store Guest CSR values */ REG_S t0, (KVM_ARCH_GUEST_SEPC)(a0) @@ -206,6 +205,20 @@ SYM_FUNC_START(__kvm_riscv_switch_to) REG_L s10, (KVM_ARCH_HOST_S10)(a0) REG_L s11, (KVM_ARCH_HOST_S11)(a0) + csrr t1, CSR_SCAUSE + csrr t2, CSR_STVAL + csrr t3, CSR_HTVAL + csrr t4, CSR_HTINST + REG_S t0, (KVM_ARCH_TRAP_SEPC)(a1) + REG_S t1, (KVM_ARCH_TRAP_SCAUSE)(a1) + REG_S t2, (KVM_ARCH_TRAP_STVAL)(a1) + REG_S t3, (KVM_ARCH_TRAP_HTVAL)(a1) + REG_S t4, (KVM_ARCH_TRAP_HTINST)(a1) + + /* Restore Host SSTATUS */ + REG_L t5, (KVM_ARCH_HOST_SSTATUS)(a0) + csrw CSR_SSTATUS, t5 + /* Return to C code */ ret SYM_FUNC_END(__kvm_riscv_switch_to)