From patchwork Fri Nov 18 00:05:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 21990 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp690500wrr; Thu, 17 Nov 2022 16:07:06 -0800 (PST) X-Google-Smtp-Source: AA0mqf49UB095VZWn0MQHLmlpBJSHv05Lck6tbI+OFGBCUCzsrw8rznanRA22uqySYX/XU2ejD7H X-Received: by 2002:a05:6402:5406:b0:467:4b3d:f2ed with SMTP id ev6-20020a056402540600b004674b3df2edmr4207244edb.101.1668730025866; Thu, 17 Nov 2022 16:07:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668730025; cv=none; d=google.com; s=arc-20160816; b=VlZxn1xxrS21lL3acX9z+3atx0VWNMJdFqdGtrtvu3PiRIqp7idT8vW1LBHKdvRFfd +4nTVGsbg/U/SQIY1P0dCTxYVONJJGwDGhxcC7YyY/qCOylepSQucCnKIC1dlQiRmu/V Tq1DnJc9F4AOpSOLEsAezVv4nkGJTOhGbikbhG1QBtptkPMZIb9At34Bnigw9XGW05tv s3X82+deXV+ChCkn9OGukXRjuXqFzTR8SfGjDBEQEYmjxDikqMbUYGDsk0DELdDKHfBj oIseO5EgB/s6mr3ObuvQLpGLrwV6RHkNKGDGhk86K56zfRwa1CFWDViipy8VLJ7ILM6t L/7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=PyyshX2MXtCgxFh5/yxvPHPhEZ9CUlXVS8URKYK9m/0=; b=Jpt5z5LXif6BHFU0f9l9vVW6ZnEXURpwkbJf038Gw2EFOXLVGrqU3WnxOa06xS8WVO kfcbDYMVHPeOHPfo9FTKqtSzvt893fTRcDpSXurik8apWvLFTpYc55s6wa3np6RXJykS r5uDTUID85MEMZDegUJ5zZaw26AGqORcEV0L8WL+xR4wNzJtnaUimXlYEf5wpsSI5EuQ eG7fx2ChSdRxjQaDyDKrKkj0NGxjrnbBcwvRnE6m7GD+xrcgAPT52sFy1lO2GvUC7YCT cFX/xnwClNykZpMzD2TCOeHm8AgM+p60uvx4t20iBcuk3CdgMHQ121vEikp+rXitY52o n/tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RjVMaBgD; 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=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g23-20020a170906349700b007ad812915c9si1455497ejb.581.2022.11.17.16.06.35; Thu, 17 Nov 2022 16:07:05 -0800 (PST) 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=@intel.com header.s=Intel header.b=RjVMaBgD; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235133AbiKRAFe (ORCPT + 99 others); Thu, 17 Nov 2022 19:05:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233270AbiKRAFa (ORCPT ); Thu, 17 Nov 2022 19:05:30 -0500 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74C7ABC0; Thu, 17 Nov 2022 16:05:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668729929; x=1700265929; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=hWL8ZNgUOuvv1B4SV56p3dDMPMbvsjEleV962v2qcqc=; b=RjVMaBgDDUqIB3RA8JHiiYYKXgzaF/Dm8V9C71i0jLSP8h8khC+XCr+n T8gZwQ5yv36gaA+29UvaxC8ndzzzEHGg+OyaIiTOJH1py68nvwhsjT+HT tmJiJs9e91MFG2uajznUD+JGZ2BqrLXOu1BId21OpDnrxvMQBwXWKonyH u6gdWwt9IP4FCdLrk9163NVysTjheBROnmnNKXNkzxJiQJxQssU2xuoNg gohLESHOCwNM7lY0twhvbxmr2Q/4K7t+5eJadzxijGBW3hndfrKnmD2xB 8DbXMV4wZi0zgvf87ErURkvO3wPzbzLCcSJ/yZ08y+duU2MYr23Zj7F4r A==; X-IronPort-AV: E=McAfee;i="6500,9779,10534"; a="300546400" X-IronPort-AV: E=Sophos;i="5.96,172,1665471600"; d="scan'208";a="300546400" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2022 16:05:28 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10534"; a="590814123" X-IronPort-AV: E=Sophos;i="5.96,172,1665471600"; d="scan'208";a="590814123" Received: from jmartin2-mobl.amr.corp.intel.com (HELO localhost) ([10.209.2.15]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Nov 2022 16:05:27 -0800 From: ira.weiny@intel.com To: Bjorn Helgaas , Dan Williams Cc: Ira Weiny , Bjorn Helgaas , Gregory Price , Jonathan Cameron , Lukas Wunner , Vishal Verma , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-cxl@vger.kernel.org Subject: [PATCH V2] PCI/DOE: Detect on stack work items automatically Date: Thu, 17 Nov 2022 16:05:24 -0800 Message-Id: <20221118000524.1477383-1-ira.weiny@intel.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749790255337548979?= X-GMAIL-MSGID: =?utf-8?q?1749790255337548979?= From: Ira Weiny Work item initialization needs to be done with either INIT_WORK_ONSTACK() or INIT_WORK() depending on how the work item is allocated. The callers of pci_doe_submit_task() allocate struct pci_doe_task on the stack and pci_doe_submit_task() incorrectly used INIT_WORK(). Jonathan suggested creating doe task allocation macros such as DECLARE_CDAT_DOE_TASK_ONSTACK().[1] The issue with this is the work function is not known to the callers and must be initialized correctly. A follow up suggestion was to have an internal 'pci_doe_work' item allocated by pci_doe_submit_task().[2] This requires an allocation which could restrict the context where tasks are used. Another idea was to have an intermediate step to initialize the task struct with a new call.[3] This added a lot of complexity. Lukas pointed out that object_is_on_stack() is available to detect this automatically. Use object_is_on_stack() to determine the correct init work function to call. [1] https://lore.kernel.org/linux-cxl/20221014151045.24781-1-Jonathan.Cameron@huawei.com/T/#m88a7f50dcce52f30c8bf5c3dcc06fa9843b54a2d [2] https://lore.kernel.org/linux-cxl/20221014151045.24781-1-Jonathan.Cameron@huawei.com/T/#m63c636c5135f304480370924f4d03c00357be667 [3] https://lore.kernel.org/all/20221115011943.1051039-1-ira.weiny@intel.com/ Cc: Bjorn Helgaas Cc: Dan Williams Reported-by: Gregory Price Reported-by: Jonathan Cameron Suggested-by: Lukas Wunner Signed-off-by: Ira Weiny --- Changes from V1 Update oneliner Use object_is_on_stack() to make this a simple fix --- drivers/pci/doe.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) base-commit: 30a0b95b1335e12efef89dd78518ed3e4a71a763 prerequisite-patch-id: dfea657e07f37aa9d7c3d477d68b07f64fe78721 prerequisite-patch-id: e27264e76e637214ee50cdab0e5854b223d44b4e diff --git a/drivers/pci/doe.c b/drivers/pci/doe.c index e402f05068a5..42de517022d9 100644 --- a/drivers/pci/doe.c +++ b/drivers/pci/doe.c @@ -19,6 +19,7 @@ #include #include #include +#include #define PCI_DOE_PROTOCOL_DISCOVERY 0 @@ -529,7 +530,10 @@ int pci_doe_submit_task(struct pci_doe_mb *doe_mb, struct pci_doe_task *task) return -EIO; task->doe_mb = doe_mb; - INIT_WORK(&task->work, doe_statemachine_work); + if (object_is_on_stack(&task->work)) + INIT_WORK_ONSTACK(&task->work, doe_statemachine_work); + else + INIT_WORK(&task->work, doe_statemachine_work); queue_work(doe_mb->work_queue, &task->work); return 0; }