Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp2819786imm; Sun, 24 Jun 2018 05:23:01 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJ/IGsAy4jnpPyDVQdKDuKVzdQrk5q3Ayrc9Pq7Uf341Fpgf6WLyEauCVdUqjF0rxljRD6m X-Received: by 2002:a62:ff1d:: with SMTP id b29-v6mr9057124pfn.181.1529842981908; Sun, 24 Jun 2018 05:23:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529842981; cv=none; d=google.com; s=arc-20160816; b=Q1nqaVL0RlKonJlAhklpGw0Rr4SrsrK0dnjxlHKkQx8ZZUS3gtxF11+D904hOWzVf+ 9wBrxhjN75zMnfs9ERvo4uVBF2Fsu6Blw48qR7PRucrYySEico2ZeVhGpbh46xJ2YsIF RMFmXdyHZThqSyw3L4ERGZw34lZ7YrWGEjAgPXSLE6FA2WeyiFOlCvJTFzrsQFKs+Iwr K9c1UkS6nVhr5rZu3eKnzCoiIvtUAW1Tfz/AHA9GKJSfJsmhGFW8wmXkkEK0+qjzIKwr UpX1RbPb2U+ZK84lEUTR2hZsWZk/9i5JFj4C/cjLLzKqQjXUn8vpzbMpCbEE1syhN+1v vtZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=EwW80gXGlaW7kjOUk2nIC0Mnbc2OCV00qWJinqgan14=; b=ZrRClvGTEKrQrrSrCAI2osd8DRr5Z6xF64Vr5+KJaToukQ0qgkPmxH1RJF8isukKpy lHksiOvHR6JNiCyPm35fjm+bUKUgqxTaw/34mlvWnd3NcmY6eg7KRT8hWZo7KSjrhpNv aqemhXQ81cV7iENk4JYk6vZi/uqMKJ2MUyzmThuK4JvEncm/dvPdlzTmhxhbyL36ZWJ9 C5pPNJBcGZrijdMzrRjo5h995NyYPyiIbD30gwcDmpnLkViVNyyHDVEDUX2Oz1i7o7Zy bJmOL75vUap87zJ6xpGftNf5Uksje55VJEr5PPOhAchiouYep1eoMhJSGrVPh7coLkJb jrvw== 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 d1-v6si12498021pln.471.2018.06.24.05.22.46; Sun, 24 Jun 2018 05:23:01 -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; 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 S1751844AbeFXMWH (ORCPT + 99 others); Sun, 24 Jun 2018 08:22:07 -0400 Received: from terminus.zytor.com ([198.137.202.136]:49987 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751567AbeFXMWF (ORCPT ); Sun, 24 Jun 2018 08:22:05 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w5OCLs2R824128 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sun, 24 Jun 2018 05:21:54 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w5OCLsVc824125; Sun, 24 Jun 2018 05:21:54 -0700 Date: Sun, 24 Jun 2018 05:21:54 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Lukas Wunner Message-ID: Cc: hpa@zytor.com, linux-kernel@vger.kernel.org, mingo@kernel.org, bhelgaas@google.com, mika.westerberg@linux.intel.com, lukas@wunner.de, tglx@linutronix.de Reply-To: bhelgaas@google.com, mingo@kernel.org, hpa@zytor.com, linux-kernel@vger.kernel.org, tglx@linutronix.de, lukas@wunner.de, mika.westerberg@linux.intel.com In-Reply-To: <32fc25aa35ecef4b2692f57687bb7fc2a57230e2.1529828292.git.lukas@wunner.de> References: <32fc25aa35ecef4b2692f57687bb7fc2a57230e2.1529828292.git.lukas@wunner.de> To: linux-tip-commits@vger.kernel.org Subject: [tip:irq/core] genirq: Update code comments wrt recycled thread_mask Git-Commit-ID: 836557bd58e5e65c05c73af9f6ebed885dbfccfc X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, T_DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 836557bd58e5e65c05c73af9f6ebed885dbfccfc Gitweb: https://git.kernel.org/tip/836557bd58e5e65c05c73af9f6ebed885dbfccfc Author: Lukas Wunner AuthorDate: Sun, 24 Jun 2018 10:35:18 +0200 Committer: Thomas Gleixner CommitDate: Sun, 24 Jun 2018 14:17:26 +0200 genirq: Update code comments wrt recycled thread_mask Previously a race existed between __free_irq() and __setup_irq() wherein the thread_mask of a just removed action could be handed out to a newly added action and the freed irq thread would then tread on the oneshot mask bit of the newly added irq thread in irq_finalize_oneshot(): time | __free_irq() | raw_spin_lock_irqsave(&desc->lock, flags); | | raw_spin_unlock_irqrestore(&desc->lock, flags); | | __setup_irq() | raw_spin_lock_irqsave(&desc->lock, flags); | | raw_spin_unlock_irqrestore(&desc->lock, flags); | | irq_thread() of freed irq (__free_irq() waits in synchronize_irq()) | irq_thread_fn() | irq_finalize_oneshot() | raw_spin_lock_irq(&desc->lock); | desc->threads_oneshot &= ~action->thread_mask; | raw_spin_unlock_irq(&desc->lock); v The race was known at least since 2012 when it was documented in a code comment by commit e04268b0effc ("genirq: Remove paranoid warnons and bogus fixups"). The race itself is harmless as nothing touches any of the potentially freed data after synchronize_irq(). In 2017 the race was close by commit 9114014cf4e6 ("genirq: Add mutex to irq desc to serialize request/free_irq()"), apparently inadvertantly so because the race is neither mentioned in the commit message nor was the code comment updated. Make up for that. Signed-off-by: Lukas Wunner Signed-off-by: Thomas Gleixner Cc: Bjorn Helgaas Cc: Mika Westerberg Cc: linux-pci@vger.kernel.org Link: https://lkml.kernel.org/r/32fc25aa35ecef4b2692f57687bb7fc2a57230e2.1529828292.git.lukas@wunner.de --- kernel/irq/manage.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c index 591cfe901162..123a227d3357 100644 --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c @@ -1025,10 +1025,7 @@ static int irq_thread(void *data) * This is the regular exit path. __free_irq() is stopping the * thread via kthread_stop() after calling * synchronize_irq(). So neither IRQTF_RUNTHREAD nor the - * oneshot mask bit can be set. We cannot verify that as we - * cannot touch the oneshot mask at this point anymore as - * __setup_irq() might have given out currents thread_mask - * again. + * oneshot mask bit can be set. */ task_work_cancel(current, irq_thread_dtor); return 0; @@ -1245,7 +1242,9 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new) /* * Protects against a concurrent __free_irq() call which might wait * for synchronize_irq() to complete without holding the optional - * chip bus lock and desc->lock. + * chip bus lock and desc->lock. Also protects against handing out + * a recycled oneshot thread_mask bit while it's still in use by + * its previous owner. */ mutex_lock(&desc->request_mutex);