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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EFB30C3DA4A for ; Thu, 8 Aug 2024 08:42:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Subject:CC:To: From:Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=fo5uWmVhdn+m0ix4cRGBVu2lyPwFtBHVz3VyXT3L/bY=; b=dqRbOkZ7Ou7TqizfdNtj+AOuwl WMeV1gOqqGlLdikfXt3baK3z6B7HJ9evHm+X/kXeba/O8UqzMVMwqHYvD3jXV9GIOOhvFhPoEorvg qrZHQaxViJIUY1JOWggQ26OgF17RekdNCSBpkj+NPvRz6fZMlOpqoOK1fXtfunoB80QNhF0NdVrSk fdk+iIMEuTscUtdXssNjhCJPMTZE+N1dhmv2CRXjJV1n5UNt+b0EvyPDM8zg7N/bSGkLWFPcJTT23 DIJfrRCVJwP6dPbAPuXwITlXCqZqVmZDtry7ZJn8V5yZICiDmwhLavS7g7stlb21+pavbafJbyrJs usMim9iA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbyic-00000007cbx-2Mmj; Thu, 08 Aug 2024 08:41:58 +0000 Received: from frasgout.his.huawei.com ([185.176.79.56]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sbyi2-00000007cUZ-38e5 for linux-arm-kernel@lists.infradead.org; Thu, 08 Aug 2024 08:41:24 +0000 Received: from mail.maildlp.com (unknown [172.18.186.216]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4WfgSD1W5Fz6K9g4; Thu, 8 Aug 2024 16:38:52 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id 9A21B1400C9; Thu, 8 Aug 2024 16:41:13 +0800 (CST) Received: from localhost (10.203.177.66) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 8 Aug 2024 09:41:11 +0100 Date: Thu, 8 Aug 2024 09:41:08 +0100 From: Jonathan Cameron To: Gavin Shan CC: , , , , , Subject: Re: [PATCH] cpumask: Fix crash on updating CPU enabled mask Message-ID: <20240808094108.00004b97@Huawei.com> In-Reply-To: <20240808040808.647316-1-gshan@redhat.com> References: <20240808040808.647316-1-gshan@redhat.com> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.203.177.66] X-ClientProxiedBy: lhrpeml500004.china.huawei.com (7.191.163.9) To lhrpeml500005.china.huawei.com (7.191.163.240) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240808_014123_107452_12EC9FEE X-CRM114-Status: GOOD ( 17.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, 8 Aug 2024 14:08:08 +1000 Gavin Shan wrote: > The CPU enabled mask instead of the CPU possible mask should be used > by set_cpu_enabled(). Otherwise, we run into crash due to write to > the read-only CPU possible mask when vCPU is hot added on ARM64. > > (qemu) device_add host-arm-cpu,id=cpu1,socket-id=1 > Unable to handle kernel write to read-only memory at virtual address ffff800080fa7190 > : > Call trace: > register_cpu+0x1a4/0x2e8 > arch_register_cpu+0x84/0xd8 > acpi_processor_add+0x480/0x5b0 > acpi_bus_attach+0x1c4/0x300 > acpi_dev_for_one_check+0x3c/0x50 > device_for_each_child+0x68/0xc8 > acpi_dev_for_each_child+0x48/0x80 > acpi_bus_attach+0x84/0x300 > acpi_bus_scan+0x74/0x220 > acpi_scan_rescan_bus+0x54/0x88 > acpi_device_hotplug+0x208/0x478 > acpi_hotplug_work_fn+0x2c/0x50 > process_one_work+0x15c/0x3c0 > worker_thread+0x2ec/0x400 > kthread+0x120/0x130 > ret_from_fork+0x10/0x20 > > Fix it by passing the CPU enabled mask instead of the CPU possible > mask to set_cpu_enabled(). > > Fixes: 51c4767503d5 ("Merge tag 'bitmap-6.11-rc1' of https://github.com:/norov/linux") > Signed-off-by: Gavin Shan Thanks Gavin! We'd flagged the merge conflict but thought we'd chase it with a patch adding set_cpu_enabled() as you have it fixed below. I completely missed that Linus took a different path whilst resolving the conflict to https://lore.kernel.org/all/20240701175051.0ef5d901@canb.auug.org.au/ which was what Stephen did for linux-next (which would have needed a follow up to use the new infrastructure. Anyhow, all's well that ends well. Reviewed-by: Jonathan Cameron > --- > include/linux/cpumask.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h > index 801a7e524113..53158de44b83 100644 > --- a/include/linux/cpumask.h > +++ b/include/linux/cpumask.h > @@ -1037,7 +1037,7 @@ void init_cpu_online(const struct cpumask *src); > assign_bit(cpumask_check(cpu), cpumask_bits(mask), (val)) > > #define set_cpu_possible(cpu, possible) assign_cpu((cpu), &__cpu_possible_mask, (possible)) > -#define set_cpu_enabled(cpu, enabled) assign_cpu((cpu), &__cpu_possible_mask, (enabled)) > +#define set_cpu_enabled(cpu, enabled) assign_cpu((cpu), &__cpu_enabled_mask, (enabled)) > #define set_cpu_present(cpu, present) assign_cpu((cpu), &__cpu_present_mask, (present)) > #define set_cpu_active(cpu, active) assign_cpu((cpu), &__cpu_active_mask, (active)) > #define set_cpu_dying(cpu, dying) assign_cpu((cpu), &__cpu_dying_mask, (dying))