Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp5621653ybi; Wed, 31 Jul 2019 00:30:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqwchVYvhgUcPXljLo8yTab5kyO4gef7zKnf+BXN+SPUdgmEu5mp1bZgYNrb11Y9QViPbrmA X-Received: by 2002:a17:90a:cf0d:: with SMTP id h13mr1451949pju.63.1564558256023; Wed, 31 Jul 2019 00:30:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564558256; cv=none; d=google.com; s=arc-20160816; b=SgREQrNTEXmMC64scxbKwUDwFBCFMfBVeEKq/tLLuwGgZ/IQOXwWtOcryiZhYv2fKZ vci5fjOtUL+8JCdsBGgy0yOoofuzD2EtLBxGQ4IOMmz3OnR/LG79xcoohLt8shNOr8BW oxLK4VYEp3dGkVHYF51omPaij0msusxSiW3YiT2VQnKhxAD2yqpupEKoxj+7pkjA+3bk G6RMfdSL2RQCUgMDXVPLySLk59W9pwpCTOuxZWe3jZUw1PKFnUkTKpT/IhkV85ah8yUw fOUtX7CaS8l4SBr/YDK3H04qiqtIhGh6WYMGwGVCdiAjdcWlxMTrD8YbeuBnDlPiH98/ mdFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=qU9tOJPiFi8TuJFj6AQwXvcoVLt8SoI2Z+8B3y84t18=; b=soARLtz0l7cBrW53EMF4o8myGYNtVTA+se5Sc4fpRi0rE2HYgeG58z5PnlxVlHMu0D w2giFgWBQY641yRAlLixiWcg5Y5wq60n6Ks455Ei62tT7+lTxJh6DGzqdmq3+3YfliMZ OmiF3oy/SNtmpN3WmJmN9RpF9CICyfr67SwDHEDaxr5ZXdsA3JXh/QQfGAnrHUeq+PQq gtgNtITy3ycp1hyWhBaMSbd75uahW+SLDEw8p5KGwOIxWAtp5hyxqLqdncC9nHlLaMHP DOVtpgv8WypWS9FK3jOHdyKH3aXPJ5RcanHwX6kecR3CU2PqAIcXobi3xEGADhu2jVG6 2zAg== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m128si30114214pfm.97.2019.07.31.00.30.41; Wed, 31 Jul 2019 00:30: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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726550AbfGaG6N (ORCPT + 99 others); Wed, 31 Jul 2019 02:58:13 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:47092 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726334AbfGaG6N (ORCPT ); Wed, 31 Jul 2019 02:58:13 -0400 Received: by mail-wr1-f67.google.com with SMTP id z1so68335214wru.13 for ; Tue, 30 Jul 2019 23:58:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=qU9tOJPiFi8TuJFj6AQwXvcoVLt8SoI2Z+8B3y84t18=; b=M7vMeboSrFot6knFicZX94y6SAfRfWfvIPVPsTwn1ftLV3tpMSSKzWkh8FM4H9WyJC pYqMZB1d0YaYPwGsHy06XGGLCXWIiVXL5fp2xFkpDXYq4Iv8mtM1E/H2OGHoS/jYkK7X dVAcl9fhTEu4wktffcAIQ61f8q9LRpjzTAGPySP4Eh8N5ggqnYRRQQE91ZyKXaWf9KBw DDsrsSuIw2WmiDFGi+BvywleWbByR90omrQ5pRx7nFN7i5jSB43OZLnWPBuXEX3ieTlU o67olm2aE2zc8q7rd6LI2eMdSwwMbnsmEnm1C5Bn/p16m/B9QtsC8tp4ypUIdI/OSUr2 JtWQ== X-Gm-Message-State: APjAAAW06B50fbkYcBk5Y+dcmnZ+vb6j53DMTXB9LH7PAKuDIm+zHOl+ vLInpPt+eH1uH5R1XBMo5YUfIA== X-Received: by 2002:a05:6000:1043:: with SMTP id c3mr79068480wrx.236.1564556291018; Tue, 30 Jul 2019 23:58:11 -0700 (PDT) Received: from ?IPv6:2001:b07:6468:f312:91e7:65e:d8cd:fdb3? ([2001:b07:6468:f312:91e7:65e:d8cd:fdb3]) by smtp.gmail.com with ESMTPSA id t140sm1471116wmt.0.2019.07.30.23.58.09 (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Tue, 30 Jul 2019 23:58:10 -0700 (PDT) Subject: Re: [RFC PATCH 13/16] RISC-V: KVM: Add timer functionality To: Atish Patra , "paul.walmsley@sifive.com" , "rkrcmar@redhat.com" , "palmer@sifive.com" , Anup Patel Cc: "linux-riscv@lists.infradead.org" , "daniel.lezcano@linaro.org" , Alistair Francis , Damien Le Moal , "linux-kernel@vger.kernel.org" , "hch@infradead.org" , "tglx@linutronix.de" , "anup@brainfault.org" , "kvm@vger.kernel.org" References: <20190729115544.17895-1-anup.patel@wdc.com> <20190729115544.17895-14-anup.patel@wdc.com> <7fe9e845c33e49e4c215e12b1ee1b5ed86a95bc1.camel@wdc.com> From: Paolo Bonzini Message-ID: <0be68aeb-06de-71c7-375e-95f82112dae1@redhat.com> Date: Wed, 31 Jul 2019 08:58:09 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <7fe9e845c33e49e4c215e12b1ee1b5ed86a95bc1.camel@wdc.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 31/07/19 03:55, Atish Patra wrote: > On Tue, 2019-07-30 at 13:26 +0200, Paolo Bonzini wrote: >> On 29/07/19 13:57, Anup Patel wrote: >>> + if (delta_ns > VCPU_TIMER_PROGRAM_THRESHOLD_NS) { >>> + hrtimer_start(&t->hrt, ktime_add_ns(ktime_get(), >>> delta_ns), >> >> I think the guest would prefer if you saved the time before enabling >> interrupts on the host, and use that here instead of ktime_get(). >> Otherwise the timer could be delayed arbitrarily by host interrupts. >> >> (Because the RISC-V SBI timer is relative only---which is >> unfortunate--- > > Just to clarify: RISC-V SBI timer call passes absolute time. > > https://elixir.bootlin.com/linux/v5.3-rc2/source/drivers/clocksource/timer-riscv.c#L32 > > That's why we compute a delta between absolute time passed via SBI and > current time. hrtimer is programmed to trigger only after the delta > time from now. Nevermind, I got lost in all the conversions. One important issue is the lack of ability to program a delta between HS/HU-mode cycles and VS/VU-mode cycles. Without this, it's impossible to do virtual machine migration (except with hcounteren trap-and-emulate, which I think we agree is not acceptable). I found the open issue at https://github.com/riscv/riscv-isa-manual/issues/298 and commented on it. Paolo