From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB2F6C6377D for ; Thu, 22 Jul 2021 18:06:31 +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 6B31960271 for ; Thu, 22 Jul 2021 18:06:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6B31960271 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@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:MIME-Version:References:In-Reply-To: Subject:Cc:To:From:Message-ID:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=uX1PuqPVeZzLAqd6zwBV0ztMBn1QloHlpD2zXsHefHk=; b=VPC2Uq3hzS3bFn LhE7RacmGdxZXl7nVTWCi/npXhmOjmEr5q1URTumzdcVLJvmTNUnO7zxKPaJ2FudpHov6Qe1H+Rfu 1sX9EkRJrztwbMYsTS6KcW4qa6K471Xz7WWJ+eDDseylLtpwTa/yW8okLmQI0yLEgNPQkmceFx+QG 9aEd8prPb82Fdk4XHQr8FpvhX9HPN1X9GmLEymOzaj5B5OVWoeY9oN8ylX8C+i86bbSh/Lufpwbmi /0aZ0oR8KyMPyLLbp5SBcU6QE5qTEyjTbhvWC6AWQA5GoRbiN15uu5sXH16psEoXFkErs+YRVgbXR PR97N/Cp3F+yuIyldjpg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m6d4E-002O1y-Dk; Thu, 22 Jul 2021 18:05:06 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m6d4A-002O1V-7t for linux-arm-kernel@lists.infradead.org; Thu, 22 Jul 2021 18:05:03 +0000 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 F2B0D61380; Thu, 22 Jul 2021 18:05:01 +0000 (UTC) Received: from sofa.misterjones.org ([185.219.108.64] helo=wait-a-minute.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 1m6d48-000Kxq-3W; Thu, 22 Jul 2021 19:05:00 +0100 Date: Thu, 22 Jul 2021 19:04:59 +0100 Message-ID: <87wnpi1ayc.wl-maz@kernel.org> From: Marc Zyngier To: Quentin Perret Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, will@kernel.org, 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: References: <20210715163159.1480168-1-maz@kernel.org> <20210715163159.1480168-5-maz@kernel.org> <87wnpl86sz.wl-maz@kernel.org> 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") X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: qperret@google.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, will@kernel.org, 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210722_110502_364642_DD3FC5C0 X-CRM114-Status: GOOD ( 30.39 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, 20 Jul 2021 16:49:45 +0100, Quentin Perret wrote: > > On Tuesday 20 Jul 2021 at 14:15:56 (+0100), Marc Zyngier wrote: > > On Tue, 20 Jul 2021 12:13:20 +0100, > > Quentin Perret wrote: > > > > > > On Thursday 15 Jul 2021 at 17:31:47 (+0100), Marc Zyngier wrote: > > > > +struct s2_walk_data { > > > > + kvm_pte_t pteval; > > > > + u32 level; > > > > +}; > > > > + > > > > +static int s2_walker(u64 addr, u64 end, u32 level, kvm_pte_t *ptep, > > > > + enum kvm_pgtable_walk_flags flag, void * const arg) > > > > +{ > > > > + struct s2_walk_data *data = arg; > > > > + > > > > + data->level = level; > > > > + data->pteval = *ptep; > > > > + return 0; > > > > +} > > > > + > > > > +/* Assumes mmu_lock taken */ > > > > +static bool __check_ioguard_page(struct kvm_vcpu *vcpu, gpa_t ipa) > > > > +{ > > > > + struct s2_walk_data data; > > > > + struct kvm_pgtable_walker walker = { > > > > + .cb = s2_walker, > > > > + .flags = KVM_PGTABLE_WALK_LEAF, > > > > + .arg = &data, > > > > + }; > > > > + > > > > + kvm_pgtable_walk(vcpu->arch.hw_mmu->pgt, ALIGN_DOWN(ipa, PAGE_SIZE), > > > > + PAGE_SIZE, &walker); > > > > + > > > > + /* Must be a PAGE_SIZE mapping with our annotation */ > > > > + return (BIT(ARM64_HW_PGTABLE_LEVEL_SHIFT(data.level)) == PAGE_SIZE && > > > > + data.pteval == MMIO_NOTE); > > > > > > Nit: you could do this check in the walker directly and check the return > > > value of kvm_pgtable_walk() instead. That would allow to get rid of > > > struct s2_walk_data. > > > > > > Also, though the compiler might be able to optimize, maybe simplify the > > > level check to level == (KVM_PGTABLE_MAX_LEVELS - 1)? > > > > Yup, all good points. I guess I could do the same in my other series > > that parses the userspace PT to extract the level. > > Well, actually, let me take that back. I think something like you have > would be useful, but in pgtable.c directly and re-usable for stage-1 and > stage-2 walks. Maybe something like the below (totally untested)? > > I could use such a walker in several places as well in the memory > ownership series: > > - following the idea of [1], I could remove the > kvm_pgtable_stage2_find_range() function entirely; > > - [2] defines 2 custom walkers that do nothing but walk host stage-2 > and hyp stage-1 page-tables to check permissions and such -- they > could be removed/re-implemented easily as well. > > And you seem to need something similar here, so clearly there is a need. > WDYT? So FWIW, I've now pushed out an updated series for the THP changes[1], and you will find a similar patch at the base of the branch. Please have a look and let me know what you think! Thanks, M. [1] https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git/log/?h=kvm-arm64/mmu/mapping-levels -- Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel