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 6DF4EC3ABAC for ; Fri, 2 May 2025 13:42:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2B92A6B000A; Fri, 2 May 2025 09:42:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 266336B0092; Fri, 2 May 2025 09:42:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 12E6D6B0093; Fri, 2 May 2025 09:42:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E86E06B0092 for ; Fri, 2 May 2025 09:41:59 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 377E21D0956 for ; Fri, 2 May 2025 13:42:00 +0000 (UTC) X-FDA: 83398081200.13.2251654 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf10.hostedemail.com (Postfix) with ESMTP id 0597EC000D for ; Fri, 2 May 2025 13:41:57 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=evdR5ekL; dmarc=pass (policy=quarantine) header.from=redhat.com; spf=pass (imf10.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1746193318; a=rsa-sha256; cv=none; b=WyOUplSWF5qKzqWI2tExYKJTt/dL3kfSNinFRgYoyaPXfsQX+UTmLZOs/ycRPRj9oZFYCJ GDjUfrAq57L8R0aMpK57C7MmlB0QHzWwmtoAZJHjkmqcta6nAwtQfsg34Zm8Tle8xDbHXq L3DKc35no2UIqAS+rHdgCO0RyxafeR0= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=evdR5ekL; dmarc=pass (policy=quarantine) header.from=redhat.com; spf=pass (imf10.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1746193318; 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=5ynGlkRsk+Imh41/5x5BheKOozxWwcZOycP4AjDpPpk=; b=7tJtMrurJjdW+JqdYQE4rT/G2lb9gXlK+3HxOGQBd/TTAlktoqLbxcqTTIG++sS0BcOH3U tilk8txFcX+/8xJBTyUXRaNc5mzyJ9lvZ0fCwhOizEWz3OPDs1fSDlzvpPQHqy3LtDSdQe pJdNPQER6q32fLEyudI78dO8agtF0ZM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1746193317; 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=5ynGlkRsk+Imh41/5x5BheKOozxWwcZOycP4AjDpPpk=; b=evdR5ekLguaZw7++JMrvCN3V0arzhCI5SmFIbnKbTf1DevNqKAGc9RI98Pzj2TBGAovbE4 Rmz9TskoiwE+bV0o7Xv634Tp0HpLMdAg4K9EMgZGc9FkZLHwR8nE8lFebaJOW+CuUFYVMu g3ikhW8g3A/REixktjENei+w2d0/+UY= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-441-_WnTn2J_OhyhN6lXR5WLZA-1; Fri, 02 May 2025 09:41:53 -0400 X-MC-Unique: _WnTn2J_OhyhN6lXR5WLZA-1 X-Mimecast-MFC-AGG-ID: _WnTn2J_OhyhN6lXR5WLZA_1746193311 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 338F61801A14; Fri, 2 May 2025 13:41:51 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.188]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B6778180045B; Fri, 2 May 2025 13:41:47 +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: <0aa1b4a2-47b2-40a4-ae14-ce2dd457a1f7@lunn.ch> References: <0aa1b4a2-47b2-40a4-ae14-ce2dd457a1f7@lunn.ch> <1015189.1746187621@warthog.procyon.org.uk> To: Andrew Lunn Cc: dhowells@redhat.com, David Hildenbrand , John Hubbard , "David S. Miller" , Jakub Kicinski , willy@infradead.org, netdev@vger.kernel.org, linux-mm@kvack.org Subject: MSG_ZEROCOPY and the O_DIRECT vs fork() race MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1021351.1746193306.1@warthog.procyon.org.uk> Date: Fri, 02 May 2025 14:41:46 +0100 Message-ID: <1021352.1746193306@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 0597EC000D X-Stat-Signature: rkdxft8g4f578duhk3bir4k4mn6tget1 X-Rspam-User: X-HE-Tag: 1746193317-736105 X-HE-Meta: U2FsdGVkX19hFLm5EsBMeicxtoR55oEAd0/uuppkeFzCRRefuxJtjsiDDFwKB2PmMdQfuG+uWz/5SbzoOPcS6snticB/5LlDJ9PuTBysoQIFfGnjFycE/L0qSVNn4Fe3qoGv96FqD6jhsXvsYVS/tN5FKHLd6ribe+RdjSD0A1eMnBArfIeqESbJpMGcEuf3J8YPkk5F3cQEpD3p2bsaYut5mRrEa5P7VGRr1AT6SRoT5w5HsNtQ7EbYoWcflKp69AKz3oYElVTaTwVg1vF1n7O57oXMi65cfEvRVhaogtkqm1uOi5Ymdej0Re8FWnXVddmyzRZNq0vIzUjGmLVi5UOh075hz9HCOC8OqS05wpDNpiEkith13D5TmYd0BH27MolkjYC2CD9jmTIkJ4+ykWigfBeZD1otOK9XHfpSRXBAy6tcNheja+unuAhZhJqdWXdqDM6lOI95Lh3AiKfyALTqVA2Q208MYdwmWTenNhPcpiLbQgmomccPSppe9Wmm3UzxPnn6/Bbx+OZlZA8QxVzWjQI56U7Yu4GBxz+XrbSRgO0vuajPhT+qU/r8QV204HGdB55nCBfR/f4UZuTVHnpbo9Qm92pPeQjurtVBDFlsvr2WcX2YEToSShdcy+fBYY045gPk9Dluy30dovUhMMDR3vADHEb9g+uhKBqbC2jHIf7KgtlakM7HYoS93ncUTW0j1LdoM36u4ftmnLQwiTY8R03cX5mJBA5dcaMKqriSDPL49gPeig2FW9vOg3yT5Y9DhuwCYxm70+lfmFvFArrSmyxxfpTDtslDsi+i1jx8YOzL0hyfJgKZBLwRbDz6CISHQw5URcfI/7pTdSanZbNoP2OkbVji9fTfLT/uqIRuNotHRpzMZKCqKXAda59l4PeslSUdHfjLsjcUytMuuOcRXxq18JpLzUaNEO9hG4+uovI2jsPt/HK65gp8sdiwIiHxnxUoHq+Rrz+lofF 6vL8267I jbVXSSai8AMFMUwR6c2ocPiw9S+9AVAyBiHUSMTBOKSluHp+Khc9qwFw3LJ4ne9PvjWSfqg4oCjXd4+ZBIbfPWsh4WasXSWDAdZpWrUto9x3flxR6OzLFucm4kczla2RY5mdKhsElPmqXc++PJdfOh9fh70SmVychu98oByy4E2oUFtd7qFWYGhsRJOwiYYiNHk305E0NF6PeVTYKTL2A0rROVUgQlcyhmEruTRcfU46K/KCXfzTLb6ZbS/vW8Y/JfDYlYKRji1bJyer2+Xc12UuKIHbYmIIRAlPuCT35A/mplMx8EU6t2G9fT/1ntaoHXdbJTC033+5GBt0MrjAhUB42E5nReiaUULXD0/t6Xuvqy8Q= 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: List-Subscribe: List-Unsubscribe: Andrew Lunn wrote: > > I'm looking into making the sendmsg() code properly handle the 'DIO vs > > fork' issue (where pages need pinning rather than refs taken) and also > > getting rid of the taking of refs entirely as the page refcount is going > > to go away in the relatively near future. > > Sorry, new to this conversation, and i don't know what you mean by DIO > vs fork. As I understand it, there's a race between O_DIRECT I/O and fork whereby if you, say, start a DIO read operation on a page and then fork, the target page gets attached to child and a copy made for the parent (because the refcount is elevated by the I/O) - and so only the child sees the result. This is made more interesting by such as AIO where the parent gets the completion notification, but not the data. Further, a DIO write is then alterable by the child if the DMA has not yet happened. One of the things mm/gup.c does is to work around this issue... However, I don't think that MSG_ZEROCOPY handles this - and so zerocopy sendmsg is, I think, subject to the same race. > Could you point me at a discussion. I don't know of one, offhand, apart from in the logs for mm/gup.c. I've added a couple more mm guys and the mm list to the cc: field. The information in the description of fc1d8e7cca2daa18d2fe56b94874848adf89d7f5 may be relevant. David