From patchwork Wed Nov 16 17:03:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 13045608 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 69094C4332F for ; Wed, 16 Nov 2022 17:17: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: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: References:Mime-Version:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=NHPm2UiPLwlv2U5VWzw4Shih+hZZmGRgP7qVt6LwQhM=; b=2ocoiiZbc8Dq7paOiC2YLH1TAu ZZQjJrpsNcgWxigpNxFRJtvB7HbThbyHyrAxuTPQCx+hOZAu643CQxDu5yDmjPzTQZP/xiseiLJ8I HODAj9FX4Us52QuFNR3PFP2a0bE/WbxfnZIompFYhvhaoqsIp7rND8oD75J2el237CQIS+zQxo6vi GHA6JQhhI8QtT3vxWPS9UTsMePssIfqcWicvIn5veWp3cgLqRsAwKgMDXw8UkwTgwx9jhxj5Olo+P +yEEbJed7a1m/JTbsmCe3iqphzunLsW42zbmWDZ2E/7Wgh5NPTRQ9/s3iUefvDUTr1dUHusiTasrS pT5pexmA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ovM1J-006Lf9-S6; Wed, 16 Nov 2022 17:16:18 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ovM1D-006LIP-Jm for linux-arm-kernel@bombadil.infradead.org; Wed, 16 Nov 2022 17:16:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:Cc:To:From:Subject: Message-ID:References:Mime-Version:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=UNHIEymVb+XSzDMRY7di2ZGqPLVkyCRzgk1tuxxw7oc=; b=kj+OuUsfGLqbJvlR5rqmSK/9Mn bU/q2wIMx3Gtk5hxG2nqBU+QVMRiJCleztsZC3t8fRl9y5CfU2wvT/i+7VLPMShrRYWs/uzNd1Mpm DY7k4/9RcDA9aNg1HTJR7xXWxuUsicEGWA6SJeaHXCc5uepAY2o4ULWIHFiO514WH8YagMNmT6+uT lnMzNH9/+jCRCUmUJAAF7u6zfJlfn6IOeN9AQdnxcmr+uIcGPWJ4NxX79SRKhaG7U4CXVv31Z+7/2 qB6rP9RRaeZBdNpGh7po/j28GGKsCJ86F6aiJbP8p/aITYKOCRFv6amNHbp7Den/+l5tLFY8+Ldb7 rHIlNrog==; Received: from mail-ed1-x549.google.com ([2a00:1450:4864:20::549]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ovLpa-001PcD-9S for linux-arm-kernel@lists.infradead.org; Wed, 16 Nov 2022 17:04:14 +0000 Received: by mail-ed1-x549.google.com with SMTP id c9-20020a05640227c900b00463de74bc15so12990164ede.13 for ; Wed, 16 Nov 2022 09:04:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=UNHIEymVb+XSzDMRY7di2ZGqPLVkyCRzgk1tuxxw7oc=; b=ULXXfyFHyQ/ZzVkyLWpxN5DnlpcorBmr7G0YcKEPr2b2mJrX39TIEN9HZ6c0hZDTyx 329LbDpAKIwekVtzcha75hsVu8Si4bfwJSXe0h7d+t4hQpqKu9yAKDCX0EnQbqn9YLgg 2Ytm/pKNd6sLkdxUelG6cKU40fEj5vr55vNfLdGYzj9cGjcnS7iFPT6ZfNxCEM1kt0IL ngAYqkkEAFKLCS7zC2p+Hd94ACzVr4mUJK6MBaN9BBcH3DaZbgMK73RRoJAG3fXExPE6 f+egV7/6COHJt96CMB21bc8wKQPQsqc0pI5ORROQnC8W2U5V53bGpF760O2bosKDghWD RQ4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=UNHIEymVb+XSzDMRY7di2ZGqPLVkyCRzgk1tuxxw7oc=; b=gXnyckQ9whPx1sZqvYWSg7vutPDGb6QIj3IL23p5hss/oiwNEXl8yrRctTcFKUU96Y ioVUTHHfolcJs/aT+8gt4WEcSqgYapWol2tgrpYwr9seDs7sewTHgCy0lV0uYVFQYsJ5 1ALp/y5/nilRA4WAqiuEju/oo6XDEaAjbkcurgh1bptzLP6UF+BOfx94BXAeqEQA8A2F jet6FWLIWQutG3+a+WL9G/Y3cQEcNuc4n+zG/jL1L72IpXXmSdKxJi9AtyXBTSZOEvwA fPr6SdzLcRwS7CHuryo+pfrTURT9k9ZFj2spSeXjcgUgk+HHEloQOtvmUGRyvikTZN9l Gccg== X-Gm-Message-State: ANoB5pk0SghBm4EwOUUYZ7qdIzqTH/CmWZBzjz9QfLq+lTEiQ6aOa1Ea 3gyfq5dT4yjSomuYn55YhCMg+3Tma4Fb X-Google-Smtp-Source: AA0mqf7bePVxvTek80mJF7MvMu/XjAXSSdk17HBMIgnsABCOlR0Jqni4M2Ms2XVeDVgnHMr7E43fgsMQt7X3 X-Received: from big-boi.c.googlers.com ([fda3:e722:ac3:cc00:31:98fb:c0a8:129]) (user=qperret job=sendgmr) by 2002:a50:d790:0:b0:461:7fe6:9ea7 with SMTP id w16-20020a50d790000000b004617fe69ea7mr19716772edi.94.1668618244971; Wed, 16 Nov 2022 09:04:04 -0800 (PST) Date: Wed, 16 Nov 2022 17:03:34 +0000 In-Reply-To: <20221116170335.2341003-1-qperret@google.com> Mime-Version: 1.0 References: <20221116170335.2341003-1-qperret@google.com> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog Message-ID: <20221116170335.2341003-12-qperret@google.com> Subject: [PATCH 11/12] KVM: arm64: Handle FFA_MEM_LEND calls from the host From: Quentin Perret To: Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Oliver Upton , Catalin Marinas , Will Deacon , Sudeep Holla , Andrew Walbran Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kernel-team@android.com, qperret@google.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221116_170410_446983_205B799A X-CRM114-Status: GOOD ( 11.47 ) 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 From: Will Deacon Handle FFA_MEM_LEND calls from the host by treating them identically to FFA_MEM_SHARE calls for the purposes of the host stage-2 page-table, but forwarding on the original request to EL3. Signed-off-by: Will Deacon Signed-off-by: Quentin Perret --- arch/arm64/kvm/hyp/nvhe/ffa.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvhe/ffa.c index 8f690b80af60..84024cba12ff 100644 --- a/arch/arm64/kvm/hyp/nvhe/ffa.c +++ b/arch/arm64/kvm/hyp/nvhe/ffa.c @@ -122,10 +122,10 @@ static int spmd_unmap_ffa_buffers(void) return res.a0 == FFA_SUCCESS ? FFA_RET_SUCCESS : res.a2; } -static void spmd_mem_share(struct arm_smccc_res *res, u32 len, u32 fraglen) +static void spmd_mem_xfer(struct arm_smccc_res *res, u64 func_id, u32 len, + u32 fraglen) { - arm_smccc_1_1_smc(FFA_FN64_MEM_SHARE, - len, fraglen, + arm_smccc_1_1_smc(func_id, len, fraglen, 0, 0, 0, 0, 0, res); } @@ -323,8 +323,9 @@ static int ffa_host_unshare_ranges(struct ffa_mem_region_addr_range *ranges, return ret; } -static void do_ffa_mem_share(struct arm_smccc_res *res, - struct kvm_cpu_context *ctxt) +static __always_inline void do_ffa_mem_xfer(const u64 func_id, + struct arm_smccc_res *res, + struct kvm_cpu_context *ctxt) { DECLARE_REG(u32, len, ctxt, 1); DECLARE_REG(u32, fraglen, ctxt, 2); @@ -335,6 +336,9 @@ static void do_ffa_mem_share(struct arm_smccc_res *res, int ret = 0; u32 offset; + BUILD_BUG_ON(func_id != FFA_FN64_MEM_SHARE && + func_id != FFA_FN64_MEM_LEND); + if (addr_mbz || npages_mbz || fraglen > len || fraglen > KVM_FFA_MBOX_NR_PAGES * PAGE_SIZE) { ret = FFA_RET_INVALID_PARAMETERS; @@ -384,7 +388,7 @@ static void do_ffa_mem_share(struct arm_smccc_res *res, if (ret) goto out_unlock; - spmd_mem_share(res, len, fraglen); + spmd_mem_xfer(res, func_id, len, fraglen); if (res->a0 != FFA_SUCCESS) { WARN_ON(ffa_host_unshare_ranges(reg->constituents, reg->addr_range_cnt)); @@ -535,13 +539,15 @@ bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt) goto out_handled; case FFA_MEM_SHARE: case FFA_FN64_MEM_SHARE: - do_ffa_mem_share(&res, host_ctxt); + do_ffa_mem_xfer(FFA_FN64_MEM_SHARE, &res, host_ctxt); goto out_handled; case FFA_MEM_RECLAIM: do_ffa_mem_reclaim(&res, host_ctxt); goto out_handled; case FFA_MEM_LEND: case FFA_FN64_MEM_LEND: + do_ffa_mem_xfer(FFA_FN64_MEM_LEND, &res, host_ctxt); + goto out_handled; case FFA_MEM_FRAG_TX: break; }