Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp753035imm; Wed, 4 Jul 2018 05:30:31 -0700 (PDT) X-Google-Smtp-Source: AAOMgpco1VhlHtQbBVad4hDK7me8Pl4Dnxz0MPiC0Aaey2xbjPYcaDgqTRLE1Mf5uTE6IhilU3Um X-Received: by 2002:a62:2119:: with SMTP id h25-v6mr1982261pfh.112.1530707431571; Wed, 04 Jul 2018 05:30:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530707431; cv=none; d=google.com; s=arc-20160816; b=OgNLMk/Om60Qnbs0U9xizDcF16a/b7pJoA4WejkeJuLLgVBDYZxDFmrc1kctk40GMv WNWGXyUME/HBC8Gr3DqAduy73P4mCgHyJsqLbfszvV3TNumUzjQK/bWdrTkTr3QRhlHm dXteKi9l05dkcGslmtd/RT3VUGuhE7RYSO1kM6PykUDmL19QIpkdGsYcrGsMzo5tQSlD W8bBvZ3JjZqf76PesOhwo2DgMlvEQR67gWEX9/oK3Dyd8U3utfNvIF/1hiZ4wb4SX78I ad5micxPlidOC8ZRI8Cb4SJzMV7/eLWFM/oo0PaZjvMJOxLGcndKu9V3Ej06eSUcKRLB ecEA== 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-transfer-encoding :content-id:mime-version:subject:cc:to:references:in-reply-to:from :organization:arc-authentication-results; bh=edWa4nXzmerxewWmNDFmhj0kwj7Qj3aiZELDrUbFP+Y=; b=vDER3xSdAvq6mmiHGG9tmLzXZ+sNKFjMhGsNer4jyNrgYazPgVVTMPp4oGSy5KWpRE Q25/C99RwZsx7rFOGJQgYAM9t3B3+9IukjlZw9ihuUJJkpoj0PcTrIvCocOb5V2OWfYh P6OGKlt4fc0zLvtgmnahw6dmbBYkKAjshDcWoCRs1q66ZQgG3RUCwL9miZ0Ok9NBxEgQ g0OvjvXxU/066lhG3bQDJ6SraZQV5nE7AyTzP2NQBTC1TdAyeF8KHO866Mm3bWUbUvZ9 ehtKaHL98m323Qvx3x27+2VtgyV5uIlwTJ+RRZ4l4OOm0vJfpciXJ55eo8H54z6up1f+ H39Q== 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 e10-v6si3265613pga.8.2018.07.04.05.30.16; Wed, 04 Jul 2018 05:30:31 -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 S934521AbeGDM3h convert rfc822-to-8bit (ORCPT + 99 others); Wed, 4 Jul 2018 08:29:37 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44928 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933269AbeGDM3g (ORCPT ); Wed, 4 Jul 2018 08:29:36 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 598FB400138A; Wed, 4 Jul 2018 12:29:35 +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 9F93F2026D76; Wed, 4 Jul 2018 12:29:33 +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: <24655.1530695695@warthog.procyon.org.uk> References: <24655.1530695695@warthog.procyon.org.uk> <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: [PATCH] cachefiles: Fix assertion "6 == 5 is false" at fs/fscache/operation.c:494 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <24366.1530707373.1@warthog.procyon.org.uk> Content-Transfer-Encoding: 8BIT Date: Wed, 04 Jul 2018 13:29:33 +0100 Message-ID: <24367.1530707373@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 04 Jul 2018 12:29:35 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 04 Jul 2018 12:29:35 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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 So something like the attached. Possibly the changes to operation.c should be split into a separate patch. David --- commit f3d49bdba2756bda41d18280b34f04c80f7f324c Author: kiran modukuri Date: Tue Jul 18 16:25:49 2017 -0700 cachefiles: Fix assertion "6 == 5 is false" at fs/fscache/operation.c:494 There is a potential race in fscache operation enqueuing for reading and copying multiple pages from cachefiles to netfs. Under some heavy load system, it will happen very often. If this race occurs, an oops similar to the following is seen: kernel BUG at fs/fscache/operation.c:69! invalid opcode: 0000 [#1] SMP ... #0 [ffff883fff0838d8] machine_kexec at ffffffff81051beb #1 [ffff883fff083938] crash_kexec at ffffffff810f2542 #2 [ffff883fff083a08] oops_end at ffffffff8163e1a8 #3 [ffff883fff083a30] die at ffffffff8101859b #4 [ffff883fff083a60] do_trap at ffffffff8163d860 #5 [ffff883fff083ab0] do_invalid_op at ffffffff81015204 #6 [ffff883fff083b60] invalid_op at ffffffff8164701e [exception RIP: fscache_enqueue_operation+246] RIP: ffffffffa0b793c6 RSP: ffff883fff083c18 RFLAGS: 00010046 RAX: 0000000000000019 RBX: ffff8832ed1a9ec0 RCX: 0000000000000006 RDX: 0000000000000000 RSI: 0000000000000046 RDI: 0000000000000046 RBP: ffff883fff083c20 R8: 0000000000000086 R9: 000000000000178f R10: ffffffff816aeb00 R11: ffff883fff08392e R12: ffff8802f0525620 R13: ffff88407ffc01d8 R14: 0000000000000000 R15: 0000000000000003 ORIG_RAX: ffffffffffffffff CS: 0010 SS: 0000 #7 [ffff883fff083c10] fscache_enqueue_operation at ffffffffa0b793c6 #8 [ffff883fff083c28] cachefiles_read_waiter at ffffffffa0b15a48 #9 [ffff883fff083c48] __wake_up_common at ffffffff810af028 Reported-by: Lei Xue Reported-by: Vegard Nossum Reported-by: Anthony DeRobertis Reported-by: NeilBrown Reported-by: Daniel Axtens Reported-by: KiranKumar Modukuri Signed-off-by: David Howells diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c index 5082c8a49686..b2cb6cdcd87f 100644 --- a/fs/cachefiles/rdwr.c +++ b/fs/cachefiles/rdwr.c @@ -27,6 +27,7 @@ static int cachefiles_read_waiter(wait_queue_entry_t *wait, unsigned mode, struct cachefiles_one_read *monitor = container_of(wait, struct cachefiles_one_read, monitor); struct cachefiles_object *object; + struct fscache_retrieval *op = monitor->op; struct wait_bit_key *key = _key; struct page *page = wait->private; @@ -51,16 +52,22 @@ static int cachefiles_read_waiter(wait_queue_entry_t *wait, unsigned mode, list_del(&wait->entry); /* move onto the action list and queue for FS-Cache thread pool */ - ASSERT(monitor->op); + ASSERT(op); - object = container_of(monitor->op->op.object, - struct cachefiles_object, fscache); + /* We need to temporarily bump the usage count as we don't own a ref + * here otherwise cachefiles_read_copier() may free the op between the + * monitor being enqueued on the op->to_do list and the op getting + * enqueued on the work queue. + */ + fscache_get_retrieval(op); + object = container_of(op->op.object, struct cachefiles_object, fscache); 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); + fscache_put_retrieval(op); return 0; } diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c index e30c5975ea58..28ce646cc32c 100644 --- a/fs/fscache/operation.c +++ b/fs/fscache/operation.c @@ -69,8 +69,9 @@ void fscache_enqueue_operation(struct fscache_operation *op) ASSERT(list_empty(&op->pend_link)); ASSERT(op->processor != NULL); ASSERT(fscache_object_is_available(op->object)); - ASSERTCMP(atomic_read(&op->usage), >, 0); - ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS); + ASSERTCMP(atomic_read(&op->usage), >, 1); + ASSERTIFCMP(op->state != FSCACHE_OP_ST_IN_PROGRESS, + op->state, ==, FSCACHE_OP_ST_CANCELLED); fscache_stat(&fscache_n_op_enqueue); switch (op->flags & FSCACHE_OP_TYPE) { @@ -499,7 +500,8 @@ void fscache_put_operation(struct fscache_operation *op) struct fscache_cache *cache; _enter("{OBJ%x OP%x,%d}", - op->object->debug_id, op->debug_id, atomic_read(&op->usage)); + op->object ? op->object->debug_id : 0, + op->debug_id, atomic_read(&op->usage)); ASSERTCMP(atomic_read(&op->usage), >, 0);