Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp5969161ybx; Mon, 11 Nov 2019 01:33:53 -0800 (PST) X-Google-Smtp-Source: APXvYqxr44QL+m/uqu2fUF0yZVT2JVlIgAt5Mr/H5EwOC+b1ysrwcgz52yGggGNVfF01k+oGnAsS X-Received: by 2002:a17:906:1c4d:: with SMTP id l13mr21473400ejg.308.1573464833339; Mon, 11 Nov 2019 01:33:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573464833; cv=none; d=google.com; s=arc-20160816; b=ljK3o+PkHm/kgwpbZZQaGM6wL7L2lg2sTRRAiv3E4u8lfXKpfb+yYwdQknsHsIvYHH W08nDOT/o4TGUa8L6fTDLTGK+iudy9/SkOptc6tKjz9dLFLJCcG2ZMmRod3vcZ4SJY2g A4VTRmlROsuNgFR8m9Dj7HnLYUtdar+vQ/j61Tv03U78+5KIBVxcbABEx/embQYyGzM3 bj4od4Wr+VA2luLscdZUAyoAHXMnQ36L60r0M7fPRa8nWA5zWa01OOSNOdvgvv4wLLcP 0r57kMwI7DaZujr0Zg9S4qGzs6VFLsH5FiNWN4f7g7Pv7LrphssM6t5qoiG/kLlg6f3i Nn6w== 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 :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=+5h1hCGg89V2tLcXl/B8NG8uH3hYgrB3/l23LOEft3E=; b=Ap/f8F3v46T7yWYgv1vWQiUnRT1RIrc79KZj/bs/jL2nd40wQM5uUTXSkYDcwi7EKe aixgjqsn8wVyJlXwQg7kA7b5qWfywttAAB9B6RaxLOuKZ24WPhv/HEFGcAuWAegk/9E8 ES8r0s4/f8aZSHdoIWM7Xx7cK4ri8p7tAcBnTiMrvh7f208RELpktklyE2Oj40dccyLf dcy/TmnkBG9aTzlOK/izxkVchVj1xpKAtUcjWU8jieRpPjvBQFwQ+ocvN/Jv/7BAd6nd GDT/unAcPqx8i3iVsPED8iCTMp5Ui6WgB9qA7Rch+imgl9Mmx73frvNlGCo7fSTRX0U0 +5Rw== ARC-Authentication-Results: i=1; mx.google.com; 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 ch17si9286284ejb.184.2019.11.11.01.33.30; Mon, 11 Nov 2019 01:33:53 -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; 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 S1727159AbfKKJco (ORCPT + 99 others); Mon, 11 Nov 2019 04:32:44 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:55754 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726976AbfKKJcm (ORCPT ); Mon, 11 Nov 2019 04:32:42 -0500 Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1iU63l-000379-BG; Mon, 11 Nov 2019 10:32:33 +0100 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id F0E1D1C03AB; Mon, 11 Nov 2019 10:32:32 +0100 (CET) Date: Mon, 11 Nov 2019 09:32:32 -0000 From: "tip-bot2 for Frederic Weisbecker" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: irq/core] irq_work: Fix irq_work_claim() memory ordering Cc: Frederic Weisbecker , Linus Torvalds , "Paul E . McKenney" , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , linux-kernel@vger.kernel.org In-Reply-To: <20191108160858.31665-3-frederic@kernel.org> References: <20191108160858.31665-3-frederic@kernel.org> MIME-Version: 1.0 Message-ID: <157346475270.29376.12510079913530639928.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the irq/core branch of tip: Commit-ID: 25269871db1ad0cbbaafd5098cbdb40c8db4ccb9 Gitweb: https://git.kernel.org/tip/25269871db1ad0cbbaafd5098cbdb40c8db4ccb9 Author: Frederic Weisbecker AuthorDate: Fri, 08 Nov 2019 17:08:56 +01:00 Committer: Ingo Molnar CommitterDate: Mon, 11 Nov 2019 09:03:31 +01:00 irq_work: Fix irq_work_claim() memory ordering 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: Linus Torvalds Cc: Paul E . McKenney Cc: Peter Zijlstra Cc: Thomas Gleixner Link: https://lkml.kernel.org/r/20191108160858.31665-3-frederic@kernel.org Signed-off-by: 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 df0dbf4..255454a 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; }