Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp5738673pxb; Mon, 14 Feb 2022 06:33:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJyuTviPA/nHUVZ0ukWZq4RbOun4aj/m6gI9jIab2vlyrUel/2lreZivM0Z+GUUGQ5oBmWr+ X-Received: by 2002:a17:902:ced1:: with SMTP id d17mr21517plg.37.1644849188520; Mon, 14 Feb 2022 06:33:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644849188; cv=none; d=google.com; s=arc-20160816; b=YnpiOrULeJRPdyVKpPrUG32lCTZpLxah97TEHZsXHDx1sXBvqd36rb50r2cv+av5m9 T3K9hl/Majs6JZCz1j86g+jQUR0I+e7DIkki4RuGZf2WDgsp6wDMR+Fs+mDj2bQeBZhd H/qt/re1TC2jDhACFWYJtp7bGrNB3dzkYFqw9rNmMliSGE/s0Sklck6UC6AxJgT9idPy Elv02LFSI9JCyX3JqVdVG7Zvu9SYi1LllDBgwJ1S7T8do+dSDk/5TBs4qG2T3FxnbTiM YgD31b9spAPIF8R8xUa4UCE+hP65Y+0vvzicW2bjPWbKvRgpN5M6NbR/thnry64C4LF2 4AKw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=KX6Bez3baY9zMnJuEZa+tlt56XGFb7xdH8wp5lvFQVg=; b=I+scqX5zqFvSCjSTDVv+DPY3NI4SKTPOV8khuc/YuugpjbMsTs8gRf3NC440LqJB2/ zbbs/zLfOGBEN3CJpn3/NAEMk/BZFvUXQb4E9hbuvk3X/+RaRvR/yOp4DsF9R12jPXUE xZzkDsuAclFI3j1ANKx5E7GiigN/dh7WzX09MW7wVwg3UaQ+dD8q8QKfWv8enkJGfhbd Csa/5MrPAe6UBXtNcurmustn1BFAKRRdU3Hn8BIoeUt4QH8pgeTnStC7SkVM8wpFHX26 5TS8gaHTIEvDi+vwUGr9kajjzykj9FZDuBeBtbUoaiCg95yeEJN8u1p0I/rdepkFPVs/ pHag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bOWva5Tc; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id om18si13444979pjb.75.2022.02.14.06.32.49; Mon, 14 Feb 2022 06:33:08 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=bOWva5Tc; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241526AbiBNJx4 (ORCPT + 99 others); Mon, 14 Feb 2022 04:53:56 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:33318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245721AbiBNJun (ORCPT ); Mon, 14 Feb 2022 04:50:43 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91F0265490; Mon, 14 Feb 2022 01:41:33 -0800 (PST) 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 52EEFB80DC4; Mon, 14 Feb 2022 09:41:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D74AC340E9; Mon, 14 Feb 2022 09:41:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644831691; bh=X/BFUlpcGhyLwAO9j1bzq1Q46bsIUcjSuLw8ydqvLzM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bOWva5TcHr0k7VojK/Gu16btMj3+dNTyua2PcZhYWEOKBrH5M+OKeTf7TvBkkzIHf OaYLEDUvRN6rPKx9HY1245pbXSek5sLDJ9fRojacZE1AmAdiDj1gGqP9+PLcrv+okc IpjNbrq+t++PMC1IqJgE85YJ7px7YTxyNixKYxbs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sean Christopherson , Hou Wenlong , Paolo Bonzini , Sasha Levin Subject: [PATCH 5.10 037/116] KVM: eventfd: Fix false positive RCU usage warning Date: Mon, 14 Feb 2022 10:25:36 +0100 Message-Id: <20220214092459.965271910@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220214092458.668376521@linuxfoundation.org> References: <20220214092458.668376521@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 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 From: Hou Wenlong [ Upstream commit 6a0c61703e3a5d67845a4b275e1d9d7bc1b5aad7 ] Fix the following false positive warning: ============================= WARNING: suspicious RCU usage 5.16.0-rc4+ #57 Not tainted ----------------------------- arch/x86/kvm/../../../virt/kvm/eventfd.c:484 RCU-list traversed in non-reader section!! other info that might help us debug this: rcu_scheduler_active = 2, debug_locks = 1 3 locks held by fc_vcpu 0/330: #0: ffff8884835fc0b0 (&vcpu->mutex){+.+.}-{3:3}, at: kvm_vcpu_ioctl+0x88/0x6f0 [kvm] #1: ffffc90004c0bb68 (&kvm->srcu){....}-{0:0}, at: vcpu_enter_guest+0x600/0x1860 [kvm] #2: ffffc90004c0c1d0 (&kvm->irq_srcu){....}-{0:0}, at: kvm_notify_acked_irq+0x36/0x180 [kvm] stack backtrace: CPU: 26 PID: 330 Comm: fc_vcpu 0 Not tainted 5.16.0-rc4+ Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.14.0-0-g155821a1990b-prebuilt.qemu.org 04/01/2014 Call Trace: dump_stack_lvl+0x44/0x57 kvm_notify_acked_gsi+0x6b/0x70 [kvm] kvm_notify_acked_irq+0x8d/0x180 [kvm] kvm_ioapic_update_eoi+0x92/0x240 [kvm] kvm_apic_set_eoi_accelerated+0x2a/0xe0 [kvm] handle_apic_eoi_induced+0x3d/0x60 [kvm_intel] vmx_handle_exit+0x19c/0x6a0 [kvm_intel] vcpu_enter_guest+0x66e/0x1860 [kvm] kvm_arch_vcpu_ioctl_run+0x438/0x7f0 [kvm] kvm_vcpu_ioctl+0x38a/0x6f0 [kvm] __x64_sys_ioctl+0x89/0xc0 do_syscall_64+0x3a/0x90 entry_SYSCALL_64_after_hwframe+0x44/0xae Since kvm_unregister_irq_ack_notifier() does synchronize_srcu(&kvm->irq_srcu), kvm->irq_ack_notifier_list is protected by kvm->irq_srcu. In fact, kvm->irq_srcu SRCU read lock is held in kvm_notify_acked_irq(), making it a false positive warning. So use hlist_for_each_entry_srcu() instead of hlist_for_each_entry_rcu(). Reviewed-by: Sean Christopherson Signed-off-by: Hou Wenlong Message-Id: Signed-off-by: Paolo Bonzini Signed-off-by: Sasha Levin --- virt/kvm/eventfd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c index c2323c27a28b5..518cd8dc390e2 100644 --- a/virt/kvm/eventfd.c +++ b/virt/kvm/eventfd.c @@ -451,8 +451,8 @@ bool kvm_irq_has_notifier(struct kvm *kvm, unsigned irqchip, unsigned pin) idx = srcu_read_lock(&kvm->irq_srcu); gsi = kvm_irq_map_chip_pin(kvm, irqchip, pin); if (gsi != -1) - hlist_for_each_entry_rcu(kian, &kvm->irq_ack_notifier_list, - link) + hlist_for_each_entry_srcu(kian, &kvm->irq_ack_notifier_list, + link, srcu_read_lock_held(&kvm->irq_srcu)) if (kian->gsi == gsi) { srcu_read_unlock(&kvm->irq_srcu, idx); return true; @@ -468,8 +468,8 @@ void kvm_notify_acked_gsi(struct kvm *kvm, int gsi) { struct kvm_irq_ack_notifier *kian; - hlist_for_each_entry_rcu(kian, &kvm->irq_ack_notifier_list, - link) + hlist_for_each_entry_srcu(kian, &kvm->irq_ack_notifier_list, + link, srcu_read_lock_held(&kvm->irq_srcu)) if (kian->gsi == gsi) kian->irq_acked(kian); } -- 2.34.1