Received: by 10.192.165.148 with SMTP id m20csp4024250imm; Tue, 8 May 2018 01:22:58 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr9/UNCAWm1Wr2lBBTCl/1NZtWj3s59+EbzC5UlOTk+y/QB1K5055EjL2TDeGoHvwz+4DR4 X-Received: by 2002:a63:705d:: with SMTP id a29-v6mr32300933pgn.202.1525767778504; Tue, 08 May 2018 01:22:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525767778; cv=none; d=google.com; s=arc-20160816; b=w8XB3XpPxBWugE1MzUHspXBLRzNea40ZYwGQISVtf5pBXfGdPgDSJtaVlEUETDSt/s iFTfBFFyZNIpD04GB+vhr8auIWhyOh1kPVTasvYpz+6xUCxY24exKFcQMgZL6W5B1gHF LaBFCvVZ3NepYQNUo8yDkhySxiTCP/B8x2910zZkX34IFFU6eHayGIXy6iRfAimh9Ot5 +qK/bC5k3PHi9KeUGo8n4DnkrFXj4WVKebmYf4RNqXgRGS0R4LvGmdmXzJUfxuNrOeg5 eLnv5s6PiaKACbaq5a3eA7ZYP7dlY0ZHjIcJiAj/oJvTMO7Tzfh/hQH/x40HstsoDkns ZJXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=lroEBtx0bRdtvzOdjrC45XRqGLx4VUavVpi6hBhb3jk=; b=zsILD7A8NXnE4W0jO8vC9lIQOfahNDGPAFukLWh2S9Qv05LVwH0qp38WOm+9zmPFx/ hlwQJa691E4hTUSESQiAEmMCm7CbykfiZ1nF5w6nk50e/jpfY/8LMOrJiY0BWwpfd8aU vOqtYR90TVyjL+brzrhXH9brVlCuAdhirk0KENt1bfF0WI3vwHuYGJARUK3pgnAFP3Y9 DoOaknGdzr4FJt7laYm13BHtclKlB30LCTGPothvkbqytBcVLAYoPs9jLjBQBFCS4UJb fDDnbMr4Lr4GJn1NE6u6dPgpGG+IJkXxeVyQYJvuOyRR9ZZ1uOnDi4DX/iC9foxUhEHX P6uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=i+DWvISF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 31-v6si23589701plz.364.2018.05.08.01.22.44; Tue, 08 May 2018 01:22:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=i+DWvISF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S933054AbeEHIVv (ORCPT + 99 others); Tue, 8 May 2018 04:21:51 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:39017 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932732AbeEHIVs (ORCPT ); Tue, 8 May 2018 04:21:48 -0400 Received: by mail-pf0-f193.google.com with SMTP id a22so9504009pfn.6; Tue, 08 May 2018 01:21:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=lroEBtx0bRdtvzOdjrC45XRqGLx4VUavVpi6hBhb3jk=; b=i+DWvISF2OzjO7G4EXChVklMQxgG5sbP9ekNg1s7Q/2XPWDGbSDwQQ7tpWezwL5LbO DvQqc0zsCstCmpQhM1gS9yQ7J/MI+7Y7/KPqQqQEnEhJEOc3laJQTZMnr6KHQUuVOUKk VoIcK+kYZkVQw48JCvJV/h9h/QKtg25au9FGhdqK+KytefuzkgZk/zbdvkinvDqw8+AF anfIz+gIFamkG+lPyBgF10zhsdCHM2iPRzRiDBX62fjQAZRiUpl8pqH06FHWUd7GcTtz I0hjytLLzv7wocIWkXeBi6Q75/X9SQX4F9f0XVtNQ98Sc7ndYUI3z/gD4krj40Kl9jSY iJng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=lroEBtx0bRdtvzOdjrC45XRqGLx4VUavVpi6hBhb3jk=; b=jDIXjv7NvBtli3Wqh608xJYP+ksOkKmYwYzDqj3G8/3Y/kMMMM83RX9QB8gTZACNR9 AefBZBm6AFASCN2qn3l0EmWQ+Yb059Ug3vpGf9y7ssWp6eRH67eKE/qRkcluDTZuZAlg CIXm+EB5NGJohoCbDBq9fpE6dF9IrjnUH7Tqdhb1KY3j8DbZyhnKlE+Az7PsAwd6fUat iQbSjoRk7Zf4IoPeAZkEDV1TdWCvkqoun2PDkLs0ARpL9zWgztNazPWgUc1IC5q3TO1a ZccjXw3yKsDbjudp9Wc3nYq/OeXQJ06Fnq9Cv3Q04ZkfsNPT4TaUSVXGKdg2QuW56Ip3 Nogg== X-Gm-Message-State: ALQs6tDlo0NBaCd10a0ig3PjSp1/qb9uQM/5zpe2zbrp2qT2u0uaPhL2 IDimbukEFGhcvNbga1+/TW8= X-Received: by 10.98.147.66 with SMTP id b63mr39324292pfe.130.1525767707790; Tue, 08 May 2018 01:21:47 -0700 (PDT) Received: from oslab.tsinghua.edu.cn ([2402:f000:1:4413:9049:25cd:b90:73a0]) by smtp.gmail.com with ESMTPSA id v5sm16454034pff.130.2018.05.08.01.21.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 May 2018 01:21:47 -0700 (PDT) From: Jia-Ju Bai To: tj@kernel.org Cc: linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] ata: libata-pmp: Fix a possible data race in sata_pmp_handle_link_fail Date: Tue, 8 May 2018 16:21:40 +0800 Message-Id: <20180508082140.14038-1-baijiaju1990@gmail.com> X-Mailer: git-send-email 2.17.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The write operation to "link->flags" is protected by the lock on line 898, but the read operation to this data on line 892 is not protected by the lock. Thus, there may exist a data race for "link->flags". To fix this data race, the read operation to "link->flags" should be also protected by the lock. Signed-off-by: Jia-Ju Bai --- drivers/ata/libata-pmp.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/ata/libata-pmp.c b/drivers/ata/libata-pmp.c index 85aa76116a30..42f61106ac70 100644 --- a/drivers/ata/libata-pmp.c +++ b/drivers/ata/libata-pmp.c @@ -889,15 +889,14 @@ static int sata_pmp_handle_link_fail(struct ata_link *link, int *link_tries) return 1; /* disable this link */ + spin_lock_irqsave(ap->lock, flags); if (!(link->flags & ATA_LFLAG_DISABLED)) { ata_link_warn(link, "failed to recover link after %d tries, disabling\n", ATA_EH_PMP_LINK_TRIES); - - spin_lock_irqsave(ap->lock, flags); link->flags |= ATA_LFLAG_DISABLED; - spin_unlock_irqrestore(ap->lock, flags); } + spin_unlock_irqrestore(ap->lock, flags); ata_dev_disable(link->device); link->eh_context.i.action = 0; -- 2.17.0