From patchwork Mon Feb 21 16:12:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 12753877 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 6B8A2C433F5 for ; Mon, 21 Feb 2022 16:14:27 +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=yVwLNHvcWk4kR9 BYeDJL0ISd/tTnepl6QdWNozz9mxc22zNRYREr5gDOQki4bi/SF++rtRLWs546KdjmwFi7LNFWKZj 3iYQ5HgQWgvB//YcHM6fKs/Q4CiBPIIeZpCDSDc7OAkCHoB8cF4sxG2TyOkk/aFw9Gfq9t0TylOyt Ktg2lxtt6ESaFVGn2Z1xHcK7BkcJ3qBTQ41VAmSAuWtu6QmRj94f9YFof7ZpsHnLuz9QdlGL3E1AK 2+snwGItyuEc1SzXMS/+qVBNhIKQNsbEdZ7CroVUC31K+IjXKmC62xKs19f6UvGae8DL5fGFCUG5S VJh4hnakqw52moYh8i3g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nMBKM-006cPQ-Qu; Mon, 21 Feb 2022 16:14:18 +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 1nMBKI-006cK1-8j for linux-riscv@lists.infradead.org; Mon, 21 Feb 2022 16:14:17 +0000 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.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 A0AE14025B for ; Mon, 21 Feb 2022 16:14:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645460048; bh=PQyFtNV3tW1qRmwZ8HqaxvUDcyO7BHPqZZLC0geQ1k0=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Pw8zIvxw8A6Tu9811T0MQ/EKgt2aY0nsNu+pz29KErjTymjyH3xZuOREbWsZtGj1L BU/x6aRF6Sd0KxpS3NfSmIrth+ezrzOwZM3cgPUWzNy4iDv5A9x5dKybHFt7bsMXLm NG83fDsWrbvFDtL8hjVAadebzmnvKtR7LIx79MWea08Y68hZuaQYOjp0NfVuXjmUyC fqQeJHJbJc9f8MEOW5Kld+Q244pFQLqTRKYpAq9j836uf3g9JvAazwI+gKyD1ndmnx JoNM6iBvXS7PTK3wwoUTNZVYUSAsoYR0+atuHFHvRGAJNdvoyp6hSq5H1TMciAeoBp MBtvmiDI3o9Dw== Received: by mail-wr1-f72.google.com with SMTP id k20-20020adfc714000000b001e305cd1597so7605664wrg.19 for ; Mon, 21 Feb 2022 08:14:08 -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=HBTjRz+Ce1AAZW1Ykcf9pK4Nj8NUD7khe4JvDJKKbsQb649k+fgkzQIrvfXEgrIs7O /Ci8g0os2odnlS5GBa+z0JDMwAwtoSWLJF860Rzu/n09dmi466rwskQsb2OOmb4EFUtX 3JnQg+Cyfnfr2P1wI21JWlgtPtqYkjCd2tbZksmsabK0Ykck/ysvW0tUeBrIKJir01o5 nGAlHSZDAVkZ9+vXUS0PullC3Z20FVqhujGjgYMrAZYo0KGy9eIjwCPNCfl4LpJiisKf Wbkg4R1cOYbfxXvS+ZVGkJWLviJ3O3na8YLjPowxyOrGGgTKCXoXqBDwSw2IkIe9E1bj OliQ== X-Gm-Message-State: AOAM533FnMD1SLi2aeBPceMIi178/WOrg1lVa1pK1FEU/VETgWYul+S4 Cj+0y0fmxjnboaDayH/JV3pz5n+sovD+Z4JBZy609OmnhyB3DWjoH3u69p8XIPN2dLm7LlXe9n7 ruerPJ4Jpa++zARzHw65cQwdDueVd0RaJaxHIeKkKcEB6GA== X-Received: by 2002:a5d:59ae:0:b0:1dd:66c3:c67b with SMTP id p14-20020a5d59ae000000b001dd66c3c67bmr15950154wrr.400.1645460048038; Mon, 21 Feb 2022 08:14:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJwNwlTRPQUvSp/uTF60wmHJDYNhgiXOGL05nzjrbLdn6G2rJra00RbHGeqsfRNSqcTRx5zKzA== X-Received: by 2002:a5d:59ae:0:b0:1dd:66c3:c67b with SMTP id p14-20020a5d59ae000000b001dd66c3c67bmr15950135wrr.400.1645460047868; Mon, 21 Feb 2022 08:14:07 -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 o4sm32504065wrc.52.2022.02.21.08.14.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 08:14:07 -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 v2 1/4] riscv: Fix is_linear_mapping with recent move of KASAN region Date: Mon, 21 Feb 2022 17:12:29 +0100 Message-Id: <20220221161232.2168364-2-alexandre.ghiti@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220221161232.2168364-1-alexandre.ghiti@canonical.com> References: <20220221161232.2168364-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-20220221_081414_487966_0741ABD0 X-CRM114-Status: GOOD ( 14.23 ) 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 Mon Feb 21 16:12:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 12753878 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 47C78C433EF for ; Mon, 21 Feb 2022 16:15:22 +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=mRfq2cxdSn0luI AoyW81dWMbEXbcUv8i8pnWQ3+3V1tC+K/szGeKv3f+xkPL6isHrd3N5sOQGmvP9daVEFMPzvt1chd dfXf1oPWE97eGLk94WGMgzyYKiSWeRa2W/9QZeST4NN/tSTFbH5V9jZrGMqVFJRiQ2//n6c0K3wXz /QpHS159JSQbQn+delHUS+2u/BjCfxSJDPVHou198Rpwa2ZykaLrfcPRoQdR+goI/BUJv3Al63Mzb bUSMmwT4JwPi/gl1Ac28QuUyUvd9EpYlLudMgnt6ch+iOKfQbZeFAR57PyUppnxOGPtnmX9GfCqWl bRNbBv3M3GJlspC1yxLQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nMBLG-006ciR-2S; Mon, 21 Feb 2022 16:15:14 +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 1nMBLD-006chL-FQ for linux-riscv@lists.infradead.org; Mon, 21 Feb 2022 16:15:12 +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-1.canonical.com (Postfix) with ESMTPS id 532BA3F203 for ; Mon, 21 Feb 2022 16:15:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645460109; bh=5wR2inrb50SGryPV3ql5qm7RIRt9i7gNq/sby+Clcps=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VN7Dhyuauh9RFyBI5ipyI8n0C4NYgAO5DDi3VIbLmt2nWXCkqkNF1wof+aCWixrsh /iQaN/+hGGWRSRs3qwaFNhXGD5H6kf3XAgNRxCmC3ywbMQprU5caJ3rKqdqDYJ15xt qcPVTUbbWI5yB9eHFRY+gjN+r9sJpc3AO4J+xyGKz8uo4jeYeAIs2RLjoTlG/QBVsa jE7JHGHtu99yCWUNDlFJ10biaXkmKRSMgfpz+ME/ZRimaAG3IzaE6SYimmLcHDNYsO tZSw9hQBd1aBo7LH8UPcCzH8sVdIGM/EBNNf462KqKilE8xpr5F81Xvoky59UHMN2P E2Xc8KWvic/7Q== Received: by mail-wr1-f69.google.com with SMTP id e11-20020adf9bcb000000b001e316b01456so7588984wrc.21 for ; Mon, 21 Feb 2022 08:15:09 -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=eZx4i1IIZNMR/JHT85GKCM/Cm6GVk3XigtbN0kRjJqfOQ3g2lcPIFLQrccoMWtPNyg fttNj8wjXSCHPLZE39qnw5pvIrFh9Kcvxy2AKs9N23cGwLkgfYk7ebhN+oGQIc0CyOTh TYSSCcaKNSe+RmZnMCGGx4qWvsDaNmxCKCDRXVliHd65Mt6SJwxPPNaA7+jKox0Sk8CD vV2r3kiYr9RaxcgCd+YxQQOJGUYquOB7A0EZkUblJLit5JCdRvlenSq+njZIM6d+2fti QNv6fNALizwQxwjygbWZhqeCXgFzuOhhE9Wnqh2PMo2C6Vl7zxI7iLnBDMGvaCTdkvpY 9UKQ== X-Gm-Message-State: AOAM531IynJjcDmDQeoba5PIQy4j2R5veTRMDHeoFh1aVGHVV4ybkJ1R DIZEv2aLnTz/I5J8kg0najuk/edQfWS4nriw5KHyS0hSJFD1KyXeoB7jfw0oLKXKpea4HAjMq9m /MhNDMrfekMwpUzY3OpON6jzyTX4jLckykLmxQ0mGV+On2Q== X-Received: by 2002:adf:e952:0:b0:1e3:39ed:d990 with SMTP id m18-20020adfe952000000b001e339edd990mr16495587wrn.215.1645460109056; Mon, 21 Feb 2022 08:15:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJw4/RK1fIWDS+henbbXZJgauSuqwElTcKvG20tpmepmsmnqy5mytufnWbPM6q+0YBF1+QKZTA== X-Received: by 2002:adf:e952:0:b0:1e3:39ed:d990 with SMTP id m18-20020adfe952000000b001e339edd990mr16495579wrn.215.1645460108908; Mon, 21 Feb 2022 08:15:08 -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 3sm49978552wrz.86.2022.02.21.08.15.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 08:15:08 -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 v2 2/4] riscv: Fix config KASAN && SPARSEMEM && !SPARSE_VMEMMAP Date: Mon, 21 Feb 2022 17:12:30 +0100 Message-Id: <20220221161232.2168364-3-alexandre.ghiti@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220221161232.2168364-1-alexandre.ghiti@canonical.com> References: <20220221161232.2168364-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-20220221_081511_689298_26C217F6 X-CRM114-Status: GOOD ( 12.40 ) 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 Mon Feb 21 16:12:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 12753879 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 01D6EC433EF for ; Mon, 21 Feb 2022 16:16:24 +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=aZwcg3Zpgey7LZ HWlBoq4/Wlcx4ermnQGbCRmWri87KTmP3snaRIRn9wPhkiOaVgFXCQZ0RMpjyGpmoXkfHwjw5njny tOmhNGZ+QNAdynWIoJcBPDuFu2pyBPv/Cq5y7IVXAYoLlJSTnDAE87Wp2ZcpXVjBkpNAVdGjlsq/h dS7I3HfIPcfqDTGxqVaSLsu7hTj4jTccbxOiBafjtveAnP6eqzk3bYRri4W8EvnuGU6FDqtvynnj/ gceUxpnkwoPq2Ii3hLzxp3UBSDJsYYQw8czijQy0j3mhAnXQWzUNubClrlErw9ZMxGWsBhwLShH12 GLIHjEwWNlAJHWTPa0mQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nMBMG-006d5C-51; Mon, 21 Feb 2022 16:16:16 +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 1nMBMB-006d2O-RR for linux-riscv@lists.infradead.org; Mon, 21 Feb 2022 16:16:13 +0000 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 9540640049 for ; Mon, 21 Feb 2022 16:16:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645460170; bh=cguSXJTSK/jUGjEgH9bI1vq5RLn1H9fQDOjhSSVs79w=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=a4EFzjDZUur7R7YNccmSMOVcwfl4gTQIls+xPg+ySJ51J5QrxGwvagPfe4kbyGx5I NN6aPlKjb+yHetwTWJXbAVk5kOTvfXBc45bq1wbyw790NZ6sWRlRuAmPGb6sk6h1NI 43noR0Nmq1rYj8hIwl/uAKicu28qE/G4EXrHA1y0kT36VdzTohP7XmUwgQlSv+yZiQ /1V4PBj/TkKasACCiYEjR+TqHJd3hEZR3J0xli7M2f3lLulJbOMqwXNy6SqSfj5YkC NhpKyw5BtZ/6XyUdhG3jtdjLWrHgH0t9snVJLeGdwwI9zFkoIT8ZJGHelxXGfgw9yO RU5Zeykrqc8Pg== Received: by mail-wm1-f72.google.com with SMTP id j39-20020a05600c1c2700b0037becd18addso4580068wms.4 for ; Mon, 21 Feb 2022 08:16:10 -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=p2hanRu2UjjJn2EheHVWX8GMXlP7C2kf7Rf3uqGophPMkoL7V1Uq0eX5AiyMKnBovk XcaWB8patDPUZA9AbbG/D1YnCSW5NfUDbZW4ON/7R26frgG+tFv0yr4vFeF+fyqAlRgY cIkCYyfpRQ+UuwfQCNGOPyt2jv0rGqhCKVp+2gZJu6YJFN5zo71WKI71cteI2eaGUATj rAkcshKZVqjNOHJgn5POQ5lMA4VG2utBVV9rYrSAFo//sZ5tk09HZGvhH3v5tG1oOv5c BmFjLR2TvEAiaHvAGTHCD1q9dTa17ph2CIrJoUEpFhgTlOTP3axTSYMV+mxJtsZWmKtS pUbg== X-Gm-Message-State: AOAM532mFVhyDhtAfmLKNOeXbWPeyk6Yw7lO8q3OE6Uj8fj4TDAPssZn zMxBP1I3ID0K8oTT6DgBm8qTWnIzKdV/Mah7R3V/p3z0rCCB5zf9oyaGL+9q1c7Z4+0cEvk61CR cz4KVfkDaoKfdUe1lVMhNU9WK1qijn6jemgekbecr/8SSNQ== X-Received: by 2002:adf:f14e:0:b0:1e4:a64c:c1f8 with SMTP id y14-20020adff14e000000b001e4a64cc1f8mr16542838wro.512.1645460170158; Mon, 21 Feb 2022 08:16:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJzYgUE7MZQmI+ZQcdzJiIN1T9Ug6obXjiEHel6BWLTa8oJLZK8xZY9nQ5A4HYo6se/kNAsxNA== X-Received: by 2002:adf:f14e:0:b0:1e4:a64c:c1f8 with SMTP id y14-20020adff14e000000b001e4a64cc1f8mr16542818wro.512.1645460169981; Mon, 21 Feb 2022 08:16:09 -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 r2sm10098731wmq.24.2022.02.21.08.16.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 08:16:09 -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 v2 3/4] riscv: Fix DEBUG_VIRTUAL false warnings Date: Mon, 21 Feb 2022 17:12:31 +0100 Message-Id: <20220221161232.2168364-4-alexandre.ghiti@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220221161232.2168364-1-alexandre.ghiti@canonical.com> References: <20220221161232.2168364-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-20220221_081612_070610_379FC7C3 X-CRM114-Status: GOOD ( 12.21 ) 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 Mon Feb 21 16:12:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 12753880 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 BFC28C433EF for ; Mon, 21 Feb 2022 16:17:28 +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=sIeJEvvYrADfpT WAP3G9uX1L3WLveKYSInRrPs5gB2oOVq9rGbJasR9JZ1zZHsNOh2RCRf+kc+MVMllM6WkdC1XDvX3 x6KS8HnvMn01R0p+ovx+009XAHkXfE+Wi8N1qCRLSCjx2AgKUB3cXRbZyMHeRluzvxjhdfJIh1Dga 1KMWAMPNhErnxiHsVCWXvZgtmMLSza1utsgVcDgLOmLPy9szh47Dd7pGo7yJ50yyio3wZgYqVSGkV q+favRIt6RX+WbvsHnCnvffYLYeDVw7vddXL1vs7eu5a3p+D2ux12U5q1MHxki3+y26sP2UD3mixP DtvUildDe4yoO/ajvU9Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nMBNF-006dXJ-DL; Mon, 21 Feb 2022 16:17:17 +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 1nMBNB-006dV8-8E for linux-riscv@lists.infradead.org; Mon, 21 Feb 2022 16:17:15 +0000 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.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 E3CEE40257 for ; Mon, 21 Feb 2022 16:17:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645460231; bh=JOP3F1szvziyyHwwb25WbMBDR7/phOdbs80dtO/BlA0=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=o6EukZQ8zM9KFiyjjWt91Mw/lHEpWlHO3z4p/T1PQ/LyAtU9uJZrkiu6m5+Bv05uA Xmg7qHoxgOykf6BaDg6E4+MY+SZEyAusjIc+Awq7Y2Z0OaQXtF3kFD+rWAojcYtYGq F3cWfb0SKFDUG+4nb0UU3i8oucARxPZY5DLEmN9qT4JPmEFte0G/P5iLg5WIf80eAL YgVOupU/E5NC+gWGNJSevFUNXYA4O2wJujyvfZKwYe65jQflfJiDkEoNRaP7+M3T3j iPuIsXcNOY1aGCUflhS/k1DAz5nmdUPqjvUVDr6EjNyDOuOdcEfJNFBZSfZE0IkpUQ pnSTavhokJelw== Received: by mail-wr1-f71.google.com with SMTP id j8-20020adfc688000000b001e3322ced69so7613398wrg.13 for ; Mon, 21 Feb 2022 08:17:11 -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=NAUr9apoO5DDsACQ6a8V8+kYIhhDZK8ouHYRGz7zJpPrahtu109E1xykMS7ou5Tfrt Q2zN00GqEh7VJm/kUDGLEAUnAsQD5DRBV5rsIAcoB96oOxy0lzqXJ9ebseEQAGTh903i j3uVfMnR3lNJ7c8X8i0HfJKYMCgbFHXoLM5gR4E/XnKS8uv3OLI7sAmkNIKt4dcftAYV WEjHVCwCQek4u4oDY7dZcEbQqlQJ/LHxKfXRnjzNiwlncabeQ+OeA+xYYF+H1SiV9bRY jq6z34PaE+Pz8mwpMWIoDJD2aS8BTiPsg5DJo8Q5IJpakQni2EH4utV93+xrIZTPhiXz a+9w== X-Gm-Message-State: AOAM533mFNtNSoRLp01BX3ug00uu54kRceyTvSRUPFNp+7rTmsdYX9cI 3GSeJ8jotF/FzqR4SvA+jbVyU29bIkn9T+mxYwT2qaHRcb8U9KpP6jtubx2udu2TXM3+uAam34u l5HKEt5N5LZ5gWcnuKvBaU9A7tf8khbygbDxtEjQXa9FdGQ== X-Received: by 2002:a5d:5885:0:b0:1e8:edbf:2d07 with SMTP id n5-20020a5d5885000000b001e8edbf2d07mr15598185wrf.85.1645460231228; Mon, 21 Feb 2022 08:17:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJzXKrYccEg4SGZYpkC/dp+cdaF1zX9TsezjyOZb4KizvNQIRmWsWVT22DWvpfUqlPM3f+r6/A== X-Received: by 2002:a5d:5885:0:b0:1e8:edbf:2d07 with SMTP id n5-20020a5d5885000000b001e8edbf2d07mr15598169wrf.85.1645460231012; Mon, 21 Feb 2022 08:17:11 -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 c11-20020a05600c0a4b00b0037c91e085ddsm9825161wmq.40.2022.02.21.08.17.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 08:17:10 -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 v2 4/4] riscv: Fix config KASAN && DEBUG_VIRTUAL Date: Mon, 21 Feb 2022 17:12:32 +0100 Message-Id: <20220221161232.2168364-5-alexandre.ghiti@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220221161232.2168364-1-alexandre.ghiti@canonical.com> References: <20220221161232.2168364-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-20220221_081713_467051_0F247260 X-CRM114-Status: UNSURE ( 9.93 ) 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