Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp344001rwb; Thu, 27 Jul 2023 13:44:38 -0700 (PDT) X-Google-Smtp-Source: APBJJlGThPFvoKiLp8XoablZGYCzZYVcz5gYzurn42c0LfdWg8IvyD0iBernc2jzl8dGMVCqtFxP X-Received: by 2002:a17:903:1210:b0:1b7:f443:c7f8 with SMTP id l16-20020a170903121000b001b7f443c7f8mr437067plh.15.1690490677840; Thu, 27 Jul 2023 13:44:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690490677; cv=none; d=google.com; s=arc-20160816; b=UEUmfdcGumLLvJ6QpA+HPPnDQq1zeoNDrc3auIBBXhQuUbdMFHSuKiFK1QEgU7lVgy YOw4prsCghK4LrwVf9MifOUzZQvX8a7u0C6W3X//+SiNZQmXZpuY/janXiMHLgHPGrgy anEVIR5eAXeFWihF2UC6m+1SeZnX1jf6sqXc/9MI4TTUZpBYNc/ZmYvRRQ9M9TPs2HhQ cffjApZfUqXeUEzfhuXxz7HD+P03i8lpQIiXRrPUKVZYrGBEm1l89ySViw+JkGklfqe8 T3eDAo347O/FReOHpPTAisbBE4+F6Di+XHRsXxCt628zqbsVVQu6uw0f0MrJ67ZcIphb XZqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=Fq1uv7dMr3ZuT9wDGvaRY4ANvAe84czlPLuNsNaYPzg=; fh=j1JDH73fcWB4Blred2oEpdEDMR/EnNf6YcbeNWaU9GU=; b=dsTPqUNfTaIU3fFaaK74WNBsrbIdF4OMKCMEQCIu3RMu+ce1j6FFy9jj54HBAzygKw gqz7g5Xn+irSV7QGMv2cgMIRQKc9PnlIUkOuDhX4cFLDWmH6WnV3ptM+6NAXrjPd6L1F 80GDCfXWZD7rlcA5y5/Sc1ph1cxxOsmf0XQm/NqD8DAwyYC8dJ30kozY3BzMwfNggP4x /NnT6OCWu5qSXttKZu3wH4YUIDdZ5f8JrrrNbucL+jiC1xav8dGx8ziYAQHBLsl0WjG7 dA/qRpCDgalSbE1XkQ4R3A1wp55bYEx88/rjxjYsYr6hKORRw92n+mrmlCnieUBmADup EPaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=niPNNtu7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kg14-20020a170903060e00b001bb7d55d15csi1729959plb.284.2023.07.27.13.44.25; Thu, 27 Jul 2023 13:44:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=niPNNtu7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232774AbjG0UV4 (ORCPT + 99 others); Thu, 27 Jul 2023 16:21:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229487AbjG0UVy (ORCPT ); Thu, 27 Jul 2023 16:21:54 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F15719BA; Thu, 27 Jul 2023 13:21:53 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id CD06461F2D; Thu, 27 Jul 2023 20:21:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7EBEC433C7; Thu, 27 Jul 2023 20:21:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690489312; bh=3rw7ZIN3BKsO676ed+02hCwwOMbF4a1g3XcYswtgriM=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=niPNNtu7vCRsKPXg3YUeFLFf07Onh1mbdg8Q/7inkmKkPSokapGpJhLuNcdk+hBfw 4JlitXrp3JNPQKAw+3tJje1+Jah4cZ6QQlBZfS5vJPrUViev9FPqmQ9ympRdgg7oTD 7cL2Wun/TREvTm4CmpMz8Ezu0+GjORpi/7T9i/4uVxJ+WaCCPACWd4qpWV8C86aeK7 in0qEkY2nEl3B2O7MSHXcCJ4F6BaxGGj3uI266IuKngQhSnDHN1dXmUUUy0mQQuvot ogM5SaW5SMb3dhNaPlntdVspMkDT6CydUgFxqp5LHomYbo4x1TXI8/0pgruVF+fGFq Epa/3HqT+6NVA== Date: Thu, 27 Jul 2023 15:21:49 -0500 From: Bjorn Helgaas To: Ira Weiny Cc: Bjorn Helgaas , Dan Williams , Jonathan Cameron , Lukas Wunner , Davidlohr Bueso , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] PCI/DOE: Fix destroy_work_on_stack() race Message-ID: <20230727202149.GA793572@bhelgaas> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230726-doe-fix-v1-1-af07e614d4dd@intel.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 26, 2023 at 11:29:42AM -0700, Ira Weiny wrote: > The following debug object splat was observed in testing. > > [ 14.061937] ------------[ cut here ]------------ > [ 14.063899] ODEBUG: free active (active state 0) object: 0000000097d23782 object type: work_struct hint: doe_statemachine_work+0x0/0x510 > [ 14.067480] WARNING: CPU: 1 PID: 71 at lib/debugobjects.c:514 debug_print_object+0x7d/0xb0 > ... > [ 14.080951] Workqueue: pci 0000:36:00.0 DOE [1 doe_statemachine_work > [ 14.083485] RIP: 0010:debug_print_object+0x7d/0xb0 > ... > [ 14.116231] Call Trace: > [ 14.117652] > [ 14.118958] ? debug_print_object+0x7d/0xb0 > [ 14.120782] ? __warn+0x7d/0x130 > [ 14.122399] ? debug_print_object+0x7d/0xb0 > [ 14.123746] ? report_bug+0x18d/0x1c0 > [ 14.125025] ? handle_bug+0x3c/0x80 > [ 14.126506] ? exc_invalid_op+0x13/0x60 > [ 14.127796] ? asm_exc_invalid_op+0x16/0x20 > [ 14.129380] ? debug_print_object+0x7d/0xb0 > [ 14.130688] ? debug_print_object+0x7d/0xb0 > [ 14.131997] ? __pfx_doe_statemachine_work+0x10/0x10 > [ 14.133597] debug_object_free.part.0+0x11b/0x150 > [ 14.134940] doe_statemachine_work+0x45e/0x510 > [ 14.136348] process_one_work+0x1d4/0x3c0 > ... > [ 14.161484] > [ 14.162434] ---[ end trace 0000000000000000 ]--- > > This occurs because destroy_work_on_stack() was called after signaling > the completion in the calling thread. This creates a race between > destroy_work_on_stack() and the task->work struct going of scope in the > pci_doe(). > > Signal the work complete after destroying the work struct. This is safe > because signal_task_complete() is the final thing the work item does and > the workqueue code is careful not to access the work struct after. > > Fixes: abf04be0e707 ("PCI/DOE: Fix memory leak with CONFIG_DEBUG_OBJECTS=y") > Cc: Lukas Wunner > Signed-off-by: Ira Weiny Thanks, applied to pci/misc with Lukas' reviewed-by and Dan's ack for v6.6. I edited out the timestamps and some of the call trace from the splat because they didn't seem relevant. > --- > drivers/pci/doe.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/pci/doe.c b/drivers/pci/doe.c > index 1b97a5ab71a9..e3aab5edaf70 100644 > --- a/drivers/pci/doe.c > +++ b/drivers/pci/doe.c > @@ -293,8 +293,8 @@ static int pci_doe_recv_resp(struct pci_doe_mb *doe_mb, struct pci_doe_task *tas > static void signal_task_complete(struct pci_doe_task *task, int rv) > { > task->rv = rv; > - task->complete(task); > destroy_work_on_stack(&task->work); > + task->complete(task); > } > > static void signal_task_abort(struct pci_doe_task *task, int rv) > > --- > base-commit: 20ea1e7d13c1b544fe67c4a8dc3943bb1ab33e6f > change-id: 20230726-doe-fix-f57943f9ea82 > > Best regards, > -- > Ira Weiny >