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.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS 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 5531DC433ED for ; Wed, 7 Apr 2021 14:49:16 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CD07161359 for ; Wed, 7 Apr 2021 14:49:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CD07161359 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 4B0566B007D; Wed, 7 Apr 2021 10:49:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 45F4E6B007E; Wed, 7 Apr 2021 10:49:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 302A26B0080; Wed, 7 Apr 2021 10:49:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0190.hostedemail.com [216.40.44.190]) by kanga.kvack.org (Postfix) with ESMTP id 1550D6B007D for ; Wed, 7 Apr 2021 10:49:15 -0400 (EDT) Received: from smtpin39.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id C4A50180AD83E for ; Wed, 7 Apr 2021 14:49:14 +0000 (UTC) X-FDA: 78005853828.39.9218263 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf08.hostedemail.com (Postfix) with ESMTP id 0C89680192E3 for ; Wed, 7 Apr 2021 14:49:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=AiiGNCBjYcZfRgU7sybUVpHDghOneRNQTa+6Qoodddo=; b=WOfw0rgoWKaJU02SiNuw0A82B7 9r5wfYjhQy5j81NgXRYs+/EdCxqykSktmbma8JypoQ3BjyJUsk/TK05vTWaICdjbXSFSnRd5p/ZHG PDoDR1ORkVgcLe+T6f/AU4GyPW2hgVlqOOiX7RWXiOjY1crGgvlIls6GJ+CpmL9evuU3LOBlc/Idq 9z1TAhFjWQ0HvDzpOy+VR39oXLxtIJFhatB8np3619DrWGMuGzEWgd/iJtpRaiLgLOmmgtfkwwhnZ 9UAgyNHihUk3iSGcTizTp/bNzwPZBc1R4jhU3va+4RUD2pGUIcOifv5lHlP5us5gGvij/3mzsb3Y9 TyOvVFmg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lU9Sx-00EcVC-Ck; Wed, 07 Apr 2021 14:47:48 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id A1373300219; Wed, 7 Apr 2021 16:47:34 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 8857D2BBEA8E3; Wed, 7 Apr 2021 16:47:34 +0200 (CEST) Date: Wed, 7 Apr 2021 16:47:34 +0200 From: Peter Zijlstra To: Michel Lespinasse Cc: Linux-MM , Laurent Dufour , Michal Hocko , Matthew Wilcox , Rik van Riel , Paul McKenney , Andrew Morton , Suren Baghdasaryan , Joel Fernandes , Rom Lemarchand , Linux-Kernel Subject: Re: [RFC PATCH 09/37] mm: add per-mm mmap sequence counter for speculative page fault handling. Message-ID: References: <20210407014502.24091-1-michel@lespinasse.org> <20210407014502.24091-10-michel@lespinasse.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210407014502.24091-10-michel@lespinasse.org> X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 0C89680192E3 X-Stat-Signature: y9ck4gg1tkkq57ik5o4566tadua95smx Received-SPF: none (infradead.org>: No applicable sender policy available) receiver=imf08; identity=mailfrom; envelope-from=""; helo=casper.infradead.org; client-ip=90.155.50.34 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617806945-909821 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 Tue, Apr 06, 2021 at 06:44:34PM -0700, Michel Lespinasse wrote: > The counter's write side is hooked into the existing mmap locking API: > mmap_write_lock() increments the counter to the next (odd) value, and > mmap_write_unlock() increments it again to the next (even) value. > > The counter's speculative read side is supposed to be used as follows: > > seq = mmap_seq_read_start(mm); > if (seq & 1) > goto fail; > .... speculative handling here .... > if (!mmap_seq_read_check(mm, seq) > goto fail; > > This API guarantees that, if none of the "fail" tests abort > speculative execution, the speculative code section did not run > concurrently with any mmap writer. So this is obviously safe, but it's also super excessive. Any change, anywhere, will invalidate and abort a SPF. Since you make a complete copy of the vma, you could memcmp it in its entirety instead of this.