Received: by 2002:a05:6500:2018:b0:1fb:9675:f89d with SMTP id t24csp298495lqh; Fri, 31 May 2024 01:23:21 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVXHv45xA90ZtaMiR+AiPcEjXmVpdPKy2OAwyvJX4rllSBSBUMK6x++KZU5VgsbQ7bkflK3cY8bnm6Jx0d2ZfMBaAnL0qkLtqOCrWA/JQ== X-Google-Smtp-Source: AGHT+IHZZkZlQI/KFIrnYCEYe+o3RfLoaLQEOOiP50KJHcZ8I+FImm633QBPUXZMAnRls/eP22+T X-Received: by 2002:a50:cd9a:0:b0:57a:3416:85ad with SMTP id 4fb4d7f45d1cf-57a364acf61mr953189a12.35.1717143801105; Fri, 31 May 2024 01:23:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717143801; cv=pass; d=google.com; s=arc-20160816; b=BH2lpRqEzmPLO0ZyquCgrA2pItPDYYeD8Wl3N5ApPvHwYkid77ZQQplXF0e8XH7yxi lKTIJ4uqgwcB17DcmGPsVycM4W1pjaNtKjJLNes9B+suEnRrs521U3hEQ31N9v7A+JIY UzO3NpRCrf+nTYzzQ9TB5DJJXphfxt8qXU0dEQq8zP/x6mEKCLZS1bAAYPAxJ0+PFMFU ZE5NMDlb3O7MGiu7O96yF9WUNVlz+8gXU4VhYGoLwkY50v4RFDNT+gdv38IVBh1L6wap VvRNI2FLHHtr6yd6E7iSEnkSqVsMF4Hm7xF+BfG8rGacsxrmAypkEW0DBNMXjMixTvgG 3G1A== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ccYnb6zhiB/aH/usWIdTsL879a4h4ytGkNRSAUGO+zk=; fh=gl8dYwiJrRKBnLBmPUcglhbW6QYEAY+pkPSbddZrANs=; b=pBkd4zTsQPAeGXJtIpM52310b11Z9PgcQJ6Seow/YaObhYAfXlcepfaee0HkQV3Xwl wBUCW0Sghjr6sEdrPGrraa/PmILgp4aVGESCTuaVRRaWrfd4Mn94/iEwgWDF8cAU6GGO MnPZCDh/eSUhB+/EtUhO+Ah2XYPX5uAJSv40QCESJXuoA71LQvVJr1k6CVC9Y+gM25aT LnM6F6v3JsQTDWIJCn6IEKBDfcwTv3Po0mgjdTLpba/ARF/6MwW4VOsVI0znoysgnPoX sDddgzFPgHw8e08vq3kPs+GJWA/zwb9Xa+wLQsSWR/0QYaUAD4+0IPhgJRoFNmOwtDVV jCkg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=YqzOHD4S; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-196449-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-196449-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57a31cc95edsi717933a12.635.2024.05.31.01.23.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 May 2024 01:23:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-196449-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=YqzOHD4S; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-196449-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-196449-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 am.mirrors.kernel.org (Postfix) with ESMTPS id BB0851F29055 for ; Fri, 31 May 2024 08:13:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4ABE877F10; Fri, 31 May 2024 08:13:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="YqzOHD4S" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8C067C6DF for ; Fri, 31 May 2024 08:12:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717143180; cv=none; b=RPSs/DLP6EicUxB1DjQy1TF9hUwWMyCMWSlsLYQ/5z7f2FBX+btb6xVCqllUvEvvLSH5xrspPKnETgpn2xysqjYpPd3/VeBE6e4ZQmsl2VIbmcKrlDQ3ZPGquTJyqgXd3bG2TPqtPVR5lyrfyOB5k+v4GuYm79bBre7VlLnZavo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717143180; c=relaxed/simple; bh=ikiPA1J5OkAmYTlYwym2P+F42MJMV8ZnlTu7TRlEtOg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=McpuFcSr+yJgv6tytFQ1nEY5FmY1g/JOLe5byWtOKeTYuaGIRCg0QmF9Xj+V93F+FWDfnq76mDxF/Nsb4xfQC181tjX1D7TABSUBEgyqelGcHO89qp+G3QjFZRxw7rWgug2S48wMWhJj5F5hDj70Hi/LfDAsjEKvQerATQFeHlE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=YqzOHD4S; arc=none smtp.client-ip=192.198.163.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1717143179; x=1748679179; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ikiPA1J5OkAmYTlYwym2P+F42MJMV8ZnlTu7TRlEtOg=; b=YqzOHD4S8jOZtNZE5eZuwDL1BdYwFYnekC0/vCh8Vr/kppIWDELLmIWO 2LZxKLjJFbueil/r0XZULahdomkqk0PpOGRHn6BcgnZDJZKr2yKmCXZxu 9vR27ZCKqkQrWEXwpeeg7zE9MbBvC58weXnC4eIHTmenqBn1PFl8AgMVs Ojt3Ubwg2uDq3sR/Qa5E/i+5OBTBYfk8RoUA5ppnp2cvwdaVDIHPSHXpZ W2bdt6kby4FVUCP1VeK/ht32KhrUtOmqCDrgToFhzugUpdglXpqdYNnEo AXFSBptwoDAaz8fjsV46XeP2MwN2OaBgsOWA2Q6C2PwPCNpUUcJenTc8L A==; X-CSE-ConnectionGUID: G20DW+vaSHK8GslEQQPWTg== X-CSE-MsgGUID: fysvJCoVS0Gc29Dowu6BlQ== X-IronPort-AV: E=McAfee;i="6600,9927,11088"; a="25079745" X-IronPort-AV: E=Sophos;i="6.08,203,1712646000"; d="scan'208";a="25079745" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2024 01:12:58 -0700 X-CSE-ConnectionGUID: paWjvUcmRbmdg62OQ/tn+g== X-CSE-MsgGUID: RxkDEidERZauFldGWycaVw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,203,1712646000"; d="scan'208";a="59270933" Received: from unknown (HELO yhuang6-mobl2.ccr.corp.intel.com) ([10.255.30.35]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2024 01:12:54 -0700 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , Hugh Dickins , Alistair Popple , Anshuman Khandual , David Hildenbrand , Mel Gorman , Miaohe Lin , Minchan Kim , Ryan Roberts , Yang Shi , Yu Zhao , Kairui Song , Barry Song , Chris Li , Yosry Ahmed Subject: [PATCH 1/3] mm,swap: fix a theoretical underflow in readahead window calculation Date: Fri, 31 May 2024 16:12:28 +0800 Message-Id: <20240531081230.310128-2-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240531081230.310128-1-ying.huang@intel.com> References: <20240531081230.310128-1-ying.huang@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In swap readahead window calculation, if the fault PFN is smaller than the readahead window size, underflow may occurs. This is only possible in theory, because the start of the virtual address space will not be used for anonymous pages in practice. Even if underflow occurs, there will be no functional bugs. In the worst cases, some swap entries may be swapped in incorrectly and some pages may be allocate on the wrong nodes. Anyway, we still needs to fix the issue via some underflow checking. Fixes: ec560175c0b6 ("mm, swap: VMA based swap readahead") Signed-off-by: "Huang, Ying" Cc: Hugh Dickins Cc: Alistair Popple Cc: Anshuman Khandual Cc: David Hildenbrand Cc: Mel Gorman Cc: Miaohe Lin Cc: Minchan Kim Cc: Ryan Roberts Cc: Yang Shi Cc: Yu Zhao Cc: Kairui Song Cc: Barry Song Cc: Chris Li Cc: Yosry Ahmed --- mm/swap_state.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/swap_state.c b/mm/swap_state.c index 642c30d8376c..848c167df530 100644 --- a/mm/swap_state.c +++ b/mm/swap_state.c @@ -787,6 +787,8 @@ static void swap_ra_info(struct vm_fault *vmf, lpfn = fpfn - left; rpfn = fpfn + win - left; } + if ((long)lpfn < 0) + lpfn = 0; start = max3(lpfn, PFN_DOWN(vma->vm_start), PFN_DOWN(faddr & PMD_MASK)); end = min3(rpfn, PFN_DOWN(vma->vm_end), -- 2.39.2