Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp500971pxb; Wed, 15 Sep 2021 07:00:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5X8ueP8Cmi5VTYbW2U5/W+WCA+Rl3bpTpc8hpZbVCVebgpT8WL9XLfv3wdH4LGGKwWDwY X-Received: by 2002:a17:906:6547:: with SMTP id u7mr142918ejn.544.1631714403147; Wed, 15 Sep 2021 07:00:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631714403; cv=none; d=google.com; s=arc-20160816; b=M4PIY0PpPmCS8iopBDAC0aoFXO8b0vVxMQF3sUwJA8X0WZee5LBqAluSOBNfEAxgyU 8XYiHKB/k47Ez/XWMUWE9VZyoa5PKTj2ofKaQ41lf6cOH2WFJtHFfwy08OLnqPOCGi7r wo6mpPf0Ndv+lRHX/XoR506nhXZB2w19tPv6naRTsNAxsDErId4CTS3PFAQJDTxFrK2H O9EewjoMW0lmuhPfBf201IU0M4JXpsmf2O3xn7vlrTKIwMNBynBvkk2DSMLCslo5zL7W vyOboOhj7MZhCzKZOvP/C3cBTS0FJD/+6E+1C4byfbbkanR8rJeBlHg8ksVZpz9F9Y8U evHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=Zxs0ZNhAkVV515E9n5pzzMri9IibOFXH4ZtwDojnOyg=; b=AUzMWZeG9pKuO3qyvZqVBHIR1NoM68faJ2NFe/Gh1F8Nb1yYV4SGQjY1fr62e2Y5d9 BrQ+bU2zg1bW87yIjfu6F1Zqq2TD9OIihDu/3CRUopFbfH+7mgRv4DIDq6p84HKmDXwD g4UQSXHrrJYYy1TCycyTH0k+jFMOr5s5cmR2Yi7pITzVYGx3LU78hr89vrG5x2HRrB7Q IKeBDqqlD80tP88QvkQCL8ibOajQ8ubNFh8MjAgF8Co6WkkBvUF7iPuuC7bnfNZIe1l2 gpBThBSeMOx38k6+6RVaKmzrhN3FapTflhyvVcE/S2HouVewqJiJMB6VZYGHVuhHFGDf kaKw== 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=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p14si51694ejn.419.2021.09.15.06.59.35; Wed, 15 Sep 2021 07:00:03 -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=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238025AbhION62 (ORCPT + 99 others); Wed, 15 Sep 2021 09:58:28 -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 >>