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 51835C433F5 for ; Mon, 25 Apr 2022 07:41:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DF4078D0010; Mon, 25 Apr 2022 03:41:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DA4C98D0006; Mon, 25 Apr 2022 03:41:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C6C268D0010; Mon, 25 Apr 2022 03:41:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id B8E108D0006 for ; Mon, 25 Apr 2022 03:41:34 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 9A8F9623D5 for ; Mon, 25 Apr 2022 07:41:34 +0000 (UTC) X-FDA: 79394606508.26.A091CF4 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by imf07.hostedemail.com (Postfix) with ESMTP id 4EBE140038 for ; Mon, 25 Apr 2022 07:41:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650872493; x=1682408493; h=message-id:subject:from:to:cc:date:in-reply-to: references:mime-version:content-transfer-encoding; bh=ypRaFhfgGoMckctkb+UqL7k4rnajuSRtG45ikgdAanE=; b=ng6/ZMIS82mbAQTzpmR5pBNg/E0P+zBvAfW4kjIiqLPnXUpETeTFnbfb 68uLLEaIC/EKq5lrDgfbeNHkCK9QEo4W1xnE3dBnmvPfDkIEmCT9saX4R 1IvuQxZAhFaV834N6ZuC46M7PD31q7ngsIKfP5B8Toe2hj3fBZKIQCUbW pHPnlZTTD3sMW/rmoeCbZeotFEMFufC3C+Migh90x0lI/hYZB3Pw4J4Hi RE0yGFvNSP2RpK+9c5PjkkxMUG6HWXp3A11ROYpcqcl+/gjJXkH+KmRdC FaVjK1OpKtOys/6rqu8PfLJUJ/67Mockf6meO++4rw0Mn+HcUQaHiJkRD A==; X-IronPort-AV: E=McAfee;i="6400,9594,10327"; a="264688490" X-IronPort-AV: E=Sophos;i="5.90,287,1643702400"; d="scan'208";a="264688490" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2022 00:41:32 -0700 X-IronPort-AV: E=Sophos;i="5.90,287,1643702400"; d="scan'208";a="676565732" Received: from wupeng-mobl.ccr.corp.intel.com ([10.254.215.115]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2022 00:41:27 -0700 Message-ID: <8aeebc2f0b2a251d3d70402cd0edf063ba911013.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: Miaohe Lin , akpm@linux-foundation.org Cc: willy@infradead.org, vbabka@suse.cz, dhowells@redhat.com, neilb@suse.de, david@redhat.com, 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 Date: Mon, 25 Apr 2022 15:41:25 +0800 In-Reply-To: <20220424091105.48374-2-linmiaohe@huawei.com> References: <20220424091105.48374-1-linmiaohe@huawei.com> <20220424091105.48374-2-linmiaohe@huawei.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.38.3-1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Stat-Signature: pu6onqx8un65wsbwwe7gerr7nqn555gf X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 4EBE140038 X-Rspam-User: Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="ng6/ZMIS"; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf07.hostedemail.com: domain of ying.huang@intel.com has no SPF policy when checking 134.134.136.24) smtp.mailfrom=ying.huang@intel.com X-HE-Tag: 1650872492-432857 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: 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. Is it possible to use a special swap offset? For example, 0 or -1? Best Regards, Huang, Ying [snip]