Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp2704649ybx; Fri, 8 Nov 2019 08:11:38 -0800 (PST) X-Google-Smtp-Source: APXvYqxoKPmoTNpnRJuFing6Fp+9/yGt/FUa0OUsGY4AnikFNosW42wULCTK4GE3gkPMAjWQU0Xz X-Received: by 2002:a50:ec1a:: with SMTP id g26mr8278836edr.84.1573229498120; Fri, 08 Nov 2019 08:11:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573229498; cv=none; d=google.com; s=arc-20160816; b=zePw+H0cdzCmS+H/Kl2xhOMw8NrUFt3CHRr/qV+EEs6vAejIAT3fuwdU/KL+69VP+h 0kNmbMLvA6DI8fJnusqSCKKL55r5+SP/NwyDmOn4A2vsh4XIw6dBPUhnijfeHeOyHJ52 dfWiplXvl7+umVOCASxMm+REQk5QbmemnLrK5N8sLqa7gg+E1xh3I+m/PsZ5rxOX1j7C SmcgEPvD7HdnSfGBnWu4k7XMJ54s21OWYje1OIUYvsq4rpGOIwYoV/pCncG/yNaiUEJS SZOTHGeDeuueVpQrQMuN632U9qDUwG7U6EKgksjF6Dcg/CilLEgznQr8pWH1vNdVFYhD nVOg== 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=UUPF8q/WjnJ4xxJar2QJFFc0f11c/KNs3pgKC6FkJT4=; b=Sle6dyj6lOVEbPzT3HBOeFMWyd64FQMjIzLyoZCclPS5GyFJt5vzGQYVbiVQVLEZWG kIYYr+9qVhN6SZ3vR5AX5T+x208bSn+yVhucwvlRzaPBgD6FDEAv/B5lgzMLgUVaSU+d zY5qj2nBW2ovdxlXE6+GjN3AvRW2XQyQKhIYB5FVgIP/OzOGi60m76klTFSy9Uvrgu8o 2rGl+LMCIxHJpzWorWEc4Wy47WGTs8R+Bizf410weJNpaQ5Wm1LYp2rScEoHm8zhdT3G ben5630v1jJSgMHksKJ6lXn+dP8kwS5PZ9RZ3OBIh/l1OX1cDqw5FyWRQ5pXsmjS+aNk fVEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Fbwe+kKY; 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 uz25si4005397ejb.43.2019.11.08.08.11.15; Fri, 08 Nov 2019 08:11:38 -0800 (PST) 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=Fbwe+kKY; 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 S1727963AbfKHQJ2 (ORCPT + 99 others); Fri, 8 Nov 2019 11:09:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:55194 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727931AbfKHQJ0 (ORCPT ); Fri, 8 Nov 2019 11:09:26 -0500 Received: from lenoir.home (lfbn-ncy-1-150-155.w83-194.abo.wanadoo.fr [83.194.232.155]) (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 756F622475; Fri, 8 Nov 2019 16:09:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573229365; bh=XH1045tMYe+K9HbmMd0qPKXHpNyh8RryBxSXENHeHbg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fbwe+kKYtZbPru7xnexqYZU3rCZu07jeOMY28auKVHZ35xDF0dLCufWoiOKtABWGu yhRlgTCpnYarBViylj1pKHMiS4OC+SGLCQ0ZKpPozHa81DC3e+ScKX13mvGYGA7pSM 3zt1Sns8Cyvp+DSbclW2Z9T86RkPZzL87gRLvDQc= From: Frederic Weisbecker To: Peter Zijlstra , Ingo Molnar Cc: LKML , Frederic Weisbecker , "Paul E . McKenney" , Thomas Gleixner Subject: [PATCH 2/4] irq_work: Fix irq_work_claim() ordering Date: Fri, 8 Nov 2019 17:08:56 +0100 Message-Id: <20191108160858.31665-3-frederic@kernel.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191108160858.31665-1-frederic@kernel.org> References: <20191108160858.31665-1-frederic@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When irq_work_claim() finds IRQ_WORK_PENDING flag already set, we just return and don't raise a new IPI. We expect the destination to see and handle our latest updades thanks to the pairing atomic_xchg() in irq_work_run_list(). But cmpxchg() doesn't guarantee a full memory barrier upon failure. So it's possible that the destination misses our latest updates. So use atomic_fetch_or() instead that is unconditionally fully ordered and also performs exactly what we want here and simplify the code. Signed-off-by: Frederic Weisbecker Cc: Paul E. McKenney Cc: Thomas Gleixner Cc: Peter Zijlstra Cc: Ingo Molnar --- kernel/irq_work.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/kernel/irq_work.c b/kernel/irq_work.c index df0dbf4d859b..255454a48346 100644 --- a/kernel/irq_work.c +++ b/kernel/irq_work.c @@ -29,24 +29,16 @@ static DEFINE_PER_CPU(struct llist_head, lazy_list); */ static bool irq_work_claim(struct irq_work *work) { - int flags, oflags, nflags; + int oflags; + oflags = atomic_fetch_or(IRQ_WORK_CLAIMED, &work->flags); /* - * Start with our best wish as a premise but only trust any - * flag value after cmpxchg() result. + * If the work is already pending, no need to raise the IPI. + * The pairing atomic_xchg() in irq_work_run() makes sure + * everything we did before is visible. */ - flags = atomic_read(&work->flags) & ~IRQ_WORK_PENDING; - for (;;) { - nflags = flags | IRQ_WORK_CLAIMED; - oflags = atomic_cmpxchg(&work->flags, flags, nflags); - if (oflags == flags) - break; - if (oflags & IRQ_WORK_PENDING) - return false; - flags = oflags; - cpu_relax(); - } - + if (oflags & IRQ_WORK_PENDING) + return false; return true; } -- 2.23.0