Received: by 10.223.185.111 with SMTP id b44csp905732wrg; Fri, 9 Mar 2018 16:30:56 -0800 (PST) X-Google-Smtp-Source: AG47ELuhTVgL6d/c1C/vUsah9ZAJSVQvcvM06y25X+UY4zynuSdm+s0e7HZzezrB4+B7ROAuisFh X-Received: by 10.98.242.6 with SMTP id m6mr334607pfh.230.1520641856689; Fri, 09 Mar 2018 16:30:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520641856; cv=none; d=google.com; s=arc-20160816; b=PZMhu6MNdFl3RkVbpGBQX3ID4YVB3Kq7eGh599HE2zKlsF4zTBMfCL5YG4NDPn2Hid ArIPihohZDZwiX7GAfzjKE7gTcYxAYSkx7SMCfcdZGZYsD0otha9QtH45DjSo1ZCpP43 pYu6eZy5pNw/gs9zDOezT4kwWWmXvhqPQ+qYMjQeFYA8aDRoFiktL6nQy+ooSkv7brEl 1rbYtvkydu49Gy1BRiTnUmE2ZRYLMdPva8QGopbD5LWEvaPlGoGdeX3q5O8XOQnenmF7 cmocCJXn3/Xb5xlMuL6Bof8y0TqBY/swI/Tq/zYAhZrQ8EnM7ecT6QF1OBAXhEvdtWQJ slMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Sy+BIoF1s7n1YtezsJli0XEZsCjPBmnHDP7BexnBqB4=; b=Bm6+DUtAxVewT2rYPbm5Bz6/i6GlsbbxQfec437kcGA2k+SJiOPf9GGJYHnZ+M+g8A qTYCkrSljKcZQaecIav453Dpt2sjHP91TvazIypU8ToQRQkCsoKD4VcsaT6lIjNJij0x 5FR2+9ipnAC0rdh9ek81Vg8CJMPlqFmKa5EWlMrkV9xTBZ9+4wu0zGeGBKo0ZWqDcMo7 30ltzUAGtots71vk2swOm+QXKvAyY2kuJlSz3WIVB3wv4vJNHQDjcLATYnpMRQeemLaQ 2F6hIJFwYrkNeEAfUi0cVH9pL/U2Ym3AlxPJif6sZhD/5rnkHNMv39HlgzOeF7RQT2Pw 7Xsg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 37-v6si1743254plq.451.2018.03.09.16.30.42; Fri, 09 Mar 2018 16:30:56 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933993AbeCJAWz (ORCPT + 99 others); Fri, 9 Mar 2018 19:22:55 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:40232 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933946AbeCJAWw (ORCPT ); Fri, 9 Mar 2018 19:22:52 -0500 Received: from localhost (unknown [185.236.200.248]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 216B21192; Sat, 10 Mar 2018 00:22:52 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, yuyufen , Tomasz Majchrzak , stable@ver.kernel.org ("v4.8+"), NeilBrown , Shaohua Li Subject: [PATCH 4.9 30/65] md: only allow remove_and_add_spares when no sync_thread running. Date: Fri, 9 Mar 2018 16:18:30 -0800 Message-Id: <20180310001827.315883030@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180310001824.927996722@linuxfoundation.org> References: <20180310001824.927996722@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 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 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: NeilBrown commit 39772f0a7be3b3dc26c74ea13fe7847fd1522c8b upstream. The locking protocols in md assume that a device will never be removed from an array during resync/recovery/reshape. When that isn't happening, rcu or reconfig_mutex is needed to protect an rdev pointer while taking a refcount. When it is happening, that protection isn't needed. Unfortunately there are cases were remove_and_add_spares() is called when recovery might be happening: is state_store(), slot_store() and hot_remove_disk(). In each case, this is just an optimization, to try to expedite removal from the personality so the device can be removed from the array. If resync etc is happening, we just have to wait for md_check_recover to find a suitable time to call remove_and_add_spares(). This optimization and not essential so it doesn't matter if it fails. So change remove_and_add_spares() to abort early if resync/recovery/reshape is happening, unless it is called from md_check_recovery() as part of a newly started recovery. The parameter "this" is only NULL when called from md_check_recovery() so when it is NULL, there is no need to abort. As this can result in a NULL dereference, the fix is suitable for -stable. cc: yuyufen Cc: Tomasz Majchrzak Fixes: 8430e7e0af9a ("md: disconnect device from personality before trying to remove it.") Cc: stable@ver.kernel.org (v4.8+) Signed-off-by: NeilBrown Signed-off-by: Shaohua Li Signed-off-by: Greg Kroah-Hartman --- drivers/md/md.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -8224,6 +8224,10 @@ static int remove_and_add_spares(struct int removed = 0; bool remove_some = false; + if (this && test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) + /* Mustn't remove devices when resync thread is running */ + return 0; + rdev_for_each(rdev, mddev) { if ((this == NULL || rdev == this) && rdev->raid_disk >= 0 &&