Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp578616imm; Wed, 4 Jul 2018 02:15:57 -0700 (PDT) X-Google-Smtp-Source: AAOMgpci4l+bofa40ybrqH6g5WjDBGIqB8ScKDK9OM9SbOR8OjXEsi3T7WG/CXU+VOj2u8M/PYSF X-Received: by 2002:a65:4ecd:: with SMTP id w13-v6mr1187354pgq.214.1530695757458; Wed, 04 Jul 2018 02:15:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530695757; cv=none; d=google.com; s=arc-20160816; b=jt/sElbmaoiw6mMGWA580B8BgoHxrbFrWqVWqvb0YtLMjo6HpruyHGyJVyVouPccwt eyrqUrK+fvBD/OFtwnLsJLXbgHz0iwx8QOKLWk0Kz2w9NZMiybyYH6WjeBICEkKcL7Tg 85go6vRCckzWbyG9TyQPs4ua1Pr8BY1xRAZT1DEroU4fF4sKVnVCstPQdyTtUMcO9Ti4 BwlYVzDPYhMMDTUg1cem8TQQLRlt6ycVAfOmZZ81KvB0S5Xc7ySSDWnlVGaSuQApf8by q9uKSudRgqZ0NPeqkvjrCvg37jK5TfTkDznAy9aYdHP/5TNKmPpQocXQF6/yQx8DNwPg 9Hbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:content-id:mime-version :subject:cc:to:references:in-reply-to:from:organization :arc-authentication-results; bh=qJudIArv1x4GToadVgJw1Rf+3ArsdhwGuelK1rqAbqc=; b=Tw94M5srqZw3Lx11dJrnJVPE1Yew1gXI3cKZJCyVpOrsdr+dEo4KOcgXZsEL/TGt3C NocnhJ8l69kxrsQit2tGyQY41vWjKFT35TtazKbbkdN7f96XNqTHhXqLdVwSGhLBIoAc mhPBEi4/bVJKz6iK/tqQPKm3eICC78A4nFGExHPo6XL+5quZ+OgRFk//iN20S/fUUhAM 9Sx+0kKPKoQP4PVbwYzLwigAvpReyQxiVVXVUWGHxdo3sMYLutwnIYzt7rXqUd4VILjt 85AfMHJhbfIDE9oySKVKWY7pplxSdjkN6vqm94L1xx1QPDhqJBa5iLCjM6QxJYoW9tPv jdsg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w10-v6si3085323ply.482.2018.07.04.02.15.42; Wed, 04 Jul 2018 02:15:57 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933471AbeGDJPB (ORCPT + 99 others); Wed, 4 Jul 2018 05:15:01 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33566 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932479AbeGDJO7 (ORCPT ); Wed, 4 Jul 2018 05:14:59 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 70E7681A4EAD; Wed, 4 Jul 2018 09:14:59 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-123-203.rdu2.redhat.com [10.10.123.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E4591C581; Wed, 4 Jul 2018 09:14:56 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells In-Reply-To: <877emb2740.fsf@notabene.neil.brown.name> References: <877emb2740.fsf@notabene.neil.brown.name> <20180222073330.36259-1-carmark.dlut@gmail.com> To: NeilBrown Cc: dhowells@redhat.com, Andrew Morton , Anthony DeRobertis , linux-cachefs@redhat.com, linux-kernel@vger.kernel.org, Lei Xue , Vegard Nossum , Daniel Axtens , KiranKumar Modukuri Subject: Re: [PATCH] cachefiles: fix multiple-put race. MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <24654.1530695695.1@warthog.procyon.org.uk> Date: Wed, 04 Jul 2018 10:14:55 +0100 Message-ID: <24655.1530695695@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 04 Jul 2018 09:14:59 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Wed, 04 Jul 2018 09:14:59 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'dhowells@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org NeilBrown wrote: > + fscache_enqueue_retrieval(monitor->op); > + > spin_lock(&object->work_lock); > list_add_tail(&monitor->op_link, &monitor->op->to_do); > spin_unlock(&object->work_lock); > > - fscache_enqueue_retrieval(monitor->op); That won't necessarily work because the work processor can then happen before you've added the work to the to_do list. I'm thinking that KiranKumar's solution might be the best one. The problem is that cachefiles_read_waiter() doesn't have a ref on the monitor object but is entirely dependent on the waitqueue lock for safety. I think KiranKumar's patch is correct to take a ref before doing the queuing. It might be possible to then pass this along to the work processor, but that might be too fiddly. Actually, I want to get rid of the page monitoring stuff entirely as it's quite fragile and use an iterator and direct-IO instead, but we have to fix this for now. David