Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp21854ybp; Thu, 3 Oct 2019 09:37:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqwPc75jtUrvTkem3j4diDCUSVjLWKNREEkjy438MROL+w+b6iAOfainOz2GihU5LB/PWvl/ X-Received: by 2002:a17:906:6c8:: with SMTP id v8mr8652138ejb.252.1570120637891; Thu, 03 Oct 2019 09:37:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570120637; cv=none; d=google.com; s=arc-20160816; b=SaWUReeGp59O5dem9Kma6B4a6zvXSGTcCq9ku8iYTm+dwv+Qh0vXOcy+kJhk2FSDQx ckrG47UbYL9ZDCSKWEdjg2Th5F7mCscKpoNhPAh1ie4yBULs0AHg3uoRCm3ESf0mIoMu W3lRUd8vkLERfHRngsxVHABv1DcMf3aotfA6bQqM61pkmZdMcoMZXQmQyyr5bWkLM/b6 e/FOK547QAT+xGDm430uOUzzRFSaLWm/Y8nz9zOCB6lRfko1zjg8jXihX0sRFbYAm3R1 gjtCpWxwVJ5xIaXVeeC6ka2RF59eJ29ZtC+mRME3oKRHuNzujqGeL7t8QBbDueQFlaFm 8P4w== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Ajv4m4wxm3DwFBcp9yffjNjKRazWLNv+1Zq23isP8sY=; b=jVJ5F0O/SdQoHDE6i1aOvEiPaW2HUm9FNPqeuUFTseH4XQa+V8IxNTo8XX21LfDr01 dkQY6WsrPI8XOHotD0bAbYPjYUrr3YkMw1Ik44wigXq4TJO9KAEdmyLjw6edukzRlvc9 sy35/+2z5FWF5PEfeMS8EzFasVu7D/bXUYx4nGopjuYfgjpSEBLn/QVl11dcPZtZ2p9s WGgkoqBHLJUisf/WjzntiiY4PF8iPdnKIZaAFeX0g95Bs8LENYd7/+eneOZjplYkW1Fn Tkt9SIbrzV3EyW+mrM6pqqL+83d62rfJ3awiIxoOuB4395gCoHbFk1TnTiDMFjxNBBJA LkQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=b63VNdnB; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g11si1543259ejj.11.2019.10.03.09.36.53; Thu, 03 Oct 2019 09:37:17 -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=b63VNdnB; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391977AbfJCQdO (ORCPT + 99 others); Thu, 3 Oct 2019 12:33:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:41056 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390880AbfJCQdK (ORCPT ); Thu, 3 Oct 2019 12:33:10 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1D34320830; Thu, 3 Oct 2019 16:33:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570120389; bh=9SO459Tx95hQLcr6M3fZdhK5p3dMn/Dz2ldcdyi20Qc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b63VNdnBZNldewZPfA5xPVQritekO/WHznHhudjwoj+yFSL1C/bRUKsaMp2IxYtn/ WY7bXCMJrdI5kJ4aILK0XlE1K4t+KTf0wofFWdtw5IMpWkSVPRjH3Z1wcOf6vbnqpk B+0PhK4+ujnB4nnJ0/plB8HctGSPqcCStG0dYBhw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , Jinyu Qi , Joerg Roedel , Robin Murphy , Sasha Levin Subject: [PATCH 5.2 166/313] iommu/iova: Avoid false sharing on fq_timer_on Date: Thu, 3 Oct 2019 17:52:24 +0200 Message-Id: <20191003154549.324600329@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191003154533.590915454@linuxfoundation.org> References: <20191003154533.590915454@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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