Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp5311918pxv; Wed, 21 Jul 2021 02:22:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzrxlKD6M0+iUoTUNxzH07J02sceb/3gIXUIoVg/79ENQFfcctwTPpD/nmDWbrrT1US/kh7 X-Received: by 2002:a17:907:7786:: with SMTP id ky6mr37956979ejc.93.1626859357337; Wed, 21 Jul 2021 02:22:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626859357; cv=none; d=google.com; s=arc-20160816; b=TDaK3d/uRRrzlOeGUWfrbGlpS3OYDi+Nzb75h2AaE1FwRpGQnHLMsErds9V505C1xF KQra7gxrwGbFl7GvMEbPcvTmlABX+OpT5ZWtrsKD7nk0DouWDl1O931UlXTfV7MCJmOd KORUXWetHPw5u1JgXuagAmf7KYvbn98EU6t/4Ru/wUzLCac9n157T95JQOyb1tWYLBqg jyOHvsDhvBcpTdF90ZZKbLsRaqOo68Q/uzfTrxDDeYpW34LfaywKntbttBQR0AtPqPhr wctkJp9BdNJ6lKV9Eqv+moHLwZdbWjDweLLLc5IM+3Qe9IFy+jJr3nuz0AR6P2pdRSvF qEUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date; bh=ipM6baE8QLmJ+O8m2GS/pAZI91dj4nYXA4JeYIOmwlk=; b=l1ZhYbY2Mv4AA0aKp7yovqwGQSR4uKOs1cc/zK84N/an8eQr27G5zDqbc7qNec/C+1 uOY6Nmm7lCnX2bpbQCy4qDXzn9dC8b1wlT5sQ0esegbMGThQTrpv1Ekl+rgXqF1no3NS WfUHZtKymaDmqMPc2ufjY2pNdcF1s8vi6PToJVCYFmxBiARVJgWfbuSNjPOWfGt201dF VeBgNRhTh3K4/TZqhfWKbs/dPVb9DhATqDV3idFUJkoZh7qGvG/o1oZDFHfDY/VItZD3 TS1b/dC/Z+8q6vHlejh3muNeyKAqN8GIdSAUzotDjf8vGtUc8cgHXB6O6k6YrRHHbTZa 0rLw== ARC-Authentication-Results: i=1; mx.google.com; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m8si27652684edr.203.2021.07.21.02.22.13; Wed, 21 Jul 2021 02:22:37 -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; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238065AbhGUIjo (ORCPT + 99 others); Wed, 21 Jul 2021 04:39:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:57478 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237159AbhGUIaZ (ORCPT ); Wed, 21 Jul 2021 04:30:25 -0400 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 31F3960FE9; Wed, 21 Jul 2021 09:11:02 +0000 (UTC) Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1m68Fo-00EfUP-5u; Wed, 21 Jul 2021 10:11:00 +0100 Date: Wed, 21 Jul 2021 10:10:59 +0100 Message-ID: <87fsw82frw.wl-maz@kernel.org> From: Marc Zyngier To: Sergey Senozhatsky Cc: Will Deacon , Suleiman Souhlal , Joel Fernandes , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: Re: [PATCHv2 4/4] arm64: add host pv-vcpu-state support In-Reply-To: References: <20210709043713.887098-1-senozhatsky@chromium.org> <20210709043713.887098-5-senozhatsky@chromium.org> <874kcz33g5.wl-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: senozhatsky@chromium.org, will@kernel.org, suleiman@google.com, joelaf@google.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 21 Jul 2021 02:15:47 +0100, Sergey Senozhatsky wrote: > > On (21/07/12 17:24), Marc Zyngier wrote: > > > > > > void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) > > > { > > > + kvm_update_vcpu_preempted(vcpu, true); > > > > This doesn't look right. With this, you are now telling the guest that > > a vcpu that is blocked on WFI is preempted. This really isn't the > > case, as it has voluntarily entered a low-power mode while waiting for > > an interrupt. Indeed, the vcpu isn't running. A physical CPU wouldn't > > be running either. > > I suppose you are talking about kvm_vcpu_block(). kvm_vcpu_block() is how things are implemented. WFI is the instruction I'm concerned about. > Well, it checks kvm_vcpu_check_block() but then it simply schedule() > out the vcpu process, which does look like "the vcpu is > preempted". Once we sched_in() that vcpu process again we mark it as > non-preempted, even though it remains in kvm wfx handler. Why isn't > it right? Because the vcpu hasn't been "preempted". It has *voluntarily* gone into a low-power mode, and how KVM implements this "low-power mode" is none of the guest's business. This is exactly the same behaviour that you will have on bare metal. From a Linux guest perspective, the vcpu is *idle*, not doing anything, and only waiting for an interrupt to start executing again. This is a fundamentally different concept from preempting a vcpu because its time-slice is up. In this second case, you can indeed mitigate things by exposing steal time and preemption status as you break the illusion of a machine that is completely controlled by the guest. If the "reched on interrupt delivery while blocked on WFI" is too slow for you, then *that* is the thing that needs addressing. Feeding extra state to the guest doesn't help. > Another call path is iret: > > > __schedule() > context_switch() > prepare_task_switch() > fire_sched_in_preempt_notifiers() > kvm_sched_out() > kvm_arch_vcpu_put() I'm not sure how a x86 concept is relevant here. Thanks, M. -- Without deviation from the norm, progress is not possible.