Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp1222175rdb; Fri, 9 Feb 2024 14:29:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IEDZenUoQGIAI5qMXig65txpB4/5d76pofEaSQTfKhitO+JuyDg7qUUBqGvBkxlwRADZZ5v X-Received: by 2002:a05:620a:31aa:b0:785:bb46:860b with SMTP id bi42-20020a05620a31aa00b00785bb46860bmr632970qkb.50.1707517756053; Fri, 09 Feb 2024 14:29:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707517756; cv=pass; d=google.com; s=arc-20160816; b=KuWbH2XY1tShW+ZOwNzm92aHmWxsBUdm3zCfrfZs2Qc/J0WHtAS4nyba/5ZIFdQ0Cj Dl+TJLYHzelXZod89ycjZU3BCgYkn7dpevIkkgWezzswfAIRfasCc+YkMkdRIOHPSnoj wcEjBoricqFkNRtx+VZOAi7yVFfIJ9iVYQHra333ooBLHMRKHDp6zoaNoIMq6r7tFAT+ hrTC8h3kDoxlP6tG5CRLE2D4s2aMoqDwjZXHx48+U4qV/uM8gpXGnEJPMNXZba8dZZ3Q R3i+fuK4EDcS+5DB++E1XUHlZsYdniN4VRiCmjy7m7HD6bsEBY8T/x3u1xwLNZgsXH0n u6GA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:reply-to:dkim-signature; bh=H5hQFyPpf+rydxjBfMUUkTUJgr64hFiwgdcvFQinuS0=; fh=oSyOVGn/uDIIfNlG6eofs8ES4cr4voyYmCy6ftOrFas=; b=SAvLeKVWXq6KDVdlSUEN1jet66aEOPcvSoWBvv2twhvjq8s+ITmJDVJoO2j3VbAKmb memGukqPVnrcx3brNO4Dg5WqkOloMRexR1OULGNF+ZFChl+4FUltt2Qw45rTQh5wbgen b5mNoKrJMSt2niIrgIO+YNJpTnWWAg9vOhbkHfxyWmM8sTASARVh1yVNKBdOw9PT2c5l QSKBRf+8miTAiqNKRPLbYTqDsH3cv8uJbKoojrLmGaOPInXMcQ6Y+3+ExWd3/DwJaq7w nm3lbN8V6C6iRXxLvpXQsjDALfKW27mTWvZT8uZmSGivFF+3yvihzwLk5M1J5QTKp69W 3u+g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=SIscm1Td; 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-60104-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60104-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; AJvYcCWEwF8Gf1TQWlwEcST1h79Ej/7SA2W9hfzMnV1x+jpOICxbkVqH2RXYDJTs2Zd9xevZXCDJJIIcGPP4HsaPkf4Qi9oQWYnc1j7qAgKSaw== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id pj4-20020a05620a1d8400b00785a962bff0si468769qkn.348.2024.02.09.14.29.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 14:29:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60104-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=SIscm1Td; 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-60104-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60104-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id CBAA01C229E2 for ; Fri, 9 Feb 2024 22:29:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E14FF364D9; Fri, 9 Feb 2024 22:29:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="SIscm1Td" Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.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 96FF22E3E4 for ; Fri, 9 Feb 2024 22:29:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707517743; cv=none; b=nQi+zgAi4vKHckp3QEmrCIiC/f8rqunSgtZLxzV67u+et0qU9yHspZj46QZhOgtJcRHGk1AQLD7MCpltfbWYZ8xYhWxynJH2uVHGOpThKOrcBLlDHLswuXJMqVg7IoRZ3NLHT8zUIdTOcUun4b8RBWrQVjjrolVpMtbo/BdZZeE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707517743; c=relaxed/simple; bh=fIqYvORhxAkyZm48va/2ujkvGA7C8gveY8KxKZlfit8=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=C9dcoiuI9sIkUNnH4nzQvL+SwwveoERyrN2XsnuSyti3tL2ZTR5Nj8//9RbZ+z31Z8Jy92yoUEUDCV/+vlifiY9HK9dPqSXB/za0/vPeogUGouGvx/hywIJs1Lu5AJQsOYAq1UfvjxwwDaKfPDba+tkX3/n25rU90jyOCV/ki00= 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=SIscm1Td; arc=none smtp.client-ip=209.85.215.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-pg1-f202.google.com with SMTP id 41be03b00d2f7-5c670f70a37so1466765a12.2 for ; Fri, 09 Feb 2024 14:29:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707517741; x=1708122541; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:reply-to:from:to:cc :subject:date:message-id:reply-to; bh=H5hQFyPpf+rydxjBfMUUkTUJgr64hFiwgdcvFQinuS0=; b=SIscm1Tdv48XiEjz2aULMyi6MQ2rnjaJt5Fwnz4t1rR2ImKXv1n3e/fvvp62YQr79b 0mLDKp1cJ8wilJVvw3JnI0V2Whdwai95C/Wzv/+qTkjtCFN0dBDqcdPv2ltLMJnMSUlw qJtNzqknyiVBq2hlElFG+aMUJZVeNiCrSBahIp++bADTzPs2R+36tSW1HQTJedLWK4+u oQbctEz9n7rJwrUW/y9/0dkbEBDEPH4/FGeynSggChs29A12dqT+RUxOQrX536SoWIPM bRazaiSeqGXMODYPwEC3fQpSvU67iZkem4e8wR0l0j0Ie+qSceiYz/piiIw+HVd1/kTQ 3f6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707517741; x=1708122541; h=cc:to:from:subject:message-id:mime-version:date:reply-to :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=H5hQFyPpf+rydxjBfMUUkTUJgr64hFiwgdcvFQinuS0=; b=B1SY4BN6StV8R91B+s1DJZF90msZ5jtRohGNzajqYRvfzPS4vzDwtME+fzzlDHQCFd pZ3SRwVqrgn+qtqke/sYdUef1RUWrbNl7AYH9oooOq8v/FlEW0sKygn9oq3BnvNId7EN Ut2iiQN03mmlAAT1N+XwDmICDxMP67q4OhiPm5VrVcWrUAFpLI54N7ggqFjHbhCV37Mw f9mjlTONMvIbhP9nfRVNDOn60kyfzm5rCAYYVklB6av+4xZkMWyPWmL1ht2bRbxyqgxa R1L/6dMVn1iQCxtugNVyXX/m2xjgnC00isHZX7S0TwpyApVBAP2KBagy7SZK7A6wLtNj NhRA== X-Gm-Message-State: AOJu0Yxw4XT9YnbAJek38nyASs52KiQdh2276J11/12kigG7W/03RAL1 /uxm7375yeig45LMSI3jAjrwjVO0p+FbLFCyv1DkrFIbe47+/U23zRzPWjXrJHLDIra1arovbNu xYA== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a65:6d07:0:b0:5dc:5111:d8b1 with SMTP id bf7-20020a656d07000000b005dc5111d8b1mr936pgb.5.1707517740545; Fri, 09 Feb 2024 14:29:00 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 9 Feb 2024 14:28:54 -0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Message-ID: <20240209222858.396696-1-seanjc@google.com> Subject: [PATCH v4 0/4] KVM: x86/mmu: Pre-check for mmu_notifier retry From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yan Zhao , Friedrich Weber , Kai Huang , Yuan Yao , Xu Yilun , Yu Zhang , Chao Peng , Fuad Tabba , Michael Roth , Isaku Yamahata , David Matlack Content-Type: text/plain; charset="UTF-8" Retry page faults without acquiring mmu_lock, and potentially even without resolving a pfn, if the gfn is covered by an active invalidation. This avoids resource and lock contention, which can be especially beneficial for preemptible kernels as KVM can get stuck bouncing mmu_lock between a vCPU and the invalidation task the vCPU is waiting on to finish. v4: - Pre-check for retry before resolving the pfn, too. [Yan] - Add a patch to fix a private/shared vs. memslot validity check priority inversion bug. - Refactor kvm_faultin_pfn() to clean up the handling of noslot faults. v3: - https://lkml.kernel.org/r/20240203003518.387220-1-seanjc%40google.com - Release the pfn, i.e. put the struct page reference if one was held, as the caller doesn't expect to get a reference on "failure". [Yuan] - Fix a typo in the comment. v2: - Introduce a dedicated helper and collapse to a single patch (because adding an unused helper would be quite silly). - Add a comment to explain the "unsafe" check in kvm_faultin_pfn(). [Kai] - Add Kai's Ack. v1: https://lore.kernel.org/all/20230825020733.2849862-1-seanjc@google.com Sean Christopherson (4): KVM: x86/mmu: Retry fault before acquiring mmu_lock if mapping is changing KVM: x86/mmu: Move private vs. shared check above slot validity checks KVM: x86/mmu: Move slot checks from __kvm_faultin_pfn() to kvm_faultin_pfn() KVM: x86/mmu: Handle no-slot faults at the beginning of kvm_faultin_pfn() arch/x86/kvm/mmu/mmu.c | 134 ++++++++++++++++++++++---------- arch/x86/kvm/mmu/mmu_internal.h | 5 +- include/linux/kvm_host.h | 26 +++++++ 3 files changed, 122 insertions(+), 43 deletions(-) base-commit: 60eedcfceda9db46f1b333e5e1aa9359793f04fb -- 2.43.0.687.g38aa6559b0-goog