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 37815C433F5 for ; Tue, 19 Apr 2022 11:14:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C12EA8D0063; Tue, 19 Apr 2022 07:14:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BBFD28D0047; Tue, 19 Apr 2022 07:14:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A60308D0063; Tue, 19 Apr 2022 07:14:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0129.hostedemail.com [216.40.44.129]) by kanga.kvack.org (Postfix) with ESMTP id 963E28D0047 for ; Tue, 19 Apr 2022 07:14:34 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 54CE118289F7F for ; Tue, 19 Apr 2022 11:14:34 +0000 (UTC) X-FDA: 79373370468.30.6B61443 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf16.hostedemail.com (Postfix) with ESMTP id 511A018000E for ; Tue, 19 Apr 2022 11:14:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650366873; 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=tI8tC7M7FOnSjVVan7Dl8S2hnr3ClK5HwT08ub3keLk=; b=bZyokd9njrfL0d2QhQiFcTE3SSw0LawWJNAd8WJaRzVhwhJ+I49N5Ltg2Eb8quY9f4Sghl jVew8WJAcUqjbveEki3jv5OTzjNyhrHlUCSfPKgK4wzX/1tjSwiBSP+DvTfbxgscB6Ozg5 IH7O78/GKCZbsCaVrmC9016talUXdmE= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-91-l-rl6_qmONGjt1rpZpO0Cw-1; Tue, 19 Apr 2022 07:14:32 -0400 X-MC-Unique: l-rl6_qmONGjt1rpZpO0Cw-1 Received: by mail-wr1-f72.google.com with SMTP id v21-20020adfa1d5000000b0020a80b3b107so833679wrv.0 for ; Tue, 19 Apr 2022 04:14:32 -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 :content-language:to:cc:references:from:organization:subject :in-reply-to:content-transfer-encoding; bh=tI8tC7M7FOnSjVVan7Dl8S2hnr3ClK5HwT08ub3keLk=; b=JLUXZKpNOc+0QqSaYm2kj93ajPQK75tRqYKPT+Qf5czrnesOIUC5flmrsBYDkW66XQ 17CWL5eE4ExgXslQRlWNpdVC2YshiluuqzlUT3XPzvdo3qAJymy7BCiP0T/VC4T+U0qG IKdtdAkiY/thLfZkZ4zdsRZMUkDUgGhY3IsWfKxiosrm0suMA+Mm/oVTCbXXocO3gqCY mD2xWPHIauCT2mZoKhizhbMAC5NpcF3Lizd1MK8QbC6Odk+yQUkQMFZq2w5/YLCJH/gP BkAGIERHLFmNgX51aW28S6jm3uTCbocQB/tdF+t1PBe8M1lQKMfCup7fGg5gjDeZiS7V IeBw== X-Gm-Message-State: AOAM533vBIbGu2yDOJHLDZSq8N4eJsZ9iBwPldQ74BuvSZ7iJ8mpZMNp +z9CsLKxTY5Mt3+tf9GuvCGRn21SiPOhf0shmSaLyNG2UGA92rwp3FOi/fKLihT5iQqMO7itZiK 1B8VEN4bEoCM= X-Received: by 2002:a7b:cbd3:0:b0:38e:bc95:5048 with SMTP id n19-20020a7bcbd3000000b0038ebc955048mr15670623wmi.203.1650366871036; Tue, 19 Apr 2022 04:14:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw31+3IeKIX4RGpI3eJ6i8AGhxWRNH1+xULyuevom6pT9dOS+6cHlxz7ntNmwSZdUUzV4rb2g== X-Received: by 2002:a7b:cbd3:0:b0:38e:bc95:5048 with SMTP id n19-20020a7bcbd3000000b0038ebc955048mr15670582wmi.203.1650366870738; Tue, 19 Apr 2022 04:14:30 -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 d5-20020a056000186500b0020a8688963bsm8956346wri.89.2022.04.19.04.14.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 19 Apr 2022 04:14:30 -0700 (PDT) Message-ID: <21003e7a-01e4-c751-dd41-fce4149d424c@redhat.com> Date: Tue, 19 Apr 2022 13:14:29 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.2 To: Alistair Popple Cc: Miaohe Lin , akpm@linux-foundation.org, willy@infradead.org, vbabka@suse.cz, dhowells@redhat.com, neilb@suse.de, 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> <87tuapk9n7.fsf@nvdebian.thelocal> <5a78dd68-343d-ac57-a698-2cfead8ee366@huawei.com> <72cfde7a-61d7-980c-4653-94ae83eb4257@redhat.com> <87pmldjxiq.fsf@nvdebian.thelocal> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v2] mm/swapfile: unuse_pte can map random data if swap read fails In-Reply-To: <87pmldjxiq.fsf@nvdebian.thelocal> 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-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 511A018000E X-Rspam-User: Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bZyokd9n; spf=none (imf16.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Stat-Signature: 3b1zzko4tkszprf3jt4q8okmeotmn3cf X-HE-Tag: 1650366873-236092 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 19.04.22 10:08, Alistair Popple wrote: > David Hildenbrand writes: > >> On 19.04.22 09:29, Miaohe Lin wrote: >>> On 2022/4/19 11:51, Alistair Popple wrote: >>>> Miaohe Lin writes: >>>> >>>>> 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. >>>> >>>> Hi Miaohe, >>>>> It seems we're not actually using the pfn that gets stored in the special swap >>>> entry here. Is my understanding correct? If so I think it would be better to use >>> >>> Yes, you're right. The pfn is not used now. What we need here is a special swap entry >>> to do the right things. I think we can change to store some debugging information instead >>> of pfn if needed in the future. >>> >>>> the new PTE markers Peter introduced[1] rather than adding another swap entry >>>> type. >>> >>> IIUC, we should not reuse that swap entry here. From definition: >>> >>> PTE markers >>> `=========' >>> ... >>> PTE marker is a new type of swap entry that is ony applicable to file >>> backed memories like shmem and hugetlbfs. It's used to persist some >>> pte-level information even if the original present ptes in pgtable are >>> zapped. >>> >>> It's designed for file backed memories while swapin error entry is for anonymous >>> memories. And there has some differences in processing. So it's not a good idea >>> to reuse pte markers. Or am I miss something? >> >> I tend to agree. As raised in my other reply, maybe we can simply reuse >> hwpoison entries and update the documentation of them accordingly. > > Unless I've missed something I don't think PTE markers should be restricted > solely to file backed memory. It's true that the only user of them at the moment > is UFFD-WP for file backed memory, but PTE markers are just a special swap entry > same as what is added here. There is a difference. What we want here is "there used to be something mapped but it's not readable anymore. Please fail hard when userspace tries accessing this.". Just like with hwpoison entries. What a pte marker expresses is that "here is nothing mapped right now but we have additional metadata available here. For file-backed memory, it translates to: If we ever touch this page, lookup the pagecache what to map here." In the anonymous memory world, this would map to "populate the zeropage or a fresh anonymous page on access." and keep the metadata around. Yes, one might argue that for uffd-wp on anonymous memory it might make sense to use pte marker as well, when no page has been populated yet. IIRC, trying to arm uffd-wp when there is nothing populated yet will simply get ignored. > > That said I don't think there has been any attempt to make PTE markers work for > anything other than UFFD-WP because it was unclear if there ever would be > another user. We discussed using it for softdirty tracking as well. -- Thanks, David / dhildenb