Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1979686pxb; Fri, 5 Mar 2021 04:40:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJwMoJ4QAlExv3btR5MJCu6gB1Y3U6y7+1mLC0K3UkE2lQ/9j3PE4XryJrlW/6lvY+Sf/1il X-Received: by 2002:a05:6402:c88:: with SMTP id cm8mr8860776edb.62.1614948014900; Fri, 05 Mar 2021 04:40:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614948014; cv=none; d=google.com; s=arc-20160816; b=TyYlYw/B93V5Vy68nYIrhfxAXDFanzWJptSvdfi3ua2+0CTrC7gvQjkNFnxTHk6Ana nhAWGYPE21nXr7yv8BHXfrA5wNTlLGBQQjOcFJ584/e4u3Fdhh/qUUHtToZQdqjcPE0P s1sqGkwUnHqu/omAxsSDQXC3LbO14aSmuW1vneH0atwxcT9+B0F3DXN83GBjOY1sytCY ZwITJdfeGaZxIQyUYfLJI0Wh3PnckJ0vNhI4fBIS7yto0Q8dM+RrjojPp1XEMA+57x2i 4RddhVGCgExRo/oYdKcafWh+kkp7k5JX06cy9fGYRRVxwvxT69qW6iWqLea/Tr44pssq g0eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=UbpCQwlCBRi8E7xfD1uUfSL8yLkPNtDL3Q6ZaP8k7Uw=; b=AQprtK7NcQOWrk0cXw36CKNJfcycVywZTXsxMxeRyPoTZdk9pdoJIMjJCgrt7kFAhn LGUvvTJLDORFxJPf2mCW4EE51d4rYROv0Fk9EB+h5Qpm+Rw/cljYDLxR8PeKF5ImLk7T BnSsgNC8GmEXjJ0soFeg8M7SRSwFEEKNeEx/edI5BCpAG7t3iT/0EeBkPZkmqNKo1Lo5 UIhyemVXQBShId8kdv7M0CfsRlvd40pgG3pXoqrsWOs3QYKOZzAy6oiX7vH/TnaJZVSl J9AeQvyzu/0ftM009RbLH4GqQLnhkh//7LiOtSUuq6l+bYP5b0+ITlx3fF9s1KNahsAD YrYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PUPGIsaK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bi6si1475721edb.419.2021.03.05.04.39.51; Fri, 05 Mar 2021 04:40:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PUPGIsaK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233108AbhCEMi5 (ORCPT + 99 others); Fri, 5 Mar 2021 07:38:57 -0500 Received: from mail.kernel.org ([198.145.29.99]:51622 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232041AbhCEMiN (ORCPT ); Fri, 5 Mar 2021 07:38:13 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5C8F865044; Fri, 5 Mar 2021 12:38:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614947892; bh=8ei/CYS8xQb5XrjFQ4+j+HL/fQtR6lLh7r6wnkYH01s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PUPGIsaKt86Nkp1rmJKzZSmqavTWiv/Ggw7zITJFbR7XfylW/JOloh1cXcmDsW30/ ghycwhM0E1jTwnGFBFLEXzAtkSQA4JVGv1aR+A+rkh+4l1MjS2RYc0jzht+lEVKGmc 1IOWk2Qhlji1tywXtQbC8tOwCLqCiMBMdg4tVLJI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jens Axboe , Anthony Iliopoulos Subject: [PATCH 4.19 49/52] swap: fix swapfile read/write offset Date: Fri, 5 Mar 2021 13:22:20 +0100 Message-Id: <20210305120856.064797764@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210305120853.659441428@linuxfoundation.org> References: <20210305120853.659441428@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jens Axboe commit caf6912f3f4af7232340d500a4a2008f81b93f14 upstream. We're not factoring in the start of the file for where to write and read the swapfile, which leads to very unfortunate side effects of writing where we should not be... [This issue only affects swapfiles on filesystems on top of blockdevs that implement rw_page ops (brd, zram, btt, pmem), and not on top of any other block devices, in contrast to the upstream commit fix.] Fixes: dd6bd0d9c7db ("swap: use bdev_read_page() / bdev_write_page()") Signed-off-by: Jens Axboe Signed-off-by: Anthony Iliopoulos Signed-off-by: Greg Kroah-Hartman --- mm/page_io.c | 11 +++-------- mm/swapfile.c | 2 +- 2 files changed, 4 insertions(+), 9 deletions(-) --- a/mm/page_io.c +++ b/mm/page_io.c @@ -38,7 +38,6 @@ static struct bio *get_swap_bio(gfp_t gf bio->bi_iter.bi_sector = map_swap_page(page, &bdev); bio_set_dev(bio, bdev); - bio->bi_iter.bi_sector <<= PAGE_SHIFT - 9; bio->bi_end_io = end_io; for (i = 0; i < nr; i++) @@ -262,11 +261,6 @@ out: return ret; } -static sector_t swap_page_sector(struct page *page) -{ - return (sector_t)__page_file_index(page) << (PAGE_SHIFT - 9); -} - static inline void count_swpout_vm_event(struct page *page) { #ifdef CONFIG_TRANSPARENT_HUGEPAGE @@ -325,7 +319,8 @@ int __swap_writepage(struct page *page, return ret; } - ret = bdev_write_page(sis->bdev, swap_page_sector(page), page, wbc); + ret = bdev_write_page(sis->bdev, map_swap_page(page, &sis->bdev), + page, wbc); if (!ret) { count_swpout_vm_event(page); return 0; @@ -376,7 +371,7 @@ int swap_readpage(struct page *page, boo return ret; } - ret = bdev_read_page(sis->bdev, swap_page_sector(page), page); + ret = bdev_read_page(sis->bdev, map_swap_page(page, &sis->bdev), page); if (!ret) { if (trylock_page(page)) { swap_slot_free_notify(page); --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2305,7 +2305,7 @@ sector_t map_swap_page(struct page *page { swp_entry_t entry; entry.val = page_private(page); - return map_swap_entry(entry, bdev); + return map_swap_entry(entry, bdev) << (PAGE_SHIFT - 9); } /*