Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp128195lqb; Tue, 16 Apr 2024 10:35:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWjKYzsWctcAMpTcUFYcrnqqj5Htao8+ejqWQNHy4wbHX/HGAGM+Y2kddmndZ3eBPAbOcKmv0fu/wkS8nqgJ/AhnpBOoi4gPtyyljuiQw== X-Google-Smtp-Source: AGHT+IG5snkSU17LomNFSJTAwNglpYQWaoIxIdNX/0I9PJu1g23yNXDwhUqTXPywqvHYwlqg71Q1 X-Received: by 2002:a17:907:1c0d:b0:a4e:7a36:4c38 with SMTP id nc13-20020a1709071c0d00b00a4e7a364c38mr12888378ejc.20.1713288924376; Tue, 16 Apr 2024 10:35:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713288924; cv=pass; d=google.com; s=arc-20160816; b=EN/Gl7FF2hKf0Tu2ZlFxXEPcX42iWvWFC/0Zsll8ekSp1N8FtOUMvMv/wJK6g57amZ c3li0jGWZx6tg4ybunldV7wLSBo8OzLAaNAVdAdXdgsgHuO6GkckqsmMF9oD7aX5Rovm bA5TL97wbXFYl/wWD9ll7EC63RykaPDVBirs1ntxroJot5soX/BieZdo2HmnBgCaTg5o DL0Uu2lrJGRGvh8bW+OQcD1tT4Key0W5udCPPeGOcBn7PCH83wUPLc3nXbDpuco1LjXQ DMRkRUwiBegrWZwjVDsbfqBg3dVy88pWEaIgzMsQKRgGSWpigMt3WHE9Qr/8TKi9Qvm1 T7VQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:organization:references :in-reply-to:message-id:subject:cc:to:from:date; bh=8OoQjc2SqlKAL3boX29fVynADUNk5Te72ii3+mKHu8U=; fh=rF0euBRnOtvpvXnq8+9Ub4hOunsjlh5BwWPvJFMJFgo=; b=Dsjbe61CR4JTJqPo/r4Jr2H6S8BLfUl+xK372hKS38mVnDI1pNKWdq1KJO8vUyZrmP V77Y9CpCtzcacJ/7u484RpAEUeMciyaSFhDmxwA0Fi7k8rz9hAbMznIBrciqAa72Aocv X/ntwyx8e4gXYRTEjHuLFpwMToqZ0wfTnsoMkVhN8ATsHj2UtOYWmv0pPW6gfb+1GAVB GE/RfnMJfhvP46xk/QT6QIAiOCirzvZ42yGkQBOSvX/uaC+vPLvWMRqD5Cr8p33mvwxu dIRalm0K8jd1NL9YACTIvq3ngKnmj2azr4ncBPJQrbTNKtBihCNkChrSNJVujbbQqXWn VYng==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-147319-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147319-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id hp15-20020a1709073e0f00b00a51a9b05607si5727578ejc.411.2024.04.16.10.35.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 10:35:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-147319-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; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-147319-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147319-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.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 am.mirrors.kernel.org (Postfix) with ESMTPS id EDD0A1F2354F for ; Tue, 16 Apr 2024 17:35:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1D8F3134402; Tue, 16 Apr 2024 17:35:11 +0000 (UTC) Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (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 4EF311327FB; Tue, 16 Apr 2024 17:35:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713288910; cv=none; b=FjMQWTKT78d7YKHeWMqIdCDxzYNeemwk/I8yyv5uHlbuwC+A2DojC2LhvROT5pklawV0wpk82iJcUJaiKkAS5hCMObE7Zv0rf3YADgo26mTlXxB5+rWujaYBq2+aB7W779VWoiw494rsikPTK8B/7kgpfmtpyZKVr+U6rtz8nKs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713288910; c=relaxed/simple; bh=Z7BK1ffY1oFsL11vJXHcwMHmQHUgwlPvHa/5kupznIc=; h=Date:From:To:CC:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=rd2fGRHEhYMLy2hPL0iPECZ5e7lUIJ7LJBHbvhBCCdi7/FpFxmMicltBdLK47qdL5sMdyC2uNracLnLiVwrkqGdX8YHpN72UP7pdUdbxFpy6FAOGBDSzzetX0603wMf1o8CVOeisgTAA0QO6t7NwVGijzDQYCFMS7SiQkoBOgDE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=Huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=Huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.31]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4VJrdq4sLxz6K8xC; Wed, 17 Apr 2024 01:30:07 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id 185F11400D3; Wed, 17 Apr 2024 01:35:04 +0800 (CST) Received: from localhost (10.202.227.76) 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.35; Tue, 16 Apr 2024 18:35:03 +0100 Date: Tue, 16 Apr 2024 18:35:02 +0100 From: Jonathan Cameron To: "Rafael J. Wysocki" CC: , , , , , , , , , Russell King , Miguel Luis , James Morse , Salil Mehta , Jean-Philippe Brucker , Catalin Marinas , Will Deacon , , Subject: Re: [PATCH v5 02/18] ACPI: processor: Set the ACPI_COMPANION for the struct cpu instance Message-ID: <20240416183502.00007527@Huawei.com> In-Reply-To: References: <20240412143719.11398-1-Jonathan.Cameron@huawei.com> <20240412143719.11398-3-Jonathan.Cameron@huawei.com> <20240415164854.0000264f@Huawei.com> <20240415175057.00002e11@Huawei.com> <20240415183454.000072f6@Huawei.com> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: lhrpeml100002.china.huawei.com (7.191.160.241) To lhrpeml500005.china.huawei.com (7.191.163.240) On Mon, 15 Apr 2024 19:41:43 +0200 "Rafael J. Wysocki" wrote: > On Mon, Apr 15, 2024 at 7:35=E2=80=AFPM Jonathan Cameron > wrote: > > > > On Mon, 15 Apr 2024 17:50:57 +0100 > > Jonathan Cameron wrote: > > =20 > > > On Mon, 15 Apr 2024 18:19:17 +0200 > > > "Rafael J. Wysocki" wrote: > > > =20 > > > > On Mon, Apr 15, 2024 at 6:16=E2=80=AFPM Rafael J. Wysocki wrote: =20 > > > > > > > > > > On Mon, Apr 15, 2024 at 5:49=E2=80=AFPM Jonathan Cameron > > > > > wrote: =20 > > > > > > > > > > > > On Fri, 12 Apr 2024 20:10:54 +0200 > > > > > > "Rafael J. Wysocki" wrote: > > > > > > =20 > > > > > > > On Fri, Apr 12, 2024 at 4:38=E2=80=AFPM Jonathan Cameron > > > > > > > wrote: =20 > > > > > > > > > > > > > > > > The arm64 specific arch_register_cpu() needs to access the = _STA > > > > > > > > method of the DSDT object so make it available by assigning= the > > > > > > > > appropriate handle to the struct cpu instance. > > > > > > > > > > > > > > > > Signed-off-by: Jonathan Cameron > > > > > > > > --- > > > > > > > > drivers/acpi/acpi_processor.c | 3 +++ > > > > > > > > 1 file changed, 3 insertions(+) > > > > > > > > > > > > > > > > diff --git a/drivers/acpi/acpi_processor.c b/drivers/acpi/a= cpi_processor.c > > > > > > > > index 7a0dd35d62c9..93e029403d05 100644 > > > > > > > > --- a/drivers/acpi/acpi_processor.c > > > > > > > > +++ b/drivers/acpi/acpi_processor.c > > > > > > > > @@ -235,6 +235,7 @@ static int acpi_processor_get_info(stru= ct acpi_device *device) > > > > > > > > union acpi_object object =3D { 0 }; > > > > > > > > struct acpi_buffer buffer =3D { sizeof(union acpi_o= bject), &object }; > > > > > > > > struct acpi_processor *pr =3D acpi_driver_data(devi= ce); > > > > > > > > + struct cpu *c; > > > > > > > > int device_declaration =3D 0; > > > > > > > > acpi_status status =3D AE_OK; > > > > > > > > static int cpu0_initialized; > > > > > > > > @@ -314,6 +315,8 @@ static int acpi_processor_get_info(stru= ct acpi_device *device) > > > > > > > > cpufreq_add_device("acpi-cpufreq"); > > > > > > > > } > > > > > > > > > > > > > > > > + c =3D &per_cpu(cpu_devices, pr->id); > > > > > > > > + ACPI_COMPANION_SET(&c->dev, device); =20 > > > > > > > > > > > > > > This is also set for per_cpu(cpu_sys_devices, pr->id) in > > > > > > > acpi_processor_add(), via acpi_bind_one(). =20 > > > > > > > > > > > > Hi Rafael, > > > > > > > > > > > > cpu_sys_devices gets filled with a pointer to this same structu= re. > > > > > > The contents gets set in register_cpu() so at this point > > > > > > it doesn't point anywhere. As a side note register_cpu() > > > > > > memsets to zero the value I set it to in the code above which i= sn't > > > > > > great, particularly as I want to use this in post_eject for > > > > > > arm64. > > > > > > > > > > > > We could make a copy of the handle and put it back after > > > > > > the memset in register_cpu() but that is also ugly. > > > > > > It's the best I've come up with to make sure this is still set > > > > > > come remove time but is rather odd. =20 > > > > > > > > > > > > > > Moreover, there is some pr->id validation in acpi_processor_a= dd(), so > > > > > > > it seems premature to use it here this way. > > > > > > > > > > > > > > I think that ACPI_COMPANION_SET() should be called from here = on > > > > > > > per_cpu(cpu_sys_devices, pr->id) after validating pr->id (so = the > > > > > > > pr->id validation should all be done here) and then NULL can = be passed > > > > > > > as acpi_dev to acpi_bind_one() in acpi_processor_add(). Then= , there > > > > > > > will be one physical device corresponding to the processor AC= PI device > > > > > > > and no confusion. =20 > > > > > > > > > > > > I'm fairly sure this is pointing to the same device but agreed = this > > > > > > is a tiny bit confusing. However we can't use cpu_sys_devices a= t this point > > > > > > so I'm not immediately seeing a cleaner solution :( =20 > > > > > > > > > > Well, OK. > > > > > > > > > > Please at least consider doing the pr->id validation checks before > > > > > setting the ACPI companion for &per_cpu(cpu_devices, pr->id). > > > > > > > > > > Also, acpi_bind_one() needs to be called on the "physical" devices > > > > > passed to ACPI_COMPANION_SET() (with NULL as the second argument)= for > > > > > the reference counting and physical device lookup to work. > > > > > > > > > > Please also note that acpi_primary_dev_companion() should return > > > > > per_cpu(cpu_sys_devices, pr->id) for the processor ACPI device, w= hich > > > > > depends on the order of acpi_bind_one() calls involving the same = ACPI > > > > > device. =20 > > > > > > > > Of course, if the value set by ACPI_COMPANION_SET() is cleared > > > > subsequently, the above is not needed, but then using > > > > ACPI_COMPANION_SET() is questionable overall. =20 > > > > > > Agreed + smoothing over that by stashing and putting it back doesn't > > > work because there is an additional call to acpi_bind_one() inbetween > > > here and the one you reference. > > > > > > The arch_register_cpu() calls end up calling register_cpu() / > > > device_register() / acpi_device_notify() / acpi_bind_one() > > > > > > With current code that fails (silently) =20 >=20 > And that's why there is an explicit acpi_bind_one() invocation in > acpi_processor_add(). >=20 > > > If I make sure the handle is set before register_cpu() then it > > > succeeds, but we end up with duplicate sysfs files etc because we > > > bind twice. =20 >=20 > Right, I should have recalled that earlier. >=20 > > > I think the only way around this is larger reorganization of the > > > CPU hotplug code to pull the arch_register_cpu() call to where > > > the acpi_bind_one() call is. However that changes a lot more than I'= d like > > > (and I don't have it working yet). =20 >=20 > I see. >=20 > > > Alternatively find somewhere else to stash the handle, or just add it= as > > > a parameter to arch_register_cpu(). Right now this feels the easier > > > path to me. arch_register_cpu(int cpu, acpi_handle handle) > > > > > > Would that be a path you'd consider? =20 > > > > Another option would be to do the per_cpu(processors, pr->id) =3D pr > > a few lines earlier than currently and access that directly from the > > arch_register_cpu() call. Similarly remove that reference a bit later = and > > use it in arch_unregister_cpu(). > > > > This seems like the simplest solution, but I may be missing something. = =20 >=20 > This should work AFAICS, but I'd move the entire piece of code between > BUG_ON() and setting per_cpu(processors, pr->id) inclusive: Hi Rafael, Unfortunately this is more complex on x86 than I realized :( On x86 the initial pr->id is invalid, which is one of the conditions that leads to acpi_processor_hotadd_init() being called. It only become valid after acpi_map_cpu() in acpi_processor_hotadd_init(). So the best I can immediately come up with is to factor out these checks an= d the setting of the per_cpu structures and set them either in acpi_processor_hot= add_init() or in an else for the non hotplug / normal registration path (where the pr-= >id is valid). Naturally found this on my final set of tests... A little ugly but not 'too bad'.=20 Jonathan p.s. No one minds if I break x86, right? >=20 > BUG_ON(pr->id >=3D nr_cpu_ids); >=20 > /* > * 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 processor\n", > pr->id); > /* Give up, but do not abort the namespace scan. */ > goto err; > } > /* > * processor_device_array is not cleared on errors to allow buggy BIOS > * checks. > */ > per_cpu(processor_device_array, pr->id) =3D device; > per_cpu(processors, pr->id) =3D pr; >=20 > into acpi_processor_get_info(), right after the point where pr->id is set.