Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp3021954rwl; Thu, 13 Apr 2023 14:38:12 -0700 (PDT) X-Google-Smtp-Source: AKy350ak2y9h/H0x2Os5pfjFmEC83CUO3/phXml67W/D+fUN21RR152vZQ0NwjdrML5Fd3W9XyDF X-Received: by 2002:a05:6a00:c94:b0:63b:5609:3bb5 with SMTP id a20-20020a056a000c9400b0063b56093bb5mr3822117pfv.18.1681421892413; Thu, 13 Apr 2023 14:38:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681421892; cv=none; d=google.com; s=arc-20160816; b=GP3OHzg02dMErbI43+keUVcxug4iwH0KfMttFrB6uCYHOvPGFyTYIqueFZizoDPHGy 1j2jnCsCmNoUHx6SZQ4NtX8wGgwT1TeNKPeqlHv2CWovFiQ0tsu4kjmw4tdhiFUgCj6t z7ph9cJdwMMDkcwIrlLscqxAVeDt9GH7aSkSEoRu9z/JPgZtZwSJaf+rXxytj/Mz7iYY uJNVgJl3Ej2V/JXI6xHbEfIaVdKR08B8BMgPNVaMbDaqxLxBXZA/0ysFkFQvLxUgIBjI mtiowkQB4G46/twSGY8thYsQBvmQVZwljsxrVZFSRQrJ76Dxoxm7c8QDToyHw3A1abPe WsIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:content-id:mime-version:subject :cc:to:references:in-reply-to:from:organization:dkim-signature; bh=aXoXuwHwggTCSjwlFujDwYoatDG4/c/4JuEabqde8o4=; b=faVMqRcVlp2n6gYIpPR6pUWxfSpv0akjo2CwySjy1EneFu6XbeCa2KEFMDT6NpUDd3 QGE0tRYsB4smnhNsoWvl5InXug78bG+UUELxm1LbRzNpR0nz8onJMsJWxhsznuw8/KmS YcfvT8cATFY5bdTfpFr9gOyGDbt7fxhYoPMcixXlGtL91xmnBNhNGGphzv4hx12p8wkM IgnHJYG5lB9ocZzON7+jql4nUnUZRHgj8PdzL84IPE6GhjTBCJrlP9M2loDe3JmbhGRg QS9RxWlMvYTrVamrkyRiVFt7n8Vb/e5IANSCr9QFfgpnU7aO/xWDHBtWWIQQrpOGLNeq bH1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=P29FKnTz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r207-20020a632bd8000000b0050faafb6a11si2848775pgr.807.2023.04.13.14.38.00; Thu, 13 Apr 2023 14:38:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=P29FKnTz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 S229949AbjDMV1t (ORCPT + 99 others); Thu, 13 Apr 2023 17:27:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229729AbjDMV1s (ORCPT ); Thu, 13 Apr 2023 17:27:48 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AF0459D2 for ; Thu, 13 Apr 2023 14:27:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681421223; 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=P29FKnTzWzJjVgVuKTBQd1cImelJs5EhoAuq/T7ofuWXNtpPFpu/NJ7jJpDEna8hadipEx 0izqHV8myq1BJz5kgR6xpBZCbL6U8TXOLImCqasSJJssf7UYSAufP7Gs2TXAEhRN+yLUhj sc+yhFmdfjs7fmjfGSBOmx8+nO6dEd4= 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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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