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.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 CF536C433DF for ; Mon, 12 Oct 2020 10:45:35 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 37F292078E for ; Mon, 12 Oct 2020 10:45:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="fVqmSQOR" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 37F292078E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.5899.15325 (Exim 4.92) (envelope-from ) id 1kRvKU-0007Yh-06; Mon, 12 Oct 2020 10:45:22 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 5899.15325; Mon, 12 Oct 2020 10:45:21 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kRvKT-0007Ya-SS; Mon, 12 Oct 2020 10:45:21 +0000 Received: by outflank-mailman (input) for mailman id 5899; Mon, 12 Oct 2020 10:45:20 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kRvKR-0007Xt-8L for xen-devel@lists.xenproject.org; Mon, 12 Oct 2020 10:45:20 +0000 Received: from merlin.infradead.org (unknown [2001:8b0:10b:1231::1]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 96f7f16a-5a4e-4c65-adfa-319f3de547e5; Mon, 12 Oct 2020 10:45:16 +0000 (UTC) Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kRvKI-0002rw-Te; Mon, 12 Oct 2020 10:45:11 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 08611300DB4; Mon, 12 Oct 2020 12:45:09 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id E95E920A2950E; Mon, 12 Oct 2020 12:45:08 +0200 (CEST) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kRvKR-0007Xt-8L for xen-devel@lists.xenproject.org; Mon, 12 Oct 2020 10:45:20 +0000 X-Inumbo-ID: 96f7f16a-5a4e-4c65-adfa-319f3de547e5 Received: from merlin.infradead.org (unknown [2001:8b0:10b:1231::1]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 96f7f16a-5a4e-4c65-adfa-319f3de547e5; Mon, 12 Oct 2020 10:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=z5pzSV5nBQT8SxLlSdLOzbr7Kyh1DTeoSAzBFZne3gQ=; b=fVqmSQORpjIfktIa6KeeyDumA1 M2YhWhOV4tEOpYdOX/rmk7+aGrLU3e4ZHMP6wAwDixCnWObMzp8iDVj5CQFc6fwNOnOtdxvX+tPvh U9cv4Ay5cZMAbsZUvjm0bXBwOqbnleDCuTudxxQoUjlw1FyZ4dDM8IDtXmAaSGvLL0qY9EeBfqSZJ fLsrdUSNIyaXt6zqrq3VAeG502NoG+2DIzhyGGUxplRgJy+d46bkcX86qaDDsipOsu4DNHlutWggV XJVFUch8HvPOVceoLhvlHmBBCsDTJ8xBT2Yin5OVz+H8HvPedxHs5hYSQaBRpH1ITTWQgBOcqXfwQ xtRyOjwA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kRvKI-0002rw-Te; Mon, 12 Oct 2020 10:45:11 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 08611300DB4; Mon, 12 Oct 2020 12:45:09 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id E95E920A2950E; Mon, 12 Oct 2020 12:45:08 +0200 (CEST) Date: Mon, 12 Oct 2020 12:45:08 +0200 From: Peter Zijlstra To: =?iso-8859-1?Q?J=FCrgen_Gro=DF?= Cc: xen-devel@lists.xenproject.org, x86@kernel.org, linux-kernel@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Andy Lutomirski Subject: Re: [PATCH] x86/alternative: don't call text_poke() in lazy TLB mode Message-ID: <20201012104508.GS2628@hirez.programming.kicks-ass.net> References: <20201009144225.12019-1-jgross@suse.com> <20201012101330.GR2628@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Mon, Oct 12, 2020 at 12:26:06PM +0200, Jürgen Groß wrote: > > > @@ -807,6 +807,15 @@ static inline temp_mm_state_t use_temporary_mm(struct mm_struct *mm) > > > temp_mm_state_t temp_state; > > > lockdep_assert_irqs_disabled(); > > > + > > > + /* > > > + * Make sure not to be in TLB lazy mode, as otherwise we'll end up > > > + * with a stale address space WITHOUT being in lazy mode after > > > + * restoring the previous mm. > > > + */ > > > + if (this_cpu_read(cpu_tlbstate.is_lazy)) > > > + leave_mm(smp_processor_id()); > > > + > > > temp_state.mm = this_cpu_read(cpu_tlbstate.loaded_mm); > > > switch_mm_irqs_off(NULL, mm, current); > > > > Would it make sense to write it like: > > > > this_state.mm = this_cpu_read(cpu_tlbstate.is_lazy) ? > > &init_mm : this_cpu_read(cpu_tlbstate.loaded_mm); > > > > Possibly with that wrapped in a conveniently named helper function. > > Fine with me, but I don't think it matters that much. > > For each batch of text_poke() it will be hit only once, and I'm not sure > it is really a good idea to use the knowledge that leave_mm() is just a > switch to init_mm here. Yeah, I'm not sure either. But it's something I came up with when looking at all this. Andy, what's your preference?