Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp32933imm; Thu, 21 Jun 2018 13:22:45 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLYlVz+nEclqJdIEqBnz/syO0qjGox/kyL0xpPDsunoG4Bph/vQFiXG/27Wjwj5pt4S8clG X-Received: by 2002:a65:6103:: with SMTP id z3-v6mr19453105pgu.125.1529612565538; Thu, 21 Jun 2018 13:22:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529612565; cv=none; d=google.com; s=arc-20160816; b=V/KQGnmUehNgSh63q218oMhePl6wGIHJrjKNgOBf5l6dC0Kh+vKkWg6py0O0zIsvCF d1AjeXOExTurzEvPvVXXfo3jM/X0/+3Nly35mMGDg6FIjQ0ceOzF9OC6xsbgN+NnhI+/ GIxKyG9rn9pa9PCp7LoIzaD6MQnfOAKYIhMCcG+bTIFJ5nGu+QilrzicPhWFwh9F8nMM Y2pfcIlpVAxC6uhz+W3vzqM6zNNoimwTxuvhcQV34s58P1JSs8g7E7AfaNA6Tl01WRt9 g5m7ued9YFiKWV5CK0m/w2437j++EBac7jUj/56dixi84FQlP+O51Oy8RwcxSKDrXrGw gzug== 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=iMa+FmD5+ZJlcHDoyBh5vodLTfWPvzVjPG/5xdabMec=; b=I5CH4nOkLlyw1WRcgqC+PRjtIgJ+fTmyt0+3J3AvI+rKMNfBdBDCozMpSJ5Cu5EvE+ rU9L7kr9uHFGMYOkTMc0AGddAocOU8JIVBvaZUYdDBb4ODJiZpiA7StWJi2MBxwVvwvT DIbbe5uyGgdJmRXXfOdZpMQpLp1nZNyUzzK3D23FJKiaXb8XEYfr+samw6rAinKmQuP8 ChKdaCjlJJsX6qrza9Go5Z5UCdembTjmhOOHv4NZrrGnMiFt3aqRGX69DajpcNzhN5iL 91rbvOheFi29tgIpqzSAAegN4BWvoD2gcLooK001FuqgUvdFKI+ytJev3jmwqxddHqKo ODKA== 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 1-v6si5403413plj.411.2018.06.21.13.22.31; Thu, 21 Jun 2018 13:22:45 -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 S933248AbeFUUVu (ORCPT + 99 others); Thu, 21 Jun 2018 16:21:50 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:39738 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932686AbeFUUVt (ORCPT ); Thu, 21 Jun 2018 16:21:49 -0400 Received: from p4fea482e.dip0.t-ipconnect.de ([79.234.72.46] helo=nanos) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1fW65R-00042S-8x; Thu, 21 Jun 2018 22:21:45 +0200 Date: Thu, 21 Jun 2018 22:21: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: <8f770886632640321592873e4c902218d42c436b.1527194314.git.lukas@wunner.de> Message-ID: References: <8f770886632640321592873e4c902218d42c436b.1527194314.git.lukas@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 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. Thanks, tglx