Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp3883357ybv; Sun, 16 Feb 2020 08:06:26 -0800 (PST) X-Google-Smtp-Source: APXvYqw4MNoG2h3AwvFgpk9h40buHc4caVzFGlqSXtiW9lLx2rdxWy6pMBdpa9x5tA/oSd9OKl0r X-Received: by 2002:a9d:2ae5:: with SMTP id e92mr9300953otb.72.1581869186155; Sun, 16 Feb 2020 08:06:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581869186; cv=none; d=google.com; s=arc-20160816; b=lUriKN6JGpq6RuOzf/fyu74xkS9c32v6cc23Br5LuigW9iwFPVODWZ5JX0rHcEg7VK USEKqja6gYyVow12GDtp3Iuj7x4TK7EffFA2JDtZmmpowAKJ+4XAFXB03nMchv3RAeT5 m6UjOAJ8grjmiXnuwDRulGcVvhIBdUXFkdqa8nV0kfAvC+BA+mbjjCkH1yC/LOAvH/Xz XLcHSD/elClGoPUVUxqZcRC1dMDPh7erUbdCRfHZN1b2adYgvZLBCw92hBk6v0M2k/ki DNmFt6XkUrFHFKvFsZr+dmq5xvDNp6aEdk38rpjMz07Z7v2qDG4GZJoyY36BDKrz4YdN WsKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=MZlY5jXxovnVpKhXenFIH3sYVC3V8sCSqoLKnbMBfrg=; b=JTW6gxk/kdlxdlZGLVY03jei7plfMWpY6gWy4xpvfrN0zCUGzLH3OZ9NaiuU3dSVBR iOr/y4Xzr3i+7QKCQeLzDjj3ApU0JZ061+wRMm5uyM0uXdgKaIDz5ghpmxAU24213Z+n JT5d1K8lxKWbip+0dieCzdwja0TrbYs/DjgC1AkMtaQNYDUbUTspegdKuwrMnSCoP5ik e49vAjl4Xsuiq1g4DUhZOl5Ai59F80Z87+9ibt20scRwQRZahf9bQUEqwaakhu+6Fi+P zvP/7bLVnXAytfiK0MKUp1xXe6k8YplrYNdz4W6biciF6b55I9iSsKsTtRe3rAuT9aum 2nFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@web.de header.s=dbaedf251592 header.b=KMyaulIL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w4si5917772otq.144.2020.02.16.08.06.13; Sun, 16 Feb 2020 08:06:26 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@web.de header.s=dbaedf251592 header.b=KMyaulIL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728382AbgBPQGJ (ORCPT + 99 others); Sun, 16 Feb 2020 11:06:09 -0500 Received: from mout.web.de ([212.227.15.3]:60155 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728293AbgBPQGI (ORCPT ); Sun, 16 Feb 2020 11:06:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1581869156; bh=MZlY5jXxovnVpKhXenFIH3sYVC3V8sCSqoLKnbMBfrg=; h=X-UI-Sender-Class:Subject:To:Cc:References:From:Date:In-Reply-To; b=KMyaulILEc0ViK1SjeBPOF9a98z71AIW87x+3leMPx3lnAgzGJ9l/h1G3DMapurvr DP0fHiGoXftlHgzqMeJjBBp2nCeoHTTy5j84XSqavLH9x4nW/bmzLVuGh/I0ILEMN3 ZzpNoX3i3CC8Gi5AazB9hKuvNtHe78hcPBeGEQ/g= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from [192.168.1.10] ([95.157.55.156]) by smtp.web.de (mrweb004 [213.165.67.108]) with ESMTPSA (Nemesis) id 0M4lkz-1jO4FN2tjh-00ywOb; Sun, 16 Feb 2020 17:05:56 +0100 Subject: Re: [PATCH v2 3/3] riscv: Fix crash when flushing executable ioremap regions To: Alex Ghiti , Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org Cc: linux-kernel@vger.kernel.org References: <8a555b0b0934f0ba134de92f6cf9db8b1744316c.1581767384.git.jan.kiszka@web.de> From: Jan Kiszka Message-ID: Date: Sun, 16 Feb 2020 17:05:55 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: en-US Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:4IYkYoTip6rhKbBbR3p45GwgeQBDPssEbOY75DgUV5s0zWnKyf0 /xbkS6vPCX50+OITwD3eb3uAo87TZJvAW3LpnZXgsALeRQfWGvJHoU6LUBLgJI7bjbzFoSv qVOUmoJr7OI59ePFab4bMeymQ8p/fZFDG9pIq0dzd5fCPpVrjlxo8RQHkbaMl7cRTaApIvn ggBPQKU+Rd9hUusHBcXYA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:+wWHqJLZyLs=:6QTPINZQciCeoWt1mjpoif U0g4M0oP+tuEm0imgfgwvi+9PJsPduQv1+os4sPFys5GYlx22fgSjghLYtewimO19gTUj++Ze vFYGKdCMmh8c0CwowbhJ6vv5kxVRObsvoWdGJ2v/0dO6Wxtf8136fOtSNd6gPJbQz3vheannA s31KAgPiF8M5LSKv/4vkiIgpANe08i2+JOFHS+X1XfZX9HLe3bQrnRnns2H6zVBzaH0vl1X/F IegofJz+Y/WqBsDLVT95hyGVBrkuhotjHp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jf4pPxEoAB9uFtirYWuJzI5yJ7xUn9qDi2yJpPO904u0E+i7ww/ELI/pAu Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 16.02.20 15:41, Alex Ghiti wrote: > Hi Jan, > > On 2/15/20 6:49 AM, Jan Kiszka wrote: >> From: Jan Kiszka >> >> Those are not backed by page structs, and pte_page is returning an >> invalid pointer. >> >> Signed-off-by: Jan Kiszka >> =3D2D-- >> =A0 arch/riscv/mm/cacheflush.c | 3 ++- >> =A0 1 file changed, 2 insertions(+), 1 deletion(-) >> >> diff --git a/arch/riscv/mm/cacheflush.c b/arch/riscv/mm/cacheflush.c >> index 8930ab7278e6..9ee2c1a387cc 100644 >> =3D2D-- a/arch/riscv/mm/cacheflush.c >> +++ b/arch/riscv/mm/cacheflush.c >> @@ -84,7 +84,8 @@ void flush_icache_pte(pte_t pte) >> =A0 { >> =A0=A0=A0=A0=A0 struct page *page =3D3D pte_page(pte); >> >> -=A0=A0=A0 if (!test_and_set_bit(PG_dcache_clean, &page->flags)) >> +=A0=A0=A0 if (!pfn_valid(pte_pfn(pte)) || >> +=A0=A0=A0=A0=A0=A0=A0 !test_and_set_bit(PG_dcache_clean, &page->flags)= ) >> =A0=A0=A0=A0=A0=A0=A0=A0=A0 flush_icache_all(); >> =A0 } >> =A0 #endif /* CONFIG_MMU */ >> =3D2D- >> 2.16.4 >> >> > > When did you encounter such a situation ? i.e. executable code that is > not backed by struct page ? > > Riscv uses the generic implementation of ioremap and the way > _PAGE_IOREMAP is defined does not allow to map executable memory region > using ioremap, so I'm interested to understand how we end up in > flush_icache_pte for an executable region not backed by any struct page. You can create executable mappings of memory that Linux does not initially consider as RAM via ioremap_prot or ioremap_page_range. We are using that in Jailhouse to load the hypervisor code into reserved memory that is ioremapped for the purpose. Works fine on x86, arm and arm64. Jan