Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3713145rwb; Fri, 16 Dec 2022 20:56:21 -0800 (PST) X-Google-Smtp-Source: AA0mqf7YshrcrX8354C8uSUonuC+72/qCTNa3tTOajvhBjnZ0JemwI4vxSUd+1IZPa9ptTjXMawR X-Received: by 2002:a17:906:c083:b0:7a6:5b50:a32c with SMTP id f3-20020a170906c08300b007a65b50a32cmr32472468ejz.12.1671252981577; Fri, 16 Dec 2022 20:56:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671252981; cv=none; d=google.com; s=arc-20160816; b=fhaCHlRMzLLlo97j5e0q+/wh4ICUyY7mDHx/WIGuebk8lRCSGQ0Q04WMqbMpMqVOpF djQZEvUiMfUts4x6aVxV4TpXgL19zdWS08IUONH8yJY9Nkg78XGRdT4nCVEXv15MDjpB 6GkKyt6F7mlBGNixBXEV0lQD6AMcCvjk3a/Xmt+UDwz3FGDJFmjlcjarhFLahzFi/Tr/ vbi/LJdjTN+6plvn0TXXXMD974Fc1XAxNA/NKkTlUAi8tZhnJlcvgnzYTm+9b2MqeN8r uEgbAVvettpk4NHcSxcgl2xX+2K3vGSiQck7BxnEpmUX77T9esEjNT2FvYbvVAVnK5W5 j7pA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=igh8qy8rEJ/HKaAG0/pCIIFMuJJiLsx7f/WlxqjWaiI=; b=aE6nLQoyvrSxk1aTnp51rKyXOON7aGuKPhO71DNFMPfG0MpkH829hB0EM9rKBVlSF7 SJRm7zW+Jf8Vr3h/4w/pIJX0agD2NMMuqVEzTA+rwrcDcsGa8E/ilGRJtbGkXF7Gnd4B VtFjNP4zuWzd+YtkYGkFabxYKIbwCW+B7aXda26hPPD/jbNW7Fyer+Ku3n03LC1fHDPp qjFbpQ3rOwtCfln4j9Yc+SMR2Ir7WPmzaoNMIxjS5vNYX/Gfsp2oknimcdWvE0NB48B6 0Le1pGRonb/MevLkkpvZAcByMSXn6e/hUGQgrgAN3Oxk5crTddX2qOgjsBoqpzwkOKTM ZLNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Dmp0xPhO; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x21-20020a170906135500b0078d3a35e181si3251771ejb.871.2022.12.16.20.56.03; Fri, 16 Dec 2022 20:56:21 -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=@redhat.com header.s=mimecast20190719 header.b=Dmp0xPhO; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230028AbiLQEmH (ORCPT + 70 others); Fri, 16 Dec 2022 23:42:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229480AbiLQEmE (ORCPT ); Fri, 16 Dec 2022 23:42:04 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 701F3140BE for ; Fri, 16 Dec 2022 20:41:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671252076; 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=igh8qy8rEJ/HKaAG0/pCIIFMuJJiLsx7f/WlxqjWaiI=; b=Dmp0xPhOvmYYzKnVgzQIFn1p+EqWLzTpf7lcF+EGC1Y+zIg9hN0l5IIoca9mBk43YkhDPu YxbdiIvwJijW3uWYHhq7W3W2gR+3n9b756RD7sCqGDxlg1jXEiPvitCPEo5NSVQPqbMDbM CxI51Y7EVGLYHLwBzGbOQ+kzXaVXmMM= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-671-ufHIsj6nPX-Qwk2ajdCYuQ-1; Fri, 16 Dec 2022 23:41:13 -0500 X-MC-Unique: ufHIsj6nPX-Qwk2ajdCYuQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3FFA63C0F7E1; Sat, 17 Dec 2022 04:41:12 +0000 (UTC) Received: from [10.22.8.73] (unknown [10.22.8.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id A36D72166B26; Sat, 17 Dec 2022 04:41:11 +0000 (UTC) Message-ID: Date: Fri, 16 Dec 2022 23:41:11 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.0 Subject: Re: possible deadlock in __ata_sff_interrupt Content-Language: en-US To: Al Viro , Linus Torvalds Cc: Boqun Feng , Damien Le Moal , Wei Chen , linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, syzbot , linux-fsdevel , Chuck Lever , Jeff Layton , Peter Zijlstra References: <5eff70b8-04fc-ee87-973a-2099a65f6e29@opensource.wdc.com> <80dc24c5-2c4c-b8da-5017-31aae65a4dfa@opensource.wdc.com> From: Waiman Long In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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 12/16/22 22:05, Al Viro wrote: > On Fri, Dec 16, 2022 at 08:31:54PM -0600, Linus Torvalds wrote: >> Ok, let's bring in Waiman for the rwlock side. >> >> On Fri, Dec 16, 2022 at 5:54 PM Boqun Feng wrote: >>> Right, for a reader not in_interrupt(), it may be blocked by a random >>> waiting writer because of the fairness, even the lock is currently held >>> by a reader: >>> >>> CPU 1 CPU 2 CPU 3 >>> read_lock(&tasklist_lock); // get the lock >>> >>> write_lock_irq(&tasklist_lock); // wait for the lock >>> >>> read_lock(&tasklist_lock); // cannot get the lock because of the fairness >> But this should be ok - because CPU1 can make progress and eventually >> release the lock. >> >> So the tasklist_lock use is fine on its own - the reason interrupts >> are special is because an interrupt on CPU 1 taking the lock for >> reading would deadlock otherwise. As long as it happens on another >> CPU, the original CPU should then be able to make progress. >> >> But the problem here seems to be thst *another* lock is also involved >> (in this case apparently "host->lock", and now if CPU1 and CPU2 get >> these two locks in a different order, you can get an ABBA deadlock. >> >> And apparently our lockdep machinery doesn't catch that issue, so it >> doesn't get flagged. > Lockdep has actually caught that; the locks involved are mention in the > report (https://marc.info/?l=linux-ide&m=167094379710177&w=2). The form > of report might have been better, but if anything, it doesn't mention > potential involvement of tasklist_lock writer, turning that into a deadlock. > > OTOH, that's more or less implicit for the entire class: > > read_lock(A) [non-interrupt] > local_irq_disable() local_irq_disable() > spin_lock(B) write_lock(A) > read_lock(A) > [in interrupt] > spin_lock(B) > > is what that sort of reports is about. In this case A is tasklist_lock, > B is host->lock. Possible call chains for CPU1 and CPU2 are reported... > > I wonder why analogues of that hadn't been reported for other SCSI hosts - > it's a really common pattern there... > >> I'm not sure what the lockdep rules for rwlocks are, but maybe lockdep >> treats rwlocks as being _always_ unfair, not knowing about that "it's >> only unfair when it's in interrupt context". >> >> Maybe we need to always make rwlock unfair? Possibly only for tasklist_lock? That may not be a good idea as the cacheline bouncing problem will be back with reduced performance. > ISTR threads about the possibility of explicit read_lock_unfair()... Another possible alternative is to treat the read_lock as unfair if interrupt has been disabled as I think we should reduce the interrupt disabled interval as much as possible. Thought? Cheers, Longman