Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp376864lqm; Wed, 1 May 2024 03:33:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWXiwSHj0/mun7xHls+ts1C+PJyIbq8lZxiRG10F4FWAXJGTVnMtQPNrUD077tQhyIl8BTTZ6iFHaLUTw0BneFAr4ZoRDET4mHjGm/ewQ== X-Google-Smtp-Source: AGHT+IHBCOxUzzgLGHriERI64f1bT0il8fk/xtu/Ou1I1cNN8mJvYqGn9gX9/pMJsosch+jtMcvU X-Received: by 2002:a37:e314:0:b0:790:fd6a:928 with SMTP id y20-20020a37e314000000b00790fd6a0928mr1652900qki.70.1714559632564; Wed, 01 May 2024 03:33:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714559632; cv=pass; d=google.com; s=arc-20160816; b=Ghh2cpYk05GZ/2XuSDC3ivKYufO+nrF0YmMmOMsQN7gEcXRjgFa9z2ye2+cyFupm5H svVOvzn5JpzOKucnMlo3KnR/NQeC6xP64lgQwhGHOg2uR1Nd0XtdjKn0k6sRWAdDV6H/ 2CULUUbocentmrR/vYDA/RsnT5xUkvOvG9GW6sUEU0XYEGElQfgJKDVDtgyQlEMSArp/ QoLo/c/5B2y+qZ7TFa1uBoRknAx+QfU50Kekud6BG/Hs5ldggjmCylUUD/DX1/cCIVK2 MaSQy6xBmiKTST27pDr+h51KB5NgU/bTGuPWllZs7HnMalKJPc6kLdunMwTZhM0hoVAi eeMA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=F3Rv6xRyLMIQbC6pPBDmGwewvdeX7X4Yb9g/5DiEGHE=; fh=JUjLB/NG6O8z3adw30m8ek4iTkOzpfrZcgvIR9mALyc=; b=hWJvj8ySH//xG3etk5PBq/IJ8n4UxkPaJkZiLHp1o9gzZqRAVB6nLtjKYmGqfYhLBA XHyase+prJBdHstYT2t+OCXKlEmxZUrRF6fL3TPAOXT4AwM6UdBqqYG9dLU2Xtll8j8H 5gNty7Pja/lyO5rgNLzaThxgQHExLguLckw4RxpbGFqrMXaK2xujeXrQGqX1UILmdl3L Mv39PfqKcx5m4i5QE/UTuNQi+KxDWAL8xg/QVcE/w1K9eD4y56L7uo1u3gspp8Qi2SCD 4/0gJro7SkpS7n2Lam/gzxzZtCNIX6xbdylEqvCxh0pfMUW/6/ceSGketoELfbDR5C2t P6bg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gdf9TwPN; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-165148-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165148-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id n1-20020ae9c301000000b0078ef1622a70si29732683qkg.68.2024.05.01.03.33.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 03:33:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-165148-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gdf9TwPN; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-165148-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165148-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 2B9771C208EC for ; Wed, 1 May 2024 10:33:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9A3B553E38; Wed, 1 May 2024 10:33:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="gdf9TwPN" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E98F333CD1 for ; Wed, 1 May 2024 10:33:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714559624; cv=none; b=nfEpAD7kwX5Y/uEfD9Xfql4G4sHJKvGeSlw2knaWGKyxpo9TpWGKDBC4oVA4ro+DRh9kQ2bdXj3vs+KGe011hCOMdVef3bQsX07rDs5t7DOj1a7i2P8t34Pq8tBS26O3FHFwWG0YxnolU3obl1wC+j1TIkbH/DC4GrBZCThjSGg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714559624; c=relaxed/simple; bh=QNBtujc6UZHL1288knXMhnVLCejZtwYmy6UxhheX4dQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=lQIe/PdpbfMUTy8LvaHs8mpqtMB6dpuNXHjqG7aeR5+d6gJYkWTXUDc1uNPTiVCx5CMNzy+icM/rkDyg8Qs4X+v0XHZA6MT4WscLrixXYxSYm/8L3xZsbI5Jw5BpnjQG0wcKspjl/CbDLoIqeBONYycSaB5Gw7NWo+MsRuDxFNg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=gdf9TwPN; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714559621; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=F3Rv6xRyLMIQbC6pPBDmGwewvdeX7X4Yb9g/5DiEGHE=; b=gdf9TwPNZfiqEJPZQYX1pcYMLNf8bxaJ88DpEXv7VTQfP7m9KC9K5s60qCk/SqoMSC2bah rnPQxOcI3W1R99ULiuSxDH+M+ntKp1rDNKq5Gf886gKLqHnz+zuZ+Cein2oJFvJGDZ2VWq t09hMj1b6kZEfechXWceDq3ZNU+kqcA= Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-688-D6YmBZbsM0uueAg-5xrnZg-1; Wed, 01 May 2024 06:33:40 -0400 X-MC-Unique: D6YmBZbsM0uueAg-5xrnZg-1 Received: by mail-pj1-f72.google.com with SMTP id 98e67ed59e1d1-2b35b8a9feaso77647a91.3 for ; Wed, 01 May 2024 03:33:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714559620; x=1715164420; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=F3Rv6xRyLMIQbC6pPBDmGwewvdeX7X4Yb9g/5DiEGHE=; b=agPyFac9txQ8vwU7z4ZUVaPsFCgvfvgz1M8G8v2lnEUuap+ZUCbtZAGumw8ANJUf/2 cCfEN0GLtpN36wDy+6ggp++xxU6IfOOLumzSX5iDvRhGTsdGVqCaJySTr/t672IqQlEp YQZU469aHeOWeJzQfU3YpFMChMhDRqLEUKGOM5BXwd33UbJ7KTdlZImzKm0xQT3phrc6 ZIDqsy5+DAkuCTXfdNJdEgadzAAX2nxZU2IpgkMVheiK3STJiNg1OAoCZm4Jv+Qgf/Ei vH6lOjl6rW9FcQd6PXTfXjz4ryFyO3qvBKH2RzTCkLDKRxmY6RHv8lUgNicen+9WOK+s 13QQ== X-Forwarded-Encrypted: i=1; AJvYcCU+xmbLBRn8Y95t9i7kD20I178iN1JTbsi3DRQdERc/6jOvAg96+dJz/9OKOBXdV657SHHDyNqCEvAS7KBnes7kOvg2G6TlffjdsPuR X-Gm-Message-State: AOJu0YxO1esd8FosfM84DheC5Q+hXg+qRf2zAr4+taWph2IeQuEn3dXK J2sRGmy5w2WNraHqLVqFahrODZ77lvBlApPetmnMgkGkQ01YOzOWvJvJG7lgrOtQEvYcClau9vZ CMUkZyUB5QV+yI7UUgqPebtjNXTDULZsUbsDhT9tTwZPJldTv2TVvFb5V19siWg== X-Received: by 2002:a17:90b:4a87:b0:29d:dd93:5865 with SMTP id lp7-20020a17090b4a8700b0029ddd935865mr1797777pjb.46.1714559619363; Wed, 01 May 2024 03:33:39 -0700 (PDT) X-Received: by 2002:a17:90b:4a87:b0:29d:dd93:5865 with SMTP id lp7-20020a17090b4a8700b0029ddd935865mr1797745pjb.46.1714559618837; Wed, 01 May 2024 03:33:38 -0700 (PDT) Received: from [192.168.68.50] ([43.252.112.88]) by smtp.gmail.com with ESMTPSA id sz15-20020a17090b2d4f00b002aff85b97dfsm1057594pjb.27.2024.05.01.03.33.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 01 May 2024 03:33:38 -0700 (PDT) Message-ID: <0febde44-99f1-48ba-a233-78b9a32468da@redhat.com> Date: Wed, 1 May 2024 20:33:27 +1000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v9 06/19] ACPI: processor: Move checks and availability of acpi_processor earlier Content-Language: en-US To: Jonathan Cameron , Thomas Gleixner , Peter Zijlstra , linux-pm@vger.kernel.org, loongarch@lists.linux.dev, linux-acpi@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, x86@kernel.org, Russell King , "Rafael J . Wysocki" , Miguel Luis , James Morse , Salil Mehta , Jean-Philippe Brucker , Catalin Marinas , Will Deacon , Marc Zyngier , Hanjun Guo Cc: Ingo Molnar , Borislav Petkov , Dave Hansen , linuxarm@huawei.com, justin.he@arm.com, jianyong.wu@arm.com References: <20240430142434.10471-1-Jonathan.Cameron@huawei.com> <20240430142434.10471-7-Jonathan.Cameron@huawei.com> From: Gavin Shan In-Reply-To: <20240430142434.10471-7-Jonathan.Cameron@huawei.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 5/1/24 00:24, Jonathan Cameron wrote: > Make the per_cpu(processors, cpu) entries available earlier so that > they are available in arch_register_cpu() as ARM64 will need access > to the acpi_handle to distinguish between acpi_processor_add() > and earlier registration attempts (which will fail as _STA cannot > be checked). > > Reorder the remove flow to clear this per_cpu() after > arch_unregister_cpu() has completed, allowing it to be used in > there as well. > > Note that on x86 for the CPU hotplug case, the pr->id prior to > acpi_map_cpu() may be invalid. Thus the per_cpu() structures > must be initialized after that call or after checking the ID > is valid (not hotplug path). > > Signed-off-by: Jonathan Cameron > > --- > v9: Add back a blank line accidentally removed in code move. > Fix up error returns so that the new cleanup in processor_add() > is triggered on detection of the bios bug. > Combined with the previous 2 patches, should solve the leak > that Gavin identified. > --- > drivers/acpi/acpi_processor.c | 80 +++++++++++++++++++++-------------- > 1 file changed, 49 insertions(+), 31 deletions(-) > It would be nice for acpi_processor_set_per_cpu() to return errno, explained as below. The patch looks good to me in either me. Reviewed-by: Gavin Shan > diff --git a/drivers/acpi/acpi_processor.c b/drivers/acpi/acpi_processor.c > index 16e36e55a560..4a79b42d649e 100644 > --- a/drivers/acpi/acpi_processor.c > +++ b/drivers/acpi/acpi_processor.c > @@ -183,8 +183,38 @@ static void __init acpi_pcc_cpufreq_init(void) {} > #endif /* CONFIG_X86 */ > > /* Initialization */ > +static DEFINE_PER_CPU(void *, processor_device_array); > + > +static bool acpi_processor_set_per_cpu(struct acpi_processor *pr, > + struct acpi_device *device) > +{ > + BUG_ON(pr->id >= nr_cpu_ids); > + > + /* > + * Buggy BIOS check. > + * ACPI id of processors can be reported wrongly by the BIOS. > + * Don't trust it blindly > + */ > + if (per_cpu(processor_device_array, pr->id) != NULL && > + per_cpu(processor_device_array, pr->id) != device) { > + dev_warn(&device->dev, > + "BIOS reported wrong ACPI id %d for the processor\n", > + pr->id); > + return false; > + } > + /* > + * processor_device_array is not cleared on errors to allow buggy BIOS > + * checks. > + */ > + per_cpu(processor_device_array, pr->id) = device; > + per_cpu(processors, pr->id) = pr; > + > + return true; > +} > + I think it'd better for acpi_processor_set_per_cpu() to return errno. -EINVAL is returned if a mismatched ACPI device is found, and 0 is returned on success. With the improvement, the callers needn't to translate boolen to errno. > #ifdef CONFIG_ACPI_HOTPLUG_CPU > -static int acpi_processor_hotadd_init(struct acpi_processor *pr) > +static int acpi_processor_hotadd_init(struct acpi_processor *pr, > + struct acpi_device *device) > { > int ret; > > @@ -198,8 +228,16 @@ static int acpi_processor_hotadd_init(struct acpi_processor *pr) > if (ret) > goto out; > > + if (!acpi_processor_set_per_cpu(pr, device)) { > + ret = -EINVAL; > + acpi_unmap_cpu(pr->id); > + goto out; > + } > + If errno is returned from acpi_processor_set_per_cpu(), this chunk of code becomes: ret = acpi_processor_set_per_cpu(pr, device); if (ret) { acpi_unmap_cpu(pr->id); goto out; } > ret = arch_register_cpu(pr->id); > if (ret) { > + /* Leave the processor device array in place to detect buggy bios */ > + per_cpu(processors, pr->id) = NULL; > acpi_unmap_cpu(pr->id); > goto out; > } > @@ -217,7 +255,8 @@ static int acpi_processor_hotadd_init(struct acpi_processor *pr) > return ret; > } > #else > -static inline int acpi_processor_hotadd_init(struct acpi_processor *pr) > +static inline int acpi_processor_hotadd_init(struct acpi_processor *pr, > + struct acpi_device *device) > { > return -ENODEV; > } > @@ -316,10 +355,13 @@ static int acpi_processor_get_info(struct acpi_device *device) > * because cpuid <-> apicid mapping is persistent now. > */ > if (invalid_logical_cpuid(pr->id) || !cpu_present(pr->id)) { > - int ret = acpi_processor_hotadd_init(pr); > + int ret = acpi_processor_hotadd_init(pr, device); > > if (ret) > return ret; > + } else { > + if (!acpi_processor_set_per_cpu(pr, device)) > + return -EINVAL; > } > ret = acpi_processor_set_per_cpu(pr, device); if (ret) return ret; > /* > @@ -365,8 +407,6 @@ static int acpi_processor_get_info(struct acpi_device *device) > * (cpu_data(cpu)) values, like CPU feature flags, family, model, etc. > * Such things have to be put in and set up by the processor driver's .probe(). > */ > -static DEFINE_PER_CPU(void *, processor_device_array); > - > static int acpi_processor_add(struct acpi_device *device, > const struct acpi_device_id *id) > { > @@ -395,28 +435,6 @@ static int acpi_processor_add(struct acpi_device *device, > if (result) /* Processor is not physically present or unavailable */ > goto err_clear_driver_data; > > - BUG_ON(pr->id >= nr_cpu_ids); > - > - /* > - * Buggy BIOS check. > - * ACPI id of processors can be reported wrongly by the BIOS. > - * Don't trust it blindly > - */ > - if (per_cpu(processor_device_array, pr->id) != NULL && > - per_cpu(processor_device_array, pr->id) != device) { > - dev_warn(&device->dev, > - "BIOS reported wrong ACPI id %d for the processor\n", > - pr->id); > - /* Give up, but do not abort the namespace scan. */ > - goto err_clear_driver_data; > - } > - /* > - * processor_device_array is not cleared on errors to allow buggy BIOS > - * checks. > - */ > - per_cpu(processor_device_array, pr->id) = device; > - per_cpu(processors, pr->id) = pr; > - > dev = get_cpu_device(pr->id); > if (!dev) { > result = -ENODEV; > @@ -470,10 +488,6 @@ static void acpi_processor_remove(struct acpi_device *device) > device_release_driver(pr->dev); > acpi_unbind_one(pr->dev); > > - /* Clean up. */ > - per_cpu(processor_device_array, pr->id) = NULL; > - per_cpu(processors, pr->id) = NULL; > - > cpu_maps_update_begin(); > cpus_write_lock(); > > @@ -481,6 +495,10 @@ static void acpi_processor_remove(struct acpi_device *device) > arch_unregister_cpu(pr->id); > acpi_unmap_cpu(pr->id); > > + /* Clean up. */ > + per_cpu(processor_device_array, pr->id) = NULL; > + per_cpu(processors, pr->id) = NULL; > + > cpus_write_unlock(); > cpu_maps_update_done(); > Thanks, Gavin