Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp904069lqt; Tue, 19 Mar 2024 07:20:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUkc8hDaJEMCt76ShzLfVj3Dg3U0YNK9oYU6OWRIWQ9MBSDdlfokB+7XnKNzuy22beFTsNL8QacZUBBWot2++FDMuCGZ34ziNYETj9Xpw== X-Google-Smtp-Source: AGHT+IEpFMDwER5WGwzwAX23jIvqO0sEOwEK6iTnj850iCW2nLW7rc1x4rj5DENVYE6cz7sdrTkY X-Received: by 2002:a17:90a:c28b:b0:29a:a31d:695a with SMTP id f11-20020a17090ac28b00b0029aa31d695amr3816972pjt.1.1710858029693; Tue, 19 Mar 2024 07:20:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710858029; cv=pass; d=google.com; s=arc-20160816; b=Xj7yawya9AUu6ya9rBam2R7bwerFUl6ks5qkN6QU0ycksbhNH1njhuxDIR6tIPTmZr oNRmQwon5xVAwkLrOPas0Hm8RvJ7eiVJP2tuMreV2U9BnZeblzEIrK9EfpR2SVPZOnhp KurSbneoICETeWJnL50XrL0ZjyahblCuX0f/l9RIqD3z6MVj3HknTqJ7xAU8FjWZTGVC ZepRdAPxYoaN3S26Wjoejj084Dy0vjYb4ybh76QTo/0lmyYNaCelJSXxgOl44d3/Y5JM bWUer11RVRXGKTN6wPDf5MA2c0YpMOAU30upFjkbimhNNblyzM23R5Z6QedFdijHCheB okCA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date; bh=uY0qxlw//M+6aMPb3I31m17sB7/8n312uzHk70Butgg=; fh=D/XNpAWX8/nBCk12uqjE1fDLZaQtH+YeY8O1y2zWZZ8=; b=oRD9UWDtng4Mw9VAAbATaQr/OK/SMLaL80h/3D1cA2b0ngdeb39ujw96Q/W3kUj9SE pDm7EXpQ6AK+BkZ7nN3pW0BY86K2NSGBJbhXbrOg1h5AxXe5gd9qHpfYc3cM65Xd+sjh +8cx6psSo3V05GnMa8+C2SXWz4TBdVRB+3MaWUbo2K/tufuCqt4HGil7neGqUXBMkw2v DvBr+KsaOACHfLAKVSIgHR0bpFWElpa66ziQyPV57pkvmYCDtM9zv8tSwuAXJaNkizfs zdgcmWDZSGUyU3gbGEh+GVH7v3w3tz250BlXqoiYQlTE16c1RceQxHmMaE5F0Z/WjahP 4PSg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-107636-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107636-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d15-20020a17090ab30f00b0029bb52196e3si10437041pjr.48.2024.03.19.07.20.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 07:20:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-107636-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-107636-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107636-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 55F5F2834CB for ; Tue, 19 Mar 2024 14:20:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4867681754; Tue, 19 Mar 2024 14:20:24 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3B0248120F for ; Tue, 19 Mar 2024 14:20:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710858023; cv=none; b=h/zCBhzqsw61J4YTZLND3J/dcf+sNPKLmafvkgfdT0Tp0iMGXgaT7qYCJaqQSTx6vhg7visefcgwO7qdYsLIm+CDvKVQVEg5KJgoQIK6ZJFF1qijPC/y880RvaHJx0x60ZQuy8LKQohjxMNs1SH0UnL153ddIRdPlq5l7K1w7h8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710858023; c=relaxed/simple; bh=GLbxYrXg8mXxjrmR6+SdA9SoSheCqqhGIEidBHJPmR4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=RT/UsayvCWF7zpXAPcBskwjpyOk/rOLGA2r3Rv4uilW95A/Tu2nY1dO6Bkd1Cx36Hm8RdgWxoGxsEDB8tcTSjQpvpt56nnlHEsof3mHL3k58Ep0yIv54+YITh0bIigMGpX6PL/EwEq1Z/hNVw6bpNYD1Wrxk5ZK1UmyZEM+H8vk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 4B88A106F; Tue, 19 Mar 2024 07:20:55 -0700 (PDT) Received: from bogus (e103737-lin.cambridge.arm.com [10.1.197.49]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 442423F762; Tue, 19 Mar 2024 07:20:19 -0700 (PDT) Date: Tue, 19 Mar 2024 14:20:16 +0000 From: Sudeep Holla To: Jens Wiklander Cc: Lorenzo Pieralisi , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Sudeep Holla , Marc Bonnici , Olivier Deprez Subject: Re: [PATCH] firmware: arm_ffa: support running as a guest in a vm Message-ID: References: <20240307092132.943881-1-jens.wiklander@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Fri, Mar 08, 2024 at 01:35:05PM +0100, Jens Wiklander wrote: > On Fri, Mar 8, 2024 at 10:44 AM Lorenzo Pieralisi wrote: > > > > On Thu, Mar 07, 2024 at 10:21:32AM +0100, Jens Wiklander wrote: > > > Add support for running the driver in a guest to a hypervisor. The main > > > difference is that the notification interrupt is retrieved > > > with FFA_FEAT_NOTIFICATION_PENDING_INT and that > > > FFA_NOTIFICATION_BITMAP_CREATE doesn't need to be called. > > > > I have a couple of questions about these changes, comments below. > > > > > FFA_FEAT_NOTIFICATION_PENDING_INT gives the interrupt the hypervisor has > > > chosen to notify its guest of pending notifications. > > > > > > Signed-off-by: Jens Wiklander > > > --- > > > drivers/firmware/arm_ffa/driver.c | 45 ++++++++++++++++++------------- > > > 1 file changed, 27 insertions(+), 18 deletions(-) > > > > > > diff --git a/drivers/firmware/arm_ffa/driver.c b/drivers/firmware/arm_ffa/driver.c > > > index f2556a8e9401..c183c7d39c0f 100644 > > > --- a/drivers/firmware/arm_ffa/driver.c > > > +++ b/drivers/firmware/arm_ffa/driver.c > > > @@ -1306,17 +1306,28 @@ static void ffa_sched_recv_irq_work_fn(struct work_struct *work) > > > ffa_notification_info_get(); > > > } > > > > > > +static int ffa_get_notif_intid(int *intid) > > > +{ > > > + int ret; > > > + > > > + ret = ffa_features(FFA_FEAT_SCHEDULE_RECEIVER_INT, 0, intid, NULL); > > > + if (!ret) > > > + return 0; > > > + ret = ffa_features(FFA_FEAT_NOTIFICATION_PENDING_INT, 0, intid, NULL); > > > + if (!ret) > > > + return 0; > > > > I think that both interrupts should be probed in eg a host and the > > actions their handlers should take are different. > > +1, I have the same opinion. > > > + > > > + pr_err("Failed to retrieve one of scheduler Rx or notif pending interrupts\n"); > > > + return ret; > > > +} > > > + > > > static int ffa_sched_recv_irq_map(void) > > > { > > > - int ret, irq, sr_intid; > > > + int ret, irq, intid; > > > > > > - /* The returned sr_intid is assumed to be SGI donated to NS world */ > > > - ret = ffa_features(FFA_FEAT_SCHEDULE_RECEIVER_INT, 0, &sr_intid, NULL); > > > - if (ret < 0) { > > > - if (ret != -EOPNOTSUPP) > > > - pr_err("Failed to retrieve scheduler Rx interrupt\n"); > > > + ret = ffa_get_notif_intid(&intid); > > > + if (ret) > > > return ret; > > > - } > > > > > > if (acpi_disabled) { > > > struct of_phandle_args oirq = {}; > > > @@ -1329,12 +1340,12 @@ static int ffa_sched_recv_irq_map(void) > > > > > > oirq.np = gic; > > > oirq.args_count = 1; > > > - oirq.args[0] = sr_intid; > > > + oirq.args[0] = intid; > > > irq = irq_create_of_mapping(&oirq); > > > of_node_put(gic); > > > #ifdef CONFIG_ACPI > > > } else { > > > - irq = acpi_register_gsi(NULL, sr_intid, ACPI_EDGE_SENSITIVE, > > > + irq = acpi_register_gsi(NULL, intid, ACPI_EDGE_SENSITIVE, > > > ACPI_ACTIVE_HIGH); > > > #endif > > > > This means that for both schedule receiver interrupt and notification > > pending interrupt we would end up calling FFA_NOTIFICATION_INFO_GET (?), > > which is not correct AFAIK, for many reasons. > > > > If there is a pending notification for a VM, a scheduler receiver > > interrupt is triggered in the host. This would end up calling > > FFA_NOTIFICATION_INFO_GET(), that is destructive (calling it again in > > the notified *guest* - in the interrupt handler triggered by the > > hypervisor - would not return the pending notifications for it). > > > > Therefore, the action for the pending notification interrupt should > > be different and should just call FFA_NOTIFICATION_GET. > > > > Please let me know if that matches your understanding, this > > hunk is unclear to me. As you can expect, the above matches my understanding too. > > This patch was made from the assumption that this FF-A driver is a > guest driver, that is, FFA_NOTIFICATION_INFO_GET lands in the > Hypervisor at EL2. The FFA_NOTIFICATION_INFO_GET call is needed to > know which FFA_NOTIFICATION_GET calls should be dispatched in this VM, > to retrieve global notifications and per vCPU notifications. > OK and I assume this aligns with the below excerpts from the spec about FFA_NOTIFICATION_INFO_GET: " This ABI is invoked by a VM at the Non-secure virtual FF-A instance with the SMC or HVC conduits to request the Hypervisor to return the list of SPs and VMs that have pending notifications. The Hypervisor returns the list of those endpoints whose schedulers are implemented in the calling VM. " But if OPTEE driver in the VM/guest is the scheduler for the OPTEE SP, then I would expect the FF-A driver to just register for SRI. It can't be NPI as that contradicts with above. > If the FF-A driver is supposed to be a host driver instead, then I > wonder where we should have the guest driver. > At least so far we haven't found a strong reason to have different versions for each. > For clarification, my setup has Xen as hypervisor at EL2 (doing the > host processing), TF-A as SPMD at EL3, and OP-TEE as SPMC at S-EL1. > I'm testing this on QEMU. I'm going to post the Xen patches relating > to this quite soon. > OK, thanks for the setup info. > I believe that until now the FF-A driver has worked under the > assumption that it's a non-secure physical FF-A instance. With > hypervisor at EL2 it becomes a virtual FF-A instance. > Agreed. > > > > > } > > > @@ -1442,17 +1453,15 @@ static void ffa_notifications_setup(void) > > > int ret, irq; > > > > > > ret = ffa_features(FFA_NOTIFICATION_BITMAP_CREATE, 0, NULL, NULL); > > > - if (ret) { > > > - pr_info("Notifications not supported, continuing with it ..\n"); > > > - return; > > > - } > > > + if (!ret) { > > > > > > - ret = ffa_notification_bitmap_create(); > > > - if (ret) { > > > - pr_info("Notification bitmap create error %d\n", ret); > > > - return; > > > + ret = ffa_notification_bitmap_create(); > > > + if (ret) { > > > + pr_err("notification_bitmap_create error %d\n", ret); > > > + return; > > > + } > > > + drv_info->bitmap_created = true; > > > } > > > - drv_info->bitmap_created = true; > > > > This boils down to saying that FFA_NOTIFICATION_BITMAP_CREATE is not > > implemented for a VM (because the hypervisor should take care of issuing > > that call before the VM is created), so if the feature is not present > > that does not mean that notifications aren't supported. > > > > It is just about removing a spurious log. > > > > Is that correct ? > > No, this is about not aborting notification setup just because we have > a hypervisor that handles the FFA_NOTIFICATION_BITMAP_CREATE call. Understood. > With this patch, if ffa_get_notif_intid() fails, then we don't have > support for notifications. > But I still don't understand the mixup of SRI and NPI in your usecase model. It should be just SRI. NPI handler must just use NOTIFICATION_GET and not INFO_GET as Lorenzo has explained above. -- Regards, Sudeep