From patchwork Tue May 16 02:35:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Collingbourne X-Patchwork-Id: 13242482 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 6A5BAC7EE23 for ; Tue, 16 May 2023 02:35:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 045BF900004; Mon, 15 May 2023 22:35:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F376E900002; Mon, 15 May 2023 22:35:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DB092900004; Mon, 15 May 2023 22:35:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id C8A36900002 for ; Mon, 15 May 2023 22:35:25 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A0889AF463 for ; Tue, 16 May 2023 02:35:25 +0000 (UTC) X-FDA: 80794551810.23.B38F1CA Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf15.hostedemail.com (Postfix) with ESMTP id CEB46A000A for ; Tue, 16 May 2023 02:35:23 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=5CElQQQJ; spf=pass (imf15.hostedemail.com: domain of 36utiZAMKCHckXXbjjbgZ.Xjhgdips-hhfqVXf.jmb@flex--pcc.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=36utiZAMKCHckXXbjjbgZ.Xjhgdips-hhfqVXf.jmb@flex--pcc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684204523; 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=BNa4l1F+5QMrqUAe4k1x2vD+9zG0bZzdq9LlZrfkoEE=; b=oxKGbhr/w6RwUdlJIaBIJVgaV1VWCFYs1VHbWGrhtbgV7se7K7/MZ3VBcp6L28tG7xMQK8 eMwwjbCyPB4xMns5ZqZR1mQ10J1IvJFFuhseI+8wTFzKcRx5eXIBgFth82JhpRSJW1DUPG oyD4V16urrIZ47MBXi3wrH+ttTlSa7g= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684204523; a=rsa-sha256; cv=none; b=04YIcCaRHKjr5+IWpM7WD4yECw+S8Aal+G0TqCE7GUTPuANE2uPj0vl1CNITRacJgYt73D cDoyT8CYmA56ZDewOcPxt77xCVuledaI14oZ0TLlq/PAN87TQYGbdkjBybKqvqtrkAB30j uX5TRkPyojLL95UZvWvPkYj9oc629Mw= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=5CElQQQJ; spf=pass (imf15.hostedemail.com: domain of 36utiZAMKCHckXXbjjbgZ.Xjhgdips-hhfqVXf.jmb@flex--pcc.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=36utiZAMKCHckXXbjjbgZ.Xjhgdips-hhfqVXf.jmb@flex--pcc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-b9a829a3de0so30149987276.2 for ; Mon, 15 May 2023 19:35:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684204523; x=1686796523; h=content-transfer-encoding:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:from:to:cc:subject:date :message-id:reply-to; bh=BNa4l1F+5QMrqUAe4k1x2vD+9zG0bZzdq9LlZrfkoEE=; b=5CElQQQJT/aTXqmIkBL5nk8ZqROWxHVeiTpJhgNNP6gAWJxiEdiM9NRKcz3h9LcW3E 6iQOSor97QYs0lfZ6derwYy+EoBPTPG0wrSAhW6MB+C8I2ulfFpVq0xWstKnv/gCOSI3 sTayVf/EDsxUwV0fRpbyEQMKAl72VTxZxebOOXGkY9Zo/GRaXgJzrZb8R3DJyyI3TILH gbJgCWXVuSYD5aavaLo40em5VxUV5CUuQmcRhtfE7LKpENGuSe0F4bGretjtH/Hk+Er8 ZzXcJDrPpAVybe+zFrgxXOsiLxl2HMfrPhFvpy1NLp3M2k09zHnGgLcbjVvYkYgEHIGy lFdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684204523; x=1686796523; h=content-transfer-encoding:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=BNa4l1F+5QMrqUAe4k1x2vD+9zG0bZzdq9LlZrfkoEE=; b=GW3YeczBamcZiL9Qf/ElgpDN4gq6Zq6zdynEIgHeXeE7VTq6qWFNqOsQRvaZQIrJ7Q gmhvl42mtFe650jM0gLiodfe9WxEeXSz3EtGWXoDWqmtt3W0F4sTlr84ska8H4hKQnNb JflaBJ19d2id6eiEzVCv4lGBcvmlH0KQ4k2q+c+zGtHOeFw+lSuZE6ItrAJFg28b476T nfKCyqu+joIcqC9H3CUGmVhoia6CRNbHkowo9mU/OOeq8E+7zG657CfrAh41IpE6fQpK fQ28mtaavMlgFTfba2RpKlGWkcifkg+zT1ZB4sLwczSiDIeSt/6EZA4U5c8u7p6fJDXj CXEw== X-Gm-Message-State: AC+VfDyFH7knEsWokbmriuuUfXNLZToUrDuvOPSifUzQ2wSDugpDdvTo tCkfqhu8alJ8seqa2O6Laxp1YYI= X-Google-Smtp-Source: ACHHUZ5++OLyfAEF8T2icYgWUbhVixyck2Y9LW7OB4tG8eRNkSZySF8iIX6XNzPK6UHQZ30i8umUU5Y= X-Received: from pcc-desktop.svl.corp.google.com ([2620:15c:2d3:205:c825:9c0b:b4be:8ee4]) (user=pcc job=sendgmr) by 2002:a25:d8cd:0:b0:b9a:703d:e650 with SMTP id p196-20020a25d8cd000000b00b9a703de650mr15802130ybg.7.1684204522988; Mon, 15 May 2023 19:35:22 -0700 (PDT) Date: Mon, 15 May 2023 19:35:12 -0700 In-Reply-To: <20230516023514.2643054-1-pcc@google.com> Message-Id: <20230516023514.2643054-2-pcc@google.com> Mime-Version: 1.0 References: <20230516023514.2643054-1-pcc@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Subject: [PATCH v2 1/2] mm: Call arch_swap_restore() from do_swap_page() From: Peter Collingbourne To: Catalin Marinas Cc: Peter Collingbourne , " =?utf-8?b?UXVuLXdlaSBMaW4gKA==?= =?utf-8?b?5p6X576k5bS0KQ==?= " , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "surenb@google.com" , "david@redhat.com" , " =?utf-8?b?Q2hpbndlbiBDaGFuZyAo?= =?utf-8?b?5by16Yym5paHKQ==?= " , "kasan-dev@googlegroups.com" , " =?utf-8?b?S3Vhbi1ZaW5nIExlZSAo5p2O5Yag56mOKQ==?= " , " =?utf-8?b?Q2FzcGVyIExpICjmnY7kuK3mpq4p?= " , "gregkh@linuxfoundation.org" , vincenzo.frascino@arm.com, Alexandru Elisei , will@kernel.org, eugenis@google.com, Steven Price , stable@vger.kernel.org X-Rspamd-Queue-Id: CEB46A000A X-Stat-Signature: kg4qfhwhcwabne8pby3sxw7wr8i6i1ii X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1684204523-527772 X-HE-Meta: U2FsdGVkX188Zfy/ptwAUgnIco7NrxvqmYPzflNwv7TB1bP1Y08P0oq6+dJC3/hRqzPIe/QgJ6Fuycm+xsh4Kozaw2kZZDjOZ1ZPfC8pJfKC65YBff6Iz4Zx7mpLxaQlzhQMUNaP7rj2geXZDiOA9KYGcS1YxQteytgfBlSGsyiZ6ubIiz5T+1Ptp2bD8RgnHoy1cTpmRsL+6285v1Uc6Jcf44GZF29i+6aTlDWMqdH2mcf8BFNBdwYha1YjNDCvBi9KMHriDsqxFy098ZoLUW2r4VZct9moFfClpu/NaXv7NNDlKFYjwf3AQg64uIm6dRFIcKKqTirlK1d7Yynh2gvxEVm0ng2cMvr7Z7siH9SxqYM7vN7iWkUZwqGtGF/o6jMSSh/LCxEW7JaPcq1z9YCi/1kYhOWwl4Uxv8tlA7yY1LMaJnicT0TemsZYAa/A3kzLPbUzu648qOtTSqH92jzjRWHCNiQpvUgKgKhQMo+PY1o+fR7TetH9RR1nxDlwlWmat/x7J4kad1wVpzwO1niiEwpz5R6dkRfEk3jLyIg8VtdNS8MIwgIvo9AwyHtNSUOoYjBASt/+rbKL1hkFnrPE4+YB9q4PeozvFqEGAGeEP/ps6dCujbbmUEIy1Ql/A1vXomw2bQHzVyTxR2idYNPkitfnIX0Fe+yIPnuu4RasdvU5Od2+NecMAV+IRnS/HIIAn4EGGZaUPQ75GhMQq8RdV6Ny+qY50yUlH09Ghn/A1Nq6A+BKH6vgi1H2jJBZ7muIBCzo60WfsEqtjeUeYaQzC3b8nQLjBSDxB7oMhi/Tn+hgHuBgehBu5OLcWV0B1AzzelskQED1qKE3h5ZPW4GEWvEpJxjGkfcuklIb/tzaeO1FalhWnq86c4PzM2mv3V2BbsgcTIvtkPqsj1m8imWjGCjLL8wvJYjTRIs1LZtBXntRcH5O7zN2DKvaUZ1MO9FhJxgOPWVC8uNF/3Z YHsY2uJN DXVikjF8buLWy0PpRwy4OomfsOAB++i7w8CykzZyGbBBLsAjUW/J0MkQTvRMpAJlqoC0EJhuddf7BixuVe1JA5JUWBInNS0KyWXfNoDucWq+a1ftnRLto5T6Kw8F2p1LXALNQMYi++XCjWuwuF5QpcvlzLdF3pD69+TJWjprUM/ply0PcTzKLssQ8NX1laXTT4LYqqrtZImVmXw/Oh+DNNao+cOF0tHFAkm5Z08nUYBnIAtmXpxDb3yH5JKbriSq182yUjLjISEVnszvxn4XKTQCu1O5KGmrXerOyuVdpiJNAH+XT92IqzTzwuMQxANHgT77L5U+Xsv4jhum5QDe9qMxTCUGweZEEXkH6Mrkxr8GtMb9DEpBkJ0eVZysJMpUfDxcPwflSgTO8DguR7tHr+JVJAYKQLj8Dqf6DhBlYzVqs0h3J4Te5eAUr5+gNYpjU/5PhEPruK6hrkZvfREAqzvo+FVItAaNlHltrqzigi4ImlK2N11R0Wb3wkAYXxU0OSkACPtn0COQcOwtFpSGFIio70PWHeiifGdijoqf1tcORk7TD2ORcTymHeocc+9K3NooaHj9Gc9Wd364PhV+Su5xFaYYkQooq9L/ePLMXuNhafG4HTpDBzdU3po/eOyXikPEZziWIRGnsmHSp6sf6+AxPiSacQtV+6UALlPNGJv6z87w+WnaP8Vols55l9RkvoWoTjN4IqrFpSv+Wi8TyoFvllvYYFwC4GND3aWN1XHfqwIyHY58ba/cRLjJR10QxHdshTFH9OwyPU+SZcjyp4OIdxJBja4h7kQPE6Wh25WhIQt2KDs+09hHptiOzf7XgpkPyNbxWSpD1+Hcmxn2pwWXyOB0wSO1DQJ+D 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 c145e0b47c77 ("mm: streamline COW logic in do_swap_page()") moved the call to swap_free() before the call to set_pte_at(), which meant that the MTE tags could end up being freed before set_pte_at() had a chance to restore them. Fix it by adding a call to the arch_swap_restore() hook before the call to swap_free(). Signed-off-by: Peter Collingbourne Link: https://linux-review.googlesource.com/id/I6470efa669e8bd2f841049b8c61020c510678965 Cc: # 6.1 Fixes: c145e0b47c77 ("mm: streamline COW logic in do_swap_page()") Reported-by: Qun-wei Lin (林群崴) Link: https://lore.kernel.org/all/5050805753ac469e8d727c797c2218a9d780d434.camel@mediatek.com/ --- v2: - Call arch_swap_restore() directly instead of via arch_do_swap_page() mm/memory.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mm/memory.c b/mm/memory.c index 01a23ad48a04..a2d9e6952d31 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3914,6 +3914,13 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) } } + /* + * Some architectures may have to restore extra metadata to the page + * when reading from swap. This metadata may be indexed by swap entry + * so this must be called before swap_free(). + */ + arch_swap_restore(entry, folio); + /* * Remove the swap entry and conditionally try to free up the swapcache. * We're already holding a reference on the page but haven't mapped it From patchwork Tue May 16 02:35:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Collingbourne X-Patchwork-Id: 13242483 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 98915C77B7D for ; Tue, 16 May 2023 02:35:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 303E7900005; Mon, 15 May 2023 22:35:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B542900002; Mon, 15 May 2023 22:35:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 17C01900005; Mon, 15 May 2023 22:35:28 -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 0233A900002 for ; Mon, 15 May 2023 22:35:28 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id C93471A1382 for ; Tue, 16 May 2023 02:35:27 +0000 (UTC) X-FDA: 80794551894.13.631DF19 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf11.hostedemail.com (Postfix) with ESMTP id 1703C40005 for ; Tue, 16 May 2023 02:35:25 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=vKfIPmvX; spf=pass (imf11.hostedemail.com: domain of 37etiZAMKCHonaaemmejc.amkjglsv-kkitYai.mpe@flex--pcc.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=37etiZAMKCHonaaemmejc.amkjglsv-kkitYai.mpe@flex--pcc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684204526; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=PFB1dkpGULUqWzGVGpWTfZD/wGkLnLUL2yYSj9UHJe8=; b=hZNKDZRH/2yotyzeoyXWU05YRLmtsAfL08RZYldxAzgrz7UHQJ65EdsurQpRSGv0fyHtLl 1VhBb2tXfpqJ2vgH/JHiZLs6pHXaYUgJ9vvzO38+sLIqNmJ0v2fgKBuKrxBcSp1xZAL6O7 aBuhkGW34VknkxuBm2pNTPWQ7M37EXc= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=vKfIPmvX; spf=pass (imf11.hostedemail.com: domain of 37etiZAMKCHonaaemmejc.amkjglsv-kkitYai.mpe@flex--pcc.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=37etiZAMKCHonaaemmejc.amkjglsv-kkitYai.mpe@flex--pcc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684204526; a=rsa-sha256; cv=none; b=nqRqjhF7JuFcbOAZTekf/UkQ/129NU/OWiJhjrNxkiWzf6WF+KdmtnkGAd3a4kU/Sd9E6K Ku68up7/HMYCCmNzeGAUP/ml6ob8qk6nU13vpJVF6YWke93k978uTAnZ5k01BtJIoQGBNc 1rK3kxWHRdm/r6Clwg/dTm3T+mZVJmY= Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-ba237aec108so13774116276.3 for ; Mon, 15 May 2023 19:35:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684204525; x=1686796525; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=PFB1dkpGULUqWzGVGpWTfZD/wGkLnLUL2yYSj9UHJe8=; b=vKfIPmvXwnD0w7nKCyGYrqfY1+bvNHFzXFFqCB1zgx7Ey+JHvhLlTX1gixZuKdcpXU tiT5mMmzC+UGiH/Q00Zml7jrN0hEnCMHjQ8uXyM/k+i9GzNcZCf3vs79dfYH0Yamrfd3 Cy1rlI9uSYMq+wvjBv5hMjQokz3Xl2kHys6gOXr3jNSdure6QZBkSzK93IkNCjmZ9U1y 823lY14YjWLv5PCGqNrkuuZ/KPqLnX7mUm8TGj9U47m2Z8fOztmpQXhjmlTH/LDAmpDw jxUWGL7K2en3kCoXjKvsdWJDnfKprcI2/EKvKrie44kXLalA4JR6xQQFh8fAPBGeqBw6 JkWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684204525; x=1686796525; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PFB1dkpGULUqWzGVGpWTfZD/wGkLnLUL2yYSj9UHJe8=; b=UNGVknmlURRIlDoibjsJj30Sufsae/VydGtmVya/MRRKE5hqqj40Hoe5eWVLFCi0NW M6udskwO3cVQZDGAQnich8bsf7UGdE4eW8bECX+64tVzF7NUYhDvwOIgvEvP1oAqDCdu lFGf5l/VRErsQlwCuOzKslRukix9DJM/C8Phf+vGR2sxUuO9mkZBKeb4mA7k6nToXkew 7TEpewTIkF6Ob2IlfnqGP+uV/6RIZJ3g4J924FTijVBSCzURl1dhdD3QSYOVzaF+y5st +bYUYLk5KFHXBCeLjU69DmBEuzYFzNRIPI5ctiuxa8UqpXybughpjwc9cJH0Y7EhllDG q0iw== X-Gm-Message-State: AC+VfDyXemo7TYaQONvBYExHXPLZw9xzoA7CT/UAlFwqrx72/K2HNVLM P4wiY+bzCY5TPaiyDUKLHFOc548= X-Google-Smtp-Source: ACHHUZ5CfBJqKCPcdGvyED5Wc7zjHX1ZbzPa4swaTK2n5p8NxRfX+/XBk45of4pSm71BST0vk+9zGIY= X-Received: from pcc-desktop.svl.corp.google.com ([2620:15c:2d3:205:c825:9c0b:b4be:8ee4]) (user=pcc job=sendgmr) by 2002:a25:dc43:0:b0:ba1:6f1b:8905 with SMTP id y64-20020a25dc43000000b00ba16f1b8905mr21936003ybe.4.1684204525241; Mon, 15 May 2023 19:35:25 -0700 (PDT) Date: Mon, 15 May 2023 19:35:13 -0700 In-Reply-To: <20230516023514.2643054-1-pcc@google.com> Message-Id: <20230516023514.2643054-3-pcc@google.com> Mime-Version: 1.0 References: <20230516023514.2643054-1-pcc@google.com> X-Mailer: git-send-email 2.40.1.606.ga4b1b128d6-goog Subject: [PATCH v2 2/2] arm64: mte: Simplify swap tag restoration logic and fix uninitialized tag issue From: Peter Collingbourne To: Catalin Marinas Cc: Peter Collingbourne , " =?utf-8?b?UXVuLXdlaSBMaW4gKA==?= =?utf-8?b?5p6X576k5bS0KQ==?= " , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "surenb@google.com" , "david@redhat.com" , " =?utf-8?b?Q2hpbndlbiBDaGFuZyAo?= =?utf-8?b?5by16Yym5paHKQ==?= " , "kasan-dev@googlegroups.com" , " =?utf-8?b?S3Vhbi1ZaW5nIExlZSAo5p2O5Yag56mOKQ==?= " , " =?utf-8?b?Q2FzcGVyIExpICjmnY7kuK3mpq4p?= " , "gregkh@linuxfoundation.org" , vincenzo.frascino@arm.com, Alexandru Elisei , will@kernel.org, eugenis@google.com, Steven Price , stable@vger.kernel.org X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 1703C40005 X-Stat-Signature: xjf47u76m9y3ui7zx69izkxqcbyscoih X-HE-Tag: 1684204525-428858 X-HE-Meta: U2FsdGVkX1/g7phJwBzn1/eJKzFTELg/3UeMKAsLoLN0F4ZdzCM9cF2d5vgwSXhG8Qc3vCC73bIC31/8WFNo5sKaD4v/DuWidTk169na4SpWXdwVUez2lVLP9dr9/AED7CcrdiwuODZmNu1bXX0mHL1mScYXAXfpcFR5Y+Bbsvz4E9qxgmkm6+BtfORtXBh+e7p3InSr8BQDt8RZlaNo6aA2pRre/BonzY1kGmkNkz/zNT0/4j8W9F+PgiOjpGlSpYxCgPW/Y2AuecA5V0DQ0O5fMkr/slHVXc1v1p9nh4aMetaeBanRu2poN1ADssfo0KFsHmeFN8K26d8qK/BhL8KL8ZnbApHbFo7eSHXy3+iSm646A2g8L3ZmaoKz6YZoBWzoVSO5cpoeacGT3pt8/PTkREfwt5zh/0UusbvAnoob3Ve1s8l9up85OkEeLmRKNgJN/BJIjQcurjAdx/1buFYxBefNvMBtkDBH/Tz68C5arbZqZq0lJISQOQ3PbHUNF1jESQuzO7rf/Udt3qCTjnRmNiB/Cdcxp24xUktxBgNZKVKMPa9lUvRUoeWdcsrEwLkPCvPMSMGOtSsbTGjGhBXRk1dd0qsftLUYw/JO41A6/lh3KQe2822FGHtAnSNpw/SFzi5jYgRv8ycGA6PdzQSK0XrQsbDRHmGQIHHIoU+pPK+ixzXzuju0VPS3YBted6LAU6PfhL/JH/VGwZda1RS/wcjmbaxMcu9uwEwDEITlUKYq0RlJoOpJjV4q6rQ8VnmYN6TEfoejXLJenNnzD8iSZ/DGs1iRBF9L8YOz68zmesRVv9KFUnSjRw0gvzhgRP1SiLcOTQFYYKCEisQqXy00HzicoZIwh9DikZpYI6qwB16S67AegAg+FR0ObZYufDMbokPjL6wtQcqFtWxFK8CtNRo2JSRL+DOYFnMT3x7AKsxV/IIqNIhSjZI4XAShmU5Xauf0RHFWOiouZCb USrbp4X4 Kx8lyFfPT8VGXscbgsf0j9lx7fTBTXd9IzkC+iVFMk53ri6lM3fFen0Vw1mY/UHXnUXtRZacc0p4MybzGD3pI2z/0X8JHGOX3Etl8pixI2mSzjLnkS5lhDnmUqwtUYXXxx3fv7ygM+QHBqkTuMjqgH8Mu9p9ZA51MD3yHrr4LQ7NtvnoIWt4VMTXdHbioxMcst5qtdlAwRGbk8aeUFD8/JF6Yooc8mBY2B5x+wMETxh9ZkeztD+KGyt6DYB30hQ0L1Kfs8S2IjdcP5pfUzpY/lLqaKtPyQDdC1zelc75VWwwjgFoez7LQeg8tAEv33+rKOYmL/KschrJOa3YsRrt1hj5IRmGJwjs+SMyWQs9GKqwo/uQzQLY+Sf0mciA4KxpZ4Z6HMbqa/7osdtHFkXVG4dB6D7gqWspJT3Pq5jlKsjNjteF/hBP16rsB1V8wAofHS2JbGe66w3J7hm35GL7N+bUCCAOW/2NILernLSQSraP56biXmwnMhfUSnAbVswvBM92kkYOp0gYwbfK0tM2iwcmE5cBiMHOrj2Blcg7htontkm3/Dv6z5gTZkeyAA7k6pV3wuYqt0IUFGv6HOeIgb1tKmfvTzrGsvyUzLYvyNYxL5u6BalwjNItShVS2P2U+PYKnHPQ8F32bVPTvObblKoPj376Mv99Efl7ALk2whSvXo+/hItSExuhafUdoEBUKC66KsqWtQkK2hOfAbtGCpWjO6pVhbHTt8gLZFGNwcERfhDQGII9KkDmhWg== 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: As a result of the previous two patches, there are no circumstances in which a swapped-in page is installed in a page table without first having arch_swap_restore() called on it. Therefore, we no longer need the logic in set_pte_at() that restores the tags, so remove it. Because we can now rely on the page being locked, we no longer need to handle the case where a page is having its tags restored by multiple tasks concurrently, so we can slightly simplify the logic in mte_restore_tags(). This patch also fixes an issue where a page can have PG_mte_tagged set with uninitialized tags. The issue is that the mte_sync_page_tags() function sets PG_mte_tagged if it initializes page tags. Then we return to mte_sync_tags(), which sets PG_mte_tagged again. At best, this is redundant. However, it is possible for mte_sync_page_tags() to return without having initialized tags for the page, i.e. in the case where check_swap is true (non-compound page), is_swap_pte(old_pte) is false and pte_is_tagged is false. So at worst, we set PG_mte_tagged on a page with uninitialized tags. This can happen if, for example, page migration causes a PTE for an untagged page to be replaced. If the userspace program subsequently uses mprotect() to enable PROT_MTE for that page, the uninitialized tags will be exposed to userspace. Signed-off-by: Peter Collingbourne Link: https://linux-review.googlesource.com/id/I8ad54476f3b2d0144ccd8ce0c1d7a2963e5ff6f3 Fixes: e059853d14ca ("arm64: mte: Fix/clarify the PG_mte_tagged semantics") Cc: # 6.1 --- The Fixes: tag (and the commit message in general) are written assuming that this patch is landed in a maintainer tree instead of "arm64: mte: Do not set PG_mte_tagged if tags were not initialized". arch/arm64/include/asm/mte.h | 4 ++-- arch/arm64/include/asm/pgtable.h | 14 ++------------ arch/arm64/kernel/mte.c | 32 +++----------------------------- arch/arm64/mm/mteswap.c | 7 +++---- 4 files changed, 10 insertions(+), 47 deletions(-) diff --git a/arch/arm64/include/asm/mte.h b/arch/arm64/include/asm/mte.h index 20dd06d70af5..dfea486a6a85 100644 --- a/arch/arm64/include/asm/mte.h +++ b/arch/arm64/include/asm/mte.h @@ -90,7 +90,7 @@ static inline bool try_page_mte_tagging(struct page *page) } void mte_zero_clear_page_tags(void *addr); -void mte_sync_tags(pte_t old_pte, pte_t pte); +void mte_sync_tags(pte_t pte); void mte_copy_page_tags(void *kto, const void *kfrom); void mte_thread_init_user(void); void mte_thread_switch(struct task_struct *next); @@ -122,7 +122,7 @@ static inline bool try_page_mte_tagging(struct page *page) static inline void mte_zero_clear_page_tags(void *addr) { } -static inline void mte_sync_tags(pte_t old_pte, pte_t pte) +static inline void mte_sync_tags(pte_t pte) { } static inline void mte_copy_page_tags(void *kto, const void *kfrom) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index b6ba466e2e8a..efdf48392026 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -337,18 +337,8 @@ static inline void __set_pte_at(struct mm_struct *mm, unsigned long addr, * don't expose tags (instruction fetches don't check tags). */ if (system_supports_mte() && pte_access_permitted(pte, false) && - !pte_special(pte)) { - pte_t old_pte = READ_ONCE(*ptep); - /* - * We only need to synchronise if the new PTE has tags enabled - * or if swapping in (in which case another mapping may have - * set tags in the past even if this PTE isn't tagged). - * (!pte_none() && !pte_present()) is an open coded version of - * is_swap_pte() - */ - if (pte_tagged(pte) || (!pte_none(old_pte) && !pte_present(old_pte))) - mte_sync_tags(old_pte, pte); - } + !pte_special(pte) && pte_tagged(pte)) + mte_sync_tags(pte); __check_safe_pte_update(mm, ptep, pte); diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c index f5bcb0dc6267..c40728046fed 100644 --- a/arch/arm64/kernel/mte.c +++ b/arch/arm64/kernel/mte.c @@ -35,41 +35,15 @@ DEFINE_STATIC_KEY_FALSE(mte_async_or_asymm_mode); EXPORT_SYMBOL_GPL(mte_async_or_asymm_mode); #endif -static void mte_sync_page_tags(struct page *page, pte_t old_pte, - bool check_swap, bool pte_is_tagged) -{ - if (check_swap && is_swap_pte(old_pte)) { - swp_entry_t entry = pte_to_swp_entry(old_pte); - - if (!non_swap_entry(entry)) - mte_restore_tags(entry, page); - } - - if (!pte_is_tagged) - return; - - if (try_page_mte_tagging(page)) { - mte_clear_page_tags(page_address(page)); - set_page_mte_tagged(page); - } -} - -void mte_sync_tags(pte_t old_pte, pte_t pte) +void mte_sync_tags(pte_t pte) { struct page *page = pte_page(pte); long i, nr_pages = compound_nr(page); - bool check_swap = nr_pages == 1; - bool pte_is_tagged = pte_tagged(pte); - - /* Early out if there's nothing to do */ - if (!check_swap && !pte_is_tagged) - return; /* if PG_mte_tagged is set, tags have already been initialised */ for (i = 0; i < nr_pages; i++, page++) { - if (!page_mte_tagged(page)) { - mte_sync_page_tags(page, old_pte, check_swap, - pte_is_tagged); + if (try_page_mte_tagging(page)) { + mte_clear_page_tags(page_address(page)); set_page_mte_tagged(page); } } diff --git a/arch/arm64/mm/mteswap.c b/arch/arm64/mm/mteswap.c index cd508ba80ab1..3a78bf1b1364 100644 --- a/arch/arm64/mm/mteswap.c +++ b/arch/arm64/mm/mteswap.c @@ -53,10 +53,9 @@ void mte_restore_tags(swp_entry_t entry, struct page *page) if (!tags) return; - if (try_page_mte_tagging(page)) { - mte_restore_page_tags(page_address(page), tags); - set_page_mte_tagged(page); - } + WARN_ON_ONCE(!try_page_mte_tagging(page)); + mte_restore_page_tags(page_address(page), tags); + set_page_mte_tagged(page); } void mte_invalidate_tags(int type, pgoff_t offset)