From patchwork Tue Oct 27 13:50:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 11860465 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9163B61C for ; Tue, 27 Oct 2020 13:50:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6DAAD21D24 for ; Tue, 27 Oct 2020 13:50:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="OMpo2w/I" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752701AbgJ0NuJ (ORCPT ); Tue, 27 Oct 2020 09:50:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:23122 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752691AbgJ0NuJ (ORCPT ); Tue, 27 Oct 2020 09:50:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603806608; 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=w2rnUKEZ22Vx5ogw1wCvAP9HIPkqe7RCtGF/gA32QhE=; b=OMpo2w/IFpjcPz7+qEXS2srehL8AaO1gLtEV1Dk7iVO5+6eK4R/3p2G6T7Mjx0h+eDZ/Wz R+nx3C1GC4oQSl3A+tedTyqcPcP/kvPpr9C2jRWr3EGi892WFGXkvGMBBpAefs1mwO+3T+ Z+yqfQx0bqZJj5L85G2CQ3tQBRHhrds= 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-114-wVeQcTRKPwCO7Q_duK70uQ-1; Tue, 27 Oct 2020 09:50:06 -0400 X-MC-Unique: wVeQcTRKPwCO7Q_duK70uQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DC9AFADC28; Tue, 27 Oct 2020 13:50:04 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-120-70.rdu2.redhat.com [10.10.120.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id 03D235C1BB; Tue, 27 Oct 2020 13:50: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 01/10] afs: Fix copy_file_range() From: David Howells To: linux-afs@lists.infradead.org Cc: Christoph Hellwig , dhowells@redhat.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Tue, 27 Oct 2020 13:50:03 +0000 Message-ID: <160380660321.3467511.6644741119983042797.stgit@warthog.procyon.org.uk> In-Reply-To: <160380659566.3467511.15495463187114465303.stgit@warthog.procyon.org.uk> References: <160380659566.3467511.15495463187114465303.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.23 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The prevention of splice-write without explicit ops made the copy_file_write() syscall to an afs file (as done by the generic/112 xfstest) fail with EINVAL. Fix by using iter_file_splice_write() for afs. Fixes: 36e2c7421f02 ("fs: don't allow splice read/write without explicit ops") Signed-off-by: David Howells cc: Christoph Hellwig Reviewed-by: Christoph Hellwig --- fs/afs/file.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/afs/file.c b/fs/afs/file.c index 371d1488cc54..91225421ad37 100644 --- a/fs/afs/file.c +++ b/fs/afs/file.c @@ -33,6 +33,7 @@ const struct file_operations afs_file_operations = { .write_iter = afs_file_write, .mmap = afs_file_mmap, .splice_read = generic_file_splice_read, + .splice_write = iter_file_splice_write, .fsync = afs_fsync, .lock = afs_lock, .flock = afs_flock, From patchwork Tue Oct 27 13:50:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 11860471 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8AA7A61C for ; Tue, 27 Oct 2020 13:50:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6C23321D24 for ; Tue, 27 Oct 2020 13:50:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="CtG65hG0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752721AbgJ0NuX (ORCPT ); Tue, 27 Oct 2020 09:50:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:33624 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752713AbgJ0NuQ (ORCPT ); Tue, 27 Oct 2020 09:50:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603806615; 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=x9U/jwdb6mwOhoCQYyqS94x38hiiYC1ycmew3Gz8Xmk=; b=CtG65hG0ikFPr8mRIr6mLergDArhMREnDrhNpg+Vq7TZ/oaGzzpk0xWrqRMguMdASDKf2B vxCcb0BnFu4YYRNbUAmMYI73KUY6FyptuHLg5qR74tXfAdfsFjDTKn7RfKWC/s0RZzxRpS auh46gK9sWPKp6UlQbRMm3Hie/dbFRA= 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-146-nfl23dv6NLiVBWastLENqw-1; Tue, 27 Oct 2020 09:50:13 -0400 X-MC-Unique: nfl23dv6NLiVBWastLENqw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D001018B9ED2; Tue, 27 Oct 2020 13:50:11 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-120-70.rdu2.redhat.com [10.10.120.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id DCDD862A0B; Tue, 27 Oct 2020 13:50:10 +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 02/10] afs: Fix tracing deref-before-check From: David Howells To: linux-afs@lists.infradead.org Cc: Dan Carpenter , Dan Carpenter , dhowells@redhat.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Tue, 27 Oct 2020 13:50:10 +0000 Message-ID: <160380661010.3467511.18209967343006168466.stgit@warthog.procyon.org.uk> In-Reply-To: <160380659566.3467511.15495463187114465303.stgit@warthog.procyon.org.uk> References: <160380659566.3467511.15495463187114465303.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.23 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The patch dca54a7bbb8c: "afs: Add tracing for cell refcount and active user count" from Oct 13, 2020, leads to the following Smatch complaint: fs/afs/cell.c:596 afs_unuse_cell() warn: variable dereferenced before check 'cell' (see line 592) Fix this by moving the retrieval of the cell debug ID to after the check of the validity of the cell pointer. Reported-by: Dan Carpenter Fixes: dca54a7bbb8c ("afs: Add tracing for cell refcount and active user count") Signed-off-by: David Howells cc: Dan Carpenter --- fs/afs/cell.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/afs/cell.c b/fs/afs/cell.c index 52233fa6195f..887b673f6223 100644 --- a/fs/afs/cell.c +++ b/fs/afs/cell.c @@ -589,7 +589,7 @@ struct afs_cell *afs_use_cell(struct afs_cell *cell, enum afs_cell_trace reason) */ void afs_unuse_cell(struct afs_net *net, struct afs_cell *cell, enum afs_cell_trace reason) { - unsigned int debug_id = cell->debug_id; + unsigned int debug_id; time64_t now, expire_delay; int u, a; @@ -604,6 +604,7 @@ void afs_unuse_cell(struct afs_net *net, struct afs_cell *cell, enum afs_cell_tr if (cell->vl_servers->nr_servers) expire_delay = afs_cell_gc_delay; + debug_id = cell->debug_id; u = atomic_read(&cell->ref); a = atomic_dec_return(&cell->active); trace_afs_cell(debug_id, u, a, reason); From patchwork Tue Oct 27 13:50:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 11860469 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BD48192C for ; Tue, 27 Oct 2020 13:50:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9963322284 for ; Tue, 27 Oct 2020 13:50:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="QLQpMS9X" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752744AbgJ0Nu3 (ORCPT ); Tue, 27 Oct 2020 09:50:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:48466 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752739AbgJ0Nu1 (ORCPT ); Tue, 27 Oct 2020 09:50:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603806626; 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=hhBCr/kNOv10l2PohOVnQJvYd1RPY4KWC4eptFHnJ5k=; b=QLQpMS9X8vOfi0WKJz0KZZccAHMjsshQTbqim8Fnk8qpwjeEYjlEPmFQvpzcxjT8DroIjL OFa/1H5nKmpIq/pWbe9yFJncp2jo3BbJhEs5eBQeCuFCJKy2OX96CoI5AC2MB8zdvstTYs LKlLf2irwU7wpcmbEDRqnQFFJXymQsg= 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-7-85uRaBgJOPKVNzUf8EOfvA-1; Tue, 27 Oct 2020 09:50:23 -0400 X-MC-Unique: 85uRaBgJOPKVNzUf8EOfvA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E7E9918B9ECB; Tue, 27 Oct 2020 13:50:21 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-120-70.rdu2.redhat.com [10.10.120.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id D23565B4A6; Tue, 27 Oct 2020 13:50:20 +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 03/10] afs: Fix a use after free in afs_xattr_get_acl() From: David Howells To: linux-afs@lists.infradead.org Cc: Dan Carpenter , Colin Ian King , dhowells@redhat.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Tue, 27 Oct 2020 13:50:17 +0000 Message-ID: <160380661706.3467511.14857214144343578659.stgit@warthog.procyon.org.uk> In-Reply-To: <160380659566.3467511.15495463187114465303.stgit@warthog.procyon.org.uk> References: <160380659566.3467511.15495463187114465303.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.23 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Dan Carpenter The "op" pointer is freed earlier when we call afs_put_operation(). Fixes: e49c7b2f6de7 ("afs: Build an abstraction around an "operation" concept") Signed-off-by: Dan Carpenter Signed-off-by: David Howells cc: Colin Ian King --- fs/afs/xattr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/afs/xattr.c b/fs/afs/xattr.c index 84f3c4f57531..38884d6c57cd 100644 --- a/fs/afs/xattr.c +++ b/fs/afs/xattr.c @@ -85,7 +85,7 @@ static int afs_xattr_get_acl(const struct xattr_handler *handler, if (acl->size <= size) memcpy(buffer, acl->data, acl->size); else - op->error = -ERANGE; + ret = -ERANGE; } } From patchwork Tue Oct 27 13:50:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 11860473 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5153A61C for ; Tue, 27 Oct 2020 13:50:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3016521D24 for ; Tue, 27 Oct 2020 13:50:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="AQDeBA4B" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752760AbgJ0Nuf (ORCPT ); Tue, 27 Oct 2020 09:50:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:42154 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752751AbgJ0Nue (ORCPT ); Tue, 27 Oct 2020 09:50:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603806632; 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=u97YpgkYwOflA5DyVOMrwMI90QOOsJn8Gu3ZLDUNc0g=; b=AQDeBA4BglUdTuMI5Q1Acl9WsnNTo4wpud+NNve4xd5PRxJilGS+ADKCwsNEpPJ/gXodhe zblIuiixh66w6JRAY1wCaCDt4BamyPPHJWLtqJwOuu1wjsFAGyR2FQZweCM0AB86Enl9WG kzdkgHteZoytEMGB1zDL/eWswEJInK4= 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-222-ApJocr91McWnoZZsoSCXmg-1; Tue, 27 Oct 2020 09:50:29 -0400 X-MC-Unique: ApJocr91McWnoZZsoSCXmg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A667FADC24; Tue, 27 Oct 2020 13:50:28 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-120-70.rdu2.redhat.com [10.10.120.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id E73941C4; Tue, 27 Oct 2020 13:50:27 +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 04/10] afs: Fix afs_launder_page to not clear PG_writeback From: David Howells To: linux-afs@lists.infradead.org Cc: dhowells@redhat.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Tue, 27 Oct 2020 13:50:27 +0000 Message-ID: <160380662715.3467511.74460863169151977.stgit@warthog.procyon.org.uk> In-Reply-To: <160380659566.3467511.15495463187114465303.stgit@warthog.procyon.org.uk> References: <160380659566.3467511.15495463187114465303.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.23 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Fix afs_launder_page() to not clear PG_writeback on the page it is laundering as the flag isn't set in this case. Fixes: 4343d00872e1 ("afs: Get rid of the afs_writeback record") Signed-off-by: David Howells --- fs/afs/internal.h | 1 + fs/afs/write.c | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/fs/afs/internal.h b/fs/afs/internal.h index 81b0485fd22a..289f5dffa46f 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -812,6 +812,7 @@ struct afs_operation { pgoff_t last; /* last page in mapping to deal with */ unsigned first_offset; /* offset into mapping[first] */ unsigned last_to; /* amount of mapping[last] */ + bool laundering; /* Laundering page, PG_writeback not set */ } store; struct { struct iattr *attr; diff --git a/fs/afs/write.c b/fs/afs/write.c index da12abd6db21..b937ec047ec9 100644 --- a/fs/afs/write.c +++ b/fs/afs/write.c @@ -396,7 +396,8 @@ static void afs_store_data_success(struct afs_operation *op) op->ctime = op->file[0].scb.status.mtime_client; afs_vnode_commit_status(op, &op->file[0]); if (op->error == 0) { - afs_pages_written_back(vnode, op->store.first, op->store.last); + if (!op->store.laundering) + afs_pages_written_back(vnode, op->store.first, op->store.last); afs_stat_v(vnode, n_stores); atomic_long_add((op->store.last * PAGE_SIZE + op->store.last_to) - (op->store.first * PAGE_SIZE + op->store.first_offset), @@ -415,7 +416,7 @@ static const struct afs_operation_ops afs_store_data_operation = { */ static int afs_store_data(struct address_space *mapping, pgoff_t first, pgoff_t last, - unsigned offset, unsigned to) + unsigned offset, unsigned to, bool laundering) { struct afs_vnode *vnode = AFS_FS_I(mapping->host); struct afs_operation *op; @@ -448,6 +449,7 @@ static int afs_store_data(struct address_space *mapping, op->store.last = last; op->store.first_offset = offset; op->store.last_to = to; + op->store.laundering = laundering; op->mtime = vnode->vfs_inode.i_mtime; op->flags |= AFS_OPERATION_UNINTR; op->ops = &afs_store_data_operation; @@ -601,7 +603,7 @@ static int afs_write_back_from_locked_page(struct address_space *mapping, if (end > i_size) to = i_size & ~PAGE_MASK; - ret = afs_store_data(mapping, first, last, offset, to); + ret = afs_store_data(mapping, first, last, offset, to, false); switch (ret) { case 0: ret = count; @@ -921,7 +923,7 @@ int afs_launder_page(struct page *page) trace_afs_page_dirty(vnode, tracepoint_string("launder"), page->index, priv); - ret = afs_store_data(mapping, page->index, page->index, t, f); + ret = afs_store_data(mapping, page->index, page->index, t, f, true); } trace_afs_page_dirty(vnode, tracepoint_string("laundered"), From patchwork Tue Oct 27 13:50:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 11860475 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 50DC192C for ; Tue, 27 Oct 2020 13:50:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2F4FA21D41 for ; Tue, 27 Oct 2020 13:50:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="gzD8vBqu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752781AbgJ0Nun (ORCPT ); Tue, 27 Oct 2020 09:50:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:50306 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752770AbgJ0Num (ORCPT ); Tue, 27 Oct 2020 09:50:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603806640; 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=ORcn3B8leoo4q9li1h7odSk682umRjCQ5ZaqggknKR8=; b=gzD8vBquEcJS2tfHRmFW4LTipgqwXbj46YLVOmZSJ+nlL40qibqEadbhdcP/MC75RYHJqO JWpZwqebOofSDkCBEa9odabm/rvqVj1IezUF3Rf8aJVF6JefPf/k8s9kjqrQBzGgPVsPBN 6bX0/GofdqFEXvMmp/bgSkiTmgbk1KE= 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-532-gxCmdxOwOne1cMeZ5dFaXg-1; Tue, 27 Oct 2020 09:50:36 -0400 X-MC-Unique: gxCmdxOwOne1cMeZ5dFaXg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BAF75ADC27; Tue, 27 Oct 2020 13:50:35 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-120-70.rdu2.redhat.com [10.10.120.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id A672B5D9DD; Tue, 27 Oct 2020 13:50:34 +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 05/10] afs: Fix to take ref on page when PG_private is set From: David Howells To: linux-afs@lists.infradead.org Cc: "Matthew Wilcox (Oracle)" , dhowells@redhat.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Tue, 27 Oct 2020 13:50:33 +0000 Message-ID: <160380663388.3467511.14067951162593405018.stgit@warthog.procyon.org.uk> In-Reply-To: <160380659566.3467511.15495463187114465303.stgit@warthog.procyon.org.uk> References: <160380659566.3467511.15495463187114465303.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.23 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Fix afs to take a ref on a page when it sets PG_private on it and to drop the ref when removing the flag. Note that in afs_write_begin(), a lot of the time, PG_private is already set on a page to which we're going to add some data. In such a case, we leave the bit set and mustn't increment the page count. To this end, make TestSetPagePrivate() available. Fixes: 31143d5d515e ("AFS: implement basic file write support") Reported-by: Matthew Wilcox (Oracle) Signed-off-by: David Howells --- fs/afs/dir.c | 3 +++ fs/afs/dir_edit.c | 1 + fs/afs/file.c | 2 ++ fs/afs/write.c | 9 +++++++-- include/linux/page-flags.h | 1 + 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/fs/afs/dir.c b/fs/afs/dir.c index 1d2e61e0ab04..064eb66c33e9 100644 --- a/fs/afs/dir.c +++ b/fs/afs/dir.c @@ -283,6 +283,7 @@ static struct afs_read *afs_read_dir(struct afs_vnode *dvnode, struct key *key) set_page_private(req->pages[i], 1); SetPagePrivate(req->pages[i]); + get_page(req->pages[i]); unlock_page(req->pages[i]); i++; } else { @@ -1977,6 +1978,7 @@ static int afs_dir_releasepage(struct page *page, gfp_t gfp_flags) set_page_private(page, 0); ClearPagePrivate(page); + put_page(page); /* The directory will need reloading. */ if (test_and_clear_bit(AFS_VNODE_DIR_VALID, &dvnode->flags)) @@ -2006,5 +2008,6 @@ static void afs_dir_invalidatepage(struct page *page, unsigned int offset, if (offset == 0 && length == PAGE_SIZE) { set_page_private(page, 0); ClearPagePrivate(page); + put_page(page); } } diff --git a/fs/afs/dir_edit.c b/fs/afs/dir_edit.c index b108528bf010..997f6798beee 100644 --- a/fs/afs/dir_edit.c +++ b/fs/afs/dir_edit.c @@ -246,6 +246,7 @@ void afs_edit_dir_add(struct afs_vnode *vnode, if (!PagePrivate(page)) { set_page_private(page, 1); SetPagePrivate(page); + get_page(page); } dir_page = kmap(page); } diff --git a/fs/afs/file.c b/fs/afs/file.c index 91225421ad37..7dafa2266048 100644 --- a/fs/afs/file.c +++ b/fs/afs/file.c @@ -632,6 +632,7 @@ static void afs_invalidatepage(struct page *page, unsigned int offset, page->index, priv); set_page_private(page, 0); ClearPagePrivate(page); + put_page(page); } } @@ -666,6 +667,7 @@ static int afs_releasepage(struct page *page, gfp_t gfp_flags) page->index, priv); set_page_private(page, 0); ClearPagePrivate(page); + put_page(page); } /* indicate that the page can be released */ diff --git a/fs/afs/write.c b/fs/afs/write.c index b937ec047ec9..29685947324e 100644 --- a/fs/afs/write.c +++ b/fs/afs/write.c @@ -151,7 +151,8 @@ int afs_write_begin(struct file *file, struct address_space *mapping, priv |= f; trace_afs_page_dirty(vnode, tracepoint_string("begin"), page->index, priv); - SetPagePrivate(page); + if (!TestSetPagePrivate(page)) + get_page(page); set_page_private(page, priv); _leave(" = 0"); return 0; @@ -338,6 +339,8 @@ static void afs_pages_written_back(struct afs_vnode *vnode, trace_afs_page_dirty(vnode, tracepoint_string("clear"), pv.pages[loop]->index, priv); set_page_private(pv.pages[loop], 0); + ClearPagePrivate(pv.pages[loop]); + put_page(pv.pages[loop]); end_page_writeback(pv.pages[loop]); } first += count; @@ -863,7 +866,8 @@ vm_fault_t afs_page_mkwrite(struct vm_fault *vmf) priv |= 0; /* From */ trace_afs_page_dirty(vnode, tracepoint_string("mkwrite"), vmf->page->index, priv); - SetPagePrivate(vmf->page); + if (!TestSetPagePrivate(vmf->page)) + get_page(vmf->page); set_page_private(vmf->page, priv); file_update_time(file); @@ -930,6 +934,7 @@ int afs_launder_page(struct page *page) page->index, priv); set_page_private(page, 0); ClearPagePrivate(page); + put_page(page); #ifdef CONFIG_AFS_FSCACHE if (PageFsCache(page)) { diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 4f6ba9379112..37d65b55a6c6 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -365,6 +365,7 @@ PAGEFLAG(SwapBacked, swapbacked, PF_NO_TAIL) */ PAGEFLAG(Private, private, PF_ANY) __SETPAGEFLAG(Private, private, PF_ANY) __CLEARPAGEFLAG(Private, private, PF_ANY) + TESTSETFLAG(Private, private, PF_ANY) PAGEFLAG(Private2, private_2, PF_ANY) TESTSCFLAG(Private2, private_2, PF_ANY) PAGEFLAG(OwnerPriv1, owner_priv_1, PF_ANY) TESTCLEARFLAG(OwnerPriv1, owner_priv_1, PF_ANY) From patchwork Tue Oct 27 13:50:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 11860479 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B526261C for ; Tue, 27 Oct 2020 13:50:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 98E7921D41 for ; Tue, 27 Oct 2020 13:50:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="buA4rSQR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752799AbgJ0Nuv (ORCPT ); Tue, 27 Oct 2020 09:50:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:37961 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752789AbgJ0Nus (ORCPT ); Tue, 27 Oct 2020 09:50:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603806647; 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=s2YMz5yf9+SeEgiySGBI5pPwoN+sAaxpPqNpLxdLua0=; b=buA4rSQRqcbTR9CCs1cQEgmvr9mjAt6XdsZLJI64DJqYt83IAmAcIPWZ8WHtzyGJCdNCZX 1iwAZtYjUnA9b+icFKjT6gSLnrD+DV8f2jEdJiwZyykw0BB/bKTZ1UfGgdkiIKO6lc7oJv lBMzXsqIu79HIsf6cDtpyiEwzzhVSV4= 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-323-j7gEmXULMwq8YjggTPd6wg-1; Tue, 27 Oct 2020 09:50:43 -0400 X-MC-Unique: j7gEmXULMwq8YjggTPd6wg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9C2EAADC26; Tue, 27 Oct 2020 13:50:42 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-120-70.rdu2.redhat.com [10.10.120.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id B7B0860C07; Tue, 27 Oct 2020 13:50:41 +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 06/10] afs: Fix page leak on afs_write_begin() failure From: David Howells To: linux-afs@lists.infradead.org Cc: Nick Piggin , dhowells@redhat.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Tue, 27 Oct 2020 13:50:41 +0000 Message-ID: <160380664097.3467511.9634415545849258835.stgit@warthog.procyon.org.uk> In-Reply-To: <160380659566.3467511.15495463187114465303.stgit@warthog.procyon.org.uk> References: <160380659566.3467511.15495463187114465303.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.23 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Fix the leak of the target page in afs_write_begin() when it fails. Fixes: 15b4650e55e0 ("afs: convert to new aops") Signed-off-by: David Howells cc: Nick Piggin --- fs/afs/write.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/fs/afs/write.c b/fs/afs/write.c index 29685947324e..16a896096ccf 100644 --- a/fs/afs/write.c +++ b/fs/afs/write.c @@ -76,7 +76,7 @@ static int afs_fill_page(struct afs_vnode *vnode, struct key *key, */ int afs_write_begin(struct file *file, struct address_space *mapping, loff_t pos, unsigned len, unsigned flags, - struct page **pagep, void **fsdata) + struct page **_page, void **fsdata) { struct afs_vnode *vnode = AFS_FS_I(file_inode(file)); struct page *page; @@ -110,9 +110,6 @@ int afs_write_begin(struct file *file, struct address_space *mapping, SetPageUptodate(page); } - /* page won't leak in error case: it eventually gets cleaned off LRU */ - *pagep = page; - try_again: /* See if this page is already partially written in a way that we can * merge the new write with. @@ -154,6 +151,7 @@ int afs_write_begin(struct file *file, struct address_space *mapping, if (!TestSetPagePrivate(page)) get_page(page); set_page_private(page, priv); + *_page = page; _leave(" = 0"); return 0; @@ -163,17 +161,18 @@ int afs_write_begin(struct file *file, struct address_space *mapping, flush_conflicting_write: _debug("flush conflict"); ret = write_one_page(page); - if (ret < 0) { - _leave(" = %d", ret); - return ret; - } + if (ret < 0) + goto error; ret = lock_page_killable(page); - if (ret < 0) { - _leave(" = %d", ret); - return ret; - } + if (ret < 0) + goto error; goto try_again; + +error: + put_page(page); + _leave(" = %d", ret); + return ret; } /* From patchwork Tue Oct 27 13:50:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 11860487 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7A85792C for ; Tue, 27 Oct 2020 13:51:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5FCB221D41 for ; Tue, 27 Oct 2020 13:51:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="h0/8Ik7l" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752812AbgJ0Nu5 (ORCPT ); Tue, 27 Oct 2020 09:50:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:40169 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752800AbgJ0Nux (ORCPT ); Tue, 27 Oct 2020 09:50:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603806652; 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=zRhi7APciQrik/nT2sHzIcXgBkf/nbz0yk1cveHlULg=; b=h0/8Ik7lXlxa79KL7rJahbtsFPPlPn6Fm9yB740YMjuI3Vpg4akeGPaVgScADtI94AotHk 2nh17k0EVWlpSyzn5isBHM31dDJPDnT72yW7g9N6pwDfOtR4UrGIqaLfdl1RiSP4c8E1ms XvbK3ksJyUbWtDUlS/GYH+RuGxVoUV4= 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-410-81TvMCYzPEKj26z6PGNGAA-1; Tue, 27 Oct 2020 09:50:50 -0400 X-MC-Unique: 81TvMCYzPEKj26z6PGNGAA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 769B4ADC25; Tue, 27 Oct 2020 13:50:49 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-120-70.rdu2.redhat.com [10.10.120.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9548B5C1BB; Tue, 27 Oct 2020 13:50:48 +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 07/10] afs: Fix where page->private is set during write From: David Howells To: linux-afs@lists.infradead.org Cc: dhowells@redhat.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Tue, 27 Oct 2020 13:50:47 +0000 Message-ID: <160380664783.3467511.6933796884685103590.stgit@warthog.procyon.org.uk> In-Reply-To: <160380659566.3467511.15495463187114465303.stgit@warthog.procyon.org.uk> References: <160380659566.3467511.15495463187114465303.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.23 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org In afs, page->private is set to indicate the dirty region of a page. This is done in afs_write_begin(), but that can't take account of whether the copy into the page actually worked. Fix this by moving the change of page->private into afs_write_end(). Fixes: 4343d00872e1 ("afs: Get rid of the afs_writeback record") Signed-off-by: David Howells --- fs/afs/write.c | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/fs/afs/write.c b/fs/afs/write.c index 16a896096ccf..5ed5df906744 100644 --- a/fs/afs/write.c +++ b/fs/afs/write.c @@ -135,22 +135,8 @@ int afs_write_begin(struct file *file, struct address_space *mapping, if (!test_bit(AFS_VNODE_NEW_CONTENT, &vnode->flags) && (to < f || from > t)) goto flush_conflicting_write; - if (from < f) - f = from; - if (to > t) - t = to; - } else { - f = from; - t = to; } - priv = (unsigned long)t << AFS_PRIV_SHIFT; - priv |= f; - trace_afs_page_dirty(vnode, tracepoint_string("begin"), - page->index, priv); - if (!TestSetPagePrivate(page)) - get_page(page); - set_page_private(page, priv); *_page = page; _leave(" = 0"); return 0; @@ -184,6 +170,9 @@ int afs_write_end(struct file *file, struct address_space *mapping, { struct afs_vnode *vnode = AFS_FS_I(file_inode(file)); struct key *key = afs_file_key(file); + unsigned long priv; + unsigned int f, from = pos & (PAGE_SIZE - 1); + unsigned int t, to = from + copied; loff_t i_size, maybe_i_size; int ret; @@ -215,6 +204,30 @@ int afs_write_end(struct file *file, struct address_space *mapping, SetPageUptodate(page); } + if (PagePrivate(page)) { + priv = page_private(page); + f = priv & AFS_PRIV_MAX; + t = priv >> AFS_PRIV_SHIFT; + if (from < f) + f = from; + if (to > t) + t = to; + priv = (unsigned long)t << AFS_PRIV_SHIFT; + priv |= f; + trace_afs_page_dirty(vnode, tracepoint_string("dirty+"), + page->index, priv); + } else { + SetPagePrivate(page); + get_page(page); + f = from; + t = to; + priv = (unsigned long)t << AFS_PRIV_SHIFT; + priv |= f; + trace_afs_page_dirty(vnode, tracepoint_string("dirty"), + page->index, priv); + } + + set_page_private(page, priv); set_page_dirty(page); if (PageDirty(page)) _debug("dirtied"); From patchwork Tue Oct 27 13:50:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 11860481 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4D35692C for ; Tue, 27 Oct 2020 13:51:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 27B9321D24 for ; Tue, 27 Oct 2020 13:51:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Y1+tWpQu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752842AbgJ0NvF (ORCPT ); Tue, 27 Oct 2020 09:51:05 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:53415 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752802AbgJ0NvE (ORCPT ); Tue, 27 Oct 2020 09:51:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603806662; 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=8+jb4Uum0YDVbkpAFXhZteFm7QpAvfmGgqEE4z4q5ck=; b=Y1+tWpQuOG5aDjnZDm4d7ohmURRvq7U/NtQLozf1mtEaC6W9W5EAQm+xnc+16Bma7vmHDv ysQ+sSrpX8MSAsmvSkjuqicekXzcZ3iBhyvb3GEBy+kL8U8nh1Vj9SGEcNS4Nx9WX2ONV4 zu4UbvCXt4a5+pcdEYW0pGbfRjUhOl8= 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-563-m7wWUJasOqSgkfC57lUcSw-1; Tue, 27 Oct 2020 09:50:57 -0400 X-MC-Unique: m7wWUJasOqSgkfC57lUcSw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4A2DA106B80D; Tue, 27 Oct 2020 13:50:56 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-120-70.rdu2.redhat.com [10.10.120.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5749B60C07; Tue, 27 Oct 2020 13:50:55 +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 08/10] afs: Wrap page->private manipulations in inline functions From: David Howells To: linux-afs@lists.infradead.org Cc: dhowells@redhat.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Tue, 27 Oct 2020 13:50:54 +0000 Message-ID: <160380665455.3467511.8273234602878423351.stgit@warthog.procyon.org.uk> In-Reply-To: <160380659566.3467511.15495463187114465303.stgit@warthog.procyon.org.uk> References: <160380659566.3467511.15495463187114465303.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.23 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The afs filesystem uses page->private to store the dirty range within a page such that in the event of a conflicting 3rd-party write to the server, we write back just the bits that got changed locally. However, there are a couple of problems with this: (1) I need a bit to note if the page might be mapped so that partial invalidation doesn't shrink the range. (2) There aren't necessarily sufficient bits to store the entire range of data altered (say it's a 32-bit system with 64KiB pages or transparent huge pages are in use). So wrap the accesses in inline functions so that future commits can change how this works. Also move them out of the tracing header into the in-directory header. There's not really any need for them to be in the tracing header. Signed-off-by: David Howells --- fs/afs/internal.h | 28 ++++++++++++++++++++++++++++ fs/afs/write.c | 31 +++++++++++++------------------ include/trace/events/afs.h | 19 +++---------------- 3 files changed, 44 insertions(+), 34 deletions(-) diff --git a/fs/afs/internal.h b/fs/afs/internal.h index 289f5dffa46f..acefa6bf0a4d 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -858,6 +858,34 @@ struct afs_vnode_cache_aux { u64 data_version; } __packed; +/* + * We use page->private to hold the amount of the page that we've written to, + * splitting the field into two parts. However, we need to represent a range + * 0...PAGE_SIZE inclusive, so we can't support 64K pages on a 32-bit system. + */ +#if PAGE_SIZE > 32768 +#define __AFS_PAGE_PRIV_MASK 0xffffffff +#define __AFS_PAGE_PRIV_SHIFT 32 +#else +#define __AFS_PAGE_PRIV_MASK 0xffff +#define __AFS_PAGE_PRIV_SHIFT 16 +#endif + +static inline unsigned int afs_page_dirty_from(unsigned long priv) +{ + return priv & __AFS_PAGE_PRIV_MASK; +} + +static inline unsigned int afs_page_dirty_to(unsigned long priv) +{ + return (priv >> __AFS_PAGE_PRIV_SHIFT) & __AFS_PAGE_PRIV_MASK; +} + +static inline unsigned long afs_page_dirty(unsigned int from, unsigned int to) +{ + return ((unsigned long)to << __AFS_PAGE_PRIV_SHIFT) | from; +} + #include /*****************************************************************************/ diff --git a/fs/afs/write.c b/fs/afs/write.c index 5ed5df906744..91bc2cb2cad1 100644 --- a/fs/afs/write.c +++ b/fs/afs/write.c @@ -117,8 +117,8 @@ int afs_write_begin(struct file *file, struct address_space *mapping, t = f = 0; if (PagePrivate(page)) { priv = page_private(page); - f = priv & AFS_PRIV_MAX; - t = priv >> AFS_PRIV_SHIFT; + f = afs_page_dirty_from(priv); + t = afs_page_dirty_to(priv); ASSERTCMP(f, <=, t); } @@ -206,23 +206,19 @@ int afs_write_end(struct file *file, struct address_space *mapping, if (PagePrivate(page)) { priv = page_private(page); - f = priv & AFS_PRIV_MAX; - t = priv >> AFS_PRIV_SHIFT; + f = afs_page_dirty_from(priv); + t = afs_page_dirty_to(priv); if (from < f) f = from; if (to > t) t = to; - priv = (unsigned long)t << AFS_PRIV_SHIFT; - priv |= f; + priv = afs_page_dirty(f, t); trace_afs_page_dirty(vnode, tracepoint_string("dirty+"), page->index, priv); } else { SetPagePrivate(page); get_page(page); - f = from; - t = to; - priv = (unsigned long)t << AFS_PRIV_SHIFT; - priv |= f; + priv = afs_page_dirty(from, to); trace_afs_page_dirty(vnode, tracepoint_string("dirty"), page->index, priv); } @@ -526,8 +522,8 @@ static int afs_write_back_from_locked_page(struct address_space *mapping, */ start = primary_page->index; priv = page_private(primary_page); - offset = priv & AFS_PRIV_MAX; - to = priv >> AFS_PRIV_SHIFT; + offset = afs_page_dirty_from(priv); + to = afs_page_dirty_to(priv); trace_afs_page_dirty(vnode, tracepoint_string("store"), primary_page->index, priv); @@ -572,8 +568,8 @@ static int afs_write_back_from_locked_page(struct address_space *mapping, } priv = page_private(page); - f = priv & AFS_PRIV_MAX; - t = priv >> AFS_PRIV_SHIFT; + f = afs_page_dirty_from(priv); + t = afs_page_dirty_to(priv); if (f != 0 && !test_bit(AFS_VNODE_NEW_CONTENT, &vnode->flags)) { unlock_page(page); @@ -874,8 +870,7 @@ vm_fault_t afs_page_mkwrite(struct vm_fault *vmf) */ wait_on_page_writeback(vmf->page); - priv = (unsigned long)PAGE_SIZE << AFS_PRIV_SHIFT; /* To */ - priv |= 0; /* From */ + priv = afs_page_dirty(0, PAGE_SIZE); trace_afs_page_dirty(vnode, tracepoint_string("mkwrite"), vmf->page->index, priv); if (!TestSetPagePrivate(vmf->page)) @@ -933,8 +928,8 @@ int afs_launder_page(struct page *page) f = 0; t = PAGE_SIZE; if (PagePrivate(page)) { - f = priv & AFS_PRIV_MAX; - t = priv >> AFS_PRIV_SHIFT; + f = afs_page_dirty_from(priv); + t = afs_page_dirty_to(priv); } trace_afs_page_dirty(vnode, tracepoint_string("launder"), diff --git a/include/trace/events/afs.h b/include/trace/events/afs.h index 8eb49231c6bb..e718ae17ad91 100644 --- a/include/trace/events/afs.h +++ b/include/trace/events/afs.h @@ -966,19 +966,6 @@ TRACE_EVENT(afs_dir_check_failed, __entry->vnode, __entry->off, __entry->i_size) ); -/* - * We use page->private to hold the amount of the page that we've written to, - * splitting the field into two parts. However, we need to represent a range - * 0...PAGE_SIZE inclusive, so we can't support 64K pages on a 32-bit system. - */ -#if PAGE_SIZE > 32768 -#define AFS_PRIV_MAX 0xffffffff -#define AFS_PRIV_SHIFT 32 -#else -#define AFS_PRIV_MAX 0xffff -#define AFS_PRIV_SHIFT 16 -#endif - TRACE_EVENT(afs_page_dirty, TP_PROTO(struct afs_vnode *vnode, const char *where, pgoff_t page, unsigned long priv), @@ -999,10 +986,10 @@ TRACE_EVENT(afs_page_dirty, __entry->priv = priv; ), - TP_printk("vn=%p %lx %s %lu-%lu", + TP_printk("vn=%p %lx %s %x-%x", __entry->vnode, __entry->page, __entry->where, - __entry->priv & AFS_PRIV_MAX, - __entry->priv >> AFS_PRIV_SHIFT) + afs_page_dirty_from(__entry->priv), + afs_page_dirty_to(__entry->priv)) ); TRACE_EVENT(afs_call_state, From patchwork Tue Oct 27 13:51:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 11860485 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D53B161C for ; Tue, 27 Oct 2020 13:51:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BB48721D24 for ; Tue, 27 Oct 2020 13:51:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="UGNh5Luh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752846AbgJ0NvJ (ORCPT ); Tue, 27 Oct 2020 09:51:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:36327 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752844AbgJ0NvH (ORCPT ); Tue, 27 Oct 2020 09:51:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603806666; 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=WwHqBrIiBjdf25gGnD1YX594H4Kf+w9kJfjTvFy9bM0=; b=UGNh5LuhIwj2lxXrjAHX5dRCUOgqtJAT+OX2qGxcMgTVFaDpROrsv4NpwpaQP3vyo3mNEf y8cyXsB/SaLZ79PkRP8X0csXAmz5u7OtG/c8L/oYxQzrOVWUHMCJUn4VxuQxEZ0+1ioZ9c rPBW473tZd56kx+5NJvA6oHPlvedtnw= 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-396-LvrG_EvTOzG34sLbFgXHZg-1; Tue, 27 Oct 2020 09:51:04 -0400 X-MC-Unique: LvrG_EvTOzG34sLbFgXHZg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 02CF3ADC28; Tue, 27 Oct 2020 13:51:03 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-120-70.rdu2.redhat.com [10.10.120.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id 412255C1BB; Tue, 27 Oct 2020 13:51:02 +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 09/10] afs: Alter dirty range encoding in page->private From: David Howells To: linux-afs@lists.infradead.org Cc: dhowells@redhat.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Tue, 27 Oct 2020 13:51:01 +0000 Message-ID: <160380666151.3467511.11680534843519213308.stgit@warthog.procyon.org.uk> In-Reply-To: <160380659566.3467511.15495463187114465303.stgit@warthog.procyon.org.uk> References: <160380659566.3467511.15495463187114465303.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.23 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Currently, page->private on an afs page is used to store the range of dirtied data within the page, where the range includes the lower bound, but excludes the upper bound (e.g. 0-1 is a range covering a single byte). This, however, requires a superfluous bit for the last-byte bound so that on a 4KiB page, it can say 0-4096 to indicate the whole page, the idea being that having both numbers the same would indicate an empty range. This is unnecessary as the PG_private bit is clear if it's an empty range (as is PG_dirty). Alter the way the dirty range is encoded in page->private such that the upper bound is reduced by 1 (e.g. 0-0 is then specified the same single byte range mentioned above). Applying this to both bounds frees up two bits, one of which can be used in a future commit. Signed-off-by: David Howells --- fs/afs/internal.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/afs/internal.h b/fs/afs/internal.h index acefa6bf0a4d..0ff1088a7c87 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -878,12 +878,12 @@ static inline unsigned int afs_page_dirty_from(unsigned long priv) static inline unsigned int afs_page_dirty_to(unsigned long priv) { - return (priv >> __AFS_PAGE_PRIV_SHIFT) & __AFS_PAGE_PRIV_MASK; + return ((priv >> __AFS_PAGE_PRIV_SHIFT) & __AFS_PAGE_PRIV_MASK) + 1; } static inline unsigned long afs_page_dirty(unsigned int from, unsigned int to) { - return ((unsigned long)to << __AFS_PAGE_PRIV_SHIFT) | from; + return ((unsigned long)(to - 1) << __AFS_PAGE_PRIV_SHIFT) | from; } #include From patchwork Tue Oct 27 13:51:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 11860489 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 32B1E61C for ; Tue, 27 Oct 2020 13:51:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 12C9A221F8 for ; Tue, 27 Oct 2020 13:51:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="B+UrlGof" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2502419AbgJ0NvU (ORCPT ); Tue, 27 Oct 2020 09:51:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:24786 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2442646AbgJ0NvQ (ORCPT ); Tue, 27 Oct 2020 09:51:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603806675; 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=3AiLl1eB6pu6nkS4S8/HRk5466oI9SjgvcO/Y14HF40=; b=B+UrlGofNgv34BU1YcYZMCGqI7hIr7fHrPCv6CKlfTncaWnj3ADuMg+h1OTHTiTF5f1xed I6nblVfXKk86w99vfaWnhDKjmnV1k8jtRFnyUcFbdo7oOOhba/DDPrYdOuiRQJNhtVZAKT hq+qmIkgUEd1uiwUM76alx4x0OAZalc= 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-34-04png136NkuYy9KXzprDbw-1; Tue, 27 Oct 2020 09:51:11 -0400 X-MC-Unique: 04png136NkuYy9KXzprDbw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E6680809DD5; Tue, 27 Oct 2020 13:51:09 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-120-70.rdu2.redhat.com [10.10.120.70]) by smtp.corp.redhat.com (Postfix) with ESMTP id 026146EF55; Tue, 27 Oct 2020 13:51:08 +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 10/10] afs: Fix afs_invalidatepage to adjust the dirty region From: David Howells To: linux-afs@lists.infradead.org Cc: dhowells@redhat.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Tue, 27 Oct 2020 13:51:08 +0000 Message-ID: <160380666821.3467511.7028989455667789924.stgit@warthog.procyon.org.uk> In-Reply-To: <160380659566.3467511.15495463187114465303.stgit@warthog.procyon.org.uk> References: <160380659566.3467511.15495463187114465303.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.23 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Fix afs_invalidatepage() to adjust the dirty region recorded in page->private when truncating a page. If the dirty region is entirely removed, then the private data is cleared and the page dirty state is cleared. Without this, if the page is truncated and then expanded again by truncate, zeros from the expanded, but no-longer dirty region may get written back to the server if the page gets laundered due to a conflicting 3rd-party write. It mustn't, however, shorten the dirty region of the page if that page is still mmapped and has been marked dirty by afs_page_mkwrite(), so a flag is stored in page->private to record this. Fixes: 4343d00872e1 ("afs: Get rid of the afs_writeback record") Signed-off-by: David Howells --- fs/afs/file.c | 74 +++++++++++++++++++++++++++++++++++++------- fs/afs/internal.h | 16 ++++++++-- fs/afs/write.c | 1 + include/trace/events/afs.h | 5 ++- 4 files changed, 80 insertions(+), 16 deletions(-) diff --git a/fs/afs/file.c b/fs/afs/file.c index 7dafa2266048..e3cec86cc6ef 100644 --- a/fs/afs/file.c +++ b/fs/afs/file.c @@ -601,6 +601,65 @@ static int afs_readpages(struct file *file, struct address_space *mapping, return ret; } +/* + * Adjust the dirty region of the page on truncation or full invalidation, + * getting rid of the markers altogether if the region is entirely invalidated. + */ +static void afs_invalidate_dirty(struct page *page, unsigned int offset, + unsigned int length) +{ + struct afs_vnode *vnode = AFS_FS_I(page->mapping->host); + unsigned long priv; + unsigned int f, t, end = offset + length; + + priv = page_private(page); + + /* we clean up only if the entire page is being invalidated */ + if (offset == 0 && length == thp_size(page)) + goto full_invalidate; + + /* If the page was dirtied by page_mkwrite(), the PTE stays writable + * and we don't get another notification to tell us to expand it + * again. + */ + if (afs_is_page_dirty_mmapped(priv)) + return; + + /* We may need to shorten the dirty region */ + f = afs_page_dirty_from(priv); + t = afs_page_dirty_to(priv); + + if (t <= offset || f >= end) + return; /* Doesn't overlap */ + + if (f < offset && t > end) + return; /* Splits the dirty region - just absorb it */ + + if (f >= offset && t <= end) + goto undirty; + + if (f < offset) + t = offset; + else + f = end; + if (f == t) + goto undirty; + + priv = afs_page_dirty(f, t); + set_page_private(page, priv); + trace_afs_page_dirty(vnode, tracepoint_string("trunc"), page->index, priv); + return; + +undirty: + trace_afs_page_dirty(vnode, tracepoint_string("undirty"), page->index, priv); + clear_page_dirty_for_io(page); +full_invalidate: + trace_afs_page_dirty(vnode, tracepoint_string("inval"), page->index, priv); + set_page_private(page, 0); + ClearPagePrivate(page); + put_page(page); +} + /* * invalidate part or all of a page * - release a page and clean up its private data if offset is 0 (indicating @@ -609,9 +668,6 @@ static int afs_readpages(struct file *file, struct address_space *mapping, static void afs_invalidatepage(struct page *page, unsigned int offset, unsigned int length) { - struct afs_vnode *vnode = AFS_FS_I(page->mapping->host); - unsigned long priv; - _enter("{%lu},%u,%u", page->index, offset, length); BUG_ON(!PageLocked(page)); @@ -625,17 +681,11 @@ static void afs_invalidatepage(struct page *page, unsigned int offset, fscache_uncache_page(vnode->cache, page); } #endif - - if (PagePrivate(page)) { - priv = page_private(page); - trace_afs_page_dirty(vnode, tracepoint_string("inval"), - page->index, priv); - set_page_private(page, 0); - ClearPagePrivate(page); - put_page(page); - } } + if (PagePrivate(page)) + afs_invalidate_dirty(page, offset, length); + _leave(""); } diff --git a/fs/afs/internal.h b/fs/afs/internal.h index 0ff1088a7c87..bf8fb9863b0e 100644 --- a/fs/afs/internal.h +++ b/fs/afs/internal.h @@ -864,11 +864,13 @@ struct afs_vnode_cache_aux { * 0...PAGE_SIZE inclusive, so we can't support 64K pages on a 32-bit system. */ #if PAGE_SIZE > 32768 -#define __AFS_PAGE_PRIV_MASK 0xffffffff +#define __AFS_PAGE_PRIV_MASK 0x7fffffff #define __AFS_PAGE_PRIV_SHIFT 32 +#define __AFS_PRIV_MMAPPED 0x80000000 #else -#define __AFS_PAGE_PRIV_MASK 0xffff +#define __AFS_PAGE_PRIV_MASK 0x7fff #define __AFS_PAGE_PRIV_SHIFT 16 +#define __AFS_PRIV_MMAPPED 0x8000 #endif static inline unsigned int afs_page_dirty_from(unsigned long priv) @@ -886,6 +888,16 @@ static inline unsigned long afs_page_dirty(unsigned int from, unsigned int to) return ((unsigned long)(to - 1) << __AFS_PAGE_PRIV_SHIFT) | from; } +static inline unsigned long afs_page_dirty_mmapped(unsigned long priv) +{ + return priv | __AFS_PRIV_MMAPPED; +} + +static inline bool afs_is_page_dirty_mmapped(unsigned long priv) +{ + return priv & __AFS_PRIV_MMAPPED; +} + #include /*****************************************************************************/ diff --git a/fs/afs/write.c b/fs/afs/write.c index 91bc2cb2cad1..057d02fd4d02 100644 --- a/fs/afs/write.c +++ b/fs/afs/write.c @@ -871,6 +871,7 @@ vm_fault_t afs_page_mkwrite(struct vm_fault *vmf) wait_on_page_writeback(vmf->page); priv = afs_page_dirty(0, PAGE_SIZE); + priv = afs_page_dirty_mmapped(priv); trace_afs_page_dirty(vnode, tracepoint_string("mkwrite"), vmf->page->index, priv); if (!TestSetPagePrivate(vmf->page)) diff --git a/include/trace/events/afs.h b/include/trace/events/afs.h index e718ae17ad91..91d515cb3aed 100644 --- a/include/trace/events/afs.h +++ b/include/trace/events/afs.h @@ -986,10 +986,11 @@ TRACE_EVENT(afs_page_dirty, __entry->priv = priv; ), - TP_printk("vn=%p %lx %s %x-%x", + TP_printk("vn=%p %lx %s %x-%x%s", __entry->vnode, __entry->page, __entry->where, afs_page_dirty_from(__entry->priv), - afs_page_dirty_to(__entry->priv)) + afs_page_dirty_to(__entry->priv), + afs_is_page_dirty_mmapped(__entry->priv) ? " M" : "") ); TRACE_EVENT(afs_call_state,