From patchwork Mon Jan 6 15:48:43 2025 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: 13927611 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 971A1E7719C for ; Mon, 6 Jan 2025 15:51:09 +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=9RVcV40vrFzxtIiHT1XFtMoBs4uTgaTa8AfLGk0EiYY=; b=GoMcnvA5UHUo8q Jgqiygncdw+Uug6GhMPFiMMCxDq14+Lpl1+wy4C1hH/Jb9V3U49As574AJRwC32JOGbnxYGW3WMdL BnrC3smJxHUbFkOEUNetmkkItl4lZ8KfJMF9ocZzODsmO3zwCORKsiOYs4C2/KdA1gjjJd0uxQh0m FPfDji7jfAYounMTvWOnAaiSqol3iMNERkaNWETHaq2UKYkF85Wko9WHOVd5EHSWA8EJekGtLCmU5 8KonCiS9VnDxSvUBEqrOi+SrtjMW7Py+cCXFvbskuRWTbpi0YEGFfm8VwjFUwpBbDsjeJnu16+on6 CR7WUb0JjobF8hBmFwww==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tUpNh-00000001qcX-1QIE; Mon, 06 Jan 2025 15:51:05 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tUpMO-00000001qAr-2VBL for linux-riscv@lists.infradead.org; Mon, 06 Jan 2025 15:49:45 +0000 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-21670dce0a7so27181885ad.1 for ; Mon, 06 Jan 2025 07:49:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1736178584; x=1736783384; 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=pZted/4cRJuHwsNYAobqssxEi0f1evq9XJsjrZaPJkE=; b=qE09TAerULb2Uj/U+3abDvmMdeiN+gxMokDgR22KtWwj3jLhHSLBSq7JKPE0BEtnYC tdkGdH98Y4xiDBnss4ZQYZSukZYYq5Do3pDghRwn14Hh9afUc5t4Z1a/JENzhTo4z7Bc RA2gd1+xP7uA3w7WAaxyiYfG9cGzOpJjhuJmsFEMTtRcpKD8X7BtaMwsmuO6jh7xO+Ub 13tWwMhthoCkjytNsYMU4WlBkmwkxqdekHtq0KC6u3zoitfmkMPKh9ooqMhVOHhOKF+Q Y6huWmVLLKIxYZaS+Y2lqZjWPlrp6qFGJOqoGXchUBrtiB7Qb2ICPg6k6JkpOFq536K7 1BIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736178584; x=1736783384; 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=pZted/4cRJuHwsNYAobqssxEi0f1evq9XJsjrZaPJkE=; b=fDtGyYw72IeylboMRgSisLDeznjGYwOwpN3Np87qS3P/bVcIe/HeXiyNqqOt9c5Ni4 AaKQb4stRmeHylTsbjb29nMIEzB4PPvnWohVTWnmlaS4Z05DnK7ifyGwS2vO/eOGN9zA fAU8WN3DYWuM6c8eypg0/H4CFb9fjvZ+XGPMCdsrUtOFxIJkotns86e7llRpAK4V+PWB JwB9OZh5QRAPDa2ACtM/ILxALhPEtc9MdvYAIYwbhlpIKA+jlj9vor8VyYZ2Nk8/nuas 7f8Qxe88/6ApurN2ASBJ/xem1DfwE1OinT6EPthQtlb4tRag0s3AB9qUHI9XLqny58sj /ukg== X-Forwarded-Encrypted: i=1; AJvYcCWJlrvPUCQ1LnNX9Jv9jd3Etw4jehqxUMGsIBv2ECeQgbnA6zM7iBbgpKsuhuEV2yuwouD2TXzb6MDhaQ==@lists.infradead.org X-Gm-Message-State: AOJu0YzPodPuO5Xuziq8QFdBsWRxS5WbaSsuAaQ40T33oLO8EScMRjg7 FsolPw2n3yeNAxMNhsVmjKLesufKt9V5erI22+VkcC270jnlTloOdXzf2Tio5V6owWwfEAGNw3k v X-Gm-Gg: ASbGncv5hLyR0o2KZtdHIjs19lwSpPUu3hjQ0ALOXo5fDHqqO7iHgRNV5eeh3RtYmYo W0t0NyIT9YAYp3yvrhPle3Tu4JvrrGIM+tOO4IysNA1ywevepSUvr8YbK/7aoqta3oMafwf/ZlI QS4jVY2wgNv/kjoxCwxZDxoivOE7tpELk929ebE4WGB94QFdI7wWqyOdaqREr0I8txZJQpQIR1w DEAT7ZHXxhJNwTr4fL5cGWKM67roEdROyBB/tot4uGlM2E7rdE5V3kNaw== X-Google-Smtp-Source: AGHT+IEOmk52vJbM/lir6EnXzGo8rHZx0c8SdsX59VoQTeStIErxbb+u7Tg8JzB4+OJAm4+54IkSXg== X-Received: by 2002:a17:902:e886:b0:216:5e6e:68cb with SMTP id d9443c01a7336-219e6e9fd95mr868563935ad.16.1736178584085; Mon, 06 Jan 2025 07:49:44 -0800 (PST) Received: from carbon-x1.. ([2a01:e0a:e17:9700:16d2:7456:6634:9626]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc9f6967sm292479535ad.214.2025.01.06.07.49.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2025 07:49:43 -0800 (PST) From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Paul Walmsley , Palmer Dabbelt , Anup Patel , Atish Patra , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Cc: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= Subject: [PATCH 6/6] RISC-V: KVM: add support for SBI_FWFT_MISALIGNED_DELEG Date: Mon, 6 Jan 2025 16:48:43 +0100 Message-ID: <20250106154847.1100344-7-cleger@rivosinc.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250106154847.1100344-1-cleger@rivosinc.com> References: <20250106154847.1100344-1-cleger@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250106_074944_640732_E9F919E4 X-CRM114-Status: GOOD ( 12.80 ) 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 SBI_FWFT_MISALIGNED_DELEG needs hedeleg to be modified to delegate misaligned load/store exceptions. Save and restore it during CPU load/put. Signed-off-by: Clément Léger --- arch/riscv/kvm/vcpu.c | 3 +++ arch/riscv/kvm/vcpu_sbi_fwft.c | 39 ++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c index 3420a4a62c94..bb6f788d46f5 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -641,6 +641,7 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) { void *nsh; struct kvm_vcpu_csr *csr = &vcpu->arch.guest_csr; + struct kvm_vcpu_config *cfg = &vcpu->arch.cfg; vcpu->cpu = -1; @@ -666,6 +667,7 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) csr->vstval = nacl_csr_read(nsh, CSR_VSTVAL); csr->hvip = nacl_csr_read(nsh, CSR_HVIP); csr->vsatp = nacl_csr_read(nsh, CSR_VSATP); + cfg->hedeleg = nacl_csr_read(nsh, CSR_HEDELEG); } else { csr->vsstatus = csr_read(CSR_VSSTATUS); csr->vsie = csr_read(CSR_VSIE); @@ -676,6 +678,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); } } diff --git a/arch/riscv/kvm/vcpu_sbi_fwft.c b/arch/riscv/kvm/vcpu_sbi_fwft.c index 55433e805baa..1e85ff6666af 100644 --- a/arch/riscv/kvm/vcpu_sbi_fwft.c +++ b/arch/riscv/kvm/vcpu_sbi_fwft.c @@ -14,6 +14,8 @@ #include #include +#define MIS_DELEG (1UL << EXC_LOAD_MISALIGNED | 1UL << EXC_STORE_MISALIGNED) + static const enum sbi_fwft_feature_t kvm_fwft_defined_features[] = { SBI_FWFT_MISALIGNED_EXC_DELEG, SBI_FWFT_LANDING_PAD, @@ -35,7 +37,44 @@ static bool kvm_fwft_is_defined_feature(enum sbi_fwft_feature_t feature) return false; } +static bool kvm_sbi_fwft_misaligned_delegation_supported(struct kvm_vcpu *vcpu) +{ + if (!unaligned_ctl_available()) + return false; + + return true; +} + +static int kvm_sbi_fwft_set_misaligned_delegation(struct kvm_vcpu *vcpu, + struct kvm_sbi_fwft_config *conf, + unsigned long value) +{ + if (value == 1) + csr_set(CSR_HEDELEG, MIS_DELEG); + else if (value == 0) + csr_clear(CSR_HEDELEG, MIS_DELEG); + else + return SBI_ERR_INVALID_PARAM; + + 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 const struct kvm_sbi_fwft_feature features[] = { + { + .id = SBI_FWFT_MISALIGNED_EXC_DELEG, + .supported = kvm_sbi_fwft_misaligned_delegation_supported, + .set = kvm_sbi_fwft_set_misaligned_delegation, + .get = kvm_sbi_fwft_get_misaligned_delegation, + } }; static struct kvm_sbi_fwft_config *