From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F3B96455612 for ; Thu, 1 Oct 2026 22:46:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.197 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790894808; cv=none; b=iQVqmKaNYxA10EYHK2c5ZBT9O3ln1mAhtdG2pDroBLO+kBekpM6TQm7zGWDoB7EJdYb7CXhbcYbzN6s2qjjpj41BKZHy5rv9lKcEy+Pwv2G98rZEwZfvAstZEUaTdnYvn9phWhHGalq4rIEwS/QaXUWH8bPJToe642/V3yw6yfc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790894808; c=relaxed/simple; bh=I4Eb0TQXvIje7w417a5e7xobqbWORtKJ3XI4af3ycUQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Q1f8T43MSmrV7t+J5ORLuPIZZ6DCl2XBkp1AtS26h7qCy8XT1sNtoVRzlR4G96aqgi4hTBFDDGFSBz1E1udAU/qx+0Yk+eawL/PL8dYipuK+rumwkt5y2W/lLahTsQNoodhAyBP3Q/HoWUv8SrthJoqR8qnhNM2fOiYrxnv73Y4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--praan.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=fEQyV4DG; arc=none smtp.client-ip=209.85.215.197 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--praan.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="fEQyV4DG" Received: by mail-pg1-f197.google.com with SMTP id 41be03b00d2f7-cc7d2ff0087so2244234a12.0 for ; Thu, 01 Oct 2026 15:46:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1790894806; x=1791499606; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=x0wc41/LqtlI4rj0/ni4k6LG5KAkWTAQw55eEd0Lzvs=; b=fEQyV4DGaWITeMh1P2XQ+dfEXTltnyx6bF0iOcvQCoLZGTCT5UZglhmE2SrRNZjoSi 14rOF4fiAcvAIiot5lN3nlLM09sF0DqqrSMh2dxVrShme1bqnjRuh7yA1LwbVVwX/TWs CsmBLlmnwXOFvF0raxZ+Flqh5Jpg4awOh/MTw+1ZwGovCprIq0RVXdLLAX68Kp5TZDOT /5Le/Z5xmfqiUf2ImwLOKSIl718Ge++oo/JD9wfhvZp1hpZld8GpVcywiPWKELhmCA9t 83Us6De6+yGoLEYUhHJ2rURY47Y8VLgVUY8DSsbh4VHLrMw+b/P/FO8kTVuKDUgco7MP KpHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790894806; x=1791499606; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=x0wc41/LqtlI4rj0/ni4k6LG5KAkWTAQw55eEd0Lzvs=; b=IAWCFIdSItPTIlYqjfHkRPiUZ8uLxBCcYwf3iU3i+VZzflPpRD/V7WDoBaUV8+qqSE oV3prvO2nuG+/VjyyRkAjOxkQEajO0PNEqJX0ClXLRcFnVdZ37HLqPnjF/ya/tLjYlth 60bXFAxOkrt8Xkrt1NBqbVDknEuc6TjUXjm1wRV0KghZi0wK5sltIAOwKvLDYRLV4bxE IFT8qUuUfgWMkxYoj2YSO2DwW971t1ZWYQroMHP4E7TBV8royOkzJrIT4xczXHbKHIfd DKFyK9XTOGRa5Wckp0IexD2XAZd1tdUa0tDtZhiMzKx12d0IyLk26HSlup0bP01fvU4U Cf3w== X-Forwarded-Encrypted: i=1; AKwUvByAMJRC0iBkBalX/MRr75bFaGKFT75d+COR+Q5eNnubojpgGihXLGGpWNZAw2zg5RbtY3GPB68CIQM=@vger.kernel.org X-Gm-Message-State: AFuF++l4mkWOpbf7GsoXHhHpGig8ipEzJQTygLUOQtVW1WUQAwjXi0k1 klR8+nEyKkphXHtT5pDLwrxAsOBBstbp8Zgb7wqPYYqBAm5k+BK7/7pA0Yr4Vl4enpgTxQYivyU DKg== X-Received: from pgbcs6.prod.google.com ([2002:a05:6a02:4186:b0:cc7:d1fb:4ccd]) (user=praan job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:6a10:b0:3de:8ee8:8306 with SMTP id adf61e73a8af0-3e0bcfdd8ecmr751775637.31.1790894806215; Thu, 01 Oct 2026 15:46:46 -0700 (PDT) Date: Thu, 1 Oct 2026 22:45:30 +0000 In-Reply-To: <20261001224531.765278-1-praan@google.com> Precedence: bulk X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20261001224531.765278-1-praan@google.com> X-Mailer: git-send-email 2.56.0.rc1.315.gc6ed9934b7-goog Message-ID: <20261001224531.765278-7-praan@google.com> Subject: [RFC PATCH 6/7] iommufd/selftest: Add observability test for iommu-nr-pages From: Pranjal Shrivastava To: Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Kevin Tian , Alex Williamson , David Matlack , Jonathan Corbet , Shuah Khan , Randy Dunlap Cc: Mostafa Saleh , Daniel Mentz , Samiullah Khawaja , iommu@lists.linux.dev, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, Logan Odell , Pranjal Shrivastava , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Add a test case to validate the iommu-nr-pages fdinfo metric. The test maps sparse IOVAs to force page table directory allocations, verifies that the metric increments accordingly, and asserts that the count remains stranded after unmapping, verifying the current behaviour required for future automated reclamation logic. Signed-off-by: Pranjal Shrivastava --- tools/testing/selftests/iommu/iommufd.c | 48 +++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c index d44b34b05757..f5f4ef01ea4f 100644 --- a/tools/testing/selftests/iommu/iommufd.c +++ b/tools/testing/selftests/iommu/iommufd.c @@ -3613,4 +3613,52 @@ TEST_F(iommufd_device_pasid, pasid_attach) test_cmd_mock_domain_replace(self->stdev_id, self->ioas_id); } +TEST_F(iommufd_ioas, iommufd_nr_pages) +{ + char path[256]; + char line[128]; + FILE *f; + long nr_pages_initial = -1; + long nr_pages_mapped = -1; + long nr_pages_final = -1; + + if (!self->stdev_id) + SKIP(return, "Needs a device attached for HWPT"); + + snprintf(path, sizeof(path), "/proc/self/fdinfo/%d", self->fd); + f = fopen(path, "r"); + ASSERT_NE(NULL, f); + while (fgets(line, sizeof(line), f)) { + if (sscanf(line, "iommu-nr-pages:\t%ld", &nr_pages_initial) == 1) + break; + } + fclose(f); + ASSERT_GE(nr_pages_initial, 0); + + /* Map a page at start and one far away */ + test_ioctl_ioas_map_fixed(buffer, PAGE_SIZE, self->base_iova); + test_ioctl_ioas_map_fixed(buffer, PAGE_SIZE, self->base_iova + (1UL << 30)); + + f = fopen(path, "r"); + ASSERT_NE(NULL, f); + while (fgets(line, sizeof(line), f)) { + if (sscanf(line, "iommu-nr-pages:\t%ld", &nr_pages_mapped) == 1) + break; + } + fclose(f); + ASSERT_GT(nr_pages_mapped, nr_pages_initial); + + test_ioctl_ioas_unmap(self->base_iova, PAGE_SIZE); + test_ioctl_ioas_unmap(self->base_iova + (1UL << 30), PAGE_SIZE); + + f = fopen(path, "r"); + ASSERT_NE(NULL, f); + while (fgets(line, sizeof(line), f)) { + if (sscanf(line, "iommu-nr-pages:\t%ld", &nr_pages_final) == 1) + break; + } + fclose(f); + ASSERT_EQ(nr_pages_final, nr_pages_mapped); +} + TEST_HARNESS_MAIN -- 2.56.0.rc1.315.gc6ed9934b7-goog