From mboxrd@z Thu Jan 1 00:00:00 1970 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 9E868CA0ED3 for ; Mon, 2 Sep 2024 15:37:25 +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-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=eUd6qtGS84S2PljjkqBjEjGDRhtwDThabCjiS9Z1zNo=; b=VppcG+u9bx737yuYnCozt9nLpz sCTyJ9hXNas51woLQje7mOe3viJZNsSXep//EekI2YkuCdwBXMrx02pY3rqy7SWTUXBUGctAmSZSv u2PNVw7kkj4aZJOyuKaM0WttwMlG784FFue+e5oZUOGa4qvdoY07pVezfFjG3L3lhJyldR/NbZV3q q2GjT2vnpTVYdg1WYXUNkv8JT1D2P2M9YprqIFarnISxnEaaQOZoAqNeBzOKPQXFGn9lz0b+zLitK EzN/PyCXxP7BA6l+nOZNoczomedVi37Z/3ZCvA3IEOvrpq+5Ew2Sg3CPecdllt1NPUGpOG1nDNhJv b/aB6uiA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sl97B-0000000EsSF-352b; Mon, 02 Sep 2024 15:37:13 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sl94V-0000000ErkA-0sdl for linux-arm-kernel@lists.infradead.org; Mon, 02 Sep 2024 15:34:28 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 65DC4FEC; Mon, 2 Sep 2024 08:34:52 -0700 (PDT) Received: from [10.57.74.147] (unknown [10.57.74.147]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E373B3F66E; Mon, 2 Sep 2024 08:34:21 -0700 (PDT) Message-ID: Date: Mon, 2 Sep 2024 16:34:19 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 21/43] arm64: RME: Runtime faulting of memory To: Matias Ezequiel Vara Larsen Cc: kvm@vger.kernel.org, kvmarm@lists.linux.dev, Catalin Marinas , Marc Zyngier , Will Deacon , James Morse , Oliver Upton , Suzuki K Poulose , Zenghui Yu , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Joey Gouly , Alexandru Elisei , Christoffer Dall , Fuad Tabba , linux-coco@lists.linux.dev, Ganapatrao Kulkarni , Gavin Shan , Shanker Donthineni , Alper Gun References: <20240821153844.60084-1-steven.price@arm.com> <20240821153844.60084-22-steven.price@arm.com> From: Steven Price Content-Language: en-GB In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240902_083427_320237_107A7937 X-CRM114-Status: GOOD ( 15.81 ) 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 On 02/09/2024 14:25, Matias Ezequiel Vara Larsen wrote: > Hello Steven, > > On Wed, Aug 21, 2024 at 04:38:22PM +0100, Steven Price wrote: ... >> +static int private_memslot_fault(struct kvm_vcpu *vcpu, >> + phys_addr_t fault_ipa, >> + struct kvm_memory_slot *memslot) >> +{ >> + struct kvm *kvm = vcpu->kvm; >> + gpa_t gpa_stolen_mask = kvm_gpa_stolen_bits(kvm); >> + gfn_t gfn = (fault_ipa & ~gpa_stolen_mask) >> PAGE_SHIFT; >> + bool is_priv_gfn = !((fault_ipa & gpa_stolen_mask) == gpa_stolen_mask); >> + bool priv_exists = kvm_mem_is_private(kvm, gfn); >> + struct kvm_mmu_memory_cache *memcache = &vcpu->arch.mmu_page_cache; >> + kvm_pfn_t pfn; >> + int ret; >> + >> + if (priv_exists != is_priv_gfn) { >> + kvm_prepare_memory_fault_exit(vcpu, >> + fault_ipa & ~gpa_stolen_mask, >> + PAGE_SIZE, >> + kvm_is_write_fault(vcpu), >> + false, is_priv_gfn); >> + >> + return 0; >> + } > > If I understand correctly, `kvm_prepare_memory_fault_exit()` ends up > returning to the VMM with the KVM_EXIT_MEMORY_FAULT exit reason. The > documentation says (https://docs.kernel.org/virt/kvm/api.html#kvm-run): > > "Note! KVM_EXIT_MEMORY_FAULT is unique among all KVM exit reasons in that > it accompanies a return code of ‘-1’, not ‘0’! errno will always be set > to EFAULT or EHWPOISON when KVM exits with KVM_EXIT_MEMORY_FAULT, > userspace should assume kvm_run.exit_reason is stale/undefined for all > other error numbers." > > Shall the return code be different for KVM_EXIT_MEMORY_FAULT? > > Thanks, Matias. Ah, good spot - I've no idea why KVM_EXIT_MEMORY_FAULT is special in this regard, but yes I guess we should be returning -EFAULT here. Thanks, Steve