Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2889772rwd; Wed, 14 Jun 2023 08:32:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5ZgSPwRv2rk+Qvdwlz0IbO3l1XwdVQa4300sINNY7VvuVP0BRzmiC1AxWCK4iuCrP8ldYZ X-Received: by 2002:a17:902:d4cc:b0:1af:d4f0:1dbe with SMTP id o12-20020a170902d4cc00b001afd4f01dbemr14005646plg.23.1686756723362; Wed, 14 Jun 2023 08:32:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686756723; cv=none; d=google.com; s=arc-20160816; b=hM8zeVCihektITGCGe0+bJTYQGZMCOez67r5T0P+ga+rj8dBsjTxkhXsIXkFBLf4lN vkjBYNy9pd3zmKjk9hvNlB/mNPAAgeybH/GunBwgaJrRR3qqwaBUGpXCRDa+TYEQO6ob OHgQK/omblqVq1E3ID8KRVjSkMiQfYQPZSI+bwV6C2fBrXGpza8yTZr/99bW2RosFG4r eSZQ1kBXMsFFTckoke0PwRKkaUjZoSi9zWB2XXuzPlY25ZkpdW3++zNL0y9r/PaNuUFT xCB9n7X4+9SF9gFcWa85chEnT6N/lqQ1vUxmh2Z4kzW2YOHa/zmkFjECZfGHQuIvLscJ R7xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=8S3yVWX79DOEfJOa4C6brDoMRwt5t2S8Kzap9NWc/WM=; b=Z0Wl+xeffLMqe6o0MYeiAKaes4mM2IqIjgr7VyxpXgR3Cq4wemBsolyWbgm12RUmkq k00u6J+ougAOO2M75ws8GAKmdqdfGblqet7nx6y75gEWECw6y9ATQugEAvYkKUWg+zIt OefcHEIOtTMc9fgNw4Wk85iLt2P3qtSDga4f5xASq/EicENWD6FYcSvhJg0Wo7WCTXMm c1LX6rYNBaaOOj49fDCgBO6QEuP93OFuKiG4tcahePz8s8+g1pyAyT1euHI1iaUxdK3d NtHwjIoJL/SFTw3ls0xikxNtt9loecdGRqDETzUXe6wdAYdwcijrxUp46CGXIaQP3GGT 34Nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RsV7jPB4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f1-20020a170902ce8100b001b07c3c31f1si11362012plg.267.2023.06.14.08.31.48; Wed, 14 Jun 2023 08:32:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RsV7jPB4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343569AbjFNPK3 (ORCPT + 99 others); Wed, 14 Jun 2023 11:10:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343734AbjFNPKV (ORCPT ); Wed, 14 Jun 2023 11:10:21 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D6691FE8 for ; Wed, 14 Jun 2023 08:10:10 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id F1AF763A74 for ; Wed, 14 Jun 2023 15:10:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0DC1C433C8; Wed, 14 Jun 2023 15:10:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686755409; bh=tC8eacPvb1QHrtphp4pCjOVMIPldZgf3oShJrp8Cncc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=RsV7jPB4ADmcDf3PcrZ5J0jVbNzS9Rzpswx1r6en52P4Sx6EXeyg/YWNnvvgKJlKe 04j8Ek/3E/TGCl0A+qqbp0yEFNHM8ugfnJuBjsksDTeKMVXU7dhFsHvnckwQmowYkd 7NFvFuYEXfNw1MwbRVePY8NsRnP5wc3QyuS1JIY9G+1NlsZ0Tp47j2KqCgmMgtit41 lveVeHunVLx3yCElYzAvtcalyZKJpvXfpmK4vHUNnX7IO36RejarQd53aOUvq402fM s43EGh5+momIWeangwzsDOuWC74oqStLH9yz7UcESnVG0Rx90d3i5cktyiXD2W1b4c q3zebp8iplzGw== Date: Wed, 14 Jun 2023 16:10:03 +0100 From: Lee Jones To: Dave Hansen Cc: Peter Zijlstra , Dave Hansen , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: x86: pgtable / kaslr initialisation (OOB) help Message-ID: <20230614151003.GY3635807@google.com> References: <20230614132339.GS3635807@google.com> <20230614141654.GA1640123@hirez.programming.kicks-ass.net> <20230614143732.GW3635807@google.com> <0cefb67a-6fae-daa2-c871-ae35b96aac08@intel.com> <20230614150615.GX3635807@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230614150615.GX3635807@google.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 14 Jun 2023, Lee Jones wrote: > Thanks for chiming in Dave. I hoped you would. > > On Wed, 14 Jun 2023, Dave Hansen wrote: > > > On 6/14/23 07:37, Lee Jones wrote: > > > Still unsure how we (the kernel) can/should write to an area of memory > > > that does not belong to it. Should we allocate enough memory > > > (2*PAGE_SIZE? rather than 8-Bytes) for trampoline_pgd_entry to consume > > > in a more sane way? > > > > No. > > > > I think this: > > > > set_pgd(&trampoline_pgd_entry, > > __pgd(_KERNPG_TABLE | __pa(p4d_page_tramp))); > > > > is bogus-ish. set_pgd() wants to operate on a pgd_t inside a pgd > > *PAGE*. But it's just being pointed at a single _entry_. The address > > of 'trampoline_pgd_entry' in your case also just (unfortunately) > > happens to pass the: > > > > __pti_set_user_pgtbl -> pgdp_maps_userspace() > > > > test. I _think_ we want these to just be something like: > > > > trampoline_pgd_entry = __pgd(_KERNPG_TABLE | > > __pa(p4d_page_tramp); > > > > That'll keep us away from all of the set_pgd()-induced nastiness. > > Okay. Is this what you're suggesting? > > diff --git a/arch/x86/mm/kaslr.c b/arch/x86/mm/kaslr.c v > index d336bb0cb38b..803595c7dcc8 100644 > --- a/arch/x86/mm/kaslr.c > +++ b/arch/x86/mm/kaslr.c > @@ -176,7 +176,7 @@ void __meminit init_trampoline_kaslr(void) > set_pgd(&trampoline_pgd_entry, > __pgd(_KERNPG_TABLE | __pa(p4d_page_tramp))); > } else { > - set_pgd(&trampoline_pgd_entry, > - __pgd(_KERNPG_TABLE | __pa(pud_page_tramp))); > + trampoline_pgd_entry = > + __pgd(_KERNPG_TABLE | __pa(p4d_page_tramp); Note the change of *.page_tramp here. s/pud/p4d/ I'm assuming that too was intentional? > } > } > > If so, I'll take it for a spin right now. -- Lee Jones [李琼斯]