From patchwork Wed Jul 10 23:42:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Houghton X-Patchwork-Id: 13729882 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 CDC63C3DA42 for ; Wed, 10 Jul 2024 23:46:38 +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=wAPg+uoGyE7jrnqbrfnqp+qBfKQe/ElheERXpCs/y30=; b=HUM7y9KBeIlw24pj01ESaXGrOB q5iFMt3G+uDQNJQSYli3RPxYgGM6wB3oreB+EHLCGea6PvV4xOBhjX0h7t1FBEiDW1MyZL7q6MJ4A zZ27oKKH8q5H32v//imTpNbgZDv3Og0+3h/kxqKqIbZF7hDpO/JJy2YqVViIak8aUlyeFxDsHC6hr sKpQE/KMskodur2npvlJkN2R8pYrNQHWcLKetc0NiVW98h18tjugnuqWmK1PsH4UJFPgPZtDR4e1G NwLyK+uvXgvXIuAMNhy9pikHQx4PvAasCL1lVPDF8Htr73d10wEQ3qmtTpke9xW4GLUUwhxPC/Dn6 lIoNhnsQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sRh10-0000000C9A1-41C4; Wed, 10 Jul 2024 23:46:26 +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 1sRgxW-0000000C7FJ-47xW for linux-arm-kernel@lists.infradead.org; Wed, 10 Jul 2024 23:42:54 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-651e54bb41bso4323107b3.1 for ; Wed, 10 Jul 2024 16:42:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1720654970; x=1721259770; 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=wAPg+uoGyE7jrnqbrfnqp+qBfKQe/ElheERXpCs/y30=; b=fMepc5pBpQOaav4+GrlhFN5nPwuN66elxOsRso4KObIsJmvF+RDc5SYadThjR35j3r WPURhc3mrW94M9raCzHiPZ5j59REvOVqKT0N38Pe9V1WTjRhisVzlNWG1W51IS6cX3pW VJtFrVqQAPK9L5vteASgflJoWqdaXyG5UKD2p6n4CmL7RiHQJ0gSnEIuCgDlx64ppl61 VP8mc7gApjnEQT+QGefGEulFD2PcgyGr4ErRukvBUYJC5OXO97ZTeZcn/I716nJgxUoH Dh1lwF4Em4sF7JNrPW41TpczApE/gDO1g5o8+Q3jpaAgA7P0JvhMz7YEONAJ27KLgd1q 9Ylg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720654970; x=1721259770; 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=wAPg+uoGyE7jrnqbrfnqp+qBfKQe/ElheERXpCs/y30=; b=hy8zsgECN/EYpu1PC0WKx1hwFIzDzYs1kOReZGBWH1DfFvGGlbieUkD2UFz6GqJrPY PZMuMDRb35/fYRAqU69X33oHvrBUUnpVE2JIWns6rjFme61w8ahg6dTcUGuNZn9hqwo8 I53+m29Uo9hiZEYuOT/GwrYWegHYCq54HHsp6DgmNQz1DTjV1DEj1qE4cGLMuijqo2Dk LCnysTa+s6RgAce36uBL4XWx8QgurQU22FrZaodVlqRnr3jmxjlbdk1fpR+IATdDCk3w lC3C75yhUxuOWHO2jAqfHAi/7A3i19slsL+BI+1FR71ox8TtBnKGdX1z3TNvgBgQ6exh TYTA== X-Forwarded-Encrypted: i=1; AJvYcCVjkI6pBZOKNesIigh0eYrkdzkMujY9tAHXmsDmhlK1XaUCiYR5fj8oXozrsLpGRvknFjzYbO6iFyQbjO7ZFk2n9NPsr5gKrfrCq9Tjf+5/ZQKXZOA= X-Gm-Message-State: AOJu0Ywlzb296fX8aN/srvhNs/qFsyGAWTSGlTIkFVDsx4XGuoGt8G6R nh/TyyYegTL6+1ekiAEqAw2K8G5UGn7m0Rv5bKmXeMsYKmjVLV+yU18PfVx9TCrDq9tHZPb8cYQ YSix4iepkQxPoQeoVkQ== X-Google-Smtp-Source: AGHT+IEUTEcOd07Ngb0BqkggJw4ozgt7Za8itkm1dvA0VYqtERMoRdOJmQ0AmWvr6/7REaf9c4XX0hx8Il26mfc6 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-e041b17dfb5mr382800276.8.1720654969766; Wed, 10 Jul 2024 16:42:49 -0700 (PDT) Date: Wed, 10 Jul 2024 23:42:16 +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-13-jthoughton@google.com> Subject: [RFC PATCH 12/18] KVM: arm64: Add userfault support for steal-time 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_164251_149308_074EF465 X-CRM114-Status: GOOD ( 14.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 As part of KVM_RUN, we may need to write steal-time information to guest memory. In the case that the gfn we are writing to is userfault-enabled, we should return to userspace with fault information. With asynchronous userfaults, this change is not necessary and merely acts as an optimization. Signed-off-by: James Houghton --- arch/arm64/include/asm/kvm_host.h | 2 +- arch/arm64/kvm/arm.c | 8 ++++++-- arch/arm64/kvm/pvtime.c | 11 +++++++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 36b8e97bf49e..4c7bd72ba9e8 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -1166,7 +1166,7 @@ static inline bool kvm_arch_pmi_in_guest(struct kvm_vcpu *vcpu) long kvm_hypercall_pv_features(struct kvm_vcpu *vcpu); gpa_t kvm_init_stolen_time(struct kvm_vcpu *vcpu); -void kvm_update_stolen_time(struct kvm_vcpu *vcpu); +int kvm_update_stolen_time(struct kvm_vcpu *vcpu); bool kvm_arm_pvtime_supported(void); int kvm_arm_pvtime_set_attr(struct kvm_vcpu *vcpu, diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 59716789fe0f..4c7994e44217 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -974,8 +974,12 @@ static int check_vcpu_requests(struct kvm_vcpu *vcpu) */ kvm_check_request(KVM_REQ_IRQ_PENDING, vcpu); - if (kvm_check_request(KVM_REQ_RECORD_STEAL, vcpu)) - kvm_update_stolen_time(vcpu); + if (kvm_check_request(KVM_REQ_RECORD_STEAL, vcpu)) { + int ret = kvm_update_stolen_time(vcpu); + + if (ret <= 0) + return ret; + } if (kvm_check_request(KVM_REQ_RELOAD_GICv4, vcpu)) { /* The distributor enable bits were changed */ diff --git a/arch/arm64/kvm/pvtime.c b/arch/arm64/kvm/pvtime.c index 4ceabaa4c30b..ba0164726310 100644 --- a/arch/arm64/kvm/pvtime.c +++ b/arch/arm64/kvm/pvtime.c @@ -10,7 +10,7 @@ #include -void kvm_update_stolen_time(struct kvm_vcpu *vcpu) +int kvm_update_stolen_time(struct kvm_vcpu *vcpu) { struct kvm *kvm = vcpu->kvm; u64 base = vcpu->arch.steal.base; @@ -20,9 +20,14 @@ void kvm_update_stolen_time(struct kvm_vcpu *vcpu) int idx; if (base == INVALID_GPA) - return; + return 1; idx = srcu_read_lock(&kvm->srcu); + if (gfn_to_hva(kvm, base + offset) == KVM_HVA_ERR_USERFAULT) { + kvm_prepare_memory_fault_exit(vcpu, base + offset, PAGE_SIZE, + true, false, false, true); + return -EFAULT; + } if (!kvm_get_guest(kvm, base + offset, steal)) { steal = le64_to_cpu(steal); vcpu->arch.steal.last_steal = READ_ONCE(current->sched_info.run_delay); @@ -30,6 +35,8 @@ void kvm_update_stolen_time(struct kvm_vcpu *vcpu) kvm_put_guest(kvm, base + offset, cpu_to_le64(steal)); } srcu_read_unlock(&kvm->srcu, idx); + + return 1; } long kvm_hypercall_pv_features(struct kvm_vcpu *vcpu)