Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp108227lqp; Fri, 12 Apr 2024 11:49:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWWybmzBXRHFo4GRwh7RMd7VPomeIT0KBXpqRFOsu2X/xjA1H35FUn/RzIunPkPbC6mPd3X9yjtqmIxbss8b5pGYfhroZtTrd25xh9Vow== X-Google-Smtp-Source: AGHT+IGvgVq2NvQBDZ+ZF9SDuR/E9u7gXv/VMJlYsxztZSGbnAc8M9McFRscR3dkvhvC1URU690s X-Received: by 2002:a17:90b:e8d:b0:2a2:510f:fa43 with SMTP id fv13-20020a17090b0e8d00b002a2510ffa43mr3126223pjb.32.1712947791954; Fri, 12 Apr 2024 11:49:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712947791; cv=pass; d=google.com; s=arc-20160816; b=ZWB6a+81NKlRDstwAon+DHFbIkc+BhadN9CO6wkO3kK15oJhBcoJz6w3hPgCwy30vi nxzc1HxsHFBPWUcO6RCNyWp8ZIO/M5BCx3JlK1TbPe2igcp9oDagAxBzxiiZZk88FWqE IUdAgD8nhB7ZMq1Pxvd2l7xvsCAQpGq0hV7FRJ1xclNxzJWvmeGQNCGm2+oQMUQ0ZYAo Z7ia2Sr+y+Ry0YGgaYQ8W3Ior1HqSmXx1fqW8hEWt1OarDeUteB+MQk1FPc/bmG87VcC jAiEIKL0Y6pIp4rFXElUHpBjyrZZSFHk64AOBx/F+y1+dKO7Dt/aBP6Q5bkocl954Emg 3ybw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ISLMFGOGyzbAhcth9c+vgcaA14m4ctbEbkD9TmYI1+8=; fh=yP9/9NQ8JOhr5f5lerK2hDh3Sh0WWkYPMLBopZQWVjs=; b=p73XQxAWxtQqLP7I8cF1hiHJ8uZPzj3AfZ2iAAjNNQA5wgSnR/fFuwkhlRlzxxwPu5 aVCNk2gBtPM5GKIzXOFaS6K95r1lZzQMrfbnBR8AVoYp5Zu5/c1f2Nttk8pCBS2pgH1y eiPx0EkU67jSr56mSKKYP8qgvofYeCqRhb5Y2rH1+FmTka8/IlFZXkcnogYW7NrTDXhO bBi3bwQXhih8uTpMxgMoJ6BF74Ze8pUy3/zCFcRNlQRBU2rz+x+3R8bGQGm+ui2GnLjB v2+AA+xJFWOtjUE+uupD/ctT44MyAJ7oQlCWCG2GBOK/OmEfFnPU3Ew5+OjgrvPTth4q 0qOw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=1dGZk9+h; 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-143224-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143224-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id o10-20020a17090a55ca00b002a2a70f148bsi5823950pjm.69.2024.04.12.11.49.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 11:49:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-143224-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=1dGZk9+h; 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-143224-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143224-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 75F25B244AF for ; Fri, 12 Apr 2024 18:45:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1C08B14F9C4; Fri, 12 Apr 2024 18:45:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="1dGZk9+h" Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (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 CA2E314E2C5 for ; Fri, 12 Apr 2024 18:45:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712947541; cv=none; b=LUbUU0OGSU+Tfyk27UtJP4twrkp90Q+V2hxj8MccJQv/4C11/vKZtTDCQfcOKw/w4EZlCwMwdSa1Jv3Mtgc/Mv0YxczlkCjNknZRRpwwhf6r28TjrSP24eTNq3d66/DfqWHe7gUuDKBKLBl3AHIwy7FbvBrEcOGyEM86unLsqNA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712947541; c=relaxed/simple; bh=Mxmh9m8cG1SINwjvCiVceMBEadI/CDBdioZFxVCsP84=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HO8QKs86UY5D52hNA2ChC5JGnvuNemEzM999Od6NFo5D8D3XgrMlcmKxB+Ld3iOz8Efjr1ejja/AEP37P+Z/jLOt6C5kyZZ0cA1hvl8oJ4krpOGpKqls+4DZJ/pILbZRZ43dVhTb36ga8cXHF8+wyTjfyuzpf4Vgqk5eQS/jzUw= 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=1dGZk9+h; arc=none smtp.client-ip=209.85.215.174 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-pg1-f174.google.com with SMTP id 41be03b00d2f7-5dbf7b74402so796709a12.0 for ; Fri, 12 Apr 2024 11:45:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712947539; x=1713552339; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=ISLMFGOGyzbAhcth9c+vgcaA14m4ctbEbkD9TmYI1+8=; b=1dGZk9+h1Q2Q9iaogm/cvA5Gz6mo72i/ro8ANc77ALWCk9pUoomZCV5HtZc3B9gK78 RJJnF3JQEY+ySY7/MUIZcs1FxPGHpw+DmUXC9pv/+7+W2dJXBu01QFHhdQbr8hsaGILT 6bEfrqaZDwY0mgRTjaxhdHWP/m33XO5k3X7ISKx+hEYcvvzOJTNlWk/EJXyJ5IGM4BDP gSM3t5NDjJGirvNAWympm58UnEyz6seuba0uaRW9Li4ZYzsPl1yK99tD97M/ETKM3aqh 4zX74JUJ3xnee0JvOAPmRXPI4OY7FNtyWa7ncsuHS1GKsX567dqXi3btGvG+z7n9YbRr ol0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712947539; x=1713552339; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ISLMFGOGyzbAhcth9c+vgcaA14m4ctbEbkD9TmYI1+8=; b=Zb1oiYRpYtwXtsvxJV/XOK0kQuNS2czItj1EHLoapK0ZMDhpkOASKpq+QtqZIjLhl/ SHReWKWYrvMmoT+SvxuLaX2Y26jTLWXyh5xDINoxD31U8btMUojQUr/gDT9EKJG5++nt JStgYOuXbiRw+9soHhdiF6ABhw/wxyK2aKm6/Gbw5j3xyo7T5+J/+N4T6edeDLs3pfX0 6ZuEijToHGxLcgGJvjvUoiqXg86J7XEz8tuQkOi8B3y5IfJDI4vb3bPE97qpsQ/EYchv qJ3a05g05p6RzTtJBc3irjafF4tePYFxoapr9/JDut3zKO0/1/fzQR/8GNrjvendPujR 8M3g== X-Forwarded-Encrypted: i=1; AJvYcCWwXF3Or7Q0tn5+A96tlJ2VzkRRhBsu7RP3HLRecQTiptFahcqyF+0K8ySgOHwplEqpTTvExujDcqGwfXtaVLAzeZ4Up7eIWsWDnmEl X-Gm-Message-State: AOJu0YyrnDdrEwNdNFgiInfjgjnrBDhc+qEeJsehi6I/wRoDFsnpF/Br lRHoyNwMUdQ0OZxdGKQIvLZgMzBpsLjQDMJhxkpI74udX/8egyE3VP3RiXP06g== X-Received: by 2002:a17:90a:9af:b0:2a5:3e4e:29a0 with SMTP id 44-20020a17090a09af00b002a53e4e29a0mr3344779pjo.6.1712947538843; Fri, 12 Apr 2024 11:45:38 -0700 (PDT) Received: from google.com (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with ESMTPSA id i20-20020a632214000000b005cd835182c5sm3009589pgi.79.2024.04.12.11.45.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 11:45:38 -0700 (PDT) Date: Fri, 12 Apr 2024 11:45:33 -0700 From: David Matlack To: James Houghton Cc: Andrew Morton , Paolo Bonzini , Yu Zhao , Marc Zyngier , Oliver Upton , Sean Christopherson , Jonathan Corbet , James Morse , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Shaoqin Huang , Gavin Shan , Ricardo Koller , Raghavendra Rao Ananta , Ryan Roberts , David Rientjes , Axel Rasmussen , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org Subject: Re: [PATCH v3 1/7] mm: Add a bitmap into mmu_notifier_{clear,test}_young Message-ID: References: <20240401232946.1837665-1-jthoughton@google.com> <20240401232946.1837665-2-jthoughton@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240401232946.1837665-2-jthoughton@google.com> On 2024-04-01 11:29 PM, James Houghton wrote: > The bitmap is provided for secondary MMUs to use if they support it. For > test_young(), after it returns, the bitmap represents the pages that > were young in the interval [start, end). For clear_young, it represents > the pages that we wish the secondary MMU to clear the accessed/young bit > for. > > If a bitmap is not provided, the mmu_notifier_{test,clear}_young() API > should be unchanged except that if young PTEs are found and the > architecture supports passing in a bitmap, instead of returning 1, > MMU_NOTIFIER_YOUNG_FAST is returned. > > This allows MGLRU's look-around logic to work faster, resulting in a 4% > improvement in real workloads[1]. Also introduce MMU_NOTIFIER_YOUNG_FAST > to indicate to main mm that doing look-around is likely to be > beneficial. > > If the secondary MMU doesn't support the bitmap, it must return > an int that contains MMU_NOTIFIER_YOUNG_BITMAP_UNRELIABLE. > > [1]: https://lore.kernel.org/all/20230609005935.42390-1-yuzhao@google.com/ > > Suggested-by: Yu Zhao > Signed-off-by: James Houghton > --- > include/linux/mmu_notifier.h | 93 +++++++++++++++++++++++++++++++++--- > include/trace/events/kvm.h | 13 +++-- > mm/mmu_notifier.c | 20 +++++--- > virt/kvm/kvm_main.c | 19 ++++++-- > 4 files changed, 123 insertions(+), 22 deletions(-) > > diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h > index f349e08a9dfe..daaa9db625d3 100644 > --- a/include/linux/mmu_notifier.h > +++ b/include/linux/mmu_notifier.h > @@ -61,6 +61,10 @@ enum mmu_notifier_event { > > #define MMU_NOTIFIER_RANGE_BLOCKABLE (1 << 0) > > +#define MMU_NOTIFIER_YOUNG (1 << 0) > +#define MMU_NOTIFIER_YOUNG_BITMAP_UNRELIABLE (1 << 1) MMU_NOTIFIER_YOUNG_BITMAP_UNRELIABLE appears to be unused by all callers of test/clear_young(). I would vote to remove it. > +#define MMU_NOTIFIER_YOUNG_FAST (1 << 2) Instead of MMU_NOTIFIER_YOUNG_FAST, how about MMU_NOTIFIER_YOUNG_LOOK_AROUND? i.e. The secondary MMU is returning saying it recommends doing a look-around and passing in a bitmap? That would avoid the whole "what does FAST really mean" confusion. > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > index fb49c2a60200..ca4b1ef9dfc2 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -917,10 +917,15 @@ static int kvm_mmu_notifier_clear_flush_young(struct mmu_notifier *mn, > static int kvm_mmu_notifier_clear_young(struct mmu_notifier *mn, > struct mm_struct *mm, > unsigned long start, > - unsigned long end) > + unsigned long end, > + unsigned long *bitmap) > { > trace_kvm_age_hva(start, end); > > + /* We don't support bitmaps. Don't test or clear anything. */ > + if (bitmap) > + return MMU_NOTIFIER_YOUNG_BITMAP_UNRELIABLE; Wouldn't it be a bug to get a bitmap here? The main MM is only suppost to pass in a bitmap if the secondary MMU returns MMU_NOTIFIER_YOUNG_FAST, which KVM does not do at this point. Put another way, this check seems unneccessary. > + > /* > * Even though we do not flush TLB, this will still adversely > * affect performance on pre-Haswell Intel EPT, where there is > @@ -939,11 +944,17 @@ static int kvm_mmu_notifier_clear_young(struct mmu_notifier *mn, > > static int kvm_mmu_notifier_test_young(struct mmu_notifier *mn, > struct mm_struct *mm, > - unsigned long address) > + unsigned long start, > + unsigned long end, > + unsigned long *bitmap) > { > - trace_kvm_test_age_hva(address); > + trace_kvm_test_age_hva(start, end); > + > + /* We don't support bitmaps. Don't test or clear anything. */ > + if (bitmap) > + return MMU_NOTIFIER_YOUNG_BITMAP_UNRELIABLE; Same thing here.