From patchwork Tue Jun 14 06:39:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hyeonggon Yoo <42.hyeyoo@gmail.com> X-Patchwork-Id: 12880492 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 50A09C43334 for ; Tue, 14 Jun 2022 06:40:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DDA956B0404; Tue, 14 Jun 2022 02:40:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D64478D0210; Tue, 14 Jun 2022 02:40:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BB6858D020F; Tue, 14 Jun 2022 02:40:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id A819E6B0404 for ; Tue, 14 Jun 2022 02:40:05 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 8212D356FF for ; Tue, 14 Jun 2022 06:40:05 +0000 (UTC) X-FDA: 79575891570.20.88C44F3 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by imf19.hostedemail.com (Postfix) with ESMTP id 3B6E31A0091 for ; Tue, 14 Jun 2022 06:40:05 +0000 (UTC) Received: by mail-pl1-f176.google.com with SMTP id h1so6968553plf.11 for ; Mon, 13 Jun 2022 23:40:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KkeX/HZamFTBlpDUrjr6IEnoOZGEHEMo14ra6Yxk+ps=; b=TnzlNFuQWvRZT5fpMqRFx5dvZCXlI03BiTFUIixFga+sXNMn1vhK79oWilCt2FhDMZ D3f6UXf//EETfm4DrWwYSPQLm88J7ZCyQ5Xml5IQhXS0KN3TY3yTiKhR02owR4u313O0 v8RJFopqJKeWDOQ6+CkE/qENbkVp4J+kBY4xdT5arr6S+OEO+ANAlDwK0AsXofxpm6g4 6zCvYqCgU0G0P8LOmhbG4hxLHZCDnEn2JABYknUiRCdsBvx0cBmawzCK4BNix1HzuPRz By/GZ3PTymhhruwgPZ2F5CuGq4zaul0QoPdoz6HAzV+o82LIccFvfPfadzLtLYYGMBXw 6nvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KkeX/HZamFTBlpDUrjr6IEnoOZGEHEMo14ra6Yxk+ps=; b=UJK38gXxYOw3975cnYTCMy4LPCtfNNf1EzogPRZ5j/+HXSqzGCnqU5bFy1tVfUCDsL GG3DarK7f6EkhUeeRseTqwqe7Dm5UdqzpsMc2R1daijnOYKcdyo5LRLDIdCdSt2ehYqP f39v7ogqgmPmDpUj0ZDKqUJBwz1FVj3t2vDDzkKaSr8aBG9GDnnvOrGbJNDluxF5ULwe 3bT7X4/4Hmaa/vGWCChngoe9p9XPKDbpOTrhp2NFwztbevLQo52jMV5k+Q598AhgDHTP 4/UC/rqgtBvynXbsGjpuwSQGlD9KVJekclFiTn90aSGCX1fkTIcla579ke6jlwqPdJ7y lEkQ== X-Gm-Message-State: AJIora9wiH+Bl/59yYIHMSNtSVOmJkNHZT+iW9SFsmb2PtciCGQa/UT3 FDOjPXJ7M/6eKN0djV7hg2I= X-Google-Smtp-Source: AGRyM1u2w23gOa4xhpBOm5rCSU+j1jcGX+G04jWltPJLQpbZ8v38boiqNgtUcgZBkA0/G2BDlU3Ibg== X-Received: by 2002:a17:903:32c5:b0:164:1a67:30c5 with SMTP id i5-20020a17090332c500b001641a6730c5mr2785172plr.31.1655188804253; Mon, 13 Jun 2022 23:40:04 -0700 (PDT) Received: from hyeyoo.. ([114.29.24.243]) by smtp.gmail.com with ESMTPSA id v10-20020a170902b7ca00b0016363b15acasm6284451plz.112.2022.06.13.23.39.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jun 2022 23:40:03 -0700 (PDT) From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , Dan Williams , Paolo Bonzini , Jane Chu , "Aneesh Kumar K . V" , Sean Christopherson , Tianyu Lan , Mike Rapoport , Rick Edgecombe , linux-mm@kvack.org Cc: Borislav Petkov , x86@kernel.org, Hyeonggon Yoo <42.hyeyoo@gmail.com> Subject: [RFC 2/2] x86/mm/cpa: drop pgprot_clear_protnone_bits() Date: Tue, 14 Jun 2022 15:39:33 +0900 Message-Id: <20220614063933.13030-3-42.hyeyoo@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220614063933.13030-1-42.hyeyoo@gmail.com> References: <20220614063933.13030-1-42.hyeyoo@gmail.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655188805; a=rsa-sha256; cv=none; b=Dg7hKaqqHOmaTyLrngteEy9Ts9LfzBzNE0gdOfx9pvGBQzdeVwGR15v2Kupps48ZnHhEsN RnbAc0jwZz7ZlRehtUCN8qW3oKJgjk1T4anHElDXSn+N3WAVZudLeDt9pQcVFZ5z1ss+M5 hLq5cZTrMO5aO8LnNINa3pd6nVCapKk= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=TnzlNFuQ; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf19.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.214.176 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655188805; 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=KkeX/HZamFTBlpDUrjr6IEnoOZGEHEMo14ra6Yxk+ps=; b=DA8FHKuUf4Bnj4vcY+RyeAhlpM6se0b8T4uoQOislOQpcIGye6ExM5Pf2T4zT8hYCO3kQv fwheQdScGsjwXvMzkBpqiwwKLH+cjew8jmF4IBe7ns8OaqDpVCShFtmwqDkYEIGRL373Yu 5GU3QjzLBIQUz7ZHSxuP4Nh2Xld06ZI= Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=TnzlNFuQ; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf19.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.214.176 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com X-Rspam-User: X-Stat-Signature: b9dqbrq7ndkubzjoy3gutcjuffxitzoh X-Rspamd-Queue-Id: 3B6E31A0091 X-Rspamd-Server: rspam08 X-HE-Tag: 1655188805-333923 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: commit a8aed3e0752b4 ("x86/mm/pageattr: Prevent PSE and GLOABL leftovers to confuse pmd/pte_present and pmd_huge") made CPA clear _PAGE_GLOBAL when _PAGE_PRESENT is not set. This prevents kernel crashing when kernel reads a page with !_PAGE_PRESENT and _PAGE_PROTNONE (_PAGE_GLOBAL). And then it set _PAGE_GLOBAL back when setting _PAGE_PRESENT again. After commit d1440b23c922d ("x86/mm: Factor out pageattr _PAGE_GLOBAL setting") made kernel not set unconditionally _PAGE_GLOBAL, pages lose global flag after _set_pages_np() and _set_pages_p() are called. But after commit 3166851142411 ("x86: skip check for spurious faults for non-present faults"), spurious_kernel_fault() does not confuse pte/pmd entries with _PAGE_PROTNONE as present anymore. So simply drop pgprot_clear_protnone_bits(). Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- arch/x86/mm/pat/set_memory.c | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c index 67cf969fed0d..8a8ce8d78694 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -746,23 +746,6 @@ static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte) #endif } -static pgprot_t pgprot_clear_protnone_bits(pgprot_t prot) -{ - /* - * _PAGE_GLOBAL means "global page" for present PTEs. - * But, it is also used to indicate _PAGE_PROTNONE - * for non-present PTEs. - * - * This ensures that a _PAGE_GLOBAL PTE going from - * present to non-present is not confused as - * _PAGE_PROTNONE. - */ - if (!(pgprot_val(prot) & _PAGE_PRESENT)) - pgprot_val(prot) &= ~_PAGE_GLOBAL; - - return prot; -} - static int __should_split_large_page(pte_t *kpte, unsigned long address, struct cpa_data *cpa) { @@ -824,7 +807,6 @@ static int __should_split_large_page(pte_t *kpte, unsigned long address, * different bit positions in the two formats. */ req_prot = pgprot_4k_2_large(req_prot); - req_prot = pgprot_clear_protnone_bits(req_prot); if (pgprot_val(req_prot) & _PAGE_PRESENT) pgprot_val(req_prot) |= _PAGE_PSE; @@ -1013,8 +995,6 @@ __split_large_page(struct cpa_data *cpa, pte_t *kpte, unsigned long address, return 1; } - ref_prot = pgprot_clear_protnone_bits(ref_prot); - /* * Get the target pfn from the original entry: */ @@ -1246,8 +1226,6 @@ static void populate_pte(struct cpa_data *cpa, pte = pte_offset_kernel(pmd, start); - pgprot = pgprot_clear_protnone_bits(pgprot); - while (num_pages-- && start < end) { set_pte(pte, pfn_pte(cpa->pfn, pgprot)); @@ -1542,8 +1520,6 @@ static int __change_page_attr(struct cpa_data *cpa, int primary) new_prot = static_protections(new_prot, address, pfn, 1, 0, CPA_PROTECT); - new_prot = pgprot_clear_protnone_bits(new_prot); - /* * We need to keep the pfn from the existing PTE, * after all we're only going to change it's attributes