Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1251510ybl; Fri, 23 Aug 2019 16:12:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqx7QJ8T8lG9RmQxH9eMMv6h+fAcVCDGcdcAn8idroE/H3qfq3dXlKGT/JqaXNl8XwDKIbL5 X-Received: by 2002:a62:8343:: with SMTP id h64mr7713303pfe.170.1566601976548; Fri, 23 Aug 2019 16:12:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566601976; cv=none; d=google.com; s=arc-20160816; b=vAubB/kGNkHHpqdFv+a9mJAkiiAcnY12sOzwnmTNBizWLFNxz84blX+hs6X1pCsbTk xqmYy2hvobnoG9eMfJ2gxb+B46drdq0lg5i+XGbuSmj5xfoF/6ztVbEF0pPVkrl/56Ov OCILBPttTPRjJ2R5bgeOlwIC+9O6jY23PvHxnir+Z2NRCnZ2mr2m8Hx1VaSx6z7Px7e3 1AqQADjKfm0P6vSpjw9H5rkBR3a3DTTEnQmphmLgse55o2aZqgUz1E116qaIOHJLlBRd CHtZIvnQaUVSA0W6c639HqNXavLR+d1/R0d9iJljrcFxdagHyUaYDAzBks2nR+aNdG8n Z58A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=iRAIEkmwp6JE/WX2NGJMgDWxiWJMs7wvHv42hCwyQfI=; b=oEuXQYSQwhtfSAfAXFyPWmJR8MBtLhqP2b3ty8M/Akp31vpRFfMUrHpbfYhmuhgwxv nbIXtbum4Tcfahm/fj0+zRJgjbHmzYTsyuFlXorfImEwDEgYrubtEnJ8H75FVYQOj7VX JmL/vkQJrJwFMFU/8EQkPDexKaoEeDJq6Qyp8T47gWICMTTwCj9hsbwKVfk70sw3p6kK QmLbMafpJj/yC14mwMoH8zFXKDWqqv/QGL7tPvtqzC4IedHy+bOyR7GjpoGY6K1Qz0nD KHxZZ9L2tseQtASmYCFZzIdIotg1ubA6hGA8tZsrDdMqDtfRLe3M8YV652MvgUwenQDh a1Qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=YEpPQAEv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b15si3032414pgj.141.2019.08.23.16.12.41; Fri, 23 Aug 2019 16:12:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=YEpPQAEv; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405365AbfHWML2 (ORCPT + 99 others); Fri, 23 Aug 2019 08:11:28 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:36977 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405336AbfHWML2 (ORCPT ); Fri, 23 Aug 2019 08:11:28 -0400 Received: by mail-wr1-f67.google.com with SMTP id z11so8431129wrt.4 for ; Fri, 23 Aug 2019 05:11:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=iRAIEkmwp6JE/WX2NGJMgDWxiWJMs7wvHv42hCwyQfI=; b=YEpPQAEvWA9shVqsD3mh8d8r/uR1cXm76LWodn7SiQ5pxKz7XzPS/ZenBR9boBZyaG caGIKN8nTkYwxmJT/mzu7KBhHgk4GeQi8KzLsfjZvbcWPNgfjk8U7abtLLKyXdj5Iamh WEsHh//w59EZk4ZHq2zco+dvqKcSqeOpqKfAgAxs24rR3jk7qj70m/eSqghKeO27BCbg 57q5BniRpmfS+Onee+Wyw2JZmiPvY2YoeKKMT+7msYpvsBdu8lDwXAgn8HTnnVp8Mqhf ANB5y7OGnpvyOk+4i8bGpz2IwFMlbb8/P8hrdq+BDZUs4bKztK084OcOQFc10fpgUOCS PrkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=iRAIEkmwp6JE/WX2NGJMgDWxiWJMs7wvHv42hCwyQfI=; b=V0+FxKgEPhr+nHcKgarSZ7TLmCJmWOlnM4wSNijlQn3kWubjz9/zIxP/dq2c7ndzIb G8u5ZOYnCeo0HmDDe7cD+9Hgbu5gosJoFr+eIyOrMvfpGe1EcUOiT7ncX8yYzlVvnLo9 8/EsHGFj0cnfO5IuSMc0XKTsFG2WygIfPfVs2/B2r+rA6TS1gMORhDemV0mu0EkU+ytM ZJY9inqakkapuMPib3vrCWHkurh5W9I5qCxHb0L/8EDEQHyUiq1et1FT7tX+2VLxP8mT cNyqM/eoU17eo8bdelEToeINTEmr4ccVcwi0IU0SclictqYzie+Xl9/sl8Jh+m32nibc 7dEA== X-Gm-Message-State: APjAAAUwnFxoJupEBEXTY01GeNkDttkyBtGx0Yq5PBYNXAZU57mQNkaf /7AoEzng00xzpRLSrlGVNlO0tyj87mj4VU2Edu1Tsg== X-Received: by 2002:a5d:4ecb:: with SMTP id s11mr4728857wrv.323.1566562285504; Fri, 23 Aug 2019 05:11:25 -0700 (PDT) MIME-Version: 1.0 References: <20190822084131.114764-1-anup.patel@wdc.com> <20190822084131.114764-16-anup.patel@wdc.com> <09d74212-4fa3-d64c-5a63-d556e955b88c@amazon.com> In-Reply-To: From: Anup Patel Date: Fri, 23 Aug 2019 17:41:13 +0530 Message-ID: Subject: Re: [PATCH v5 15/20] RISC-V: KVM: Add timer functionality To: Alexander Graf Cc: Anup Patel , Palmer Dabbelt , Paul Walmsley , Paolo Bonzini , Radim K , Daniel Lezcano , Thomas Gleixner , Atish Patra , Alistair Francis , Damien Le Moal , Christoph Hellwig , "kvm@vger.kernel.org" , "linux-riscv@lists.infradead.org" , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 23, 2019 at 5:19 PM Alexander Graf wrote: > > > > On 23.08.19 13:46, Anup Patel wrote: > > On Fri, Aug 23, 2019 at 5:03 PM Graf (AWS), Alexander wrote: > >> > >> > >> > >>> Am 23.08.2019 um 13:05 schrieb Anup Patel : > >>> > >>>> On Fri, Aug 23, 2019 at 1:23 PM Alexander Graf wrote: > >>>> > >>>>> On 22.08.19 10:46, Anup Patel wrote: > >>>>> From: Atish Patra > >>>>> > >>>>> The RISC-V hypervisor specification doesn't have any virtual timer > >>>>> feature. > >>>>> > >>>>> Due to this, the guest VCPU timer will be programmed via SBI calls. > >>>>> The host will use a separate hrtimer event for each guest VCPU to > >>>>> provide timer functionality. We inject a virtual timer interrupt to > >>>>> the guest VCPU whenever the guest VCPU hrtimer event expires. > >>>>> > >>>>> The following features are not supported yet and will be added in > >>>>> future: > >>>>> 1. A time offset to adjust guest time from host time > >>>>> 2. A saved next event in guest vcpu for vm migration > >>>> > >>>> Implementing these 2 bits right now should be trivial. Why wait? > >>> > > [...] > > >>>> ... in fact, I feel like I'm missing something obvious here. How does > >>>> the guest trigger the timer event? What is the argument it uses for that > >>>> and how does that play with the tbfreq in the earlier patch? > >>> > >>> We have SBI call inferface between Hypervisor and Guest. One of the > >>> SBI call allows Guest to program time event. The next event is specified > >>> as absolute cycles. The Guest can read time using TIME CSR which > >>> returns system timer value (@ tbfreq freqency). > >>> > >>> Guest Linux will know the tbfreq from DTB passed by QEMU/KVMTOOL > >>> and it has to be same as Host tbfreq. > >>> > >>> The TBFREQ config register visible to user-space is a read-only CONFIG > >>> register which tells user-space tools (QEMU/KVMTOOL) about Host tbfreq. > >> > >> And it's read-only because you can not trap on TB reads? > > > > There is no TB registers. > > > > The tbfreq can only be know through DT/ACPI kind-of HW description > > for both Host and Guest. > > > > The KVM user-space tool needs to know TBFREQ so that it can set correct > > value in generated DT for Guest Linux. > > So what access methods do get influenced by TBFREQ? If it's only the SBI > timer, we can control the frequency, which means we can make TBFREQ > read/write. There are two things influenced by TBFREQ: 1. TIME CSR which is a free running counter 2. SBI calls for programming next timer event The Guest TIME CSR will be at same rate as Host TIME CSR so we cannot show different TBFREQ to Guest Linux. In future, we will be having a dedicated RISC-V timer extension which will have all programming done via CSRs but until then we are stuck with TIME CSR + SBI call combination. Regards, Anup > > > Alex