From patchwork Thu Apr 10 03:57:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 14045854 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 EE37BC369A2 for ; Thu, 10 Apr 2025 03:57:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B4D4D2800C9; Wed, 9 Apr 2025 23:57:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AFCE22800C8; Wed, 9 Apr 2025 23:57:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 99E7B2800C9; Wed, 9 Apr 2025 23:57:41 -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 76DE62800C8 for ; Wed, 9 Apr 2025 23:57:41 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B5D86161A58 for ; Thu, 10 Apr 2025 03:57:42 +0000 (UTC) X-FDA: 83316775164.26.2FB5358 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf19.hostedemail.com (Postfix) with ESMTP id 2CB8D1A0004 for ; Thu, 10 Apr 2025 03:57:41 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SvYQ6EBx; dmarc=pass (policy=quarantine) header.from=redhat.com; spf=pass (imf19.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=1744257461; a=rsa-sha256; cv=none; b=iLPg3En4bte6hfIcn0ILhT+qZ3cDGuTK969H+aEuzJ0HAgDE98mcRT7p/V9uzKkvIo6UyO qHQyGw5zpf6Br4aPU8I+2qwf735Qd5a5TCrL0EEWhM2iQFTtFzw6cZOioInysBRx+2ESPg 5dpbbHaQ+zBVfLdF4CEaIlEXHg2kMNs= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SvYQ6EBx; dmarc=pass (policy=quarantine) header.from=redhat.com; spf=pass (imf19.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=1744257461; 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=3pd14nYhYMgdjkQtwmpN+tA62d+FdLUKaQa7vusgjMQ=; b=eLplJK2Ud85rVFvSntfxc3q8j/OZHr41O6O+kxZorSQqnFDZrHieAbVmQzvWrKqhTQq52I NBIIXLVY7GPieGyds4fIE3KkSysuJcKKuTmctW8mCHDCzo/dZPGwMSu4vIbG0hIcdbOavX Z2td/++eXL1lD22Lz3ZJ+MZpnCxHOHo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744257460; 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=3pd14nYhYMgdjkQtwmpN+tA62d+FdLUKaQa7vusgjMQ=; b=SvYQ6EBxPbjUynpoL2JTCJPoEaC+0jB5NzcZK1TPiaYQaOn+Sc09vZU1UWfSmfZlJLqTPh w2Qwi355t3FQe2Ezq3CfFfTlgkUmw+EdJEcPKg4YA7BMYvsB6gsTDFi6VrM1EWFR5gRrPp O3Vi2ahClDTr4j551ig/stnJCXaNkNA= Received: from mx-prod-mc-01.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-616-BPQvouKcNg2_QR0P7W8Big-1; Wed, 09 Apr 2025 23:57:36 -0400 X-MC-Unique: BPQvouKcNg2_QR0P7W8Big-1 X-Mimecast-MFC-AGG-ID: BPQvouKcNg2_QR0P7W8Big_1744257455 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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8E72B1956050; Thu, 10 Apr 2025 03:57:35 +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 A99A419560AD; Thu, 10 Apr 2025 03:57:31 +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 2/4] mm/gup: remove unneeded checking in follow_page_pte() Date: Thu, 10 Apr 2025 11:57:15 +0800 Message-ID: <20250410035717.473207-3-bhe@redhat.com> In-Reply-To: <20250410035717.473207-1-bhe@redhat.com> References: <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-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CEMX8IuTQJLq0cD2aG zRZqg0z6 81wWSKoTRG4Ej4iqXT8CtiJko5nJx76Sz79ni3i8nHylJhGkDNLWA4mJG8uOyfQ7FU27BxuhGIj+CmXjehiBJABb+goxS0RS6/x+NemjUm5dErFY= 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 set. However, it's not supported both GUP_GET and GUP_PIN are set. Even though this check need be done, it should be done earlier, but not doing it till entering into follow_page_pte() and failed. Furthermore, this checking has been done in is_valid_gup_args() and all external users of __get_user_pages() will call is_valid_gup_args() to catch the illegal setting. We don't need to worry about internal users of __get_user_pages() because the gup_flags are set by MM code correctly. Here remove the checking in follow_page_pte(), and add VM_WARN_ON_ONCE() to catch the possible exceptional setting just in case. And also change the VM_BUG_ON to VM_WARN_ON_ONCE() for checking (!!pages != !!(gup_flags & (FOLL_GET | FOLL_PIN))) because the checking has been done in is_valid_gup_args() for external users of __get_user_pages(). Signed-off-by: Baoquan He Reviewed-by: Oscar Salvador Acked-by: David Hildenbrand --- mm/gup.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 84461d384ae2..eb668da933e1 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -844,11 +844,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); @@ -1432,7 +1427,11 @@ static long __get_user_pages(struct mm_struct *mm, start = untagged_addr_remote(mm, start); - VM_BUG_ON(!!pages != !!(gup_flags & (FOLL_GET | FOLL_PIN))); + VM_WARN_ON_ONCE(!!pages != !!(gup_flags & (FOLL_GET | FOLL_PIN))); + + /* FOLL_GET and FOLL_PIN are mutually exclusive. */ + VM_WARN_ON_ONCE((gup_flags & (FOLL_PIN | FOLL_GET)) == + (FOLL_PIN | FOLL_GET)); do { struct page *page;