From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.9 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C9C3C433F5 for ; Wed, 15 Sep 2021 13:57:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7DDAD61263 for ; Wed, 15 Sep 2021 13:57:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237938AbhION63 (ORCPT ); Wed, 15 Sep 2021 09:58:29 -0400 Received: from foss.arm.com ([217.140.110.172]:55828 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237842AbhION6T (ORCPT ); Wed, 15 Sep 2021 09:58:19 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4F2236D; Wed, 15 Sep 2021 06:57:00 -0700 (PDT) Received: from [10.163.44.48] (unknown [10.163.44.48]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 281F43F719; Wed, 15 Sep 2021 06:56:57 -0700 (PDT) Subject: Re: [PATCH] arm64/traps: Avoid unnecessary kernel/user pointer conversion To: Mark Rutland Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Vincenzo Frascino , Catalin Marinas , Will Deacon References: <20210914152742.27047-1-amit.kachhap@arm.com> <20210914160056.GA35239@C02TD0UTHF1T.local> From: Amit Kachhap Message-ID: <6662988b-b891-b6b0-cd7a-bd7f661fc737@arm.com> Date: Wed, 15 Sep 2021 19:26:55 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <20210914160056.GA35239@C02TD0UTHF1T.local> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 9/14/21 9:30 PM, Mark Rutland wrote: > On Tue, Sep 14, 2021 at 08:57:42PM +0530, Amit Daniel Kachhap wrote: >> Annotating a pointer from kernel to __user and then back again might >> confuse sparse. In call_undef_hook() it can be avoided by not using the >> intermediate user pointer variable. > > When you say "might confuse sparse", does it complain today? If so, can > you include an example of what goes wrong? No it does not give warning. The __force option silences the warning. My idea is to remove the unwanted __force annotations and not mix user and kernel pointers. > >> Note: This patch adds no functional changes to code. >> >> Cc: Catalin Marinas >> Cc: Will Deacon >> Signed-off-by: Amit Daniel Kachhap >> --- >> arch/arm64/kernel/traps.c | 3 ++- >> 1 file changed, 2 insertions(+), 1 deletion(-) >> >> diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c >> index b03e383d944a..357d10a8bbf5 100644 >> --- a/arch/arm64/kernel/traps.c >> +++ b/arch/arm64/kernel/traps.c >> @@ -404,7 +404,8 @@ static int call_undef_hook(struct pt_regs *regs) >> >> if (!user_mode(regs)) { >> __le32 instr_le; >> - if (get_kernel_nofault(instr_le, (__force __le32 *)pc)) >> + if (get_kernel_nofault(instr_le, >> + (__le32 *)instruction_pointer(regs))) > > Can we make `pc` an unsigned long, instead? I think it can be done. > > It'd be nice to handle all three cases consistently, even if that means > adding __force to the two user cases. Agree with your suggestion. Even in the 2 user cases, __force may not be needed as the typecast will be from from unsigned long to user pointer. BR, Amit > > Thanks, > Mark. > >> goto exit; >> instr = le32_to_cpu(instr_le); >> } else if (compat_thumb_mode(regs)) { >> -- >> 2.17.1 >>