From patchwork Tue Jun 14 06:39:32 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: 12880491 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 6C6E0C433EF for ; Tue, 14 Jun 2022 06:40:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BB6ED6B0402; Tue, 14 Jun 2022 02:40:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B67028D0210; Tue, 14 Jun 2022 02:40:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E0EB8D020F; Tue, 14 Jun 2022 02:40:00 -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 8B5F86B0402 for ; Tue, 14 Jun 2022 02:40:00 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id 6599D12128A for ; Tue, 14 Jun 2022 06:40:00 +0000 (UTC) X-FDA: 79575891360.16.645BD59 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by imf30.hostedemail.com (Postfix) with ESMTP id 0926A8008F for ; Tue, 14 Jun 2022 06:39:59 +0000 (UTC) Received: by mail-pl1-f177.google.com with SMTP id f9so7033263plg.0 for ; Mon, 13 Jun 2022 23:39:59 -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=r/OSHyw2h9GxpZzni9LUt3ZrKKoUqLFVHpCx3XbR62g=; b=Wx1qjnTVPh2e22cmROCEkhdSJqOfuId5wm6SWExe7RnKjvsO/QtFWzQy9hVNHTiE1K yE0PPIQ9TnMZBiQxjKVUrmkx6Im3Rp+Sa5eIZC4qZDGtLz0+gKAIS/U1OgWXqtyIDmrB V25tAzrpnCpdddkqX7B3EfZuSg3uXM/JG1bM3r9wMi8ch8CITXHyRZDnMblljrqPh4ML +WYx2aTY15j3sYBfrtzQkwS1oUewoKcY/BXk2rB2jrxJ7GbjR4fxVBkgfcUZTWYha93C pu5LsD/dwIplWyGHHfl2w+6uPHuYgYP7p+Bv34xVjs9iSV3mxDbdFXt4a1NvzDRaScr5 VqTQ== 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=r/OSHyw2h9GxpZzni9LUt3ZrKKoUqLFVHpCx3XbR62g=; b=7D9n8jzwJoWUraUacT18DmG/Nza1nXj/WQLan++tDymWrjsLGDIU9PeYpb5Qn4oXal 9Ba+ZLYKRXrCTExxZjcUOmaTl+FkQcSqJG32hK4wQmcrL+x+wiIXZXoyYThgfgdSlV9w 7MzrI5F3xHPfDDrVK6n+905Yq3igX0KERX/Q54Kzbnh7HSdAFXiPpdfAHtNcW0WSYxIa yMJo3WwrR2rsFF7I1MDMfTnE5nSbbJktXjJH0a+890GM++4hB4rvOGXTjz+E13pthTzY w6pdd6Jg2jMXlZGkG8k/+PeYKJtuo5irSqJeUyuqF90R/r7t3vrzbZm5NA1il4JiLcuS rUrA== X-Gm-Message-State: AOAM531g6K+l1tPg/rGDQNPfi2uRx4IgGMG9rSdaVDak6lHGLX65i/jQ WWw9krNq2PGt8sPuEpfoaRg= X-Google-Smtp-Source: ABdhPJy+LCV4T/obNQNDEmowoBnF/cAHBiGvkrR4Z+hS3nX5wU6Y0GdkndX8HxaTMqtnaHMKWMpjdg== X-Received: by 2002:a17:902:c951:b0:166:4f65:cff2 with SMTP id i17-20020a170902c95100b001664f65cff2mr2944322pla.7.1655188798999; Mon, 13 Jun 2022 23:39:58 -0700 (PDT) Received: from hyeyoo.. ([114.29.24.243]) by smtp.gmail.com with ESMTPSA id v10-20020a170902b7ca00b0016363b15acasm6284451plz.112.2022.06.13.23.39.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jun 2022 23:39:58 -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 1/2] x86/mm/cpa: always fail when user address is passed Date: Tue, 14 Jun 2022 15:39:32 +0900 Message-Id: <20220614063933.13030-2-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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655188800; 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=r/OSHyw2h9GxpZzni9LUt3ZrKKoUqLFVHpCx3XbR62g=; b=c/6A3kCrFke566J7emLxzgylRoz2XdTJ5UBzYLCpq5GMfMxbFAKcybzeA++QuzV+tXPhbc gqGvZQ0ngdczCdF2ZLU1M4xFI6WKteC1NB6piIm2O3uVLemfalbWZHamc9jU8Lx0vHq1l9 CpSN3fKPcepr5YeLd7fInBByasdaL0o= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Wx1qjnTV; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf30.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.214.177 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655188800; a=rsa-sha256; cv=none; b=YGZGok1+st0bHRyh2Ra+ceTFCkko3whs8mBZu7XrbNmhdrQYd73oJZO7sfGAbrlr6yJKTP TRp6UL7dXaBM1QgG9R4BchYcsFPc/4P7rersWoNE+Z/utZ45A5kJl7versyPOxId4Sf8nC UjYeIyrMBjGSBGtSUJeQ1kL4hd1eJws= X-Rspamd-Queue-Id: 0926A8008F X-Rspam-User: X-Stat-Signature: 3bswg8qktwmhzpu1cacqbka4trjyt77k Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Wx1qjnTV; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf30.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.214.177 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com X-Rspamd-Server: rspam04 X-HE-Tag: 1655188799-763396 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: Currently CPA is not used for user mappings (only pgd of init_mm or and efi_mm is used). For simplicity, always fail when user address is passed. Note that efi_mm uses 1:1 mapping so its address should not be considered as user address. Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- arch/x86/mm/pat/set_memory.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c index 1abd5438f126..67cf969fed0d 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -1514,6 +1515,11 @@ static int __change_page_attr(struct cpa_data *cpa, int primary) pte_t *kpte, old_pte; address = __cpa_addr(cpa, cpa->curpage); + + if (WARN((IS_ENABLED(CONFIG_EFI) ? cpa->pgd != efi_mm.pgd : true) + && address <= TASK_SIZE_MAX, + KERN_WARNING "CPA: Got a user address")) + return -EINVAL; repeat: kpte = _lookup_address_cpa(cpa, address, &level); if (!kpte) 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