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=-5.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 10CADC43461 for ; Thu, 10 Sep 2020 16:43:16 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5444721941 for ; Thu, 10 Sep 2020 16:43:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PB4JUGrc" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5444721941 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 60C6E6B0092; Thu, 10 Sep 2020 12:43:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5BD026B0093; Thu, 10 Sep 2020 12:43:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4D2FF6B0095; Thu, 10 Sep 2020 12:43:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0102.hostedemail.com [216.40.44.102]) by kanga.kvack.org (Postfix) with ESMTP id 3699E6B0092 for ; Thu, 10 Sep 2020 12:43:14 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id F02AF8249980 for ; Thu, 10 Sep 2020 16:43:13 +0000 (UTC) X-FDA: 77247721866.20.veil42_221016d270e7 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id B7C7A180C07AF for ; Thu, 10 Sep 2020 16:43:13 +0000 (UTC) X-HE-Tag: veil42_221016d270e7 X-Filterd-Recvd-Size: 4962 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Thu, 10 Sep 2020 16:43:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599756192; 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=TgSJjTXbpkXh2o0gkcQWD9wwqe3worwk3nJzHA/vWWg=; b=PB4JUGrc+fxKDQpHHP1/Br1wVll9XMBtOtlhAwDw/Ws3CqBi32iilVjzyIFTpuulhgimu1 hmZNBPEu3/uIabS9/8ZtwpQctfKX30UPdmDUyHiYMh6fRWDwy4di6zJ0pDWTG7p2c4I7jU GNTXoyJS6/hQE5IznWnLfiM8Ga08PIY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-27-TeaD4IRHOQaY8UHnGtFJPg-1; Thu, 10 Sep 2020 12:43:10 -0400 X-MC-Unique: TeaD4IRHOQaY8UHnGtFJPg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5CF81801AEA; Thu, 10 Sep 2020 16:43:08 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.40.195.89]) by smtp.corp.redhat.com (Postfix) with SMTP id 26F737EEC9; Thu, 10 Sep 2020 16:43:03 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Thu, 10 Sep 2020 18:43:08 +0200 (CEST) Date: Thu, 10 Sep 2020 18:43:03 +0200 From: Oleg Nesterov To: Mircea CIRJALIU - MELIU Cc: Adalbert =?utf-8?B?TGF6xINy?= , "linux-mm@kvack.org" , "linux-api@vger.kernel.org" , Andrew Morton , Alexander Graf , Stefan Hajnoczi , Jerome Glisse , Paolo Bonzini , Mihai =?utf-8?B?RG9uyJt1?= , Andy Lutomirski , Arnd Bergmann , Sargun Dhillon , Aleksa Sarai , Jann Horn , Kees Cook , Matthew Wilcox , Christian Brauner Subject: Re: [RESEND RFC PATCH 4/5] mm/remote_mapping: use a pidfd to access memory belonging to unrelated process Message-ID: <20200910164302.GA12976@redhat.com> References: <20200904113116.20648-1-alazar@bitdefender.com> <20200904113116.20648-5-alazar@bitdefender.com> <20200907143008.GB31050@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Rspamd-Queue-Id: B7C7A180C07AF X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 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 09/09, Mircea CIRJALIU - MELIU wrote: > > > From: Oleg Nesterov > > > > But why is it safe to drop ->mmap_sem without checking > > FAULT_FLAG_ALLOW_RETRY/RETRY_NOWAIT ? > > > Dropping mmap_sem will have the same effects regardless of FAULT_FLAG_ALLOW_RETRY/RETRY_NOWAIT. > Another thread can unmap the VMA from underneath us, or remap another one in its place. > In the end, the VMA has to be revalidated when re-acquiring the mmap_sem. > Or am I wrong?! To simplify, lets forget about RETRY_NOWAIT/TRIED. Again, I can be easily wrong. But iiuc, you simply can't drop mmap_sem if FAULT_FLAG_ALLOW_RETRY is not set, the caller doesn't expect mmap_sem can be unlocked. OTOH, if FAULT_FLAG_ALLOW_RETRY is set and you drop mmap_sem, you can only return VM_FAULT_RETRY to let the caller know it was dropped. > > > + * If FAULT_FLAG_ALLOW_RETRY is set, the mmap_sem must be > > released > > > + * before returning VM_FAULT_RETRY only if > > FAULT_FLAG_RETRY_NOWAIT is > > > + * not set. > > > > Well, iiuc FAULT_FLAG_ALLOW_RETRY means that ->fault() _can_ drop > > mmap_sem and return VM_FAULT_RETRY (unless NOWAIT). > > That comment is just copied from elsewhere in the code. > My interpretation was that the fault handler _should_ return with mmap_sem > held or not depending on FAULT_FLAG_RETRY_NOWAIT. Yes, this depends on FAULT_FLAG_RETRY_NOWAIT. But your comment above looks as if he mmap_sem must be _always_ released if FAULT_FLAG_ALLOW_RETRY && !FAULT_FLAG_RETRY_NOWAIT. This is not true. Nevermind. If you ever resend this patch, please CC mm/ experts. I tried to look at this code again and I feel it has much more problems, but as I said this is not my area. And I think you should split this patch, mirror_vm_fault() should come in a separate patch to simplify the review. Oleg.