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 X-Spam-Level: X-Spam-Status: No, score=-3.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D20D7C4363D for ; Thu, 24 Sep 2020 14:03:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 525802220C for ; Thu, 24 Sep 2020 14:03:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="HpQfoeid" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 525802220C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9DC906B0003; Thu, 24 Sep 2020 10:03:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 98A726B0037; Thu, 24 Sep 2020 10:03:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 87A3D6B0055; Thu, 24 Sep 2020 10:03:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0060.hostedemail.com [216.40.44.60]) by kanga.kvack.org (Postfix) with ESMTP id 6F1B56B0003 for ; Thu, 24 Sep 2020 10:03:01 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id EA1BF180AD807 for ; Thu, 24 Sep 2020 14:03:00 +0000 (UTC) X-FDA: 77298121320.19.magic26_2b0346b2715f Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id F1AD21ACC3E for ; Thu, 24 Sep 2020 14:02:40 +0000 (UTC) X-HE-Tag: magic26_2b0346b2715f X-Filterd-Recvd-Size: 4771 Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Thu, 24 Sep 2020 14:02:40 +0000 (UTC) Received: by mail-qk1-f172.google.com with SMTP id q63so3338567qkf.3 for ; Thu, 24 Sep 2020 07:02:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=DX2HQBWGuaee0luRYYI4yMH5TJumhhW2wtpCA8Ku7VM=; b=HpQfoeidFIVPg4nNWvc99Nd1mzrQYL7G5U3CfwQS6NtRbSZ6TWjV3NaFirSAgay8+7 qPkj9wN/8HI6zi4hV92cb3wmwVKvcf9IjHpyIeZCPvsu5/oWGU90Z1mn4GI2RiC1FvW/ fQ+okKbI4dzzb0R6+cL3CgVL5ymexsRNylv6jWp7s88HQ7JfFjYL+vA98LXH9JudhEWI nBlZW41T72JraFIFMo+xcmWAfOnU18KTBrBdI/STIvlPMxSm+PtoRaMfTSdq9dQjU061 BPy+5vdnYnZFad3cQQ7Sk95i6VXk5j0vi9xBRE5JreeisjZhgq5OAOrjWs7jANCNWsjk boPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=DX2HQBWGuaee0luRYYI4yMH5TJumhhW2wtpCA8Ku7VM=; b=W8Z5oaWb+iT4b0k0xqB9GxqYB922E5R6d9W/EKZweBTqGOwx3RNBGG5tXI3//taqvE hJvWv36GYykZ7fXoSGgmf1j5ZPzC35rY1/sw9eFhZMdtVSRhtJNnPlf96fhooJO495em tKYQK+mdTTLrBElEuyge0qXqqa1Z0FWsxjny136pOMmHWiiwn5DZrb+ZRp/bNKrMeqSz iJ2lQcbxZ+d+MXgk51lFERL9YbqHRewBrHXc1cl80cPrr4km8vqcSYS6t41rAcoYeSCO gMvUffmI1hQRUrSeyyvrXUxKe4a7jrMGpsbNAI3IGqUYQ5LDB8GHleCk3e4sQ0ur0W7W kmCg== X-Gm-Message-State: AOAM532VCLnKUwNJfvfpXcX1F+4L99GQZcFCXc2HvYFduTp3QMyWgYg8 Gga4q6GIhK70ccBcq39iKmHQrA== X-Google-Smtp-Source: ABdhPJzdb+LYnbfPo+87vNSC6CT7v1UxrZxA4oszJTG1SGGGsOjoeh2l7+pKS8fv9n+QXuNFfGESIQ== X-Received: by 2002:ae9:e84c:: with SMTP id a73mr4721002qkg.61.1600956159787; Thu, 24 Sep 2020 07:02:39 -0700 (PDT) Received: from ziepe.ca ([206.223.160.26]) by smtp.gmail.com with ESMTPSA id x43sm2375131qtx.40.2020.09.24.07.02.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2020 07:02:38 -0700 (PDT) Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1kLRpV-000LQR-Ov; Thu, 24 Sep 2020 11:02:37 -0300 Date: Thu, 24 Sep 2020 11:02:37 -0300 From: Jason Gunthorpe To: Jan Kara Cc: Peter Xu , John Hubbard , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Michal Hocko , Kirill Tkhai , Kirill Shutemov , Hugh Dickins , Christoph Hellwig , Andrea Arcangeli , Oleg Nesterov , Leon Romanovsky , Linus Torvalds , Jann Horn Subject: Re: [PATCH 1/5] mm: Introduce mm_struct.has_pinned Message-ID: <20200924140237.GD9916@ziepe.ca> References: <224908c1-5d0f-8e01-baa9-94ec2374971f@nvidia.com> <20200922151736.GD19098@xz-x1> <20200922161046.GB731578@ziepe.ca> <20200922175415.GI19098@xz-x1> <20200922191116.GK8409@ziepe.ca> <20200923002735.GN19098@xz-x1> <20200923131043.GA59978@xz-x1> <20200923142003.GB15875@quack2.suse.cz> <20200923171207.GB9916@ziepe.ca> <20200924074409.GB27019@quack2.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200924074409.GB27019@quack2.suse.cz> 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, Sep 24, 2020 at 09:44:09AM +0200, Jan Kara wrote: > > After the page is pinned it is prevented from being freed and > > recycled. After GUP has the pin it must check that the PTE still > > points at the same page, otherwise it might have pinned a page that is > > alreay free'd - and that would be a use-after-free issue. > > I don't think a page use-after-free is really the reason - we add page > reference through page_ref_add_unless(page, x, 0) - i.e., it will fail for > already freed page. I mean, the page could have been freed and already reallocated with a positive refcount, so the add_unless check isn't protective. The add_unless prevents the page from being freed. The 2nd pte read ensures it wasn't already freed/reassigned before the pin. If something drives the page refcount to zero then it is already synchronized with GUP fast because of the atomic add_unless, no need to re-check the pte for that case?? But I don't know what the DAX case is you mentioned. Jason