From patchwork Fri Feb 18 13:35:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 12751442 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 87882C433EF for ; Fri, 18 Feb 2022 13:46:08 +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=ehUyKX69NM0GxhOxeVueavwDB2lOtjqPmTlhZg2GHTE=; b=oXkbcALy+Y55Ur gSOUIvhsTy9uSXKc0F3Ps8lz2qWbbWCrtChOgkF3pXwkojEeJw+IhAYE7MBYoPFEUweXux8H0wT6k Pd6P0jry/6HLi/qflEkzF8pt0i3fEH2Op96414TCRZSCI+pndSdhxbfvfzlLk32vqDLBQv7JtBBWC jCKws6f1ev1Kq4WSpeaARBWFKcD2kg+2jzERGEyTUfbkFa1MmzCtRpu5sQav/zrKwf4+Vypcjtev1 ITHbRbDox0eygxgUA17tttjql7JGcNbUzSoloxz6WqTbLXiSnOxBUvZIq62L08+HzCDLR+DdfOZ/H gZyWaR2t39XOnGWyM0Vw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nL3aB-00Egrt-74; Fri, 18 Feb 2022 13:45:59 +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 1nL3RG-00EcyY-2k for linux-riscv@lists.infradead.org; Fri, 18 Feb 2022 13:36:50 +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 A7E4A4001E for ; Fri, 18 Feb 2022 13:36:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645191402; bh=H/bO0aBxUyDz5Z1iaHc3hPM9Zt6+vPNG7kqFlweb1Sg=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=g4ClVBKoiKOVYoMBtn/PaYmVnT2JIEhCAgy9ZAOhFQN1xPOS0EasbsYR6GiM7SbqT 0IdM2i/wNFu8PtbzrbOlSkU+k3NmlSmfkdeap/l5sUkm2OIkubr2I84NkWxuJhyox9 aRBVICcdHwAM/11F29WC90JB5YsPZEfVxiL19nD9varG7jfkqkKRSFouRswg8imna5 Zmt+0Yj2fCOIlVa935DNJ8XXCe+JO6A1PmcySF7+LxNeMEDFv2gHgeqIMeQg643qx0 toy8OzlSFH2TQN//SAMrQFk4/uFA0+5ifyo6fVA4IoqePtmlJHZFvB8y5vHjA9zuDO DdjK+KsKqGDtg== Received: by mail-wm1-f72.google.com with SMTP id h82-20020a1c2155000000b003552c13626cso5943781wmh.3 for ; Fri, 18 Feb 2022 05:36:42 -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=H/bO0aBxUyDz5Z1iaHc3hPM9Zt6+vPNG7kqFlweb1Sg=; b=Bf1VHIzH1jjnMBE7lMMVEWKZh06qJLPWetgfEm4S2lZJHs/PSNtxOmrUGYW4Z1KN7o nVlaJJTN2xcdvo1LapI05fqvXJIAGusFHCVH31wevfJn3VkYwTXCdGF4wh9vCuGpX0k3 DJaPIG/cFOVdXNLtP3BSqVevqEqvrDaaWyQGegEkWKIwK0c+3GNLn9WMzGIDc8LnCja8 Atwg5owBmrjTxSrasHI8NsW9PzqijjNt07gFbTO7kNm1vHwn60heAH29bQG+xRhn33d2 S8VeRBQiDxI7+Goq/vDqYqVo7V3ACGGTy1l/6Pe7y4TboF9NDBLW8wusE9puXI6+b7b1 HLcw== X-Gm-Message-State: AOAM530grbKYhmsRwb7DwSxZ1noB4YkDn9fqWMyY6dDcwOKViMha0CHb SxK334weU8sobc2ceZAeotDsbAtIHKeAx8waSiwmo0L4qUXJup5r1w0euZf+3AZPkxjpOdkF1WJ NWNvbK7j0kY7icoLvUzKvB/bfxf8cSTHR5UVZq4vfwKq5fg== X-Received: by 2002:adf:c188:0:b0:1e6:8ecb:ea5a with SMTP id x8-20020adfc188000000b001e68ecbea5amr5888273wre.711.1645191402137; Fri, 18 Feb 2022 05:36:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJyONeVylq+VBkXW8VpHpa9vSjAFyqnAnqrsQ2M08ZZvxaC3/JU4jOZLRotcih0KkieDFRj/qg== X-Received: by 2002:adf:c188:0:b0:1e6:8ecb:ea5a with SMTP id x8-20020adfc188000000b001e68ecbea5amr5888255wre.711.1645191401906; Fri, 18 Feb 2022 05:36:41 -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 z7sm4146155wml.40.2022.02.18.05.36.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Feb 2022 05:36:41 -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 1/4] riscv: Fix is_linear_mapping with recent move of KASAN region Date: Fri, 18 Feb 2022 14:35:10 +0100 Message-Id: <20220218133513.1762929-2-alexandre.ghiti@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220218133513.1762929-1-alexandre.ghiti@canonical.com> References: <20220218133513.1762929-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-20220218_053646_297063_A832F449 X-CRM114-Status: GOOD ( 13.67 ) 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 Reported-by: kernel test robot --- arch/riscv/include/asm/page.h | 2 +- 1 file changed, 1 insertion(+), 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) ({ \ From patchwork Fri Feb 18 13:35:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 12751443 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 4A3F6C433EF for ; Fri, 18 Feb 2022 13:46:26 +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=RFZFzjs3h0iZe/ Keia5SWo3zV7Qnm6rLRnrZmY+l+xf3bPsR3g51YnDrBE58ds9ytr+4AZ0fixbdHLsO3moe7GlXmH1 jxuD8hCZGdlEQgaCbTwY/ruX58Kcy8GY8TLYgtrkC6y4mDOd+ffPF8Hvh3qEzcjh0nqKV/P9dX/yj GG8FU4zZ35zDV6psP/9zsl2eaXwSdUviX0cA6Dk/N+b/2M0FA3lPJZh/mb7W+WF8SnWPBOK1J+qrz jcZkcsDdmqVtMex+a2g/S6efaw8NIGDgmxW4O+K98ukEF2B9AYPh1TGGS29Q4XIJJxaVqEppOgJ1a er3ODXQ7p83jT6bteWHA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nL3aT-00EgyN-0O; Fri, 18 Feb 2022 13:46: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 1nL3SD-00EdPR-2B for linux-riscv@lists.infradead.org; Fri, 18 Feb 2022 13:37:47 +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-0.canonical.com (Postfix) with ESMTPS id 9C7E64001E for ; Fri, 18 Feb 2022 13:37:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645191463; bh=5wR2inrb50SGryPV3ql5qm7RIRt9i7gNq/sby+Clcps=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qZuo+9Csuk+9lm4KjCfI9sOW1y/+M6zZS6c2K7eLmCTFmq7gOMj4jzO1lD+pclrtQ 7RF8NbzT9DWNJbOzZI1lFfv3hfRWMheQyQXkuXXBrnblME10x1269GVi5H8N5Xx6BY cHR31WadHXSYtlqZZBKcQQsStuOO+aqTk/dOERY48V5RNU5U2DvaNKkYu0b5R/tHYD xhZ63bm9Kxz8uGlrq26o33GPw30N0oNRmJ12BegPlzmOqCTWveCGeb+b9iPTbs3d6r v/oSTcD9BYTSWccymiWo8KPHqeUo+5SIo4EMBHR6lwpDCzvoAG79RnT+gRBNKVV8HC y8PJPCvADzAwQ== Received: by mail-wm1-f70.google.com with SMTP id i188-20020a1c3bc5000000b0037bb9f6feeeso5941106wma.5 for ; Fri, 18 Feb 2022 05:37:43 -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=SmBkBXXG0VqxNVZgPeO79pTwByaiLO1qslHMAw4B8UKQQO0SdJRJJ84FzO1cFwZOe4 //tzKZ4llktdC/d3Js3iBCiszXvuwOVWjewA8obMUix6BhOUQymzYa2gLB12P3aSUwFQ cLXVP1YWQ9b/HPZgfmZeXGYKgRVL1CpMSMISawgIyNXtp2IL9rPQ6whud+dnX3Pq42xQ oC/m9ghK7P9VJtuVOggAUkxGOuyZxrVFR1WxdvwBKW1ro906/s/nF54liwfqqlDE3Plo RtE3T2uhjnkNzf4TIeA5JW3L4hXR+e8Dvk6q9kbtXqrYP7Zhu0f0hOmYKbkmoy9G/yTl Tbyg== X-Gm-Message-State: AOAM532oLHOIzMb8/fGPOP2FU4NEhkuLlB2dZyuGeskgXRYTL0yxDXs5 CqEpqU00mVRDTkVfyvVctAUO0nowAgYGEP8vy6oSOafOemul5jk29LgY/ujQhUsO05gvS6S5Iv3 aWyt7WOUrvoxGvwxZKTGmrn/ABRQWApEA58z+HC1nntcbIA== X-Received: by 2002:a1c:7715:0:b0:37b:dc94:9eb4 with SMTP id t21-20020a1c7715000000b0037bdc949eb4mr7292829wmi.61.1645191463168; Fri, 18 Feb 2022 05:37:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJz1rOcJLLe1sMpbmzJaKzZ9MrfRNf1PgF+TEXDfRIfQBwQQMxq9mXwaThHJyZuyQwyiE6VwOg== X-Received: by 2002:a1c:7715:0:b0:37b:dc94:9eb4 with SMTP id t21-20020a1c7715000000b0037bdc949eb4mr7292811wmi.61.1645191463026; Fri, 18 Feb 2022 05:37:43 -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 h21sm4886378wmq.26.2022.02.18.05.37.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Feb 2022 05:37:42 -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 2/4] riscv: Fix config KASAN && SPARSEMEM && !SPARSE_VMEMMAP Date: Fri, 18 Feb 2022 14:35:11 +0100 Message-Id: <20220218133513.1762929-3-alexandre.ghiti@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220218133513.1762929-1-alexandre.ghiti@canonical.com> References: <20220218133513.1762929-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-20220218_053745_280043_291D788E 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 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 18 13:35:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 12751444 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 0A306C433F5 for ; Fri, 18 Feb 2022 13:46:39 +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=x0kQfkwVmmc+X/ cDoLyv5L+eTV2I9+ENeTS59/grw0xTGW3al+6JkgfacIxiIfzr5yFeLrcVbhditL9o+ZtPmR/Kv4P 0je/XeZs3AQgsPAxG+XGSp+SkYDflrlHOX8K6M4VfJFSnXcHwJJPaiFUKNlqVFzHkUwnamF6rwQJT ie7zxC8rs2eWleswOQym4+HNiIthVAetftzHLcyrGrg4i/JLaaN/6kHI8ze4RHj7O4J7Pi3eHa4fK woT6Oq2c5iD5mRkGmJnJLx0pXJfK+kgDPtpofZ15gjz3qp8b9YbLqCxxvBXhGfdV0CrSg4G8zGuD8 L+nAYIeV/HG4WRzSOFGA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nL3af-00Eh3V-QD; Fri, 18 Feb 2022 13:46:29 +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 1nL3TF-00Edrw-HS for linux-riscv@lists.infradead.org; Fri, 18 Feb 2022 13:38:52 +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 3BDC340296 for ; Fri, 18 Feb 2022 13:38:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645191525; bh=cguSXJTSK/jUGjEgH9bI1vq5RLn1H9fQDOjhSSVs79w=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TQsngHCzn9zqpqt981ryZom9swr51N9uEni5VKWX2OH5fie7OtaVJVWGFaU7qho+L o8W3J9RQrKVrDcYPEnfnaZu+cBnVCvkqMfYDZUUKx8RAQ+qFURnUC6o1Z5Ky31epB4 HQ1Ur9BCmf7FAYTnJjsXJpfpOqU2J3cNC+xEAz5tR8cgz9hJuTLXHzRLtq4Edqst02 XEVS4vyTN0r5YvA7bsYehd6+E6Rd+MqvxnZTjMIMA/4lkTPyqsi65WaFgIb/lJmT/1 JPWIUsVb0pV/cT/4pDROYHeLMKRcxoTQwkrEVI2fkffluPlb9Ca/LDi54MXImgUI4r WNrxFyJOlYO1g== Received: by mail-wm1-f69.google.com with SMTP id t2-20020a7bc3c2000000b003528fe59cb9so2861401wmj.5 for ; Fri, 18 Feb 2022 05:38:44 -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=M4YGM6Y4RcEY0Bw2q8T5lFAxcARqpDlezduHTYj4y4f2wjdtu5GynrNRe4YAhjVnSb jVt4bY/PurrK0fE6WGNjsUMDTvjjUzADSeu1dS8GGpiLMtBr7z+pB2imbOdVoK4LB9Hf wgCR7eBXgv5PcyvE5U/zRlRFFWlwS9AkZFJCZ28sJw1tiqBQzjwseiXHfJCx4VmHytlR jw3jcyxpH9yojhap0Hvma7Ys66Uc4lxYFma2A34taydehfim2VSRzI7i0qt6WenD9rgT Bl3AAv+tR4D9WKE6GSD7re4Ky6he56YO+7//CAisJFLAYoAlNj8pUGbEK9m9iX8fPCRy AXQA== X-Gm-Message-State: AOAM532Ofk3MCAQbWZqTq1eUujOxZx7ajRHN8ARf8x/fG1oKrcy97Uiu 08Q8Y0w6j70/lGepSDtu9y1ddfYnNK+NdWyC7MrYzrh5MB9hLQJlLQlTX/Sk3vqGrCxJUVGz5p5 ZQ4mD8pAIuYH5CVmJsbFl4LKprthJz8Qoq0/XFYVbqHsG+g== X-Received: by 2002:a7b:cbc6:0:b0:37b:c56b:9eb9 with SMTP id n6-20020a7bcbc6000000b0037bc56b9eb9mr7250946wmi.17.1645191524258; Fri, 18 Feb 2022 05:38:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJwwdi9qCsRGOKRf5aFH1Q0xUVlWAkuAr/mtea9chk3ia4coprzZyLiP+xUhMh9Zer9nD237Mg== X-Received: by 2002:a7b:cbc6:0:b0:37b:c56b:9eb9 with SMTP id n6-20020a7bcbc6000000b0037bc56b9eb9mr7250929wmi.17.1645191524072; Fri, 18 Feb 2022 05:38:44 -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 g5sm4282472wmk.38.2022.02.18.05.38.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Feb 2022 05:38:43 -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 3/4] riscv: Fix DEBUG_VIRTUAL false warnings Date: Fri, 18 Feb 2022 14:35:12 +0100 Message-Id: <20220218133513.1762929-4-alexandre.ghiti@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220218133513.1762929-1-alexandre.ghiti@canonical.com> References: <20220218133513.1762929-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-20220218_053849_749426_F539F675 X-CRM114-Status: GOOD ( 12.02 ) 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 18 13:35:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 12751445 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 2A2E3C433EF for ; Fri, 18 Feb 2022 13:46:47 +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=mbP5JQxVTasw9v pdP+pyLlESBglSILzXFksuZe7KYRizm4FNIZ8wBA5w8RaEstjhlXhn4YPs73JRWmE7A8hu3Uhn87Y qjiDGuHZe9FjdGxwr6p/kspQ3mI6fIbVLZGFFP0sWWCHOgoUsC1tpa2oRbIbm7tvkitVFQM3qIIE+ CW9s3AkiM8nifyig62+WuIl8OOVwbvMUrx0mMUrExqeZojLB/D95oEqEDGZgpjxXD5sqAxYWffsHg y/z0HHcVzFlxTUHjD5Liz7vPnbBB3udkkC6MRBJySom/ewdRVbnaKWAtkqjEF1RLHgc5yqFjSXfUB idSinybsfdCUWOrWDeug==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nL3ap-00Eh7V-3l; Fri, 18 Feb 2022 13:46:39 +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 1nL3UB-00EeLo-H9 for linux-riscv@lists.infradead.org; Fri, 18 Feb 2022 13:39:50 +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 51AFD4025B for ; Fri, 18 Feb 2022 13:39:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1645191586; bh=JOP3F1szvziyyHwwb25WbMBDR7/phOdbs80dtO/BlA0=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HkBgePu1z6Xb6T7ZU/TwY2W3OP3b9XR8R+DhdYzwQQ3HDjpcZXhjzTtPfF2uNXv5T W4hBSf+BKGreno7qJ7238UZHBPoOI2rpDdEIpP7VPkqSxTuoVfFwxcLo6yXbVAZm8V 3aGS5mK/0m3Rw5vyYOZRODSct5rAuiFRAi4NYISg3a42CI2x8FetaM5eYphowgTnp0 rzZAYHOTDDbIOp4EQud6hLTDA2ecjVyTk5Xz9b/ufUzPfyu3tOsEZ+z9LjMbHKSwA6 ngWt5hbEcCKqpBCRABhH++cHiNbx/LbXIatzsS3x6VBpnA+YMMUMtVpHCt9Ds8sAgT 9Lj7WY3HPu9wA== Received: by mail-wm1-f72.google.com with SMTP id v130-20020a1cac88000000b0037e3d70e7e1so3181927wme.1 for ; Fri, 18 Feb 2022 05:39:46 -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=TN4H2UgmlA1Pdjz8ZTO/wmcegJfTE9gkJq3n8L4jrwoSJ4Lcc/odK8QGOBJnSFhDoQ S9GWlEZ5TEsUCFBpvcTxqY8lIzx2rjXCGGj3yCMUKMmbnz0Xwe7OBgH9LklQHbUfZTt7 8zT0nNfsePL0/uoCIY+3GylNYxU2klI7EMcM/vmvsiG9DXOVdTmQVL60Tajg9f7LqKpo DUA1b4gH3epfyMni4rdDWmz5y3jUhpsd6MP0FehV/Pptz//xNi09eQa3w0hBv9xK0Rsz Q+uyFUStM+fLXGH0oTKUd4AlRsn3WFlhSSVZOUXZrRcG1PMVzze5+eoybOx5DhLumHQP Q23g== X-Gm-Message-State: AOAM530zTYnjdJc33uorZCZy12Dksoft+F+ipXuJP3OzDxg/GzICGXn+ 0oUBf2ycHER63MJWi/N4H/ySll14KLfHLofGDAYDPIRSSMpWUJwm7q3cwxi3vGtN4WjQ16hW5fz 0YOE2g7+1x0wOcUzcuiL7IaJIvgvYHSoJiijlMhlAKV6dbA== X-Received: by 2002:adf:e5d0:0:b0:1da:4dfb:497e with SMTP id a16-20020adfe5d0000000b001da4dfb497emr6489396wrn.282.1645191585234; Fri, 18 Feb 2022 05:39:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJwa9rnt86pwmOEJdbUgC/kacrYzPY5oQ4mpvy+Mq/o4FjRWXCIzn6psjVvt7DCwVdslstNNkQ== X-Received: by 2002:adf:e5d0:0:b0:1da:4dfb:497e with SMTP id a16-20020adfe5d0000000b001da4dfb497emr6489383wrn.282.1645191585101; Fri, 18 Feb 2022 05:39:45 -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 x11sm4183619wmi.37.2022.02.18.05.39.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Feb 2022 05:39:44 -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 4/4] riscv: Fix config KASAN && DEBUG_VIRTUAL Date: Fri, 18 Feb 2022 14:35:13 +0100 Message-Id: <20220218133513.1762929-5-alexandre.ghiti@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220218133513.1762929-1-alexandre.ghiti@canonical.com> References: <20220218133513.1762929-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-20220218_053947_738273_30B4CF25 X-CRM114-Status: UNSURE ( 9.84 ) 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