Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2399357lqp; Sun, 24 Mar 2024 17:50:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU8LS9+w9NdJpkRPw3+PUvRLvElG6vU1tt7zqs7FaIUx99gWSEgR/VHmhGlImpCQSYIXDMt8Nw5p8kn4tcNQ6HG6LqQepmEsMXBB7CZlw== X-Google-Smtp-Source: AGHT+IGazN/uSqQrykbWz/nLV6/LcytJhpPRwhB2DJb2rzuh6HILlzJxZXuz4Q3WsYyH44HP9aZl X-Received: by 2002:a17:902:6808:b0:1dd:a3e2:de77 with SMTP id h8-20020a170902680800b001dda3e2de77mr5782654plk.20.1711327856097; Sun, 24 Mar 2024 17:50:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711327856; cv=pass; d=google.com; s=arc-20160816; b=Cm9fDTw3IXEBawkclUFIwqH+dACs4PzZYSzXW/OZQfWWbLyfLtCFpiDh7/jrER1AK5 7gs1TNqFx/iW070ilqJ76ZW5SfwjdTJ51ezql2cSqpa3HPXu7CDxh47sp7XCnmhKH9nc FQivEdpXO/aMxtTE6tbf4SsNL34i+sNQ2ayqEXrR1vOk7w8XllV79hZARs3V8C2DQR9O Ey8bZIDqzaIK08VXy3m5/ePDIlmQIfKau3buUFLdKNiI0AmMPCcvJrTPgY+lxTR6S5a5 Vj+CJRPm3oHRWMbj+sGUdMUv1e5x0B4Ow1xfOskJIvBhWV7VKZbFJ/7tBg7wQcUgvMIM 2AVA== 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=57GChJYLu7jBBHKmDZO5Zri5PLhx09k6Saod+BtoAXw=; fh=BFe/SD/VaxNZVkj/xtqG/zIhaqC7hT+j3pFgGgZyIow=; b=idvRio+qvHvDurFPfg2etgg/S8MfUBEZTaYkwhDAytMiSlsfPgjh1z3d/f3p62pWxm Ar7RcM6l4nyrxDdThIp4AsMMaBlxl9ByqN4lBYc9d0XbWaTK6kk/rd4cW5oYt0VPNWbQ XXLqt4OYv5NzV5g1RA4GUZh7e997qm8izkqC40FY+kBRwuH8PrQV8WdUAyiXtl8Y3qXL suFNLqNeGvi3lXcbUcc3hMtPxB8uFqtUIE4mcFS5rj5V+mdwWopMRfGxRiDEuWmraY9n CW2XswBnhSmvWUqTG4jwFiyp6irwKQdYOxsJ4FqbtlXILCaZKY+XYbAC3hj4N5t+QcCU lw6g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NcLhzsZD; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113410-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113410-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id y7-20020a17090322c700b001e01f24fcb1si2060756plg.173.2024.03.24.17.50.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 17:50:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113410-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NcLhzsZD; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113410-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113410-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 119D2287AFF for ; Mon, 25 Mar 2024 00:29:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 313FB1A6993; Sun, 24 Mar 2024 22:43:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NcLhzsZD" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C5241A62FA; Sun, 24 Mar 2024 22:43:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320212; cv=none; b=PoeHHw0nuucYVoq2oYHsBB0evwbdsXkFRAJiopUG0c6TSc0boPttZNoQm1e605kJ61JAYxXq7WGm/Ajl4XzlnqbEAb+fT8a9TbGCwLY72DYbNsFNjNoiLKwtrUtxoldujw24Syzmx/R+B7kzHn5MLbY4v8d5casU4lXCTpjtAxQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320212; c=relaxed/simple; bh=4FUPlWa79cawkkNKxG7WUAwRAA85F1SBpHi+Rf23veo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U2jlxa7YtzY/39kqvr4jlNmRX9kUCYeDaZ8wV0r1LMpcFDROlIkbSmb8SHSPzfixjFAwhowpJDeozrZBnPhbksLsehbfuNJju1vgBDbea9k2Dbgf6XfeohpmpYy4UFRbh1qYURXkqATb/3vCnro50aJqI0oXQmJ5d1QAvRDdUvQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NcLhzsZD; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 72154C43601; Sun, 24 Mar 2024 22:43:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320212; bh=4FUPlWa79cawkkNKxG7WUAwRAA85F1SBpHi+Rf23veo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NcLhzsZDOeK9Rp2MAlxJKWKOa4bfRReWrHl5sggmMZk7GHM3stmsAHb49TbddyqBC bwG1biw5wbVH3EriPBH9zCtgJ2gQSNP6nKiFMWF4tox0Bj4IQwd8/wuP/41QRpBA7a xuX9v5+SVTPERlpwBZky7sZSmM/NwHZx9iEGuqsaewO6hXEZ/W0/L9GlEgrBFisCVq Z1oVjN+tSz3mcWbtijAmX73ioG6cdH9fLtSh9wu8CkwHS2G+iPnRZ+Euc56Cnxs/My 58GgaqZyxeCwh5BB08FANDVujr+7h3DjGpCV6rltV5uobIPj9ZxWFGjuDwNRiHjQqu Bpo4Xap9c89qw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Anup Patel , Andrew Jones , Anup Patel , Sasha Levin Subject: [PATCH 6.8 519/715] RISC-V: KVM: Forward SEED CSR access to user space Date: Sun, 24 Mar 2024 18:31:38 -0400 Message-ID: <20240324223455.1342824-520-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Anup Patel [ Upstream commit d808f0b1be4888a87524164bc7dad2242734de38 ] The SEED CSR access from VS/VU mode (guest) will always trap to HS-mode (KVM) when Zkr extension is available to the Guest/VM. Forward this CSR access to KVM user space so that it can be emulated based on the method chosen by VMM. Fixes: f370b4e668f0 ("RISC-V: KVM: Allow scalar crypto extensions for Guest/VM") Signed-off-by: Anup Patel Reviewed-by: Andrew Jones Signed-off-by: Anup Patel Signed-off-by: Sasha Levin --- arch/riscv/kvm/vcpu_insn.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/arch/riscv/kvm/vcpu_insn.c b/arch/riscv/kvm/vcpu_insn.c index 7a6abed41bc17..ee7215f4071f5 100644 --- a/arch/riscv/kvm/vcpu_insn.c +++ b/arch/riscv/kvm/vcpu_insn.c @@ -7,6 +7,8 @@ #include #include +#include + #define INSN_OPCODE_MASK 0x007c #define INSN_OPCODE_SHIFT 2 #define INSN_OPCODE_SYSTEM 28 @@ -213,9 +215,20 @@ struct csr_func { unsigned long wr_mask); }; +static int seed_csr_rmw(struct kvm_vcpu *vcpu, unsigned int csr_num, + unsigned long *val, unsigned long new_val, + unsigned long wr_mask) +{ + if (!riscv_isa_extension_available(vcpu->arch.isa, ZKR)) + return KVM_INSN_ILLEGAL_TRAP; + + return KVM_INSN_EXIT_TO_USER_SPACE; +} + static const struct csr_func csr_funcs[] = { KVM_RISCV_VCPU_AIA_CSR_FUNCS KVM_RISCV_VCPU_HPMCOUNTER_CSR_FUNCS + { .base = CSR_SEED, .count = 1, .func = seed_csr_rmw }, }; /** -- 2.43.0