Received: by 2002:a05:6a10:c7d3:0:0:0:0 with SMTP id h19csp73084pxy; Sat, 14 Aug 2021 00:32:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxk82SbQ+F/DQve7LhbZcRyjiNcfy2zT7ZBHG7WyetrwW21ViV46cWzOSRBXTreBowUqves X-Received: by 2002:a05:6402:5112:: with SMTP id m18mr7841341edd.47.1628926349464; Sat, 14 Aug 2021 00:32:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628926349; cv=none; d=google.com; s=arc-20160816; b=wIYE56LGxEEG5Avx+wnmQogNR9QcJPdUuWjLZryQz7T93A0zh4jrZUzQ5zmw1elvm2 7DyvladTvfSxxzEyEVVlXw1ZDLKiHy4vvvLQ4JrTdfMinfEVrpTSFg27iwJITTgBBWva JL66wXmcW4SIAHZRjLsiKFyUk4swJ9jXA6Xrtiwa+fk1PGZ3l921FE2E2kBpX+PSXCdW bE7olUoSYOiGq52TD/g3zr04FjQqQQitZGOU9VmwvvwK2gU8a+faOKvM1dFDQJ7NN31Z p9zC8K7eL+k1DUqh6Eq2XxvNTjjt4n6OTLGXh1Y12cnJJRK/EMk6BcDcTjlgYvdAoIyb DfuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:subject:from :references:cc:to:dkim-signature; bh=1TtSUDMLTyWrnaOTR2UJPOGTDs88Lu3pvS9ZFwMmYSo=; b=vQPxNgHwVpDtYzFTu+QKh2IimNGEdh21JH0XYKwWQPRDiuEnliocaXkOxdiKm6zDNA Mc+lhY+nfXXtmFvMygOY8tb6Yh2dpU2qUG970qT/HZ0FGKQrPSxr67WoZoNjBJ1DJY2l ir0JlcHaXOp+9V9bTJzKHajSsb3a/8CR0gM0UR3G/BOdeJS+kpvIbxaJ/IZ+8Bn+r6ZS mbeZbFR765VUslGpnAlcvA9S8/douB5CHOr18w/Rp8JfWALke3huKpquFfVBkvDVBwJh d0J0b40TVkZzkt8sqJtEZWgfsIqCS3n/hpEk1v5FlVWsJDxaN1mqvkEp50Lom4rdbt8n BedA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JELr58Fc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id la20si5330981ejc.3.2021.08.14.00.31.45; Sat, 14 Aug 2021 00:32:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JELr58Fc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S237317AbhHNHW4 (ORCPT + 99 others); Sat, 14 Aug 2021 03:22:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:29931 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237275AbhHNHWx (ORCPT ); Sat, 14 Aug 2021 03:22:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628925745; 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=1TtSUDMLTyWrnaOTR2UJPOGTDs88Lu3pvS9ZFwMmYSo=; b=JELr58FcRMuQeDYfk+6ORCWiJhK53Ug73j3OvpxiAmK/WV6jerbDxq9ov0n3ymC+jCUniJ oyObYGWp+umchUEU2PIB85hMxLkBjX1zfxPTBHLfPbAuPubi7Ck9aFcTQPBzWTIH6t++A/ XiW+4/EHCC92HPbCwz3OhcNREFfN6v0= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-360-TM9ftO-XPUOiuzObTWLX2w-1; Sat, 14 Aug 2021 03:22:21 -0400 X-MC-Unique: TM9ftO-XPUOiuzObTWLX2w-1 Received: by mail-ed1-f69.google.com with SMTP id eg56-20020a05640228b8b02903be79801f9aso5940937edb.21 for ; Sat, 14 Aug 2021 00:22:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:references:from:subject:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=1TtSUDMLTyWrnaOTR2UJPOGTDs88Lu3pvS9ZFwMmYSo=; b=JfgsAf3nl0MlanQS7Ng090Oias0DKtnkuptkEvuhtzhExQrPxJ9lJgV6ep23NdPnjR bXT4lOC3qlI5SlQVi0pLDggauJvdQoospU7pjM70pmo9T65sMHaYvkokOslKuolGxu3Z +VrXOQzblwDOYF5Y93jH8lOPKIIw2ThskIkXPZWa04rCCyFFOZVKPsUdeOCkx/Ph+qqo qXTr/bcz0ezlkXx5jx+uQ1uiE7khuVhDhesUYsOCKpHNXxd7yd1fDL7XLqd+XSS/AFup CttzjxVdt63XKlY32Av+zO4Lw4y/16uQJd2uIp062L20IWDS7f80+CX/mDVhUK1g9d4x vZOg== X-Gm-Message-State: AOAM532mKi6YK7xXLqkrJB1HyFe4EiMzDSKBFoE18nE0QOTXgd8jY0XM PyzVGcpM9wbmS19rrhAUJoYf8j5ZtUy+OhMZ9QhrbsIES50O7gY/g9JWQgC7QRwwQSUSdGLMgT6 4pcjQOsuJ99chE5+g9iZ6Sw+h X-Received: by 2002:a05:6402:1d33:: with SMTP id dh19mr7880369edb.10.1628925740649; Sat, 14 Aug 2021 00:22:20 -0700 (PDT) X-Received: by 2002:a05:6402:1d33:: with SMTP id dh19mr7880346edb.10.1628925740441; Sat, 14 Aug 2021 00:22:20 -0700 (PDT) Received: from [192.168.10.118] ([93.56.169.140]) by smtp.gmail.com with ESMTPSA id z4sm1412515edc.33.2021.08.14.00.22.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 14 Aug 2021 00:22:19 -0700 (PDT) To: Hikaru Nishida , linux-kernel@vger.kernel.org, dme@dme.org, tglx@linutronix.de, mlevitsk@redhat.com Cc: suleiman@google.com, Borislav Petkov , "H. Peter Anvin" , Ingo Molnar , Jim Mattson , Joerg Roedel , John Stultz , Sean Christopherson , Stephen Boyd , Vitaly Kuznetsov , Wanpeng Li , kvm@vger.kernel.org, x86@kernel.org References: <20210806100710.2425336-1-hikalium@chromium.org> <20210806190607.v2.3.Ib0cb8ecae99f0ccd0e2814b310adba00b9e81d94@changeid> From: Paolo Bonzini Subject: Re: [v2 PATCH 3/4] x86/kvm: Add host side support for virtual suspend time injection Message-ID: <2ec642dd-dde6-bee6-3de3-0fa78d288995@redhat.com> Date: Sat, 14 Aug 2021 09:22:18 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210806190607.v2.3.Ib0cb8ecae99f0ccd0e2814b310adba00b9e81d94@changeid> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/08/21 12:07, Hikaru Nishida wrote: > +#if defined(CONFIG_KVM_VIRT_SUSPEND_TIMING) || \ > + defined(CONFIG_KVM_VIRT_SUSPEND_TIMING_GUEST) > +#define VIRT_SUSPEND_TIMING_VECTOR 0xec > +#endif No need to use a new vector. You can rename the existing MSR_KVM_ASYNC_PF_INT to MSR_KVM_HYPERVISOR_CALLBACK_INT or something like that, and add the code to sysvec_kvm_asyncpf_interrupt. > +static void kvm_make_suspend_time_interrupt(struct kvm_vcpu *vcpu) > +{ > + kvm_queue_interrupt(vcpu, VIRT_SUSPEND_TIMING_VECTOR, false); > + kvm_make_request(KVM_REQ_EVENT, vcpu); > +} Use kvm_apic_set_irq which will inject the interrupt as soon as possible, so you do not even need to check kvm_vcpu_ready_for_interrupt_injection. > +#ifdef CONFIG_KVM_VIRT_SUSPEND_TIMING > + if (kvm->suspend_injection_requested && > + kvm_vcpu_ready_for_interrupt_injection(vcpu)) { > + kvm_write_suspend_time(kvm); > + kvm_make_suspend_time_interrupt(vcpu); > + kvm->suspend_injection_requested = false; > + } > +#endif Do not read variables in vcpu_run; There is KVM_REQ_* if you need to do work in the vCPU run loop. > + mutex_lock(&kvm_lock); > + list_for_each_entry(kvm, &vm_list, vm_list) { > + if (!(kvm->arch.msr_suspend_time & KVM_MSR_ENABLED)) > + continue; > + > + kvm_for_each_vcpu(i, vcpu, kvm) > + vcpu->arch.tsc_offset_adjustment -= adj; > + > + /* > + * Move the offset of kvm_clock here as if it is stopped > + * during the suspension. > + */ > + kvm->arch.kvmclock_offset -= suspend_time_ns; > + > + /* suspend_time is accumulated per VM. */ > + kvm->suspend_time_ns += suspend_time_ns; > + kvm->suspend_injection_requested = true; > + /* > + * This adjustment will be reflected to the struct provided > + * from the guest via MSR_KVM_HOST_SUSPEND_TIME before > + * the notification interrupt is injected. > + */ > + } > + mutex_unlock(&kvm_lock); > +} As pointed out by Thomas, this should be a work item. Paolo