Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp774300imm; Fri, 22 Jun 2018 05:11:22 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLrktI4vhrSUfG/aQnBEbSjbdTj+ncnIdBHIcgh5ubxU6hrHIhGsT4JjdZ/QqohOxd9u8E/ X-Received: by 2002:a17:902:968c:: with SMTP id n12-v6mr1430826plp.15.1529669482659; Fri, 22 Jun 2018 05:11:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529669482; cv=none; d=google.com; s=arc-20160816; b=rT0OOxLjuzhtrmoADXHLQYRB+Vj/G0knYG6poaLY75sb/oyhE8MRDjRfucmKiD7WZc yI6aOY9jvaV/ik6duErpwWklQ2z874iuoyVsm81fHv81HXadbwiQ6hOyMg3UvvhXdXsD vX62UC+sMjNHCeOPywU4NY7vLFa2Z2tDW739LZzBzYUJGCNWNJ+nP6LuxviJXTVKgMBT QAvvlVtzrYygMHosaIwmGxdf5BOPsWwWt5tNCHYCTVrdhtDkxvxeJYTswm1Qfg6Pt9Fp BU7+mSgGTOYbVZCbO2wqfn2nx9hwZ8yAZJB4q1anaiep5f+qllUtL+LSmPI1VN6W+IDx cRGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:mime-version:message-id:date:subject:cc:to :from:dkim-signature:arc-authentication-results; bh=+sSI/o5/rt4K9tKRIZVFgJ5IP8lkHm5hYF4ZR54+2yQ=; b=zQFdr7xCRFKGpA+rgawmAhyARaRbX+D8o9T5I5IlB4hTYYBD5NRx+mflEOHoAAYRZp q53+JqVcGrxDc2t2JRhKgEcie0rmndB6AkxOrWJHS6OadVy3cPRjL/ZwI/y3OY4tvx8/ w9D8ksBuyvcvbQtfxzqOdMIuxwPo4GHMcQvJ4tgwr/eAWrYEPEU6w5Ay/o5ax4y5FOVD k+NZT3soUdZk189byKlNGefVyjakiCTP5v17H6oDxECphMDPTg94A0+Yngi2EFyPP+PY nmxOxkJ6mH2ytRwMYFM5mBpj2TJPJfhfqWNP+uTQ4DDG2yIFTSxgwsgrGmtU9vlSRjUW PRww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@MicroFocusInternational.onmicrosoft.com header.s=selector1-suse-com header.b=mHXD53Y+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p91-v6si7020029plb.457.2018.06.22.05.10.55; Fri, 22 Jun 2018 05:11:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@MicroFocusInternational.onmicrosoft.com header.s=selector1-suse-com header.b=mHXD53Y+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751317AbeFVMJq (ORCPT + 99 others); Fri, 22 Jun 2018 08:09:46 -0400 Received: from prvmx02.microfocus.com ([130.57.1.217]:17557 "EHLO prvmx02.microfocus.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751005AbeFVMJo (ORCPT ); Fri, 22 Jun 2018 08:09:44 -0400 Received: from prvxcaht03.microfocus.com (Not Verified[137.65.248.137]) by prvmx02.microfocus.com with Trustwave SEG (v7,5,8,10121) (using TLS: TLSv1.2, AES256-SHA256) id ; Fri, 22 Jun 2018 05:55:00 -0600 Received: from NAM03-DM3-obe.outbound.protection.outlook.com (137.65.224.20) by mail.microfocus.com (137.65.248.137) with Microsoft SMTP Server (TLS) id 14.3.339.0; Fri, 22 Jun 2018 05:54:42 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=MicroFocusInternational.onmicrosoft.com; s=selector1-suse-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+sSI/o5/rt4K9tKRIZVFgJ5IP8lkHm5hYF4ZR54+2yQ=; b=mHXD53Y+SMoqLyPGB1P0KBJ2hfcXCbfD0SD6SrFyceKzzRHy+F+GYN8qHu6XIRYcb6L763/Y3VnGt8amVPK5djyy3qpcECQm0l03ryq13eQDkxrY4yV/moEKUexwjxTi9LNT+dqmJP6Eps+Kcl+F4kPlsq1CYUhOfEtknNQqpTM= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=guomin.chen@suse.com; Received: from linux-6dga.apac.novell.com (45.122.156.254) by SN1PR18MB2143.namprd18.prod.outlook.com (2603:10b6:802:2a::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.884.20; Fri, 22 Jun 2018 11:54:35 +0000 From: guomin chen To: Thomas Gleixner , Brijesh Singh , Borislav Petkov , Andrew Morton CC: Takashi Iwai , Lee Chun-Yi , , , guomin chen , Tom Lendacky , Bjorn Helgaas , Yaowei Bai , Dan Williams , Subject: [PATCH 1/1] resource: Fixed iomem resource release failed on release_mem_region_adjustable() when memory node or cpu node hot-remove. Date: Fri, 22 Jun 2018 19:52:52 +0800 Message-ID: <20180622115252.5174-1-guomin.chen@suse.com> X-Mailer: git-send-email 2.12.3 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [45.122.156.254] X-ClientProxiedBy: CO2PR04CA0077.namprd04.prod.outlook.com (2603:10b6:102:1::45) To SN1PR18MB2143.namprd18.prod.outlook.com (2603:10b6:802:2a::14) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2b34dc01-b306-4fea-3391-08d5d836ef4d X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(711020)(2017052603328)(7153060)(7193020);SRVR:SN1PR18MB2143; X-Microsoft-Exchange-Diagnostics: 1;SN1PR18MB2143;3:oWzH2xslQimDphnMVFbEXFjBWG/3uq53MRPlyMGupybWa8xLymhS4wk19ncShJIyqWZzxoMgQ80WSoowftAjEK2NJICma6CsS3xAUjDK1S0q8cz7XFZTENM5a36OmD2zGIRAnujOSOnVC0qQDnEPlZ1CjV5R37dWxh0wWIAEz1YD6cbXFUzO8+V9a6naya3UPAw5RKHCgWG551P5Reb7XZ0n+vEDpYKeY8zLJt0x16i6KlsXUGtegoG51B0imyLy;25:HqX5+zReMy8i2sPqu+khWBY9Axmd0QRzyLJ3cpQjgDGYX7RTvIygy3rXQAUWzBqK06nw4LrtSEopJXzmklGzb9Mwxcr5uYQVdBGtRuPZ1Eu7UhcbrgKqtL1Nbsj5f6XEoZZyqL8V25wqvHqfY5E5W7mkPfS8CdN4AF9R+m3CZBmH+s5zj1rkG7tsQWFdOm+m3vMwYimUJd1B0/9IDqOxOH3vfXcX/NXNuOUC/i09ew4mY6OU7lmPe0larZGpcoUTXl75QM5ZZqP0JJHeTCODk/cLK5ln1FagRfaGLvFTccnOFHk4Bvrh4HEr54TRpHacnNTdieYIJKyXZvUyeHaC/Q==;31:tvEyAEdPCOjepcasbjNFlAFCReP1cQkA7wH9MucVYC9zin3gcfxHmOaPKIc79ThWiSzlgqxP62faJO9gb268Xs/P3gLBQSWHSLcVj/H0nHc0UikjdHA4bQLDGBVZ5WVEwsfRr1w8imRTBNQwTUBlF0e96Spq2ASgYgp6lYifoKmGeddIT83uZtYgJlIO2lufje0KyLrn0GUTWiumJaptBtm0IduVW6ayahPhQrq3XoU= X-MS-TrafficTypeDiagnostic: SN1PR18MB2143: X-LD-Processed: 856b813c-16e5-49a5-85ec-6f081e13b527,ExtAddr X-Microsoft-Exchange-Diagnostics: 1;SN1PR18MB2143;20:H6KIhxvlREy+ycAQswYG21h10IGMBYjXqPdsE78DHWrIMZMleeYVaiJ1XllFI46gtbF1OvoDVb6wRkVylRTkMNj6hzsKt5Rhfe8Pc8ZpXrZpE8QwvpH/zb6+q6YFY3VxdxDyf6tX43/7H6Z6yOerF9CNlaxkJ+kiDR+3295tV9+AhUB0vqtY0KKRSorJqcvZNoRmh8RVEeDELRSTiJNA560lCLCe72Y8sA0nIqD3i5fqxMefQ+1ljaug+V1B5x33DLZO7xIDZxdRQF46bTecdxIGYvIrfV14BbT8aCdmjH0Nvs1UeU7zY723hp57YV1cNiOJQu5Mn4KT5UkwA+A0vtZ0PLcOMzmP/thpslDFTN2GDZG3/PXa17tVPQaYTRRiN2pyj4yP+ik1qwkHnDAJlYHHYb+tjlQoWHCeqtR1iR8qa6oYsUmzyVoPm39rom6bTEXw/br+ZlpXFWGjWSuMN+SG1OBqrv69U3QFXtRKfuiTf85RLle1Whzk+CIxXljE X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(173505980823694)(9452136761055)(767451399110)(211936372134217)(153496737603132)(228905959029699); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231254)(944501410)(52105095)(10201501046)(3002001)(149027)(150027)(6041310)(20161123558120)(20161123560045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(6072148)(201708071742011)(7699016);SRVR:SN1PR18MB2143;BCL:0;PCL:0;RULEID:;SRVR:SN1PR18MB2143; X-Microsoft-Exchange-Diagnostics: 1;SN1PR18MB2143;4:eFTUcPJoqn2Z6DA7ki4eoWtonHDK/V2jU5CiLpnksKfoIRbwrr32yPREG3EIE7G2H04Ho7cuAznyVjEA/35H6P4evs2dNEVnqMzn6fHEkBe9gpfBx98LSGw9ch9Kxof4DrSQHLmJthiR+hCrCh4yKwFgI15r2OikDLmWobtjvb4A3dXqdzRQ5BIL8tYxQQuOjhCl5bHNC4k1HWrcBeVnOWf1Usg4hJc5dJgk645qvSpg50zSmpaWEzC2uoGrFav06WCv2E1oIV+q0PKzlvlBaVtLMMMYWgs/pRdeHJQBUVbvNpjDRJ29hH1HmugT6i8iYr7sc6oCHWh5swiuI3vKoeu7JninBVFZgd5BbWFlayLk42zJ1o68jiqot9SlI1zmt0Hm+1tUl4lig7/5IuzipISEDTe8oJHYQYisKrMj2QoS5ZiAIEU36E8MeLbFUNumbmpT4vcrj9eXbyzuPQvp2DohY7QgkVmNayr48pLFLQE= X-Forefront-PRVS: 071156160B X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(346002)(39860400002)(39380400002)(366004)(376002)(396003)(189003)(199004)(50466002)(25786009)(575784001)(6512007)(48376002)(106356001)(478600001)(86362001)(81166006)(8936002)(81156014)(36756003)(8666007)(16586007)(2906002)(6486002)(86152003)(4326008)(110136005)(54906003)(6666003)(316002)(1076002)(68736007)(53936002)(386003)(2616005)(8676002)(7416002)(6116002)(956004)(476003)(6506007)(305945005)(26005)(97736004)(186003)(3846002)(16526019)(52116002)(105586002)(47776003)(5660300001)(66066001)(486006)(7736002)(50226002)(51416003);DIR:OUT;SFP:1102;SCL:1;SRVR:SN1PR18MB2143;H:linux-6dga.apac.novell.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; Received-SPF: None (protection.outlook.com: suse.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;SN1PR18MB2143;23:z5Z6GJUhQ3J1k96+YeidAxyecqLNcX6iYA9ubCS1p?= =?us-ascii?Q?U+I4/M9/8Fn7f4pjHPUua+u9dfutiEkNd5mQ/l11FVAg/E/wec7j2W+pKLyd?= =?us-ascii?Q?YAUr4QONWEJna/eVcUWj/ICOeIUOReMzKOURcff19Gc+Ikk/YHrUChqyxDxF?= =?us-ascii?Q?moagZQUM7Bjm5f8eE5xi/PZiefxynj8Aal3IwPsJS+eCAH3aelwm4xMOOg3Z?= =?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/FWWv4Qm53C8k0tCp7JpuToEVw==;5:7qV6Aqr1DPDRFfGUHwTVgobkfkF2adhOpNfmrC68+cv4LL4vtm4Po9zZP0LgCxrpZIjy5ORjN0RsxSCQmdiGb1XMknwqX9q4aCfTBw4bQMEWufzJCfpWFlXyNyy6NEILxfSG4pcDtp2zgtwfI/DwwJpS4OFXqNCRDJRl87qKC1k=;24:G4gxdsash6BT6II5XB2UxXlpxU3yZdCKYIBKuV/ZkLtbqpwId96Wyuh6+17ftnbI60rO+u2IFqz2GLXSfTc8of0aOpdZjuQttFThKUoI1Ac= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;SN1PR18MB2143;7:bgD6gJ/GPiS87HVsjxNX9YsV4nF69OxieQ18qSQNLUzBpxrA3etyCmfeVWyKtGCsAYYO6v5A9NGz5rQrUNWdGExefpmpjscKwQlL6A6ZZdEAVXOFEDifP8XGO33uIKcDX4lsayDAexGBgempv1JPmaWSj4R9kmFpcvQxsjg3VxLt7wcgb+cdcnYfRtjArNZQ15bRqRHuT7XCP7xwPBvUrLq3CKKJhiHRFevautWLhnJol+fuyuI1fommS77MdfYb X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jun 2018 11:54:35.4941 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2b34dc01-b306-4fea-3391-08d5d836ef4d X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 856b813c-16e5-49a5-85ec-6f081e13b527 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR18MB2143 X-OriginatorOrg: suse.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We've got a bug report indicating the hot-remove node resource release failed,when the memory on this node is divided into several sections.because the release_mem_region_adjustable() can only release one resource that must be [start,end]. In my case, the BIOS supports faulty memory isolation. if BIOS detected bad memory block, the BIOS will isolates this badblock. And set this badblock memory to EfiUnusableMemory in EFI memory map base on UEFI 2.7 spec.For example in my system, the memory range on node2 is [mem 0x0000080000000000-0x00000807ffffffff].but the BIOS detected the [8004e000000-8004e0fffff] is a badblock memory. So the memory on node2 seem like this: 80000000000-8004dffffff : System RAM 8004e000000-8004e0fffff : Unusable memory 8004e100000-807ffffffff : System RAM Now, when offline the cpu node2,the kernel will try to release ioresource [mem 0x0000080000000000-0x00000807ffffffff]. at this time, the kernel will release failed,and output error message: "Unable to release resource <0x0000080000000000-0x00000807ffffffff> (-22)". Because the release_mem_region_adjustable() can only release one resource that must be [0x0000080000000000 , 0x00000807ffffffff]. but now,the iomem resource on node2 [0x0000080000000000, 0x00000807ffffffff] are divided into three resources [80000000000- 8004dffffff],[8004e000000-8004e0fffff]and[8004e100000-807ffffffff]. This patch help to Release multiple iomem resources at once when node hot-remove. Such as in above case, when hot-remove the cpu node2,the kernel will try to release resource [0x0000080000000000- 0x00000807ffffffff].And this patch will release three resources [80000000000-8004dffffff],[8004e000000-8004e0fffff] and [8004e100000-807ffffffff]. Cc: Thomas Gleixner Cc: Brijesh Singh Cc: Borislav Petkov Cc: Andrew Morton Cc: Tom Lendacky Cc: Bjorn Helgaas Cc: Yaowei Bai Cc: Takashi Iwai Cc: Dan Williams Cc: linux-efi@vger.kernel.org Cc: linux-kernel@vger.kernel.org your.patch Cc: Lee Chun-Yi Signed-off-by: guomin chen --- kernel/resource.c | 73 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 30 deletions(-) diff --git a/kernel/resource.c b/kernel/resource.c index 30e1bc68503b..959bcce4c405 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -1240,6 +1240,7 @@ int release_mem_region_adjustable(struct resource *parent, struct resource *res; struct resource *new_res; resource_size_t end; + resource_size_t new_start = start; int ret = -EINVAL; end = start + size - 1; @@ -1257,7 +1258,7 @@ int release_mem_region_adjustable(struct resource *parent, break; /* look for the next resource if it does not fit into */ - if (res->start > start || res->end < end) { + if (res->end < new_start) { p = &res->sibling; continue; } @@ -1271,42 +1272,54 @@ int release_mem_region_adjustable(struct resource *parent, } /* found the target resource; let's adjust accordingly */ - if (res->start == start && res->end == end) { + if (res->start == new_start && res->end == end) { /* free the whole entry */ *p = res->sibling; free_resource(res); ret = 0; - } else if (res->start == start && res->end != end) { - /* adjust the start */ - ret = __adjust_resource(res, end + 1, - res->end - end); - } else if (res->start != start && res->end == end) { - /* adjust the end */ - ret = __adjust_resource(res, res->start, - start - res->start); + } else if (res->end > end) { + if (res->start >= new_start) { + /* adjust the start */ + ret = __adjust_resource(res, end + 1, + res->end - end); + } else { + /* split into two entries */ + if (!new_res) { + ret = -ENOMEM; + break; + } + new_res->name = res->name; + new_res->start = end + 1; + new_res->end = res->end; + new_res->flags = res->flags; + new_res->desc = res->desc; + new_res->parent = res->parent; + new_res->sibling = res->sibling; + new_res->child = NULL; + + ret = __adjust_resource(res, res->start, + new_start - res->start); + if (ret) + break; + res->sibling = new_res; + new_res = NULL; + } } else { - /* split into two entries */ - if (!new_res) { - ret = -ENOMEM; - break; + if (res->start < new_start) { + /* adjust the end */ + ret = __adjust_resource(res, res->start, + new_start - res->start); + new_start = res->end+1; + p = &res->sibling; + } else { + new_start = res->end+1; + *p = res->sibling; + free_resource(res); + ret = 0; } - new_res->name = res->name; - new_res->start = end + 1; - new_res->end = res->end; - new_res->flags = res->flags; - new_res->desc = res->desc; - new_res->parent = res->parent; - new_res->sibling = res->sibling; - new_res->child = NULL; - - ret = __adjust_resource(res, res->start, - start - res->start); - if (ret) - break; - res->sibling = new_res; - new_res = NULL; + if (res->end < end) + continue; } - break; } -- 2.12.3