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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DFCF1C77B7A for ; Tue, 30 May 2023 19:37:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 54382280002; Tue, 30 May 2023 15:37:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4F2B3280001; Tue, 30 May 2023 15:37:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 392F7280002; Tue, 30 May 2023 15:37:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 2A8E7280001 for ; Tue, 30 May 2023 15:37:42 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 046BD1401BB for ; Tue, 30 May 2023 19:37:41 +0000 (UTC) X-FDA: 80847931164.28.50F98DF Received: from out-28.mta0.migadu.com (out-28.mta0.migadu.com [91.218.175.28]) by imf11.hostedemail.com (Postfix) with ESMTP id 7323C4001F for ; Tue, 30 May 2023 19:37:38 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=oTgfsm6Y; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf11.hostedemail.com: domain of oliver.upton@linux.dev designates 91.218.175.28 as permitted sender) smtp.mailfrom=oliver.upton@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685475458; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=xJBcu8ATCUO1aDY2yQ8vOVcCThAxEWqTiihzn189BcI=; b=8cQkm+JiyGRYKtVUstQUuLC7jusUL8OxfzmD/c7ihl1yjH79AYY1sZEoQTzCat653IUe5O Ej/Cz4Md2GVC8Xo4qsm5DYzX82HeuSqYowdaEr6jkE8ZwBQhlDH4BGy8sKGzeQXGgFOFSb tGOb9oHP4FkN2TmkRRCkWMrBiTMht30= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=oTgfsm6Y; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf11.hostedemail.com: domain of oliver.upton@linux.dev designates 91.218.175.28 as permitted sender) smtp.mailfrom=oliver.upton@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685475458; a=rsa-sha256; cv=none; b=3zOUPQbomNmGHlaCFsmtQKbSJxrklV6g7Tg72t+1AwzMpNhGmej/+SCJODYPXrhWj2JpAo vNzM66NqCJsI1LOb9Ls0l8eQPx7D21eXkQ725UXW4Z/eLiym+8XM/t3SmxJdOtSxhX9LB9 i/uOzNIG+ju/r1GqSMn2ZpvtsVF45YE= Date: Tue, 30 May 2023 19:37:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1685475455; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xJBcu8ATCUO1aDY2yQ8vOVcCThAxEWqTiihzn189BcI=; b=oTgfsm6Y7m0cHeGsa3KJXNWXMuNSlm0sfaQCoEPDjFj6jxNxzseINRPUWevletZvuYk83p +kFUfwmLUYdIL6pvdibsqLd2oceBrIf/xJKHf7O+W7xiGADvFsQD0goq381G/kYiPU+lqt jv2kELueVaqLNY647oTCnG+i/dK3+OY= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Yu Zhao Cc: Andrew Morton , Paolo Bonzini , Alistair Popple , Anup Patel , Ben Gardon , Borislav Petkov , Catalin Marinas , Chao Peng , Christophe Leroy , Dave Hansen , Fabiano Rosas , Gaosheng Cui , Gavin Shan , "H. Peter Anvin" , Ingo Molnar , James Morse , "Jason A. Donenfeld" , Jason Gunthorpe , Jonathan Corbet , Marc Zyngier , Masami Hiramatsu , Michael Ellerman , Michael Larabel , Mike Rapoport , Nicholas Piggin , Paul Mackerras , Peter Xu , Sean Christopherson , Steven Rostedt , Suzuki K Poulose , Thomas Gleixner , Thomas Huth , Will Deacon , Zenghui Yu , kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, linux-trace-kernel@vger.kernel.org, x86@kernel.org, linux-mm@google.com Subject: Re: [PATCH mm-unstable v2 04/10] kvm/arm64: make stage2 page tables RCU safe Message-ID: References: <20230526234435.662652-1-yuzhao@google.com> <20230526234435.662652-5-yuzhao@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 7323C4001F X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 1nq9eiswsspk4riaagy1wpdw1tkzkm1k X-HE-Tag: 1685475458-954748 X-HE-Meta: U2FsdGVkX1/ZULHI4Q5jkkrJia0Bkty4KhMhgpvW4y7RflVvX+ByOKwn0C8n49KLU03UPchFWHsy0i3SHOGMR0GbE8yldh1fUTfQ6jx/xV9DhY8ct/ln98hhkXCwvhdWfBQQ5iVC67QTxGfSEIdbUNAJEuQfuhW5y6mz3upNAlK9NaYQ/WW+XIlFqnBEvfBI4ikCQ+gZv/qzfuNxxhDINAXpX0XyrEwTZTlrLdBWYqDFMp8ujQ2Gj6bD0Mk6WS8ZwVi34N++FARtcpaS40sQdvJ0MisRTHmY0iA5v3sbjKjN7exw0XfenyukYZdZJDo0bztl4MIY4iqorgsJEjm6bE3CoLKjRgtSfpmSBAUtReueOvnsPJsBcUtjSjnR9AB+WdWfLp5KQmohn1MmFidObJ7fqMPxXygBJaAg+spPFHk3JjAUXHhs3WLXVItLIbO00CW/YOfQ0v0HnPZDsO/pmWBwtWDRXf7GncV7yHQumpmMm1+yZwreJPjnfxai2jNmwmm8PytxxLcyoMUe49yXfFKA5HImYmDE1Uu4IiEu9yp6uD88gaTRiH+tBAOjKMhVMVKDkd3ti7veboH7WcjFHuI6Paqg/hfDsG2Qve9OxZVf2L4KPxRcHU+P4oI2X39DLYOV1LPoesb0C1Zg954MdVzczY18qOcvkeW0xdRiRx4AxJTPhS2MBoB/gILIVSyNnL+U1Kj2dQqY6IiKTsN9iLxY7ERWHN+F0aQSrwC/MsmN+4M02ux80veGN+iXSO4qrLrrZAtk4dxKwslfDvXEZyA34tmpVSBgS5BJ+bG/f/HM+opDHMKdfW2AHmW+IYrpMbQFBC86mECU0bXwrMPTQikubV4Ww/9AWQCTi6lxtEITttgNG9SQ2oJNIwzh9hV0i7k4ESNpUd8qoLPTQGiEiTPJ67RXN7olJUiv/d0XCwP9tpCCVDAonW9VNgGWc44FlZO+tS+24hdmUVQAbDK ylFwAFtC 04rMuZdSS1IOux6OPTZqCS0Ls7fIH0MFswpX/sITibrJ10/pKnjgcOTXzPkwUTzUuiEKnASm3BzfoYAQzNRq+cfjlpt9KraXr0ZfH2rinM4XzjJxez4uFFk1JdnC+aeDY270rJl4ANlMsMFSS4NpfKzGsMA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hi Yu, On Sat, May 27, 2023 at 02:13:07PM -0600, Yu Zhao wrote: > On Sat, May 27, 2023 at 12:08 PM Oliver Upton wrote: > > diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c > > index 3d61bd3e591d..bfbebdcb4ef0 100644 > > --- a/arch/arm64/kvm/hyp/pgtable.c > > +++ b/arch/arm64/kvm/hyp/pgtable.c > > @@ -1019,7 +1019,7 @@ static int stage2_unmap_walker(const struct kvm_pgtable_visit_ctx *ctx, > > kvm_granule_size(ctx->level)); > > > > if (childp) > > - mm_ops->put_page(childp); > > + mm_ops->free_removed_table(childp, ctx->level); > > Thanks, Oliver. > > A couple of things I haven't had the chance to verify -- I'm hoping > you could help clarify: > 1. For unmapping, with free_removed_table(), wouldn't we have to look > into the table we know it's empty unnecessarily? As it is currently implemented, yes. But, there's potential to fast-path the implementation by checking page_count() before starting the walk. > 2. For remapping and unmapping, how does free_removed_table() put the > final refcnt on the table passed in? (Previously we had > put_page(childp) in stage2_map_walk_table_post(). So I'm assuming we'd > have to do something equivalent with free_removed_table().) Heh, that's a bug, and an embarrassing one at that! Sent out a fix for that, since it would appear we leak memory on table->block transitions. PTAL if you have a chance. https://lore.kernel.org/all/20230530193213.1663411-1-oliver.upton@linux.dev/ -- Thanks, Oliver