Received: by 2002:ab2:7855:0:b0:1f9:5764:f03e with SMTP id m21csp369461lqp; Wed, 22 May 2024 07:06:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVSl+KevHugylNAE82bKnLJklGVQjc+Ee6bG24fIJz9SCnsko6/g2z7yFmZ+x4XOEsrQZlG9G1u4/vvdvKWzmEXFif9RA1JiKaQjLWofw== X-Google-Smtp-Source: AGHT+IG4eLq4Z+P9Wl2g2Stt+KPGJ6gABNyng9Yqr8AgAn7yM/jRJlt3kQsiMenYRicMKX13f0mE X-Received: by 2002:a05:6870:148a:b0:245:2f02:84f3 with SMTP id 586e51a60fabf-24c68d8105emr2111336fac.55.1716386786396; Wed, 22 May 2024 07:06:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716386786; cv=pass; d=google.com; s=arc-20160816; b=C4greGrlgbcz+T/dZul0GDWYzS76yTPKG08ddgJ4zixSDNM0NhSOwRtmiMbeasNg7R ih8B4rWYhLIJtabmqD/Dvx7//3AV+7igoTYihL5f/T+EX37AfY9KYIJtNmrwgD/9Sxry u4e1PrmnpnC2CyPcg9/9enpsA0PuFtENDk/BUTKaCe+2Kfgv5yJaWJBKQI8349g5WxK9 Of6ICG7UTuDVuICpZ5aceQy8hvLSM/BbU6qVmOur+Sb9X8qLdikQuEJQpx9uB9Q2Ig5g fP8ZxkxdR5OzQiud7bQ0398mhvOAItq35saUUwN7UthKmsioOlcbmWyPR1AsLmf+TFN1 lBTg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :reply-to:message-id:subject:cc:to:from:date:dkim-signature; bh=DGIHdh6C9kf3xohOy6zelPFZjDHpCE0/tlY+EHwmYFQ=; fh=wTTdwo4pxHTZOSkahQitc9bGXacBOBcu3RCwZOpv8P8=; b=NHTaWc06/xt/NxByGKkZOAprnSGKdeAIzRiMIjG8S/YyfrvnCH3w5Mwk6K2jr61LzI Hx4HSZZDgaqDC95rvYnVQ3Ug5C4gRHbj2mC9/fCkg7AdafP3OiixOWIKYqxU0L7rRiEk jCL5BlaVn83ltVfZSUtqCGRjGvij5rATtzOAXdfE67q0ofA2OF303lbueXB2HDg2vbfk TTF+JG8WPWUeLadR8l77DGWy9rGesb+kRGKBRcMYCMwA7L40pbqR5NqucwQSwBoD3JVu LSOjyl3DSceW+SoRkDCy2yuQ92UdZ8euZMISDrExpQJCgejQDXJ3LYnfwFHC4J/po05Y Yrpg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=TCKc+LOT; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-186326-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-186326-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id a1e0cc1a2514c-803187f359fsi134707241.176.2024.05.22.07.06.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 07:06:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-186326-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=TCKc+LOT; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-186326-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-186326-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 990FB1C21C5C for ; Wed, 22 May 2024 14:06:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 74A7B13E03E; Wed, 22 May 2024 14:06:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TCKc+LOT" Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 22B1B6AB9 for ; Wed, 22 May 2024 14:06:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716386779; cv=none; b=G0fcev3IHTBg0fXwICyNzPC03peflYMmUEcEVs0EpXvGRoX557Sa6AhwdzL3D15sdnAeb8iFBaw72XMc/FfRWhGUNOhuDom7Y6sGuK0LfgSxIGLyhVd1qddaA7CX3tPvfi6+lQs/uy4Zu/58DmidffIR3jmdlAV2tToPQwQHmk8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716386779; c=relaxed/simple; bh=yG+H6NXM+gADjyTua45URn88sT7dUFGj3GVYs9fsNpI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Ibf6oyfPnchua4rexpdHsjD3gsfWmuBoDzZSRwSgbNaeKvuj2UEOczdiZO4n7FCojrAIRwLB9/gO9Pnx6IOqD0yziLxzYriyekqir73Luydbk5FavKe+uZoUsrWbReRDnVQl3juRocdt0kP8Mt0t63OksnWoBFomfotZWWSBFBU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=TCKc+LOT; arc=none smtp.client-ip=209.85.208.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-56e69888a36so11092832a12.3 for ; Wed, 22 May 2024 07:06:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716386776; x=1716991576; darn=vger.kernel.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=DGIHdh6C9kf3xohOy6zelPFZjDHpCE0/tlY+EHwmYFQ=; b=TCKc+LOTtw6BligeB+xsnXBtoEXViTjaPriHtN62JxNeW3ximREFScLRc8WF9vzuRt J6/HCIS680mVvUwRoNkAYv4rWGzy3zAOhvBe+cB97y8IyKm400mjfbfkLXPAWFZ2s6kX 6386zYKgYkAUihyMJahbFWVf9f1ZeC1kfIvS5Fe7NyATIn8ntKhuqPwvFVRpAZR4NqL2 +sE3tNqJo0JyuR4y4Z7PDnDFeXewIo+nJfhr9R9RgGsIspNXNA/QSNjF7TxB9N8Qpn96 ZXguLNzTGbN3qj6qXvIKuSp/u4ooeeFmTrVSDn//4lJknfmodUcnvEOTkrAW47m5X+cZ HXOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716386776; x=1716991576; h=user-agent:in-reply-to:content-disposition:mime-version:references :reply-to:message-id:subject:cc:to:from:date:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=DGIHdh6C9kf3xohOy6zelPFZjDHpCE0/tlY+EHwmYFQ=; b=FsmQ/klqeM0nTiRAj4XGBDpjWZJ0RKGEOjq8O5v59xkzMwybuQqd5r1seB+Ce+ZWmL PPHFdsa984ixH0NiPe302hnDRYTshqO2HmHDMvJ304Uebfy1VANYqtO1tXk+QlkYpw5s 3t9hZ/tzWoRiFImvgLu8Mi0cQchr68qkI88zKO8Poqr2t7Ct/D/8z3CNAk37hhAc+OdM iPET4r89pf2Xn2jw7RI/gK/4uAQUYloqMe6ZcyDcYYqMn9aFLTaOu1twi3TDLnDZZWk8 Rb2U0cSzhNlGuqwxY9lgB9eJLgSLsx0CQpNLM3ibmB85dHJ2gfPl0T09+bFYCpvKAcw/ +p+w== X-Forwarded-Encrypted: i=1; AJvYcCUFMtmKE0TO7cvCOe6KJ6SdNaRxXGohZpEp+7+z57413u7pFoeEBs1aK64gQjsFWbd9o3UGIqbNWVKVgAURb+Ou9VanOP0ytS13zhtX X-Gm-Message-State: AOJu0YwcyYIGmf/riKptRHZlv/f211PnBj4XvE8arP1s/e2TYm/zk4n/ c4eVEM0AjMhzUXmZ9xJmgVFa+i6wNxjOBXl67GC2N5L7HJKIyOu6 X-Received: by 2002:a50:c048:0:b0:56e:22b6:d924 with SMTP id 4fb4d7f45d1cf-57832a3fab9mr1297350a12.13.1716386776003; Wed, 22 May 2024 07:06:16 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57509d459desm8654687a12.61.2024.05.22.07.06.15 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 22 May 2024 07:06:15 -0700 (PDT) Date: Wed, 22 May 2024 14:06:14 +0000 From: Wei Yang To: Thomas Gleixner Cc: Wei Yang , mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, linux-kernel@vger.kernel.org, Vivek Goyal , "Kirill A . Shutemov" , Ingo Molnar , Steve Wahl , Borislav Petkov Subject: Re: [PATCH] x86/head/64: level2_kernel_pgt's kernel area is built with _PAGE_PRESENT set Message-ID: <20240522140614.fxe6tw6y5clrnve3@master> Reply-To: Wei Yang References: <20240323232621.10400-1-richard.weiyang@gmail.com> <87jzjmgod2.ffs@tglx> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87jzjmgod2.ffs@tglx> User-Agent: NeoMutt/20170113 (1.7.2) On Wed, May 22, 2024 at 11:58:01AM +0200, Thomas Gleixner wrote: >On Sat, Mar 23 2024 at 23:26, Wei Yang wrote: >> The code is first introduced in 'commit 1ab60e0f72f7 ("[PATCH] x86-64: >> Relocatable Kernel Support")'. Then 'commit c88d71508e36b >> ("x86/boot/64: Rewrite startup_64() in C")', convert it to c. And >> 'commit 2aa85f246c181 ("x86/boot/64: Make level2_kernel_pgt pages >> invalid outside kernel area")' limit the range from _text to _end. >> >> Originally, it does the check because the loop iterate the whole >> level2_kernel_pgt, while currently it just fixup the kernel area. This >> area is built with _PAGE_PRESENT set. > >What's the actual problem you are trying to solve? Not a problem. It tries to remove some duplicate check. > >> /* fixup pages that are part of the kernel image */ >> for (; i <= pmd_index((unsigned long)_end); i++) >> - if (pmd[i] & _PAGE_PRESENT) >> - pmd[i] += load_delta; >> + pmd[i] += load_delta; > >Fixing up non-present PMDs is a pointless exercise. > Agree. While we are sure then range here must present. The whole process looks like this pmd in [0, _text) unset _PAGE_PRESENT pmd in [_text, _end] fix up delta pmd in (_end, 256) unset _PAGE_PRESENT Since we have compiled in _PAGE_PRESENT in this page table, it is not necessary to check _PAGE_PRESENT again before fixing up delta. BTW, if one entry between _text and _end is not present, we will failed to fixing the kernel code pmd entry, which will lead to some problem. >Thanks, > > tglx -- Wei Yang Help you, Help me