Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp1473103pxu; Thu, 8 Oct 2020 12:19:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzIaI504tyINNPAf2nofOrr56oBnU5wP5Vv4YUqj2frKk39aIPdXZId7d7DDR9/8xGhr9O6 X-Received: by 2002:a05:6402:21c5:: with SMTP id bi5mr10914559edb.380.1602184779844; Thu, 08 Oct 2020 12:19:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602184779; cv=none; d=google.com; s=arc-20160816; b=FIxbk0JaXKPCRM1lIt8L4gyvN/ii0UHcpmvVmAI0QLZeJ/LoNQ3Uvb8M+t2FBBsxgt OAgWtiaytYSd79kVhg3GEW8w6vmCEfnpbSlk8V3yr5qmC7U75/305x92Ht1/43X2iJdz X7Xij5rd2gaDxsc1OIDPBLvWWFCDJGfnr5wIehO02PFPuSfnVs416LsJTQaaPS9yAnHX oiwgl2hO2ejf7hneu0BG0Zluy2LdW9sLVRbeqbI9kYHRdRdwC/4yArXMFOf+PSFtxVME orBeQytBh8VpRKNBL3ppt7IFJkA0BNawflk65Fs5u6j+uWNn5Uu7bCoPr5leqy/6QxvF Pnbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=RrkOdAbBDCwyeOQ37z5tV7CnkLENGAjGaGO/schUabQ=; b=T1yM8JXwuVUSGLW2MmWvVEytj+Mea38flh70R6MZEz5wSLmvVw2aHsg3DGl4eQxGu/ Zf4wkZPpsZUrHGH6WFF1lJ1PwlaJfUkIbKKkIsoisn0uvzPdmGlJJmfkMaCMuxIjGk92 q8fJucnxyQplrCwDWSWv/+QwFLqmo23GnrWPKN3e9Rt8+/leqzgfOsRSJdFMUGN47Lce DR6emQQtKifbz4TGam2COQqk6ocKu6rCxe0Icfe+zwKn6LpTYedsFcEGvS/Xck7uWsO2 3ePpVT6V7k34CHN8EM0QHUNGwmz8/skfubPFBR7J2CnjDZvqCaTBhi0ZEmg0+/Xzrhth XxOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=KOwuXgfs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m2si3995637eds.31.2020.10.08.12.19.16; Thu, 08 Oct 2020 12:19:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=KOwuXgfs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728898AbgJHS1u (ORCPT + 99 others); Thu, 8 Oct 2020 14:27:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725874AbgJHS1u (ORCPT ); Thu, 8 Oct 2020 14:27:50 -0400 Received: from mail-il1-x142.google.com (mail-il1-x142.google.com [IPv6:2607:f8b0:4864:20::142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19B9DC061755 for ; Thu, 8 Oct 2020 11:27:50 -0700 (PDT) Received: by mail-il1-x142.google.com with SMTP id r10so1826328ilm.11 for ; Thu, 08 Oct 2020 11:27:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=RrkOdAbBDCwyeOQ37z5tV7CnkLENGAjGaGO/schUabQ=; b=KOwuXgfsy9d3hZ9ebY1MDbA+SQZ34Ep/hpkIyi8xd/Dzs9rEKt+5vx2AiS6+Cqohrf WUu1wEzLRxNjDKUUKrGAiu8Sh6LunX42uuGSGKthYgpZLrbUp9a6XlrUQZHp4R3dyZSG A8QT+Bjdc9CK8oYU7MkpW/4899D7lD3plf1FxnSFhUgoUIRNOa1wb9O+Ul3y+g3MWXYi MoV9lwPLXmhoKVDd6m4Ps/XTbjYdaenWSmXkncPd6DwJ5P8Z7U+gh+cojH0Uaad3+QjD uPUNlh3k7E6bB2LtRrjm+l5Bu0HNLzZSeb0ch/kEnd/YjUlnMBeR8pd79dGcCj+WLQmD OeYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=RrkOdAbBDCwyeOQ37z5tV7CnkLENGAjGaGO/schUabQ=; b=fC3+RJ2nyI2bG1UAJQYoTV9gqqGSt1RRyOQyInmRtX+lNzU8s/PzcEJdLtNcha+375 EYbwh+VEgTKshdfxVx/cTtdVWQ+LwYA+2ykQVau2jb9UscJTBugTN7IFIvV+ckHNP1q8 Kz+JwcitefCVyOUqGHOGM2iCTTVPNMG/LKmHgWh1y7ydb8spbSdqLgBT37cKkLbz0WKy qBsrsowxH8O8pqTqBnLRA09JRUxBHafPHb61/sFfU5vvEc2raEwlB5yACNofnBhNjIts OGaAeYlrIkIuEp4P3Uw1reZhaTrzoQ65qrim6SC8d6xmgT1RpFuRpnGnKCnkFYb5ngAs SjhA== X-Gm-Message-State: AOAM531g9c63yneUu1bRWsb8iHZWFY474dNvMs28tbiUB2RiykwSDyeM Gk2cy8D/w8y2TV9kflfQr2WlVSCEWD/+bmyhq4cZQQ== X-Received: by 2002:a92:7914:: with SMTP id u20mr7656969ilc.203.1602181668922; Thu, 08 Oct 2020 11:27:48 -0700 (PDT) MIME-Version: 1.0 References: <20200925212302.3979661-1-bgardon@google.com> <20200925212302.3979661-18-bgardon@google.com> <6990180c-f99c-3f1d-ef6a-57e37a9999d2@redhat.com> In-Reply-To: <6990180c-f99c-3f1d-ef6a-57e37a9999d2@redhat.com> From: Ben Gardon Date: Thu, 8 Oct 2020 11:27:37 -0700 Message-ID: Subject: Re: [PATCH 17/22] kvm: mmu: Support dirty logging for the TDP MMU To: Paolo Bonzini Cc: LKML , kvm , Cannon Matthews , Peter Xu , Sean Christopherson , Peter Shier , Peter Feiner , Junaid Shahid , Jim Mattson , Yulei Zhang , Wanpeng Li , Vitaly Kuznetsov , Xiao Guangrong Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 25, 2020 at 6:04 PM Paolo Bonzini wrote: > > On 25/09/20 23:22, Ben Gardon wrote: > > start_level, KVM_MAX_HUGEPAGE_LEVEL, false); > > + if (kvm->arch.tdp_mmu_enabled) > > + flush = kvm_tdp_mmu_wrprot_slot(kvm, memslot, false) || flush; > > spin_unlock(&kvm->mmu_lock); > > > > In fact you can just pass down the end-level KVM_MAX_HUGEPAGE_LEVEL or > PGLEVEL_4K here to kvm_tdp_mmu_wrprot_slot and from there to > wrprot_gfn_range. That makes sense. My only worry there is the added complexity of error handling values besides PG_LEVEL_2M and PG_LEVEL_4K. Since there are only two callers, I don't think that will be too much of a problem though. I don't think KVM_MAX_HUGEPAGE_LEVEL would actually be a good value to pass in as I don't think that would write protect 2M mappings. KVM_MAX_HUGEPAGE_LEVEL is defined as PG_LEVEL_1G, or 3. > > > > > + /* > > + * Take a reference on the root so that it cannot be freed if > > + * this thread releases the MMU lock and yields in this loop. > > + */ > > + get_tdp_mmu_root(kvm, root); > > + > > + spte_set = wrprot_gfn_range(kvm, root, slot->base_gfn, > > + slot->base_gfn + slot->npages, skip_4k) || > > + spte_set; > > + > > + put_tdp_mmu_root(kvm, root); > > > Generalyl using "|=" is the more common idiom in mmu.c. I changed to this in response to some feedback on the RFC, about mixing bitwise ops and bools, but I like the |= syntax more as well. > > > +static bool clear_dirty_gfn_range(struct kvm *kvm, struct kvm_mmu_page *root, > > + gfn_t start, gfn_t end) > > ... > > + __handle_changed_spte(kvm, as_id, iter.gfn, iter.old_spte, > > + new_spte, iter.level); > > + handle_changed_spte_acc_track(iter.old_spte, new_spte, > > + iter.level); > > Is it worth not calling handle_changed_spte? handle_changed_spte_dlog > obviously will never fire but duplicating the code is a bit ugly. > > I guess this patch is the first one that really gives the "feeling" of > what the data structures look like. The main difference with the shadow > MMU is that you have the tdp_iter instead of the callback-based code of > slot_handle_level_range, but otherwise it's not hard to follow one if > you know the other. Reorganizing the code so that mmu.c is little more > than a wrapper around the two will help as well in this respect. > > Paolo >