Received: by 2002:a05:7412:a986:b0:f9:90c9:de9f with SMTP id o6csp25322rdh; Wed, 20 Dec 2023 13:15:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IFZtEf9p5T+pEW3EmVwedNhsKLVgb/U8xTXsMMn69WYHAv7mQjqJ1g9yEFmYDppKrlwwvkg X-Received: by 2002:a17:902:7b8d:b0:1d0:6ffd:9e36 with SMTP id w13-20020a1709027b8d00b001d06ffd9e36mr20526654pll.136.1703106915413; Wed, 20 Dec 2023 13:15:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703106915; cv=none; d=google.com; s=arc-20160816; b=oLpj2gaNeyfgOzmA4xLCugb7Chbs64B4X5OAh4myrBV9ZHN8w+hLELEaJSl1/ka4du ADibjowekHmLft6PAQuaj+s8YPvGCiFNFIXzLNRu5zy6p+l5vCKv1vM3A+/TuWXWOZdw 0VjWxgtW4vEoeKZzM7lXn+3QE6yh/qvKkbkq/erE862zwFW4cQIbQesUI/5z+U1zkuhZ Ukc78lMJR5D977LxEkbMW9X/VrjF/Ov3Zj8ceNQh9WfpAJg36VqoFBugea08YfpJyNkP xS5B1wz0ODte4xyokWJI9vtpu/d/mU+3kl3+TL66BiW0dPZLpcxdH49Cz/OsKn77rugd IKmA== ARC-Message-Signature: i=1; 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=UMjsBpZoKYyS3ZQxtkGdgQk6qYCYjwgqSngojKqxrHI=; fh=fIrTyN0sBFXBdo1bt66/wH9AFvNf59/kZZ2HkT0wfCA=; b=vjwmd5rlaQGDNpAdRdGvN90IVBO2HeXz65E4G1P/N9u6Odl84e9C9EVGm2otFRujQ2 fBafX8S0nTpuCSIsmoZLD/UuJBYTt2Rt+nqs947Ii7f11jqQUaG6PxEH5e6fLKLXTof+ +TIX3ikN8z8Fse9NyRfC6d5ezYdPhCyVRs8YkauqhoOdgikj6j/j5sw8knS3fX8+p0OM uOQjxE+dKBWsmWWiPeCOtbz2XvHeis52OAc2mLeqhfRRSm6cnq74anE7cKL2EUWL4e/E XFj65L1E9kvntNrdGQh3uFszcl4OzLdDHWDexftagULX2ZX6syHVHP+oM0bLKNc2TqeU 0IEw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-7434-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7434-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d16-20020a170902aa9000b001d35084e9efsi264265plr.125.2023.12.20.13.15.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 13:15:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-7434-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-7434-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7434-linux.lists.archive=gmail.com@vger.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 0E55C286912 for ; Wed, 20 Dec 2023 21:15:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5B20848796; Wed, 20 Dec 2023 21:15:09 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (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 BD4D61DFF8 for ; Wed, 20 Dec 2023 21:15:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ghiti.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ghiti.fr Received: by mail.gandi.net (Postfix) with ESMTPSA id 79F0220004; Wed, 20 Dec 2023 21:15:00 +0000 (UTC) Message-ID: <594df6bc-0207-46f6-aa81-dcf1f3665917@ghiti.fr> Date: Wed, 20 Dec 2023 22:14:59 +0100 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] riscv: put va_kernel_xip_pa_offset into CONFIG_XIP_KERNEL Content-Language: en-US To: Yunhui Cui , paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, ajones@ventanamicro.com, alexghiti@rivosinc.com, anup@brainfault.org, samitolvanen@google.com, rppt@kernel.org, panqinglin2020@iscas.ac.cn, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org References: <20231220103428.61758-1-cuiyunhui@bytedance.com> From: Alexandre Ghiti In-Reply-To: <20231220103428.61758-1-cuiyunhui@bytedance.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-GND-Sasl: alex@ghiti.fr Hi Yunhui, On 20/12/2023 11:34, Yunhui Cui wrote: > opitmize the kernel_mapping_pa_to_va() and kernel_mapping_va_to_pa(). > > Signed-off-by: Yunhui Cui > --- > arch/riscv/include/asm/page.h | 33 ++++++++++++++++++++------------- > 1 file changed, 20 insertions(+), 13 deletions(-) > > diff --git a/arch/riscv/include/asm/page.h b/arch/riscv/include/asm/page.h > index 5488ecc337b6..0d2b479d02cd 100644 > --- a/arch/riscv/include/asm/page.h > +++ b/arch/riscv/include/asm/page.h > @@ -113,8 +113,8 @@ struct kernel_mapping { > unsigned long va_pa_offset; > /* Offset between kernel mapping virtual address and kernel load address */ > unsigned long va_kernel_pa_offset; > - unsigned long va_kernel_xip_pa_offset; > #ifdef CONFIG_XIP_KERNEL > + unsigned long va_kernel_xip_pa_offset; > uintptr_t xiprom; > uintptr_t xiprom_sz; > #endif > @@ -134,12 +134,25 @@ extern phys_addr_t phys_ram_base; > #else > void *linear_mapping_pa_to_va(unsigned long x); > #endif > -#define kernel_mapping_pa_to_va(y) ({ \ > - unsigned long _y = (unsigned long)(y); \ > - (IS_ENABLED(CONFIG_XIP_KERNEL) && _y < phys_ram_base) ? \ > - (void *)(_y + kernel_map.va_kernel_xip_pa_offset) : \ > - (void *)(_y + kernel_map.va_kernel_pa_offset + XIP_OFFSET); \ > - }) > + > +#ifdef CONFIG_XIP_KERNEL > +#define kernel_mapping_pa_to_va(y) \ > + (((unsigned long)(y) < phys_ram_base) ? \ > + (void *)((unsigned long)(y) + kernel_map.va_kernel_xip_pa_offset) : \ > + (void *)((unsigned long)(y) + kernel_map.va_kernel_pa_offset + XIP_OFFSET)) > + > +#define kernel_mapping_va_to_pa(y) \ > + (((unsigned long)(y) < kernel_map.virt_addr + XIP_OFFSET) ? \ > + ((unsigned long)(y) - kernel_map.va_kernel_xip_pa_offset) : \ > + ((unsigned long)(y) - kernel_map.va_kernel_pa_offset - XIP_OFFSET)) > +#else > +#define kernel_mapping_pa_to_va(y) \ > + ((void *)((unsigned long)(y) + kernel_map.va_kernel_pa_offset + XIP_OFFSET)) > + > +#define kernel_mapping_va_to_pa(y) \ > + ((unsigned long)(y) - kernel_map.va_kernel_pa_offset - XIP_OFFSET) > +#endif > + > #define __pa_to_va_nodebug(x) linear_mapping_pa_to_va(x) > > #ifndef CONFIG_DEBUG_VIRTUAL > @@ -147,12 +160,6 @@ void *linear_mapping_pa_to_va(unsigned long x); > #else > phys_addr_t linear_mapping_va_to_pa(unsigned long x); > #endif > -#define kernel_mapping_va_to_pa(y) ({ \ > - unsigned long _y = (unsigned long)(y); \ > - (IS_ENABLED(CONFIG_XIP_KERNEL) && _y < kernel_map.virt_addr + XIP_OFFSET) ? \ > - (_y - kernel_map.va_kernel_xip_pa_offset) : \ > - (_y - kernel_map.va_kernel_pa_offset - XIP_OFFSET); \ > - }) > > #define __va_to_pa_nodebug(x) ({ \ > unsigned long _x = x; \ Not sure using #ifdef optimizes anything since the compiler should do the same with the IS_ENABLED(CONFIG_XIP_KERNEL) and it does not really improve the readability of this file which is already overloaded with #ifdef, so I don't think this change is needed. Thanks, Alex