Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp856706imu; Tue, 20 Nov 2018 08:01:05 -0800 (PST) X-Google-Smtp-Source: AJdET5cdUfOt/TPj3ymFzld9AKbNYhmKPSoy2IFUfhoCcWypsPNaka60tCaSQZSJrcXquxCIZPFQ X-Received: by 2002:a62:18ce:: with SMTP id 197mr2866184pfy.88.1542729665335; Tue, 20 Nov 2018 08:01:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542729665; cv=none; d=google.com; s=arc-20160816; b=wVoR8QwHdpen+R+ar/BxX63BfgnFl00icReCkdC88/KRIrdtUgSSvFnKtw55xM/AwY b5nBB8mzbIWEmt/32hSyqC7hESZYx/SVocac0vyUUYzc27PYcn9W5kmqAph3qcFSmEqP HNIKN3ww50r5xN86k4JbB7Mot0wqbgMaop0+rTkZh8cwnccA6BcGerz7cGiLN0pIn5yl eSb2wk+/krcEOaky0tRCkUc48nOzbgX53pdW6N2kv/SKhhddyHZ5QUkptqCGDi+ZxGOD +JUwCKmKUQ3vx75HtK1o0t83arMeLN3YWOjmYt643H4dXn+ym9+VvMdA4g4NEAv/nPms oW+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=2KJUtfiEoR5xgqW9da8Nu0NwZG+hMg7l5QpxmGBW0jY=; b=q4Cj+xJ42aMYEYf/8tKODD/0OdsJfg2jqRoRnFp9CVyHa9jhIDfyrcDiE0LpACYhRK oJQ2gDRZyly2iQYLaB0Xt/8OgjESw6fLoP63aObqgX9iVUVEN7pfEEk6pbEO15df6jOY zBvRpWXuFFNujrPGgNluE7PE5oW+9mPhaps7C7a/ZC15fnvkgA0KZgeslZDBcufekHdT 3ZH3Y3Xo74gDJKXDfm5A6fhrw6QbSyLTfe22scpO6zY5ZH0kiDXLNrA/7lmXvBBCY+eo ls76qha04JKqCb8imWKf4WbtCsN1MJ9eYEwBqHk1E+ZctEo+Y8524yc5W1BIq2lCN1AJ GnAg== ARC-Authentication-Results: i=1; mx.google.com; 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 f11si10021668plr.341.2018.11.20.08.00.49; Tue, 20 Nov 2018 08:01:05 -0800 (PST) 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; 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 S1729785AbeKUAvU (ORCPT + 99 others); Tue, 20 Nov 2018 19:51:20 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:40552 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726916AbeKUAvU (ORCPT ); Tue, 20 Nov 2018 19:51:20 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id EF78E54F76CEB; Tue, 20 Nov 2018 22:21:55 +0800 (CST) Received: from localhost.localdomain (10.175.124.28) by smtp.huawei.com (10.3.19.204) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 20 Nov 2018 22:21:50 +0800 From: Gao Xiang To: Greg Kroah-Hartman , CC: LKML , , "Chao Yu" , Miao Xie , , Gao Xiang Subject: [PATCH 08/10] staging: erofs: locked before registering for all new workgroups Date: Tue, 20 Nov 2018 22:34:23 +0800 Message-ID: <20181120143425.43637-9-gaoxiang25@huawei.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20181120143425.43637-1-gaoxiang25@huawei.com> References: <20181120143425.43637-1-gaoxiang25@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.124.28] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Let's make sure that the one registering a workgroup will also take the primary work lock at first for two reasons: 1) There's no need to introduce such a race window (and consequently overhead) between registering and locking, other tasks could break in by chance, and the race seems unnecessary (no benefit at all); 2) It's better to take the primary work when a workgroup is registered to apply the cache managed policy, for example, if some other tasks break in, it could turn into the in-place decompression rather than use as the cached decompression. Reviewed-by: Chao Yu Signed-off-by: Gao Xiang --- drivers/staging/erofs/unzip_vle.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/staging/erofs/unzip_vle.c b/drivers/staging/erofs/unzip_vle.c index 4e5843e8ee35..a1376f3c6065 100644 --- a/drivers/staging/erofs/unzip_vle.c +++ b/drivers/staging/erofs/unzip_vle.c @@ -420,18 +420,22 @@ z_erofs_vle_work_register(const struct z_erofs_vle_work_finder *f, work = z_erofs_vle_grab_primary_work(grp); work->pageofs = f->pageofs; + /* lock all primary followed works before visible to others */ + if (unlikely(!mutex_trylock(&work->lock))) + /* for a new workgroup, try_lock *never* fails */ + DBG_BUGON(1); + if (gnew) { int err = erofs_register_workgroup(f->sb, &grp->obj, 0); if (err) { + mutex_unlock(&work->lock); kmem_cache_free(z_erofs_workgroup_cachep, grp); return ERR_PTR(-EAGAIN); } } *f->owned_head = *f->grp_ret = grp; - - mutex_lock(&work->lock); return work; } -- 2.14.4