Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp587287imw; Fri, 15 Jul 2022 09:03:13 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vQVaxQzVDAlB+v3dLZprrumOr7sgbS/P7ksPPsz4Y5vWm8OtHILp4iAicOG9Bn+oRzCetG X-Received: by 2002:a0c:f284:0:b0:472:fb3c:fa4b with SMTP id k4-20020a0cf284000000b00472fb3cfa4bmr12546706qvl.76.1657900993181; Fri, 15 Jul 2022 09:03:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657900993; cv=none; d=google.com; s=arc-20160816; b=xRDGIM2YKHPe7dCLa3aBEYC1U1IRUpHAPcOO+1D22NGkfQKJygYrD8O0zMbu9gfGme Veajx1dvZscFe9l5nQN2P64Nqdp/XT5xxoh+uavcdp2+iDap6XO+MmnoLSUCPY98IbSc t4PrQCkVIfGt3r5OBXnMGMZ+qdn280n6pHew4+vfss15o4ioUfckajlskHu0V2HFW1x4 sswi55rsEfNtVNf+4MJ7noLVQ+qp8z3aDBkOPHIz38/vxgRPr6DC93WXkvYbXBtL9M6M 65EM27CfofK+hrtUT5vBsRrpjvhkp9vLZxRuETLnsLC6XpsMT2OeY4NgA6fEZX1iZOYd JvLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=mIopSGAH3mTa/L5EYVPega0Li+O294uXD/7Fiv3FbZo=; b=VMPJyPbCIx3gBZCQv48qS7Z2chD6TYALy14vZ8COSCda+u5onRm8eMerlgO18cJmFP on54apoR4TvBpslyV38C7XC6bqfwkDO2dnQMpLiQGvEmhoBjjI0BT3YmiUV1x5KsJ9j8 V6yA+MHARDAfEeivFdeL7Bc+tGmIdSbSHpu9fGuuP3ntoUMsqqL0h9lJVKuy5FS6sTkw 77SPOmMzTsjlk0LE73tZgDtXRosY4CadMreVjOMirHn9+Cyd7WFk96McQl8xMXahJeZk iKbNLJvnxY8xFgpkhQRNJEZQrOJA3ywYdAqKRVZkbFTLjQ4+COvRSSuuD0W7Gdh9P+8B rwxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@semihalf.com header.s=google header.b=r4EXCR1l; 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 dx3-20020a05620a608300b006b550164dadsi2892334qkb.176.2022.07.15.09.02.57; Fri, 15 Jul 2022 09:03:13 -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=r4EXCR1l; 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 S232308AbiGOQAr (ORCPT + 99 others); Fri, 15 Jul 2022 12:00:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231555AbiGOQAo (ORCPT ); Fri, 15 Jul 2022 12:00:44 -0400 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE50A6C119 for ; Fri, 15 Jul 2022 09:00:43 -0700 (PDT) Received: by mail-lf1-x12c.google.com with SMTP id o7so8497908lfq.9 for ; Fri, 15 Jul 2022 09:00:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=mIopSGAH3mTa/L5EYVPega0Li+O294uXD/7Fiv3FbZo=; b=r4EXCR1lFsBKKqZK7VFCnZQxznNws5DThf7w05STlutfX+LxffmlXJic/kW2E8qg/t DKPrUlO9a6Fj5qLYbChTFy8tqbHhexn0eRkqmzSLhR9/ydpqDlfX6E2chixJYgGCo1tb U+LLFeu+Ny7iDvnZVGlwd+spWQXWmt7nN1n8/4dhM2zarAE/zp31gIWgbSM/Yz7UgMF4 Mt7sfJMLM9Z1LuZhgh/pmrHXMYSUfyi+SzOn4Bi7VzyAZKnW55TBHhX0BLKBE5Dqb+NA JTNTjZRuFAhm8s7vz0JToq48xP8eV/mebB4yv5uTU5PSfKtpqknn2nngKrvn1Q3LBx8R FLZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=mIopSGAH3mTa/L5EYVPega0Li+O294uXD/7Fiv3FbZo=; b=0QoWnhgowMwVDo0Hf6TRHFxQfXjs2Iw7Hfo0+04nW28Y2G94NheuIRLH5mlP6cuo6n hjpgjrKjkZaxcTabvuvqblYsU1mcnjoVFT2ucQgXUcw98dIWxwYmQ6/upB+hzIiFNLTF xnWUaoRvIWdYgP/Hwka4Yx7G0s+s78axjxDy5wl4NIl6mFkhfTR57lme7R8Gx3ZYA1Hq iAvwb36qOXr0UoOKvk+RiXlfjCk+fJSi5umpY1RkJOxMjAub79I9Ar2pjIqVw+Y3fl28 gujQIuyVxKSyXb1vcZdBXPCht1lOKY8evWtggAu1GVqjH8tAnnwD1/U6rSbpYt7coxmU LZnA== X-Gm-Message-State: AJIora/uEOrrfgzWdR8xkgLzltzRm/m57Pf7QJ/pBmiJkeKJjHbLQYyV LXhvTzloHR/acmf6lWyXJ2qZXw== X-Received: by 2002:a05:6512:3e15:b0:489:e882:12c7 with SMTP id i21-20020a0565123e1500b00489e88212c7mr8640328lfv.0.1657900842057; Fri, 15 Jul 2022 09:00:42 -0700 (PDT) Received: from dmaluka.office.semihalf.net ([83.142.187.84]) by smtp.gmail.com with ESMTPSA id c12-20020a056512238c00b0047968606114sm959772lfv.111.2022.07.15.09.00.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 09:00:40 -0700 (PDT) From: Dmytro Maluka To: Sean Christopherson , 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 , Rong L Liu , Zhenyu Wang , Tomasz Nowicki , Grzegorz Jaszczyk , Dmitry Torokhov , Dmytro Maluka Subject: [PATCH 0/3] KVM: Fix oneshot interrupts forwarding Date: Fri, 15 Jul 2022 17:59:25 +0200 Message-Id: <20220715155928.26362-1-dmy@semihalf.com> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog MIME-Version: 1.0 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,RCVD_IN_DNSWL_NONE, 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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. This patch series fixes this issue (for now on x86 only) 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. Patches 1 and 2 implement the prerequisites needed for KVM irqfd to know the interrupt mask state. Patch 3 implements the actual fix: postponing resamplefd notify in KVM irqfd until the irq is unmasked. Please see individual patches for more details. Dmytro Maluka (3): KVM: x86: Move kvm_(un)register_irq_mask_notifier() to generic KVM KVM: x86: Add kvm_irq_is_masked() KVM: irqfd: Postpone resamplefd notify for oneshot interrupts arch/x86/include/asm/kvm_host.h | 11 +----- arch/x86/kvm/i8259.c | 11 ++++++ arch/x86/kvm/ioapic.c | 11 ++++++ arch/x86/kvm/ioapic.h | 1 + arch/x86/kvm/irq_comm.c | 34 +++++++++--------- include/linux/kvm_host.h | 13 +++++++ include/linux/kvm_irqfd.h | 14 ++++++++ virt/kvm/eventfd.c | 63 +++++++++++++++++++++++++++++++++ virt/kvm/irqchip.c | 34 ++++++++++++++++++ 9 files changed, 164 insertions(+), 28 deletions(-) -- 2.37.0.170.g444d1eabd0-goog