Message ID | dd39dfd18bcae4e5116597d4e9c186249aa15850.1671098103.git.baskov@ispras.ru |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp327759wrn; Thu, 15 Dec 2022 04:43:30 -0800 (PST) X-Google-Smtp-Source: AA0mqf79Sr+QqINmsRzgGVzt1R+3BoFVmU2EimxStiof9Z/XeftfkIHdeSyjqFH/5/8FkT0440yi X-Received: by 2002:a17:906:8257:b0:7c1:5098:907f with SMTP id f23-20020a170906825700b007c15098907fmr17002138ejx.61.1671108210538; Thu, 15 Dec 2022 04:43:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671108210; cv=none; d=google.com; s=arc-20160816; b=fTcohW9T61Z+V6GgJKvl5MvgjboQQr59NeDKpA93Nrrs0pJPY7St6SWUeWiVMQVhlr B3IwIWh7YvNTJqNEmLw3lQLXN2mHIngC3Uu4DPbA/VLMihGlizxh96rmSQfUgZGS5AuT CAMjghydSJK+BY2GNqNBJRPzCx25Tc7V5U9c/auCIAVlTARJc/CU22+yHRXgoz3KJHW9 t0IWrUQQ6/VhsnBi2BFDQ5CU+GHpqn3bMH7QGkrAxFECUhXGwBEYwF6BwQuNmY4M6tpE rIiYIXDHVk4/Tp3cZFAozGzU2Umv8FmTtJQStjwUIz4y3r21k3ODJJ6qb1OZbD9vFlhe a5Vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=KkRKm6qcAmh0kiXQ21qOF8qFcABzU2w96OZgSYkHTXk=; b=f/Cgd9Gf+Nwc/aEmzB0t84OETqjrdYuSp56MdwdPA3oyLeUeIZFbpGzWODGWch+72k shmaH95zOSq1B4GUO2vksNKcGCWl9V1vFo3Cs7r2UH9g1iCoxFgZlJIFRfOJPtTiUDHe 59EqT79N6fPNV5EhRUwbbVbK/25PUAmmiSmR91wg6ZPbnCKY9XrW21pj0iRZYfzp2JJ9 74/kS2Scbn38sGKPfZ8JOMK0AjMKkT4nBid7GufSvPXL2TJHJuiCzMe//J6TeG5L5Y3X 6hnSSYs7IvT2XeaTlSSwfMaLbmu8/dqmht9CcWM7rjlsKhS6SgBFRotwNVgJ4pnAdyrN O8PQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=obfol3CW; 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=ispras.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hd12-20020a170907968c00b007ad855bc09csi15139828ejc.595.2022.12.15.04.43.07; Thu, 15 Dec 2022 04:43:30 -0800 (PST) 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=@ispras.ru header.s=default header.b=obfol3CW; 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=ispras.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229626AbiLOMlq (ORCPT <rfc822;jeantsuru.cumc.mandola@gmail.com> + 99 others); Thu, 15 Dec 2022 07:41:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229905AbiLOMlY (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 15 Dec 2022 07:41:24 -0500 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAD0D27916; Thu, 15 Dec 2022 04:40:24 -0800 (PST) Received: from localhost.localdomain (unknown [83.149.199.65]) by mail.ispras.ru (Postfix) with ESMTPSA id 3C6D740737AF; Thu, 15 Dec 2022 12:40:23 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 3C6D740737AF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1671108023; bh=KkRKm6qcAmh0kiXQ21qOF8qFcABzU2w96OZgSYkHTXk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=obfol3CWp8LzXplKHkyHUZG/d7EfhBPFxgNTXiq/+9N8zDYn8ZUrazpcQ4bVXwJ2r K84oqYuP8j8keBSAxnJ3M0/tyucNLJbN6LEyFF9wedck8+HdFNuJb30hP0EVXy+rmU Mj7tXclEFv5gACAMJ1Rgv50xHd23feclvEs1SYc0= From: Evgeniy Baskov <baskov@ispras.ru> To: Ard Biesheuvel <ardb@kernel.org> Cc: Evgeniy Baskov <baskov@ispras.ru>, Borislav Petkov <bp@alien8.de>, Andy Lutomirski <luto@kernel.org>, Dave Hansen <dave.hansen@linux.intel.com>, Ingo Molnar <mingo@redhat.com>, Peter Zijlstra <peterz@infradead.org>, Thomas Gleixner <tglx@linutronix.de>, Alexey Khoroshilov <khoroshilov@ispras.ru>, Peter Jones <pjones@redhat.com>, "Limonciello, Mario" <mario.limonciello@amd.com>, joeyli <jlee@suse.com>, lvc-project@linuxtesting.org, x86@kernel.org, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH v4 09/26] x86/boot: Remove mapping from page fault handler Date: Thu, 15 Dec 2022 15:38:00 +0300 Message-Id: <dd39dfd18bcae4e5116597d4e9c186249aa15850.1671098103.git.baskov@ispras.ru> X-Mailer: git-send-email 2.37.4 In-Reply-To: <cover.1671098103.git.baskov@ispras.ru> References: <cover.1671098103.git.baskov@ispras.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752283963084720402?= X-GMAIL-MSGID: =?utf-8?q?1752283963084720402?= |
Series |
x86_64: Improvements at compressed kernel stage
|
|
Commit Message
Evgeniy Baskov
Dec. 15, 2022, 12:38 p.m. UTC
After every implicit mapping is removed, this code is no longer needed. Remove memory mapping from page fault handler to ensure that there are no hidden invalid memory accesses. Tested-by: Mario Limonciello <mario.limonciello@amd.com> Tested-by: Peter Jones <pjones@redhat.com> Signed-off-by: Evgeniy Baskov <baskov@ispras.ru> --- arch/x86/boot/compressed/ident_map_64.c | 26 ++++++++++--------------- 1 file changed, 10 insertions(+), 16 deletions(-)
Comments
On Thu, 15 Dec 2022 at 13:40, Evgeniy Baskov <baskov@ispras.ru> wrote: > > After every implicit mapping is removed, this code is no longer needed. > > Remove memory mapping from page fault handler to ensure that there are > no hidden invalid memory accesses. > > Tested-by: Mario Limonciello <mario.limonciello@amd.com> > Tested-by: Peter Jones <pjones@redhat.com> > Signed-off-by: Evgeniy Baskov <baskov@ispras.ru> Reviewed-by: Ard Biesheuvel <ardb@kernel.org> > --- > arch/x86/boot/compressed/ident_map_64.c | 26 ++++++++++--------------- > 1 file changed, 10 insertions(+), 16 deletions(-) > > diff --git a/arch/x86/boot/compressed/ident_map_64.c b/arch/x86/boot/compressed/ident_map_64.c > index fec795a4ce23..ba5108c58a4e 100644 > --- a/arch/x86/boot/compressed/ident_map_64.c > +++ b/arch/x86/boot/compressed/ident_map_64.c > @@ -386,27 +386,21 @@ void do_boot_page_fault(struct pt_regs *regs, unsigned long error_code) > { > unsigned long address = native_read_cr2(); > unsigned long end; > - bool ghcb_fault; > + char *msg; > > - ghcb_fault = sev_es_check_ghcb_fault(address); > + if (sev_es_check_ghcb_fault(address)) > + msg = "Page-fault on GHCB page:"; > + else > + msg = "Unexpected page-fault:"; > > address &= PMD_MASK; > end = address + PMD_SIZE; > > /* > - * Check for unexpected error codes. Unexpected are: > - * - Faults on present pages > - * - User faults > - * - Reserved bits set > - */ > - if (error_code & (X86_PF_PROT | X86_PF_USER | X86_PF_RSVD)) > - do_pf_error("Unexpected page-fault:", error_code, address, regs->ip); > - else if (ghcb_fault) > - do_pf_error("Page-fault on GHCB page:", error_code, address, regs->ip); > - > - /* > - * Error code is sane - now identity map the 2M region around > - * the faulting address. > + * Since all memory allocations are made explicit > + * now, every page fault at this stage is an > + * error and the error handler is there only > + * for debug purposes. > */ > - kernel_add_identity_map(address, end, MAP_WRITE); > + do_pf_error(msg, error_code, address, regs->ip); > } > -- > 2.37.4 >
diff --git a/arch/x86/boot/compressed/ident_map_64.c b/arch/x86/boot/compressed/ident_map_64.c index fec795a4ce23..ba5108c58a4e 100644 --- a/arch/x86/boot/compressed/ident_map_64.c +++ b/arch/x86/boot/compressed/ident_map_64.c @@ -386,27 +386,21 @@ void do_boot_page_fault(struct pt_regs *regs, unsigned long error_code) { unsigned long address = native_read_cr2(); unsigned long end; - bool ghcb_fault; + char *msg; - ghcb_fault = sev_es_check_ghcb_fault(address); + if (sev_es_check_ghcb_fault(address)) + msg = "Page-fault on GHCB page:"; + else + msg = "Unexpected page-fault:"; address &= PMD_MASK; end = address + PMD_SIZE; /* - * Check for unexpected error codes. Unexpected are: - * - Faults on present pages - * - User faults - * - Reserved bits set - */ - if (error_code & (X86_PF_PROT | X86_PF_USER | X86_PF_RSVD)) - do_pf_error("Unexpected page-fault:", error_code, address, regs->ip); - else if (ghcb_fault) - do_pf_error("Page-fault on GHCB page:", error_code, address, regs->ip); - - /* - * Error code is sane - now identity map the 2M region around - * the faulting address. + * Since all memory allocations are made explicit + * now, every page fault at this stage is an + * error and the error handler is there only + * for debug purposes. */ - kernel_add_identity_map(address, end, MAP_WRITE); + do_pf_error(msg, error_code, address, regs->ip); }