From patchwork Wed Feb 15 05:09:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Collingbourne X-Patchwork-Id: 13141322 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 56708C636CC for ; Wed, 15 Feb 2023 05:09:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 923036B0074; Wed, 15 Feb 2023 00:09:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8D2F06B0075; Wed, 15 Feb 2023 00:09:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 79A356B0078; Wed, 15 Feb 2023 00:09:21 -0500 (EST) 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 6A0AD6B0074 for ; Wed, 15 Feb 2023 00:09:21 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 24F791212E6 for ; Wed, 15 Feb 2023 05:09:21 +0000 (UTC) X-FDA: 80468347722.28.0DF9049 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf30.hostedemail.com (Postfix) with ESMTP id 618DC800C5 for ; Wed, 15 Feb 2023 05:09:19 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=PAVs9wTH; spf=pass (imf30.hostedemail.com: domain of 3_mjsYwMKCKcWJJNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--pcc.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3_mjsYwMKCKcWJJNVVNSL.JVTSPUbe-TTRcHJR.VYN@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=1676437759; 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=oz1c94+PpSpdOwRxmJhtyfwix/rF7URLVnLJpJ4OuRQ=; b=UaNmWfwYw0/yQZg0LnRq+gKVZGNn1toMe2sk42fiqfiAC35N67tu3UqTJBNADYDLDW9IM+ p3iSE5Zm88fKtJDE1KshtXhq7f1laLwe+UpkyPeM6zq6jsxvba2b9S3j4UiXlqJY/oavkg nAqjpbZjkDTDgBRtq/XYA6NlHUpd/3c= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=PAVs9wTH; spf=pass (imf30.hostedemail.com: domain of 3_mjsYwMKCKcWJJNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--pcc.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3_mjsYwMKCKcWJJNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--pcc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676437759; a=rsa-sha256; cv=none; b=HTKb46US+yrbq7bG/oPiWszd1rI9XTU2EHWNrwlBWeu3Njp9l96sqzYnL8bMo37N8fEkCb dlWqe89ykhVWjfylV8AGBEfiUXHQwUcLokKv2ZHAPcq9+F7yz30apo6O0H0BHLLq4VEOYv 704UX8kabm+74yE/hMkEvTG3a6hQu8s= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-52ec7c792b1so165830977b3.5 for ; Tue, 14 Feb 2023 21:09:19 -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=oz1c94+PpSpdOwRxmJhtyfwix/rF7URLVnLJpJ4OuRQ=; b=PAVs9wTHuHqSwdcXMccaVRi59RVMu0fidE3NSoZW9Pmt84r9A7VI97aWIZJzb8OYfV XB9svOI3UGKkfvMLPWWpv5fCkxC3Ez+vBsJRjEYxoLotr34BEi+4cCL+f8c6akzvKJgY HO7rMm0aUhukTkjHLUbwDKw3cdz7BMWzOpLwMtGuPYRDHRU2ShL3LnmPac+F5HFZRzpF 02J7y2OeS0bSMab5TdzI4cLbo0T3SegMO0IGmQK3hUOW/2hkexLAXB3Shg/bUbwQ2FEm qg739zx4pTnFrmjYMgixcf28HbVJS75iGYe4pNgbFfRyTG1wFmoAk7aSs+DITRWMkY5g rdOg== 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=oz1c94+PpSpdOwRxmJhtyfwix/rF7URLVnLJpJ4OuRQ=; b=cQftdZQfHCpy76aCrzFddMM6J/wCfXRu7TnjKag1njVS3niTEMTWd0HCAD8/DEQb58 u28rhuVUOSDr29dlFteoh8caPMO6Nip3OPJL5xPKfJ99EieMTAjE9wwp3MKO9ocRNzgE tjgD5qiS+t/b/nZxBjo/66JxvCHYT0YXoCDIeI2WvbSqswjw4iSoN/4eyPEY7xp316ZT OhRkjbZOrjEUfluRzjqxBXoSLdRj/6HUzfBCj6dMRkH8RpXKAcPICCpRsRjkxEKgGAzK +0ZUss3RVlsspL0ETGIzHw0Tcv3GnaVCqbM7uG3sKvhXz8SULI0OquQWxrxNMOfph89g ACMQ== X-Gm-Message-State: AO0yUKXpiQblbg9p+b9sRt7VLlH9vPhmd6cZaHTNeDv7m5caiqMYnu9K T64zDmjcm9HXWRPZLWXayHzeGg4= X-Google-Smtp-Source: AK7set8Jv69dLvHNhXRcipzuj+FaMPD6itu9fekdMrlFGOW8fqWQ+CBzIrkh2Nr4ezQ+OweciUym0ms= X-Received: from pcc-desktop.svl.corp.google.com ([2620:15c:2d3:205:d5d8:eed0:c0c1:29d7]) (user=pcc job=sendgmr) by 2002:a05:6902:341:b0:8bb:3a1:e811 with SMTP id e1-20020a056902034100b008bb03a1e811mr129660ybs.348.1676437758447; Tue, 14 Feb 2023 21:09:18 -0800 (PST) Date: Tue, 14 Feb 2023 21:09:11 -0800 Message-Id: <20230215050911.1433132-1-pcc@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.39.1.581.gbfd45094c4-goog Subject: [PATCH v2] 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-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: nken7aubwhkcryka5dreg4jwwmonfpb1 X-Rspamd-Queue-Id: 618DC800C5 X-HE-Tag: 1676437759-94626 X-HE-Meta: U2FsdGVkX1/DWETVYqz+CJeKcRek6PKK0IvQVqyGGeXvpL04yusAPxJnNbnnBwU2EeTknwKmPVm7pYMyURgnhdu0/NSntXEAjHQOeZaScux3Tzah1sldHn8Px7wN4eZxvitafA/4ZdQIREhKmiUGqBJgjo87kjE5jR+9lOj5PYb5Vc0SSMPdGrxpJ3i9M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Rp3RY4kwgqfDAr1BeJPKtoma4LpmX2gmMtwqfdIdj7O9oNI//LI9EWD4w/z5f3iO7i02mEwmndaj5lgOD+nCkW3EirEajo0lIN/qGDKCbL+2LZwDGdb3R9w8Aui2VhxAhZyS2Q7U1OGhBzg4L6fgFTHHwKIvr4YVFPbcGkA9NkwxpL40itepO8J2+Z93jjQ6gCO+w3cxt2tngurHKYysVQMugMP7s7VsOzK0AS/+bb23QupxlBW0wT5gtq8T5ZbiVsscAeoNAHoDQvh1F3g7G0tr0YaQXq4SDVBCLsjeaPMIxFNnkkLIKeZcMpl8AjAk797eCVx+fAAyICejF9glhGgxDZ+BB2fJLoU409R2sVfrgklKvBYNDoumLYDU9VTG/QcHKY6Ikk3bmgmUe7Vu+QUERQ0NLP3vr2f3EXOqgwsKPYj0xNI6Y/Hhyp4Cy+qcZcxRHKZ8AZj6RYVMWAROvOyQxi6qbv3aMutDoP67zTAO9gpWWgR7psbLc3xQG/vono6QEmwULeUKGF1TSqdvp5yNdiGsnKxstyrjp9HaV22+6iBWVmE29AWx97zHWFvJsem3NxQuLDSAhvmn/AexrftX4KNr+lAWqF7UKV90fRm1lNZ4= 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 Fixes: 20794545c146 ("arm64: kasan: Revert "arm64: mte: reset the page tag in page->flags"") Reviewed-by: Andrey Konovalov --- v2: - added Fixes tag 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);