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 8926F803F7 for ; Tue, 10 Nov 2026 19:19:59 +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 6AAJIkhS018393; Tue, 10 Nov 2026 22:18:47 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AAJIkhS018393 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=default; t=1794338328; bh=MJPIY1Ho1+V8mHluyMsUfv7vNnIRKnDecJmaDOgBQ7g=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe; b=EK2FqCr0jAgfbzWtHc8FssIybOK7J26s3uSQpTc2y2CX9gJNaFQKTJ7a3vVcKCWKL m6oLRgqRLVGBvc/KzL+SshmKyWv8/L7iXYN61NdMEDzgneraZ7/IbtNxPe+6dUj29q 7XxeFm+1JUszoht37iL3xkt+modUwpddVfhJd543bwnEsuYA2p0J+d3xII63/r8hx/ oRDxaqiY38OftOt254XBnfQtAeYgCc7MmRcsK4SHAA71xjzIWgMXudPrhSUa/LYPPL kgGo+J17MF6QILyNQkENeRr8XpV7nHHDNM25sBd4YCWoPIoiJXV6M8VYV9ZPe3NxEc mJl8hxEoPFRcw== Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AAJIgQe018374 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Tue, 10 Nov 2026 22:18:42 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AAJIgQe018374 Authentication-Results: mail.openvz.org; dkim=pass (2048-bit key) header.d=openvz.org header.i=@openvz.org header.b="oKFXfllO" Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4b0a307487aso11368655e9.1 for ; Tue, 10 Nov 2026 11:18:42 -0800 (PST) X-Gm-Message-State: APuU4Z9L1DfvZ3+ljNKEXpJTNAFaRp29uRTlLsNzmQNJUwqmL9hIQg+9 8Jvn25F/TXhEEjwBbetDQE5iI2g2WI34xwmmKOyO7+OC4E3jtS2O6I+fwYZdbEbAPvJg/jUCXt1 UgV2yXtTYYmRCwGhmR2ekemQbFpZf+NBrhsqs/f7cG9OH9f8Yiy71oA== X-Gm-Gg: AYBFou0hVPNdapyoLWbXIqJ5PnKys1baf5+PrtxRkTOIHU10uTLknoDkEGRxDwZLJLC 4nS/rLUZwftk3JZTRkzVrwAMqhpb8GfXT+Jx3KDwZQczAC2GhrqEdYEHHVtaWiWAIfsq/lyjb0/ X0Jpzy4LktY9aPLBqz7YtN7ubJ0NZrB4SwPMb0+dR2exxTBjv6niRePEUIh3en6vFzGw8U3vrnf miOjVBQMYIkXxORB50/rEQAAtbzGTntwEvy74hQOO8ZSQ9Jyt8QREQccDExTBMlo8ePM7RXGc/4 WTDS2gT6hA== X-Received: by 2002:a05:600c:840c:b0:4af:c210:5b3f with SMTP id 5b1f17b1804b1-4ba09377dbfmr1725535e9.24.1794338322051; Tue, 10 Nov 2026 11:18:42 -0800 (PST) X-Received: by 2002:a05:600c:840c:b0:4af:c210:5b3f with SMTP id 5b1f17b1804b1-4ba09377dbfmr1725375e9.24.1794338321666; Tue, 10 Nov 2026 11:18:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794338321; cv=none; d=google.com; s=arc-20260327; b=gAb5ke5lTZ/x8xPHIX57oxGjSXSFNTRs4ts3lZNPXSmbTx10GaPIHDpTjHVu8yrGwG o8z1wCgSoNWNw1HEMMmRvrddV88A/VTXYYV3RMiWkxmjlhk1l1yvhf3l2p2QoIfnv3Xy QHVU7Djx/1B9I6RZHWF9V4N9q/0L75FGX1RLo/YfNpLiXZbKA3S4jodZvBv2Ak+foDJK xGBw7FcZ7O2H10YpYWfSFZbbNkQvUHsVyKR/pSB/G9WonWxPUVmQwXNPS7tKpoGGOM6Z lm7zNFoAaLUF0dOKhZi6o+3Egj4CsaBcvI+XvUIigDya3iVCQnrIbefx/f/zwav5KfIt mbhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=fXzUvs3+QqNjZTmJuWGMHDnVsVeJPdpWGiutKvzuKow=; fh=ozrYJQ1t3QIP6s65KBq5xgJxiFM2qf+5wwn3ABTusyU=; b=lI/InBT/Ew1i13SLUtV9qQC0dNadBqrgwqSrlpXlgB5h2MhH4RABHpVCGZQkjUPcLD dbYs/DBZfz8qBfyRxSZxDQCLVrNL+oGRr7554neLKG58AgUZdBZBpP8tWSZvKOH9f258 HFtFN2r5tIymb42ju//et0kzryt3VM4dhS0pnWOFPcCmHzcHZdd8EONxGkU+jwr9bJeI eT+RyRdkrWZt3C2m2oJqHIa38zIuqD+KmY3q0CTrHsQ/TI4FuuqCYbgTpDDHvXSRDMqi 9jbk0RCDBAXyvk9RkSWou/PEu1oKkQLUCDliHbXXyWCrHVUo9nHQHW98enbw11GK5XTs 06Sg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@openvz.org header.s=google header.b=oKFXfllO; 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 5b1f17b1804b1-4ba01ff5df2sor6664805e9.11.2026.11.10.11.18.41 for (Google Transport Security); Tue, 10 Nov 2026 11:18:41 -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=oKFXfllO; 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=1794338321; x=1794943121; darn=openvz.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=fXzUvs3+QqNjZTmJuWGMHDnVsVeJPdpWGiutKvzuKow=; b=oKFXfllOjUv3IPMNF2Dikj5Kg7Tr35BWByYLui2NG1OFXvsF2sCAuJVIZdcAJFT2aR cgWN7TgnLYukqapuuj9q4NEEQN5crVgSwImk1E5s+cRX747ILnFwwwY4DqF9Po4J0/M0 PM1rrzEYPCXYYBKrJF2c8YRPvtpD7CT4OfmD/CVRtcnaocx16hD9AeZABwysiORuOV0n X/BPj/9w2YmGcfyb+4QsFLQeCaN7U1f3ndftjmAe2HuDuduNo0Dp6l7lOtd+e41hsCIJ Kjo1oeYAIgvIprKAICbqJWXlqlHrCyi2o3p9IoCI9IJtz4Cm1qPD3bf0xfTV+po4FIOR zxLg== X-Received: by 2002:a05:600c:840c:b0:4af:c210:5b3f with SMTP id 5b1f17b1804b1-4ba09377dbfmr1725065e9.24.1794338321259; Tue, 10 Nov 2026 11:18:41 -0800 (PST) Received: from athena.sw.ru ([2a06:5b06:b600:300:4f78:6441:d0f1:22af]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4ba01fea745sm80156815e9.10.2026.11.10.11.18.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2026 11:18:40 -0800 (PST) From: "Denis V. Lunev" To: khorenko@virtuozzo.com Date: Tue, 10 Nov 2026 20:18:35 +0100 Message-ID: <20261110191836.3000352-3-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261110191836.3000352-1-den@openvz.org> References: <20261110191836.3000352-1-den@openvz.org> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1 2/3] ms/iommu/amd: serialize sequence allocation under concurrent TLB invalidations 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: Ankit Soni With concurrent TLB invalidations, completion wait randomly gets timed out because cmd_sem_val was incremented outside the IOMMU spinlock, allowing CMD_COMPL_WAIT commands to be queued out of sequence and breaking the ordering assumption in wait_on_sem(). Move the cmd_sem_val increment under iommu->lock so completion sequence allocation is serialized with command queuing. And remove the unnecessary return. Fixes: d2a0cac10597 ("iommu/amd: move wait_on_sem() out of spinlock") Tested-by: Srikanth Aithal Reported-by: Srikanth Aithal Signed-off-by: Ankit Soni Reviewed-by: Vasant Hegde Signed-off-by: Joerg Roedel (cherry picked from commit 9e249c48412828e807afddc21527eb734dc9bd3d) Context adjusted: vz10 does not have cmd_sem_paddr in struct amd_iommu. https://virtuozzo.atlassian.net/browse/VSTOR-154424 Feature: fix ms/iommu Signed-off-by: Denis V. Lunev --- drivers/iommu/amd/amd_iommu_types.h | 2 +- drivers/iommu/amd/init.c | 2 +- drivers/iommu/amd/iommu.c | 18 ++++++++++++------ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h index 95f63c5f6159..05a54f8f0434 100644 --- a/drivers/iommu/amd/amd_iommu_types.h +++ b/drivers/iommu/amd/amd_iommu_types.h @@ -791,7 +791,7 @@ struct amd_iommu { u32 flags; volatile u64 *cmd_sem; - atomic64_t cmd_sem_val; + u64 cmd_sem_val; #ifdef CONFIG_AMD_IOMMU_DEBUGFS /* DebugFS Info */ diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c index 07f1159a5e28..36ea9ce775ec 100644 --- a/drivers/iommu/amd/init.c +++ b/drivers/iommu/amd/init.c @@ -1749,7 +1749,7 @@ static int __init init_iommu_one(struct amd_iommu *iommu, struct ivhd_header *h, iommu->pci_seg = pci_seg; raw_spin_lock_init(&iommu->lock); - atomic64_set(&iommu->cmd_sem_val, 0); + iommu->cmd_sem_val = 0; /* Add IOMMU to internal data structures */ list_add_tail(&iommu->list, &amd_iommu_list); diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index 00608e55e70c..373596fa07c0 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -1391,6 +1391,12 @@ static int iommu_queue_command(struct amd_iommu *iommu, struct iommu_cmd *cmd) return iommu_queue_command_sync(iommu, cmd, true); } +static u64 get_cmdsem_val(struct amd_iommu *iommu) +{ + lockdep_assert_held(&iommu->lock); + return ++iommu->cmd_sem_val; +} + /* * This function queues a completion wait command into the command * buffer of an IOMMU @@ -1405,11 +1411,11 @@ static int iommu_completion_wait(struct amd_iommu *iommu) if (!iommu->need_sync) return 0; - data = atomic64_inc_return(&iommu->cmd_sem_val); - build_completion_wait(&cmd, iommu, data); - raw_spin_lock_irqsave(&iommu->lock, flags); + data = get_cmdsem_val(iommu); + build_completion_wait(&cmd, iommu, data); + ret = __iommu_queue_command_sync(iommu, &cmd, false); raw_spin_unlock_irqrestore(&iommu->lock, flags); @@ -3092,10 +3098,11 @@ static void iommu_flush_irt_and_complete(struct amd_iommu *iommu, u16 devid) return; build_inv_irt(&cmd, devid); - data = atomic64_inc_return(&iommu->cmd_sem_val); - build_completion_wait(&cmd2, iommu, data); raw_spin_lock_irqsave(&iommu->lock, flags); + data = get_cmdsem_val(iommu); + build_completion_wait(&cmd2, iommu, data); + ret = __iommu_queue_command_sync(iommu, &cmd, true); if (ret) goto out_err; @@ -3109,7 +3116,6 @@ static void iommu_flush_irt_and_complete(struct amd_iommu *iommu, u16 devid) out_err: raw_spin_unlock_irqrestore(&iommu->lock, flags); - return; } static inline u8 iommu_get_int_tablen(struct iommu_dev_data *dev_data) -- 2.53.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel