From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7CFC7CCA482 for ; Fri, 15 Jul 2022 16:00:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232141AbiGOQAr (ORCPT ); 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-Google-Smtp-Source: AGRyM1sy8e8fPJdsNFqKUZ3+IuaUwVfbMDgUo5p1mH0WqHRT0w0vw/BcUr3AlC/CEkBL043+uaOgvA== 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 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