Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp3220864ybj; Mon, 23 Sep 2019 17:17:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqznrB0fGUFHHC6324dX3MNRKS5ih6NLs+XgLqfmKtZtR6VJCNHdq8bq68IVeJWbs4evOj/x X-Received: by 2002:a50:ee10:: with SMTP id g16mr2853892eds.267.1569284279517; Mon, 23 Sep 2019 17:17:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569284279; cv=none; d=google.com; s=arc-20160816; b=TJPSKQDp7Gb3NSvsXBeFKlmgvByltbJAa8r8/YcbsZ0RXjWklXXsPJ6VzRSSHUBAWg k0DNajrr3w2YvWmwG1VSgRAicnZLK+eTz1ifvJIfFdPjJvt/9CRw1y/C7ykgBFKa0yZy +vOsWLhipBSmQkC6UvRlqgq1KOP6mF3om3o8oUqCubBMScGfVOy1H9AzsaDxutvFiE9h BhFc9Dx7WG//SZZTyYIn3oqFC2SaoHiEuTjQLx1C2hl1fMRfwd1NFp9qgPGP9eZbaWfo sZlSvbbH6CQKzdPOBtITkcQW39QF71Z2OocDy3A8wl6hMokAEMnk4+v3GK/6Fqz6Yodh Du4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Ajv4m4wxm3DwFBcp9yffjNjKRazWLNv+1Zq23isP8sY=; b=momYkTXzqgaPMIQeQiN2ceH3j5oLMzxNYETsvcCeIIdck2ZbWLsnVpmTbFQ94qnobE Vcwbf8fH1BmxY5tjQnumJaZrumlcJVl+rDTM9qsGQYUVISpKz9QbDaQhebKCPeuq/cvi UjZSBO/l+7FG0SZn0RlhYZ5e+OPNnm2OMd2/o3f5bkB/4Y82RYc7wrzUU9mfaDINfs2T uh9gUio4M2vZ2/82aFotWLW2dAQsm9g2LeMPUcbxCU3aCfY7gTEu/bjW2/00eu9IM3uE eViqv0HELlBZgEHw3hliqrjJjKIP51puIiKbaC2Ai3Fyuvm8KTaKNcYlDSVvDrE10KuE 3S1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hfjoYIhx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v7si70645edr.125.2019.09.23.17.17.22; Mon, 23 Sep 2019 17:17:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hfjoYIhx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390138AbfIVSsN (ORCPT + 99 others); Sun, 22 Sep 2019 14:48:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:44732 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391342AbfIVSsD (ORCPT ); Sun, 22 Sep 2019 14:48:03 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6FCC3208C2; Sun, 22 Sep 2019 18:48:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569178082; bh=9SO459Tx95hQLcr6M3fZdhK5p3dMn/Dz2ldcdyi20Qc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hfjoYIhx38qd4UtAVlq5KgUsD4z78DPFI7BRTjh7voCbXW7/Jz7yWvYze4BX4raQf 0QTH/3PLeidWIhDBM5aWJMYT8VrIu/PcicTLRIHVJisyH55At1yddD67nBJKnLzGzl w9hZpVXaPnHh+fkn8Ooj819YHqGRCYkey+F8qTfM= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Eric Dumazet , Jinyu Qi , Joerg Roedel , Robin Murphy , Sasha Levin , iommu@lists.linux-foundation.org Subject: [PATCH AUTOSEL 5.3 152/203] iommu/iova: Avoid false sharing on fq_timer_on Date: Sun, 22 Sep 2019 14:42:58 -0400 Message-Id: <20190922184350.30563-152-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190922184350.30563-1-sashal@kernel.org> References: <20190922184350.30563-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Dumazet [ Upstream commit 0d87308cca2c124f9bce02383f1d9632c9be89c4 ] In commit 14bd9a607f90 ("iommu/iova: Separate atomic variables to improve performance") Jinyu Qi identified that the atomic_cmpxchg() in queue_iova() was causing a performance loss and moved critical fields so that the false sharing would not impact them. However, avoiding the false sharing in the first place seems easy. We should attempt the atomic_cmpxchg() no more than 100 times per second. Adding an atomic_read() will keep the cache line mostly shared. This false sharing came with commit 9a005a800ae8 ("iommu/iova: Add flush timer"). Signed-off-by: Eric Dumazet Fixes: 9a005a800ae8 ('iommu/iova: Add flush timer') Cc: Jinyu Qi Cc: Joerg Roedel Acked-by: Robin Murphy Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin --- drivers/iommu/iova.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c index 3e1a8a6755723..41c605b0058f9 100644 --- a/drivers/iommu/iova.c +++ b/drivers/iommu/iova.c @@ -577,7 +577,9 @@ void queue_iova(struct iova_domain *iovad, spin_unlock_irqrestore(&fq->lock, flags); - if (atomic_cmpxchg(&iovad->fq_timer_on, 0, 1) == 0) + /* Avoid false sharing as much as possible. */ + if (!atomic_read(&iovad->fq_timer_on) && + !atomic_cmpxchg(&iovad->fq_timer_on, 0, 1)) mod_timer(&iovad->fq_timer, jiffies + msecs_to_jiffies(IOVA_FQ_TIMEOUT)); } -- 2.20.1