Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp781462imm; Wed, 17 Oct 2018 08:13:54 -0700 (PDT) X-Google-Smtp-Source: ACcGV634DEAj2N7+eGV6jqLvAus0OLTETwbshXnSCVOua5vXJRWpQIjx3MhL1DtG9Xc7zTSvw/60 X-Received: by 2002:a63:d208:: with SMTP id a8-v6mr22904492pgg.99.1539789234549; Wed, 17 Oct 2018 08:13:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539789234; cv=none; d=google.com; s=arc-20160816; b=j4y9SM6ax9+fWl0G9lK61w0ggsSeQ5s2N2BF9vcw3oMp7eSIR9K+m7qhR5he4HJQkd npzrb7XJ0hMzFSez453M8qnm25bkj7zMRergmAHMI0pd/lVmfoLbsYlglANkYann9iQG 6dr4Xl8so9zvwHpGr2GYnnl91Wyc5GZ3NTV6Al3O/db6AaMOw1b4EkUOBshm1d2zEQ5P xVV2KgFVS/R1WlfTxGedkBcSx/BIVR2BrMHR6mDHEnttYOmDp2CfN8I62Le0m5LY+Mkt FIapeDDB66Z4PoeFMSe+cBz/1On4297zjkBc2bwNibSpyoWo0HmpOatsg1cfnW24cU1E nAKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=6IlPPVer3cCDM9s5XwuxYjT2m1bX7z07CSi9LKXlLqo=; b=xv0E7PeyIBw6Wxc+tRS9w42yu6CGwVvmKdtBCpjwObrc/k0HrgF5w9p2ETY1mdNLwT 0YJgzHUIJftJzyk+6ifNo/To7ftyls28A5DY7TX5RKxQmRx/D/PUlRDX1OYnawqDklN+ IrMtqiLNB8OtxK2/O1F4JqRGdm+5LsE6CPk3RpcMHocB41Jal4xLP+AOKtkrwgWIlqI4 a3Mz4uzV0LYvJo/xipHlSjCmMaCkPQWpLJzVcPCuVn3fSVSlt+IkVaFSLOMjcHPP8H6j BuzVnfZ+XhIhQmBWeEyxFylJJFG1+vPCnZbIThCTeb88SKbbS6nLJHBMjunAYvIGGexO R+jA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=oDZqAnBl; 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 16-v6si17351738pgw.208.2018.10.17.08.13.38; Wed, 17 Oct 2018 08:13:54 -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=@amarulasolutions.com header.s=google header.b=oDZqAnBl; 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 S1727873AbeJQXHw (ORCPT + 99 others); Wed, 17 Oct 2018 19:07:52 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:40091 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727014AbeJQXHw (ORCPT ); Wed, 17 Oct 2018 19:07:52 -0400 Received: by mail-ed1-f68.google.com with SMTP id r1-v6so25232695edd.7 for ; Wed, 17 Oct 2018 08:11:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=6IlPPVer3cCDM9s5XwuxYjT2m1bX7z07CSi9LKXlLqo=; b=oDZqAnBlZVDYDyGcir6Y6dUm1uvFYJzHXzBffZOJTkyqzxB7JuUz5XcPjyZjcZa9vP QkZlUs1LRgLH9dg2T0BN0VvQdFGurQBnvf2fc+lviQ73DzfhLg243sB4pincild/8MJy wT0J3MPMtWSaqkqAF6PsCH0kglnmRHC7ApiPs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=6IlPPVer3cCDM9s5XwuxYjT2m1bX7z07CSi9LKXlLqo=; b=gDYBGSp2CvB1/tGpiLCodTNnQq9Ua5m1SQE5vRCpyX3GPtVUJadZyEdRZl85IHmakx yUK5DZPvZA2Z9SiWL+teKLLU3r1aJPQ+A8EYxBXjXCIKThnYCmQwxhRPTTtSyR+GbN8I Wl2n1/K+fIxE1rUJLDbB/8ZEo77cBy8+lrXwBDKeK45K98TBpqGBQjuM1a4fQQw3Sihd L5aYP94d6RLQgSajVjj1Gqw0Psw/6jbxb5u5zo+pDcV4hvQqHLq8vc9oTAxiu53rYBkU D3UtISEmhOvKPORtYu+A1AE1r0p2seL2dFJrt/NTts6eGoiAYWfQPxyUn9ITDvJsvB4q B3Wg== X-Gm-Message-State: ABuFfogr4+ho+9TmBdADm0fPjtbGttpm9mKjqaZc2uPnxm0bNKLvEVAS AbfVZrP/FvMZEWwbFwJ/zBNPu22XO2/AnQ== X-Received: by 2002:a50:b322:: with SMTP id q31-v6mr874275edd.194.1539789102735; Wed, 17 Oct 2018 08:11:42 -0700 (PDT) Received: from andrea (15.152.230.94.awnet.cz. [94.230.152.15]) by smtp.gmail.com with ESMTPSA id f22-v6sm6333014eda.9.2018.10.17.08.11.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 17 Oct 2018 08:11:42 -0700 (PDT) Date: Wed, 17 Oct 2018 17:11:34 +0200 From: Andrea Parri To: David Howells Cc: gregkh@linux-foundation.org, Kiran Kumar Modukuri , viro@zeniv.linux.org.uk, sandeen@redhat.com, linux-cachefs@redhat.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/4] fscache: Fix race in fscache_op_complete() due to split atomic_sub & read Message-ID: <20181017151134.GA8966@andrea> References: <153978619457.8478.3813964117489247515.stgit@warthog.procyon.org.uk> <153978621809.8478.2198040871218302573.stgit@warthog.procyon.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <153978621809.8478.2198040871218302573.stgit@warthog.procyon.org.uk> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi David, On Wed, Oct 17, 2018 at 03:23:38PM +0100, David Howells wrote: > From: kiran.modukuri > > The code in fscache_retrieval_complete is using atomic_sub followed by an > atomic_read: > > atomic_sub(n_pages, &op->n_pages); > if (atomic_read(&op->n_pages) <= 0) > fscache_op_complete(&op->op, true); > > This causes two threads doing a decrement of n_pages to race with each > other seeing the op->refcount 0 at same time - and they end up calling > fscache_op_complete() in both the threads leading to an assertion failure. > > Fix this by using atomic_sub_return() instead of two calls. Seems a case for atomic_sub_return_relaxed()... why not? Andrea