Received: by 2002:a5d:925a:0:0:0:0:0 with SMTP id e26csp1075842iol; Thu, 9 Jun 2022 22:55:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSEQLdRxIU6UahzLDyvZV3LrboTKKeJ5RfTzqQxY974v+NqMUvVSO4CeVMPrgISoCnZECv X-Received: by 2002:a17:907:980c:b0:70b:543b:f4cd with SMTP id ji12-20020a170907980c00b0070b543bf4cdmr36962159ejc.34.1654840545088; Thu, 09 Jun 2022 22:55:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654840545; cv=none; d=google.com; s=arc-20160816; b=YsQEUYQKvNZ9a0LlyaTmjHEIuDg0/Rdyn2n/XRIV55FOCEH46aDDvgCvHdgEiHUSqS S0l1ZmLcO2qBNwwpLwrNYIGupVrM+34CcRXp7rIYwSKJ81BIRyeM0H3gclJ9EHquGwtc yW5wwtfgLXzySlEo+hVV6QCZqtXMW9QvaxBuCbhZJgtNvOvCBwp74/3/rh9/eHmq2fYa RmtwmvkUAfF5w/Mara6Dfs4KA7xQhDJTCeuO/EFy94P7HGYjlq24riRBkaQsFadFsGLs ah3lgTmCafl1PRzSD2EEYlb6Hpsh82kJ42LlHLcUrDy0pgYKVUMK1JMICmbireFipJnL 9Yrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=yT2dY1CxLSVJ5jM9XqmB8hnkuELf74CsmsabBpi5suY=; b=qxWlNt0c+Ppfiu0XfrNG7Ydxqwp/PEkXIy9xr6dcIzWPEnWcHdIWo40V8lqsyvcZSq WIDcYfLAA/jXR4LsZXNnPEB3UJRmT+F1CDoAA3GoprrsgKmK/OYeTPF5Tzk0dja2YM7E S/GDr8/C1sbF1lxI5G7Fa7aETwrvvfv7bjX5TYmejjVFyAiC8GSsb1hOBJLj24gAKnl6 YQq1kUMXEUIFIMxi2qHRpzKYvmBkG4yeqmfoA/hAg3McWQwoAoFOqqEOhIh9rnyfCI1s rOkeYI4uNZ6USz+dOWxKZRWJGNwNw3WgAExRIu4VkdwbR4kExOeqw5HpEHvIHYk1k+Ds R4dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20210112.gappssmtp.com header.s=20210112 header.b=AWO8jA8j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r9-20020a05640251c900b0043011328f47si25731673edd.4.2022.06.09.22.55.18; Thu, 09 Jun 2022 22:55:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@brainfault-org.20210112.gappssmtp.com header.s=20210112 header.b=AWO8jA8j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241310AbiFJExR (ORCPT + 99 others); Fri, 10 Jun 2022 00:53:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240448AbiFJExP (ORCPT ); Fri, 10 Jun 2022 00:53:15 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9E99317518 for ; Thu, 9 Jun 2022 21:53:11 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id o37-20020a05600c512500b0039c4ba4c64dso545556wms.2 for ; Thu, 09 Jun 2022 21:53:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=yT2dY1CxLSVJ5jM9XqmB8hnkuELf74CsmsabBpi5suY=; b=AWO8jA8jbizmFTZ2iKFOurF6Q+l71eaS9jhDiXhwP1Qvx+Rj98w8QYl3ulywOvgtv6 t5SQx1gDPX8B4Ijs0PmiEepDNZOLPrpkK5KNnw6CIgQAq7372hQrSJga4evSuejWB1Mq huhBQeeEQeakxBKZzpEN7Pg/RFD9OA+a9XMsmmVMT5Wv6bku3CHe/hMlPrs31emgAeyI 0zSaG8XP8kKpm+bGI2jierEB2C96vJwv/UEMrOJdE7iOfiFySytQSA/R2RCsDMO1JMBF 4vK7EQ3fJRvz4E3Y8Zgb36zCnnM8ypbwB/RzBCyuAWk1VoPc8bVfuYN5KB1DZ/q/1wLy shEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=yT2dY1CxLSVJ5jM9XqmB8hnkuELf74CsmsabBpi5suY=; b=yd2Wj2oZSQg1TQzrxcERz3yDuLqyI7iwJ6iJpTtbjTCey54ucFV1bfb9U5l0VPxewb Wt7NMK6n5D+w3KWiui9+sxHXm8GwulFvOnc4xfV9sMUrOpoGrmPRkllDdZKoup1Luxqg bJUe0ca0MjrYYmyGvo52FoKFYzWu/1K7DXGDdlJfdZywSGazK4VcU7zEFrqijHQqdAaI qKZQvZxxforDlsq577ZzAbdAat4lCHxObK7DtEgFMdkoG9OkMvpH+hd0lSBRKmsEvS5H tjvi2HcScpkxDv/nmu1VD/IpoOJPwbYgK3s5tgraZ/ZRkT3uJQqFuaUiMsvT0QgS5Nfh wWgA== X-Gm-Message-State: AOAM532fVy7/YSR1ZP8okpGPx0LKfdLRx8kjxnAJBkvkd7AvnJK4gsTl SUJ7iw7JXv1fsVa34VYAvPwo3mqfbFiA0eHGQG1QrA== X-Received: by 2002:a7b:c10d:0:b0:39c:4a17:1e90 with SMTP id w13-20020a7bc10d000000b0039c4a171e90mr6532508wmi.108.1654836790199; Thu, 09 Jun 2022 21:53:10 -0700 (PDT) MIME-Version: 1.0 References: <20220527042937.1124009-1-atishp@rivosinc.com> In-Reply-To: <20220527042937.1124009-1-atishp@rivosinc.com> From: Anup Patel Date: Fri, 10 Jun 2022 10:22:58 +0530 Message-ID: Subject: Re: [PATCH v4 0/4] Add Sstc extension support To: Atish Patra Cc: "linux-kernel@vger.kernel.org List" , Albert Ou , Atish Patra , Jisheng Zhang , linux-riscv , Palmer Dabbelt , Paul Walmsley , Rob Herring Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 27, 2022 at 9:59 AM Atish Patra wrote: > > 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. > > KVM directly updates the vstimecmp as well if the guest kernel invokes the SBI > call instead of updating stimecmp directly. This is required because KVM will > enable sstc extension if the hardware supports it unless the VMM explicitly > disables it for that guest. The hardware is expected to compare the > vstimecmp at every cycle if sstc is enabled and any stale value in vstimecmp > will lead to spurious timer interrupts. This also helps maintaining the > backward compatibility with older kernels. > > Similary, the M-mode firmware(OpenSBI) uses stimecmp for older kernel > without sstc support as STIP bit in mip is read only for hardware with sstc. > > 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 implements the Sstc extension in KVM. > > This series has been tested on Qemu(RV32 & RV64) with additional patches in > Qemu[2]. This series can also be found at [3]. > > Changes from v3->v4: > 1. Rebased on 5.18-rc6 > 2. Unified vstimemp & next_cycles. > 3. Addressed comments in PATCH 3 & 4. > > Changes from v2->v3: > 1. Dropped unrelated KVM fixes from this series. > 2. Rebased on 5.18-rc3. > > 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/qemu/tree/sstc_v3 > [3] https://github.com/atishp04/linux/tree/sstc_v4 > > Atish Patra (4): > 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: Support sstc extension Please don't forget to CC kvm-riscv mailing list for KVM RISC-V patches. We have a patchwork setup for KVM RISC-V will also miss a series if patches are not CCed. Regards, Anup > > arch/riscv/include/asm/csr.h | 11 ++ > arch/riscv/include/asm/hwcap.h | 1 + > arch/riscv/include/asm/kvm_vcpu_timer.h | 8 +- > arch/riscv/include/uapi/asm/kvm.h | 1 + > arch/riscv/kernel/cpu.c | 1 + > arch/riscv/kernel/cpufeature.c | 1 + > arch/riscv/kvm/main.c | 12 +- > arch/riscv/kvm/vcpu.c | 5 +- > arch/riscv/kvm/vcpu_timer.c | 144 +++++++++++++++++++++++- > drivers/clocksource/timer-riscv.c | 24 +++- > 10 files changed, 198 insertions(+), 10 deletions(-) > > -- > 2.25.1 >