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 Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72652C433EF for ; Thu, 24 Feb 2022 12:06:44 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id D153F4BFDB; Thu, 24 Feb 2022 07:06:43 -0500 (EST) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@kernel.org Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id J+AuLz0oX4UI; Thu, 24 Feb 2022 07:06:42 -0500 (EST) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 720D14BFF1; Thu, 24 Feb 2022 07:06:42 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 7AE5D4BFD5 for ; Thu, 24 Feb 2022 07:06:41 -0500 (EST) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id h7uG6vhh7cEv for ; Thu, 24 Feb 2022 07:06:39 -0500 (EST) Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id BF98D4BFD4 for ; Thu, 24 Feb 2022 07:06:39 -0500 (EST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 9CF85B82189; Thu, 24 Feb 2022 12:06:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4CC8FC340E9; Thu, 24 Feb 2022 12:06:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1645704396; bh=s5cR5NFzFbdMtdogbsupOZzKCqs7xZOC8kKtfo4aTBY=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=fT6+tn4A1qZIeEOKO3xZnr3xVbNbRguQGlUwGssV01PE0glAWs88+qnen/o1ChD4/ teZtPOicGL/c40Bx2UbU7udt3fExWByFw0ghUeOI0ctVzvNm2NekZ+I1G86RzWNzv+ NA90tnr+VgqelnZ1JePjyYN/py76M9C9hoRoie1CRH/A8+zO/iOMEgX2j7NSdVAgVG s1y5l1K0xXRgfgv7nwdsU8wBjL1yjwvtp/EP/uoPwrqjSNB+vTz1nxf3WJ33gW5bE4 82xc5cJ6dlr2TbyluyfU2ZtBxgYrxAxtRXr0orwwbI9/ei69bSgQQ5+QNu6IDRyMdJ FRLFHOezWPKBw== 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 1nNCtG-00AAhy-2a; Thu, 24 Feb 2022 12:06:34 +0000 Date: Thu, 24 Feb 2022 12:06:33 +0000 Message-ID: <871qzs4gfq.wl-maz@kernel.org> From: Marc Zyngier To: Oliver Upton Subject: Re: [PATCH v3 02/19] KVM: arm64: Create a helper to check if IPA is valid In-Reply-To: <20220223041844.3984439-3-oupton@google.com> References: <20220223041844.3984439-1-oupton@google.com> <20220223041844.3984439-3-oupton@google.com> 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: oupton@google.com, kvmarm@lists.cs.columbia.edu, pbonzini@redhat.com, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, anup@brainfault.org, atishp@atishpatra.org, seanjc@google.com, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, pshier@google.com, reijiw@google.com, ricarkol@google.com, rananta@google.com, jingzhangos@google.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Cc: Wanpeng Li , kvm@vger.kernel.org, Joerg Roedel , Peter Shier , kvm-riscv@lists.infradead.org, Atish Patra , Paolo Bonzini , Vitaly Kuznetsov , kvmarm@lists.cs.columbia.edu, Jim Mattson X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu On Wed, 23 Feb 2022 04:18:27 +0000, Oliver Upton wrote: > > Create a helper that tests if a given IPA fits within the guest's > address space. > > Signed-off-by: Oliver Upton > --- > arch/arm64/include/asm/kvm_mmu.h | 9 +++++++++ > arch/arm64/kvm/vgic/vgic-kvm-device.c | 2 +- > 2 files changed, 10 insertions(+), 1 deletion(-) > > diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h > index 81839e9a8a24..78e8be7ea627 100644 > --- a/arch/arm64/include/asm/kvm_mmu.h > +++ b/arch/arm64/include/asm/kvm_mmu.h > @@ -111,6 +111,7 @@ alternative_cb_end > #else > > #include > +#include I'd rather you avoid that. This sort of linux->asm->linux transitive inclusions always lead to a terrible mess at some point. Which is why we use #defines below. And yes, the pgtable.h inclusion is a bad precedent. > #include > #include > #include > @@ -147,6 +148,14 @@ static __always_inline unsigned long __kern_hyp_va(unsigned long v) > #define kvm_phys_size(kvm) (_AC(1, ULL) << kvm_phys_shift(kvm)) > #define kvm_phys_mask(kvm) (kvm_phys_size(kvm) - _AC(1, ULL)) > > +/* > + * Returns true if the provided IPA exists within the VM's IPA space. > + */ > +static inline bool kvm_ipa_valid(struct kvm *kvm, phys_addr_t guest_ipa) > +{ > + return !(guest_ipa & ~kvm_phys_mask(kvm)); > +} > + I'm all for the helper, but just make it a #define to be consistent with the rest of the code. > #include > #include > > diff --git a/arch/arm64/kvm/vgic/vgic-kvm-device.c b/arch/arm64/kvm/vgic/vgic-kvm-device.c > index c6d52a1fd9c8..e3853a75cb00 100644 > --- a/arch/arm64/kvm/vgic/vgic-kvm-device.c > +++ b/arch/arm64/kvm/vgic/vgic-kvm-device.c > @@ -27,7 +27,7 @@ int vgic_check_iorange(struct kvm *kvm, phys_addr_t ioaddr, > if (addr + size < addr) > return -EINVAL; > > - if (addr & ~kvm_phys_mask(kvm) || addr + size > kvm_phys_size(kvm)) > + if (!kvm_ipa_valid(kvm, addr) || addr + size > kvm_phys_size(kvm)) > return -E2BIG; I think you can pretty much use this helper everywhere something is compared to kvm_phys_size(), and the above becomes: if (!kvm_ipa_valid(kvm, addr) || !kvm_ipa_valid(kvm, addr + size - 1)) Same this goes for the couple of occurrences in arch/arm64/kvm/mmu.c. Thanks, M. -- Without deviation from the norm, progress is not possible. _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm