From mboxrd@z Thu Jan 1 00:00:00 1970 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 971EFC433F5 for ; Mon, 25 Apr 2022 08:51:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 148048D001F; Mon, 25 Apr 2022 04:51:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0D20F8D0006; Mon, 25 Apr 2022 04:51:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E8DF98D001F; Mon, 25 Apr 2022 04:51:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id D496F8D0006 for ; Mon, 25 Apr 2022 04:51:07 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id A8EC082A10 for ; Mon, 25 Apr 2022 08:51:07 +0000 (UTC) X-FDA: 79394781774.23.DC3C2F8 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf31.hostedemail.com (Postfix) with ESMTP id 03CB120042 for ; Mon, 25 Apr 2022 08:50:59 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4KmzH83GVmz1JBG0; Mon, 25 Apr 2022 16:50:12 +0800 (CST) Received: from [10.174.177.76] (10.174.177.76) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 25 Apr 2022 16:51:02 +0800 Subject: Re: [PATCH v3 1/3] mm/swapfile: unuse_pte can map random data if swap read fails To: David Hildenbrand , "ying.huang@intel.com" CC: , , , , , , , , , , , , Tim C Chen , Andrew Morton References: <20220424091105.48374-1-linmiaohe@huawei.com> <20220424091105.48374-2-linmiaohe@huawei.com> <8aeebc2f0b2a251d3d70402cd0edf063ba911013.camel@intel.com> <6c6694965fa3e6d85d78d56703090f227a55bb83.camel@intel.com> From: Miaohe Lin Message-ID: <63c96d54-f16b-4a39-a665-227cc194cf96@huawei.com> Date: Mon, 25 Apr 2022 16:51:02 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.177.76] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 03CB120042 X-Stat-Signature: 9sa31mckiwyi4kho7d7pranwztqizgct X-Rspam-User: Authentication-Results: imf31.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf31.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-HE-Tag: 1650876659-224092 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: On 2022/4/25 16:01, David Hildenbrand wrote: > On 25.04.22 09:55, ying.huang@intel.com wrote: >> On Mon, 2022-04-25 at 09:49 +0200, David Hildenbrand wrote: >>> On 25.04.22 09:41, ying.huang@intel.com wrote: >>>> Hi, Miaohe, >>>> >>>> On Sun, 2022-04-24 at 17:11 +0800, Miaohe Lin wrote: >>>>> There is a bug in unuse_pte(): when swap page happens to be unreadable, >>>>> page filled with random data is mapped into user address space. In case >>>>> of error, a special swap entry indicating swap read fails is set to the >>>>> page table. So the swapcache page can be freed and the user won't end up >>>>> with a permanently mounted swap because a sector is bad. And if the page >>>>> is accessed later, the user process will be killed so that corrupted data >>>>> is never consumed. On the other hand, if the page is never accessed, the >>>>> user won't even notice it. >>>>> >>>>> Signed-off-by: Miaohe Lin >>>>> Acked-by: David Hildenbrand >>>>> --- >>>>>  include/linux/swap.h | 7 ++++++- >>>>>  include/linux/swapops.h | 10 ++++++++++ >>>>>  mm/memory.c | 5 ++++- >>>>>  mm/swapfile.c | 11 +++++++++++ >>>>>  4 files changed, 31 insertions(+), 2 deletions(-) >>>>> >>>>> diff --git a/include/linux/swap.h b/include/linux/swap.h >>>>> index 5553189d0215..b82c196d8867 100644 >>>>> --- a/include/linux/swap.h >>>>> +++ b/include/linux/swap.h >>>>> @@ -55,6 +55,10 @@ static inline int current_is_kswapd(void) >>>>>   * actions on faults. >>>>>   */ >>>>> >>>>> +#define SWP_SWAPIN_ERROR_NUM 1 >>>>> +#define SWP_SWAPIN_ERROR (MAX_SWAPFILES + SWP_HWPOISON_NUM + \ >>>>> + SWP_MIGRATION_NUM + SWP_DEVICE_NUM + \ >>>>> + SWP_PTE_MARKER_NUM) >>>>> >>>>> >>>> >>>> It appears wasteful to use another swap device number. >>> >>> Do we really care? >>> >>> We currently use 5 bits for swap types, so we have a total of 32. >>> >>> SWP_HWPOISON_NUM -> 1 >>> SWP_MIGRATION_NUM -> 3 >>> SWP_PTE_MARKER_NUM -> 1 >>> SWP_DEVICE_NUM -> 4 >>> SWP_SWAPIN_ERROR_NUM -> 1 >>> >>> Which would leave us with 32 - 10 = 22 swap devices. IMHO that's plenty >>> for real life scenarios. >> >> Creating multiple swap partitions on one disk can improve the >> scalability of swap subsystem, although we usually don't have so many >> disks for swap. > > Exactly, and IMHO if we have 22 or 23 doesn't make a real difference > here ... I tend to agree with David. Thanks both! >