From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796385693; b=IK09KmQDxNfBuMyEYvtIRUWHtQlKocmjerxxoKW308dVWjjNgMQd+ErsQfrU7+4GZyUn e+AaUjMvXQkwBOmfCry8dT4Ez+NEfBfaV4mIP7H5aRJY0EZjA+cm+gnUz13N+lfi+nvDN f374Ofhakm47w4TftpxaztzMTj3BjetTSjXvRgD8WBMQa1JkuhG1LnZWoDCLh8I5qreq+ eGUYYHcFLSOa30jWqXtIN+qg3Mu4pouZahbGxAcFWBcAEm/cOSVboBC6/4uOPtTNkRE7x ZPyNUkp7aCCBq+Uq1TYZIRDDYgBfHP02wdA1UIgy/qX/2u6ZMBglaxxrHN1XyRrD1ng== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385693; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=Sx/CgX0FljWO8mnMlRdV9qzxTA2GzCeYyUWj6y+ShpU=; b=KfBu0rclJfmm+mxn6/6yfxxUGC9QOapOgImWlxSVZJRoi/cBCNGOadto18QLl/X1Rydy V05qGjoLEeeVnx9pXwBtPzbNIcUDF7UEyVwINrOqe0onNyQOo6TMjdsDCGfMER0Q5yW49 8VCdpC7GaXuKMjXT1KYsBqGrRpk0MBHOgD9bfgKaO/HToo+cr4jEgClad5Ln7kMFqsdWL 94O8vFJMgOLTteMwPYd39QTUmf8B1aeSWvz/LSRvN52ktPOO5agPFLCQYIRpC8KrpnqC8 sSjl4/txVg6onYFxL0aP1Os2XBviS/VwJG70iWOUA8D7NCR7hJAai7ldc2XWMkOcx7Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=gMYH9FY2; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F3F23606A335; Fri, 4 Dec 2026 12:01:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=gMYH9FY2 Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED6CE1F00897; Fri, 4 Dec 2026 12:01:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796385692; bh=Sx/CgX0FljWO8mnMlRdV9qzxTA2GzCeYyUWj6y+ShpU=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=gMYH9FY22ghJUrqrfTc7OveXd5r82x+9O0Dko8wWurMnv0Pvr23sXnP3Slh96V3c1 WESknNeEa4kvgt/tIdcjF3iIWNEbU1H9QNgj684FjTSWDow4YU7KhndY7I+SceoIcr PemVYi7YKHhD5jMnabdBZUeZkzZE1rVlMmL6wst95MEFFw31Mh0CqMzShb1f3NVvrA dtaIYc4XK6Rje8RthXl5BhaAJUW+GUjHfzXXbxKPnB/08s591LEGKEkuM/nzXQI30g 8dFFF9iWoZDxBByRKXRbgWaZyMky+ApMzZQNcUYycP+gB1L0TXwAc9RvuHoCoU4Lm7 l6mfJUNEgcBBg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v3] vhost: account the per-device kernel allocations to memcg Reply-To: sashiko-reviews@lists.linux.dev To: "Tao Cui" , "Michael S. Tsirkin" Cc: "Jason Wang" , =?utf-8?b?RXVnZW5pbyBQw6lyZXo=?= , "Stefan Hajnoczi" , "Stefano Garzarella" , "Bobby Eshleman" , "Mike Christie" , "Andrey Drobyshev" , virtualization@lists.linux.dev, kvm@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, cuitao@kylinos.cn In-Reply-To: <20261203120106.2607381-1-cui.tao@linux.dev> References: <20261203120106.2607381-1-cui.tao@linux.dev> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 12:01:31 +0000 X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] vhost/vdpa: __GFP_ACCOUNT in vhost_vdpa_probe() charges wrong memcg - [Low] vhost/scsi: persistent per-vq cmd->tvc_log pool buffer left unaccounted -- commit 96c8a4875392fddf28877578e29b8895152689ec Author: Tao Cui vhost: account the per-device kernel allocations to memcg This commit adds __GFP_ACCOUNT / GFP_KERNEL_ACCOUNT to per-device allocations across vhost core and the net, scsi, vdpa, and vsock backends so resident kernel memory is charged to the owning memcg. > diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c > index e44044449cef8..d70472a87eae4 100644 > --- a/drivers/vhost/scsi.c > +++ b/drivers/vhost/scsi.c > @@ -2000,18 +2000,19 @@ static int vhost_scsi_setup_vq_cmds(struct vhost_= virtqueue *vq, int max_cmds) > if (svq->scsi_cmds) > return 0; > =20 > - if (sbitmap_init_node(&svq->scsi_tags, max_cmds, -1, GFP_KERNEL, > + if (sbitmap_init_node(&svq->scsi_tags, max_cmds, -1, GFP_KERNEL_ACCOUNT, > NUMA_NO_NODE, false, true)) > return -ENOMEM; > svq->max_cmds =3D max_cmds; > =20 > - svq->scsi_cmds =3D kzalloc_objs(*tv_cmd, max_cmds); > + svq->scsi_cmds =3D kzalloc_objs(*tv_cmd, max_cmds, GFP_KERNEL_ACCOUNT); > if (!svq->scsi_cmds) { > sbitmap_free(&svq->scsi_tags); > return -ENOMEM; > } > =20 > - svq->upages =3D kzalloc_objs(struct page *, VHOST_SCSI_PREALLOC_UPAGES); > + svq->upages =3D kzalloc_objs(struct page *, VHOST_SCSI_PREALLOC_UPAGES, > + GFP_KERNEL_ACCOUNT); > if (!svq->upages) > goto out; > =20 > @@ -2020,7 +2021,8 @@ static int vhost_scsi_setup_vq_cmds(struct vhost_vi= rtqueue *vq, int max_cmds) > =20 > if (vs->inline_sg_cnt) { > tv_cmd->sgl =3D kzalloc_objs(struct scatterlist, > - vs->inline_sg_cnt); > + vs->inline_sg_cnt, > + GFP_KERNEL_ACCOUNT); > if (!tv_cmd->sgl) { > pr_err("Unable to allocate tv_cmd->sgl\n"); > goto out; > @@ -2030,7 +2032,8 @@ static int vhost_scsi_setup_vq_cmds(struct vhost_vi= rtqueue *vq, int max_cmds) > if (vhost_has_feature(vq, VIRTIO_SCSI_F_T10_PI) && > vs->inline_sg_cnt) { > tv_cmd->prot_sgl =3D kzalloc_objs(struct scatterlist, > - vs->inline_sg_cnt); > + vs->inline_sg_cnt, > + GFP_KERNEL_ACCOUNT); > if (!tv_cmd->prot_sgl) { > pr_err("Unable to allocate tv_cmd->prot_sgl\n"); > goto out; [Severity: Low] Should cmd->tvc_log in vhost_scsi_copy_cmd_log() also use GFP_KERNEL_ACCOUNT? drivers/vhost/scsi.c:vhost_scsi_copy_cmd_log() { if (!cmd->tvc_log) cmd->tvc_log =3D kmalloc_objs(*cmd->tvc_log, vq->dev->iov_limit); ... } Although allocated lazily on the first logged command, cmd->tvc_log is preserved across commands in vhost_scsi_get_cmd() alongside cmd->sgl and cmd->prot_sgl, and freed with the per-vq pool in vhost_scsi_destroy_vq_cmds(). Without accounting, enabling VHOST_F_LOG_ALL lets a container hold 16 KiB per command slot (2 MiB for a 128-entry virtqueue) outside its memcg limit. [ ... ] > diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c > index c729efd108d07..9a5bd454fe7b5 100644 > --- a/drivers/vhost/vdpa.c > +++ b/drivers/vhost/vdpa.c [ ... ] > @@ -1689,7 +1689,8 @@ static int vhost_vdpa_probe(struct vdpa_device *vdp= a) > (vdpa->ngroups > 1 || vdpa->nas > 1)) > return -EOPNOTSUPP; > =20 > - v =3D kzalloc_obj(*v, GFP_KERNEL | __GFP_RETRY_MAYFAIL); > + v =3D kzalloc_obj(*v, GFP_KERNEL | __GFP_RETRY_MAYFAIL | > + __GFP_ACCOUNT); > if (!v) > return -ENOMEM; > =20 > @@ -1711,7 +1712,8 @@ static int vhost_vdpa_probe(struct vdpa_device *vdp= a) > v->dev.release =3D vhost_vdpa_release_dev; > v->dev.parent =3D &vdpa->dev; > v->dev.devt =3D MKDEV(MAJOR(vhost_vdpa_major), minor); > - v->vqs =3D kmalloc_objs(struct vhost_virtqueue, v->nvqs); > + v->vqs =3D kmalloc_objs(struct vhost_virtqueue, v->nvqs, > + GFP_KERNEL_ACCOUNT); > if (!v->vqs) { > r =3D -ENOMEM; > goto err; [Severity: Medium] Won't accounting v and v->vqs in vhost_vdpa_probe() charge the wrong memcg? Unlike the other vhost backends that allocate device state on open(), vhost_vdpa_probe() runs on bus probe and frees v and v->vqs only in vhost_vdpa_release_dev() when the device is removed. When a device is created from a non-root provisioning cgroup via vdpa_nl_cmd_dev_add_set_doit(), v and v->vqs (~19 KiB per virtqueue) are charged to that probing cgroup for the device's lifetime, pinning a dying memcg if it exits and risking spurious -ENOMEM on probe. Conversely, when probed in the root cgroup, containers opening /dev/vhost-vdpa-N are never charged for them. Keeping probe-time allocations unaccounted, or moving v->vqs allocation to vhost_vdpa_open() and vhost_vdpa_cleanup(), would avoid this. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203120106.2607= 381-1-cui.tao@linux.dev?part=3D1