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.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 6179BC433E2 for ; Mon, 7 Sep 2020 14:30:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DA1C120768 for ; Mon, 7 Sep 2020 14:30:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RRRdXqug" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DA1C120768 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 095BC6B0068; Mon, 7 Sep 2020 10:30:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0461B6B006E; Mon, 7 Sep 2020 10:30:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E76F28E0001; Mon, 7 Sep 2020 10:30:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0087.hostedemail.com [216.40.44.87]) by kanga.kvack.org (Postfix) with ESMTP id CE0D06B0068 for ; Mon, 7 Sep 2020 10:30:22 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 8CE5F8248D52 for ; Mon, 7 Sep 2020 14:30:22 +0000 (UTC) X-FDA: 77236500684.13.knot62_4415c15270cc Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin13.hostedemail.com (Postfix) with ESMTP id 6585318140B67 for ; Mon, 7 Sep 2020 14:30:22 +0000 (UTC) X-HE-Tag: knot62_4415c15270cc X-Filterd-Recvd-Size: 5317 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Mon, 7 Sep 2020 14:30:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599489021; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sUG8cF3p9BM+fhUV3H/SKqqivV8JS8s0QdlQ+W61fOo=; b=RRRdXqugN6dWjD3RSYzJxdNntPDjDxy1YdDlWc0sDncNnk7iEm5XuCZuaiVQbHxkwBfRpP yk/9XOaPQyeCg2EGzIStKM2hKtRQi0cRSHGouU9llcyaFYd2IZ2IOGDYHbj8/GQGe+3vVu //nuFx8nLm2pQuwkYqZP1CjCPFg4LKY= 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-96-2e9iq7GyNg28Jr_RLdFH0g-1; Mon, 07 Sep 2020 10:30:19 -0400 X-MC-Unique: 2e9iq7GyNg28Jr_RLdFH0g-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E63368015A8; Mon, 7 Sep 2020 14:30:16 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.40.192.127]) by smtp.corp.redhat.com (Postfix) with SMTP id A419B78390; Mon, 7 Sep 2020 14:30:09 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Mon, 7 Sep 2020 16:30:16 +0200 (CEST) Date: Mon, 7 Sep 2020 16:30:08 +0200 From: Oleg Nesterov To: Adalbert =?utf-8?B?TGF6xINy?= Cc: linux-mm@kvack.org, linux-api@vger.kernel.org, Andrew Morton , Alexander Graf , Stefan Hajnoczi , Jerome Glisse , Paolo Bonzini , Mihai =?utf-8?B?RG9uyJt1?= , Mircea Cirjaliu , 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: <20200907143008.GB31050@redhat.com> References: <20200904113116.20648-1-alazar@bitdefender.com> <20200904113116.20648-5-alazar@bitdefender.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20200904113116.20648-5-alazar@bitdefender.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Rspamd-Queue-Id: 6585318140B67 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 Content-Transfer-Encoding: quoted-printable 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: it seems that nobody is going to review this patch ;) So I tried to read mirror_vm_fault() and the usage of mmap_sem doesn't look right to me. But let me repeat, this is not my area I can be easily wrong, please correct me. On 09/04, Adalbert Laz=C4=83r wrote: > > +static vm_fault_t mirror_vm_fault(struct vm_fault *vmf) > +{ > + struct vm_area_struct *vma =3D vmf->vma; > + struct mm_struct *mm =3D vma->vm_mm; > + struct remote_vma_context *ctx =3D vma->vm_private_data; > + struct remote_view *view =3D ctx->view; > + struct file *file =3D vma->vm_file; > + struct remote_file_context *fctx =3D file->private_data; > + unsigned long req_addr; > + unsigned int gup_flags; > + struct page *req_page; > + vm_fault_t result =3D VM_FAULT_SIGBUS; > + struct mm_struct *src_mm =3D fctx->mm; > + unsigned long seq; > + int idx; > + > +fault_retry: > + seq =3D mmu_interval_read_begin(&view->mmin); > + > + idx =3D srcu_read_lock(&fctx->fault_srcu); > + > + /* check if view was invalidated */ > + if (unlikely(!READ_ONCE(view->valid))) { > + pr_debug("%s: region [%lx-%lx) was invalidated!!\n", __func__, > + view->offset, view->offset + view->size); > + goto out_invalid; /* VM_FAULT_SIGBUS */ > + } > + > + /* drop current mm semapchore */ > + up_read(¤t->mm->mmap_sem); Please use mmap_read_lock/unlock(mm) instead of down/up_read(mmap_sem). But why is it safe to drop ->mmap_sem without checking FAULT_FLAG_ALLOW_RETRY/RETRY_NOWAIT ? > + /* take remote mm semaphore */ > + if (vmf->flags & FAULT_FLAG_ALLOW_RETRY) { > + if (!down_read_trylock(&src_mm->mmap_sem)) { I don't understand this... perhaps you meant FAULT_FLAG_RETRY_NOWAIT ? > + * 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_se= m and return VM_FAULT_RETRY (unless NOWAIT). > + if (vmf->flags & (FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_TRIED)) { > + if (!(vmf->flags & FAULT_FLAG_KILLABLE)) > + if (current && fatal_signal_pending(current)) { > + up_read(¤t->mm->mmap_sem); > + return VM_FAULT_RETRY; I fail to understand this. But in any case, you do not need to check current !=3D NULL and up_read() looks wrong if RETRY_NOWAIT? Oleg.