From patchwork Tue Sep 12 00:56:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 1832585 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=DLEAFypQ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ide-owner@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4Rl6Rt1qpVz1yhL for ; Tue, 12 Sep 2023 12:07:54 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236557AbjILCHz (ORCPT ); Mon, 11 Sep 2023 22:07:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237286AbjILCCE (ORCPT ); Mon, 11 Sep 2023 22:02:04 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A28521A8282; Mon, 11 Sep 2023 18:32:26 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8074C32789; Tue, 12 Sep 2023 00:56:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694480219; bh=C+8EDt/gME5JJRwiAsAzxWTei+r9m7fJ3KsaEm2eE/c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DLEAFypQuZJLhsyNYfTJLdI4BvasbC9uhJINRn5oWbyUTAVa0uNYP/mixgdymCUvK 7aDVUqLZ+hw9pjjKsElX11v013Tw6p+3/+rMUNS0V7W4qUlmIQuBdkVLkwvMQ5mCOs 1facE7Kf6dlcwOcehLsLiZ3MBT4GRZp/DVdDRH+JkD0R0DVoxZVlsC8AV2Wi3njis9 u+lpI5hz0yrBum3zSsR4Kh1EI0orCEhEmY1z56WibxvenLNwOlOTVsvI6Pj+s8pqch 6v1ELsDBouZIbSIC+rO0/Y6MtivAxJbh3tJSm2qfyebNyQl4Ji+7g1F7m+X8jw+tz4 HEz2C2hoi89rA== From: Damien Le Moal To: linux-ide@vger.kernel.org Cc: linux-scsi@vger.kernel.org, "Martin K . Petersen" , John Garry , Rodrigo Vivi , Paul Ausbeck , Kai-Heng Feng , Joe Breuer Subject: [PATCH v2 01/21] ata: libata-core: Fix ata_port_request_pm() locking Date: Tue, 12 Sep 2023 09:56:35 +0900 Message-ID: <20230912005655.368075-2-dlemoal@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230912005655.368075-1-dlemoal@kernel.org> References: <20230912005655.368075-1-dlemoal@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-ide@vger.kernel.org The function ata_port_request_pm() checks the port flag ATA_PFLAG_PM_PENDING and calls ata_port_wait_eh() if this flag is set to ensure that power management operations for a port are not secheduled simultaneously. However, this flag check is done without holding the port lock. Fix this by taking the port lock on entry to the function and checking the flag under this lock. The lock is released and re-taken if ata_port_wait_eh() needs to be called. Fixes: 5ef41082912b ("ata: add ata port system PM callbacks") Cc: stable@vger.kernel.org Signed-off-by: Damien Le Moal Reviewed-by: Hannes Reinecke --- drivers/ata/libata-core.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 74314311295f..c4898483d716 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c @@ -5040,17 +5040,20 @@ static void ata_port_request_pm(struct ata_port *ap, pm_message_t mesg, struct ata_link *link; unsigned long flags; - /* Previous resume operation might still be in - * progress. Wait for PM_PENDING to clear. + spin_lock_irqsave(ap->lock, flags); + + /* + * A previous PM operation might still be in progress. Wait for + * ATA_PFLAG_PM_PENDING to clear. */ if (ap->pflags & ATA_PFLAG_PM_PENDING) { + spin_unlock_irqrestore(ap->lock, flags); ata_port_wait_eh(ap); + spin_lock_irqsave(ap->lock, flags); WARN_ON(ap->pflags & ATA_PFLAG_PM_PENDING); } - /* request PM ops to EH */ - spin_lock_irqsave(ap->lock, flags); - + /* Request PM operation to EH */ ap->pm_mesg = mesg; ap->pflags |= ATA_PFLAG_PM_PENDING; ata_for_each_link(link, ap, HOST_FIRST) { @@ -5062,10 +5065,8 @@ static void ata_port_request_pm(struct ata_port *ap, pm_message_t mesg, spin_unlock_irqrestore(ap->lock, flags); - if (!async) { + if (!async) ata_port_wait_eh(ap); - WARN_ON(ap->pflags & ATA_PFLAG_PM_PENDING); - } } /*