From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756661AbcKBU2H (ORCPT ); Wed, 2 Nov 2016 16:28:07 -0400 Received: from mail-oi0-f41.google.com ([209.85.218.41]:33050 "EHLO mail-oi0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756031AbcKBU2F (ORCPT ); Wed, 2 Nov 2016 16:28:05 -0400 Subject: Re: [RFC][PATCH] arm64: Add support for CONFIG_DEBUG_VIRTUAL To: Ard Biesheuvel References: <1477613892-26076-1-git-send-email-labbott@redhat.com> <20161028144951.GI5806@leverpostej> <4911a788-602f-6ad0-b8e7-53f9de9fa8c5@redhat.com> <6a76edf2-3f80-fb18-4fc1-2e0b1f085d20@redhat.com> Cc: Mark Rutland , Will Deacon , Catalin Marinas , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" From: Laura Abbott Message-ID: <58b065d6-839c-7ec0-5594-741a72851edb@redhat.com> Date: Wed, 2 Nov 2016 14:28:02 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/29/2016 02:39 AM, Ard Biesheuvel wrote: > On 28 October 2016 at 23:07, Laura Abbott wrote: >>>>> diff --git a/arch/arm64/mm/physaddr.c b/arch/arm64/mm/physaddr.c >>>>> new file mode 100644 >>>>> index 0000000..6c271e2 >>>>> --- /dev/null >>>>> +++ b/arch/arm64/mm/physaddr.c >>>>> @@ -0,0 +1,17 @@ >>>>> +#include >>>>> + >>>>> +#include >>>>> + >>>>> +unsigned long __virt_to_phys(unsigned long x) >>>>> +{ >>>>> + phys_addr_t __x = (phys_addr_t)x; >>>>> + >>>>> + if (__x & BIT(VA_BITS - 1)) { >>>>> + /* The bit check ensures this is the right range */ >>>>> + return (__x & ~PAGE_OFFSET) + PHYS_OFFSET; >>>>> + } else { >>>>> + VIRTUAL_BUG_ON(x < kimage_vaddr || x > (unsigned long)_end); >>>> >>>> >>>> IIUC, in (3) you were asking if the last check should be '>' or '>='? >>>> >>>> To match high_memory, I suspect the latter, as _end doesn't fall within >>>> the mapped virtual address space. >>>> >>> >>> I was actually concerned about if _end would be correct with KASLR. >>> Ard confirmed that it gets fixed up to be correct. I'll change the >>> check to check for >=. >>> >> >> While testing this, I found two places with __pa(_end) to get bounds, >> one in arm64 code and one in memblock code. x86 gets away with this >> because memblock is actually __pa_symbol and x86 does image placement >> different and can check against the maximum image size. I think >> including _end in __pa_symbol but excluding it from the generic >> __virt_to_phys makes sense. It's a bit nicer than doing _end - 1 + >> 1 everywhere. >> > > Could we redefine __pa_symbol() under CONFIG_DEBUG_VIRTUAL to > something that checks (x >= kimage_vaddr + TEXT_OFFSET || x <= > (unsigned long)_end), i.e., reject linear virtual addresses? (Assuming > my understanding of the meaning of __pa_symbol() is correct) > Yes, that's going to be my approach. I originally prototyped this with just x >= kimage_vaddr but kimage_vaddr + TEXT_OFFSET is a tighter bound. Thanks, Laura