Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp329054pxm; Wed, 2 Mar 2022 16:31:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJwzOqE3ZyKGrA05hb89NjBvAuBfg5dMG3fDoQURHuG3j+1AqlkdmRxx0yy4cdBbufG+hmQu X-Received: by 2002:a05:6a00:1a09:b0:4e1:67a7:2c87 with SMTP id g9-20020a056a001a0900b004e167a72c87mr35632071pfv.37.1646267504266; Wed, 02 Mar 2022 16:31:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646267504; cv=none; d=google.com; s=arc-20160816; b=bHQY5gY00Ot1eVBMTapKk2bPeGMDuun/swDq3FIhcd3RspjLGOm6fSlhwEuta12oa3 AFThKdhSr7bcVecYRE7h6mZTeNF3jqC4MWvqtG+ZzpiNKsIaQiMPV5lvJU8Lwq/suPlx cpihuNmNvs5EgvEKjFMkGLOJHPQD6GkwNENXl6tscNi5KOiCvDK5pakjEWHsTIKUxRWO WqGveoPcX1dGGfOUg0XB9Pl1x31e8hGMXAXXINY4MPD8Xw+cFPLzOPsKaxVtTSyX5p9q FnEoTnLx9ENq1nPD3AwhP2PoGI3A0XlwZfDnMSIe2+Mha0tGthvu42CxFqaUDyHP+w3e IgFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=g7EzPTbKYLqO23m3ywH5y06sJN6hD3WoKEJqYdmdBo8=; b=QCwjxWMdiwNo9DDVnFJaffd3F7PEgVDkY9f5PpNsF5B8kZXId8/lQK88BHeB6Rxegs HwkQoXacbo+uKDM2+/jRVK2tTd9HPaCX09QqMkHNa44xZZXFaSg/GAycHkXDrXm2HGpq 7Nl0cn2UapM/Z9OQx7Vxer1PPOfixoOgzHJtdyLEjiZPWi+8Ii/JMoKlKcuYZWMSgwT/ blkEz+bDazBKsX+YZWGsx1AVmYBIIsnr3qq1cc6NOPOlISHYBsvK34t1FLvIp/Ilzh9D Tysf8mwsWiL7PYLt23yVUDVZIMQ2BWd/xyLP2+5tILTcyVUsC7MAd8EwfozELwpBqng1 BOpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=a9yHIBRH; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id d3-20020a631d03000000b00364e8398936si455916pgd.640.2022.03.02.16.31.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 16:31:44 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=a9yHIBRH; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D76A922EDF4; Wed, 2 Mar 2022 15:42:13 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233220AbiCBW0m (ORCPT + 99 others); Wed, 2 Mar 2022 17:26:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229660AbiCBW0j (ORCPT ); Wed, 2 Mar 2022 17:26:39 -0500 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E98B4E3C74 for ; Wed, 2 Mar 2022 14:25:54 -0800 (PST) Received: by mail-pl1-x62b.google.com with SMTP id z2so2814050plg.8 for ; Wed, 02 Mar 2022 14:25:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=g7EzPTbKYLqO23m3ywH5y06sJN6hD3WoKEJqYdmdBo8=; b=a9yHIBRHVnkkbeJTPV3c7G5nXhO7+BJASkO0lFCAY8yXyU+/uaBydkqUomDxsuecPC b+DLOTNSKvcGdpbIcWKyXEMs939C8QZvZ67peRNpPBbJc/tWDaIlBFvMn6C4H76PxOpI Tb+o/c/TYtDJYPyfJE+K4jkP72YTPt28V5ipJSdnOI/iSDZI4oT4ENpdNOUkfpx8DarH YkiPc2l4g/2iXH2u7O/wZyJ0SfrGr7PDkS6CL0VgM/O74V3NG8CSPZqdfc7QgsR0f639 vQTihqM4qujlCo0NR3ubWH0Jl2hh5WhNmm3wUj8OglcB0xe51c+ubeRXs7rJCEGTZ+GT K8vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=g7EzPTbKYLqO23m3ywH5y06sJN6hD3WoKEJqYdmdBo8=; b=n3ecxT8W/h+VkiXrwjo1llxRZCSJmQFFGNyPVQtZ42w41TaZvtFus3LkiXO621926l 4p1WRnjPGtR4OLY0s1y9oNVoomYQWoG0qdNaMHIdCt+oyTTqomzOZ+hd8qJaV+Z2VOQw 8SwbFIBeI/sTue4m66lg8Noe9LH3ZO0q6489ZmzToi7z/sTYVUCiTkxydZ8XuUqsFnYS Y/vHtlppFLYku1nBH6JKizsBv90AA4GHJirPn8mr2/9jj88YjTv1vSKWUFw/WQkps7Tb QZt1GNtc5XEYlpXtUhF2ifNVL2dn/yZ0YhVy/Sx6tMwNRPbiaGdjD5hwYDFc0Nsb8IG2 Z3tQ== X-Gm-Message-State: AOAM532rPMNxH+e7Qrhqv2RheBN1ZbIPEVip5rk0gVMSVrBw+Z1LoCbx XPWCzv4f7ufmcgu18OA7vZYHMQ== X-Received: by 2002:a17:902:7109:b0:151:8311:d3b5 with SMTP id a9-20020a170902710900b001518311d3b5mr10511752pll.13.1646259954286; Wed, 02 Mar 2022 14:25:54 -0800 (PST) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id g1-20020a056a000b8100b004f111c21535sm181713pfj.80.2022.03.02.14.25.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 14:25:53 -0800 (PST) Date: Wed, 2 Mar 2022 22:25:50 +0000 From: Sean Christopherson To: Paolo Bonzini Cc: Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , David Hildenbrand , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, David Matlack , Ben Gardon , Mingwei Zhang Subject: Re: [PATCH v3 22/28] KVM: x86/mmu: Zap defunct roots via asynchronous worker Message-ID: References: <20220226001546.360188-1-seanjc@google.com> <20220226001546.360188-23-seanjc@google.com> <442859af-6454-b15e-b2ad-0fc7c4e22909@redhat.com> <94b5c78d-3878-1a6c-ab53-37daf3d6eb9c@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <94b5c78d-3878-1a6c-ab53-37daf3d6eb9c@redhat.com> X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable 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 On Wed, Mar 02, 2022, Paolo Bonzini wrote: > On 3/2/22 21:47, Sean Christopherson wrote: > > On Wed, Mar 02, 2022, Paolo Bonzini wrote: > > > For now let's do it the simple but ugly way. Keeping > > > next_invalidated_root() does not make things worse than the status quo, and > > > further work will be easier to review if it's kept separate from this > > > already-complex work. > > > > Oof, that's not gonna work. My approach here in v3 doesn't work either. I finally > > remembered why I had the dedicated tdp_mmu_defunct_root flag and thus the smp_mb_*() > > dance. > > > > kvm_tdp_mmu_zap_invalidated_roots() assumes that it was gifted a reference to > > _all_ invalid roots by kvm_tdp_mmu_invalidate_all_roots(). This works in the > > current code base only because kvm->slots_lock is held for the entire duration, > > i.e. roots can't become invalid between the end of kvm_tdp_mmu_invalidate_all_roots() > > and the end of kvm_tdp_mmu_zap_invalidated_roots(). > > Yeah, of course that doesn't work if kvm_tdp_mmu_zap_invalidated_roots() > calls kvm_tdp_mmu_put_root() and the worker also does the same > kvm_tdp_mmu_put_root(). > > But, it seems so me that we were so close to something that works and is > elegant with the worker idea. It does avoid the possibility of two "puts", > because the work item is created on the valid->invalid transition. What do > you think of having a separate workqueue for each struct kvm, so that > kvm_tdp_mmu_zap_invalidated_roots() can be replaced with a flush? I definitely like the idea, but I'm getting another feeling of deja vu. Ah, I think the mess I created was zapping via async worker without a dedicated workqueue, and so the flush became very annoying/painful. I have the "dedicated list" idea coded up. If testing looks good, I'll post it as a v3.5 (without your xchg() magic or other kvm_tdp_mmu_put_root() changes). That way we have a less-awful backup (and/or an intermediate step) if the workqueue idea is delayed or doesn't work. Assuming it works, it's much prettier than having a defunct flag. > I can probably do it next Friday. Early-ish warning, I'll be offline March 11th - March 23rd inclusive. FWIW, other than saving me from another painful rebase, there's no urgent need to get this series into 5.18.