From patchwork Fri Feb 25 12:39:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 12760189 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 C471DC433EF for ; Fri, 25 Feb 2022 12:41:12 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=x5LobbI8Y86Io1L31MZ7LAnwTTe1SkuHeTzjPO1QQiM=; b=3EVvfwPXMU2RH7 tFMP/PPNK9t9uGzJfHgINmuXfrey07BBClym22VGLJX2fimErxXyWKwgRm8msq37eifxzhx+QPtpE DQLlZdmx/z61Bxuxr2UWH7q9VTYz/oE8HSExC3jRWT6f3pX4cIY8sFKuiiC5BVSvwWF1v2zVSHR+I JCPHGsUi/0btvWYqiJsl8FC9ldHRH14qmkNRFYSqDeTNctu/oIdAtH4tJxIhT/pb320BtUIF1fH0L cyaSLf1bPZ8cByJo5arUXhccbMl/WoDm+xPb2ebZhhgyWFo58Amv3B29EYuLkaIRDISn3bBjYrtgl kN/DQK6EpEG0ocUVj3cw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNZu9-004scR-ST; Fri, 25 Feb 2022 12:41:01 +0000 Received: from smtp-relay-internal-0.canonical.com ([185.125.188.122]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNZu7-004sbo-4D for linux-riscv@lists.infradead.org; Fri, 25 Feb 2022 12:41:00 +0000 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 D38243F1B6 for ; Fri, 25 Feb 2022 12:40:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645792857; bh=PQyFtNV3tW1qRmwZ8HqaxvUDcyO7BHPqZZLC0geQ1k0=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BMrC50W2SGWjb2OEkCsBv31eAbccM4CKDnxGu5PeMdcvtT8jRgwjM0T0rjhLM7X/z P/w4xFyonwNZxJxPYbbkAGwl9XF3Fq9pv7XJoKRVuQl4JHMk+CP4LGbEKIuMHwdANJ loCFWY2Ynbld/B2Xs/0SDFxX2ZhOugwe4Ak/KT7MICClkrop9winal2Lz3dDGebDYT jN9qphsDKXzurubHsOj5ksvVtgjAlihMCOt6qlZ+0c3//jq/LRkZw6w3E5HT36b7wh W2rCdS9Y9Sz4+PJq3qbzQNizIr9kKoK8aeoCdzB/dhYABwfkPLI8ndA5XIJ/foQ4/2 QnEei6NIdj8mw== Received: by mail-wm1-f69.google.com with SMTP id q17-20020a1ca711000000b0037be98d03a1so1537766wme.0 for ; Fri, 25 Feb 2022 04:40:57 -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=tqSiU2iPVTaIe2ccpz+JYjQHf4akpfD2tFVUWMNGocsUikg2O1Ler8mrSwUMJd/pwz cK5PqBshK52/YtAbnv6jaiR7NKpAKaMOR/0iG1C6oNLPaekPwdnmuih8i2ym4fQD3KEv veZzQ3TATnJItGST14KQHYec0nzsxC4Y/dx6ev/ZC+IaP8aTcxfooICSnfamp+u8xqYY lzO5M3DKJve3LU+nJCoQ4D6QoncxKBA5FaDRdOASEudzGvICWhW95YoPQ/tnrwMSh8oc 1JGRq0wIQCLzkN2a3R2h8UzYgWTk8f9B7l7D0VuYChJVvWVo7iDdOTlFwalp0Gu1N1AA 0Q3A== X-Gm-Message-State: AOAM533ROH2yqW5Fapcte+KvKJk9Gp1C7KQR95et6xjPBC4be1nBtTBp wlESSEkrpny+xND2gKXEP2ddN7S9UMNUGXflH7sdZE+uNrE0Hs4yHFgaToX/S6M40JEokTXyCR1 V/Re7MLcE3nBWWZ9VRq4W/aHocW6YAT16vLBvY36udmL6XA== X-Received: by 2002:adf:a54c:0:b0:1ed:ab82:d5c with SMTP id j12-20020adfa54c000000b001edab820d5cmr5903431wrb.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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220225_044059_317390_9888EE2C X-CRM114-Status: GOOD ( 14.10 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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) >= kernel_map.virt_addr && (x) < (kernel_map.virt_addr + kernel_map.size)) #define is_linear_mapping(x) \ - ((x) >= PAGE_OFFSET && (!IS_ENABLED(CONFIG_64BIT) || (x) < kernel_map.virt_addr)) + ((x) >= PAGE_OFFSET && (!IS_ENABLED(CONFIG_64BIT) || (x) < PAGE_OFFSET + KERN_VIRT_SIZE)) #define linear_mapping_pa_to_va(x) ((void *)((unsigned long)(x) + kernel_map.va_pa_offset)) #define kernel_mapping_pa_to_va(y) ({ \ diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index 7e949f25c933..e3549e50de95 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -13,6 +13,7 @@ #ifndef CONFIG_MMU #define KERNEL_LINK_ADDR PAGE_OFFSET +#define KERN_VIRT_SIZE (UL(-1)) #else #define ADDRESS_SPACE_END (UL(-1)) From patchwork Fri Feb 25 12:39:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 12760190 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 E304DC433F5 for ; Fri, 25 Feb 2022 12:42:12 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=fe02P35DbdCPUn9REHwiAthHOefUmjz9ur3EW1RZq/Q=; b=XNV1Ad3JXs0kdP vk6UpS21Lao+OuIISqnrNGEUK6d2pIzfzDNccb3AShyTLcnBmwy9pkt8RIyeKYnKzpBCmeQy3Q21W /7gIU2V8oOmkBGKg/k48fg7CBFBBtbnU+DUIsYgERHGhRqnW92hohPY1AfKsNso44vznG4nYKsVaZ WE+hZCE74voAWAHAplotFz9VH7vMEqAVmgyMgbVyviO3squbAF9hwyftcJLztMRq7RjS9yx4xTvhE bBUHMpP2h9Z9ovVcFhkChplzBmy/FyJQC1UBf3CPtgBdKjQ8bfkuQTcynDhF24LeFHtPtdXju8nMQ nufgU161jjMEJQ9Cwqcw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNZvA-004stN-MV; Fri, 25 Feb 2022 12:42:04 +0000 Received: from smtp-relay-internal-1.canonical.com ([185.125.188.123]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNZv7-004srQ-Qb for linux-riscv@lists.infradead.org; Fri, 25 Feb 2022 12:42:03 +0000 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (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 218023FCA4 for ; Fri, 25 Feb 2022 12:42:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645792920; bh=5wR2inrb50SGryPV3ql5qm7RIRt9i7gNq/sby+Clcps=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ohKOTkf/fqpEZpKXnJlcNghWHkOJjmBhKZXyfhI8d9UXhu//q0aej3SkQM6rjyfqg huLXTRqdxtFwmeskYx+o5yA0GgwHVtT3NfUGNbvYKv8y3II35xZxVZ8JGm8l4FQ2Au osQQkfnFc3+o460C3YN80y2//11ZGmZ74I/Q67yZri+KJ9rbZESQrQFkibpRmTT61p IN1UkkCLVEcSWEnNH9xD7HT8YvqNRYHAjbmdwWcDQwCQYITLKv2+3XxYFiVY+CRFdB ZZtvKkusKlaqGUnNQtugbKg2BjQyrmAK4JfZcxQxLUvhzLhdK1MRgObd0LimWfl+7b 9BA/AcFqztAJA== Received: by mail-wm1-f70.google.com with SMTP id m21-20020a7bcf35000000b00380e364b5d2so1276029wmg.2 for ; Fri, 25 Feb 2022 04:42: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=5wR2inrb50SGryPV3ql5qm7RIRt9i7gNq/sby+Clcps=; b=v6oHtQV/CoZ9KdUIhLVIs1C2jN2jNvYLhS3lNGiW5CMguHWLDf9lT+VdP4zdekjO2p H+tFXIUbS3Mhjhg4l8JTbuJU9h3CkRBgeRd4Bhp7vV6AuY8YAfHfzpbcNSx6iHGqSqmL RGBjb6IhooqwTR2cErvsZwcgZHo+r2yt1+7YNFt3brvVqneGapb45Eq0C90LdoBDCweo 15IQyaZ8X2TcPeNF+Zkg/a3MjymRdiYnfn6pNfNzolqAoUV+MVawVlYpNKoj/KdnLu07 n2C8EMeM9EiXyRLoD+08/EdVrjTimeoctcknYaL/YsgEzonTdEvcQ2u9oZZS+GIJFmUZ vwqg== X-Gm-Message-State: AOAM532DlNZMg26ViJliKkgac8gRf96/y60DXyyse0oP10uXLBcRMIiO /4FaSymGl2m9Z2Q0UqKzc+xYbwxSAl1dxF3TM7Hs/EXSYUfYukZRE1nkUp26rpB7E49MdZ/ez8H WC0KEzn9aYWPvfBWfM62uzl+ELbr4r3BpOT/pVTxpq59+Ug== X-Received: by 2002:adf:80c2:0:b0:1e3:3b9e:ab6d with SMTP id 60-20020adf80c2000000b001e33b9eab6dmr6234423wrl.253.1645792918687; 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220225_044202_011810_23110485 X-CRM114-Status: GOOD ( 12.37 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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) for (i = 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)); for (i = 0; i < PTRS_PER_PMD; ++i) set_pmd(kasan_early_shadow_pmd + i, From patchwork Fri Feb 25 12:39:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 12760191 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 AB8C5C433EF for ; Fri, 25 Feb 2022 12:43:12 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=/bqt88Ln4R5ptMQHD6woiwuMRThs+qc5EzrhD/6HuoA=; b=vazlvBlREMc1DG nwI+yPDQARKiDioCvLqMhxvw4/K5ABeCG99o6hzvGg6QsSyNLdTcKlQ6/S3Zu1jl8c2eqBMjjueY5 Xqr/Eej9PGmrodIyjE0lWXITTvxu2yVA5YGHi10it8JWCNiVv/OQ14qvW5aqgZU3t91DQkCXyO8Mn PeItusWqSV58cTDH8SHP4iC1lrEYpOG2IHFu0YAXoH+54NwdemhZlwmKP720c3WGHUS6EsblxEzIF IiMBuxcHDkqlK1aeVGr/Pcyv2q9FrpOuV/pk+9XzoFCv3/VkGFlZ2ztH6ItlJgmLB7H7BW+SzrJTH DRrIP0QY64DRKE4Qddpw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNZw9-004tJb-1B; Fri, 25 Feb 2022 12:43:05 +0000 Received: from smtp-relay-internal-1.canonical.com ([185.125.188.123]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNZw5-004tHp-9H for linux-riscv@lists.infradead.org; Fri, 25 Feb 2022 12:43:03 +0000 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 12B073F1D9 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-f69.google.com with SMTP id n31-20020a05600c3b9f00b003812242973aso1270414wms.4 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=AZKUP/6f6hT4aMN3KLjP6Xg5diuqhvUNNKS3A0jFcgUjLpn5VJyh6Q/zxNBdlyti7t UqRliawaI88eGKlYHAunGh8TdTFjNzCUd+kGKjX0Qb+bVmktnpLV/LBOELEhplzCyAAh Uv7VR6lr9R76X4WCl5IoTKjfx3J4+1Sg7m+gWl1FncwJ3vxZMvozJMS8Xz7tzEc0n1NZ sZdctVHHWmrCLTo0aHYfIAAwBOGHNjWotCjHrW1tN5/5y1WiXwWIPE4JeYrEjIkOceln 6FzGJRIFavWhyKrqAuIzbTKqg2qJQx7H2y9SoqZCxAOWHJ5ug/2fUWdpYg5WCFUaj0Dn R3Lw== X-Gm-Message-State: AOAM532jikE0M06YPYiGa/Jvrc8wGmatLMohMyNkNjJU+virTT1ebdnB AibM+kOYcPhDCe9Lhpx4RDsRMo7Qs5JGAujMwos1eb+yKNM6hXh0UFmV273u8ThEmMzykcyLB9m +JvG7NgBWUcx+jjjwRBIQ9iCIi9H3nCpE+bnzlAoN6ZeXug== X-Received: by 2002:a05:600c:3483:b0:380:edaf:d479 with SMTP id a3-20020a05600c348300b00380edafd479mr2577991wmq.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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220225_044301_482349_7C9A1FCF X-CRM114-Status: GOOD ( 12.29 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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 @@ phys_addr_t __virt_to_phys(unsigned long x) { - phys_addr_t y = x - PAGE_OFFSET; - /* * Boundary checking aginst the kernel linear mapping space. */ - WARN(y >= 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); From patchwork Fri Feb 25 12:39:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 12760194 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 5A751C433F5 for ; Fri, 25 Feb 2022 12:44:16 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Xmx4stEWuV26jwOmn6KERmmk9N+5X6UxaRqStAS3XB8=; b=tjodFkfdgUPj+6 Y4a0co5bbeBsTK6TrV+68UQD3qT3dMvn0AMJ5/R8Xs/bIRSw232k855Yl1SxfssMvJ+hEYcI1v6Rk mWdjJ380o9KCGaOqMCb45Y9S0NLFGL1LgZTKxUbIOjDfHI1s4/7gSNEdZciwAbfJ0fcyaP7NNH38q radBgL5JqTBngn7itg/Dahs7skJiMU7G1GtG4mZDpQQtT3M+U1p1O+15yoRNn09wDa5Rm9V4glbpV VXx2TbZ5/89zKBcY/PHYssv+D+u6nIw/1nU/R19oITQ0WQKJg1vP/jaNHfBwR6A19Zusq5FXC529s ZuJlIFgqUir6mAwKU0Bg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNZxA-004tdR-IL; Fri, 25 Feb 2022 12:44:08 +0000 Received: from smtp-relay-internal-1.canonical.com ([185.125.188.123]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNZx6-004tbX-1P for linux-riscv@lists.infradead.org; Fri, 25 Feb 2022 12:44:06 +0000 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-1.canonical.com (Postfix) with ESMTPS id 403753F1DD 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-f71.google.com with SMTP id h206-20020a1c21d7000000b003552c13626cso1520314wmh.3 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=BXMoLPKFj4wOOggBVw09R1i1WPbTbtLih9LngYR2BJHtWprwGgo8qKlPPesnsf+W09 Y24D3J7EIq+vaECuUH9WHLvsrlojftvtzG/ZMT7MnxaTXqyAXozqtJZ8UQ9PHYRIXe9V GETFmixpTuULWazQuBEYD/D0ocEU2A0Ggz6yQujbBhZEKimv+P8YrvgTcKB9DE7JB1kv asHmU78x/c0YvcjkVvyQwkL1evApaSJL8KHbXbmgijEzV4aOZ99AD/6ejUuWN5iafNo/ Z76PUQrFdr9qjCC3KQUstpIoD4j1lNvGgxtVvmPD8pU/H16pDaE9Wy1RatRDDweNWqGP VFxg== X-Gm-Message-State: AOAM531KrYKgbW74qoG4EV6cepsKF6PY9GtGuXh4EQ06BGwtnNxTnT6D x+MUV+J2gJzs7Xft+QxQvDadvyAmq66ViK3c2B4sc0vgZn6JXMLNBt7YrVJrAHSBy26MDjy9bdw SoRRy1PEdD+NgM+RBcsaS3xcTmn3EDa6Qmz5eDDWVbKx6Xw== X-Received: by 2002:a7b:ce84:0:b0:37c:52fe:a3ff with SMTP id q4-20020a7bce84000000b0037c52fea3ffmr2567629wmj.48.1645793040960; 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220225_044404_232978_08527949 X-CRM114-Status: UNSURE ( 9.90 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org __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) += kasan_init.o ifdef CONFIG_KASAN KASAN_SANITIZE_kasan_init.o := n KASAN_SANITIZE_init.o := n +ifdef CONFIG_DEBUG_VIRTUAL +KASAN_SANITIZE_physaddr.o := n +endif endif obj-$(CONFIG_DEBUG_VIRTUAL) += physaddr.o From patchwork Fri Feb 25 12:39:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 12760195 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 8630FC433EF for ; Fri, 25 Feb 2022 12:45:16 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=RkiQOU+3bKTjw/+XkgRSVpwIrr6deyAN3d8Q4fNAF/o=; b=zmVbYgYTYW6ZG8 Asx8UEmX0d5knvrjx76Zsb3+V2Qs3WL7tchG7rF7Ad2mC/lm+0dCKZjXNIaiJm5k7kD357pLtwcBm YxJCukCaVgSI9QVnIAxxjsxn3qB4k4QXlerIhKHRCTxd5z/x9NWqYhP4unklpyLvkW9oTvnVr9/z2 xKzbLSx/WqWQOVkhVdpIvUAof1rG+2uTYkyNrrSLLWNMm1sFk1ia+HLZlGM5soazCFoFjgr8FmlyK 6rbM9mrPibnDU8xfxj1cI2rZ2xyg1tw76uJnzK9XAFw1kTllUu8nT8VwQG6Xid0XO4DLbYXYWpgq8 Ik1hSJ+iDWzG9gWyxWww==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNZy7-004trN-Qf; Fri, 25 Feb 2022 12:45:07 +0000 Received: from smtp-relay-internal-0.canonical.com ([185.125.188.122]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNZy4-004tqP-EN for linux-riscv@lists.infradead.org; Fri, 25 Feb 2022 12:45:05 +0000 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.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 7B1283FE4B 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-wr1-f69.google.com with SMTP id u9-20020adfae49000000b001e89793bcb0so850292wrd.17 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=FwsDyOCA6BLoOj5d5RSkmN6Li/aqahYBJkeFdjE6PCn0UhXSApdS85WrdY+9If0gsq qiD5yXW0VDemqbgvSpqZC//XSsYb46gG09JtXqDB4gPu4IbrM30dzFYhciKbYQd7BLfw iKiNuMcP1SQR0q7G1NRIP5YC/YEYazDIZTVtvjKMiPLoFOb6w3+Hf9x8uef8BMx0kbnL LFwV3wEPhiQ9tCfSNeT33rZkp4LfdXBOXGcYZ51WlydArd+mZETazg1UN8Q2KAO/j3H/ phP43uFxGWLaAsI+nRQNMY7oiQ3WKDe0d77iet8gNloKKw5bF0dG7bRdmtKpuuQ+xB8r Lw6Q== X-Gm-Message-State: AOAM532oPovmrwsl6MowrNNr8pEBLKSTALmhd9ZNW49Z61Te8b0i7dM9 749Psc1HzuSp4z/5U7KTdCVa0e+Czz4IauplWUR6TaGb9aRLmvaWIWB54oRoC6YTO5nE/amdA4c tIK6pUm+9riI0dsB1UGTMvh03olhpZGIJ5Q9xvE2Mlltjfw== X-Received: by 2002:a5d:6a41:0:b0:1ed:c1da:6c22 with SMTP id t1-20020a5d6a41000000b001edc1da6c22mr5742735wrw.473.1645793102135; 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220225_044504_648618_02843F15 X-CRM114-Status: GOOD ( 15.34 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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 (0xffffffffffffffff) WARNING: CPU: 0 PID: 0 at arch/riscv/mm/physaddr.c:14 __virt_to_phys+0xac/0x1b8 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 = SWIOTLB_NO_FORCE; #endif - high_memory = (void *)(__va(PFN_PHYS(max_low_pfn))); memblock_free_all(); print_vm_layout(); @@ -195,6 +194,7 @@ static void __init setup_bootmem(void) min_low_pfn = PFN_UP(phys_ram_base); max_low_pfn = max_pfn = PFN_DOWN(phys_ram_end); + high_memory = (void *)(__va(PFN_PHYS(max_low_pfn))); dma32_phys_limit = min(4UL * SZ_1G, (unsigned long)PFN_PHYS(max_low_pfn)); set_max_mapnr(max_low_pfn - ARCH_PFN_OFFSET); From patchwork Fri Feb 25 12:39:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 12760196 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 E02FFC433FE for ; Fri, 25 Feb 2022 12:46:15 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Uxf1ZSgp966f63QNA7QgQtTKAIjaKeVgUVB0EIyg1cU=; b=VQrWsaf4fvALYU Srb8X61BTpEnmKFx1hMNg5O2Xnud/zUWBMYJ777eQMdUl+dR5+oAjcaCI4ivtR/6aq0a993Qe3a5U lsyTh+Z3dRJxB5U3wSeIHkQ8fFmaK8ZQH/rjG4Xaxo7hSDZ7j4o+P6EEjs5QJJggOg1KWb+iozYuI mbb+X3XuWlFO3URxZkJr9yXhDo8fc1RNhb5tfpv/5IkSGsfGPnJr4MnwGpyI5KnS451XoOlOVEDOV ryhqe161njSrcx580OkdkmSy1owrTBeKSpQMZalhM5gIMljqWdJYCbT6wNv2sxBCeTQGAs717YiR3 OdXCLG54jSuUWpxYey9g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNZz5-004u5b-7V; Fri, 25 Feb 2022 12:46:07 +0000 Received: from smtp-relay-internal-1.canonical.com ([185.125.188.123]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNZz3-004u4w-67 for linux-riscv@lists.infradead.org; Fri, 25 Feb 2022 12:46:06 +0000 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 016D93FCAC for ; Fri, 25 Feb 2022 12:46:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645793164; bh=IZZDTFAqzc8aGjWg1aZGEvUIk/RV0NTNXI1qwgw2jtM=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=arCbRdYZk5seUtqfpFHMcTWaLOyKd5+OpIelhJFWZJY87neb4lBCZw9T8kSVKZsY9 e/AniF1Uv/fIuSPX6esv+MhDG9Y5lzpfwAAswU0acqt5J7Jmt08OOiwJ3ROtEtcRBO rZerSAoFM/Fcp526nk1oh5piNIder39elup/LfbXJUukWd8gOYxw+gvzjIf5F4L9ko nRqGl2XG7oK0TxA5Ko5M5b0TBVyEquDkLf5T98e5ayyexgzWOA2RHvVHhvoLzYP1PZ g+TCdCXMj0zYeWMK1Gb1saO7SdLZ9JUkvM1MY2i/Y0cvq+B0agYEeGnMdfUTjkF6Fa y24RMBd4kydKA== Received: by mail-wm1-f69.google.com with SMTP id 10-20020a1c020a000000b0037fae68fcc2so1511678wmc.8 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=l0RxGpczg0kORCQmUIP9Z7eB7pBZBfy+JIKlpc9P5jNtJhe2XmG3WN/Op0bmRfHo+N 178KPUQw4xmEKfBRxd/XLXNXQGLfnYRg0tmOY376aap6wE52kDLA37Iw4CiCHpE4InFp u08rlLe8MOFQzpHRicIzZZ+ps1fgnLfrMqAm5KyKSMjIspQTXcAxnPkgPxZLUi05UNHG aiXz38sw2BlrYSd7OynEOeIL1k1MCbeKxgDEWPP/8ClLbzMr/EpYNrbaoVihjfifZYq/ EpaOCvxa58O2C/eWDPIbqxHWs5ZhxIzlEjOji8gSMJHTY1oYDlcwLgZ09M20Tm3q5jK9 Y+pA== X-Gm-Message-State: AOAM533ZhD1uZi4dzmiQ03Z4XyGonLkvUb3TWM9IDnIiGjkfcBXunonO qjr80NwM3UcurVaMJpz1GJY6jxhgCZpHNyouPGUhVhcfjGAFf9LQeDUTZqhDQP52CdZo48HnSPl CM/+XBTjzfcZpHz2QDrRriQNLywcC4wb+09SCNAhtA3qA7g== X-Received: by 2002:a5d:59af:0:b0:1e4:a027:ce3b with SMTP id p15-20020a5d59af000000b001e4a027ce3bmr5811399wrr.318.1645793163265; 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220225_044605_446261_B3D2974A X-CRM114-Status: GOOD ( 13.90 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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 = pt_ops.get_pud_virt(pfn_to_phys(_pgd_pfn(*pgd))); } else { base_pud = (pud_t *)pgd_page_vaddr(*pgd); - if (base_pud == lm_alias(kasan_early_shadow_pud)) + if (base_pud == lm_alias(kasan_early_shadow_pud)) { base_pud = memblock_alloc(PTRS_PER_PUD * sizeof(pud_t), PAGE_SIZE); + memcpy(base_pud, (void *)kasan_early_shadow_pud, + sizeof(pud_t) * PTRS_PER_PUD); + } } pudp = base_pud + pud_index(vaddr);