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 E0606C433F5 for ; Mon, 25 Apr 2022 07:56:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 669178D0014; Mon, 25 Apr 2022 03:56:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 619AE8D0006; Mon, 25 Apr 2022 03:56:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4E1AF8D0014; Mon, 25 Apr 2022 03:56:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id 40B058D0006 for ; Mon, 25 Apr 2022 03:56:02 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 099F428589 for ; Mon, 25 Apr 2022 07:56:02 +0000 (UTC) X-FDA: 79394642964.12.9E4B8AE Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by imf03.hostedemail.com (Postfix) with ESMTP id 1C5112002C for ; Mon, 25 Apr 2022 07:55:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650873361; x=1682409361; h=message-id:subject:from:to:cc:date:in-reply-to: references:mime-version:content-transfer-encoding; bh=n+/wbTwudVU2aA3nzC/xFgJqQskv98VvTFPXw2JV4mQ=; b=Tge0qEC3y+Anh4HcG5BPRGLhJL1f79y5POUYJm9n2shSFyeU0ReWNQf7 opL9D2eDylz8hZdP6xcFXS4EqgPfQ1OMt7dd2i5j+Jm6/ZR3Vl62sAVeT u/uvyK0AnCF3bKZx59MVZAo/vl7JZNNFtkL1ModRThnxCn6X/HNjccWYq Nhf8YDSOl7oU98cynLLo2mjNvTeog5/k8G1pTYEfnnIJVDEL+GsHsgYfa GFa62Dso0cmkY3ZCFhKHegDjAkSPXh9IvUiIV3Azf1BQRwOD7UJGKxrkk 5TFrKtJrRAOFav2oRhxiv0RkTwHQOHF3WpeS/0SOU7wAmbfGHfHn3uItm w==; X-IronPort-AV: E=McAfee;i="6400,9594,10327"; a="265340652" X-IronPort-AV: E=Sophos;i="5.90,287,1643702400"; d="scan'208";a="265340652" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2022 00:55:58 -0700 X-IronPort-AV: E=Sophos;i="5.90,287,1643702400"; d="scan'208";a="579152268" Received: from wupeng-mobl.ccr.corp.intel.com ([10.254.215.115]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2022 00:55:54 -0700 Message-ID: <6c6694965fa3e6d85d78d56703090f227a55bb83.camel@intel.com> Subject: Re: [PATCH v3 1/3] mm/swapfile: unuse_pte can map random data if swap read fails From: "ying.huang@intel.com" To: David Hildenbrand , Miaohe Lin , akpm@linux-foundation.org Cc: willy@infradead.org, vbabka@suse.cz, dhowells@redhat.com, neilb@suse.de, apopple@nvidia.com, surenb@google.com, minchan@kernel.org, peterx@redhat.com, sfr@canb.auug.org.au, naoya.horiguchi@nec.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Tim C Chen Date: Mon, 25 Apr 2022 15:55:51 +0800 In-Reply-To: References: <20220424091105.48374-1-linmiaohe@huawei.com> <20220424091105.48374-2-linmiaohe@huawei.com> <8aeebc2f0b2a251d3d70402cd0edf063ba911013.camel@intel.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.38.3-1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 1C5112002C X-Stat-Signature: rkmkmrx7dmbewtkxtrkmf4e6c3864occ X-Rspam-User: Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=Tge0qEC3; spf=none (imf03.hostedemail.com: domain of ying.huang@intel.com has no SPF policy when checking 192.55.52.115) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com X-HE-Tag: 1650873356-877042 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 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. > I'd prefer reworking this when we really run into trouble (and we could > think about using more bits for applicable architectures then, for > select 64bit architectures it might be fairly easily possible). Best Regards, Huang, Ying