Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp1326319rdh; Fri, 27 Oct 2023 10:42:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFSr9SsFrYut6RsKhvlK/LKoXcqzqt1AnAb/DkLPizyGtsj+SMrkRP2TUZiBIc6nwmkzlX7 X-Received: by 2002:a05:6808:4191:b0:3b2:e73a:16f7 with SMTP id dj17-20020a056808419100b003b2e73a16f7mr3149848oib.2.1698428532562; Fri, 27 Oct 2023 10:42:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698428532; cv=none; d=google.com; s=arc-20160816; b=lsgulnCAIt6YYNOyv7XbWbjqHZoQdLDCUDxompQ86hrKqnc+ckrOFPTa3kZ7VDrbk4 c57gMDpbVWNmvr1r3CCf9lg/YeZtnHMYyyTOI5SNP38ITd0rpkPAj8h+GuvsPY2RA2jV i4Bgu45uh43t941GDwiHzO63E1UP2s90b6axhyn6vIVCyGhQbc+JOV5YxfO/yE6pnSjr fLpK8BHb7kI4aoY5GgTuARq26+MtQeL/+a8AW4BOuo4gO90bt4HTiiCpLpaUgGO61wFN SQKD5IokIB3XaENhmmIufvnitAQDdMqbWcyCRNxSQNHW+fpATp/676xqgj04c4powWTd sTsg== 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=Zl9xOdOypts4WvQdyS7jVbRn41c2NCajV1vwM0e7soo=; fh=9APSbwIfkhYj7+YxIJSk+P9JqaksPcGIm0Qn+gRWANQ=; b=XnxX6Wy0CN7p6eslnkNmSk0Yb0wNE1PCY3bjz+N/le+1ttD/nYNdAMPq4rGEm7kPLu QAiykRx6GN1tRVm014ApdnIelVY0bxmA9nfzhq7tvtul+JPzJOzaNAZI4Shn8A5sOSnZ PboCEZQZ8LWB9HJsf9v7F3UxJ8ozYJT5jhYFPj9FZOz1bThg+mTJNyBS+2oTWnTCxh7O 4UnPRTqc94LEg9xqqsQ4SOrwFkMHcS3bAYZIlVTHUwLd9umS8ffOUXqUPzPUT5pVqLx1 ICfbKRazj+f7VzDvZsh2HacZ0WetnwyyuZ6aMjPKbH2+b0+dl5cjNEjsPpOmprGFTX/G 2Ulg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mwa.re header.s=google header.b=VQiSOs3K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id b200-20020a2534d1000000b00da034b5865esi3191758yba.187.2023.10.27.10.42.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 10:42:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@mwa.re header.s=google header.b=VQiSOs3K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 8412A83731AE; Fri, 27 Oct 2023 10:42:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232101AbjJ0RmB (ORCPT + 99 others); Fri, 27 Oct 2023 13:42:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232039AbjJ0RmA (ORCPT ); Fri, 27 Oct 2023 13:42:00 -0400 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B86011B for ; Fri, 27 Oct 2023 10:41:57 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-507d1cc0538so3227825e87.2 for ; Fri, 27 Oct 2023 10:41:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mwa.re; s=google; t=1698428515; x=1699033315; 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=Zl9xOdOypts4WvQdyS7jVbRn41c2NCajV1vwM0e7soo=; b=VQiSOs3KK/7bRSgdw8x7bA1ycXi85+TOCljMbaH7lsrBQV7e0hssFwRjumY3oslxXx EN6TU7ztcyyPz/ag6Npp8puj8/aWjYZMQOydT5jxkj7y8KOSmGpNAJoEpjvBB1g4l3C4 7Nf62CkUEicvpvBkaiBrPAm3QXrCN/aK7YXVXI1zYJqJqoGYjOKbwmOTYxPC0jnI77W5 xaXMgiJUyEFus+gJ35Byuihtu64V5+BuY8dyeedGJo+3FsVq6g5DqJyIELyKmQwObsOq pfDi+dRIsKKdr9zhEhknR09aULxbtSHIVpONSytyL3O2R07OESa1DOpUpuy0QFPE3cPI bsKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698428515; x=1699033315; 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=Zl9xOdOypts4WvQdyS7jVbRn41c2NCajV1vwM0e7soo=; b=GjMbtA0kyyl0Kq/o/Su/ZXkToqJWubdy283OXLYkymEQpi/oZEMa86VUQJFR2j2VxI 9AQys15s+wUS74igjp9emr5nlfst7v8xvQNbiuUB3Uu0RVpmnKc9A1+N5frKWKCmMm73 NZ8Vt4IZafa9IBmBn+xTxtlkUxpYyG/pnfrhqRNzB6CTtBwGRTbi0cc8rJ+SnCg67gxe sj6S3gpKHhKca44nRwkyQGqOJSiFVMRyv7DtsWd+mZNMxV8N6d+tJe3fHdl2h6/j3fmQ WaeZPAhYR63hdqh1ztJ2qSpP9ZL/CvG31zPoHRJ/AbBHULk0EQcY+DeHwLDdf0P0Eyof SEwQ== X-Gm-Message-State: AOJu0YzKSZW6uufZ1XDbQhRMyZT/adEgZY2Ydn9zyzM5DSI42Ntroa35 f2/htmIiRnCgrjE7k44jMloz58DHHXa2a+A4twhHqORcY6ci63Ch5O6iJ00lxM0= X-Received: by 2002:a05:6512:282c:b0:508:2022:7738 with SMTP id cf44-20020a056512282c00b0050820227738mr2385452lfb.19.1698428515297; Fri, 27 Oct 2023 10:41:55 -0700 (PDT) MIME-Version: 1.0 References: <87ttql5aq7.wl-maz@kernel.org> <86cyx250w9.wl-maz@kernel.org> In-Reply-To: <86cyx250w9.wl-maz@kernel.org> From: Jan Henrik Weinstock Date: Fri, 27 Oct 2023 19:41:44 +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 howler.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 (howler.vger.email [0.0.0.0]); Fri, 27 Oct 2023 10:42:09 -0700 (PDT) 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 excee= ds 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. Am Mi., 25. Okt. 2023 um 14:42 Uhr schrieb Marc Zyngier : > > On Wed, 25 Oct 2023 13:12:14 +0100, > Jan Henrik Weinstock wrote: > > > > 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. > > Why would that be an acceptable behaviour? > > > 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. > > Why? If that's not acceptable, how do you even cope with the basic > preemption? > > > 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. > > On the face of it, this makes little sense: > > - While in userspace, no interrupt source that normally delivered > without any userpsace intervention will be blocked (timers, > VLPIs...). I cannot how this can be a good idea. > > - Trapping WFE is an important scheduling hint, and returning to > userspace defeats it. Contended spinlocks, for example, will be even > slower to acquire. > > I'm sure you have a particular use case for such a degraded behaviour, > but since you are not describing it, I'm not at all inclined to > actively break KVM's performance and scalability. > > 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