Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2360602rwb; Mon, 19 Sep 2022 04:06:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM67/aewGABRznodUJUKmOLR8j8g3wa/USl6Ag3kYtTFueosETZfkADgUCwseJO5Pac3Hf5S X-Received: by 2002:a17:907:9729:b0:77e:af0c:84ca with SMTP id jg41-20020a170907972900b0077eaf0c84camr12257742ejc.629.1663585596781; Mon, 19 Sep 2022 04:06:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663585596; cv=none; d=google.com; s=arc-20160816; b=ucIN+kR3KznvlKe7zBxcCFPLoFPrdzbJD120C3rKs2wjPvwku1pFaW5J9OjhJs4NkM XRxIQX6FJhASpZje6VJa0SutHhj3llyCJ9A94pE2VFfHLlj+WI5DlRIB/y4qbHpkOvC1 mk2RXqkW7SaRgbEaHX3EbJ7rBMLGTS2MwUMbsY17rzONneF227FA78XRsBi+oWjfATMF Fjl/xqlii6XmVjMUqO0gBmkSgZ3IaWuteJ8HZ5Sj2K8apJFSi4+EUXCVC4mTuV3DeNYh MiLok8LoGeNxt5raN2aBj3ezYjki/iZUcCRmCi4l3KDGw2fwZv7p8lcgUshxuhW6T1qG LasQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=D6S2ri6n4xHsIr6NotF3mBYQx/P6/v+D8uDTpkvb8VA=; b=q5cR/wxv9Wj9ovPlQAkxdMxjecmdsgwWB20sml7KFSseTh3cqwa5NOo9yDakwx8S86 creP4g81eKVcrwJWEflyVJNBrd281bDs8Tl7SJQRzYGnJz9rRLhSx4bZ5+k61HCmH3Db E2bXtHEUtVqZ3QntxFG5sCqLTve47JsrCfj22Fvfky0TmwO8m4FXjQ7jrMqb5OJlOdnh v8zqB2ZSnwXsGSiI6IDG/aVPPaHNnX7orYjmHS0miW0sjJQRMBw/nqKO54f8mtmJvG93 lrXlu+Ohn1oeDMeEV8/LZmEXkjKKvMGINkeIeVFsOPlTqPlcqJ+HuwhL66Bequ6wq9Br hv/Q== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g21-20020a170906539500b0073d92cad668si19679047ejo.664.2022.09.19.04.06.11; Mon, 19 Sep 2022 04:06:36 -0700 (PDT) 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 S230034AbiISKqc (ORCPT + 99 others); Mon, 19 Sep 2022 06:46:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229812AbiISKqC (ORCPT ); Mon, 19 Sep 2022 06:46:02 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AA2C6595 for ; Mon, 19 Sep 2022 03:29:03 -0700 (PDT) Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MWLQr0bnZzQj7k; Mon, 19 Sep 2022 18:25:08 +0800 (CST) Received: from dggpemm500001.china.huawei.com (7.185.36.107) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 19 Sep 2022 18:29:00 +0800 Received: from [10.174.177.243] (10.174.177.243) 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; Mon, 19 Sep 2022 18:29:00 +0800 Message-ID: <269c06a8-3885-dbcf-a26e-e7c2312d435d@huawei.com> Date: Mon, 19 Sep 2022 18:29:00 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [PATCH] ARM: mm: Provide better fault message for permission fault Content-Language: en-US To: Russell King CC: , References: <20220919051130.1339-1-wangkefeng.wang@huawei.com> From: Kefeng Wang In-Reply-To: <20220919051130.1339-1-wangkefeng.wang@huawei.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.243] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, 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 Sorry, is_permission_fault() could be used if CONFIG_MMU disabled, will resend. On 2022/9/19 13:11, Kefeng Wang wrote: > If there is a permission fault in __do_kernel_fault(), we only > print the generic "paging request" message which don't show > read, write or execute information, let's provide better fault > message for them. > > Signed-off-by: Kefeng Wang > --- > arch/arm/mm/fault.c | 35 +++++++++++++++++++++-------------- > 1 file changed, 21 insertions(+), 14 deletions(-) > > diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c > index 46cccd6bf705..d1b848f0f7ed 100644 > --- a/arch/arm/mm/fault.c > +++ b/arch/arm/mm/fault.c > @@ -95,6 +95,19 @@ void show_pte(const char *lvl, struct mm_struct *mm, unsigned long addr) > > pr_cont("\n"); > } > + > +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) > + return true; > +#else > + if (fs == FS_L1_PERM || fs == FS_L2_PERM) > + return true; > +#endif > + return false; > +} > #else /* CONFIG_MMU */ > void show_pte(const char *lvl, struct mm_struct *mm, unsigned long addr) > { } > @@ -137,7 +150,14 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr, > /* > * No handler, we'll have to terminate things with extreme prejudice. > */ > - if (addr < PAGE_SIZE) { > + if (is_permission_fault(fsr)) { > + if (fsr & FSR_WRITE) > + msg = "write to read-only memory"; > + else if (fsr & FSR_LNX_PF) > + msg = "execute from non-executable memory"; > + else > + msg = "read from unreadable memory"; > + } else if (addr < PAGE_SIZE) { > msg = "NULL pointer dereference"; > } else { > if (kfence_handle_page_fault(addr, is_write_fault(fsr), regs)) > @@ -204,19 +224,6 @@ void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs) > #define VM_FAULT_BADMAP ((__force vm_fault_t)0x010000) > #define VM_FAULT_BADACCESS ((__force vm_fault_t)0x020000) > > -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) > - return true; > -#else > - if (fs == FS_L1_PERM || fs == FS_L2_PERM) > - return true; > -#endif > - return false; > -} > - > static vm_fault_t __kprobes > __do_page_fault(struct mm_struct *mm, unsigned long addr, unsigned int flags, > unsigned long vma_flags, struct pt_regs *regs)