Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp85588lqm; Tue, 30 Apr 2024 13:41:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUR0ocF/eVMUspbw6jLx5DwhEVH2WK+8CA/2Ka7Lb1GpDDvLNJFULjEPCtJYt3GoDvT7m41lZcwuhBWGNH2a4wWjCjnNf0XzvZ4t8MovQ== X-Google-Smtp-Source: AGHT+IG4aUlbyvfG9pLsJPqr0xVx6akWR+D89MHUngiKRhLX0A0Mgo2bF+cpKUuGWXNjKpRyP6GZ X-Received: by 2002:a05:6870:910c:b0:233:f233:c3ee with SMTP id o12-20020a056870910c00b00233f233c3eemr645097oae.50.1714509670918; Tue, 30 Apr 2024 13:41:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714509670; cv=pass; d=google.com; s=arc-20160816; b=sIGb09thabHT3OnR1ZnLO+5yqMg49FkR2cCrPXb4zCpRE5LtleNbV8W5+6eTxJ57fx gO/p1//MvjwZKdxe+pot0d8eOZnXJE6JXktgixNBH/vyMNK+M52STaHjLImYAsFBmKiG 5BEEGjgvCR4ybkyQHCdO/wpxYAJ23m0w9JLkY6BWalWXhfRJ+9TMCzYi73edwsOx4R/C C2q+CdAlh808OuvikgH0FVx4lNJfs5r1t7lMBDVew0o0m10Cv0+fbWBWjpAB5nvMMgAw 7IAM6BvlrGHg5IygN8fRrsf005D3IG+AQBBwe0oXLdtUCqEJ7dW4THSM9ZPoanBz3RSE Fnkg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=NgrzgAgGo8i+xwDb/b3m3FxSOTPzpaahtRRF4Q7L0yk=; fh=Fwb2oUXuDeDvZJGHn0wIaOPi60cuosViVSI+x3pjv5s=; b=GUJg4rKP3pyZdRT64emW7VTevFhg6uM0FaIywkFgWMxzyh1lhW3Po4gRRVuv1l21kB B/0CUogWH9jCfxjDZPwmc4Bo5rGE8enXzVX05k8qKUXbLcGRxPXlAMKq9VS79BT9Y+YU DGK+aLTzuzIzWSoFb1ZCyjq0BMJUzGl1ewDVqnG805voJI8R83qWFBJKaMwl5rGj2sOH MbVltZswFZfh/rzh0ReCAmSelO80MWC9whmab4hjYCe61zhS3o8Z+Myi8rC6b+jwGYvR LGeZosCq1/Fws7FdjjdYUCffzI5E09vyZzWM8hCZmFkcYNodjpKixTcNOPPDiNfG2zOQ Xi1w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QYgYGkiH; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-164717-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164717-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id bx26-20020a056a02051a00b005e49cd906d6si21161936pgb.97.2024.04.30.13.41.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 13:41:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-164717-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QYgYGkiH; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-164717-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164717-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 816BF284FFD for ; Tue, 30 Apr 2024 20:41:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 32188179B2; Tue, 30 Apr 2024 20:40:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="QYgYGkiH" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A47CB19DF5F for ; Tue, 30 Apr 2024 20:40:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714509654; cv=none; b=iCQF3lm+pAzpDxIieN0j4O298DGG2JnkNDk3HMO2yVOKKJsRuSGggob7IpfozywfVzOAUACV7yI0g8O8wxX7sDBueH1xgb60H+JmMc6nU0SwnzFf2M/nuEny4kbwszKezVjC7J/W5VmUsyUg9nUGM6WeSJs5WkNLKjHzxurZgpY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714509654; c=relaxed/simple; bh=w+6KTqRYqH4g82XjjMnM1W0nz4LoVWr/B/W1NuzYark=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=hZXnsw/rwojiRnMmPpmqa1l327M6kmiI9RDSV//+Jj9NucjfLtZFe9o3myLiQwDWshjN3WYWFX9eHfIUvEbQeuK0iYYTheDTp8BVvQ8jRJr9iWTWusHSWVoAj3LhcbTqINx/Ps6jkn1YZGS7LExrE7uWP2/JhnbSESh6AX4Khg8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=QYgYGkiH; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714509651; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=NgrzgAgGo8i+xwDb/b3m3FxSOTPzpaahtRRF4Q7L0yk=; b=QYgYGkiHsRiJixcdlZ7RqSNalxXWFLJzRDlam8RzcixD2Pen3gTp1EWGBSdC+FZKfzjMEd FIuGVzsKXd81z0HZ5hPcOu9ZdwJmeb+r3j+W1eX+k2xIeHnSus5atzIS/bAYNG8pdyh433 wAsF5Md7aQfEil88Ei9860HHzkNhFOk= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-446-Wx_lFYOlMO2wvDeYEn4muA-1; Tue, 30 Apr 2024 16:40:47 -0400 X-MC-Unique: Wx_lFYOlMO2wvDeYEn4muA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6E3E8380673C; Tue, 30 Apr 2024 20:40:47 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.192.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id AA563C01595; Tue, 30 Apr 2024 20:40:45 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , Vincent Donnefort , Dan Williams Subject: [PATCH v1 0/2] mm/memory: cleanly support zeropage in vm_insert_page*(), vm_map_pages*() and vmf_insert_mixed() Date: Tue, 30 Apr 2024 22:40:42 +0200 Message-ID: <20240430204044.52755-1-david@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 There is interest in mapping zeropages via vm_insert_pages() [1] into MAP_SHARED mappings. For now, we only get zeropages in MAP_SHARED mappings via vmf_insert_mixed() from FSDAX code, and I think it's a bit shaky in some cases because we refcount the zeropage when mapping it but not necessarily always when unmapping it ... and we should actually never refcount it. It's all a bit tricky, especially how zeropages in MAP_SHARED mappings interact with GUP (FOLL_LONGTERM), mprotect(), write-faults and s390x forbidding the shared zeropage (rewrite on its way upstream [2]). This series tries to take the careful approach of only allowing the zeropage where it is likely safe to use (which should cover the existing FSDAX use case and [1]), preventing that it could accidentially get mapped writable during a write fault, mprotect() etc, and preventing issues with FOLL_LONGTERM in the future with other users. Only very lightly tested ... because I yet have to even get fsdax running (I guess, file system on emulated DIMM in a VM? Hmmm :) ). [1] https://lkml.kernel.org/r/20240430111354.637356-1-vdonnefort@google.com [2] https://lkml.kernel.org/r/20240411161441.910170-1-david@redhat.com Cc: Andrew Morton Cc: Vincent Donnefort Cc: Dan Williams David Hildenbrand (2): mm/memory: cleanly support zeropage in vm_insert_page*(), vm_map_pages*() and vmf_insert_mixed() mm/rmap: sanity check that zeropages are not passed to RMAP include/linux/rmap.h | 3 ++ mm/memory.c | 92 ++++++++++++++++++++++++++++++++++---------- mm/mprotect.c | 2 + 3 files changed, 76 insertions(+), 21 deletions(-) -- 2.44.0