Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp1309668lqt; Fri, 7 Jun 2024 14:31:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWwiXaqrwn/+/2nXvt0tGNgPrgj2jz3UTNpwouePTp3hk4WZ+8eCMylEGyuglwV1eDSnRug7e7flMKkCkOXRxN77t4qn29J5u6XTxef8g== X-Google-Smtp-Source: AGHT+IE8nM2xOvcKscXX6ZzvFNpkWPpXNEmPEpHPf+hQMriuiwihYVxm7eiBWU92mPW9hnE1SOVF X-Received: by 2002:a05:6a21:190:b0:1af:a35b:a34f with SMTP id adf61e73a8af0-1b2f9a0dcfamr4485118637.25.1717795903146; Fri, 07 Jun 2024 14:31:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717795903; cv=pass; d=google.com; s=arc-20160816; b=SJsvnJ1P89pihlYmeUnYFwnVTLhHmnZzSKVgDUJeQ/BRlTzgY1cb+XPHClDbRrM/Z0 Hq0mPwi0Zy5bvHZ+Y4ao2FQCdsw0u2VUN3aZOMBVFClpB5EEsJl4vuXKsE2AzKKIlbeO yYl0XMtKGR1xpTRBHIEKujx3EQDWsEvkpRFW3FWqKCsY8lGfrsPduwc5pic1RwSpblbO 4RZdCbQ36YkeviJmJx/XF2MxiJ+sJ9y6KES0qRnJhx6aOcVwaeegLS/QjzJnh+4Oc+15 Z86hGU96Cp6/Z34L4pNKw7ogCAJuTEfy3R+Ava7P0gT7TBlrEgUHnzuQM3kV9yap8YSt sMZQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=UkdZ96YN647dkuRI6ZAsJuXtAJAx2hnE0W95n3oCCZw=; fh=LviSB7JAySM0OJaaowGf+iT+MgG4Z2kNkWsBLRmzLso=; b=Ymy5GG8+TNXP5QhIEudedWSMI0C50HVobxufDwPE0jpgft60Ab2n/dwQd/IXH8qxJx DygGrETSmE+a4eb7uIsRTIcYop/mUwXNVh9NcnCCs8C8rMvlJ6V5P0WgIZEin3ULSFx1 T367un1Me65YiwFAwN2YAcC52yBJ4br9fqwmAaH0x0rm1DtqXxIV6LJ3Kmq7uOMQrvgf GxW74kEth6/2E4Vx7D/GG2oIdCYCjs0rltymJCRLS86eKej/5r+glccW+H1VYMQWR/n+ KwLwwvnZHee1ZmWFEehBKkF4zEcAS/St0wcmmxU+EoKdEU/zJTqsXa8XU0JRc9c0t56N tLWg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="IhL/6QVb"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-206549-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206549-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6e54d607deesi70601a12.798.2024.06.07.14.31.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 14:31:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-206549-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="IhL/6QVb"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-206549-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206549-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 1192AB227D6 for ; Fri, 7 Jun 2024 17:33:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D10CA19AA65; Fri, 7 Jun 2024 17:33:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="IhL/6QVb" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (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 B1F2B19478 for ; Fri, 7 Jun 2024 17:33:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717781604; cv=none; b=r8tliAOm9NJxZHRGd4aJ15FmWKppuX8hvZZgWLAWmnakRRJXatWRN2pQcvnBlZHmGl9mP+faJp02blrlz7yYptT5P990I50+eYuDaICd9yfsV93PUoBrr0aLH4Ycf9AdRxeDyrx8rsnYTosa7OsqpilRzJMY3SthhBW60yZo+2o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717781604; c=relaxed/simple; bh=DJkQykK9Jx8Er6B2H79K1ibbQjfGa6B7jp8dJp37if8=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=bh1Ig7b0eaRmb2+bpHoQd69Yl/1tn0uA+sMpdqJ8fbMXVAvX+ngozN54pOmvV74PbnmlNAEBdWqutzOAxzV0rI/x7ZaymxY58D5IH2czLiX07bhUofK9ns16K8QbteDuxZfwQy/yDPzbl+pObcBIr2zQF3vw2wLNRRC+qSVvzK0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=IhL/6QVb; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717781603; x=1749317603; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=DJkQykK9Jx8Er6B2H79K1ibbQjfGa6B7jp8dJp37if8=; b=IhL/6QVbEcHioKcFnbfh+jswziPyN+7X5Pyfkll1PAdBcBUqR7Nm0TgL 2gt9XOBCBR+CzJgzQ0WUc3Mi3I0/9rPYkIWZac3tsWiEP51bBX6gRgBvO txHq1EzZQU/X4598fOAXhUMUhV5C8m+Exz8/xCeGx/CrXrY9zCyyyx+jJ CuhHSS/3H75Xo7aYXplBcLncMxVlhUwFBcusLNJmFTwnNSY8kCjv+RdMq KcEMgrBsLAtqa2JTna+SY9PxuCIElUR+DUXemeWcZMVm0Zof/n1LUhCuT cLdd5/+OF4Am+NQdnhxPC6TYaZiXenSSjsJIXaVUKj0U782pGYcZspfQA w==; X-CSE-ConnectionGUID: gly0ZibDT4+P/x2JRMSLKA== X-CSE-MsgGUID: ctTqKdF1S4G7yMbkqh3pxw== X-IronPort-AV: E=McAfee;i="6600,9927,11096"; a="18340859" X-IronPort-AV: E=Sophos;i="6.08,221,1712646000"; d="scan'208";a="18340859" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Jun 2024 10:33:23 -0700 X-CSE-ConnectionGUID: /8hFgTybQ6WQEnECxLAI0Q== X-CSE-MsgGUID: x027f1S3ROuFajdE0DBjig== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,221,1712646000"; d="scan'208";a="38494227" Received: from jacob-builder.jf.intel.com ([10.54.39.125]) by fmviesa010.fm.intel.com with ESMTP; 07 Jun 2024 10:33:22 -0700 From: Jacob Pan To: "Lu Baolu" , LKML , iommu@lists.linux.dev Cc: "Tian, Kevin" , Yi Liu , sanjay.k.kumar@intel.com, Jacob Pan Subject: [PATCH] iommu/vt-d: Handle volatile descriptor status read Date: Fri, 7 Jun 2024 10:38:17 -0700 Message-Id: <20240607173817.3914600-1-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.25.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 Queued invalidation wait descriptor status is volatile in that IOMMU hardware writes the data upon completion. Use READ_ONCE() to prevent compiler optimizations which ensures memory reads every time. As a side effect, READ_ONCE() also enforces strict types and may add an extra instruction. But it should not have negative performance impact since we use cpu_relax anyway and the extra time(by adding an instruction) may allow IOMMU HW request cacheline ownership easier. e.g. gcc 12.3 BEFORE: 81 38 ad de 00 00 cmpl $0x2,(%rax) AFTER (with READ_ONCE()) 772f: 8b 00 mov (%rax),%eax 7731: 3d ad de 00 00 cmp $0x2,%eax //status data is 32 bit Signed-off-by: Jacob Pan --- drivers/iommu/intel/dmar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c index 304e84949ca7..1c8d3141cb55 100644 --- a/drivers/iommu/intel/dmar.c +++ b/drivers/iommu/intel/dmar.c @@ -1446,7 +1446,7 @@ int qi_submit_sync(struct intel_iommu *iommu, struct qi_desc *desc, */ writel(qi->free_head << shift, iommu->reg + DMAR_IQT_REG); - while (qi->desc_status[wait_index] != QI_DONE) { + while (READ_ONCE(qi->desc_status[wait_index]) != QI_DONE) { /* * We will leave the interrupts disabled, to prevent interrupt * context to queue another cmd while a cmd is already submitted -- 2.25.1