From patchwork Mon Mar 31 08:13:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 14033791 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 76A56C3600B for ; Mon, 31 Mar 2025 16:31:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 56CF9280008; Mon, 31 Mar 2025 12:31:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4F39A280005; Mon, 31 Mar 2025 12:31:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3BB96280008; Mon, 31 Mar 2025 12:31:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 174BE280005 for ; Mon, 31 Mar 2025 12:31:06 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9DEE957A33 for ; Mon, 31 Mar 2025 08:13:47 +0000 (UTC) X-FDA: 83281132494.05.2DC2E0C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf22.hostedemail.com (Postfix) with ESMTP id DF3A9C0004 for ; Mon, 31 Mar 2025 08:13:45 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JCAX5KaT; spf=pass (imf22.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=1743408825; 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=VpQkE/o6UqynMHBaEyGhtuzDswvJwtgU/N8i6Bf76yI=; b=Pm3oUVwgetOivgLc2oJvJVDLm/oIPN+3Rex2OeZFaMVMz3TTIaTgG5Hw8NmnvEnatFNhJd yjRQmwixq/C1c/70ShSIeLEhYqyjFMCZK+gSlOB8tKhiBEJ9bPmf7cmK6hjHtTcej1lVgp YiQiHplNHusBP7WEFJEPHgx+HLdzcuc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743408825; a=rsa-sha256; cv=none; b=LW5bJiqtQBSkDN17hFbGHqechXC2jULKxpw7979BaYKpdb1GrNUjxDxOIpF6v/TycuLeRN FwBZuch48ty63/tn6eN7M2dGSy52a1tlG8FvscVmwt9wHD9DSH7o21S2vWticf3jeFLhP+ L61aAw7nr71Rl/SrEUVYSVHdGkhkydQ= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JCAX5KaT; spf=pass (imf22.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=1743408825; 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=VpQkE/o6UqynMHBaEyGhtuzDswvJwtgU/N8i6Bf76yI=; b=JCAX5KaThZGkoi3RXSw4XhNz3zAJGxvfLUWTRGevlk/CikbrAtt242CCs/dUIMIx0MJVbP P9fH0HRXD3qsPK1H1EZ3qVdYI7aiWKisKpxKk1aoSBRRKiXyntXOyGkUzkZhYxDFpFw+EX DtlygZB3a2aDGMey5VV67Sd1s2Vr+qg= 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-641-fGwKGbB3NxqKefEQ3WVoQw-1; Mon, 31 Mar 2025 04:13:39 -0400 X-MC-Unique: fGwKGbB3NxqKefEQ3WVoQw-1 X-Mimecast-MFC-AGG-ID: fGwKGbB3NxqKefEQ3WVoQw_1743408818 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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4C260180882E; Mon, 31 Mar 2025 08:13:38 +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 2BCB11955BF1; Mon, 31 Mar 2025 08:13:34 +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 1/7] mm/gup: fix wrongly calculated returned value in fault_in_safe_writeable() Date: Mon, 31 Mar 2025 16:13:21 +0800 Message-ID: <20250331081327.256412-2-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-Rspam-User: X-Rspamd-Server: rspam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mXYRDY r3LWGbFa4ubBYMgZoyhrnAlQhAPd8T/3Fg31cAtRO6oJQTLBckoru3oGbE+BrQ5qetYCixJ/I8TP0joJ71R9zLyreACla696yZRigqrTQJaleK5U2jYKiz98Lcr2O0/kvCZgVPjVPNONgIixKHNP4NtebOW0NoLpZ6F5c0auXR0mWpBZIelfGLttrZOZshqMfgakW4wUdMUB6oRUAVnpbc3Yq07TS13vGn1+hdN64ZKOfWhxcUEgffqgnr63tc2wGghHVtJWEVsZC5SOG9gUMzNSXKMH00lfL1+mHMqrej7amLNDJCaKE4e19PCuaXRjgGFP7PRM9ZkbgTjTzg9RM3rDT+l88XhLr9/GgQWE1TQ9LM/Q1Tbrcyjajjg== 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: Not like fault_in_readable() or fault_in_writeable(), in fault_in_safe_writeable() local variable 'start' is increased page by page to loop till the whole address range is handled. However, it mistakenly calcalates the size of handled range with 'uaddr - start'. Fix it here. Signed-off-by: Baoquan He --- v1->v2: - Fix a patch log typo caused by copy-and-paste error. Thanks to Yanjun. mm/gup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 855ab860f88b..73777b1de679 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2207,8 +2207,8 @@ size_t fault_in_safe_writeable(const char __user *uaddr, size_t size) } while (start != end); mmap_read_unlock(mm); - if (size > (unsigned long)uaddr - start) - return size - ((unsigned long)uaddr - start); + if (size > start - (unsigned long)uaddr) + return size - (start - (unsigned long)uaddr); return 0; } EXPORT_SYMBOL(fault_in_safe_writeable);