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.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,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 94659C2D0A8 for ; Mon, 28 Sep 2020 12:49:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 41AF1221E8 for ; Mon, 28 Sep 2020 12:49:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="f9lb2tgP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726565AbgI1Mtk (ORCPT ); Mon, 28 Sep 2020 08:49:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726310AbgI1Mtj (ORCPT ); Mon, 28 Sep 2020 08:49:39 -0400 Received: from mail-qt1-x841.google.com (mail-qt1-x841.google.com [IPv6:2607:f8b0:4864:20::841]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9850AC061755 for ; Mon, 28 Sep 2020 05:49:39 -0700 (PDT) Received: by mail-qt1-x841.google.com with SMTP id o21so591993qtp.2 for ; Mon, 28 Sep 2020 05:49:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=C7pLuM6q9GITD003wal8FUvMqWiJb4o3xG/3xTeMIHw=; b=f9lb2tgPovyEXgA0Z4FOMgi3I5WM4fBlC3HOpM70LPWDcNTyUIrsetkEgxSbET6gAK 3nKGSJc6Ub1KXYMckQVyXMumjmiBV4aEkPHu0vd33RSDrVhtFcOPjmx2R9RWDfoGSUF9 WoK4s1dUzp5TRfJcyPWmkbAPdi/wMVzJf4V+S4eRYobTP9huYHbVRPyBLVb5yD8wNMxx Xz+rB/6VCcuNtjmYfQfJBfHnO7i0LEXvIwBrkzAc7KySYSwf4EgQ0JVLaTy/0P5QMCmX JSO4/vjoDkbffgbtEEU5bc9jR3Y6HY8/zAEtSRvZ53rivyLk2Zm8zuyZIJQT6qlcFPlq APsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=C7pLuM6q9GITD003wal8FUvMqWiJb4o3xG/3xTeMIHw=; b=OkSMg8f3AF63X7iSmHqnlMiQXOVPVGEPApMhrdJbUDGsM3V20i0sghbCnqDw1k/nn4 CWA67Of1Ff5AYkC0u6X+WovIb+DnNmKuvsljGX+J0xDUAC38tLFGmbGcTxAa3mS6sx5F NJbT8rb43oooAk/u6CbcMbYZS4wwV+tEpSrK46mtNqMowQvjeHHnEtR5Qkl942rrQOM0 vf7FOH9RJQJaHk1XGfiqgPG6j0TAUz0EG4//v3QqkvwPY6f+Zt7WXDniKXT/1+mFwwgu 2M0/7pe/+4sZ1yptrLnOVorSkPGNwYaxDtDqnAVRMFpmuXHLydTbgA6NnlMy8oEeA90M HTHg== X-Gm-Message-State: AOAM530yq1xmynh89XmBBywhwD541ByyAuEh04MgTIoxS9Yzu30EmP/Z CJFJRO4gNwT/BeEPZBsEz5D46g== X-Google-Smtp-Source: ABdhPJyB+Vuryqx/W9VfWYdCvFbbTCxY1i7cOBauOwmzZPqPCJn7ocXQN/trIb1W22V1vrEwQ9qduQ== X-Received: by 2002:ac8:4d07:: with SMTP id w7mr1338294qtv.243.1601297378789; Mon, 28 Sep 2020 05:49:38 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-156-34-48-30.dhcp-dynamic.fibreop.ns.bellaliant.net. [156.34.48.30]) by smtp.gmail.com with ESMTPSA id e24sm826203qka.76.2020.09.28.05.49.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Sep 2020 05:49:37 -0700 (PDT) Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1kMsb3-001ueb-Ap; Mon, 28 Sep 2020 09:49:37 -0300 Date: Mon, 28 Sep 2020 09:49:37 -0300 From: Jason Gunthorpe To: Linus Torvalds Cc: Leon Romanovsky , Peter Xu , John Hubbard , Linux-MM , Linux Kernel Mailing List , Andrew Morton , Jan Kara , Michal Hocko , Kirill Tkhai , Kirill Shutemov , Hugh Dickins , Christoph Hellwig , Andrea Arcangeli , Oleg Nesterov , Jann Horn Subject: Re: [PATCH 1/5] mm: Introduce mm_struct.has_pinned Message-ID: <20200928124937.GN9916@ziepe.ca> References: <20200924183953.GG9916@ziepe.ca> <20200924213010.GL79898@xz-x1> <20200926004136.GJ9916@ziepe.ca> <20200927062337.GE2280698@unreal> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Sep 27, 2020 at 11:45:30AM -0700, Linus Torvalds wrote: > On Sun, Sep 27, 2020 at 11:16 AM Linus Torvalds > wrote: > > > > Btw, I'm not convinced about the whole "turn the pte read-only and > > then back". If the fork races with another thread doing a pinning > > fast-GUP on another CPU, there are memory ordering issues etc too. > > That's not necessarily visible on x86 (the "turn read-only being a > > locked op will force serialization), but it all looks dodgy as heck. Oh. Yes, looking again the atomics in the final arrangement of copy_present_page() aren't going to be strong enough to order this. Sorry for missing, wasn't able to look very deeply during the weekend. Not seeing an obvious option besides adding a smp_mb() before page_maybe_dma_pinned() as Peter once suggested. > .. looking at it more, I also think it could possibly lose the dirty > bit for the case where another CPU did a HW dirty/accessed bit update > in between the original read of the pte, and then us writing back the > writable pte again. Ah, I see: set_pte_at(src_mm, addr, src_pte, pte); wants to be some arch specific single bit ptep_clear_wrprotect().. Thanks, Jason