Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1236702lqa; Mon, 29 Apr 2024 02:21:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU9jGF48iS4j9ddLrpDbwMex1qyPvftBOzMxm8aap5Xaz7YJpqHeYQnpvJJy7J7cWr3uFFc1TL5tQ65MeYUqPoY+fxxGbplWp+Jw4Kg6w== X-Google-Smtp-Source: AGHT+IH7PlnWD62VCec6OuAor+QCAY8n/ZsKwqQ+M4HKsrqpooXKNNXQNWgGDfYhqknX9HC4VgSR X-Received: by 2002:a9d:6558:0:b0:6eb:df08:752d with SMTP id q24-20020a9d6558000000b006ebdf08752dmr12779004otl.11.1714382509254; Mon, 29 Apr 2024 02:21:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714382509; cv=pass; d=google.com; s=arc-20160816; b=HmB8pLQn39bC/6d9/Tr+DZ/uwztH/wmhmGKhDxJrYU1iT6+CnSyCUFGhs8pbqCvMOB 19IcCX/2IlUJ+nXHEdHOPTYQg/YTcPaU39Otw51iLajimtsUA++5qRnfsmuZSJl5XlsH lIiEj790mdMyFIf4FXmfREFLpFkUZto2k+cAr4cDPInb64L31NKNNGqsTHMLIITB/ZAz T/5l/0dk2yi/ReStW3y1QAwMoW4ov5qehHHFI8u/AYlnUWVYXVBlGYL3jinc6VEzV9yR avZSjdSj5h8lF4JnT//HUei1HgPglbf7DQXBLJN+FhLIrrCB/WLDUTXhvqdhPhCLdtYh MyCg== 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=13Auz6TY7uQ68DUuVsDgQy++HeZYuKNsXvCK2RbTVXw=; fh=VHyIJamHBEsbAmOgmMvtdaE2SQUshA1/AqQunn0nIW4=; b=KlWZ59u7OWCTlI57cvowrag4ih/tagW2Xl1+p71R30i6GUojfvoPDo9TIgfhGcjUGc snQuL8fybA6FUDTnFDzM6BUdhM5xX8DcF4lPv2GXXblBIVzVCP6t/MWn4CT4XDM99sIF yALvN6AS885ZcH7dIhP0FrnsHHXA4i0eilkGS+HJrlNuoMHmcT88TcySLxZO2kD2yqbJ W7Se9PyBSK5cMxWYeg5jUcMWoFXBS6kXwOCEbbcaqi9Xwo7w39fyZiB2iyLwhA+6pPLl 4UbnSJIv6mKdAZlXPMDoOXxHfsDN+5DM0kSm5g+Uo21wFW9//QXIEjTb7qVzi1p/ToIT pxGA==; 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-161979-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-161979-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 75-20020a63014e000000b005feab3f4591si13923609pgb.152.2024.04.29.02.21.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 02:21:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-161979-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; 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-161979-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-161979-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id D423C282A6F for ; Mon, 29 Apr 2024 09:21:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7AB3F22EF5; Mon, 29 Apr 2024 09:21:39 +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 7F97C12E7F; Mon, 29 Apr 2024 09:21:36 +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=1714382498; cv=none; b=dwz1PVOxLrFpbbYcy0uDL1/nS6tjTKWyWTTcOVx2gOUmbA3gqBeCfD1PakWQgltf7F4WU51DIn7jvwGeYKZJFE5BZiC5Kf6O04UJ4DBONRUsS2kZMNejGIlPquV4MwWmxf5Wy9LR+3WWrc1JSflGkcvK/31J1hFpMSUgqCp943Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714382498; c=relaxed/simple; bh=psU9IiCnjLKZ0N5EAzULiwZffDrrX9StQx6qKklgmuY=; h=Date:From:To:CC:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lZdWHpeFMErwxFTNC6Emlsqh8NfoWXnR9LB0KZDq7RsX2z2yNMgFYuwd2LlrFieLwpHlGEW6JER0rUmSnE0vcpGRavy7BCcK7G/al4HaQRLw31S8PbFS+spk5U9cOF4DO3F/yWKnm7TsCPrHoaCv4FEPwJ6N+crKKbYMsapiTB4= 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.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4VSd751DX3z6K6pc; Mon, 29 Apr 2024 17:18:57 +0800 (CST) Received: from lhrpeml500005.china.huawei.com (unknown [7.191.163.240]) by mail.maildlp.com (Postfix) with ESMTPS id 21420140B63; Mon, 29 Apr 2024 17:21:34 +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; Mon, 29 Apr 2024 10:21:33 +0100 Date: Mon, 29 Apr 2024 10:21:31 +0100 From: Jonathan Cameron To: Marc Zyngier , CC: Thomas Gleixner , Peter Zijlstra , , , , , , , , , Russell King , "Rafael J . Wysocki" , Miguel Luis , "James Morse" , Salil Mehta , Jean-Philippe Brucker , Catalin Marinas , Will Deacon , Hanjun Guo , Ingo Molnar , Borislav Petkov , Dave Hansen , , , , "Lorenzo Pieralisi" , Sudeep Holla Subject: Re: [PATCH v8 11/16] irqchip/gic-v3: Add support for ACPI's disabled but 'online capable' CPUs Message-ID: <20240429101938.000027b2@huawei.com> In-Reply-To: <87frv5u3p8.wl-maz@kernel.org> References: <20240426135126.12802-1-Jonathan.Cameron@huawei.com> <20240426135126.12802-12-Jonathan.Cameron@huawei.com> <87il04t7j2.wl-maz@kernel.org> <20240426192858.000033d9@huawei.com> <87frv5u3p8.wl-maz@kernel.org> 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="US-ASCII" Content-Transfer-Encoding: 7bit X-ClientProxiedBy: lhrpeml500006.china.huawei.com (7.191.161.198) To lhrpeml500005.china.huawei.com (7.191.163.240) On Sun, 28 Apr 2024 12:28:03 +0100 Marc Zyngier wrote: > On Fri, 26 Apr 2024 19:28:58 +0100, > Jonathan Cameron wrote: > > > > > > I'll not send a formal v9 until early next week, so here is the current state > > if you have time to take another look before then. > > Don't bother resending this on my account -- you only sent it on > Friday and there hasn't been much response to it yet. There is still a > problem (see below), but looks otherwise OK. > > [...] > > > @@ -2363,11 +2381,25 @@ gic_acpi_parse_madt_gicc(union acpi_subtable_headers *header, > > (struct acpi_madt_generic_interrupt *)header; > > u32 reg = readl_relaxed(acpi_data.dist_base + GICD_PIDR2) & GIC_PIDR2_ARCH_MASK; > > u32 size = reg == GIC_PIDR2_ARCH_GICv4 ? SZ_64K * 4 : SZ_64K * 2; > > + int cpu = get_cpu_for_acpi_id(gicc->uid); > > I already commented that get_cpu_for_acpi_id() can... Indeed sorry - I blame Friday syndrome for me failing to address that. > > > void __iomem *redist_base; > > > > - if (!acpi_gicc_is_usable(gicc)) > > + /* Neither enabled or online capable means it doesn't exist, skip it */ > > + if (!(gicc->flags & (ACPI_MADT_ENABLED | ACPI_MADT_GICC_ONLINE_CAPABLE))) > > return 0; > > > > + /* > > + * Capable but disabled CPUs can be brought online later. What about > > + * the redistributor? ACPI doesn't want to say! > > + * Virtual hotplug systems can use the MADT's "always-on" GICR entries. > > + * Otherwise, prevent such CPUs from being brought online. > > + */ > > + if (!(gicc->flags & ACPI_MADT_ENABLED)) { > > + pr_warn("CPU %u's redistributor is inaccessible: this CPU can't be brought online\n", cpu); > > + cpumask_set_cpu(cpu, &broken_rdists); > > ... return -EINVAL, and then be passed to cpumask_set_cpu(), with > interesting effects. It shouldn't happen, but I trust anything that > comes from firmware tables as much as I trust a campaigning > politician's promises. This should really result in the RD being > considered unusable, but without affecting any CPU (there is no valid > CPU the first place). > > Another question is what get_cpu_for acpi_id() returns for a disabled > CPU. A valid CPU number? Or -EINVAL? It's a match function that works by iterating over 0 to nr_cpu_ids and if (uid == get_acpi_id_for_cpu(cpu)) So the question become does get_acpi_id_for_cpu() return a valid CPU number for a disabled CPU. That uses acpi_cpu_get_madt_gicc(cpu)->uid so this all gets a bit circular. That looks it up via cpu_madt_gicc[cpu] which after the proposed updated patch is set if enabled or online capable. There are however a few other error checks in acpi_map_gic_cpu_interface() that could lead to it not being set (MPIDR validity checks). I suspect all of these end up being fatal elsewhere which is why this hasn't blown up before. If any of those cases are possible we could get a null pointer dereference. Easy to harden this case via the following (which will leave us with -EINVAL. There are other call sites that might trip over this. I'm inclined to harden them as a separate issue though so as not to get in the way of this patch set. diff --git a/arch/arm64/include/asm/acpi.h b/arch/arm64/include/asm/acpi.h index bc9a6656fc0c..a407f9cd549e 100644 --- a/arch/arm64/include/asm/acpi.h +++ b/arch/arm64/include/asm/acpi.h @@ -124,7 +124,8 @@ static inline int get_cpu_for_acpi_id(u32 uid) int cpu; for (cpu = 0; cpu < nr_cpu_ids; cpu++) - if (uid == get_acpi_id_for_cpu(cpu)) + if (acpi_cpu_get_madt_gicc(cpu) && + uid == get_acpi_id_for_cpu(cpu)) return cpu; return -EINVAL; I'll spin an additional patch to make that change after testing I haven't messed it up. At the call site in gic_acpi_parse_madt_gicc() I'm not sure we can do better than just skipping setting broken_rdists. I'll also pull the declaration of that cpu variable down into this condition so it's more obvious we only care about it in this error path. Jonathan > > Thanks, > > M. >