From mboxrd@z Thu Jan 1 00:00:00 1970 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 A1E14E69E85 for ; Mon, 2 Dec 2024 18:56:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0EFE66B007B; Mon, 2 Dec 2024 13:56:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0786D6B0083; Mon, 2 Dec 2024 13:56:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E0CC36B0085; Mon, 2 Dec 2024 13:56:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 938266B007B for ; Mon, 2 Dec 2024 13:56:26 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 2B57012027F for ; Mon, 2 Dec 2024 18:56:26 +0000 (UTC) X-FDA: 82850924646.28.E0F36FD Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by imf19.hostedemail.com (Postfix) with ESMTP id A390B1A000B for ; Mon, 2 Dec 2024 18:56:10 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="Z/eU0mtP"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf19.hostedemail.com: domain of nifan.cxl@gmail.com designates 209.85.214.172 as permitted sender) smtp.mailfrom=nifan.cxl@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733165772; a=rsa-sha256; cv=none; b=U1yWk10+SgBeXem8ADiL77ZirrOGvSMChFCv1wKk6vrI98W0aqE0MlTQluA1Y5ptxyI10c ws9ZohTSPD2eYeZp58Iw8AXW0P43XXs/YOPn23b41BAF4Y+6KuthfOefb3EwTROi6tw8h0 zlhkXWjUwIpY0gP45k3dfrGMNhMinmE= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="Z/eU0mtP"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf19.hostedemail.com: domain of nifan.cxl@gmail.com designates 209.85.214.172 as permitted sender) smtp.mailfrom=nifan.cxl@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733165772; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=RcYNbvRxmzFdfgrPFRhAAXEwiwJyjG9BESXy0MkNjBQ=; b=dSca2EJN0EQ21zNG7v/B/Bi+eNmdBaF5v7P9GUW4rkPy5K/ajrhJQfgliyIR5ZD4+kvPR6 Ds22BBHlHnLGPwh+QfF7T5emuvMUQTtegZdOIzFcWMNAMdqiShQSZLtW5dZCxJPEjD+Sxe ibQbK+mua/lXrv2YevCeFFWM2mtaotk= Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-215348d1977so36131675ad.3 for ; Mon, 02 Dec 2024 10:56:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733165783; x=1733770583; darn=kvack.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:from:to:cc:subject:date:message-id:reply-to; bh=RcYNbvRxmzFdfgrPFRhAAXEwiwJyjG9BESXy0MkNjBQ=; b=Z/eU0mtPQki0thn6IYjailvibWiYdMN9teQyUpJEWETq7GteERjkJW/iXQ9kHS14/u h7qqLQjKxWl2FFGhG9Xk0/+uyQvnSSUbUWubkU7WjK+L5AuzPhBSy+U9zkD96XzFwbk1 S2Pf79kZseuOJOvR9wzBgH8KizGqdZI4kmqQL9WRVpEtrpoVwIAY3uAXnecdkCdg1wAQ orLP2UBJIyCuHGyf7HxW18xZPecP2GwICfR3k24ZivEPrdpMWCgQxhcEhlWU8r+CA/6x aZ/DMVD6A9Pj01Xn2QKXs8oPg/Pi6L9bQi7mK/hPtVFVQMdhK2xTJolObc/tYy6bJeZl Tn5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733165783; x=1733770583; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=RcYNbvRxmzFdfgrPFRhAAXEwiwJyjG9BESXy0MkNjBQ=; b=LzVMawJBrCMlIuxj1tH3LQL06BtlTK4L0H3zNGK1AO9l6I7HC9jEFjK9ZCyNCpuC+W mMc/VKNEC4Pb1SLAh8I2YymbUpoqTbxLZoPD5+ISNpTcl4AsbLNn1Gf9p4Wh7/6zlZpM EMI9ymfNzQ1VAGsUaPOt96wV6e4C/L7J+DezQhcF8e3EQDlfAetL8Jf+8Ke0756gypqL 1ar7t2X3wVkmVdtsPYWutMVV6MUNaxnGvEv5MO5ZPrIQFGbqQcNybMLZObVBT+ZFiTf1 rPAVSWjN8LZwV1vjOYMfqPKF5arPq+SlvAZn7rRX5tkwFEywaq5Avps4FmZI8GD6Xk4L 4Mxw== X-Forwarded-Encrypted: i=1; AJvYcCXSnXgy1Z7Iyi9EUAN86cEnd9Veq1Jaf6wLN8nQ87xWeZ/oHiID/JUE/QTAfrIAxOHZwqtJcmiKAg==@kvack.org X-Gm-Message-State: AOJu0YxJBPDT6WGfHHovf4WstzLvMaYL0PXUmSTgVb5jCcvZ8scUZq/V TP+tLw80ga/P2efvZ5+hJvidIQ2gUksME5eg/N00xMMBmYnCyMeS X-Gm-Gg: ASbGnctGditvwNTFpUY+G/djKOG2XfsuAPJtKna0WhoQGneRECqZqeyA0xhV1mST4yC 3FuSlabXAhgDTw2soFCI5rQ5L2QPawRLHY7o9NPVhNVL7LBrSDhLulJxEpMFbGHk8ASkPZ8VmUS ygo0jt63QM8YzYeSXZfJ5CjbdhEZNhiSDIJED3LQe65rUZDVnhr3GzMT3hFM7friinpC9OR3O/8 Lyg+Zj6dfP3PZH5Bfnj3TM0R5MLMz5cWTOEqoyokbtV5lV+F77Hkw== X-Google-Smtp-Source: AGHT+IHLZj6yTSfs9ZXhLJt3U+34O39eJvm4MKiMp3YXnQc3/osEwF077n23jN5W2XDXD5sC7Zk71w== X-Received: by 2002:a17:902:e884:b0:202:cbf:2d6f with SMTP id d9443c01a7336-21501f6ef31mr241061275ad.57.1733165782665; Mon, 02 Dec 2024 10:56:22 -0800 (PST) Received: from smc-140338-bm01 ([149.97.161.244]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-215218f1da4sm81021835ad.12.2024.12.02.10.56.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2024 10:56:22 -0800 (PST) From: Fan Ni X-Google-Original-From: Fan Ni Date: Mon, 2 Dec 2024 18:56:20 +0000 To: Nathan Fontenot Cc: alison.schofield@intel.com, dan.j.williams@intel.com, linux-cxl@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH] cxl: Update Soft Reserved resources upon region creation Message-ID: References: <20241202155542.22111-1-nathan.fontenot@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20241202155542.22111-1-nathan.fontenot@amd.com> X-Stat-Signature: 9tdr1sxu5ytnx1etdwaaubi9i1g7anj5 X-Rspam-User: X-Rspamd-Queue-Id: A390B1A000B X-Rspamd-Server: rspam08 X-HE-Tag: 1733165770-878336 X-HE-Meta: U2FsdGVkX18E3meUUlTJlNQ7PMCWOORzkk2W2+UXrjKm+NyTDORNWbj74EBIFgTZ3CLDn7qjpr7uqEeaCtGJqlMcey0ZEHgq2w5IEO5riDe8C3FVbMm9ebqoQzgCuvLhMDghnK0dGXq2B21b+pGFtNgTLtNW1npkk2vkdqX86xiqw+eJ7FjJIAdWwOD2G25lhEmmTDKOGTYe6hOSa/pnqcvHUf92LIWSXC3DrqExPR4oq4JvBqqRgcoy1Qu4H9tt2PKHrYo9/ddmOZANFu3ReKkdRRewKz1M6c/ut2arPBhif/o1lPdMp2I+zQUgu6jOqPPSYcF2GErvQMDG03EaxtYyOEigG9lkpQI4jedd8ZAvbO7ULJwqyl7+LbXTtv83641Xhu/boEobDaoNlDTuSM7x5Jg+kC0sBqXdloDgFC04CzQTqNCDIwjUX7wfBbqPIUfAlYdeXC0eT0hmbfAVNY6hL1Yn6Z1IQksWCciA2Kg/yhOQ3w+Y9JADPzZ61oKFRz28mqlJLU68gWIC0bATssu7A72NVqa/m9NYTnYz94fTDMzCaj9SyGuWir0X2X+UV+6KEKU0Xab3jRBJ3/A1YOdTA3GoYS9VYyf3ACCSXwUt6s/15AeAO9MIxVUDk8kY0Xl22v3C3dVmxt5/a5G1KohhZczcPE0y4Q+wkwE/X0gDkjuXwhOWhbqDlSSSZvw3yN4o1Dn3+aITjFqnz/LNzZ1nwRSACjokUc9WvYVwsjl7hFill4YZNK5qFWBJjc9sbowQ/BVOchxBnvelfF2EofcO54DVMtdg8uh1bNj6VjnBCzKV2JO+xtMBpywxqOKzpHeN+mJiBEnDMdxLGqJiJTvFPR0gew6jW1vMR5VHHu6yKUalxs0ap8B6u7NRDMJ7W+gcSh5f7DKqJQDzj2pqeTQnI6ZSXJoytZMwqj3S6vrGWljOyDBnh/EAHMdWC+owfR+AOoDAYGvTmIL2qvk 1DMPgkPJ 43vcz9AZsjjyVZUcW/r2fxlDFteG6VhlrGbS+PUagzchJu+/Dqy5Q9Fgd5gxaJOrUDvODdyXvQHEcQ0yvf7yswpYfFjKlV8ZZqgXQ91sxyvUV93QCg7nncppFL1p/PBWNOhe2hAZKNXgmgXvrUmkrzsGjZMe4SVWyshjwuNTyEHMjJ4kQCU4iJO0M3jYEqI77SFpDrx6SeYiyoZocFGMsF/LG45ozAT5KT3rHSat0vnslZwU2RthQ5UgdmZjtpmlJsdqxGM2L7PPs/APtselzIXUkHavhWCaqLkbFQdKKb6XPPX8ynV1hzYuLJUN5EigWdJ560N7xdbIz3MPcjxi6t4DGZnaS738s5/nnQoaqi7mDa63AwYNtb+T37tXcAT/ip9uoz30PDXuCXW4xfBKcjdYnn37WufNzsD9J6LT2WrN12sAsXmIWvKqx+IXdCSeulIqr 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: List-Subscribe: List-Unsubscribe: On Mon, Dec 02, 2024 at 09:55:42AM -0600, Nathan Fontenot wrote: > Update handling of SOFT RESERVE iomem resources that intersect with > CXL region resources to remove the intersections from the SOFT RESERVE > resources. The current approach of leaving the SOFT RESERVE > resource as is can cause failures during hotplug replace of CXL > devices because the resource is not available for reuse after > teardown of the CXL device. > > The approach is to trim out any pieces of SOFT RESERVE resources > that intersect CXL regions. To do this, first set aside any SOFT RESERVE > resources that intersect with a CFMWS into a separate resource tree > during e820__reserve_resources_late() that would have been otherwise > added to the iomem resource tree. > > As CXL regions are created the cxl resource created for the new > region is used to trim intersections from the SOFT RESERVE > resources that were previously set aside. > > Once CXL device probe has completed ant remaining SOFT RESERVE resources /ant/any/ > remaining are added to the iomem resource tree. As each resource > is added to the oiomem resource tree a new notifier chain is invoked /oiomem/iomem/ > to notify the dax driver of newly added SOFT RESERVE resources so that > the dax driver can consume them. In general, the patch is kind of complicated and hard to review for me. I am wondering if it can be broken down to make it easier to review. One minor thing inline. > > Signed-off-by: Nathan Fontenot > --- > arch/x86/kernel/e820.c | 17 ++++- > drivers/cxl/core/region.c | 8 +- > drivers/cxl/port.c | 15 ++++ > drivers/dax/hmem/device.c | 13 ++-- > drivers/dax/hmem/hmem.c | 15 ++++ > drivers/dax/hmem/hmem.h | 11 +++ > include/linux/dax.h | 4 - > include/linux/ioport.h | 6 ++ > kernel/resource.c | 155 +++++++++++++++++++++++++++++++++++++- > 9 files changed, 229 insertions(+), 15 deletions(-) > create mode 100644 drivers/dax/hmem/hmem.h > > diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c > index 4893d30ce438..cab82e9324a5 100644 > --- a/arch/x86/kernel/e820.c > +++ b/arch/x86/kernel/e820.c > @@ -1210,14 +1210,23 @@ static unsigned long __init ram_alignment(resource_size_t pos) > > void __init e820__reserve_resources_late(void) > { > - int i; > struct resource *res; > + int i; > > + /* > + * Prior to inserting SOFT_RESERVED resources we want to check for an > + * intersection with potential CXL resources. Any SOFT_RESERVED resources > + * that do intersect a potential CXL resource are set aside so they > + * can be trimmed to accommodate CXL resource intersections and added to > + * the iomem resource tree after the CXL drivers have completed their > + * device probe. > + */ > res = e820_res; > - for (i = 0; i < e820_table->nr_entries; i++) { > - if (!res->parent && res->end) > + for (i = 0; i < e820_table->nr_entries; i++, res++) { > + if (res->desc == IORES_DESC_SOFT_RESERVED) > + insert_soft_reserve_resource(res); > + else if (!res->parent && res->end) > insert_resource_expand_to_fit(&iomem_resource, res); > - res++; Maybe we can keep the original (res++) here to avoid the noise since it is a style thing and does not affect what we want to achieve. Fan > } > > /* > diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c > index 21ad5f242875..c458a6313b31 100644 > --- a/drivers/cxl/core/region.c > +++ b/drivers/cxl/core/region.c > @@ -3226,6 +3226,12 @@ static int match_region_by_range(struct device *dev, void *data) > return rc; > } > > +static int insert_region_resource(struct resource *parent, struct resource *res) > +{ > + trim_soft_reserve_resources(res); > + return insert_resource(parent, res); > +} > + > /* Establish an empty region covering the given HPA range */ > static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd, > struct cxl_endpoint_decoder *cxled) > @@ -3272,7 +3278,7 @@ static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd, > > *res = DEFINE_RES_MEM_NAMED(hpa->start, range_len(hpa), > dev_name(&cxlr->dev)); > - rc = insert_resource(cxlrd->res, res); > + rc = insert_region_resource(cxlrd->res, res); > if (rc) { > /* > * Platform-firmware may not have split resources like "System > diff --git a/drivers/cxl/port.c b/drivers/cxl/port.c > index d7d5d982ce69..4461f2a80d72 100644 > --- a/drivers/cxl/port.c > +++ b/drivers/cxl/port.c > @@ -89,6 +89,20 @@ static int cxl_switch_port_probe(struct cxl_port *port) > return -ENXIO; > } > > +static void cxl_sr_update(struct work_struct *w) > +{ > + merge_soft_reserve_resources(); > +} > + > +DECLARE_DELAYED_WORK(cxl_sr_work, cxl_sr_update); > + > +static void schedule_soft_reserve_update(void) > +{ > + int timeout = 5 * HZ; > + > + mod_delayed_work(system_wq, &cxl_sr_work, timeout); > +} > + > static int cxl_endpoint_port_probe(struct cxl_port *port) > { > struct cxl_endpoint_dvsec_info info = { .port = port }; > @@ -140,6 +154,7 @@ static int cxl_endpoint_port_probe(struct cxl_port *port) > */ > device_for_each_child(&port->dev, root, discover_region); > > + schedule_soft_reserve_update(); > return 0; > } > > diff --git a/drivers/dax/hmem/device.c b/drivers/dax/hmem/device.c > index f9e1a76a04a9..c45791ad4858 100644 > --- a/drivers/dax/hmem/device.c > +++ b/drivers/dax/hmem/device.c > @@ -4,6 +4,7 @@ > #include > #include > #include > +#include "hmem.h" > > static bool nohmem; > module_param_named(disable, nohmem, bool, 0444); > @@ -17,6 +18,9 @@ static struct resource hmem_active = { > .flags = IORESOURCE_MEM, > }; > > +struct platform_device *hmem_pdev; > +EXPORT_SYMBOL_GPL(hmem_pdev); > + > int walk_hmem_resources(struct device *host, walk_hmem_fn fn) > { > struct resource *res; > @@ -35,7 +39,6 @@ EXPORT_SYMBOL_GPL(walk_hmem_resources); > > static void __hmem_register_resource(int target_nid, struct resource *res) > { > - struct platform_device *pdev; > struct resource *new; > int rc; > > @@ -51,15 +54,15 @@ static void __hmem_register_resource(int target_nid, struct resource *res) > if (platform_initialized) > return; > > - pdev = platform_device_alloc("hmem_platform", 0); > - if (!pdev) { > + hmem_pdev = platform_device_alloc("hmem_platform", 0); > + if (!hmem_pdev) { > pr_err_once("failed to register device-dax hmem_platform device\n"); > return; > } > > - rc = platform_device_add(pdev); > + rc = platform_device_add(hmem_pdev); > if (rc) > - platform_device_put(pdev); > + platform_device_put(hmem_pdev); > else > platform_initialized = true; > } > diff --git a/drivers/dax/hmem/hmem.c b/drivers/dax/hmem/hmem.c > index 5e7c53f18491..d626b60a9716 100644 > --- a/drivers/dax/hmem/hmem.c > +++ b/drivers/dax/hmem/hmem.c > @@ -5,6 +5,7 @@ > #include > #include > #include "../bus.h" > +#include "hmem.h" > > static bool region_idle; > module_param_named(region_idle, region_idle, bool, 0644); > @@ -123,8 +124,22 @@ static int hmem_register_device(struct device *host, int target_nid, > return rc; > } > > +static int dax_hmem_cb(struct notifier_block *nb, unsigned long action, > + void *arg) > +{ > + struct resource *res = arg; > + > + return hmem_register_device(&hmem_pdev->dev, > + phys_to_target_node(res->start), res); > +} > + > +static struct notifier_block hmem_nb = { > + .notifier_call = dax_hmem_cb > +}; > + > static int dax_hmem_platform_probe(struct platform_device *pdev) > { > + register_soft_reserve_notifier(&hmem_nb); > return walk_hmem_resources(&pdev->dev, hmem_register_device); > } > > diff --git a/drivers/dax/hmem/hmem.h b/drivers/dax/hmem/hmem.h > new file mode 100644 > index 000000000000..95583b59cef7 > --- /dev/null > +++ b/drivers/dax/hmem/hmem.h > @@ -0,0 +1,11 @@ > +// SPDX-License-Identifier: GPL-2.0 > +#ifndef _HMEM_H > +#define _HMEM_H > + > +typedef int (*walk_hmem_fn)(struct device *dev, int target_nid, > + const struct resource *res); > +int walk_hmem_resources(struct device *dev, walk_hmem_fn fn); > + > +extern struct platform_device *hmem_pdev; > + > +#endif > diff --git a/include/linux/dax.h b/include/linux/dax.h > index 9d3e3327af4c..119b4e27a592 100644 > --- a/include/linux/dax.h > +++ b/include/linux/dax.h > @@ -282,8 +282,4 @@ static inline void hmem_register_resource(int target_nid, struct resource *r) > { > } > #endif > - > -typedef int (*walk_hmem_fn)(struct device *dev, int target_nid, > - const struct resource *res); > -int walk_hmem_resources(struct device *dev, walk_hmem_fn fn); > #endif > diff --git a/include/linux/ioport.h b/include/linux/ioport.h > index 6e9fb667a1c5..487371a46392 100644 > --- a/include/linux/ioport.h > +++ b/include/linux/ioport.h > @@ -14,6 +14,7 @@ > #include > #include > #include > +#include > /* > * Resources are tree-like, allowing > * nesting etc.. > @@ -249,6 +250,11 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start); > int adjust_resource(struct resource *res, resource_size_t start, > resource_size_t size); > resource_size_t resource_alignment(struct resource *res); > +extern void trim_soft_reserve_resources(const struct resource *res); > +extern void merge_soft_reserve_resources(void); > +extern int insert_soft_reserve_resource(struct resource *res); > +extern int register_soft_reserve_notifier(struct notifier_block *nb); > +extern int unregister_soft_reserve_notifier(struct notifier_block *nb); > static inline resource_size_t resource_size(const struct resource *res) > { > return res->end - res->start + 1; > diff --git a/kernel/resource.c b/kernel/resource.c > index a83040fde236..8fc4121a1887 100644 > --- a/kernel/resource.c > +++ b/kernel/resource.c > @@ -30,7 +30,7 @@ > #include > #include > #include > - > +#include > > struct resource ioport_resource = { > .name = "PCI IO", > @@ -48,7 +48,15 @@ struct resource iomem_resource = { > }; > EXPORT_SYMBOL(iomem_resource); > > +struct resource srmem_resource = { > + .name = "Soft Reserved mem", > + .start = 0, > + .end = -1, > + .flags = IORESOURCE_MEM, > +}; > + > static DEFINE_RWLOCK(resource_lock); > +static DEFINE_RWLOCK(srmem_resource_lock); > > static struct resource *next_resource(struct resource *p, bool skip_children) > { > @@ -1034,6 +1042,151 @@ int adjust_resource(struct resource *res, resource_size_t start, > } > EXPORT_SYMBOL(adjust_resource); > > +static BLOCKING_NOTIFIER_HEAD(soft_reserve_chain); > + > +int register_soft_reserve_notifier(struct notifier_block *nb) > +{ > + return blocking_notifier_chain_register(&soft_reserve_chain, nb); > +} > +EXPORT_SYMBOL(register_soft_reserve_notifier); > + > +int unregister_soft_reserve_notifier(struct notifier_block *nb) > +{ > + return blocking_notifier_chain_unregister(&soft_reserve_chain, nb); > +} > +EXPORT_SYMBOL(unregister_soft_reserve_notifier); > + > +static int soft_reserve_notify(unsigned long val, void *v) > +{ > + struct resource *res = v; > + > + pr_info("Adding Soft Reserve resource %pr\n", res); > + return blocking_notifier_call_chain(&soft_reserve_chain, val, v); > +} > + > +static void trim_soft_reserve(struct resource *sr_res, > + const struct resource *res) > +{ > + struct resource *new_res; > + > + if (sr_res->start == res->start && sr_res->end == res->end) { > + release_resource(sr_res); > + free_resource(sr_res); > + } else if (sr_res->start == res->start) { > + WARN_ON(adjust_resource(sr_res, res->end + 1, > + sr_res->end - res->end)); > + } else if (sr_res->end == res->end) { > + WARN_ON(adjust_resource(sr_res, sr_res->start, > + res->start - sr_res->start)); > + } else { > + /* > + * Adjust existing resource to cover the resource > + * range prior to the range to be trimmed. > + */ > + adjust_resource(sr_res, sr_res->start, > + res->start - sr_res->start); > + > + /* > + * Add new resource to cover the resource range for > + * the range after the range to be trimmed. > + */ > + new_res = alloc_resource(GFP_KERNEL); > + if (!new_res) > + return; > + > + *new_res = DEFINE_RES_NAMED(res->end + 1, sr_res->end - res->end, > + "Soft Reserved", sr_res->flags); > + new_res->desc = IORES_DESC_SOFT_RESERVED; > + insert_resource(&srmem_resource, new_res); > + } > +} > + > +void trim_soft_reserve_resources(const struct resource *res) > +{ > + struct resource *sr_res; > + > + write_lock(&srmem_resource_lock); > + for (sr_res = srmem_resource.child; sr_res; sr_res = sr_res->sibling) { > + if (resource_contains(sr_res, res)) { > + trim_soft_reserve(sr_res, res); > + break; > + } > + } > + write_unlock(&srmem_resource_lock); > +} > +EXPORT_SYMBOL(trim_soft_reserve_resources); > + > +void merge_soft_reserve_resources(void) > +{ > + struct resource *sr_res, *next; > + > + write_lock(&srmem_resource_lock); > + for (sr_res = srmem_resource.child; sr_res; sr_res = next) { > + next = sr_res->sibling; > + > + release_resource(sr_res); > + if (insert_resource(&iomem_resource, sr_res)) > + pr_info("Could not add Soft Reserve %pr\n", sr_res); > + else > + soft_reserve_notify(0, sr_res); > + } > + write_unlock(&srmem_resource_lock); > +} > +EXPORT_SYMBOL(merge_soft_reserve_resources); > + > +struct srmem_arg { > + struct resource *res; > + int overlaps; > +}; > + > +static int srmem_parse_cfmws(union acpi_subtable_headers *hdr, > + void *arg, const unsigned long unused) > +{ > + struct acpi_cedt_cfmws *cfmws; > + struct srmem_arg *args = arg; > + struct resource cfmws_res; > + struct resource *res; > + > + res = args->res; > + > + cfmws = (struct acpi_cedt_cfmws *)hdr; > + cfmws_res = DEFINE_RES_MEM(cfmws->base_hpa, > + cfmws->base_hpa + cfmws->window_size); > + > + if (resource_overlaps(&cfmws_res, res)) { > + args->overlaps += 1; > + return 1; > + } > + > + return 0; > +} > + > +static bool resource_overlaps_cfmws(struct resource *res) > +{ > + struct srmem_arg arg = { > + .res = res, > + .overlaps = 0 > + }; > + > + acpi_table_parse_cedt(ACPI_CEDT_TYPE_CFMWS, srmem_parse_cfmws, &arg); > + > + if (arg.overlaps) > + return true; > + > + return false; > +} > + > +int insert_soft_reserve_resource(struct resource *res) > +{ > + if (resource_overlaps_cfmws(res)) { > + pr_info("Reserving Soft Reserve %pr\n", res); > + return insert_resource(&srmem_resource, res); > + } > + > + return insert_resource(&iomem_resource, res); > +} > +EXPORT_SYMBOL(insert_soft_reserve_resource); > + > static void __init > __reserve_region_with_split(struct resource *root, resource_size_t start, > resource_size_t end, const char *name) > -- > 2.43.0 > -- Fan Ni (From gmail)