Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3082118pxj; Mon, 7 Jun 2021 01:36:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZzyPmCE40Czn/WCkhFfJq9NgNm0ni7aEURtkI2dFH3JtI6lxl/hGRKOwDwoQmbvXB9//t X-Received: by 2002:a05:6402:845:: with SMTP id b5mr18617320edz.266.1623054977830; Mon, 07 Jun 2021 01:36:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623054977; cv=none; d=google.com; s=arc-20160816; b=1ASchvjX9RtI037wk1Q3c0TP/pT4iImI32m9BSntQlfxyEcPjX4Lm3tJgeF22tT/1g aU657ca1oJvywRYOCKeYmhnY5NW6kci6Vgqeh5b6F4EKubZOwN8MITGRSCB1Yqqyo5Dq raZUm0dMwuiTz5+wNyV273iVhzSCrqF7g6fjZtNAJwV3wVFUeEwd0dYI3G604cKJMMpm R08QqXMwItMqtVM4n9H0rk+rcvNV3owRw0HyIRPeSSMc1i/uXi+qyJ8REmIuTPh9oQ5u CXGgUZQtRm9XQdB3DHMO5Ve6P57wDyeYoyi6w+NXuRhYu4hio4H9knTqeRfonARHDvVP GFFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:references:cc :to:from:subject; bh=Bu6NpCPEgAnuXz2myTPF4Oc0zS4O67sS/XUFFGEvTR4=; b=YjyBZxkg/CHEWgb+X/ZroYaGJfrZnI8HEeNnJQ/4YOaXUQTRYpMP8yb3XsVgWncOpF rh+0sXXUhFIAqao1I2fXFj50RpQEKOF/stb15Ekp2y0M3mqI5GZ3mUKDfOJbquPQ/ROH /CXJc+3b9OxGwUXPYcNEX1shWaq+ik4NbUlE2heW2ddMEfQ2uST14G8sxac653ULU70K a2+NOcUm71Vnn7Pdh4TR/G7b9TGBGcJqqM3+cNrVmPLTHA8cBAocckG/RzFXsTLRzd39 sNyUeZYbSJQSL88FaJ5EEcbd4rAAD75jeULCa38rzDGyr8XeafPKttl7oODeg2lgUF81 UY1w== 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 m1si11979230ejj.214.2021.06.07.01.35.54; Mon, 07 Jun 2021 01:36:17 -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 S230200AbhFGIet (ORCPT + 99 others); Mon, 7 Jun 2021 04:34:49 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:4494 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229966AbhFGIes (ORCPT ); Mon, 7 Jun 2021 04:34:48 -0400 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Fz64b3jz7zZfBC; Mon, 7 Jun 2021 16:30:07 +0800 (CST) Received: from dggpemm500001.china.huawei.com (7.185.36.107) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 7 Jun 2021 16:32:56 +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.2176.2; Mon, 7 Jun 2021 16:32:55 +0800 Subject: Re: [PATCH v2 7/7] ARM: mm: Fix PXN process with LPAE feature From: Kefeng Wang To: "Russell King (Oracle)" CC: , Catalin Marinas , , Andrew Morton , Jungseung Lee References: <20210602070246.83990-1-wangkefeng.wang@huawei.com> <20210602070246.83990-8-wangkefeng.wang@huawei.com> <20210602105255.GK30436@shell.armlinux.org.uk> <62f08378-85e7-2a07-3fd0-b287047ce1b5@huawei.com> <20210602155843.GN30436@shell.armlinux.org.uk> Message-ID: Date: Mon, 7 Jun 2021 16:32:55 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Originating-IP: [10.174.177.243] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Russell,  any comments, thanks. On 2021/6/3 17:38, Kefeng Wang wrote: > > On 2021/6/2 23:58, Russell King (Oracle) wrote: >> On Wed, Jun 02, 2021 at 11:13:14PM +0800, Kefeng Wang wrote: >>>    IFSR format when using the Short-descriptor translation table format >>> >>>      Domain fault      01001            First level   01011     >>> Second level >>> >>>      Permission fault 01101            First level   01111 Second level >>> >>>    IFSR format when using the Long-descriptor translation table format >>> >>>     0011LL Permission fault. LL bits indicate levelb. >>> >>> After check the ARM spec, I think for the permission fault, we >>> should panic >>> with or without LPAE, will change to >> As I explained in one of the previous patches, the page tables that get >> used for mapping kernel space are the _tasks_ own page tables. Any new >> kernel mappings are lazily copied to the task page tables - such as >> when a module is loaded. >> >> The first time we touch a page, we could end up with a page translation >> fault. This will call do_page_fault(), and so with your proposal, >> loading a module will potentially cause a kernel panic in this case, >> probably leading to systems that panic early during userspace boot. > > Could we add some FSR_FS check, only panic when the permission fault, > eg, > > +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 int __kprobes >  do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs > *regs) >  { > @@ -255,8 +268,7 @@ do_page_fault(unsigned long addr, unsigned int > fsr, struct pt_regs *regs) > >         if (fsr & FSR_LNX_PF) { >                 vm_flags = VM_EXEC; > - > -               if (!user_mode(regs)) > +               if (is_permission_fault && !user_mode(regs)) >                         die_kernel_fault("execution of memory", >                                          mm, addr, fsr, regs); >         } > > diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h > index 9ecc2097a87a..187954b4acca 100644 > --- a/arch/arm/mm/fault.h > +++ b/arch/arm/mm/fault.h > @@ -14,6 +14,8 @@ > >  #ifdef CONFIG_ARM_LPAE >  #define FSR_FS_AEA             17 > +#define FS_PERM_NOLL           0xC > +#define FS_PERM_NOLL_MASK      0x3C > >  static inline int fsr_fs(unsigned int fsr) >  { > @@ -21,6 +23,8 @@ static inline int fsr_fs(unsigned int fsr) >  } >  #else >  #define FSR_FS_AEA             22 > +#define FS_L1_PERM             0xD > +#define FS_L2_PERM             0xF > > and suggestion or proper solution to solve the issue? > >>