Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp562683imm; Fri, 22 Jun 2018 01:11:19 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKT3nM83X11N/0MozXV8+5ZGQvyPj5VVpH1B2hOomg9NKUhXj6RnsaCfetjMRwg5pDaE8oY X-Received: by 2002:a63:2f04:: with SMTP id v4-v6mr489286pgv.33.1529655079631; Fri, 22 Jun 2018 01:11:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529655079; cv=none; d=google.com; s=arc-20160816; b=MK53Vzsdj0AqUa42Zoj+g4kUMYsztWdI+eJDPMl3OTYaZ/DgWzR8phMurzFJKKxaHF 1+YLoZ1vfmhTOl2MLlMcqdgZUa799dOl7dHzKK788rwsHDUlQce7kq7VeBdVTLUDMvJX bcaVdjz7vC/vAumXmGGghZhkbO46nDTJCg04K9W+fTQgJrDymc0h/ZsLcVyhvSEKsqg3 vEH+P2Lj5NChuq4WrKzDSbyHnnZyffO8AZMAa6sT1j3ju12PjEVnpRtnBHEAttpriwzR kYzMDGZ4y+NmSH9pHdoOMstnwN9hNvksrUjpucz6U8cUxKadZQssNYct+ToWHTWhRsR1 rfwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=mjgMaoOamBd89QxvFbv8ZUcJWwpFj1vByFLDvR8yUiY=; b=CirFcIybCPsozv4B9RTRRL9gaai9mPGVdp6FybNLgODDughDWQ2FOVCw/H7+s9n6Wa GCr0nluu81XqrpXYDOWGDiZ3p7HDC6OjzpQuJUWWI4bNPQoU1lFQZTdnuqJXZUBKiVWe x9ACfL6ET0a6B5R99++qfbhlOnbuDWHkEdIKi04xLV8BUjh5pOu302ik/vUc2vaZRZ4k Kv7NjO8GhlyDjN4Nv6PFhxBtsdA/YjRxShvTbikDkSE11z0x2tg6dFC74JfPDXc+46pS cwOTU6ho0H7xCKSQ8VW1WbxRhqbIkn3BcRo6EVGUkFI038F+NtR9VivzXe2FEVAl5wt3 uklg== 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 u8-v6si5776886pgr.578.2018.06.22.01.11.04; Fri, 22 Jun 2018 01:11:19 -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 S1754080AbeFVIJP (ORCPT + 99 others); Fri, 22 Jun 2018 04:09:15 -0400 Received: from bmailout2.hostsharing.net ([83.223.90.240]:51291 "EHLO bmailout2.hostsharing.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751258AbeFVIJM (ORCPT ); Fri, 22 Jun 2018 04:09:12 -0400 X-Greylist: delayed 465 seconds by postgrey-1.27 at vger.kernel.org; Fri, 22 Jun 2018 04:09:12 EDT 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 bmailout2.hostsharing.net (Postfix) with ESMTPS id 3F0782800B1DB; Fri, 22 Jun 2018 10:01:26 +0200 (CEST) Received: by h08.hostsharing.net (Postfix, from userid 100393) id D2A3C1C038; Fri, 22 Jun 2018 10:01:25 +0200 (CEST) Date: Fri, 22 Jun 2018 10:01:25 +0200 From: Lukas Wunner To: Thomas Gleixner 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() Message-ID: <20180622080125.GA13709@wunner.de> References: <8f770886632640321592873e4c902218d42c436b.1527194314.git.lukas@wunner.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Thanks, Lukas