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=-6.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 23E9AC433E0 for ; Wed, 20 Jan 2021 15:05:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 927C323381 for ; Wed, 20 Jan 2021 15:05:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 927C323381 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9607D6B0007; Wed, 20 Jan 2021 10:05:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8E9296B0008; Wed, 20 Jan 2021 10:05:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7629D6B000A; Wed, 20 Jan 2021 10:05:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0093.hostedemail.com [216.40.44.93]) by kanga.kvack.org (Postfix) with ESMTP id 5F1576B0007 for ; Wed, 20 Jan 2021 10:05:27 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 29306824999B for ; Wed, 20 Jan 2021 15:05:27 +0000 (UTC) X-FDA: 77726477094.14.shoes57_62030692755b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin14.hostedemail.com (Postfix) with ESMTP id 020EA1822989D for ; Wed, 20 Jan 2021 15:05:26 +0000 (UTC) X-HE-Tag: shoes57_62030692755b X-Filterd-Recvd-Size: 5327 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Wed, 20 Jan 2021 15:05:26 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 7A01A23356; Wed, 20 Jan 2021 15:05:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611155125; bh=9874V4EQF8pGhQeRtiLlHuHTZWGypK1q+CZx02TXhZM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=uVer5+wzd/VviGPx62NgeNadLX736EMkLOQOVHuy+k8sx0BcR+ivCEkKsnZIoxtnT GpWkXKSHUVrX3tMi+iQiZNVYUchhp0zB4TrjPy0CuHAyWgurs4kWeeuPwxfawgBGve xWg9JGEgJG54bZgaB141RZ4cuaX9zxlmp5uYxxVFC9vITcsuqfvwAakLkytsiWOGfL pNtcU5EE62T/qNQ15LxVmcJccjD7XRVg6hOvj3C8536te+4LBKab+YM8J44PRYhLZX NgPhXfCDCBlcUFMljfwDktrV1a/D2LNFJaqimj3Xi9rVUzUTR1HHM4iQVtrs0WE0Q2 /+v3XgxNylKfQ== Date: Wed, 20 Jan 2021 17:05:10 +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: <20210120150510.GO1106298@kernel.org> References: <20201203062949.5484-1-rppt@kernel.org> <20201203062949.5484-6-rppt@kernel.org> <20210119202213.GI2260413@casper.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210119202213.GI2260413@casper.infradead.org> 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 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 ;-) > > + addr = (unsigned long)page_address(page); > > + flush_tlb_kernel_range(addr, addr + PAGE_SIZE); > > + > > + __SetPageUptodate(page); > > Once you've added it to the cache, somebody else can come along and try > to lock it. They will set PageWaiter. Now you call __SetPageUptodate > and wipe out their PageWaiter bit. So you won't wake them up when you > unlock. > > You can call __SetPageUptodate before adding it to the page cache, > but once it's visible to another thread, you can't do that. Will fix. > > + ret = VM_FAULT_LOCKED; > > + } > > + > > + vmf->page = page; > > You're supposed to return the page locked, so use find_lock_page() instead > of find_get_page(). Ok/ > > + return ret; > > + > > +err_del_page_cache: > > + delete_from_page_cache(page); > > +err_put_page: > > + put_page(page); > > + return vmf_error(err); > > +} -- Sincerely yours, Mike.