Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp178606imd; Wed, 31 Oct 2018 16:54:30 -0700 (PDT) X-Google-Smtp-Source: AJdET5driGG/UvxNvwBKZ9OgjhcVPs8Xj2NZLoF/X8EA1C8uh4ljrRxe2ota9tkhQFCYlVpykzI/ X-Received: by 2002:a63:86c2:: with SMTP id x185mr4672407pgd.230.1541030070091; Wed, 31 Oct 2018 16:54:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541030070; cv=none; d=google.com; s=arc-20160816; b=RmJxdtQM2IxUs/TX6r+aqcI8GmpE0hRu5AH+2mBVvgX9vYe+ciAvv0u633eD0Q0g8L bjCPmL0q/g11M2T/aXfBDhB7xNVovS/h3CsJHb72VIc0KmsUz+jFikjEww25CXpMCpQ9 cMkZ6XafmuBWkKBWQ2N87utonLDauOwMHUVI/GWthnkOhmrQiDm85tmGIurbJmoIQ7mr MPedq5o9rx3yDyVIgoN4McGDZH+LusuZgs5FT3CUabDDV95MOICORY3ocd4V4avDXG+P MAtNJi7JZHvlBf3brxpybNmjI1aIyLlfsh/DluZZfs7OVvlrjml2mJ76bN0s9fXF4SUl oJeg== 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=m9Pt2aWhy9JWHf7SxARfrgqCSBos+78d4c9mtpGxwHA=; b=ZKP2di13NYzPV6osbSXBfjzB/kdVp1TGlzx8484284Bc9i1jhMoz+END7pLn5Ke+ez S24vG1nID4Wt8m+BvvlyPFbfTTzoq2PgiTqROXFdAz+99CiezZvwfGEfy7g93+ZI7XDu cR0CwW7JRd/O4MxngIDNuEEtqTlekkwPplxusaB93uP746+HZQ2BlaHGRHwHS7DMYY0y RwWLZHRuh827TxYb3xhIBBg4M+HxIUrdHLNNGAp6uTHpw84ZMMURbRpNayrpptc2KjQT ReQ2Sw3niZ7cqfPqVGEHmq3HZbYSni5fyA2rMraQT0NNluzOeRzdPvOyehhnqL0dSUJh KGfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1fDyhSjn; 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 94-v6si8261466plb.87.2018.10.31.16.54.15; Wed, 31 Oct 2018 16:54:30 -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=@kernel.org header.s=default header.b=1fDyhSjn; 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 S1727843AbeKAIyU (ORCPT + 99 others); Thu, 1 Nov 2018 04:54:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:52860 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727312AbeKAIGH (ORCPT ); Thu, 1 Nov 2018 04:06:07 -0400 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 E34372085A; Wed, 31 Oct 2018 23:05:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541027157; bh=aPI56e/X7Fen3qsq7FQyLmzMg0HBIEjJB7cM+v0IHpk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1fDyhSjnT+afS4T+tRBORMkcuFGQcXEilwFgPMdsjEZPabMrCZYUbzGQ/k3YJvsfn ICifSVnfh+S1IUhmAmP7RcmPN8DGmuILdUrNYIYjye+4LMnowrjLsh+YJDTxmVmshy mryZHga6pqq/jh2uQ05QV0AiTM+bD9BkQjjBdufY= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Javier=20Gonz=C3=A1lez?= , =?UTF-8?q?Javier=20Gonz=C3=A1lez?= , =?UTF-8?q?Matias=20Bj=C3=B8rling?= , Jens Axboe , Sasha Levin Subject: [PATCH AUTOSEL 4.19 016/146] lightnvm: pblk: fix race condition on metadata I/O Date: Wed, 31 Oct 2018 19:03:31 -0400 Message-Id: <20181031230541.28822-16-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031230541.28822-1-sashal@kernel.org> References: <20181031230541.28822-1-sashal@kernel.org> 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 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 --- drivers/lightnvm/pblk-write.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/lightnvm/pblk-write.c b/drivers/lightnvm/pblk-write.c index ee774a86cf1e..879227d584e7 100644 --- a/drivers/lightnvm/pblk-write.c +++ b/drivers/lightnvm/pblk-write.c @@ -417,12 +417,11 @@ int pblk_submit_meta_io(struct pblk *pblk, struct pblk_line *meta_line) 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_submit_meta_io(struct pblk *pblk, 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)) -- 2.17.1