Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4584732imw; Tue, 19 Jul 2022 09:16:48 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tMTQvzfc/1nnt4ksmhKLD3MstL3JEGca7/edF8tV9IudhQ3zNxXRY5q+h+CB6mjDDEh7am X-Received: by 2002:ad4:5bcb:0:b0:473:1d9b:5d25 with SMTP id t11-20020ad45bcb000000b004731d9b5d25mr26433536qvt.94.1658247408252; Tue, 19 Jul 2022 09:16:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658247408; cv=none; d=google.com; s=arc-20160816; b=EI5nuhXv/wOYhkq4P8JhVGPdJCvBobLNso2WXNXH5/rTsXjEATmtj/HTBKjCsV/7wC u4keFhp7kTu4Bw7vFtrpJ7DClXfMb4HGMBKVCa43oIy9ZhRe74+B2ascX7EmwBCQBxH5 PvnFTS8BlfJijE27GRHsmWz3ybJF/WEbFX/cya9ZA2fGiXY17H9yhO7uE8O6wMDZxy7i j79UUB9aTwcApqGViIbTAg/dGMSDRzPxBs+KtyolpGgSGRVAMARwdg3Kfitt4KvVDpWr UguK+0nx+B1MlAkOnDpI6ZN6j2gEPt0mU+3dp4ZmcE6dUogNZjL35VpnE4utLC62ksJP Dv6A== 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=19tyF3hcmEXgvgnp46r5wyMNhL+B65efr3ypQp+I6Lc=; b=pDAxtjKrhrwZsi3Gd6JNkC/YeZy+5aLnYN2DlAfXpZ9VvBRZASKvKJQk0y/ywiS0Ju izFADKjE6OF5krkc7iRFP8LDs9Ojkt96oFOTGJ6qJCo0k6T3xQmVxYYnEFxxSnwSQj+y pTUDFuJZgu6qwoXFeTWqj3ChvyYSsXNU95Fsd1T3/GD3T0lY/zDxsxCvIGnEeM5wwWxt MR10MUd4hZlTNSSJ1BX6NRK95u5mB14oIiDyBwHkxUYVvF0gAk5nACAI1sei6I/FmOio My5i2iYCGFgSGgLMs1Wlt+ciSunxzQtfonKBXDOagPilLtkmjta24LnzB/HcOz0fd5Pa ZYtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b="bgi94v/2"; 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=alien8.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x21-20020a05620a0b5500b006b5e2d5fc2dsi3143720qkg.348.2022.07.19.09.16.33; Tue, 19 Jul 2022 09:16:48 -0700 (PDT) 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=@alien8.de header.s=dkim header.b="bgi94v/2"; 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=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238403AbiGSPPs (ORCPT + 99 others); Tue, 19 Jul 2022 11:15:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239321AbiGSPPe (ORCPT ); Tue, 19 Jul 2022 11:15:34 -0400 Received: from mail.skyhub.de (mail.skyhub.de [5.9.137.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9E57550C3; Tue, 19 Jul 2022 08:15:24 -0700 (PDT) Received: from zn.tnic (p200300ea97297609329c23fffea6a903.dip0.t-ipconnect.de [IPv6:2003:ea:9729:7609:329c:23ff:fea6:a903]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id A7AEA1EC050F; Tue, 19 Jul 2022 17:15:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1658243715; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=19tyF3hcmEXgvgnp46r5wyMNhL+B65efr3ypQp+I6Lc=; b=bgi94v/2BF7PUNqG8xmemrFZBnufFiYdPdUaAnPFw21wpY2AenhYjpMtVIXjal1w+mzOf/ /mJpaBLsrk1CG9OmmXyV1Mk42F2fLkopvrYioaM30O2wLjdfezvPIdmQCQWST61U2bwz0K 8qYCxwZHFYMHLQZMFQVOq4Y1vdDkO/E= Date: Tue, 19 Jul 2022 17:15:11 +0200 From: Borislav Petkov To: Juergen Gross Cc: xen-devel@lists.xenproject.org, x86@kernel.org, linux-kernel@vger.kernel.org, brchuckz@netscape.net, jbeulich@suse.com, Thomas Gleixner , Ingo Molnar , Dave Hansen , "H. Peter Anvin" , Andy Lutomirski , Peter Zijlstra , Boris Ostrovsky , stable@vger.kernel.org Subject: Re: [PATCH 3/3] x86: decouple pat and mtrr handling Message-ID: References: <20220715142549.25223-1-jgross@suse.com> <20220715142549.25223-4-jgross@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220715142549.25223-4-jgross@suse.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS 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 Fri, Jul 15, 2022 at 04:25:49PM +0200, Juergen Gross wrote: > Today PAT is usable only with MTRR being active, with some nasty tweaks > to make PAT usable when running as Xen PV guest, which doesn't support > MTRR. > > The reason for this coupling is, that both, PAT MSR changes and MTRR > changes, require a similar sequence and so full PAT support was added > using the already available MTRR handling. > > Xen PV PAT handling can work without MTRR, as it just needs to consume > the PAT MSR setting done by the hypervisor without the ability and need > to change it. This in turn has resulted in a convoluted initialization > sequence and wrong decisions regarding cache mode availability due to > misguiding PAT availability flags. > > Fix all of that by allowing to use PAT without MTRR and by adding an > environment dependent PAT init function. Aha, there's the explanation I was looking for. > diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c > index 0a1bd14f7966..3edfb779dab5 100644 > --- a/arch/x86/kernel/cpu/common.c > +++ b/arch/x86/kernel/cpu/common.c > @@ -2408,8 +2408,8 @@ void __init cache_bp_init(void) > { > if (IS_ENABLED(CONFIG_MTRR)) > mtrr_bp_init(); > - else > - pat_disable("PAT support disabled because CONFIG_MTRR is disabled in the kernel."); > + > + pat_cpu_init(); > } > > void cache_ap_init(void) > @@ -2417,7 +2417,8 @@ void cache_ap_init(void) > if (cache_aps_delayed_init) > return; > > - mtrr_ap_init(); > + if (!mtrr_ap_init()) > + pat_ap_init_nomtrr(); > } So I'm reading this as: if it couldn't init AP's MTRRs, init its PAT. But currently, the code sets the MTRRs for the delayed case or when the CPU is not online by doing ->set_all and in there it sets first MTRRs and then PAT. I think the code above should simply try the two things, one after the other, independently from one another. And I see you've added another stomp machine call for PAT only. Now, what I think the design of all this should be, is: you have a bunch of things you need to do at each point: * cache_ap_init * cache_aps_init * ... Now, in each those, you look at whether PAT or MTRR is supported and you do only those which are supported. Also, the rendezvous handler should do: if MTRR: do MTRR specific stuff if PAT: do PAT specific stuff This way you have clean definitions of what needs to happen when and you also do *only* the things that the platform supports, by keeping the proper order of operations - I believe MTRRs first and then PAT. This way we'll get rid of that crazy maze of who calls what and when. But first we need to define those points where stuff needs to happen and then for each point define what stuff needs to happen. How does that sound? Thx. -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette