Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1235787imm; Fri, 22 Jun 2018 12:46:57 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLuCL3wiHxOZSo+PYkslAve225+PaSyFoZQaGeKDzL6CE2X4syi7KwWCEU3neJv747wGMny X-Received: by 2002:a63:6a89:: with SMTP id f131-v6mr2591972pgc.311.1529696817455; Fri, 22 Jun 2018 12:46:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529696817; cv=none; d=google.com; s=arc-20160816; b=plQCWhto1TZs7/E3w3taZpBFZo8qT7LntDjiTtU+YssQXnQz3pu4w9oJtUURMTC+1D rlyUQ4cxP8+NwvDs9jpV6kjaoUaHyj91/rXr8OTzke/mOMm6SeopAXstZEToukmGeqEL MeQklQSOXl6hCHD2h+zZd2OScXhooytlKbiqyqpieJDtLuKX7qJ5IyA/DfCMhkNM2IWs bM+S37juPEUKdYCnl4ooDMR//DgRSAF7r25agN1YAeRKxXXYTWoJbVEQ9hYVs0yAq1dO 3KOYbGCXZP0shFimDXir87rEhAOoF6ifW/joWqux8aDWVhQODOyhVtg8mSu9aW9r/df2 lKag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date :arc-authentication-results; bh=aUimau7o17xF3LhGfI4jPYvHbMXM2E8npGg5IKZzcv4=; b=pJFqETp8+BI6lnVX4Op2gOC/NFxESUU67ieU6J4D7wLJgh4b/bkfneSwRXQmFg0va2 T38mV9XQJ/PSrtGJUh7FWjdhFMlf0UMOBmFd/GDTwV4FCWZfbMKYiDm0/kvW4/IRrZRz Gg5+ZtbJ6Vl62YzB3/93hs+oC670xO02k497UMmbHnCvGyzo53FAcUDSKDMue54LfF6R DWdS8sQOz20lbdFgpdZ6y4WDvg0UX2wNkdBfwpWsrunEfIuT5j5Xybc8Yj9UYT43BoCF jQfVfbwZdgc6SVvToF+/Y+jJcqCX4bWSb04dL5aHtMZHyjMGg1WYlx8kAcIcS4M/J9Wv 0wcA== 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 p20-v6si2031698pgb.195.2018.06.22.12.46.43; Fri, 22 Jun 2018 12:46:57 -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 S934541AbeFVTov (ORCPT + 99 others); Fri, 22 Jun 2018 15:44:51 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:42706 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934111AbeFVTot (ORCPT ); Fri, 22 Jun 2018 15:44:49 -0400 Received: from p4fea482e.dip0.t-ipconnect.de ([79.234.72.46] helo=nanos.glx-home) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1fWRzA-0002Lh-Pr; Fri, 22 Jun 2018 21:44:45 +0200 Date: Fri, 22 Jun 2018 21:44:44 +0200 (CEST) From: Thomas Gleixner To: Lukas Wunner cc: Bjorn Helgaas , Mika Westerberg , Sebastian Andrzej Siewior , linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org Subject: Re: [PATCH] genirq: Synchronize only with single thread on free_irq() In-Reply-To: <20180622080125.GA13709@wunner.de> Message-ID: References: <8f770886632640321592873e4c902218d42c436b.1527194314.git.lukas@wunner.de> <20180622080125.GA13709@wunner.de> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII 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 On Fri, 22 Jun 2018, Lukas Wunner wrote: > On Thu, Jun 21, 2018 at 10:21:44PM +0200, Thomas Gleixner wrote: > > On Thu, 24 May 2018, Lukas Wunner wrote: > > > static int irq_wait_for_interrupt(struct irqaction *action) > > > { > > > - set_current_state(TASK_INTERRUPTIBLE); > > > + for (;;) { > > > + set_current_state(TASK_INTERRUPTIBLE); > > > > > > - while (!kthread_should_stop()) { > > > + if (kthread_should_stop()) { > > > + /* may need to run one last time. */ > > > + if (test_and_clear_bit(IRQTF_RUNTHREAD, > > > + &action->thread_flags)) { > > > + __set_current_state(TASK_RUNNING); > > > + return 0; > > > + } > > > + __set_current_state(TASK_RUNNING); > > > + return -1; > > > + } > > > > > > if (test_and_clear_bit(IRQTF_RUNTHREAD, > > > &action->thread_flags)) { > > > @@ -766,10 +776,7 @@ static int irq_wait_for_interrupt(struct irqaction *action) > > > return 0; > > > } > > > schedule(); > > > - set_current_state(TASK_INTERRUPTIBLE); > > > } > > > - __set_current_state(TASK_RUNNING); > > > - return -1; > > > } > > > > > > /* > > > @@ -990,7 +997,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 > > > + * synchronize_hardirq(). 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 > > > @@ -1595,7 +1602,7 @@ static struct irqaction *__free_irq(struct irq_desc *desc, void *dev_id) > > > unregister_handler_proc(irq, action); > > > > > > /* Make sure it's not being used on another CPU: */ > > > - synchronize_irq(irq); > > > + synchronize_hardirq(irq); > > > > So after that, action can be freed and when the thread above tries to > > access it. Nice Use After Free. That needs more thought. > > No, after that, kthread_stop() is called which blocks until the IRQ > thread has completed. Only then is the action freed. Missed that. Fair enough. Thanks, tglx