Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp345102rwb; Fri, 18 Nov 2022 02:13:02 -0800 (PST) X-Google-Smtp-Source: AA0mqf5R6H1FHE5m76jHDrbLonlzZ4+WgXi28DUBp7arRxtYq/WWnApRiVLXAtT8OQ/LztnkujVr X-Received: by 2002:a17:90a:d718:b0:218:6b54:b788 with SMTP id y24-20020a17090ad71800b002186b54b788mr7972447pju.41.1668766382555; Fri, 18 Nov 2022 02:13:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668766382; cv=none; d=google.com; s=arc-20160816; b=lATh7pM7hAPT433PHwe5+yH0SgfofpaH93cgDYFfNvhwBprNLgceK4o04GqfooBO+z luD6CipweZct+T5KXwmgcNRGzXowy9yfWfLG6+Xpf1ImCUFcA9vYw54Qs+l2+13f8j89 vv2aASzQQtNiEyjxVmtVo1vj2QGHCm2C+Aq/FoHepy2om2vTYdsSmzy1LYoJnW619UwO GcaeUrF3yEoaT2tfrjDUG3R8FIIR/NOyNsorNYOm9lvmsXzz954fu4epziOf0OqiNpJb TzrrLxW7qWzdHVqL/kbkjae/EWZpcBz1K3BfwFLEiaGY0QkkXwe1ZEiXSL/c79hq3yel lh+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=oouyc3E2/kTKEoSw0l4+KRMujxJd0Y4gwMIe9x4F9Po=; b=Adh+r3m5pc/Z0WL3gsANLkCEYodGlK/6gnDYr0oA+wt5W29aWhBJtWHfgsIoW5Uq4D rq7wlCyazLXp0EUjHa1stgKoxornUrn1AFYkPrPnMI7UNyojLjtRsUPMxWdzphL0T0tY YWFRnqzToSN0JX8RKHPaq+nWo6sg1F+2EUVwxRlpSd+EIQ9dxvS6ZeHInCJ06PRFsqHZ 4jX61V+E3jYhHtFkVoBd9xtGIaWPZ90T73FPtjO/9HsWvVonwhhQgKI6KPo7EOEIV9p6 dTs1VwKd8QsKC3eKCzAOfLsuyxqr5f9Bl0alCZRJrhD4DasDzFwbZ+hIrLCUWMp8UGPi 3RHQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kb11-20020a17090ae7cb00b0020d9f17b911si8307373pjb.99.2022.11.18.02.12.51; Fri, 18 Nov 2022 02:13:02 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241893AbiKRJUs convert rfc822-to-8bit (ORCPT + 91 others); Fri, 18 Nov 2022 04:20:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241885AbiKRJUn (ORCPT ); Fri, 18 Nov 2022 04:20:43 -0500 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E83B915723 for ; Fri, 18 Nov 2022 01:20:41 -0800 (PST) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-127-s_i65QyxOm-BfoHKhLWIYw-1; Fri, 18 Nov 2022 09:20:38 +0000 X-MC-Unique: s_i65QyxOm-BfoHKhLWIYw-1 Received: from AcuMS.Aculab.com (10.202.163.6) by AcuMS.aculab.com (10.202.163.6) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Fri, 18 Nov 2022 09:20:38 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.044; Fri, 18 Nov 2022 09:20:38 +0000 From: David Laight To: "'ira.weiny@intel.com'" , Bjorn Helgaas , Dan Williams CC: 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: RE: [PATCH V2] PCI/DOE: Detect on stack work items automatically Thread-Topic: [PATCH V2] PCI/DOE: Detect on stack work items automatically Thread-Index: AQHY+uF8IwLsQKEiakO+LlTXtrnK365EZJiQ Date: Fri, 18 Nov 2022 09:20:38 +0000 Message-ID: References: <20221118000524.1477383-1-ira.weiny@intel.com> In-Reply-To: <20221118000524.1477383-1-ira.weiny@intel.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,PDS_BAD_THREAD_QP_64, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 From: ira.weiny@intel.com > Sent: 18 November 2022 00:05 > > 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. This is all a bit strange. The 'onstack' flag is needed for the diagnostic check: is_on_stack = object_is_on_stack(addr); if (is_on_stack == onstack) return; pr_warn(...); WARN_ON(1); So setting the flag to the location of the buffer just subverts the check. It that is sane there ought to be a proper way to do it. OTOH using an on-stack structure for INIT_WORK seems rather strange. Since the kernel thread must sleep waiting for the 'work' to complete why not just perform the required code there. Also you really don't want to OOPS with anything from the stack linked into global kernel data structures. While wait queues are pretty limited in scope and probably ok, this looks like a big accident waiting to happen. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)