From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.197 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796001838; b=xd9Es+r0rq3Q4rkKuOZ6QeHbSLNbPv7jl1Q+DlGJEouCbU7IBGpHUAQ5U1sBrOeWFNgQ QjMhwYqhDzKOZK+93TRkh6Qs0Q7K9uqe/ihW1qmT8CFNsKNFeAOP9AyWwBGpdvQn7mWiB 351ib8h+w70zUZ0zuA/I+9MTEuAZEsaPJorlUlBtaAi0pTgrsrxVvLCEot7JZHD9C/FW1 VPLvd79rabD3wjqVcWE3pV3t4fCbspTdZBDlg37+GvZcbdK4W/0/qPONiI+qEpNamCjmP Lo7k/tP4JgrDp79pkc4EzIFRUXf12fj47SQf+46h7MNv9rGAieRUQRluUQjBXE707pQ== 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=zeuo0LJs+2hnSDR/oJXwM3oRG01vt9hE/ozXM4r3hGlEDk+2KDzBluhiFny+JYm3JZw3 j7pZOf37JdDNeYj4CXAB0Cs2s/n62yk3B6TE7qXt3LxQ9hG2hL97tS14RXcCelA6sPzGE kjLebjmQm625AuhC7T6TGg1slgw7aDBxAWg1XteK152da225as2r7D2IPz5ixSf3JOA7j 3vR4T68A5Idg2VUWNPH9va5/HIoOiJqzPBIXhvz6KclpyabsQCx0ZU6V52WfJCP1+mdn/ iPM2ttG4U5Te4X7E8zX551LX1PfuIZA65+FWDEi/v7ls67voEMO5/sPs+t0Rwj6QRKw== 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=OSuDPFiS; arc=none smtp.remote-ip=209.85.215.197 Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) (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 DD005606A333 for ; Mon, 30 Nov 2026 01:23:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DD005606A333 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=OSuDPFiS Received: by mail-pg1-f197.google.com with SMTP id 41be03b00d2f7-cd66551e02cso9052169a12.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=lists.linux.dev; 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=OSuDPFiSK6cnvExWUWsE6HC1EWlmmE1HbWytduD+/fmsl8qX3Cb5Lqr7vUSY4jxS/O 6UdPWXjZFVqQ7hjyEX3nE8tQVogpYhDZTsPJ7ZRbi1NXQ9nEFEEdTdOtyO1hAKG3lp1T m5PExDxTZ96c9ntWWL8xmEC/uQjJDxS3JArZw3o7CNGPdNVmSS7+1GGgKmy9iSo7bO1j ap5azTAdwHZYPXm1CEbmMfBs9oLfyvwFZ/d+8zMMHVzVfd8Mgj4c9jB7yy4Q3v5zA8X9 f5DuP4FIbXb7mh6yok11zkGrUBFrbXPn8pSkssS3M6ifYdFUotqMRe2FQSJGwox+IQYt +ajw== 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=G9e+94OL9FzcLBKOc4Kejes6VaLu3ua3YT7Ujp3vMzcT6I2i+yoD6U8wG4rq2krin+ 5CsgnuyzPAGWUlGFDzc+nvlQPPXQv2jbP58D0fMECYtuyClTMBK7EvFIgdE1eNUJEJVb eR5ghVvC5N8czAufL9xT1RgNu7J6M6so7v93Fulv9Pnr5kDj0tb6hYujHIhR0EHrb53R GxHe8zg2+zWdG9DjRjO8DT+fSbXlY15tpULuAMswxJAhPj2bvtGbIydq9cMCBqV/5pso xQkBDdf0TrBU7SfkMyve66oJpRdChf4lPRS3FVrlfL/uNuDBvppBIAGeayEzVs9CawAT by8A== X-Forwarded-Encrypted: i=1; AL+hErELhLXbKRemkKbJzxKdsBMcvvOT5Rf2gNr2tHo+uVHq0yfOHZwMPsM7y4ibS3TNgJauwZypzBd+IyxqGV9rpA==@lists.linux.dev X-Gm-Message-State: APuU4Z8TtnSxz1XkGub1YkBQ3qN6TR3EIKzaorek367fu9PjmDhlgnWe Jf+gFQaph+miIx96nCyXHMUu7+rOpVMOKv13nCvW893UKgSJuxxBYxcBuoOzJ+hwhZ5rZi1znVh +8LDZ2hYJuZF046czCTM6z68tLQ== 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: virtualization@lists.linux.dev 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