From nobody Tue Jun 16 18:02:54 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 77A953A8727 for ; Mon, 20 Apr 2026 13:20:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776691261; cv=none; b=TYHvv4AEi78+zngPX450PGM/K8d5W+V7BVd2Y5+bUEqCcJfo5vNKBpDHN4MZ6X2wcqAAonDkVvRo9J6iZQbJwqQXPxGIUxVJm5PkyUJc74O0LeltjbbCGdJ+shmNHInfX/6arWZJqeiEtys6BmshTYf60hWfY3KcolFaC1ZQJfc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776691261; c=relaxed/simple; bh=oRz4R1uy7BvYcGv9q3SW450IGK8oQQE9HdAqw2IRtxk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=iD43nWfzImMaFbBd+Ku1H1xoelozQWVItBHV606D/bDl3wi/VUgh19+MrSCCV/EoIcmKbAHnCxWiqXjHZwHu7ujgMvM8NSUa2Ige3/AuQIFbveuyfBSoxWAeYa8FNy7Pv4Vl9h5LtjWWczszStwr6wH5OAoXwnTWCemAU18sRXQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=XY6/zVO9; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=fF4+aoQ9; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="XY6/zVO9"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="fF4+aoQ9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776691258; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=ZNw8VU2wHUCMW8yOpvKsEhvAEIS86OBEtLoYfE3AKWY=; b=XY6/zVO9HQb6IhjAWwRrK1wocom4m4QRTATqpSzKFJN8Zacxin60+pr+hgmgftbf2jtcQu uvmS23Th/qe3K9aKdxQRdu+iIZB5BwQ1Jerdv7d9floS0qsgQVYWvor6WIy9jJP0bk4IT4 wcjjuxjNnLDRXS52iymtsVufAaAbwgg= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-398-xOmXYO9nPjmMu-pciXI9mg-1; Mon, 20 Apr 2026 09:20:57 -0400 X-MC-Unique: xOmXYO9nPjmMu-pciXI9mg-1 X-Mimecast-MFC-AGG-ID: xOmXYO9nPjmMu-pciXI9mg_1776691256 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-43d7d0947aeso2291589f8f.3 for ; Mon, 20 Apr 2026 06:20:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1776691256; x=1777296056; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=ZNw8VU2wHUCMW8yOpvKsEhvAEIS86OBEtLoYfE3AKWY=; b=fF4+aoQ9ORE+8pfPTrY9kG7rar5FYNikC4i9K7e0v9tPpt2C5FwkWfyCfPEEpAy/pv CnqLM1jYEgwYtHevuEjNDYqSqAodtWChyk5m61n7ozsaDQHwZ+kDnFi7Ef8eJ8sgYdGg z8M+U5LvhAsDLB7uPTBuwO+t1vLECvG33ptkZ0XDMXvIOEug+vGqCRf75K2pDkJQUHnZ Fizh2cBJkn4MB/iuOw9ZZXvWmKYZzrknCW81lUBhtDusJTfH5bvvQCvincWxjPpmCJwp FfjxKXmroSm1EPN9FnI4BOBNRlmKkX9PemriunFoGlTJ7F7LTHhQ5Z4aD+WeImQehbPa d4Sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776691256; x=1777296056; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ZNw8VU2wHUCMW8yOpvKsEhvAEIS86OBEtLoYfE3AKWY=; b=V0/UePfqmebVvGsHE2q0tDcon19b+ljQ7L+oMn9H+4MdFzpFlhktvlMnlkpq+tg+WK QKPV0T4HwTEAzxuBNBImx4HN8tjt+bC2UVeUjdXjAhxXOkuVor7/xlRqQ91DLaA7v3/d GdVkq3D3cHCqc3q3XOqUBJpmVm7ClxKXX94+BPxdqtotLnFuHEDAzOcFXTp52qVvFsHq Pd03oOqVL8c7hXdSzdAKDVtfAgrrsv5qTx3095Cp2tYxu6TaHRTO2JoMVj5Hoei7D0Ns 8iZNiyz3sZUjf+1MTsvTuzJ1sMdZP3PU7wFz52VhIOAV5E+VWQOJPUxBO/12EgiPnBhY +wkA== X-Forwarded-Encrypted: i=1; AFNElJ/r+xYmVcuAmoR+urivY9j9H+69pGvXDKk1327He/MU0VG6H9Xc/3mv/UsSR1zgdbOX7jT/NN8Yw+n6KkQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxTPanukivPkgfSRbInw2InkOvX7egbtcyFN7OgAC67DGpqCwHJ arNnAmTr0LmKL2SsRq+XE7NMFhJX7aLQjjao/1he4tG0ZUJ9eth/V7UYUAxYUC7Dj5+rMlwjS39 +RPLaj4j3zR699dYqExjWwbACZaIVm7ke95NkS1KtEy+p9epx/umdMT+DwcG3/jEUrw== X-Gm-Gg: AeBDiev3/X/hxMAIyAE+wBGGJD+qkUtECrqP1GDEjvyp8qfBQVMApquHC4NsxaPZ5kw WHyxQwiWKDSvu6oEjZmQolVGukmxPBaiXsf56JK2RbdKK7NO6ix2U8gXT0p/GJjP/9KOqHrRphM Osg/PoPWzv36vBYbHbLL4DCnD2WlZAD1qpYll4up2lduvTda7bSmACwKJkdU3ESIMv3d9DSBkad /1E4knh2815DcbG6AM1GYT0IpD1yAMykS1SSaXmNgpBz7UlyBiLXfPSCyXSc0VgwGXgCz7ME94X IuvZOfEF3VOP6p0cXSbOmPoY8Ci27FUvOcfmw7+JR5arCQ8B85scsLKzb4Lk2uJHDRbwfJaJ/4k Wv/8QuYlv7JH4ra5yd6pAUIkZ/6Mqc5tsda97LApwIQV7YfhKBIOHJmXtvj2cKVxFdgv+haf2ku w5Tjrwk9rj X-Received: by 2002:a5d:5e01:0:b0:43d:c95c:5e75 with SMTP id ffacd0b85a97d-43fe3dbec67mr19818827f8f.4.1776691255868; Mon, 20 Apr 2026 06:20:55 -0700 (PDT) X-Received: by 2002:a5d:5e01:0:b0:43d:c95c:5e75 with SMTP id ffacd0b85a97d-43fe3dbec67mr19818744f8f.4.1776691255247; Mon, 20 Apr 2026 06:20:55 -0700 (PDT) Received: from stex1.redhat.corp (host-87-16-204-83.retail.telecomitalia.it. [87.16.204.83]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43fe4cb1405sm28294807f8f.4.2026.04.20.06.20.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Apr 2026 06:20:53 -0700 (PDT) From: Stefano Garzarella To: netdev@vger.kernel.org Cc: Eric Dumazet , Simon Horman , Stefano Garzarella , kvm@vger.kernel.org, Arseniy Krasnov , "David S. Miller" , Paolo Abeni , Jakub Kicinski , "Michael S. Tsirkin" , Jason Wang , virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Xuan Zhuo , Stefan Hajnoczi , Yiming Qian Subject: [PATCH net] vsock/virtio: fix MSG_ZEROCOPY pinned-pages accounting Date: Mon, 20 Apr 2026 15:20:51 +0200 Message-ID: <20260420132051.217589-1-sgarzare@redhat.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Stefano Garzarella virtio_transport_init_zcopy_skb() uses iter->count as the size argument for msg_zerocopy_realloc(), which in turn passes it to mm_account_pinned_pages() for RLIMIT_MEMLOCK accounting. However, this function is called after virtio_transport_fill_skb() has already consumed the iterator via __zerocopy_sg_from_iter(), so on the last skb, iter->count will be 0, skipping the RLIMIT_MEMLOCK enforcement. Pass pkt_len (the total bytes being sent) as an explicit parameter to virtio_transport_init_zcopy_skb() instead of reading the already-consumed iter->count. This matches TCP and UDP, which both call msg_zerocopy_realloc() with the original message size. Fixes: 581512a6dc93 ("vsock/virtio: MSG_ZEROCOPY flag support") Reported-by: Yiming Qian Signed-off-by: Stefano Garzarella Reviewed-by: Bobby Eshleman --- net/vmw_vsock/virtio_transport_common.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio= _transport_common.c index 0742091beae7..416d533f493d 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -73,6 +73,7 @@ static bool virtio_transport_can_zcopy(const struct virti= o_transport *t_ops, static int virtio_transport_init_zcopy_skb(struct vsock_sock *vsk, struct sk_buff *skb, struct msghdr *msg, + size_t pkt_len, bool zerocopy) { struct ubuf_info *uarg; @@ -81,12 +82,10 @@ static int virtio_transport_init_zcopy_skb(struct vsock= _sock *vsk, uarg =3D msg->msg_ubuf; net_zcopy_get(uarg); } else { - struct iov_iter *iter =3D &msg->msg_iter; struct ubuf_info_msgzc *uarg_zc; =20 uarg =3D msg_zerocopy_realloc(sk_vsock(vsk), - iter->count, - NULL, false); + pkt_len, NULL, false); if (!uarg) return -1; =20 @@ -398,11 +397,17 @@ static int virtio_transport_send_pkt_info(struct vsoc= k_sock *vsk, * each iteration. If this is last skb for this buffer * and MSG_ZEROCOPY mode is in use - we must allocate * completion for the current syscall. + * + * Pass pkt_len because msg iter is already consumed + * by virtio_transport_fill_skb(), so iter->count + * can not be used for RLIMIT_MEMLOCK pinned-pages + * accounting done by msg_zerocopy_realloc(). */ if (info->msg && info->msg->msg_flags & MSG_ZEROCOPY && skb_len =3D=3D rest_len && info->op =3D=3D VIRTIO_VSOCK_OP_RW) { if (virtio_transport_init_zcopy_skb(vsk, skb, info->msg, + pkt_len, can_zcopy)) { kfree_skb(skb); ret =3D -ENOMEM; --=20 2.53.0