From nobody Thu Nov 6 10:44:02 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1716973376; cv=none; d=zohomail.com; s=zohoarc; b=mAa12o3Bi49p4ql0n9FQ2nq5Z4ESW81ikoyhZUvOsblk9VnencgB/j9JuQHurbS+Z5tHxEnKZngpvm8dDyFfMPPx3DtOP5Q2gPcLOFtpzCANC/wTR+pD78Bp440NQhvwfvyPh2GRlionXaM5HwANvrBM6oRbs04pv8QDXxv5eNs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716973376; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=q0Nh3rBmN+pTUZ9mi1QuaHwm6Qdmm1bW1P320o0L9uQ=; b=IHkiqeEn99X06OtgQOdUBq03wQzPsayN7y1/h5HzziGhLsSwxmsDDfCpMIp8rdk6riIQyAn+Zc8gqUaXAKRvclt9VQZ7uNk0Uj+S4Qzv7FToT4+RYL4NS0k8ZZUl5C/nQfBovoPM9OPw8548ubXgZupbFcGkqZkGZF1P6jiXVyo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1716973376482761.240607572744; Wed, 29 May 2024 02:02:56 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.731689.1137343 (Exim 4.92) (envelope-from ) id 1sCFCU-00071I-QB; Wed, 29 May 2024 09:02:26 +0000 Received: by outflank-mailman (output) from mailman id 731689.1137343; Wed, 29 May 2024 09:02:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sCFCU-00071B-ND; Wed, 29 May 2024 09:02:26 +0000 Received: by outflank-mailman (input) for mailman id 731689; Wed, 29 May 2024 09:02:25 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1sCFCT-0006nV-T7 for xen-devel@lists.xenproject.org; Wed, 29 May 2024 09:02:25 +0000 Received: from mail-qv1-xf34.google.com (mail-qv1-xf34.google.com [2607:f8b0:4864:20::f34]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 2a42f51a-1d9a-11ef-90a1-e314d9c70b13; Wed, 29 May 2024 11:02:24 +0200 (CEST) Received: by mail-qv1-xf34.google.com with SMTP id 6a1803df08f44-6ab9d406101so10364256d6.3 for ; Wed, 29 May 2024 02:02:24 -0700 (PDT) Received: from localhost ([213.195.114.223]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ac163189cbsm52218246d6.125.2024.05.29.02.02.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 02:02:22 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 2a42f51a-1d9a-11ef-90a1-e314d9c70b13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=google; t=1716973343; x=1717578143; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=q0Nh3rBmN+pTUZ9mi1QuaHwm6Qdmm1bW1P320o0L9uQ=; b=UrCRNhoAdwKdMwnay26lSkyLKktz/PB5H92GLpZxY27JCpJxj/cf5ZewimxjIy28hr fV5XTeAa4MyoxbDVvBL9cm17LFMuRO7GsJxeoVM/UGz6OLS7VaMhpVYhtbiQ/CIhfBEo mBUKP+Twdv2nzuy9KtzB8y4SXpuXmzmzbicmM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716973343; x=1717578143; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=q0Nh3rBmN+pTUZ9mi1QuaHwm6Qdmm1bW1P320o0L9uQ=; b=jKCK9rPPQij7Z2sFb3KGSteqLY6q78V5/TOV71rWFIfCbI3XO8DVuJikl7kqAhiIBS g/JA5396YceHog8lOwiDgB8XKPYQkMJbYcOsaDbr3DMeLvl0287vnebNW/xM6MjJlnq0 KDjN9QyFk8Cx1dVTpFyWZMcIXZoIV4z7rvsqyJZJOPG6sgF/iO3G0M4nKUhbT8r2cAL6 6O/xKXw1tNd0xxDWxbYZ8WqengB6CVyR2ceW1aw0KNu8iG8khEuoFZnNjgW3xbPso4UW VEimtzETbXHnZZtI9Q50CUdr+jc+sg4Kt1kmVWm1P0l3zKyl6ETokyVF1jcJV0bs9wnk Br0w== X-Gm-Message-State: AOJu0Yxg+JxPe7mLlFPVUa02Ni7NyzAo6dT9b4/sZKs4DnfiWVqULpEO ZT5doBshy5l01CSd4cnByPlgSV5ZglTsTVjAG2iGlYSPmm8+dFS6KMmIgCgkGvkY6cHy7yIqRQc m X-Google-Smtp-Source: AGHT+IFHRIN1eZv4oe0SSy/cz+Iz9pCra+5E0JzLjhkBniawjYKENoDwI5H8li2IB8bRXo70SdnG0g== X-Received: by 2002:a05:6214:4a07:b0:6a0:b3cc:ee48 with SMTP id 6a1803df08f44-6abc8cd1be4mr175200136d6.37.1716973342641; Wed, 29 May 2024 02:02:22 -0700 (PDT) From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Roger Pau Monne , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini Subject: [PATCH for-4.19 2/9] xen/cpu: do not get the CPU map in stop_machine_run() Date: Wed, 29 May 2024 11:01:24 +0200 Message-ID: <20240529090132.59434-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240529090132.59434-1-roger.pau@citrix.com> References: <20240529090132.59434-1-roger.pau@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) X-ZM-MESSAGEID: 1716973377678100005 The current callers of stop_machine_run() outside of init code already have= the CPU maps locked, and hence there's no reason for stop_machine_run() to atte= mpt to lock again. Replace the get_cpu_maps() call with a suitable unreachable assert. Further changes will modify the conditions under which get_cpu_maps() retur= ns success and without the adjustment proposed here the usage of stop_machine_run() in cpu_down() would then return an error. Signed-off-by: Roger Pau Monn=C3=A9 --- xen/common/cpu.c | 5 +++++ xen/common/stop_machine.c | 15 ++++++++------- xen/include/xen/cpu.h | 2 ++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/xen/common/cpu.c b/xen/common/cpu.c index 8709db4d2957..6173220e771b 100644 --- a/xen/common/cpu.c +++ b/xen/common/cpu.c @@ -68,6 +68,11 @@ void cpu_hotplug_done(void) write_unlock(&cpu_add_remove_lock); } =20 +bool cpu_map_locked(void) +{ + return rw_is_locked(&cpu_add_remove_lock); +} + static NOTIFIER_HEAD(cpu_chain); =20 void __init register_cpu_notifier(struct notifier_block *nb) diff --git a/xen/common/stop_machine.c b/xen/common/stop_machine.c index 398cfd507c10..7face75648e8 100644 --- a/xen/common/stop_machine.c +++ b/xen/common/stop_machine.c @@ -82,9 +82,15 @@ int stop_machine_run(int (*fn)(void *data), void *data, = unsigned int cpu) BUG_ON(!local_irq_is_enabled()); BUG_ON(!is_idle_vcpu(current)); =20 - /* cpu_online_map must not change. */ - if ( !get_cpu_maps() ) + /* + * cpu_online_map must not change. The only two callers of + * stop_machine_run() outside of init code already have the CPU map lo= cked. + */ + if ( system_state >=3D SYS_STATE_active && !cpu_map_locked() ) + { + ASSERT_UNREACHABLE(); return -EBUSY; + } =20 nr_cpus =3D num_online_cpus(); if ( cpu_online(this) ) @@ -92,10 +98,7 @@ int stop_machine_run(int (*fn)(void *data), void *data, = unsigned int cpu) =20 /* Must not spin here as the holder will expect us to be descheduled. = */ if ( !spin_trylock(&stopmachine_lock) ) - { - put_cpu_maps(); return -EBUSY; - } =20 stopmachine_data.fn =3D fn; stopmachine_data.fn_data =3D data; @@ -136,8 +139,6 @@ int stop_machine_run(int (*fn)(void *data), void *data,= unsigned int cpu) =20 spin_unlock(&stopmachine_lock); =20 - put_cpu_maps(); - return ret; } =20 diff --git a/xen/include/xen/cpu.h b/xen/include/xen/cpu.h index e1d4eb59675c..d8c8264c58b0 100644 --- a/xen/include/xen/cpu.h +++ b/xen/include/xen/cpu.h @@ -13,6 +13,8 @@ void put_cpu_maps(void); void cpu_hotplug_begin(void); void cpu_hotplug_done(void); =20 +bool cpu_map_locked(void); + /* Receive notification of CPU hotplug events. */ void register_cpu_notifier(struct notifier_block *nb); =20 --=20 2.44.0