From nobody Tue Jun 23 22:34:08 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3301C433EF for ; Fri, 25 Feb 2022 12:41:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235062AbiBYMlc (ORCPT ); Fri, 25 Feb 2022 07:41:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230513AbiBYMlb (ORCPT ); Fri, 25 Feb 2022 07:41:31 -0500 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 369991E4820 for ; Fri, 25 Feb 2022 04:40:59 -0800 (PST) Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 11CA33FCAC for ; Fri, 25 Feb 2022 12:40:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645792858; bh=PQyFtNV3tW1qRmwZ8HqaxvUDcyO7BHPqZZLC0geQ1k0=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Ae6uwJoC7HFzBfCRFar5n4oo8URjTrhqDLUy+iEc11IBAdnXENDiWBeq0HdQzIx6O JKgMxNIz31k2Mew4emurIYzwawPv9ApigXVoU8I02ZEUlflbvFssM0pewq75qziPwK Fpvo3VOJkzq4ze0RbML8LpiFue7xYyjWaxrDtxxsixyf7sSZAYUs8ctumU4VXid72e eKVNy4VvGF4iT0VMSVkbehNqX7ZljzmzqLh98pr0yQ8XPBM2o+hsMcFBz/yUeAUOun G5BdTWqcoKX+Z0rsY6GafwqjatY1bTgQ3CrHg/5M0B8+EYJdlZsSy9Gcse7lMqljJv 82nOslOOxrEsA== Received: by mail-wm1-f72.google.com with SMTP id i131-20020a1c3b89000000b0037bb9f6feeeso1508042wma.5 for ; Fri, 25 Feb 2022 04:40:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PQyFtNV3tW1qRmwZ8HqaxvUDcyO7BHPqZZLC0geQ1k0=; b=t9yoZphzXm4qiJDAq2KDTkzGhW29tOxIMTiXIyfssRYNbN3CY3Ygmg8j4Elwc2HPGt uPKygaBYxslS0J8G8+yHEpSu/EB6wWW3mfT6K5INASAn6vW1Lpf4+v6UUEl4CATjDDHv lYooiTJqEvpJPyjrZtc5miEjtBOweyv8gjmbVj2bzWNt58lls1gWAnjBRuhrBwoBaZ8x KFhcMWKo4Biy3bGDvS1K/CoAsEQCSzpfz9IvrqPK41nMJbm+MD//Iz7YPeT5HI3uFeIR qmav9MWMzhp4ZIq/+PDN0y2nniTMQdULtCng3QIwTneqI5ZBXjcKRznp9Atg5TMfNSKP L7EQ== X-Gm-Message-State: AOAM530MKou4eAPSa5zeX46oF2+OSvWy1A9Rq0j4REu3Sh8RjgSSlz3x q6NJXafLEO/PTnf86Psy5aAfnW/iY5FQvDkXsS9rAlzlO/yt4KGasYOXGoGqr0r67hU2RMsJblx GfDEd/5UE0AJQ8cyI+weXDaUHnWeD3IOhls8tzuhvNA== X-Received: by 2002:adf:a54c:0:b0:1ed:ab82:d5c with SMTP id j12-20020adfa54c000000b001edab820d5cmr5903436wrb.636.1645792857567; Fri, 25 Feb 2022 04:40:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJwT+su/PUtxfMPaEWHXQEsOYe5HRBKTe0eLxFb9GXFhSjzcIXlRc3bYFdCjzbmxa8WeOAipFA== X-Received: by 2002:adf:a54c:0:b0:1ed:ab82:d5c with SMTP id j12-20020adfa54c000000b001edab820d5cmr5903415wrb.636.1645792857391; Fri, 25 Feb 2022 04:40:57 -0800 (PST) Received: from localhost.localdomain (lfbn-gre-1-195-1.w90-112.abo.wanadoo.fr. [90.112.158.1]) by smtp.gmail.com with ESMTPSA id b10-20020a5d550a000000b001e551ce8a64sm3228332wrv.9.2022.02.25.04.40.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Feb 2022 04:40:57 -0800 (PST) From: Alexandre Ghiti To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Alexandre Ghiti , Aleksandr Nogikh , Nick Hu , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com Subject: [PATCH -fixes v3 1/6] riscv: Fix is_linear_mapping with recent move of KASAN region Date: Fri, 25 Feb 2022 13:39:48 +0100 Message-Id: <20220225123953.3251327-2-alexandre.ghiti@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220225123953.3251327-1-alexandre.ghiti@canonical.com> References: <20220225123953.3251327-1-alexandre.ghiti@canonical.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" KASAN region was recently moved between the linear mapping and the kernel mapping, is_linear_mapping used to check the validity of an address by using the start of the kernel mapping, which is now wrong. Fix this by using the maximum size of the physical memory. Fixes: f7ae02333d13 ("riscv: Move KASAN mapping next to the kernel mapping") Signed-off-by: Alexandre Ghiti --- arch/riscv/include/asm/page.h | 2 +- arch/riscv/include/asm/pgtable.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/page.h b/arch/riscv/include/asm/page.h index 160e3a1e8f8b..004372f8da54 100644 --- a/arch/riscv/include/asm/page.h +++ b/arch/riscv/include/asm/page.h @@ -119,7 +119,7 @@ extern phys_addr_t phys_ram_base; ((x) >=3D kernel_map.virt_addr && (x) < (kernel_map.virt_addr + kernel_ma= p.size)) =20 #define is_linear_mapping(x) \ - ((x) >=3D PAGE_OFFSET && (!IS_ENABLED(CONFIG_64BIT) || (x) < kernel_map.v= irt_addr)) + ((x) >=3D PAGE_OFFSET && (!IS_ENABLED(CONFIG_64BIT) || (x) < PAGE_OFFSET = + KERN_VIRT_SIZE)) =20 #define linear_mapping_pa_to_va(x) ((void *)((unsigned long)(x) + kernel_m= ap.va_pa_offset)) #define kernel_mapping_pa_to_va(y) ({ \ diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgta= ble.h index 7e949f25c933..e3549e50de95 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -13,6 +13,7 @@ =20 #ifndef CONFIG_MMU #define KERNEL_LINK_ADDR PAGE_OFFSET +#define KERN_VIRT_SIZE (UL(-1)) #else =20 #define ADDRESS_SPACE_END (UL(-1)) --=20 2.32.0 From nobody Tue Jun 23 22:34:08 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2BD2C433EF for ; Fri, 25 Feb 2022 12:42:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237299AbiBYMmf (ORCPT ); Fri, 25 Feb 2022 07:42:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230513AbiBYMmc (ORCPT ); Fri, 25 Feb 2022 07:42:32 -0500 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B83216949E for ; Fri, 25 Feb 2022 04:42:00 -0800 (PST) Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id EEFEE3F1B6 for ; Fri, 25 Feb 2022 12:41:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645792918; bh=5wR2inrb50SGryPV3ql5qm7RIRt9i7gNq/sby+Clcps=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FOvyzcUt7DvbL9/Vgde1Q4k4ZUGno96zyoj/3oJR1kJOj8jn1RpTHAInOTot2DEY3 rAmnZVWebB7uEZ2xX0QsRNnw7egvOM+kxs1VpIexclZGnbmGjOD/2A0XlXvg/LtQVX tOFcriMXwbAtesIrhXwi3LoMkSg7yYdfPTIhqE63b7i7z5XExeBMbEkhKKTXYVW/mx FPqGRPrusbYPRvWRx3tP/z0+Ie069tZDV4fBbkDS1T//CwgtKj0x/SlhY+hfgITDKO FRbWo2uo0jqM3UAGyWz6qwirA+sAyGRINivzHE+sTjY1Ii3p2yc0ELfxD7AhfGsCCY T7DKlRGyYyOyQ== Received: by mail-wm1-f72.google.com with SMTP id r206-20020a1c44d7000000b00380e36c6d34so1510302wma.4 for ; Fri, 25 Feb 2022 04:41:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5wR2inrb50SGryPV3ql5qm7RIRt9i7gNq/sby+Clcps=; b=tYJR5+wUKJlfsg3qAym1hWP1ffmwcMrBr5u8lSbhY6vODYhNU2A8B9eoX5XFpBpFab O+gsbqr+gxqpL8lkYIfJAfOT+C/sHvSJYpXDNkwNPB5pw3oV7G2TaFeZySjSGkW8UeVr FyfDFWgAUUlnI+qHEQ5EqFPZ1NvqcJSbpo3WiwmJfO1Da8fnW9wU1hNVqbi03qMV3UBB ebjcVhAFI3lqcupUF0ds+bOPlpYJTaVlbnkP0SXxbwSW87o/VbduGQMUd57PHZSDTRgy 7EJoCX/JJR62qpssIdRcMAA95vHjOxr1eGRaFNoW4JXJmFYRoF3GsWUMR5/tfydpRt1t 8Xvw== X-Gm-Message-State: AOAM531sCTUL/yVsPgZCdD6tcunbf7yIzvD4RyTtOJ2/v4SOrFHXAmQR VWzi6aYErlWzZuwVEn/sT99i9veWlgINNMzp/+vtyvvP3kbG8GsxHtcTnkEitHHeylZIna3ueJG 6dIW42SPcYIvVnRY6al/w4p2TQ+rgsi2lMlujkcP7cw== X-Received: by 2002:adf:80c2:0:b0:1e3:3b9e:ab6d with SMTP id 60-20020adf80c2000000b001e33b9eab6dmr6234414wrl.253.1645792918685; Fri, 25 Feb 2022 04:41:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJx83iJoyNT5BQRvq3mMRYqD931oXS9YXkhhT249/SBb5EDJpj7lWu/6JE6+IOyTRBie/j9F6Q== X-Received: by 2002:adf:80c2:0:b0:1e3:3b9e:ab6d with SMTP id 60-20020adf80c2000000b001e33b9eab6dmr6234407wrl.253.1645792918458; Fri, 25 Feb 2022 04:41:58 -0800 (PST) Received: from localhost.localdomain (lfbn-gre-1-195-1.w90-112.abo.wanadoo.fr. [90.112.158.1]) by smtp.gmail.com with ESMTPSA id p18-20020adfba92000000b001e4ae791663sm2234860wrg.62.2022.02.25.04.41.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Feb 2022 04:41:58 -0800 (PST) From: Alexandre Ghiti To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Alexandre Ghiti , Aleksandr Nogikh , Nick Hu , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com Subject: [PATCH -fixes v3 2/6] riscv: Fix config KASAN && SPARSEMEM && !SPARSE_VMEMMAP Date: Fri, 25 Feb 2022 13:39:49 +0100 Message-Id: <20220225123953.3251327-3-alexandre.ghiti@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220225123953.3251327-1-alexandre.ghiti@canonical.com> References: <20220225123953.3251327-1-alexandre.ghiti@canonical.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In order to get the pfn of a struct page* when sparsemem is enabled without vmemmap, the mem_section structures need to be initialized which happens in sparse_init. But kasan_early_init calls pfn_to_page way before sparse_init is called, which then tries to dereference a null mem_section pointer. Fix this by removing the usage of this function in kasan_early_init. Fixes: 8ad8b72721d0 ("riscv: Add KASAN support") Signed-off-by: Alexandre Ghiti --- arch/riscv/mm/kasan_init.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/riscv/mm/kasan_init.c b/arch/riscv/mm/kasan_init.c index f61f7ca6fe0f..85e849318389 100644 --- a/arch/riscv/mm/kasan_init.c +++ b/arch/riscv/mm/kasan_init.c @@ -202,8 +202,7 @@ asmlinkage void __init kasan_early_init(void) =20 for (i =3D 0; i < PTRS_PER_PTE; ++i) set_pte(kasan_early_shadow_pte + i, - mk_pte(virt_to_page(kasan_early_shadow_page), - PAGE_KERNEL)); + pfn_pte(virt_to_pfn(kasan_early_shadow_page), PAGE_KERNEL)); =20 for (i =3D 0; i < PTRS_PER_PMD; ++i) set_pmd(kasan_early_shadow_pmd + i, --=20 2.32.0 From nobody Tue Jun 23 22:34:08 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4CCD5C433F5 for ; Fri, 25 Feb 2022 12:43:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240666AbiBYMnf (ORCPT ); Fri, 25 Feb 2022 07:43:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239864AbiBYMne (ORCPT ); Fri, 25 Feb 2022 07:43:34 -0500 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F731199D5F for ; Fri, 25 Feb 2022 04:43:02 -0800 (PST) Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 515963F1A1 for ; Fri, 25 Feb 2022 12:43:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645792980; bh=cguSXJTSK/jUGjEgH9bI1vq5RLn1H9fQDOjhSSVs79w=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pM0+kpRWb7dd7Tsz6ltx3TxX3tylo7zrS6pHacHj8ytb2VwP5mPPsCY/p0I+3/z5J 39PHlTTSu50mUO0v9aOJ/lQc+/TPcz7gE4bLQdLEW3oyZqNTw9Nrj1A+EjgRY0a+Pw cfi01C3Bxv57tQsmKwjHhHa3v+zMSD74I+0aB9wtBsNgifhxqwR6X9aypde3GuEMhN 3GxpytXM90YuqhKusGb5eujXEhbWlhS4A8eJ1qG/PmT/Cf22g14XZkqfC7yyMfl0DB qNy9bKeZV36OyyNDclIcVgVPoWk9VD5iWxdmtkTPjEnJPQ0KOHMObLUdAoDNdEdTuQ 1GQxUvOgp6tfA== Received: by mail-wm1-f71.google.com with SMTP id m21-20020a7bcf35000000b00380e364b5d2so1276990wmg.2 for ; Fri, 25 Feb 2022 04:43:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cguSXJTSK/jUGjEgH9bI1vq5RLn1H9fQDOjhSSVs79w=; b=KZqyi+X9vrBztFgEKBuMmr/qaZ4xqCXT7MFC/s0+oF2Vb5asmFpH86rBfV8UltSQc7 Q5cCtHHpbzJNm0p4o4ZTXnyAnhVjXQ+5Zm/Xl6AQSmAfYyqSyCkqQA61vobJNdjIfGWO 0zxuDXPXN1xpPAfciS/DAY+ib9E1M4jl5KLE2j05ZKC+3yZcMpz628jSqt2eNweQe5yu iZm6vMpZ1L9DfcQPAkzkHUceJaqBvW2D5lxFZ1ejBMcOTiYYfZnKsmS5HWid1y7dekzV JUJ6Hi0eshZ/jDlYkMv7xe4qYKTnRNE0S0MZCVJr09CpB8gJc7UgFXBA3U+hmYEmMVw0 zJgw== X-Gm-Message-State: AOAM533mIibBQe+yjnZlB2Flso21NJbf+pHBOv+WbeaR9umM+fHIBEjj z/SkQ7r0pwd24HUyfvkFO+i2GSsXT27ZImB3e3S1xJpiHJaJP4QN2Kn4UWHsgxzTmdjbhOryatT S/CiAyhPMflszQXo/8+smlmmmpU84e8hN999E6lj6tg== X-Received: by 2002:a05:600c:3483:b0:380:edaf:d479 with SMTP id a3-20020a05600c348300b00380edafd479mr2577992wmq.20.1645792979759; Fri, 25 Feb 2022 04:42:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJwcRpOmBxAvnb9C8VWTL3Q+pIs+JnIpbWsXck+OsKjusYuwlpFrwhhbzMfm7RYXdb8ihagxtg== X-Received: by 2002:a05:600c:3483:b0:380:edaf:d479 with SMTP id a3-20020a05600c348300b00380edafd479mr2577978wmq.20.1645792979554; Fri, 25 Feb 2022 04:42:59 -0800 (PST) Received: from localhost.localdomain (lfbn-gre-1-195-1.w90-112.abo.wanadoo.fr. [90.112.158.1]) by smtp.gmail.com with ESMTPSA id g7-20020a5d5407000000b001e2628b6490sm2248342wrv.17.2022.02.25.04.42.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Feb 2022 04:42:59 -0800 (PST) From: Alexandre Ghiti To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Alexandre Ghiti , Aleksandr Nogikh , Nick Hu , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com Subject: [PATCH -fixes v3 3/6] riscv: Fix DEBUG_VIRTUAL false warnings Date: Fri, 25 Feb 2022 13:39:50 +0100 Message-Id: <20220225123953.3251327-4-alexandre.ghiti@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220225123953.3251327-1-alexandre.ghiti@canonical.com> References: <20220225123953.3251327-1-alexandre.ghiti@canonical.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" KERN_VIRT_SIZE used to encompass the kernel mapping before it was redefined when moving the kasan mapping next to the kernel mapping to only match the maximum amount of physical memory. Then, kernel mapping addresses that go through __virt_to_phys are now declared as wrong which is not true, one can use __virt_to_phys on such addresses. Fix this by redefining the condition that matches wrong addresses. Fixes: f7ae02333d13 ("riscv: Move KASAN mapping next to the kernel mapping") Signed-off-by: Alexandre Ghiti --- arch/riscv/mm/physaddr.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/arch/riscv/mm/physaddr.c b/arch/riscv/mm/physaddr.c index e7fd0c253c7b..19cf25a74ee2 100644 --- a/arch/riscv/mm/physaddr.c +++ b/arch/riscv/mm/physaddr.c @@ -8,12 +8,10 @@ =20 phys_addr_t __virt_to_phys(unsigned long x) { - phys_addr_t y =3D x - PAGE_OFFSET; - /* * Boundary checking aginst the kernel linear mapping space. */ - WARN(y >=3D KERN_VIRT_SIZE, + WARN(!is_linear_mapping(x) && !is_kernel_mapping(x), "virt_to_phys used for non-linear address: %pK (%pS)\n", (void *)x, (void *)x); =20 --=20 2.32.0 From nobody Tue Jun 23 22:34:08 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82050C433EF for ; Fri, 25 Feb 2022 12:44:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240687AbiBYMom (ORCPT ); Fri, 25 Feb 2022 07:44:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230124AbiBYMog (ORCPT ); Fri, 25 Feb 2022 07:44:36 -0500 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F25BB1C8847 for ; Fri, 25 Feb 2022 04:44:03 -0800 (PST) Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id B105E3FC9E for ; Fri, 25 Feb 2022 12:44:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645793041; bh=JOP3F1szvziyyHwwb25WbMBDR7/phOdbs80dtO/BlA0=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LLJ6IWhpJ6nKNMqqShVRMVnNn4J9YumQp3stAbxcpEJ0RnmNXnk/rNVg6SGNanG27 +QT7s39/jdtDzDVljmRtn6l+7ScI1VObQ6yN83+YGJhp/PIEtEz28vR8+6mBq5czzS 6dOG8HjyvtgNLWP6Y5xDpw5Xjz/1jX4ZXeIzdCNiAn0GhlR0Qpcdc7atoMaIZDkrYk BOar5vJeuNq/sji1jI+ZTO4IzhHWMWHwYVsLzFwfk1zQb2o8iRHlpsh4UiXzyMXmFz uNr+L3gtxs1U9JmSkCC9Zbu+ln6OrmeCGGIXSYUKVjjrj3z0UIX3xYAhoXZzv2Lqr/ 6B/uD0n8PLXZQ== Received: by mail-wm1-f69.google.com with SMTP id ay7-20020a05600c1e0700b003813d7a7d03so460680wmb.1 for ; Fri, 25 Feb 2022 04:44:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JOP3F1szvziyyHwwb25WbMBDR7/phOdbs80dtO/BlA0=; b=i3F9QY8XTaXnHhL91NmFRilioObzPgaPswmylIssHMozN8d5EH9tcpNLzaxoBRKbA7 zY988/nL6eYzv8TR+rVzfloHswKWWwMu4QQv1w9DHf2Z+eJ7mSJMVWIgBSRz3Rqf27nE 9tK22T1nhQg9eXfMI+PaXdDBQeippp6hJngdvduaoWUuByGeh5h1vmxyhsJxkXLhcKBc sEp/qVk9Ep5rTO7Wk+sSH20ODwbjP/qtWOMOYog4R6WzyahNg3GDt7aXeshJeLssgk5M ZUak44pCtjd5C2QGBiEFqgOZqvRBspqd6MEw35qUjOOqP6kNpSyLFPS+txn2WlQiotF0 iCLQ== X-Gm-Message-State: AOAM531v5/4/W2X2HZyqTO+SpFhdqkA3Ju7mDLsmyXAMOfo/kTJUbQP7 Pi1B6O/kosYW8eG8RcF3LPczFaLoL/6ZBLJAfjHsfIWa0DrJDi0eO2NTAfKgVy1MS9SqSGqh5gl qF7j1Y7K+/HPZfC0pOFU7Ozul8olWzoWuSoHrQIKttQ== X-Received: by 2002:a7b:ce84:0:b0:37c:52fe:a3ff with SMTP id q4-20020a7bce84000000b0037c52fea3ffmr2567642wmj.48.1645793040998; Fri, 25 Feb 2022 04:44:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJztvmWREbdipkwIP+Q6hL7beS4tVObs1D+0g7s/qnUUZuZ6sJgmbN9exqgPVTMCY5OVHLM1OQ== X-Received: by 2002:a7b:ce84:0:b0:37c:52fe:a3ff with SMTP id q4-20020a7bce84000000b0037c52fea3ffmr2567618wmj.48.1645793040749; Fri, 25 Feb 2022 04:44:00 -0800 (PST) Received: from localhost.localdomain (lfbn-gre-1-195-1.w90-112.abo.wanadoo.fr. [90.112.158.1]) by smtp.gmail.com with ESMTPSA id f10-20020a05600c154a00b0037bbbc15ca7sm10658533wmg.36.2022.02.25.04.44.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Feb 2022 04:44:00 -0800 (PST) From: Alexandre Ghiti To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Alexandre Ghiti , Aleksandr Nogikh , Nick Hu , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com Subject: [PATCH -fixes v3 4/6] riscv: Fix config KASAN && DEBUG_VIRTUAL Date: Fri, 25 Feb 2022 13:39:51 +0100 Message-Id: <20220225123953.3251327-5-alexandre.ghiti@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220225123953.3251327-1-alexandre.ghiti@canonical.com> References: <20220225123953.3251327-1-alexandre.ghiti@canonical.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" __virt_to_phys function is called very early in the boot process (ie kasan_early_init) so it should not be instrumented by KASAN otherwise it bugs. Fix this by declaring phys_addr.c as non-kasan instrumentable. Signed-off-by: Alexandre Ghiti --- arch/riscv/mm/Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/riscv/mm/Makefile b/arch/riscv/mm/Makefile index 7ebaef10ea1b..ac7a25298a04 100644 --- a/arch/riscv/mm/Makefile +++ b/arch/riscv/mm/Makefile @@ -24,6 +24,9 @@ obj-$(CONFIG_KASAN) +=3D kasan_init.o ifdef CONFIG_KASAN KASAN_SANITIZE_kasan_init.o :=3D n KASAN_SANITIZE_init.o :=3D n +ifdef CONFIG_DEBUG_VIRTUAL +KASAN_SANITIZE_physaddr.o :=3D n +endif endif =20 obj-$(CONFIG_DEBUG_VIRTUAL) +=3D physaddr.o --=20 2.32.0 From nobody Tue Jun 23 22:34:08 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C21B0C433F5 for ; Fri, 25 Feb 2022 12:45:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240688AbiBYMpi (ORCPT ); Fri, 25 Feb 2022 07:45:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230124AbiBYMpg (ORCPT ); Fri, 25 Feb 2022 07:45:36 -0500 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 633D51C8847 for ; Fri, 25 Feb 2022 04:45:04 -0800 (PST) Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id BCDB840017 for ; Fri, 25 Feb 2022 12:45:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645793102; bh=SnSbt9srZ7OcpfO0TO3d0HjnXYX+4WJ6SgK04DiqgE8=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bcEi+LRiTemlC7Hj63WfwVaBWrkJ6xI0+QDibvP7bLfF+CmKjYWpu0MIIlYHLDZXU zs1bFHorBWqxTimKZlX/U0Va8OvbWkKVF3aeO9i5jQTwi9l1a/QOACSr9rSxqX+Qhx m+GARMgijfuxqQVTVF0YcoVAHVjXC/I/TS8YQIjFx2xvBShUoLmiz6WLLvtyqG79pf Png5lW6KSjhxNRhnlBErHRotSf0uScw9OWAv6qKIaT6HUaKhhYrJtLf7pqBiZoM0Oz viNNFKRvi6DmzuMI2o4N+1r+DH1VfkzJA1EOGlKXMYpm+8uJEmxtso/VmgKjKbbT4J d8BTk+vYhecTg== Received: by mail-wm1-f72.google.com with SMTP id r8-20020a05600c35c800b0038118108e71so1266302wmq.7 for ; Fri, 25 Feb 2022 04:45:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SnSbt9srZ7OcpfO0TO3d0HjnXYX+4WJ6SgK04DiqgE8=; b=aNMnUwpbUuF+xQDgHSFCjXOrZfxAUAfNlakJW+w/8e+Kgo2sm7A5aXBFRbxJORPtjz KMJgBPkIyod686fPFMP308ENkFI/UfMXKPRErr8wvKzEvCviWZKmLZB1AwtN+VW0OLRc kmF1OrQsbSeyqmnqEFtezoF7RcwJPJF94l/ZjXw6KsqYHmgaRh8+vUCfGReKLt4TDhQb Y8f9udNM4C0kZLxg1YC0nSSb0nKNUBlSBvOi/GljU66DQc1lwUCcaAUFbgX5cN5Oa9La DWX/YieQ7vj4qqegZUdc7H1IqZTXZN6umK+57M0s6CY80O/SN5AFNWzN9jnfwCapRIqO CLuQ== X-Gm-Message-State: AOAM533gAdKOFWBpIJT7i57atSnblFLxQH+ypgvKRrC9htsb+o7uGgi2 b8bBFCjqMbioYM77MHxwEWce3A5prw6Xbfg88zPFm0iw2TarbDurbt0/w4CAeoXfYwAKJWUW3RJ JnBoUS7LjMkkKr1GLuu/tTPzE6LUUMzkOVeTKD5DF0g== X-Received: by 2002:a5d:6a41:0:b0:1ed:c1da:6c22 with SMTP id t1-20020a5d6a41000000b001edc1da6c22mr5742732wrw.473.1645793102134; Fri, 25 Feb 2022 04:45:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJwQgKrZu6jaYzaCu1NYJXPtNkDwJhWrhUHTE8uagr23ma/j8UbcytWvj2M2yAnW2lyu4uqPTg== X-Received: by 2002:a5d:6a41:0:b0:1ed:c1da:6c22 with SMTP id t1-20020a5d6a41000000b001edc1da6c22mr5742718wrw.473.1645793101972; Fri, 25 Feb 2022 04:45:01 -0800 (PST) Received: from localhost.localdomain (lfbn-gre-1-195-1.w90-112.abo.wanadoo.fr. [90.112.158.1]) by smtp.gmail.com with ESMTPSA id l13-20020a05600002ad00b001ea78a5df11sm2712125wry.1.2022.02.25.04.45.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Feb 2022 04:45:01 -0800 (PST) From: Alexandre Ghiti To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Alexandre Ghiti , Aleksandr Nogikh , Nick Hu , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com Subject: [PATCH -fixes v3 5/6] riscv: Move high_memory initialization to setup_bootmem Date: Fri, 25 Feb 2022 13:39:52 +0100 Message-Id: <20220225123953.3251327-6-alexandre.ghiti@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220225123953.3251327-1-alexandre.ghiti@canonical.com> References: <20220225123953.3251327-1-alexandre.ghiti@canonical.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" high_memory used to be initialized in mem_init, way after setup_bootmem. But a call to dma_contiguous_reserve in this function gives rise to the below warning because high_memory is equal to 0 and is used at the very beginning at cma_declare_contiguous_nid. It went unnoticed since the move of the kasan region redefined KERN_VIRT_SIZE so that it does not encompass -1 anymore. Fix this by initializing high_memory in setup_bootmem. ------------[ cut here ]------------ virt_to_phys used for non-linear address: ffffffffffffffff (0xfffffffffffff= fff) WARNING: CPU: 0 PID: 0 at arch/riscv/mm/physaddr.c:14 __virt_to_phys+0xac/0= x1b8 Modules linked in: CPU: 0 PID: 0 Comm: swapper Not tainted 5.17.0-rc1-00007-ga68b89289e26 #27 Hardware name: riscv-virtio,qemu (DT) epc : __virt_to_phys+0xac/0x1b8 ra : __virt_to_phys+0xac/0x1b8 epc : ffffffff80014922 ra : ffffffff80014922 sp : ffffffff84a03c30 gp : ffffffff85866c80 tp : ffffffff84a3f180 t0 : ffffffff86bce657 t1 : fffffffef09406e8 t2 : 0000000000000000 s0 : ffffffff84a03c70 s1 : ffffffffffffffff a0 : 000000000000004f a1 : 00000000000f0000 a2 : 0000000000000002 a3 : ffffffff8011f408 a4 : 0000000000000000 a5 : 0000000000000000 a6 : 0000000000f00000 a7 : ffffffff84a03747 s2 : ffffffd800000000 s3 : ffffffff86ef4000 s4 : ffffffff8467f828 s5 : fffffff800000000 s6 : 8000000000006800 s7 : 0000000000000000 s8 : 0000000480000000 s9 : 0000000080038ea0 s10: 0000000000000000 s11: ffffffffffffffff t3 : ffffffff84a035c0 t4 : fffffffef09406e8 t5 : fffffffef09406e9 t6 : ffffffff84a03758 status: 0000000000000100 badaddr: 0000000000000000 cause: 0000000000000003 [] cma_declare_contiguous_nid+0xf2/0x64a [] dma_contiguous_reserve_area+0x46/0xb4 [] dma_contiguous_reserve+0x174/0x18e [] paging_init+0x12c/0x35e [] setup_arch+0x120/0x74e [] start_kernel+0xce/0x68c irq event stamp: 0 hardirqs last enabled at (0): [<0000000000000000>] 0x0 hardirqs last disabled at (0): [<0000000000000000>] 0x0 softirqs last enabled at (0): [<0000000000000000>] 0x0 softirqs last disabled at (0): [<0000000000000000>] 0x0 ---[ end trace 0000000000000000 ]--- Fixes: f7ae02333d13 ("riscv: Move KASAN mapping next to the kernel mapping") Signed-off-by: Alexandre Ghiti --- arch/riscv/mm/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index c27294128e18..0d588032d6e6 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -125,7 +125,6 @@ void __init mem_init(void) else swiotlb_force =3D SWIOTLB_NO_FORCE; #endif - high_memory =3D (void *)(__va(PFN_PHYS(max_low_pfn))); memblock_free_all(); =20 print_vm_layout(); @@ -195,6 +194,7 @@ static void __init setup_bootmem(void) =20 min_low_pfn =3D PFN_UP(phys_ram_base); max_low_pfn =3D max_pfn =3D PFN_DOWN(phys_ram_end); + high_memory =3D (void *)(__va(PFN_PHYS(max_low_pfn))); =20 dma32_phys_limit =3D min(4UL * SZ_1G, (unsigned long)PFN_PHYS(max_low_pfn= )); set_max_mapnr(max_low_pfn - ARCH_PFN_OFFSET); --=20 2.32.0 From nobody Tue Jun 23 22:34:08 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7057CC433EF for ; Fri, 25 Feb 2022 12:46:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240703AbiBYMqi (ORCPT ); Fri, 25 Feb 2022 07:46:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230124AbiBYMqg (ORCPT ); Fri, 25 Feb 2022 07:46:36 -0500 Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C24A421CD12 for ; Fri, 25 Feb 2022 04:46:04 -0800 (PST) Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id A602C3F1C9 for ; Fri, 25 Feb 2022 12:46:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645793163; bh=IZZDTFAqzc8aGjWg1aZGEvUIk/RV0NTNXI1qwgw2jtM=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NbuplYwpZDA6vimglNGnb8sl8yD7+jhJ2oi2Ti0IUGF2J8G0s9m/GZ+8jhnFutli7 5Y/Ldq7Ixg47hG+FvmiBCry+Tp5sr26yKf4JRpOvFLrfi8/Lpl9dPIzsgq7lpu8Ozj KLe95HHy8+5oGLpMPcRsrSHu4fIr55Z47JvXsBPcnoUcgLNgqrigfjUQFk/tV88G7r t6vujrku7IlIqFQ/9Y6We8xM4uT8TJuQLRIOjs/R9lE0l4xg2bsUBtlv/FmKcYAHkU qiK3MXgm0a3NJakRdxbIAWeelxK8C3XhS53DBYDYoiePomfoUPJ6G03o+FWa3R4oA+ 0dx1/xoQYLzEw== Received: by mail-wm1-f69.google.com with SMTP id w3-20020a7bc743000000b0037c5168b3c4so1510781wmk.7 for ; Fri, 25 Feb 2022 04:46:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IZZDTFAqzc8aGjWg1aZGEvUIk/RV0NTNXI1qwgw2jtM=; b=5MFNklMRl4lPD1dBHw6iQRs6qpAfetCZZFL9EAFzXMsrN9fHIIUh1TnbEypkD6jVQW dtxokPL0gVgyMdqZP9CSj3bEByw5k6aC5aRUXHWXR5hAZDTTAPNn/jT9B5A8vi+oynwE 0RVNSzt3xYiCTiD92fAkuanttp0qONjLVPSU4tVubtUgHsJ1HXtJdCf5vRAWmHiBewHV ElRXMHHVjkPxl39lGdTh3VClILARJBNhY+k/RKPjIpf8xynKSsHvFe6liWMNDV73RMwF WzuXn9BhCdHo7M43okBU7vjCfAuavyIJ68LooQBmLoYihd66mponshpe5LhrGmuGM+Lm 42Qw== X-Gm-Message-State: AOAM531QnMq/ZcoBPoFYjqTrF+kB+M7wvz1Hon5AOe+Tzl/iRGRcW3qk lEsi0339dlKXI+ZK3vgjn+FySuKqCl6veRCc2N89zHMIS00MUoxJsBUTg07yD6k+X1/tP11LR5b DUKdPeYjpuHx90XYq1tb8h2/aRzZ38LbZ00LlCmYpZA== X-Received: by 2002:a5d:59af:0:b0:1e4:a027:ce3b with SMTP id p15-20020a5d59af000000b001e4a027ce3bmr5811393wrr.318.1645793163256; Fri, 25 Feb 2022 04:46:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJxO7k/BdZpfrSelXcnhXik1Fk/jhx3wZbS/FHtdA4vPeJI99+BzxjzzIqpykVUwH5wXXBm4Wg== X-Received: by 2002:a5d:59af:0:b0:1e4:a027:ce3b with SMTP id p15-20020a5d59af000000b001e4a027ce3bmr5811384wrr.318.1645793163068; Fri, 25 Feb 2022 04:46:03 -0800 (PST) Received: from localhost.localdomain (lfbn-gre-1-195-1.w90-112.abo.wanadoo.fr. [90.112.158.1]) by smtp.gmail.com with ESMTPSA id e33-20020a05600c4ba100b003810c690ba2sm4741109wmp.3.2022.02.25.04.46.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Feb 2022 04:46:02 -0800 (PST) From: Alexandre Ghiti To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Alexandre Ghiti , Aleksandr Nogikh , Nick Hu , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com Subject: [PATCH -fixes v3 6/6] riscv: Fix kasan pud population Date: Fri, 25 Feb 2022 13:39:53 +0100 Message-Id: <20220225123953.3251327-7-alexandre.ghiti@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220225123953.3251327-1-alexandre.ghiti@canonical.com> References: <20220225123953.3251327-1-alexandre.ghiti@canonical.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In sv48, the kasan inner regions are not aligned on PGDIR_SIZE and then when we populate the kasan linear mapping region, we clear the kasan vmalloc region which is in the same PGD. Fix this by copying the content of the kasan early pud after allocating a new PGD for the first time. Fixes: e8a62cc26ddf ("riscv: Implement sv48 support") Signed-off-by: Alexandre Ghiti --- arch/riscv/mm/kasan_init.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/riscv/mm/kasan_init.c b/arch/riscv/mm/kasan_init.c index 85e849318389..cd1a145257b7 100644 --- a/arch/riscv/mm/kasan_init.c +++ b/arch/riscv/mm/kasan_init.c @@ -113,8 +113,11 @@ static void __init kasan_populate_pud(pgd_t *pgd, base_pud =3D pt_ops.get_pud_virt(pfn_to_phys(_pgd_pfn(*pgd))); } else { base_pud =3D (pud_t *)pgd_page_vaddr(*pgd); - if (base_pud =3D=3D lm_alias(kasan_early_shadow_pud)) + if (base_pud =3D=3D lm_alias(kasan_early_shadow_pud)) { base_pud =3D memblock_alloc(PTRS_PER_PUD * sizeof(pud_t), PAGE_SIZE); + memcpy(base_pud, (void *)kasan_early_shadow_pud, + sizeof(pud_t) * PTRS_PER_PUD); + } } =20 pudp =3D base_pud + pud_index(vaddr); --=20 2.32.0