Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7865785rwb; Wed, 23 Nov 2022 11:50:59 -0800 (PST) X-Google-Smtp-Source: AA0mqf4ZtzSwXrqKkE5oQXm5zhwiilLdYw//++rfLpQPtpVZI5p+IHz8FtfkblvcU+s9e+CIrKGH X-Received: by 2002:a17:902:eb42:b0:183:fffb:1c09 with SMTP id i2-20020a170902eb4200b00183fffb1c09mr17348508pli.69.1669233059563; Wed, 23 Nov 2022 11:50:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669233059; cv=none; d=google.com; s=arc-20160816; b=PGx7KeihPcHLGi2iHoCzxZi2eANncsHlKc5gsqXSQy+ZQz91CUKSDdoMhvF9S23ugr 2T+zvCCKaq9JEjkvWg/3huPGloAbzbiwuZKnEYpq/f0ULOS7Xpwp1mc6YSGhZYKO4/qH vSsEqifZVWnH+I6v0n19+6GiLDxNniLbgm32EceL/+iar1WPlo6Ayx3DSGmD5gLLsJnX opRoWm7jdTx96diu1zvgdtM9f+sU3Y++G7zhZZwZ/GUcMmkweDXVs6izHpLvUbK0SNFX DHQhzWQ9HQT274VkvG8Xsl2jXCdkHaRk+BtolFFcPoM/QlFucsxnHLTJCPYpseewtX1u PU8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=xYNUdKeKDvT8mT9/ZHcNVoishfiUIhq0BFNbiLz19yA=; b=P7LlG8M3njBpxBiJNkpdRsmLhlcyxUv6hzOKbKYVo4Npn6lcAxLQkKTXXU+dCxVo+/ UNrTLgtvyKiD8/06duh5iVj+M/aDrx+CdqGaBreXHsjDvL+lNYP/39mkLYQlfVKxVEas M9DNVugxbhiqX6KMAPuTbsuvHFhoF04dfIKzCY50xQYUVMKHf4GA3B9alG3lqod/4oUW xZO76ZSAKPkHH9upPMfrLzwJ3jF7okL2g8N/bAeyYCfbJN7OoIA5uixACDqLTxUA+8Sg /eksJPPdcvV9G8lLYOEs2nv64ans5JkbHYsv9RQMu7HYXImsMM7PAzgyFXIyyrKLC1aO u2Pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=GkcQ4aDS; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l9-20020a655609000000b0046edbb5b20esi520598pgs.668.2022.11.23.11.50.43; Wed, 23 Nov 2022 11:50:59 -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=@atishpatra.org header.s=google header.b=GkcQ4aDS; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239840AbiKWTM5 (ORCPT + 89 others); Wed, 23 Nov 2022 14:12:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239688AbiKWTMt (ORCPT ); Wed, 23 Nov 2022 14:12:49 -0500 Received: from mail-oa1-x32.google.com (mail-oa1-x32.google.com [IPv6:2001:4860:4864:20::32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25F9238B for ; Wed, 23 Nov 2022 11:12:46 -0800 (PST) Received: by mail-oa1-x32.google.com with SMTP id 586e51a60fabf-1322d768ba7so21939092fac.5 for ; Wed, 23 Nov 2022 11:12:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=atishpatra.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=xYNUdKeKDvT8mT9/ZHcNVoishfiUIhq0BFNbiLz19yA=; b=GkcQ4aDShxTS/4JJ20x52W1asLWeep8pqcGzmv6Dc8t7/RytG/dgK1GAiBGHIoG7Jx tczb1a1x73VjicRSW1kWfAi31UZ5tUgBU0ZUXf248ak/5xaTu+LFg6f8dW57NDqJBuJh 1wIhteLDo9cI+ZCcHbud0ARTw2Hdq39z3Dw1o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xYNUdKeKDvT8mT9/ZHcNVoishfiUIhq0BFNbiLz19yA=; b=hFHtVN5Hvlpig/KvhDVA2dZATFOgwqbSnvtWtFAUi7CaJQtLIC60nSWIt6DpWrV5Cx uU3oDYNbmoqijjTvykzB3EqEKecxpkzXLw8hKXcOtD57xtEJiAppEn1TBXCED6Idmy+J veWdLavllu+Veh47beJjS6IJCrGOVH7vKwcuNVfN67GEeePwVWaXcWIjFQNUXzpig2QI 2YBHGtyDV7byN13J38AnmMeW7qOrW1iaBGJ94n9+4aIg0VA7GdbGcWSdoq1M0cRESjoj 5GVPjfY4FjS8aFl5z2ERXZP9T16nXRjGyC7JAB7GghIR55FDQ2RdETwn+O1GG/PAuZr/ dNBA== X-Gm-Message-State: ANoB5pmYzQK70jO5vqLRWpiyX6hSw1OA8EqdaCRATYNrrmHoJXteGC7K tVD5ntOBeUa366CeyUoqxNCEdZrtLvTeQl6ZtwB+ X-Received: by 2002:a05:6870:60a4:b0:132:79b1:f85 with SMTP id t36-20020a05687060a400b0013279b10f85mr8030534oae.274.1669230765966; Wed, 23 Nov 2022 11:12:45 -0800 (PST) MIME-Version: 1.0 References: <20221121133303.1782246-1-alexghiti@rivosinc.com> In-Reply-To: From: Atish Patra Date: Wed, 23 Nov 2022 11:12:35 -0800 Message-ID: Subject: Re: [PATCH] riscv: Sync efi page table's kernel mappings before switching To: Emil Renner Berthing Cc: Alexandre Ghiti , Ard Biesheuvel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Heinrich Schuchardt , linux-efi@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 23, 2022 at 9:19 AM Emil Renner Berthing wrote: > > Hi Alexandre, > > On Mon, 21 Nov 2022 at 14:33, Alexandre Ghiti wrote: > > > > The EFI page table is initially created as a copy of the kernel page table. > > With VMAP_STACK enabled, kernel stacks are allocated in the vmalloc area: > > if the stack is allocated in a new PGD (one that was not present at the > > moment of the efi page table creation or not synced in a previous vmalloc > > fault), the kernel will take a trap when switching to the efi page table > > when the vmalloc kernel stack is accessed, resulting in a kernel panic. > > > > Fix that by updating the efi kernel mappings before switching to the efi > > page table. > > > > Signed-off-by: Alexandre Ghiti > > Thanks for the patch! With this applied on the Ubuntu 5.19 kernel I > can enable CONFIG_VMAP_STACK and cat /sys/firmware/efi/efivars/* on > the Unmatched without locking up. So > > Tested-by: Emil Renner Berthing > > > --- > > arch/riscv/include/asm/efi.h | 6 +++++- > > arch/riscv/include/asm/pgalloc.h | 11 ++++++++--- > > 2 files changed, 13 insertions(+), 4 deletions(-) > > > > diff --git a/arch/riscv/include/asm/efi.h b/arch/riscv/include/asm/efi.h > > index f74879a8f1ea..e229d7be4b66 100644 > > --- a/arch/riscv/include/asm/efi.h > > +++ b/arch/riscv/include/asm/efi.h > > @@ -10,6 +10,7 @@ > > #include > > #include > > #include > > +#include > > > > #ifdef CONFIG_EFI > > extern void efi_init(void); > > @@ -20,7 +21,10 @@ extern void efi_init(void); > > int efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md); > > int efi_set_mapping_permissions(struct mm_struct *mm, efi_memory_desc_t *md); > > > > -#define arch_efi_call_virt_setup() efi_virtmap_load() > > +#define arch_efi_call_virt_setup() ({ \ > > + sync_kernel_mappings(efi_mm.pgd); \ > > + efi_virtmap_load(); \ > > + }) > > #define arch_efi_call_virt_teardown() efi_virtmap_unload() > > > > #define ARCH_EFI_IRQ_FLAGS_MASK (SR_IE | SR_SPIE) > > diff --git a/arch/riscv/include/asm/pgalloc.h b/arch/riscv/include/asm/pgalloc.h > > index 947f23d7b6af..59dc12b5b7e8 100644 > > --- a/arch/riscv/include/asm/pgalloc.h > > +++ b/arch/riscv/include/asm/pgalloc.h > > @@ -127,6 +127,13 @@ static inline void p4d_free(struct mm_struct *mm, p4d_t *p4d) > > #define __p4d_free_tlb(tlb, p4d, addr) p4d_free((tlb)->mm, p4d) > > #endif /* __PAGETABLE_PMD_FOLDED */ > > > > +static inline void sync_kernel_mappings(pgd_t *pgd) > > +{ > > + memcpy(pgd + USER_PTRS_PER_PGD, > > + init_mm.pgd + USER_PTRS_PER_PGD, > > + (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t)); > > +} > > + > > static inline pgd_t *pgd_alloc(struct mm_struct *mm) > > { > > pgd_t *pgd; > > @@ -135,9 +142,7 @@ static inline pgd_t *pgd_alloc(struct mm_struct *mm) > > if (likely(pgd != NULL)) { > > memset(pgd, 0, USER_PTRS_PER_PGD * sizeof(pgd_t)); > > /* Copy kernel mappings */ > > - memcpy(pgd + USER_PTRS_PER_PGD, > > - init_mm.pgd + USER_PTRS_PER_PGD, > > - (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t)); > > + sync_kernel_mappings(pgd); > > } > > return pgd; > > } > > -- > > 2.37.2 > > Thanks for the fix. With the correct Fixes tag in commit description:A Reviewed-by: Atish Patra -- Regards, Atish