Received: by 2002:a05:7412:2a8a:b0:fc:a2b0:25d7 with SMTP id u10csp373420rdh; Wed, 7 Feb 2024 07:16:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IH2Oou7Q8hAcbet3X5+AsukKTyG4U/QA+S4EJtfqcW6KBVHK7Oy/+bHRBUvYls1WfAxWXW+ X-Received: by 2002:a05:6a20:4393:b0:19c:9c1d:6090 with SMTP id i19-20020a056a20439300b0019c9c1d6090mr5827885pzl.6.1707318968305; Wed, 07 Feb 2024 07:16:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707318968; cv=pass; d=google.com; s=arc-20160816; b=eek9ZHxhMMEEMdF0FUHDbVn8mFasFtSJqyT+ZEzjGF6F/ZSgyrGYbxMJvSTYye9gqV SSE7/0gVI0wFMGTEMcKtZtfIkDt26rEVH9Q2DPL3wkKtJSnrDlRjDAb7IiGp69jtcJEF qbzSYAV/Rp1i6jUfSBchYSxQukRFixdqmOxxKreyNQux8PpA6tT0zz5OLm0YtuJ0o+wl DkytNq82QEcKAfNKtiJ0V0175rvi+6PWrjPFfm2b+pRomXz2xFU+b99TVXZBsFq7VDd9 L9ObtSHFFxdKIRiVN58WqY6+cfApXq05Axu2RznQqwx0w8W8B352ZsSNdgSBa8ZShVg0 28sA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :in-reply-to:date:dkim-signature; bh=C/5FPgGvRtWIxXt/NaMkBCrrVZJi2vGASXviIWBw83Q=; fh=iLvEMY/AJIa1dk2HL7fBNjunVww91P9p52CNPoEajuY=; b=Ly23uzLrSFiqPD8WMzgR6e5h9vQNyBPplQXIDXWoeW7OGZYyS8mCKrlE5AjoBVe6c6 U49bxWLKsjB6KEaa5Jqc5KL0lQh78lUqtRVJc2+pgnXgOUjgcqfh4OQmbdYcA0pO9JaR gqE4K9eguerwPpp9XaxmrqkbaNW39b4DSSQ4IFfmf/UyAXvfRO80q/HUwvA8no++FsgI NVvxf4iAlopl9PbzsZ6ADejNzTRHl/avmpFySVuf1203lgLYYmsK66KYmAq/r9Ua+umi IuM2y3s23YiYnguqeaISEDvoOiLe+JEZCLsfFrnu+3qhfLYWYOr2et7TDkiFmxor8Bfu X4EQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=AtX7nhxl; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-56698-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56698-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=2; AJvYcCUF4UkVrykfQEzOr+n5axwP4ESdDgtiPISdNKaBPgSbM5+rt1qkg+UGIs0kpUJy4qzMNozEnxVbN0FRAeFeQTVByclVFKIsLjXStLfL3A== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id x52-20020a056a000bf400b006dbbae74070si1727223pfu.184.2024.02.07.07.16.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 07:16:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56698-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=AtX7nhxl; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-56698-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56698-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 C30F328387D for ; Wed, 7 Feb 2024 15:10:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E1B287FBB4; Wed, 7 Feb 2024 15:10:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="AtX7nhxl" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 617C97F488 for ; Wed, 7 Feb 2024 15:10:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707318633; cv=none; b=mi114vKRU8/xNtzaq66C71raRv8tIo7ugY3uJ/PI1J1GrN5oZHtj32QYlmDKQq3XyN7geq4lc+jQ4El5m35bk3wEe0/YkU0LdISAoCE5+q8U4sSjWCY+eZAz0ElMW95Jv/UGr+zLQrvix1qC45zARj7X0Q6Ayu1jmfb3kumpS5c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707318633; c=relaxed/simple; bh=TDeuMYw3V5mfviFayWil0sUeiH295xl/tQfWNiFIdFg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=c5cP8crJan6ef7nilO8tm8LT2tSHuZFgPERiyrQf/kbpr3gIJlHzYHKy/4M3Bv/4RGmp470zvGlpWPIc9AeTA01KgI9B7SRZCgiLMenPFa/2dKHZbxww8jAsEUD2uO6L20/6mcYU6386HbrpLNnBOhicPDoriT31AOteivlKPOU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=AtX7nhxl; arc=none smtp.client-ip=209.85.219.202 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=flex--seanjc.bounces.google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc6df2b2d1aso926793276.1 for ; Wed, 07 Feb 2024 07:10:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707318630; x=1707923430; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=C/5FPgGvRtWIxXt/NaMkBCrrVZJi2vGASXviIWBw83Q=; b=AtX7nhxlgibTRw+/Xuk1ltRXz6DAeXR1MOjqdE8mMFF5Q1PrKrmwcQ2E2imBhe5l+E DVVO95MQh6dG2yMwt7utxjtaBVlTlk4qd11EO6K3i+l8CLvR6kdlxt8m6kJSQw9DsS1D EIx8NoYelrredMlJj7KtQDH3JM90e/KNnwpYkUEuKjCsQkv8OzXuHuZ3ZzMIosC3rWKI N5UqY4+VBR5F8oFEn8wVaUa93sIi4LDQnoXlUlVSfCemXIfkCOHriP4SGwLopFs5d0EE /keGIyll82Q24nQQHjsDbdV+4cz2aq3IzBC+Hhxd5rXpbkVy88gzZWC5DQUKVyZ3p928 UcMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707318630; x=1707923430; h=content-transfer-encoding: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=C/5FPgGvRtWIxXt/NaMkBCrrVZJi2vGASXviIWBw83Q=; b=nzxxGd780nM+ZpEx1HF//ZIjgRMzHk+hyhDytcEYlvtPIw6gPfF/zpgNABb7PeaNhY BSLVLp6L+N+ga3SoCFK0nJ0lpAOHxdvw9rGaPB7kS7MMg9AcjY1MJ+3lA3y2CRGrk2OD AMXVv//HabUbqLGpu7glkxaLueOA/q+UKMjh6uKWQlVUI6vh84uruMyG4MPYzLk0ty88 444Y0inzm9K2KWdVPpo1+xAOQg6rb7SA8d9rxyYfDq54tOmDD3Vkgadvw5WAsXkNwxwh fvvtrsTqYBNiMb1m16PUi5l3+LU3+lEwvEXxNjDuRK3Hy4ndQ/mPV5Tc22r4yTr5hFwl yOIg== X-Gm-Message-State: AOJu0YyPN3eFnIbKeQcyypvkV8fg0T+sFP+ZeS2TXGy0DPrxcCjE2EK3 tpqwmYgGrqXyvU48QtE8RbULzqS8TH2mAsq/+QQHM5rpKrsQ7l1Yr2+PnCXdrbzHuIfK3qxTEsH Jug== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:220c:b0:dc2:5456:d9ac with SMTP id dm12-20020a056902220c00b00dc25456d9acmr181054ybb.5.1707318630365; Wed, 07 Feb 2024 07:10:30 -0800 (PST) Date: Wed, 7 Feb 2024 07:10:28 -0800 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240115125707.1183-1-paul@xen.org> <20240115125707.1183-19-paul@xen.org> Message-ID: Subject: Re: [PATCH v12 18/20] KVM: pfncache: check the need for invalidation under read lock first From: Sean Christopherson To: David Woodhouse Cc: Paul Durrant , Paolo Bonzini , Jonathan Corbet , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Shuah Khan , kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Tue, Feb 06, 2024, David Woodhouse wrote: > On Tue, 2024-02-06 at 20:47 -0800, Sean Christopherson wrote: > >=20 > > I'm saying this: > >=20 > > =C2=A0 When processing mmu_notifier invalidations for gpc caches, pre-c= heck for > > =C2=A0 overlap with the invalidation event while holding gpc->lock for = read, and > > =C2=A0 only take gpc->lock for write if the cache needs to be invalidat= ed.=C2=A0 Doing > > =C2=A0 a pre-check without taking gpc->lock for write avoids unnecessar= ily > > =C2=A0 contending the lock for unrelated invalidations, which is very b= eneficial > > =C2=A0 for caches that are heavily used (but rarely subjected to mmu_no= tifier > > =C2=A0 invalidations). > >=20 > > is much friendlier to readers than this: > >=20 > > =C2=A0 Taking a write lock on a pfncache will be disruptive if the cach= e is > > =C2=A0 heavily used (which only requires a read lock). Hence, in the MM= U notifier > > =C2=A0 callback, take read locks on caches to check for a match; only t= aking a > > =C2=A0 write lock to actually perform an invalidation (after a another = check). >=20 > That's a somewhat subjective observation. I actually find the latter to > be far more succinct and obvious. >=20 > Actually... maybe I find yours harder because it isn't actually stating > the situation as I understand it. You said "unrelated invalidation" in > your first email, and "overlap with the invalidation event" in this > one... neither of which makes sense to me because there is no *other* > invalidation here. I am referring to the "mmu_notifier invalidation event". While a particula= r GPC may not be affected by the invalidation, it's entirely possible that a diff= erent GPC and/or some chunk of guest memory does need to be invalidated/zapped. > We're only talking about the MMU notifier gratuitously taking the write It's not "the MMU notifier" though, it's KVM that unnecessarily takes a loc= k. I know I'm being somewhat pedantic, but the distinction does matter. E.g. wi= th guest_memfd, there will be invalidations that get routed through this code,= but that do not originate in the mmu_notifier. And I think it's important to make it clear to readers that an mmu_notifier= really just is a notification from the primary MMU, albeit a notification that com= es with a rather strict contract. > lock on a GPC that it *isn't* going to invalidate (the common case), > and that disrupting users which are trying to take the read lock on > that GPC.