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 5BCFAC25B78 for ; Tue, 4 Jun 2024 23:00:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D13096B0099; Tue, 4 Jun 2024 19:00:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CC2796B009A; Tue, 4 Jun 2024 19:00:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B62D56B009B; Tue, 4 Jun 2024 19:00:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 997B46B0099 for ; Tue, 4 Jun 2024 19:00:45 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 4BE93A23E3 for ; Tue, 4 Jun 2024 23:00:45 +0000 (UTC) X-FDA: 82194727650.20.B866B78 Received: from out-180.mta1.migadu.com (out-180.mta1.migadu.com [95.215.58.180]) by imf13.hostedemail.com (Postfix) with ESMTP id 587A520007 for ; Tue, 4 Jun 2024 23:00:41 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="Y9kw/6fC"; spf=pass (imf13.hostedemail.com: domain of oliver.upton@linux.dev designates 95.215.58.180 as permitted sender) smtp.mailfrom=oliver.upton@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717542041; 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=+MGPWWPfczYg0bV6msWVM8wo7iUe4hq2RoxquwpyNXc=; b=wmfgeygydgXyoRmr9qBRuSMUzCfVM99MzUTcAq1cPHr0tYWDssGX4ohKcuenNsWdDcRjx5 kN1vbINDyeq+Fb57DpoCGpF8Dsqqxt0344MbcuFmvPCdBPmBj6maZd1hBgWQP8XxVWxi69 5FGQ1kb2SzALB5aY62jR2a26feVkcPc= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="Y9kw/6fC"; spf=pass (imf13.hostedemail.com: domain of oliver.upton@linux.dev designates 95.215.58.180 as permitted sender) smtp.mailfrom=oliver.upton@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717542041; a=rsa-sha256; cv=none; b=G9D/95+25+Cev0I1eKY/0dvlrhc8T38qId9CjDV6dDNpieQA69owMBhwStpGuQ11wKCX4k fiv+5MwFtXE2vlb6YMghxGcdjOtjKKxH4Mc6tWPPdC4HpJIsrNwKhW/K6+I8LWCMoC7TIN J2aCQOgH286RC6amyOVftz/iWAyXqac= X-Envelope-To: jthoughton@google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1717542038; 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=+MGPWWPfczYg0bV6msWVM8wo7iUe4hq2RoxquwpyNXc=; b=Y9kw/6fCw7WeofkUSeTV2BTDMr5jngNUCtFMMUMXtMQwQZ57KMcePca1DBVS/t4qEWis16 iF4e3V2COwO/t2Yct7KRRLkVhD5NRIOHTq7i/FQgEBT9QWzcLz+QujFnkzpcYe5jZDxDJW +mCbFXXZogKs/7ZLafe//WQoP8h37Tw= X-Envelope-To: akpm@linux-foundation.org X-Envelope-To: pbonzini@redhat.com X-Envelope-To: aou@eecs.berkeley.edu X-Envelope-To: ankita@nvidia.com X-Envelope-To: anup@brainfault.org X-Envelope-To: atishp@atishpatra.org X-Envelope-To: axelrasmussen@google.com X-Envelope-To: maobibo@loongson.cn X-Envelope-To: catalin.marinas@arm.com X-Envelope-To: dmatlack@google.com X-Envelope-To: rientjes@google.com X-Envelope-To: chenhuacai@kernel.org X-Envelope-To: james.morse@arm.com X-Envelope-To: corbet@lwn.net X-Envelope-To: maz@kernel.org X-Envelope-To: mpe@ellerman.id.au X-Envelope-To: npiggin@gmail.com X-Envelope-To: palmer@dabbelt.com X-Envelope-To: paul.walmsley@sifive.com X-Envelope-To: rananta@google.com X-Envelope-To: ryan.roberts@arm.com X-Envelope-To: seanjc@google.com X-Envelope-To: shahuang@redhat.com X-Envelope-To: shuah@kernel.org X-Envelope-To: suzuki.poulose@arm.com X-Envelope-To: zhaotianrui@loongson.cn X-Envelope-To: will@kernel.org X-Envelope-To: yuzhao@google.com X-Envelope-To: yuzenghui@huawei.com X-Envelope-To: kvm-riscv@lists.infradead.org X-Envelope-To: kvm@vger.kernel.org X-Envelope-To: kvmarm@lists.linux.dev X-Envelope-To: linux-arm-kernel@lists.infradead.org X-Envelope-To: linux-doc@vger.kernel.org X-Envelope-To: linux-kernel@vger.kernel.org X-Envelope-To: linux-kselftest@vger.kernel.org X-Envelope-To: linux-mips@vger.kernel.org X-Envelope-To: linux-mm@kvack.org X-Envelope-To: linux-riscv@lists.infradead.org X-Envelope-To: linuxppc-dev@lists.ozlabs.org X-Envelope-To: loongarch@lists.linux.dev Date: Tue, 4 Jun 2024 23:00:28 +0000 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: James Houghton Cc: Andrew Morton , Paolo Bonzini , Albert Ou , Ankit Agrawal , Anup Patel , Atish Patra , Axel Rasmussen , Bibo Mao , Catalin Marinas , David Matlack , David Rientjes , Huacai Chen , James Morse , Jonathan Corbet , Marc Zyngier , Michael Ellerman , Nicholas Piggin , Palmer Dabbelt , Paul Walmsley , Raghavendra Rao Ananta , Ryan Roberts , Sean Christopherson , Shaoqin Huang , Shuah Khan , Suzuki K Poulose , Tianrui Zhao , Will Deacon , Yu Zhao , Zenghui Yu , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mips@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, loongarch@lists.linux.dev Subject: Re: [PATCH v4 6/7] KVM: arm64: Relax locking for kvm_test_age_gfn and kvm_age_gfn Message-ID: References: <20240529180510.2295118-1-jthoughton@google.com> <20240529180510.2295118-7-jthoughton@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-Server: rspam05 X-Rspamd-Queue-Id: 587A520007 X-Stat-Signature: o79d6onqf4e165zr8eudw8hke6di8jpn X-Rspam-User: X-HE-Tag: 1717542041-25911 X-HE-Meta: U2FsdGVkX1+W48nESfopLADkXB34LyrI/mnDgmwfXtT6XNIWWgMyRuEBr/Ju+9g1tUrQ8ts8RywGZmMUBzrrBroU1J0WfPhNlzq2gdzYQvYwivlyBPuUrl+IxGcpeMJRQFFjCAD8ntF0DwBSa7/vEnAFY9hm/TagEzp39IicfCfjmyNMBaNICT5RQzJVMnj/Bn6jWjD3B0OfDR+wfyn5ROgrC6TKW4iUd2IMwackr6GASHFYq/H2cnssdHqvC/IgGR1NPRneqDOp9Awkt5PeWQjxufTwqEU4XzUlp6oVZWYXIsD+xYE7WglzAHwFhwSFCepfc0yy0GG1kw9peQiYCinypbwwbhueLxXJLfGdWxcDAvLoJ/2yfw3ZvqO4R3Dk8e+OnfcXCZ7SLjPzXKm0N3660veoyeBNBjFvFhiEE8WjNSzmi8oF22eDaKhIOEuwkGEvxmb3afU1x1ffcQ1z2ljDYDK2euggerJ8/GVet/noTBGb4gJuGC59Vq/12ATVZK0qwq7hShqvyvgQHtaKKc3zEpwwACkCXH9ND/nuAiLIBiUkcLe6QKe/rz/o+bPwkdi+aAF9KNOu2Mlbl/SmL5p4LrJdT8nCA0DnMEBKGIv1RZllkQJzk9NAMGRdXT+lI5fzVWY9sp6NvLFQ0KyTuRg/aHcAJBkJRBVniNEEhWFZiExZF6sLROadCgQSOzncl/nz+C5S1xIiL7Alq2MLLC2/2ohmRmmCM1GjsM227JChcwY1q4+TP5gJ0tLcLasmCronSmYl8hg7ZBzutccLMJNh0wnYhXi52qNnc0se6j9xDiudkawtzmmYCz5ziOgj8BvR5Gma2gFPFUgr+MA211s9PGOsr6GRq/8fdy8WPjnLHW0vPt8AEHSGVeC5x1wRiptsDf0NzdMpFwhTld7GVsj0/3QVB5+DM1rwcj1wrsHJxbUji2KKPARPAKMnHKopdShdjmDecxYhSqnauU0 ZOPRfkYI w8dyzUzfTONpOW5zrAv5pRbJF5NtVxiGwPLcdAzJkL61Y9isqgZwFsWkEMD0oya0ZW5BQI+OBRdBYl13mxXqblAGqkW/6DhOPs1ZHq8yAu2fuG6OpOtg0HbmOvD8JwYv8ZrdRxDjXfG3gQB3gpk3YMXixNNkBGHwryJYa 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: List-Subscribe: List-Unsubscribe: On Tue, Jun 04, 2024 at 03:20:20PM -0700, James Houghton wrote: > On Fri, May 31, 2024 at 12:18 PM Oliver Upton wrote: > > > > On Fri, May 31, 2024 at 12:11:33PM -0700, Oliver Upton wrote: > > > On Wed, May 29, 2024 at 06:05:09PM +0000, James Houghton wrote: > > > > > > [...] > > > > > > > diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c > > > > index 9e2bbee77491..eabb07c66a07 100644 > > > > --- a/arch/arm64/kvm/hyp/pgtable.c > > > > +++ b/arch/arm64/kvm/hyp/pgtable.c > > > > @@ -1319,10 +1319,8 @@ static int stage2_age_walker(const struct kvm_pgtable_visit_ctx *ctx, > > > > data->young = true; > > > > > > > > /* > > > > - * stage2_age_walker() is always called while holding the MMU lock for > > > > - * write, so this will always succeed. Nonetheless, this deliberately > > > > - * follows the race detection pattern of the other stage-2 walkers in > > > > - * case the locking mechanics of the MMU notifiers is ever changed. > > > > + * This walk may not be exclusive; the PTE is permitted to change > > > > + * from under us. > > > > */ > > > > if (data->mkold && !stage2_try_set_pte(ctx, new)) > > > > return -EAGAIN; > > > > > > It is probably worth mentioning that if there was a race to update the > > > PTE then the GFN is most likely young, so failing to clear AF probably > > > isn't even consequential. > > Thanks Oliver. > > > > > Oh, and the WARN_ON() in kvm_pgtable_stage2_test_clear_young() is bogus > > now. Maybe demote it to: > > > > r = kvm_pgtable_walk(...); > > WARN_ON_ONCE(r && r != -EAGAIN); > > Oh, indeed, thank you. Just to make sure -- does it make sense to > retry the cmpxchg if it fails? For example, the way I have it now for > x86[1], we retry the cmpxchg if the spte is still a leaf, otherwise we > move on to the next one having done nothing. Does something like that > make sense for arm64? At least for arm64 I do not see a need for retry. The only possible races are: - A stage-2 fault handler establishing / adjusting the mapping for the GFN. If the guest is directly accessing the GFN in question, what's the point of wiping out AF? Even when returning -EAGAIN we've already primed stage2_age_data::young, so we report the correct state back to the primary MMU. - Another kvm_age_gfn() trying to age the same GFN. I haven't even looked to see if this is possible from the primary MMU POV, but in theory one of the calls will win the race and clear AF. Given Yu's concerns about making pending writers wait, we should take every opportunity to bail on the walk. -- Thanks, Oliver