From patchwork Wed Jul 10 23:42:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Houghton X-Patchwork-Id: 13729883 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9550BC3DA42 for ; Wed, 10 Jul 2024 23:46:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=QcajhSgtnKDY4bKjbf4ZVWmvqiJNI58ACmEJvGd9BEA=; b=v/j4boyqLrQkSHhCJV2G9nVHs0 vIUr5XI4wpmFq6yN4dQvsyiItRnzd3eLN3GSv+p4LnlV1mnUdirQp7M+uzu3tpc4UyTIDd8YoPm0U xz2UKNj0uAEKDbTU8ZnTpzGhpTSj6TA/Ax0uoyfyhqILgiCzYzeucuq4sAYSWq+SkImujuRsgWX86 545o/kz+V5rB/VfI+4eUsMVameakdeOIe5y4YQJHj+FRcWNBseom41UnAfb1OjxlSXqPsZzF4RoVT 0GB3rtkGMizfXY/UddgJ56i7xUsaKL74N75zEmstcgnbZXsayksBOEjY7OVrxblr44CguBXsBkjaq YB65rMig==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sRh1G-0000000C9HP-225x; Wed, 10 Jul 2024 23:46:42 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sRgxY-0000000C7Gs-2Z7S for linux-arm-kernel@lists.infradead.org; Wed, 10 Jul 2024 23:42:55 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-653b4b01872so5683677b3.1 for ; Wed, 10 Jul 2024 16:42:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1720654971; x=1721259771; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=QcajhSgtnKDY4bKjbf4ZVWmvqiJNI58ACmEJvGd9BEA=; b=bvss2ujwTiIlWFczO5c8BDqSBc9mjCQ2a3ZbHCyaIbey3Hbz+zi3JkejcCcDIg34zE erzyvMZZiCXAC+bltFUg9Y+5fPkBzpMwtRRgCXpWwSWMJcDl7z7hQyDUB385qppWVXpN tG3ZM6gvO/H8sBWCg0auBseM8LKxUJk8TfUixvPufVw0idJsbLGJlvRENza6XNPmX+4R K0BMDvAb8FOGJLHf87Bh9+nL7X2oJSUljHrGqK/4xzV28/0O9B8pFyImIbbh/eok0UBA q92vec6nDibNN4o5C8c5VENBiBV7YAgwJsL7tzKk2FUzDj9qlaPZNw8czagGh+/rYNFA ufpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720654971; x=1721259771; h=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=QcajhSgtnKDY4bKjbf4ZVWmvqiJNI58ACmEJvGd9BEA=; b=Y7cCH5u0oHXeYWa4OG/1CQFDYNaHyCb+IR1XgqtmJmqERzbX/gxLRA1AbvM0GXz177 t17WDRo0GPFs3CaDIdOHZXU9hl/e1wS0ORB9yAXQ3XKbk9z8HOR/trpvF8Me6EJnWa7n hUtcC1tzuVxGZvvWOBNou6vwvVlUhuXFHYfV06Zee00EV4Vn9KuJ36VhPTEUjIEHRZcL 2ZMyK6x4yBLu2MSx/fbd2MX0PV/GKHmGBWlVUc1Cw4d4ZXG4Aiy21/PMZZ46CD66YHNE N7OA6K1F/Co8GkAh5KFyiAAKI3Z3fS7T+10rIYatxzplYHH1cPlGbQWA2ZD/1fzam7w8 j39A== X-Forwarded-Encrypted: i=1; AJvYcCU7GpG22cmrLmE6ReOduVg4tZSx2bwmeIseH7RhEU2RhUYAbh18vpg4uMrdPmhADvIAfyTAR4519Zc4G1V4aIAabTIIIVQphU7wwKGl91Px2W0JiAM= X-Gm-Message-State: AOJu0YxGXQKOjJpKzZJY54+v2+fKSUckkLQNR0Oa5iL8YanIdC+sXrQl iCF4ybS9AlN75pM6KLcDb16IYOe7gbgjkzGSwGUgzQK8JJzjiGjtdOKYMcL340yjjoVAYQPZ9ST x9pWuZl7khhujdYGyYQ== X-Google-Smtp-Source: AGHT+IEC/EQtrNezpt+9blgHEpHxd1YhFnUWh0/2vBf3Usnz5Irc0nFTjIjjYgCU/UmvBPArza1QUIUaWp5gpwOj X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:a05:690c:6d0d:b0:61c:89a4:dd5f with SMTP id 00721157ae682-658ebabc90amr1126767b3.0.1720654970940; Wed, 10 Jul 2024 16:42:50 -0700 (PDT) Date: Wed, 10 Jul 2024 23:42:17 +0000 In-Reply-To: <20240710234222.2333120-1-jthoughton@google.com> Mime-Version: 1.0 References: <20240710234222.2333120-1-jthoughton@google.com> X-Mailer: git-send-email 2.45.2.993.g49e7a77208-goog Message-ID: <20240710234222.2333120-14-jthoughton@google.com> Subject: [RFC PATCH 13/18] KVM: Add atomic parameter to __gfn_to_hva_many From: James Houghton To: Paolo Bonzini Cc: Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Sean Christopherson , Shuah Khan , Peter Xu , Axel Rasmussen , David Matlack , James Houghton , kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240710_164252_792361_CC9675C7 X-CRM114-Status: GOOD ( 11.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Atomic translations cannot wait for userspace to resolve a userfault. Add an atomic parameter for later use with KVM Userfault. Signed-off-by: James Houghton --- virt/kvm/kvm_main.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 77eb9f0de02d..4ac018cac704 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -2679,7 +2679,7 @@ static bool memslot_is_readonly(const struct kvm_memory_slot *slot) } static unsigned long __gfn_to_hva_many(const struct kvm_memory_slot *slot, gfn_t gfn, - gfn_t *nr_pages, bool write) + gfn_t *nr_pages, bool write, bool atomic) { if (!slot || slot->flags & KVM_MEMSLOT_INVALID) return KVM_HVA_ERR_BAD; @@ -2699,7 +2699,7 @@ static unsigned long __gfn_to_hva_many(const struct kvm_memory_slot *slot, gfn_t static unsigned long gfn_to_hva_many(struct kvm_memory_slot *slot, gfn_t gfn, gfn_t *nr_pages) { - return __gfn_to_hva_many(slot, gfn, nr_pages, true); + return __gfn_to_hva_many(slot, gfn, nr_pages, true, false); } unsigned long gfn_to_hva_memslot(struct kvm_memory_slot *slot, @@ -2732,7 +2732,7 @@ EXPORT_SYMBOL_GPL(kvm_vcpu_gfn_to_hva); unsigned long gfn_to_hva_memslot_prot(struct kvm_memory_slot *slot, gfn_t gfn, bool *writable) { - unsigned long hva = __gfn_to_hva_many(slot, gfn, NULL, false); + unsigned long hva = __gfn_to_hva_many(slot, gfn, NULL, false, false); if (!kvm_is_error_hva(hva) && writable) *writable = !memslot_is_readonly(slot); @@ -3002,7 +3002,8 @@ kvm_pfn_t __gfn_to_pfn_memslot(const struct kvm_memory_slot *slot, gfn_t gfn, bool atomic, bool interruptible, bool *async, bool write_fault, bool *writable, hva_t *hva) { - unsigned long addr = __gfn_to_hva_many(slot, gfn, NULL, write_fault); + unsigned long addr = __gfn_to_hva_many(slot, gfn, NULL, write_fault, + atomic); if (hva) *hva = addr; @@ -3074,7 +3075,7 @@ int gfn_to_page_many_atomic(struct kvm_memory_slot *slot, gfn_t gfn, unsigned long addr; gfn_t entry = 0; - addr = gfn_to_hva_many(slot, gfn, &entry); + addr = __gfn_to_hva_many(slot, gfn, &entry, true, true); if (kvm_is_error_hva(addr)) return -1;