Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp6771994rwb; Wed, 10 Aug 2022 00:22:26 -0700 (PDT) X-Google-Smtp-Source: AA6agR57tvWpKYgDUBdv+WJ7DAJAE90cqfP2TJuftrEWPZIcN6ZxF5neBu5qsvxJVYrv7eVna5SP X-Received: by 2002:a65:6697:0:b0:41c:9d44:6cb6 with SMTP id b23-20020a656697000000b0041c9d446cb6mr22727837pgw.471.1660116145929; Wed, 10 Aug 2022 00:22:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660116145; cv=none; d=google.com; s=arc-20160816; b=xU5T4ldW80fVZINs1x5zY2UuhZIV5LPPYaLOovC5U5ynIuWDoiIV9RnA4/ehIWluHu uSRfFxVbRI1yys9Ak4bQ4i9s2o+8A4oYJ0XDMe2NZeYuQOIADzPz+9NCz7R8TDOw+UkD fNanxD1vK0iHQ/2iTg7wtbVQOFnOVA2zORWiFBtELPRVgLOdB6DIxE7LtIZvWVqoMYCy QSjMp2cIRQua5S+RXjoxxdCJOtRUHxZwBHgsNRUD7s410IuTMbDH5fOiGQrOV2J5lw6y JUkI3ckEoOe9UEGliSOB3A6jh2q8qNG6qeGSnuQ6PljPiokPogw91EHWxTgz8nC9OTiX y3eg== 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=4b2v0NBYNs9qaaqxgZD6Ogc4H6NN4/4D8+mFYZGQgj4=; b=iPW4emqWI76uvixpkk/EWkUpem9t1v9k94xMUYIne/ahkArV7+SlHodit71BxEXaxS atheOlywwc71JVoKOlAMn7QeVZRl9FW9nHBE3/G/86+nIiSf72cWE2jyC5Y8GruPA1nj 3oKVIWlnHi+TDZRFQ0QxaWULUbN8rsm824JiKSC27s9dNuxF2GhFt3sZj7zb1lNw0evJ S8E8gDsB5Bb/XvOTF4E8k63Y1CIm2Smj/4FfRkQxAmIaBl2dxw2LAfgRBZYbp/xLrrFB x+E6RwXE5MieU9bP4R3lyCu/DTocOp7o1sGe3Dd/WbP2gNGVuR4O5ocaPZYCGgHcmtJz DoMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=m1ftmx62; 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 nv5-20020a17090b1b4500b001f2bbd3bf8bsi1276418pjb.178.2022.08.10.00.22.12; Wed, 10 Aug 2022 00:22:25 -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=m1ftmx62; 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 S230525AbiHJGvn (ORCPT + 99 others); Wed, 10 Aug 2022 02:51:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229475AbiHJGvm (ORCPT ); Wed, 10 Aug 2022 02:51:42 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADC0171BD7; Tue, 9 Aug 2022 23:51:40 -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 ams.source.kernel.org (Postfix) with ESMTPS id 54603B81AE6; Wed, 10 Aug 2022 06:51:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0EE0CC433D6; Wed, 10 Aug 2022 06:51:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660114298; bh=ahGwuAXwFB0kVpDwl1Y5QMjaxY0VAa6qcPz8jo98lIE=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=m1ftmx62OGBQQmdEb6o+nyAu7gFB4JAfHm56Ki/zP1RKC9oYM8J2yq92YFlfE56iZ T0FB389el0kFaEqL7QVnE4LXCA/uKqL6qtdfH3L1l+zgdXvq0E9SvyQ2Pn0GwLbX1R IMmdf7zr3AulKgyCjldeSx8mNd1xqH1c9fzThLRGAGW5WHJ6L1JTbSYGnHEgXsmYoh tc0vcch8qKebPkbsxJnhKxbYplgNBqalAYI0gTwD0jwA8bXmNV6lD/0DL9NIk1onOb M+xlMN1v0QvjDhIl1viQJCYbqblmlKVGYdQWvbdsgbYnIfGK0SMHixU8i5xG8bYv1S K9hVJOj4Jmyag== Received: from ip-185-104-136-29.ptr.icomera.net ([185.104.136.29] 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 1oLfZ0-0024Yo-Rg; Wed, 10 Aug 2022 07:51:35 +0100 Date: Wed, 10 Aug 2022 07:51:24 +0100 Message-ID: <87o7wsbngz.wl-maz@kernel.org> From: Marc Zyngier To: Dmytro Maluka Cc: "Dong, Eddie" , "Christopherson,, Sean" , 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" , Eric Auger , Alex Williamson , "Liu, Rong L" , Zhenyu Wang , Tomasz Nowicki , Grzegorz Jaszczyk , "upstream@semihalf.com" , Dmitry Torokhov Subject: Re: [PATCH v2 0/5] KVM: Fix oneshot interrupts forwarding In-Reply-To: References: <20220805193919.1470653-1-dmy@semihalf.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: 185.104.136.29 X-SA-Exim-Rcpt-To: dmy@semihalf.com, eddie.dong@intel.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, eric.auger@redhat.com, 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 Wed, 10 Aug 2022 00:30:29 +0100, Dmytro Maluka wrote: > > On 8/9/22 10:01 PM, Dong, Eddie wrote: > > > > > >> -----Original Message----- > >> From: Dmytro Maluka > >> Sent: Tuesday, August 9, 2022 12:24 AM > >> To: Dong, Eddie ; Christopherson,, Sean > >> ; Paolo Bonzini ; > >> kvm@vger.kernel.org > >> Cc: Thomas Gleixner ; Ingo Molnar ; > >> Borislav Petkov ; Dave Hansen ; > >> x86@kernel.org; H. Peter Anvin ; linux- > >> kernel@vger.kernel.org; Eric Auger ; Alex > >> Williamson ; Liu, Rong L ; > >> Zhenyu Wang ; Tomasz Nowicki > >> ; Grzegorz Jaszczyk ; > >> upstream@semihalf.com; Dmitry Torokhov > >> Subject: Re: [PATCH v2 0/5] KVM: Fix oneshot interrupts forwarding > >> > >> On 8/9/22 1:26 AM, Dong, Eddie 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. The > >>>> existing KVM code doesn't take that into account, which results in > >>>> erroneous extra interrupts in the guest caused by premature re-assert of an > >> unacknowledged IRQ by the host. > >>> > >>> Interesting... How it behaviors in native side? > >> > >> In native it behaves correctly, since Linux masks such a oneshot interrupt at the > >> beginning of hardirq, so that the EOI at the end of hardirq doesn't result in its > >> immediate re-assert, and then unmasks it later, after its threaded irq handler > >> completes. > >> > >> In handle_fasteoi_irq(): > >> > >> if (desc->istate & IRQS_ONESHOT) > >> mask_irq(desc); > >> > >> handle_irq_event(desc); > >> > >> cond_unmask_eoi_irq(desc, chip); > >> > >> > >> and later in unmask_threaded_irq(): > >> > >> unmask_irq(desc); > >> > >> I also mentioned that in patch #3 description: > >> "Linux keeps such interrupt masked until its threaded handler finishes, to > >> prevent the EOI from re-asserting an unacknowledged interrupt. > > > > That makes sense. Can you include the full story in cover letter too? > > Ok, I will. > > > > > > >> 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." Sorry to barge in pretty late in the conversation (just been Cc'd on this), but why shouldn't the resamplefd be notified? If there has been an EOI, a new level must be made visible to the guest interrupt controller, no matter what the state of the interrupt masking is. Whether this new level is actually *presented* to a vCPU is another matter entirely, and is arguably a problem for the interrupt controller emulation. For example on arm64, we expect to be able to read the pending state of an interrupt from the guest irrespective of the masking state of that interrupt. Any change to the interrupt flow should preserve this. Thankfully, we don't have the polarity issue (there is no such thing in the GIC architecture) and we only deal with pending/not-pending. Thanks, M. -- Without deviation from the norm, progress is not possible.