From patchwork Mon Mar 31 08:13:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 14033788 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 C5F5EC36011 for ; Mon, 31 Mar 2025 16:29:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E5231280003; Mon, 31 Mar 2025 12:29:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E01C2280001; Mon, 31 Mar 2025 12:29:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CCA0E280003; Mon, 31 Mar 2025 12:29:23 -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 A87F4280001 for ; Mon, 31 Mar 2025 12:29:23 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A0844C0CD2 for ; Mon, 31 Mar 2025 08:13:51 +0000 (UTC) X-FDA: 83281132662.16.13DCCF0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf26.hostedemail.com (Postfix) with ESMTP id BEE6C14000E for ; Mon, 31 Mar 2025 08:13:49 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="PVe1/g9D"; spf=pass (imf26.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=1743408829; 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:in-reply-to:references:references:dkim-signature; bh=w0gf9RGsw/MtUT85PnmYum3vQIHTxmH593ortJMGyJU=; b=goZ8M1V9JWt+Rk07TpDtRx9YiARxkdRKuEvWaO8Wj7ILFNHBOAABWGSmnVvFzGlwpWElDZ gAG/KdaQ4g3cXCfHQXNlXaJ2M5YUAn37cMXyXmsXNMtiHQ4eK+SN/O0SwpOUgPhIVmGNYR DEskxKBh8abIsTzyj45T1SrqtABXGjE= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="PVe1/g9D"; spf=pass (imf26.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743408829; a=rsa-sha256; cv=none; b=EmfnFqoX/IVkk3PKSUvN5C4mgC7LeAX8HDR14LNkkVxniCh13CCQ81H3nCuUcacgmfGt9j mi6z63t+YGGC6ns4qtMNfRSMDPyS9iB4KDnS0AqgLKcp0P1h5RkJoaI0dqpP0u6g0Zyvy4 eftYLdD881dCgorsHF6rdl3iWhjCyW0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1743408829; 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: in-reply-to:in-reply-to:references:references; bh=w0gf9RGsw/MtUT85PnmYum3vQIHTxmH593ortJMGyJU=; b=PVe1/g9DwaNvsyUwWvNp709Brrnckkzd3j9CK0J7mZd5Lwhlq7ASf0nP2BlLbu54hdTfT7 BqJn88fHqBgv8CRiu+gv7SOMIZ6OuIkA0be3ah2lT6r9yc6lIM+qAYwP+8AMDxlR8f22CT L1SDYqAvAZDWvY8dodZcLu7CpUT5Tdg= Received: from mx-prod-mc-06.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-371-Vy8rpVrTPkeCly9O0-hLPQ-1; Mon, 31 Mar 2025 04:13:45 -0400 X-MC-Unique: Vy8rpVrTPkeCly9O0-hLPQ-1 X-Mimecast-MFC-AGG-ID: Vy8rpVrTPkeCly9O0-hLPQ_1743408824 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 34A251800258; Mon, 31 Mar 2025 08:13:43 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.112.9]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 07CC51955BEF; Mon, 31 Mar 2025 08:13:39 +0000 (UTC) From: Baoquan He To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, yanjun.zhu@linux.dev, Baoquan He Subject: [PATCH v2 2/7] mm/gup: check if both GUP_GET and GUP_PIN are set in __get_user_pages() earlier Date: Mon, 31 Mar 2025 16:13:22 +0800 Message-ID: <20250331081327.256412-3-bhe@redhat.com> In-Reply-To: <20250331081327.256412-1-bhe@redhat.com> References: <20250331081327.256412-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Rspamd-Que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GI0DmRKz51ILD9YEBu vQNurdpS 0Hwkz9UNT6xVZ1UnEEhe0/wnf2y634HwmK2x9VP1lsrWpka1d9n3ZD2agh4kyIn6/kHb3Y3/io489JlHOymgBnIiogelTcFGNRLpyG2RxbPaYJjABKLSOuWM9Q2aBCHVBpcSXvSJccGOzFIwTKu2buweDh1fBgI06kQZHGdv1PRFh94+fj20M1Ase0UTPX5OwalWIZYb/ODdlwEnbZOyPKsOtCYXsy+z5f549oPZjb6iKPLATUIDUjs3B/Qrfcj/j3P8P/9+MYPOZSlLHHMz4K2Le4osxZ95WPyKETZWx0iR+NgC/qQR1WaBtu6VdLFRA8Gydu+LElJq0cA2bNJ9C0Y3D4ndz637jX45uH3GyqV18Nn1/w0vRHrZSjA== 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: In __get_user_pages(), it will traverse page table and take a reference to the page the given user address corresponds to if GUP_GET or GUP_PIN is et. However, it's not supported both GUP_GET and GUP_PIN are set. This check should be done earlier, but not doing it till entering into follow_page_pte() and failed. Here move the checking to the beginning of __get_user_pages(). Signed-off-by: Baoquan He --- v1->v2: - Fix code bug caused by copy-and-paste error, this is reported by lkp test robot. mm/gup.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 73777b1de679..f9bce14ed3cd 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -847,11 +847,6 @@ static struct page *follow_page_pte(struct vm_area_struct *vma, pte_t *ptep, pte; int ret; - /* FOLL_GET and FOLL_PIN are mutually exclusive. */ - if (WARN_ON_ONCE((flags & (FOLL_PIN | FOLL_GET)) == - (FOLL_PIN | FOLL_GET))) - return ERR_PTR(-EINVAL); - ptep = pte_offset_map_lock(mm, pmd, address, &ptl); if (!ptep) return no_page_table(vma, flags, address); @@ -1434,6 +1429,11 @@ static long __get_user_pages(struct mm_struct *mm, VM_BUG_ON(!!pages != !!(gup_flags & (FOLL_GET | FOLL_PIN))); + /* FOLL_GET and FOLL_PIN are mutually exclusive. */ + if (WARN_ON_ONCE((gup_flags & (FOLL_PIN | FOLL_GET)) == + (FOLL_PIN | FOLL_GET))) + return -EINVAL; + do { struct page *page; unsigned int page_increm;