Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp6859365rwb; Wed, 10 Aug 2022 02:22:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR4SN4bK/STlBGJmzwESOpLGJg1fHsCK6D6E3P4TziPtIObHU+e+SNSrGHXnbUMx0jEua+BI X-Received: by 2002:a17:906:6a0a:b0:731:4a2b:a1b1 with SMTP id qw10-20020a1709066a0a00b007314a2ba1b1mr10684392ejc.544.1660123321608; Wed, 10 Aug 2022 02:22:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660123321; cv=none; d=google.com; s=arc-20160816; b=S6vW0E+0yfgAQGvxiWJQj4kDvlQcn4CMJm3XnnF0GM/RlULUaiGgtx6obe21tuTiJ0 tQo/asVt66u7z0W7Kaz8zoG/c5xtOCriqV/xzwDTYIdPIfmP5XIkdyh3L8ogCTD/i4Mz sCG8JsNmbR8tAzSqk71znPN6AKtDbjzKxuUQRhz2NMQBT8EUX1uU0WfEUIfSbUSWM9rN RdJQo+cazs03GSYa49sWSWoah1KKR2Z3xKA1aoaJLmOHYhbXy1Rui8b9iwt9CLTEigvW NgW4ipuOLnBC+YtGKVae6ujbDgj4QrCVZQlwB1tyXPqQDiOiSVSQ3RmSaeXHxuqW0dVg /NHg== 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=HlOmZJYvc+TNbCeCwHEbq4+dxx08Rt6LMedV+rOqZKA=; b=DH8zEIuaaHN/pqjkV+vzsI2eHyzv6Y8BsQ5McmTs5XQViDK0Mnxg8cTj0KYQ4A+RVX J/AhlwUSlabnZnZ6v69rXUQzc+et//X/FsfhDSByxlh1Vd6LUsr5jagc70q6j/riKcz4 OyjeUnAyybFDfLCJ0lMR2B8DFXVBpxj2eLM10ujnMD66m/GEiCrFyChncGR80vGHFRxi +M4j16C05/4IG3pWLhRKxVEv+KMXgeTLUZDG49h+RySUeGtysjDzJhZNdmR8uXWpj9Nb kwOed75vDunhrfxKR5sdLarMz2EICbMPh3u4SaASNt6k4otBVSqVIjUhp46napHqq8aq 2h3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=n222h+Xw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m12-20020a056402510c00b0043bb87a322csi13164024edd.52.2022.08.10.02.21.36; Wed, 10 Aug 2022 02:22:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=n222h+Xw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S231765AbiHJIlf (ORCPT + 99 others); Wed, 10 Aug 2022 04:41:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231791AbiHJIlP (ORCPT ); Wed, 10 Aug 2022 04:41:15 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B200A5FADF; Wed, 10 Aug 2022 01:41:13 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 117E260F2F; Wed, 10 Aug 2022 08:41:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 671A9C433D6; Wed, 10 Aug 2022 08:41:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660120872; bh=W+5o4r15y/YZOMNcS6zt9psCyFTlTq1LiJF1ngryy9A=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=n222h+XwRK28pcXwKMTejItjWNIhfdJF4v4oQ68ChMut2KZ2ek8ntZJZtXUNNceNW 60cmbWLmjDFZYqbsj67G9f9oz9y6k8d2sFngcHo9HETmFNJ4Wn7jAXv3/tmV9dOqQ6 gOM9idD/tfYzyJftuRzBeGDr+XgaHM6wSk3lQ+5nbTi3+TEb4UUNsifolRvJ3aCeYP 5ZQ106rYfnlffPsl0oMgkKIg0hURsRiZo2r4KcCmt8F2ZlmOvIp5EEBtp3mTQzm+K8 YZBDvVDYyoDrXJXiImHtVkQ/85oeExgjgp8prerilhThxfgSEzvvtkrUHj2QtURbMM lWIp7H1ogPpPg== Received: from [104.132.45.97] (helo=wait-a-minute.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 1oLhH3-0025Xw-Vx; Wed, 10 Aug 2022 09:41:10 +0100 Date: Wed, 10 Aug 2022 09:41:07 +0100 Message-ID: <87mtccbie4.wl-maz@kernel.org> From: Marc Zyngier To: eric.auger@redhat.com, Dmytro Maluka Cc: Sean Christopherson , Paolo Bonzini , kvm@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org, Alex Williamson , Rong L Liu , Zhenyu Wang , Tomasz Nowicki , Grzegorz Jaszczyk , upstream@semihalf.com, Dmitry Torokhov Subject: Re: [PATCH v2 3/5] KVM: irqfd: Postpone resamplefd notify for oneshot interrupts In-Reply-To: <56ab2bc2-378b-3ece-2d45-e0f484087aa7@redhat.com> References: <20220805193919.1470653-1-dmy@semihalf.com> <20220805193919.1470653-4-dmy@semihalf.com> <56ab2bc2-378b-3ece-2d45-e0f484087aa7@redhat.com> 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: 104.132.45.97 X-SA-Exim-Rcpt-To: eric.auger@redhat.com, dmy@semihalf.com, seanjc@google.com, pbonzini@redhat.com, kvm@vger.kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, linux-kernel@vger.kernel.org, alex.williamson@redhat.com, rong.l.liu@intel.com, zhenyuw@linux.intel.com, tn@semihalf.com, jaz@semihalf.com, upstream@semihalf.com, dtor@google.com 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=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 09 Aug 2022 21:45:25 +0100, Eric Auger wrote: > > Hi Dmytro, > > On 8/5/22 21:39, Dmytro Maluka wrote: > > The existing KVM mechanism for forwarding of level-triggered interrupts > > using resample eventfd doesn't work quite correctly in the case of > > interrupts that are handled in a Linux guest as oneshot interrupts > > (IRQF_ONESHOT). Such an interrupt is acked to the device in its > > threaded irq handler, i.e. later than it is acked to the interrupt > > controller (EOI at the end of hardirq), not earlier. > > > > Linux keeps such interrupt masked until its threaded handler finishes, > > to prevent the EOI from re-asserting an unacknowledged interrupt. > > However, with KVM + vfio (or whatever is listening on the resamplefd) > > we don't check that the interrupt is still masked in the guest at the > > moment of EOI. Resamplefd is notified regardless, so vfio prematurely > > unmasks the host physical IRQ, thus a new (unwanted) physical interrupt > > is generated in the host and queued for injection to the guest. > > > > The fact that the virtual IRQ is still masked doesn't prevent this new > > physical IRQ from being propagated to the guest, because: > > > > 1. It is not guaranteed that the vIRQ will remain masked by the time > > when vfio signals the trigger eventfd. > > 2. KVM marks this IRQ as pending (e.g. setting its bit in the virtual > > IRR register of IOAPIC on x86), so after the vIRQ is unmasked, this > > new pending interrupt is injected by KVM to the guest anyway. > > > > There are observed at least 2 user-visible issues caused by those > > extra erroneous pending interrupts for oneshot irq in the guest: > > > > 1. System suspend aborted due to a pending wakeup interrupt from > > ChromeOS EC (drivers/platform/chrome/cros_ec.c). > > 2. Annoying "invalid report id data" errors from ELAN0000 touchpad > > (drivers/input/mouse/elan_i2c_core.c), flooding the guest dmesg > > every time the touchpad is touched. > > > > This patch fixes the issue on x86 by checking if the interrupt is > > unmasked when we receive irq ack (EOI) and, in case if it's masked, > > postponing resamplefd notify until the guest unmasks it. > > > > It doesn't fix the issue for other archs yet, since it relies on KVM > > irq mask notifiers functionality which currently works only on x86. > > On other archs we can register mask notifiers but they are never called. > > So on other archs resampler->masked is always false, so the behavior is > > the same as before this patch. The core issue seems that you would like to be able to retire a interrupt from what has been queued into the guest by a previous resampling (because the line has effectively dropped in the meantime). On arm64, it would be easy enough to sample the pending state of the physical line and adjust the state of the virtual interrupt accordingly. This would at least have the advantage of preserving the illusion of an interrupt being directly routed to the guest and its pending state being preserved between EOI and unmask. It isn't perfect either though as, assuming the guest can ack the interrupt on the device without exiting, the line would still appear as pending until the next exit, possibly the unmask. M. -- Without deviation from the norm, progress is not possible.