From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756162AbdKNTVZ (ORCPT ); Tue, 14 Nov 2017 14:21:25 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:52389 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751637AbdKNTVQ (ORCPT ); Tue, 14 Nov 2017 14:21:16 -0500 X-Google-Smtp-Source: AGs4zMY34u/ETbIpPnWHr/HOy/zDE1HIxDEVThAz1bZh0V3oy2eawF8QFMBaqSQtR8D83povBVu5Vw== Date: Tue, 14 Nov 2017 22:21:13 +0300 From: "Kirill A. Shutemov" To: Thomas Gleixner Cc: "Kirill A. Shutemov" , Ingo Molnar , x86@kernel.org, "H. Peter Anvin" , Linus Torvalds , Andy Lutomirski , Nicholas Piggin , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCHv2 1/2] x86/mm: Do not allow non-MAP_FIXED mapping across DEFAULT_MAP_WINDOW border Message-ID: <20171114192113.t7pq5p2n5emmiw2n@node.shutemov.name> References: <20171114134322.40321-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 14, 2017 at 05:01:50PM +0100, Thomas Gleixner wrote: > On Tue, 14 Nov 2017, Kirill A. Shutemov wrote: > > --- a/arch/x86/mm/hugetlbpage.c > > +++ b/arch/x86/mm/hugetlbpage.c > > @@ -166,11 +166,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr, > > > > if (addr) { > > addr = ALIGN(addr, huge_page_size(h)); > > + if (TASK_SIZE - len >= addr) > > + goto get_unmapped_area; > > That's wrong. You got it right in arch_get_unmapped_area_topdown() ... Ouch. Please ignore selftest patch. I'll rework it to cover hugetlb. > > + > > + /* See a comment in arch_get_unmapped_area_topdown */ > > This is lame, really. > > > + if ((addr > DEFAULT_MAP_WINDOW) != > > + (addr + len > DEFAULT_MAP_WINDOW)) > > + goto get_unmapped_area; > > Instead of duplicating that horrible formatted condition and adding this > lousy comment why can't you just put all of it (including the TASK_SIZE > check) into a proper validation function and put the comment there? > > The fixed up variant of your patch below does that. > > Aside of that please spend a bit more time on describing things precisely > at the technical and factual level next time. I fixed that up (once more) > both in the comment and the changelog. > > Please double check. Works fine. > +bool mmap_address_hint_valid(unsigned long addr, unsigned long len) > +{ > + if (TASK_SIZE - len < addr) > + return false; > +#if CONFIG_PGTABLE_LEVELS >= 5 > + return (addr > DEFAULT_MAP_WINDOW) == (addr + len > DEFAULT_MAP_WINDOW); Is it micro optimization? I don't feel it necessary. It's not that hot codepath to care about few cycles. (And one more place to care about for boot-time switching.) If you think it's needed, maybe IS_ENABLED() instead? > +#else > + return true; > +#endif > +} -- Kirill A. Shutemov