Received: by 2002:a05:6512:3a82:0:0:0:0 with SMTP id q2csp522912lfu; Mon, 25 Apr 2022 03:56:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwVblS07IOXJVTbDUPlp+1SO5P7c/ZJutMqE/QO28GVu18b0aqOS/6Swvv60M903hXtb8+n X-Received: by 2002:a17:907:6d11:b0:6f3:66a9:b57b with SMTP id sa17-20020a1709076d1100b006f366a9b57bmr9524444ejc.374.1650884208619; Mon, 25 Apr 2022 03:56:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650884208; cv=none; d=google.com; s=arc-20160816; b=GbhtttftSQyBcFt/HGm/9Lw5wrNupuc5wGfTdnndr/5lCW0OGvFb+QYcsuysCl1meC GktNgFgHuM9QQ6KEv3BhZoQ8whpztrBxNfiypi0BooaGWLhwkb23aDULOKa7WFFzzOTQ RvdniL7UTv9q3HKtIko/vS5SPuUHbJ/lFEP1gckhLVlLyb+EArlW42gsadedgcrvsBRg Ik4n56LJuecQnxotKJzSg7p4tby6dfjRGlg6DmSAV2MrCmFjhErWYAbrI1nDVCxFIzND ALYRxRlpBy4lCyXj3heWmD3GPh+Qf0cTm7khfz1fQFalNp+ckwy5hb9YoHdN1OsQR3Lc 9xXQ== 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:date:cc:to:from:subject :message-id:dkim-signature; bh=0Xk7zVh5BKgMHFETsLBaTbG0lShEoPVEoDmrllZngew=; b=G5bpAaAAfS6mXWFFXHQ05QCBkBi6SULgwnRdIxFY9zF4NQPQK2lQvrdleaWROTfqw6 1Ky2jO0frjldLq9v/KDFgKxXvkCXXybuMCCwzvFAjQ1fakZlKEZuzsSHgXsKz5VZFsca IknO8kgYlPa1oPv2HAYQUUkkmE93DUWdHulPYU6kFQMFfrUIV/HNBO3N8b9QEBird2d4 X2MzHNyQcVJzoVuqoOCLyTBQ4diDmbZ0p4Y9PJgjzAdBW1RjHJwaiz+2cHqIhovHofrY RnliGGY9oCjgT3WkGDGkHPwk2VYdF06Q6ioxv2c+2Tb8NaonJoDrZHclEfU9RQdwltus VPKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UBtBpH0K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s12-20020a508d0c000000b00423f9a0d0a2si12239375eds.431.2022.04.25.03.55.58; Mon, 25 Apr 2022 03:56:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UBtBpH0K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229565AbiDYIAR (ORCPT + 99 others); Mon, 25 Apr 2022 04:00:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234298AbiDYH7M (ORCPT ); Mon, 25 Apr 2022 03:59:12 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 390AFCD2 for ; Mon, 25 Apr 2022 00:55:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650873359; x=1682409359; h=message-id:subject:from:to:cc:date:in-reply-to: references:mime-version:content-transfer-encoding; bh=n+/wbTwudVU2aA3nzC/xFgJqQskv98VvTFPXw2JV4mQ=; b=UBtBpH0K/GUlICOaqLI+e74cpEsRkf6NGMzvCjs9gsyGj6joRUQrH8vc h4xD9FinqA3D3Yz4LAH6gLIv0CQidNA/gEEwuxqLE+IpyHjf2bDgYP2OV 7yvPPKJUUNamlx6j5aMnacBz1745G1ASnSeSn02MzuPvLDXYfIyFIYVVC Rc21vSbsohC7LgO2f77g6+KWaDQ1r4Ijck3nWjl6NO44l8KOYp0Cxa+Pm 8aV+r8a/H+mqrVqOEpEDpGQzwuBdpito0j9qgApHYJZMb7q/xORDPACdf wa/7xu/loEJiNgBOC2CBJg/l330B8E/rgTtNTyiCoIWLuMwB40cUUrhsS g==; X-IronPort-AV: E=McAfee;i="6400,9594,10327"; a="351622192" X-IronPort-AV: E=Sophos;i="5.90,287,1643702400"; d="scan'208";a="351622192" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.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-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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