Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1930484lqa; Tue, 30 Apr 2024 03:47:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWKoIoG1xoFQ/Swc5L3qT3tlEI46wMIY1yDPifv+fcicl/ywKGqKXuHyXiW7vUOMwfOtnR7Q7Siqog0XeJI0GexbABNtYbOXXdCf0FHLQ== X-Google-Smtp-Source: AGHT+IH4hs4c+5VZj2iUJMzgIrH6lOjB4HEWpHSzobFNMANPvJ61VI6RjKH8esStSlWL+O6qNAK4 X-Received: by 2002:a05:6402:40ce:b0:572:707f:1a99 with SMTP id z14-20020a05640240ce00b00572707f1a99mr5944620edb.25.1714474077490; Tue, 30 Apr 2024 03:47:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714474077; cv=pass; d=google.com; s=arc-20160816; b=ecQxtWc6q8ejD5AZV4s1+zlgwCvSVif/7QPCsx2roWr+SsXmQcM5OsqtWx/qBvV5e5 pchv1a6CPePl0TDdGydhtct3FgCs8mjHx86aRCe9/SXfWwxHmpngDoN8rgomz72BlFwj 7pSKWXOqpHkZnlXwO/JZOQw9LcIKajdOa3Ho04y84erpkg6L1ma8Xpw+p8yDGLKCDX+h lEBlJbmBaUn1jn9B7MIcLoYZtXL79qyJPjnhfKF8XYI9DUS4tf06NyexR84FoIFxkjvS /XLtHeGCD0Q8H6aC90QbGXb3+Kc9ZUyjMaWtUQ9bfA7NeUaNVlYTtoTAzr9BJFKHpPxA ZbFQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=gl1amXlEiUsoDONs7b9uFhr8MkJEfSSCI4cIhY5QMf4=; fh=ke5VkNl6heNYtjCnK2NynA8hn/Nx9d3MEQq3JhbbY/Y=; b=ezWwv3Fqm99mJxcd7ytlI9brD7FkUT17HzbC3YSgxg7JYziTI6aT5KhUSMqNpE/cKO 7dxMzE6FUuFiPIxL/d/LqSNQwby0V2T+1r0sJeN+iI/uB+eCE2t33AnW5a3puZL+IgXT qJdilLM1woUuW8RNqhx9hXatqhTeOnzVwGgZ+Haj59Jumh5AYeb5dakvD7qkTLEyMgT3 5J8jmgGHzi7P1Rrk364ubFiASIku4Qws+4xQijZMpjliSE2Iqtp76a9kHoX/8MHDv9YQ PZZny/wJlp5WRcu8Hc3T2kCUhf1ZChjFI9jB+grgQpzQH9Y0cpOqd0QNXRN+DTkqPD35 /0iw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mGvXxDPs; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-163793-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163793-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id o8-20020aa7d3c8000000b005722e4d0f72si8100089edr.641.2024.04.30.03.47.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 03:47:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-163793-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mGvXxDPs; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-163793-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163793-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 0ABFA1F221D8 for ; Tue, 30 Apr 2024 10:47:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 92F2112C80B; Tue, 30 Apr 2024 10:47:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mGvXxDPs" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 613C81292C8; Tue, 30 Apr 2024 10:47:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714474067; cv=none; b=K6oUQHbDGsEU3GZpCXttlKRGXljevGdUK9BNNxvYoD7L8rKYTCDi0V75yN4fHvoJRWp6mYv60PtlutntAcalyTyalW4thld2ww+ieLtGkKztJh9xsrVNhDGqjIqaYhcjeDENSxyxxdZ3pmdWzd+OxwTa+LKHeXZqSGdT6Wpaq78= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714474067; c=relaxed/simple; bh=WZUKSeKyIPsk8d6ycvulrut5Qa11GliUpPCP6FFms4U=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=nxuKy+mS2heE7LEnOQIlArUQJjCkqjREETQR/MFzEeJo8oBQNUPgAW2j/y0oKjXuF+9tFEapJzeWVZSGZZb2BLut2/2P9KlmOKTSkGd6UKtEIMAgKr+ptwgpEOaIoY+qgu6rOirMgfpFdoVklC1FJPhZcxeKtk7+m/G/t2C0JQg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mGvXxDPs; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39A9BC4AF5F; Tue, 30 Apr 2024 10:47:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714474067; bh=WZUKSeKyIPsk8d6ycvulrut5Qa11GliUpPCP6FFms4U=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=mGvXxDPseshKWHrhk/EJeXU0vbKAkmpT4jipiadYfEt06SESJdnr7pN1XwuX2XKAP QolD4+xZe394t1sKP3d/WuOd5qF+EUSIiZGg1zknqEDshwq0iyiHBI/YMyMynWgdAx u5OJjMyNBwLAdgfIfRdCKfzy8oXNku/V63JuL/TL3MNqi6qdXxA3rpJL5BLqu1Emv6 vMK+E8j7Yf1PYaIr87oBrL3G7KvHXuyQAJbZBOJ2Rfz7D/f569l7zZIKPWxPhA1p9a yrmrpXF3CyD39HRjByGsK1lXLjGt1BvVcQjVZB0LJtPW2PYj56DewQ5lHUyjyGYKGM havP8C0Hc0PNQ== Received: by mail-ot1-f43.google.com with SMTP id 46e09a7af769-6ea0a6856d7so804394a34.1; Tue, 30 Apr 2024 03:47:47 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCUU62zyOzw/kiGVC6iSrqHCLfqb3vHRv2XbjcjM6Rc01TXYFZ24XBiu7V4cmJ1ldVlEoDC08pQlpWK5+Tl8VDrqKWyyjAX2++hs/2sn7RwRRBkOWTiyhg48TWYzR5lwIupz6IsDQciF6RR11QO+Q1DLhQvAOBNqtV7/6fQJ4j996OTI5tvyI07uL92xodlnWtb7j79ezYq+bBPN64ozWg== X-Gm-Message-State: AOJu0Yyzkj/KMMLroO2YLMa/cBeKISxvpUZtGk4xXFLOGgBGq/2f7AyG gIL1VWhKIAPzwUTN+c50dQNDHA7dndJDGh1DC0aabvwoHWZaQ8DIQyXY0VsQXB9hnaJ+PZTOS0Q GSAFM7zeekn5RdHgDSyBtHfbLjps= X-Received: by 2002:a4a:9287:0:b0:5af:be60:ccdc with SMTP id i7-20020a4a9287000000b005afbe60ccdcmr3602815ooh.0.1714474066271; Tue, 30 Apr 2024 03:47:46 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240426135126.12802-1-Jonathan.Cameron@huawei.com> <20240426135126.12802-5-Jonathan.Cameron@huawei.com> <80a2e07f-ecb2-48af-b2be-646f17e0e63e@redhat.com> <20240430102838.00006e04@Huawei.com> <20240430111341.00003dba@huawei.com> <20240430114534.0000600e@huawei.com> In-Reply-To: <20240430114534.0000600e@huawei.com> From: "Rafael J. Wysocki" Date: Tue, 30 Apr 2024 12:47:34 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v8 04/16] ACPI: processor: Move checks and availability of acpi_processor earlier To: Jonathan Cameron Cc: "Rafael J. Wysocki" , Gavin Shan , 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 , Miguel Luis , James Morse , Salil Mehta , Jean-Philippe Brucker , Catalin Marinas , Will Deacon , Marc Zyngier , Hanjun Guo , Ingo Molnar , Borislav Petkov , Dave Hansen , linuxarm@huawei.com, justin.he@arm.com, jianyong.wu@arm.com, Lorenzo Pieralisi , Sudeep Holla Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Apr 30, 2024 at 12:45=E2=80=AFPM Jonathan Cameron wrote: > > On Tue, 30 Apr 2024 12:17:38 +0200 > "Rafael J. Wysocki" wrote: > > > On Tue, Apr 30, 2024 at 12:13=E2=80=AFPM Jonathan Cameron > > wrote: > > > > > > On Tue, 30 Apr 2024 10:28:38 +0100 > > > Jonathan Cameron wrote: > > > > > > > On Tue, 30 Apr 2024 14:17:24 +1000 > > > > Gavin Shan wrote: > > > > > > > > > On 4/26/24 23:51, 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 ac= cess > > > > > > to the acpi_handle to distinguish between acpi_processor_add() > > > > > > and earlier registration attempts (which will fail as _STA cann= ot > > > > > > 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 > > > > > > > > > > > > --- > > > > > > v8: On buggy bios detection when setting per_cpu structures > > > > > > do not carry on. > > > > > > Fix up the clearing of per cpu structures to remove unwant= ed > > > > > > side effects and ensure an error code isn't use to referen= ce them. > > > > > > --- > > > > > > drivers/acpi/acpi_processor.c | 79 +++++++++++++++++++++-----= --------- > > > > > > 1 file changed, 48 insertions(+), 31 deletions(-) > > > > > > > > > > > > diff --git a/drivers/acpi/acpi_processor.c b/drivers/acpi/acpi_= processor.c > > > > > > index ba0a6f0ac841..3b180e21f325 100644 > > > > > > --- a/drivers/acpi/acpi_processor.c > > > > > > +++ b/drivers/acpi/acpi_processor.c > > > > > > @@ -183,8 +183,38 @@ static void __init acpi_pcc_cpufreq_init(v= oid) {} > > > > > > #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 >=3D nr_cpu_ids); > > > > > > > > > > One blank line after BUG_ON() if we need to follow original imple= mentation. > > > > > > > > Sure unintentional - I'll put that back. > > > > > > > > > > > > > > > + /* > > > > > > + * 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) !=3D NULL && > > > > > > + per_cpu(processor_device_array, pr->id) !=3D device) { > > > > > > + dev_warn(&device->dev, > > > > > > + "BIOS reported wrong ACPI id %d for the proc= essor\n", > > > > > > + pr->id); > > > > > > + /* Give up, but do not abort the namespace scan. */ > > > > > > > > > > It depends on how the return value is handled by the caller if th= e namespace > > > > > is continued to be scanned. The caller can be acpi_processor_hota= dd_init() > > > > > and acpi_processor_get_info() after this patch is applied. So I t= hink this > > > > > specific comment need to be moved to the caller. > > > > > > > > Good point. This gets messy and was an unintended change. > > > > > > > > Previously the options were: > > > > 1) acpi_processor_get_info() failed for other reasons - this code w= as never called. > > > > 2) acpi_processor_get_info() succeeded without acpi_processor_hotad= d_init (non hotplug) > > > > this code then ran and would paper over the problem doing a bunc= h of cleanup under err. > > > > 3) acpi_processor_get_info() succeeded with acpi_processor_hotadd_i= nit called. > > > > This code then ran and would paper over the problem doing a bunc= h of cleanup under err. > > > > > > > > We should maintain that or argue cleanly against it. > > > > > > > > This isn't helped the the fact I have no idea which cases we care a= bout for that bios > > > > bug handling. Do any of those bios's ever do hotplug? Guess we ha= ve to try and maintain > > > > whatever protection this was offering. > > > > > > > > Also, the original code leaks data in some paths and I have limited= idea > > > > of whether it is intentional or not. So to tidy the issue up that y= ou've identified > > > > I'll need to try and make that code consistent first. > > > > > > > > I suspect the only way to do that is going to be to duplicate the a= llocations we > > > > 'want' to leak to deal with the bios bug detection. > > > > > > > > For example acpi_processor_get_info() failing leaks pr and pr->thro= ttling.shared_cpu_map > > > > before this series. After this series we need pr to leak because it= 's used for the detection > > > > via processor_device_array. > > > > > > > > I'll work through this but it's going to be tricky to tell if we ge= t right. > > > > Step 1 will be closing the existing leaks and then we will have som= ething > > > > consistent to build on. > > > > > > > I 'think' that fixing the original leaks makes this all much more str= aight forward. > > > That return 0 for acpi_processor_get_info() never made sense as far a= s I can tell. > > > The pr isn't used after this point. > > > > > > What about something along lines of. > > > > > > diff --git a/drivers/acpi/acpi_processor.c b/drivers/acpi/acpi_proces= sor.c > > > index 161c95c9d60a..97cff4492304 100644 > > > --- a/drivers/acpi/acpi_processor.c > > > +++ b/drivers/acpi/acpi_processor.c > > > @@ -392,8 +392,10 @@ static int acpi_processor_add(struct acpi_device= *device, > > > device->driver_data =3D pr; > > > > > > result =3D acpi_processor_get_info(device); > > > - if (result) /* Processor is not physically present or unavail= able */ > > > - return 0; > > > + if (result) { /* Processor is not physically present or unava= ilable */ > > > + result =3D 0; > > > > As per my previous message (just sent) this should be an error code, > > as returning 0 from acpi_processor_add() is generally problematic. > Ok. I'll switch to that, but as a separate precusor patch. Independent of > the memory leak fixes. Sure, thank you!