From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 395B1C001B0 for ; Wed, 19 Jul 2023 19:44:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9564F280089; Wed, 19 Jul 2023 15:44:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 905CD28004C; Wed, 19 Jul 2023 15:44:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7CE44280089; Wed, 19 Jul 2023 15:44:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6A65528004C for ; Wed, 19 Jul 2023 15:44:47 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 19005A0427 for ; Wed, 19 Jul 2023 19:44:47 +0000 (UTC) X-FDA: 81029389014.23.342BA04 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf24.hostedemail.com (Postfix) with ESMTP id A51BA180002 for ; Wed, 19 Jul 2023 19:44:44 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="m+PE/dTT"; spf=none (imf24.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689795885; h=from:from:sender: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:dkim-signature; bh=09gXH5WPLUH/2CplgzC5LRXG+n41z1xeytY52mkD4kk=; b=swZ5QGgF0KnaZUp5i+5pFFRl1gdniEGKI6KbLcnfYtXeB3MuCcqYslY+wOTgIpAWK++s0c ShcNus/6aSFs00hdKcH7hoHae2+Xdd3y0st22CjQ852AnVcgu88DI77dtil955SFwufe7U VKNlHBVKSxfxTsZjwr9iynxo7Lk15kI= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="m+PE/dTT"; spf=none (imf24.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689795885; a=rsa-sha256; cv=none; b=z5EfGdsonABy4LyYfCzAF/zSLONqfP4E/+0xt2lFaUZadJn2hzHvv9bpNg9ne+pkRuaup9 AYa6LbBma1A1cLmnP9sh8fuqgbqqkCjmp3N37U29p1vmJHS6fKRbVa+emGis8QX9d3k+Jv hm6EhJSCFiDx98tdhMwp2lRxP3EU6kI= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=09gXH5WPLUH/2CplgzC5LRXG+n41z1xeytY52mkD4kk=; b=m+PE/dTTM6VCcwL3b0YBkVYCFM RnUKaVfGae71cAmNweNZy6Nyxt6jJ7PHj4eHZ93P7R+SPZ+W8/sc9dndzPM1eJAcZ4fEeDKGrYick AEwXOTN1BmSMXPLuJ+xd1G3/rdLNhryhdV2WffAppSEvJ341tuObuAiOSFiRCiQMTRkxqw0s/jNEl Z8LQ/9Bqmeia+xH+uoxXnlFlP/GvG/R6Mf5sL2Xvx/RwovZ3hPZVyAIt8zQeanjnpwloY1Vc5HeCn 7IysHoWWw5mxmqU9IqDXIQQ7jHtSXiDpYphdgr4DbytftBGRRvWcfnKaS/ysIOl40NBZBJqpEOLLr rl151uwg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qMD65-006PmY-2t; Wed, 19 Jul 2023 19:44:29 +0000 Date: Wed, 19 Jul 2023 20:44:29 +0100 From: Matthew Wilcox To: Miklos Szeredi Cc: Matt Whitlock , David Howells , netdev@vger.kernel.org, Dave Chinner , Linus Torvalds , Jens Axboe , linux-fsdevel@kvack.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Christoph Hellwig , linux-fsdevel@vger.kernel.org Subject: Re: [RFC PATCH 1/4] splice: Fix corruption of spliced data after splice() returns Message-ID: References: <20230629155433.4170837-1-dhowells@redhat.com> <20230629155433.4170837-2-dhowells@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspamd-Queue-Id: A51BA180002 X-Rspam-User: X-Stat-Signature: czjazm89x6ndnrtgh96hsrrotm6zx1n1 X-Rspamd-Server: rspam01 X-HE-Tag: 1689795884-724105 X-HE-Meta: U2FsdGVkX18wS9cASUvRX5uMG6jGvGYN3FDgGbrMbR/yEvMNGi+Q1ln0n6nfw7cJ+DtI5/1mnMVfjgsoc48SKXb0DOgtPeDhbmJWBxAuIeivJhPahAA3oz+4sL47tTt3Gd+onAOQAHYEs5M4wFUkrEDzkfCmmDZjv5OaGy5ZsN/AthCJQ1wTNp+z2M66/AK4ugYMm4wnbv2NrG91suxhsB1bWrKWfCtP8Jjb0vvi1jLih8xrBgG+unqQUu8JHWHVl7IVOk0JIIfK/ZhRyfOQ6NG3QlGQ65t0h1QYPooNY70ANAtCzqp+Yi8dHICuTems/3T4x8zoC+t2xXiCJye5X0sTTjcYAIcY2w6X2cT943WZiRUL2a2aJx2ON5SKEfMqdhABFDuXiokAfJHS8Uks221hXjPyjRbHMpk4VrF0sul/+xKfU4yuxxjEWEZaTB1kUT9l9VUvmt48DsjX796Zg/Wv4XnP1vzta4qhxJfMuxACwsGOEYjwe4i4LEkpFbQezOaTnNS8btgbB803JgZng3oEuoSPdRGP9ok7kWsOV7CBzrMVty+qAKJQONp04+q7A99l82yO96GW2HYmwgkV9eIBlNTjjPaMnoATw+jgi9Zl4LqOHORaVognV5cmVezEU0h7iiRWcEj/boACJzZjRB+WB5p2frYIpKPynabuoXqIj5kJEq2TxLSdpl5O3+itvMLCiLwgT4I2r79hkHtRQwqVySNkAuBb5pvv6Y6wm4ALw9hD+g3BKG3hbXU35tqPM7N3kO0Nk+RlZgeAMzkmtyUgAaGplvZlB7CcQ7BesXCrDsxH466kJjqFYQdZhq9oEAMZ6F/kGlacF1iHq5PEaC370DQi1K7cweV5kDCuSQ7YZOuZsMmAP02TpbSNGVaaI6O/1UY5cApr+EWqXPJj/XuLML6RX19215uRZmyg5VEcEAvdoD/vZ0LrYfLs+5c3zZQogpSEJWTqG1an1EQ BMuCg5bx TKqYolwu+svePEspVbUCE97zXOp/789EVu6YQwq98pcHXuaTem7AC01mFTgXrZecXESIg3fLwaptiegg5Hc3IKTpG6VobLGJWacdhswH8dSr/WvZ6hTRBa299sA7ZHh7GF2FXFFzGAYW/tiEmSCagnUzMoh9yNLukGxpk5QzWrbgvwNLQxN1rVS2A2yIRo3EBDYoLm/LCBiWZPX7yzYdspdre4uOD5xIV0aHSbYeuk8ivHCzSPUIlmqPZps/W590IxY2COWudZJuAAE4= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Jul 19, 2023 at 09:35:33PM +0200, Miklos Szeredi wrote: > On Wed, 19 Jul 2023 at 19:59, Matt Whitlock wrote: > > > > On Wednesday, 19 July 2023 06:17:51 EDT, Miklos Szeredi wrote: > > > On Thu, 29 Jun 2023 at 17:56, David Howells wrote: > > >> > > >> Splicing data from, say, a file into a pipe currently leaves the source > > >> pages in the pipe after splice() returns - but this means that those pages > > >> can be subsequently modified by shared-writable mmap(), write(), > > >> fallocate(), etc. before they're consumed. > > > > > > What is this trying to fix? The above behavior is well known, so > > > it's not likely to be a problem. > > > > Respectfully, it's not well-known, as it's not documented. If the splice(2) > > man page had mentioned that pages can be mutated after they're already > > ostensibly at rest in the output pipe buffer, then my nightly backups > > wouldn't have been incurring corruption silently for many months. > > splice(2): > > Though we talk of copying, actual copies are generally avoided. > The kernel does this by implementing a pipe buffer as a set of > refer‐ > ence-counted pointers to pages of kernel memory. The > kernel creates "copies" of pages in a buffer by creating new pointers > (for the > output buffer) referring to the pages, and increasing the > reference counts for the pages: only pointers are copied, not the > pages of the > buffer. > > While not explicitly stating that the contents of the pages can change > after being spliced, this can easily be inferred from the above > semantics. So what's the API that provides the semantics of _copying_? And, frankly, this is a "you're holding it wrong" kind of argument. It only makes sense if you're read the implementation, which is at best level 2: https://ozlabs.org/~rusty/index.cgi/tech/2008-03-30.html and worst a level -5: https://ozlabs.org/~rusty/index.cgi/tech/2008-04-01.html