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=-11.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 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 E9688C433E9 for ; Thu, 3 Sep 2020 17:58:30 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 ACAE720709 for ; Thu, 3 Sep 2020 17:58:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="tZjyD1Vs"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="OYIl2/io" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ACAE720709 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=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Y5B0QSZQ2hucaCyOYtaojjKHQx8XaOFtm/iu7OHt4zY=; b=tZjyD1VsG6prZ5DYU8mG2RxHN Z6UEWz4CnXoF07wIAN/1F7Szrl3yb9RY85Rf+f7fDn14QgdX7CKukH8vItLi8BcHUMtuVzEXkO51j K5Iq0by7fXBsA1GZdpVWVYJ5nivGSlfR53EJX1aYDBE/dZaDj3REMkdj96w24IfaXIrlb0/JooKTY Ietybvdl2pMxUzYK6DOV9oRnZ5Hs/FBlPBISlzv1p7568mXpWrilbGaYOMMKb5/eEoXDd8+ZQewVr gI21+OeFfs4uBIZ1xL+mjfDhFRe8Hxb14Ptbl2EKTfsxrhEnCKiFZ5iTbj1Af5VHPMoUJ1SndrF/G FSLhduLiw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kDtU0-0004L8-G3; Thu, 03 Sep 2020 17:57:12 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kDtTy-0004KX-2o for linux-arm-kernel@lists.infradead.org; Thu, 03 Sep 2020 17:57:10 +0000 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (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 1B16B20709; Thu, 3 Sep 2020 17:57:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599155828; bh=2XdIHt52yGXUwXroS4penvSseXtOpwUM7768fr+Nxs0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=OYIl2/iooQM9oQC0nlZG9sDIqd/xYwgtOg6VMWOLVBG4LJQzN18kpFAz5sd852tDv NG33WdJFquZEcbGDKCg7hi+/v8nnMY+vsl1pUFPfNaSfswAIS5v34skZcsjyVr76Rb pcUgNYMtgvTMaN7siXy1EFuzPJvLsIQH4el3Jw1A= Date: Thu, 3 Sep 2020 18:57:03 +0100 From: Will Deacon To: Alexandru Elisei Subject: Re: [PATCH v3 09/21] KVM: arm64: Convert unmap_stage2_range() to generic page-table API Message-ID: <20200903175702.GA8078@willie-the-truck> References: <20200825093953.26493-1-will@kernel.org> <20200825093953.26493-10-will@kernel.org> <1f2e88b7-0265-195f-3bd8-4e1d5b8694e3@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1f2e88b7-0265-195f-3bd8-4e1d5b8694e3@arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200903_135710_280802_4F27BAC8 X-CRM114-Status: GOOD ( 27.76 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marc Zyngier , kernel-team@android.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, Catalin Marinas 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 Wed, Sep 02, 2020 at 05:23:08PM +0100, Alexandru Elisei wrote: > On 8/25/20 10:39 AM, Will Deacon wrote: > > Convert unmap_stage2_range() to use kvm_pgtable_stage2_unmap() instead > > of walking the page-table directly. > > > > Cc: Marc Zyngier > > Cc: Quentin Perret > > Signed-off-by: Will Deacon > > --- > > arch/arm64/kvm/mmu.c | 57 +++++++++++++++++++++++++------------------- > > 1 file changed, 32 insertions(+), 25 deletions(-) > > > > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > > index 704b471a48ce..751ce2462765 100644 > > --- a/arch/arm64/kvm/mmu.c > > +++ b/arch/arm64/kvm/mmu.c > > @@ -39,6 +39,33 @@ static bool is_iomap(unsigned long flags) > > return flags & KVM_S2PTE_FLAG_IS_IOMAP; > > } > > > > +/* > > + * Release kvm_mmu_lock periodically if the memory region is large. Otherwise, > > + * we may see kernel panics with CONFIG_DETECT_HUNG_TASK, > > + * CONFIG_LOCKUP_DETECTOR, CONFIG_LOCKDEP. Additionally, holding the lock too > > + * long will also starve other vCPUs. We have to also make sure that the page > > + * tables are not freed while we released the lock. > > + */ > > +#define stage2_apply_range(kvm, addr, end, fn, resched) \ > > +({ \ > > + int ret; \ > > + struct kvm *__kvm = (kvm); \ > > + bool __resched = (resched); \ > > + u64 next, __addr = (addr), __end = (end); \ > > + do { \ > > + struct kvm_pgtable *pgt = __kvm->arch.mmu.pgt; \ > > + if (!pgt) \ > > + break; \ > > I'm 100% sure there's a reason why we've dropped the READ_ONCE, but it still looks > to me like the compiler might decide to optimize by reading pgt once at the start > of the loop and stashing it in a register. Would you mind explaining what I am > missing? The load always happens with the mmu_lock held, so I think it's not a problem because it means that the pointer is stable. spin_lock()/spin_unlock() imply compiler barriers. > > + next = stage2_pgd_addr_end(__kvm, __addr, __end); \ > > + ret = fn(pgt, __addr, next - __addr); \ > > + if (ret) \ > > + break; \ > > + if (__resched && next != __end) \ > > + cond_resched_lock(&__kvm->mmu_lock); \ > > + } while (__addr = next, __addr != __end); \ > > + ret; \ > > +}) > > This seems unusual to me. We have a non-trivial, multiline macro which calls > cond_resched(), has 6 local variables, and is called from exactly one place.I am > curious why we are not open coding the loop in __unmap_stage2_range() or using a > function. It's called from three places. That said, I think it's like this because in an earlier life it was used as an iterator and therefore had to be a macro. I can try moving it into a function instead. Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel