Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp571137ybg; Tue, 28 Jul 2020 13:05:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzx3va3a8fmbyEpwq6DV/Yn2ClT0Kz248ZWJcmeWETDFN6qIT8SXE6a2mBEigl2yrrAmyoh X-Received: by 2002:a17:907:11db:: with SMTP id va27mr28323698ejb.175.1595966758947; Tue, 28 Jul 2020 13:05:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595966758; cv=none; d=google.com; s=arc-20160816; b=DIDMrP49K2fJPFDTpQkWXpiH3Gpg00gs7bOl7wnqnLxsX4VKg3AuAZ332YF76MXp6C KXkzjgEtfF8BkMyrzuSGoApKD25C18n8OzPwAqyAfDf997kjwkIVwiEHNFoEB6c2B4Rq m1/MnZbMxuejKhXe4A5+VGv7/tqPgz+ikoYaT3fRnPQD0mC7nea/U2l9O0UGqkeO8mDJ gIVJofhlffYLRmbewM1gbAG67CCiKaEc4m4ItcaHis+RsPf2j7w/Z4XtTNN37mbBim5l jO/iQS1o6EhRKkrKdWtERBJs4MLQPF2z9VZaGoVEerx7A3HmI/j1UomAdnFN0lHMC/LX 4PxA== 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:from:date :dkim-signature; bh=ADR3sxjOiI8EIqhLZSouL3EW3hA1BdmVXcyDJSxtf1g=; b=Sg8190KpKHrGtfCGrx9JJQuniRrhk+4QGnsLBSxBe7gDQvon1JzDNYltCYTcUC5+E/ cqJNjct/COBNhVnALnx9OdpSzYWRCFqqcwaA3vP7ztKEM4/oimG6NRbgg9E0jfZxrKOF +BSHnfk5bHMSGdPu68QkVu22MNJP0QAJlSfpnagNGumIamTOnkxIrO2CaVjsZk+f8h7Q Hs9UqYAVc51ClBLpdtuKdRiFiUWKYbwg80VzsvPNaDkAVI07g8LkuX9rtV2rcia2FDEl NRKzryYfK1QFx6O7YoU2KS6giKnV/LtlNus8U1TZLpVoUmqQ9koAvRf+n2b0b6ImrvZp 3kHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=feIz9NzY; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f9si9424327ejl.71.2020.07.28.13.05.37; Tue, 28 Jul 2020 13:05:58 -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=pass header.i=@chromium.org header.s=google header.b=feIz9NzY; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729225AbgG1T1U (ORCPT + 99 others); Tue, 28 Jul 2020 15:27:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728589AbgG1T1T (ORCPT ); Tue, 28 Jul 2020 15:27:19 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D1DBC061794 for ; Tue, 28 Jul 2020 12:27:19 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id l2so5193045pff.0 for ; Tue, 28 Jul 2020 12:27:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=ADR3sxjOiI8EIqhLZSouL3EW3hA1BdmVXcyDJSxtf1g=; b=feIz9NzYxqlqeBvyyAc1jflhjVzz8J4U13VpEpSwtoe0a5xoAHqa5zj9JZPoaGp9OI Gtguyun+XZ7PxMgQn9grw1fuZwRkkSo0A9fVzds0NXyOPE6iFJqPUmLdunNhxWJFIFNX VsHJ+53FL3iwFfhSpElXpHgVF+wVhBTxQxVB8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=ADR3sxjOiI8EIqhLZSouL3EW3hA1BdmVXcyDJSxtf1g=; b=HfrLAXq0AMZIV62KDUY5Bi3y2+LfzYT+9HLQnTGTLeekUNbv9GeNwOwpsnSTomoYE7 FT1YH5ju02eTbIIbRG+wGGNRY/2guDTf4XS/7nU2+c3b5SJZZpQJJD58coqbl4+k8gp2 UERad92vHr/RoI5vCvjLPP6OiBqc2Mk7DYDpLgldoCOslUqJAUavnSzTFQXMMDpAZc7m cbhR+WoYmo5lSnK/b0hYi29dZBfnDf//C7rMUPLs0JjVYOpNRAM/qdshWsJ7+aZXiGJl d2Z/Xbi4heUCgf+9XlMHIwKTJ84NsUhSIFCVn6gAShPQOBzwbCnJgxNAzeWusmkZ1qvp OrSQ== X-Gm-Message-State: AOAM533TIQdWdHB4g9tG+wmS8AJG4zJHYh1K4qcv3WqfZzhdzL7T1yrh eAzWrxNFj+RaN723FL+MqJKZdA== X-Received: by 2002:aa7:8557:: with SMTP id y23mr25596453pfn.148.1595964438941; Tue, 28 Jul 2020 12:27:18 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id y8sm3912560pjj.17.2020.07.28.12.27.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jul 2020 12:27:18 -0700 (PDT) Date: Tue, 28 Jul 2020 12:27:17 -0700 From: Kees Cook To: Arvind Sankar Cc: x86@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 6/8] x86/kaslr: Simplify process_gb_huge_pages Message-ID: <202007281225.C24B966D7@keescook> References: <20200727215047.3341098-1-nivedita@alum.mit.edu> <20200727230801.3468620-7-nivedita@alum.mit.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200727230801.3468620-7-nivedita@alum.mit.edu> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > +++ 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