From patchwork Mon Feb 10 19:37:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13968580 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 E2C1BC021A2 for ; Mon, 10 Feb 2025 19:38:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 27AE96B0083; Mon, 10 Feb 2025 14:38:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 22AFE6B0085; Mon, 10 Feb 2025 14:38:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0CC0A6B0089; Mon, 10 Feb 2025 14:38:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id E15616B0083 for ; Mon, 10 Feb 2025 14:38:11 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 8FEBD1C754C for ; Mon, 10 Feb 2025 19:38:11 +0000 (UTC) X-FDA: 83105045982.27.DE420A6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf29.hostedemail.com (Postfix) with ESMTP id 5AD51120002 for ; Mon, 10 Feb 2025 19:38:09 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UtP5y4Yr; spf=pass (imf29.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1739216289; 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: references:dkim-signature; bh=MCWz0QKB/3zA+wyPgSQYXWNTlsWbH4Vu3NwNK9eMowA=; b=w3O+2y89MFG7bgVVBnCLYMSE5pMToC7hu4EiFI1agBMAYUba8BKMyaae2+4aWqFwqN1ajc ee9Q81QGA6VzMLzVO8oyMR0N8QjMPGx06oMveqOyPv4hjcHUXm6l0bul5Xvepv9bx8IpfV 5IPDvkUV9IxMP5sux585/vOMuvxxEqg= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UtP5y4Yr; spf=pass (imf29.hostedemail.com: domain of dhildenb@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhildenb@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1739216289; a=rsa-sha256; cv=none; b=HnFAxLe2WKy3es7cmdq2qRc6CO2cMIK6O8PbnPcs9MHzB82lqlWVeZqAQPeiZoqsMijppc XTs7XnK443zKtVk3UberXTSs/iDNzYXo1Bqtn5MqGcG0Dnj4JP8WVjPwr5HDBQ3LX/4fkT Txz42TTcY2Xi0AARTx9uwfikPNcz1nM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1739216288; h=from:from: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; bh=MCWz0QKB/3zA+wyPgSQYXWNTlsWbH4Vu3NwNK9eMowA=; b=UtP5y4YrC1pXYufZxEZPPslSmSH/8v3Y3WvMrBxzNAnVt2I3Hx7OSsHo5YcuyHvM0L0BAc zoOuc88gNEXhYq1M6XFVuli56bK2U47AaNNOsU/umrrbjMWvatKnnuKF0wQyiH2MO8iCqH KIIHoh5XO5x/UNcjue3xUM8hVK+DfJs= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-195-zyjasvCbORyNr2VZUSN7Sw-1; Mon, 10 Feb 2025 14:38:07 -0500 X-MC-Unique: zyjasvCbORyNr2VZUSN7Sw-1 X-Mimecast-MFC-AGG-ID: zyjasvCbORyNr2VZUSN7Sw Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-43933b8d9b1so12558955e9.3 for ; Mon, 10 Feb 2025 11:38:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739216286; x=1739821086; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=MCWz0QKB/3zA+wyPgSQYXWNTlsWbH4Vu3NwNK9eMowA=; b=YyhFEqrqX24TMuEVpcyn1lb58/0L/RpyMb+DTt2PmKggnDvpBK1e4UIMQwzznLPklf vbmGZiAZpywUUKNN9z4lf29mvhkL9M1xHzhyA8h7mg3L2bF7ElEo5AQo8558a55ZcELy OeMTmzfOaPKbk2DubiOwYRODdwhG0pLQQK/Qsi5OG2COXJ5qRgqfaXMtE3WxV9qzok6L um/XFSM0Bw/HYNfLKaBSiEVXpzIc2aX4PcGGODJur9mYMm1aLdfLOu9CfKuF5l/ecb6F p07JnIyHAIxu4LldBk1udLKvW2rvC/npV7Sd5afT3hQ5L5erpznf33TD4HuEVITl5In3 3q3w== X-Forwarded-Encrypted: i=1; AJvYcCV/uubECzOIEK9Q17BG/4yn/lTE5q8P/lNeanT7aHmKIsa/E2FjzUl5G/EzUD3L3w0U3pHS2+Lopw==@kvack.org X-Gm-Message-State: AOJu0YyOniBXDSnQcffOoWFVq//udDZBPD5Itn/ZU2eVNHbLUI3L3yQy jviHuJUHWIZz7IbgLN0PImo0grRfVU/SEJTp0lrvRVydrKX1Cwy0aP/rmFb1n2wr4TKFpY4nZmr p6V4hEMKkatQNGDQDebmN09kiOeaw7Vyjb4zwZ5O1rAPp9a5s X-Gm-Gg: ASbGncsiPNdmuCHJz6g730ynhZwcOKXRia4z7zvUV9jfQcnAPetClirpcOLG2EO43YH j4zOC/+JV0Y0eWhWN7AjChjBHHUca4ytKGDPydMcvyFQ9x/OtD5T/DbZkJuxF6jbLVyIdwelxmT W96dQmHvQUJdp0nh2I7Fic7+8kN5h0HmktcYFQnADyqb4QYGKN9+bAEYx6EP5VEKxkJfmMtlyC3 DCE3ear6ZNFcubNf1+G4lJRKRpC6oPiEB+ExKc9G8S6DiIOFLZ/DHNvG0ejU8OHr/LhXM5OWPDl wD23M57Tz+6tgoWuk5cbLx9xl0xnIbWZESsBmxQmS92p13Vuc/a/AJ2U3KB2UaiWiw== X-Received: by 2002:a05:600c:1e0e:b0:431:5e3c:2ff0 with SMTP id 5b1f17b1804b1-439249889a8mr117184905e9.8.1739216286107; Mon, 10 Feb 2025 11:38:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IEHEaOpDMG7a/03CRbYKSofR+ckzDf4tR3vs9lDmaTs2zKGFHodBnTigVeQlsjTuu7+8Xv9cw== X-Received: by 2002:a05:600c:1e0e:b0:431:5e3c:2ff0 with SMTP id 5b1f17b1804b1-439249889a8mr117184625e9.8.1739216285660; Mon, 10 Feb 2025 11:38:05 -0800 (PST) Received: from localhost (p200300cbc734b80012c465cd348aaee6.dip0.t-ipconnect.de. [2003:cb:c734:b800:12c4:65cd:348a:aee6]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-4390d94db77sm189019515e9.15.2025.02.10.11.38.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 10 Feb 2025 11:38:04 -0800 (PST) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-doc@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-mm@kvack.org, nouveau@lists.freedesktop.org, linux-trace-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, damon@lists.linux.dev, David Hildenbrand , Andrew Morton , =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , Jonathan Corbet , Alex Shi , Yanteng Si , Karol Herbst , Lyude Paul , Danilo Krummrich , David Airlie , Simona Vetter , Masami Hiramatsu , Oleg Nesterov , Peter Zijlstra , SeongJae Park , "Liam R. Howlett" , Lorenzo Stoakes , Vlastimil Babka , Jann Horn , Pasha Tatashin , Peter Xu , Alistair Popple , Jason Gunthorpe Subject: [PATCH v2 00/17] mm: fixes for device-exclusive entries (hmm) Date: Mon, 10 Feb 2025 20:37:42 +0100 Message-ID: <20250210193801.781278-1-david@redhat.com> X-Mailer: git-send-email 2.48.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 6wXoTkyzvlYbLLp7N4fyzifW5FMTQmKGIDfRK1P-XQw_1739216286 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 5AD51120002 X-Stat-Signature: aie79hhzmhow8oq94mkm7kacwnr8o5yq X-Rspam-User: X-HE-Tag: 1739216289-260520 X-HE-Meta: U2FsdGVkX195ke6xWmnFtQWksM4+jjmQtXUjZVYHNdyIx7h63mAy361x+0ZRYQKM7woejJf4VLEh84lPRaBNeOu1ROwGpeGH+xH/rdwykLdSdjQAz1xIc+XT5fBzdYlFGFw2c2mL3l+jZAVlUp8ezaqpobfBoy5XYg8DDRYaOOttPHQTd+OrwoDoSETI+g5xEn3Yb/iyqNiDRGh5CwyHPEfANO4+O/9U9U/e5/TaiG2QSU0D/iLENhtsS9yEAKRLchM+WPcl5GkrF3s3PRJp2KBowE1+KmmdHlHujO8YVTwblInS3CCYh5T4e284v/kDNSAYezmUyV65ZeQy7OawPJxz5kQjIEC38ux57g/UDKquk6B3i/zXtiXTp5c8W736KKvzU6b6v5mRTEI3imoa4WVaRPb6gk9Bj1RaRDnKktJJqQbTQnVmExM2k6JgJmoW0zC/WYB48O3+dR5iHMJcu6bnYkA4rfqgZQg7SfQ6VMggLRTqKhk4vChzTXceUwf0AXDGVvXvlC2CF5yzm320C+GyBFqb2EmmzdHOpQuCrNhdXVdMv2CQ234PdCJZ2t01Jkr9KWRxGQu7kTWO2Sr9a67Ib7k/B+1FicwnAr6ffoBy9zt+0R3xQWLS0K0PZ9oJ/8Mc7ogI/b3VP367HRnFC+Osip4pt/jTPtxe0Ifj5xBZrsEZWqQLCgEONxKZ7vMe/2sc5BEK0IoIooLoUK0owlStMkbYjJGnsxWAiiIs1O3JXhfEywzAwZ5PMjqLCG+Ibp4oIQqKVoBeFcR5WhfIyYrJQkC27XkBxwY2TWTLS4bPp6ea0BILTlc6Nzauv2mcRgRpx7kKw3fXysUj0RkXTdj8xhGsdMlh0VXtZVNKMRYEYvQ1nlEfs3dl28q9E3L7AhKELxPAeGoqrB4QNPWEdVWXvsEtszjr5ywR8b8v6yszOOj+4A3YuGlXtYpPcPt9EdVN5WqFIKDCyWLVL5S ntOCkeP7 3mfrH7QU2XDoKVcvmcp9IlmqgkgiJeqmKs7bVqf0fdOGmwarjBOj3z5lbH74PxZQ6/+zwM477VY4abfEJWPWPRboYZUPI6a+stIKqgP3RexvbArDwlHPCw7FH1/Zw7/veh+zkj2juepvkj6Nb2D30S21hnJSwMgkcQCFbQ2H0Y8HT3l7N/fX3Tk9dM/NdbHoQzdd1sBWRFeaFHjHaY2CybDf6vLK+4RnBKAsa9DoohoR7qSgpjuG7Y42/AF5oRR37NoGbPc9aR4JV7yyiJ8AXLPVheMuBJFxQIdGPsQzLRa3rzQIpkpSlSNGavkL6iyEzz6oUba1C7Pr0Lj/BoTlklVLpxJpzQuEDTFQg9M4CPyygfNI6mO7bpTMPVar3wHSHCeSOPvVvRfYSj/+dtcn5XE3b2zh2EolzXr3o3BBGFxMHF6QCbMVy00eHrDXXaNVIn5u42pw0qNrxSOaij6TWnMm95gH26+ZxJZJISrG37FMs2LZZmTt7HXqfzjNEIyysTa7BvAEZOAXn4+cRQKqoPRFKjJwk9Pocipy1tIEWUtLT60LVwfrFS9ta/g6qUWCNPqHvPue7SRwvV5JqPm43CKM3T9M9crf0NroVkGXbsZvL13RqIbH8fnRYJJ1H/bsapx+r9YVqIWE49t201srUO4DMpVVMyqlqnJZ6ZqTaAwuIZf5irjkDZkcjD6GNu3M1C+3VS0rdgH1n65w469+27e0NUhCpd/isIgnRy3WJe3SMizlyetyGl7UEELhwE/Nm1QBIuyjloBgm5/RKTTAH/fjhcPvG0MRaz1Tb0loqfaXt6971HfxbobLjPNVC0nQ8/ZjXFezBFaN5fp3n55nXxr1SBxk9wHFIIr30WclyX+NI+ZM= 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: List-Subscribe: List-Unsubscribe: Against mm-hotfixes-stable for now. Discussing the PageTail() call in make_device_exclusive_range() with Willy, I recently discovered [1] that device-exclusive handling does not properly work with THP, making the hmm-tests selftests fail if THPs are enabled on the system. Looking into more details, I found that hugetlb is not properly fenced, and I realized that something that was bugging me for longer -- how device-exclusive entries interact with mapcounts -- completely breaks migration/swapout/split/hwpoison handling of these folios while they have device-exclusive PTEs. The program below can be used to allocate 1 GiB worth of pages and making them device-exclusive on a kernel with CONFIG_TEST_HMM. Once they are device-exclusive, these folios cannot get swapped out (proc$pid/smaps_rollup will always indicate 1 GiB RSS no matter how much one forces memory reclaim), and when having a memory block onlined to ZONE_MOVABLE, trying to offline it will loop forever and complain about failed migration of a page that should be movable. # echo offline > /sys/devices/system/memory/memory136/state # echo online_movable > /sys/devices/system/memory/memory136/state # ./hmm-swap & ... wait until everything is device-exclusive # echo offline > /sys/devices/system/memory/memory136/state [ 285.193431][T14882] page: refcount:2 mapcount:0 mapping:0000000000000000 index:0x7f20671f7 pfn:0x442b6a [ 285.196618][T14882] memcg:ffff888179298000 [ 285.198085][T14882] anon flags: 0x5fff0000002091c(referenced|uptodate| dirty|active|owner_2|swapbacked|node=1|zone=3|lastcpupid=0x7ff) [ 285.201734][T14882] raw: ... [ 285.204464][T14882] raw: ... [ 285.207196][T14882] page dumped because: migration failure [ 285.209072][T14882] page_owner tracks the page as allocated [ 285.210915][T14882] page last allocated via order 0, migratetype Movable, gfp_mask 0x140dca(GFP_HIGHUSER_MOVABLE|__GFP_COMP|__GFP_ZERO), id 14926, tgid 14926 (hmm-swap), ts 254506295376, free_ts 227402023774 [ 285.216765][T14882] post_alloc_hook+0x197/0x1b0 [ 285.218874][T14882] get_page_from_freelist+0x76e/0x3280 [ 285.220864][T14882] __alloc_frozen_pages_noprof+0x38e/0x2740 [ 285.223302][T14882] alloc_pages_mpol+0x1fc/0x540 [ 285.225130][T14882] folio_alloc_mpol_noprof+0x36/0x340 [ 285.227222][T14882] vma_alloc_folio_noprof+0xee/0x1a0 [ 285.229074][T14882] __handle_mm_fault+0x2b38/0x56a0 [ 285.230822][T14882] handle_mm_fault+0x368/0x9f0 ... This series fixes all issues I found so far. There is no easy way to fix without a bigger rework/cleanup. I have a bunch of cleanups on top (some previous sent, some the result of the discussion in v1) that I will send out separately once this landed and I get to it. I wish we could just use some special present PROT_NONE PTEs instead of these (non-present, non-none) fake-swap entries; but that just results in the same problem we keep having (lack of spare PTE bits), and staring at other similar fake-swap entries, that ship has sailed. With this series, make_device_exclusive() doesn't actually belong into mm/rmap.c anymore, but I'll leave moving that for another day. I only tested this series with the hmm-tests selftests due to lack of HW, so I'd appreciate some testing, especially if the interaction between two GPUs wanting a device-exclusive entry works as expected. #include #include #include #include #include #include #include #include #include #include #define HMM_DMIRROR_EXCLUSIVE _IOWR('H', 0x05, struct hmm_dmirror_cmd) struct hmm_dmirror_cmd { __u64 addr; __u64 ptr; __u64 npages; __u64 cpages; __u64 faults; }; const size_t size = 1 * 1024 * 1024 * 1024ul; const size_t chunk_size = 2 * 1024 * 1024ul; int main(void) { struct hmm_dmirror_cmd cmd; size_t cur_size; int fd, ret; char *addr, *mirror; fd = open("/dev/hmm_dmirror1", O_RDWR, 0); if (fd < 0) { perror("open failed\n"); exit(1); } addr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (addr == MAP_FAILED) { perror("mmap failed\n"); exit(1); } madvise(addr, size, MADV_NOHUGEPAGE); memset(addr, 1, size); mirror = malloc(chunk_size); for (cur_size = 0; cur_size < size; cur_size += chunk_size) { cmd.addr = (uintptr_t)addr + cur_size; cmd.ptr = (uintptr_t)mirror; cmd.npages = chunk_size / getpagesize(); ret = ioctl(fd, HMM_DMIRROR_EXCLUSIVE, &cmd); if (ret) { perror("ioctl failed\n"); exit(1); } } pause(); return 0; } [1] https://lkml.kernel.org/r/25e02685-4f1d-47fa-be5b-01ff85bb0ce2@redhat.com Cc: Andrew Morton Cc: "Jérôme Glisse" Cc: Jonathan Corbet Cc: Alex Shi Cc: Yanteng Si Cc: Karol Herbst Cc: Lyude Paul Cc: Danilo Krummrich Cc: David Airlie Cc: Simona Vetter Cc: Masami Hiramatsu Cc: Oleg Nesterov Cc: Peter Zijlstra Cc: SeongJae Park Cc: "Liam R. Howlett" Cc: Lorenzo Stoakes Cc: Vlastimil Babka Cc: Jann Horn Cc: Pasha Tatashin Cc: Peter Xu Cc: Alistair Popple Cc: Jason Gunthorpe v1 -> v2: * "mm/rmap: convert make_device_exclusive_range() to make_device_exclusive()" -> Fix and simplify return value handling when calling dmirror_atomic_map() -> Fix parameter order when calling make_device_exclusive() [both things were fixed by the separate cleanups I previously sent, realized it when re-testing the fixes here only] -> Heavily extend documentation of make_device_exclusive() * "mm/rmap: implement make_device_exclusive() using folio_walk instead of rmap walk" -> Keep MMU_NOTIFY_EXCLUSIVE, and update comments/description * "mm/rmap: handle device-exclusive entries correctly in try_to_migrate_one()" -> Handle PageHWPoison with device-private pages differently * Added a bunch of "handle device-exclusive entries correctly" fixes, now handling all page_vma_mapped_walk() callers correctly * Added "mm/rmap: avoid -EBUSY from make_device_exclusive()" to fix some hmm selftest failures I saw while testing under memory pressure * Plenty of comment/description updates and improvements David Hildenbrand (17): mm/gup: reject FOLL_SPLIT_PMD with hugetlb VMAs mm/rmap: reject hugetlb folios in folio_make_device_exclusive() mm/rmap: convert make_device_exclusive_range() to make_device_exclusive() mm/rmap: implement make_device_exclusive() using folio_walk instead of rmap walk mm/memory: detect writability in restore_exclusive_pte() through can_change_pte_writable() mm: use single SWP_DEVICE_EXCLUSIVE entry type mm/page_vma_mapped: device-exclusive entries are not migration entries kernel/events/uprobes: handle device-exclusive entries correctly in __replace_page() mm/ksm: handle device-exclusive entries correctly in write_protect_page() mm/rmap: handle device-exclusive entries correctly in try_to_unmap_one() mm/rmap: handle device-exclusive entries correctly in try_to_migrate_one() mm/rmap: handle device-exclusive entries correctly in page_vma_mkclean_one() mm/page_idle: handle device-exclusive entries correctly in page_idle_clear_pte_refs_one() mm/damon: handle device-exclusive entries correctly in damon_folio_young_one() mm/damon: handle device-exclusive entries correctly in damon_folio_mkold_one() mm/rmap: keep mapcount untouched for device-exclusive entries mm/rmap: avoid -EBUSY from make_device_exclusive() Documentation/mm/hmm.rst | 2 +- Documentation/translations/zh_CN/mm/hmm.rst | 2 +- drivers/gpu/drm/nouveau/nouveau_svm.c | 5 +- include/linux/mmu_notifier.h | 2 +- include/linux/rmap.h | 5 +- include/linux/swap.h | 7 +- include/linux/swapops.h | 27 +- kernel/events/uprobes.c | 13 +- lib/test_hmm.c | 41 +- mm/damon/ops-common.c | 23 +- mm/damon/paddr.c | 10 +- mm/gup.c | 3 + mm/ksm.c | 9 +- mm/memory.c | 28 +- mm/mprotect.c | 8 - mm/page_idle.c | 9 +- mm/page_table_check.c | 5 +- mm/page_vma_mapped.c | 3 +- mm/rmap.c | 469 +++++++++----------- 19 files changed, 315 insertions(+), 356 deletions(-) base-commit: e5b2a356dc8a88708d97bd47cca3b8f7ed7af6cb Tested-by: Alistair Popple