Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp2706311rdh; Mon, 30 Oct 2023 05:36:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFeURjlQ0ABSLPvXMdN3Q9SMAWFCqy/bWU5TBNAw1Zdo4QW9zU9IM/t5yW6a/bU3yw5AWCK X-Received: by 2002:a05:6a00:14d2:b0:6bd:254a:8876 with SMTP id w18-20020a056a0014d200b006bd254a8876mr8696647pfu.23.1698669387896; Mon, 30 Oct 2023 05:36:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698669387; cv=none; d=google.com; s=arc-20160816; b=m8GC8SpZAoGSnhFlEa97sRdmNJYLvvpuQ1Dn2Gq7L7b3vE6DKjKN1dPxz6MyMeX6dc BPiBlXMWopWjMp6S7me8gRAgZ96ywFb14WL1pL5i6oouY7i1xlBfGS8kwd5efuG97uJU cXnQZY+JYmvKv0BWWHJPq+yMqxf+HP0a3VnZ1DpOneNcq0BlhoM8JPeFJn7ULXbj+dGP ZwsT4gCHfzx9dNaMDs0Sb0w/vi2o9RgDshCpZkIzqVupW+iqJ6kKQRei5FQcU6nKXaAl 6biAFe7Hh0F3r6xn8AYU14lzel8uzyaeIP/6h0lGwQG8h9QUA7asgtVu97pX6We3I8NK dYEQ== 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:dkim-signature; bh=3iVUC8WAdNMRHMzaMzHmVFpjtU8InaZC8fAyEofR/MY=; fh=Zqa9pQKdV1ogoxefhu2MEbaWEHbvjsGDNzwWyUJeGq4=; b=Y78FXrVxtoqXLzxwtqXQhL/eQBLlutZx+fS5+UeqeLBoAJzqXFLXnSiMOm7BLnhArV TrrJ6Qyp8r0nhy6hJcb/93GF5J38DohpZzlofja+4AoG0xnYeVdthy2kcu2AS6Ai9qwh arI7uOu4i4xh0CEoJS2pB5jIumg9hsS1fGo2wkLisuFRzc9tjmXixfTExxITkyFwDlaG x2s8Q0gI8eELDIyhRXEzY8dQHSE+JeXKxviHqiOs8ARJlD3O6vygubJz4/lOTKG8UTOu eYC/4itwA7hLLvOWLXVZtXwBBS8k0Nv+fWVvKh/3dBol/1aIU6rQ2BU7ZtXSGby08pdv zt2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="T/eyqJHU"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id s41-20020a056a0017a900b006be1c26af7dsi4894394pfg.236.2023.10.30.05.36.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 05:36:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="T/eyqJHU"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 3EC6C809FA34; Mon, 30 Oct 2023 05:36:25 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233191AbjJ3MgR (ORCPT + 99 others); Mon, 30 Oct 2023 08:36:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232291AbjJ3MgQ (ORCPT ); Mon, 30 Oct 2023 08:36:16 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B8CEC6 for ; Mon, 30 Oct 2023 05:36:14 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A2B04C433C7; Mon, 30 Oct 2023 12:36:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698669373; bh=/71kbiytdp/VoW3kuCJ1kqiDxE4ZD+L4PqRlfCczo0I=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=T/eyqJHUuAonHxnuxkt6GEdACiAWxX9iI1QzI/1RvlpMqU+QIDFtVwJ77UdO0XvJC whof5OokBZX4wF9CnXOJilVIpV5+6Vm3nfMb9Dmn0iL21Ijq/oVFyOmGXToQ3b79uo +Px4uqo3N8WAbbkz+P6kLR1kTuGBpuT5r4SsJf1bH41QU76hfWLInxSyk8xNcNm5ss HbgM4IgDJY+Mr5i+VpNTJ3FnH/IQ+f10OD1v+xEPcU64+kY2ArVy3bmKZxvB7i6q4I k47oIEq2mQDF6WbGwAJZpWuAyBW/R5SZ9/+zn6LmcoBGl3Nm5hIALsSVer6hj82+ad 4rxYLEkan3pew== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1qxRV5-008vI6-5Z; Mon, 30 Oct 2023 12:36:11 +0000 Date: Mon, 30 Oct 2023 12:36:09 +0000 Message-ID: <86msw01e4m.wl-maz@kernel.org> From: Marc Zyngier To: Jan Henrik Weinstock Cc: oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Lukas =?UTF-8?B?SsO8bmdlcg==?= Subject: Re: KVM exit to userspace on WFI In-Reply-To: References: <87ttql5aq7.wl-maz@kernel.org> <86cyx250w9.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/29.1 (aarch64-unknown-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: jan@mwa.re, oliver.upton@linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, lukas@mwa.re X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-Spam-Status: No, score=-1.7 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 30 Oct 2023 05:36:25 -0700 (PDT) [please make an effort not to top-post] On Fri, 27 Oct 2023 18:41:44 +0100, Jan Henrik Weinstock wrote: > > Hi Marc, > > the basic idea behind this is to have a (single-threaded) execution loop, > something like this: > > vcpu-thread: vcpu-run | process-io-devices | vcpu-run | process-io... > ^ > WFX or timeout > > We switch to simulating IO devices whenever the vcpu is idle (wfi) or exceeds > a certain budget of instructions (counted via pmu). Our fallback currently is > to kick the vcpu out of its execution using a signal (via a timeout/alarm). But > of course, if the cpu is stuck at a wfi, we are wasting a lot of time. > > I understand that the proposed behavior is not desirable for most use cases, > which is why I suggest locking it behind a flag, e.g. > KVM_ARCH_FLAG_WFX_EXIT_TO_USER. But how do you reconcile the fact that exposing this to userspace breaks fundamental expectations that the guest has, such as getting its timer interrupts and directly injected LPIs? Implementing WFI in userspace breaks it. What about the case where we don't trap WFx and let the *guest* wait for an interrupt? Honestly, what you are describing seems to be a use model that doesn't fit KVM, which is a general purpose hypervisor, but more a simulation environment. Yes, the primitives are the same, but the plumbing is wildly different. *If* that's the stuff you're looking at, then I'm afraid you'll have to do it in different way, because what you are suggesting is fundamentally incompatible with the guarantees that KVM gives to guest and userspace. Because your KVM_ARCH_FLAG_WFX_EXIT_TO_USER is really a lie. It should really be named something more along the lines of KVM_ARCH_FLAG_WFX_EXIT_TO_USER_SOMETIME_AND_I_DONT_EVEN_KNOW_WHEN (probably with additional clauses related to breaking things). Overall, you are still asking for something that is not guaranteed at the architecture level, even less in KVM, and I'm not going to add support for something that can only work "sometime". M. -- Without deviation from the norm, progress is not possible.