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 1A650C433EF for ; Tue, 8 Mar 2022 13:32:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8FDB78D0002; Tue, 8 Mar 2022 08:32:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8AC828D0001; Tue, 8 Mar 2022 08:32:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 759878D0002; Tue, 8 Mar 2022 08:32:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 638D28D0001 for ; Tue, 8 Mar 2022 08:32:32 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 3CCC819DF for ; Tue, 8 Mar 2022 13:32:32 +0000 (UTC) X-FDA: 79221308544.15.07B80C9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf22.hostedemail.com (Postfix) with ESMTP id A68DCC000A for ; Tue, 8 Mar 2022 13:32:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646746351; 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=iSB2Ol/nnrrRd3g4Qot/m3+tnisbJitEe8TFiqjPaUA=; b=L6NFMhjNlG/YryuDlL+ZkOw9cv+uSxSIhizF0zTjPKFizbtvRsPFYy+EI+ZLWI3Bf3zNhC jHUitSt+zPPbN8nVRsSZM3u/MjNKIrFDqkwCW7Uz22JmNsPE0dOx5W+SfUzVgYiswlabuN M7Oa0NMAdyJSRUKw0U8oWKxXY3On0t8= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-116-4_Aw36fMMWihHES4AdW19A-1; Tue, 08 Mar 2022 08:32:29 -0500 X-MC-Unique: 4_Aw36fMMWihHES4AdW19A-1 Received: by mail-wm1-f72.google.com with SMTP id f189-20020a1c38c6000000b0037d1bee4847so1156736wma.9 for ; Tue, 08 Mar 2022 05:32:28 -0800 (PST) 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=iSB2Ol/nnrrRd3g4Qot/m3+tnisbJitEe8TFiqjPaUA=; b=Y3BmO/DF9/a67CzWG77tey1bdqHg5W/w0PJBqqFCsvuMs4h/JN3Bj5d9bZEY6ZtYVo pZNF+4zf2Y2KRXKGCADljfXImjLs4FKwxgB7OmiPavleoCmwJQXksfS0xMzNrCDY+35c jRfHRS3lVyLdjAvcNMQAahu0l5EIOXQogEoACS9sSZXPaGDlLnwtFqdummFIxRllb8Ry 7aECciU2uiruyfPGZZ9MnN07EKnIhqWQbQMQ8IlP4GSBUwK76u80Ch22zeYLnJ5IuQLk GI8rBdR5ImsXvG6ypdyn//ano756Vf9VNomPMiMM+I8P0txoY5LWF79x4KRqf023klgW fikw== X-Gm-Message-State: AOAM531itXyIfzxG/LH8L1Xf1PJuFT1Eyc4OyykeXwfuE4HpOFaWnUgo YBnjMm4fJB8oen1gZ0qkS49QP6GoWE7ZyRoUCKVMC0WcaSI1zhVvtBTESPomCeGhqLQ6wsMUyxk GpR/fU0RMUUY= X-Received: by 2002:a1c:f003:0:b0:381:17f5:21b8 with SMTP id a3-20020a1cf003000000b0038117f521b8mr3549026wmb.158.1646746347797; Tue, 08 Mar 2022 05:32:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJzmpaWAjeRm0d1i/b5jSMA7gKRkARjJJZmqUgvv3qpUXLmIJkGjHmpvaHNXbNDVRpDo9Z4ZIQ== X-Received: by 2002:a1c:f003:0:b0:381:17f5:21b8 with SMTP id a3-20020a1cf003000000b0038117f521b8mr3549001wmb.158.1646746347524; Tue, 08 Mar 2022 05:32:27 -0800 (PST) Received: from ?IPV6:2003:cb:c708:b000:acda:b420:16aa:6b67? (p200300cbc708b000acdab42016aa6b67.dip0.t-ipconnect.de. [2003:cb:c708:b000:acda:b420:16aa:6b67]) by smtp.gmail.com with ESMTPSA id f20-20020a05600c4e9400b003898e252cd4sm2599464wmq.12.2022.03.08.05.32.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 08 Mar 2022 05:32:26 -0800 (PST) Message-ID: Date: Tue, 8 Mar 2022 14:32:25 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 To: Gerald Schaefer Cc: Linus Torvalds , Andreas Gruenbacher , Alexander Viro , linux-s390 , Linux-MM , linux-fsdevel , linux-btrfs , Christian Borntraeger , Jason Gunthorpe , John Hubbard , "akpm@linux-foundation.org" , Heiko Carstens , Alexander Gordeev References: <2266e1a8-ac79-94a1-b6e2-47475e5986c5@redhat.com> <81f2f76d-24ef-c23b-449e-0b8fdec506e1@redhat.com> <1bdb0184-696c-0f1a-3054-d88391c32e64@redhat.com> <20220308142047.7a725518@thinkpad> From: David Hildenbrand Organization: Red Hat Subject: Re: Buffered I/O broken on s390x with page faults disabled (gfs2) In-Reply-To: <20220308142047.7a725518@thinkpad> 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-Queue-Id: A68DCC000A X-Stat-Signature: 7y4pcjq9as4k7pkum3jr8z99snms7afr X-Rspam-User: Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=L6NFMhjN; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf22.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=david@redhat.com X-Rspamd-Server: rspam03 X-HE-Tag: 1646746351-112257 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 08.03.22 14:20, Gerald Schaefer wrote: > On Tue, 8 Mar 2022 13:24:19 +0100 > David Hildenbrand wrote: > > [...] >> >> From 1e51e8a93894f87c0a4d0e908391e0628ae56afe Mon Sep 17 00:00:00 2001 >> From: David Hildenbrand >> Date: Tue, 8 Mar 2022 12:51:26 +0100 >> Subject: [PATCH] mm/gup: fix buffered I/O on s390x with pagefaults disabled >> >> On s390x, we actually need a pte_mkyoung() / pte_mkdirty() instead of >> going via the page and leaving the PTE unmodified. E.g., if we only >> mark the page accessed via mark_page_accessed() when doing a FOLL_TOUCH, >> we'll miss to clear the HW invalid bit in the pte and subsequent accesses >> via the MMU would still require a pagefault. >> >> Otherwise, buffered I/O will loop forever because it will keep stumling >> over the set HW invalid bit, requiring a page fault. >> >> Reported-by: Andreas Gruenbacher >> Signed-off-by: David Hildenbrand >> --- >> mm/gup.c | 32 +++++++++++++++++++++++++------- >> 1 file changed, 25 insertions(+), 7 deletions(-) >> >> diff --git a/mm/gup.c b/mm/gup.c >> index a9d4d724aef7..de3311feb377 100644 >> --- a/mm/gup.c >> +++ b/mm/gup.c >> @@ -587,15 +587,33 @@ static struct page *follow_page_pte(struct vm_area_struct *vma, >> } >> } >> if (flags & FOLL_TOUCH) { >> - if ((flags & FOLL_WRITE) && >> - !pte_dirty(pte) && !PageDirty(page)) >> - set_page_dirty(page); >> /* >> - * pte_mkyoung() would be more correct here, but atomic care >> - * is needed to avoid losing the dirty bit: it is easier to use >> - * mark_page_accessed(). >> + * We have to be careful with updating the PTE on architectures >> + * that have a HW dirty bit: while updating the PTE we might >> + * lose that bit again and we'd need an atomic update: it is >> + * easier to leave the PTE untouched for these architectures. >> + * >> + * s390x doesn't have a hw referenced / dirty bit and e.g., sets >> + * the hw invalid bit in pte_mkold(), to catch further >> + * references. We have to update the PTE here to e.g., clear the >> + * invalid bit; otherwise, callers that rely on not requiring >> + * an MMU fault once GUP(FOLL_TOUCH) succeeded will loop forever >> + * because the page won't actually be accessible via the MMU. >> */ >> - mark_page_accessed(page); >> + if (IS_ENABLED(CONFIG_S390)) { >> + pte = pte_mkyoung(pte); >> + if (flags & FOLL_WRITE) >> + pte = pte_mkdirty(pte); >> + if (!pte_same(pte, *ptep)) { >> + set_pte_at(vma->vm_mm, address, ptep, pte); >> + update_mmu_cache(vma, address, ptep); >> + } >> + } else { >> + if ((flags & FOLL_WRITE) && >> + !pte_dirty(pte) && !PageDirty(page)) >> + set_page_dirty(page); >> + mark_page_accessed(page); >> + } >> } >> if ((flags & FOLL_MLOCK) && (vma->vm_flags & VM_LOCKED)) { >> /* Do not mlock pte-mapped THP */ > > Thanks David, your analysis looks valid, at least it seems that you found > a scenario where we would have HW invalid bit set due to pte_mkold() in > ptep_clear_flush_young(), and still GUP would find and return that page, IIUC. > > I think pte handling should be similar to pmd handling in follow_trans_huge_pmd() > -> touch_pmd(), or cow_user_page() (see comment on software "accessed" bits), > which is more or less what your patch does. > > Some possible concerns: > - set_page_dirty() would not be done any more for s390, is that intended and ok? I strongly assume so, because the page is mapped via a PTE, which is writable and dirty. This is similar to THP logic. > - using set_pte_at() here seems a bit dangerous, as I'm not sure if this will > always only operate on invalid PTEs. Using it on active valid PTEs could > result in TLB issues because of missing flush. Also not sure about kvm impact. > Using ptep_set_access_flags() seems safer, again similar to touch_pmd() and > also cow_user_page(). Yeah, I sticked to what follow_pfn_pte() does for simplicity for now. But I agree that following what touch_pmd() does looks saner -- ptep_set_access_flags(). > > Looking at cow_user_page(), I also wonder if the arch_faults_on_old_pte() > logic could be used here. I must admit that I did not really understand the > "losing the dirty bit" part of the comment, but it seems that we might need > to not only check for arch_faults_on_old_pte(), but also for something like > "arch_faults_for_dirty_pte". > > Last but not least, IIUC, this issue should affect all archs that return > true on arch_faults_on_old_pte(). After all, the basic problem seems to be > that a pagefault is required for PTEs marked as old, in combination with > GUP still returning a valid page. So maybe this should not be restricted > to IS_ENABLED(CONFIG_S390). Yeah, as raised, the IS_ENABLED(CONFIG_S390) part is just a quick hack to see if this would fix the issue. arch_faults_on_dirty_pte / arch_faults_on_old_pte might be a replacement. We just would have to be careful for architectures that e.g., have arch_faults_on_old_pte=true and arch_faults_on_dirty_pte=false (i.e., hw dirty bit but no hw accessed bit). Would have to think about how to handle that properly ... Thanks! -- Thanks, David / dhildenb