Received: by 2002:a05:6500:1b41:b0:1fb:d597:ff75 with SMTP id cz1csp405578lqb; Tue, 4 Jun 2024 15:21:21 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWHEPIQKbRJhT9uDtH2Wbm7CjZG+Fp002cfzgslNtIvnH0rcKzKNDwPHMXmvgl7tFQ9LRCmoWFRHFwTFN6uv7YgaoTtnMqJEKeMVjk7mA== X-Google-Smtp-Source: AGHT+IHw2JVnKtr7WiU98rh2Hb7noPWXXHaLDng2dbn9n1gmf/tgpc0PN9AeWXEJqePmJsSa3aay X-Received: by 2002:a05:6a20:7488:b0:1af:cf12:c7ac with SMTP id adf61e73a8af0-1b2b7002b7emr1240907637.34.1717539681612; Tue, 04 Jun 2024 15:21:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717539681; cv=pass; d=google.com; s=arc-20160816; b=k+HWgyMBP8TJfl5a3Aub5NfoqxoNOgkubMnYbhQkUw5wHi+I7spBIqz5Lss4iNrEaM 9Df/6A+REppZHZj74VLuz2oIJRUQd74ActwW0xMbNjj8nK3x1PHDhE/4qe7PVqOD1e1U rN6I8KHUPEWCKx5VDBITX8SGQrDv/4gArKMfdy17hQckCXU/7kqYgfLYtO4Ad/4FTOkL paOjSY1CuBAsHMdzxEGwJiwFBXWSVUkJFgTVB96MLvUKNdAoHC0W2JAT0tofVIbFfvrq s6EzPByuiHXygCjI3GkvIA8Vh847mHvc10h4FsNDc2FgCjBBQtzgPd5GYSkDA+KudC+3 dhVw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=AIBmj4SOCWbNZTcEJ36wTOG253WABX8+/zZKq57PG38=; fh=X2zIPV7H/VhL2bzuoGAACvmgPp0p8xj71Q9lPnIMTEo=; b=DHe3m+jRFqN94uwObRQ6Lchm7qFvOwCvtC4F4HrJKcLhGR/B6T6oDClAGlcdk+SkrH NebElB2+jnCN8IAVEPPIjDEtWLwdDU6qIXk1wYYrGZ4Q6DcrRBNJS1t/8fo+ApFcyMjO 8oHA4jL5nlt8fQ6nt5QD3e9+xnVjk6/WHCBqdzv08LJlHScboDCFoc74qSas9S+nvcEW UU/vF5HNf67x9xSpn0ogWLTeLJ6LIJHtV7OmJ6HzDWF2j1U8LrAwJREmzLb74R48MZBc 8svv0e0PS7CsLnVW7qwUSLMjYxZkUMzFwU0ymOyYuCvMigQDOF6KQWgqZGOSNkZ3xVhV QiYQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=IA3BDoh4; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-201456-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201456-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d2e1a72fcca58-70242d594cfsi2963893b3a.340.2024.06.04.15.21.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 15:21:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-201456-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=IA3BDoh4; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-201456-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201456-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 73B5D284138 for ; Tue, 4 Jun 2024 22:21:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7CC5014C591; Tue, 4 Jun 2024 22:21:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="IA3BDoh4" Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1B091442FE for ; Tue, 4 Jun 2024 22:20:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717539660; cv=none; b=LiRstSCcN8buFK9d2JH+i3NSVx9XZSd0/WXCdyDSLQd03CUhbkXAj1dvo6SlsaWmYDHJKsWnYFb6hpwHMoN+jwuEYGVHarnNtBJwXMKYgIL5mFTg9QeU29FSv4JkWM5oc8qC4d31LNpvE8kkqJ14hOIsbTOegx16LqvR9xF0zx8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717539660; c=relaxed/simple; bh=PEwtsHuB5I4aiO3jiKouMVnFQZ+bv8RQ/fbI3oGiDcE=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=VMfs3m9KZTVNqRgK1W8MjmmDYZnZoqk6M9CxfVkta72NZCowMFsmp4CLf9HdwSHO1KnUy1HslWzhUVvEGgfv7W+sqoyC/aQeTztOdA4jNc56horryUDzrpRoPErd62Ohb/tmImSk8V8wEgBqwDrzneWVIfYoaGSF7U9cfZIxkfA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=IA3BDoh4; arc=none smtp.client-ip=209.85.160.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-qt1-f173.google.com with SMTP id d75a77b69052e-43dfe020675so137741cf.0 for ; Tue, 04 Jun 2024 15:20:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717539656; x=1718144456; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=AIBmj4SOCWbNZTcEJ36wTOG253WABX8+/zZKq57PG38=; b=IA3BDoh41QbII5/51gETpHN3tQmqumLEBtU03HGvR2buAutTMZLhn2XOS727DURXP9 mm+CkSzoy0MnlwjM25EamvaEuAHEybz+ZzCYaV2uhGkEYEJmlflRkuOvHoh/R9aXdALr AqTX1tPmwiKj6DB0TqVYETU05FduCslg13+jaYxoIw1IiIzgnNpo+ClOkW+4Priy4TZg 7NOv5Mgjm1fO3oaoXKE23V2t4KaowBNbxeDzNuMsdEl8GQuYjl+GxW2rDLPUAZC/UjG6 xbfKdoWJGEnnidbzJ4uKM5j2B4U7XPLmaWaNclFix88oXT5iS9VA6sLZj8SSjoJ4gPfm ZUdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717539656; x=1718144456; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AIBmj4SOCWbNZTcEJ36wTOG253WABX8+/zZKq57PG38=; b=Vg2QwaFCo02PSSeIVSAnJxyVqY4teLWzWAyRzyo2RN3tLIZcSx52YU1Um+7ASUPUj6 dHKqhRQyCfmLWix3K7mzHF0MZsFpamRUuduR9SSG1lYiscsAiQW+6PtTUq9UU3Lt4oKr I1JP4nctxK9cuzxMATuhTHAWXlK+DEUeX7zsQl79kOVp7neDSO8E9HxCDEYR9uLhozJB WpuRbu23O+N8NPJ2aD0C5d9FHgATldNv9wV60yJ2LvFvLhpXNGCVWyBxdCjCAVha4g7j lq3WmDPjxlNN0IL0Mrl1OJpk7RrfLj/zgJa+M6WJqHnm/IApPcH4BUNLKSCIkxzGfwO/ a2Uw== X-Forwarded-Encrypted: i=1; AJvYcCVEkHkZmCBNCbEXK0EBE422tv8+at9NPpQJDiV6iYp/tobtWPbGW6CQzDAtmlgTiq99OCK+Iasp/n+uqlOVQvYDhYo3ZwWBB5oHZwg3 X-Gm-Message-State: AOJu0YzjdgLtlqOhHueAUBwpIAuo0nncfUJxVH1f25jf6CT1SPUaAAeX +IZUwovGfTdUzFy0KOrOYCdBVCiTu448O9LPjgKWUExqacZHbh8oZb02uvBZeBBy8DY5jVqik28 Dl98AHP7/w41B97ok5QSD3M2cxm5ybNk3Fiwx X-Received: by 2002:a05:622a:5a98:b0:43d:dc3b:518c with SMTP id d75a77b69052e-4402ce13c55mr332451cf.11.1717539656344; Tue, 04 Jun 2024 15:20:56 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240529180510.2295118-1-jthoughton@google.com> <20240529180510.2295118-7-jthoughton@google.com> In-Reply-To: From: James Houghton Date: Tue, 4 Jun 2024 15:20:20 -0700 Message-ID: Subject: Re: [PATCH v4 6/7] KVM: arm64: Relax locking for kvm_test_age_gfn and kvm_age_gfn To: Oliver Upton 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, May 31, 2024 at 12:18=E2=80=AFPM 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/pgtabl= e.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 =3D true; > > > > > > /* > > > - * stage2_age_walker() is always called while holding the MMU loc= k for > > > - * write, so this will always succeed. Nonetheless, this delibera= tely > > > - * follows the race detection pattern of the other stage-2 walker= s in > > > - * case the locking mechanics of the MMU notifiers is ever change= d. > > > + * 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 =3D kvm_pgtable_walk(...); > WARN_ON_ONCE(r && r !=3D -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? [1]: https://lore.kernel.org/linux-mm/20240529180510.2295118-6-jthoughton@g= oogle.com/