Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp4634531rwe; Mon, 17 Apr 2023 16:14:40 -0700 (PDT) X-Google-Smtp-Source: AKy350ZntJyqPzwuUANvNjDgmmkWr95ojgvx1Wz4loQ77efQ9xvRIfLSCnRyNi5nZJ3wh2rGf/fF X-Received: by 2002:a05:6a00:2394:b0:63b:6d60:9a02 with SMTP id f20-20020a056a00239400b0063b6d609a02mr17179068pfc.34.1681773279936; Mon, 17 Apr 2023 16:14:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681773279; cv=none; d=google.com; s=arc-20160816; b=AfRVN6rU66OCV79gywiTClyL94820hlwpQE9cnDoEblo8983g0cAm/EQ3AjpMe5uM0 T62UkCk4Oiv2W5gD3SK9Ti8yPqrFEgGdzCvQ/25FM3D8Z2gg4NEJJOlPkTHED3Q61I18 cvTyFjOnSlxZbBrZhy4hljYxYaVhAsPkXCNdEbqJ+OerLv2APBYii68rzh3m0hbN9mIj NJ7Id4WHdIArI4xlWjnz4QT35Hxs1LDzIx1oUWBv9EHAdTxSDlKKXwFUSW2d3N9VeJk+ Gj3yEUrxUPRYZDubN1mG8sAUyS+6LiwqdgidhgMQZPDfbQzqgwRdfuUNqZu1KwH5a+Kb o8WA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=TYiYTf71z2QgKJBu/vBOofEjUIMRz93Rtu7+eYyDuHM=; b=PDhC7XXwVunLgTfQzmamgBh9i98U7Q5h36mjgzAY2z3N+L/jLDiWO8cwVXUXJr6rAo D/Uspc5x2WiKVOJ83UCcm2Lgs5MxtY46qPD/RS8H/D1jU3LS9OIgQ+LpwbZFNxP9p5mm 9y1LSnFSSPkilzrunvWNk98iReHuQ6SMXF8L7GOJvZNEPWn2pZ5/0vk9/6VmV6Qn+8t1 QkLMrdTbMquztRufO7eKmAjvfdPQRVH30dUPNKo9CzDTMjyWO1PquAlh9noU3MGYXsBI M/9rYKYtInCR4m5Zthgf9+zh1HcBmz1jXRctYAEtrIgjMWSlt+his/qj9FhvyP3x+ZW5 37CA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=BjYy4y4h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 203-20020a6306d4000000b005193a2c7b24si12690340pgg.473.2023.04.17.16.14.25; Mon, 17 Apr 2023 16:14:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=BjYy4y4h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230135AbjDQW5m (ORCPT + 99 others); Mon, 17 Apr 2023 18:57:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230053AbjDQW5k (ORCPT ); Mon, 17 Apr 2023 18:57:40 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9256940FB; Mon, 17 Apr 2023 15:57:30 -0700 (PDT) Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33HM2MwT007875; Mon, 17 Apr 2023 22:57:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=message-id : date : mime-version : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding; s=qcppdkim1; bh=TYiYTf71z2QgKJBu/vBOofEjUIMRz93Rtu7+eYyDuHM=; b=BjYy4y4hlgTnSr+4IwhM8QQfNv+eBf0I58/MJqGD8gZ6NwHIQb3h7TQV7k5m+JNrYjoG aUkn3nZgOgBQ71imRbDZ4s3FbLVugjMVg4fTqvlqX+YGxKL4eMNduKQ5BNgzFO+hOkI5 s/nA+IBaQF2eBGpEz+1qj5KpH4Hs6kAReD7KxfUJBd3NrxfVvu88zCKdIcQbl0H/jEw5 HCS438ghoUnvWwYOSWwtEJQSiQySgAyN+znoUmy0zlf24QGcWrCi7z8NBNay1uA1yoaV be2eoE+z8Z3sviGiEBbovMNzTrwqlEJAIgziwOtE6EgRLaMqeNEr7Ac/lz2zTwazx3S4 vw== Received: from nasanppmta05.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3q19kg0phr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Apr 2023 22:57:18 +0000 Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 33HMvHfQ026364 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 17 Apr 2023 22:57:17 GMT Received: from [10.134.65.165] (10.80.80.8) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Mon, 17 Apr 2023 15:57:16 -0700 Message-ID: Date: Mon, 17 Apr 2023 15:57:16 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: [PATCH v11 20/26] virt: gunyah: Add resource tickets Content-Language: en-US To: Alex Elder , Srinivas Kandagatla , Prakruthi Deepak Heragu CC: Murali Nalajala , Trilok Soni , Srivatsa Vaddagiri , Carl van Schaik , Dmitry Baryshkov , Bjorn Andersson , "Konrad Dybcio" , Arnd Bergmann , "Greg Kroah-Hartman" , Rob Herring , Krzysztof Kozlowski , Jonathan Corbet , Bagas Sanjaya , Will Deacon , Andy Gross , Catalin Marinas , Jassi Brar , , , , , References: <20230304010632.2127470-1-quic_eberman@quicinc.com> <20230304010632.2127470-21-quic_eberman@quicinc.com> From: Elliot Berman In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: pQIDRNy4YdHcA9erZIuWQwlbO6_BTI_7 X-Proofpoint-ORIG-GUID: pQIDRNy4YdHcA9erZIuWQwlbO6_BTI_7 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-17_14,2023-04-17_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxlogscore=999 suspectscore=0 bulkscore=0 spamscore=0 impostorscore=0 lowpriorityscore=0 priorityscore=1501 clxscore=1015 mlxscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304170202 X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/31/2023 7:27 AM, Alex Elder wrote: > On 3/3/23 7:06 PM, Elliot Berman wrote: >> Some VM functions need to acquire Gunyah resources. For instance, Gunyah >> vCPUs are exposed to the host as a resource. The Gunyah vCPU function >> will register a resource ticket and be able to interact with the >> hypervisor once the resource ticket is filled. >> >> Resource tickets are the mechanism for functions to acquire ownership of >> Gunyah resources. Gunyah functions can be created before the VM's >> resources are created and made available to Linux. A resource ticket >> identifies a type of resource and a label of a resource which the ticket >> holder is interested in. >> >> Resources are created by Gunyah as configured in the VM's devicetree >> configuration. Gunyah doesn't process the label and that makes it >> possible for userspace to create multiple resources with the same label. >> Resource ticket owners need to be prepared for populate to be called >> multiple times if userspace created multiple resources with the same >> label. >> >> Signed-off-by: Elliot Berman > > One possibly substantive suggestion here, plus a couple suggestions > to add or revise comments. > >                     -Alex > >> --- >>   drivers/virt/gunyah/vm_mgr.c  | 112 +++++++++++++++++++++++++++++++++- >>   drivers/virt/gunyah/vm_mgr.h  |   4 ++ >>   include/linux/gunyah_vm_mgr.h |  14 +++++ >>   3 files changed, 129 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/virt/gunyah/vm_mgr.c b/drivers/virt/gunyah/vm_mgr.c >> index 88db011395ec..0269bcdaf692 100644 >> --- a/drivers/virt/gunyah/vm_mgr.c >> +++ b/drivers/virt/gunyah/vm_mgr.c >> @@ -165,6 +165,74 @@ static long gh_vm_rm_function(struct gh_vm *ghvm, >> struct gh_fn_desc *f) >>       return r; >>   } >> +int gh_vm_add_resource_ticket(struct gh_vm *ghvm, struct >> gh_vm_resource_ticket *ticket) >> +{ >> +    struct gh_vm_resource_ticket *iter; >> +    struct gh_resource *ghrsc; >> +    int ret = 0; >> + >> +    mutex_lock(&ghvm->resources_lock); >> +    list_for_each_entry(iter, &ghvm->resource_tickets, list) { >> +        if (iter->resource_type == ticket->resource_type && >> iter->label == ticket->label) { >> +            ret = -EEXIST; >> +            goto out; >> +        } >> +    } >> + >> +    if (!try_module_get(ticket->owner)) { >> +        ret = -ENODEV; >> +        goto out; >> +    } >> + >> +    list_add(&ticket->list, &ghvm->resource_tickets); >> +    INIT_LIST_HEAD(&ticket->resources); >> + >> +    list_for_each_entry(ghrsc, &ghvm->resources, list) { >> +        if (ghrsc->type == ticket->resource_type && ghrsc->rm_label >> == ticket->label) { >> +            if (!ticket->populate(ticket, ghrsc)) >> +                list_move(&ghrsc->list, &ticket->resources); >> +        } >> +    } >> +out: >> +    mutex_unlock(&ghvm->resources_lock); >> +    return ret; >> +} >> +EXPORT_SYMBOL_GPL(gh_vm_add_resource_ticket); >> + >> +void gh_vm_remove_resource_ticket(struct gh_vm *ghvm, struct >> gh_vm_resource_ticket *ticket) >> +{ >> +    struct gh_resource *ghrsc, *iter; >> + >> +    mutex_lock(&ghvm->resources_lock); >> +    list_for_each_entry_safe(ghrsc, iter, &ticket->resources, list) { >> +        ticket->unpopulate(ticket, ghrsc); >> +        list_move(&ghrsc->list, &ghvm->resources); >> +    } >> + >> +    module_put(ticket->owner); >> +    list_del(&ticket->list); >> +    mutex_unlock(&ghvm->resources_lock); >> +} >> +EXPORT_SYMBOL_GPL(gh_vm_remove_resource_ticket); >> + >> +static void gh_vm_add_resource(struct gh_vm *ghvm, struct gh_resource >> *ghrsc) >> +{ >> +    struct gh_vm_resource_ticket *ticket; >> + >> +    mutex_lock(&ghvm->resources_lock); >> +    list_for_each_entry(ticket, &ghvm->resource_tickets, list) { >> +        if (ghrsc->type == ticket->resource_type && ghrsc->rm_label >> == ticket->label) { >> +            if (!ticket->populate(ticket, ghrsc)) { >> +                list_add(&ghrsc->list, &ticket->resources); >> +                goto found; >> +            } > > I think the "goto found" belongs here, unconditionally. > You disallow adding more than one ticket of a given type > with the same label.  So you will never match another > ticket once you've matched this one. > > The populate function generally shouldn't fail.  I think > it only fails if you find a duplicate, and again, I think > you prevent that from happening.  (But if it does, you > silently ignore it...) > I agree with this suggestion, no need to waste continue checking other tickets once we find the match. I'll move the "goto found" line. [snip] Thanks, Elliot