Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp941528ybm; Wed, 22 May 2019 14:20:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqwhxhXO9D1SLZ+St2ON7iTPvskDv3bkb+7v74qRomukRjutMt0SCDmyQIIVhdj+YavYJ9wp X-Received: by 2002:a62:4dc5:: with SMTP id a188mr47622098pfb.8.1558560048549; Wed, 22 May 2019 14:20:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558560048; cv=none; d=google.com; s=arc-20160816; b=zJqTG5v4rfcWw5fL5T9Qw36HCsmhcRAAp4dGAfjHEeoE3eCsvT7tITSCOT191+dWn8 VOiLus+A8REFr1xM4jWQCRSIcl5cfsdnGA0Au4IU3lzA74+T9NAmUNxKp95zvYGwjG7T 8rDw18WP1gpr2mUq0ZfGZBH2aCP9ZXPHHqYKWuzyWrYqBtnkfHi0pcZIt/wCg66Esx+f Q4m2WuqD8X1t0NlERewTcrVAs8IlwFq5SKIFoZnG+16PHg7jaMz0q1Jjds+S80Z04B4J Yo6lqL75SJ5PyjSWPeImvQEy126MtabXvYF2GssakhSvMxHbLmtNKLCnfBLSXH7/2eox TXqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=xBlxGTGLhDHKTdapGjfzSxUkvnAgB8aV2NBqH4W5GOU=; b=LbGAIf+zcixFro5jXiVE/at/ISnF337FozX6PzJwdH8dQRu4w52sM+STWtjOweSlci /8OS84gH8axAKmYNaJ2Z6/xszHJnwY4hxF2d1y+cyLcLlybbNQyaOpx0yBNqc8M1QwRU IdPQeStNBokbqfywnqpna9ysMauAhV9naihlX1MxAOzkUWdgRrjWSlUHm3MuD6GHUjsX WP6in08F3yDDyMz+nuR13gQqy7vEJ2qdWpWzAqJQ2OGv3N2vxLsegtsfuUvqhINg46yo /cbScB1MkCGk/N0duglRCS7WhLT8MPWosTHCam4sJu6A03o65hZyUqJYx+zrBi7Y6t9L GvlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cWBMS3PZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f11si15534398pgs.335.2019.05.22.14.20.32; Wed, 22 May 2019 14:20:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cWBMS3PZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730325AbfEVVSF (ORCPT + 99 others); Wed, 22 May 2019 17:18:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:49802 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729483AbfEVVSF (ORCPT ); Wed, 22 May 2019 17:18:05 -0400 Received: from localhost.localdomain (c-73-223-200-170.hsd1.ca.comcast.net [73.223.200.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9878B2173E; Wed, 22 May 2019 21:18:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558559883; bh=vm5TFptU4z16aOaq6WyJVuLQG+smQSsecNHc6EdO2EQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=cWBMS3PZhojaDwCxM24fm9eZtn2egLd4rKSnhyyfFkuHkE9NM/B7vOwsCfa4hFLGr uBaSKoEy87eBUtvEQ4U3tKU9B0eI9hYynsiUeYbH9IeamI/gPYa5UnGJ8MDzTEXSLm uv2bfg9jqE4iHSK1DBHm1Bj5munpo/iw6Bx190H4= Date: Wed, 22 May 2019 14:18:03 -0700 From: Andrew Morton To: Mike Rapoport Cc: Andrea Arcangeli , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sebastian Andrzej Siewior , Borislav Petkov , "Dr. David Alan Gilbert" , kvm@vger.kernel.org Subject: Re: [PATCH] mm/gup: continue VM_FAULT_RETRY processing event for pre-faults Message-Id: <20190522141803.c6714f96f57612caaac5d19b@linux-foundation.org> In-Reply-To: <20190522203828.GC18865@rapoport-lnx> References: <1557844195-18882-1-git-send-email-rppt@linux.ibm.com> <20190522122113.a2edc8aba32f0fad189bae21@linux-foundation.org> <20190522203828.GC18865@rapoport-lnx> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 22 May 2019 23:38:29 +0300 Mike Rapoport wrote: > (added kvm) > > On Wed, May 22, 2019 at 12:21:13PM -0700, Andrew Morton wrote: > > On Tue, 14 May 2019 17:29:55 +0300 Mike Rapoport wrote: > > > > > When get_user_pages*() is called with pages = NULL, the processing of > > > VM_FAULT_RETRY terminates early without actually retrying to fault-in all > > > the pages. > > > > > > If the pages in the requested range belong to a VMA that has userfaultfd > > > registered, handle_userfault() returns VM_FAULT_RETRY *after* user space > > > has populated the page, but for the gup pre-fault case there's no actual > > > retry and the caller will get no pages although they are present. > > > > > > This issue was uncovered when running post-copy memory restore in CRIU > > > after commit d9c9ce34ed5c ("x86/fpu: Fault-in user stack if > > > copy_fpstate_to_sigframe() fails"). > > > > > > After this change, the copying of FPU state to the sigframe switched from > > > copy_to_user() variants which caused a real page fault to get_user_pages() > > > with pages parameter set to NULL. > > > > You're saying that argument buf_fx in copy_fpstate_to_sigframe() is NULL? > > Apparently I haven't explained well. The 'pages' parameter in the call to > get_user_pages_unlocked() is NULL. Doh. > > If so was that expected by the (now cc'ed) developers of > > d9c9ce34ed5c8923 ("x86/fpu: Fault-in user stack if > > copy_fpstate_to_sigframe() fails")? > > > > It seems rather odd. copy_fpregs_to_sigframe() doesn't look like it's > > expecting a NULL argument. > > > > Also, I wonder if copy_fpstate_to_sigframe() would be better using > > fault_in_pages_writeable() rather than get_user_pages_unlocked(). That > > seems like it operates at a more suitable level and I guess it will fix > > this issue also. > > If I understand correctly, one of the points of d9c9ce34ed5c8923 ("x86/fpu: > Fault-in user stack if copy_fpstate_to_sigframe() fails") was to to avoid > page faults, hence the use of get_user_pages(). > > With fault_in_pages_writeable() there might be a page fault, unless I've > completely mistaken. > > Unrelated to copy_fpstate_to_sigframe(), the issue could happen if any call > to get_user_pages() with pages parameter set to NULL tries to access > userfaultfd-managed memory. Currently, there are 4 in tree users: > > arch/x86/kernel/fpu/signal.c:198:8-31: -> gup with !pages > arch/x86/mm/mpx.c:423:11-25: -> gup with !pages > virt/kvm/async_pf.c:90:1-22: -> gup with !pages > virt/kvm/kvm_main.c:1437:6-20: -> gup with !pages OK. > I don't know if anybody is using mpx with uffd and anyway mpx seems to go > away. > > As for KVM, I think that post-copy live migration of L2 guest might trigger > that as well. Not sure though, I'm not really familiar with KVM code. > > > > In post-copy mode of CRIU, the destination memory is managed with > > > userfaultfd and lack of the retry for pre-fault case in get_user_pages() > > > causes a crash of the restored process. > > > > > > Making the pre-fault behavior of get_user_pages() the same as the "normal" > > > one fixes the issue. > > > > Should this be backported into -stable trees? > > I think that it depends on whether KVM affected by this or not. > How do we determine this? I guess it doesn't matter much.