From patchwork Fri Mar 4 20:10:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 1601427 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=hLW0ouwr; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=rivosinc-com.20210112.gappssmtp.com header.i=@rivosinc-com.20210112.gappssmtp.com header.a=rsa-sha256 header.s=20210112 header.b=gWSOzgXN; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4K9JrP6Mxhz9sFt for ; Sat, 5 Mar 2022 07:10:45 +1100 (AEDT) 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=NNGfZisRqxrU/0NRm3WkruSFmIIHr74RY0GEEAiidmo=; b=hLW0ouwrttJvrl GZKPSAphXnJYAtcHKoYM/efUBmXqo6tYG4MG5Gc78nZxrhKgOSklxYBGsU1eQ83rCN04YQ60VRnYy gvGpLP5DxcK8dDcQQqE/OLZznUYUNcw3/XwmUZc9HPUiByALJhtkd7Vde6c7aVWxFZ7r/QElZyYBR Xf5RvyLOFFjC6cOos+uiypqhD9PF7VC6e896fF9rtNFw3kV1WUnW+0sKKCxPOv5WGZ9arEX4ZDbT4 de/l0dyYvujvND21X4W6dXN1ZWA7PYjBLZ1U2ptvteT7W2fJxDd0Ic9AYtE98BzkR6/QiJw88vOsd v/o7JvSX9qecIB1cfNbA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nQEGB-00Bt8R-DC; Fri, 04 Mar 2022 20:10:43 +0000 Received: from mail-qt1-x835.google.com ([2607:f8b0:4864:20::835]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nQEG7-00Bt6i-IO for kvm-riscv@lists.infradead.org; Fri, 04 Mar 2022 20:10:41 +0000 Received: by mail-qt1-x835.google.com with SMTP id n11so8360759qtk.8 for ; Fri, 04 Mar 2022 12:10:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=c3hwhrGILXdhz/XeWc3KW5uuxAFbMTxchWciY7LftwM=; b=gWSOzgXN0en0k+yoq+gp40hIQ0jSbo3zMvH3uDi3oO6KZwtgAzpOILlFXgVqme9ZQe QL3YG2VE/6OjVosmCdiTn+JwxyrijZr0T7iam6gOGSXhvyljatoF9/m4/mCf0/oW5EY8 BgDtLZTQYDyLXoBJzGDoEBc47P5Qytf0LNtobMd+TVur6an2OoC899T5IGQYae6dupq5 hlGs3iz76pUFYOrI5x2MLuKu1g7fe1bc7sZrJckIiAV4QeBEYYhiMirYgU00wffDYnKV 0UbdZaOomJYY6WQ7i7RdG6OraQxQ8soBBvKsgseUzObhZdsLPcG0e6DWNPh2AAxdB6qm VsWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=c3hwhrGILXdhz/XeWc3KW5uuxAFbMTxchWciY7LftwM=; b=U9zMgapq7VSKELa5czYD3J1q7YRrljmLKjjizUZbSiVMppOstnhDLmPhhM6qTCWqlN NGT34LjT2dTg7skvhUo6zrw93DZ2of8I9Sm27RHt3051MSsi888zWggts4MiLHPlSlFZ NjN9jix+GeimMpSzOntxf/oJr02afrKrWclR9cJeYSTT9uA3rjkas6D/nc0xt+RxeEFv RtqWQZqjWtcxDCHkL92rWQhS57xh+e710hxacBn91Kdhkwo8o24R4V6gWOfiS6kEXyGb afvXS0LDcFQ/TSFPr+7Qz1cFTreoD423Hb0dG63FkMbnhk1yy4444MuZ5TlQjZoXN/0o 1MWw== X-Gm-Message-State: AOAM532ahJPJmEYiAxe9Y0OySfDXn3vS811gBfPP1ht5bIopHGp0a/hk dW6dQF9LTdcedkenjFIy0TGMtw== X-Google-Smtp-Source: ABdhPJy7TOhFoNFD4vGDLADKFrKXnucp+teoiBHQIPQ3w172uA42MtTQNHkgRMmFcWN/TpxO2Qz/Qg== X-Received: by 2002:a05:622a:548:b0:2e0:4a6f:7c7e with SMTP id m8-20020a05622a054800b002e04a6f7c7emr375590qtx.303.1646424637904; Fri, 04 Mar 2022 12:10:37 -0800 (PST) Received: from rivos-atish.. (adsl-70-228-75-190.dsl.akrnoh.ameritech.net. [70.228.75.190]) by smtp.gmail.com with ESMTPSA id 20-20020ac84e94000000b002de8f564305sm4605481qtp.1.2022.03.04.12.10.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 12:10:37 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Atish Patra , Anup Patel , Damien Le Moal , devicetree@vger.kernel.org, Jisheng Zhang , Krzysztof Kozlowski , kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, Palmer Dabbelt , Paul Walmsley , Rob Herring Subject: [RFC PATCH v2 0/7] Add Sstc extension support Date: Fri, 4 Mar 2022 12:10:13 -0800 Message-Id: <20220304201020.810380-1-atishp@rivosinc.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220304_121039_622084_DD21F5AA X-CRM114-Status: GOOD ( 13.82 ) X-Spam-Score: 0.0 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: This series implements Sstc extension support which was ratified recently. Before the Sstc extension, an SBI call is necessary to generate timer interrupts as only M-mode have access to the timecompar [...] Content analysis details: (0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:835 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: kvm-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: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This series implements Sstc extension support which was ratified recently. Before the Sstc extension, an SBI call is necessary to generate timer interrupts as only M-mode have access to the timecompare registers. Thus, there is significant latency to generate timer interrupts at kernel. For virtualized enviornments, its even worse as the KVM handles the SBI call and uses a software timer to emulate the timecomapre register. Sstc extension solves both these problems by defining a stimecmp/vstimecmp at supervisor (host/guest) level. It allows kernel to program a timer and recieve interrupt without supervisor execution enviornment (M-mode/HS mode) intervention. To maintain backward compatibility, KVM directly updates the vstimecmp if older kernel without sstc support is running in guest. Similary, the M-mode firmware(OpenSBI) uses stimecmp for older kernel without sstc support. The PATCH 1 & 2 enables the basic infrastructure around Sstc extension while PATCH 3 lets kernel use the Sstc extension if it is available in hardware. PATCH 4 & 5 adds the infrastructure for KVM to use sstc while PATCH 6 actually uses the Sstc extension if available. This series has been tested on Qemu(RV32 & RV64) with additional patches in OpenSBI[2] and Qemu[3]. This series can also be found at [4]. Changes from v1->v2: 1. Separate the static key from kvm usage 2. Makde the sstc specific static key local to the driver/clocksource 3. Moved the vstimecmp update code to the vcpu_timer 4. Used function pointers instead of static key to invoke vstimecmp vs hrtimer at the run time. This will help in future for migration of vms from/to sstc enabled hardware to non-sstc enabled hardware. 5. Unified the vstimer & timer to 1 timer as only one of them will be used at runtime. [1] https://drive.google.com/file/d/1m84Re2yK8m_vbW7TspvevCDR82MOBaSX/view [2] https://github.com/atishp04/opensbi/tree/sstc_v1 [3] https://github.com/atishp04/qemu/tree/sstc_v1 [3] https://github.com/atishp04/linux/tree/sstc_v2 Atish Patra (7): RISC-V: Add SSTC extension CSR details RISC-V: Enable sstc extension parsing from DT RISC-V: Prefer sstc extension if available RISC-V: KVM: Remove 's' & 'u' as valid ISA extension RISC-V: KVM: Restrict the extensions that can be disabled RISC-V: KVM: Introduce ISA extension register RISC-V: KVM: Support sstc extension arch/riscv/include/asm/csr.h | 11 ++ arch/riscv/include/asm/hwcap.h | 1 + arch/riscv/include/asm/kvm_host.h | 1 + arch/riscv/include/asm/kvm_vcpu_timer.h | 8 +- arch/riscv/include/uapi/asm/kvm.h | 21 ++++ arch/riscv/kernel/cpu.c | 1 + arch/riscv/kernel/cpufeature.c | 4 +- arch/riscv/kvm/main.c | 12 ++- arch/riscv/kvm/vcpu.c | 128 ++++++++++++++++++++-- arch/riscv/kvm/vcpu_timer.c | 138 +++++++++++++++++++++++- drivers/clocksource/timer-riscv.c | 21 +++- 11 files changed, 328 insertions(+), 18 deletions(-) --- 2.30.2