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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55BB1C36010 for ; Fri, 11 Apr 2025 11:15:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7BB0A2801AF; Fri, 11 Apr 2025 07:15:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7696D28019B; Fri, 11 Apr 2025 07:15:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 62EE42801AF; Fri, 11 Apr 2025 07:15:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 474E028019B for ; Fri, 11 Apr 2025 07:15:35 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 1FDE51A1ED8 for ; Fri, 11 Apr 2025 11:15:36 +0000 (UTC) X-FDA: 83321507472.08.499CEDB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf03.hostedemail.com (Postfix) with ESMTP id 77E602000F for ; Fri, 11 Apr 2025 11:15:34 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bgJOVt75; dmarc=pass (policy=quarantine) header.from=redhat.com; spf=pass (imf03.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1744370134; a=rsa-sha256; cv=none; b=FFHc0mDINWBexgWU2CHMIHdQndPmlZs3ar/lEeacFRUbg5bY1rBzFjVUu4rk9JYau3+4qH UR7Ptr/6JYv4BH1tTDGJiQ/xd/WLPwoOHHa7IRAh6dcFjYTEsVGBPuSKPZ4iGYr2HZNNaz PI+uKy5FvXOjlbo/xj69GSLrjBXmIOM= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bgJOVt75; dmarc=pass (policy=quarantine) header.from=redhat.com; spf=pass (imf03.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1744370134; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=CA31YbKQ9t+xwlWojz0Bu12fhPmL96OxavjpM95pz3I=; b=LrMeGvVlQ0GyDhX3iGUP6Uy5HTF9OebZeRRy2xuhKXZk/fKKKf5VB03FhJcfWgRVqqzIVW AfO4oBApK/IkNfHHKERkqznACO6hKgjAMbQlftojT1YUyRK9hTgWnpbJWq994HI3KM/M8m JX8wpDMIwOuM35LBWRsbTicx/i/Mfd0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744370133; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=CA31YbKQ9t+xwlWojz0Bu12fhPmL96OxavjpM95pz3I=; b=bgJOVt754TrSqdE44keKPEfkIk6M+NMxDvddUPncnd9C8xF2s0YRfNWUBRxQqK18xAjDHv RThjPP2u7HZVfu2h83do2yvtciOXWpILnkOwol0tBb9N8e5toH3V5ElJ17ytWLcDxN5DSs CP6S7GRcwCDz8JciSduiRQiz8mlbpec= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-382-6tv7J8avPSGWnMDhrjdRhA-1; Fri, 11 Apr 2025 07:15:32 -0400 X-MC-Unique: 6tv7J8avPSGWnMDhrjdRhA-1 X-Mimecast-MFC-AGG-ID: 6tv7J8avPSGWnMDhrjdRhA_1744370131 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D5B9D195608A; Fri, 11 Apr 2025 11:15:30 +0000 (UTC) Received: from localhost (unknown [10.72.112.38]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 787E01955DCE; Fri, 11 Apr 2025 11:15:28 +0000 (UTC) Date: Fri, 11 Apr 2025 19:15:23 +0800 From: Baoquan He To: David Hildenbrand Cc: linux-mm@kvack.org, akpm@linux-foundation.org, osalvador@suse.de, yanjun.zhu@linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 4/4] mm/gup: clean up codes in fault_in_xxx() functions Message-ID: References: <20250410035717.473207-1-bhe@redhat.com> <20250410035717.473207-5-bhe@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 77E602000F X-Stat-Signature: y3g87oe9mf53if8cdq855b3q4h8h5fd3 X-Rspam-User: X-HE-Tag: 1744370134-75820 X-HE-Meta: U2FsdGVkX1/94ZbG05UGYAeWvXvdaovmBJE2kqJD7G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o8EAhfYH9GrRuBxhDItIzxQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 04/11/25 at 10:54am, David Hildenbrand wrote: > On 10.04.25 05:57, Baoquan He wrote: > > The code style in fault_in_readable() and fault_in_writable() is a > > little inconsistent with fault_in_safe_writeable(). In fault_in_readable() > > and fault_in_writable(), it uses 'uaddr' passed in as loop cursor. While > > in fault_in_safe_writeable(), local variable 'start' is used as loop > > cursor. This may mislead people when reading code or making change in > > these codes. > > > > Here define explicit loop cursor and use for loop to simplify codes in > > these three functions. These cleanup can make them be consistent in > > code style and improve readability. > > > > Signed-off-by: Baoquan He > > --- > > mm/gup.c | 65 +++++++++++++++++++++++--------------------------------- > > 1 file changed, 26 insertions(+), 39 deletions(-) > > > > diff --git a/mm/gup.c b/mm/gup.c > > index 77a5bc622567..a76bd7e90a71 100644 > > --- a/mm/gup.c > > +++ b/mm/gup.c > > @@ -2113,28 +2113,24 @@ static long __get_user_pages_locked(struct mm_struct *mm, unsigned long start, > > */ > > size_t fault_in_writeable(char __user *uaddr, size_t size) > > { > > - char __user *start = uaddr, *end; > > + const unsigned long start = (unsigned long)uaddr; > > + const unsigned long end = start + size; > > + unsigned long cur = start; > > I would initialize cur in the for loop header, makes the loop easier to > read. Both is fine to me. It's to satisfy checkpatch.sh which complains about exceeding 80 char in the line. > > > if (unlikely(size == 0)) > > return 0; > > + > > Would not add that line to keep it like fault_in_readable() below. Will remove it. > > > if (!user_write_access_begin(uaddr, size)) > > return size; > > - if (!PAGE_ALIGNED(uaddr)) { > > - unsafe_put_user(0, uaddr, out); > > - uaddr = (char __user *)PAGE_ALIGN((unsigned long)uaddr); > > - } > > - end = (char __user *)PAGE_ALIGN((unsigned long)start + size); > > - if (unlikely(end < start)) > > - end = NULL; > > - while (uaddr != end) { > > - unsafe_put_user(0, uaddr, out); > > - uaddr += PAGE_SIZE; > > - } > > + > > + /* Stop once we overflow to 0. */ > > + for (; cur && cur < end; cur = PAGE_ALIGN_DOWN(cur + PAGE_SIZE)) > > + unsafe_put_user(0, (char __user *)cur, out); > > Staring at fault_in_safe_writeable(), we could also do > > /* Stop once we overflow to 0. */ > end = PAGE_ALIGN(end) > if (start < end) > end = 0; > > for (cur = start; cur != end; cur = PAGE_ALIGN_DOWN(cur + PAGE_SIZE)) > unsafe_put_user(0, (char __user *)cur, out); > > Essentially, removing the "cur" check from the loop condition. Not sure if > that is better. The current code is simpler. Your now saying may save the CPU execution instructions a little bit. Both is fine to me. I don't have strong preference, I can make v4 to address these concerns if decided. Thanks for careful checking. > > In any case, if all functions later look similar and clearer it's a big win. Agreed.