From patchwork Fri Sep 27 12:51:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 831105 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70F80F9C1; Fri, 27 Sep 2024 12:52:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727441539; cv=fail; b=m9djbk1V3UdwsBIxhqSoUHOvWope/uE0SfdAtod9qYmLPlgGRPa/H2YTqhO7dysvI0MJeHt3HzWTs4cUhsZgZNN9uqdafJ7zVn1fs827lck3az0dqLYagTwMheZsnnI/I/Sz8p0mZTvIJKD+1B2QNSlJ60uc45NVXZoW0o6ISk8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727441539; c=relaxed/simple; bh=JJ0syywZks346iX3343ipqA9nVnqNorbEWhDbdKy50g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=LFbiAfyc+RIDS3xU/sPIMpnSKfrl2CRkYTnYyoOINe8QvZaR/ctprqAnvRSMgcwtKd38JzZUQjzViYeirO9WlpPnjLN509PjEIUm1OZdUdE3BQrUvrRUDxjWW46W4oL6Mo97SNdqYBo9sjgObCJuYyOlWtmSTbKC3K3lmUFMqYg= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=JWx099h6; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=HOBiU7q4; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="JWx099h6"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="HOBiU7q4" Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48R5gZN8025994; Fri, 27 Sep 2024 12:51:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=meQWsa6pqi4gRe3614XH1tchOUd5jCH9YSDFm265TZ8=; b= JWx099h6qd/XB92eMPNpuGjFSwqrvobzGWP21/J/25u9HvibT14t3ri+qAKt4oeS Y3NgrRWzeafem1mdpn52jl3SeScAhYNFCzyhomh9tVwdt5jppCYNtN11Uh11vWya QOlaMh8PM1NgG2XCPdcwYKX37N4XyTK9OZRvqyjNnxP/9nBkJWCentk2YUp6BNpY VL4DI8J2+sNuggaL/SyF394YeccRQYtvBGD6FovLIxgRzKR8P4rQ+HiOXA5ZavYT 4nAWM7DPFyAMBsWs/HkCIE1I9fSKYCv8Nb9ffqPjNJlLIrm9UDcoT3XrGtKOU4Zc EtFi6TGAFDrxQwPSKzuSYA== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41smx3d4gw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Sep 2024 12:51:35 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 48RBmmkC030416; Fri, 27 Sep 2024 12:51:34 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2170.outbound.protection.outlook.com [104.47.58.170]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 41smkdkc03-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Sep 2024 12:51:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JiBBXtTSdNDUQHG/XNLMKspR2kllJ1apoeOA8c0atQNppoTT/xNf6VUSlNpsKbLbKvCLVfI1r0WulGV0DcvMdYWc0N1yzLov5exxM2Aabat4iGx9D0HKyGCYoZodfeUKTv24kMaoug0BLwOjKSmdx8RVGl6o6sk4A0WckCycZDwTBoYcsaBNcHOTE4LEe3xbHYRA9jR2kaM8hQma/OtDG4QZCAiEMuuroXaDQXjgg8UkaKjE6/2LeUXt33Qh/Xof9FMBrwlne14vYMIrSvGLuQNIOZMb6kL5zhprbCiEHiYS1VcxgMT4Zm9S0o7La/ThTBgKWA4dt44jgPqu+RG+AA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=meQWsa6pqi4gRe3614XH1tchOUd5jCH9YSDFm265TZ8=; b=v4Uw/If6qgPU9bHnFCpEaiZ1iKt7tVmRIdI/o5qIBL6Pr+519QnULMi66I4qpOUbhNHeVoQAlF2+66v22lMp4kXNA5FjbFyvExGE78ZbfiIiNBx/wYkS98TNVPY5Q2Pi0kMXFWXI1pU0ZeA8I/UQ/EjuJ9GCOiGAB18Z6r23uPYPl2GilTcdCucchtlBfaAmBysSbOftcVeyDrab2rxDj7Gcj70xPV9IXBP5lDq1ZJ+dCBymUjcrmoex/ToDQ/Pida/R/8h8Ttc6pkZfWWJuA7etmNy5lFp0f7Mqzl8qIkLfaz+uxER/pU2WxErqEy4RueFlUmDJB8+ygS95NBQHOQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=meQWsa6pqi4gRe3614XH1tchOUd5jCH9YSDFm265TZ8=; b=HOBiU7q4/Y3zCk2/ovxnoTMYjgOu+kR+/nEHNdvKKI2ma4lZSyu5/luqN8AxNVIO1t04/x1c9NLuc6Bv12X0T1UDBCDi/ofTaua8Yb1bt+sl0rANnJARRiKtU4oFiAIoJ9pHDgrBBhfNPFM4V+P2QbIJHrVMpw9frMRL7d/R4Gc= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by IA0PR10MB6820.namprd10.prod.outlook.com (2603:10b6:208:437::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.10; Fri, 27 Sep 2024 12:51:32 +0000 Received: from SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e]) by SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e%5]) with mapi id 15.20.8026.009; Fri, 27 Sep 2024 12:51:32 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: Suren Baghdasaryan , "Liam R . Howlett" , Matthew Wilcox , Vlastimil Babka , "Paul E . McKenney" , Jann Horn , David Hildenbrand , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song , Richard Henderson , Ivan Kokshaysky , Matt Turner , Thomas Bogendoerfer , "James E . J . Bottomley" , Helge Deller , Chris Zankel , Max Filippov , Arnd Bergmann , linux-alpha@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linux-arch@vger.kernel.org, Shuah Khan , Christian Brauner , linux-kselftest@vger.kernel.org, Sidhartha Kumar Subject: [RFC PATCH 2/4] mm: add PTE_MARKER_GUARD PTE marker Date: Fri, 27 Sep 2024 13:51:12 +0100 Message-ID: <03570f8a0ad2a9c0a92cc0c594e375c4185eccdc.1727440966.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: References: X-ClientProxiedBy: LO2P123CA0015.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:a6::27) To SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR10MB5613:EE_|IA0PR10MB6820:EE_ X-MS-Office365-Filtering-Correlation-Id: 693c504e-27f9-41b0-c70f-08dcdef31cb2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: 7nNrvUvMBna91H8v+DQSvY4z6loP4LzHg4gg76Jahk/HokFHpk1KGMwZruv/GvIZ8dDdB0SmZ1JwIXUq98R1ed6Q/MLn0zMRBCu7aZCSevKUDapgjE62wdtbATCzxiMh30+L7VmUjgLuT9fYSbpXkYmgBNJt33dzE0fFMpsMm3/26MLQLHMiyTgHLmfFoRniQJYIJYOsYCMXCA60flRsmJJ2CTV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XqvWOGSknlIl77Q2xOs5gDsdqG1NfSQVKtQKMMkAxbA0AeCtOwM0H/MUuQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SJ0PR10MB5613.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(7416014)(376014)(1800799024)(366016); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: fi0xQ/qb2XAH2fFLsVxurm4LxH5F6mXjXMCteANE+cExBOrfEijS3SxerrZ/MGltRLGSej4tksKFdfQJBp+3hs52fgex54t9b2mnQMxNThdIZIVqqMUrIaKl41TRYy8gA20bHfLj+KePe1GCmZG6w5P+oB2uBl3hljxUi3eq6b+39Sx9moCBnvsIDx9wjNFHWgPUTVCuJWkJmzDh0OHtuAfPoqiFHOWJRsMilx1dpQ6iC4jGIZxXyMo7wW48WsUIHb1POBIT/bUdA1XOhokRVjgeR+y3fIu9cAtPH9vmfaODpMGnX1CSgHUieZYpcMxQDkgb59JEgChLOCGbCbDcZIsfvH4b5MYI+4NuqmN4ohRGkGHHdFABC3BosfrwvZhsp2086L+bw50s4Yc4IJRJETSVTm6LrkYI8v3KNMGS7zDyqJ+q4kgEWSK0dkhtrHiRmC/ACRm6ZNnrKoCBvKmhhYK/0tjUpYCsqhguXfEeC9Ul5/AxONTH3R06pI4blpJZpoLfJ2C7UZgqM+g9ZqHNESoeF5V2U7/f2oXeujAjOdq9RFHRgklbYGzGldiyfC/ctOfNhmRL4n55jONrBtqUlYEruBLdYpXlX3NL4iH0JwQMbs03ux9du2n8/pXJNuzV1owx9kcMgLpZwYiTMRVHl/CrvnRiKVNwE6jJY35r9lT8+t31N5g5XcAqqtlDAXo8cmXxWxYAcXEb5knHKc0dttnSjTPIzuQKl0+dSnR0liOf50JRd5DNf+udMCgcrPzUY1AOwXCDJr9IYTlz17zqkrEV9YIeWDT/H0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2QPLexsGn2DfSnLpRr6SZWqewqbxfnafIeUFKvkjiaPP07uXobo2eweZAhia0RPzO/GXraLiR5x0oi7eY1/k6J3XIFjhSuOTwEnsC8j7IkhObI989svzKgY/Prsi4L7xhKq3eoy7Y9RZQIwZ+TZW6jk8obGcHRh6gTwbCIHSJOQMRBecABz9HcM/xa75Duy9EOzXUmpUdnc4R6VETN6hxn/4Cv+rZ7CyXvfCLlqK41PyQj3/FnyQ5x5gO7DOVRdjB8KcpyPsPY2YN9nt9NxWZHxECpHLBLj+6smz0SdTcB7dfRg53ISzvxrqCszsmon2Uh7TvhZbEHdpahYIiSHL2+TITydWYmjnn5GZ82X7VedTm90zSWNBGsvo/ka07cSv9lw+x+qf0jwe9jpnJCWgu6bv0J0RIvr0SDbs70REEB/fEUQg= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 693c504e-27f9-41b0-c70f-08dcdef31cb2 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Sep 2024 12:51:32.0535 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: eng9sAdM/DpV++rLe9HKZxmQ4cZKgEX62aZsn3Gu7yFre3XrckD6CR1uYthKT7DUV91Ybkt3i8oQNEkdfIkNEUeP6DDAaU/P7Lsw4OSrmQw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR10MB6820 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-27_06,2024-09-27_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 spamscore=0 bulkscore=0 suspectscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2408220000 definitions=main-2409270092 X-Proofpoint-ORIG-GUID: PF5f5kub0HJcgp19TOds1_mVvYzdTsrX X-Proofpoint-GUID: PF5f5kub0HJcgp19TOds1_mVvYzdTsrX Add a new PTE marker that results in any access causing the accessing process to segfault. This is preferable to PTE_MARKER_POISONED, which results in the same handling as hardware poisoned memory, and is thus undesirable for cases where we simply wish to 'soft' poison a range. This is in preparation for implementing the ability to specify guard pages at the page table level, i.e. ranges that, when accessed, should cause process termination. Additionally, rename zap_drop_file_uffd_wp() to zap_drop_markers() - the function checks the ZAP_FLAG_DROP_MARKER flag so naming it for this single purpose was simply incorrect. We then reuse the same logic to determine whether a zap should clear a guard entry - this should only be performed on teardown and never on MADV_DONTNEED or the like. Signed-off-by: Lorenzo Stoakes --- include/linux/mm_inline.h | 2 +- include/linux/swapops.h | 26 ++++++++++++++++++++++++-- mm/hugetlb.c | 3 +++ mm/memory.c | 18 +++++++++++++++--- 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h index 6f801c7b36e2..0d97a14bf051 100644 --- a/include/linux/mm_inline.h +++ b/include/linux/mm_inline.h @@ -531,7 +531,7 @@ static inline pte_marker copy_pte_marker( { pte_marker srcm = pte_marker_get(entry); /* Always copy error entries. */ - pte_marker dstm = srcm & PTE_MARKER_POISONED; + pte_marker dstm = srcm & (PTE_MARKER_POISONED | PTE_MARKER_GUARD); /* Only copy PTE markers if UFFD register matches. */ if ((srcm & PTE_MARKER_UFFD_WP) && userfaultfd_wp(dst_vma)) diff --git a/include/linux/swapops.h b/include/linux/swapops.h index cb468e418ea1..4d0606df0791 100644 --- a/include/linux/swapops.h +++ b/include/linux/swapops.h @@ -426,9 +426,15 @@ typedef unsigned long pte_marker; * "Poisoned" here is meant in the very general sense of "future accesses are * invalid", instead of referring very specifically to hardware memory errors. * This marker is meant to represent any of various different causes of this. + * + * Note that, when encountered by the faulting logic, PTEs with this marker will + * result in VM_FAULT_HWPOISON and thus regardless trigger hardware memory error + * logic. */ #define PTE_MARKER_POISONED BIT(1) -#define PTE_MARKER_MASK (BIT(2) - 1) +/* Indicates that, on fault, this PTE will case a SIGSEGV signal to be sent. */ +#define PTE_MARKER_GUARD BIT(2) +#define PTE_MARKER_MASK (BIT(3) - 1) static inline swp_entry_t make_pte_marker_entry(pte_marker marker) { @@ -461,9 +467,25 @@ static inline swp_entry_t make_poisoned_swp_entry(void) } static inline int is_poisoned_swp_entry(swp_entry_t entry) +{ + /* + * We treat guard pages as poisoned too as these have the same semantics + * as poisoned ranges, only with different fault handling. + */ + return is_pte_marker_entry(entry) && + (pte_marker_get(entry) & + (PTE_MARKER_POISONED | PTE_MARKER_GUARD)); +} + +static inline swp_entry_t make_guard_swp_entry(void) +{ + return make_pte_marker_entry(PTE_MARKER_GUARD); +} + +static inline int is_guard_swp_entry(swp_entry_t entry) { return is_pte_marker_entry(entry) && - (pte_marker_get(entry) & PTE_MARKER_POISONED); + (pte_marker_get(entry) & PTE_MARKER_GUARD); } /* diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 190fa05635f4..daf69ac46360 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6348,6 +6348,9 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, ret = VM_FAULT_HWPOISON_LARGE | VM_FAULT_SET_HINDEX(hstate_index(h)); goto out_mutex; + } else if (marker & PTE_MARKER_GUARD) { + ret = VM_FAULT_SIGSEGV; + goto out_mutex; } } diff --git a/mm/memory.c b/mm/memory.c index 5c6486e33e63..6c413c3d72fd 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1457,7 +1457,7 @@ static inline bool should_zap_folio(struct zap_details *details, return !folio_test_anon(folio); } -static inline bool zap_drop_file_uffd_wp(struct zap_details *details) +static inline bool zap_drop_markers(struct zap_details *details) { if (!details) return false; @@ -1478,7 +1478,7 @@ zap_install_uffd_wp_if_needed(struct vm_area_struct *vma, if (vma_is_anonymous(vma)) return; - if (zap_drop_file_uffd_wp(details)) + if (zap_drop_markers(details)) return; for (;;) { @@ -1673,7 +1673,15 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, * drop the marker if explicitly requested. */ if (!vma_is_anonymous(vma) && - !zap_drop_file_uffd_wp(details)) + !zap_drop_markers(details)) + continue; + } else if (is_guard_swp_entry(entry)) { + /* + * Ordinary zapping should not remove guard PTE + * markers. Only do so if we should remove PTE markers + * in general. + */ + if (!zap_drop_markers(details)) continue; } else if (is_hwpoison_entry(entry) || is_poisoned_swp_entry(entry)) { @@ -4005,6 +4013,10 @@ static vm_fault_t handle_pte_marker(struct vm_fault *vmf) if (marker & PTE_MARKER_POISONED) return VM_FAULT_HWPOISON; + /* Hitting a guard page is always a fatal condition. */ + if (marker & PTE_MARKER_GUARD) + return VM_FAULT_SIGSEGV; + if (pte_marker_entry_uffd_wp(entry)) return pte_marker_handle_uffd_wp(vmf);