Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3490783imu; Sun, 11 Nov 2018 16:17:23 -0800 (PST) X-Google-Smtp-Source: AJdET5clwTyAX3YccvM0CU5ry+nN9mrRjEva2kGw7VGYNfncxTNGJr525wbZrpmxgzfV5ir3rRSB X-Received: by 2002:a63:e445:: with SMTP id i5mr15594110pgk.307.1541981843913; Sun, 11 Nov 2018 16:17:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541981843; cv=none; d=google.com; s=arc-20160816; b=Fu6HK7I8eM0H0flVB82CbaJE9uMgpdteDA9DJOs5ofZcV3AbhL2wd+3h5kYAC9llrS YyWTV7Gl9U9VNA+vtqxMS1Qi2Zu5sW1PNTTm7jhqNUC4sdPUPiHMTvL8Ck2ChLlRQXXN UIF4UNIquB4rE+Zb/514YshV0YsCDmIiH0PIp7eQbms1zTtYDIAusnNzVRjCo4N8DBcy 6pdQgc5bA313UsGNGZKv2sD898IViQoG25VbagpZ+NOwpCNPQSEEQhaJsdCIqOW533Uw 4TJIq/vYyQ75hxXfU+g4yoXzwF9Wzme9WatGqB/5gThMFWxTcHkXeHMhu276Q2hCzHoW Q4ZQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=PhS58sXRfO/zf1Or+FFK0uBETWPavndmJysvuUYVTlI=; b=UxSNoc1qrORdTJK+YbZWpmLGZPR+AZaJJdAaDsCeBNn8L2qE4frAhXjMIw1FJ3PpZF BaAU4eEsdZ4C4zUHKssxAcX6u5okpry5WgcnBIHX1747t77KGENLbbkVt1JqYXx8D/5S KKiFevWz4YtU9LL0IxRl314Zo8QK/uj7bfc80DHLDfUlzlhohvof79c+C4AhzzHAr5zc tvP6/SQYGmTThEVaEBBzp60CzbRu3RruHaaGcfkG6jZAzc5Mh+Bj2O+aduHxbcXFmA3u jR+TBKxzcfOS657pEGi9waMM6CL1+quDnjobh8t/thf9OgtpHvOH8CaRYMbRVN2W7OgA HLeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=djZW9tEu; 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 f3-v6si16019295pld.186.2018.11.11.16.17.08; Sun, 11 Nov 2018 16:17:23 -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=djZW9tEu; 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 S1730583AbeKLKGE (ORCPT + 99 others); Mon, 12 Nov 2018 05:06:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:59862 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730098AbeKLIRK (ORCPT ); Mon, 12 Nov 2018 03:17:10 -0500 Received: from localhost (unknown [206.108.79.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5121721508; Sun, 11 Nov 2018 22:27:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975234; bh=lMuMJnzDI7WMeIEanwHbhoBgtXgYL5HcMNIqQ/aYq7Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=djZW9tEuuFazMqagzdCYd8xsGi1F1I7l3wZ4vzdNu3f3v2s60scMxjN+h8b9emWbU fem3JY2RmeuOMeayBKylTLBs6ZnD0GqxxEc4/0xfCp37zINgbuqHF/Xhl2w2L3C84q yk/WXKJP8JI7yDaASyxPYAZ66LIRKhZoCJOvGzDk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Javier=20Gonz=C3=A1lez?= , =?UTF-8?q?Matias=20Bj=C3=B8rling?= , Jens Axboe , Sasha Levin Subject: [PATCH 4.19 062/361] lightnvm: pblk: fix race condition on metadata I/O Date: Sun, 11 Nov 2018 14:16:49 -0800 Message-Id: <20181111221628.628372058@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Javier González [ Upstream commit d8adaa3b86324c6186d0adf74bc256bdacfffdb6 ] In pblk, when a new line is allocated, metadata for the previously written line is scheduled. This is done through a fixed memory region that is shared through time and contexts across different lines and therefore protected by a lock. Unfortunately, this lock is not properly covering all the metadata used for sharing this memory regions, resulting in a race condition. This patch fixes this race condition by protecting this metadata properly. Fixes: dd2a43437337 ("lightnvm: pblk: sched. metadata on write thread") Signed-off-by: Javier González Signed-off-by: Matias Bjørling Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/lightnvm/pblk-write.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) --- a/drivers/lightnvm/pblk-write.c +++ b/drivers/lightnvm/pblk-write.c @@ -417,12 +417,11 @@ int pblk_submit_meta_io(struct pblk *pbl rqd->ppa_list[i] = addr_to_gen_ppa(pblk, paddr, id); } + spin_lock(&l_mg->close_lock); emeta->mem += rq_len; - if (emeta->mem >= lm->emeta_len[0]) { - spin_lock(&l_mg->close_lock); + if (emeta->mem >= lm->emeta_len[0]) list_del(&meta_line->list); - spin_unlock(&l_mg->close_lock); - } + spin_unlock(&l_mg->close_lock); pblk_down_page(pblk, rqd->ppa_list, rqd->nr_ppas); @@ -491,14 +490,15 @@ static struct pblk_line *pblk_should_sub struct pblk_line *meta_line; spin_lock(&l_mg->close_lock); -retry: if (list_empty(&l_mg->emeta_list)) { spin_unlock(&l_mg->close_lock); return NULL; } meta_line = list_first_entry(&l_mg->emeta_list, struct pblk_line, list); - if (meta_line->emeta->mem >= lm->emeta_len[0]) - goto retry; + if (meta_line->emeta->mem >= lm->emeta_len[0]) { + spin_unlock(&l_mg->close_lock); + return NULL; + } spin_unlock(&l_mg->close_lock); if (!pblk_valid_meta_ppa(pblk, meta_line, data_rqd))