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=-8.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 81095C41604 for ; Tue, 6 Oct 2020 06:36:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3809020796 for ; Tue, 6 Oct 2020 06:36:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726957AbgJFGg0 (ORCPT ); Tue, 6 Oct 2020 02:36:26 -0400 Received: from foss.arm.com ([217.140.110.172]:39588 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725962AbgJFGg0 (ORCPT ); Tue, 6 Oct 2020 02:36:26 -0400 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 A69381435; Mon, 5 Oct 2020 23:36:25 -0700 (PDT) Received: from [10.163.74.99] (unknown [10.163.74.99]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 475E03F66B; Mon, 5 Oct 2020 23:36:21 -0700 (PDT) Subject: Re: [PATCH] arm64/mm: Validate hotplug range before creating linear mapping To: Will Deacon Cc: Mark Rutland , David Hildenbrand , catalin.marinas@arm.com, linux-kernel@vger.kernel.org, Steven Price , Andrew Morton , Robin Murphy , Ard Biesheuvel , linux-arm-kernel@lists.infradead.org References: <1600332402-30123-1-git-send-email-anshuman.khandual@arm.com> <20200928203539.GA12218@willie-the-truck> <09266aed-7eef-5b16-5d52-0dcb7dcb7246@arm.com> <20200929152221.GA13995@willie-the-truck> From: Anshuman Khandual Message-ID: <262f2fd8-2e0c-4eaf-d4ff-f72728049f52@arm.com> Date: Tue, 6 Oct 2020 12:05:51 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/30/2020 01:32 PM, Anshuman Khandual wrote: > But if __is_lm_address() checks against the effective linear range instead > i.e [_PAGE_OFFSET(vabits_actual)..(PAGE_END - 1)], it can be used for hot > plug physical range check there after. Perhaps something like this, though > not tested properly. > > diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h > index afa722504bfd..6da046b479d4 100644 > --- a/arch/arm64/include/asm/memory.h > +++ b/arch/arm64/include/asm/memory.h > @@ -238,7 +238,10 @@ static inline const void *__tag_set(const void *addr, u8 tag) > * space. Testing the top bit for the start of the region is a > * sufficient check and avoids having to worry about the tag. > */ > -#define __is_lm_address(addr) (!(((u64)addr) & BIT(vabits_actual - 1))) > +static inline bool __is_lm_address(unsigned long addr) > +{ > + return ((addr >= _PAGE_OFFSET(vabits_actual)) && (addr <= (PAGE_END - 1))); > +} > > #define __lm_to_phys(addr) (((addr) + physvirt_offset)) > #define __kimg_to_phys(addr) ((addr) - kimage_voffset) > diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c > index d59ffabb9c84..5750370a7e8c 100644 > --- a/arch/arm64/mm/mmu.c > +++ b/arch/arm64/mm/mmu.c > @@ -1451,8 +1451,7 @@ static bool inside_linear_region(u64 start, u64 size) > * address range mapped by the linear map, the start address should > * be calculated using vabits_actual. > */ > - return ((start >= __pa(_PAGE_OFFSET(vabits_actual))) > - && ((start + size) <= __pa(PAGE_END - 1))); > + return __is_lm_address(__va(start)) && __is_lm_address(__va(start + size)); > } > > int arch_add_memory(int nid, u64 start, u64 size, Will/Ard, Any thoughts about this ? __is_lm_address() now checks for a range instead of a bit. This will be compatible later on, even if linear mapping range changes from current lower half scheme. - Anshuman