Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp958984ybx; Thu, 31 Oct 2019 03:40:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqz9G1sVuP8/h1//iZGhE9cNhHlts1KmAgEbe4wavYRnqtlvRgLEbdWv6iw+ofUOfXzifpFU X-Received: by 2002:a17:906:e290:: with SMTP id gg16mr3185552ejb.280.1572518427205; Thu, 31 Oct 2019 03:40:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572518427; cv=none; d=google.com; s=arc-20160816; b=d0szEUVjDIwfRhTZrN6g4EKltfiIMt8H1kJI63Sqxx9nz445wNylIeIm1R8sanTWZZ mBzzzoYIJeGzWxieaWK/6Bx4T5hsmbfm05GG/K8k5n/7629RbcaPE8FtXu3VaSeN/tZX vi700KQ0gc6k5JgA37YphFtXd6WyBdQfvKLtA/b8+P9f65ZGy6YEq6RlnVSeGiIlTvva UDkGyjL+6NyyCFkakEykPpNxzo0wpqShQSPuUX4wFmJwD35/NYnK4IKEnwIn+0EVBs8u VvUYaGWGNpCeqw4nlv+ggt3t3BJY5x7KZF0hMq0LPynvPQVg/fRgpqPSJO2Z0AvGkewI 7qoQ== 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:dkim-signature; bh=L9UYXWAgwZMaVyLOOzOt+ACtOFd1s/GUXWoDpY54l7s=; b=nlVrzNN345VqW+goH2Dpu7N8kdzxYkG1mDqD5hZSeT34l3h3i4Vv5/int3qr+eFz9a DVnE1ZrseaTToiAEH4LB4NzR1I0Afksg57BkxUOpxYolEv8HvI0SDPIcQsw7NtvH7Dka KsC5QncVf6/I9Dp1RNEIitGYU1USNLmUOgKSvzalOrF8ZY/UNM4CoHGRFqHuCbb5vK8H xqVGCacRAGxxxgxwNDi/TljvRLqFXyp5DKMUDkiUc7kHvghs3nYLV25E2A+Yx1fojkmK l9SI15JxEJzZdHpmKn37RljipdH/pPcW70rgxkiFo5TwNYrvnMwmePrL+IXDnF1ZmpuO MaWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=FxquD+5R; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=openvz.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g4si4226864edj.263.2019.10.31.03.40.03; Thu, 31 Oct 2019 03:40:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-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=@yandex-team.ru header.s=default header.b=FxquD+5R; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=openvz.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726867AbfJaKja (ORCPT + 99 others); Thu, 31 Oct 2019 06:39:30 -0400 Received: from forwardcorp1j.mail.yandex.net ([5.45.199.163]:39086 "EHLO forwardcorp1j.mail.yandex.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726913AbfJaKja (ORCPT ); Thu, 31 Oct 2019 06:39:30 -0400 Received: from mxbackcorp1o.mail.yandex.net (mxbackcorp1o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::301]) by forwardcorp1j.mail.yandex.net (Yandex) with ESMTP id 4313A2E0DD2; Thu, 31 Oct 2019 13:39:27 +0300 (MSK) Received: from sas1-7fab0cd91cd2.qloud-c.yandex.net (sas1-7fab0cd91cd2.qloud-c.yandex.net [2a02:6b8:c14:3a93:0:640:7fab:cd9]) by mxbackcorp1o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id 3cec8TshNm-dQei0e3i; Thu, 31 Oct 2019 13:39:27 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1572518367; bh=L9UYXWAgwZMaVyLOOzOt+ACtOFd1s/GUXWoDpY54l7s=; h=In-Reply-To:Message-Id:References:Date:Subject:To:From:Cc; b=FxquD+5RhfjDSq5dXzcScL6eS8oKzAE+Mo/0o2dZ9OXaVEfQGdcX/1jB1JrGhq5hl /+lBPkWy3ZflQRUXM7J2rdjsEu7Yk4yGSO1IdKv3t967ErW6zbP+CQwANLqHNWyOSN bMUAqV7cFsqHLblJgGV+x/H3tdXwDp4OyduA4OEw= Authentication-Results: mxbackcorp1o.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Received: from 95.108.174.193-red.dhcp.yndx.net (95.108.174.193-red.dhcp.yndx.net [95.108.174.193]) by sas1-7fab0cd91cd2.qloud-c.yandex.net (nwsmtp/Yandex) with ESMTPSA id N03nYWr42k-dQWKoRGl; Thu, 31 Oct 2019 13:39:26 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) From: Dmitry Monakhov To: linux-fsdevel@vger.kernel.org Cc: linux-ext4@vger.kernel.org, jack@suse.cz, Dmitry Monakhov Subject: [PATCH 2/2] fs/quota: Check that quota is not dirty before release Date: Thu, 31 Oct 2019 10:39:20 +0000 Message-Id: <20191031103920.3919-2-dmonakhov@openvz.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20191031103920.3919-1-dmonakhov@openvz.org> References: <20191031103920.3919-1-dmonakhov@openvz.org> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Dmitry Monakhov There is a race window where quota was redirted once we drop dq_list_lock inside dqput(), but before we grab dquot->dq_lock inside dquot_release() TASK1 TASK2 (chowner) ->dqput() we_slept: spin_lock(&dq_list_lock) if (dquot_dirty(dquot)) { spin_unlock(&dq_list_lock); dquot->dq_sb->dq_op->write_dquot(dquot); goto we_slept if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) { spin_unlock(&dq_list_lock); dquot->dq_sb->dq_op->release_dquot(dquot); dqget() mark_dquot_dirty() dqput() goto we_slept; } So dquot dirty quota will be released by TASK1, but on next we_sleept loop we detect this and call ->write_dquot() for it. XFSTEST: https://github.com/dmonakhov/xfstests/commit/440a80d4cbb39e9234df4d7240aee1d551c36107 Signed-off-by: Dmitry Monakhov --- fs/ocfs2/quota_global.c | 2 +- fs/quota/dquot.c | 2 +- include/linux/quotaops.h | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/fs/ocfs2/quota_global.c b/fs/ocfs2/quota_global.c index 7a92219..eda8348 100644 --- a/fs/ocfs2/quota_global.c +++ b/fs/ocfs2/quota_global.c @@ -728,7 +728,7 @@ static int ocfs2_release_dquot(struct dquot *dquot) mutex_lock(&dquot->dq_lock); /* Check whether we are not racing with some other dqget() */ - if (atomic_read(&dquot->dq_count) > 1) + if (dquot_is_busy(dquot)) goto out; /* Running from downconvert thread? Postpone quota processing to wq */ if (current == osb->dc_task) { diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c index b492b9e..72d24a5 100644 --- a/fs/quota/dquot.c +++ b/fs/quota/dquot.c @@ -497,7 +497,7 @@ int dquot_release(struct dquot *dquot) mutex_lock(&dquot->dq_lock); /* Check whether we are not racing with some other dqget() */ - if (atomic_read(&dquot->dq_count) > 1) + if (dquot_is_busy(dquot)) goto out_dqlock; if (dqopt->ops[dquot->dq_id.type]->release_dqblk) { ret = dqopt->ops[dquot->dq_id.type]->release_dqblk(dquot); diff --git a/include/linux/quotaops.h b/include/linux/quotaops.h index 185d948..91e0b76 100644 --- a/include/linux/quotaops.h +++ b/include/linux/quotaops.h @@ -54,6 +54,16 @@ static inline struct dquot *dqgrab(struct dquot *dquot) atomic_inc(&dquot->dq_count); return dquot; } + +static inline bool dquot_is_busy(struct dquot *dquot) +{ + if (test_bit(DQ_MOD_B, &dquot->dq_flags)) + return true; + if (atomic_read(&dquot->dq_count) > 1) + return true; + return false; +} + void dqput(struct dquot *dquot); int dquot_scan_active(struct super_block *sb, int (*fn)(struct dquot *dquot, unsigned long priv), -- 2.7.4