From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 90AE2803BB for ; Tue, 10 Nov 2026 16:46:53 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AAGjYwv016413; Tue, 10 Nov 2026 19:45:38 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AAGjYwv016413 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=default; t=1794329140; bh=nCIKjBqwKcj+sAh6zCqzNWA0NODca3c1fioL91ePskY=; h=From:To:Date:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe; b=VdhZ3zUPLX4T50+Qbpm/LXKcqGsBszt1MK/ewUuVxrF7POHp2nmCYP+uYtB7f/MBt qk+6I8t2Sp/k1tv39P8FYT2hBH6YDOgH0B/xW3C7rL15Il8xcJxg87CRMsipQVvuWX ZXA8QK0QsQYbql0QWOeWnjZ4SIwFfmAe5YPvR7Xf9PSmI4vMeuEI4sST1kTG64v6CX SjZuKjzvUjiKMYN2ScsuS9iYMFwd+bbRMMGCtNyjZ6d2Ia6GNAd8wev2xMUDmQtR9k 2RSoSubdzgo2SzMucqXjis8UvhWmUS8mFXoChbjBa6ZJU64eBTw8itifzOs7ZwQNi8 8f0IC5ejLzbcQ== Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AAGjXF3016408 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Tue, 10 Nov 2026 19:45:33 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AAGjXF3016408 Authentication-Results: mail.openvz.org; dkim=pass (2048-bit key) header.d=openvz.org header.i=@openvz.org header.b="JuDn8ATC" Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-4925ef75fc4so1913898f8f.1 for ; Tue, 10 Nov 2026 08:45:33 -0800 (PST) X-Gm-Message-State: APuU4Z+dGIWkT2BL9QVOtyVYU7KQy4RcdvsZcO0XN841xhtM4IR841ZQ IhBgVgy/H60J1uoPMOZ2Hf+a76drk3I6gQN//HWHCmjpUjHBbw/XZCXvjIIGmqrEy2NQD1awq4p OIWoKrnI1yfa1FPKHnMfToy3xxP3/kkURrvOlYCxbEh1fQD9uP7dnrA== X-Gm-Gg: AYBFou2W7HDg90YLQeGcQA5cuHObaSeRxjHRZpg5l6ZpRSU0mmsU4crpEbSLMbU7ZK7 euHRa5tD/opcrmRaV7RzY9FJnfG9tJh1QUVMbDFVdhBjZKTgFk9ypuoC7F5E6baGfaZsUo8kOOX CBagD6ybnY3ZgjaNvUwDlFrlnbedzFtcb2o/5Vs1YV3BM4Glnfy2pAMhM6WXtDek+gO/Lwr+y4i KahTIAGYndP1Jstlxs93uc2EisJRx3HjGn4B4sfaMOlGdGCisUTHvKaDKCKjnNOka8tUmRLqep3 gA+9JN4IBg== X-Received: by 2002:a05:6000:144e:b0:48b:69d4:bb35 with SMTP id ffacd0b85a97d-4982e82c12amr6549203f8f.12.1794329132886; Tue, 10 Nov 2026 08:45:32 -0800 (PST) X-Received: by 2002:a05:6000:144e:b0:48b:69d4:bb35 with SMTP id ffacd0b85a97d-4982e82c12amr6549165f8f.12.1794329132508; Tue, 10 Nov 2026 08:45:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794329132; cv=none; d=google.com; s=arc-20260327; b=JLv9D2SdWeJyqp9HXd26VwpgsYjEq46U/x54UlWgPbvgfZHMGn5btBKM1gY+T0TsnL gdxM7+x/D2WELUifGbdPyA22Awdi2lKQ5a4Ewoejh05Gid5ooY/4cepFN4uv0eMNTRgH Bgll8ZpukHthI8lMok4bbgVmA+tixg5vfZQbs6LFXGh1oCLI9PIaAqCfniD2I2BOa6fl 8z9frPc6E2A2+jckOp+yrW9KiBs3Hi1GwxNZ22Pl8rQg50j198PBh+gDAx0jTx5DBBqN OCCvfrs5YowHG5FHyiEeYTEGPG6elh0R1GK4NawifeRjMNKYAqJTVp6wUkv+fOksUWnr hBzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=6ROdjRfHkAusV9U6bK8DmNKyBorOYQDr+oJH0rZibV8=; fh=ozrYJQ1t3QIP6s65KBq5xgJxiFM2qf+5wwn3ABTusyU=; b=Etn8gbsy3lc0finoeDnUj54SnQXCAbK34a3Hmmbm5sTWU87VErf+RShAz+rbIO9uO2 rA79qYHWWlbp1Be8oa09tQyTiyV9U9jOxG3Za9wS+rFTjM/oVGg7XvddXmRDqFMQSYVL D9PHnHFWGYspjVeBnNmBIYYepAJndNSSfMnE1p7C0Bknd3Je8E3vYKF8QniKibIDukTw rD2vC5XaXWixdtN6lDUDGpxbhxln/xgsD/XxUigAFE19GAzErqlQIOVw7HsGANRWCo6D LdmXia7SNSr3yDqzDHRRKCgeyjk8+dt7NxfrAHer0YG52Iz+AeOQNVh+ZfgdNSNjuNPG x7Xg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@openvz.org header.s=google header.b=JuDn8ATC; spf=softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:4f78:6441:d0f1:22af as permitted sender) smtp.mailfrom=den@openvz.org; dara=neutral header.i=@openvz.org Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id ffacd0b85a97d-498336a9fa7sor521031f8f.13.2026.11.10.08.45.32 for (Google Transport Security); Tue, 10 Nov 2026 08:45:32 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:4f78:6441:d0f1:22af as permitted sender) client-ip=2a06:5b06:b600:300:4f78:6441:d0f1:22af; Authentication-Results: mx.google.com; dkim=pass header.i=@openvz.org header.s=google header.b=JuDn8ATC; spf=softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:4f78:6441:d0f1:22af as permitted sender) smtp.mailfrom=den@openvz.org; dara=neutral header.i=@openvz.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1794329132; x=1794933932; darn=openvz.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=6ROdjRfHkAusV9U6bK8DmNKyBorOYQDr+oJH0rZibV8=; b=JuDn8ATCRmR+HJtccF0x5b28swon4SB9ywn+MhsfSgUt4UsiPaazgzz8+ohTEFkMI+ 9Hr9b7WRNbUNMnNpUXR3MDdkZl/hVOMlYubHg5omXmZ3yTXSiS7I1jig1EVtgD/dse/v ysSNlUqgcUndaeu1UvTLOr4+5q/fuTxAIJEbJKykH3SzQMFYCCHdyR4oH7DUVGBdt71F UV0R1cx+oFJNr7f4rfa5sUqqG3QlyBXr2l44Nn3lngkFYaNuJNK38heMZABu5uxhpAFe mSVuhKg8vFlPJJ+58I7ThVRDROFVfWaTwp5DjYvO78P+141k4cBOe/9br03EoXv4jGqR KMWA== X-Received: by 2002:a05:600c:468c:b0:4a6:b49f:9ae5 with SMTP id 5b1f17b1804b1-4ba0235b9b0mr56333725e9.34.1794329131874; Tue, 10 Nov 2026 08:45:31 -0800 (PST) Received: from athena.sw.ru ([2a06:5b06:b600:300:4f78:6441:d0f1:22af]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4ba0234a5dcsm76309345e9.2.2026.11.10.08.45.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2026 08:45:31 -0800 (PST) From: "Denis V. Lunev" To: khorenko@virtuozzo.com Date: Tue, 10 Nov 2026 17:45:29 +0100 Message-ID: <20261110164529.2794752-1-den@openvz.org> X-Mailer: git-send-email 2.53.0 MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1] iommu/amd/pgtbl: fix DMA faults on IOVAs mapped while the table grows X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org From: Denis V. Lunev increase_address_space() publishes the new root and mode and only then points the DTEs at the new root. alloc_pte() reads pgtable->mode without the domain lock, so a mapper on another CPU that sees the new mode installs its PTEs under the new root and hands the IOVA to the device while the IOMMU still walks the old table: nvme 0000:63:00.0: AMD-Vi: Event logged [IO_PAGE_FAULT domain=0x0004 address=0xfffffffffff40000 flags=0x0030] The v1 table starts with 3 levels and grows to 6 on the first IOVA dma-iommu takes from the top of the 64-bit space, once the 32-bit space runs out. That happens under heavy DMA load, so many CPUs map into the window at once. A faulting device read of memory fails the command with Data Transfer Error. A faulting device write to memory is posted and gets dropped silently: an NVMe READ completes successfully and the buffer keeps whatever it held before. Update the DTEs inside the seqcount write section. alloc_pte() and fetch_pte() spin in read_seqcount_begin() until it ends, so nothing is mapped under the new root before the devices use it. Mainline is not affected since commit 789a5913b29c ("iommu/amd: Use the generic iommu page table"): increase_top() calls change_top() before it publishes the new top. https://virtuozzo.atlassian.net/browse/VSTOR-154276 Fixes: 6eedb59c18a3 ("iommu/amd: Remove amd_iommu_domain_get_pgtable") Feature: fix ms/iommu Signed-off-by: Denis V. Lunev --- Reproduced on epyc06 (Supermicro H12DSU-iN, EPYC 7352, four Optane in one IOMMU group): an out-of-tree module eats the group's 32-bit IOVA space through a root port while fio reads the drives, and a kprobe delays amd_iommu_update_and_flush_device_table() to hold the window open. Stock 6.12.0-211.52.1.22.9.vz10 faults on every try, and fio verify sees reads return stale buffers with no I/O error. With this patch: no faults, no verify mismatches, and the first 64-bit IOVA is mapped only after the last DTE flush. drivers/iommu/amd/io_pgtable.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/amd/io_pgtable.c b/drivers/iommu/amd/io_pgtable.c index 70c2f5b1631b..46dfed9bd7e2 100644 --- a/drivers/iommu/amd/io_pgtable.c +++ b/drivers/iommu/amd/io_pgtable.c @@ -131,12 +131,15 @@ static bool increase_address_space(struct amd_io_pgtable *pgtable, *pte = PM_LEVEL_PDE(pgtable->mode, iommu_virt_to_phys(pgtable->root)); + /* + * Keep the seqcount odd until the DTEs point at the new root, or a + * concurrent alloc_pte() maps an IOVA the device cannot translate yet. + */ write_seqcount_begin(&pgtable->seqcount); pgtable->root = pte; pgtable->mode += 1; - write_seqcount_end(&pgtable->seqcount); - amd_iommu_update_and_flush_device_table(domain); + write_seqcount_end(&pgtable->seqcount); pte = NULL; ret = true; -- 2.53.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel