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 2F005C77B6F for ; Thu, 13 Apr 2023 21:27:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 538686B0072; Thu, 13 Apr 2023 17:27:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4E923900003; Thu, 13 Apr 2023 17:27:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3D6ED900002; Thu, 13 Apr 2023 17:27:06 -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 2DE5C6B0072 for ; Thu, 13 Apr 2023 17:27:06 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id EADDDC03DB for ; Thu, 13 Apr 2023 21:27:05 +0000 (UTC) X-FDA: 80677653210.13.569A325 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf01.hostedemail.com (Postfix) with ESMTP id 2C68A40003 for ; Thu, 13 Apr 2023 21:27:02 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=E8+u1Eav; spf=pass (imf01.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681421223; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=aXoXuwHwggTCSjwlFujDwYoatDG4/c/4JuEabqde8o4=; b=MgJG67dgt1q1N+acmPB64ijRs69LZvZlMtE36l1dRPfLlUwxCjwf+7kWVA+TCnKsybqAuf zSD8gObDXx+g1PFR9xFtyDW2qar8WmqXwzBYSfLiND42edZ0AW3J1gj5gJ3Lfs0Fr0wvRO jsKOU2Cqt+juhq6UgcXEVaFExfDeOy0= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=E8+u1Eav; spf=pass (imf01.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681421223; a=rsa-sha256; cv=none; b=rSH6te912bdgFMFgHngJ5M/5HRwQYs4g2dZGGH+PBHW+c3VRaFujJCiQ1omkA5K7jDZtVu wDp9q1E3qECGRJ8XdOweUKX6E5CpAy78aTTRvsrE7y2o18HRstmrTnksfOPU9SSIN/+7QN SjJ7mhxdPcCxXou9sjWrIL7QdUSOUXQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681421222; 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: in-reply-to:in-reply-to:references:references; bh=aXoXuwHwggTCSjwlFujDwYoatDG4/c/4JuEabqde8o4=; b=E8+u1Eaveg7Nbbq2Ntazsca2UTd/C0rHJyb+G7CRb2Pd3ROCUq0tW/jJZEO1YdF1CRklgc yNrRLfrkIDj1OcCLlo+bHiYZuJGh3jYkK1plMjE9pvgLSPwh7+YKr3DXrKYRldOCTvi1D1 IOeGn4TpgQCEMdxCEvVe1SdfJhb32Ts= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-547-FAdCCV2ANj2qvZ0o-Yp-KQ-1; Thu, 13 Apr 2023 17:27:00 -0400 X-MC-Unique: FAdCCV2ANj2qvZ0o-Yp-KQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DCF173C0F22E; Thu, 13 Apr 2023 21:26:59 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.177]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA69CC16028; Thu, 13 Apr 2023 21:26:57 +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: <20230413044123.GB3390869@ZenIV> References: <20230413044123.GB3390869@ZenIV> <20230411160902.4134381-1-dhowells@redhat.com> <20230411160902.4134381-7-dhowells@redhat.com> To: Al Viro , Matthew Wilcox Cc: dhowells@redhat.com, netdev@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , David Ahern , Christoph Hellwig , Andrew Morton , Jens Axboe , Jeff Layton , Christian Brauner , Chuck Lever III , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: How to determine if a page can be spliced into an skbuff, or if it should be copied/rejected? MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1208133.1681421217.1@warthog.procyon.org.uk> Date: Thu, 13 Apr 2023 22:26:57 +0100 Message-ID: <1208134.1681421217@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8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BFWtSIVqtnnWr6W1obYfAPdyrh Vt3xVAOo XEQpgNDQeaY6UToqPQA4mSjLT8pGFheZsWxabxqBNZFNIUWZEAlIq8PSPzNldjKGzQhRTEuoCRywXSi5Waxy5muBDGWIe1Aj+bQ902gE8BTctpbV2T40M+k/DiiBVQdtkuA5YzxMVhSU3PPS8hHDZt4w4Cp/CSIISuvhG1DJbA5UOzFflgYZhdsEjf2W2pRKrv/Fay4nvy1c6MqB26d4svzqTjEfL/J5aX1uuznMGc2sJnawpiShg0fBV5lUQKUlnf3hy9e7wRpYVZG+frPzFOc5t29+3GJfkiy4sZkKJvFxA8kH4MeBoSQn4beqULk9KSnSraFJhN6reRrBgpV27sBG4TBm0a9mbDXyroVPyUT3tzTg3C95nKHOmNXSGf3iWlM2TokqAD+RfgKaRxFrprFAEuu8M9GQ2IXMh 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: Al Viro wrote: > On Tue, Apr 11, 2023 at 05:08:50PM +0100, David Howells wrote: > > Add a function to handle MSG_SPLICE_PAGES being passed internally to > > sendmsg(). Pages are spliced into the given socket buffer if possible and > > copied in if not (ie. they're slab pages or have a zero refcount). > > That "ie." would better be "e.g." - that condition is *not* enough for > tell the unsafe ones from the rest. > > sendpage_ok() would be better off called "might_be_ok_to_sendpage()". > If it's false, we'd better not grab a reference to the page and expect the > sucker to stay safe until the reference is dropped. However, AFAICS > it might return true on a page that is not safe in that respect. > > What rules do you propose for sendpage users? "Pass whatever page reference > you want, it'll do the right thing"? Anything short of that would better > be documented as explicitly as possible... Hmmm... Fair point. Is everything passed through splice guaranteed to be safe, I wonder? Probably not because vmsplice(). Does that mean the existing callers of sendpage_ok() are also making unviable assumptions? So there are the following 'classes' of memory that I can immediately think of: - Zero page Splice (no ref?) - Kernel core data Splice - Module core data (vmalloc'd) Splice - Supervisor stack Copy - Slab objects Copy - Page frags Splice - Other skbuff frags Splice - Arbitrary pages (eg. sunrpc xdr buf) Splice (probably) - Ordinary pipe buffers Splice - Spliced tmpfs Splice - Spliced pagecache (file/block) Splice - Spliced DIO file/block Splice - Vmspliced mmap'd anon Splice (with pin?) - Vmspliced MAP_SHARED pagecache Splice (with pin?) - Vmspliced MAP_SHARED DAX Splice? - Vmspliced MAP_SHARED MTD Splice? - Vmspliced MAP_SHARED other device Reject? (e.g. graphics card mem) - Vmspliced /dev/{mem,kmem} Reject? Question is how to tell that we're looking at something that must be copied or rejected? sendpage_ok() checks the PG_slab bit and the pagecount, for example. David