Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp381377pxb; Wed, 20 Jan 2021 09:10:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJw2YGUFObt3sAmDWqQvTOXNtUCfSL/YZpZPteCgE98eO7t3Wtin8sGmplmilKgS1+HLVB+T X-Received: by 2002:a17:906:60f:: with SMTP id s15mr6050871ejb.25.1611162624806; Wed, 20 Jan 2021 09:10:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611162624; cv=none; d=google.com; s=arc-20160816; b=iSq4aZJdcCRQ9mTRHMuGJllnXbTUNdBkDDYQ+KukVOPL5/CHgxCJwtm7yxh9rwD/0Z Lz51GEQ5IPngTGCJGOGLYcbpgcxBxqUYJFchcLamw1NfqoeqmKpxxk0hQ6YA4qIciOvv mz5ca3c5G0ZXwcrnFyuiAgMC1BMBYQQb4DADl0Kag4MW6BP/fmwX94Fb//OMH730JpOI 3suPKu9DgBEx5IuRmG5xsKOJHhTdtIXDI6Emx56JSt7S4I3CGugplBz66PT116TLG+h+ ppgJXXso/xdkgrnCbC00NaCuF7dCmPHoWD0/6lmxuf+7p355VYdTPHZWBRGyC+Ugbimm gdbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=TTicKH+ytZP9IgqZUqrv8gdHefRUC9ppo1qwB8h/IcA=; b=tv3xU/JW8/uP7bHvgWJO+T4Z5H3dAzBYX7Sm+pjviFApq+A7MxCltBWC3a2A7HAunh XbQO0xJFRqjM6RYLpC5+AWE4ewS2vtQfGTmDeXNZ7igsjQRPYWHVjWctMOjBz9GQ6V1c ngyDzuA4uvSVpfFcPJvF9w/KfQ6spdBQiJJsHV4onjuLeOuyJ1iFColhb9mv6PXsm8ZR nLyrqotpvELjfpCRBO8wdxTOlsVIK+41rf346w0Q+qmzhzMhug+l9y4dnEuIy3uqu6sw uQTmMd6WRV9HWgGPiy9zwvp9zpA2PIRVUB8zyAL8Xf/SAoJKz89YysJTRpX19xt6Bpzv gYuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Vmed0anB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dp16si968440ejc.564.2021.01.20.09.09.59; Wed, 20 Jan 2021 09:10:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Vmed0anB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391488AbhATRJA (ORCPT + 99 others); Wed, 20 Jan 2021 12:09:00 -0500 Received: from mail.kernel.org ([198.145.29.99]:58714 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391685AbhATRFk (ORCPT ); Wed, 20 Jan 2021 12:05:40 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id A0CF0233E2; Wed, 20 Jan 2021 17:04:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611162296; bh=va+8yzZazWv2hNG2ZtWuIyB2nJKfDd4jMqhGqRAZb7o=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Vmed0anBzGag0Z8bSuEA0Tx/cC2Rraek86TT4ZNBf5NWU9KhkSVm47/e5qYB2EgMG Hh793Ebmr7UiucCD7spwxNAAotjKclldyTVEYvY9+Om97WYeu5OqlrmkqqKdKRpINM GV6HUfz4n8Lekq7b7M91CggobdUqgDEJR05GIrgy0oOyeyO3ODydj2WcNDpe3XSGHF QplrvZQrYQPXpoJ2Cyr26Z2rsG2RRiX+lrymQWzImJfV+oWjs+Ld2e7BrF1+MXHfM+ dqmV2WkQoEQfDON1aBRr8qJafeH3vkc+RZswoi3YHDceC2JJuhHPHvpbcu02/r+uVD Qbg9LOZsR6tsA== Date: Wed, 20 Jan 2021 19:04:39 +0200 From: Mike Rapoport To: Matthew Wilcox Cc: Andrew Morton , Alexander Viro , Andy Lutomirski , Arnd Bergmann , Borislav Petkov , Catalin Marinas , Christopher Lameter , Dan Williams , Dave Hansen , David Hildenbrand , Elena Reshetova , "H. Peter Anvin" , Ingo Molnar , James Bottomley , "Kirill A. Shutemov" , Mark Rutland , Mike Rapoport , Michael Kerrisk , Palmer Dabbelt , Paul Walmsley , Peter Zijlstra , Rick Edgecombe , Roman Gushchin , Shakeel Butt , Shuah Khan , Thomas Gleixner , Tycho Andersen , Will Deacon , linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-nvdimm@lists.01.org, linux-riscv@lists.infradead.org, x86@kernel.org, Hagen Paul Pfeifer Subject: Re: [PATCH v14 05/10] mm: introduce memfd_secret system call to create "secret" memory areas Message-ID: <20210120170439.GP1106298@kernel.org> References: <20201203062949.5484-1-rppt@kernel.org> <20201203062949.5484-6-rppt@kernel.org> <20210119202213.GI2260413@casper.infradead.org> <20210120150510.GO1106298@kernel.org> <20210120160210.GK2260413@casper.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210120160210.GK2260413@casper.infradead.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 20, 2021 at 04:02:10PM +0000, Matthew Wilcox wrote: > On Wed, Jan 20, 2021 at 05:05:10PM +0200, Mike Rapoport wrote: > > On Tue, Jan 19, 2021 at 08:22:13PM +0000, Matthew Wilcox wrote: > > > On Thu, Dec 03, 2020 at 08:29:44AM +0200, Mike Rapoport wrote: > > > > +static vm_fault_t secretmem_fault(struct vm_fault *vmf) > > > > +{ > > > > + struct address_space *mapping = vmf->vma->vm_file->f_mapping; > > > > + struct inode *inode = file_inode(vmf->vma->vm_file); > > > > + pgoff_t offset = vmf->pgoff; > > > > + vm_fault_t ret = 0; > > > > + unsigned long addr; > > > > + struct page *page; > > > > + int err; > > > > + > > > > + if (((loff_t)vmf->pgoff << PAGE_SHIFT) >= i_size_read(inode)) > > > > + return vmf_error(-EINVAL); > > > > + > > > > + page = find_get_page(mapping, offset); > > > > + if (!page) { > > > > + > > > > + page = secretmem_alloc_page(vmf->gfp_mask); > > > > + if (!page) > > > > + return vmf_error(-ENOMEM); > > > > > > Just use VM_FAULT_OOM directly. > > > > Ok. > > > > > > + err = add_to_page_cache(page, mapping, offset, vmf->gfp_mask); > > > > + if (unlikely(err)) > > > > + goto err_put_page; > > > > > > What if the error is EEXIST because somebody else raced with you to add > > > a new page to the page cache? > > > > Right, for -EEXIST I need a retry here, thanks. > > > > > > + err = set_direct_map_invalid_noflush(page, 1); > > > > + if (err) > > > > + goto err_del_page_cache; > > > > > > Does this work correctly if somebody else has a reference to the page > > > in the meantime? > > > > Yes, it does. If somebody else won the race that page was dropped from the > > direct map and this call would be essentially a nop. And anyway, the very > > next patch changes the way pages are removed from the direct map ;-) > > What I'm thinking is: > > thread A page faults > doesn't find page > allocates page > adds page to page cache > thread B page faults > does find page in page cache > set direct map invalid fails > deletes from page cache > ... ? Hmm, this is not nice indeed... -- Sincerely yours, Mike.