From patchwork Tue Oct 5 12:20:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12536511 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2003C433F5 for ; Tue, 5 Oct 2021 12:22:35 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 96B0461186 for ; Tue, 5 Oct 2021 12:22:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 96B0461186 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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=+xVhQXFjaLBrZvU7m+KHlhhrb/tTEB7aYSJMqg25cw4=; b=sGL vTTkgjj1QLAP7BE+bkvhr+tSrdL060q3JQYve9jkeu5RLT2Wq43N7a4Gj7hUcAErhMgxPaEESGHpI 0NUpVIsjDkX/VJXepmpYl+1qRcJKu9HUOUGvtSmj4QNtW60/Qi29R1Z3CktXwVYwTiGPkGZfM/RtS S9aKOOxILZvLhfxVvgRk2cc31vJzqwz/mc50NX0c26aJq9L+ve6vZw3F5DS4DRAc95Z37oqGuAX3b os/DxkWCnGRcSgNnS5Yk5Bb/YCI5ghbJgRzGa4kG1UrYE5RXaEHaPWY1dusLC1J5R49RE/MWQouRG DB8FaIgq/EHpUVc6zcBFMwJoi0xWWBQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mXjRP-00AMQy-2A; Tue, 05 Oct 2021 12:21:03 +0000 Received: from mail-wr1-x449.google.com ([2a00:1450:4864:20::449]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mXjR0-00AMIf-Nz for linux-arm-kernel@lists.infradead.org; Tue, 05 Oct 2021 12:20:40 +0000 Received: by mail-wr1-x449.google.com with SMTP id e12-20020a056000178c00b001606927de88so5639170wrg.10 for ; Tue, 05 Oct 2021 05:20:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=m/O1dgx/6dc/3G/WHpfSWl4EY1iI+ZyzOq/yOOojIvY=; b=OD7BHJzoRVq9YndsXgA6wM/uouP19YQUkJYZ8SUt7BtxMUEI+dl3vAXpdyo4nfKnWt Vsk3eSZrnL0Xe2Kf7qXbwwa9X56ZprMhgVUSz8+b4KMXu1kWFP2HjR5vgHXhPoy3q2uk X3Ii7WpVkiUK2r48b53wLkrH/4pqCMMwoVCZy/1d9SHnKai8GthwWqAm0kbbsLwMqyTZ L1rwzgHNArnHLbBPv0/S6y4EUzjDFknvyxBXSxWd2aNnJOK/6Th6VsFTHqsxAsWAuz5N 4/OkIdVv/6RiRMYvlaDGJumhw+2CBQPd+nv8BstqehoOILYGz0t1fie2R4BxE5Rh3G3V 6DuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=m/O1dgx/6dc/3G/WHpfSWl4EY1iI+ZyzOq/yOOojIvY=; b=G4l4eHPm513+1W2EdfkbJcNUIwuWc39NXLEFAJ+RQbB5fR1CIGwm65gZXg66qkf1xb nbzoLhYZQuzWgKeAaOfypjj1MqTEzfwfPy/DzvlQQVVtiV23MunvwZ13dXKz2Q3Z4L0m IDOZaquRJQTzldEv2MH0KI98PxVb6w9GYnZiOCqJXLzic0zxb8pVM9+d99IaduxRYgyU mD3SkGV/s2ferNinTtb9Ja6Gk7Rq3clSURRP+PkodDXRmQh2gVfnKaQiyk2q9X2HJo9i NEjjQ9VdhtGAbI44/ANmwvOWBbs03cb/3Fu8ECo/Tg12FbuQWFI5WnlfTuNSiJ3EvjCy aoNA== X-Gm-Message-State: AOAM532XTRlAtzbGyCbgSJpGrlUFkUbkabUJ9IIWatQ1YoU/+cGgLf6P y9S2NqRammPUXKBRwIE0R/kHpDlVfkl4 X-Google-Smtp-Source: ABdhPJwmuoUenb0uSWOlCBVEwk5H7f0VMu8HbnUjMB8fSNcFpLR024d7GwmK+6XLgt3zfreUU7OOwG2C8UMa X-Received: from luke.lon.corp.google.com ([2a00:79e0:d:210:c8bd:fb02:d32e:faa0]) (user=qperret job=sendgmr) by 2002:a05:600c:3b26:: with SMTP id m38mr612627wms.0.1633436435583; Tue, 05 Oct 2021 05:20:35 -0700 (PDT) Date: Tue, 5 Oct 2021 13:20:31 +0100 Message-Id: <20211005122031.809857-1-qperret@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.33.0.800.g4c38ced690-goog Subject: [PATCH] KVM: arm64: Release mmap_lock when using VM_SHARED with MTE From: Quentin Perret To: Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Catalin Marinas , Will Deacon , Steven Price , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org Cc: kernel-team@android.com, Quentin Perret X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211005_052038_829612_95E206DE X-CRM114-Status: GOOD ( 12.83 ) 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 VM_SHARED mappings are currently forbidden in a memslot with MTE to prevent two VMs racing to sanitise the same page. However, this check is performed while holding current->mm's mmap_lock, but fails to release it. Fix this by releasing the lock when needed. Fixes: ea7fc1bb1cd1 ("KVM: arm64: Introduce MTE VM feature") Signed-off-by: Quentin Perret --- arch/arm64/kvm/mmu.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 1a94a7ca48f2..69bd1732a299 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1529,8 +1529,10 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm, * when updating the PG_mte_tagged page flag, see * sanitise_mte_tags for more details. */ - if (kvm_has_mte(kvm) && vma->vm_flags & VM_SHARED) - return -EINVAL; + if (kvm_has_mte(kvm) && vma->vm_flags & VM_SHARED) { + ret = -EINVAL; + break; + } if (vma->vm_flags & VM_PFNMAP) { /* IO region dirty page logging not allowed */