Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2513698rda; Wed, 25 Oct 2023 05:12:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEdlWihjq9f1bhqT3WXuIUNSVgkj/8nv2jBepJIBudI9hvw+XMVKUbic1viNToi9KM5EB+h X-Received: by 2002:a05:6870:5ccd:b0:1d5:d8f0:7d7e with SMTP id et13-20020a0568705ccd00b001d5d8f07d7emr21162964oab.53.1698235967611; Wed, 25 Oct 2023 05:12:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698235967; cv=none; d=google.com; s=arc-20160816; b=qTbUz+CCpIvPqi3mOi4dJ8BP/T6h2qPiKzzEw+JkkW0LcDEjoBip89/rnORR7N6b8o 5l63g7YBxbbbHA9gl0HW0YXJJrSyESEdNaYC67DbCb/YzUqq9IsjysFVCIwlOHyhg8zQ TXd/uXJek2xAkS9Rn6y+VaEjtDdu8zZ0XBaaKXq7VkvII2dQJxqWpVqeSmpAQdLaRHVd zGO6Yg28jq8kM5eQSLxBPOAkk/R3xR+4/NjFpJTmRIiCHecZ2oy9/9cA0l50USoObkQn p8I/Em89bKEN/98iz11ioOz8mGDQaoXU0VIliOT00I7+Kxy4DJ4CiSLGD4hgoSbkdVX6 okww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=bmQirNixdBVLhzipjmpOh2DK+B144w1ZHT/Th2x89pQ=; fh=9APSbwIfkhYj7+YxIJSk+P9JqaksPcGIm0Qn+gRWANQ=; b=c13B2xsEh641xfnrOTYZBwpb/YbPjkOtisOtq7HindAFq2GZXvsN4d+o+3LmONX4Xf FEa3LDjcIdAwWTBdqDBOAY8/qTARwRd3mUxR5TO2B+XOpkg263vPMcTmXuq3MrKNJ2lw H1Hxq8qemmOtvxjstpKx51n77wf5tZmCtHY+x6a6X0bx3QAXFAx9iYs7BBlUwCAYHasP 3jRQO9OnBHOXXk0b4WSTXi2xMDU64rgLTzr4D5Ui/zx25zVsE/kD54ceIvJCVsUaS5Bf 06CeEFy9abj15XMzMsDXH4og4upax46hWVaSRiMTazwSkLc6gxIh7CVkL93l4PA+tbW1 K4mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mwa.re header.s=google header.b=AxEvfFUL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=mwa.re Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id s125-20020a257783000000b00da061c954b2si2863726ybc.99.2023.10.25.05.12.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 05:12:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@mwa.re header.s=google header.b=AxEvfFUL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=mwa.re Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 59549809B738; Wed, 25 Oct 2023 05:12:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234757AbjJYMMc (ORCPT + 99 others); Wed, 25 Oct 2023 08:12:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234803AbjJYMMb (ORCPT ); Wed, 25 Oct 2023 08:12:31 -0400 Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A192218C for ; Wed, 25 Oct 2023 05:12:27 -0700 (PDT) Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2c5087d19a6so82638261fa.0 for ; Wed, 25 Oct 2023 05:12:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mwa.re; s=google; t=1698235946; x=1698840746; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=bmQirNixdBVLhzipjmpOh2DK+B144w1ZHT/Th2x89pQ=; b=AxEvfFUL/0usdcOCkF6SNtQ7QRY39pD1tW5LkM3jP6gAvdZSOV7tcrzx48LKRt7ki6 Ljav4p+LUtYY6AmBE8mlo1zW3HLsAKe30faAP3ORgimJ4vISI1IzhZCpMNDg3u8sKyCv 9ky1wqLq9XwymHarMu66PMQmfh+FmVjFvT4Qt0OR5wC1rS8R7fmmQpdM1nSn4my5kT53 tJPoI7v6DTpdRcuICtFijaJvAKFMEsPd5JMyuM8Gj1+wWNf4x9MxBdPdy7hShTAvUVIC shT7pUxE/svCDMdGfwlEzezvhpAyyni2o5wm9/MxYVUSCeL73kL3GqLk5SCvoZJFJx3m LqYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698235946; x=1698840746; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bmQirNixdBVLhzipjmpOh2DK+B144w1ZHT/Th2x89pQ=; b=DIwOaEL0/HU1waxoeUP45MiSaesu69a91WLO0FGd5u+agN7lnYtSf6dmWgKX+I1RjT dHvgHWRuTOuBPcMHPKtWGxx+TFnn9VlS/nz91gU6XL0S1R/rIbZ8EeifzDby/jLWnzWh V0aWU9Gj2g7Kfj17H0SiWs95JI2OCuSZDlRO6QxcFOmQAaFok+x8ZzsUCEYWEdWtfTCp R2P/spWfxokfbjO8Sy1DkhvHiD9OnhF1WChY4DWK2SD6aLq3ToxcD9uG0WqmVaIKtBoa L0C6z25MScj7M6gjuy/zUw5HPSxArmWSzf2F5fKNrSen1Ea/PPCWiPM75+BY3IP2PbT+ 3Sog== X-Gm-Message-State: AOJu0Yz9rb4v0JPCCae90a0zMDS10Wixg9EaGpvU6gR85U9XH1yF/Qeg C/6xGtmwrvC7NdYOz0lISyxxbw/SYLsTDhhz2wfGWA== X-Received: by 2002:a2e:b911:0:b0:2c5:2132:24f5 with SMTP id b17-20020a2eb911000000b002c5213224f5mr9609306ljb.53.1698235945658; Wed, 25 Oct 2023 05:12:25 -0700 (PDT) MIME-Version: 1.0 References: <87ttql5aq7.wl-maz@kernel.org> In-Reply-To: <87ttql5aq7.wl-maz@kernel.org> From: Jan Henrik Weinstock Date: Wed, 25 Oct 2023 14:12:14 +0200 Message-ID: Subject: Re: KVM exit to userspace on WFI To: Marc Zyngier 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, =?UTF-8?Q?Lukas_J=C3=BCnger?= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Wed, 25 Oct 2023 05:12:44 -0700 (PDT) Hi Marc, Thanks for your feedback. I understand that request_interrupt_window is not to be used. I assume a setting a flag is a better way, something similar to KVM_ARCH_FLAG_RETURN_NISV_IO_ABORT_TO_USER, e.g. KVM_ARCH_FLAG_WFX_EXIT_TO_USER. I will also check that WFx traps are always enabled while this mode is active to make sure userspace does not get blocked/scheduled out. The reason for this is that we cannot have the thread that executes KVM_RUN to be blocked or scheduled out whenever it hits a WFI. Nop-WFIs are not a problem, since the PE will just continue executing instructions, which is fine. We are currently using a timeout signal that kicks KVM_RUN back into userspace, but we are seeing a lot of time wasted because our KVM thread hangs in WFI/WFEs. It would be better if we could just return from KVM_RUN immediately if the thread would otherwise be blocked. Thanks Jan Am Fr., 20. Okt. 2023 um 21:56 Uhr schrieb Marc Zyngier : > > Hi Jan, > > On Fri, 20 Oct 2023 19:45:05 +0100, > Jan Henrik Weinstock wrote: > > > > Hi all, > > > > I am looking for a way to have KVM_RUN exit back to userspace once the > > vcpu encounters a WFI. It seems the kvm_run->request_interrupt_window > > flag is currently ignored by arm64. > > Well, that's consistent with arm64 not being an x86 implementation. We > can inject interrupts any time, and there is no notion of "interrupt > window". > > > So my solution thus far is to > > patch kvm_handle_wfx in arch/arm64/kvm/handle_exit.c and return to > > userspace with KVM_EXIT_IRQ_WINDOW_OPEN - working example attached. > > Any chance to get this (or something similar) mainline? > > Certainly not as such. For start, this won't hit all WFIs, but only > those that actively trap. And we don't even *try* to trap WFx in a > number of cases (vcpu alone in its run queue and/or direct injection). > There isn't even any guarantee that WFx is anything other than a NOP > (it is architecturally only a hint), in which case no trap applies. > > So your "working example" really isn't one, as the architecture > doesn't give you a way to do what you're asking for. If you want to > cause an exit, writing to 'immediate_exit' and delivering a signal is > the way. > > Thanks, > > M. > > -- > Without deviation from the norm, progress is not possible. --=20 Dr.-Ing. Jan Henrik Weinstock Managing Director MachineWare GmbH | www.machineware.de H=C3=BChnermarkt 19, 52062 Aachen, Germany Amtsgericht Aachen HRB25734 Gesch=C3=A4ftsf=C3=BChrung Lukas J=C3=BCnger Dr.-Ing. Jan Henrik Weinstock