Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp105756ybk; Fri, 8 May 2020 15:17:55 -0700 (PDT) X-Google-Smtp-Source: APiQypLwdqdpPT2lG5KOr6apSihtK1RoX+Bp5EKZ+65uMbjqLvLEAe6i7xwmnvGgG0FguT2vaHnQ X-Received: by 2002:aa7:cd7c:: with SMTP id ca28mr4159818edb.181.1588976275398; Fri, 08 May 2020 15:17:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588976275; cv=none; d=google.com; s=arc-20160816; b=D9i1663tbplnGF9CuylI78VtuaRmVOJE7jEQzticCZZY/PDHc4M/Y6BtrOoH9g5MOZ 359vXZzi8qvrvYjxlim9IFVXxDbPt2xRc1bCCC1Auc8Wo0YyAgmgeeclj2Yot0Sd7gyu N2fUUqShuKjUn8z9wxSEqsE8r2F92udqWb8cHVURSAh9Fie/s6eRdWGPjdnUZ61yEt6z jfZFp5/U+8kmeXztNGZmfXyw4AjNd7FHOwVJ/ETxQEgrMuS1+FwcCzabasEFHehOx3sQ E9q6rBrltrUaf/HofDguvomh96Rp1hlbfh1B3DmA0+qh+/lMgBb+YHWaP12micdx2Koh sgmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:organization:dkim-signature; bh=UD5XSlgRABZpNQHqOmdLjL/+0BOjmyS50s2XjxLJF1s=; b=p8Lo+J0L5JiOU4PFH9zwdovzXO5B5GZxbfQen729h4nGIkx29QUNKNAPoR1xlEgFIq LaLoSkUk0xuti9WtQUSEtzFcUZwOQOS27fIcgMhZB5y8LMXZxy5ww8eqyCDXz0xTJ95J HHz2gSqI4hiwoW/lVvyZemjFb0UB3hkBoCkuYmX4Wp67+w6QYd4iT6qcxskmh4agKrnA 963EJqQqtOuve7MHlvDDnV0oFd/480HdN/63M8uDokGvua+X1cr5XAOCEukpajAIZwrf Hh960WRAUAlJfiZJxJajBPr35ekqgyfKXJedggrbSaqaWXP2P6HUtwgKD6frG5tD7mgU ZUBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NLZ1cOk2; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cd11si1674911ejb.435.2020.05.08.15.17.30; Fri, 08 May 2020 15:17:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NLZ1cOk2; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728165AbgEHWRN (ORCPT + 99 others); Fri, 8 May 2020 18:17:13 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:49880 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728154AbgEHWRM (ORCPT ); Fri, 8 May 2020 18:17:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588976231; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UD5XSlgRABZpNQHqOmdLjL/+0BOjmyS50s2XjxLJF1s=; b=NLZ1cOk2ivR0cb7eFLbXxpqck7zm3C2UcRsDLKrLb39vIVi7hOlKddO99kr+/Cld1mc9uH Ogx37m03Co8YIqr/1adDSoqVO8ElxbVQ/bivInO8gIuGRavy0PbzEVvcvymogjIcPu1xLU hURG0YFRC7fhkBNpE7jgprIXjcpsaY8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-411-jBu2rhgDOtqTABtnEkhyIQ-1; Fri, 08 May 2020 18:17:09 -0400 X-MC-Unique: jBu2rhgDOtqTABtnEkhyIQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E8BCD475; Fri, 8 May 2020 22:17:07 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-118-225.rdu2.redhat.com [10.10.118.225]) by smtp.corp.redhat.com (Postfix) with ESMTP id 99BAF2E183; Fri, 8 May 2020 22:17:03 +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 Subject: [PATCH 2/5] NFS: Fix fscache super_cookie index_key from changing after umount From: David Howells To: torvalds@linux-foundation.org, Trond Myklebust Cc: Dave Wysochanski , dhowells@redhat.com, Anna Schumaker , linux-nfs@vger.kernel.org, linux-cachefs@redhat.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Fri, 08 May 2020 23:17:02 +0100 Message-ID: <158897622270.1119820.974990693177541039.stgit@warthog.procyon.org.uk> In-Reply-To: <158897619675.1119820.2203023452686054109.stgit@warthog.procyon.org.uk> References: <158897619675.1119820.2203023452686054109.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.21 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Dave Wysochanski Commit 402cb8dda949 ("fscache: Attach the index key and aux data to the cookie") added the index_key and index_key_len parameters to fscache_acquire_cookie(), and updated the callers in the NFS client. One of the callers was inside nfs_fscache_get_super_cookie() and was changed to use the full struct nfs_fscache_key as the index_key. However, a couple members of this structure contain pointers and thus will change each time the same NFS share is remounted. Since index_key is used for fscache_cookie->key_hash and this subsequently is used to compare cookies, the effectiveness of fscache with NFS is reduced to the point at which a umount occurs. Any subsequent remount of the same share will cause a unique NFS super_block index_key and key_hash to be generated for the same data, rendering any prior fscache data unable to be found. A simple reproducer demonstrates the problem. 1. Mount share with 'fsc', create a file, drop page cache systemctl start cachefilesd mount -o vers=3,fsc 127.0.0.1:/export /mnt dd if=/dev/zero of=/mnt/file1.bin bs=4096 count=1 echo 3 > /proc/sys/vm/drop_caches 2. Read file into page cache and fscache, then unmount dd if=/mnt/file1.bin of=/dev/null bs=4096 count=1 umount /mnt 3. Remount and re-read which should come from fscache mount -o vers=3,fsc 127.0.0.1:/export /mnt echo 3 > /proc/sys/vm/drop_caches dd if=/mnt/file1.bin of=/dev/null bs=4096 count=1 4. Check for READ ops in mountstats - there should be none grep READ: /proc/self/mountstats Looking at the history and the removed function, nfs_super_get_key(), we should only use nfs_fscache_key.key plus any uniquifier, for the fscache index_key. Fixes: 402cb8dda949 ("fscache: Attach the index key and aux data to the cookie") Signed-off-by: Dave Wysochanski Signed-off-by: David Howells --- fs/nfs/fscache.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/nfs/fscache.c b/fs/nfs/fscache.c index 1abf126c2df4..8eff1fd806b1 100644 --- a/fs/nfs/fscache.c +++ b/fs/nfs/fscache.c @@ -188,7 +188,8 @@ void nfs_fscache_get_super_cookie(struct super_block *sb, const char *uniq, int /* create a cache index for looking up filehandles */ nfss->fscache = fscache_acquire_cookie(nfss->nfs_client->fscache, &nfs_fscache_super_index_def, - key, sizeof(*key) + ulen, + &key->key, + sizeof(key->key) + ulen, NULL, 0, nfss, 0, true); dfprintk(FSCACHE, "NFS: get superblock cookie (0x%p/0x%p)\n",