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 84730C433E0 for ; Wed, 20 Jan 2021 17:17:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 52EBC22CE3 for ; Wed, 20 Jan 2021 17:17:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390101AbhATRGj (ORCPT ); Wed, 20 Jan 2021 12:06:39 -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-api@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. 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.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 7CFBFC433DB for ; Wed, 20 Jan 2021 17:05:00 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 38453233EF for ; Wed, 20 Jan 2021 17:04:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 38453233EF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 964D9100EB857; Wed, 20 Jan 2021 09:04:59 -0800 (PST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=198.145.29.99; helo=mail.kernel.org; envelope-from=rppt@kernel.org; receiver= Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id D9E1E100EB855 for ; Wed, 20 Jan 2021 09:04:56 -0800 (PST) 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 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-Disposition: inline In-Reply-To: <20210120160210.GK2260413@casper.infradead.org> Message-ID-Hash: WE7ORKWY3SR5EW6LKOXZX4ZHJXELN5OK X-Message-ID-Hash: WE7ORKWY3SR5EW6LKOXZX4ZHJXELN5OK X-MailFrom: rppt@kernel.org X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation CC: Andrew Morton , Alexander Viro , Andy Lutomirski , Arnd Bergmann , Borislav Petkov , Catalin Marinas , Christopher Lameter , 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 X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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. _______________________________________________ Linux-nvdimm mailing list -- linux-nvdimm@lists.01.org To unsubscribe send an email to linux-nvdimm-leave@lists.01.org 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=-4.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED 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 D8F5BC433E6 for ; Wed, 20 Jan 2021 17:05:34 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8F8FE22CE3 for ; Wed, 20 Jan 2021 17:05:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8F8FE22CE3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=BbddkltkxfIX05ZxFazz1hM58neskjUgIiCfHp7GOO8=; b=oZF6N/n9fpI0gFU6yH4xxCgy1 mgGaQd5sfvpLFB3Le8D/YAZXNksKkqR3yEj2VERfnhsK82sxEJq0KIJRatcFLQ2gQmvGryh14Cp4/ YkMcL9aBCPtGg5Hl/Z88ryG2vujl9m6gIYic4VNqprs3aVBeJJFVTcyiFd4SU0WOdYuw15zQcgqWV Ucn2MvAfreGFRzC7yvPcnC2+y5aP3e0NW/YTggOUtRB2PBS0gd7sficCTcrQkzNpAFEfAsJnq+glc MUSX+dB9bE/pT1MgLT7u54zDPo5e4q+AMX7infRkxTcko2GYLBPp3pCLIrXD8uHK0xgvlbmkLM5V+ tGyjr8FqQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2Gul-0007VR-KV; Wed, 20 Jan 2021 17:05:03 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2Guf-0007Sy-C7; Wed, 20 Jan 2021 17:04:58 +0000 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 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-Disposition: inline In-Reply-To: <20210120160210.GK2260413@casper.infradead.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210120_120457_563183_17897854 X-CRM114-Status: GOOD ( 24.47 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , David Hildenbrand , Peter Zijlstra , Catalin Marinas , Dave Hansen , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, "H. Peter Anvin" , Christopher Lameter , Shuah Khan , Thomas Gleixner , Elena Reshetova , linux-arch@vger.kernel.org, Tycho Andersen , linux-nvdimm@lists.01.org, Will Deacon , x86@kernel.org, linux-riscv@lists.infradead.org, Mike Rapoport , Ingo Molnar , Michael Kerrisk , Arnd Bergmann , James Bottomley , Hagen Paul Pfeifer , Borislav Petkov , Alexander Viro , Andy Lutomirski , Paul Walmsley , "Kirill A. Shutemov" , Dan Williams , linux-arm-kernel@lists.infradead.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, Palmer Dabbelt , linux-fsdevel@vger.kernel.org, Shakeel Butt , Andrew Morton , Rick Edgecombe , Roman Gushchin Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.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. _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv 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=-4.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED 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 85E87C433E0 for ; Wed, 20 Jan 2021 17:06:54 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 410752242A for ; Wed, 20 Jan 2021 17:06:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 410752242A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Fd+RGUwmbimvooCHWedc8z63IGnAHM7WvL5PfwkPv+E=; b=qMwXNDRBSohw1DRaCRvohe3Vb 9FU7zWskHcEqJKdEFmH5fdJDlUytN7Vq8kY9lzUk3KTEWOTizzNuBAIHtLyLYBDwtQmnkhewZdRE5 N/Czg7APJ3UKOmYHlLkTh2hRDP4Bs8l9K8FifW3m5/KXs5AU1OyJIutTFjf7Qt6LzKmXr+RF8qn+S nLPp8GXqS0ozn+A6ffEzrI5tp8CF6uS9H9u8CtyKLWBJNI+oJvk1TvM25wkJDnqPYW7GpoLw6l99y MKWH3pF4oMTdNnOy9IX6LqVQ/xQsQ4KtxnuRCOcZC4QrCuppntcKnZE3l7BpMKsLxMxewm/eBzXFh BJrK4f2Og==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2Guj-0007Uq-0l; Wed, 20 Jan 2021 17:05:01 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2Guf-0007Sy-C7; Wed, 20 Jan 2021 17:04:58 +0000 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 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-Disposition: inline In-Reply-To: <20210120160210.GK2260413@casper.infradead.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210120_120457_563183_17897854 X-CRM114-Status: GOOD ( 24.47 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , David Hildenbrand , Peter Zijlstra , Catalin Marinas , Dave Hansen , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, "H. Peter Anvin" , Christopher Lameter , Shuah Khan , Thomas Gleixner , Elena Reshetova , linux-arch@vger.kernel.org, Tycho Andersen , linux-nvdimm@lists.01.org, Will Deacon , x86@kernel.org, linux-riscv@lists.infradead.org, Mike Rapoport , Ingo Molnar , Michael Kerrisk , Arnd Bergmann , James Bottomley , Hagen Paul Pfeifer , Borislav Petkov , Alexander Viro , Andy Lutomirski , Paul Walmsley , "Kirill A. Shutemov" , Dan Williams , linux-arm-kernel@lists.infradead.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, Palmer Dabbelt , linux-fsdevel@vger.kernel.org, Shakeel Butt , Andrew Morton , Rick Edgecombe , Roman Gushchin Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel