From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 98206606A329 for ; Fri, 6 Nov 2026 13:26:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=OA1uIkgi Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 05063112D5D; Fri, 6 Nov 2026 13:26:36 +0000 (UTC) Received: from mta1.migadu.com (out-68.mta1.migadu.com [95.215.58.68]) by gabe.freedesktop.org (Postfix) with ESMTPS id E0A52112D5D for ; Fri, 6 Nov 2026 13:26:28 +0000 (UTC) X-Envelope-To: dri-devel@lists.freedesktop.org DKIM-Signature: a=rsa-sha256; bh=lnwy3IIIUITEEW39wV2rv1u7rm4YP9o1MSolIsKb45g=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1793971587; v=1; x=1794576387; b=OA1uIkgiaN4r0zvj6ublIecrPHGtkbWtKtwihfI9ccqDDw3V/PMBcJXtCb8NOf/Gm5noaS+s zAWisHoPCBdLvbILRTYUrpJhYZdWE/BfjZJLxK/RDFzOflNHCAwXbQIdiYpg4xd4tdLzoUIymhQ YtX5sOf8qRUl+QFvN348h5E4= X-Envelope-To: dri-devel@lists.freedesktop.org Received: by smtp.migadu.com with ESMTPS id 42ebb214afb95bc7; Fri, 06 Nov 2026 13:20:17 +0000 X-Mizu-Trace-ID: 42ebb214afb95bc7 X-Migadu-Flow: FLOW_OUT From: Tao Cui To: akpm@linux-foundation.org, dgilbert@interlog.com, mkp@kernel.org, loberman@redhat.com, jmeneghi@redhat.com, kraxel@redhat.com, vivek.kasireddy@intel.com, mst@redhat.com, jasowangio@gmail.com, eperezma@redhat.com, stefanha@redhat.com, sgarzare@redhat.com, rostedt@goodmis.org, vdonnefort@google.com, mhiramat@kernel.org, jgg@ziepe.ca, kevin.tian@intel.com, axboe@kernel.dk Cc: linux-mm@kvack.org, James.Bottomley@HansenPartnership.com, sumit.semwal@linaro.org, christian.koenig@amd.com, phasta@kernel.org, joro@8bytes.org, will@kernel.org, linux-scsi@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, kvm@vger.kernel.org, virtualization@lists.linux.dev, linux-trace-kernel@vger.kernel.org, iommu@lists.linux.dev, io-uring@vger.kernel.org, linux-kernel@vger.kernel.org, bobbyeshleman@meta.com, mathieu.desnoyers@efficios.com, robin.murphy@arm.com, mason@kernel.org, aesteve@redhat.com, tjmercier@google.com, harry@kernel.org, vbabka@suse.cz, cui.tao@linux.dev, cuitao@kylinos.cn Subject: [PATCH 5/7] iommufd: account the hw_queue page array to memcg Date: Fri, 6 Nov 2026 21:18:27 +0800 Message-ID: <20261106131829.3228926-6-cui.tao@linux.dev> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261106131829.3228926-1-cui.tao@linux.dev> References: <20261106131829.3228926-1-cui.tao@linux.dev> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "dri-devel" X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 From: Tao Cui IOMMUFD_CMD_HW_QUEUE_ALLOC pins up to max_npages pages just to check that a user supplied queue region is physically contiguous, and the page array for that check is plain GFP_KERNEL. The size comes from cmd->length, a u64 that is only overflow checked, and the array is freed again as soon as the contiguity check fails, so the allocation can be repeated concurrently: a 1GB region costs about 2MB of uncharged memory per attempt. Every other iommufd allocation that scales with user input is already charged, and the pinned pages charge the mapper at map time. Charge this array like the rest. Signed-off-by: Tao Cui --- drivers/iommu/iommufd/viommu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/iommufd/viommu.c b/drivers/iommu/iommufd/viommu.c index f7951057a1e5..ab17e190da49 100644 --- a/drivers/iommu/iommufd/viommu.c +++ b/drivers/iommu/iommufd/viommu.c @@ -330,7 +330,8 @@ iommufd_hw_queue_alloc_phys(struct iommu_hw_queue_alloc *cmd, * Use kvcalloc() to avoid memory fragmentation for a large page array. * Set __GFP_NOWARN to avoid syzkaller blowups */ - pages = kvzalloc_objs(*pages, max_npages, GFP_KERNEL | __GFP_NOWARN); + pages = kvzalloc_objs(*pages, max_npages, + GFP_KERNEL | __GFP_NOWARN | __GFP_ACCOUNT); if (!pages) return ERR_PTR(-ENOMEM); -- 2.43.0