From mboxrd@z Thu Jan 1 00:00:00 1970 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 1CA48C433FE for ; Tue, 22 Nov 2022 16:58:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 436586B0071; Tue, 22 Nov 2022 11:58:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3E7B36B0073; Tue, 22 Nov 2022 11:58:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2AE528E0001; Tue, 22 Nov 2022 11:58:13 -0500 (EST) 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 16B386B0071 for ; Tue, 22 Nov 2022 11:58:13 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id B4F7DC01C6 for ; Tue, 22 Nov 2022 16:58:12 +0000 (UTC) X-FDA: 80161686024.12.3DA7DE8 Received: from server.eikelenboom.it (server.eikelenboom.it [91.121.65.215]) by imf24.hostedemail.com (Postfix) with ESMTP id 16D8D18000E for ; Tue, 22 Nov 2022 16:58:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=eikelenboom.it; s=20180706; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date:Message-ID:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=H6t2vr3/228MGqi5OTqaW5cnhOLcZTruHIsBGnxyGhY=; b=EGT6r8Tw0ldjoY/OA7z2dj++Jt RLwO+w+J0DbJBP2Yzy0PFGyCfdvFrhuvqbYOdxnNr3nWxOybp1czj1YTbXJVMRnIIoV6K1ihb7ReZ 6Tltqdk7RErFvd0ZYKCMOtI4toGGXymprPJ6yXh8euSE+a7IRaZQd66zp/tU3VjsQwME=; Received: from 131-195-250-62.ftth.glasoperator.nl ([62.250.195.131]:53692 helo=[172.16.1.50]) by server.eikelenboom.it with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1oxWbf-00033s-1p; Tue, 22 Nov 2022 17:58:47 +0100 Message-ID: Date: Tue, 22 Nov 2022 17:57:50 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: [PATCH] mm: introduce arch_has_hw_pmd_young() Content-Language: nl-NL To: Juergen Gross , linux-kernel@vger.kernel.org, x86@kernel.org, linux-mm@kvack.org Cc: yuzhao@google.com, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andrew Morton References: <20221121093245.4587-1-jgross@suse.com> <40c58b1b-9b90-ccd8-1387-362de236af2a@suse.com> From: Sander Eikelenboom In-Reply-To: <40c58b1b-9b90-ccd8-1387-362de236af2a@suse.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669136291; a=rsa-sha256; cv=none; b=Bm5cde/dOO+LsGbZPqer1OFs1ctQzO7rAXE4peJ44sUqa6YOuXXUIy8vk12YMqzNV4cFjf KPcFv/6Nht2iCT3reMpwCPFwOVP9UINQ2PW95TBXhkG19KV4dvPGhwqRk2OqbW0sD1uDs7 5GQBIkPAx5IoMNmtPaZMxmXM9N7hbx8= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=eikelenboom.it header.s=20180706 header.b=EGT6r8Tw; spf=pass (imf24.hostedemail.com: domain of linux@eikelenboom.it designates 91.121.65.215 as permitted sender) smtp.mailfrom=linux@eikelenboom.it; dmarc=pass (policy=none) header.from=eikelenboom.it ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669136291; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=H6t2vr3/228MGqi5OTqaW5cnhOLcZTruHIsBGnxyGhY=; b=nUVm7nyNPoSAFCIfUEqUsf4nuWur9qfWWyeS+JrSwOkbkBrhI9CvaqYcjJQtXggedt+ozF R6R2+T+RgLkUtM+4XbL3hIKaCyNKTxOBx6NjDB4FvGRsCC3uevEzqjVIwz5f0EHr8K0seh 8NqdjuU5p9smyTIHU6tKwP8pp8s4fEM= X-Stat-Signature: h99r4xabgsthpwd3ngnpq4wwosyhoezz X-Rspamd-Queue-Id: 16D8D18000E X-Rspam-User: Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=eikelenboom.it header.s=20180706 header.b=EGT6r8Tw; spf=pass (imf24.hostedemail.com: domain of linux@eikelenboom.it designates 91.121.65.215 as permitted sender) smtp.mailfrom=linux@eikelenboom.it; dmarc=pass (policy=none) header.from=eikelenboom.it X-Rspamd-Server: rspam02 X-HE-Tag: 1669136290-721543 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: On 21/11/2022 10:50, Juergen Gross wrote: > On 21.11.22 10:32, Juergen Gross wrote: >> When running as a Xen PV guests commit eed9a328aa1a ("mm: x86: add >> CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG") can cause a protection violation >> in pmdp_test_and_clear_young(): >> >> BUG: unable to handle page fault for address: ffff8880083374d0 >> #PF: supervisor write access in kernel mode >> #PF: error_code(0x0003) - permissions violation >> PGD 3026067 P4D 3026067 PUD 3027067 PMD 7fee5067 PTE 8010000008337065 >> Oops: 0003 [#1] PREEMPT SMP NOPTI >> CPU: 7 PID: 158 Comm: kswapd0 Not tainted 6.1.0-rc5-20221118-doflr+ #1 >> RIP: e030:pmdp_test_and_clear_young+0x25/0x40 >> >> This happens because the Xen hypervisor can't emulate direct writes to >> page table entries other than PTEs. >> >> This can easily be fixed by introducing arch_has_hw_pmd_young() >> similar to arch_has_hw_pte_young() and test that instead of >> CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG. > > I just spotted that I missed to update my commit message to match the > patch: > > s/arch_has_hw_pmd_young/arch_has_hw_nonleaf_pmd_young/ > > I'll wait with a resend in order to get some feedback first. > > > Juergen Hi Juergen, Thanks for the patch, had it running overnight and did some kernel compiles. No crashes with this patch so far, so it seems to work for me. -- Sander >> >> Fixes: eed9a328aa1a ("mm: x86: add CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG") >> Reported-by: Sander Eikelenboom >> Signed-off-by: Juergen Gross >> --- >> arch/x86/include/asm/pgtable.h | 8 ++++++++ >> include/linux/pgtable.h | 11 +++++++++++ >> mm/vmscan.c | 10 +++++----- >> 3 files changed, 24 insertions(+), 5 deletions(-) >> >> diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h >> index 5059799bebe3..c567a6ed17ce 100644 >> --- a/arch/x86/include/asm/pgtable.h >> +++ b/arch/x86/include/asm/pgtable.h >> @@ -1438,6 +1438,14 @@ static inline bool arch_has_hw_pte_young(void) >> return true; >> } >> >> +#ifdef CONFIG_XEN_PV >> +#define arch_has_hw_nonleaf_pmd_young arch_has_hw_nonleaf_pmd_young >> +static inline bool arch_has_hw_nonleaf_pmd_young(void) >> +{ >> + return !cpu_feature_enabled(X86_FEATURE_XENPV); >> +} >> +#endif >> + >> #ifdef CONFIG_PAGE_TABLE_CHECK >> static inline bool pte_user_accessible_page(pte_t pte) >> { >> diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h >> index a108b60a6962..58fc7e2d9575 100644 >> --- a/include/linux/pgtable.h >> +++ b/include/linux/pgtable.h >> @@ -260,6 +260,17 @@ static inline int pmdp_clear_flush_young(struct vm_area_struct *vma, >> #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ >> #endif >> >> +#ifndef arch_has_hw_nonleaf_pmd_young >> +/* >> + * Return whether the accessed bit in non-leaf PMD entries is supported on the >> + * local CPU. >> + */ >> +static inline bool arch_has_hw_nonleaf_pmd_young(void) >> +{ >> + return IS_ENABLED(CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG); >> +} >> +#endif >> + >> #ifndef arch_has_hw_pte_young >> /* >> * Return whether the accessed bit is supported on the local CPU. >> diff --git a/mm/vmscan.c b/mm/vmscan.c >> index 04d8b88e5216..a04ac3b18326 100644 >> --- a/mm/vmscan.c >> +++ b/mm/vmscan.c >> @@ -3975,7 +3975,7 @@ static void walk_pmd_range_locked(pud_t *pud, unsigned long next, struct vm_area >> goto next; >> >> if (!pmd_trans_huge(pmd[i])) { >> - if (IS_ENABLED(CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG) && >> + if (arch_has_hw_nonleaf_pmd_young() && >> get_cap(LRU_GEN_NONLEAF_YOUNG)) >> pmdp_test_and_clear_young(vma, addr, pmd + i); >> goto next; >> @@ -4073,14 +4073,14 @@ static void walk_pmd_range(pud_t *pud, unsigned long start, unsigned long end, >> #endif >> walk->mm_stats[MM_NONLEAF_TOTAL]++; >> >> -#ifdef CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG >> - if (get_cap(LRU_GEN_NONLEAF_YOUNG)) { >> + if (arch_has_hw_nonleaf_pmd_young() && >> + get_cap(LRU_GEN_NONLEAF_YOUNG)) { >> if (!pmd_young(val)) >> continue; >> >> walk_pmd_range_locked(pud, addr, vma, args, bitmap, &pos); >> } >> -#endif >> + >> if (!walk->force_scan && !test_bloom_filter(walk->lruvec, walk->max_seq, pmd + i)) >> continue; >> >> @@ -5354,7 +5354,7 @@ static ssize_t show_enabled(struct kobject *kobj, struct kobj_attribute *attr, c >> if (arch_has_hw_pte_young() && get_cap(LRU_GEN_MM_WALK)) >> caps |= BIT(LRU_GEN_MM_WALK); >> >> - if (IS_ENABLED(CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG) && get_cap(LRU_GEN_NONLEAF_YOUNG)) >> + if (arch_has_hw_nonleaf_pmd_young() && get_cap(LRU_GEN_NONLEAF_YOUNG)) >> caps |= BIT(LRU_GEN_NONLEAF_YOUNG); >> >> return snprintf(buf, PAGE_SIZE, "0x%04x\n", caps); >