From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 7D2213043DC for ; Mon, 3 Aug 2026 01:48:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785721713; cv=none; b=Y9H7qcCOX3R/gmHOHfxTuIpXKTiVEhNH5Dr+625LlJRV8NlYr9vMCoki+TqlzIgJyk4mUEnvKWeTEF9IYOfQTxWgTdpXhH5kBrXPijjv+Qlx34tEdZ4zNxEqOShUVZGghOgF0NUb6RCwNOn3RDu5boTanQlQioaTQ4++tlkC7bY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785721713; c=relaxed/simple; bh=F5jjXvOUykyUu9zaFjniBFZS1TJ9Ywm2mqV/IlHg49A=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=aVuWWlxuOWyQkWRCJmtutKHHoWJALbi7AX2/kiJc+ZIpqziOgeVDQu3sljeFdHgDPV4iL/9V09pksK7B63gRj2ce7ow+fuYExGTUDL6/Q2IiduCJoNhlo0bcVvehx5Nwp8N8Sk0btyWjBkwbAuwefpf8NDlz0kVKypxewTrYI1k= 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=iBx2Ne9s; arc=none smtp.client-ip=209.85.214.179 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="iBx2Ne9s" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2cad8076b01so32013415ad.2 for ; Sun, 02 Aug 2026 18:48:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785721711; x=1786326511; 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:content-type; bh=0HsrDyLiG2SqFngrsM9H92PhXRSraWTBf1HxDTa+ur0=; b=iBx2Ne9swTp6Bma3PYPm/5tO6vrXYIn59TbHwbGyzYQNGxRsr0X6/H8Qujj6GbhXXX YRHFSSDFA56DZP85QmuUhxt/KZNoa7pSBVzZcE6hIlQM9I8EBQFekkO5Ix5Acac7kLG5 BBP4Q7EA0SB0et7lhPxPHFL8C/EgTANcSUBf+GkwjaLbxZZ9kReodvvBnYiQxt4yR1na lDPx2yVYjlCUnF8JOzaJcFCO64IeihLAT+X7gM3WsTcw7IHZJAODUjcnc00yqQcMhuPI EUucZMkl39oOPVbnKBye9MI0Ns7HnxA8rXwR3sjdpJOHADj5//524qyYPx8+t2RLLJ+J qsYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785721711; x=1786326511; 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:content-type; bh=0HsrDyLiG2SqFngrsM9H92PhXRSraWTBf1HxDTa+ur0=; b=pW8ig3wx890AuAiWe//x4MnSiBORMW//qZR8cyvvWxu8RDcELcQpUoluTUbDilHRiJ exjpjAge74zrzgbFQ7NPtSASWbOnMWUdTMjCycdP741Vgx3zcj9Z88tZ5VGuRQ8rgkme E3CxOSKCnS/Xq2uYGoqm0HOyQFcb8Mjt8t1KVF3GWRrf59VcidotOv4htwd9sEaevjGQ F5UQkpt2nGng7DK3a+Pd4qVUhG7m+MMNnoOK83T0Fke/nORx8wKCrWQzJ10uGPKP8ucR Y/Hg4OB/3n8N5CHCi7c8YCTFrtNdfO56K11u+hw4k+6v1OIyn1rSSfD7+5LDv5mmU3pd MXZw== X-Forwarded-Encrypted: i=1; AHgh+RoRW3nD6DEItn6SC/KXU9pcxTzXAYScIJu8qQH+HgOc6Zlv4gL9IyuCvLibJfjneydHxPMha874QxzzEO0=@vger.kernel.org X-Gm-Message-State: AOJu0YzUXTF5rSXWc0nbNYTNDL8ZbqVDNOx+3cyiDi4IDVaV3t/pz2WS llt43Gg1zgVBhKu5g0vIkRtCH5yHZS5bca58ixXU6d5ga/x+vxz0A+0E X-Gm-Gg: AR+sD11DMYLQdif0mD47LEckabRlV2vSrWp/szQWdyItrTNc0k4Ozn7xsIVNM5+uDTJ nn5/5V104lDqmyUyvg4wtbxkFpQ2gqu7fJvPUZ9gK5CCfYgv5bZhJaZvyEG2ZTpNCxoPIOfbrO5 I2Ur9QaHi5AFBOg8HQeRbYyj2G8xMeI7GCkbGj0jbjXN9HZcw1NJenXWfQeTn7tHkUO4G0wtWcX YhsQ8lbt/W4GIaVDcqa4H8ZtGfhxAMtP3kNVP1sA+V/d/e6ptNzCeTHrBFaKmFRolB4jxG0r5Vy kvcT7gxc5BIdSQ1i+OyCZ88eHBAZSvSfCdSRwomc/1drnHyPooAGGnWfpzh1vJ8MkNOrUuDRB6l qwYR1z+sHcfupFw2y6fqMOigtmwBmj2NAmvCXFAYsmr8DpZsqBskbQvCJofXPkMLDP7snIROE1s t2m8YKNehlcp4WXoYxFmvod/qjyn22Q3NTIm1HY7ihIL7qmlE2AIpwcp3D5bUtFLj00frc1hUx4 rwIkck/Zr1ByL7wGjQ0lMGJuDmlQtVn7yQsXJEjCuLEE5bnsQ== X-Received: by 2002:a17:903:1a4d:b0:2cc:df15:91de with SMTP id d9443c01a7336-2d0524a2b59mr81446775ad.42.1785721710586; Sun, 02 Aug 2026 18:48:30 -0700 (PDT) Received: from JUNVYYANG-MC1.tencent.com ([43.132.141.20]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2d04b0eb491sm30422855ad.42.2026.08.02.18.48.27 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 02 Aug 2026 18:48:30 -0700 (PDT) From: Jun Yang To: netdev@vger.kernel.org Cc: Jun Yang , stable@kernel.org, TencentOS Corvus AI , "Michael S. Tsirkin" , Jason Wang , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , kvm@vger.kernel.org, virtualization@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH] vhost: reset the vring metadata cache on vring reconfiguration Date: Mon, 3 Aug 2026 09:45:14 +0800 Message-ID: <20260803014823.68623-1-juny24602@gmail.com> X-Mailer: git-send-email 2.50.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Jun Yang vq->meta_iotlb[] caches the vhost_iotlb_map that backs each vring metadata region, and iotlb_access_ok() returns early on a cache hit, taking the hit as proof that the region has already been validated: if (vhost_vq_meta_fetch(vq, addr, len, type)) return true; The cache is reset on VHOST_IOTLB_UPDATE and VHOST_IOTLB_INVALIDATE, on device IOTLB (re)initialisation and on vq reset, but not when VHOST_SET_VRING_ADDR replaces vq->desc, vq->avail and vq->used, nor when VHOST_SET_VRING_NUM changes the region sizes. With a device IOTLB attached both ioctls are accepted while the vq is live, and neither validates the addresses at ioctl time: vq_access_ok() and vq_log_used_access_ok() return true early because the addresses are GIOVAs, deferring validation to prefetch time. Once the cache has been populated that deferred validation no longer runs -- vq_meta_prefetch() hits the stale entry and returns true -- and vhost_vq_meta_fetch() keeps translating through the old mapping as map->addr + addr - map->start for an address the mapping no longer covers. vhost_copy_to_user() and vhost_copy_from_user() consume the result with __copy_to_user() and __copy_from_user(), which do not check it either, so a subsequent used ring update or descriptor fetch accesses memory outside the region the IOTLB actually maps. Reset the metadata cache whenever the vring is reconfigured, so the new addresses are pushed back through iotlb_access_ok()'s slow path. Fixes: f88949138058 ("vhost: introduce O(1) vq metadata cache") Cc: stable@kernel.org Reported-by: TencentOS Corvus AI Signed-off-by: Jun Yang --- drivers/vhost/vhost.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 4c525b3e16ea..77c96993100b 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -2126,6 +2126,14 @@ static long vhost_vring_set_num_addr(struct vhost_dev *d, BUG(); } + /* + * The metadata cache holds the IOTLB mapping that backed the previous + * desc/avail/used addresses and vring size, both of which are being + * replaced here. iotlb_access_ok() takes a cache hit as proof that the + * region was validated, so the stale entries have to go. + */ + __vhost_vq_meta_reset(vq); + mutex_unlock(&vq->mutex); return r; -- 2.55.0