Received: by 2002:a05:7412:2a8a:b0:fc:a2b0:25d7 with SMTP id u10csp86963rdh; Tue, 6 Feb 2024 20:54:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IGd/rbFJotKsbcCj+nwVG4t8AcUFsM/MZpASuQrKarCZco7TJbwH1U0rZnqNVgygbUYIlFS X-Received: by 2002:a05:6402:344a:b0:560:521:31f2 with SMTP id l10-20020a056402344a00b00560052131f2mr3204198edc.2.1707281659300; Tue, 06 Feb 2024 20:54:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707281659; cv=pass; d=google.com; s=arc-20160816; b=gYiOzaTXmgn6PDV/5SR+8LwKhsRDbl6GpYHhSyutqPkFtgHQ4pIKenhDTC6E5AM4/g F7UeUGvAiij26EpZNKr4iBatc4e+Mvxfv/gzyCgaxcXt15Df06eVJ+SLJR3h2zfG75P0 jUy6IR3hyxtE9AW5W3EUKexVb6B4kBAs9XajbySviDAYz6+rOSmp5RLp70rj1wlRBp8U CasTuWO25kYJ0jYWra7xQaQkQ4BYCovwjCkUVwtDN/z5Y2rTcojq0DL+EwBrLAlO6UHT /oQV2R/7jBTsYVixMo18QrHzFGKDSBnKMqPAdWyd0xVogKQBjnWXrv92yU85jtJjf6gO uzLw== 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=hce16hi5r9jaUuXKSD0hh20zF7wxE3dX5YfP7OrTZb4=; fh=A7OEzlMrR/W64Qq/HnPNzU9mEUVvisqmbfJx7pRTQQE=; b=ZLjNxQniGiw4zGqDyjWmUKYkMTHmY5SX6rd6GtaAF9oq68Ysg6h+JzgRnKW1LnBJmD b8xQfr7oyT8dj70U2maQpLEf3q5PiYwgwZtDdPx78c6C11GG5LODhXgk2+riVh2Z7Bm3 MDkhklHTMQoWNu/tFHYNvMPDND3XHGf4y6sSZvwwf/veGEtGJVpn8oA0xxboykDKaUbT 4rozodkn23d7gA8R6kd75HPbIt82zkw2RvSIG8uwHX1puImSP8LkmaVY4uzfq20Mlv9o pL1HrcAuspepNKLNXZvEE0cOmGpGyndnqfUBV2wHLEAwNI97lAccKEju+rSvdrNrZ2Kj XXCA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="gys/lQW8"; 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-55966-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55966-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; AJvYcCWoXD/wx5XD7utOA8fIxFdpKxgzYuJsxahxAvrZ+oHTUoVfKQjK/gIoiLe+KKM7/XEE/fxVVEhxPy8Z8YdCodqox4gs0G9M6zmXb40prg== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id bm27-20020a0564020b1b00b0055f63fd6152si335802edb.602.2024.02.06.20.54.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 20:54:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-55966-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="gys/lQW8"; 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-55966-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-55966-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 140851F26341 for ; Wed, 7 Feb 2024 04:54:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C18B61CD28; Wed, 7 Feb 2024 04:47:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="gys/lQW8" Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (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 3C41A3F9DA for ; Wed, 7 Feb 2024 04:47:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707281251; cv=none; b=TOrhHSpW0tHcu6VJ8FU2Ax/gooqinqaJsaJP6ORcMq93QiVa1nGJT1LCqg5cSl3ybZspRCDrZqIztzs/IgwRaA0e4LnIOeTyuaKEn3MkpYSYT+jMtL7c9n3LHu/T3Mhv9ah03UW+ad78gw9iKXScKdX/BPkaJk5zpZvf6krV1jU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707281251; c=relaxed/simple; bh=zVn982hH7Ke/vzoOh5ZD3uQcFpFgpzxTNq2oZsY6+R8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=pHrw1y/qW35LxDu5kmVsy/utZpOPayOfXm67BOw+95qUvc2tOLDZExNEPBFbsAmnQ0pu6S32nJwspSmvLIVeNFS1ROpeosJjppxRzS3lv7rL+ywrAgyTRBz38rwNexK+tPgRm19FSZeMtG11/UMA7ddfoPlzhn3kWdOq3VCjwao= 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=gys/lQW8; arc=none smtp.client-ip=209.85.210.201 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-pf1-f201.google.com with SMTP id d2e1a72fcca58-6e04e1ac036so310588b3a.3 for ; Tue, 06 Feb 2024 20:47:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707281249; x=1707886049; 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=hce16hi5r9jaUuXKSD0hh20zF7wxE3dX5YfP7OrTZb4=; b=gys/lQW8YfQmrkLJoBp86Eum0xZhgZ+v5OncAqSztvsC5khBy5v2RGB4aUEzFnIgk4 C9HX1U0WsOd45rhXGydJ56F81M3L6267g2cXzqPJSfkofk2natin9TgBUFpQF/w1hYoN ctthTQt58/hAii2J7YVdIXrD10HHIwIQinU2dkB9+BgNA8mdlcn6OaYbNjcmYDb1/6j/ VmFSm7r0U2YWWSmihZLk0sYGHK7nJKgxzJQrGrGPA+xOLWmJtFxBPXnXRKXhPogVWfMW 0SnsdjQ5NAYiSz4DwkiA5ZMtZ3zMdEW0wewtT/MNJyf3oJQxThQ+dtuxYD2QdxxUKfFX dOjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707281249; x=1707886049; 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=hce16hi5r9jaUuXKSD0hh20zF7wxE3dX5YfP7OrTZb4=; b=ZMLrlalDJ4BWNLe21EjBp/KCqjn3jH54YGxauRUTYmMHTZ1m/s6y+PgMVHxWynWHxF iHrtTOl6mQbZjWxfOngChla3oi3PJ42wuhlU/c+YyYp7mFQ52KsA6LTrxTmNQAhvSZB5 H/eNyrQLGSUPXDqnhXxwlG6e3DeopFuh+Vk+gAmaiJDrG4yzgQ/KVWp0MEOJRLGjcuyA LQHU85O1zDWYDPF+xTqAqlW/4eGZ4wl2rBb57+kuffFl9m5AN/Q7ZHLcdbPNRFxpL5zv DqjJy26JBWUWL9CVp8CJLL1OvuvsZAZ4ZdPcQ2912ACiMbCAMqKsW5WPmeCDEGp5bTOe hpkg== X-Gm-Message-State: AOJu0YxEC9rnHil1bVOvl0tyP/FdLIujyrEFHXOvFMVFoALvN0K9IBjk cxA3/Ii0gKbaFhLenUu3DiGoJb36bGzYm7zJKr4jpVxXCXxWzPMeglyoAhjadbCAhIhKG4FH67F FiQ== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:2d8a:b0:6e0:610f:33b3 with SMTP id fb10-20020a056a002d8a00b006e0610f33b3mr98869pfb.1.1707281249550; Tue, 06 Feb 2024 20:47:29 -0800 (PST) Date: Tue, 6 Feb 2024 20:47:27 -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:22 -0800, Sean Christopherson wrote: > > On Mon, Jan 15, 2024, Paul Durrant wrote: > > > From: Paul Durrant > > >=20 > > > Taking a write lock on a pfncache will be disruptive if the cache is > >=20 > > *Unnecessarily* taking a write lock. >=20 > No. Taking a write lock will be disrupting. >=20 > Unnecessarily taking a write lock will be unnecessarily disrupting. >=20 > Taking a write lock on a Thursday will be disrupting on a Thursday. >=20 > But the key is that if the cache is heavily used, the user gets > disrupted. If the invalidation is relevant, then this code is taking gpc->lock for wri= te no matter what. The purpose of the changelog is to explain _why_ a patch adds= value. > > =C2=A0 Please save readers a bit of brain power > > and explain that this is beneificial when there are _unrelated_ invalid= ation. >=20 > I don't understand what you're saying there. Paul's sentence did have > an implicit "...so do that less then", but that didn't take much brain > power to infer. I'm saying this: When processing mmu_notifier invalidations for gpc caches, pre-check for overlap with the invalidation event while holding gpc->lock for read, and only take gpc->lock for write if the cache needs to be invalidated. Doin= g a pre-check without taking gpc->lock for write avoids unnecessarily contending the lock for unrelated invalidations, which is very beneficial for caches that are heavily used (but rarely subjected to mmu_notifier invalidations). is much friendlier to readers than this: Taking a write lock on a pfncache will be disruptive if the cache is heavily used (which only requires a read lock). Hence, in the MMU notifie= r callback, take read locks on caches to check for a match; only taking a write lock to actually perform an invalidation (after a another check). Is it too much hand-holding, and bordering on stating the obvious? Maybe. = But (a) a lot of people that read mailing lists and KVM code are *not* kernel e= xperts, and (b) a changelog is written _once_, and read hundreds if not thousands o= f times. If we can save each reader even a few seconds, then taking an extra minute = or two to write a more verbose changelog is a net win.