From patchwork Wed Apr 12 21:34:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anish Moorthy X-Patchwork-Id: 13209555 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8399AC77B76 for ; Wed, 12 Apr 2023 21:35:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230009AbjDLVfb (ORCPT ); Wed, 12 Apr 2023 17:35:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229828AbjDLVfY (ORCPT ); Wed, 12 Apr 2023 17:35:24 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 129D37EEC for ; Wed, 12 Apr 2023 14:35:23 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-54f3e30726cso92487247b3.22 for ; Wed, 12 Apr 2023 14:35:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1681335322; x=1683927322; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=2HEZpjwJAllfV0I5F7ADUYQU3lomGIeMIJyobWdtpuc=; b=lAmykGgc7/jSWWpiEUSSuOFZq53ucIIAMaKUFqmueRpj2EzlhWgnqQLfis3Ztcd4wi h5Zgje/Jxjcj2CcRv9fSMfzcrGEpsPUQ+X4OYlwUzTG9hZZgzZxEg4iERSVRsazSR4dQ mbJBRRiQGBkQ1VaXe8CftZCD+8LyveM0bff5wLsLok2+QNnHiJm2xDU1peod1tRA9Gme 8K+wJXLIyDSfDU2Liq5+LTeILHdZRIhAdBtJ4tBTagjbxyHGme3Bdyd46qOb/TRcpdXT elyMkDBA5mdJuuZYGfiFiCeYQ/U5/qRgk3o+DrSjOQIWmibO2PFVdAWi+0KxVip7dHLw hBDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681335322; x=1683927322; 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=2HEZpjwJAllfV0I5F7ADUYQU3lomGIeMIJyobWdtpuc=; b=K7U9dSxZb6mzYS9IRrC/CWPZQQX4xQiYfQ+N+QiptZSHL2x7oi67UcydcvKCIbjv5G GohVKa2GmOhhh7dYZ+41omrsV0h2HZKT1F/gaBQ80y292iLslbKjfqtE+bzOU5tFk2f3 kRBzrgcZmzl9+PV0fIJV2xpQ2bbQ82XaoGdn1zkxyTqeU6j+vDvYBdXkuz4Dmjm3EZtc f3HBmeVM7GaIhI/DtdkT+ldAmehGaSD42B1IKkbxoDqOshHgE3gFSEMtYGcLl5o7fbT4 oEA7V9bXQD9mcBK2UVZMTbpCXg941NQT1w2+mxOP5y9kUJ53JgE8oD/RBYmxrXIIgUAo MNKw== X-Gm-Message-State: AAQBX9fWoKydd0dJmLX11ekeCRVelExPLajCx/6gl238J+h/cj8+q9Hh hJbpzmJXVcISpNqm4rQrn/Cd8wL3djau9A== X-Google-Smtp-Source: AKy350ZEcbjFijoKkL3xtGAA1xKzYaEJ45MS8KT6dNFR0HK9SeJ8kLYqa/GC16fyN32eT7P0BxcvFD5YNNEzLA== X-Received: from laogai.c.googlers.com ([fda3:e722:ac3:cc00:2b:7d90:c0a8:2c9]) (user=amoorthy job=sendgmr) by 2002:a25:d78b:0:b0:b67:d295:d614 with SMTP id o133-20020a25d78b000000b00b67d295d614mr9968308ybg.12.1681335322385; Wed, 12 Apr 2023 14:35:22 -0700 (PDT) Date: Wed, 12 Apr 2023 21:34:56 +0000 In-Reply-To: <20230412213510.1220557-1-amoorthy@google.com> Mime-Version: 1.0 References: <20230412213510.1220557-1-amoorthy@google.com> X-Mailer: git-send-email 2.40.0.577.gac1e443424-goog Message-ID: <20230412213510.1220557-9-amoorthy@google.com> Subject: [PATCH v3 08/22] KVM: Annotate -EFAULTs from kvm_vcpu_read_guest_page() From: Anish Moorthy To: pbonzini@redhat.com, maz@kernel.org Cc: oliver.upton@linux.dev, seanjc@google.com, jthoughton@google.com, amoorthy@google.com, bgardon@google.com, dmatlack@google.com, ricarkol@google.com, axelrasmussen@google.com, peterx@redhat.com, kvm@vger.kernel.org, kvmarm@lists.linux.dev Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Implement KVM_CAP_MEMORY_FAULT_INFO for efaults generated by kvm_vcpu_read_guest_page(). Signed-off-by: Anish Moorthy --- virt/kvm/kvm_main.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index b29a38af543f0..572adba9ad8ed 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -3014,7 +3014,11 @@ int kvm_vcpu_read_guest_page(struct kvm_vcpu *vcpu, gfn_t gfn, void *data, { struct kvm_memory_slot *slot = kvm_vcpu_gfn_to_memslot(vcpu, gfn); - return __kvm_read_guest_page(slot, gfn, data, offset, len); + int ret = __kvm_read_guest_page(slot, gfn, data, offset, len); + + if (ret == -EFAULT) + kvm_populate_efault_info(vcpu, gfn * PAGE_SIZE + offset, len); + return ret; } EXPORT_SYMBOL_GPL(kvm_vcpu_read_guest_page);