From patchwork Tue Oct 9 11:11:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Matias Bjorling X-Patchwork-Id: 10632337 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7587D15E8 for ; Tue, 9 Oct 2018 11:17:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 563AC28A45 for ; Tue, 9 Oct 2018 11:17:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4AF4728A6E; Tue, 9 Oct 2018 11:17:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E3CBD28A45 for ; Tue, 9 Oct 2018 11:17:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726562AbeJISeK (ORCPT ); Tue, 9 Oct 2018 14:34:10 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:41653 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726977AbeJIS35 (ORCPT ); Tue, 9 Oct 2018 14:29:57 -0400 Received: by mail-pl1-f195.google.com with SMTP id q17-v6so664473plr.8 for ; Tue, 09 Oct 2018 04:13:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lightnvm-io.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AYVRZNNBiLGoGN7ee6jJBIiPOJAQ8oCo8VOfejch4uU=; b=bUIxXt4Nz+3DxXDiFwyHugI/mcQCkIzFhOAj3gLrGA6nGNDITCnTgQJjJ7DMFCD71M U5e8s4xN08HS/glgGE9tc0MgYF6QYoksFNM/U1yScZJbS+ikUuZUfakfbXDhe8uxKZ8P QcWFlaiVs4+bdeaTWNCS3xrfdK6v7qoxAPya/6TJKEp59u17LPjgioyffxwxitAsOVd5 xhv4+oYv04L+7kJHM+1aeX+6sYtlTcv0XDDF7aBFCLztaX/azlEn47KVIpkivBP0unAd alZTV/AVe9oVyrf9h/qP0oxVxUrudXN39Mf2qXBXmgtdYS2j5n398Bh79Qp8g16rtCHJ CyeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AYVRZNNBiLGoGN7ee6jJBIiPOJAQ8oCo8VOfejch4uU=; b=Zpr3sYPBl4WF6fqyB3O/QL9LWaxFlHOFEuQBixc9kvjjoZRf+vqw7VzTTdY3ce+HlP nFuJfulDWLyOsVI1zgrcHXBwwpUUuz+2Wq4SBpkdnyjSmihKEFiLTBkz+3YacxhFlDYg fK45Bn6FVhlP4SktczIVR7egIBAX9ae1KGXgWfBb2Skrra2/8niNcQmfbjZErn9EmpOO imOoZwRKYY7pj0oeUjHOL2wSii1rbCRH5BojEajfbUxGylxFT5Uo+56SDXNlIfmajsko kXTtT6G8Wf/MMup+hCoi5fatDU9OZD+JCQYsR58Wg19VEfWuUYtVOtN/zNijU7ebCVGl MyzQ== X-Gm-Message-State: ABuFfohzZrrFd7T3MaF5uM5kSDDSAgx/66QmdXg/IwGI66TM8aE3ISUT ZUrZWT4zAtJ6UsUUfLTlbND8ag== X-Google-Smtp-Source: ACcGV61+LiSd0BrqhYVRAPHeLj4IrKx0XJOCpzRAcIR3gkII0nlUFJLFDSrFlZhaABudgrY0+sdbvw== X-Received: by 2002:a17:902:5590:: with SMTP id g16-v6mr27914511pli.46.1539083610996; Tue, 09 Oct 2018 04:13:30 -0700 (PDT) Received: from skyninja.hgst.com (rap-us.hgst.com. [199.255.44.250]) by smtp.gmail.com with ESMTPSA id p1-v6sm25342380pff.128.2018.10.09.04.13.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Oct 2018 04:13:29 -0700 (PDT) From: =?utf-8?q?Matias_Bj=C3=B8rling?= To: axboe@fb.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Jav?= =?utf-8?q?ier_Gonz=C3=A1lez?= , =?utf-8?q?Javier_Gonz?= =?utf-8?q?=C3=A1lez?= , =?utf-8?q?Matias_Bj=C3=B8rling?= Subject: [GIT PULL 05/45] lightnvm: pblk: fix race condition on metadata I/O Date: Tue, 9 Oct 2018 13:11:35 +0200 Message-Id: <20181009111215.7653-6-mb@lightnvm.io> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181009111215.7653-1-mb@lightnvm.io> References: <20181009111215.7653-1-mb@lightnvm.io> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Javier González 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 --- 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 508c63701eda..df99c45778d4 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))