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 1EF30C433EF for ; Thu, 14 Apr 2022 21:08:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 86D7B6B0071; Thu, 14 Apr 2022 17:08:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 81E586B0073; Thu, 14 Apr 2022 17:08:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 696D46B0074; Thu, 14 Apr 2022 17:08:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id 569A96B0071 for ; Thu, 14 Apr 2022 17:08:21 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 1DCED12343A for ; Thu, 14 Apr 2022 21:08:21 +0000 (UTC) X-FDA: 79356722802.11.0597640 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf29.hostedemail.com (Postfix) with ESMTP id 5CFEB12000A for ; Thu, 14 Apr 2022 21:08:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649970499; 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: in-reply-to:in-reply-to:references:references; bh=50hb9t2hWQpx3A7gqpiBQ8RZfEOgSrHlGcFbRUMDwYE=; b=a1PxToFf9FiIv0/7j2R0mjkPDOVjYsT/wKhiztBcXuObjxtVSffJWRuyl9qpOvB7tTTX1u 40WUVh55yT3jWayhOJOkxIAQ9sycHIqllB7Uvss2yuIkKr537MCsgaXwjHVJG3ZUT6KOZ1 2Q5C6fMXkFZ9pZWnk1HkaexJsK53Fqo= Received: from mail-il1-f199.google.com (mail-il1-f199.google.com [209.85.166.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-66-_yATKpqBPOqz2_N_Eme5Jg-1; Thu, 14 Apr 2022 17:08:18 -0400 X-MC-Unique: _yATKpqBPOqz2_N_Eme5Jg-1 Received: by mail-il1-f199.google.com with SMTP id v14-20020a056e020f8e00b002caa6a5d918so3704763ilo.15 for ; Thu, 14 Apr 2022 14:08:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=50hb9t2hWQpx3A7gqpiBQ8RZfEOgSrHlGcFbRUMDwYE=; b=ZneVXqwp55TNnFu1e3kkk+xCyOGv5Wh8F7LxT5vYbBxWbYeibAK8lajdJIslbso6YZ IH1z6KwslmsZxyuV71LRJ9gRK7ot+K2op3txvPNh5u0lJLRPvnXThkeP7P+Wng9pNow7 +IlB9GQDYXt8edQt8jUNHqNnP2J0tJ6vBsMdatGyff2emxbpZhQ+hTr07V2ncwl1PwZf nEViWpw5Awq4PmhI60By5MYePxsG7DSEDanLNu/eUkje/YxQBV4d83uBufyd+ibN8hln kzLRCvd9fNiTJFVTHcJ/69jC8cbdthgWiiOmDVp7wpcsEXZj3LxGv68xEVOQlN/iZwyo qIBg== X-Gm-Message-State: AOAM5339OUImriA230dHc73+rpX8Y3paM/fJ1Lc/x/DIFr4lj3HNxwE+ 5v4efS1XpZa+Rf50VhdL35ANugMsTsxg8HonQH+woObmpT3/s5QDlg+9OLw4iaeNrnLMb3/Clsf vpEg2lEKyhmo= X-Received: by 2002:a02:a40d:0:b0:326:72dd:feb8 with SMTP id c13-20020a02a40d000000b0032672ddfeb8mr2047804jal.303.1649970498008; Thu, 14 Apr 2022 14:08:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzrSXg03wSwlqNUJEo5bOLrh3rEmDmIMlVB4DukeCQuZK49xyTij9i84kCWVWLY49WnoHGUTQ== X-Received: by 2002:a02:a40d:0:b0:326:72dd:feb8 with SMTP id c13-20020a02a40d000000b0032672ddfeb8mr2047790jal.303.1649970497702; Thu, 14 Apr 2022 14:08:17 -0700 (PDT) Received: from xz-m1.local (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id h24-20020a6bfb18000000b006497692016bsm1800923iog.15.2022.04.14.14.08.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Apr 2022 14:08:17 -0700 (PDT) Date: Thu, 14 Apr 2022 17:08:15 -0400 From: Peter Xu To: Andrew Morton Cc: Marek Szyprowski , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Mike Kravetz , Nadav Amit , Matthew Wilcox , Mike Rapoport , David Hildenbrand , Hugh Dickins , Jerome Glisse , "Kirill A . Shutemov" , Andrea Arcangeli , Axel Rasmussen , Alistair Popple Subject: Re: [PATCH v8 03/23] mm: Check against orig_pte for finish_fault() Message-ID: References: <20220405014646.13522-1-peterx@redhat.com> <20220405014836.14077-1-peterx@redhat.com> <710c48c9-406d-e4c5-a394-10501b951316@samsung.com> <6ccf5f5f-8dc5-16cc-f06c-78401b822a54@samsung.com> <20220414135740.42fb26be9e13d2aada35f140@linux-foundation.org> MIME-Version: 1.0 In-Reply-To: <20220414135740.42fb26be9e13d2aada35f140@linux-foundation.org> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Rspam-User: X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 5CFEB12000A X-Stat-Signature: cjog9at1iiod4x3q8zddjpjpuopqau8h Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=a1PxToFf; spf=none (imf29.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-HE-Tag: 1649970500-906136 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 Thu, Apr 14, 2022 at 01:57:40PM -0700, Andrew Morton wrote: > On Thu, 14 Apr 2022 12:30:06 -0400 Peter Xu wrote: > > > > Reported-by: Marek Szyprowski > > > > > > Tested-by: Marek Szyprowski > > > > Thanks, Marek, for the fast feedback! > > Certainly. > > > I've also verified it for the uffd-wp case so the whole series keeps > > running as usual and nothing else shows up after the new patch replaced. > > > > Andrew, any suggestion on how we proceed with the replacement patch? > > E.g. do you want me to post it separately to the list? > > I turned it into an incremental diff and queued it against [03/23]: > > --- a/include/linux/mm_types.h~mm-check-against-orig_pte-for-finish_fault-fix > +++ a/include/linux/mm_types.h > @@ -814,6 +814,8 @@ typedef struct { > * @FAULT_FLAG_UNSHARE: The fault is an unsharing request to unshare (and mark > * exclusive) a possibly shared anonymous page that is > * mapped R/O. > + * @FAULT_FLAG_ORIG_PTE_VALID: whether the fault has vmf->orig_pte cached. > + * We should only access orig_pte if this flag set. > * > * About @FAULT_FLAG_ALLOW_RETRY and @FAULT_FLAG_TRIED: we can specify > * whether we would allow page faults to retry by specifying these two > @@ -850,6 +852,7 @@ enum fault_flag { > FAULT_FLAG_INSTRUCTION = 1 << 8, > FAULT_FLAG_INTERRUPTIBLE = 1 << 9, > FAULT_FLAG_UNSHARE = 1 << 10, > + FAULT_FLAG_ORIG_PTE_VALID = 1 << 11, > }; > > #endif /* _LINUX_MM_TYPES_H */ > --- a/mm/memory.c~mm-check-against-orig_pte-for-finish_fault-fix > +++ a/mm/memory.c > @@ -4194,6 +4194,15 @@ void do_set_pte(struct vm_fault *vmf, st > set_pte_at(vma->vm_mm, addr, vmf->pte, entry); > } > > +static bool vmf_pte_changed(struct vm_fault *vmf) > +{ > + if (vmf->flags & FAULT_FLAG_ORIG_PTE_VALID) { > + return !pte_same(*vmf->pte, vmf->orig_pte); > + } > + > + return !pte_none(*vmf->pte); > +} > + > /** > * finish_fault - finish page fault once we have prepared the page to fault > * > @@ -4252,7 +4261,7 @@ vm_fault_t finish_fault(struct vm_fault > vmf->address, &vmf->ptl); > ret = 0; > /* Re-check under ptl */ > - if (likely(pte_same(*vmf->pte, vmf->orig_pte))) > + if (likely(!vmf_pte_changed(vmf))) > do_set_pte(vmf, page, vmf->address); > else > ret = VM_FAULT_NOPAGE; > @@ -4720,13 +4729,7 @@ static vm_fault_t handle_pte_fault(struc > * concurrent faults and from rmap lookups. > */ > vmf->pte = NULL; > - /* > - * Always initialize orig_pte. This matches with below > - * code to have orig_pte to be the none pte if pte==NULL. > - * This makes the rest code to be always safe to reference > - * it, e.g. in finish_fault() we'll detect pte changes. > - */ > - pte_clear(vmf->vma->vm_mm, vmf->address, &vmf->orig_pte); > + vmf->flags &= ~FAULT_FLAG_ORIG_PTE_VALID; > } else { > /* > * If a huge pmd materialized under us just retry later. Use > @@ -4750,6 +4753,7 @@ static vm_fault_t handle_pte_fault(struc > */ > vmf->pte = pte_offset_map(vmf->pmd, vmf->address); > vmf->orig_pte = *vmf->pte; > + vmf->flags |= FAULT_FLAG_ORIG_PTE_VALID; > > /* > * some architectures can have larger ptes than wordsize, > _ > I verified the diff, that matches with what I got. Thanks Andrew. -- Peter Xu