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=-10.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING, 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 BF183C433E2 for ; Tue, 8 Sep 2020 06:15:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 938612078B for ; Tue, 8 Sep 2020 06:15:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728790AbgIHGPc (ORCPT ); Tue, 8 Sep 2020 02:15:32 -0400 Received: from verein.lst.de ([213.95.11.211]:51452 "EHLO verein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728775AbgIHGPb (ORCPT ); Tue, 8 Sep 2020 02:15:31 -0400 Received: by verein.lst.de (Postfix, from userid 2407) id BA83B68AFE; Tue, 8 Sep 2020 08:15:28 +0200 (CEST) Date: Tue, 8 Sep 2020 08:15:28 +0200 From: Christoph Hellwig To: Arnd Bergmann Cc: Christoph Hellwig , Russell King , Alexander Viro , kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linus.walleij@linaro.org, Russell King , Andrew Morton , Dmitry Safonov <0x7f454c46@gmail.com>, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/9] ARM: traps: use get_kernel_nofault instead of set_fs() Message-ID: <20200908061528.GB13930@lst.de> References: <20200907153701.2981205-1-arnd@arndb.de> <20200907153701.2981205-3-arnd@arndb.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200907153701.2981205-3-arnd@arndb.de> User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-arch-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arch@vger.kernel.org > +static void dump_mem(const char *, const char *, unsigned long, unsigned long, bool kernel_mode); This adds a pointlessly long line. And looking at the code I don't see why the argument is even needed. dump_mem() currently does an unconditional set_fs(KERNEL_DS), so it should always use get_kernel_nofault. > +static void dump_instr(const char *lvl, struct pt_regs *regs) > { > unsigned long addr = instruction_pointer(regs); > const int thumb = thumb_mode(regs); > @@ -173,10 +169,20 @@ static void __dump_instr(const char *lvl, struct pt_regs *regs) > for (i = -4; i < 1 + !!thumb; i++) { > unsigned int val, bad; > > - if (thumb) > - bad = get_user(val, &((u16 *)addr)[i]); > - else > - bad = get_user(val, &((u32 *)addr)[i]); > + if (!user_mode(regs)) { > + if (thumb) { > + u16 val16; > + bad = get_kernel_nofault(val16, &((u16 *)addr)[i]); > + val = val16; > + } else { > + bad = get_kernel_nofault(val, &((u32 *)addr)[i]); > + } > + } else { > + if (thumb) > + bad = get_user(val, &((u16 *)addr)[i]); > + else > + bad = get_user(val, &((u32 *)addr)[i]); > + } When I looked at this earlier I just added a little helper to make this a little easier to read. Here is my patch from an old tree: http://git.infradead.org/users/hch/misc.git/commitdiff/67413030ccb7a64a7eb828e13ff0795f4eadfeb7 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=-10.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,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 5CC7EC433E2 for ; Tue, 8 Sep 2020 06:17:03 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1191B2078B for ; Tue, 8 Sep 2020 06:17:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="bIjSvf+W" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1191B2078B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=kCW8nICfvPkwRcAQbJ88cCxNdBj7qoImjXWKz0vYKGs=; b=bIjSvf+WPjQVD/pjssQvX2Xrm ydOo4Fl0UdTw3bmKh+ecz+3bQH/ZdC4Pr6dIVpOSIy70WeQA2KoQTIMv9nJOrVUlbQvW22bZ2SbUD maLnRXr5ypNOLERrUf3KzOnJ2v8+df15zC5vJlTt8MaXmpKwZi3cpiiF3zSOBZLtbHh5VQQeOTBEB Vw5J6eCE6yUvhh13kxEb9n5qXWyzG8cVBjl4OxdwHDNT2dXoUhv5oz0igBUqQJ9A1ck1MYMiU08Hh HO06wHpaS0pFypyymwWXW4IphIXK+HZiuspPFB7RsUOQknZ5vOMXWpD5jL8Ht/bpMdstcNCqN5/bY 1z/HKo30w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kFWuk-0000jl-R5; Tue, 08 Sep 2020 06:15:34 +0000 Received: from verein.lst.de ([213.95.11.211]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kFWuh-0000jC-Gj for linux-arm-kernel@lists.infradead.org; Tue, 08 Sep 2020 06:15:32 +0000 Received: by verein.lst.de (Postfix, from userid 2407) id BA83B68AFE; Tue, 8 Sep 2020 08:15:28 +0200 (CEST) Date: Tue, 8 Sep 2020 08:15:28 +0200 From: Christoph Hellwig To: Arnd Bergmann Subject: Re: [PATCH 2/9] ARM: traps: use get_kernel_nofault instead of set_fs() Message-ID: <20200908061528.GB13930@lst.de> References: <20200907153701.2981205-1-arnd@arndb.de> <20200907153701.2981205-3-arnd@arndb.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200907153701.2981205-3-arnd@arndb.de> User-Agent: Mutt/1.5.17 (2007-11-01) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200908_021531_666552_5A7FB515 X-CRM114-Status: GOOD ( 17.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, Dmitry Safonov <0x7f454c46@gmail.com>, linus.walleij@linaro.org, kernel@vger.kernel.org, Russell King , linux-kernel@vger.kernel.org, Russell King , Andrew Morton , Christoph Hellwig , linux-arm-kernel@lists.infradead.org, Alexander Viro Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org > +static void dump_mem(const char *, const char *, unsigned long, unsigned long, bool kernel_mode); This adds a pointlessly long line. And looking at the code I don't see why the argument is even needed. dump_mem() currently does an unconditional set_fs(KERNEL_DS), so it should always use get_kernel_nofault. > +static void dump_instr(const char *lvl, struct pt_regs *regs) > { > unsigned long addr = instruction_pointer(regs); > const int thumb = thumb_mode(regs); > @@ -173,10 +169,20 @@ static void __dump_instr(const char *lvl, struct pt_regs *regs) > for (i = -4; i < 1 + !!thumb; i++) { > unsigned int val, bad; > > - if (thumb) > - bad = get_user(val, &((u16 *)addr)[i]); > - else > - bad = get_user(val, &((u32 *)addr)[i]); > + if (!user_mode(regs)) { > + if (thumb) { > + u16 val16; > + bad = get_kernel_nofault(val16, &((u16 *)addr)[i]); > + val = val16; > + } else { > + bad = get_kernel_nofault(val, &((u32 *)addr)[i]); > + } > + } else { > + if (thumb) > + bad = get_user(val, &((u16 *)addr)[i]); > + else > + bad = get_user(val, &((u32 *)addr)[i]); > + } When I looked at this earlier I just added a little helper to make this a little easier to read. Here is my patch from an old tree: http://git.infradead.org/users/hch/misc.git/commitdiff/67413030ccb7a64a7eb828e13ff0795f4eadfeb7 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel