From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 61AE630E0EE for ; Mon, 10 Aug 2026 13:41:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786369264; cv=none; b=m/EJXLVQxN1qLxGshJKruMRHn9+upxt5Wi1ZgTJSgGK5DpIfToErVGxUTTnsPIT/BTqsKtOl9FqH93JP2RM0v8zgZN78Fe8f/eXF7vCaG3A/Ou8N6BA22Jhf0TPcOUqY/ilre6rrxcB1/LIEv+wOkLDKTdQFTjypL0D2soMeWGs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786369264; c=relaxed/simple; bh=m53EkhQFEeVWYP+OkPDmqEJQ4fOSY+ZFOJarQope3ZQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RzhyDwe7G3EOlR9KjzygTpSIPK+ucqTGAwUxlIbfU5QE4FHvAl1CHQI5VPOnv6z5H8TPPrh2+SHU7+DfgodTY2LdpwXsoz1piAzPpQU/yA5NhYFZxGGHDdG6DVCdUBhyKMxfQQnqdF73D+vYiP/vo61T+q9GVUCXlCzUByHNYZQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hUUIcsdO; arc=none smtp.client-ip=209.85.210.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hUUIcsdO" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-84e0688b7e8so1532615b3a.1 for ; Mon, 10 Aug 2026 06:41:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786369263; x=1786974063; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=rWtRbZHwwJKxr9m3CvsahX+FmG6nPUQO4TaHyIPdRr8=; b=hUUIcsdO8n63I3MroaQ5IychCQiR9EfZj0Kq8Cyp3XKBszsMXOkvVVpAaHQSf2PX8Z ZpYuxJPvQDy2lnM2GeTTvHNXnEsHUjAWzHsuTg0xP6choYgZ3AwzexC1iXFk+GeU/GqY f9OqMM9AhvfgOnj2Ae/Ln8buaoIex2A5wVhZhDLohHInm7qMiRz7mYdyVq5IxjQBBDV5 fk9etYiJmRziMezg1T8GuS2oZDEfi8aRK6cP/wkk4LsnqN02e3yAQ1davXhTMjTDi3ue OmHZCzsFOCyrNZPWxSZ6IKB0+9CzkxlkfoT0PTSzWLtJ88qhFxEjv1pwJCzNXKKUHNFA w7/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786369263; x=1786974063; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=rWtRbZHwwJKxr9m3CvsahX+FmG6nPUQO4TaHyIPdRr8=; b=aOmuiKcGmXAEWXCHcAREK8gTnE2Ew0QFub74B82Kk00E8MIUxWsHdVchKcPlhZ0XCu wRHbTbReloGbxHVUQ9vDiDl/Do9tUBtuUBmQLcSgemmi4z6hAVCRJsHo7Nryl+0tEyMp H4uznUOy4AEP+PxhRET/jgWyE580Zy1DySq8D87wDqYaj2ZR06zAb2IxH2tcq8JicKKg koPcmBPiH7pEkkO4H7s+gamJdPZ3P99mton0iiO8qVa7GBmfRhAHCcxuXjN+af5p+oi/ b2vP7JoajGfeCXRaTsF+NTteCpG1aJbZAVJmFl9RZ8xBf20Pwvgpl4b3puI8Xf1jHjYz giog== X-Forwarded-Encrypted: i=1; AHgh+RqiAPIpTSHREvMYOUcRDhADXWJiOCnOqezo9H/XAm3mjCiIFWVKyLAmYjK/3DkBhaLr6DmjGeK+bZz9Wxw=@vger.kernel.org X-Gm-Message-State: AOJu0Yy25G6zt8VI6nd89jVB2YMTg39bJYbcnZblJEXpRihRttiJqZw7 8L+NSAnLfbV8cRCfK3ubEM2+SQLoZWcHOT25/eh/FmgI+FtIZLEv7CZh X-Gm-Gg: AR+sD13QZd507ud0udYnnt+ZlzdoPWOyjvTDXnj0Dc90Bt8jgH/N1Yy0aLglgaSTT2R eMWlZPidii4pThqAs8cX3DW8XwWm5QV7TZVCGwVxEooLK4NlPwMhmgddQBEUEGYBJPXmjJDrm/H jU6u1sdRqehaezpoADP0uJfBzEFGbVN42MJkVAV78h2m5B+H32p298eHSm5vbGHVAfCgrgX5O5I qDGpyP6IBVU/lep7ThBQcehrZ/8DCIshhIJH/aOBh1AUf4M9f6ME77fFmq+eBIyX0aM8OzLfmF5 2MF/pDpBfqQVbhwNkmfSHWQcMh8kuDxD4GcuMewXkdEDPCzxr2bZVWJMulBmlBCasUbxhzs1CtY f0hlhXnhomYVcqgGbatjeOizwdc4vdjPNdGPtXFzOyMDsZfVFWbOF99WEqgqoZJ6FZ3ho40fWGY pEk1BCjcT2k0WwrgCdC+h0XjpTnUGXUxMtwNyS6OSDRZ/fKSbtXxqsAaXLx/8= X-Received: by 2002:a05:6a00:4086:b0:847:b16b:46d9 with SMTP id d2e1a72fcca58-84f9c9983d1mr1774067b3a.34.1786369262252; Mon, 10 Aug 2026 06:41:02 -0700 (PDT) Received: from gmail.com ([123.118.75.63]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84f5a51f166sm4006236b3a.35.2026.08.10.06.40.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Aug 2026 06:41:01 -0700 (PDT) From: Jia Jia To: stefanha@redhat.com, sgarzare@redhat.com, mst@redhat.com, jasowangio@gmail.com Cc: eperezma@redhat.com, kvm@vger.kernel.org, virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/2] vhost/vsock: discard IOTLB when ACCESS_PLATFORM is cleared Date: Mon, 10 Aug 2026 21:40:17 +0800 Message-Id: <20260810134018.143973-2-physicalmtea@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260810134018.143973-1-physicalmtea@gmail.com> References: <20260810134018.143973-1-physicalmtea@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit vhost_vsock_set_features() leaves the device IOTLB attached when userspace clears VIRTIO_F_ACCESS_PLATFORM. Descriptors can therefore continue to use translations installed before the feature change, including HVAs made stale by a later memory table update. Detach the device IOTLB before acknowledging a feature mask without ACCESS_PLATFORM. Serialize each virtqueue handoff with its own mutex while clearing its IOTLB pointer, resetting its metadata cache, and updating its acknowledged features. Keep the old IOTLB alive until all virtqueues have dropped their references, then free it. Also drop queued IOTLB miss messages and wake readers now that the device no longer accepts IOTLB updates. Fixes: e13a6915a03f ("vhost/vsock: add IOTLB API support") Suggested-by: Michael S. Tsirkin Signed-off-by: Jia Jia --- drivers/vhost/vsock.c | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c index 9aaab6bb8061..7372c22691de 100644 --- a/drivers/vhost/vsock.c +++ b/drivers/vhost/vsock.c @@ -851,6 +851,30 @@ static int vhost_vsock_set_cid(struct vhost_vsock *vsock, u64 guest_cid) return 0; } +/* Caller must hold the device mutex. */ +static void vhost_vsock_clear_iotlb(struct vhost_vsock *vsock, u64 features) +{ + struct vhost_iotlb *iotlb; + struct vhost_virtqueue *vq; + int i; + + iotlb = vsock->dev.iotlb; + vsock->dev.iotlb = NULL; + + for (i = 0; i < ARRAY_SIZE(vsock->vqs); i++) { + mutex_lock(&vsock->vqs[i].mutex); + vq = &vsock->vqs[i]; + vq->iotlb = NULL; + memset(vq->meta_iotlb, 0, sizeof(vq->meta_iotlb)); + vq->acked_features = features; + mutex_unlock(&vsock->vqs[i].mutex); + } + + vhost_clear_msg(&vsock->dev); + vhost_iotlb_free(iotlb); + wake_up_interruptible_poll(&vsock->dev.wait, EPOLLIN | EPOLLRDNORM); +} + static int vhost_vsock_set_features(struct vhost_vsock *vsock, u64 features) { struct vhost_virtqueue *vq; @@ -872,11 +896,16 @@ static int vhost_vsock_set_features(struct vhost_vsock *vsock, u64 features) vsock->seqpacket_allow = features & (1ULL << VIRTIO_VSOCK_F_SEQPACKET); - for (i = 0; i < ARRAY_SIZE(vsock->vqs); i++) { - vq = &vsock->vqs[i]; - mutex_lock(&vq->mutex); - vq->acked_features = features; - mutex_unlock(&vq->mutex); + if (!(features & (1ULL << VIRTIO_F_ACCESS_PLATFORM)) && + vsock->dev.iotlb) { + vhost_vsock_clear_iotlb(vsock, features); + } else { + for (i = 0; i < ARRAY_SIZE(vsock->vqs); i++) { + vq = &vsock->vqs[i]; + mutex_lock(&vq->mutex); + vq->acked_features = features; + mutex_unlock(&vq->mutex); + } } mutex_unlock(&vsock->dev.mutex); return 0; -- 2.34.1