Received: by 2002:a05:6359:322:b0:b3:69d0:12d8 with SMTP id ef34csp450002rwb; Wed, 10 Aug 2022 10:49:55 -0700 (PDT) X-Google-Smtp-Source: AA6agR7cTLtZEsjFdEXM7z2FqTbRreebkGSXcRCXTpU62tpDP4SKJg/YYRRTRXik1uUXps2eHLjf X-Received: by 2002:a05:6a00:cc7:b0:52f:2ada:11c5 with SMTP id b7-20020a056a000cc700b0052f2ada11c5mr16274237pfv.19.1660153794884; Wed, 10 Aug 2022 10:49:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660153794; cv=none; d=google.com; s=arc-20160816; b=faD+r8Ele+7lJYhJ6yh9quiRK/Qh+7MhAqH9pZUCmcp6vkPpcmc9VpZ7w6WxWO4rcD +SKOQBMcDyGh93iJ7Zy30GEzGjbzzn2VDwHr08ZqQADHZOzq2N9WFfyh8xYU+sfhNoEW OFPYfrc99gk2Oh+Uh5DT8Wte99NrDu1Ez20WX6s+HIg1INhMJWGPfIKCJJ1tim4yN0Q/ ni26WbRN6PTkxCPB/fgaDkXrmD87RBAI6gZ+/Sjj/2ol4TLu172PQM9wUfoxZZG6vUV5 SD8I0TuumUE0gxaBIcaEByB2ABAxREEA7/MSKJJTDMkw43StHDg4t9t6JnkWHXCwgqQz uq/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=SspRo8j3eYOak2Or93Ie6jAhlC0rna8TGwHIKsAIEiQ=; b=lrOXJw630tWnv8njzVYXJpBwfyw/62bHJXaKvZ/04MDF4iaToFSpAgffcZ9f1pZ9pV R4dWToASpaZSIG8/mLgO8k9KN9dXCTle2/lf3y6HCiKFMsxLDzCN3zSDXTvuWKyohrRa 3Xgs8AOi7+5y9BtXEm95GhFw5mCZmG1e1Nq/rNBulEm273OYYUdmtzNb1mBJ6zjS6Xet uyM2/rzUcXEKDYNRACkEk7FFGbsTEX70VAMDDP6HmU2FJs/oed+64crtBKw1l6/LGUYA kbUinEpEuLe2bQLuau7UklfFOmf+3HvOlJobfgiW+zn7jFyJsxJYTwTPAuTjuXX7I+OF HwWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@semihalf.com header.s=google header.b=lOhgyb0o; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=semihalf.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r26-20020a639b1a000000b0041c2c6ad5fesi17015594pgd.376.2022.08.10.10.49.41; Wed, 10 Aug 2022 10:49:54 -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=@semihalf.com header.s=google header.b=lOhgyb0o; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=semihalf.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232428AbiHJRe3 (ORCPT + 99 others); Wed, 10 Aug 2022 13:34:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231750AbiHJRe1 (ORCPT ); Wed, 10 Aug 2022 13:34:27 -0400 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E674082F8E for ; Wed, 10 Aug 2022 10:34:25 -0700 (PDT) Received: by mail-lj1-x229.google.com with SMTP id l21so5339412ljj.2 for ; Wed, 10 Aug 2022 10:34:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:from:references:cc:to:subject:from:to:cc; bh=SspRo8j3eYOak2Or93Ie6jAhlC0rna8TGwHIKsAIEiQ=; b=lOhgyb0o5yEA35AJoSIfAzLAbl2zzGS5GqFCmePaZtF00tBUKojZx+pF8rDF6OHEWM PQ7gg7OQs3rtxsU3sytaJiOc5vFd22H9A4BlRzffRgAtrDwuyP3A/jwTtrIWiBQlTi+f 28IY2k6x2rmh32fTZzN6CEMqMp2YzhApGRopKs+Y0FbYuZIWU1eRTsdKfMSs7eCWJ4Af o3YPZop0rvEG3FHRMP11YxfVsirNEXJT/rSPMPJnQZiCYYtzu4dATqRCJhxzM3qhhTVa 68qkF0xz4owQtcJH1YpimeS/PgQvjR8foTRt1SZ5PDUwDS/8wDwZ8kYA9EqYd2lZO4nX oA7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:from:references:cc:to:subject :x-gm-message-state:from:to:cc; bh=SspRo8j3eYOak2Or93Ie6jAhlC0rna8TGwHIKsAIEiQ=; b=p20JWjg9DKimvEZEqnh/c5DVT0enCUPLwNVcffCUV03j06YX8QPh3jsc5xqe8+e1rI I8VevVG79+FHpb5lo6UJ1Z7LX+ha6FkGAmtW5ByPHdUJ3EnBLvXjf1zyvDJm3iWQ/uO3 v0atD9cVioI3HhxeJteIGDtHtIY8bVvMlecVN8j6sCBQ0/nilc9FerPxd/9OXJeNnkMS cvHmgS7Nj4ddUVwRiHwAjSOYJVU0FSH2frDb7BPjX+ik6cm/PJQXIRJadYCyTQRVfATu 3tfdSPgSCYjJAWUaDIa0G4PzNhtmq2F+jXoe8dDLtugBbbaBlWiK3o4Pa2YjUiRoxgTZ sBxA== X-Gm-Message-State: ACgBeo3OLuz0BcgdApDElMYHF6Ij8CE+FaW9qYylRJb1EcbeJ3qb7yuS ry40ofIDwJ6xZc0y3xY0jkUCKw== X-Received: by 2002:a05:651c:446:b0:25e:5629:213b with SMTP id g6-20020a05651c044600b0025e5629213bmr8665148ljg.53.1660152862760; Wed, 10 Aug 2022 10:34:22 -0700 (PDT) Received: from ?IPv6:2a02:a31b:33d:9c00:463a:87e3:44fc:2b2f? ([2a02:a31b:33d:9c00:463a:87e3:44fc:2b2f]) by smtp.gmail.com with ESMTPSA id h2-20020ac25962000000b0048b0aa2f87csm407376lfp.181.2022.08.10.10.34.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 10 Aug 2022 10:34:22 -0700 (PDT) Subject: Re: [PATCH v2 0/5] KVM: Fix oneshot interrupts forwarding 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 , Marc Zyngier References: <20220805193919.1470653-1-dmy@semihalf.com> From: Dmytro Maluka Message-ID: Date: Wed, 10 Aug 2022 19:34:20 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 8/10/22 7:17 PM, Dong, Eddie wrote: >>> >>> >>>> 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." >>>> >>> >>> Emulation of level triggered IRQ is a pain point ☹ I read we need to >>> emulate the "level" of the IRQ pin (connecting from device to IRQchip, i.e. >> ioapic here). >>> Technically, the guest can change the polarity of vIOAPIC, which will >>> lead to a new virtual IRQ even w/o host side interrupt. >> >> Thanks, interesting point. Do you mean that this behavior (a new vIRQ as a >> result of polarity change) may already happen with the existing KVM code? >> >> It doesn't seem so to me. AFAICT, KVM completely ignores the vIOAPIC polarity >> bit, in particular it doesn't handle change of the polarity by the guest (i.e. >> doesn't update the virtual IRR register, and so on), so it shouldn't result in a >> new interrupt. > > Correct, KVM doesn't handle polarity now. Probably because unlikely the commercial OSes > will change polarity. > >> >> Since commit 100943c54e09 ("kvm: x86: ignore ioapic polarity") there seems to >> be an assumption that KVM interpretes the IRQ level value as active (asserted) >> vs inactive (deasserted) rather than high vs low, i.e. > > Asserted/deasserted vs. high/low is same to me, though asserted/deasserted hints more for event rather than state. > >> the polarity doesn't matter to KVM. >> >> So, since both sides (KVM emulating the IOAPIC, and vfio/whatever emulating >> an external interrupt source) seem to operate on a level of abstraction of >> "asserted" vs "de-asserted" interrupt state regardless of the polarity, and that >> seems not a bug but a feature, it seems that we don't need to emulate the IRQ >> level as such. Or am I missing something? > > YES, I know current KVM doesn't handle it. Whether we should support it is another story which I cannot speak for. > Paolo and Alex are the right person ???? > The reason I mention this is because the complexity to adding a pending event vs. supporting a interrupt pin state is same. > I am wondering if we need to revisit it or not. Behavior closing to real hardware helps us to avoid potential issues IMO, but I am fine to either choice. I guess that would imply revisiting KVM irqfd interface, since its design is based rather on events than states, even for level-triggered interrupts: - trigger event (from vfio to KVM) to assert an IRQ - resample event (from KVM to vfio) to de-assert an IRQ > >> >> OTOH, I guess this means that the existing KVM's emulation of level-triggered >> interrupts is somewhat limited (a guest may legitimately expect an interrupt >> fired as a result of polarity change, and that case is not supported by KVM). But >> that is rather out of scope of the oneshot interrupts issue addressed by this >> patchset. > > Agree. > I didn't know any commercial OSes change polarity either. But I know Xen hypervisor uses polarity under certain condition. > One day, we may see the issue when running Xen as a L1 hypervisor. But this is not the current worry. > > >> >>> "pending" field of kvm_kernel_irqfd_resampler in patch 3 means more an >> event rather than an interrupt level. > > I know. I am fine either. > > Thanks Eddie > >>> >>>