From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C250BC47096 for ; Thu, 3 Jun 2021 15:52:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A750E613E9 for ; Thu, 3 Jun 2021 15:52:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229881AbhFCPyW (ORCPT ); Thu, 3 Jun 2021 11:54:22 -0400 Received: from mail-yb1-f181.google.com ([209.85.219.181]:33556 "EHLO mail-yb1-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229826AbhFCPyV (ORCPT ); Thu, 3 Jun 2021 11:54:21 -0400 Received: by mail-yb1-f181.google.com with SMTP id f84so9571028ybg.0 for ; Thu, 03 Jun 2021 08:52:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=V0E1bQ+uKUVeIFgvkIlglV33FCznGkcgKYHmyJqXHZ4=; b=L6c8kr29xlQkfikA6a4PIf875euklpqQN8EDPNIOkcCRGCACOIUxKiYzdH59e2Gdz+ llM+M3HbTJjzz6D1YkvrdHTH9mma5v1oj3jm5hcu8R+6tfq84GXqAJp4V1WLddFy0ZQI wFzBY0zW2VLkGcBJY5JoJV2nZ1aADn2s7hVRk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=V0E1bQ+uKUVeIFgvkIlglV33FCznGkcgKYHmyJqXHZ4=; b=WstAp8+LSD8WzWOyeeGzgDZZ0ikW9Xjc1lM/oQoIpU7RRTPcOCOSLtMOgbhjD8/tQO S8TXHpbA/S7tk/xnO53s27IvmVVUELl1LP688CXftk1D5l6vODFTjc+PpHd7YcDtxCHc YmH8ILNZWvu3dZfaXPqF0x2NwaKBEUYSJCwCa2dQc3G70kksZsOPh72RL9CJVm2EbTAt Io12TcTKRJDXsjvfWbAYXfkuYXXnzmhvTiVDkT8wePVsOPSQ/ypFxLkfAPciuWa3Ai51 69ru/miG+DJXNL0cMLbOMkTjHRxuezut9vjM8I1gyx0RmDQ6Sw0mRYTtptWArYf8K0Of 0aqg== X-Gm-Message-State: AOAM532GJqfvp7lcjX+6EuicQfy4tjevbotz5uAO8u17sISWUR6jLTd/ VGR0iAHPocun/jjIQh+t1CmPJl9kBWHausCCcdLbIw== X-Google-Smtp-Source: ABdhPJyP9W19k/Ki6c2DwddIwJwVZOUopod0HSUrSsvq+oGgiLZQc/+ykQGJfWEIsf0Ermak0Nf58vUycg2mFIDfLuQ= X-Received: by 2002:a25:d256:: with SMTP id j83mr825910ybg.421.1622735496472; Thu, 03 Jun 2021 08:51:36 -0700 (PDT) MIME-Version: 1.0 References: <20210603082749.1256129-1-alex@ghiti.fr> <20210603082749.1256129-2-alex@ghiti.fr> <20210603202748.2775f739@xhacker> <20210603204942.703c9cb4@xhacker> In-Reply-To: <20210603204942.703c9cb4@xhacker> From: Vitaly Wool Date: Thu, 3 Jun 2021 17:51:25 +0200 Message-ID: Subject: Re: [PATCH v3 1/3] riscv: Factorize xip and !xip kernel address conversion macros To: Jisheng Zhang Cc: Alexandre Ghiti , Paul Walmsley , Palmer Dabbelt , Albert Ou , Jisheng Zhang , Christoph Hellwig , Zong Li , Anup Patel , linux-riscv , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 3, 2021, 14:57 Jisheng Zhang wrote: > > On Thu, 3 Jun 2021 20:27:48 +0800 > Jisheng Zhang wrote: > > > On Thu, 3 Jun 2021 10:27:47 +0200 > > Alexandre Ghiti wrote: > > > > > To simplify the kernel address conversion code, make the same definition of > > > kernel_mapping_pa_to_va and kernel_mapping_va_to_pa compatible for both xip > > > and !xip kernel by defining XIP_OFFSET to 0 in !xip kernel. > > > > > > Signed-off-by: Alexandre Ghiti > > > --- > > > arch/riscv/include/asm/page.h | 14 +++----------- > > > arch/riscv/include/asm/pgtable.h | 2 ++ > > > 2 files changed, 5 insertions(+), 11 deletions(-) > > > > > > diff --git a/arch/riscv/include/asm/page.h b/arch/riscv/include/asm/page.h > > > index 6a7761c86ec2..6e004d8fda4d 100644 > > > --- a/arch/riscv/include/asm/page.h > > > +++ b/arch/riscv/include/asm/page.h > > > @@ -93,9 +93,7 @@ extern unsigned long va_pa_offset; > > > #ifdef CONFIG_64BIT > > > extern unsigned long va_kernel_pa_offset; > > > #endif > > > -#ifdef CONFIG_XIP_KERNEL > > > extern unsigned long va_kernel_xip_pa_offset; > > > -#endif > > > extern unsigned long pfn_base; > > > #define ARCH_PFN_OFFSET (pfn_base) > > > #else > > > @@ -103,6 +101,7 @@ extern unsigned long pfn_base; > > > #ifdef CONFIG_64BIT > > > #define va_kernel_pa_offset 0 > > > #endif > > > +#define va_kernel_xip_pa_offset 0 > > > #define ARCH_PFN_OFFSET (PAGE_OFFSET >> PAGE_SHIFT) > > > #endif /* CONFIG_MMU */ > > > > > > @@ -110,29 +109,22 @@ extern unsigned long kernel_virt_addr; > > > > > > #ifdef CONFIG_64BIT > > > #define linear_mapping_pa_to_va(x) ((void *)((unsigned long)(x) + va_pa_offset)) > > > -#ifdef CONFIG_XIP_KERNEL > > > #define kernel_mapping_pa_to_va(y) ({ \ > > > unsigned long _y = y; \ > > > (_y >= CONFIG_PHYS_RAM_BASE) ? > > > > This CONFIG_PHYS_RAM_BASE is only available for XIP, could result in a > > compiler error for !XIP? > > > > I'm also concerned with the unecessary overhead of kernel_mapping_pa_to_va() > > for !XIP case, there's a "if" condition branch, and extra symbol: va_kernel_xip_pa_offset > > Err, I just found this symobl always exists no matter XIP is enabled or not. > I will send out a patch for this clean up What cleanup? Best regards, Vitaly > > > > > > (void *)((unsigned long)(_y) + va_kernel_pa_offset + XIP_OFFSET) : \ > > > (void *)((unsigned long)(_y) + va_kernel_xip_pa_offset); \ > > > }) > > > -#else > > > -#define kernel_mapping_pa_to_va(x) ((void *)((unsigned long)(x) + va_kernel_pa_offset)) > > > -#endif > > > #define __pa_to_va_nodebug(x) linear_mapping_pa_to_va(x) > > > > > > #define linear_mapping_va_to_pa(x) ((unsigned long)(x) - va_pa_offset) > > > -#ifdef CONFIG_XIP_KERNEL > > > #define kernel_mapping_va_to_pa(y) ({ \ > > > unsigned long _y = y; \ > > > (_y < kernel_virt_addr + XIP_OFFSET) ? \ > > > ((unsigned long)(_y) - va_kernel_xip_pa_offset) : \ > > > ((unsigned long)(_y) - va_kernel_pa_offset - XIP_OFFSET); \ > > > }) > > > > Similar as kernel_mapping_pa_to_va(), an overhead of "if" condition branch > > for !XIP and extra va_kernel_xip_pa_offset symbol. > > > > > -#else > > > -#define kernel_mapping_va_to_pa(x) ((unsigned long)(x) - va_kernel_pa_offset) > > > -#endif > > > + > > > #define __va_to_pa_nodebug(x) ({ \ > > > unsigned long _x = x; \ > > > (_x < kernel_virt_addr) ? \ > > > @@ -141,7 +133,7 @@ extern unsigned long kernel_virt_addr; > > > #else > > > #define __pa_to_va_nodebug(x) ((void *)((unsigned long) (x) + va_pa_offset)) > > > #define __va_to_pa_nodebug(x) ((unsigned long)(x) - va_pa_offset) > > > -#endif > > > +#endif /* CONFIG_64BIT */ > > > > > > #ifdef CONFIG_DEBUG_VIRTUAL > > > extern phys_addr_t __virt_to_phys(unsigned long x); > > > diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h > > > index bde8ce3bfe7c..d98e931a31e5 100644 > > > --- a/arch/riscv/include/asm/pgtable.h > > > +++ b/arch/riscv/include/asm/pgtable.h > > > @@ -77,6 +77,8 @@ > > > > > > #ifdef CONFIG_XIP_KERNEL > > > #define XIP_OFFSET SZ_8M > > > +#else > > > +#define XIP_OFFSET 0 > > > #endif > > > > > > #ifndef __ASSEMBLY__ > > > > > > > > _______________________________________________ > linux-riscv mailing list > linux-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A478C47096 for ; Thu, 3 Jun 2021 15:53:02 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 43282613DC for ; Thu, 3 Jun 2021 15:53:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 43282613DC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=konsulko.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=I9kxbxr7wH0L/bpJaoVvopfUwNUHjKwY71Ds2N/l4CY=; b=J6TrL8GU+/YWGz V8yOn7/tncHJ3x3BQOeS3h9nV8RWwxEdegOzM7sO/jaYXGTsOlqNYd44jQCOmVB/t1acj6s4wbLTK 9scr0CXrwXPrIWHPwOxqm+z9kAbTFC0te34qNfOrDOYUgds47vWeVCUxIn7snzC3N2ncI2EmB0Ki0 H5yKW+Eu0umAjPvIL7PQe6zhO4A3Adg+A/0rBCI/UQa5cgIYwn5En9R8D4KrxfLw+8/bVRZqkFhto kObERaBIp2vdWue0tvQcK8l5Rq6QvZHLJy9ddmySmrVL2jNLRtMMGGb47KAkOIP9EzG/kmlk4v8r3 76f3KdGPDyQcQdDhSOjA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lopeF-009PqT-EJ; Thu, 03 Jun 2021 15:52:43 +0000 Received: from mail-yb1-f172.google.com ([209.85.219.172]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lopeA-009PpR-DD for linux-riscv@lists.infradead.org; Thu, 03 Jun 2021 15:52:42 +0000 Received: by mail-yb1-f172.google.com with SMTP id b9so9453597ybg.10 for ; Thu, 03 Jun 2021 08:52:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=V0E1bQ+uKUVeIFgvkIlglV33FCznGkcgKYHmyJqXHZ4=; b=L6c8kr29xlQkfikA6a4PIf875euklpqQN8EDPNIOkcCRGCACOIUxKiYzdH59e2Gdz+ llM+M3HbTJjzz6D1YkvrdHTH9mma5v1oj3jm5hcu8R+6tfq84GXqAJp4V1WLddFy0ZQI wFzBY0zW2VLkGcBJY5JoJV2nZ1aADn2s7hVRk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=V0E1bQ+uKUVeIFgvkIlglV33FCznGkcgKYHmyJqXHZ4=; b=tH3KoYY/zwYq2rt5Q/6CAp6LBjfL8y16seSw+OVxe0uaE3J0MSdUoM+jxZeg2xwjci ilVu1HIFwjZANLas4Y9g7qZMAgO1pUu4s/EiAtj0aEAjYF9n5pnZpCk3pz4CJ+/Xw4S9 OARPxCiNYnun4L06RbETTZaDAdj53bkBGQQWwfI3cZ4oRrR46AYYn/Z3hgK5ksqU8sJy f9SM00rGNFvrB/lckzPXk3BiOEN7tzsos2XVNYpqEL2XBUNyUldd/BszOMnapQMlZMON tHTziBr2v844l+pRnsYtkzO/yNuaL7nLf1w8Hf42NtFWqIiofvRrM9nhzpu6YF2BUrvk IHEg== X-Gm-Message-State: AOAM533nBcmMl1r0RBOQeBgesD+dnfrEoLgKBBWguF5pSIZCAjs63IM+ s1Kc7KlpSexcSvl52UwWMVtKeZq+JL//FInDhjOoqg== X-Google-Smtp-Source: ABdhPJyP9W19k/Ki6c2DwddIwJwVZOUopod0HSUrSsvq+oGgiLZQc/+ykQGJfWEIsf0Ermak0Nf58vUycg2mFIDfLuQ= X-Received: by 2002:a25:d256:: with SMTP id j83mr825910ybg.421.1622735496472; Thu, 03 Jun 2021 08:51:36 -0700 (PDT) MIME-Version: 1.0 References: <20210603082749.1256129-1-alex@ghiti.fr> <20210603082749.1256129-2-alex@ghiti.fr> <20210603202748.2775f739@xhacker> <20210603204942.703c9cb4@xhacker> In-Reply-To: <20210603204942.703c9cb4@xhacker> From: Vitaly Wool Date: Thu, 3 Jun 2021 17:51:25 +0200 Message-ID: Subject: Re: [PATCH v3 1/3] riscv: Factorize xip and !xip kernel address conversion macros To: Jisheng Zhang Cc: Alexandre Ghiti , Paul Walmsley , Palmer Dabbelt , Albert Ou , Jisheng Zhang , Christoph Hellwig , Zong Li , Anup Patel , linux-riscv , LKML X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210603_085238_462527_595688BC X-CRM114-Status: GOOD ( 24.88 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On Thu, Jun 3, 2021, 14:57 Jisheng Zhang wrote: > > On Thu, 3 Jun 2021 20:27:48 +0800 > Jisheng Zhang wrote: > > > On Thu, 3 Jun 2021 10:27:47 +0200 > > Alexandre Ghiti wrote: > > > > > To simplify the kernel address conversion code, make the same definition of > > > kernel_mapping_pa_to_va and kernel_mapping_va_to_pa compatible for both xip > > > and !xip kernel by defining XIP_OFFSET to 0 in !xip kernel. > > > > > > Signed-off-by: Alexandre Ghiti > > > --- > > > arch/riscv/include/asm/page.h | 14 +++----------- > > > arch/riscv/include/asm/pgtable.h | 2 ++ > > > 2 files changed, 5 insertions(+), 11 deletions(-) > > > > > > diff --git a/arch/riscv/include/asm/page.h b/arch/riscv/include/asm/page.h > > > index 6a7761c86ec2..6e004d8fda4d 100644 > > > --- a/arch/riscv/include/asm/page.h > > > +++ b/arch/riscv/include/asm/page.h > > > @@ -93,9 +93,7 @@ extern unsigned long va_pa_offset; > > > #ifdef CONFIG_64BIT > > > extern unsigned long va_kernel_pa_offset; > > > #endif > > > -#ifdef CONFIG_XIP_KERNEL > > > extern unsigned long va_kernel_xip_pa_offset; > > > -#endif > > > extern unsigned long pfn_base; > > > #define ARCH_PFN_OFFSET (pfn_base) > > > #else > > > @@ -103,6 +101,7 @@ extern unsigned long pfn_base; > > > #ifdef CONFIG_64BIT > > > #define va_kernel_pa_offset 0 > > > #endif > > > +#define va_kernel_xip_pa_offset 0 > > > #define ARCH_PFN_OFFSET (PAGE_OFFSET >> PAGE_SHIFT) > > > #endif /* CONFIG_MMU */ > > > > > > @@ -110,29 +109,22 @@ extern unsigned long kernel_virt_addr; > > > > > > #ifdef CONFIG_64BIT > > > #define linear_mapping_pa_to_va(x) ((void *)((unsigned long)(x) + va_pa_offset)) > > > -#ifdef CONFIG_XIP_KERNEL > > > #define kernel_mapping_pa_to_va(y) ({ \ > > > unsigned long _y = y; \ > > > (_y >= CONFIG_PHYS_RAM_BASE) ? > > > > This CONFIG_PHYS_RAM_BASE is only available for XIP, could result in a > > compiler error for !XIP? > > > > I'm also concerned with the unecessary overhead of kernel_mapping_pa_to_va() > > for !XIP case, there's a "if" condition branch, and extra symbol: va_kernel_xip_pa_offset > > Err, I just found this symobl always exists no matter XIP is enabled or not. > I will send out a patch for this clean up What cleanup? Best regards, Vitaly > > > > > > (void *)((unsigned long)(_y) + va_kernel_pa_offset + XIP_OFFSET) : \ > > > (void *)((unsigned long)(_y) + va_kernel_xip_pa_offset); \ > > > }) > > > -#else > > > -#define kernel_mapping_pa_to_va(x) ((void *)((unsigned long)(x) + va_kernel_pa_offset)) > > > -#endif > > > #define __pa_to_va_nodebug(x) linear_mapping_pa_to_va(x) > > > > > > #define linear_mapping_va_to_pa(x) ((unsigned long)(x) - va_pa_offset) > > > -#ifdef CONFIG_XIP_KERNEL > > > #define kernel_mapping_va_to_pa(y) ({ \ > > > unsigned long _y = y; \ > > > (_y < kernel_virt_addr + XIP_OFFSET) ? \ > > > ((unsigned long)(_y) - va_kernel_xip_pa_offset) : \ > > > ((unsigned long)(_y) - va_kernel_pa_offset - XIP_OFFSET); \ > > > }) > > > > Similar as kernel_mapping_pa_to_va(), an overhead of "if" condition branch > > for !XIP and extra va_kernel_xip_pa_offset symbol. > > > > > -#else > > > -#define kernel_mapping_va_to_pa(x) ((unsigned long)(x) - va_kernel_pa_offset) > > > -#endif > > > + > > > #define __va_to_pa_nodebug(x) ({ \ > > > unsigned long _x = x; \ > > > (_x < kernel_virt_addr) ? \ > > > @@ -141,7 +133,7 @@ extern unsigned long kernel_virt_addr; > > > #else > > > #define __pa_to_va_nodebug(x) ((void *)((unsigned long) (x) + va_pa_offset)) > > > #define __va_to_pa_nodebug(x) ((unsigned long)(x) - va_pa_offset) > > > -#endif > > > +#endif /* CONFIG_64BIT */ > > > > > > #ifdef CONFIG_DEBUG_VIRTUAL > > > extern phys_addr_t __virt_to_phys(unsigned long x); > > > diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h > > > index bde8ce3bfe7c..d98e931a31e5 100644 > > > --- a/arch/riscv/include/asm/pgtable.h > > > +++ b/arch/riscv/include/asm/pgtable.h > > > @@ -77,6 +77,8 @@ > > > > > > #ifdef CONFIG_XIP_KERNEL > > > #define XIP_OFFSET SZ_8M > > > +#else > > > +#define XIP_OFFSET 0 > > > #endif > > > > > > #ifndef __ASSEMBLY__ > > > > > > > > _______________________________________________ > linux-riscv mailing list > linux-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv