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 3003CC369AB for ; Sun, 13 Apr 2025 01:07:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 46AA568004D; Sat, 12 Apr 2025 21:07:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4196A680041; Sat, 12 Apr 2025 21:07:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2E17068004D; Sat, 12 Apr 2025 21:07:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 10D8C680041 for ; Sat, 12 Apr 2025 21:07:47 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3640E161B07 for ; Sun, 13 Apr 2025 01:07:47 +0000 (UTC) X-FDA: 83327233374.09.FE2EE03 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf27.hostedemail.com (Postfix) with ESMTP id 60D3E40004 for ; Sun, 13 Apr 2025 01:07:45 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aqWisnHG; dmarc=pass (policy=quarantine) header.from=redhat.com; spf=pass (imf27.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.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=1744506465; 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=03+uly0NYJpu0OTtZ8HRkaQGJ563a6TC/2I8HSCmiVg=; b=bOHQKMnN/b+MXaiWXliEjw5/5c9+pfBIyFIZ0/7BJ8KI1fEoLCcdPpAAeGl4MVeHN8veAJ /deRLQEHD4ZjVklBh8EkF3mTr+WhJ42lh26As+72RZPWxEM7iB1LoGGhsW8eAFNeooL9tu uXt0SubFn7JHNQ8KVYMN/IABMyIGot4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1744506465; a=rsa-sha256; cv=none; b=tav/XBQN3n7sEOfaBasihTyKqyq0gSEjECv5m5CRbBbCoDPLjVevFCkv8SUmK7S1sWti/w 7qiw8ij92R8IBu962xiweX+DfckJARSdJ49vXPE6l1AkeVibaB7tuwWO4pqC+jI+R4S+es Oc6Hcpqs9ThnGYzsfrPfGUfr1S+g4Kg= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aqWisnHG; dmarc=pass (policy=quarantine) header.from=redhat.com; spf=pass (imf27.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744506464; 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=03+uly0NYJpu0OTtZ8HRkaQGJ563a6TC/2I8HSCmiVg=; b=aqWisnHGp6X7+Ed5ena7J6cfF+woSNu5P1S3cB/N3A6i5RJJhqWxpqsHA83EUy4PokBNJI Tp2ng5jZMv5gpy0KKnTs5QHd4A7X7dtkAuhdO4p/LB9BzRUxcX6KLgyLGkdPjJ7Py9jv9x EfDxp2J3gs/rG0BXEXNR4JRvADHvbCY= 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-467-9u9wwuz_PqWbNX-TvH21fw-1; Sat, 12 Apr 2025 21:07:38 -0400 X-MC-Unique: 9u9wwuz_PqWbNX-TvH21fw-1 X-Mimecast-MFC-AGG-ID: 9u9wwuz_PqWbNX-TvH21fw_1744506457 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 1C4F51956087; Sun, 13 Apr 2025 01:07:37 +0000 (UTC) Received: from localhost (unknown [10.72.112.43]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 67C4D3001D15; Sun, 13 Apr 2025 01:07:33 +0000 (UTC) Date: Sun, 13 Apr 2025 09:07:29 +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> <332ce477-59f6-47f9-9687-10b642b86230@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <332ce477-59f6-47f9-9687-10b642b86230@redhat.com> X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 60D3E40004 X-Stat-Signature: 3p7uhmndifxx1ywnrszyffnzu986dgou X-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d2VXViKjYQORBDWzpAYhxgU3F9ECRbAYxOXvCrLuQYgBqc0w2hSMtSyQCJgxYYEpk1q2RbSOtUQznJmNTyUwdNCYdjhaDEDYAI04nP7ueMa1Q+hNVNDfH781tZ7hq7FJecOHjZ6o/ngvYBaD3qD9fmta8Pgf7ss0tns1tVERXP8sDrYV8JjTRI0hbisGb8svEE6AgK4yOOIOfCMRPHEvMQoR6cdXJ1O8msbJ+paG77TzBb84zrKAhTEqETuNSBEugKy+ea8i3D1M5YH7OuUUnYNbX0jn84QFUuTH5uHRCtvpnjsrtAMX0/FqvOtk9UG4rezdKEU8Jv7ytsRUaS6z2LoQG9Ega9wTBrRN/0OvkSxRnV9MgYjR+G1DoC7AIWnZD1vVBUrPqrUF6LYwOyxlwfL2/ar5dNUp0PC/sVAtXUB7RlXrDcBoCvJJ9dLQw 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 01:41pm, David Hildenbrand wrote: > On 11.04.25 13:15, Baoquan He wrote: > > 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. > > Did checkpatch.sh actually complain? You might be happy to learn that the > new limit is 100. :) That's great to know. I never noticed this and always wrap via vim's indication. > > [...] > > > > /* 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. > > Whatever you prefer! Great, will make change in v4. Thx.