From patchwork Mon Sep 9 13:08:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Snehal Koukuntla X-Patchwork-Id: 13797163 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 21ABAECE57A for ; Mon, 9 Sep 2024 14:15:29 +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:Mime-Version:Date:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=gkcR1LQPE4FCQJPuyJ1psNJiBytHsKUOZJ03Mjoli6E=; b=avrTZ7CLcnMPjguOHcGuDCV9ld ocC+STUMsA8WHh5sMqSEiclW2AdA+yvx09+S2twV6hGGKjCtn3m/Zou49K4XB/NT/ZhAnUCs5CRuk amjtmlqMPLfaj/jHM9HboKL+4H7UwpPvhqXwvfjx4igMoYZshfUOa4h2r05zpdtZWqUG8IVaSXjHr L0ThFJ3MyGHlsxDSG+MBhd96379+KKu85kPgCPaxL2DI1eiVKCLAhK6OmcmMWgOR0k+zvm9wRkJ6W hR8jf8YgDn4TY1ZftDrzGtLpTM0y5YVI9ABfDr5Atd0T5JFLucFZ82wtqPDpt9yUbLT+zGMoBHI+A mrvMAbTg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1snfAo-00000002EXP-2Jnm; Mon, 09 Sep 2024 14:15:22 +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 1sne8K-0000000201k-3CXZ for linux-arm-kernel@lists.infradead.org; Mon, 09 Sep 2024 13:08:46 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-6cf78470a56so140960477b3.3 for ; Mon, 09 Sep 2024 06:08:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725887322; x=1726492122; darn=lists.infradead.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=gkcR1LQPE4FCQJPuyJ1psNJiBytHsKUOZJ03Mjoli6E=; b=kwlCcJ+mymgH1tvjCOQnX7g+XTxbt2jyWpQLn2kiXvT3iWmzekoTCT6L+sowBH18vx psbFC4HHjECzW1nRaOV7kmZ4kuZCnV50Ez45zfjl47VERMLHKZ35W8xq4ciIcN58Im5j 59osEL+JL5KkPwyFTWvYsQwI2XWWhwndGu4652bcxT3hBFm6VwjbatISgQLwVi9QP6m8 6l1DfBOd8Vd2LxyjPUClCB1swYKipzr3hE+w6HtMnL8sauXK+9jA4mId71/xL5meDRYI W3E8AHFbuGmkkILvgjBjXCwwUkti/snw3rGQ8lVhgeYMgdVAdkjvOB8PkoB/Q/dCvqNs 7jxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725887322; x=1726492122; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=gkcR1LQPE4FCQJPuyJ1psNJiBytHsKUOZJ03Mjoli6E=; b=j1vj9P67UbnhAlt9tdYqFJIY9sp91VbrozWfdemBni1Mu4b8XIggfTsUu2N/YVBwEU cx0McTL/N86gZheFtKRRXlNlQhQI5NjbfW/3I139F9lFimp78/lyIw77n0vqNO6SzCQn ZAmj2LnhosYwVNsGgNbN72Ls8rv9OlkqWotVeoLzMvpnrOcdsC8wWT8ZrgqpXuo6DE1i 1u/cKl6da64Jim0VhFFHywlK88gpSBuONn7D/Siqg7zsP511zY5h8hWp88Bie9zlwalp ucmt0Gs41ybhbgiQT79I+5i/7ZlganUdPCQYQPzPdERE9IMVXM+XSiONNoNnlNi1wbtN M2yg== X-Forwarded-Encrypted: i=1; AJvYcCV0zlpetXvq47lxw09A8FplNfJE4EFoZvBdsWjlmUJRHBwG8m6BwlKwdkjOJKWY86eV7aQ1HU1ZE8leqCod19GW@lists.infradead.org X-Gm-Message-State: AOJu0Yx7VPJ+LTRECCDKPjq36VXofVy4lQ3eyNxpElc06AGyn81LHqaq f30z4EBElcT9cqx7vCgfm+JWFfSbY9vojl77JmSqeBWWQ3kGoLYbjws/lvsyONEzLszJTX+rPek L4AXG0wxuX1FDDbcBulXuQg== X-Google-Smtp-Source: AGHT+IHZHeeJzJA+rBQ2ukVV7/hhG+otbYJ/RCdAhQjZtiHGvPzEoizdzLQoCYDilJms56oKXlfXRy7wmQN6XoFmtg== X-Received: from snehalreddy-1.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:c1f]) (user=snehalreddy job=sendgmr) by 2002:a05:6902:4d1:b0:e0b:cce3:45c7 with SMTP id 3f1490d57ef6-e1d349e38d5mr19825276.9.1725887322131; Mon, 09 Sep 2024 06:08:42 -0700 (PDT) Date: Mon, 9 Sep 2024 13:08:32 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Message-ID: <20240909130832.1203849-1-snehalreddy@google.com> Subject: [PATCH v2] KVM: arm64: Add memory length checks and remove inline in do_ffa_mem_xfer From: Snehal Koukuntla To: Marc Zyngier , Oliver Upton Cc: James Morse , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Sudeep Holla , Sebastian Ene , Vincent Donnefort , Snehal , Jean-Philippe Brucker , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240909_060844_839041_80ADC4B6 X-CRM114-Status: GOOD ( 11.91 ) 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 Check size during allocation to fix discrepancy in memory reclaim path. Currently only happens during memory reclaim, inconsistent with mem_xfer Also do_ffa_mem_xfer() does not need __always_inline Signed-off-by: Snehal Koukuntla Signed-off-by: Snehal Koukuntla --- arch/arm64/kvm/hyp/nvhe/ffa.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/nvhe/ffa.c b/arch/arm64/kvm/hyp/nvhe/ffa.c index e715c157c2c4..637425f63fd1 100644 --- a/arch/arm64/kvm/hyp/nvhe/ffa.c +++ b/arch/arm64/kvm/hyp/nvhe/ffa.c @@ -426,7 +426,7 @@ static void do_ffa_mem_frag_tx(struct arm_smccc_res *res, return; } -static __always_inline void do_ffa_mem_xfer(const u64 func_id, +static void do_ffa_mem_xfer(const u64 func_id, struct arm_smccc_res *res, struct kvm_cpu_context *ctxt) { @@ -461,6 +461,11 @@ static __always_inline void do_ffa_mem_xfer(const u64 func_id, goto out_unlock; } + if (len > ffa_desc_buf.len) { + ret = FFA_RET_NO_MEMORY; + goto out_unlock; + } + buf = hyp_buffers.tx; memcpy(buf, host_buffers.tx, fraglen);