Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp203263lqb; Tue, 16 Apr 2024 13:04:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWXLu9bwfFBok7Eemv/chUrwfQ+h8o/bigy6qEGEHmpbfFHYFC4NBERsorze/pfeX5r9FwmpmqapVt+680El/tCgcXmdR87YJtPGVIzYg== X-Google-Smtp-Source: AGHT+IHz4Y4ADxxD3ToUR5DaUrCcYVxfb1im6HjRfhAPWe1SwfcFRNStAbIhT0JfaCvTkFouZCqg X-Received: by 2002:a0c:e852:0:b0:699:2274:b229 with SMTP id l18-20020a0ce852000000b006992274b229mr15135484qvo.14.1713297849449; Tue, 16 Apr 2024 13:04:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713297849; cv=pass; d=google.com; s=arc-20160816; b=Tsm+exRnT9dKH75J3QoTRYjqYQ9o27Kf1DsUE0cp7sTYRpWGZognMXc9URlhoDULyV 7Hm8TItPlqm3w4afBGj7Cuaisi0mgwCW/3bO6oZuDIUO+7S3wkcg6ivV9iz6SQ139TeW OpNddsiO5PXzhRxD1aunOf8esi+HgGuPgjjCMINFbn5HykYNk1iUowCfE5NCDmEsLRfy xMq2IwO7nVDbrNMjNuT33Zx2HxGzHiy/S5WvkmAlSOs9Zp0nF745y/wD2QdBv9Y0uIhN a67oMwU98SRXprJ3wiDgQpD6kKmC5H4wMqG3HqrZxU3ogFIc3LsuEY2y1kg1r6A1+msy v3nQ== 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:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=nbcE90xuDry2aCSk9988wlaN5aA3byE5lbgb1P1YcSg=; fh=wuqZP5JbAVo6SKWP7iEIjnMMoqRj4uZ/o/T6vqmA+30=; b=b/+wmHKApQYT5KjJSp3af+ksV4WICXyrDQ4nLLDAdPoK5/dRIxc7PKrVL4/8XqNTJi QzNOFQTOTatB54xREJkMAvhVEe+HdavzmK3FI7aevjFTJsEpdO47C47/ShFpMk0E7w/1 vGoZkb4uTbgha0wNBlV7Jy9SstYIfh0tjJb6fx0WhYOU+AqSDB/R6f/J1Oux2a7sAzWh vCYQJiyaXbrmTjOH1cPTw3/IXH0kWWeRRsGZYwcqcc0bt3JxcTk03E920iYcdHBa8AL1 9MbIUqLn8MPwG8ehyX40hLbcRCoruI9ynKvObX/CP7+C/Vdx9WAOMCPUv3ug4B1duq+u R3Xg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-147493-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147493-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.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 jo14-20020a056214500e00b0069b4cc975b3si14782743qvb.134.2024.04.16.13.04.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 13:04:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-147493-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; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-147493-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147493-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.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 30F221C21794 for ; Tue, 16 Apr 2024 20:04:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 44A72139CE6; Tue, 16 Apr 2024 20:04:01 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2B2981CF8A; Tue, 16 Apr 2024 20:03:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713297840; cv=none; b=Jn+C8bmR2o3PN6BO/xXMu8IwVhIDCTQ2BMbqAfrpT0knFAEFMFUf/eJTqayYaBpApjsiBJFRKQ5Mtnd9U1Y3FohiZ00oAVlUPy1bZoSqB7F4nADGugMhrvZhoQD7rcR49TNQGYCJa3fkuSQFFqj8aKtxNP5q4z/WVVFj/kNl/Ww= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713297840; c=relaxed/simple; bh=5qLLMccxABZD/LLYQ5sprUAdT2RZypurlvipvjwR8nM=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type; b=Dbkd8WGIi/u+UA2ywaoi/K4iR4GNkO9Gk6yZycTZ8ysUtriI9lXfuy1koGr/+SD4/hwkTavucahpeQkpXWWAte790A+jXFPzweohhZPYJRojw+8mE05Yr86fGv1PFGrUA3sl4q9ttZmnYNVQGy7y9MvctPZhHWSSifAOLijOy/g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3CE32339; Tue, 16 Apr 2024 13:04:26 -0700 (PDT) Received: from [192.168.20.58] (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 244383F738; Tue, 16 Apr 2024 13:03:53 -0700 (PDT) Message-ID: <9f36bedd-1a68-43a9-826d-ce56caf01c52@arm.com> Date: Tue, 16 Apr 2024 15:03:52 -0500 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 v3 2/3] riscv: cacheinfo: initialize cacheinfo's level and type from ACPI PPTT Content-Language: en-US To: Yunhui Cui , rafael@kernel.org, lenb@kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, linux-riscv@lists.infradead.org, bhelgaas@google.com, james.morse@arm.com, jhugo@codeaurora.org, john.garry@huawei.com, Jonathan.Cameron@huawei.com, pierre.gondois@arm.com, sudeep.holla@arm.com, tiantao6@huawei.com References: <20240416031438.7637-1-cuiyunhui@bytedance.com> <20240416031438.7637-2-cuiyunhui@bytedance.com> From: Jeremy Linton In-Reply-To: <20240416031438.7637-2-cuiyunhui@bytedance.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi, On 4/15/24 22:14, Yunhui Cui wrote: > Before cacheinfo can be built correctly, we need to initialize level > and type. Since RSIC-V currently does not have a register group that > describes cache-related attributes like ARM64, we cannot obtain them > directly, so now we obtain cache leaves from the ACPI PPTT table > (acpi_get_cache_info()) and set the cache type through split_levels. > > Suggested-by: Jeremy Linton > Suggested-by: Sudeep Holla > Signed-off-by: Yunhui Cui > --- > arch/riscv/kernel/cacheinfo.c | 20 ++++++++++++++++++++ > 1 file changed, 20 insertions(+) > > diff --git a/arch/riscv/kernel/cacheinfo.c b/arch/riscv/kernel/cacheinfo.c > index 30a6878287ad..dc5fb70362f1 100644 > --- a/arch/riscv/kernel/cacheinfo.c > +++ b/arch/riscv/kernel/cacheinfo.c > @@ -6,6 +6,7 @@ > #include > #include > #include > +#include > > static struct riscv_cacheinfo_ops *rv_cache_ops; > > @@ -78,6 +79,25 @@ int populate_cache_leaves(unsigned int cpu) > struct device_node *prev = NULL; > int levels = 1, level = 1; > > + if (!acpi_disabled) { > + int ret, idx, fw_levels, split_levels; > + > + ret = acpi_get_cache_info(cpu, &fw_levels, &split_levels); > + if (ret) > + return ret; > + > + for (idx = 0; level <= this_cpu_ci->num_levels && > + idx < this_cpu_ci->num_leaves; idx++, level++) { AFAIK the purpose of idx here it to assure that the number of cache leaves is not overflowing. But right below we are utilizing two of them at once, so this check isn't correct. OTOH, since its allocated as levels + split_levels I don't think its actually possible for this to cause a problem. Might be worthwhile to just hoist it before the loop and revalidate the total leaves about to be utilized. > + if (level <= split_levels) { > + ci_leaf_init(this_leaf++, CACHE_TYPE_DATA, level); > + ci_leaf_init(this_leaf++, CACHE_TYPE_INST, level); > + } else { > + ci_leaf_init(this_leaf++, CACHE_TYPE_UNIFIED, level); > + } > + } > + return 0; > + } > + > if (of_property_read_bool(np, "cache-size")) > ci_leaf_init(this_leaf++, CACHE_TYPE_UNIFIED, level); > if (of_property_read_bool(np, "i-cache-size"))