From patchwork Fri Nov 4 01:10:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Collingbourne X-Patchwork-Id: 13031155 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5EC58C433FE for ; Fri, 4 Nov 2022 01:12:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Mime-Version: Message-Id:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=PSSZ+y2OabSRNDaeYYGs6UBUo2PQMJAbKLqsjUN98VQ=; b=ylm KCDpuaknRLRXlD2C88XEMPeearecVrfzeNPU7fw2DKZIowXOQa/KXdfJsWVHsp9wEpbVLFPSnQkxc 5geNKM0rKEe+7ujMnvrPXJU/piDgJ2ypfWQIIlpwfpqUjSyf2y8tKGPw/TKlPb8AaVP7gUaCbAyCR //Yb8/pJK9zHAazTxXHdItHSIqGtSlfWj6DhMDV2mw5u0O1ZMRSBNHZdGicH7UKtUTMfkRh1MKBm6 /usjkX1E9/eUlJQ6D0l0h40lsxUT00+0159DjwAS08caxtMKnmclWkaJH3Vs1RVNtbhhjxZ7hXcNV 2bwSsOOuOAcIkYssr5uRCnvWWpX5yMA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oqlEf-0024Wx-R3; Fri, 04 Nov 2022 01:11:05 +0000 Received: from mail-pg1-x54a.google.com ([2607:f8b0:4864:20::54a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oqlEc-0024WA-9n for linux-arm-kernel@lists.infradead.org; Fri, 04 Nov 2022 01:11:03 +0000 Received: by mail-pg1-x54a.google.com with SMTP id f19-20020a63f113000000b0046fde69a09dso1711693pgi.10 for ; Thu, 03 Nov 2022 18:11:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:mime-version:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=MD4sMsdZ3Kj9lzVMKTpZ1mSgffrTJwexAbptSvbOBTs=; b=KAGDbvUBGRMCwSDrAXBTfRWpNauve+o6eufOssRdV8+ifYozwSybHg4nY9bJPm/KDt 74XyI+eiTBQmG0nE2ysra4jkAYePQx4ZoS8wiT1TlV0xL01s8tqKePoWJk4W9r4Yo9nx Hn1hv2IdqZci+4cKUeAd+aRYtmRQ2qD9wSzI5+/pegF3BAxcWRWNNZcOMs2p+X4Lj36y Q6DEOEddA5LiwkUhytRm9r5yvfo8ERcuJtlFm3bNCGkJXMcL5pfFdvTr5U40J8iwDMu/ Cyve//FTWDMlncsRKNKr4OxEqSFf1F4uq/IHjwwII/bX4GiFocJYFLcWJiDfp1W1Poih DyOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=MD4sMsdZ3Kj9lzVMKTpZ1mSgffrTJwexAbptSvbOBTs=; b=1Svd4qMJtl9nu4xwdlLd1C6Hl/czeesG+sb5Dm7CiFx0iBwWJs37ohZEbU80KFCgXn ALvcqOpxfEoxNOr9UaSLd4DNA+Zg0Vgs2icNw5CzxsEU/MR2wh/8lGWO/UCK0XvnwFCx xu/MqtL2lXeUw5jf5JLTdlq8JoHjBOIJvfmkfRLh3N5AjX7Ux0vv+Cadb4N1HRvss1Xz P5eCwpT5HgVebzu+3UBZ39JMSwgIk/d990eZqY6zD0OiVtTw50LUApVLBJ7JnxeB6pCN AmxhkhthvvpOyRhSfgdpf9WMdmAMo1+w7LN9j9+e7B+jJdjhlxUUQvd97Pme+12x3JYc BQcA== X-Gm-Message-State: ACrzQf0gJNMpUsL1Y105V8+poyrpkKf9rUEfMWEuWDW9ixesMUfZSZUd 7djWAyiC61PbW316DdHT68WHH0tzQBCulSqFBx01e9MNdGh7zlpqQgfwYgZShH11UJiF/Jtw8zc 8gcJdUAJLLTFvyUe0faYUIwxCruskst4nv0Fbxa6R2VU0faezDrPbQmxtkf9i2UH3IvDvfDOI X-Google-Smtp-Source: AMsMyM41C+IFtgA5t1c+69xBTRkwpvyPxjIzeGnprwRfU+qsGdt/Bl29bDMEYWzWzr8sDSkH76xhnvA= X-Received: from pcc-desktop.svl.corp.google.com ([2620:15c:2ce:200:2844:b0ec:e556:30d8]) (user=pcc job=sendgmr) by 2002:a17:90a:1287:b0:20a:f469:7307 with SMTP id g7-20020a17090a128700b0020af4697307mr220586pja.213.1667524259464; Thu, 03 Nov 2022 18:10:59 -0700 (PDT) Date: Thu, 3 Nov 2022 18:10:33 -0700 Message-Id: <20221104011041.290951-1-pcc@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Subject: [PATCH v5 0/8] KVM: arm64: permit MAP_SHARED mappings with MTE enabled From: Peter Collingbourne To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu Cc: Peter Collingbourne , Cornelia Huck , Catalin Marinas , Will Deacon , Marc Zyngier , Evgenii Stepanov , kvm@vger.kernel.org, Steven Price , Vincenzo Frascino X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221103_181102_385043_7078B56A X-CRM114-Status: GOOD ( 26.30 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi, This patch series allows VMMs to use shared mappings in MTE enabled guests. The first five patches were taken from Catalin's tree [1] which addressed some review feedback from when they were previously sent out as v3 of this series. The first patch from Catalin's tree makes room for an additional PG_arch_3 flag by making the newer PG_arch_* flags arch-dependent. The next four patches are based on a series that Catalin sent out prior to v3, whose cover letter [2] I quote from below: > This series aims to fix the races between initialising the tags on a > page and setting the PG_mte_tagged flag. Currently the flag is set > either before or after that tag initialisation and this can lead to CoW > copying stale tags. The first patch moves the flag setting after the > tags have been initialised, solving the CoW issue. However, concurrent > mprotect() on a shared mapping may (very rarely) lead to valid tags > being zeroed. > > The second skips the sanitise_mte_tags() call in kvm_set_spte_gfn(), > deferring it to user_mem_abort(). The outcome is that no > sanitise_mte_tags() can be simplified to skip the pfn_to_online_page() > check and only rely on VM_MTE_ALLOWED vma flag that can be checked in > user_mem_abort(). > > The third and fourth patches use PG_arch_3 as a lock for page tagging, > based on Peter Collingbourne's idea of a two-bit lock. > > I think the first patch can be queued but the rest needs some in depth > review and test. With this series (if correct) we could allos MAP_SHARED > on KVM guest memory but this is to be discussed separately as there are > some KVM ABI implications. In this v5 I rebased Catalin's tree onto -next again. Please double check my rebase, which resolved the conflict with commit a8e5e5146ad0 ("arm64: mte: Avoid setting PG_mte_tagged if no tags cleared or restored"). I now have Reviewed-by for all patches except for the last one, which adds the documentation. Thanks for the reviews so far, and please take a look! I've tested it on QEMU as well as on MTE-capable hardware by booting a Linux kernel and userspace under a crosvm with MTE support [3]. [1] git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux devel/mte-pg-flags [2] https://lore.kernel.org/all/20220705142619.4135905-1-catalin.marinas@arm.com/ [3] https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3892141 Catalin Marinas (4): mm: Do not enable PG_arch_2 for all 64-bit architectures arm64: mte: Fix/clarify the PG_mte_tagged semantics KVM: arm64: Simplify the sanitise_mte_tags() logic arm64: mte: Lock a page for MTE tag initialisation Peter Collingbourne (4): mm: Add PG_arch_3 page flag KVM: arm64: unify the tests for VMAs in memslots when MTE is enabled KVM: arm64: permit all VM_MTE_ALLOWED mappings with MTE enabled Documentation: document the ABI changes for KVM_CAP_ARM_MTE Documentation/virt/kvm/api.rst | 5 ++- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/mte.h | 65 ++++++++++++++++++++++++++++++- arch/arm64/include/asm/pgtable.h | 4 +- arch/arm64/kernel/cpufeature.c | 4 +- arch/arm64/kernel/elfcore.c | 2 +- arch/arm64/kernel/hibernate.c | 2 +- arch/arm64/kernel/mte.c | 21 +++++----- arch/arm64/kvm/guest.c | 18 +++++---- arch/arm64/kvm/mmu.c | 55 +++++++++++--------------- arch/arm64/mm/copypage.c | 7 +++- arch/arm64/mm/fault.c | 4 +- arch/arm64/mm/mteswap.c | 16 +++----- fs/proc/page.c | 3 +- include/linux/kernel-page-flags.h | 1 + include/linux/page-flags.h | 3 +- include/trace/events/mmflags.h | 9 +++-- mm/Kconfig | 8 ++++ mm/huge_memory.c | 3 +- 19 files changed, 152 insertions(+), 79 deletions(-)