From patchwork Fri Feb 10 09:06:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 13135554 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8E91C05027 for ; Fri, 10 Feb 2023 09:06:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 66BF66B011F; Fri, 10 Feb 2023 04:06:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5C7776B0121; Fri, 10 Feb 2023 04:06:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 465BB6B0122; Fri, 10 Feb 2023 04:06:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 1998F6B011F for ; Fri, 10 Feb 2023 04:06:17 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id B6BD8C1488 for ; Fri, 10 Feb 2023 09:06:16 +0000 (UTC) X-FDA: 80450800752.01.CD7511E Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by imf19.hostedemail.com (Postfix) with ESMTP id 93B5E1A001A for ; Fri, 10 Feb 2023 09:06:14 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=FoSVZzCp; spf=pass (imf19.hostedemail.com: domain of dan.j.williams@intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676019974; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=oA+zrlhsxTicB4JREMkAp7hINgQp3GNpARD4FxAUpgs=; b=Xir3Eg2AGrX+As2LHOacQ4Yy8jLK4YM6heJhhwiTvZDAmekWBuwrNkklK5UFHKMOgH/sdF DrtSdYiNsDFZKxQPJCZqQBMhvemM9pddU4tHtLfq82+gygyiAlm4VvOeYm3Vw9j7cGt7Zk nI+2yq7JeMtRsiiD0p8+x+jSx7+hReo= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=FoSVZzCp; spf=pass (imf19.hostedemail.com: domain of dan.j.williams@intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676019974; a=rsa-sha256; cv=none; b=WwbUuyfW28t1m1Nqp+4+FtdZ6hkKydM23jUETRx/QNU+IItQh8kvHxrBNg0qQc5j7p8nIA 0vDOxlIUnzuuKvDPEGnzMfnI/YyWs4Oq8NGHfS8D7RNuzvv/SoNw1bETQ744whxB2geMQk hWDYMtjOOLKjtNN6AMlekkbRbPViBSo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1676019974; x=1707555974; h=subject:from:to:cc:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=s+JhIpX+g9sjvv5ZiADOIwQseU67ppQ0dtunIobOaPU=; b=FoSVZzCpEuK93BjViEPsgOsWDT/V0KFsVcwyCVR6CBKAMDaTxb+C/h7a gZ0S78N3FUi59hasDyfFVACMrsfnkwDsh73jTTmKZRgmD9Dkjx4OHExop gSR57dlpmyHSy2BOcUz/NGxK7emo4RrAKaUNttBkIv+XJ2dxs78lWMmHG f05pycl7xkdf4l5ldFoxBq9TKIy5NZVffpioCmLywXS2U7C4J66+OCVUD 7eW0paqHmG2DX76EckYUVhfICaB8+wDNcAY/Ac8AKmx5ND3U8MOxB10BS 8v40f6XJ2NiL5f3PkuHxIkVHO6k521ZY4OG/GNbouBHuxWUVbhAnp4AIp w==; X-IronPort-AV: E=McAfee;i="6500,9779,10616"; a="416600043" X-IronPort-AV: E=Sophos;i="5.97,286,1669104000"; d="scan'208";a="416600043" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Feb 2023 01:06:04 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10616"; a="669930234" X-IronPort-AV: E=Sophos;i="5.97,286,1669104000"; d="scan'208";a="669930234" Received: from hrchavan-mobl.amr.corp.intel.com (HELO dwillia2-xfh.jf.intel.com) ([10.209.46.42]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Feb 2023 01:06:04 -0800 Subject: [PATCH v2 07/20] cxl/region: Refactor attach_target() for autodiscovery From: Dan Williams To: linux-cxl@vger.kernel.org Cc: Vishal Verma , Dave Jiang , Ira Weiny , Jonathan Cameron , Fan Ni , dave.hansen@linux.intel.com, linux-mm@kvack.org, linux-acpi@vger.kernel.org Date: Fri, 10 Feb 2023 01:06:04 -0800 Message-ID: <167601996393.1924368.2202255054618600069.stgit@dwillia2-xfh.jf.intel.com> In-Reply-To: <167601992097.1924368.18291887895351917895.stgit@dwillia2-xfh.jf.intel.com> References: <167601992097.1924368.18291887895351917895.stgit@dwillia2-xfh.jf.intel.com> User-Agent: StGit/0.18-3-g996c MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: co1hoe7kmb3wfkqqzez1gj1h3tttbtib X-Rspamd-Queue-Id: 93B5E1A001A X-HE-Tag: 1676019974-90986 X-HE-Meta: U2FsdGVk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EuT71vkahvyBr6ZrbbUAuL6CrSiiUS5jxPOMoIHxLgnWRWV6lE139nvlgSgx1O60H16fqtj5/iTcZnjoxqnBbp56eRy/BaUQRnYxdHtCiHHOFryTLRpSjT/OOVodtIRmGYHVJCo89cgqMVAmN5EW8fLp5LX8zK1XnjSKNHOvSqDCbEgDyOFbivjD+I7NllFdTraP+hlAIic6g1UCioNLckGZXNKCiLjCnlgzmvZ2e17ht49Bc+rM/6Yp7C3V+PA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Region autodiscovery is the process of kernel creating 'struct cxl_region' object to represent active CXL memory ranges it finds already active in hardware when the driver loads. Typically this happens when platform firmware establishes CXL memory regions and then publishes them in the memory map. However, this can also happen in the case of kexec-reboot after the kernel has created regions. In the autodiscovery case the region creation process starts with a known endpoint decoder. Refactor attach_target() into a helper that is suitable to be called from either sysfs, for runtime region creation, or from cxl_port_probe() after it has enumerated all endpoint decoders. The cxl_port_probe() context is an async device-core probing context, so it is not appropriate to allow SIGTERM to interrupt the assembly process. Refactor attach_target() to take @cxled and @state as arguments where @state indicates whether waiting from the region rwsem is interruptible or not. No behavior change is intended. Reviewed-by: Vishal Verma Reviewed-by: Dave Jiang Reviewed-by: Ira Weiny Reviewed-by: Jonathan Cameron Tested-by: Fan Ni Link: https://lore.kernel.org/r/167564538227.847146.16305045998592488364.stgit@dwillia2-xfh.jf.intel.com Signed-off-by: Dan Williams --- drivers/cxl/core/region.c | 47 +++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index e440db8611a4..040bbd39c81d 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -1422,31 +1422,25 @@ void cxl_decoder_kill_region(struct cxl_endpoint_decoder *cxled) up_write(&cxl_region_rwsem); } -static int attach_target(struct cxl_region *cxlr, const char *decoder, int pos) +static int attach_target(struct cxl_region *cxlr, + struct cxl_endpoint_decoder *cxled, int pos, + unsigned int state) { - struct device *dev; - int rc; - - dev = bus_find_device_by_name(&cxl_bus_type, NULL, decoder); - if (!dev) - return -ENODEV; - - if (!is_endpoint_decoder(dev)) { - put_device(dev); - return -EINVAL; - } + int rc = 0; - rc = down_write_killable(&cxl_region_rwsem); + if (state == TASK_INTERRUPTIBLE) + rc = down_write_killable(&cxl_region_rwsem); + else + down_write(&cxl_region_rwsem); if (rc) - goto out; + return rc; + down_read(&cxl_dpa_rwsem); - rc = cxl_region_attach(cxlr, to_cxl_endpoint_decoder(dev), pos); + rc = cxl_region_attach(cxlr, cxled, pos); if (rc == 0) set_bit(CXL_REGION_F_INCOHERENT, &cxlr->flags); up_read(&cxl_dpa_rwsem); up_write(&cxl_region_rwsem); -out: - put_device(dev); return rc; } @@ -1484,8 +1478,23 @@ static size_t store_targetN(struct cxl_region *cxlr, const char *buf, int pos, if (sysfs_streq(buf, "\n")) rc = detach_target(cxlr, pos); - else - rc = attach_target(cxlr, buf, pos); + else { + struct device *dev; + + dev = bus_find_device_by_name(&cxl_bus_type, NULL, buf); + if (!dev) + return -ENODEV; + + if (!is_endpoint_decoder(dev)) { + rc = -EINVAL; + goto out; + } + + rc = attach_target(cxlr, to_cxl_endpoint_decoder(dev), pos, + TASK_INTERRUPTIBLE); +out: + put_device(dev); + } if (rc < 0) return rc;