Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp5382504rwp; Mon, 17 Jul 2023 03:12:01 -0700 (PDT) X-Google-Smtp-Source: APBJJlF+RchYDeGEB8ys4JwnhlOvszzHkeYtkKhXzZTUU37BWBHguj9lly9Vmgs/ajD1BIQoqQca X-Received: by 2002:a05:6a20:7f93:b0:125:928d:6745 with SMTP id d19-20020a056a207f9300b00125928d6745mr14435103pzj.15.1689588721145; Mon, 17 Jul 2023 03:12:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689588721; cv=none; d=google.com; s=arc-20160816; b=QIFc6VzrYdeGvQWf0k+7w3XRcY9cVEsY6h47AGQ//SUMCJfFVATP0CsStxrCPmUZ47 K1xxoQMI4gn6h896lGCWOQ2l3rBvp6S+U2dbPQoW+VHZmcGFGbyv/xp5u1qrHamKnp58 TFT+W1VawME3hmm4C++LtjG0DTNt4hU08ri0qZmWWW2PvBxhxsec3uGGFq2rGvD/Eddk ouUcCXalqRVRHAgYNk8PU5lJHzRjeYsngxX2+DALVBJ7N6A0Tb4DtlaZAifLYLTeU8jz o+lgTWDXtVFAhyxQmWg4eYCcPhcO4X8QnNbecrMq6RivG1RjUxOXFwSYIktxyG3wgLpR uNrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:organization:message-id:date:subject:cc:to :from:dkim-signature; bh=QEFEFTfhFTgTz8WN0CVlm/U0Yy69uIPJT1kBZsbF6yc=; fh=FnS9P2OJszqo7isshV63rXpyvoiIqNCcrSLEa0ise84=; b=e9va8orEshiBwyvdhwhrolmk4LqU2dvXX/D/QnllxYcA38g3KfOKjpnG/7gGf8DAHr SwGPTx0/0/nWM4KpFXKgkYhSl45ENfUwYWMWi8yhjrPqJTbqfOWnq4ZHFayc3rzFrHjf XlD0Sdlh3rizt7nddjg4SqjmKiq4r2qshQgRhBt0sNVAoY21PFXPUbcCNqElY/RCWlzT vs1/94HCm1Vo5lDvGlz6J+Yp4G2tH49g7RvsbwzaaXmuVDgfu9oZKaxm32pyJr9V3MHx X5Cg5QT/YRAnqWhT3K7ohSJVf00U1JtjDTd1ZK5aQGYyPj07BfqVWo2YCfdMIhPEKQD3 emNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=E6GmhAVL; 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 fi14-20020a056a00398e00b0067f03c85d73si11387892pfb.115.2023.07.17.03.11.49; Mon, 17 Jul 2023 03:12:01 -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=@intel.com header.s=Intel header.b=E6GmhAVL; 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 S229998AbjGQJqE (ORCPT + 99 others); Mon, 17 Jul 2023 05:46:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230487AbjGQJpw (ORCPT ); Mon, 17 Jul 2023 05:45:52 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 375F8191 for ; Mon, 17 Jul 2023 02:45:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689587151; x=1721123151; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EDXsm4U6iPwm/gHpcA6eH2CMKgicEHwy5vRLSE1JCUI=; b=E6GmhAVL0Gf5eS79Kx9o61Aa5aKuGMwzqynDWxTnXLFdhOOSB7TPgJNp aQnNpnLRZEx4lkvzxalMkPbS+q/xyKtYC7LFZKLUKzK9sr4qtKUy9c0pH coXotaq2TXQfBm7Dv/2gL2ROJq13J0Diu4QZHsJjJivwnCdg8tdgcCTFx h69KcH2JOPFnHOnho6Z+/PbuZgpUuYZQqZxj0vZUvFXVKkbCrPjEeUrPX bp5AVnyqaXHsszC9/9A/UUAVIB5mIsUVkBeo8ubGD0RjZStTq6mEGWf/a sAUJk0xQcVfmREcO0rULNCstv+shLy5E7XI55pgm/TV6uTJ/85YvPY3MC A==; X-IronPort-AV: E=McAfee;i="6600,9927,10773"; a="368531673" X-IronPort-AV: E=Sophos;i="6.01,211,1684825200"; d="scan'208";a="368531673" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jul 2023 02:45:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10773"; a="847220700" X-IronPort-AV: E=Sophos;i="6.01,211,1684825200"; d="scan'208";a="847220700" Received: from jkrzyszt-mobl2.ger.corp.intel.com ([10.213.9.176]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jul 2023 02:45:47 -0700 From: Janusz Krzysztofik To: "x86@kernel.org" , "Edgecombe, Rick P" Cc: "Gross, Jurgen" , "bp@alien8.de" , "dave.hansen@linux.intel.com" , "Marczykowski, Marek" , "andi.shyti@linux.intel.com" , "mingo@redhat.com" , "tglx@linutronix.de" , "linux-kernel@vger.kernel.org" , "intel-gfx@lists.freedesktop.org" Subject: Re: [PATCH v3 RESEND] x86/mm: Fix PAT bit missing from page protection modify mask Date: Mon, 17 Jul 2023 11:45:45 +0200 Message-ID: <7545651.EvYhyI6sBW@jkrzyszt-mobl2.ger.corp.intel.com> Organization: Intel Technology Poland sp. z o.o. - ul. Slowackiego 173, 80-298 Gdansk - KRS 101882 - NIP 957-07-52-316 In-Reply-To: <9c14a3597d658a065e853b6e5f64ff21b4b7b575.camel@intel.com> References: <20230710073613.8006-2-janusz.krzysztofik@linux.intel.com> <9c14a3597d658a065e853b6e5f64ff21b4b7b575.camel@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE 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 Hi Rick, On Monday, 10 July 2023 19:58:07 CEST Edgecombe, Rick P wrote: > On Mon, 2023-07-10 at 09:36 +0200, Janusz Krzysztofik wrote: > > The issue needs to be fixed by including _PAGE_PAT bit into a bitmask > > used > > by pgprot_modify() for selecting bits to be preserved. We can do > > that > > either internally to pgprot_modify() (as initially proposed), or by > > making > > _PAGE_PAT a part of _PAGE_CHG_MASK. If we go for the latter then, > > since > > _PAGE_PAT is the same as _PAGE_PSE, we need to note that > > _HPAGE_CHG_MASK > > -- a huge pmds' counterpart of _PAGE_CHG_MASK, introduced by commit > > c489f1257b8c ("thp: add pmd_modify"), defined as (_PAGE_CHG_MASK | > > _PAGE_PSE) -- will no longer differ from _PAGE_CHG_MASK. If such > > modification of _PAGE_CHG_MASK was irrelevant to its users then one > > might > > wonder why that new _HPAGE_CHG_MASK symbol was introduced instead of > > reusing the existing one with that otherwise irrelevant bit > > (_PAGE_PSE in > > that case) added. > > > > Assume that adding _PAGE_PAT to _PAGE_CHG_MASK doesn't break > > pte_modify() > > and its users, and go for it. Also, add _PAGE_PAT_LARGE to > > _HPAGE_CHG_MASK for symmetry. For better clarity, split out common > > bits > > from both symbols to another one and use it together with specific > > bits > > when defining the masks. > > I think this whole entanglement is a bit confusing, but not > functionally broken. > > The problem is kind of that the existing code assumes that all vma- > >vm_page_prot relevant prot bit positions are identical between PTE and > PMDs. The bug is that _PAGE_PAT is not treated as relevant, but it > actually is. So fixing it breaks the assumption. > > Not trying to suggest we shouldn't do the simple fix here, but I wonder > if it is worth clearing it up further? > > I think at least we should include a comment around _PAGE_CHG_MASK or > _PAGE_PAT as to why it is assumed that this will not cause problems. > This way, someone in the future can see the error in the reasoning if > something changes. Would something like this be useful and correct > reasoning? > > /* > * Bit 7 has different meanings for PTEs and PMDs. On PTEs it is the > * PAT bit, and on PMDs it is the PSE bit. This creates some confusing > * entanglement in code that operates page table bits that end up in > * both PTEs and PMDs. > * > * vma->vm_page_prot is used for constructing both PTE's and huge > * page PMDs. This member is set via vm_pgprot_modify() which, despite > * vma->vm_page_prot being used to set huge pages as well, only filters > * bits with _PAGE_CHG_MASK (actually in pgprot_modify()). This means > * by having _PAGE_PAT in _PAGE_CHG_MASK, _PAGE_PSE will also be > * preserved. AFAICU, your concern is different than mine was. I was wondering if by adding _PAGE_PAT to _PAGE_CHG_MASK we didn't break PTEs in pte_modify(), while you seem to be rather thinking of potential breakage of PMDs in pgprot_modify(). > * > * This should be harmless because vma->vm_page_prot is only applied to > * leaf page table entries. In the case of _PAGE_PAT in > * vma->vm_page_prot being inadvertently applied to a huge page, this > * is fine because _PAGE_PSE will already be being set on a huge page. > * It is expected that code should not try to add _PAGE_PSE to > * vma->vm_page_prot, so there shouldn't be the case of inadvertently > * setting _PAGE_PAT in a PTE. So the saving grace is that PSE is > * *always* set on PMDs that add bits derived from vma->vm_page_prot. > */ > I could add your comment and resubmit, but my experience from communication with audience of this patch tells me that silence means rather no acceptance. Thanks, Janusz