Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1753752rbb; Mon, 26 Feb 2024 23:04:58 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWhTQYZbVnQspZKlWsmT5s6dFIBE3jo0L6+1mVCGu5bZu9XQJRxy1nDY9iqmvoMzmMj3ema6TSU5GNERXnlHpfloBe5CBbr3ybcJBOlOw== X-Google-Smtp-Source: AGHT+IHLsPCoS1xlBgzeE2SYg3iq3YmaGqVTzK5Ni+lICU5o92Vp/1c+g4E0K9+7DX50XKUMpq1q X-Received: by 2002:a05:620a:6503:b0:785:bff2:25f5 with SMTP id qb3-20020a05620a650300b00785bff225f5mr1784387qkn.37.1709017498343; Mon, 26 Feb 2024 23:04:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709017498; cv=pass; d=google.com; s=arc-20160816; b=q3Pv3RsViPBtJH5lvukiCMaZysZir+sr6d54hOWFat68YBhxGG8o0lbisANU0MbIYt +YQ+woalDutFeydU4JBR4mKnSrgsyoS+NgQH2Re7JQ5IYAy6Ca8gFoOgaj1/NBfOQFuf wUjHb0wxk0Rx+hA6XMiCdHN7X642tItWHiP5CQYjaaI3NoEis1pW2T5kDqJhxbF3Lvza DlM53TNm5S4K7ktKPlNmHsgWg3ClgustcXXCp14/8QmelLT/2Ll1DLypUqwXKJee+8I2 sKtXuw1cg++r7jNMMGb1Q0u3+jF6QM4ufFMkjR/9k6c0ps9EroTjRFtbTX+Zubo06EGX B8kg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=5Xh9xry9yXUPCbuZkIvBEujR1IE4YpcvcS1See1vKpM=; fh=OwJI2a79kGLpgMJu87UaxgQe3HQ8dD+Q5sCbMXERE4w=; b=0C7i2h/hHb8DvEyf0Vpkf5+L17jD01SkYSkGpqXVBWkf7+cOIOlHtsJHTFR9uJUvgx BoRXAYg6+TuYS+PgQf7nojzWKpy/Dssd6S+RJE5cY1eCNIOETk4fxVIRkxyrs+pidH+k 1dQo6vz2UWEq1SSyvhDptlEH0Xpyoe30ittBjgjMV29gNideFHPgzYn5+iwiE4jPOuxU A8x+V6sH7mjXsBSkM8K3f4z6eMqtfZL3zvuBEk6ufkgFI88ggAJRvLahPm/aOihWyBKH 75mYx3/QQC0npeVWigJeg3+gP5Tv8W+8TIeTH3zLHY7bU40LuuCTqT5D8GM4V84ZrbAw zTDQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=QL23UPDg; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-82775-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82775-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id u25-20020a05620a085900b00787b81733ebsi6545527qku.604.2024.02.26.23.04.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 23:04:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-82775-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=QL23UPDg; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-82775-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82775-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 1D0011C213EE for ; Tue, 27 Feb 2024 07:04:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1DC965381B; Tue, 27 Feb 2024 07:04:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QL23UPDg" Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0108728366 for ; Tue, 27 Feb 2024 07:04:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709017492; cv=none; b=RKjsDazX83I+CXt6uIWhZEXrITthEqT1XsqSt9RwSH+Wj7f/nTF6fYuROkaKLf+1TrvIHW5gAq71hVb5aVRsj9bDHjHPlK52ZQhmZ8gIgR0ZipITxWYubNmEHUwxkulEtmYbTuO1xFAzTXgou4Hzrjntd42I4hxLUZJDeeHObjE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709017492; c=relaxed/simple; bh=zBL8nxW+5/neV82/pCUbPddBMc5jugz9xVoVZc2ucAs=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=MSitVehquCPJk2VCX7ILKt71SoBXTZAVWFE/Cpo+g02YDRBlIyL3x5NCbRQof2kY0x2TcoLSSK2aLVdqsLtvnfoEQ5TmbVF1t4yrAdqWqMuWy361EEEBWnTOrgEmWxVdOilamuiZDMsZKPjaa8/3I3lh8bI15R4MxFiZV67BRzA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QL23UPDg; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1dca8b86ee7so14067525ad.2 for ; Mon, 26 Feb 2024 23:04:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709017490; x=1709622290; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=5Xh9xry9yXUPCbuZkIvBEujR1IE4YpcvcS1See1vKpM=; b=QL23UPDg7H6PcMBeDbhFvmyqnBBLnGgwHxNxe7I3oTQJFUGuHf2b1TGe5vyMuujCo3 aLP9GpQSTRrdMkPeYW9PA1TPygKVJcU2jegFtbBDssjzl8ZHCeVNE4swCxlqvPLHd2mi Ot8Y4tUsh+aR6Km0m3iAjWXc6ja9hsY4kZUqlqfuY1c3Lw8grXhEkSDFhwltDzXSll5h WAcL/kBqxdzfDmG3VXcNG+1rhp4C3y39UGkBbksco8a6WlgeZwc/NWfEawZivU6NY4t7 enCvIrOzSnXqpcqUQeFdsICVbe5dSWqn8eiwINnlz/i+LdKPmaLqIuBvnMHE79Aq4J/g OaKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709017490; x=1709622290; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=5Xh9xry9yXUPCbuZkIvBEujR1IE4YpcvcS1See1vKpM=; b=nZHAikzApwfo734+AXEMBBtTP/pt+r6eZMhjWEAMLdKlcrw2c9q8EjhFrpKhQSUEhL TqJfmoR/d3j2X3BTDKHU0knJyc0cJyZuKSVE2uFMXvyhtcLxe4L1Ak5KV7OOnAVjkudS mkRhTZmc9O0SJ7Hj3DsFvsWWbwa+2arGwLOXz+ZbeBD3VNCY7oPwp+h7qGp1Bfxd0tvC qI6AwzQnRWsFii0jUD7AGbTX82GhcWdt5Yr98cFmHTRWjPkHlPLjts/YQ9z5x0afEI4P U+okrE4NWf/ZewddhPb8CFJu6LY1scfLI37LRCqd6S7gUmDilexldvY73y9xYaSoSb15 irBg== X-Forwarded-Encrypted: i=1; AJvYcCVDfxa/23xx0PcVtsaOzfQcOQFldXAXd8JwgZd4Y1a5ymmOpDsxJQXwpXv1UzWuczkEh0/OjnxTtgADPVWRRu4i++vZlXAti/ryntEa X-Gm-Message-State: AOJu0YxC9Kiy57TONdZTv+mZrMB9m/Ye/jNTNLvVQStH5CZ8Vv2V5OKR tLiH/kqVahJc7fzrHZhPnYu/aFo0vgFeVPFuv57S0kOdimRzcc2Q X-Received: by 2002:a17:902:ed8b:b0:1db:d13d:6bf3 with SMTP id e11-20020a170902ed8b00b001dbd13d6bf3mr6479790plj.62.1709017490243; Mon, 26 Feb 2024 23:04:50 -0800 (PST) Received: from LancedeMBP.lan ([112.10.225.117]) by smtp.gmail.com with ESMTPSA id x9-20020a1709029a4900b001dc944299acsm783347plv.217.2024.02.26.23.04.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 23:04:50 -0800 (PST) From: Lance Yang To: akpm@linux-foundation.org Cc: ryan.roberts@arm.com, 21cnbao@gmail.com, david@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Lance Yang Subject: [PATCH 1/1] mm/memory: Fix boundary check for next PFN in folio_pte_batch() Date: Tue, 27 Feb 2024 15:04:18 +0800 Message-Id: <20240227070418.62292-1-ioworker0@gmail.com> X-Mailer: git-send-email 2.33.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Previously, in folio_pte_batch(), only the upper boundary of the folio was checked using '>=' for comparison. This led to incorrect behavior when the next PFN exceeded the lower boundary of the folio, especially in corner cases where the next PFN might fall into a different folio. Signed-off-by: Lance Yang --- mm/memory.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 642b4f2be523..e5291d1e8c37 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -986,12 +986,15 @@ static inline int folio_pte_batch(struct folio *folio, unsigned long addr, pte_t *start_ptep, pte_t pte, int max_nr, fpb_t flags, bool *any_writable) { - unsigned long folio_end_pfn = folio_pfn(folio) + folio_nr_pages(folio); + unsigned long folio_start_pfn, folio_end_pfn; const pte_t *end_ptep = start_ptep + max_nr; pte_t expected_pte, *ptep; bool writable; int nr; + folio_start_pfn = folio_pfn(folio); + folio_end_pfn = folio_start_pfn + folio_nr_pages(folio); + if (any_writable) *any_writable = false; @@ -1015,7 +1018,7 @@ static inline int folio_pte_batch(struct folio *folio, unsigned long addr, * corner cases the next PFN might fall into a different * folio. */ - if (pte_pfn(pte) >= folio_end_pfn) + if (pte_pfn(pte) >= folio_end_pfn || pte_pfn(pte) < folio_start_pfn) break; if (any_writable) -- 2.33.1