Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp570321ybg; Tue, 28 Jul 2020 13:04:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwsjxxPQGsGB+2sZm8mCXPeaDpUIDaEfVeBOhF9n2anBUSfnPy7g7J9RwYXDf39KTR+4uMv X-Received: by 2002:aa7:d291:: with SMTP id w17mr7228140edq.332.1595966695135; Tue, 28 Jul 2020 13:04:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595966695; cv=none; d=google.com; s=arc-20160816; b=wNAGmPQJuJF0Uf6RfeGByqFJuvKoYP3D4QR7KS2T0GBCcA/2OubqYRApIVPMXbqOOR p8iEV6CgHJ8bXLWsKTOh2plVGF2OrF0Gn+syvr4SLWQJ6V2T0hosgi5Uww+jaRIS3unu DjqthP0aEQoFeWgFAm6J0kir59rsYtVySYP9A8jX3ZixU48tuGJ/gnC8PdPX3lmlBjUl rBqttTU7L7Guq1kvFT8xvST9hK7C17/yI5WWNTUb8FOthhgAkvNQt3BHh/RzlohqW15C NoSA0AKuTZ4UcSq4oLHsJNiqRPkHnUelFB2Zk/Nj3ij1azIodlJfdPiY2XS5qzcc6uMg AIjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:date:from :dkim-signature; bh=GOowIkYgNWQMJY1z2glDszfCPetfRLh+NG8awSyRKwA=; b=sdzpRDdVrlbmWuByptV6Ka5v3VbWzMJ17BHJoEdIT8x3L5rz4x/1VfIVjueDr7uTHO s4ozfJ0JpZkvLMieSC3wtEvQFCKXdeU5Nb3srJ78sd+uoFzmBACq0nHASV8iSQhJeszc CDCzg3aNZFRKHOZhNAmmFpXI+3dCVYkHMj9g4wQp8eUo4vxUGF3nWOe582L2XVr8Jf50 vlYPvUtPSh2exTL1UjpJPOxhl+Lu7AkIuX4OpKddsgG0rSEMgao296a3QwMtOQVHpj5s QomPfQA3/JTK+v1xKIDHiZAhfAL4XQhuHiZ7Ja7xphrJy6jXsZK7zPuzuvEAoG3lcWKX OP4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=cya3xNOk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rv4si7772501ejb.366.2020.07.28.13.04.33; Tue, 28 Jul 2020 13:04:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=cya3xNOk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732959AbgG1TpS (ORCPT + 99 others); Tue, 28 Jul 2020 15:45:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730048AbgG1TpO (ORCPT ); Tue, 28 Jul 2020 15:45:14 -0400 Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C93D9C061794 for ; Tue, 28 Jul 2020 12:45:13 -0700 (PDT) Received: by mail-qk1-x741.google.com with SMTP id 2so15796180qkf.10 for ; Tue, 28 Jul 2020 12:45:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=GOowIkYgNWQMJY1z2glDszfCPetfRLh+NG8awSyRKwA=; b=cya3xNOkiBwf0XFJOc0t7Hv3b/7hGbd6OyyXU+Ex9UL2sXzVwOffXHiWV/cCrr8mZZ sMUOS8iKAWJYdfwwfbNJ1U1g9laf5eBaF7mHeGHrE3ZAS1De0nRuo0znpyn/ohbBDqaW Cy3yITRvHDPkG3DKQ6R1+8+S0OSWsQspfYHYAmb0ytq0I+ATFoS9XZE7SDXKZr6bNW+K sxu5zQONpBuwA+PM0ArjIG9+Fs12LWZeSW/uGzZE67kbU3D05XnPaTRut9MaixDgEfr7 BdV6SNWsyuYbxZFqg9WoK3Vy9rJIliQ50W3Rm/YcgEoNsprzIoNeMvr2PHDyYLCmxmqs QqVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:date:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=GOowIkYgNWQMJY1z2glDszfCPetfRLh+NG8awSyRKwA=; b=aOtEq8rEGZSTlkpNpkuEIMbGgI/PuK6oqeXSw3M2sPAwnpaqgxxb/JTUCG1OfnHOEA KrQ4FWeJaGklHW2ANEWlQBfBxwHnb0inFaciJFZTMHH8YQqMKcnhyyeqbq6TXhreykv4 kCh+XY9tl+wYPXE+Zz3h3SokPi70UFKN6H65jdBqkbJrv3oIzDEWvZqccMfkS+QQHEuG n0Lcr9SZclVHpgHvVnOqs+Pu+CAnGhU/WrNRJHwY4ywPCeZ/x3z5BkfX3abf2Isjh3WB p4HGRn/3wkAF2wiNNbkx1lkcdQFAVedirsS+eHpzj/0eRHnlUHnda4/8H+OTaqRh1Oef ez2A== X-Gm-Message-State: AOAM5316kGteHawW4u5uN0w3J4BLOjsk7lDExdKl2DdUhARotsa9w9rv juhx9VSqHgplh1OSQ/uLQIs= X-Received: by 2002:a37:80c:: with SMTP id 12mr30581782qki.149.1595965512983; Tue, 28 Jul 2020 12:45:12 -0700 (PDT) Received: from rani.riverdale.lan ([2001:470:1f07:5f3::b55f]) by smtp.gmail.com with ESMTPSA id b22sm21849553qka.43.2020.07.28.12.45.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jul 2020 12:45:12 -0700 (PDT) From: Arvind Sankar X-Google-Original-From: Arvind Sankar Date: Tue, 28 Jul 2020 15:45:11 -0400 To: Kees Cook Cc: Arvind Sankar , x86@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 6/8] x86/kaslr: Simplify process_gb_huge_pages Message-ID: <20200728194511.GB4150860@rani.riverdale.lan> References: <20200727215047.3341098-1-nivedita@alum.mit.edu> <20200727230801.3468620-7-nivedita@alum.mit.edu> <202007281225.C24B966D7@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <202007281225.C24B966D7@keescook> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 28, 2020 at 12:27:17PM -0700, Kees Cook wrote: > On Mon, Jul 27, 2020 at 07:07:59PM -0400, Arvind Sankar wrote: > > Short-circuit the whole function on 32-bit. > > > > Replace the loop to determine the number of 1Gb pages with arithmetic. > > > > Fix one minor bug: if the end of the region is aligned on a 1Gb > > boundary, the current code will not use the last available 1Gb page due > > to an off-by-one error. > > > > Signed-off-by: Arvind Sankar > > Can you add some KUnit tests could be written to do validation of the > refactorings? Touching this code is so painful. :) > > -Kees Can I try to do that later -- I've never written a KUnit test, though it's probably a good opportunity to learn how to do one. > > > +++ b/arch/x86/boot/compressed/kaslr.c > > @@ -546,49 +546,43 @@ static void store_slot_info(struct mem_vector *region, unsigned long image_size) > > static void > > process_gb_huge_pages(struct mem_vector *region, unsigned long image_size) > > { > > - unsigned long addr, size = 0; > > + unsigned long pud_start, pud_end, gb_huge_pages; > > struct mem_vector tmp; > > - int i = 0; > > > > - if (!max_gb_huge_pages) { > > + if (IS_ENABLED(CONFIG_X86_32) || !max_gb_huge_pages) { > > store_slot_info(region, image_size); > > return; > > } > > Won't max_gb_huge_pages always be false for 32-bit? > > -- > Kees Cook It will, assuming someone doesn't pass bogus command-line arguments to reserve Gb pages on 32-bit. But the IS_ENABLED check allows the compiler to eliminate the entire function at compile time.