Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3728930yba; Tue, 9 Apr 2019 03:38:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqyFfe+GH0PkyD/GjwBLlW4GXJCx8EreC3CGHZTnTTJkfMTDs+Xmw+avcrQFngHQ5AF5flpB X-Received: by 2002:a62:1a0d:: with SMTP id a13mr36389035pfa.198.1554806298447; Tue, 09 Apr 2019 03:38:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554806298; cv=none; d=google.com; s=arc-20160816; b=x3bb3ima2bA5DNaD6mRz59h1rzZHPUmQrbeeqrcA0N4QA0tnNC+q+jybFA9uCgj29f oqmriXGDGv8Oj+HrC1yAkrEWOMFPq0z4rgRWYAloZk3UeuYnhe7xclvy1mL2beMM9DJy W/WaLbQY6uVu4253iaLiOVrtlqCh5+Hw4iL3GkmndHzi/jRtIn5NzyYWrxYv1x0PazJP mcW9W+2X0kftM2YScv0pWP07D3Hb1wLxQVLQomDqPAidKp6j17FXDTEjweWy0+5NarXZ Yg0BifLxd1T1buBySKkxA2QI1KCo6iwogubyu45bpATOljre/wAKB3qliTN9ub7kSKfU fq3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:dkim-signature:dkim-signature; bh=W2OOWhT0xfHYKDW9na1kRIP32lEGGyA/E7TJhIoajMo=; b=Hs+/Kh8SPxL8QVTUXnnPB53XY6dhbaPAJJ1hNPFfJO1+DyqRgqaYuNqIJ9nKlxv8yV 3V9KKUz3galg4RCzRIoPSp4ywJ8Qpd4EqkoztSzKwjtTe8ZT/zNUHVMpIvQ7QwP0kgJE J3Er86Nkj3w5P0yiOhgH2nFtMCE5fQMFpO7DsL7aZw6c+vBDQZxjfNoQqgV1w9vU8xPy a7IWwZbmtmpl/OuYsNCPVw3Bi9l3PCIefXc3rdq4pWMoJRWfih7wlDgc042gC2IFkDl/ niJmK8HgN0NAcsa61Gdb2FiycoGInMdeEwFjsKTJqtfpVZoaI+Mi1ekZ55qWhWlgndyT mEsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=icli6rr+; dkim=pass header.i=@codeaurora.org header.s=default header.b=ODIJ4PA8; 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 q190si12459789pfc.215.2019.04.09.03.38.02; Tue, 09 Apr 2019 03:38:18 -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=@codeaurora.org header.s=default header.b=icli6rr+; dkim=pass header.i=@codeaurora.org header.s=default header.b=ODIJ4PA8; 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 S1727039AbfDIKgz (ORCPT + 99 others); Tue, 9 Apr 2019 06:36:55 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:37038 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726066AbfDIKgx (ORCPT ); Tue, 9 Apr 2019 06:36:53 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 4BACE6110F; Tue, 9 Apr 2019 10:36:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1554806212; bh=dxzTPPPoyNwyoS5eFhOa7hTyrVyMHAbV16DEwfPsRdU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=icli6rr+fhPubyckZf7rQDsZB2wp/65eNpNbippPqyDzuQuUgYfZY+7+th0eFT3vN YedTM4FE6b0qNUBddhxMghSHHHW4KBwMzeWy7ehI9Zzh9kZgKnAF+Oy+812x7InSgO AaSYt5Q7KlTXSqt0y4Hoete7eCX+4JYh1KmKqor8= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_INVALID,DKIM_SIGNED autolearn=no autolearn_force=no version=3.4.0 Received: from codeaurora.org (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: stummala@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 2FC356115A; Tue, 9 Apr 2019 10:36:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1554806211; bh=dxzTPPPoyNwyoS5eFhOa7hTyrVyMHAbV16DEwfPsRdU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ODIJ4PA83GoLy/lM1hvqfa83oV4ERmV6GntkhmmFywiblP0S1XF9WKs4llbKkPrkm KHxrQPXLddgAte9W8w2AkMcQ/xXNbXT5dqNLbkuWZaNgtx9/dBiefEzlead8T58gHZ XK0bOp0IPP4u0i9Mo46tngbSY/tpprD5eSCerClw= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 2FC356115A Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=stummala@codeaurora.org From: Sahitya Tummala To: Jaegeuk Kim , Chao Yu , linux-f2fs-devel@lists.sourceforge.net Cc: Sahitya Tummala , linux-kernel@vger.kernel.org Subject: [PATCH 3/4] f2fs: fix race between online resize path and allocate new data block path Date: Tue, 9 Apr 2019 16:06:17 +0530 Message-Id: <1554806178-32728-3-git-send-email-stummala@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1554806178-32728-1-git-send-email-stummala@codeaurora.org> References: <1554806178-32728-1-git-send-email-stummala@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There can be a potential race between allocate_segment_for_resize() and allocate_data_block(), resulting into two issues - 1. The allocate_data_block() can get a data block from a segment which is currently being resized. This results in data being updated in an outdated or already resized segment. 2. It also results into these warnings from get_new_segment(): f2fs_bug_on(sbi, secno >= NEW_MAIN_SECS(sbi)); Fix these by using curseg_mutex lock in the resize context to prevent race with allocate_data_block() path. Signed-off-by: Sahitya Tummala --- fs/f2fs/segment.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 1c3cc30..e7c411f 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -2643,12 +2643,14 @@ void allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type) struct curseg_info *curseg = CURSEG_I(sbi, type); unsigned int old_segno = curseg->segno; + mutex_lock(&curseg->curseg_mutex); if (f2fs_need_SSR(sbi) && get_ssr_segment(sbi, type)) change_curseg(sbi, type); else new_curseg(sbi, type, true); stat_inc_seg_type(sbi, curseg); + mutex_unlock(&curseg->curseg_mutex); if (get_valid_blocks(sbi, old_segno, false) == 0) __set_test_and_free(sbi, old_segno); -- Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.