Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2372797rdb; Thu, 21 Sep 2023 17:30:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFE5UeEffCGRK+JNgKul0VejVjbdx7XW1XvIbViAXDTwEcvlwrfTOFZmoKPO+lIrr2KK3nw X-Received: by 2002:a05:6a20:394c:b0:13e:1d49:7249 with SMTP id r12-20020a056a20394c00b0013e1d497249mr6261019pzg.2.1695342640330; Thu, 21 Sep 2023 17:30:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695342640; cv=none; d=google.com; s=arc-20160816; b=sj8BEjvT1C6KhvoLr6f9Mf6kRUD6uMnY6eR1Rm1H+m4em4MNiJbLRSDGuuh1B3VeMO tqOPdvWkg57id+mJP+4IQ7NSYYNAepI4vhoC+/Bpb7R/Z92vDuD2NNH3hDzNQ+BxTn+i 5uhNxPBilc0Xepr610ZXmneBD3/7HewvLiZPFXYuN9sUG2gQTz61jJI1Nn1+jc2wiQ0+ TZyWeWTA6P+MebJqNTG91Kc2IUmBSBO0ZiE9CVmDlUPPnKILhrz3Mv0stv1lZr5kFjFE sS6d7paTdZ87Age+yixuYIMrrr5h/2efQwg/yaFXbqmnEYSyiShPMab+r2h66ol4u1Wq gvuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=wz9DrRdcdVVuAipyFL7+yUJ9r1lHv1bDpxPkFxDk1Ys=; fh=s8Yofl6NjzKOuIWfAaTKi6agDuBgqDcPrLLdgSv9F+s=; b=qzBr3UMh1UgLGA5xLogDr2X+69GuX+s/rMlNZLP7XbUJxMstAN6iLVDUKZ+lrbogws Y/OWajyYJVrjGeI+RIszsMpw4RO5HuxADfOPcH+8DEYxJodmtspQHRJaJiEEiDK7Itd7 LTR0PE0wYrmpAspzBIzyK383yHAihctF17ht7xaGnNmEgKxvHwAj44eJZ5cl+Mc+TRxT M3hL6sf+WGjJ/uvtZ65XWV14/OcnlFbZqXyVB+8ydNjUz7cjAz3CPI3HV/an8hqfiH1m 6XG/n1xaM48c+zea3iUvpOX8Fq5EY8FmqRoUgbu9Rv6wXgE7T6FMdY8/z0l9Q9YTf0p2 NolQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=OJMlhkKR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id s20-20020a632c14000000b00578dff7fccbsi2616888pgs.137.2023.09.21.17.30.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 17:30:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=OJMlhkKR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 611918299929; Thu, 21 Sep 2023 13:48:38 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231890AbjIUUsj (ORCPT + 99 others); Thu, 21 Sep 2023 16:48:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232072AbjIUUsZ (ORCPT ); Thu, 21 Sep 2023 16:48:25 -0400 Received: from mail-oi1-x249.google.com (mail-oi1-x249.google.com [IPv6:2607:f8b0:4864:20::249]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3F0B9280A for ; Thu, 21 Sep 2023 10:48:45 -0700 (PDT) Received: by mail-oi1-x249.google.com with SMTP id 5614622812f47-3adbcfd059aso1744845b6e.0 for ; Thu, 21 Sep 2023 10:48:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695318525; x=1695923325; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=wz9DrRdcdVVuAipyFL7+yUJ9r1lHv1bDpxPkFxDk1Ys=; b=OJMlhkKR1I+UDMSPZvsRWNOqeJK7nBF/NcFbN6EHRR0q3q96Yt/7OaPuxORzqHLYHZ D0Sd4e/Xub912jW0cOlqRYI9uXa8LE1HwJts3KCJ7tSs8DFZQ9M9dl9YOQR5Ekm2Ge1a 0FG6zoptouzK8g07hy/zw15oKBpVY3viWhqCtPwysnjMyoyLHGWv3aM3527hvjUrj+5/ yYP2rpN4mQ1PgEpr9mBq9HZbSUCopa7C0EQ0gIGcVOhJKa0gKGpJ+ab8/iUaw5K45iOj dhoZlVFqjiUe4qVBuXWX30Oxn/JJFuIHRnDLm+7lVyRlTWbdzYyI2yo9zN3dRD3io28N PNIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695318525; x=1695923325; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wz9DrRdcdVVuAipyFL7+yUJ9r1lHv1bDpxPkFxDk1Ys=; b=kZ5ejE7jWaH7uEAU0UHSupXzNVO4L1ZbAsCQv3y0oI+TCC1yu8nixtmf2xwKrqhLjI 73h+p3bzigQVJ2bpfvuVCb2yvCp1/T7FH01BBoi8n0yfm7mPk1CuXTqbPiNaj/G1cMlW 8SywZpFvEZWR9CGb2EHxN7Je69ZtRYCyOoIVW+3uFYlWWYlSICtIoTPTJJhqkXC+Pk61 3RjOQt2jcPPNpiv21SxRthmRJOZSm6vD7zZla5279v8GRykbgT6/fHvXENfJyDAH9+G2 Q6X4hCgcYWl+0mAtOGA/ioJPp9oQf9Jat9sewGjo3wPpG2GVMYYqBgngNOEdoOOVlxVd 8naA== X-Gm-Message-State: AOJu0YzIYpIY8O2aPK19kdoNtoxAJGRq3xAdIe5V1UVl4HPR9cLuCCtB M236U2pmmyb3LL7sheQamjFxy80pRKk= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:1704:b0:d64:f7ec:6d5d with SMTP id by4-20020a056902170400b00d64f7ec6d5dmr84990ybb.10.1695306762523; Thu, 21 Sep 2023 07:32:42 -0700 (PDT) Date: Thu, 21 Sep 2023 14:32:41 +0000 In-Reply-To: Mime-Version: 1.0 References: <20230916003916.2545000-1-seanjc@google.com> <20230916003916.2545000-3-seanjc@google.com> Message-ID: Subject: Re: [PATCH 2/3] KVM: x86/mmu: Take "shared" instead of "as_id" TDP MMU's yield-safe iterator From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Pattara Teerapong , David Stevens , Yiwei Zhang , Paul Hsia Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-8.0 required=5.0 tests=BAYES_00,DATE_IN_PAST_03_06, DKIMWL_WL_MED,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 21 Sep 2023 13:48:38 -0700 (PDT) On Thu, Sep 21, 2023, Paolo Bonzini wrote: > On 9/16/23 02:39, Sean Christopherson wrote: > > Replace the address space ID in for_each_tdp_mmu_root_yield_safe() with a > > shared (vs. exclusive) param, and have the walker iterate over all address > > spaces as all callers want to process all address spaces. Drop the @as_id > > param as well as the manual address space iteration in callers. > > > > Add the @shared param even though the two current callers pass "false" > > unconditionally, as the main reason for refactoring the walker is to > > simplify using it to zap invalid TDP MMU roots, which is done with > > mmu_lock held for read. > > > > Cc: stable@vger.kernel.org > > Signed-off-by: Sean Christopherson > > You konw what, I don't really like the "bool shared" arguments anymore. Yeah, I don't like the "shared" arguments either. Never did, but they are necessary for some paths, and I don't see an obviously better solution. :-/ > For example, neither tdp_mmu_next_root nor kvm_tdp_mmu_put_root need to know > if the lock is taken for read or write; protection is achieved via RCU and > tdp_mmu_pages_lock. It's more self-documenting to remove the argument and > assert that the lock is taken. > > Likewise, the argument is more or less unnecessary in the > for_each_*_tdp_mmu_root_yield_safe() macros. Many users check for the lock > before calling it; and all of them either call small functions that do the > check, or end up calling tdp_mmu_set_spte_atomic() and > tdp_mmu_iter_set_spte(), so the per-iteration checks are also overkill. Agreed. > It may be useful to a few assertions to make up for the lost check before > the first execution of the body of for_each_*_tdp_mmu_root_yield_safe(), but > even this is more for documentation reasons than to catch actual bugs. I think it's more than sufficient, arguably even better, to document which paths *require* mmu_lock be held for read vs. write, and which paths work with either. > I'll send a v2. Can we do a cleanup of the @shared arguments on top? I would like to keep the diff reasonably small to minimize the v6.1 backport.