From patchwork Thu Apr 10 03:57:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 14045852 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 2E66FC3601E for ; Thu, 10 Apr 2025 03:57:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D82B32800C6; Wed, 9 Apr 2025 23:57:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D33392800C4; Wed, 9 Apr 2025 23:57:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C20E92800C6; Wed, 9 Apr 2025 23:57:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id A394D2800C4 for ; Wed, 9 Apr 2025 23:57:33 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E44FE5C348 for ; Thu, 10 Apr 2025 03:57:34 +0000 (UTC) X-FDA: 83316774828.05.6A8C451 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf08.hostedemail.com (Postfix) with ESMTP id 2FFA9160009 for ; Thu, 10 Apr 2025 03:57:33 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=c+4S1w4h; spf=pass (imf08.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=quarantine) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1744257453; 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:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=CiT2WlYj/3fGyAtdbQzd4KFmS0fPVbTqImfcUooLUaU=; b=7XgloyDJ3k1JFc16L9+Uw1FUIgv3yMI/hM6m4hB+EXAzaHg/oiZB0CLiS06cxOD0DhZgW1 5FojQXAGvVyuDEKK2LAajDwx+p65eOXB/ZDdlFrE8fqBcucZSqy5tWz8/lf2PU0ku102ln Nrrc7/YE+gJu/rBLXONhA2m1FOVgIqc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1744257453; a=rsa-sha256; cv=none; b=fQZ3wmgRGyeABidwacAHbwcNwFLCRApZ6xx+c8u8ATanSBxa9sKCBaJs2HQxDaWS65zmS3 Q+sH7kUAdBhyRbm03nlxM0z6cgkS8UOj/R3dQlCBPa5JnYW0Q18ixLVpDu7kUEuWsNjuyq DKTBqKULUdIi6lpBXU1RpnNsNjsw8zk= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=c+4S1w4h; spf=pass (imf08.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=quarantine) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744257452; 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: content-transfer-encoding:content-transfer-encoding; bh=CiT2WlYj/3fGyAtdbQzd4KFmS0fPVbTqImfcUooLUaU=; b=c+4S1w4hzMb2hR5okMh9+AohTOzuoGdvTSH8f+fTkl91M/ne76pYA9R3tthRY25jffbQVF 1UzSvMZ7yr4g8ebuLVkJab+6r/mDLij2zMsOxUTq+LlQSs/g4u3V0nDdMk7WVAIikUVl82 QZPZOrXntXwzI4F/81KG7TZTcX88tT0= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-599-vLY6ecL0NHSZsop-igExNw-1; Wed, 09 Apr 2025 23:57:27 -0400 X-MC-Unique: vLY6ecL0NHSZsop-igExNw-1 X-Mimecast-MFC-AGG-ID: vLY6ecL0NHSZsop-igExNw_1744257446 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B711F1801A12; Thu, 10 Apr 2025 03:57:25 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.112.38]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3FDF519560AD; Thu, 10 Apr 2025 03:57:20 +0000 (UTC) From: Baoquan He To: linux-mm@kvack.org Cc: akpm@linux-foundation.org, david@redhat.com, osalvador@suse.de, yanjun.zhu@linux.dev, linux-kernel@vger.kernel.org, Baoquan He Subject: [PATCH v4 0/4] mm/gup: Minor fix, cleanup and improvements Date: Thu, 10 Apr 2025 11:57:13 +0800 Message-ID: <20250410035717.473207-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 2FFA9160009 X-Stat-Signature: ktfemcbwk8iza9xwtzrwjy7op7k6moyu X-HE-Tag: 1744257453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1JfxWnXv7qHfgTS7FvYQN1C9pHRAuccPTnZYq2gpw/MZjzjLWlnQFDelEghrrFHTMNUro0g8pX5hTq+eN3vQzevmTwYzv0V4IudBDVi631T+PwHa54CuPAu9wZEYb1V7/BZ+/WuLgZgxXCf3jr4w0Uj34a58XmYHLAcvsj1OOLw96ijGJIyRPtfyEUcIPC9j5mGAfXo4LLNsl+DgKkkAkAKUgTj8mgNKg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: These were made from code inspection in mm/gup.c. v3->v4: ======== - Make patch 1 to fix the code bug in fault_in_safe_writeable(); - Add patch 4 to do the code optimization to make fault_in_xxx() functions own the consistent code style; - Add reviewing tags from David and Oscar for patch 2; v2->v3: ========= - In patch 1, change to use local variable 'start' as a loop cursor in fault_in_readable() and fault_in_writeable() so that they have the consistent code style with fault_in_safe_writeable(). Doing this can avoid ugly long line caused by kinds of type cast (const char __user *). Thanks to David who suggested two ways including this one, I found this is better when changing code. - In patch2, changes to add VM_WARN_ON_ONCE() for both below chekcing because all external users of __get_user_pages() have done the checking in is_valid_gup_args() before calling __get_user_pages(). Just adding these VM_WARN_ON_ONCE() in case, e.g internal setting wrong flags in kernel code. Thanks to David for suggesting this. - (gup_flags & (FOLL_PIN | FOLL_GET)) == (FOLL_PIN | FOLL_GET)) - !!pages != !!(gup_flags & (FOLL_GET | FOLL_PIN)) - Drop - the old patch 3 of v2 because it's from misunderstanding; - the old patch 4, 5 of v2 because they have been merged into x86 tip tree by Ingo; - the old patch 7 of v2 because it has been coverred in another thread. Thanks to David for telling the thread link. - In patch 3, add reviewing tags from Oscar and David. v1->v2: ========== - In patch 1, I carelessly copied the fault_in_readable() as fault_in_writeable(). Thanks to Yanjun for pointing it out. - In patch 2, I copied the code in follow_page_pte() to __get_user_pages() directly w/o adjustment which is done but not merged to patch. That failed testing taken by lkp test robot, thanks for reporting. Baoquan He (4): mm/gup: fix wrongly calculated returned value in fault_in_safe_writeable() mm/gup: remove unneeded checking in follow_page_pte() mm/gup: remove gup_fast_pgd_leaf() and clean up the relevant codes mm/gup: clean up codes in fault_in_xxx() functions mm/gup.c | 125 +++++++++++++++---------------------------------------- 1 file changed, 34 insertions(+), 91 deletions(-)