Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp272818pxb; Fri, 3 Sep 2021 01:37:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzQcFyMY9j3AJLjT/5swXdO2ZaSYMf6xMcXG7T5uQVvZvCqWCuXna07wXQH+edGkPqRuNwH X-Received: by 2002:aa7:d99a:: with SMTP id u26mr2742032eds.297.1630658219919; Fri, 03 Sep 2021 01:36:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630658219; cv=none; d=google.com; s=arc-20160816; b=dBviL5P+IN2Op1G3C2GJMfG2odFnvAhu3WlusSWtunDeFpXESbClt9OPiNNUGmvI46 /rG7a0FXMwQOmQ8ddBzccNUjCkm3oZyG9t/o9CmipGGuZDTkXsIcbD0XdtbCHx1NotyG J5xASQbvQYGldHCXknxs5PqOL5V9WHpfjRdQWyUo5KXEcRAzXJL49z5bASU8aZx/q26O 9sl/7p7TwIBl8JvGIkJUC/pMheud/eayhnVcIRRRtxctLCZn7ho7az7Fh/dwGD0aYYx+ 2bMI4BVmDNomW10aIZkp/AOXaw+dOVlNyOkPlXarsmouhJ5P/vTc4zsyl22vfP5nyQKQ 8Y9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=J8RoxJY5YWD6L345C8pVJswsjYCAar57SLMZj5T/CnQ=; b=YRU/wyHf7jWhUjuY0qW9+siE3SPmLYkZAf8K/qIxwKyzj1Jin8GL5rx2GRTXp7hC5Z 2vmhE0Wip2UNUIHTtika2k8ePjDfkXVMXpj2QwdwxGH5nMLVEZc8e7I0M8wZrZD6gvWR S7TrvL9sZHNKdl0o6150eNCViJJuDebW7ufv+3KrtVOeol9/Jj11S/gQ4N5+CeQzGrPv Kstx2vtdqqrzaVKvg71sTriOaZA+h43iriOv4rbem+hXCvpbUat6FLW1f9BLQ2PI/kAe th2mjl973Q8v2rzfcLZIeJB11/8OHYBmjgclzvV7KvtipvBs6rINJJPsimrgsdW3GGHm 60Yg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q23si4646680ejr.192.2021.09.03.01.36.35; Fri, 03 Sep 2021 01:36:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348310AbhICIfv (ORCPT + 99 others); Fri, 3 Sep 2021 04:35:51 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:15382 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234851AbhICIfu (ORCPT ); Fri, 3 Sep 2021 04:35:50 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4H19wr218mzbgyS; Fri, 3 Sep 2021 16:30:52 +0800 (CST) Received: from kwepemm600003.china.huawei.com (7.193.23.202) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Fri, 3 Sep 2021 16:34:39 +0800 Received: from huawei.com (10.175.113.32) by kwepemm600003.china.huawei.com (7.193.23.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Fri, 3 Sep 2021 16:34:38 +0800 From: Nanyong Sun To: , , , , , CC: , Subject: [PATCH -next] powerpc/mm: check base flags in ioremap_prot Date: Fri, 3 Sep 2021 17:03:39 +0800 Message-ID: <20210903090339.3671524-1-sunnanyong@huawei.com> X-Mailer: git-send-email 2.18.0.huawei.25 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm600003.china.huawei.com (7.193.23.202) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some drivers who call ioremap_prot without setting base flags like ioremap_prot(addr, len, 0) may work well before commit 56f3c1413f5c ("powerpc/mm: properly set PAGE_KERNEL flags in ioremap()"), but now they will get a virtual address "successfully" from ioremap_prot and badly fault on memory access later because that patch also dropped the hack adding of base flags for ioremap_prot. So return NULL and throw a warning if the caller of ioremap_prot did not set base flags properly. Why not just hack adding PAGE_KERNEL flags in the ioremap_prot, because most scenarios can be covered by high level functions like ioremap(), ioremap_coherent(), ioremap_cache()... so it is better to keep max flexibility for this low level api. Signed-off-by: Nanyong Sun --- arch/powerpc/mm/ioremap.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/powerpc/mm/ioremap.c b/arch/powerpc/mm/ioremap.c index 57342154d2b0..b7eda0f0d04d 100644 --- a/arch/powerpc/mm/ioremap.c +++ b/arch/powerpc/mm/ioremap.c @@ -46,6 +46,10 @@ void __iomem *ioremap_prot(phys_addr_t addr, unsigned long size, unsigned long f pte_t pte = __pte(flags); void *caller = __builtin_return_address(0); + /* The caller should set base page flags properly */ + if (WARN_ON((flags & _PAGE_PRESENT) == 0)) + return NULL; + /* writeable implies dirty for kernel addresses */ if (pte_write(pte)) pte = pte_mkdirty(pte); -- 2.18.0.huawei.25