Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3634808imu; Mon, 28 Jan 2019 08:11:19 -0800 (PST) X-Google-Smtp-Source: ALg8bN4E4eoRVAEsbN4pBG0leBCCYRYQN3i+wKUgxR41Q/H6MfelyTxCQS2LUEBAOUBlBLIbC3ow X-Received: by 2002:a65:560e:: with SMTP id l14mr20338976pgs.168.1548691879603; Mon, 28 Jan 2019 08:11:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548691879; cv=none; d=google.com; s=arc-20160816; b=wR06n3Y9gS6uy/ge4rGH3Fr+phEssAAG43tWEkR5lykM6anIWa5pt3kvUwnqFe9J7O 9X5cNa2FQvQZNde+PhuHfIvw//CRbGvFRa6HvnRlnqZ8eCtsP69zxbbiRkQcshfFddMw CrVaufjswb+WiaEaFeWexmxbZfVBILRHYooGWUmBcnk1f+FhaKtdyHmv/jVhIsu4LuYQ njvq4BXZORT5xhevGCNDxbxXzwuWM0AG6eEWIolieAXV/77XD3ltB4F0ztm+pPmmjOdA o+HdKjNSGLuAtj15XmB+dvG4vt+Ish+c34BK6IpI1a1jSjsLnqrU5cRmTavcvSzyGEk1 4eSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Ed9nVB0wH+MXm0nRHVphYS804qCoTtjiuRfyHjnnaXY=; b=kbhwiqheUI9qfgmBE5GxztAPuiW16JFLWpZONYvSKbXkp14mY2zM0sHc2cuO+BCakI Dzgs62bxoEDTVMJwUakCS4tJhDH1/KosR6qlfEcGF6QOmPcsjB2NsrkgZQhsW0h1iEkh PSZhqtqDiQC1YA2znES0GogQjrdh2i9hdGweWM/wO654W7i+xy6zGUnf4v5HvDInp30q CrHsGaBYLCWfq/5cKe8mBsXJTrkIQwj5Qjq8/iZhvtsN5ZtAwaytv3dbDyEh5D/ZodTL mYVkydcjx33FqF+MCnGTLrQIjtrbl3D97VPQ69UKNFrBtVSzaM7XICFgR2I+D1MbA9fP tNIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TbxsSvpr; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i129si36322831pfb.32.2019.01.28.08.11.04; Mon, 28 Jan 2019 08:11:19 -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; dkim=pass header.i=@kernel.org header.s=default header.b=TbxsSvpr; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732496AbfA1QIx (ORCPT + 99 others); Mon, 28 Jan 2019 11:08:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:32828 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731323AbfA1QIw (ORCPT ); Mon, 28 Jan 2019 11:08:52 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EC75E2147A; Mon, 28 Jan 2019 16:08:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548691731; bh=lW34iHSQcZJ+uNbYPwul3+/VjEc8ceDuGS7KkJJERxo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TbxsSvpr/R1amX6GS8KxuTzLbzNhRPQXnG8z8Q57Sm3KCuv5SMYeUT5kQ84hb+QWa wnKpN/DmuCmRXkgoMNA8dvupCAiOaKR9h/d+lD0CfMfRoMZedm2Rdo27BTGW7ZFMOr 1msJzbYtCd+QiS7IXCbS7E+DeQ8rPgFB8xdIpDqE= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Roland Kammerer , Jens Axboe , Sasha Levin , drbd-dev@lists.linbit.com, linux-block@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 199/258] drbd: narrow rcu_read_lock in drbd_sync_handshake Date: Mon, 28 Jan 2019 10:58:25 -0500 Message-Id: <20190128155924.51521-199-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190128155924.51521-1-sashal@kernel.org> References: <20190128155924.51521-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Roland Kammerer [ Upstream commit d29e89e34952a9ad02c77109c71a80043544296e ] So far there was the possibility that we called genlmsg_new(GFP_NOIO)/mutex_lock() while holding an rcu_read_lock(). This included cases like: drbd_sync_handshake (acquire the RCU lock) drbd_asb_recover_1p drbd_khelper drbd_bcast_event genlmsg_new(GFP_NOIO) --> may sleep drbd_sync_handshake (acquire the RCU lock) drbd_asb_recover_1p drbd_khelper notify_helper genlmsg_new(GFP_NOIO) --> may sleep drbd_sync_handshake (acquire the RCU lock) drbd_asb_recover_1p drbd_khelper notify_helper mutex_lock --> may sleep While using GFP_ATOMIC whould have been possible in the first two cases, the real fix is to narrow the rcu_read_lock. Reported-by: Jia-Ju Bai Reviewed-by: Lars Ellenberg Signed-off-by: Roland Kammerer Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/block/drbd/drbd_receiver.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c index 75f6b47169e6..45ac5fe288e4 100644 --- a/drivers/block/drbd/drbd_receiver.c +++ b/drivers/block/drbd/drbd_receiver.c @@ -3364,7 +3364,7 @@ static enum drbd_conns drbd_sync_handshake(struct drbd_peer_device *peer_device, enum drbd_conns rv = C_MASK; enum drbd_disk_state mydisk; struct net_conf *nc; - int hg, rule_nr, rr_conflict, tentative; + int hg, rule_nr, rr_conflict, tentative, always_asbp; mydisk = device->state.disk; if (mydisk == D_NEGOTIATING) @@ -3415,8 +3415,12 @@ static enum drbd_conns drbd_sync_handshake(struct drbd_peer_device *peer_device, rcu_read_lock(); nc = rcu_dereference(peer_device->connection->net_conf); + always_asbp = nc->always_asbp; + rr_conflict = nc->rr_conflict; + tentative = nc->tentative; + rcu_read_unlock(); - if (hg == 100 || (hg == -100 && nc->always_asbp)) { + if (hg == 100 || (hg == -100 && always_asbp)) { int pcount = (device->state.role == R_PRIMARY) + (peer_role == R_PRIMARY); int forced = (hg == -100); @@ -3455,9 +3459,6 @@ static enum drbd_conns drbd_sync_handshake(struct drbd_peer_device *peer_device, "Sync from %s node\n", (hg < 0) ? "peer" : "this"); } - rr_conflict = nc->rr_conflict; - tentative = nc->tentative; - rcu_read_unlock(); if (hg == -100) { /* FIXME this log message is not correct if we end up here -- 2.19.1