From patchwork Fri Mar 1 10:40:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 13578324 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AFFFFC5475B for ; Fri, 1 Mar 2024 10:41:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=gs0YpJIXcT0xrm51j71p/1j5MO4+z7+ly6ljArGeqQg=; b=0cM1AGLKaeQLW7/3wmVcEyRmN3 p56yWISsNcznlPi/H7KSPyQVvq/W2BQ0mNpMpPvWiDzWTu/Srho0sVjT/sVSEFvuVIUkTCMuaiZKd M6Gh+b1qC00N/h6D+/dUJ7rPqBPjVynKQjkoy5+su8+PvYax/M7z2L9Yi/IuMOsTb4eZce6OswHaZ p4mipsZZnhoWDzHWpSfL8FDWqL2S3MO+sXMHM6bLrJ5qI8bcoqktzbmFMUpwnFWDkIBlBjNL7JSYc fvpOToj6ba26pPKBLAs/Wcz/568j6ssQpmRV3PRP83kxTaJGPkluicNNRr0jy9vN2bXcFd0+HnCPc fBzPFEvg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rg0K8-0000000HOiX-1zjr; Fri, 01 Mar 2024 10:41:04 +0000 Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rg0K6-0000000HOfx-1gXP for linux-arm-kernel@lists.infradead.org; Fri, 01 Mar 2024 10:41:03 +0000 Received: by mail-wm1-x34a.google.com with SMTP id 5b1f17b1804b1-412b4744e9dso11073315e9.3 for ; Fri, 01 Mar 2024 02:41:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709289659; x=1709894459; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=o/KU3cNIFLTplwJBdg6kNeEa2H7z36K2XvosSAlRDg0=; b=H1HZjLscy6tbOJxYDG8l2mx7XJH9hyjlPo4o4ItLL+NWH2c8PjhU1kV1st5necg2cI NOYoyUM8PKp5hqoEnR652CtsLp/eg3qNKemzKnUSw0ZSrUwKotrMyMygFrSs0yuhqzb1 eQFTpqCdec7XW4dZAjy/PK0jtnh1OgrRGFqv6/D5soF61Zo7A1rkAJve5F6KxPRMFC0Z 2oGt0fUTE5uVHhxKT3HSsjMY6GPtH370F7ziXiE8yEGV8zpBUuifXc3kZ0y7Q38fyye3 59OUvZKf1S2gKn3cJj4yLOjs5rZSiXQrTQq29gUneYjQxd0bBql9McuMhQYwgmvH1r/x JbpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709289659; x=1709894459; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=o/KU3cNIFLTplwJBdg6kNeEa2H7z36K2XvosSAlRDg0=; b=F+Rdlm3J7y3ZfaZEREkhSnRG+xzXecvDPdMGS0BIZ5ukVh6kydsyd9lWDHA0hH+D/s MZAmitDo0oJR/pGsf7lc+JswKNrqsrIaNEXco30EpCHYrX5qemGIEc068Gmc/BZ4S4Is Hg6ikneZXnZSp+8w1l2kbyKvZ7N9j/is5W8c7ALivm4B7iyTNasUSU2IcpRpy1lFySso N+8iNtc7sMI3ah3gcGi5LxQvIA4vavdIP17drSrLWnFIWw3z3qG4+X7NVTbxsmCwCD/S y/2khmKP/hJMzi1Ng7+onioBqSglla3ndEMpUdjTPz7fd3tvzWnDtCYmvXpHulciC4m1 y8xg== X-Gm-Message-State: AOJu0YwJ5+g1f2K9ybdx4m642gDHXpjUVtcFg1prqFJlgQAMB2fYfN5p bwafnG+5aVFSu4h7H/nlWyKClrj6pSjJbbm+gRpl9w3RML8CX6KQmUJNEf5xLYwV/9PS1CM6LzH kNcINaeJxhxUvpamIbMLw/bNG+73WRwGx6eQ9EQP6/FrmdI/lj1ThNotOcfwtk/ziTQI5aTJ2QC EOPYU6DKizOSMECAmmN879Ya41JeyGY2+pWLgcE3KD X-Google-Smtp-Source: AGHT+IEwNadGlK5tTNvImY22iXwiAKFvL5QPYjgGpfJ+GrKGG1luVBa8q/imjoSPpx03kAlzbTZDadbg X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:118a]) (user=ardb job=sendgmr) by 2002:adf:ec8b:0:b0:33d:6bbb:c7fb with SMTP id z11-20020adfec8b000000b0033d6bbbc7fbmr2110wrn.6.1709289659403; Fri, 01 Mar 2024 02:40:59 -0800 (PST) Date: Fri, 1 Mar 2024 11:40:49 +0100 In-Reply-To: <20240301104046.1234309-4-ardb+git@google.com> Mime-Version: 1.0 References: <20240301104046.1234309-4-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=1071; i=ardb@kernel.org; h=from:subject; bh=UmpVTh2W4yVIC6MjrFw2QXQNGc5O+BcHsxj+TXkksHw=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIfXhho0285Qe/qvmkAuOM50qNmXHw3npJ5kys/3yFvbfd Vwz+9q0jlIWBjEOBlkxRRaB2X/f7Tw9UarWeZYszBxWJpAhDFycAjCRLheG/8FGS7OrJ6/ZoxG7 8dTXALXtiQu8G5bUGVg3RiyZWPmpvYqRoSfnj9Zze5d7+fzf1x29eqDhsNCVqrc/e59eqLpmcM/ zAC8A X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Message-ID: <20240301104046.1234309-6-ardb+git@google.com> Subject: [PATCH 2/2] arm64/mm: Avoid ID mapping of kpti flag if it is no longer needed From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: catalin.marinas@arm.com, will@kernel.org, Ard Biesheuvel X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240301_024102_470195_285801E5 X-CRM114-Status: GOOD ( 14.91 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Ard Biesheuvel arm64_use_ng_mappings will be set to 'true' by the early boot code if it decides to use non-global (nG) attributes for all kernel mappings, typically when enabling KASLR on a system that does not implement E0PD. In this case, the G-to-nG update routines are never called, and so there is no reason to create the writable mapping of the associated status flag in the ID map. Signed-off-by: Ard Biesheuvel --- arch/arm64/mm/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index b131ed31a6c8..bf5b1c426ad0 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -777,7 +777,7 @@ static void __init create_idmap(void) IDMAP_ROOT_LEVEL, (pte_t *)idmap_pg_dir, false, __phys_to_virt(ptep) - ptep); - if (IS_ENABLED(CONFIG_UNMAP_KERNEL_AT_EL0)) { + if (IS_ENABLED(CONFIG_UNMAP_KERNEL_AT_EL0) && !arm64_use_ng_mappings) { extern u32 __idmap_kpti_flag; u64 pa = __pa_symbol(&__idmap_kpti_flag);