Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp85739imm; Tue, 17 Jul 2018 14:30:59 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcNwSYfEdCFEiKMtp/TALGKuNjfreCpa5e7dBCelQ0Z9goyriYXyEw2Dl5TtEwG5X6towLJ X-Received: by 2002:a17:902:24a5:: with SMTP id w34-v6mr3178748pla.52.1531863059305; Tue, 17 Jul 2018 14:30:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531863059; cv=none; d=google.com; s=arc-20160816; b=OSJBEYfeSFYn3QATkUWD5DyxQJ0xwyvlm4PCqgQ2kjwey4svXApFdJprM9QuasmqnU TM+t2kvQTIEIz1qSeLYDz+iwVoxbKggHfyCfQh2/XiPUbIxQsa7MEHl+2Re+x89kIdA2 ZNd+8KIBrOaUilHNK5xRwKiEuP+jDtE3koklHE7+jAgeCjShnSJQFiEcGOK9VJjpyYYr EA2JW0oA5zWUtoeawFvKcy6aW/G7h8NUJ0aqeJBmJsZoed8REaJJbgWqvqUrCUl3N4Cy D7eAYRhORKMvYYxJH6rgbYlm2ak92SQjs4ps9cGn42IPU0qSJN2SULPt57ftA+ELhnmr zCOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=ioBu0b51u0eMwxNMCUEKASKj3DpMGeWVz5rC4foFZbY=; b=z7KJxstQvMPUOPpNY8QuXIIeirgC5UjW196PNLnaU2WU/W9MQlpwyq3jkM2jE/Ia8J d2v/i1JhEuQGzWe5qGLqyRwqY+8biE7V3CATxsX9vmHs7hk6UlQxM94tx8XcVzS1uU8t t7/Xv6vufz53UmJehm7xMdGkJkC9BeZLGKecYSwUHLLLapeSdgxa1TeeY2WBd+YRuaYo Yk6iCP8KvQFsbDuA1RTXTFLzmM1VmszKBR4xMMr63nD36iaoXSQ74OUb+2TCGQ0dgyaT UQZBmwdou/fq0UBW1c16uhGDaBHOPo0+Iw2XZ//sS7xlE1RTWKhYmSBZ9M9bePOXGlRB mbKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NSfc9KRt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x62-v6si1774064pfa.80.2018.07.17.14.30.43; Tue, 17 Jul 2018 14:30:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NSfc9KRt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730598AbeGQWEe (ORCPT + 99 others); Tue, 17 Jul 2018 18:04:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:39376 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729742AbeGQWEe (ORCPT ); Tue, 17 Jul 2018 18:04:34 -0400 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id ED2FC20835 for ; Tue, 17 Jul 2018 21:30:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1531863001; bh=vhzNjPZPH7URPqYqI6QDcxV7h7klUk6Hf2qBzSiEoHE=; h=In-Reply-To:References:From:Date:Subject:To:Cc:From; b=NSfc9KRtDK3J5zF6VjHNhH4UTykZy1jAefYlij+dZ4y76rQfpwq6vVe8IBCG0R0CA B773183wuwq5zb7xDtFhU7WUgtr//ThTDNnKAHXrExvpILhI9Rt09tkYylfb6+NH8Q 2kgNmRQq1/fD9CqQ0cansb8KbpbKrLJ5XZBNcehY= Received: by mail-wr1-f52.google.com with SMTP id g6-v6so2602048wrp.0 for ; Tue, 17 Jul 2018 14:30:00 -0700 (PDT) X-Gm-Message-State: AOUpUlFuEqO/MdjZF9/F5KqrCvN4Bqnk+zKv7QPchmpaAZFJ/miaNVct t2JDJqjA5RUhJafLasbUE1VNit3kOGFy4rX/rG1+JA== X-Received: by 2002:adf:81c3:: with SMTP id 61-v6mr2539343wra.120.1531862999454; Tue, 17 Jul 2018 14:29:59 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a1c:d548:0:0:0:0:0 with HTTP; Tue, 17 Jul 2018 14:29:38 -0700 (PDT) In-Reply-To: References: <20180716190337.26133-1-riel@surriel.com> <20180716190337.26133-5-riel@surriel.com> From: Andy Lutomirski Date: Tue, 17 Jul 2018 14:29:38 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 4/7] x86,tlb: make lazy TLB mode lazier To: Rik van Riel Cc: Andy Lutomirski , LKML , X86 ML , Mike Galbraith , kernel-team , Ingo Molnar , Dave Hansen Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 17, 2018 at 1:16 PM, Rik van Riel wrote: > Can I skip both the cr4 and let switches when the TLB contents > are no longer valid and got reloaded? > > If the TLB contents are still valid, either because we never went > into lazy TLB mode, or because no invalidates happened while > we were lazy, we immediately return. > > The cr4 and ldt reloads only happen if the TLB was invalidated > while we were in lazy TLB mode. Yes, since the only events that would change the LDT or the required CR4 value will unconditionally broadcast to every CPU in mm_cpumask regardless of whether they're lazy. The interesting case is that you go lazy, you miss an invalidation IPI because you were lazy, then you go unlazy, notice the tlb_gen change, and flush. If this happens, you know that you only missed a page table update and not an LDT update or a CR4 update, because the latter would have sent the IPI even though you were lazy. So you should skip the CR4 and LDT updates. I suppose a different approach would be to fix the issue below and to try to track when the LDT actually needs reloading. But that latter part seems a bit complicated for minimal gain. (Do you believe me? If not, please argue back!) >> Hmm. load_mm_cr4() should bypass itself when mm == &init_mm. Want to >> fix that part or should I? > > I would be happy to send in a patch for this, and one for > the above optimization you pointed out. > Yes please!