Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp412278rwb; Thu, 22 Sep 2022 01:05:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4bL7YEwsVhVf49/D+EsH61Sa4o0t6nx7tLf3gqKMejYmMdixt9GHYMFBT3+gaH7T0CB/qU X-Received: by 2002:a17:90a:f291:b0:200:acc9:422d with SMTP id fs17-20020a17090af29100b00200acc9422dmr13528659pjb.21.1663833927002; Thu, 22 Sep 2022 01:05:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663833926; cv=none; d=google.com; s=arc-20160816; b=ugB4MZDX3R0v17qnIFSZVfGrkCAcUUYV1GDlPHiuYWc8C50aV5Wa8FTWcGS8imrdi3 BXfPsTf20uXwMwNOoJhL9kETR7OY48MYyKVrscoS1GA4W29rrQhijUJChY0aT42KfjUI ulCAtLFTGqNXA1cdhx53w3713TI5Rnhj9xzYUs+XXACG2CFTVH13sqDRmIuoKJSLIXy5 3lJsX0m9lj6LPuXraniTdFH/LIC2PupTbbI/Zp8W/WPRnFM5PYddinl4ke+prxYY8VK6 NdK834duazWaV4uavV9PB6jsMHqEDDRloyvlR6zkdG4pT1z0Gfs/u4zajkPGJN9cn/nP 7cKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=A/6P+49+txy9CwhkmQnCT/OyodU+SYAPIXL+4B/Isj0=; b=fCrfMobm+/3uAWpyFh5Ev+HgYddG0rH0vcxCO8LHwyMCi/LmxhW/m/MXQOwkqYWmhc LsIGGhXo//a9lcBo8UQJheOTWTwpL7EvdUIizVO72kvEo2JBZcAXobNp8uFr9jkWg4hW u4zcB81R+hwpxSNwU2CzSt5WmTClsAAfLds9/jlrWbneyH4YonramvSYZQfWuWxUzkh2 nPQ9dklpkIXpIA92fL9LVgF7Cw/bL5a3WNjzsMohdbU6wtN7jg0vk/9t23FE7SQAxJuG WUCLMFEIMeetLvPvjhkpxUf50fgM7ebZyx3rEg6k1Hy1u+Npxakm1HJo1zhD+vNmjAz0 OEaQ== ARC-Authentication-Results: i=1; mx.google.com; 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 u4-20020a056a00158400b0054576310f12si5419210pfk.366.2022.09.22.01.05.14; Thu, 22 Sep 2022 01:05:26 -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; 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 S230266AbiIVHe4 (ORCPT + 99 others); Thu, 22 Sep 2022 03:34:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229803AbiIVHey (ORCPT ); Thu, 22 Sep 2022 03:34:54 -0400 Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADED24A13D for ; Thu, 22 Sep 2022 00:34:50 -0700 (PDT) Received: (Authenticated sender: alex@ghiti.fr) by mail.gandi.net (Postfix) with ESMTPSA id AD1C3100002; Thu, 22 Sep 2022 07:34:40 +0000 (UTC) Message-ID: <48082184-93ea-8564-5a69-ff00350c0201@ghiti.fr> Date: Thu, 22 Sep 2022 09:34:40 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH 2/2] riscv: Move cast inside kernel_mapping_[pv]a_to_[vp]a Content-Language: en-US To: Samuel Holland , Palmer Dabbelt , linux-riscv@lists.infradead.org Cc: Albert Ou , Guo Ren , Heiko Stuebner , Paul Walmsley , linux-kernel@vger.kernel.org, Alexandre Ghiti , Arnd Bergmann , Geert Uytterhoeven , Jisheng Zhang , Nick Kossifidis , Qinglin Pan , Tong Tiangen References: <20220922054743.30159-1-samuel@sholland.org> <20220922054743.30159-2-samuel@sholland.org> From: Alexandre Ghiti In-Reply-To: <20220922054743.30159-2-samuel@sholland.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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 9/22/22 07:47, Samuel Holland wrote: > Before commit 44c922572952 ("RISC-V: enable XIP"), these macros cast > their argument to unsigned long. That commit moved the cast after an > assignment to an unsigned long variable, rendering it ineffectual. > Move the cast back, so we can remove the cast at each call site. > > Signed-off-by: Samuel Holland > --- > > arch/riscv/errata/thead/errata.c | 4 ++-- > arch/riscv/include/asm/page.h | 18 +++++++++--------- > arch/riscv/mm/init.c | 16 ++++++++-------- > 3 files changed, 19 insertions(+), 19 deletions(-) > > diff --git a/arch/riscv/errata/thead/errata.c b/arch/riscv/errata/thead/errata.c > index 83174f13783e..38c2c6b0f6b8 100644 > --- a/arch/riscv/errata/thead/errata.c > +++ b/arch/riscv/errata/thead/errata.c > @@ -76,8 +76,8 @@ void __init_or_module thead_errata_patch_func(struct alt_entry *begin, struct al > if (cpu_req_errata & tmp) { > /* On vm-alternatives, the mmu isn't running yet */ > if (stage == RISCV_ALTERNATIVES_EARLY_BOOT) > - memcpy((void *)kernel_mapping_va_to_pa((unsigned long)alt->old_ptr), > - (void *)kernel_mapping_va_to_pa((unsigned long)alt->alt_ptr), > + memcpy((void *)kernel_mapping_va_to_pa(alt->old_ptr), > + (void *)kernel_mapping_va_to_pa(alt->alt_ptr), > alt->alt_len); > else > patch_text_nosync(alt->old_ptr, alt->alt_ptr, alt->alt_len); > diff --git a/arch/riscv/include/asm/page.h b/arch/riscv/include/asm/page.h > index ac70b0fd9a9a..9f432c1b5289 100644 > --- a/arch/riscv/include/asm/page.h > +++ b/arch/riscv/include/asm/page.h > @@ -123,20 +123,20 @@ extern phys_addr_t phys_ram_base; > ((x) >= PAGE_OFFSET && (!IS_ENABLED(CONFIG_64BIT) || (x) < PAGE_OFFSET + KERN_VIRT_SIZE)) > > #define linear_mapping_pa_to_va(x) ((void *)((unsigned long)(x) + kernel_map.va_pa_offset)) > -#define kernel_mapping_pa_to_va(y) ({ \ > - unsigned long _y = y; \ > - (IS_ENABLED(CONFIG_XIP_KERNEL) && _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_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); \ > }) > #define __pa_to_va_nodebug(x) linear_mapping_pa_to_va(x) > > #define linear_mapping_va_to_pa(x) ((unsigned long)(x) - kernel_map.va_pa_offset) > #define kernel_mapping_va_to_pa(y) ({ \ > - unsigned long _y = y; \ > - (IS_ENABLED(CONFIG_XIP_KERNEL) && _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); \ > + 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) ({ \ > diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c > index b56a0a75533f..7d59516ce6b3 100644 > --- a/arch/riscv/mm/init.c > +++ b/arch/riscv/mm/init.c > @@ -927,15 +927,15 @@ static void __init pt_ops_set_early(void) > */ > static void __init pt_ops_set_fixmap(void) > { > - pt_ops.alloc_pte = kernel_mapping_pa_to_va((uintptr_t)alloc_pte_fixmap); > - pt_ops.get_pte_virt = kernel_mapping_pa_to_va((uintptr_t)get_pte_virt_fixmap); > + pt_ops.alloc_pte = kernel_mapping_pa_to_va(alloc_pte_fixmap); > + pt_ops.get_pte_virt = kernel_mapping_pa_to_va(get_pte_virt_fixmap); > #ifndef __PAGETABLE_PMD_FOLDED > - pt_ops.alloc_pmd = kernel_mapping_pa_to_va((uintptr_t)alloc_pmd_fixmap); > - pt_ops.get_pmd_virt = kernel_mapping_pa_to_va((uintptr_t)get_pmd_virt_fixmap); > - pt_ops.alloc_pud = kernel_mapping_pa_to_va((uintptr_t)alloc_pud_fixmap); > - pt_ops.get_pud_virt = kernel_mapping_pa_to_va((uintptr_t)get_pud_virt_fixmap); > - pt_ops.alloc_p4d = kernel_mapping_pa_to_va((uintptr_t)alloc_p4d_fixmap); > - pt_ops.get_p4d_virt = kernel_mapping_pa_to_va((uintptr_t)get_p4d_virt_fixmap); > + pt_ops.alloc_pmd = kernel_mapping_pa_to_va(alloc_pmd_fixmap); > + pt_ops.get_pmd_virt = kernel_mapping_pa_to_va(get_pmd_virt_fixmap); > + pt_ops.alloc_pud = kernel_mapping_pa_to_va(alloc_pud_fixmap); > + pt_ops.get_pud_virt = kernel_mapping_pa_to_va(get_pud_virt_fixmap); > + pt_ops.alloc_p4d = kernel_mapping_pa_to_va(alloc_p4d_fixmap); > + pt_ops.get_p4d_virt = kernel_mapping_pa_to_va(get_p4d_virt_fixmap); > #endif > } > Indeed, the inner cast was useless: Reviewed-by: Alexandre Ghiti Thanks, Alex