From patchwork Mon Jul 17 20:19:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 121591 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp1327943vqt; Mon, 17 Jul 2023 13:26:11 -0700 (PDT) X-Google-Smtp-Source: APBJJlF7qswhRBqRuj172pXCSCtwvsYfzTXSbqFaj3VttM7IJh3ZgarXJRXs5eecSmnBIEXpkVwi X-Received: by 2002:a17:902:ef96:b0:1b8:7d0d:5ac5 with SMTP id iz22-20020a170902ef9600b001b87d0d5ac5mr9411225plb.50.1689625571260; Mon, 17 Jul 2023 13:26:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689625571; cv=none; d=google.com; s=arc-20160816; b=s/PZYWD5djgr9yzrKc2Dn9w7TBhy9J+xUuqO/4KpZwfG/Aa9S1uLKwfRSo0DdhAA2h Khw40Wr81JrhhAEubbqHv5cePuNNW0y5v34Iq6S77PfXL+9L4jad0B0zNKE7eh2umSES MWoa33HkO/t3PN0SWg88cfoW+EM2nKjtOXLtHEx+PZhkm+Y8My2731KBR/0qTwc/PUSR 222O4voWlPv7kyorOy6/7LaOGXEhozNWTGp0Bzez1uwaBCY90m/uTgnZF0O4VkAAN3iN Vgd94LQRT72WtoXPAARROvkbGmxiEtsUKBY3u4gH/UWVhctsrAA3Ge/KBDYr6Kg2+Cp8 YFhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:cc:subject:to:reply-to:sender:from :dkim-signature:dkim-signature:date; bh=5g+e7Kt7N77MeQFIg5zCypZ5xcAyk/U+HKCYby31Fyo=; fh=NRZ8ckGiKEjwkOHTM6kJesNpW6m5ZbVaupb9tNq6hFg=; b=vVGGD1hWyWtXo8X9lWnxo+a9K83mfympyQ47AqIhJ5VzubMPzEoQ4BUVNtL8oYtfkF huWuhv88a/oWD6hr5LutjfWFX1cdGGk7kGyCebadpQfAHCx/Y1Jx9s3jX+STLmBy4xTA SQi3zx7eb+PS4I4vI1VKxWm05H3Vd8TwXIAM1n5GX6aa+edVXK+q/RM0kZnQi2tiO3SV Yb1svpGBgMz343oVYNOsxIOMINutsp7sdCGpnK6sa+C8UwYCyuLY2rcT0fWgxOu52B5C behrZRZ5odzLrsbvYU6KXzBHwXbc/sjhb15pKgQ2kWVBR9346b1iKCg1pSW9FW+gihY9 5Vpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=0Vkkqv6r; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l3-20020a170903244300b001b886728cddsi407444pls.416.2023.07.17.13.25.58; Mon, 17 Jul 2023 13:26:11 -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=@linutronix.de header.s=2020 header.b=0Vkkqv6r; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230177AbjGQUTp (ORCPT + 99 others); Mon, 17 Jul 2023 16:19:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230022AbjGQUTn (ORCPT ); Mon, 17 Jul 2023 16:19:43 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6084194; Mon, 17 Jul 2023 13:19:41 -0700 (PDT) Date: Mon, 17 Jul 2023 20:19:39 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1689625180; h=from:from:sender:sender:reply-to: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:content-transfer-encoding; bh=5g+e7Kt7N77MeQFIg5zCypZ5xcAyk/U+HKCYby31Fyo=; b=0Vkkqv6rXDXMJrftEIS7sj/xF2s8HAlmY5tPQsQv9ftbwGa1hyvrFCvbw6HjEW81duQAKQ oM41APpPcBvkJoKb6nZIH9CWx3F2qw8sXwISmA3Xt5jCXaXdzD5gfvZDO5FcnwHlq7Y4CC E8Gv2XpRVCIpA4ZpwObGgZTyctY5TDulHPp3IsC73pysjdEt0O8AfZg9piXAQx143LXFs/ rUt4c8JLzwoJVakcIoTgdjknn0l6eQervtWqkmJsyUYdBcuQZki+sPCHVMrdsWnNlVZfrP Kf5q9L1xsQJwJer6p3jJdja6T2c5vps4ES/FaE/+plPV+HtQOX4RuSJWfDB8+g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1689625180; h=from:from:sender:sender:reply-to: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:content-transfer-encoding; bh=5g+e7Kt7N77MeQFIg5zCypZ5xcAyk/U+HKCYby31Fyo=; b=PntMVBuDpiscCrpCJJP7/KmrkK9UkFUvnK/C0M3O9/t6Eriz4+M+p1yGmUtf4awGnJdai1 9IlqBoZU1oEETeCg== From: "tip-bot2 for Janusz Krzysztofik" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/mm] x86/mm: Fix PAT bit missing from page protection modify mask Cc: Janusz Krzysztofik , Dave Hansen , Andi Shyti , Juergen Gross , marmarek@invisiblethingslab.com, x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <168962517947.28540.12391028567128094902.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771700822700482543 X-GMAIL-MSGID: 1771700822700482543 The following commit has been merged into the x86/mm branch of tip: Commit-ID: 548cb932051fb6232ac983ed6673dae7bdf3cf4c Gitweb: https://git.kernel.org/tip/548cb932051fb6232ac983ed6673dae7bdf3cf4c Author: Janusz Krzysztofik AuthorDate: Mon, 10 Jul 2023 09:36:14 +02:00 Committer: Dave Hansen CommitterDate: Mon, 17 Jul 2023 07:41:45 -07:00 x86/mm: Fix PAT bit missing from page protection modify mask Visible glitches have been observed when running graphics applications on Linux under Xen hypervisor. Those observations have been confirmed with failures from kms_pwrite_crc Intel GPU test that verifies data coherency of DRM frame buffer objects using hardware CRC checksums calculated by display controllers, exposed to userspace via debugfs. Affected processing paths have then been identified with new IGT test variants that mmap the objects using different methods and caching modes [1]. When running as a Xen PV guest, Linux uses Xen provided PAT configuration which is different from its native one. In particular, Xen specific PTE encoding of write-combining caching, likely used by graphics applications, differs from the Linux default one found among statically defined minimal set of supported modes. Since Xen defines PTE encoding of the WC mode as _PAGE_PAT, it no longer belongs to the minimal set, depends on correct handling of _PAGE_PAT bit, and can be mismatched with write-back caching. When a user calls mmap() for a DRM buffer object, DRM device specific .mmap file operation, called from mmap_region(), takes care of setting PTE encoding bits in a vm_page_prot field of an associated virtual memory area structure. Unfortunately, _PAGE_PAT bit is not preserved when the vma's .vm_flags are then applied to .vm_page_prot via vm_set_page_prot(). Bits to be preserved are determined with _PAGE_CHG_MASK symbol that doesn't cover _PAGE_PAT. As a consequence, WB caching is requested instead of WC when running under Xen (also, WP is silently changed to WT, and UC downgraded to UC_MINUS). When running on bare metal, WC is not affected, but WP and WT extra modes are unintentionally replaced with WC and UC, respectively. WP and WT modes, encoded with _PAGE_PAT bit set, were introduced by commit 281d4078bec3 ("x86: Make page cache mode a real type"). Care was taken to extend _PAGE_CACHE_MASK symbol with that additional bit, but that symbol has never been used for identification of bits preserved when applying page protection flags. Support for all cache modes under Xen, including the problematic WC mode, was then introduced by commit 47591df50512 ("xen: Support Xen pv-domains using PAT"). 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. Add _PAGE_PAT to _PAGE_CHG_MASK and _PAGE_PAT_LARGE to _HPAGE_CHG_MASK for symmetry. Split out common bits from both symbols to a common symbol for clarity. [ dhansen: tweak the solution changelog description ] [1] https://gitlab.freedesktop.org/drm/igt-gpu-tools/-/commit/0f0754413f14 Fixes: 281d4078bec3 ("x86: Make page cache mode a real type") Signed-off-by: Janusz Krzysztofik Signed-off-by: Dave Hansen Reviewed-by: Andi Shyti Reviewed-by: Juergen Gross Tested-by: Marek Marczykowski-Górecki Link: https://gitlab.freedesktop.org/drm/intel/-/issues/7648 Link: https://lore.kernel.org/all/20230710073613.8006-2-janusz.krzysztofik%40linux.intel.com --- arch/x86/include/asm/pgtable_types.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h index ba3e255..a6deb67 100644 --- a/arch/x86/include/asm/pgtable_types.h +++ b/arch/x86/include/asm/pgtable_types.h @@ -125,11 +125,12 @@ * instance, and is *not* included in this mask since * pte_modify() does modify it. */ -#define _PAGE_CHG_MASK (PTE_PFN_MASK | _PAGE_PCD | _PAGE_PWT | \ - _PAGE_SPECIAL | _PAGE_ACCESSED | _PAGE_DIRTY | \ - _PAGE_SOFT_DIRTY | _PAGE_DEVMAP | _PAGE_ENC | \ - _PAGE_UFFD_WP) -#define _HPAGE_CHG_MASK (_PAGE_CHG_MASK | _PAGE_PSE) +#define _COMMON_PAGE_CHG_MASK (PTE_PFN_MASK | _PAGE_PCD | _PAGE_PWT | \ + _PAGE_SPECIAL | _PAGE_ACCESSED | _PAGE_DIRTY |\ + _PAGE_SOFT_DIRTY | _PAGE_DEVMAP | _PAGE_ENC | \ + _PAGE_UFFD_WP) +#define _PAGE_CHG_MASK (_COMMON_PAGE_CHG_MASK | _PAGE_PAT) +#define _HPAGE_CHG_MASK (_COMMON_PAGE_CHG_MASK | _PAGE_PSE | _PAGE_PAT_LARGE) /* * The cache modes defined here are used to translate between pure SW usage