Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2527745pxb; Fri, 17 Sep 2021 11:50:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwkN2a1pEIhnPxs8VB6/LZaaK/cAAe4Cg+EG5DbgLQzjWkFATBAFGXGkZVV1lU4ZxMAAHs X-Received: by 2002:aa7:db85:: with SMTP id u5mr14156161edt.234.1631904646837; Fri, 17 Sep 2021 11:50:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631904646; cv=none; d=google.com; s=arc-20160816; b=ELf2+envjTHKK8a7az4TBRWp6athX3Q11FD+1ia7NvK9no64gnk0rcipsEsUw/1wS6 BNwEWDlhnlhZmyKGnsvTobCEgJCFliG9eyRkm9V+IHskyj5tHJfZm3FzQRkPHt4r4dip 7UHb22VeyXPBC9h1l7+lzAi2rPrzaVh+rKfrhIdom4fl7jwZSb4XbZjnse2RfDtcoJGj OGNQmuvqji5rSqsuv+adiid1MCq/Mpa0JRtCDFRfFSd3UgquXscaW1qvXTyD2KI9Qrxh qSmYFp4TTg8+8/V9eB/Al1CoHTCngpZAij9q+HGZc1VuFuC4voSjsKek/+2qk2a6fUOk ez9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=2Qrxh8voHCpd+DHlrJ+3VG7oVZL9bHStkPdTBvLvaLw=; b=RFMS68SoGTT9z0WLuW2+4d8o5l24oi7GMVuqiPrv9pkW3QhcwUiOPT15XxCc+7P7fZ iJbpH+FkvOPx0aA4LR4WKV9z5/M0NNHnZSDi7UzFyAAEyywA4gX6kbemhm838X6yM0sp v7RPj+GRTK9lL0bN2GWvXxGSs2KlktTlaZ5uX1TabEFCLFY9hbn6IYqLsqoXVBVcFhCw vJkBatoOkeVknYlWU6wkgsAtSfW5KKwDXaeUYOULuufAbItInggNFPXw/+KIMSjrgLKq aEKhqsJbekj+IYrzgVlcs1d+DB6Pdg6JEYTEy6Lt1sF18NWVm6HKf3+4XxCq84fQ5OZs t/7g== 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 m15si7666584ejn.484.2021.09.17.11.49.47; Fri, 17 Sep 2021 11:50:46 -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 S241367AbhIQJiC (ORCPT + 99 others); Fri, 17 Sep 2021 05:38:02 -0400 Received: from foss.arm.com ([217.140.110.172]:50496 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241198AbhIQJh7 (ORCPT ); Fri, 17 Sep 2021 05:37:59 -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 92122101E; Fri, 17 Sep 2021 02:36:36 -0700 (PDT) Received: from C02TD0UTHF1T.local (unknown [10.57.20.241]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 428D43F59C; Fri, 17 Sep 2021 02:36:35 -0700 (PDT) Date: Fri, 17 Sep 2021 10:36:28 +0100 From: Mark Rutland To: Amit Daniel Kachhap Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Vincenzo Frascino , Kevin Brodsky , Catalin Marinas , Will Deacon Subject: Re: [PATCH v2] arm64/traps: Avoid unnecessary kernel/user pointer conversion Message-ID: <20210917093628.GB75427@C02TD0UTHF1T.local> References: <20210917055811.22341-1-amit.kachhap@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210917055811.22341-1-amit.kachhap@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 17, 2021 at 11:28:11AM +0530, Amit Daniel Kachhap wrote: > Annotating a pointer from kernel to __user and then back again requires > an extra __force annotation to silent sparse warning. In call_undef_hook() > this unnecessary complexity can be avoided by modifying the intermediate > user pointer to unsigned long. > > This way there is no inter-changeable use of user and kernel pointers > and the code is consistent. > > Note: This patch adds no functional changes to code. > > Cc: Catalin Marinas > Cc: Will Deacon > Signed-off-by: Amit Daniel Kachhap I like that this clarifies that `pc` is not necessarily a user pointer, and this makes the relevant lines shorter and eaier to read, so FWIW: Acked-by: Mark Rutland Thanks, Mark. > --- > Changes from v1: > * Instead of directly using instruction_pointer() for kernel pointers, > modified the pc type from void __user * to unsigned long as suggested > by Mark Rutland. > > arch/arm64/kernel/traps.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c > index b03e383d944a..09236751283e 100644 > --- a/arch/arm64/kernel/traps.c > +++ b/arch/arm64/kernel/traps.c > @@ -400,11 +400,11 @@ static int call_undef_hook(struct pt_regs *regs) > unsigned long flags; > u32 instr; > int (*fn)(struct pt_regs *regs, u32 instr) = NULL; > - void __user *pc = (void __user *)instruction_pointer(regs); > + unsigned long pc = instruction_pointer(regs); > > if (!user_mode(regs)) { > __le32 instr_le; > - if (get_kernel_nofault(instr_le, (__force __le32 *)pc)) > + if (get_kernel_nofault(instr_le, (__le32 *)pc)) > goto exit; > instr = le32_to_cpu(instr_le); > } else if (compat_thumb_mode(regs)) { > -- > 2.17.1 >