Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp6431815ybe; Wed, 18 Sep 2019 03:26:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqwT4iEe2SrzmSLI1iNZtGKAIyFiOSBX6qnYtLTQTX/NaLIiR+HblgVwEn5n/MUBIg/0Qb/3 X-Received: by 2002:a50:934c:: with SMTP id n12mr9555381eda.12.1568802383731; Wed, 18 Sep 2019 03:26:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568802383; cv=none; d=google.com; s=arc-20160816; b=hDxouyYH56Q3TtSWuHBjk0dHI1+Avu2hASq25IthdmlQJ0jrtRXS8svR2EkkIvSeYy /F23+4idB6HkoWhZ+bo70A18v1vkLIxF6MDNDW5gQ/gPY0eK+DK+4h6D9gbLlhvr8X3R 4rOm/AgwMjy5d2az7YlIb1EeZkSEz8jlMckTIc8hBO/R7UtkNBWL3F2moIYcP3foOnA2 AmF9Mp2ZjatFzWRMmOqh7XqqViXQ18TSK1ZJwRruvlV3gVim8iSnfC+L+Bj+hqUq31hA YBmlPEo3dFn9k6B7DDhnD9Gfddg88mZqi/0ZAc9ydhtXmSb80LGmbE4AxgTVC1weje+H ODUw== 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:dkim-signature; bh=PzJJIzaT+H0i65urk/DowU+Nu1kZ2zWoYZTl/vMnWsA=; b=IaEZW+x5y0S+30s08tCl4UuWueZkt6CxFw3fnkc1eOT52rEhexPueLY09zeVJQ3r86 Jn8z1OYuU5UYUqm6GAH386NExQmmLzlyKr9pQD5XkWfXlBFRO2CYVjLNfv8H3dz8Bac2 jxRoX+k5UgH6pwDv+Xyo4/aoIwRUFu+7oI6QMfd03HEFmrV4cvWCu/usc70PcWMZi4Wu oOnOXBJYk0IQp837q10zxcmwGg4qeqXSzptsoqq8VEkkJGYTmTKTwVk6BwOd9hrkPh2W Pj/Y2soaIhAIID6IiXeFLiIyNkpkjowLpZXVK+zdb+KlzxHUff+zlnkXakqqMr5UogAw nqkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NBkUq176; 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=pass (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 h91si3166851edd.270.2019.09.18.03.25.59; Wed, 18 Sep 2019 03:26:23 -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=@redhat.com header.s=mimecast20190719 header.b=NBkUq176; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729827AbfIRKX4 (ORCPT + 99 others); Wed, 18 Sep 2019 06:23:56 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:24031 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729713AbfIRKXz (ORCPT ); Wed, 18 Sep 2019 06:23:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1568802233; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PzJJIzaT+H0i65urk/DowU+Nu1kZ2zWoYZTl/vMnWsA=; b=NBkUq176kVQSB9vtvsFK2KbuEdUGO/D6ecCpIunhu82G0jzJrck64DsaduzznUKbWzDhwU 8eAFdHBni7jK1MVlmentoyiTGEslp4iHuc+R8VZoGy42x6OdjNifUK7+5D2JHjoFjpQwhK Ny9T2LxyAXpzD/wAGi6RkHcLm50mRVo= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-202-ob8Hl-fgPmKLiPY9wB2YSg-1; Wed, 18 Sep 2019 06:23:50 -0400 Received: by mail-wr1-f69.google.com with SMTP id j2so2190817wre.1 for ; Wed, 18 Sep 2019 03:23:50 -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=/BXfx7jonw/Kdws8cuIdF1uOWxKnVxEGGX2roqyV5/g=; b=F8S1mZXciBZZH4ChZ4TD2bu7BNJ53Qv3QtGSdNWo87kilL7hM9u02XcqbKz7ZeruOn RgsVxG81Ks3NDSC8rOChC1NKNhTrLBS5sLb3Zgu+cqyLbvOL/HP6M6v6eHlMlqpT62KW XUgt7mOlgEtug84gUvHtfiPUKUq2HRUEnyCQX+znyUjfx9oACvVpeV5wdxnaYQ02gXWk lbOwoekZOq4WEhdEqgQx348JlzcNKercaG0+NuBfGAUR0NvdYngo4h1oxh94MOiSTcq3 9XvHL9+JmD2LFOHqOvwO9vs6b4V/RBFITVOglsriYFBkJwYedaKByyPk6Z6qVbbvsHo0 tQ5g== X-Gm-Message-State: APjAAAXV62N8+mw0ffb0luuZ0Xl+ZwMm4YB0tbIZGAbKTZiN8eBKQcjD aBduQ37t9kPEzeC0pTPEtHdxIkTOwRlMxzPnNHJEtTUe36ZCTe6DRrrlcA7jqD/Revbw6RDLIXP s8B5qbNYoKN67+nHiAqgNJWHN X-Received: by 2002:adf:e443:: with SMTP id t3mr2384766wrm.181.1568802229667; Wed, 18 Sep 2019 03:23:49 -0700 (PDT) X-Received: by 2002:adf:e443:: with SMTP id t3mr2384734wrm.181.1568802229356; Wed, 18 Sep 2019 03:23:49 -0700 (PDT) Received: from ?IPv6:2001:b07:6468:f312:c46c:2acb:d8d2:21d8? ([2001:b07:6468:f312:c46c:2acb:d8d2:21d8]) by smtp.gmail.com with ESMTPSA id h125sm2260481wmf.31.2019.09.18.03.23.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Sep 2019 03:23:48 -0700 (PDT) Subject: Re: [RFC PATCH v3 4/6] psci: Add hvc call service for ptp_kvm. To: "Jianyong Wu (Arm Technology China)" , "netdev@vger.kernel.org" , "yangbo.lu@nxp.com" , "john.stultz@linaro.org" , "tglx@linutronix.de" , "sean.j.christopherson@intel.com" , "maz@kernel.org" , "richardcochran@gmail.com" , Mark Rutland , Will Deacon , Suzuki Poulose Cc: "linux-kernel@vger.kernel.org" , "kvm@vger.kernel.org" , Steve Capper , "Kaly Xin (Arm Technology China)" , "Justin He (Arm Technology China)" , nd , "linux-arm-kernel@lists.infradead.org" References: <20190918080716.64242-1-jianyong.wu@arm.com> <20190918080716.64242-5-jianyong.wu@arm.com> <83ed7fac-277f-a31e-af37-8ec134f39d26@redhat.com> From: Paolo Bonzini Message-ID: <629538ea-13fb-e666-8df6-8ad23f114755@redhat.com> Date: Wed, 18 Sep 2019 12:23:47 +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: Content-Language: en-US X-MC-Unique: ob8Hl-fgPmKLiPY9wB2YSg-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 18/09/19 11:57, Jianyong Wu (Arm Technology China) wrote: > Hi Paolo, >=20 >> On 18/09/19 10:07, Jianyong Wu wrote: >>> +=09case ARM_SMCCC_VENDOR_HYP_KVM_PTP_FUNC_ID: >>> +=09=09getnstimeofday(ts); >> >> This is not Y2038-safe. Please use ktime_get_real_ts64 instead, and spl= it the >> 64-bit seconds value between val[0] and val[1]. >> > As far as I know, y2038-safe will only affect signed 32-bit integer, > how does it affect 64-bit integer? > And why split 64-bit number into two blocks is necessary? val is an u32, not an u64. (And val[0], where you store the seconds, is best treated as signed, since val[0] =3D=3D -1 is returned for SMCCC_RET_NOT_SUPPORTED). >> However, it seems to me that the new function is not needed and you can >> just use ktime_get_snapshot. You'll get the time in systime_snapshot->r= eal >> and the cycles value in systime_snapshot->cycles. >=20 > See patch 5/6, I need both counter cycle and clocksource, ktime_get_snaps= hot seems only offer cycles. No, patch 5/6 only needs the current clock (ptp_sc.cycles is never accessed). So you could just use READ_ONCE(tk->tkr_mono.clock). However, even then I don't think it is correct to use ptp_sc.cs blindly in patch 5. I think there is a misunderstanding on the meaning of system_counterval.cs as passed to get_device_system_crosststamp. system_counterval.cs is not the active clocksource; it's the clocksource on which system_counterval.cycles is based. Hypothetically, the clocksource could be one for which ptp_sc.cycles is _not_ a cycle value. If you set system_counterval.cs to the system clocksource, get_device_system_crosststamp will return a bogus value. So system_counterval.cs should be set to something like &clocksource_counter (from drivers/clocksource/arm_arch_timer.c). Perhaps the right place to define kvm_arch_ptp_get_clock_fn is in that file= ? >>> +=09=09get_current_counterval(&sc); >>> +=09=09val[0] =3D ts->tv_sec; >>> +=09=09val[1] =3D ts->tv_nsec; >>> +=09=09val[2] =3D sc.cycles; >>> +=09=09val[3] =3D 0; >>> +=09=09break; >> >> This should return a guest-cycles value. If the cycles values always th= e same >> between the host and the guest on ARM, then okay. If not, you have to >> apply whatever offset exists. >> > In my opinion, when use ptp_kvm as clock sources to sync time > between host and guest, user should promise the guest and host has no > clock offset. What would be the adverse effect of having a fixed offset between guest and host? If there were one, you'd have to check that and fail the hypercall if there is an offset. But again, I think it's enough to subtract vcpu_vtimer(vcpu)->cntvoff or something like that. You also have to check here that the clocksource is based on the ARM architectural timer. Again, maybe you could place the implementation in drivers/clocksource/arm_arch_timer.c, and make it return -ENODEV if the active clocksource is not clocksource_counter. Then KVM can look for errors and return SMCCC_RET_NOT_SUPPORTED in that case. Thanks, Paolo > So we can be sure that the cycle between guest and > host should be keep consistent. But I need check it. > I think host cycle should be returned to guest as we should promise > we get clock and counter in the same time.