Received: by 2002:a9a:4c47:0:b029:116:c383:538 with SMTP id u7csp7540783lko; Fri, 30 Jul 2021 06:07:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOYCBl2eXuj0kJBahdRcuUekIjFXM2ULPNSQsJdkxlSwIrZtG4ojw3dupcgbVqJye2Xq5w X-Received: by 2002:a05:6e02:111:: with SMTP id t17mr1065828ilm.221.1627650428375; Fri, 30 Jul 2021 06:07:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627650428; cv=none; d=google.com; s=arc-20160816; b=ZOiRgzp3AKQ2Ioat+rDsqfaS+TKUVJBk1sBj95MuA8TFI9h8QM7IhYV7xmtzgEpaxi NvZQTIIM363c6CpBzFL4z4qCAAHxcD/YcewRolf+9QQMkOJ5TxLgWh1FERrA+J8mERZv wxi8AY+5C+NWwo9aQdusokJ0VrjOU4kniH66kbd2XYEPpuPsI0T3uqIJMkK8KNsyrCgJ Wb6dG7gmthbfIviLE2eqZNm9sbW0XGfWkspX4mvohXFUo31kjfbqHhuhjJdsD+n38iny jgWnqIk+WcASef1ydhMjEFfIL7RzxeO2iVHKlMveGpyW8R7j1YJ+0CSvvJ/J5WhafvxJ /U9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date; bh=l9gU6IYYmwBk5HomdwFWMODjGO5TbmpcoKpOlZlVcYg=; b=sb0pzu4LNnzOSGhOoyRy6PNvBN4DWP/92dC5FGvsoLh5NV7hPqztt2HADdkn248U4C jUfq3Po2H1LVWaCzwH456GqBIo3psEzxZ1/l7+B0fKSDGyFsRrMBGh7iBaSxH6u1dRVn CviXDYRxMsuZRZcysvgcsKr+AlHteCADWK9EAlHErEYKZAP7p0JLXnYeY9FwFVKBqLd6 iIUXXVhQVgFEMsfvH6ut5AJTnWXH2N2yLziAPNmaBJ6BiIGSMJR/iJZ/odM9PfHt9cIV wZzygRg9a6VaTYjil5WJPHkCurT0Zv6xSBOaChiOSZFc82iABeOCIgGQN9kkCkBRJkhb Kbsg== ARC-Authentication-Results: i=1; mx.google.com; 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 k12si1605179ilu.161.2021.07.30.06.06.55; Fri, 30 Jul 2021 06:07:08 -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; 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 S238866AbhG3NEm (ORCPT + 99 others); Fri, 30 Jul 2021 09:04:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:59950 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230445AbhG3NEk (ORCPT ); Fri, 30 Jul 2021 09:04:40 -0400 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5737761019; Fri, 30 Jul 2021 13:04:36 +0000 (UTC) Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1m9SBm-0020Ld-F0; Fri, 30 Jul 2021 14:04:34 +0100 Date: Fri, 30 Jul 2021 14:04:33 +0100 Message-ID: <871r7g2bry.wl-maz@kernel.org> From: Marc Zyngier To: Will Deacon 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 In-Reply-To: <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> <20210730122658.GG23589@willie-the-truck> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: will@kernel.org, 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, vatsa@codeaurora.org, sdonthineni@nvidia.com, james.morse@arm.com, suzuki.poulose@arm.com, alexandru.elisei@arm.com, kernel-team@android.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 30 Jul 2021 13:26:59 +0100, Will Deacon wrote: > > 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. Yup, the srcu_read_unlock() should be moved at the end of this function. It's rather silly as it is currently written... > > > 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. The SRCU read lock should protect us against memslots being removed whilst we're accessing it. In a way, this is no different from taking a page fault. For new memslots, it is a lot less clear. There are multiple levels of locking, more or less documented... It feels like slots_arch_lock is the right tool for this job, but I need to page all that stuff in... M. -- Without deviation from the norm, progress is not possible.