Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5373203ybv; Mon, 17 Feb 2020 18:39:19 -0800 (PST) X-Google-Smtp-Source: APXvYqxMcTwP/oOhpEze8ArPQcm9RJ0EUDm/wfQn2FvZghDOcS5BBNc7+3cO8+Ms03Lp6k90P0o/ X-Received: by 2002:a05:6830:210d:: with SMTP id i13mr14332338otc.192.1581993558832; Mon, 17 Feb 2020 18:39:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581993558; cv=none; d=google.com; s=arc-20160816; b=xRcvdvo0e8w66pVIFnLSaKpoIwbrVIwVmGLMKRJBQtPjhIXJMTafOqRyvDE/IA30tP YAFrL+LOpm5QzmaIuh6AkDLcaiO7WgUAjoGDfzH+NOc9TiOhhnxCsShnx4uaTXJ1DBsG o/NQPQTG26JQvVA+kEtNJVLxmj0+rXTEuPcHqMxz5JzdzgIpeJGs4JpqN2blVBrvkiG6 A2n0ouSn3q8X4nHVOOmKUdG3/l6+7P+S3cr++fOptH22y1F6FBB2EiVliW59UA/xUiEa 5PKFt89/b7AwQlrGZhCuAuGz62qCwXiqV3RrcH3UncNXwEtMmBCfinewYFHDTeJWQqOO 44RA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=z5Wztdcq0xb5666uBgxA54T8GeJH0yGcRfh+PsUTNPQ=; b=y96BaVc3bonw7YyoF84xniJy4mm2cblOjIOL8aAkXTt5CuFcGdOhGz36/0rcuH5ieg BYkYFie0o6rWK5oNv1N3loek+JPyxXN2kmYm0vYHcit5CWpt4IQFEpB3sWueDOYHPYyr dpMJLcLzV4PGm3rYoguw5lBkfuTZpgc02mq8F03HXmeUV70gp/G4N41weW7Kv8Egl86I nIdCqTrnENky+23mafeAVRQlp/NtMJ8fLPauXEQm/y3+dszAcROqHOPLhAwKUIOKznrV hvMeaju1J9HdsjG++T/oeHE3AlzJt3K0BHU++BVi//fb93eYKDh1K5YkhvpV67fOMJO0 wayQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=P3PMLLCE; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q6si1261041otg.248.2020.02.17.18.39.06; Mon, 17 Feb 2020 18:39:18 -0800 (PST) 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=@google.com header.s=20161025 header.b=P3PMLLCE; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726289AbgBRChn (ORCPT + 99 others); Mon, 17 Feb 2020 21:37:43 -0500 Received: from mail-ed1-f68.google.com ([209.85.208.68]:44129 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726171AbgBRChm (ORCPT ); Mon, 17 Feb 2020 21:37:42 -0500 Received: by mail-ed1-f68.google.com with SMTP id g19so22971288eds.11 for ; Mon, 17 Feb 2020 18:37:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=z5Wztdcq0xb5666uBgxA54T8GeJH0yGcRfh+PsUTNPQ=; b=P3PMLLCEbNYaCu0qdw/g5C4RvRHZH85ToAPVXjkycwT8DIIjd6ZnrBTzeYT154aEPU 8WIRYxAtxADcakO/f5CnGd5ezgaZF5PMjJjuYZK/PrJmUwLwAuOXoYBZnDtvynnC+/Qt UIexo26ogliBZwZZho21As0rU3GfVsDYaH0FCF6PSZ7czmNUdasyWG/Ja/iAqEDRK/c4 8p31iIF+2pShFmlqk6Svt8ErLUIY1P0+XQ0rSPTM/fl0IvQEmTRmAkshWhIxBxtELrpF xivT3NSQkXbHZbpu/VGozRGSFtTXZWHL+A+cewLOibUbJ5BnUhKDpMqxsGqXAfKg7bQS UO/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=z5Wztdcq0xb5666uBgxA54T8GeJH0yGcRfh+PsUTNPQ=; b=lXnviHwke6GMY/8h1s5Z4c6KtS82BLy7nlxX4py2199pTYfjQxXV3L0D4tfmXm7x7g zg6ZQSj8yRO2wVhBQ4gRhoevyJsN4NyjYU5vCdgO06IudVKRdbFsMmDPomi+0VkLpjLJ qwrK9wXzTEqXwT9hJLXCrYATih8of2Wnj5fgMCdsQzk28g+MicyJn8jv5x9sLD/BCx9D p0kQZZmGDrIX717IXHB6eilUeTz/NqviSEPI+rS0qnUQQH9Yyf+Wm2r0ohVrVwdQpyin PjMZX7WNpugOUsfa51Sr+oDm8iAlWGpHLMesb+9wWZL68p4O38Wr0llR+PCmFiguKFSp mcyw== X-Gm-Message-State: APjAAAV+fjcCH8NVM2b3hmT0mmGO4k6XeNHcCeMNw443BY6e3wXdDGMr aCs+X0eQ1d1f5krywNATGhCMvioEuSLUYwQ5vEKOO2JR X-Received: by 2002:a05:6402:61a:: with SMTP id n26mr15749135edv.135.1581993459575; Mon, 17 Feb 2020 18:37:39 -0800 (PST) MIME-Version: 1.0 References: <20200214225849.108108-1-bgeffon@google.com> <20200214231954.GA29849@redhat.com> <20200217160739.GB1309280@xz-x1> <20200218022655.GE29216@redhat.com> In-Reply-To: <20200218022655.GE29216@redhat.com> From: Brian Geffon Date: Mon, 17 Feb 2020 20:37:07 -0600 Message-ID: Subject: Re: [RFC PATCH] userfaultfd: Address race after fault. To: Andrea Arcangeli Cc: Peter Xu , Andrew Morton , linux-mm , LKML , Mike Rapoport , Sonny Rao , "Kirill A . Shutemov" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Andrea, That all makes sense, thanks so much for that detailed explanation. Brian On Mon, Feb 17, 2020 at 8:27 PM Andrea Arcangeli wrote: > > On Mon, Feb 17, 2020 at 07:50:19PM -0600, Brian Geffon wrote: > > But in the meantime, if the plan of record will be to always allow > > retrying then shouldn't the block I mailed a patch on be removed > > regardless because do_user_addr_fault always starts with > > FAULT_FLAG_ALLOW_RETRY and we shouldn't ever land there without it in > > the future and allows userfaultfd to retry? > > It might hide the limitation but only if the page fault originated in > userland (Android's case), but that's not something userfault users > should depend on. Userfaults (unlike sigsegv trapping) are meant to be > reliable and transparent to all user and kernel accesses alike. > > It is also is unclear how long Android will be forced to keep doing > bounce buffers copies in RAM before considering passing any memory to > kernel syscalls. > > For all other users where the kernel access may be the one triggering > the fault the patch will remove a debug aid and the kernel fault would > then fail by hitting on the below: > > /* Not returning to user mode? Handle exceptions or die: */ > no_context(regs, hw_error_code, address, SIGBUS, BUS_ADRERR); > > There may be more side effects in other archs I didn't evaluate > because there's no other place where the common code can return > VM_FAULT_RETRY despite the arch code explicitly told the common code > it can't do that (by not setting FAULT_FLAG_ALLOW_RETRY) so it doesn't > look very safe and it doesn't seem a generic enough solution to the > problem. > > That dump_stack() helped a lot to identify those kernel outliers that > erroneously use get_user_pages instead of the gup_locked/unlocked > variant that are uffd-capable. > > Thanks, > Andrea >