Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp623672rwr; Thu, 27 Apr 2023 06:13:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7jpcitHZNzfU7t425ULZQ1fXjd7js0F5tyCRP/Z3LP9BvZbsGlXoQtq2oKC47oSy3sA0DS X-Received: by 2002:a17:903:124c:b0:1a6:6bdb:b548 with SMTP id u12-20020a170903124c00b001a66bdbb548mr1873983plh.1.1682601223604; Thu, 27 Apr 2023 06:13:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682601223; cv=none; d=google.com; s=arc-20160816; b=XSiWx+cp1CjUz0i5Zng6tyu9Mnnwo9x6EgG15sGhwIQOgq6AOUPw5l5EuFihqlsr/H S1qvWfo33ZPO5w8814wOee4FLFO8bbDFa4MuhGhjxqU7B4seJwP0E+JB8MsyxxteT366 SF4xNY+HtqOAT6EjZazHiBxu6s+WQHdLyBezhsGx23NZq9WSIBxrKd7vTnV0mJ7gRhRV iP3l1LPDsb/OWX5n4RVcYeAj9cFGrAhGVR3iYSkKoKWZxZITui2oRF4XGkMAxHNQp/w7 3jOWpfv/IuGPpM3EEoE6ceilxSM/ARltLdAxsIXDz/EaHgG9h6zTH5/9UWRmJV7wJh/y ih4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=9ymSyk174Q/aRoWNbYUHHG8erPdr3iK0BpQYJmy801k=; b=IWCu8fscdzFl+6VCPVu2FiNW5+c5WDX1bCwLXpQjL9wWjMFY0gTyetV4QNJ5MpGPn1 uCvsq0quPDN7hJRDzuJTOK1hYjyq8YucRR79BDLCxhTqG7+aRZ9/RVXF5xH6WShQBeYG RKMGYoEloBg8bRYp7ZlFPHtpOTAURFG2QYLtNtx0/3qyNh9eoZle5F+udTaFcXm4ImFt TF7LIieah7PWFMnQCVH58A86ry+f6l3L/iT8DIahjQHGWXFuOBI2HfRGxRsz5dU0R5Il pAcYb8QIDn3gL8GzGp3c1DfngEc1pMcHxmiHynEuyxiWiYgvDvBmzYCz/1l84G0DczzU aDwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=HIgpg5N7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s2-20020a17090ad48200b00246ff6d046asi18321683pju.94.2023.04.27.06.13.28; Thu, 27 Apr 2023 06:13:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=HIgpg5N7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243615AbjD0NNV (ORCPT + 99 others); Thu, 27 Apr 2023 09:13:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243404AbjD0NNT (ORCPT ); Thu, 27 Apr 2023 09:13:19 -0400 Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EF0A3C29 for ; Thu, 27 Apr 2023 06:13:17 -0700 (PDT) Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-5051abd03a7so12560063a12.2 for ; Thu, 27 Apr 2023 06:13:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1682601195; x=1685193195; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=9ymSyk174Q/aRoWNbYUHHG8erPdr3iK0BpQYJmy801k=; b=HIgpg5N7XJjzbxz+z7IgxgVQ5128JI4dtyixvRnwGndbaq5YVIPtJHd+DaOorca26k cr99XyR833joae9EIrXDFvGYDfgdx97lSuMToDnUqFhu9JA7SVMQJHER3oDi1Rp3QEOF mLPJ2w5t3aMH0JrLeMU3g1mTm+pQghwAf7n/nH6OPPuRRH8u1MJicYy4tnsZoD/6nenc EeThR0OHBw47zlfBPnB+cq15TJ0QLrtuGCvLMwLcZZYUg6DqV/RYw9pkk1E3rpyPuXst ayDxj8TjQBJExMKsUnsMDqZQTfzm6bZlQ6b/oOXxuNOUqTuU/9i+0PZUQfGkDAoFnKXE v4wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682601195; x=1685193195; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=9ymSyk174Q/aRoWNbYUHHG8erPdr3iK0BpQYJmy801k=; b=hdrd54fdimaKrKnVgZyEv3pE3QmNEv29/MgOpcVTmMPxsuv0aoOzZ4l3SiRqTu3UQm vxDUJ0M0TADvm1GTP1Jm0mzg9VjdbLPJWfe57YoVUJcFuwXdESVsRPmyzOKfTVkQWsEA z1KtqxdYwdT0IWpZ8yTRAmWe32TzKV29AFcslf3erDJG9aWEy4UajTOJPguJosAajWhn AF7OaQzugUyDzBJi9rK8PgaR7KrvhPVh/3uqnoeu3Xkw/tolEPsZCCiktT2sWS2YQR6c 5/u7YblpsCGVFPrca8mozS96o68MC9Nfyp9WoraKqho07FzDzrI+JxBrjHGnvvUrJcHD k/7w== X-Gm-Message-State: AC+VfDwESXEAEi0mj5o3JaMP/e3CCwZzyvtbHeapwZR0ctWIJLRZzr4v L6zVdnZwdgUeyaInIwC2Rb/QyQ== X-Received: by 2002:a17:907:7da9:b0:94b:cd7c:59f4 with SMTP id oz41-20020a1709077da900b0094bcd7c59f4mr1742934ejc.16.1682601195517; Thu, 27 Apr 2023 06:13:15 -0700 (PDT) Received: from localhost (cst2-173-16.cust.vodafone.cz. [31.30.173.16]) by smtp.gmail.com with ESMTPSA id t25-20020a17090616d900b009534603453dsm9503863ejd.131.2023.04.27.06.13.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 06:13:14 -0700 (PDT) Date: Thu, 27 Apr 2023 15:13:13 +0200 From: Andrew Jones To: Sunil V L Cc: Palmer Dabbelt , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-acpi@vger.kernel.org, linux-crypto@vger.kernel.org, platform-driver-x86@vger.kernel.org, llvm@lists.linux.dev, corbet@lwn.net, Paul Walmsley , aou@eecs.berkeley.edu, lenb@kernel.org, daniel.lezcano@linaro.org, tglx@linutronix.de, qianweili@huawei.com, wangzhou1@hisilicon.com, herbert@gondor.apana.org.au, Marc Zyngier , luzmaximilian@gmail.com, hdegoede@redhat.com, markgross@kernel.org, nathan@kernel.org, ndesaulniers@google.com, trix@redhat.com, rafael@kernel.org, davem@davemloft.net, rafael.j.wysocki@intel.com Subject: Re: [PATCH V4 08/23] RISC-V: ACPI: Cache and retrieve the RINTC structure Message-ID: References: <20230404182037.863533-9-sunilvl@ventanamicro.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 27, 2023 at 04:22:56PM +0530, Sunil V L wrote: > On Thu, Apr 27, 2023 at 12:25:42PM +0200, Andrew Jones wrote: > > On Thu, Apr 27, 2023 at 02:52:50PM +0530, Sunil V L wrote: > > > Hi Palmer, > > > > > > On Wed, Apr 26, 2023 at 11:45:00AM -0700, Palmer Dabbelt wrote: > > > > On Tue, 04 Apr 2023 11:20:22 PDT (-0700), sunilvl@ventanamicro.com wrote: > > > > > RINTC structures in the MADT provide mapping between the hartid > > > > > and the CPU. This is required many times even at run time like > > > > > cpuinfo. So, instead of parsing the ACPI table every time, cache > > > > > the RINTC structures and provide a function to get the correct > > > > > RINTC structure for a given cpu. > > > > > > > > > > Signed-off-by: Sunil V L > > > > > Acked-by: Rafael J. Wysocki > > > > > --- > > > > > arch/riscv/include/asm/acpi.h | 2 ++ > > > > > arch/riscv/kernel/acpi.c | 60 +++++++++++++++++++++++++++++++++++ > > > > > 2 files changed, 62 insertions(+) > > > > > > > > > > diff --git a/arch/riscv/include/asm/acpi.h b/arch/riscv/include/asm/acpi.h > > > > > index 9be52b6ffae1..1606dce8992e 100644 > > > > > --- a/arch/riscv/include/asm/acpi.h > > > > > +++ b/arch/riscv/include/asm/acpi.h > > > > > @@ -59,6 +59,8 @@ static inline bool acpi_has_cpu_in_madt(void) > > > > > > > > > > static inline void arch_fix_phys_package_id(int num, u32 slot) { } > > > > > > > > > > +struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu); > > > > > +u32 get_acpi_id_for_cpu(int cpu); > > > > > #endif /* CONFIG_ACPI */ > > > > > > > > > > #endif /*_ASM_ACPI_H*/ > > > > > diff --git a/arch/riscv/kernel/acpi.c b/arch/riscv/kernel/acpi.c > > > > > index 81d448c41714..40ab55309c70 100644 > > > > > --- a/arch/riscv/kernel/acpi.c > > > > > +++ b/arch/riscv/kernel/acpi.c > > > > > @@ -24,6 +24,66 @@ EXPORT_SYMBOL(acpi_disabled); > > > > > int acpi_pci_disabled = 1; /* skip ACPI PCI scan and IRQ initialization */ > > > > > EXPORT_SYMBOL(acpi_pci_disabled); > > > > > > > > > > +static struct acpi_madt_rintc cpu_madt_rintc[NR_CPUS]; > > > > > + > > > > > +static int acpi_parse_madt_rintc(union acpi_subtable_headers *header, const unsigned long end) > > > > > +{ > > > > > + struct acpi_madt_rintc *rintc = (struct acpi_madt_rintc *)header; > > > > > + int cpuid; > > > > > + > > > > > + if (!(rintc->flags & ACPI_MADT_ENABLED)) > > > > > + return 0; > > > > > + > > > > > + cpuid = riscv_hartid_to_cpuid(rintc->hart_id); > > > > > > > > Unless I'm missing something, this races with CPUs coming online. Maybe > > > > that's a rare enough case we don't care, but I think we'd also just have > > > > simpler logic if we fixed it... > > > > > > > This depend only on cpuid_to_hartid_map filled up. I wish I could > > > initialize this RINTC mapping in setup_smp() itself like ARM64. But in > > > RISC-V, this file smpboot.c gets built only when CONFIG_SMP is enabled. > > > Hence, we need to initialize this array outside of setup_smp(). > > > > > > I can update the code to initialize this from setup_arch() immediately > > > after setup_smp() if ACPI is enabled. That should avoid the global > > > variable check also. Let me know if you prefer this. > > > > > > > > + /* > > > > > + * When CONFIG_SMP is disabled, mapping won't be created for > > > > > + * all cpus. > > > > > + * CPUs more than NR_CPUS, will be ignored. > > > > > + */ > > > > > + if (cpuid >= 0 && cpuid < NR_CPUS) > > > > > + cpu_madt_rintc[cpuid] = *rintc; > > > > > + > > > > > + return 0; > > > > > +} > > > > > + > > > > > +static int acpi_init_rintc_array(void) > > > > > +{ > > > > > + if (acpi_table_parse_madt(ACPI_MADT_TYPE_RINTC, acpi_parse_madt_rintc, 0) > 0) > > > > > + return 0; > > > > > + > > > > > + return -ENODEV; > > > > > +} > > > > > + > > > > > +/* > > > > > + * Instead of parsing (and freeing) the ACPI table, cache > > > > > + * the RINTC structures since they are frequently used > > > > > + * like in cpuinfo. > > > > > + */ > > > > > +struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu) > > > > > +{ > > > > > + static bool rintc_init_done; > > > > > > > > ... basically just get rid of this global variable, and instead have a > > > > > > > > if (!&cpu_madt_rintc[cpu]) > > > > ... parse ... > > > > return &cpu_madt_rintc[cpu]; > > > > > > > > that'd probably let us get rid of a handful of these helpers too, as now > > > > it's just a call to the parsing bits. > > > > > > > I am afraid this (!&cpu_madt_rintc[cpu]) check won't work since we are > > > not caching the RINTC pointers but actual contents itself. So, the > > > address is always valid. However, as per Drew's earlier feedback I am > > > going to reduce one helper. I am planning to send the next version of > > > this patch once 6.4 rc1 is available since the ACPICA patches are merged > > > now. > > > > > > > > + > > > > > + if (!rintc_init_done) { > > > > > + if (acpi_init_rintc_array()) { > > > > > + pr_err("No valid RINTC entries exist\n"); > > > > > + return NULL; > > > > > + } > > > > > + > > > > > + rintc_init_done = true; > > > > > + } > > > > > + > > > > > + return &cpu_madt_rintc[cpu]; > > > > > +} > > > > > + > > > > > +u32 get_acpi_id_for_cpu(int cpu) > > > > > +{ > > > > > + struct acpi_madt_rintc *rintc = acpi_cpu_get_madt_rintc(cpu); > > > > > + > > > > > + BUG_ON(!rintc); > > > > > > > > We should have some better error reporting here. It looks like all the > > > > callerss of get_acpi_id_for_cpu() are tolerant of a nonsense ID being > > > > returned, so maybe we just pr_warn() something users can understand and then > > > > return -1 or something? > > > > > > > > > > RINTC is mandatory for ACPI systems. Also, all 32bit values are valid > > > for UID. So, there is no bogus value we can return. > > > > > > Actually, I just realized this check is redundant. It will never be NULL > > > since it is a static array. So, we can just get rid of the BUG. > > > > It can be NULL on the first call of acpi_cpu_get_madt_rintc(), which is > > a good time to BUG if there's isn't an RINTC. > > > Sorry, I mean if we change the initialization to get called from > setup_arch, then we can get rid of this check along with global variable > check, correct? Sounds good to me, but now I think we're pushing the question of whether to BUG or not on a missing RINTC to that new init function, because otherwise we'll still end up in get_acpi_id_for_cpu() eventually with or without a valid rintc from which we get the uid (and the uid has no specified bogus value). Thanks, drew