From patchwork Thu Jul 15 19:41:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Widawsky X-Patchwork-Id: 12380815 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA0EFC636CA for ; Thu, 15 Jul 2021 19:49:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 95786613CA for ; Thu, 15 Jul 2021 19:49:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243936AbhGOTwm (ORCPT ); Thu, 15 Jul 2021 15:52:42 -0400 Received: from mga02.intel.com ([134.134.136.20]:23361 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344486AbhGOTtj (ORCPT ); Thu, 15 Jul 2021 15:49:39 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10046"; a="197803805" X-IronPort-AV: E=Sophos;i="5.84,243,1620716400"; d="scan'208";a="197803805" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jul 2021 12:41:34 -0700 X-IronPort-AV: E=Sophos;i="5.84,243,1620716400"; d="scan'208";a="489564799" Received: from cherrera-mobl1.amr.corp.intel.com (HELO bad-guy.kumite) ([10.252.135.149]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jul 2021 12:41:34 -0700 From: Ben Widawsky To: linux-cxl@vger.kernel.org Cc: Ben Widawsky , Alison Schofield , Dan Williams , Ira Weiny , Jonathan Cameron , Vishal Verma Subject: [PATCH 5/6] cxl: Pass fops and shutdown to memdev creation Date: Thu, 15 Jul 2021 12:41:24 -0700 Message-Id: <20210715194125.898305-6-ben.widawsky@intel.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715194125.898305-1-ben.widawsky@intel.com> References: <20210715194125.898305-1-ben.widawsky@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org Drivers that use cxl_core for registering a cxl_memdev will likely require synchronization with the core for shutdown so as to not race against the device going away. The main example currently is with the ioctl interface. Through the duration of the ioctl it's expected that the underlying memdev will not disappear. Additionally, it may be desirable to have the fops be passed along as well for drivers which do not want the standard handler for the character device's ioctl. As memdev is being migrated to core, this separation must be made. Signed-off-by: Ben Widawsky --- drivers/cxl/mem.h | 2 ++ drivers/cxl/pci.c | 23 +++++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/drivers/cxl/mem.h b/drivers/cxl/mem.h index 2092f86beeb8..2b7481376621 100644 --- a/drivers/cxl/mem.h +++ b/drivers/cxl/mem.h @@ -42,12 +42,14 @@ extern int cxl_mem_major; * @cdev: char dev core object for ioctl operations * @cxlm: pointer to the parent device driver data * @id: id number of this memdev instance. + * @shutdown: Optional function to call on memory device shutdown. */ struct cxl_memdev { struct device dev; struct cdev cdev; struct cxl_mem *cxlm; int id; + void (*shutdown)(struct cxl_memdev *cxlmd); }; /** diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c index 6f10b19c9c83..418ae0eac188 100644 --- a/drivers/cxl/pci.c +++ b/drivers/cxl/pci.c @@ -1293,11 +1293,13 @@ static void cxl_memdev_unregister(void *_cxlmd) struct device *dev = &cxlmd->dev; cdev_device_del(&cxlmd->cdev, dev); - cxl_memdev_shutdown(cxlmd); + if (cxlmd->shutdown) + cxlmd->shutdown(cxlmd); put_device(dev); } -static struct cxl_memdev *cxl_memdev_alloc(struct cxl_mem *cxlm) +static struct cxl_memdev *cxl_memdev_alloc(struct cxl_mem *cxlm, + const struct file_operations *fops) { struct pci_dev *pdev = cxlm->pdev; struct cxl_memdev *cxlmd; @@ -1323,7 +1325,7 @@ static struct cxl_memdev *cxl_memdev_alloc(struct cxl_mem *cxlm) device_set_pm_not_required(dev); cdev = &cxlmd->cdev; - cdev_init(cdev, &cxl_memdev_fops); + cdev_init(cdev, fops); return cxlmd; err: @@ -1331,15 +1333,17 @@ static struct cxl_memdev *cxl_memdev_alloc(struct cxl_mem *cxlm) return ERR_PTR(rc); } -static struct cxl_memdev *devm_cxl_add_memdev(struct device *host, - struct cxl_mem *cxlm) +static struct cxl_memdev * +devm_cxl_add_memdev(struct device *host, struct cxl_mem *cxlm, + const struct file_operations *fops, + void (*shutdown)(struct cxl_memdev *cxlmd)) { struct cxl_memdev *cxlmd; struct device *dev; struct cdev *cdev; int rc; - cxlmd = cxl_memdev_alloc(cxlm); + cxlmd = cxl_memdev_alloc(cxlm, fops); if (IS_ERR(cxlmd)) return cxlmd; @@ -1362,6 +1366,7 @@ static struct cxl_memdev *devm_cxl_add_memdev(struct device *host, rc = devm_add_action_or_reset(host, cxl_memdev_unregister, cxlmd); if (rc) return ERR_PTR(rc); + cxlmd->shutdown = shutdown; return cxlmd; err: @@ -1369,7 +1374,8 @@ static struct cxl_memdev *devm_cxl_add_memdev(struct device *host, * The cdev was briefly live, shutdown any ioctl operations that * saw that state. */ - cxl_memdev_shutdown(cxlmd); + if (shutdown) + shutdown(cxlmd); put_device(dev); return ERR_PTR(rc); } @@ -1610,7 +1616,8 @@ static int cxl_mem_probe(struct pci_dev *pdev, const struct pci_device_id *id) if (rc) return rc; - cxlmd = devm_cxl_add_memdev(&pdev->dev, cxlm); + cxlmd = devm_cxl_add_memdev(&pdev->dev, cxlm, &cxl_memdev_fops, + cxl_memdev_shutdown); if (IS_ERR(cxlmd)) return PTR_ERR(cxlmd);