From patchwork Wed Jul 26 08:43:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mayuresh Chitale X-Patchwork-Id: 13327627 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 C7A8CC001DC for ; Wed, 26 Jul 2023 08:44:14 +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: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:In-Reply-To:References: List-Owner; bh=htZWyALG+FugiGo2zufZN1iLVJBu4I/IVmAgitb77K4=; b=NIbD99dIOvrJ1J oBkBsT5xmGuozBWgyYpu6MmjQVWuS0tneIct3veEdQrA4dSglBZf1o6GDDzSL41mbdHDxu9S1xMIP MwNHVoTnqur+iso64WUKFe6ZhtRds+Q6TwnRZ9QRJFy5UR6XNYI2212ie0QFQpBYvNsoc0s9f1Lop fqYAwc1f3VlcpmthrDq1mMA71PprMefc7lNdP3CdBP4H/PcWakZ9kpQjM8GSbvsmtpxkGsfivAH9N 89Ans9FJoQyU9TPCulMus/Bmxpwm1kDTiBptzLle6zTxbmrecqLhxK8VPf+NZ2tZVPnSmVQid53Tj WwTd5x/h7d4Keo+ecyHw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qOa7s-009c3R-2N; Wed, 26 Jul 2023 08:44:08 +0000 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qOa7q-009c1x-0a for linux-riscv@lists.infradead.org; Wed, 26 Jul 2023 08:44:07 +0000 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1b9c368f4b5so4923595ad.0 for ; Wed, 26 Jul 2023 01:44:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1690361043; x=1690965843; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=DQc80XoWnWN+d0bN0a57A7yXCEucxsJNa3airtwPdzU=; b=Hp2YtMOJInODfh2RWJnZcs3r3BCbH0ObrksVLi76QalIoUjE9Ky2QLTWtluMnS07Lm cy9jHRYtAxMVi2aj59ILj+OQVqCHVarW2HTPIjg7wVuwjWsM1ZXLehF+9UE3DnnU14cf iWQGUhyt6+I233gVjENypM7bBVS2xSSuB+r3FVOII6Pmjz1S/wZvaI6WOlbGJa3dJQII fLy/j+uS8jAPTgadIJHcyPFNtU4zMhNFR7lZfUq0Rt8KlRZE1pAwPkQGoK2ds0kPUlAH PJ9oGK/kV1RKnchodGEDyymE5qjRJmfvgdBssBj3x8thUq48AM3BV2zuX2DUtRlSQmHG Zj/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690361043; x=1690965843; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=DQc80XoWnWN+d0bN0a57A7yXCEucxsJNa3airtwPdzU=; b=jOD7ZmZyQffFibVNMTT5GAM0mUOyIUOhjgjC1Ej7YmLX4U8q+PlzIpNl8eBbLRlTed OxH44+Zv8Kd/sof0TYwAaxkmKa5lgGKm7egXntLguToK1RPalVDDhNxXxSIAzJqap8pI oo9+/g+rjx7IusYRwhmUS/UFOGzlLuij/WyYH7k4i68Oov+Eynu5a5wf5YxFmmJgGYKc mh65oYS/y+/quYbYaJgw+46yfSPVf+qZMLNejnvqkB7SF0T2WcXBIt9dS4m+IEyvJ5lw 2qH9LEFjbLTGm+S/JO+sL83Pu7vMgNfpSF8w7fETUN1VVKb6v32qy2K+GGEfnFT89ZxN 9KIA== X-Gm-Message-State: ABy/qLYJfXo1CdQxWGUWOMa5MVr1Fa9yARplo3l6TGinrG5O5C+d/eKN eiDCqyAVaopHquQ9cFzFsbN4jg== X-Google-Smtp-Source: APBJJlExZpncboZpnmSU/bDA6WhjsS+diGAbylKBltrvAwOAn+i5mgN5Gq5g82Zb6GypEbpgJ4Kldw== X-Received: by 2002:a17:902:b18f:b0:1b8:ad90:7af8 with SMTP id s15-20020a170902b18f00b001b8ad907af8mr1606145plr.17.1690361042634; Wed, 26 Jul 2023 01:44:02 -0700 (PDT) Received: from mchitale-vm.. ([103.97.165.210]) by smtp.googlemail.com with ESMTPSA id y19-20020a170902ed5300b001b3bf8001a9sm3978637plb.48.2023.07.26.01.43.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 01:44:02 -0700 (PDT) From: Mayuresh Chitale To: Palmer Dabbelt , Anup Patel Cc: Mayuresh Chitale , Andrew Jones , Atish Patra , Paul Walmsley , Albert Ou , linux-riscv@lists.infradead.org, kvm-riscv@lists.infradead.org, Conor Dooley , Krzysztof Kozlowski , Rob Herring , devicetree@vger.kernel.org Subject: [PATCH v4 0/7] Risc-V Kvm Smstateen Date: Wed, 26 Jul 2023 14:13:45 +0530 Message-Id: <20230726084352.2136377-1-mchitale@ventanamicro.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230726_014406_224284_EDFEC8A8 X-CRM114-Status: GOOD ( 12.21 ) 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 This series adds support to detect the Smstateen extension for both, the host and the guest vcpu. It also adds senvcfg and sstateen0 to the ONE_REG interface and the vcpu context save/restore. The motivation behind Smstateen from the spec (https://github.com/riscv/riscv-state-enable): "The implementation of optional RISC-V extensions has the potential to open covert channels between separate user threads, or between separate guest OSes running under a hypervisor. The problem occurs when an extension adds processor state---usually explicit registers, but possibly other forms of state---that the main OS or hypervisor is unaware of (and hence won’t context-switch) but that can be modified/written by one user thread or guest OS and perceived/ examined/read by another." Changes in v4: - Update commit description for patch 1 - Rebase to kvm_riscv_queue - Add reviewed-by tag Changes in v3: - Move DT bindings change to a separate patch - Move senvcfg/sstateen0 save/restore to separate function Changes in v2: - Add smstaeen description in riscv/extensions.yaml - Avoid line wrap at 80 chars Mayuresh Chitale (7): RISC-V: Detect Smstateen extension dt-bindings: riscv: Add smstateen entry RISC-V: KVM: Add kvm_vcpu_config RISC-V: KVM: Enable Smstateen accesses RISCV: KVM: Add senvcfg context save/restore RISCV: KVM: Add sstateen0 context save/restore RISCV: KVM: Add sstateen0 to ONE_REG .../devicetree/bindings/riscv/extensions.yaml | 6 ++ arch/riscv/include/asm/csr.h | 18 +++++ arch/riscv/include/asm/hwcap.h | 1 + arch/riscv/include/asm/kvm_host.h | 18 +++++ arch/riscv/include/uapi/asm/kvm.h | 11 +++ arch/riscv/kernel/cpu.c | 1 + arch/riscv/kernel/cpufeature.c | 1 + arch/riscv/kvm/vcpu.c | 70 +++++++++++++++---- arch/riscv/kvm/vcpu_onereg.c | 41 +++++++++++ 9 files changed, 154 insertions(+), 13 deletions(-)