Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.70 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796001838; b=JIL3RKSbQnSn54TjyGAKRnN1nS4rA+JAicD5ydd7gzTS8XZujUlpL52nTX28gtYS0Cdz WgBAM2UdqzS5TpGDRNklf3gD7hFg1zAptBPq1Lh1GQjPjgwPq5ZWB5jSM6ZlzLA/hJ7LA LKXBFrDfbViqx/yg5YotK2WJr2j03+DJdCw9hl+mdjUyOFxSLsDXiXj2xc+U4DMiIuyqw T5YJKBcIvkbJW/ebNNQUR/S3re9Vv6Ek3JR74VszC/EOVONWsZZL8+jkBKcg/tsjRdWek mlu/E0vKvdi9mu7oUYCwB4K2I/XvkNLYupqoC0pq0tV/fXAuUxgXRGmhrbp2uiXgBTQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796001838; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:Mime-Version: X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=AI7OA3R/b+0ihzuydEAYO/16ywaFcZfLh4xvpwCrpVY=; b=VXWQH/b6vmzbSCZXI2/7OhlwYYtFJjMrkxFMFFPZN0UKoqozhUADG9kI8mwhjxmDaZEV WtXirgYLc+SA2GvfQ1j/+3gWbcWq/Szfc5UKeZyZWmP1WKVvM1JQnDDWe+Q7oNHJci7Zf /DUXQt82bw8lG8nIAxLYy0e9EqU2ybh/TmP6aqfrUPCToyrCroUgiiN5o6M+U8TfLrIF6 dQ9L8rbGqcP8g3M03DiHHi6O+WSm/Nkl8lAecVoWoA9oqN7hx/NOdZwZhKxomxyAzasnE VPaeK3dRqB0Sr42XkyAeLQQ0Mu8Gs3zyk0pIhNDo2tTMRJC21+11i9dU8Jc6BWuHQmw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--souravpanda.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=PAyTzcvs; arc=none smtp.remote-ip=209.85.216.70 Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6612F606A329 for ; Mon, 30 Nov 2026 01:23:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6612F606A329 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--souravpanda.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=PAyTzcvs Received: by mail-pj1-f70.google.com with SMTP id 98e67ed59e1d1-3b40e7f4fa2so12584061a91.2 for ; Sun, 29 Nov 2026 17:23:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796001837; x=1796606637; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=AI7OA3R/b+0ihzuydEAYO/16ywaFcZfLh4xvpwCrpVY=; b=PAyTzcvsA8B977RWwxeLCOd4VvYZTDVEeI23cKiKS8j7l3aakyQMxoA4v8P+RGTXfB qEu1k+Xav6koMtQcFbCh/9GJpWAwEasdU0Bn9vg/XDRP0n/xZ/+X5lI7VEbrHAjvuwUZ Ucm/a8jPaa+qhM++sAg8n8YtP0N5VckGnFEGIYUIPcMxgDp8BeZMHKxqcrdEvCZxgoL9 bhQnhGzlac4spgZyyzaCoMoFBSUcLmLHSk4M+rPSoEpYflKK0vLxvei5yz/8I1N00M5y SjGYvHjjrpBHcKctP969cVqCFVnkxBXzRv+LSjdP4K6x2p2+06lyal6+HOFK07n9JfMf SDyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796001837; x=1796606637; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=AI7OA3R/b+0ihzuydEAYO/16ywaFcZfLh4xvpwCrpVY=; b=llN+CC2omAZwrEktepPEIobaOh5q66T9cTNQyUPC7YP0UVO0QnNb+tJAIFSP5jYwdk Q6QTj7BEdPT/BkVmFCdG8pg256npGZP3oeWFBSysyMUApShFuHc5YPEA9KHl9rYTwI/o 9rfjrQMic80XmaC5fnSfjjwxg38oRSt9KQy9+v7Y0HyIWCjnXlmbOLSWenj2OuEsfQZV 484AIXQ9uBA8eocrRUyAWSA4kfISdo5pVkIAylbHuvw2zMuMRi+gM/aN8JPS90Qz4DBK rUV2/Nq3H28TaP6yT1Jl/7NxaGEduvNHnoOP0To6Vp84TqHT1KccMc42SxI3q9Sp+58D W/Ww== X-Forwarded-Encrypted: i=1; AL+hErHaCdOcpVUBsRGw6/xjHe0k3EuWfKO4hCZMjvk0xirr3kWDcGRl7GMJvYIbPPf3UkdX14+Uda/wEso=@vger.kernel.org X-Gm-Message-State: APuU4Z/9Ki9nvIV5A15jcA4G7/CKubH0ceXy4lQZGi9L8klmu2L3t3Sl TQIJiAYvDttDVfpwpVi39E9chebMGypciozaTPaeNnWdmeIjqFRWhECL2SIoTWwu6FSWwbIQKQ4 JmAnoEcA2CZtmz4OYpA0jYqhUtA== X-Received: from pjbkb13.prod.google.com ([2002:a17:90a:e7cd:b0:3b4:1351:6103]) (user=souravpanda job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3d90:b0:3ab:b39f:41b9 with SMTP id 98e67ed59e1d1-3b41cb42c13mr27929606a91.61.1796001836478; Sun, 29 Nov 2026 17:23:56 -0800 (PST) Date: Mon, 30 Nov 2026 01:23:49 +0000 X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 X-Mailer: git-send-email 2.56.1.839.g22a8290db9-goog Message-ID: <20261130012354.1894611-1-souravpanda@google.com> Subject: [RFC PATCH 0/5] virtio-pmem & device-dax: host-backed range discard via fallocate() / MADV_REMOVE From: Sourav Panda To: djbw@kernel.org, vishal.l.verma@intel.com, dave.jiang@intel.com, alison.schofield@intel.com, pankaj.gupta.linux@gmail.com, mst@redhat.com, jasowangio@gmail.com, eperezma@redhat.com, viro@zeniv.linux.org.uk, brauner@kernel.org Cc: iweiny@kernel.org, jack@suse.cz, xuanzhuo@linux.alibaba.com, shuah@kernel.org, david@kernel.org, souravpanda@google.com, nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org, virtualization@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Device-dax on top of virtio-pmem is a cheap way to give an application in a guest a large heap. With 1G alignment the guest spends about 4K of struct page per GiB instead of 16M, the mappings are PUD entries, and the guest physical layout never changes. What it cannot do is give memory back: fallocate() on /dev/daxX.Y fails with -ENODEV, so once the application has touched a page the host backs it until the device goes away. This series lets userspace punch holes in a device-dax instance, with fallocate(FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE) or madvise(MADV_REMOVE), and passes them to the host through a new virtio-pmem discard request. The host frees the backing, for example by punching a hole in the backing file, and the range reads back as zeroes. Guest userspace fallocate(PUNCH_HOLE) / madvise(MADV_REMOVE) | v vfs vfs_fallocate() [patch 3] | v device-dax dax_fallocate() [patch 4] | 1. block page faults on the device | 2. zap the align-sized mappings covering the range | 3. -EBUSY if any page is still referenced v libnvdimm nvdimm_discard() -> nd_region->discard() [patch 2] | v virtio-pmem VIRTIO_PMEM_REQ_TYPE_DISCARD {offset, len} [patch 2] =====|============================================================== v Host VMM punch a hole in the backing file The granularity of a discard is whatever the host can free, 2M for a hugetlbfs-backed region say, and has nothing to do with the size of the guest mappings. Device-dax only has mappings of dev_dax->align, so a discard zaps the entries that cover it and lets them fault back in at full size. Guest mappings are never split: guest mapping |<------------------ 1 GiB ----------------->| host backing | 2M | 2M | 2M | .. | 2M | 2M | .. | 2M | 2M | ^^ released to the host; zero-filled on next touch Patch 1 fixes an existing bug in the mmap() offset check. Patch 2 adds the virtio-pmem request and a ->discard() hook on the nd_region, patch 3 lets a character device implement ->fallocate(), patch 4 is the device-dax side and patch 5 a selftest. Things I would like opinions on: - The virtio side needs a spec change, which I will send separately. The request guarantees zeroes on the next read, which virtio-blk DISCARD does not, so "discard" may be the wrong name for it. - virtio-mem solves a related problem, but it resizes kernel-managed RAM at the host's request. Here the application owns the region and decides which ranges to release, without hot(un)plug and without giving up the 1G mappings. - On devices that can discard, page faults take a per-device percpu rwsem for read. Patch 4 has the numbers behind that choice. - Nothing wipes a device when its last user exits. A supervisor that hands a device to a new user is expected to punch out the whole range first. Sourav Panda (5): dax/device: validate mmap offset alignment against dev_dax->align virtio_pmem: add VIRTIO_PMEM_F_DISCARD and region discard hook vfs: allow fallocate() on character devices implementing ->fallocate() dax/device: add fallocate() discard support selftests/dax: add devdax_discard tests Documentation/ABI/testing/sysfs-bus-dax | 11 + drivers/dax/bus.c | 40 +++ drivers/dax/bus.h | 5 + drivers/dax/dax-private.h | 39 +++ drivers/dax/device.c | 211 +++++++++++++++- drivers/dax/pmem.c | 16 ++ drivers/nvdimm/nd.h | 3 + drivers/nvdimm/nd_virtio.c | 170 +++++++++++-- drivers/nvdimm/region_devs.c | 61 +++++ drivers/nvdimm/virtio_pmem.c | 44 ++++ drivers/nvdimm/virtio_pmem.h | 10 +- fs/open.c | 8 +- include/linux/libnvdimm.h | 20 ++ include/uapi/linux/virtio_pmem.h | 49 +++- tools/testing/selftests/dax/.gitignore | 2 + tools/testing/selftests/dax/Makefile | 3 +- tools/testing/selftests/dax/devdax_discard.c | 250 +++++++++++++++++++ 17 files changed, 905 insertions(+), 37 deletions(-) create mode 100644 tools/testing/selftests/dax/.gitignore create mode 100644 tools/testing/selftests/dax/devdax_discard.c base-commit: ebb7a8dc1e74c705daffe11c2faf38ec2628f838 -- 2.56.1.839.g22a8290db9-goog