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 59820C433F5 for ; Tue, 19 Apr 2022 07:37:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C413F8D0057; Tue, 19 Apr 2022 03:37:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BF1348D0047; Tue, 19 Apr 2022 03:37:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AB94D8D0057; Tue, 19 Apr 2022 03:37:07 -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 9C7668D0047 for ; Tue, 19 Apr 2022 03:37:07 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 604201207F5 for ; Tue, 19 Apr 2022 07:37:07 +0000 (UTC) X-FDA: 79372822494.12.4297F2A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf26.hostedemail.com (Postfix) with ESMTP id 7454914000B for ; Tue, 19 Apr 2022 07:37:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650353826; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FM4KVGRiRcud5YspVdmyurfb+munCUhUXXDotfhbDB4=; b=DZmpbzrxzG2r2e34hIVrZfHj9yd+62rBelAVbCLf4gGctvU5CVIMD91g2+KvRMPd72d9Cz QTV3UE+lxOnTvcuwfZoOjeTT9TtrgQv0Br0ZVKW8j2pcPUcoM8Id85empkLyZRID6d7aHQ quuJ/OJxbqTVybDSTMyaUL5vOzO8K1w= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-117-JUpEez7VNz6vWP4D6T4EGQ-1; Tue, 19 Apr 2022 03:37:04 -0400 X-MC-Unique: JUpEez7VNz6vWP4D6T4EGQ-1 Received: by mail-ej1-f71.google.com with SMTP id sh19-20020a1709076e9300b006e8b88cb88bso5537712ejc.4 for ; Tue, 19 Apr 2022 00:37:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:organization:in-reply-to :content-transfer-encoding; bh=FM4KVGRiRcud5YspVdmyurfb+munCUhUXXDotfhbDB4=; b=XQ/UT8LTyhgIwlWCho//zfXDedIl6I4kBaX3aEmI0HbBK82Ptzg4Y4Zs0KfQABPXCY CB3oB68E5+7i+Fh3XhiI9SuVX8NqPmU76WHwLjrJM4k3D2lPJoO0BUuu+NRhDbewFDtG 2HDyRGeEUmY83T5OtH6Wo7TWR2ca1pq6GfNzkEpxsnds6c5aoeU8QGYUFo6ugEJAOc0E e5AH+snoanY0pc7FRjkF015DFZoYlSI76FYaC/N/XqBHkze1ctuJfQhbDKKqmzoUUsii YKkq41OtfkbtJObtruf2tVeTcAxHXYHN8/K7DMUAya4GHQHzTE+PH/PayeoUxJt/N95Z 1Vdw== X-Gm-Message-State: AOAM531Ufqu80Bfozg3hSO6JNrEmJUc1yoaLX7d3voAWlfEZR8tXFJtQ YceeRR5BZ4HfHQ7q/sRhB8OEBLl6UO2GLMCB7B8fjaBUoD9t/XNSaIjAnEJb3KJZ4xxgPe506wU JytuZn6sDyI8= X-Received: by 2002:a17:907:2cc7:b0:6df:b76d:940d with SMTP id hg7-20020a1709072cc700b006dfb76d940dmr12199067ejc.742.1650353823745; Tue, 19 Apr 2022 00:37:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3hG/W1nT/V3lbt+DapwBobEev6m6WKfqd6rBDyvMyzO4s4Jf3Z9XJXBOz1X7nb8ywMLE6pw== X-Received: by 2002:a17:907:2cc7:b0:6df:b76d:940d with SMTP id hg7-20020a1709072cc700b006dfb76d940dmr12199035ejc.742.1650353823437; Tue, 19 Apr 2022 00:37:03 -0700 (PDT) Received: from ?IPV6:2003:cb:c704:5d00:d8c2:fbf6:a608:957a? (p200300cbc7045d00d8c2fbf6a608957a.dip0.t-ipconnect.de. [2003:cb:c704:5d00:d8c2:fbf6:a608:957a]) by smtp.gmail.com with ESMTPSA id p9-20020a05640243c900b0041facb9ac9esm7805598edc.1.2022.04.19.00.37.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 19 Apr 2022 00:37:02 -0700 (PDT) Message-ID: Date: Tue, 19 Apr 2022 09:37:01 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.2 Subject: Re: [PATCH v2] mm/swapfile: unuse_pte can map random data if swap read fails To: 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, rcampbell@nvidia.com, naoya.horiguchi@nec.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20220416030549.60559-1-linmiaohe@huawei.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: <20220416030549.60559-1-linmiaohe@huawei.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Stat-Signature: 9z1ya3gx6xgcunrcaws4mj577x4j3ezj X-Rspam-User: Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=DZmpbzrx; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf26.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=david@redhat.com X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 7454914000B X-HE-Tag: 1650353825-219494 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 16.04.22 05:05, 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 > --- > v2: > use special swap entry to avoid permanently mounted swap > free the bad page in swapcache > --- > 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 d112434f85df..03c576111737 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 SWAP_READ_ERROR_NUM 1 > +#define SWAP_READ_ERROR (MAX_SWAPFILES + SWP_HWPOISON_NUM + \ > + SWP_MIGRATION_NUM + SWP_DEVICE_NUM + \ > + SWP_PTE_MARKER_NUM) Does anything speak against reusing the hwpoison marker? At least from a program POV it's similar "the previously well defined content at this user space address is no longer readable/writable". I recall that we can just set the pfn to 0 for the hwpoison marker. There is e.g., check_hwpoisoned_entry() and it just stops if it finds "pfn=0". -- Thanks, David / dhildenb