Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp591584imm; Fri, 17 Aug 2018 03:23:38 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzP1uNy1e9wvE4qNQbGOlRzv2vUyJdFAqJUTh9iGRWkkNUP42e7qchO4lodGMWl5DRWydu7 X-Received: by 2002:a63:d54e:: with SMTP id v14-v6mr32983264pgi.264.1534501418630; Fri, 17 Aug 2018 03:23:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534501418; cv=none; d=google.com; s=arc-20160816; b=BB1DMKIUzE7F7QjMVocTCoL3XrYJffisSK4v2bnP9qRjFxlz0B55PCTbUAOJyPDJqe PNCm1NAAOerBCSEpuIa5fx61InrYbeqiFuD3s2xWfeEgSt7vr7SarVaFVCPV9hkxUstd 4kWPB8CHmvGUA9FQzz0UQ2xq7mwg5pFGpJPfQrZnrzIDRuv2FvN8XbGYlXxFwPIASiCF bbytESpZaQsCYPYam76nQL+WSccJd9q+jc+qogWrB/4gpWzEhVs/IwlC9P/KmUz/O2sX MR2/jhhsSiBZZlZJRbk8KHsMuLmW5DC1TH8uPeqaIn2EuPxvIrUzuhgv743b5+fvA328 vw6w== 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 :message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=hVfKH5fxvtMI2nn+wFotQVSEFmCc6QzAd/OwPbB5mRw=; b=DQaHy2hcvryxZrKlMgp+e6OARAPNrBsYmEOeEpeflnYeoBUPrLxOQ1VYr/k4SdXJ03 2S6tvNlcYOX835SPwfduatzSi48clrxyasX/28W5InWSxgFJhFHkA9vHR6wsLfGOJJyi dryklV3QsPM1PZ/uMlAJ9uEFaqJ4FIU2DH35JJUPJwyu0w4+3n4vvEP0YoWw9hlVwlNr TpYnYG1iTzKyVEasF5vAdDOORrEsSF50bykFbbKBK+sOjFmy66gPt4NKs1wfLwi1+MFN P9R4T8Mc9BXxNua0McMjRg9becxRknCj+LWwEcqyXJ1NjuAc9C9bSEvpOfA+WJN7jv7w 99Ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@javigon-com.20150623.gappssmtp.com header.s=20150623 header.b=JXdXzh8B; 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 a35-v6si2088640pla.27.2018.08.17.03.23.23; Fri, 17 Aug 2018 03:23:38 -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=@javigon-com.20150623.gappssmtp.com header.s=20150623 header.b=JXdXzh8B; 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 S1726530AbeHQNZJ (ORCPT + 99 others); Fri, 17 Aug 2018 09:25:09 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:45669 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726294AbeHQNZI (ORCPT ); Fri, 17 Aug 2018 09:25:08 -0400 Received: by mail-ed1-f66.google.com with SMTP id s16-v6so4248153edq.12 for ; Fri, 17 Aug 2018 03:22:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=javigon-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=hVfKH5fxvtMI2nn+wFotQVSEFmCc6QzAd/OwPbB5mRw=; b=JXdXzh8BY0BBYk/N95Ue2lFimLeZbiZtnJhSYmgiqG1RK+gd4TDjOAfJ3v88QfKZR9 dKJKVxx4xbqvt4gpGwlnTvVG0shMGNrP7yRIM4kl8BoBUdHCSdhifETV/q/jaF/3cavQ JtEhBGuC2QC3Csv/GRRVkLYGB8ZARIpAo1dOWG0fYO5iYDHJM7OKmZKuqEOxGr0S6enl QPZ+aD5t0pu1GH4d1GKmf+tJUc7wSwCChDrqqxjjprkmeH+b0xu/Wha48q4fbEuaX5FO nHidHosrb+ewj8TpsiYyVkinaO/ffPcogmRCfCPqXGjaEhS5n6+cl2BOzbhX4QedHnZ1 Z0Ng== 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:mime-version :content-transfer-encoding; bh=hVfKH5fxvtMI2nn+wFotQVSEFmCc6QzAd/OwPbB5mRw=; b=KbcXNXQ3gsjRFiwOHDbUiXNk4lGm/MuCoAsySyiUqTZ1ZQbVdSkpMobuxChtIczmw/ PnIvlT0/FVmVkDIRjcsIYHRmyFMyDUNZXdng9IRSnXqprEzSYBTHqDl09YwJciSnKV5x L98nSONKVtP6LxwtXijwOlMJjOU5ChPw30o4k3XnL6a1xYj98tGkzl6u4nHO18yC1XKi /reBD+BVY75EsN0JT1Xr/FEd4WaeurWr19wxF4Q2MRA0zj3QqSjFBYEmnuSuxXQxUacS 89Phqm0PzWyIvMBkO8KKcn0hF7LLCnHrdY59QohS+euXefJcJPWhA4pTbDYAmq7cyoAq oK3Q== X-Gm-Message-State: AOUpUlG/r1zOgkDFxtQBlKtF03QfwC10lzLW0PkQ4J+C/ltcz+42OYAt 4W1ZPyIlTA8eOtT8d1XpXlBwKg== X-Received: by 2002:a50:c082:: with SMTP id k2-v6mr40353218edf.294.1534501335088; Fri, 17 Aug 2018 03:22:15 -0700 (PDT) Received: from ch-wrk-javier.cnexlabs.com (6164211-cl69.boa.fiberby.dk. [193.106.164.211]) by smtp.gmail.com with ESMTPSA id q26-v6sm2217865eda.35.2018.08.17.03.22.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 17 Aug 2018 03:22:14 -0700 (PDT) From: "=?UTF-8?q?Javier=20Gonz=C3=A1lez?=" X-Google-Original-From: =?UTF-8?q?Javier=20Gonz=C3=A1lez?= To: mb@lightnvm.io Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Javier=20Gonz=C3=A1lez?= Subject: [PATCH] lightnvm: pblk: fix race condition on metadata I/O Date: Fri, 17 Aug 2018 12:22:04 +0200 Message-Id: <1534501324-13693-1-git-send-email-javier@cnexlabs.com> X-Mailer: git-send-email 2.7.4 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 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 on 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 --- 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)) -- 2.7.4