Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3514355rwb; Fri, 16 Dec 2022 16:34:06 -0800 (PST) X-Google-Smtp-Source: AA0mqf49yZEK6TKFpqcbhfbDpDBv3FXZb+mJ9ggnt9towEy0ZOnRis8Vaha/0P+200Sv+GjlYn9S X-Received: by 2002:a17:902:9a4c:b0:189:85ed:e947 with SMTP id x12-20020a1709029a4c00b0018985ede947mr34376810plv.54.1671237246660; Fri, 16 Dec 2022 16:34:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671237246; cv=none; d=google.com; s=arc-20160816; b=cP3AJkocNiffyVAxHptFXrf3G3ueMH2NDSVFXqTOU9xg5JB6ZnPuyGlhIzqdExMpLP uubHP1NvWKXWnYqoFYGRwPAGG9+5ZlBB2ZnIOpQ/biYFEbQUhWWRijC9lzakZQXG6h+F bb8YSzMFjBteCQU6vw76l/pOuEwN4rsNA3VKA/SeG9Larjm3/fK2AyvWEi6EfrF5pDdM pwcuk96aVthKnWVthqoJe2Xnhs47UtUy2noE1iwf3ZXh+v1YSSZfFZdQ1yDWOslBpYfv Y5Qg3eehNeuIOjlHyw6/AXPryl6aWfXppKTnE+s83Pv0zqZpFeIM4jovsVIIfL+PVaum E/nQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:feedback-id :dkim-signature; bh=LNWvhNkvHdAkxkOlPBeECbMH6IGETqYR0jkIh2pLD9U=; b=rhSGCCiI0oOddGSuSPy9H7q+Jke2a6dP/5cJWDq1cpnDj+YkwJr+06FoD+KSq278Bv xfhvkGg0YwaRIezE5Q2h37U4dIaEXGOny1zkjB79M5bozZN4Sh4qdZ5kTemjk7Kb02JN /9u1EBv+bBKk/B+Uu2QXAu3TfSK11UUDPLy1QxKQjDhTcl5uL9w+wFg9YliH6tBJAX1Q c7UtBSokMqmfGWUaI8KZ+2dNKGVsjCrUh2hhcYpvHVrWwd+OWFJ4Gus6v1NqcaUoBJo6 j90e4+pYd1hQXPcxRXS+yUYuIFw+Bp+4pzeLSF8495aqMLYEvzTo1p38fwauz+5ait6E KWKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=JFVLPMOG; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b13-20020a170902d50d00b00182d9015d42si4763715plg.225.2022.12.16.16.33.57; Fri, 16 Dec 2022 16:34:06 -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=@gmail.com header.s=20210112 header.b=JFVLPMOG; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230123AbiLPXyW (ORCPT + 68 others); Fri, 16 Dec 2022 18:54:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229548AbiLPXyV (ORCPT ); Fri, 16 Dec 2022 18:54:21 -0500 Received: from mail-qt1-x82a.google.com (mail-qt1-x82a.google.com [IPv6:2607:f8b0:4864:20::82a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B64D27CFC; Fri, 16 Dec 2022 15:54:20 -0800 (PST) Received: by mail-qt1-x82a.google.com with SMTP id ay32so4014279qtb.11; Fri, 16 Dec 2022 15:54:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:from:to:cc:subject:date :message-id:reply-to; bh=LNWvhNkvHdAkxkOlPBeECbMH6IGETqYR0jkIh2pLD9U=; b=JFVLPMOGKeQ6YL0ru7V0Nnd8JyloRgwYo1r/AF+3WtiQhaulOI0HuzRTMXVFkuJXJJ A6zHTWihKYOlcvPmmc5W2bKUteG/bDsBJ9VJ5txvTr+x+T9AxhkZH0pHYAYHiYDDAaGW PX2GJz54V1sYGMDuBMopMALVxXBcdf3+Jo9125p48N8DZlVsNa1gaZApATwekrA28xBg XAZ7o/0vUXOaAhWgggXCrVr4xrCVVEtAH5GxgFBoDTeke83dTmSpnqbz0IbaVbq6LxZq 3rx4hWPwg8SZKP02a0u5mos7L0jNqoMEV7mkWMJDW+NrNLeIAXvNWozmXH0MQJM+k8F2 tSOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LNWvhNkvHdAkxkOlPBeECbMH6IGETqYR0jkIh2pLD9U=; b=VYhkj3HgZwVgTPzSzBgywLPishjms0IKxQR5R7fJ1OlVwRMS9kUpmEXTOldWI4Le3Q 8hvr8DHk/MghrF9FpoTnrPP9eg+Zm/o9yka/9SkiTM0dP1vU0KQT9V0rBdNHcscrZ7X2 +DSOdhsispTyZlqsc2ZXMi+TuC6P4mLiPagZAIS4vCJPQjde7+l3pAvO3V4GQW7DwuaF 4uzXRoDmJJGqxUYN3nhEgWOqmmBmBcFJOoI73hSAOeQw2YhcaAcjJMtl8RBMwrBeHecP 643PjrPC70/2OKcGihPBx7ihuVrGnbg0LI33in6Bf4/D1NY6Ep52hK9EbRZFVwQxisNX 6iYg== X-Gm-Message-State: ANoB5pnH20r8/ZWCsCebZyTFNZzBEjYuAi/Gh+WhQTYX1A1hkKQBii57 NtY1wWZFfwdxOBo5OUl7h8Y= X-Received: by 2002:ac8:72d6:0:b0:3a7:ee15:d94c with SMTP id o22-20020ac872d6000000b003a7ee15d94cmr44950182qtp.47.1671234859177; Fri, 16 Dec 2022 15:54:19 -0800 (PST) Received: from auth2-smtp.messagingengine.com (auth2-smtp.messagingengine.com. [66.111.4.228]) by smtp.gmail.com with ESMTPSA id m1-20020ac86881000000b0039a55f78792sm2055750qtq.89.2022.12.16.15.54.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Dec 2022 15:54:18 -0800 (PST) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailauth.nyi.internal (Postfix) with ESMTP id 1A08D27C0054; Fri, 16 Dec 2022 18:54:17 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 16 Dec 2022 18:54:18 -0500 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeekgddugecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeeuohhquhhn ucfhvghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuggftrfgrth htvghrnhephedugfduffffteeutddvheeuveelvdfhleelieevtdeguefhgeeuveeiudff iedvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepsg hoqhhunhdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqieelvdeghedtieeg qddujeejkeehheehvddqsghoqhhunhdrfhgvnhhgpeepghhmrghilhdrtghomhesfhhigi hmvgdrnhgrmhgv X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 16 Dec 2022 18:54:16 -0500 (EST) Date: Fri, 16 Dec 2022 15:54:09 -0800 From: Boqun Feng To: Al Viro Cc: Linus Torvalds , 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 Subject: Re: possible deadlock in __ata_sff_interrupt Message-ID: References: <5eff70b8-04fc-ee87-973a-2099a65f6e29@opensource.wdc.com> <80dc24c5-2c4c-b8da-5017-31aae65a4dfa@opensource.wdc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 On Fri, Dec 16, 2022 at 11:39:21PM +0000, Al Viro wrote: > [Boqun Feng Cc'd] > > On Fri, Dec 16, 2022 at 03:26:21AM -0800, Linus Torvalds wrote: > > On Thu, Dec 15, 2022 at 7:41 PM Al Viro wrote: > > > > > > CPU1: ptrace(2) > > > ptrace_check_attach() > > > read_lock(&tasklist_lock); > > > > > > CPU2: setpgid(2) > > > write_lock_irq(&tasklist_lock); > > > spins > > > > > > CPU1: takes an interrupt that would call kill_fasync(). grep and the > > > first instance of kill_fasync() is in hpet_interrupt() - it's not > > > something exotic. IRQs disabled on CPU2 won't stop it. > > > kill_fasync(..., SIGIO, ...) > > > kill_fasync_rcu() > > > read_lock_irqsave(&fa->fa_lock, flags); > > > send_sigio() > > > read_lock_irqsave(&fown->lock, flags); > > > read_lock(&tasklist_lock); > > > > > > ... and CPU1 spins as well. > > > > Nope. See kernel/locking/qrwlock.c: > > [snip rwlocks are inherently unfair, queued ones are somewhat milder, but > all implementations have writers-starving behaviour for read_lock() at least > when in_interrupt()] > > D'oh... Consider requested "Al, you are a moron" duly delivered... I plead > having been on way too low caffeine and too little sleep ;-/ > > Looking at the original report, looks like the scenario there is meant to be > the following: > > CPU1: read_lock(&tasklist_lock) > tasklist_lock grabbed > > CPU2: get an sg write(2) feeding request to libata; host->lock is taken, > request is immediately completed and scsi_done() is about to be called. > host->lock grabbed > > CPU3: write_lock_irq(&tasklist_lock) > spins on tasklist_lock until CPU1 gets through. > > CPU2: get around to kill_fasync() called by sg_rq_end_io() and to grabbing > tasklist_lock inside send_sigio() > spins, since it's not in an interrupt and there's a pending writer > host->lock is held, spin until CPU3 gets through. 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 Regards, Boqun > > CPU1: take an interrupt, which on libata will try to grab host->lock > tasklist_lock is held, spins on host->lock until CPU2 gets through > > Am I reading it correctly?