From patchwork Fri Oct 27 18:21:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13438939 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50A00C25B70 for ; Fri, 27 Oct 2023 18:22:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 97BA780014; Fri, 27 Oct 2023 14:22:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9061B8000C; Fri, 27 Oct 2023 14:22:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 70A3080014; Fri, 27 Oct 2023 14:22:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 50E208000C for ; Fri, 27 Oct 2023 14:22:52 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E7AE3809E5 for ; Fri, 27 Oct 2023 18:22:51 +0000 (UTC) X-FDA: 81392062542.02.3303C99 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf29.hostedemail.com (Postfix) with ESMTP id 261A3120002 for ; Fri, 27 Oct 2023 18:22:49 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=H3PwEBhf; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf29.hostedemail.com: domain of 3-f87ZQYKCBoI40D926EE6B4.2ECB8DKN-CCAL02A.EH6@flex--seanjc.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3-f87ZQYKCBoI40D926EE6B4.2ECB8DKN-CCAL02A.EH6@flex--seanjc.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698430970; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=MfwjFnr1wNHEBMs743caMc0qlRTo5HMEnN08vNH/OXQ=; b=D+DMM/m6/QZbMb2AwWa83pJRPXy3BC/HkFx0jJMg2tGHYePc3wF6Hq9dgMcEP6s5Ixwy03 b6ZGvtG916f5rcvBu1PYmVdnuujNpJEiCCyVPBgnFwdYoo1zUD+e/q133eSEfVxgh0Tmho nsSe9I78pQnM0NiD3e45VoazK6X1m04= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=H3PwEBhf; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf29.hostedemail.com: domain of 3-f87ZQYKCBoI40D926EE6B4.2ECB8DKN-CCAL02A.EH6@flex--seanjc.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3-f87ZQYKCBoI40D926EE6B4.2ECB8DKN-CCAL02A.EH6@flex--seanjc.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698430970; a=rsa-sha256; cv=none; b=te3g6djuJbRcHNbxRAo7+tIfGO4pcMwf2ctRZvzEB62qwL7j74U6XWYnGGW3S2iHdIoZ+V jbm+zL4Y4IwODLxADumRQ0brtY1YaC2dzyto8xOosuyl5S6tvyKTgpEVkHNUrLugmOrdsq tm1nELlJrIsiTzJ/PzMR9l+RWSjtGNs= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-5a7b9e83b70so22724417b3.0 for ; Fri, 27 Oct 2023 11:22:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698430969; x=1699035769; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=MfwjFnr1wNHEBMs743caMc0qlRTo5HMEnN08vNH/OXQ=; b=H3PwEBhfr0C275u3UgFNg/ZSi6zPgcf5TwGvrYzQ/jY8mPmMpig5D/L2ErLBeDjq8F A7rMQMASx9QdD1GtPc3rQGKy8y7VN3UTjPjC2mfEtz/H1iaT+TROlT/PWGJa2ZgO5ag1 8wiiuiXdmKreeraEdDpjTG6v8gSr0imorgwscCf//xk3jBnj90DNts5RfAR5/BPGiBGI wXVtoqeyibM3sxW1upBNwkWb2ZNfOE0pGVWh7/5SaDHSJEPMhpEqbODQPq5MuRBy5Dyu nZffDxJoSn35FdbCp3gTsSjj5snGfu6P+8X84RWDIMv4rxQ+lVRCX0FUnhx3LBmXh8Ss R8Kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698430969; x=1699035769; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=MfwjFnr1wNHEBMs743caMc0qlRTo5HMEnN08vNH/OXQ=; b=g9y4/JgnZueQvjI4dUeFwA9NomF3+SjiQ4EcjhSdFN6BopLDutSjV5qpAUwbuumd61 vw32GKsq68xH0DKmbTNvbotVbzBo0+dbqS2zBACPeSRat0+DYkZdUnmHicNgdY5uwiIB VALUxouD3xttNjPk81uEFYZRn6hVP/4EXYHhukZ88OAmOf9P+JyXY2w7Nb45JKso4j5J ow/PhM2krKD9QsqPEEkFxh2B0D6q0d0fDlUjDtBMfWOBJfLp6cJxx4J/OwtntZI5ZQvk YJGMyN0HFZDqMCd4tgiEWOycqIrlE929Tbsn1Hkbd2fS+KVBMD4xSYcx4XhFz6ahVbuA IxwA== X-Gm-Message-State: AOJu0YypodrstE4+mgPj77qOFLJ7sQ0rkZ/jdnFdZqgfOKrUoNb9xHnE l2f4P+PZtQOY3HtGSc80IdGBnMTLV8k= X-Google-Smtp-Source: AGHT+IHtw6A7NuD1zDZw/j7xBoNpID5PTLHCLxD7YeudY/tlgoiYGQdJN9iuOebDV/xY0oQ2kV5qeLUK06Q= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a0d:ca0f:0:b0:59b:e663:23b0 with SMTP id m15-20020a0dca0f000000b0059be66323b0mr102868ywd.4.1698430969394; Fri, 27 Oct 2023 11:22:49 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 27 Oct 2023 11:21:54 -0700 In-Reply-To: <20231027182217.3615211-1-seanjc@google.com> Mime-Version: 1.0 References: <20231027182217.3615211-1-seanjc@google.com> X-Mailer: git-send-email 2.42.0.820.g83a721a137-goog Message-ID: <20231027182217.3615211-13-seanjc@google.com> Subject: [PATCH v13 12/35] KVM: Prepare for handling only shared mappings in mmu_notifier events From: Sean Christopherson To: Paolo Bonzini , Marc Zyngier , Oliver Upton , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Sean Christopherson , Alexander Viro , Christian Brauner , "Matthew Wilcox (Oracle)" , Andrew Morton Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Xiaoyao Li , Xu Yilun , Chao Peng , Fuad Tabba , Jarkko Sakkinen , Anish Moorthy , David Matlack , Yu Zhang , Isaku Yamahata , " =?utf-8?q?Micka=C3=ABl_Sala?= =?utf-8?q?=C3=BCn?= " , Vlastimil Babka , Vishal Annapurve , Ackerley Tng , Maciej Szmigiero , David Hildenbrand , Quentin Perret , Michael Roth , Wang , Liam Merwick , Isaku Yamahata , "Kirill A . Shutemov" X-Rspam-User: X-Stat-Signature: xfpxu9xp8eb5xhbt4rk6cn71mowcd1h6 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 261A3120002 X-HE-Tag: 1698430969-203767 X-HE-Meta: U2FsdGVkX18ffyntTm0goyCjP2jVcj+ggm18ao0iWAqgfQBmToWIkpkVjPYSWWpr0+d2dXhv+vN/lVghRGepDTx8o6pkDvzreErqgrh1h281iLZa8D4eeDvLbShULNh/2pYCaWEd9hVf9UsA6cXvPlXMaL3ipPjgh47MiukNozCPsd8MBiGDO0bq5kcN6BsM5B4foooDVL/m11ciujYqXs5YCOpfH9yH91A/6T6CYFxVYaOs/NlvtcAExBCmCIM6phqejv7aFAbohTRu9CGkDWXp7pal9/PuXrq52RIA4vOgM0r2hTrQhRTezJlfYmsYNtPuXDWmHpdJAnhmSKj48hWKrP0sonkuJMYFIGWZfVjb/TmSdi4Hq/eZgzPGMQUM0MIat/nqkBGRZ/i8BVwTJZ7TgKYNNSDt2YrrGVxr8rXfHuyHrq2GisuVXAB6GNW1IwS0fOeBksPFSbfxe0QkVcTp2yjg9lR+uqbQ0Xb0uPuTwDPHTOteGzgGcoTiXE66SjnJZn6heoLCNlwxB17i95hAHlQcafWqWglcD3Zy7hhPuJ2bGpJb2KFKMuD8JRE8w+AiPlI12QFL+ilBms/bju63Q0j7gJW9vg/+f+1WhmjYummXU2fTvlniczV1s4L9RFZBkfm1781qB9KDxmBGw/dXsn3Mg651zcg7YSOmU2VUZug1wrGCvMZ/BIizmqIrdIgThcrecjWq2xbVBu0zcqw4403h1YIKwXjRnxjUnBRJQSQ25ROBHZ4vM4TlVLp4O+Qv1corHjTDP7bL8t7RrNCQpb0cvfiWkf75ON+Ot0KDBF4XhbeKQeRdmvNaxL2UypbOcGzT48OUJ2ibgdQ01sBjTpRbgF8gnvQeE9IFtA0VC89pOGGbibGMUQtRIj7QKkPtQaOenCSx89/ms4p+fcIaoYU/ByyiCNHnASp33qusdqROKZ4cuhjr7TFahfFxeDrTgtnr0WScexvT1/8 b5al1nfV nFvyl/XOrAfbVlCsDz3g2eUAPFKKnzNy9VA5lwiMS67UEUoVww14yvgOFS3i4Iw4n1h36E/iHnWRKeX3ouvi8wgv+OJuWT4tSxhHhPnpWYfVCj6ohFrhAtrKASYTvLqElCsglBUhQUkKux2eVRAtgBPN/wqHEoc1xdS5jm1GphK0shYN+m2oCL6xrQ4ajVVayq410tamc9TqKAMssAiLAC3LcnU0Gzq96M5zIx90/g4qAMqAvHiRa7lWSofnCDQWzW399x7n2t8SCRALckKe3k36hocj9s84G1XKWCg1+a2yFiPl/+zChVseRGlSkvxJ85C9yoSCTe+MsH5F1HgPM43kLRl35dtT031/hrtWY/5RqK3fIYfL3RXiWJtttZo7QQsTzdgGhiU7DTVWYmbEYbwOv/A8dTTgXQ4JSf3nH7wQv/p93v50sH5SaO0qYxqAQFvJSG7k4Z2xc2W1pqqXx3pstD/ErHZqh9+56zMPA7Nihr3pCxJSyRaFMnoz6xkvXbqo5lzAsotSZTbA1bA+QOTRAh/jaQRfIxDANWoGGgjbJB0YGYy5RObZ/pH6sbX7hI6WWRHLpE1p/yBtwufEATJM/OrQlSklpdmywMVcXashKEJzDpTZr390zK+pizflFwOwji5rNOwwiCy1wyYyQZqtZ0Y4/QjJQ6T+T3PpQVOX4HXnS+Ozxk5a6zZnyXfWL3clLQmRS7ldGYV+FompcDq9Ggy6uBA+R78ibgiiXQX1AEEkxbcw94ZihWK9J7rdnXm941OC47Lib5FcOVxYVOHXVVeG/KQ4QoBmVtJVHN/7A9ZR75y+89PMbh6RIudPCMTo9pppCkiZwWFpqNz7i7I7+dUkwJ6not0J9Wz7eCMVYR3yvhpTuLlbwYA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add flags to "struct kvm_gfn_range" to let notifier events target only shared and only private mappings, and write up the existing mmu_notifier events to be shared-only (private memory is never associated with a userspace virtual address, i.e. can't be reached via mmu_notifiers). Add two flags so that KVM can handle the three possibilities (shared, private, and shared+private) without needing something like a tri-state enum. Link: https://lore.kernel.org/all/ZJX0hk+KpQP0KUyB@google.com Signed-off-by: Sean Christopherson --- include/linux/kvm_host.h | 2 ++ virt/kvm/kvm_main.c | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 96aa930536b1..89c1a991a3b8 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -263,6 +263,8 @@ struct kvm_gfn_range { gfn_t start; gfn_t end; union kvm_mmu_notifier_arg arg; + bool only_private; + bool only_shared; bool may_block; }; bool kvm_unmap_gfn_range(struct kvm *kvm, struct kvm_gfn_range *range); diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index cb9376833c18..302ccb87b4c1 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -635,6 +635,13 @@ static __always_inline kvm_mn_ret_t __kvm_handle_hva_range(struct kvm *kvm, * the second or later invocation of the handler). */ gfn_range.arg = range->arg; + + /* + * HVA-based notifications aren't relevant to private + * mappings as they don't have a userspace mapping. + */ + gfn_range.only_private = false; + gfn_range.only_shared = true; gfn_range.may_block = range->may_block; /*