Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp38903lqt; Thu, 18 Apr 2024 07:56:54 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWN6NJdiHvOGz8skCbVtDNzt/Iqmw/ZmPygFxrqIk8zPPR4D8hu3dBZaIcqqBguIwTF813HBmOBYD8H+WHlutJDSSKXf69HTehL48XXwA== X-Google-Smtp-Source: AGHT+IG6GAiYoE5wsya+shbyxWztLIfVmxHZvlGINwca8sZ5WzPnHrIx6CihCQQVLKwRoQLLYMDc X-Received: by 2002:a05:6a21:3e01:b0:1a7:9adc:86e4 with SMTP id bk1-20020a056a213e0100b001a79adc86e4mr3461094pzc.23.1713452214127; Thu, 18 Apr 2024 07:56:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713452214; cv=pass; d=google.com; s=arc-20160816; b=v259Zy5O6ZoElCB3UoSeASRv1bVg7sTIilN28RIcyt2X7kb5180xl0zTpb1SD3ORUI Dgo1JwOjnAYMAzYy1alXjllqZfIVe4YrALHCv+xcOD4nZBOB71HIZDAOpTtWT4r7BFPo fJ2rtN4pZ1CGhayRS7Z06evNLui5DdWTrXejG/GnosFSlVhLz5yjEwOGkS4udebN3QCe u3FPnqQIfSOBMmgEnq9l5CdogYt+LIofgcvY38XzGMLe/MVLkfmzAMAUdXuBC+ev+grA B1U6mjkJGxPw45zwhh5kJgNaGH7cqy3YKifs0lwuGqppcjqvmu3WdafZcRJQJqeFvmCk dNJg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=JY0qCZAt1G9FqrirGdQPEL//dx+I/VeYeDHijBAzwaE=; fh=A+jwM+WDDAa3R6x9zvSkj947w/GavU6scVmeadPapOE=; b=IIpKEgc9YU363hT9KXdD+0B60M8A3047VmFzZshdgdd9PZCnGx5ldWQOt1UWrG5Iwz iyV5AyWIosjpfck1OIQnGL0AknKRPA2iyDerTA7ZZ/vYt0e5gq9yi5H+wUaW2m8rtiWn Ecg94VwrC/3M/PY5GalkpqsywRr1VA7Rp3OcZkF5FEiXOdNyy4voVbCRXV4x8ZBAJQJf 74+59iOrV1u/z5qjZ5X9h1S3keHr0A9ERaV1q5bnaZBOxIHupCagS07m/1rrh2Iho7bR bXHzmWL3fpU6kKMNElZQ38QKpqKk8iCo4W7/H8tA0NpoawsuyztOhPHEreWbjjDtfGmW tq9w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=Fs099w3h; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-150307-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150307-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id j19-20020aa78dd3000000b006ecef03a767si1572676pfr.340.2024.04.18.07.56.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 07:56:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-150307-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=Fs099w3h; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-150307-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150307-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id CC1D3B290D1 for ; Thu, 18 Apr 2024 14:30:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 331BE16DEA1; Thu, 18 Apr 2024 14:27:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="Fs099w3h" Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0A8716D327 for ; Thu, 18 Apr 2024 14:27:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713450440; cv=none; b=lATOUfMSAGY2ZJwYnAgHlpJyHHFJNSO/Jj1LqN3fODC8+o42fVGZC2+foO50xre+MlbYBrvNd5NavpsEBgYJnJh9KuTkJGODCHgOwFGU4SVYPHS0dvCFWo1VdPhvKcFMNP+4icUvZZLQCuGZXwbGXZWK8zDDcKA7LE58N2umigo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713450440; c=relaxed/simple; bh=jmGcUvmOSHSqYkb7pBNAS2mVaUm49bDaV7hi2clFia8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JwN2wK1+MqxxktK9FRJIlhX9wkm/e7IX1nbSYxKMQBaU7+S5RfsryBVB/UcS/D9uX/UiCF72npXuSyAi3lEf7txI+rnmB30XXAXtSyW9z+fXYr119YgxoTg690vxlSr65487tGTWQXgwDfSqswx0UxkLXUk2XpLa4lBEQpT9S/o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=Fs099w3h; arc=none smtp.client-ip=209.85.221.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-343d32aba7eso184361f8f.1 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=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JY0qCZAt1G9FqrirGdQPEL//dx+I/VeYeDHijBAzwaE=; b=Fs099w3h93nPvR3q4Es8mQTeBlSfS0ZYVwXvg/GhnZAHhG7AXcN5/wSMg2tPkBt0HC CS67fAz7UZqoacW0cObF50fg90PGctvfo0qS++lxwMcS1gxO0zVeoxwM2LTHycZGZ+Xi c+LFQ8BPxqmVq2ni0o9n9LAaBCYfaZPJIxcxtB0/NvG1ACNJXFvOram8W1ipJt9KP4y+ 3ikC8bKZ4IwFwWOoYU9AacRsVERuIMTknM2VTunFRCoEL+NKLM/qMvtyBnd4xBWCC8Px 1QFcTdUgccCwyvPJrXiz5+j7YkGBz3bjKQjG7e0QR8McVQWhATAb+QUj2bNY3ST8bfUj P8RQ== 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=AwxjH+6iMihhIOxbtUnN94dnaMqql4aA44PwlFXFQxYKqvIvkvuMgHCg6/VpO5Zwem PhJOHBLNSaHo6JD3ZYiyF5l0q2eSFE5uH0PUK7eQOqY2+jWJ5MXu8F4gbPNI5Uj2f1EZ Tooi25ydzelagz2E6lsDJ0zymOjNfiNeLAL6xLjEn8o4o+dSWcQeZ9VgQJLeEV8Oc6FX ZHhpILrwrJGXTwoks4zn8UmzUUOq9xvEcwnWBoIoPk+GxLM7Ps3ibhOn54G7DFj8zqCs ADF8gXyNOOp9HpyL3WmRcOd6oxe5Z5HXcUasMPJ/KskcjR8tuTgRClRaC01U+psMzu5e TX6g== X-Forwarded-Encrypted: i=1; AJvYcCVf5D0uM5Mc7hA73OAePdnIgztc7DZlMRBXbBCKC6Y1LdoAFG28A4WSF828q65xzbrwgOhiICcG8S8eD+yucP2mcy2D4DTyVkH4YU9w X-Gm-Message-State: AOJu0YyQSQTRm0INt+MDqgcdCqYhp2e1Pq2EsvWXbdFBNrrJAGmS4zg6 ivEW0cYGh7Q2dBE0wlXWOlTUCBFY6gPMm+1ocv3NL2nlMk1iyEzn2OqK+/sv5qI= 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?q?Cl=C3=A9ment=20L=C3=A9ger?= To: Conor Dooley , Rob Herring , Krzysztof Kozlowski , Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Atish Patra Cc: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= , 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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, } }; -- 2.43.0