Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp6902423pxv; Fri, 30 Jul 2021 05:28:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwbiKWkP66eyDr4I59nnSqn3IJSQkQxxmeIAy/uqh4YGoUygNFGvJRnWxxbpt+rLpJyeats X-Received: by 2002:a05:6638:33a6:: with SMTP id h38mr2006080jav.130.1627648109624; Fri, 30 Jul 2021 05:28:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627648109; cv=none; d=google.com; s=arc-20160816; b=d9dWZT3iQOWjQIDj9iVSTE+dSNsVT0t+CXjty6k28jPoDjGbRk/R+Nxreq9dMVm0i3 PWInMQ/+c2qdeN8OUI0VptqPJuYACihBNi5kryyq6jtehPzy8T/xpbQOSI7xKc6s0RZ6 Qo1CzrIUU7U9zzCX1ykFZTKRPWFhO0lbIL2xZCgSVs0u3BbJnbZD2ip/eH1uRgzfJAe8 IgqHAMqUY0kb7Vibbfzi+Ps/g4M//3QN7mf/aW9hQ/fFEPZqvxDs+HJWMM7IMb1sx1ay 4e0/UIcK7SpvowR5fOSosTX0BtosT3u24OsrjgTCfD0ketI0gBK9cFTel8uI/kOZjvfs a/lA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=YYPd8kv11i6HCOKpyiG53AZGNjIwrDp89tRcnPhf0nw=; b=h8J7y9beqKPfcqOvmQ9WHZ6zZrCfCSc2NdPKZsQYkzCILF75DpzrmhHC+taAcnsx/T okn2xhtGeJOB0H7rjGOT67PrVaNr7f8NccRikvoyQ2kSLjfsW56i4byTjKF6upTeId9v D42EiVPKOVbHwrWelx68yklzZnT9qFdPPWtmNucA2p25L1YctM+Q0HeISZER6Y9Ws5BL nU/8lYhuOX8tfhcuqFaY3G1p22qKCq3SBH0PNodW4fk40TMZ6g0JsZjSB39rTMTuKWNO vnBl6h7iC1wKwshn1WTXEAb6vVOMZ4aaW0jbQnGV6W9f48vw40UB4s/guERIXGHxtpwo V8pA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qOvuP+PZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x90si1637812jah.3.2021.07.30.05.28.18; Fri, 30 Jul 2021 05:28:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qOvuP+PZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238713AbhG3M1J (ORCPT + 99 others); Fri, 30 Jul 2021 08:27:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:52778 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238736AbhG3M1J (ORCPT ); Fri, 30 Jul 2021 08:27:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4B1F66103B; Fri, 30 Jul 2021 12:27:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1627648024; bh=wT4Jmfp7K7e7610QIG6UJIKHHYTDycOajWViNs/FQzc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=qOvuP+PZHGEQ6QFN9P+8FzxInej00GZmWtK4vwy+MZHMp1WOGMrViCMD0C4E/22gb MLo9g0h9j0QBO24ETL9yVk+AyNhZxKNKXxTWahTA5VCPHB65mgTEuHclGoqvxNecn5 35Rpc2I2tuELdVK3Zmf8w431pR7IeEuLHZVO1yZ2sGEVlACBETPeYaXCT47Gy4u1ca do/tEe5NT7emIko7C5viwa0FRQ9Lo27DJljdYaZCHS8xYb0RglMeBNuIdFY302g55t llilOsUMxh7gMxsM5V2437OQA72tkzPS28rHXsx8u+qJ0OcWkMXN/UpQzpy19blt9G Wl4B6Bo4b/VRw== Date: Fri, 30 Jul 2021 13:26:59 +0100 From: Will Deacon To: Marc Zyngier Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, qperret@google.com, dbrazdil@google.com, Srivatsa Vaddagiri , Shanker R Donthineni , James Morse , Suzuki K Poulose , Alexandru Elisei , kernel-team@android.com Subject: Re: [PATCH 04/16] KVM: arm64: Add MMIO checking infrastructure Message-ID: <20210730122658.GG23589@willie-the-truck> References: <20210715163159.1480168-1-maz@kernel.org> <20210715163159.1480168-5-maz@kernel.org> <20210727181107.GC19173@willie-the-truck> <8735ryep6d.wl-maz@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8735ryep6d.wl-maz@kernel.org> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 28, 2021 at 10:57:30AM +0100, Marc Zyngier wrote: > On Tue, 27 Jul 2021 19:11:08 +0100, > Will Deacon wrote: > > On Thu, Jul 15, 2021 at 05:31:47PM +0100, Marc Zyngier wrote: > > > +bool kvm_install_ioguard_page(struct kvm_vcpu *vcpu, gpa_t ipa) > > > +{ > > > + struct kvm_mmu_memory_cache *memcache; > > > + struct kvm_memory_slot *memslot; > > > + int ret, idx; > > > + > > > + if (!test_bit(KVM_ARCH_FLAG_MMIO_GUARD, &vcpu->kvm->arch.flags)) > > > + return false; > > > + > > > + /* Must be page-aligned */ > > > + if (ipa & ~PAGE_MASK) > > > + return false; > > > + > > > + /* > > > + * The page cannot be in a memslot. At some point, this will > > > + * have to deal with device mappings though. > > > + */ > > > + idx = srcu_read_lock(&vcpu->kvm->srcu); > > > + memslot = gfn_to_memslot(vcpu->kvm, ipa >> PAGE_SHIFT); > > > + srcu_read_unlock(&vcpu->kvm->srcu, idx); > > > > What does this memslot check achieve? A new memslot could be added after > > you've checked, no? > > If you start allowing S2 annotations to coexist with potential memory > mappings, you're in for trouble. The faulting logic will happily > overwrite the annotation, and that's probably not what you want. I don't disagree, but the check above appears to be racy. > As for new (or moving) memslots, I guess they should be checked > against existing annotations. Something like that, but the devil is in the details as it will need to synchronize with this check somehow. Will