From patchwork Mon Aug 8 14:56:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Lu X-Patchwork-Id: 12938859 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D865CC25B0C for ; Mon, 8 Aug 2022 14:57:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4B9366B0071; Mon, 8 Aug 2022 10:57:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4405C8E0002; Mon, 8 Aug 2022 10:57:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3076A6B0073; Mon, 8 Aug 2022 10:57:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 20A436B0071 for ; Mon, 8 Aug 2022 10:57:36 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id E5DB0A0F98 for ; Mon, 8 Aug 2022 14:57:35 +0000 (UTC) X-FDA: 79776729270.12.732F35A Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by imf01.hostedemail.com (Postfix) with ESMTP id 22D9440178 for ; Mon, 8 Aug 2022 14:57:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1659970655; x=1691506655; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RqWLLHXdKq7i3jEZDCWPo2WblS5wC3PZ6h5tyOrVLyQ=; b=VM1r39Lszl3PX0aG6E+nDZTFpxslCC4feklX8Ja+vDq6IeR+tcPMm87O XuUlLEApx7gFrBeuJgDDpywm91NqfuZfuCXRkTvZbASLG15I9WkQev7Fw /148Kmh2hRYZ4OmedFleoYkFYoT/hkdKabzx1KWF/mxCK6JiRXg4L6jpJ vcSJ7gQsOrD7qhS2w2BugiRrJgnefCOamqlcgmQGqmQlaeZl2hO3NJ5Op S94PNBnchNPgtHdgjpiQPWYxkIXyRfBBgUNgBuuYdkK9ePRBhq+E9dIWY nfh8UTJkXGWe51y/Pv9U4R/RwKGIooObk4lqxonrDg3lXy5NG8qYglpmm Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10433"; a="376904739" X-IronPort-AV: E=Sophos;i="5.93,222,1654585200"; d="scan'208";a="376904739" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Aug 2022 07:57:34 -0700 X-IronPort-AV: E=Sophos;i="5.93,222,1654585200"; d="scan'208";a="663980492" Received: from ziqianlu-desk2.sh.intel.com ([10.238.2.76]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Aug 2022 07:57:32 -0700 From: Aaron Lu To: Dave Hansen , Rick Edgecombe Cc: Song Liu , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 1/4] x86/mm/cpa: restore global bit when page is present Date: Mon, 8 Aug 2022 22:56:46 +0800 Message-Id: <20220808145649.2261258-2-aaron.lu@intel.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220808145649.2261258-1-aaron.lu@intel.com> References: <20220808145649.2261258-1-aaron.lu@intel.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659970655; a=rsa-sha256; cv=none; b=LBuKShaMS3jY/Vvy9nvtDQ2m5w6CD59bEx0eBQEpAMTl+D6DIIcOE8B9GSmjt83cZDL5kl 4sJ/RGQZP6MjAdH5fQfZ0E02hSy2nCfilXfgdi9HDDo88EHVM+Dn5OKRNHn6Gm0U5yjHDo Am8D8xGuVlpd1ZyZ3UNzfwYZgI9Y6CE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659970655; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=TzMGC4+/VGSo67bF0WlkxoKjHQ2K9FAGMqQM0siIVvM=; b=p3bXdG1d+jZy8mbC8EO/uIgTGpPetZUfyvbm0uos47Hkr6F00RVCKq2eZAokAeaqqZJC04 l/kVp9G9CWTDQsIgxRm7ZTBec39V/PDyyKn86jVBzSuF1TlzoBztC855nkj+p4ebulrRET W70710Jx3yWOnpbBfQXLiZtsEZzq4bY= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=VM1r39Ls; spf=pass (imf01.hostedemail.com: domain of aaron.lu@intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=aaron.lu@intel.com; dmarc=pass (policy=none) header.from=intel.com X-Stat-Signature: y6zsmqx5yxywe7p3hraex1yxgcxejsj3 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 22D9440178 Authentication-Results: imf01.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=VM1r39Ls; spf=pass (imf01.hostedemail.com: domain of aaron.lu@intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=aaron.lu@intel.com; dmarc=pass (policy=none) header.from=intel.com X-HE-Tag: 1659970654-13594 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: For configs that don't have PTI enabled or cpus that don't need meltdown mitigation, current kernel can lose GLOBAL bit after a page goes through a cycle of present -> not present -> present. It happened like this(__vunmap() does this in vm_remove_mappings()): original page protection: 0x8000000000000163 (NX/G/D/A/RW/P) set_memory_np(page, 1): 0x8000000000000062 (NX/D/A/RW) lose G and P set_memory_p(pagem 1): 0x8000000000000063 (NX/D/A/RW/P) restored P In the end, this page's protection no longer has Global bit set and this would create problem for this merge small mapping feature. For this reason, restore Global bit for systems that do not have PTI enabled if page is present. (pgprot_clear_protnone_bits() deserves a better name if this patch is acceptible but first, I would like to get some feedback if this is the right way to solve this so I didn't bother with the name yet) Signed-off-by: Aaron Lu --- arch/x86/mm/pat/set_memory.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c index 1abd5438f126..33657a54670a 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -758,6 +758,8 @@ static pgprot_t pgprot_clear_protnone_bits(pgprot_t prot) */ if (!(pgprot_val(prot) & _PAGE_PRESENT)) pgprot_val(prot) &= ~_PAGE_GLOBAL; + else + pgprot_val(prot) |= _PAGE_GLOBAL & __default_kernel_pte_mask; return prot; }