From patchwork Tue Feb 14 01:52:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Collingbourne X-Patchwork-Id: 13139254 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 57BE0C636CC for ; Tue, 14 Feb 2023 01:52:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B8B0C6B0073; Mon, 13 Feb 2023 20:52:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B3B47280002; Mon, 13 Feb 2023 20:52:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A032F280001; Mon, 13 Feb 2023 20:52:33 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 8CC2D6B0073 for ; Mon, 13 Feb 2023 20:52:33 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 3F053C032B for ; Tue, 14 Feb 2023 01:52:33 +0000 (UTC) X-FDA: 80464222986.06.D000415 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf11.hostedemail.com (Postfix) with ESMTP id 96BEB40009 for ; Tue, 14 Feb 2023 01:52:30 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=cF3vp2hn; spf=pass (imf11.hostedemail.com: domain of 3XenqYwMKCAIreeiqqing.eqonkpwz-oomxcem.qti@flex--pcc.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3XenqYwMKCAIreeiqqing.eqonkpwz-oomxcem.qti@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=1676339550; 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=2J+3GOG2P0hnwklMWKGq0tLBKfNtpEESwIEDcAq6rlI=; b=BGrFSO8UnXaLkqZqaWKyw/0RJwhSzLS7KXn/aJfz3mQ10zxMEx6pDMsRjs5t6PJmPuFrur lIOaqLdpY5v+8R+QYfak519F7wB4u3RTd1W5+0L204xulK5U0PwyebtoHGciJM85NMr5td CBLDIuCTD4yZrJAlToKZM4s5xnhwzNA= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=cF3vp2hn; spf=pass (imf11.hostedemail.com: domain of 3XenqYwMKCAIreeiqqing.eqonkpwz-oomxcem.qti@flex--pcc.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3XenqYwMKCAIreeiqqing.eqonkpwz-oomxcem.qti@flex--pcc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676339550; a=rsa-sha256; cv=none; b=u5rBo52sG03Qpx4ujnWaJwmkeWYr2ASE+Th7abONcd0OsFSb6bdD+j5RDcCIZ+ZrxgeTwy UKMsK/XbW3cSSvQvZG6dz8GNh4OHaaB7yFsC+LKwPE2my7rwKb23v9gTeScEChIz3DRfHi 1u/PCYaRPIWff7VVjn+7w34tMXisdm8= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-52a8f97c8ccso143553947b3.6 for ; Mon, 13 Feb 2023 17:52:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=content-transfer-encoding:cc:to:from:subject:mime-version :message-id:date:from:to:cc:subject:date:message-id:reply-to; bh=2J+3GOG2P0hnwklMWKGq0tLBKfNtpEESwIEDcAq6rlI=; b=cF3vp2hnvMgG9ens+55wFDLcpBIkUkt4Nr/ypQnsswmAhEKnCMkvo8mhtgwk6R2oWI hnMGi8RcYBDYS6G4DDTcN8MUzkLnggjUk60MrjOF4qdbV194PhN2YZqViUOzWTyIcQJ6 brzQ5pW4Q58FaWVJNjaNBxB2xGQ4iKx4H373x7OOuRmEN96Xjvrh0gCNa6HTX6opFTlJ qOlGG819eQxpIR8i/XLQ64Ea+m3or5yzSsVe0t95k1uYg1O6kfvdyJDKv9u0PVB7y9r4 fjTDsRkGaP8mohZ7h8DRJ8Wp/HnJAyL73ibTgS74esVy7uZVBqUF5/4Op1M/HpywygD3 rtJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:from:subject:mime-version :message-id:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=2J+3GOG2P0hnwklMWKGq0tLBKfNtpEESwIEDcAq6rlI=; b=lf2c8ZdzR1/JubU4iuuPQ5Z/iRqH26kaP+gn3u1aWDKMg+iDLMtpKnXZX1F5ZB46oe FEXM9oKOmc0ZU4otHw9Uv45j5NOhTQkZBXoG8ZEVPdwfxfgky6XwiSZ4fGDcJUXEt2QV n7VV6ZrFZTaOP3L7mPa9hqM8d/rCaeuE91dcidKQGZ9SffwK3mzdHE06XpKpG+v665xz NaL6AjEVn7im/doS9sn6etSbog/p5Tqk3DlNkoligor9nfSzGfMFW6oEG3uTM7FZl5KT TTnkUclBdf2FO0+U8xi+DzPKeEYFZoq39NYuVitMOhAA3i+s9gQV+brEXjj+iQ2t44h+ tAOQ== X-Gm-Message-State: AO0yUKW4dwBt0J6ZSJ4hRiHZc1+5N24ljG8tJDXQmMbm1WsN+xrFMLPr pmpDGcY3Fol5Rt0R9ILogAseLFc= X-Google-Smtp-Source: AK7set8JX2UCuUx1r/BRaJun6ZhAJ9kw7czlUn0qrE78/cOFud3HqDmluAZSD4UYPrIYk/Z3I/l8GIk= X-Received: from pcc-desktop.svl.corp.google.com ([2620:15c:2d3:205:6153:a2b0:1bfd:87af]) (user=pcc job=sendgmr) by 2002:a05:6902:1147:b0:8df:1fcb:f1c8 with SMTP id p7-20020a056902114700b008df1fcbf1c8mr9ybu.2.1676339549200; Mon, 13 Feb 2023 17:52:29 -0800 (PST) Date: Mon, 13 Feb 2023 17:52:14 -0800 Message-Id: <20230214015214.747873-1-pcc@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.39.1.581.gbfd45094c4-goog Subject: [PATCH] arm64: Reset KASAN tag in copy_highpage with HW tags only From: Peter Collingbourne To: catalin.marinas@arm.com, andreyknvl@gmail.com Cc: Peter Collingbourne , " =?utf-8?b?UXVuLXdlaSBMaW4gKA==?= =?utf-8?b?5p6X576k5bS0KQ==?= " , " =?utf-8?b?R3Vhbmd5ZSBZYW5nICjmnajlhYnkuJop?= " , linux-mm@kvack.org, " =?utf-8?b?Q2hpbndlbiBDaGFuZyAo5by16Yym5paHKQ==?= " , kasan-dev@googlegroups.com, ryabinin.a.a@gmail.com, linux-arm-kernel@lists.infradead.org, vincenzo.frascino@arm.com, will@kernel.org, eugenis@google.com, " =?utf-8?b?S3Vhbi1ZaW5nIExlZSAo5p2O?= =?utf-8?b?5Yag56mOKQ==?= " , stable@vger.kernel.org X-Stat-Signature: t7zwu3ipnqtppg6jr7ndewk13kz5ty5p X-Rspam-User: X-Rspamd-Queue-Id: 96BEB40009 X-Rspamd-Server: rspam06 X-HE-Tag: 1676339550-186289 X-HE-Meta: U2FsdGVkX18F5A5khPC348PrgAXVz1wsAl4K/7dsbq5rgKW1pK1Q577T4prEkolOUS0RJhnm/wgp4LS70aMAv2wGct7fdlUScwt+XlB2Z34UNWAikBrDRlRB5gOO9PaKzUP6Zp1hPCHugwoQzWFHy0MZm1UzKMbp2lYx0fkmS0P+19qr/6y+zypiVVYJYfqrpF7TtEvY7+dCO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18pyYO9bXUO9Z3DiFBRFyAK90QwGIo5MNDuOfXWKbWxVTmh7uV3ZOXovDCKiGWYI71VvUPAwpz0Pd6PNFMhR8tI9/w2VMyyZ80D90iGu9pN49vVxWmnYrtHyiMaR4TrZlG9GK8fiq6XILmgTNBeJR+FEeHMZKS1sw2gnSFJCdHPUlJIFsJdjY0aTqauTOcO+uEZ/rKpcCc/92b/ISpfptXBosFVv4GQtMnqXvMDlJ7qLMNL7pCMH/57LVN3wQd+65VMODlhv8ccyhtuRFOM8jyMxQ2CkNnvtuMQz8P5hrYHBZPuZhx5IchOZteDBaVOZk42a3zn9aJj2DCaSRMn2uf8W5+bASbne07KGkcsci8bwGD7zAKR8ILWYvBH3/I2381wMGtE+FRAt5bIeZKZ1hXVrouswDgJRB5arBbnd4ETdpJ+mXDMOWtTBJBWbd+5n3ZVA9vjdJTGBZjNTagNWXoz4fuDawqjGy8la2RZTnVI3do1LmlONmEAmxpzsSMptlJjV5E8n7vLNZwoPNbrZs5TiFyKq6/lKekCLPNqK4w1fWThmnq/Rp/sAGtEe5MoWh7I/959HbjBevQ/xwG8IxItDf87SekgvVmr3T4/GA= 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: During page migration, the copy_highpage function is used to copy the page data to the target page. If the source page is a userspace page with MTE tags, the KASAN tag of the target page must have the match-all tag in order to avoid tag check faults during subsequent accesses to the page by the kernel. However, the target page may have been allocated in a number of ways, some of which will use the KASAN allocator and will therefore end up setting the KASAN tag to a non-match-all tag. Therefore, update the target page's KASAN tag to match the source page. We ended up unintentionally fixing this issue as a result of a bad merge conflict resolution between commit e059853d14ca ("arm64: mte: Fix/clarify the PG_mte_tagged semantics") and commit 20794545c146 ("arm64: kasan: Revert "arm64: mte: reset the page tag in page->flags""), which preserved a tag reset for PG_mte_tagged pages which was considered to be unnecessary at the time. Because SW tags KASAN uses separate tag storage, update the code to only reset the tags when HW tags KASAN is enabled. Signed-off-by: Peter Collingbourne Link: https://linux-review.googlesource.com/id/If303d8a709438d3ff5af5fd85706505830f52e0c Reported-by: "Kuan-Ying Lee (李冠穎)" Cc: # 6.1 --- For the stable branch, e059853d14ca needs to be cherry-picked and the following merge conflict resolution is needed: - page_kasan_tag_reset(to); + if (kasan_hw_tags_enabled()) + page_kasan_tag_reset(to); - /* It's a new page, shouldn't have been tagged yet */ - WARN_ON_ONCE(!try_page_mte_tagging(to)); arch/arm64/mm/copypage.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/arm64/mm/copypage.c b/arch/arm64/mm/copypage.c index 8dd5a8fe64b4..4aadcfb01754 100644 --- a/arch/arm64/mm/copypage.c +++ b/arch/arm64/mm/copypage.c @@ -22,7 +22,8 @@ void copy_highpage(struct page *to, struct page *from) copy_page(kto, kfrom); if (system_supports_mte() && page_mte_tagged(from)) { - page_kasan_tag_reset(to); + if (kasan_hw_tags_enabled()) + page_kasan_tag_reset(to); /* It's a new page, shouldn't have been tagged yet */ WARN_ON_ONCE(!try_page_mte_tagging(to)); mte_copy_page_tags(kto, kfrom);