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 149C0C4727F for ; Mon, 28 Sep 2020 12:49:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 76F1B21974 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" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 76F1B21974 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B5F7E6B0068; Mon, 28 Sep 2020 08:49:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AE8016B006C; Mon, 28 Sep 2020 08:49:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9B0226B006E; Mon, 28 Sep 2020 08:49:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0093.hostedemail.com [216.40.44.93]) by kanga.kvack.org (Postfix) with ESMTP id 82AE06B0068 for ; Mon, 28 Sep 2020 08:49:40 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 39CD252A6 for ; Mon, 28 Sep 2020 12:49:40 +0000 (UTC) X-FDA: 77312451720.25.cars12_2116d3627181 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id 17C3B1804E3A0 for ; Mon, 28 Sep 2020 12:49:40 +0000 (UTC) X-HE-Tag: cars12_2116d3627181 X-Filterd-Recvd-Size: 5317 Received: from mail-qt1-f194.google.com (mail-qt1-f194.google.com [209.85.160.194]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Mon, 28 Sep 2020 12:49:39 +0000 (UTC) Received: by mail-qt1-f194.google.com with SMTP id a4so593219qth.0 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=bZKxsnm1TA3D/8EbeMIz7iKG3pLLu103UTI01ylB5v1a9s61RX8OkraFlSCvmENpc1 n0u20UV506AuXVc4kHCK1A1nRJyuIRmYhtxvnsqOQafjZC98N7MnwbWcVeNTnx5QnqjB xMW6o7DxOtTV0uVO2H4OieWz0UblW1tJ1gl5F73SrqgrsWfnGo9fEGhbgJXI1aNNxlwm blE8xTZCzDdQA3h5G/gYd96IP3uMa+y+jIvUV4ONyJQgGll0mj38PC29G/yMshQIIdGW 5F6+kTqOoTz6GrUKziKoakWl3JtURWq8VDbtvkMlhlJ+DjSjvUVez3UAz/EpSxveY9kJ iHPA== X-Gm-Message-State: AOAM530g7c7lVngDQo/QmY8hHaEXvzkLzTzTezxLSEYPIY8pT5H+bFD3 wBwdNMToBBtx2dJrsjuJ6I1bGg== 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: 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 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