From mboxrd@z Thu Jan 1 00:00:00 1970 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 3AC58C61DA4 for ; Mon, 6 Feb 2023 10:48:03 +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:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version: References:Message-ID:Subject:CC:To:From:Date:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=7fsVNlsiyGfzagZx1P+y4DDdrHkcWgC7gln3+uTv6vM=; b=m0BZLOuoJFYErJ dcNU9aGcFdf2CKyDVsTpfAZ30jR/NNABoRvXxF56SS61zt/ArG1uwWGXPCohEmOs539Kw7dp7QqWz TWMupSv414BDtFn93nZH02IZzY/oZ5DwRrndSM7mFwGCumxdV9qary+fS+VobSfeSAiR72zAKn9qi 0S6XEdS/mh+ACBWJNiScVuxec1ZyZRN8XP7lEnI3w+4OdhqvfT5pE6InPKq1FSLQeEzBKoZJNkf1o z9YUr3NMl+vI/AOCTR7W5A7e9hgVNnzfxsGNbHldM8Eof5PpoJ6mv0ZJAieO1E4qdVez72lArYtJ/ 5UWwHWmfks5Mpr1zI6Ug==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pOz1f-008BTy-UL; Mon, 06 Feb 2023 10:47:08 +0000 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pOz1W-008BQk-LP for linux-arm-kernel@lists.infradead.org; Mon, 06 Feb 2023 10:47:00 +0000 Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3166H1Fd031288; Mon, 6 Feb 2023 10:46:50 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=date : from : to : cc : subject : message-id : reply-to : references : mime-version : content-type : in-reply-to; s=qcppdkim1; bh=aCHh43spwV/1Pii0j/iZxs1Y1fpmhenTUzufbRtMQQU=; b=c8BH5aUWG3jvGdCu22D+3qwq84ObGe85/laH6dZqgOYSiL40Btaxy/QRPiDD5J1Earvb O5/V0eGRNaZAB7Lh3B/ibMvnOoCAOC7UA7L1YIEWotVMZ4Yeyh01AdpAMooyEjO8FV6v wen7SctrXC/XYZNRP6XGJA0MwuKYjV1hBARJYqnr4oO/XWnpHaLZrXEG5uiFyx0SmTbq gDOMl6LNhpdj+zqIJ+7ewWyLM0WI/HuKjR1yqMZOzkJWO6GnB4okLa4j5UGZGNatxXNI teY1uD6p7YcmM1TxXV48DQJYNfNIAwk8RrLiEhalsmmA973cPIKy8ImOHWW4p6tpFq1E Tw== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3nhfreuf9x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 06 Feb 2023 10:46:49 +0000 Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 316AkmN2018281 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 6 Feb 2023 10:46:48 GMT Received: from quicinc.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Mon, 6 Feb 2023 02:46:41 -0800 Date: Mon, 6 Feb 2023 16:16:37 +0530 From: Srivatsa Vaddagiri To: Elliot Berman CC: Bjorn Andersson , Alex Elder , Murali Nalajala , Trilok Soni , Carl van Schaik , Prakruthi Deepak Heragu , Dmitry Baryshkov , Arnd Bergmann , "Greg Kroah-Hartman" , Rob Herring , Krzysztof Kozlowski , Jonathan Corbet , Bagas Sanjaya , Catalin Marinas , Will Deacon , Marc Zyngier , Jassi Brar , Sudeep Holla , , , , , Subject: Re: [PATCH v9 23/27] virt: gunyah: Add IO handlers Message-ID: <20230206104637.GG332@quicinc.com> References: <20230120224627.4053418-1-quic_eberman@quicinc.com> <20230120224627.4053418-24-quic_eberman@quicinc.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20230120224627.4053418-24-quic_eberman@quicinc.com> X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: fbIDtkTLM12OUOr8yiICcuXqyf03ZiuH X-Proofpoint-GUID: fbIDtkTLM12OUOr8yiICcuXqyf03ZiuH X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-02-06_05,2023-02-06_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 lowpriorityscore=0 spamscore=0 clxscore=1015 impostorscore=0 mlxscore=0 malwarescore=0 priorityscore=1501 adultscore=0 mlxlogscore=757 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302060093 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230206_024658_844257_3FB4EC05 X-CRM114-Status: GOOD ( 17.52 ) 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: , Reply-To: Srivatsa Vaddagiri Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org * Elliot Berman [2023-01-20 14:46:22]: > +static inline bool gh_vm_io_handler_matches(struct gunyah_vm_io_handler *io_hdlr, u64 addr, > + u64 len, u64 data) > +{ > + u64 mask = BIT_ULL(io_hdlr->len * BITS_PER_BYTE) - 1; > + > + if (io_hdlr->addr != addr) Isn't this test redundant (given that caller would have performed same test)? > + return false; > + > + if (!io_hdlr->datamatch) > + return true; > + > + if (io_hdlr->len != len) > + return false; > + > + return (data & mask) == (io_hdlr->data & mask); > +} > + > +static struct gunyah_vm_io_handler *gh_vm_mgr_find_io_hdlr(struct gunyah_vm *ghvm, u64 addr, > + u64 len, u64 data) > +{ > + struct gunyah_vm_io_handler *io_hdlr = NULL; > + struct rb_node *root = NULL; > + > + root = ghvm->mmio_handler_root.rb_node; > + while (root) { > + io_hdlr = rb_entry(root, struct gunyah_vm_io_handler, node); > + if (addr < io_hdlr->addr) > + root = root->rb_left; > + else if (addr > io_hdlr->addr) > + root = root->rb_right; > + else if (gh_vm_io_handler_matches(io_hdlr, addr, len, data)) In case of handler not matching, don't we need to modify root? Otherwise we can be stuck in infinite loop here AFAICS. > + return io_hdlr; > + } > + return NULL; > +} // snip > +int gh_vm_mgr_add_io_handler(struct gunyah_vm *ghvm, struct gunyah_vm_io_handler *io_hdlr) > +{ > + struct rb_node **root, *parent = NULL; > + > + if (io_hdlr->datamatch && > + (!io_hdlr->len || io_hdlr->len > (sizeof(io_hdlr->data) * BITS_PER_BYTE))) > + return -EINVAL; > + > + root = &ghvm->mmio_handler_root.rb_node; > + while (*root) { > + struct gunyah_vm_io_handler *curr = rb_entry(*root, struct gunyah_vm_io_handler, > + node); > + > + parent = *root; > + if (io_hdlr->addr < curr->addr) > + root = &((*root)->rb_left); > + else if (io_hdlr->addr > curr->addr) > + root = &((*root)->rb_right); > + else We should allow two io_handlers on the same addr, but with different data matches I think. > + return -EEXIST; > + } > + > + rb_link_node(&io_hdlr->node, parent, root); > + rb_insert_color(&io_hdlr->node, &ghvm->mmio_handler_root); > + return 0; > +} > +EXPORT_SYMBOL_GPL(gh_vm_mgr_add_io_handler); _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel