From patchwork Thu Dec 1 15:42:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 28419 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp325510wrr; Thu, 1 Dec 2022 07:29:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf5Z/BM+vHpjfNwywjsbqUgcU4QYl5TR5ouXun4TGPkXdU/Pft9ox+panU5lTU7XZYKBXcQ1 X-Received: by 2002:a17:90b:3444:b0:214:e1:cabe with SMTP id lj4-20020a17090b344400b0021400e1cabemr49118721pjb.153.1669908585787; Thu, 01 Dec 2022 07:29:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669908585; cv=none; d=google.com; s=arc-20160816; b=iusVLrLjhGqtvyLFtNatLDhShOHGIkJnUoiVComfmg46BBZyq7cTbVuQFvcnBGYaf4 shFkPYsj0LnMTd+h2OJ75OqATqgT3pzrJ+xwP/m52fMKwuF6UUlLWCcIXREK5nCaCKzS /JtYh/2DOFSWxR254YgdCrRJWDzNU7Hz26nFFS1NB4QXtmREYRQW8Q8t9UVIg7kpJcqJ TzZGvnGuBFeuExpA3jNigfDAB/cFHEGCccR5/I9uKa+XG0KYnpIrRwS3emj9q7nGXz3M N2Eiu1sv/tvAYn0VF4aQUH1yTn1R4TKFEuUSg6FWJtl0oEQuBWChf7FC4105Av5QdDHa Ij9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=5gTXuUuhidjN8OAJCE0KZCHp9X9cF3HFSJWzhdnR0N4=; b=YUCLTVy7IZ6lKhZ1cp2h/2tXSjgMI1pdIP7ZaTshd71Wz7rnCZnbqra13nKW5ZH+Ck jBbZlaXXPaw1VpIkw9A66K+1EyofxmFDFjPX6ZlIdTw/502PgjGFIAl+/m2Ol6UtVbBd Dt0Chea+RPQ99Aj9fu1cFlUELRHqVi93xFlRzdRVfC7BiFuOtT3r0E07q/bnVhDQHKEm nYACIAKGYtaLE3FzlsMjOzDBvSl8bv3y9kO2x4HudMB1S5O/KjVscOeBnJj6eHCr0POk lsBHkG6KtIPk3PvMzkN/ixh/tsYM3b0URn0HfmdRKQJgdCZ/c2dTDe33pYk2ZS9Zo1z8 4UAg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r11-20020a1709028bcb00b00188881adcd7si803723plo.550.2022.12.01.07.29.32; Thu, 01 Dec 2022 07:29:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231576AbiLAPZh (ORCPT + 99 others); Thu, 1 Dec 2022 10:25:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229658AbiLAPZf (ORCPT ); Thu, 1 Dec 2022 10:25:35 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46197AA8CC for ; Thu, 1 Dec 2022 07:25:33 -0800 (PST) Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NNKY247dfzqSn7; Thu, 1 Dec 2022 23:21:26 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 1 Dec 2022 23:25:30 +0800 From: Kefeng Wang To: Russell King , Marco Elver , CC: Alexander Potapenko , , Kefeng Wang Subject: [PATCH] ARM: kfence: only handle translation faults Date: Thu, 1 Dec 2022 23:42:58 +0800 Message-ID: <20221201154258.126144-1-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751026065136066018?= X-GMAIL-MSGID: =?utf-8?q?1751026065136066018?= This is a similar fixup like arm64 does, only handle translation faults in case of unexpected kfence report when alignment faults on ARM, see more from commit 0bb1fbffc631 ("arm64: mm: kfence: only handle translation faults"). Fixes: 75969686ec0d ("ARM: 9166/1: Support KFENCE for ARM") Signed-off-by: Kefeng Wang --- arch/arm/mm/fault.c | 18 ++++++++++++++++-- arch/arm/mm/fault.h | 9 ++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c index 46cccd6bf705..de988cba9a4b 100644 --- a/arch/arm/mm/fault.c +++ b/arch/arm/mm/fault.c @@ -105,6 +105,19 @@ static inline bool is_write_fault(unsigned int fsr) return (fsr & FSR_WRITE) && !(fsr & FSR_CM); } +static inline bool is_translation_fault(unsigned int fsr) +{ + int fs = fsr_fs(fsr); +#ifdef CONFIG_ARM_LPAE + if ((fs & FS_MMU_NOLL_MASK) == FS_TRANS_NOLL) + return true; +#else + if (fs == FS_L1_TRANS || fs == FS_L2_TRANS) + return true; +#endif + return false; +} + static void die_kernel_fault(const char *msg, struct mm_struct *mm, unsigned long addr, unsigned int fsr, struct pt_regs *regs) @@ -140,7 +153,8 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr, if (addr < PAGE_SIZE) { msg = "NULL pointer dereference"; } else { - if (kfence_handle_page_fault(addr, is_write_fault(fsr), regs)) + if (is_translation_fault(fsr) && + kfence_handle_page_fault(addr, is_write_fault(fsr), regs)) return; msg = "paging request"; @@ -208,7 +222,7 @@ static inline bool is_permission_fault(unsigned int fsr) { int fs = fsr_fs(fsr); #ifdef CONFIG_ARM_LPAE - if ((fs & FS_PERM_NOLL_MASK) == FS_PERM_NOLL) + if ((fs & FS_MMU_NOLL_MASK) == FS_PERM_NOLL) return true; #else if (fs == FS_L1_PERM || fs == FS_L2_PERM) diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h index 83b5ab32d7a4..54927ba1fa6e 100644 --- a/arch/arm/mm/fault.h +++ b/arch/arm/mm/fault.h @@ -14,8 +14,9 @@ #ifdef CONFIG_ARM_LPAE #define FSR_FS_AEA 17 +#define FS_TRANS_NOLL 0x4 #define FS_PERM_NOLL 0xC -#define FS_PERM_NOLL_MASK 0x3C +#define FS_MMU_NOLL_MASK 0x3C static inline int fsr_fs(unsigned int fsr) { @@ -23,8 +24,10 @@ static inline int fsr_fs(unsigned int fsr) } #else #define FSR_FS_AEA 22 -#define FS_L1_PERM 0xD -#define FS_L2_PERM 0xF +#define FS_L1_TRANS 0x5 +#define FS_L2_TRANS 0x7 +#define FS_L1_PERM 0xD +#define FS_L2_PERM 0xF static inline int fsr_fs(unsigned int fsr) {