Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp940677pxf; Wed, 7 Apr 2021 15:37:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZlQ/CfsuZCDWmkOaEVACGj19zzZbuo79yurGTHzdJrI+CDWBvsFQC7mJ231tBKr01Kfk+ X-Received: by 2002:a05:6402:206d:: with SMTP id bd13mr135634edb.38.1617835070776; Wed, 07 Apr 2021 15:37:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617835070; cv=none; d=google.com; s=arc-20160816; b=jeiaf2HstNxr6TUzaLDlCYptskziuNJnicfH7ptyzIMXPlTnqJ991gGDlOtlD0c8MY Rjh1jadF8UYmdhAigvjxZ3uDdNyhHxXmKM3Ohy4yFd/9i02yXzNIUWVfNJQCnb2V/F/f Ub1b2OhBnxpYVU/xm1ZL5WyDr7cczxp+f7tu5LAgzgwiMyCEbOiMCAT0m/Ml2QcmiGzN IGLDBVoFJANYs5G4tRqBPRtrhz0Y/GEG3PxkbyJV4/sJFcwX50M6XchkR+TBWSoTcde8 xI4yr6xNqWOIpcBofxbQBvKfLuKIMQsepbLlHVGEsoEjbYIhA2EV5+lj0OCjX0dkOfH8 LPzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=AiiGNCBjYcZfRgU7sybUVpHDghOneRNQTa+6Qoodddo=; b=wRuN3YFDVzPBYSF9uE6rgtd48LB//sOZ72LVhBzfsgzg7ZOU6J19esIW9BJsO/XDvH eShofCqsHxoe9ZyDNCmTrguj3+JVc8LQWmrV61wiJq6yVxPOw36M5FMEWSqNEJGH0A/C 5Eg0c9ST3xyQrZ4H3copjX5z6YNwGQfZj3jlgag0JTHQ8kBdArCU7Ag6oTQZ7ZTQVe59 cOVOjnnTTGVZSS3Tj6V4DI4ctKRYpwnfBegj5LJVyr0KcQBLZ+DQIRqR3EnpFs+8aCHh zfzMd1fbctZa6Ph+Nz5n2wMJvgBMGTl2+FnkrR06qeAu3IHw7v26rxe6j5iiBJbuJRae o7og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=WOfw0rgo; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s16si5176947ejr.498.2021.04.07.15.37.27; Wed, 07 Apr 2021 15:37:50 -0700 (PDT) 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=@infradead.org header.s=casper.20170209 header.b=WOfw0rgo; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242565AbhDGOvB (ORCPT + 99 others); Wed, 7 Apr 2021 10:51:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353135AbhDGOu5 (ORCPT ); Wed, 7 Apr 2021 10:50:57 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30D7BC061756 for ; Wed, 7 Apr 2021 07:50:48 -0700 (PDT) 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> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.