Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3389560ybt; Tue, 23 Jun 2020 00:45:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDXifhqnVnh5yqkZyMll5XZ8+eB0LZfo/qlQKm4AGwQ+mK6zZ74Qft7FLjQZOmI3G4wPYG X-Received: by 2002:a17:906:840a:: with SMTP id n10mr13057948ejx.453.1592898316619; Tue, 23 Jun 2020 00:45:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592898316; cv=none; d=google.com; s=arc-20160816; b=0WOTojYk/iK4Lx0w3Bs/qoni3NLfY5dPf7Tx/2t+hDlN1DW6DsgzC0KyKQRR4pFHsb 9Uvyyb4kVRJz3JyzPlQO+qnMrpyVTm6tjGCgqe4/UmC+9OjUYBXRu+3iLlFgEL29Jpjb 3mRzg09U7EwbPxmG5+/RkEbQjNptpvIAlrCUEdeffUDQBrNcg6e3BTczGCpqyqfWky5e uZ0qcdvX0JLoLacWVgO20JWJ27coky31Ggf5iAGvfmEX/Yc0xEMg/PcfC4YHb08bXkpm ps2yvlGh+4WqCaAPjrHJRareRznm5+d+cQNYGFheVlmnozXA09MqJZhA1YOscXeNMUlm LSIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=bRQOtyl6lVhUbOXwbZ0j6gA48P7oZ6lHfj3tURdm+Qk=; b=0KzZ6Lzhv+CZz+xQSg9dSt1P+/LAjFknCDxtmbisK04TfGX7xKIa5BbKBmmXrevIFA cy85LqpIIP6QCEV7yoid/0r0IErCSpkE9ZR0fz0011gLAe6X6fbaMcYd9Mrri/mxFIgV HhZVRrxYFF5FeyxRrXG/ya/ggfTQTtGBVlT4j9bntxHuC0aQA4txITq00+txEZhbrPZ0 yLZUVwZh5oF8TJYtP5FGAec3NCBomtgIcO6pI1C2adBR8ADi5gx8qB/JdTEwu/HQXsbI fdJNnhjv/vL+LROaEOS/l5mxvqHyfE3dFqAl7tlv8QGJsixgoJKb7S2PqJKL34O5ndKY G2jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IrRgvi1F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f20si948924edc.220.2020.06.23.00.44.53; Tue, 23 Jun 2020 00:45:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IrRgvi1F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731041AbgFWHkB (ORCPT + 99 others); Tue, 23 Jun 2020 03:40:01 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:40914 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731588AbgFWHkA (ORCPT ); Tue, 23 Jun 2020 03:40:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592897999; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bRQOtyl6lVhUbOXwbZ0j6gA48P7oZ6lHfj3tURdm+Qk=; b=IrRgvi1FqQa6JaNlNuI4m4BstDE68ncGNsSdm/VHP3ae1XsvmIV4bJ27ZAPTqvvOIOwxV8 1zDOeCgglB6o+fFqpBWsw6lGCqD4L94Zt0iQPgwfbNxbzNAWjbRfHuZ/fEx2fxIIZ1A9yI D86b9D68A2wKSHUrlcTVmB4lRZNn+g4= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-152-GzDKbgbNOB2chCGTovowuA-1; Tue, 23 Jun 2020 03:39:57 -0400 X-MC-Unique: GzDKbgbNOB2chCGTovowuA-1 Received: by mail-wr1-f72.google.com with SMTP id r5so14477543wrt.9 for ; Tue, 23 Jun 2020 00:39:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=bRQOtyl6lVhUbOXwbZ0j6gA48P7oZ6lHfj3tURdm+Qk=; b=oi+F12WBJLyeZb4N3M5wI3ADr3YJVVju2NGSsKfXQ9B/QAJD5Bkn+9w+6pnxevxegq qxMFlvF9tVu/kRSQJh0VPjv+ZBR5uuz11VxIJMO3ZVjqKziY7uRqHCVDQUEl6sfSybol 8t8ASjOiMBgU6qaHr3jewXpF4QK1N1Aa6KLJC+r7coru63OJMF1y1izLIGv0S0/decwe XPULqZyXewPClKR7tbd92PHyDI5k8a5kPSo6jMHNggGhtvRbBcBM/vNg8s0EnuaWWZT8 T4DXiFPL2VxUA6fttIB9f0gWRwd+f/bFaV2pEuHsBfKHhpyhmrPIPU4qvDqCf/damI8n hI3A== X-Gm-Message-State: AOAM530cai8X9ZseflYk9J5QY+9BJcVftvlARi5t03RKyfbnagt7JNoM DrYi9dtkpn8Z7O2YJ0HDsiX3AOB1wFpSM7kMqJUTdxz3wU8xSR+JkwcIZNezyLh9EtnJpOtu+uk yhetZICG2CZtZdWnT98GGybzh X-Received: by 2002:adf:f68d:: with SMTP id v13mr22045557wrp.291.1592897996031; Tue, 23 Jun 2020 00:39:56 -0700 (PDT) X-Received: by 2002:adf:f68d:: with SMTP id v13mr22045539wrp.291.1592897995798; Tue, 23 Jun 2020 00:39:55 -0700 (PDT) Received: from ?IPv6:2001:b07:6468:f312:24f5:23b:4085:b879? ([2001:b07:6468:f312:24f5:23b:4085:b879]) by smtp.gmail.com with ESMTPSA id d9sm21004342wre.28.2020.06.23.00.39.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 23 Jun 2020 00:39:55 -0700 (PDT) Subject: Re: [PATCH v2] kvm: Fix false positive RCU usage warning To: madhuparnabhowmik10@gmail.com, sean.j.christopherson@intel.com, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, tglx@linutronix.de, bp@alien8.de Cc: x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, joel@joelfernandes.org, paulmck@kernel.org, frextrite@gmail.com, linux-kernel-mentees@lists.linuxfoundation.org, Paul McKenney References: <20200516082227.22194-1-madhuparnabhowmik10@gmail.com> From: Paolo Bonzini Message-ID: <9fff3c6b-1978-c647-16f7-563a1cdf62ff@redhat.com> Date: Tue, 23 Jun 2020 09:39:53 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <20200516082227.22194-1-madhuparnabhowmik10@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 16/05/20 10:22, madhuparnabhowmik10@gmail.com wrote: > From: Madhuparna Bhowmik > > Fix the following false positive warnings: > > [ 9403.765413][T61744] ============================= > [ 9403.786541][T61744] WARNING: suspicious RCU usage > [ 9403.807865][T61744] 5.7.0-rc1-next-20200417 #4 Tainted: G L > [ 9403.838945][T61744] ----------------------------- > [ 9403.860099][T61744] arch/x86/kvm/mmu/page_track.c:257 RCU-list traversed in non-reader section!! > > and > > [ 9405.859252][T61751] ============================= > [ 9405.859258][T61751] WARNING: suspicious RCU usage > [ 9405.880867][T61755] ----------------------------- > [ 9405.911936][T61751] 5.7.0-rc1-next-20200417 #4 Tainted: G L > [ 9405.911942][T61751] ----------------------------- > [ 9405.911950][T61751] arch/x86/kvm/mmu/page_track.c:232 RCU-list traversed in non-reader section!! > > Since srcu read lock is held, these are false positive warnings. > Therefore, pass condition srcu_read_lock_held() to > list_for_each_entry_rcu(). > > Reported-by: kernel test robot > Signed-off-by: Madhuparna Bhowmik > --- > v2: > -Rebase v5.7-rc5 > > arch/x86/kvm/mmu/page_track.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/kvm/mmu/page_track.c b/arch/x86/kvm/mmu/page_track.c > index ddc1ec3bdacd..1ad79c7aa05b 100644 > --- a/arch/x86/kvm/mmu/page_track.c > +++ b/arch/x86/kvm/mmu/page_track.c > @@ -229,7 +229,8 @@ void kvm_page_track_write(struct kvm_vcpu *vcpu, gpa_t gpa, const u8 *new, > return; > > idx = srcu_read_lock(&head->track_srcu); > - hlist_for_each_entry_rcu(n, &head->track_notifier_list, node) > + hlist_for_each_entry_rcu(n, &head->track_notifier_list, node, > + srcu_read_lock_held(&head->track_srcu)) > if (n->track_write) > n->track_write(vcpu, gpa, new, bytes, n); > srcu_read_unlock(&head->track_srcu, idx); > @@ -254,7 +255,8 @@ void kvm_page_track_flush_slot(struct kvm *kvm, struct kvm_memory_slot *slot) > return; > > idx = srcu_read_lock(&head->track_srcu); > - hlist_for_each_entry_rcu(n, &head->track_notifier_list, node) > + hlist_for_each_entry_rcu(n, &head->track_notifier_list, node, > + srcu_read_lock_held(&head->track_srcu)) > if (n->track_flush_slot) > n->track_flush_slot(kvm, slot, n); > srcu_read_unlock(&head->track_srcu, idx); > Hi, sorry for the delay in reviewing this patch. I would like to ask Paul about it. While you're correctly fixing a false positive, hlist_for_each_entry_rcu would have a false _negative_ if you called it under rcu_read_lock/unlock and the data structure was protected by SRCU. This is why for example srcu_dereference is used instead of rcu_dereference_check, and why srcu_dereference uses __rcu_dereference_check (with the two underscores) instead of rcu_dereference_check. Using rcu_dereference_check would add an "|| rcu_read_lock_held()" to the condition which is wrong. I think instead you should add hlist_for_each_srcu and hlist_for_each_entry_srcu macro to include/linux/rculist.h. There is no need for equivalents of hlist_for_each_entry_continue_rcu and hlist_for_each_entry_from_rcu, because they use rcu_dereference_raw. However, it's not documented why they do so. Paul, do you have any objections to the idea? Thanks, Paolo