From patchwork Wed Jul 10 23:42:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Houghton X-Patchwork-Id: 13729875 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 4A3BAC3DA41 for ; Wed, 10 Jul 2024 23:44:42 +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=d8Rmzp/FnvTnt3i+tgLuvGyYDZdc9771iECvmROSKp8=; b=Nr9CTnSrSEnD3uz+zRmcA3Gub7 1NH3nUAJqw0i4u8zJ3yRnyqULYfZuQyNGwIeTkaNXg9AOio0FgmrTmgBmQEYpYVXGDf/V8Lak6BX7 ousQvNLX6UFpspBS+DdHJLDwgG18wYUGq42X6NDsKomrNvAcbF4QBaJa8GMv91dhokttFxvRIXox3 DCx6AsKvJGht2PuKZF03spXipz1+KWPJ7WhUcTbuwqPh5P2bu/COiKzvbuV7pG/yRuuNJUfzDsVVW QftBuzpI82s0kxAfrDXakqlcM73xhMS0g03As6bln3WvIwKVpUPAAENGWErfLV/SUl5VeaOLGrsHs PDt1sHvg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sRgzA-0000000C88w-1meS; Wed, 10 Jul 2024 23:44:32 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sRgxQ-0000000C7AH-2VyT for linux-arm-kernel@lists.infradead.org; Wed, 10 Jul 2024 23:42:46 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-e02b7adfb95so493874276.2 for ; Wed, 10 Jul 2024 16:42:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1720654963; x=1721259763; 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=d8Rmzp/FnvTnt3i+tgLuvGyYDZdc9771iECvmROSKp8=; b=Mni6drhQumZe175IOiQX8ttzYIR+YDAM9mNqAfXFiOHmjVzbxjQQp13eshBex8yhe0 QSDecFia1Uu7bh16Jbr/mz6VMZ+jUfye/q82f+NvlnLiY9305cV1HGP0CEOjqkUuOkvb 9bq0XPSlRMJ3QMJY9QAD3KJQSXMrjj6aO6gE9itu225XeZAU6voF3Kma9UX/073/AG5r GcPTtclTZjSEhxzoydyy9J9Y+HqZRhmDx/hG1xENNSG89EtGGzhoLrDeVtcWReacCLtc JfIc6VqmR3fPvf8uygm9P44IB9UEEVfhCMrweCAoYhIQfFBLXoA6TBMq+Lrink45xLTT pr7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720654963; x=1721259763; 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=d8Rmzp/FnvTnt3i+tgLuvGyYDZdc9771iECvmROSKp8=; b=LgIuJ7riOGCZoYnLOrHAd4u1n/07jOL0ij2u1mspLY/KSShHVckMutbb7HeXVYwkNP VjUqt2f/2bvVZE1MBJPNulAt8yYl1M+zqBhztzawz6J0tqBtif1UTSw0s40a6kzObGzb KPfXJh8szDt/sWgscwWouDVH2sJNQDWCOxfoRYprEYDsGB/ZYaSfNQo4qcGw3F/Jauez EAtzWSzcqtRcGEyZF0zc1GHw6fzyaohXvGJvwSh1IwGJfeBu1xObRa2UHY3LZGpRTg2+ /sHQigrdNpyrthO4/TPfF3E54HEfSr0ZJTTM0TZxJR2Kz7lH+hqGuvLFefWOzAAsj7kp /6Aw== X-Forwarded-Encrypted: i=1; AJvYcCXv+rwgoQtynRRvXJ8IeWHD4KgS5r2J2UOTkAyby25M8J9G0C/AbI9OLfgOaVw1iWpwT4xsOmhx2M/dO3n7jJw7rxy9cBnhb7ZDVclr0E3KPDsj4p0= X-Gm-Message-State: AOJu0YztZzer4ONL07/97jX7Z5fnkVg0wqF3ZjgUfPXOiDi36zwTB+iZ CGLh6vckL2N/yc/4F7T0JCEnPvk7WZ1q1hLYjM9iEVXLgMpsQLQy5y1hIPXyqlMLZki+RusPq2c 36ltwmVuLIq0B/85N6Q== X-Google-Smtp-Source: AGHT+IGzfu/is15/zbZN55ThZYoCmQ5oYPE0p+29NB0c/bvGkmqxURl5E0ogcz1hwkdaxZ/C24+OiRdX8VZRICmx X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:a05:6902:2101:b0:e03:31ec:8a24 with SMTP id 3f1490d57ef6-e041b17dfb5mr382792276.8.1720654962919; Wed, 10 Jul 2024 16:42:42 -0700 (PDT) Date: Wed, 10 Jul 2024 23:42:09 +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-6-jthoughton@google.com> Subject: [RFC PATCH 05/18] KVM: Add KVM_PFN_ERR_USERFAULT 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_164244_701519_71F2EF13 X-CRM114-Status: GOOD ( 13.15 ) 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 When a GFN -> HVA translation (__gfn_to_hva_many()) fails with KVM_HVA_ERR_USERFAULT as part of a GFN -> PFN conversion (__gfn_to_pfn_memslot()), we need to return some kind of KVM_PFN_ERR. Introduce a new KVM_PFN_ERR_USERFAULT so that callers know that it is a userfault. Signed-off-by: James Houghton --- include/linux/kvm_host.h | 1 + virt/kvm/kvm_main.c | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 4cca896fb44a..2005906c78c8 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -97,6 +97,7 @@ #define KVM_PFN_ERR_HWPOISON (KVM_PFN_ERR_MASK + 1) #define KVM_PFN_ERR_RO_FAULT (KVM_PFN_ERR_MASK + 2) #define KVM_PFN_ERR_SIGPENDING (KVM_PFN_ERR_MASK + 3) +#define KVM_PFN_ERR_USERFAULT (KVM_PFN_ERR_MASK + 4) /* * error pfns indicate that the gfn is in slot but faild to diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 758deb90a050..840e02c75fe3 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -3009,9 +3009,11 @@ kvm_pfn_t __gfn_to_pfn_memslot(const struct kvm_memory_slot *slot, gfn_t gfn, if (kvm_is_error_hva(addr)) { if (writable) *writable = false; - - return addr == KVM_HVA_ERR_RO_BAD ? KVM_PFN_ERR_RO_FAULT : - KVM_PFN_NOSLOT; + if (addr == KVM_HVA_ERR_RO_BAD) + return KVM_PFN_ERR_RO_FAULT; + if (addr == KVM_HVA_ERR_USERFAULT) + return KVM_PFN_ERR_USERFAULT; + return KVM_PFN_NOSLOT; } /* Do not map writable pfn in the readonly memslot. */