Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp2664399imm; Sun, 24 Jun 2018 01:37:05 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKUtzvn3UG2uFnH/buJXgdfH5tM5btfb90qs9GLBYRkQPtBLj3cThsp8OXxTxC51zIjMgrG X-Received: by 2002:a65:4146:: with SMTP id x6-v6mr6899223pgp.221.1529829424962; Sun, 24 Jun 2018 01:37:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529829424; cv=none; d=google.com; s=arc-20160816; b=OxqJl/sIji8e9rq4GlXsaRw5k1hmENfUUfCMIdZn/PCw9kN7uGVFCJv3r/MBCzMZVs hIspioRml31vO+BEac/A6R9pQJA3nqHi3YX1gPqoZk+GXS4+F4cqGVJWAGxb6kUE+Xn6 1LaeGnI+Ek7lJrI2zixCWuXGHjidOd7i3w3M/FOl0S+/yOfqtdBzPL442OnI27yxf0tH ysORE/7iF66GMeTfWtyBslH0EVfhCZNoWhWSD8pVTd3ldQjG9yIxdElLnXkzOKo0jKyx OEpKyT0WEMrAC7CtqAF24i+YRi9eOyb93h5IT3g+c9C8IQNo9t5mS6FJUNhzon4BDeKW IUog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:date:from:message-id :arc-authentication-results; bh=OGRy0i1F/nongQpe9veIICx+xmO3TWXkAWKPrG+a7g8=; b=hed7ylW/7RnVLTomQVUFUzedkpvmg0yP6CtunZtxx5+TVLEahd/fSdQ6xwt/CzLRgj 14vven3pRraLHN2NXB3SfuJj/+qiXDEpHWG3mDJulW4llPurAuE+BRMHV7xSEhIk0cJi FqbhM3FHzUH7BZNuCCmaZD0cOwrsS+DCPv6oIgXJq1xBCbD1pfNSGQ6F421W4ISwuMNz g+xc3QhxzhDTK9kt11jdJhj/a/D+5VorwVvP50Ox02g4RhOchqnUFrKYubq2exYAnqcb vB81lc3blTCDZHzF9V4zNvRZSwamuY45O97hSxwCQRPH1v8YqLTYSMAMuycHpFjV+e3n nKsA== 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 f34-v6si11250715plf.495.2018.06.24.01.36.40; Sun, 24 Jun 2018 01:37:04 -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 S1751834AbeFXIfk (ORCPT + 99 others); Sun, 24 Jun 2018 04:35:40 -0400 Received: from mailout3.hostsharing.net ([176.9.242.54]:38451 "EHLO mailout3.hostsharing.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750984AbeFXIfi (ORCPT ); Sun, 24 Jun 2018 04:35:38 -0400 Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.hostsharing.net", Issuer "COMODO RSA Domain Validation Secure Server CA" (not verified)) by mailout3.hostsharing.net (Postfix) with ESMTPS id 050F8101E69BB; Sun, 24 Jun 2018 10:35:37 +0200 (CEST) Received: from localhost (unknown [89.246.108.87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by h08.hostsharing.net (Postfix) with ESMTPSA id 92574603E134; Sun, 24 Jun 2018 10:35:36 +0200 (CEST) X-Mailbox-Line: From 32fc25aa35ecef4b2692f57687bb7fc2a57230e2 Mon Sep 17 00:00:00 2001 Message-Id: <32fc25aa35ecef4b2692f57687bb7fc2a57230e2.1529828292.git.lukas@wunner.de> From: Lukas Wunner Date: Sun, 24 Jun 2018 10:35:18 +0200 Subject: [PATCH v2 1/2] genirq: Update code comments wrt recycled thread_mask To: Thomas Gleixner Cc: Bjorn Helgaas , Mika Westerberg , linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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"). But it wasn't until 2017 that it was fixed 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 --- 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); -- 2.17.1