Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp5168040ioo; Tue, 31 May 2022 22:45:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwY85GP6YcK8AnOE+y2NYNnyFhlZs6RLBUlYk27cxtA6wUq4oBFWkCWKJUdLmKdsPjN705M X-Received: by 2002:a17:907:1c25:b0:6fe:e07a:9d4d with SMTP id nc37-20020a1709071c2500b006fee07a9d4dmr39887970ejc.310.1654062344868; Tue, 31 May 2022 22:45:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654062344; cv=none; d=google.com; s=arc-20160816; b=AsriwivXPhh36p/mmxUpqlMwXHXvoY9a9BL4YPkxyjp6F2Bsco+rIJ5ZfLuqT4oDZw hsJqnn4ySLm1Kd52FkdfLwxL/EvfP18O9B5d1aeTz4Pz/0obQeTFDLWEzJRrPbX0n7C8 Dm7A7LUZKN0TEUpi8VBUABCKhp5fSr6LBbG2f5DAwVnoF1+awShmJpmykWXgMgxB2Jjh 2/QzpEBvDGzRY1X7pvMIoI8ButFRXrf7ikq74Pb8zgl7grYCNTnrhz4HYtJh7yN5TutL uk2Vf8xZyP5XZvteVW4jMULv9aZa5byfjywMhHNdZN4LQa474toRZoYemm1Ua06gwoGL 2IJw== 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 :references:message-id:subject:cc:to:from:date:dkim-signature; bh=uqoSIbCtua+IC7RBkn+r4d0GMW9KAubTX5HTLEAODlA=; b=KCWrMNVKoBzUWJv2xzJ5kiPx6figmBTxwWCT3FmIFH9FWGoyArFdB698AxjZnOpSfC 7HACussKmAwnGGe0krSCYzjaXsR0Ixb994Xor4k3YWAM0wnC5BIVPBflQg/da/c6Dum+ Aa0L+gLlih/uQqV8a2jDV1PYM/VcUKhU4xwql/yE7I0dkxmgMPhgtc4BZs2lh3MG25+Y rcIsL9UICTavKfZz1GsawJPatj/TYfeAtYMkBNKDyWwVhHjN3rUoJJ+Ni04lVgTt+fUu GCkPyVSQFpfLpO5zaPUZ8finPuY+58H/KseEeJyxB3b0kC6Un/P4xK5d/I7cW059zNAD dF9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="h/lpOwb2"; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w26-20020a170906b19a00b006ff453083b2si837566ejy.127.2022.05.31.22.45.08; Tue, 31 May 2022 22:45:44 -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=@intel.com header.s=Intel header.b="h/lpOwb2"; 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 S238560AbiFAExx (ORCPT + 99 others); Wed, 1 Jun 2022 00:53:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229831AbiFAExv (ORCPT ); Wed, 1 Jun 2022 00:53:51 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5BEF9D06A; Tue, 31 May 2022 21:53:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1654059230; x=1685595230; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=q2BPmfI7+VWxsW5xSu/b2ZDNOg6Dpg5wYC/5y7r5YRU=; b=h/lpOwb2KcUeQDeOo0cLgN3QgChP+EjKbVNym5MViqZYdb/k/SdGdcKe ADYZITfrkt/+LGNxfm4uMfuPjUe+x+kXV5qfH8LX3uQZw9GvbRuRahw5G c+dwOmCS87YvpAhHdEk2AcH3XZcFoqXm0poSgH2sy4hrTZIvPrnsRMz+k jdEgEfrTAPIdFijL+7bL20gH3v/n5WUt6HCDSHTcisSYwi1MVaVRpMiq6 KN/owp6lOezE0KSGIJKApXB1ek9R1ZxT6ihiqB3hR+IA7WchoTE0QvWur YwPkVOLykacArRX9yJmMVpQLAx7C2eprIE94LMgCLkgtnB0byKso3yJbi g==; X-IronPort-AV: E=McAfee;i="6400,9594,10364"; a="275481252" X-IronPort-AV: E=Sophos;i="5.91,266,1647327600"; d="scan'208";a="275481252" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2022 21:53:50 -0700 X-IronPort-AV: E=Sophos;i="5.91,266,1647327600"; d="scan'208";a="576753246" Received: from mdossant-mobl1.amr.corp.intel.com (HELO localhost) ([10.212.154.135]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2022 21:53:50 -0700 Date: Tue, 31 May 2022 21:53:49 -0700 From: Ira Weiny To: Davidlohr Bueso Cc: Dan Williams , Bjorn Helgaas , Jonathan Cameron , Alison Schofield , Vishal Verma , Dave Jiang , Ben Widawsky , linux-kernel@vger.kernel.org, linux-cxl@vger.kernel.org, linux-pci@vger.kernel.org, a.manzanares@samsung.com Subject: Re: [PATCH v9 3/9] PCI: Create PCI library functions in support of DOE mailboxes. Message-ID: References: <20220531152632.1397976-1-ira.weiny@intel.com> <20220531152632.1397976-4-ira.weiny@intel.com> <20220531172507.5ert5tgwellpe7fx@offworld> <20220531175652.qog7xaqmypy36whu@offworld> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220531175652.qog7xaqmypy36whu@offworld> X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,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 Tue, May 31, 2022 at 10:56:52AM -0700, Davidlohr Bueso wrote: > On Tue, 31 May 2022, Davidlohr Bueso wrote: > > > On Tue, 31 May 2022, ira.weiny@intel.com wrote: > > > > > +static void doe_statemachine_work(struct work_struct *work) > > > +{ > > > + struct delayed_work *w = to_delayed_work(work); > > > + struct pci_doe_mb *doe_mb = container_of(w, struct pci_doe_mb, > > > + statemachine); > > > + struct pci_dev *pdev = doe_mb->pdev; > > > + int offset = doe_mb->cap_offset; > > > + struct pci_doe_task *task; > > > + u32 val; > > > + int rc; > > > + > > > + mutex_lock(&doe_mb->task_lock); > > > + task = doe_mb->cur_task; > > > + mutex_unlock(&doe_mb->task_lock); > > > > Instead of a mutex, would it be better to use a rwsem here to protect > > the state machine and allow for concurrent reads for the work callback? > > It is a general interface and a trivial change, but not sure how much > > performance is cared about. > > Actually why is this a sleeping lock at all? Afaict all critical regions > are short and just deal with loads and stores of oe_mb->task_lock (and > pci_doe_submit_task also checks the doe_mb->flags with the lock held). > This could be a spinlock or similarly a rwlock. This is a good point... My only excuse is that task_lock used to lock more than just the cur_task so I suspect that I just kept it as a mutex after a rework at some point with out thinking about this deeper. Thinking about it I don't see a benefit to a rwlock. We don't have multiple readers. But I've just looked at this code again and I'm not sure that the exclusion is correct with regard to the state machine. I think the state needs to be IDLE before retire_cur_task() is called or the state machine could be in an invalid state when the next task runs. I think there is a bug in the DOE_WAIT_ABORT* cases when not error and not busy. In that case there is a race with the next task getting run the state being DOE_WAIT_ABORT*. In the timeout case we will call the mailbox dead. I can't remember if Jonathan originally locked the state machine or the task or both. I think I have fixed it but, I'll look at it again in the morning. Thanks, Ira > > Thanks, > Davidlohr