Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2941978yba; Sun, 28 Apr 2019 12:54:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqwgZCvmWBFJ61HOF54vc+kC5XGSYiMhQNZqZ4c6pHZXM8M3BOsIorIjPtzjOWo6BtJOg1Sm X-Received: by 2002:a63:5466:: with SMTP id e38mr56255061pgm.340.1556481297665; Sun, 28 Apr 2019 12:54:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556481297; cv=none; d=google.com; s=arc-20160816; b=MxE56n/6t/wdbSsu4OOxAX0n470yt+pzGoeOfcIE93xtrGZXKX3dXhg0SRzvxUp908 JkecpFUoFj25vH8dzE0IWRr1mNAdEgj7BT5K9qGwcN7h/hPCFVKUkuJECRhqheov3b9w bgH2/2/KBJVFMqsSZfXop7gmb/pH5PWVng78hyU+1ZDo1tnLpo075s9vpOWnmILSq6hl 0nb2SwpOa9PPmLWRBRiyLtchXp3JtXOvgidzWW8r0NctHCEgKWnfrpT72XqqZ1R9Ev0W PS9IuZUe86o9ebqf6JyKj2BHnzNs0vnbr+ZZkEUk0vKyqmRxAY3gKKjf+VhPujd1stwR 1CYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=ow0hOBCWNf9L4Sr2+kvBTmny91Rm+CzMXx0+dpHwDRU=; b=E8X1qZCnb+ODNr7ikgu9c11ke5UGoIAss9ee+uWSSLYOWQuIk+k/UyoFvDy/qrAF5V 9c4HKHSXvdnRDe/+QQEGOdtnv0LcYqXRBkxR7hK9BvWXv3JHIiUi/4Br3abS5T/AFfmO +qIXDN/zh1Hq6mztU+hkO1vkWjpa1KNqEgWW0xTBQng0gPNyBA8gYzB2OF57UZR7gEgk 4O1MXY+Fm9tJr5EH8rSNEUgQORA8S3eMNuEnUu9IFYnCPM+gGdevRgDpdv37zpgOGI7j 3USOJWoGxKWb0Wvcwl4rAysecXqZDepfpMPcroDTg2EMN0Z17lbaoashwMS7H1WlgT+i c+lQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ZP7OsTV7; 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 u4si11606031pgp.477.2019.04.28.12.54.42; Sun, 28 Apr 2019 12:54:57 -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=ZP7OsTV7; 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 S1727180AbfD1TxX (ORCPT + 99 others); Sun, 28 Apr 2019 15:53:23 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:45464 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726315AbfD1TxW (ORCPT ); Sun, 28 Apr 2019 15:53:22 -0400 Received: by mail-qt1-f193.google.com with SMTP id b3so9722725qtc.12; Sun, 28 Apr 2019 12:53:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ow0hOBCWNf9L4Sr2+kvBTmny91Rm+CzMXx0+dpHwDRU=; b=ZP7OsTV7OnO15ur8/sU+Vk4YTNDhi/gFAmnK2tuUeF9s+hZY9txYbrw5JydmT9L471 ByHrvrG/OcyFjzqkFEiM0kcRuC0bEcdpb8hCYSc2lLPbyNiMem69tgyY5XHlYHwWw9tz ehzRrfKtU51Mna/DuGIie3Ora8+3utNt+BaTuJ6IjuV2Egv0tme9zPjWlXXYTtNypTQ1 63H4dT2aaOySOywLwePW5IhvrqI02Gn5I0LReUYhXKB6JuWyhP1Zys5YFsv1sRMNrKrT K48z1BER14z1kkolRo6vK+yIxbmz/GorjCXF5LMhJ2Iv+ur7kQuSOIphH5NrbiMdMy1c r9Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ow0hOBCWNf9L4Sr2+kvBTmny91Rm+CzMXx0+dpHwDRU=; b=isFtPsjfWYSnrHNj58XIey63tYfF18ys0pEL9TxPMzdOF1BYcZ+0CTyQ8OL5FKc+kC fNJjtVT/WebcG1oqJViEwVq9V9c+E/JTdv4NOsiRdpAcqX6VJOivGpoBDaOwkSx+UJVs QQW53STSG3xbTdE7mXhemhGT82P+lDdLM0/dNU6OJAgECIYgGnea32Lur2heJTTp5t9o oiGHLqvTWQRRL0uuJx1GKq4SPtikcs2LF8c3hcWuPNSVgFxw/Nk73G12C5/vZap30oDU ruCqPtu5zr2PrLIlJpv1e8OVqXVjXgx3kxTGdD2KqXDTePLfOqLeKyVXn8y31f0rVCZz vk/Q== X-Gm-Message-State: APjAAAXk3k+kyQ6DK/Fj4skhTICYyM/lwyes6pcm2Q6Vd0LFUFL39vf9 +MVMPnmk+rzlX49yJkVrSFlGDAHOtpAkQ9yh8QM= X-Received: by 2002:ac8:25b8:: with SMTP id e53mr10755423qte.194.1556481201803; Sun, 28 Apr 2019 12:53:21 -0700 (PDT) MIME-Version: 1.0 References: <20190428104041.11262-1-lukas.bulwahn@gmail.com> In-Reply-To: <20190428104041.11262-1-lukas.bulwahn@gmail.com> From: Song Liu Date: Sun, 28 Apr 2019 12:53:10 -0700 Message-ID: Subject: Re: [PATCH] md: properly lock and unlock in rdev_attr_store() To: Lukas Bulwahn Cc: Shaohua Li , Neil Brown , Arnd Bergmann , Himanshu Jha , clang-built-linux@googlegroups.com, linux-raid , open list Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Apr 28, 2019 at 3:41 AM Lukas Bulwahn wrote: > > rdev_attr_store() should lock and unlock mddev->reconfig_mutex in a > balanced way with mddev_lock() and mddev_unlock(). > > But when rdev->mddev is NULL, rdev_attr_store() would try to unlock > without locking before. Resolve this locking issue.. > > This locking issue was detected with Clang Thread Safety Analyser: > > drivers/md/md.c:3393:3: warning: releasing mutex 'mddev->reconfig_mutex' that was not held [-Wthread-safety-analysis] > mddev_unlock(mddev); > ^ > > This warning was reported after annotating mutex functions and > mddev_lock() and mddev_unlock(). > > Fixes: 27c529bb8e90 ("md: lock access to rdev attributes properly") > Link: https://groups.google.com/d/topic/clang-built-linux/CvBiiQLB0H4/discussion > Signed-off-by: Lukas Bulwahn > --- > Arnd, Neil, here a proposal to fix lock and unlocking asymmetry. > > I quite sure that if mddev is NULL, it should just return. I think current code will just return -EBUSY when mddev is NULL, right? Song > > I am still puzzled if the return value from mddev_lock() should be really > return by rdev_attr_store() when it is not 0. But that was the behaviour > before, so I will keep it that way. > > drivers/md/md.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/md/md.c b/drivers/md/md.c > index 05ffffb8b769..a9735d8f1e70 100644 > --- a/drivers/md/md.c > +++ b/drivers/md/md.c > @@ -3384,7 +3384,9 @@ rdev_attr_store(struct kobject *kobj, struct attribute *attr, > return -EIO; > if (!capable(CAP_SYS_ADMIN)) > return -EACCES; > - rv = mddev ? mddev_lock(mddev): -EBUSY; > + if (!mddev) > + return -EBUSY; > + rv = mddev_lock(mddev); > if (!rv) { > if (rdev->mddev == NULL) > rv = -EBUSY; > -- > 2.17.1 >