From nobody Wed Nov 25 05:21:18 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.56 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793971167; b=5B8eTtvrYTu/QGhQs5iFVT8HhqZ4zZ5d79ZXziRyUjmbCiLdoGTBA8asMtjjJBQRduec c80d3Y77libVZ9PQabV/3e+OpPiqjBcai2BvI3kk+tYf2RFQQDVG2kt08gzrqw4m5Sn97 jHVqXvS2hZF6ImCSN8k7hd/GKhm0x1i1S1bsJQXAGH5pC+VhQa0kTH/fCYX1YeSUWtsux rsYpWQ9E7is+xsqYgc0VckdYLvv0sT8VEosXIAGPEQghqu3Qtfg8wKSXxtHITQ6w5AJso HgAyIRtspayIFiAoAChjW90en/U00sGGOhtAqzUH/6K0LYYrjfeLV1j41Ewldxb5hVg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793971167; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=OjxbtrTpVECakggq3aaOcAKtXEWGwtyTzHqRGiNRk7Q=; b=A6ddrXFy0/lvs/c+20E9OZkYkV3biC3qHdKmwWpHmVRJfJoNnANAPN+Wt2m2Ywd55mrl YpX/QMs28k2vZM0vvdson2V+I1228186e6eDQVx6GVKjcZKemEm22sr1VvRFFOLReprko PJNWKYnpLMtdznDKs8Xzb+X9NCbz0ua4Ie7uugksp/0UXsvOSusS3Qoqtj+VuaaSxb/nQ 5j4FSuawucMnP6Wrwuab8mLO2lKShWVvYyxlCgM1dVR/7jgUUcKlD3e8dPkfW69YFU4Xu K6pU+4+e6rYuidhhk4GYUIlhWXG9XtkhZyU7fvqwATn9uegW3eEjBfMOpGEzdAbVkKg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=jeFNHfv5; arc=none smtp.remote-ip=91.218.175.56 Received: from mta0.migadu.com (out-56.mta0.migadu.com [91.218.175.56]) (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 0AFF0606A32F for ; Fri, 6 Nov 2026 13:19:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0AFF0606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=jeFNHfv5 X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=KO2+Pw/HQKx0a4JyoCFPhhmUGDsn7IBoIsdjd3UIB1k=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1793971165; v=1; x=1794575965; b=jeFNHfv5f4zmg3psPVOfCRejiIcbH0mRSeUBXfYvbsOUUduFnoh4Xb/lFO75h7OZwr3xb52j hl5asAf3vpi1tP7ZCwkufcg0keAVYJ9DH3vunUx+P7OTGGe6hcvnkzOe8I6jXRUX5LbI2tCx1XU DqQcY5Z6CBplWlVJlLCwbnXY= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 99a7a9ba11e11fd9; Fri, 06 Nov 2026 13:19:24 +0000 X-Mizu-Trace-ID: 99a7a9ba11e11fd9 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 1/7] scsi: sg and st: account the command buffer memory to memcg Date: Fri, 6 Nov 2026 21:18:23 +0800 Message-ID: <20261106131829.3228926-2-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-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Tao Cui The sg data buffers are unaccounted: the per-fd reserved buffer, the scatter-gather page array, and the order-0..N pages behind it, plus the per-device tape buffer in st. All of it is user controllable. The reserved size is capped only by the device max_sectors, SG_MAX_QUEUE (16) commands can be in flight per fd, and the fd count is bounded by RLIMIT_NOFILE. Nothing is charged to the memcg of the process driving it. The September 2026 fixes in sg_build_indirect reshaped the element sizing and left the accounting alone. Mark these allocations __GFP_ACCOUNT so the driving process pays for the memory it induces. Signed-off-by: Tao Cui --- drivers/scsi/sg.c | 23 ++++++++++++++++++++--- drivers/scsi/st.c | 7 ++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index 6551f1284d44..9c1414479b21 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -911,6 +911,19 @@ static int put_compat_request_table(struct compat_sg_r= eq_info __user *o, } #endif =20 +/* + * The sg passthrough of the blktrace ioctls has the same exposure as the + * block device path: holding the node is the only requirement today, and + * a created trace outlives the fd. Must match the gate in + * blk_trace_ioctl(). + */ +static bool sg_is_blktrace_cmd(unsigned int cmd) +{ + return cmd =3D=3D BLKTRACESETUP || cmd =3D=3D BLKTRACESETUP2 || + cmd =3D=3D BLKTRACESTART || cmd =3D=3D BLKTRACESTOP || + cmd =3D=3D BLKTRACETEARDOWN; +} + static long sg_ioctl_common(struct file *filp, Sg_device *sdp, Sg_fd *sfp, unsigned int cmd_in, void __user *p) @@ -920,6 +933,9 @@ sg_ioctl_common(struct file *filp, Sg_device *sdp, Sg_f= d *sfp, Sg_request *srp; unsigned long iflags; =20 + if (sg_is_blktrace_cmd(cmd_in) && !capable(CAP_SYS_ADMIN)) + return -EPERM; + SCSI_LOG_TIMEOUT(3, sg_printk(KERN_INFO, sdp, "sg_ioctl: cmd=3D0x%x\n", (int) cmd_in)); read_only =3D (O_RDWR !=3D (filp->f_flags & O_ACCMODE)); @@ -1829,7 +1845,7 @@ static int sg_build_sgat(Sg_scatter_hold * schp, const Sg_fd * sfp, int tablesize) { int sg_bufflen =3D tablesize * sizeof(struct page *); - gfp_t gfp_flags =3D GFP_ATOMIC | __GFP_NOWARN; + gfp_t gfp_flags =3D GFP_ATOMIC | __GFP_NOWARN | __GFP_ACCOUNT; =20 schp->pages =3D kzalloc(sg_bufflen, gfp_flags); if (!schp->pages) @@ -1844,7 +1860,8 @@ sg_build_indirect(Sg_scatter_hold * schp, Sg_fd * sfp= , int buff_size) int ret_sz =3D 0, i, k, rem_sz, num, mx_sc_elems; int sg_tablesize =3D sfp->parentdp->sg_tablesize; int blk_size =3D buff_size, order; - gfp_t gfp_mask =3D GFP_ATOMIC | __GFP_COMP | __GFP_NOWARN | __GFP_ZERO; + gfp_t gfp_mask =3D GFP_ATOMIC | __GFP_COMP | __GFP_NOWARN | + __GFP_ACCOUNT | __GFP_ZERO; =20 if (blk_size < 0) return -EFAULT; @@ -2134,7 +2151,7 @@ sg_add_sfp(Sg_device * sdp) unsigned long iflags; int bufflen; =20 - sfp =3D kzalloc_obj(*sfp, GFP_ATOMIC | __GFP_NOWARN); + sfp =3D kzalloc_obj(*sfp, GFP_ATOMIC | __GFP_NOWARN | __GFP_ACCOUNT); if (!sfp) return ERR_PTR(-ENOMEM); =20 diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c index e9d41e3cc2dd..b92633ab2757 100644 --- a/drivers/scsi/st.c +++ b/drivers/scsi/st.c @@ -4074,7 +4074,7 @@ static struct st_buffer *new_tape_buffer(int max_sg) { struct st_buffer *tb; =20 - tb =3D kzalloc_obj(struct st_buffer); + tb =3D kzalloc_obj(struct st_buffer, GFP_KERNEL_ACCOUNT); if (!tb) { printk(KERN_NOTICE "st: Can't allocate new tape buffer.\n"); return NULL; @@ -4083,7 +4083,8 @@ static struct st_buffer *new_tape_buffer(int max_sg) tb->use_sg =3D max_sg; tb->buffer_size =3D 0; =20 - tb->reserved_pages =3D kzalloc_objs(struct page *, max_sg); + tb->reserved_pages =3D kzalloc_objs(struct page *, max_sg, + GFP_KERNEL_ACCOUNT); if (!tb->reserved_pages) { kfree(tb); return NULL; @@ -4109,7 +4110,7 @@ static int enlarge_buffer(struct st_buffer * STbuffer= , int new_size) =20 max_segs =3D STbuffer->use_sg; =20 - priority =3D GFP_KERNEL | __GFP_NOWARN; + priority =3D GFP_KERNEL | __GFP_NOWARN | __GFP_ACCOUNT; =20 if (STbuffer->cleared) priority |=3D __GFP_ZERO; --=20 2.43.0 From nobody Wed Nov 25 05:21:18 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.72 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793971181; b=KyzJKt7DdZP0b/nq0MRLPVfCAjDXr0Bcjr0SllNwZNz5sLl/OTFHrCRZAWA1Lkm0NfuD UcDtDAKzPuAVbHwro4W6eXN2uBYBDfnejPmgKE7aNqeDBWzkYSxe/RWfYFGOyASJbyXpq eMrUrZTsteeWwBwSAKFeBeeygXX7cjqVyU5JfqlWOP2fE3KATKBTjRnVZJ7YjwoJ3VyGN WwYkCCSP9ofiCxyybAX/mZ43XdQi27t6vEvFkXm8WrDrvMyfThgUg2rasO0pyN9vyYp6v wAm3pL/Z/UDsN/xJZ3DhaliC7m3a689fKtBs5xDaFxFLxkfVSlWULPwceYmRgPdP9bw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793971181; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=uHDTPFGM/AF1nyT/Yc6bbkTHW5yMlJbnq5ZETvmi2Vs=; b=L9eWpJijlNtI8wEJIaUYfFxQ/D4ZG0mKhiVqdqHIxDhQ19/hKU5B3GquDC2OKIMYQQH9 JEnFwKtV6a1cBKVnEi+j5wLnZiBgTRDtxvUgDSWzF33VUtWzKSOtMK8rnTXGQ5obYSfT+ N6fVpZaqLUBdLwPvfD3JKjpoxdUHuIFjLNwMmrhlsgPIxpqBnZYEOLLS9PmfCl8qxQyXM och6u3cx7V+nDXd69DUhmdit6elQmWM/CsDRM/F/2l2Qjn8ijJV5hkNjCfxS40qCT9V7d fxQ0d2HUgzi5XWJRUOKesJhdgFNVwIcZI7M93Ep1tkoSSyNVGe/2XeTJRsYNPI9dMrQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=e39dX1aD; arc=none smtp.remote-ip=91.218.175.72 Received: from mta0.migadu.com (out-72.mta0.migadu.com [91.218.175.72]) (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 7CC43606A330 for ; Fri, 6 Nov 2026 13:19:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7CC43606A330 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=e39dX1aD X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=55Gu1BuWJQRvJsCcgFgbtSGQhBxGx47gTgITgbn0eiI=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1793971178; v=1; x=1794575978; b=e39dX1aDFsU5NTPTFLe3+RT+3/gSUyvAl18yS049B+1+avfXR5NJDC/GkY5xOMwPLboBKIzd N/1dhMtcwKi5kzXqiwRZhxE3jiyRM5th46sYicPK4WAzdzE7WYf96hN+5fs28ZwivqYdNalGYQh JAlb8yu3ez3DJaz2LqvdS2LE= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 2231816b5623e6c8; Fri, 06 Nov 2026 13:19:38 +0000 X-Mizu-Trace-ID: 2231816b5623e6c8 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 2/7] dma-buf/udmabuf: account the page array metadata to memcg Date: Fri, 6 Nov 2026 21:18:24 +0800 Message-ID: <20261106131829.3228926-3-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-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Tao Cui udmabuf pins the pages of a memfd and hands them out as a dma-buf. The data pages keep the accounting of the memfd they were instantiated in, but the bookkeeping around them does not: the page pointer array and the pinned_folios array, both sized by the buffer page count, plus the transient folios array sized by the memfd folio count, are plain GFP_KERNEL. A 1GB buffer costs about 4MB of uncharged SUnreclaim memory, and size_limit_mb defaults to INT_MAX. Charge the three kvmalloc allocations so the creator pays for the metadata it induces. The system heap in the same subsystem already accounts its buffer allocation; the data pages here stay with the memfd. Signed-off-by: Tao Cui Reviewed-by: T.J. Mercier --- drivers/dma-buf/udmabuf.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c index df6dd0046242..40182c82df6b 100644 --- a/drivers/dma-buf/udmabuf.c +++ b/drivers/dma-buf/udmabuf.c @@ -190,11 +190,12 @@ static void unpin_all_folios(struct udmabuf *ubuf) =20 static __always_inline int init_udmabuf(struct udmabuf *ubuf, pgoff_t pgcn= t) { - ubuf->pages =3D kvmalloc_objs(*ubuf->pages, pgcnt); + ubuf->pages =3D kvmalloc_objs(*ubuf->pages, pgcnt, GFP_KERNEL_ACCOUNT); if (!ubuf->pages) return -ENOMEM; =20 - ubuf->pinned_folios =3D kvmalloc_objs(*ubuf->pinned_folios, pgcnt); + ubuf->pinned_folios =3D kvmalloc_objs(*ubuf->pinned_folios, pgcnt, + GFP_KERNEL_ACCOUNT); if (!ubuf->pinned_folios) return -ENOMEM; =20 @@ -387,7 +388,7 @@ static long udmabuf_create(struct miscdevice *device, if (ret) goto err; =20 - folios =3D kvmalloc_objs(*folios, max_nr_folios); + folios =3D kvmalloc_objs(*folios, max_nr_folios, GFP_KERNEL_ACCOUNT); if (!folios) { ret =3D -ENOMEM; goto err; --=20 2.43.0 From nobody Wed Nov 25 05:21:18 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.108 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793971195; b=NMe3u4jPnZBfpG5CZEV8d23nOc+dSjnDlXVru7uHHdhj5nB6i49SaaVCnFsw+R5z+u4z nA1lf/Vr/QKjg0O1b0wBKIRnn/Cb2lKCFyyJEHLYuNfJYFUYz1a/w1n/pjRhlCw2OFmbh v/3TPZHZ3CP/fmH22kffXD9oliYFXHvSksUqjD7J+FgX7a52vBaKS2pCZNzpLsJeJrkoz Qu2/A0tt4tVT9xMTwLQ1/Gd89u1mWC2GT+7g+5nqftk96IXQL6JB0tTUnEhSMd+0FJTjb +785PzvDv72tr6FZXU97CpBOft+BCdcQ1gB/dk1ucTvJY5M/0HM4IHmEwUP+tcvFCzg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793971195; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=CYfB1FwPouVvSzabiejXQPBqorI59dDF0aM5IPAqcsI=; b=EDgQ/0qO777hiZnMjixYAyvvYoSGovvnvY4C9lqpLj2pqqSFzTHN4WS/dD3iSkl8gpMn rbw/9u2dhn4gw5MoS3YWLTp4TQ6q3F86oz6ieiEfD1GrYj/vwD9pz3TkpViPpsw9CWcpr OH3laxgxlfTyCA1ZqYh0qB0OcYXNR0m46AKeS/rGBhsicYhHN/bCltXjaizhBAzIbKWsV L2GuTkvDlBV2gc6QtszlOv9mZewGMt2uscdM3Kj7FZyM/a2FILwUxjLB/QI4cPg9ExuXe 6ZO4LISSSSjGp2fJ7bpoiWrFjtgfXk+J3fYhu1q01Ukgp+JWZ0ZZDRE+LWJmiKDTeJw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=OBh2yzfS; arc=none smtp.remote-ip=95.215.58.108 Received: from mta1.migadu.com (out-108.mta1.migadu.com [95.215.58.108]) (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 8B737606A330 for ; Fri, 6 Nov 2026 13:19:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8B737606A330 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=OBh2yzfS X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=73QCibDvpuaBGtRTNbIkxL+btURCG2VkLUsjiT9bmAg=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1793971192; v=1; x=1794575992; b=OBh2yzfS4sOkxhGkT+JBPca55NoqbHEL9VIcAcbEj1J1rXgOoQHQgV3Mcnc02kQNXVO902W+ noDVT/X6o8QePW+IXif0wVhRtAIt7pCstFsBd5LRqmTL17bi9HehYz49UEdj6gHklLbJYcIOxCM FPVWpW0g4r5YYg1Ao8bNZ4dk= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id b2c073d8feb08521; Fri, 06 Nov 2026 13:19:52 +0000 X-Mizu-Trace-ID: b2c073d8feb08521 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 3/7] vhost: account the per-device kernel allocations to memcg Date: Fri, 6 Nov 2026 21:18:25 +0800 Message-ID: <20261106131829.3228926-4-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-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Tao Cui Everything except the worker struct is allocated with plain GFP_KERNEL: the per-vq iovec and log arrays at VHOST_SET_OWNER, the memory table at VHOST_SET_MEM_TABLE whose size follows the user supplied region count, the pending message nodes, and the vhost_net/vhost_vsock device structs with their fallback to vmalloc. The worker has been accounted since the vhost_task conversion. A container that can open /dev/vhost-net or /dev/vhost-vsock, which device plugins hand out with passthrough, holds roughly 150KB of resident kernel memory per device after SET_OWNER. Charge the rest the same way the worker already is. Signed-off-by: Tao Cui Acked-by: Michael S. Tsirkin --- drivers/vhost/net.c | 14 ++++++++------ drivers/vhost/vhost.c | 16 ++++++++++------ drivers/vhost/vsock.c | 5 +++-- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index 4570a4ffbab2..bab6597c696d 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -249,7 +249,7 @@ vhost_net_ubuf_alloc(struct vhost_virtqueue *vq, bool z= copy) /* No zero copy backend? Nothing to count. */ if (!zcopy) return NULL; - ubufs =3D kmalloc_obj(*ubufs); + ubufs =3D kmalloc_obj(*ubufs, GFP_KERNEL_ACCOUNT); if (!ubufs) return ERR_PTR(-ENOMEM); atomic_set(&ubufs->refcount, 1); @@ -302,7 +302,8 @@ static int vhost_net_set_ubuf_info(struct vhost_net *n) if (!zcopy) continue; n->vqs[i].ubuf_info =3D - kmalloc_objs(*n->vqs[i].ubuf_info, UIO_MAXIOV); + kmalloc_objs(*n->vqs[i].ubuf_info, UIO_MAXIOV, + GFP_KERNEL_ACCOUNT); if (!n->vqs[i].ubuf_info) goto err; } @@ -1344,17 +1345,18 @@ static int vhost_net_open(struct inode *inode, stru= ct file *f) struct xdp_buff *xdp; int i; =20 - n =3D kvmalloc_obj(*n, GFP_KERNEL | __GFP_RETRY_MAYFAIL); + n =3D kvmalloc_obj(*n, GFP_KERNEL | __GFP_RETRY_MAYFAIL | + __GFP_ACCOUNT); if (!n) return -ENOMEM; - vqs =3D kmalloc_objs(*vqs, VHOST_NET_VQ_MAX); + vqs =3D kmalloc_objs(*vqs, VHOST_NET_VQ_MAX, GFP_KERNEL_ACCOUNT); if (!vqs) { kvfree(n); return -ENOMEM; } =20 queue =3D kmalloc_array(VHOST_NET_BATCH, sizeof(void *), - GFP_KERNEL); + GFP_KERNEL_ACCOUNT); if (!queue) { kfree(vqs); kvfree(n); @@ -1362,7 +1364,7 @@ static int vhost_net_open(struct inode *inode, struct= file *f) } n->vqs[VHOST_NET_VQ_RX].rxq.queue =3D queue; =20 - xdp =3D kmalloc_objs(*xdp, VHOST_NET_BATCH); + xdp =3D kmalloc_objs(*xdp, VHOST_NET_BATCH, GFP_KERNEL_ACCOUNT); if (!xdp) { kfree(vqs); kvfree(n); diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index ea127af58ada..d1274106ad5d 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -526,11 +526,14 @@ static long vhost_dev_alloc_iovecs(struct vhost_dev *= dev) =20 for (i =3D 0; i < dev->nvqs; ++i) { vq =3D dev->vqs[i]; - vq->indirect =3D kmalloc_objs(*vq->indirect, UIO_MAXIOV); - vq->log =3D kmalloc_objs(*vq->log, dev->iov_limit); - vq->heads =3D kmalloc_objs(*vq->heads, dev->iov_limit); + vq->indirect =3D kmalloc_objs(*vq->indirect, UIO_MAXIOV, + GFP_KERNEL_ACCOUNT); + vq->log =3D kmalloc_objs(*vq->log, dev->iov_limit, + GFP_KERNEL_ACCOUNT); + vq->heads =3D kmalloc_objs(*vq->heads, dev->iov_limit, + GFP_KERNEL_ACCOUNT); vq->nheads =3D kmalloc_array(dev->iov_limit, sizeof(*vq->nheads), - GFP_KERNEL); + GFP_KERNEL_ACCOUNT); if (!vq->indirect || !vq->log || !vq->heads || !vq->nheads) goto err_nomem; } @@ -2053,7 +2056,8 @@ static long vhost_set_memory(struct vhost_dev *d, str= uct vhost_memory __user *m) return -E2BIG; if (max_iotlb_entries <=3D 0) return -EINVAL; - newmem =3D kvzalloc_flex(*newmem, regions, mem.nregions); + newmem =3D kvzalloc_flex(*newmem, regions, mem.nregions, + GFP_KERNEL_ACCOUNT); if (!newmem) return -ENOMEM; =20 @@ -3405,7 +3409,7 @@ EXPORT_SYMBOL_GPL(vhost_disable_notify); struct vhost_msg_node *vhost_new_msg(struct vhost_virtqueue *vq, int type) { /* Make sure all padding within the structure is initialized. */ - struct vhost_msg_node *node =3D kzalloc_obj(*node); + struct vhost_msg_node *node =3D kzalloc_obj(*node, GFP_KERNEL_ACCOUNT); if (!node) return NULL; =20 diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c index 0cb87971d749..600daeb05e7b 100644 --- a/drivers/vhost/vsock.c +++ b/drivers/vhost/vsock.c @@ -721,11 +721,12 @@ static int vhost_vsock_dev_open(struct inode *inode, = struct file *file) /* This struct is large and allocation could fail, fall back to vmalloc * if there is no other way. */ - vsock =3D kvmalloc_obj(*vsock, GFP_KERNEL | __GFP_RETRY_MAYFAIL); + vsock =3D kvmalloc_obj(*vsock, GFP_KERNEL | __GFP_RETRY_MAYFAIL | + __GFP_ACCOUNT); if (!vsock) return -ENOMEM; =20 - vqs =3D kmalloc_objs(*vqs, ARRAY_SIZE(vsock->vqs)); + vqs =3D kmalloc_objs(*vqs, ARRAY_SIZE(vsock->vqs), GFP_KERNEL_ACCOUNT); if (!vqs) { ret =3D -ENOMEM; goto out; --=20 2.43.0 From nobody Wed Nov 25 05:21:18 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.132 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793971206; b=Z8ZLRn6Yxg2P+5PdcM1KwcPzDqapzkVTTPZdx5SpcILD8vi0J05G86q8ZwdU5msPAdY+ B1w/v+9DcU4Kfc12e2nClo9Rrzt6ZBonOxoZJWhbsrScr1pobYn6H0aA4cJfi8QO2Df+W dRWbvAsBKn08TuqXxSW/Z9kh7XO8IPA1CIJDmopq5G+/4V3sZGcavxfrViLInPU2CFzCU rk1PN16bupzScz6aC89G0qDQYDFAm8KskoOK9GDyCMmEohtmkKiWvEr7jPkI+uWZ+UXC5 rtUQ5/ex5nc/Kryic1OAGkE6/2VeDHWAqXKPlVyUn3DmY315jkU/VG6oeUWioCICo/g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793971206; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=hTZCBIjpZOspCZhwg+BKx9PwD4UeGBiWTdjVtWLRfNE=; b=4RUMj2ryjZVa+N3cIrvC2SmVpcOVc0HEO3nquZN9DJoa5keZLeUvVOQ3x3t4lEzWWYfy ZKHxQN2sLsT6uRChx2oZNxOqCEjFDCVBMi8tjB7seYRd4GH6crMXrKaSYpw4sMUukg3Kh Iunv1x1vTSESkPSEOOxeobupyA0EUV2E9dWI+bTwG/M+2mD3p1FOZ/XjtmTaJzCLzbSc6 jogklCVV3R9pk+RwWzlGIVlc7S3Z2kwfLw7PqDFK0khZ1eucvD2cvbmNaV4e6CXziR2Fj Ge6nxllbbSHZZTedf3i+LHSPXW9O7sMC0Bnes+KBB0lsvE/k67vwmRssWLKSdHWz/Ig== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=ZsQM8du1; arc=none smtp.remote-ip=95.215.58.132 Received: from mta1.migadu.com (out-132.mta1.migadu.com [95.215.58.132]) (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 CFB91606D80E for ; Fri, 6 Nov 2026 13:20:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CFB91606D80E Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=ZsQM8du1 X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=SEovZ4ALBXSWOhtuKK3tlcth4LgwnYMDhPbgNF54x8Y=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1793971204; v=1; x=1794576004; b=ZsQM8du1un+p13NyVJ1yhVa398SB8wxdZLQ0JQyp1c6X5ODPLHnxJZqvtRCTrx1iU6llGtKE 7Xp3yGRC03VJqWi9CIvNXW4YucO+qekJmzhNVV2+KxCdstjLOrP+rqHxJ3s/GMjAgX4LRILhr7N SpABoT3u/6S3cKTo5soLK5RE= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 7dc7413b7e7a1b47; Fri, 06 Nov 2026 13:20:03 +0000 X-Mizu-Trace-ID: 7dc7413b7e7a1b47 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 4/7] tracing: account ring buffer pages and trace_array metadata to memcg Date: Fri, 6 Nov 2026 21:18:26 +0800 Message-ID: <20261106131829.3228926-5-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-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Tao Cui Creating an instance immediately allocates two full sets of per-cpu ring buffers, array buffer plus snapshot, about 1.375MB per cpu per set on the default config, plus the trace_array and its name. None of it is charged: neither trace.c nor ring_buffer.c passes __GFP_ACCOUNT, while user_events in the same directory accounts everything it allocates. Instance creation is currently gated by tracefs file permissions alone, so a rootful container with the host tracefs bound in can create instances until the host runs out of memory. Charge the ring buffer pages and the trace_array metadata to the creating cgroup. Signed-off-by: Tao Cui --- kernel/trace/ring_buffer.c | 8 +++++++- kernel/trace/trace.c | 6 +++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 1fd28a72e6ee..676c059c112c 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -441,7 +441,13 @@ static struct buffer_data_page *alloc_cpu_data(int cpu= , int order) * gracefully without invoking oom-killer and the system is not * destabilized. */ - mflags =3D GFP_KERNEL | __GFP_RETRY_MAYFAIL | __GFP_COMP | __GFP_ZERO; + /* + * The subbuffers are charged to the memcg of whoever caused the + * allocation: the creator of a trace instance, or root at boot for + * the global trace. + */ + mflags =3D GFP_KERNEL | __GFP_RETRY_MAYFAIL | __GFP_COMP | __GFP_ZERO | + __GFP_ACCOUNT; =20 page =3D alloc_pages_node(cpu_to_node(cpu), mflags, order); if (!page) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index e8c4efa8107b..04b60b9cc4f5 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -8693,11 +8693,11 @@ trace_array_create_systems(const char *name, const = char *systems, int ret; =20 ret =3D -ENOMEM; - tr =3D kzalloc_obj(*tr); + tr =3D kzalloc_obj(*tr, GFP_KERNEL_ACCOUNT); if (!tr) return ERR_PTR(ret); =20 - tr->name =3D kstrdup(name, GFP_KERNEL); + tr->name =3D kstrdup(name, GFP_KERNEL_ACCOUNT); if (!tr->name) goto out_free_tr; =20 @@ -8708,7 +8708,7 @@ trace_array_create_systems(const char *name, const ch= ar *systems, goto out_free_tr; =20 if (systems) { - tr->system_names =3D kstrdup_const(systems, GFP_KERNEL); + tr->system_names =3D kstrdup_const(systems, GFP_KERNEL_ACCOUNT); if (!tr->system_names) goto out_free_tr; } --=20 2.43.0 From nobody Wed Nov 25 05:21:18 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.162 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793971227; b=wOvPO7+VWkxcABHk1b0DSKzsEn6JBUqkwH101aUaJN4oQOOTvKlo2LDpX6oTp5f1wdtJ ha4+oaQUsQYRmrLF61iAbhF96bpOq2b/Zg/KRisNLsw64lIobiCJpy2QuVzUhoC7nesBU OlP8rTRheD0l4lxVDpvDENpx3zDH89aEeSq/+XeKY7FC9tZihbBcBcYHp8g2s664mKuYP C4X7oLuq0EKM8arXseLFF37tbLsEaiJDVLJO4CxvzvRMXwPBUK3OaHrpF/bc5HxlDP2pA FMJ8SedcbWYxgFHLxo6u0lCM7H6SeyzDPzRm40Svs912RccB1xZr6CEdRAQ1N/OffDg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793971227; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=q5STX0i0nZe9qBiCwKpYPE22fAldGg2mVbLAiRStB5A=; b=1bMRStHxfv2cVfA60SvDSkF+e19Zhyn7+NDk/r4r68XrOudtwnntYa7fLWC7crlFpfKx woG+dgEJkBGhxLd7md02kOmknlVuMO6BNk/5g6hr+Jc7Q+hM5nhnqXjHbiiW/1kafrxE/ 4H2yxBQFTNmzZAjlHqpC7lioRoRcwJ+9n82E+h1MoOljUZJcb9e3ccxZkMJt4q+6wqNV/ g4mLJSmf2k5TfDyT4hyxwl+1o6Rv/3W6bj1Wq6hY9eGh/S/s/oy5nPW2cLa6GAXLcGs5m k/i2cBWJRquVNCd7LRkbGdeH8HkEjlXmZTWNVGoWBrxD98HXIbT6aLvgVCB7dYE71XQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=tTWcvoJF; arc=none smtp.remote-ip=95.215.58.162 Received: from mta1.migadu.com (out-162.mta1.migadu.com [95.215.58.162]) (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 E0DD9606A32C for ; Fri, 6 Nov 2026 13:20:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E0DD9606A32C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=tTWcvoJF X-Envelope-To: linux-kernel@vger.kernel.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=1793971225; v=1; x=1794576025; b=tTWcvoJFhREnEQce4WCZ3iyBtwJ88lVb41kXcUU14zTdACClX1UBA8ST/5W8aC4OORpFSjok PY/QxaUVCsJk0mtuUJL2rIBltOH9TqnhodbbNfQQ2yywMsYC8BQceK2fsDaSr5fzvkr+B7tzBhe WHMLhXhd7qR6ADqpzdTXVBgg= X-Envelope-To: linux-kernel@vger.kernel.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-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Jason Gunthorpe --- 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 =3D kvzalloc_objs(*pages, max_npages, GFP_KERNEL | __GFP_NOWARN); + pages =3D kvzalloc_objs(*pages, max_npages, + GFP_KERNEL | __GFP_NOWARN | __GFP_ACCOUNT); if (!pages) return ERR_PTR(-ENOMEM); =20 --=20 2.43.0 From nobody Wed Nov 25 05:21:18 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.191 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793971246; b=mB3AQV5mZABV8lsfIVaYUnN99tpf6gG0Jc+r6n4EzrShoUwFWB0cIr11/HtSDSykPVV/ l4zSTapRIqNg+v8Bp5C9oInmCrNTQTYZVfmgubdHvZeA2xtp5/CqVRYyVulHIkL+tjTw6 zePWOCDpPz6vjiSpiA0ygl/O0JfSHC9os4MoeTjjm+W3af2Wws1MtJ/eVB2G+R26VeCin Yp+p8gEq7HdkAQV25u/le7Be/+AoTM0X38DSy6ClvfzNWluYto1TVcnbQO3HRE25dOQMn cp+XRGpJJ7q4WaDzqaJGiyrTT6/sjIkWH5lGTmuT1k/E2fY4drg10P9iNSHefafPxEg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793971246; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=fUXCYLhn52D7jjqtCGZ+7rWovE/XUiCSennV1JjWXTc=; b=LNs+J6O6Mepd/4LtUM5x0Cq/9Yb8/4zva77quApfRTm2HZmj7E5BlbI5CrPtsHz+GMV4 Sc4yPQrstrac/grzt8AnGz9T3Uwa5sJeEsmjfmeAdHNZtKQfebiD988nsDosKVy8vW8Z2 zKbSVHJ9qycObzoBs0ErPSkF7k4+QU3Ny0CAq9woAfsE5TFebJubQMsk0LmU62HguBdz0 0/jrdzfD8lCBrz3B+gxqUb517oILM3MDaa8gxNuhY8wKzfHkFC5NUZPJBEjaF4Kr8dxCb J9i1RkE6I2stWe57vsvUG7SKVAQCQ6TUyTVq9H2SegnJEqN6C9F6AbKKyeEYpz4GRKQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=AWU+oP3u; arc=none smtp.remote-ip=95.215.58.191 Received: from mta1.migadu.com (out-191.mta1.migadu.com [95.215.58.191]) (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 57A91606A331 for ; Fri, 6 Nov 2026 13:20:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 57A91606A331 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=AWU+oP3u X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=ojgBXCCljWWMx/by6O5nBZ1cYADUOJnAnHqRvmqKFno=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1793971243; v=1; x=1794576043; b=AWU+oP3uE+Bp9M4NHthTv7q7awqULRAk7AJ+yUdGd8HP3gv4OZ3L3y2iim+wbp8ZY+SmjP6f RQOZ8k1aHyjLLkndQT62PYK+Mb5tL6fxCe7tCZ6NDOnwdYBj1Z+KZlsMEmliGrhC5h4dkKcDQnt /zsj+KNoWYeiGHHuaHTmkkzg= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id fd2f547758ebbf7f; Fri, 06 Nov 2026 13:20:43 +0000 X-Mizu-Trace-ID: fd2f547758ebbf7f 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 6/7] io_uring: account the ring context and SQPOLL thread data to memcg Date: Fri, 6 Nov 2026 21:18:28 +0800 Message-ID: <20261106131829.3228926-7-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-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Tao Cui The io_ring_ctx and the SQPOLL io_sqd are the last per-ring allocations made with plain GFP_KERNEL. The larger surfaces around them are already charged: io_mapped_ubuf and io_rsrc_node since commit 075d5837bafc ("io_uring/rsrc: charge buffer arrays and nodes to memcg"), the tctx node and its XArrays since commit 0b34e7b20a48 ("io_uring: charge tctx nodes and personalities"). Charge the context and the SQPOLL thread data the same way. Signed-off-by: Tao Cui --- io_uring/io_uring.c | 2 +- io_uring/rsrc.c | 3 ++- io_uring/sqpoll.c | 2 +- io_uring/tctx.c | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 03724419c4e1..d39cdde49a9f 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -229,7 +229,7 @@ static __cold struct io_ring_ctx *io_ring_ctx_alloc(str= uct io_uring_params *p) int hash_bits; bool ret; =20 - ctx =3D kzalloc_obj(*ctx); + ctx =3D kzalloc_obj(*ctx, GFP_KERNEL_ACCOUNT); if (!ctx) return NULL; =20 diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c index e0345c3e764e..9a971c983686 100644 --- a/io_uring/rsrc.c +++ b/io_uring/rsrc.c @@ -825,7 +825,8 @@ static bool io_coalesce_buffer(struct page ***pages, in= t *nr_pages, unsigned i, j; =20 /* Store head pages only*/ - new_array =3D kvmalloc_objs(struct page *, nr_folios); + new_array =3D kvmalloc_objs(struct page *, nr_folios, + GFP_KERNEL_ACCOUNT); if (!new_array) return false; =20 diff --git a/io_uring/sqpoll.c b/io_uring/sqpoll.c index d387488db2de..b82d3a285337 100644 --- a/io_uring/sqpoll.c +++ b/io_uring/sqpoll.c @@ -172,7 +172,7 @@ static struct io_sq_data *io_get_sq_data(struct io_urin= g_params *p, return sqd; } =20 - sqd =3D kzalloc_obj(*sqd); + sqd =3D kzalloc_obj(*sqd, GFP_KERNEL_ACCOUNT); if (!sqd) return ERR_PTR(-ENOMEM); =20 diff --git a/io_uring/tctx.c b/io_uring/tctx.c index b4fecea3ea47..6673393100ec 100644 --- a/io_uring/tctx.c +++ b/io_uring/tctx.c @@ -23,7 +23,7 @@ static struct io_wq *io_init_wq_offload(struct io_ring_ct= x *ctx, mutex_lock(&ctx->uring_lock); hash =3D ctx->hash_map; if (!hash) { - hash =3D kzalloc_obj(*hash); + hash =3D kzalloc_obj(*hash, GFP_KERNEL_ACCOUNT); if (!hash) { mutex_unlock(&ctx->uring_lock); return ERR_PTR(-ENOMEM); @@ -85,7 +85,7 @@ __cold struct io_uring_task *io_uring_alloc_task_context(= struct task_struct *tas struct io_uring_task *tctx; int ret; =20 - tctx =3D kzalloc_obj(*tctx); + tctx =3D kzalloc_obj(*tctx, GFP_KERNEL_ACCOUNT); if (unlikely(!tctx)) return ERR_PTR(-ENOMEM); =20 --=20 2.43.0 From nobody Wed Nov 25 05:21:18 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.215 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793971258; b=u3O98675aXGZx8HZKfcy90sQ0CZPHXp3BRsVzmvxNmZpnzUWWQJbVQUSeJdleWty4Igg RAAjcs8tLZUWzzP4A95OIe//PtYLi4JS3yGHSQyCmHeva/Xq3iQ4fLOKkGU6Rp4zkm9NJ /7eRhwc/sOZC+OH8HuYBr6uJKlJxcANNOTKC+By/fISX1/QcJWse7FJj1aZSVuHucYucv 5htvDjMQ/HZDBhZSnzLdgBWl55Y9fy4c5nc3xKmV4TkEjIbGUPziowoVGkxyD/5zS3pPF LD7M96gChDqQQUZTE3w65lEY++6ragrZcYBMvXgMpNHgHTJQkntw1Vo2Yf65QfMXeSg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793971258; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=mBQnCmi6lRqH8GAi8YV/xcgTg4V0TO+wKEtX2yDXFxQ=; b=3QJvZ+5NA+rcBgfxczUw5MI0Tt7evRrM0EyBnWe2exOh3AR36Vzw8I9Y4uiJ6wqqGOV5 ziRNqNfY2RhVcbVirztNjUDSQW7waX3vcej78+j0rEFwsBLRqbFeOS0QgR8EPdxbGPWep XjW7SBXBslZs0LjMepv+dLbxQn/cD+424nYX0m5cxGJY6xi9rxICKrdWXeTCOlMfqNf7O CSe2idxQPD92jC5AzxLP2PWjbE+mxw0iIOrd5/YD39hzFJrg1q3w0K6DDi0Ij5iwvw6j4 +va8BhCfX67aM7pXJSIBF2xrNRUrmGhFm+ALMl6pdy+WUiyUi3x3IyMmLmwXhfK938A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=AeWGSHSw; arc=none smtp.remote-ip=95.215.58.215 Received: from mta1.migadu.com (out-215.mta1.migadu.com [95.215.58.215]) (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 111CB606A339 for ; Fri, 6 Nov 2026 13:20:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 111CB606A339 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=AeWGSHSw X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=dKQ/3LCCVbNcrSr0Tnyt8Yullo0Ku/Vkln3W2FNUdns=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1793971256; v=1; x=1794576056; b=AeWGSHSw5gCUCbueF62VSkT4cd4H1UWyOnuiftbsvsH889tMmC2ju0ZopLoCA7ztdQoWRGFj Ah9CMYssyGipSVl+fOz0aQ50JMH5mol+kXYjs90BTdwmZzGC1/1QzVy/MXrru2z9UISsupQEMQg oQNHTipoer+T01odkijK4tPs= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 178d9492481963cf; Fri, 06 Nov 2026 13:20:55 +0000 X-Mizu-Trace-ID: 178d9492481963cf 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 7/7] io_uring: account the remaining per-object allocations to memcg Date: Fri, 6 Nov 2026 21:18:29 +0800 Message-ID: <20261106131829.3228926-8-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-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Tao Cui A handful of io_uring allocations still scale with user controlled counts on plain GFP_KERNEL: the per-ring io-wq and its workers, the alloc cache entry arrays, the provided buffer peek and import iovec arrays, and the registered eventfd contexts. The tctx side is covered by commit 0b34e7b20a48 ("io_uring: charge tctx nodes and personalities"). Charge what is left. Signed-off-by: Tao Cui --- io_uring/alloc_cache.c | 3 ++- io_uring/eventfd.c | 2 +- io_uring/io-wq.c | 4 ++-- io_uring/kbuf.c | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/io_uring/alloc_cache.c b/io_uring/alloc_cache.c index 58423888b736..f41df1878633 100644 --- a/io_uring/alloc_cache.c +++ b/io_uring/alloc_cache.c @@ -22,7 +22,8 @@ bool io_alloc_cache_init(struct io_alloc_cache *cache, unsigned max_nr, unsigned int size, unsigned int init_bytes) { - cache->entries =3D kvmalloc_array(max_nr, sizeof(void *), GFP_KERNEL); + cache->entries =3D kvmalloc_array(max_nr, sizeof(void *), + GFP_KERNEL_ACCOUNT); if (!cache->entries) return true; =20 diff --git a/io_uring/eventfd.c b/io_uring/eventfd.c index 63fe6e5d79ba..52f5d5b85f30 100644 --- a/io_uring/eventfd.c +++ b/io_uring/eventfd.c @@ -132,7 +132,7 @@ int io_eventfd_register(struct io_ring_ctx *ctx, void _= _user *arg, if (copy_from_user(&fd, fds, sizeof(*fds))) return -EFAULT; =20 - ev_fd =3D kmalloc_obj(*ev_fd); + ev_fd =3D kmalloc_obj(*ev_fd, GFP_KERNEL_ACCOUNT); if (!ev_fd) return -ENOMEM; =20 diff --git a/io_uring/io-wq.c b/io_uring/io-wq.c index 92df54c6f50c..98f3aa378baf 100644 --- a/io_uring/io-wq.c +++ b/io_uring/io-wq.c @@ -981,7 +981,7 @@ static bool create_io_worker(struct io_wq *wq, struct i= o_wq_acct *acct) =20 __set_current_state(TASK_RUNNING); =20 - worker =3D kzalloc_obj(*worker); + worker =3D kzalloc_obj(*worker, GFP_KERNEL_ACCOUNT); if (!worker) { fail: atomic_dec(&acct->nr_running); @@ -1358,7 +1358,7 @@ struct io_wq *io_wq_create(unsigned bounded, struct i= o_wq_data *data) if (WARN_ON_ONCE(!bounded)) return ERR_PTR(-EINVAL); =20 - wq =3D kzalloc_obj(struct io_wq); + wq =3D kzalloc_obj(struct io_wq, GFP_KERNEL_ACCOUNT); if (!wq) return ERR_PTR(-ENOMEM); =20 diff --git a/io_uring/kbuf.c b/io_uring/kbuf.c index abf44f5dba26..bc6e552a91dd 100644 --- a/io_uring/kbuf.c +++ b/io_uring/kbuf.c @@ -288,7 +288,7 @@ static int io_ring_buffers_peek(struct io_kiocb *req, s= truct buf_sel_arg *arg, * a speculative peek operation. */ if (arg->mode & KBUF_MODE_EXPAND && nr_avail > nr_iovs && arg->max_len) { - iov =3D kmalloc_objs(struct iovec, nr_avail); + iov =3D kmalloc_objs(struct iovec, nr_avail, GFP_KERNEL_ACCOUNT); if (unlikely(!iov)) return -ENOMEM; arg->iovs =3D iov; --=20 2.43.0