From patchwork Mon May 29 06:13:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13258139 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 04188C77B7A for ; Mon, 29 May 2023 06:14:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 558E0900003; Mon, 29 May 2023 02:14:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4E170900002; Mon, 29 May 2023 02:14:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 35B13900003; Mon, 29 May 2023 02:14:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 178A5900002 for ; Mon, 29 May 2023 02:14:20 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D837FADB08 for ; Mon, 29 May 2023 06:14:19 +0000 (UTC) X-FDA: 80842277838.03.F530CD2 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by imf04.hostedemail.com (Postfix) with ESMTP id 098C540015 for ; Mon, 29 May 2023 06:14:16 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=NYpzLUE7; spf=pass (imf04.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685340858; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=aUy/JryjGSlpC3TCt9Xk24fhImxIYPcAwmgZjW9oHR8=; b=QNcso4B/iUGbHA8262xnZ1qsVNx6TSRWjwNQAzW110G3qoc2+KOKCBGEOOPvwMD/f9xaRq kvE7FEr2R+3+AC37SRxvvC0NW5FjmdzVLPZBxfRkCnvCWSNm9lkJicHQC7t8gF7vk0lnY+ WF92PckVfnI8yefHC9UrAsrtwBjLglw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685340858; a=rsa-sha256; cv=none; b=hItS9jTaLkdzmvWV8PHaNjlUWgsBApQWl7yDRB1WLTatVKTHDTEmJ53AhOyyjCFvyfgVcs jdmy7jrR6QXeMfbUYBTDRYVa2AYJ8pZ9OzaqG8M/OVSTPby7LFdpfJje00wdU+mwCGUOAu vYPt2kv2N4udEZuOjBjksOdEvg1iVjY= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=NYpzLUE7; spf=pass (imf04.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685340857; x=1716876857; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=lZvg1L57BcoSEw3CqHyDTtH9MeFq1P/MjhjyoIG9cOk=; b=NYpzLUE7YicObbvpvXYk0uzjaz6zkeGalV/5dGRMUUvpyV0lHbCVkzK0 lXIlvi95JIsEibDVahCnTHqqkw65+gqpXD2BL+C7bXyokGv6gQ+/F8C/O zjylYUJA8sfTohMl3XJ4/Nm7W64jWgLZtAtVdbvYUuLMcEs2zzkUwnG6H EpsAGOsy7lTueNN0IPW5qHd6TN4B+58l7IHBUGM24xoj0Mvjj7kts8Rmq /vnGgFxkpp9tDiCwUwWsjot0agiWyMpMiQQQdrL4BDrar0BZCJ1xOdyIu ZLl8qutdG+rjR8Tk/vm/w7u/h1O7Am52de+XTGpoF7RhntlbNGVIQLVp0 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10724"; a="357881767" X-IronPort-AV: E=Sophos;i="6.00,200,1681196400"; d="scan'208";a="357881767" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2023 23:14:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10724"; a="1036079969" X-IronPort-AV: E=Sophos;i="6.00,200,1681196400"; d="scan'208";a="1036079969" Received: from azhao3-mobl1.ccr.corp.intel.com (HELO yhuang6-mobl2.ccr.corp.intel.com) ([10.255.28.126]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2023 23:14:11 -0700 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying , David Hildenbrand , Hugh Dickins , Johannes Weiner , Matthew Wilcox , Michal Hocko , Minchan Kim , Tim Chen , Yang Shi , Yu Zhao , Chris Li , Yosry Ahmed Subject: [PATCH -V3 0/5] swap: cleanup get/put_swap_device() usage Date: Mon, 29 May 2023 14:13:50 +0800 Message-Id: <20230529061355.125791-1-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Stat-Signature: 9eu9ujsareke98nc1z8sndqdw4t5efrg X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 098C540015 X-Rspam-User: X-HE-Tag: 1685340856-790927 X-HE-Meta: U2FsdGVkX18apzWcheCoALWwkLVnpVLZh3GlhBcPOQiNvU+u/THUmegX/M2N7PGwZ+a+jZnhNwcDPWF9L+U83bCy3yg66m2/jZyUQ2l8oHYEUZ3GBGajMvLc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ogosity: 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: The general rule to use a swap entry is as follows. When we get a swap entry, if there aren't some other ways to prevent swapoff, such as the folio in swap cache is locked, page table lock is held, etc., the swap entry may become invalid because of swapoff. Then, we need to enclose all swap related functions with get_swap_device() and put_swap_device(), unless the swap functions call get/put_swap_device() by themselves. Based on the above rule, all get/put_swap_device() usage are checked and cleaned up if necessary. Changelogs: V3: - Fix build error in [2/5], Thanks David! - Fix comments and patch description about the folio in swap cache, Thanks David! - Collected reviewed-by. V2: - Split patch per David's comments. Thanks! Best Regards, Huang, Ying