Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp676440pxu; Thu, 7 Jan 2021 15:32:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJwhIUsVqPqjv71HCK+jVSby8xPOYre0P++UXDz6Dtgl7/PbXMHdfMWwXOLMkugQvhszjW67 X-Received: by 2002:a17:907:111c:: with SMTP id qu28mr811716ejb.540.1610062344534; Thu, 07 Jan 2021 15:32:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610062344; cv=none; d=google.com; s=arc-20160816; b=X01rwUiHq/ak0v9okeKHm6CBBwRuvIeCUQajRgrSW0Mk6Tk/5An7iDeayAU6hhna/4 70/GdlpWsUDgAPY+GCNpne7VKWCKBzlbdIGukfC2x36L0cCtlJ2mWfVzsmvSDJ0trsn0 9IHDPyJe+SRz5iW+Sy1/0YgEhMmNyipX76pJ+6qa/SR0C1Ml+jlkVi7f0/BXshr42nM7 DHjVp/5zrHYalnwst7O49zlcocaLo2aCnNOffjBU3Jc0C6C2jUgs5ysRZfn/q3N1eZsX VRTVza6N4WnDvFN+UZf/7nbbCZ1PsCzCfYoj78v0j5Pjm9WZ3qCSjSeON1Eh4VZNg6yh N0EA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=7eEumnZITt8LSMG+c5eHBTJyWBxx4LQFGtGACeYt0tw=; b=Rf9vp8niX4XkwoPMD/7ZvzAcsXZjRsKMEh6f/8h3ZCvfOMJnu+12twE9LndRwVdIzR HBrMRKCMHvMJbCRa7SWAvGrM/MKTYheJc1Jm09hR6clwIMOUa+CfLvQ9npIpRrtqIYrE 2WSRI46Krwqz75rjgPTGNsEre5fCurm727X0k+fRhi3cYQ9haC56aEZBICRnLdlszM3n lImFQWKzcfq4MXBJWSg4IVBiP74tQH1pPh6Vmqpc9GTThn4aTXF/BjL5ou/uYL/68Azt 0aNSBco0Ep2twKYlZYYrvTzrWEm5vcaDkUkuyFTd64Q2aT8Hzo3wbp6sjsyGyXW5OS6v UdLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Ef1NL0sh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p12si2791383eji.735.2021.01.07.15.32.01; Thu, 07 Jan 2021 15:32:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Ef1NL0sh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727913AbhAGXa0 (ORCPT + 99 others); Thu, 7 Jan 2021 18:30:26 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:44757 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725944AbhAGXaZ (ORCPT ); Thu, 7 Jan 2021 18:30:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610062138; 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: in-reply-to:in-reply-to:references:references; bh=7eEumnZITt8LSMG+c5eHBTJyWBxx4LQFGtGACeYt0tw=; b=Ef1NL0shonOik7Vwtd3OfkjUgBlyVGJiZwFs/l9lEZP/do+mgTwScBnjyE0bqZzpoiy1VH qfVp1CS5wzZP+hZZ0FriXzJ6+29fezKiYOcl5/Wg3z/u3B7qD9kmYr81XSPd+LWqUtiwqe KdJr/IIT7WMgLIH7pvA/RAg0uIsy/vE= 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-473-tre5Cf1FP2-6t6-_WPBalw-1; Thu, 07 Jan 2021 18:28:57 -0500 X-MC-Unique: tre5Cf1FP2-6t6-_WPBalw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1F77810054FF; Thu, 7 Jan 2021 23:28:54 +0000 (UTC) Received: from mail (ovpn-112-222.rdu2.redhat.com [10.10.112.222]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A8E505D9DE; Thu, 7 Jan 2021 23:28:47 +0000 (UTC) Date: Thu, 7 Jan 2021 18:28:46 -0500 From: Andrea Arcangeli To: Linus Torvalds Cc: Linux-MM , Linux Kernel Mailing List , Yu Zhao , Andy Lutomirski , Peter Xu , Pavel Emelyanov , Mike Kravetz , Mike Rapoport , Minchan Kim , Will Deacon , Peter Zijlstra , Hugh Dickins , "Kirill A. Shutemov" , Matthew Wilcox , Oleg Nesterov , Jann Horn , Kees Cook , John Hubbard , Leon Romanovsky , Jason Gunthorpe , Jan Kara , Kirill Tkhai Subject: Re: [PATCH 2/2] mm: soft_dirty: userfaultfd: introduce wrprotect_tlb_flush_pending Message-ID: References: <20210107200402.31095-1-aarcange@redhat.com> <20210107200402.31095-3-aarcange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.0.4 (2020-12-30) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 07, 2021 at 02:42:17PM -0800, Linus Torvalds wrote: > On Thu, Jan 7, 2021 at 2:31 PM Andrea Arcangeli wrote: > > > > Random memory corruption will still silently materialize as result of > > the speculative lookups in the above scenario. > > Explain. > > Yes, you'll get random memory corruption if you keep doing wrprotect() > without mmap_sem held for writing. I didn't meant that. > But I thought we agreed earlier that that is a bug. And I thought the > softdirty code already got it for writing. softdirty used mmap_read_lock too but this again isn't relevant here and for the sake of discussion we can safely assume mmap_read_lock doesn't exist in the kernel, and everything takes the mmap_write_lock whenever a mmap_lock is taken at all. I mean something bad will happen if a write happens, but soft dirty cannot register it because we didn't wrprotect the pte? Some dirty page won't be transferred to destination and it will be assumed there was no softy dirty event for such page? Otherwise it would mean that wrprotecting is simply optional for all pages under clear_refs? Not doing the final TLB flush in softdirty caused some issue even when there was no COW and the deferred flush only would delay the wrprotect fault: https://lore.kernel.org/linux-mm/CA+32v5zzFYJQ7eHfJP-2OHeR+6p5PZsX=RDJNU6vGF3hLO+j-g@mail.gmail.com/ https://lore.kernel.org/linux-mm/20210105221628.GA12854@willie-the-truck/ Skipping the wrprotection of the pte because of a speculative pagecache lookup elevating a random page_count, from the userland point of view, I guessed would behave as missing the final TLB flush before clear_refs returns to userland, just worse. Thanks, Andrea