From nobody Mon Dec 30 17:29:05 2024 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1727196177; cv=none; d=zohomail.com; s=zohoarc; b=Zbc6Vtv1xbvXuaPL2qDkhp4kHsaRJe8BwB0e1y9ACFpf7yy/USgvhMOSdgaJZK0h/Qq+SgiIhElywSMzE70a38I3EPUmyfz/+mhWfT3Wbhxwmj8OMbD5fMfI/43nDamv71C45yFnVifgOiwRUvtAW4N7o30epQ8/EU1qyX5/MfE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727196177; h=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=/5xCjLUs3pPbWQfdWyUE12cQ5VpHeo8Aa8a68hh3s7U=; b=jQe/eSZcKz25uwDEW/1eTjimRI/RNb/I22Qhb2c/czvi525nErV3x40dyLTjLcQ98Oo3E3W4kEMCEONqQXHmQ3JYyVDzrRwDShQaR729WI46II6ZaPqcijpbfLFQtcnKmSfE7qkJ+VyOe98RRK+6cCbPYZo41ks/RT0p60p9YiM= 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=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1727196177087349.6749289164761; Tue, 24 Sep 2024 09:42:57 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.803176.1213639 (Exim 4.92) (envelope-from ) id 1st8cW-0006qx-BX; Tue, 24 Sep 2024 16:42:36 +0000 Received: by outflank-mailman (output) from mailman id 803176.1213639; Tue, 24 Sep 2024 16:42:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1st8cW-0006qo-7e; Tue, 24 Sep 2024 16:42:36 +0000 Received: by outflank-mailman (input) for mailman id 803176; Tue, 24 Sep 2024 16:42:35 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1st8cU-0006l4-VU for xen-devel@lists.xenproject.org; Tue, 24 Sep 2024 16:42:34 +0000 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [2a00:1450:4864:20::629]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id ff096dc4-7a93-11ef-99a2-01e77a169b0f; Tue, 24 Sep 2024 18:42:33 +0200 (CEST) Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-a8a7b1c2f2bso955797466b.0 for ; Tue, 24 Sep 2024 09:42:33 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9393134917sm101862166b.203.2024.09.24.09.42.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Sep 2024 09:42:31 -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: ff096dc4-7a93-11ef-99a2-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727196152; x=1727800952; 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=/5xCjLUs3pPbWQfdWyUE12cQ5VpHeo8Aa8a68hh3s7U=; b=amu5GcfusJyKLzM1T42Z6EOmefResITmUVLZpxhmICTHlX+TvLSZO3Onp1NyOrGmHk WR7fyJsJjgJpYWpWlO04TL5jM1mIXa08qN1JFfFuzZwXpMLretmYTxWyHS3Qf+0YoNWI t37YJIAQtbg0I1uOStweoFoJCUKyl+ohUOx3/sldmc9sf80aDaJcml6Qq3LaQVYl04ig 8JmOpDYB5HxXR1thEdHD2WzQtFeOBNkWXseYBP/SgPSaqoVkD4U6UZfPS5VbC6Eu3Twr PUhktKBxke3RFI6pBpxtyG2fVXNRMQwclBGRZmpDP8PicAaIYojbv2vJAE944VsaMp1r CT9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727196152; x=1727800952; 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=/5xCjLUs3pPbWQfdWyUE12cQ5VpHeo8Aa8a68hh3s7U=; b=XOQHG7/LkaBaB3HeI0CZqYPAoT/PrJsXBmWTcgDN0pAlV0qJkv0nzHDLV9PjPLmCja qLtksKKEBS8lqNnzmffzgGcABMoJBLsZrh9jLT85TFzrUsRuLhUFzswDrouWk91YaXG8 uBhPlxQYoUFhJu3IQ2KbBYea2I2z8BB6fVLk6ohUr7CFy9Hi65AAVbYE2eixLwWhvyTf 5p+dS5xjtYOsfplvGiivE/Xn2RIm+BOcf34xQ/AceBQhItVTmuZjW4Zy6NNfjjtBiOwq LlmlX2YZ2mXJMyjTTzilzyDZQp36An+UlFP08BVgflTdDtgYcAKGvGBGROTZfmiDNCp7 3TOQ== X-Gm-Message-State: AOJu0Yyc0TDy215MVPAz/5r/ZlGWye56d3irWXGTdXQMJtCTHjMVgpu4 JacN3d62Ey0+UGHkfzsKBdq6h5Fxm0Jvw9hSa4VDf+loZ3Dwn2ElNGy/sw== X-Google-Smtp-Source: AGHT+IHD00C3g7Fx0hoscqOIGTJ9K6Y5t4Ql7OetvMHqBuOrmX96dauwfvurBGUOqTg17WX3M5YI/w== X-Received: by 2002:a17:907:94c7:b0:a8d:1774:eb73 with SMTP id a640c23a62f3a-a90d51841d8mr1870312566b.57.1727196152167; Tue, 24 Sep 2024 09:42:32 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , Jan Beulich , Shawn Anastasio , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Julien Grall Subject: [PATCH v2 1/2] xen: introduce common macros for per-CPU sections defintion Date: Tue, 24 Sep 2024 18:42:27 +0200 Message-ID: <27aba3aae7f4a5d4694ab141dca325d7231f2f66.1727185495.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.46.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1727196177643116600 Content-Type: text/plain; charset="utf-8" Introduce PERCPU_BSS macro which manages: * Alignment of the section start * Insertion of per-CPU data sections * Alignment and start/end markers for per-CPU data This change simplifies the linker script maintenance and ensures a unified approach for per-CPU sections across different architectures. Refactor the linker scripts for Arm, PPC, and x86 architectures by using the common macro PERCPU_BSS defined in xen/xen.lds.h to handle per-CPU data sections. No functional changes. Signed-off-by: Oleksii Kurochko Acked-by: Julien Grall Acked-by: Jan Beulich --- Changes in V2: - rename PERCPU_SECTION to PERCPU_BSS - update the commit message - add Acked-by: Julien Grall - add Acked-by: Jan Beulich --- xen/arch/arm/xen.lds.S | 9 +-------- xen/arch/ppc/xen.lds.S | 9 +-------- xen/arch/x86/xen.lds.S | 9 +-------- xen/include/xen/xen.lds.h | 10 ++++++++++ 4 files changed, 13 insertions(+), 24 deletions(-) diff --git a/xen/arch/arm/xen.lds.S b/xen/arch/arm/xen.lds.S index bd884664ad..0987052f1a 100644 --- a/xen/arch/arm/xen.lds.S +++ b/xen/arch/arm/xen.lds.S @@ -198,14 +198,7 @@ SECTIONS __bss_start =3D .; *(.bss.stack_aligned) *(.bss.page_aligned) - . =3D ALIGN(PAGE_SIZE); - __per_cpu_start =3D .; - *(.bss.percpu.page_aligned) - *(.bss.percpu) - . =3D ALIGN(SMP_CACHE_BYTES); - *(.bss.percpu.read_mostly) - . =3D ALIGN(SMP_CACHE_BYTES); - __per_cpu_data_end =3D .; + PERCPU_BSS *(.bss .bss.*) . =3D ALIGN(POINTER_ALIGN); __bss_end =3D .; diff --git a/xen/arch/ppc/xen.lds.S b/xen/arch/ppc/xen.lds.S index 38cd857187..0c4b94814b 100644 --- a/xen/arch/ppc/xen.lds.S +++ b/xen/arch/ppc/xen.lds.S @@ -148,14 +148,7 @@ SECTIONS __bss_start =3D .; *(.bss.stack_aligned) *(.bss.page_aligned) - . =3D ALIGN(PAGE_SIZE); - __per_cpu_start =3D .; - *(.bss.percpu.page_aligned) - *(.bss.percpu) - . =3D ALIGN(SMP_CACHE_BYTES); - *(.bss.percpu.read_mostly) - . =3D ALIGN(SMP_CACHE_BYTES); - __per_cpu_data_end =3D .; + PERCPU_BSS *(.bss .bss.*) . =3D ALIGN(POINTER_ALIGN); __bss_end =3D .; diff --git a/xen/arch/x86/xen.lds.S b/xen/arch/x86/xen.lds.S index d48de67cfd..b60d2f0d82 100644 --- a/xen/arch/x86/xen.lds.S +++ b/xen/arch/x86/xen.lds.S @@ -321,14 +321,7 @@ SECTIONS DECL_SECTION(.bss) { __bss_start =3D .; *(.bss.page_aligned*) - . =3D ALIGN(PAGE_SIZE); - __per_cpu_start =3D .; - *(.bss.percpu.page_aligned) - *(.bss.percpu) - . =3D ALIGN(SMP_CACHE_BYTES); - *(.bss.percpu.read_mostly) - . =3D ALIGN(SMP_CACHE_BYTES); - __per_cpu_data_end =3D .; + PERCPU_BSS *(.bss .bss.*) . =3D ALIGN(POINTER_ALIGN); __bss_end =3D .; diff --git a/xen/include/xen/xen.lds.h b/xen/include/xen/xen.lds.h index a17810bb28..24b8900ffe 100644 --- a/xen/include/xen/xen.lds.h +++ b/xen/include/xen/xen.lds.h @@ -151,6 +151,16 @@ #define LOCK_PROFILE_DATA #endif =20 +#define PERCPU_BSS \ + . =3D ALIGN(PAGE_SIZE); \ + __per_cpu_start =3D .; \ + *(.bss.percpu.page_aligned) \ + *(.bss.percpu) \ + . =3D ALIGN(SMP_CACHE_BYTES); \ + *(.bss.percpu.read_mostly) \ + . =3D ALIGN(SMP_CACHE_BYTES); \ + __per_cpu_data_end =3D .; \ + #ifdef CONFIG_HAS_VPCI #define VPCI_ARRAY \ . =3D ALIGN(POINTER_ALIGN); \ --=20 2.46.1 From nobody Mon Dec 30 17:29:05 2024 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=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1727196177; cv=none; d=zohomail.com; s=zohoarc; b=kaZNWAkh6vsuIhVX8dtakkOd9mtQy3G3ZJIpwBXioCFhB5KkWce3wwovMShUidYi3s2qAr1r9tp8TpGhOtWDenfHaaDOVjk5cQhPO7dqAd7cqzH77D5tMXMZjotYhWy82u6EsoCK4Z3DelXruyp3M/llXRTPvoFEaH3nT4glmho= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727196177; h=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=MMXSImRDsl0ngqSTSrK1CSW4XaKEG4u0XTGvXo/25TA=; b=G3MrXOgaSBOceDhFsQIcXBWuahr78juD9LP4/7tQH9yeViMGvuIir2ADzjiXPG+cCIjhEC5jEKTN0UqbTUcDid5NRC08OTHllYsxG5fRKhYey9tu3gnMy9qBQ9bmXHRXPls0s10NBNLHt4yqcyy12GilLNYILJx+2vFVh4myq3w= 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=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1727196177290250.26746036057114; Tue, 24 Sep 2024 09:42:57 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.803177.1213642 (Exim 4.92) (envelope-from ) id 1st8cW-0006tJ-J2; Tue, 24 Sep 2024 16:42:36 +0000 Received: by outflank-mailman (output) from mailman id 803177.1213642; Tue, 24 Sep 2024 16:42:36 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1st8cW-0006sf-FA; Tue, 24 Sep 2024 16:42:36 +0000 Received: by outflank-mailman (input) for mailman id 803177; Tue, 24 Sep 2024 16:42:35 +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 1st8cU-0006ag-UZ for xen-devel@lists.xenproject.org; Tue, 24 Sep 2024 16:42:35 +0000 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [2a00:1450:4864:20::52a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ffb6c025-7a93-11ef-a0ba-8be0dac302b0; Tue, 24 Sep 2024 18:42:34 +0200 (CEST) Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-5c241feb80dso102915a12.0 for ; Tue, 24 Sep 2024 09:42:34 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9393134917sm101862166b.203.2024.09.24.09.42.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Sep 2024 09:42:32 -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: ffb6c025-7a93-11ef-a0ba-8be0dac302b0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727196153; x=1727800953; 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=MMXSImRDsl0ngqSTSrK1CSW4XaKEG4u0XTGvXo/25TA=; b=WfxYT9UTKnCBFsJUFp3gvRRsIpoR3DJP0kd3eioQbZyGXY8/AYjSEhOn5yzxruD/lL lQJ9aXo4+st1dH4Ptkc7cQaOyC1iCYl1KKl4rDXyQ5apbhHqfnThfYfTvQa+wxL8tDHY WAXBV3gD9E2il2rIEJ2dZXs0Ec/ejkOM96fSFDuQehFOe/mCwRWUwn4S3sIK6x2iQMQ6 fCazI0pz4F0jhNHjW9788tgIvTkKzUuCEws3XfHxiwNcvum7MYEPuCY4L38+wFuvvYG6 EE14E78chBKkzfo2oRpMCyIaVL1FpAwxjNsEOP/EVIAjVgDafeLHJpQung9+f8xW/TjZ 5dQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727196153; x=1727800953; 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=MMXSImRDsl0ngqSTSrK1CSW4XaKEG4u0XTGvXo/25TA=; b=hfsJ2x+6tF3l9GkZXa5q+uB+awPCiAwRp8Ku+l3pnnAC+cYoi6aHtwFQykw0JNOyAq bDORH9aqTzNkNsGp2+xURtrI+O9SFdJuPfORlLHVZT792nfQYeGDbZTtujOJuh9xJYCa yytU7OrqAnLsLx6LT9RE8P9bcG7n4+U5hcpdQBQsVH99pMLvsR5ASWpjZKB16aXjEeOD W35ICtEjiNF0P+LGPv1wsW9Y752SKX3CkMZEaFOMZLJEjk/GZbnQ5adaVIGV9oFGb9fN kHawjVMb3PfoyeAo6uVgWKzDHCAQ3+kAnXM4SuVJLKxUkzwQov5YvnNysGdo5ejpvzit M32A== X-Gm-Message-State: AOJu0YxP2pQ2mP1yGJUrGS8jyFqN36zk7D2DhiiWdx1jv1SxVy7ly2/4 WkNyTRuUBzGqhG8AjLhq84v3rkmO1qRst9XDWBsssRBT+SR8Zg/ANeh0dg== X-Google-Smtp-Source: AGHT+IFHfCXN1mLftbRoKdmWDn5LUdcy6tLnqayNqIP1d+ftyOFziSjY1GZQtzHGaVh+vUOMI+gbaA== X-Received: by 2002:a17:906:6a0c:b0:a8d:59d7:f92b with SMTP id a640c23a62f3a-a92d5611329mr348572966b.30.1727196153275; Tue, 24 Sep 2024 09:42:33 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , Volodymyr Babchuk , Andrew Cooper , Jan Beulich , Shawn Anastasio , Alistair Francis , Bob Eshleman , Connor Davis , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v2 2/2] xen: move per-cpu area management into common code Date: Tue, 24 Sep 2024 18:42:28 +0200 Message-ID: X-Mailer: git-send-email 2.46.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1727196177745116600 Content-Type: text/plain; charset="utf-8" Centralize per-cpu area management to reduce code duplication and enhance maintainability across architectures. The per-cpu area management code, which is largely common among architectures, is moved to a shared implementation in xen/common/percpu.c. This change includes: * Remove percpu.c from the X86 and Arm architectures. * For x86, define INVALID_PERCPU_AREAS and PARK_OFFLINE_CPUS. * Drop the declaration of __per_cpu_offset[] from stubs.c in PPC and RISC-V to facilitate the build of the common per-cpu code. No functional changes for x86. For Arm add support of CPU_RESUME_FAILED, CPU_REMOVE and freeing of percpu in the case when system_state !=3D SYS_STATE_suspend. Signed-off-by: Oleksii Kurochko --- Changes in V2: - move definition of park_offline_cpus for Arm, PPC and RISC-V to - add to arm/asm/smp.h inclusion of ( at least, it is needed as it uses DECLARE_PER_CPU and also to not break the build because of moved definition of=20 park_offline_cpus to asm-generic/percpu.h ) - remove x86/percpu.c as all the code was moved to common percpu.c. - add define PARK_OFFLINE_CPUS to x86/asm/percpu.h as x86 defines it in own way. - drop ARCH_PERCPU_AREA_CHECK and ARCH_CPU_PERCPU_CALLBACK as the code inside this definitions were integrated to common code. - use park_offline_cpus ? 0 : -EBUSY; instead of arch_percpu_area_init_status() in init_percpu_area(). - update cpu_percpu_callback() to handle CPU_UP_CANCELED, case CPU_DEAD, case CPU_RESUME_FAILED and also CPU parking and SYS_STATE_suspend. - move declaration of percpu_init_areas() to xen/percpu.h. --- xen/arch/arm/Makefile | 1 - xen/arch/arm/include/asm/smp.h | 7 +- xen/arch/arm/percpu.c | 85 ----------------------- xen/arch/ppc/include/asm/smp.h | 6 -- xen/arch/ppc/stubs.c | 1 - xen/arch/riscv/include/asm/smp.h | 6 -- xen/arch/riscv/stubs.c | 1 - xen/arch/x86/Makefile | 1 - xen/arch/x86/include/asm/Makefile | 1 - xen/arch/x86/include/asm/percpu.h | 16 +++++ xen/arch/x86/percpu.c | 112 ------------------------------ xen/common/Makefile | 1 + xen/common/percpu.c | 110 +++++++++++++++++++++++++++++ xen/include/asm-generic/percpu.h | 9 ++- xen/include/xen/percpu.h | 4 ++ 15 files changed, 140 insertions(+), 221 deletions(-) delete mode 100644 xen/arch/arm/percpu.c create mode 100644 xen/arch/x86/include/asm/percpu.h delete mode 100644 xen/arch/x86/percpu.c create mode 100644 xen/common/percpu.c diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index 7792bff597..e4ad1ce851 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -39,7 +39,6 @@ obj-$(CONFIG_MEM_ACCESS) +=3D mem_access.o obj-y +=3D mm.o obj-y +=3D monitor.o obj-y +=3D p2m.o -obj-y +=3D percpu.o obj-y +=3D platform.o obj-y +=3D platform_hypercall.o obj-y +=3D physdev.o diff --git a/xen/arch/arm/include/asm/smp.h b/xen/arch/arm/include/asm/smp.h index e99a3a3f53..8f765ed12a 100644 --- a/xen/arch/arm/include/asm/smp.h +++ b/xen/arch/arm/include/asm/smp.h @@ -2,6 +2,7 @@ #define __ASM_SMP_H =20 #ifndef __ASSEMBLY__ +#include #include #include #endif @@ -12,12 +13,6 @@ extern unsigned long smp_up_cpu; DECLARE_PER_CPU(cpumask_var_t, cpu_sibling_mask); DECLARE_PER_CPU(cpumask_var_t, cpu_core_mask); =20 -/* - * Do we, for platform reasons, need to actually keep CPUs online when we - * would otherwise prefer them to be off? - */ -#define park_offline_cpus false - extern void noreturn stop_cpu(void); =20 extern int arch_smp_init(void); diff --git a/xen/arch/arm/percpu.c b/xen/arch/arm/percpu.c deleted file mode 100644 index 87fe960330..0000000000 --- a/xen/arch/arm/percpu.c +++ /dev/null @@ -1,85 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -#include -#include -#include -#include -#include - -unsigned long __per_cpu_offset[NR_CPUS]; -#define INVALID_PERCPU_AREA (-(long)__per_cpu_start) -#define PERCPU_ORDER (get_order_from_bytes(__per_cpu_data_end-__per_cpu_st= art)) - -void __init percpu_init_areas(void) -{ - unsigned int cpu; - for ( cpu =3D 1; cpu < NR_CPUS; cpu++ ) - __per_cpu_offset[cpu] =3D INVALID_PERCPU_AREA; -} - -static int init_percpu_area(unsigned int cpu) -{ - char *p; - if ( __per_cpu_offset[cpu] !=3D INVALID_PERCPU_AREA ) - return -EBUSY; - if ( (p =3D alloc_xenheap_pages(PERCPU_ORDER, 0)) =3D=3D NULL ) - return -ENOMEM; - memset(p, 0, __per_cpu_data_end - __per_cpu_start); - __per_cpu_offset[cpu] =3D p - __per_cpu_start; - return 0; -} - -struct free_info { - unsigned int cpu; - struct rcu_head rcu; -}; -static DEFINE_PER_CPU(struct free_info, free_info); - -static void _free_percpu_area(struct rcu_head *head) -{ - struct free_info *info =3D container_of(head, struct free_info, rcu); - unsigned int cpu =3D info->cpu; - char *p =3D __per_cpu_start + __per_cpu_offset[cpu]; - free_xenheap_pages(p, PERCPU_ORDER); - __per_cpu_offset[cpu] =3D INVALID_PERCPU_AREA; -} - -static void free_percpu_area(unsigned int cpu) -{ - struct free_info *info =3D &per_cpu(free_info, cpu); - info->cpu =3D cpu; - call_rcu(&info->rcu, _free_percpu_area); -} - -static int cpu_percpu_callback( - struct notifier_block *nfb, unsigned long action, void *hcpu) -{ - unsigned int cpu =3D (unsigned long)hcpu; - int rc =3D 0; - - switch ( action ) - { - case CPU_UP_PREPARE: - rc =3D init_percpu_area(cpu); - break; - case CPU_UP_CANCELED: - case CPU_DEAD: - free_percpu_area(cpu); - break; - default: - break; - } - - return notifier_from_errno(rc); -} - -static struct notifier_block cpu_percpu_nfb =3D { - .notifier_call =3D cpu_percpu_callback, - .priority =3D 100 /* highest priority */ -}; - -static int __init percpu_presmp_init(void) -{ - register_cpu_notifier(&cpu_percpu_nfb); - return 0; -} -presmp_initcall(percpu_presmp_init); diff --git a/xen/arch/ppc/include/asm/smp.h b/xen/arch/ppc/include/asm/smp.h index 7b1517ce18..2b872218be 100644 --- a/xen/arch/ppc/include/asm/smp.h +++ b/xen/arch/ppc/include/asm/smp.h @@ -7,10 +7,4 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_sibling_mask); DECLARE_PER_CPU(cpumask_var_t, cpu_core_mask); =20 -/* - * Do we, for platform reasons, need to actually keep CPUs online when we - * would otherwise prefer them to be off? - */ -#define park_offline_cpus false - #endif diff --git a/xen/arch/ppc/stubs.c b/xen/arch/ppc/stubs.c index bdb5f8c66d..fff82f5cf3 100644 --- a/xen/arch/ppc/stubs.c +++ b/xen/arch/ppc/stubs.c @@ -141,7 +141,6 @@ void smp_send_state_dump(unsigned int cpu) /* domain.c */ =20 DEFINE_PER_CPU(struct vcpu *, curr_vcpu); -unsigned long __per_cpu_offset[NR_CPUS]; =20 void context_switch(struct vcpu *prev, struct vcpu *next) { diff --git a/xen/arch/riscv/include/asm/smp.h b/xen/arch/riscv/include/asm/= smp.h index b1ea91b1eb..c63c499d12 100644 --- a/xen/arch/riscv/include/asm/smp.h +++ b/xen/arch/riscv/include/asm/smp.h @@ -8,12 +8,6 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_sibling_mask); DECLARE_PER_CPU(cpumask_var_t, cpu_core_mask); =20 -/* - * Do we, for platform reasons, need to actually keep CPUs online when we - * would otherwise prefer them to be off? - */ -#define park_offline_cpus false - #endif =20 /* diff --git a/xen/arch/riscv/stubs.c b/xen/arch/riscv/stubs.c index 2aa245f272..5951b0ce91 100644 --- a/xen/arch/riscv/stubs.c +++ b/xen/arch/riscv/stubs.c @@ -133,7 +133,6 @@ void smp_send_state_dump(unsigned int cpu) /* domain.c */ =20 DEFINE_PER_CPU(struct vcpu *, curr_vcpu); -unsigned long __per_cpu_offset[NR_CPUS]; =20 void context_switch(struct vcpu *prev, struct vcpu *next) { diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile index 00ab091634..bf68f38c0e 100644 --- a/xen/arch/x86/Makefile +++ b/xen/arch/x86/Makefile @@ -54,7 +54,6 @@ obj-y +=3D mpparse.o obj-y +=3D nmi.o obj-y +=3D numa.o obj-y +=3D pci.o -obj-y +=3D percpu.o obj-y +=3D physdev.o obj-$(CONFIG_COMPAT) +=3D x86_64/physdev.o obj-y +=3D psr.o diff --git a/xen/arch/x86/include/asm/Makefile b/xen/arch/x86/include/asm/M= akefile index daab34ff0a..2c27787d31 100644 --- a/xen/arch/x86/include/asm/Makefile +++ b/xen/arch/x86/include/asm/Makefile @@ -1,3 +1,2 @@ # SPDX-License-Identifier: GPL-2.0-only generic-y +=3D div64.h -generic-y +=3D percpu.h diff --git a/xen/arch/x86/include/asm/percpu.h b/xen/arch/x86/include/asm/p= ercpu.h new file mode 100644 index 0000000000..b892dc2f00 --- /dev/null +++ b/xen/arch/x86/include/asm/percpu.h @@ -0,0 +1,16 @@ +#ifndef __X86_PERCPU_H__ +#define __X86_PERCPU_H__ + +#define PARK_OFFLINE_CPUS + +#include + +/* + * Force uses of per_cpu() with an invalid area to attempt to access the + * middle of the non-canonical address space resulting in a #GP, rather th= an a + * possible #PF at (NULL + a little) which has security implications in the + * context of PV guests. + */ +#define INVALID_PERCPU_AREA (0x8000000000000000UL - (unsigned long)__per_c= pu_start) + +#endif /* __X86_PERCPU_H__ */ diff --git a/xen/arch/x86/percpu.c b/xen/arch/x86/percpu.c deleted file mode 100644 index 3205eacea6..0000000000 --- a/xen/arch/x86/percpu.c +++ /dev/null @@ -1,112 +0,0 @@ -#include -#include -#include -#include -#include - -unsigned long __per_cpu_offset[NR_CPUS]; - -/* - * Force uses of per_cpu() with an invalid area to attempt to access the - * middle of the non-canonical address space resulting in a #GP, rather th= an a - * possible #PF at (NULL + a little) which has security implications in the - * context of PV guests. - */ -#define INVALID_PERCPU_AREA (0x8000000000000000UL - (unsigned long)__per_c= pu_start) -#define PERCPU_ORDER get_order_from_bytes(__per_cpu_data_end - __per_cpu_s= tart) - -void __init percpu_init_areas(void) -{ - unsigned int cpu; - - for ( cpu =3D 1; cpu < NR_CPUS; cpu++ ) - __per_cpu_offset[cpu] =3D INVALID_PERCPU_AREA; -} - -static int init_percpu_area(unsigned int cpu) -{ - char *p; - - if ( __per_cpu_offset[cpu] !=3D INVALID_PERCPU_AREA ) - return 0; - - if ( (p =3D alloc_xenheap_pages(PERCPU_ORDER, 0)) =3D=3D NULL ) - return -ENOMEM; - - memset(p, 0, __per_cpu_data_end - __per_cpu_start); - __per_cpu_offset[cpu] =3D p - __per_cpu_start; - - return 0; -} - -struct free_info { - unsigned int cpu; - struct rcu_head rcu; -}; -static DEFINE_PER_CPU(struct free_info, free_info); - -static void cf_check _free_percpu_area(struct rcu_head *head) -{ - struct free_info *info =3D container_of(head, struct free_info, rcu); - unsigned int cpu =3D info->cpu; - char *p =3D __per_cpu_start + __per_cpu_offset[cpu]; - - free_xenheap_pages(p, PERCPU_ORDER); - __per_cpu_offset[cpu] =3D INVALID_PERCPU_AREA; -} - -static void free_percpu_area(unsigned int cpu) -{ - struct free_info *info =3D &per_cpu(free_info, cpu); - - info->cpu =3D cpu; - call_rcu(&info->rcu, _free_percpu_area); -} - -static int cf_check cpu_percpu_callback( - struct notifier_block *nfb, unsigned long action, void *hcpu) -{ - unsigned int cpu =3D (unsigned long)hcpu; - int rc =3D 0; - - switch ( action ) - { - case CPU_UP_PREPARE: - rc =3D init_percpu_area(cpu); - break; - case CPU_UP_CANCELED: - case CPU_DEAD: - case CPU_RESUME_FAILED: - if ( !park_offline_cpus && system_state !=3D SYS_STATE_suspend ) - free_percpu_area(cpu); - break; - case CPU_REMOVE: - if ( park_offline_cpus ) - free_percpu_area(cpu); - break; - } - - return notifier_from_errno(rc); -} - -static struct notifier_block cpu_percpu_nfb =3D { - .notifier_call =3D cpu_percpu_callback, - .priority =3D 100 /* highest priority */ -}; - -static int __init cf_check percpu_presmp_init(void) -{ - register_cpu_notifier(&cpu_percpu_nfb); - - return 0; -} -presmp_initcall(percpu_presmp_init); - -/* - * Local variables: - * mode: C - * c-file-style: "BSD" - * c-basic-offset: 4 - * indent-tabs-mode: nil - * End: - */ diff --git a/xen/common/Makefile b/xen/common/Makefile index fc52e0857d..f90bb00d23 100644 --- a/xen/common/Makefile +++ b/xen/common/Makefile @@ -31,6 +31,7 @@ obj-y +=3D notifier.o obj-$(CONFIG_NUMA) +=3D numa.o obj-y +=3D page_alloc.o obj-y +=3D pdx.o +obj-y +=3D percpu.o obj-$(CONFIG_PERF_COUNTERS) +=3D perfc.o obj-bin-$(CONFIG_HAS_PMAP) +=3D pmap.init.o obj-y +=3D preempt.o diff --git a/xen/common/percpu.c b/xen/common/percpu.c new file mode 100644 index 0000000000..58a774154d --- /dev/null +++ b/xen/common/percpu.c @@ -0,0 +1,110 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include +#include +#include +#include +#include + +#ifndef INVALID_PERCPU_AREA +#define INVALID_PERCPU_AREA (-(long)__per_cpu_start) +#endif + +#define PERCPU_ORDER get_order_from_bytes(__per_cpu_data_end - __per_cpu_s= tart) + +unsigned long __per_cpu_offset[NR_CPUS]; + +void __init percpu_init_areas(void) +{ + unsigned int cpu; + + for ( cpu =3D 1; cpu < NR_CPUS; cpu++ ) + __per_cpu_offset[cpu] =3D INVALID_PERCPU_AREA; +} + +static int init_percpu_area(unsigned int cpu) +{ + char *p; + + if ( __per_cpu_offset[cpu] !=3D INVALID_PERCPU_AREA ) + return park_offline_cpus ? 0 : -EBUSY; + + if ( (p =3D alloc_xenheap_pages(PERCPU_ORDER, 0)) =3D=3D NULL ) + return -ENOMEM; + + memset(p, 0, __per_cpu_data_end - __per_cpu_start); + __per_cpu_offset[cpu] =3D p - __per_cpu_start; + + return 0; +} + +struct free_info { + unsigned int cpu; + struct rcu_head rcu; +}; +static DEFINE_PER_CPU(struct free_info, free_info); + +static void cf_check _free_percpu_area(struct rcu_head *head) +{ + struct free_info *info =3D container_of(head, struct free_info, rcu); + unsigned int cpu =3D info->cpu; + char *p =3D __per_cpu_start + __per_cpu_offset[cpu]; + + free_xenheap_pages(p, PERCPU_ORDER); + __per_cpu_offset[cpu] =3D INVALID_PERCPU_AREA; +} + +static void free_percpu_area(unsigned int cpu) +{ + struct free_info *info =3D &per_cpu(free_info, cpu); + + info->cpu =3D cpu; + call_rcu(&info->rcu, _free_percpu_area); +} + +static int cf_check cpu_percpu_callback( + struct notifier_block *nfb, unsigned long action, void *hcpu) +{ + unsigned int cpu =3D (unsigned long)hcpu; + int rc =3D 0; + + switch ( action ) + { + case CPU_UP_PREPARE: + rc =3D init_percpu_area(cpu); + break; + case CPU_UP_CANCELED: + case CPU_DEAD: + case CPU_RESUME_FAILED: + if ( !park_offline_cpus && system_state !=3D SYS_STATE_suspend ) + free_percpu_area(cpu); + break; + case CPU_REMOVE: + if ( park_offline_cpus ) + free_percpu_area(cpu); + break; + } + + return notifier_from_errno(rc); +} + +static struct notifier_block cpu_percpu_nfb =3D { + .notifier_call =3D cpu_percpu_callback, + .priority =3D 100 /* highest priority */ +}; + +static int __init cf_check percpu_presmp_init(void) +{ + register_cpu_notifier(&cpu_percpu_nfb); + + return 0; +} +presmp_initcall(percpu_presmp_init); + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/asm-generic/percpu.h b/xen/include/asm-generic/per= cpu.h index 60af4f9ff9..d36afda2dd 100644 --- a/xen/include/asm-generic/percpu.h +++ b/xen/include/asm-generic/percpu.h @@ -10,7 +10,14 @@ extern char __per_cpu_start[]; extern const char __per_cpu_data_end[]; extern unsigned long __per_cpu_offset[NR_CPUS]; -void percpu_init_areas(void); + +#ifndef PARK_OFFLINE_CPUS +/* + * Do we, for platform reasons, need to actually keep CPUs online when we + * would otherwise prefer them to be off? + */ +#define park_offline_cpus false +#endif =20 #define per_cpu(var, cpu) \ (*RELOC_HIDE(&per_cpu__##var, __per_cpu_offset[cpu])) diff --git a/xen/include/xen/percpu.h b/xen/include/xen/percpu.h index 57522f346b..90c4e120ec 100644 --- a/xen/include/xen/percpu.h +++ b/xen/include/xen/percpu.h @@ -33,4 +33,8 @@ #define get_cpu_var(var) this_cpu(var) #define put_cpu_var(var) =20 +#ifndef __ASSEMBLY__ +void percpu_init_areas(void); +#endif + #endif /* __XEN_PERCPU_H__ */ --=20 2.46.1