Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2187885rwb; Mon, 7 Nov 2022 10:09:45 -0800 (PST) X-Google-Smtp-Source: AMsMyM6Yuuhtx7vCySlvQPc8A9rRcYux/DyzxlszN4fllKBddGFXrRDWeUK0bVyycveRTvmXjOAk X-Received: by 2002:a17:907:7704:b0:780:da38:4480 with SMTP id kw4-20020a170907770400b00780da384480mr49457140ejc.64.1667844585289; Mon, 07 Nov 2022 10:09:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667844585; cv=none; d=google.com; s=arc-20160816; b=GjWwllslJrh0xYjoO7iziRocq7LJ+n42gMe95Pe6smiujiTfK75FHIxo1sIXfpu/2C KE3ahE0eE4ZxCFwyzq2AU4oHC/aphityLo5ejECHhBZc59xiWYnqzTsgaMirky2UN/oF 3ZNF5Kc5kVwvGYQ3C0SNB3fRwXMST9iYRXaMTFSKkgpoZPSqo5dgLmy1s3dsAtbGDy1s gIQ+jMPJu5gZBa5jNeRad67PZMLMcFnTwk3RWsWxUEr2Huo2OBZgAoRR1I0c/u7dMg7S 5jw/Hz0dAfQa0iGmwWnYolzJskRawzH+g+D/Se1us6lOp4Ns91/1V6nvYRorGenFWFUI /z8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=PF79h4dVzt8QKvyZ3V9HY+3qxNCjwAzPYDohnWph56g=; b=szktOWasUrYRNVm/mDAHyEtgwYMd9nsPB4MXDmDAJHngNEh4KCdowqc9HI53l3VRqv vMfGcED8qkmA7k+2H0AI5lJN/tSQA/AxnK2xKXdtcQ7zJCNW2DvKY7dAdHOqIvprJooB m1rz0C6y4wfGNAyzPXKUrdJJP3EDRCZeCD8VhoJoM8oFxW4s13wbUUB92AwdgGDN/fQR QrmwsnJ6f4BjGxKzohzfmDUopOasqRK8ndhwiqbVYF4Fhtbu2fa5yA9WRkekJ6HobQq+ uR2aUNsjIe0Tf4YJlF/BNu2Wqg/AtWzCnnaElyemUX1NjDRD/mBLXYgp8wwJ4T3PGIZM BSag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=c68OYk9t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hp20-20020a1709073e1400b0073da4a0f01csi10059484ejc.743.2022.11.07.10.09.22; Mon, 07 Nov 2022 10:09:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=c68OYk9t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231500AbiKGSG0 (ORCPT + 92 others); Mon, 7 Nov 2022 13:06:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232920AbiKGSGD (ORCPT ); Mon, 7 Nov 2022 13:06:03 -0500 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB6B02A252 for ; Mon, 7 Nov 2022 10:02:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1667844168; x=1699380168; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=fDIy9GNTqYrRaEubc/ZHCrZPmxPfpeXIk3PMc/Gyqec=; b=c68OYk9tZSXmJ8jCOPSEpjwn1321r/PurhpVfnV9daOcZvb9QrZVkFSy 3evjHV1Rjel6ReUEDVNZAzLEru7EO3NtiYD73V0EfzqKwlupDAhJjGs4K eOjOjrFBJyR/U/euok33o2uiKezamnqsX3rKOFQEk/WOs//jpwobHEQrV btCliQ5A7mT0xAJfCO2OiXoWraaYIOIfmnHy6Klcg614KqW1fafq6+Tdq uZxEGGe/KkCIp7sq3YG0TiEIpGpqmG36qIWRqoMrJ443B9zv5Uopa5wkh Bg3ouLBNFL1QB8QVspisxgFBZ1MD4RKqFqvS/mp/dctfk+r50PnwvDh0R g==; X-IronPort-AV: E=McAfee;i="6500,9779,10524"; a="290870719" X-IronPort-AV: E=Sophos;i="5.96,145,1665471600"; d="scan'208";a="290870719" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Nov 2022 10:02:48 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10524"; a="741598319" X-IronPort-AV: E=Sophos;i="5.96,145,1665471600"; d="scan'208";a="741598319" Received: from peggykes-mobl.amr.corp.intel.com (HELO [10.251.7.244]) ([10.251.7.244]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Nov 2022 10:02:47 -0800 Message-ID: Date: Mon, 7 Nov 2022 10:02:44 -0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: [PATCHv11 04/16] x86/mm: Handle LAM on context switch Content-Language: en-US To: "Kirill A. Shutemov" , Andy Lutomirski Cc: "Kirill A. Shutemov" , Dave Hansen , Peter Zijlstra , x86@kernel.org, Kostya Serebryany , Andrey Ryabinin , Andrey Konovalov , Alexander Potapenko , Taras Madan , Dmitry Vyukov , "H . J . Lu" , Andi Kleen , Rick Edgecombe , Bharata B Rao , Jacob Pan , Ashok Raj , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20221025001722.17466-1-kirill.shutemov@linux.intel.com> <20221025001722.17466-5-kirill.shutemov@linux.intel.com> <20221107171419.k33qd4rz3tyfrovs@box.shutemov.name> From: Dave Hansen In-Reply-To: <20221107171419.k33qd4rz3tyfrovs@box.shutemov.name> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/7/22 09:14, Kirill A. Shutemov wrote: > --- a/arch/x86/mm/tlb.c > +++ b/arch/x86/mm/tlb.c > @@ -561,7 +561,15 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next, > if (real_prev == next) { > VM_WARN_ON(this_cpu_read(cpu_tlbstate.ctxs[prev_asid].ctx_id) != > next->context.ctx_id); > - VM_WARN_ON(prev_lam != new_lam); > + > + /* > + * 'prev_lam' does not necessary match 'new_lam' here. In case > + * of race with LAM enabling, the updated 'lam_cr3_mask' can be > + * been before LAM-enabling IPI kicks in. > + * > + * The race is harmless: it is okay to update CR3 with new LAM > + * mode. The IPI will rewrite CR3 shortly. > + */ So, let's do something like this in switch_mm_irqs_off(): /* Not actually switching mm's */ VM_WARN_ON(this_cpu_read(cpu_tlbstate.... /* * If this races with another thread that enables * lam, 'new_lam' might not match 'prev_lam'. */ Then, in enable_lam_func(), something like this: /* * Update CR3 to get LAM active on the CPU * * This might not actually need to update CR3 if a context * switch happened between updating 'lam_cr3_mask' and * running this IPI handler. Update it unconditionally for * simplicity. */ cr3 = __read_cr3(); cr3 &= ~(X86_CR3_LAM_U48 | X86_CR3_LAM_U57); cr3 |= lam_mask; write_cr3(cr3); set_tlbstate_cr3_lam_mask(lam_mask); I'd much rather get folks thinking about IPI races in the IPI handler rather than thinking about the IPI handler in the context switch path. It's kinda silly to be describing the occasional superfluous enable_lam_func() activity from switch_mm_irqs_off().